1 /* ebrowse.c --- parsing files for the ebrowse C++ browser
3 Copyright (C) 1992-2016 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 <http://www.gnu.org/licenses/>. */
30 /* The SunOS compiler doesn't have SEEK_END. */
37 /* Files are read in chunks of this number of bytes. */
39 enum { READ_CHUNK_SIZE
= 100 * 1024 };
41 /* Value is true if strings X and Y compare equal. */
44 streq (char const *x
, char const *y
)
46 return strcmp (x
, y
) == 0;
50 filename_eq (char const *x
, char const *y
)
53 return strcasecmp (x
, y
) == 0;
54 #elif defined WINDOWSNT
55 return stricmp (x
, y
) == 0;
61 /* The default output file name. */
63 #define DEFAULT_OUTFILE "BROWSE"
65 /* A version string written to the output file. Change this whenever
66 the structure of the output file changes. */
68 #define EBROWSE_FILE_VERSION "ebrowse 5.0"
70 /* The output file consists of a tree of Lisp objects, with major
71 nodes built out of Lisp structures. These are the heads of the
72 Lisp structs with symbols identifying their type. */
74 #define TREE_HEADER_STRUCT "[ebrowse-hs "
75 #define TREE_STRUCT "[ebrowse-ts "
76 #define MEMBER_STRUCT "[ebrowse-ms "
77 #define CLASS_STRUCT "[ebrowse-cs "
79 /* The name of the symbol table entry for global functions, variables,
80 defines etc. This name also appears in the browser display. */
82 #define GLOBALS_NAME "*Globals*"
84 /* Token definitions. */
88 YYEOF
= 0, /* end of file */
89 CSTRING
= 256, /* string constant */
90 CCHAR
, /* character constant */
91 CINT
, /* integral constant */
92 CFLOAT
, /* real constant */
98 IDENT
, /* identifier */
121 /* Keywords. The undef's are there because these
122 three symbols are very likely to be defined somewhere. */
135 CONTINUE
, /* continue */
136 DEFAULT
, /* default */
148 T_INLINE
, /* inline */
152 OPERATOR
, /* operator */
153 PRIVATE
, /* private */
154 PROTECTED
, /* protected */
156 REGISTER
, /* register */
164 TEMPLATE
, /* template */
168 TYPEDEF
, /* typedef */
170 UNSIGNED
, /* unsigned */
171 VIRTUAL
, /* virtual */
173 VOLATILE
, /* volatile */
175 MUTABLE
, /* mutable */
179 SIGNATURE
, /* signature (GNU extension) */
180 NAMESPACE
, /* namespace */
181 EXPLICIT
, /* explicit */
182 TYPENAME
, /* typename */
183 CONST_CAST
, /* const_cast */
184 DYNAMIC_CAST
, /* dynamic_cast */
185 REINTERPRET_CAST
, /* reinterpret_cast */
186 STATIC_CAST
, /* static_cast */
192 /* Storage classes, in a wider sense. */
197 SC_MEMBER
, /* Is an instance member. */
198 SC_STATIC
, /* Is static member. */
199 SC_FRIEND
, /* Is friend function. */
200 SC_TYPE
/* Is a type definition. */
203 /* Member visibility. */
214 #define F_VIRTUAL 1 /* Is virtual function. */
215 #define F_INLINE 2 /* Is inline function. */
216 #define F_CONST 4 /* Is const. */
217 #define F_PURE 8 /* Is pure virtual function. */
218 #define F_MUTABLE 16 /* Is mutable. */
219 #define F_TEMPLATE 32 /* Is a template. */
220 #define F_EXPLICIT 64 /* Is explicit constructor. */
221 #define F_THROW 128 /* Has a throw specification. */
222 #define F_EXTERNC 256 /* Is declared extern "C". */
223 #define F_DEFINE 512 /* Is a #define. */
225 /* Set and test a bit in an int. */
228 set_flag (int *f
, int flag
)
234 has_flag (int f
, int flag
)
236 return (f
& flag
) != 0;
239 /* Structure describing a class member. */
243 struct member
*next
; /* Next in list of members. */
244 struct member
*anext
; /* Collision chain in member_table. */
245 struct member
**list
; /* Pointer to list in class. */
246 unsigned param_hash
; /* Hash value for parameter types. */
247 int vis
; /* Visibility (public, ...). */
248 int flags
; /* See F_* above. */
249 char *regexp
; /* Matching regular expression. */
250 const char *filename
; /* Don't free this shared string. */
251 int pos
; /* Buffer position of occurrence. */
252 char *def_regexp
; /* Regular expression matching definition. */
253 const char *def_filename
; /* File name of definition. */
254 int def_pos
; /* Buffer position of definition. */
255 char name
[FLEXIBLE_ARRAY_MEMBER
]; /* Member name. */
258 /* Structures of this type are used to connect class structures with
259 their super and subclasses. */
263 struct sym
*sym
; /* The super or subclass. */
264 struct link
*next
; /* Next in list or NULL. */
267 /* Structure used to record namespace aliases. */
271 struct alias
*next
; /* Next in list. */
272 struct sym
*namesp
; /* Namespace in which defined. */
273 struct link
*aliasee
; /* List of aliased namespaces (A::B::C...). */
274 char name
[FLEXIBLE_ARRAY_MEMBER
]; /* Alias name. */
277 /* The structure used to describe a class in the symbol table,
278 or a namespace in all_namespaces. */
282 int flags
; /* Is class a template class?. */
283 unsigned char visited
; /* Used to find circles. */
284 struct sym
*next
; /* Hash collision list. */
285 struct link
*subs
; /* List of subclasses. */
286 struct link
*supers
; /* List of superclasses. */
287 struct member
*vars
; /* List of instance variables. */
288 struct member
*fns
; /* List of instance functions. */
289 struct member
*static_vars
; /* List of static variables. */
290 struct member
*static_fns
; /* List of static functions. */
291 struct member
*friends
; /* List of friend functions. */
292 struct member
*types
; /* List of local types. */
293 char *regexp
; /* Matching regular expression. */
294 int pos
; /* Buffer position. */
295 const char *filename
; /* File in which it can be found. */
296 const char *sfilename
; /* File in which members can be found. */
297 struct sym
*namesp
; /* Namespace in which defined. . */
298 char name
[FLEXIBLE_ARRAY_MEMBER
]; /* Name of the class. */
301 /* Experimental: Print info for `--position-info'. We print
302 '(CLASS-NAME SCOPE MEMBER-NAME). */
308 struct sym
*info_cls
= NULL
;
309 struct member
*info_member
= NULL
;
311 /* Experimental. For option `--position-info', the buffer position we
312 are interested in. When this position is reached, print out
313 information about what we know about that point. */
315 int info_position
= -1;
317 /* Command line options structure for getopt_long. */
319 struct option options
[] =
321 {"append", no_argument
, NULL
, 'a'},
322 {"files", required_argument
, NULL
, 'f'},
323 {"help", no_argument
, NULL
, -2},
324 {"min-regexp-length", required_argument
, NULL
, 'm'},
325 {"max-regexp-length", required_argument
, NULL
, 'M'},
326 {"no-nested-classes", no_argument
, NULL
, 'n'},
327 {"no-regexps", no_argument
, NULL
, 'x'},
328 {"no-structs-or-unions", no_argument
, NULL
, 's'},
329 {"output-file", required_argument
, NULL
, 'o'},
330 {"position-info", required_argument
, NULL
, 'p'},
331 {"search-path", required_argument
, NULL
, 'I'},
332 {"verbose", no_argument
, NULL
, 'v'},
333 {"version", no_argument
, NULL
, -3},
334 {"very-verbose", no_argument
, NULL
, 'V'},
338 /* Semantic values of tokens. Set by yylex.. */
340 unsigned yyival
; /* Set for token CINT. */
341 char *yytext
; /* Set for token IDENT. */
348 /* Current line number. */
352 /* The name of the current input file. */
354 const char *filename
;
356 /* Three character class vectors, and macros to test membership
363 #define IDENTP(C) is_ident[(unsigned char) (C)]
364 #define DIGITP(C) is_digit[(unsigned char) (C)]
365 #define WHITEP(C) is_white[(unsigned char) (C)]
367 /* Command line flags. */
374 int f_nested_classes
= 1;
376 /* Maximum and minimum lengths of regular expressions matching a
377 member, class etc., for writing them to the output file. These are
378 overridable from the command line. */
387 size_t inbuffer_size
;
389 /* Return the current buffer position in the input file. */
391 #define BUFFER_POS() (in - inbuffer)
393 /* If current lookahead is CSTRING, the following points to the
394 first character in the string constant. Used for recognizing
399 /* The size of the hash tables for classes.and members. Should be
402 #define TABLE_SIZE 1001
404 /* The hash table for class symbols. */
406 struct sym
*class_table
[TABLE_SIZE
];
408 /* Hash table containing all member structures. This is generally
409 faster for member lookup than traversing the member lists of a
412 struct member
*member_table
[TABLE_SIZE
];
414 /* Hash table for namespace aliases */
416 struct alias
*namespace_alias_table
[TABLE_SIZE
];
418 /* The special class symbol used to hold global functions,
421 struct sym
*global_symbols
;
423 /* The current namespace. */
425 struct sym
*current_namespace
;
427 /* The list of all known namespaces. */
429 struct sym
*all_namespaces
;
431 /* Stack of namespaces we're currently nested in, during the parse. */
433 struct sym
**namespace_stack
;
434 int namespace_stack_size
;
437 /* The current lookahead token. */
441 /* Structure describing a keyword. */
445 const char *name
; /* Spelling. */
446 int tk
; /* Token value. */
447 struct kw
*next
; /* Next in collision chain. */
450 /* Keywords are lookup up in a hash table of their own. */
452 #define KEYWORD_TABLE_SIZE 1001
453 struct kw
*keyword_table
[KEYWORD_TABLE_SIZE
];
460 struct search_path
*next
;
463 struct search_path
*search_path
;
464 struct search_path
*search_path_tail
;
466 /* Function prototypes. */
468 static char *matching_regexp (void);
469 static struct sym
*add_sym (const char *, struct sym
*);
470 static void add_global_defn (char *, char *, int, unsigned, int, int, int);
471 static void add_global_decl (char *, char *, int, unsigned, int, int, int);
472 static struct member
*add_member (struct sym
*, char *, int, int, unsigned);
473 static void class_definition (struct sym
*, int, int, int);
474 static char *operator_name (int *);
475 static void parse_qualified_param_ident_or_type (char **);
477 /***********************************************************************
479 ***********************************************************************/
481 /* Print an error in a printf-like style with the current input file
482 name and line number. */
485 yyerror (const char *format
, const char *s
)
487 fprintf (stderr
, "%s:%d: ", filename
, yyline
);
488 fprintf (stderr
, format
, s
);
493 /* Like malloc but print an error and exit if not enough memory is
497 xmalloc (size_t nbytes
)
499 void *p
= malloc (nbytes
);
502 yyerror ("out of memory", NULL
);
509 /* Like realloc but print an error and exit if out of memory. */
512 xrealloc (void *p
, size_t sz
)
517 yyerror ("out of memory", NULL
);
524 /* Like strdup, but print an error and exit if not enough memory is
525 available.. If S is null, return null. */
531 return strcpy (xmalloc (strlen (s
) + 1), s
);
537 /***********************************************************************
539 ***********************************************************************/
541 /* Initialize the symbol table. This currently only sets up the
542 special symbol for globals (`*Globals*'). */
547 global_symbols
= add_sym (GLOBALS_NAME
, NULL
);
551 /* Add a symbol for class NAME to the symbol table. NESTED_IN_CLASS
552 is the class in which class NAME was found. If it is null,
553 this means the scope of NAME is the current namespace.
555 If a symbol for NAME already exists, return that. Otherwise
556 create a new symbol and set it to default values. */
559 add_sym (const char *name
, struct sym
*nested_in_class
)
564 struct sym
*scope
= nested_in_class
? nested_in_class
: current_namespace
;
566 for (s
= name
, h
= 0; *s
; ++s
)
570 for (sym
= class_table
[h
]; sym
; sym
= sym
->next
)
571 if (streq (name
, sym
->name
)
572 && ((!sym
->namesp
&& !scope
)
573 || (sym
->namesp
&& scope
574 && streq (sym
->namesp
->name
, scope
->name
))))
585 sym
= xmalloc (offsetof (struct sym
, name
) + strlen (name
) + 1);
586 memset (sym
, 0, offsetof (struct sym
, name
));
587 strcpy (sym
->name
, name
);
589 sym
->next
= class_table
[h
];
590 class_table
[h
] = sym
;
597 /* Add links between superclass SUPER and subclass SUB. */
600 add_link (struct sym
*super
, struct sym
*sub
)
602 struct link
*lnk
, *lnk2
, *p
, *prev
;
604 /* See if a link already exists. */
605 for (p
= super
->subs
, prev
= NULL
;
606 p
&& strcmp (sub
->name
, p
->sym
->name
) > 0;
607 prev
= p
, p
= p
->next
)
610 /* Avoid duplicates. */
611 if (p
== NULL
|| p
->sym
!= sub
)
613 lnk
= (struct link
*) xmalloc (sizeof *lnk
);
614 lnk2
= (struct link
*) xmalloc (sizeof *lnk2
);
625 lnk2
->next
= sub
->supers
;
631 /* Find in class CLS member NAME.
633 VAR non-zero means look for a member variable; otherwise a function
634 is searched. SC specifies what kind of member is searched---a
635 static, or per-instance member etc. HASH is a hash code for the
636 parameter types of functions. Value is a pointer to the member
637 found or null if not found. */
639 static struct member
*
640 find_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
642 struct member
**list
;
644 unsigned name_hash
= 0;
651 list
= &cls
->friends
;
659 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
663 list
= var
? &cls
->vars
: &cls
->fns
;
667 for (s
= name
; *s
; ++s
)
668 name_hash
= (name_hash
<< 1) ^ *s
;
669 i
= name_hash
% TABLE_SIZE
;
671 for (p
= member_table
[i
]; p
; p
= p
->anext
)
672 if (p
->list
== list
&& p
->param_hash
== hash
&& streq (name
, p
->name
))
679 /* Add to class CLS information for the declaration of member NAME.
680 REGEXP is a regexp matching the declaration, if non-null. POS is
681 the position in the source where the declaration is found. HASH is
682 a hash code for the parameter list of the member, if it's a
683 function. VAR non-zero means member is a variable or type. SC
684 specifies the type of member (instance member, static, ...). VIS
685 is the member's visibility (public, protected, private). FLAGS is
686 a bit set giving additional information about the member (see the
690 add_member_decl (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int vis
, int flags
)
694 m
= find_member (cls
, name
, var
, sc
, hash
);
696 m
= add_member (cls
, name
, var
, sc
, hash
);
698 /* Have we seen a new filename? If so record that. */
699 if (!cls
->filename
|| !filename_eq (cls
->filename
, filename
))
700 m
->filename
= filename
;
713 m
->vis
= V_PROTECTED
;
727 /* Add to class CLS information for the definition of member NAME.
728 REGEXP is a regexp matching the declaration, if non-null. POS is
729 the position in the source where the declaration is found. HASH is
730 a hash code for the parameter list of the member, if it's a
731 function. VAR non-zero means member is a variable or type. SC
732 specifies the type of member (instance member, static, ...). VIS
733 is the member's visibility (public, protected, private). FLAGS is
734 a bit set giving additional information about the member (see the
738 add_member_defn (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
742 if (sc
== SC_UNKNOWN
)
744 m
= find_member (cls
, name
, var
, SC_MEMBER
, hash
);
747 m
= find_member (cls
, name
, var
, SC_STATIC
, hash
);
749 m
= add_member (cls
, name
, var
, sc
, hash
);
754 m
= find_member (cls
, name
, var
, sc
, hash
);
756 m
= add_member (cls
, name
, var
, sc
, hash
);
760 cls
->sfilename
= filename
;
762 if (!filename_eq (cls
->sfilename
, filename
))
763 m
->def_filename
= filename
;
765 m
->def_regexp
= regexp
;
775 /* Add a symbol for a define named NAME to the symbol table.
776 REGEXP is a regular expression matching the define in the source,
777 if it is non-null. POS is the position in the file. */
780 add_define (char *name
, char *regexp
, int pos
)
782 add_global_defn (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
783 add_global_decl (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
787 /* Add information for the global definition of NAME.
788 REGEXP is a regexp matching the declaration, if non-null. POS is
789 the position in the source where the declaration is found. HASH is
790 a hash code for the parameter list of the member, if it's a
791 function. VAR non-zero means member is a variable or type. SC
792 specifies the type of member (instance member, static, ...). VIS
793 is the member's visibility (public, protected, private). FLAGS is
794 a bit set giving additional information about the member (see the
798 add_global_defn (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
803 /* Try to find out for which classes a function is a friend, and add
804 what we know about it to them. */
806 for (i
= 0; i
< TABLE_SIZE
; ++i
)
807 for (sym
= class_table
[i
]; sym
; sym
= sym
->next
)
808 if (sym
!= global_symbols
&& sym
->friends
)
809 if (find_member (sym
, name
, 0, SC_FRIEND
, hash
))
810 add_member_defn (sym
, name
, regexp
, pos
, hash
, 0,
813 /* Add to global symbols. */
814 add_member_defn (global_symbols
, name
, regexp
, pos
, hash
, var
, sc
, flags
);
818 /* Add information for the global declaration of NAME.
819 REGEXP is a regexp matching the declaration, if non-null. POS is
820 the position in the source where the declaration is found. HASH is
821 a hash code for the parameter list of the member, if it's a
822 function. VAR non-zero means member is a variable or type. SC
823 specifies the type of member (instance member, static, ...). VIS
824 is the member's visibility (public, protected, private). FLAGS is
825 a bit set giving additional information about the member (see the
829 add_global_decl (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
831 /* Add declaration only if not already declared. Header files must
832 be processed before source files for this to have the right effect.
833 I do not want to handle implicit declarations at the moment. */
835 struct member
*found
;
837 m
= found
= find_member (global_symbols
, name
, var
, sc
, hash
);
839 m
= add_member (global_symbols
, name
, var
, sc
, hash
);
841 /* Definition already seen => probably last declaration implicit.
842 Override. This means that declarations must always be added to
843 the symbol table before definitions. */
846 if (!global_symbols
->filename
847 || !filename_eq (global_symbols
->filename
, filename
))
848 m
->filename
= filename
;
856 info_cls
= global_symbols
;
862 /* Add a symbol for member NAME to class CLS.
863 VAR non-zero means it's a variable. SC specifies the kind of
864 member. HASH is a hash code for the parameter types of a function.
865 Value is a pointer to the member's structure. */
867 static struct member
*
868 add_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
870 struct member
*m
= xmalloc (offsetof (struct member
, name
)
871 + strlen (name
) + 1);
872 struct member
**list
;
875 unsigned name_hash
= 0;
879 strcpy (m
->name
, name
);
880 m
->param_hash
= hash
;
887 m
->def_regexp
= NULL
;
888 m
->def_filename
= NULL
;
891 assert (cls
!= NULL
);
896 list
= &cls
->friends
;
904 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
908 list
= var
? &cls
->vars
: &cls
->fns
;
912 for (s
= name
; *s
; ++s
)
913 name_hash
= (name_hash
<< 1) ^ *s
;
914 i
= name_hash
% TABLE_SIZE
;
915 m
->anext
= member_table
[i
];
919 /* Keep the member list sorted. It's cheaper to do it here than to
920 sort them in Lisp. */
921 for (prev
= NULL
, p
= *list
;
922 p
&& strcmp (name
, p
->name
) > 0;
923 prev
= p
, p
= p
->next
)
935 /* Given the root R of a class tree, step through all subclasses
936 recursively, marking functions as virtual that are declared virtual
940 mark_virtual (struct sym
*r
)
943 struct member
*m
, *m2
;
945 for (p
= r
->subs
; p
; p
= p
->next
)
947 for (m
= r
->fns
; m
; m
= m
->next
)
948 if (has_flag (m
->flags
, F_VIRTUAL
))
950 for (m2
= p
->sym
->fns
; m2
; m2
= m2
->next
)
951 if (m
->param_hash
== m2
->param_hash
&& streq (m
->name
, m2
->name
))
952 set_flag (&m2
->flags
, F_VIRTUAL
);
955 mark_virtual (p
->sym
);
960 /* For all roots of the class tree, mark functions as virtual that
961 are virtual because of a virtual declaration in a base class. */
964 mark_inherited_virtual (void)
969 for (i
= 0; i
< TABLE_SIZE
; ++i
)
970 for (r
= class_table
[i
]; r
; r
= r
->next
)
971 if (r
->supers
== NULL
)
976 /* Create and return a symbol for a namespace with name NAME. */
979 make_namespace (char *name
, struct sym
*context
)
981 struct sym
*s
= xmalloc (offsetof (struct sym
, name
) + strlen (name
) + 1);
982 memset (s
, 0, offsetof (struct sym
, name
));
983 strcpy (s
->name
, name
);
984 s
->next
= all_namespaces
;
991 /* Find the symbol for namespace NAME. If not found, return NULL */
994 check_namespace (char *name
, struct sym
*context
)
996 struct sym
*p
= NULL
;
998 for (p
= all_namespaces
; p
; p
= p
->next
)
1000 if (streq (p
->name
, name
) && (p
->namesp
== context
))
1007 /* Find the symbol for namespace NAME. If not found, add a new symbol
1008 for NAME to all_namespaces. */
1011 find_namespace (char *name
, struct sym
*context
)
1013 struct sym
*p
= check_namespace (name
, context
);
1016 p
= make_namespace (name
, context
);
1022 /* Find namespace alias with name NAME. If not found return NULL. */
1024 static struct link
*
1025 check_namespace_alias (char *name
)
1027 struct link
*p
= NULL
;
1032 for (s
= name
, h
= 0; *s
; ++s
)
1036 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1037 if (streq (name
, al
->name
) && (al
->namesp
== current_namespace
))
1046 /* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */
1049 register_namespace_alias (char *new_name
, struct link
*old_name
)
1055 for (s
= new_name
, h
= 0; *s
; ++s
)
1060 /* Is it already in the table of aliases? */
1061 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1062 if (streq (new_name
, al
->name
) && (al
->namesp
== current_namespace
))
1065 al
= xmalloc (offsetof (struct alias
, name
) + strlen (new_name
) + 1);
1066 strcpy (al
->name
, new_name
);
1067 al
->next
= namespace_alias_table
[h
];
1068 al
->namesp
= current_namespace
;
1069 al
->aliasee
= old_name
;
1070 namespace_alias_table
[h
] = al
;
1074 /* Enter namespace with name NAME. */
1077 enter_namespace (char *name
)
1079 struct sym
*p
= find_namespace (name
, current_namespace
);
1081 if (namespace_sp
== namespace_stack_size
)
1083 int size
= max (10, 2 * namespace_stack_size
);
1085 = (struct sym
**) xrealloc ((void *)namespace_stack
,
1086 size
* sizeof *namespace_stack
);
1087 namespace_stack_size
= size
;
1090 namespace_stack
[namespace_sp
++] = current_namespace
;
1091 current_namespace
= p
;
1095 /* Leave the current namespace. */
1098 leave_namespace (void)
1100 assert (namespace_sp
> 0);
1101 current_namespace
= namespace_stack
[--namespace_sp
];
1106 /***********************************************************************
1107 Writing the Output File
1108 ***********************************************************************/
1110 /* Write string S to the output file FP in a Lisp-readable form.
1111 If S is null, write out `()'. */
1114 putstr (const char *s
, FILE *fp
)
1131 /* A dynamically allocated buffer for constructing a scope name. */
1134 int scope_buffer_size
;
1135 int scope_buffer_len
;
1138 /* Make sure scope_buffer has enough room to add LEN chars to it. */
1141 ensure_scope_buffer_room (int len
)
1143 if (scope_buffer_len
+ len
>= scope_buffer_size
)
1145 int new_size
= max (2 * scope_buffer_size
, scope_buffer_len
+ len
);
1146 scope_buffer
= (char *) xrealloc (scope_buffer
, new_size
);
1147 scope_buffer_size
= new_size
;
1152 /* Recursively add the scope names of symbol P and the scopes of its
1153 namespaces to scope_buffer. Value is a pointer to the complete
1154 scope name constructed. */
1157 sym_scope_1 (struct sym
*p
)
1162 sym_scope_1 (p
->namesp
);
1166 ensure_scope_buffer_room (3);
1167 strcpy (scope_buffer
+ scope_buffer_len
, "::");
1168 scope_buffer_len
+= 2;
1171 len
= strlen (p
->name
);
1172 ensure_scope_buffer_room (len
+ 1);
1173 strcpy (scope_buffer
+ scope_buffer_len
, p
->name
);
1174 scope_buffer_len
+= len
;
1176 if (has_flag (p
->flags
, F_TEMPLATE
))
1178 ensure_scope_buffer_room (3);
1179 strcpy (scope_buffer
+ scope_buffer_len
, "<>");
1180 scope_buffer_len
+= 2;
1183 return scope_buffer
;
1187 /* Return the scope of symbol P in printed representation, i.e.
1188 as it would appear in a C*+ source file. */
1191 sym_scope (struct sym
*p
)
1195 scope_buffer_size
= 1024;
1196 scope_buffer
= (char *) xmalloc (scope_buffer_size
);
1199 *scope_buffer
= '\0';
1200 scope_buffer_len
= 0;
1203 sym_scope_1 (p
->namesp
);
1205 return scope_buffer
;
1209 /* Dump the list of members M to file FP. Value is the length of the
1213 dump_members (FILE *fp
, struct member
*m
)
1219 for (n
= 0; m
; m
= m
->next
, ++n
)
1221 fputs (MEMBER_STRUCT
, fp
);
1222 putstr (m
->name
, fp
);
1223 putstr (NULL
, fp
); /* FIXME? scope for globals */
1224 fprintf (fp
, "%u ", (unsigned) m
->flags
);
1225 putstr (m
->filename
, fp
);
1226 putstr (m
->regexp
, fp
);
1227 fprintf (fp
, "%u ", (unsigned) m
->pos
);
1228 fprintf (fp
, "%u ", (unsigned) m
->vis
);
1230 putstr (m
->def_filename
, fp
);
1231 putstr (m
->def_regexp
, fp
);
1232 fprintf (fp
, "%u", (unsigned) m
->def_pos
);
1243 /* Dump class ROOT to stream FP. */
1246 dump_sym (FILE *fp
, struct sym
*root
)
1248 fputs (CLASS_STRUCT
, fp
);
1249 putstr (root
->name
, fp
);
1251 /* Print scope, if any. */
1253 putstr (sym_scope (root
), fp
);
1258 fprintf (fp
, "%d", root
->flags
);
1259 putstr (root
->filename
, fp
);
1260 putstr (root
->regexp
, fp
);
1261 fprintf (fp
, "%u", (unsigned) root
->pos
);
1262 putstr (root
->sfilename
, fp
);
1268 /* Dump class ROOT and its subclasses to file FP. Value is the
1269 number of classes written. */
1272 dump_tree (FILE *fp
, struct sym
*root
)
1277 dump_sym (fp
, root
);
1287 for (lk
= root
->subs
; lk
; lk
= lk
->next
)
1289 fputs (TREE_STRUCT
, fp
);
1290 n
+= dump_tree (fp
, lk
->sym
);
1296 dump_members (fp
, root
->vars
);
1297 n
+= dump_members (fp
, root
->fns
);
1298 dump_members (fp
, root
->static_vars
);
1299 n
+= dump_members (fp
, root
->static_fns
);
1300 n
+= dump_members (fp
, root
->friends
);
1301 dump_members (fp
, root
->types
);
1316 /* Dump the entire class tree to file FP. */
1319 dump_roots (FILE *fp
)
1324 /* Output file header containing version string, command line
1328 fputs (TREE_HEADER_STRUCT
, fp
);
1329 putstr (EBROWSE_FILE_VERSION
, fp
);
1342 /* Mark functions as virtual that are so because of functions
1343 declared virtual in base classes. */
1344 mark_inherited_virtual ();
1346 /* Dump the roots of the graph. */
1347 for (i
= 0; i
< TABLE_SIZE
; ++i
)
1348 for (r
= class_table
[i
]; r
; r
= r
->next
)
1351 fputs (TREE_STRUCT
, fp
);
1352 n
+= dump_tree (fp
, r
);
1362 /***********************************************************************
1364 ***********************************************************************/
1367 #define INCREMENT_LINENO \
1369 if (f_very_verbose) \
1372 printf ("%d:\n", yyline); \
1378 #define INCREMENT_LINENO ++yyline
1381 /* Define two macros for accessing the input buffer (current input
1382 file). GET(C) sets C to the next input character and advances the
1383 input pointer. UNGET retracts the input pointer. */
1385 #define GET(C) ((C) = *in++)
1386 #define UNGET() (--in)
1389 /* Process a preprocessor line. Value is the next character from the
1390 input buffer not consumed. */
1393 process_pp_line (void)
1395 int in_comment
= 0, in_string
= 0;
1399 /* Skip over white space. The `#' has been consumed already. */
1400 while (WHITEP (GET (c
)))
1403 /* Read the preprocessor command (if any). */
1410 /* Is it a `define'? */
1413 if (*yytext
&& streq (yytext
, "define"))
1428 char *regexp
= matching_regexp ();
1429 int pos
= BUFFER_POS ();
1430 add_define (yytext
, regexp
, pos
);
1434 while (c
&& (c
!= '\n' || in_comment
|| in_string
))
1438 else if (c
== '/' && !in_comment
)
1443 else if (c
== '*' && in_comment
)
1449 in_string
= !in_string
;
1461 /* Value is the next token from the input buffer. */
1472 while (WHITEP (GET (c
)))
1494 /* String and character constants. */
1497 while (GET (c
) && c
!= end_char
)
1502 /* Escape sequences. */
1505 if (end_char
== '\'')
1506 yyerror ("EOF in character constant", NULL
);
1508 yyerror ("EOF in string constant", NULL
);
1526 /* Hexadecimal escape sequence. */
1528 for (i
= 0; i
< 2; ++i
)
1532 if (c
>= '0' && c
<= '7')
1534 else if (c
>= 'a' && c
<= 'f')
1536 else if (c
>= 'A' && c
<= 'F')
1549 /* Octal escape sequence. */
1551 for (i
= 0; i
< 3; ++i
)
1555 if (c
>= '0' && c
<= '7')
1572 if (end_char
== '\'')
1573 yyerror ("newline in character constant", NULL
);
1575 yyerror ("newline in string constant", NULL
);
1585 return end_char
== '\'' ? CCHAR
: CSTRING
;
1587 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1588 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1589 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1590 case 'v': case 'w': case 'x': case 'y': case 'z':
1591 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1592 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1593 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1594 case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_':
1596 /* Identifier and keywords. */
1603 while (IDENTP (GET (*p
)))
1605 hash
= (hash
<< 1) ^ *p
++;
1606 if (p
== yytext_end
- 1)
1608 int size
= yytext_end
- yytext
;
1609 yytext
= (char *) xrealloc (yytext
, 2 * size
);
1610 yytext_end
= yytext
+ 2 * size
;
1611 p
= yytext
+ size
- 1;
1618 for (k
= keyword_table
[hash
% KEYWORD_TABLE_SIZE
]; k
; k
= k
->next
)
1619 if (streq (k
->name
, yytext
))
1626 /* C and C++ comments, '/' and '/='. */
1654 while (GET (c
) && c
!= '\n')
1656 /* Don't try to read past the end of the input buffer if
1657 the file ends in a C++ comment without a newline. */
1734 yyerror ("invalid token '..' ('...' assumed)", NULL
);
1738 else if (!DIGITP (c
))
1792 c
= process_pp_line ();
1797 case '(': case ')': case '[': case ']': case '{': case '}':
1798 case ';': case ',': case '?': case '~':
1804 if (GET (c
) == 'x' || c
== 'X')
1809 yyival
= yyival
* 16 + c
- '0';
1810 else if (c
>= 'a' && c
<= 'f')
1811 yyival
= yyival
* 16 + c
- 'a' + 10;
1812 else if (c
>= 'A' && c
<= 'F')
1813 yyival
= yyival
* 16 + c
- 'A' + 10;
1823 while (c
>= '0' && c
<= '7')
1825 yyival
= (yyival
<< 3) + c
- '0';
1830 /* Integer suffixes. */
1836 case '1': case '2': case '3': case '4': case '5': case '6':
1837 case '7': case '8': case '9':
1838 /* Integer or floating constant, part before '.'. */
1841 while (GET (c
) && DIGITP (c
))
1842 yyival
= 10 * yyival
+ c
- '0';
1848 /* Digits following '.'. */
1852 /* Optional exponent. */
1853 if (c
== 'E' || c
== 'e')
1855 if (GET (c
) == '-' || c
== '+')
1862 /* Optional type suffixes. */
1875 /* Actually local to matching_regexp. These variables must be in
1876 global scope for the case that `static' get's defined away. */
1878 static char *matching_regexp_buffer
, *matching_regexp_end_buf
;
1881 /* Value is the string from the start of the line to the current
1882 position in the input buffer, or maybe a bit more if that string is
1883 shorter than min_regexp. */
1886 matching_regexp (void)
1895 if (matching_regexp_buffer
== NULL
)
1897 matching_regexp_buffer
= (char *) xmalloc (max_regexp
);
1898 matching_regexp_end_buf
= &matching_regexp_buffer
[max_regexp
] - 1;
1901 /* Scan back to previous newline of buffer start. */
1902 for (p
= in
- 1; p
> inbuffer
&& *p
!= '\n'; --p
)
1907 while (in
- p
< min_regexp
&& p
> inbuffer
)
1909 /* Line probably not significant enough */
1910 for (--p
; p
> inbuffer
&& *p
!= '\n'; --p
)
1917 /* Copy from end to make sure significant portions are included.
1918 This implies that in the browser a regular expressing of the form
1919 `^.*{regexp}' has to be used. */
1920 for (s
= matching_regexp_end_buf
- 1, t
= in
;
1921 s
> matching_regexp_buffer
&& t
> p
;)
1925 if (*s
== '"' || *s
== '\\')
1929 *(matching_regexp_end_buf
- 1) = '\0';
1934 /* Return a printable representation of token T. */
1937 token_string (int t
)
1943 case CSTRING
: return "string constant";
1944 case CCHAR
: return "char constant";
1945 case CINT
: return "int constant";
1946 case CFLOAT
: return "floating constant";
1947 case ELLIPSIS
: return "...";
1948 case LSHIFTASGN
: return "<<=";
1949 case RSHIFTASGN
: return ">>=";
1950 case ARROWSTAR
: return "->*";
1951 case IDENT
: return "identifier";
1952 case DIVASGN
: return "/=";
1953 case INC
: return "++";
1954 case ADDASGN
: return "+=";
1955 case DEC
: return "--";
1956 case ARROW
: return "->";
1957 case SUBASGN
: return "-=";
1958 case MULASGN
: return "*=";
1959 case MODASGN
: return "%=";
1960 case LOR
: return "||";
1961 case ORASGN
: return "|=";
1962 case LAND
: return "&&";
1963 case ANDASGN
: return "&=";
1964 case XORASGN
: return "^=";
1965 case POINTSTAR
: return ".*";
1966 case DCOLON
: return "::";
1967 case EQ
: return "==";
1968 case NE
: return "!=";
1969 case LE
: return "<=";
1970 case LSHIFT
: return "<<";
1971 case GE
: return ">=";
1972 case RSHIFT
: return ">>";
1973 case ASM
: return "asm";
1974 case AUTO
: return "auto";
1975 case BREAK
: return "break";
1976 case CASE
: return "case";
1977 case CATCH
: return "catch";
1978 case CHAR
: return "char";
1979 case CLASS
: return "class";
1980 case CONST
: return "const";
1981 case CONTINUE
: return "continue";
1982 case DEFAULT
: return "default";
1983 case DELETE
: return "delete";
1984 case DO
: return "do";
1985 case DOUBLE
: return "double";
1986 case ELSE
: return "else";
1987 case ENUM
: return "enum";
1988 case EXTERN
: return "extern";
1989 case FLOAT
: return "float";
1990 case FOR
: return "for";
1991 case FRIEND
: return "friend";
1992 case GOTO
: return "goto";
1993 case IF
: return "if";
1994 case T_INLINE
: return "inline";
1995 case INT
: return "int";
1996 case LONG
: return "long";
1997 case NEW
: return "new";
1998 case OPERATOR
: return "operator";
1999 case PRIVATE
: return "private";
2000 case PROTECTED
: return "protected";
2001 case PUBLIC
: return "public";
2002 case REGISTER
: return "register";
2003 case RETURN
: return "return";
2004 case SHORT
: return "short";
2005 case SIGNED
: return "signed";
2006 case SIZEOF
: return "sizeof";
2007 case STATIC
: return "static";
2008 case STRUCT
: return "struct";
2009 case SWITCH
: return "switch";
2010 case TEMPLATE
: return "template";
2011 case THIS
: return "this";
2012 case THROW
: return "throw";
2013 case TRY
: return "try";
2014 case TYPEDEF
: return "typedef";
2015 case UNION
: return "union";
2016 case UNSIGNED
: return "unsigned";
2017 case VIRTUAL
: return "virtual";
2018 case VOID
: return "void";
2019 case VOLATILE
: return "volatile";
2020 case WHILE
: return "while";
2021 case MUTABLE
: return "mutable";
2022 case BOOL
: return "bool";
2023 case TRUE
: return "true";
2024 case FALSE
: return "false";
2025 case SIGNATURE
: return "signature";
2026 case NAMESPACE
: return "namespace";
2027 case EXPLICIT
: return "explicit";
2028 case TYPENAME
: return "typename";
2029 case CONST_CAST
: return "const_cast";
2030 case DYNAMIC_CAST
: return "dynamic_cast";
2031 case REINTERPRET_CAST
: return "reinterpret_cast";
2032 case STATIC_CAST
: return "static_cast";
2033 case TYPEID
: return "typeid";
2034 case USING
: return "using";
2035 case WCHAR
: return "wchar_t";
2036 case YYEOF
: return "EOF";
2051 /* Reinitialize the scanner for a new input file. */
2054 re_init_scanner (void)
2062 yytext
= (char *) xmalloc (size
* sizeof *yytext
);
2063 yytext_end
= yytext
+ size
;
2068 /* Insert a keyword NAME with token value TKV into the keyword hash
2072 insert_keyword (const char *name
, int tkv
)
2076 struct kw
*k
= (struct kw
*) xmalloc (sizeof *k
);
2078 for (s
= name
; *s
; ++s
)
2081 h
%= KEYWORD_TABLE_SIZE
;
2084 k
->next
= keyword_table
[h
];
2085 keyword_table
[h
] = k
;
2089 /* Initialize the scanner for the first file. This sets up the
2090 character class vectors and fills the keyword hash table. */
2097 /* Allocate the input buffer */
2098 inbuffer_size
= READ_CHUNK_SIZE
+ 1;
2099 inbuffer
= in
= (char *) xmalloc (inbuffer_size
);
2102 /* Set up character class vectors. */
2103 for (i
= 0; i
< sizeof is_ident
; ++i
)
2105 if (i
== '_' || isalnum (i
))
2108 if (i
>= '0' && i
<= '9')
2111 if (i
== ' ' || i
== '\t' || i
== '\f' || i
== '\v')
2115 /* Fill keyword hash table. */
2116 insert_keyword ("and", LAND
);
2117 insert_keyword ("and_eq", ANDASGN
);
2118 insert_keyword ("asm", ASM
);
2119 insert_keyword ("auto", AUTO
);
2120 insert_keyword ("bitand", '&');
2121 insert_keyword ("bitor", '|');
2122 insert_keyword ("bool", BOOL
);
2123 insert_keyword ("break", BREAK
);
2124 insert_keyword ("case", CASE
);
2125 insert_keyword ("catch", CATCH
);
2126 insert_keyword ("char", CHAR
);
2127 insert_keyword ("class", CLASS
);
2128 insert_keyword ("compl", '~');
2129 insert_keyword ("const", CONST
);
2130 insert_keyword ("const_cast", CONST_CAST
);
2131 insert_keyword ("continue", CONTINUE
);
2132 insert_keyword ("default", DEFAULT
);
2133 insert_keyword ("delete", DELETE
);
2134 insert_keyword ("do", DO
);
2135 insert_keyword ("double", DOUBLE
);
2136 insert_keyword ("dynamic_cast", DYNAMIC_CAST
);
2137 insert_keyword ("else", ELSE
);
2138 insert_keyword ("enum", ENUM
);
2139 insert_keyword ("explicit", EXPLICIT
);
2140 insert_keyword ("extern", EXTERN
);
2141 insert_keyword ("false", FALSE
);
2142 insert_keyword ("float", FLOAT
);
2143 insert_keyword ("for", FOR
);
2144 insert_keyword ("friend", FRIEND
);
2145 insert_keyword ("goto", GOTO
);
2146 insert_keyword ("if", IF
);
2147 insert_keyword ("inline", T_INLINE
);
2148 insert_keyword ("int", INT
);
2149 insert_keyword ("long", LONG
);
2150 insert_keyword ("mutable", MUTABLE
);
2151 insert_keyword ("namespace", NAMESPACE
);
2152 insert_keyword ("new", NEW
);
2153 insert_keyword ("not", '!');
2154 insert_keyword ("not_eq", NE
);
2155 insert_keyword ("operator", OPERATOR
);
2156 insert_keyword ("or", LOR
);
2157 insert_keyword ("or_eq", ORASGN
);
2158 insert_keyword ("private", PRIVATE
);
2159 insert_keyword ("protected", PROTECTED
);
2160 insert_keyword ("public", PUBLIC
);
2161 insert_keyword ("register", REGISTER
);
2162 insert_keyword ("reinterpret_cast", REINTERPRET_CAST
);
2163 insert_keyword ("return", RETURN
);
2164 insert_keyword ("short", SHORT
);
2165 insert_keyword ("signed", SIGNED
);
2166 insert_keyword ("sizeof", SIZEOF
);
2167 insert_keyword ("static", STATIC
);
2168 insert_keyword ("static_cast", STATIC_CAST
);
2169 insert_keyword ("struct", STRUCT
);
2170 insert_keyword ("switch", SWITCH
);
2171 insert_keyword ("template", TEMPLATE
);
2172 insert_keyword ("this", THIS
);
2173 insert_keyword ("throw", THROW
);
2174 insert_keyword ("true", TRUE
);
2175 insert_keyword ("try", TRY
);
2176 insert_keyword ("typedef", TYPEDEF
);
2177 insert_keyword ("typeid", TYPEID
);
2178 insert_keyword ("typename", TYPENAME
);
2179 insert_keyword ("union", UNION
);
2180 insert_keyword ("unsigned", UNSIGNED
);
2181 insert_keyword ("using", USING
);
2182 insert_keyword ("virtual", VIRTUAL
);
2183 insert_keyword ("void", VOID
);
2184 insert_keyword ("volatile", VOLATILE
);
2185 insert_keyword ("wchar_t", WCHAR
);
2186 insert_keyword ("while", WHILE
);
2187 insert_keyword ("xor", '^');
2188 insert_keyword ("xor_eq", XORASGN
);
2193 /***********************************************************************
2195 ***********************************************************************/
2197 /* Match the current lookahead token and set it to the next token. */
2199 #define MATCH() (tk = yylex ())
2201 /* Return the lookahead token. If current lookahead token is cleared,
2202 read a new token. */
2204 #define LA1 (tk == -1 ? (tk = yylex ()) : tk)
2206 /* Is the current lookahead equal to the token T? */
2208 #define LOOKING_AT(T) (tk == (T))
2210 /* Is the current lookahead one of T1 or T2? */
2212 #define LOOKING_AT2(T1, T2) (tk == (T1) || tk == (T2))
2214 /* Is the current lookahead one of T1, T2 or T3? */
2216 #define LOOKING_AT3(T1, T2, T3) (tk == (T1) || tk == (T2) || tk == (T3))
2218 /* Is the current lookahead one of T1...T4? */
2220 #define LOOKING_AT4(T1, T2, T3, T4) \
2221 (tk == (T1) || tk == (T2) || tk == (T3) || tk == (T4))
2223 /* Match token T if current lookahead is T. */
2225 #define MATCH_IF(T) if (LOOKING_AT (T)) MATCH (); else ((void) 0)
2227 /* Skip to matching token if current token is T. */
2229 #define SKIP_MATCHING_IF(T) \
2230 if (LOOKING_AT (T)) skip_matching (); else ((void) 0)
2233 /* Skip forward until a given token TOKEN or YYEOF is seen and return
2234 the current lookahead token after skipping. */
2239 while (!LOOKING_AT2 (YYEOF
, token
))
2244 /* Skip over pairs of tokens (parentheses, square brackets,
2245 angle brackets, curly brackets) matching the current lookahead. */
2248 skip_matching (void)
2276 if (LOOKING_AT (open
))
2278 else if (LOOKING_AT (close
))
2280 else if (LOOKING_AT (YYEOF
))
2291 skip_initializer (void)
2315 /* Build qualified namespace alias (A::B::c) and return it. */
2317 static struct link
*
2318 match_qualified_namespace_alias (void)
2320 struct link
*head
= NULL
;
2321 struct link
*cur
= NULL
;
2322 struct link
*tmp
= NULL
;
2330 tmp
= (struct link
*) xmalloc (sizeof *cur
);
2331 tmp
->sym
= find_namespace (yytext
, cur
? cur
->sym
: NULL
);
2335 cur
= cur
->next
= tmp
;
2352 /* Re-initialize the parser by resetting the lookahead token. */
2355 re_init_parser (void)
2361 /* Parse a parameter list, including the const-specifier,
2362 pure-specifier, and throw-list that may follow a parameter list.
2363 Return in FLAGS what was seen following the parameter list.
2364 Returns a hash code for the parameter types. This value is used to
2365 distinguish between overloaded functions. */
2368 parm_list (int *flags
)
2373 while (!LOOKING_AT2 (YYEOF
, ')'))
2377 /* Skip over grouping parens or parameter lists in parameter
2383 /* Next parameter. */
2389 /* Ignore the scope part of types, if any. This is because
2390 some types need scopes when defined outside of a class body,
2391 and don't need them inside the class body. This means that
2392 we have to look for the last IDENT in a sequence of
2393 IDENT::IDENT::... */
2398 unsigned ident_type_hash
= 0;
2400 parse_qualified_param_ident_or_type (&last_id
);
2403 /* LAST_ID null means something like `X::*'. */
2404 for (; *last_id
; ++last_id
)
2405 ident_type_hash
= (ident_type_hash
<< 1) ^ *last_id
;
2406 hash
= (hash
<< 1) ^ ident_type_hash
;
2415 /* This distinction is made to make `func (void)' equivalent
2419 if (!LOOKING_AT (')'))
2420 hash
= (hash
<< 1) ^ VOID
;
2423 case BOOL
: case CHAR
: case CLASS
: case CONST
:
2424 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2425 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2426 case UNION
: case UNSIGNED
: case VOLATILE
: case WCHAR
:
2429 hash
= (hash
<< 1) ^ LA1
;
2433 case '*': case '&': case '[': case ']':
2434 hash
= (hash
<< 1) ^ LA1
;
2444 if (LOOKING_AT (')'))
2448 if (LOOKING_AT (CONST
))
2450 /* We can overload the same function on `const' */
2451 hash
= (hash
<< 1) ^ CONST
;
2452 set_flag (flags
, F_CONST
);
2456 if (LOOKING_AT (THROW
))
2459 SKIP_MATCHING_IF ('(');
2460 set_flag (flags
, F_THROW
);
2463 if (LOOKING_AT ('='))
2466 if (LOOKING_AT (CINT
) && yyival
== 0)
2469 set_flag (flags
, F_PURE
);
2478 /* Print position info to stdout. */
2483 if (info_position
>= 0 && BUFFER_POS () <= info_position
)
2485 printf ("(\"%s\" \"%s\" \"%s\" %d)\n",
2486 info_cls
->name
, sym_scope (info_cls
),
2487 info_member
->name
, info_where
);
2491 /* Parse a member declaration within the class body of CLS. VIS is
2492 the access specifier for the member (private, protected,
2496 member (struct sym
*cls
, int vis
)
2500 char *regexp
= NULL
;
2511 while (!LOOKING_AT4 (';', '{', '}', YYEOF
))
2519 /* A function or class may follow. */
2522 set_flag (&flags
, F_TEMPLATE
);
2523 /* Skip over template argument list */
2524 SKIP_MATCHING_IF ('<');
2528 set_flag (&flags
, F_EXPLICIT
);
2532 set_flag (&flags
, F_MUTABLE
);
2536 set_flag (&flags
, F_INLINE
);
2540 set_flag (&flags
, F_VIRTUAL
);
2569 /* Remember IDENTS seen so far. Among these will be the member
2571 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
2575 strcpy (id
+ 1, yytext
);
2578 strcpy (id
, yytext
);
2584 char *s
= operator_name (&sc
);
2585 id
= (char *) xrealloc (id
, strlen (s
) + 1);
2591 /* Most probably the beginning of a parameter list. */
2597 if (!(is_constructor
= streq (id
, cls
->name
)))
2598 regexp
= matching_regexp ();
2603 pos
= BUFFER_POS ();
2604 hash
= parm_list (&flags
);
2607 regexp
= matching_regexp ();
2609 if (id
&& cls
!= NULL
)
2610 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, flags
);
2612 while (!LOOKING_AT3 (';', '{', YYEOF
))
2615 if (LOOKING_AT ('{') && id
&& cls
)
2616 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0, sc
, flags
);
2623 case STRUCT
: case UNION
: case CLASS
:
2630 /* More than one ident here to allow for MS-DOS specialties
2631 like `_export class' etc. The last IDENT seen counts
2632 as the class name. */
2633 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
2635 if (LOOKING_AT (IDENT
))
2640 if (LOOKING_AT2 (':', '{'))
2641 class_definition (anonymous
? NULL
: cls
, class_tag
, flags
, 1);
2646 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
2647 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
2648 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
2657 if (LOOKING_AT (';'))
2659 /* The end of a member variable, a friend declaration or an access
2660 declaration. We don't want to add friend classes as members. */
2661 if (id
&& sc
!= SC_FRIEND
&& cls
)
2663 regexp
= matching_regexp ();
2664 pos
= BUFFER_POS ();
2668 if (type_seen
|| !paren_seen
)
2669 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2671 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, 0);
2678 else if (LOOKING_AT ('{'))
2681 if (sc
== SC_TYPE
&& id
&& cls
)
2683 regexp
= matching_regexp ();
2684 pos
= BUFFER_POS ();
2688 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2689 add_member_defn (cls
, id
, regexp
, pos
, 0, 1, sc
, 0);
2701 /* Parse the body of class CLS. TAG is the tag of the class (struct,
2705 class_body (struct sym
*cls
, int tag
)
2707 int vis
= tag
== CLASS
? PRIVATE
: PUBLIC
;
2710 while (!LOOKING_AT2 (YYEOF
, '}'))
2714 case PRIVATE
: case PROTECTED
: case PUBLIC
:
2718 if (LOOKING_AT (':'))
2725 /* Probably conditional compilation for inheritance list.
2726 We don't known whether there comes more of this.
2727 This is only a crude fix that works most of the time. */
2732 while (LOOKING_AT2 (IDENT
, ',')
2733 || LOOKING_AT3 (PUBLIC
, PROTECTED
, PRIVATE
));
2742 /* Try to synchronize */
2743 case CHAR
: case CLASS
: case CONST
:
2744 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2745 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2746 case UNION
: case UNSIGNED
: case VOID
: case VOLATILE
:
2747 case TYPEDEF
: case STATIC
: case T_INLINE
: case FRIEND
:
2748 case VIRTUAL
: case TEMPLATE
: case IDENT
: case '~':
2749 case BOOL
: case WCHAR
: case EXPLICIT
: case MUTABLE
:
2761 /* Parse a qualified identifier. Current lookahead is IDENT. A
2762 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
2763 symbol for that class. */
2766 parse_classname (void)
2768 struct sym
*last_class
= NULL
;
2770 while (LOOKING_AT (IDENT
))
2772 last_class
= add_sym (yytext
, last_class
);
2775 if (LOOKING_AT ('<'))
2778 set_flag (&last_class
->flags
, F_TEMPLATE
);
2781 if (!LOOKING_AT (DCOLON
))
2791 /* Parse an operator name. Add the `static' flag to *SC if an
2792 implicitly static operator has been parsed. Value is a pointer to
2793 a static buffer holding the constructed operator name string. */
2796 operator_name (int *sc
)
2798 static size_t id_size
= 0;
2799 static char *id
= NULL
;
2805 if (LOOKING_AT2 (NEW
, DELETE
))
2807 /* `new' and `delete' are implicitly static. */
2808 if (*sc
!= SC_FRIEND
)
2811 s
= token_string (LA1
);
2814 ptrdiff_t slen
= strlen (s
);
2818 size_t new_size
= max (len
, 2 * id_size
);
2819 id
= (char *) xrealloc (id
, new_size
);
2822 char *z
= stpcpy (id
, s
);
2824 /* Vector new or delete? */
2825 if (LOOKING_AT ('['))
2827 z
= stpcpy (z
, "[");
2830 if (LOOKING_AT (']'))
2839 size_t tokens_matched
= 0;
2844 int new_size
= max (len
, 2 * id_size
);
2845 id
= (char *) xrealloc (id
, new_size
);
2848 char *z
= stpcpy (id
, "operator");
2850 /* Beware access declarations of the form "X::f;" Beware of
2851 `operator () ()'. Yet another difficulty is found in
2852 GCC 2.95's STL: `operator == __STL_NULL_TMPL_ARGS (...'. */
2853 while (!(LOOKING_AT ('(') && tokens_matched
)
2854 && !LOOKING_AT2 (';', YYEOF
))
2856 s
= token_string (LA1
);
2857 len
+= strlen (s
) + 2;
2860 ptrdiff_t idlen
= z
- id
;
2861 size_t new_size
= max (len
, 2 * id_size
);
2862 id
= (char *) xrealloc (id
, new_size
);
2867 if (*s
!= ')' && *s
!= ']')
2872 /* If this is a simple operator like `+', stop now. */
2873 if (!isalpha ((unsigned char) *s
) && *s
!= '(' && *s
!= '[')
2884 /* This one consumes the last IDENT of a qualified member name like
2885 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2886 symbol structure for the ident. */
2889 parse_qualified_ident_or_type (char **last_id
)
2891 struct sym
*cls
= NULL
;
2896 while (LOOKING_AT (IDENT
))
2898 int len
= strlen (yytext
) + 1;
2901 id
= (char *) xrealloc (id
, len
);
2904 strcpy (id
, yytext
);
2908 SKIP_MATCHING_IF ('<');
2910 if (LOOKING_AT (DCOLON
))
2912 struct sym
*pcn
= NULL
;
2913 struct link
*pna
= check_namespace_alias (id
);
2918 enter_namespace (pna
->sym
->name
);
2924 else if ((pcn
= check_namespace (id
, current_namespace
)))
2926 enter_namespace (pcn
->name
);
2930 cls
= add_sym (id
, cls
);
2949 /* This one consumes the last IDENT of a qualified member name like
2950 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2951 symbol structure for the ident. */
2954 parse_qualified_param_ident_or_type (char **last_id
)
2956 struct sym
*cls
= NULL
;
2957 static char *id
= NULL
;
2958 static int id_size
= 0;
2960 assert (LOOKING_AT (IDENT
));
2964 int len
= strlen (yytext
) + 1;
2967 id
= (char *) xrealloc (id
, len
);
2970 strcpy (id
, yytext
);
2974 SKIP_MATCHING_IF ('<');
2976 if (LOOKING_AT (DCOLON
))
2978 cls
= add_sym (id
, cls
);
2985 while (LOOKING_AT (IDENT
));
2989 /* Parse a class definition.
2991 CONTAINING is the class containing the class being parsed or null.
2992 This may also be null if NESTED != 0 if the containing class is
2993 anonymous. TAG is the tag of the class (struct, union, class).
2994 NESTED is non-zero if we are parsing a nested class.
2996 Current lookahead is the class name. */
2999 class_definition (struct sym
*containing
, int tag
, int flags
, int nested
)
3001 struct sym
*current
;
3002 struct sym
*base_class
;
3004 /* Set CURRENT to null if no entry has to be made for the class
3005 parsed. This is the case for certain command line flag
3007 if ((tag
!= CLASS
&& !f_structs
) || (nested
&& !f_nested_classes
))
3011 current
= add_sym (yytext
, containing
);
3012 current
->pos
= BUFFER_POS ();
3013 current
->regexp
= matching_regexp ();
3014 current
->filename
= filename
;
3015 current
->flags
= flags
;
3018 /* If at ':', base class list follows. */
3019 if (LOOKING_AT (':'))
3028 case VIRTUAL
: case PUBLIC
: case PROTECTED
: case PRIVATE
:
3033 base_class
= parse_classname ();
3034 if (base_class
&& current
&& base_class
!= current
)
3035 add_link (base_class
, current
);
3038 /* The `,' between base classes or the end of the base
3039 class list. Add the previously found base class.
3040 It's done this way to skip over sequences of
3041 `A::B::C' until we reach the end.
3043 FIXME: it is now possible to handle `class X : public B::X'
3044 because we have enough information. */
3050 /* A syntax error, possibly due to preprocessor constructs
3056 class A : private B.
3058 MATCH until we see something like `;' or `{'. */
3059 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 */