diff options
author | Michal Marek <mmarek@suse.cz> | 2011-02-02 17:52:13 -0500 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2011-03-17 10:13:55 -0400 |
commit | 68eb8563a1adf27fae18dde4c95fb796c17563df (patch) | |
tree | 792085b5e18719922554bc72ccfb8a1d042a262c /scripts | |
parent | 7ec8eda154cbdcabb5305d90fb0952973dcaa560 (diff) |
genksyms: Add helpers for building string lists
Signed-off-by: Michal Marek <mmarek@suse.cz>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/genksyms/genksyms.c | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c index 2a1a3b84beba..d17b7a2b941f 100644 --- a/scripts/genksyms/genksyms.c +++ b/scripts/genksyms/genksyms.c | |||
@@ -66,6 +66,8 @@ static const struct { | |||
66 | 66 | ||
67 | static int equal_list(struct string_list *a, struct string_list *b); | 67 | static int equal_list(struct string_list *a, struct string_list *b); |
68 | static void print_list(FILE * f, struct string_list *list); | 68 | static 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); | ||
69 | static void print_location(void); | 71 | static void print_location(void); |
70 | static void print_type_name(enum symbol_type type, const char *name); | 72 | static 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) | |||
299 | } | 301 | } |
300 | } | 302 | } |
301 | 303 | ||
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 | |||
302 | struct string_list *copy_node(struct string_list *node) | 333 | struct 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) | |||
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 | } |