1 /* ebrowse.c --- parsing files for the ebrowse C++ browser
3 Copyright (C) 1992-2013 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30 /* The SunOS compiler doesn't have SEEK_END. */
35 /* Conditionalize function prototypes. */
37 /* Value is non-zero if strings X and Y compare equal. */
39 #define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0)
43 /* Files are read in chunks of this number of bytes. */
45 #define READ_CHUNK_SIZE (100 * 1024)
47 #if defined (__MSDOS__)
48 #define FILENAME_EQ(X,Y) (strcasecmp (X,Y) == 0)
50 #if defined (WINDOWSNT)
51 #define FILENAME_EQ(X,Y) (stricmp (X,Y) == 0)
53 #define FILENAME_EQ(X,Y) (streq (X,Y))
56 /* The default output file name. */
58 #define DEFAULT_OUTFILE "BROWSE"
60 /* A version string written to the output file. Change this whenever
61 the structure of the output file changes. */
63 #define EBROWSE_FILE_VERSION "ebrowse 5.0"
65 /* The output file consists of a tree of Lisp objects, with major
66 nodes built out of Lisp structures. These are the heads of the
67 Lisp structs with symbols identifying their type. */
69 #define TREE_HEADER_STRUCT "[ebrowse-hs "
70 #define TREE_STRUCT "[ebrowse-ts "
71 #define MEMBER_STRUCT "[ebrowse-ms "
72 #define CLASS_STRUCT "[ebrowse-cs "
74 /* The name of the symbol table entry for global functions, variables,
75 defines etc. This name also appears in the browser display. */
77 #define GLOBALS_NAME "*Globals*"
79 /* Token definitions. */
83 YYEOF
= 0, /* end of file */
84 CSTRING
= 256, /* string constant */
85 CCHAR
, /* character constant */
86 CINT
, /* integral constant */
87 CFLOAT
, /* real constant */
93 IDENT
, /* identifier */
116 /* Keywords. The undef's are there because these
117 three symbols are very likely to be defined somewhere. */
130 CONTINUE
, /* continue */
131 DEFAULT
, /* default */
143 T_INLINE
, /* inline */
147 OPERATOR
, /* operator */
148 PRIVATE
, /* private */
149 PROTECTED
, /* protected */
151 REGISTER
, /* register */
159 TEMPLATE
, /* template */
163 TYPEDEF
, /* typedef */
165 UNSIGNED
, /* unsigned */
166 VIRTUAL
, /* virtual */
168 VOLATILE
, /* volatile */
170 MUTABLE
, /* mutable */
174 SIGNATURE
, /* signature (GNU extension) */
175 NAMESPACE
, /* namespace */
176 EXPLICIT
, /* explicit */
177 TYPENAME
, /* typename */
178 CONST_CAST
, /* const_cast */
179 DYNAMIC_CAST
, /* dynamic_cast */
180 REINTERPRET_CAST
, /* reinterpret_cast */
181 STATIC_CAST
, /* static_cast */
187 /* Storage classes, in a wider sense. */
192 SC_MEMBER
, /* Is an instance member. */
193 SC_STATIC
, /* Is static member. */
194 SC_FRIEND
, /* Is friend function. */
195 SC_TYPE
/* Is a type definition. */
198 /* Member visibility. */
209 #define F_VIRTUAL 1 /* Is virtual function. */
210 #define F_INLINE 2 /* Is inline function. */
211 #define F_CONST 4 /* Is const. */
212 #define F_PURE 8 /* Is pure virtual function. */
213 #define F_MUTABLE 16 /* Is mutable. */
214 #define F_TEMPLATE 32 /* Is a template. */
215 #define F_EXPLICIT 64 /* Is explicit constructor. */
216 #define F_THROW 128 /* Has a throw specification. */
217 #define F_EXTERNC 256 /* Is declared extern "C". */
218 #define F_DEFINE 512 /* Is a #define. */
220 /* Two macros to set and test a bit in an int. */
222 #define SET_FLAG(F, FLAG) ((F) |= (FLAG))
223 #define HAS_FLAG(F, FLAG) (((F) & (FLAG)) != 0)
225 /* Structure describing a class member. */
229 struct member
*next
; /* Next in list of members. */
230 struct member
*anext
; /* Collision chain in member_table. */
231 struct member
**list
; /* Pointer to list in class. */
232 unsigned param_hash
; /* Hash value for parameter types. */
233 int vis
; /* Visibility (public, ...). */
234 int flags
; /* See F_* above. */
235 char *regexp
; /* Matching regular expression. */
236 const char *filename
; /* Don't free this shared string. */
237 int pos
; /* Buffer position of occurrence. */
238 char *def_regexp
; /* Regular expression matching definition. */
239 const char *def_filename
; /* File name of definition. */
240 int def_pos
; /* Buffer position of definition. */
241 char name
[FLEXIBLE_ARRAY_MEMBER
]; /* Member name. */
244 /* Structures of this type are used to connect class structures with
245 their super and subclasses. */
249 struct sym
*sym
; /* The super or subclass. */
250 struct link
*next
; /* Next in list or NULL. */
253 /* Structure used to record namespace aliases. */
257 struct alias
*next
; /* Next in list. */
258 struct sym
*namesp
; /* Namespace in which defined. */
259 struct link
*aliasee
; /* List of aliased namespaces (A::B::C...). */
260 char name
[FLEXIBLE_ARRAY_MEMBER
]; /* Alias name. */
263 /* The structure used to describe a class in the symbol table,
264 or a namespace in all_namespaces. */
268 int flags
; /* Is class a template class?. */
269 unsigned char visited
; /* Used to find circles. */
270 struct sym
*next
; /* Hash collision list. */
271 struct link
*subs
; /* List of subclasses. */
272 struct link
*supers
; /* List of superclasses. */
273 struct member
*vars
; /* List of instance variables. */
274 struct member
*fns
; /* List of instance functions. */
275 struct member
*static_vars
; /* List of static variables. */
276 struct member
*static_fns
; /* List of static functions. */
277 struct member
*friends
; /* List of friend functions. */
278 struct member
*types
; /* List of local types. */
279 char *regexp
; /* Matching regular expression. */
280 int pos
; /* Buffer position. */
281 const char *filename
; /* File in which it can be found. */
282 const char *sfilename
; /* File in which members can be found. */
283 struct sym
*namesp
; /* Namespace in which defined. . */
284 char name
[FLEXIBLE_ARRAY_MEMBER
]; /* Name of the class. */
287 /* Experimental: Print info for `--position-info'. We print
288 '(CLASS-NAME SCOPE MEMBER-NAME). */
294 struct sym
*info_cls
= NULL
;
295 struct member
*info_member
= NULL
;
297 /* Experimental. For option `--position-info', the buffer position we
298 are interested in. When this position is reached, print out
299 information about what we know about that point. */
301 int info_position
= -1;
303 /* Command line options structure for getopt_long. */
305 struct option options
[] =
307 {"append", no_argument
, NULL
, 'a'},
308 {"files", required_argument
, NULL
, 'f'},
309 {"help", no_argument
, NULL
, -2},
310 {"min-regexp-length", required_argument
, NULL
, 'm'},
311 {"max-regexp-length", required_argument
, NULL
, 'M'},
312 {"no-nested-classes", no_argument
, NULL
, 'n'},
313 {"no-regexps", no_argument
, NULL
, 'x'},
314 {"no-structs-or-unions", no_argument
, NULL
, 's'},
315 {"output-file", required_argument
, NULL
, 'o'},
316 {"position-info", required_argument
, NULL
, 'p'},
317 {"search-path", required_argument
, NULL
, 'I'},
318 {"verbose", no_argument
, NULL
, 'v'},
319 {"version", no_argument
, NULL
, -3},
320 {"very-verbose", no_argument
, NULL
, 'V'},
324 /* Semantic values of tokens. Set by yylex.. */
326 unsigned yyival
; /* Set for token CINT. */
327 char *yytext
; /* Set for token IDENT. */
334 /* Current line number. */
338 /* The name of the current input file. */
340 const char *filename
;
342 /* Three character class vectors, and macros to test membership
349 #define IDENTP(C) is_ident[(unsigned char) (C)]
350 #define DIGITP(C) is_digit[(unsigned char) (C)]
351 #define WHITEP(C) is_white[(unsigned char) (C)]
353 /* Command line flags. */
360 int f_nested_classes
= 1;
362 /* Maximum and minimum lengths of regular expressions matching a
363 member, class etc., for writing them to the output file. These are
364 overridable from the command line. */
373 size_t inbuffer_size
;
375 /* Return the current buffer position in the input file. */
377 #define BUFFER_POS() (in - inbuffer)
379 /* If current lookahead is CSTRING, the following points to the
380 first character in the string constant. Used for recognizing
385 /* The size of the hash tables for classes.and members. Should be
388 #define TABLE_SIZE 1001
390 /* The hash table for class symbols. */
392 struct sym
*class_table
[TABLE_SIZE
];
394 /* Hash table containing all member structures. This is generally
395 faster for member lookup than traversing the member lists of a
398 struct member
*member_table
[TABLE_SIZE
];
400 /* Hash table for namespace aliases */
402 struct alias
*namespace_alias_table
[TABLE_SIZE
];
404 /* The special class symbol used to hold global functions,
407 struct sym
*global_symbols
;
409 /* The current namespace. */
411 struct sym
*current_namespace
;
413 /* The list of all known namespaces. */
415 struct sym
*all_namespaces
;
417 /* Stack of namespaces we're currently nested in, during the parse. */
419 struct sym
**namespace_stack
;
420 int namespace_stack_size
;
423 /* The current lookahead token. */
427 /* Structure describing a keyword. */
431 const char *name
; /* Spelling. */
432 int tk
; /* Token value. */
433 struct kw
*next
; /* Next in collision chain. */
436 /* Keywords are lookup up in a hash table of their own. */
438 #define KEYWORD_TABLE_SIZE 1001
439 struct kw
*keyword_table
[KEYWORD_TABLE_SIZE
];
446 struct search_path
*next
;
449 struct search_path
*search_path
;
450 struct search_path
*search_path_tail
;
452 /* Function prototypes. */
454 static char *matching_regexp (void);
455 static struct sym
*add_sym (const char *, struct sym
*);
456 static void add_global_defn (char *, char *, int, unsigned, int, int, int);
457 static void add_global_decl (char *, char *, int, unsigned, int, int, int);
458 static struct member
*add_member (struct sym
*, char *, int, int, unsigned);
459 static void class_definition (struct sym
*, int, int, int);
460 static char *operator_name (int *);
461 static void parse_qualified_param_ident_or_type (char **);
463 /***********************************************************************
465 ***********************************************************************/
467 /* Print an error in a printf-like style with the current input file
468 name and line number. */
471 yyerror (const char *format
, const char *s
)
473 fprintf (stderr
, "%s:%d: ", filename
, yyline
);
474 fprintf (stderr
, format
, s
);
479 /* Like malloc but print an error and exit if not enough memory is
483 xmalloc (size_t nbytes
)
485 void *p
= malloc (nbytes
);
488 yyerror ("out of memory", NULL
);
495 /* Like realloc but print an error and exit if out of memory. */
498 xrealloc (void *p
, size_t sz
)
503 yyerror ("out of memory", NULL
);
510 /* Like strdup, but print an error and exit if not enough memory is
511 available.. If S is null, return null. */
517 return strcpy (xmalloc (strlen (s
) + 1), s
);
523 /***********************************************************************
525 ***********************************************************************/
527 /* Initialize the symbol table. This currently only sets up the
528 special symbol for globals (`*Globals*'). */
533 global_symbols
= add_sym (GLOBALS_NAME
, NULL
);
537 /* Add a symbol for class NAME to the symbol table. NESTED_IN_CLASS
538 is the class in which class NAME was found. If it is null,
539 this means the scope of NAME is the current namespace.
541 If a symbol for NAME already exists, return that. Otherwise
542 create a new symbol and set it to default values. */
545 add_sym (const char *name
, struct sym
*nested_in_class
)
550 struct sym
*scope
= nested_in_class
? nested_in_class
: current_namespace
;
552 for (s
= name
, h
= 0; *s
; ++s
)
556 for (sym
= class_table
[h
]; sym
; sym
= sym
->next
)
557 if (streq (name
, sym
->name
)
558 && ((!sym
->namesp
&& !scope
)
559 || (sym
->namesp
&& scope
560 && streq (sym
->namesp
->name
, scope
->name
))))
571 sym
= xmalloc (offsetof (struct sym
, name
) + strlen (name
) + 1);
572 memset (sym
, 0, offsetof (struct sym
, name
));
573 strcpy (sym
->name
, name
);
575 sym
->next
= class_table
[h
];
576 class_table
[h
] = sym
;
583 /* Add links between superclass SUPER and subclass SUB. */
586 add_link (struct sym
*super
, struct sym
*sub
)
588 struct link
*lnk
, *lnk2
, *p
, *prev
;
590 /* See if a link already exists. */
591 for (p
= super
->subs
, prev
= NULL
;
592 p
&& strcmp (sub
->name
, p
->sym
->name
) > 0;
593 prev
= p
, p
= p
->next
)
596 /* Avoid duplicates. */
597 if (p
== NULL
|| p
->sym
!= sub
)
599 lnk
= (struct link
*) xmalloc (sizeof *lnk
);
600 lnk2
= (struct link
*) xmalloc (sizeof *lnk2
);
611 lnk2
->next
= sub
->supers
;
617 /* Find in class CLS member NAME.
619 VAR non-zero means look for a member variable; otherwise a function
620 is searched. SC specifies what kind of member is searched---a
621 static, or per-instance member etc. HASH is a hash code for the
622 parameter types of functions. Value is a pointer to the member
623 found or null if not found. */
625 static struct member
*
626 find_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
628 struct member
**list
;
630 unsigned name_hash
= 0;
637 list
= &cls
->friends
;
645 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
649 list
= var
? &cls
->vars
: &cls
->fns
;
653 for (s
= name
; *s
; ++s
)
654 name_hash
= (name_hash
<< 1) ^ *s
;
655 i
= name_hash
% TABLE_SIZE
;
657 for (p
= member_table
[i
]; p
; p
= p
->anext
)
658 if (p
->list
== list
&& p
->param_hash
== hash
&& streq (name
, p
->name
))
665 /* Add to class CLS information for the declaration of member NAME.
666 REGEXP is a regexp matching the declaration, if non-null. POS is
667 the position in the source where the declaration is found. HASH is
668 a hash code for the parameter list of the member, if it's a
669 function. VAR non-zero means member is a variable or type. SC
670 specifies the type of member (instance member, static, ...). VIS
671 is the member's visibility (public, protected, private). FLAGS is
672 a bit set giving additional information about the member (see the
676 add_member_decl (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int vis
, int flags
)
680 m
= find_member (cls
, name
, var
, sc
, hash
);
682 m
= add_member (cls
, name
, var
, sc
, hash
);
684 /* Have we seen a new filename? If so record that. */
685 if (!cls
->filename
|| !FILENAME_EQ (cls
->filename
, filename
))
686 m
->filename
= filename
;
699 m
->vis
= V_PROTECTED
;
713 /* Add to class CLS information for the definition of member NAME.
714 REGEXP is a regexp matching the declaration, if non-null. POS is
715 the position in the source where the declaration is found. HASH is
716 a hash code for the parameter list of the member, if it's a
717 function. VAR non-zero means member is a variable or type. SC
718 specifies the type of member (instance member, static, ...). VIS
719 is the member's visibility (public, protected, private). FLAGS is
720 a bit set giving additional information about the member (see the
724 add_member_defn (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
728 if (sc
== SC_UNKNOWN
)
730 m
= find_member (cls
, name
, var
, SC_MEMBER
, hash
);
733 m
= find_member (cls
, name
, var
, SC_STATIC
, hash
);
735 m
= add_member (cls
, name
, var
, sc
, hash
);
740 m
= find_member (cls
, name
, var
, sc
, hash
);
742 m
= add_member (cls
, name
, var
, sc
, hash
);
746 cls
->sfilename
= filename
;
748 if (!FILENAME_EQ (cls
->sfilename
, filename
))
749 m
->def_filename
= filename
;
751 m
->def_regexp
= regexp
;
761 /* Add a symbol for a define named NAME to the symbol table.
762 REGEXP is a regular expression matching the define in the source,
763 if it is non-null. POS is the position in the file. */
766 add_define (char *name
, char *regexp
, int pos
)
768 add_global_defn (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
769 add_global_decl (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
773 /* Add information for the global definition of NAME.
774 REGEXP is a regexp matching the declaration, if non-null. POS is
775 the position in the source where the declaration is found. HASH is
776 a hash code for the parameter list of the member, if it's a
777 function. VAR non-zero means member is a variable or type. SC
778 specifies the type of member (instance member, static, ...). VIS
779 is the member's visibility (public, protected, private). FLAGS is
780 a bit set giving additional information about the member (see the
784 add_global_defn (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
789 /* Try to find out for which classes a function is a friend, and add
790 what we know about it to them. */
792 for (i
= 0; i
< TABLE_SIZE
; ++i
)
793 for (sym
= class_table
[i
]; sym
; sym
= sym
->next
)
794 if (sym
!= global_symbols
&& sym
->friends
)
795 if (find_member (sym
, name
, 0, SC_FRIEND
, hash
))
796 add_member_defn (sym
, name
, regexp
, pos
, hash
, 0,
799 /* Add to global symbols. */
800 add_member_defn (global_symbols
, name
, regexp
, pos
, hash
, var
, sc
, flags
);
804 /* Add information for the global declaration of NAME.
805 REGEXP is a regexp matching the declaration, if non-null. POS is
806 the position in the source where the declaration is found. HASH is
807 a hash code for the parameter list of the member, if it's a
808 function. VAR non-zero means member is a variable or type. SC
809 specifies the type of member (instance member, static, ...). VIS
810 is the member's visibility (public, protected, private). FLAGS is
811 a bit set giving additional information about the member (see the
815 add_global_decl (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
817 /* Add declaration only if not already declared. Header files must
818 be processed before source files for this to have the right effect.
819 I do not want to handle implicit declarations at the moment. */
821 struct member
*found
;
823 m
= found
= find_member (global_symbols
, name
, var
, sc
, hash
);
825 m
= add_member (global_symbols
, name
, var
, sc
, hash
);
827 /* Definition already seen => probably last declaration implicit.
828 Override. This means that declarations must always be added to
829 the symbol table before definitions. */
832 if (!global_symbols
->filename
833 || !FILENAME_EQ (global_symbols
->filename
, filename
))
834 m
->filename
= filename
;
842 info_cls
= global_symbols
;
848 /* Add a symbol for member NAME to class CLS.
849 VAR non-zero means it's a variable. SC specifies the kind of
850 member. HASH is a hash code for the parameter types of a function.
851 Value is a pointer to the member's structure. */
853 static struct member
*
854 add_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
856 struct member
*m
= xmalloc (offsetof (struct member
, name
)
857 + strlen (name
) + 1);
858 struct member
**list
;
861 unsigned name_hash
= 0;
865 strcpy (m
->name
, name
);
866 m
->param_hash
= hash
;
873 m
->def_regexp
= NULL
;
874 m
->def_filename
= NULL
;
877 assert (cls
!= NULL
);
882 list
= &cls
->friends
;
890 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
894 list
= var
? &cls
->vars
: &cls
->fns
;
898 for (s
= name
; *s
; ++s
)
899 name_hash
= (name_hash
<< 1) ^ *s
;
900 i
= name_hash
% TABLE_SIZE
;
901 m
->anext
= member_table
[i
];
905 /* Keep the member list sorted. It's cheaper to do it here than to
906 sort them in Lisp. */
907 for (prev
= NULL
, p
= *list
;
908 p
&& strcmp (name
, p
->name
) > 0;
909 prev
= p
, p
= p
->next
)
921 /* Given the root R of a class tree, step through all subclasses
922 recursively, marking functions as virtual that are declared virtual
926 mark_virtual (struct sym
*r
)
929 struct member
*m
, *m2
;
931 for (p
= r
->subs
; p
; p
= p
->next
)
933 for (m
= r
->fns
; m
; m
= m
->next
)
934 if (HAS_FLAG (m
->flags
, F_VIRTUAL
))
936 for (m2
= p
->sym
->fns
; m2
; m2
= m2
->next
)
937 if (m
->param_hash
== m2
->param_hash
&& streq (m
->name
, m2
->name
))
938 SET_FLAG (m2
->flags
, F_VIRTUAL
);
941 mark_virtual (p
->sym
);
946 /* For all roots of the class tree, mark functions as virtual that
947 are virtual because of a virtual declaration in a base class. */
950 mark_inherited_virtual (void)
955 for (i
= 0; i
< TABLE_SIZE
; ++i
)
956 for (r
= class_table
[i
]; r
; r
= r
->next
)
957 if (r
->supers
== NULL
)
962 /* Create and return a symbol for a namespace with name NAME. */
965 make_namespace (char *name
, struct sym
*context
)
967 struct sym
*s
= xmalloc (offsetof (struct sym
, name
) + strlen (name
) + 1);
968 memset (s
, 0, offsetof (struct sym
, name
));
969 strcpy (s
->name
, name
);
970 s
->next
= all_namespaces
;
977 /* Find the symbol for namespace NAME. If not found, return NULL */
980 check_namespace (char *name
, struct sym
*context
)
982 struct sym
*p
= NULL
;
984 for (p
= all_namespaces
; p
; p
= p
->next
)
986 if (streq (p
->name
, name
) && (p
->namesp
== context
))
993 /* Find the symbol for namespace NAME. If not found, add a new symbol
994 for NAME to all_namespaces. */
997 find_namespace (char *name
, struct sym
*context
)
999 struct sym
*p
= check_namespace (name
, context
);
1002 p
= make_namespace (name
, context
);
1008 /* Find namespace alias with name NAME. If not found return NULL. */
1010 static struct link
*
1011 check_namespace_alias (char *name
)
1013 struct link
*p
= NULL
;
1018 for (s
= name
, h
= 0; *s
; ++s
)
1022 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1023 if (streq (name
, al
->name
) && (al
->namesp
== current_namespace
))
1032 /* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */
1035 register_namespace_alias (char *new_name
, struct link
*old_name
)
1041 for (s
= new_name
, h
= 0; *s
; ++s
)
1046 /* Is it already in the table of aliases? */
1047 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1048 if (streq (new_name
, al
->name
) && (al
->namesp
== current_namespace
))
1051 al
= xmalloc (offsetof (struct alias
, name
) + strlen (new_name
) + 1);
1052 strcpy (al
->name
, new_name
);
1053 al
->next
= namespace_alias_table
[h
];
1054 al
->namesp
= current_namespace
;
1055 al
->aliasee
= old_name
;
1056 namespace_alias_table
[h
] = al
;
1060 /* Enter namespace with name NAME. */
1063 enter_namespace (char *name
)
1065 struct sym
*p
= find_namespace (name
, current_namespace
);
1067 if (namespace_sp
== namespace_stack_size
)
1069 int size
= max (10, 2 * namespace_stack_size
);
1071 = (struct sym
**) xrealloc ((void *)namespace_stack
,
1072 size
* sizeof *namespace_stack
);
1073 namespace_stack_size
= size
;
1076 namespace_stack
[namespace_sp
++] = current_namespace
;
1077 current_namespace
= p
;
1081 /* Leave the current namespace. */
1084 leave_namespace (void)
1086 assert (namespace_sp
> 0);
1087 current_namespace
= namespace_stack
[--namespace_sp
];
1092 /***********************************************************************
1093 Writing the Output File
1094 ***********************************************************************/
1096 /* Write string S to the output file FP in a Lisp-readable form.
1097 If S is null, write out `()'. */
1100 putstr (const char *s
, FILE *fp
)
1117 /* A dynamically allocated buffer for constructing a scope name. */
1120 int scope_buffer_size
;
1121 int scope_buffer_len
;
1124 /* Make sure scope_buffer has enough room to add LEN chars to it. */
1127 ensure_scope_buffer_room (int len
)
1129 if (scope_buffer_len
+ len
>= scope_buffer_size
)
1131 int new_size
= max (2 * scope_buffer_size
, scope_buffer_len
+ len
);
1132 scope_buffer
= (char *) xrealloc (scope_buffer
, new_size
);
1133 scope_buffer_size
= new_size
;
1138 /* Recursively add the scope names of symbol P and the scopes of its
1139 namespaces to scope_buffer. Value is a pointer to the complete
1140 scope name constructed. */
1143 sym_scope_1 (struct sym
*p
)
1148 sym_scope_1 (p
->namesp
);
1152 ensure_scope_buffer_room (3);
1153 strcat (scope_buffer
, "::");
1154 scope_buffer_len
+= 2;
1157 len
= strlen (p
->name
);
1158 ensure_scope_buffer_room (len
+ 1);
1159 strcat (scope_buffer
, p
->name
);
1160 scope_buffer_len
+= len
;
1162 if (HAS_FLAG (p
->flags
, F_TEMPLATE
))
1164 ensure_scope_buffer_room (3);
1165 strcat (scope_buffer
, "<>");
1166 scope_buffer_len
+= 2;
1169 return scope_buffer
;
1173 /* Return the scope of symbol P in printed representation, i.e.
1174 as it would appear in a C*+ source file. */
1177 sym_scope (struct sym
*p
)
1181 scope_buffer_size
= 1024;
1182 scope_buffer
= (char *) xmalloc (scope_buffer_size
);
1185 *scope_buffer
= '\0';
1186 scope_buffer_len
= 0;
1189 sym_scope_1 (p
->namesp
);
1191 return scope_buffer
;
1195 /* Dump the list of members M to file FP. Value is the length of the
1199 dump_members (FILE *fp
, struct member
*m
)
1205 for (n
= 0; m
; m
= m
->next
, ++n
)
1207 fputs (MEMBER_STRUCT
, fp
);
1208 putstr (m
->name
, fp
);
1209 putstr (NULL
, fp
); /* FIXME? scope for globals */
1210 fprintf (fp
, "%u ", (unsigned) m
->flags
);
1211 putstr (m
->filename
, fp
);
1212 putstr (m
->regexp
, fp
);
1213 fprintf (fp
, "%u ", (unsigned) m
->pos
);
1214 fprintf (fp
, "%u ", (unsigned) m
->vis
);
1216 putstr (m
->def_filename
, fp
);
1217 putstr (m
->def_regexp
, fp
);
1218 fprintf (fp
, "%u", (unsigned) m
->def_pos
);
1229 /* Dump class ROOT to stream FP. */
1232 dump_sym (FILE *fp
, struct sym
*root
)
1234 fputs (CLASS_STRUCT
, fp
);
1235 putstr (root
->name
, fp
);
1237 /* Print scope, if any. */
1239 putstr (sym_scope (root
), fp
);
1244 fprintf (fp
, "%u", root
->flags
);
1245 putstr (root
->filename
, fp
);
1246 putstr (root
->regexp
, fp
);
1247 fprintf (fp
, "%u", (unsigned) root
->pos
);
1248 putstr (root
->sfilename
, fp
);
1254 /* Dump class ROOT and its subclasses to file FP. Value is the
1255 number of classes written. */
1258 dump_tree (FILE *fp
, struct sym
*root
)
1263 dump_sym (fp
, root
);
1273 for (lk
= root
->subs
; lk
; lk
= lk
->next
)
1275 fputs (TREE_STRUCT
, fp
);
1276 n
+= dump_tree (fp
, lk
->sym
);
1282 dump_members (fp
, root
->vars
);
1283 n
+= dump_members (fp
, root
->fns
);
1284 dump_members (fp
, root
->static_vars
);
1285 n
+= dump_members (fp
, root
->static_fns
);
1286 n
+= dump_members (fp
, root
->friends
);
1287 dump_members (fp
, root
->types
);
1302 /* Dump the entire class tree to file FP. */
1305 dump_roots (FILE *fp
)
1310 /* Output file header containing version string, command line
1314 fputs (TREE_HEADER_STRUCT
, fp
);
1315 putstr (EBROWSE_FILE_VERSION
, fp
);
1328 /* Mark functions as virtual that are so because of functions
1329 declared virtual in base classes. */
1330 mark_inherited_virtual ();
1332 /* Dump the roots of the graph. */
1333 for (i
= 0; i
< TABLE_SIZE
; ++i
)
1334 for (r
= class_table
[i
]; r
; r
= r
->next
)
1337 fputs (TREE_STRUCT
, fp
);
1338 n
+= dump_tree (fp
, r
);
1348 /***********************************************************************
1350 ***********************************************************************/
1353 #define INCREMENT_LINENO \
1355 if (f_very_verbose) \
1358 printf ("%d:\n", yyline); \
1364 #define INCREMENT_LINENO ++yyline
1367 /* Define two macros for accessing the input buffer (current input
1368 file). GET(C) sets C to the next input character and advances the
1369 input pointer. UNGET retracts the input pointer. */
1371 #define GET(C) ((C) = *in++)
1372 #define UNGET() (--in)
1375 /* Process a preprocessor line. Value is the next character from the
1376 input buffer not consumed. */
1379 process_pp_line (void)
1381 int in_comment
= 0, in_string
= 0;
1385 /* Skip over white space. The `#' has been consumed already. */
1386 while (WHITEP (GET (c
)))
1389 /* Read the preprocessor command (if any). */
1396 /* Is it a `define'? */
1399 if (*yytext
&& streq (yytext
, "define"))
1414 char *regexp
= matching_regexp ();
1415 int pos
= BUFFER_POS ();
1416 add_define (yytext
, regexp
, pos
);
1420 while (c
&& (c
!= '\n' || in_comment
|| in_string
))
1424 else if (c
== '/' && !in_comment
)
1429 else if (c
== '*' && in_comment
)
1435 in_string
= !in_string
;
1447 /* Value is the next token from the input buffer. */
1458 while (WHITEP (GET (c
)))
1480 /* String and character constants. */
1483 while (GET (c
) && c
!= end_char
)
1488 /* Escape sequences. */
1491 if (end_char
== '\'')
1492 yyerror ("EOF in character constant", NULL
);
1494 yyerror ("EOF in string constant", NULL
);
1512 /* Hexadecimal escape sequence. */
1514 for (i
= 0; i
< 2; ++i
)
1518 if (c
>= '0' && c
<= '7')
1520 else if (c
>= 'a' && c
<= 'f')
1522 else if (c
>= 'A' && c
<= 'F')
1535 /* Octal escape sequence. */
1537 for (i
= 0; i
< 3; ++i
)
1541 if (c
>= '0' && c
<= '7')
1558 if (end_char
== '\'')
1559 yyerror ("newline in character constant", NULL
);
1561 yyerror ("newline in string constant", NULL
);
1571 return end_char
== '\'' ? CCHAR
: CSTRING
;
1573 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1574 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1575 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1576 case 'v': case 'w': case 'x': case 'y': case 'z':
1577 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1578 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1579 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1580 case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_':
1582 /* Identifier and keywords. */
1589 while (IDENTP (GET (*p
)))
1591 hash
= (hash
<< 1) ^ *p
++;
1592 if (p
== yytext_end
- 1)
1594 int size
= yytext_end
- yytext
;
1595 yytext
= (char *) xrealloc (yytext
, 2 * size
);
1596 yytext_end
= yytext
+ 2 * size
;
1597 p
= yytext
+ size
- 1;
1604 for (k
= keyword_table
[hash
% KEYWORD_TABLE_SIZE
]; k
; k
= k
->next
)
1605 if (streq (k
->name
, yytext
))
1612 /* C and C++ comments, '/' and '/='. */
1640 while (GET (c
) && c
!= '\n')
1642 /* Don't try to read past the end of the input buffer if
1643 the file ends in a C++ comment without a newline. */
1720 yyerror ("invalid token '..' ('...' assumed)", NULL
);
1724 else if (!DIGITP (c
))
1778 c
= process_pp_line ();
1783 case '(': case ')': case '[': case ']': case '{': case '}':
1784 case ';': case ',': case '?': case '~':
1790 if (GET (c
) == 'x' || c
== 'X')
1795 yyival
= yyival
* 16 + c
- '0';
1796 else if (c
>= 'a' && c
<= 'f')
1797 yyival
= yyival
* 16 + c
- 'a' + 10;
1798 else if (c
>= 'A' && c
<= 'F')
1799 yyival
= yyival
* 16 + c
- 'A' + 10;
1809 while (c
>= '0' && c
<= '7')
1811 yyival
= (yyival
<< 3) + c
- '0';
1816 /* Integer suffixes. */
1822 case '1': case '2': case '3': case '4': case '5': case '6':
1823 case '7': case '8': case '9':
1824 /* Integer or floating constant, part before '.'. */
1827 while (GET (c
) && DIGITP (c
))
1828 yyival
= 10 * yyival
+ c
- '0';
1834 /* Digits following '.'. */
1838 /* Optional exponent. */
1839 if (c
== 'E' || c
== 'e')
1841 if (GET (c
) == '-' || c
== '+')
1848 /* Optional type suffixes. */
1861 /* Actually local to matching_regexp. These variables must be in
1862 global scope for the case that `static' get's defined away. */
1864 static char *matching_regexp_buffer
, *matching_regexp_end_buf
;
1867 /* Value is the string from the start of the line to the current
1868 position in the input buffer, or maybe a bit more if that string is
1869 shorter than min_regexp. */
1872 matching_regexp (void)
1881 if (matching_regexp_buffer
== NULL
)
1883 matching_regexp_buffer
= (char *) xmalloc (max_regexp
);
1884 matching_regexp_end_buf
= &matching_regexp_buffer
[max_regexp
] - 1;
1887 /* Scan back to previous newline of buffer start. */
1888 for (p
= in
- 1; p
> inbuffer
&& *p
!= '\n'; --p
)
1893 while (in
- p
< min_regexp
&& p
> inbuffer
)
1895 /* Line probably not significant enough */
1896 for (--p
; p
> inbuffer
&& *p
!= '\n'; --p
)
1903 /* Copy from end to make sure significant portions are included.
1904 This implies that in the browser a regular expressing of the form
1905 `^.*{regexp}' has to be used. */
1906 for (s
= matching_regexp_end_buf
- 1, t
= in
;
1907 s
> matching_regexp_buffer
&& t
> p
;)
1911 if (*s
== '"' || *s
== '\\')
1915 *(matching_regexp_end_buf
- 1) = '\0';
1920 /* Return a printable representation of token T. */
1923 token_string (int t
)
1929 case CSTRING
: return "string constant";
1930 case CCHAR
: return "char constant";
1931 case CINT
: return "int constant";
1932 case CFLOAT
: return "floating constant";
1933 case ELLIPSIS
: return "...";
1934 case LSHIFTASGN
: return "<<=";
1935 case RSHIFTASGN
: return ">>=";
1936 case ARROWSTAR
: return "->*";
1937 case IDENT
: return "identifier";
1938 case DIVASGN
: return "/=";
1939 case INC
: return "++";
1940 case ADDASGN
: return "+=";
1941 case DEC
: return "--";
1942 case ARROW
: return "->";
1943 case SUBASGN
: return "-=";
1944 case MULASGN
: return "*=";
1945 case MODASGN
: return "%=";
1946 case LOR
: return "||";
1947 case ORASGN
: return "|=";
1948 case LAND
: return "&&";
1949 case ANDASGN
: return "&=";
1950 case XORASGN
: return "^=";
1951 case POINTSTAR
: return ".*";
1952 case DCOLON
: return "::";
1953 case EQ
: return "==";
1954 case NE
: return "!=";
1955 case LE
: return "<=";
1956 case LSHIFT
: return "<<";
1957 case GE
: return ">=";
1958 case RSHIFT
: return ">>";
1959 case ASM
: return "asm";
1960 case AUTO
: return "auto";
1961 case BREAK
: return "break";
1962 case CASE
: return "case";
1963 case CATCH
: return "catch";
1964 case CHAR
: return "char";
1965 case CLASS
: return "class";
1966 case CONST
: return "const";
1967 case CONTINUE
: return "continue";
1968 case DEFAULT
: return "default";
1969 case DELETE
: return "delete";
1970 case DO
: return "do";
1971 case DOUBLE
: return "double";
1972 case ELSE
: return "else";
1973 case ENUM
: return "enum";
1974 case EXTERN
: return "extern";
1975 case FLOAT
: return "float";
1976 case FOR
: return "for";
1977 case FRIEND
: return "friend";
1978 case GOTO
: return "goto";
1979 case IF
: return "if";
1980 case T_INLINE
: return "inline";
1981 case INT
: return "int";
1982 case LONG
: return "long";
1983 case NEW
: return "new";
1984 case OPERATOR
: return "operator";
1985 case PRIVATE
: return "private";
1986 case PROTECTED
: return "protected";
1987 case PUBLIC
: return "public";
1988 case REGISTER
: return "register";
1989 case RETURN
: return "return";
1990 case SHORT
: return "short";
1991 case SIGNED
: return "signed";
1992 case SIZEOF
: return "sizeof";
1993 case STATIC
: return "static";
1994 case STRUCT
: return "struct";
1995 case SWITCH
: return "switch";
1996 case TEMPLATE
: return "template";
1997 case THIS
: return "this";
1998 case THROW
: return "throw";
1999 case TRY
: return "try";
2000 case TYPEDEF
: return "typedef";
2001 case UNION
: return "union";
2002 case UNSIGNED
: return "unsigned";
2003 case VIRTUAL
: return "virtual";
2004 case VOID
: return "void";
2005 case VOLATILE
: return "volatile";
2006 case WHILE
: return "while";
2007 case MUTABLE
: return "mutable";
2008 case BOOL
: return "bool";
2009 case TRUE
: return "true";
2010 case FALSE
: return "false";
2011 case SIGNATURE
: return "signature";
2012 case NAMESPACE
: return "namespace";
2013 case EXPLICIT
: return "explicit";
2014 case TYPENAME
: return "typename";
2015 case CONST_CAST
: return "const_cast";
2016 case DYNAMIC_CAST
: return "dynamic_cast";
2017 case REINTERPRET_CAST
: return "reinterpret_cast";
2018 case STATIC_CAST
: return "static_cast";
2019 case TYPEID
: return "typeid";
2020 case USING
: return "using";
2021 case WCHAR
: return "wchar_t";
2022 case YYEOF
: return "EOF";
2037 /* Reinitialize the scanner for a new input file. */
2040 re_init_scanner (void)
2048 yytext
= (char *) xmalloc (size
* sizeof *yytext
);
2049 yytext_end
= yytext
+ size
;
2054 /* Insert a keyword NAME with token value TKV into the keyword hash
2058 insert_keyword (const char *name
, int tkv
)
2062 struct kw
*k
= (struct kw
*) xmalloc (sizeof *k
);
2064 for (s
= name
; *s
; ++s
)
2067 h
%= KEYWORD_TABLE_SIZE
;
2070 k
->next
= keyword_table
[h
];
2071 keyword_table
[h
] = k
;
2075 /* Initialize the scanner for the first file. This sets up the
2076 character class vectors and fills the keyword hash table. */
2083 /* Allocate the input buffer */
2084 inbuffer_size
= READ_CHUNK_SIZE
+ 1;
2085 inbuffer
= in
= (char *) xmalloc (inbuffer_size
);
2088 /* Set up character class vectors. */
2089 for (i
= 0; i
< sizeof is_ident
; ++i
)
2091 if (i
== '_' || isalnum (i
))
2094 if (i
>= '0' && i
<= '9')
2097 if (i
== ' ' || i
== '\t' || i
== '\f' || i
== '\v')
2101 /* Fill keyword hash table. */
2102 insert_keyword ("and", LAND
);
2103 insert_keyword ("and_eq", ANDASGN
);
2104 insert_keyword ("asm", ASM
);
2105 insert_keyword ("auto", AUTO
);
2106 insert_keyword ("bitand", '&');
2107 insert_keyword ("bitor", '|');
2108 insert_keyword ("bool", BOOL
);
2109 insert_keyword ("break", BREAK
);
2110 insert_keyword ("case", CASE
);
2111 insert_keyword ("catch", CATCH
);
2112 insert_keyword ("char", CHAR
);
2113 insert_keyword ("class", CLASS
);
2114 insert_keyword ("compl", '~');
2115 insert_keyword ("const", CONST
);
2116 insert_keyword ("const_cast", CONST_CAST
);
2117 insert_keyword ("continue", CONTINUE
);
2118 insert_keyword ("default", DEFAULT
);
2119 insert_keyword ("delete", DELETE
);
2120 insert_keyword ("do", DO
);
2121 insert_keyword ("double", DOUBLE
);
2122 insert_keyword ("dynamic_cast", DYNAMIC_CAST
);
2123 insert_keyword ("else", ELSE
);
2124 insert_keyword ("enum", ENUM
);
2125 insert_keyword ("explicit", EXPLICIT
);
2126 insert_keyword ("extern", EXTERN
);
2127 insert_keyword ("false", FALSE
);
2128 insert_keyword ("float", FLOAT
);
2129 insert_keyword ("for", FOR
);
2130 insert_keyword ("friend", FRIEND
);
2131 insert_keyword ("goto", GOTO
);
2132 insert_keyword ("if", IF
);
2133 insert_keyword ("inline", T_INLINE
);
2134 insert_keyword ("int", INT
);
2135 insert_keyword ("long", LONG
);
2136 insert_keyword ("mutable", MUTABLE
);
2137 insert_keyword ("namespace", NAMESPACE
);
2138 insert_keyword ("new", NEW
);
2139 insert_keyword ("not", '!');
2140 insert_keyword ("not_eq", NE
);
2141 insert_keyword ("operator", OPERATOR
);
2142 insert_keyword ("or", LOR
);
2143 insert_keyword ("or_eq", ORASGN
);
2144 insert_keyword ("private", PRIVATE
);
2145 insert_keyword ("protected", PROTECTED
);
2146 insert_keyword ("public", PUBLIC
);
2147 insert_keyword ("register", REGISTER
);
2148 insert_keyword ("reinterpret_cast", REINTERPRET_CAST
);
2149 insert_keyword ("return", RETURN
);
2150 insert_keyword ("short", SHORT
);
2151 insert_keyword ("signed", SIGNED
);
2152 insert_keyword ("sizeof", SIZEOF
);
2153 insert_keyword ("static", STATIC
);
2154 insert_keyword ("static_cast", STATIC_CAST
);
2155 insert_keyword ("struct", STRUCT
);
2156 insert_keyword ("switch", SWITCH
);
2157 insert_keyword ("template", TEMPLATE
);
2158 insert_keyword ("this", THIS
);
2159 insert_keyword ("throw", THROW
);
2160 insert_keyword ("true", TRUE
);
2161 insert_keyword ("try", TRY
);
2162 insert_keyword ("typedef", TYPEDEF
);
2163 insert_keyword ("typeid", TYPEID
);
2164 insert_keyword ("typename", TYPENAME
);
2165 insert_keyword ("union", UNION
);
2166 insert_keyword ("unsigned", UNSIGNED
);
2167 insert_keyword ("using", USING
);
2168 insert_keyword ("virtual", VIRTUAL
);
2169 insert_keyword ("void", VOID
);
2170 insert_keyword ("volatile", VOLATILE
);
2171 insert_keyword ("wchar_t", WCHAR
);
2172 insert_keyword ("while", WHILE
);
2173 insert_keyword ("xor", '^');
2174 insert_keyword ("xor_eq", XORASGN
);
2179 /***********************************************************************
2181 ***********************************************************************/
2183 /* Match the current lookahead token and set it to the next token. */
2185 #define MATCH() (tk = yylex ())
2187 /* Return the lookahead token. If current lookahead token is cleared,
2188 read a new token. */
2190 #define LA1 (tk == -1 ? (tk = yylex ()) : tk)
2192 /* Is the current lookahead equal to the token T? */
2194 #define LOOKING_AT(T) (tk == (T))
2196 /* Is the current lookahead one of T1 or T2? */
2198 #define LOOKING_AT2(T1, T2) (tk == (T1) || tk == (T2))
2200 /* Is the current lookahead one of T1, T2 or T3? */
2202 #define LOOKING_AT3(T1, T2, T3) (tk == (T1) || tk == (T2) || tk == (T3))
2204 /* Is the current lookahead one of T1...T4? */
2206 #define LOOKING_AT4(T1, T2, T3, T4) \
2207 (tk == (T1) || tk == (T2) || tk == (T3) || tk == (T4))
2209 /* Match token T if current lookahead is T. */
2211 #define MATCH_IF(T) if (LOOKING_AT (T)) MATCH (); else ((void) 0)
2213 /* Skip to matching token if current token is T. */
2215 #define SKIP_MATCHING_IF(T) \
2216 if (LOOKING_AT (T)) skip_matching (); else ((void) 0)
2219 /* Skip forward until a given token TOKEN or YYEOF is seen and return
2220 the current lookahead token after skipping. */
2225 while (!LOOKING_AT2 (YYEOF
, token
))
2230 /* Skip over pairs of tokens (parentheses, square brackets,
2231 angle brackets, curly brackets) matching the current lookahead. */
2234 skip_matching (void)
2262 if (LOOKING_AT (open
))
2264 else if (LOOKING_AT (close
))
2266 else if (LOOKING_AT (YYEOF
))
2277 skip_initializer (void)
2301 /* Build qualified namespace alias (A::B::c) and return it. */
2303 static struct link
*
2304 match_qualified_namespace_alias (void)
2306 struct link
*head
= NULL
;
2307 struct link
*cur
= NULL
;
2308 struct link
*tmp
= NULL
;
2316 tmp
= (struct link
*) xmalloc (sizeof *cur
);
2317 tmp
->sym
= find_namespace (yytext
, cur
? cur
->sym
: NULL
);
2321 cur
= cur
->next
= tmp
;
2338 /* Re-initialize the parser by resetting the lookahead token. */
2341 re_init_parser (void)
2347 /* Parse a parameter list, including the const-specifier,
2348 pure-specifier, and throw-list that may follow a parameter list.
2349 Return in FLAGS what was seen following the parameter list.
2350 Returns a hash code for the parameter types. This value is used to
2351 distinguish between overloaded functions. */
2354 parm_list (int *flags
)
2359 while (!LOOKING_AT2 (YYEOF
, ')'))
2363 /* Skip over grouping parens or parameter lists in parameter
2369 /* Next parameter. */
2375 /* Ignore the scope part of types, if any. This is because
2376 some types need scopes when defined outside of a class body,
2377 and don't need them inside the class body. This means that
2378 we have to look for the last IDENT in a sequence of
2379 IDENT::IDENT::... */
2384 unsigned ident_type_hash
= 0;
2386 parse_qualified_param_ident_or_type (&last_id
);
2389 /* LAST_ID null means something like `X::*'. */
2390 for (; *last_id
; ++last_id
)
2391 ident_type_hash
= (ident_type_hash
<< 1) ^ *last_id
;
2392 hash
= (hash
<< 1) ^ ident_type_hash
;
2401 /* This distinction is made to make `func (void)' equivalent
2405 if (!LOOKING_AT (')'))
2406 hash
= (hash
<< 1) ^ VOID
;
2409 case BOOL
: case CHAR
: case CLASS
: case CONST
:
2410 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2411 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2412 case UNION
: case UNSIGNED
: case VOLATILE
: case WCHAR
:
2415 hash
= (hash
<< 1) ^ LA1
;
2419 case '*': case '&': case '[': case ']':
2420 hash
= (hash
<< 1) ^ LA1
;
2430 if (LOOKING_AT (')'))
2434 if (LOOKING_AT (CONST
))
2436 /* We can overload the same function on `const' */
2437 hash
= (hash
<< 1) ^ CONST
;
2438 SET_FLAG (*flags
, F_CONST
);
2442 if (LOOKING_AT (THROW
))
2445 SKIP_MATCHING_IF ('(');
2446 SET_FLAG (*flags
, F_THROW
);
2449 if (LOOKING_AT ('='))
2452 if (LOOKING_AT (CINT
) && yyival
== 0)
2455 SET_FLAG (*flags
, F_PURE
);
2464 /* Print position info to stdout. */
2469 if (info_position
>= 0 && BUFFER_POS () <= info_position
)
2471 printf ("(\"%s\" \"%s\" \"%s\" %d)\n",
2472 info_cls
->name
, sym_scope (info_cls
),
2473 info_member
->name
, info_where
);
2477 /* Parse a member declaration within the class body of CLS. VIS is
2478 the access specifier for the member (private, protected,
2482 member (struct sym
*cls
, int vis
)
2486 char *regexp
= NULL
;
2497 while (!LOOKING_AT4 (';', '{', '}', YYEOF
))
2505 /* A function or class may follow. */
2508 SET_FLAG (flags
, F_TEMPLATE
);
2509 /* Skip over template argument list */
2510 SKIP_MATCHING_IF ('<');
2514 SET_FLAG (flags
, F_EXPLICIT
);
2518 SET_FLAG (flags
, F_MUTABLE
);
2522 SET_FLAG (flags
, F_INLINE
);
2526 SET_FLAG (flags
, F_VIRTUAL
);
2555 /* Remember IDENTS seen so far. Among these will be the member
2557 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
2561 strcpy (id
+ 1, yytext
);
2564 strcpy (id
, yytext
);
2570 char *s
= operator_name (&sc
);
2571 id
= (char *) xrealloc (id
, strlen (s
) + 1);
2577 /* Most probably the beginning of a parameter list. */
2583 if (!(is_constructor
= streq (id
, cls
->name
)))
2584 regexp
= matching_regexp ();
2589 pos
= BUFFER_POS ();
2590 hash
= parm_list (&flags
);
2593 regexp
= matching_regexp ();
2595 if (id
&& cls
!= NULL
)
2596 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, flags
);
2598 while (!LOOKING_AT3 (';', '{', YYEOF
))
2601 if (LOOKING_AT ('{') && id
&& cls
)
2602 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0, sc
, flags
);
2609 case STRUCT
: case UNION
: case CLASS
:
2616 /* More than one ident here to allow for MS-DOS specialties
2617 like `_export class' etc. The last IDENT seen counts
2618 as the class name. */
2619 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
2621 if (LOOKING_AT (IDENT
))
2626 if (LOOKING_AT2 (':', '{'))
2627 class_definition (anonymous
? NULL
: cls
, class_tag
, flags
, 1);
2632 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
2633 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
2634 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
2643 if (LOOKING_AT (';'))
2645 /* The end of a member variable, a friend declaration or an access
2646 declaration. We don't want to add friend classes as members. */
2647 if (id
&& sc
!= SC_FRIEND
&& cls
)
2649 regexp
= matching_regexp ();
2650 pos
= BUFFER_POS ();
2654 if (type_seen
|| !paren_seen
)
2655 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2657 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, 0);
2664 else if (LOOKING_AT ('{'))
2667 if (sc
== SC_TYPE
&& id
&& cls
)
2669 regexp
= matching_regexp ();
2670 pos
= BUFFER_POS ();
2674 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2675 add_member_defn (cls
, id
, regexp
, pos
, 0, 1, sc
, 0);
2687 /* Parse the body of class CLS. TAG is the tag of the class (struct,
2691 class_body (struct sym
*cls
, int tag
)
2693 int vis
= tag
== CLASS
? PRIVATE
: PUBLIC
;
2696 while (!LOOKING_AT2 (YYEOF
, '}'))
2700 case PRIVATE
: case PROTECTED
: case PUBLIC
:
2704 if (LOOKING_AT (':'))
2711 /* Probably conditional compilation for inheritance list.
2712 We don't known whether there comes more of this.
2713 This is only a crude fix that works most of the time. */
2718 while (LOOKING_AT2 (IDENT
, ',')
2719 || LOOKING_AT3 (PUBLIC
, PROTECTED
, PRIVATE
));
2728 /* Try to synchronize */
2729 case CHAR
: case CLASS
: case CONST
:
2730 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2731 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2732 case UNION
: case UNSIGNED
: case VOID
: case VOLATILE
:
2733 case TYPEDEF
: case STATIC
: case T_INLINE
: case FRIEND
:
2734 case VIRTUAL
: case TEMPLATE
: case IDENT
: case '~':
2735 case BOOL
: case WCHAR
: case EXPLICIT
: case MUTABLE
:
2747 /* Parse a qualified identifier. Current lookahead is IDENT. A
2748 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
2749 symbol for that class. */
2752 parse_classname (void)
2754 struct sym
*last_class
= NULL
;
2756 while (LOOKING_AT (IDENT
))
2758 last_class
= add_sym (yytext
, last_class
);
2761 if (LOOKING_AT ('<'))
2764 SET_FLAG (last_class
->flags
, F_TEMPLATE
);
2767 if (!LOOKING_AT (DCOLON
))
2777 /* Parse an operator name. Add the `static' flag to *SC if an
2778 implicitly static operator has been parsed. Value is a pointer to
2779 a static buffer holding the constructed operator name string. */
2782 operator_name (int *sc
)
2784 static size_t id_size
= 0;
2785 static char *id
= NULL
;
2791 if (LOOKING_AT2 (NEW
, DELETE
))
2793 /* `new' and `delete' are implicitly static. */
2794 if (*sc
!= SC_FRIEND
)
2797 s
= token_string (LA1
);
2800 len
= strlen (s
) + 10;
2803 size_t new_size
= max (len
, 2 * id_size
);
2804 id
= (char *) xrealloc (id
, new_size
);
2809 /* Vector new or delete? */
2810 if (LOOKING_AT ('['))
2815 if (LOOKING_AT (']'))
2824 size_t tokens_matched
= 0;
2829 int new_size
= max (len
, 2 * id_size
);
2830 id
= (char *) xrealloc (id
, new_size
);
2833 strcpy (id
, "operator");
2835 /* Beware access declarations of the form "X::f;" Beware of
2836 `operator () ()'. Yet another difficulty is found in
2837 GCC 2.95's STL: `operator == __STL_NULL_TMPL_ARGS (...'. */
2838 while (!(LOOKING_AT ('(') && tokens_matched
)
2839 && !LOOKING_AT2 (';', YYEOF
))
2841 s
= token_string (LA1
);
2842 len
+= strlen (s
) + 2;
2845 size_t new_size
= max (len
, 2 * id_size
);
2846 id
= (char *) xrealloc (id
, new_size
);
2850 if (*s
!= ')' && *s
!= ']')
2855 /* If this is a simple operator like `+', stop now. */
2856 if (!isalpha ((unsigned char) *s
) && *s
!= '(' && *s
!= '[')
2867 /* This one consumes the last IDENT of a qualified member name like
2868 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2869 symbol structure for the ident. */
2872 parse_qualified_ident_or_type (char **last_id
)
2874 struct sym
*cls
= NULL
;
2879 while (LOOKING_AT (IDENT
))
2881 int len
= strlen (yytext
) + 1;
2884 id
= (char *) xrealloc (id
, len
);
2887 strcpy (id
, yytext
);
2891 SKIP_MATCHING_IF ('<');
2893 if (LOOKING_AT (DCOLON
))
2895 struct sym
*pcn
= NULL
;
2896 struct link
*pna
= check_namespace_alias (id
);
2901 enter_namespace (pna
->sym
->name
);
2907 else if ((pcn
= check_namespace (id
, current_namespace
)))
2909 enter_namespace (pcn
->name
);
2913 cls
= add_sym (id
, cls
);
2932 /* This one consumes the last IDENT of a qualified member name like
2933 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2934 symbol structure for the ident. */
2937 parse_qualified_param_ident_or_type (char **last_id
)
2939 struct sym
*cls
= NULL
;
2940 static char *id
= NULL
;
2941 static int id_size
= 0;
2943 assert (LOOKING_AT (IDENT
));
2947 int len
= strlen (yytext
) + 1;
2950 id
= (char *) xrealloc (id
, len
);
2953 strcpy (id
, yytext
);
2957 SKIP_MATCHING_IF ('<');
2959 if (LOOKING_AT (DCOLON
))
2961 cls
= add_sym (id
, cls
);
2968 while (LOOKING_AT (IDENT
));
2972 /* Parse a class definition.
2974 CONTAINING is the class containing the class being parsed or null.
2975 This may also be null if NESTED != 0 if the containing class is
2976 anonymous. TAG is the tag of the class (struct, union, class).
2977 NESTED is non-zero if we are parsing a nested class.
2979 Current lookahead is the class name. */
2982 class_definition (struct sym
*containing
, int tag
, int flags
, int nested
)
2984 struct sym
*current
;
2985 struct sym
*base_class
;
2987 /* Set CURRENT to null if no entry has to be made for the class
2988 parsed. This is the case for certain command line flag
2990 if ((tag
!= CLASS
&& !f_structs
) || (nested
&& !f_nested_classes
))
2994 current
= add_sym (yytext
, containing
);
2995 current
->pos
= BUFFER_POS ();
2996 current
->regexp
= matching_regexp ();
2997 current
->filename
= filename
;
2998 current
->flags
= flags
;
3001 /* If at ':', base class list follows. */
3002 if (LOOKING_AT (':'))
3011 case VIRTUAL
: case PUBLIC
: case PROTECTED
: case PRIVATE
:
3016 base_class
= parse_classname ();
3017 if (base_class
&& current
&& base_class
!= current
)
3018 add_link (base_class
, current
);
3021 /* The `,' between base classes or the end of the base
3022 class list. Add the previously found base class.
3023 It's done this way to skip over sequences of
3024 `A::B::C' until we reach the end.
3026 FIXME: it is now possible to handle `class X : public B::X'
3027 because we have enough information. */
3033 /* A syntax error, possibly due to preprocessor constructs
3039 class A : private B.
3041 MATCH until we see something like `;' or `{'. */
3042 while (!LOOKING_AT3 (';', YYEOF
, '{'))
3053 /* Parse the class body if there is one. */
3054 if (LOOKING_AT ('{'))
3056 if (tag
!= CLASS
&& !f_structs
)
3061 class_body (current
, tag
);
3063 if (LOOKING_AT ('}'))
3066 if (LOOKING_AT (';') && !nested
)
3073 /* Add to class *CLS information for the declaration of variable or
3074 type *ID. If *CLS is null, this means a global declaration. SC is
3075 the storage class of *ID. FLAGS is a bit set giving additional
3076 information about the member (see the F_* defines). */
3079 add_declarator (struct sym
**cls
, char **id
, int flags
, int sc
)
3081 if (LOOKING_AT2 (';', ','))
3083 /* The end of a member variable or of an access declaration
3084 `X::f'. To distinguish between them we have to know whether
3085 type information has been seen. */
3088 char *regexp
= matching_regexp ();
3089 int pos
= BUFFER_POS ();
3092 add_member_defn (*cls
, *id
, regexp
, pos
, 0, 1, SC_UNKNOWN
, flags
);
3094 add_global_defn (*id
, regexp
, pos
, 0, 1, sc
, flags
);
3100 else if (LOOKING_AT ('{'))
3102 if (sc
== SC_TYPE
&& *id
)
3104 /* A named enumeration. */
3105 char *regexp
= matching_regexp ();
3106 int pos
= BUFFER_POS ();
3107 add_global_defn (*id
, regexp
, pos
, 0, 1, sc
, flags
);
3119 /* Parse a declaration. */
3122 declaration (int flags
)
3125 struct sym
*cls
= NULL
;
3126 char *regexp
= NULL
;
3132 while (!LOOKING_AT3 (';', '{', YYEOF
))
3155 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
3156 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
3157 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
3161 case CLASS
: case STRUCT
: case UNION
:
3162 /* This is for the case `STARTWRAP class X : ...' or
3163 `declare (X, Y)\n class A : ...'. */
3171 /* Assumed to be the start of an initialization in this
3173 skip_initializer ();
3177 add_declarator (&cls
, &id
, flags
, sc
);
3182 char *s
= operator_name (&sc
);
3183 id
= (char *) xrealloc (id
, strlen (s
) + 1);
3189 SET_FLAG (flags
, F_INLINE
);
3195 if (LOOKING_AT (IDENT
))
3197 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
3199 strcpy (id
+ 1, yytext
);
3205 cls
= parse_qualified_ident_or_type (&id
);
3209 /* Most probably the beginning of a parameter list. */
3216 if (!(is_constructor
= streq (id
, cls
->name
)))
3217 regexp
= matching_regexp ();
3222 pos
= BUFFER_POS ();
3223 hash
= parm_list (&flags
);
3226 regexp
= matching_regexp ();
3229 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0,
3234 /* This may be a C functions, but also a macro
3235 call of the form `declare (A, B)' --- such macros
3236 can be found in some class libraries. */
3241 regexp
= matching_regexp ();
3242 pos
= BUFFER_POS ();
3243 hash
= parm_list (&flags
);
3244 add_global_decl (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3247 /* This is for the case that the function really is
3248 a macro with no `;' following it. If a CLASS directly
3249 follows, we would miss it otherwise. */
3250 if (LOOKING_AT3 (CLASS
, STRUCT
, UNION
))
3254 while (!LOOKING_AT3 (';', '{', YYEOF
))
3257 if (!cls
&& id
&& LOOKING_AT ('{'))
3258 add_global_defn (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3266 add_declarator (&cls
, &id
, flags
, sc
);
3270 /* Parse a list of top-level declarations/definitions. START_FLAGS
3271 says in which context we are parsing. If it is F_EXTERNC, we are
3272 parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0
3276 globals (int start_flags
)
3280 int flags
= start_flags
;
3292 if (LOOKING_AT (IDENT
))
3294 char *namespace_name
= xstrdup (yytext
);
3297 if (LOOKING_AT ('='))
3299 struct link
*qna
= match_qualified_namespace_alias ();
3301 register_namespace_alias (namespace_name
, qna
);
3303 if (skip_to (';') == ';')
3306 else if (LOOKING_AT ('{'))
3309 enter_namespace (namespace_name
);
3315 free (namespace_name
);
3322 if (LOOKING_AT (CSTRING
) && *string_start
== 'C'
3323 && *(string_start
+ 1) == '"')
3325 /* This is `extern "C"'. */
3328 if (LOOKING_AT ('{'))
3331 globals (F_EXTERNC
);
3335 SET_FLAG (flags
, F_EXTERNC
);
3341 SKIP_MATCHING_IF ('<');
3342 SET_FLAG (flags
, F_TEMPLATE
);
3345 case CLASS
: case STRUCT
: case UNION
:
3350 /* More than one ident here to allow for MS-DOS and OS/2
3351 specialties like `far', `_Export' etc. Some C++ libs
3352 have constructs like `_OS_DLLIMPORT(_OS_CLIENT)' in front
3353 of the class name. */
3354 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
3356 if (LOOKING_AT (IDENT
))
3361 /* Don't add anonymous unions. */
3362 if (LOOKING_AT2 (':', '{') && !anonymous
)
3363 class_definition (NULL
, class_tk
, flags
, 0);
3366 if (skip_to (';') == ';')
3370 flags
= start_flags
;
3380 declaration (flags
);
3381 flags
= start_flags
;
3386 yyerror ("parse error", NULL
);
3391 /* Parse the current input file. */
3396 while (globals (0) == 0)
3402 /***********************************************************************
3404 ***********************************************************************/
3406 /* Add the list of paths PATH_LIST to the current search path for
3410 add_search_path (char *path_list
)
3414 char *start
= path_list
;
3415 struct search_path
*p
;
3417 while (*path_list
&& *path_list
!= SEPCHAR
)
3420 p
= (struct search_path
*) xmalloc (sizeof *p
);
3421 p
->path
= (char *) xmalloc (path_list
- start
+ 1);
3422 memcpy (p
->path
, start
, path_list
- start
);
3423 p
->path
[path_list
- start
] = '\0';
3426 if (search_path_tail
)
3428 search_path_tail
->next
= p
;
3429 search_path_tail
= p
;
3432 search_path
= search_path_tail
= p
;
3434 while (*path_list
== SEPCHAR
)
3440 /* Open FILE and return a file handle for it, or -1 if FILE cannot be
3441 opened. Try to find FILE in search_path first, then try the
3442 unchanged file name. */
3445 open_file (char *file
)
3448 static char *buffer
;
3449 static int buffer_size
;
3450 struct search_path
*path
;
3451 int flen
= strlen (file
) + 1; /* +1 for the slash */
3453 filename
= xstrdup (file
);
3455 for (path
= search_path
; path
&& fp
== NULL
; path
= path
->next
)
3457 int len
= strlen (path
->path
) + flen
;
3459 if (len
+ 1 >= buffer_size
)
3461 buffer_size
= max (len
+ 1, 2 * buffer_size
);
3462 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3465 strcpy (buffer
, path
->path
);
3466 strcat (buffer
, "/");
3467 strcat (buffer
, file
);
3468 fp
= fopen (buffer
, "r");
3471 /* Try the original file name. */
3473 fp
= fopen (file
, "r");
3476 yyerror ("cannot open", NULL
);
3482 /* Display usage information and exit program. */
3484 static char const *const usage_message
[] =
3487 Usage: ebrowse [options] {files}\n\
3489 -a, --append append output to existing file\n\
3490 -f, --files=FILES read input file names from FILE\n\
3491 -I, --search-path=LIST set search path for input files\n\
3492 -m, --min-regexp-length=N set minimum regexp length to N\n\
3493 -M, --max-regexp-length=N set maximum regexp length to N\n\
3496 -n, --no-nested-classes exclude nested classes\n\
3497 -o, --output-file=FILE set output file name to FILE\n\
3498 -p, --position-info print info about position in file\n\
3499 -s, --no-structs-or-unions don't record structs or unions\n\
3500 -v, --verbose be verbose\n\
3501 -V, --very-verbose be very verbose\n\
3502 -x, --no-regexps don't record regular expressions\n\
3503 --help display this help\n\
3504 --version display version info\n\
3509 static _Noreturn
void
3513 for (i
= 0; i
< sizeof usage_message
/ sizeof *usage_message
; i
++)
3514 fputs (usage_message
[i
], stdout
);
3515 exit (error
? EXIT_FAILURE
: EXIT_SUCCESS
);
3519 /* Display version and copyright info. The VERSION macro is set
3520 from config.h and contains the Emacs version. */
3523 # define VERSION "21"
3526 static _Noreturn
void
3529 char emacs_copyright
[] = COPYRIGHT
;
3531 printf ("ebrowse %s\n", VERSION
);
3532 puts (emacs_copyright
);
3533 puts ("This program is distributed under the same terms as Emacs.");
3534 exit (EXIT_SUCCESS
);
3538 /* Parse one input file FILE, adding classes and members to the symbol
3542 process_file (char *file
)
3546 fp
= open_file (file
);
3549 size_t nread
, nbytes
;
3551 /* Give a progress indication if needed. */
3563 /* Read file to inbuffer. */
3566 if (nread
+ READ_CHUNK_SIZE
>= inbuffer_size
)
3568 inbuffer_size
= nread
+ READ_CHUNK_SIZE
+ 1;
3569 inbuffer
= (char *) xrealloc (inbuffer
, inbuffer_size
);
3572 nbytes
= fread (inbuffer
+ nread
, 1, READ_CHUNK_SIZE
, fp
);
3577 inbuffer
[nread
] = '\0';
3579 /* Reinitialize scanner and parser for the new input file. */
3583 /* Parse it and close the file. */
3590 /* Read a line from stream FP and return a pointer to a static buffer
3591 containing its contents without the terminating newline. Value
3592 is null when EOF is reached. */
3595 read_line (FILE *fp
)
3597 static char *buffer
;
3598 static int buffer_size
;
3601 while ((c
= getc (fp
)) != EOF
&& c
!= '\n')
3603 if (i
>= buffer_size
)
3605 buffer_size
= max (100, buffer_size
* 2);
3606 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3612 if (c
== EOF
&& i
== 0)
3615 if (i
== buffer_size
)
3617 buffer_size
= max (100, buffer_size
* 2);
3618 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3622 if (i
> 0 && buffer
[i
- 1] == '\r')
3623 buffer
[i
- 1] = '\0';
3628 /* Main entry point. */
3631 main (int argc
, char **argv
)
3634 int any_inputfiles
= 0;
3635 static const char *out_filename
= DEFAULT_OUTFILE
;
3636 static char **input_filenames
= NULL
;
3637 static int input_filenames_size
= 0;
3638 static int n_input_files
;
3640 filename
= "command line";
3643 while ((i
= getopt_long (argc
, argv
, "af:I:m:M:no:p:svVx",
3644 options
, NULL
)) != EOF
)
3650 info_position
= atoi (optarg
);
3654 f_nested_classes
= 0;
3661 /* Add the name of a file containing more input files. */
3663 if (n_input_files
== input_filenames_size
)
3665 input_filenames_size
= max (10, 2 * input_filenames_size
);
3666 input_filenames
= (char **) xrealloc ((void *)input_filenames
,
3667 input_filenames_size
);
3669 input_filenames
[n_input_files
++] = xstrdup (optarg
);
3672 /* Append new output to output file instead of truncating it. */
3677 /* Include structs in the output */
3682 /* Be verbose (give a progress indication). */
3687 /* Be very verbose (print file names as they are processed). */
3693 /* Change the name of the output file. */
3695 out_filename
= optarg
;
3698 /* Set minimum length for regular expression strings
3699 when recorded in the output file. */
3701 min_regexp
= atoi (optarg
);
3704 /* Set maximum length for regular expression strings
3705 when recorded in the output file. */
3707 max_regexp
= atoi (optarg
);
3710 /* Add to search path. */
3712 add_search_path (optarg
);
3726 /* Call init_scanner after command line flags have been processed to be
3727 able to add keywords depending on command line (not yet
3732 /* Open output file */
3737 /* Check that the file to append to exists, and is not
3738 empty. More specifically, it should be a valid file
3739 produced by a previous run of ebrowse, but that's too
3740 difficult to check. */
3744 fp
= fopen (out_filename
, "r");
3747 yyerror ("file `%s' must exist for --append", out_filename
);
3748 exit (EXIT_FAILURE
);
3751 rc
= fseek (fp
, 0, SEEK_END
);
3754 yyerror ("error seeking in file `%s'", out_filename
);
3755 exit (EXIT_FAILURE
);
3761 yyerror ("error getting size of file `%s'", out_filename
);
3762 exit (EXIT_FAILURE
);
3767 yyerror ("file `%s' is empty", out_filename
);
3768 /* It may be ok to use an empty file for appending.
3769 exit (EXIT_FAILURE); */
3775 yyout
= fopen (out_filename
, f_append
? "a" : "w");
3778 yyerror ("cannot open output file `%s'", out_filename
);
3779 exit (EXIT_FAILURE
);
3783 /* Process input files specified on the command line. */
3784 while (optind
< argc
)
3786 process_file (argv
[optind
++]);
3790 /* Process files given on stdin if no files specified. */
3791 if (!any_inputfiles
&& n_input_files
== 0)
3794 while ((file
= read_line (stdin
)) != NULL
)
3795 process_file (file
);
3799 /* Process files from `--files=FILE'. Every line in FILE names
3800 one input file to process. */
3801 for (i
= 0; i
< n_input_files
; ++i
)
3803 FILE *fp
= fopen (input_filenames
[i
], "r");
3806 yyerror ("cannot open input file `%s'", input_filenames
[i
]);
3810 while ((file
= read_line (fp
)) != NULL
)
3811 process_file (file
);
3817 /* Write output file. */
3820 /* Close output file. */
3821 if (yyout
!= stdout
)
3824 return EXIT_SUCCESS
;
3827 /* ebrowse.c ends here */