1
This commit is contained in:
Alex Yatskov 2016-10-29 18:58:26 -07:00
parent 9c2679efad
commit e78353710b

88
main.c
View File

@ -3,16 +3,92 @@
#include <eb/eb.h>
#include <eb/error.h>
int dump(const char path[]) {
(void) path;
void print_book_info(EB_Book * book) {
EB_Disc_Code disc_code;
if (eb_disc_type(book, &disc_code) == EB_SUCCESS) {
printf("book type: ");
switch (disc_code) {
case EB_DISC_EB:
printf("EB_DISC_EB\n");
break;
case EB_DISC_EPWING:
printf("EB_DISC_EPWING\n");
break;
case EB_DISC_INVALID:
printf("EB_DISC_INVALID\n");
break;
default:
printf("undefined\n");
break;
}
}
else {
perror("error: failed to get book type\n");
}
const EB_Error_Code error_code = eb_initialize_library();
if (error_code != EB_SUCCESS) {
perror("error: failed to initialize eb\n");
EB_Character_Code char_code;
if (eb_character_code(book, &char_code) == EB_SUCCESS) {
printf("character type: ");
switch (char_code) {
case EB_CHARCODE_ISO8859_1:
printf("EB_CHARCODE_ISO8859_1\n");
break;
case EB_CHARCODE_JISX0208:
printf("EB_CHARCODE_JISX0208\n");
break;
case EB_CHARCODE_JISX0208_GB2312:
printf("EB_CHARCODE_JISX0208_GB2312\n");
break;
case EB_CHARCODE_INVALID:
printf("EB_CHARCODE_INVALID\n");
break;
default:
printf("undefined\n");
break;
}
}
else {
perror("error: failed to get book character code\n");
}
EB_Subbook_Code sub_codes[EB_MAX_SUBBOOKS];
int sub_count = 0;
if (eb_subbook_list(book, sub_codes, &sub_count) == EB_SUCCESS) {
char title[EB_MAX_TITLE_LENGTH + 1];
for (int i = 0; i < sub_count; ++i) {
if (eb_subbook_title2(book, sub_codes[i], title) == EB_SUCCESS) {
printf("sub-book found: %d (%s)\n", sub_codes[i], title);
}
else {
perror("error: could not get sub-book title\n");
}
}
}
else {
perror("error: could not get sub-book list\n");
}
}
int dump(const char path[]) {
printf("processing dictionary: %s\n", path);
if (eb_initialize_library() != EB_SUCCESS) {
perror("error: failed to initialize library\n");
return 1;
}
EB_Book book;
if (eb_bind(&book, path) != EB_SUCCESS) {
perror("error: failed to bind book\n");
eb_finalize_book(&book);
return 1;
}
print_book_info(&book);
eb_finalize_book(&book);
eb_finalize_library();
return 0;
}
@ -20,7 +96,7 @@ int dump(const char path[]) {
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "usage: %s path\n", argv[0]);
return 1;
return 2;
}
return dump(argv[1]);