From 604a88ab070fbd22e9a27e380e8fcd124c44f89d Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Tue, 21 Dec 2021 14:25:12 +0900 Subject: [PATCH] Imported Upstream version 0.2.12 --- ChangeLog | 138 ++++++++++++++++++++++++++++++++++++++++++++ NEWS | 9 +++ README | 4 +- VERSION | 2 +- configure | 22 +++---- configure.ac | 2 +- datrie/alpha-map.c | 2 +- datrie/alpha-map.h | 2 +- datrie/darray.c | 6 +- datrie/darray.h | 2 +- datrie/tail.c | 29 +++++++++- datrie/tail.h | 2 +- datrie/typedefs.h | 12 ++-- tests/test_byte_alpha.c | 3 +- tests/test_file.c | 12 ++-- tests/test_iterator.c | 13 +++-- tests/test_nonalpha.c | 9 +-- tests/test_null_trie.c | 5 +- tests/test_store-retrieve.c | 25 ++++---- tests/test_term_state.c | 2 +- tests/test_walk.c | 7 ++- tests/utils.c | 6 +- tests/utils.h | 4 +- tools/trietool.c | 57 +++++++++++++----- 24 files changed, 292 insertions(+), 83 deletions(-) diff --git a/ChangeLog b/ChangeLog index 627d909..2d87b42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,141 @@ +2018-06-19 Theppitak Karoonboonyanan + + * configure.ac: + - Bump library revision to reflect code changes. + + * NEWS: + === Version 0.2.12 === + +2018-06-19 Theppitak Karoonboonyanan + + Use HTTPS in URL + + * README: + - Update document URL to HTTPS + +2018-06-14 Theppitak Karoonboonyanan + + Cast (wchar_t *) to fix warnings in tests + + "%ls" printf() format requires (wchar_t *) [aka int *] arg. + So, let's cast (AlphaChar *) [aka unsigned int *] to satisfy it. + + * tests/test_walk.c: + * tests/test_iterator.c: + * tests/test_store-retrieve.c: + * tests/test_file.c: + * tests/test_nonalpha.c: + * tests/test_null_trie.c: + - Add include, for wchar_t type + - Cast "%ls" args from (AlphaChar *) to (wchar_t *) + +2018-06-06 Theppitak Karoonboonyanan + + Avoid non-ANSI C snprintf() + + * tools/trietool.c (+full_path, prepare_trie, close_trie): + - Instead of preparing full path name with snprintf(), which is + non-ANSI, and still risks path name trimming, do it with + size-calculated malloc(). + - free() it as needed. + +2018-06-04 Theppitak Karoonboonyanan + + Fix sscanf() string format + + * tools/trietool.c (prepare_trie): + - Define b, e as unsigned int, as required by "%x" format. + Fixing warning from '-Wformat=' gcc option. + +2018-06-04 Theppitak Karoonboonyanan + + Fix compiler warnings in tests + + * tests/test_byte_alpha.c (main): + * tests/test_file.c (main): + * tests/test_iterator.c (main): + * tests/test_nonalpha.c (main): + * tests/test_null_trie.c (main): + * tests/test_store-retrieve.c (main): + * tests/test_term_state.c (main): + * tests/test_walk.c (main): + - Declare main function with 'main (void)'. + Fixing warning from '-Wstrict-prototypes' gcc option. + * tests/test_walk.c (main): + - Split long string, which required C90 compilers. + Fixing warning from '-Woverlength-strings' gcc option. + +2018-06-04 Theppitak Karoonboonyanan + + Duplicate TrieChar string in more portable manner + + * datrie/tail.c (tail_set_suffix, +tc_strdup, +tc_strlen): + - Replace cast strdup() with crafted implementation, + allowing TrieChar to be of larger size than char. + Fixing warning from '-Wint-to-pointer-cast' gcc option. + +2018-06-04 Theppitak Karoonboonyanan + + Split long string + + * tools/trietool.c (usage): + - Split help message which was too long and required C90 compiler. + Caught by '-Woverlength-strings' gcc option. + +2018-06-04 Theppitak Karoonboonyanan + + Remove unused byte, word, dword typedefs + + These are likely to conflict with other uses. + + * datrie/typedefs.h (-byte, -word, -dword): + - Remove the unused typedefs + + Thanks Peter Moulder for the patch. + +2018-06-04 Theppitak Karoonboonyanan + + Rename TRUE/FALSE in Bool enum to avoid clash + + Some other header file may have already define TRUE/FALSE. + + * datrie/typedefs.h (Bool): + - Rename FALSE, TRUE to DA_FALSE, DA_TRUE respectively, + and define FALSE, TRUE macros only if they haven't been defined. + + Thanks Peter Moulder for the patch. + +2018-06-04 Theppitak Karoonboonyanan + + Declare argument-less functions with "(void)" + + "f()" declaration form is K&R style, specifying that no information + about the number or types of parameters is supplied. This caused + warnings on '-Wstrict-prototypes' gcc option. + + * datrie/alpha-map.h, datrie/alpha-map.c (alpha_map_new): + * datrie/darray.h, datrie/darray.c (da_new, symbols_new): + * datrie/tail.h, datrie/tail.c (tail_new): + * tests/utils.h, tests/utils.c (en_alpha_map_new, en_trie_new): + - Use "(void)" form in declaration + - Also use "(void)" form in definition, for consistency + + Thanks Peter Moulder for the initial patch. + +2018-05-24 Theppitak Karoonboonyanan + + Remove duplicate include + + * tools/trietool.c: + - Remove duplicate include + +2018-04-23 Theppitak Karoonboonyanan + + Add missing include in test + + * tests/test_byte_alpha.c: + - Add missing include for utils.h + 2018-04-23 Theppitak Karoonboonyanan * configure.ac: diff --git a/NEWS b/NEWS index 165ffa0..9d011a9 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,14 @@ libdatrie +0.2.12 (2018-06-19) +====== +- More C90 (ANSI C) compliance. + (Thanks Peter Moulder for the patch) +- Prevent some compiling conflicts with other sources. + (Thanks Peter Moulder for the patch) +- Fix miscellaneous compiler warnings. +- Prevent trimming on extremely long dictionary path names. + 0.2.11 (2018-04-23) ====== - Detect iconv() error more correctly in trietool. diff --git a/README b/README index f28f17b..3ed389b 100644 --- a/README +++ b/README @@ -12,7 +12,7 @@ manipulation. This makes it ideal for lexical analyzers, as well as spelling dictionaries. See the details of the implementation at [2]: - http://linux.thai.net/~thep/datrie/datrie.html + https://linux.thai.net/~thep/datrie/datrie.html Historically, this was first implemented as C++ classes in a library called midatrie [2], but later simplified and rewritten from scratch in C. @@ -29,5 +29,5 @@ References (Sep 1989). pp. 1066-1077. [2] Karoonboonyanan, T. "An Implementation of Double-Array Trie". - http://linux.thai.net/~thep/datrie/datrie.html + https://linux.thai.net/~thep/datrie/datrie.html diff --git a/VERSION b/VERSION index d3b5ba4..f2722b1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.11 +0.2.12 diff --git a/configure b/configure index 82a968b..3e13f49 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for libdatrie 0.2.11. +# Generated by GNU Autoconf 2.69 for libdatrie 0.2.12. # # Report bugs to . # @@ -590,8 +590,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='libdatrie' PACKAGE_TARNAME='libdatrie' -PACKAGE_VERSION='0.2.11' -PACKAGE_STRING='libdatrie 0.2.11' +PACKAGE_VERSION='0.2.12' +PACKAGE_STRING='libdatrie 0.2.12' PACKAGE_BUGREPORT='theppitak@gmail.com' PACKAGE_URL='' @@ -1337,7 +1337,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures libdatrie 0.2.11 to adapt to many kinds of systems. +\`configure' configures libdatrie 0.2.12 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1408,7 +1408,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of libdatrie 0.2.11:";; + short | recursive ) echo "Configuration of libdatrie 0.2.12:";; esac cat <<\_ACEOF @@ -1521,7 +1521,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -libdatrie configure 0.2.11 +libdatrie configure 0.2.12 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1944,7 +1944,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by libdatrie $as_me 0.2.11, which was +It was created by libdatrie $as_me 0.2.12, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2812,7 +2812,7 @@ fi # Define the identity of the package. PACKAGE='libdatrie' - VERSION='0.2.11' + VERSION='0.2.12' cat >>confdefs.h <<_ACEOF @@ -2911,7 +2911,7 @@ fi # Interfaces added: CURRENT++ REVISION=0 AGE++ # Interfaces changed/removed: CURRENT++ REVISION=0 AGE=0 LT_CURRENT=4 -LT_REVISION=4 +LT_REVISION=5 LT_AGE=3 @@ -13561,7 +13561,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by libdatrie $as_me 0.2.11, which was +This file was extended by libdatrie $as_me 0.2.12, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -13627,7 +13627,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -libdatrie config.status 0.2.11 +libdatrie config.status 0.2.12 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 41249b9..e477b2f 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AM_INIT_AUTOMAKE(dist-xz no-dist-gzip) # Interfaces added: CURRENT++ REVISION=0 AGE++ # Interfaces changed/removed: CURRENT++ REVISION=0 AGE=0 LT_CURRENT=4 -LT_REVISION=4 +LT_REVISION=5 LT_AGE=3 AC_SUBST(LT_CURRENT) AC_SUBST(LT_REVISION) diff --git a/datrie/alpha-map.c b/datrie/alpha-map.c index c869027..9bd313d 100644 --- a/datrie/alpha-map.c +++ b/datrie/alpha-map.c @@ -137,7 +137,7 @@ static int alpha_map_recalc_work_area (AlphaMap *alpha_map); * The created object must be freed with alpha_map_free(). */ AlphaMap * -alpha_map_new () +alpha_map_new (void) { AlphaMap *alpha_map; diff --git a/datrie/alpha-map.h b/datrie/alpha-map.h index f47a5a1..2066737 100644 --- a/datrie/alpha-map.h +++ b/datrie/alpha-map.h @@ -65,7 +65,7 @@ extern "C" { */ typedef struct _AlphaMap AlphaMap; -AlphaMap * alpha_map_new (); +AlphaMap * alpha_map_new (void); AlphaMap * alpha_map_clone (const AlphaMap *a_map); diff --git a/datrie/darray.c b/datrie/darray.c index 910cf18..d1a04b0 100644 --- a/datrie/darray.c +++ b/datrie/darray.c @@ -44,7 +44,7 @@ struct _Symbols { TrieChar symbols[TRIE_CHAR_MAX + 1]; }; -static Symbols * symbols_new (); +static Symbols * symbols_new (void); static void symbols_add (Symbols *syms, TrieChar c); #define symbols_add_fast(s,c) ((s)->symbols[(s)->num_symbols++] = c) @@ -87,7 +87,7 @@ static void da_free_cell (DArray *d, *------------------------------------*/ static Symbols * -symbols_new () +symbols_new (void) { Symbols *syms; @@ -180,7 +180,7 @@ struct _DArray { * Create a new empty doubla-array object. */ DArray * -da_new () +da_new (void) { DArray *d; diff --git a/datrie/darray.h b/datrie/darray.h index 7cbf588..8907683 100644 --- a/datrie/darray.h +++ b/datrie/darray.h @@ -50,7 +50,7 @@ TrieChar symbols_get (const Symbols *syms, int index); typedef struct _DArray DArray; -DArray * da_new (); +DArray * da_new (void); DArray * da_fread (FILE *file); diff --git a/datrie/tail.c b/datrie/tail.c index 49b0fd6..25d78b4 100644 --- a/datrie/tail.c +++ b/datrie/tail.c @@ -93,7 +93,7 @@ struct _Tail { * Create a new empty tail object. */ Tail * -tail_new () +tail_new (void) { Tail *t; @@ -270,6 +270,31 @@ tail_get_suffix (const Tail *t, TrieIndex index) return LIKELY (index < t->num_tails) ? t->tails[index].suffix : NULL; } +static size_t +tc_strlen (const TrieChar *str) +{ + size_t len = 0; + while (*str++) { + ++len; + } + return len; +} + +static TrieChar * +tc_strdup (const TrieChar *str) +{ + TrieChar *dup + = (TrieChar *) malloc (sizeof (TrieChar) * (tc_strlen (str) + 1)); + TrieChar *p = dup; + + while (*str) { + *p++ = *str++; + } + *p = (TrieChar) 0; + + return dup; +} + /** * @brief Set suffix of existing entry * @@ -289,7 +314,7 @@ tail_set_suffix (Tail *t, TrieIndex index, const TrieChar *suffix) */ TrieChar *tmp = NULL; if (suffix) { - tmp = (TrieChar *) strdup ((const char *)suffix); + tmp = tc_strdup (suffix); if (UNLIKELY (!tmp)) return FALSE; } diff --git a/datrie/tail.h b/datrie/tail.h index 6e8a800..accab94 100644 --- a/datrie/tail.h +++ b/datrie/tail.h @@ -39,7 +39,7 @@ */ typedef struct _Tail Tail; -Tail * tail_new (); +Tail * tail_new (void); Tail * tail_fread (FILE *file); diff --git a/datrie/typedefs.h b/datrie/typedefs.h index d385b61..ed12d67 100644 --- a/datrie/typedefs.h +++ b/datrie/typedefs.h @@ -29,7 +29,13 @@ #include -typedef enum { FALSE = 0, TRUE = 1 } Bool; +typedef enum { DA_FALSE = 0, DA_TRUE = 1 } Bool; +#ifndef FALSE +# define FALSE DA_FALSE +#endif +#ifndef TRUE +# define TRUE DA_TRUE +#endif # if UCHAR_MAX == 0xff # ifndef UINT8_TYPEDEF @@ -120,10 +126,6 @@ typedef enum { FALSE = 0, TRUE = 1 } Bool; # error "int32 type is undefined!" # endif -typedef uint8 byte; -typedef uint16 word; -typedef uint32 dword; - #endif /* __TYPEDEFS_H */ diff --git a/tests/test_byte_alpha.c b/tests/test_byte_alpha.c index 2389ef7..69a22bd 100644 --- a/tests/test_byte_alpha.c +++ b/tests/test_byte_alpha.c @@ -27,12 +27,13 @@ */ #include +#include "utils.h" #include #include #define TEST_DATA 255 int -main () +main (void) { AlphaMap *alpha_map; Trie *test_trie; diff --git a/tests/test_file.c b/tests/test_file.c index 06fea6b..9c53b2a 100644 --- a/tests/test_file.c +++ b/tests/test_file.c @@ -27,6 +27,7 @@ #include #include "utils.h" #include +#include #include #define TRIE_FILENAME "test.tri" @@ -39,11 +40,12 @@ trie_enum_mark_rec (const AlphaChar *key, TrieData key_data, void *user_data) src_data = dict_src_get_data (key); if (TRIE_DATA_ERROR == src_data) { - printf ("Extra entry in file: key '%ls', data %d.\n", key, key_data); + printf ("Extra entry in file: key '%ls', data %d.\n", + (wchar_t *)key, key_data); *is_failed = TRUE; } else if (src_data != key_data) { printf ("Data mismatch for: key '%ls', expected %d, got %d.\n", - key, src_data, key_data); + (wchar_t *)key, src_data, key_data); *is_failed = TRUE; } else { dict_src_set_data (key, TRIE_DATA_READ); @@ -53,7 +55,7 @@ trie_enum_mark_rec (const AlphaChar *key, TrieData key_data, void *user_data) } int -main () +main (void) { Trie *test_trie; DictRec *dict_p; @@ -70,7 +72,7 @@ main () for (dict_p = dict_src; dict_p->key; dict_p++) { if (!trie_store (test_trie, dict_p->key, dict_p->data)) { printf ("Failed to add key '%ls', data %d.\n", - dict_p->key, dict_p->data); + (wchar_t *)dict_p->key, dict_p->data); goto err_trie_created; } } @@ -105,7 +107,7 @@ main () for (dict_p = dict_src; dict_p->key; dict_p++) { if (dict_p->data != TRIE_DATA_READ) { printf ("Entry missed in file: key '%ls', data %d.\n", - dict_p->key, dict_p->data); + (wchar_t *)dict_p->key, dict_p->data); is_failed = TRUE; } } diff --git a/tests/test_iterator.c b/tests/test_iterator.c index 559fa23..a0bea7c 100644 --- a/tests/test_iterator.c +++ b/tests/test_iterator.c @@ -28,9 +28,10 @@ #include "utils.h" #include #include +#include int -main () +main (void) { Trie *test_trie; DictRec *dict_p; @@ -50,7 +51,7 @@ main () for (dict_p = dict_src; dict_p->key; dict_p++) { if (!trie_store (test_trie, dict_p->key, dict_p->data)) { printf ("Failed to add key '%ls', data %d.\n", - dict_p->key, dict_p->data); + (wchar_t *)dict_p->key, dict_p->data); goto err_trie_created; } } @@ -82,18 +83,18 @@ main () key_data = trie_iterator_get_data (trie_it); if (TRIE_DATA_ERROR == key_data) { printf ("Failed to get data from trie iterator for key '%ls'\n", - key); + (wchar_t *)key); is_failed = TRUE; } /* mark entries found in trie */ src_data = dict_src_get_data (key); if (TRIE_DATA_ERROR == src_data) { printf ("Extra entry in trie: key '%ls', data %d.\n", - key, key_data); + (wchar_t *)key, key_data); is_failed = TRUE; } else if (src_data != key_data) { printf ("Data mismatch for: key '%ls', expected %d, got %d.\n", - key, src_data, key_data); + (wchar_t *)key, src_data, key_data); is_failed = TRUE; } else { dict_src_set_data (key, TRIE_DATA_READ); @@ -106,7 +107,7 @@ main () for (dict_p = dict_src; dict_p->key; dict_p++) { if (dict_p->data != TRIE_DATA_READ) { printf ("Entry missed in trie: key '%ls', data %d.\n", - dict_p->key, dict_p->data); + (wchar_t *)dict_p->key, dict_p->data); is_failed = TRUE; } } diff --git a/tests/test_nonalpha.c b/tests/test_nonalpha.c index 9a0c922..6b02223 100644 --- a/tests/test_nonalpha.c +++ b/tests/test_nonalpha.c @@ -27,6 +27,7 @@ #include #include "utils.h" #include +#include const AlphaChar *nonalpha_src[] = { (AlphaChar *)L"a6acus", @@ -35,7 +36,7 @@ const AlphaChar *nonalpha_src[] = { }; int -main () +main (void) { Trie *test_trie; DictRec *dict_p; @@ -55,7 +56,7 @@ main () for (dict_p = dict_src; dict_p->key; dict_p++) { if (!trie_store (test_trie, dict_p->key, dict_p->data)) { printf ("Failed to add key '%ls', data %d.\n", - dict_p->key, dict_p->data); + (wchar_t *)dict_p->key, dict_p->data); goto err_trie_created; } } @@ -65,12 +66,12 @@ main () for (nonalpha_key = nonalpha_src; *nonalpha_key; nonalpha_key++) { if (trie_retrieve (test_trie, *nonalpha_key, &trie_data)) { printf ("False duplication on key '%ls', with existing data %d.\n", - *nonalpha_key, trie_data); + (wchar_t *)*nonalpha_key, trie_data); is_fail = TRUE; } if (trie_store (test_trie, *nonalpha_key, TRIE_DATA_UNREAD)) { printf ("Wrongly added key '%ls' containing non-alphanet char\n", - *nonalpha_key); + (wchar_t *)*nonalpha_key); is_fail = TRUE; } } diff --git a/tests/test_null_trie.c b/tests/test_null_trie.c index ae21ffc..00d133a 100644 --- a/tests/test_null_trie.c +++ b/tests/test_null_trie.c @@ -27,10 +27,11 @@ #include #include "utils.h" #include +#include #include int -main () +main (void) { Trie *test_trie; TrieState *trie_root_state; @@ -66,7 +67,7 @@ main () key = trie_iterator_get_key (trie_it); if (key) { printf ("Got key from empty trie, which is weird! (key='%ls')\n", - key); + (wchar_t *)key); is_failed = TRUE; free (key); } diff --git a/tests/test_store-retrieve.c b/tests/test_store-retrieve.c index fed7213..a6f76bd 100644 --- a/tests/test_store-retrieve.c +++ b/tests/test_store-retrieve.c @@ -27,11 +27,12 @@ #include #include "utils.h" #include +#include #include #include int -main () +main (void) { Trie *test_trie; DictRec *dict_p; @@ -53,7 +54,7 @@ main () for (dict_p = dict_src; dict_p->key; dict_p++) { if (!trie_store (test_trie, dict_p->key, dict_p->data)) { printf ("Failed to add key '%ls', data %d.\n", - dict_p->key, dict_p->data); + (wchar_t *)dict_p->key, dict_p->data); goto err_trie_created; } } @@ -63,12 +64,12 @@ main () is_failed = FALSE; for (dict_p = dict_src; dict_p->key; dict_p++) { if (!trie_retrieve (test_trie, dict_p->key, &trie_data)) { - printf ("Failed to retrieve key '%ls'.\n", dict_p->key); + printf ("Failed to retrieve key '%ls'.\n", (wchar_t *)dict_p->key); is_failed = TRUE; } if (trie_data != dict_p->data) { printf ("Wrong data for key '%ls'; expected %d, got %d.\n", - dict_p->key, dict_p->data, trie_data); + (wchar_t *)dict_p->key, dict_p->data, trie_data); is_failed = TRUE; } } @@ -87,9 +88,9 @@ main () i = rand () % n_entries; } while (TRIE_DATA_READ == dict_src[i].data); - printf ("Deleting '%ls'\n", dict_src[i].key); + printf ("Deleting '%ls'\n", (wchar_t *)dict_src[i].key); if (!trie_delete (test_trie, dict_src[i].key)) { - printf ("Failed to delete '%ls'\n", dict_src[i].key); + printf ("Failed to delete '%ls'\n", (wchar_t *)dict_src[i].key); is_failed = TRUE; } dict_src[i].data = TRIE_DATA_READ; @@ -107,12 +108,12 @@ main () continue; if (!trie_retrieve (test_trie, dict_p->key, &trie_data)) { - printf ("Failed to retrieve key '%ls'.\n", dict_p->key); + printf ("Failed to retrieve key '%ls'.\n", (wchar_t *)dict_p->key); is_failed = TRUE; } if (trie_data != dict_p->data) { printf ("Wrong data for key '%ls'; expected %d, got %d.\n", - dict_p->key, dict_p->data, trie_data); + (wchar_t *)dict_p->key, dict_p->data, trie_data); is_failed = TRUE; } } @@ -147,18 +148,18 @@ main () key_data = trie_iterator_get_data (trie_it); if (TRIE_DATA_ERROR == key_data) { printf ("Failed to get data from trie iterator for key '%ls'\n", - key); + (wchar_t *)key); is_failed = TRUE; } /* mark entries found in trie */ src_data = dict_src_get_data (key); if (TRIE_DATA_ERROR == src_data) { printf ("Extra entry in trie: key '%ls', data %d.\n", - key, key_data); + (wchar_t *)key, key_data); is_failed = TRUE; } else if (src_data != key_data) { printf ("Data mismatch for: key '%ls', expected %d, got %d.\n", - key, src_data, key_data); + (wchar_t *)key, src_data, key_data); is_failed = TRUE; } else { dict_src_set_data (key, TRIE_DATA_READ); @@ -171,7 +172,7 @@ main () for (dict_p = dict_src; dict_p->key; dict_p++) { if (dict_p->data != TRIE_DATA_READ) { printf ("Entry missed in trie: key '%ls', data %d.\n", - dict_p->key, dict_p->data); + (wchar_t *)dict_p->key, dict_p->data); is_failed = TRUE; } } diff --git a/tests/test_term_state.c b/tests/test_term_state.c index 918d6c5..a08ea93 100644 --- a/tests/test_term_state.c +++ b/tests/test_term_state.c @@ -38,7 +38,7 @@ * */ int -main () +main (void) { Trie *test_trie; TrieState *trie_state; diff --git a/tests/test_walk.c b/tests/test_walk.c index dbac9fc..6c7ae30 100644 --- a/tests/test_walk.c +++ b/tests/test_walk.c @@ -27,6 +27,7 @@ #include #include "utils.h" #include +#include /* * Sample trie in http://linux.thai.net/~thep/datrie/datrie.html @@ -82,7 +83,7 @@ print_walkables (const AlphaChar *walkables, int n_elm) #define ALPHABET_SIZE 256 int -main () +main (void) { Trie *test_trie; DictRec *dict_p; @@ -103,7 +104,7 @@ main () for (dict_p = walk_dict; dict_p->key; dict_p++) { if (!trie_store (test_trie, dict_p->key, dict_p->data)) { printf ("Failed to add key '%ls', data %d.\n", - dict_p->key, dict_p->data); + (wchar_t *)dict_p->key, dict_p->data); goto err_trie_created; } } @@ -111,6 +112,8 @@ main () printf ( "Now the trie structure is supposed to be:\n" "\n" + ); + printf ( " +---o-> (3) -o-> (4) -l-> [5]\n" " |\n" " | +---i-> (7) -z-> (8) -e-> [9]\n" diff --git a/tests/utils.c b/tests/utils.c index b7fbfe9..b29801a 100644 --- a/tests/utils.c +++ b/tests/utils.c @@ -40,7 +40,7 @@ msg_step (const char *msg) * Trie creation helpers * *-------------------------*/ static AlphaMap * -en_alpha_map_new () +en_alpha_map_new (void) { AlphaMap *en_map; @@ -60,7 +60,7 @@ err_map_not_created: } Trie * -en_trie_new () +en_trie_new (void) { AlphaMap *en_map; Trie *en_trie; @@ -129,7 +129,7 @@ DictRec dict_src[] = { }; int -dict_src_n_entries () +dict_src_n_entries (void) { return sizeof (dict_src) / sizeof (dict_src[0]) - 1; } diff --git a/tests/utils.h b/tests/utils.h index e426c78..2a54f78 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -34,7 +34,7 @@ void msg_step (const char *msg); /*-------------------------* * Trie creation helpers * *-------------------------*/ -Trie * en_trie_new (); +Trie * en_trie_new (void); /*---------------------------* * Dict source for testing * @@ -50,7 +50,7 @@ struct _DictRec { extern DictRec dict_src[]; -int dict_src_n_entries (); +int dict_src_n_entries (void); TrieData dict_src_get_data (const AlphaChar *key); int dict_src_set_data (const AlphaChar *key, TrieData data); diff --git a/tools/trietool.c b/tools/trietool.c index 0782e75..11d9812 100644 --- a/tools/trietool.c +++ b/tools/trietool.c @@ -21,7 +21,6 @@ #include -#include #include /* iconv encoding name for AlphaChar string */ @@ -181,31 +180,42 @@ close_conv (ProgEnv *env) iconv_close (env->from_alpha_conv); } +static char * +full_path (const char *path, const char *name, const char *ext) +{ + int full_size = strlen (path) + strlen (name) + strlen (ext) + 2; + char *full_path_buff = (char *) malloc (full_size); + sprintf (full_path_buff, "%s/%s%s", path, name, ext); + return full_path_buff; +} + static int prepare_trie (ProgEnv *env) { char buff[256]; + char *path_name; - snprintf (buff, sizeof (buff), - "%s/%s.tri", env->path, env->trie_name); - env->trie = trie_new_from_file (buff); + path_name = full_path (env->path, env->trie_name, ".tri"); + env->trie = trie_new_from_file (path_name); + free (path_name); if (!env->trie) { FILE *sbm; AlphaMap *alpha_map; - snprintf (buff, sizeof (buff), - "%s/%s.abm", env->path, env->trie_name); - sbm = fopen (buff, "r"); + path_name = full_path (env->path, env->trie_name, ".abm"); + sbm = fopen (path_name, "r"); if (!sbm) { - fprintf (stderr, "Cannot open alphabet map file %s\n", buff); + fprintf (stderr, "Cannot open alphabet map file %s\n", path_name); + free (path_name); return -1; } + free (path_name); alpha_map = alpha_map_new (); while (fgets (buff, sizeof (buff), sbm)) { - int b, e; + unsigned int b, e; /* read the range * format: [b,e] @@ -234,14 +244,13 @@ static int close_trie (ProgEnv *env) { if (trie_is_dirty (env->trie)) { - char path[256]; - - snprintf (path, sizeof (path), - "%s/%s.tri", env->path, env->trie_name); + char *path = full_path (env->path, env->trie_name, ".tri"); if (trie_save (env->trie, path) != 0) { fprintf (stderr, "Cannot save trie to %s\n", path); + free (path); return -1; } + free (path); } trie_free (env->trie); @@ -555,27 +564,43 @@ usage (const char *prog_name, int exit_status) { printf ("%s - double-array trie manipulator\n", prog_name); printf ("Usage: %s [OPTION]... TRIE CMD ARG ...\n", prog_name); + printf ("Options:\n"); printf ( - "Options:\n" " -p, --path DIR set trie directory to DIR [default=.]\n" + ); + printf ( " -h, --help display this help and exit\n" + ); + printf ( " -V, --version output version information and exit\n" - "\n" - "Commands:\n" + ); + printf ("\n"); + printf ("Commands:\n"); + printf ( " add WORD DATA ...\n" " Add WORD with DATA to trie\n" + ); + printf ( " add-list [OPTION] LISTFILE\n" " Add words and data listed in LISTFILE to trie\n" " Options:\n" " -e, --encoding ENC specify character encoding of LISTFILE\n" + ); + printf ( " delete WORD ...\n" " Delete WORD from trie\n" + ); + printf ( " delete-list [OPTION] LISTFILE\n" " Delete words listed in LISTFILE from trie\n" " Options:\n" " -e, --encoding ENC specify character encoding of LISTFILE\n" + ); + printf ( " query WORD\n" " Query WORD data from trie\n" + ); + printf ( " list\n" " List all words in trie\n" ); -- 2.7.4