@@ -66,6 +66,8 @@ static const struct {
6666
6767static int equal_list (struct string_list * a , struct string_list * b );
6868static void print_list (FILE * f , struct string_list * list );
69+ static struct string_list * concat_list (struct string_list * start , ...);
70+ static struct string_list * mk_node (const char * string );
6971static void print_location (void );
7072static void print_type_name (enum symbol_type type , const char * name );
7173
@@ -299,6 +301,35 @@ void free_list(struct string_list *s, struct string_list *e)
299301 }
300302}
301303
304+ static struct string_list * mk_node (const char * string )
305+ {
306+ struct string_list * newnode ;
307+
308+ newnode = xmalloc (sizeof (* newnode ));
309+ newnode -> string = xstrdup (string );
310+ newnode -> tag = SYM_NORMAL ;
311+ newnode -> next = NULL ;
312+
313+ return newnode ;
314+ }
315+
316+ static struct string_list * concat_list (struct string_list * start , ...)
317+ {
318+ va_list ap ;
319+ struct string_list * n , * n2 ;
320+
321+ if (!start )
322+ return NULL ;
323+ for (va_start (ap , start ); (n = va_arg (ap , struct string_list * ));) {
324+ for (n2 = n ; n2 -> next ; n2 = n2 -> next )
325+ ;
326+ n2 -> next = start ;
327+ start = n ;
328+ }
329+ va_end (ap );
330+ return start ;
331+ }
332+
302333struct string_list * copy_node (struct string_list * node )
303334{
304335 struct string_list * newnode ;
@@ -499,42 +530,17 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc)
499530 case SYM_ENUM :
500531 subsym = find_symbol (cur -> string , cur -> tag );
501532 if (!subsym ) {
502- struct string_list * n , * t = NULL ;
533+ struct string_list * n ;
503534
504535 error_with_pos ("expand undefined %s %s" ,
505536 symbol_types [cur -> tag ].name ,
506537 cur -> string );
507-
508- n = xmalloc (sizeof (* n ));
509- n -> string = xstrdup (symbol_types [cur -> tag ].name );
510- n -> tag = SYM_NORMAL ;
511- n -> next = t ;
512- t = n ;
513-
514- n = xmalloc (sizeof (* n ));
515- n -> string = xstrdup (cur -> string );
516- n -> tag = SYM_NORMAL ;
517- n -> next = t ;
518- t = n ;
519-
520- n = xmalloc (sizeof (* n ));
521- n -> string = xstrdup ("{" );
522- n -> tag = SYM_NORMAL ;
523- n -> next = t ;
524- t = n ;
525-
526- n = xmalloc (sizeof (* n ));
527- n -> string = xstrdup ("UNKNOWN" );
528- n -> tag = SYM_NORMAL ;
529- n -> next = t ;
530- t = n ;
531-
532- n = xmalloc (sizeof (* n ));
533- n -> string = xstrdup ("}" );
534- n -> tag = SYM_NORMAL ;
535- n -> next = t ;
536- t = n ;
537-
538+ n = concat_list (mk_node
539+ (symbol_types [cur -> tag ].name ),
540+ mk_node (cur -> string ),
541+ mk_node ("{" ),
542+ mk_node ("UNKNOWN" ),
543+ mk_node ("}" ), NULL );
538544 subsym =
539545 add_symbol (cur -> string , cur -> tag , n , 0 );
540546 }
0 commit comments