diff --git a/book.c b/book.c index cb6e205..8189e6f 100644 --- a/book.c +++ b/book.c @@ -78,7 +78,7 @@ static void encode_book(Book* book, json_t* book_json) { * Exported functions */ -char* book_read(EB_Book* book, EB_Hookset* hookset, const EB_Position* position, Book_Mode mode, Gaiji_Context* context) { +char* book_read(EB_Book* book, EB_Hookset* hookset, const EB_Position* position, Book_Mode mode, Gaiji_Table* table) { if (eb_seek_text(book, position) != EB_SUCCESS) { return NULL; } @@ -93,7 +93,7 @@ char* book_read(EB_Book* book, EB_Hookset* hookset, const EB_Position* position, book, NULL, hookset, - context, + table, ARRSIZE(data) - 1, data, &data_length @@ -104,7 +104,7 @@ char* book_read(EB_Book* book, EB_Hookset* hookset, const EB_Position* position, book, NULL, hookset, - context, + table, ARRSIZE(data) - 1, data, &data_length diff --git a/book.h b/book.h index a07cd56..7665695 100644 --- a/book.h +++ b/book.h @@ -61,7 +61,7 @@ typedef enum { * Functions */ -char* book_read(EB_Book* book, EB_Hookset* hookset, const EB_Position* position, Book_Mode mode, Gaiji_Context* context); +char* book_read(EB_Book* book, EB_Hookset* hookset, const EB_Position* position, Book_Mode mode, Gaiji_Table* table); void book_free(Book* book); void book_dump(Book* book, bool pretty_print, FILE* fp); diff --git a/gaiji.c b/gaiji.c index 03a4c54..93b788e 100644 --- a/gaiji.c +++ b/gaiji.c @@ -27,7 +27,7 @@ * Macros */ -#define GAIJI_CONTEXT(name, ents) {\ +#define GAIJI_TABLE(name, ents) {\ name,\ gaiji_table_##ents##_wide,\ ARRSIZE(gaiji_table_##ents##_wide),\ @@ -49,15 +49,15 @@ #include "tables/gaiji_table_snmkg99.h" #include "tables/gaiji_table_wadai5.h" -static const Gaiji_Context gaiji_contexts[] = { - GAIJI_CONTEXT("ジーニアス英和辞典", genius), - GAIJI_CONTEXT("スーパー大辞林", daijirin), - GAIJI_CONTEXT("大辞泉", daijisen), - GAIJI_CONTEXT("広辞苑第六版", kojien), - GAIJI_CONTEXT("新和英大辞典", wadai5), - GAIJI_CONTEXT("新明解国語辞典 ", snmkg99), - GAIJI_CONTEXT("新英和・和英中辞典", chujiten), - GAIJI_CONTEXT("明鏡国語辞典", meikyojj), +static const Gaiji_Table gaiji_tables[] = { + GAIJI_TABLE("ジーニアス英和辞典", genius), + GAIJI_TABLE("スーパー大辞林", daijirin), + GAIJI_TABLE("大辞泉", daijisen), + GAIJI_TABLE("広辞苑第六版", kojien), + GAIJI_TABLE("新和英大辞典", wadai5), + GAIJI_TABLE("新明解国語辞典 ", snmkg99), + GAIJI_TABLE("新英和・和英中辞典", chujiten), + GAIJI_TABLE("明鏡国語辞典", meikyojj), }; /* @@ -120,20 +120,20 @@ static void encode_sequence(char output[], int size, const char utf8[]) { * Exported functions */ -const Gaiji_Context* gaiji_context_select(const char name[]) { - for (unsigned i = 0; i < ARRSIZE(gaiji_contexts); ++i) { - const Gaiji_Context* context = gaiji_contexts + i; - if (strcmp(context->name, name) == 0) { - return context; +const Gaiji_Table* gaiji_table_select(const char name[]) { + for (unsigned i = 0; i < ARRSIZE(gaiji_tables); ++i) { + const Gaiji_Table* table = gaiji_tables + i; + if (strcmp(table->name, name) == 0) { + return table; } } return NULL; } -void gaiji_stub_encode(char output[], int size, int code, const Gaiji_Context* context, Gaiji_Width width) { +void gaiji_stub_encode(char output[], int size, int code, const Gaiji_Table* table, Gaiji_Width width) { do { - if (context == NULL) { + if (table == NULL) { break; } @@ -142,12 +142,12 @@ void gaiji_stub_encode(char output[], int size, int code, const Gaiji_Context* c switch (width) { case GAIJI_WIDTH_WIDE: - entries = context->table_wide; - count = context->count_wide; + entries = table->table_wide; + count = table->count_wide; break; case GAIJI_WIDTH_NARROW: - entries = context->table_narrow; - count = context->count_narrow; + entries = table->table_narrow; + count = table->count_narrow; break; } diff --git a/gaiji.h b/gaiji.h index 78c725d..01da232 100644 --- a/gaiji.h +++ b/gaiji.h @@ -23,9 +23,9 @@ * Constants */ -#define MAX_UTF8_BYTES 9 -#define MAX_STUB_BYTES 32 -#define MAX_CONTEXT_NAME 256 +#define MAX_UTF8_BYTES 9 +#define MAX_STUB_BYTES 32 +#define MAX_TABLE_NAME 256 /* * Types @@ -37,12 +37,12 @@ typedef struct { } Gaiji_Entry; typedef struct { - char name[MAX_CONTEXT_NAME]; + char name[MAX_TABLE_NAME]; const Gaiji_Entry* table_wide; int count_wide; const Gaiji_Entry* table_narrow; int count_narrow; -} Gaiji_Context; +} Gaiji_Table; typedef enum { GAIJI_WIDTH_WIDE, @@ -53,8 +53,8 @@ typedef enum { * Functions */ -const Gaiji_Context* gaiji_context_select(const char name[]); -void gaiji_stub_encode(char output[], int size, int code, const Gaiji_Context* context, Gaiji_Width width); +const Gaiji_Table* gaiji_table_select(const char name[]); +void gaiji_stub_encode(char output[], int size, int code, const Gaiji_Table* table, Gaiji_Width width); void gaiji_stub_decode(char output[], int size, const char input[]); #endif /* GAIJI_H */ diff --git a/main.c b/main.c index 7724af3..a0215a2 100644 --- a/main.c +++ b/main.c @@ -35,7 +35,7 @@ * Local functions */ -static void export_subbook_entries(Book_Subbook* subbook, EB_Book* eb_book, EB_Hookset* eb_hookset, Gaiji_Context* context) { +static void export_subbook_entries(Book_Subbook* subbook, EB_Book* eb_book, EB_Hookset* eb_hookset, Gaiji_Table* table) { if (subbook->entry_capacity == 0) { subbook->entry_capacity = 16384; subbook->entries = malloc(subbook->entry_capacity * sizeof(Book_Entry)); @@ -58,38 +58,38 @@ static void export_subbook_entries(Book_Subbook* subbook, EB_Book* eb_book, EB_H } Book_Entry* entry = subbook->entries + subbook->entry_count++; - entry->heading = book_read(eb_book, eb_hookset, &hit->heading, BOOK_MODE_HEADING, context); - entry->text = book_read(eb_book, eb_hookset, &hit->text, BOOK_MODE_TEXT, context); + entry->heading = book_read(eb_book, eb_hookset, &hit->heading, BOOK_MODE_HEADING, table); + entry->text = book_read(eb_book, eb_hookset, &hit->text, BOOK_MODE_TEXT, table); } } while (hit_count > 0); } static void export_subbook(Book_Subbook* subbook, EB_Book* eb_book, EB_Hookset* eb_hookset) { - Gaiji_Context context = {}; + Gaiji_Table table = {}; char title[EB_MAX_TITLE_LENGTH + 1]; if (eb_subbook_title(eb_book, title) == EB_SUCCESS) { subbook->title = eucjp_to_utf8(title); - context = *gaiji_context_select(subbook->title); + table = *gaiji_table_select(subbook->title); } if (eb_have_copyright(eb_book)) { EB_Position position; if (eb_copyright(eb_book, &position) == EB_SUCCESS) { - subbook->copyright = book_read(eb_book, eb_hookset, &position, BOOK_MODE_TEXT, &context); + subbook->copyright = book_read(eb_book, eb_hookset, &position, BOOK_MODE_TEXT, &table); } } if (eb_search_all_alphabet(eb_book) == EB_SUCCESS) { - export_subbook_entries(subbook, eb_book, eb_hookset, &context); + export_subbook_entries(subbook, eb_book, eb_hookset, &table); } if (eb_search_all_kana(eb_book) == EB_SUCCESS) { - export_subbook_entries(subbook, eb_book, eb_hookset, &context); + export_subbook_entries(subbook, eb_book, eb_hookset, &table); } if (eb_search_all_asis(eb_book) == EB_SUCCESS) { - export_subbook_entries(subbook, eb_book, eb_hookset, &context); + export_subbook_entries(subbook, eb_book, eb_hookset, &table); } }