WIP
This commit is contained in:
parent
8e64583e4b
commit
e0bd97c505
2
gaiji.c
2
gaiji.c
@ -84,7 +84,7 @@ static void encode_sequence(char output[], int size, const char utf8[]) {
|
||||
* Exported functions
|
||||
*/
|
||||
|
||||
const Gaiji_context * gaiji_select_table(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;
|
||||
if (strcmp(context->name, name) == 0) {
|
||||
|
12
hooks.c
12
hooks.c
@ -50,7 +50,7 @@
|
||||
}
|
||||
|
||||
/*
|
||||
* Tag printers
|
||||
* Local functions
|
||||
*/
|
||||
|
||||
HOOK_TAGGER(begin_candidate); /* EB_HOOK_BEGIN_CANDIDATE */
|
||||
@ -94,10 +94,6 @@ HOOK_TAGGER(set_indent); /* EB_HOOK_SET_INDENT */
|
||||
HOOK_TAGGER(wide_jisx0208); /* EB_HOOK_WIDE_JISX0208 */
|
||||
HOOK_TAGGER(null); /* EB_HOOK_NULL */
|
||||
|
||||
/*
|
||||
* Local functions
|
||||
*/
|
||||
|
||||
static EB_Error_Code hook_narrow_font( /* EB_HOOK_NARROW_FONT */
|
||||
EB_Book* book,
|
||||
EB_Appendix* appendix,
|
||||
@ -106,11 +102,10 @@ static EB_Error_Code hook_narrow_font( /* EB_HOOK_NARROW_FONT */
|
||||
int argc,
|
||||
const unsigned int argv[]
|
||||
) {
|
||||
assert(argc > 0);
|
||||
|
||||
(void)appendix;
|
||||
(void)code;
|
||||
|
||||
assert(argc > 0);
|
||||
char stub[MAX_STUB_BYTES];
|
||||
gaiji_build_stub(stub, ARRSIZE(stub), argv[0], container, GAIJI_WIDTH_NARROW);
|
||||
eb_write_text_string(book, stub);
|
||||
@ -126,11 +121,10 @@ static EB_Error_Code hook_wide_font( /* EB_HOOK_WIDE_FONT */
|
||||
int argc,
|
||||
const unsigned int argv[]
|
||||
) {
|
||||
assert(argc > 0);
|
||||
|
||||
(void)appendix;
|
||||
(void)code;
|
||||
|
||||
assert(argc > 0);
|
||||
char stub[MAX_STUB_BYTES];
|
||||
gaiji_build_stub(stub, ARRSIZE(stub), argv[0], container, GAIJI_WIDTH_WIDE);
|
||||
eb_write_text_string(book, stub);
|
||||
|
47
main.c
47
main.c
@ -22,32 +22,27 @@
|
||||
#include "convert.h"
|
||||
#include "util.h"
|
||||
#include "hooks.h"
|
||||
#include "gaiji.h"
|
||||
|
||||
#include "eb/eb/eb.h"
|
||||
#include "eb/text.h"
|
||||
#include "eb/eb/error.h"
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
|
||||
#define MAX_HITS 256
|
||||
|
||||
/*
|
||||
* Local functions
|
||||
*/
|
||||
|
||||
static void export_subbook_entries(EB_Book* eb_book, EB_Hookset* eb_hookset, Subbook* subbook) {
|
||||
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));
|
||||
}
|
||||
|
||||
EB_Hit hits[MAX_HITS];
|
||||
EB_Hit hits[256];
|
||||
int hit_count = 0;
|
||||
|
||||
do {
|
||||
if (eb_hit_list(eb_book, MAX_HITS, hits, &hit_count) != EB_SUCCESS) {
|
||||
if (eb_hit_list(eb_book, ARRSIZE(hits), hits, &hit_count) != EB_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -60,40 +55,54 @@ static void export_subbook_entries(EB_Book* eb_book, EB_Hookset* eb_hookset, Sub
|
||||
}
|
||||
|
||||
Entry* entry = subbook->entries + subbook->entry_count++;
|
||||
entry->heading = read_book_data(eb_book, eb_hookset, &hit->heading, READ_MODE_HEADING);
|
||||
entry->text = read_book_data(eb_book, eb_hookset, &hit->text, READ_MODE_TEXT);
|
||||
entry->heading = read_book_data(
|
||||
eb_book,
|
||||
eb_hookset,
|
||||
context,
|
||||
&hit->heading,
|
||||
READ_MODE_HEADING
|
||||
);
|
||||
entry->text = read_book_data(
|
||||
eb_book,
|
||||
eb_hookset,
|
||||
context,
|
||||
&hit->text,
|
||||
READ_MODE_TEXT
|
||||
);
|
||||
}
|
||||
}
|
||||
while (hit_count > 0);
|
||||
}
|
||||
|
||||
static void export_subbook(EB_Book* eb_book, EB_Hookset* eb_hookset, Subbook* subbook) {
|
||||
static void export_subbook(Subbook* subbook, EB_Book* eb_book, EB_Hookset* eb_hookset) {
|
||||
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);
|
||||
context = *gaiji_select_context(subbook->title);
|
||||
}
|
||||
|
||||
if (eb_have_copyright(eb_book)) {
|
||||
EB_Position position;
|
||||
if (eb_copyright(eb_book, &position) == EB_SUCCESS) {
|
||||
subbook->copyright = read_book_data(eb_book, eb_hookset, &position, READ_MODE_TEXT);
|
||||
subbook->copyright = read_book_data(eb_book, eb_hookset, &context, &position, READ_MODE_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
if (eb_search_all_alphabet(eb_book) == EB_SUCCESS) {
|
||||
export_subbook_entries(eb_book, eb_hookset, subbook);
|
||||
export_subbook_entries(subbook, eb_book, eb_hookset, &context);
|
||||
}
|
||||
|
||||
if (eb_search_all_kana(eb_book) == EB_SUCCESS) {
|
||||
export_subbook_entries(eb_book, eb_hookset, subbook);
|
||||
export_subbook_entries(subbook, eb_book, eb_hookset, &context);
|
||||
}
|
||||
|
||||
if (eb_search_all_asis(eb_book) == EB_SUCCESS) {
|
||||
export_subbook_entries(eb_book, eb_hookset, subbook);
|
||||
export_subbook_entries(subbook, eb_book, eb_hookset, &context);
|
||||
}
|
||||
}
|
||||
|
||||
static void export_book(const char path[], Book* book) {
|
||||
static void export_book(Book* book, const char path[]) {
|
||||
do {
|
||||
EB_Error_Code error;
|
||||
if ((error = eb_initialize_library()) != EB_SUCCESS) {
|
||||
@ -156,7 +165,7 @@ static void export_book(const char path[], Book* book) {
|
||||
for (int i = 0; i < book->subbook_count; ++i) {
|
||||
Subbook* subbook = book->subbooks + i;
|
||||
if ((error = eb_set_subbook(&eb_book, sub_codes[i])) == EB_SUCCESS) {
|
||||
export_subbook(&eb_book, &eb_hookset, subbook);
|
||||
export_subbook(subbook, &eb_book, &eb_hookset);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Failed to set subbook: %s\n", eb_error_message(error));
|
||||
@ -200,7 +209,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
Book book = {};
|
||||
export_book(argv[optind], &book);
|
||||
export_book(&book, argv[optind]);
|
||||
dump_book(&book, pretty_print, stdout);
|
||||
free_book(&book);
|
||||
|
||||
|
18
util.c
18
util.c
@ -29,12 +29,6 @@
|
||||
|
||||
#include "jansson/include/jansson.h"
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
|
||||
#define MAX_TEXT 1024
|
||||
|
||||
/*
|
||||
* Local functions
|
||||
*/
|
||||
@ -85,12 +79,12 @@ static void encode_book(Book* book, json_t* book_json) {
|
||||
* Exported functions
|
||||
*/
|
||||
|
||||
char* read_book_data(EB_Book* book, EB_Hookset* hookset, const EB_Position* position, ReadMode mode) {
|
||||
char* read_book_data(EB_Book* book, EB_Hookset* hookset, Gaiji_context* context, const EB_Position* position, ReadMode mode) {
|
||||
if (eb_seek_text(book, position) != EB_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char data[MAX_TEXT];
|
||||
char data[1024];
|
||||
ssize_t data_length = 0;
|
||||
EB_Error_Code error;
|
||||
|
||||
@ -100,8 +94,8 @@ char* read_book_data(EB_Book* book, EB_Hookset* hookset, const EB_Position* posi
|
||||
book,
|
||||
NULL,
|
||||
hookset,
|
||||
NULL,
|
||||
MAX_TEXT - 1,
|
||||
context,
|
||||
ARRSIZE(data) - 1,
|
||||
data,
|
||||
&data_length
|
||||
);
|
||||
@ -111,8 +105,8 @@ char* read_book_data(EB_Book* book, EB_Hookset* hookset, const EB_Position* posi
|
||||
book,
|
||||
NULL,
|
||||
hookset,
|
||||
NULL,
|
||||
MAX_TEXT - 1,
|
||||
context,
|
||||
ARRSIZE(data) - 1,
|
||||
data,
|
||||
&data_length
|
||||
);
|
||||
|
4
util.h
4
util.h
@ -25,6 +25,8 @@
|
||||
|
||||
#include "eb/eb/eb.h"
|
||||
|
||||
#include "gaiji.h"
|
||||
|
||||
/*
|
||||
* Macros
|
||||
*/
|
||||
@ -71,7 +73,7 @@ typedef enum {
|
||||
* Functions
|
||||
*/
|
||||
|
||||
char* read_book_data(EB_Book* book, EB_Hookset* hookset, const EB_Position* position, ReadMode mode);
|
||||
char* read_book_data(EB_Book* book, EB_Hookset* hookset, Gaiji_context* context, const EB_Position* position, ReadMode mode);
|
||||
void free_book(Book* book);
|
||||
void dump_book(Book* book, bool pretty_print, FILE* fp);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user