aboutsummaryrefslogtreecommitdiff
path: root/scripts/write_config
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2015-05-15 01:38:34 +0200
committerKarel Kočí <cynerd@email.cz>2015-05-15 01:38:34 +0200
commitf9bd4784d55c6e2afe4c102a1212a7661ac0ef80 (patch)
treefa2140a1147e6805f502f41ffcf06a860f807feb /scripts/write_config
parent2e9ef6384bf9a9b599a5f7438d8772fcbccb760f (diff)
downloadlinux-conf-perf-f9bd4784d55c6e2afe4c102a1212a7661ac0ef80.tar.gz
linux-conf-perf-f9bd4784d55c6e2afe4c102a1212a7661ac0ef80.tar.bz2
linux-conf-perf-f9bd4784d55c6e2afe4c102a1212a7661ac0ef80.zip
Rewrite write_config solution check and fix apply
solution.apply failed in case of last solution.
Diffstat (limited to 'scripts/write_config')
-rw-r--r--scripts/write_config/solution.c119
-rw-r--r--scripts/write_config/solution.h10
-rw-r--r--scripts/write_config/write.c26
3 files changed, 105 insertions, 50 deletions
diff --git a/scripts/write_config/solution.c b/scripts/write_config/solution.c
index f575864..c2007a4 100644
--- a/scripts/write_config/solution.c
+++ b/scripts/write_config/solution.c
@@ -1,50 +1,89 @@
#include "solution.h"
extern int exit_status;
-void solution_check(struct symlist *sl, FILE * f) {
+
+struct solution *solution_load(FILE * fmap, FILE * fsolved) {
+ char buffer[BUFFER_SIZE];
+ size_t buff_pos;
+
int c;
- // skip first line
- do
- c = fgetc(f);
- while (c != EOF && c != '\n');
+ buff_pos = 0;
+ size_t buff_pos_old;
+ while (1) {
+ c = fgetc(fsolved);
+ if (c == '\n') {
+ buff_pos_old = buff_pos;
+ buff_pos = 0;
+ } else if (c == EOF) {
+ break;
+ } else {
+ buffer[buff_pos++] = (char) c;
+ }
+ }
+ buffer[buff_pos_old++] = '\0';
+ char *hash;
+ hash = malloc(buff_pos_old * sizeof(char));
+ memcpy(hash, buffer, buff_pos_old * sizeof(char));
- char *w;
- size_t w_size = 1, w_pos = 0;
- w = malloc((w_size + 1) * sizeof(char));
- do {
- c = fgetc(f);
+ while (1) {
+ do {
+ c = fgetc(fmap);
+ buffer[buff_pos++] = (char) c;
+ } while (c != ':');
+ buffer[buff_pos] = '\0';
+ if (!strcmp(buffer, hash))
+ break;
+ do {
+ c = fgetc(fmap);
+ } while (c != '\n');
+ }
+
+ size_t sz = 2;
+ struct solution *sol;
+ sol = malloc(sizeof(struct solution));
+ sol->sol = malloc(sz * sizeof(int));
+ sol->size = 0;
+ while (1) {
+ c = fgetc(fmap);
if (c == ' ' || c == '\n') {
- w[w_pos] = '\0';
- w_pos = 0;
- char *ww = w;
- bool neg = false;
- if (w[0] == '-') {
- neg = true;
- ww = w + 1;
- }
- int id = atoi(ww);
- if ((unsigned) id > sl->maxid)
- break;
- if (id == 0)
- continue;
- if (sl->array[id - 1].sym == NULL)
- continue;
- if (neg ==
- (sym_get_tristate_value(sl->array[id - 1].sym) ==
- no ? true : false))
- {
- } else {
- printf("Problem %s=%d/%d\n", sl->array[id - 1].sym->name,
- !neg,
- sym_get_tristate_value(sl->array[id - 1].sym));
- exit_status++;
+ buffer[buff_pos] = '\0';
+ if (sol->size >= sz) {
+ sz *= 2;
+ sol->sol = realloc(sol->sol, sz * sizeof(int));
}
+ sol->sol[sol->size++] = atoi(buffer);
} else {
- if (w_pos >= w_size) {
- w_size *= 2;
- w = realloc(w, (w_size + 1) * sizeof(char));
- }
- w[w_pos++] = (char) c;
+ buffer[buff_pos++] = (char) c;
+ }
+ if (c == '\n')
+ break;
+ }
+
+ return sol;
+}
+
+void solution_check(struct symlist *sl, struct solution *s) {
+ unsigned i;
+ for (i = 0; i < s->size; s++) {
+ bool neg = false;
+ if (s->sol[i] < 0) {
+ neg = true;
+ s->sol[i] *= -1;
+ }
+ if ((unsigned) s->sol[i] > sl->maxid)
+ break;
+ if (s->sol[i] == 0)
+ continue;
+ if (sl->array[s->sol[i] - 1].sym == NULL)
+ continue;
+ if (neg ==
+ (sym_get_tristate_value(sl->array[s->sol[i] - 1].sym) ==
+ no ? true : false)) {
+ } else {
+ printf("Problem %s=%d/%d\n",
+ sl->array[s->sol[i] - 1].sym->name, !neg,
+ sym_get_tristate_value(sl->array[s->sol[i] - 1].sym));
+ exit_status++;
}
- } while (c != EOF && c != '\n');
+ }
}
diff --git a/scripts/write_config/solution.h b/scripts/write_config/solution.h
index 91db619..100a9fe 100644
--- a/scripts/write_config/solution.h
+++ b/scripts/write_config/solution.h
@@ -8,6 +8,14 @@
#ifndef _SOLUTION_H_
#define _SOLUTION_H_
-void solution_check(struct symlist *sl, FILE * f);
+#define BUFFER_SIZE 32
+
+struct solution {
+ int *sol;
+ size_t size;
+};
+
+struct solution *solution_load(FILE *fmap, FILE *fsolved);
+void solution_check(struct symlist *sl, struct solution *s);
#endif /* _SOLUTION_H_ */
diff --git a/scripts/write_config/write.c b/scripts/write_config/write.c
index 29fcd60..5402286 100644
--- a/scripts/write_config/write.c
+++ b/scripts/write_config/write.c
@@ -39,11 +39,12 @@ int main(int argc, char **argv) {
exit(3);
}
- char *rules_file, *symbol_map_file, *def_config_file, *solution_file;
+ char *rules_file, *symbol_map_file, *def_config_file, *config_map, *config_solved;
asprintf(&rules_file, "%s/%s", folder, DEFAULT_RULES_FILE);
asprintf(&symbol_map_file, "%s/%s", folder, DEFAULT_SYMBOL_MAP_FILE);
asprintf(&def_config_file, "%s/%s", folder, DEFAULT_DEF_CONFIG_FILE);
- asprintf(&solution_file, "%s/%s", folder, DEFAULT_SOLUTION_FILE);
+ asprintf(&config_map, "%s/%s", folder, DEFAULT_CONFIG_MAP_FILE);
+ asprintf(&config_solved, "%s/%s", folder, DEFAULT_CONFIG_SOLVED_FILE);
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@@ -57,18 +58,25 @@ int main(int argc, char **argv) {
FILE *f = fopen(symbol_map_file, "r");
if (f == NULL) {
Eprintf("Can't open file: %s\n", symbol_map_file);
- exit(1);
+ exit(-1);
}
struct symlist *sl = symlist_read(f);
fclose(f);
- f = fopen(solution_file, "r");
- if (f == NULL) {
- Eprintf("Can't open file: %s\n", solution_file);
- exit(2);
+ FILE *fconfig_map = fopen(config_map, "r");
+ if (fconfig_map == NULL) {
+ Eprintf("Can't open file: %s\n", config_map);
+ exit(-2);
}
- solution_check(sl, f);
- fclose(f);
+ FILE *fconfig_solved = fopen(config_solved, "r");
+ if (fconfig_map == NULL) {
+ Eprintf("Can't open file: %s\n", config_solved);
+ exit(-3);
+ }
+ //struct solution *sol = solution_load(fconfig_map, fconfig_solved);
+ //solution_check(sl, sol);
+ fclose(fconfig_map);
+ fclose(fconfig_solved);
conf_write(".config");