1 /* ebrowse.c --- parsing files for the ebrowse C++ browser
3 Copyright (C) 1992-2011 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
33 /* The SunOS compiler doesn't have SEEK_END. */
38 /* Conditionalize function prototypes. */
40 /* Value is non-zero if strings X and Y compare equal. */
42 #define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0)
46 /* Files are read in chunks of this number of bytes. */
48 #define READ_CHUNK_SIZE (100 * 1024)
50 /* The character used as a separator in path lists (like $PATH). */
52 #if defined(__MSDOS__)
53 #define PATH_LIST_SEPARATOR ';'
54 #define FILENAME_EQ(X,Y) (strcasecmp(X,Y) == 0)
56 #if defined(WINDOWSNT)
57 #define PATH_LIST_SEPARATOR ';'
58 #define FILENAME_EQ(X,Y) (stricmp(X,Y) == 0)
60 #define PATH_LIST_SEPARATOR ':'
61 #define FILENAME_EQ(X,Y) (streq(X,Y))
64 /* The default output file name. */
66 #define DEFAULT_OUTFILE "BROWSE"
68 /* A version string written to the output file. Change this whenever
69 the structure of the output file changes. */
71 #define EBROWSE_FILE_VERSION "ebrowse 5.0"
73 /* The output file consists of a tree of Lisp objects, with major
74 nodes built out of Lisp structures. These are the heads of the
75 Lisp structs with symbols identifying their type. */
77 #define TREE_HEADER_STRUCT "[ebrowse-hs "
78 #define TREE_STRUCT "[ebrowse-ts "
79 #define MEMBER_STRUCT "[ebrowse-ms "
80 #define CLASS_STRUCT "[ebrowse-cs "
82 /* The name of the symbol table entry for global functions, variables,
83 defines etc. This name also appears in the browser display. */
85 #define GLOBALS_NAME "*Globals*"
87 /* Token definitions. */
91 YYEOF
= 0, /* end of file */
92 CSTRING
= 256, /* string constant */
93 CCHAR
, /* character constant */
94 CINT
, /* integral constant */
95 CFLOAT
, /* real constant */
101 IDENT
, /* identifier */
124 /* Keywords. The undef's are there because these
125 three symbols are very likely to be defined somewhere. */
138 CONTINUE
, /* continue */
139 DEFAULT
, /* default */
151 T_INLINE
, /* inline */
155 OPERATOR
, /* operator */
156 PRIVATE
, /* private */
157 PROTECTED
, /* protected */
159 REGISTER
, /* register */
167 TEMPLATE
, /* template */
171 TYPEDEF
, /* typedef */
173 UNSIGNED
, /* unsigned */
174 VIRTUAL
, /* virtual */
176 VOLATILE
, /* volatile */
178 MUTABLE
, /* mutable */
182 SIGNATURE
, /* signature (GNU extension) */
183 NAMESPACE
, /* namespace */
184 EXPLICIT
, /* explicit */
185 TYPENAME
, /* typename */
186 CONST_CAST
, /* const_cast */
187 DYNAMIC_CAST
, /* dynamic_cast */
188 REINTERPRET_CAST
, /* reinterpret_cast */
189 STATIC_CAST
, /* static_cast */
195 /* Storage classes, in a wider sense. */
200 SC_MEMBER
, /* Is an instance member. */
201 SC_STATIC
, /* Is static member. */
202 SC_FRIEND
, /* Is friend function. */
203 SC_TYPE
/* Is a type definition. */
206 /* Member visibility. */
217 #define F_VIRTUAL 1 /* Is virtual function. */
218 #define F_INLINE 2 /* Is inline function. */
219 #define F_CONST 4 /* Is const. */
220 #define F_PURE 8 /* Is pure virtual function. */
221 #define F_MUTABLE 16 /* Is mutable. */
222 #define F_TEMPLATE 32 /* Is a template. */
223 #define F_EXPLICIT 64 /* Is explicit constructor. */
224 #define F_THROW 128 /* Has a throw specification. */
225 #define F_EXTERNC 256 /* Is declared extern "C". */
226 #define F_DEFINE 512 /* Is a #define. */
228 /* Two macros to set and test a bit in an int. */
230 #define SET_FLAG(F, FLAG) ((F) |= (FLAG))
231 #define HAS_FLAG(F, FLAG) (((F) & (FLAG)) != 0)
233 /* Structure describing a class member. */
237 struct member
*next
; /* Next in list of members. */
238 struct member
*anext
; /* Collision chain in member_table. */
239 struct member
**list
; /* Pointer to list in class. */
240 unsigned param_hash
; /* Hash value for parameter types. */
241 int vis
; /* Visibility (public, ...). */
242 int flags
; /* See F_* above. */
243 char *regexp
; /* Matching regular expression. */
244 const char *filename
; /* Don't free this shared string. */
245 int pos
; /* Buffer position of occurrence. */
246 char *def_regexp
; /* Regular expression matching definition. */
247 const char *def_filename
; /* File name of definition. */
248 int def_pos
; /* Buffer position of definition. */
249 char name
[1]; /* Member name. */
252 /* Structures of this type are used to connect class structures with
253 their super and subclasses. */
257 struct sym
*sym
; /* The super or subclass. */
258 struct link
*next
; /* Next in list or NULL. */
261 /* Structure used to record namespace aliases. */
265 struct alias
*next
; /* Next in list. */
266 struct sym
*namesp
; /* Namespace in which defined. */
267 struct link
*aliasee
; /* List of aliased namespaces (A::B::C...). */
268 char name
[1]; /* Alias name. */
271 /* The structure used to describe a class in the symbol table,
272 or a namespace in all_namespaces. */
276 int flags
; /* Is class a template class?. */
277 unsigned char visited
; /* Used to find circles. */
278 struct sym
*next
; /* Hash collision list. */
279 struct link
*subs
; /* List of subclasses. */
280 struct link
*supers
; /* List of superclasses. */
281 struct member
*vars
; /* List of instance variables. */
282 struct member
*fns
; /* List of instance functions. */
283 struct member
*static_vars
; /* List of static variables. */
284 struct member
*static_fns
; /* List of static functions. */
285 struct member
*friends
; /* List of friend functions. */
286 struct member
*types
; /* List of local types. */
287 char *regexp
; /* Matching regular expression. */
288 int pos
; /* Buffer position. */
289 const char *filename
; /* File in which it can be found. */
290 const char *sfilename
; /* File in which members can be found. */
291 struct sym
*namesp
; /* Namespace in which defined. . */
292 char name
[1]; /* Name of the class. */
295 /* Experimental: Print info for `--position-info'. We print
296 '(CLASS-NAME SCOPE MEMBER-NAME). */
302 struct sym
*info_cls
= NULL
;
303 struct member
*info_member
= NULL
;
305 /* Experimental. For option `--position-info', the buffer position we
306 are interested in. When this position is reached, print out
307 information about what we know about that point. */
309 int info_position
= -1;
311 /* Command line options structure for getopt_long. */
313 struct option options
[] =
315 {"append", no_argument
, NULL
, 'a'},
316 {"files", required_argument
, NULL
, 'f'},
317 {"help", no_argument
, NULL
, -2},
318 {"min-regexp-length", required_argument
, NULL
, 'm'},
319 {"max-regexp-length", required_argument
, NULL
, 'M'},
320 {"no-nested-classes", no_argument
, NULL
, 'n'},
321 {"no-regexps", no_argument
, NULL
, 'x'},
322 {"no-structs-or-unions", no_argument
, NULL
, 's'},
323 {"output-file", required_argument
, NULL
, 'o'},
324 {"position-info", required_argument
, NULL
, 'p'},
325 {"search-path", required_argument
, NULL
, 'I'},
326 {"verbose", no_argument
, NULL
, 'v'},
327 {"version", no_argument
, NULL
, -3},
328 {"very-verbose", no_argument
, NULL
, 'V'},
332 /* Semantic values of tokens. Set by yylex.. */
334 unsigned yyival
; /* Set for token CINT. */
335 char *yytext
; /* Set for token IDENT. */
342 /* Current line number. */
346 /* The name of the current input file. */
348 const char *filename
;
350 /* Three character class vectors, and macros to test membership
357 #define IDENTP(C) is_ident[(unsigned char) (C)]
358 #define DIGITP(C) is_digit[(unsigned char) (C)]
359 #define WHITEP(C) is_white[(unsigned char) (C)]
361 /* Command line flags. */
368 int f_nested_classes
= 1;
370 /* Maximum and minimum lengths of regular expressions matching a
371 member, class etc., for writing them to the output file. These are
372 overridable from the command line. */
381 size_t inbuffer_size
;
383 /* Return the current buffer position in the input file. */
385 #define BUFFER_POS() (in - inbuffer)
387 /* If current lookahead is CSTRING, the following points to the
388 first character in the string constant. Used for recognizing
393 /* The size of the hash tables for classes.and members. Should be
396 #define TABLE_SIZE 1001
398 /* The hash table for class symbols. */
400 struct sym
*class_table
[TABLE_SIZE
];
402 /* Hash table containing all member structures. This is generally
403 faster for member lookup than traversing the member lists of a
406 struct member
*member_table
[TABLE_SIZE
];
408 /* Hash table for namespace aliases */
410 struct alias
*namespace_alias_table
[TABLE_SIZE
];
412 /* The special class symbol used to hold global functions,
415 struct sym
*global_symbols
;
417 /* The current namespace. */
419 struct sym
*current_namespace
;
421 /* The list of all known namespaces. */
423 struct sym
*all_namespaces
;
425 /* Stack of namespaces we're currently nested in, during the parse. */
427 struct sym
**namespace_stack
;
428 int namespace_stack_size
;
431 /* The current lookahead token. */
435 /* Structure describing a keyword. */
439 const char *name
; /* Spelling. */
440 int tk
; /* Token value. */
441 struct kw
*next
; /* Next in collision chain. */
444 /* Keywords are lookup up in a hash table of their own. */
446 #define KEYWORD_TABLE_SIZE 1001
447 struct kw
*keyword_table
[KEYWORD_TABLE_SIZE
];
454 struct search_path
*next
;
457 struct search_path
*search_path
;
458 struct search_path
*search_path_tail
;
460 /* Function prototypes. */
462 static char *matching_regexp (void);
463 static struct sym
*add_sym (const char *, struct sym
*);
464 static void add_global_defn (char *, char *, int, unsigned, int, int, int);
465 static void add_global_decl (char *, char *, int, unsigned, int, int, int);
466 static struct member
*add_member (struct sym
*, char *, int, int, unsigned);
467 static void class_definition (struct sym
*, int, int, int);
468 static char *operator_name (int *);
469 static void parse_qualified_param_ident_or_type (char **);
470 static void usage (int) NO_RETURN
;
471 static void version (void) NO_RETURN
;
475 /***********************************************************************
477 ***********************************************************************/
479 /* Print an error in a printf-like style with the current input file
480 name and line number. */
483 yyerror (const char *format
, const char *s
)
485 fprintf (stderr
, "%s:%d: ", filename
, yyline
);
486 fprintf (stderr
, format
, s
);
491 /* Like malloc but print an error and exit if not enough memory is
495 xmalloc (size_t nbytes
)
497 void *p
= malloc (nbytes
);
500 yyerror ("out of memory", NULL
);
507 /* Like realloc but print an error and exit if out of memory. */
510 xrealloc (void *p
, size_t sz
)
515 yyerror ("out of memory", NULL
);
522 /* Like strdup, but print an error and exit if not enough memory is
523 available.. If S is null, return null. */
529 s
= strcpy (xmalloc (strlen (s
) + 1), s
);
535 /***********************************************************************
537 ***********************************************************************/
539 /* Initialize the symbol table. This currently only sets up the
540 special symbol for globals (`*Globals*'). */
545 global_symbols
= add_sym (GLOBALS_NAME
, NULL
);
549 /* Add a symbol for class NAME to the symbol table. NESTED_IN_CLASS
550 is the class in which class NAME was found. If it is null,
551 this means the scope of NAME is the current namespace.
553 If a symbol for NAME already exists, return that. Otherwise
554 create a new symbol and set it to default values. */
557 add_sym (const char *name
, struct sym
*nested_in_class
)
562 struct sym
*scope
= nested_in_class
? nested_in_class
: current_namespace
;
564 for (s
= name
, h
= 0; *s
; ++s
)
568 for (sym
= class_table
[h
]; sym
; sym
= sym
->next
)
569 if (streq (name
, sym
->name
)
570 && ((!sym
->namesp
&& !scope
)
571 || (sym
->namesp
&& scope
572 && streq (sym
->namesp
->name
, scope
->name
))))
583 sym
= (struct sym
*) xmalloc (sizeof *sym
+ strlen (name
));
584 memset (sym
, 0, sizeof *sym
);
585 strcpy (sym
->name
, name
);
587 sym
->next
= class_table
[h
];
588 class_table
[h
] = sym
;
595 /* Add links between superclass SUPER and subclass SUB. */
598 add_link (struct sym
*super
, struct sym
*sub
)
600 struct link
*lnk
, *lnk2
, *p
, *prev
;
602 /* See if a link already exists. */
603 for (p
= super
->subs
, prev
= NULL
;
604 p
&& strcmp (sub
->name
, p
->sym
->name
) > 0;
605 prev
= p
, p
= p
->next
)
608 /* Avoid duplicates. */
609 if (p
== NULL
|| p
->sym
!= sub
)
611 lnk
= (struct link
*) xmalloc (sizeof *lnk
);
612 lnk2
= (struct link
*) xmalloc (sizeof *lnk2
);
623 lnk2
->next
= sub
->supers
;
629 /* Find in class CLS member NAME.
631 VAR non-zero means look for a member variable; otherwise a function
632 is searched. SC specifies what kind of member is searched---a
633 static, or per-instance member etc. HASH is a hash code for the
634 parameter types of functions. Value is a pointer to the member
635 found or null if not found. */
637 static struct member
*
638 find_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
640 struct member
**list
;
642 unsigned name_hash
= 0;
649 list
= &cls
->friends
;
657 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
661 list
= var
? &cls
->vars
: &cls
->fns
;
665 for (s
= name
; *s
; ++s
)
666 name_hash
= (name_hash
<< 1) ^ *s
;
667 i
= name_hash
% TABLE_SIZE
;
669 for (p
= member_table
[i
]; p
; p
= p
->anext
)
670 if (p
->list
== list
&& p
->param_hash
== hash
&& streq (name
, p
->name
))
677 /* Add to class CLS information for the declaration of member NAME.
678 REGEXP is a regexp matching the declaration, if non-null. POS is
679 the position in the source where the declaration is found. HASH is
680 a hash code for the parameter list of the member, if it's a
681 function. VAR non-zero means member is a variable or type. SC
682 specifies the type of member (instance member, static, ...). VIS
683 is the member's visibility (public, protected, private). FLAGS is
684 a bit set giving additional information about the member (see the
688 add_member_decl (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int vis
, int flags
)
692 m
= find_member (cls
, name
, var
, sc
, hash
);
694 m
= add_member (cls
, name
, var
, sc
, hash
);
696 /* Have we seen a new filename? If so record that. */
697 if (!cls
->filename
|| !FILENAME_EQ (cls
->filename
, filename
))
698 m
->filename
= filename
;
711 m
->vis
= V_PROTECTED
;
725 /* Add to class CLS information for the definition of member NAME.
726 REGEXP is a regexp matching the declaration, if non-null. POS is
727 the position in the source where the declaration is found. HASH is
728 a hash code for the parameter list of the member, if it's a
729 function. VAR non-zero means member is a variable or type. SC
730 specifies the type of member (instance member, static, ...). VIS
731 is the member's visibility (public, protected, private). FLAGS is
732 a bit set giving additional information about the member (see the
736 add_member_defn (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
740 if (sc
== SC_UNKNOWN
)
742 m
= find_member (cls
, name
, var
, SC_MEMBER
, hash
);
745 m
= find_member (cls
, name
, var
, SC_STATIC
, hash
);
747 m
= add_member (cls
, name
, var
, sc
, hash
);
752 m
= find_member (cls
, name
, var
, sc
, hash
);
754 m
= add_member (cls
, name
, var
, sc
, hash
);
758 cls
->sfilename
= filename
;
760 if (!FILENAME_EQ (cls
->sfilename
, filename
))
761 m
->def_filename
= filename
;
763 m
->def_regexp
= regexp
;
773 /* Add a symbol for a define named NAME to the symbol table.
774 REGEXP is a regular expression matching the define in the source,
775 if it is non-null. POS is the position in the file. */
778 add_define (char *name
, char *regexp
, int pos
)
780 add_global_defn (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
781 add_global_decl (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
785 /* Add information for the global definition of NAME.
786 REGEXP is a regexp matching the declaration, if non-null. POS is
787 the position in the source where the declaration is found. HASH is
788 a hash code for the parameter list of the member, if it's a
789 function. VAR non-zero means member is a variable or type. SC
790 specifies the type of member (instance member, static, ...). VIS
791 is the member's visibility (public, protected, private). FLAGS is
792 a bit set giving additional information about the member (see the
796 add_global_defn (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
801 /* Try to find out for which classes a function is a friend, and add
802 what we know about it to them. */
804 for (i
= 0; i
< TABLE_SIZE
; ++i
)
805 for (sym
= class_table
[i
]; sym
; sym
= sym
->next
)
806 if (sym
!= global_symbols
&& sym
->friends
)
807 if (find_member (sym
, name
, 0, SC_FRIEND
, hash
))
808 add_member_defn (sym
, name
, regexp
, pos
, hash
, 0,
811 /* Add to global symbols. */
812 add_member_defn (global_symbols
, name
, regexp
, pos
, hash
, var
, sc
, flags
);
816 /* Add information for the global declaration of NAME.
817 REGEXP is a regexp matching the declaration, if non-null. POS is
818 the position in the source where the declaration is found. HASH is
819 a hash code for the parameter list of the member, if it's a
820 function. VAR non-zero means member is a variable or type. SC
821 specifies the type of member (instance member, static, ...). VIS
822 is the member's visibility (public, protected, private). FLAGS is
823 a bit set giving additional information about the member (see the
827 add_global_decl (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
829 /* Add declaration only if not already declared. Header files must
830 be processed before source files for this to have the right effect.
831 I do not want to handle implicit declarations at the moment. */
833 struct member
*found
;
835 m
= found
= find_member (global_symbols
, name
, var
, sc
, hash
);
837 m
= add_member (global_symbols
, name
, var
, sc
, hash
);
839 /* Definition already seen => probably last declaration implicit.
840 Override. This means that declarations must always be added to
841 the symbol table before definitions. */
844 if (!global_symbols
->filename
845 || !FILENAME_EQ (global_symbols
->filename
, filename
))
846 m
->filename
= filename
;
854 info_cls
= global_symbols
;
860 /* Add a symbol for member NAME to class CLS.
861 VAR non-zero means it's a variable. SC specifies the kind of
862 member. HASH is a hash code for the parameter types of a function.
863 Value is a pointer to the member's structure. */
865 static struct member
*
866 add_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
868 struct member
*m
= (struct member
*) xmalloc (sizeof *m
+ strlen (name
));
869 struct member
**list
;
872 unsigned name_hash
= 0;
876 strcpy (m
->name
, name
);
877 m
->param_hash
= hash
;
884 m
->def_regexp
= NULL
;
885 m
->def_filename
= NULL
;
888 assert (cls
!= NULL
);
893 list
= &cls
->friends
;
901 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
905 list
= var
? &cls
->vars
: &cls
->fns
;
909 for (s
= name
; *s
; ++s
)
910 name_hash
= (name_hash
<< 1) ^ *s
;
911 i
= name_hash
% TABLE_SIZE
;
912 m
->anext
= member_table
[i
];
916 /* Keep the member list sorted. It's cheaper to do it here than to
917 sort them in Lisp. */
918 for (prev
= NULL
, p
= *list
;
919 p
&& strcmp (name
, p
->name
) > 0;
920 prev
= p
, p
= p
->next
)
932 /* Given the root R of a class tree, step through all subclasses
933 recursively, marking functions as virtual that are declared virtual
937 mark_virtual (struct sym
*r
)
940 struct member
*m
, *m2
;
942 for (p
= r
->subs
; p
; p
= p
->next
)
944 for (m
= r
->fns
; m
; m
= m
->next
)
945 if (HAS_FLAG (m
->flags
, F_VIRTUAL
))
947 for (m2
= p
->sym
->fns
; m2
; m2
= m2
->next
)
948 if (m
->param_hash
== m2
->param_hash
&& streq (m
->name
, m2
->name
))
949 SET_FLAG (m2
->flags
, F_VIRTUAL
);
952 mark_virtual (p
->sym
);
957 /* For all roots of the class tree, mark functions as virtual that
958 are virtual because of a virtual declaration in a base class. */
961 mark_inherited_virtual (void)
966 for (i
= 0; i
< TABLE_SIZE
; ++i
)
967 for (r
= class_table
[i
]; r
; r
= r
->next
)
968 if (r
->supers
== NULL
)
973 /* Create and return a symbol for a namespace with name NAME. */
976 make_namespace (char *name
, struct sym
*context
)
978 struct sym
*s
= (struct sym
*) xmalloc (sizeof *s
+ strlen (name
));
979 memset (s
, 0, sizeof *s
);
980 strcpy (s
->name
, name
);
981 s
->next
= all_namespaces
;
988 /* Find the symbol for namespace NAME. If not found, retrun NULL */
991 check_namespace (char *name
, struct sym
*context
)
993 struct sym
*p
= NULL
;
995 for (p
= all_namespaces
; p
; p
= p
->next
)
997 if (streq (p
->name
, name
) && (p
->namesp
== context
))
1004 /* Find the symbol for namespace NAME. If not found, add a new symbol
1005 for NAME to all_namespaces. */
1008 find_namespace (char *name
, struct sym
*context
)
1010 struct sym
*p
= check_namespace (name
, context
);
1013 p
= make_namespace (name
, context
);
1019 /* Find namespace alias with name NAME. If not found return NULL. */
1021 static struct link
*
1022 check_namespace_alias (char *name
)
1024 struct link
*p
= NULL
;
1029 for (s
= name
, h
= 0; *s
; ++s
)
1033 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1034 if (streq (name
, al
->name
) && (al
->namesp
== current_namespace
))
1043 /* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */
1046 register_namespace_alias (char *new_name
, struct link
*old_name
)
1052 for (s
= new_name
, h
= 0; *s
; ++s
)
1057 /* Is it already in the table of aliases? */
1058 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1059 if (streq (new_name
, al
->name
) && (al
->namesp
== current_namespace
))
1062 al
= (struct alias
*) xmalloc (sizeof *al
+ strlen (new_name
));
1063 strcpy (al
->name
, new_name
);
1064 al
->next
= namespace_alias_table
[h
];
1065 al
->namesp
= current_namespace
;
1066 al
->aliasee
= old_name
;
1067 namespace_alias_table
[h
] = al
;
1071 /* Enter namespace with name NAME. */
1074 enter_namespace (char *name
)
1076 struct sym
*p
= find_namespace (name
, current_namespace
);
1078 if (namespace_sp
== namespace_stack_size
)
1080 int size
= max (10, 2 * namespace_stack_size
);
1082 = (struct sym
**) xrealloc ((void *)namespace_stack
,
1083 size
* sizeof *namespace_stack
);
1084 namespace_stack_size
= size
;
1087 namespace_stack
[namespace_sp
++] = current_namespace
;
1088 current_namespace
= p
;
1092 /* Leave the current namespace. */
1095 leave_namespace (void)
1097 assert (namespace_sp
> 0);
1098 current_namespace
= namespace_stack
[--namespace_sp
];
1103 /***********************************************************************
1104 Writing the Output File
1105 ***********************************************************************/
1107 /* Write string S to the output file FP in a Lisp-readable form.
1108 If S is null, write out `()'. */
1111 putstr (const char *s
, FILE *fp
)
1128 /* A dynamically allocated buffer for constructing a scope name. */
1131 int scope_buffer_size
;
1132 int scope_buffer_len
;
1135 /* Make sure scope_buffer has enough room to add LEN chars to it. */
1138 ensure_scope_buffer_room (int len
)
1140 if (scope_buffer_len
+ len
>= scope_buffer_size
)
1142 int new_size
= max (2 * scope_buffer_size
, scope_buffer_len
+ len
);
1143 scope_buffer
= (char *) xrealloc (scope_buffer
, new_size
);
1144 scope_buffer_size
= new_size
;
1149 /* Recursively add the scope names of symbol P and the scopes of its
1150 namespaces to scope_buffer. Value is a pointer to the complete
1151 scope name constructed. */
1154 sym_scope_1 (struct sym
*p
)
1159 sym_scope_1 (p
->namesp
);
1163 ensure_scope_buffer_room (3);
1164 strcat (scope_buffer
, "::");
1165 scope_buffer_len
+= 2;
1168 len
= strlen (p
->name
);
1169 ensure_scope_buffer_room (len
+ 1);
1170 strcat (scope_buffer
, p
->name
);
1171 scope_buffer_len
+= len
;
1173 if (HAS_FLAG (p
->flags
, F_TEMPLATE
))
1175 ensure_scope_buffer_room (3);
1176 strcat (scope_buffer
, "<>");
1177 scope_buffer_len
+= 2;
1180 return scope_buffer
;
1184 /* Return the scope of symbol P in printed representation, i.e.
1185 as it would appear in a C*+ source file. */
1188 sym_scope (struct sym
*p
)
1192 scope_buffer_size
= 1024;
1193 scope_buffer
= (char *) xmalloc (scope_buffer_size
);
1196 *scope_buffer
= '\0';
1197 scope_buffer_len
= 0;
1200 sym_scope_1 (p
->namesp
);
1202 return scope_buffer
;
1206 /* Dump the list of members M to file FP. Value is the length of the
1210 dump_members (FILE *fp
, struct member
*m
)
1216 for (n
= 0; m
; m
= m
->next
, ++n
)
1218 fputs (MEMBER_STRUCT
, fp
);
1219 putstr (m
->name
, fp
);
1220 putstr (NULL
, fp
); /* FIXME? scope for globals */
1221 fprintf (fp
, "%u ", (unsigned) m
->flags
);
1222 putstr (m
->filename
, fp
);
1223 putstr (m
->regexp
, fp
);
1224 fprintf (fp
, "%u ", (unsigned) m
->pos
);
1225 fprintf (fp
, "%u ", (unsigned) m
->vis
);
1227 putstr (m
->def_filename
, fp
);
1228 putstr (m
->def_regexp
, fp
);
1229 fprintf (fp
, "%u", (unsigned) m
->def_pos
);
1240 /* Dump class ROOT to stream FP. */
1243 dump_sym (FILE *fp
, struct sym
*root
)
1245 fputs (CLASS_STRUCT
, fp
);
1246 putstr (root
->name
, fp
);
1248 /* Print scope, if any. */
1250 putstr (sym_scope (root
), fp
);
1255 fprintf (fp
, "%u", root
->flags
);
1256 putstr (root
->filename
, fp
);
1257 putstr (root
->regexp
, fp
);
1258 fprintf (fp
, "%u", (unsigned) root
->pos
);
1259 putstr (root
->sfilename
, fp
);
1265 /* Dump class ROOT and its subclasses to file FP. Value is the
1266 number of classes written. */
1269 dump_tree (FILE *fp
, struct sym
*root
)
1274 dump_sym (fp
, root
);
1284 for (lk
= root
->subs
; lk
; lk
= lk
->next
)
1286 fputs (TREE_STRUCT
, fp
);
1287 n
+= dump_tree (fp
, lk
->sym
);
1293 dump_members (fp
, root
->vars
);
1294 n
+= dump_members (fp
, root
->fns
);
1295 dump_members (fp
, root
->static_vars
);
1296 n
+= dump_members (fp
, root
->static_fns
);
1297 n
+= dump_members (fp
, root
->friends
);
1298 dump_members (fp
, root
->types
);
1313 /* Dump the entire class tree to file FP. */
1316 dump_roots (FILE *fp
)
1321 /* Output file header containing version string, command line
1325 fputs (TREE_HEADER_STRUCT
, fp
);
1326 putstr (EBROWSE_FILE_VERSION
, fp
);
1339 /* Mark functions as virtual that are so because of functions
1340 declared virtual in base classes. */
1341 mark_inherited_virtual ();
1343 /* Dump the roots of the graph. */
1344 for (i
= 0; i
< TABLE_SIZE
; ++i
)
1345 for (r
= class_table
[i
]; r
; r
= r
->next
)
1348 fputs (TREE_STRUCT
, fp
);
1349 n
+= dump_tree (fp
, r
);
1359 /***********************************************************************
1361 ***********************************************************************/
1364 #define INCREMENT_LINENO \
1366 if (f_very_verbose) \
1369 printf ("%d:\n", yyline); \
1375 #define INCREMENT_LINENO ++yyline
1378 /* Define two macros for accessing the input buffer (current input
1379 file). GET(C) sets C to the next input character and advances the
1380 input pointer. UNGET retracts the input pointer. */
1382 #define GET(C) ((C) = *in++)
1383 #define UNGET() (--in)
1386 /* Process a preprocessor line. Value is the next character from the
1387 input buffer not consumed. */
1390 process_pp_line (void)
1392 int in_comment
= 0, in_string
= 0;
1396 /* Skip over white space. The `#' has been consumed already. */
1397 while (WHITEP (GET (c
)))
1400 /* Read the preprocessor command (if any). */
1407 /* Is it a `define'? */
1410 if (*yytext
&& streq (yytext
, "define"))
1425 char *regexp
= matching_regexp ();
1426 int pos
= BUFFER_POS ();
1427 add_define (yytext
, regexp
, pos
);
1431 while (c
&& (c
!= '\n' || in_comment
|| in_string
))
1435 else if (c
== '/' && !in_comment
)
1440 else if (c
== '*' && in_comment
)
1446 in_string
= !in_string
;
1458 /* Value is the next token from the input buffer. */
1469 while (WHITEP (GET (c
)))
1491 /* String and character constants. */
1494 while (GET (c
) && c
!= end_char
)
1499 /* Escape sequences. */
1502 if (end_char
== '\'')
1503 yyerror ("EOF in character constant", NULL
);
1505 yyerror ("EOF in string constant", NULL
);
1523 /* Hexadecimal escape sequence. */
1525 for (i
= 0; i
< 2; ++i
)
1529 if (c
>= '0' && c
<= '7')
1531 else if (c
>= 'a' && c
<= 'f')
1533 else if (c
>= 'A' && c
<= 'F')
1546 /* Octal escape sequence. */
1548 for (i
= 0; i
< 3; ++i
)
1552 if (c
>= '0' && c
<= '7')
1569 if (end_char
== '\'')
1570 yyerror ("newline in character constant", NULL
);
1572 yyerror ("newline in string constant", NULL
);
1582 return end_char
== '\'' ? CCHAR
: CSTRING
;
1584 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1585 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1586 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1587 case 'v': case 'w': case 'x': case 'y': case 'z':
1588 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1589 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1590 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1591 case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_':
1593 /* Identifier and keywords. */
1600 while (IDENTP (GET (*p
)))
1602 hash
= (hash
<< 1) ^ *p
++;
1603 if (p
== yytext_end
- 1)
1605 int size
= yytext_end
- yytext
;
1606 yytext
= (char *) xrealloc (yytext
, 2 * size
);
1607 yytext_end
= yytext
+ 2 * size
;
1608 p
= yytext
+ size
- 1;
1615 for (k
= keyword_table
[hash
% KEYWORD_TABLE_SIZE
]; k
; k
= k
->next
)
1616 if (streq (k
->name
, yytext
))
1623 /* C and C++ comments, '/' and '/='. */
1651 while (GET (c
) && c
!= '\n')
1653 /* Don't try to read past the end of the input buffer if
1654 the file ends in a C++ comment without a newline. */
1731 yyerror ("invalid token '..' ('...' assumed)", NULL
);
1735 else if (!DIGITP (c
))
1789 c
= process_pp_line ();
1794 case '(': case ')': case '[': case ']': case '{': case '}':
1795 case ';': case ',': case '?': case '~':
1801 if (GET (c
) == 'x' || c
== 'X')
1806 yyival
= yyival
* 16 + c
- '0';
1807 else if (c
>= 'a' && c
<= 'f')
1808 yyival
= yyival
* 16 + c
- 'a' + 10;
1809 else if (c
>= 'A' && c
<= 'F')
1810 yyival
= yyival
* 16 + c
- 'A' + 10;
1820 while (c
>= '0' && c
<= '7')
1822 yyival
= (yyival
<< 3) + c
- '0';
1827 /* Integer suffixes. */
1833 case '1': case '2': case '3': case '4': case '5': case '6':
1834 case '7': case '8': case '9':
1835 /* Integer or floating constant, part before '.'. */
1838 while (GET (c
) && DIGITP (c
))
1839 yyival
= 10 * yyival
+ c
- '0';
1845 /* Digits following '.'. */
1849 /* Optional exponent. */
1850 if (c
== 'E' || c
== 'e')
1852 if (GET (c
) == '-' || c
== '+')
1859 /* Optional type suffixes. */
1872 /* Actually local to matching_regexp. These variables must be in
1873 global scope for the case that `static' get's defined away. */
1875 static char *matching_regexp_buffer
, *matching_regexp_end_buf
;
1878 /* Value is the string from the start of the line to the current
1879 position in the input buffer, or maybe a bit more if that string is
1880 shorter than min_regexp. */
1883 matching_regexp (void)
1892 if (matching_regexp_buffer
== NULL
)
1894 matching_regexp_buffer
= (char *) xmalloc (max_regexp
);
1895 matching_regexp_end_buf
= &matching_regexp_buffer
[max_regexp
] - 1;
1898 /* Scan back to previous newline of buffer start. */
1899 for (p
= in
- 1; p
> inbuffer
&& *p
!= '\n'; --p
)
1904 while (in
- p
< min_regexp
&& p
> inbuffer
)
1906 /* Line probably not significant enough */
1907 for (--p
; p
> inbuffer
&& *p
!= '\n'; --p
)
1914 /* Copy from end to make sure significant portions are included.
1915 This implies that in the browser a regular expressing of the form
1916 `^.*{regexp}' has to be used. */
1917 for (s
= matching_regexp_end_buf
- 1, t
= in
;
1918 s
> matching_regexp_buffer
&& t
> p
;)
1922 if (*s
== '"' || *s
== '\\')
1926 *(matching_regexp_end_buf
- 1) = '\0';
1931 /* Return a printable representation of token T. */
1934 token_string (int t
)
1940 case CSTRING
: return "string constant";
1941 case CCHAR
: return "char constant";
1942 case CINT
: return "int constant";
1943 case CFLOAT
: return "floating constant";
1944 case ELLIPSIS
: return "...";
1945 case LSHIFTASGN
: return "<<=";
1946 case RSHIFTASGN
: return ">>=";
1947 case ARROWSTAR
: return "->*";
1948 case IDENT
: return "identifier";
1949 case DIVASGN
: return "/=";
1950 case INC
: return "++";
1951 case ADDASGN
: return "+=";
1952 case DEC
: return "--";
1953 case ARROW
: return "->";
1954 case SUBASGN
: return "-=";
1955 case MULASGN
: return "*=";
1956 case MODASGN
: return "%=";
1957 case LOR
: return "||";
1958 case ORASGN
: return "|=";
1959 case LAND
: return "&&";
1960 case ANDASGN
: return "&=";
1961 case XORASGN
: return "^=";
1962 case POINTSTAR
: return ".*";
1963 case DCOLON
: return "::";
1964 case EQ
: return "==";
1965 case NE
: return "!=";
1966 case LE
: return "<=";
1967 case LSHIFT
: return "<<";
1968 case GE
: return ">=";
1969 case RSHIFT
: return ">>";
1970 case ASM
: return "asm";
1971 case AUTO
: return "auto";
1972 case BREAK
: return "break";
1973 case CASE
: return "case";
1974 case CATCH
: return "catch";
1975 case CHAR
: return "char";
1976 case CLASS
: return "class";
1977 case CONST
: return "const";
1978 case CONTINUE
: return "continue";
1979 case DEFAULT
: return "default";
1980 case DELETE
: return "delete";
1981 case DO
: return "do";
1982 case DOUBLE
: return "double";
1983 case ELSE
: return "else";
1984 case ENUM
: return "enum";
1985 case EXTERN
: return "extern";
1986 case FLOAT
: return "float";
1987 case FOR
: return "for";
1988 case FRIEND
: return "friend";
1989 case GOTO
: return "goto";
1990 case IF
: return "if";
1991 case T_INLINE
: return "inline";
1992 case INT
: return "int";
1993 case LONG
: return "long";
1994 case NEW
: return "new";
1995 case OPERATOR
: return "operator";
1996 case PRIVATE
: return "private";
1997 case PROTECTED
: return "protected";
1998 case PUBLIC
: return "public";
1999 case REGISTER
: return "register";
2000 case RETURN
: return "return";
2001 case SHORT
: return "short";
2002 case SIGNED
: return "signed";
2003 case SIZEOF
: return "sizeof";
2004 case STATIC
: return "static";
2005 case STRUCT
: return "struct";
2006 case SWITCH
: return "switch";
2007 case TEMPLATE
: return "template";
2008 case THIS
: return "this";
2009 case THROW
: return "throw";
2010 case TRY
: return "try";
2011 case TYPEDEF
: return "typedef";
2012 case UNION
: return "union";
2013 case UNSIGNED
: return "unsigned";
2014 case VIRTUAL
: return "virtual";
2015 case VOID
: return "void";
2016 case VOLATILE
: return "volatile";
2017 case WHILE
: return "while";
2018 case MUTABLE
: return "mutable";
2019 case BOOL
: return "bool";
2020 case TRUE
: return "true";
2021 case FALSE
: return "false";
2022 case SIGNATURE
: return "signature";
2023 case NAMESPACE
: return "namespace";
2024 case EXPLICIT
: return "explicit";
2025 case TYPENAME
: return "typename";
2026 case CONST_CAST
: return "const_cast";
2027 case DYNAMIC_CAST
: return "dynamic_cast";
2028 case REINTERPRET_CAST
: return "reinterpret_cast";
2029 case STATIC_CAST
: return "static_cast";
2030 case TYPEID
: return "typeid";
2031 case USING
: return "using";
2032 case WCHAR
: return "wchar_t";
2033 case YYEOF
: return "EOF";
2048 /* Reinitialize the scanner for a new input file. */
2051 re_init_scanner (void)
2059 yytext
= (char *) xmalloc (size
* sizeof *yytext
);
2060 yytext_end
= yytext
+ size
;
2065 /* Insert a keyword NAME with token value TKV into the keyword hash
2069 insert_keyword (const char *name
, int tkv
)
2073 struct kw
*k
= (struct kw
*) xmalloc (sizeof *k
);
2075 for (s
= name
; *s
; ++s
)
2078 h
%= KEYWORD_TABLE_SIZE
;
2081 k
->next
= keyword_table
[h
];
2082 keyword_table
[h
] = k
;
2086 /* Initialize the scanner for the first file. This sets up the
2087 character class vectors and fills the keyword hash table. */
2094 /* Allocate the input buffer */
2095 inbuffer_size
= READ_CHUNK_SIZE
+ 1;
2096 inbuffer
= in
= (char *) xmalloc (inbuffer_size
);
2099 /* Set up character class vectors. */
2100 for (i
= 0; i
< sizeof is_ident
; ++i
)
2102 if (i
== '_' || isalnum (i
))
2105 if (i
>= '0' && i
<= '9')
2108 if (i
== ' ' || i
== '\t' || i
== '\f' || i
== '\v')
2112 /* Fill keyword hash table. */
2113 insert_keyword ("and", LAND
);
2114 insert_keyword ("and_eq", ANDASGN
);
2115 insert_keyword ("asm", ASM
);
2116 insert_keyword ("auto", AUTO
);
2117 insert_keyword ("bitand", '&');
2118 insert_keyword ("bitor", '|');
2119 insert_keyword ("bool", BOOL
);
2120 insert_keyword ("break", BREAK
);
2121 insert_keyword ("case", CASE
);
2122 insert_keyword ("catch", CATCH
);
2123 insert_keyword ("char", CHAR
);
2124 insert_keyword ("class", CLASS
);
2125 insert_keyword ("compl", '~');
2126 insert_keyword ("const", CONST
);
2127 insert_keyword ("const_cast", CONST_CAST
);
2128 insert_keyword ("continue", CONTINUE
);
2129 insert_keyword ("default", DEFAULT
);
2130 insert_keyword ("delete", DELETE
);
2131 insert_keyword ("do", DO
);
2132 insert_keyword ("double", DOUBLE
);
2133 insert_keyword ("dynamic_cast", DYNAMIC_CAST
);
2134 insert_keyword ("else", ELSE
);
2135 insert_keyword ("enum", ENUM
);
2136 insert_keyword ("explicit", EXPLICIT
);
2137 insert_keyword ("extern", EXTERN
);
2138 insert_keyword ("false", FALSE
);
2139 insert_keyword ("float", FLOAT
);
2140 insert_keyword ("for", FOR
);
2141 insert_keyword ("friend", FRIEND
);
2142 insert_keyword ("goto", GOTO
);
2143 insert_keyword ("if", IF
);
2144 insert_keyword ("inline", T_INLINE
);
2145 insert_keyword ("int", INT
);
2146 insert_keyword ("long", LONG
);
2147 insert_keyword ("mutable", MUTABLE
);
2148 insert_keyword ("namespace", NAMESPACE
);
2149 insert_keyword ("new", NEW
);
2150 insert_keyword ("not", '!');
2151 insert_keyword ("not_eq", NE
);
2152 insert_keyword ("operator", OPERATOR
);
2153 insert_keyword ("or", LOR
);
2154 insert_keyword ("or_eq", ORASGN
);
2155 insert_keyword ("private", PRIVATE
);
2156 insert_keyword ("protected", PROTECTED
);
2157 insert_keyword ("public", PUBLIC
);
2158 insert_keyword ("register", REGISTER
);
2159 insert_keyword ("reinterpret_cast", REINTERPRET_CAST
);
2160 insert_keyword ("return", RETURN
);
2161 insert_keyword ("short", SHORT
);
2162 insert_keyword ("signed", SIGNED
);
2163 insert_keyword ("sizeof", SIZEOF
);
2164 insert_keyword ("static", STATIC
);
2165 insert_keyword ("static_cast", STATIC_CAST
);
2166 insert_keyword ("struct", STRUCT
);
2167 insert_keyword ("switch", SWITCH
);
2168 insert_keyword ("template", TEMPLATE
);
2169 insert_keyword ("this", THIS
);
2170 insert_keyword ("throw", THROW
);
2171 insert_keyword ("true", TRUE
);
2172 insert_keyword ("try", TRY
);
2173 insert_keyword ("typedef", TYPEDEF
);
2174 insert_keyword ("typeid", TYPEID
);
2175 insert_keyword ("typename", TYPENAME
);
2176 insert_keyword ("union", UNION
);
2177 insert_keyword ("unsigned", UNSIGNED
);
2178 insert_keyword ("using", USING
);
2179 insert_keyword ("virtual", VIRTUAL
);
2180 insert_keyword ("void", VOID
);
2181 insert_keyword ("volatile", VOLATILE
);
2182 insert_keyword ("wchar_t", WCHAR
);
2183 insert_keyword ("while", WHILE
);
2184 insert_keyword ("xor", '^');
2185 insert_keyword ("xor_eq", XORASGN
);
2190 /***********************************************************************
2192 ***********************************************************************/
2194 /* Match the current lookahead token and set it to the next token. */
2196 #define MATCH() (tk = yylex ())
2198 /* Return the lookahead token. If current lookahead token is cleared,
2199 read a new token. */
2201 #define LA1 (tk == -1 ? (tk = yylex ()) : tk)
2203 /* Is the current lookahead equal to the token T? */
2205 #define LOOKING_AT(T) (tk == (T))
2207 /* Is the current lookahead one of T1 or T2? */
2209 #define LOOKING_AT2(T1, T2) (tk == (T1) || tk == (T2))
2211 /* Is the current lookahead one of T1, T2 or T3? */
2213 #define LOOKING_AT3(T1, T2, T3) (tk == (T1) || tk == (T2) || tk == (T3))
2215 /* Is the current lookahead one of T1...T4? */
2217 #define LOOKING_AT4(T1, T2, T3, T4) \
2218 (tk == (T1) || tk == (T2) || tk == (T3) || tk == (T4))
2220 /* Match token T if current lookahead is T. */
2222 #define MATCH_IF(T) if (LOOKING_AT (T)) MATCH (); else ((void) 0)
2224 /* Skip to matching token if current token is T. */
2226 #define SKIP_MATCHING_IF(T) \
2227 if (LOOKING_AT (T)) skip_matching (); else ((void) 0)
2230 /* Skip forward until a given token TOKEN or YYEOF is seen and return
2231 the current lookahead token after skipping. */
2236 while (!LOOKING_AT2 (YYEOF
, token
))
2241 /* Skip over pairs of tokens (parentheses, square brackets,
2242 angle brackets, curly brackets) matching the current lookahead. */
2245 skip_matching (void)
2273 if (LOOKING_AT (open
))
2275 else if (LOOKING_AT (close
))
2277 else if (LOOKING_AT (YYEOF
))
2288 skip_initializer (void)
2312 /* Build qualified namespace alias (A::B::c) and return it. */
2314 static struct link
*
2315 match_qualified_namespace_alias (void)
2317 struct link
*head
= NULL
;
2318 struct link
*cur
= NULL
;
2319 struct link
*tmp
= NULL
;
2327 tmp
= (struct link
*) xmalloc (sizeof *cur
);
2328 tmp
->sym
= find_namespace (yytext
, cur
? cur
->sym
: NULL
);
2332 cur
= cur
->next
= tmp
;
2349 /* Re-initialize the parser by resetting the lookahead token. */
2352 re_init_parser (void)
2358 /* Parse a parameter list, including the const-specifier,
2359 pure-specifier, and throw-list that may follow a parameter list.
2360 Return in FLAGS what was seen following the parameter list.
2361 Returns a hash code for the parameter types. This value is used to
2362 distinguish between overloaded functions. */
2365 parm_list (int *flags
)
2370 while (!LOOKING_AT2 (YYEOF
, ')'))
2374 /* Skip over grouping parens or parameter lists in parameter
2380 /* Next parameter. */
2386 /* Ignore the scope part of types, if any. This is because
2387 some types need scopes when defined outside of a class body,
2388 and don't need them inside the class body. This means that
2389 we have to look for the last IDENT in a sequence of
2390 IDENT::IDENT::... */
2395 unsigned ident_type_hash
= 0;
2397 parse_qualified_param_ident_or_type (&last_id
);
2400 /* LAST_ID null means something like `X::*'. */
2401 for (; *last_id
; ++last_id
)
2402 ident_type_hash
= (ident_type_hash
<< 1) ^ *last_id
;
2403 hash
= (hash
<< 1) ^ ident_type_hash
;
2412 /* This distinction is made to make `func (void)' equivalent
2416 if (!LOOKING_AT (')'))
2417 hash
= (hash
<< 1) ^ VOID
;
2420 case BOOL
: case CHAR
: case CLASS
: case CONST
:
2421 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2422 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2423 case UNION
: case UNSIGNED
: case VOLATILE
: case WCHAR
:
2426 hash
= (hash
<< 1) ^ LA1
;
2430 case '*': case '&': case '[': case ']':
2431 hash
= (hash
<< 1) ^ LA1
;
2441 if (LOOKING_AT (')'))
2445 if (LOOKING_AT (CONST
))
2447 /* We can overload the same function on `const' */
2448 hash
= (hash
<< 1) ^ CONST
;
2449 SET_FLAG (*flags
, F_CONST
);
2453 if (LOOKING_AT (THROW
))
2456 SKIP_MATCHING_IF ('(');
2457 SET_FLAG (*flags
, F_THROW
);
2460 if (LOOKING_AT ('='))
2463 if (LOOKING_AT (CINT
) && yyival
== 0)
2466 SET_FLAG (*flags
, F_PURE
);
2475 /* Print position info to stdout. */
2480 if (info_position
>= 0 && BUFFER_POS () <= info_position
)
2482 printf ("(\"%s\" \"%s\" \"%s\" %d)\n",
2483 info_cls
->name
, sym_scope (info_cls
),
2484 info_member
->name
, info_where
);
2488 /* Parse a member declaration within the class body of CLS. VIS is
2489 the access specifier for the member (private, protected,
2493 member (struct sym
*cls
, int vis
)
2497 char *regexp
= NULL
;
2508 while (!LOOKING_AT4 (';', '{', '}', YYEOF
))
2516 /* A function or class may follow. */
2519 SET_FLAG (flags
, F_TEMPLATE
);
2520 /* Skip over template argument list */
2521 SKIP_MATCHING_IF ('<');
2525 SET_FLAG (flags
, F_EXPLICIT
);
2529 SET_FLAG (flags
, F_MUTABLE
);
2533 SET_FLAG (flags
, F_INLINE
);
2537 SET_FLAG (flags
, F_VIRTUAL
);
2566 /* Remember IDENTS seen so far. Among these will be the member
2568 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
2572 strcpy (id
+ 1, yytext
);
2575 strcpy (id
, yytext
);
2581 char *s
= operator_name (&sc
);
2582 id
= (char *) xrealloc (id
, strlen (s
) + 1);
2588 /* Most probably the beginning of a parameter list. */
2594 if (!(is_constructor
= streq (id
, cls
->name
)))
2595 regexp
= matching_regexp ();
2600 pos
= BUFFER_POS ();
2601 hash
= parm_list (&flags
);
2604 regexp
= matching_regexp ();
2606 if (id
&& cls
!= NULL
)
2607 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, flags
);
2609 while (!LOOKING_AT3 (';', '{', YYEOF
))
2612 if (LOOKING_AT ('{') && id
&& cls
)
2613 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0, sc
, flags
);
2620 case STRUCT
: case UNION
: case CLASS
:
2627 /* More than one ident here to allow for MS-DOS specialties
2628 like `_export class' etc. The last IDENT seen counts
2629 as the class name. */
2630 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
2632 if (LOOKING_AT (IDENT
))
2637 if (LOOKING_AT2 (':', '{'))
2638 class_definition (anonymous
? NULL
: cls
, class_tag
, flags
, 1);
2643 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
2644 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
2645 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
2654 if (LOOKING_AT (';'))
2656 /* The end of a member variable, a friend declaration or an access
2657 declaration. We don't want to add friend classes as members. */
2658 if (id
&& sc
!= SC_FRIEND
&& cls
)
2660 regexp
= matching_regexp ();
2661 pos
= BUFFER_POS ();
2665 if (type_seen
|| !paren_seen
)
2666 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2668 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, 0);
2675 else if (LOOKING_AT ('{'))
2678 if (sc
== SC_TYPE
&& id
&& cls
)
2680 regexp
= matching_regexp ();
2681 pos
= BUFFER_POS ();
2685 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2686 add_member_defn (cls
, id
, regexp
, pos
, 0, 1, sc
, 0);
2698 /* Parse the body of class CLS. TAG is the tag of the class (struct,
2702 class_body (struct sym
*cls
, int tag
)
2704 int vis
= tag
== CLASS
? PRIVATE
: PUBLIC
;
2707 while (!LOOKING_AT2 (YYEOF
, '}'))
2711 case PRIVATE
: case PROTECTED
: case PUBLIC
:
2715 if (LOOKING_AT (':'))
2722 /* Probably conditional compilation for inheritance list.
2723 We don't known whether there comes more of this.
2724 This is only a crude fix that works most of the time. */
2729 while (LOOKING_AT2 (IDENT
, ',')
2730 || LOOKING_AT3 (PUBLIC
, PROTECTED
, PRIVATE
));
2739 /* Try to synchronize */
2740 case CHAR
: case CLASS
: case CONST
:
2741 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2742 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2743 case UNION
: case UNSIGNED
: case VOID
: case VOLATILE
:
2744 case TYPEDEF
: case STATIC
: case T_INLINE
: case FRIEND
:
2745 case VIRTUAL
: case TEMPLATE
: case IDENT
: case '~':
2746 case BOOL
: case WCHAR
: case EXPLICIT
: case MUTABLE
:
2758 /* Parse a qualified identifier. Current lookahead is IDENT. A
2759 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
2760 symbol for that class. */
2763 parse_classname (void)
2765 struct sym
*last_class
= NULL
;
2767 while (LOOKING_AT (IDENT
))
2769 last_class
= add_sym (yytext
, last_class
);
2772 if (LOOKING_AT ('<'))
2775 SET_FLAG (last_class
->flags
, F_TEMPLATE
);
2778 if (!LOOKING_AT (DCOLON
))
2788 /* Parse an operator name. Add the `static' flag to *SC if an
2789 implicitly static operator has been parsed. Value is a pointer to
2790 a static buffer holding the constructed operator name string. */
2793 operator_name (int *sc
)
2795 static size_t id_size
= 0;
2796 static char *id
= NULL
;
2802 if (LOOKING_AT2 (NEW
, DELETE
))
2804 /* `new' and `delete' are implicitly static. */
2805 if (*sc
!= SC_FRIEND
)
2808 s
= token_string (LA1
);
2811 len
= strlen (s
) + 10;
2814 size_t new_size
= max (len
, 2 * id_size
);
2815 id
= (char *) xrealloc (id
, new_size
);
2820 /* Vector new or delete? */
2821 if (LOOKING_AT ('['))
2826 if (LOOKING_AT (']'))
2835 size_t tokens_matched
= 0;
2840 int new_size
= max (len
, 2 * id_size
);
2841 id
= (char *) xrealloc (id
, new_size
);
2844 strcpy (id
, "operator");
2846 /* Beware access declarations of the form "X::f;" Beware of
2847 `operator () ()'. Yet another difficulty is found in
2848 GCC 2.95's STL: `operator == __STL_NULL_TMPL_ARGS (...'. */
2849 while (!(LOOKING_AT ('(') && tokens_matched
)
2850 && !LOOKING_AT2 (';', YYEOF
))
2852 s
= token_string (LA1
);
2853 len
+= strlen (s
) + 2;
2856 size_t new_size
= max (len
, 2 * id_size
);
2857 id
= (char *) xrealloc (id
, new_size
);
2861 if (*s
!= ')' && *s
!= ']')
2866 /* If this is a simple operator like `+', stop now. */
2867 if (!isalpha ((unsigned char) *s
) && *s
!= '(' && *s
!= '[')
2878 /* This one consumes the last IDENT of a qualified member name like
2879 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2880 symbol structure for the ident. */
2883 parse_qualified_ident_or_type (char **last_id
)
2885 struct sym
*cls
= NULL
;
2890 while (LOOKING_AT (IDENT
))
2892 int len
= strlen (yytext
) + 1;
2895 id
= (char *) xrealloc (id
, len
);
2898 strcpy (id
, yytext
);
2902 SKIP_MATCHING_IF ('<');
2904 if (LOOKING_AT (DCOLON
))
2906 struct sym
*pcn
= NULL
;
2907 struct link
*pna
= check_namespace_alias (id
);
2912 enter_namespace (pna
->sym
->name
);
2918 else if ((pcn
= check_namespace (id
, current_namespace
)))
2920 enter_namespace (pcn
->name
);
2924 cls
= add_sym (id
, cls
);
2943 /* This one consumes the last IDENT of a qualified member name like
2944 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2945 symbol structure for the ident. */
2948 parse_qualified_param_ident_or_type (char **last_id
)
2950 struct sym
*cls
= NULL
;
2951 static char *id
= NULL
;
2952 static int id_size
= 0;
2954 assert (LOOKING_AT (IDENT
));
2958 int len
= strlen (yytext
) + 1;
2961 id
= (char *) xrealloc (id
, len
);
2964 strcpy (id
, yytext
);
2968 SKIP_MATCHING_IF ('<');
2970 if (LOOKING_AT (DCOLON
))
2972 cls
= add_sym (id
, cls
);
2979 while (LOOKING_AT (IDENT
));
2983 /* Parse a class definition.
2985 CONTAINING is the class containing the class being parsed or null.
2986 This may also be null if NESTED != 0 if the containing class is
2987 anonymous. TAG is the tag of the class (struct, union, class).
2988 NESTED is non-zero if we are parsing a nested class.
2990 Current lookahead is the class name. */
2993 class_definition (struct sym
*containing
, int tag
, int flags
, int nested
)
2995 struct sym
*current
;
2996 struct sym
*base_class
;
2998 /* Set CURRENT to null if no entry has to be made for the class
2999 parsed. This is the case for certain command line flag
3001 if ((tag
!= CLASS
&& !f_structs
) || (nested
&& !f_nested_classes
))
3005 current
= add_sym (yytext
, containing
);
3006 current
->pos
= BUFFER_POS ();
3007 current
->regexp
= matching_regexp ();
3008 current
->filename
= filename
;
3009 current
->flags
= flags
;
3012 /* If at ':', base class list follows. */
3013 if (LOOKING_AT (':'))
3022 case VIRTUAL
: case PUBLIC
: case PROTECTED
: case PRIVATE
:
3027 base_class
= parse_classname ();
3028 if (base_class
&& current
&& base_class
!= current
)
3029 add_link (base_class
, current
);
3032 /* The `,' between base classes or the end of the base
3033 class list. Add the previously found base class.
3034 It's done this way to skip over sequences of
3035 `A::B::C' until we reach the end.
3037 FIXME: it is now possible to handle `class X : public B::X'
3038 because we have enough information. */
3044 /* A syntax error, possibly due to preprocessor constructs
3050 class A : private B.
3052 MATCH until we see something like `;' or `{'. */
3053 while (!LOOKING_AT3 (';', YYEOF
, '{'))
3064 /* Parse the class body if there is one. */
3065 if (LOOKING_AT ('{'))
3067 if (tag
!= CLASS
&& !f_structs
)
3072 class_body (current
, tag
);
3074 if (LOOKING_AT ('}'))
3077 if (LOOKING_AT (';') && !nested
)
3084 /* Add to class *CLS information for the declaration of variable or
3085 type *ID. If *CLS is null, this means a global declaration. SC is
3086 the storage class of *ID. FLAGS is a bit set giving additional
3087 information about the member (see the F_* defines). */
3090 add_declarator (struct sym
**cls
, char **id
, int flags
, int sc
)
3092 if (LOOKING_AT2 (';', ','))
3094 /* The end of a member variable or of an access declaration
3095 `X::f'. To distinguish between them we have to know whether
3096 type information has been seen. */
3099 char *regexp
= matching_regexp ();
3100 int pos
= BUFFER_POS ();
3103 add_member_defn (*cls
, *id
, regexp
, pos
, 0, 1, SC_UNKNOWN
, flags
);
3105 add_global_defn (*id
, regexp
, pos
, 0, 1, sc
, flags
);
3111 else if (LOOKING_AT ('{'))
3113 if (sc
== SC_TYPE
&& *id
)
3115 /* A named enumeration. */
3116 char *regexp
= matching_regexp ();
3117 int pos
= BUFFER_POS ();
3118 add_global_defn (*id
, regexp
, pos
, 0, 1, sc
, flags
);
3130 /* Parse a declaration. */
3133 declaration (int flags
)
3136 struct sym
*cls
= NULL
;
3137 char *regexp
= NULL
;
3143 while (!LOOKING_AT3 (';', '{', YYEOF
))
3166 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
3167 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
3168 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
3172 case CLASS
: case STRUCT
: case UNION
:
3173 /* This is for the case `STARTWRAP class X : ...' or
3174 `declare (X, Y)\n class A : ...'. */
3182 /* Assumed to be the start of an initialization in this
3184 skip_initializer ();
3188 add_declarator (&cls
, &id
, flags
, sc
);
3193 char *s
= operator_name (&sc
);
3194 id
= (char *) xrealloc (id
, strlen (s
) + 1);
3200 SET_FLAG (flags
, F_INLINE
);
3206 if (LOOKING_AT (IDENT
))
3208 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
3210 strcpy (id
+ 1, yytext
);
3216 cls
= parse_qualified_ident_or_type (&id
);
3220 /* Most probably the beginning of a parameter list. */
3227 if (!(is_constructor
= streq (id
, cls
->name
)))
3228 regexp
= matching_regexp ();
3233 pos
= BUFFER_POS ();
3234 hash
= parm_list (&flags
);
3237 regexp
= matching_regexp ();
3240 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0,
3245 /* This may be a C functions, but also a macro
3246 call of the form `declare (A, B)' --- such macros
3247 can be found in some class libraries. */
3252 regexp
= matching_regexp ();
3253 pos
= BUFFER_POS ();
3254 hash
= parm_list (&flags
);
3255 add_global_decl (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3258 /* This is for the case that the function really is
3259 a macro with no `;' following it. If a CLASS directly
3260 follows, we would miss it otherwise. */
3261 if (LOOKING_AT3 (CLASS
, STRUCT
, UNION
))
3265 while (!LOOKING_AT3 (';', '{', YYEOF
))
3268 if (!cls
&& id
&& LOOKING_AT ('{'))
3269 add_global_defn (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3277 add_declarator (&cls
, &id
, flags
, sc
);
3281 /* Parse a list of top-level declarations/definitions. START_FLAGS
3282 says in which context we are parsing. If it is F_EXTERNC, we are
3283 parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0
3287 globals (int start_flags
)
3291 int flags
= start_flags
;
3303 if (LOOKING_AT (IDENT
))
3305 char *namespace_name
= xstrdup (yytext
);
3308 if (LOOKING_AT ('='))
3310 struct link
*qna
= match_qualified_namespace_alias ();
3312 register_namespace_alias (namespace_name
, qna
);
3314 if (skip_to (';') == ';')
3317 else if (LOOKING_AT ('{'))
3320 enter_namespace (namespace_name
);
3326 free (namespace_name
);
3333 if (LOOKING_AT (CSTRING
) && *string_start
== 'C'
3334 && *(string_start
+ 1) == '"')
3336 /* This is `extern "C"'. */
3339 if (LOOKING_AT ('{'))
3342 globals (F_EXTERNC
);
3346 SET_FLAG (flags
, F_EXTERNC
);
3352 SKIP_MATCHING_IF ('<');
3353 SET_FLAG (flags
, F_TEMPLATE
);
3356 case CLASS
: case STRUCT
: case UNION
:
3361 /* More than one ident here to allow for MS-DOS and OS/2
3362 specialties like `far', `_Export' etc. Some C++ libs
3363 have constructs like `_OS_DLLIMPORT(_OS_CLIENT)' in front
3364 of the class name. */
3365 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
3367 if (LOOKING_AT (IDENT
))
3372 /* Don't add anonymous unions. */
3373 if (LOOKING_AT2 (':', '{') && !anonymous
)
3374 class_definition (NULL
, class_tk
, flags
, 0);
3377 if (skip_to (';') == ';')
3381 flags
= start_flags
;
3391 declaration (flags
);
3392 flags
= start_flags
;
3397 yyerror ("parse error", NULL
);
3402 /* Parse the current input file. */
3407 while (globals (0) == 0)
3413 /***********************************************************************
3415 ***********************************************************************/
3417 /* Add the list of paths PATH_LIST to the current search path for
3421 add_search_path (char *path_list
)
3425 char *start
= path_list
;
3426 struct search_path
*p
;
3428 while (*path_list
&& *path_list
!= PATH_LIST_SEPARATOR
)
3431 p
= (struct search_path
*) xmalloc (sizeof *p
);
3432 p
->path
= (char *) xmalloc (path_list
- start
+ 1);
3433 memcpy (p
->path
, start
, path_list
- start
);
3434 p
->path
[path_list
- start
] = '\0';
3437 if (search_path_tail
)
3439 search_path_tail
->next
= p
;
3440 search_path_tail
= p
;
3443 search_path
= search_path_tail
= p
;
3445 while (*path_list
== PATH_LIST_SEPARATOR
)
3451 /* Open FILE and return a file handle for it, or -1 if FILE cannot be
3452 opened. Try to find FILE in search_path first, then try the
3453 unchanged file name. */
3456 open_file (char *file
)
3459 static char *buffer
;
3460 static int buffer_size
;
3461 struct search_path
*path
;
3462 int flen
= strlen (file
) + 1; /* +1 for the slash */
3464 filename
= xstrdup (file
);
3466 for (path
= search_path
; path
&& fp
== NULL
; path
= path
->next
)
3468 int len
= strlen (path
->path
) + flen
;
3470 if (len
+ 1 >= buffer_size
)
3472 buffer_size
= max (len
+ 1, 2 * buffer_size
);
3473 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3476 strcpy (buffer
, path
->path
);
3477 strcat (buffer
, "/");
3478 strcat (buffer
, file
);
3479 fp
= fopen (buffer
, "r");
3482 /* Try the original file name. */
3484 fp
= fopen (file
, "r");
3487 yyerror ("cannot open", NULL
);
3493 /* Display usage information and exit program. */
3496 Usage: ebrowse [options] {files}\n\
3498 -a, --append append output to existing file\n\
3499 -f, --files=FILES read input file names from FILE\n\
3500 -I, --search-path=LIST set search path for input files\n\
3501 -m, --min-regexp-length=N set minimum regexp length to N\n\
3502 -M, --max-regexp-length=N set maximum regexp length to N\n\
3503 -n, --no-nested-classes exclude nested classes\n\
3504 -o, --output-file=FILE set output file name to FILE\n\
3505 -p, --position-info print info about position in file\n\
3506 -s, --no-structs-or-unions don't record structs or unions\n\
3507 -v, --verbose be verbose\n\
3508 -V, --very-verbose be very verbose\n\
3509 -x, --no-regexps don't record regular expressions\n\
3510 --help display this help\n\
3511 --version display version info\n\
3518 exit (error
? EXIT_FAILURE
: EXIT_SUCCESS
);
3522 /* Display version and copyright info. The VERSION macro is set
3523 from config.h and contains the Emacs version. */
3526 # define VERSION "21"
3532 /* Makes it easier to update automatically. */
3533 char emacs_copyright
[] = "Copyright (C) 2011 Free Software Foundation, Inc.";
3535 printf ("ebrowse %s\n", VERSION
);
3536 puts (emacs_copyright
);
3537 puts ("This program is distributed under the same terms as Emacs.");
3538 exit (EXIT_SUCCESS
);
3542 /* Parse one input file FILE, adding classes and members to the symbol
3546 process_file (char *file
)
3550 fp
= open_file (file
);
3553 size_t nread
, nbytes
;
3555 /* Give a progress indication if needed. */
3567 /* Read file to inbuffer. */
3570 if (nread
+ READ_CHUNK_SIZE
>= inbuffer_size
)
3572 inbuffer_size
= nread
+ READ_CHUNK_SIZE
+ 1;
3573 inbuffer
= (char *) xrealloc (inbuffer
, inbuffer_size
);
3576 nbytes
= fread (inbuffer
+ nread
, 1, READ_CHUNK_SIZE
, fp
);
3581 inbuffer
[nread
] = '\0';
3583 /* Reinitialize scanner and parser for the new input file. */
3587 /* Parse it and close the file. */
3594 /* Read a line from stream FP and return a pointer to a static buffer
3595 containing its contents without the terminating newline. Value
3596 is null when EOF is reached. */
3599 read_line (FILE *fp
)
3601 static char *buffer
;
3602 static int buffer_size
;
3605 while ((c
= getc (fp
)) != EOF
&& c
!= '\n')
3607 if (i
>= buffer_size
)
3609 buffer_size
= max (100, buffer_size
* 2);
3610 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3616 if (c
== EOF
&& i
== 0)
3619 if (i
== buffer_size
)
3621 buffer_size
= max (100, buffer_size
* 2);
3622 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3626 if (i
> 0 && buffer
[i
- 1] == '\r')
3627 buffer
[i
- 1] = '\0';
3632 /* Main entry point. */
3635 main (int argc
, char **argv
)
3638 int any_inputfiles
= 0;
3639 static const char *out_filename
= DEFAULT_OUTFILE
;
3640 static char **input_filenames
= NULL
;
3641 static int input_filenames_size
= 0;
3642 static int n_input_files
;
3644 filename
= "command line";
3647 while ((i
= getopt_long (argc
, argv
, "af:I:m:M:no:p:svVx",
3648 options
, NULL
)) != EOF
)
3654 info_position
= atoi (optarg
);
3658 f_nested_classes
= 0;
3665 /* Add the name of a file containing more input files. */
3667 if (n_input_files
== input_filenames_size
)
3669 input_filenames_size
= max (10, 2 * input_filenames_size
);
3670 input_filenames
= (char **) xrealloc ((void *)input_filenames
,
3671 input_filenames_size
);
3673 input_filenames
[n_input_files
++] = xstrdup (optarg
);
3676 /* Append new output to output file instead of truncating it. */
3681 /* Include structs in the output */
3686 /* Be verbose (give a progress indication). */
3691 /* Be very verbose (print file names as they are processed). */
3697 /* Change the name of the output file. */
3699 out_filename
= optarg
;
3702 /* Set minimum length for regular expression strings
3703 when recorded in the output file. */
3705 min_regexp
= atoi (optarg
);
3708 /* Set maximum length for regular expression strings
3709 when recorded in the output file. */
3711 max_regexp
= atoi (optarg
);
3714 /* Add to search path. */
3716 add_search_path (optarg
);
3730 /* Call init_scanner after command line flags have been processed to be
3731 able to add keywords depending on command line (not yet
3736 /* Open output file */
3741 /* Check that the file to append to exists, and is not
3742 empty. More specifically, it should be a valid file
3743 produced by a previous run of ebrowse, but that's too
3744 difficult to check. */
3748 fp
= fopen (out_filename
, "r");
3751 yyerror ("file `%s' must exist for --append", out_filename
);
3752 exit (EXIT_FAILURE
);
3755 rc
= fseek (fp
, 0, SEEK_END
);
3758 yyerror ("error seeking in file `%s'", out_filename
);
3759 exit (EXIT_FAILURE
);
3765 yyerror ("error getting size of file `%s'", out_filename
);
3766 exit (EXIT_FAILURE
);
3771 yyerror ("file `%s' is empty", out_filename
);
3772 /* It may be ok to use an empty file for appending.
3773 exit (EXIT_FAILURE); */
3779 yyout
= fopen (out_filename
, f_append
? "a" : "w");
3782 yyerror ("cannot open output file `%s'", out_filename
);
3783 exit (EXIT_FAILURE
);
3787 /* Process input files specified on the command line. */
3788 while (optind
< argc
)
3790 process_file (argv
[optind
++]);
3794 /* Process files given on stdin if no files specified. */
3795 if (!any_inputfiles
&& n_input_files
== 0)
3798 while ((file
= read_line (stdin
)) != NULL
)
3799 process_file (file
);
3803 /* Process files from `--files=FILE'. Every line in FILE names
3804 one input file to process. */
3805 for (i
= 0; i
< n_input_files
; ++i
)
3807 FILE *fp
= fopen (input_filenames
[i
], "r");
3810 yyerror ("cannot open input file `%s'", input_filenames
[i
]);
3814 while ((file
= read_line (fp
)) != NULL
)
3815 process_file (file
);
3821 /* Write output file. */
3824 /* Close output file. */
3825 if (yyout
!= stdout
)
3828 return EXIT_SUCCESS
;
3831 /* ebrowse.c ends here */