1 /* ebrowse.c --- parsing files for the ebrowse C++ browser
3 Copyright (C) 1992-2012 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/>. */
29 /* The SunOS compiler doesn't have SEEK_END. */
34 /* Conditionalize function prototypes. */
36 /* Value is non-zero if strings X and Y compare equal. */
38 #define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0)
42 /* Files are read in chunks of this number of bytes. */
44 #define READ_CHUNK_SIZE (100 * 1024)
46 /* The character used as a separator in path lists (like $PATH). */
48 #if defined (__MSDOS__)
49 #define PATH_LIST_SEPARATOR ';'
50 #define FILENAME_EQ(X,Y) (strcasecmp (X,Y) == 0)
52 #if defined (WINDOWSNT)
53 #define PATH_LIST_SEPARATOR ';'
54 #define FILENAME_EQ(X,Y) (stricmp (X,Y) == 0)
56 #define PATH_LIST_SEPARATOR ':'
57 #define FILENAME_EQ(X,Y) (streq (X,Y))
60 /* The default output file name. */
62 #define DEFAULT_OUTFILE "BROWSE"
64 /* A version string written to the output file. Change this whenever
65 the structure of the output file changes. */
67 #define EBROWSE_FILE_VERSION "ebrowse 5.0"
69 /* The output file consists of a tree of Lisp objects, with major
70 nodes built out of Lisp structures. These are the heads of the
71 Lisp structs with symbols identifying their type. */
73 #define TREE_HEADER_STRUCT "[ebrowse-hs "
74 #define TREE_STRUCT "[ebrowse-ts "
75 #define MEMBER_STRUCT "[ebrowse-ms "
76 #define CLASS_STRUCT "[ebrowse-cs "
78 /* The name of the symbol table entry for global functions, variables,
79 defines etc. This name also appears in the browser display. */
81 #define GLOBALS_NAME "*Globals*"
83 /* Token definitions. */
87 YYEOF
= 0, /* end of file */
88 CSTRING
= 256, /* string constant */
89 CCHAR
, /* character constant */
90 CINT
, /* integral constant */
91 CFLOAT
, /* real constant */
97 IDENT
, /* identifier */
120 /* Keywords. The undef's are there because these
121 three symbols are very likely to be defined somewhere. */
134 CONTINUE
, /* continue */
135 DEFAULT
, /* default */
147 T_INLINE
, /* inline */
151 OPERATOR
, /* operator */
152 PRIVATE
, /* private */
153 PROTECTED
, /* protected */
155 REGISTER
, /* register */
163 TEMPLATE
, /* template */
167 TYPEDEF
, /* typedef */
169 UNSIGNED
, /* unsigned */
170 VIRTUAL
, /* virtual */
172 VOLATILE
, /* volatile */
174 MUTABLE
, /* mutable */
178 SIGNATURE
, /* signature (GNU extension) */
179 NAMESPACE
, /* namespace */
180 EXPLICIT
, /* explicit */
181 TYPENAME
, /* typename */
182 CONST_CAST
, /* const_cast */
183 DYNAMIC_CAST
, /* dynamic_cast */
184 REINTERPRET_CAST
, /* reinterpret_cast */
185 STATIC_CAST
, /* static_cast */
191 /* Storage classes, in a wider sense. */
196 SC_MEMBER
, /* Is an instance member. */
197 SC_STATIC
, /* Is static member. */
198 SC_FRIEND
, /* Is friend function. */
199 SC_TYPE
/* Is a type definition. */
202 /* Member visibility. */
213 #define F_VIRTUAL 1 /* Is virtual function. */
214 #define F_INLINE 2 /* Is inline function. */
215 #define F_CONST 4 /* Is const. */
216 #define F_PURE 8 /* Is pure virtual function. */
217 #define F_MUTABLE 16 /* Is mutable. */
218 #define F_TEMPLATE 32 /* Is a template. */
219 #define F_EXPLICIT 64 /* Is explicit constructor. */
220 #define F_THROW 128 /* Has a throw specification. */
221 #define F_EXTERNC 256 /* Is declared extern "C". */
222 #define F_DEFINE 512 /* Is a #define. */
224 /* Two macros to set and test a bit in an int. */
226 #define SET_FLAG(F, FLAG) ((F) |= (FLAG))
227 #define HAS_FLAG(F, FLAG) (((F) & (FLAG)) != 0)
229 /* Structure describing a class member. */
233 struct member
*next
; /* Next in list of members. */
234 struct member
*anext
; /* Collision chain in member_table. */
235 struct member
**list
; /* Pointer to list in class. */
236 unsigned param_hash
; /* Hash value for parameter types. */
237 int vis
; /* Visibility (public, ...). */
238 int flags
; /* See F_* above. */
239 char *regexp
; /* Matching regular expression. */
240 const char *filename
; /* Don't free this shared string. */
241 int pos
; /* Buffer position of occurrence. */
242 char *def_regexp
; /* Regular expression matching definition. */
243 const char *def_filename
; /* File name of definition. */
244 int def_pos
; /* Buffer position of definition. */
245 char name
[1]; /* Member name. */
248 /* Structures of this type are used to connect class structures with
249 their super and subclasses. */
253 struct sym
*sym
; /* The super or subclass. */
254 struct link
*next
; /* Next in list or NULL. */
257 /* Structure used to record namespace aliases. */
261 struct alias
*next
; /* Next in list. */
262 struct sym
*namesp
; /* Namespace in which defined. */
263 struct link
*aliasee
; /* List of aliased namespaces (A::B::C...). */
264 char name
[1]; /* Alias name. */
267 /* The structure used to describe a class in the symbol table,
268 or a namespace in all_namespaces. */
272 int flags
; /* Is class a template class?. */
273 unsigned char visited
; /* Used to find circles. */
274 struct sym
*next
; /* Hash collision list. */
275 struct link
*subs
; /* List of subclasses. */
276 struct link
*supers
; /* List of superclasses. */
277 struct member
*vars
; /* List of instance variables. */
278 struct member
*fns
; /* List of instance functions. */
279 struct member
*static_vars
; /* List of static variables. */
280 struct member
*static_fns
; /* List of static functions. */
281 struct member
*friends
; /* List of friend functions. */
282 struct member
*types
; /* List of local types. */
283 char *regexp
; /* Matching regular expression. */
284 int pos
; /* Buffer position. */
285 const char *filename
; /* File in which it can be found. */
286 const char *sfilename
; /* File in which members can be found. */
287 struct sym
*namesp
; /* Namespace in which defined. . */
288 char name
[1]; /* Name of the class. */
291 /* Experimental: Print info for `--position-info'. We print
292 '(CLASS-NAME SCOPE MEMBER-NAME). */
298 struct sym
*info_cls
= NULL
;
299 struct member
*info_member
= NULL
;
301 /* Experimental. For option `--position-info', the buffer position we
302 are interested in. When this position is reached, print out
303 information about what we know about that point. */
305 int info_position
= -1;
307 /* Command line options structure for getopt_long. */
309 struct option options
[] =
311 {"append", no_argument
, NULL
, 'a'},
312 {"files", required_argument
, NULL
, 'f'},
313 {"help", no_argument
, NULL
, -2},
314 {"min-regexp-length", required_argument
, NULL
, 'm'},
315 {"max-regexp-length", required_argument
, NULL
, 'M'},
316 {"no-nested-classes", no_argument
, NULL
, 'n'},
317 {"no-regexps", no_argument
, NULL
, 'x'},
318 {"no-structs-or-unions", no_argument
, NULL
, 's'},
319 {"output-file", required_argument
, NULL
, 'o'},
320 {"position-info", required_argument
, NULL
, 'p'},
321 {"search-path", required_argument
, NULL
, 'I'},
322 {"verbose", no_argument
, NULL
, 'v'},
323 {"version", no_argument
, NULL
, -3},
324 {"very-verbose", no_argument
, NULL
, 'V'},
328 /* Semantic values of tokens. Set by yylex.. */
330 unsigned yyival
; /* Set for token CINT. */
331 char *yytext
; /* Set for token IDENT. */
338 /* Current line number. */
342 /* The name of the current input file. */
344 const char *filename
;
346 /* Three character class vectors, and macros to test membership
353 #define IDENTP(C) is_ident[(unsigned char) (C)]
354 #define DIGITP(C) is_digit[(unsigned char) (C)]
355 #define WHITEP(C) is_white[(unsigned char) (C)]
357 /* Command line flags. */
364 int f_nested_classes
= 1;
366 /* Maximum and minimum lengths of regular expressions matching a
367 member, class etc., for writing them to the output file. These are
368 overridable from the command line. */
377 size_t inbuffer_size
;
379 /* Return the current buffer position in the input file. */
381 #define BUFFER_POS() (in - inbuffer)
383 /* If current lookahead is CSTRING, the following points to the
384 first character in the string constant. Used for recognizing
389 /* The size of the hash tables for classes.and members. Should be
392 #define TABLE_SIZE 1001
394 /* The hash table for class symbols. */
396 struct sym
*class_table
[TABLE_SIZE
];
398 /* Hash table containing all member structures. This is generally
399 faster for member lookup than traversing the member lists of a
402 struct member
*member_table
[TABLE_SIZE
];
404 /* Hash table for namespace aliases */
406 struct alias
*namespace_alias_table
[TABLE_SIZE
];
408 /* The special class symbol used to hold global functions,
411 struct sym
*global_symbols
;
413 /* The current namespace. */
415 struct sym
*current_namespace
;
417 /* The list of all known namespaces. */
419 struct sym
*all_namespaces
;
421 /* Stack of namespaces we're currently nested in, during the parse. */
423 struct sym
**namespace_stack
;
424 int namespace_stack_size
;
427 /* The current lookahead token. */
431 /* Structure describing a keyword. */
435 const char *name
; /* Spelling. */
436 int tk
; /* Token value. */
437 struct kw
*next
; /* Next in collision chain. */
440 /* Keywords are lookup up in a hash table of their own. */
442 #define KEYWORD_TABLE_SIZE 1001
443 struct kw
*keyword_table
[KEYWORD_TABLE_SIZE
];
450 struct search_path
*next
;
453 struct search_path
*search_path
;
454 struct search_path
*search_path_tail
;
456 /* Function prototypes. */
458 static char *matching_regexp (void);
459 static struct sym
*add_sym (const char *, struct sym
*);
460 static void add_global_defn (char *, char *, int, unsigned, int, int, int);
461 static void add_global_decl (char *, char *, int, unsigned, int, int, int);
462 static struct member
*add_member (struct sym
*, char *, int, int, unsigned);
463 static void class_definition (struct sym
*, int, int, int);
464 static char *operator_name (int *);
465 static void parse_qualified_param_ident_or_type (char **);
466 static void usage (int) NO_RETURN
;
467 static void version (void) NO_RETURN
;
471 /***********************************************************************
473 ***********************************************************************/
475 /* Print an error in a printf-like style with the current input file
476 name and line number. */
479 yyerror (const char *format
, const char *s
)
481 fprintf (stderr
, "%s:%d: ", filename
, yyline
);
482 fprintf (stderr
, format
, s
);
487 /* Like malloc but print an error and exit if not enough memory is
491 xmalloc (size_t nbytes
)
493 void *p
= malloc (nbytes
);
496 yyerror ("out of memory", NULL
);
503 /* Like realloc but print an error and exit if out of memory. */
506 xrealloc (void *p
, size_t sz
)
511 yyerror ("out of memory", NULL
);
518 /* Like strdup, but print an error and exit if not enough memory is
519 available.. If S is null, return null. */
525 s
= strcpy (xmalloc (strlen (s
) + 1), s
);
531 /***********************************************************************
533 ***********************************************************************/
535 /* Initialize the symbol table. This currently only sets up the
536 special symbol for globals (`*Globals*'). */
541 global_symbols
= add_sym (GLOBALS_NAME
, NULL
);
545 /* Add a symbol for class NAME to the symbol table. NESTED_IN_CLASS
546 is the class in which class NAME was found. If it is null,
547 this means the scope of NAME is the current namespace.
549 If a symbol for NAME already exists, return that. Otherwise
550 create a new symbol and set it to default values. */
553 add_sym (const char *name
, struct sym
*nested_in_class
)
558 struct sym
*scope
= nested_in_class
? nested_in_class
: current_namespace
;
560 for (s
= name
, h
= 0; *s
; ++s
)
564 for (sym
= class_table
[h
]; sym
; sym
= sym
->next
)
565 if (streq (name
, sym
->name
)
566 && ((!sym
->namesp
&& !scope
)
567 || (sym
->namesp
&& scope
568 && streq (sym
->namesp
->name
, scope
->name
))))
579 sym
= (struct sym
*) xmalloc (sizeof *sym
+ strlen (name
));
580 memset (sym
, 0, sizeof *sym
);
581 strcpy (sym
->name
, name
);
583 sym
->next
= class_table
[h
];
584 class_table
[h
] = sym
;
591 /* Add links between superclass SUPER and subclass SUB. */
594 add_link (struct sym
*super
, struct sym
*sub
)
596 struct link
*lnk
, *lnk2
, *p
, *prev
;
598 /* See if a link already exists. */
599 for (p
= super
->subs
, prev
= NULL
;
600 p
&& strcmp (sub
->name
, p
->sym
->name
) > 0;
601 prev
= p
, p
= p
->next
)
604 /* Avoid duplicates. */
605 if (p
== NULL
|| p
->sym
!= sub
)
607 lnk
= (struct link
*) xmalloc (sizeof *lnk
);
608 lnk2
= (struct link
*) xmalloc (sizeof *lnk2
);
619 lnk2
->next
= sub
->supers
;
625 /* Find in class CLS member NAME.
627 VAR non-zero means look for a member variable; otherwise a function
628 is searched. SC specifies what kind of member is searched---a
629 static, or per-instance member etc. HASH is a hash code for the
630 parameter types of functions. Value is a pointer to the member
631 found or null if not found. */
633 static struct member
*
634 find_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
636 struct member
**list
;
638 unsigned name_hash
= 0;
645 list
= &cls
->friends
;
653 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
657 list
= var
? &cls
->vars
: &cls
->fns
;
661 for (s
= name
; *s
; ++s
)
662 name_hash
= (name_hash
<< 1) ^ *s
;
663 i
= name_hash
% TABLE_SIZE
;
665 for (p
= member_table
[i
]; p
; p
= p
->anext
)
666 if (p
->list
== list
&& p
->param_hash
== hash
&& streq (name
, p
->name
))
673 /* Add to class CLS information for the declaration of member NAME.
674 REGEXP is a regexp matching the declaration, if non-null. POS is
675 the position in the source where the declaration is found. HASH is
676 a hash code for the parameter list of the member, if it's a
677 function. VAR non-zero means member is a variable or type. SC
678 specifies the type of member (instance member, static, ...). VIS
679 is the member's visibility (public, protected, private). FLAGS is
680 a bit set giving additional information about the member (see the
684 add_member_decl (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int vis
, int flags
)
688 m
= find_member (cls
, name
, var
, sc
, hash
);
690 m
= add_member (cls
, name
, var
, sc
, hash
);
692 /* Have we seen a new filename? If so record that. */
693 if (!cls
->filename
|| !FILENAME_EQ (cls
->filename
, filename
))
694 m
->filename
= filename
;
707 m
->vis
= V_PROTECTED
;
721 /* Add to class CLS information for the definition of member NAME.
722 REGEXP is a regexp matching the declaration, if non-null. POS is
723 the position in the source where the declaration is found. HASH is
724 a hash code for the parameter list of the member, if it's a
725 function. VAR non-zero means member is a variable or type. SC
726 specifies the type of member (instance member, static, ...). VIS
727 is the member's visibility (public, protected, private). FLAGS is
728 a bit set giving additional information about the member (see the
732 add_member_defn (struct sym
*cls
, char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
736 if (sc
== SC_UNKNOWN
)
738 m
= find_member (cls
, name
, var
, SC_MEMBER
, hash
);
741 m
= find_member (cls
, name
, var
, SC_STATIC
, hash
);
743 m
= add_member (cls
, name
, var
, sc
, hash
);
748 m
= find_member (cls
, name
, var
, sc
, hash
);
750 m
= add_member (cls
, name
, var
, sc
, hash
);
754 cls
->sfilename
= filename
;
756 if (!FILENAME_EQ (cls
->sfilename
, filename
))
757 m
->def_filename
= filename
;
759 m
->def_regexp
= regexp
;
769 /* Add a symbol for a define named NAME to the symbol table.
770 REGEXP is a regular expression matching the define in the source,
771 if it is non-null. POS is the position in the file. */
774 add_define (char *name
, char *regexp
, int pos
)
776 add_global_defn (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
777 add_global_decl (name
, regexp
, pos
, 0, 1, SC_FRIEND
, F_DEFINE
);
781 /* Add information for the global definition of NAME.
782 REGEXP is a regexp matching the declaration, if non-null. POS is
783 the position in the source where the declaration is found. HASH is
784 a hash code for the parameter list of the member, if it's a
785 function. VAR non-zero means member is a variable or type. SC
786 specifies the type of member (instance member, static, ...). VIS
787 is the member's visibility (public, protected, private). FLAGS is
788 a bit set giving additional information about the member (see the
792 add_global_defn (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
797 /* Try to find out for which classes a function is a friend, and add
798 what we know about it to them. */
800 for (i
= 0; i
< TABLE_SIZE
; ++i
)
801 for (sym
= class_table
[i
]; sym
; sym
= sym
->next
)
802 if (sym
!= global_symbols
&& sym
->friends
)
803 if (find_member (sym
, name
, 0, SC_FRIEND
, hash
))
804 add_member_defn (sym
, name
, regexp
, pos
, hash
, 0,
807 /* Add to global symbols. */
808 add_member_defn (global_symbols
, name
, regexp
, pos
, hash
, var
, sc
, flags
);
812 /* Add information for the global declaration of NAME.
813 REGEXP is a regexp matching the declaration, if non-null. POS is
814 the position in the source where the declaration is found. HASH is
815 a hash code for the parameter list of the member, if it's a
816 function. VAR non-zero means member is a variable or type. SC
817 specifies the type of member (instance member, static, ...). VIS
818 is the member's visibility (public, protected, private). FLAGS is
819 a bit set giving additional information about the member (see the
823 add_global_decl (char *name
, char *regexp
, int pos
, unsigned int hash
, int var
, int sc
, int flags
)
825 /* Add declaration only if not already declared. Header files must
826 be processed before source files for this to have the right effect.
827 I do not want to handle implicit declarations at the moment. */
829 struct member
*found
;
831 m
= found
= find_member (global_symbols
, name
, var
, sc
, hash
);
833 m
= add_member (global_symbols
, name
, var
, sc
, hash
);
835 /* Definition already seen => probably last declaration implicit.
836 Override. This means that declarations must always be added to
837 the symbol table before definitions. */
840 if (!global_symbols
->filename
841 || !FILENAME_EQ (global_symbols
->filename
, filename
))
842 m
->filename
= filename
;
850 info_cls
= global_symbols
;
856 /* Add a symbol for member NAME to class CLS.
857 VAR non-zero means it's a variable. SC specifies the kind of
858 member. HASH is a hash code for the parameter types of a function.
859 Value is a pointer to the member's structure. */
861 static struct member
*
862 add_member (struct sym
*cls
, char *name
, int var
, int sc
, unsigned int hash
)
864 struct member
*m
= (struct member
*) xmalloc (sizeof *m
+ strlen (name
));
865 struct member
**list
;
868 unsigned name_hash
= 0;
872 strcpy (m
->name
, name
);
873 m
->param_hash
= hash
;
880 m
->def_regexp
= NULL
;
881 m
->def_filename
= NULL
;
884 assert (cls
!= NULL
);
889 list
= &cls
->friends
;
897 list
= var
? &cls
->static_vars
: &cls
->static_fns
;
901 list
= var
? &cls
->vars
: &cls
->fns
;
905 for (s
= name
; *s
; ++s
)
906 name_hash
= (name_hash
<< 1) ^ *s
;
907 i
= name_hash
% TABLE_SIZE
;
908 m
->anext
= member_table
[i
];
912 /* Keep the member list sorted. It's cheaper to do it here than to
913 sort them in Lisp. */
914 for (prev
= NULL
, p
= *list
;
915 p
&& strcmp (name
, p
->name
) > 0;
916 prev
= p
, p
= p
->next
)
928 /* Given the root R of a class tree, step through all subclasses
929 recursively, marking functions as virtual that are declared virtual
933 mark_virtual (struct sym
*r
)
936 struct member
*m
, *m2
;
938 for (p
= r
->subs
; p
; p
= p
->next
)
940 for (m
= r
->fns
; m
; m
= m
->next
)
941 if (HAS_FLAG (m
->flags
, F_VIRTUAL
))
943 for (m2
= p
->sym
->fns
; m2
; m2
= m2
->next
)
944 if (m
->param_hash
== m2
->param_hash
&& streq (m
->name
, m2
->name
))
945 SET_FLAG (m2
->flags
, F_VIRTUAL
);
948 mark_virtual (p
->sym
);
953 /* For all roots of the class tree, mark functions as virtual that
954 are virtual because of a virtual declaration in a base class. */
957 mark_inherited_virtual (void)
962 for (i
= 0; i
< TABLE_SIZE
; ++i
)
963 for (r
= class_table
[i
]; r
; r
= r
->next
)
964 if (r
->supers
== NULL
)
969 /* Create and return a symbol for a namespace with name NAME. */
972 make_namespace (char *name
, struct sym
*context
)
974 struct sym
*s
= (struct sym
*) xmalloc (sizeof *s
+ strlen (name
));
975 memset (s
, 0, sizeof *s
);
976 strcpy (s
->name
, name
);
977 s
->next
= all_namespaces
;
984 /* Find the symbol for namespace NAME. If not found, return NULL */
987 check_namespace (char *name
, struct sym
*context
)
989 struct sym
*p
= NULL
;
991 for (p
= all_namespaces
; p
; p
= p
->next
)
993 if (streq (p
->name
, name
) && (p
->namesp
== context
))
1000 /* Find the symbol for namespace NAME. If not found, add a new symbol
1001 for NAME to all_namespaces. */
1004 find_namespace (char *name
, struct sym
*context
)
1006 struct sym
*p
= check_namespace (name
, context
);
1009 p
= make_namespace (name
, context
);
1015 /* Find namespace alias with name NAME. If not found return NULL. */
1017 static struct link
*
1018 check_namespace_alias (char *name
)
1020 struct link
*p
= NULL
;
1025 for (s
= name
, h
= 0; *s
; ++s
)
1029 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1030 if (streq (name
, al
->name
) && (al
->namesp
== current_namespace
))
1039 /* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */
1042 register_namespace_alias (char *new_name
, struct link
*old_name
)
1048 for (s
= new_name
, h
= 0; *s
; ++s
)
1053 /* Is it already in the table of aliases? */
1054 for (al
= namespace_alias_table
[h
]; al
; al
= al
->next
)
1055 if (streq (new_name
, al
->name
) && (al
->namesp
== current_namespace
))
1058 al
= (struct alias
*) xmalloc (sizeof *al
+ strlen (new_name
));
1059 strcpy (al
->name
, new_name
);
1060 al
->next
= namespace_alias_table
[h
];
1061 al
->namesp
= current_namespace
;
1062 al
->aliasee
= old_name
;
1063 namespace_alias_table
[h
] = al
;
1067 /* Enter namespace with name NAME. */
1070 enter_namespace (char *name
)
1072 struct sym
*p
= find_namespace (name
, current_namespace
);
1074 if (namespace_sp
== namespace_stack_size
)
1076 int size
= max (10, 2 * namespace_stack_size
);
1078 = (struct sym
**) xrealloc ((void *)namespace_stack
,
1079 size
* sizeof *namespace_stack
);
1080 namespace_stack_size
= size
;
1083 namespace_stack
[namespace_sp
++] = current_namespace
;
1084 current_namespace
= p
;
1088 /* Leave the current namespace. */
1091 leave_namespace (void)
1093 assert (namespace_sp
> 0);
1094 current_namespace
= namespace_stack
[--namespace_sp
];
1099 /***********************************************************************
1100 Writing the Output File
1101 ***********************************************************************/
1103 /* Write string S to the output file FP in a Lisp-readable form.
1104 If S is null, write out `()'. */
1107 putstr (const char *s
, FILE *fp
)
1124 /* A dynamically allocated buffer for constructing a scope name. */
1127 int scope_buffer_size
;
1128 int scope_buffer_len
;
1131 /* Make sure scope_buffer has enough room to add LEN chars to it. */
1134 ensure_scope_buffer_room (int len
)
1136 if (scope_buffer_len
+ len
>= scope_buffer_size
)
1138 int new_size
= max (2 * scope_buffer_size
, scope_buffer_len
+ len
);
1139 scope_buffer
= (char *) xrealloc (scope_buffer
, new_size
);
1140 scope_buffer_size
= new_size
;
1145 /* Recursively add the scope names of symbol P and the scopes of its
1146 namespaces to scope_buffer. Value is a pointer to the complete
1147 scope name constructed. */
1150 sym_scope_1 (struct sym
*p
)
1155 sym_scope_1 (p
->namesp
);
1159 ensure_scope_buffer_room (3);
1160 strcat (scope_buffer
, "::");
1161 scope_buffer_len
+= 2;
1164 len
= strlen (p
->name
);
1165 ensure_scope_buffer_room (len
+ 1);
1166 strcat (scope_buffer
, p
->name
);
1167 scope_buffer_len
+= len
;
1169 if (HAS_FLAG (p
->flags
, F_TEMPLATE
))
1171 ensure_scope_buffer_room (3);
1172 strcat (scope_buffer
, "<>");
1173 scope_buffer_len
+= 2;
1176 return scope_buffer
;
1180 /* Return the scope of symbol P in printed representation, i.e.
1181 as it would appear in a C*+ source file. */
1184 sym_scope (struct sym
*p
)
1188 scope_buffer_size
= 1024;
1189 scope_buffer
= (char *) xmalloc (scope_buffer_size
);
1192 *scope_buffer
= '\0';
1193 scope_buffer_len
= 0;
1196 sym_scope_1 (p
->namesp
);
1198 return scope_buffer
;
1202 /* Dump the list of members M to file FP. Value is the length of the
1206 dump_members (FILE *fp
, struct member
*m
)
1212 for (n
= 0; m
; m
= m
->next
, ++n
)
1214 fputs (MEMBER_STRUCT
, fp
);
1215 putstr (m
->name
, fp
);
1216 putstr (NULL
, fp
); /* FIXME? scope for globals */
1217 fprintf (fp
, "%u ", (unsigned) m
->flags
);
1218 putstr (m
->filename
, fp
);
1219 putstr (m
->regexp
, fp
);
1220 fprintf (fp
, "%u ", (unsigned) m
->pos
);
1221 fprintf (fp
, "%u ", (unsigned) m
->vis
);
1223 putstr (m
->def_filename
, fp
);
1224 putstr (m
->def_regexp
, fp
);
1225 fprintf (fp
, "%u", (unsigned) m
->def_pos
);
1236 /* Dump class ROOT to stream FP. */
1239 dump_sym (FILE *fp
, struct sym
*root
)
1241 fputs (CLASS_STRUCT
, fp
);
1242 putstr (root
->name
, fp
);
1244 /* Print scope, if any. */
1246 putstr (sym_scope (root
), fp
);
1251 fprintf (fp
, "%u", root
->flags
);
1252 putstr (root
->filename
, fp
);
1253 putstr (root
->regexp
, fp
);
1254 fprintf (fp
, "%u", (unsigned) root
->pos
);
1255 putstr (root
->sfilename
, fp
);
1261 /* Dump class ROOT and its subclasses to file FP. Value is the
1262 number of classes written. */
1265 dump_tree (FILE *fp
, struct sym
*root
)
1270 dump_sym (fp
, root
);
1280 for (lk
= root
->subs
; lk
; lk
= lk
->next
)
1282 fputs (TREE_STRUCT
, fp
);
1283 n
+= dump_tree (fp
, lk
->sym
);
1289 dump_members (fp
, root
->vars
);
1290 n
+= dump_members (fp
, root
->fns
);
1291 dump_members (fp
, root
->static_vars
);
1292 n
+= dump_members (fp
, root
->static_fns
);
1293 n
+= dump_members (fp
, root
->friends
);
1294 dump_members (fp
, root
->types
);
1309 /* Dump the entire class tree to file FP. */
1312 dump_roots (FILE *fp
)
1317 /* Output file header containing version string, command line
1321 fputs (TREE_HEADER_STRUCT
, fp
);
1322 putstr (EBROWSE_FILE_VERSION
, fp
);
1335 /* Mark functions as virtual that are so because of functions
1336 declared virtual in base classes. */
1337 mark_inherited_virtual ();
1339 /* Dump the roots of the graph. */
1340 for (i
= 0; i
< TABLE_SIZE
; ++i
)
1341 for (r
= class_table
[i
]; r
; r
= r
->next
)
1344 fputs (TREE_STRUCT
, fp
);
1345 n
+= dump_tree (fp
, r
);
1355 /***********************************************************************
1357 ***********************************************************************/
1360 #define INCREMENT_LINENO \
1362 if (f_very_verbose) \
1365 printf ("%d:\n", yyline); \
1371 #define INCREMENT_LINENO ++yyline
1374 /* Define two macros for accessing the input buffer (current input
1375 file). GET(C) sets C to the next input character and advances the
1376 input pointer. UNGET retracts the input pointer. */
1378 #define GET(C) ((C) = *in++)
1379 #define UNGET() (--in)
1382 /* Process a preprocessor line. Value is the next character from the
1383 input buffer not consumed. */
1386 process_pp_line (void)
1388 int in_comment
= 0, in_string
= 0;
1392 /* Skip over white space. The `#' has been consumed already. */
1393 while (WHITEP (GET (c
)))
1396 /* Read the preprocessor command (if any). */
1403 /* Is it a `define'? */
1406 if (*yytext
&& streq (yytext
, "define"))
1421 char *regexp
= matching_regexp ();
1422 int pos
= BUFFER_POS ();
1423 add_define (yytext
, regexp
, pos
);
1427 while (c
&& (c
!= '\n' || in_comment
|| in_string
))
1431 else if (c
== '/' && !in_comment
)
1436 else if (c
== '*' && in_comment
)
1442 in_string
= !in_string
;
1454 /* Value is the next token from the input buffer. */
1465 while (WHITEP (GET (c
)))
1487 /* String and character constants. */
1490 while (GET (c
) && c
!= end_char
)
1495 /* Escape sequences. */
1498 if (end_char
== '\'')
1499 yyerror ("EOF in character constant", NULL
);
1501 yyerror ("EOF in string constant", NULL
);
1519 /* Hexadecimal escape sequence. */
1521 for (i
= 0; i
< 2; ++i
)
1525 if (c
>= '0' && c
<= '7')
1527 else if (c
>= 'a' && c
<= 'f')
1529 else if (c
>= 'A' && c
<= 'F')
1542 /* Octal escape sequence. */
1544 for (i
= 0; i
< 3; ++i
)
1548 if (c
>= '0' && c
<= '7')
1565 if (end_char
== '\'')
1566 yyerror ("newline in character constant", NULL
);
1568 yyerror ("newline in string constant", NULL
);
1578 return end_char
== '\'' ? CCHAR
: CSTRING
;
1580 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1581 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1582 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1583 case 'v': case 'w': case 'x': case 'y': case 'z':
1584 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
1585 case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
1586 case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
1587 case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_':
1589 /* Identifier and keywords. */
1596 while (IDENTP (GET (*p
)))
1598 hash
= (hash
<< 1) ^ *p
++;
1599 if (p
== yytext_end
- 1)
1601 int size
= yytext_end
- yytext
;
1602 yytext
= (char *) xrealloc (yytext
, 2 * size
);
1603 yytext_end
= yytext
+ 2 * size
;
1604 p
= yytext
+ size
- 1;
1611 for (k
= keyword_table
[hash
% KEYWORD_TABLE_SIZE
]; k
; k
= k
->next
)
1612 if (streq (k
->name
, yytext
))
1619 /* C and C++ comments, '/' and '/='. */
1647 while (GET (c
) && c
!= '\n')
1649 /* Don't try to read past the end of the input buffer if
1650 the file ends in a C++ comment without a newline. */
1727 yyerror ("invalid token '..' ('...' assumed)", NULL
);
1731 else if (!DIGITP (c
))
1785 c
= process_pp_line ();
1790 case '(': case ')': case '[': case ']': case '{': case '}':
1791 case ';': case ',': case '?': case '~':
1797 if (GET (c
) == 'x' || c
== 'X')
1802 yyival
= yyival
* 16 + c
- '0';
1803 else if (c
>= 'a' && c
<= 'f')
1804 yyival
= yyival
* 16 + c
- 'a' + 10;
1805 else if (c
>= 'A' && c
<= 'F')
1806 yyival
= yyival
* 16 + c
- 'A' + 10;
1816 while (c
>= '0' && c
<= '7')
1818 yyival
= (yyival
<< 3) + c
- '0';
1823 /* Integer suffixes. */
1829 case '1': case '2': case '3': case '4': case '5': case '6':
1830 case '7': case '8': case '9':
1831 /* Integer or floating constant, part before '.'. */
1834 while (GET (c
) && DIGITP (c
))
1835 yyival
= 10 * yyival
+ c
- '0';
1841 /* Digits following '.'. */
1845 /* Optional exponent. */
1846 if (c
== 'E' || c
== 'e')
1848 if (GET (c
) == '-' || c
== '+')
1855 /* Optional type suffixes. */
1868 /* Actually local to matching_regexp. These variables must be in
1869 global scope for the case that `static' get's defined away. */
1871 static char *matching_regexp_buffer
, *matching_regexp_end_buf
;
1874 /* Value is the string from the start of the line to the current
1875 position in the input buffer, or maybe a bit more if that string is
1876 shorter than min_regexp. */
1879 matching_regexp (void)
1888 if (matching_regexp_buffer
== NULL
)
1890 matching_regexp_buffer
= (char *) xmalloc (max_regexp
);
1891 matching_regexp_end_buf
= &matching_regexp_buffer
[max_regexp
] - 1;
1894 /* Scan back to previous newline of buffer start. */
1895 for (p
= in
- 1; p
> inbuffer
&& *p
!= '\n'; --p
)
1900 while (in
- p
< min_regexp
&& p
> inbuffer
)
1902 /* Line probably not significant enough */
1903 for (--p
; p
> inbuffer
&& *p
!= '\n'; --p
)
1910 /* Copy from end to make sure significant portions are included.
1911 This implies that in the browser a regular expressing of the form
1912 `^.*{regexp}' has to be used. */
1913 for (s
= matching_regexp_end_buf
- 1, t
= in
;
1914 s
> matching_regexp_buffer
&& t
> p
;)
1918 if (*s
== '"' || *s
== '\\')
1922 *(matching_regexp_end_buf
- 1) = '\0';
1927 /* Return a printable representation of token T. */
1930 token_string (int t
)
1936 case CSTRING
: return "string constant";
1937 case CCHAR
: return "char constant";
1938 case CINT
: return "int constant";
1939 case CFLOAT
: return "floating constant";
1940 case ELLIPSIS
: return "...";
1941 case LSHIFTASGN
: return "<<=";
1942 case RSHIFTASGN
: return ">>=";
1943 case ARROWSTAR
: return "->*";
1944 case IDENT
: return "identifier";
1945 case DIVASGN
: return "/=";
1946 case INC
: return "++";
1947 case ADDASGN
: return "+=";
1948 case DEC
: return "--";
1949 case ARROW
: return "->";
1950 case SUBASGN
: return "-=";
1951 case MULASGN
: return "*=";
1952 case MODASGN
: return "%=";
1953 case LOR
: return "||";
1954 case ORASGN
: return "|=";
1955 case LAND
: return "&&";
1956 case ANDASGN
: return "&=";
1957 case XORASGN
: return "^=";
1958 case POINTSTAR
: return ".*";
1959 case DCOLON
: return "::";
1960 case EQ
: return "==";
1961 case NE
: return "!=";
1962 case LE
: return "<=";
1963 case LSHIFT
: return "<<";
1964 case GE
: return ">=";
1965 case RSHIFT
: return ">>";
1966 case ASM
: return "asm";
1967 case AUTO
: return "auto";
1968 case BREAK
: return "break";
1969 case CASE
: return "case";
1970 case CATCH
: return "catch";
1971 case CHAR
: return "char";
1972 case CLASS
: return "class";
1973 case CONST
: return "const";
1974 case CONTINUE
: return "continue";
1975 case DEFAULT
: return "default";
1976 case DELETE
: return "delete";
1977 case DO
: return "do";
1978 case DOUBLE
: return "double";
1979 case ELSE
: return "else";
1980 case ENUM
: return "enum";
1981 case EXTERN
: return "extern";
1982 case FLOAT
: return "float";
1983 case FOR
: return "for";
1984 case FRIEND
: return "friend";
1985 case GOTO
: return "goto";
1986 case IF
: return "if";
1987 case T_INLINE
: return "inline";
1988 case INT
: return "int";
1989 case LONG
: return "long";
1990 case NEW
: return "new";
1991 case OPERATOR
: return "operator";
1992 case PRIVATE
: return "private";
1993 case PROTECTED
: return "protected";
1994 case PUBLIC
: return "public";
1995 case REGISTER
: return "register";
1996 case RETURN
: return "return";
1997 case SHORT
: return "short";
1998 case SIGNED
: return "signed";
1999 case SIZEOF
: return "sizeof";
2000 case STATIC
: return "static";
2001 case STRUCT
: return "struct";
2002 case SWITCH
: return "switch";
2003 case TEMPLATE
: return "template";
2004 case THIS
: return "this";
2005 case THROW
: return "throw";
2006 case TRY
: return "try";
2007 case TYPEDEF
: return "typedef";
2008 case UNION
: return "union";
2009 case UNSIGNED
: return "unsigned";
2010 case VIRTUAL
: return "virtual";
2011 case VOID
: return "void";
2012 case VOLATILE
: return "volatile";
2013 case WHILE
: return "while";
2014 case MUTABLE
: return "mutable";
2015 case BOOL
: return "bool";
2016 case TRUE
: return "true";
2017 case FALSE
: return "false";
2018 case SIGNATURE
: return "signature";
2019 case NAMESPACE
: return "namespace";
2020 case EXPLICIT
: return "explicit";
2021 case TYPENAME
: return "typename";
2022 case CONST_CAST
: return "const_cast";
2023 case DYNAMIC_CAST
: return "dynamic_cast";
2024 case REINTERPRET_CAST
: return "reinterpret_cast";
2025 case STATIC_CAST
: return "static_cast";
2026 case TYPEID
: return "typeid";
2027 case USING
: return "using";
2028 case WCHAR
: return "wchar_t";
2029 case YYEOF
: return "EOF";
2044 /* Reinitialize the scanner for a new input file. */
2047 re_init_scanner (void)
2055 yytext
= (char *) xmalloc (size
* sizeof *yytext
);
2056 yytext_end
= yytext
+ size
;
2061 /* Insert a keyword NAME with token value TKV into the keyword hash
2065 insert_keyword (const char *name
, int tkv
)
2069 struct kw
*k
= (struct kw
*) xmalloc (sizeof *k
);
2071 for (s
= name
; *s
; ++s
)
2074 h
%= KEYWORD_TABLE_SIZE
;
2077 k
->next
= keyword_table
[h
];
2078 keyword_table
[h
] = k
;
2082 /* Initialize the scanner for the first file. This sets up the
2083 character class vectors and fills the keyword hash table. */
2090 /* Allocate the input buffer */
2091 inbuffer_size
= READ_CHUNK_SIZE
+ 1;
2092 inbuffer
= in
= (char *) xmalloc (inbuffer_size
);
2095 /* Set up character class vectors. */
2096 for (i
= 0; i
< sizeof is_ident
; ++i
)
2098 if (i
== '_' || isalnum (i
))
2101 if (i
>= '0' && i
<= '9')
2104 if (i
== ' ' || i
== '\t' || i
== '\f' || i
== '\v')
2108 /* Fill keyword hash table. */
2109 insert_keyword ("and", LAND
);
2110 insert_keyword ("and_eq", ANDASGN
);
2111 insert_keyword ("asm", ASM
);
2112 insert_keyword ("auto", AUTO
);
2113 insert_keyword ("bitand", '&');
2114 insert_keyword ("bitor", '|');
2115 insert_keyword ("bool", BOOL
);
2116 insert_keyword ("break", BREAK
);
2117 insert_keyword ("case", CASE
);
2118 insert_keyword ("catch", CATCH
);
2119 insert_keyword ("char", CHAR
);
2120 insert_keyword ("class", CLASS
);
2121 insert_keyword ("compl", '~');
2122 insert_keyword ("const", CONST
);
2123 insert_keyword ("const_cast", CONST_CAST
);
2124 insert_keyword ("continue", CONTINUE
);
2125 insert_keyword ("default", DEFAULT
);
2126 insert_keyword ("delete", DELETE
);
2127 insert_keyword ("do", DO
);
2128 insert_keyword ("double", DOUBLE
);
2129 insert_keyword ("dynamic_cast", DYNAMIC_CAST
);
2130 insert_keyword ("else", ELSE
);
2131 insert_keyword ("enum", ENUM
);
2132 insert_keyword ("explicit", EXPLICIT
);
2133 insert_keyword ("extern", EXTERN
);
2134 insert_keyword ("false", FALSE
);
2135 insert_keyword ("float", FLOAT
);
2136 insert_keyword ("for", FOR
);
2137 insert_keyword ("friend", FRIEND
);
2138 insert_keyword ("goto", GOTO
);
2139 insert_keyword ("if", IF
);
2140 insert_keyword ("inline", T_INLINE
);
2141 insert_keyword ("int", INT
);
2142 insert_keyword ("long", LONG
);
2143 insert_keyword ("mutable", MUTABLE
);
2144 insert_keyword ("namespace", NAMESPACE
);
2145 insert_keyword ("new", NEW
);
2146 insert_keyword ("not", '!');
2147 insert_keyword ("not_eq", NE
);
2148 insert_keyword ("operator", OPERATOR
);
2149 insert_keyword ("or", LOR
);
2150 insert_keyword ("or_eq", ORASGN
);
2151 insert_keyword ("private", PRIVATE
);
2152 insert_keyword ("protected", PROTECTED
);
2153 insert_keyword ("public", PUBLIC
);
2154 insert_keyword ("register", REGISTER
);
2155 insert_keyword ("reinterpret_cast", REINTERPRET_CAST
);
2156 insert_keyword ("return", RETURN
);
2157 insert_keyword ("short", SHORT
);
2158 insert_keyword ("signed", SIGNED
);
2159 insert_keyword ("sizeof", SIZEOF
);
2160 insert_keyword ("static", STATIC
);
2161 insert_keyword ("static_cast", STATIC_CAST
);
2162 insert_keyword ("struct", STRUCT
);
2163 insert_keyword ("switch", SWITCH
);
2164 insert_keyword ("template", TEMPLATE
);
2165 insert_keyword ("this", THIS
);
2166 insert_keyword ("throw", THROW
);
2167 insert_keyword ("true", TRUE
);
2168 insert_keyword ("try", TRY
);
2169 insert_keyword ("typedef", TYPEDEF
);
2170 insert_keyword ("typeid", TYPEID
);
2171 insert_keyword ("typename", TYPENAME
);
2172 insert_keyword ("union", UNION
);
2173 insert_keyword ("unsigned", UNSIGNED
);
2174 insert_keyword ("using", USING
);
2175 insert_keyword ("virtual", VIRTUAL
);
2176 insert_keyword ("void", VOID
);
2177 insert_keyword ("volatile", VOLATILE
);
2178 insert_keyword ("wchar_t", WCHAR
);
2179 insert_keyword ("while", WHILE
);
2180 insert_keyword ("xor", '^');
2181 insert_keyword ("xor_eq", XORASGN
);
2186 /***********************************************************************
2188 ***********************************************************************/
2190 /* Match the current lookahead token and set it to the next token. */
2192 #define MATCH() (tk = yylex ())
2194 /* Return the lookahead token. If current lookahead token is cleared,
2195 read a new token. */
2197 #define LA1 (tk == -1 ? (tk = yylex ()) : tk)
2199 /* Is the current lookahead equal to the token T? */
2201 #define LOOKING_AT(T) (tk == (T))
2203 /* Is the current lookahead one of T1 or T2? */
2205 #define LOOKING_AT2(T1, T2) (tk == (T1) || tk == (T2))
2207 /* Is the current lookahead one of T1, T2 or T3? */
2209 #define LOOKING_AT3(T1, T2, T3) (tk == (T1) || tk == (T2) || tk == (T3))
2211 /* Is the current lookahead one of T1...T4? */
2213 #define LOOKING_AT4(T1, T2, T3, T4) \
2214 (tk == (T1) || tk == (T2) || tk == (T3) || tk == (T4))
2216 /* Match token T if current lookahead is T. */
2218 #define MATCH_IF(T) if (LOOKING_AT (T)) MATCH (); else ((void) 0)
2220 /* Skip to matching token if current token is T. */
2222 #define SKIP_MATCHING_IF(T) \
2223 if (LOOKING_AT (T)) skip_matching (); else ((void) 0)
2226 /* Skip forward until a given token TOKEN or YYEOF is seen and return
2227 the current lookahead token after skipping. */
2232 while (!LOOKING_AT2 (YYEOF
, token
))
2237 /* Skip over pairs of tokens (parentheses, square brackets,
2238 angle brackets, curly brackets) matching the current lookahead. */
2241 skip_matching (void)
2269 if (LOOKING_AT (open
))
2271 else if (LOOKING_AT (close
))
2273 else if (LOOKING_AT (YYEOF
))
2284 skip_initializer (void)
2308 /* Build qualified namespace alias (A::B::c) and return it. */
2310 static struct link
*
2311 match_qualified_namespace_alias (void)
2313 struct link
*head
= NULL
;
2314 struct link
*cur
= NULL
;
2315 struct link
*tmp
= NULL
;
2323 tmp
= (struct link
*) xmalloc (sizeof *cur
);
2324 tmp
->sym
= find_namespace (yytext
, cur
? cur
->sym
: NULL
);
2328 cur
= cur
->next
= tmp
;
2345 /* Re-initialize the parser by resetting the lookahead token. */
2348 re_init_parser (void)
2354 /* Parse a parameter list, including the const-specifier,
2355 pure-specifier, and throw-list that may follow a parameter list.
2356 Return in FLAGS what was seen following the parameter list.
2357 Returns a hash code for the parameter types. This value is used to
2358 distinguish between overloaded functions. */
2361 parm_list (int *flags
)
2366 while (!LOOKING_AT2 (YYEOF
, ')'))
2370 /* Skip over grouping parens or parameter lists in parameter
2376 /* Next parameter. */
2382 /* Ignore the scope part of types, if any. This is because
2383 some types need scopes when defined outside of a class body,
2384 and don't need them inside the class body. This means that
2385 we have to look for the last IDENT in a sequence of
2386 IDENT::IDENT::... */
2391 unsigned ident_type_hash
= 0;
2393 parse_qualified_param_ident_or_type (&last_id
);
2396 /* LAST_ID null means something like `X::*'. */
2397 for (; *last_id
; ++last_id
)
2398 ident_type_hash
= (ident_type_hash
<< 1) ^ *last_id
;
2399 hash
= (hash
<< 1) ^ ident_type_hash
;
2408 /* This distinction is made to make `func (void)' equivalent
2412 if (!LOOKING_AT (')'))
2413 hash
= (hash
<< 1) ^ VOID
;
2416 case BOOL
: case CHAR
: case CLASS
: case CONST
:
2417 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2418 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2419 case UNION
: case UNSIGNED
: case VOLATILE
: case WCHAR
:
2422 hash
= (hash
<< 1) ^ LA1
;
2426 case '*': case '&': case '[': case ']':
2427 hash
= (hash
<< 1) ^ LA1
;
2437 if (LOOKING_AT (')'))
2441 if (LOOKING_AT (CONST
))
2443 /* We can overload the same function on `const' */
2444 hash
= (hash
<< 1) ^ CONST
;
2445 SET_FLAG (*flags
, F_CONST
);
2449 if (LOOKING_AT (THROW
))
2452 SKIP_MATCHING_IF ('(');
2453 SET_FLAG (*flags
, F_THROW
);
2456 if (LOOKING_AT ('='))
2459 if (LOOKING_AT (CINT
) && yyival
== 0)
2462 SET_FLAG (*flags
, F_PURE
);
2471 /* Print position info to stdout. */
2476 if (info_position
>= 0 && BUFFER_POS () <= info_position
)
2478 printf ("(\"%s\" \"%s\" \"%s\" %d)\n",
2479 info_cls
->name
, sym_scope (info_cls
),
2480 info_member
->name
, info_where
);
2484 /* Parse a member declaration within the class body of CLS. VIS is
2485 the access specifier for the member (private, protected,
2489 member (struct sym
*cls
, int vis
)
2493 char *regexp
= NULL
;
2504 while (!LOOKING_AT4 (';', '{', '}', YYEOF
))
2512 /* A function or class may follow. */
2515 SET_FLAG (flags
, F_TEMPLATE
);
2516 /* Skip over template argument list */
2517 SKIP_MATCHING_IF ('<');
2521 SET_FLAG (flags
, F_EXPLICIT
);
2525 SET_FLAG (flags
, F_MUTABLE
);
2529 SET_FLAG (flags
, F_INLINE
);
2533 SET_FLAG (flags
, F_VIRTUAL
);
2562 /* Remember IDENTS seen so far. Among these will be the member
2564 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
2568 strcpy (id
+ 1, yytext
);
2571 strcpy (id
, yytext
);
2577 char *s
= operator_name (&sc
);
2578 id
= (char *) xrealloc (id
, strlen (s
) + 1);
2584 /* Most probably the beginning of a parameter list. */
2590 if (!(is_constructor
= streq (id
, cls
->name
)))
2591 regexp
= matching_regexp ();
2596 pos
= BUFFER_POS ();
2597 hash
= parm_list (&flags
);
2600 regexp
= matching_regexp ();
2602 if (id
&& cls
!= NULL
)
2603 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, flags
);
2605 while (!LOOKING_AT3 (';', '{', YYEOF
))
2608 if (LOOKING_AT ('{') && id
&& cls
)
2609 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0, sc
, flags
);
2616 case STRUCT
: case UNION
: case CLASS
:
2623 /* More than one ident here to allow for MS-DOS specialties
2624 like `_export class' etc. The last IDENT seen counts
2625 as the class name. */
2626 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
2628 if (LOOKING_AT (IDENT
))
2633 if (LOOKING_AT2 (':', '{'))
2634 class_definition (anonymous
? NULL
: cls
, class_tag
, flags
, 1);
2639 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
2640 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
2641 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
2650 if (LOOKING_AT (';'))
2652 /* The end of a member variable, a friend declaration or an access
2653 declaration. We don't want to add friend classes as members. */
2654 if (id
&& sc
!= SC_FRIEND
&& cls
)
2656 regexp
= matching_regexp ();
2657 pos
= BUFFER_POS ();
2661 if (type_seen
|| !paren_seen
)
2662 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2664 add_member_decl (cls
, id
, regexp
, pos
, hash
, 0, sc
, vis
, 0);
2671 else if (LOOKING_AT ('{'))
2674 if (sc
== SC_TYPE
&& id
&& cls
)
2676 regexp
= matching_regexp ();
2677 pos
= BUFFER_POS ();
2681 add_member_decl (cls
, id
, regexp
, pos
, 0, 1, sc
, vis
, 0);
2682 add_member_defn (cls
, id
, regexp
, pos
, 0, 1, sc
, 0);
2694 /* Parse the body of class CLS. TAG is the tag of the class (struct,
2698 class_body (struct sym
*cls
, int tag
)
2700 int vis
= tag
== CLASS
? PRIVATE
: PUBLIC
;
2703 while (!LOOKING_AT2 (YYEOF
, '}'))
2707 case PRIVATE
: case PROTECTED
: case PUBLIC
:
2711 if (LOOKING_AT (':'))
2718 /* Probably conditional compilation for inheritance list.
2719 We don't known whether there comes more of this.
2720 This is only a crude fix that works most of the time. */
2725 while (LOOKING_AT2 (IDENT
, ',')
2726 || LOOKING_AT3 (PUBLIC
, PROTECTED
, PRIVATE
));
2735 /* Try to synchronize */
2736 case CHAR
: case CLASS
: case CONST
:
2737 case DOUBLE
: case ENUM
: case FLOAT
: case INT
:
2738 case LONG
: case SHORT
: case SIGNED
: case STRUCT
:
2739 case UNION
: case UNSIGNED
: case VOID
: case VOLATILE
:
2740 case TYPEDEF
: case STATIC
: case T_INLINE
: case FRIEND
:
2741 case VIRTUAL
: case TEMPLATE
: case IDENT
: case '~':
2742 case BOOL
: case WCHAR
: case EXPLICIT
: case MUTABLE
:
2754 /* Parse a qualified identifier. Current lookahead is IDENT. A
2755 qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
2756 symbol for that class. */
2759 parse_classname (void)
2761 struct sym
*last_class
= NULL
;
2763 while (LOOKING_AT (IDENT
))
2765 last_class
= add_sym (yytext
, last_class
);
2768 if (LOOKING_AT ('<'))
2771 SET_FLAG (last_class
->flags
, F_TEMPLATE
);
2774 if (!LOOKING_AT (DCOLON
))
2784 /* Parse an operator name. Add the `static' flag to *SC if an
2785 implicitly static operator has been parsed. Value is a pointer to
2786 a static buffer holding the constructed operator name string. */
2789 operator_name (int *sc
)
2791 static size_t id_size
= 0;
2792 static char *id
= NULL
;
2798 if (LOOKING_AT2 (NEW
, DELETE
))
2800 /* `new' and `delete' are implicitly static. */
2801 if (*sc
!= SC_FRIEND
)
2804 s
= token_string (LA1
);
2807 len
= strlen (s
) + 10;
2810 size_t new_size
= max (len
, 2 * id_size
);
2811 id
= (char *) xrealloc (id
, new_size
);
2816 /* Vector new or delete? */
2817 if (LOOKING_AT ('['))
2822 if (LOOKING_AT (']'))
2831 size_t tokens_matched
= 0;
2836 int new_size
= max (len
, 2 * id_size
);
2837 id
= (char *) xrealloc (id
, new_size
);
2840 strcpy (id
, "operator");
2842 /* Beware access declarations of the form "X::f;" Beware of
2843 `operator () ()'. Yet another difficulty is found in
2844 GCC 2.95's STL: `operator == __STL_NULL_TMPL_ARGS (...'. */
2845 while (!(LOOKING_AT ('(') && tokens_matched
)
2846 && !LOOKING_AT2 (';', YYEOF
))
2848 s
= token_string (LA1
);
2849 len
+= strlen (s
) + 2;
2852 size_t new_size
= max (len
, 2 * id_size
);
2853 id
= (char *) xrealloc (id
, new_size
);
2857 if (*s
!= ')' && *s
!= ']')
2862 /* If this is a simple operator like `+', stop now. */
2863 if (!isalpha ((unsigned char) *s
) && *s
!= '(' && *s
!= '[')
2874 /* This one consumes the last IDENT of a qualified member name like
2875 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2876 symbol structure for the ident. */
2879 parse_qualified_ident_or_type (char **last_id
)
2881 struct sym
*cls
= NULL
;
2886 while (LOOKING_AT (IDENT
))
2888 int len
= strlen (yytext
) + 1;
2891 id
= (char *) xrealloc (id
, len
);
2894 strcpy (id
, yytext
);
2898 SKIP_MATCHING_IF ('<');
2900 if (LOOKING_AT (DCOLON
))
2902 struct sym
*pcn
= NULL
;
2903 struct link
*pna
= check_namespace_alias (id
);
2908 enter_namespace (pna
->sym
->name
);
2914 else if ((pcn
= check_namespace (id
, current_namespace
)))
2916 enter_namespace (pcn
->name
);
2920 cls
= add_sym (id
, cls
);
2939 /* This one consumes the last IDENT of a qualified member name like
2940 `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
2941 symbol structure for the ident. */
2944 parse_qualified_param_ident_or_type (char **last_id
)
2946 struct sym
*cls
= NULL
;
2947 static char *id
= NULL
;
2948 static int id_size
= 0;
2950 assert (LOOKING_AT (IDENT
));
2954 int len
= strlen (yytext
) + 1;
2957 id
= (char *) xrealloc (id
, len
);
2960 strcpy (id
, yytext
);
2964 SKIP_MATCHING_IF ('<');
2966 if (LOOKING_AT (DCOLON
))
2968 cls
= add_sym (id
, cls
);
2975 while (LOOKING_AT (IDENT
));
2979 /* Parse a class definition.
2981 CONTAINING is the class containing the class being parsed or null.
2982 This may also be null if NESTED != 0 if the containing class is
2983 anonymous. TAG is the tag of the class (struct, union, class).
2984 NESTED is non-zero if we are parsing a nested class.
2986 Current lookahead is the class name. */
2989 class_definition (struct sym
*containing
, int tag
, int flags
, int nested
)
2991 struct sym
*current
;
2992 struct sym
*base_class
;
2994 /* Set CURRENT to null if no entry has to be made for the class
2995 parsed. This is the case for certain command line flag
2997 if ((tag
!= CLASS
&& !f_structs
) || (nested
&& !f_nested_classes
))
3001 current
= add_sym (yytext
, containing
);
3002 current
->pos
= BUFFER_POS ();
3003 current
->regexp
= matching_regexp ();
3004 current
->filename
= filename
;
3005 current
->flags
= flags
;
3008 /* If at ':', base class list follows. */
3009 if (LOOKING_AT (':'))
3018 case VIRTUAL
: case PUBLIC
: case PROTECTED
: case PRIVATE
:
3023 base_class
= parse_classname ();
3024 if (base_class
&& current
&& base_class
!= current
)
3025 add_link (base_class
, current
);
3028 /* The `,' between base classes or the end of the base
3029 class list. Add the previously found base class.
3030 It's done this way to skip over sequences of
3031 `A::B::C' until we reach the end.
3033 FIXME: it is now possible to handle `class X : public B::X'
3034 because we have enough information. */
3040 /* A syntax error, possibly due to preprocessor constructs
3046 class A : private B.
3048 MATCH until we see something like `;' or `{'. */
3049 while (!LOOKING_AT3 (';', YYEOF
, '{'))
3060 /* Parse the class body if there is one. */
3061 if (LOOKING_AT ('{'))
3063 if (tag
!= CLASS
&& !f_structs
)
3068 class_body (current
, tag
);
3070 if (LOOKING_AT ('}'))
3073 if (LOOKING_AT (';') && !nested
)
3080 /* Add to class *CLS information for the declaration of variable or
3081 type *ID. If *CLS is null, this means a global declaration. SC is
3082 the storage class of *ID. FLAGS is a bit set giving additional
3083 information about the member (see the F_* defines). */
3086 add_declarator (struct sym
**cls
, char **id
, int flags
, int sc
)
3088 if (LOOKING_AT2 (';', ','))
3090 /* The end of a member variable or of an access declaration
3091 `X::f'. To distinguish between them we have to know whether
3092 type information has been seen. */
3095 char *regexp
= matching_regexp ();
3096 int pos
= BUFFER_POS ();
3099 add_member_defn (*cls
, *id
, regexp
, pos
, 0, 1, SC_UNKNOWN
, flags
);
3101 add_global_defn (*id
, regexp
, pos
, 0, 1, sc
, flags
);
3107 else if (LOOKING_AT ('{'))
3109 if (sc
== SC_TYPE
&& *id
)
3111 /* A named enumeration. */
3112 char *regexp
= matching_regexp ();
3113 int pos
= BUFFER_POS ();
3114 add_global_defn (*id
, regexp
, pos
, 0, 1, sc
, flags
);
3126 /* Parse a declaration. */
3129 declaration (int flags
)
3132 struct sym
*cls
= NULL
;
3133 char *regexp
= NULL
;
3139 while (!LOOKING_AT3 (';', '{', YYEOF
))
3162 case INT
: case CHAR
: case LONG
: case UNSIGNED
:
3163 case SIGNED
: case CONST
: case DOUBLE
: case VOID
:
3164 case SHORT
: case VOLATILE
: case BOOL
: case WCHAR
:
3168 case CLASS
: case STRUCT
: case UNION
:
3169 /* This is for the case `STARTWRAP class X : ...' or
3170 `declare (X, Y)\n class A : ...'. */
3178 /* Assumed to be the start of an initialization in this
3180 skip_initializer ();
3184 add_declarator (&cls
, &id
, flags
, sc
);
3189 char *s
= operator_name (&sc
);
3190 id
= (char *) xrealloc (id
, strlen (s
) + 1);
3196 SET_FLAG (flags
, F_INLINE
);
3202 if (LOOKING_AT (IDENT
))
3204 id
= (char *) xrealloc (id
, strlen (yytext
) + 2);
3206 strcpy (id
+ 1, yytext
);
3212 cls
= parse_qualified_ident_or_type (&id
);
3216 /* Most probably the beginning of a parameter list. */
3223 if (!(is_constructor
= streq (id
, cls
->name
)))
3224 regexp
= matching_regexp ();
3229 pos
= BUFFER_POS ();
3230 hash
= parm_list (&flags
);
3233 regexp
= matching_regexp ();
3236 add_member_defn (cls
, id
, regexp
, pos
, hash
, 0,
3241 /* This may be a C functions, but also a macro
3242 call of the form `declare (A, B)' --- such macros
3243 can be found in some class libraries. */
3248 regexp
= matching_regexp ();
3249 pos
= BUFFER_POS ();
3250 hash
= parm_list (&flags
);
3251 add_global_decl (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3254 /* This is for the case that the function really is
3255 a macro with no `;' following it. If a CLASS directly
3256 follows, we would miss it otherwise. */
3257 if (LOOKING_AT3 (CLASS
, STRUCT
, UNION
))
3261 while (!LOOKING_AT3 (';', '{', YYEOF
))
3264 if (!cls
&& id
&& LOOKING_AT ('{'))
3265 add_global_defn (id
, regexp
, pos
, hash
, 0, sc
, flags
);
3273 add_declarator (&cls
, &id
, flags
, sc
);
3277 /* Parse a list of top-level declarations/definitions. START_FLAGS
3278 says in which context we are parsing. If it is F_EXTERNC, we are
3279 parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0
3283 globals (int start_flags
)
3287 int flags
= start_flags
;
3299 if (LOOKING_AT (IDENT
))
3301 char *namespace_name
= xstrdup (yytext
);
3304 if (LOOKING_AT ('='))
3306 struct link
*qna
= match_qualified_namespace_alias ();
3308 register_namespace_alias (namespace_name
, qna
);
3310 if (skip_to (';') == ';')
3313 else if (LOOKING_AT ('{'))
3316 enter_namespace (namespace_name
);
3322 free (namespace_name
);
3329 if (LOOKING_AT (CSTRING
) && *string_start
== 'C'
3330 && *(string_start
+ 1) == '"')
3332 /* This is `extern "C"'. */
3335 if (LOOKING_AT ('{'))
3338 globals (F_EXTERNC
);
3342 SET_FLAG (flags
, F_EXTERNC
);
3348 SKIP_MATCHING_IF ('<');
3349 SET_FLAG (flags
, F_TEMPLATE
);
3352 case CLASS
: case STRUCT
: case UNION
:
3357 /* More than one ident here to allow for MS-DOS and OS/2
3358 specialties like `far', `_Export' etc. Some C++ libs
3359 have constructs like `_OS_DLLIMPORT(_OS_CLIENT)' in front
3360 of the class name. */
3361 while (!LOOKING_AT4 (YYEOF
, ';', ':', '{'))
3363 if (LOOKING_AT (IDENT
))
3368 /* Don't add anonymous unions. */
3369 if (LOOKING_AT2 (':', '{') && !anonymous
)
3370 class_definition (NULL
, class_tk
, flags
, 0);
3373 if (skip_to (';') == ';')
3377 flags
= start_flags
;
3387 declaration (flags
);
3388 flags
= start_flags
;
3393 yyerror ("parse error", NULL
);
3398 /* Parse the current input file. */
3403 while (globals (0) == 0)
3409 /***********************************************************************
3411 ***********************************************************************/
3413 /* Add the list of paths PATH_LIST to the current search path for
3417 add_search_path (char *path_list
)
3421 char *start
= path_list
;
3422 struct search_path
*p
;
3424 while (*path_list
&& *path_list
!= PATH_LIST_SEPARATOR
)
3427 p
= (struct search_path
*) xmalloc (sizeof *p
);
3428 p
->path
= (char *) xmalloc (path_list
- start
+ 1);
3429 memcpy (p
->path
, start
, path_list
- start
);
3430 p
->path
[path_list
- start
] = '\0';
3433 if (search_path_tail
)
3435 search_path_tail
->next
= p
;
3436 search_path_tail
= p
;
3439 search_path
= search_path_tail
= p
;
3441 while (*path_list
== PATH_LIST_SEPARATOR
)
3447 /* Open FILE and return a file handle for it, or -1 if FILE cannot be
3448 opened. Try to find FILE in search_path first, then try the
3449 unchanged file name. */
3452 open_file (char *file
)
3455 static char *buffer
;
3456 static int buffer_size
;
3457 struct search_path
*path
;
3458 int flen
= strlen (file
) + 1; /* +1 for the slash */
3460 filename
= xstrdup (file
);
3462 for (path
= search_path
; path
&& fp
== NULL
; path
= path
->next
)
3464 int len
= strlen (path
->path
) + flen
;
3466 if (len
+ 1 >= buffer_size
)
3468 buffer_size
= max (len
+ 1, 2 * buffer_size
);
3469 buffer
= (char *) xrealloc (buffer
, buffer_size
);
3472 strcpy (buffer
, path
->path
);
3473 strcat (buffer
, "/");
3474 strcat (buffer
, file
);
3475 fp
= fopen (buffer
, "r");
3478 /* Try the original file name. */
3480 fp
= fopen (file
, "r");
3483 yyerror ("cannot open", NULL
);
3489 /* Display usage information and exit program. */
3492 Usage: ebrowse [options] {files}\n\
3494 -a, --append append output to existing file\n\
3495 -f, --files=FILES read input file names from FILE\n\
3496 -I, --search-path=LIST set search path for input files\n\
3497 -m, --min-regexp-length=N set minimum regexp length to N\n\
3498 -M, --max-regexp-length=N set maximum regexp length to N\n\
3499 -n, --no-nested-classes exclude nested classes\n\
3500 -o, --output-file=FILE set output file name to FILE\n\
3501 -p, --position-info print info about position in file\n\
3502 -s, --no-structs-or-unions don't record structs or unions\n\
3503 -v, --verbose be verbose\n\
3504 -V, --very-verbose be very verbose\n\
3505 -x, --no-regexps don't record regular expressions\n\
3506 --help display this help\n\
3507 --version display version info\n\
3514 exit (error
? EXIT_FAILURE
: EXIT_SUCCESS
);
3518 /* Display version and copyright info. The VERSION macro is set
3519 from config.h and contains the Emacs version. */
3522 # define VERSION "21"
3528 /* Makes it easier to update automatically. */
3529 char emacs_copyright
[] = "Copyright (C) 2012 Free Software Foundation, Inc.";
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 */