~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to extern/fftw/kernel/scan.c

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2003, 2006 Matteo Frigo
 
3
 * Copyright (c) 2003, 2006 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
/* $Id: scan.c,v 1.19 2006-01-10 13:24:41 athena Exp $ */
 
22
 
 
23
#include "ifftw.h"
 
24
#include <string.h>
 
25
#include <stddef.h>
 
26
#include <stdarg.h>
 
27
#include <stdio.h>
 
28
 
 
29
#ifdef USE_CTYPE
 
30
#include <ctype.h>
 
31
#else
 
32
/* Screw ctype. On linux, the is* functions call a routine that gets
 
33
   the ctype map in the current locale.  Because this operation is
 
34
   expensive, the map is cached on a per-thread basis.  I am not
 
35
   willing to link this crap with FFTW.  Not over my dead body.
 
36
 
 
37
   Sic transit gloria mundi.
 
38
*/
 
39
#undef isspace
 
40
#define isspace(x) ((x) >= 0 && (x) <= ' ')
 
41
#undef isdigit
 
42
#define isdigit(x) ((x) >= '0' && (x) <= '9')
 
43
#undef isupper
 
44
#define isupper(x) ((x) >= 'A' && (x) <= 'Z')
 
45
#undef islower
 
46
#define islower(x) ((x) >= 'a' && (x) <= 'z')
 
47
#endif
 
48
 
 
49
static int mygetc(scanner *sc)
 
50
{
 
51
     if (sc->ungotc != EOF) {
 
52
          int c = sc->ungotc;
 
53
          sc->ungotc = EOF;
 
54
          return c;
 
55
     }
 
56
     return(sc->getchr(sc));
 
57
}
 
58
 
 
59
#define GETCHR(sc) mygetc(sc)
 
60
 
 
61
static void myungetc(scanner *sc, int c)
 
62
{
 
63
     sc->ungotc = c;
 
64
}
 
65
 
 
66
#define UNGETCHR(sc, c) myungetc(sc, c)
 
67
 
 
68
static void eat_blanks(scanner *sc)
 
69
{
 
70
     int ch;
 
71
     while (ch = GETCHR(sc), isspace(ch))
 
72
          ;
 
73
     UNGETCHR(sc, ch);
 
74
}
 
75
 
 
76
static void mygets(scanner *sc, char *s, size_t maxlen)
 
77
{
 
78
     char *s0 = s;
 
79
     int ch;
 
80
 
 
81
     A(maxlen > 0);
 
82
     while ((ch = GETCHR(sc)) != EOF && !isspace(ch)
 
83
            && ch != ')' && ch != '(' && s < s0 + maxlen)
 
84
          *s++ = ch;
 
85
     *s = 0;
 
86
     UNGETCHR(sc, ch);
 
87
}
 
88
 
 
89
static long getlong(scanner *sc, int base, int *ret)
 
90
{
 
91
     int sign = 1, ch, count;
 
92
     long x = 0;     
 
93
 
 
94
     ch = GETCHR(sc);
 
95
     if (ch == '-' || ch == '+') {
 
96
          sign = ch == '-' ? -1 : 1;
 
97
          ch = GETCHR(sc);
 
98
     }
 
99
     for (count = 0; ; ++count) {
 
100
          if (isdigit(ch)) 
 
101
               ch -= '0';
 
102
          else if (isupper(ch))
 
103
               ch -= 'A' - 10;
 
104
          else if (islower(ch))
 
105
               ch -= 'a' - 10;
 
106
          else
 
107
               break;
 
108
          x = x * base + ch;
 
109
          ch = GETCHR(sc);
 
110
     }
 
111
     x *= sign;
 
112
     UNGETCHR(sc, ch);
 
113
     *ret = count > 0;
 
114
     return x;
 
115
}
 
116
 
 
117
/* vscan is mostly scanf-like, with our additional format specifiers,
 
118
   but with a few twists.  It returns simply 0 or 1 indicating whether
 
119
   the match was successful. '(' and ')' in the format string match
 
120
   those characters preceded by any whitespace.  Finally, if a
 
121
   character match fails, it will ungetchr() the last character back
 
122
   onto the stream. */
 
123
static int vscan(scanner *sc, const char *format, va_list ap)
 
124
{
 
125
     const char *s = format;
 
126
     char c;
 
127
     int ch = 0;
 
128
     size_t fmt_len;
 
129
 
 
130
     while ((c = *s++)) {
 
131
          fmt_len = 0;
 
132
          switch (c) {
 
133
              case '%':
 
134
          getformat:
 
135
                   switch ((c = *s++)) {
 
136
                       case 's': {
 
137
                            char *x = va_arg(ap, char *);
 
138
                            mygets(sc, x, fmt_len);
 
139
                            break;
 
140
                       }
 
141
                       case 'd': {
 
142
                            int *x = va_arg(ap, int *);
 
143
                            *x = (int) getlong(sc, 10, &ch);
 
144
                            if (!ch) return 0;
 
145
                            break;
 
146
                       }
 
147
                       case 'x': {
 
148
                            int *x = va_arg(ap, int *);
 
149
                            *x = (int) getlong(sc, 16, &ch);
 
150
                            if (!ch) return 0;
 
151
                            break;
 
152
                       }
 
153
                       case 'M': {
 
154
                            md5uint *x = va_arg(ap, md5uint *);
 
155
                            *x = (md5uint)
 
156
                                    (0xffffffffUL & getlong(sc, 16, &ch));
 
157
                            if (!ch) return 0;
 
158
                            break;
 
159
                       }
 
160
                       case '*': {
 
161
                            if ((fmt_len = va_arg(ap, int)) <= 0) return 0;
 
162
                            goto getformat;
 
163
                       }
 
164
                       default:
 
165
                            A(0 /* unknown format */);
 
166
                            break;
 
167
                   }
 
168
                   break;
 
169
              default:
 
170
                   if (isspace(c) || c == '(' || c == ')')
 
171
                        eat_blanks(sc);
 
172
                   if (!isspace(c) && (ch = GETCHR(sc)) != c) {
 
173
                        UNGETCHR(sc, ch);
 
174
                        return 0;
 
175
                   }
 
176
                   break;
 
177
          }
 
178
     }
 
179
     return 1;
 
180
}
 
181
 
 
182
static int scan(scanner *sc, const char *format, ...)
 
183
{
 
184
     int ret;
 
185
     va_list ap;
 
186
     va_start(ap, format);
 
187
     ret = vscan(sc, format, ap);
 
188
     va_end(ap);
 
189
     return ret;
 
190
}
 
191
 
 
192
scanner *X(mkscanner)(size_t size, int (*getchr)(scanner *sc))
 
193
{
 
194
     scanner *s = (scanner *)MALLOC(size, OTHER);
 
195
     s->scan = scan;
 
196
     s->vscan = vscan;
 
197
     s->getchr = getchr;
 
198
     s->ungotc = EOF;
 
199
     return s;
 
200
}
 
201
 
 
202
void X(scanner_destroy)(scanner *sc)
 
203
{
 
204
     X(ifree)(sc);
 
205
}