X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=common%2Ftst-trie.c;h=2b7bdee64e7bb7e8cac5f9bbb80573249341337b;hb=dc75ac4e4a24e8f400f95ab6ff4e7c903d8bfb6c;hp=df9e1d27bc23de2d33c4493f014adbcb7a640959;hpb=c7ca68d5bda0b49e7b7bc6a997a4140e6197bf11;p=apps%2Fpfixtools.git diff --git a/common/tst-trie.c b/common/tst-trie.c index df9e1d2..2b7bdee 100644 --- a/common/tst-trie.c +++ b/common/tst-trie.c @@ -86,6 +86,51 @@ static trie_t *create_trie_from_file(const char *file) return db; } +__attribute__((used)) +static void check_trie_with_file(const trie_t *db, const char *file) +{ + file_map_t map; + const char *p, *end; + char line[BUFSIZ]; + + if (!file_map_open(&map, file, false)) { + return; + } + p = map.map; + end = map.end; + while (end > p && end[-1] != '\n') { + --end; + } + if (end != map.end) { + warn("file %s miss a final \\n, ignoring last line", file); + } + + while (p < end && p != NULL) { + const char *eol = (char *)memchr(p, '\n', end - p); + if (eol == NULL) { + eol = end; + } + if (eol - p > BUFSIZ) { + p = eol - BUFSIZ; + } + int i = 0; +#if 1 + for (const char *s = eol - 1 ; s >= p ; --s) { + line[i++] = ascii_tolower(*s); + } +#else + memcpy(line, p, eol - p); + i = eol - p; +#endif + line[i] = '\0'; + if (!trie_lookup(db, line)) { + warn("'%s' not found in the trie", line); + } + p = eol + 1; + } + file_map_close(&map); +} + int main(int argc, char *argv[]) { @@ -131,6 +176,7 @@ int main(int argc, char *argv[]) if (argc > 1) { trie = create_trie_from_file(argv[1]); trie_inspect(trie, false); + check_trie_with_file(trie, argv[1]); if (argc > 2) { const uint32_t how_many = 8 * 1000 * 1000; struct timeval start, end;