History

genksyms: Add helpers for building string lists

Michal Marek committed 15 years ago

Commit 68eb8561 parent 7ec8eda1 file · +38 −32Browse files

Unified · Split

scripts/genksyms/genksyms.c+38−32
@@ -66,6 +66,8 @@ static const struct { · 65 unmodified lines
66 66
67static int equal_list(struct string_list *a, struct string_list *b);67static int equal_list(struct string_list *a, struct string_list *b);
68static void print_list(FILE * f, struct string_list *list);68static void print_list(FILE * f, struct string_list *list);
69static struct string_list *concat_list(struct string_list *start, ...);
70static struct string_list *mk_node(const char *string);
69static void print_location(void);71static void print_location(void);
70static void print_type_name(enum symbol_type type, const char *name);72static void print_type_name(enum symbol_type type, const char *name);
71 73
@@ -299,6 +301,35 @@ void free_list(struct string_list *s, struct string_list *e) · 227 unmodified lines
299 }301 }
300}302}
301 303
304static 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
316static 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
302struct string_list *copy_node(struct string_list *node)333struct string_list *copy_node(struct string_list *node)
303{334{
304 struct string_list *newnode;335 struct string_list *newnode;
@@ -499,42 +530,17 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc) · 194 unmodified lines
499 case SYM_ENUM:530 case SYM_ENUM:
500 subsym = find_symbol(cur->string, cur->tag);531 subsym = find_symbol(cur->string, cur->tag);
501 if (!subsym) {532 if (!subsym) {
502 struct string_list *n, *t = NULL;533 struct string_list *n;
503 534
504 error_with_pos("expand undefined %s %s",535 error_with_pos("expand undefined %s %s",
505 symbol_types[cur->tag].name,536 symbol_types[cur->tag].name,
506 cur->string);537 cur->string);
507 538 n = concat_list(mk_node
508 n = xmalloc(sizeof(*n));539 (symbol_types[cur->tag].name),
509 n->string = xstrdup(symbol_types[cur->tag].name);540 mk_node(cur->string),
510 n->tag = SYM_NORMAL;541 mk_node("{"),
511 n->next = t;542 mk_node("UNKNOWN"),
512 t = n;543 mk_node("}"), NULL);
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 subsym =544 subsym =
539 add_symbol(cur->string, cur->tag, n, 0);545 add_symbol(cur->string, cur->tag, n, 0);
540 }546 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t