Cleanup
This commit is contained in:
parent
e849fd4325
commit
a2b6d36fe7
6
book.c
6
book.c
@ -78,7 +78,7 @@ static void encode_book(Book* book, json_t* book_json) {
|
|||||||
* Exported functions
|
* 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) {
|
if (eb_seek_text(book, position) != EB_SUCCESS) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ char* book_read(EB_Book* book, EB_Hookset* hookset, const EB_Position* position,
|
|||||||
book,
|
book,
|
||||||
NULL,
|
NULL,
|
||||||
hookset,
|
hookset,
|
||||||
context,
|
table,
|
||||||
ARRSIZE(data) - 1,
|
ARRSIZE(data) - 1,
|
||||||
data,
|
data,
|
||||||
&data_length
|
&data_length
|
||||||
@ -104,7 +104,7 @@ char* book_read(EB_Book* book, EB_Hookset* hookset, const EB_Position* position,
|
|||||||
book,
|
book,
|
||||||
NULL,
|
NULL,
|
||||||
hookset,
|
hookset,
|
||||||
context,
|
table,
|
||||||
ARRSIZE(data) - 1,
|
ARRSIZE(data) - 1,
|
||||||
data,
|
data,
|
||||||
&data_length
|
&data_length
|
||||||
|
2
book.h
2
book.h
@ -61,7 +61,7 @@ typedef enum {
|
|||||||
* Functions
|
* 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_free(Book* book);
|
||||||
void book_dump(Book* book, bool pretty_print, FILE* fp);
|
void book_dump(Book* book, bool pretty_print, FILE* fp);
|
||||||
|
|
||||||
|
42
gaiji.c
42
gaiji.c
@ -27,7 +27,7 @@
|
|||||||
* Macros
|
* Macros
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define GAIJI_CONTEXT(name, ents) {\
|
#define GAIJI_TABLE(name, ents) {\
|
||||||
name,\
|
name,\
|
||||||
gaiji_table_##ents##_wide,\
|
gaiji_table_##ents##_wide,\
|
||||||
ARRSIZE(gaiji_table_##ents##_wide),\
|
ARRSIZE(gaiji_table_##ents##_wide),\
|
||||||
@ -49,15 +49,15 @@
|
|||||||
#include "tables/gaiji_table_snmkg99.h"
|
#include "tables/gaiji_table_snmkg99.h"
|
||||||
#include "tables/gaiji_table_wadai5.h"
|
#include "tables/gaiji_table_wadai5.h"
|
||||||
|
|
||||||
static const Gaiji_Context gaiji_contexts[] = {
|
static const Gaiji_Table gaiji_tables[] = {
|
||||||
GAIJI_CONTEXT("ジーニアス英和辞典", genius),
|
GAIJI_TABLE("ジーニアス英和辞典", genius),
|
||||||
GAIJI_CONTEXT("スーパー大辞林", daijirin),
|
GAIJI_TABLE("スーパー大辞林", daijirin),
|
||||||
GAIJI_CONTEXT("大辞泉", daijisen),
|
GAIJI_TABLE("大辞泉", daijisen),
|
||||||
GAIJI_CONTEXT("広辞苑第六版", kojien),
|
GAIJI_TABLE("広辞苑第六版", kojien),
|
||||||
GAIJI_CONTEXT("新和英大辞典", wadai5),
|
GAIJI_TABLE("新和英大辞典", wadai5),
|
||||||
GAIJI_CONTEXT("新明解国語辞典 ", snmkg99),
|
GAIJI_TABLE("新明解国語辞典 ", snmkg99),
|
||||||
GAIJI_CONTEXT("新英和・和英中辞典", chujiten),
|
GAIJI_TABLE("新英和・和英中辞典", chujiten),
|
||||||
GAIJI_CONTEXT("明鏡国語辞典", meikyojj),
|
GAIJI_TABLE("明鏡国語辞典", meikyojj),
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -120,20 +120,20 @@ static void encode_sequence(char output[], int size, const char utf8[]) {
|
|||||||
* Exported functions
|
* Exported functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Gaiji_Context* gaiji_context_select(const char name[]) {
|
const Gaiji_Table* gaiji_table_select(const char name[]) {
|
||||||
for (unsigned i = 0; i < ARRSIZE(gaiji_contexts); ++i) {
|
for (unsigned i = 0; i < ARRSIZE(gaiji_tables); ++i) {
|
||||||
const Gaiji_Context* context = gaiji_contexts + i;
|
const Gaiji_Table* table = gaiji_tables + i;
|
||||||
if (strcmp(context->name, name) == 0) {
|
if (strcmp(table->name, name) == 0) {
|
||||||
return context;
|
return table;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
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 {
|
do {
|
||||||
if (context == NULL) {
|
if (table == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,12 +142,12 @@ void gaiji_stub_encode(char output[], int size, int code, const Gaiji_Context* c
|
|||||||
|
|
||||||
switch (width) {
|
switch (width) {
|
||||||
case GAIJI_WIDTH_WIDE:
|
case GAIJI_WIDTH_WIDE:
|
||||||
entries = context->table_wide;
|
entries = table->table_wide;
|
||||||
count = context->count_wide;
|
count = table->count_wide;
|
||||||
break;
|
break;
|
||||||
case GAIJI_WIDTH_NARROW:
|
case GAIJI_WIDTH_NARROW:
|
||||||
entries = context->table_narrow;
|
entries = table->table_narrow;
|
||||||
count = context->count_narrow;
|
count = table->count_narrow;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
gaiji.h
14
gaiji.h
@ -23,9 +23,9 @@
|
|||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MAX_UTF8_BYTES 9
|
#define MAX_UTF8_BYTES 9
|
||||||
#define MAX_STUB_BYTES 32
|
#define MAX_STUB_BYTES 32
|
||||||
#define MAX_CONTEXT_NAME 256
|
#define MAX_TABLE_NAME 256
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Types
|
* Types
|
||||||
@ -37,12 +37,12 @@ typedef struct {
|
|||||||
} Gaiji_Entry;
|
} Gaiji_Entry;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char name[MAX_CONTEXT_NAME];
|
char name[MAX_TABLE_NAME];
|
||||||
const Gaiji_Entry* table_wide;
|
const Gaiji_Entry* table_wide;
|
||||||
int count_wide;
|
int count_wide;
|
||||||
const Gaiji_Entry* table_narrow;
|
const Gaiji_Entry* table_narrow;
|
||||||
int count_narrow;
|
int count_narrow;
|
||||||
} Gaiji_Context;
|
} Gaiji_Table;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GAIJI_WIDTH_WIDE,
|
GAIJI_WIDTH_WIDE,
|
||||||
@ -53,8 +53,8 @@ typedef enum {
|
|||||||
* Functions
|
* Functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Gaiji_Context* gaiji_context_select(const char name[]);
|
const Gaiji_Table* gaiji_table_select(const char name[]);
|
||||||
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);
|
||||||
void gaiji_stub_decode(char output[], int size, const char input[]);
|
void gaiji_stub_decode(char output[], int size, const char input[]);
|
||||||
|
|
||||||
#endif /* GAIJI_H */
|
#endif /* GAIJI_H */
|
||||||
|
18
main.c
18
main.c
@ -35,7 +35,7 @@
|
|||||||
* Local functions
|
* 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) {
|
if (subbook->entry_capacity == 0) {
|
||||||
subbook->entry_capacity = 16384;
|
subbook->entry_capacity = 16384;
|
||||||
subbook->entries = malloc(subbook->entry_capacity * sizeof(Book_Entry));
|
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++;
|
Book_Entry* entry = subbook->entries + subbook->entry_count++;
|
||||||
entry->heading = book_read(eb_book, eb_hookset, &hit->heading, BOOK_MODE_HEADING, 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, context);
|
entry->text = book_read(eb_book, eb_hookset, &hit->text, BOOK_MODE_TEXT, table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (hit_count > 0);
|
while (hit_count > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void export_subbook(Book_Subbook* subbook, EB_Book* eb_book, EB_Hookset* eb_hookset) {
|
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];
|
char title[EB_MAX_TITLE_LENGTH + 1];
|
||||||
if (eb_subbook_title(eb_book, title) == EB_SUCCESS) {
|
if (eb_subbook_title(eb_book, title) == EB_SUCCESS) {
|
||||||
subbook->title = eucjp_to_utf8(title);
|
subbook->title = eucjp_to_utf8(title);
|
||||||
context = *gaiji_context_select(subbook->title);
|
table = *gaiji_table_select(subbook->title);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eb_have_copyright(eb_book)) {
|
if (eb_have_copyright(eb_book)) {
|
||||||
EB_Position position;
|
EB_Position position;
|
||||||
if (eb_copyright(eb_book, &position) == EB_SUCCESS) {
|
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) {
|
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) {
|
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) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user