diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py index c78ae1d..9f4b23c 100644 --- a/.ycm_extra_conf.py +++ b/.ycm_extra_conf.py @@ -1,8 +1,12 @@ def FlagsForFile(filename, **kwargs): flags = [ - '-Wall', '-Wextra', '-Werror', - '-std=c11', - '-x', 'c', + '-Wall', + '-Wextra', + '-Werror', + '-std=gnu11', + '-I/mnt/projects/zero-epwing/eb', + '-x', + 'c', ] return { diff --git a/main.c b/main.c index 082633c..6d0881c 100644 --- a/main.c +++ b/main.c @@ -16,7 +16,11 @@ * along with this program. If not, see . */ +#define _BSD_SOURCE + #include +#include +#include #include "convert.h" #include "util.h" @@ -80,21 +84,64 @@ static void dump_book(EB_Book* book) { } } -static int process(const char path[]) { - if (eb_initialize_library() != EB_SUCCESS) { - fprintf(stderr, "error: failed to initialize library\n"); - return 1; - } - - EB_Book book; - eb_initialize_book(&book); +static int export(const char path[]) { + Book book_data = {}; do { - if (eb_bind(&book, path) != EB_SUCCESS) { - fprintf(stderr, "error: failed to bind book\n"); + if (eb_initialize_library() != EB_SUCCESS) { + strcpy(book_data.error, "failed to initialize library"); break; } + EB_Book book; + eb_initialize_book(&book); + + if (eb_bind(&book, path) != EB_SUCCESS) { + strcpy(book_data.error, "failed to bind book to path"); + eb_finalize_library(); + break; + } + + EB_Character_Code character_code; + if (eb_character_code(&book, &character_code) == EB_SUCCESS) { + switch (character_code) { + case EB_CHARCODE_ISO8859_1: + strcpy(book_data.character_code, "iso 8859-1"); + break; + case EB_CHARCODE_JISX0208: + strcpy(book_data.character_code, "jis x 0208"); + break; + case EB_CHARCODE_JISX0208_GB2312: + strcpy(book_data.character_code, "jis x 0208 / gb 2312"); + break; + default: + strcpy(book_data.character_code, "invalid"); + break; + } + } + else { + strcpy(book_data.character_code, "error"); + } + + EB_Disc_Code disc_code; + if (eb_disc_type(&book, &disc_code) == EB_SUCCESS) { + switch (disc_code) { + case EB_DISC_EB: + strcpy(book_data.disc_code, "eb"); + break; + case EB_DISC_EPWING: + strcpy(book_data.disc_code, "epwing"); + break; + default: + strcpy(book_data.disc_code, "invalid"); + break; + } + } + else { + strcpy(book_data.disc_code, "error"); + } + + EB_Subbook_Code sub_codes[EB_MAX_SUBBOOKS]; int sub_count = 0; @@ -111,11 +158,12 @@ static int process(const char path[]) { fprintf(stderr, "error: failed to set sub-book\n"); } } - } - while (0); - eb_finalize_book(&book); - eb_finalize_library(); + eb_finalize_book(&book); + eb_finalize_library(); + } + while(0); + return 0; } @@ -125,5 +173,5 @@ int main(int argc, char *argv[]) { return 2; } - return process(argv[1]); + return export(argv[1]); } diff --git a/util.h b/util.h index 88516e2..a944191 100644 --- a/util.h +++ b/util.h @@ -21,6 +21,42 @@ #include +/* + Dictionary structures +*/ + +typedef struct { + char* heading; + char* text; + char* error; + + int page; + int offset; +} Entry; + +typedef struct { + char* title; + char* error; + + Entry* entries; + int entry_count; +} Subbook; + +typedef struct { + char character_code[256]; + char disc_code[256]; + char copyright; + + Subbook* subbooks; + int subbook_count; + + char error[256]; +} Book; + +/* + Array +*/ + typedef struct { void** ptr; size_t used;