static int check_match(char *haystack, char *needle){ wchar_t *l_haystack; wchar_t *l_needle; char *rp; gint len; len = strlen(needle); rp = haystack; while(*rp != '\0'){ if(strncasecmp(rp, needle, len) == 0) return(0); if(isascii(*rp)) rp += 1; else rp += 2; } return(1); /* l_haystack = any_to_utf8(haystack); l_needle = any_to_utf8(needle); rp = wcsstr(l_haystack, l_needle); free(l_haystack); free(l_needle); if(rp == NULL) return(1); else return(0); */ } static gint ebook_full_search(BOOK_INFO *binfo, char *word, gint method) { EB_Error_Code error_code=EB_SUCCESS; EB_Position text_position; EB_Position current_position; EB_Position next_position; int i, len; char heading[MAXLEN_TEXT + 1]; char text[MAXLEN_TEXT + 1]; char *keywords[EBOOK_MAX_KEYWORDS + 1]; SEARCH_RESULT *rp; char *p; // g_print("ebook_full_text_search : %s\n", word); if((error_code = ebook_set_subbook(binfo)) != EB_SUCCESS) return(error_code); error_code = eb_text(binfo->book, &text_position); if (error_code != EB_SUCCESS) { fprintf(stderr, "failed to get text information, %s\n", eb_error_message(error_code)); return(error_code); } error_code = eb_seek_text(binfo->book, &text_position); if (error_code != EB_SUCCESS) { fprintf(stderr, "failed to seek text, %s\n", eb_error_message(error_code)); return(error_code); } current_position = text_position; for(i=0;;i++){ error_code = eb_read_text(binfo->book, binfo->appendix, &heading_hookset, NULL, MAXLEN_TEXT, heading, &len); if (error_code != EB_SUCCESS) { fprintf(stderr, "failed to read text : %s\n", eb_error_message(error_code)); return(error_code); } /* error_code = eb_read_heading(binfo->book, binfo->appendix, &heading_hookset, NULL, MAXLEN_HEADING, heading, &len); if (error_code != EB_SUCCESS) { fprintf(stderr, "failed to read the heading, %s\n", eb_error_message(error_code)); return(error_code); } */ heading[len] = '\0'; p = strchr(heading, '\n'); if(p != NULL) *p = '\0'; // HOOKSETなしで読む error_code = eb_seek_text(binfo->book, ¤t_position); if (error_code != EB_SUCCESS) { fprintf(stderr, "failed to seek text, %s\n", eb_error_message(error_code)); return(error_code); } error_code = eb_read_text(binfo->book, binfo->appendix, NULL, NULL, MAXLEN_TEXT, text, &len); if (error_code != EB_SUCCESS) { fprintf(stderr, "failed to read text : %s\n", eb_error_message(error_code)); return(error_code); } text[len] = '\0'; /* g_print("page = 0x%0x, offset = 0x%0x\n", current_position.page, current_position.offset); */ // g_print("heading = %s\n\ntext = %s\n\n", heading, text); // 全文検索する if(check_match(text, word) == 0){ hit_count ++; /* error_code = eb_seek_text(binfo->book, ¤t_position); if (error_code != EB_SUCCESS) { fprintf(stderr, "failed to seek text, %s\n", eb_error_message(error_code)); return(error_code); } error_code = eb_read_text(binfo->book, binfo->appendix, &text_hookset, NULL, MAXLEN_TEXT, text, &len); if (error_code != EB_SUCCESS) { fprintf(stderr, "failed to read text : %s\n", eb_error_message(error_code)); return(error_code); } text[len] = '\0'; */ rp = (SEARCH_RESULT *)calloc(sizeof(SEARCH_RESULT),1); if(rp == NULL){ fprintf(stderr, "No memory\n"); exit(1); } rp->heading = strdup(heading); rp->book_info = binfo; rp->search_method = method; rp->pos_heading = current_position; rp->pos_text = current_position; search_result = g_list_append(search_result, rp); // g_print("heading = %s\n\ntext = %s\n\n", heading, text); } error_code = eb_forward_text(binfo->book, NULL); if (error_code == EB_ERR_END_OF_CONTENT) { // g_print("EB_ERR_END_OF_CONTENT\n"); break; } else if (error_code != EB_SUCCESS) { fprintf(stderr, "failed to forward text, %s\n", eb_error_message(error_code)); return(error_code); } error_code = eb_tell_text(binfo->book, &next_position); if(error_code != EB_SUCCESS){ fprintf(stderr, "failed to tell text : %s\n", eb_error_message(error_code)); return(error_code); } if((current_position.page == next_position.page) && (current_position.offset == next_position.offset)){ /* if(next_position.offset == 2047){ next_position.page = next_position.page + 1; next_position.offset = 0; } else { next_position.offset ++; } */ break; } current_position = next_position; } // g_print("total %d searched, %d hits\n", i+1, hit_count); return(error_code); } static gint ebook_full_heading_search(binfo, word){ }