1 /* ebrowse.c --- parsing files for the ebrowse C++ browser
3 Copyright (C) 1992-2018 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 (at
10 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 <https://www.gnu.org/licenses/>. */
29 #include <flexmember.h>
31 #include <unlocked-io.h>
33 /* The SunOS compiler doesn't have SEEK_END. */
38 /* Files are read in chunks of this number of bytes. */
40 enum { READ_CHUNK_SIZE
= 100 * 1024 };
42 /* Value is true if strings X and Y compare equal. */
45 streq (char const *x
, char const *y
)
47 return strcmp (x
, y
) == 0;
51 filename_eq (char const *x
, char const *y
)
54 return strcasecmp (x
, y
) == 0;
55 #elif defined WINDOWSNT
56 return stricmp (x
, y
) == 0;
62 /* The default output file name. */
64 #define DEFAULT_OUTFILE "BROWSE"
66 /* A version string written to the output file. Change this whenever
67 the structure of the output file changes. */
69 #define EBROWSE_FILE_VERSION "ebrowse 5.0"
71 /* The output file consists of a tree of Lisp objects, with major
72 nodes built out of Lisp structures. These are the heads of the
73 Lisp structs with symbols identifying their type. */
75 #define TREE_HEADER_STRUCT "[ebrowse-hs "
76 #define TREE_STRUCT "[ebrowse-ts "
77 #define MEMBER_STRUCT "[ebrowse-ms "
78 #define CLASS_STRUCT "[ebrowse-cs "
80 /* The name of the symbol table entry for global functions, variables,
81 defines etc. This name also appears in the browser display. */
83 #define GLOBALS_NAME "*Globals*"
85 /* Token definitions. */
89 YYEOF
= 0, /* end of file */
90 CSTRING
= 256, /* string constant */
91 CCHAR
, /* character constant */
92 CINT
, /* integral constant */
93 CFLOAT
, /* real constant */
99 IDENT
, /* identifier */
122 /* Keywords. The undef's are there because these
123 three symbols are very likely to be defined somewhere. */
136 CONTINUE
, /* continue */
137 DEFAULT
, /* default */
149 T_INLINE
, /* inline */
153 OPERATOR
, /* operator */
154 PRIVATE
, /* private */
155 PROTECTED
, /* protected */
157 REGISTER
, /* register */
165 TEMPLATE
, /* template */
169 TYPEDEF
, /* typedef */
171 UNSIGNED
, /* unsigned */
172 VIRTUAL
, /* virtual */
174 VOLATILE
, /* volatile */
176 MUTABLE
, /* mutable */
180 SIGNATURE
, /* signature (GNU extension) */
181 NAMESPACE
, /* namespace */
182 EXPLICIT
, /* explicit */
183 TYPENAME
, /* typename */
184 CONST_CAST
, /* const_cast */
185 DYNAMIC_CAST
, /* dynamic_cast */
186 REINTERPRET_CAST
, /* reinterpret_cast */
187 STATIC_CAST
, /* static_cast */
193 /* Storage classes, in a wider sense. */
198 SC_MEMBER
, /* Is an instance member. */
199 SC_STATIC
, /* Is static member. */
200 SC_FRIEND
, /* Is friend function. */
201 SC_TYPE
/* Is a type definition. */
204 /* Member visibility. */
215 #define F_VIRTUAL 1 /* Is virtual function. */
216 #define F_INLINE 2 /* Is inline function. */
217 #define F_CONST 4 /* Is const. */
218 #define F_PURE 8 /* Is pure virtual function. */
219 #define F_MUTABLE 16 /* Is mutable. */
220 #define F_TEMPLATE 32 /* Is a template. */
221 #define F_EXPLICIT 64 /* Is explicit constructor. */
222 #define F_THROW 128 /* Has a throw specification. */
223 #define F_EXTERNC 256 /* Is declared extern "C". */
224 #define F_DEFINE 512 /* Is a #define. */
226 /* Set and test a bit in an int. */
229 set_flag (int *f
, int flag
)
235 has_flag (int f
, int flag
)
237 return (f
& flag
) != 0;
240 /* Structure describing a class member. */
244 struct member
*next
; /* Next in list of members. */
245 struct member
*anext
; /* Collision chain in member_table. */
246 struct member
**list
; /* Pointer to list in class. */
247 unsigned param_hash
; /* Hash value for parameter types. */
248 int vis
; /* Visibility (public, ...). */
249 int flags
; /* See F_* above. */
250 char *regexp
; /* Matching regular expression. */
251 const char *filename
; /* Don't free this shared string. */
252 int pos
; /* Buffer position of occurrence. */
253 char *def_regexp
; /* Regular expression matching definition. */
254 const char *def_filename
; /* File name of definition. */
255 int def_pos
; /* Buffer position of definition. */
256 char name
[FLEXIBLE_ARRAY_MEMBER
]; /* Member name. */
259 /* Structures of this type are used to connect class structures with
260 their super and subclasses. */
264 struct sym
*sym
; /* The super or subclass. */
265 struct link
*next
; /* Next in list or NULL. */
268 /* Structure used to record namespace aliases. */
272 struct alias
*next
; /* Next in list. */
273 struct sym
*namesp
; /* Namespace in which defined. */
274 struct link
*aliasee
; /* List of aliased namespaces (A::B::C...). */
275 char name
[FLEXIBLE_ARRAY_MEMBER
]; /* Alias name. */
278 /* The structure used to describe a class in the symbol table,
279 or a namespace in all_namespaces. */
283 int flags
; /* Is class a template class?. */
284 unsigned char visited
; /* Used to find circles. */
285 struct sym
*next
; /* Hash collision list. */
286 struct link
*subs
; /* List of subclasses. */
287 struct link
*supers
; /* List of superclasses. */
288 struct member
*vars
; /* List of instance variables. */
289 struct member
*fns
; /* List of instance functions. */
290 struct member
*static_vars
; /* List of static variables. */
291 struct member
*static_fns
; /* List of static functions. */
292 struct member
*friends
; /* List of friend functions. */
293 struct member
*types
; /* List of local types. */
294 char *regexp
; /* Matching regular expression. */
295 int pos
; /* Buffer position. */
296 const char *filename
; /* File in which it can be found. */
297 const char *sfilename
; /* File in which members can be found. */
298 struct sym
*namesp
; /* Namespace in which defined. . */
299 char name
[FLEXIBLE_ARRAY_MEMBER
]; /* Name of the class. */
302 /* Experimental: Print info for `--position-info'. We print
303 '(CLASS-NAME SCOPE MEMBER-NAME). */
309 struct sym
*info_cls
= NULL
;
310 struct member
*info_member
= NULL
;
312 /* Experimental. For option `--position-info', the buffer position we
313 are interested in. When this position is reached, print out
314 information about what we know about that point. */
316 int info_position
= -1;
318 /* Command line options structure for getopt_long. */
320 struct option options
[] =
322 {"append", no_argument
, NULL
, 'a'},
323 {"files", required_argument
, NULL
, 'f'},
324 {"help", no_argument
, NULL
, -2},
325 {"min-regexp-length", required_argument
, NULL
, 'm'},
326 {"max-regexp-length", required_argument
, NULL
, 'M'},
327 {"no-nested-classes", no_argument
, NULL
, 'n'},
328 {"no-regexps", no_argument
, NULL
, 'x'},
329 {"no-structs-or-unions", no_argument
, NULL
, 's'},
330 {"output-file", required_argument
, NULL
, 'o'},
331 {"position-info", required_argument
, NULL
, 'p'},
332 {"search-path", required_argument
, NULL
, 'I'},
333 {"verbose", no_argument
, NULL
, 'v'},
334 {"version", no_argument
, NULL
, -3},
335 {"very-verbose", no_argument
, NULL
, 'V'},
339 /* Semantic values of tokens. Set by yylex.. */
341 unsigned yyival
; /* Set for token CINT. */
342 char *yytext
; /* Set for token IDENT. */
349 /* Current line number. */
353 /* The name of the current input file. */
355 const char *filename
;
357 /* Three character class vectors, and macros to test membership
364 #define IDENTP(C) is_ident[(unsigned char) (C)]
365 #define DIGITP(C) is_digit[(unsigned char) (C)]
366 #define WHITEP(C) is_white[(unsigned char) (C)]
368 /* Command line flags. */
375 int f_nested_classes
= 1;
377 /* Maximum and minimum lengths of regular expressions matching a
378 member, class etc., for writing them to the output file. These are
379 overridable from the command line. */
388 size_t inbuffer_size
;
390 /* Return the current buffer position in the input file. */
392 #define BUFFER_POS() (in - inbuffer)
394 /* If current lookahead is CSTRING, the following points to the
395 first character in the string constant. Used for recognizing
400 /* The size of the hash tables for classes.and members. Should be
403 #define TABLE_SIZE 1001
405 /* The hash table for class symbols. */
407 struct sym
*class_table
[TABLE_SIZE
];
409 /* Hash table containing all member structures. This is generally
410 faster for member lookup than traversing the member lists of a
413 struct member
*member_table
[TABLE_SIZE
];
415 /* Hash table for namespace aliases */
417 struct alias
*namespace_alias_table
[TABLE_SIZE
];
419 /* The special class symbol used to hold global functions,
422 struct sym
*global_symbols
;
424 /* The current namespace. */
426 struct sym
*current_namespace
;
428 /* The list of all known namespaces. */
430 struct sym
*all_namespaces
;
432 /* Stack of namespaces we're currently nested in, during the parse. */
434 struct sym
**namespace_stack
;
435 int namespace_stack_size
;
438 /* The current lookahead token. */
442 /* Structure describing a keyword. */
446 const char *name
; /* Spelling. */
447 int tk
; /* Token value. */
448 struct kw
*next
; /* Next in collision chain. */
451 /* Keywords are lookup up in a hash table of their own. */
453 #define KEYWORD_TABLE_SIZE 1001
454 struct kw
*keyword_table
[KEYWORD_TABLE_SIZE
];
461 struct search_path
*next
;
464 struct search_path
*search_path
;
465 struct search_path
*search_path_tail
;
467 /* Function prototypes. */
469 static char *matching_regexp (void);
470 static struct sym
*add_sym (const char *, struct sym
*);
471 static void add_global_defn (char *, char *, int, unsigned, int, int, int);
472 static void add_global_decl (char *, char *, int, unsigned, int, int, int);
473 static struct member
*add_member (struct sym
*, char *, int, int, unsigned);
474 static void class_definition (struct sym
*, int, int, int);
475 static char *operator_name (int *);
476 static void parse_qualified_param_ident_or_type (char **);
478 /***********************************************************************
480 ***********************************************************************/
482 /* Print an error in a printf-like style with the current input file
483 name and line number. */
486 yyerror (const char *format
, const char *s
)
488 fprintf (stderr
, "%s:%d: ", filename
, yyline
);
489 fprintf (stderr
, format
, s
);
494 /* Like malloc but print an error and exit if not enough memory is
498 xmalloc (size_t nbytes
)
500 void *p
= malloc (nbytes
);
503 yyerror ("out of memory", NULL
);
510 /* Like realloc but print an error and exit if out of memory. */
513 xrealloc (void *p
, size_t sz
)
518 yyerror ("out of memory", NULL
);
525 /* Like strdup, but print an error and exit if not enough memory is
526 available.. If S is null, return null. */
532 return strcpy (xmalloc (strlen (s
) + 1), s
);
538 /***********************************************************************
540 ***********************************************************************/
542 /* Initialize the symbol table. This currently only sets up the
543 special symbol for globals (`*Globals*'). */
548 global_symbols
= add_sym (GLOBALS_NAME
, NULL
);
552 /* Add a symbol for class NAME to the symbol table. NESTED_IN_CLASS
553 is the class in which class NAME was found. If it is null,
554 this means the scope of NAME is the current namespace.
556 If a symbol for NAME already exists, return that. Otherwise
557 create a new symbol and set it to default values. */
560 add_sym (const char *name
, struct sym
*nested_in_class
)
565 struct sym
*scope
= nested_in_class
? nested_in_class
: current_namespace
;
567 for (s
= name
, h
= 0; *s
; ++s
)
571 for (sym
= class_table
[h
]; sym
; sym
= sym
->next
)
572 if (streq (name
, sym
->name
)
573 && ((!sym
->namesp
&& !scope
)
574 || (sym
->namesp
&& scope
575 && streq (sym
->namesp
->name
, scope
->name
))))
586 sym
= xmalloc (FLEXSIZEOF (struct sym
, name
, strlen (name
) + 1));
587 memset (sym
, 0, offsetof (struct sym
, name
));
588 strcpy (sym
->name
, name
);
590 sym
->next
= class_table
[h
];
591 class_table
[h
] = sym
;
598 /* Add links between superclass SUPER and subclass SUB. */
601 add_link (struct sym
*super
, struct sym
*sub
)
603 struct link
*lnk
, *lnk2
, *p
, *prev
;
605 /* See if a link already exists. */
606 for (p
= super
->subs
, prev
= NULL
;
607 p
&& strcmp (sub
->name
, p
->sym
->name
) > 0;
608 prev
= p
, p
= p
->next
)
611 /* Avoid duplicates. */
612 if (p
== NULL
|| p
->sym
!= sub
)
614 lnk
= (struct link
*) xmalloc (sizeof *lnk
);
615 lnk2
= (struct link
*) xmalloc (sizeof *lnk2
);
626 lnk2
->next
= sub
->supers
;
632 /* Find in class CLS member NAME.
634 VAR non-zero means look for a member variable; otherwise a function
635 is searched. SC specifies what kind of member is searched---a
636 static, or per-instance member etc. HASH is a hash code for the
637 parameter types of functions. Value is a pointer to the member
638 found or null if not found. */
640 static struct member
*
641 find_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
643 struct member
**list
;
645 unsigned name_hash
= 0;
652 list
= &cls
->friends
;
660 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
664 list
= var
? &cls
->vars
: &cls
->fns
;
668 for (s
= name
; *s
; ++s
)
669 name_hash
= (name_hash
<< 1) ^ *s
;
670 i
= name_hash
% TABLE_SIZE
;
672 for (p
= member_table
[i
]; p
; p
= p
->anext
)
673 if (p
->list
== list
&& p
->param_hash
== hash
&& streq (name
, p
->name
))
680 /* Add to class CLS information for the declaration of member NAME.
681 REGEXP is a regexp matching the declaration, if non-null. POS is
682 the position in the source where the declaration is found. HASH is
683 a hash code for the parameter list of the member, if it's a
684 function. VAR non-zero means member is a variable or type. SC
685 specifies the type of member (instance member, static, ...). VIS
686 is the member's visibility (public, protected, private). FLAGS is
687 a bit set giving additional information about the member (see the
691 add_member_decl (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int vis
, int flags
)
695 m
= find_member (cls
, name
, var
, sc
, hash
);
697 m
= add_member (cls
, name
, var
, sc
, hash
);
699 /* Have we seen a new filename? If so record that. */
700 if (!cls
->filename
|| !filename_eq (cls
->filename
, filename
))
701 m
->filename
= filename
;
714 m
->vis
= V_PROTECTED
;
728 /* Add to class CLS information for the definition of member NAME.
729 REGEXP is a regexp matching the declaration, if non-null. POS is
730 the position in the source where the declaration is found. HASH is
731 a hash code for the parameter list of the member, if it's a
732 function. VAR non-zero means member is a variable or type. SC
733 specifies the type of member (instance member, static, ...). VIS
734 is the member's visibility (public, protected, private). FLAGS is
735 a bit set giving additional information about the member (see the
739 add_member_defn (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
743 if (sc
== SC_UNKNOWN
)
745 m
= find_member (cls
, name
, var
, SC_MEMBER
, hash
);
748 m
= find_member (cls
, name
, var
, SC_STATIC
, hash
);
750 m
= add_member (cls
, name
, var
, sc
, hash
);
755 m
= find_member (cls
, name
, var
, sc
, hash
);
757 m
= add_member (cls
, name
, var
, sc
, hash
);
761 cls
->sfilename
= filename
;
763 if (!filename_eq (cls
->sfilename
, filename
))
764 m
->def_filename
= filename
;
766 m
->def_regexp
= regexp
;
776 /* Add a symbol for a define named NAME to the symbol table.
777 REGEXP is a regular expression matching the define in the source,
778 if it is non-null. POS is the position in the file. */
781 add_define (char *name
, char *regexp
, int pos
)
783 add_global_defn (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
784 add_global_decl (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
788 /* Add information for the global definition of NAME.
789 REGEXP is a regexp matching the declaration, if non-null. POS is
790 the position in the source where the declaration is found. HASH is
791 a hash code for the parameter list of the member, if it's a
792 function. VAR non-zero means member is a variable or type. SC
793 specifies the type of member (instance member, static, ...). VIS
794 is the member's visibility (public, protected, private). FLAGS is
795 a bit set giving additional information about the member (see the
799 add_global_defn (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
804 /* Try to find out for which classes a function is a friend, and add
805 what we know about it to them. */
807 for (i
= 0; i
< TABLE_SIZE
; ++i
)
808 for (sym
= class_table
[i
]; sym
; sym
= sym
->next
)
809 if (sym
!= global_symbols
&& sym
->friends
)
810 if (find_member (sym
, name
, 0, SC_FRIEND
, hash
))
811 add_member_defn (sym
, name
, regexp
, pos
, hash
, 0,
814 /* Add to global symbols. */
815 add_member_defn (global_symbols
, name
, regexp
, pos
, hash
, var
, sc
, flags
);
819 /* Add information for the global declaration of NAME.
820 REGEXP is a regexp matching the declaration, if non-null. POS is
821 the position in the source where the declaration is found. HASH is
822 a hash code for the parameter list of the member, if it's a
823 function. VAR non-zero means member is a variable or type. SC
824 specifies the type of member (instance member, static, ...). VIS
825 is the member's visibility (public, protected, private). FLAGS is
826 a bit set giving additional information about the member (see the
830 add_global_decl (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
832 /* Add declaration only if not already declared. Header files must
833 be processed before source files for this to have the right effect.
834 I do not want to handle implicit declarations at the moment. */
836 struct member
*found
;
838 m
= found
= find_member (global_symbols
, name
, var
, sc
, hash
);
840 m
= add_member (global_symbols
, name
, var
, sc
, hash
);
842 /* Definition already seen => probably last declaration implicit.
843 Override. This means that declarations must always be added to
844 the symbol table before definitions. */
847 if (!global_symbols
->filename
848 || !filename_eq (global_symbols
->filename
, filename
))
849 m
->filename
= filename
;
857 info_cls
= global_symbols
;
863 /* Add a symbol for member NAME to class CLS.
864 VAR non-zero means it's a variable. SC specifies the kind of
865 member. HASH is a hash code for the parameter types of a function.
866 Value is a pointer to the member's structure. */
868 static struct member
*
869 add_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
871 struct member
*m
= xmalloc (FLEXSIZEOF (struct member
, name
,
873 struct member
**list
;
876 unsigned name_hash
= 0;
880 strcpy (m
->name
, name
);
881 m
->param_hash
= hash
;
888 m
->def_regexp
= NULL
;
889 m
->def_filename
= NULL
;
892 assert (cls
!= NULL
);
897 list
= &cls
->friends
;
905 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
909 list
= var
? &cls
->vars
: &cls
->fns
;
913 for (s
= name
; *s
; ++s
)
914 name_hash
= (name_hash
<< 1) ^ *s
;
915 i
= name_hash
% TABLE_SIZE
;
916 m
->anext
= member_table
[i
];
920 /* Keep the member list sorted. It's cheaper to do it here than to
921 sort them in Lisp. */
922 for (prev
= NULL
, p
= *list
;
923 p
&& strcmp (name
, p
->name
) > 0;
924 prev
= p
, p
= p
->next
)
936 /* Given the root R of a class tree, step through all subclasses
937 recursively, marking functions as virtual that are declared virtual
941 mark_virtual (struct sym
*r
)
944 struct member
*m
, *m2
;
946 for (p
= r
->subs
; p
; p
= p
->next
)
948 for (m
= r
->fns
; m
; m
= m
->next
)
949 if (has_flag (m
->flags
, F_VIRTUAL
))
951 for (m2
= p
->sym
->fns
; m2
; m2
= m2
->next
)
952 if (m
->param_hash
== m2
->param_hash
&& streq (m
->name
, m2
->name
))
953 set_flag (&m2
->flags
, F_VIRTUAL
);
956 mark_virtual (p
->sym
);
961 /* For all roots of the class tree, mark functions as virtual that
962 are virtual because of a virtual declaration in a base class. */
965 mark_inherited_virtual (void)
970 for (i
= 0; i
< TABLE_SIZE
; ++i
)
971 for (r
= class_table
[i
]; r
; r
= r
->next
)
972 if (r
->supers
== NULL
)
977 /* Create and return a symbol for a namespace with name NAME. */
980 make_namespace (char *name
, struct sym
*context
)
982 struct sym
*s
= xmalloc (FLEXSIZEOF (struct sym
, name
, strlen (name
) + 1));
983 memset (s
, 0, offsetof (struct sym
, name
));
984 strcpy (s
->name
, name
);
985 s
->next
= all_namespaces
;
992 /* Find the symbol for namespace NAME. If not found, return NULL */
995 check_namespace (char *name
, struct sym
*context
)
997 struct sym
*p
= NULL
;
999 for (p
= all_namespaces
; p
; p
= p
->next
)
1001 if (streq (p
->name
, name
) && (p
->namesp
== context
))
1008 /* Find the symbol for namespace NAME. If not found, add a new symbol
1009 for NAME to all_namespaces. */
1012 find_namespace (char *name
, struct sym
*context
)
1014 struct sym
*p
= check_namespace (name
, context
);
1017 p
= make_namespace (name
, context
);
1023 /* Find namespace alias with name NAME. If not found return NULL. */
1025 static struct link
*
1026 check_namespace_alias (char *name
)
1028 struct link
*p
= NULL
;
1033 for (s
= name
, h
= 0; *s
; ++s
)
1037 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1038 if (streq (name
, al
->name
) && (al
->namesp
== current_namespace
))
1047 /* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */
1050 register_namespace_alias (char *new_name
, struct link
*old_name
)
1056 for (s
= new_name
, h
= 0; *s
; ++s
)
1061 /* Is it already in the table of aliases? */
1062 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1063 if (streq (new_name
, al
->name
) && (al
->namesp
== current_namespace
))
1066 al
= xmalloc (FLEXSIZEOF (struct alias
, name
, strlen (new_name
) + 1));
1067 strcpy (al
->name
, new_name
);
1068 al
->next
= namespace_alias_table
[h
];
1069 al
->namesp
= current_namespace
;
1070 al
->aliasee
= old_name
;
1071 namespace_alias_table
[h
] = al
;
1075 /* Enter namespace with name NAME. */
1078 enter_namespace (char *name
)
1080 struct sym
*p
= find_namespace (name
, current_namespace
);
1082 if (namespace_sp
== namespace_stack_size
)
1084 int size
= max (10, 2 * namespace_stack_size
);
1086 = (struct sym
**) xrealloc ((void *)namespace_stack
,
1087 size
* sizeof *namespace_stack
);
1088 namespace_stack_size
= size
;
1091 namespace_stack
[namespace_sp
++] = current_namespace
;
1092 current_namespace
= p
;
1096 /* Leave the current namespace. */
1099 leave_namespace (void)
1101 assert (namespace_sp
> 0);
1102 current_namespace
= namespace_stack
[--namespace_sp
];
1107 /***********************************************************************
1108 Writing the Output File
1109 ***********************************************************************/
1111 /* Write string S to the output file FP in a Lisp-readable form.
1112 If S is null, write out `()'. */
1115 putstr (const char *s
, FILE *fp
)
1132 /* A dynamically allocated buffer for constructing a scope name. */
1135 int scope_buffer_size
;
1136 int scope_buffer_len
;
1139 /* Make sure scope_buffer has enough room to add LEN chars to it. */
1142 ensure_scope_buffer_room (int len
)
1144 if (scope_buffer_len
+ len
>= scope_buffer_size
)
1146 int new_size
= max (2 * scope_buffer_size
, scope_buffer_len
+ len
);
1147 scope_buffer
= (char *) xrealloc (scope_buffer
, new_size
);
1148 scope_buffer_size
= new_size
;
1153 /* Recursively add the scope names of symbol P and the scopes of its
1154 namespaces to scope_buffer. Value is a pointer to the complete
1155 scope name constructed. */
1158 sym_scope_1 (struct sym
*p
)
1163 sym_scope_1 (p
->namesp
);
1167 ensure_scope_buffer_room (3);
1168 strcpy (scope_buffer
+ scope_buffer_len
, "::");
1169 scope_buffer_len
+= 2;
1172 len
= strlen (p
->name
);
1173 ensure_scope_buffer_room (len
+ 1);
1174 strcpy (scope_buffer
+ scope_buffer_len
, p
->name
);
1175 scope_buffer_len
+= len
;
1177 if (has_flag (p
->flags
, F_TEMPLATE
))
1179 ensure_scope_buffer_room (3);
1180 strcpy (scope_buffer
+ scope_buffer_len
, "<>");
1181 scope_buffer_len
+= 2;
1184 return scope_buffer
;
1188 /* Return the scope of symbol P in printed representation, i.e.
1189 as it would appear in a C*+ source file. */
1192 sym_scope (struct sym
*p
)
1196 scope_buffer_size
= 1024;
1197 scope_buffer
= (char *) xmalloc (scope_buffer_size
);
1200 *scope_buffer
= '\0';
1201 scope_buffer_len
= 0;
1204 sym_scope_1 (p
->namesp
);
1206 return scope_buffer
;
1210 /* Dump the list of members M to file FP. Value is the length of the
1214 dump_members (FILE *fp
, struct member
*m
)
1220 for (n
= 0; m
; m
= m
->next
, ++n
)
1222 fputs (MEMBER_STRUCT
, fp
);
1223 putstr (m
->name
, fp
);
1224 putstr (NULL
, fp
); /* FIXME? scope for globals */
1225 fprintf (fp
, "%u ", (unsigned) m
->flags
);
1226 putstr (m
->filename
, fp
);
1227 putstr (m
->regexp
, fp
);
1228 fprintf (fp
, "%u ", (unsigned) m
->pos
);
1229 fprintf (fp
, "%u ", (unsigned) m
->vis
);
1231 putstr (m
->def_filename
, fp
);
1232 putstr (m
->def_regexp
, fp
);
1233 fprintf (fp
, "%u", (unsigned) m
->def_pos
);
1244 /* Dump class ROOT to stream FP. */
1247 dump_sym (FILE *fp
, struct sym
*root
)
1249 fputs (CLASS_STRUCT
, fp
);
1250 putstr (root
->name
, fp
);
1252 /* Print scope, if any. */
1254 putstr (sym_scope (root
), fp
);
1259 fprintf (fp
, "%d", root
->flags
);
1260 putstr (root
->filename
, fp
);
1261 putstr (root
->regexp
, fp
);
1262 fprintf (fp
, "%u", (unsigned) root
->pos
);
1263 putstr (root
->sfilename
, fp
);
1269 /* Dump class ROOT and its subclasses to file FP. Value is the
1270 number of classes written. */
1273 dump_tree (FILE *fp
, struct sym
*root
)
1278 dump_sym (fp
, root
);
1288 for (lk
= root
->subs
; lk
; lk
= lk
->next
)
1290 fputs (TREE_STRUCT
, fp
);
1291 n
+= dump_tree (fp
, lk
->sym
);
1297 dump_members (fp
, root
->vars
);
1298 n
+= dump_members (fp
, root
->fns
);
1299 dump_members (fp
, root
->static_vars
);
1300 n
+= dump_members (fp
, root
->static_fns
);
1301 n
+= dump_members (fp
, root
->friends
);
1302 dump_members (fp
, root
->types
);
1317 /* Dump the entire class tree to file FP. */
1320 dump_roots (FILE *fp
)
1325 /* Output file header containing version string, command line
1329 fputs (TREE_HEADER_STRUCT
, fp
);
1330 putstr (EBROWSE_FILE_VERSION
, fp
);
1343 /* Mark functions as virtual that are so because of functions
1344 declared virtual in base classes. */
1345 mark_inherited_virtual ();
1347 /* Dump the roots of the graph. */
1348 for (i
= 0; i
< TABLE_SIZE
; ++i
)
1349 for (r
= class_table
[i
]; r
; r
= r
->next
)
1352 fputs (TREE_STRUCT
, fp
);
1353 n
+= dump_tree (fp
, r
);
1363 /***********************************************************************
1365 ***********************************************************************/
1368 #define INCREMENT_LINENO \
1370 if (f_very_verbose) \
1373 printf ("%d:\n", yyline); \
1379 #define INCREMENT_LINENO ++yyline
1382 /* Define two macros for accessing the input buffer (current input
1383 file). GET(C) sets C to the next input character and advances the
1384 input pointer. UNGET retracts the input pointer. */
1386 #define GET(C) ((C) = *in++)
1387 #define UNGET() (--in)
1390 /* Process a preprocessor line. Value is the next character from the
1391 input buffer not consumed. */
1394 process_pp_line (void)
1396 int in_comment
= 0, in_string
= 0;
1400 /* Skip over white space. The `#' has been consumed already. */
1401 while (WHITEP (GET (c
)))
1404 /* Read the preprocessor command (if any). */
1411 /* Is it a `define'? */
1414 if (*yytext
&& streq (yytext
, "define"))
1429 char *regexp
= matching_regexp ();
1430 int pos
= BUFFER_POS ();
1431 add_define (yytext
, regexp
, pos
);
1435 while (c
&& (c
!= '\n' || in_comment
|| in_string
))
1439 else if (c
== '/' && !in_comment
)
1444 else if (c
== '*' && in_comment
)
1450 in_string
= !in_string
;
1462 /* Value is the next token from the input buffer. */
1473 while (WHITEP (GET (c
)))
1495 /* String and character constants. */
1498 while (GET (c
) && c
!= end_char
)
1503 /* Escape sequences. */
1506 if (end_char
== '\'')
1507 yyerror ("EOF in character constant", NULL
);
1509 yyerror ("EOF in string constant", NULL
);
1527 /* Hexadecimal escape sequence. */
1529 for (i
= 0; i
< 2; ++i
)
1533 if (c
>= '0' && c
<= '7')
1535 else if (c
>= 'a' && c
<= 'f')
1537 else if (c
>= 'A' && c
<= 'F')
1550 /* Octal escape sequence. */
1552 for (i
= 0; i
< 3; ++i
)
1556 if (c
>= '0' && c
<= '7')
1573 if (end_char
== '\'')
1574 yyerror ("newline in character constant", NULL
);
1576 yyerror ("newline in string constant", NULL
);
1586 return end_char
== '\'' ? CCHAR
: CSTRING
;
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':
1592 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1593 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1594 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1595 case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_':
1597 /* Identifier and keywords. */
1604 while (IDENTP (GET (*p
)))
1606 hash
= (hash
<< 1) ^ *p
++;
1607 if (p
== yytext_end
- 1)
1609 int size
= yytext_end
- yytext
;
1610 yytext
= (char *) xrealloc (yytext
, 2 * size
);
1611 yytext_end
= yytext
+ 2 * size
;
1612 p
= yytext
+ size
- 1;
1619 for (k
= keyword_table
[hash
% KEYWORD_TABLE_SIZE
]; k
; k
= k
->next
)
1620 if (streq (k
->name
, yytext
))
1627 /* C and C++ comments, '/' and '/='. */
1655 while (GET (c
) && c
!= '\n')
1657 /* Don't try to read past the end of the input buffer if
1658 the file ends in a C++ comment without a newline. */
1735 yyerror ("invalid token '..' ('...' assumed)", NULL
);
1739 else if (!DIGITP (c
))
1793 c
= process_pp_line ();
1798 case '(': case ')': case '[': case ']': case '{': case '}':
1799 case ';': case ',': case '?': case '~':
1805 if (GET (c
) == 'x' || c
== 'X')
1810 yyival
= yyival
* 16 + c
- '0';
1811 else if (c
>= 'a' && c
<= 'f')
1812 yyival
= yyival
* 16 + c
- 'a' + 10;
1813 else if (c
>= 'A' && c
<= 'F')
1814 yyival
= yyival
* 16 + c
- 'A' + 10;
1824 while (c
>= '0' && c
<= '7')
1826 yyival
= (yyival
<< 3) + c
- '0';
1831 /* Integer suffixes. */
1837 case '1': case '2': case '3': case '4': case '5': case '6':
1838 case '7': case '8': case '9':
1839 /* Integer or floating constant, part before '.'. */
1842 while (GET (c
) && DIGITP (c
))
1843 yyival
= 10 * yyival
+ c
- '0';
1849 /* Digits following '.'. */
1853 /* Optional exponent. */
1854 if (c
== 'E' || c
== 'e')
1856 if (GET (c
) == '-' || c
== '+')
1863 /* Optional type suffixes. */
1876 /* Actually local to matching_regexp. These variables must be in
1877 global scope for the case that `static' get's defined away. */
1879 static char *matching_regexp_buffer
, *matching_regexp_end_buf
;
1882 /* Value is the string from the start of the line to the current
1883 position in the input buffer, or maybe a bit more if that string is
1884 shorter than min_regexp. */
1887 matching_regexp (void)
1896 if (matching_regexp_buffer
== NULL
)
1898 matching_regexp_buffer
= (char *) xmalloc (max_regexp
);
1899 matching_regexp_end_buf
= &matching_regexp_buffer
[max_regexp
] - 1;
1902 /* Scan back to previous newline of buffer start. */
1903 for (p
= in
- 1; p
> inbuffer
&& *p
!= '\n'; --p
)
1908 while (in
- p
< min_regexp
&& p
> inbuffer
)
1910 /* Line probably not significant enough */
1911 for (--p
; p
> inbuffer
&& *p
!= '\n'; --p
)
1918 /* Copy from end to make sure significant portions are included.
1919 This implies that in the browser a regular expressing of the form
1920 `^.*{regexp}' has to be used. */
1921 for (s
= matching_regexp_end_buf
- 1, t
= in
;
1922 s
> matching_regexp_buffer
&& t
> p
;)
1926 if (*s
== '"' || *s
== '\\')
1930 *(matching_regexp_end_buf
- 1) = '\0';
1935 /* Return a printable representation of token T. */
1938 token_string (int t
)
1944 case CSTRING
: return "string constant";
1945 case CCHAR
: return "char constant";
1946 case CINT
: return "int constant";
1947 case CFLOAT
: return "floating constant";
1948 case ELLIPSIS
: return "...";
1949 case LSHIFTASGN
: return "<<=";
1950 case RSHIFTASGN
: return ">>=";
1951 case ARROWSTAR
: return "->*";
1952 case IDENT
: return "identifier";
1953 case DIVASGN
: return "/=";
1954 case INC
: return "++";
1955 case ADDASGN
: return "+=";
1956 case DEC
: return "--";
1957 case ARROW
: return "->";
1958 case SUBASGN
: return "-=";
1959 case MULASGN
: return "*=";
1960 case MODASGN
: return "%=";
1961 case LOR
: return "||";
1962 case ORASGN
: return "|=";
1963 case LAND
: return "&&";
1964 case ANDASGN
: return "&=";
1965 case XORASGN
: return "^=";
1966 case POINTSTAR
: return ".*";
1967 case DCOLON
: return "::";
1968 case EQ
: return "==";
1969 case NE
: return "!=";
1970 case LE
: return "<=";
1971 case LSHIFT
: return "<<";
1972 case GE
: return ">=";
1973 case RSHIFT
: return ">>";
1974 case ASM
: return "asm";
1975 case AUTO
: return "auto";
1976 case BREAK
: return "break";
1977 case CASE
: return "case";
1978 case CATCH
: return "catch";
1979 case CHAR
: return "char";
1980 case CLASS
: return "class";
1981 case CONST
: return "const";
1982 case CONTINUE
: return "continue";
1983 case DEFAULT
: return "default";
1984 case DELETE
: return "delete";
1985 case DO
: return "do";
1986 case DOUBLE
: return "double";
1987 case ELSE
: return "else";
1988 case ENUM
: return "enum";
1989 case EXTERN
: return "extern";
1990 case FLOAT
: return "float";
1991 case FOR
: return "for";
1992 case FRIEND
: return "friend";
1993 case GOTO
: return "goto";
1994 case IF
: return "if";
1995 case T_INLINE
: return "inline";
1996 case INT
: return "int";
1997 case LONG
: return "long";
1998 case NEW
: return "new";
1999 case OPERATOR
: return "operator";
2000 case PRIVATE
: return "private";
2001 case PROTECTED
: return "protected";
2002 case PUBLIC
: return "public";
2003 case REGISTER
: return "register";
2004 case RETURN
: return "return";
2005 case SHORT
: return "short";
2006 case SIGNED
: return "signed";
2007 case SIZEOF
: return "sizeof";
2008 case STATIC
: return "static";
2009 case STRUCT
: return "struct";
2010 case SWITCH
: return "switch";
2011 case TEMPLATE
: return "template";
2012 case THIS
: return "this";
2013 case THROW
: return "throw";
2014 case TRY
: return "try";
2015 case TYPEDEF
: return "typedef";
2016 case UNION
: return "union";
2017 case UNSIGNED
: return "unsigned";
2018 case VIRTUAL
: return "virtual";
2019 case VOID
: return "void";
2020 case VOLATILE
: return "volatile";
2021 case WHILE
: return "while";
2022 case MUTABLE
: return "mutable";
2023 case BOOL
: return "bool";
2024 case TRUE
: return "true";
2025 case FALSE
: return "false";
2026 case SIGNATURE
: return "signature";
2027 case NAMESPACE
: return "namespace";
2028 case EXPLICIT
: return "explicit";
2029 case TYPENAME
: return "typename";
2030 case CONST_CAST
: return "const_cast";
2031 case DYNAMIC_CAST
: return "dynamic_cast";
2032 case REINTERPRET_CAST
: return "reinterpret_cast";
2033 case STATIC_CAST
: return "static_cast";
2034 case TYPEID
: return "typeid";
2035 case USING
: return "using";
2036 case WCHAR
: return "wchar_t";
2037 case YYEOF
: return "EOF";
2052 /* Reinitialize the scanner for a new input file. */
2055 re_init_scanner (void)
2063 yytext
= (char *) xmalloc (size
* sizeof *yytext
);
2064 yytext_end
= yytext
+ size
;
2069 /* Insert a keyword NAME with token value TKV into the keyword hash
2073 insert_keyword (const char *name
, int tkv
)
2077 struct kw
*k
= (struct kw
*) xmalloc (sizeof *k
);
2079 for (s
= name
; *s
; ++s
)
2082 h
%= KEYWORD_TABLE_SIZE
;
2085 k
->next
= keyword_table
[h
];
2086 keyword_table
[h
] = k
;
2090 /* Initialize the scanner for the first file. This sets up the
2091 character class vectors and fills the keyword hash table. */
2098 /* Allocate the input buffer */
2099 inbuffer_size
= READ_CHUNK_SIZE
+ 1;
2100 inbuffer
= in
= (char *) xmalloc (inbuffer_size
);
2103 /* Set up character class vectors. */
2104 for (i
= 0; i
< sizeof is_ident
; ++i
)
2106 if (i
== '_' || isalnum (i
))
2109 if (i
>= '0' && i
<= '9')
2112 if (i
== ' ' || i
== '\t' || i
== '\f' || i
== '\v')
2116 /* Fill keyword hash table. */
2117 insert_keyword ("and", LAND
);
2118 insert_keyword ("and_eq", ANDASGN
);
2119 insert_keyword ("asm", ASM
);
2120 insert_keyword ("auto", AUTO
);
2121 insert_keyword ("bitand", '&');
2122 insert_keyword ("bitor", '|');
2123 insert_keyword ("bool", BOOL
);
2124 insert_keyword ("break", BREAK
);
2125 insert_keyword ("case", CASE
);
2126 insert_keyword ("catch", CATCH
);
2127 insert_keyword ("char", CHAR
);
2128 insert_keyword ("class", CLASS
);
2129 insert_keyword ("compl", '~');
2130 insert_keyword ("const", CONST
);
2131 insert_keyword ("const_cast", CONST_CAST
);
2132 insert_keyword ("continue", CONTINUE
);
2133 insert_keyword ("default", DEFAULT
);
2134 insert_keyword ("delete", DELETE
);
2135 insert_keyword ("do", DO
);
2136 insert_keyword ("double", DOUBLE
);
2137 insert_keyword ("dynamic_cast", DYNAMIC_CAST
);
2138 insert_keyword ("else", ELSE
);
2139 insert_keyword ("enum", ENUM
);
2140 insert_keyword ("explicit", EXPLICIT
);
2141 insert_keyword ("extern", EXTERN
);
2142 insert_keyword ("false", FALSE
);
2143 insert_keyword ("float", FLOAT
);
2144 insert_keyword ("for", FOR
);
2145 insert_keyword ("friend", FRIEND
);
2146 insert_keyword ("goto", GOTO
);
2147 insert_keyword ("if", IF
);
2148 insert_keyword ("inline", T_INLINE
);
2149 insert_keyword ("int", INT
);
2150 insert_keyword ("long", LONG
);
2151 insert_keyword ("mutable", MUTABLE
);
2152 insert_keyword ("namespace", NAMESPACE
);
2153 insert_keyword ("new", NEW
);
2154 insert_keyword ("not", '!');
2155 insert_keyword ("not_eq", NE
);
2156 insert_keyword ("operator", OPERATOR
);
2157 insert_keyword ("or", LOR
);
2158 insert_keyword ("or_eq", ORASGN
);
2159 insert_keyword ("private", PRIVATE
);
2160 insert_keyword ("protected", PROTECTED
);
2161 insert_keyword ("public", PUBLIC
);
2162 insert_keyword ("register", REGISTER
);
2163 insert_keyword ("reinterpret_cast", REINTERPRET_CAST
);
2164 insert_keyword ("return", RETURN
);
2165 insert_keyword ("short", SHORT
);
2166 insert_keyword ("signed", SIGNED
);
2167 insert_keyword ("sizeof", SIZEOF
);
2168 insert_keyword ("static", STATIC
);
2169 insert_keyword ("static_cast", STATIC_CAST
);
2170 insert_keyword ("struct", STRUCT
);
2171 insert_keyword ("switch", SWITCH
);
2172 insert_keyword ("template", TEMPLATE
);
2173 insert_keyword ("this", THIS
);
2174 insert_keyword ("throw", THROW
);
2175 insert_keyword ("true", TRUE
);
2176 insert_keyword ("try", TRY
);
2177 insert_keyword ("typedef", TYPEDEF
);
2178 insert_keyword ("typeid", TYPEID
);
2179 insert_keyword ("typename", TYPENAME
);
2180 insert_keyword ("union", UNION
);
2181 insert_keyword ("unsigned", UNSIGNED
);
2182 insert_keyword ("using", USING
);
2183 insert_keyword ("virtual", VIRTUAL
);
2184 insert_keyword ("void", VOID
);
2185 insert_keyword ("volatile", VOLATILE
);
2186 insert_keyword ("wchar_t", WCHAR
);
2187 insert_keyword ("while", WHILE
);
2188 insert_keyword ("xor", '^');
2189 insert_keyword ("xor_eq", XORASGN
);
2194 /***********************************************************************
2196 ***********************************************************************/
2198 /* Match the current lookahead token and set it to the next token. */
2200 #define MATCH() (tk = yylex ())
2202 /* Return the lookahead token. If current lookahead token is cleared,
2203 read a new token. */
2205 #define LA1 (tk == -1 ? (tk = yylex ()) : tk)
2207 /* Is the current lookahead equal to the token T? */
2209 #define LOOKING_AT(T) (tk == (T))
2211 /* Is the current lookahead one of T1 or T2? */
2213 #define LOOKING_AT2(T1, T2) (tk == (T1) || tk == (T2))
2215 /* Is the current lookahead one of T1, T2 or T3? */
2217 #define LOOKING_AT3(T1, T2, T3) (tk == (T1) || tk == (T2) || tk == (T3))
2219 /* Is the current lookahead one of T1...T4? */
2221 #define LOOKING_AT4(T1, T2, T3, T4) \
2222 (tk == (T1) || tk == (T2) || tk == (T3) || tk == (T4))
2224 /* Match token T if current lookahead is T. */
2226 #define MATCH_IF(T) if (LOOKING_AT (T)) MATCH (); else ((void) 0)
2228 /* Skip to matching token if current token is T. */
2230 #define SKIP_MATCHING_IF(T) \
2231 if (LOOKING_AT (T)) skip_matching (); else ((void) 0)
2234 /* Skip forward until a given token TOKEN or YYEOF is seen and return
2235 the current lookahead token after skipping. */
2240 while (!LOOKING_AT2 (YYEOF
, token
))
2245 /* Skip over pairs of tokens (parentheses, square brackets,
2246 angle brackets, curly brackets) matching the current lookahead. */
2249 skip_matching (void)
2277 if (LOOKING_AT (open
))
2279 else if (LOOKING_AT (close
))
2281 else if (LOOKING_AT (YYEOF
))
2292 skip_initializer (void)
2316 /* Build qualified namespace alias (A::B::c) and return it. */
2318 static struct link
*
2319 match_qualified_namespace_alias (void)
2321 struct link
*head
= NULL
;
2322 struct link
*cur
= NULL
;
2323 struct link
*tmp
= NULL
;
2331 tmp
= (struct link
*) xmalloc (sizeof *cur
);
2332 tmp
->sym
= find_namespace (yytext
, cur
? cur
->sym
: NULL
);
2336 cur
= cur
->next
= tmp
;
2353 /* Re-initialize the parser by resetting the lookahead token. */
2356 re_init_parser (void)
2362 /* Parse a parameter list, including the const-specifier,
2363 pure-specifier, and throw-list that may follow a parameter list.
2364 Return in FLAGS what was seen following the parameter list.
2365 Returns a hash code for the parameter types. This value is used to
2366 distinguish between overloaded functions. */
2369 parm_list (int *flags
)
2374 while (!LOOKING_AT2 (YYEOF
, ')'))
2378 /* Skip over grouping parens or parameter lists in parameter
2384 /* Next parameter. */
2390 /* Ignore the scope part of types, if any. This is because
2391 some types need scopes when defined outside of a class body,
2392 and don't need them inside the class body. This means that
2393 we have to look for the last IDENT in a sequence of
2394 IDENT::IDENT::... */
2399 unsigned ident_type_hash
= 0;
2401 parse_qualified_param_ident_or_type (&last_id
);
2404 /* LAST_ID null means something like `X::*'. */
2405 for (; *last_id
; ++last_id
)
2406 ident_type_hash
= (ident_type_hash
<< 1) ^ *last_id
;
2407 hash
= (hash
<< 1) ^ ident_type_hash
;
2416 /* This distinction is made to make `func (void)' equivalent
2420 if (!LOOKING_AT (')'))
2421 hash
= (hash
<< 1) ^ VOID
;
2424 case BOOL
: case CHAR
: case CLASS
: case CONST
:
2425 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2426 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2427 case UNION
: case UNSIGNED
: case VOLATILE
: case WCHAR
:
2430 hash
= (hash
<< 1) ^ LA1
;
2434 case '*': case '&': case '[': case ']':
2435 hash
= (hash
<< 1) ^ LA1
;
2445 if (LOOKING_AT (')'))
2449 if (LOOKING_AT (CONST
))
2451 /* We can overload the same function on `const' */
2452 hash
= (hash
<< 1) ^ CONST
;
2453 set_flag (flags
, F_CONST
);
2457 if (LOOKING_AT (THROW
))
2460 SKIP_MATCHING_IF ('(');
2461 set_flag (flags
, F_THROW
);
2464 if (LOOKING_AT ('='))
2467 if (LOOKING_AT (CINT
) && yyival
== 0)
2470 set_flag (flags
, F_PURE
);
2479 /* Print position info to stdout. */
2484 if (info_position
>= 0 && BUFFER_POS () <= info_position
)
2486 printf ("(\"%s\" \"%s\" \"%s\" %d)\n",
2487 info_cls
->name
, sym_scope (info_cls
),
2488 info_member
->name
, info_where
);
2492 /* Parse a member declaration within the class body of CLS. VIS is
2493 the access specifier for the member (private, protected,
2497 member (struct sym
*cls
, int vis
)
2501 char *regexp
= NULL
;
2512 while (!LOOKING_AT4 (';', '{', '}', YYEOF
))
2520 /* A function or class may follow. */
2523 set_flag (&flags
, F_TEMPLATE
);
2524 /* Skip over template argument list */
2525 SKIP_MATCHING_IF ('<');
2529 set_flag (&flags
, F_EXPLICIT
);
2533 set_flag (&flags
, F_MUTABLE
);
2537 set_flag (&flags
, F_INLINE
);
2541 set_flag (&flags
, F_VIRTUAL
);
2570 /* Remember IDENTS seen so far. Among these will be the member
2572 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
2576 strcpy (id
+ 1, yytext
);
2579 strcpy (id
, yytext
);
2585 char *s
= operator_name (&sc
);
2586 id
= (char *) xrealloc (id
, strlen (s
) + 1);
2592 /* Most probably the beginning of a parameter list. */
2598 if (!(is_constructor
= streq (id
, cls
->name
)))
2599 regexp
= matching_regexp ();
2604 pos
= BUFFER_POS ();
2605 hash
= parm_list (&flags
);
2608 regexp
= matching_regexp ();
2610 if (id
&& cls
!= NULL
)
2611 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, flags
);
2613 while (!LOOKING_AT3 (';', '{', YYEOF
))
2616 if (LOOKING_AT ('{') && id
&& cls
)
2617 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0, sc
, flags
);
2624 case STRUCT
: case UNION
: case CLASS
:
2631 /* More than one ident here to allow for MS-DOS specialties
2632 like `_export class' etc. The last IDENT seen counts
2633 as the class name. */
2634 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
2636 if (LOOKING_AT (IDENT
))
2641 if (LOOKING_AT2 (':', '{'))
2642 class_definition (anonymous
? NULL
: cls
, class_tag
, flags
, 1);
2647 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
2648 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
2649 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
2658 if (LOOKING_AT (';'))
2660 /* The end of a member variable, a friend declaration or an access
2661 declaration. We don't want to add friend classes as members. */
2662 if (id
&& sc
!= SC_FRIEND
&& cls
)
2664 regexp
= matching_regexp ();
2665 pos
= BUFFER_POS ();
2669 if (type_seen
|| !paren_seen
)
2670 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2672 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, 0);
2679 else if (LOOKING_AT ('{'))
2682 if (sc
== SC_TYPE
&& id
&& cls
)
2684 regexp
= matching_regexp ();
2685 pos
= BUFFER_POS ();
2689 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2690 add_member_defn (cls
, id
, regexp
, pos
, 0, 1, sc
, 0);
2702 /* Parse the body of class CLS. TAG is the tag of the class (struct,
2706 class_body (struct sym
*cls
, int tag
)
2708 int vis
= tag
== CLASS
? PRIVATE
: PUBLIC
;
2711 while (!LOOKING_AT2 (YYEOF
, '}'))
2715 case PRIVATE
: case PROTECTED
: case PUBLIC
:
2719 if (LOOKING_AT (':'))
2726 /* Probably conditional compilation for inheritance list.
2727 We don't known whether there comes more of this.
2728 This is only a crude fix that works most of the time. */
2733 while (LOOKING_AT2 (IDENT
, ',')
2734 || LOOKING_AT3 (PUBLIC
, PROTECTED
, PRIVATE
));
2743 /* Try to synchronize */
2744 case CHAR
: case CLASS
: case CONST
:
2745 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2746 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2747 case UNION
: case UNSIGNED
: case VOID
: case VOLATILE
:
2748 case TYPEDEF
: case STATIC
: case T_INLINE
: case FRIEND
:
2749 case VIRTUAL
: case TEMPLATE
: case IDENT
: case '~':
2750 case BOOL
: case WCHAR
: case EXPLICIT
: case MUTABLE
:
2762 /* Parse a qualified identifier. Current lookahead is IDENT. A
2763 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
2764 symbol for that class. */
2767 parse_classname (void)
2769 struct sym
*last_class
= NULL
;
2771 while (LOOKING_AT (IDENT
))
2773 last_class
= add_sym (yytext
, last_class
);
2776 if (LOOKING_AT ('<'))
2779 set_flag (&last_class
->flags
, F_TEMPLATE
);
2782 if (!LOOKING_AT (DCOLON
))
2792 /* Parse an operator name. Add the `static' flag to *SC if an
2793 implicitly static operator has been parsed. Value is a pointer to
2794 a static buffer holding the constructed operator name string. */
2797 operator_name (int *sc
)
2799 static size_t id_size
= 0;
2800 static char *id
= NULL
;
2806 if (LOOKING_AT2 (NEW
, DELETE
))
2808 /* `new' and `delete' are implicitly static. */
2809 if (*sc
!= SC_FRIEND
)
2812 s
= token_string (LA1
);
2815 ptrdiff_t slen
= strlen (s
);
2819 size_t new_size
= max (len
, 2 * id_size
);
2820 id
= (char *) xrealloc (id
, new_size
);
2823 char *z
= stpcpy (id
, s
);
2825 /* Vector new or delete? */
2826 if (LOOKING_AT ('['))
2828 z
= stpcpy (z
, "[");
2831 if (LOOKING_AT (']'))
2840 size_t tokens_matched
= 0;
2845 int new_size
= max (len
, 2 * id_size
);
2846 id
= (char *) xrealloc (id
, new_size
);
2849 char *z
= stpcpy (id
, "operator");
2851 /* Beware access declarations of the form "X::f;" Beware of
2852 `operator () ()'. Yet another difficulty is found in
2853 GCC 2.95's STL: `operator == __STL_NULL_TMPL_ARGS (...'. */
2854 while (!(LOOKING_AT ('(') && tokens_matched
)
2855 && !LOOKING_AT2 (';', YYEOF
))
2857 s
= token_string (LA1
);
2858 len
+= strlen (s
) + 2;
2861 ptrdiff_t idlen
= z
- id
;
2862 size_t new_size
= max (len
, 2 * id_size
);
2863 id
= (char *) xrealloc (id
, new_size
);
2868 if (*s
!= ')' && *s
!= ']')
2873 /* If this is a simple operator like `+', stop now. */
2874 if (!isalpha ((unsigned char) *s
) && *s
!= '(' && *s
!= '[')
2885 /* This one consumes the last IDENT of a qualified member name like
2886 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2887 symbol structure for the ident. */
2890 parse_qualified_ident_or_type (char **last_id
)
2892 struct sym
*cls
= NULL
;
2897 while (LOOKING_AT (IDENT
))
2899 int len
= strlen (yytext
) + 1;
2902 id
= (char *) xrealloc (id
, len
);
2905 strcpy (id
, yytext
);
2909 SKIP_MATCHING_IF ('<');
2911 if (LOOKING_AT (DCOLON
))
2913 struct sym
*pcn
= NULL
;
2914 struct link
*pna
= check_namespace_alias (id
);
2919 enter_namespace (pna
->sym
->name
);
2925 else if ((pcn
= check_namespace (id
, current_namespace
)))
2927 enter_namespace (pcn
->name
);
2931 cls
= add_sym (id
, cls
);
2950 /* This one consumes the last IDENT of a qualified member name like
2951 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2952 symbol structure for the ident. */
2955 parse_qualified_param_ident_or_type (char **last_id
)
2957 struct sym
*cls
= NULL
;
2958 static char *id
= NULL
;
2959 static int id_size
= 0;
2961 assert (LOOKING_AT (IDENT
));
2965 int len
= strlen (yytext
) + 1;
2968 id
= (char *) xrealloc (id
, len
);
2971 strcpy (id
, yytext
);
2975 SKIP_MATCHING_IF ('<');
2977 if (LOOKING_AT (DCOLON
))
2979 cls
= add_sym (id
, cls
);
2986 while (LOOKING_AT (IDENT
));
2990 /* Parse a class definition.
2992 CONTAINING is the class containing the class being parsed or null.
2993 This may also be null if NESTED != 0 if the containing class is
2994 anonymous. TAG is the tag of the class (struct, union, class).
2995 NESTED is non-zero if we are parsing a nested class.
2997 Current lookahead is the class name. */
3000 class_definition (struct sym
*containing
, int tag
, int flags
, int nested
)
3002 struct sym
*current
;
3003 struct sym
*base_class
;
3005 /* Set CURRENT to null if no entry has to be made for the class
3006 parsed. This is the case for certain command line flag
3008 if ((tag
!= CLASS
&& !f_structs
) || (nested
&& !f_nested_classes
))
3012 current
= add_sym (yytext
, containing
);
3013 current
->pos
= BUFFER_POS ();
3014 current
->regexp
= matching_regexp ();
3015 current
->filename
= filename
;
3016 current
->flags
= flags
;
3019 /* If at ':', base class list follows. */
3020 if (LOOKING_AT (':'))
3029 case VIRTUAL
: case PUBLIC
: case PROTECTED
: case PRIVATE
:
3034 base_class
= parse_classname ();
3035 if (base_class
&& current
&& base_class
!= current
)
3036 add_link (base_class
, current
);
3039 /* The `,' between base classes or the end of the base
3040 class list. Add the previously found base class.
3041 It's done this way to skip over sequences of
3042 `A::B::C' until we reach the end.
3044 FIXME: it is now possible to handle `class X : public B::X'
3045 because we have enough information. */
3051 /* A syntax error, possibly due to preprocessor constructs
3057 class A : private B.
3059 MATCH until we see something like `;' or `{'. */
3060 while (!LOOKING_AT3 (';', YYEOF
, '{'))
3070 /* Parse the class body if there is one. */
3071 if (LOOKING_AT ('{'))
3073 if (tag
!= CLASS
&& !f_structs
)
3078 class_body (current
, tag
);
3080 if (LOOKING_AT ('}'))
3083 if (LOOKING_AT (';') && !nested
)
3090 /* Add to class *CLS information for the declaration of variable or
3091 type *ID. If *CLS is null, this means a global declaration. SC is
3092 the storage class of *ID. FLAGS is a bit set giving additional
3093 information about the member (see the F_* defines). */
3096 add_declarator (struct sym
**cls
, char **id
, int flags
, int sc
)
3098 if (LOOKING_AT2 (';', ','))
3100 /* The end of a member variable or of an access declaration
3101 `X::f'. To distinguish between them we have to know whether
3102 type information has been seen. */
3105 char *regexp
= matching_regexp ();
3106 int pos
= BUFFER_POS ();
3109 add_member_defn (*cls
, *id
, regexp
, pos
, 0, 1, SC_UNKNOWN
, flags
);
3111 add_global_defn (*id
, regexp
, pos
, 0, 1, sc
, flags
);
3117 else if (LOOKING_AT ('{'))
3119 if (sc
== SC_TYPE
&& *id
)
3121 /* A named enumeration. */
3122 char *regexp
= matching_regexp ();
3123 int pos
= BUFFER_POS ();
3124 add_global_defn (*id
, regexp
, pos
, 0, 1, sc
, flags
);
3136 /* Parse a declaration. */
3139 declaration (int flags
)
3142 struct sym
*cls
= NULL
;
3143 char *regexp
= NULL
;
3149 while (!LOOKING_AT3 (';', '{', YYEOF
))
3172 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
3173 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
3174 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
3178 case CLASS
: case STRUCT
: case UNION
:
3179 /* This is for the case `STARTWRAP class X : ...' or
3180 `declare (X, Y)\n class A : ...'. */
3188 /* Assumed to be the start of an initialization in this
3190 skip_initializer ();
3194 add_declarator (&cls
, &id
, flags
, sc
);
3199 char *s
= operator_name (&sc
);
3200 id
= (char *) xrealloc (id
, strlen (s
) + 1);
3206 set_flag (&flags
, F_INLINE
);
3212 if (LOOKING_AT (IDENT
))
3214 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
3216 strcpy (id
+ 1, yytext
);
3222 cls
= parse_qualified_ident_or_type (&id
);
3226 /* Most probably the beginning of a parameter list. */
3233 if (!(is_constructor
= streq (id
, cls
->name
)))
3234 regexp
= matching_regexp ();
3239 pos
= BUFFER_POS ();
3240 hash
= parm_list (&flags
);
3243 regexp
= matching_regexp ();
3246 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0,
3251 /* This may be a C functions, but also a macro
3252 call of the form `declare (A, B)' --- such macros
3253 can be found in some class libraries. */
3258 regexp
= matching_regexp ();
3259 pos
= BUFFER_POS ();
3260 hash
= parm_list (&flags
);
3261 add_global_decl (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3264 /* This is for the case that the function really is
3265 a macro with no `;' following it. If a CLASS directly
3266 follows, we would miss it otherwise. */
3267 if (LOOKING_AT3 (CLASS
, STRUCT
, UNION
))
3271 while (!LOOKING_AT3 (';', '{', YYEOF
))
3274 if (!cls
&& id
&& LOOKING_AT ('{'))
3275 add_global_defn (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3283 add_declarator (&cls
, &id
, flags
, sc
);
3287 /* Parse a list of top-level declarations/definitions. START_FLAGS
3288 says in which context we are parsing. If it is F_EXTERNC, we are
3289 parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0
3293 globals (int start_flags
)
3297 int flags
= start_flags
;
3309 if (LOOKING_AT (IDENT
))
3311 char *namespace_name
= xstrdup (yytext
);
3314 if (LOOKING_AT ('='))
3316 struct link
*qna
= match_qualified_namespace_alias ();
3318 register_namespace_alias (namespace_name
, qna
);
3320 if (skip_to (';') == ';')
3323 else if (LOOKING_AT ('{'))
3326 enter_namespace (namespace_name
);
3332 free (namespace_name
);
3339 if (LOOKING_AT (CSTRING
) && *string_start
== 'C'
3340 && *(string_start
+ 1) == '"')
3342 /* This is `extern "C"'. */
3345 if (LOOKING_AT ('{'))
3348 globals (F_EXTERNC
);
3352 set_flag (&flags
, F_EXTERNC
);
3358 SKIP_MATCHING_IF ('<');
3359 set_flag (&flags
, F_TEMPLATE
);
3362 case CLASS
: case STRUCT
: case UNION
:
3367 /* More than one ident here to allow for MS-DOS and OS/2
3368 specialties like `far', `_Export' etc. Some C++ libs
3369 have constructs like `_OS_DLLIMPORT(_OS_CLIENT)' in front
3370 of the class name. */
3371 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
3373 if (LOOKING_AT (IDENT
))
3378 /* Don't add anonymous unions. */
3379 if (LOOKING_AT2 (':', '{') && !anonymous
)
3380 class_definition (NULL
, class_tk
, flags
, 0);
3383 if (skip_to (';') == ';')
3387 flags
= start_flags
;
3397 declaration (flags
);
3398 flags
= start_flags
;
3403 yyerror ("parse error", NULL
);
3408 /* Parse the current input file. */
3413 while (globals (0) == 0)
3419 /***********************************************************************
3421 ***********************************************************************/
3423 /* Add the list of paths PATH_LIST to the current search path for
3427 add_search_path (char *path_list
)
3431 char *start
= path_list
;
3432 struct search_path
*p
;
3434 while (*path_list
&& *path_list
!= SEPCHAR
)
3437 p
= (struct search_path
*) xmalloc (sizeof *p
);
3438 p
->path
= (char *) xmalloc (path_list
- start
+ 1);
3439 memcpy (p
->path
, start
, path_list
- start
);
3440 p
->path
[path_list
- start
] = '\0';
3443 if (search_path_tail
)
3445 search_path_tail
->next
= p
;
3446 search_path_tail
= p
;
3449 search_path
= search_path_tail
= p
;
3451 while (*path_list
== SEPCHAR
)
3457 /* Open FILE and return a file handle for it, or -1 if FILE cannot be
3458 opened. Try to find FILE in search_path first, then try the
3459 unchanged file name. */
3462 open_file (char *file
)
3465 static char *buffer
;
3466 static int buffer_size
;
3467 struct search_path
*path
;
3468 int flen
= strlen (file
) + 1; /* +1 for the slash */
3470 filename
= xstrdup (file
);
3472 for (path
= search_path
; path
&& fp
== NULL
; path
= path
->next
)
3474 int len
= strlen (path
->path
) + flen
;
3476 if (len
+ 1 >= buffer_size
)
3478 buffer_size
= max (len
+ 1, 2 * buffer_size
);
3479 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3482 char *z
= stpcpy (buffer
, path
->path
);
3485 fp
= fopen (buffer
, "r");
3488 /* Try the original file name. */
3490 fp
= fopen (file
, "r");
3493 yyerror ("cannot open", NULL
);
3499 /* Display usage information and exit program. */
3501 static char const *const usage_message
[] =
3504 Usage: ebrowse [options] {files}\n\
3506 -a, --append append output to existing file\n\
3507 -f, --files=FILES read input file names from FILE\n\
3508 -I, --search-path=LIST set search path for input files\n\
3509 -m, --min-regexp-length=N set minimum regexp length to N\n\
3510 -M, --max-regexp-length=N set maximum regexp length to N\n\
3513 -n, --no-nested-classes exclude nested classes\n\
3514 -o, --output-file=FILE set output file name to FILE\n\
3515 -p, --position-info print info about position in file\n\
3516 -s, --no-structs-or-unions don't record structs or unions\n\
3517 -v, --verbose be verbose\n\
3518 -V, --very-verbose be very verbose\n\
3519 -x, --no-regexps don't record regular expressions\n\
3520 --help display this help\n\
3521 --version display version info\n\
3526 static _Noreturn
void
3530 for (i
= 0; i
< sizeof usage_message
/ sizeof *usage_message
; i
++)
3531 fputs (usage_message
[i
], stdout
);
3532 exit (error
? EXIT_FAILURE
: EXIT_SUCCESS
);
3536 /* Display version and copyright info. The VERSION macro is set
3537 from config.h and contains the Emacs version. */
3540 # define VERSION "21"
3543 static _Noreturn
void
3546 char emacs_copyright
[] = COPYRIGHT
;
3548 printf ("ebrowse %s\n", VERSION
);
3549 puts (emacs_copyright
);
3550 puts ("This program is distributed under the same terms as Emacs.");
3551 exit (EXIT_SUCCESS
);
3555 /* Parse one input file FILE, adding classes and members to the symbol
3559 process_file (char *file
)
3563 fp
= open_file (file
);
3566 size_t nread
, nbytes
;
3568 /* Give a progress indication if needed. */
3580 /* Read file to inbuffer. */
3583 if (nread
+ READ_CHUNK_SIZE
>= inbuffer_size
)
3585 inbuffer_size
= nread
+ READ_CHUNK_SIZE
+ 1;
3586 inbuffer
= (char *) xrealloc (inbuffer
, inbuffer_size
);
3589 nbytes
= fread (inbuffer
+ nread
, 1, READ_CHUNK_SIZE
, fp
);
3594 inbuffer
[nread
] = '\0';
3596 /* Reinitialize scanner and parser for the new input file. */
3600 /* Parse it and close the file. */
3607 /* Read a line from stream FP and return a pointer to a static buffer
3608 containing its contents without the terminating newline. Value
3609 is null when EOF is reached. */
3612 read_line (FILE *fp
)
3614 static char *buffer
;
3615 static int buffer_size
;
3618 while ((c
= getc (fp
)) != EOF
&& c
!= '\n')
3620 if (i
>= buffer_size
)
3622 buffer_size
= max (100, buffer_size
* 2);
3623 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3629 if (c
== EOF
&& i
== 0)
3632 if (i
== buffer_size
)
3634 buffer_size
= max (100, buffer_size
* 2);
3635 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3639 if (i
> 0 && buffer
[i
- 1] == '\r')
3640 buffer
[i
- 1] = '\0';
3645 /* Main entry point. */
3648 main (int argc
, char **argv
)
3651 int any_inputfiles
= 0;
3652 static const char *out_filename
= DEFAULT_OUTFILE
;
3653 static char **input_filenames
= NULL
;
3654 static int input_filenames_size
= 0;
3655 static int n_input_files
;
3657 filename
= "command line";
3660 while ((i
= getopt_long (argc
, argv
, "af:I:m:M:no:p:svVx",
3661 options
, NULL
)) != EOF
)
3667 info_position
= atoi (optarg
);
3671 f_nested_classes
= 0;
3678 /* Add the name of a file containing more input files. */
3680 if (n_input_files
== input_filenames_size
)
3682 input_filenames_size
= max (10, 2 * input_filenames_size
);
3683 input_filenames
= (char **) xrealloc ((void *)input_filenames
,
3684 input_filenames_size
);
3686 input_filenames
[n_input_files
++] = xstrdup (optarg
);
3689 /* Append new output to output file instead of truncating it. */
3694 /* Include structs in the output */
3699 /* Be verbose (give a progress indication). */
3704 /* Be very verbose (print file names as they are processed). */
3710 /* Change the name of the output file. */
3712 out_filename
= optarg
;
3715 /* Set minimum length for regular expression strings
3716 when recorded in the output file. */
3718 min_regexp
= atoi (optarg
);
3721 /* Set maximum length for regular expression strings
3722 when recorded in the output file. */
3724 max_regexp
= atoi (optarg
);
3727 /* Add to search path. */
3729 add_search_path (optarg
);
3743 /* Call init_scanner after command line flags have been processed to be
3744 able to add keywords depending on command line (not yet
3749 /* Open output file */
3754 /* Check that the file to append to exists, and is not
3755 empty. More specifically, it should be a valid file
3756 produced by a previous run of ebrowse, but that's too
3757 difficult to check. */
3761 fp
= fopen (out_filename
, "r");
3764 yyerror ("file '%s' must exist for --append", out_filename
);
3765 exit (EXIT_FAILURE
);
3768 rc
= fseek (fp
, 0, SEEK_END
);
3771 yyerror ("error seeking in file '%s'", out_filename
);
3772 exit (EXIT_FAILURE
);
3778 yyerror ("error getting size of file '%s'", out_filename
);
3779 exit (EXIT_FAILURE
);
3784 yyerror ("file '%s' is empty", out_filename
);
3785 /* It may be ok to use an empty file for appending.
3786 exit (EXIT_FAILURE); */
3792 yyout
= fopen (out_filename
, f_append
? "a" : "w");
3795 yyerror ("cannot open output file '%s'", out_filename
);
3796 exit (EXIT_FAILURE
);
3800 /* Process input files specified on the command line. */
3801 while (optind
< argc
)
3803 process_file (argv
[optind
++]);
3807 /* Process files given on stdin if no files specified. */
3808 if (!any_inputfiles
&& n_input_files
== 0)
3811 while ((file
= read_line (stdin
)) != NULL
)
3812 process_file (file
);
3816 /* Process files from `--files=FILE'. Every line in FILE names
3817 one input file to process. */
3818 for (i
= 0; i
< n_input_files
; ++i
)
3820 FILE *fp
= fopen (input_filenames
[i
], "r");
3823 yyerror ("cannot open input file '%s'", input_filenames
[i
]);
3827 while ((file
= read_line (fp
)) != NULL
)
3828 process_file (file
);
3834 /* Write output file. */
3837 /* Close output file. */
3838 if (yyout
!= stdout
)
3841 return EXIT_SUCCESS
;
3844 /* ebrowse.c ends here */