comparison lib-src/ebrowse.c @ 42174:e3b97ef49aee

Include stdlib.h and string.h conditionally.
author Pavel Janík <Pavel@Janik.cz>
date Wed, 19 Dec 2001 06:03:40 +0000
parents 1ba618f8fdb5
children 20ee6e9752ef
comparison
equal deleted inserted replaced
42173:9c9bb29ed93f 42174:e3b97ef49aee
4 2000, 2001 4 2000, 2001
5 Free Software Foundation Inc. 5 Free Software Foundation Inc.
6 6
7 Author: Gerd Moellmann <gerd@gnu.org> 7 Author: Gerd Moellmann <gerd@gnu.org>
8 Maintainer: FSF 8 Maintainer: FSF
9 9
10 This file is part of GNU Emacs. 10 This file is part of GNU Emacs.
11 11
12 GNU Emacs is free software; you can redistribute it and/or modify 12 GNU Emacs is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by 13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option) 14 the Free Software Foundation; either version 2, or (at your option)
26 #ifdef HAVE_CONFIG_H 26 #ifdef HAVE_CONFIG_H
27 #include <config.h> 27 #include <config.h>
28 #endif 28 #endif
29 29
30 #include <stdio.h> 30 #include <stdio.h>
31
32 #ifdef HAVE_STDLIB_H
31 #include <stdlib.h> 33 #include <stdlib.h>
34 #endif
35
36 #ifdef HAVE_STRING_H
32 #include <string.h> 37 #include <string.h>
38 #endif
39
33 #include <ctype.h> 40 #include <ctype.h>
34 #include <assert.h> 41 #include <assert.h>
35 #include "getopt.h" 42 #include "getopt.h"
36 43
37 /* The SunOS compiler doesn't have SEEK_END. */ 44 /* The SunOS compiler doesn't have SEEK_END. */
398 405
399 /* Return the current buffer position in the input file. */ 406 /* Return the current buffer position in the input file. */
400 407
401 #define BUFFER_POS() (in - inbuffer) 408 #define BUFFER_POS() (in - inbuffer)
402 409
403 /* If current lookahead is CSTRING, the following points to the 410 /* If current lookahead is CSTRING, the following points to the
404 first character in the string constant. Used for recognizing 411 first character in the string constant. Used for recognizing
405 extern "C". */ 412 extern "C". */
406 413
407 char *string_start; 414 char *string_start;
408 415
684 /* Avoid duplicates. */ 691 /* Avoid duplicates. */
685 if (p == NULL || p->sym != sub) 692 if (p == NULL || p->sym != sub)
686 { 693 {
687 lnk = (struct link *) xmalloc (sizeof *lnk); 694 lnk = (struct link *) xmalloc (sizeof *lnk);
688 lnk2 = (struct link *) xmalloc (sizeof *lnk2); 695 lnk2 = (struct link *) xmalloc (sizeof *lnk2);
689 696
690 lnk->sym = sub; 697 lnk->sym = sub;
691 lnk->next = p; 698 lnk->next = p;
692 699
693 if (prev) 700 if (prev)
694 prev->next = lnk; 701 prev->next = lnk;
726 switch (sc) 733 switch (sc)
727 { 734 {
728 case SC_FRIEND: 735 case SC_FRIEND:
729 list = &cls->friends; 736 list = &cls->friends;
730 break; 737 break;
731 738
732 case SC_TYPE: 739 case SC_TYPE:
733 list = &cls->types; 740 list = &cls->types;
734 break; 741 break;
735 742
736 case SC_STATIC: 743 case SC_STATIC:
737 list = var ? &cls->static_vars : &cls->static_fns; 744 list = var ? &cls->static_vars : &cls->static_fns;
738 break; 745 break;
739 746
740 default: 747 default:
741 list = var ? &cls->vars : &cls->fns; 748 list = var ? &cls->vars : &cls->fns;
742 break; 749 break;
743 } 750 }
744 751
926 specifies the type of member (instance member, static, ...). VIS 933 specifies the type of member (instance member, static, ...). VIS
927 is the member's visibility (public, protected, private). FLAGS is 934 is the member's visibility (public, protected, private). FLAGS is
928 a bit set giving additional information about the member (see the 935 a bit set giving additional information about the member (see the
929 F_* defines). */ 936 F_* defines). */
930 937
931 void 938 void
932 add_global_decl (name, regexp, pos, hash, var, sc, flags) 939 add_global_decl (name, regexp, pos, hash, var, sc, flags)
933 char *name, *regexp; 940 char *name, *regexp;
934 int pos; 941 int pos;
935 unsigned hash; 942 unsigned hash;
936 int var; 943 int var;
1006 switch (sc) 1013 switch (sc)
1007 { 1014 {
1008 case SC_FRIEND: 1015 case SC_FRIEND:
1009 list = &cls->friends; 1016 list = &cls->friends;
1010 break; 1017 break;
1011 1018
1012 case SC_TYPE: 1019 case SC_TYPE:
1013 list = &cls->types; 1020 list = &cls->types;
1014 break; 1021 break;
1015 1022
1016 case SC_STATIC: 1023 case SC_STATIC:
1017 list = var ? &cls->static_vars : &cls->static_fns; 1024 list = var ? &cls->static_vars : &cls->static_fns;
1018 break; 1025 break;
1019 1026
1020 default: 1027 default:
1021 list = var ? &cls->vars : &cls->fns; 1028 list = var ? &cls->vars : &cls->fns;
1022 break; 1029 break;
1023 } 1030 }
1024 1031
1110 check_namespace (name, context) 1117 check_namespace (name, context)
1111 char *name; 1118 char *name;
1112 struct sym *context; 1119 struct sym *context;
1113 { 1120 {
1114 struct sym *p = NULL; 1121 struct sym *p = NULL;
1115 1122
1116 for (p = all_namespaces; p; p = p->next) 1123 for (p = all_namespaces; p; p = p->next)
1117 { 1124 {
1118 if (streq (p->name, name) && (p->namesp == context)) 1125 if (streq (p->name, name) && (p->namesp == context))
1119 break; 1126 break;
1120 } 1127 }
1135 if (p == NULL) 1142 if (p == NULL)
1136 p = make_namespace (name, context); 1143 p = make_namespace (name, context);
1137 1144
1138 return p; 1145 return p;
1139 } 1146 }
1140 1147
1141 1148
1142 /* Find namespace alias with name NAME. If not found return NULL. */ 1149 /* Find namespace alias with name NAME. If not found return NULL. */
1143 1150
1144 struct link * 1151 struct link *
1145 check_namespace_alias (name) 1152 check_namespace_alias (name)
1208 namespace_stack 1215 namespace_stack
1209 = (struct sym **) xrealloc ((void *)namespace_stack, 1216 = (struct sym **) xrealloc ((void *)namespace_stack,
1210 size * sizeof *namespace_stack); 1217 size * sizeof *namespace_stack);
1211 namespace_stack_size = size; 1218 namespace_stack_size = size;
1212 } 1219 }
1213 1220
1214 namespace_stack[namespace_sp++] = current_namespace; 1221 namespace_stack[namespace_sp++] = current_namespace;
1215 current_namespace = p; 1222 current_namespace = p;
1216 } 1223 }
1217 1224
1218 1225
1280 char * 1287 char *
1281 sym_scope_1 (p) 1288 sym_scope_1 (p)
1282 struct sym *p; 1289 struct sym *p;
1283 { 1290 {
1284 int len; 1291 int len;
1285 1292
1286 if (p->namesp) 1293 if (p->namesp)
1287 sym_scope_1 (p->namesp); 1294 sym_scope_1 (p->namesp);
1288 1295
1289 if (*scope_buffer) 1296 if (*scope_buffer)
1290 { 1297 {
1295 1302
1296 len = strlen (p->name); 1303 len = strlen (p->name);
1297 ensure_scope_buffer_room (len + 1); 1304 ensure_scope_buffer_room (len + 1);
1298 strcat (scope_buffer, p->name); 1305 strcat (scope_buffer, p->name);
1299 scope_buffer_len += len; 1306 scope_buffer_len += len;
1300 1307
1301 if (HAS_FLAG (p->flags, F_TEMPLATE)) 1308 if (HAS_FLAG (p->flags, F_TEMPLATE))
1302 { 1309 {
1303 ensure_scope_buffer_room (3); 1310 ensure_scope_buffer_room (3);
1304 strcat (scope_buffer, "<>"); 1311 strcat (scope_buffer, "<>");
1305 scope_buffer_len += 2; 1312 scope_buffer_len += 2;
1306 } 1313 }
1307 1314
1308 return scope_buffer; 1315 return scope_buffer;
1309 } 1316 }
1310 1317
1311 1318
1312 /* Return the scope of symbol P in printed representation, i.e. 1319 /* Return the scope of symbol P in printed representation, i.e.
1319 if (!scope_buffer) 1326 if (!scope_buffer)
1320 { 1327 {
1321 scope_buffer_size = 1024; 1328 scope_buffer_size = 1024;
1322 scope_buffer = (char *) xmalloc (scope_buffer_size); 1329 scope_buffer = (char *) xmalloc (scope_buffer_size);
1323 } 1330 }
1324 1331
1325 *scope_buffer = '\0'; 1332 *scope_buffer = '\0';
1326 scope_buffer_len = 0; 1333 scope_buffer_len = 0;
1327 1334
1328 if (p->namesp) 1335 if (p->namesp)
1329 sym_scope_1 (p->namesp); 1336 sym_scope_1 (p->namesp);
1330 1337
1331 return scope_buffer; 1338 return scope_buffer;
1332 } 1339 }
1375 FILE *fp; 1382 FILE *fp;
1376 struct sym *root; 1383 struct sym *root;
1377 { 1384 {
1378 fputs (CLASS_STRUCT, fp); 1385 fputs (CLASS_STRUCT, fp);
1379 PUTSTR (root->name, fp); 1386 PUTSTR (root->name, fp);
1380 1387
1381 /* Print scope, if any. */ 1388 /* Print scope, if any. */
1382 if (root->namesp) 1389 if (root->namesp)
1383 PUTSTR (sym_scope (root), fp); 1390 PUTSTR (sym_scope (root), fp);
1384 else 1391 else
1385 PUTSTR (NULL, fp); 1392 PUTSTR (NULL, fp);
1386 1393
1387 /* Print flags. */ 1394 /* Print flags. */
1388 fprintf (fp, "%u", root->flags); 1395 fprintf (fp, "%u", root->flags);
1389 PUTSTR (root->filename, fp); 1396 PUTSTR (root->filename, fp);
1390 PUTSTR (root->regexp, fp); 1397 PUTSTR (root->regexp, fp);
1391 fprintf (fp, "%u", (unsigned) root->pos); 1398 fprintf (fp, "%u", (unsigned) root->pos);
1561 char *regexp = matching_regexp (); 1568 char *regexp = matching_regexp ();
1562 int pos = BUFFER_POS (); 1569 int pos = BUFFER_POS ();
1563 add_define (yytext, regexp, pos); 1570 add_define (yytext, regexp, pos);
1564 } 1571 }
1565 } 1572 }
1566 1573
1567 while (c && (c != '\n' || in_comment || in_string)) 1574 while (c && (c != '\n' || in_comment || in_string))
1568 { 1575 {
1569 if (c == '\\') 1576 if (c == '\\')
1570 GET (c); 1577 GET (c);
1571 else if (c == '/' && !in_comment) 1578 else if (c == '/' && !in_comment)
1578 if (GET (c) == '/') 1585 if (GET (c) == '/')
1579 in_comment = 0; 1586 in_comment = 0;
1580 } 1587 }
1581 else if (c == '"') 1588 else if (c == '"')
1582 in_string = !in_string; 1589 in_string = !in_string;
1583 1590
1584 if (c == '\n') 1591 if (c == '\n')
1585 INCREMENT_LINENO; 1592 INCREMENT_LINENO;
1586 1593
1587 GET (c); 1594 GET (c);
1588 } 1595 }
2182 void 2189 void
2183 re_init_scanner () 2190 re_init_scanner ()
2184 { 2191 {
2185 in = inbuffer; 2192 in = inbuffer;
2186 yyline = 1; 2193 yyline = 1;
2187 2194
2188 if (yytext == NULL) 2195 if (yytext == NULL)
2189 { 2196 {
2190 int size = 256; 2197 int size = 256;
2191 yytext = (char *) xmalloc (size * sizeof *yytext); 2198 yytext = (char *) xmalloc (size * sizeof *yytext);
2192 yytext_end = yytext + size; 2199 yytext_end = yytext + size;
2384 switch (open = LA1) 2391 switch (open = LA1)
2385 { 2392 {
2386 case '{': 2393 case '{':
2387 close = '}'; 2394 close = '}';
2388 break; 2395 break;
2389 2396
2390 case '(': 2397 case '(':
2391 close = ')'; 2398 close = ')';
2392 break; 2399 break;
2393 2400
2394 case '<': 2401 case '<':
2395 close = '>'; 2402 close = '>';
2396 break; 2403 break;
2397 2404
2398 case '[': 2405 case '[':
2399 close = ']'; 2406 close = ']';
2400 break; 2407 break;
2401 2408
2402 default: 2409 default:
2403 abort (); 2410 abort ();
2404 } 2411 }
2405 2412
2406 for (n = 0;;) 2413 for (n = 0;;)
2503 case IDENT: 2510 case IDENT:
2504 if (!type_seen) 2511 if (!type_seen)
2505 { 2512 {
2506 char *last_id; 2513 char *last_id;
2507 unsigned ident_type_hash = 0; 2514 unsigned ident_type_hash = 0;
2508 2515
2509 parse_qualified_param_ident_or_type (&last_id); 2516 parse_qualified_param_ident_or_type (&last_id);
2510 if (last_id) 2517 if (last_id)
2511 { 2518 {
2512 /* LAST_ID null means something like `X::*'. */ 2519 /* LAST_ID null means something like `X::*'. */
2513 for (; *last_id; ++last_id) 2520 for (; *last_id; ++last_id)
2531 2538
2532 case BOOL: case CHAR: case CLASS: case CONST: 2539 case BOOL: case CHAR: case CLASS: case CONST:
2533 case DOUBLE: case ENUM: case FLOAT: case INT: 2540 case DOUBLE: case ENUM: case FLOAT: case INT:
2534 case LONG: case SHORT: case SIGNED: case STRUCT: 2541 case LONG: case SHORT: case SIGNED: case STRUCT:
2535 case UNION: case UNSIGNED: case VOLATILE: case WCHAR: 2542 case UNION: case UNSIGNED: case VOLATILE: case WCHAR:
2536 case ELLIPSIS: 2543 case ELLIPSIS:
2537 type_seen = 1; 2544 type_seen = 1;
2538 hash = (hash << 1) ^ LA1; 2545 hash = (hash << 1) ^ LA1;
2539 MATCH (); 2546 MATCH ();
2540 break; 2547 break;
2541 2548
2551 } 2558 }
2552 2559
2553 if (LOOKING_AT (')')) 2560 if (LOOKING_AT (')'))
2554 { 2561 {
2555 MATCH (); 2562 MATCH ();
2556 2563
2557 if (LOOKING_AT (CONST)) 2564 if (LOOKING_AT (CONST))
2558 { 2565 {
2559 /* We can overload the same function on `const' */ 2566 /* We can overload the same function on `const' */
2560 hash = (hash << 1) ^ CONST; 2567 hash = (hash << 1) ^ CONST;
2561 SET_FLAG (*flags, F_CONST); 2568 SET_FLAG (*flags, F_CONST);
2636 break; 2643 break;
2637 2644
2638 case EXPLICIT: 2645 case EXPLICIT:
2639 SET_FLAG (flags, F_EXPLICIT); 2646 SET_FLAG (flags, F_EXPLICIT);
2640 goto typeseen; 2647 goto typeseen;
2641 2648
2642 case MUTABLE: 2649 case MUTABLE:
2643 SET_FLAG (flags, F_MUTABLE); 2650 SET_FLAG (flags, F_MUTABLE);
2644 goto typeseen; 2651 goto typeseen;
2645 2652
2646 case T_INLINE: 2653 case T_INLINE:
2771 declaration. We don't want to add friend classes as members. */ 2778 declaration. We don't want to add friend classes as members. */
2772 if (id && sc != SC_FRIEND && cls) 2779 if (id && sc != SC_FRIEND && cls)
2773 { 2780 {
2774 regexp = matching_regexp (); 2781 regexp = matching_regexp ();
2775 pos = BUFFER_POS (); 2782 pos = BUFFER_POS ();
2776 2783
2777 if (cls != NULL) 2784 if (cls != NULL)
2778 { 2785 {
2779 if (type_seen || !paren_seen) 2786 if (type_seen || !paren_seen)
2780 add_member_decl (cls, id, regexp, pos, 0, 1, sc, vis, 0); 2787 add_member_decl (cls, id, regexp, pos, 0, 1, sc, vis, 0);
2781 else 2788 else
2782 add_member_decl (cls, id, regexp, pos, hash, 0, sc, vis, 0); 2789 add_member_decl (cls, id, regexp, pos, hash, 0, sc, vis, 0);
2783 } 2790 }
2784 } 2791 }
2785 2792
2786 MATCH (); 2793 MATCH ();
2787 print_info (); 2794 print_info ();
2788 } 2795 }
2789 else if (LOOKING_AT ('{')) 2796 else if (LOOKING_AT ('{'))
2790 { 2797 {
2877 2884
2878 struct sym * 2885 struct sym *
2879 parse_classname () 2886 parse_classname ()
2880 { 2887 {
2881 struct sym *last_class = NULL; 2888 struct sym *last_class = NULL;
2882 2889
2883 while (LOOKING_AT (IDENT)) 2890 while (LOOKING_AT (IDENT))
2884 { 2891 {
2885 last_class = add_sym (yytext, last_class); 2892 last_class = add_sym (yytext, last_class);
2886 MATCH (); 2893 MATCH ();
2887 2894
2888 if (LOOKING_AT ('<')) 2895 if (LOOKING_AT ('<'))
2889 { 2896 {
2890 skip_matching (); 2897 skip_matching ();
2891 SET_FLAG (last_class->flags, F_TEMPLATE); 2898 SET_FLAG (last_class->flags, F_TEMPLATE);
2892 } 2899 }
2893 2900
2894 if (!LOOKING_AT (DCOLON)) 2901 if (!LOOKING_AT (DCOLON))
2895 break; 2902 break;
2896 2903
2897 MATCH (); 2904 MATCH ();
2898 } 2905 }
2899 2906
2900 return last_class; 2907 return last_class;
2901 } 2908 }
2911 { 2918 {
2912 static int id_size = 0; 2919 static int id_size = 0;
2913 static char *id = NULL; 2920 static char *id = NULL;
2914 char *s; 2921 char *s;
2915 int len; 2922 int len;
2916 2923
2917 MATCH (); 2924 MATCH ();
2918 2925
2919 if (LOOKING_AT2 (NEW, DELETE)) 2926 if (LOOKING_AT2 (NEW, DELETE))
2920 { 2927 {
2921 /* `new' and `delete' are implicitly static. */ 2928 /* `new' and `delete' are implicitly static. */
2922 if (*sc != SC_FRIEND) 2929 if (*sc != SC_FRIEND)
2923 *sc = SC_STATIC; 2930 *sc = SC_STATIC;
2924 2931
2925 s = token_string (LA1); 2932 s = token_string (LA1);
2926 MATCH (); 2933 MATCH ();
2927 2934
2928 len = strlen (s) + 10; 2935 len = strlen (s) + 10;
2929 if (len > id_size) 2936 if (len > id_size)
2930 { 2937 {
2931 int new_size = max (len, 2 * id_size); 2938 int new_size = max (len, 2 * id_size);
2932 id = (char *) xrealloc (id, new_size); 2939 id = (char *) xrealloc (id, new_size);
2933 id_size = new_size; 2940 id_size = new_size;
2934 } 2941 }
2935 strcpy (id, s); 2942 strcpy (id, s);
2936 2943
2937 /* Vector new or delete? */ 2944 /* Vector new or delete? */
2938 if (LOOKING_AT ('[')) 2945 if (LOOKING_AT ('['))
2939 { 2946 {
2940 strcat (id, "["); 2947 strcat (id, "[");
2941 MATCH (); 2948 MATCH ();
2942 2949
2943 if (LOOKING_AT (']')) 2950 if (LOOKING_AT (']'))
2944 { 2951 {
2945 strcat (id, "]"); 2952 strcat (id, "]");
2946 MATCH (); 2953 MATCH ();
2947 } 2954 }
3002 { 3009 {
3003 struct sym *cls = NULL; 3010 struct sym *cls = NULL;
3004 char *id = NULL; 3011 char *id = NULL;
3005 size_t id_size = 0; 3012 size_t id_size = 0;
3006 int enter = 0; 3013 int enter = 0;
3007 3014
3008 while (LOOKING_AT (IDENT)) 3015 while (LOOKING_AT (IDENT))
3009 { 3016 {
3010 int len = strlen (yytext) + 1; 3017 int len = strlen (yytext) + 1;
3011 if (len > id_size) 3018 if (len > id_size)
3012 { 3019 {
3231 case ENUM: 3238 case ENUM:
3232 case TYPEDEF: 3239 case TYPEDEF:
3233 sc = SC_TYPE; 3240 sc = SC_TYPE;
3234 MATCH (); 3241 MATCH ();
3235 break; 3242 break;
3236 3243
3237 case STATIC: 3244 case STATIC:
3238 sc = SC_STATIC; 3245 sc = SC_STATIC;
3239 MATCH (); 3246 MATCH ();
3240 break; 3247 break;
3241 3248
3359 if (cls) 3366 if (cls)
3360 add_member_defn (cls, id, regexp, pos, 0, 1, SC_UNKNOWN, flags); 3367 add_member_defn (cls, id, regexp, pos, 0, 1, SC_UNKNOWN, flags);
3361 else 3368 else
3362 add_global_defn (id, regexp, pos, 0, 1, sc, flags); 3369 add_global_defn (id, regexp, pos, 0, 1, sc, flags);
3363 } 3370 }
3364 3371
3365 MATCH (); 3372 MATCH ();
3366 print_info (); 3373 print_info ();
3367 } 3374 }
3368 else if (LOOKING_AT ('{')) 3375 else if (LOOKING_AT ('{'))
3369 { 3376 {
3397 int flags = start_flags; 3404 int flags = start_flags;
3398 3405
3399 for (;;) 3406 for (;;)
3400 { 3407 {
3401 char *prev_in = in; 3408 char *prev_in = in;
3402 3409
3403 switch (LA1) 3410 switch (LA1)
3404 { 3411 {
3405 case NAMESPACE: 3412 case NAMESPACE:
3406 { 3413 {
3407 MATCH (); 3414 MATCH ();
3408 3415
3409 if (LOOKING_AT (IDENT)) 3416 if (LOOKING_AT (IDENT))
3410 { 3417 {
3411 char *namespace_name = xstrdup (yytext); 3418 char *namespace_name = xstrdup (yytext);
3412 MATCH (); 3419 MATCH ();
3413 3420
3414 if (LOOKING_AT ('=')) 3421 if (LOOKING_AT ('='))
3415 { 3422 {
3416 struct link *qna = match_qualified_namespace_alias (); 3423 struct link *qna = match_qualified_namespace_alias ();
3417 if (qna) 3424 if (qna)
3418 register_namespace_alias (namespace_name, qna); 3425 register_namespace_alias (namespace_name, qna);
3419 3426
3420 if (skip_to (';') == ';') 3427 if (skip_to (';') == ';')
3421 MATCH (); 3428 MATCH ();
3422 } 3429 }
3423 else if (LOOKING_AT ('{')) 3430 else if (LOOKING_AT ('{'))
3424 { 3431 {
3439 if (LOOKING_AT (CSTRING) && *string_start == 'C' 3446 if (LOOKING_AT (CSTRING) && *string_start == 'C'
3440 && *(string_start + 1) == '"') 3447 && *(string_start + 1) == '"')
3441 { 3448 {
3442 /* This is `extern "C"'. */ 3449 /* This is `extern "C"'. */
3443 MATCH (); 3450 MATCH ();
3444 3451
3445 if (LOOKING_AT ('{')) 3452 if (LOOKING_AT ('{'))
3446 { 3453 {
3447 MATCH (); 3454 MATCH ();
3448 globals (F_EXTERNC); 3455 globals (F_EXTERNC);
3449 MATCH_IF ('}'); 3456 MATCH_IF ('}');
3450 } 3457 }
3451 else 3458 else
3452 SET_FLAG (flags, F_EXTERNC); 3459 SET_FLAG (flags, F_EXTERNC);
3453 } 3460 }
3454 break; 3461 break;
3455 3462
3456 case TEMPLATE: 3463 case TEMPLATE:
3457 MATCH (); 3464 MATCH ();
3458 SKIP_MATCHING_IF ('<'); 3465 SKIP_MATCHING_IF ('<');
3459 SET_FLAG (flags, F_TEMPLATE); 3466 SET_FLAG (flags, F_TEMPLATE);
3460 break; 3467 break;
3490 case YYEOF: 3497 case YYEOF:
3491 return 1; 3498 return 1;
3492 3499
3493 case '}': 3500 case '}':
3494 return 0; 3501 return 0;
3495 3502
3496 default: 3503 default:
3497 declaration (flags); 3504 declaration (flags);
3498 flags = start_flags; 3505 flags = start_flags;
3499 break; 3506 break;
3500 } 3507 }
3529 { 3536 {
3530 while (*path_list) 3537 while (*path_list)
3531 { 3538 {
3532 char *start = path_list; 3539 char *start = path_list;
3533 struct search_path *p; 3540 struct search_path *p;
3534 3541
3535 while (*path_list && *path_list != PATH_LIST_SEPARATOR) 3542 while (*path_list && *path_list != PATH_LIST_SEPARATOR)
3536 ++path_list; 3543 ++path_list;
3537 3544
3538 p = (struct search_path *) xmalloc (sizeof *p); 3545 p = (struct search_path *) xmalloc (sizeof *p);
3539 p->path = (char *) xmalloc (path_list - start + 1); 3546 p->path = (char *) xmalloc (path_list - start + 1);
3540 memcpy (p->path, start, path_list - start); 3547 memcpy (p->path, start, path_list - start);
3541 p->path[path_list - start] = '\0'; 3548 p->path[path_list - start] = '\0';
3542 p->next = NULL; 3549 p->next = NULL;
3566 FILE *fp = NULL; 3573 FILE *fp = NULL;
3567 static char *buffer; 3574 static char *buffer;
3568 static int buffer_size; 3575 static int buffer_size;
3569 struct search_path *path; 3576 struct search_path *path;
3570 int flen = strlen (file) + 1; /* +1 for the slash */ 3577 int flen = strlen (file) + 1; /* +1 for the slash */
3571 3578
3572 filename = xstrdup (file); 3579 filename = xstrdup (file);
3573 3580
3574 for (path = search_path; path && fp == NULL; path = path->next) 3581 for (path = search_path; path && fp == NULL; path = path->next)
3575 { 3582 {
3576 int len = strlen (path->path) + flen; 3583 int len = strlen (path->path) + flen;
3578 if (len + 1 >= buffer_size) 3585 if (len + 1 >= buffer_size)
3579 { 3586 {
3580 buffer_size = max (len + 1, 2 * buffer_size); 3587 buffer_size = max (len + 1, 2 * buffer_size);
3581 buffer = (char *) xrealloc (buffer, buffer_size); 3588 buffer = (char *) xrealloc (buffer, buffer_size);
3582 } 3589 }
3583 3590
3584 strcpy (buffer, path->path); 3591 strcpy (buffer, path->path);
3585 strcat (buffer, "/"); 3592 strcat (buffer, "/");
3586 strcat (buffer, file); 3593 strcat (buffer, file);
3587 fp = fopen (buffer, "r"); 3594 fp = fopen (buffer, "r");
3588 } 3595 }
3589 3596
3590 /* Try the original file name. */ 3597 /* Try the original file name. */
3591 if (fp == NULL) 3598 if (fp == NULL)
3592 fp = fopen (file, "r"); 3599 fp = fopen (file, "r");
3593 3600
3594 if (fp == NULL) 3601 if (fp == NULL)
3595 yyerror ("cannot open", NULL); 3602 yyerror ("cannot open", NULL);
3596 3603
3597 return fp; 3604 return fp;
3598 } 3605 }
3599 3606
3600 3607
3601 /* Display usage information and exit program. */ 3608 /* Display usage information and exit program. */
3651 void 3658 void
3652 process_file (file) 3659 process_file (file)
3653 char *file; 3660 char *file;
3654 { 3661 {
3655 FILE *fp; 3662 FILE *fp;
3656 3663
3657 fp = open_file (file); 3664 fp = open_file (file);
3658 if (fp) 3665 if (fp)
3659 { 3666 {
3660 int nread, nbytes; 3667 int nread, nbytes;
3661 3668
3662 /* Give a progress indication if needed. */ 3669 /* Give a progress indication if needed. */
3663 if (f_very_verbose) 3670 if (f_very_verbose)
3664 { 3671 {
3677 if (nread + READ_CHUNK_SIZE >= inbuffer_size) 3684 if (nread + READ_CHUNK_SIZE >= inbuffer_size)
3678 { 3685 {
3679 inbuffer_size = nread + READ_CHUNK_SIZE + 1; 3686 inbuffer_size = nread + READ_CHUNK_SIZE + 1;
3680 inbuffer = (char *) xrealloc (inbuffer, inbuffer_size); 3687 inbuffer = (char *) xrealloc (inbuffer, inbuffer_size);
3681 } 3688 }
3682 3689
3683 nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp); 3690 nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp);
3684 if (nbytes <= 0) 3691 if (nbytes <= 0)
3685 break; 3692 break;
3686 nread += nbytes; 3693 nread += nbytes;
3687 } 3694 }
3720 buffer = (char *) xrealloc (buffer, buffer_size); 3727 buffer = (char *) xrealloc (buffer, buffer_size);
3721 } 3728 }
3722 3729
3723 buffer[i++] = c; 3730 buffer[i++] = c;
3724 } 3731 }
3725 3732
3726 if (c == EOF && i == 0) 3733 if (c == EOF && i == 0)
3727 return NULL; 3734 return NULL;
3728 3735
3729 if (i == buffer_size) 3736 if (i == buffer_size)
3730 { 3737 {
3731 buffer_size = max (100, buffer_size * 2); 3738 buffer_size = max (100, buffer_size * 2);
3732 buffer = (char *) xrealloc (buffer, buffer_size); 3739 buffer = (char *) xrealloc (buffer, buffer_size);
3733 } 3740 }
3763 { 3770 {
3764 /* Experimental. */ 3771 /* Experimental. */
3765 case 'p': 3772 case 'p':
3766 info_position = atoi (optarg); 3773 info_position = atoi (optarg);
3767 break; 3774 break;
3768 3775
3769 case 'n': 3776 case 'n':
3770 f_nested_classes = 0; 3777 f_nested_classes = 0;
3771 break; 3778 break;
3772 3779
3773 case 'x': 3780 case 'x':
3774 f_regexps = 0; 3781 f_regexps = 0;
3775 break; 3782 break;
3776 3783
3777 /* Add the name of a file containing more input files. */ 3784 /* Add the name of a file containing more input files. */
3778 case 'f': 3785 case 'f':
3779 if (n_input_files == input_filenames_size) 3786 if (n_input_files == input_filenames_size)
3780 { 3787 {
3781 input_filenames_size = max (10, 2 * input_filenames_size); 3788 input_filenames_size = max (10, 2 * input_filenames_size);
3868 rc = ftell (fp); 3875 rc = ftell (fp);
3869 if (rc == -1) 3876 if (rc == -1)
3870 yyerror ("error getting size of file `%s'", out_filename); 3877 yyerror ("error getting size of file `%s'", out_filename);
3871 else if (rc == 0) 3878 else if (rc == 0)
3872 yyerror ("file `%s' is empty", out_filename); 3879 yyerror ("file `%s' is empty", out_filename);
3873 3880
3874 fclose (fp); 3881 fclose (fp);
3875 } 3882 }
3876 3883
3877 yyout = fopen (out_filename, f_append ? "a" : "w"); 3884 yyout = fopen (out_filename, f_append ? "a" : "w");
3878 if (yyout == NULL) 3885 if (yyout == NULL)
3879 { 3886 {
3880 yyerror ("cannot open output file `%s'", out_filename); 3887 yyerror ("cannot open output file `%s'", out_filename);
3881 exit (1); 3888 exit (1);
3901 /* Process files from `--files=FILE'. Every line in FILE names 3908 /* Process files from `--files=FILE'. Every line in FILE names
3902 one input file to process. */ 3909 one input file to process. */
3903 for (i = 0; i < n_input_files; ++i) 3910 for (i = 0; i < n_input_files; ++i)
3904 { 3911 {
3905 FILE *fp = fopen (input_filenames[i], "r"); 3912 FILE *fp = fopen (input_filenames[i], "r");
3906 3913
3907 if (fp == NULL) 3914 if (fp == NULL)
3908 yyerror ("cannot open input file `%s'", input_filenames[i]); 3915 yyerror ("cannot open input file `%s'", input_filenames[i]);
3909 else 3916 else
3910 { 3917 {
3911 char *file; 3918 char *file;