From 7573dcd2260c79138c24ab89dcebecd7a7aa9851 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Wed, 9 Oct 2013 10:48:00 +0800 Subject: [PATCH] Move edef.h out of bind.h and buffer.h out of edef.h. --- Makefile | 58 ++- bind.c | 839 +++++++++++++++++++++---------------------- bind.h | 2 - ebind.c | 795 ++++++++++++++++++++-------------------- edef.h | 1 - input.c | 1057 +++++++++++++++++++++++++++--------------------------- 6 files changed, 1373 insertions(+), 1379 deletions(-) diff --git a/Makefile b/Makefile index f7fa3a6..fa62477 100644 --- a/Makefile +++ b/Makefile @@ -126,15 +126,15 @@ depend: ${SRC} # DO NOT DELETE THIS LINE -- make depend uses it -ansi.o: ansi.c estruct.h retcode.h edef.h buffer.h crypt.h line.h utf8.h +ansi.o: ansi.c estruct.h retcode.h edef.h basic.o: basic.c basic.h buffer.h crypt.h line.h utf8.h display.h \ estruct.h retcode.h edef.h input.h bind.h random.h terminal.h defines.h \ window.h bindable.o: bindable.c bindable.h defines.h buffer.h crypt.h line.h \ utf8.h display.h edef.h estruct.h retcode.h file.h input.h bind.h lock.h \ terminal.h -bind.o: bind.c bind.h edef.h buffer.h crypt.h line.h utf8.h estruct.h \ - retcode.h bindable.h display.h ebind.h exec.h file.h flook.h input.h \ +bind.o: bind.c bind.h edef.h estruct.h retcode.h bindable.h buffer.h \ + crypt.h line.h utf8.h display.h ebind.h exec.h file.h flook.h input.h \ names.h window.h defines.h buffer.o: buffer.c buffer.h crypt.h line.h utf8.h defines.h display.h \ edef.h estruct.h retcode.h file.h input.h bind.h window.h @@ -142,46 +142,41 @@ crypt.o: crypt.c crypt.h display.o: display.c display.h buffer.h crypt.h line.h utf8.h estruct.h \ retcode.h edef.h input.h bind.h termio.h terminal.h defines.h version.h \ wrapper.h window.h -ebind.o: ebind.c ebind.h basic.h bind.h edef.h buffer.h crypt.h line.h \ - utf8.h estruct.h retcode.h bindable.h eval.h exec.h file.h isearch.h \ +ebind.o: ebind.c ebind.h basic.h bind.h edef.h estruct.h retcode.h \ + bindable.h buffer.h crypt.h line.h utf8.h eval.h exec.h file.h isearch.h \ random.h region.h search.h spawn.h window.h defines.h word.h -eval.o: eval.c eval.h basic.h bind.h edef.h buffer.h crypt.h line.h \ - utf8.h estruct.h retcode.h display.h exec.h execute.h flook.h input.h \ +eval.o: eval.c eval.h basic.h bind.h buffer.h crypt.h line.h utf8.h \ + display.h estruct.h retcode.h edef.h exec.h execute.h flook.h input.h \ random.h search.h terminal.h defines.h termio.h version.h window.h -exec.o: exec.c exec.h buffer.h crypt.h line.h utf8.h bind.h edef.h \ - estruct.h retcode.h display.h eval.h file.h flook.h input.h window.h \ +exec.o: exec.c exec.h buffer.h crypt.h line.h utf8.h bind.h display.h \ + estruct.h retcode.h edef.h eval.h file.h flook.h input.h window.h \ defines.h -execute.o: execute.c execute.h edef.h buffer.h crypt.h line.h utf8.h \ - estruct.h retcode.h bind.h random.h display.h file.h terminal.h \ - defines.h window.h +execute.o: execute.c execute.h edef.h estruct.h retcode.h bind.h random.h \ + display.h file.h crypt.h buffer.h line.h utf8.h terminal.h defines.h \ + window.h file.o: file.c file.h crypt.h retcode.h buffer.h line.h utf8.h defines.h \ estruct.h edef.h execute.h fileio.h input.h bind.h lock.h log.h window.h fileio.o: fileio.c fileio.h crypt.h retcode.h defines.h flook.o: flook.c flook.h retcode.h defines.h fileio.h crypt.h -globals.o: globals.c defines.h edef.h buffer.h crypt.h line.h utf8.h \ - estruct.h retcode.h -ibmpc.o: ibmpc.c estruct.h retcode.h edef.h buffer.h crypt.h line.h \ - utf8.h -input.o: input.c input.h bind.h edef.h buffer.h crypt.h line.h utf8.h \ - estruct.h retcode.h bindable.h display.h exec.h names.h terminal.h \ - defines.h wrapper.h +globals.o: globals.c defines.h edef.h estruct.h retcode.h +ibmpc.o: ibmpc.c estruct.h retcode.h edef.h +input.o: input.c input.h bind.h edef.h estruct.h retcode.h bindable.h \ + display.h exec.h names.h terminal.h defines.h wrapper.h isearch.o: isearch.c isearch.h basic.h buffer.h crypt.h line.h utf8.h \ display.h estruct.h retcode.h edef.h input.h bind.h search.h terminal.h \ defines.h window.h line.o: line.c line.h utf8.h buffer.h crypt.h edef.h estruct.h retcode.h \ log.h window.h defines.h -lock.o: lock.c lock.h estruct.h retcode.h display.h edef.h buffer.h \ - crypt.h line.h utf8.h input.h bind.h +lock.o: lock.c lock.h estruct.h retcode.h display.h edef.h input.h bind.h log.o: log.c log.h retcode.h -main.o: main.c basic.h bind.h edef.h buffer.h crypt.h line.h utf8.h \ - estruct.h retcode.h bindable.h display.h eval.h execute.h file.h input.h \ +main.o: main.c basic.h bind.h bindable.h buffer.h crypt.h line.h utf8.h \ + display.h edef.h estruct.h retcode.h eval.h execute.h file.h input.h \ lock.h log.h random.h search.h terminal.h defines.h termio.h version.h \ window.h -names.o: names.c names.h basic.h bind.h edef.h buffer.h crypt.h line.h \ - utf8.h estruct.h retcode.h bindable.h display.h eval.h exec.h file.h \ - isearch.h region.h random.h search.h spawn.h window.h defines.h word.h -pklock.o: pklock.c pklock.h estruct.h retcode.h edef.h buffer.h crypt.h \ - line.h utf8.h +names.o: names.c names.h basic.h bind.h bindable.h buffer.h crypt.h \ + line.h utf8.h display.h eval.h exec.h file.h retcode.h isearch.h \ + region.h random.h search.h spawn.h window.h defines.h word.h +pklock.o: pklock.c pklock.h estruct.h retcode.h edef.h posix.o: posix.c termio.h random.o: random.c random.h basic.h buffer.h crypt.h line.h utf8.h \ display.h estruct.h retcode.h edef.h execute.h input.h bind.h log.h \ @@ -195,12 +190,11 @@ spawn.o: spawn.c spawn.h defines.h buffer.h crypt.h line.h utf8.h \ display.h estruct.h retcode.h edef.h file.h flook.h input.h bind.h log.h \ terminal.h window.h tcap.o: tcap.c terminal.h defines.h display.h estruct.h retcode.h edef.h \ - buffer.h crypt.h line.h utf8.h termio.h + termio.h termio.o: termio.c termio.h estruct.h retcode.h utf8.h utf8.o: utf8.c utf8.h -vmsvt.o: vmsvt.c estruct.h retcode.h edef.h buffer.h crypt.h line.h \ - utf8.h -vt52.o: vt52.c estruct.h retcode.h edef.h buffer.h crypt.h line.h utf8.h +vmsvt.o: vmsvt.c estruct.h retcode.h edef.h +vt52.o: vt52.c estruct.h retcode.h edef.h window.o: window.c window.h defines.h buffer.h crypt.h line.h utf8.h \ basic.h display.h edef.h estruct.h retcode.h execute.h terminal.h \ wrapper.h diff --git a/bind.c b/bind.c index bc373ca..b88b51c 100644 --- a/bind.c +++ b/bind.c @@ -1,18 +1,19 @@ /* bind.c -- implements bind.h */ #include "bind.h" -/* bind.c +/* bind.c * - * This file is for functions having to do with key bindings, - * descriptions, help commands and startup file. + * This file is for functions having to do with key bindings, + * descriptions, help commands and startup file. * - * Written 11-feb-86 by Daniel Lawrence - * Modified by Petri Kutvonen + * Written 11-feb-86 by Daniel Lawrence + * Modified by Petri Kutvonen */ #include #include +#include "edef.h" #include "bindable.h" #include "buffer.h" #include "display.h" @@ -29,232 +30,232 @@ static char *getfname( fn_t) ; int help(int f, int n) -{ /* give me some help!!!! - bring up a fake buffer and read the help file - into it with view mode */ - struct window *wp; /* scaning pointer to windows */ - struct buffer *bp; /* buffer pointer to help */ - char *fname = NULL; /* ptr to file returned by flook() */ +{ /* give me some help!!!! + bring up a fake buffer and read the help file + into it with view mode */ + struct window *wp; /* scaning pointer to windows */ + struct buffer *bp; /* buffer pointer to help */ + char *fname = NULL; /* ptr to file returned by flook() */ - /* first check if we are already here */ - bp = bfind( hlpfname, FALSE, BFINVS); + /* first check if we are already here */ + bp = bfind( hlpfname, FALSE, BFINVS); - if (bp == NULL) { - fname = flook( hlpfname, FALSE); - if (fname == NULL) { - mlwrite("(Help file is not online)"); - return FALSE; - } - } + if (bp == NULL) { + fname = flook( hlpfname, FALSE); + if (fname == NULL) { + mlwrite("(Help file is not online)"); + return FALSE; + } + } - /* split the current window to make room for the help stuff */ - if (splitwind(FALSE, 1) == FALSE) - return FALSE; + /* split the current window to make room for the help stuff */ + if (splitwind(FALSE, 1) == FALSE) + return FALSE; - if (bp == NULL) { - /* and read the stuff in */ - if (getfile(fname, FALSE) == FALSE) - return FALSE; - } else - swbuffer(bp); + if (bp == NULL) { + /* and read the stuff in */ + if (getfile(fname, FALSE) == FALSE) + return FALSE; + } else + swbuffer(bp); - /* make this window in VIEW mode, update all mode lines */ - curwp->w_bufp->b_mode |= MDVIEW; - curwp->w_bufp->b_flag |= BFINVS; - wp = wheadp; - while (wp != NULL) { - wp->w_flag |= WFMODE; - wp = wp->w_wndp; - } - return TRUE; + /* make this window in VIEW mode, update all mode lines */ + curwp->w_bufp->b_mode |= MDVIEW; + curwp->w_bufp->b_flag |= BFINVS; + wp = wheadp; + while (wp != NULL) { + wp->w_flag |= WFMODE; + wp = wp->w_wndp; + } + return TRUE; } int deskey(int f, int n) -{ /* describe the command for a certain key */ - int c; /* key to describe */ - char *ptr; /* string pointer to scan output strings */ - char outseq[NSTRING]; /* output buffer for command sequence */ +{ /* describe the command for a certain key */ + int c; /* key to describe */ + char *ptr; /* string pointer to scan output strings */ + char outseq[NSTRING]; /* output buffer for command sequence */ - /* prompt the user to type us a key to describe */ - mlwrite(": describe-key "); + /* prompt the user to type us a key to describe */ + mlwrite(": describe-key "); - /* get the command sequence to describe - change it to something we can print as well */ - cmdstr(c = getckey(FALSE), &outseq[0]); + /* get the command sequence to describe + change it to something we can print as well */ + cmdstr(c = getckey(FALSE), &outseq[0]); - /* and dump it out */ - ostring(outseq); - ostring(" "); + /* and dump it out */ + ostring(outseq); + ostring(" "); - /* find the right ->function */ - if ((ptr = getfname(getbind(c))) == NULL) - ptr = "Not Bound"; + /* find the right ->function */ + if ((ptr = getfname(getbind(c))) == NULL) + ptr = "Not Bound"; - /* output the command sequence */ - ostring(ptr); - return TRUE; + /* output the command sequence */ + ostring(ptr); + return TRUE; } /* * bindtokey: - * add a new key to the key binding table + * add a new key to the key binding table * - * int f, n; command arguments [IGNORED] + * int f, n; command arguments [IGNORED] */ int bindtokey(int f, int n) { - unsigned int c; /* command key to bind */ - fn_t kfunc; /* ptr to the requested function to bind to */ - struct key_tab *ktp; /* pointer into the command table */ - int found; /* matched command flag */ - char outseq[80]; /* output buffer for keystroke sequence */ + unsigned int c; /* command key to bind */ + fn_t kfunc; /* ptr to the requested function to bind to */ + struct key_tab *ktp; /* pointer into the command table */ + int found; /* matched command flag */ + char outseq[80]; /* output buffer for keystroke sequence */ - /* prompt the user to type in a key to bind */ - mlwrite(": bind-to-key "); + /* prompt the user to type in a key to bind */ + mlwrite(": bind-to-key "); - /* get the function name to bind it to */ - kfunc = getname(); - if (kfunc == NULL) { - mlwrite("(No such function)"); - return FALSE; - } - ostring(" "); + /* get the function name to bind it to */ + kfunc = getname(); + if (kfunc == NULL) { + mlwrite("(No such function)"); + return FALSE; + } + ostring(" "); - /* get the command sequence to bind */ - c = getckey((kfunc == metafn) || (kfunc == cex) || - (kfunc == unarg) || (kfunc == ctrlg)); + /* get the command sequence to bind */ + c = getckey((kfunc == metafn) || (kfunc == cex) || + (kfunc == unarg) || (kfunc == ctrlg)); - /* change it to something we can print as well */ - cmdstr(c, &outseq[0]); + /* change it to something we can print as well */ + cmdstr(c, &outseq[0]); - /* and dump it out */ - ostring(outseq); + /* and dump it out */ + ostring(outseq); - /* if the function is a prefix key */ - if (kfunc == metafn || kfunc == cex || - kfunc == unarg || kfunc == ctrlg) { + /* if the function is a prefix key */ + if (kfunc == metafn || kfunc == cex || + kfunc == unarg || kfunc == ctrlg) { - /* search for an existing binding for the prefix key */ - ktp = &keytab[0]; - found = FALSE; - while (ktp->k_fp != NULL) { - if (ktp->k_fp == kfunc) - unbindchar(ktp->k_code); - ++ktp; - } + /* search for an existing binding for the prefix key */ + ktp = &keytab[0]; + found = FALSE; + while (ktp->k_fp != NULL) { + if (ktp->k_fp == kfunc) + unbindchar(ktp->k_code); + ++ktp; + } - /* reset the appropriate global prefix variable */ - if (kfunc == metafn) - metac = c; - if (kfunc == cex) - ctlxc = c; - if (kfunc == unarg) - reptc = c; - if (kfunc == ctrlg) - abortc = c; - } + /* reset the appropriate global prefix variable */ + if (kfunc == metafn) + metac = c; + if (kfunc == cex) + ctlxc = c; + if (kfunc == unarg) + reptc = c; + if (kfunc == ctrlg) + abortc = c; + } - /* search the table to see if it exists */ - ktp = &keytab[0]; - found = FALSE; - while (ktp->k_fp != NULL) { - if (ktp->k_code == c) { - found = TRUE; - break; - } - ++ktp; - } + /* search the table to see if it exists */ + ktp = &keytab[0]; + found = FALSE; + while (ktp->k_fp != NULL) { + if (ktp->k_code == c) { + found = TRUE; + break; + } + ++ktp; + } - if (found) { /* it exists, just change it then */ - ktp->k_fp = kfunc; - } else { /* otherwise we need to add it to the end */ - /* if we run out of binding room, bitch */ - if (ktp >= &keytab[NBINDS]) { - mlwrite("Binding table FULL!"); - return FALSE; - } + if (found) { /* it exists, just change it then */ + ktp->k_fp = kfunc; + } else { /* otherwise we need to add it to the end */ + /* if we run out of binding room, bitch */ + if (ktp >= &keytab[NBINDS]) { + mlwrite("Binding table FULL!"); + return FALSE; + } - ktp->k_code = c; /* add keycode */ - ktp->k_fp = kfunc; /* and the function pointer */ - ++ktp; /* and make sure the next is null */ - ktp->k_code = 0; - ktp->k_fp = NULL; - } - return TRUE; + ktp->k_code = c; /* add keycode */ + ktp->k_fp = kfunc; /* and the function pointer */ + ++ktp; /* and make sure the next is null */ + ktp->k_code = 0; + ktp->k_fp = NULL; + } + return TRUE; } /* * unbindkey: - * delete a key from the key binding table + * delete a key from the key binding table * - * int f, n; command arguments [IGNORED] + * int f, n; command arguments [IGNORED] */ int unbindkey(int f, int n) { - int c; /* command key to unbind */ - char outseq[80]; /* output buffer for keystroke sequence */ + int c; /* command key to unbind */ + char outseq[80]; /* output buffer for keystroke sequence */ - /* prompt the user to type in a key to unbind */ - mlwrite(": unbind-key "); + /* prompt the user to type in a key to unbind */ + mlwrite(": unbind-key "); - /* get the command sequence to unbind */ - c = getckey(FALSE); /* get a command sequence */ + /* get the command sequence to unbind */ + c = getckey(FALSE); /* get a command sequence */ - /* change it to something we can print as well */ - cmdstr(c, &outseq[0]); + /* change it to something we can print as well */ + cmdstr(c, &outseq[0]); - /* and dump it out */ - ostring(outseq); + /* and dump it out */ + ostring(outseq); - /* if it isn't bound, bitch */ - if (unbindchar(c) == FALSE) { - mlwrite("(Key not bound)"); - return FALSE; - } - return TRUE; + /* if it isn't bound, bitch */ + if (unbindchar(c) == FALSE) { + mlwrite("(Key not bound)"); + return FALSE; + } + return TRUE; } /* * unbindchar() * - * int c; command key to unbind + * int c; command key to unbind */ int unbindchar(int c) { - struct key_tab *ktp; /* pointer into the command table */ - struct key_tab *sktp; /* saved pointer into the command table */ - int found; /* matched command flag */ + struct key_tab *ktp; /* pointer into the command table */ + struct key_tab *sktp; /* saved pointer into the command table */ + int found; /* matched command flag */ - /* search the table to see if the key exists */ - ktp = &keytab[0]; - found = FALSE; - while (ktp->k_fp != NULL) { - if (ktp->k_code == c) { - found = TRUE; - break; - } - ++ktp; - } + /* search the table to see if the key exists */ + ktp = &keytab[0]; + found = FALSE; + while (ktp->k_fp != NULL) { + if (ktp->k_code == c) { + found = TRUE; + break; + } + ++ktp; + } - /* if it isn't bound, bitch */ - if (!found) - return FALSE; + /* if it isn't bound, bitch */ + if (!found) + return FALSE; - /* save the pointer and scan to the end of the table */ - sktp = ktp; - while (ktp->k_fp != NULL) - ++ktp; - --ktp; /* backup to the last legit entry */ + /* save the pointer and scan to the end of the table */ + sktp = ktp; + while (ktp->k_fp != NULL) + ++ktp; + --ktp; /* backup to the last legit entry */ - /* copy the last entry to the current one */ - sktp->k_code = ktp->k_code; - sktp->k_fp = ktp->k_fp; + /* copy the last entry to the current one */ + sktp->k_code = ktp->k_code; + sktp->k_fp = ktp->k_fp; - /* null out the last one */ - ktp->k_code = 0; - ktp->k_fp = NULL; - return TRUE; + /* null out the last one */ + ktp->k_code = 0; + ktp->k_fp = NULL; + return TRUE; } /* describe bindings @@ -262,386 +263,386 @@ int unbindchar(int c) * into it with view mode */ int desbind(int f, int n) -#if APROP +#if APROP { - buildlist(TRUE, ""); - return TRUE; + buildlist(TRUE, ""); + return TRUE; } int apro(int f, int n) -{ /* Apropos (List functions that match a substring) */ - char mstring[NSTRING]; /* string to match cmd names to */ - int status; /* status return */ +{ /* Apropos (List functions that match a substring) */ + char mstring[NSTRING]; /* string to match cmd names to */ + int status; /* status return */ - status = mlreply("Apropos string: ", mstring, NSTRING - 1); - if (status != TRUE) - return status; + status = mlreply("Apropos string: ", mstring, NSTRING - 1); + if (status != TRUE) + return status; - return buildlist(FALSE, mstring); + return buildlist(FALSE, mstring); } /* * build a binding list (limited or full) * - * int type; true = full list, false = partial list - * char *mstring; match string if a partial list + * int type; true = full list, false = partial list + * char *mstring; match string if a partial list */ int buildlist(int type, char *mstring) #endif { - struct window *wp; /* scanning pointer to windows */ - struct key_tab *ktp; /* pointer into the command table */ - struct name_bind *nptr; /* pointer into the name binding table */ - struct buffer *bp; /* buffer to put binding list into */ - int cpos; /* current position to use in outseq */ - char outseq[80]; /* output buffer for keystroke sequence */ + struct window *wp; /* scanning pointer to windows */ + struct key_tab *ktp; /* pointer into the command table */ + struct name_bind *nptr; /* pointer into the name binding table */ + struct buffer *bp; /* buffer to put binding list into */ + int cpos; /* current position to use in outseq */ + char outseq[80]; /* output buffer for keystroke sequence */ - /* split the current window to make room for the binding list */ - if (splitwind(FALSE, 1) == FALSE) - return FALSE; + /* split the current window to make room for the binding list */ + if (splitwind(FALSE, 1) == FALSE) + return FALSE; - /* and get a buffer for it */ - bp = bfind("*Binding list*", TRUE, 0); - if (bp == NULL || bclear(bp) == FALSE) { - mlwrite("Can not display binding list"); - return FALSE; - } + /* and get a buffer for it */ + bp = bfind("*Binding list*", TRUE, 0); + if (bp == NULL || bclear(bp) == FALSE) { + mlwrite("Can not display binding list"); + return FALSE; + } - /* let us know this is in progress */ - mlwrite("(Building binding list)"); + /* let us know this is in progress */ + mlwrite("(Building binding list)"); - /* disconect the current buffer */ - if (--curbp->b_nwnd == 0) { /* Last use. */ - curbp->b_dotp = curwp->w_dotp; - curbp->b_doto = curwp->w_doto; - curbp->b_markp = curwp->w_markp; - curbp->b_marko = curwp->w_marko; - } + /* disconect the current buffer */ + if (--curbp->b_nwnd == 0) { /* Last use. */ + curbp->b_dotp = curwp->w_dotp; + curbp->b_doto = curwp->w_doto; + curbp->b_markp = curwp->w_markp; + curbp->b_marko = curwp->w_marko; + } - /* connect the current window to this buffer */ - curbp = bp; /* make this buffer current in current window */ - bp->b_mode = 0; /* no modes active in binding list */ - bp->b_nwnd++; /* mark us as more in use */ - wp = curwp; - wp->w_bufp = bp; - wp->w_linep = bp->b_linep; - wp->w_flag = WFHARD | WFFORCE; - wp->w_dotp = bp->b_dotp; - wp->w_doto = bp->b_doto; - wp->w_markp = NULL; - wp->w_marko = 0; + /* connect the current window to this buffer */ + curbp = bp; /* make this buffer current in current window */ + bp->b_mode = 0; /* no modes active in binding list */ + bp->b_nwnd++; /* mark us as more in use */ + wp = curwp; + wp->w_bufp = bp; + wp->w_linep = bp->b_linep; + wp->w_flag = WFHARD | WFFORCE; + wp->w_dotp = bp->b_dotp; + wp->w_doto = bp->b_doto; + wp->w_markp = NULL; + wp->w_marko = 0; - /* build the contents of this window, inserting it line by line */ - nptr = &names[0]; - while (nptr->n_func != NULL) { + /* build the contents of this window, inserting it line by line */ + nptr = &names[0]; + while (nptr->n_func != NULL) { - /* add in the command name */ - strcpy(outseq, nptr->n_name); - cpos = strlen(outseq); + /* add in the command name */ + strcpy(outseq, nptr->n_name); + cpos = strlen(outseq); -#if APROP - /* if we are executing an apropos command..... */ - if (type == FALSE && - /* and current string doesn't include the search string */ - strinc(outseq, mstring) == FALSE) - goto fail; +#if APROP + /* if we are executing an apropos command..... */ + if (type == FALSE && + /* and current string doesn't include the search string */ + strinc(outseq, mstring) == FALSE) + goto fail; #endif - /* search down any keys bound to this */ - ktp = &keytab[0]; - while (ktp->k_fp != NULL) { - if (ktp->k_fp == nptr->n_func) { - /* padd out some spaces */ - while (cpos < 28) - outseq[cpos++] = ' '; + /* search down any keys bound to this */ + ktp = &keytab[0]; + while (ktp->k_fp != NULL) { + if (ktp->k_fp == nptr->n_func) { + /* padd out some spaces */ + while (cpos < 28) + outseq[cpos++] = ' '; - /* add in the command sequence */ - cmdstr(ktp->k_code, &outseq[cpos]); - strcat(outseq, "\n"); + /* add in the command sequence */ + cmdstr(ktp->k_code, &outseq[cpos]); + strcat(outseq, "\n"); - /* and add it as a line into the buffer */ - if (linstr(outseq) != TRUE) - return FALSE; + /* and add it as a line into the buffer */ + if (linstr(outseq) != TRUE) + return FALSE; - cpos = 0; /* and clear the line */ - } - ++ktp; - } + cpos = 0; /* and clear the line */ + } + ++ktp; + } - /* if no key was bound, we need to dump it anyway */ - if (cpos > 0) { - outseq[cpos++] = '\n'; - outseq[cpos] = 0; - if (linstr(outseq) != TRUE) - return FALSE; - } + /* if no key was bound, we need to dump it anyway */ + if (cpos > 0) { + outseq[cpos++] = '\n'; + outseq[cpos] = 0; + if (linstr(outseq) != TRUE) + return FALSE; + } - fail: /* and on to the next name */ - ++nptr; - } + fail: /* and on to the next name */ + ++nptr; + } - curwp->w_bufp->b_mode |= MDVIEW; /* put this buffer view mode */ - curbp->b_flag &= ~BFCHG; /* don't flag this as a change */ - wp->w_dotp = lforw(bp->b_linep); /* back to the beginning */ - wp->w_doto = 0; - wp = wheadp; /* and update ALL mode lines */ - while (wp != NULL) { - wp->w_flag |= WFMODE; - wp = wp->w_wndp; - } - mlwrite(""); /* clear the mode line */ - return TRUE; + curwp->w_bufp->b_mode |= MDVIEW; /* put this buffer view mode */ + curbp->b_flag &= ~BFCHG; /* don't flag this as a change */ + wp->w_dotp = lforw(bp->b_linep); /* back to the beginning */ + wp->w_doto = 0; + wp = wheadp; /* and update ALL mode lines */ + while (wp != NULL) { + wp->w_flag |= WFMODE; + wp = wp->w_wndp; + } + mlwrite(""); /* clear the mode line */ + return TRUE; } -#if APROP +#if APROP /* * does source include sub? * - * char *source; string to search in - * char *sub; substring to look for + * char *source; string to search in + * char *sub; substring to look for */ int strinc(char *source, char *sub) { - char *sp; /* ptr into source */ - char *nxtsp; /* next ptr into source */ - char *tp; /* ptr into substring */ + char *sp; /* ptr into source */ + char *nxtsp; /* next ptr into source */ + char *tp; /* ptr into substring */ - /* for each character in the source string */ - sp = source; - while (*sp) { - tp = sub; - nxtsp = sp; + /* for each character in the source string */ + sp = source; + while (*sp) { + tp = sub; + nxtsp = sp; - /* is the substring here? */ - while (*tp) { - if (*nxtsp++ != *tp) - break; - else - tp++; - } + /* is the substring here? */ + while (*tp) { + if (*nxtsp++ != *tp) + break; + else + tp++; + } - /* yes, return a success */ - if (*tp == 0) - return TRUE; + /* yes, return a success */ + if (*tp == 0) + return TRUE; - /* no, onward */ - sp++; - } - return FALSE; + /* no, onward */ + sp++; + } + return FALSE; } #endif /* * get a command key sequence from the keyboard * - * int mflag; going for a meta sequence? + * int mflag; going for a meta sequence? */ unsigned int getckey(int mflag) { - unsigned int c; /* character fetched */ - char tok[NSTRING]; /* command incoming */ + unsigned int c; /* character fetched */ + char tok[NSTRING]; /* command incoming */ - /* check to see if we are executing a command line */ - if (clexec) { - macarg(tok); /* get the next token */ - return stock(tok); - } + /* check to see if we are executing a command line */ + if (clexec) { + macarg(tok); /* get the next token */ + return stock(tok); + } - /* or the normal way */ - if (mflag) - c = get1key(); - else - c = getcmd(); - return c; + /* or the normal way */ + if (mflag) + c = get1key(); + else + c = getcmd(); + return c; } /* * execute the startup file * - * char *sfname; name of startup file (null if default) + * char *sfname; name of startup file (null if default) */ int startup(char *sfname) { - char *fname; /* resulting file name to execute */ + char *fname; /* resulting file name to execute */ - /* look up the startup file */ - if (*sfname != 0) - fname = flook(sfname, TRUE); - else - fname = flook( rcfname, TRUE); + /* look up the startup file */ + if (*sfname != 0) + fname = flook(sfname, TRUE); + else + fname = flook( rcfname, TRUE); - /* if it isn't around, don't sweat it */ - if (fname == NULL) - return TRUE; + /* if it isn't around, don't sweat it */ + if (fname == NULL) + return TRUE; - /* otherwise, execute the sucker */ - return dofile(fname); + /* otherwise, execute the sucker */ + return dofile(fname); } /* * change a key command to a string we can print out * - * int c; sequence to translate - * char *seq; destination string for sequence + * int c; sequence to translate + * char *seq; destination string for sequence */ void cmdstr(int c, char *seq) { - char *ptr; /* pointer into current position in sequence */ + char *ptr; /* pointer into current position in sequence */ - ptr = seq; + ptr = seq; - /* apply meta sequence if needed */ - if (c & META) { - *ptr++ = 'M'; - *ptr++ = '-'; - } + /* apply meta sequence if needed */ + if (c & META) { + *ptr++ = 'M'; + *ptr++ = '-'; + } - /* apply ^X sequence if needed */ - if (c & CTLX) { - *ptr++ = '^'; - *ptr++ = 'X'; - } + /* apply ^X sequence if needed */ + if (c & CTLX) { + *ptr++ = '^'; + *ptr++ = 'X'; + } - /* apply SPEC sequence if needed */ - if (c & SPEC) { - *ptr++ = 'F'; - *ptr++ = 'N'; - } + /* apply SPEC sequence if needed */ + if (c & SPEC) { + *ptr++ = 'F'; + *ptr++ = 'N'; + } - /* apply control sequence if needed */ - if (c & CONTROL) { - *ptr++ = '^'; - } + /* apply control sequence if needed */ + if (c & CONTROL) { + *ptr++ = '^'; + } - /* and output the final sequence */ + /* and output the final sequence */ - *ptr++ = c & 255; /* strip the prefixes */ + *ptr++ = c & 255; /* strip the prefixes */ - *ptr = 0; /* terminate the string */ + *ptr = 0; /* terminate the string */ } /* * This function looks a key binding up in the binding table * - * int c; key to find what is bound to it + * int c; key to find what is bound to it */ int (*getbind(int c))(int, int) { - struct key_tab *ktp; + struct key_tab *ktp; - ktp = &keytab[0]; /* Look in key table. */ - while (ktp->k_fp != NULL) { - if (ktp->k_code == c) - return ktp->k_fp; - ++ktp; - } + ktp = &keytab[0]; /* Look in key table. */ + while (ktp->k_fp != NULL) { + if (ktp->k_code == c) + return ktp->k_fp; + ++ktp; + } - /* no such binding */ - return NULL; + /* no such binding */ + return NULL; } /* * getfname: - * This function takes a ptr to function and gets the name - * associated with it. + * This function takes a ptr to function and gets the name + * associated with it. */ static char *getfname(fn_t func) { - struct name_bind *nptr; /* pointer into the name binding table */ + struct name_bind *nptr; /* pointer into the name binding table */ - /* skim through the table, looking for a match */ - nptr = &names[0]; - while (nptr->n_func != NULL) { - if (nptr->n_func == func) - return nptr->n_name; - ++nptr; - } - return NULL; + /* skim through the table, looking for a match */ + nptr = &names[0]; + while (nptr->n_func != NULL) { + if (nptr->n_func == func) + return nptr->n_name; + ++nptr; + } + return NULL; } /* * match fname to a function in the names table * and return any match or NULL if none * - * char *fname; name to attempt to match + * char *fname; name to attempt to match */ int (*fncmatch(char *fname)) (int, int) { - struct name_bind *ffp; /* pointer to entry in name binding table */ + struct name_bind *ffp; /* pointer to entry in name binding table */ - /* scan through the table, returning any match */ - ffp = &names[0]; - while (ffp->n_func != NULL) { - if (strcmp(fname, ffp->n_name) == 0) - return ffp->n_func; - ++ffp; - } - return NULL; + /* scan through the table, returning any match */ + ffp = &names[0]; + while (ffp->n_func != NULL) { + if (strcmp(fname, ffp->n_name) == 0) + return ffp->n_func; + ++ffp; + } + return NULL; } /* * stock: - * String key name TO Command Key + * String key name TO Command Key * - * char *keyname; name of key to translate to Command key form + * char *keyname; name of key to translate to Command key form */ unsigned int stock(char *keyname) { - unsigned int c; /* key sequence to return */ + unsigned int c; /* key sequence to return */ - /* parse it up */ - c = 0; + /* parse it up */ + c = 0; - /* first, the META prefix */ - if (*keyname == 'M' && *(keyname + 1) == '-') { - c = META; - keyname += 2; - } + /* first, the META prefix */ + if (*keyname == 'M' && *(keyname + 1) == '-') { + c = META; + keyname += 2; + } - /* next the function prefix */ - if (*keyname == 'F' && *(keyname + 1) == 'N') { - c |= SPEC; - keyname += 2; - } + /* next the function prefix */ + if (*keyname == 'F' && *(keyname + 1) == 'N') { + c |= SPEC; + keyname += 2; + } - /* control-x as well... (but not with FN) */ - if (*keyname == '^' && *(keyname + 1) == 'X' && !(c & SPEC)) { - c |= CTLX; - keyname += 2; - } + /* control-x as well... (but not with FN) */ + if (*keyname == '^' && *(keyname + 1) == 'X' && !(c & SPEC)) { + c |= CTLX; + keyname += 2; + } - /* a control char? */ - if (*keyname == '^' && *(keyname + 1) != 0) { - c |= CONTROL; - ++keyname; - } - if (*keyname < 32) { - c |= CONTROL; - *keyname += 'A'; - } + /* a control char? */ + if (*keyname == '^' && *(keyname + 1) != 0) { + c |= CONTROL; + ++keyname; + } + if (*keyname < 32) { + c |= CONTROL; + *keyname += 'A'; + } - /* make sure we are not lower case (not with function keys) */ - if (*keyname >= 'a' && *keyname <= 'z' && !(c & SPEC)) - *keyname -= 32; + /* make sure we are not lower case (not with function keys) */ + if (*keyname >= 'a' && *keyname <= 'z' && !(c & SPEC)) + *keyname -= 32; - /* the final sequence... */ - c |= *keyname; - return c; + /* the final sequence... */ + c |= *keyname; + return c; } /* * string key name to binding name.... * - * char *skey; name of keey to get binding for + * char *skey; name of keey to get binding for */ char *transbind(char *skey) { - char *bindname; + char *bindname; - bindname = getfname(getbind(stock(skey))); - if (bindname == NULL) - bindname = "ERROR"; + bindname = getfname(getbind(stock(skey))); + if (bindname == NULL) + bindname = "ERROR"; - return bindname; + return bindname; } diff --git a/bind.h b/bind.h index d8e1f4b..3e4c569 100644 --- a/bind.h +++ b/bind.h @@ -1,8 +1,6 @@ #ifndef _BIND_H_ #define _BIND_H_ -#include "edef.h" - #define APROP 1 /* Add code for Apropos command */ #if APROP diff --git a/ebind.c b/ebind.c index 98c1719..7af8614 100644 --- a/ebind.c +++ b/ebind.c @@ -1,11 +1,11 @@ /* ebind.c -- implements ebind.h */ #include "ebind.h" -/* ebind.c +/* ebind.c * - * Initial default key to function bindings + * Initial default key to function bindings * - * Modified by Petri Kutvonen + * Modified by Petri Kutvonen */ #include @@ -13,6 +13,7 @@ #include "basic.h" #include "bind.h" +#include "edef.h" #include "bindable.h" #include "buffer.h" #include "eval.h" @@ -34,407 +35,407 @@ * control-X commands. */ struct key_tab keytab[NBINDS] = { - {CONTROL | 'A', gotobol} - , - {CONTROL | 'B', backchar} - , - {CONTROL | 'C', insspace} - , - {CONTROL | 'D', forwdel} - , - {CONTROL | 'E', gotoeol} - , - {CONTROL | 'F', forwchar} - , - {CONTROL | 'G', ctrlg} - , - {CONTROL | 'H', backdel} - , - {CONTROL | 'I', insert_tab} - , - {CONTROL | 'J', indent} - , - {CONTROL | 'K', killtext} - , - {CONTROL | 'L', redraw} - , - {CONTROL | 'M', insert_newline} - , - {CONTROL | 'N', forwline} - , - {CONTROL | 'O', openline} - , - {CONTROL | 'P', backline} - , - {CONTROL | 'Q', quote} - , - {CONTROL | 'R', backsearch} - , - {CONTROL | 'S', forwsearch} - , - {CONTROL | 'T', twiddle} - , - {CONTROL | 'U', unarg} - , - {CONTROL | 'V', forwpage} - , - {CONTROL | 'W', killregion} - , - {CONTROL | 'X', cex} - , - {CONTROL | 'Y', yank} - , - {CONTROL | 'Z', backpage} - , - {CONTROL | ']', metafn} - , - {CTLX | CONTROL | 'B', listbuffers} - , - {CTLX | CONTROL | 'C', quit} - , /* Hard quit. */ -#if PKCODE & AEDIT - {CTLX | CONTROL | 'A', detab} - , + {CONTROL | 'A', gotobol} + , + {CONTROL | 'B', backchar} + , + {CONTROL | 'C', insspace} + , + {CONTROL | 'D', forwdel} + , + {CONTROL | 'E', gotoeol} + , + {CONTROL | 'F', forwchar} + , + {CONTROL | 'G', ctrlg} + , + {CONTROL | 'H', backdel} + , + {CONTROL | 'I', insert_tab} + , + {CONTROL | 'J', indent} + , + {CONTROL | 'K', killtext} + , + {CONTROL | 'L', redraw} + , + {CONTROL | 'M', insert_newline} + , + {CONTROL | 'N', forwline} + , + {CONTROL | 'O', openline} + , + {CONTROL | 'P', backline} + , + {CONTROL | 'Q', quote} + , + {CONTROL | 'R', backsearch} + , + {CONTROL | 'S', forwsearch} + , + {CONTROL | 'T', twiddle} + , + {CONTROL | 'U', unarg} + , + {CONTROL | 'V', forwpage} + , + {CONTROL | 'W', killregion} + , + {CONTROL | 'X', cex} + , + {CONTROL | 'Y', yank} + , + {CONTROL | 'Z', backpage} + , + {CONTROL | ']', metafn} + , + {CTLX | CONTROL | 'B', listbuffers} + , + {CTLX | CONTROL | 'C', quit} + , /* Hard quit. */ +#if PKCODE & AEDIT + {CTLX | CONTROL | 'A', detab} + , #endif -#if PKCODE - {CTLX | CONTROL | 'D', filesave} - , /* alternative */ -#else -#if AEDIT - {CTLX | CONTROL | 'D', detab} - , -#endif -#endif -#if AEDIT - {CTLX | CONTROL | 'E', entab} - , -#endif - {CTLX | CONTROL | 'F', filefind} - , - {CTLX | CONTROL | 'I', insfile} - , - {CTLX | CONTROL | 'L', lowerregion} - , - {CTLX | CONTROL | 'M', delmode} - , - {CTLX | CONTROL | 'N', mvdnwind} - , - {CTLX | CONTROL | 'O', deblank} - , - {CTLX | CONTROL | 'P', mvupwind} - , - {CTLX | CONTROL | 'R', fileread} - , - {CTLX | CONTROL | 'S', filesave} - , -#if AEDIT - {CTLX | CONTROL | 'T', trim} - , -#endif - {CTLX | CONTROL | 'U', upperregion} - , - {CTLX | CONTROL | 'V', viewfile} - , - {CTLX | CONTROL | 'W', filewrite} - , - {CTLX | CONTROL | 'X', swapmark} - , - {CTLX | CONTROL | 'Z', shrinkwind} - , - {CTLX | '?', deskey} - , - {CTLX | '!', spawn} - , - {CTLX | '@', pipecmd} - , - {CTLX | '#', filter_buffer} - , - {CTLX | '$', execprg} - , - {CTLX | '=', showcpos} - , - {CTLX | '(', ctlxlp} - , - {CTLX | ')', ctlxrp} - , - {CTLX | '^', enlargewind} - , - {CTLX | '0', delwind} - , - {CTLX | '1', onlywind} - , - {CTLX | '2', splitwind} - , - {CTLX | 'A', setvar} - , - {CTLX | 'B', usebuffer} - , - {CTLX | 'C', spawncli} - , -#if BSD | __hpux | SVR4 - {CTLX | 'D', bktoshell} - , -#endif - {CTLX | 'E', ctlxe} - , - {CTLX | 'F', setfillcol} - , - {CTLX | 'K', killbuffer} - , - {CTLX | 'M', setemode} - , - {CTLX | 'N', filename} - , - {CTLX | 'O', nextwind} - , - {CTLX | 'P', prevwind} - , -#if PKCODE - {CTLX | 'Q', quote} - , /* alternative */ -#endif -#if ISRCH - {CTLX | 'R', risearch} - , - {CTLX | 'S', fisearch} - , -#endif - {CTLX | 'W', resize} - , - {CTLX | 'X', nextbuffer} - , - {CTLX | 'Z', enlargewind} - , -#if WORDPRO - {META | CONTROL | 'C', wordcount} - , -#endif -#if PKCODE - {META | CONTROL | 'D', newsize} - , -#endif -#if PROC - {META | CONTROL | 'E', execproc} - , -#endif -#if CFENCE - {META | CONTROL | 'F', getfence} - , -#endif - {META | CONTROL | 'H', delbword} - , - {META | CONTROL | 'K', unbindkey} - , - {META | CONTROL | 'L', reposition} - , - {META | CONTROL | 'M', delgmode} - , - {META | CONTROL | 'N', namebuffer} - , - {META | CONTROL | 'R', qreplace} - , - {META | CONTROL | 'S', newsize} - , - {META | CONTROL | 'T', newwidth} - , - {META | CONTROL | 'V', scrnextdw} - , -#if WORDPRO - {META | CONTROL | 'W', killpara} - , -#endif - {META | CONTROL | 'Z', scrnextup} - , - {META | ' ', setmark} - , - {META | '?', help} - , - {META | '!', reposition} - , - {META | '.', setmark} - , - {META | '>', gotoeob} - , - {META | '<', gotobob} - , - {META | '~', unmark} - , -#if APROP - {META | 'A', apro} - , -#endif - {META | 'B', backword} - , - {META | 'C', capword} - , - {META | 'D', delfword} - , -#if CRYPT - {META | 'E', set_encryption_key} - , -#endif - {META | 'F', forwword} - , - {META | 'G', gotoline} - , -#if PKCODE -#if WORDPRO - {META | 'J', justpara} - , -#endif -#endif - {META | 'K', bindtokey} - , - {META | 'L', lowerword} - , - {META | 'M', setgmode} - , -#if WORDPRO - {META | 'N', gotoeop} - , - {META | 'P', gotobop} - , - {META | 'Q', fillpara} - , -#endif - {META | 'R', sreplace} - , -#if PKCODE - {META | 'S', forwsearch} - , /* alternative P.K. */ -#else -#if BSD - {META | 'S', bktoshell} - , -#endif -#endif - {META | 'U', upperword} - , - {META | 'V', backpage} - , - {META | 'W', copyregion} - , - {META | 'X', namedcmd} - , - {META | 'Z', quickexit} - , - {META | 0x7F, delbword} - , - -#if MSDOS - {SPEC | CONTROL | '_', forwhunt} - , - {SPEC | CONTROL | 'S', backhunt} - , - {SPEC | 71, gotobol} - , - {SPEC | 72, backline} - , - {SPEC | 73, backpage} - , - {SPEC | 75, backchar} - , - {SPEC | 77, forwchar} - , - {SPEC | 79, gotoeol} - , - {SPEC | 80, forwline} - , - {SPEC | 81, forwpage} - , - {SPEC | 82, insspace} - , - {SPEC | 83, forwdel} - , - {SPEC | 115, backword} - , - {SPEC | 116, forwword} - , -#if WORDPRO - {SPEC | 132, gotobop} - , - {SPEC | 118, gotoeop} - , -#endif - {SPEC | 84, cbuf1} - , - {SPEC | 85, cbuf2} - , - {SPEC | 86, cbuf3} - , - {SPEC | 87, cbuf4} - , - {SPEC | 88, cbuf5} - , - {SPEC | 89, cbuf6} - , - {SPEC | 90, cbuf7} - , - {SPEC | 91, cbuf8} - , - {SPEC | 92, cbuf9} - , - {SPEC | 93, cbuf10} - , #if PKCODE - {SPEC | 117, gotoeob} - , - {SPEC | 119, gotobob} - , - {SPEC | 141, gotobop} - , - {SPEC | 145, gotoeop} - , - {SPEC | 146, yank} - , - {SPEC | 147, killregion} - , + {CTLX | CONTROL | 'D', filesave} + , /* alternative */ +#else +#if AEDIT + {CTLX | CONTROL | 'D', detab} + , +#endif +#endif +#if AEDIT + {CTLX | CONTROL | 'E', entab} + , +#endif + {CTLX | CONTROL | 'F', filefind} + , + {CTLX | CONTROL | 'I', insfile} + , + {CTLX | CONTROL | 'L', lowerregion} + , + {CTLX | CONTROL | 'M', delmode} + , + {CTLX | CONTROL | 'N', mvdnwind} + , + {CTLX | CONTROL | 'O', deblank} + , + {CTLX | CONTROL | 'P', mvupwind} + , + {CTLX | CONTROL | 'R', fileread} + , + {CTLX | CONTROL | 'S', filesave} + , +#if AEDIT + {CTLX | CONTROL | 'T', trim} + , +#endif + {CTLX | CONTROL | 'U', upperregion} + , + {CTLX | CONTROL | 'V', viewfile} + , + {CTLX | CONTROL | 'W', filewrite} + , + {CTLX | CONTROL | 'X', swapmark} + , + {CTLX | CONTROL | 'Z', shrinkwind} + , + {CTLX | '?', deskey} + , + {CTLX | '!', spawn} + , + {CTLX | '@', pipecmd} + , + {CTLX | '#', filter_buffer} + , + {CTLX | '$', execprg} + , + {CTLX | '=', showcpos} + , + {CTLX | '(', ctlxlp} + , + {CTLX | ')', ctlxrp} + , + {CTLX | '^', enlargewind} + , + {CTLX | '0', delwind} + , + {CTLX | '1', onlywind} + , + {CTLX | '2', splitwind} + , + {CTLX | 'A', setvar} + , + {CTLX | 'B', usebuffer} + , + {CTLX | 'C', spawncli} + , +#if BSD | __hpux | SVR4 + {CTLX | 'D', bktoshell} + , +#endif + {CTLX | 'E', ctlxe} + , + {CTLX | 'F', setfillcol} + , + {CTLX | 'K', killbuffer} + , + {CTLX | 'M', setemode} + , + {CTLX | 'N', filename} + , + {CTLX | 'O', nextwind} + , + {CTLX | 'P', prevwind} + , +#if PKCODE + {CTLX | 'Q', quote} + , /* alternative */ +#endif +#if ISRCH + {CTLX | 'R', risearch} + , + {CTLX | 'S', fisearch} + , +#endif + {CTLX | 'W', resize} + , + {CTLX | 'X', nextbuffer} + , + {CTLX | 'Z', enlargewind} + , +#if WORDPRO + {META | CONTROL | 'C', wordcount} + , +#endif +#if PKCODE + {META | CONTROL | 'D', newsize} + , +#endif +#if PROC + {META | CONTROL | 'E', execproc} + , +#endif +#if CFENCE + {META | CONTROL | 'F', getfence} + , +#endif + {META | CONTROL | 'H', delbword} + , + {META | CONTROL | 'K', unbindkey} + , + {META | CONTROL | 'L', reposition} + , + {META | CONTROL | 'M', delgmode} + , + {META | CONTROL | 'N', namebuffer} + , + {META | CONTROL | 'R', qreplace} + , + {META | CONTROL | 'S', newsize} + , + {META | CONTROL | 'T', newwidth} + , + {META | CONTROL | 'V', scrnextdw} + , +#if WORDPRO + {META | CONTROL | 'W', killpara} + , +#endif + {META | CONTROL | 'Z', scrnextup} + , + {META | ' ', setmark} + , + {META | '?', help} + , + {META | '!', reposition} + , + {META | '.', setmark} + , + {META | '>', gotoeob} + , + {META | '<', gotobob} + , + {META | '~', unmark} + , +#if APROP + {META | 'A', apro} + , +#endif + {META | 'B', backword} + , + {META | 'C', capword} + , + {META | 'D', delfword} + , +#if CRYPT + {META | 'E', set_encryption_key} + , +#endif + {META | 'F', forwword} + , + {META | 'G', gotoline} + , +#if PKCODE +#if WORDPRO + {META | 'J', justpara} + , +#endif +#endif + {META | 'K', bindtokey} + , + {META | 'L', lowerword} + , + {META | 'M', setgmode} + , +#if WORDPRO + {META | 'N', gotoeop} + , + {META | 'P', gotobop} + , + {META | 'Q', fillpara} + , +#endif + {META | 'R', sreplace} + , +#if PKCODE + {META | 'S', forwsearch} + , /* alternative P.K. */ +#else +#if BSD + {META | 'S', bktoshell} + , +#endif +#endif + {META | 'U', upperword} + , + {META | 'V', backpage} + , + {META | 'W', copyregion} + , + {META | 'X', namedcmd} + , + {META | 'Z', quickexit} + , + {META | 0x7F, delbword} + , + +#if MSDOS + {SPEC | CONTROL | '_', forwhunt} + , + {SPEC | CONTROL | 'S', backhunt} + , + {SPEC | 71, gotobol} + , + {SPEC | 72, backline} + , + {SPEC | 73, backpage} + , + {SPEC | 75, backchar} + , + {SPEC | 77, forwchar} + , + {SPEC | 79, gotoeol} + , + {SPEC | 80, forwline} + , + {SPEC | 81, forwpage} + , + {SPEC | 82, insspace} + , + {SPEC | 83, forwdel} + , + {SPEC | 115, backword} + , + {SPEC | 116, forwword} + , +#if WORDPRO + {SPEC | 132, gotobop} + , + {SPEC | 118, gotoeop} + , +#endif + {SPEC | 84, cbuf1} + , + {SPEC | 85, cbuf2} + , + {SPEC | 86, cbuf3} + , + {SPEC | 87, cbuf4} + , + {SPEC | 88, cbuf5} + , + {SPEC | 89, cbuf6} + , + {SPEC | 90, cbuf7} + , + {SPEC | 91, cbuf8} + , + {SPEC | 92, cbuf9} + , + {SPEC | 93, cbuf10} + , +#if PKCODE + {SPEC | 117, gotoeob} + , + {SPEC | 119, gotobob} + , + {SPEC | 141, gotobop} + , + {SPEC | 145, gotoeop} + , + {SPEC | 146, yank} + , + {SPEC | 147, killregion} + , #endif #endif -#if VT220 - {SPEC | '1', fisearch} - , /* VT220 keys */ - {SPEC | '2', yank} - , - {SPEC | '3', killregion} - , - {SPEC | '4', setmark} - , - {SPEC | '5', backpage} - , - {SPEC | '6', forwpage} - , - {SPEC | 'A', backline} - , - {SPEC | 'B', forwline} - , - {SPEC | 'C', forwchar} - , - {SPEC | 'D', backchar} - , - {SPEC | 'c', metafn} - , - {SPEC | 'd', backchar} - , - {SPEC | 'e', forwline} - , - {SPEC | 'f', gotobob} - , - {SPEC | 'h', help} - , - {SPEC | 'i', cex} - , +#if VT220 + {SPEC | '1', fisearch} + , /* VT220 keys */ + {SPEC | '2', yank} + , + {SPEC | '3', killregion} + , + {SPEC | '4', setmark} + , + {SPEC | '5', backpage} + , + {SPEC | '6', forwpage} + , + {SPEC | 'A', backline} + , + {SPEC | 'B', forwline} + , + {SPEC | 'C', forwchar} + , + {SPEC | 'D', backchar} + , + {SPEC | 'c', metafn} + , + {SPEC | 'd', backchar} + , + {SPEC | 'e', forwline} + , + {SPEC | 'f', gotobob} + , + {SPEC | 'h', help} + , + {SPEC | 'i', cex} + , #endif - {0x7F, backdel} - , + {0x7F, backdel} + , - /* special internal bindings */ - { SPEC | META | 'W', wrapword }, /* called on word wrap */ - { SPEC | META | 'C', nullproc }, /* every command input */ - { SPEC | META | 'R', nullproc }, /* on file read */ - { SPEC | META | 'X', nullproc }, /* on window change P.K. */ + /* special internal bindings */ + { SPEC | META | 'W', wrapword }, /* called on word wrap */ + { SPEC | META | 'C', nullproc }, /* every command input */ + { SPEC | META | 'R', nullproc }, /* on file read */ + { SPEC | META | 'X', nullproc }, /* on window change P.K. */ - {0, NULL} + {0, NULL} }; diff --git a/edef.h b/edef.h index 57fdada..251a11e 100644 --- a/edef.h +++ b/edef.h @@ -10,7 +10,6 @@ #ifndef EDEF_H_ #define EDEF_H_ -#include "buffer.h" #include "estruct.h" /* Initialized global external declarations. */ diff --git a/input.c b/input.c index 37ed89a..ae68c28 100644 --- a/input.c +++ b/input.c @@ -2,12 +2,12 @@ #include "input.h" -/* input.c +/* input.c * - * Various input routines + * Various input routines * - * written by Daniel Lawrence 5/9/86 - * modified by Petri Kutvonen + * written by Daniel Lawrence 5/9/86 + * modified by Petri Kutvonen */ #include @@ -15,6 +15,7 @@ #include #include "bind.h" +#include "edef.h" #include "bindable.h" #include "display.h" #include "exec.h" @@ -22,28 +23,28 @@ #include "terminal.h" #include "wrapper.h" -#if PKCODE +#if PKCODE #if MSDOS && TURBO -#include +#include #endif #endif -#if PKCODE && (UNIX || (MSDOS && TURBO)) -#define COMPLC 1 +#if PKCODE && (UNIX || (MSDOS && TURBO)) +#define COMPLC 1 #else -#define COMPLC 0 +#define COMPLC 0 #endif -#define NKBDM 256 /* # of strokes, keyboard macro */ -int kbdm[ NKBDM] ; /* Macro */ -int *kbdptr ; /* current position in keyboard buf */ -int *kbdend = &kbdm[0] ; /* ptr to end of the keyboard */ +#define NKBDM 256 /* # of strokes, keyboard macro */ +int kbdm[ NKBDM] ; /* Macro */ +int *kbdptr ; /* current position in keyboard buf */ +int *kbdend = &kbdm[0] ; /* ptr to end of the keyboard */ -kbdstate kbdmode = STOP ; /* current keyboard macro mode */ -int lastkey = 0 ; /* last keystoke */ -int kbdrep = 0 ; /* number of repetitions */ +kbdstate kbdmode = STOP ; /* current keyboard macro mode */ +int lastkey = 0 ; /* last keystoke */ +int kbdrep = 0 ; /* number of repetitions */ -static const int quotec = 0x11 ; /* quote char during mlreply() */ +static const int quotec = 0x11 ; /* quote char during mlreply() */ /* * Ask a yes or no question in the message line. Return either TRUE, FALSE, or @@ -52,27 +53,27 @@ static const int quotec = 0x11 ; /* quote char during mlreply() */ */ int mlyesno( const char *prompt) { - char c; /* input character */ - char buf[NPAT]; /* prompt to user */ + char c; /* input character */ + char buf[NPAT]; /* prompt to user */ - for (;;) { - /* build and prompt the user */ - strcpy(buf, prompt); - strcat(buf, " (y/n)? "); - mlwrite(buf); + for (;;) { + /* build and prompt the user */ + strcpy(buf, prompt); + strcat(buf, " (y/n)? "); + mlwrite(buf); - /* get the responce */ - c = tgetc(); + /* get the responce */ + c = tgetc(); - if (c == ectoc(abortc)) /* Bail out! */ - return ABORT; + if (c == ectoc(abortc)) /* Bail out! */ + return ABORT; - if (c == 'y' || c == 'Y') - return TRUE; + if (c == 'y' || c == 'Y') + return TRUE; - if (c == 'n' || c == 'N') - return FALSE; - } + if (c == 'n' || c == 'N') + return FALSE; + } } /* @@ -85,38 +86,38 @@ int mlyesno( const char *prompt) int mlreply( const char *prompt, char *buf, int nbuf) { - return nextarg(prompt, buf, nbuf, ctoec('\n')); + return nextarg(prompt, buf, nbuf, ctoec('\n')); } int mlreplyt(const char *prompt, char *buf, int nbuf, int eolchar) { - return nextarg(prompt, buf, nbuf, eolchar); + return nextarg(prompt, buf, nbuf, eolchar); } /* * ectoc: - * expanded character to character - * collapse the CONTROL and SPEC flags back into an ascii code + * expanded character to character + * collapse the CONTROL and SPEC flags back into an ascii code */ int ectoc(int c) { - if (c & CONTROL) - c = c & ~(CONTROL | 0x40); - if (c & SPEC) - c = c & 255; - return c; + if (c & CONTROL) + c = c & ~(CONTROL | 0x40); + if (c & SPEC) + c = c & 255; + return c; } /* * ctoec: - * character to extended character - * pull out the CONTROL and SPEC prefixes (if possible) + * character to extended character + * pull out the CONTROL and SPEC prefixes (if possible) */ int ctoec(int c) { - if (c >= 0x00 && c <= 0x1F) - c = CONTROL | (c + '@'); - return c; + if (c >= 0x00 && c <= 0x1F) + c = CONTROL | (c + '@'); + return c; } /* @@ -126,615 +127,615 @@ int ctoec(int c) */ fn_t getname(void) { - int cpos; /* current column on screen output */ - int c; - char *sp; /* pointer to string for output */ - struct name_bind *ffp; /* first ptr to entry in name binding table */ - struct name_bind *cffp; /* current ptr to entry in name binding table */ - struct name_bind *lffp; /* last ptr to entry in name binding table */ - char buf[NSTRING]; /* buffer to hold tentative command name */ + int cpos; /* current column on screen output */ + int c; + char *sp; /* pointer to string for output */ + struct name_bind *ffp; /* first ptr to entry in name binding table */ + struct name_bind *cffp; /* current ptr to entry in name binding table */ + struct name_bind *lffp; /* last ptr to entry in name binding table */ + char buf[NSTRING]; /* buffer to hold tentative command name */ - /* starting at the beginning of the string buffer */ - cpos = 0; + /* starting at the beginning of the string buffer */ + cpos = 0; - /* if we are executing a command line get the next arg and match it */ - if (clexec) { - if (macarg(buf) != TRUE) - return NULL; - return fncmatch(&buf[0]); - } + /* if we are executing a command line get the next arg and match it */ + if (clexec) { + if (macarg(buf) != TRUE) + return NULL; + return fncmatch(&buf[0]); + } - /* build a name string from the keyboard */ - while (TRUE) { - c = tgetc(); + /* build a name string from the keyboard */ + while (TRUE) { + c = tgetc(); - /* if we are at the end, just match it */ - if (c == 0x0d) { - buf[cpos] = 0; + /* if we are at the end, just match it */ + if (c == 0x0d) { + buf[cpos] = 0; - /* and match it off */ - return fncmatch(&buf[0]); + /* and match it off */ + return fncmatch(&buf[0]); - } else if (c == ectoc(abortc)) { /* Bell, abort */ - ctrlg(FALSE, 0); - TTflush(); - return NULL; + } else if (c == ectoc(abortc)) { /* Bell, abort */ + ctrlg(FALSE, 0); + TTflush(); + return NULL; - } else if (c == 0x7F || c == 0x08) { /* rubout/erase */ - if (cpos != 0) { - TTputc('\b'); - TTputc(' '); - TTputc('\b'); - --ttcol; - --cpos; - TTflush(); - } + } else if (c == 0x7F || c == 0x08) { /* rubout/erase */ + if (cpos != 0) { + TTputc('\b'); + TTputc(' '); + TTputc('\b'); + --ttcol; + --cpos; + TTflush(); + } - } else if (c == 0x15) { /* C-U, kill */ - while (cpos != 0) { - TTputc('\b'); - TTputc(' '); - TTputc('\b'); - --cpos; - --ttcol; - } + } else if (c == 0x15) { /* C-U, kill */ + while (cpos != 0) { + TTputc('\b'); + TTputc(' '); + TTputc('\b'); + --cpos; + --ttcol; + } - TTflush(); + TTflush(); - } else if (c == ' ' || c == 0x1b || c == 0x09) { + } else if (c == ' ' || c == 0x1b || c == 0x09) { /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ - /* attempt a completion */ - buf[cpos] = 0; /* terminate it for us */ - ffp = &names[0]; /* scan for matches */ - while (ffp->n_func != NULL) { - if (strncmp(buf, ffp->n_name, strlen(buf)) - == 0) { - /* a possible match! More than one? */ - if ((ffp + 1)->n_func == NULL || - (strncmp - (buf, (ffp + 1)->n_name, - strlen(buf)) != 0)) { - /* no...we match, print it */ - sp = ffp->n_name + cpos; - while (*sp) - TTputc(*sp++); - TTflush(); - return ffp->n_func; - } else { + /* attempt a completion */ + buf[cpos] = 0; /* terminate it for us */ + ffp = &names[0]; /* scan for matches */ + while (ffp->n_func != NULL) { + if (strncmp(buf, ffp->n_name, strlen(buf)) + == 0) { + /* a possible match! More than one? */ + if ((ffp + 1)->n_func == NULL || + (strncmp + (buf, (ffp + 1)->n_name, + strlen(buf)) != 0)) { + /* no...we match, print it */ + sp = ffp->n_name + cpos; + while (*sp) + TTputc(*sp++); + TTflush(); + return ffp->n_func; + } else { /* << << << << << << << << << << << << << << << << << */ - /* try for a partial match against the list */ + /* try for a partial match against the list */ - /* first scan down until we no longer match the current input */ - lffp = (ffp + 1); - while ((lffp + - 1)->n_func != - NULL) { - if (strncmp - (buf, - (lffp + - 1)->n_name, - strlen(buf)) - != 0) - break; - ++lffp; - } + /* first scan down until we no longer match the current input */ + lffp = (ffp + 1); + while ((lffp + + 1)->n_func != + NULL) { + if (strncmp + (buf, + (lffp + + 1)->n_name, + strlen(buf)) + != 0) + break; + ++lffp; + } - /* and now, attempt to partial complete the string, char at a time */ - while (TRUE) { - /* add the next char in */ - buf[cpos] = - ffp-> - n_name[cpos]; + /* and now, attempt to partial complete the string, char at a time */ + while (TRUE) { + /* add the next char in */ + buf[cpos] = + ffp-> + n_name[cpos]; - /* scan through the candidates */ - cffp = ffp + 1; - while (cffp <= - lffp) { - if (cffp-> - n_name - [cpos] - != - buf - [cpos]) - goto onward; - ++cffp; - } + /* scan through the candidates */ + cffp = ffp + 1; + while (cffp <= + lffp) { + if (cffp-> + n_name + [cpos] + != + buf + [cpos]) + goto onward; + ++cffp; + } - /* add the character */ - TTputc(buf - [cpos++]); - } + /* add the character */ + TTputc(buf + [cpos++]); + } /* << << << << << << << << << << << << << << << << << */ - } - } - ++ffp; - } + } + } + ++ffp; + } - /* no match.....beep and onward */ - TTbeep(); - onward:; - TTflush(); + /* no match.....beep and onward */ + TTbeep(); + onward:; + TTflush(); /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ - } else { - if (cpos < NSTRING - 1 && c > ' ') { - buf[cpos++] = c; - TTputc(c); - } + } else { + if (cpos < NSTRING - 1 && c > ' ') { + buf[cpos++] = c; + TTputc(c); + } - ++ttcol; - TTflush(); - } - } + ++ttcol; + TTflush(); + } + } } -/* tgetc: Get a key from the terminal driver, resolve any keyboard - macro action */ +/* tgetc: Get a key from the terminal driver, resolve any keyboard + macro action */ int tgetc(void) { - int c; /* fetched character */ + int c; /* fetched character */ - /* if we are playing a keyboard macro back, */ - if (kbdmode == PLAY) { + /* if we are playing a keyboard macro back, */ + if (kbdmode == PLAY) { - /* if there is some left... */ - if (kbdptr < kbdend) - return (int) *kbdptr++; + /* if there is some left... */ + if (kbdptr < kbdend) + return (int) *kbdptr++; - /* at the end of last repitition? */ - if (--kbdrep < 1) { - kbdmode = STOP; -#if VISMAC == 0 - /* force a screen update after all is done */ - update(FALSE); + /* at the end of last repitition? */ + if (--kbdrep < 1) { + kbdmode = STOP; +#if VISMAC == 0 + /* force a screen update after all is done */ + update(FALSE); #endif - } else { + } else { - /* reset the macro to the begining for the next rep */ - kbdptr = &kbdm[0]; - return (int) *kbdptr++; - } - } + /* reset the macro to the begining for the next rep */ + kbdptr = &kbdm[0]; + return (int) *kbdptr++; + } + } - /* fetch a character from the terminal driver */ - c = TTgetc(); + /* fetch a character from the terminal driver */ + c = TTgetc(); - /* record it for $lastkey */ - lastkey = c; + /* record it for $lastkey */ + lastkey = c; - /* save it if we need to */ - if (kbdmode == RECORD) { - *kbdptr++ = c; - kbdend = kbdptr; + /* save it if we need to */ + if (kbdmode == RECORD) { + *kbdptr++ = c; + kbdend = kbdptr; - /* don't overrun the buffer */ - if (kbdptr == &kbdm[NKBDM - 1]) { - kbdmode = STOP; - TTbeep(); - } - } + /* don't overrun the buffer */ + if (kbdptr == &kbdm[NKBDM - 1]) { + kbdmode = STOP; + TTbeep(); + } + } - /* and finally give the char back */ - return c; + /* and finally give the char back */ + return c; } -/* GET1KEY: Get one keystroke. The only prefixs legal here - are the SPEC and CONTROL prefixes. - */ +/* GET1KEY: Get one keystroke. The only prefixs legal here + are the SPEC and CONTROL prefixes. + */ int get1key(void) { - int c; + int c; - /* get a keystroke */ - c = tgetc(); + /* get a keystroke */ + c = tgetc(); -#if MSDOS - if (c == 0) { /* Apply SPEC prefix */ - c = tgetc(); - if (c >= 0x00 && c <= 0x1F) /* control key? */ - c = CONTROL | (c + '@'); - return SPEC | c; - } +#if MSDOS + if (c == 0) { /* Apply SPEC prefix */ + c = tgetc(); + if (c >= 0x00 && c <= 0x1F) /* control key? */ + c = CONTROL | (c + '@'); + return SPEC | c; + } #endif - if (c >= 0x00 && c <= 0x1F) /* C0 control -> C- */ - c = CONTROL | (c + '@'); - return c; + if (c >= 0x00 && c <= 0x1F) /* C0 control -> C- */ + c = CONTROL | (c + '@'); + return c; } -/* GETCMD: Get a command from the keyboard. Process all applicable - prefix keys - */ +/* GETCMD: Get a command from the keyboard. Process all applicable + prefix keys + */ int getcmd(void) { - int c; /* fetched keystroke */ + int c; /* fetched keystroke */ #if VT220 - int d; /* second character P.K. */ - int cmask = 0; + int d; /* second character P.K. */ + int cmask = 0; #endif - /* get initial character */ - c = get1key(); + /* get initial character */ + c = get1key(); #if VT220 proc_metac: #endif - if (c == 128+27) /* CSI */ - goto handle_CSI; - /* process META prefix */ - if (c == (CONTROL | '[')) { - c = get1key(); + if (c == 128+27) /* CSI */ + goto handle_CSI; + /* process META prefix */ + if (c == (CONTROL | '[')) { + c = get1key(); #if VT220 - if (c == '[' || c == 'O') { /* CSI P.K. */ + if (c == '[' || c == 'O') { /* CSI P.K. */ handle_CSI: - c = get1key(); - if (c >= 'A' && c <= 'D') - return SPEC | c | cmask; - if (c >= 'E' && c <= 'z' && c != 'i' && c != 'c') - return SPEC | c | cmask; - d = get1key(); - if (d == '~') /* ESC [ n ~ P.K. */ - return SPEC | c | cmask; - switch (c) { /* ESC [ n n ~ P.K. */ - case '1': - c = d + 32; - break; - case '2': - c = d + 48; - break; - case '3': - c = d + 64; - break; - default: - c = '?'; - break; - } - if (d != '~') /* eat tilde P.K. */ - get1key(); - if (c == 'i') { /* DO key P.K. */ - c = ctlxc; - goto proc_ctlxc; - } else if (c == 'c') /* ESC key P.K. */ - c = get1key(); - else - return SPEC | c | cmask; - } + c = get1key(); + if (c >= 'A' && c <= 'D') + return SPEC | c | cmask; + if (c >= 'E' && c <= 'z' && c != 'i' && c != 'c') + return SPEC | c | cmask; + d = get1key(); + if (d == '~') /* ESC [ n ~ P.K. */ + return SPEC | c | cmask; + switch (c) { /* ESC [ n n ~ P.K. */ + case '1': + c = d + 32; + break; + case '2': + c = d + 48; + break; + case '3': + c = d + 64; + break; + default: + c = '?'; + break; + } + if (d != '~') /* eat tilde P.K. */ + get1key(); + if (c == 'i') { /* DO key P.K. */ + c = ctlxc; + goto proc_ctlxc; + } else if (c == 'c') /* ESC key P.K. */ + c = get1key(); + else + return SPEC | c | cmask; + } #endif #if VT220 - if (c == (CONTROL | '[')) { - cmask = META; - goto proc_metac; - } + if (c == (CONTROL | '[')) { + cmask = META; + goto proc_metac; + } #endif - if (islower(c)) /* Force to upper */ - c ^= DIFCASE; - if (c >= 0x00 && c <= 0x1F) /* control key */ - c = CONTROL | (c + '@'); - return META | c; - } -#if PKCODE - else if (c == metac) { - c = get1key(); + if (islower(c)) /* Force to upper */ + c ^= DIFCASE; + if (c >= 0x00 && c <= 0x1F) /* control key */ + c = CONTROL | (c + '@'); + return META | c; + } +#if PKCODE + else if (c == metac) { + c = get1key(); #if VT220 - if (c == (CONTROL | '[')) { - cmask = META; - goto proc_metac; - } + if (c == (CONTROL | '[')) { + cmask = META; + goto proc_metac; + } #endif - if (islower(c)) /* Force to upper */ - c ^= DIFCASE; - if (c >= 0x00 && c <= 0x1F) /* control key */ - c = CONTROL | (c + '@'); - return META | c; - } + if (islower(c)) /* Force to upper */ + c ^= DIFCASE; + if (c >= 0x00 && c <= 0x1F) /* control key */ + c = CONTROL | (c + '@'); + return META | c; + } #endif -#if VT220 +#if VT220 proc_ctlxc: #endif - /* process CTLX prefix */ - if (c == ctlxc) { - c = get1key(); + /* process CTLX prefix */ + if (c == ctlxc) { + c = get1key(); #if VT220 - if (c == (CONTROL | '[')) { - cmask = CTLX; - goto proc_metac; - } + if (c == (CONTROL | '[')) { + cmask = CTLX; + goto proc_metac; + } #endif - if (c >= 'a' && c <= 'z') /* Force to upper */ - c -= 0x20; - if (c >= 0x00 && c <= 0x1F) /* control key */ - c = CONTROL | (c + '@'); - return CTLX | c; - } + if (c >= 'a' && c <= 'z') /* Force to upper */ + c -= 0x20; + if (c >= 0x00 && c <= 0x1F) /* control key */ + c = CONTROL | (c + '@'); + return CTLX | c; + } - /* otherwise, just return it */ - return c; + /* otherwise, just return it */ + return c; } -/* A more generalized prompt/reply function allowing the caller - to specify the proper terminator. If the terminator is not - a return ('\n') it will echo as "" - */ +/* A more generalized prompt/reply function allowing the caller + to specify the proper terminator. If the terminator is not + a return ('\n') it will echo as "" + */ int getstring( const char *prompt, char *buf, int nbuf, int eolchar) { - int cpos; /* current character position in string */ - int c; - boolean quotef ; /* are we quoting the next char? */ -#if COMPLC - int ffile, ocpos, nskip = 0, didtry = 0; + int cpos; /* current character position in string */ + int c; + boolean quotef ; /* are we quoting the next char? */ +#if COMPLC + int ffile, ocpos, nskip = 0, didtry = 0; #if MSDOS - struct ffblk ffblk; - char *fcp; + struct ffblk ffblk; + char *fcp; #endif -#if UNIX - static char tmp[] = "/tmp/meXXXXXX"; - FILE *tmpf = NULL; +#if UNIX + static char tmp[] = "/tmp/meXXXXXX"; + FILE *tmpf = NULL; #endif - ffile = (strcmp(prompt, "Find file: ") == 0 - || strcmp(prompt, "View file: ") == 0 - || strcmp(prompt, "Insert file: ") == 0 - || strcmp(prompt, "Write file: ") == 0 - || strcmp(prompt, "Read file: ") == 0 - || strcmp(prompt, "File to execute: ") == 0); + ffile = (strcmp(prompt, "Find file: ") == 0 + || strcmp(prompt, "View file: ") == 0 + || strcmp(prompt, "Insert file: ") == 0 + || strcmp(prompt, "Write file: ") == 0 + || strcmp(prompt, "Read file: ") == 0 + || strcmp(prompt, "File to execute: ") == 0); #endif - cpos = 0; - quotef = FALSE; + cpos = 0; + quotef = FALSE; - /* prompt the user for the input string */ - mlwrite(prompt); + /* prompt the user for the input string */ + mlwrite(prompt); - for (;;) { -#if COMPLC - if (!didtry) - nskip = -1; - didtry = 0; + for (;;) { +#if COMPLC + if (!didtry) + nskip = -1; + didtry = 0; #endif - /* get a character from the user */ - c = get1key(); + /* get a character from the user */ + c = get1key(); - /* If it is a , change it to a */ -#if PKCODE - if (c == (CONTROL | 0x4d) && !quotef) + /* If it is a , change it to a */ +#if PKCODE + if (c == (CONTROL | 0x4d) && !quotef) #else - if (c == (CONTROL | 0x4d)) + if (c == (CONTROL | 0x4d)) #endif - c = CONTROL | 0x40 | '\n'; + c = CONTROL | 0x40 | '\n'; - /* if they hit the line terminate, wrap it up */ - if (c == eolchar && quotef == FALSE) { - buf[cpos++] = 0; + /* if they hit the line terminate, wrap it up */ + if (c == eolchar && quotef == FALSE) { + buf[cpos++] = 0; - /* clear the message line */ - mlwrite(""); - TTflush(); + /* clear the message line */ + mlwrite(""); + TTflush(); - /* if we default the buffer, return FALSE */ - if (buf[0] == 0) - return FALSE; + /* if we default the buffer, return FALSE */ + if (buf[0] == 0) + return FALSE; - return TRUE; - } + return TRUE; + } - /* change from command form back to character form */ - c = ectoc(c); + /* change from command form back to character form */ + c = ectoc(c); - if (c == ectoc(abortc) && quotef == FALSE) { - /* Abort the input? */ - ctrlg(FALSE, 0); - TTflush(); - return ABORT; - } else if ((c == 0x7F || c == 0x08) && quotef == FALSE) { - /* rubout/erase */ - if (cpos != 0) { - outstring("\b \b"); - --ttcol; + if (c == ectoc(abortc) && quotef == FALSE) { + /* Abort the input? */ + ctrlg(FALSE, 0); + TTflush(); + return ABORT; + } else if ((c == 0x7F || c == 0x08) && quotef == FALSE) { + /* rubout/erase */ + if (cpos != 0) { + outstring("\b \b"); + --ttcol; - if (buf[--cpos] < 0x20) { - outstring("\b \b"); - --ttcol; - } - if (buf[cpos] == '\n') { - outstring("\b\b \b\b"); - ttcol -= 2; - } + if (buf[--cpos] < 0x20) { + outstring("\b \b"); + --ttcol; + } + if (buf[cpos] == '\n') { + outstring("\b\b \b\b"); + ttcol -= 2; + } - TTflush(); - } + TTflush(); + } - } else if (c == 0x15 && quotef == FALSE) { - /* C-U, kill */ - while (cpos != 0) { - outstring("\b \b"); - --ttcol; + } else if (c == 0x15 && quotef == FALSE) { + /* C-U, kill */ + while (cpos != 0) { + outstring("\b \b"); + --ttcol; - if (buf[--cpos] < 0x20) { - outstring("\b \b"); - --ttcol; - } - if (buf[cpos] == '\n') { - outstring("\b\b \b\b"); - ttcol -= 2; - } - } - TTflush(); + if (buf[--cpos] < 0x20) { + outstring("\b \b"); + --ttcol; + } + if (buf[cpos] == '\n') { + outstring("\b\b \b\b"); + ttcol -= 2; + } + } + TTflush(); -#if COMPLC - } else if ((c == 0x09 || c == ' ') && quotef == FALSE - && ffile) { - /* TAB, complete file name */ - char ffbuf[255]; -#if MSDOS - char sffbuf[128]; - int lsav = -1; +#if COMPLC + } else if ((c == 0x09 || c == ' ') && quotef == FALSE + && ffile) { + /* TAB, complete file name */ + char ffbuf[255]; +#if MSDOS + char sffbuf[128]; + int lsav = -1; #endif - int n, iswild = 0; + int n, iswild = 0; - didtry = 1; - ocpos = cpos; - while (cpos != 0) { - outstring("\b \b"); - --ttcol; + didtry = 1; + ocpos = cpos; + while (cpos != 0) { + outstring("\b \b"); + --ttcol; - if (buf[--cpos] < 0x20) { - outstring("\b \b"); - --ttcol; - } - if (buf[cpos] == '\n') { - outstring("\b\b \b\b"); - ttcol -= 2; - } - if (buf[cpos] == '*' || buf[cpos] == '?') - iswild = 1; -#if MSDOS - if (lsav < 0 && (buf[cpos] == '\\' || - buf[cpos] == '/' || - buf[cpos] == ':' - && cpos == 1)) - lsav = cpos; + if (buf[--cpos] < 0x20) { + outstring("\b \b"); + --ttcol; + } + if (buf[cpos] == '\n') { + outstring("\b\b \b\b"); + ttcol -= 2; + } + if (buf[cpos] == '*' || buf[cpos] == '?') + iswild = 1; +#if MSDOS + if (lsav < 0 && (buf[cpos] == '\\' || + buf[cpos] == '/' || + buf[cpos] == ':' + && cpos == 1)) + lsav = cpos; #endif - } - TTflush(); - if (nskip < 0) { - buf[ocpos] = 0; -#if UNIX - if (tmpf != NULL) - fclose(tmpf); - strcpy(tmp, "/tmp/meXXXXXX"); - strcpy(ffbuf, "echo "); - strcat(ffbuf, buf); - if (!iswild) - strcat(ffbuf, "*"); - strcat(ffbuf, " >"); - xmkstemp(tmp); - strcat(ffbuf, tmp); - strcat(ffbuf, " 2>&1"); - system(ffbuf); - tmpf = fopen(tmp, "r"); + } + TTflush(); + if (nskip < 0) { + buf[ocpos] = 0; +#if UNIX + if (tmpf != NULL) + fclose(tmpf); + strcpy(tmp, "/tmp/meXXXXXX"); + strcpy(ffbuf, "echo "); + strcat(ffbuf, buf); + if (!iswild) + strcat(ffbuf, "*"); + strcat(ffbuf, " >"); + xmkstemp(tmp); + strcat(ffbuf, tmp); + strcat(ffbuf, " 2>&1"); + system(ffbuf); + tmpf = fopen(tmp, "r"); #endif -#if MSDOS - strcpy(sffbuf, buf); - if (!iswild) - strcat(sffbuf, "*.*"); +#if MSDOS + strcpy(sffbuf, buf); + if (!iswild) + strcat(sffbuf, "*.*"); #endif - nskip = 0; - } -#if UNIX - c = ' '; - for (n = nskip; n > 0; n--) - while ((c = getc(tmpf)) != EOF - && c != ' '); + nskip = 0; + } +#if UNIX + c = ' '; + for (n = nskip; n > 0; n--) + while ((c = getc(tmpf)) != EOF + && c != ' '); #endif -#if MSDOS - if (nskip == 0) { - strcpy(ffbuf, sffbuf); - c = findfirst(ffbuf, &ffblk, - FA_DIREC) ? '*' : ' '; - } else if (nskip > 0) - c = findnext(&ffblk) ? 0 : ' '; +#if MSDOS + if (nskip == 0) { + strcpy(ffbuf, sffbuf); + c = findfirst(ffbuf, &ffblk, + FA_DIREC) ? '*' : ' '; + } else if (nskip > 0) + c = findnext(&ffblk) ? 0 : ' '; #endif - nskip++; + nskip++; - if (c != ' ') { - TTbeep(); - nskip = 0; - } -#if UNIX - while ((c = getc(tmpf)) != EOF && c != '\n' - && c != ' ' && c != '*') + if (c != ' ') { + TTbeep(); + nskip = 0; + } +#if UNIX + while ((c = getc(tmpf)) != EOF && c != '\n' + && c != ' ' && c != '*') #endif -#if MSDOS - if (c == '*') - fcp = sffbuf; - else { - strncpy(buf, sffbuf, lsav + 1); - cpos = lsav + 1; - fcp = ffblk.ff_name; - } - while (c != 0 && (c = *fcp++) != 0 && c != '*') +#if MSDOS + if (c == '*') + fcp = sffbuf; + else { + strncpy(buf, sffbuf, lsav + 1); + cpos = lsav + 1; + fcp = ffblk.ff_name; + } + while (c != 0 && (c = *fcp++) != 0 && c != '*') #endif - { - if (cpos < nbuf - 1) - buf[cpos++] = c; - } -#if UNIX - if (c == '*') - TTbeep(); + { + if (cpos < nbuf - 1) + buf[cpos++] = c; + } +#if UNIX + if (c == '*') + TTbeep(); #endif - for (n = 0; n < cpos; n++) { - c = buf[n]; - if ((c < ' ') && (c != '\n')) { - outstring("^"); - ++ttcol; - c ^= 0x40; - } + for (n = 0; n < cpos; n++) { + c = buf[n]; + if ((c < ' ') && (c != '\n')) { + outstring("^"); + ++ttcol; + c ^= 0x40; + } - if (c != '\n') { - if (disinp) - TTputc(c); - } else { /* put out for */ - outstring(""); - ttcol += 3; - } - ++ttcol; - } - TTflush(); -#if UNIX - rewind(tmpf); - unlink(tmp); + if (c != '\n') { + if (disinp) + TTputc(c); + } else { /* put out for */ + outstring(""); + ttcol += 3; + } + ++ttcol; + } + TTflush(); +#if UNIX + rewind(tmpf); + unlink(tmp); #endif #endif - } else if ((c == quotec || c == 0x16) && quotef == FALSE) { - quotef = TRUE; - } else { - quotef = FALSE; - if (cpos < nbuf - 1) { - buf[cpos++] = c; + } else if ((c == quotec || c == 0x16) && quotef == FALSE) { + quotef = TRUE; + } else { + quotef = FALSE; + if (cpos < nbuf - 1) { + buf[cpos++] = c; - if ((c < ' ') && (c != '\n')) { - outstring("^"); - ++ttcol; - c ^= 0x40; - } + if ((c < ' ') && (c != '\n')) { + outstring("^"); + ++ttcol; + c ^= 0x40; + } - if (c != '\n') { - if (disinp) - TTputc(c); - } else { /* put out for */ - outstring(""); - ttcol += 3; - } - ++ttcol; - TTflush(); - } - } - } + if (c != '\n') { + if (disinp) + TTputc(c); + } else { /* put out for */ + outstring(""); + ttcol += 3; + } + ++ttcol; + TTflush(); + } + } + } } /* * output a string of characters * - * char *s; string to output + * char *s; string to output */ void outstring(char *s) { - if (disinp) - while (*s) - TTputc(*s++); + if (disinp) + while (*s) + TTputc(*s++); } /* * output a string of output characters * - * char *s; string to output + * char *s; string to output */ void ostring(char *s) { - if (discmd) - while (*s) - TTputc(*s++); + if (discmd) + while (*s) + TTputc(*s++); }