WIP
This commit is contained in:
parent
e0bd97c505
commit
32dc5fafb9
12
gaiji.c
12
gaiji.c
@ -40,7 +40,7 @@
|
||||
|
||||
#include "gaiji_table_daijisen.h"
|
||||
|
||||
static const Gaiji_context gaiji_contexts[] = {
|
||||
static const Gaiji_Context gaiji_contexts[] = {
|
||||
GAIJI_CONTEXT("大辞泉", daijisen),
|
||||
};
|
||||
|
||||
@ -84,9 +84,9 @@ static void encode_sequence(char output[], int size, const char utf8[]) {
|
||||
* Exported functions
|
||||
*/
|
||||
|
||||
const Gaiji_context* gaiji_select_context(const char name[]) {
|
||||
const Gaiji_Context* gaiji_select_context(const char name[]) {
|
||||
for (unsigned i = 0; i < ARRSIZE(gaiji_contexts); ++i) {
|
||||
const Gaiji_context* context = gaiji_contexts + i;
|
||||
const Gaiji_Context* context = gaiji_contexts + i;
|
||||
if (strcmp(context->name, name) == 0) {
|
||||
return context;
|
||||
}
|
||||
@ -95,13 +95,13 @@ const Gaiji_context* gaiji_select_context(const char name[]) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void gaiji_build_stub(char output[], int size, int code, const Gaiji_context* context, Gaiji_width width) {
|
||||
void gaiji_build_stub(char output[], int size, int code, const Gaiji_Context* context, Gaiji_Width width) {
|
||||
do {
|
||||
if (context == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
const Gaiji_entry* entries = NULL;
|
||||
const Gaiji_Entry* entries = NULL;
|
||||
int count = 0;
|
||||
|
||||
switch (width) {
|
||||
@ -118,7 +118,7 @@ void gaiji_build_stub(char output[], int size, int code, const Gaiji_context* co
|
||||
assert(entries != NULL);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const Gaiji_entry* entry = entries + i;
|
||||
const Gaiji_Entry* entry = entries + i;
|
||||
if (entry->code == code) {
|
||||
encode_sequence(output, size, entry->utf8);
|
||||
return;
|
||||
|
18
gaiji.h
18
gaiji.h
@ -25,7 +25,7 @@
|
||||
|
||||
#define MAX_UTF8_BYTES 9
|
||||
#define MAX_STUB_BYTES 32
|
||||
#define MAX_TABLE_NAME 256
|
||||
#define MAX_CONTEXT_NAME 256
|
||||
|
||||
/*
|
||||
* Types
|
||||
@ -34,27 +34,27 @@
|
||||
typedef struct {
|
||||
int code;
|
||||
char utf8[MAX_UTF8_BYTES];
|
||||
} Gaiji_entry;
|
||||
} Gaiji_Entry;
|
||||
|
||||
typedef struct {
|
||||
char name[MAX_TABLE_NAME];
|
||||
const Gaiji_entry* table_wide;
|
||||
char name[MAX_CONTEXT_NAME];
|
||||
const Gaiji_Entry* table_wide;
|
||||
int count_wide;
|
||||
const Gaiji_entry* table_narrow;
|
||||
const Gaiji_Entry* table_narrow;
|
||||
int count_narrow;
|
||||
} Gaiji_context;
|
||||
} Gaiji_Context;
|
||||
|
||||
typedef enum {
|
||||
GAIJI_WIDTH_WIDE,
|
||||
GAIJI_WIDTH_NARROW,
|
||||
} Gaiji_width;
|
||||
} Gaiji_Width;
|
||||
|
||||
/*
|
||||
* Functions
|
||||
*/
|
||||
|
||||
const Gaiji_context* gaiji_select_context(const char name[]);
|
||||
void gaiji_build_stub(char output[], int size, int code, const Gaiji_context* context, Gaiji_width width);
|
||||
const Gaiji_Context* gaiji_select_context(const char name[]);
|
||||
void gaiji_build_stub(char output[], int size, int code, const Gaiji_Context* context, Gaiji_Width width);
|
||||
void gaiji_fixup_stub(char output[], int size, const char input[]);
|
||||
|
||||
#endif /* GAIJI_H */
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include "gaiji.h"
|
||||
|
||||
static const Gaiji_entry gaiji_table_daijisen_narrow[] = {
|
||||
static const Gaiji_Entry gaiji_table_daijisen_narrow[] = {
|
||||
{ 0xA121, { 0xC2, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* */
|
||||
{ 0xA122, { 0xC2, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ¡ */
|
||||
{ 0xA123, { 0xC2, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ¢ */
|
||||
@ -252,7 +252,7 @@ static const Gaiji_entry gaiji_table_daijisen_narrow[] = {
|
||||
{ 0xA34F, { 0xCB, 0x9C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ˜ */
|
||||
};
|
||||
|
||||
static const Gaiji_entry gaiji_table_daijisen_wide[] = {
|
||||
static const Gaiji_Entry gaiji_table_daijisen_wide[] = {
|
||||
{ 0xB322, { 0xE3, 0x8B, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋘ cb4960 */
|
||||
{ 0xB323, { 0xE3, 0x8B, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋙ cb4960 */
|
||||
{ 0xB324, { 0xE3, 0x8B, 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋚ cb4960 */
|
||||
|
4
main.c
4
main.c
@ -32,7 +32,7 @@
|
||||
* Local functions
|
||||
*/
|
||||
|
||||
static void export_subbook_entries(Subbook* subbook, EB_Book* eb_book, EB_Hookset* eb_hookset, Gaiji_context* context) {
|
||||
static void export_subbook_entries(Subbook* subbook, EB_Book* eb_book, EB_Hookset* eb_hookset, Gaiji_Context* context) {
|
||||
if (subbook->entry_cap == 0) {
|
||||
subbook->entry_cap = 16384;
|
||||
subbook->entries = malloc(subbook->entry_cap * sizeof(Entry));
|
||||
@ -75,7 +75,7 @@ static void export_subbook_entries(Subbook* subbook, EB_Book* eb_book, EB_Hookse
|
||||
}
|
||||
|
||||
static void export_subbook(Subbook* subbook, EB_Book* eb_book, EB_Hookset* eb_hookset) {
|
||||
Gaiji_context context = {};
|
||||
Gaiji_Context context = {};
|
||||
char title[EB_MAX_TITLE_LENGTH + 1];
|
||||
if (eb_subbook_title(eb_book, title) == EB_SUCCESS) {
|
||||
subbook->title = eucjp_to_utf8(title);
|
||||
|
2
util.c
2
util.c
@ -79,7 +79,7 @@ static void encode_book(Book* book, json_t* book_json) {
|
||||
* Exported functions
|
||||
*/
|
||||
|
||||
char* read_book_data(EB_Book* book, EB_Hookset* hookset, Gaiji_context* context, const EB_Position* position, ReadMode mode) {
|
||||
char* read_book_data(EB_Book* book, EB_Hookset* hookset, Gaiji_Context* context, const EB_Position* position, Read_Mode mode) {
|
||||
if (eb_seek_text(book, position) != EB_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
6
util.h
6
util.h
@ -40,7 +40,7 @@
|
||||
typedef struct {
|
||||
char* heading;
|
||||
char* text;
|
||||
} TextBlock;
|
||||
} Text_Block;
|
||||
|
||||
typedef struct {
|
||||
char* heading;
|
||||
@ -67,13 +67,13 @@ typedef struct {
|
||||
typedef enum {
|
||||
READ_MODE_TEXT,
|
||||
READ_MODE_HEADING,
|
||||
} ReadMode;
|
||||
} Read_Mode;
|
||||
|
||||
/*
|
||||
* Functions
|
||||
*/
|
||||
|
||||
char* read_book_data(EB_Book* book, EB_Hookset* hookset, Gaiji_context* context, const EB_Position* position, ReadMode mode);
|
||||
char* read_book_data(EB_Book* book, EB_Hookset* hookset, Gaiji_Context* context, const EB_Position* position, Read_Mode mode);
|
||||
void free_book(Book* book);
|
||||
void dump_book(Book* book, bool pretty_print, FILE* fp);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user