diff options
author | Sam Ravnborg <sam@mars.ravnborg.org> | 2005-01-03 23:17:14 +0100 |
---|---|---|
committer | Sam Ravnborg <sam@mars.ravnborg.org> | 2005-01-03 23:17:14 +0100 |
commit | f7f364646ca46423e26d2185cfc8a68e91cef2f7 (patch) | |
tree | b66457a1de27f91a92e2d46e788b33c66bad82f4 /scripts | |
parent | dd5c154428950357a5fb885b4d3c86a8fbefd92d (diff) | |
download | history-f7f364646ca46423e26d2185cfc8a68e91cef2f7.tar.gz |
kconfig: introduce util.c
Moved two functions from menu.c to new file util.c.
Introduced functions to handle growable strings - no user yet.
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/kconfig/lkc.h | 13 | ||||
-rw-r--r-- | scripts/kconfig/menu.c | 40 | ||||
-rw-r--r-- | scripts/kconfig/util.c | 109 | ||||
-rw-r--r-- | scripts/kconfig/zconf.tab.c_shipped | 1 | ||||
-rw-r--r-- | scripts/kconfig/zconf.y | 1 |
5 files changed, 124 insertions, 40 deletions
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index e348ee7d86a54d..b8a67fc9d6476d 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -56,9 +56,22 @@ void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep); void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep); void menu_finalize(struct menu *parent); void menu_set_type(int type); + +/* util.c */ struct file *file_lookup(const char *name); int file_write_dep(const char *name); +struct gstr { + size_t len; + char *s; +}; +struct gstr str_new(void); +struct gstr str_assign(const char *s); +void str_free(struct gstr *gs); +void str_append(struct gstr *gs, const char *s); +void str_printf(struct gstr *gs, const char *fmt, ...); +const char *str_get(struct gstr *gs); + /* symbol.c */ void sym_init(void); void sym_clear_all_valid(void); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 7b26f982bad59f..0c13156f33441f 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -388,43 +388,3 @@ struct menu *menu_get_parent_menu(struct menu *menu) return menu; } -struct file *file_lookup(const char *name) -{ - struct file *file; - - for (file = file_list; file; file = file->next) { - if (!strcmp(name, file->name)) - return file; - } - - file = malloc(sizeof(*file)); - memset(file, 0, sizeof(*file)); - file->name = strdup(name); - file->next = file_list; - file_list = file; - return file; -} - -int file_write_dep(const char *name) -{ - struct file *file; - FILE *out; - - if (!name) - name = ".config.cmd"; - out = fopen("..config.tmp", "w"); - if (!out) - return 1; - fprintf(out, "deps_config := \\\n"); - for (file = file_list; file; file = file->next) { - if (file->next) - fprintf(out, "\t%s \\\n", file->name); - else - fprintf(out, "\t%s\n", file->name); - } - fprintf(out, "\n.config include/linux/autoconf.h: $(deps_config)\n\n$(deps_config):\n"); - fclose(out); - rename("..config.tmp", name); - return 0; -} - diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c new file mode 100644 index 00000000000000..1fa4c0b801b34f --- /dev/null +++ b/scripts/kconfig/util.c @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2002-2005 Roman Zippel <zippel@linux-m68k.org> + * Copyright (C) 2002-2005 Sam Ravnborg <sam@ravnborg.org> + * + * Released under the terms of the GNU GPL v2.0. + */ + +#include <string.h> +#include "lkc.h" + +/* file already present in list? If not add it */ +struct file *file_lookup(const char *name) +{ + struct file *file; + + for (file = file_list; file; file = file->next) { + if (!strcmp(name, file->name)) + return file; + } + + file = malloc(sizeof(*file)); + memset(file, 0, sizeof(*file)); + file->name = strdup(name); + file->next = file_list; + file_list = file; + return file; +} + +/* write a dependency file as used by kbuild to track dependencies */ +int file_write_dep(const char *name) +{ + struct file *file; + FILE *out; + + if (!name) + name = ".config.cmd"; + out = fopen("..config.tmp", "w"); + if (!out) + return 1; + fprintf(out, "deps_config := \\\n"); + for (file = file_list; file; file = file->next) { + if (file->next) + fprintf(out, "\t%s \\\n", file->name); + else + fprintf(out, "\t%s\n", file->name); + } + fprintf(out, "\n.config include/linux/autoconf.h: $(deps_config)\n\n$(deps_config):\n"); + fclose(out); + rename("..config.tmp", name); + return 0; +} + + +/* Allocate initial growable sting */ +struct gstr str_new(void) +{ + struct gstr gs; + gs.s = malloc(sizeof(char) * 64); + gs.len = 16; + strcpy(gs.s, "\0"); + return gs; +} + +/* Allocate and assign growable string */ +struct gstr str_assign(const char *s) +{ + struct gstr gs; + gs.s = strdup(s); + gs.len = strlen(s) + 1; + return gs; +} + +/* Free storage for growable string */ +void str_free(struct gstr *gs) +{ + if (gs->s) + free(gs->s); + gs->s = NULL; + gs->len = 0; +} + +/* Append to growable string */ +void str_append(struct gstr *gs, const char *s) +{ + size_t l = strlen(gs->s) + strlen(s) + 1; + if (l > gs->len) { + gs->s = realloc(gs->s, l); + gs->len = l; + } + strcat(gs->s, s); +} + +/* Append printf formatted string to growable string */ +void str_printf(struct gstr *gs, const char *fmt, ...) +{ + va_list ap; + char s[10000]; /* big enough... */ + va_start(ap, fmt); + vsnprintf(s, sizeof(s), fmt, ap); + str_append(gs, s); + va_end(ap); +} + +/* Retreive value of growable string */ +const char *str_get(struct gstr *gs) +{ + return gs->s; +} + diff --git a/scripts/kconfig/zconf.tab.c_shipped b/scripts/kconfig/zconf.tab.c_shipped index a48105a405bb77..f163d8d2d9ef2e 100644 --- a/scripts/kconfig/zconf.tab.c_shipped +++ b/scripts/kconfig/zconf.tab.c_shipped @@ -2121,6 +2121,7 @@ void zconfdump(FILE *out) } #include "lex.zconf.c" +#include "util.c" #include "confdata.c" #include "expr.c" #include "symbol.c" diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index aad1f51147656a..54460f8d3696b2 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -683,6 +683,7 @@ void zconfdump(FILE *out) } #include "lex.zconf.c" +#include "util.c" #include "confdata.c" #include "expr.c" #include "symbol.c" |