genksyms: Add helpers for building string lists
Signed-off-by: Michal Marek <mmarek@suse.cz> Acked-by: Sam Ravnborg <sam@ravnborg.org>
This commit is contained in:
parent
7ec8eda154
commit
68eb8563a1
|
@ -66,6 +66,8 @@ static const struct {
|
||||||
|
|
||||||
static int equal_list(struct string_list *a, struct string_list *b);
|
static int equal_list(struct string_list *a, struct string_list *b);
|
||||||
static void print_list(FILE * f, struct string_list *list);
|
static void print_list(FILE * f, struct string_list *list);
|
||||||
|
static struct string_list *concat_list(struct string_list *start, ...);
|
||||||
|
static struct string_list *mk_node(const char *string);
|
||||||
static void print_location(void);
|
static void print_location(void);
|
||||||
static void print_type_name(enum symbol_type type, const char *name);
|
static void print_type_name(enum symbol_type type, const char *name);
|
||||||
|
|
||||||
|
@ -299,6 +301,35 @@ void free_list(struct string_list *s, struct string_list *e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct string_list *mk_node(const char *string)
|
||||||
|
{
|
||||||
|
struct string_list *newnode;
|
||||||
|
|
||||||
|
newnode = xmalloc(sizeof(*newnode));
|
||||||
|
newnode->string = xstrdup(string);
|
||||||
|
newnode->tag = SYM_NORMAL;
|
||||||
|
newnode->next = NULL;
|
||||||
|
|
||||||
|
return newnode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct string_list *concat_list(struct string_list *start, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
struct string_list *n, *n2;
|
||||||
|
|
||||||
|
if (!start)
|
||||||
|
return NULL;
|
||||||
|
for (va_start(ap, start); (n = va_arg(ap, struct string_list *));) {
|
||||||
|
for (n2 = n; n2->next; n2 = n2->next)
|
||||||
|
;
|
||||||
|
n2->next = start;
|
||||||
|
start = n;
|
||||||
|
}
|
||||||
|
va_end(ap);
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
struct string_list *copy_node(struct string_list *node)
|
struct string_list *copy_node(struct string_list *node)
|
||||||
{
|
{
|
||||||
struct string_list *newnode;
|
struct string_list *newnode;
|
||||||
|
@ -499,42 +530,17 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc)
|
||||||
case SYM_ENUM:
|
case SYM_ENUM:
|
||||||
subsym = find_symbol(cur->string, cur->tag);
|
subsym = find_symbol(cur->string, cur->tag);
|
||||||
if (!subsym) {
|
if (!subsym) {
|
||||||
struct string_list *n, *t = NULL;
|
struct string_list *n;
|
||||||
|
|
||||||
error_with_pos("expand undefined %s %s",
|
error_with_pos("expand undefined %s %s",
|
||||||
symbol_types[cur->tag].name,
|
symbol_types[cur->tag].name,
|
||||||
cur->string);
|
cur->string);
|
||||||
|
n = concat_list(mk_node
|
||||||
n = xmalloc(sizeof(*n));
|
(symbol_types[cur->tag].name),
|
||||||
n->string = xstrdup(symbol_types[cur->tag].name);
|
mk_node(cur->string),
|
||||||
n->tag = SYM_NORMAL;
|
mk_node("{"),
|
||||||
n->next = t;
|
mk_node("UNKNOWN"),
|
||||||
t = n;
|
mk_node("}"), NULL);
|
||||||
|
|
||||||
n = xmalloc(sizeof(*n));
|
|
||||||
n->string = xstrdup(cur->string);
|
|
||||||
n->tag = SYM_NORMAL;
|
|
||||||
n->next = t;
|
|
||||||
t = n;
|
|
||||||
|
|
||||||
n = xmalloc(sizeof(*n));
|
|
||||||
n->string = xstrdup("{");
|
|
||||||
n->tag = SYM_NORMAL;
|
|
||||||
n->next = t;
|
|
||||||
t = n;
|
|
||||||
|
|
||||||
n = xmalloc(sizeof(*n));
|
|
||||||
n->string = xstrdup("UNKNOWN");
|
|
||||||
n->tag = SYM_NORMAL;
|
|
||||||
n->next = t;
|
|
||||||
t = n;
|
|
||||||
|
|
||||||
n = xmalloc(sizeof(*n));
|
|
||||||
n->string = xstrdup("}");
|
|
||||||
n->tag = SYM_NORMAL;
|
|
||||||
n->next = t;
|
|
||||||
t = n;
|
|
||||||
|
|
||||||
subsym =
|
subsym =
|
||||||
add_symbol(cur->string, cur->tag, n, 0);
|
add_symbol(cur->string, cur->tag, n, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue