1
zero-epwing/main.c

104 lines
2.7 KiB
C
Raw Normal View History

2016-10-29 23:58:09 +00:00
#include <stdio.h>
2016-10-30 02:05:38 +00:00
#include <string.h>
2016-10-30 00:38:50 +00:00
#include <eb/eb.h>
#include <eb/error.h>
2016-10-30 01:58:26 +00:00
void print_book_info(EB_Book * book) {
2016-10-30 02:05:38 +00:00
printf("Book info for %s:\n", book->path);
2016-10-30 01:58:26 +00:00
EB_Disc_Code disc_code;
if (eb_disc_type(book, &disc_code) == EB_SUCCESS) {
2016-10-30 02:05:38 +00:00
printf("\tBook type: ");
2016-10-30 01:58:26 +00:00
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 {
2016-10-30 02:05:38 +00:00
perror("\tError: failed to get book type\n");
2016-10-30 01:58:26 +00:00
}
EB_Character_Code char_code;
if (eb_character_code(book, &char_code) == EB_SUCCESS) {
2016-10-30 02:05:38 +00:00
printf("\tCharacter type: ");
2016-10-30 01:58:26 +00:00
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 {
2016-10-30 02:05:38 +00:00
perror("\tError: failed to get book character code\n");
2016-10-30 01:58:26 +00:00
}
EB_Subbook_Code sub_codes[EB_MAX_SUBBOOKS];
int sub_count = 0;
if (eb_subbook_list(book, sub_codes, &sub_count) == EB_SUCCESS) {
2016-10-30 02:05:38 +00:00
printf("\tFound %d sub-book(s):\n", sub_count);
2016-10-30 01:58:26 +00:00
char title[EB_MAX_TITLE_LENGTH + 1];
for (int i = 0; i < sub_count; ++i) {
2016-10-30 02:05:38 +00:00
if (eb_subbook_title2(book, sub_codes[i], title) != EB_SUCCESS) {
strcpy(title, "<unknown>");
2016-10-30 01:58:26 +00:00
}
2016-10-30 02:05:38 +00:00
printf("\t\t %d: %s\n", sub_codes[i], title);
2016-10-30 01:58:26 +00:00
}
}
else {
2016-10-30 02:05:38 +00:00
perror("\tError: could not get sub-book list\n");
2016-10-30 01:58:26 +00:00
}
}
2016-10-30 01:27:05 +00:00
int dump(const char path[]) {
2016-10-30 01:58:26 +00:00
if (eb_initialize_library() != EB_SUCCESS) {
perror("error: failed to initialize library\n");
2016-10-30 01:27:05 +00:00
return 1;
2016-10-30 00:38:50 +00:00
}
2016-10-29 23:58:09 +00:00
2016-10-30 01:58:26 +00:00
EB_Book book;
if (eb_bind(&book, path) != EB_SUCCESS) {
perror("error: failed to bind book\n");
eb_finalize_book(&book);
return 1;
}
2016-10-30 01:27:05 +00:00
2016-10-30 01:58:26 +00:00
print_book_info(&book);
eb_finalize_book(&book);
2016-10-30 00:38:50 +00:00
eb_finalize_library();
2016-10-30 01:27:05 +00:00
return 0;
}
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "usage: %s path\n", argv[0]);
2016-10-30 01:58:26 +00:00
return 2;
2016-10-30 01:27:05 +00:00
}
return dump(argv[1]);
2016-10-29 23:58:09 +00:00
}