QString QEb::readText(void *para, bool hook_flag) { char buff[1024+1]; ssize_t len; QByteArray b; for(;;) { EB_Error_Code ecode; if (hook_flag) ecode = eb_read_text(&book, &appendix, &hookset, para, 1024, buff, &len); else ecode = eb_read_text(&book, &appendix, NULL, para, 1024, buff, &len); if (ecode != EB_SUCCESS) { dispError("eb_read_text", ecode); break; } if (len > 0) b += QByteArray(buff, (int)len); if (isTextStopped()) break; //if (len < 1024) // break; } return eucToUtf(b); }
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: lookup_word -- -- Description: -- Lookup the input word and send the results to the output file. -- -- Parameters: -- None. -- -- Returns: -- None. -- ------------------------------------------------------------------------*/ static void lookup_word(void) { char lookup_word_utf8[MAXLEN_LOOKUP_WORD + 1]; char lookup_word_eucjp[MAXLEN_LOOKUP_WORD + 1]; char *status_conv = NULL; EB_Error_Code error_code; EB_Hit hits[MAX_HITS]; FILE *in_file = NULL; FILE *out_file = NULL; int hit_count; int heading_length; int text_length; int i; /* Get the word to lookup */ in_file = fopen(in_path, "r"); if(in_file == NULL) { fprintf(stderr, "Error: Could not open input file: \"%s\"", in_path); die(1); } if(fgets(lookup_word_utf8, MAXLEN_LOOKUP_WORD, in_file) == NULL) { fclose(in_file); fprintf(stderr, "Error: Could not read word from input file: \"%s\"", in_path); die(1); } fclose(in_file); /* Remove the final '\n' */ if(lookup_word_utf8[strlen(lookup_word_utf8) - 1] == '\n') { lookup_word_utf8[strlen(lookup_word_utf8) - 1] = '\0'; } /* Convert the lookup word from UTF-8 to EUC-JP */ status_conv = convert_encoding(lookup_word_eucjp, MAXLEN_LOOKUP_WORD, lookup_word_utf8, strlen(lookup_word_utf8), "EUC-JP", "UTF-8"); if(status_conv == NULL) { fprintf(stderr, "Error: Something went wront when trying to encode the lookup word\n"); die(1); } /* Perform an exact search of the lookup word */ error_code = eb_search_exactword(&book, lookup_word_eucjp); if(error_code != EB_SUCCESS) { fprintf(stderr, "Error: Failed to search for the word, %s: %s\n", eb_error_message(error_code), lookup_word_eucjp); die(1); } while(1) { /* Get the list of hits */ error_code = eb_hit_list(&book, MAX_HITS, hits, &hit_count); if(error_code != EB_SUCCESS) { fprintf(stderr, "Error: Failed to get hit entries, %s\n", eb_error_message(error_code)); die(1); } /* Are we done? */ if(hit_count == 0) { break; } /* Create 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); } /* Output only the number of hits? */ if(show_hit_count) { fprintf(out_file, "{HITS: %d}\n", hit_count); } /* Determine the max number of hits to output */ hit_count = MIN(hit_count, max_hits_to_output); /* For each search hit, print the hit information to the output file */ for(i = 0; i < hit_count; i++) { /* Did the user specify a particular hit index to output? */ if(hit_to_output >= 0) { i = hit_to_output; } /* Output the hit number */ if(print_hit_number && (hit_count > 1) && (hit_to_output == -1)) { fprintf(out_file, "{ENTRY: %d}\n", i); } /* Print the heading of the hit to file */ if(print_heading) { /* Seek to the heading */ error_code = eb_seek_text(&book, &(hits[i].heading)); if(error_code != EB_SUCCESS) { fprintf(stderr, "Error: Failed to seek the subbook, %s\n", eb_error_message(error_code)); fclose(out_file); die(1); } /* Read the heading */ error_code = eb_read_heading(&book, NULL, &hookset, NULL, MAXLEN_HEADING, heading, &heading_length); if(error_code != EB_SUCCESS) { fprintf(stderr, "Error: Failed to read the subbook, %s\n", eb_error_message(error_code)); fclose(out_file); die(1); } /* Convert from EUC-JP to UTF-8 */ status_conv = convert_encoding(conv_buf, MAXLEN_CONV, heading, heading_length, "UTF-8", "EUC-JP"); if(status_conv == NULL) { fprintf(stderr, "Error: Something went wrong when trying to encode the the heading\n"); fclose(out_file); die(1); } /* Replace gaiji that have UTF-8 equivalents */ replace_gaiji_with_utf8(final_buf, conv_buf); /* Output the header to file (in UTF-8) */ fprintf(out_file, "%s\n", conv_buf); } /* Print the text of the hit to file */ if(print_text) { /* Seek to the text */ error_code = eb_seek_text(&book, &(hits[i].text)); if(error_code != EB_SUCCESS) { fprintf(stderr, "Error: Failed to seek the subbook, %s\n", eb_error_message(error_code)); fclose(out_file); die(1); } /* Read the text*/ error_code = eb_read_text(&book, NULL, &hookset, NULL, MAXLEN_TEXT, text, &text_length); if(error_code != EB_SUCCESS) { fprintf(stderr, "Error: Failed to read the subbook, %s\n", eb_error_message(error_code)); fclose(out_file); die(1); } } /* Convert from EUC-JP to UTF-8 */ status_conv = convert_encoding(conv_buf, MAXLEN_CONV, text, text_length, "UTF-8", "EUC-JP"); if(status_conv == NULL) { fprintf(stderr, "Error: Something went wrong when trying to encode the the text\n"); fclose(out_file); die(1); } /* Replace gaiji that have UTF-8 equivalents */ replace_gaiji_with_utf8(final_buf, conv_buf); /* Output the text to file (in UTF-8) */ fwrite(final_buf, 1, strlen(final_buf), out_file); /* Since the user specified a hit index, don't display the other hits */ if(hit_to_output >= 0) { break; } } fclose(out_file); } } /* lookup_word */
/*------------------------------------------------------------------------ -- Name: lookup_link -- -- Description: -- Lookup the input link and send the results to the output file. -- -- Parameters: -- None. -- -- Returns: -- None. -- ------------------------------------------------------------------------*/ static void lookup_link(void) { EB_Error_Code error_code; EB_Position position; FILE *in_file = NULL; FILE *out_file = NULL; char link_text[MAXLEN_LOOKUP_WORD] = ""; char *status_conv = NULL; int text_length; int parse_result; in_file = fopen(in_path, "r"); if(in_file == NULL) { fprintf(stderr, "Error: Could not open input file: \"%s\"", in_path); die(1); } if(fgets(link_text, MAXLEN_LOOKUP_WORD, in_file) == NULL) { fclose(in_file); fprintf(stderr, "Error: Could not read word from input file: \"%s\"", in_path); die(1); } fclose(in_file); /* Parse the location of the link in the subbook */ parse_result = sscanf(link_text, "%X %X", &position.page, &position.offset); /* If link was not parsed correctly (2 is the expected number of fields in the input file) */ if(parse_result != 2) { fprintf(stderr, "Error: Could not parse link from input file, %d.\n", parse_result); die(1); } error_code = eb_seek_text(&book, &position); if(error_code != EB_SUCCESS) { fprintf(stderr, "Error: Failed to seek text, \"%s\"\n", eb_error_message(error_code)); die(1); } error_code = eb_read_text(&book, NULL, &hookset, NULL, MAXLEN_TEXT, text, &text_length); if(error_code != EB_SUCCESS) { fprintf(stderr, "Error: Failed to read text, \"%s\"\n", eb_error_message(error_code)); die(1); } /* Convert from EUC-JP to UTF-8 */ status_conv = convert_encoding(conv_buf, MAXLEN_CONV, text, text_length, "UTF-8", "EUC-JP"); if(status_conv == NULL) { fprintf(stderr, "Error: Something went wrong when trying to encode the the text\n"); die(1); } /* Replace gaiji that have UTF-8 equivalents */ replace_gaiji_with_utf8(final_buf, conv_buf); out_file = fopen(out_path, "w"); /* Output the text to file (in UTF-8) */ fwrite(final_buf, 1, strlen(final_buf), out_file); fclose(out_file); } /* lookup_link */