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 BROWSE_STRUCT "[ebrowse-bs "
81 #define CLASS_STRUCT "[ebrowse-cs "
83 /* The name of the symbol table entry for global functions, variables,
84 defines etc. This name also appears in the browser display. */
86 #define GLOBALS_NAME "*Globals*"
88 /* Token definitions. */
92 YYEOF
= 0, /* end of file */
93 CSTRING
= 256, /* string constant */
94 CCHAR
, /* character constant */
95 CINT
, /* integral constant */
96 CFLOAT
, /* real constant */
100 RSHIFTASGN
, /* >>= */
102 IDENT
, /* identifier */
125 /* Keywords. The undef's are there because these
126 three symbols are very likely to be defined somewhere. */
139 CONTINUE
, /* continue */
140 DEFAULT
, /* default */
152 T_INLINE
, /* inline */
156 OPERATOR
, /* operator */
157 PRIVATE
, /* private */
158 PROTECTED
, /* protected */
160 REGISTER
, /* register */
168 TEMPLATE
, /* template */
172 TYPEDEF
, /* typedef */
174 UNSIGNED
, /* unsigned */
175 VIRTUAL
, /* virtual */
177 VOLATILE
, /* volatile */
179 MUTABLE
, /* mutable */
183 SIGNATURE
, /* signature (GNU extension) */
184 NAMESPACE
, /* namespace */
185 EXPLICIT
, /* explicit */
186 TYPENAME
, /* typename */
187 CONST_CAST
, /* const_cast */
188 DYNAMIC_CAST
, /* dynamic_cast */
189 REINTERPRET_CAST
, /* reinterpret_cast */
190 STATIC_CAST
, /* static_cast */
196 /* Storage classes, in a wider sense. */
201 SC_MEMBER
, /* Is an instance member. */
202 SC_STATIC
, /* Is static member. */
203 SC_FRIEND
, /* Is friend function. */
204 SC_TYPE
/* Is a type definition. */
207 /* Member visibility. */
218 #define F_VIRTUAL 1 /* Is virtual function. */
219 #define F_INLINE 2 /* Is inline function. */
220 #define F_CONST 4 /* Is const. */
221 #define F_PURE 8 /* Is pure virtual function. */
222 #define F_MUTABLE 16 /* Is mutable. */
223 #define F_TEMPLATE 32 /* Is a template. */
224 #define F_EXPLICIT 64 /* Is explicit constructor. */
225 #define F_THROW 128 /* Has a throw specification. */
226 #define F_EXTERNC 256 /* Is declared extern "C". */
227 #define F_DEFINE 512 /* Is a #define. */
229 /* Two macros to set and test a bit in an int. */
231 #define SET_FLAG(F, FLAG) ((F) |= (FLAG))
232 #define HAS_FLAG(F, FLAG) (((F) & (FLAG)) != 0)
234 /* Structure describing a class member. */
238 struct member
*next
; /* Next in list of members. */
239 struct member
*anext
; /* Collision chain in member_table. */
240 struct member
**list
; /* Pointer to list in class. */
241 unsigned param_hash
; /* Hash value for parameter types. */
242 int vis
; /* Visibility (public, ...). */
243 int flags
; /* See F_* above. */
244 char *regexp
; /* Matching regular expression. */
245 const char *filename
; /* Don't free this shared string. */
246 int pos
; /* Buffer position of occurrence. */
247 char *def_regexp
; /* Regular expression matching definition. */
248 const char *def_filename
; /* File name of definition. */
249 int def_pos
; /* Buffer position of definition. */
250 char name
[1]; /* Member name. */
253 /* Structures of this type are used to connect class structures with
254 their super and subclasses. */
258 struct sym
*sym
; /* The super or subclass. */
259 struct link
*next
; /* Next in list or NULL. */
262 /* Structure used to record namespace aliases. */
266 struct alias
*next
; /* Next in list. */
267 struct sym
*namesp
; /* Namespace in which defined. */
268 struct link
*aliasee
; /* List of aliased namespaces (A::B::C...). */
269 char name
[1]; /* Alias name. */
272 /* The structure used to describe a class in the symbol table,
273 or a namespace in all_namespaces. */
277 int flags
; /* Is class a template class?. */
278 unsigned char visited
; /* Used to find circles. */
279 struct sym
*next
; /* Hash collision list. */
280 struct link
*subs
; /* List of subclasses. */
281 struct link
*supers
; /* List of superclasses. */
282 struct member
*vars
; /* List of instance variables. */
283 struct member
*fns
; /* List of instance functions. */
284 struct member
*static_vars
; /* List of static variables. */
285 struct member
*static_fns
; /* List of static functions. */
286 struct member
*friends
; /* List of friend functions. */
287 struct member
*types
; /* List of local types. */
288 char *regexp
; /* Matching regular expression. */
289 int pos
; /* Buffer position. */
290 const char *filename
; /* File in which it can be found. */
291 const char *sfilename
; /* File in which members can be found. */
292 struct sym
*namesp
; /* Namespace in which defined. . */
293 char name
[1]; /* Name of the class. */
296 /* Experimental: Print info for `--position-info'. We print
297 '(CLASS-NAME SCOPE MEMBER-NAME). */
303 struct sym
*info_cls
= NULL
;
304 struct member
*info_member
= NULL
;
306 /* Experimental. For option `--position-info', the buffer position we
307 are interested in. When this position is reached, print out
308 information about what we know about that point. */
310 int info_position
= -1;
312 /* Command line options structure for getopt_long. */
314 struct option options
[] =
316 {"append", no_argument
, NULL
, 'a'},
317 {"files", required_argument
, NULL
, 'f'},
318 {"help", no_argument
, NULL
, -2},
319 {"min-regexp-length", required_argument
, NULL
, 'm'},
320 {"max-regexp-length", required_argument
, NULL
, 'M'},
321 {"no-nested-classes", no_argument
, NULL
, 'n'},
322 {"no-regexps", no_argument
, NULL
, 'x'},
323 {"no-structs-or-unions", no_argument
, NULL
, 's'},
324 {"output-file", required_argument
, NULL
, 'o'},
325 {"position-info", required_argument
, NULL
, 'p'},
326 {"search-path", required_argument
, NULL
, 'I'},
327 {"verbose", no_argument
, NULL
, 'v'},
328 {"version", no_argument
, NULL
, -3},
329 {"very-verbose", no_argument
, NULL
, 'V'},
333 /* Semantic values of tokens. Set by yylex.. */
335 unsigned yyival
; /* Set for token CINT. */
336 char *yytext
; /* Set for token IDENT. */
343 /* Current line number. */
347 /* The name of the current input file. */
349 const char *filename
;
351 /* Three character class vectors, and macros to test membership
358 #define IDENTP(C) is_ident[(unsigned char) (C)]
359 #define DIGITP(C) is_digit[(unsigned char) (C)]
360 #define WHITEP(C) is_white[(unsigned char) (C)]
362 /* Command line flags. */
369 int f_nested_classes
= 1;
371 /* Maximum and minimum lengths of regular expressions matching a
372 member, class etc., for writing them to the output file. These are
373 overridable from the command line. */
384 /* Return the current buffer position in the input file. */
386 #define BUFFER_POS() (in - inbuffer)
388 /* If current lookahead is CSTRING, the following points to the
389 first character in the string constant. Used for recognizing
394 /* The size of the hash tables for classes.and members. Should be
397 #define TABLE_SIZE 1001
399 /* The hash table for class symbols. */
401 struct sym
*class_table
[TABLE_SIZE
];
403 /* Hash table containing all member structures. This is generally
404 faster for member lookup than traversing the member lists of a
407 struct member
*member_table
[TABLE_SIZE
];
409 /* Hash table for namespace aliases */
411 struct alias
*namespace_alias_table
[TABLE_SIZE
];
413 /* The special class symbol used to hold global functions,
416 struct sym
*global_symbols
;
418 /* The current namespace. */
420 struct sym
*current_namespace
;
422 /* The list of all known namespaces. */
424 struct sym
*all_namespaces
;
426 /* Stack of namespaces we're currently nested in, during the parse. */
428 struct sym
**namespace_stack
;
429 int namespace_stack_size
;
432 /* The current lookahead token. */
436 /* Structure describing a keyword. */
440 const char *name
; /* Spelling. */
441 int tk
; /* Token value. */
442 struct kw
*next
; /* Next in collision chain. */
445 /* Keywords are lookup up in a hash table of their own. */
447 #define KEYWORD_TABLE_SIZE 1001
448 struct kw
*keyword_table
[KEYWORD_TABLE_SIZE
];
455 struct search_path
*next
;
458 struct search_path
*search_path
;
459 struct search_path
*search_path_tail
;
461 /* Function prototypes. */
463 static char *matching_regexp (void);
464 static struct sym
*add_sym (const char *, struct sym
*);
465 static void add_global_defn (char *, char *, int, unsigned, int, int, int);
466 static void add_global_decl (char *, char *, int, unsigned, int, int, int);
467 static struct member
*add_member (struct sym
*, char *, int, int, unsigned);
468 static void class_definition (struct sym
*, int, int, int);
469 static char *operator_name (int *);
470 static void parse_qualified_param_ident_or_type (char **);
471 static void usage (int) NO_RETURN
;
472 static void version (void) NO_RETURN
;
476 /***********************************************************************
478 ***********************************************************************/
480 /* Print an error in a printf-like style with the current input file
481 name and line number. */
484 yyerror (const char *format
, const char *s
)
486 fprintf (stderr
, "%s:%d: ", filename
, yyline
);
487 fprintf (stderr
, format
, s
);
492 /* Like malloc but print an error and exit if not enough memory is
498 void *p
= malloc (nbytes
);
501 yyerror ("out of memory", NULL
);
508 /* Like realloc but print an error and exit if out of memory. */
511 xrealloc (void *p
, int sz
)
516 yyerror ("out of memory", NULL
);
523 /* Like strdup, but print an error and exit if not enough memory is
524 available.. If S is null, return null. */
530 s
= strcpy (xmalloc (strlen (s
) + 1), s
);
536 /***********************************************************************
538 ***********************************************************************/
540 /* Initialize the symbol table. This currently only sets up the
541 special symbol for globals (`*Globals*'). */
546 global_symbols
= add_sym (GLOBALS_NAME
, NULL
);
550 /* Add a symbol for class NAME to the symbol table. NESTED_IN_CLASS
551 is the class in which class NAME was found. If it is null,
552 this means the scope of NAME is the current namespace.
554 If a symbol for NAME already exists, return that. Otherwise
555 create a new symbol and set it to default values. */
558 add_sym (const char *name
, struct sym
*nested_in_class
)
563 struct sym
*scope
= nested_in_class
? nested_in_class
: current_namespace
;
565 for (s
= name
, h
= 0; *s
; ++s
)
569 for (sym
= class_table
[h
]; sym
; sym
= sym
->next
)
570 if (streq (name
, sym
->name
)
571 && ((!sym
->namesp
&& !scope
)
572 || (sym
->namesp
&& scope
573 && streq (sym
->namesp
->name
, scope
->name
))))
584 sym
= (struct sym
*) xmalloc (sizeof *sym
+ strlen (name
));
585 memset (sym
, 0, sizeof *sym
);
586 strcpy (sym
->name
, name
);
588 sym
->next
= class_table
[h
];
589 class_table
[h
] = sym
;
596 /* Add links between superclass SUPER and subclass SUB. */
599 add_link (struct sym
*super
, struct sym
*sub
)
601 struct link
*lnk
, *lnk2
, *p
, *prev
;
603 /* See if a link already exists. */
604 for (p
= super
->subs
, prev
= NULL
;
605 p
&& strcmp (sub
->name
, p
->sym
->name
) > 0;
606 prev
= p
, p
= p
->next
)
609 /* Avoid duplicates. */
610 if (p
== NULL
|| p
->sym
!= sub
)
612 lnk
= (struct link
*) xmalloc (sizeof *lnk
);
613 lnk2
= (struct link
*) xmalloc (sizeof *lnk2
);
624 lnk2
->next
= sub
->supers
;
630 /* Find in class CLS member NAME.
632 VAR non-zero means look for a member variable; otherwise a function
633 is searched. SC specifies what kind of member is searched---a
634 static, or per-instance member etc. HASH is a hash code for the
635 parameter types of functions. Value is a pointer to the member
636 found or null if not found. */
638 static struct member
*
639 find_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
641 struct member
**list
;
643 unsigned name_hash
= 0;
650 list
= &cls
->friends
;
658 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
662 list
= var
? &cls
->vars
: &cls
->fns
;
666 for (s
= name
; *s
; ++s
)
667 name_hash
= (name_hash
<< 1) ^ *s
;
668 i
= name_hash
% TABLE_SIZE
;
670 for (p
= member_table
[i
]; p
; p
= p
->anext
)
671 if (p
->list
== list
&& p
->param_hash
== hash
&& streq (name
, p
->name
))
678 /* Add to class CLS information for the declaration of member NAME.
679 REGEXP is a regexp matching the declaration, if non-null. POS is
680 the position in the source where the declaration is found. HASH is
681 a hash code for the parameter list of the member, if it's a
682 function. VAR non-zero means member is a variable or type. SC
683 specifies the type of member (instance member, static, ...). VIS
684 is the member's visibility (public, protected, private). FLAGS is
685 a bit set giving additional information about the member (see the
689 add_member_decl (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int vis
, int flags
)
693 m
= find_member (cls
, name
, var
, sc
, hash
);
695 m
= add_member (cls
, name
, var
, sc
, hash
);
697 /* Have we seen a new filename? If so record that. */
698 if (!cls
->filename
|| !FILENAME_EQ (cls
->filename
, filename
))
699 m
->filename
= filename
;
712 m
->vis
= V_PROTECTED
;
726 /* Add to class CLS information for the definition of member NAME.
727 REGEXP is a regexp matching the declaration, if non-null. POS is
728 the position in the source where the declaration is found. HASH is
729 a hash code for the parameter list of the member, if it's a
730 function. VAR non-zero means member is a variable or type. SC
731 specifies the type of member (instance member, static, ...). VIS
732 is the member's visibility (public, protected, private). FLAGS is
733 a bit set giving additional information about the member (see the
737 add_member_defn (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
741 if (sc
== SC_UNKNOWN
)
743 m
= find_member (cls
, name
, var
, SC_MEMBER
, hash
);
746 m
= find_member (cls
, name
, var
, SC_STATIC
, hash
);
748 m
= add_member (cls
, name
, var
, sc
, hash
);
753 m
= find_member (cls
, name
, var
, sc
, hash
);
755 m
= add_member (cls
, name
, var
, sc
, hash
);
759 cls
->sfilename
= filename
;
761 if (!FILENAME_EQ (cls
->sfilename
, filename
))
762 m
->def_filename
= filename
;
764 m
->def_regexp
= regexp
;
774 /* Add a symbol for a define named NAME to the symbol table.
775 REGEXP is a regular expression matching the define in the source,
776 if it is non-null. POS is the position in the file. */
779 add_define (char *name
, char *regexp
, int pos
)
781 add_global_defn (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
782 add_global_decl (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
786 /* Add information for the global definition of NAME.
787 REGEXP is a regexp matching the declaration, if non-null. POS is
788 the position in the source where the declaration is found. HASH is
789 a hash code for the parameter list of the member, if it's a
790 function. VAR non-zero means member is a variable or type. SC
791 specifies the type of member (instance member, static, ...). VIS
792 is the member's visibility (public, protected, private). FLAGS is
793 a bit set giving additional information about the member (see the
797 add_global_defn (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
802 /* Try to find out for which classes a function is a friend, and add
803 what we know about it to them. */
805 for (i
= 0; i
< TABLE_SIZE
; ++i
)
806 for (sym
= class_table
[i
]; sym
; sym
= sym
->next
)
807 if (sym
!= global_symbols
&& sym
->friends
)
808 if (find_member (sym
, name
, 0, SC_FRIEND
, hash
))
809 add_member_defn (sym
, name
, regexp
, pos
, hash
, 0,
812 /* Add to global symbols. */
813 add_member_defn (global_symbols
, name
, regexp
, pos
, hash
, var
, sc
, flags
);
817 /* Add information for the global declaration of NAME.
818 REGEXP is a regexp matching the declaration, if non-null. POS is
819 the position in the source where the declaration is found. HASH is
820 a hash code for the parameter list of the member, if it's a
821 function. VAR non-zero means member is a variable or type. SC
822 specifies the type of member (instance member, static, ...). VIS
823 is the member's visibility (public, protected, private). FLAGS is
824 a bit set giving additional information about the member (see the
828 add_global_decl (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
830 /* Add declaration only if not already declared. Header files must
831 be processed before source files for this to have the right effect.
832 I do not want to handle implicit declarations at the moment. */
834 struct member
*found
;
836 m
= found
= find_member (global_symbols
, name
, var
, sc
, hash
);
838 m
= add_member (global_symbols
, name
, var
, sc
, hash
);
840 /* Definition already seen => probably last declaration implicit.
841 Override. This means that declarations must always be added to
842 the symbol table before definitions. */
845 if (!global_symbols
->filename
846 || !FILENAME_EQ (global_symbols
->filename
, filename
))
847 m
->filename
= filename
;
855 info_cls
= global_symbols
;
861 /* Add a symbol for member NAME to class CLS.
862 VAR non-zero means it's a variable. SC specifies the kind of
863 member. HASH is a hash code for the parameter types of a function.
864 Value is a pointer to the member's structure. */
866 static struct member
*
867 add_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
869 struct member
*m
= (struct member
*) xmalloc (sizeof *m
+ strlen (name
));
870 struct member
**list
;
873 unsigned name_hash
= 0;
877 strcpy (m
->name
, name
);
878 m
->param_hash
= hash
;
885 m
->def_regexp
= NULL
;
886 m
->def_filename
= NULL
;
889 assert (cls
!= NULL
);
894 list
= &cls
->friends
;
902 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
906 list
= var
? &cls
->vars
: &cls
->fns
;
910 for (s
= name
; *s
; ++s
)
911 name_hash
= (name_hash
<< 1) ^ *s
;
912 i
= name_hash
% TABLE_SIZE
;
913 m
->anext
= member_table
[i
];
917 /* Keep the member list sorted. It's cheaper to do it here than to
918 sort them in Lisp. */
919 for (prev
= NULL
, p
= *list
;
920 p
&& strcmp (name
, p
->name
) > 0;
921 prev
= p
, p
= p
->next
)
933 /* Given the root R of a class tree, step through all subclasses
934 recursively, marking functions as virtual that are declared virtual
938 mark_virtual (struct sym
*r
)
941 struct member
*m
, *m2
;
943 for (p
= r
->subs
; p
; p
= p
->next
)
945 for (m
= r
->fns
; m
; m
= m
->next
)
946 if (HAS_FLAG (m
->flags
, F_VIRTUAL
))
948 for (m2
= p
->sym
->fns
; m2
; m2
= m2
->next
)
949 if (m
->param_hash
== m2
->param_hash
&& streq (m
->name
, m2
->name
))
950 SET_FLAG (m2
->flags
, F_VIRTUAL
);
953 mark_virtual (p
->sym
);
958 /* For all roots of the class tree, mark functions as virtual that
959 are virtual because of a virtual declaration in a base class. */
962 mark_inherited_virtual (void)
967 for (i
= 0; i
< TABLE_SIZE
; ++i
)
968 for (r
= class_table
[i
]; r
; r
= r
->next
)
969 if (r
->supers
== NULL
)
974 /* Create and return a symbol for a namespace with name NAME. */
977 make_namespace (char *name
, struct sym
*context
)
979 struct sym
*s
= (struct sym
*) xmalloc (sizeof *s
+ strlen (name
));
980 memset (s
, 0, sizeof *s
);
981 strcpy (s
->name
, name
);
982 s
->next
= all_namespaces
;
989 /* Find the symbol for namespace NAME. If not found, retrun NULL */
992 check_namespace (char *name
, struct sym
*context
)
994 struct sym
*p
= NULL
;
996 for (p
= all_namespaces
; p
; p
= p
->next
)
998 if (streq (p
->name
, name
) && (p
->namesp
== context
))
1005 /* Find the symbol for namespace NAME. If not found, add a new symbol
1006 for NAME to all_namespaces. */
1009 find_namespace (char *name
, struct sym
*context
)
1011 struct sym
*p
= check_namespace (name
, context
);
1014 p
= make_namespace (name
, context
);
1020 /* Find namespace alias with name NAME. If not found return NULL. */
1022 static struct link
*
1023 check_namespace_alias (char *name
)
1025 struct link
*p
= NULL
;
1030 for (s
= name
, h
= 0; *s
; ++s
)
1034 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1035 if (streq (name
, al
->name
) && (al
->namesp
== current_namespace
))
1044 /* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */
1047 register_namespace_alias (char *new_name
, struct link
*old_name
)
1053 for (s
= new_name
, h
= 0; *s
; ++s
)
1058 /* Is it already in the table of aliases? */
1059 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1060 if (streq (new_name
, al
->name
) && (al
->namesp
== current_namespace
))
1063 al
= (struct alias
*) xmalloc (sizeof *al
+ strlen (new_name
));
1064 strcpy (al
->name
, new_name
);
1065 al
->next
= namespace_alias_table
[h
];
1066 al
->namesp
= current_namespace
;
1067 al
->aliasee
= old_name
;
1068 namespace_alias_table
[h
] = al
;
1072 /* Enter namespace with name NAME. */
1075 enter_namespace (char *name
)
1077 struct sym
*p
= find_namespace (name
, current_namespace
);
1079 if (namespace_sp
== namespace_stack_size
)
1081 int size
= max (10, 2 * namespace_stack_size
);
1083 = (struct sym
**) xrealloc ((void *)namespace_stack
,
1084 size
* sizeof *namespace_stack
);
1085 namespace_stack_size
= size
;
1088 namespace_stack
[namespace_sp
++] = current_namespace
;
1089 current_namespace
= p
;
1093 /* Leave the current namespace. */
1096 leave_namespace (void)
1098 assert (namespace_sp
> 0);
1099 current_namespace
= namespace_stack
[--namespace_sp
];
1104 /***********************************************************************
1105 Writing the Output File
1106 ***********************************************************************/
1108 /* Write string S to the output file FP in a Lisp-readable form.
1109 If S is null, write out `()'. */
1112 putstr (const char *s
, FILE *fp
)
1129 /* A dynamically allocated buffer for constructing a scope name. */
1132 int scope_buffer_size
;
1133 int scope_buffer_len
;
1136 /* Make sure scope_buffer has enough room to add LEN chars to it. */
1139 ensure_scope_buffer_room (int len
)
1141 if (scope_buffer_len
+ len
>= scope_buffer_size
)
1143 int new_size
= max (2 * scope_buffer_size
, scope_buffer_len
+ len
);
1144 scope_buffer
= (char *) xrealloc (scope_buffer
, new_size
);
1145 scope_buffer_size
= new_size
;
1150 /* Recursively add the scope names of symbol P and the scopes of its
1151 namespaces to scope_buffer. Value is a pointer to the complete
1152 scope name constructed. */
1155 sym_scope_1 (struct sym
*p
)
1160 sym_scope_1 (p
->namesp
);
1164 ensure_scope_buffer_room (3);
1165 strcat (scope_buffer
, "::");
1166 scope_buffer_len
+= 2;
1169 len
= strlen (p
->name
);
1170 ensure_scope_buffer_room (len
+ 1);
1171 strcat (scope_buffer
, p
->name
);
1172 scope_buffer_len
+= len
;
1174 if (HAS_FLAG (p
->flags
, F_TEMPLATE
))
1176 ensure_scope_buffer_room (3);
1177 strcat (scope_buffer
, "<>");
1178 scope_buffer_len
+= 2;
1181 return scope_buffer
;
1185 /* Return the scope of symbol P in printed representation, i.e.
1186 as it would appear in a C*+ source file. */
1189 sym_scope (struct sym
*p
)
1193 scope_buffer_size
= 1024;
1194 scope_buffer
= (char *) xmalloc (scope_buffer_size
);
1197 *scope_buffer
= '\0';
1198 scope_buffer_len
= 0;
1201 sym_scope_1 (p
->namesp
);
1203 return scope_buffer
;
1207 /* Dump the list of members M to file FP. Value is the length of the
1211 dump_members (FILE *fp
, struct member
*m
)
1217 for (n
= 0; m
; m
= m
->next
, ++n
)
1219 fputs (MEMBER_STRUCT
, fp
);
1220 putstr (m
->name
, fp
);
1221 putstr (NULL
, fp
); /* FIXME? scope for globals */
1222 fprintf (fp
, "%u ", (unsigned) m
->flags
);
1223 putstr (m
->filename
, fp
);
1224 putstr (m
->regexp
, fp
);
1225 fprintf (fp
, "%u ", (unsigned) m
->pos
);
1226 fprintf (fp
, "%u ", (unsigned) m
->vis
);
1228 putstr (m
->def_filename
, fp
);
1229 putstr (m
->def_regexp
, fp
);
1230 fprintf (fp
, "%u", (unsigned) m
->def_pos
);
1241 /* Dump class ROOT to stream FP. */
1244 dump_sym (FILE *fp
, struct sym
*root
)
1246 fputs (CLASS_STRUCT
, fp
);
1247 putstr (root
->name
, fp
);
1249 /* Print scope, if any. */
1251 putstr (sym_scope (root
), fp
);
1256 fprintf (fp
, "%u", root
->flags
);
1257 putstr (root
->filename
, fp
);
1258 putstr (root
->regexp
, fp
);
1259 fprintf (fp
, "%u", (unsigned) root
->pos
);
1260 putstr (root
->sfilename
, fp
);
1266 /* Dump class ROOT and its subclasses to file FP. Value is the
1267 number of classes written. */
1270 dump_tree (FILE *fp
, struct sym
*root
)
1275 dump_sym (fp
, root
);
1285 for (lk
= root
->subs
; lk
; lk
= lk
->next
)
1287 fputs (TREE_STRUCT
, fp
);
1288 n
+= dump_tree (fp
, lk
->sym
);
1294 dump_members (fp
, root
->vars
);
1295 n
+= dump_members (fp
, root
->fns
);
1296 dump_members (fp
, root
->static_vars
);
1297 n
+= dump_members (fp
, root
->static_fns
);
1298 n
+= dump_members (fp
, root
->friends
);
1299 dump_members (fp
, root
->types
);
1314 /* Dump the entire class tree to file FP. */
1317 dump_roots (FILE *fp
)
1322 /* Output file header containing version string, command line
1326 fputs (TREE_HEADER_STRUCT
, fp
);
1327 putstr (EBROWSE_FILE_VERSION
, fp
);
1340 /* Mark functions as virtual that are so because of functions
1341 declared virtual in base classes. */
1342 mark_inherited_virtual ();
1344 /* Dump the roots of the graph. */
1345 for (i
= 0; i
< TABLE_SIZE
; ++i
)
1346 for (r
= class_table
[i
]; r
; r
= r
->next
)
1349 fputs (TREE_STRUCT
, fp
);
1350 n
+= dump_tree (fp
, r
);
1360 /***********************************************************************
1362 ***********************************************************************/
1365 #define INCREMENT_LINENO \
1367 if (f_very_verbose) \
1370 printf ("%d:\n", yyline); \
1376 #define INCREMENT_LINENO ++yyline
1379 /* Define two macros for accessing the input buffer (current input
1380 file). GET(C) sets C to the next input character and advances the
1381 input pointer. UNGET retracts the input pointer. */
1383 #define GET(C) ((C) = *in++)
1384 #define UNGET() (--in)
1387 /* Process a preprocessor line. Value is the next character from the
1388 input buffer not consumed. */
1391 process_pp_line (void)
1393 int in_comment
= 0, in_string
= 0;
1397 /* Skip over white space. The `#' has been consumed already. */
1398 while (WHITEP (GET (c
)))
1401 /* Read the preprocessor command (if any). */
1408 /* Is it a `define'? */
1411 if (*yytext
&& streq (yytext
, "define"))
1426 char *regexp
= matching_regexp ();
1427 int pos
= BUFFER_POS ();
1428 add_define (yytext
, regexp
, pos
);
1432 while (c
&& (c
!= '\n' || in_comment
|| in_string
))
1436 else if (c
== '/' && !in_comment
)
1441 else if (c
== '*' && in_comment
)
1447 in_string
= !in_string
;
1459 /* Value is the next token from the input buffer. */
1470 while (WHITEP (GET (c
)))
1492 /* String and character constants. */
1495 while (GET (c
) && c
!= end_char
)
1500 /* Escape sequences. */
1503 if (end_char
== '\'')
1504 yyerror ("EOF in character constant", NULL
);
1506 yyerror ("EOF in string constant", NULL
);
1524 /* Hexadecimal escape sequence. */
1526 for (i
= 0; i
< 2; ++i
)
1530 if (c
>= '0' && c
<= '7')
1532 else if (c
>= 'a' && c
<= 'f')
1534 else if (c
>= 'A' && c
<= 'F')
1547 /* Octal escape sequence. */
1549 for (i
= 0; i
< 3; ++i
)
1553 if (c
>= '0' && c
<= '7')
1570 if (end_char
== '\'')
1571 yyerror ("newline in character constant", NULL
);
1573 yyerror ("newline in string constant", NULL
);
1583 return end_char
== '\'' ? CCHAR
: CSTRING
;
1585 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1586 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1587 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1588 case 'v': case 'w': case 'x': case 'y': case 'z':
1589 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1590 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1591 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1592 case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_':
1594 /* Identifier and keywords. */
1601 while (IDENTP (GET (*p
)))
1603 hash
= (hash
<< 1) ^ *p
++;
1604 if (p
== yytext_end
- 1)
1606 int size
= yytext_end
- yytext
;
1607 yytext
= (char *) xrealloc (yytext
, 2 * size
);
1608 yytext_end
= yytext
+ 2 * size
;
1609 p
= yytext
+ size
- 1;
1616 for (k
= keyword_table
[hash
% KEYWORD_TABLE_SIZE
]; k
; k
= k
->next
)
1617 if (streq (k
->name
, yytext
))
1624 /* C and C++ comments, '/' and '/='. */
1652 while (GET (c
) && c
!= '\n')
1654 /* Don't try to read past the end of the input buffer if
1655 the file ends in a C++ comment without a newline. */
1732 yyerror ("invalid token '..' ('...' assumed)", NULL
);
1736 else if (!DIGITP (c
))
1790 c
= process_pp_line ();
1795 case '(': case ')': case '[': case ']': case '{': case '}':
1796 case ';': case ',': case '?': case '~':
1802 if (GET (c
) == 'x' || c
== 'X')
1807 yyival
= yyival
* 16 + c
- '0';
1808 else if (c
>= 'a' && c
<= 'f')
1809 yyival
= yyival
* 16 + c
- 'a' + 10;
1810 else if (c
>= 'A' && c
<= 'F')
1811 yyival
= yyival
* 16 + c
- 'A' + 10;
1821 while (c
>= '0' && c
<= '7')
1823 yyival
= (yyival
<< 3) + c
- '0';
1828 /* Integer suffixes. */
1834 case '1': case '2': case '3': case '4': case '5': case '6':
1835 case '7': case '8': case '9':
1836 /* Integer or floating constant, part before '.'. */
1839 while (GET (c
) && DIGITP (c
))
1840 yyival
= 10 * yyival
+ c
- '0';
1846 /* Digits following '.'. */
1850 /* Optional exponent. */
1851 if (c
== 'E' || c
== 'e')
1853 if (GET (c
) == '-' || c
== '+')
1860 /* Optional type suffixes. */
1873 /* Actually local to matching_regexp. These variables must be in
1874 global scope for the case that `static' get's defined away. */
1876 static char *matching_regexp_buffer
, *matching_regexp_end_buf
;
1879 /* Value is the string from the start of the line to the current
1880 position in the input buffer, or maybe a bit more if that string is
1881 shorter than min_regexp. */
1884 matching_regexp (void)
1893 if (matching_regexp_buffer
== NULL
)
1895 matching_regexp_buffer
= (char *) xmalloc (max_regexp
);
1896 matching_regexp_end_buf
= &matching_regexp_buffer
[max_regexp
] - 1;
1899 /* Scan back to previous newline of buffer start. */
1900 for (p
= in
- 1; p
> inbuffer
&& *p
!= '\n'; --p
)
1905 while (in
- p
< min_regexp
&& p
> inbuffer
)
1907 /* Line probably not significant enough */
1908 for (--p
; p
> inbuffer
&& *p
!= '\n'; --p
)
1915 /* Copy from end to make sure significant portions are included.
1916 This implies that in the browser a regular expressing of the form
1917 `^.*{regexp}' has to be used. */
1918 for (s
= matching_regexp_end_buf
- 1, t
= in
;
1919 s
> matching_regexp_buffer
&& t
> p
;)
1923 if (*s
== '"' || *s
== '\\')
1927 *(matching_regexp_end_buf
- 1) = '\0';
1932 /* Return a printable representation of token T. */
1935 token_string (int t
)
1941 case CSTRING
: return "string constant";
1942 case CCHAR
: return "char constant";
1943 case CINT
: return "int constant";
1944 case CFLOAT
: return "floating constant";
1945 case ELLIPSIS
: return "...";
1946 case LSHIFTASGN
: return "<<=";
1947 case RSHIFTASGN
: return ">>=";
1948 case ARROWSTAR
: return "->*";
1949 case IDENT
: return "identifier";
1950 case DIVASGN
: return "/=";
1951 case INC
: return "++";
1952 case ADDASGN
: return "+=";
1953 case DEC
: return "--";
1954 case ARROW
: return "->";
1955 case SUBASGN
: return "-=";
1956 case MULASGN
: return "*=";
1957 case MODASGN
: return "%=";
1958 case LOR
: return "||";
1959 case ORASGN
: return "|=";
1960 case LAND
: return "&&";
1961 case ANDASGN
: return "&=";
1962 case XORASGN
: return "^=";
1963 case POINTSTAR
: return ".*";
1964 case DCOLON
: return "::";
1965 case EQ
: return "==";
1966 case NE
: return "!=";
1967 case LE
: return "<=";
1968 case LSHIFT
: return "<<";
1969 case GE
: return ">=";
1970 case RSHIFT
: return ">>";
1971 case ASM
: return "asm";
1972 case AUTO
: return "auto";
1973 case BREAK
: return "break";
1974 case CASE
: return "case";
1975 case CATCH
: return "catch";
1976 case CHAR
: return "char";
1977 case CLASS
: return "class";
1978 case CONST
: return "const";
1979 case CONTINUE
: return "continue";
1980 case DEFAULT
: return "default";
1981 case DELETE
: return "delete";
1982 case DO
: return "do";
1983 case DOUBLE
: return "double";
1984 case ELSE
: return "else";
1985 case ENUM
: return "enum";
1986 case EXTERN
: return "extern";
1987 case FLOAT
: return "float";
1988 case FOR
: return "for";
1989 case FRIEND
: return "friend";
1990 case GOTO
: return "goto";
1991 case IF
: return "if";
1992 case T_INLINE
: return "inline";
1993 case INT
: return "int";
1994 case LONG
: return "long";
1995 case NEW
: return "new";
1996 case OPERATOR
: return "operator";
1997 case PRIVATE
: return "private";
1998 case PROTECTED
: return "protected";
1999 case PUBLIC
: return "public";
2000 case REGISTER
: return "register";
2001 case RETURN
: return "return";
2002 case SHORT
: return "short";
2003 case SIGNED
: return "signed";
2004 case SIZEOF
: return "sizeof";
2005 case STATIC
: return "static";
2006 case STRUCT
: return "struct";
2007 case SWITCH
: return "switch";
2008 case TEMPLATE
: return "template";
2009 case THIS
: return "this";
2010 case THROW
: return "throw";
2011 case TRY
: return "try";
2012 case TYPEDEF
: return "typedef";
2013 case UNION
: return "union";
2014 case UNSIGNED
: return "unsigned";
2015 case VIRTUAL
: return "virtual";
2016 case VOID
: return "void";
2017 case VOLATILE
: return "volatile";
2018 case WHILE
: return "while";
2019 case MUTABLE
: return "mutable";
2020 case BOOL
: return "bool";
2021 case TRUE
: return "true";
2022 case FALSE
: return "false";
2023 case SIGNATURE
: return "signature";
2024 case NAMESPACE
: return "namespace";
2025 case EXPLICIT
: return "explicit";
2026 case TYPENAME
: return "typename";
2027 case CONST_CAST
: return "const_cast";
2028 case DYNAMIC_CAST
: return "dynamic_cast";
2029 case REINTERPRET_CAST
: return "reinterpret_cast";
2030 case STATIC_CAST
: return "static_cast";
2031 case TYPEID
: return "typeid";
2032 case USING
: return "using";
2033 case WCHAR
: return "wchar_t";
2034 case YYEOF
: return "EOF";
2049 /* Reinitialize the scanner for a new input file. */
2052 re_init_scanner (void)
2060 yytext
= (char *) xmalloc (size
* sizeof *yytext
);
2061 yytext_end
= yytext
+ size
;
2066 /* Insert a keyword NAME with token value TKV into the keyword hash
2070 insert_keyword (const char *name
, int tkv
)
2074 struct kw
*k
= (struct kw
*) xmalloc (sizeof *k
);
2076 for (s
= name
; *s
; ++s
)
2079 h
%= KEYWORD_TABLE_SIZE
;
2082 k
->next
= keyword_table
[h
];
2083 keyword_table
[h
] = k
;
2087 /* Initialize the scanner for the first file. This sets up the
2088 character class vectors and fills the keyword hash table. */
2095 /* Allocate the input buffer */
2096 inbuffer_size
= READ_CHUNK_SIZE
+ 1;
2097 inbuffer
= in
= (char *) xmalloc (inbuffer_size
);
2100 /* Set up character class vectors. */
2101 for (i
= 0; i
< sizeof is_ident
; ++i
)
2103 if (i
== '_' || isalnum (i
))
2106 if (i
>= '0' && i
<= '9')
2109 if (i
== ' ' || i
== '\t' || i
== '\f' || i
== '\v')
2113 /* Fill keyword hash table. */
2114 insert_keyword ("and", LAND
);
2115 insert_keyword ("and_eq", ANDASGN
);
2116 insert_keyword ("asm", ASM
);
2117 insert_keyword ("auto", AUTO
);
2118 insert_keyword ("bitand", '&');
2119 insert_keyword ("bitor", '|');
2120 insert_keyword ("bool", BOOL
);
2121 insert_keyword ("break", BREAK
);
2122 insert_keyword ("case", CASE
);
2123 insert_keyword ("catch", CATCH
);
2124 insert_keyword ("char", CHAR
);
2125 insert_keyword ("class", CLASS
);
2126 insert_keyword ("compl", '~');
2127 insert_keyword ("const", CONST
);
2128 insert_keyword ("const_cast", CONST_CAST
);
2129 insert_keyword ("continue", CONTINUE
);
2130 insert_keyword ("default", DEFAULT
);
2131 insert_keyword ("delete", DELETE
);
2132 insert_keyword ("do", DO
);
2133 insert_keyword ("double", DOUBLE
);
2134 insert_keyword ("dynamic_cast", DYNAMIC_CAST
);
2135 insert_keyword ("else", ELSE
);
2136 insert_keyword ("enum", ENUM
);
2137 insert_keyword ("explicit", EXPLICIT
);
2138 insert_keyword ("extern", EXTERN
);
2139 insert_keyword ("false", FALSE
);
2140 insert_keyword ("float", FLOAT
);
2141 insert_keyword ("for", FOR
);
2142 insert_keyword ("friend", FRIEND
);
2143 insert_keyword ("goto", GOTO
);
2144 insert_keyword ("if", IF
);
2145 insert_keyword ("inline", T_INLINE
);
2146 insert_keyword ("int", INT
);
2147 insert_keyword ("long", LONG
);
2148 insert_keyword ("mutable", MUTABLE
);
2149 insert_keyword ("namespace", NAMESPACE
);
2150 insert_keyword ("new", NEW
);
2151 insert_keyword ("not", '!');
2152 insert_keyword ("not_eq", NE
);
2153 insert_keyword ("operator", OPERATOR
);
2154 insert_keyword ("or", LOR
);
2155 insert_keyword ("or_eq", ORASGN
);
2156 insert_keyword ("private", PRIVATE
);
2157 insert_keyword ("protected", PROTECTED
);
2158 insert_keyword ("public", PUBLIC
);
2159 insert_keyword ("register", REGISTER
);
2160 insert_keyword ("reinterpret_cast", REINTERPRET_CAST
);
2161 insert_keyword ("return", RETURN
);
2162 insert_keyword ("short", SHORT
);
2163 insert_keyword ("signed", SIGNED
);
2164 insert_keyword ("sizeof", SIZEOF
);
2165 insert_keyword ("static", STATIC
);
2166 insert_keyword ("static_cast", STATIC_CAST
);
2167 insert_keyword ("struct", STRUCT
);
2168 insert_keyword ("switch", SWITCH
);
2169 insert_keyword ("template", TEMPLATE
);
2170 insert_keyword ("this", THIS
);
2171 insert_keyword ("throw", THROW
);
2172 insert_keyword ("true", TRUE
);
2173 insert_keyword ("try", TRY
);
2174 insert_keyword ("typedef", TYPEDEF
);
2175 insert_keyword ("typeid", TYPEID
);
2176 insert_keyword ("typename", TYPENAME
);
2177 insert_keyword ("union", UNION
);
2178 insert_keyword ("unsigned", UNSIGNED
);
2179 insert_keyword ("using", USING
);
2180 insert_keyword ("virtual", VIRTUAL
);
2181 insert_keyword ("void", VOID
);
2182 insert_keyword ("volatile", VOLATILE
);
2183 insert_keyword ("wchar_t", WCHAR
);
2184 insert_keyword ("while", WHILE
);
2185 insert_keyword ("xor", '^');
2186 insert_keyword ("xor_eq", XORASGN
);
2191 /***********************************************************************
2193 ***********************************************************************/
2195 /* Match the current lookahead token and set it to the next token. */
2197 #define MATCH() (tk = yylex ())
2199 /* Return the lookahead token. If current lookahead token is cleared,
2200 read a new token. */
2202 #define LA1 (tk == -1 ? (tk = yylex ()) : tk)
2204 /* Is the current lookahead equal to the token T? */
2206 #define LOOKING_AT(T) (tk == (T))
2208 /* Is the current lookahead one of T1 or T2? */
2210 #define LOOKING_AT2(T1, T2) (tk == (T1) || tk == (T2))
2212 /* Is the current lookahead one of T1, T2 or T3? */
2214 #define LOOKING_AT3(T1, T2, T3) (tk == (T1) || tk == (T2) || tk == (T3))
2216 /* Is the current lookahead one of T1...T4? */
2218 #define LOOKING_AT4(T1, T2, T3, T4) \
2219 (tk == (T1) || tk == (T2) || tk == (T3) || tk == (T4))
2221 /* Match token T if current lookahead is T. */
2223 #define MATCH_IF(T) if (LOOKING_AT (T)) MATCH (); else ((void) 0)
2225 /* Skip to matching token if current token is T. */
2227 #define SKIP_MATCHING_IF(T) \
2228 if (LOOKING_AT (T)) skip_matching (); else ((void) 0)
2231 /* Skip forward until a given token TOKEN or YYEOF is seen and return
2232 the current lookahead token after skipping. */
2237 while (!LOOKING_AT2 (YYEOF
, token
))
2242 /* Skip over pairs of tokens (parentheses, square brackets,
2243 angle brackets, curly brackets) matching the current lookahead. */
2246 skip_matching (void)
2274 if (LOOKING_AT (open
))
2276 else if (LOOKING_AT (close
))
2278 else if (LOOKING_AT (YYEOF
))
2289 skip_initializer (void)
2313 /* Build qualified namespace alias (A::B::c) and return it. */
2315 static struct link
*
2316 match_qualified_namespace_alias (void)
2318 struct link
*head
= NULL
;
2319 struct link
*cur
= NULL
;
2320 struct link
*tmp
= NULL
;
2328 tmp
= (struct link
*) xmalloc (sizeof *cur
);
2329 tmp
->sym
= find_namespace (yytext
, cur
? cur
->sym
: NULL
);
2333 cur
= cur
->next
= tmp
;
2350 /* Re-initialize the parser by resetting the lookahead token. */
2353 re_init_parser (void)
2359 /* Parse a parameter list, including the const-specifier,
2360 pure-specifier, and throw-list that may follow a parameter list.
2361 Return in FLAGS what was seen following the parameter list.
2362 Returns a hash code for the parameter types. This value is used to
2363 distinguish between overloaded functions. */
2366 parm_list (int *flags
)
2371 while (!LOOKING_AT2 (YYEOF
, ')'))
2375 /* Skip over grouping parens or parameter lists in parameter
2381 /* Next parameter. */
2387 /* Ignore the scope part of types, if any. This is because
2388 some types need scopes when defined outside of a class body,
2389 and don't need them inside the class body. This means that
2390 we have to look for the last IDENT in a sequence of
2391 IDENT::IDENT::... */
2396 unsigned ident_type_hash
= 0;
2398 parse_qualified_param_ident_or_type (&last_id
);
2401 /* LAST_ID null means something like `X::*'. */
2402 for (; *last_id
; ++last_id
)
2403 ident_type_hash
= (ident_type_hash
<< 1) ^ *last_id
;
2404 hash
= (hash
<< 1) ^ ident_type_hash
;
2413 /* This distinction is made to make `func (void)' equivalent
2417 if (!LOOKING_AT (')'))
2418 hash
= (hash
<< 1) ^ VOID
;
2421 case BOOL
: case CHAR
: case CLASS
: case CONST
:
2422 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2423 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2424 case UNION
: case UNSIGNED
: case VOLATILE
: case WCHAR
:
2427 hash
= (hash
<< 1) ^ LA1
;
2431 case '*': case '&': case '[': case ']':
2432 hash
= (hash
<< 1) ^ LA1
;
2442 if (LOOKING_AT (')'))
2446 if (LOOKING_AT (CONST
))
2448 /* We can overload the same function on `const' */
2449 hash
= (hash
<< 1) ^ CONST
;
2450 SET_FLAG (*flags
, F_CONST
);
2454 if (LOOKING_AT (THROW
))
2457 SKIP_MATCHING_IF ('(');
2458 SET_FLAG (*flags
, F_THROW
);
2461 if (LOOKING_AT ('='))
2464 if (LOOKING_AT (CINT
) && yyival
== 0)
2467 SET_FLAG (*flags
, F_PURE
);
2476 /* Print position info to stdout. */
2481 if (info_position
>= 0 && BUFFER_POS () <= info_position
)
2483 printf ("(\"%s\" \"%s\" \"%s\" %d)\n",
2484 info_cls
->name
, sym_scope (info_cls
),
2485 info_member
->name
, info_where
);
2489 /* Parse a member declaration within the class body of CLS. VIS is
2490 the access specifier for the member (private, protected,
2494 member (struct sym
*cls
, int vis
)
2498 char *regexp
= NULL
;
2509 while (!LOOKING_AT4 (';', '{', '}', YYEOF
))
2517 /* A function or class may follow. */
2520 SET_FLAG (flags
, F_TEMPLATE
);
2521 /* Skip over template argument list */
2522 SKIP_MATCHING_IF ('<');
2526 SET_FLAG (flags
, F_EXPLICIT
);
2530 SET_FLAG (flags
, F_MUTABLE
);
2534 SET_FLAG (flags
, F_INLINE
);
2538 SET_FLAG (flags
, F_VIRTUAL
);
2567 /* Remember IDENTS seen so far. Among these will be the member
2569 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
2573 strcpy (id
+ 1, yytext
);
2576 strcpy (id
, yytext
);
2582 char *s
= operator_name (&sc
);
2583 id
= (char *) xrealloc (id
, strlen (s
) + 1);
2589 /* Most probably the beginning of a parameter list. */
2595 if (!(is_constructor
= streq (id
, cls
->name
)))
2596 regexp
= matching_regexp ();
2601 pos
= BUFFER_POS ();
2602 hash
= parm_list (&flags
);
2605 regexp
= matching_regexp ();
2607 if (id
&& cls
!= NULL
)
2608 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, flags
);
2610 while (!LOOKING_AT3 (';', '{', YYEOF
))
2613 if (LOOKING_AT ('{') && id
&& cls
)
2614 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0, sc
, flags
);
2621 case STRUCT
: case UNION
: case CLASS
:
2628 /* More than one ident here to allow for MS-DOS specialties
2629 like `_export class' etc. The last IDENT seen counts
2630 as the class name. */
2631 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
2633 if (LOOKING_AT (IDENT
))
2638 if (LOOKING_AT2 (':', '{'))
2639 class_definition (anonymous
? NULL
: cls
, class_tag
, flags
, 1);
2644 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
2645 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
2646 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
2655 if (LOOKING_AT (';'))
2657 /* The end of a member variable, a friend declaration or an access
2658 declaration. We don't want to add friend classes as members. */
2659 if (id
&& sc
!= SC_FRIEND
&& cls
)
2661 regexp
= matching_regexp ();
2662 pos
= BUFFER_POS ();
2666 if (type_seen
|| !paren_seen
)
2667 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2669 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, 0);
2676 else if (LOOKING_AT ('{'))
2679 if (sc
== SC_TYPE
&& id
&& cls
)
2681 regexp
= matching_regexp ();
2682 pos
= BUFFER_POS ();
2686 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2687 add_member_defn (cls
, id
, regexp
, pos
, 0, 1, sc
, 0);
2699 /* Parse the body of class CLS. TAG is the tag of the class (struct,
2703 class_body (struct sym
*cls
, int tag
)
2705 int vis
= tag
== CLASS
? PRIVATE
: PUBLIC
;
2708 while (!LOOKING_AT2 (YYEOF
, '}'))
2712 case PRIVATE
: case PROTECTED
: case PUBLIC
:
2716 if (LOOKING_AT (':'))
2723 /* Probably conditional compilation for inheritance list.
2724 We don't known whether there comes more of this.
2725 This is only a crude fix that works most of the time. */
2730 while (LOOKING_AT2 (IDENT
, ',')
2731 || LOOKING_AT3 (PUBLIC
, PROTECTED
, PRIVATE
));
2740 /* Try to synchronize */
2741 case CHAR
: case CLASS
: case CONST
:
2742 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2743 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2744 case UNION
: case UNSIGNED
: case VOID
: case VOLATILE
:
2745 case TYPEDEF
: case STATIC
: case T_INLINE
: case FRIEND
:
2746 case VIRTUAL
: case TEMPLATE
: case IDENT
: case '~':
2747 case BOOL
: case WCHAR
: case EXPLICIT
: case MUTABLE
:
2759 /* Parse a qualified identifier. Current lookahead is IDENT. A
2760 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
2761 symbol for that class. */
2764 parse_classname (void)
2766 struct sym
*last_class
= NULL
;
2768 while (LOOKING_AT (IDENT
))
2770 last_class
= add_sym (yytext
, last_class
);
2773 if (LOOKING_AT ('<'))
2776 SET_FLAG (last_class
->flags
, F_TEMPLATE
);
2779 if (!LOOKING_AT (DCOLON
))
2789 /* Parse an operator name. Add the `static' flag to *SC if an
2790 implicitly static operator has been parsed. Value is a pointer to
2791 a static buffer holding the constructed operator name string. */
2794 operator_name (int *sc
)
2796 static int id_size
= 0;
2797 static char *id
= NULL
;
2803 if (LOOKING_AT2 (NEW
, DELETE
))
2805 /* `new' and `delete' are implicitly static. */
2806 if (*sc
!= SC_FRIEND
)
2809 s
= token_string (LA1
);
2812 len
= strlen (s
) + 10;
2815 int new_size
= max (len
, 2 * id_size
);
2816 id
= (char *) xrealloc (id
, new_size
);
2821 /* Vector new or delete? */
2822 if (LOOKING_AT ('['))
2827 if (LOOKING_AT (']'))
2836 int tokens_matched
= 0;
2841 int new_size
= max (len
, 2 * id_size
);
2842 id
= (char *) xrealloc (id
, new_size
);
2845 strcpy (id
, "operator");
2847 /* Beware access declarations of the form "X::f;" Beware of
2848 `operator () ()'. Yet another difficulty is found in
2849 GCC 2.95's STL: `operator == __STL_NULL_TMPL_ARGS (...'. */
2850 while (!(LOOKING_AT ('(') && tokens_matched
)
2851 && !LOOKING_AT2 (';', YYEOF
))
2853 s
= token_string (LA1
);
2854 len
+= strlen (s
) + 2;
2857 int new_size
= max (len
, 2 * id_size
);
2858 id
= (char *) xrealloc (id
, new_size
);
2862 if (*s
!= ')' && *s
!= ']')
2867 /* If this is a simple operator like `+', stop now. */
2868 if (!isalpha ((unsigned char) *s
) && *s
!= '(' && *s
!= '[')
2879 /* This one consumes the last IDENT of a qualified member name like
2880 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2881 symbol structure for the ident. */
2884 parse_qualified_ident_or_type (char **last_id
)
2886 struct sym
*cls
= NULL
;
2891 while (LOOKING_AT (IDENT
))
2893 int len
= strlen (yytext
) + 1;
2896 id
= (char *) xrealloc (id
, len
);
2899 strcpy (id
, yytext
);
2903 SKIP_MATCHING_IF ('<');
2905 if (LOOKING_AT (DCOLON
))
2907 struct sym
*pcn
= NULL
;
2908 struct link
*pna
= check_namespace_alias (id
);
2913 enter_namespace (pna
->sym
->name
);
2919 else if ((pcn
= check_namespace (id
, current_namespace
)))
2921 enter_namespace (pcn
->name
);
2925 cls
= add_sym (id
, cls
);
2944 /* This one consumes the last IDENT of a qualified member name like
2945 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2946 symbol structure for the ident. */
2949 parse_qualified_param_ident_or_type (char **last_id
)
2951 struct sym
*cls
= NULL
;
2952 static char *id
= NULL
;
2953 static int id_size
= 0;
2955 while (LOOKING_AT (IDENT
))
2957 int len
= strlen (yytext
) + 1;
2960 id
= (char *) xrealloc (id
, len
);
2963 strcpy (id
, yytext
);
2967 SKIP_MATCHING_IF ('<');
2969 if (LOOKING_AT (DCOLON
))
2971 cls
= add_sym (id
, cls
);
2981 /* Parse a class definition.
2983 CONTAINING is the class containing the class being parsed or null.
2984 This may also be null if NESTED != 0 if the containing class is
2985 anonymous. TAG is the tag of the class (struct, union, class).
2986 NESTED is non-zero if we are parsing a nested class.
2988 Current lookahead is the class name. */
2991 class_definition (struct sym
*containing
, int tag
, int flags
, int nested
)
2993 struct sym
*current
;
2994 struct sym
*base_class
;
2996 /* Set CURRENT to null if no entry has to be made for the class
2997 parsed. This is the case for certain command line flag
2999 if ((tag
!= CLASS
&& !f_structs
) || (nested
&& !f_nested_classes
))
3003 current
= add_sym (yytext
, containing
);
3004 current
->pos
= BUFFER_POS ();
3005 current
->regexp
= matching_regexp ();
3006 current
->filename
= filename
;
3007 current
->flags
= flags
;
3010 /* If at ':', base class list follows. */
3011 if (LOOKING_AT (':'))
3020 case VIRTUAL
: case PUBLIC
: case PROTECTED
: case PRIVATE
:
3025 base_class
= parse_classname ();
3026 if (base_class
&& current
&& base_class
!= current
)
3027 add_link (base_class
, current
);
3030 /* The `,' between base classes or the end of the base
3031 class list. Add the previously found base class.
3032 It's done this way to skip over sequences of
3033 `A::B::C' until we reach the end.
3035 FIXME: it is now possible to handle `class X : public B::X'
3036 because we have enough information. */
3042 /* A syntax error, possibly due to preprocessor constructs
3048 class A : private B.
3050 MATCH until we see something like `;' or `{'. */
3051 while (!LOOKING_AT3 (';', YYEOF
, '{'))
3062 /* Parse the class body if there is one. */
3063 if (LOOKING_AT ('{'))
3065 if (tag
!= CLASS
&& !f_structs
)
3070 class_body (current
, tag
);
3072 if (LOOKING_AT ('}'))
3075 if (LOOKING_AT (';') && !nested
)
3082 /* Add to class *CLS information for the declaration of variable or
3083 type *ID. If *CLS is null, this means a global declaration. SC is
3084 the storage class of *ID. FLAGS is a bit set giving additional
3085 information about the member (see the F_* defines). */
3088 add_declarator (struct sym
**cls
, char **id
, int flags
, int sc
)
3090 if (LOOKING_AT2 (';', ','))
3092 /* The end of a member variable or of an access declaration
3093 `X::f'. To distinguish between them we have to know whether
3094 type information has been seen. */
3097 char *regexp
= matching_regexp ();
3098 int pos
= BUFFER_POS ();
3101 add_member_defn (*cls
, *id
, regexp
, pos
, 0, 1, SC_UNKNOWN
, flags
);
3103 add_global_defn (*id
, regexp
, pos
, 0, 1, sc
, flags
);
3109 else if (LOOKING_AT ('{'))
3111 if (sc
== SC_TYPE
&& *id
)
3113 /* A named enumeration. */
3114 char *regexp
= matching_regexp ();
3115 int pos
= BUFFER_POS ();
3116 add_global_defn (*id
, regexp
, pos
, 0, 1, sc
, flags
);
3128 /* Parse a declaration. */
3131 declaration (int flags
)
3134 struct sym
*cls
= NULL
;
3135 char *regexp
= NULL
;
3141 while (!LOOKING_AT3 (';', '{', YYEOF
))
3164 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
3165 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
3166 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
3170 case CLASS
: case STRUCT
: case UNION
:
3171 /* This is for the case `STARTWRAP class X : ...' or
3172 `declare (X, Y)\n class A : ...'. */
3180 /* Assumed to be the start of an initialization in this
3182 skip_initializer ();
3186 add_declarator (&cls
, &id
, flags
, sc
);
3191 char *s
= operator_name (&sc
);
3192 id
= (char *) xrealloc (id
, strlen (s
) + 1);
3198 SET_FLAG (flags
, F_INLINE
);
3204 if (LOOKING_AT (IDENT
))
3206 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
3208 strcpy (id
+ 1, yytext
);
3214 cls
= parse_qualified_ident_or_type (&id
);
3218 /* Most probably the beginning of a parameter list. */
3225 if (!(is_constructor
= streq (id
, cls
->name
)))
3226 regexp
= matching_regexp ();
3231 pos
= BUFFER_POS ();
3232 hash
= parm_list (&flags
);
3235 regexp
= matching_regexp ();
3238 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0,
3243 /* This may be a C functions, but also a macro
3244 call of the form `declare (A, B)' --- such macros
3245 can be found in some class libraries. */
3250 regexp
= matching_regexp ();
3251 pos
= BUFFER_POS ();
3252 hash
= parm_list (&flags
);
3253 add_global_decl (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3256 /* This is for the case that the function really is
3257 a macro with no `;' following it. If a CLASS directly
3258 follows, we would miss it otherwise. */
3259 if (LOOKING_AT3 (CLASS
, STRUCT
, UNION
))
3263 while (!LOOKING_AT3 (';', '{', YYEOF
))
3266 if (!cls
&& id
&& LOOKING_AT ('{'))
3267 add_global_defn (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3275 add_declarator (&cls
, &id
, flags
, sc
);
3279 /* Parse a list of top-level declarations/definitions. START_FLAGS
3280 says in which context we are parsing. If it is F_EXTERNC, we are
3281 parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0
3285 globals (int start_flags
)
3289 int flags
= start_flags
;
3301 if (LOOKING_AT (IDENT
))
3303 char *namespace_name
= xstrdup (yytext
);
3306 if (LOOKING_AT ('='))
3308 struct link
*qna
= match_qualified_namespace_alias ();
3310 register_namespace_alias (namespace_name
, qna
);
3312 if (skip_to (';') == ';')
3315 else if (LOOKING_AT ('{'))
3318 enter_namespace (namespace_name
);
3324 free (namespace_name
);
3331 if (LOOKING_AT (CSTRING
) && *string_start
== 'C'
3332 && *(string_start
+ 1) == '"')
3334 /* This is `extern "C"'. */
3337 if (LOOKING_AT ('{'))
3340 globals (F_EXTERNC
);
3344 SET_FLAG (flags
, F_EXTERNC
);
3350 SKIP_MATCHING_IF ('<');
3351 SET_FLAG (flags
, F_TEMPLATE
);
3354 case CLASS
: case STRUCT
: case UNION
:
3359 /* More than one ident here to allow for MS-DOS and OS/2
3360 specialties like `far', `_Export' etc. Some C++ libs
3361 have constructs like `_OS_DLLIMPORT(_OS_CLIENT)' in front
3362 of the class name. */
3363 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
3365 if (LOOKING_AT (IDENT
))
3370 /* Don't add anonymous unions. */
3371 if (LOOKING_AT2 (':', '{') && !anonymous
)
3372 class_definition (NULL
, class_tk
, flags
, 0);
3375 if (skip_to (';') == ';')
3379 flags
= start_flags
;
3389 declaration (flags
);
3390 flags
= start_flags
;
3395 yyerror ("parse error", NULL
);
3400 /* Parse the current input file. */
3405 while (globals (0) == 0)
3411 /***********************************************************************
3413 ***********************************************************************/
3415 /* Add the list of paths PATH_LIST to the current search path for
3419 add_search_path (char *path_list
)
3423 char *start
= path_list
;
3424 struct search_path
*p
;
3426 while (*path_list
&& *path_list
!= PATH_LIST_SEPARATOR
)
3429 p
= (struct search_path
*) xmalloc (sizeof *p
);
3430 p
->path
= (char *) xmalloc (path_list
- start
+ 1);
3431 memcpy (p
->path
, start
, path_list
- start
);
3432 p
->path
[path_list
- start
] = '\0';
3435 if (search_path_tail
)
3437 search_path_tail
->next
= p
;
3438 search_path_tail
= p
;
3441 search_path
= search_path_tail
= p
;
3443 while (*path_list
== PATH_LIST_SEPARATOR
)
3449 /* Open FILE and return a file handle for it, or -1 if FILE cannot be
3450 opened. Try to find FILE in search_path first, then try the
3451 unchanged file name. */
3454 open_file (char *file
)
3457 static char *buffer
;
3458 static int buffer_size
;
3459 struct search_path
*path
;
3460 int flen
= strlen (file
) + 1; /* +1 for the slash */
3462 filename
= xstrdup (file
);
3464 for (path
= search_path
; path
&& fp
== NULL
; path
= path
->next
)
3466 int len
= strlen (path
->path
) + flen
;
3468 if (len
+ 1 >= buffer_size
)
3470 buffer_size
= max (len
+ 1, 2 * buffer_size
);
3471 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3474 strcpy (buffer
, path
->path
);
3475 strcat (buffer
, "/");
3476 strcat (buffer
, file
);
3477 fp
= fopen (buffer
, "r");
3480 /* Try the original file name. */
3482 fp
= fopen (file
, "r");
3485 yyerror ("cannot open", NULL
);
3491 /* Display usage information and exit program. */
3494 Usage: ebrowse [options] {files}\n\
3496 -a, --append append output to existing file\n\
3497 -f, --files=FILES read input file names from FILE\n\
3498 -I, --search-path=LIST set search path for input files\n\
3499 -m, --min-regexp-length=N set minimum regexp length to N\n\
3500 -M, --max-regexp-length=N set maximum regexp length to N\n\
3501 -n, --no-nested-classes exclude nested classes\n\
3502 -o, --output-file=FILE set output file name to FILE\n\
3503 -p, --position-info print info about position in file\n\
3504 -s, --no-structs-or-unions don't record structs or unions\n\
3505 -v, --verbose be verbose\n\
3506 -V, --very-verbose be very verbose\n\
3507 -x, --no-regexps don't record regular expressions\n\
3508 --help display this help\n\
3509 --version display version info\n\
3516 exit (error
? EXIT_FAILURE
: EXIT_SUCCESS
);
3520 /* Display version and copyright info. The VERSION macro is set
3521 from config.h and contains the Emacs version. */
3524 # define VERSION "21"
3530 /* Makes it easier to update automatically. */
3531 char emacs_copyright
[] = "Copyright (C) 2011 Free Software Foundation, Inc.";
3533 printf ("ebrowse %s\n", VERSION
);
3534 puts (emacs_copyright
);
3535 puts ("This program is distributed under the same terms as Emacs.");
3536 exit (EXIT_SUCCESS
);
3540 /* Parse one input file FILE, adding classes and members to the symbol
3544 process_file (char *file
)
3548 fp
= open_file (file
);
3553 /* Give a progress indication if needed. */
3565 /* Read file to inbuffer. */
3568 if (nread
+ READ_CHUNK_SIZE
>= inbuffer_size
)
3570 inbuffer_size
= nread
+ READ_CHUNK_SIZE
+ 1;
3571 inbuffer
= (char *) xrealloc (inbuffer
, inbuffer_size
);
3574 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 */