uim_eb * uim_eb_new (const char *bookpath) { uim_eb *ueb; EB_Error_Code err; ueb = uim_malloc(sizeof(uim_eb)); eb_initialize_book(&ueb->book); err = eb_bind(&ueb->book, bookpath); if (err != EB_SUCCESS) { uim_notify_fatal(N_("eb: wrong bookpath")); free(ueb); return NULL; } err = eb_subbook_list(&ueb->book, ueb->subCodes, &ueb->subCount); if (err != EB_SUCCESS) { uim_notify_fatal(N_("eb: eb_subbook_list() failed\n")); free(ueb); return NULL; } return ueb; }
// Initialize Subbook QList <EB_Subbook_Code> QEb::subbookList() { EB_Subbook_Code codes[EB_MAX_SUBBOOKS]; int cnt; QList <EB_Subbook_Code> list; EB_Error_Code ecode = eb_subbook_list(&book, codes, &cnt); if (ecode != EB_SUCCESS) dispError("eb_subbook_list", ecode); else for(int i = 0; i < cnt; i++) list << codes[i]; return list; }
int main(int argc, char *argv[]) { EB_Error_Code error_code; EB_Book book; EB_Subbook_Code subbook_list[EB_MAX_SUBBOOKS]; int subbook_count; int subbook_index; int font_start; unsigned char bitmap[EB_SIZE_NARROW_FONT_16]; int i, j; /* コマンド行引数をチェック。*/ if (argc != 3) { fprintf(stderr, "Usage: %s book-path subbook-index\n", argv[0]); exit(1); } /* EB ライブラリと `book' を初期化。*/ eb_initialize_library(); eb_initialize_book(&book); /* 書籍を `book' に結び付ける。*/ error_code = eb_bind(&book, argv[1]); if (error_code != EB_SUCCESS) { fprintf(stderr, "%s: failed to bind the book, %s: %s\n", argv[0], eb_error_message(error_code), argv[1]); goto die; } /* 副本の一覧を取得。*/ error_code = eb_subbook_list(&book, subbook_list, &subbook_count); if (error_code != EB_SUCCESS) { fprintf(stderr, "%s: failed to get the subbbook list, %s\n", argv[0], eb_error_message(error_code)); goto die; } /* 副本のインデックスを取得。*/ subbook_index = atoi(argv[2]); /*「現在の副本 (current subbook)」を設定。*/ error_code = eb_set_subbook(&book, subbook_list[subbook_index]); if (error_code != EB_SUCCESS) { fprintf(stderr, "%s: failed to set the current subbook, %s\n", argv[0], eb_error_message(error_code)); goto die; } /*「現在の外字の大きさ」を設定。*/ if (eb_set_font(&book, EB_FONT_16) < 0) { fprintf(stderr, "%s: failed to set the font size, %s\n", argv[0], eb_error_message(error_code)); goto die; } /* 外字の開始位置を取得。*/ error_code = eb_narrow_font_start(&book, &font_start); if (error_code != EB_SUCCESS) { fprintf(stderr, "%s: failed to get font information, %s\n", argv[0], eb_error_message(error_code)); goto die; } i = font_start; for (;;) { /* 外字のビットマップデータを取得。*/ error_code = eb_narrow_font_character_bitmap(&book, i, (char *)bitmap); if (error_code != EB_SUCCESS) { fprintf(stderr, "%s: failed to get font data, %s\n", argv[0], eb_error_message(error_code)); goto die; } /* ビットマップをアスキーアートにして出力。*/ printf("code point=%04x\n", i); for (j = 0; j < 16; j++) { fputc((bitmap[j] & 0x80) ? '*' : ' ', stdout); fputc((bitmap[j] & 0x40) ? '*' : ' ', stdout); fputc((bitmap[j] & 0x20) ? '*' : ' ', stdout); fputc((bitmap[j] & 0x10) ? '*' : ' ', stdout); fputc((bitmap[j] & 0x08) ? '*' : ' ', stdout); fputc((bitmap[j] & 0x04) ? '*' : ' ', stdout); fputc((bitmap[j] & 0x02) ? '*' : ' ', stdout); fputc((bitmap[j] & 0x01) ? '*' : ' ', stdout); fputc('\n', stdout); } fputs("--------\n", stdout); /* 外字の文字番号を一つ進める。*/ error_code = eb_forward_narrow_font_character(&book, 1, &i); if (error_code != EB_SUCCESS) break; } /* 書籍と EB ライブラリの利用を終了。*/ eb_finalize_book(&book); eb_finalize_library(); exit(0); /* エラー発生で終了するときの処理。*/ die: eb_finalize_book(&book); eb_finalize_library(); exit(1); }
/* * Uncompress files in `book' and output them under `out_top_path'. * If it succeeds, 0 is returned. Otherwise -1 is returned. */ int ebzip_unzip_book(const char *out_top_path, const char *book_path, char subbook_name_list[][EB_MAX_DIRECTORY_NAME_LENGTH + 1], int subbook_name_count) { EB_Book book; EB_Error_Code error_code; EB_Subbook_Code subbook_list[EB_MAX_SUBBOOKS]; EB_Subbook_Code subbook_code; int subbook_count = 0; int result; int i; eb_initialize_book(&book); /* * Bind a book. */ error_code = eb_bind(&book, book_path); if (error_code != EB_SUCCESS) { fprintf(stderr, "%s: %s\n", invoked_name, eb_error_message(error_code)); fflush(stderr); return -1; } /* * For each targe subbook, convert a subbook-names to a subbook-codes. * If no subbook is specified by `--subbook'(`-S'), set all subbooks * as the target. */ if (subbook_name_count == 0) { error_code = eb_subbook_list(&book, subbook_list, &subbook_count); if (error_code != EB_SUCCESS) { fprintf(stderr, "%s: %s\n", invoked_name, eb_error_message(error_code)); fflush(stderr); return -1; } } else { for (i = 0; i < subbook_name_count; i++) { error_code = find_subbook(&book, subbook_name_list[i], &subbook_code); if (error_code != EB_SUCCESS) { fprintf(stderr, _("%s: unknown subbook name `%s'\n"), invoked_name, subbook_name_list[i]); return -1; } subbook_list[subbook_count++] = subbook_code; } } /* * Uncompress the book. */ if (book.disc_code == EB_DISC_EB) { result = ebzip_unzip_book_eb(&book, out_top_path, book_path, subbook_list, subbook_count); } else { result = ebzip_unzip_book_epwing(&book, out_top_path, book_path, subbook_list, subbook_count); } eb_finalize_book(&book); return result; }
/*------------------------------------------------------------------------ -- Name: init -- -- Description: -- Initialize EB Lib, set hooks, open the desired subbook. -- -- Parameters: -- None. -- -- Returns: -- None. -- ------------------------------------------------------------------------*/ static void init(void) { EB_Error_Code error_code; EB_Subbook_Code subbook_list[EB_MAX_SUBBOOKS]; FILE *out_file = NULL; int subbook_count; /* Blank the output file */ out_file = fopen(out_path, "w"); if(out_file == NULL) { fprintf(stderr, "Error: Could not open output file, \"%s\"\n", out_path); die(1); } fclose(out_file); /* Init EB Lib */ eb_initialize_library(); eb_initialize_book(&book); eb_initialize_hookset(&hookset); /* Set hooks */ eb_set_hook(&hookset, &hook_narrow_font); eb_set_hook(&hookset, &hook_wide_font); if(set_emphasis_hook) { eb_set_hook(&hookset, &hook_begin_emphasis); eb_set_hook(&hookset, &hook_end_emphasis); } if(set_keyword_hook) { eb_set_hook(&hookset, &hook_begin_keyword); eb_set_hook(&hookset, &hook_end_keyword); } if(set_reference_hook) { eb_set_hook(&hookset, &hook_begin_reference); eb_set_hook(&hookset, &hook_end_reference); } if(set_subscript_hook) { eb_set_hook(&hookset, &hook_begin_subscript); eb_set_hook(&hookset, &hook_end_subscript); } if(set_superscript_hook) { eb_set_hook(&hookset, &hook_begin_superscript); eb_set_hook(&hookset, &hook_end_superscript); } /* Open the EPWING book */ error_code = eb_bind(&book, book_path); if(error_code != EB_SUCCESS) { fprintf(stderr, "Error: Failed to bind the book, %s: %s\n", eb_error_message(error_code), book_path); die(1); } /* Get the subbook list */ error_code = eb_subbook_list(&book, subbook_list, &subbook_count); if(error_code != EB_SUCCESS) { fprintf(stderr, "Error: Failed to get the subbbook list, %s\n", eb_error_message(error_code)); die(1); } /* Get the subbook */ error_code = eb_set_subbook(&book, subbook_list[subbook_index]); if(error_code != EB_SUCCESS) { fprintf(stderr, "Error: Failed to set the current subbook, %s\n", eb_error_message(error_code)); die(1); } /* Get the subbook directory (the name only, not the full path) */ error_code = eb_subbook_directory(&book, subbook_directory); if(error_code != EB_SUCCESS) { fprintf(stderr, "Error: Failed to get the subbook directory: %s\n", eb_error_message(error_code)); die(1); } /* Set the font */ if (eb_set_font(&book, EB_FONT_16) < 0) { fprintf(stderr, "Error: Failed to set the font size: %s\n", eb_error_message(error_code)); die(1); } } /* init */