aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/ebrowse.c
diff options
context:
space:
mode:
authorJoakim Verona2011-06-16 00:22:07 +0200
committerJoakim Verona2011-06-16 00:22:07 +0200
commita7513ade3bc0fe79430d5541d88c9dcda0932bec (patch)
tree4383951ba698a11e9f8933a9d8c72e00aa872a10 /lib-src/ebrowse.c
parent4bd51ad5c3445b644dfb017d5b57b10a90aa325f (diff)
parent4bba86e6210a74326e843a8fdc8409127105e1fe (diff)
downloademacs-a7513ade3bc0fe79430d5541d88c9dcda0932bec.tar.gz
emacs-a7513ade3bc0fe79430d5541d88c9dcda0932bec.zip
merge from upstream
Diffstat (limited to 'lib-src/ebrowse.c')
-rw-r--r--lib-src/ebrowse.c285
1 files changed, 119 insertions, 166 deletions
diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c
index 59a1dde7634..7871a804997 100644
--- a/lib-src/ebrowse.c
+++ b/lib-src/ebrowse.c
@@ -41,12 +41,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
41 41
42#define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0) 42#define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0)
43 43
44/* The ubiquitous `max' and `min' macros. */ 44#include <min-max.h>
45
46#ifndef max
47#define max(X, Y) ((X) > (Y) ? (X) : (Y))
48#define min(X, Y) ((X) < (Y) ? (X) : (Y))
49#endif
50 45
51/* Files are read in chunks of this number of bytes. */ 46/* Files are read in chunks of this number of bytes. */
52 47
@@ -82,7 +77,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
82#define TREE_HEADER_STRUCT "[ebrowse-hs " 77#define TREE_HEADER_STRUCT "[ebrowse-hs "
83#define TREE_STRUCT "[ebrowse-ts " 78#define TREE_STRUCT "[ebrowse-ts "
84#define MEMBER_STRUCT "[ebrowse-ms " 79#define MEMBER_STRUCT "[ebrowse-ms "
85#define BROWSE_STRUCT "[ebrowse-bs "
86#define CLASS_STRUCT "[ebrowse-cs " 80#define CLASS_STRUCT "[ebrowse-cs "
87 81
88/* The name of the symbol table entry for global functions, variables, 82/* The name of the symbol table entry for global functions, variables,
@@ -384,7 +378,7 @@ int max_regexp = 50;
384 378
385char *inbuffer; 379char *inbuffer;
386char *in; 380char *in;
387int inbuffer_size; 381size_t inbuffer_size;
388 382
389/* Return the current buffer position in the input file. */ 383/* Return the current buffer position in the input file. */
390 384
@@ -465,59 +459,16 @@ struct search_path *search_path_tail;
465 459
466/* Function prototypes. */ 460/* Function prototypes. */
467 461
468int yylex (void); 462static char *matching_regexp (void);
469void yyparse (void); 463static struct sym *add_sym (const char *, struct sym *);
470void re_init_parser (void); 464static void add_global_defn (char *, char *, int, unsigned, int, int, int);
471const char *token_string (int); 465static void add_global_decl (char *, char *, int, unsigned, int, int, int);
472char *matching_regexp (void); 466static struct member *add_member (struct sym *, char *, int, int, unsigned);
473void init_sym (void); 467static void class_definition (struct sym *, int, int, int);
474struct sym *add_sym (const char *, struct sym *); 468static char *operator_name (int *);
475void add_link (struct sym *, struct sym *); 469static void parse_qualified_param_ident_or_type (char **);
476void add_member_defn (struct sym *, char *, char *, 470static void usage (int) NO_RETURN;
477 int, unsigned, int, int, int); 471static void version (void) NO_RETURN;
478void add_member_decl (struct sym *, char *, char *, int,
479 unsigned, int, int, int, int);
480void dump_roots (FILE *);
481void *xmalloc (int);
482void xfree (void *);
483void add_global_defn (char *, char *, int, unsigned, int, int, int);
484void add_global_decl (char *, char *, int, unsigned, int, int, int);
485void add_define (char *, char *, int);
486void mark_inherited_virtual (void);
487void leave_namespace (void);
488void enter_namespace (char *);
489void register_namespace_alias (char *, struct link *);
490void insert_keyword (const char *, int);
491void re_init_scanner (void);
492void init_scanner (void);
493void process_file (char *);
494void add_search_path (char *);
495FILE *open_file (char *);
496int process_pp_line (void);
497int dump_members (FILE *, struct member *);
498void dump_sym (FILE *, struct sym *);
499int dump_tree (FILE *, struct sym *);
500struct member *find_member (struct sym *, char *, int, int, unsigned);
501struct member *add_member (struct sym *, char *, int, int, unsigned);
502void mark_virtual (struct sym *);
503struct sym *make_namespace (char *, struct sym *);
504char *sym_scope (struct sym *);
505char *sym_scope_1 (struct sym *);
506int skip_to (int);
507void skip_matching (void);
508void member (struct sym *, int);
509void class_body (struct sym *, int);
510void class_definition (struct sym *, int, int, int);
511void declaration (int);
512unsigned parm_list (int *);
513char *operator_name (int *);
514struct sym *parse_classname (void);
515struct sym *parse_qualified_ident_or_type (char **);
516void parse_qualified_param_ident_or_type (char **);
517int globals (int);
518void yyerror (const char *, const char *);
519void usage (int) NO_RETURN;
520void version (void) NO_RETURN;
521 472
522 473
523 474
@@ -528,7 +479,7 @@ void version (void) NO_RETURN;
528/* Print an error in a printf-like style with the current input file 479/* Print an error in a printf-like style with the current input file
529 name and line number. */ 480 name and line number. */
530 481
531void 482static void
532yyerror (const char *format, const char *s) 483yyerror (const char *format, const char *s)
533{ 484{
534 fprintf (stderr, "%s:%d: ", filename, yyline); 485 fprintf (stderr, "%s:%d: ", filename, yyline);
@@ -540,8 +491,8 @@ yyerror (const char *format, const char *s)
540/* Like malloc but print an error and exit if not enough memory is 491/* Like malloc but print an error and exit if not enough memory is
541 available. */ 492 available. */
542 493
543void * 494static void *
544xmalloc (int nbytes) 495xmalloc (size_t nbytes)
545{ 496{
546 void *p = malloc (nbytes); 497 void *p = malloc (nbytes);
547 if (p == NULL) 498 if (p == NULL)
@@ -555,8 +506,8 @@ xmalloc (int nbytes)
555 506
556/* Like realloc but print an error and exit if out of memory. */ 507/* Like realloc but print an error and exit if out of memory. */
557 508
558void * 509static void *
559xrealloc (void *p, int sz) 510xrealloc (void *p, size_t sz)
560{ 511{
561 p = realloc (p, sz); 512 p = realloc (p, sz);
562 if (p == NULL) 513 if (p == NULL)
@@ -571,7 +522,7 @@ xrealloc (void *p, int sz)
571/* Like strdup, but print an error and exit if not enough memory is 522/* Like strdup, but print an error and exit if not enough memory is
572 available.. If S is null, return null. */ 523 available.. If S is null, return null. */
573 524
574char * 525static char *
575xstrdup (char *s) 526xstrdup (char *s)
576{ 527{
577 if (s) 528 if (s)
@@ -588,7 +539,7 @@ xstrdup (char *s)
588/* Initialize the symbol table. This currently only sets up the 539/* Initialize the symbol table. This currently only sets up the
589 special symbol for globals (`*Globals*'). */ 540 special symbol for globals (`*Globals*'). */
590 541
591void 542static void
592init_sym (void) 543init_sym (void)
593{ 544{
594 global_symbols = add_sym (GLOBALS_NAME, NULL); 545 global_symbols = add_sym (GLOBALS_NAME, NULL);
@@ -602,7 +553,7 @@ init_sym (void)
602 If a symbol for NAME already exists, return that. Otherwise 553 If a symbol for NAME already exists, return that. Otherwise
603 create a new symbol and set it to default values. */ 554 create a new symbol and set it to default values. */
604 555
605struct sym * 556static struct sym *
606add_sym (const char *name, struct sym *nested_in_class) 557add_sym (const char *name, struct sym *nested_in_class)
607{ 558{
608 struct sym *sym; 559 struct sym *sym;
@@ -643,7 +594,7 @@ add_sym (const char *name, struct sym *nested_in_class)
643 594
644/* Add links between superclass SUPER and subclass SUB. */ 595/* Add links between superclass SUPER and subclass SUB. */
645 596
646void 597static void
647add_link (struct sym *super, struct sym *sub) 598add_link (struct sym *super, struct sym *sub)
648{ 599{
649 struct link *lnk, *lnk2, *p, *prev; 600 struct link *lnk, *lnk2, *p, *prev;
@@ -683,7 +634,7 @@ add_link (struct sym *super, struct sym *sub)
683 parameter types of functions. Value is a pointer to the member 634 parameter types of functions. Value is a pointer to the member
684 found or null if not found. */ 635 found or null if not found. */
685 636
686struct member * 637static struct member *
687find_member (struct sym *cls, char *name, int var, int sc, unsigned int hash) 638find_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
688{ 639{
689 struct member **list; 640 struct member **list;
@@ -733,7 +684,7 @@ find_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
733 a bit set giving additional information about the member (see the 684 a bit set giving additional information about the member (see the
734 F_* defines). */ 685 F_* defines). */
735 686
736void 687static void
737add_member_decl (struct sym *cls, char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int vis, int flags) 688add_member_decl (struct sym *cls, char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int vis, int flags)
738{ 689{
739 struct member *m; 690 struct member *m;
@@ -781,7 +732,7 @@ add_member_decl (struct sym *cls, char *name, char *regexp, int pos, unsigned in
781 a bit set giving additional information about the member (see the 732 a bit set giving additional information about the member (see the
782 F_* defines). */ 733 F_* defines). */
783 734
784void 735static void
785add_member_defn (struct sym *cls, char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags) 736add_member_defn (struct sym *cls, char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
786{ 737{
787 struct member *m; 738 struct member *m;
@@ -823,7 +774,7 @@ add_member_defn (struct sym *cls, char *name, char *regexp, int pos, unsigned in
823 REGEXP is a regular expression matching the define in the source, 774 REGEXP is a regular expression matching the define in the source,
824 if it is non-null. POS is the position in the file. */ 775 if it is non-null. POS is the position in the file. */
825 776
826void 777static void
827add_define (char *name, char *regexp, int pos) 778add_define (char *name, char *regexp, int pos)
828{ 779{
829 add_global_defn (name, regexp, pos, 0, 1, SC_FRIEND, F_DEFINE); 780 add_global_defn (name, regexp, pos, 0, 1, SC_FRIEND, F_DEFINE);
@@ -841,7 +792,7 @@ add_define (char *name, char *regexp, int pos)
841 a bit set giving additional information about the member (see the 792 a bit set giving additional information about the member (see the
842 F_* defines). */ 793 F_* defines). */
843 794
844void 795static void
845add_global_defn (char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags) 796add_global_defn (char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
846{ 797{
847 int i; 798 int i;
@@ -872,7 +823,7 @@ add_global_defn (char *name, char *regexp, int pos, unsigned int hash, int var,
872 a bit set giving additional information about the member (see the 823 a bit set giving additional information about the member (see the
873 F_* defines). */ 824 F_* defines). */
874 825
875void 826static void
876add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags) 827add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
877{ 828{
878 /* Add declaration only if not already declared. Header files must 829 /* Add declaration only if not already declared. Header files must
@@ -911,7 +862,7 @@ add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var,
911 member. HASH is a hash code for the parameter types of a function. 862 member. HASH is a hash code for the parameter types of a function.
912 Value is a pointer to the member's structure. */ 863 Value is a pointer to the member's structure. */
913 864
914struct member * 865static struct member *
915add_member (struct sym *cls, char *name, int var, int sc, unsigned int hash) 866add_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
916{ 867{
917 struct member *m = (struct member *) xmalloc (sizeof *m + strlen (name)); 868 struct member *m = (struct member *) xmalloc (sizeof *m + strlen (name));
@@ -982,7 +933,7 @@ add_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
982 recursively, marking functions as virtual that are declared virtual 933 recursively, marking functions as virtual that are declared virtual
983 in base classes. */ 934 in base classes. */
984 935
985void 936static void
986mark_virtual (struct sym *r) 937mark_virtual (struct sym *r)
987{ 938{
988 struct link *p; 939 struct link *p;
@@ -1006,7 +957,7 @@ mark_virtual (struct sym *r)
1006/* For all roots of the class tree, mark functions as virtual that 957/* For all roots of the class tree, mark functions as virtual that
1007 are virtual because of a virtual declaration in a base class. */ 958 are virtual because of a virtual declaration in a base class. */
1008 959
1009void 960static void
1010mark_inherited_virtual (void) 961mark_inherited_virtual (void)
1011{ 962{
1012 struct sym *r; 963 struct sym *r;
@@ -1021,7 +972,7 @@ mark_inherited_virtual (void)
1021 972
1022/* Create and return a symbol for a namespace with name NAME. */ 973/* Create and return a symbol for a namespace with name NAME. */
1023 974
1024struct sym * 975static struct sym *
1025make_namespace (char *name, struct sym *context) 976make_namespace (char *name, struct sym *context)
1026{ 977{
1027 struct sym *s = (struct sym *) xmalloc (sizeof *s + strlen (name)); 978 struct sym *s = (struct sym *) xmalloc (sizeof *s + strlen (name));
@@ -1036,7 +987,7 @@ make_namespace (char *name, struct sym *context)
1036 987
1037/* Find the symbol for namespace NAME. If not found, retrun NULL */ 988/* Find the symbol for namespace NAME. If not found, retrun NULL */
1038 989
1039struct sym * 990static struct sym *
1040check_namespace (char *name, struct sym *context) 991check_namespace (char *name, struct sym *context)
1041{ 992{
1042 struct sym *p = NULL; 993 struct sym *p = NULL;
@@ -1053,7 +1004,7 @@ check_namespace (char *name, struct sym *context)
1053/* Find the symbol for namespace NAME. If not found, add a new symbol 1004/* Find the symbol for namespace NAME. If not found, add a new symbol
1054 for NAME to all_namespaces. */ 1005 for NAME to all_namespaces. */
1055 1006
1056struct sym * 1007static struct sym *
1057find_namespace (char *name, struct sym *context) 1008find_namespace (char *name, struct sym *context)
1058{ 1009{
1059 struct sym *p = check_namespace (name, context); 1010 struct sym *p = check_namespace (name, context);
@@ -1067,7 +1018,7 @@ find_namespace (char *name, struct sym *context)
1067 1018
1068/* Find namespace alias with name NAME. If not found return NULL. */ 1019/* Find namespace alias with name NAME. If not found return NULL. */
1069 1020
1070struct link * 1021static struct link *
1071check_namespace_alias (char *name) 1022check_namespace_alias (char *name)
1072{ 1023{
1073 struct link *p = NULL; 1024 struct link *p = NULL;
@@ -1091,7 +1042,7 @@ check_namespace_alias (char *name)
1091 1042
1092/* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */ 1043/* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */
1093 1044
1094void 1045static void
1095register_namespace_alias (char *new_name, struct link *old_name) 1046register_namespace_alias (char *new_name, struct link *old_name)
1096{ 1047{
1097 unsigned h; 1048 unsigned h;
@@ -1119,7 +1070,7 @@ register_namespace_alias (char *new_name, struct link *old_name)
1119 1070
1120/* Enter namespace with name NAME. */ 1071/* Enter namespace with name NAME. */
1121 1072
1122void 1073static void
1123enter_namespace (char *name) 1074enter_namespace (char *name)
1124{ 1075{
1125 struct sym *p = find_namespace (name, current_namespace); 1076 struct sym *p = find_namespace (name, current_namespace);
@@ -1140,7 +1091,7 @@ enter_namespace (char *name)
1140 1091
1141/* Leave the current namespace. */ 1092/* Leave the current namespace. */
1142 1093
1143void 1094static void
1144leave_namespace (void) 1095leave_namespace (void)
1145{ 1096{
1146 assert (namespace_sp > 0); 1097 assert (namespace_sp > 0);
@@ -1156,22 +1107,23 @@ leave_namespace (void)
1156/* Write string S to the output file FP in a Lisp-readable form. 1107/* Write string S to the output file FP in a Lisp-readable form.
1157 If S is null, write out `()'. */ 1108 If S is null, write out `()'. */
1158 1109
1159#define PUTSTR(s, fp) \ 1110static inline void
1160 do { \ 1111putstr (const char *s, FILE *fp)
1161 if (!s) \ 1112{
1162 { \ 1113 if (!s)
1163 putc ('(', fp); \ 1114 {
1164 putc (')', fp); \ 1115 putc ('(', fp);
1165 putc (' ', fp); \ 1116 putc (')', fp);
1166 } \ 1117 putc (' ', fp);
1167 else \ 1118 }
1168 { \ 1119 else
1169 putc ('"', fp); \ 1120 {
1170 fputs (s, fp); \ 1121 putc ('"', fp);
1171 putc ('"', fp); \ 1122 fputs (s, fp);
1172 putc (' ', fp); \ 1123 putc ('"', fp);
1173 } \ 1124 putc (' ', fp);
1174 } while (0) 1125 }
1126}
1175 1127
1176/* A dynamically allocated buffer for constructing a scope name. */ 1128/* A dynamically allocated buffer for constructing a scope name. */
1177 1129
@@ -1182,7 +1134,7 @@ int scope_buffer_len;
1182 1134
1183/* Make sure scope_buffer has enough room to add LEN chars to it. */ 1135/* Make sure scope_buffer has enough room to add LEN chars to it. */
1184 1136
1185void 1137static void
1186ensure_scope_buffer_room (int len) 1138ensure_scope_buffer_room (int len)
1187{ 1139{
1188 if (scope_buffer_len + len >= scope_buffer_size) 1140 if (scope_buffer_len + len >= scope_buffer_size)
@@ -1198,7 +1150,7 @@ ensure_scope_buffer_room (int len)
1198 namespaces to scope_buffer. Value is a pointer to the complete 1150 namespaces to scope_buffer. Value is a pointer to the complete
1199 scope name constructed. */ 1151 scope name constructed. */
1200 1152
1201char * 1153static char *
1202sym_scope_1 (struct sym *p) 1154sym_scope_1 (struct sym *p)
1203{ 1155{
1204 int len; 1156 int len;
@@ -1232,7 +1184,7 @@ sym_scope_1 (struct sym *p)
1232/* Return the scope of symbol P in printed representation, i.e. 1184/* Return the scope of symbol P in printed representation, i.e.
1233 as it would appear in a C*+ source file. */ 1185 as it would appear in a C*+ source file. */
1234 1186
1235char * 1187static char *
1236sym_scope (struct sym *p) 1188sym_scope (struct sym *p)
1237{ 1189{
1238 if (!scope_buffer) 1190 if (!scope_buffer)
@@ -1254,7 +1206,7 @@ sym_scope (struct sym *p)
1254/* Dump the list of members M to file FP. Value is the length of the 1206/* Dump the list of members M to file FP. Value is the length of the
1255 list. */ 1207 list. */
1256 1208
1257int 1209static int
1258dump_members (FILE *fp, struct member *m) 1210dump_members (FILE *fp, struct member *m)
1259{ 1211{
1260 int n; 1212 int n;
@@ -1264,16 +1216,16 @@ dump_members (FILE *fp, struct member *m)
1264 for (n = 0; m; m = m->next, ++n) 1216 for (n = 0; m; m = m->next, ++n)
1265 { 1217 {
1266 fputs (MEMBER_STRUCT, fp); 1218 fputs (MEMBER_STRUCT, fp);
1267 PUTSTR (m->name, fp); 1219 putstr (m->name, fp);
1268 PUTSTR (NULL, fp); /* FIXME? scope for globals */ 1220 putstr (NULL, fp); /* FIXME? scope for globals */
1269 fprintf (fp, "%u ", (unsigned) m->flags); 1221 fprintf (fp, "%u ", (unsigned) m->flags);
1270 PUTSTR (m->filename, fp); 1222 putstr (m->filename, fp);
1271 PUTSTR (m->regexp, fp); 1223 putstr (m->regexp, fp);
1272 fprintf (fp, "%u ", (unsigned) m->pos); 1224 fprintf (fp, "%u ", (unsigned) m->pos);
1273 fprintf (fp, "%u ", (unsigned) m->vis); 1225 fprintf (fp, "%u ", (unsigned) m->vis);
1274 putc (' ', fp); 1226 putc (' ', fp);
1275 PUTSTR (m->def_filename, fp); 1227 putstr (m->def_filename, fp);
1276 PUTSTR (m->def_regexp, fp); 1228 putstr (m->def_regexp, fp);
1277 fprintf (fp, "%u", (unsigned) m->def_pos); 1229 fprintf (fp, "%u", (unsigned) m->def_pos);
1278 putc (']', fp); 1230 putc (']', fp);
1279 putc ('\n', fp); 1231 putc ('\n', fp);
@@ -1287,24 +1239,24 @@ dump_members (FILE *fp, struct member *m)
1287 1239
1288/* Dump class ROOT to stream FP. */ 1240/* Dump class ROOT to stream FP. */
1289 1241
1290void 1242static void
1291dump_sym (FILE *fp, struct sym *root) 1243dump_sym (FILE *fp, struct sym *root)
1292{ 1244{
1293 fputs (CLASS_STRUCT, fp); 1245 fputs (CLASS_STRUCT, fp);
1294 PUTSTR (root->name, fp); 1246 putstr (root->name, fp);
1295 1247
1296 /* Print scope, if any. */ 1248 /* Print scope, if any. */
1297 if (root->namesp) 1249 if (root->namesp)
1298 PUTSTR (sym_scope (root), fp); 1250 putstr (sym_scope (root), fp);
1299 else 1251 else
1300 PUTSTR (NULL, fp); 1252 putstr (NULL, fp);
1301 1253
1302 /* Print flags. */ 1254 /* Print flags. */
1303 fprintf (fp, "%u", root->flags); 1255 fprintf (fp, "%u", root->flags);
1304 PUTSTR (root->filename, fp); 1256 putstr (root->filename, fp);
1305 PUTSTR (root->regexp, fp); 1257 putstr (root->regexp, fp);
1306 fprintf (fp, "%u", (unsigned) root->pos); 1258 fprintf (fp, "%u", (unsigned) root->pos);
1307 PUTSTR (root->sfilename, fp); 1259 putstr (root->sfilename, fp);
1308 putc (']', fp); 1260 putc (']', fp);
1309 putc ('\n', fp); 1261 putc ('\n', fp);
1310} 1262}
@@ -1313,7 +1265,7 @@ dump_sym (FILE *fp, struct sym *root)
1313/* Dump class ROOT and its subclasses to file FP. Value is the 1265/* Dump class ROOT and its subclasses to file FP. Value is the
1314 number of classes written. */ 1266 number of classes written. */
1315 1267
1316int 1268static int
1317dump_tree (FILE *fp, struct sym *root) 1269dump_tree (FILE *fp, struct sym *root)
1318{ 1270{
1319 struct link *lk; 1271 struct link *lk;
@@ -1360,7 +1312,7 @@ dump_tree (FILE *fp, struct sym *root)
1360 1312
1361/* Dump the entire class tree to file FP. */ 1313/* Dump the entire class tree to file FP. */
1362 1314
1363void 1315static void
1364dump_roots (FILE *fp) 1316dump_roots (FILE *fp)
1365{ 1317{
1366 int i, n = 0; 1318 int i, n = 0;
@@ -1371,7 +1323,7 @@ dump_roots (FILE *fp)
1371 if (!f_append) 1323 if (!f_append)
1372 { 1324 {
1373 fputs (TREE_HEADER_STRUCT, fp); 1325 fputs (TREE_HEADER_STRUCT, fp);
1374 PUTSTR (EBROWSE_FILE_VERSION, fp); 1326 putstr (EBROWSE_FILE_VERSION, fp);
1375 1327
1376 putc ('\"', fp); 1328 putc ('\"', fp);
1377 if (!f_structs) 1329 if (!f_structs)
@@ -1434,7 +1386,7 @@ do { \
1434/* Process a preprocessor line. Value is the next character from the 1386/* Process a preprocessor line. Value is the next character from the
1435 input buffer not consumed. */ 1387 input buffer not consumed. */
1436 1388
1437int 1389static int
1438process_pp_line (void) 1390process_pp_line (void)
1439{ 1391{
1440 int in_comment = 0, in_string = 0; 1392 int in_comment = 0, in_string = 0;
@@ -1505,7 +1457,7 @@ process_pp_line (void)
1505 1457
1506/* Value is the next token from the input buffer. */ 1458/* Value is the next token from the input buffer. */
1507 1459
1508int 1460static int
1509yylex (void) 1461yylex (void)
1510{ 1462{
1511 int c; 1463 int c;
@@ -1927,7 +1879,7 @@ static char *matching_regexp_buffer, *matching_regexp_end_buf;
1927 position in the input buffer, or maybe a bit more if that string is 1879 position in the input buffer, or maybe a bit more if that string is
1928 shorter than min_regexp. */ 1880 shorter than min_regexp. */
1929 1881
1930char * 1882static char *
1931matching_regexp (void) 1883matching_regexp (void)
1932{ 1884{
1933 char *p; 1885 char *p;
@@ -1978,7 +1930,7 @@ matching_regexp (void)
1978 1930
1979/* Return a printable representation of token T. */ 1931/* Return a printable representation of token T. */
1980 1932
1981const char * 1933static const char *
1982token_string (int t) 1934token_string (int t)
1983{ 1935{
1984 static char b[3]; 1936 static char b[3];
@@ -2095,7 +2047,7 @@ token_string (int t)
2095 2047
2096/* Reinitialize the scanner for a new input file. */ 2048/* Reinitialize the scanner for a new input file. */
2097 2049
2098void 2050static void
2099re_init_scanner (void) 2051re_init_scanner (void)
2100{ 2052{
2101 in = inbuffer; 2053 in = inbuffer;
@@ -2110,11 +2062,11 @@ re_init_scanner (void)
2110} 2062}
2111 2063
2112 2064
2113/* Insert a keyword NAME with token value TK into the keyword hash 2065/* Insert a keyword NAME with token value TKV into the keyword hash
2114 table. */ 2066 table. */
2115 2067
2116void 2068static void
2117insert_keyword (const char *name, int tk) 2069insert_keyword (const char *name, int tkv)
2118{ 2070{
2119 const char *s; 2071 const char *s;
2120 unsigned h = 0; 2072 unsigned h = 0;
@@ -2125,7 +2077,7 @@ insert_keyword (const char *name, int tk)
2125 2077
2126 h %= KEYWORD_TABLE_SIZE; 2078 h %= KEYWORD_TABLE_SIZE;
2127 k->name = name; 2079 k->name = name;
2128 k->tk = tk; 2080 k->tk = tkv;
2129 k->next = keyword_table[h]; 2081 k->next = keyword_table[h];
2130 keyword_table[h] = k; 2082 keyword_table[h] = k;
2131} 2083}
@@ -2134,7 +2086,7 @@ insert_keyword (const char *name, int tk)
2134/* Initialize the scanner for the first file. This sets up the 2086/* Initialize the scanner for the first file. This sets up the
2135 character class vectors and fills the keyword hash table. */ 2087 character class vectors and fills the keyword hash table. */
2136 2088
2137void 2089static void
2138init_scanner (void) 2090init_scanner (void)
2139{ 2091{
2140 int i; 2092 int i;
@@ -2278,7 +2230,7 @@ init_scanner (void)
2278/* Skip forward until a given token TOKEN or YYEOF is seen and return 2230/* Skip forward until a given token TOKEN or YYEOF is seen and return
2279 the current lookahead token after skipping. */ 2231 the current lookahead token after skipping. */
2280 2232
2281int 2233static int
2282skip_to (int token) 2234skip_to (int token)
2283{ 2235{
2284 while (!LOOKING_AT2 (YYEOF, token)) 2236 while (!LOOKING_AT2 (YYEOF, token))
@@ -2289,7 +2241,7 @@ skip_to (int token)
2289/* Skip over pairs of tokens (parentheses, square brackets, 2241/* Skip over pairs of tokens (parentheses, square brackets,
2290 angle brackets, curly brackets) matching the current lookahead. */ 2242 angle brackets, curly brackets) matching the current lookahead. */
2291 2243
2292void 2244static void
2293skip_matching (void) 2245skip_matching (void)
2294{ 2246{
2295 int open, close, n; 2247 int open, close, n;
@@ -2332,7 +2284,7 @@ skip_matching (void)
2332 } 2284 }
2333} 2285}
2334 2286
2335void 2287static void
2336skip_initializer (void) 2288skip_initializer (void)
2337{ 2289{
2338 for (;;) 2290 for (;;)
@@ -2359,7 +2311,7 @@ skip_initializer (void)
2359 2311
2360/* Build qualified namespace alias (A::B::c) and return it. */ 2312/* Build qualified namespace alias (A::B::c) and return it. */
2361 2313
2362struct link * 2314static struct link *
2363match_qualified_namespace_alias (void) 2315match_qualified_namespace_alias (void)
2364{ 2316{
2365 struct link *head = NULL; 2317 struct link *head = NULL;
@@ -2396,7 +2348,7 @@ match_qualified_namespace_alias (void)
2396 2348
2397/* Re-initialize the parser by resetting the lookahead token. */ 2349/* Re-initialize the parser by resetting the lookahead token. */
2398 2350
2399void 2351static void
2400re_init_parser (void) 2352re_init_parser (void)
2401{ 2353{
2402 tk = -1; 2354 tk = -1;
@@ -2409,7 +2361,7 @@ re_init_parser (void)
2409 Returns a hash code for the parameter types. This value is used to 2361 Returns a hash code for the parameter types. This value is used to
2410 distinguish between overloaded functions. */ 2362 distinguish between overloaded functions. */
2411 2363
2412unsigned 2364static unsigned
2413parm_list (int *flags) 2365parm_list (int *flags)
2414{ 2366{
2415 unsigned hash = 0; 2367 unsigned hash = 0;
@@ -2522,7 +2474,7 @@ parm_list (int *flags)
2522 2474
2523/* Print position info to stdout. */ 2475/* Print position info to stdout. */
2524 2476
2525void 2477static void
2526print_info (void) 2478print_info (void)
2527{ 2479{
2528 if (info_position >= 0 && BUFFER_POS () <= info_position) 2480 if (info_position >= 0 && BUFFER_POS () <= info_position)
@@ -2537,7 +2489,7 @@ print_info (void)
2537 the access specifier for the member (private, protected, 2489 the access specifier for the member (private, protected,
2538 public). */ 2490 public). */
2539 2491
2540void 2492static void
2541member (struct sym *cls, int vis) 2493member (struct sym *cls, int vis)
2542{ 2494{
2543 char *id = NULL; 2495 char *id = NULL;
@@ -2746,7 +2698,7 @@ member (struct sym *cls, int vis)
2746/* Parse the body of class CLS. TAG is the tag of the class (struct, 2698/* Parse the body of class CLS. TAG is the tag of the class (struct,
2747 union, class). */ 2699 union, class). */
2748 2700
2749void 2701static void
2750class_body (struct sym *cls, int tag) 2702class_body (struct sym *cls, int tag)
2751{ 2703{
2752 int vis = tag == CLASS ? PRIVATE : PUBLIC; 2704 int vis = tag == CLASS ? PRIVATE : PUBLIC;
@@ -2807,7 +2759,7 @@ class_body (struct sym *cls, int tag)
2807 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a 2759 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
2808 symbol for that class. */ 2760 symbol for that class. */
2809 2761
2810struct sym * 2762static struct sym *
2811parse_classname (void) 2763parse_classname (void)
2812{ 2764{
2813 struct sym *last_class = NULL; 2765 struct sym *last_class = NULL;
@@ -2837,13 +2789,13 @@ parse_classname (void)
2837 implicitly static operator has been parsed. Value is a pointer to 2789 implicitly static operator has been parsed. Value is a pointer to
2838 a static buffer holding the constructed operator name string. */ 2790 a static buffer holding the constructed operator name string. */
2839 2791
2840char * 2792static char *
2841operator_name (int *sc) 2793operator_name (int *sc)
2842{ 2794{
2843 static int id_size = 0; 2795 static size_t id_size = 0;
2844 static char *id = NULL; 2796 static char *id = NULL;
2845 const char *s; 2797 const char *s;
2846 int len; 2798 size_t len;
2847 2799
2848 MATCH (); 2800 MATCH ();
2849 2801
@@ -2859,7 +2811,7 @@ operator_name (int *sc)
2859 len = strlen (s) + 10; 2811 len = strlen (s) + 10;
2860 if (len > id_size) 2812 if (len > id_size)
2861 { 2813 {
2862 int new_size = max (len, 2 * id_size); 2814 size_t new_size = max (len, 2 * id_size);
2863 id = (char *) xrealloc (id, new_size); 2815 id = (char *) xrealloc (id, new_size);
2864 id_size = new_size; 2816 id_size = new_size;
2865 } 2817 }
@@ -2880,7 +2832,7 @@ operator_name (int *sc)
2880 } 2832 }
2881 else 2833 else
2882 { 2834 {
2883 int tokens_matched = 0; 2835 size_t tokens_matched = 0;
2884 2836
2885 len = 20; 2837 len = 20;
2886 if (len > id_size) 2838 if (len > id_size)
@@ -2901,7 +2853,7 @@ operator_name (int *sc)
2901 len += strlen (s) + 2; 2853 len += strlen (s) + 2;
2902 if (len > id_size) 2854 if (len > id_size)
2903 { 2855 {
2904 int new_size = max (len, 2 * id_size); 2856 size_t new_size = max (len, 2 * id_size);
2905 id = (char *) xrealloc (id, new_size); 2857 id = (char *) xrealloc (id, new_size);
2906 id_size = new_size; 2858 id_size = new_size;
2907 } 2859 }
@@ -2927,7 +2879,7 @@ operator_name (int *sc)
2927 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the 2879 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2928 symbol structure for the ident. */ 2880 symbol structure for the ident. */
2929 2881
2930struct sym * 2882static struct sym *
2931parse_qualified_ident_or_type (char **last_id) 2883parse_qualified_ident_or_type (char **last_id)
2932{ 2884{
2933 struct sym *cls = NULL; 2885 struct sym *cls = NULL;
@@ -2992,14 +2944,16 @@ parse_qualified_ident_or_type (char **last_id)
2992 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the 2944 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2993 symbol structure for the ident. */ 2945 symbol structure for the ident. */
2994 2946
2995void 2947static void
2996parse_qualified_param_ident_or_type (char **last_id) 2948parse_qualified_param_ident_or_type (char **last_id)
2997{ 2949{
2998 struct sym *cls = NULL; 2950 struct sym *cls = NULL;
2999 static char *id = NULL; 2951 static char *id = NULL;
3000 static int id_size = 0; 2952 static int id_size = 0;
3001 2953
3002 while (LOOKING_AT (IDENT)) 2954 assert (LOOKING_AT (IDENT));
2955
2956 do
3003 { 2957 {
3004 int len = strlen (yytext) + 1; 2958 int len = strlen (yytext) + 1;
3005 if (len > id_size) 2959 if (len > id_size)
@@ -3022,6 +2976,7 @@ parse_qualified_param_ident_or_type (char **last_id)
3022 else 2976 else
3023 break; 2977 break;
3024 } 2978 }
2979 while (LOOKING_AT (IDENT));
3025} 2980}
3026 2981
3027 2982
@@ -3034,7 +2989,7 @@ parse_qualified_param_ident_or_type (char **last_id)
3034 2989
3035 Current lookahead is the class name. */ 2990 Current lookahead is the class name. */
3036 2991
3037void 2992static void
3038class_definition (struct sym *containing, int tag, int flags, int nested) 2993class_definition (struct sym *containing, int tag, int flags, int nested)
3039{ 2994{
3040 struct sym *current; 2995 struct sym *current;
@@ -3131,7 +3086,7 @@ class_definition (struct sym *containing, int tag, int flags, int nested)
3131 the storage class of *ID. FLAGS is a bit set giving additional 3086 the storage class of *ID. FLAGS is a bit set giving additional
3132 information about the member (see the F_* defines). */ 3087 information about the member (see the F_* defines). */
3133 3088
3134void 3089static void
3135add_declarator (struct sym **cls, char **id, int flags, int sc) 3090add_declarator (struct sym **cls, char **id, int flags, int sc)
3136{ 3091{
3137 if (LOOKING_AT2 (';', ',')) 3092 if (LOOKING_AT2 (';', ','))
@@ -3174,7 +3129,7 @@ add_declarator (struct sym **cls, char **id, int flags, int sc)
3174 3129
3175/* Parse a declaration. */ 3130/* Parse a declaration. */
3176 3131
3177void 3132static void
3178declaration (int flags) 3133declaration (int flags)
3179{ 3134{
3180 char *id = NULL; 3135 char *id = NULL;
@@ -3328,7 +3283,7 @@ declaration (int flags)
3328 parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0 3283 parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0
3329 otherwise. */ 3284 otherwise. */
3330 3285
3331int 3286static int
3332globals (int start_flags) 3287globals (int start_flags)
3333{ 3288{
3334 int anonymous; 3289 int anonymous;
@@ -3446,7 +3401,7 @@ globals (int start_flags)
3446 3401
3447/* Parse the current input file. */ 3402/* Parse the current input file. */
3448 3403
3449void 3404static void
3450yyparse (void) 3405yyparse (void)
3451{ 3406{
3452 while (globals (0) == 0) 3407 while (globals (0) == 0)
@@ -3462,7 +3417,7 @@ yyparse (void)
3462/* Add the list of paths PATH_LIST to the current search path for 3417/* Add the list of paths PATH_LIST to the current search path for
3463 input files. */ 3418 input files. */
3464 3419
3465void 3420static void
3466add_search_path (char *path_list) 3421add_search_path (char *path_list)
3467{ 3422{
3468 while (*path_list) 3423 while (*path_list)
@@ -3497,7 +3452,7 @@ add_search_path (char *path_list)
3497 opened. Try to find FILE in search_path first, then try the 3452 opened. Try to find FILE in search_path first, then try the
3498 unchanged file name. */ 3453 unchanged file name. */
3499 3454
3500FILE * 3455static FILE *
3501open_file (char *file) 3456open_file (char *file)
3502{ 3457{
3503 FILE *fp = NULL; 3458 FILE *fp = NULL;
@@ -3556,7 +3511,7 @@ Usage: ebrowse [options] {files}\n\
3556 --version display version info\n\ 3511 --version display version info\n\
3557" 3512"
3558 3513
3559void 3514static void
3560usage (int error) 3515usage (int error)
3561{ 3516{
3562 puts (USAGE); 3517 puts (USAGE);
@@ -3571,7 +3526,7 @@ usage (int error)
3571# define VERSION "21" 3526# define VERSION "21"
3572#endif 3527#endif
3573 3528
3574void 3529static void
3575version (void) 3530version (void)
3576{ 3531{
3577 /* Makes it easier to update automatically. */ 3532 /* Makes it easier to update automatically. */
@@ -3587,7 +3542,7 @@ version (void)
3587/* Parse one input file FILE, adding classes and members to the symbol 3542/* Parse one input file FILE, adding classes and members to the symbol
3588 table. */ 3543 table. */
3589 3544
3590void 3545static void
3591process_file (char *file) 3546process_file (char *file)
3592{ 3547{
3593 FILE *fp; 3548 FILE *fp;
@@ -3595,7 +3550,7 @@ process_file (char *file)
3595 fp = open_file (file); 3550 fp = open_file (file);
3596 if (fp) 3551 if (fp)
3597 { 3552 {
3598 int nread, nbytes; 3553 size_t nread, nbytes;
3599 3554
3600 /* Give a progress indication if needed. */ 3555 /* Give a progress indication if needed. */
3601 if (f_very_verbose) 3556 if (f_very_verbose)
@@ -3619,12 +3574,10 @@ process_file (char *file)
3619 } 3574 }
3620 3575
3621 nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp); 3576 nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp);
3622 if (nbytes <= 0) 3577 if (nbytes == 0)
3623 break; 3578 break;
3624 nread += nbytes; 3579 nread += nbytes;
3625 } 3580 }
3626 if (nread < 0)
3627 nread = 0;
3628 inbuffer[nread] = '\0'; 3581 inbuffer[nread] = '\0';
3629 3582
3630 /* Reinitialize scanner and parser for the new input file. */ 3583 /* Reinitialize scanner and parser for the new input file. */
@@ -3642,7 +3595,7 @@ process_file (char *file)
3642 containing its contents without the terminating newline. Value 3595 containing its contents without the terminating newline. Value
3643 is null when EOF is reached. */ 3596 is null when EOF is reached. */
3644 3597
3645char * 3598static char *
3646read_line (FILE *fp) 3599read_line (FILE *fp)
3647{ 3600{
3648 static char *buffer; 3601 static char *buffer;