diff --git a/epp/Makefile.am b/epp/Makefile.am index 0dbcb285..e8794e48 100644 --- a/epp/Makefile.am +++ b/epp/Makefile.am @@ -20,9 +20,8 @@ bin_PROGRAMS = epp epp_SOURCES = \ - cpplib.h \ + cpplib.h \ cpphash.h \ - header.h \ cppalloc.c \ cpperror.c \ cppexp.c \ diff --git a/epp/cppalloc.c b/epp/cppalloc.c index b9fbd45d..7f2f1440 100644 --- a/epp/cppalloc.c +++ b/epp/cppalloc.c @@ -22,19 +22,18 @@ * You are forbidden to forbid anyone else to use, share and improve * what you give them. Help stamp out software-hoarding! */ -#include "config.h" #include -#include "header.h" +#include "config.h" +#include "cpplib.h" static void -memory_full() +memory_full(void) { - fatal("Memory exhausted."); + cpp_fatal("Memory exhausted."); } void * -xmalloc(size) - unsigned size; +xmalloc(unsigned size) { char *ptr = (char *)malloc(size); @@ -46,9 +45,7 @@ xmalloc(size) } void * -xrealloc(old, size) - void *old; - unsigned size; +xrealloc(void *old, unsigned size) { char *ptr = (char *)realloc(old, size); @@ -58,8 +55,7 @@ xrealloc(old, size) } void * -xcalloc(number, size) - unsigned number, size; +xcalloc(unsigned number, unsigned size) { char *ptr = (char *)calloc(number, size); diff --git a/epp/cpperror.c b/epp/cpperror.c index 7fce8d8a..484a4999 100644 --- a/epp/cpperror.c +++ b/epp/cpperror.c @@ -24,16 +24,14 @@ #include #include -#include "header.h" +#include "config.h" +#include "cpplib.h" /* Print the file names and line numbers of the #include * commands which led to the current file. */ -void fatal(char *str, char *arg); - void -cpp_print_containing_files(pfile) - cpp_reader *pfile; +cpp_print_containing_files(cpp_reader * pfile) { cpp_buffer *ip; int first = 1; @@ -74,10 +72,8 @@ cpp_print_containing_files(pfile) } void -cpp_file_line_for_message(pfile, filename, line, column) - cpp_reader *pfile; - char *filename; - int line, column; +cpp_file_line_for_message(cpp_reader * pfile, const char *filename, + int line, int column) { pfile = NULL; if (column > 0) @@ -92,34 +88,51 @@ cpp_file_line_for_message(pfile, filename, line, column) /* IS_ERROR is 1 for error, 0 for warning */ void -cpp_message(pfile, is_error, msg, arg1, arg2, arg3) - int is_error; - cpp_reader *pfile; - char *msg; - char *arg1, *arg2, *arg3; +cpp_message_v(cpp_reader * pfile, int is_error, const char *msg, va_list args) { if (is_error) pfile->errors++; else fprintf(stderr, "warning: "); - fprintf(stderr, msg, arg1, arg2, arg3); + vfprintf(stderr, msg, args); fprintf(stderr, "\n"); } void -fatal(str, arg) - char *str, *arg; +cpp_message(cpp_reader * pfile, int is_error, const char *msg, ...) +{ + va_list args; + + va_start(args, msg); + + cpp_message_v(pfile, is_error, msg, args); + + va_end(args); +} + +static void +cpp_fatal_v(const char *msg, va_list args) { fprintf(stderr, "%s: ", progname); - fprintf(stderr, str, arg); + vfprintf(stderr, msg, args); fprintf(stderr, "\n"); exit(FATAL_EXIT_CODE); } void -cpp_pfatal_with_name(pfile, name) - cpp_reader *pfile; - char *name; +cpp_fatal(const char *msg, ...) +{ + va_list args; + + va_start(args, msg); + + cpp_fatal_v(msg, args); + + va_end(args); +} + +void +cpp_pfatal_with_name(cpp_reader * pfile, const char *name) { cpp_perror_with_name(pfile, name); #ifdef VMS diff --git a/epp/cppexp.c b/epp/cppexp.c index fe3fc87c..65e2a405 100644 --- a/epp/cppexp.c +++ b/epp/cppexp.c @@ -25,7 +25,8 @@ /* Parse a C expression from text in a string */ #include "config.h" -#include "header.h" +#include "cpplib.h" +#include "cpphash.h" #ifdef __EMX__ #include @@ -102,10 +103,6 @@ struct arglist * number with SUM's sign, where A, B, and SUM are all C integers. */ #define possible_sum_sign(a, b, sum) ((((a) ^ (b)) | ~ ((a) ^ (sum))) < 0) -static void integer_overflow(); -static long left_shift(); -static long right_shift(); - #define ERROR 299 #define OROR 300 #define ANDAND 301 @@ -141,14 +138,11 @@ struct operation /* maybe needs to actually deal with floating point numbers */ -struct operation -parse_number(pfile, start, olen) - cpp_reader *pfile; - char *start; - int olen; +static struct operation +parse_number(cpp_reader * pfile, const char *start, int olen) { struct operation op; - char *p = start; + const char *p = start; int c; unsigned long n = 0, nd, ULONG_MAX_over_base; int base = 10; @@ -251,7 +245,7 @@ parse_number(pfile, start, olen) struct token { - char *operator; + const char *oper; int token; }; @@ -271,9 +265,8 @@ static struct token tokentab2[] = { /* Read one token. */ -struct operation -cpp_lex(pfile) - cpp_reader *pfile; +static struct operation +cpp_lex(cpp_reader * pfile) { int c; struct token *toktab; @@ -282,6 +275,9 @@ cpp_lex(pfile) unsigned char *tok_start, *tok_end; int old_written; + op.value = 0; + op.unsignedp = 0; + retry: old_written = CPP_WRITTEN(pfile); @@ -332,7 +328,7 @@ cpp_lex(pfile) unsigned width = MAX_CHAR_TYPE_SIZE; int wide_flag = 0; int max_chars; - char *ptr = (char*)tok_start; + char *ptr = (char *)tok_start; #ifdef MULTIBYTE_CHARS char token_buffer[MAX_LONG_TYPE_SIZE / @@ -360,7 +356,7 @@ cpp_lex(pfile) while (1) { - if (ptr >= (char*)CPP_PWRITTEN(pfile) || (c = *ptr++) == '\'') + if (ptr >= (char *)CPP_PWRITTEN(pfile) || (c = *ptr++) == '\'') break; if (c == '\\') @@ -403,7 +399,7 @@ cpp_lex(pfile) { int num_bits = num_chars * width; - if (cpp_lookup(pfile, "__CHAR_UNSIGNED__", + if (cpp_lookup("__CHAR_UNSIGNED__", sizeof("__CHAR_UNSIGNED__") - 1, -1) || ((result >> (num_bits - 1)) & 1) == 0) op.value @@ -452,9 +448,9 @@ cpp_lex(pfile) /* See if it is a special token of length 2. */ if (tok_start + 2 == tok_end) { - for (toktab = tokentab2; toktab->operator != NULL; toktab++) - if (tok_start[0] == toktab->operator[0] - && tok_start[1] == toktab->operator[1]) + for (toktab = tokentab2; toktab->oper != NULL; toktab++) + if (tok_start[0] == toktab->oper[0] + && tok_start[1] == toktab->oper[1]) break; if (toktab->token == ERROR) { @@ -492,9 +488,7 @@ cpp_lex(pfile) * after the zeros. A value of 0 does not mean end of string. */ int -cpp_parse_escape(pfile, string_ptr) - cpp_reader *pfile; - char **string_ptr; +cpp_parse_escape(cpp_reader * pfile, char **string_ptr) { int c = *(*string_ptr)++; @@ -594,19 +588,14 @@ cpp_parse_escape(pfile, string_ptr) } static void -integer_overflow(pfile) - cpp_reader *pfile; +integer_overflow(cpp_reader * pfile) { if (CPP_PEDANTIC(pfile)) cpp_pedwarn(pfile, "integer overflow in preprocessor expression"); } static long -left_shift(pfile, a, unsignedp, b) - cpp_reader *pfile; - long a; - int unsignedp; - unsigned long b; +left_shift(cpp_reader * pfile, long a, int unsignedp, unsigned long b) { if (b >= HOST_BITS_PER_LONG) { @@ -627,11 +616,7 @@ left_shift(pfile, a, unsignedp, b) } static long -right_shift(pfile, a, unsignedp, b) - cpp_reader *pfile; - long a; - int unsignedp; - unsigned long b; +right_shift(cpp_reader * pfile, long a, int unsignedp, unsigned long b) { pfile = NULL; if (b >= HOST_BITS_PER_LONG) @@ -672,9 +657,8 @@ right_shift(pfile, a, unsignedp, b) /* Parse and evaluate a C expression, reading from PFILE. * Returns the value of the expression. */ -HOST_WIDE_INT cpp_parse_expr(pfile) - cpp_reader * - pfile; +HOST_WIDE_INT +cpp_parse_expr(cpp_reader * pfile) { /* The implementation is an operator precedence parser, * i.e. a bottom-up parser, using a stack for not-yet-reduced tokens. diff --git a/epp/cpphash.c b/epp/cpphash.c index 7c63d7a9..2b14bdd7 100644 --- a/epp/cpphash.c +++ b/epp/cpphash.c @@ -22,36 +22,22 @@ * You are forbidden to forbid anyone else to use, share and improve * what you give them. Help stamp out software-hoarding! */ -#include "header.h" +#include "cpplib.h" #include "cpphash.h" static HASHNODE *hashtab[HASHSIZE]; -HASHNODE *cpp_lookup(struct parse_file *pfile, - const unsigned char *name, int len, int hash); -void delete_macro(HASHNODE * hp); -HASHNODE *install(unsigned char *name, int len, enum node_type type, - int ivalue, char *value, int hash); - -/* Define a generic NULL if one hasn't already been defined. */ - -#ifndef NULL -#define NULL 0 -#endif - -#ifndef __STDC__ -#define const -#define volatile -#endif #include #include +#define IS_IDCHAR(ch) is_idchar[(unsigned char)(ch)] + /* * return hash function on name. must be compatible with the one * computed a step at a time, elsewhere */ int -hashf(const unsigned char *name, int len, int hashsize) +hashf(const char *name, int len, int hashsize) { int r = 0; @@ -72,16 +58,14 @@ hashf(const unsigned char *name, int len, int hashsize) * Otherwise, compute the hash code. */ HASHNODE * -cpp_lookup(struct parse_file * pfile, const unsigned char *name, int len, - int hash) +cpp_lookup(const char *name, int len, int hash) { - const unsigned char *bp; + const char *bp; HASHNODE *bucket; - pfile = NULL; if (len < 0) { - for (bp = name; is_idchar[*bp]; bp++); + for (bp = name; IS_IDCHAR(*bp); bp++); len = bp - name; } if (hash < 0) @@ -90,7 +74,8 @@ cpp_lookup(struct parse_file * pfile, const unsigned char *name, int len, bucket = hashtab[hash]; while (bucket) { - if (bucket->length == len && strncmp(bucket->name, name, len) == 0) + if (bucket->length == len + && strncmp((const char *)bucket->name, name, len) == 0) return bucket; bucket = bucket->next; } @@ -112,8 +97,7 @@ cpp_lookup(struct parse_file * pfile, const unsigned char *name, int len, * If #undef freed the DEFINITION, that would crash. */ void -delete_macro(hp) - HASHNODE *hp; +delete_macro(HASHNODE * hp) { if (hp->prev != NULL) @@ -157,22 +141,17 @@ delete_macro(hp) * Otherwise, compute the hash code. */ HASHNODE * -install(name, len, type, ivalue, value, hash) - unsigned char *name; - int len; - enum node_type type; - int ivalue; - char *value; - int hash; +install(const char *name, int len, enum node_type type, int ivalue, char *value, + int hash) { HASHNODE *hp; int i, bucket; - unsigned char *p, *q; + const char *p; if (len < 0) { p = name; - while (is_idchar[*p]) + while (IS_IDCHAR(*p)) p++; len = p - name; } @@ -194,18 +173,14 @@ install(name, len, type, ivalue, value, hash) hp->value.ival = ivalue; else hp->value.cpval = value; - hp->name = ((unsigned char *)hp) + sizeof(HASHNODE); - p = hp->name; - q = name; - for (i = 0; i < len; i++) - *p++ = *q++; + hp->name = ((char *)hp) + sizeof(HASHNODE); + memcpy(hp->name, name, len); hp->name[len] = 0; return hp; } void -cpp_hash_cleanup(pfile) - cpp_reader *pfile; +cpp_hash_cleanup(cpp_reader * pfile) { int i; diff --git a/epp/cpphash.h b/epp/cpphash.h index 7b2ef56b..ca19628c 100644 --- a/epp/cpphash.h +++ b/epp/cpphash.h @@ -18,7 +18,7 @@ struct hashnode * of the chain and gets deleted. */ enum node_type type; /* type of special token */ int length; /* length of token, for quick comparison */ - unsigned char *name; /* the actual name */ + char *name; /* the actual name */ union hashval value; /* pointer to expansion, or whatever */ }; @@ -35,5 +35,9 @@ typedef struct hashnode HASHNODE; #define HASHSTEP(old, c) ((old << 2) + c) #define MAKE_POS(v) (v & 0x7fffffff) /* make number positive */ -extern HASHNODE *install -PARAMS((unsigned char *, int, enum node_type, int, char *, int)); +extern int hashf(const char *name, int len, int hashsize); +extern HASHNODE *cpp_lookup(const char *name, int len, int hash); +extern void delete_macro(HASHNODE * hp); +extern HASHNODE *install(const char *name, int len, enum node_type type, + int ivalue, char *value, int hash); +extern void cpp_hash_cleanup(cpp_reader * pfile); diff --git a/epp/cpplib.c b/epp/cpplib.c index ecef0b43..eb56f83f 100644 --- a/epp/cpplib.c +++ b/epp/cpplib.c @@ -22,7 +22,7 @@ * You are forbidden to forbid anyone else to use, share and improve * what you give them. Help stamp out software-hoarding! */ -char *version_string = "0.0.0"; +const char *version_string = "0.0.0"; #include "config.h" @@ -38,7 +38,7 @@ char *version_string = "0.0.0"; #define LOCAL_INCLUDE_DIR "/usr/local/include" #endif -#include "header.h" +#include "cpplib.h" #include "cpphash.h" #ifndef STDC_VALUE @@ -82,13 +82,6 @@ char *version_string = "0.0.0"; /* This defines "errno" properly for VMS, and gives us EACCES. */ #include -/* AIX #defines index as a macro for inlining by compiler - * and the non-ansi declaration gives it indigestion */ -#if !defined(index) || !defined(_AIX) -extern char *index(); -extern char *rindex(); -#endif - #ifndef O_RDONLY #define O_RDONLY 0 #endif @@ -98,20 +91,6 @@ extern char *rindex(); #define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) #define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) -/* Find the largest host integer type and set its size and type. */ - -#ifndef HOST_BITS_PER_WIDE_INT - -#if HOST_BITS_PER_LONG > HOST_BITS_PER_INT -#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG -#define HOST_WIDE_INT long -#else -#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT -#define HOST_WIDE_INT int -#endif - -#endif - #ifndef S_ISREG #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #endif @@ -122,10 +101,6 @@ extern char *rindex(); /* Define a generic NULL if one hasn't already been defined. */ -#ifndef NULL -#define NULL 0 -#endif - #ifndef GENERIC_PTR #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__) #define GENERIC_PTR void * @@ -134,10 +109,6 @@ extern char *rindex(); #endif #endif -#ifndef NULL_PTR -#define NULL_PTR ((GENERIC_PTR)0) -#endif - #ifndef INCLUDE_LEN_FUDGE #define INCLUDE_LEN_FUDGE 0 #endif @@ -145,10 +116,10 @@ extern char *rindex(); /* Symbols to predefine. */ #ifdef CPP_PREDEFINES -static char *predefs = CPP_PREDEFINES; +static const char *predefs = CPP_PREDEFINES; #else -static char *predefs = ""; +static const char *predefs = ""; #endif @@ -190,6 +161,18 @@ static char *predefs = ""; #define REGISTER_PREFIX "" #endif +struct directive +{ + int length; + int (*func) (cpp_reader * pfile, struct directive * keyword, + unsigned char *buf, unsigned char *limit); + const char *name; + enum node_type type; + char command_reads_line; + char traditional_comments; + char pass_thru; +}; + /* In the definition of a #assert name, this structure forms * a list of the individual values asserted. * Each value is itself a list of "tokens". @@ -210,13 +193,13 @@ struct assertion_hashnode * of the chain and gets deleted. */ struct assertion_hashnode **bucket_hdr; int length; /* length of token, for quick comparison */ - unsigned char *name; /* the actual name */ + char *name; /* the actual name */ /* List of token-sequences. */ struct tokenlist_list *value; }; -#define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0) -#define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0) +#define SKIP_WHITE_SPACE(p) do { while (is_hor_space[(unsigned char)(*p)]) p++; } while (0) +#define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[(unsigned char)(*p)]) p++; } while (0) #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF) #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N)) @@ -248,52 +231,43 @@ char *progname; struct cpp_pending { struct cpp_pending *next; - char *cmd; - char *arg; + const char *cmd; + const char *arg; }; +/* Structure returned by create_definition */ +typedef struct +{ + struct definition *defn; + char *symnam; + int symlen; +} MACRODEF; + /* Forward declarations. */ static void add_import(cpp_reader * pfile, int fd, char *fname); -static void append_include_chain(); -static void make_assertion(); -static void path_include(); -static void initialize_builtins(); -static void initialize_char_syntax(); -extern void delete_macro(); -static int finclude(cpp_reader * pfile, int f, char *fname, +static int finclude(cpp_reader * pfile, int f, const char *fname, int system_header_p, - struct file_name_list *dirptr); -static void validate_else(cpp_reader * pfile, char *directive); +static void validate_else(cpp_reader * pfile, const char *directive); static int comp_def_part(int first, unsigned char *beg1, int len1, unsigned char *beg2, int len2, int last); -extern void fancy_abort(); static int lookup_import(cpp_reader * pfile, char *filename, - struct file_name_list *searchptr); static int redundant_include_p(cpp_reader * pfile, char *name); static int is_system_include(cpp_reader * pfile, char *filename); -static struct file_name_map *read_name_map(); -static char *read_filename_string(); static int open_include_file(cpp_reader * pfile, char *filename, - struct file_name_list *searchptr); static int check_macro_name(cpp_reader * pfile, unsigned char *symname, + const char *usage); - char *usage); - -static int compare_defs(); static int compare_token_lists(struct arglist *l1, struct arglist *l2); static HOST_WIDE_INT eval_if_expression(cpp_reader * pfile, unsigned char *buf, - int length); -static int change_newlines(); static int file_size_and_mode(int fd, int *mode_pointer, - long int *size_pointer); static struct arglist *read_token_list(cpp_reader * pfile, int *error_flag); static void free_token_list(struct arglist *tokens); @@ -303,38 +277,44 @@ static void push_macro_expansion(cpp_reader * pfile, int xbuf_len, HASHNODE * hp); static struct cpp_pending *nreverse_pending(struct cpp_pending *list); -static char *savestring(char *input); +static char *savestring(const char *input); static void conditional_skip(cpp_reader * pfile, int skip, enum node_type type, - unsigned char *control_macro); static void skip_if_group(cpp_reader * pfile, int any); +static void cpp_error_with_line(cpp_reader * pfile, int line, + int column, const char *msg); +static void cpp_pedwarn_with_line(cpp_reader * pfile, int line, + int column, const char *msg); +static void cpp_pedwarn_with_file_and_line(cpp_reader * pfile, + const char *file, int line, + const char *msg, + const char *arg1, + const char *arg2, + const char *arg3); +static void cpp_error_from_errno(cpp_reader * pfile, const char *name); + +static cpp_buffer *cpp_push_buffer(cpp_reader * pfile, unsigned char *buffer, + long length); +static cpp_buffer *cpp_pop_buffer(cpp_reader * pfile); + /* Last arg to output_line_command. */ enum file_change_code { same_file, enter_file, leave_file }; -/* External declarations. */ - -extern HOST_WIDE_INT cpp_parse_expr PARAMS((cpp_reader *)); - -extern char *getenv(); -extern FILE *fdopen(); -extern char *version_string; -extern struct tm *localtime(); - /* These functions are declared to return int instead of void since they * are going to be placed in a table and some old compilers have trouble with * pointers to functions returning void. */ static int do_define(cpp_reader * pfile, struct directive *keyword, - unsigned char *buf, unsigned char *limit); -static int do_line(cpp_reader * pfile, struct directive *keyword); +static int do_line(cpp_reader * pfile, struct directive *keyword, + unsigned char *unused1, unsigned char *unused2); static int do_include(cpp_reader * pfile, struct directive *keyword, unsigned char *unused1, unsigned char *unused2); @@ -366,8 +346,6 @@ static int do_elif(cpp_reader * pfile, struct directive *keyword, static int do_endif(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, unsigned char *limit); -static int do_once(cpp_reader * pfile); - static int do_assert(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, unsigned char *limit); @@ -378,19 +356,15 @@ static int do_warning(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, unsigned char *limit); struct arglist *reverse_token_list(struct arglist *tokens); -void parse_set_mark(struct parse_marker *pmark, +static int parse_name(cpp_reader * pfile, int c); + +static void parse_set_mark(struct parse_marker *pmark, cpp_reader * pfile); -int check_assertion(cpp_reader * pfile, unsigned char *name, - int sym_length, int tokens_specified, - - struct arglist *tokens); -void parse_clear_mark(struct parse_marker *pmark); -void parse_goto_mark(struct parse_marker *pmark, - +static void parse_clear_mark(struct parse_marker *pmark); +static void parse_goto_mark(struct parse_marker *pmark, cpp_reader * pfile); -void parse_move_mark(struct parse_marker *pmark, - +static void parse_move_mark(struct parse_marker *pmark, cpp_reader * pfile); struct file_name_list @@ -419,15 +393,15 @@ struct file_name_list /* The */ static struct default_include { - char *fname; /* The name of the directory. */ + const char *fname; /* The name of the directory. */ int cplusplus; /* Only look here if we're compiling C++. */ int cxx_aware; /* Includes in this directory don't need to - * * * be wrapped in extern "C" when compiling - * * * C++. */ + * be wrapped in extern "C" when compiling + * C++. */ } include_defaults_array[] #ifdef INCLUDE_DEFAULTS -= INCLUDE_DEFAULTS; + = INCLUDE_DEFAULTS; #else = @@ -526,8 +500,7 @@ static unsigned char is_space[256]; /* Initialize syntactic classifications of characters. */ static void -initialize_char_syntax(opts) - struct cpp_options *opts; +initialize_char_syntax(struct cpp_options *opts) { int i; @@ -546,32 +519,30 @@ initialize_char_syntax(opts) } for (i = '0'; i <= '9'; i++) is_idchar[i] = 1; - is_idchar['_'] = 1; - is_idstart['_'] = 1; - is_idchar['$'] = opts->dollars_in_ident; - is_idstart['$'] = opts->dollars_in_ident; + is_idchar[(unsigned char)'_'] = 1; + is_idstart[(unsigned char)'_'] = 1; + is_idchar[(unsigned char)'$'] = opts->dollars_in_ident; + is_idstart[(unsigned char)'$'] = opts->dollars_in_ident; /* horizontal space table */ - is_hor_space[' '] = 1; - is_hor_space['\t'] = 1; - is_hor_space['\v'] = 1; - is_hor_space['\f'] = 1; - is_hor_space['\r'] = 1; + is_hor_space[(unsigned char)' '] = 1; + is_hor_space[(unsigned char)'\t'] = 1; + is_hor_space[(unsigned char)'\v'] = 1; + is_hor_space[(unsigned char)'\f'] = 1; + is_hor_space[(unsigned char)'\r'] = 1; - is_space[' '] = 1; - is_space['\t'] = 1; - is_space['\v'] = 1; - is_space['\f'] = 1; - is_space['\n'] = 1; - is_space['\r'] = 1; + is_space[(unsigned char)' '] = 1; + is_space[(unsigned char)'\t'] = 1; + is_space[(unsigned char)'\v'] = 1; + is_space[(unsigned char)'\f'] = 1; + is_space[(unsigned char)'\n'] = 1; + is_space[(unsigned char)'\r'] = 1; } /* Place into PFILE a quoted string representing the string SRC. * Caller must reserve enough space in pfile->token_buffer. */ static void -quote_string(pfile, src) - cpp_reader *pfile; - char *src; +quote_string(cpp_reader * pfile, const char *src) { unsigned char c; @@ -605,9 +576,7 @@ quote_string(pfile, src) /* Make sure PFILE->token_buffer will hold at least N more chars. */ void -cpp_grow_buffer(pfile, n) - cpp_reader *pfile; - long n; +cpp_grow_buffer(cpp_reader * pfile, long n) { long old_written = CPP_WRITTEN(pfile); @@ -625,9 +594,7 @@ cpp_grow_buffer(pfile, n) */ void -cpp_define(pfile, str) - cpp_reader *pfile; - unsigned char *str; +cpp_define(cpp_reader * pfile, unsigned char *str) { unsigned char *buf, *p; @@ -642,7 +609,7 @@ cpp_define(pfile, str) if (*p == 0) { buf = (unsigned char *)alloca(p - buf + 4); - strcpy((char *)buf, str); + strcpy((char *)buf, (const char *)str); strcat((char *)buf, " 1"); } else if (*p != '=') @@ -656,7 +623,7 @@ cpp_define(pfile, str) /* Copy the entire option so we can modify it. */ buf = (unsigned char *)alloca(2 * strlen((char *)str) + 1); - strncpy(buf, str, p - str); + strncpy((char *)buf, (const char *)str, p - str); /* Change the = to a space. */ buf[p - str] = ' '; /* Scan for any backslash-newline and remove it. */ @@ -679,17 +646,14 @@ cpp_define(pfile, str) * OPTION is the option name for which STR was the argument. */ static void -make_assertion(pfile, option, str) - cpp_reader *pfile; - char *option; - unsigned char *str; +make_assertion(cpp_reader * pfile, const char *option, const char *str) { cpp_buffer *ip; unsigned char *buf, *p, *q; /* Copy the entire option so we can modify it. */ buf = (unsigned char *)alloca(strlen((char *)str) + 1); - strcpy((char *)buf, str); + strcpy((char *)buf, (const char *)str); /* Scan for any backslash-newline and remove it. */ p = q = buf; while (*p) @@ -722,9 +686,8 @@ make_assertion(pfile, option, str) * FIRST is the beginning of the chain to append, and LAST is the end. */ static void -append_include_chain(pfile, first, last) - cpp_reader *pfile; - struct file_name_list *first, *last; +append_include_chain(cpp_reader * pfile, struct file_name_list *first, + struct file_name_list *last) { struct cpp_options *opts = CPP_OPTIONS(pfile); struct file_name_list *dir; @@ -760,10 +723,7 @@ append_include_chain(pfile, first, last) * to be inserted literally. */ static void -deps_output(pfile, string, spacer) - cpp_reader *pfile; - char *string; - int spacer; +deps_output(cpp_reader * pfile, const char *string, int spacer) { int size = strlen(string); @@ -800,9 +760,7 @@ deps_output(pfile, string, spacer) * add all the names to the search path for include files. */ static void -path_include(pfile, path) - cpp_reader *pfile; - char *path; +path_include(cpp_reader * pfile, char *path) { char *p; @@ -834,7 +792,6 @@ path_include(pfile, path) } dirtmp = - (struct file_name_list *)xmalloc(sizeof(struct file_name_list)); dirtmp->next = 0; /* New one goes on the end */ @@ -854,8 +811,7 @@ path_include(pfile, path) } void -init_parse_options(opts) - struct cpp_options *opts; +init_parse_options(struct cpp_options *opts) { memset((char *)opts, 0, sizeof *opts); opts->in_fname = NULL; @@ -887,28 +843,23 @@ init_parse_options(opts) opts->warnings_are_errors = 0; } -enum cpp_token -null_underflow(pfile) - cpp_reader *pfile; +static enum cpp_token +null_underflow(cpp_reader * pfile) { pfile = NULL; return CPP_EOF; } -int -null_cleanup(pbuf, pfile) - cpp_buffer *pbuf; - cpp_reader *pfile; +static int +null_cleanup(cpp_buffer * pbuf, cpp_reader * pfile) { pbuf = NULL; pfile = NULL; return 0; } -int -macro_cleanup(pbuf, pfile) - cpp_buffer *pbuf; - cpp_reader *pfile; +static int +macro_cleanup(cpp_buffer * pbuf, cpp_reader * pfile) { HASHNODE *macro = (HASHNODE *) pbuf->data; @@ -920,10 +871,8 @@ macro_cleanup(pbuf, pfile) return 0; } -int -file_cleanup(pbuf, pfile) - cpp_buffer *pbuf; - cpp_reader *pfile; +static int +file_cleanup(cpp_buffer * pbuf, cpp_reader * pfile) { pfile = NULL; if (pbuf->buf) @@ -941,9 +890,7 @@ file_cleanup(pbuf, pfile) * If not the start of a comment, return '/'. */ static int -skip_comment(pfile, linep) - cpp_reader *pfile; - long *linep; +skip_comment(cpp_reader * pfile, long *linep) { int c = 0; @@ -1004,8 +951,7 @@ skip_comment(pfile, linep) /* Skip whitespace \-newline and comments. Does not macro-expand. */ void -cpp_skip_hspace(pfile) - cpp_reader *pfile; +cpp_skip_hspace(cpp_reader * pfile) { while (1) { @@ -1044,9 +990,8 @@ cpp_skip_hspace(pfile) /* Read the rest of the current line. * The line is appended to PFILE's output buffer. */ -void -copy_rest_of_line(pfile) - cpp_reader *pfile; +static void +copy_rest_of_line(cpp_reader * pfile) { struct cpp_options *opts = CPP_OPTIONS(pfile); @@ -1096,8 +1041,7 @@ copy_rest_of_line(pfile) } void -skip_rest_of_line(pfile) - cpp_reader *pfile; +skip_rest_of_line(cpp_reader * pfile) { long old = CPP_WRITTEN(pfile); @@ -1108,9 +1052,8 @@ skip_rest_of_line(pfile) /* Handle a possible # directive. * '#' has already been read. */ -int -handle_directive(pfile) - cpp_reader *pfile; +static int +handle_directive(cpp_reader * pfile) { int c; struct directive *kt; @@ -1127,7 +1070,7 @@ handle_directive(pfile) /* Handle # followed by a line number. */ if (CPP_PEDANTIC(pfile)) cpp_pedwarn(pfile, "`#' followed by integer"); - do_line(pfile, NULL); + do_line(pfile, NULL, NULL, NULL); goto done_a_directive; } /* Now find the directive name. */ @@ -1149,7 +1092,7 @@ handle_directive(pfile) if (kt->length <= 0) goto not_a_directive; if (kt->length == ident_length - && !strncmp(kt->name, ident, ident_length)) + && !strncmp(kt->name, (const char *)ident, ident_length)) break; } @@ -1158,10 +1101,8 @@ handle_directive(pfile) /* Nonzero means do not delete comments within the directive. * #define needs this when -traditional. */ int comments = CPP_TRADITIONAL(pfile) - && kt->traditional_comments; int save_put_out_comments = - CPP_OPTIONS(pfile)->put_out_comments; CPP_OPTIONS(pfile)->put_out_comments = comments; @@ -1215,10 +1156,8 @@ handle_directive(pfile) * KEYWORD is the keyword-table entry for the directive. */ static void -pass_thru_directive(buf, limit, pfile, keyword) - unsigned char *buf, *limit; - cpp_reader *pfile; - struct directive *keyword; +pass_thru_directive(char *buf, char *limit, cpp_reader * pfile, + struct directive *keyword) { unsigned keyword_length = keyword->length; @@ -1244,7 +1183,7 @@ pass_thru_directive(buf, limit, pfile, keyword) struct arglist { struct arglist *next; - unsigned char *name; + char *name; int length; int argno; char rest_args; @@ -1263,11 +1202,8 @@ struct arglist * have already been deleted from the argument. */ static DEFINITION * -collect_expansion(pfile, buf, limit, nargs, arglist) - cpp_reader *pfile; - unsigned char *buf, *limit; - int nargs; - struct arglist *arglist; +collect_expansion(cpp_reader * pfile, unsigned char *buf, unsigned char *limit, + int nargs, struct arglist *arglist) { DEFINITION *defn; unsigned char *p, *lastp, *exp_p; @@ -1462,7 +1398,8 @@ collect_expansion(pfile, buf, limit, nargs, arglist) if (arg->name[0] == c && arg->length == id_len - && strncmp(arg->name, id_beg, id_len) == 0) + && strncmp((const char *)arg->name, + (const char *)id_beg, id_len) == 0) { if (expected_delimiter && CPP_OPTIONS(pfile)->warn_stringify) @@ -1486,7 +1423,6 @@ collect_expansion(pfile, buf, limit, nargs, arglist) /* make a pat node for this arg and append it to the end of * the pat list */ tpat = - (struct reflist *) xmalloc(sizeof(struct reflist)); @@ -1573,34 +1509,19 @@ static char rest_extension[] = "..."; /* Create a DEFINITION node from a #define directive. Arguments are * as for do_define. */ static MACRODEF -create_definition(buf, limit, pfile, predefinition) - unsigned char *buf, *limit; - cpp_reader *pfile; - int predefinition; +create_definition(unsigned char *buf, unsigned char *limit, cpp_reader * pfile, + int predefinition) { unsigned char *bp; /* temp ptr into input buffer */ unsigned char *symname; /* remember where symbol name starts */ int sym_length; /* and how long it is */ int rest_args = 0; long line, col; - char *file = + const char *file = CPP_BUFFER(pfile) ? CPP_BUFFER(pfile)->nominal_fname : ""; DEFINITION *defn; int arglengths = 0; /* Accumulate lengths of arg names - - * - * * - * * * - * * * * - * * * * * - * * * * * * - * * * * * * * - * * * * * * * * - * * * * * * * * * - * * * * * * * * * * - * * * * * * * * * * * - * * * * * * * * * * * * - * * * * * * * * * * * * * plus number of args. */ + * plus number of args. */ MACRODEF mdef; cpp_buf_line_and_col(CPP_BUFFER(pfile), &line, &col); @@ -1634,7 +1555,7 @@ create_definition(buf, limit, pfile, predefinition) temp = (struct arglist *)alloca(sizeof(struct arglist)); - temp->name = bp; + temp->name = (char *)bp; temp->next = arg_ptrs; temp->argno = argno++; temp->rest_args = 0; @@ -1653,14 +1574,15 @@ create_definition(buf, limit, pfile, predefinition) bp++; /* do we have a "special" rest-args extension here? */ if ((unsigned)(limit - bp) > REST_EXTENSION_LENGTH && - strncmp(rest_extension, bp, REST_EXTENSION_LENGTH) == 0) + strncmp(rest_extension, (const char *)bp, + REST_EXTENSION_LENGTH) == 0) { rest_args = 1; temp->rest_args = 1; break; } } - temp->length = bp - temp->name; + temp->length = (char *)bp - temp->name; if (rest_args == 1) bp += REST_EXTENSION_LENGTH; arglengths += temp->length + 2; @@ -1686,12 +1608,13 @@ create_definition(buf, limit, pfile, predefinition) for (otemp = temp->next; otemp != NULL; otemp = otemp->next) if (temp->length == otemp->length && - strncmp(temp->name, otemp->name, temp->length) == 0) + strncmp((const char *)temp->name, + (const char *)otemp->name, temp->length) == 0) { - unsigned char *name; + char *name; - name = (unsigned char *)alloca(temp->length + 1); - (void)strncpy(name, temp->name, temp->length); + name = (char *)alloca(temp->length + 1); + strncpy(name, (const char *)temp->name, temp->length); name[temp->length] = '\0'; cpp_error(pfile, "duplicate argument name `%s' in `#define'", @@ -1784,7 +1707,7 @@ create_definition(buf, limit, pfile, predefinition) } } /* now everything from bp before limit is the definition. */ - defn = collect_expansion(pfile, bp, limit, -1, NULL_PTR); + defn = collect_expansion(pfile, bp, limit, -1, NULL); defn->args.argnames = (unsigned char *)""; } @@ -1794,7 +1717,7 @@ create_definition(buf, limit, pfile, predefinition) /* OP is null if this is a predefinition */ defn->predefined = predefinition; mdef.defn = defn; - mdef.symnam = symname; + mdef.symnam = (char *)symname; mdef.symlen = sym_length; return mdef; @@ -1808,10 +1731,7 @@ create_definition(buf, limit, pfile, predefinition) * USAGE is the kind of name this is intended for. */ static int -check_macro_name(pfile, symname, usage) - cpp_reader *pfile; - unsigned char *symname; - char *usage; +check_macro_name(cpp_reader * pfile, unsigned char *symname, const char *usage) { unsigned char *p; int sym_length; @@ -1833,7 +1753,7 @@ check_macro_name(pfile, symname, usage) } else { - if (!strncmp(symname, "defined", 7) && sym_length == 7) + if (!strncmp((const char *)symname, "defined", 7) && sym_length == 7) cpp_error(pfile, "invalid %s name `defined'", usage); } return sym_length; @@ -1843,8 +1763,7 @@ check_macro_name(pfile, symname, usage) * return zero if two DEFINITIONs are isomorphic */ static int -compare_defs(d1, d2) - DEFINITION *d1, *d2; +compare_defs(DEFINITION * d1, DEFINITION * d2) { struct reflist *a1, *a2; unsigned char *p1 = d1->expansion; @@ -1858,10 +1777,11 @@ compare_defs(d1, d2) for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2; a1 = a1->next, a2 = a2->next) { - if (!((a1->nchars == a2->nchars && !strncmp(p1, p2, a1->nchars)) - || !comp_def_part(first, p1, a1->nchars, p2, a2->nchars, 0)) - || a1->argno != a2->argno - || a1->stringify != a2->stringify + if (! + ((a1->nchars == a2->nchars + && !strncmp((const char *)p1, (const char *)p2, a1->nchars)) + || !comp_def_part(first, p1, a1->nchars, p2, a2->nchars, 0)) + || a1->argno != a2->argno || a1->stringify != a2->stringify || a1->raw_before != a2->raw_before || a1->raw_after != a2->raw_after) return 1; @@ -1887,11 +1807,8 @@ compare_defs(d1, d2) * so ignore trailing whitespace entirely. */ static int -comp_def_part(first, beg1, len1, beg2, len2, last) - int first; - unsigned char *beg1, *beg2; - int len1, len2; - int last; +comp_def_part(int first, unsigned char *beg1, int len1, + unsigned char *beg2, int len2, int last) { unsigned char *end1 = beg1 + len1; unsigned char *end2 = beg2 + len2; @@ -1937,10 +1854,8 @@ comp_def_part(first, beg1, len1, beg2, len2, last) * or NULL for a "predefined" macro. */ static int -do_define(pfile, keyword, buf, limit) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *buf, *limit; +do_define(cpp_reader * pfile, struct directive *keyword, + unsigned char *buf, unsigned char *limit) { int hashcode; MACRODEF mdef; @@ -1952,7 +1867,7 @@ do_define(pfile, keyword, buf, limit) hashcode = hashf(mdef.symnam, mdef.symlen, HASHSIZE); - if ((hp = cpp_lookup(pfile, mdef.symnam, mdef.symlen, hashcode)) != NULL) + if ((hp = cpp_lookup(mdef.symnam, mdef.symlen, hashcode)) != NULL) { int ok = 0; @@ -1968,22 +1883,23 @@ do_define(pfile, keyword, buf, limit) /* Print the warning if it's not ok. */ if (!ok) { - unsigned char *msg; /* what pain... */ + char *msg; /* what pain... */ /* If we are passing through #define and #undef directives, do * that for this re-definition now. */ if (CPP_OPTIONS(pfile)->debug_output && keyword) - pass_thru_directive(buf, limit, pfile, keyword); + pass_thru_directive((char *)buf, (char *)limit, pfile, keyword); - msg = (unsigned char *)alloca(mdef.symlen + 22); + msg = (char *)alloca(mdef.symlen + 22); *msg = '`'; memcpy(msg + 1, mdef.symnam, mdef.symlen); - strcpy((char *)(msg + mdef.symlen + 1), "' redefined"); + strcpy((msg + mdef.symlen + 1), "' redefined"); cpp_pedwarn(pfile, msg); if (hp->type == T_MACRO) cpp_pedwarn_with_file_and_line(pfile, hp->value.defn->file, hp->value.defn->line, - "this is the location of the previous definition"); + "this is the location of the previous definition", + NULL, NULL, NULL); } /* Replace the old definition. */ hp->type = T_MACRO; @@ -1994,7 +1910,7 @@ do_define(pfile, keyword, buf, limit) /* If we are passing through #define and #undef directives, do * that for this new definition now. */ if (CPP_OPTIONS(pfile)->debug_output && keyword) - pass_thru_directive(buf, limit, pfile, keyword); + pass_thru_directive((char *)buf, (char *)limit, pfile, keyword); install(mdef.symnam, mdef.symlen, T_MACRO, 0, (char *)mdef.defn, hashcode); } @@ -2030,16 +1946,13 @@ struct argdata }; cpp_buffer * -cpp_push_buffer(pfile, buffer, length) - cpp_reader *pfile; - unsigned char *buffer; - long length; +cpp_push_buffer(cpp_reader * pfile, unsigned char *buffer, long length) { #ifdef STATIC_BUFFERS cpp_buffer *buf = CPP_BUFFER(pfile); if (buf == pfile->buffer_stack) - fatal("macro or `#include' recursion too deep"); + cpp_fatal("macro or `#include' recursion too deep"); buf--; memset((char *)buf, 0, sizeof(cpp_buffer)); CPP_BUFFER(pfile) = buf; @@ -2059,9 +1972,8 @@ cpp_push_buffer(pfile, buffer, length) return buf; } -cpp_buffer * -cpp_pop_buffer(pfile) - cpp_reader *pfile; +static cpp_buffer * +cpp_pop_buffer(cpp_reader * pfile) { cpp_buffer *buf = CPP_BUFFER(pfile); @@ -2081,9 +1993,8 @@ cpp_pop_buffer(pfile) /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer. * Pop the buffer when done. */ -void -cpp_scan_buffer(pfile) - cpp_reader *pfile; +static void +cpp_scan_buffer(cpp_reader * pfile) { cpp_buffer *buffer = CPP_BUFFER(pfile); @@ -2111,10 +2022,7 @@ cpp_scan_buffer(pfile) */ static void -cpp_expand_to_buffer(pfile, buf, length) - cpp_reader *pfile; - unsigned char *buf; - int length; +cpp_expand_to_buffer(cpp_reader * pfile, unsigned char *buf, int length) { cpp_buffer *ip; unsigned char *limit = buf + length; @@ -2145,11 +2053,8 @@ cpp_expand_to_buffer(pfile, buf, length) } static void -adjust_position(buf, limit, linep, colp) - unsigned char *buf; - unsigned char *limit; - long *linep; - long *colp; +adjust_position(unsigned char *buf, unsigned char *limit, long *linep, + long *colp) { while (buf < limit) { @@ -2165,8 +2070,7 @@ adjust_position(buf, limit, linep, colp) /* Move line_base forward, updating lineno and colno. */ static void -update_position(pbuf) - cpp_buffer *pbuf; +update_position(cpp_buffer * pbuf) { unsigned char *old_pos = pbuf->buf + pbuf->line_base; unsigned char *new_pos = pbuf->cur; @@ -2182,9 +2086,7 @@ update_position(pbuf) } void -cpp_buf_line_and_col(pbuf, linep, colp) - cpp_buffer *pbuf; - long *linep, *colp; +cpp_buf_line_and_col(cpp_buffer * pbuf, long *linep, long *colp) { long dummy; @@ -2206,8 +2108,7 @@ cpp_buf_line_and_col(pbuf, linep, colp) /* Return the cpp_buffer that corresponds to a file (not a macro). */ cpp_buffer * -cpp_file_buffer(pfile) - cpp_reader *pfile; +cpp_file_buffer(cpp_reader * pfile) { cpp_buffer *ip = CPP_BUFFER(pfile); @@ -2218,9 +2119,7 @@ cpp_file_buffer(pfile) } static long -count_newlines(buf, limit) - unsigned char *buf; - unsigned char *limit; +count_newlines(unsigned char *buf, unsigned char *limit) { long count = 0; @@ -2243,10 +2142,8 @@ count_newlines(buf, limit) */ static void -output_line_command(pfile, conditional, file_change) - cpp_reader *pfile; - int conditional; - enum file_change_code file_change; +output_line_command(cpp_reader * pfile, int conditional, + enum file_change_code file_change) { long line, col; cpp_buffer *ip = CPP_BUFFER(pfile); @@ -2326,19 +2223,16 @@ output_line_command(pfile, conditional, file_change) */ static enum cpp_token -macarg(pfile, rest_args) - cpp_reader *pfile; - int rest_args; +macarg(cpp_reader * pfile, int rest_args) { int paren = 0; enum cpp_token token; char save_put_out_comments = - CPP_OPTIONS(pfile)->put_out_comments; CPP_OPTIONS(pfile)->put_out_comments = 0; - token = 0; + token = CPP_OTHER; /* Try to parse as much of the argument as exists at this * input stack level. */ pfile->no_macro_expand++; @@ -2389,9 +2283,7 @@ macarg(pfile, rest_args) * The string is copied into itself with its beginning staying fixed. */ static int -change_newlines(start, length) - unsigned char *start; - int length; +change_newlines(unsigned char *start, int length) { unsigned char *ibp; unsigned char *obp; @@ -2431,8 +2323,7 @@ change_newlines(start, length) } static struct tm * -timestamp(pfile) - cpp_reader *pfile; +timestamp(cpp_reader * pfile) { if (!pfile->timebuf) { @@ -2443,7 +2334,7 @@ timestamp(pfile) return pfile->timebuf; } -static char *monthnames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", +static const char *monthnames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", }; @@ -2453,11 +2344,10 @@ static char *monthnames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", */ static void -special_symbol(hp, pfile) - HASHNODE *hp; - cpp_reader *pfile; +special_symbol(HASHNODE * hp, cpp_reader * pfile) { - char *buf; + const char *buf; + char *bufx; int len; int true_indepth; cpp_buffer *ip = NULL; @@ -2481,7 +2371,7 @@ special_symbol(hp, pfile) case T_FILE: case T_BASE_FILE: { - char *string; + const char *string; if (hp->type == T_BASE_FILE) { @@ -2503,13 +2393,15 @@ special_symbol(hp, pfile) if (ip->fname != NULL) true_indepth++; - buf = (char *)alloca(8); /* Eight bytes ought to be more than enough */ - sprintf(buf, "%d", true_indepth - 1); + bufx = (char *)alloca(8); /* Eight bytes ought to be more than enough */ + sprintf(bufx, "%d", true_indepth - 1); + buf = bufx; break; case T_VERSION: - buf = (char *)alloca(3 + strlen(version_string)); - sprintf(buf, "\"%s\"", version_string); + bufx = (char *)alloca(3 + strlen(version_string)); + sprintf(bufx, "\"%s\"", version_string); + buf = bufx; break; #ifndef NO_BUILTIN_SIZE_TYPE @@ -2537,9 +2429,9 @@ special_symbol(hp, pfile) break; case T_CONST: - buf = (char *)alloca(4 * sizeof(int)); - - sprintf(buf, "%d", hp->value.ival); + bufx = (char *)alloca(4 * sizeof(int)); + sprintf(bufx, "%d", hp->value.ival); + buf = bufx; break; case T_SPECLINE: @@ -2549,21 +2441,23 @@ special_symbol(hp, pfile) adjust_position(CPP_LINE_BASE(ip), ip->cur, &line, &col); - buf = (char *)alloca(10); - sprintf(buf, "%d", (int)line); + bufx = (char *)alloca(10); + sprintf(bufx, "%d", (int)line); + buf = bufx; } break; case T_DATE: case T_TIME: - buf = (char *)alloca(20); + bufx = (char *)alloca(20); timebuf = timestamp(pfile); if (hp->type == T_DATE) - sprintf(buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon], + sprintf(bufx, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon], timebuf->tm_mday, timebuf->tm_year + 1900); else - sprintf(buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min, - timebuf->tm_sec); + sprintf(bufx, "\"%02d:%02d:%02d\"", timebuf->tm_hour, + timebuf->tm_min, timebuf->tm_sec); + buf = bufx; break; case T_SPEC_DEFINED: @@ -2578,7 +2472,7 @@ special_symbol(hp, pfile) } if (!is_idstart[*ip->cur]) goto oops; - if ((hp = cpp_lookup(pfile, ip->cur, -1, -1))) + if ((hp = cpp_lookup((const char *)ip->cur, -1, -1))) { buf = " 1 "; } @@ -2613,8 +2507,7 @@ special_symbol(hp, pfile) /* Initialize the built-in macros. */ static void -initialize_builtins(pfile) - cpp_reader *pfile; +initialize_builtins(cpp_reader * pfile) { install("__LINE__", -1, T_SPECLINE, 0, 0, -1); install("__DATE__", -1, T_DATE, 0, 0, -1); @@ -2712,8 +2605,7 @@ initialize_builtins(pfile) * could cause mis-tokenization. */ static int -unsafe_chars(c1, c2) - int c1, c2; +unsafe_chars(int c1, int c2) { switch (c1) { @@ -2821,9 +2713,7 @@ unsafe_chars(c1, c2) * an argument list follows; arguments come from the input stack. */ static void -macroexpand(pfile, hp) - cpp_reader *pfile; - HASHNODE *hp; +macroexpand(cpp_reader * pfile, HASHNODE * hp) { int nargs; DEFINITION *defn = hp->value.defn; @@ -2847,7 +2737,7 @@ macroexpand(pfile, hp) { enum cpp_token token; - token = 0; + token = CPP_OTHER; args = (struct argdata *)alloca((nargs + 1) * sizeof(struct argdata)); @@ -2945,20 +2835,7 @@ macroexpand(pfile, hp) { unsigned char *exp = defn->expansion; int offset; /* offset in expansion, - - * - * * - * * * - * * * * - * * * * * - * * * * * * - * * * * * * * - * * * * * * * * - * * * * * * * * * - * * * * * * * * * * - * * * * * * * * * * * - * * * * * * * * * * * * - * * * * * * * * * * * * * copied a piece at a time */ + * copied a piece at a time */ int totlen; /* total amount of exp buffer filled so far */ struct reflist *ap, *last_ap; @@ -3234,11 +3111,8 @@ macroexpand(pfile, hp) } static void -push_macro_expansion(pfile, xbuf, xbuf_len, hp) - cpp_reader *pfile; - unsigned char *xbuf; - int xbuf_len; - HASHNODE *hp; +push_macro_expansion(cpp_reader * pfile, unsigned char *xbuf, int xbuf_len, + HASHNODE * hp) { cpp_buffer *mbuf = cpp_push_buffer(pfile, xbuf, xbuf_len); @@ -3273,8 +3147,7 @@ push_macro_expansion(pfile, xbuf, xbuf_len, hp) * Also, horizontal space is skipped, and macros are popped. */ static enum cpp_token -get_directive_token(pfile) - cpp_reader *pfile; +get_directive_token(cpp_reader * pfile) { for (;;) { @@ -3310,10 +3183,8 @@ get_directive_token(pfile) * This is safe. */ static int -do_include(pfile, keyword, unused1, unused2) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *unused1, *unused2; +do_include(cpp_reader * pfile, struct directive *keyword, + unsigned char *unused1, unsigned char *unused2) { int importing = (keyword->type == T_IMPORT); int skip_dirs = (keyword->type == T_INCLUDE_NEXT); @@ -3388,7 +3259,7 @@ do_include(pfile, keyword, unused1, unused2) for (fp = CPP_BUFFER(pfile); fp != NULL; fp = CPP_PREV_BUFFER(fp)) { int n; - char *ep, *nam; + const char *ep, *nam; if ((nam = fp->nominal_fname) != NULL) { @@ -3397,13 +3268,13 @@ do_include(pfile, keyword, unused1, unused2) dsp[0].next = search_start; search_start = dsp; #ifndef VMS - ep = rindex(nam, '/'); + ep = strrchr(nam, '/'); #else /* VMS */ - ep = rindex(nam, ']'); + ep = strrchr(nam, ']'); if (ep == NULL) - ep = rindex(nam, '>'); + ep = strrchr(nam, '>'); if (ep == NULL) - ep = rindex(nam, ':'); + ep = strrchr(nam, ':'); if (ep != NULL) ep++; #endif /* VMS */ @@ -3485,14 +3356,14 @@ do_include(pfile, keyword, unused1, unused2) if (_fnisabs(fbeg)) #endif { - strncpy(fname, fbeg, flen); + strncpy(fname, (const char *)fbeg, flen); fname[flen] = 0; if (redundant_include_p(pfile, fname)) return 0; if (importing) - f = lookup_import(pfile, fname, NULL_PTR); + f = lookup_import(pfile, fname, NULL); else - f = open_include_file(pfile, fname, NULL_PTR); + f = open_include_file(pfile, fname, NULL); if (f == -2) return 0; /* Already included this file */ } @@ -3518,7 +3389,7 @@ do_include(pfile, keyword, unused1, unused2) { fname[0] = 0; } - strncat(fname, fbeg, flen); + strncat(fname, (const char *)fbeg, flen); #ifdef VMS /* Change this 1/2 Unix 1/2 VMS file specification into a * full VMS file specification */ @@ -3533,7 +3404,7 @@ do_include(pfile, keyword, unused1, unused2) strncpy(fname, fbeg, flen); fname[flen] = 0; /* if it's '#include filename', add the missing .h */ - if (index(fname, '.') == NULL) + if (strchr(fname, '.') == NULL) { strcat(fname, ".h"); } @@ -3563,7 +3434,7 @@ do_include(pfile, keyword, unused1, unused2) if (f < 0) { /* A file that was not found. */ - strncpy(fname, fbeg, flen); + strncpy(fname, (const char *)fbeg, flen); fname[flen] = 0; /* If generating dependencies and -MG was specified, we assume missing * files are leaf files, living in the same directory as the source file @@ -3646,7 +3517,6 @@ do_include(pfile, keyword, unused1, unused2) /* Add it to list of files included. */ ptr = - (struct file_name_list *)xmalloc(sizeof(struct file_name_list)); ptr->control_macro = 0; @@ -3701,15 +3571,14 @@ do_include(pfile, keyword, unused1, unused2) * to make a repeated include do nothing. */ static int -redundant_include_p(pfile, name) - cpp_reader *pfile; - char *name; +redundant_include_p(cpp_reader * pfile, char *name) { struct file_name_list *l = pfile->all_include_files; for (; l; l = l->next) if (!strcmp(name, l->fname) - && l->control_macro && cpp_lookup(pfile, l->control_macro, -1, -1)) + && l->control_macro + && cpp_lookup((const char *)l->control_macro, -1, -1)) return 1; return 0; } @@ -3726,9 +3595,7 @@ redundant_include_p(pfile, name) * for which C++ should (on most systems) assume `extern "C"'. */ static int -is_system_include(pfile, filename) - cpp_reader *pfile; - char *filename; +is_system_include(cpp_reader * pfile, char *filename) { struct file_name_list *searchptr; @@ -3760,15 +3627,10 @@ is_system_include(pfile, filename) * Otherwise, compute the hash code. */ static ASSERTION_HASHNODE * -assertion_install(pfile, name, len, hash) - cpp_reader *pfile; - unsigned char *name; - int len; - int hash; +assertion_install(cpp_reader * pfile, const char *name, int len, int hash) { ASSERTION_HASHNODE *hp; int i, bucket; - unsigned char *p, *q; i = sizeof(ASSERTION_HASHNODE) + len + 1; hp = (ASSERTION_HASHNODE *) xmalloc(i); @@ -3781,11 +3643,8 @@ assertion_install(pfile, name, len, hash) hp->next->prev = hp; hp->length = len; hp->value = 0; - hp->name = ((unsigned char *)hp) + sizeof(ASSERTION_HASHNODE); - p = hp->name; - q = name; - for (i = 0; i < len; i++) - *p++ = *q++; + hp->name = ((char *)hp) + sizeof(ASSERTION_HASHNODE); + memcpy(hp->name, name, len); hp->name[len] = 0; return hp; } @@ -3801,11 +3660,7 @@ assertion_install(pfile, name, len, hash) */ static ASSERTION_HASHNODE * -assertion_lookup(pfile, name, len, hash) - cpp_reader *pfile; - unsigned char *name; - int len; - int hash; +assertion_lookup(cpp_reader * pfile, const char *name, int len, int hash) { ASSERTION_HASHNODE *bucket; @@ -3820,8 +3675,7 @@ assertion_lookup(pfile, name, len, hash) } static void -delete_assertion(hp) - ASSERTION_HASHNODE *hp; +delete_assertion(ASSERTION_HASHNODE * hp) { struct tokenlist_list *tail; @@ -3853,11 +3707,9 @@ delete_assertion(hp) * The value returned in the end of the string written to RESULT, * or NULL on error. */ -static unsigned char * -convert_string(pfile, result, in, limit, handle_escapes) - cpp_reader *pfile; - unsigned char *result, *in, *limit; - int handle_escapes; +static char * +convert_string(cpp_reader * pfile, char *result, char *in, char *limit, + int handle_escapes) { unsigned char c; @@ -3866,7 +3718,7 @@ convert_string(pfile, result, in, limit, handle_escapes) return NULL; while (in < limit) { - unsigned char c = *in++; + c = *in++; switch (c) { @@ -3878,12 +3730,11 @@ convert_string(pfile, result, in, limit, handle_escapes) case '\\': if (handle_escapes) { - char *bpc = (char *)in; + char *bpc = in; int i = - (unsigned char)cpp_parse_escape(pfile, &bpc); - in = (unsigned char *)bpc; + in = bpc; if (i >= 0) *result++ = (unsigned char)c; break; @@ -3904,9 +3755,8 @@ convert_string(pfile, result, in, limit, handle_escapes) #define FNAME_HASHSIZE 37 static int -do_line(pfile, keyword) - cpp_reader *pfile; - struct directive *keyword; +do_line(cpp_reader * pfile, struct directive *keyword, + unsigned char *unused1, unsigned char *unused2) { cpp_buffer *ip = CPP_BUFFER(pfile); int new_lineno; @@ -3917,6 +3767,8 @@ do_line(pfile, keyword) token = get_directive_token(pfile); keyword = NULL; + unused1 = unused2 = NULL; + if (token != CPP_NUMBER || !isdigit(pfile->token_buffer[old_written])) { cpp_error(pfile, "invalid format `#line' command"); @@ -3936,8 +3788,8 @@ do_line(pfile, keyword) if (token == CPP_STRING) { - unsigned char *fname = pfile->token_buffer + old_written; - unsigned char *end_name; + char *fname = (char *)pfile->token_buffer + old_written; + char *end_name; static HASHNODE *fname_table[FNAME_HASHSIZE]; HASHNODE *hp, **hash_bucket; unsigned char *p; @@ -3946,7 +3798,8 @@ do_line(pfile, keyword) /* Turn the file name, which is a character string literal, * into a null-terminated string. Do this in place. */ - end_name = convert_string(pfile, fname, fname, CPP_PWRITTEN(pfile), 1); + end_name = + convert_string(pfile, fname, fname, (char *)CPP_PWRITTEN(pfile), 1); if (end_name == NULL) { cpp_error(pfile, "invalid format `#line' command"); @@ -4032,10 +3885,8 @@ do_line(pfile, keyword) */ static int -do_undef(pfile, keyword, buf, limit) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *buf, *limit; +do_undef(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, + unsigned char *limit) { int sym_length; HASHNODE *hp; @@ -4044,12 +3895,12 @@ do_undef(pfile, keyword, buf, limit) SKIP_WHITE_SPACE(buf); sym_length = check_macro_name(pfile, buf, "macro"); - while ((hp = cpp_lookup(pfile, buf, sym_length, -1)) != NULL) + while ((hp = cpp_lookup((const char *)buf, sym_length, -1)) != NULL) { /* If we are generating additional info for debugging (with -g) we * need to pass through all effective #undef commands. */ if (CPP_OPTIONS(pfile)->debug_output && keyword) - pass_thru_directive(orig_buf, limit, pfile, keyword); + pass_thru_directive((char *)orig_buf, (char *)limit, pfile, keyword); if (hp->type != T_MACRO) cpp_warning(pfile, "undefining `%s'", hp->name); delete_macro(hp); @@ -4072,10 +3923,8 @@ do_undef(pfile, keyword, buf, limit) */ static int -do_error(pfile, keyword, buf, limit) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *buf, *limit; +do_error(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, + unsigned char *limit) { int length = limit - buf; unsigned char *copy = (unsigned char *)xmalloc(length + 1); @@ -4095,10 +3944,8 @@ do_error(pfile, keyword, buf, limit) */ static int -do_warning(pfile, keyword, buf, limit) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *buf, *limit; +do_warning(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, + unsigned char *limit) { int length = limit - buf; unsigned char *copy = (unsigned char *)xmalloc(length + 1); @@ -4115,11 +3962,10 @@ do_warning(pfile, keyword, buf, limit) * avoid ever including it again. */ static int -do_once(pfile) - cpp_reader *pfile; +do_once(cpp_reader * pfile) { cpp_buffer *ip = NULL; - struct file_name_list *new; + struct file_name_list *new_; for (ip = CPP_BUFFER(pfile);; ip = CPP_PREV_BUFFER(ip)) { @@ -4129,14 +3975,14 @@ do_once(pfile) break; } - new = (struct file_name_list *)xmalloc(sizeof(struct file_name_list)); + new_ = (struct file_name_list *)xmalloc(sizeof(struct file_name_list)); - new->next = pfile->dont_repeat_files; - pfile->dont_repeat_files = new; - new->fname = savestring(ip->fname); - new->control_macro = 0; - new->got_name_map = 0; - new->c_system_include_path = 0; + new_->next = pfile->dont_repeat_files; + pfile->dont_repeat_files = new_; + new_->fname = savestring(ip->fname); + new_->control_macro = 0; + new_->got_name_map = 0; + new_->c_system_include_path = 0; return 0; } @@ -4144,10 +3990,8 @@ do_once(pfile) /* #ident has already been copied to the output file, so just ignore it. */ static int -do_ident(pfile, keyword, buf, limit) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *buf, *limit; +do_ident(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, + unsigned char *limit) { /* long old_written = CPP_WRITTEN (pfile); */ @@ -4167,17 +4011,15 @@ do_ident(pfile, keyword, buf, limit) * Just check for some recognized pragmas that need validation here. */ static int -do_pragma(pfile, keyword, buf, limit) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *buf, *limit; +do_pragma(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, + unsigned char *limit) { while (*buf == ' ' || *buf == '\t') buf++; keyword = NULL; limit = NULL; - if (!strncmp(buf, "once", 4)) + if (!strncmp((const char *)buf, "once", 4)) { /* Allow #pragma once in system headers, since that's not the user's * fault. */ @@ -4185,12 +4027,12 @@ do_pragma(pfile, keyword, buf, limit) cpp_warning(pfile, "`#pragma once' is obsolete"); do_once(pfile); } - if (!strncmp(buf, "implementation", 14)) + if (!strncmp((const char *)buf, "implementation", 14)) { /* Be quiet about `#pragma implementation' for a file only if it hasn't * been included yet. */ struct file_name_list *ptr; - unsigned char *p = buf + 14, *fname, *inc_fname; + char *p = (char *)buf + 14, *fname, *inc_fname; int fname_len; SKIP_WHITE_SPACE(p); @@ -4198,14 +4040,15 @@ do_pragma(pfile, keyword, buf, limit) return 0; fname = p + 1; - p = (unsigned char *)index(fname, '\"'); - fname_len = (int) (((int) (p != NULL)) ? ((int) (p - fname)) : ((int) (strlen((char *)fname)))); + p = strchr(fname, '\"'); + fname_len = + (int)(((int)(p != NULL)) ? ((int)(p - fname)) + : ((int)(strlen(fname)))); for (ptr = pfile->all_include_files; ptr; ptr = ptr->next) { - inc_fname = (unsigned char *)rindex(ptr->fname, '/'); - inc_fname = - inc_fname ? inc_fname + 1 : (unsigned char *)ptr->fname; + inc_fname = strrchr(ptr->fname, '/'); + inc_fname = inc_fname ? inc_fname + 1 : (char *)ptr->fname; if (inc_fname && !strncmp(inc_fname, fname, fname_len)) cpp_warning(pfile, "`#pragma implementation' for `%s' appears after file is included", @@ -4231,15 +4074,13 @@ do_pragma(pfile, keyword, buf, limit) */ static int -do_if(pfile, keyword, buf, limit) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *buf, *limit; +do_if(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, + unsigned char *limit) { HOST_WIDE_INT value = eval_if_expression(pfile, buf, limit - buf); keyword = NULL; - conditional_skip(pfile, value == 0, T_IF, NULL_PTR); + conditional_skip(pfile, value == 0, T_IF, NULL); return 0; } @@ -4249,10 +4090,8 @@ do_if(pfile, keyword, buf, limit) */ static int -do_elif(pfile, keyword, buf, limit) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *buf, *limit; +do_elif(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, + unsigned char *limit) { keyword = NULL; @@ -4299,10 +4138,7 @@ do_elif(pfile, keyword, buf, limit) * then parse the result as a C expression and return the value as an int. */ static HOST_WIDE_INT -eval_if_expression(pfile, buf, length) - cpp_reader *pfile; - unsigned char *buf; - int length; +eval_if_expression(cpp_reader * pfile, unsigned char *buf, int length) { HASHNODE *save_defined; HOST_WIDE_INT value; @@ -4329,14 +4165,12 @@ eval_if_expression(pfile, buf, length) */ static int -do_xifdef(pfile, keyword, unused1, unused2) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *unused1, *unused2; +do_xifdef(cpp_reader * pfile, struct directive *keyword, unsigned char *unused1, + unsigned char *unused2) { int skip; cpp_buffer *ip = CPP_BUFFER(pfile); - unsigned char *ident; + char *ident; int ident_length; enum cpp_token token; int start_of_file = 0; @@ -4353,7 +4187,7 @@ do_xifdef(pfile, keyword, unused1, unused2) token = get_directive_token(pfile); pfile->no_macro_expand--; - ident = pfile->token_buffer + old_written; + ident = (char *)pfile->token_buffer + old_written; ident_length = CPP_WRITTEN(pfile) - old_written; CPP_SET_WRITTEN(pfile, old_written); /* Pop */ @@ -4365,7 +4199,7 @@ do_xifdef(pfile, keyword, unused1, unused2) } else if (token == CPP_NAME) { - HASHNODE *hp = cpp_lookup(pfile, ident, ident_length, -1); + HASHNODE *hp = cpp_lookup(ident, ident_length, -1); skip = (hp == NULL) ^ (keyword->type == T_IFNDEF); if (start_of_file && !skip) @@ -4403,12 +4237,8 @@ do_xifdef(pfile, keyword, unused1, unused2) * Otherwise, CONTROL_MACRO is 0. */ static void -conditional_skip(pfile, skip, type, control_macro) - cpp_reader *pfile; - int skip; - enum node_type type; - unsigned char *control_macro; - +conditional_skip(cpp_reader * pfile, int skip, enum node_type type, + unsigned char *control_macro) { IF_STACK_FRAME *temp; @@ -4439,17 +4269,14 @@ conditional_skip(pfile, skip, type, control_macro) */ static void -skip_if_group(pfile, any) - cpp_reader *pfile; - int any; - +skip_if_group(cpp_reader * pfile, int any) { int c; struct directive *kt; IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */ int ident_length; - unsigned char *ident; + char *ident; struct parse_marker line_start_mark; parse_set_mark(&line_start_mark, pfile); @@ -4482,8 +4309,8 @@ skip_if_group(pfile, any) parse_name(pfile, GETC()); ident_length = CPP_WRITTEN(pfile) - old_written; - ident = pfile->token_buffer + old_written; - pfile->limit = ident; + ident = (char *)pfile->token_buffer + old_written; + pfile->limit = (unsigned char *)ident; for (kt = directive_table; kt->length >= 0; kt++) { @@ -4603,11 +4430,8 @@ skip_if_group(pfile, any) */ static int -do_else(pfile, keyword, buf, limit) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *buf, *limit; - +do_else(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, + unsigned char *limit) { cpp_buffer *ip = CPP_BUFFER(pfile); @@ -4656,11 +4480,8 @@ do_else(pfile, keyword, buf, limit) */ static int -do_endif(pfile, keyword, buf, limit) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *buf, *limit; - +do_endif(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, + unsigned char *limit) { if (CPP_PEDANTIC(pfile)) validate_else(pfile, "#endif"); @@ -4732,10 +4553,7 @@ do_endif(pfile, keyword, buf, limit) * the command name. P points to the first char after the command name. */ static void -validate_else(pfile, directive) - cpp_reader *pfile; - char *directive; - +validate_else(cpp_reader * pfile, const char *directive) { int c; @@ -4750,9 +4568,7 @@ validate_else(pfile, directive) * Return the kind of token we got. */ enum cpp_token -cpp_get_token(pfile) - cpp_reader *pfile; - +cpp_get_token(cpp_reader * pfile) { int c, c2, c3; long old_written = 0; @@ -5246,7 +5062,7 @@ cpp_get_token(pfile) letter: { HASHNODE *hp; - unsigned char *ident; + char *ident; int before_name_written = CPP_WRITTEN(pfile); int ident_len; @@ -5254,9 +5070,9 @@ cpp_get_token(pfile) pfile->only_seen_white = 0; if (pfile->no_macro_expand) return CPP_NAME; - ident = pfile->token_buffer + before_name_written; - ident_len = CPP_PWRITTEN(pfile) - ident; - hp = cpp_lookup(pfile, ident, ident_len, -1); + ident = (char *)pfile->token_buffer + before_name_written; + ident_len = CPP_PWRITTEN(pfile) - (unsigned char *)ident; + hp = cpp_lookup(ident, ident_len, -1); if (!hp) return CPP_NAME; if (hp->type == T_DISABLED) @@ -5266,7 +5082,8 @@ cpp_get_token(pfile) int i; CPP_RESERVE(pfile, 3); - ident = pfile->token_buffer + before_name_written; + ident = + (char *)pfile->token_buffer + before_name_written; CPP_ADJUST_WRITTEN(pfile, 2); for (i = ident_len; i >= 0; i--) ident[i + 2] = ident[i]; @@ -5292,7 +5109,8 @@ cpp_get_token(pfile) if (PEEKC() != EOF) break; next_buf = CPP_PREV_BUFFER(CPP_BUFFER(pfile)); - (*CPP_BUFFER(pfile)->cleanup) (CPP_BUFFER(pfile), pfile); + (*CPP_BUFFER(pfile)->cleanup) (CPP_BUFFER(pfile), + pfile); CPP_BUFFER(pfile) = next_buf; } parse_set_mark(¯o_mark, pfile); @@ -5344,8 +5162,8 @@ cpp_get_token(pfile) && pfile->buffer->rlimit[-1] == ' ') { int c1 = pfile->buffer->rlimit[-3]; - int c2 = - CPP_BUF_PEEK(CPP_PREV_BUFFER(CPP_BUFFER(pfile))); + + c2 = CPP_BUF_PEEK(CPP_PREV_BUFFER(CPP_BUFFER(pfile))); if (c2 == EOF || !unsafe_chars(c1, c2)) pfile->buffer->rlimit -= 2; @@ -5412,11 +5230,10 @@ cpp_get_token(pfile) } } +#if 0 /* Unused */ /* Like cpp_get_token, but skip spaces and comments. */ enum cpp_token -cpp_get_non_space_token(pfile) - cpp_reader *pfile; - +cpp_get_non_space_token(cpp_reader * pfile) { int old_written = CPP_WRITTEN(pfile); @@ -5430,14 +5247,12 @@ cpp_get_non_space_token(pfile) CPP_SET_WRITTEN(pfile, old_written); } } +#endif /* Parse an identifier starting with C. */ int -parse_name(pfile, c) - cpp_reader *pfile; - int c; - +parse_name(cpp_reader * pfile, int c) { for (;;) { @@ -5466,9 +5281,7 @@ parse_name(pfile, c) /* Hash a file name for import_hash_table. */ static int -import_hash(f) - char *f; - +import_hash(char *f) { int val = 0; @@ -5483,11 +5296,8 @@ import_hash(f) * or -1 if unsuccessful. */ static int -lookup_import(pfile, filename, searchptr) - cpp_reader *pfile; - char *filename; - struct file_name_list *searchptr; - +lookup_import(cpp_reader * pfile, char *filename, + struct file_name_list *searchptr) { struct import_file *i; int h; @@ -5534,11 +5344,7 @@ lookup_import(pfile, filename, searchptr) /* Add the file FNAME, open on descriptor FD, to import_hash_table. */ static void -add_import(pfile, fd, fname) - cpp_reader *pfile; - int fd; - char *fname; - +add_import(cpp_reader * pfile, int fd, char *fname) { struct import_file *i; int hashval; @@ -5577,16 +5383,13 @@ struct file_name_map * file. */ static char * -read_filename_string(ch, f) - int ch; - FILE *f; - +read_filename_string(int ch, FILE * f) { char *alloc, *set; int len; len = 20; - set = alloc = xmalloc(len + 1); + set = alloc = (char *)xmalloc(len + 1); if (!is_space[ch]) { *set++ = ch; @@ -5595,7 +5398,7 @@ read_filename_string(ch, f) if (set - alloc == len) { len *= 2; - alloc = xrealloc(alloc, len + 1); + alloc = (char *)xrealloc(alloc, len + 1); set = alloc + len / 2; } *set++ = ch; @@ -5617,10 +5420,7 @@ struct file_name_map_list /* Read the file name map file for DIRNAME. */ static struct file_name_map * -read_name_map(pfile, dirname) - cpp_reader *pfile; - char *dirname; - +read_name_map(cpp_reader * pfile, const char *dirname) { struct file_name_map_list *map_list_ptr; char *name; @@ -5632,7 +5432,6 @@ read_name_map(pfile, dirname) return map_list_ptr->map_list_map; map_list_ptr = - ((struct file_name_map_list *)xmalloc(sizeof(struct file_name_map_list))); map_list_ptr->map_list_name = savestring(dirname); @@ -5667,7 +5466,6 @@ read_name_map(pfile, dirname) to = read_filename_string(ch, f); ptr = - ((struct file_name_map *)xmalloc(sizeof(struct file_name_map))); ptr->map_from = from; @@ -5677,7 +5475,7 @@ read_name_map(pfile, dirname) ptr->map_to = to; else { - ptr->map_to = xmalloc(dirlen + strlen(to) + 2); + ptr->map_to = (char *)xmalloc(dirlen + strlen(to) + 2); strcpy(ptr->map_to, dirname); ptr->map_to[dirlen] = '/'; strcpy(ptr->map_to + dirlen + 1, to); @@ -5706,15 +5504,12 @@ read_name_map(pfile, dirname) * read_name_map. */ static int -open_include_file(pfile, filename, searchptr) - cpp_reader *pfile; - char *filename; - struct file_name_list *searchptr; - +open_include_file(cpp_reader * pfile, char *filename, + struct file_name_list *searchptr) { struct file_name_map *map; - char *from; - char *p, *dir; + const char *from; + const char *p, *dir; if (searchptr && !searchptr->got_name_map) { @@ -5742,7 +5537,7 @@ open_include_file(pfile, filename, searchptr) * looking in. Thus #include will look up sys/types.h * in /usr/include/header.gcc and look up types.h in * /usr/include/sys/header.gcc. */ - p = rindex(filename, '/'); + p = strrchr(filename, '/'); if (!p) p = filename; if (searchptr @@ -5760,10 +5555,13 @@ open_include_file(pfile, filename, searchptr) } else { - dir = (char *)alloca(p - filename + 1); - memcpy(dir, filename, p - filename); - dir[p - filename] = '\0'; + char *s; + + s = (char *)alloca(p - filename + 1); + memcpy(s, filename, p - filename); + s[p - filename] = '\0'; from = p + 1; + dir = s; } for (map = read_name_map(pfile, dir); map; map = map->map_next) if (!strcmp(map->map_from, from)) @@ -5784,13 +5582,8 @@ open_include_file(pfile, filename, searchptr) * The caller is responsible for the cpp_push_buffer. */ static int -finclude(pfile, f, fname, system_header_p, dirptr) - cpp_reader *pfile; - int f; - char *fname; - int system_header_p; - struct file_name_list *dirptr; - +finclude(cpp_reader * pfile, int f, const char *fname, int system_header_p, + struct file_name_list *dirptr) { int st_mode; long st_size; @@ -5885,10 +5678,7 @@ finclude(pfile, f, fname, system_header_p, dirptr) } int -push_parse_file(pfile, fname) - cpp_reader *pfile; - char *fname; - +push_parse_file(cpp_reader * pfile, const char *fname) { struct cpp_options *opts = CPP_OPTIONS(pfile); struct cpp_pending *pend; @@ -5931,7 +5721,7 @@ push_parse_file(pfile, fname) if (!opts->inhibit_predefs) { - char *p = (char *)alloca(strlen(predefs) + 1); + p = (char *)alloca(strlen(predefs) + 1); strcpy(p, predefs); while (*p) @@ -6041,7 +5831,7 @@ push_parse_file(pfile, fname) opts->done_initializing = 1; { /* read the appropriate environment variable and if it exists - * * * replace include_defaults with the listed path. */ + * replace include_defaults with the listed path. */ char *epath = 0; switch ((opts->objc << 1) + opts->cplusplus) @@ -6075,7 +5865,6 @@ push_parse_file(pfile, fname) * sizeof(struct default_include)) + - sizeof (include_defaults_array)); @@ -6117,7 +5906,7 @@ push_parse_file(pfile, fname) * tack on the standard include file dirs to the specified list */ if (!opts->no_standard_includes) { - struct default_include *p = include_defaults; + struct default_include *di = include_defaults; char *specd_prefix = opts->include_prefix; char *default_prefix = savestring(GCC_INCLUDE_DIR); int default_len = 0; @@ -6131,62 +5920,57 @@ push_parse_file(pfile, fname) /* Search "translated" versions of GNU directories. * These have /usr/local/lib/gcc... replaced by specd_prefix. */ if (specd_prefix != 0 && default_len != 0) - for (p = include_defaults; p->fname; p++) + for (di = include_defaults; di->fname; di++) { /* Some standard dirs are only for C++. */ - if (!p->cplusplus + if (!di->cplusplus || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) { /* Does this dir start with the prefix? */ - if (!strncmp(p->fname, default_prefix, default_len)) + if (!strncmp(di->fname, default_prefix, default_len)) { /* Yes; change prefix and add to search list. */ - struct file_name_list *new + struct file_name_list *new_ = - (struct file_name_list *) xmalloc(sizeof(struct file_name_list)); int this_len = - strlen(specd_prefix) + strlen(p->fname) - - + strlen(specd_prefix) + strlen(di->fname) - default_len; char *str = - (char *)xmalloc(this_len + 1); strcpy(str, specd_prefix); - strcat(str, p->fname + default_len); - new->fname = str; - new->control_macro = 0; - new->c_system_include_path = !p->cxx_aware; - new->got_name_map = 0; - append_include_chain(pfile, new, new); + strcat(str, di->fname + default_len); + new_->fname = str; + new_->control_macro = 0; + new_->c_system_include_path = !di->cxx_aware; + new_->got_name_map = 0; + append_include_chain(pfile, new_, new_); if (opts->first_system_include == 0) - opts->first_system_include = new; + opts->first_system_include = new_; } } } /* Search ordinary names for GNU include directories. */ - for (p = include_defaults; p->fname; p++) + for (di = include_defaults; di->fname; di++) { /* Some standard dirs are only for C++. */ - if (!p->cplusplus + if (!di->cplusplus || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) { - struct file_name_list *new - = - - (struct file_name_list *) + struct file_name_list *new_ + = (struct file_name_list *) xmalloc(sizeof(struct file_name_list)); - new->control_macro = 0; - new->c_system_include_path = !p->cxx_aware; - new->fname = p->fname; - new->got_name_map = 0; - append_include_chain(pfile, new, new); + new_->control_macro = 0; + new_->c_system_include_path = !di->cxx_aware; + new_->fname = (char *)di->fname; + new_->got_name_map = 0; + append_include_chain(pfile, new_, new_); if (opts->first_system_include == 0) - opts->first_system_include = new; + opts->first_system_include = new_; } } } @@ -6198,14 +5982,14 @@ push_parse_file(pfile, fname) /* With -v, print the list of dirs to search. */ if (opts->verbose) { - struct file_name_list *p; + struct file_name_list *fl; fprintf(stderr, "#include \"...\" search starts here:\n"); - for (p = opts->include; p; p = p->next) + for (fl = opts->include; fl; fl = fl->next) { - if (p == opts->first_bracket_include) + if (fl == opts->first_bracket_include) fprintf(stderr, "#include <...> search starts here:\n"); - fprintf(stderr, " %s\n", p->fname); + fprintf(stderr, " %s\n", fl->fname); } fprintf(stderr, "End of search list.\n"); } @@ -6227,7 +6011,7 @@ push_parse_file(pfile, fname) return FATAL_EXIT_CODE; } cpp_push_buffer(pfile, NULL, 0); - finclude(pfile, fd, pend->arg, 0, NULL_PTR); + finclude(pfile, fd, pend->arg, 0, NULL); cpp_scan_buffer(pfile); } } @@ -6249,7 +6033,7 @@ push_parse_file(pfile, fname) * inhibit compilation. */ if (opts->print_deps_missing_files && (opts->print_deps == 0 || !opts->no_output)) - fatal(pfile, "-MG must be specified with one of -M or -MM"); + cpp_fatal("-MG must be specified with one of -M or -MM"); /* Either of two environment variables can specify output of deps. * Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET", @@ -6309,18 +6093,18 @@ push_parse_file(pfile, fname) deps_output(pfile, "-", ':'); else { - char *p, *q; + char *q; int len; /* Discard all directory prefixes from filename. */ - if ((q = rindex(opts->in_fname, '/')) != NULL + if ((q = strrchr(opts->in_fname, '/')) != NULL #ifdef DIR_SEPARATOR - && (q = rindex(opts->in_fname, DIR_SEPARATOR)) != NULL + && (q = strrchr(opts->in_fname, DIR_SEPARATOR)) != NULL #endif ) ++q; else - q = opts->in_fname; + q = (char *)opts->in_fname; /* Copy remainder to mungable area. */ p = (char *)alloca(strlen(q) + 8); @@ -6329,7 +6113,7 @@ push_parse_file(pfile, fname) /* Output P, but remove known suffixes. */ len = strlen(p); q = p + len; - if (len >= 2 && p[len - 2] == '.' && index("cCsSm", p[len - 1])) + if (len >= 2 && p[len - 2] == '.' && strchr("cCsSm", p[len - 1])) q = p + (len - 2); else if (len >= 3 && p[len - 3] == '.' @@ -6371,7 +6155,7 @@ push_parse_file(pfile, fname) return FATAL_EXIT_CODE; } cpp_push_buffer(pfile, NULL, 0); - finclude(pfile, fd, pend->arg, 0, NULL_PTR); + finclude(pfile, fd, pend->arg, 0, NULL); } } pfile->no_record_file--; @@ -6386,15 +6170,13 @@ push_parse_file(pfile, fname) } opts->pending = NULL; - if (finclude(pfile, f, fname, 0, NULL_PTR)) + if (finclude(pfile, f, fname, 0, NULL)) output_line_command(pfile, 0, same_file); return SUCCESS_EXIT_CODE; } void -init_parse_file(pfile) - cpp_reader *pfile; - +init_parse_file(cpp_reader * pfile) { memset((char *)pfile, 0, sizeof(cpp_reader)); pfile->get_token = cpp_get_token; @@ -6413,9 +6195,7 @@ init_parse_file(pfile) } static struct cpp_pending * -nreverse_pending(list) - struct cpp_pending *list; - +nreverse_pending(struct cpp_pending *list) { struct cpp_pending *prev = 0, *next, *pend; @@ -6429,14 +6209,9 @@ nreverse_pending(list) } static void -push_pending(pfile, cmd, arg) - cpp_reader *pfile; - char *cmd; - char *arg; - +push_pending(cpp_reader * pfile, const char *cmd, const char *arg) { struct cpp_pending *pend - = (struct cpp_pending *)xmalloc(sizeof(struct cpp_pending)); pend->cmd = cmd; @@ -6451,11 +6226,7 @@ push_pending(pfile, cmd, arg) * Returns number of handled arguments. */ int -cpp_handle_options(pfile, argc, argv) - cpp_reader *pfile; - int argc; - char **argv; - +cpp_handle_options(cpp_reader * pfile, int argc, char **argv) { int i; struct cpp_options *opts = CPP_OPTIONS(pfile); @@ -6465,7 +6236,7 @@ cpp_handle_options(pfile, argc, argv) if (argv[i][0] != '-') { if (opts->out_fname != NULL) - fatal("Usage: %s [switches] input output", argv[0]); + cpp_fatal("Usage: %s [switches] input output", argv[0]); else if (opts->in_fname != NULL) opts->out_fname = argv[i]; else @@ -6481,14 +6252,15 @@ cpp_handle_options(pfile, argc, argv) || !strcmp(argv[i], "-imacros")) { if (i + 1 == argc) - fatal("Filename missing after `%s' option", argv[i]); + cpp_fatal("Filename missing after `%s' option", + argv[i]); else push_pending(pfile, argv[i], argv[i + 1]), i++; } if (!strcmp(argv[i], "-iprefix")) { if (i + 1 == argc) - fatal("Filename missing after `-iprefix' option"); + cpp_fatal("Filename missing after `-iprefix' option"); else opts->include_prefix = argv[++i]; } @@ -6501,10 +6273,9 @@ cpp_handle_options(pfile, argc, argv) struct file_name_list *dirtmp; if (i + 1 == argc) - fatal("Filename missing after `-isystem' option"); + cpp_fatal("Filename missing after `-isystem' option"); dirtmp = - (struct file_name_list *)xmalloc(sizeof(struct file_name_list)); @@ -6540,7 +6311,6 @@ cpp_handle_options(pfile, argc, argv) } dirtmp = - (struct file_name_list *)xmalloc(sizeof(struct file_name_list)); @@ -6548,7 +6318,7 @@ cpp_handle_options(pfile, argc, argv) dirtmp->control_macro = 0; dirtmp->c_system_include_path = 0; if (i + 1 == argc) - fatal + cpp_fatal ("Directory name missing after `-iwithprefix' option"); dirtmp->fname = (char *)xmalloc(strlen(argv[i + 1]) @@ -6582,7 +6352,6 @@ cpp_handle_options(pfile, argc, argv) } dirtmp = - (struct file_name_list *)xmalloc(sizeof(struct file_name_list)); @@ -6590,7 +6359,7 @@ cpp_handle_options(pfile, argc, argv) dirtmp->control_macro = 0; dirtmp->c_system_include_path = 0; if (i + 1 == argc) - fatal + cpp_fatal ("Directory name missing after `-iwithprefixbefore' option"); dirtmp->fname = (char *)xmalloc(strlen(argv[i + 1]) @@ -6607,7 +6376,6 @@ cpp_handle_options(pfile, argc, argv) struct file_name_list *dirtmp; dirtmp = - (struct file_name_list *)xmalloc(sizeof(struct file_name_list)); @@ -6615,7 +6383,7 @@ cpp_handle_options(pfile, argc, argv) dirtmp->control_macro = 0; dirtmp->c_system_include_path = 0; if (i + 1 == argc) - fatal + cpp_fatal ("Directory name missing after `-idirafter' option"); else dirtmp->fname = argv[++i]; @@ -6631,9 +6399,9 @@ cpp_handle_options(pfile, argc, argv) case 'o': if (opts->out_fname != NULL) - fatal("Output filename specified twice"); + cpp_fatal("Output filename specified twice"); if (i + 1 == argc) - fatal("Filename missing after -o option"); + cpp_fatal("Filename missing after -o option"); opts->out_fname = argv[++i]; if (!strcmp(opts->out_fname, "-")) opts->out_fname = ""; @@ -6758,7 +6526,8 @@ cpp_handle_options(pfile, argc, argv) if (!strcmp(argv[i], "-MD") || !strcmp(argv[i], "-MMD")) { if (i + 1 == argc) - fatal("Filename missing after %s option", argv[i]); + cpp_fatal("Filename missing after %s option", + argv[i]); opts->deps_file = argv[++i]; } else @@ -6816,7 +6585,7 @@ cpp_handle_options(pfile, argc, argv) if (argv[i][2] != 0) push_pending(pfile, "-D", argv[i] + 2); else if (i + 1 == argc) - fatal("Macro name missing after -D option"); + cpp_fatal("Macro name missing after -D option"); else i++, push_pending(pfile, "-D", argv[i]); break; @@ -6828,7 +6597,7 @@ cpp_handle_options(pfile, argc, argv) if (argv[i][2] != 0) p = argv[i] + 2; else if (i + 1 == argc) - fatal("Assertion missing after -A option"); + cpp_fatal("Assertion missing after -A option"); else p = argv[++i]; @@ -6868,7 +6637,7 @@ cpp_handle_options(pfile, argc, argv) if (argv[i][2] != 0) push_pending(pfile, "-U", argv[i] + 2); else if (i + 1 == argc) - fatal("Macro name missing after -U option"); + cpp_fatal("Macro name missing after -U option"); else push_pending(pfile, "-U", argv[i + 1]), i++; break; @@ -6902,7 +6671,6 @@ cpp_handle_options(pfile, argc, argv) else { dirtmp = - (struct file_name_list *)xmalloc(sizeof(struct file_name_list)); @@ -6912,7 +6680,8 @@ cpp_handle_options(pfile, argc, argv) if (argv[i][2] != 0) dirtmp->fname = argv[i] + 2; else if (i + 1 == argc) - fatal("Directory name missing after -I option"); + cpp_fatal + ("Directory name missing after -I option"); else dirtmp->fname = argv[++i]; dirtmp->got_name_map = 0; @@ -6957,9 +6726,7 @@ cpp_handle_options(pfile, argc, argv) } void -cpp_finish(pfile) - cpp_reader *pfile; - +cpp_finish(cpp_reader * pfile) { struct cpp_options *opts = CPP_OPTIONS(pfile); @@ -6971,8 +6738,7 @@ cpp_finish(pfile) /* Don't actually write the deps file if compilation has failed. */ if (pfile->errors == 0) { - char *deps_mode = - + const char *deps_mode = opts->print_deps_append ? "a" : "w"; if (opts->deps_file == 0) @@ -6984,18 +6750,15 @@ cpp_finish(pfile) if (opts->deps_file) { if (ferror(deps_stream) || fclose(deps_stream) != 0) - fatal("I/O error on output"); + cpp_fatal("I/O error on output"); } } } } static int -do_assert(pfile, keyword, buf, limit) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *buf, *limit; - +do_assert(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, + unsigned char *limit) { long symstart; /* remember where symbol name starts */ int c; @@ -7045,12 +6808,10 @@ do_assert(pfile, keyword, buf, limit) { ASSERTION_HASHNODE *hp; - unsigned char *symname = pfile->token_buffer + symstart; + const char *symname = (char *)pfile->token_buffer + symstart; int hashcode = - hashf(symname, sym_length, ASSERTION_HASHSIZE); struct tokenlist_list *value = - (struct tokenlist_list *)xmalloc(sizeof(struct tokenlist_list)); hp = assertion_lookup(pfile, symname, sym_length, hashcode); @@ -7074,11 +6835,8 @@ do_assert(pfile, keyword, buf, limit) } static int -do_unassert(pfile, keyword, buf, limit) - cpp_reader *pfile; - struct directive *keyword; - unsigned char *buf, *limit; - +do_unassert(cpp_reader * pfile, struct directive *keyword, unsigned char *buf, + unsigned char *limit) { long symstart; /* remember where symbol name starts */ int sym_length; /* and how long it is */ @@ -7125,9 +6883,8 @@ do_unassert(pfile, keyword, buf, limit) { ASSERTION_HASHNODE *hp; - unsigned char *symname = pfile->token_buffer + symstart; + const char *symname = (char *)pfile->token_buffer + symstart; int hashcode = - hashf(symname, sym_length, ASSERTION_HASHSIZE); struct tokenlist_list *tail, *prev; @@ -7180,14 +6937,9 @@ do_unassert(pfile, keyword, buf, limit) * NAME is not null terminated; its length is SYM_LENGTH. * If TOKENS_SPECIFIED is 0, then don't check for any token list. */ -int -check_assertion(pfile, name, sym_length, tokens_specified, tokens) - cpp_reader *pfile; - unsigned char *name; - int sym_length; - int tokens_specified; - struct arglist *tokens; - +static int +check_assertion(cpp_reader * pfile, const char *name, int sym_length, + int tokens_specified, struct arglist *tokens) { ASSERTION_HASHNODE *hp; int hashcode = hashf(name, sym_length, ASSERTION_HASHSIZE); @@ -7227,9 +6979,7 @@ check_assertion(pfile, name, sym_length, tokens_specified, tokens) /* Compare two lists of tokens for equality including order of tokens. */ static int -compare_token_lists(l1, l2) - struct arglist *l1, *l2; - +compare_token_lists(struct arglist *l1, struct arglist *l2) { while (l1 && l2) { @@ -7246,17 +6996,15 @@ compare_token_lists(l1, l2) } struct arglist * -reverse_token_list(tokens) - struct arglist *tokens; - +reverse_token_list(struct arglist *tokens) { - struct arglist *prev = 0, *this, *next; + struct arglist *prev = 0, *cur, *next; - for (this = tokens; this; this = next) + for (cur = tokens; cur; cur = next) { - next = this->next; - this->next = prev; - prev = this; + next = cur->next; + cur->next = prev; + prev = cur; } return prev; } @@ -7266,10 +7014,7 @@ reverse_token_list(tokens) * (In case of error, return 0 and store -1 in *ERROR_FLAG.) */ static struct arglist * -read_token_list(pfile, error_flag) - cpp_reader *pfile; - int *error_flag; - +read_token_list(cpp_reader * pfile, int *error_flag) { struct arglist *token_ptrs = 0; int depth = 1; @@ -7324,8 +7069,8 @@ read_token_list(pfile, error_flag) length = CPP_WRITTEN(pfile) - name_written; temp = (struct arglist *)xmalloc(sizeof(struct arglist) + length + 1); - temp->name = (unsigned char *)(temp + 1); - memcpy((char *)temp->name, (char *)(pfile->token_buffer + name_written), + temp->name = (char *)(temp + 1); + memcpy(temp->name, (char *)(pfile->token_buffer + name_written), length); temp->name[length] = 0; temp->next = token_ptrs; @@ -7348,9 +7093,7 @@ read_token_list(pfile, error_flag) } static void -free_token_list(tokens) - struct arglist *tokens; - +free_token_list(struct arglist *tokens) { while (tokens) { @@ -7366,11 +7109,7 @@ free_token_list(tokens) * and store them in *MODE_POINTER and *SIZE_POINTER. */ static int -file_size_and_mode(fd, mode_pointer, size_pointer) - int fd; - int *mode_pointer; - long int *size_pointer; - +file_size_and_mode(int fd, int *mode_pointer, long int *size_pointer) { struct stat sbuf; @@ -7389,11 +7128,7 @@ file_size_and_mode(fd, mode_pointer, size_pointer) * which must be LEN unless end-of-file was reached. */ static int -safe_read(desc, ptr, len) - int desc; - char *ptr; - int len; - +safe_read(int desc, char *ptr, int len) { int left = len; @@ -7418,12 +7153,10 @@ safe_read(desc, ptr, len) } static char * -savestring(input) - char *input; - +savestring(const char *input) { unsigned size = strlen(input); - char *output = xmalloc(size + 1); + char *output = (char *)xmalloc(size + 1); strcpy(output, input); return output; @@ -7431,10 +7164,7 @@ savestring(input) /* Initialize PMARK to remember the current position of PFILE. */ void -parse_set_mark(pmark, pfile) - struct parse_marker *pmark; - cpp_reader *pfile; - +parse_set_mark(struct parse_marker *pmark, cpp_reader * pfile) { cpp_buffer *pbuf = CPP_BUFFER(pfile); @@ -7445,17 +7175,15 @@ parse_set_mark(pmark, pfile) } /* Cleanup PMARK - we no longer need it. */ -void -parse_clear_mark(pmark) - struct parse_marker *pmark; - +static void +parse_clear_mark(struct parse_marker *pmark) { struct parse_marker **pp = &pmark->buf->marks; for (;; pp = &(*pp)->next) { if (*pp == NULL) - fatal("internal error", "in parse_set_mark"); + cpp_fatal("internal error", "in parse_set_mark"); if (*pp == pmark) break; } @@ -7464,39 +7192,31 @@ parse_clear_mark(pmark) /* Backup the current position of PFILE to that saved in PMARK. */ -void -parse_goto_mark(pmark, pfile) - struct parse_marker *pmark; - cpp_reader *pfile; - +static void +parse_goto_mark(struct parse_marker *pmark, cpp_reader * pfile) { cpp_buffer *pbuf = CPP_BUFFER(pfile); if (pbuf != pmark->buf) - fatal("internal error %s", "parse_goto_mark"); + cpp_fatal("internal error %s", "parse_goto_mark"); pbuf->cur = pbuf->buf + pmark->position; } /* Reset PMARK to point to the current position of PFILE. (Same * as parse_clear_mark (PMARK), parse_set_mark (PMARK, PFILE) but faster. */ -void -parse_move_mark(pmark, pfile) - struct parse_marker *pmark; - cpp_reader *pfile; - +static void +parse_move_mark(struct parse_marker *pmark, cpp_reader * pfile) { cpp_buffer *pbuf = CPP_BUFFER(pfile); if (pbuf != pmark->buf) - fatal("internal error %s", "parse_move_mark"); + cpp_fatal("internal error %s", "parse_move_mark"); pmark->position = pbuf->cur - pbuf->buf; } int -cpp_read_check_assertion(pfile) - cpp_reader *pfile; - +cpp_read_check_assertion(cpp_reader * pfile) { int name_start = CPP_WRITTEN(pfile); int name_length, name_written; @@ -7514,21 +7234,19 @@ cpp_read_check_assertion(pfile) struct arglist *token_ptrs = read_token_list(pfile, &error_flag); result = check_assertion(pfile, - pfile->token_buffer + name_start, name_length, - 1, token_ptrs); + (char *)pfile->token_buffer + name_start, + name_length, 1, token_ptrs); } else result = check_assertion(pfile, - pfile->token_buffer + name_start, name_length, - 0, NULL_PTR); + (char *)pfile->token_buffer + name_start, + name_length, 0, NULL); CPP_ADJUST_WRITTEN(pfile, -name_length); /* pop */ return result; } -void -cpp_print_file_and_line(pfile) - cpp_reader *pfile; - +static void +cpp_print_file_and_line(cpp_reader * pfile) { cpp_buffer *ip = cpp_file_buffer(pfile); @@ -7542,30 +7260,30 @@ cpp_print_file_and_line(pfile) } } -void cpp_error(cpp_reader * pfile, char *msg, char *arg1, - char *arg2, char *arg3); -void -cpp_error(pfile, msg, arg1, arg2, arg3) - cpp_reader *pfile; - char *msg; - char *arg1, *arg2, *arg3; - +static void +cpp_error_v(cpp_reader * pfile, const char *msg, va_list args) { cpp_print_containing_files(pfile); cpp_print_file_and_line(pfile); - cpp_message(pfile, 1, msg, arg1, arg2, arg3); + cpp_message_v(pfile, 1, msg, args); +} + +void +cpp_error(cpp_reader * pfile, const char *msg, ...) +{ + va_list args; + + va_start(args, msg); + + cpp_error_v(pfile, msg, args); + + va_end(args); } /* Print error message but don't count it. */ -void cpp_warning(cpp_reader * pfile, char *msg, char *arg1, - char *arg2, char *arg3); -void -cpp_warning(pfile, msg, arg1, arg2, arg3) - cpp_reader *pfile; - char *msg; - char *arg1, *arg2, *arg3; - +static void +cpp_warning_v(cpp_reader * pfile, const char *msg, va_list args) { if (CPP_OPTIONS(pfile)->inhibit_warnings) return; @@ -7575,36 +7293,40 @@ cpp_warning(pfile, msg, arg1, arg2, arg3) cpp_print_containing_files(pfile); cpp_print_file_and_line(pfile); - cpp_message(pfile, 0, msg, arg1, arg2, arg3); + cpp_message_v(pfile, 0, msg, args); +} + +void +cpp_warning(cpp_reader * pfile, const char *msg, ...) +{ + va_list args; + + va_start(args, msg); + + cpp_warning_v(pfile, msg, args); + + va_end(args); } /* Print an error message and maybe count it. */ -void cpp_pedwarn(cpp_reader * pfile, char *msg, char *arg1, - char *arg2, char *arg3); void -cpp_pedwarn(pfile, msg, arg1, arg2, arg3) - cpp_reader *pfile; - char *msg; - char *arg1, *arg2, *arg3; - +cpp_pedwarn(cpp_reader * pfile, const char *msg, ...) { + va_list args; + + va_start(args, msg); + if (CPP_OPTIONS(pfile)->pedantic_errors) - cpp_error(pfile, msg, arg1, arg2, arg3); + cpp_error_v(pfile, msg, args); else - cpp_warning(pfile, msg, arg1, arg2, arg3); + cpp_warning_v(pfile, msg, args); + + va_end(args); } -void cpp_error_with_line(cpp_reader * pfile, int line, - int column, char *msg, char *arg1, - char *arg2, char *arg3); -void -cpp_error_with_line(pfile, line, column, msg, arg1, arg2, arg3) - cpp_reader *pfile; - int line, column; - char *msg; - char *arg1, *arg2, *arg3; - +static void +cpp_error_with_line(cpp_reader * pfile, int line, int column, const char *msg) { cpp_buffer *ip = cpp_file_buffer(pfile); @@ -7613,16 +7335,11 @@ cpp_error_with_line(pfile, line, column, msg, arg1, arg2, arg3) if (ip != NULL) cpp_file_line_for_message(pfile, ip->nominal_fname, line, column); - cpp_message(pfile, 1, msg, arg1, arg2, arg3); + cpp_message(pfile, 1, msg, NULL, NULL, NULL); } static void -cpp_warning_with_line(pfile, line, column, msg, arg1, arg2, arg3) - cpp_reader *pfile; - int line, column; - char *msg; - char *arg1, *arg2, *arg3; - +cpp_warning_with_line(cpp_reader * pfile, int line, int column, const char *msg) { cpp_buffer *ip; @@ -7639,42 +7356,26 @@ cpp_warning_with_line(pfile, line, column, msg, arg1, arg2, arg3) if (ip != NULL) cpp_file_line_for_message(pfile, ip->nominal_fname, line, column); - cpp_message(pfile, 0, msg, arg1, arg2, arg3); + cpp_message(pfile, 0, msg, NULL, NULL, NULL); } -void cpp_pedwarn_with_line(cpp_reader * pfile, int line, - int column, char *msg, char *arg1, - char *arg2, char *arg3); -void -cpp_pedwarn_with_line(pfile, line, column, msg, arg1, arg2, arg3) - cpp_reader *pfile; - int line; - int column; - char *msg; - char *arg1, *arg2, *arg3; - +static void +cpp_pedwarn_with_line(cpp_reader * pfile, int line, int column, const char *msg) { if (CPP_OPTIONS(pfile)->pedantic_errors) - cpp_error_with_line(pfile, column, line, msg, arg1, arg2, arg3); + cpp_error_with_line(pfile, column, line, msg); else - cpp_warning_with_line(pfile, line, column, msg, arg1, arg2, arg3); + cpp_warning_with_line(pfile, line, column, msg); } /* Report a warning (or an error if pedantic_errors) * giving specified file name and line number, not current. */ -void cpp_pedwarn_with_file_and_line(cpp_reader * pfile, - char *file, int line, - char *msg, char *arg1, - char *arg2, char *arg3); void -cpp_pedwarn_with_file_and_line(pfile, file, line, msg, arg1, arg2, arg3) - cpp_reader *pfile; - char *file; - int line; - char *msg; - char *arg1, *arg2, *arg3; - +cpp_pedwarn_with_file_and_line(cpp_reader * pfile, + const char *file, int line, + const char *msg, const char *arg1, + const char *arg2, const char *arg3) { if (!CPP_OPTIONS(pfile)->pedantic_errors && CPP_OPTIONS(pfile)->inhibit_warnings) @@ -7702,25 +7403,19 @@ extern const char *const sys_errlist[]; extern char *sys_errlist[]; #endif -#else /* HAVE_STRERROR */ -char *strerror(); - -#endif +#endif /* HAVE_STRERROR */ /* * my_strerror - return the descriptive text associated with an `errno' code. */ -char *my_strerror(int errnum); -char * -my_strerror(errnum) - int errnum; - +static const char * +my_strerror(int errnum) { - char *result; + const char *result; #ifndef HAVE_STRERROR - result = (char *)((errnum < sys_nerr) ? sys_errlist[errnum] : 0); + result = ((errnum < sys_nerr) ? sys_errlist[errnum] : 0); #else result = strerror(errnum); #endif @@ -7733,12 +7428,8 @@ my_strerror(errnum) /* Error including a message from `errno'. */ -void cpp_error_from_errno(cpp_reader * pfile, char *name); -void -cpp_error_from_errno(pfile, name) - cpp_reader *pfile; - char *name; - +static void +cpp_error_from_errno(cpp_reader * pfile, const char *name) { cpp_buffer *ip = cpp_file_buffer(pfile); @@ -7750,12 +7441,8 @@ cpp_error_from_errno(pfile, name) cpp_message(pfile, 1, "%s: %s", name, my_strerror(errno), NULL); } -void cpp_perror_with_name(cpp_reader * pfile, char *name); void -cpp_perror_with_name(pfile, name) - cpp_reader *pfile; - char *name; - +cpp_perror_with_name(cpp_reader * pfile, const char *name) { cpp_message(pfile, 1, "%s: %s: %s", progname, name, my_strerror(errno)); } diff --git a/epp/cpplib.h b/epp/cpplib.h index d63f555f..ea46bb00 100644 --- a/epp/cpplib.h +++ b/epp/cpplib.h @@ -21,139 +21,137 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. You are forbidden to forbid anyone else to use, share and improve what you give them. Help stamp out software-hoarding! */ +#include #include #include -#ifdef __cplusplus -extern "C" -{ +#ifndef HOST_BITS_PER_WIDE_INT + +#if HOST_BITS_PER_LONG > HOST_BITS_PER_INT +#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG +#define HOST_WIDE_INT long +#else +#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT +#define HOST_WIDE_INT int +#endif + #endif #define STATIC_BUFFERS - struct parse_file; - typedef struct cpp_reader cpp_reader; - typedef struct cpp_buffer cpp_buffer; - typedef struct cpp_options cpp_options; - typedef struct hashnode cpp_hashnode; +typedef struct cpp_reader cpp_reader; +typedef struct cpp_buffer cpp_buffer; +typedef struct cpp_options cpp_options; - enum cpp_token - { - CPP_EOF = -1, - CPP_OTHER = 0, - CPP_COMMENT = 1, - CPP_HSPACE, - CPP_VSPACE, /* newlines and #line directives */ - CPP_NAME, - CPP_NUMBER, - CPP_CHAR, - CPP_STRING, - CPP_DIRECTIVE, - CPP_LPAREN, /* "(" */ - CPP_RPAREN, /* ")" */ - CPP_LBRACE, /* "{" */ - CPP_RBRACE, /* "}" */ - CPP_COMMA, /* "," */ - CPP_SEMICOLON, /* ";" */ - CPP_3DOTS, /* "..." */ - /* POP_TOKEN is returned when we've popped a cpp_buffer. */ - CPP_POP - }; +enum cpp_token +{ + CPP_EOF = -1, + CPP_OTHER = 0, + CPP_COMMENT = 1, + CPP_HSPACE, + CPP_VSPACE, /* newlines and #line directives */ + CPP_NAME, + CPP_NUMBER, + CPP_CHAR, + CPP_STRING, + CPP_DIRECTIVE, + CPP_LPAREN, /* "(" */ + CPP_RPAREN, /* ")" */ + CPP_LBRACE, /* "{" */ + CPP_RBRACE, /* "}" */ + CPP_COMMA, /* "," */ + CPP_SEMICOLON, /* ";" */ + CPP_3DOTS, /* "..." */ + /* POP_TOKEN is returned when we've popped a cpp_buffer. */ + CPP_POP +}; -#ifndef PARAMS -#ifdef __STDC -#define PARAMS(P) P -#else -#define PARAMS(P) () -#endif -#endif /* !PARAMS */ - - typedef enum cpp_token (*parse_underflow_t) PARAMS((cpp_reader *)); - typedef int (*parse_cleanup_t) PARAMS((cpp_buffer *, cpp_reader *)); +typedef enum cpp_token (*parse_underflow_t) (cpp_reader *); +typedef int (*parse_cleanup_t) (cpp_buffer *, cpp_reader *); /* A parse_marker indicates a previous position, which we can backtrack to. */ - struct parse_marker - { - cpp_buffer *buf; - struct parse_marker *next; - int position; - }; +struct parse_marker +{ + cpp_buffer *buf; + struct parse_marker *next; + int position; +}; - extern void parse_set_mark PARAMS((struct parse_marker *, cpp_reader *)); - extern void parse_clear_mark PARAMS((struct parse_marker *)); - extern void parse_goto_mark PARAMS((struct parse_marker *, cpp_reader *)); - extern void parse_move_mark PARAMS((struct parse_marker *, cpp_reader *)); - - extern int cpp_handle_options PARAMS((cpp_reader *, int, char **)); - extern enum cpp_token cpp_get_token PARAMS((cpp_reader *)); - extern void cpp_skip_hspace PARAMS((cpp_reader *)); - extern enum cpp_token cpp_get_non_space_token PARAMS((cpp_reader *)); +extern int cpp_handle_options(cpp_reader * pfile, int, char **); +extern enum cpp_token cpp_get_token(cpp_reader * pfile); +extern void cpp_skip_hspace(cpp_reader * pfile); /* Maintain and search list of included files, for #import. */ #define IMPORT_HASH_SIZE 31 - struct import_file - { - char *name; - ino_t inode; - dev_t dev; - struct import_file *next; - }; +struct import_file +{ + char *name; + ino_t inode; + dev_t dev; + struct import_file *next; +}; /* If we have a huge buffer, may need to cache more recent counts */ #define CPP_LINE_BASE(BUF) ((BUF)->buf + (BUF)->line_base) - struct cpp_buffer - { - unsigned char *buf; - unsigned char *cur; - unsigned char *rlimit; /* end of valid data */ - unsigned char *alimit; /* end of allocated buffer */ - unsigned char *prev; /* start of current token */ +enum dump_type +{ + dump_none = 0, dump_only, dump_names, dump_definitions +}; - char *fname; - /* Filename specified with #line command. */ - char *nominal_fname; +struct cpp_buffer +{ + unsigned char *buf; + unsigned char *cur; + unsigned char *rlimit; /* end of valid data */ + unsigned char *alimit; /* end of allocated buffer */ + unsigned char *prev; /* start of current token */ - /* Record where in the search path this file was found. - * For #include_next. */ - struct file_name_list *dir; + const char *fname; + /* Filename specified with #line command. */ + const char *nominal_fname; - long line_base; - long lineno; /* Line number at CPP_LINE_BASE. */ - long colno; /* Column number at CPP_LINE_BASE. */ + /* Record where in the search path this file was found. + * For #include_next. */ + struct file_name_list *dir; + + long line_base; + long lineno; /* Line number at CPP_LINE_BASE. */ + long colno; /* Column number at CPP_LINE_BASE. */ #ifndef STATIC_BUFFERS - cpp_buffer *chain; + cpp_buffer *chain; #endif - parse_underflow_t underflow; - parse_cleanup_t cleanup; - void *data; - struct parse_marker *marks; - /* Value of if_stack at start of this file. - * Used to prohibit unmatched #endif (etc) in an include file. */ - struct if_stack *if_stack; + parse_underflow_t underflow; + parse_cleanup_t cleanup; + void *data; + struct parse_marker *marks; + /* Value of if_stack at start of this file. + * Used to prohibit unmatched #endif (etc) in an include file. */ + struct if_stack *if_stack; - /* True if this is a header file included using . */ - char system_header_p; - char seen_eof; + /* True if this is a header file included using . */ + char system_header_p; + char seen_eof; - /* True if buffer contains escape sequences. - * Currently there are are only two kind: - * "@-" means following identifier should not be macro-expanded. - * "@ " means a token-separator. This turns into " " in final output - * if not stringizing and needed to separate tokens; otherwise nothing. - * "@@" means a normal '@'. - * (An '@' inside a string stands for itself and is never an escape.) */ - char has_escapes; - }; + /* True if buffer contains escape sequences. + * Currently there are are only two kind: + * "@-" means following identifier should not be macro-expanded. + * "@ " means a token-separator. This turns into " " in final output + * if not stringizing and needed to separate tokens; otherwise nothing. + * "@@" means a normal '@'. + * (An '@' inside a string stands for itself and is never an escape.) */ + char has_escapes; +}; - struct cpp_pending; /* Forward declaration - for C++. */ - struct file_name_map_list; +struct cpp_pending; /* Forward declaration - for C++. */ +struct file_name_map_list; + +typedef struct assertion_hashnode ASSERTION_HASHNODE; - typedef struct assertion_hashnode ASSERTION_HASHNODE; #define ASSERTION_HASHSIZE 37 #ifdef STATIC_BUFFERS @@ -162,97 +160,97 @@ extern "C" #define CPP_STACK_MAX 200 #endif - struct cpp_reader - { - unsigned char *limit; - parse_underflow_t get_token; - cpp_buffer *buffer; +struct cpp_reader +{ + unsigned char *limit; + parse_underflow_t get_token; + cpp_buffer *buffer; #ifdef STATIC_BUFFERS - cpp_buffer buffer_stack[CPP_STACK_MAX]; + cpp_buffer buffer_stack[CPP_STACK_MAX]; #endif - int errors; /* Error counter for exit code */ - void *data; + int errors; /* Error counter for exit code */ + void *data; - unsigned char *token_buffer; - int token_buffer_size; + unsigned char *token_buffer; + int token_buffer_size; - /* Line where a newline was first seen in a string constant. */ - int multiline_string_line; + /* Line where a newline was first seen in a string constant. */ + int multiline_string_line; - /* Current depth in #include directives that use <...>. */ - int system_include_depth; + /* Current depth in #include directives that use <...>. */ + int system_include_depth; - /* List of included files that contained #pragma once. */ - struct file_name_list *dont_repeat_files; + /* List of included files that contained #pragma once. */ + struct file_name_list *dont_repeat_files; - /* List of other included files. - * If ->control_macro if nonzero, the file had a #ifndef - * around the entire contents, and ->control_macro gives the macro name. */ - struct file_name_list *all_include_files; + /* List of other included files. + * If ->control_macro if nonzero, the file had a #ifndef + * around the entire contents, and ->control_macro gives the macro name. */ + struct file_name_list *all_include_files; - /* Current maximum length of directory names in the search path - * for include files. (Altered as we get more of them.) */ - int max_include_len; + /* Current maximum length of directory names in the search path + * for include files. (Altered as we get more of them.) */ + int max_include_len; - /* Hash table of files already included with #include or #import. */ - struct import_file *import_hash_table[IMPORT_HASH_SIZE]; + /* Hash table of files already included with #include or #import. */ + struct import_file *import_hash_table[IMPORT_HASH_SIZE]; - struct if_stack *if_stack; + struct if_stack *if_stack; - /* Nonzero means we are inside an IF during a -pcp run. In this mode - * macro expansion is done, and preconditions are output for all macro - * uses requiring them. */ - char pcp_inside_if; + /* Nonzero means we are inside an IF during a -pcp run. In this mode + * macro expansion is done, and preconditions are output for all macro + * uses requiring them. */ + char pcp_inside_if; - /* Nonzero means we have printed (while error reporting) a list of - * containing files that matches the current status. */ - char input_stack_listing_current; + /* Nonzero means we have printed (while error reporting) a list of + * containing files that matches the current status. */ + char input_stack_listing_current; - /* If non-zero, macros are not expanded. */ - char no_macro_expand; + /* If non-zero, macros are not expanded. */ + char no_macro_expand; - /* Print column number in error messages. */ - char show_column; + /* Print column number in error messages. */ + char show_column; - /* We're printed a warning recommending against using #import. */ - char import_warning; + /* We're printed a warning recommending against using #import. */ + char import_warning; - /* If true, character between '<' and '>' are a single (string) token. */ - char parsing_include_directive; + /* If true, character between '<' and '>' are a single (string) token. */ + char parsing_include_directive; - /* True if escape sequences (as described for has_escapes in - * parse_buffer) should be emitted. */ - char output_escapes; + /* True if escape sequences (as described for has_escapes in + * parse_buffer) should be emitted. */ + char output_escapes; - /* 0: Have seen non-white-space on this line. - * 1: Only seen white space so far on this line. - * 2: Only seen white space so far in this file. */ - char only_seen_white; + /* 0: Have seen non-white-space on this line. + * 1: Only seen white space so far on this line. + * 2: Only seen white space so far in this file. */ + char only_seen_white; - /* Nonzero means this file was included with a -imacros or -include - * command line and should not be recorded as an include file. */ + /* Nonzero means this file was included with a -imacros or -include + * command line and should not be recorded as an include file. */ - int no_record_file; + int no_record_file; - long lineno; + long lineno; - struct tm *timebuf; + struct tm *timebuf; - ASSERTION_HASHNODE *assertion_hashtab[ASSERTION_HASHSIZE]; + ASSERTION_HASHNODE *assertion_hashtab[ASSERTION_HASHSIZE]; - /* Buffer of -M output. */ - char *deps_buffer; + /* Buffer of -M output. */ + char *deps_buffer; - /* Number of bytes allocated in above. */ - int deps_allocated_size; + /* Number of bytes allocated in above. */ + int deps_allocated_size; - /* Number of bytes used. */ - int deps_size; + /* Number of bytes used. */ + int deps_size; - /* Number of bytes since the last newline. */ - int deps_column; - }; + /* Number of bytes since the last newline. */ + int deps_column; +}; #define CPP_BUF_PEEK(BUFFER) \ ((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur : EOF) @@ -296,117 +294,117 @@ extern "C" #endif /* Pointed to by parse_file::data. */ - struct cpp_options - { - char *in_fname; +struct cpp_options +{ + const char *in_fname; - /* Name of output file, for error messages. */ - char *out_fname; + /* Name of output file, for error messages. */ + const char *out_fname; - struct file_name_map_list *map_list; + struct file_name_map_list *map_list; - /* Non-0 means -v, so print the full set of include dirs. */ - char verbose; + /* Non-0 means -v, so print the full set of include dirs. */ + char verbose; - /* Nonzero means use extra default include directories for C++. */ + /* Nonzero means use extra default include directories for C++. */ - char cplusplus; + char cplusplus; - /* Nonzero means handle cplusplus style comments */ + /* Nonzero means handle cplusplus style comments */ - char cplusplus_comments; + char cplusplus_comments; - /* Nonzero means handle #import, for objective C. */ + /* Nonzero means handle #import, for objective C. */ - char objc; + char objc; - /* Nonzero means this is an assembly file, and allow - * unknown directives, which could be comments. */ + /* Nonzero means this is an assembly file, and allow + * unknown directives, which could be comments. */ - int lang_asm; + int lang_asm; - /* Nonzero means turn NOTREACHED into #pragma NOTREACHED etc */ + /* Nonzero means turn NOTREACHED into #pragma NOTREACHED etc */ - char for_lint; + char for_lint; - /* Nonzero means handle CHILL comment syntax - * and output CHILL string delimiter for __DATE___ etc. */ + /* Nonzero means handle CHILL comment syntax + * and output CHILL string delimiter for __DATE___ etc. */ - char chill; + char chill; - /* Nonzero means copy comments into the output file. */ + /* Nonzero means copy comments into the output file. */ - char put_out_comments; + char put_out_comments; - /* Nonzero means don't process the ANSI trigraph sequences. */ + /* Nonzero means don't process the ANSI trigraph sequences. */ - char no_trigraphs; + char no_trigraphs; - /* Nonzero means print the names of included files rather than - * the preprocessed output. 1 means just the #include "...", - * 2 means #include <...> as well. */ + /* Nonzero means print the names of included files rather than + * the preprocessed output. 1 means just the #include "...", + * 2 means #include <...> as well. */ - char print_deps; + char print_deps; - /* Nonzero if missing .h files in -M output are assumed to be generated - * files and not errors. */ + /* Nonzero if missing .h files in -M output are assumed to be generated + * files and not errors. */ - char print_deps_missing_files; + char print_deps_missing_files; - /* If true, fopen (deps_file, "a") else fopen (deps_file, "w"). */ - char print_deps_append; + /* If true, fopen (deps_file, "a") else fopen (deps_file, "w"). */ + char print_deps_append; - /* Nonzero means print names of header files (-H). */ + /* Nonzero means print names of header files (-H). */ - char print_include_names; + char print_include_names; - /* Nonzero means try to make failure to fit ANSI C an error. */ + /* Nonzero means try to make failure to fit ANSI C an error. */ - char pedantic_errors; + char pedantic_errors; - /* Nonzero means don't print warning messages. -w. */ + /* Nonzero means don't print warning messages. -w. */ - char inhibit_warnings; + char inhibit_warnings; - /* Nonzero means warn if slash-star appears in a comment. */ + /* Nonzero means warn if slash-star appears in a comment. */ - char warn_comments; + char warn_comments; - /* Nonzero means warn if there are any trigraphs. */ + /* Nonzero means warn if there are any trigraphs. */ - char warn_trigraphs; + char warn_trigraphs; - /* Nonzero means warn if #import is used. */ + /* Nonzero means warn if #import is used. */ - char warn_import; + char warn_import; - /* Nonzero means warn if a macro argument is (or would be) - * stringified with -traditional. */ + /* Nonzero means warn if a macro argument is (or would be) + * stringified with -traditional. */ - char warn_stringify; + char warn_stringify; - /* Nonzero means turn warnings into errors. */ + /* Nonzero means turn warnings into errors. */ - char warnings_are_errors; + char warnings_are_errors; - /* Nonzero causes output not to be done, - * but directives such as #define that have side effects - * are still obeyed. */ + /* Nonzero causes output not to be done, + * but directives such as #define that have side effects + * are still obeyed. */ - char no_output; + char no_output; - /* Nonzero means don't output line number information. */ + /* Nonzero means don't output line number information. */ - char no_line_commands; + char no_line_commands; /* Nonzero means output the text in failing conditionals, inside #failed ... #endfailed. */ - char output_conditionals; + char output_conditionals; - /* Nonzero means -I- has been seen, - * so don't look for #include "foo" the source-file directory. */ - char ignore_srcdir; + /* Nonzero means -I- has been seen, + * so don't look for #include "foo" the source-file directory. */ + char ignore_srcdir; /* Zero means dollar signs are punctuation. -$ stores 0; -traditional may store 1. Default is 1 for VMS, 0 otherwise. @@ -415,44 +413,44 @@ extern "C" #define lose(b) foo (b) #define test$ lose (test) */ - char dollars_in_ident; + char dollars_in_ident; #ifndef DOLLARS_IN_IDENTIFIERS #define DOLLARS_IN_IDENTIFIERS 1 #endif - /* Nonzero means try to imitate old fashioned non-ANSI preprocessor. */ - char traditional; + /* Nonzero means try to imitate old fashioned non-ANSI preprocessor. */ + char traditional; - /* Nonzero means give all the error messages the ANSI standard requires. */ - char pedantic; + /* Nonzero means give all the error messages the ANSI standard requires. */ + char pedantic; - char done_initializing; + char done_initializing; - struct file_name_list *include; /* First dir to search */ - /* First dir to search for */ - /* This is the first element to use for #include <...>. - * If it is 0, use the entire chain for such includes. */ - struct file_name_list *first_bracket_include; - /* This is the first element in the chain that corresponds to - * a directory of system header files. */ - struct file_name_list *first_system_include; - struct file_name_list *last_include; /* Last in chain */ + struct file_name_list *include; /* First dir to search */ + /* First dir to search for */ + /* This is the first element to use for #include <...>. + * If it is 0, use the entire chain for such includes. */ + struct file_name_list *first_bracket_include; + /* This is the first element in the chain that corresponds to + * a directory of system header files. */ + struct file_name_list *first_system_include; + struct file_name_list *last_include; /* Last in chain */ - /* Chain of include directories to put at the end of the other chain. */ - struct file_name_list *after_include; - struct file_name_list *last_after_include; /* Last in chain */ + /* Chain of include directories to put at the end of the other chain. */ + struct file_name_list *after_include; + struct file_name_list *last_after_include; /* Last in chain */ - /* Chain to put at the start of the system include files. */ - struct file_name_list *before_system; - struct file_name_list *last_before_system; /* Last in chain */ + /* Chain to put at the start of the system include files. */ + struct file_name_list *before_system; + struct file_name_list *last_before_system; /* Last in chain */ - /* Directory prefix that should replace `/usr' in the standard - * include file directories. */ - char *include_prefix; + /* Directory prefix that should replace `/usr' in the standard + * include file directories. */ + char *include_prefix; - char inhibit_predefs; - char no_standard_includes; - char no_standard_cplusplus_includes; + char inhibit_predefs; + char no_standard_includes; + char no_standard_cplusplus_includes; /* dump_only means inhibit output of the preprocessed text and instead output the definitions of all user-defined @@ -461,9 +459,7 @@ extern "C" dump_definitions means pass the whole definition (plus #define) through */ - enum - { dump_none = 0, dump_only, dump_names, dump_definitions } - dump_macros; + enum dump_type dump_macros; /* Nonzero means pass all #define and #undef directives which we actually process through to the output stream. This feature is used primarily @@ -471,18 +467,18 @@ extern "C" debuggers which understand about preprocessor macros, but it may also be useful with -E to figure out how symbols are defined, and where they are defined. */ - int debug_output; + int debug_output; - /* Pending -D, -U and -A options, in reverse order. */ - struct cpp_pending *pending; + /* Pending -D, -U and -A options, in reverse order. */ + struct cpp_pending *pending; - /* File name which deps are being written to. - * This is 0 if deps are being written to stdout. */ - char *deps_file; + /* File name which deps are being written to. + * This is 0 if deps are being written to stdout. */ + char *deps_file; - /* Target-name to write with the dependency information. */ - char *deps_target; - }; + /* Target-name to write with the dependency information. */ + char *deps_target; +}; #define CPP_TRADITIONAL(PFILE) (CPP_OPTIONS(PFILE)-> traditional) #define CPP_PEDANTIC(PFILE) (CPP_OPTIONS (PFILE)->pedantic) @@ -490,7 +486,7 @@ extern "C" /* Name under which this program was invoked. */ - extern char *progname; +extern char *progname; /* The structure of a node in the hash table. The hash table has entries for all tokens defined by #define commands (type T_MACRO), @@ -500,55 +496,46 @@ extern "C" by a separate piece of code. */ /* different flavors of hash nodes --- also used in keyword table */ - enum node_type - { - T_DEFINE = 1, /* the `#define' keyword */ - T_INCLUDE, /* the `#include' keyword */ - T_INCLUDE_NEXT, /* the `#include_next' keyword */ - T_IMPORT, /* the `#import' keyword */ - T_IFDEF, /* the `#ifdef' keyword */ - T_IFNDEF, /* the `#ifndef' keyword */ - T_IF, /* the `#if' keyword */ - T_ELSE, /* `#else' */ - T_PRAGMA, /* `#pragma' */ - T_ELIF, /* `#elif' */ - T_UNDEF, /* `#undef' */ - T_LINE, /* `#line' */ - T_ERROR, /* `#error' */ - T_WARNING, /* `#warning' */ - T_ENDIF, /* `#endif' */ - T_SCCS, /* `#sccs', used on system V. */ - T_IDENT, /* `#ident', used on system V. */ - T_ASSERT, /* `#assert', taken from system V. */ - T_UNASSERT, /* `#unassert', taken from system V. */ - T_SPECLINE, /* special symbol `__LINE__' */ - T_DATE, /* `__DATE__' */ - T_FILE, /* `__FILE__' */ - T_BASE_FILE, /* `__BASE_FILE__' */ - T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */ - T_VERSION, /* `__VERSION__' */ - T_SIZE_TYPE, /* `__SIZE_TYPE__' */ - T_PTRDIFF_TYPE, /* `__PTRDIFF_TYPE__' */ - T_WCHAR_TYPE, /* `__WCHAR_TYPE__' */ - T_USER_LABEL_PREFIX_TYPE, /* `__USER_LABEL_PREFIX__' */ - T_REGISTER_PREFIX_TYPE, /* `__REGISTER_PREFIX__' */ - T_TIME, /* `__TIME__' */ - T_CONST, /* Constant value, used by `__STDC__' */ - T_MACRO, /* macro defined by `#define' */ - T_DISABLED, /* macro temporarily turned off for rescan */ - T_SPEC_DEFINED, /* special `defined' macro for use in #if statements */ - T_PCSTRING, /* precompiled string (hashval is KEYDEF *) */ - T_UNUSED /* Used for something not defined. */ - }; - -/* Structure returned by create_definition */ - typedef struct macrodef MACRODEF; - struct macrodef - { - struct definition *defn; - unsigned char *symnam; - int symlen; - }; +enum node_type +{ + T_DEFINE = 1, /* the `#define' keyword */ + T_INCLUDE, /* the `#include' keyword */ + T_INCLUDE_NEXT, /* the `#include_next' keyword */ + T_IMPORT, /* the `#import' keyword */ + T_IFDEF, /* the `#ifdef' keyword */ + T_IFNDEF, /* the `#ifndef' keyword */ + T_IF, /* the `#if' keyword */ + T_ELSE, /* `#else' */ + T_PRAGMA, /* `#pragma' */ + T_ELIF, /* `#elif' */ + T_UNDEF, /* `#undef' */ + T_LINE, /* `#line' */ + T_ERROR, /* `#error' */ + T_WARNING, /* `#warning' */ + T_ENDIF, /* `#endif' */ + T_SCCS, /* `#sccs', used on system V. */ + T_IDENT, /* `#ident', used on system V. */ + T_ASSERT, /* `#assert', taken from system V. */ + T_UNASSERT, /* `#unassert', taken from system V. */ + T_SPECLINE, /* special symbol `__LINE__' */ + T_DATE, /* `__DATE__' */ + T_FILE, /* `__FILE__' */ + T_BASE_FILE, /* `__BASE_FILE__' */ + T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */ + T_VERSION, /* `__VERSION__' */ + T_SIZE_TYPE, /* `__SIZE_TYPE__' */ + T_PTRDIFF_TYPE, /* `__PTRDIFF_TYPE__' */ + T_WCHAR_TYPE, /* `__WCHAR_TYPE__' */ + T_USER_LABEL_PREFIX_TYPE, /* `__USER_LABEL_PREFIX__' */ + T_REGISTER_PREFIX_TYPE, /* `__REGISTER_PREFIX__' */ + T_TIME, /* `__TIME__' */ + T_CONST, /* Constant value, used by `__STDC__' */ + T_MACRO, /* macro defined by `#define' */ + T_DISABLED, /* macro temporarily turned off for rescan */ + T_SPEC_DEFINED, /* special `defined' macro for use in #if statements */ + T_PCSTRING, /* precompiled string (hashval is KEYDEF *) */ + T_UNUSED /* Used for something not defined. */ +}; /* Structure allocated for every #define. For a simple replacement such as @@ -571,87 +558,94 @@ extern "C" { (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL } where (x, y) means (nchars, argno). */ - typedef struct definition DEFINITION; - struct definition - { - int nargs; - int length; /* length of expansion string */ - int predefined; /* True if the macro was builtin or */ - /* came from the command line */ - unsigned char *expansion; - int line; /* Line number of definition */ - char *file; /* File of definition */ - char rest_args; /* Nonzero if last arg. absorbs the rest */ - struct reflist - { - struct reflist *next; - char stringify; /* nonzero if this arg was preceded by a +struct reflist +{ + struct reflist *next; + char stringify; /* nonzero if this arg was preceded by a * # operator. */ - char raw_before; /* Nonzero if a ## operator before arg. */ - char raw_after; /* Nonzero if a ## operator after arg. */ - char rest_args; /* Nonzero if this arg. absorbs the rest */ - int nchars; /* Number of literal chars to copy before - * this arg occurrence. */ - int argno; /* Number of arg to substitute (origin-0) */ - } - *pattern; - union - { - /* Names of macro args, concatenated in reverse order - * with comma-space between them. - * The only use of this is that we warn on redefinition - * if this differs between the old and new definitions. */ - unsigned char *argnames; - } - args; - }; + char raw_before; /* Nonzero if a ## operator before arg. */ + char raw_after; /* Nonzero if a ## operator after arg. */ + char rest_args; /* Nonzero if this arg. absorbs the rest */ + int nchars; /* Number of literal chars to copy before + * this arg occurrence. */ + int argno; /* Number of arg to substitute (origin-0) */ +}; - extern unsigned char is_idchar[256]; +typedef struct definition DEFINITION; +struct definition +{ + int nargs; + int length; /* length of expansion string */ + int predefined; /* True if the macro was builtin or */ + /* came from the command line */ + unsigned char *expansion; + int line; /* Line number of definition */ + const char *file; /* File of definition */ + char rest_args; /* Nonzero if last arg. absorbs the rest */ + struct reflist *pattern; + union + { + /* Names of macro args, concatenated in reverse order + * with comma-space between them. + * The only use of this is that we warn on redefinition + * if this differs between the old and new definitions. */ + unsigned char *argnames; + } + args; +}; + +extern unsigned char is_idchar[256]; /* Stack of conditionals currently in progress (including both successful and failing conditionals). */ - struct if_stack - { - struct if_stack *next; /* for chaining to the next stack frame */ - char *fname; /* copied from input when frame is made */ - int lineno; /* similarly */ - int if_succeeded; /* true if a leg of this if-group +struct if_stack +{ + struct if_stack *next; /* for chaining to the next stack frame */ + const char *fname; /* copied from input when frame is made */ + int lineno; /* similarly */ + int if_succeeded; /* true if a leg of this if-group * has been passed through rescan */ - unsigned char *control_macro; /* For #ifndef at start of file, - * this is the macro name tested. */ - enum node_type type; /* type of last directive seen in this group */ - }; - typedef struct if_stack IF_STACK_FRAME; + unsigned char *control_macro; /* For #ifndef at start of file, + * this is the macro name tested. */ + enum node_type type; /* type of last directive seen in this group */ +}; +typedef struct if_stack IF_STACK_FRAME; - extern void cpp_buf_line_and_col PARAMS((cpp_buffer *, long *, long *)); - extern cpp_buffer *cpp_file_buffer PARAMS((cpp_reader *)); - extern void cpp_define PARAMS((cpp_reader *, unsigned char *)); +extern void cpp_buf_line_and_col(cpp_buffer *, long *, long *); +extern cpp_buffer *cpp_file_buffer(cpp_reader *); +extern void cpp_define(cpp_reader *, unsigned char *); - extern void cpp_error(); - extern void cpp_warning(); - extern void cpp_pedwarn(); - extern void cpp_error_with_line(); - extern void cpp_pedwarn_with_line(); - extern void cpp_pedwarn_with_file_and_line(); - extern void fatal(); - extern void cpp_error_from_errno(); - extern void cpp_perror_with_name(); - extern void cpp_pfatal_with_name(); +extern void cpp_error(cpp_reader * pfile, const char *msg, ...); +extern void cpp_warning(cpp_reader * pfile, const char *msg, ...); +extern void cpp_pedwarn(cpp_reader * pfile, const char *msg, ...); +extern void cpp_fatal(const char *msg, ...); +extern void cpp_file_line_for_message(cpp_reader * pfile, + const char *filename, int line, + int column); +extern void cpp_perror_with_name(cpp_reader * pfile, const char *name); +extern void cpp_pfatal_with_name(cpp_reader * pfile, const char *name); +extern void cpp_message(cpp_reader * pfile, int is_error, + const char *msg, ...); +extern void cpp_message_v(cpp_reader * pfile, int is_error, + const char *msg, va_list args); - extern void cpp_grow_buffer PARAMS((cpp_reader *, long)); - extern int cpp_parse_escape PARAMS((cpp_reader *, char **)); - extern cpp_buffer *cpp_push_buffer - PARAMS((cpp_reader *, unsigned char *, long)); - extern cpp_buffer *cpp_pop_buffer PARAMS((cpp_reader *)); +extern void cpp_grow_buffer(cpp_reader * pfile, long n); +extern int cpp_parse_escape(cpp_reader * pfile, char **string_ptr); - extern cpp_hashnode *cpp_lookup PARAMS((cpp_reader *, const unsigned char *, - int, int)); +void cpp_print_containing_files(cpp_reader * pfile); +HOST_WIDE_INT cpp_parse_expr(cpp_reader * pfile); +void skip_rest_of_line(cpp_reader * pfile); +void init_parse_file(cpp_reader * pfile); +void init_parse_options(struct cpp_options *opts); +int push_parse_file(cpp_reader * pfile, const char *fname); +void cpp_finish(cpp_reader * pfile); +int cpp_read_check_assertion(cpp_reader * pfile); + +void *xmalloc(unsigned size); +void *xrealloc(void *old, unsigned size); +void *xcalloc(unsigned number, unsigned size); #ifdef __EMX__ #define PATH_SEPARATOR ';' #endif - -#ifdef __cplusplus -} -#endif diff --git a/epp/cppmain.c b/epp/cppmain.c index 8432d9c1..85b121dc 100644 --- a/epp/cppmain.c +++ b/epp/cppmain.c @@ -20,31 +20,18 @@ * You are forbidden to forbid anyone else to use, share and improve * what you give them. Help stamp out software-hoarding! */ -#include "header.h" #include #include #include #include "config.h" - -extern char *getenv(); +#include "cpplib.h" cpp_reader parse_in; cpp_options options; -/* More 'friendly' abort that prints the line and file. - * config.h can #define abort fancy_abort if you like that sort of thing. */ - -void -fancy_abort() -{ - fatal("Internal gcc abort."); -} - int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { char *p; int i; @@ -67,7 +54,7 @@ main(argc, argv) argi += cpp_handle_options(&parse_in, argc - argi, argv + argi); if (argi < argc) - fatal("Invalid option `%s'", argv[argi]); + cpp_fatal("Invalid option `%s'", argv[argi]); parse_in.show_column = 1; i = push_parse_file(&parse_in, opts->in_fname); diff --git a/epp/header.h b/epp/header.h deleted file mode 100644 index c2dc2538..00000000 --- a/epp/header.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * declares.h - * This is a file with some declarations in it to get everyone to shut up :) - * --Mandrake - */ - -#include "cpplib.h" - -#ifndef HOST_BITS_PER_WIDE_INT - -#if HOST_BITS_PER_LONG > HOST_BITS_PER_INT -#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG -#define HOST_WIDE_INT long -#else -#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT -#define HOST_WIDE_INT int -#endif - -#endif - -struct directive -{ - int length; - int (*func) (); - char *name; - enum node_type type; - char command_reads_line; - char traditional_comments; - char pass_thru; -}; - -void *xmalloc(unsigned size); -void *xrealloc(void *old, unsigned size); -void *xcalloc(unsigned number, unsigned size); -void cpp_print_containing_files(cpp_reader * pfile); -void cpp_file_line_for_message(cpp_reader * pfile, - char *filename, int line, - - int column); -void cpp_message(cpp_reader * pfile, int is_error, char *msg, - char *arg1, char *arg2, char *arg3); -void cpp_pfatal_with_name(cpp_reader * pfile, char *name); -struct operation parse_number(cpp_reader * pfile, char *start, int olen); -struct operation cpp_lex(cpp_reader * pfile); -int cpp_parse_escape(cpp_reader * pfile, char **string_ptr); -HOST_WIDE_INT cpp_parse_expr(cpp_reader * pfile); -void cpp_grow_buffer(cpp_reader * pfile, long n); -void cpp_define(cpp_reader * pfile, unsigned char *str); -void init_parse_options(struct cpp_options *opts); -enum cpp_token null_underflow(cpp_reader * pfile); -int null_cleanup(cpp_buffer * pbuf, cpp_reader * pfile); -int macro_cleanup(cpp_buffer * pbuf, cpp_reader * pfile); -int file_cleanup(cpp_buffer * pbuf, cpp_reader * pfile); -void cpp_skip_hspace(cpp_reader * pfile); -void copy_rest_of_line(cpp_reader * pfile); -void skip_rest_of_line(cpp_reader * pfile); -int handle_directive(cpp_reader * pfile); -cpp_buffer *cpp_push_buffer(cpp_reader * pfile, unsigned char *buffer, - - long length); -cpp_buffer *cpp_pop_buffer(cpp_reader * pfile); -void cpp_scan_buffer(cpp_reader * pfile); -void cpp_buf_line_and_col(cpp_buffer * pbuf, long *linep, - - long *colp); -int hashf(const unsigned char *name, int len, int hashsize); -void cpp_hash_cleanup(cpp_reader * pfile); -int cpp_read_check(cpp_reader * pfile); -int parse_name(cpp_reader * pfile, int c); -void init_parse_file(cpp_reader * pfile); -void init_parse_options(struct cpp_options *opts); -int push_parse_file(cpp_reader * pfile, char *fname); -void cpp_finish(cpp_reader * pfile); -cpp_buffer *cpp_file_buffer(cpp_reader * pfile); -int cpp_read_check_assertion(cpp_reader * pfile); -void fancy_abort(void); -enum cpp_token cpp_get_token(cpp_reader * pfile); -enum cpp_token cpp_get_non_space_token(cpp_reader * pfile); -int cpp_handle_options(cpp_reader * pfile, int argc, - - char **argv); -void cpp_print_file_and_line(cpp_reader * pfile);