From c8a33ffb0aad5ebc2f50045eb8a460daa67f446d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 28 Jul 2015 10:23:29 +0200 Subject: Allconfig add inv option Added inv option for generating inverted configurations. Inverted configuration contains configuration options that are not in original configuration file. --- scripts/allconfig/Makefile | 3 ++- scripts/allconfig/allconfig.c | 28 +++++++++++++++++++---- scripts/allconfig/inv.c | 53 +++++++++++++++++++++++++++++++++++++++++++ scripts/allconfig/inv.h | 18 +++++++++++++++ 4 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 scripts/allconfig/inv.c create mode 100644 scripts/allconfig/inv.h diff --git a/scripts/allconfig/Makefile b/scripts/allconfig/Makefile index ffe320e..44e7b7b 100644 --- a/scripts/allconfig/Makefile +++ b/scripts/allconfig/Makefile @@ -7,7 +7,8 @@ all: allconfig KCONFIG_PREFIX = ../shared/kconfig include $(KCONFIG_PREFIX)/files.mk -SRC = allconfig.c +SRC = allconfig.c \ + inv.c OBJ = $(patsubst %.c,%.o,$(SRC)) CFLAGS = -O0 -Wall -ggdb -DDEBUG INCLUDES = -I../shared diff --git a/scripts/allconfig/allconfig.c b/scripts/allconfig/allconfig.c index acd1050..19486e4 100644 --- a/scripts/allconfig/allconfig.c +++ b/scripts/allconfig/allconfig.c @@ -7,9 +7,10 @@ #include #include #include +#include "inv.h" int verbose_level; -bool full_config; +bool full_config, inv_config; char *kconfig_file; char *output_config_file; @@ -25,10 +26,12 @@ int main(int argc, char **argv) { if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { print_help(); exit(0); - } else if (!strcmp(argv[i], "-v")) { + } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose")) { verbose_level++; } else if (!strcmp(argv[i], "--all")) { full_config = true; + } else if (!strcmp(argv[i], "--inv")) { + inv_config = true; } else if (kconfig_file == NULL) { kconfig_file = argv[i]; } else if (input_config_file == NULL) { @@ -55,6 +58,10 @@ int main(int argc, char **argv) { conf_parse(kconfig_file); conf_read(input_config_file); + if (inv_config) { + inv_prepare(input_config_file); + } + struct symbol *sym; sym = sym_find("MODULES"); if (sym == NULL) { @@ -83,8 +90,9 @@ int main(int argc, char **argv) { goto printit; continue; printit: - fprintf(f, "CONFIG_%s=%s\n", sym->name, - sym_get_tristate_value(sym) == no ? "n" : "y"); + if (!inv_config || !inv_fixed(sym)) + fprintf(f, "CONFIG_%s=%s\n", sym->name, + sym_get_tristate_value(sym) == no ? "n" : "y"); } } fclose(f); @@ -93,7 +101,17 @@ int main(int argc, char **argv) { } void print_help() { - printf("Usage: allconfig [-v] [-h] Kconfig Input Output\n"); + printf + ("Usage: allconfig [-v] [-h] [--all] [--inv] Kconfig Input Output\n"); printf(" This is generating full configuration.\n"); printf(" Output configuration has all configuration options.\n"); + printf("\n"); + printf(" Options:\n"); + printf(" -v, --verbose Increase level of verbose output.\n"); + printf(" -h, --help Print this help text.\n"); + printf + (" --all Genetate full configuration. Including non dependency\n"); + printf(" configuration options"); + printf + (" --inv Generate configuration of missing configratuon options.\n"); } diff --git a/scripts/allconfig/inv.c b/scripts/allconfig/inv.c new file mode 100644 index 0000000..0e87163 --- /dev/null +++ b/scripts/allconfig/inv.c @@ -0,0 +1,53 @@ +#include "inv.h" + +void inv_prepare(char *input_file) { + FILE *f; + f = fopen(input_file, "r"); + if (f == NULL) { + Eprintf("Can't open input file: %s\n", input_file); + exit(-2); + } + + struct property *fixed_prop; + fixed_prop = malloc(sizeof(struct property)); + fixed_prop->type = P_UNKNOWN; + fixed_prop->lineno = LINENUM_IDENTIFICATOR; + fixed_prop->next = NULL; + char buffer[READBUFFER_SIZE]; + while (fgets(buffer, READBUFFER_SIZE, f) != NULL) { + if (buffer[0] == '\0' || buffer[1] == '\0') + continue; + if (buffer[0] != '#') { + char *wstr = buffer + 7; + char *end = strchr(wstr, '='); + *end = '\0'; + struct symbol *sym = sym_find(wstr); + if (sym->type != S_BOOLEAN && sym->type != S_TRISTATE) + continue; + if (sym->prop == NULL) { + sym->prop = fixed_prop; + continue; + } + struct property *prop; + prop = sym->prop; + while (prop->next != NULL) + prop = prop->next; + prop->next = fixed_prop; + } + } + + fclose(f); +} + +bool inv_fixed(struct symbol *sym) { + if (sym->prop == NULL) + return false; + struct property *prop; + prop = sym->prop; + while (prop->next != NULL) + prop = prop->next; + if (prop->type == P_UNKNOWN && prop->lineno == LINENUM_IDENTIFICATOR) + return true; + else + return false; +} diff --git a/scripts/allconfig/inv.h b/scripts/allconfig/inv.h new file mode 100644 index 0000000..718a688 --- /dev/null +++ b/scripts/allconfig/inv.h @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +#include +#include + +#ifndef _INV_H_ +#define _INV_H_ + +#define READBUFFER_SIZE 127 +#define LINENUM_IDENTIFICATOR -10 + +void inv_prepare(char *input_file); +bool inv_fixed(struct symbol *sym); + +#endif /* _INV_H_ */ -- cgit v1.2.3