X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/b23b5a5b7dca39b708015979ed8c25901390ac14..3bace81626cc6ecdffc7901f3d03aa051d18c0af:/lib-src/ebrowse.c diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c index 2cb656ae53..a1fe10b863 100644 --- a/lib-src/ebrowse.c +++ b/lib-src/ebrowse.c @@ -1,6 +1,6 @@ /* ebrowse.c --- parsing files for the ebrowse C++ browser -Copyright (C) 1992-2011 Free Software Foundation, Inc. +Copyright (C) 1992-2012 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -20,11 +20,7 @@ along with GNU Emacs. If not, see . */ #include #include - -#ifdef HAVE_STDLIB_H #include -#endif - #include #include #include @@ -41,12 +37,7 @@ along with GNU Emacs. If not, see . */ #define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0) -/* The ubiquitous `max' and `min' macros. */ - -#ifndef max -#define max(X, Y) ((X) > (Y) ? (X) : (Y)) -#define min(X, Y) ((X) < (Y) ? (X) : (Y)) -#endif +#include /* Files are read in chunks of this number of bytes. */ @@ -54,16 +45,16 @@ along with GNU Emacs. If not, see . */ /* The character used as a separator in path lists (like $PATH). */ -#if defined(__MSDOS__) +#if defined (__MSDOS__) #define PATH_LIST_SEPARATOR ';' -#define FILENAME_EQ(X,Y) (strcasecmp(X,Y) == 0) +#define FILENAME_EQ(X,Y) (strcasecmp (X,Y) == 0) #else -#if defined(WINDOWSNT) +#if defined (WINDOWSNT) #define PATH_LIST_SEPARATOR ';' -#define FILENAME_EQ(X,Y) (stricmp(X,Y) == 0) +#define FILENAME_EQ(X,Y) (stricmp (X,Y) == 0) #else #define PATH_LIST_SEPARATOR ':' -#define FILENAME_EQ(X,Y) (streq(X,Y)) +#define FILENAME_EQ(X,Y) (streq (X,Y)) #endif #endif /* The default output file name. */ @@ -82,7 +73,6 @@ along with GNU Emacs. If not, see . */ #define TREE_HEADER_STRUCT "[ebrowse-hs " #define TREE_STRUCT "[ebrowse-ts " #define MEMBER_STRUCT "[ebrowse-ms " -#define BROWSE_STRUCT "[ebrowse-bs " #define CLASS_STRUCT "[ebrowse-cs " /* The name of the symbol table entry for global functions, variables, @@ -384,7 +374,7 @@ int max_regexp = 50; char *inbuffer; char *in; -int inbuffer_size; +size_t inbuffer_size; /* Return the current buffer position in the input file. */ @@ -498,7 +488,7 @@ yyerror (const char *format, const char *s) available. */ static void * -xmalloc (int nbytes) +xmalloc (size_t nbytes) { void *p = malloc (nbytes); if (p == NULL) @@ -513,7 +503,7 @@ xmalloc (int nbytes) /* Like realloc but print an error and exit if out of memory. */ static void * -xrealloc (void *p, int sz) +xrealloc (void *p, size_t sz) { p = realloc (p, sz); if (p == NULL) @@ -991,7 +981,7 @@ make_namespace (char *name, struct sym *context) } -/* Find the symbol for namespace NAME. If not found, retrun NULL */ +/* Find the symbol for namespace NAME. If not found, return NULL */ static struct sym * check_namespace (char *name, struct sym *context) @@ -1113,22 +1103,23 @@ leave_namespace (void) /* Write string S to the output file FP in a Lisp-readable form. If S is null, write out `()'. */ -#define PUTSTR(s, fp) \ - do { \ - if (!s) \ - { \ - putc ('(', fp); \ - putc (')', fp); \ - putc (' ', fp); \ - } \ - else \ - { \ - putc ('"', fp); \ - fputs (s, fp); \ - putc ('"', fp); \ - putc (' ', fp); \ - } \ - } while (0) +static inline void +putstr (const char *s, FILE *fp) +{ + if (!s) + { + putc ('(', fp); + putc (')', fp); + putc (' ', fp); + } + else + { + putc ('"', fp); + fputs (s, fp); + putc ('"', fp); + putc (' ', fp); + } +} /* A dynamically allocated buffer for constructing a scope name. */ @@ -1221,16 +1212,16 @@ dump_members (FILE *fp, struct member *m) for (n = 0; m; m = m->next, ++n) { fputs (MEMBER_STRUCT, fp); - PUTSTR (m->name, fp); - PUTSTR (NULL, fp); /* FIXME? scope for globals */ + putstr (m->name, fp); + putstr (NULL, fp); /* FIXME? scope for globals */ fprintf (fp, "%u ", (unsigned) m->flags); - PUTSTR (m->filename, fp); - PUTSTR (m->regexp, fp); + putstr (m->filename, fp); + putstr (m->regexp, fp); fprintf (fp, "%u ", (unsigned) m->pos); fprintf (fp, "%u ", (unsigned) m->vis); putc (' ', fp); - PUTSTR (m->def_filename, fp); - PUTSTR (m->def_regexp, fp); + putstr (m->def_filename, fp); + putstr (m->def_regexp, fp); fprintf (fp, "%u", (unsigned) m->def_pos); putc (']', fp); putc ('\n', fp); @@ -1248,20 +1239,20 @@ static void dump_sym (FILE *fp, struct sym *root) { fputs (CLASS_STRUCT, fp); - PUTSTR (root->name, fp); + putstr (root->name, fp); /* Print scope, if any. */ if (root->namesp) - PUTSTR (sym_scope (root), fp); + putstr (sym_scope (root), fp); else - PUTSTR (NULL, fp); + putstr (NULL, fp); /* Print flags. */ fprintf (fp, "%u", root->flags); - PUTSTR (root->filename, fp); - PUTSTR (root->regexp, fp); + putstr (root->filename, fp); + putstr (root->regexp, fp); fprintf (fp, "%u", (unsigned) root->pos); - PUTSTR (root->sfilename, fp); + putstr (root->sfilename, fp); putc (']', fp); putc ('\n', fp); } @@ -1328,7 +1319,7 @@ dump_roots (FILE *fp) if (!f_append) { fputs (TREE_HEADER_STRUCT, fp); - PUTSTR (EBROWSE_FILE_VERSION, fp); + putstr (EBROWSE_FILE_VERSION, fp); putc ('\"', fp); if (!f_structs) @@ -2067,11 +2058,11 @@ re_init_scanner (void) } -/* Insert a keyword NAME with token value TK into the keyword hash +/* Insert a keyword NAME with token value TKV into the keyword hash table. */ static void -insert_keyword (const char *name, int tk) +insert_keyword (const char *name, int tkv) { const char *s; unsigned h = 0; @@ -2082,7 +2073,7 @@ insert_keyword (const char *name, int tk) h %= KEYWORD_TABLE_SIZE; k->name = name; - k->tk = tk; + k->tk = tkv; k->next = keyword_table[h]; keyword_table[h] = k; } @@ -2520,7 +2511,7 @@ member (struct sym *cls, int vis) /* A function or class may follow. */ case TEMPLATE: - MATCH(); + MATCH (); SET_FLAG (flags, F_TEMPLATE); /* Skip over template argument list */ SKIP_MATCHING_IF ('<'); @@ -2797,10 +2788,10 @@ parse_classname (void) static char * operator_name (int *sc) { - static int id_size = 0; + static size_t id_size = 0; static char *id = NULL; const char *s; - int len; + size_t len; MATCH (); @@ -2816,7 +2807,7 @@ operator_name (int *sc) len = strlen (s) + 10; if (len > id_size) { - int new_size = max (len, 2 * id_size); + size_t new_size = max (len, 2 * id_size); id = (char *) xrealloc (id, new_size); id_size = new_size; } @@ -2837,7 +2828,7 @@ operator_name (int *sc) } else { - int tokens_matched = 0; + size_t tokens_matched = 0; len = 20; if (len > id_size) @@ -2858,7 +2849,7 @@ operator_name (int *sc) len += strlen (s) + 2; if (len > id_size) { - int new_size = max (len, 2 * id_size); + size_t new_size = max (len, 2 * id_size); id = (char *) xrealloc (id, new_size); id_size = new_size; } @@ -2939,7 +2930,7 @@ parse_qualified_ident_or_type (char **last_id) } while (enter--) - leave_namespace(); + leave_namespace (); return cls; } @@ -2956,7 +2947,9 @@ parse_qualified_param_ident_or_type (char **last_id) static char *id = NULL; static int id_size = 0; - while (LOOKING_AT (IDENT)) + assert (LOOKING_AT (IDENT)); + + do { int len = strlen (yytext) + 1; if (len > id_size) @@ -2979,6 +2972,7 @@ parse_qualified_param_ident_or_type (char **last_id) else break; } + while (LOOKING_AT (IDENT)); } @@ -3532,7 +3526,7 @@ static void version (void) { /* Makes it easier to update automatically. */ - char emacs_copyright[] = "Copyright (C) 2011 Free Software Foundation, Inc."; + char emacs_copyright[] = "Copyright (C) 2012 Free Software Foundation, Inc."; printf ("ebrowse %s\n", VERSION); puts (emacs_copyright); @@ -3552,7 +3546,7 @@ process_file (char *file) fp = open_file (file); if (fp) { - int nread, nbytes; + size_t nread, nbytes; /* Give a progress indication if needed. */ if (f_very_verbose) @@ -3576,12 +3570,10 @@ process_file (char *file) } nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp); - if (nbytes <= 0) + if (nbytes == 0) break; nread += nbytes; } - if (nread < 0) - nread = 0; inbuffer[nread] = '\0'; /* Reinitialize scanner and parser for the new input file. */