1 /* Utility functions for scan-decls and fix-header programs.
2 Copyright (C) 1993, 1994, 1998, 2002, 2003, 2007, 2008
3 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 3, or (at your option) any
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING3. If not see
17 <http://www.gnu.org/licenses/>. */
21 #include "coretypes.h"
26 int source_lineno = 1;
27 sstring source_filename;
30 make_sstring_space (sstring *str, int count)
32 int cur_pos = str->ptr - str->base;
33 int cur_size = str->limit - str->base;
34 int new_size = cur_pos + count + 100;
36 if (new_size <= cur_size)
39 str->base = (char *) xrealloc (str->base, new_size);
40 str->ptr = str->base + cur_size;
41 str->limit = str->base + new_size;
45 sstring_append (sstring *dst, sstring *src)
48 int count = SSTRING_LENGTH (src);
50 MAKE_SSTRING_SPACE (dst, count + 1);
53 while (--count >= 0) *d++ = *s++;
59 scan_ident (FILE *fp, sstring *s, int c)
68 if (c == EOF || ! ISIDNUM (c))
72 MAKE_SSTRING_SPACE (s, 1);
78 scan_string (FILE *fp, sstring *s, int init)
85 if (c == EOF || c == '\n')
102 MAKE_SSTRING_SPACE (s, 1);
107 /* Skip horizontal white spaces (spaces, tabs, and C-style comments). */
110 skip_spaces (FILE *fp, int c)
114 if (c == ' ' || c == '\t')
132 source_lineno++, lineno++;
135 else if ((c = getc (fp)) == '/')
146 read_upto (FILE *fp, sstring *str, int delim)
153 if (ch == EOF || ch == delim)
155 SSTRING_PUT (str, ch);
157 MAKE_SSTRING_SPACE (str, 1);
163 get_token (FILE *fp, sstring *s)
170 c = skip_spaces (fp, c);
179 c = get_token (fp, s);
182 source_lineno = atoi (s->base) - 1; /* '\n' will add 1 */
183 get_token (fp, &source_filename);
206 } while (c != EOF && ISDIGIT (c));
213 c = scan_ident (fp, s, c);
215 return IDENTIFIER_TOKEN;
217 if (c == '\'' || c == '"')
219 c = scan_string (fp, s, c);
221 return c == '\'' ? CHAR_TOKEN : STRING_TOKEN;
225 MAKE_SSTRING_SPACE (s, 1);
231 hashstr (const char *str, unsigned int len)
233 unsigned int n = len;
235 const unsigned char *s = (const unsigned char *) str;
238 r = r * 67 + (*s++ - 113);