1 /* Utility functions for scan-decls and fix-header programs.
2 Copyright (C) 1993, 1994, 1998, 2002, 2003 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 (sstring
*str
, int count
)
31 int cur_pos
= str
->ptr
- str
->base
;
32 int cur_size
= str
->limit
- str
->base
;
33 int new_size
= cur_pos
+ count
+ 100;
35 if (new_size
<= cur_size
)
38 str
->base
= xrealloc (str
->base
, new_size
);
39 str
->ptr
= str
->base
+ cur_size
;
40 str
->limit
= str
->base
+ new_size
;
44 sstring_append (sstring
*dst
, sstring
*src
)
47 int count
= SSTRING_LENGTH (src
);
49 MAKE_SSTRING_SPACE (dst
, count
+ 1);
52 while (--count
>= 0) *d
++ = *s
++;
58 scan_ident (FILE *fp
, sstring
*s
, int c
)
67 if (c
== EOF
|| ! ISIDNUM (c
))
71 MAKE_SSTRING_SPACE (s
, 1);
77 scan_string (FILE *fp
, sstring
*s
, int init
)
84 if (c
== EOF
|| c
== '\n')
101 MAKE_SSTRING_SPACE (s
, 1);
106 /* Skip horizontal white spaces (spaces, tabs, and C-style comments). */
109 skip_spaces (FILE *fp
, int c
)
113 if (c
== ' ' || c
== '\t')
131 source_lineno
++, lineno
++;
134 else if ((c
= getc (fp
)) == '/')
145 read_upto (FILE *fp
, sstring
*str
, int delim
)
152 if (ch
== EOF
|| ch
== delim
)
154 SSTRING_PUT (str
, ch
);
156 MAKE_SSTRING_SPACE (str
, 1);
162 get_token (FILE *fp
, sstring
*s
)
169 c
= skip_spaces (fp
, c
);
178 c
= get_token (fp
, s
);
181 source_lineno
= atoi (s
->base
) - 1; /* '\n' will add 1 */
182 get_token (fp
, &source_filename
);
205 } while (c
!= EOF
&& ISDIGIT (c
));
212 c
= scan_ident (fp
, s
, c
);
214 return IDENTIFIER_TOKEN
;
216 if (c
== '\'' || c
== '"')
218 c
= scan_string (fp
, s
, c
);
220 return c
== '\'' ? CHAR_TOKEN
: STRING_TOKEN
;
224 MAKE_SSTRING_SPACE (s
, 1);
230 hashstr (const char *str
, unsigned int len
)
232 unsigned int n
= len
;
234 const unsigned char *s
= (const unsigned char *) str
;
237 r
= r
* 67 + (*s
++ - 113);