diff options
Diffstat (limited to 'bin/ksh/emacs.c')
-rw-r--r-- | bin/ksh/emacs.c | 324 |
1 files changed, 118 insertions, 206 deletions
diff --git a/bin/ksh/emacs.c b/bin/ksh/emacs.c index 06a99627a2d..27a0ea623c6 100644 --- a/bin/ksh/emacs.c +++ b/bin/ksh/emacs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: emacs.c,v 1.31 2004/12/19 04:14:20 deraadt Exp $ */ +/* $OpenBSD: emacs.c,v 1.32 2004/12/20 11:34:26 otto Exp $ */ /* * Emacs-like command line editing and history @@ -109,34 +109,34 @@ static int x_curprefix; static char *macroptr; static int prompt_skip; -static int x_ins(char *cp); -static void x_delete(int nc, int push); +static int x_ins(char *); +static void x_delete(int, int); static int x_bword(void); static int x_fword(void); -static void x_goto(char *cp); -static void x_bs(int c); -static int x_size_str(char *cp); -static int x_size(int c); -static void x_zots(char *str); -static void x_zotc(int c); -static void x_load_hist(char **hp); -static int x_search(char *pat, int sameline, int offset); -static int x_match(char *str, char *pat); -static void x_redraw(int limit); -static void x_push(int nchars); -static char * x_mapin(const char *cp); -static char * x_mapout(int c); -static void x_print(int prefix, int key); +static void x_goto(char *); +static void x_bs(int); +static int x_size_str(char *); +static int x_size(int); +static void x_zots(char *); +static void x_zotc(int); +static void x_load_hist(char **); +static int x_search(char *, int, int); +static int x_match(char *, char *); +static void x_redraw(int); +static void x_push(int); +static char * x_mapin(const char *); +static char * x_mapout(int); +static void x_print(int, int); static void x_adjust(void); -static void x_e_ungetc(int c); +static void x_e_ungetc(int); static int x_e_getc(void); -static void x_e_putc(int c); -static void x_e_puts(const char *s); -static int x_comment(int c); -static int x_fold_case(int c); +static void x_e_putc(int); +static void x_e_puts(const char *); +static int x_comment(int); +static int x_fold_case(int); static char *x_lastcp(void); -static void do_complete(int flags, Comp_type type); -static int x_emacs_putbuf(const char *s, size_t len); +static void do_complete(int, Comp_type); +static int x_emacs_putbuf(const char *, size_t); /* The lines between START-FUNC-TAB .. END-FUNC-TAB are run through a @@ -307,9 +307,7 @@ static struct x_defbindings const x_defbindings[] = { }; int -x_emacs(buf, len) - char *buf; - size_t len; +x_emacs(char *buf, size_t len) { int c; const char *p; @@ -380,8 +378,7 @@ x_emacs(buf, len) } static int -x_insert(c) - int c; +x_insert(int c) { char str[2]; @@ -400,8 +397,7 @@ x_insert(c) } static int -x_ins_string(c) - int c; +x_ins_string(int c) { if (macroptr) { x_e_putc(BEL); @@ -418,9 +414,7 @@ x_ins_string(c) static int x_do_ins(const char *cp, int len); static int -x_do_ins(cp, len) - const char *cp; - int len; +x_do_ins(const char *cp, int len) { if (xep+len >= xend) { x_e_putc(BEL); @@ -435,8 +429,7 @@ x_do_ins(cp, len) } static int -x_ins(s) - char *s; +x_ins(char *s) { char *cp = xcp; int adj = x_adj_done; @@ -466,9 +459,7 @@ x_ins(s) * this is used for x_escape() in do_complete() */ static int -x_emacs_putbuf(s, len) - const char *s; - size_t len; +x_emacs_putbuf(const char *s, size_t len) { int rval; @@ -478,8 +469,7 @@ x_emacs_putbuf(s, len) } static int -x_del_back(c) - int c; +x_del_back(int c) { int col = xcp - xbuf; @@ -495,8 +485,7 @@ x_del_back(c) } static int -x_del_char(c) - int c; +x_del_char(int c) { int nleft = xep - xcp; @@ -512,9 +501,7 @@ x_del_char(c) /* Delete nc chars to the right of the cursor (including cursor position) */ static void -x_delete(nc, push) - int nc; - int push; +x_delete(int nc, int push) { int i,j; char *cp; @@ -569,39 +556,35 @@ x_delete(nc, push) } static int -x_del_bword(c) - int c; +x_del_bword(int c) { x_delete(x_bword(), TRUE); return KSTD; } static int -x_mv_bword(c) - int c; +x_mv_bword(int c) { (void)x_bword(); return KSTD; } static int -x_mv_fword(c) - int c; +x_mv_fword(int c) { x_goto(xcp + x_fword()); return KSTD; } static int -x_del_fword(c) - int c; +x_del_fword(int c) { x_delete(x_fword(), TRUE); return KSTD; } static int -x_bword() +x_bword(void) { int nc = 0; char *cp = xcp; @@ -628,7 +611,7 @@ x_bword() } static int -x_fword() +x_fword(void) { int nc = 0; char *cp = xcp; @@ -654,8 +637,7 @@ x_fword() } static void -x_goto(cp) - char *cp; +x_goto(char *cp) { if (cp < xbp || cp >= (xbp + x_displen)) { @@ -682,8 +664,7 @@ x_goto(cp) } static void -x_bs(c) - int c; +x_bs(int c) { int i; i = x_size(c); @@ -692,8 +673,7 @@ x_bs(c) } static int -x_size_str(cp) - char *cp; +x_size_str(char *cp) { int size = 0; while (*cp) @@ -702,8 +682,7 @@ x_size_str(cp) } static int -x_size(c) - int c; +x_size(int c) { if (c=='\t') return 4; /* Kludge, tabs are always four spaces. */ @@ -713,8 +692,7 @@ x_size(c) } static void -x_zots(str) - char *str; +x_zots(char *str) { int adj = x_adj_done; @@ -724,8 +702,7 @@ x_zots(str) } static void -x_zotc(c) - int c; +x_zotc(int c) { if (c == '\t') { /* Kludge, tabs are always four spaces. */ @@ -738,8 +715,7 @@ x_zotc(c) } static int -x_mv_back(c) - int c; +x_mv_back(int c) { int col = xcp - xbuf; @@ -754,8 +730,7 @@ x_mv_back(c) } static int -x_mv_forw(c) - int c; +x_mv_forw(int c) { int nleft = xep - xcp; @@ -770,8 +745,7 @@ x_mv_forw(c) } static int -x_search_char_forw(c) - int c; +x_search_char_forw(int c) { char *cp = xcp; @@ -791,8 +765,7 @@ x_search_char_forw(c) } static int -x_search_char_back(c) - int c; +x_search_char_back(int c) { char *cp = xcp, *p; @@ -813,8 +786,7 @@ x_search_char_back(c) } static int -x_newline(c) - int c; +x_newline(int c) { x_e_putc('\r'); x_e_putc('\n'); @@ -824,27 +796,25 @@ x_newline(c) } static int -x_end_of_text(c) - int c; +x_end_of_text(int c) { return KEOL; } -static int x_beg_hist(c) int c; { x_load_hist(history); return KSTD;} +static int x_beg_hist(int c) { x_load_hist(history); return KSTD;} -static int x_end_hist(c) int c; { x_load_hist(histptr); return KSTD;} +static int x_end_hist(int c) { x_load_hist(histptr); return KSTD;} -static int x_prev_com(c) int c; { x_load_hist(x_histp - x_arg); return KSTD;} +static int x_prev_com(int c) { x_load_hist(x_histp - x_arg); return KSTD;} -static int x_next_com(c) int c; { x_load_hist(x_histp + x_arg); return KSTD;} +static int x_next_com(int c) { x_load_hist(x_histp + x_arg); return KSTD;} /* Goto a particular history number obtained from argument. * If no argument is given history 1 is probably not what you * want so we'll simply go to the oldest one. */ static int -x_goto_hist(c) - int c; +x_goto_hist(int c) { if (x_arg_defaulted) x_load_hist(history); @@ -854,8 +824,7 @@ x_goto_hist(c) } static void -x_load_hist(hp) - char **hp; +x_load_hist(char **hp) { int oldsize; @@ -876,16 +845,14 @@ x_load_hist(hp) } static int -x_nl_next_com(c) - int c; +x_nl_next_com(int c) { x_nextcmd = source->line - (histptr - x_histp) + 1; return (x_newline(c)); } static int -x_eot_del(c) - int c; +x_eot_del(int c) { if (xep == xbuf && x_arg_defaulted) return (x_end_of_text(c)); @@ -895,8 +862,7 @@ x_eot_del(c) /* reverse incremental history search */ static int -x_search_hist(c) - int c; +x_search_hist(int c) { int offset = -1; /* offset of match in xbuf, else -1 */ char pat [256+1]; /* pattern buffer */ @@ -958,10 +924,7 @@ x_search_hist(c) /* search backward from current line */ static int -x_search(pat, sameline, offset) - char *pat; - int sameline; - int offset; +x_search(char *pat, int sameline, int offset) { char **hp; int i; @@ -983,8 +946,7 @@ x_search(pat, sameline, offset) /* return position of first match of pattern in string, else -1 */ static int -x_match(str, pat) - char *str, *pat; +x_match(char *str, char *pat) { if (*pat == '^') { return (strncmp(str, pat+1, strlen(pat+1)) == 0) ? 0 : -1; @@ -995,8 +957,7 @@ x_match(str, pat) } static int -x_del_line(c) - int c; +x_del_line(int c) { int i, j; @@ -1014,24 +975,21 @@ x_del_line(c) } static int -x_mv_end(c) - int c; +x_mv_end(int c) { x_goto(xep); return KSTD; } static int -x_mv_begin(c) - int c; +x_mv_begin(int c) { x_goto(xbuf); return KSTD; } static int -x_draw_line(c) - int c; +x_draw_line(int c) { x_redraw(-1); return KSTD; @@ -1043,8 +1001,7 @@ x_draw_line(c) * redrawing. */ static void -x_redraw(limit) - int limit; +x_redraw(int limit) { int i, j; char *cp; @@ -1099,8 +1056,7 @@ x_redraw(limit) } static int -x_transpose(c) - int c; +x_transpose(int c) { char tmp; @@ -1152,32 +1108,28 @@ x_transpose(c) } static int -x_literal(c) - int c; +x_literal(int c) { x_curprefix = -1; return KSTD; } static int -x_meta1(c) - int c; +x_meta1(int c) { x_curprefix = 1; return KSTD; } static int -x_meta2(c) - int c; +x_meta2(int c) { x_curprefix = 2; return KSTD; } static int -x_kill(c) - int c; +x_kill(int c) { int col = xcp - xbuf; int lastcol = xep - xbuf; @@ -1197,8 +1149,7 @@ x_kill(c) } static void -x_push(nchars) - int nchars; +x_push(int nchars) { char *cp = str_nsave(xcp, nchars, AEDIT); if (killstack[killsp]) @@ -1208,8 +1159,7 @@ x_push(nchars) } static int -x_yank(c) - int c; +x_yank(int c) { if (killsp == 0) killtp = KILLSIZE; @@ -1227,8 +1177,7 @@ x_yank(c) } static int -x_meta_yank(c) - int c; +x_meta_yank(int c) { int len; if ((x_last_command != XFUNC_yank && x_last_command != XFUNC_meta_yank) @@ -1252,8 +1201,7 @@ x_meta_yank(c) } static int -x_abort(c) - int c; +x_abort(int c) { /* x_zotc(c); */ xlp = xep = xcp = xbp = xbuf; @@ -1263,16 +1211,14 @@ x_abort(c) } static int -x_error(c) - int c; +x_error(int c) { x_e_putc(BEL); return KSTD; } static int -x_stuffreset(c) - int c; +x_stuffreset(int c) { #ifdef TIOCSTI (void)x_stuff(c); @@ -1288,8 +1234,7 @@ x_stuffreset(c) } static int -x_stuff(c) - int c; +x_stuff(int c) { #ifdef TIOCSTI char ch = c; @@ -1303,8 +1248,7 @@ x_stuff(c) } static char * -x_mapin(cp) - const char *cp; +x_mapin(const char *cp) { char *new, *op; @@ -1329,8 +1273,7 @@ x_mapin(cp) } static char * -x_mapout(c) - int c; +x_mapout(int c) { static char buf[8]; char *p = buf; @@ -1345,8 +1288,7 @@ x_mapout(c) } static void -x_print(prefix, key) - int prefix, key; +x_print(int prefix, int key) { if (prefix == 1) shprintf("%s", x_mapout(x_prefix1)); @@ -1360,10 +1302,9 @@ x_print(prefix, key) } int -x_bind(a1, a2, macro, list) - const char *a1, *a2; - int macro; /* bind -m */ - int list; /* bind -l */ +x_bind( const char *a1, const char *a2, + int macro, /* bind -m */ + int list) /* bind -l */ { Findex f; int prefix, key; @@ -1453,7 +1394,7 @@ x_bind(a1, a2, macro, list) } void -x_init_emacs() +x_init_emacs(void) { int i, j; char *locale; @@ -1488,9 +1429,7 @@ x_init_emacs() static void bind_if_not_bound(int p, int k, int func); static void -bind_if_not_bound(p, k, func) - int p, k; - int func; +bind_if_not_bound(int p, int k, int func) { /* Has user already bound this key? If so, don't override it */ if (x_bound[((p) * X_TABSZ + (k)) / 8] @@ -1501,8 +1440,7 @@ bind_if_not_bound(p, k, func) } void -x_emacs_keys(ec) - X_chars *ec; +x_emacs_keys(X_chars *ec) { if (ec->erase >= 0) { bind_if_not_bound(0, ec->erase, XFUNC_del_back); @@ -1519,16 +1457,14 @@ x_emacs_keys(ec) } static int -x_set_mark(c) - int c; +x_set_mark(int c) { xmp = xcp; return KSTD; } static int -x_kill_region(c) - int c; +x_kill_region(int c) { int rsize; char *xr; @@ -1551,8 +1487,7 @@ x_kill_region(c) } static int -x_xchg_point_mark(c) - int c; +x_xchg_point_mark(int c) { char *tmp; @@ -1567,8 +1502,7 @@ x_xchg_point_mark(c) } static int -x_version(c) - int c; +x_version(int c) { char *o_xbuf = xbuf, *o_xend = xend; char *o_xbp = xbp, *o_xep = xep, *o_xcp = xcp; @@ -1597,16 +1531,14 @@ x_version(c) } static int -x_noop(c) - int c; +x_noop(int c) { return KSTD; } #ifdef SILLY static int -x_game_of_life(c) - int c; +x_game_of_life(int c) { char newbuf [256+1]; char *ip, *op; @@ -1662,57 +1594,49 @@ x_game_of_life(c) static int -x_comp_comm(c) - int c; +x_comp_comm(int c) { do_complete(XCF_COMMAND, CT_COMPLETE); return KSTD; } static int -x_list_comm(c) - int c; +x_list_comm(int c) { do_complete(XCF_COMMAND, CT_LIST); return KSTD; } static int -x_complete(c) - int c; +x_complete(int c) { do_complete(XCF_COMMAND_FILE, CT_COMPLETE); return KSTD; } static int -x_enumerate(c) - int c; +x_enumerate(int c) { do_complete(XCF_COMMAND_FILE, CT_LIST); return KSTD; } static int -x_comp_file(c) - int c; +x_comp_file(int c) { do_complete(XCF_FILE, CT_COMPLETE); return KSTD; } static int -x_list_file(c) - int c; +x_list_file(int c) { do_complete(XCF_FILE, CT_LIST); return KSTD; } static int -x_comp_list(c) - int c; +x_comp_list(int c) { do_complete(XCF_COMMAND_FILE, CT_COMPLIST); return KSTD; } static int -x_expand(c) - int c; +x_expand(int c) { char **words; int nwords = 0; @@ -1746,9 +1670,8 @@ x_expand(c) /* type == 0 for list, 1 for complete and 2 for complete-list */ static void -do_complete(flags, type) - int flags; /* XCF_{COMMAND,FILE,COMMAND_FILE} */ - Comp_type type; +do_complete(int flags, /* XCF_{COMMAND,FILE,COMMAND_FILE} */ + Comp_type type) { char **words; int nwords; @@ -1813,7 +1736,7 @@ do_complete(flags, type) */ static void -x_adjust() +x_adjust(void) { x_adj_done++; /* flag the fact that we were called. */ /* @@ -1829,14 +1752,13 @@ x_adjust() static int unget_char = -1; static void -x_e_ungetc(c) - int c; +x_e_ungetc(int c) { unget_char = c; } static int -x_e_getc() +x_e_getc(void) { int c; @@ -1856,8 +1778,7 @@ x_e_getc() } static void -x_e_putc(c) - int c; +x_e_putc(int c) { if (c == '\r' || c == '\n') x_col = 0; @@ -1887,8 +1808,7 @@ x_e_putc(c) #ifdef DEBUG static int -x_debug_info(c) - int c; +x_debug_info(int c) { x_flush(); shellf("\nksh debug:\n"); @@ -1905,8 +1825,7 @@ x_debug_info(c) #endif static void -x_e_puts(s) - const char *s; +x_e_puts(const char *s) { int adj = x_adj_done; @@ -1925,8 +1844,7 @@ x_e_puts(s) */ static int -x_set_arg(c) - int c; +x_set_arg(int c) { int n = 0; int first = 1; @@ -1949,8 +1867,7 @@ x_set_arg(c) /* Comment or uncomment the current line. */ static int -x_comment(c) - int c; +x_comment(int c) { int oldsize = x_size_str(xbuf); int len = xep - xbuf; @@ -1986,8 +1903,7 @@ x_comment(c) */ static int -x_prev_histword(c) - int c; +x_prev_histword(int c) { char *rcp; char *cp; @@ -2035,24 +1951,21 @@ x_prev_histword(c) /* Uppercase N(1) words */ static int -x_fold_upper(c) - int c; +x_fold_upper(int c) { return x_fold_case('U'); } /* Lowercase N(1) words */ static int -x_fold_lower(c) - int c; +x_fold_lower(int c) { return x_fold_case('L'); } /* Lowercase N(1) words */ static int -x_fold_capitalize(c) - int c; +x_fold_capitalize(int c) { return x_fold_case('C'); } @@ -2069,8 +1982,7 @@ x_fold_capitalize(c) */ static int -x_fold_case(c) - int c; +x_fold_case(int c) { char *cp = xcp; @@ -2137,7 +2049,7 @@ x_fold_case(c) */ static char * -x_lastcp() +x_lastcp(void) { char *rcp; int i; |