static void search_selection() { GtkTextIter start; GtkTextIter end; gchar *text; gchar *euc_str; gint method; LOG(LOG_DEBUG, "IN : search_selection()"); gtk_text_buffer_get_selection_bounds(text_buffer, &start, &end); text = gtk_text_buffer_get_text(text_buffer, &start, &end, FALSE); if(strlen(text) == 0) return; gtk_entry_set_text(GTK_ENTRY(word_entry), text); euc_str = iconv_convert("utf-8", "euc-jp", text); method = ebook_search_method(); if(method == SEARCH_METHOD_INTERNET){ web_search(); } else if(method == SEARCH_METHOD_GREP){ clear_message(); grep_search(euc_str); } else { clear_message(); ebook_search(euc_str, method); if(search_result == NULL) push_message(_("No hit.")); } save_word_history(text); gtk_editable_select_region(GTK_EDITABLE(word_entry), 0, GTK_ENTRY(word_entry)->text_length); // show_result_tree(); g_free(euc_str); LOG(LOG_DEBUG, "OUT : search_selection()"); }
static void search_selected(gchar *str) { gchar *euc_str; gint method; glong len; LOG(LOG_DEBUG, "IN : search_selected(%s)", str); if(selection_mode <= SELECTION_DO_NOTHING) { LOG(LOG_DEBUG, "OUT : search_selected() = NOP1"); return; } if(strcmp(previous, str) == 0){ // Do nothing if the word is the save as before. LOG(LOG_DEBUG, "same as before"); ; } else { euc_str = iconv_convert("utf-8", "euc-jp", str); if(validate_euc_str(euc_str) == FALSE) { g_free(euc_str); LOG(LOG_DEBUG, "OUT : search_selected() = INVALID"); return; } remove_space(euc_str); len = g_utf8_strlen(str, -1); if((auto_minchar <= len) && (len <= auto_maxchar)) { gtk_entry_set_text(GTK_ENTRY(word_entry), str); method = ebook_search_method(); if((method == SEARCH_METHOD_INTERNET) || (method == SEARCH_METHOD_MULTI) || (method == SEARCH_METHOD_FULL_TEXT)){ LOG(LOG_DEBUG, "OUT : search_selected() = NOP2"); return; } if(selection_mode <= SELECTION_COPY_ONLY) { LOG(LOG_DEBUG, "OUT : search_selected() = COPY"); return; } clear_message(); clear_search_result(); if(method == SEARCH_METHOD_GREP){ grep_search(euc_str); show_result_tree(); select_first_item(); if(selection_mode == SELECTION_SEARCH_TOP) bring_to_top(main_window); save_word_history(str); } else { ebook_search_auto(euc_str, method); show_result_tree(); if(search_result){ if(selection_mode == SELECTION_POPUP) { show_result_in_popup(); } else { select_first_item(); if(selection_mode == SELECTION_SEARCH_TOP) bring_to_top(main_window); } save_word_history(str); } else { current_in_result = NULL; set_current_result(NULL); if(selection_mode == SELECTION_POPUP) { beep(); } else { if(selection_mode == SELECTION_SEARCH_TOP) bring_to_top(main_window); push_message(_("No hit.")); } } } sprintf(previous, "%s", str); } else { LOG(LOG_DEBUG, "OUT : search_selected() = LENGTH"); } g_free(euc_str); } LOG(LOG_DEBUG, "OUT : search_selected()"); }
static int procline(str_t *l, int nottext) { regmatch_t pmatch; int c, i, r; regoff_t offset; /* size_t will be converted to regoff_t. ssize_t is guaranteed to fit * into regoff_t */ if (l->len > SSIZE_MAX) { errx(2, "Line is too big to process"); } c = 0; i = 0; if (matchall) { c = 1; goto print; } for (i = 0; i < patterns; i++) { offset = 0; redo: if (fg_pattern[i].pattern) { r = grep_search(&fg_pattern[i], l->dat + offset, l->len - offset, &pmatch); pmatch.rm_so += offset; pmatch.rm_eo += offset; } else { pmatch.rm_so = offset; pmatch.rm_eo = l->len; r = regexec(&r_pattern[i], l->dat, 1, &pmatch, eflags); } if (r == 0 && xflag) { if (pmatch.rm_so != 0 || pmatch.rm_eo != l->len) r = REG_NOMATCH; } if (r == 0) { c = 1; if (oflag && pmatch.rm_so != pmatch.rm_eo) goto print; break; } } if (oflag) return c; print: if (vflag) c = !c; if (c && binbehave == BIN_FILE_BIN && nottext) return c; /* Binary file */ if ((tail > 0 || c) && !cflag && !qflag) { if (c) { if (first > 0 && tail == 0 && (Bflag < linesqueued) && (Aflag || Bflag)) printf("--\n"); first = 1; tail = Aflag; if (Bflag > 0) printqueue(); linesqueued = 0; printline(l, ':', oflag ? &pmatch : NULL); } else { printline(l, '-', oflag ? &pmatch : NULL); tail--; } } if (oflag && !matchall) { offset = pmatch.rm_eo; goto redo; } return c; }