annotate src/fftw-3.3.3/api/import-wisdom-from-file.c @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents 37bf6b4a2645
children
rev   line source
Chris@10 1 /*
Chris@10 2 * Copyright (c) 2003, 2007-11 Matteo Frigo
Chris@10 3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
Chris@10 4 *
Chris@10 5 * This program is free software; you can redistribute it and/or modify
Chris@10 6 * it under the terms of the GNU General Public License as published by
Chris@10 7 * the Free Software Foundation; either version 2 of the License, or
Chris@10 8 * (at your option) any later version.
Chris@10 9 *
Chris@10 10 * This program is distributed in the hope that it will be useful,
Chris@10 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@10 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@10 13 * GNU General Public License for more details.
Chris@10 14 *
Chris@10 15 * You should have received a copy of the GNU General Public License
Chris@10 16 * along with this program; if not, write to the Free Software
Chris@10 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@10 18 *
Chris@10 19 */
Chris@10 20
Chris@10 21 #include "api.h"
Chris@10 22 #include <stdio.h>
Chris@10 23
Chris@10 24 /* getc()/putc() are *unbelievably* slow on linux. Looks like glibc
Chris@10 25 is grabbing a lock for each call to getc()/putc(), or something
Chris@10 26 like that. You pay the price for these idiotic posix threads
Chris@10 27 whether you use them or not.
Chris@10 28
Chris@10 29 So, we do our own buffering. This completely defeats the purpose
Chris@10 30 of having stdio in the first place, of course.
Chris@10 31 */
Chris@10 32
Chris@10 33 #define BUFSZ 256
Chris@10 34
Chris@10 35 typedef struct {
Chris@10 36 scanner super;
Chris@10 37 FILE *f;
Chris@10 38 char buf[BUFSZ];
Chris@10 39 char *bufr, *bufw;
Chris@10 40 } S;
Chris@10 41
Chris@10 42 static int getchr_file(scanner * sc_)
Chris@10 43 {
Chris@10 44 S *sc = (S *) sc_;
Chris@10 45
Chris@10 46 if (sc->bufr >= sc->bufw) {
Chris@10 47 sc->bufr = sc->buf;
Chris@10 48 sc->bufw = sc->buf + fread(sc->buf, 1, BUFSZ, sc->f);
Chris@10 49 if (sc->bufr >= sc->bufw)
Chris@10 50 return EOF;
Chris@10 51 }
Chris@10 52
Chris@10 53 return *(sc->bufr++);
Chris@10 54 }
Chris@10 55
Chris@10 56 static scanner *mkscanner_file(FILE *f)
Chris@10 57 {
Chris@10 58 S *sc = (S *) X(mkscanner)(sizeof(S), getchr_file);
Chris@10 59 sc->f = f;
Chris@10 60 sc->bufr = sc->bufw = sc->buf;
Chris@10 61 return &sc->super;
Chris@10 62 }
Chris@10 63
Chris@10 64 int X(import_wisdom_from_file)(FILE *input_file)
Chris@10 65 {
Chris@10 66 scanner *s = mkscanner_file(input_file);
Chris@10 67 planner *plnr = X(the_planner)();
Chris@10 68 int ret = plnr->adt->imprt(plnr, s);
Chris@10 69 X(scanner_destroy)(s);
Chris@10 70 return ret;
Chris@10 71 }
Chris@10 72
Chris@10 73 int X(import_wisdom_from_filename)(const char *filename)
Chris@10 74 {
Chris@10 75 FILE *f = fopen(filename, "r");
Chris@10 76 int ret;
Chris@10 77 if (!f) return 0; /* error opening file */
Chris@10 78 ret = X(import_wisdom_from_file)(f);
Chris@10 79 if (fclose(f)) ret = 0; /* error closing file */
Chris@10 80 return ret;
Chris@10 81 }