All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Marek <mmarek@suse.cz>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 4/7] genksyms: Add helpers for building string lists
Date: Sun, 13 Mar 2011 07:30:22 +0100	[thread overview]
Message-ID: <1299997825-18977-5-git-send-email-mmarek@suse.cz> (raw)
In-Reply-To: <1299997825-18977-1-git-send-email-mmarek@suse.cz>

Signed-off-by: Michal Marek <mmarek@suse.cz>
---
 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 2a1a3b8..d17b7a2 100644
--- a/scripts/genksyms/genksyms.c
+++ b/scripts/genksyms/genksyms.c
@@ -66,6 +66,8 @@ static const struct {
 
 static int equal_list(struct string_list *a, struct string_list *b);
 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_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 *newnode;
@@ -499,42 +530,17 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc)
 		case SYM_ENUM:
 			subsym = find_symbol(cur->string, cur->tag);
 			if (!subsym) {
-				struct string_list *n, *t = NULL;
+				struct string_list *n;
 
 				error_with_pos("expand undefined %s %s",
 					       symbol_types[cur->tag].name,
 					       cur->string);
-
-				n = xmalloc(sizeof(*n));
-				n->string = xstrdup(symbol_types[cur->tag].name);
-				n->tag = SYM_NORMAL;
-				n->next = t;
-				t = n;
-
-				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;
-
+				n = concat_list(mk_node
+						(symbol_types[cur->tag].name),
+						mk_node(cur->string),
+						mk_node("{"),
+						mk_node("UNKNOWN"),
+						mk_node("}"), NULL);
 				subsym =
 				    add_symbol(cur->string, cur->tag, n, 0);
 			}
-- 
1.7.4.1


  parent reply	other threads:[~2011-03-13  6:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-13  6:30 [PATCH 0/7] genksyms: Track changes to enum constant Michal Marek
2011-03-13  6:30 ` [PATCH 1/7] genksyms: Do not paste the bison header file to lex.c Michal Marek
2011-03-13  6:30 ` [PATCH 2/7] genksyms: Simplify lexer Michal Marek
2011-03-13  6:30 ` [PATCH 3/7] genksyms: Simplify printing of symbol types Michal Marek
2011-03-13  6:30 ` Michal Marek [this message]
2011-03-13  6:30 ` [PATCH 5/7] genksyms: simplify usage of find_symbol() Michal Marek
2011-03-13  6:30 ` [PATCH 6/7] genksyms: Track changes to enum constants Michal Marek
2011-03-13  6:30 ` [PATCH 7/7] genksyms: Regenerate lexer and parser Michal Marek
2011-03-13  7:19 ` [PATCH 0/7] genksyms: Track changes to enum constant Sam Ravnborg
2011-03-13 13:40   ` Michal Marek
2011-03-17 14:18     ` Michal Marek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1299997825-18977-5-git-send-email-mmarek@suse.cz \
    --to=mmarek@suse.cz \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.