comparison lib-src/ebrowse.c @ 30232:ad501fc526c2

(xrealloc, xmalloc): Renamed from yrealloc and ymalloc.
author Gerd Moellmann <gerd@gnu.org>
date Fri, 14 Jul 2000 17:59:55 +0000
parents d00767029418
children 2a6bbd7e52a1
comparison
equal deleted inserted replaced
30231:5b3608e3adaf 30232:ad501fc526c2
474 void add_member_defn P_ ((struct sym *, char *, char *, 474 void add_member_defn P_ ((struct sym *, char *, char *,
475 int, unsigned, int, int, int)); 475 int, unsigned, int, int, int));
476 void add_member_decl P_ ((struct sym *, char *, char *, int, 476 void add_member_decl P_ ((struct sym *, char *, char *, int,
477 unsigned, int, int, int, int)); 477 unsigned, int, int, int, int));
478 void dump_roots P_ ((FILE *)); 478 void dump_roots P_ ((FILE *));
479 void *ymalloc P_ ((int)); 479 void *xmalloc P_ ((int));
480 void add_global_defn P_ ((char *, char *, int, unsigned, int, int, int)); 480 void add_global_defn P_ ((char *, char *, int, unsigned, int, int, int));
481 void add_global_decl P_ ((char *, char *, int, unsigned, int, int, int)); 481 void add_global_decl P_ ((char *, char *, int, unsigned, int, int, int));
482 void add_define P_ ((char *, char *, int)); 482 void add_define P_ ((char *, char *, int));
483 void mark_inherited_virtual P_ ((void)); 483 void mark_inherited_virtual P_ ((void));
484 void leave_namespace P_ ((void)); 484 void leave_namespace P_ ((void));
540 available. This isn't called `xmalloc' because src/m/alpha.h, 540 available. This isn't called `xmalloc' because src/m/alpha.h,
541 and maybe others, contain an incompatible prototype for xmalloc 541 and maybe others, contain an incompatible prototype for xmalloc
542 and xrealloc. */ 542 and xrealloc. */
543 543
544 void * 544 void *
545 ymalloc (nbytes) 545 xmalloc (nbytes)
546 int nbytes; 546 int nbytes;
547 { 547 {
548 void *p = malloc (nbytes); 548 void *p = malloc (nbytes);
549 if (p == NULL) 549 if (p == NULL)
550 { 550 {
556 556
557 557
558 /* Like realloc but print an error and exit if out of memory. */ 558 /* Like realloc but print an error and exit if out of memory. */
559 559
560 void * 560 void *
561 yrealloc (p, sz) 561 xrealloc (p, sz)
562 void *p; 562 void *p;
563 int sz; 563 int sz;
564 { 564 {
565 p = realloc (p, sz); 565 p = realloc (p, sz);
566 if (p == NULL) 566 if (p == NULL)
578 char * 578 char *
579 xstrdup (s) 579 xstrdup (s)
580 char *s; 580 char *s;
581 { 581 {
582 if (s) 582 if (s)
583 s = strcpy (ymalloc (strlen (s) + 1), s); 583 s = strcpy (xmalloc (strlen (s) + 1), s);
584 return s; 584 return s;
585 } 585 }
586 586
587 587
588 588
631 { 631 {
632 putchar ('\t'); 632 putchar ('\t');
633 puts (name); 633 puts (name);
634 } 634 }
635 635
636 sym = (struct sym *) ymalloc (sizeof *sym + strlen (name)); 636 sym = (struct sym *) xmalloc (sizeof *sym + strlen (name));
637 bzero (sym, sizeof *sym); 637 bzero (sym, sizeof *sym);
638 strcpy (sym->name, name); 638 strcpy (sym->name, name);
639 sym->namesp = scope; 639 sym->namesp = scope;
640 sym->next = class_table[h]; 640 sym->next = class_table[h];
641 class_table[h] = sym; 641 class_table[h] = sym;
660 ; 660 ;
661 661
662 /* Avoid duplicates. */ 662 /* Avoid duplicates. */
663 if (p == NULL || p->sym != sub) 663 if (p == NULL || p->sym != sub)
664 { 664 {
665 lnk = (struct link *) ymalloc (sizeof *lnk); 665 lnk = (struct link *) xmalloc (sizeof *lnk);
666 lnk2 = (struct link *) ymalloc (sizeof *lnk2); 666 lnk2 = (struct link *) xmalloc (sizeof *lnk2);
667 667
668 lnk->sym = sub; 668 lnk->sym = sub;
669 lnk->next = p; 669 lnk->next = p;
670 670
671 if (prev) 671 if (prev)
957 char *name; 957 char *name;
958 int var; 958 int var;
959 int sc; 959 int sc;
960 unsigned hash; 960 unsigned hash;
961 { 961 {
962 struct member *m = (struct member *) ymalloc (sizeof *m + strlen (name)); 962 struct member *m = (struct member *) xmalloc (sizeof *m + strlen (name));
963 struct member **list; 963 struct member **list;
964 struct member *p; 964 struct member *p;
965 struct member *prev; 965 struct member *prev;
966 unsigned name_hash = 0; 966 unsigned name_hash = 0;
967 int i; 967 int i;
1069 1069
1070 struct sym * 1070 struct sym *
1071 make_namespace (name) 1071 make_namespace (name)
1072 char *name; 1072 char *name;
1073 { 1073 {
1074 struct sym *s = (struct sym *) ymalloc (sizeof *s + strlen (name)); 1074 struct sym *s = (struct sym *) xmalloc (sizeof *s + strlen (name));
1075 bzero (s, sizeof *s); 1075 bzero (s, sizeof *s);
1076 strcpy (s->name, name); 1076 strcpy (s->name, name);
1077 s->next = all_namespaces; 1077 s->next = all_namespaces;
1078 s->namesp = current_namespace; 1078 s->namesp = current_namespace;
1079 all_namespaces = s; 1079 all_namespaces = s;
1124 /* Is it already in the list of aliases? */ 1124 /* Is it already in the list of aliases? */
1125 for (al = p->namesp_aliases; al; al = al->next) 1125 for (al = p->namesp_aliases; al; al = al->next)
1126 if (streq (new_name, p->name)) 1126 if (streq (new_name, p->name))
1127 return; 1127 return;
1128 1128
1129 al = (struct alias *) ymalloc (sizeof *al + strlen (new_name)); 1129 al = (struct alias *) xmalloc (sizeof *al + strlen (new_name));
1130 strcpy (al->name, new_name); 1130 strcpy (al->name, new_name);
1131 al->next = p->namesp_aliases; 1131 al->next = p->namesp_aliases;
1132 p->namesp_aliases = al; 1132 p->namesp_aliases = al;
1133 } 1133 }
1134 1134
1142 struct sym *p = find_namespace (name); 1142 struct sym *p = find_namespace (name);
1143 1143
1144 if (namespace_sp == namespace_stack_size) 1144 if (namespace_sp == namespace_stack_size)
1145 { 1145 {
1146 int size = max (10, 2 * namespace_stack_size); 1146 int size = max (10, 2 * namespace_stack_size);
1147 namespace_stack = (struct sym **) yrealloc (namespace_stack, size); 1147 namespace_stack = (struct sym **) xrealloc (namespace_stack, size);
1148 namespace_stack_size = size; 1148 namespace_stack_size = size;
1149 } 1149 }
1150 1150
1151 namespace_stack[namespace_sp++] = current_namespace; 1151 namespace_stack[namespace_sp++] = current_namespace;
1152 current_namespace = p; 1152 current_namespace = p;
1202 int len; 1202 int len;
1203 { 1203 {
1204 if (scope_buffer_len + len >= scope_buffer_size) 1204 if (scope_buffer_len + len >= scope_buffer_size)
1205 { 1205 {
1206 int new_size = max (2 * scope_buffer_size, scope_buffer_len + len); 1206 int new_size = max (2 * scope_buffer_size, scope_buffer_len + len);
1207 scope_buffer = (char *) yrealloc (new_size); 1207 scope_buffer = (char *) xrealloc (new_size);
1208 scope_buffer_size = new_size; 1208 scope_buffer_size = new_size;
1209 } 1209 }
1210 } 1210 }
1211 1211
1212 1212
1254 struct sym *p; 1254 struct sym *p;
1255 { 1255 {
1256 if (!scope_buffer) 1256 if (!scope_buffer)
1257 { 1257 {
1258 scope_buffer_size = 1024; 1258 scope_buffer_size = 1024;
1259 scope_buffer = (char *) ymalloc (scope_buffer_size); 1259 scope_buffer = (char *) xmalloc (scope_buffer_size);
1260 } 1260 }
1261 1261
1262 *scope_buffer = '\0'; 1262 *scope_buffer = '\0';
1263 scope_buffer_len = 0; 1263 scope_buffer_len = 0;
1264 1264
1674 { 1674 {
1675 hash = (hash << 1) ^ *p++; 1675 hash = (hash << 1) ^ *p++;
1676 if (p == yytext_end - 1) 1676 if (p == yytext_end - 1)
1677 { 1677 {
1678 int size = yytext_end - yytext; 1678 int size = yytext_end - yytext;
1679 yytext = (char *) yrealloc (yytext, 2 * size); 1679 yytext = (char *) xrealloc (yytext, 2 * size);
1680 yytext_end = yytext + 2 * size; 1680 yytext_end = yytext + 2 * size;
1681 p = yytext + size - 1; 1681 p = yytext + size - 1;
1682 } 1682 }
1683 } 1683 }
1684 1684
1952 if (!f_regexps) 1952 if (!f_regexps)
1953 return NULL; 1953 return NULL;
1954 1954
1955 if (buffer == NULL) 1955 if (buffer == NULL)
1956 { 1956 {
1957 buffer = (char *) ymalloc (max_regexp); 1957 buffer = (char *) xmalloc (max_regexp);
1958 end_buf = &buffer[max_regexp] - 1; 1958 end_buf = &buffer[max_regexp] - 1;
1959 } 1959 }
1960 1960
1961 /* Scan back to previous newline of buffer start. */ 1961 /* Scan back to previous newline of buffer start. */
1962 for (p = in - 1; p > inbuffer && *p != '\n'; --p) 1962 for (p = in - 1; p > inbuffer && *p != '\n'; --p)
2117 yyline = 1; 2117 yyline = 1;
2118 2118
2119 if (yytext == NULL) 2119 if (yytext == NULL)
2120 { 2120 {
2121 int size = 256; 2121 int size = 256;
2122 yytext = (char *) ymalloc (size * sizeof *yytext); 2122 yytext = (char *) xmalloc (size * sizeof *yytext);
2123 yytext_end = yytext + size; 2123 yytext_end = yytext + size;
2124 } 2124 }
2125 } 2125 }
2126 2126
2127 2127
2133 char *name; 2133 char *name;
2134 int tk; 2134 int tk;
2135 { 2135 {
2136 char *s; 2136 char *s;
2137 unsigned h = 0; 2137 unsigned h = 0;
2138 struct kw *k = (struct kw *) ymalloc (sizeof *k); 2138 struct kw *k = (struct kw *) xmalloc (sizeof *k);
2139 2139
2140 for (s = name; *s; ++s) 2140 for (s = name; *s; ++s)
2141 h = (h << 1) ^ *s; 2141 h = (h << 1) ^ *s;
2142 2142
2143 h %= KEYWORD_TABLE_SIZE; 2143 h %= KEYWORD_TABLE_SIZE;
2156 { 2156 {
2157 int i; 2157 int i;
2158 2158
2159 /* Allocate the input buffer */ 2159 /* Allocate the input buffer */
2160 inbuffer_size = READ_CHUNK_SIZE + 1; 2160 inbuffer_size = READ_CHUNK_SIZE + 1;
2161 inbuffer = in = (char *) ymalloc (inbuffer_size); 2161 inbuffer = in = (char *) xmalloc (inbuffer_size);
2162 yyline = 1; 2162 yyline = 1;
2163 2163
2164 /* Set up character class vectors. */ 2164 /* Set up character class vectors. */
2165 for (i = 0; i < sizeof is_ident; ++i) 2165 for (i = 0; i < sizeof is_ident; ++i)
2166 { 2166 {
2815 2815
2816 len = strlen (s) + 10; 2816 len = strlen (s) + 10;
2817 if (len > id_size) 2817 if (len > id_size)
2818 { 2818 {
2819 int new_size = max (len, 2 * id_size); 2819 int new_size = max (len, 2 * id_size);
2820 id = (char *) yrealloc (id, new_size); 2820 id = (char *) xrealloc (id, new_size);
2821 id_size = new_size; 2821 id_size = new_size;
2822 } 2822 }
2823 strcpy (id, s); 2823 strcpy (id, s);
2824 2824
2825 /* Vector new or delete? */ 2825 /* Vector new or delete? */
2841 2841
2842 len = 20; 2842 len = 20;
2843 if (len > id_size) 2843 if (len > id_size)
2844 { 2844 {
2845 int new_size = max (len, 2 * id_size); 2845 int new_size = max (len, 2 * id_size);
2846 id = (char *) yrealloc (id, new_size); 2846 id = (char *) xrealloc (id, new_size);
2847 id_size = new_size; 2847 id_size = new_size;
2848 } 2848 }
2849 strcpy (id, "operator"); 2849 strcpy (id, "operator");
2850 2850
2851 /* Beware access declarations of the form "X::f;" Beware of 2851 /* Beware access declarations of the form "X::f;" Beware of
2857 s = token_string (LA1); 2857 s = token_string (LA1);
2858 len += strlen (s) + 2; 2858 len += strlen (s) + 2;
2859 if (len > id_size) 2859 if (len > id_size)
2860 { 2860 {
2861 int new_size = max (len, 2 * id_size); 2861 int new_size = max (len, 2 * id_size);
2862 id = (char *) yrealloc (id, new_size); 2862 id = (char *) xrealloc (id, new_size);
2863 id_size = new_size; 2863 id_size = new_size;
2864 } 2864 }
2865 2865
2866 if (*s != ')' && *s != ']') 2866 if (*s != ')' && *s != ']')
2867 strcat (id, " "); 2867 strcat (id, " ");
2895 while (LOOKING_AT (IDENT)) 2895 while (LOOKING_AT (IDENT))
2896 { 2896 {
2897 int len = strlen (yytext) + 1; 2897 int len = strlen (yytext) + 1;
2898 if (len > id_size) 2898 if (len > id_size)
2899 { 2899 {
2900 id = (char *) yrealloc (id, len); 2900 id = (char *) xrealloc (id, len);
2901 id_size = len; 2901 id_size = len;
2902 } 2902 }
2903 strcpy (id, yytext); 2903 strcpy (id, yytext);
2904 *last_id = id; 2904 *last_id = id;
2905 MATCH (); 2905 MATCH ();
2935 while (LOOKING_AT (IDENT)) 2935 while (LOOKING_AT (IDENT))
2936 { 2936 {
2937 int len = strlen (yytext) + 1; 2937 int len = strlen (yytext) + 1;
2938 if (len > id_size) 2938 if (len > id_size)
2939 { 2939 {
2940 id = (char *) yrealloc (id, len); 2940 id = (char *) xrealloc (id, len);
2941 id_size = len; 2941 id_size = len;
2942 } 2942 }
2943 strcpy (id, yytext); 2943 strcpy (id, yytext);
2944 *last_id = id; 2944 *last_id = id;
2945 MATCH (); 2945 MATCH ();
3381 struct search_path *p; 3381 struct search_path *p;
3382 3382
3383 while (*path_list && *path_list != PATH_LIST_SEPARATOR) 3383 while (*path_list && *path_list != PATH_LIST_SEPARATOR)
3384 ++path_list; 3384 ++path_list;
3385 3385
3386 p = (struct search_path *) ymalloc (sizeof *p); 3386 p = (struct search_path *) xmalloc (sizeof *p);
3387 p->path = (char *) ymalloc (path_list - start + 1); 3387 p->path = (char *) xmalloc (path_list - start + 1);
3388 memcpy (p->path, start, path_list - start); 3388 memcpy (p->path, start, path_list - start);
3389 p->path[path_list - start] = '\0'; 3389 p->path[path_list - start] = '\0';
3390 p->next = NULL; 3390 p->next = NULL;
3391 3391
3392 if (search_path_tail) 3392 if (search_path_tail)
3424 int len = strlen (path->path) + flen; 3424 int len = strlen (path->path) + flen;
3425 3425
3426 if (len + 1 >= buffer_size) 3426 if (len + 1 >= buffer_size)
3427 { 3427 {
3428 buffer_size = max (len + 1, 2 * buffer_size); 3428 buffer_size = max (len + 1, 2 * buffer_size);
3429 buffer = (char *) yrealloc (buffer, buffer_size); 3429 buffer = (char *) xrealloc (buffer, buffer_size);
3430 } 3430 }
3431 3431
3432 strcpy (buffer, path->path); 3432 strcpy (buffer, path->path);
3433 strcat (buffer, "/"); 3433 strcat (buffer, "/");
3434 strcat (buffer, file); 3434 strcat (buffer, file);
3519 for (nread = 0;;) 3519 for (nread = 0;;)
3520 { 3520 {
3521 if (nread + READ_CHUNK_SIZE >= inbuffer_size) 3521 if (nread + READ_CHUNK_SIZE >= inbuffer_size)
3522 { 3522 {
3523 inbuffer_size = nread + READ_CHUNK_SIZE + 1; 3523 inbuffer_size = nread + READ_CHUNK_SIZE + 1;
3524 inbuffer = (char *) yrealloc (inbuffer, inbuffer_size); 3524 inbuffer = (char *) xrealloc (inbuffer, inbuffer_size);
3525 } 3525 }
3526 3526
3527 nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp); 3527 nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp);
3528 if (nbytes <= 0) 3528 if (nbytes <= 0)
3529 break; 3529 break;
3559 while ((c = getc (fp)) != EOF && c != '\n') 3559 while ((c = getc (fp)) != EOF && c != '\n')
3560 { 3560 {
3561 if (i >= buffer_size) 3561 if (i >= buffer_size)
3562 { 3562 {
3563 buffer_size = max (100, buffer_size * 2); 3563 buffer_size = max (100, buffer_size * 2);
3564 buffer = (char *) yrealloc (buffer, buffer_size); 3564 buffer = (char *) xrealloc (buffer, buffer_size);
3565 } 3565 }
3566 3566
3567 buffer[i++] = c; 3567 buffer[i++] = c;
3568 } 3568 }
3569 3569
3571 return NULL; 3571 return NULL;
3572 3572
3573 if (i == buffer_size) 3573 if (i == buffer_size)
3574 { 3574 {
3575 buffer_size = max (100, buffer_size * 2); 3575 buffer_size = max (100, buffer_size * 2);
3576 buffer = (char *) yrealloc (buffer, buffer_size); 3576 buffer = (char *) xrealloc (buffer, buffer_size);
3577 } 3577 }
3578 3578
3579 buffer[i] = '\0'; 3579 buffer[i] = '\0';
3580 return buffer; 3580 return buffer;
3581 } 3581 }
3619 /* Add the name of a file containing more input files. */ 3619 /* Add the name of a file containing more input files. */
3620 case 'f': 3620 case 'f':
3621 if (n_input_files == input_filenames_size) 3621 if (n_input_files == input_filenames_size)
3622 { 3622 {
3623 input_filenames_size = max (10, 2 * input_filenames_size); 3623 input_filenames_size = max (10, 2 * input_filenames_size);
3624 input_filenames = (char **) yrealloc (input_filenames, 3624 input_filenames = (char **) xrealloc (input_filenames,
3625 input_filenames_size); 3625 input_filenames_size);
3626 } 3626 }
3627 input_filenames[n_input_files++] = xstrdup (optarg); 3627 input_filenames[n_input_files++] = xstrdup (optarg);
3628 break; 3628 break;
3629 3629