📄 srch_rep.c
字号:
value2 = value - ('a' - 'A'); else value2 = value; return(value2);}int search_prompt(flag) /* prompt and read search string (srch_str) */int flag;{ char *tmp_srch; char *srch_1; char *srch_3;#ifndef XAE tmp_srch = get_string(search_prompt_str, FALSE);#else if (flag) tmp_srch = get_string(search_prompt_str, FALSE); else { tmp_srch = xalloc(strlen(xsrch_string) + 1); copy_str(xsrch_string, tmp_srch); }#endif /* ifndef XAE */ if (*tmp_srch != (char) NULL) { if (srch_str != NULL) free(srch_str); srch_3 = srch_str = tmp_srch; if (u_srch_str != NULL) free(u_srch_str); srch_1 = u_srch_str = xalloc(strlen(srch_str) + 1); while (*srch_3 != (char) NULL) /* make upper case version of string */ { *srch_1 = toupper(*srch_3); srch_1++; srch_3++; } *srch_1 = (char) NULL; if (strlen(srch_str) >= 1) value = search(TRUE, curr_buff->curr_line, curr_buff->position, curr_buff->pointer, 0, FALSE, TRUE); } return(0);}void replace() /* replace the given one string with another */{ int counter; int i, j; int chng_all; /* change all occurrences */ int go_on; /* continue to replace */ int t_vert; /* temporary vertical position */ int t_horz; /* temporary horizontal position */ int s_flag; /* temporary select flag */ int t_posit; /* temporary position */ int t_pos; /* temporary abs_pos */ int temp_flag; /* temp storage for value of overstrike */ int temp_abs_line; /* keep track of original absolute line */ char *pnt; /* temporary pointer */ char *t_srch_str; /* temp search string */ char *ut_srch_str; /* upper case search string */ char *response; /* response from user */ char *del_strg; /* string deleted from line */ char res; /* value to hold response */ struct text *t_line; /* temp pointer to hold curr_buff->curr_line *//* continue to look for occurrences while go_on is true, if chng_all is true, do not prompt user whether or not to change*/ temp_abs_line = curr_buff->absolute_lin; temp_flag = overstrike; overstrike = FALSE; s_flag = mark_text; mark_text = FALSE; t_pos = curr_buff->scr_pos; t_srch_str = srch_str; ut_srch_str = u_srch_str; t_posit = curr_buff->position; t_line = curr_buff->curr_line; t_vert = curr_buff->scr_vert; t_horz = curr_buff->scr_horz; go_on = TRUE; u_srch_str = u_old_string; srch_str = old_string; chng_all = FALSE; while (go_on) { if (search(TRUE, curr_buff->curr_line, curr_buff->position, curr_buff->pointer, 0, FALSE, TRUE)) { wstandout(curr_buff->win); if (curr_buff->position == curr_buff->curr_line->line_length) waddch(curr_buff->win, ' '); else if ((*curr_buff->pointer >= ' ') && (*curr_buff->pointer < 127)) waddch(curr_buff->win, *curr_buff->pointer); else value = out_char(curr_buff->win, *curr_buff->pointer, curr_buff->scr_pos, curr_buff->scr_vert, 0); wstandend(curr_buff->win); wrefresh(curr_buff->win); if (!chng_all) { response = get_string(replace_action_prompt, TRUE); if (toupper(*response) == toupper(*replace_all_char)) chng_all = TRUE; else if (toupper(*response) == toupper(*quit_char)) go_on = FALSE; res = *response; free(response); } wmove(curr_buff->win, curr_buff->scr_vert, curr_buff->scr_horz); if ((*curr_buff->pointer >= ' ') && (*curr_buff->pointer < 127)) waddch(curr_buff->win, *curr_buff->pointer); else value = out_char(curr_buff->win, *curr_buff->pointer, curr_buff->scr_pos, curr_buff->scr_vert, 0); if (((toupper(res) == toupper(*replace_r_char)) || (go_on) || (res == (char) NULL)) && (toupper(res) != toupper(*replace_skip_char))) { del_strg = del_string(repl_length - 1); counter = strlen(new_string) + 1; pnt = new_string; for (i = 1; i < counter; i++) { if ((!literal) && (*pnt == '&')) { undel_string(del_strg, (repl_length - 1)); for (j = 1; j < repl_length; j++) right(TRUE); } else if ((!literal) && ((*pnt == '\\') && (pnt[1] == '&'))) { i++; pnt++; insert(*pnt); } else insert(*pnt); pnt++; } if (!forward) { for (i = 1; i < counter; i++) left(TRUE); } free(del_strg); } } else go_on = FALSE; } u_srch_str = ut_srch_str; srch_str = t_srch_str; curr_buff->curr_line = t_line; curr_buff->pointer = curr_buff->curr_line->line; for (value = 1; value < t_posit; value++) curr_buff->pointer++; curr_buff->position = t_posit; curr_buff->abs_pos = curr_buff->scr_pos = t_pos; curr_buff->scr_vert = t_vert; curr_buff->scr_horz = t_horz; mark_text = s_flag; midscreen(curr_buff->scr_vert, curr_buff->position); werase(com_win); wrefresh(com_win); overstrike = temp_flag; curr_buff->absolute_lin = temp_abs_line;}int repl_prompt(flag) /* prompt for replace parameters */int flag;{ char *rparam; char *rp; char *start; char *upt; char delimiter; int last_char; int counter;#ifndef XAE rp = rparam = get_string(replace_prompt_str, TRUE);#else if (flag) rp = rparam = get_string(replace_prompt_str, TRUE); else { counter = strlen(xnew_string) + strlen(xold_string) + 2; if (counter > 2) { rp = rparam = xalloc(counter + 3); *rp = '\33'; rp++; copy_str(xold_string, rp); while (*rp != (char) NULL) rp++; *rp = '\33'; rp++; copy_str(xnew_string, rp); while (*rp != (char) NULL) rp++; *rp = '\33'; rp++; *rp = (char) NULL; rp = rparam; } else rp = "\000"; }#endif /* ifndef XAE */ delimiter = *rp; if (*rp != (char) NULL) { ++rp; start = rp; counter = 1; while ((*rp != delimiter) && (*rp != (char) NULL)) { counter++; rp++; } if (*rp == (char) NULL) last_char = TRUE; else { last_char = FALSE; *rp = (char) NULL; } if (old_string != NULL) { free(old_string); free(new_string); free(u_old_string); } old_string = xalloc(counter); u_old_string = xalloc(counter); copy_str(start, old_string); upt = u_old_string; while (*start != (char) NULL) { *upt = toupper(*start); upt++; start++; } *upt = (char) NULL; if (!last_char) start = ++rp; counter = 1; while ((*rp != delimiter) && (*rp != (char) NULL)) { counter++; rp++; } *rp = (char) NULL; new_string = xalloc(counter); copy_str(start, new_string); free(rparam); if (strlen(old_string) >= 1) replace(); } return(0);}void match() /* find the matching (), {}, or [] */{ int level; /* level of nesting */ int t_vert; /* temporary vertical position */ int t_horz; /* temporary horizontal position */ int s_flag; /* temporary select flag */ int t_posit; /* temporary position */ int t_pos; /* temporary abs_pos */ int mforward; /* temporary storage of true forward */ int mliteral; /* temp storage of true literal value */ int total_lines; /* sum of lines moved */ int temp_abs_line; /* keep track of original line */ char curr_char; /* the current character */ char *t_srch_str; /* temp search string */ char *ut_srch_str; /* upper case search string */ char *direction; /* direction in which to move */ struct text *t_line; /* temp pointer to hold curr_buff->curr_line */ if ((*curr_buff->pointer == '{') || (*curr_buff->pointer == '}') || (*curr_buff->pointer == '(') || (*curr_buff->pointer == ')') || (*curr_buff->pointer == '[') || (*curr_buff->pointer == ']') || (*curr_buff->pointer == '<') || (*curr_buff->pointer == '>')) { temp_abs_line = curr_buff->absolute_lin; curr_char = *curr_buff->pointer; mliteral = literal; mforward = forward; literal = FALSE; if ((*curr_buff->pointer == '{') || (*curr_buff->pointer == '(') || (*curr_buff->pointer == '[') || (*curr_buff->pointer == '<')) /* provide matches for quoted characters - > ] ) } */ { direction = "d"; forward = TRUE; } else { direction = "u"; forward = FALSE; } s_flag = mark_text; mark_text = FALSE; t_pos = curr_buff->scr_pos; t_srch_str = srch_str; ut_srch_str = u_srch_str; t_posit = curr_buff->position; t_line = curr_buff->curr_line; t_vert = curr_buff->scr_vert; t_horz = curr_buff->scr_horz; if ((curr_char == '{') || (curr_char == '}')) srch_str = "[{}]"; if ((curr_char == '(') || (curr_char == ')')) srch_str = "[()]"; if ((curr_char == '<') || (curr_char == '>')) srch_str = "[<>]"; if ((curr_char == '[') || (curr_char == ']')) srch_str = "[\\[\\]]"; u_srch_str = srch_str; level = 1; total_lines = 0; while ((level > 0) && (search(FALSE, curr_buff->curr_line, curr_buff->position, curr_buff->pointer, 0, FALSE, TRUE))) { total_lines += lines_moved; curr_buff->curr_line = srch_line; curr_buff->pointer = start_of_string; curr_buff->position = tmp_pos; if (*start_of_string == curr_char) level++; else level--; } lines_moved = total_lines; curr_buff->curr_line = t_line; curr_buff->pointer = curr_buff->curr_line->line; for (value = 1; value < t_posit; value++) curr_buff->pointer++; curr_buff->position = t_posit; curr_buff->abs_pos = curr_buff->scr_pos = t_pos; curr_buff->scr_vert = t_vert; curr_buff->scr_horz = t_horz; mark_text = s_flag; if (level == 0) { if (lines_moved != 0) move_rel(direction, lines_moved); if ((lines_moved != 0) || (forward)) { while (curr_buff->position < tmp_pos) right(TRUE); } else if ((lines_moved == 0) && (!forward)) { while (curr_buff->position > tmp_pos) left(TRUE); } } else { clr_cmd_line = TRUE; wmove(com_win, 0, 0); wclrtoeol(com_win); wprintw(com_win, cant_find_match_str); wrefresh(com_win); curr_buff->absolute_lin = temp_abs_line; } u_srch_str = ut_srch_str; srch_str = t_srch_str; literal = mliteral; forward = mforward; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -