1
This commit is contained in:
Alex Yatskov 2016-11-19 19:45:37 -08:00
parent e0bd97c505
commit 32dc5fafb9
6 changed files with 23 additions and 23 deletions

12
gaiji.c
View File

@ -40,7 +40,7 @@
#include "gaiji_table_daijisen.h" #include "gaiji_table_daijisen.h"
static const Gaiji_context gaiji_contexts[] = { static const Gaiji_Context gaiji_contexts[] = {
GAIJI_CONTEXT("大辞泉", daijisen), GAIJI_CONTEXT("大辞泉", daijisen),
}; };
@ -84,9 +84,9 @@ static void encode_sequence(char output[], int size, const char utf8[]) {
* Exported functions * 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) { 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) { if (strcmp(context->name, name) == 0) {
return context; return context;
} }
@ -95,13 +95,13 @@ const Gaiji_context* gaiji_select_context(const char name[]) {
return NULL; 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 { do {
if (context == NULL) { if (context == NULL) {
break; break;
} }
const Gaiji_entry* entries = NULL; const Gaiji_Entry* entries = NULL;
int count = 0; int count = 0;
switch (width) { switch (width) {
@ -118,7 +118,7 @@ void gaiji_build_stub(char output[], int size, int code, const Gaiji_context* co
assert(entries != NULL); assert(entries != NULL);
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
const Gaiji_entry* entry = entries + i; const Gaiji_Entry* entry = entries + i;
if (entry->code == code) { if (entry->code == code) {
encode_sequence(output, size, entry->utf8); encode_sequence(output, size, entry->utf8);
return; return;

18
gaiji.h
View File

@ -25,7 +25,7 @@
#define MAX_UTF8_BYTES 9 #define MAX_UTF8_BYTES 9
#define MAX_STUB_BYTES 32 #define MAX_STUB_BYTES 32
#define MAX_TABLE_NAME 256 #define MAX_CONTEXT_NAME 256
/* /*
* Types * Types
@ -34,27 +34,27 @@
typedef struct { typedef struct {
int code; int code;
char utf8[MAX_UTF8_BYTES]; char utf8[MAX_UTF8_BYTES];
} Gaiji_entry; } Gaiji_Entry;
typedef struct { typedef struct {
char name[MAX_TABLE_NAME]; char name[MAX_CONTEXT_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_Context;
typedef enum { typedef enum {
GAIJI_WIDTH_WIDE, GAIJI_WIDTH_WIDE,
GAIJI_WIDTH_NARROW, GAIJI_WIDTH_NARROW,
} Gaiji_width; } Gaiji_Width;
/* /*
* Functions * Functions
*/ */
const Gaiji_context* gaiji_select_context(const char name[]); 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_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[]); void gaiji_fixup_stub(char output[], int size, const char input[]);
#endif /* GAIJI_H */ #endif /* GAIJI_H */

View File

@ -22,7 +22,7 @@
#include "gaiji.h" #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 } }, /*   */ { 0xA121, { 0xC2, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /*   */
{ 0xA122, { 0xC2, 0xA1, 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 } }, /* ¢ */ { 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 } }, /* ˜ */ { 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 */ { 0xB322, { 0xE3, 0x8B, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋘ cb4960 */
{ 0xB323, { 0xE3, 0x8B, 0x99, 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 */ { 0xB324, { 0xE3, 0x8B, 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, /* ㋚ cb4960 */

4
main.c
View File

@ -32,7 +32,7 @@
* Local functions * 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) { if (subbook->entry_cap == 0) {
subbook->entry_cap = 16384; subbook->entry_cap = 16384;
subbook->entries = malloc(subbook->entry_cap * sizeof(Entry)); 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) { 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]; 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);

2
util.c
View File

@ -79,7 +79,7 @@ static void encode_book(Book* book, json_t* book_json) {
* Exported functions * 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) { if (eb_seek_text(book, position) != EB_SUCCESS) {
return NULL; return NULL;
} }

6
util.h
View File

@ -40,7 +40,7 @@
typedef struct { typedef struct {
char* heading; char* heading;
char* text; char* text;
} TextBlock; } Text_Block;
typedef struct { typedef struct {
char* heading; char* heading;
@ -67,13 +67,13 @@ typedef struct {
typedef enum { typedef enum {
READ_MODE_TEXT, READ_MODE_TEXT,
READ_MODE_HEADING, READ_MODE_HEADING,
} ReadMode; } Read_Mode;
/* /*
* Functions * 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 free_book(Book* book);
void dump_book(Book* book, bool pretty_print, FILE* fp); void dump_book(Book* book, bool pretty_print, FILE* fp);