2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
28 # include "splintMacros.nf"
31 int reader_getInt (char **s)
44 if (**s < '0' || **s > '9')
46 llbug (message ("getInt: bad int: %s", cstring_fromChars (*s)));
50 i = -1 * (int) (**s - '0');
57 while (**s >= '0' && **s <= '9')
60 i += (int) (**s - '0');
67 llbug (message ("No int to read: %s", cstring_fromChars (*s)));
70 while (**s == '\n' || **s == ' ' || **s == '\t')
79 reader_loadChar (char **s)
94 ** not sure if this works...
98 reader_getDouble (char **s)
100 char *end = mstring_createEmpty ();
103 ret = strtod (*s, &end);
110 ** read to ' ', '\t'. '\n', '#', ',' or '\0'
114 reader_getWord (char **s)
120 while ((c = **s) != '\0' && (c != ' ') && (c != ',')
121 && (c != '\n') && (c != '\t') && (c != '#'))
132 res = mstring_copy (t);
142 reader_readUntil (char **s, char x)
148 while ((c = **s) != '\0' && (c != x))
153 llassert (**s != '\0');
157 res = cstring_fromChars (mstring_copy (t));
163 reader_readUntilOne (char **s, char *x)
169 while ((c = **s) != '\0' && (!mstring_containsChar (x, c)))
174 llassert (**s != '\0');
178 res = cstring_fromChars (mstring_copy (t));
184 reader_optCheckChar (char **s, char c)
198 reader_doCheckChar (char **s, char c, char *file, int line)
200 /*@unchecked@*/ static int nbadchars = 0;
212 llfatalbug (cstring_makeLiteral
213 ("checkChar: Too many errors. Check library is up to date."));
217 llbug (message ("checkChar: %q: Bad char, expecting %h: %s",
218 fileloc_unparseRaw (cstring_fromChars (file), line),
220 cstring_fromChars (*s)));
225 void reader_checkUngetc (int c, FILE *f)
234 char *reader_readLine (FILE *f, char *s, int max)
236 char *res = fgets (s, MAX_DUMP_LINE_LENGTH, f);
240 if (strlen (res) == size_fromInt (MAX_DUMP_LINE_LENGTH - 1))
242 llfatalerrorLoc (message ("Maximum line length exceeded (%d): %s", max,
243 cstring_fromChars (s)));