diff options
Diffstat (limited to 'edit.c')
-rw-r--r-- | edit.c | 196 |
1 files changed, 98 insertions, 98 deletions
@@ -29,7 +29,7 @@ #include "eval.h" #include "log.h" -static void insert_string __P ((char *arg)); +static void insert_string(char *arg); /* history buffer */ char *hist[MAX_HIST]; /* saved history lines */ @@ -71,16 +71,16 @@ edit_function internal_functions[] = { {(char *)0, (function_str)0 } }; -int lookup_edit_name __P2 (char *,name, char **,arg) +int lookup_edit_name(char *name, char **arg) { int i, len, flen; char *fname, *extra = NULL; - + if ((fname = strchr(name, ' '))) len = fname - name; else len = strlen(name); - + for (i=1; (fname = internal_functions[i].name); i++) { flen = strlen(fname); if (flen == len && !strncmp(name, fname, flen)) { @@ -95,20 +95,20 @@ int lookup_edit_name __P2 (char *,name, char **,arg) return 0; } -int lookup_edit_function __P1 (function_str,funct) +int lookup_edit_function(function_str funct) { int i; function_str ffunct; - + for (i = 1; (ffunct = internal_functions[i].funct); i++) if (funct == ffunct) return i; - + return 0; } /* return pointer to any unterminated escape code at the end of s */ -static char *find_partial_esc __P1 (char *,s) +static char *find_partial_esc(char *s) { size_t len = strlen(s); char *end = s + len; @@ -126,7 +126,7 @@ static char *find_partial_esc __P1 (char *,s) * redisplay the prompt * assume cursor is at beginning of line */ -void draw_prompt __P0 (void) +void draw_prompt(void) { if (promptlen && prompt_status == 1) { char *esc, *pstr; @@ -154,11 +154,11 @@ void draw_prompt __P0 (void) /* * clear current input line (deleteprompt == 1 if to clear also prompt) * cursor is left right after the prompt. - * + * * since we do not expect data from the user at this point, * do not print edattrbeg now. */ -void clear_input_line __P1 (int,deleteprompt) +void clear_input_line(int deleteprompt) { /* * be careful: if prompt and/or input line have been erased from screen, @@ -167,7 +167,7 @@ void clear_input_line __P1 (int,deleteprompt) if ((edlen && line_status == 0) || (promptlen && prompt_status == 0 && deleteprompt)) { int newcol = deleteprompt ? 0 : col0; int realpos = line_status == 0 ? pos : (prompt_status == 0 ? 0 : -col0); - + tty_gotoxy_opt(CURCOL(realpos), CURLINE(realpos), newcol, line0); tty_puts(edattrend); if (line0 < lines - 1) @@ -187,7 +187,7 @@ void clear_input_line __P1 (int,deleteprompt) /* * clear input line, but do nothing else */ -void clear_line __P1 (char *,dummy) +void clear_line(char *dummy) { if (!edlen) return; @@ -201,15 +201,15 @@ void clear_line __P1 (char *,dummy) * Redraw the input line and put the cursor at the current position. * The cursor is assumed to be directly after the prompt. */ -void draw_input_line __P0 (void) +void draw_input_line(void) { int i, oldline0; - + if (line_status == 0 || linemode & LM_NOECHO) return; - + tty_puts(edattrbeg); - + if (edlen) { oldline0 = line0; if (edlen < cols_1 - col0) { @@ -218,7 +218,7 @@ void draw_input_line __P0 (void) tty_printf("%.*s", cols_1 - col0, edbuf); for (i = cols_1 - col0; i <= edlen; i += cols_1) { #ifdef BUG_ANSI - if (edattrbg) + if (edattrbg) tty_printf("%s\n%s%.*s", edattrend, edattrbeg, cols_1, edbuf + i); else #endif @@ -240,7 +240,7 @@ void draw_input_line __P0 (void) /* * redraw the input line */ -void redraw_line __P1 (char *,dummy) +void redraw_line(char *dummy) { clear_input_line(1); } @@ -248,7 +248,7 @@ void redraw_line __P1 (char *,dummy) /* * redraw the input line, clearing the prompt */ -void redraw_line_noprompt __P1 (char *,dummy) +void redraw_line_noprompt(char *dummy) { clear_input_line(0); tty_putc('\n'); @@ -260,32 +260,32 @@ void redraw_line_noprompt __P1 (char *,dummy) /* * GH: transpose two words to the left */ -void transpose_words __P1 (char *,dummy) +void transpose_words(char *dummy) { /* other refers to the word to the left, this is the one we are at */ - + int this_so, other_so, this_eo, other_eo; char buf[BUFSIZE]; int n; - + if (pos > 2) { - + this_eo = this_so = pos; /* optionally traceback to find a word */ while (this_so && strchr(DELIM, edbuf[this_so])) this_so--; - + /* now find where the current word ends */ while (this_eo < edlen && !strchr(DELIM, edbuf[this_eo])) this_eo++; - + /* found a word; now find its start */ while (this_so > 0 && !strchr(DELIM, edbuf[this_so - 1])) this_so--; - + if (this_so < 2) return; /* impossible that there's another word */ - + other_so = this_so - 1; while (other_so >= 0 && strchr(DELIM, edbuf[other_so])) other_so--; @@ -294,12 +294,12 @@ void transpose_words __P1 (char *,dummy) other_eo = other_so + 1; while (other_so > 0 && !strchr(DELIM, edbuf[other_so - 1])) other_so--; - + sprintf(buf, "%.*s%.*s%.*s", - this_eo - this_so, edbuf + this_so, + this_eo - this_so, edbuf + this_so, this_so - other_eo, edbuf + other_eo, other_eo - other_so, edbuf + other_so); - + input_moveto(other_so); for (n = 0; buf[n]; input_overtype_follow(buf[n++])) ; @@ -309,7 +309,7 @@ void transpose_words __P1 (char *,dummy) /* * transpose two characters to the left */ -void transpose_chars __P1 (char *,dummy) +void transpose_chars(char *dummy) { int i, j; char c; @@ -322,7 +322,7 @@ void transpose_chars __P1 (char *,dummy) i = pos - 2; } c = edbuf[j]; edbuf[j] = edbuf[i]; edbuf[i] = c; - + if (line_status == 0) { tty_gotoxy_opt(CURCOL(pos), CURLINE(pos), CURCOL(i), CURLINE(i)); tty_putc(edbuf[i]); @@ -340,12 +340,12 @@ void transpose_chars __P1 (char *,dummy) /* * erase everything to the end of line */ -void kill_to_eol __P1 (char *,dummy) +void kill_to_eol(char *dummy) { if (line_status == 0) { - if (edattrbg) + if (edattrbg) tty_printf("%s%s", edattrend, tty_clreoln); - else + else tty_puts(tty_clreoln); if (CURLINE(edlen) > CURLINE(pos)) { tty_printf("\n%s", tty_clreoscr); @@ -360,7 +360,7 @@ void kill_to_eol __P1 (char *,dummy) /* * move cursor to end of line */ -void end_of_line __P1 (char *,dummy) +void end_of_line(char *dummy) { input_moveto(edlen); } @@ -368,7 +368,7 @@ void end_of_line __P1 (char *,dummy) /* * move cursor to beginning of line */ -void begin_of_line __P1 (char *,dummy) +void begin_of_line(char *dummy) { input_moveto(0); } @@ -376,7 +376,7 @@ void begin_of_line __P1 (char *,dummy) /* * delete a character to the right */ -void del_char_right __P1 (char *,dummy) +void del_char_right(char *dummy) { input_delete_nofollow_chars(1); } @@ -384,7 +384,7 @@ void del_char_right __P1 (char *,dummy) /* * delete a character to the left */ -void del_char_left __P1 (char *,dummy) +void del_char_left(char *dummy) { if (pos) { input_moveto(pos-1); @@ -395,7 +395,7 @@ void del_char_left __P1 (char *,dummy) /* * move a line into history, but don't do anything else */ -void to_history __P1 (char *,dummy) +void to_history(char *dummy) { if (!edlen) return; @@ -410,7 +410,7 @@ void to_history __P1 (char *,dummy) * put string in history at current position * (string is assumed to be trashable) */ -void put_history __P1 (char *,str) +void put_history(char *str) { char *p; if (hist[curline]) free(hist[curline]); @@ -418,14 +418,14 @@ void put_history __P1 (char *,str) errmsg("malloc"); return; } - + if (++curline == MAX_HIST) curline = 0; - + /* split into words and put into completion list */ - for (p = strtok(str, DELIM); p; + for (p = strtok(str, DELIM); p; p = strtok(NULL, DELIM)) { - if (strlen(p) >= MIN_WORDLEN && + if (strlen(p) >= MIN_WORDLEN && p[0] != '#') /* no commands/short words */ put_word(p); } @@ -434,7 +434,7 @@ void put_history __P1 (char *,str) /* * move a node before wordindex, i.e. make it the last word */ -static void demote_word __P1 (int,i) +static void demote_word(int i) { words[words[i].prev].next = words[i].next; words[words[i].next].prev = words[i].prev; @@ -447,7 +447,7 @@ static struct { char **words; } static_words; -static int compl_next_word __P1 (int,i) +static int compl_next_word(int i) { if (i < 0) { go_static: @@ -464,7 +464,7 @@ static int compl_next_word __P1 (int,i) return i; } -static char *compl_get_word __P1 (int,i) +static char *compl_get_word(int i) { return i < 0 ? static_words.words[-i - 1] : words[i].word; } @@ -472,7 +472,7 @@ static char *compl_get_word __P1 (int,i) /* * match and complete a word referring to the word list */ -void complete_word __P1 (char *,dummy) +void complete_word(char *dummy) { /* * GH: rewritten to allow circulating through history with @@ -482,12 +482,12 @@ void complete_word __P1 (char *,dummy) * comp_len length of current completition * root_len length of the root word (before the completition) * root start of the root word - */ - + */ + static int curr_word, comp_len = 0, root_len = 0; char *root, *p; int k, n; - + /* find word start */ if (last_edit_cmd == (function_any)complete_word && comp_len) { k = comp_len; @@ -501,9 +501,9 @@ void complete_word __P1 (char *,dummy) root_len = pos - n; } root = edbuf + n; comp_len = 0; - + /* k = chars to delete, n = position of starting word */ - + /* scan word list for next match */ while ((p = compl_get_word(curr_word = compl_next_word(curr_word)))) { if (!strncasecmp(p, root, root_len) && @@ -519,12 +519,12 @@ void complete_word __P1 (char *,dummy) } if (k > 0) input_delete_nofollow_chars(k); - + /* delete duplicate instances of the word */ if (p && curr_word >= 0 && !(words[k = curr_word].flags & WORD_UNIQUE)) { words[k].flags |= WORD_UNIQUE; - p = words[k].word; + p = words[k].word; n = words[k].next; while (words[k = n].word) { n = words[k].next; @@ -544,16 +544,16 @@ void complete_word __P1 (char *,dummy) * match and complete entire lines backwards in history * GH: made repeated complete_line cycle through history */ -void complete_line __P1 (char *,dummy) +void complete_line(char *dummy) { static int curr_line = MAX_HIST-1, root_len = 0, first_line = 0; int i; - + if (last_edit_cmd != (function_any)complete_line) { root_len = edlen; first_line = curr_line = curline; } - + for (i = curr_line - 1; i != curr_line; i--) { if (i < 0) i = MAX_HIST - 1; if (i == first_line) @@ -579,7 +579,7 @@ void complete_line __P1 (char *,dummy) * GH: word history handling stolen from cancan 2.6.3a */ -static void default_completions __P0 (void) +static void default_completions(void) { char buf[BUFSIZE]; cmdstruct *p; @@ -598,7 +598,7 @@ static void default_completions __P0 (void) words[MAX_WORDS - 1].next = 0; } -void put_static_word __P1 (char *,s) +void put_static_word(char *s) { if (static_words.used >= static_words.size) { do { @@ -619,7 +619,7 @@ void put_static_word __P1 (char *,s) /* * put word in word completion ring */ -void put_word __P1 (char *,s) +void put_word(char *s) { int r = wordindex; if (!(words[r].word = my_strdup(s))) { @@ -630,16 +630,16 @@ void put_word __P1 (char *,s) r = words[r].prev; demote_word(r); wordindex = r; - if (words[r].word) { - free(words[r].word); - words[r].word = 0; + if (words[r].word) { + free(words[r].word); + words[r].word = 0; } } /* * GH: set delimeters[DELIM_CUSTOM] */ -void set_custom_delimeters __P1 (char *,s) +void set_custom_delimeters(char *s) { char *old = delim_list[DELIM_CUSTOM]; if (!(delim_list[DELIM_CUSTOM] = my_strdup(s))) @@ -655,10 +655,10 @@ void set_custom_delimeters __P1 (char *,s) /* * enter a line */ -void enter_line __P1 (char *,dummy) +void enter_line(char *dummy) { char *p; - + if (line_status == 0) input_moveto(edlen); else { @@ -667,21 +667,21 @@ void enter_line __P1 (char *,dummy) draw_input_line(); } PRINTF("%s\n", edattrend); - + line0 = CURLINE(edlen); if (line0 < lines - 1) line0++; - + if (recordfile) fprintf(recordfile, "%s\n", edbuf); - + col0 = error = pos = line_status = 0; - + if (!*edbuf || (verbatim && *edbuf != '#')) tcp_write(tcp_fd, edbuf); else - parse_user_input(edbuf, 1); + parse_user_input(edbuf, 1); history_done = 0; - + /* don't put identical lines in history, nor empty ones */ p = hist[curline ? curline - 1 : MAX_HIST - 1]; if (!p || (edlen > 0 && strcmp(edbuf, p))) @@ -702,7 +702,7 @@ void enter_line __P1 (char *,dummy) /* * move one word forward */ -void next_word __P1 (char *,dummy) +void next_word(char *dummy) { int i; for (i = pos; edbuf[i] && !isalnum(edbuf[i]); i++) @@ -715,7 +715,7 @@ void next_word __P1 (char *,dummy) /* * move one word backward */ -void prev_word __P1 (char *,dummy) +void prev_word(char *dummy) { int i; for (i = pos; i && !isalnum(edbuf[i - 1]); i--) @@ -728,7 +728,7 @@ void prev_word __P1 (char *,dummy) /* * delete word to the right */ -void del_word_right __P1 (char *,dummy) +void del_word_right(char *dummy) { int i; for (i = pos; edbuf[i] && !isalnum(edbuf[i]); i++) @@ -741,7 +741,7 @@ void del_word_right __P1 (char *,dummy) /* * delete word to the left */ -void del_word_left __P1 (char *,dummy) +void del_word_left(char *dummy) { int i; for (i = pos; i && !isalnum(edbuf[i - 1]); i--) @@ -756,11 +756,11 @@ void del_word_left __P1 (char *,dummy) /* * GH: make word upcase */ -void upcase_word __P1 (char *,dummy) +void upcase_word(char *dummy) { int opos = pos; int npos = pos; - + if (last_edit_cmd == (function_any)upcase_word) npos = 0; else { @@ -777,7 +777,7 @@ void upcase_word __P1 (char *,dummy) /* * GH: make word downcase */ -void downcase_word __P1 (char *,dummy) +void downcase_word(char *dummy) { int opos = pos; int npos = pos; @@ -799,7 +799,7 @@ void downcase_word __P1 (char *,dummy) /* * get previous line from history list */ -void prev_line __P1 (char *,dummy) +void prev_line(char *dummy) { int i = pickline - 1; if (i < 0) i = MAX_HIST - 1; @@ -824,7 +824,7 @@ void prev_line __P1 (char *,dummy) /* * get next line from history list */ -void next_line __P1 (char *,dummy) +void next_line(char *dummy) { int i = pickline + 1; if (i == MAX_HIST) i = 0; @@ -849,7 +849,7 @@ void next_line __P1 (char *,dummy) /* * move one char backward */ -void prev_char __P1 (char *,dummy) +void prev_char(char *dummy) { input_moveto(pos-1); } @@ -857,7 +857,7 @@ void prev_char __P1 (char *,dummy) /* * move one char forward */ -void next_char __P1 (char *,dummy) +void next_char(char *dummy) { input_moveto(pos+1); } @@ -865,7 +865,7 @@ void next_char __P1 (char *,dummy) /* * Flash cursor at parentheses that matches c inserted before current pos */ -static void flashparen __P1 (char,c) +static void flashparen(char c) { int lev, i; if (line_status != 0) @@ -893,7 +893,7 @@ static void flashparen __P1 (char,c) /* * put cursor back where it belongs */ -void putbackcursor __P0 (void) +void putbackcursor(void) { if (line_status == 0) tty_gotoxy_opt(CURCOL(excursion), CURLINE(excursion), CURCOL(pos), CURLINE(pos)); @@ -903,7 +903,7 @@ void putbackcursor __P0 (void) /* * insert a typed character on screen (if it is printable) */ -void insert_char __P1 (char,c) +void insert_char(char c) { if (((c & 0x80) || (c >= ' ' && c <= '~')) && edlen < BUFSIZE - 2) { if (flashback) putbackcursor(); @@ -913,18 +913,18 @@ void insert_char __P1 (char,c) } } -static void insert_string __P1 (char *,arg) +static void insert_string(char *arg) { char buf[BUFSIZE]; int len; - + if (!arg || !*arg) return; - + my_strncpy(buf, arg, BUFSIZE-1); unescape(buf); len = strlen(buf); - + if (len > 1) { if (flashback) putbackcursor(); input_insert_follow_chars(buf, len); @@ -935,25 +935,25 @@ static void insert_string __P1 (char *,arg) /* * execute string as if typed */ -void key_run_command __P1 (char *,cmd) +void key_run_command(char *cmd) { clear_input_line(opt_compact && !opt_keyecho); if (opt_keyecho) { tty_printf("%s%s%s\n", edattrbeg, cmd, edattrend); } else if (!opt_compact) tty_putc('\n'); - + status(1); error = 0; - + if (recordfile) fprintf(recordfile, "%s\n", edbuf); - + parse_instruction(cmd, 1, 0, 1); history_done = 0; } -void edit_bootstrap __P0 (void) +void edit_bootstrap(void) { default_completions(); } |