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