cpplex.c (cpp_idcmp): New function.

* cpplex.c (cpp_idcmp): New function.
	* cpplib.h: Prototype it.
	* scan_decls.c (scan_decls): Use it to inspect token names.
	* fix-header.c (read_scan_file): Likewise.  Set system_header_p on
	the file being run through the preprocessor.
	(check_macro_names): Provide length of token to cpp_defined.

	* Makefile.in: Remove stale warning message.

From-SVN: r33552
This commit is contained in:
Zack Weinberg 2000-04-30 17:30:25 +00:00
parent 638d694d84
commit 6d2c2047b5
6 changed files with 243 additions and 200 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2297,7 +2297,6 @@ fixhdr.ready: fix-header
# The if statement is so that we don't run fixproto a second time
# if it has already been run on the files in `include'.
stmp-fixproto: fixhdr.ready fixproto stmp-int-hdrs
@echo "Various warnings and error messages from fixproto are normal"
if [ -f include/fixed ] ; then true; \
else \
: This line works around a 'make' bug in BSDI 1.1.; \

View File

@ -2048,6 +2048,37 @@ _cpp_init_input_buffer (pfile)
pfile->input_buffer_len = 8192;
}
/* Utility routine:
Compares, in the manner of strcmp(3), the token beginning at TOKEN
and extending for LEN characters to the NUL-terminated string
STRING. Typical usage:
if (! cpp_idcmp (pfile->token_buffer + here, CPP_WRITTEN (pfile) - here,
"inline"))
{ ... }
*/
int
cpp_idcmp (token, len, string)
const U_CHAR *token;
size_t len;
const char *string;
{
size_t len2 = strlen (string);
int r;
if ((r = memcmp (token, string, MIN (len, len2))))
return r;
/* The longer of the two strings sorts after the shorter. */
if (len == len2)
return 0;
else if (len < len2)
return -1;
else
return 1;
}
#if 0
/* Lexing algorithm.

View File

@ -655,8 +655,8 @@ extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
extern void cpp_scan_buffer PARAMS ((cpp_reader *, cpp_printer *));
extern void cpp_scan_buffer_nooutput PARAMS ((cpp_reader *));
extern int cpp_idcmp PARAMS ((const unsigned char *,
size_t, const char *));
/* In cpphash.c */
extern int cpp_defined PARAMS ((cpp_reader *,

View File

@ -602,11 +602,13 @@ check_macro_names (pfile, names)
cpp_reader *pfile;
namelist names;
{
size_t len;
while (*names)
{
if (cpp_defined (pfile, names, -1))
len = strlen (names);
if (cpp_defined (pfile, names, len))
recognized_macro (names);
names += strlen (names) + 1;
names += len + 1;
}
}
@ -637,6 +639,9 @@ read_scan_file (in_fname, argc, argv)
if (! cpp_start_read (&scan_in, 0, in_fname))
exit (FATAL_EXIT_CODE);
/* We are scanning a system header, so mark it as such. */
CPP_BUFFER (&scan_in)->system_header_p = 1;
scan_decls (&scan_in, argc, argv);
for (cur_symbols = &symbol_table[0]; cur_symbols->names; cur_symbols++)
check_macro_names (&scan_in, cur_symbols->names);
@ -663,6 +668,8 @@ read_scan_file (in_fname, argc, argv)
{
enum cpp_ttype token = cpp_get_token (&scan_in);
int length = CPP_WRITTEN (&scan_in) - old_written;
unsigned char *id = scan_in.token_buffer + old_written;
CPP_SET_WRITTEN (&scan_in, old_written);
if (token == CPP_EOF) /* Should not happen ... */
break;
@ -671,8 +678,7 @@ read_scan_file (in_fname, argc, argv)
cpp_pop_buffer (&scan_in);
break;
}
if (token == CPP_NAME && length == 7
&& strcmp ("_filbuf", scan_in.token_buffer + old_written) == 0)
if (token == CPP_NAME && cpp_idcmp (id, length, "_filbuf") == 0)
seen_filbuf++;
}
if (seen_filbuf)
@ -690,7 +696,7 @@ read_scan_file (in_fname, argc, argv)
SET_REQUIRED (fn);
if (need_flsbuf)
SET_REQUIRED (flsbuf_fn);
if (need_flsbuf + need_filbuf == 2)
if (need_flsbuf && need_filbuf)
new_list = "_filbuf\0_flsbuf\0";
else if (need_flsbuf)
new_list = "_flsbuf\0";

View File

@ -191,9 +191,7 @@ scan_decls (pfile, argc, argv)
maybe_handle_comma:
if (token != CPP_COMMA)
goto new_statement;
#if 0
handle_comma:
#endif
/* Handle multiple declarators in a single declaration,
as in: extern char *strcpy (), *strcat (), ... ; */
if (declarator_start == 0)
@ -202,12 +200,14 @@ scan_decls (pfile, argc, argv)
break;
case CPP_NAME:
/* "inline" and "extern" are recognized but skipped */
if (strcmp (pfile->token_buffer, "inline") == 0)
if (!cpp_idcmp (pfile->token_buffer,
CPP_WRITTEN (pfile), "inline"))
{
saw_inline = 1;
CPP_SET_WRITTEN (pfile, start_written);
}
if (strcmp (pfile->token_buffer, "extern") == 0)
else if (!cpp_idcmp (pfile->token_buffer,
CPP_WRITTEN (pfile), "extern"))
{
saw_extern = 1;
CPP_SET_WRITTEN (pfile, start_written);