📄 findrep.c
字号:
func = CopyWord; goto copy; case StringRight: case StringEndRight: func = CopyString; case CopyWord: case CopyString: copy: len = icopy_word( win, (first) ? 0 : len, (func == CopyString) ); new_string = TRUE + 1; display = TRUE; break; case BackSpace: if (len) { if (num) { if (rc == OK) { temp = *prev; *prev = pos[--num]; found_rline = prev->rline; found_rcol = fcol[num]; found_vlen = vlen[num]; goto_marker( win ); *prev = temp; } else found_rline = win->rline; display = TRUE; } rc = OK; bm.pattern[--len] = '\0'; build_boyer_array( ); if (len > max_len) s_output( (char *)bm.pattern + len - max_len, g_display.mode_line, ISEARCH, Color( Help ) ); else c_output( ' ', ISEARCH + len, g_display.mode_line, Color( Help ) ); refresh( ); } break; } } if (search) { found_rline = -1; fcol[num] = found_rcol; vlen[num] = found_vlen; if ((rc = perform_search( win )) == OK) { display = TRUE; if (search == TRUE + 1) pos[num++] = *prev; } else { s_output( find18c, g_display.mode_line, (len > max_len) ? 67 : ISEARCH + len + 1, Color( Help ) ); search = FALSE; } } if (display) { if (win->file_info->dirty) { display_current_window( win ); win->file_info->dirty = FALSE; } else show_curl_line( win ); show_ruler( win ); show_ruler_pointer( win ); show_line_col( win ); xygoto( win->ccol, win->cline ); refresh( ); } first = FALSE; } add_to_history( (char *)bm.pattern, &h_find ); RESTORE_LINE( g_display.mode_line ); if (mode.search_case != scase) { mode.search_case = scase; toggle_search_case( win ); } g_status.search = 0; return( rc );}/* * Name: icopy_word * Purpose: copy a word/string for use with isearch * Author: Jason Hood * Date: October 29, 2002 * Passed: window: pointer to current window * len: length of current pattern * str: non-zero to copy a string * Returns: new length * Notes: adds the remainder of the current word/string to the search * pattern, or appends the next. * if len is zero, copy the complete word/string. * * 031120: fix bug when searching backwards (rcol at start, not end). */static int icopy_word( TDE_WIN *window, int len, int str ){text_ptr line = window->ll->line;int llen = window->ll->len;int rcol;int (*space)( int ); /* Function to determine what a word is */int begin; rcol = window->rcol; if (window->file_info->inflate_tabs) rcol = entab_adjust_rcol( line, llen, rcol, window->file_info->ptab_size ); if (g_status.search & SEARCH_BACK) rcol += len; if (rcol >= llen) return( len ); space = (str) ? bj_isspc : myiswhitespc; if (len == 0) { /* * no search string, find the start of the (next) word */ while (space( line[rcol] ) && ++rcol < llen) ; if (rcol == llen) return( len ); begin = rcol; while (--begin >= 0 && !space( line[begin] )) ; ++begin; } else { /* * if we're already at the end of the word, * find the start of the next. */ begin = rcol; while (space( line[rcol] ) && ++rcol < llen) ; if (rcol == llen) return( len ); } while (++rcol < llen && !space( line[rcol] )) ; llen = rcol - begin; if (len + llen >= MAX_COLS) llen = MAX_COLS - len - 1; my_memcpy( bm.pattern + len, line + begin, llen ); len += llen; bm.pattern[len] = '\0'; if (window->file_info->inflate_tabs) rcol = detab_adjust_rcol( line, rcol, window->file_info->ptab_size ); check_virtual_col( window, rcol, window->ccol + llen ); return( len );}/* * Name: perform_search * Purpose: do the search * Author: Jason Hood * Date: October 6, 1999 * Passed: window: pointer to current window * Returns: OK if found, ERROR if not. * Notes: ripped out of find_string() and modified to work with regx. * * jmh 021029: have isearch leave the cursor at the end of the match. * jmh 021211: isearch forward will leave the cursor at the end, backward * will leave it at the start; also allows backward/forward to * move between start/end of the match. */int perform_search( TDE_WIN *window ){long found_line;line_list_ptr ll;register TDE_WIN *win; /* put window pointer in a register */int rc;int old_rcol;int rcol;int dummy;int tabs = 0; rc = OK; win = window; if (((g_status.search & SEARCH_REGX) && regx.search_defined == OK) || bm.search_defined == OK) { old_rcol = win->rcol; if (win->file_info->inflate_tabs) { tabs = win->file_info->ptab_size; win->rcol = entab_adjust_rcol( win->ll->line, win->ll->len, win->rcol, tabs ); } if (g_status.search & SEARCH_I) { if (g_status.search & SEARCH_BACK) { if (g_status.search & SEARCH_BEGIN) win->rcol += bm.pattern_length; } else { if (g_status.search & SEARCH_BEGIN) win->rcol -= bm.pattern_length; else --win->rcol; } g_status.search &= ~SEARCH_BEGIN; } update_line( win ); show_search_message( SEARCHING ); /* * let search results include the current line */ if (g_status.search & SEARCH_RESULTS) { if (win->rline == 1) g_status.search |= SEARCH_BEGIN; else win->rcol = (g_status.search & SEARCH_BACK) ? MAX_LINE_LENGTH : -1; } first_win = win; search_file = first_file = win->file_info; if (g_status.search & SEARCH_BACK) ll = backward_search( win, &found_line, &rcol ); else ll = forward_search( win, &found_line, &rcol ); win->rcol = old_rcol; if (ll != NULL) { if (g_status.wrapped && g_status.macro_executing) rc = ask_wrap_replace( win, &dummy ); if (rc == OK) { if (search_file != win->file_info) { win = find_file_window( search_file ); change_window( window, win ); g_status.wrapped = ERROR; } undo_move( win, 0 ); set_marker( win ); /* remember the previous position */ if ((g_status.search & SEARCH_I) && !(g_status.search & SEARCH_BACK)) rcol += bm.pattern_length; find_adjust( win, ll, found_line, rcol ); } else g_status.wrapped = FALSE; } else if (g_status.wrapped && g_status.macro_executing && (g_status.current_macro->flag & NOWRAP)) g_status.wrapped = FALSE; if ((g_status.search & SEARCH_REGX) && nfa_status == ERROR) g_status.wrapped = TRUE; else show_search_message( (g_status.wrapped == ERROR) ? CHANGED : (g_status.wrapped && !(g_status.search & SEARCH_RESULTS)) ? WRAPPED : CLR_SEARCH ); if (ll == NULL) { if ((g_status.search & SEARCH_RESULTS) && results_window != NULL) change_window( g_status.current_window, results_window ); else { /* * string not found */ if (!(g_status.search & SEARCH_I)) { combine_strings( line_out, find5a, (g_status.search & SEARCH_REGX) ? (char*)regx.pattern : (char*)bm.pattern, find5b ); error( WARNING, win->bottom_line, line_out ); } rc = ERROR; } } if (!win->file_info->dirty) show_curl_line( win ); } else { /* * find pattern not defined */ error( WARNING, win->bottom_line, find6 ); rc = ERROR; } return( rc );}/* * Name: forward_search * Purpose: search forward for pattern * Passed: window: pointer to current window * rline: pointer to real line counter * rcol: pointer to real column variable * Returns: position in file if found or NULL if not found * Date: June 5, 1991 * Notes: Start searching from cursor position to end of file. If we hit * end of file without a match, start searching from the beginning * of file to cursor position. (do wrapped searches) * * jmh 991006: incorporated boyer_moore and regx into one function. * jmh 991007: added block search and beginning position. The block should * be defined before entry. * jmh 031126: added multi-file search (ignore non-file files; check for * search_file != window->file_info). */line_list_ptr forward_search( TDE_WIN *window, long *rline, int *rcol ){int end;register TDE_WIN *win; /* put window pointer in a register */file_infos *file;line_list_ptr ll;line_list_ptr (*search_func)( line_list_ptr, long *, int * ); win = window; file = win->file_info; *rcol = win->rcol + 1; /* assume a continuing search */ *rline = win->rline; ll = win->ll; end = 0; if (g_status.search & SEARCH_BLOCK) { if ((g_status.search & SEARCH_BEGIN) || win->rline < file->block_br || win->rline > file->block_er) { *rcol = 0; *rline = file->block_br; ll = file->block_start; g_status.search |= SEARCH_BEGIN; } end = file->block_end->next->len; file->block_end->next->len = EOF; } else { if (g_status.search & SEARCH_BEGIN) { *rcol = 0; *rline = 1L; ll = file->line_list->next; } } search_func = (g_status.search & SEARCH_REGX) ? regx_search_forward : search_forward; ll = search_func( ll, rline, rcol ); if (g_status.search & SEARCH_BLOCK) file->block_end->next->len = end; if (ll == NULL) { if (g_status.search & SEARCH_ALL) { do { search_file = search_file->next; if (search_file == NULL) search_file = g_status.file_list; if (search_file == first_file) break; if (search_file->file_name[0] == '\0') continue; *rline = 1L; *rcol = 0; ll = search_func( search_file->line_list->next, rline, rcol ); } while (ll == NULL); } if (ll == NULL && first_win->rline > 0 && !(g_status.search & SEARCH_BEGIN)) { if (g_status.search & SEARCH_ALL) { win = first_win; file = first_file; } if (g_status.search & SEARCH_RESULTS) { end = win->ll->len; win->ll->len = EOF; } else if (win->ll->next != NULL) { end = win->ll->next->len; win->ll->next->len = EOF; } /* * haven't found pattern yet - now search from beginning of file */ g_status.wrapped = TRUE; *rcol = 0; if (g_status.search & SEARCH_BLOCK) { *rline = file->block_br; ll = file->block_start; } else { *rline = 1L; ll = file->line_list->next; } ll = search_func( ll, rline, rcol ); if (ll == win->ll && *rcol >= win->rcol) ll = NULL; if (g_status.search & SEARCH_RESULTS) win->ll->len = end; else if (win->ll->next != NULL) win->ll->next->len = end; } } flush_keyboard( ); g_status.search &= ~SEARCH_BEGIN; return( ll );}/* * Name: backward_search * Purpose: search backward for pattern * Passed: window: pointer to current window * rline: pointer current real line counter * rcol: pointer to real column * Returns: position in file if found or NULL if not found * Date: June 5, 1991 * Notes: Start searching from cursor position to beginning of file. If we * hit beginning of file without a match, start searching from the * end of file to cursor position. (do wrapped searches) * * jmh 991006: incorporated boyer_moore and regx into one function. * jmh 991007: added block search and beginning position. The block should * be defined before entry. * jmh 031126: added multi-file search (ignore non-file files; check for
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -