📄 findrep.c
字号:
len_s -= *offset; for (;;) { /* * Boyer-Moore fast skip loop. check character count as we move * down the line. */ for (s+=i, len_s-=i; len_s > 0 && (i = skip[*s],i); s+=i, len_s-=i); if (len_s > 0) { /* * i == 0, possible match. Boyer-Moore slow match loop. */ if (mode.search_case == MATCH) { if (s[guard] != mini_guard) goto shift_func; q = s + 1 - pat_len; for (i=0; i < pat_len; i++) if (q[i] != p[i]) goto shift_func; } else { if ((unsigned int)bj_tolower( s[guard] ) != mini_guard) goto shift_func; q = s + 1 - pat_len; for (i=0; i < pat_len; i++) if (bj_tolower( q[i] ) != bj_tolower( p[i] )) goto shift_func; } *offset = (int)(q - ll->line); assert( *offset <= ll->len - pat_len ); if (g_status.search & SEARCH_RESULTS) { if (!add_search_line( ll, *rline, *offset )) return( NULL ); len_s = 0; } else { found_len = pat_len; return( ll ); } }shift_func: if (len_s <= 0) { ll = ll->next; if (ll->len == EOF) return( NULL ); ++*rline; i = pat_len - 1; s = ll->line; len_s = ll->len; if ((g_status.search & SEARCH_BLOCK) && (file->block_type == BOX || (file->block_type == STREAM && *rline == file->block_er && file->block_ec != -1))) { bc = file->block_bc; ec = file->block_ec; if (file->inflate_tabs) { bc = entab_adjust_rcol( s, len_s, bc, file->ptab_size ); ec = entab_adjust_rcol( s, len_s, ec, file->ptab_size ); } if (bc > len_s) bc = len_s; if (ec >= len_s) ec = len_s - 1; if (file->block_type == STREAM) len_s = ec + 1; else { s += bc; len_s = ec - bc + 1; } } } else i = mini_delta2; }}/* * Name: search_backward * Purpose: search backward for pattern using boyer array * Passed: ll: pointer to node in linked list to start search * rline: pointer to real line counter * offset: offset into ll->line to start search * Returns: position in file if found else return NULL * Date: January 8, 1992 * Notes: Start searching from cursor position to beginning of file. * mini delta2 is the first rightmost occurrence of the leftmost char. */line_list_ptr search_backward( line_list_ptr ll, long *rline, int *offset ){register int i;text_ptr p;int mini_delta2;int pat_len;int len_s;text_ptr s;file_infos *file;int bc, ec; if (ll == NULL || ll->len == EOF) return( NULL ); mini_delta2 = bm.backward_md2; pat_len = bm.pattern_length; p = bm.pattern; i = 1 - pat_len; file = g_status.current_file; s = ll->line; len_s = ll->len; if ((g_status.search & SEARCH_BLOCK) && (file->block_type == BOX || (file->block_type == STREAM && (*rline == file->block_br || (*rline == file->block_er && file->block_ec != -1))))) { bc = file->block_bc; ec = (file->block_ec == -1) ? len_s : file->block_ec; if (file->inflate_tabs) { bc = entab_adjust_rcol( s, len_s, bc, file->ptab_size ); if (file->block_ec != -1) ec = entab_adjust_rcol( s, len_s, ec, file->ptab_size ); } if (bc > len_s) bc = len_s; if (ec >= len_s) ec = len_s - 1; if (file->block_type == STREAM) { if (*rline == file->block_er) { if (*offset > ec) *offset = ec; len_s = *offset + 1; } if (*rline == file->block_br) { if (*offset < bc) return( NULL ); len_s = *offset - bc + 1; } s += *offset; } else { if (*offset > ec) *offset = ec; s += *offset; len_s = *offset - bc + 1; } } else { if (s != NULL) { /* jmh (23/11/97) - prevents an empty */ s += *offset; /* last line from crashing when search- */ len_s = *offset + 1; /* ing for one character. */ } else len_s = 0; } for (;;) { /* * Boyer-Moore fast skip loop. check character count as we move * down the line. */ for (s+=i, len_s+=i; len_s > 0 && (i = bm.skip_backward[*s],i); s+=i, len_s+=i); if (len_s > 0) { /* * i == 0, possible match. Boyer-Moore slow match loop. */ if (mode.search_case == MATCH) { for (i=0; i < pat_len; i++) if (s[i] != p[i]) goto shift_func; } else { for (i=0; i < pat_len; i++) if (bj_tolower( s[i] ) != bj_tolower( p[i] )) goto shift_func; } *offset = (int)(s - ll->line); assert( *offset <= ll->len - pat_len ); if (g_status.search & SEARCH_RESULTS) { if (!add_search_line( ll, *rline, *offset )) return( NULL ); len_s = 0; } else { found_len = pat_len; return( ll ); } }shift_func: if (len_s <= 0) { ll = ll->prev; if (ll->len == EOF) return( NULL ); --*rline; i = 1 - pat_len; len_s = ll->len; s = ll->line + len_s - 1; if ((g_status.search & SEARCH_BLOCK) && (file->block_type == BOX || (file->block_type == STREAM && *rline == file->block_br))) { bc = file->block_bc; ec = (file->block_ec == -1) ? 0 : file->block_ec; if (file->inflate_tabs) { bc = entab_adjust_rcol( s, len_s, bc, file->ptab_size ); ec = entab_adjust_rcol( s, len_s, ec, file->ptab_size ); } if (bc > len_s) bc = len_s; if (ec >= len_s) ec = len_s - 1; if (file->block_type == STREAM) len_s -= bc; else { s = ll->line + ec; len_s = ec - bc + 1; } } } else i = mini_delta2; }}/* * Name: show_search_message * Purpose: display search status * Date: January 8, 1992 * Passed: i: index into message array * jmh 980816: included the non-search messages (diff and next key). * removed color parameter. * jmh 991120: added the undo messages. */void show_search_message( int i ){ /* * 0 = blank * 1 = wrapped... * 2 = searching * 3 = replacing * 4 = nfa choked * 5 = diffing... * 6 = Next Key.. * 7 = undo one * 8 = undo group * 9 = undo place * 10 = undo move * 11 = tallying.. * 12 = changed * 13 = sorting... */ assert( i >= 0 && i <= 13); s_output( find7[i], g_display.mode_line, 67, (i == CLR_SEARCH) ? ((g_status.search & SEARCH_I) ? Color( Help ) : Color( Mode )) : Color( Diag ) ); refresh( );}/* * Name: bin_offset_adjust * Purpose: modify bin_offset for a different line * Date: June 5, 1991 * Passed: window: pointer to current window * change: relative position from current rline * Notes: in binary mode, we keep an accurate count of the offset of the * cursor from the beginning of the file. */void bin_offset_adjust( TDE_WIN *window, long change ){line_list_ptr node; node = window->ll; if (change < 0) { do { node = node->prev; window->bin_offset -= node->len; } while (++change != 0); } else if (change > 0) { if (node->len == EOF) ++window->bin_offset; do { window->bin_offset += node->len; node = node->next; } while (--change != 0); } assert( window->bin_offset >= 0 );}/* * Name: find_adjust * Purpose: place cursor on screen given a position in file - default cline * Date: June 5, 1991 * Passed: window: pointer to current window * ll: position anywhere in file * rline: real line number of ll in the file * rcol: real column of ll in the file * Notes: ll could be anywhere in file. Find the start of line that * ll is on. Determine if start of line is behind or ahead of * current line. Once that is done, it is easy to determine if ll * is on screen. Lastly, current cursor position becomes start of * ll line - reposition and display. * * jmh 991125: call bin_offset_adjust(). */void find_adjust( TDE_WIN *window, line_list_ptr ll, long rline, int rcol ){long test_line;file_infos *file;register TDE_WIN *win; /* put window pointer in a register */int tabs; win = window; file = win->file_info; /* * move the cursor to the line; if it's off-screen, center it. */ test_line = rline - win->rline; if (test_line) { bin_offset_adjust( win, test_line ); win->rline = rline; win->ll = ll; if (labs( test_line ) >= g_display.end_line) { test_line = 0; file->dirty = LOCAL; } if (check_cline( win, win->cline + (int)test_line )) file->dirty = LOCAL; if (file->dirty == LOCAL) { if (g_status.command != ReplaceString || win->visible) center_window( win ); } } /* * given a real column, adjust for inflated tabs. */ if (file->inflate_tabs) tabs = file->ptab_size; else { tabs = 0; found_vlen = found_len; } if ((g_status.search & SEARCH_I) && !(g_status.search & SEARCH_BACK)) { /* * forward isearch leaves rcol at the end of the match */ found_rcol = rcol - found_len; if (tabs) { rcol = detab_adjust_rcol( ll->line, rcol, tabs ); found_rcol = detab_adjust_rcol( ll->line, found_rcol, tabs ); found_vlen = rcol - found_rcol; } } else { if (tabs) { found_vlen = detab_adjust_rcol( ll->line, rcol + found_len, tabs ); rcol = detab_adjust_rcol( ll->line, rcol, tabs ); found_vlen -= rcol; } found_rcol = rcol; } found_rline = rline; show_ruler_char( win ); check_virtual_col( win, rcol, rcol );}/* * Name: replace_string * Purpose: To set up and perform a replace operation. * Date: June 5, 1991 * Passed: window: pointer to current window * * jmh 991008: added block replace, start position. * jmh 991010: if no prompting, remember cursor position for tabs. * jmh 031027: fixed long-standing bug if wrap occurred before being found. * jmh 031120: fixed my solution to the above; * replace the match at the cursor first, not last. * jmh 031126: fix display bug after continuing the wrap, but then exiting; * replace across all files. * jmh 050709: only return ERROR on control-break. */int replace_string( TDE_WIN *window ){int block;int direction;int sub_len;int net_change;int finished;int use_prev_find;int rc;int rcol;int rcol_limit;int wrapped;char *answer;long found_line;long line_limit;line_list_ptr ll;TDE_WIN wp;TDE_WIN old_wp;register TDE_WIN *win; /* put window pointer in a register */line_list_ptr (*search_func)( TDE_WIN *, long *, int * ); win = window; if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR) return( ERROR ); check_block( NULL ); if (g
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -