Commit 16acfa62 authored by Nils Goroll's avatar Nils Goroll

add common_subkey logic - don't mark individual entries for common subkeys, but rather mark them

in a bitmask for all entries
generate filter and reorder files from test and use them
parent 392e5343
......@@ -34,7 +34,7 @@ main (void) {
for ( ; *p; ++p) *p = tolower(*p);
e = dcs_match(line);
t = dcs_match_type_id(e);
printf("--\n%sentry %d type %d - %s - %s\n", line,
printf("--\n%sentry id %d type %d - %s - %s\n", line,
e, t, dcs_type_mtd(t), dcs_type_name(t));
}
return 0;
......
......@@ -77,23 +77,29 @@ dcs_match(const char *p) {
return state.min_match_entry;
}
#define check_entry_id(entry_id, ret) \
#define check_entry_index(entry_index, ret) \
do { \
if ((entry_id < 0) || (entry_id > (DCS_ENTRY_COUNT - 1))) { \
if ((entry_index < 0) || (entry_index > (DCS_ENTRY_COUNT - 1))) { \
errno = EINVAL; \
return (ret); \
} \
} while(0)
int /* enum dcs_type */
dcs_match_type_id(int entry_id /* dcs_entry_id_t */) {
check_entry_id(entry_id, -1);
return dcs_entry[entry_id].type;
dcs_match_id(int entry_index /* dcs_entry_id_t */) {
check_entry_index(entry_index, -1);
return dcs_entry[entry_index].id;
}
int /* enum dcs_type */
dcs_match_type_id(int entry_index /* dcs_entry_id_t */) {
check_entry_index(entry_index, -1);
return dcs_entry[entry_index].type;
}
const char const *
dcs_match_key(int entry_id /* dcs_entry_id_t */) {
check_entry_id(entry_id, 0);
return dcs_entry[entry_id].key;
dcs_match_key(int entry_index /* dcs_entry_id_t */) {
check_entry_index(entry_index, 0);
return dcs_entry[entry_index].key;
}
......@@ -20,6 +20,7 @@
#ifndef DCS_MATCH_H
#define DCS_MATCH_H 1
int dcs_match(const char *p);
int dcs_match_id(int entry_id /* dcs_entry_id_t */);
int dcs_match_type_id(int entry_id /* dcs_entry_id_t */);
const char const *dcs_match_key(int entry_id /* dcs_entry_id_t */);
#endif
......@@ -30,24 +30,54 @@
int
test (const char *fixup_remove_name, const char *fixup_reorder_name);
static void fixup_out (FILE *f_remove, FILE *f_reorder, const int i, const int r);
int
main (void) {
return test(NULL, NULL);
main (int argc, char *argv[]) {
if (argc > 3) {
fprintf(stderr, "Too many arguments");
return (-1);
}
if (argc == 3)
return test(argv[1], argv[2]);
if (argc == 2)
return test(argv[1], NULL);
if (argc == 1)
return test(NULL, NULL);
}
static void
test_p_diff (const char *label, int i, const char *testkey, int r) {
test_p_diff (const char *label, const int i, const char *testkey, const int r) {
if (dcs_entry[i].type != dcs_entry[r].type) {
printf("%s\ti: %8d %s %s\ntype diff\tr: %8d %s %s\n",
label,
i, testkey, dcs_type[dcs_entry[i].type],
r, dcs_entry[r].key, dcs_type[dcs_entry[r].type]);
dcs_entry[i].id, testkey, dcs_type[dcs_entry[i].type],
dcs_entry[r].id, dcs_entry[r].key, dcs_type[dcs_entry[r].type]);
} else {
printf("%s\ti: %8d %s\n\t\tr: %8d %s\n",
label,
i, testkey,
r, dcs_entry[r].key);
dcs_entry[i].id, testkey,
dcs_entry[r].id, dcs_entry[r].key);
}
}
#ifdef NDEBUG
#define AP(x) x
#else
#define AP(x) assert((x) >= 0)
#endif
static void
fixup_out (FILE *f_remove, FILE *f_reorder, const int i, const int r) {
if (dcs_entry[i].type != dcs_entry[r].type) {
if (f_reorder)
AP(fprintf(f_reorder, " %i %s\n<->%i %s\n",
dcs_entry[i].id, dcs_entry[i].key,
dcs_entry[r].id, dcs_entry[r].key));
} else {
if (f_remove)
AP(fprintf(f_remove, "%i %s\n",
dcs_entry[i].id, dcs_entry[i].key));
}
}
......@@ -55,18 +85,32 @@ int
test (const char *fixup_remove_name, const char *fixup_reorder_name) {
int i, r, errcount = 0;
FILE *f_remove, *f_reorder;
FILE *f_remove = NULL, *f_reorder = NULL;
if (fixup_remove_name && *fixup_remove_name) {
if ((f_remove = fopen(fixup_remove_name, "a")) == NULL) {
perror("remove_file: ");
return -1;
}
}
(void) fixup_remove_name;
(void) fixup_reorder_name;
(void) f_remove;
(void) f_reorder;
if (fixup_reorder_name && *fixup_reorder_name) {
if ((f_reorder = fopen(fixup_reorder_name, "a")) == NULL) {
perror("reorder_file: ");
if (f_remove)
fclose(f_remove);
return -1;
}
}
for (i = 0; i < DCS_ENTRY_COUNT; i++) {
if (dcs_entry[i].active == 0)
continue;
if (dcs_matchstate_init.matchmask[i] == 0) {
r = dcs_match(dcs_entry[i].key);
if (i != r) {
test_p_diff("miss\t", i, dcs_entry[i].key, r);
fixup_out(f_remove, f_reorder, i, r);
errcount++;
}
} else {
......@@ -121,12 +165,14 @@ test (const char *fixup_remove_name, const char *fixup_reorder_name) {
r = dcs_match(poskey);
if (i != r) {
test_p_diff("miss n-p", i, poskey, r);
fixup_out(f_remove, f_reorder, i, r);
errcount++;
}
r = dcs_match(negkey);
if (r == i) {
test_p_diff("miss n-n", i, negkey, r);
fixup_out(f_remove, f_reorder, i, r);
errcount++;
}
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment