static void go_text_eb (uim_eb *ueb, EB_Position position, char **str, const char *enc) { EB_Hookset hookset; char text[MAX_TEXT + 1]; ssize_t text_length; ssize_t bytes; int i; if (eb_seek_text(&ueb->book, &position) != EB_SUCCESS) { uim_notify_fatal(N_("eb: eb_seek_text error occurs")); return; } eb_initialize_hookset(&hookset); for (i = 0; i < 1; i++) { char *local; iconv_t cd; if (eb_read_text(&ueb->book, NULL, &hookset, NULL, MAX_TEXT, text, &text_length) != EB_SUCCESS) { bytes = 0; uim_notify_fatal(N_("eb_read_text : an error occurs")); return; } bytes += text_length; if (text_length < 1) break; /* FIXME! check return value */ cd = (iconv_t)uim_iconv->create(enc, "EUC-JP"); local = uim_iconv->convert(cd, text); uim_iconv->release(cd); uim_eb_strappend(str, local, strlen(local)); free(local); } eb_finalize_hookset(&hookset); }
/*------------------------------------------------------------------------ -- 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 */