1 /* Utility functions for scan-decls and fix-header programs.
2 Copyright (C) 1993, 1994, 1998, 2002 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #include "coretypes.h"
25 int source_lineno
= 1;
26 sstring source_filename
;
29 make_sstring_space (str
, count
)
33 int cur_pos
= str
->ptr
- str
->base
;
34 int cur_size
= str
->limit
- str
->base
;
35 int new_size
= cur_pos
+ count
+ 100;
37 if (new_size
<= cur_size
)
40 str
->base
= xrealloc (str
->base
, new_size
);
41 str
->ptr
= str
->base
+ cur_size
;
42 str
->limit
= str
->base
+ new_size
;
46 sstring_append (dst
, src
)
51 int count
= SSTRING_LENGTH (src
);
53 MAKE_SSTRING_SPACE (dst
, count
+ 1);
56 while (--count
>= 0) *d
++ = *s
++;
74 if (c
== EOF
|| ! ISIDNUM (c
))
78 MAKE_SSTRING_SPACE (s
, 1);
84 scan_string (fp
, s
, init
)
94 if (c
== EOF
|| c
== '\n')
111 MAKE_SSTRING_SPACE (s
, 1);
116 /* Skip horizontal white spaces (spaces, tabs, and C-style comments). */
125 if (c
== ' ' || c
== '\t')
143 source_lineno
++, lineno
++;
146 else if ((c
= getc (fp
)) == '/')
157 read_upto (fp
, str
, delim
)
167 if (ch
== EOF
|| ch
== delim
)
169 SSTRING_PUT (str
, ch
);
171 MAKE_SSTRING_SPACE (str
, 1);
186 c
= skip_spaces (fp
, c
);
195 c
= get_token (fp
, s
);
198 source_lineno
= atoi (s
->base
) - 1; /* '\n' will add 1 */
199 get_token (fp
, &source_filename
);
222 } while (c
!= EOF
&& ISDIGIT (c
));
229 c
= scan_ident (fp
, s
, c
);
231 return IDENTIFIER_TOKEN
;
233 if (c
== '\'' || c
== '"')
235 c
= scan_string (fp
, s
, c
);
237 return c
== '\'' ? CHAR_TOKEN
: STRING_TOKEN
;
241 MAKE_SSTRING_SPACE (s
, 1);
251 unsigned int n
= len
;
253 const unsigned char *s
= (const unsigned char *) str
;
256 r
= r
* 67 + (*s
++ - 113);