diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-04-13 06:12:19 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-04-13 06:12:19 +0000 |
commit | 731317961dd78a8a6a84be2b662b9691fcf40d5a (patch) | |
tree | 642f051b45a10e806a55322912dad11e53435ab7 /usr.bin/mg | |
parent | f54a169ac01105217cbf6e3dfa39f465f0bde571 (diff) |
The start of KNF + -Wall. The code has been run through indent but
needs hand fixup. I stopped at keymap.c...
Diffstat (limited to 'usr.bin/mg')
38 files changed, 6221 insertions, 5325 deletions
diff --git a/usr.bin/mg/README b/usr.bin/mg/README index e37a3c26b06..3b6f8d4f1d6 100644 --- a/usr.bin/mg/README +++ b/usr.bin/mg/README @@ -18,18 +18,15 @@ copyright restrictions.) The Mg authors individually may or may not agree with the opinions expressed by Richard Stallman in "The GNU Manifesto". -To avoid GNU copyright restrictions, replace the re_search.c, regex.h -and regex.c files with empty files. - Documentation of Mg is in the TeX file mg.tex. This should be -formatted with the TeX text formatter and printed. A start twords a mg -programmers guied in in mgprog.doc, and some of the changes from 1b +formatted with the TeX text formatter and printed. A start twords a +mg programmers guide is in mgprog.doc, and some of the changes from 1b are mentioned briefly in mg2a.change. This program is intended to be a small, fast, and portable editor for -people who can't (or don't want to) run real Emacs thing for one -reason or another. It is compatible with GNU because there shouldn't -be any reason to learn more than one Emacs flavor. We have excised +people who can't (or don't want to) run real Emacs for one reason +or another. It is compatible with GNU because there shouldn't be +any reason to learn more than one Emacs flavor. We have excised most MicroEMACS features that were incompatible with the big brother, and added missing features that seemed essential. diff --git a/usr.bin/mg/basic.c b/usr.bin/mg/basic.c index c4095800c0d..990f395a616 100644 --- a/usr.bin/mg/basic.c +++ b/usr.bin/mg/basic.c @@ -7,17 +7,19 @@ * mark. Only moves between lines, which might make the * current buffer framing bad, are hard. */ -#include "def.h" +#include "def.h" -VOID setgoal(); +VOID setgoal __P((void)); /* * Go to beginning of line. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int gotobol(f, n) + int f, n; { - curwp->w_doto = 0; + curwp->w_doto = 0; return (TRUE); } @@ -27,22 +29,24 @@ gotobol(f, n) * 0. Error if you try to move back from * the beginning of the buffer. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int backchar(f, n) -register int n; + int n; { - register LINE *lp; + LINE *lp; - if (n < 0) return forwchar(f, -n); + if (n < 0) + return forwchar(f, -n); while (n--) { if (curwp->w_doto == 0) { - if ((lp=lback(curwp->w_dotp)) == curbp->b_linep) { + if ((lp = lback(curwp->w_dotp)) == curbp->b_linep) { if (!(f & FFRAND)) ewprintf("Beginning of buffer"); return (FALSE); } - curwp->w_dotp = lp; - curwp->w_doto = llength(lp); + curwp->w_dotp = lp; + curwp->w_doto = llength(lp); curwp->w_flag |= WFMOVE; } else curwp->w_doto--; @@ -53,10 +57,12 @@ register int n; /* * Go to end of line. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int gotoeol(f, n) + int f, n; { - curwp->w_doto = llength(curwp->w_dotp); + curwp->w_doto = llength(curwp->w_dotp); return (TRUE); } @@ -66,21 +72,24 @@ gotoeol(f, n) * 0. Error if you try to move forward * from the end of the buffer. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int forwchar(f, n) -register int n; + int f, n; { - if (n < 0) return backchar(f, -n); + + if (n < 0) + return backchar(f, -n); while (n--) { if (curwp->w_doto == llength(curwp->w_dotp)) { - curwp->w_dotp = lforw(curwp->w_dotp); + curwp->w_dotp = lforw(curwp->w_dotp); if (curwp->w_dotp == curbp->b_linep) { curwp->w_dotp = lback(curwp->w_dotp); if (!(f & FFRAND)) ewprintf("End of buffer"); return FALSE; } - curwp->w_doto = 0; + curwp->w_doto = 0; curwp->w_flag |= WFMOVE; } else curwp->w_doto++; @@ -93,11 +102,14 @@ register int n; * buffer. Setting WFHARD is conservative, * but almost always the case. */ +int gotobob(f, n) + int f, n; { - (VOID) setmark(f, n) ; - curwp->w_dotp = lforw(curbp->b_linep); - curwp->w_doto = 0; + + (VOID) setmark(f, n); + curwp->w_dotp = lforw(curbp->b_linep); + curwp->w_doto = 0; curwp->w_flag |= WFHARD; return TRUE; } @@ -107,11 +119,14 @@ gotobob(f, n) * Setting WFHARD is conservative, but * almost always the case. */ +int gotoeob(f, n) + int f, n; { - (VOID) setmark(f, n) ; - curwp->w_dotp = lback(curbp->b_linep); - curwp->w_doto = llength(curwp->w_dotp); + + (VOID) setmark(f, n); + curwp->w_dotp = lback(curbp->b_linep); + curwp->w_doto = llength(curwp->w_dotp); curwp->w_flag |= WFHARD; return TRUE; } @@ -123,37 +138,42 @@ gotoeob(f, n) * actually do it. The last command controls how * the goal column is set. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int forwline(f, n) + int f, n; { - register LINE *dlp; + LINE *dlp; if (n < 0) - return backline(f|FFRAND, -n); - if ((lastflag&CFCPCN) == 0) /* Fix goal. */ + return backline(f | FFRAND, -n); + if ((lastflag & CFCPCN) == 0) /* Fix goal. */ setgoal(); thisflag |= CFCPCN; - if (n == 0) return TRUE; + if (n == 0) + return TRUE; dlp = curwp->w_dotp; - while (dlp!=curbp->b_linep && n--) + while (dlp != curbp->b_linep && n--) dlp = lforw(dlp); curwp->w_flag |= WFMOVE; - if(dlp==curbp->b_linep) { /* ^N at end of buffer creates lines (like gnu) */ - if(!(curbp->b_flag&BFCHG)) { /* first change */ + if (dlp == curbp->b_linep) { /* ^N at end of buffer creates lines + * (like gnu) */ + if (!(curbp->b_flag & BFCHG)) { /* first change */ curbp->b_flag |= BFCHG; curwp->w_flag |= WFMODE; } curwp->w_doto = 0; - while(n-- >= 0) { - if((dlp = lallocx(0)) == NULL) return FALSE; + while (n-- >= 0) { + if ((dlp = lallocx(0)) == NULL) + return FALSE; dlp->l_fp = curbp->b_linep; dlp->l_bp = lback(dlp->l_fp); dlp->l_bp->l_fp = dlp->l_fp->l_bp = dlp; } curwp->w_dotp = lback(curbp->b_linep); } else { - curwp->w_dotp = dlp; - curwp->w_doto = getgoal(dlp); + curwp->w_dotp = dlp; + curwp->w_doto = getgoal(dlp); } return TRUE; } @@ -165,36 +185,38 @@ forwline(f, n) * call your alternate. Figure out the new line and * call "movedot" to perform the motion. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int backline(f, n) + int f, n; { - register LINE *dlp; + LINE *dlp; - if (n < 0) return forwline(f|FFRAND, -n); - if ((lastflag&CFCPCN) == 0) /* Fix goal. */ + if (n < 0) + return forwline(f | FFRAND, -n); + if ((lastflag & CFCPCN) == 0) /* Fix goal. */ setgoal(); thisflag |= CFCPCN; dlp = curwp->w_dotp; - while (n-- && lback(dlp)!=curbp->b_linep) + while (n-- && lback(dlp) != curbp->b_linep) dlp = lback(dlp); - curwp->w_dotp = dlp; - curwp->w_doto = getgoal(dlp); + curwp->w_dotp = dlp; + curwp->w_doto = getgoal(dlp); curwp->w_flag |= WFMOVE; return TRUE; } /* - * Set the current goal column, - * which is saved in the external variable "curgoal", - * to the current cursor column. The column is never off - * the edge of the screen; it's more like display then - * show position. + * Set the current goal column, which is saved in the external variable + * "curgoal", to the current cursor column. The column is never off + * the edge of the screen; it's more like display then show position. */ VOID -setgoal() { +setgoal() +{ - curgoal = getcolpos() - 1; /* Get the position. */ -/* we can now display past end of display, don't chop! */ + curgoal = getcolpos() - 1; /* Get the position. */ + /* we can now display past end of display, don't chop! */ } /* @@ -204,11 +226,14 @@ setgoal() { * routine above) and returns the best offset to use * when a vertical motion is made into the line. */ -getgoal(dlp) register LINE *dlp; { - register int c; - register int col; - register int newcol; - register int dbo; +int +getgoal(dlp) + LINE *dlp; +{ + int c; + int col; + int newcol; + int dbo; col = 0; dbo = 0; @@ -217,10 +242,10 @@ getgoal(dlp) register LINE *dlp; { newcol = col; if (c == '\t' #ifdef NOTAB - && !(curbp->b_flag & BFNOTAB) + && !(curbp->b_flag & BFNOTAB) #endif ) - newcol |= 0x07; + newcol |= 0x07; else if (ISCTRL(c) != FALSE) ++newcol; ++newcol; @@ -240,32 +265,34 @@ getgoal(dlp) register LINE *dlp; { * the window is zapped, we have to do a hard * update and get it back. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int forwpage(f, n) -register int n; + int f, n; { - register LINE *lp; + LINE *lp; if (!(f & FFARG)) { - n = curwp->w_ntrows - 2; /* Default scroll. */ - if (n <= 0) /* Forget the overlap */ - n = 1; /* if tiny window. */ + n = curwp->w_ntrows - 2; /* Default scroll. */ + if (n <= 0) /* Forget the overlap */ + n = 1; /* if tiny window. */ } else if (n < 0) - return backpage(f|FFRAND, -n); + return backpage(f | FFRAND, -n); #ifdef CVMVAS - else /* Convert from pages */ - n *= curwp->w_ntrows; /* to lines. */ + else /* Convert from pages */ + n *= curwp->w_ntrows; /* to lines. */ #endif lp = curwp->w_linep; - while (n-- && lforw(lp)!=curbp->b_linep) + while (n-- && lforw(lp) != curbp->b_linep) lp = lforw(lp); curwp->w_linep = lp; curwp->w_flag |= WFHARD; /* if in current window, don't move dot */ - for(n = curwp->w_ntrows; n-- && lp!=curbp->b_linep; lp = lforw(lp)) - if(lp==curwp->w_dotp) return TRUE; - curwp->w_dotp = curwp->w_linep; - curwp->w_doto = 0; + for (n = curwp->w_ntrows; n-- && lp != curbp->b_linep; lp = lforw(lp)) + if (lp == curwp->w_dotp) + return TRUE; + curwp->w_dotp = curwp->w_linep; + curwp->w_doto = 0; return TRUE; } @@ -277,58 +304,64 @@ register int n; * hard update is done because the top line in * the window is zapped. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int backpage(f, n) -register int n; + int f, n; { - register LINE *lp; + LINE *lp; if (!(f & FFARG)) { - n = curwp->w_ntrows - 2; /* Default scroll. */ - if (n <= 0) /* Don't blow up if the */ - n = 1; /* window is tiny. */ + n = curwp->w_ntrows - 2; /* Default scroll. */ + if (n <= 0) /* Don't blow up if the */ + n = 1; /* window is tiny. */ } else if (n < 0) - return forwpage(f|FFRAND, -n); + return forwpage(f | FFRAND, -n); #ifdef CVMVAS - else /* Convert from pages */ - n *= curwp->w_ntrows; /* to lines. */ + else /* Convert from pages */ + n *= curwp->w_ntrows; /* to lines. */ #endif lp = curwp->w_linep; - while (n-- && lback(lp)!=curbp->b_linep) + while (n-- && lback(lp) != curbp->b_linep) lp = lback(lp); curwp->w_linep = lp; curwp->w_flag |= WFHARD; /* if in current window, don't move dot */ - for(n = curwp->w_ntrows; n-- && lp!=curbp->b_linep; lp = lforw(lp)) - if(lp==curwp->w_dotp) return TRUE; + for (n = curwp->w_ntrows; n-- && lp != curbp->b_linep; lp = lforw(lp)) + if (lp == curwp->w_dotp) + return TRUE; curwp->w_dotp = curwp->w_linep; curwp->w_doto = 0; return TRUE; } -/* These functions are provided for compatibility with Gosling's Emacs. - * They are used to scroll the display up (or down) one line at a time. +/* + * These functions are provided for compatibility with Gosling's Emacs. They + * are used to scroll the display up (or down) one line at a time. */ - #ifdef GOSMACS +VOID forw1page(f, n) -int f, n; + int f, n; { - if (!(f & FFARG)) { - n = 1; + + if (!(f & FFARG)) { + n = 1; f = FFUNIV; } - forwpage(f|FFRAND, n); + forwpage(f | FFRAND, n); } +VOID back1page(f, n) -int f, n; + int f, n; { + if (!(f & FFARG)) { - n = 1; + n = 1; f = FFUNIV; } - backpage(f|FFRAND, n); + backpage(f | FFRAND, n); } #endif @@ -336,9 +369,11 @@ int f, n; * Page the other window. Check to make sure it exists, then * nextwind, forwpage and restore window pointers. */ +int pagenext(f, n) + int f, n; { - register MGWIN *wp; + MGWIN *wp; if (wheadp->w_wndp == NULL) { ewprintf("No other window"); @@ -358,6 +393,7 @@ pagenext(f, n) VOID isetmark() { + curwp->w_markp = curwp->w_dotp; curwp->w_marko = curwp->w_doto; } @@ -367,9 +403,12 @@ isetmark() * to the value of dot. A message is written to * the echo line. (ewprintf knows about macros) */ -/*ARGSUSED*/ +/* ARGSUSED */ +int setmark(f, n) + int f, n; { + isetmark(); ewprintf("Mark set"); return TRUE; @@ -382,11 +421,13 @@ setmark(f, n) * that moves the mark about. The only possible * error is "no mark". */ -/*ARGSUSED*/ +/* ARGSUSED */ +int swapmark(f, n) + int f, n; { - register LINE *odotp; - register int odoto; + LINE *odotp; + int odoto; if (curwp->w_markp == NULL) { ewprintf("No mark in this window"); @@ -394,8 +435,8 @@ swapmark(f, n) } odotp = curwp->w_dotp; odoto = curwp->w_doto; - curwp->w_dotp = curwp->w_markp; - curwp->w_doto = curwp->w_marko; + curwp->w_dotp = curwp->w_markp; + curwp->w_doto = curwp->w_marko; curwp->w_markp = odotp; curwp->w_marko = odoto; curwp->w_flag |= WFMOVE; @@ -409,30 +450,32 @@ swapmark(f, n) * it is the line number, else prompt for a line number * to use. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int gotoline(f, n) -register int n; + int f, n; { - register LINE *clp; - register int s; - char buf[32]; + LINE *clp; + int s; + char buf[32]; if (!(f & FFARG)) { - if ((s=ereply("Goto line: ", buf, sizeof(buf))) != TRUE) + if ((s = ereply("Goto line: ", buf, sizeof(buf))) != TRUE) return s; n = atoi(buf); } - if (n > 0) { - clp = lforw(curbp->b_linep); /* "clp" is first line */ + clp = lforw(curbp->b_linep); /* "clp" is first line */ while (--n > 0) { - if (lforw(clp) == curbp->b_linep) break; + if (lforw(clp) == curbp->b_linep) + break; clp = lforw(clp); } } else { clp = lback(curbp->b_linep); /* clp is last line */ while (n < 0) { - if (lback(clp) == curbp->b_linep) break; + if (lback(clp) == curbp->b_linep) + break; clp = lback(clp); n++; } diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c index 6f0f920fee2..a795506369b 100644 --- a/usr.bin/mg/buffer.c +++ b/usr.bin/mg/buffer.c @@ -2,9 +2,10 @@ * Buffer handling. */ #include "def.h" -#include "kbd.h" /* needed for modes */ +#include "kbd.h" /* needed for modes */ -static RSIZE itor(); +static RSIZE itor __P((char *, int, RSIZE)); +static BUFFER *makelist __P((void)); /* * Attach a buffer to a window. The values of dot and mark come @@ -12,56 +13,67 @@ static RSIZE itor(); * from some other window. *scratch* is the default alternate * buffer. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int usebuffer(f, n) + int f, n; { - register BUFFER *bp; - register int s; - char bufn[NBUFN]; + BUFFER *bp; + int s; + char bufn[NBUFN]; /* Get buffer to use from user */ if ((curbp->b_altb == NULL) && ((curbp->b_altb = bfind("*scratch*", TRUE)) == NULL)) - s=eread("Switch to buffer: ", bufn, NBUFN, EFNEW|EFBUF); + s = eread("Switch to buffer: ", bufn, NBUFN, EFNEW | EFBUF); else - s=eread("Switch to buffer: (default %s) ", bufn, NBUFN, - EFNEW|EFBUF, curbp->b_altb->b_bname); - - if (s == ABORT) return s; - if (s == FALSE && curbp->b_altb != NULL) bp = curbp->b_altb ; - else if ((bp=bfind(bufn, TRUE)) == NULL) return FALSE; + s = eread("Switch to buffer: (default %s) ", bufn, NBUFN, + EFNEW | EFBUF, curbp->b_altb->b_bname); + + if (s == ABORT) + return s; + if (s == FALSE && curbp->b_altb != NULL) + bp = curbp->b_altb; + else if ((bp = bfind(bufn, TRUE)) == NULL) + return FALSE; /* and put it in current window */ curbp = bp; - return showbuffer(bp, curwp, WFFORCE|WFHARD); + return showbuffer(bp, curwp, WFFORCE | WFHARD); } /* * pop to buffer asked for by the user. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int poptobuffer(f, n) + int f, n; { - register BUFFER *bp; - register MGWIN *wp; - register int s; - char bufn[NBUFN]; - MGWIN *popbuf(); + BUFFER *bp; + MGWIN *wp; + int s; + char bufn[NBUFN]; + MGWIN *popbuf(); /* Get buffer to use from user */ if ((curbp->b_altb == NULL) && ((curbp->b_altb = bfind("*scratch*", TRUE)) == NULL)) - s=eread("Switch to buffer in other window: ", bufn, NBUFN, - EFNEW|EFBUF); + s = eread("Switch to buffer in other window: ", bufn, NBUFN, + EFNEW | EFBUF); else - s=eread("Switch to buffer in other window: (default %s) ", - bufn, NBUFN, EFNEW|EFBUF, curbp->b_altb->b_bname); - if (s == ABORT) return s; - if (s == FALSE && curbp->b_altb != NULL) bp = curbp->b_altb ; - else if ((bp=bfind(bufn, TRUE)) == NULL) return FALSE; + s = eread("Switch to buffer in other window: (default %s) ", + bufn, NBUFN, EFNEW | EFBUF, curbp->b_altb->b_bname); + if (s == ABORT) + return s; + if (s == FALSE && curbp->b_altb != NULL) + bp = curbp->b_altb; + else if ((bp = bfind(bufn, TRUE)) == NULL) + return FALSE; /* and put it in a new window */ - if ((wp = popbuf(bp)) == NULL) return FALSE; + if ((wp = popbuf(bp)) == NULL) + return FALSE; curbp = bp; curwp = wp; return TRUE; @@ -74,49 +86,58 @@ poptobuffer(f, n) * if the buffer has been changed). Then free the header * line and the buffer header. Bound to "C-X K". */ -/*ARGSUSED*/ +/* ARGSUSED */ +int killbuffer(f, n) + int f, n; { - register BUFFER *bp; - register BUFFER *bp1; - register BUFFER *bp2; - MGWIN *wp; - register int s; - char bufn[NBUFN]; - - if ((s=eread("Kill buffer: (default %s) ", bufn, NBUFN, EFNEW|EFBUF, - curbp->b_bname)) == ABORT) return (s); - else if (s == FALSE) bp = curbp; - else if ((bp=bfind(bufn, FALSE)) == NULL) return FALSE; - - /* find some other buffer to display. try the alternate buffer, - * then the first different buffer in the buffer list. if - * there's only one buffer, create buffer *scratch* and make - * it the alternate buffer. return if *scratch* is only buffer + BUFFER *bp; + BUFFER *bp1; + BUFFER *bp2; + MGWIN *wp; + int s; + char bufn[NBUFN]; + + if ((s = eread("Kill buffer: (default %s) ", bufn, NBUFN, EFNEW | EFBUF, + curbp->b_bname)) == ABORT) + return (s); + else if (s == FALSE) + bp = curbp; + else if ((bp = bfind(bufn, FALSE)) == NULL) + return FALSE; + + /* + * Find some other buffer to display. try the alternate buffer, + * then the first different buffer in the buffer list. If there's + * only one buffer, create buffer *scratch* and make it the alternate + * buffer. Return if *scratch* is only buffer... */ if ((bp1 = bp->b_altb) == NULL) { bp1 = (bp == bheadp) ? bp->b_bufp : bheadp; if (bp1 == NULL) { /* only one buffer. see if it's *scratch* */ - if (bp == bfind("*scratch*",FALSE)) + if (bp == bfind("*scratch*", FALSE)) return FALSE; /* create *scratch* for alternate buffer */ - if ((bp1 = bfind("*scratch*",TRUE)) == NULL) + if ((bp1 = bfind("*scratch*", TRUE)) == NULL) return FALSE; } } - if (bclear(bp) != TRUE) return TRUE; + if (bclear(bp) != TRUE) + return TRUE; for (wp = wheadp; bp->b_nwnd > 0; wp = wp->w_wndp) { - if (wp->w_bufp == bp) { - bp2 = bp1->b_altb; /* save alternate buffer */ - if(showbuffer(bp1, wp, WFMODE|WFFORCE|WFHARD) != NULL) - bp1->b_altb = bp2; - else bp1 = bp2; - } + if (wp->w_bufp == bp) { + bp2 = bp1->b_altb; /* save alternate buffer */ + if (showbuffer(bp1, wp, WFMODE | WFFORCE | WFHARD)) + bp1->b_altb = bp2; + else + bp1 = bp2; + } } - if (bp == curbp) curbp = bp1; - free((char *) bp->b_linep); /* Release header line. */ - bp2 = NULL; /* Find the header. */ + if (bp == curbp) + curbp = bp1; + free(bp->b_linep); /* Release header line. */ + bp2 = NULL; /* Find the header. */ bp1 = bheadp; while (bp1 != bp) { if (bp1->b_altb == bp) @@ -124,28 +145,32 @@ killbuffer(f, n) bp2 = bp1; bp1 = bp1->b_bufp; } - bp1 = bp1->b_bufp; /* Next one in chain. */ - if (bp2 == NULL) /* Unlink it. */ + bp1 = bp1->b_bufp; /* Next one in chain. */ + if (bp2 == NULL) /* Unlink it. */ bheadp = bp1; else bp2->b_bufp = bp1; - while (bp1 != NULL) { /* Finish with altb's */ + while (bp1 != NULL) { /* Finish with altb's */ if (bp1->b_altb == bp) bp1->b_altb = (bp->b_altb == bp1) ? NULL : bp->b_altb; bp1 = bp1->b_bufp; } - free(bp->b_bname); /* Release name block */ - free((char *) bp); /* Release buffer block */ + free(bp->b_bname); /* Release name block */ + free(bp); /* Release buffer block */ return TRUE; } /* * Save some buffers - just call anycb with the arg flag. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int savebuffers(f, n) + int f, n; { - if (anycb(f) == ABORT) return ABORT; + + if (anycb(f) == ABORT) + return ABORT; return TRUE; } @@ -156,17 +181,17 @@ savebuffers(f, n) * then pops the data onto the screen. Bound to * "C-X C-B". */ -/*ARGSUSED*/ +/* ARGSUSED */ +int listbuffers(f, n) + int f, n; { - register BUFFER *bp; - register MGWIN *wp; - BUFFER *makelist(); - MGWIN *popbuf(); + BUFFER *bp; + MGWIN *wp; - if ((bp=makelist()) == NULL || (wp=popbuf(bp)) == NULL) + if ((bp = makelist()) == NULL || (wp = popbuf(bp)) == NULL) return FALSE; - wp->w_dotp = bp->b_dotp; /* fix up if window already on screen */ + wp->w_dotp = bp->b_dotp;/* fix up if window already on screen */ wp->w_doto = bp->b_doto; return TRUE; } @@ -177,150 +202,167 @@ listbuffers(f, n) * everything works. Return FALSE if there * is an error (if there is no memory). */ -BUFFER * -makelist() { - register char *cp1; - register char *cp2; - register int c; - register BUFFER *bp; - LINE *lp; - register RSIZE nbytes; - BUFFER *blp; - char b[6+1]; - char line[128]; - - if ((blp = bfind("*Buffer List*", TRUE)) == NULL) return NULL; - if (bclear(blp) != TRUE) return NULL; - blp->b_flag &= ~BFCHG; /* Blow away old. */ +static BUFFER * +makelist() +{ + char *cp1; + char *cp2; + int c; + BUFFER *bp; + LINE *lp; + RSIZE nbytes; + BUFFER *blp; + char b[6 + 1]; + char line[128]; + + if ((blp = bfind("*Buffer List*", TRUE)) == NULL) + return NULL; + if (bclear(blp) != TRUE) + return NULL; + blp->b_flag &= ~BFCHG; /* Blow away old. */ (VOID) strcpy(line, " MR Buffer"); cp1 = line + 10; - while(cp1 < line + 4 + NBUFN + 1) *cp1++ = ' '; + while (cp1 < line + 4 + NBUFN + 1) + *cp1++ = ' '; (VOID) strcpy(cp1, "Size File"); - if (addline(blp, line) == FALSE) return NULL; + if (addline(blp, line) == FALSE) + return NULL; (VOID) strcpy(line, " -- ------"); cp1 = line + 10; - while(cp1 < line + 4 + NBUFN + 1) *cp1++ = ' '; + while (cp1 < line + 4 + NBUFN + 1) + *cp1++ = ' '; (VOID) strcpy(cp1, "---- ----"); - if (addline(blp, line) == FALSE) return NULL; - bp = bheadp; /* For all buffers */ + if (addline(blp, line) == FALSE) + return NULL; + bp = bheadp; /* For all buffers */ while (bp != NULL) { - cp1 = &line[0]; /* Start at left edge */ + cp1 = &line[0]; /* Start at left edge */ *cp1++ = (bp == curbp) ? '.' : ' '; - *cp1++ = ((bp->b_flag&BFCHG) != 0) ? '*' : ' '; - *cp1++ = ' '; /* Gap. */ + *cp1++ = ((bp->b_flag & BFCHG) != 0) ? '*' : ' '; + *cp1++ = ' '; /* Gap. */ *cp1++ = ' '; - cp2 = &bp->b_bname[0]; /* Buffer name */ + cp2 = &bp->b_bname[0]; /* Buffer name */ while ((c = *cp2++) != 0) *cp1++ = c; - while (cp1 < &line[4+NBUFN+1]) + while (cp1 < &line[4 + NBUFN + 1]) *cp1++ = ' '; - nbytes = 0; /* Count bytes in buf. */ + nbytes = 0; /* Count bytes in buf. */ if (bp != blp) { lp = lforw(bp->b_linep); while (lp != bp->b_linep) { - nbytes += llength(lp)+1; + nbytes += llength(lp) + 1; lp = lforw(lp); } - if(nbytes) nbytes--; /* no bonus newline */ + if (nbytes) + nbytes--; /* no bonus newline */ } (VOID) itor(b, 6, nbytes); /* 6 digit buffer size. */ cp2 = &b[0]; while ((c = *cp2++) != 0) *cp1++ = c; - *cp1++ = ' '; /* Gap.. */ - cp2 = &bp->b_fname[0]; /* File name */ + *cp1++ = ' '; /* Gap.. */ + cp2 = &bp->b_fname[0]; /* File name */ if (*cp2 != 0) { while ((c = *cp2++) != 0) { - if (cp1 < &line[128-1]) + if (cp1 < &line[128 - 1]) *cp1++ = c; } } - *cp1 = 0; /* Add to the buffer. */ + *cp1 = 0; /* Add to the buffer. */ if (addline(blp, line) == FALSE) return NULL; bp = bp->b_bufp; } - blp->b_dotp = lforw(blp->b_linep); /* put dot at beginning of buffer */ + blp->b_dotp = lforw(blp->b_linep); /* put dot at beginning of + * buffer */ blp->b_doto = 0; - return blp; /* All done */ + return blp; /* All done */ } /* * Used above. */ -static RSIZE itor(buf, width, num) -register char buf[]; register int width; register RSIZE num; { - register RSIZE r; +static RSIZE +itor(buf, width, num) + char *buf; + int width; + RSIZE num; +{ + RSIZE r; if (num / 10 == 0) { buf[0] = (num % 10) + '0'; - for (r = 1; r < width; buf[r++] = ' ') - ; + for (r = 1; r < width; buf[r++] = ' '); buf[width] = '\0'; return 1; } else { - buf[r = itor(buf, width, num / (RSIZE)10)] = - (num % (RSIZE)10) + '0'; + buf[r = itor(buf, width, num / (RSIZE) 10)] = + (num % (RSIZE) 10) + '0'; return r + 1; } - /*NOTREACHED*/ + /* NOTREACHED */ } /* - * The argument "text" points to - * a string. Append this line to the - * buffer. Handcraft the EOL - * on the end. Return TRUE if it worked and + * The argument "text" points to a string. Append this line to the + * buffer. Handcraft the EOL on the end. Return TRUE if it worked and * FALSE if you ran out of room. */ -addline(bp, text) register BUFFER *bp; char *text; { - register LINE *lp; - register int i; - register int ntext; +int +addline(bp, text) + BUFFER *bp; + char *text; +{ + LINE *lp; + int i; + int ntext; ntext = strlen(text); - if ((lp=lalloc(ntext)) == NULL) + if ((lp = lalloc(ntext)) == NULL) return FALSE; - for (i=0; i<ntext; ++i) + for (i = 0; i < ntext; ++i) lputc(lp, i, text[i]); - bp->b_linep->l_bp->l_fp = lp; /* Hook onto the end */ + bp->b_linep->l_bp->l_fp = lp; /* Hook onto the end */ lp->l_bp = bp->b_linep->l_bp; bp->b_linep->l_bp = lp; lp->l_fp = bp->b_linep; #ifdef CANTHAPPEN - if (bp->b_dotp == bp->b_linep) /* If "." is at the end */ - bp->b_dotp = lp; /* move it to new line */ - if (bp->b_markp == bp->b_linep) /* ditto for mark */ + if (bp->b_dotp == bp->b_linep) /* If "." is at the end */ + bp->b_dotp = lp; /* move it to new line */ + if (bp->b_markp == bp->b_linep) /* ditto for mark */ bp->b_markp = lp; #endif return TRUE; } /* - * Look through the list of buffers, giving the user - * a chance to save them. Return TRUE if there are - * any changed buffers afterwards. Buffers that don't - * have an associated file don't count. Return FALSE - * if there are no changed buffers. + * Look through the list of buffers, giving the user a chance to save them. + * Return TRUE if there are any changed buffers afterwards. Buffers that + * don't have an associated file don't count. Return FALSE if there are + * no changed buffers. */ -anycb(f) { - register BUFFER *bp; - register int s = FALSE, save = FALSE; - char prompt[NFILEN + 11]; - VOID upmodes(); +int +anycb(f) + int f; +{ + BUFFER *bp; + int s = FALSE, save = FALSE; + char prompt[NFILEN + 11]; for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { if (*(bp->b_fname) != '\0' - && (bp->b_flag&BFCHG) != 0) { + && (bp->b_flag & BFCHG) != 0) { (VOID) strcpy(prompt, "Save file "); (VOID) strcpy(prompt + 10, bp->b_fname); if ((f == TRUE || (save = eyorn(prompt)) == TRUE) - && buffsave(bp) == TRUE) { + && buffsave(bp) == TRUE) { bp->b_flag &= ~BFCHG; upmodes(bp); - } else s = TRUE; - if (save == ABORT) return (save); + } else + s = TRUE; + if (save == ABORT) + return (save); save = TRUE; } } @@ -336,15 +378,17 @@ anycb(f) { * all buffers. Return pointer to the BUFFER * block for the buffer. */ -BUFFER * -bfind(bname, cflag) register char *bname; { - register BUFFER *bp; - char *malloc(); - register LINE *lp; - int i; - extern int defb_nmodes; - extern MAPS *defb_modes[PBMODES]; - extern int defb_flag; +BUFFER * +bfind(bname, cflag) + char *bname; + int cflag; +{ + BUFFER *bp; + LINE *lp; + int i; + extern int defb_nmodes; + extern MAPS *defb_modes[PBMODES]; + extern int defb_flag; bp = bheadp; while (bp != NULL) { @@ -352,14 +396,15 @@ bfind(bname, cflag) register char *bname; { return bp; bp = bp->b_bufp; } - if (cflag!=TRUE) return NULL; - /*NOSTRICT*/ - if ((bp=(BUFFER *)malloc(sizeof(BUFFER))) == NULL) { + if (cflag != TRUE) + return NULL; + /* NOSTRICT */ + if ((bp = (BUFFER *) malloc(sizeof(BUFFER))) == NULL) { ewprintf("Can't get %d bytes", sizeof(BUFFER)); return NULL; } - if ((bp->b_bname=malloc((unsigned)(strlen(bname)+1))) == NULL) { - ewprintf("Can't get %d bytes", strlen(bname)+1); + if ((bp->b_bname = malloc((strlen(bname) + 1))) == NULL) { + ewprintf("Can't get %d bytes", strlen(bname) + 1); free((char *) bp); return NULL; } @@ -368,19 +413,19 @@ bfind(bname, cflag) register char *bname; { free((char *) bp); return NULL; } - bp->b_altb = bp->b_bufp = NULL; - bp->b_dotp = lp; - bp->b_doto = 0; + bp->b_altb = bp->b_bufp = NULL; + bp->b_dotp = lp; + bp->b_doto = 0; bp->b_markp = NULL; bp->b_marko = 0; - bp->b_flag = defb_flag; - bp->b_nwnd = 0; + bp->b_flag = defb_flag; + bp->b_nwnd = 0; bp->b_linep = lp; bp->b_nmodes = defb_nmodes; i = 0; do { - bp->b_modes[i] = defb_modes[i]; - } while(i++ < defb_nmodes); + bp->b_modes[i] = defb_modes[i]; + } while (i++ < defb_nmodes); bp->b_fname[0] = '\0'; bzero(&bp->b_fi, sizeof(bp->b_fi)); (VOID) strcpy(bp->b_bname, bname); @@ -401,20 +446,22 @@ bfind(bname, cflag) register char *bname; { * that are required. Return TRUE if everything * looks good. */ -bclear(bp) register BUFFER *bp; { - register LINE *lp; - register int s; - VOID lfree(); +int +bclear(bp) + BUFFER *bp; +{ + LINE *lp; + int s; - if ((bp->b_flag&BFCHG) != 0 /* Changed. */ - && (s=eyesno("Buffer modified; kill anyway")) != TRUE) + if ((bp->b_flag & BFCHG) != 0 /* Changed. */ + && (s = eyesno("Buffer modified; kill anyway")) != TRUE) return (s); - bp->b_flag &= ~BFCHG; /* Not changed */ - while ((lp=lforw(bp->b_linep)) != bp->b_linep) + bp->b_flag &= ~BFCHG; /* Not changed */ + while ((lp = lforw(bp->b_linep)) != bp->b_linep) lfree(lp); - bp->b_dotp = bp->b_linep; /* Fix "." */ - bp->b_doto = 0; - bp->b_markp = NULL; /* Invalidate "mark" */ + bp->b_dotp = bp->b_linep; /* Fix "." */ + bp->b_doto = 0; + bp->b_markp = NULL; /* Invalidate "mark" */ bp->b_marko = 0; return TRUE; } @@ -423,44 +470,47 @@ bclear(bp) register BUFFER *bp; { * Display the given buffer in the given window. Flags indicated * action on redisplay. */ -showbuffer(bp, wp, flags) register BUFFER *bp; register MGWIN *wp; { - register BUFFER *obp; - MGWIN *owp; +int +showbuffer(bp, wp, flags) + BUFFER *bp; + MGWIN *wp; + int flags; +{ + BUFFER *obp; + MGWIN *owp; - if (wp->w_bufp == bp) { /* Easy case! */ + if (wp->w_bufp == bp) { /* Easy case! */ wp->w_flag |= flags; return TRUE; } - /* First, dettach the old buffer from the window */ if ((bp->b_altb = obp = wp->w_bufp) != NULL) { if (--obp->b_nwnd == 0) { - obp->b_dotp = wp->w_dotp; - obp->b_doto = wp->w_doto; + obp->b_dotp = wp->w_dotp; + obp->b_doto = wp->w_doto; obp->b_markp = wp->w_markp; obp->b_marko = wp->w_marko; } } - /* Now, attach the new buffer to the window */ wp->w_bufp = bp; - if (bp->b_nwnd++ == 0) { /* First use. */ - wp->w_dotp = bp->b_dotp; - wp->w_doto = bp->b_doto; + if (bp->b_nwnd++ == 0) { /* First use. */ + wp->w_dotp = bp->b_dotp; + wp->w_doto = bp->b_doto; wp->w_markp = bp->b_markp; wp->w_marko = bp->b_marko; } else - /* already on screen, steal values from other window */ + /* already on screen, steal values from other window */ for (owp = wheadp; owp != NULL; owp = wp->w_wndp) if (wp->w_bufp == bp && owp != wp) { - wp->w_dotp = owp->w_dotp; - wp->w_doto = owp->w_doto; + wp->w_dotp = owp->w_dotp; + wp->w_doto = owp->w_doto; wp->w_markp = owp->w_markp; wp->w_marko = owp->w_marko; break; } - wp->w_flag |= WFMODE|flags; + wp->w_flag |= WFMODE | flags; return TRUE; } @@ -469,71 +519,81 @@ showbuffer(bp, wp, flags) register BUFFER *bp; register MGWIN *wp; { * Returns a status. */ MGWIN * -popbuf(bp) register BUFFER *bp; { - register MGWIN *wp; +popbuf(bp) + BUFFER *bp; +{ + MGWIN *wp; - if (bp->b_nwnd == 0) { /* Not on screen yet. */ - if ((wp=wpopup()) == NULL) return NULL; + if (bp->b_nwnd == 0) { /* Not on screen yet. */ + if ((wp = wpopup()) == NULL) + return NULL; } else for (wp = wheadp; wp != NULL; wp = wp->w_wndp) if (wp->w_bufp == bp) { - wp->w_flag |= WFHARD|WFFORCE; - return wp ; + wp->w_flag |= WFHARD | WFFORCE; + return wp; } - if (showbuffer(bp, wp, WFHARD) != TRUE) return NULL; + if (showbuffer(bp, wp, WFHARD) != TRUE) + return NULL; return wp; } /* * Insert another buffer at dot. Very useful. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int bufferinsert(f, n) { - register BUFFER *bp; - register LINE *clp; - register int clo; - register int nline; - int s; - char bufn[NBUFN]; + BUFFER *bp; + LINE *clp; + int clo; + int nline; + int s; + char bufn[NBUFN]; /* Get buffer to use from user */ if (curbp->b_altb != NULL) - s=eread("Insert buffer: (default %s) ", bufn, NBUFN, - EFNEW|EFBUF, &(curbp->b_altb->b_bname), - (char *) NULL) ; + s = eread("Insert buffer: (default %s) ", bufn, NBUFN, + EFNEW | EFBUF, &(curbp->b_altb->b_bname), + (char *) NULL); else - s=eread("Insert buffer: ", bufn, NBUFN, EFNEW|EFBUF, - (char *) NULL) ; - if (s == ABORT) return (s); - if (s == FALSE && curbp->b_altb != NULL) bp = curbp->b_altb; - else if ((bp=bfind(bufn, FALSE)) == NULL) return FALSE; + s = eread("Insert buffer: ", bufn, NBUFN, EFNEW | EFBUF, + (char *) NULL); + if (s == ABORT) + return (s); + if (s == FALSE && curbp->b_altb != NULL) + bp = curbp->b_altb; + else if ((bp = bfind(bufn, FALSE)) == NULL) + return FALSE; - if (bp==curbp) { + if (bp == curbp) { ewprintf("Cannot insert buffer into self"); return FALSE; } - /* insert the buffer */ nline = 0; clp = lforw(bp->b_linep); - for(;;) { + for (;;) { for (clo = 0; clo < llength(clp); clo++) if (linsert(1, lgetc(clp, clo)) == FALSE) return FALSE; - if((clp = lforw(clp)) == bp->b_linep) break; - if (newline(FFRAND, 1) == FALSE) /* fake newline */ + if ((clp = lforw(clp)) == bp->b_linep) + break; + if (newline(FFRAND, 1) == FALSE) /* fake newline */ return FALSE; nline++; } - if (nline == 1) ewprintf("[Inserted 1 line]"); - else ewprintf("[Inserted %d lines]", nline); + if (nline == 1) + ewprintf("[Inserted 1 line]"); + else + ewprintf("[Inserted %d lines]", nline); - clp = curwp->w_linep; /* cosmetic adjustment */ - if (curwp->w_dotp == clp) { /* for offscreen insert */ - while (nline-- && lback(clp)!=curbp->b_linep) + clp = curwp->w_linep; /* cosmetic adjustment */ + if (curwp->w_dotp == clp) { /* for offscreen insert */ + while (nline-- && lback(clp) != curbp->b_linep) clp = lback(clp); - curwp->w_linep = clp; /* adjust framing. */ + curwp->w_linep = clp; /* adjust framing. */ curwp->w_flag |= WFHARD; } return (TRUE); @@ -542,13 +602,14 @@ bufferinsert(f, n) /* * Turn off the dirty bit on this buffer. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int notmodified(f, n) { - register MGWIN *wp; + MGWIN *wp; curbp->b_flag &= ~BFCHG; - wp = wheadp; /* Update mode lines. */ + wp = wheadp; /* Update mode lines. */ while (wp != NULL) { if (wp->w_bufp == curbp) wp->w_flag |= WFMODE; @@ -563,22 +624,22 @@ notmodified(f, n) * Popbuf and set all windows to top of buffer. Currently only used by * help functions. */ - +int popbuftop(bp) -register BUFFER *bp; + BUFFER *bp; { - register MGWIN *wp; + MGWIN *wp; - bp->b_dotp = lforw(bp->b_linep); - bp->b_doto = 0; - if(bp->b_nwnd != 0) { - for(wp = wheadp; wp!=NULL; wp = wp->w_wndp) - if(wp->w_bufp == bp) { - wp->w_dotp = bp->b_dotp; - wp->w_doto = 0; - wp->w_flag |= WFHARD; - } - } - return popbuf(bp) != NULL; + bp->b_dotp = lforw(bp->b_linep); + bp->b_doto = 0; + if (bp->b_nwnd != 0) { + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) + if (wp->w_bufp == bp) { + wp->w_dotp = bp->b_dotp; + wp->w_doto = 0; + wp->w_flag |= WFHARD; + } + } + return popbuf(bp) != NULL; } #endif diff --git a/usr.bin/mg/chrdef.h b/usr.bin/mg/chrdef.h index 6c2f2f3180f..4b4c386f0ec 100644 --- a/usr.bin/mg/chrdef.h +++ b/usr.bin/mg/chrdef.h @@ -1,14 +1,14 @@ /* - * sys/default/chardef.h: character set specific #defines for mg 2a + * sys/default/chardef.h: character set specific #defines for Mg 2a * Warning: System specific ones exist */ -#ifndef CHARMASK /* - * casting should be at least as efficent as anding with 0xff, + * Casting should be at least as efficent as anding with 0xff, * and won't have the size problems. Override in sysdef.h if no * unsigned char type. */ +#ifndef CHARMASK #define CHARMASK(c) ((unsigned char) (c)) #endif @@ -18,12 +18,12 @@ * understand the DEC multinational set, and let me ask * a slightly different set of questions. */ -#define _W 0x01 /* Word. */ -#define _U 0x02 /* Upper case letter. */ -#define _L 0x04 /* Lower case letter. */ -#define _C 0x08 /* Control. */ -#define _P 0x10 /* end of sentence punctuation */ -#define _D 0x20 /* is decimal digit */ +#define _W 0x01 /* Word. */ +#define _U 0x02 /* Upper case letter. */ +#define _L 0x04 /* Lower case letter. */ +#define _C 0x08 /* Control. */ +#define _P 0x10 /* end of sentence punctuation */ +#define _D 0x20 /* is decimal digit */ #define ISWORD(c) ((cinfo[CHARMASK(c)]&_W)!=0) #define ISCTRL(c) ((cinfo[CHARMASK(c)]&_C)!=0) @@ -35,45 +35,45 @@ #define TOLOWER(c) ((c)+0x20) /* - * generally useful thing for chars + * Generally useful thing for chars */ #define CCHR(x) ((x) ^ 0x40) /* CCHR('?') == DEL */ #ifndef METACH -#define METACH CCHR('[') +#define METACH CCHR('[') #endif -#ifdef XKEYS -#define K00 256 -#define K01 257 -#define K02 258 -#define K03 259 -#define K04 260 -#define K05 261 -#define K06 262 -#define K07 263 -#define K08 264 -#define K09 265 -#define K0A 266 -#define K0B 267 -#define K0C 268 -#define K0D 269 -#define K0E 270 -#define K0F 271 -#define K10 272 -#define K11 273 -#define K12 274 -#define K13 275 -#define K14 276 -#define K15 277 -#define K16 278 -#define K17 279 -#define K18 280 -#define K19 281 -#define K1A 282 -#define K1B 283 -#define K1C 284 -#define K1D 285 -#define K1E 286 -#define K1F 287 +#ifdef XKEYS +#define K00 256 +#define K01 257 +#define K02 258 +#define K03 259 +#define K04 260 +#define K05 261 +#define K06 262 +#define K07 263 +#define K08 264 +#define K09 265 +#define K0A 266 +#define K0B 267 +#define K0C 268 +#define K0D 269 +#define K0E 270 +#define K0F 271 +#define K10 272 +#define K11 273 +#define K12 274 +#define K13 275 +#define K14 276 +#define K15 277 +#define K16 278 +#define K17 279 +#define K18 280 +#define K19 281 +#define K1A 282 +#define K1B 283 +#define K1C 284 +#define K1D 285 +#define K1E 286 +#define K1F 287 #endif diff --git a/usr.bin/mg/cinfo.c b/usr.bin/mg/cinfo.c index 163017e0e07..8b342f915bf 100644 --- a/usr.bin/mg/cinfo.c +++ b/usr.bin/mg/cinfo.c @@ -15,71 +15,71 @@ * character set, and lets me ask some questions that the * standard "ctype" macros cannot ask. */ -char cinfo[256] = { - _C, _C, _C, _C, /* 0x0X */ - _C, _C, _C, _C, - _C, _C, _C, _C, - _C, _C, _C, _C, - _C, _C, _C, _C, /* 0x1X */ - _C, _C, _C, _C, - _C, _C, _C, _C, - _C, _C, _C, _C, - 0, _P, 0, 0, /* 0x2X */ - _W, _W, 0, _W, - 0, 0, 0, 0, - 0, 0, _P, 0, - _D|_W, _D|_W, _D|_W, _D|_W, /* 0x3X */ - _D|_W, _D|_W, _D|_W, _D|_W, - _D|_W, _D|_W, 0, 0, - 0, 0, 0, _P, - 0, _U|_W, _U|_W, _U|_W, /* 0x4X */ - _U|_W, _U|_W, _U|_W, _U|_W, - _U|_W, _U|_W, _U|_W, _U|_W, - _U|_W, _U|_W, _U|_W, _U|_W, - _U|_W, _U|_W, _U|_W, _U|_W, /* 0x5X */ - _U|_W, _U|_W, _U|_W, _U|_W, - _U|_W, _U|_W, _U|_W, 0, - 0, 0, 0, 0, - 0, _L|_W, _L|_W, _L|_W, /* 0x6X */ - _L|_W, _L|_W, _L|_W, _L|_W, - _L|_W, _L|_W, _L|_W, _L|_W, - _L|_W, _L|_W, _L|_W, _L|_W, - _L|_W, _L|_W, _L|_W, _L|_W, /* 0x7X */ - _L|_W, _L|_W, _L|_W, _L|_W, - _L|_W, _L|_W, _L|_W, 0, - 0, 0, 0, _C, - 0, 0, 0, 0, /* 0x8X */ - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, /* 0x9X */ - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, /* 0xAX */ - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, /* 0xBX */ - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, - _U|_W, _U|_W, _U|_W, _U|_W, /* 0xCX */ - _U|_W, _U|_W, _U|_W, _U|_W, - _U|_W, _U|_W, _U|_W, _U|_W, - _U|_W, _U|_W, _U|_W, _U|_W, - 0, _U|_W, _U|_W, _U|_W, /* 0xDX */ - _U|_W, _U|_W, _U|_W, _U|_W, - _U|_W, _U|_W, _U|_W, _U|_W, - _U|_W, _U|_W, 0, _W, - _L|_W, _L|_W, _L|_W, _L|_W, /* 0xEX */ - _L|_W, _L|_W, _L|_W, _L|_W, - _L|_W, _L|_W, _L|_W, _L|_W, - _L|_W, _L|_W, _L|_W, _L|_W, - 0, _L|_W, _L|_W, _L|_W, /* 0xFX */ - _L|_W, _L|_W, _L|_W, _L|_W, - _L|_W, _L|_W, _L|_W, _L|_W, - _L|_W, _L|_W, 0, 0 +char cinfo[256] = { + _C, _C, _C, _C, /* 0x0X */ + _C, _C, _C, _C, + _C, _C, _C, _C, + _C, _C, _C, _C, + _C, _C, _C, _C, /* 0x1X */ + _C, _C, _C, _C, + _C, _C, _C, _C, + _C, _C, _C, _C, + 0, _P, 0, 0, /* 0x2X */ + _W, _W, 0, _W, + 0, 0, 0, 0, + 0, 0, _P, 0, + _D | _W, _D | _W, _D | _W, _D | _W, /* 0x3X */ + _D | _W, _D | _W, _D | _W, _D | _W, + _D | _W, _D | _W, 0, 0, + 0, 0, 0, _P, + 0, _U | _W, _U | _W, _U | _W, /* 0x4X */ + _U | _W, _U | _W, _U | _W, _U | _W, + _U | _W, _U | _W, _U | _W, _U | _W, + _U | _W, _U | _W, _U | _W, _U | _W, + _U | _W, _U | _W, _U | _W, _U | _W, /* 0x5X */ + _U | _W, _U | _W, _U | _W, _U | _W, + _U | _W, _U | _W, _U | _W, 0, + 0, 0, 0, 0, + 0, _L | _W, _L | _W, _L | _W, /* 0x6X */ + _L | _W, _L | _W, _L | _W, _L | _W, + _L | _W, _L | _W, _L | _W, _L | _W, + _L | _W, _L | _W, _L | _W, _L | _W, + _L | _W, _L | _W, _L | _W, _L | _W, /* 0x7X */ + _L | _W, _L | _W, _L | _W, _L | _W, + _L | _W, _L | _W, _L | _W, 0, + 0, 0, 0, _C, + 0, 0, 0, 0, /* 0x8X */ + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, /* 0x9X */ + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, /* 0xAX */ + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, /* 0xBX */ + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + _U | _W, _U | _W, _U | _W, _U | _W, /* 0xCX */ + _U | _W, _U | _W, _U | _W, _U | _W, + _U | _W, _U | _W, _U | _W, _U | _W, + _U | _W, _U | _W, _U | _W, _U | _W, + 0, _U | _W, _U | _W, _U | _W, /* 0xDX */ + _U | _W, _U | _W, _U | _W, _U | _W, + _U | _W, _U | _W, _U | _W, _U | _W, + _U | _W, _U | _W, 0, _W, + _L | _W, _L | _W, _L | _W, _L | _W, /* 0xEX */ + _L | _W, _L | _W, _L | _W, _L | _W, + _L | _W, _L | _W, _L | _W, _L | _W, + _L | _W, _L | _W, _L | _W, _L | _W, + 0, _L | _W, _L | _W, _L | _W, /* 0xFX */ + _L | _W, _L | _W, _L | _W, _L | _W, + _L | _W, _L | _W, _L | _W, _L | _W, + _L | _W, _L | _W, 0, 0 }; /* @@ -87,49 +87,62 @@ char cinfo[256] = { * characters and function keys better. Returns a pointer to the terminating * '\0'. */ - -char *keyname(cp, k) -register char *cp; -register int k; +char * +keyname(cp, k) + char *cp; + int k; { - register char *np; -#ifdef FKEYS - extern char *keystrings[]; -#endif + char *np; - if(k < 0) k = CHARMASK(k); /* sign extended char */ - switch(k) { - case CCHR('@'): np = "NUL"; break; - case CCHR('I'): np = "TAB"; break; - case CCHR('J'): np = "LFD"; break; /* yuck, but that's what GNU calls it */ - case CCHR('M'): np = "RET"; break; - case CCHR('['): np = "ESC"; break; - case ' ': np = "SPC"; break; /* yuck again */ - case CCHR('?'): np = "DEL"; break; + if (k < 0) + k = CHARMASK(k);/* sign extended char */ + switch (k) { + case CCHR('@'): + np = "NUL"; + break; + case CCHR('I'): + np = "TAB"; + break; + case CCHR('J'): + np = "LFD"; + break; /* yuck, but that's what GNU calls it */ + case CCHR('M'): + np = "RET"; + break; + case CCHR('['): + np = "ESC"; + break; + case ' ': + np = "SPC"; + break; /* yuck again */ + case CCHR('?'): + np = "DEL"; + break; default: #ifdef FKEYS - if(k >= KFIRST && k <= KLAST && + if (k >= KFIRST && k <= KLAST && (np = keystrings[k - KFIRST]) != NULL) - break; + break; #endif - if(k > CCHR('?')) { - *cp++ = '0'; - *cp++ = ((k>>6)&7) + '0'; - *cp++ = ((k>>3)&7) + '0'; - *cp++ = (k&7) + '0'; + if (k > CCHR('?')) { + *cp++ = '0'; + *cp++ = ((k >> 6) & 7) + '0'; + *cp++ = ((k >> 3) & 7) + '0'; + *cp++ = (k & 7) + '0'; + *cp = '\0'; + return cp; + } + if (k < ' ') { + *cp++ = 'C'; + *cp++ = '-'; + k = CCHR(k); + if (ISUPPER(k)) + k = TOLOWER(k); + } + *cp++ = k; *cp = '\0'; return cp; - } - if(k < ' ') { - *cp++ = 'C'; - *cp++ = '-'; - k = CCHR(k); - if(ISUPPER(k)) k = TOLOWER(k); - } - *cp++ = k; - *cp = '\0'; - return cp; - } - (VOID) strcpy(cp, np); - return cp + strlen(cp); + } + (VOID) strcpy(cp, np); + return cp + strlen(cp); } diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index bf8acb24b8b..57ce809edb9 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,13 +1,13 @@ /* * This file is the general header file for all parts - * of the MicroEMACS display editor. It contains all of the + * of the Mg display editor. It contains all of the * general definitions and macros. It also contains some * conditional compilation flags. All of the per-system and * per-terminal definitions are in special header files. * The most common reason to edit this file would be to zap * the definition of CVMVAS or BACKUP. */ -#include "sysdef.h" /* Order is critical. */ +#include "sysdef.h" /* Order is critical. */ #include "ttydef.h" #include "chrdef.h" @@ -22,43 +22,43 @@ */ #ifdef NO_VOID_TYPE -# undef VOID -# define VOID int /* Default for no void is int */ +#undef VOID +#define VOID int /* Default for no void is int */ #else #ifndef VOID -# define VOID void /* Just use normal void */ -#endif /* VOID */ -#endif /* NO_VOID_TYPE */ +#define VOID void /* Just use normal void */ +#endif /* VOID */ +#endif /* NO_VOID_TYPE */ #ifdef NO_MACRO #ifndef NO_STARTUP -#define NO_STARTUP /* NO_MACRO implies NO_STARTUP */ +#define NO_STARTUP /* NO_MACRO implies NO_STARTUP */ #endif #endif -typedef int (*PF)(); /* generaly useful type */ +typedef int (*PF) (); /* generaly useful type */ /* * Table sizes, etc. */ -#define NFILEN 80 /* Length, file name. */ -#define NBUFN 24 /* Length, buffer name. */ -#define NLINE 256 /* Length, line. */ -#define PBMODES 4 /* modes per buffer */ -#define NKBDM 256 /* Length, keyboard macro. */ -#define NPAT 80 /* Length, pattern. */ -#define HUGE 1000 /* A rather large number. */ -#define NSRCH 128 /* Undoable search commands. */ -#define NXNAME 64 /* Length, extended command. */ -#define NKNAME 20 /* Length, key names */ +#define NFILEN 80 /* Length, file name. */ +#define NBUFN 24 /* Length, buffer name. */ +#define NLINE 256 /* Length, line. */ +#define PBMODES 4 /* modes per buffer */ +#define NKBDM 256 /* Length, keyboard macro. */ +#define NPAT 80 /* Length, pattern. */ +#define HUGE 1000 /* A rather large number. */ +#define NSRCH 128 /* Undoable search commands. */ +#define NXNAME 64 /* Length, extended command. */ +#define NKNAME 20 /* Length, key names */ /* * Universal. */ -#define FALSE 0 /* False, no, bad, etc. */ -#define TRUE 1 /* True, yes, good, etc. */ -#define ABORT 2 /* Death, ^G, abort, etc. */ +#define FALSE 0 /* False, no, bad, etc. */ +#define TRUE 1 /* True, yes, good, etc. */ +#define ABORT 2 /* Death, ^G, abort, etc. */ -#define KPROMPT 2 /* keyboard prompt */ +#define KPROMPT 2 /* keyboard prompt */ /* * These flag bits keep track of @@ -67,55 +67,55 @@ typedef int (*PF)(); /* generaly useful type */ * flag controls the clearing versus appending * of data in the kill buffer. */ -#define CFCPCN 0x0001 /* Last command was C-P, C-N */ -#define CFKILL 0x0002 /* Last command was a kill */ -#define CFINS 0x0004 /* Last command was self-insert */ +#define CFCPCN 0x0001 /* Last command was C-P, C-N */ +#define CFKILL 0x0002 /* Last command was a kill */ +#define CFINS 0x0004 /* Last command was self-insert */ /* * File I/O. */ -#define FIOSUC 0 /* Success. */ -#define FIOFNF 1 /* File not found. */ -#define FIOEOF 2 /* End of file. */ -#define FIOERR 3 /* Error. */ -#define FIOLONG 4 /* long line partially read */ +#define FIOSUC 0 /* Success. */ +#define FIOFNF 1 /* File not found. */ +#define FIOEOF 2 /* End of file. */ +#define FIOERR 3 /* Error. */ +#define FIOLONG 4 /* long line partially read */ /* * Directory I/O. */ -#define DIOSUC 0 /* Success. */ -#define DIOEOF 1 /* End of file. */ -#define DIOERR 2 /* Error. */ +#define DIOSUC 0 /* Success. */ +#define DIOEOF 1 /* End of file. */ +#define DIOERR 2 /* Error. */ /* * Display colors. */ -#define CNONE 0 /* Unknown color. */ -#define CTEXT 1 /* Text color. */ -#define CMODE 2 /* Mode line color. */ +#define CNONE 0 /* Unknown color. */ +#define CTEXT 1 /* Text color. */ +#define CMODE 2 /* Mode line color. */ -/* Flags for keyboard involked functions */ - -#define FFUNIV 1 /* universal argument */ -#define FFNEGARG 2 /* negitive only argument */ -#define FFOTHARG 4 /* other argument */ -#define FFARG 7 /* any argument */ -#define FFRAND 8 /* Called by other function */ +/* + * Flags for keyboard involked functions. + */ +#define FFUNIV 1 /* universal argument */ +#define FFNEGARG 2 /* negitive only argument */ +#define FFOTHARG 4 /* other argument */ +#define FFARG 7 /* any argument */ +#define FFRAND 8 /* Called by other function */ /* * Flags for "eread". */ -#define EFFUNC 0x0001 /* Autocomplete functions. */ -#define EFBUF 0x0002 /* Autocomplete buffers. */ -#define EFFILE 0x0004 /* " files (maybe someday) */ -#define EFAUTO 0x0007 /* Some autocompleteion on */ -#define EFNEW 0x0008 /* New prompt. */ -#define EFCR 0x0010 /* Echo CR at end; last read. */ +#define EFFUNC 0x0001 /* Autocomplete functions. */ +#define EFBUF 0x0002 /* Autocomplete buffers. */ +#define EFFILE 0x0004 /* " files (maybe someday) */ +#define EFAUTO 0x0007 /* Some autocompleteion on */ +#define EFNEW 0x0008 /* New prompt. */ +#define EFCR 0x0010 /* Echo CR at end; last read. */ /* * Flags for "ldelete"/"kinsert" */ - #define KNONE 0 #define KFORW 1 #define KBACK 2 @@ -132,17 +132,17 @@ typedef int (*PF)(); /* generaly useful type */ * additions will include update hints, and a * list of marks into the line. */ -typedef struct LINE { - struct LINE *l_fp; /* Link to the next line */ - struct LINE *l_bp; /* Link to the previous line */ - int l_size; /* Allocated size */ - int l_used; /* Used size */ +typedef struct LINE { + struct LINE *l_fp; /* Link to the next line */ + struct LINE *l_bp; /* Link to the previous line */ + int l_size; /* Allocated size */ + int l_used; /* Used size */ #ifndef ZEROARRAY - char l_text[1]; /* A bunch of characters. */ + char l_text[1]; /* A bunch of chars. */ #else - char l_text[]; /* A bunch of characters. */ + char l_text[]; /* A bunch of chars. */ #endif -} LINE; +} LINE; /* * The rationale behind these macros is that you @@ -170,12 +170,13 @@ typedef struct LINE { */ typedef struct LIST { union { - struct MGWIN *l_wp; - struct BUFFER *x_bp; /* l_bp is used by LINE */ - struct LIST *l_nxt; + struct MGWIN *l_wp; + struct BUFFER *x_bp; /* l_bp is used by LINE */ + struct LIST *l_nxt; } l_p; - char *l_name; + char *l_name; } LIST; + /* * Usual hack - to keep from uglifying the code with lotsa * references through the union, we #define something for it. @@ -192,19 +193,19 @@ typedef struct LIST { * terms of decoupling, the full blown redisplay is just too * expensive to run for every input character. */ -typedef struct MGWIN { - LIST w_list; /* List header */ - struct BUFFER *w_bufp; /* Buffer displayed in window */ - struct LINE *w_linep; /* Top line in the window */ - struct LINE *w_dotp; /* Line containing "." */ - struct LINE *w_markp; /* Line containing "mark" */ - int w_doto; /* Byte offset for "." */ - int w_marko; /* Byte offset for "mark" */ - char w_toprow; /* Origin 0 top row of window */ - char w_ntrows; /* # of rows of text in window */ - char w_force; /* If NZ, forcing row. */ - char w_flag; /* Flags. */ -} MGWIN; +typedef struct MGWIN { + LIST w_list; /* List header */ + struct BUFFER *w_bufp; /* Buffer displayed in window */ + struct LINE *w_linep; /* Top line in the window */ + struct LINE *w_dotp; /* Line containing "." */ + struct LINE *w_markp; /* Line containing "mark" */ + int w_doto; /* Byte offset for "." */ + int w_marko; /* Byte offset for "mark" */ + char w_toprow; /* Origin 0 top row of window */ + char w_ntrows; /* # of rows of text in window */ + char w_force; /* If NZ, forcing row. */ + char w_flag; /* Flags. */ +} MGWIN; #define w_wndp w_list.l_p.l_wp #define w_name w_list.l_name @@ -217,11 +218,11 @@ typedef struct MGWIN { * Because commands set bits in the "w_flag", update will see * all change flags, and do the most general one. */ -#define WFFORCE 0x01 /* Force reframe. */ -#define WFMOVE 0x02 /* Movement from line to line. */ -#define WFEDIT 0x04 /* Editing within a line. */ -#define WFHARD 0x08 /* Better to a full display. */ -#define WFMODE 0x10 /* Update mode line. */ +#define WFFORCE 0x01 /* Force reframe. */ +#define WFMOVE 0x02 /* Movement from line to line. */ +#define WFEDIT 0x04 /* Editing within a line. */ +#define WFHARD 0x08 /* Better to a full display. */ +#define WFMODE 0x10 /* Update mode line. */ /* * Text is kept in buffers. A buffer header, described @@ -233,30 +234,30 @@ typedef struct MGWIN { * the buffer is kept in a circularly linked list of lines, with * a pointer to the header line in "b_linep". */ -typedef struct BUFFER { - LIST b_list; /* buffer list pointer */ - struct BUFFER *b_altb; /* Link to alternate buffer */ - struct LINE *b_dotp; /* Link to "." LINE structure */ - struct LINE *b_markp; /* ditto for mark */ - struct LINE *b_linep; /* Link to the header LINE */ - struct MAPS_S *b_modes[PBMODES]; /* buffer modes */ - int b_doto; /* Offset of "." in above LINE */ - int b_marko; /* ditto for the "mark" */ - short b_nmodes; /* number of non-fundamental modes */ - char b_nwnd; /* Count of windows on buffer */ - char b_flag; /* Flags */ - char b_fname[NFILEN]; /* File name */ - struct fileinfo b_fi; /* File attributes */ -} BUFFER; +typedef struct BUFFER { + LIST b_list; /* buffer list pointer */ + struct BUFFER *b_altb; /* Link to alternate buffer */ + struct LINE *b_dotp; /* Link to "." LINE structure */ + struct LINE *b_markp; /* ditto for mark */ + struct LINE *b_linep; /* Link to the header LINE */ + struct MAPS_S *b_modes[PBMODES]; /* buffer modes */ + int b_doto; /* Offset of "." in above LINE */ + int b_marko; /* ditto for the "mark" */ + short b_nmodes; /* number of non-fundamental modes */ + char b_nwnd; /* Count of windows on buffer */ + char b_flag; /* Flags */ + char b_fname[NFILEN];/* File name */ + struct fileinfo b_fi; /* File attributes */ +} BUFFER; #define b_bufp b_list.l_p.x_bp #define b_bname b_list.l_name -#define BFCHG 0x01 /* Changed. */ -#define BFBAK 0x02 /* Need to make a backup. */ +#define BFCHG 0x01 /* Changed. */ +#define BFBAK 0x02 /* Need to make a backup. */ #ifdef NOTAB -#define BFNOTAB 0x04 /* no tab mode */ +#define BFNOTAB 0x04 /* no tab mode */ #endif -#define BFOVERWRITE 0x08 /* overwrite mode */ +#define BFOVERWRITE 0x08 /* overwrite mode */ /* * This structure holds the starting position @@ -264,43 +265,224 @@ typedef struct BUFFER { * region of a buffer. This makes passing the specification * of a region around a little bit easier. */ -typedef struct { - struct LINE *r_linep; /* Origin LINE address. */ - int r_offset; /* Origin LINE offset. */ - RSIZE r_size; /* Length in characters. */ -} REGION; +typedef struct { + struct LINE *r_linep; /* Origin LINE address. */ + int r_offset; /* Origin LINE offset. */ + RSIZE r_size; /* Length in characters. */ +} REGION; + +/* + * Prototypes. + */ + +/* tty.c */ +VOID ttinit __P((void)); +VOID ttreinit __P((void)); +VOID tttidy __P((void)); +VOID ttmove __P((int, int)); +VOID tteeol __P((void)); +VOID tteeop __P((void)); +VOID ttbeep __P((void)); +VOID ttinsl __P((int, int, int)); +VOID ttdell __P((int, int, int)); +VOID ttwindow __P((int, int)); +VOID ttnowindow __P((void)); +VOID ttcolor __P((int)); +VOID ttresize __P((void)); + +/* ttyio.c */ +VOID ttopen __P((void)); +int ttraw __P((void)); +VOID ttclose __P((void)); +int ttcooked __P((void)); +int ttputc __P((int)); +VOID ttflush __P((void)); +int ttgetc __P((void)); +int ttwait __P((void)); +VOID setttysize __P((void)); +int typeahead __P((void)); + +/* dir.c */ +VOID dirinit __P((VOID)); +int changedir __P((int, int)); +int showcwdir __P((int, int)); + +/* dired.c */ +int dired __P((int, int)); +int d_otherwindow __P((int, int)); +int d_undel __P((int, int)); +int d_undelbak __P((int, int)); +int d_findfile __P((int, int)); +int d_ffotherwindow __P((int, int)); +int d_expunge __P((int, int)); +int d_copy __P((int, int)); +int d_del __P((int, int)); +int d_rename __P((int, int)); + +/* file.c */ +int fileinsert __P((int, int)); +int filevisit __P((int, int)); +int poptofile __P((int, int)); +BUFFER *findbuffer __P((char *)); +int readin __P((char *)); +int insertfile __P((char *, char *, int)); +VOID makename __P((char *, char *)); +int filewrite __P((int, int)); +int filesave __P((int, int)); +int buffsave __P((BUFFER *)); +int makebkfile __P((int, int)); +int writeout __P((BUFFER *, char *)); +VOID upmodes __P((BUFFER *)); + +/* line.c */ +LINE *lalloc __P((int)); +LINE *lallocx __P((int)); +int lnewline __P((void)); +VOID lfree __P((LINE *)); +VOID lchange __P((int)); +VOID kdelete __P((void)); +int ldelnewline __P((void)); +int linsert __P((int, int)); + +/* window.c */ +MGWIN *wpopup __P((void)); +int nextwind __P((int, int)); + +/* buffer.c */ +BUFFER *bfind __P((char *, int)); +int poptobuffer __P((int, int)); +int killbuffer __P((int, int)); +int savebuffers __P((int, int)); +int listbuffers __P((int, int)); +int addline __P((BUFFER *, char *)); +int anycb __P((int)); +int bclear __P((BUFFER *)); +int showbuffer __P((BUFFER *, MGWIN *, int)); +MGWIN *popbuf __P((BUFFER *)); +int bufferinsert __P((int, int)); +int usebuffer __P((int, int)); +int notmodified __P((int, int)); +int popbuftop __P((BUFFER *)); + +/* display.c */ +VOID vtinit __P((void)); +VOID vttidy __P((void)); +VOID update __P((void)); + +/* echo.c */ +int eyorn __P((char *)); +int eyesno __P((char *)); +VOID ewprintf __P((const char *fmt, ...)); +int ereply __P((const char *, char *, int, ...)); +int eread __P((const char *, char *, int, int, ...)); +int getxtra __P((LIST *, LIST *, int, int)); + +/* fileio.c */ +int ffropen __P((char *, BUFFER *)); +int ffwopen __P((char *, BUFFER *)); +int ffclose __P((BUFFER *)); +int ffputbuf __P((BUFFER *)); +int ffgetline __P((char *, int, int *)); +int fbackupfile __P((char *)); +char *adjustname __P((char *)); +char *startupfile __P((char *)); +int copy __P((char *, char *)); +BUFFER *dired_ __P((char *)); +int d_makename __P((LINE *, char *)); +LIST *make_file_list __P((char *, int)); + +/* keymap.c */ +LIST *complete_function_list __P((char *, int)); +int complete_function __P((char *, int)); + +/* kbd.c */ +int do_meta __P((int, int)); +int bsmap __P((int, int)); +VOID ungetkey __P((int)); +int getkey __P((int)); +int doin __P((void)); +int rescan __P((int, int)); +int universal_argument __P((int, int)); +int digit_argument __P((int, int)); +int negative_argument __P((int, int)); +int selfinsert __P((int, int)); +int quote __P((int, int)); + +/* main.c */ +int ctrlg __P((int, int)); + +/* ttyio.c */ +VOID panic __P((char *)); + +/* cinfo.c */ +char *keyname __P((char *, int)); + +/* basic.c */ +int gotobol __P((int, int)); +int backchar __P((int, int)); +int gotoeol __P((int, int)); +int forwchar __P((int, int)); +int gotobob __P((int, int)); +int gotoeob __P((int, int)); +int forwline __P((int, int)); +int backline __P((int, int)); +VOID setgoal __P((void)); +int getgoal __P((LINE *)); +int forwpage __P((int, int)); +int backpage __P((int, int)); +int forw1page __P((int, int)); +int back1page __P((int, int)); +int pagenext __P((int, int)); +VOID isetmark __P((VOID)); +int setmark __P((int, int)); +int swapmark __P((int, int)); +int gotoline __P((int, int)); + +/* random.c */ +int getcolpos __P((void)); +int newline __P((int, int)); + +/* extend.c */ +int insert __P((int, int)); +int bindtokey __P((int, int)); +int localbind __P((int, int)); +int define_key __P((int, int)); +int unbindtokey __P((int, int)); +int localunbind __P((int, int)); +int extend __P((int, int)); +int evalexpr __P((int, int)); +int evalbuffer __P((int, int)); +int evalfile __P((int, int)); +int load __P((char *)); +int excline __P((char *)); + +/* help.c */ +int desckey __P((int, int)); +int wallchart __P((int, int)); +int help_help __P((int, int)); +int apropos_command __P((int, int)); /* * Externals. */ -extern int thisflag; -extern int lastflag; -extern int curgoal; -extern int epresf; -extern int sgarbf; -extern int mode; -extern MGWIN *curwp; -extern BUFFER *curbp; -extern MGWIN *wheadp; -extern BUFFER *bheadp; -extern char pat[]; -extern BUFFER *bfind(); -extern MGWIN *popbuf(); -extern MGWIN *wpopup(); -extern LINE *lalloc(); -extern LINE *lallocx(); -extern VOID ewprintf(); -extern int nrow; -extern int ncol; -extern int ttrow; -extern int ttcol; -extern int tceeol; -extern int tcinsl; -extern int tcdell; -extern char cinfo[]; -extern char *keystrings[]; -extern VOID update(); -extern char *keyname(); -extern char *adjustname(); -extern VOID kdelete(); -extern VOID lchange(); +extern int thisflag; +extern int lastflag; +extern int curgoal; +extern int epresf; +extern int sgarbf; +extern int mode; +extern MGWIN *curwp; +extern BUFFER *curbp; +extern MGWIN *wheadp; +extern BUFFER *bheadp; +extern char pat[]; +extern int nrow; +extern int ncol; +extern int ttrow; +extern int ttcol; +extern int tthue; +extern int tceeol; +extern int tcinsl; +extern int tcdell; +extern char cinfo[]; +extern char *keystrings[]; diff --git a/usr.bin/mg/dir.c b/usr.bin/mg/dir.c index d96e6552473..b667c862b6e 100644 --- a/usr.bin/mg/dir.c +++ b/usr.bin/mg/dir.c @@ -8,14 +8,16 @@ #include "def.h" #ifndef NO_DIR -char *wdir; -static char cwd[NFILEN]; +char *wdir; +static char cwd[NFILEN]; /* * Initialize anything the directory management routines need */ +VOID dirinit() { + if (!(wdir = getcwd(cwd, sizeof(cwd)))) panic("Can't get current directory!"); } @@ -23,34 +25,38 @@ dirinit() /* * Change current working directory */ -/*ARGSUSED*/ +/* ARGSUSED */ +int changedir(f, n) + int f, n; { - register int s; - char bufc[NPAT]; + int s; + char bufc[NPAT]; - if ((s=ereply("Change default directory: ", bufc, NPAT)) != TRUE) - return(s); + if ((s = ereply("Change default directory: ", bufc, NPAT)) != TRUE) + return (s); if (bufc[0] == '\0') (VOID) strcpy(bufc, wdir); if (chdir(bufc) == -1) { ewprintf("Can't change dir to %s", bufc); - return(FALSE); + return (FALSE); } else { if (!(wdir = getcwd(cwd, sizeof(cwd)))) panic("Can't get current directory!"); ewprintf("Current directory is now %s", wdir); - return(TRUE); + return (TRUE); } } /* * Show current directory */ -/*ARGSUSED*/ +/* ARGSUSED */ +int showcwdir(f, n) { + ewprintf("Current directory: %s", wdir); - return(TRUE); + return (TRUE); } #endif diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c index aad6763fc79..bf231c85060 100644 --- a/usr.bin/mg/dired.c +++ b/usr.bin/mg/dired.c @@ -1,195 +1,217 @@ -/* dired module for mg 2a */ -/* by Robert A. Larson */ +/* dired module for mg 2a */ +/* by Robert A. Larson */ #include "def.h" #ifndef NO_DIRED -BUFFER *dired_(); - -/*ARGSUSED*/ +/* ARGSUSED */ +int dired(f, n) -int f, n; + int f, n; { - char dirname[NFILEN]; - BUFFER *bp; - - dirname[0] = '\0'; - if(eread("Dired: ", dirname, NFILEN, EFNEW | EFCR) == ABORT) - return ABORT; - if((bp = dired_(dirname)) == NULL) return FALSE; - curbp = bp; - return showbuffer(bp, curwp, WFHARD | WFMODE); + char dirname[NFILEN]; + BUFFER *bp; + + dirname[0] = '\0'; + if (eread("Dired: ", dirname, NFILEN, EFNEW | EFCR) == ABORT) + return ABORT; + if ((bp = dired_(dirname)) == NULL) + return FALSE; + curbp = bp; + return showbuffer(bp, curwp, WFHARD | WFMODE); } -/*ARGSUSED*/ +/* ARGSUSED */ +int d_otherwindow(f, n) -int f, n; + int f, n; { - char dirname[NFILEN]; - BUFFER *bp; - MGWIN *wp; - - dirname[0] = '\0'; - if(eread("Dired other window: ", dirname, NFILEN, EFNEW | EFCR) == ABORT) - return ABORT; - if((bp = dired_(dirname)) == NULL) return FALSE; - if((wp = popbuf(bp)) == NULL) return FALSE; - curbp = bp; - curwp = wp; - return TRUE; + char dirname[NFILEN]; + BUFFER *bp; + MGWIN *wp; + + dirname[0] = '\0'; + if (eread("Dired other window: ", dirname, NFILEN, EFNEW | EFCR) == ABORT) + return ABORT; + if ((bp = dired_(dirname)) == NULL) + return FALSE; + if ((wp = popbuf(bp)) == NULL) + return FALSE; + curbp = bp; + curwp = wp; + return TRUE; } -/*ARGSUSED*/ +/* ARGSUSED */ +int d_del(f, n) -int f, n; + int f, n; { - if(n < 0) return FALSE; - while(n--) { - if(llength(curwp->w_dotp) > 0) - lputc(curwp->w_dotp, 0, 'D'); - if(lforw(curwp->w_dotp) != curbp->b_linep) - curwp->w_dotp = lforw(curwp->w_dotp); - } - curwp->w_flag |= WFEDIT | WFMOVE; - curwp->w_doto = 0; - return TRUE; + + if (n < 0) + return FALSE; + while (n--) { + if (llength(curwp->w_dotp) > 0) + lputc(curwp->w_dotp, 0, 'D'); + if (lforw(curwp->w_dotp) != curbp->b_linep) + curwp->w_dotp = lforw(curwp->w_dotp); + } + curwp->w_flag |= WFEDIT | WFMOVE; + curwp->w_doto = 0; + return TRUE; } -/*ARGSUSED*/ +/* ARGSUSED */ +int d_undel(f, n) -int f, n; + int f, n; { - if(n < 0) return d_undelbak(f, -n); - while(n--) { - if(llength(curwp->w_dotp) > 0) - lputc(curwp->w_dotp, 0, ' '); - if(lforw(curwp->w_dotp) != curbp->b_linep) - curwp->w_dotp = lforw(curwp->w_dotp); - } - curwp->w_flag |= WFEDIT | WFMOVE; - curwp->w_doto = 0; - return TRUE; + if (n < 0) + return d_undelbak(f, -n); + while (n--) { + if (llength(curwp->w_dotp) > 0) + lputc(curwp->w_dotp, 0, ' '); + if (lforw(curwp->w_dotp) != curbp->b_linep) + curwp->w_dotp = lforw(curwp->w_dotp); + } + curwp->w_flag |= WFEDIT | WFMOVE; + curwp->w_doto = 0; + return TRUE; } -/*ARGSUSED*/ +/* ARGSUSED */ +int d_undelbak(f, n) -int f, n; + int f, n; { - if(n < 0) return d_undel(f, -n); - while(n--) { - if(llength(curwp->w_dotp) > 0) - lputc(curwp->w_dotp, 0, ' '); - if(lback(curwp->w_dotp) != curbp->b_linep) - curwp->w_dotp = lback(curwp->w_dotp); - } - curwp->w_doto = 0; - curwp->w_flag |= WFEDIT | WFMOVE; - return TRUE; + + if (n < 0) + return d_undel(f, -n); + while (n--) { + if (llength(curwp->w_dotp) > 0) + lputc(curwp->w_dotp, 0, ' '); + if (lback(curwp->w_dotp) != curbp->b_linep) + curwp->w_dotp = lback(curwp->w_dotp); + } + curwp->w_doto = 0; + curwp->w_flag |= WFEDIT | WFMOVE; + return TRUE; } -/*ARGSUSED*/ +/* ARGSUSED */ +int d_findfile(f, n) -int f, n; + int f, n; { - char fname[NFILEN]; - register BUFFER *bp; - register int s; - BUFFER *findbuffer(); - - if((s = d_makename(curwp->w_dotp, fname)) == ABORT) return FALSE; - if ((bp = (s ? dired_(fname) : findbuffer(fname))) == NULL) return FALSE; - curbp = bp; - if (showbuffer(bp, curwp, WFHARD) != TRUE) return FALSE; - if (bp->b_fname[0] != 0) return TRUE; - return readin(fname); + BUFFER *bp; + int s; + char fname[NFILEN]; + + if ((s = d_makename(curwp->w_dotp, fname)) == ABORT) + return FALSE; + if ((bp = (s ? dired_(fname) : findbuffer(fname))) == NULL) + return FALSE; + curbp = bp; + if (showbuffer(bp, curwp, WFHARD) != TRUE) + return FALSE; + if (bp->b_fname[0] != 0) + return TRUE; + return readin(fname); } -/*ARGSUSED*/ +/* ARGSUSED */ +int d_ffotherwindow(f, n) -int f, n; + int f, n; { - char fname[NFILEN]; - register BUFFER *bp; - register int s; - register MGWIN *wp; - BUFFER *findbuffer(); - - if((s = d_makename(curwp->w_dotp, fname)) == ABORT) return FALSE; - if ((bp = (s ? dired_(fname) : findbuffer(fname))) == NULL) return FALSE; - if ((wp = popbuf(bp)) == NULL) return FALSE; - curbp = bp; - curwp = wp; - if (bp->b_fname[0] != 0) return TRUE; /* never true for dired buffers */ - return readin(fname); + char fname[NFILEN]; + int s; + BUFFER *bp; + MGWIN *wp; + + if ((s = d_makename(curwp->w_dotp, fname)) == ABORT) + return FALSE; + if ((bp = (s ? dired_(fname) : findbuffer(fname))) == NULL) + return FALSE; + if ((wp = popbuf(bp)) == NULL) + return FALSE; + curbp = bp; + curwp = wp; + if (bp->b_fname[0] != 0) + return TRUE; /* never true for dired buffers */ + return readin(fname); } -/*ARGSUSED*/ +/* ARGSUSED */ +int d_expunge(f, n) -int f, n; + int f, n; { - register LINE *lp, *nlp; - char fname[NFILEN]; - VOID lfree(); - - for(lp = lforw(curbp->b_linep); lp != curbp->b_linep; lp = nlp) { - nlp = lforw(lp); - if(llength(lp) && lgetc(lp, 0) == 'D') { - switch(d_makename(lp, fname)) { - case ABORT: - ewprintf("Bad line in dired buffer"); - return FALSE; - case FALSE: - if(unlink(fname) < 0) { - ewprintf("Could not delete '%s'", fname); - return FALSE; - } - break; - case TRUE: - if(rmdir(fname) < 0) { - ewprintf("Could not delete directory '%s'", fname); - return FALSE; - } - break; - } - lfree(lp); - curwp->w_flag |= WFHARD; + LINE *lp, *nlp; + char fname[NFILEN]; + + for (lp = lforw(curbp->b_linep); lp != curbp->b_linep; lp = nlp) { + nlp = lforw(lp); + if (llength(lp) && lgetc(lp, 0) == 'D') { + switch (d_makename(lp, fname)) { + case ABORT: + ewprintf("Bad line in dired buffer"); + return FALSE; + case FALSE: + if (unlink(fname) < 0) { + ewprintf("Could not delete '%s'", fname); + return FALSE; + } + break; + case TRUE: + if (rmdir(fname) < 0) { + ewprintf("Could not delete directory '%s'", + fname); + return FALSE; + } + break; + } + lfree(lp); + curwp->w_flag |= WFHARD; + } } - } - return TRUE; + return TRUE; } -/*ARGSUSED*/ +/* ARGSUSED */ +int d_copy(f, n) -int f, n; + int f, n; { - char frname[NFILEN], toname[NFILEN]; - int stat; - - if(d_makename(curwp->w_dotp, frname) != FALSE) { - ewprintf("Not a file"); - return FALSE; - } - if((stat = eread("Copy %s to: ", toname, NFILEN, EFNEW | EFCR, frname)) - != TRUE) return stat; - return copy(frname, toname) >= 0; + char frname[NFILEN], toname[NFILEN]; + int stat; + + if (d_makename(curwp->w_dotp, frname) != FALSE) { + ewprintf("Not a file"); + return FALSE; + } + if ((stat = eread("Copy %s to: ", toname, NFILEN, EFNEW | EFCR, frname)) + != TRUE) + return stat; + return copy(frname, toname) >= 0; } -/*ARGSUSED*/ +/* ARGSUSED */ +int d_rename(f, n) -int f, n; + int f, n; { - char frname[NFILEN], toname[NFILEN]; - int stat; - - if(d_makename(curwp->w_dotp, frname) != FALSE) { - ewprintf("Not a file"); - return FALSE; - } - if((stat = eread("Rename %s to: ", toname, NFILEN, EFNEW | EFCR, frname)) - != TRUE) return stat; - return rename(frname, toname) >= 0; + char frname[NFILEN], toname[NFILEN]; + int stat; + + if (d_makename(curwp->w_dotp, frname) != FALSE) { + ewprintf("Not a file"); + return FALSE; + } + if ((stat = eread("Rename %s to: ", toname, NFILEN, EFNEW | EFCR, + frname)) != TRUE) + return stat; + return rename(frname, toname) >= 0; } #endif - - diff --git a/usr.bin/mg/display.c b/usr.bin/mg/display.c index 24341c28579..321d02e6c4d 100644 --- a/usr.bin/mg/display.c +++ b/usr.bin/mg/display.c @@ -23,8 +23,8 @@ */ /* These defines really belong in sysdef.h */ #ifndef XCHAR -# define XCHAR int -# define XSHORT int +#define XCHAR int +#define XSHORT int #endif #ifdef STANDOUT_GLITCH @@ -37,17 +37,17 @@ * the longest line possible. Only some of this is * used if "ncol" isn't the same as "NCOL". */ -typedef struct { - short v_hash; /* Hash code, for compares. */ - short v_flag; /* Flag word. */ - short v_color; /* Color of the line. */ - XSHORT v_cost; /* Cost of display. */ - char v_text[NCOL]; /* The actual characters. */ -} VIDEO; - -#define VFCHG 0x0001 /* Changed. */ -#define VFHBAD 0x0002 /* Hash and cost are bad. */ -#define VFEXT 0x0004 /* extended line (beond ncol) */ +typedef struct { + short v_hash; /* Hash code, for compares. */ + short v_flag; /* Flag word. */ + short v_color; /* Color of the line. */ + XSHORT v_cost; /* Cost of display. */ + char v_text[NCOL]; /* The actual characters. */ +} VIDEO; + +#define VFCHG 0x0001 /* Changed. */ +#define VFHBAD 0x0002 /* Hash and cost are bad. */ +#define VFEXT 0x0004 /* extended line (beond ncol) */ /* * SCORE structures hold the optimal @@ -57,45 +57,42 @@ typedef struct { * fields can be "char", and the score a "short", but * this makes the code worse on the VAX. */ -typedef struct { - XCHAR s_itrace; /* "i" index for track back. */ - XCHAR s_jtrace; /* "j" index for trace back. */ - XSHORT s_cost; /* Display cost. */ -} SCORE; - -int sgarbf = TRUE; /* TRUE if screen is garbage. */ -int vtrow = 0; /* Virtual cursor row. */ -int vtcol = 0; /* Virtual cursor column. */ -int tthue = CNONE; /* Current color. */ -int ttrow = HUGE; /* Physical cursor row. */ -int ttcol = HUGE; /* Physical cursor column. */ -int tttop = HUGE; /* Top of scroll region. */ -int ttbot = HUGE; /* Bottom of scroll region. */ -int lbound = 0; /* leftmost bound of the current line */ - /* being displayed */ - -VIDEO *vscreen[NROW-1]; /* Edge vector, virtual. */ -VIDEO *pscreen[NROW-1]; /* Edge vector, physical. */ -VIDEO video[2*(NROW-1)]; /* Actual screen data. */ -VIDEO blanks; /* Blank line image. */ - -/* - * Some predeclerations to make ANSI compilers happy - */ -VOID vtinit(); -VOID vttidy(); -VOID vtmove(); -VOID vtputc(); -VOID vtpute(); -VOID vteeol(); -VOID update(); -VOID updext(); -VOID ucopy(); -VOID uline(); -VOID modeline(); -VOID hash(); -VOID setscores(); -VOID traceback(); +typedef struct { + XCHAR s_itrace; /* "i" index for track back. */ + XCHAR s_jtrace; /* "j" index for trace back. */ + XSHORT s_cost; /* Display cost. */ +} SCORE; + + +VOID vtmove __P((int, int)); +VOID vtputc __P((int)); +VOID vtpute __P((int)); +int vtputs __P((char *)); +VOID vteeol __P((void)); +VOID updext __P((int, int)); +VOID modeline __P((MGWIN *)); +VOID setscores __P((int, int)); +VOID traceback __P((int, int, int, int)); +VOID ucopy __P((VIDEO *, VIDEO *)); +VOID uline __P((int, VIDEO *, VIDEO *)); +VOID hash __P((VIDEO *)); + + +int sgarbf = TRUE; /* TRUE if screen is garbage. */ +int vtrow = 0; /* Virtual cursor row. */ +int vtcol = 0; /* Virtual cursor column. */ +int tthue = CNONE; /* Current color. */ +int ttrow = HUGE; /* Physical cursor row. */ +int ttcol = HUGE; /* Physical cursor column. */ +int tttop = HUGE; /* Top of scroll region. */ +int ttbot = HUGE; /* Bottom of scroll region. */ +int lbound = 0; /* leftmost bound of the current line */ + /* being displayed */ + +VIDEO *vscreen[NROW - 1]; /* Edge vector, virtual. */ +VIDEO *pscreen[NROW - 1]; /* Edge vector, physical. */ +VIDEO video[2 * (NROW - 1)]; /* Actual screen data. */ +VIDEO blanks; /* Blank line image. */ #ifdef GOSLING /* @@ -105,7 +102,7 @@ VOID traceback(); * It would be "SCORE score[NROW][NROW]" in old speak. * Look at "setscores" to understand what is up. */ -SCORE score[NROW*NROW]; +SCORE score[NROW * NROW]; #endif /* @@ -120,21 +117,22 @@ SCORE score[NROW*NROW]; * on the first call to redisplay. */ VOID -vtinit() { - register VIDEO *vp; - register int i; +vtinit() +{ + VIDEO *vp; + int i; ttopen(); ttinit(); vp = &video[0]; - for (i=0; i<NROW-1; ++i) { + for (i = 0; i < NROW - 1; ++i) { vscreen[i] = vp; ++vp; pscreen[i] = vp; ++vp; } blanks.v_color = CTEXT; - for (i=0; i<NCOL; ++i) + for (i = 0; i < NCOL; ++i) blanks.v_text[i] = ' '; } @@ -146,10 +144,12 @@ vtinit() { * close the terminal channel. */ VOID -vttidy() { +vttidy() +{ + ttcolor(CTEXT); - ttnowindow(); /* No scroll window. */ - ttmove(nrow-1, 0); /* Echo line. */ + ttnowindow(); /* No scroll window. */ + ttmove(nrow - 1, 0); /* Echo line. */ tteeol(); tttidy(); ttflush(); @@ -164,7 +164,10 @@ vttidy() { * more efficient. No checking for errors. */ VOID -vtmove(row, col) { +vtmove(row, col) + int row, col; +{ + vtrow = row; vtcol = col; } @@ -182,20 +185,22 @@ vtmove(row, col) { * Three guesses how we found this. */ VOID -vtputc(c) register int c; { - register VIDEO *vp; +vtputc(c) + int c; +{ + VIDEO *vp; vp = vscreen[vtrow]; if (vtcol >= ncol) - vp->v_text[ncol-1] = '$'; + vp->v_text[ncol - 1] = '$'; else if (c == '\t' #ifdef NOTAB - && !(curbp->b_flag & BFNOTAB) + && !(curbp->b_flag & BFNOTAB) #endif - ) { + ) { do { vtputc(' '); - } while (vtcol<ncol && (vtcol&0x07)!=0); + } while (vtcol < ncol && (vtcol & 0x07) != 0); } else if (ISCTRL(c)) { vtputc('^'); vtputc(CCHR(c)); @@ -203,47 +208,49 @@ vtputc(c) register int c; { vp->v_text[vtcol++] = c; } -/* Put a character to the virtual screen in an extended line. If we are - * not yet on left edge, don't print it yet. Check for overflow on - * the right margin. +/* + * Put a character to the virtual screen in an extended line. If we are not + * yet on left edge, don't print it yet. Check for overflow on the right + * margin. */ VOID vtpute(c) -int c; + int c; { - register VIDEO *vp; + VIDEO *vp; - vp = vscreen[vtrow]; + vp = vscreen[vtrow]; - if (vtcol >= ncol) vp->v_text[ncol - 1] = '$'; - else if (c == '\t' + if (vtcol >= ncol) + vp->v_text[ncol - 1] = '$'; + else if (c == '\t' #ifdef NOTAB - && !(curbp->b_flag & BFNOTAB) + && !(curbp->b_flag & BFNOTAB) #endif - ) { - do { - vtpute(' '); + ) { + do { + vtpute(' '); + } + while (((vtcol + lbound) & 0x07) != 0 && vtcol < ncol); + } else if (ISCTRL(c) != FALSE) { + vtpute('^'); + vtpute(CCHR(c)); + } else { + if (vtcol >= 0) + vp->v_text[vtcol] = c; + ++vtcol; } - while (((vtcol + lbound)&0x07) != 0 && vtcol < ncol); - } else if (ISCTRL(c) != FALSE) { - vtpute('^'); - vtpute(CCHR(c)); - } else { - if (vtcol >= 0) vp->v_text[vtcol] = c; - ++vtcol; - } } -/* Erase from the end of the - * software cursor to the end of the - * line on which the software cursor is - * located. The display routines will decide - * if a hardware erase to end of line command - * should be used to display this. +/* + * Erase from the end of the software cursor to the end of the line on which + * the software cursor is located. The display routines will decide if a + * hardware erase to end of line command should be used to display this. */ VOID -vteeol() { - register VIDEO *vp; +vteeol() +{ + VIDEO *vp; vp = vscreen[vtrow]; while (vtcol < ncol) @@ -260,37 +267,37 @@ vteeol() { * virtual and physical screens the same. */ VOID -update() { - register LINE *lp; - register MGWIN *wp; - register VIDEO *vp1; - VIDEO *vp2; - register int i; - register int j; - register int c; - register int hflag; - register int currow; - register int curcol; - register int offs; - register int size; - VOID traceback (); - VOID uline (); - - if (typeahead()) return; - if (sgarbf) { /* must update everything */ +update() +{ + LINE *lp; + MGWIN *wp; + VIDEO *vp1; + VIDEO *vp2; + int i; + int j; + int c; + int hflag; + int currow; + int curcol; + int offs; + int size; + + if (typeahead()) + return; + if (sgarbf) { /* must update everything */ wp = wheadp; - while(wp != NULL) { + while (wp != NULL) { wp->w_flag |= WFMODE | WFHARD; wp = wp->w_wndp; } } - hflag = FALSE; /* Not hard. */ + hflag = FALSE; /* Not hard. */ wp = wheadp; while (wp != NULL) { - if (wp->w_flag != 0) { /* Need update. */ - if ((wp->w_flag&WFFORCE) == 0) { + if (wp->w_flag != 0) { /* Need update. */ + if ((wp->w_flag & WFFORCE) == 0) { lp = wp->w_linep; - for (i=0; i<wp->w_ntrows; ++i) { + for (i = 0; i < wp->w_ntrows; ++i) { if (lp == wp->w_dotp) goto out; if (lp == wp->w_bufp->b_linep) @@ -298,46 +305,46 @@ update() { lp = lforw(lp); } } - i = wp->w_force; /* Reframe this one. */ + i = wp->w_force; /* Reframe this one. */ if (i > 0) { --i; if (i >= wp->w_ntrows) - i = wp->w_ntrows-1; + i = wp->w_ntrows - 1; } else if (i < 0) { i += wp->w_ntrows; if (i < 0) i = 0; } else - i = wp->w_ntrows/2; + i = wp->w_ntrows / 2; lp = wp->w_dotp; - while (i!=0 && lback(lp)!=wp->w_bufp->b_linep) { + while (i != 0 && lback(lp) != wp->w_bufp->b_linep) { --i; lp = lback(lp); } wp->w_linep = lp; - wp->w_flag |= WFHARD; /* Force full. */ - out: - lp = wp->w_linep; /* Try reduced update. */ - i = wp->w_toprow; - if ((wp->w_flag&~WFMODE) == WFEDIT) { + wp->w_flag |= WFHARD; /* Force full. */ + out: + lp = wp->w_linep; /* Try reduced update. */ + i = wp->w_toprow; + if ((wp->w_flag & ~WFMODE) == WFEDIT) { while (lp != wp->w_dotp) { ++i; lp = lforw(lp); } vscreen[i]->v_color = CTEXT; - vscreen[i]->v_flag |= (VFCHG|VFHBAD); + vscreen[i]->v_flag |= (VFCHG | VFHBAD); vtmove(i, 0); - for (j=0; j<llength(lp); ++j) + for (j = 0; j < llength(lp); ++j) vtputc(lgetc(lp, j)); vteeol(); - } else if ((wp->w_flag&(WFEDIT|WFHARD)) != 0) { + } else if ((wp->w_flag & (WFEDIT | WFHARD)) != 0) { hflag = TRUE; - while (i < wp->w_toprow+wp->w_ntrows) { + while (i < wp->w_toprow + wp->w_ntrows) { vscreen[i]->v_color = CTEXT; - vscreen[i]->v_flag |= (VFCHG|VFHBAD); + vscreen[i]->v_flag |= (VFCHG | VFHBAD); vtmove(i, 0); if (lp != wp->w_bufp->b_linep) { - for (j=0; j<llength(lp); ++j) + for (j = 0; j < llength(lp); ++j) vtputc(lgetc(lp, j)); lp = lforw(lp); } @@ -345,14 +352,14 @@ update() { ++i; } } - if ((wp->w_flag&WFMODE) != 0) + if ((wp->w_flag & WFMODE) != 0) modeline(wp); - wp->w_flag = 0; + wp->w_flag = 0; wp->w_force = 0; } wp = wp->w_wndp; } - lp = curwp->w_linep; /* Cursor location. */ + lp = curwp->w_linep; /* Cursor location. */ currow = curwp->w_toprow; while (lp != curwp->w_dotp) { ++currow; @@ -364,59 +371,62 @@ update() { c = lgetc(lp, i++); if (c == '\t' #ifdef NOTAB - && !(curbp->b_flag & BFNOTAB) + && !(curbp->b_flag & BFNOTAB) #endif - ) curcol |= 0x07; + ) + curcol |= 0x07; else if (ISCTRL(c) != FALSE) ++curcol; ++curcol; } - if (curcol >= ncol - 1) { /* extended line. */ - /* flag we are extended and changed */ + if (curcol >= ncol - 1) { /* extended line. */ + /* flag we are extended and changed */ vscreen[currow]->v_flag |= VFEXT | VFCHG; - updext(currow, curcol); /* and output extended line */ - } else lbound = 0; /* not extended line */ - - /* make sure no lines need to be de-extended because the cursor is - no longer on them */ + updext(currow, curcol); /* and output extended line */ + } else + lbound = 0; /* not extended line */ + /* + * make sure no lines need to be de-extended because the cursor is no + * longer on them + */ wp = wheadp; - while (wp != NULL) { - lp = wp->w_linep; - i = wp->w_toprow; - while (i < wp->w_toprow + wp->w_ntrows) { - if (vscreen[i]->v_flag & VFEXT) { - /* always flag extended lines as changed */ - vscreen[i]->v_flag |= VFCHG; - if ((wp != curwp) || (lp != wp->w_dotp) || - (curcol < ncol - 1)) { - vtmove(i, 0); - for (j = 0; j < llength(lp); ++j) - vtputc(lgetc(lp, j)); - vteeol(); - /* this line no longer is extended */ - vscreen[i]->v_flag &= ~VFEXT; - } + lp = wp->w_linep; + i = wp->w_toprow; + while (i < wp->w_toprow + wp->w_ntrows) { + if (vscreen[i]->v_flag & VFEXT) { + /* always flag extended lines as changed */ + vscreen[i]->v_flag |= VFCHG; + if ((wp != curwp) || (lp != wp->w_dotp) || + (curcol < ncol - 1)) { + vtmove(i, 0); + for (j = 0; j < llength(lp); ++j) + vtputc(lgetc(lp, j)); + vteeol(); + /* this line no longer is extended */ + vscreen[i]->v_flag &= ~VFEXT; + } + } + lp = lforw(lp); + ++i; } - lp = lforw(lp); - ++i; - } - /* if garbaged then fix up mode lines */ - if (sgarbf != FALSE) vscreen[i]->v_flag |= VFCHG; - /* and onward to the next window */ - wp = wp->w_wndp; + /* if garbaged then fix up mode lines */ + if (sgarbf != FALSE) + vscreen[i]->v_flag |= VFCHG; + /* and onward to the next window */ + wp = wp->w_wndp; } - if (sgarbf != FALSE) { /* Screen is garbage. */ - sgarbf = FALSE; /* Erase-page clears */ - epresf = FALSE; /* the message area. */ - tttop = HUGE; /* Forget where you set */ - ttbot = HUGE; /* scroll region. */ - tthue = CNONE; /* Color unknown. */ + if (sgarbf != FALSE) { /* Screen is garbage. */ + sgarbf = FALSE; /* Erase-page clears */ + epresf = FALSE; /* the message area. */ + tttop = HUGE; /* Forget where you set */ + ttbot = HUGE; /* scroll region. */ + tthue = CNONE; /* Color unknown. */ ttmove(0, 0); tteeop(); - for (i=0; i<nrow-1; ++i) { + for (i = 0; i < nrow - 1; ++i) { uline(i, vscreen[i], &blanks); ucopy(vscreen[i], pscreen[i]); } @@ -426,34 +436,34 @@ update() { } #ifdef GOSLING if (hflag != FALSE) { /* Hard update? */ - for (i=0; i<nrow-1; ++i) { /* Compute hash data. */ + for (i = 0; i < nrow - 1; ++i) {/* Compute hash data. */ hash(vscreen[i]); hash(pscreen[i]); } offs = 0; /* Get top match. */ - while (offs != nrow-1) { + while (offs != nrow - 1) { vp1 = vscreen[offs]; vp2 = pscreen[offs]; if (vp1->v_color != vp2->v_color - || vp1->v_hash != vp2->v_hash) + || vp1->v_hash != vp2->v_hash) break; uline(offs, vp1, vp2); ucopy(vp1, vp2); ++offs; } - if (offs == nrow-1) { /* Might get it all. */ + if (offs == nrow - 1) { /* Might get it all. */ ttmove(currow, curcol - lbound); ttflush(); return; } - size = nrow-1; /* Get bottom match. */ + size = nrow - 1; /* Get bottom match. */ while (size != offs) { - vp1 = vscreen[size-1]; - vp2 = pscreen[size-1]; + vp1 = vscreen[size - 1]; + vp2 = pscreen[size - 1]; if (vp1->v_color != vp2->v_color - || vp1->v_hash != vp2->v_hash) + || vp1->v_hash != vp2->v_hash) break; - uline(size-1, vp1, vp2); + uline(size - 1, vp1, vp2); ucopy(vp1, vp2); --size; } @@ -461,17 +471,17 @@ update() { panic("Illegal screen size in update"); setscores(offs, size); /* Do hard update. */ traceback(offs, size, size, size); - for (i=0; i<size; ++i) - ucopy(vscreen[offs+i], pscreen[offs+i]); + for (i = 0; i < size; ++i) + ucopy(vscreen[offs + i], pscreen[offs + i]); ttmove(currow, curcol - lbound); ttflush(); return; } #endif - for (i=0; i<nrow-1; ++i) { /* Easy update. */ + for (i = 0; i < nrow - 1; ++i) { /* Easy update. */ vp1 = vscreen[i]; vp2 = pscreen[i]; - if ((vp1->v_flag&VFCHG) != 0) { + if ((vp1->v_flag & VFCHG) != 0) { uline(i, vp1, vp2); ucopy(vp1, vp2); } @@ -489,39 +499,46 @@ update() { * display has done an update. */ VOID -ucopy(vvp, pvp) register VIDEO *vvp; register VIDEO *pvp; { +ucopy(vvp, pvp) + VIDEO *vvp; + VIDEO *pvp; +{ - vvp->v_flag &= ~VFCHG; /* Changes done. */ - pvp->v_flag = vvp->v_flag; /* Update model. */ - pvp->v_hash = vvp->v_hash; - pvp->v_cost = vvp->v_cost; + vvp->v_flag &= ~VFCHG; /* Changes done. */ + pvp->v_flag = vvp->v_flag; /* Update model. */ + pvp->v_hash = vvp->v_hash; + pvp->v_cost = vvp->v_cost; pvp->v_color = vvp->v_color; bcopy(vvp->v_text, pvp->v_text, ncol); } -/* updext: update the extended line which the cursor is currently - * on at a column greater than the terminal width. The line - * will be scrolled right or left to let the user see where - * the cursor is +/* + * updext: update the extended line which the cursor is currently on at a + * column greater than the terminal width. The line will be scrolled right or + * left to let the user see where the cursor is */ VOID updext(currow, curcol) -int currow, curcol; + int currow, curcol; { - register LINE *lp; /* pointer to current line */ - register int j; /* index into line */ - - /* calculate what column the left bound should be */ - /* (force cursor into middle half of screen) */ - lbound = curcol - (curcol % (ncol>>1)) - (ncol>>2); - /* scan through the line outputing characters to the virtual screen */ - /* once we reach the left edge */ - vtmove(currow, -lbound); /* start scanning offscreen */ - lp = curwp->w_dotp; /* line to output */ - for (j=0; j<llength(lp); ++j) /* until the end-of-line */ - vtpute(lgetc(lp, j)); - vteeol(); /* truncate the virtual line */ - vscreen[currow]->v_text[0] = '$'; /* and put a '$' in column 1 */ + LINE *lp; /* pointer to current line */ + int j; /* index into line */ + + /* + * calculate what column the left bound should be + * (force cursor into middle half of screen) + */ + lbound = curcol - (curcol % (ncol >> 1)) - (ncol >> 2); + /* + * scan through the line outputing characters to the virtual screen + * once we reach the left edge + */ + vtmove(currow, -lbound); /* start scanning offscreen */ + lp = curwp->w_dotp; /* line to output */ + for (j = 0; j < llength(lp); ++j) /* until the end-of-line */ + vtpute(lgetc(lp, j)); + vteeol(); /* truncate the virtual line */ + vscreen[currow]->v_text[0] = '$'; /* and put a '$' in column 1 */ } /* @@ -533,19 +550,24 @@ int currow, curcol; * line when updating CMODE color lines, because of the way that * reverse video works on most terminals. */ -VOID uline(row, vvp, pvp) VIDEO *vvp; VIDEO *pvp; { +VOID +uline(row, vvp, pvp) + int row; + VIDEO *vvp; + VIDEO *pvp; +{ #ifdef MEMMAP - putline(row+1, 1, &vvp->v_text[0]); + putline(row + 1, 1, &vvp->v_text[0]); #else - register char *cp1; - register char *cp2; - register char *cp3; - char *cp4; - char *cp5; - register int nbflag; - - if (vvp->v_color != pvp->v_color) { /* Wrong color, do a */ - ttmove(row, 0); /* full redraw. */ + char *cp1; + char *cp2; + char *cp3; + char *cp4; + char *cp5; + int nbflag; + + if (vvp->v_color != pvp->v_color) { /* Wrong color, do a */ + ttmove(row, 0); /* full redraw. */ #ifdef STANDOUT_GLITCH if (pvp->v_color != CTEXT && magic_cookie_glitch >= 0) tteeol(); @@ -553,12 +575,12 @@ VOID uline(row, vvp, pvp) VIDEO *vvp; VIDEO *pvp; { ttcolor(vvp->v_color); #ifdef STANDOUT_GLITCH cp1 = &vvp->v_text[magic_cookie_glitch > 0 ? magic_cookie_glitch : 0]; - /* the odd code for magic_cookie_glitch==0 - * is to avoid putting the invisable - * glitch character on the next line. + /* + * the odd code for magic_cookie_glitch==0 is to avoid + * putting the invisable glitch character on the next line. * (Hazeltine executive 80 model 30) */ - cp2 = &vvp->v_text[ncol - (magic_cookie_glitch >= 0 ? (magic_cookie_glitch!=0 ? magic_cookie_glitch : 1) : 0)]; + cp2 = &vvp->v_text[ncol - (magic_cookie_glitch >= 0 ? (magic_cookie_glitch != 0 ? magic_cookie_glitch : 1) : 0)]; #else cp1 = &vvp->v_text[0]; cp2 = &vvp->v_text[ncol]; @@ -572,37 +594,39 @@ VOID uline(row, vvp, pvp) VIDEO *vvp; VIDEO *pvp; { #endif return; } - cp1 = &vvp->v_text[0]; /* Compute left match. */ + cp1 = &vvp->v_text[0]; /* Compute left match. */ cp2 = &pvp->v_text[0]; - while (cp1!=&vvp->v_text[ncol] && cp1[0]==cp2[0]) { + while (cp1 != &vvp->v_text[ncol] && cp1[0] == cp2[0]) { ++cp1; ++cp2; } - if (cp1 == &vvp->v_text[ncol]) /* All equal. */ + if (cp1 == &vvp->v_text[ncol]) /* All equal. */ return; nbflag = FALSE; - cp3 = &vvp->v_text[ncol]; /* Compute right match. */ + cp3 = &vvp->v_text[ncol]; /* Compute right match. */ cp4 = &pvp->v_text[ncol]; while (cp3[-1] == cp4[-1]) { --cp3; --cp4; - if (cp3[0] != ' ') /* Note non-blanks in */ - nbflag = TRUE; /* the right match. */ + if (cp3[0] != ' ') /* Note non-blanks in */ + nbflag = TRUE; /* the right match. */ } - cp5 = cp3; /* Is erase good? */ - if (nbflag==FALSE && vvp->v_color==CTEXT) { - while (cp5!=cp1 && cp5[-1]==' ') + cp5 = cp3; /* Is erase good? */ + if (nbflag == FALSE && vvp->v_color == CTEXT) { + while (cp5 != cp1 && cp5[-1] == ' ') --cp5; /* Alcyon hack */ - if ((int)(cp3-cp5) <= tceeol) + if ((int) (cp3 - cp5) <= tceeol) cp5 = cp3; } /* Alcyon hack */ - ttmove(row, (int)(cp1-&vvp->v_text[0])); + ttmove(row, (int) (cp1 - &vvp->v_text[0])); #ifdef STANDOUT_GLITCH if (vvp->v_color != CTEXT && magic_cookie_glitch > 0) { - if(cp1 < &vvp->v_text[magic_cookie_glitch]) cp1 = &vvp->v_text[magic_cookie_glitch]; - if(cp5 > &vvp->v_text[ncol-magic_cookie_glitch]) cp5 = &vvp->v_text[ncol-magic_cookie_glitch]; + if (cp1 < &vvp->v_text[magic_cookie_glitch]) + cp1 = &vvp->v_text[magic_cookie_glitch]; + if (cp5 > &vvp->v_text[ncol - magic_cookie_glitch]) + cp5 = &vvp->v_text[ncol - magic_cookie_glitch]; } else if (magic_cookie_glitch < 0) #endif ttcolor(vvp->v_color); @@ -610,59 +634,62 @@ VOID uline(row, vvp, pvp) VIDEO *vvp; VIDEO *pvp; { ttputc(*cp1++); ++ttcol; } - if (cp5 != cp3) /* Do erase. */ + if (cp5 != cp3) /* Do erase. */ tteeol(); #endif } /* - * Redisplay the mode line for - * the window pointed to by the "wp". - * This is the only routine that has any idea - * of how the modeline is formatted. You can - * change the modeline format by hacking at - * this routine. Called by "update" any time - * there is a dirty window. - * Note that if STANDOUT_GLITCH is defined, first and last - * magic_cookie_glitch characters may never be seen. + * Redisplay the mode line for the window pointed to by the "wp". + * This is the only routine that has any idea of how the modeline is + * formatted. You can change the modeline format by hacking at this + * routine. Called by "update" any time there is a dirty window. Note + * that if STANDOUT_GLITCH is defined, first and last magic_cookie_glitch + * characters may never be seen. */ VOID -modeline(wp) register MGWIN *wp; { - register int n; - register BUFFER *bp; - int mode; - - n = wp->w_toprow+wp->w_ntrows; /* Location. */ - vscreen[n]->v_color = CMODE; /* Mode line color. */ - vscreen[n]->v_flag |= (VFCHG|VFHBAD); /* Recompute, display. */ - vtmove(n, 0); /* Seek to right line. */ +modeline(wp) + MGWIN *wp; +{ + int n; + BUFFER *bp; + int mode; + + n = wp->w_toprow + wp->w_ntrows; /* Location. */ + vscreen[n]->v_color = CMODE; /* Mode line color. */ + vscreen[n]->v_flag |= (VFCHG | VFHBAD); /* Recompute, display. */ + vtmove(n, 0); /* Seek to right line. */ bp = wp->w_bufp; - vtputc('-'); vtputc('-'); - if ((bp->b_flag&BFCHG) != 0) { /* "*" if changed. */ - vtputc('*'); vtputc('*'); + vtputc('-'); + vtputc('-'); + if ((bp->b_flag & BFCHG) != 0) { /* "*" if changed. */ + vtputc('*'); + vtputc('*'); } else { - vtputc('-'); vtputc('-'); + vtputc('-'); + vtputc('-'); } vtputc('-'); - n = 5; + n = 5; n += vtputs("Mg: "); if (bp->b_bname[0] != '\0') n += vtputs(&(bp->b_bname[0])); - while (n < 42) { /* Pad out with blanks */ + while (n < 42) { /* Pad out with blanks */ vtputc(' '); ++n; } vtputc('('); ++n; - for(mode=0;;) { - n += vtputs(bp->b_modes[mode]->p_name); - if(++mode > bp->b_nmodes) break; - vtputc('-'); - ++n; + for (mode = 0;;) { + n += vtputs(bp->b_modes[mode]->p_name); + if (++mode > bp->b_nmodes) + break; + vtputc('-'); + ++n; } vtputc(')'); ++n; - while (n < ncol) { /* Pad out. */ + while (n < ncol) { /* Pad out. */ vtputc('-'); ++n; } @@ -670,8 +697,11 @@ modeline(wp) register MGWIN *wp; { /* * output a string to the mode line, report how long it was. */ -vtputs(s) register char *s; { - register int n = 0; +int +vtputs(s) + char *s; +{ + int n = 0; while (*s != '\0') { vtputc(*s++); @@ -679,36 +709,37 @@ vtputs(s) register char *s; { } return n; } + #ifdef GOSLING /* - * Compute the hash code for - * the line pointed to by the "vp". Recompute - * it if necessary. Also set the approximate redisplay - * cost. The validity of the hash code is marked by - * a flag bit. The cost understand the advantages - * of erase to end of line. Tuned for the VAX - * by Bob McNamara; better than it used to be on + * Compute the hash code for the line pointed to by the "vp". + * Recompute it if necessary. Also set the approximate redisplay + * cost. The validity of the hash code is marked by a flag bit. + * The cost understand the advantages of erase to end of line. + * Tuned for the VAX by Bob McNamara; better than it used to be on * just about any machine. */ VOID -hash(vp) register VIDEO *vp; { - register int i; - register int n; - register char *s; - - if ((vp->v_flag&VFHBAD) != 0) { /* Hash bad. */ - s = &vp->v_text[ncol-1]; - for (i=ncol; i!=0; --i, --s) +hash(vp) + VIDEO *vp; +{ + int i; + int n; + char *s; + + if ((vp->v_flag & VFHBAD) != 0) { /* Hash bad. */ + s = &vp->v_text[ncol - 1]; + for (i = ncol; i != 0; --i, --s) if (*s != ' ') break; - n = ncol-i; /* Erase cheaper? */ + n = ncol - i; /* Erase cheaper? */ if (n > tceeol) n = tceeol; - vp->v_cost = i+n; /* Bytes + blanks. */ - for (n=0; i!=0; --i, --s) - n = (n<<5) + n + *s; - vp->v_hash = n; /* Hash code. */ - vp->v_flag &= ~VFHBAD; /* Flag as all done. */ + vp->v_cost = i + n; /* Bytes + blanks. */ + for (n = 0; i != 0; --i, --s) + n = (n << 5) + n + *s; + vp->v_hash = n; /* Hash code. */ + vp->v_flag &= ~VFHBAD; /* Flag as all done. */ } } @@ -739,77 +770,80 @@ hash(vp) register VIDEO *vp; { * bit better; but it looks ugly. */ VOID -setscores(offs, size) { - register SCORE *sp; - SCORE *sp1; - register int tempcost; - register int bestcost; - register int j; - register int i; - register VIDEO **vp; - VIDEO **pp, **vbase, **pbase; - - vbase = &vscreen[offs-1]; /* By hand CSE's. */ - pbase = &pscreen[offs-1]; - score[0].s_itrace = 0; /* [0, 0] */ +setscores(offs, size) + int offs; + int size; +{ + SCORE *sp; + SCORE *sp1; + int tempcost; + int bestcost; + int j; + int i; + VIDEO **vp, **pp; + VIDEO **vbase, **pbase; + + vbase = &vscreen[offs - 1]; /* By hand CSE's. */ + pbase = &pscreen[offs - 1]; + score[0].s_itrace = 0; /* [0, 0] */ score[0].s_jtrace = 0; - score[0].s_cost = 0; - sp = &score[1]; /* Row 0, inserts. */ + score[0].s_cost = 0; + sp = &score[1]; /* Row 0, inserts. */ tempcost = 0; vp = &vbase[1]; - for (j=1; j<=size; ++j) { + for (j = 1; j <= size; ++j) { sp->s_itrace = 0; - sp->s_jtrace = j-1; + sp->s_jtrace = j - 1; tempcost += tcinsl; tempcost += (*vp)->v_cost; sp->s_cost = tempcost; ++vp; ++sp; } - sp = &score[NROW]; /* Column 0, deletes. */ + sp = &score[NROW]; /* Column 0, deletes. */ tempcost = 0; - for (i=1; i<=size; ++i) { - sp->s_itrace = i-1; + for (i = 1; i <= size; ++i) { + sp->s_itrace = i - 1; sp->s_jtrace = 0; - tempcost += tcdell; + tempcost += tcdell; sp->s_cost = tempcost; sp += NROW; } - sp1 = &score[NROW+1]; /* [1, 1]. */ + sp1 = &score[NROW + 1]; /* [1, 1]. */ pp = &pbase[1]; - for (i=1; i<=size; ++i) { + for (i = 1; i <= size; ++i) { sp = sp1; vp = &vbase[1]; - for (j=1; j<=size; ++j) { - sp->s_itrace = i-1; + for (j = 1; j <= size; ++j) { + sp->s_itrace = i - 1; sp->s_jtrace = j; - bestcost = (sp-NROW)->s_cost; - if (j != size) /* Cd(A[i])=0 @ Dis. */ + bestcost = (sp - NROW)->s_cost; + if (j != size) /* Cd(A[i])=0 @ Dis. */ bestcost += tcdell; - tempcost = (sp-1)->s_cost; + tempcost = (sp - 1)->s_cost; tempcost += (*vp)->v_cost; - if (i != size) /* Ci(B[j])=0 @ Dsj. */ + if (i != size) /* Ci(B[j])=0 @ Dsj. */ tempcost += tcinsl; if (tempcost < bestcost) { sp->s_itrace = i; - sp->s_jtrace = j-1; + sp->s_jtrace = j - 1; bestcost = tempcost; } - tempcost = (sp-NROW-1)->s_cost; + tempcost = (sp - NROW - 1)->s_cost; if ((*pp)->v_color != (*vp)->v_color - || (*pp)->v_hash != (*vp)->v_hash) + || (*pp)->v_hash != (*vp)->v_hash) tempcost += (*vp)->v_cost; if (tempcost < bestcost) { - sp->s_itrace = i-1; - sp->s_jtrace = j-1; + sp->s_itrace = i - 1; + sp->s_jtrace = j - 1; bestcost = tempcost; } sp->s_cost = bestcost; - ++sp; /* Next column. */ + ++sp; /* Next column. */ ++vp; } ++pp; - sp1 += NROW; /* Next row. */ + sp1 += NROW; /* Next row. */ } } @@ -825,27 +859,33 @@ setscores(offs, size) { * which is acceptable because this routine is much less compute * intensive then the code that builds the score matrix! */ -VOID traceback(offs, size, i, j) { - register int itrace; - register int jtrace; - register int k; - register int ninsl; - register int ndraw; - register int ndell; - - if (i==0 && j==0) /* End of update. */ +VOID +traceback(offs, size, i, j) + int offs; + int size; + int i; + int j; +{ + int itrace; + int jtrace; + int k; + int ninsl; + int ndraw; + int ndell; + + if (i == 0 && j == 0) /* End of update. */ return; - itrace = score[(NROW*i) + j].s_itrace; - jtrace = score[(NROW*i) + j].s_jtrace; - if (itrace == i) { /* [i, j-1] */ - ninsl = 0; /* Collect inserts. */ + itrace = score[(NROW * i) + j].s_itrace; + jtrace = score[(NROW * i) + j].s_jtrace; + if (itrace == i) { /* [i, j-1] */ + ninsl = 0; /* Collect inserts. */ if (i != size) ninsl = 1; ndraw = 1; - while (itrace!=0 || jtrace!=0) { - if (score[(NROW*itrace) + jtrace].s_itrace != itrace) + while (itrace != 0 || jtrace != 0) { + if (score[(NROW * itrace) + jtrace].s_itrace != itrace) break; - jtrace = score[(NROW*itrace) + jtrace].s_jtrace; + jtrace = score[(NROW * itrace) + jtrace].s_jtrace; if (i != size) ++ninsl; ++ndraw; @@ -853,34 +893,34 @@ VOID traceback(offs, size, i, j) { traceback(offs, size, itrace, jtrace); if (ninsl != 0) { ttcolor(CTEXT); - ttinsl(offs+j-ninsl, offs+size-1, ninsl); + ttinsl(offs + j - ninsl, offs + size - 1, ninsl); } - do { /* B[j], A[j] blank. */ - k = offs+j-ndraw; + do { /* B[j], A[j] blank. */ + k = offs + j - ndraw; uline(k, vscreen[k], &blanks); } while (--ndraw); return; } - if (jtrace == j) { /* [i-1, j] */ - ndell = 0; /* Collect deletes. */ + if (jtrace == j) { /* [i-1, j] */ + ndell = 0; /* Collect deletes. */ if (j != size) ndell = 1; - while (itrace!=0 || jtrace!=0) { - if (score[(NROW*itrace) + jtrace].s_jtrace != jtrace) + while (itrace != 0 || jtrace != 0) { + if (score[(NROW * itrace) + jtrace].s_jtrace != jtrace) break; - itrace = score[(NROW*itrace) + jtrace].s_itrace; + itrace = score[(NROW * itrace) + jtrace].s_itrace; if (j != size) ++ndell; } if (ndell != 0) { ttcolor(CTEXT); - ttdell(offs+i-ndell, offs+size-1, ndell); + ttdell(offs + i - ndell, offs + size - 1, ndell); } traceback(offs, size, itrace, jtrace); return; } traceback(offs, size, itrace, jtrace); - k = offs+j-1; - uline(k, vscreen[k], pscreen[offs+i-1]); + k = offs + j - 1; + uline(k, vscreen[k], pscreen[offs + i - 1]); } #endif diff --git a/usr.bin/mg/echo.c b/usr.bin/mg/echo.c index 3663cda638c..775be72fa7e 100644 --- a/usr.bin/mg/echo.c +++ b/usr.bin/mg/echo.c @@ -6,46 +6,39 @@ * of the display screen. Used by the entire * known universe. */ -/* - * The varargs lint directive comments are 0 an attempt to get lint to shup - * up about CORRECT usage of varargs.h. It won't. - */ #include "def.h" #include "key.h" -#ifdef LOCAL_VARARGS -#include "varargs.h" +#ifdef __STDC__ +#include <stdarg.h> #else #include <varargs.h> #endif #ifndef NO_MACRO -# include "macro.h" +#include "macro.h" #endif -static int veread(); -VOID ewprintf(); -static VOID eformat(); -static VOID eputi(); -static VOID eputl(); -static VOID eputs(); -static VOID eputc(); -static int complt(); -static int complt_list(); -LIST * make_file_list(); -LIST * copy_list(); -char * strrchr(); -extern LIST * complete_function_list(); - -int epresf = FALSE; /* Stuff in echo line flag. */ +static VOID eformat __P((const char *, va_list)); +static int veread __P((const char *, char *buf, int, int, va_list)); +static VOID eputi __P((int, int)); +static VOID eputl __P((long, int)); +static VOID eputs __P((char *)); +static VOID eputc __P((char)); +static int complt __P((int, int, char *, int)); +static int complt_list __P((int, int, char *, int)); +static LIST *copy_list __P((LIST *)); +static VOID free_file_list __P((LIST *)); -extern int tthue; +int epresf = FALSE; /* Stuff in echo line flag. */ /* * Erase the echo line. */ VOID -eerase() { +eerase() +{ + ttcolor(CTEXT); - ttmove(nrow-1, 0); + ttmove(nrow - 1, 0); tteeol(); ttflush(); epresf = FALSE; @@ -58,60 +51,75 @@ eerase() { * for "no" and TRUE for "yes". No formatting * services are available. No newline required. */ -eyorn(sp) char *sp; { - register int s; +int +eyorn(sp) + char *sp; +{ + int s; #ifndef NO_MACRO - if(inmacro) return TRUE; + if (inmacro) + return TRUE; #endif ewprintf("%s? (y or n) ", sp); for (;;) { s = getkey(FALSE); - if (s == 'y' || s == 'Y') return TRUE; - if (s == 'n' || s == 'N') return FALSE; - if (s == CCHR('G')) return ctrlg(FFRAND, 1); + if (s == 'y' || s == 'Y') + return TRUE; + if (s == 'n' || s == 'N') + return FALSE; + if (s == CCHR('G')) + return ctrlg(FFRAND, 1); ewprintf("Please answer y or n. %s? (y or n) ", sp); } - /*NOTREACHED*/ + /* NOTREACHED */ } /* * Like eyorn, but for more important question. User must type either all of * "yes" or "no", and the trainling newline. */ -eyesno(sp) char *sp; { - register int s; - char buf[64]; +int +eyesno(sp) + char *sp; +{ + int s; + char buf[64]; #ifndef NO_MACRO - if(inmacro) return TRUE; + if (inmacro) + return TRUE; #endif s = ereply("%s? (yes or no) ", buf, sizeof(buf), sp); for (;;) { - if (s == ABORT) return ABORT; + if (s == ABORT) + return ABORT; if (s != FALSE) { #ifndef NO_MACRO if (macrodef) { - LINE *lp = maclcur; + LINE *lp = maclcur; - maclcur = lp->l_bp; - maclcur->l_fp = lp->l_fp; - free((char *)lp); + maclcur = lp->l_bp; + maclcur->l_fp = lp->l_fp; + free((char *) lp); } #endif if ((buf[0] == 'y' || buf[0] == 'Y') - && (buf[1] == 'e' || buf[1] == 'E') - && (buf[2] == 's' || buf[2] == 'S') - && (buf[3] == '\0')) return TRUE; + && (buf[1] == 'e' || buf[1] == 'E') + && (buf[2] == 's' || buf[2] == 'S') + && (buf[3] == '\0')) + return TRUE; if ((buf[0] == 'n' || buf[0] == 'N') - && (buf[1] == 'o' || buf[0] == 'O') - && (buf[2] == '\0')) return FALSE; + && (buf[1] == 'o' || buf[0] == 'O') + && (buf[2] == '\0')) + return FALSE; } s = ereply("Please answer yes or no. %s? (yes or no) ", buf, sizeof(buf), sp); } - /*NOTREACHED*/ + /* NOTREACHED */ } + /* * Write out a prompt, and read back a * reply. The prompt is now written out with full "ewprintf" @@ -119,21 +127,30 @@ eyesno(sp) char *sp; { * place. This is always a new message, there is no auto * completion, and the return is echoed as such. */ -/*VARARGS 0*/ +/* VARARGS */ +int +#ifdef __STDC__ +ereply(const char *fmt, char *buf, int nbuf, ...) +#else ereply(va_alist) -va_dcl + va_dcl +#endif { - va_list pvar; - register char *fp, *buf; - register int nbuf; - register int i; - - va_start(pvar); - fp = va_arg(pvar, char *); - buf = va_arg(pvar, char *); - nbuf = va_arg(pvar, int); - i = veread(fp, buf, nbuf, EFNEW|EFCR, &pvar); - va_end(pvar); + va_list ap; + int i; +#ifdef __STDC__ + va_start(ap, nbuf); +#else + char *fmt, *buf; + int nbuf; + + va_start(ap); + fmt = va_arg(ap, char *); + buf = va_arg(ap, char *); + nbuf = va_arg(ap, int); +#endif + i = veread(fmt, buf, nbuf, EFNEW | EFCR, ap); + va_end(ap); return i; } @@ -146,40 +163,62 @@ va_dcl * new prompt), an EFFUNC (autocomplete), or EFCR (echo * the carriage return as CR). */ -/* VARARGS 0 */ +/* VARARGS */ +int +#ifdef __STDC__ +eread(const char *fmt, char *buf, int nbuf, int flag, ...) +#else eread(va_alist) -va_dcl + char *fmt; + char *buf; + int nbuf; + int flag; + va_dcl +#endif { - va_list pvar; - char *fp, *buf; - int nbuf, flag, i; - va_start(pvar); - fp = va_arg(pvar, char *); - buf = va_arg(pvar, char *); - nbuf = va_arg(pvar, int); - flag = va_arg(pvar, int); - i = veread(fp, buf, nbuf, flag, &pvar); - va_end(pvar); + int i; + va_list ap; +#ifdef __STDC__ + va_start(ap, flag); +#else + char *fmt, *buf; + int nbuf; + + va_start(ap); + fmt = va_arg(ap, char *); + buf = va_arg(ap, char *); + nbuf = va_arg(ap, int); + flag = va_arg(ap, int); +#endif + i = veread(fmt, buf, nbuf, flag, ap); + va_end(ap); return i; } -static veread(fp, buf, nbuf, flag, ap) char *fp; char *buf; va_list *ap; { - register int cpos; - register int i; - register int c; +static int +veread(fp, buf, nbuf, flag, ap) + const char *fp; + char *buf; + int nbuf; + int flag; + va_list ap; +{ + int cpos; + int i; + int c; #ifndef NO_MACRO - if(inmacro) { - bcopy(maclcur->l_text, buf, maclcur->l_used); - buf[maclcur->l_used] = '\0'; - maclcur = maclcur->l_fp; - return TRUE; + if (inmacro) { + bcopy(maclcur->l_text, buf, maclcur->l_used); + buf[maclcur->l_used] = '\0'; + maclcur = maclcur->l_fp; + return TRUE; } #endif cpos = 0; - if ((flag&EFNEW)!=0 || ttrow!=nrow-1) { + if ((flag & EFNEW) != 0 || ttrow != nrow - 1) { ttcolor(CTEXT); - ttmove(nrow-1, 0); + ttmove(nrow - 1, 0); epresf = TRUE; } else eputc(' '); @@ -188,50 +227,52 @@ static veread(fp, buf, nbuf, flag, ap) char *fp; char *buf; va_list *ap; { ttflush(); for (;;) { c = getkey(FALSE); - if ((flag&EFAUTO) != 0 && (c == ' ' || c == CCHR('I'))) { + if ((flag & EFAUTO) != 0 && (c == ' ' || c == CCHR('I'))) { cpos += complt(flag, c, buf, cpos); continue; } - if ((flag&EFAUTO) != 0 && c == '?') { + if ((flag & EFAUTO) != 0 && c == '?') { complt_list(flag, c, buf, cpos); continue; } switch (c) { - case CCHR('J'): - c = CCHR('M'); /* and continue */ - case CCHR('M'): /* Return, done. */ - if ((flag&EFFUNC) != 0) { + case CCHR('J'): + c = CCHR('M'); /* and continue */ + case CCHR('M'):/* Return, done. */ + if ((flag & EFFUNC) != 0) { if ((i = complt(flag, c, buf, cpos)) == 0) continue; - if (i > 0) cpos += i; + if (i > 0) + cpos += i; } buf[cpos] = '\0'; - if ((flag&EFCR) != 0) { + if ((flag & EFCR) != 0) { ttputc(CCHR('M')); ttflush(); } #ifndef NO_MACRO - if(macrodef) { - LINE *lp; - - if((lp = lalloc(cpos)) == NULL) return FALSE; - lp->l_fp = maclcur->l_fp; - maclcur->l_fp = lp; - lp->l_bp = maclcur; - maclcur = lp; - bcopy(buf, lp->l_text, cpos); + if (macrodef) { + LINE *lp; + + if ((lp = lalloc(cpos)) == NULL) + return FALSE; + lp->l_fp = maclcur->l_fp; + maclcur->l_fp = lp; + lp->l_bp = maclcur; + maclcur = lp; + bcopy(buf, lp->l_text, cpos); } #endif goto done; - case CCHR('G'): /* Bell, abort. */ + case CCHR('G'): /* Bell, abort. */ eputc(CCHR('G')); (VOID) ctrlg(FFRAND, 0); ttflush(); return ABORT; - case CCHR('H'): - case CCHR('?'): /* Rubout, erase. */ + case CCHR('H'): + case CCHR('?'): /* Rubout, erase. */ if (cpos != 0) { ttputc('\b'); ttputc(' '); @@ -247,8 +288,8 @@ static veread(fp, buf, nbuf, flag, ap) char *fp; char *buf; va_list *ap; { } break; - case CCHR('X'): /* C-X */ - case CCHR('U'): /* C-U, kill line. */ + case CCHR('X'): /* C-X */ + case CCHR('U'): /* C-U, kill line. */ while (cpos != 0) { ttputc('\b'); ttputc(' '); @@ -264,8 +305,8 @@ static veread(fp, buf, nbuf, flag, ap) char *fp; char *buf; va_list *ap; { ttflush(); break; - case CCHR('W'): /* C-W, kill to beginning of */ - /* previous word */ + case CCHR('W'): /* C-W, kill to beginning of */ + /* previous word */ /* back up to first word character or beginning */ while ((cpos > 0) && !ISWORD(buf[cpos - 1])) { ttputc('\b'); @@ -294,11 +335,11 @@ static veread(fp, buf, nbuf, flag, ap) char *fp; char *buf; va_list *ap; { ttflush(); break; - case CCHR('\\'): - case CCHR('Q'): /* C-Q, quote next */ - c = getkey(FALSE); /* and continue */ - default: /* All the rest. */ - if (cpos < nbuf-1) { + case CCHR('\\'): + case CCHR('Q'): /* C-Q, quote next */ + c = getkey(FALSE); /* and continue */ + default: /* All the rest. */ + if (cpos < nbuf - 1) { buf[cpos++] = (char) c; eputc((char) c); ttflush(); @@ -311,254 +352,270 @@ done: return buf[0] != '\0'; /* * do completion on a list of objects. */ -static int complt(flags, c, buf, cpos) -register char *buf; -register int cpos; +static int +complt(flags, c, buf, cpos) + int flags; + int c; + char *buf; + int cpos; { - register LIST *lh, *lh2; - LIST *wholelist = NULL; - int i, nxtra; - int nhits, bxtra; - int wflag = FALSE; - int msglen, nshown; - char *msg; - - if ((flags&EFFUNC) != 0) { - buf[cpos] = '\0'; - i = complete_function(buf, c); - if(i>0) { - eputs(&buf[cpos]); - ttflush(); - return i; - } - switch(i) { + LIST *lh, *lh2; + LIST *wholelist = NULL; + int i, nxtra; + int nhits, bxtra; + int wflag = FALSE; + int msglen, nshown; + char *msg; + + if ((flags & EFFUNC) != 0) { + buf[cpos] = '\0'; + i = complete_function(buf, c); + if (i > 0) { + eputs(&buf[cpos]); + ttflush(); + return i; + } + switch (i) { case -3: - msg = " [Ambiguous]"; - break; + msg = " [Ambiguous]"; + break; case -2: - i=0; - msg = " [No match]"; - break; + i = 0; + msg = " [No match]"; + break; case -1: case 0: - return i; + return i; default: - msg = " [Internal error]"; - break; - } + msg = " [Internal error]"; + break; + } } else { - if ((flags&EFBUF) != 0) lh = &(bheadp->b_list); - else if ((flags&EFFILE) != 0) { - buf[cpos] = '\0'; - wholelist = lh = make_file_list(buf,0); - } - else panic("broken complt call: flags"); + if ((flags & EFBUF) != 0) + lh = &(bheadp->b_list); + else if ((flags & EFFILE) != 0) { + buf[cpos] = '\0'; + wholelist = lh = make_file_list(buf, 0); + } else + panic("broken complt call: flags"); - if (c == ' ') wflag = TRUE; - else if (c != '\t' && c != CCHR('M')) panic("broken complt call: c"); + if (c == ' ') + wflag = TRUE; + else if (c != '\t' && c != CCHR('M')) + panic("broken complt call: c"); - nhits = 0; - nxtra = HUGE; + nhits = 0; + nxtra = HUGE; - while (lh != NULL) { - for (i=0; i<cpos; ++i) { - if (buf[i] != lh->l_name[i]) - break; - } - if (i == cpos) { - if (nhits == 0) - lh2 = lh; - ++nhits; - if (lh->l_name[i] == '\0') nxtra = -1; - else { - bxtra = getxtra(lh, lh2, cpos, wflag); - if (bxtra < nxtra) nxtra = bxtra; - lh2 = lh; + while (lh != NULL) { + for (i = 0; i < cpos; ++i) { + if (buf[i] != lh->l_name[i]) + break; + } + if (i == cpos) { + if (nhits == 0) + lh2 = lh; + ++nhits; + if (lh->l_name[i] == '\0') + nxtra = -1; + else { + bxtra = getxtra(lh, lh2, cpos, wflag); + if (bxtra < nxtra) + nxtra = bxtra; + lh2 = lh; + } } + lh = lh->l_next; } - lh = lh->l_next; - } - if (nhits == 0) - msg = " [No match]"; - else if (nhits > 1 && nxtra == 0) - msg = " [Ambiguous]"; - else { /* Got a match, do it to it */ - /* - * Being lazy - ought to check length, but all things - * autocompleted have known types/lengths. - */ - if (nxtra < 0 && nhits > 1 && c == ' ') nxtra = 1; - for (i = 0; i < nxtra; ++i) { - buf[cpos] = lh2->l_name[cpos]; - eputc(buf[cpos++]); + if (nhits == 0) + msg = " [No match]"; + else if (nhits > 1 && nxtra == 0) + msg = " [Ambiguous]"; + else { /* Got a match, do it to it */ + /* + * Being lazy - ought to check length, but all things + * autocompleted have known types/lengths. + */ + if (nxtra < 0 && nhits > 1 && c == ' ') + nxtra = 1; + for (i = 0; i < nxtra; ++i) { + buf[cpos] = lh2->l_name[cpos]; + eputc(buf[cpos++]); + } + ttflush(); + free_file_list(wholelist); + if (nxtra < 0 && c != CCHR('M')) + return 0; + return nxtra; } - ttflush(); - free_file_list(wholelist); - if (nxtra < 0 && c != CCHR('M')) return 0; - return nxtra; - } } - /* wholelist is null if we are doing buffers. want to free - * lists that were created for us, but not the buffer list! */ + /* + * wholelist is null if we are doing buffers. want to free lists + * that were created for us, but not the buffer list! + */ free_file_list(wholelist); /* Set up backspaces, etc., being mindful of echo line limit */ msglen = strlen(msg); nshown = (ttcol + msglen + 2 > ncol) ? - ncol - ttcol - 2 : msglen; + ncol - ttcol - 2 : msglen; eputs(msg); - ttcol -= (i = nshown); /* update ttcol! */ - while (i--) /* move back before msg */ + ttcol -= (i = nshown); /* update ttcol! */ + while (i--) /* move back before msg */ ttputc('\b'); - ttflush(); /* display to user */ + ttflush(); /* display to user */ i = nshown; - while (i--) /* blank out on next flush */ + while (i--) /* blank out on next flush */ eputc(' '); - ttcol -= (i = nshown); /* update ttcol on BS's */ + ttcol -= (i = nshown); /* update ttcol on BS's */ while (i--) - ttputc('\b'); /* update ttcol again! */ + ttputc('\b'); /* update ttcol again! */ return 0; } /* * do completion on a list of objects, listing instead of completing */ -static int complt_list(flags, c, buf, cpos) -register char *buf; -register int cpos; +static int +complt_list(flags, c, buf, cpos) + int flags; + int c; + char *buf; + int cpos; { - register LIST *lh, *lh2, *lh3; - LIST *wholelist = NULL; - int i,maxwidth,width; - int preflen = 0; - BUFFER *bp; - static VOID findbind(); - int oldrow = ttrow; - int oldcol = ttcol; - int oldhue = tthue; - char linebuf[NCOL+1]; - char *cp; + LIST *lh, *lh2, *lh3; + LIST *wholelist = NULL; + int i, maxwidth, width; + int preflen = 0; + BUFFER *bp; + int oldrow = ttrow; + int oldcol = ttcol; + int oldhue = tthue; + char linebuf[NCOL + 1]; + char *cp; ttflush(); /* the results are put into a help buffer */ - bp = bfind("*help*", TRUE); - if(bclear(bp) == FALSE) return FALSE; + if (bclear(bp) == FALSE) + return FALSE; - { /* this {} present for historical reasons */ + { /* this {} present for historical reasons */ -/* - * first get the list of objects. This list may contain only the - * ones that complete what has been typed, or may be the whole list - * of all objects of this type. They are filtered later in any case. - * set wholelist if the list has been cons'ed up just for us, so we - * can free it later. We have to copy the buffer list for this - * function even though we didn't for complt. The sorting code - * does destructive changes to the list, which we don't want to - * happen to the main buffer list! - */ - if ((flags&EFBUF) != 0) - wholelist = lh = copy_list (&(bheadp->b_list)); - else if ((flags&EFFUNC) != 0) { - buf[cpos] = '\0'; - wholelist = lh = complete_function_list(buf, c); - } - else if ((flags&EFFILE) != 0) { - buf[cpos] = '\0'; - wholelist = lh = make_file_list(buf,1); /* - * we don't want to display stuff up to the / for file names - * preflen is the list of a prefix of what the user typed - * that should not be displayed. + * first get the list of objects. This list may contain only + * the ones that complete what has been typed, or may be the + * whole list of all objects of this type. They are filtered + * later in any case. Set wholelist if the list has been + * cons'ed up just for us, so we can free it later. We have + * to copy the buffer list for this function even though we + * didn't for complt. The sorting code does destructive + * changes to the list, which we don't want to happen to the + * main buffer list! */ - cp = strrchr(buf,'/'); - if (cp) - preflen = cp - buf + 1; - } - else panic("broken complt call: flags"); - - -/* sort the list, since users expect to see it in alphabetic order */ - - lh2 = lh; - while (lh2) { - lh3 = lh2->l_next; - while (lh3) { - if (strcmp(lh2->l_name, lh3->l_name) > 0) { - cp = lh2->l_name; - lh2->l_name = lh3->l_name; - lh3->l_name = cp; - } - lh3 = lh3->l_next; - } - lh2 = lh2->l_next; - } + if ((flags & EFBUF) != 0) + wholelist = lh = copy_list(&(bheadp->b_list)); + else if ((flags & EFFUNC) != 0) { + buf[cpos] = '\0'; + wholelist = lh = complete_function_list(buf, c); + } else if ((flags & EFFILE) != 0) { + buf[cpos] = '\0'; + wholelist = lh = make_file_list(buf, 1); + /* + * We don't want to display stuff up to the / for file + * names preflen is the list of a prefix of what the + * user typed that should not be displayed. + */ + cp = strrchr(buf, '/'); + if (cp) + preflen = cp - buf + 1; + } else + panic("broken complt call: flags"); -/* - * first find max width of object to be displayed, so we can - * put several on a line - */ - maxwidth = 0; - lh2 = lh; - while (lh2 != NULL) { - for (i=0; i<cpos; ++i) { - if (buf[i] != lh2->l_name[i]) - break; - } - if (i == cpos) { - width = strlen(lh2->l_name); - if (width > maxwidth) - maxwidth = width; + /* + * Sort the list, since users expect to see it in alphabetic + * order. + */ + lh2 = lh; + while (lh2) { + lh3 = lh2->l_next; + while (lh3) { + if (strcmp(lh2->l_name, lh3->l_name) > 0) { + cp = lh2->l_name; + lh2->l_name = lh3->l_name; + lh3->l_name = cp; + } + lh3 = lh3->l_next; + } + lh2 = lh2->l_next; } - lh2 = lh2->l_next; - } - maxwidth += 1 - preflen; -/* - * now do the display. objects are written into linebuf until it - * fills, and then put into the help buffer. - */ - cp = linebuf; - width = 0; - lh2 = lh; - while (lh2 != NULL) { - for (i=0; i<cpos; ++i) { - if (buf[i] != lh2->l_name[i]) - break; + /* + * First find max width of object to be displayed, so we can + * put several on a line. + */ + maxwidth = 0; + lh2 = lh; + while (lh2 != NULL) { + for (i = 0; i < cpos; ++i) { + if (buf[i] != lh2->l_name[i]) + break; + } + if (i == cpos) { + width = strlen(lh2->l_name); + if (width > maxwidth) + maxwidth = width; + } + lh2 = lh2->l_next; } - if (i == cpos) { - if ((width + maxwidth) > ncol) { - *cp = 0; - addline(bp,linebuf); - cp = linebuf; - width = 0; + maxwidth += 1 - preflen; + + /* + * Now do the display. objects are written into linebuf until + * it fills, and then put into the help buffer. + */ + cp = linebuf; + width = 0; + lh2 = lh; + while (lh2 != NULL) { + for (i = 0; i < cpos; ++i) { + if (buf[i] != lh2->l_name[i]) + break; } - strcpy(cp,lh2->l_name+preflen); - i = strlen(lh2->l_name+preflen); - cp += i; - for (; i < maxwidth; i++) - *cp++ = ' '; - width += maxwidth; + if (i == cpos) { + if ((width + maxwidth) > ncol) { + *cp = 0; + addline(bp, linebuf); + cp = linebuf; + width = 0; + } + strcpy(cp, lh2->l_name + preflen); + i = strlen(lh2->l_name + preflen); + cp += i; + for (; i < maxwidth; i++) + *cp++ = ' '; + width += maxwidth; + } + lh2 = lh2->l_next; + } + if (width > 0) { + *cp = 0; + addline(bp, linebuf); } - lh2 = lh2->l_next; - } - if (width > 0) { - *cp = 0; - addline(bp,linebuf); - } - } - /* - * note that we free lists only if they are put in wholelist - * lists that were built just for us should be freed. However - * when we use the buffer list, obviously we don't want it - * freed. + } + /* + * Note that we free lists only if they are put in wholelist lists + * that were built just for us should be freed. However when we use + * the buffer list, obviously we don't want it freed. */ free_file_list(wholelist); - popbuftop(bp); /* split the screen and put up the help buffer */ - update(); /* needed to make the new stuff actually appear */ - ttmove(oldrow,oldcol); /* update leaves cursor in arbitrary place */ - ttcolor(oldhue); /* with arbitrary color */ + popbuftop(bp); /* split the screen and put up the help + * buffer */ + update(); /* needed to make the new stuff actually + * appear */ + ttmove(oldrow, oldcol); /* update leaves cursor in arbitrary place */ + ttcolor(oldhue); /* with arbitrary color */ ttflush(); return 0; } @@ -569,16 +626,24 @@ register int cpos; * Return the longest block of characters that can be * autocompleted at this point. Sometimes the two * symbols are the same, but this is normal. - */ -getxtra(lp1, lp2, cpos, wflag) register LIST *lp1, *lp2; register int wflag; { - register int i; + */ +int +getxtra(lp1, lp2, cpos, wflag) + LIST *lp1, *lp2; + int cpos; + int wflag; +{ + int i; i = cpos; for (;;) { - if (lp1->l_name[i] != lp2->l_name[i]) break; - if (lp1->l_name[i] == '\0') break; + if (lp1->l_name[i] != lp2->l_name[i]) + break; + if (lp1->l_name[i] == '\0') + break; ++i; - if (wflag && !ISWORD(lp1->l_name[i-1])) break; + if (wflag && !ISWORD(lp1->l_name[i - 1])) + break; } return (i - cpos); } @@ -590,23 +655,34 @@ getxtra(lp1, lp2, cpos, wflag) register LIST *lp1, *lp2; register int wflag; { * echo line. The formatting is done by a call * to the standard formatting routine. */ -/*VARARGS 0 */ +/* VARARGS */ VOID +#ifdef __STDC__ +ewprintf(const char *fmt, ...) +#else ewprintf(va_alist) -va_dcl + va_dcl +#endif { - va_list pvar; - register char *fp; + va_list ap; +#ifndef __STDC__ + char *fmt; +#endif #ifndef NO_MACRO - if(inmacro) return; + if (inmacro) + return; +#endif +#ifdef __STDC__ + va_start(ap, fmt); +#else + va_start(ap); + fmt = va_arg(ap, char *); #endif - va_start(pvar); - fp = va_arg(pvar, char *); ttcolor(CTEXT); - ttmove(nrow-1, 0); - eformat(fp, &pvar); - va_end(pvar); + ttmove(nrow - 1, 0); + eformat(fmt, ap); + va_end(ap); tteeol(); ttflush(); epresf = TRUE; @@ -623,13 +699,12 @@ va_dcl */ static VOID eformat(fp, ap) -register char *fp; -register va_list *ap; + const char *fp; + va_list ap; { - register int c; - char kname[NKNAME]; - char *keyname(); - char *cp; + int c; + char kname[NKNAME]; + char *cp; while ((c = *fp++) != '\0') { if (c != '%') @@ -638,37 +713,37 @@ register va_list *ap; c = *fp++; switch (c) { case 'c': - (VOID) keyname(kname, va_arg(*ap, int)); + (VOID) keyname(kname, va_arg(ap, int)); eputs(kname); break; case 'k': cp = kname; - for(c=0; c < key.k_count; c++) { - cp = keyname(cp, key.k_chars[c]); - *cp++ = ' '; + for (c = 0; c < key.k_count; c++) { + cp = keyname(cp, key.k_chars[c]); + *cp++ = ' '; } *--cp = '\0'; eputs(kname); break; case 'd': - eputi(va_arg(*ap, int), 10); + eputi(va_arg(ap, int), 10); break; case 'o': - eputi(va_arg(*ap, int), 8); + eputi(va_arg(ap, int), 8); break; case 's': - eputs(va_arg(*ap, char *)); + eputs(va_arg(ap, char *)); break; - case 'l':/* explicit longword */ + case 'l': /* explicit longword */ c = *fp++; - switch(c) { + switch (c) { case 'd': - eputl((long)va_arg(*ap, long), 10); + eputl((long) va_arg(ap, long), 10); break; default: eputc(c); @@ -688,18 +763,18 @@ register va_list *ap; */ static VOID eputi(i, r) -register int i; -register int r; + int i; + int r; { - register int q; + int q; - if(i<0) { - eputc('-'); - i = -i; + if (i < 0) { + eputc('-'); + i = -i; } - if ((q=i/r) != 0) + if ((q = i / r) != 0) eputi(q, r); - eputc(i%r+'0'); + eputc(i % r + '0'); } /* @@ -707,18 +782,18 @@ register int r; */ static VOID eputl(l, r) -register long l; -register int r; + long l; + int r; { - register long q; + long q; - if(l < 0) { - eputc('-'); - l = -l; + if (l < 0) { + eputc('-'); + l = -l; } - if ((q=l/r) != 0) + if ((q = l / r) != 0) eputl(q, r); - eputc((int)(l%r)+'0'); + eputc((int) (l % r) + '0'); } /* @@ -726,9 +801,9 @@ register int r; */ static VOID eputs(s) -register char *s; + char *s; { - register int c; + int c; while ((c = *s++) != '\0') eputc(c); @@ -741,9 +816,10 @@ register char *s; */ static VOID eputc(c) -register char c; + char c; { - if (ttcol+2 < ncol) { + + if (ttcol + 2 < ncol) { if (ISCTRL(c)) { eputc('^'); c = CCHR(c); @@ -753,29 +829,32 @@ register char c; } } +static VOID free_file_list(lp) - LIST *lp; + LIST *lp; { -LIST *next; -while (lp) { - next = lp->l_next; - free(lp); - lp = next; -} + LIST *next; + + while (lp) { + next = lp->l_next; + free(lp); + lp = next; + } } -LIST *copy_list(lp) - LIST *lp; +static LIST * +copy_list(lp) + LIST *lp; { -LIST *current,*last; - -last = NULL; -while(lp) { - current = (LIST *)malloc(sizeof(LIST)); - current->l_next = last; - current->l_name = lp->l_name; - last = (LIST *)current; - lp = lp->l_next; -} -return(last); + LIST *current, *last; + + last = NULL; + while (lp) { + current = (LIST *) malloc(sizeof(LIST)); + current->l_next = last; + current->l_name = lp->l_name; + last = (LIST *) current; + lp = lp->l_next; + } + return (last); } diff --git a/usr.bin/mg/extend.c b/usr.bin/mg/extend.c index f9f0ba95061..774dbbfc06b 100644 --- a/usr.bin/mg/extend.c +++ b/usr.bin/mg/extend.c @@ -1,5 +1,5 @@ /* - * Extended (M-X) commands, rebinding, and + * Extended (M-X) commands, rebinding, and * startup file processing. */ #include "def.h" @@ -13,46 +13,57 @@ #include "key.h" #ifndef NO_STARTUP #ifndef BINDKEY -#define BINDKEY /* bindkey is used by FKEYS startup code */ +#define BINDKEY /* bindkey is used by FKEYS startup code */ #endif #endif #endif -extern int rescan(); +static KEYMAP *realocmap __P((KEYMAP *)); +static VOID fixmap __P((KEYMAP *, KEYMAP*, KEYMAP*)); +static char *skipwhite __P((char *)); +static char *parsetoken __P((char *)); +int load __P((char *)); +int excline __P((char *)); /* insert a string, mainly for use from macros (created by selfinsert) */ -/*ARGSUSED*/ +/* ARGSUSED */ +int insert(f, n) -int f, n; + int f, n; { - register char *cp; - char buf[128]; + char *cp; + char buf[128]; #ifndef NO_MACRO - register int count; - int c; - - if(inmacro) { - while(--n >= 0) { - for(count = 0; count < maclcur->l_used; count++) { - if((((c=maclcur->l_text[count]) == '\n') ? lnewline() - : linsert(1, c)) != TRUE) return FALSE; - } + int count; + int c; + + if (inmacro) { + while (--n >= 0) { + for (count = 0; count < maclcur->l_used; count++) { + if ((((c = maclcur->l_text[count]) == '\n') + ? lnewline() : linsert(1, c)) != TRUE) + return FALSE; + } + } + maclcur = maclcur->l_fp; + return TRUE; } - maclcur = maclcur->l_fp; - return TRUE; - } - if(n==1) thisflag |= CFINS; /* CFINS means selfinsert can tack on end */ + if (n == 1) + thisflag |= CFINS; /* CFINS means selfinsert can tack on + * end */ #endif - if(eread("Insert: ", buf, sizeof(buf), EFNEW) == FALSE) return FALSE; - while(--n >= 0) { - cp = buf; - while(*cp) { - if(((*cp == '\n') ? lnewline() : linsert(1, *cp)) != TRUE) + if (eread("Insert: ", buf, sizeof(buf), EFNEW) == FALSE) return FALSE; - cp++; + while (--n >= 0) { + cp = buf; + while (*cp) { + if (((*cp == '\n') ? lnewline() : linsert(1, *cp)) + != TRUE) + return FALSE; + cp++; + } } - } - return TRUE; + return TRUE; } /* @@ -67,273 +78,301 @@ int f, n; * don't have them. Care is taken so running out of memory will leave * the keymap in a usable state. */ -static int remap(curmap, c, funct, pref_map) -register KEYMAP *curmap;/* pointer to the map being changed */ -int c; /* character being changed */ -PF funct; /* function being changed to */ -KEYMAP *pref_map; /* if funct==prefix, map to bind to or NULL for new */ +static int +remap(curmap, c, funct, pref_map) + KEYMAP *curmap; /* pointer to the map being changed */ + int c; /* character being changed */ + PF funct; /* function being changed to */ + KEYMAP *pref_map; /* if funct==prefix, map to bind to or + NULL for new */ /* extern MAP_ELEMENT *ele; must be set before calling */ { - register int i; - int n1, n2, nold; - KEYMAP *mp; - PF *pfp; - MAP_ELEMENT *mep; - static KEYMAP *realocmap(); - - if(ele >= &curmap->map_element[curmap->map_num] || c < ele->k_base) { - if(ele > &curmap->map_element[0] && (funct!=prefix || - (ele-1)->k_prefmap==NULL)) { - n1 = c - (ele-1)->k_num; - } else n1 = HUGE; - if(ele < &curmap->map_element[curmap->map_num] && (funct!=prefix || - ele->k_prefmap==NULL)) { - n2 = ele->k_base - c; - } else n2 = HUGE; - if(n1 <= MAPELEDEF && n1 <= n2) { - ele--; - if((pfp = (PF *)malloc((unsigned)(c - ele->k_base+1) - * sizeof(PF))) == NULL) { - ewprintf("Out of memory"); - return FALSE; - } - nold = ele->k_num - ele->k_base + 1; - for(i=0; i < nold; i++) - pfp[i] = ele->k_funcp[i]; - while(--n1) pfp[i++] = curmap->map_default; - pfp[i] = funct; - ele->k_num = c; - ele->k_funcp = pfp; - } else if(n2 <= MAPELEDEF) { - if((pfp = (PF *)malloc((unsigned)(ele->k_num - c + 1) - * sizeof(PF))) == NULL) { - ewprintf("Out of memory"); - return FALSE; - } - nold = ele->k_num - ele->k_base + 1; - for(i=0; i < nold; i++) - pfp[i+n2] = ele->k_funcp[i]; - while(--n2) pfp[n2] = curmap->map_default; - pfp[0] = funct; - ele->k_base = c; - ele->k_funcp = pfp; - } else { - if(curmap->map_num >= curmap->map_max && - (curmap = realocmap(curmap)) == NULL) return FALSE; - if((pfp = (PF *)malloc(sizeof(PF))) == NULL) { - ewprintf("Out of memory"); - return FALSE; - } - pfp[0] = funct; - for(mep = &curmap->map_element[curmap->map_num]; mep > ele; mep--) { - mep->k_base = (mep-1)->k_base; - mep->k_num = (mep-1)->k_num; - mep->k_funcp = (mep-1)->k_funcp; - mep->k_prefmap = (mep-1)->k_prefmap; - } - ele->k_base = c; - ele->k_num = c; - ele->k_funcp = pfp; - ele->k_prefmap = NULL; - curmap->map_num++; - } - if(funct == prefix) { - if(pref_map != NULL) { - ele->k_prefmap = pref_map; + int i; + int n1, n2, nold; + KEYMAP *mp; + PF *pfp; + MAP_ELEMENT *mep; + + if (ele >= &curmap->map_element[curmap->map_num] || c < ele->k_base) { + if (ele > &curmap->map_element[0] && (funct != prefix || + (ele - 1)->k_prefmap == NULL)) { + n1 = c - (ele - 1)->k_num; + } else + n1 = HUGE; + if (ele < &curmap->map_element[curmap->map_num] && + (funct != prefix || ele->k_prefmap == NULL)) { + n2 = ele->k_base - c; + } else + n2 = HUGE; + if (n1 <= MAPELEDEF && n1 <= n2) { + ele--; + if ((pfp = (PF *) malloc((c - ele->k_base + 1) * + sizeof(PF))) == NULL) { + ewprintf("Out of memory"); + return FALSE; + } + nold = ele->k_num - ele->k_base + 1; + for (i = 0; i < nold; i++) + pfp[i] = ele->k_funcp[i]; + while (--n1) + pfp[i++] = curmap->map_default; + pfp[i] = funct; + ele->k_num = c; + ele->k_funcp = pfp; + } else if (n2 <= MAPELEDEF) { + if ((pfp = (PF *) malloc((ele->k_num - c + 1) + * sizeof(PF))) == NULL) { + ewprintf("Out of memory"); + return FALSE; + } + nold = ele->k_num - ele->k_base + 1; + for (i = 0; i < nold; i++) + pfp[i + n2] = ele->k_funcp[i]; + while (--n2) + pfp[n2] = curmap->map_default; + pfp[0] = funct; + ele->k_base = c; + ele->k_funcp = pfp; } else { - if((mp = (KEYMAP *)malloc(sizeof(KEYMAP) + - (MAPINIT-1)*sizeof(MAP_ELEMENT))) == NULL) { - ewprintf("Out of memory"); - ele->k_funcp[c - ele->k_base] = curmap->map_default; - return FALSE; - } - mp->map_num = 0; - mp->map_max = MAPINIT; - mp->map_default = rescan; - ele->k_prefmap = mp; - } - } - } else { - n1 = c - ele->k_base; - if(ele->k_funcp[n1] == funct && (funct!=prefix || pref_map==NULL || - pref_map==ele->k_prefmap)) - return TRUE; /* no change */ - if(funct!=prefix || ele->k_prefmap==NULL) { - if(ele->k_funcp[n1] == prefix) - ele->k_prefmap = (KEYMAP *)NULL; - ele->k_funcp[n1] = funct; /* easy case */ - if(funct==prefix) { - if(pref_map!=NULL) - ele->k_prefmap = pref_map; - else { - if((mp = (KEYMAP *)malloc(sizeof(KEYMAP) + - (MAPINIT-1)*sizeof(MAP_ELEMENT))) == NULL) { - ewprintf("Out of memory"); - ele->k_funcp[c - ele->k_base] = curmap->map_default; - return FALSE; + if (curmap->map_num >= curmap->map_max && + (curmap = realocmap(curmap)) == NULL) + return FALSE; + if ((pfp = (PF *) malloc(sizeof(PF))) == NULL) { + ewprintf("Out of memory"); + return FALSE; + } + pfp[0] = funct; + for (mep = &curmap->map_element[curmap->map_num]; + mep > ele; mep--) { + mep->k_base = (mep - 1)->k_base; + mep->k_num = (mep - 1)->k_num; + mep->k_funcp = (mep - 1)->k_funcp; + mep->k_prefmap = (mep - 1)->k_prefmap; } - mp->map_num = 0; - mp->map_max = MAPINIT; - mp->map_default = rescan; - ele->k_prefmap = mp; - } + ele->k_base = c; + ele->k_num = c; + ele->k_funcp = pfp; + ele->k_prefmap = NULL; + curmap->map_num++; } - } else { - /* this case is the splits */ - /* determine which side of the break c goes on */ - /* 0 = after break; 1 = before break */ - n2 = 1; - for(i=0; n2 && i < n1; i++) - n2 &= ele->k_funcp[i] != prefix; - if(curmap->map_num >= curmap->map_max && - (curmap = realocmap(curmap)) == NULL) return FALSE; - if((pfp = (PF *)malloc((unsigned)(ele->k_num - c + !n2) - * sizeof(PF))) == NULL) { - ewprintf("Out of memory"); - return FALSE; + if (funct == prefix) { + if (pref_map != NULL) { + ele->k_prefmap = pref_map; + } else { + if (!(mp = (KEYMAP *) malloc(sizeof(KEYMAP) + + (MAPINIT - 1) * sizeof(MAP_ELEMENT)))) { + ewprintf("Out of memory"); + ele->k_funcp[c - ele->k_base] = + curmap->map_default; + return FALSE; + } + mp->map_num = 0; + mp->map_max = MAPINIT; + mp->map_default = rescan; + ele->k_prefmap = mp; + } } - ele->k_funcp[n1] = prefix; - for(i=n1+n2; i <= ele->k_num - ele->k_base; i++) - pfp[i-n1-n2] = ele->k_funcp[i]; - for(mep = &curmap->map_element[curmap->map_num]; mep > ele; mep--) { - mep->k_base = (mep-1)->k_base; - mep->k_num = (mep-1)->k_num; - mep->k_funcp = (mep-1)->k_funcp; - mep->k_prefmap = (mep-1)->k_prefmap; + } else { + n1 = c - ele->k_base; + if (ele->k_funcp[n1] == funct && (funct != prefix || + pref_map == NULL || pref_map == ele->k_prefmap)) + return TRUE; /* no change */ + if (funct != prefix || ele->k_prefmap == NULL) { + if (ele->k_funcp[n1] == prefix) + ele->k_prefmap = (KEYMAP *) NULL; + ele->k_funcp[n1] = funct; /* easy case */ + if (funct == prefix) { + if (pref_map != NULL) + ele->k_prefmap = pref_map; + else { + if (!(mp = malloc(sizeof(KEYMAP) + + (MAPINIT - 1) * sizeof(MAP_ELEMENT)))) { + ewprintf("Out of memory"); + ele->k_funcp[c - ele->k_base] = + curmap->map_default; + return FALSE; + } + mp->map_num = 0; + mp->map_max = MAPINIT; + mp->map_default = rescan; + ele->k_prefmap = mp; + } + } + } else { + /* + * This case is the splits + * determine which side of the break c goes on + * 0 = after break; 1 = before break + */ + n2 = 1; + for (i = 0; n2 && i < n1; i++) + n2 &= ele->k_funcp[i] != prefix; + if (curmap->map_num >= curmap->map_max && + (curmap = realocmap(curmap)) == NULL) + return FALSE; + if (!(pfp = malloc((ele->k_num - c + !n2) * sizeof(PF)))) { + ewprintf("Out of memory"); + return FALSE; + } + ele->k_funcp[n1] = prefix; + for (i = n1 + n2; i <= ele->k_num - ele->k_base; i++) + pfp[i - n1 - n2] = ele->k_funcp[i]; + for (mep = &curmap->map_element[curmap->map_num]; + mep > ele; mep--) { + mep->k_base = (mep - 1)->k_base; + mep->k_num = (mep - 1)->k_num; + mep->k_funcp = (mep - 1)->k_funcp; + mep->k_prefmap = (mep - 1)->k_prefmap; + } + ele->k_num = c - !n2; + (ele + 1)->k_base = c + n2; + (ele + 1)->k_funcp = pfp; + ele += !n2; + ele->k_prefmap = NULL; + curmap->map_num++; + if (pref_map == NULL) { + if ((mp = malloc(sizeof(KEYMAP) + (MAPINIT - 1) + * sizeof(MAP_ELEMENT))) == NULL) { + ewprintf("Out of memory"); + ele->k_funcp[c - ele->k_base] = + curmap->map_default; + return FALSE; + } + mp->map_num = 0; + mp->map_max = MAPINIT; + mp->map_default = rescan; + ele->k_prefmap = mp; + } else + ele->k_prefmap = pref_map; } - ele->k_num = c - !n2; - (ele+1)->k_base = c + n2; - (ele+1)->k_funcp = pfp; - ele += !n2; - ele->k_prefmap = NULL; - curmap->map_num++; - if(pref_map == NULL) { - if((mp = (KEYMAP *)malloc(sizeof(KEYMAP) + - (MAPINIT-1)*sizeof(MAP_ELEMENT))) == NULL) { - ewprintf("Out of memory"); - ele->k_funcp[c - ele->k_base] = curmap->map_default; - return FALSE; - } - mp->map_num = 0; - mp->map_max = MAPINIT; - mp->map_default = rescan; - ele->k_prefmap = mp; - } else ele->k_prefmap = pref_map; - } } return TRUE; } -/* reallocate a keymap, used above */ -static KEYMAP *realocmap(curmap) -register KEYMAP *curmap; +/* + * Reallocate a keymap, used above. + */ +static KEYMAP * +realocmap(curmap) + KEYMAP *curmap; { - register KEYMAP *mp; - register int i; - static VOID fixmap(); - extern int nmaps; - - if((mp = (KEYMAP *)malloc((unsigned)(sizeof(KEYMAP)+ - (curmap->map_max+(MAPGROW-1))*sizeof(MAP_ELEMENT)))) == NULL) { - ewprintf("Out of memory"); - return NULL; - } - mp->map_num = curmap->map_num; - mp->map_max = curmap->map_max + MAPGROW; - mp->map_default = curmap->map_default; - for(i=curmap->map_num; i--; ) { - mp->map_element[i].k_base = curmap->map_element[i].k_base; - mp->map_element[i].k_num = curmap->map_element[i].k_num; - mp->map_element[i].k_funcp = curmap->map_element[i].k_funcp; - mp->map_element[i].k_prefmap = curmap->map_element[i].k_prefmap; - } - for(i=nmaps; i--; ) { - if(map_table[i].p_map == curmap) map_table[i].p_map = mp; - else fixmap(curmap, mp, map_table[i].p_map); - } - ele = &mp->map_element[ele - &curmap->map_element[0]]; - return mp; + KEYMAP *mp; + int i; + extern int nmaps; + + if ((mp = (KEYMAP *) malloc((unsigned) (sizeof(KEYMAP) + + (curmap->map_max + (MAPGROW - 1)) * sizeof(MAP_ELEMENT)))) == NULL) { + ewprintf("Out of memory"); + return NULL; + } + mp->map_num = curmap->map_num; + mp->map_max = curmap->map_max + MAPGROW; + mp->map_default = curmap->map_default; + for (i = curmap->map_num; i--;) { + mp->map_element[i].k_base = curmap->map_element[i].k_base; + mp->map_element[i].k_num = curmap->map_element[i].k_num; + mp->map_element[i].k_funcp = curmap->map_element[i].k_funcp; + mp->map_element[i].k_prefmap = curmap->map_element[i].k_prefmap; + } + for (i = nmaps; i--;) { + if (map_table[i].p_map == curmap) + map_table[i].p_map = mp; + else + fixmap(curmap, mp, map_table[i].p_map); + } + ele = &mp->map_element[ele - &curmap->map_element[0]]; + return mp; } -/* fix references to a reallocated keymap (recursive) */ -static VOID fixmap(curmap, mp, mt) -register KEYMAP *mt; -register KEYMAP *curmap; -KEYMAP *mp; +/* + * Fix references to a reallocated keymap (recursive). + */ +static VOID +fixmap(curmap, mp, mt) + KEYMAP *mt; + KEYMAP *curmap; + KEYMAP *mp; { - register int i; + int i; - for(i = mt->map_num; i--; ) { - if(mt->map_element[i].k_prefmap != NULL) { - if(mt->map_element[i].k_prefmap == curmap) - mt->map_element[i].k_prefmap = mp; - else fixmap(curmap, mp, mt->map_element[i].k_prefmap); + for (i = mt->map_num; i--;) { + if (mt->map_element[i].k_prefmap != NULL) { + if (mt->map_element[i].k_prefmap == curmap) + mt->map_element[i].k_prefmap = mp; + else + fixmap(curmap, mp, mt->map_element[i].k_prefmap); + } } - } } /* * do the input for local-set-key, global-set-key and define-key * then call remap to do the work. */ - -static int dobind(curmap, p, unbind) -register KEYMAP *curmap; -char *p; -int unbind; +static int +dobind(curmap, p, unbind) + KEYMAP *curmap; + char *p; + int unbind; { - PF funct; - char prompt[80]; - char *pep; - int c; - int s; - KEYMAP *pref_map = NULL; + PF funct; + char prompt[80]; + char *pep; + int c; + int s; + KEYMAP *pref_map = NULL; #ifndef NO_MACRO - if(macrodef) { - /* keystrokes arn't collected. Not hard, but pretty useless */ - /* would not work for function keys in any case */ - ewprintf("Can't rebind key in macro"); - return FALSE; + if (macrodef) { + /* + * Keystrokes aren't collected. Not hard, but pretty useless. + * Would not work for function keys in any case. + */ + ewprintf("Can't rebind key in macro"); + return FALSE; } #ifndef NO_STARTUP - if(inmacro) { - for(s=0; s < maclcur->l_used - 1; s++) { - if(doscan(curmap, c=CHARMASK(maclcur->l_text[s])) != prefix) { - if(remap(curmap, c, prefix, (KEYMAP *)NULL) != TRUE) { - return FALSE; - } + if (inmacro) { + for (s = 0; s < maclcur->l_used - 1; s++) { + if (doscan(curmap, c = CHARMASK(maclcur->l_text[s])) + != prefix) { + if (remap(curmap, c, prefix, (KEYMAP *) NULL) + != TRUE) + return FALSE; + } + curmap = ele->k_prefmap; } - curmap = ele->k_prefmap; - } - (VOID) doscan(curmap, c=maclcur->l_text[s]); - maclcur = maclcur->l_fp; + (VOID) doscan(curmap, c = maclcur->l_text[s]); + maclcur = maclcur->l_fp; } else { #endif #endif - (VOID) strcpy(prompt, p); - pep = prompt + strlen(prompt); - for(;;) { - ewprintf("%s", prompt); - pep[-1] = ' '; - pep = keyname(pep, c = getkey(FALSE)); - if(doscan(curmap,c) != prefix) break; - *pep++ = '-'; - *pep = '\0'; - curmap = ele->k_prefmap; - } + (VOID) strcpy(prompt, p); + pep = prompt + strlen(prompt); + for (;;) { + ewprintf("%s", prompt); + pep[-1] = ' '; + pep = keyname(pep, c = getkey(FALSE)); + if (doscan(curmap, c) != prefix) + break; + *pep++ = '-'; + *pep = '\0'; + curmap = ele->k_prefmap; + } #ifndef NO_STARTUP } #endif - if(unbind) funct = rescan; + if (unbind) + funct = rescan; else { - if ((s=eread("%s to command: ", prompt, 80, EFFUNC|EFNEW, prompt)) - != TRUE) return s; - if (((funct = name_function(prompt)) == prefix) ? - (pref_map = name_map(prompt)) == NULL : funct==NULL) { - ewprintf("[No match]"); - return FALSE; - } + if ((s = eread("%s to command: ", prompt, 80, EFFUNC | EFNEW, + prompt)) != TRUE) + return s; + if (((funct = name_function(prompt)) == prefix) ? + (pref_map = name_map(prompt)) == NULL : funct == NULL) { + ewprintf("[No match]"); + return FALSE; + } } return remap(curmap, c, funct, pref_map); } @@ -345,29 +384,31 @@ int unbind; * KEYMAP *curmap rather than KEYMAP **mapp. */ #ifdef BINDKEY +int bindkey(mapp, fname, keys, kcount) -KEYMAP **mapp; -char *fname; -KCHAR *keys; -int kcount; + KEYMAP **mapp; + char *fname; + KCHAR *keys; + int kcount; { - KEYMAP *curmap = *mapp; - PF funct; - int c; - KEYMAP *pref_map = NULL; + KEYMAP *curmap = *mapp; + PF funct; + int c; + KEYMAP *pref_map = NULL; - if(fname == NULL) funct = rescan; + if (fname == NULL) + funct = rescan; else if (((funct = name_function(fname)) == prefix) ? - (pref_map = name_map(fname)) == NULL : funct==NULL) { - ewprintf("[No match: %s]", fname); - return FALSE; + (pref_map = name_map(fname)) == NULL : funct == NULL) { + ewprintf("[No match: %s]", fname); + return FALSE; } - while(--kcount) { - if(doscan(curmap, c = *keys++) != prefix) { - if(remap(curmap, c, prefix, (KEYMAP *)NULL) != TRUE) - return FALSE; - } - curmap = ele->k_prefmap; + while (--kcount) { + if (doscan(curmap, c = *keys++) != prefix) { + if (remap(curmap, c, prefix, (KEYMAP *) NULL) != TRUE) + return FALSE; + } + curmap = ele->k_prefmap; } (VOID) doscan(curmap, c = *keys); return remap(curmap, c, funct, pref_map); @@ -380,27 +421,31 @@ int kcount; int dobindkey(map, func, str) KEYMAP *map; - char *func; - char *str; + char *func; + char *str; { - int i; + int i; for (i = 0; *str && i < MAXKEY; i++) { /* XXX - convert numbers w/ strol()? */ if (*str != '\\') key.k_chars[i] = *str; else { - switch(*++str) { - case 't': case 'T': + switch (*++str) { + case 't': + case 'T': key.k_chars[i] = '\t'; break; - case 'n': case 'N': + case 'n': + case 'N': key.k_chars[i] = '\n'; break; - case 'r': case 'R': + case 'r': + case 'R': key.k_chars[i] = '\r'; break; - case 'e': case 'E': + case 'e': + case 'E': key.k_chars[i] = CCHR('['); break; } @@ -408,7 +453,7 @@ dobindkey(map, func, str) str++; } key.k_count = i; - return(bindkey(&map, func, key.k_chars, key.k_count)); + return (bindkey(&map, func, key.k_chars, key.k_count)); } #endif #endif @@ -416,53 +461,65 @@ dobindkey(map, func, str) /* * This function modifies the fundamental keyboard map. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int bindtokey(f, n) + int f, n; { - return dobind(map_table[0].p_map, "Global set key: ", FALSE); + return dobind(map_table[0].p_map, "Global set key: ", FALSE); } /* * This function modifies the current mode's keyboard map. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int localbind(f, n) + int f, n; { - return dobind(curbp->b_modes[curbp->b_nmodes]->p_map, "Local set key: ", - FALSE); + + return dobind(curbp->b_modes[curbp->b_nmodes]->p_map, "Local set key: ", + FALSE); } /* * This function redefines a key in any keymap. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int define_key(f, n) + int f, n; { - static char buf[48] = "Define key map: "; - MAPS *mp; - char *strncat(); - - buf[16] = '\0'; - if(eread(buf, &buf[16], 48 - 16, EFNEW) != TRUE) return FALSE; - if((mp = name_mode(&buf[16])) == NULL) { - ewprintf("Unknown map %s", &buf[16]); - return FALSE; - } - (VOID) strncat(&buf[16], " key: ", 48-16-1); - return dobind(mp->p_map, buf, FALSE); + static char buf[48] = "Define key map: "; + MAPS *mp; + char *strncat(); + + buf[16] = '\0'; + if (eread(buf, &buf[16], 48 - 16, EFNEW) != TRUE) + return FALSE; + if ((mp = name_mode(&buf[16])) == NULL) { + ewprintf("Unknown map %s", &buf[16]); + return FALSE; + } + (VOID) strncat(&buf[16], " key: ", 48 - 16 - 1); + return dobind(mp->p_map, buf, FALSE); } +int unbindtokey(f, n) -int f, n; + int f, n; { - return dobind(map_table[0].p_map, "Global unset key: ", TRUE); + + return dobind(map_table[0].p_map, "Global unset key: ", TRUE); } +int localunbind(f, n) -int f, n; + int f, n; { - return dobind(curbp->b_modes[curbp->b_nmodes]->p_map, "Local unset key: ", - TRUE); + + return dobind(curbp->b_modes[curbp->b_nmodes]->p_map, + "Local unset key: ", TRUE); } /* @@ -472,26 +529,31 @@ int f, n; * and run the command if it is found. * Print an error if there is anything wrong. */ +int extend(f, n) + int f, n; { - PF funct; - int s; - char xname[NXNAME]; - - if(!(f & FFARG)) s = eread("M-x ", xname, NXNAME, EFNEW|EFFUNC); - else s = eread("%d M-x ", xname, NXNAME, EFNEW|EFFUNC, n); - if(s != TRUE) return s; - if((funct = name_function(xname)) != NULL) { + PF funct; + int s; + char xname[NXNAME]; + + if (!(f & FFARG)) + s = eread("M-x ", xname, NXNAME, EFNEW | EFFUNC); + else + s = eread("%d M-x ", xname, NXNAME, EFNEW | EFFUNC, n); + if (s != TRUE) + return s; + if ((funct = name_function(xname)) != NULL) { #ifndef NO_MACRO - if(macrodef) { - LINE *lp = maclcur; - macro[macrocount-1].m_funct = funct; - maclcur = lp->l_bp; - maclcur->l_fp = lp->l_fp; - free((char *)lp); - } + if (macrodef) { + LINE *lp = maclcur; + macro[macrocount - 1].m_funct = funct; + maclcur = lp->l_bp; + maclcur->l_fp = lp->l_fp; + free((char *) lp); + } #endif - return (*funct)(f, n); + return (*funct) (f, n); } ewprintf("[No match]"); return FALSE; @@ -516,45 +578,55 @@ extend(f, n) /* * evalexpr - get one line from the user, and run it. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int evalexpr(f, n) + int f, n; { - int s; - char exbuf[128]; + int s; + char exbuf[128]; if ((s = ereply("Eval: ", exbuf, 128)) != TRUE) return s; return excline(exbuf); } + /* * evalbuffer - evaluate the current buffer as line commands. Useful * for testing startup files. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int evalbuffer(f, n) + int f, n; { - register LINE *lp; - register BUFFER *bp = curbp; - register int s; - static char excbuf[128]; + LINE *lp; + BUFFER *bp = curbp; + int s; + static char excbuf[128]; for (lp = lforw(bp->b_linep); lp != bp->b_linep; lp = lforw(lp)) { - if (llength(lp) >= 128) return FALSE; + if (llength(lp) >= 128) + return FALSE; (VOID) strncpy(excbuf, ltext(lp), llength(lp)); excbuf[llength(lp)] = '\0'; /* make sure it's terminated */ - if ((s = excline(excbuf)) != TRUE) return s; + if ((s = excline(excbuf)) != TRUE) + return s; } return TRUE; } + /* * evalfile - go get a file and evaluate it as line commands. You can * go get your own startup file if need be. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int evalfile(f, n) + int f, n; { - register int s; - char fname[NFILEN]; + int s; + char fname[NFILEN]; if ((s = ereply("Load file: ", fname, NFILEN)) != TRUE) return s; @@ -564,16 +636,20 @@ evalfile(f, n) /* * load - go load the file name we got passed. */ -load(fname) char *fname; { - int s = TRUE; - int nbytes; - char excbuf[128]; +int +load(fname) + char *fname; +{ + int s = TRUE; + int nbytes; + char excbuf[128]; if ((fname = adjustname(fname)) == NULL) return FALSE; /* just to be careful */ - if (ffropen(fname, (BUFFER *) NULL) != FIOSUC) return FALSE; - while ((s = ffgetline(excbuf, sizeof(excbuf)-1, &nbytes)) == FIOSUC) { + if (ffropen(fname, (BUFFER *) NULL) != FIOSUC) + return FALSE; + while ((s = ffgetline(excbuf, sizeof(excbuf) - 1, &nbytes)) == FIOSUC) { excbuf[nbytes] = '\0'; if (excline(excbuf) != TRUE) { s = FIOERR; @@ -583,7 +659,7 @@ load(fname) char *fname; { } (VOID) ffclose((BUFFER *) NULL); excbuf[nbytes] = '\0'; - if(s!=FIOEOF || (nbytes && excline(excbuf)!=TRUE)) + if (s != FIOEOF || (nbytes && excline(excbuf) != TRUE)) return FALSE; return TRUE; } @@ -593,20 +669,22 @@ load(fname) char *fname; { * if FKEYS is defined, duplicate functionallity of dobind so function * key values don't have to fit in type char. */ +int excline(line) -register char *line; + char *line; { - register char *funcp, *argp = NULL; - register int c; - int status; - int f, n; - LINE *lp, *np; - PF fp; + char *funcp, *argp = NULL; + int c; + int status; + int f, n; + LINE *lp, *np; + PF fp; #ifdef FKEYS - int bind; - KEYMAP *curmap; - MAPS *mp; -#define BINDARG 0 /* this arg is key to bind (local/global set key) */ + int bind; + KEYMAP *curmap; + MAPS *mp; +#define BINDARG 0 /* this arg is key to bind (local/global set + * key) */ #define BINDNO 1 /* not binding or non-quoted BINDARG */ #define BINDNEXT 2 /* next arg " (define-key) */ #define BINDDO 3 /* already found key to bind */ @@ -614,19 +692,16 @@ register char *line; #else #define BINDEXT 0 #endif - PF name_function(); - LINE *lalloc(); - static char *skipwhite(), *parsetoken(); - if(macrodef || inmacro) { + if (macrodef || inmacro) { ewprintf("Not now!"); return FALSE; } - f = 0; n = 1; funcp = skipwhite(line); - if (*funcp == '\0') return TRUE; /* No error on blank lines */ + if (*funcp == '\0') + return TRUE; /* No error on blank lines */ line = parsetoken(funcp); if (*line != '\0') { *line++ = '\0'; @@ -636,135 +711,159 @@ register char *line; line = parsetoken(line); } } - if (argp != NULL) { f = FFARG; n = atoi(argp); } - if((fp = name_function(funcp)) == NULL) { - ewprintf("Unknown function: %s", funcp); - return FALSE; + if ((fp = name_function(funcp)) == NULL) { + ewprintf("Unknown function: %s", funcp); + return FALSE; } #ifdef FKEYS - if(fp == bindtokey || fp == unbindtokey) { + if (fp == bindtokey || fp == unbindtokey) { bind = BINDARG; curmap = map_table[0].p_map; - } else if(fp == localbind || fp == localunbind) { + } else if (fp == localbind || fp == localunbind) { bind = BINDARG; curmap = curbp->b_modes[curbp->b_nmodes]->p_map; - } else if(fp == define_key) bind = BINDNEXT; - else bind = BINDNO; + } else if (fp == define_key) + bind = BINDNEXT; + else + bind = BINDNO; #endif - /* Pack away all the args now... */ - if((np = lalloc(0))==FALSE) return FALSE; + /* Pack away all the args now... */ + if ((np = lalloc(0)) == FALSE) + return FALSE; np->l_fp = np->l_bp = maclcur = np; while (*line != '\0') { argp = skipwhite(line); - if (*argp == '\0') break; + if (*argp == '\0') + break; line = parsetoken(argp); if (*argp != '"') { - if (*argp == '\'') ++argp; - if((lp = lalloc((int)(line-argp)+BINDEXT))==NULL) { - status = FALSE; - goto cleanup; - } - bcopy(argp, ltext(lp), (int)(line-argp)); + if (*argp == '\'') + ++argp; + if (!(lp = lalloc((int) (line - argp) + BINDEXT))) { + status = FALSE; + goto cleanup; + } + bcopy(argp, ltext(lp), (int) (line - argp)); #ifdef FKEYS - lp->l_used--; /* don't count BINDEXT! */ - if(bind == BINDARG) bind = BINDNO; + lp->l_used--; /* don't count BINDEXT! */ + if (bind == BINDARG) + bind = BINDNO; #endif } else { /* Quoted strings special */ - ++argp; + ++argp; #ifdef FKEYS - if(bind != BINDARG) { + if (bind != BINDARG) { #endif - if((lp = lalloc((int)(line-argp)+BINDEXT))==NULL) { - status = FALSE; - goto cleanup; + lp = lalloc((int) (line - argp) + BINDEXT); + if (lp == NULL) { + status = FALSE; + goto cleanup; + } + lp->l_used = 0; +#ifdef FKEYS + } else { + key.k_count = 0; } - lp->l_used = 0; +#endif + while (*argp != '"' && *argp != '\0') { + if (*argp != '\\') + c = *argp++; + else { + switch (*++argp) { + case 't': + case 'T': + c = CCHR('I'); + break; + case 'n': + case 'N': + c = CCHR('J'); + break; + case 'r': + case 'R': + c = CCHR('M'); + break; + case 'e': + case 'E': + c = CCHR('['); + break; + case '^': + /* + * split into two statements + * due to bug in OSK cpp + */ + c = CHARMASK(*++argp); + c = ISLOWER(c) ? + CCHR(TOUPPER(c)) : CCHR(c); + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + c = *argp - '0'; + if (argp[1] <= '7' && argp[1] >= '0') { + c <<= 3; + c += *++argp - '0'; + if (argp[1] <= '7' && + argp[1] >= '0') { + c <<= 3; + c += *++argp + - '0'; + } + } + break; #ifdef FKEYS - } else { - key.k_count = 0; - } + case 'f': + case 'F': + c = *++argp - '0'; + if (ISDIGIT(argp[1])) { + c *= 10; + c += *++argp - '0'; + } + c += KFIRST; + break; #endif - while (*argp != '"' && *argp != '\0') { - if (*argp != '\\') c = *argp++; - else { - switch(*++argp) { - case 't': case 'T': - c = CCHR('I'); - break; - case 'n': case 'N': - c = CCHR('J'); - break; - case 'r': case 'R': - c = CCHR('M'); - break; - case 'e': case 'E': - c = CCHR('['); - break; - case '^': -/* split into two statements due to bug in OSK cpp */ - c = CHARMASK(*++argp); - c = ISLOWER(c) ? - CCHR(TOUPPER(c)) : CCHR(c); - break; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - c = *argp - '0'; - if(argp[1] <= '7' && argp[1] >= '0') { - c <<= 3; - c += *++argp - '0'; - if(argp[1] <= '7' && argp[1] >= '0') { - c <<= 3; - c += *++argp - '0'; + default: + c = CHARMASK(*argp); + break; } - } - break; + argp++; + } #ifdef FKEYS - case 'f': case 'F': - c = *++argp - '0'; - if(ISDIGIT(argp[1])) { - c *= 10; - c += *++argp - '0'; - } - c += KFIRST; - break; + if (bind == BINDARG) + key.k_chars[key.k_count++] = c; + else #endif - default: - c = CHARMASK(*argp); - break; - } - argp++; + lp->l_text[lp->l_used++] = c; } -#ifdef FKEYS - if(bind == BINDARG) - key.k_chars[key.k_count++] = c; - else -#endif - lp->l_text[lp->l_used++] = c; - } - if(*line) line++; + if (*line) + line++; } #ifdef FKEYS - switch(bind) { - case BINDARG: + switch (bind) { + case BINDARG: bind = BINDDO; break; - case BINDNEXT: + case BINDNEXT: lp->l_text[lp->l_used] = '\0'; - if((mp = name_mode(lp->l_text)) == NULL) { - ewprintf("No such mode: %s", lp->l_text); - status = FALSE; - free((char *)lp); - goto cleanup; + if ((mp = name_mode(lp->l_text)) == NULL) { + ewprintf("No such mode: %s", lp->l_text); + status = FALSE; + free((char *) lp); + goto cleanup; } curmap = mp->p_map; - free((char *)lp); + free((char *) lp); bind = BINDARG; break; - default: + default: #endif lp->l_fp = np->l_fp; lp->l_bp = np; @@ -775,34 +874,37 @@ register char *line; #endif } #ifdef FKEYS - switch(bind) { - default: + switch (bind) { + default: ewprintf("Bad args to set key"); status = FALSE; break; - case BINDDO: - if(fp != unbindtokey && fp != localunbind) { - lp->l_text[lp->l_used] = '\0'; - status = bindkey(&curmap, lp->l_text, key.k_chars, key.k_count); - } else status = bindkey(&curmap, (char *)NULL, key.k_chars, key.k_count); + case BINDDO: + if (fp != unbindtokey && fp != localunbind) { + lp->l_text[lp->l_used] = '\0'; + status = bindkey(&curmap, lp->l_text, key.k_chars, + key.k_count); + } else + status = bindkey(&curmap, (char *) NULL, key.k_chars, + key.k_count); break; - case BINDNO: + case BINDNO: #endif inmacro = TRUE; maclcur = maclcur->l_fp; - status = (*fp)(f, n); + status = (*fp) (f, n); inmacro = FALSE; #ifdef FKEYS } #endif cleanup: lp = maclcur->l_fp; - while(lp!=maclcur) { - np = lp->l_fp; - free((char *)lp); - lp = np; + while (lp != maclcur) { + np = lp->l_fp; + free((char *) lp); + lp = np; } - free((char *)lp); + free((char *) lp); return status; } @@ -811,25 +913,32 @@ cleanup: */ static char * skipwhite(s) -register char *s; + char *s; { - while(*s == ' ' || *s == '\t' || *s == ')' || *s == '(') s++; - if (*s == ';') *s = '\0' ; + + while (*s == ' ' || *s == '\t' || *s == ')' || *s == '(') + s++; + if (*s == ';') + *s = '\0'; return s; } static char * parsetoken(s) -register char *s; + char *s; { + if (*s != '"') { - while(*s && *s!=' ' && *s!='\t' && *s!=')' && *s!='(') s++; - if(*s==';') *s='\0'; + while (*s && *s != ' ' && *s != '\t' && *s != ')' && *s != '(') + s++; + if (*s == ';') + *s = '\0'; } else - do { /* Strings get special treatment */ + do { /* Strings get special treatment */ /* Beware: You can \ out the end of the string! */ - if (*s == '\\') ++s; - } while (*++s != '"' && *s != '\0'); + if (*s == '\\') + ++s; + } while (*++s != '"' && *s != '\0'); return s; } #endif diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c index 508b4727d25..966982f295f 100644 --- a/usr.bin/mg/file.c +++ b/usr.bin/mg/file.c @@ -3,25 +3,25 @@ */ #include "def.h" -BUFFER *findbuffer(); -VOID makename(); -VOID upmodes(); -static char *itos(); +static char *itos __P((char *, unsigned int)); /* * insert a file into the current buffer. Real easy - just call the * insertfile routine with the file name. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int fileinsert(f, n) + int f, n; { - register int s; - char fname[NFILEN]; + int s; + char fname[NFILEN]; - if ((s=eread("Insert file: ", fname, NFILEN, EFNEW|EFCR|EFFILE)) != TRUE) + s = eread("Insert file: ", fname, NFILEN, EFNEW | EFCR | EFFILE); + if (s != TRUE) return (s); return insertfile(adjustname(fname), (char *) NULL, FALSE); - /* don't set buffer name */ + /* don't set buffer name */ } /* @@ -32,22 +32,27 @@ fileinsert(f, n) * the file, create a new buffer, read in the * text, and switch to the new buffer. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int filevisit(f, n) + int f, n; { - register BUFFER *bp; - int s; - char fname[NFILEN]; - char *adjf; + BUFFER *bp; + int s; + char fname[NFILEN]; + char *adjf; - if ((s=eread("Find file: ", fname, NFILEN, EFNEW|EFCR|EFFILE)) != TRUE) + s = eread("Find file: ", fname, NFILEN, EFNEW | EFCR | EFFILE); + if (s != TRUE) return s; adjf = adjustname(fname); - if ((bp = findbuffer(adjf)) == NULL) return FALSE; + if ((bp = findbuffer(adjf)) == NULL) + return FALSE; curbp = bp; - if (showbuffer(bp, curwp, WFHARD) != TRUE) return FALSE; + if (showbuffer(bp, curwp, WFHARD) != TRUE) + return FALSE; if (bp->b_fname[0] == 0) - return readin(adjf); /* Read it in. */ + return readin(adjf); /* Read it in. */ return TRUE; } @@ -55,25 +60,29 @@ filevisit(f, n) * Pop to a file in the other window. Same as last function, just * popbuf instead of showbuffer. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int poptofile(f, n) + int f, n; { - register BUFFER *bp; - register MGWIN *wp; - int s; - char fname[NFILEN]; - char *adjf; - - if ((s=eread("Find file in other window: ", fname, NFILEN, - EFNEW|EFCR|EFFILE)) != TRUE) + BUFFER *bp; + MGWIN *wp; + int s; + char fname[NFILEN]; + char *adjf; + + if ((s = eread("Find file in other window: ", fname, NFILEN, + EFNEW | EFCR | EFFILE)) != TRUE) return s; adjf = adjustname(fname); - if ((bp = findbuffer(adjf)) == NULL) return FALSE; - if ((wp = popbuf(bp)) == NULL) return FALSE; + if ((bp = findbuffer(adjf)) == NULL) + return FALSE; + if ((wp = popbuf(bp)) == NULL) + return FALSE; curbp = bp; curwp = wp; if (bp->b_fname[0] == 0) - return readin(adjf); /* Read it in. */ + return readin(adjf); /* Read it in. */ return TRUE; } @@ -83,21 +92,21 @@ poptofile(f, n) */ BUFFER * findbuffer(fname) -char *fname; + char *fname; { - register BUFFER *bp; - char bname[NBUFN], *cp; - unsigned count = 1; + BUFFER *bp; + char bname[NBUFN], *cp; + unsigned int count = 1; - for (bp=bheadp; bp!=NULL; bp=bp->b_bufp) { + for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { if (fncmp(bp->b_fname, fname) == 0) return bp; } - makename(bname, fname); /* New buffer name. */ + makename(bname, fname); /* New buffer name. */ cp = bname + strlen(bname); - while(bfind(bname, FALSE) != NULL) { - *cp = '<'; /* add "<count>" to then name */ - (VOID) strcpy(itos(cp, ++count)+1, ">"); + while (bfind(bname, FALSE) != NULL) { + *cp = '<'; /* add "<count>" to then name */ + (VOID) strcpy(itos(cp, ++count) + 1, ">"); } return bfind(bname, TRUE); } @@ -106,12 +115,14 @@ char *fname; * Put the decimal representation of num into a buffer. Hacked to be * faster, smaller, and less general. */ -static char *itos(bufp, num) -char *bufp; -unsigned num; +static char * +itos(bufp, num) + char *bufp; + unsigned int num; { + if (num >= 10) { - bufp = itos(bufp, num/10); + bufp = itos(bufp, num / 10); num %= 10; } *++bufp = '0' + num; @@ -124,18 +135,21 @@ unsigned num; * for unsaved changes. This is called by the "read" command, the * "visit" command, and the mainline (for "uemacs file"). */ -readin(fname) char *fname; { - register int status; - register MGWIN *wp; +int +readin(fname) + char *fname; +{ + int status; + MGWIN *wp; - if (bclear(curbp) != TRUE) /* Might be old. */ + if (bclear(curbp) != TRUE) /* Might be old. */ return TRUE; - status = insertfile(fname, fname, TRUE) ; - curbp->b_flag &= ~BFCHG; /* No change. */ - for (wp=wheadp; wp!=NULL; wp=wp->w_wndp) { + status = insertfile(fname, fname, TRUE); + curbp->b_flag &= ~BFCHG;/* No change. */ + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { if (wp->w_bufp == curbp) { - wp->w_dotp = wp->w_linep = lforw(curbp->b_linep); - wp->w_doto = 0; + wp->w_dotp = wp->w_linep = lforw(curbp->b_linep); + wp->w_doto = 0; wp->w_markp = NULL; wp->w_marko = 0; } @@ -160,97 +174,105 @@ readin(fname) char *fname; { * read in, but not on a new file (you don't need to make a backup * copy of nothing). */ -static char *line = NULL; -static int linesize = 0; - -insertfile(fname, newname, needinfo) char fname[], newname[]; { - register LINE *lp1; - register LINE *lp2; - register MGWIN *wp; - int nbytes; - LINE *olp; /* Line we started at */ - int opos; /* and offset into it */ - int s, nline; - BUFFER *bp; +static char *line = NULL; +static int linesize = 0; + +int +insertfile(fname, newname, needinfo) + char *fname, *newname; + int needinfo; +{ + LINE *lp1; + LINE *lp2; + MGWIN *wp; + int nbytes; + LINE *olp; /* Line we started at */ + int opos; /* and offset into it */ + int s, nline; + BUFFER *bp; if (line == NULL) { line = malloc(NLINE); linesize = NLINE; } - bp = curbp; /* Cheap. */ + bp = curbp; /* Cheap. */ if (newname != (char *) NULL) (VOID) strcpy(bp->b_fname, newname); - /* Hard file open. */ - if ((s=ffropen(fname, needinfo ? bp : (BUFFER *) NULL)) == FIOERR) + /* Hard file open. */ + if ((s = ffropen(fname, needinfo ? bp : (BUFFER *) NULL)) == FIOERR) goto out; - if (s == FIOFNF) { /* File not found. */ + if (s == FIOFNF) { /* File not found. */ if (newname != NULL) ewprintf("(New file)"); - else ewprintf("(File not found)"); + else + ewprintf("(File not found)"); goto out; } opos = curwp->w_doto; /* Open a new line, at point, and start inserting after it */ (VOID) lnewline(); olp = lback(curwp->w_dotp); - if(olp == curbp->b_linep) { + if (olp == curbp->b_linep) { /* if at end of buffer, create a line to insert before */ (VOID) lnewline(); curwp->w_dotp = lback(curwp->w_dotp); } - nline = 0; /* Don't count fake line at end */ - while ((s=ffgetline(line, linesize, &nbytes)) != FIOERR) { + nline = 0; /* Don't count fake line at end */ + while ((s = ffgetline(line, linesize, &nbytes)) != FIOERR) { doneread: - switch(s) { - case FIOSUC: - ++nline; - /* and continue */ - case FIOEOF: /* the last line of the file */ - if ((lp1=lalloc(nbytes)) == NULL) { - s = FIOERR; /* Keep message on the */ - goto endoffile; /* display. */ - } - bcopy(line, <ext(lp1)[0], nbytes); - lp2 = lback(curwp->w_dotp); - lp2->l_fp = lp1; - lp1->l_fp = curwp->w_dotp; - lp1->l_bp = lp2; - curwp->w_dotp->l_bp = lp1; - if(s==FIOEOF) goto endoffile; - break; - case FIOLONG: { /* a line to long to fit in our buffer */ - char *cp; - int newsize; - - newsize = linesize * 2; - if(newsize < 0 || - (cp = malloc((unsigned)newsize)) == NULL) { - ewprintf("Could not allocate %d bytes", - newsize); - s = FIOERR; - goto endoffile; - } - bcopy(line, cp, linesize); - free(line); - line = cp; - s=ffgetline(line+linesize, linesize, &nbytes); - nbytes += linesize; - linesize = newsize; - if (s == FIOERR) - goto endoffile; - goto doneread; + switch (s) { + case FIOSUC: + ++nline; + /* and continue */ + case FIOEOF: /* the last line of the file */ + if ((lp1 = lalloc(nbytes)) == NULL) { + s = FIOERR; /* Keep message on the */ + goto endoffile; /* display. */ + } + bcopy(line, <ext(lp1)[0], nbytes); + lp2 = lback(curwp->w_dotp); + lp2->l_fp = lp1; + lp1->l_fp = curwp->w_dotp; + lp1->l_bp = lp2; + curwp->w_dotp->l_bp = lp1; + if (s == FIOEOF) + goto endoffile; + break; + case FIOLONG:{ /* a line too long to fit in our buffer */ + char *cp; + int newsize; + + newsize = linesize * 2; + if (newsize < 0 || + (cp = malloc((unsigned) newsize)) == NULL) { + ewprintf("Could not allocate %d bytes", + newsize); + s = FIOERR; + goto endoffile; + } + bcopy(line, cp, linesize); + free(line); + line = cp; + s = ffgetline(line + linesize, linesize, &nbytes); + nbytes += linesize; + linesize = newsize; + if (s == FIOERR) + goto endoffile; + goto doneread; + } + default: + ewprintf("Unknown code %d reading file", s); + s = FIOERR; + break; } - default: - ewprintf("Unknown code %d reading file", s); - s = FIOERR; - break; - } } endoffile: - (VOID) ffclose((BUFFER *) NULL); /* Ignore errors. */ - if (s==FIOEOF) { /* Don't zap an error. */ - if (nline == 1) ewprintf("(Read 1 line)"); - else ewprintf("(Read %d lines)", nline); + (VOID) ffclose((BUFFER *) NULL); /* Ignore errors. */ + if (s == FIOEOF) { /* Don't zap an error. */ + if (nline == 1) + ewprintf("(Read 1 line)"); + else + ewprintf("(Read %d lines)", nline); } /* Set mark at the end of the text */ curwp->w_dotp = curwp->w_markp = lback(curwp->w_dotp); @@ -258,38 +280,44 @@ endoffile: (VOID) ldelnewline(); curwp->w_dotp = olp; curwp->w_doto = opos; - if(olp == curbp->b_linep) curwp->w_dotp = lforw(olp); + if (olp == curbp->b_linep) + curwp->w_dotp = lforw(olp); #ifndef NO_BACKUP if (newname != NULL) - bp->b_flag |= BFCHG | BFBAK; /* Need a backup. */ - else bp->b_flag |= BFCHG; + bp->b_flag |= BFCHG | BFBAK; /* Need a backup. */ + else + bp->b_flag |= BFCHG; #else bp->b_flag |= BFCHG; #endif - /* if the insert was at the end of buffer, set lp1 to the end of - * buffer line, and lp2 to the beginning of the newly inserted - * text. (Otherwise lp2 is set to NULL.) This is - * used below to set pointers in other windows correctly if they - * are also at the end of buffer. + /* + * if the insert was at the end of buffer, set lp1 to the end of + * buffer line, and lp2 to the beginning of the newly inserted text. + * (Otherwise lp2 is set to NULL.) This is used below to set + * pointers in other windows correctly if they are also at the end of + * buffer. */ lp1 = bp->b_linep; if (curwp->w_markp == lp1) { lp2 = curwp->w_dotp; } else { - (VOID) ldelnewline(); /* delete extranious newline */ + (VOID) ldelnewline(); /* delete extranious newline */ out: lp2 = NULL; } - for (wp=wheadp; wp!=NULL; wp=wp->w_wndp) { + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { if (wp->w_bufp == curbp) { - wp->w_flag |= WFMODE|WFEDIT; + wp->w_flag |= WFMODE | WFEDIT; if (wp != curwp && lp2 != NULL) { - if (wp->w_dotp == lp1) wp->w_dotp = lp2; - if (wp->w_markp == lp1) wp->w_markp = lp2; - if (wp->w_linep == lp1) wp->w_linep = lp2; + if (wp->w_dotp == lp1) + wp->w_dotp = lp2; + if (wp->w_markp == lp1) + wp->w_markp = lp2; + if (wp->w_linep == lp1) + wp->w_linep = lp2; } } } - return s != FIOERR; /* False if error. */ + return s != FIOERR; /* False if error. */ } /* @@ -301,27 +329,30 @@ out: lp2 = NULL; * BDC3 optional right scan delimiter. */ VOID -makename(bname, fname) char bname[]; char fname[]; { - register char *cp1; - register char *cp2; +makename(bname, fname) + char *bname; + char *fname; +{ + char *cp1; + char *cp2; cp1 = &fname[0]; while (*cp1 != 0) ++cp1; --cp1; /* insure at least 1 character ! */ #ifdef BDC2 - while (cp1!=&fname[0] && cp1[-1]!=BDC1 && cp1[-1]!=BDC2) + while (cp1 != &fname[0] && cp1[-1] != BDC1 && cp1[-1] != BDC2) --cp1; #else - while (cp1!=&fname[0] && cp1[-1]!=BDC1) + while (cp1 != &fname[0] && cp1[-1] != BDC1) --cp1; #endif cp2 = &bname[0]; #ifdef BDC3 - while (cp2!=&bname[NBUFN-1] && *cp1!=0 && *cp1!=BDC3) + while (cp2 != &bname[NBUFN - 1] && *cp1 != 0 && *cp1 != BDC3) *cp2++ = *cp1++; #else - while (cp2!=&bname[NBUFN-1] && *cp1!=0) + while (cp2 != &bname[NBUFN - 1] && *cp1 != 0) *cp2++ = *cp1++; #endif *cp2 = 0; @@ -336,20 +367,22 @@ makename(bname, fname) char bname[]; char fname[]; { * is more compatable with Gosling EMACS than * with ITS EMACS. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int filewrite(f, n) + int f, n; { - register int s; - char fname[NFILEN]; - char *adjfname; + int s; + char fname[NFILEN]; + char *adjfname; - if ((s=eread("Write file: ", fname, NFILEN, - EFNEW|EFCR|EFFILE)) != TRUE) + if ((s = eread("Write file: ", fname, NFILEN, + EFNEW | EFCR | EFFILE)) != TRUE) return (s); adjfname = adjustname(fname); /* old attributes are no longer current */ bzero(&curbp->b_fi, sizeof(curbp->b_fi)); - if ((s=writeout(curbp, adjfname)) == TRUE) { + if ((s = writeout(curbp, adjfname)) == TRUE) { (VOID) strcpy(curbp->b_fname, adjfname); #ifndef NO_BACKUP curbp->b_flag &= ~(BFBAK | BFCHG); @@ -369,10 +402,11 @@ filewrite(f, n) #ifndef MAKEBACKUP #define MAKEBACKUP TRUE #endif -static int makebackup = MAKEBACKUP; +static int makebackup = MAKEBACKUP; #endif -/*ARGSUSED*/ +/* ARGSUSED */ +int filesave(f, n) { return buffsave(curbp); @@ -387,28 +421,31 @@ filesave(f, n) * Allow user to select whether or not to make backup files * by looking at the value of makebackup. */ -buffsave(bp) BUFFER *bp; { - register int s; +int +buffsave(bp) + BUFFER *bp; +{ + int s; - if ((bp->b_flag&BFCHG) == 0) { /* Return, no changes. */ + if ((bp->b_flag & BFCHG) == 0) { /* Return, no changes. */ ewprintf("(No changes need to be saved)"); return TRUE; } - if (bp->b_fname[0] == '\0') { /* Must have a name. */ + if (bp->b_fname[0] == '\0') { /* Must have a name. */ ewprintf("No file name"); return (FALSE); } #ifndef NO_BACKUP - if (makebackup && (bp->b_flag&BFBAK)) { + if (makebackup && (bp->b_flag & BFBAK)) { s = fbackupfile(bp->b_fname); - if (s == ABORT) /* Hard error. */ + if (s == ABORT) /* Hard error. */ return FALSE; - if (s == FALSE /* Softer error. */ - && (s=eyesno("Backup error, save anyway")) != TRUE) + if (s == FALSE /* Softer error. */ + && (s = eyesno("Backup error, save anyway")) != TRUE) return s; } #endif - if ((s=writeout(bp, bp->b_fname)) == TRUE) { + if ((s = writeout(bp, bp->b_fname)) == TRUE) { #ifndef NO_BACKUP bp->b_flag &= ~(BFCHG | BFBAK); #else @@ -420,19 +457,22 @@ buffsave(bp) BUFFER *bp; { } #ifndef NO_BACKUP -/* Since we don't have variables (we probably should) - * this is a command processor for changing the value of - * the make backup flag. If no argument is given, - * sets makebackup to true, so backups are made. If - * an argument is given, no backup files are made when - * saving a new version of a file. Only used when BACKUP - * is #defined. +/* + * Since we don't have variables (we probably should) this is a command + * processor for changing the value of the make backup flag. If no argument + * is given, sets makebackup to true, so backups are made. If an argument is + * given, no backup files are made when saving a new version of a file. Only + * used when BACKUP is #defined. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int makebkfile(f, n) { - if(f & FFARG) makebackup = n > 0; - else makebackup = !makebackup; + + if (f & FFARG) + makebackup = n > 0; + else + makebackup = !makebackup; ewprintf("Backup files %sabled", makebackup ? "en" : "dis"); return TRUE; } @@ -454,18 +494,22 @@ makebkfile(f, n) * in the "fileio.c" package. Most of the grief * is checking of some sort. */ -writeout(bp, fn) register BUFFER *bp; char *fn; { - register int s; +int +writeout(bp, fn) + BUFFER *bp; + char *fn; +{ + int s; - if ((s=ffwopen(fn,bp)) != FIOSUC) /* Open writes message. */ + if ((s = ffwopen(fn, bp)) != FIOSUC) /* Open writes message. */ return (FALSE); s = ffputbuf(bp); - if (s == FIOSUC) { /* No write error. */ + if (s == FIOSUC) { /* No write error. */ s = ffclose(bp); - if (s==FIOSUC) + if (s == FIOSUC) ewprintf("Wrote %s", fn); - } else /* Ignore close error */ - (VOID) ffclose(bp); /* if a write error. */ + } else /* Ignore close error */ + (VOID) ffclose(bp); /* if a write error. */ return s == FIOSUC; } @@ -474,9 +518,12 @@ writeout(bp, fn) register BUFFER *bp; char *fn; { * mode line updated. */ VOID -upmodes(bp) register BUFFER *bp; { - register MGWIN *wp; +upmodes(bp) + BUFFER *bp; +{ + MGWIN *wp; for (wp = wheadp; wp != NULL; wp = wp->w_wndp) - if (bp == NULL || curwp->w_bufp == bp) wp->w_flag |= WFMODE; + if (bp == NULL || curwp->w_bufp == bp) + wp->w_flag |= WFMODE; } diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c index b50758d817c..8fb3b049a43 100644 --- a/usr.bin/mg/fileio.c +++ b/usr.bin/mg/fileio.c @@ -1,10 +1,9 @@ /* - * POSIX fileio.c + * POSIX fileio.c */ #include "def.h" -static FILE *ffp; -char *adjustname(); +static FILE *ffp; #include <sys/types.h> #include <sys/stat.h> @@ -13,13 +12,17 @@ char *adjustname(); /* * Open a file for reading. */ -ffropen(fn, bp) char *fn; BUFFER *bp; { - struct stat statbuf; - - if ((ffp=fopen(fn, "r")) == NULL) +int +ffropen(fn, bp) + char *fn; + BUFFER *bp; +{ + struct stat statbuf; + + if ((ffp = fopen(fn, "r")) == NULL) return (FIOFNF); if (bp && fstat(fileno(ffp), &statbuf) == 0) { -/* set highorder bit to make sure this isn't all zero */ + /* set highorder bit to make sure this isn't all zero */ bp->b_fi.fi_mode = statbuf.st_mode | 0x8000; bp->b_fi.fi_uid = statbuf.st_uid; bp->b_fi.fi_gid = statbuf.st_gid; @@ -32,18 +35,23 @@ ffropen(fn, bp) char *fn; BUFFER *bp; { * Return TRUE if all is well, and * FALSE on error (cannot create). */ -ffwopen(fn, bp) char *fn; BUFFER *bp; { - if ((ffp=fopen(fn, "w")) == NULL) { +int +ffwopen(fn, bp) + char *fn; + BUFFER *bp; +{ + + if ((ffp = fopen(fn, "w")) == NULL) { ewprintf("Cannot open file for writing"); return (FIOERR); } - /* - * If we have file information, use it. We don't bother - * to check for errors, because there's no a lot we can do - * about it. Certainly trying to change ownership will fail - * if we aren' root. That's probably OK. If we don't have - * info, no need to get it, since any future writes will do - * the same thing. + + /* + * If we have file information, use it. We don't bother to check for + * errors, because there's no a lot we can do about it. Certainly + * trying to change ownership will fail if we aren' root. That's + * probably OK. If we don't have info, no need to get it, since any + * future writes will do the same thing. */ if (bp && bp->b_fi.fi_mode) { chmod(fn, bp->b_fi.fi_mode & 07777); @@ -54,9 +62,14 @@ ffwopen(fn, bp) char *fn; BUFFER *bp; { /* * Close a file. - * Should look at the status. + * XXX - Should look at the status. */ -ffclose() { +/* ARGSUSED */ +int +ffclose(bp) + BUFFER *bp; +{ + (VOID) fclose(ffp); return (FIOSUC); } @@ -68,32 +81,35 @@ ffclose() { * Check only at the newline and * end of buffer. */ +int ffputbuf(bp) -BUFFER *bp; + BUFFER *bp; { - register char *cp; - register char *cpend; - register LINE *lp; - register LINE *lpend; - - lpend = bp->b_linep; - lp = lforw(lpend); - do { - cp = <ext(lp)[0]; /* begining of line */ - cpend = &cp[llength(lp)]; /* end of line */ - while(cp != cpend) { - putc(*cp, ffp); - cp++; /* putc may evalualte arguments more than once */ + char *cp; + char *cpend; + LINE *lp; + LINE *lpend; + + lpend = bp->b_linep; + lp = lforw(lpend); + do { + cp = <ext(lp)[0]; /* begining of line */ + cpend = &cp[llength(lp)]; /* end of line */ + while (cp != cpend) { + putc(*cp, ffp); + cp++; /* putc may evaluate arguments + more than once */ + } + lp = lforw(lp); + if (lp == lpend) + break; /* no implied \n on last line */ + putc('\n', ffp); + } while (!ferror(ffp)); + if (ferror(ffp)) { + ewprintf("Write I/O error"); + return FIOERR; } - lp = lforw(lp); - if(lp == lpend) break; /* no implied newline on last line */ - putc('\n', ffp); - } while(!ferror(ffp)); - if(ferror(ffp)) { - ewprintf("Write I/O error"); - return FIOERR; - } - return FIOSUC; + return (FIOSUC); } /* @@ -102,25 +118,27 @@ BUFFER *bp; * line. When FIOEOF is returned, there is a valid line * of data without the normally implied \n. */ +int ffgetline(buf, nbuf, nbytes) -register char *buf; -register int nbuf; -register int *nbytes; + char *buf; + int nbuf; + int *nbytes; { - register int c; - register int i; + int c; + int i; i = 0; - while((c = getc(ffp))!=EOF && c!='\n') { + while ((c = getc(ffp)) != EOF && c != '\n') { buf[i++] = c; - if (i >= nbuf) return FIOLONG; + if (i >= nbuf) + return FIOLONG; } - if (c == EOF && ferror(ffp) != FALSE) { + if (c == EOF && ferror(ffp) != FALSE) { ewprintf("File read error"); return FIOERR; } *nbytes = i; - return c==EOF ? FIOEOF : FIOSUC; + return c == EOF ? FIOEOF : FIOSUC; } #ifndef NO_BACKUP @@ -133,13 +151,13 @@ register int *nbytes; * right thing here; I don't care that much as * I don't enable backups myself. */ -fbackupfile(fn) char *fn; { - register char *nname; - char *malloc(), *strrchr(); - int i; - char *lastpart; +int +fbackupfile(fn) + char *fn; +{ + char *nname; - if ((nname=malloc((unsigned)(strlen(fn)+1+1))) == NULL) { + if ((nname = malloc((unsigned) (strlen(fn) + 1 + 1))) == NULL) { ewprintf("Can't get %d bytes", strlen(fn) + 1); return (ABORT); } @@ -169,116 +187,125 @@ fbackupfile(fn) char *fn; { #endif #include <pwd.h> #ifndef NO_DIR -extern char *wdir; +extern char *wdir; #endif -char *adjustname(fn) -register char *fn; +char * +adjustname(fn) + char *fn; { - register char *cp; - static char fnb[NFILEN]; - struct passwd *pwent; + char *cp; + static char fnb[NFILEN]; + struct passwd *pwent; #ifdef SYMBLINK - struct stat statbuf; - int i, j; - char linkbuf[NFILEN]; + struct stat statbuf; + int i, j; + char linkbuf[NFILEN]; #endif - switch(*fn) { - case '/': - cp = fnb; - *cp++ = *fn++; - break; - case '~': - fn++; - if(*fn == '/' || *fn == '\0') { - (VOID) strcpy(fnb, getenv("HOME")); - cp = fnb + strlen(fnb); - if(*fn) fn++; - break; - } else { + switch (*fn) { + case '/': cp = fnb; - while(*fn && *fn != '/') *cp++ = *fn++; - *cp = '\0'; - if((pwent = getpwnam(fnb)) != NULL) { - (VOID) strcpy(fnb, pwent->pw_dir); - cp = fnb + strlen(fnb); - break; + *cp++ = *fn++; + break; + case '~': + fn++; + if (*fn == '/' || *fn == '\0') { + (VOID) strcpy(fnb, getenv("HOME")); + cp = fnb + strlen(fnb); + if (*fn) + fn++; + break; } else { - fn -= strlen(fnb) + 1; - /* can't find ~user, continue to default case */ + cp = fnb; + while (*fn && *fn != '/') + *cp++ = *fn++; + *cp = '\0'; + if ((pwent = getpwnam(fnb)) != NULL) { + (VOID) strcpy(fnb, pwent->pw_dir); + cp = fnb + strlen(fnb); + break; + } else { + fn -= strlen(fnb) + 1; + /* can't find ~user, continue to default case */ + } } - } default: #ifndef NODIR - strcpy(fnb, wdir); - cp = fnb + strlen(fnb); - break; + strcpy(fnb, wdir); + cp = fnb + strlen(fnb); + break; #else - return fn; /* punt */ + return fn; /* punt */ #endif - } - if(cp != fnb && cp[-1] != '/') *cp++ = '/'; - while(*fn) { - switch(*fn) { - case '.': - switch(fn[1]) { - case '\0': - *--cp = '\0'; - return fnb; - case '/': - fn += 2; - continue; - case '.': - if(fn[2]=='/' || fn[2] == '\0') { + } + if (cp != fnb && cp[-1] != '/') + *cp++ = '/'; + while (*fn) { + switch (*fn) { + case '.': + switch (fn[1]) { + case '\0': + *--cp = '\0'; + return fnb; + case '/': + fn += 2; + continue; + case '.': + if (fn[2] != '/' && fn[2] != '\0') + break; #ifdef SYMBLINK - cp[-1] = '\0'; - for(j = MAXLINK; j-- && - lstat(fnb, &statbuf) != -1 && - (statbuf.st_mode&S_IFMT) == S_IFLNK && - (i = readlink(fnb, linkbuf, sizeof linkbuf)) - != -1 ;) { - if(linkbuf[0] != '/') { - --cp; - while(cp > fnb && *--cp != '/') {} - ++cp; - (VOID) strncpy(cp, linkbuf, i); - cp += i; - } else { - (VOID) strncpy(fnb, linkbuf, i); - cp = fnb + i; + cp[-1] = '\0'; + for (j = MAXLINK; j-- && + lstat(fnb, &statbuf) != -1 && + (statbuf.st_mode & S_IFMT) == S_IFLNK && + (i = readlink(fnb, linkbuf, sizeof linkbuf)) + != -1;) { + if (linkbuf[0] != '/') { + --cp; + while (cp > fnb && *--cp != '/') { + } + ++cp; + (VOID) strncpy(cp, linkbuf, i); + cp += i; + } else { + (VOID) strncpy(fnb, linkbuf, i); + cp = fnb + i; + } + if (cp[-1] != '/') + *cp++ = '\0'; + else + cp[-1] = '\0'; } - if(cp[-1]!='/') *cp++ = '\0'; - else cp[-1] = '\0'; - } - cp[-1] = '/'; + cp[-1] = '/'; #endif - --cp; - while(cp > fnb && *--cp != '/') {} - ++cp; - if(fn[2]=='\0') { - *--cp = '\0'; - return fnb; - } - fn += 3; - continue; - } - break; - default: - break; - } - break; - case '/': - fn++; - continue; - default: - break; + --cp; + while (cp > fnb && *--cp != '/') { + } + ++cp; + if (fn[2] == '\0') { + *--cp = '\0'; + return fnb; + } + fn += 3; + continue; + default: + break; + } + break; + case '/': + fn++; + continue; + default: + break; + } + while (*fn && (*cp++ = *fn++) != '/') { + } } - while(*fn && (*cp++ = *fn++) != '/') {} - } - if(cp[-1]=='/') --cp; - *cp = '\0'; - return fnb; + if (cp[-1] == '/') + --cp; + *cp = '\0'; + return fnb; } #ifndef NO_STARTUP @@ -292,20 +319,23 @@ register char *fn; */ char * startupfile(suffix) -char *suffix; + char *suffix; { - register char *file; - static char home[NFILEN]; + char *file; + static char home[NFILEN]; - if ((file = getenv("HOME")) == NULL) goto notfound; - if (strlen(file)+7 >= NFILEN - 1) goto notfound; + if ((file = getenv("HOME")) == NULL) + goto notfound; + if (strlen(file) + 7 >= NFILEN - 1) + goto notfound; (VOID) strcpy(home, file); (VOID) strcat(home, "/.mg"); if (suffix != NULL) { (VOID) strcat(home, "-"); (VOID) strcat(home, suffix); } - if (access(home, F_OK) == 0) return home; + if (access(home, F_OK) == 0) + return home; notfound: #ifdef STARTUPFILE @@ -316,7 +346,8 @@ notfound: (VOID) strcat(home, suffix); file = home; } - if (access(file, F_OK ) == 0) return file; + if (access(file, F_OK) == 0) + return file; #endif return NULL; @@ -327,92 +358,98 @@ notfound: #include <sys/wait.h> #include "kbd.h" +int copy(frname, toname) -char *frname, *toname; + char *frname; + char *toname; { - pid_t pid; - int status; - - if(pid = vfork()) { - if(pid == -1) return -1; - execl("/bin/cp", "cp", frname, toname, (char *)NULL); - _exit(1); /* shouldn't happen */ - } - while(wait(&status) != pid) - ; - return status == 0; + pid_t pid; + int status; + + if ((pid = vfork())) { + if (pid == -1) + return -1; + execl("/bin/cp", "cp", frname, toname, (char *) NULL); + _exit(1); /* shouldn't happen */ + } + while (wait(&status) != pid); + return status == 0; } -BUFFER *dired_(dirname) -char *dirname; +BUFFER * +dired_(dirname) + char *dirname; { - register BUFFER *bp; - char line[256]; - BUFFER *findbuffer(); - FILE *dirpipe; - FILE *popen(); - char *strncpy(); - - if((dirname = adjustname(dirname)) == NULL) { - ewprintf("Bad directory name"); - return NULL; - } - if(dirname[strlen(dirname)-1] != '/') (VOID) strcat(dirname, "/"); - if((bp = findbuffer(dirname)) == NULL) { - ewprintf("Could not create buffer"); - return NULL; - } - if(bclear(bp) != TRUE) return FALSE; - (VOID) strcpy(line, "ls -al "); - (VOID) strcpy(&line[7], dirname); - if((dirpipe = popen(line, "r")) == NULL) { - ewprintf("Problem opening pipe to ls"); - return NULL; - } - line[0] = line[1] = ' '; - while(fgets(&line[2], 254, dirpipe) != NULL) { - line[strlen(line) - 1] = '\0'; /* remove ^J */ - (VOID) addline(bp, line); - } - if(pclose(dirpipe) == -1) { - ewprintf("Problem closing pipe to ls"); - return NULL; - } - bp->b_dotp = lforw(bp->b_linep); /* go to first line */ - (VOID) strncpy(bp->b_fname, dirname, NFILEN); - if((bp->b_modes[0] = name_mode("dired")) == NULL) { - bp->b_modes[0] = &map_table[0]; - ewprintf("Could not find mode dired"); - return NULL; - } - bp->b_nmodes = 0; - return bp; + BUFFER *bp; + FILE *dirpipe; + char line[256]; + + if ((dirname = adjustname(dirname)) == NULL) { + ewprintf("Bad directory name"); + return NULL; + } + if (dirname[strlen(dirname) - 1] != '/') + (VOID) strcat(dirname, "/"); + if ((bp = findbuffer(dirname)) == NULL) { + ewprintf("Could not create buffer"); + return NULL; + } + if (bclear(bp) != TRUE) + return FALSE; + (VOID) strcpy(line, "ls -al "); + (VOID) strcpy(&line[7], dirname); + if ((dirpipe = popen(line, "r")) == NULL) { + ewprintf("Problem opening pipe to ls"); + return NULL; + } + line[0] = line[1] = ' '; + while (fgets(&line[2], 254, dirpipe) != NULL) { + line[strlen(line) - 1] = '\0'; /* remove ^J */ + (VOID) addline(bp, line); + } + if (pclose(dirpipe) == -1) { + ewprintf("Problem closing pipe to ls"); + return NULL; + } + bp->b_dotp = lforw(bp->b_linep); /* go to first line */ + (VOID) strncpy(bp->b_fname, dirname, NFILEN); + if ((bp->b_modes[0] = name_mode("dired")) == NULL) { + bp->b_modes[0] = &map_table[0]; + ewprintf("Could not find mode dired"); + return NULL; + } + bp->b_nmodes = 0; + return bp; } +int d_makename(lp, fn) -register LINE *lp; -register char *fn; + LINE *lp; + char *fn; { - register char *cp; - - if(llength(lp) <= 56) return ABORT; - (VOID) strcpy(fn, curbp->b_fname); - cp = fn + strlen(fn); - bcopy(&lp->l_text[56], cp, llength(lp) - 56); - cp[llength(lp) - 56] = '\0'; - return lgetc(lp, 2) == 'd'; + char *cp; + + if (llength(lp) <= 56) + return ABORT; + (VOID) strcpy(fn, curbp->b_fname); + cp = fn + strlen(fn); + bcopy(&lp->l_text[56], cp, llength(lp) - 56); + cp[llength(lp) - 56] = '\0'; + return lgetc(lp, 2) == 'd'; } -#endif NO_DIRED +#endif /* NO_DIRED */ struct filelist { - LIST fl_l; - char fl_name[NFILEN+2]; + LIST fl_l; + char fl_name[NFILEN + 2]; }; -/* these things had better be contiguous, because we're going - * to refer to the end of dirbuf + 1 byte */ -struct direct dirbuf; -char dirdummy; +/* + * these things had better be contiguous, because we're going to refer to the + * end of dirbuf + 1 byte + */ +struct dirent dirbuf; +char dirdummy; /* * return list of file names that match the name in buf. @@ -422,133 +459,127 @@ char dirdummy; * for executables and directories. The list is not sorted. */ -LIST *make_file_list(buf,listing) - char *buf; - int listing; +LIST * +make_file_list(buf, listing) + char *buf; + int listing; { -char *dir,*file,*cp; -int len,i,preflen; -int fp; -LIST *last,*l1,*l2; -struct filelist *current; -char prefixx[NFILEN+1]; -extern int errno; -struct stat statbuf; -char statname[NFILEN+2]; - -/* We need three different strings: - * dir - the name of the directory containing what the user typed. - * Must be a real unix file name, e.g. no ~user, etc.. Must - * not end in /. - * prefix - the portion of what the user typed that is before - * the names we are going to find in the directory. Must have - * a trailing / if the user typed it. - * names from the directory. - * we open dir, and return prefix concatenated with names. - */ + char *dir, *file, *cp; + int len, i, preflen; + int fp; + LIST *last; + struct filelist *current; + char prefixx[NFILEN + 1]; + struct stat statbuf; + char statname[NFILEN + 2]; + + /* + * We need three different strings: dir - the name of the directory + * containing what the user typed. Must be a real unix file name, + * e.g. no ~user, etc.. Must not end in /. prefix - the portion of + * what the user typed that is before the names we are going to find + * in the directory. Must have a trailing / if the user typed it. + * names from the directory. we open dir, and return prefix + * concatenated with names. + */ -/* first we get a directory name we can look up */ -/* names ending in . are potentially odd, because adjustname - * will treat foo/.. as a reference to another directory, - * whereas we are interested in names starting with .. - */ -len = strlen(buf); -if (buf[len-1] == '.') { - buf[len-1] = 'x'; - dir = adjustname(buf); - buf[len-1] = '.'; -} -else - dir = adjustname(buf); -/* - * if the user typed a trailing / or the empty string - * he wants us to use his file spec as a directory name - */ -if (buf[0] && buf[strlen(buf)-1] != '/') { - file = strrchr(dir, '/'); - if (file) { - *file = 0; - if (*dir == 0) - dir = "/"; - } - else { - return(NULL); + /* first we get a directory name we can look up */ + /* + * Names ending in . are potentially odd, because adjustname will + * treat foo/.. as a reference to another directory, whereas we are + * interested in names starting with .. + */ + len = strlen(buf); + if (buf[len - 1] == '.') { + buf[len - 1] = 'x'; + dir = adjustname(buf); + buf[len - 1] = '.'; + } else + dir = adjustname(buf); + /* + * If the user typed a trailing / or the empty string + * he wants us to use his file spec as a directory name. + */ + if (buf[0] && buf[strlen(buf) - 1] != '/') { + file = strrchr(dir, '/'); + if (file) { + *file = 0; + if (*dir == 0) + dir = "/"; + } else { + return (NULL); + } } -} - -/* now we get the prefix of the name the user typed */ -strcpy(prefixx,buf); -cp = strrchr(prefixx, '/'); -if (cp == NULL) - prefixx[0] = 0; -else - cp[1] = 0; - -preflen = strlen(prefixx); -/* cp is the tail of buf that really needs to be compared */ -cp = buf + preflen; -len = strlen(cp); - -/* - * Now make sure that file names will fit in the buffers allocated. - * SV files are fairly short. For BSD, something more general - * would be required. - */ -if ((preflen + MAXNAMLEN) > NFILEN) - return(NULL); -if ((strlen(dir) + MAXNAMLEN) > NFILEN) - listing = 0; - -/* loop over the specified directory, making up the list of files */ - -/* - * Note that it is worth our time to filter out names that don't - * match, even though our caller is going to do so again, and to - * avoid doing the stat if completion is being done, because stat'ing - * every file in the directory is relatively expensive. - */ - -fp = open(dir,0); -if (fp < 0) { - return(NULL); -} + /* Now we get the prefix of the name the user typed. */ + strcpy(prefixx, buf); + cp = strrchr(prefixx, '/'); + if (cp == NULL) + prefixx[0] = 0; + else + cp[1] = 0; + + preflen = strlen(prefixx); + /* cp is the tail of buf that really needs to be compared */ + cp = buf + preflen; + len = strlen(cp); + + /* + * Now make sure that file names will fit in the buffers allocated. + * SV files are fairly short. For BSD, something more general would + * be required. + */ + if ((preflen + MAXNAMLEN) > NFILEN) + return (NULL); + if ((strlen(dir) + MAXNAMLEN) > NFILEN) + listing = 0; + + /* loop over the specified directory, making up the list of files */ + + /* + * Note that it is worth our time to filter out names that don't + * match, even though our caller is going to do so again, and to + * avoid doing the stat if completion is being done, because stat'ing + * every file in the directory is relatively expensive. + */ -last = NULL; -/* clear entry after last so we can treat d_name as ASCIZ */ -dirbuf.d_name[MAXNAMLEN] = 0; -while (1) { - if (read(fp, &dirbuf, sizeof(struct direct)) <= 0) { - break; + fp = open(dir, 0); + if (fp < 0) { + return (NULL); } - if (dirbuf.d_ino == 0) /* entry not allocated */ - continue; - for (i=0; i<len; ++i) { - if (cp[i] != dirbuf.d_name[i]) + last = NULL; + /* clear entry after last so we can treat d_name as ASCIZ */ + dirbuf.d_name[MAXNAMLEN] = 0; + while (1) { + if (read(fp, &dirbuf, sizeof(struct dirent)) <= 0) { break; + } + if (dirbuf.d_ino == 0) /* entry not allocated */ + continue; + for (i = 0; i < len; ++i) { + if (cp[i] != dirbuf.d_name[i]) + break; + } + if (i < len) + continue; + current = (struct filelist *) malloc(sizeof(struct filelist)); + current->fl_l.l_next = last; + current->fl_l.l_name = current->fl_name; + last = (LIST *) current; + strcpy(current->fl_name, prefixx); + strcat(current->fl_name, dirbuf.d_name); + if (listing) { + statbuf.st_mode = 0; + strcpy(statname, dir); + strcat(statname, "/"); + strcat(statname, dirbuf.d_name); + stat(statname, &statbuf); + if (statbuf.st_mode & 040000) + strcat(current->fl_name, "/"); + else if (statbuf.st_mode & 0100) + strcat(current->fl_name, "*"); + } } - if (i < len) - continue; - current = (struct filelist *)malloc(sizeof(struct filelist)); - current->fl_l.l_next = last; - current->fl_l.l_name = current->fl_name; - last = (LIST *)current; - strcpy(current->fl_name,prefixx); - strcat(current->fl_name,dirbuf.d_name); - if (listing) { - statbuf.st_mode = 0; - strcpy(statname,dir); - strcat(statname,"/"); - strcat(statname,dirbuf.d_name); - stat(statname,&statbuf); - if (statbuf.st_mode & 040000) - strcat(current->fl_name,"/"); - else if (statbuf.st_mode & 0100) - strcat(current->fl_name,"*"); - } - -} -close(fp); - -return (last); + close(fp); + return (last); } diff --git a/usr.bin/mg/help.c b/usr.bin/mg/help.c index ae9268aa85a..4f70c009d86 100644 --- a/usr.bin/mg/help.c +++ b/usr.bin/mg/help.c @@ -1,4 +1,4 @@ -/* Help functions for MicroGnuEmacs 2 */ +/* Help functions for Mg 2 */ #include "def.h" @@ -8,263 +8,311 @@ #ifndef NO_MACRO #include "macro.h" #endif -extern int rescan(); + +static int showall __P((char *ind, KEYMAP *map)); +static VOID findbind __P((PF, char *, KEYMAP *)); +static VOID bindfound __P((void)); /* - * Read a key from the keyboard, and look it - * up in the keymap. Display the name of the function - * currently bound to the key. + * Read a key from the keyboard, and look it up in the keymap. + * Display the name of the function currently bound to the key. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int desckey(f, n) + int f, n; { - register KEYMAP *curmap; - register PF funct; - register char *pep; - char prompt[80]; - int c; - int m; - int i; + KEYMAP *curmap; + PF funct; + char *pep; + char prompt[80]; + int c; + int m; + int i; #ifndef NO_MACRO - if(inmacro) return TRUE; /* ignore inside keyboard macro */ + if (inmacro) + return TRUE; /* ignore inside keyboard macro */ #endif - (VOID) strcpy(prompt, "Describe key briefly: "); - pep = prompt + strlen(prompt); - key.k_count = 0; - m = curbp->b_nmodes; - curmap = curbp->b_modes[m]->p_map; - for(;;) { - for(;;) { - ewprintf("%s", prompt); - pep[-1] = ' '; - pep = keyname(pep, key.k_chars[key.k_count++] = c = getkey(FALSE)); - if((funct = doscan(curmap, c)) != prefix) break; - *pep++ = '-'; - *pep = '\0'; - curmap = ele->k_prefmap; - } - if(funct != rescan) break; - if(ISUPPER(key.k_chars[key.k_count-1])) { - funct = doscan(curmap, TOLOWER(key.k_chars[key.k_count-1])); - if(funct == prefix) { + (VOID) strcpy(prompt, "Describe key briefly: "); + pep = prompt + strlen(prompt); + key.k_count = 0; + m = curbp->b_nmodes; + curmap = curbp->b_modes[m]->p_map; + for (;;) { + for (;;) { + ewprintf("%s", prompt); + pep[-1] = ' '; + pep = keyname(pep, key.k_chars[key.k_count++] = + c = getkey(FALSE)); + if ((funct = doscan(curmap, c)) != prefix) + break; + *pep++ = '-'; + *pep = '\0'; + curmap = ele->k_prefmap; + } + if (funct != rescan) + break; + if (ISUPPER(key.k_chars[key.k_count - 1])) { + funct = doscan(curmap, + TOLOWER(key.k_chars[key.k_count - 1])); + if (funct == prefix) { + *pep++ = '-'; + *pep = '\0'; + curmap = ele->k_prefmap; + continue; + } + if (funct != rescan) + break; + } +nextmode: + if (--m < 0) + break; + curmap = curbp->b_modes[m]->p_map; + for (i = 0; i < key.k_count; i++) { + funct = doscan(curmap, key.k_chars[i]); + if (funct != prefix) { + if (i == key.k_count - 1 && funct != rescan) + goto found; + funct = rescan; + goto nextmode; + } + curmap = ele->k_prefmap; + } *pep++ = '-'; *pep = '\0'; - curmap = ele->k_prefmap; - continue; - } - if(funct != rescan) break; } -nextmode: - if(--m < 0) break; - curmap = curbp->b_modes[m]->p_map; - for(i=0; i < key.k_count; i++) { - funct = doscan(curmap, key.k_chars[i]); - if(funct != prefix) { - if(i == key.k_count - 1 && funct != rescan) goto found; - funct = rescan; - goto nextmode; - } - curmap = ele->k_prefmap; - } - *pep++ = '-'; - *pep = '\0'; - } found: - if(funct == rescan) ewprintf("%k is not bound to any function"); - else if((pep = function_name(funct)) != NULL) - ewprintf("%k runs the command %s", pep); - else ewprintf("%k is bound to an unnamed function"); - return TRUE; + if (funct == rescan) + ewprintf("%k is not bound to any function"); + else if ((pep = function_name(funct)) != NULL) + ewprintf("%k runs the command %s", pep); + else + ewprintf("%k is bound to an unnamed function"); + return TRUE; } /* - * This function creates a table, listing all - * of the command keys and their current bindings, and stores - * the table in the *help* pop-up buffer. This - * lets MicroGnuEMACS produce it's own wall chart. + * This function creates a table, listing all of the command + * keys and their current bindings, and stores the table in the + * *help* pop-up buffer. This lets Mg produce it's own wall chart. */ -static BUFFER *bp; -static char buf[80]; /* used by showall and findbind */ +static BUFFER *bp; +static char buf[80]; /* used by showall and findbind */ -/*ARGSUSED*/ +/* ARGSUSED */ +int wallchart(f, n) { - int m; - static char locbind[80] = "Local keybindings for mode "; - static int showall(); + int m; + static char locbind[80] = "Local keybindings for mode "; bp = bfind("*help*", TRUE); - if (bclear(bp) != TRUE) return FALSE; /* Clear it out. */ - for(m=curbp->b_nmodes; m > 0; m--) { - (VOID) strcpy(&locbind[27], curbp->b_modes[m]->p_name); - (VOID) strcat(&locbind[27], ":"); - if((addline(bp, locbind) == FALSE) || - (showall(buf, curbp->b_modes[m]->p_map) == FALSE) || - (addline(bp, "") == FALSE)) return FALSE; + if (bclear(bp) != TRUE) + return FALSE; /* Clear it out. */ + for (m = curbp->b_nmodes; m > 0; m--) { + (VOID) strcpy(&locbind[27], curbp->b_modes[m]->p_name); + (VOID) strcat(&locbind[27], ":"); + if ((addline(bp, locbind) == FALSE) || + (showall(buf, curbp->b_modes[m]->p_map) == FALSE) || + (addline(bp, "") == FALSE)) + return FALSE; } - if((addline(bp, "Global bindings:") == FALSE) || - (showall(buf, map_table[0].p_map) == FALSE)) return FALSE; + if ((addline(bp, "Global bindings:") == FALSE) || + (showall(buf, map_table[0].p_map) == FALSE)) + return FALSE; return popbuftop(bp); } -static int showall(ind, map) -char *ind; -KEYMAP *map; +static int +showall(ind, map) + char *ind; + KEYMAP *map; { - register MAP_ELEMENT *ele; - register int i; - PF functp; - char *cp; - char *cp2; - int last; + MAP_ELEMENT *ele; + int i; + PF functp; + char *cp; + char *cp2; + int last; - if(addline(bp, "") == FALSE) return FALSE; + if (addline(bp, "") == FALSE) + return FALSE; last = -1; - for(ele = &map->map_element[0]; ele < &map->map_element[map->map_num] ; ele++) { - if(map->map_default != rescan && ++last < ele->k_base) { - cp = keyname(ind, last); - if(last < ele->k_base - 1) { - (VOID) strcpy(cp, " .. "); - cp = keyname(cp + 4, ele->k_base - 1); + for (ele = &map->map_element[0]; ele < &map->map_element[map->map_num]; + ele++) { + if (map->map_default != rescan && ++last < ele->k_base) { + cp = keyname(ind, last); + if (last < ele->k_base - 1) { + (VOID) strcpy(cp, " .. "); + cp = keyname(cp + 4, ele->k_base - 1); + } + do { + *cp++ = ' '; + } while (cp < &buf[16]); + (VOID) strcpy(cp, function_name(map->map_default)); + if (addline(bp, buf) == FALSE) + return FALSE; } - do { *cp++ = ' '; } while(cp < &buf[16]); - (VOID) strcpy(cp, function_name(map->map_default)); - if(addline(bp, buf) == FALSE) return FALSE; - } - last = ele->k_num; - for(i=ele->k_base; i <= last; i++) { - functp = ele->k_funcp[i - ele->k_base]; - if(functp != rescan) { - if(functp != prefix) cp2 = function_name(functp); - else cp2 = map_name(ele->k_prefmap); - if(cp2 != NULL) { - cp = keyname(ind, i); - do { *cp++ = ' '; } while(cp < &buf[16]); - (VOID) strcpy(cp, cp2); - if (addline(bp, buf) == FALSE) return FALSE; - } + last = ele->k_num; + for (i = ele->k_base; i <= last; i++) { + functp = ele->k_funcp[i - ele->k_base]; + if (functp != rescan) { + if (functp != prefix) + cp2 = function_name(functp); + else + cp2 = map_name(ele->k_prefmap); + if (cp2 != NULL) { + cp = keyname(ind, i); + do { + *cp++ = ' '; + } while (cp < &buf[16]); + (VOID) strcpy(cp, cp2); + if (addline(bp, buf) == FALSE) + return FALSE; + } + } } - } } - for(ele = &map->map_element[0]; ele < &map->map_element[map->map_num]; ele++) { - if(ele->k_prefmap != NULL) { - for(i = ele->k_base; ele->k_funcp[i - ele->k_base] != prefix; i++) { - if(i >= ele->k_num) /* damaged map */ - return FALSE; + for (ele = &map->map_element[0]; ele < &map->map_element[map->map_num]; + ele++) { + if (ele->k_prefmap != NULL) { + for (i = ele->k_base; + ele->k_funcp[i - ele->k_base] != prefix; i++) { + if (i >= ele->k_num) /* damaged map */ + return FALSE; + } + cp = keyname(ind, i); + *cp++ = ' '; + if (showall(cp, ele->k_prefmap) == FALSE) + return FALSE; } - cp = keyname(ind, i); - *cp++ = ' '; - if(showall(cp, ele->k_prefmap) == FALSE) return FALSE; - } } return TRUE; } +int help_help(f, n) -int f, n; + int f, n; { - KEYMAP *kp; - PF funct; + KEYMAP *kp; + PF funct; - if((kp = name_map("help")) == NULL) return FALSE; - ewprintf("a b c: "); - do { - funct = doscan(kp, getkey(FALSE)); - } while(funct==NULL || funct==help_help); + if ((kp = name_map("help")) == NULL) + return FALSE; + ewprintf("a b c: "); + do { + funct = doscan(kp, getkey(FALSE)); + } while (funct == NULL || funct == help_help); #ifndef NO_MACRO - if(macrodef && macrocount < MAXMACRO) macro[macrocount-1].m_funct = funct; + if (macrodef && macrocount < MAXMACRO) + macro[macrocount - 1].m_funct = funct; #endif - return (*funct)(f, n); + return (*funct) (f, n); } -static char buf2[128]; -static char *buf2p; +static char buf2[128]; +static char *buf2p; -/*ARGSUSED*/ +/* ARGSUSED */ +int apropos_command(f, n) -int f, n; + int f, n; { - register char *cp1, *cp2; - char string[32]; - FUNCTNAMES *fnp; - BUFFER *bp; - static VOID findbind(); + char *cp1, *cp2; + char string[32]; + FUNCTNAMES *fnp; + BUFFER *bp; - if(eread("apropos: ", string, sizeof(string), EFNEW) == ABORT) return ABORT; + if (eread("apropos: ", string, sizeof(string), EFNEW) == ABORT) + return ABORT; /* FALSE means we got a 0 character string, which is fine */ - bp = bfind("*help*", TRUE); - if(bclear(bp) == FALSE) return FALSE; - for(fnp = &functnames[0]; fnp < &functnames[nfunct]; fnp++) { - for(cp1 = fnp->n_name; *cp1; cp1++) { - cp2 = string; - while(*cp2 && *cp1 == *cp2) - cp1++, cp2++; - if(!*cp2) { - (VOID) strcpy(buf2, fnp->n_name); - buf2p = &buf2[strlen(buf2)]; - findbind(fnp->n_funct, buf, map_table[0].p_map); - if(addline(bp, buf2) == FALSE) return FALSE; - break; - } else cp1 -= cp2 - string; + bp = bfind("*help*", TRUE); + if (bclear(bp) == FALSE) + return FALSE; + for (fnp = &functnames[0]; fnp < &functnames[nfunct]; fnp++) { + for (cp1 = fnp->n_name; *cp1; cp1++) { + cp2 = string; + while (*cp2 && *cp1 == *cp2) + cp1++, cp2++; + if (!*cp2) { + (VOID) strcpy(buf2, fnp->n_name); + buf2p = &buf2[strlen(buf2)]; + findbind(fnp->n_funct, buf, map_table[0].p_map); + if (addline(bp, buf2) == FALSE) + return FALSE; + break; + } else + cp1 -= cp2 - string; + } } - } - return popbuftop(bp); + return popbuftop(bp); } -static VOID findbind(funct, ind, map) -PF funct; -char *ind; -KEYMAP *map; +static VOID +findbind(funct, ind, map) + PF funct; + char *ind; + KEYMAP *map; { - register MAP_ELEMENT *ele; - register int i; - char *cp; - int last; - static VOID bindfound(); + MAP_ELEMENT *ele; + int i; + char *cp; + int last; - last = -1; - for(ele = &map->map_element[0]; ele < &map->map_element[map->map_num]; ele++) { - if(map->map_default == funct && ++last < ele->k_base) { - cp = keyname(ind, last); - if(last < ele->k_base - 1) { - (VOID) strcpy(cp, " .. "); - (VOID) keyname(cp + 4, ele->k_base - 1); - } - bindfound(); - } - last = ele->k_num; - for(i=ele->k_base; i <= last; i++) { - if(funct == ele->k_funcp[i - ele->k_base]) { - if(funct == prefix) { - cp = map_name(ele->k_prefmap); - if(!cp || strncmp(cp, buf2, strlen(cp)) != 0) continue; + last = -1; + for (ele = &map->map_element[0]; ele < &map->map_element[map->map_num]; + ele++) { + if (map->map_default == funct && ++last < ele->k_base) { + cp = keyname(ind, last); + if (last < ele->k_base - 1) { + (VOID) strcpy(cp, " .. "); + (VOID) keyname(cp + 4, ele->k_base - 1); + } + bindfound(); + } + last = ele->k_num; + for (i = ele->k_base; i <= last; i++) { + if (funct == ele->k_funcp[i - ele->k_base]) { + if (funct == prefix) { + cp = map_name(ele->k_prefmap); + if (!cp || + strncmp(cp, buf2, strlen(cp)) != 0) + continue; + } + (VOID) keyname(ind, i); + bindfound(); + } } - (VOID) keyname(ind, i); - bindfound(); - } } - } - for(ele = &map->map_element[0]; ele < &map->map_element[map->map_num]; ele++) { - if(ele->k_prefmap != NULL) { - for(i = ele->k_base; ele->k_funcp[i - ele->k_base] != prefix; i++) { - if(i >= ele->k_num) return; /* damaged */ - } - cp = keyname(ind, i); - *cp++ = ' '; - findbind(funct, cp, ele->k_prefmap); + for (ele = &map->map_element[0]; ele < &map->map_element[map->map_num]; + ele++) { + if (ele->k_prefmap != NULL) { + for (i = ele->k_base; + ele->k_funcp[i - ele->k_base] != prefix; i++) { + if (i >= ele->k_num) + return; /* damaged */ + } + cp = keyname(ind, i); + *cp++ = ' '; + findbind(funct, cp, ele->k_prefmap); + } } - } } -static VOID bindfound() { - if(buf2p < &buf2[32]) { - do { *buf2p++ = ' '; } while(buf2p < &buf2[32]); - } else { - *buf2p++ = ','; - *buf2p++ = ' '; - } - (VOID) strcpy(buf2p, buf); - buf2p += strlen(buf); +static VOID +bindfound() +{ + + if (buf2p < &buf2[32]) { + do { + *buf2p++ = ' '; + } while (buf2p < &buf2[32]); + } else { + *buf2p++ = ','; + *buf2p++ = ' '; + } + (VOID) strcpy(buf2p, buf); + buf2p += strlen(buf); } #endif diff --git a/usr.bin/mg/kbd.c b/usr.bin/mg/kbd.c index 3c2dd86da0c..72be336b622 100644 --- a/usr.bin/mg/kbd.c +++ b/usr.bin/mg/kbd.c @@ -16,29 +16,39 @@ #define METABIT 0x80 #endif -int use_metakey = TRUE; +int use_metakey = TRUE; /* * Toggle the value of use_metakey */ +int do_meta(f, n) + int f, n; { - if(f & FFARG) use_metakey = n > 0; - else use_metakey = !use_metakey; + + if (f & FFARG) + use_metakey = n > 0; + else + use_metakey = !use_metakey; ewprintf("Meta keys %sabled", use_metakey ? "en" : "dis"); return TRUE; } #endif #ifdef BSMAP -static int bs_map = BSMAP; +static int bs_map = BSMAP; /* * Toggle backspace mapping */ +int bsmap(f, n) + int f, n; { - if(f & FFARG) bs_map = n > 0; - else bs_map = ! bs_map; + + if (f & FFARG) + bs_map = n > 0; + else + bs_map = !bs_map; ewprintf("Backspace mapping %sabled", bs_map ? "en" : "dis"); return TRUE; } @@ -46,60 +56,67 @@ bsmap(f, n) #ifndef NO_DPROMPT #define PROMPTL 80 - char prompt[PROMPTL], *promptp; +char prompt[PROMPTL], *promptp; #endif -static int pushed = FALSE; -static int pushedc; +static int pushed = FALSE; +static int pushedc; -VOID ungetkey(c) -int c; +VOID +ungetkey(c) + int c; { + #ifdef DO_METAKEY - if(use_metakey && pushed && c==CCHR('[')) pushedc |= METABIT; + if (use_metakey && pushed && c == CCHR('[')) + pushedc |= METABIT; else #endif pushedc = c; pushed = TRUE; } -int getkey(flag) -int flag; +int +getkey(flag) + int flag; { - int c; - char *keyname(); + int c; #ifndef NO_DPROMPT - if(flag && !pushed) { - if(prompt[0]!='\0' && ttwait()) { + if (flag && !pushed) { + if (prompt[0] != '\0' && ttwait()) { ewprintf("%s", prompt); /* avoid problems with % */ - update(); /* put the cursor back */ + update(); /* put the cursor back */ epresf = KPROMPT; } - if(promptp > prompt) *(promptp-1) = ' '; + if (promptp > prompt) + *(promptp - 1) = ' '; } #endif - if(pushed) { + if (pushed) { c = pushedc; pushed = FALSE; - } else c = getkbd(); + } else + c = getkbd(); #ifdef BSMAP - if(bs_map) - if(c==CCHR('H')) c=CCHR('?'); - else if(c==CCHR('?')) c=CCHR('H'); -#endif + if (bs_map) + if (c == CCHR('H')) + c = CCHR('?'); + else if (c == CCHR('?')) + c = CCHR('H'); +#endif #ifdef DO_METAKEY - if(use_metakey && (c&METABIT)) { + if (use_metakey && (c & METABIT)) { pushedc = c & ~METABIT; pushed = TRUE; c = CCHR('['); } #endif #ifndef NO_DPROMPT - if(flag && promptp < &prompt[PROMPTL - 5]) { - promptp = keyname(promptp, c); - *promptp++ = '-'; - *promptp = '\0'; + if (flag && promptp < &prompt[PROMPTL - 5]) { + promptp = keyname(promptp, c); + *promptp++ = '-'; + *promptp = '\0'; } #endif return c; @@ -111,281 +128,313 @@ int flag; * keymap element the keyboard was found in as a side effect. */ -MAP_ELEMENT *ele; +MAP_ELEMENT *ele; -PF doscan(map, c) -register KEYMAP *map; -register int c; +PF +doscan(map, c) + KEYMAP *map; + int c; { - register MAP_ELEMENT *elec = &map->map_element[0]; /* local register copy for faster access */ - register MAP_ELEMENT *last = &map->map_element[map->map_num]; - - while(elec < last && c > elec->k_num) elec++; - ele = elec; /* used by prefix and binding code */ - if(elec >= last || c < elec->k_base) - return map->map_default; - return elec->k_funcp[c - elec->k_base]; + MAP_ELEMENT *elec = &map->map_element[0]; + MAP_ELEMENT *last = &map->map_element[map->map_num]; + + while (elec < last && c > elec->k_num) + elec++; + ele = elec; /* used by prefix and binding code */ + if (elec >= last || c < elec->k_base) + return map->map_default; + return elec->k_funcp[c - elec->k_base]; } +int doin() { - KEYMAP *curmap; - PF funct; + KEYMAP *curmap; + PF funct; #ifndef NO_DPROMPT - *(promptp = prompt) = '\0'; + *(promptp = prompt) = '\0'; #endif - curmap = curbp->b_modes[curbp->b_nmodes]->p_map; - key.k_count = 0; - while((funct=doscan(curmap,(key.k_chars[key.k_count++]=getkey(TRUE)))) - == prefix) - curmap = ele->k_prefmap; + curmap = curbp->b_modes[curbp->b_nmodes]->p_map; + key.k_count = 0; + while ((funct = doscan(curmap, (key.k_chars[key.k_count++] = + getkey(TRUE)))) == prefix) + curmap = ele->k_prefmap; #ifndef NO_MACRO - if(macrodef && macrocount < MAXMACRO) - macro[macrocount++].m_funct = funct; + if (macrodef && macrocount < MAXMACRO) + macro[macrocount++].m_funct = funct; #endif - return (*funct)(0, 1); + return (*funct) (0, 1); } +int rescan(f, n) -int f, n; + int f, n; { - int c; - register KEYMAP *curmap; - int i; - PF fp; - int mode = curbp->b_nmodes; - - for(;;) { - if(ISUPPER(key.k_chars[key.k_count-1])) { - c = TOLOWER(key.k_chars[key.k_count-1]); - curmap = curbp->b_modes[mode]->p_map; - for(i=0; i < key.k_count-1; i++) { - if((fp=doscan(curmap,(key.k_chars[i]))) != prefix) break; - curmap = ele->k_prefmap; - } - if(fp==prefix) { - if((fp = doscan(curmap, c)) == prefix) - while((fp=doscan(curmap,key.k_chars[key.k_count++] = - getkey(TRUE))) == prefix) - curmap = ele->k_prefmap; - if(fp!=rescan) { + int c; + KEYMAP *curmap; + int i; + PF fp; + int mode = curbp->b_nmodes; + + for (;;) { + if (ISUPPER(key.k_chars[key.k_count - 1])) { + c = TOLOWER(key.k_chars[key.k_count - 1]); + curmap = curbp->b_modes[mode]->p_map; + for (i = 0; i < key.k_count - 1; i++) { + if ((fp = doscan(curmap, (key.k_chars[i]))) != prefix) + break; + curmap = ele->k_prefmap; + } + if (fp == prefix) { + if ((fp = doscan(curmap, c)) == prefix) + while ((fp = doscan(curmap, + key.k_chars[key.k_count++] = + getkey(TRUE))) == prefix) + curmap = ele->k_prefmap; + if (fp != rescan) { #ifndef NO_MACRO - if(macrodef && macrocount <= MAXMACRO) - macro[macrocount-1].m_funct = fp; + if (macrodef && macrocount <= MAXMACRO) + macro[macrocount - 1].m_funct = fp; #endif - return (*fp)(f, n); + return (*fp) (f, n); + } + } } - } - } - /* try previous mode */ - if(--mode < 0) return ABORT; - curmap = curbp->b_modes[mode]->p_map; - for(i=0; i < key.k_count; i++) { - if((fp=doscan(curmap,(key.k_chars[i]))) != prefix) break; - curmap = ele->k_prefmap; - } - if(fp==prefix) { - while((fp=doscan(curmap,key.k_chars[i++]=getkey(TRUE))) - == prefix) - curmap = ele->k_prefmap; - key.k_count = i; - } - if(fp!=rescan && i>=key.k_count-1) { + /* try previous mode */ + if (--mode < 0) + return ABORT; + curmap = curbp->b_modes[mode]->p_map; + for (i = 0; i < key.k_count; i++) { + if ((fp = doscan(curmap, (key.k_chars[i]))) != prefix) + break; + curmap = ele->k_prefmap; + } + if (fp == prefix) { + while ((fp = doscan(curmap, key.k_chars[i++] = getkey(TRUE))) + == prefix) + curmap = ele->k_prefmap; + key.k_count = i; + } + if (fp != rescan && i >= key.k_count - 1) { #ifndef NO_MACRO - if(macrodef && macrocount <= MAXMACRO) - macro[macrocount-1].m_funct = fp; + if (macrodef && macrocount <= MAXMACRO) + macro[macrocount - 1].m_funct = fp; #endif - return (*fp)(f, n); + return (*fp) (f, n); + } } - } } +int universal_argument(f, n) -int f, n; + int f, n; { - int c, nn=4; - KEYMAP *curmap; - PF funct; + int c, nn = 4; + KEYMAP *curmap; + PF funct; - if(f&FFUNIV) nn *= n; - for(;;) { - key.k_chars[0] = c = getkey(TRUE); - key.k_count = 1; - if(c == '-') return negative_argument(f, nn); - if(c >= '0' && c <= '9') return digit_argument(f, nn); - curmap = curbp->b_modes[curbp->b_nmodes]->p_map; - while((funct=doscan(curmap,c)) == prefix) { - curmap = ele->k_prefmap; - key.k_chars[key.k_count++] = c = getkey(TRUE); - } - if(funct != universal_argument) { + if (f & FFUNIV) + nn *= n; + for (;;) { + key.k_chars[0] = c = getkey(TRUE); + key.k_count = 1; + if (c == '-') + return negative_argument(f, nn); + if (c >= '0' && c <= '9') + return digit_argument(f, nn); + curmap = curbp->b_modes[curbp->b_nmodes]->p_map; + while ((funct = doscan(curmap, c)) == prefix) { + curmap = ele->k_prefmap; + key.k_chars[key.k_count++] = c = getkey(TRUE); + } + if (funct != universal_argument) { #ifndef NO_MACRO - if(macrodef && macrocount < MAXMACRO-1) { - if(f&FFARG) macrocount--; - macro[macrocount++].m_count = nn; - macro[macrocount++].m_funct = funct; - } + if (macrodef && macrocount < MAXMACRO - 1) { + if (f & FFARG) + macrocount--; + macro[macrocount++].m_count = nn; + macro[macrocount++].m_funct = funct; + } #endif - return (*funct)(FFUNIV, nn); + return (*funct) (FFUNIV, nn); + } + nn <<= 2; } - nn <<= 2; - } } -/*ARGSUSED*/ +/* ARGSUSED */ +int digit_argument(f, n) -int f, n; + int f, n; { - int nn, c; - KEYMAP *curmap; - PF funct; - - nn = key.k_chars[key.k_count-1] - '0'; - for(;;) { - c = getkey(TRUE); - if(c < '0' || c > '9') break; - nn *= 10; - nn += c - '0'; - } - key.k_chars[0] = c; - key.k_count = 1; - curmap = curbp->b_modes[curbp->b_nmodes]->p_map; - while((funct=doscan(curmap,c)) == prefix) { - curmap = ele->k_prefmap; - key.k_chars[key.k_count++] = c = getkey(TRUE); - } + int nn, c; + KEYMAP *curmap; + PF funct; + + nn = key.k_chars[key.k_count - 1] - '0'; + for (;;) { + c = getkey(TRUE); + if (c < '0' || c > '9') + break; + nn *= 10; + nn += c - '0'; + } + key.k_chars[0] = c; + key.k_count = 1; + curmap = curbp->b_modes[curbp->b_nmodes]->p_map; + while ((funct = doscan(curmap, c)) == prefix) { + curmap = ele->k_prefmap; + key.k_chars[key.k_count++] = c = getkey(TRUE); + } #ifndef NO_MACRO - if(macrodef && macrocount < MAXMACRO-1) { - if(f&FFARG) macrocount--; - else macro[macrocount-1].m_funct = universal_argument; - macro[macrocount++].m_count = nn; - macro[macrocount++].m_funct = funct; - } + if (macrodef && macrocount < MAXMACRO - 1) { + if (f & FFARG) + macrocount--; + else + macro[macrocount - 1].m_funct = universal_argument; + macro[macrocount++].m_count = nn; + macro[macrocount++].m_funct = funct; + } #endif - return (*funct)(FFOTHARG, nn); + return (*funct) (FFOTHARG, nn); } +int negative_argument(f, n) -int f, n; + int f, n; { - int nn = 0, c; - KEYMAP *curmap; - PF funct; - - for(;;) { - c = getkey(TRUE); - if(c < '0' || c > '9') break; - nn *= 10; - nn += c - '0'; - } - if(nn) nn = -nn; - else nn = -n; - key.k_chars[0] = c; - key.k_count = 1; - curmap = curbp->b_modes[curbp->b_nmodes]->p_map; - while((funct=doscan(curmap,c)) == prefix) { - curmap = ele->k_prefmap; - key.k_chars[key.k_count++] = c = getkey(TRUE); - } + int nn = 0, c; + KEYMAP *curmap; + PF funct; + + for (;;) { + c = getkey(TRUE); + if (c < '0' || c > '9') + break; + nn *= 10; + nn += c - '0'; + } + if (nn) + nn = -nn; + else + nn = -n; + key.k_chars[0] = c; + key.k_count = 1; + curmap = curbp->b_modes[curbp->b_nmodes]->p_map; + while ((funct = doscan(curmap, c)) == prefix) { + curmap = ele->k_prefmap; + key.k_chars[key.k_count++] = c = getkey(TRUE); + } #ifndef NO_MACRO - if(macrodef && macrocount < MAXMACRO-1) { - if(f&FFARG) macrocount--; - else macro[macrocount-1].m_funct = universal_argument; - macro[macrocount++].m_count = nn; - macro[macrocount++].m_funct = funct; - } + if (macrodef && macrocount < MAXMACRO - 1) { + if (f & FFARG) + macrocount--; + else + macro[macrocount - 1].m_funct = universal_argument; + macro[macrocount++].m_count = nn; + macro[macrocount++].m_funct = funct; + } #endif - return (*funct)(FFNEGARG, nn); + return (*funct) (FFNEGARG, nn); } /* * Insert a character. While defining a macro, create a "LINE" containing * all inserted characters. */ - +int selfinsert(f, n) -int f, n; + int f, n; { - register int c; - int count; - VOID lchange(); + int c; + int count; #ifndef NO_MACRO - LINE *lp; - int insert(); + LINE *lp; #endif - if (n < 0) return FALSE; - if (n == 0) return TRUE; - c = key.k_chars[key.k_count-1]; + if (n < 0) + return FALSE; + if (n == 0) + return TRUE; + c = key.k_chars[key.k_count - 1]; #ifndef NO_MACRO - if(macrodef && macrocount < MAXMACRO) { - if(f & FFARG) macrocount -= 2; - if(lastflag & CFINS) { /* last command was insert -- tack on end */ - macrocount--; - if(maclcur->l_size < maclcur->l_used + n) { - if((lp = lallocx(maclcur->l_used + n)) == NULL) - return FALSE; - lp->l_fp = maclcur->l_fp; - lp->l_bp = maclcur->l_bp; - lp->l_fp->l_bp = lp->l_bp->l_fp = lp; - bcopy(maclcur->l_text, lp->l_text, maclcur->l_used); - for(count = maclcur->l_used; count < lp->l_used; count++) - lp->l_text[count] = c; - free((char *)maclcur); - maclcur = lp; - } else { - maclcur->l_used += n; - for(count = maclcur->l_used-n; count < maclcur->l_used; count++) - maclcur->l_text[count] = c; - } - } else { - macro[macrocount-1].m_funct = insert; - if((lp = lallocx(n)) == NULL) return FALSE; - lp->l_bp = maclcur; - lp->l_fp = maclcur->l_fp; - maclcur->l_fp = lp; - maclcur = lp; - for(count = 0; count < n; count++) - lp->l_text[count] = c; + if (macrodef && macrocount < MAXMACRO) { + if (f & FFARG) + macrocount -= 2; + if (lastflag & CFINS) { /* last command was insert -- tack on + * end */ + macrocount--; + if (maclcur->l_size < maclcur->l_used + n) { + if ((lp = lallocx(maclcur->l_used + n)) == NULL) + return FALSE; + lp->l_fp = maclcur->l_fp; + lp->l_bp = maclcur->l_bp; + lp->l_fp->l_bp = lp->l_bp->l_fp = lp; + bcopy(maclcur->l_text, lp->l_text, maclcur->l_used); + for (count = maclcur->l_used; count < lp->l_used; count++) + lp->l_text[count] = c; + free((char *) maclcur); + maclcur = lp; + } else { + maclcur->l_used += n; + for (count = maclcur->l_used - n; + count < maclcur->l_used; count++) + maclcur->l_text[count] = c; + } + } else { + macro[macrocount - 1].m_funct = insert; + if ((lp = lallocx(n)) == NULL) + return FALSE; + lp->l_bp = maclcur; + lp->l_fp = maclcur->l_fp; + maclcur->l_fp = lp; + maclcur = lp; + for (count = 0; count < n; count++) + lp->l_text[count] = c; + } + thisflag |= CFINS; } - thisflag |= CFINS; - } #endif - if(c == '\n') { - do { - count = lnewline(); - } while (--n && count==TRUE); - return count; - } - if(curbp->b_flag & BFOVERWRITE) { /* Overwrite mode */ - lchange(WFEDIT); - while(curwp->w_doto < llength(curwp->w_dotp) && n--) - lputc(curwp->w_dotp, curwp->w_doto++, c); - if(n<=0) return TRUE; - } - return linsert(n, c); + if (c == '\n') { + do { + count = lnewline(); + } while (--n && count == TRUE); + return count; + } + if (curbp->b_flag & BFOVERWRITE) { /* Overwrite mode */ + lchange(WFEDIT); + while (curwp->w_doto < llength(curwp->w_dotp) && n--) + lputc(curwp->w_dotp, curwp->w_doto++, c); + if (n <= 0) + return TRUE; + } + return linsert(n, c); } /* - * this could be implemented as a keymap with everthing defined + * This could be implemented as a keymap with everthing defined * as self-insert. */ +int quote(f, n) + int f, n; { - register int c; - - key.k_count = 1; - if((key.k_chars[0] = getkey(TRUE)) >= '0' && key.k_chars[0] <= '7') { - key.k_chars[0] -= '0'; - if((c = getkey(TRUE)) >= '0' && c <= '7') { - key.k_chars[0] <<= 3; - key.k_chars[0] += c - '0'; - if((c = getkey(TRUE)) >= '0' && c <= '7') { - key.k_chars[0] <<= 3; - key.k_chars[0] += c - '0'; - } else ungetkey(c); - } else ungetkey(c); - } - return selfinsert(f, n); + int c; + + key.k_count = 1; + if ((key.k_chars[0] = getkey(TRUE)) >= '0' && key.k_chars[0] <= '7') { + key.k_chars[0] -= '0'; + if ((c = getkey(TRUE)) >= '0' && c <= '7') { + key.k_chars[0] <<= 3; + key.k_chars[0] += c - '0'; + if ((c = getkey(TRUE)) >= '0' && c <= '7') { + key.k_chars[0] <<= 3; + key.k_chars[0] += c - '0'; + } else + ungetkey(c); + } else + ungetkey(c); + } + return selfinsert(f, n); } diff --git a/usr.bin/mg/kbd.h b/usr.bin/mg/kbd.h index 1816fc6462c..b121f0e19a3 100644 --- a/usr.bin/mg/kbd.h +++ b/usr.bin/mg/kbd.h @@ -2,62 +2,59 @@ * kbd.h: type definitions for symbol.c and kbd.c for mg experimental */ -typedef struct { - KCHAR k_base; /* first key in element */ - KCHAR k_num; /* last key in element */ - PF *k_funcp; /* pointer to array of pointers to functions */ - struct keymap_s *k_prefmap; /* keymap of ONLY prefix key in element */ -} MAP_ELEMENT; - -/* predefined keymaps are NOT type KEYMAP because final array needs - * dimension. If any changes are made to this struct, they must be - * reflected in all keymap declarations. +typedef struct { + KCHAR k_base; /* first key in element */ + KCHAR k_num; /* last key in element */ + PF *k_funcp; /* pointer to array of pointers + * to functions */ + struct keymap_s *k_prefmap; /* keymap of ONLY prefix key in + * element */ +} MAP_ELEMENT; + +/* + * predefined keymaps are NOT type KEYMAP because final array needs + * dimension. If any changes are made to this struct, they must be reflected + * in all keymap declarations. */ -#define KEYMAPE(NUM) {\ - short map_num;\ - short map_max;\ - PF map_default;\ - MAP_ELEMENT map_element[NUM];\ +#define KEYMAPE(NUM) { \ + short map_num; /* elements used */ \ + short map_max; /* elements allocated */ \ + PF map_default; /* default function */ \ + MAP_ELEMENT map_element[NUM]; /* really [e_max] */ \ } - /* elements used */ - /* elements allocated */ - /* default function */ - /* realy [e_max] */ -typedef struct keymap_s KEYMAPE(1) KEYMAP; +typedef struct keymap_s KEYMAPE(1) KEYMAP; #define none ctrlg #define prefix (PF)NULL -/* number of map_elements to grow an overflowed keymap by */ +/* Number of map_elements to grow an overflowed keymap by */ #define IMAPEXT 0 #define MAPGROW 3 #define MAPINIT (MAPGROW+1) -/* max number of default bindings added to avoid creating new element */ +/* Max number of default bindings added to avoid creating new element */ #define MAPELEDEF 4 typedef struct MAPS_S { - KEYMAP *p_map; - char *p_name; -} MAPS; + KEYMAP *p_map; + char *p_name; +} MAPS; -extern MAPS map_table[]; +extern MAPS map_table[]; typedef struct { - PF n_funct; - char *n_name; -} FUNCTNAMES; - -extern FUNCTNAMES functnames[]; -extern int nfunct; - -extern PF doscan(); -extern PF name_function(); -extern char *function_name(); -extern int complete_function(); -extern KEYMAP *name_map(); -extern char *map_name(); -extern MAPS *name_mode(); - -extern MAP_ELEMENT *ele; + PF n_funct; + char *n_name; +} FUNCTNAMES; + +PF doscan __P((KEYMAP *, int)); +PF name_function __P((char *)); +char *function_name __P((PF)); +KEYMAP *name_map __P((char *)); +char *map_name __P((KEYMAP *)); +MAPS *name_mode __P((char *)); + +extern FUNCTNAMES functnames[]; +extern int nfunct; +extern MAP_ELEMENT *ele; diff --git a/usr.bin/mg/key.h b/usr.bin/mg/key.h index 88e8bc1f1c7..b60c36f0b35 100644 --- a/usr.bin/mg/key.h +++ b/usr.bin/mg/key.h @@ -6,8 +6,8 @@ #define MAXKEY 8 /* maximum number of prefix chars */ -EXTERN struct { /* the chacter sequence in a key */ - int k_count; /* number of chars */ - KCHAR k_chars[MAXKEY]; /* chars */ -} key; +EXTERN struct { /* the chacter sequence in a key */ + int k_count; /* number of chars */ + KCHAR k_chars[MAXKEY]; /* chars */ +} key; #undef EXTERN diff --git a/usr.bin/mg/keymap.c b/usr.bin/mg/keymap.c index 69c34e300e3..da5a1ec2724 100644 --- a/usr.bin/mg/keymap.c +++ b/usr.bin/mg/keymap.c @@ -7,292 +7,182 @@ #include "kbd.h" /* - * Defined by "basic.c". - */ -extern int gotobol(); /* Move to start of line */ -extern int backchar(); /* Move backward by characters */ -extern int gotoeol(); /* Move to end of line */ -extern int forwchar(); /* Move forward by characters */ -extern int gotobob(); /* Move to start of buffer */ -extern int gotoeob(); /* Move to end of buffer */ -extern int forwline(); /* Move forward by lines */ -extern int backline(); /* Move backward by lines */ -extern int forwpage(); /* Move forward by pages */ -extern int backpage(); /* Move backward by pages */ -extern int pagenext(); /* Page forward next window */ -extern int setmark(); /* Set mark */ -extern int swapmark(); /* Swap "." and mark */ -extern int gotoline(); /* Go to a specified line. */ -#ifdef GOSMACS -extern int forw1page(); /* move forward by lines */ -extern int back1page(); /* move back by lines */ -#endif - -/* - * Defined by "buffer.c". - */ -extern int listbuffers(); /* Display list of buffers */ -extern int usebuffer(); /* Switch a window to a buffer */ -extern int poptobuffer(); /* Other window to a buffer */ -extern int killbuffer(); /* Make a buffer go away. */ -extern int savebuffers(); /* Save unmodified buffers */ -extern int bufferinsert(); /* Insert buffer into another */ -extern int notmodified(); /* Reset modification flag */ - -#ifndef NO_DIR -/* - * Defined by "dir.c" - */ -extern int changedir(); /* change current directory */ -extern int showcwdir(); /* show current directory */ - -#ifndef NO_DIRED -/* - * defined by "dired.c" - */ -extern int dired(); /* dired */ -extern int d_findfile(); /* dired find file */ -extern int d_del(); /* dired mark for deletion */ -extern int d_undel(); /* dired unmark */ -extern int d_undelbak(); /* dired unmark backwards */ -extern int d_expunge(); /* dired expunge */ -extern int d_copy(); /* dired copy */ -extern int d_rename(); /* dired rename */ -extern int d_otherwindow(); /* dired other window */ -extern int d_ffotherwindow(); /* dired find file other window */ -#endif -#endif - -/* - * Defined by "extend.c". - */ -extern int extend(); /* Extended commands. */ -extern int bindtokey(); /* Modify global key bindings. */ -extern int localbind(); /* Modify mode key bindings. */ -extern int define_key(); /* modify any key map */ -extern int unbindtokey(); /* delete global binding */ -extern int localunbind(); /* delete local binding */ -extern int insert(); /* insert string */ -#ifndef NO_STARTUP -extern int evalexpr(); /* Extended commands (again) */ -extern int evalbuffer(); /* Evaluate current buffer */ -extern int evalfile(); /* Evaluate a file */ -#endif - -/* - * Defined by "file.c". - */ -extern int filevisit(); /* Get a file, read write */ -extern int poptofile(); /* Get a file, other window */ -extern int filewrite(); /* Write a file */ -extern int filesave(); /* Save current file */ -extern int fileinsert(); /* Insert file into buffer */ -#ifndef NO_BACKUP -extern int makebkfile(); /* Control backups on saves */ -#endif - -/* - * defined by help.c - */ -#ifndef NO_HELP -extern int desckey(); /* describe key */ -extern int wallchart(); /* Make wall chart. */ -extern int help_help(); /* help help */ -extern int apropos_command(); /* apropos */ -#endif - -/* - * defined by "kbd.c" - */ -#ifdef DO_METAKEY -extern int do_meta(); /* interpret meta keys */ -#endif -#ifdef BSMAP -extern int bsmap(); /* backspace mapping */ -#endif -extern int universal_argument(); /* Ctrl-U */ -extern int digit_argument(); /* M-1, etc. */ -extern int negative_argument(); /* M-- */ -extern int selfinsert(); /* Insert character */ -extern int rescan(); /* internal try again function */ - -/* * defined by "macro.c" */ #ifndef NO_MACRO -extern int definemacro(); /* Begin macro */ -extern int finishmacro(); /* End macro */ -extern int executemacro(); /* Execute macro */ +extern int definemacro(); /* Begin macro */ +extern int finishmacro(); /* End macro */ +extern int executemacro(); /* Execute macro */ #endif /* * Defined by "main.c". */ -extern int ctrlg(); /* Abort out of things */ -extern int quit(); /* Quit */ +extern int ctrlg(); /* Abort out of things */ +extern int quit(); /* Quit */ /* * Defined by "match.c" */ -extern int showmatch(); /* Hack to show matching paren */ +extern int showmatch(); /* Hack to show matching paren */ /* defined by "modes.c" */ -extern int indentmode(); /* set auto-indent mode */ -extern int fillmode(); /* set word-wrap mode */ -extern int blinkparen(); /* Fake blink-matching-paren var */ +extern int indentmode(); /* set auto-indent mode */ +extern int fillmode(); /* set word-wrap mode */ +extern int blinkparen(); /* Fake blink-matching-paren var */ #ifdef NOTAB -extern int notabmode(); /* no tab mode */ +extern int notabmode(); /* no tab mode */ #endif -extern int overwrite(); /* overwrite mode */ -extern int set_default_mode(); /* set default modes */ +extern int overwrite(); /* overwrite mode */ +extern int set_default_mode(); /* set default modes */ /* * defined by "paragraph.c" - the paragraph justification code. */ -extern int gotobop(); /* Move to start of paragraph. */ -extern int gotoeop(); /* Move to end of paragraph. */ -extern int fillpara(); /* Justify a paragraph. */ -extern int killpara(); /* Delete a paragraph. */ -extern int setfillcol(); /* Set fill column for justify. */ -extern int fillword(); /* Insert char with word wrap. */ +extern int gotobop(); /* Move to start of paragraph. */ +extern int gotoeop(); /* Move to end of paragraph. */ +extern int fillpara(); /* Justify a paragraph. */ +extern int killpara(); /* Delete a paragraph. */ +extern int setfillcol(); /* Set fill column for justify. */ +extern int fillword(); /* Insert char with word wrap. */ /* * Defined by "random.c". */ -extern int showcpos(); /* Show the cursor position */ -extern int twiddle(); /* Twiddle characters */ -extern int quote(); /* Insert literal */ -extern int openline(); /* Open up a blank line */ -extern int newline(); /* Insert newline */ -extern int deblank(); /* Delete blank lines */ -extern int justone(); /* Delete extra whitespace */ -extern int delwhite(); /* Delete all whitespace */ -extern int indent(); /* Insert newline, then indent */ -extern int forwdel(); /* Forward delete */ -extern int backdel(); /* Backward delete in */ -extern int killline(); /* Kill forward */ -extern int yank(); /* Yank back from killbuffer. */ +extern int showcpos(); /* Show the cursor position */ +extern int twiddle(); /* Twiddle characters */ +extern int quote(); /* Insert literal */ +extern int openline(); /* Open up a blank line */ +extern int newline(); /* Insert newline */ +extern int deblank(); /* Delete blank lines */ +extern int justone(); /* Delete extra whitespace */ +extern int delwhite(); /* Delete all whitespace */ +extern int indent(); /* Insert newline, then indent */ +extern int forwdel(); /* Forward delete */ +extern int backdel(); /* Backward delete in */ +extern int killline(); /* Kill forward */ +extern int yank(); /* Yank back from killbuffer. */ #ifdef NOTAB -extern int space_to_tabstop(); +extern int space_to_tabstop(); #endif #ifdef REGEX /* * Defined by "re_search.c" */ -extern int re_forwsearch(); /* Regex search forward */ -extern int re_backsearch(); /* Regex search backwards */ -extern int re_searchagain(); /* Repeat regex search command */ -extern int re_queryrepl(); /* Regex query replace */ -extern int setcasefold(); /* Set case fold in searches */ -extern int delmatchlines(); /* Delete all lines matching */ -extern int delnonmatchlines(); /* Delete all lines not matching */ -extern int cntmatchlines(); /* Count matching lines */ -extern int cntnonmatchlines(); /* Count nonmatching lines */ +extern int re_forwsearch();/* Regex search forward */ +extern int re_backsearch();/* Regex search backwards */ +extern int re_searchagain(); /* Repeat regex search command */ +extern int re_queryrepl(); /* Regex query replace */ +extern int setcasefold(); /* Set case fold in searches */ +extern int delmatchlines();/* Delete all lines matching */ +extern int delnonmatchlines(); /* Delete all lines not matching */ +extern int cntmatchlines();/* Count matching lines */ +extern int cntnonmatchlines(); /* Count nonmatching lines */ #endif /* * Defined by "region.c". */ -extern int killregion(); /* Kill region. */ -extern int copyregion(); /* Copy region to kill buffer. */ -extern int lowerregion(); /* Lower case region. */ -extern int upperregion(); /* Upper case region. */ +extern int killregion(); /* Kill region. */ +extern int copyregion(); /* Copy region to kill buffer. */ +extern int lowerregion(); /* Lower case region. */ +extern int upperregion(); /* Upper case region. */ #ifdef PREFIXREGION -extern int prefixregion(); /* Prefix all lines in region */ -extern int setprefix(); /* Set line prefix string */ +extern int prefixregion(); /* Prefix all lines in region */ +extern int setprefix(); /* Set line prefix string */ #endif /* * Defined by "search.c". */ -extern int forwsearch(); /* Search forward */ -extern int backsearch(); /* Search backwards */ -extern int searchagain(); /* Repeat last search command */ -extern int forwisearch(); /* Incremental search forward */ -extern int backisearch(); /* Incremental search backwards */ -extern int queryrepl(); /* Query replace */ +extern int forwsearch(); /* Search forward */ +extern int backsearch(); /* Search backwards */ +extern int searchagain(); /* Repeat last search command */ +extern int forwisearch(); /* Incremental search forward */ +extern int backisearch(); /* Incremental search backwards */ +extern int queryrepl(); /* Query replace */ /* * Defined by "spawn.c". */ -extern int spawncli(); /* Run CLI in a subjob. */ +extern int spawncli(); /* Run CLI in a subjob. */ #ifdef VMS -extern int attachtoparent(); /* Attach to parent process */ +extern int attachtoparent(); /* Attach to parent process */ #endif /* defined by "version.c" */ -extern int showversion(); /* Show version numbers, etc. */ +extern int showversion(); /* Show version numbers, etc. */ /* * Defined by "window.c". */ -extern int reposition(); /* Reposition window */ -extern int refresh(); /* Refresh the screen */ -extern int nextwind(); /* Move to the next window */ +extern int reposition(); /* Reposition window */ +extern int refresh(); /* Refresh the screen */ +extern int nextwind(); /* Move to the next window */ #ifdef GOSMACS -extern int prevwind(); /* Move to the previous window */ +extern int prevwind(); /* Move to the previous window */ #endif -extern int onlywind(); /* Make current window only one */ -extern int splitwind(); /* Split current window */ -extern int delwind(); /* Delete current window */ -extern int enlargewind(); /* Enlarge display window. */ -extern int shrinkwind(); /* Shrink window. */ +extern int onlywind(); /* Make current window only one */ +extern int splitwind(); /* Split current window */ +extern int delwind(); /* Delete current window */ +extern int enlargewind(); /* Enlarge display window. */ +extern int shrinkwind(); /* Shrink window. */ /* * Defined by "word.c". */ -extern int backword(); /* Backup by words */ -extern int forwword(); /* Advance by words */ -extern int upperword(); /* Upper case word. */ -extern int lowerword(); /* Lower case word. */ -extern int capword(); /* Initial capitalize word. */ -extern int delfword(); /* Delete forward word. */ -extern int delbword(); /* Delete backward word. */ +extern int backword(); /* Backup by words */ +extern int forwword(); /* Advance by words */ +extern int upperword(); /* Upper case word. */ +extern int lowerword(); /* Lower case word. */ +extern int capword(); /* Initial capitalize word. */ +extern int delfword(); /* Delete forward word. */ +extern int delbword(); /* Delete backward word. */ #ifdef AMIGA #ifdef DO_ICONIFY -extern int tticon(); +extern int tticon(); #endif #ifdef DO_MENU -extern int amigamenu(); /* Menu function */ +extern int amigamenu(); /* Menu function */ #endif #ifdef MOUSE -extern int amigamouse(); /* Amiga mouse functions */ -extern int mgotobob(); -extern int mforwdel(); -extern int mdelwhite(); -extern int mdelwind(); -extern int mgotoeob(); -extern int menlargewind(); -extern int mkillline(); -extern int mkillregion(); -extern int mdelfword(); -extern int mreposition(); -extern int mbackpage(); -extern int mforwpage(); -extern int mshrinkwind(); -extern int msplitwind(); -extern int myank(); -#endif MOUSE - -extern int togglewindow(); /* Defined by "ttyio.c" */ -extern int togglezooms(); /* "" "" */ +extern int amigamouse(); /* Amiga mouse functions */ +extern int mgotobob(); +extern int mforwdel(); +extern int mdelwhite(); +extern int mdelwind(); +extern int mgotoeob(); +extern int menlargewind(); +extern int mkillline(); +extern int mkillregion(); +extern int mdelfword(); +extern int mreposition(); +extern int mbackpage(); +extern int mforwpage(); +extern int mshrinkwind(); +extern int msplitwind(); +extern int myank(); +#endif /* MOUSE */ + +extern int togglewindow(); /* Defined by "ttyio.c" */ +extern int togglezooms(); /* "" "" */ #ifdef CHANGE_FONT -extern int setfont(); /* Defined by "ttyio.c" */ +extern int setfont(); /* Defined by "ttyio.c" */ #endif #ifdef CHANGE_COLOR - /* functions to mess with the mode line rendition, window colors*/ -extern int ttmode(); /* Defined by "tty.c" */ -extern int tttext(); /* "" */ -extern int textforeground(); /* "" */ -extern int textbackground(); /* "" */ -extern int modeforeground(); /* "" */ -extern int modebackground(); /* "" */ +/* functions to mess with the mode line rendition, window colors */ +extern int ttmode(); /* Defined by "tty.c" */ +extern int tttext(); /* "" */ +extern int textforeground(); /* "" */ +extern int textbackground(); /* "" */ +extern int modeforeground(); /* "" */ +extern int modebackground(); /* "" */ #endif /* @@ -303,803 +193,880 @@ extern int modebackground(); /* "" */ */ #include "amiga_maps.c" -#endif /* AMIGA */ +#endif /* AMIGA */ /* initial keymap declarations, deepest first */ #ifndef NO_HELP -static PF cHcG[] = { - ctrlg, /* ^G */ - help_help, /* ^H */ +static PF cHcG[] = { + ctrlg, /* ^G */ + help_help, /* ^H */ }; -static PF cHa[] = { - apropos_command,/* a */ - wallchart, /* b */ - desckey, /* c */ +static PF cHa[] = { + apropos_command, /* a */ + wallchart, /* b */ + desckey, /* c */ }; -static struct KEYMAPE(2+IMAPEXT) helpmap = { +static struct KEYMAPE (2 + IMAPEXT) helpmap = { 2, - 2+IMAPEXT, + 2 + IMAPEXT, rescan, { - {CCHR('G'),CCHR('H'), cHcG, (KEYMAP *)NULL}, - {'a', 'c', cHa, (KEYMAP *)NULL}, + { + CCHR('G'), CCHR('H'), cHcG, (KEYMAP *) NULL + }, + { + 'a', 'c', cHa, (KEYMAP *) NULL + }, } }; #endif -static struct KEYMAPE(1+IMAPEXT) extramap1 = { +static struct KEYMAPE (1 + IMAPEXT) extramap1 = { 0, - 1+IMAPEXT, + 1 + IMAPEXT, rescan }; -static struct KEYMAPE(1+IMAPEXT) extramap2 = { +static struct KEYMAPE (1 + IMAPEXT) extramap2 = { 0, - 1+IMAPEXT, + 1 + IMAPEXT, rescan }; -static struct KEYMAPE(1+IMAPEXT) extramap3 = { +static struct KEYMAPE (1 + IMAPEXT) extramap3 = { 0, - 1+IMAPEXT, + 1 + IMAPEXT, rescan }; -static struct KEYMAPE(1+IMAPEXT) extramap4 = { +static struct KEYMAPE (1 + IMAPEXT) extramap4 = { 0, - 1+IMAPEXT, + 1 + IMAPEXT, rescan }; -static struct KEYMAPE(1+IMAPEXT) extramap5 = { +static struct KEYMAPE (1 + IMAPEXT) extramap5 = { 0, - 1+IMAPEXT, + 1 + IMAPEXT, rescan }; -static PF cX4cF[] = { - poptofile, /* ^f */ - ctrlg, /* ^g */ +static PF cX4cF[] = { + poptofile, /* ^f */ + ctrlg, /* ^g */ }; -static PF cX4b[] = { - poptobuffer, /* b */ - rescan, /* c */ - rescan, /* d */ - rescan, /* e */ - poptofile, /* f */ +static PF cX4b[] = { + poptobuffer, /* b */ + rescan, /* c */ + rescan, /* d */ + rescan, /* e */ + poptofile, /* f */ }; -static struct KEYMAPE(2+IMAPEXT) cX4map = { +static struct KEYMAPE (2 + IMAPEXT) cX4map = { 2, - 2+IMAPEXT, + 2 + IMAPEXT, rescan, { - {CCHR('F'),CCHR('G'), cX4cF, (KEYMAP *)NULL}, - {'b', 'f', cX4b, (KEYMAP *)NULL}, + { + CCHR('F'), CCHR('G'), cX4cF, (KEYMAP *) NULL + }, + { + 'b', 'f', cX4b, (KEYMAP *) NULL + }, } }; -static PF cXcB[] = { - listbuffers, /* ^B */ - quit, /* ^C */ - rescan, /* ^D */ - rescan, /* ^E */ - filevisit, /* ^F */ - ctrlg, /* ^G */ +static PF cXcB[] = { + listbuffers, /* ^B */ + quit, /* ^C */ + rescan, /* ^D */ + rescan, /* ^E */ + filevisit, /* ^F */ + ctrlg, /* ^G */ }; -static PF cXcL[] = { - lowerregion, /* ^L */ - rescan, /* ^M */ - rescan, /* ^N */ - deblank, /* ^O */ - rescan, /* ^P */ - rescan, /* ^Q */ - rescan, /* ^R */ - filesave, /* ^S */ - rescan, /* ^T */ - upperregion, /* ^U */ - rescan, /* ^V */ - filewrite, /* ^W */ - swapmark, /* ^X */ +static PF cXcL[] = { + lowerregion, /* ^L */ + rescan, /* ^M */ + rescan, /* ^N */ + deblank, /* ^O */ + rescan, /* ^P */ + rescan, /* ^Q */ + rescan, /* ^R */ + filesave, /* ^S */ + rescan, /* ^T */ + upperregion, /* ^U */ + rescan, /* ^V */ + filewrite, /* ^W */ + swapmark, /* ^X */ }; #ifndef NO_MACRO -static PF cXlp[] = { - definemacro, /* ( */ - finishmacro, /* ) */ +static PF cXlp[] = { + definemacro, /* ( */ + finishmacro, /* ) */ }; #endif -static PF cX0[] = { - delwind, /* 0 */ - onlywind, /* 1 */ - splitwind, /* 2 */ - rescan, /* 3 */ - prefix, /* 4 */ +static PF cX0[] = { + delwind, /* 0 */ + onlywind, /* 1 */ + splitwind, /* 2 */ + rescan, /* 3 */ + prefix, /* 4 */ }; -static PF cXeq[] = { - showcpos, /* = */ +static PF cXeq[] = { + showcpos, /* = */ }; -static PF cXcar[] = { - enlargewind, /* ^ */ - rescan, /* _ */ - rescan, /* ` */ - rescan, /* a */ - usebuffer, /* b */ - rescan, /* c */ +static PF cXcar[] = { + enlargewind, /* ^ */ + rescan, /* _ */ + rescan, /* ` */ + rescan, /* a */ + usebuffer, /* b */ + rescan, /* c */ #ifndef NO_DIRED - dired, /* d */ + dired, /* d */ #else - rescan, /* d */ + rescan, /* d */ #endif #ifndef NO_MACRO - executemacro, /* e */ + executemacro, /* e */ #else - rescan, /* e */ -#endif - setfillcol, /* f */ - rescan, /* g */ - rescan, /* h */ - fileinsert, /* i */ - rescan, /* j */ - killbuffer, /* k */ - rescan, /* l */ - rescan, /* m */ - rescan, /* n */ - nextwind, /* o */ - rescan, /* p */ - rescan, /* q */ - rescan, /* r */ - savebuffers, /* s */ + rescan, /* e */ +#endif + setfillcol, /* f */ + rescan, /* g */ + rescan, /* h */ + fileinsert, /* i */ + rescan, /* j */ + killbuffer, /* k */ + rescan, /* l */ + rescan, /* m */ + rescan, /* n */ + nextwind, /* o */ + rescan, /* p */ + rescan, /* q */ + rescan, /* r */ + savebuffers, /* s */ }; #ifndef NO_MACRO -static struct KEYMAPE(6+IMAPEXT) cXmap = { +static struct KEYMAPE (6 + IMAPEXT) cXmap = { 6, - 6+IMAPEXT, + 6 + IMAPEXT, #else -static struct KEYMAPE(5+IMAPEXT) cXmap = { +static struct KEYMAPE (5 + IMAPEXT) cXmap = { 5, - 5+IMAPEXT, + 5 + IMAPEXT, #endif rescan, { - {CCHR('B'),CCHR('G'), cXcB, (KEYMAP *)NULL}, - {CCHR('L'),CCHR('X'), cXcL, (KEYMAP *)NULL}, + { + CCHR('B'), CCHR('G'), cXcB, (KEYMAP *) NULL + }, + { + CCHR('L'), CCHR('X'), cXcL, (KEYMAP *) NULL + }, #ifndef NO_MACRO - {'(', ')', cXlp, (KEYMAP *)NULL}, -#endif - {'0', '4', cX0, (KEYMAP *)&cX4map}, - {'=', '=', cXeq, (KEYMAP *)NULL}, - {'^', 's', cXcar, (KEYMAP *)NULL}, + { + '(', ')', cXlp, (KEYMAP *) NULL + }, +#endif + { + '0', '4', cX0, (KEYMAP *) & cX4map + }, + { + '=', '=', cXeq, (KEYMAP *) NULL + }, + { + '^', 's', cXcar, (KEYMAP *) NULL + }, } }; -static PF metacG[] = { - ctrlg, /* ^G */ +static PF metacG[] = { + ctrlg, /* ^G */ }; -static PF metacV[] = { - pagenext, /* ^V */ +static PF metacV[] = { + pagenext, /* ^V */ }; -static PF metasp[] = { - justone, /* space */ +static PF metasp[] = { + justone, /* space */ }; -static PF metapct[] = { - queryrepl, /* % */ +static PF metapct[] = { + queryrepl, /* % */ }; -static PF metami[] = { +static PF metami[] = { negative_argument, /* - */ - rescan, /* . */ - rescan, /* / */ - digit_argument, /* 0 */ - digit_argument, /* 1 */ - digit_argument, /* 2 */ - digit_argument, /* 3 */ - digit_argument, /* 4 */ - digit_argument, /* 5 */ - digit_argument, /* 6 */ - digit_argument, /* 7 */ - digit_argument, /* 8 */ - digit_argument, /* 9 */ - rescan, /* : */ - rescan, /* ; */ - gotobob, /* < */ - rescan, /* = */ - gotoeob, /* > */ + rescan, /* . */ + rescan, /* / */ + digit_argument, /* 0 */ + digit_argument, /* 1 */ + digit_argument, /* 2 */ + digit_argument, /* 3 */ + digit_argument, /* 4 */ + digit_argument, /* 5 */ + digit_argument, /* 6 */ + digit_argument, /* 7 */ + digit_argument, /* 8 */ + digit_argument, /* 9 */ + rescan, /* : */ + rescan, /* ; */ + gotobob, /* < */ + rescan, /* = */ + gotoeob, /* > */ }; -static PF metalb[] = { - gotobop, /* [ */ - delwhite, /* \ */ - gotoeop, /* ] */ - rescan, /* ^ */ - rescan, /* _ */ - rescan, /* ` */ - rescan, /* a */ - backword, /* b */ - capword, /* c */ - delfword, /* d */ - rescan, /* e */ - forwword, /* f */ +static PF metalb[] = { + gotobop, /* [ */ + delwhite, /* \ */ + gotoeop, /* ] */ + rescan, /* ^ */ + rescan, /* _ */ + rescan, /* ` */ + rescan, /* a */ + backword, /* b */ + capword, /* c */ + delfword, /* d */ + rescan, /* e */ + forwword, /* f */ }; -static PF metal[] = { - lowerword, /* l */ - rescan, /* m */ - rescan, /* n */ - rescan, /* o */ - rescan, /* p */ - fillpara, /* q */ - backsearch, /* r */ - forwsearch, /* s */ - rescan, /* t */ - upperword, /* u */ - backpage, /* v */ - copyregion, /* w */ - extend, /* x */ +static PF metal[] = { + lowerword, /* l */ + rescan, /* m */ + rescan, /* n */ + rescan, /* o */ + rescan, /* p */ + fillpara, /* q */ + backsearch, /* r */ + forwsearch, /* s */ + rescan, /* t */ + upperword, /* u */ + backpage, /* v */ + copyregion, /* w */ + extend, /* x */ }; -static PF metatilde[] = { - notmodified, /* ~ */ - delbword, /* DEL */ +static PF metatilde[] = { + notmodified, /* ~ */ + delbword, /* DEL */ }; -static struct KEYMAPE(8+IMAPEXT) metamap = { +static struct KEYMAPE (8 + IMAPEXT) metamap = { 8, - 8+IMAPEXT, + 8 + IMAPEXT, rescan, { - {CCHR('G'),CCHR('G'), metacG, (KEYMAP *)NULL}, - {CCHR('V'),CCHR('V'), metacV, (KEYMAP *)NULL}, - {' ', ' ', metasp, (KEYMAP *)NULL}, - {'%', '%', metapct,(KEYMAP *)NULL}, - {'-', '>', metami, (KEYMAP *)NULL}, - {'[', 'f', metalb, (KEYMAP *)NULL}, - {'l', 'x', metal, (KEYMAP *)NULL}, - {'~', CCHR('?'), metatilde,(KEYMAP *)NULL}, + { + CCHR('G'), CCHR('G'), metacG, (KEYMAP *) NULL + }, + { + CCHR('V'), CCHR('V'), metacV, (KEYMAP *) NULL + }, + { + ' ', ' ', metasp, (KEYMAP *) NULL + }, + { + '%', '%', metapct, (KEYMAP *) NULL + }, + { + '-', '>', metami, (KEYMAP *) NULL + }, + { + '[', 'f', metalb, (KEYMAP *) NULL + }, + { + 'l', 'x', metal, (KEYMAP *) NULL + }, + { + '~', CCHR('?'), metatilde, (KEYMAP *) NULL + }, } }; -static PF fund_at[] = { - setmark, /* ^@ */ - gotobol, /* ^A */ - backchar, /* ^B */ - rescan, /* ^C */ - forwdel, /* ^D */ - gotoeol, /* ^E */ - forwchar, /* ^F */ - ctrlg, /* ^G */ +static PF fund_at[] = { + setmark, /* ^@ */ + gotobol, /* ^A */ + backchar, /* ^B */ + rescan, /* ^C */ + forwdel, /* ^D */ + gotoeol, /* ^E */ + forwchar, /* ^F */ + ctrlg, /* ^G */ #ifndef NO_HELP - prefix, /* ^H */ + prefix, /* ^H */ #else - rescan, /* ^H */ + rescan, /* ^H */ #endif }; /* ^I is selfinsert */ -static PF fund_CJ[] = { - indent, /* ^J */ - killline, /* ^K */ - reposition, /* ^L */ - newline, /* ^M */ - forwline, /* ^N */ - openline, /* ^O */ - backline, /* ^P */ - quote, /* ^Q */ - backisearch, /* ^R */ - forwisearch, /* ^S */ - twiddle, /* ^T */ +static PF fund_CJ[] = { + indent, /* ^J */ + killline, /* ^K */ + reposition, /* ^L */ + newline, /* ^M */ + forwline, /* ^N */ + openline, /* ^O */ + backline, /* ^P */ + quote, /* ^Q */ + backisearch, /* ^R */ + forwisearch, /* ^S */ + twiddle, /* ^T */ universal_argument, /* ^U */ - forwpage, /* ^V */ - killregion, /* ^W */ - prefix, /* ^X */ - yank, /* ^Y */ + forwpage, /* ^V */ + killregion, /* ^W */ + prefix, /* ^X */ + yank, /* ^Y */ #ifndef VMS - spawncli, /* ^Z */ + spawncli, /* ^Z */ #else - attachtoparent, /* ^Z */ + attachtoparent, /* ^Z */ #endif }; -static PF fund_esc[] = { - prefix, /* esc */ - rescan, /* ^\ */ /* selfinsert is default on fundamental */ - rescan, /* ^] */ - rescan, /* ^^ */ - rescan, /* ^_ */ +static PF fund_esc[] = { + prefix, /* esc */ + rescan, /* ^\ *//* selfinsert is default on + * fundamental */ + rescan, /* ^] */ + rescan, /* ^^ */ + rescan, /* ^_ */ }; -static PF fund_del[] = { - backdel, /* DEL */ +static PF fund_del[] = { + backdel, /* DEL */ }; #ifndef FUND_XMAPS #define NFUND_XMAPS 0 /* extra map sections after normal ones */ #endif -static struct KEYMAPE(4+NFUND_XMAPS+IMAPEXT) fundmap = { +static struct KEYMAPE (4 + NFUND_XMAPS + IMAPEXT) fundmap = { 4 + NFUND_XMAPS, 4 + NFUND_XMAPS + IMAPEXT, selfinsert, { #ifndef NO_HELP - {CCHR('@'),CCHR('H'), fund_at, (KEYMAP *)&helpmap}, + { + CCHR('@'), CCHR('H'), fund_at, (KEYMAP *) & helpmap + }, #else - {CCHR('@'),CCHR('H'), fund_at, (KEYMAP *)NULL}, -#endif - {CCHR('J'),CCHR('Z'), fund_CJ, (KEYMAP *)&cXmap}, - {CCHR('['),CCHR('_'), fund_esc,(KEYMAP *)&metamap}, - {CCHR('?'),CCHR('?'), fund_del,(KEYMAP *)NULL}, + { + CCHR('@'), CCHR('H'), fund_at, (KEYMAP *) NULL + }, +#endif + { + CCHR('J'), CCHR('Z'), fund_CJ, (KEYMAP *) & cXmap + }, + { + CCHR('['), CCHR('_'), fund_esc, (KEYMAP *) & metamap + }, + { + CCHR('?'), CCHR('?'), fund_del, (KEYMAP *) NULL + }, #ifdef FUND_XMAPS FUND_XMAPS, #endif } }; -static PF fill_sp[] = { - fillword, /* ' ' */ +static PF fill_sp[] = { + fillword, /* ' ' */ }; -static struct KEYMAPE(1+IMAPEXT) fillmap = { +static struct KEYMAPE (1 + IMAPEXT) fillmap = { 1, - 1+IMAPEXT, + 1 + IMAPEXT, rescan, { - {' ', ' ', fill_sp, (KEYMAP *)NULL}, + { + ' ', ' ', fill_sp, (KEYMAP *) NULL + }, } }; -static PF indent_lf[] = { - newline, /* ^J */ - rescan, /* ^K */ - rescan, /* ^L */ - indent, /* ^M */ +static PF indent_lf[] = { + newline, /* ^J */ + rescan, /* ^K */ + rescan, /* ^L */ + indent, /* ^M */ }; -static struct KEYMAPE(1+IMAPEXT) indntmap = { +static struct KEYMAPE (1 + IMAPEXT) indntmap = { 1, - 1+IMAPEXT, + 1 + IMAPEXT, rescan, { - {CCHR('J'), CCHR('M'), indent_lf, (KEYMAP *)NULL}, + { + CCHR('J'), CCHR('M'), indent_lf, (KEYMAP *) NULL + }, } }; -static PF blink_rp[] = { - showmatch, /* ) */ +static PF blink_rp[] = { + showmatch, /* ) */ }; -static struct KEYMAPE(1+IMAPEXT) blinkmap = { +static struct KEYMAPE (1 + IMAPEXT) blinkmap = { 1, - 1+IMAPEXT, + 1 + IMAPEXT, rescan, { - {')', ')', blink_rp, (KEYMAP *)NULL}, + { + ')', ')', blink_rp, (KEYMAP *) NULL + }, } }; #ifdef NOTAB -static PF notab_tab[] = { +static PF notab_tab[] = { space_to_tabstop, /* ^I */ }; -static struct KEYMAPE(1+IMAPEXT) notabmap = { +static struct KEYMAPE (1 + IMAPEXT) notabmap = { 1, - 1+IMAPEXT, + 1 + IMAPEXT, rescan, { - {CCHR('I'),CCHR('I'), notab_tab, (KEYMAP *)NULL}, + { + CCHR('I'), CCHR('I'), notab_tab, (KEYMAP *) NULL + }, } }; #endif -static struct KEYMAPE(1+IMAPEXT) overwmap = { +static struct KEYMAPE (1 + IMAPEXT) overwmap = { 0, - 1+IMAPEXT, /* 1 to avoid 0 sized array */ + 1 + IMAPEXT, /* 1 to avoid 0 sized array */ rescan, { /* unused dummy entry for VMS C */ - {(KCHAR)0, (KCHAR)0, (PF *)NULL, (KEYMAP *)NULL}, + { + (KCHAR) 0, (KCHAR) 0, (PF *) NULL, (KEYMAP *) NULL + }, } }; #ifndef NO_DIRED -static PF dirednul[] = { - setmark, /* ^@ */ - gotobol, /* ^A */ - backchar, /* ^B */ - rescan, /* ^C */ - d_del, /* ^D */ - gotoeol, /* ^E */ - forwchar, /* ^F */ - ctrlg, /* ^G */ +static PF dirednul[] = { + setmark, /* ^@ */ + gotobol, /* ^A */ + backchar, /* ^B */ + rescan, /* ^C */ + d_del, /* ^D */ + gotoeol, /* ^E */ + forwchar, /* ^F */ + ctrlg, /* ^G */ #ifndef NO_HELP - prefix, /* ^H */ + prefix, /* ^H */ #endif }; -static PF diredcl[] = { - reposition, /* ^L */ - forwline, /* ^M */ - forwline, /* ^N */ - rescan, /* ^O */ - backline, /* ^P */ - rescan, /* ^Q */ - backisearch, /* ^R */ - forwisearch, /* ^S */ - rescan, /* ^T */ - universal_argument, /* ^U */ - forwpage, /* ^V */ - rescan, /* ^W */ - prefix, /* ^X */ +static PF diredcl[] = { + reposition, /* ^L */ + forwline, /* ^M */ + forwline, /* ^N */ + rescan, /* ^O */ + backline, /* ^P */ + rescan, /* ^Q */ + backisearch, /* ^R */ + forwisearch, /* ^S */ + rescan, /* ^T */ + universal_argument, /* ^U */ + forwpage, /* ^V */ + rescan, /* ^W */ + prefix, /* ^X */ }; -static PF diredcz[] = { +static PF diredcz[] = { #ifndef VMS - spawncli, /* ^Z */ + spawncli, /* ^Z */ #else - attachtoparent, /* ^Z */ -#endif - prefix, /* esc */ - rescan, /* ^\ */ - rescan, /* ^] */ - rescan, /* ^^ */ - rescan, /* ^_ */ - forwline, /* SP */ + attachtoparent, /* ^Z */ +#endif + prefix, /* esc */ + rescan, /* ^\ */ + rescan, /* ^] */ + rescan, /* ^^ */ + rescan, /* ^_ */ + forwline, /* SP */ }; -static PF diredc[] = { - d_copy, /* c */ - d_del, /* d */ - d_findfile, /* e */ - d_findfile, /* f */ +static PF diredc[] = { + d_copy, /* c */ + d_del, /* d */ + d_findfile, /* e */ + d_findfile, /* f */ }; -static PF diredn[] = { - forwline, /* n */ - d_ffotherwindow,/* o */ - backline, /* p */ - rescan, /* q */ - d_rename, /* r */ - rescan, /* s */ - rescan, /* t */ - d_undel, /* u */ - rescan, /* v */ - rescan, /* w */ - d_expunge, /* x */ +static PF diredn[] = { + forwline, /* n */ + d_ffotherwindow, /* o */ + backline, /* p */ + rescan, /* q */ + d_rename, /* r */ + rescan, /* s */ + rescan, /* t */ + d_undel, /* u */ + rescan, /* v */ + rescan, /* w */ + d_expunge, /* x */ }; -static PF direddl[] = { - d_undelbak, /* del */ +static PF direddl[] = { + d_undelbak, /* del */ }; #ifndef DIRED_XMAPS #define NDIRED_XMAPS 0 /* number of extra map sections */ #endif -static struct KEYMAPE(6 + NDIRED_XMAPS + IMAPEXT) diredmap = { +static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = { 6 + NDIRED_XMAPS, 6 + NDIRED_XMAPS + IMAPEXT, rescan, { #ifndef NO_HELP - {CCHR('@'), CCHR('H'), dirednul, (KEYMAP *)&helpmap}, + { + CCHR('@'), CCHR('H'), dirednul, (KEYMAP *) & helpmap + }, #else - {CCHR('@'), CCHR('G'), dirednul, (KEYMAP *)NULL}, -#endif - {CCHR('L'), CCHR('X'), diredcl, (KEYMAP *)&cXmap}, - {CCHR('Z'), ' ', diredcz, (KEYMAP *)&metamap}, - {'c', 'f', diredc, (KEYMAP *)NULL}, - {'n', 'x', diredn, (KEYMAP *)NULL}, - {CCHR('?'), CCHR('?'), direddl, (KEYMAP *)NULL}, + { + CCHR('@'), CCHR('G'), dirednul, (KEYMAP *) NULL + }, +#endif + { + CCHR('L'), CCHR('X'), diredcl, (KEYMAP *) & cXmap + }, + { + CCHR('Z'), ' ', diredcz, (KEYMAP *) & metamap + }, + { + 'c', 'f', diredc, (KEYMAP *) NULL + }, + { + 'n', 'x', diredn, (KEYMAP *) NULL + }, + { + CCHR('?'), CCHR('?'), direddl, (KEYMAP *) NULL + }, #ifdef DIRED_XMAPS - DIRED_XMAPS, /* map sections for dired mode keys */ + DIRED_XMAPS, /* map sections for dired mode keys */ #endif } }; #endif -/* give names to the maps, for use by help etc. - * If the map is to be bindable, it must also be listed in the - * function name table below with the same name. - * Maps created dynamicly currently don't get added here, thus are unnamed. - * Modes are just named keymaps with functions to add/subtract them from - * a buffer's list of modes. If you change a mode name, change it in +/* + * give names to the maps, for use by help etc. If the map is to be bindable, + * it must also be listed in the function name table below with the same + * name. Maps created dynamicly currently don't get added here, thus are + * unnamed. Modes are just named keymaps with functions to add/subtract them + * from a buffer's list of modes. If you change a mode name, change it in * modes.c also. */ -MAPS map_table[] = { +MAPS map_table[] = { /* fundamental map MUST be first entry */ - {(KEYMAP *)&fundmap, "fundamental"}, - {(KEYMAP *)&fillmap, "fill"}, - {(KEYMAP *)&indntmap, "indent"}, - {(KEYMAP *)&blinkmap, "blink"}, + {(KEYMAP *) & fundmap, "fundamental"}, + {(KEYMAP *) & fillmap, "fill"}, + {(KEYMAP *) & indntmap, "indent"}, + {(KEYMAP *) & blinkmap, "blink"}, #ifdef NOTAB - {(KEYMAP *)¬abmap, "notab"}, -#endif - {(KEYMAP *)&overwmap, "overwrite"}, - {(KEYMAP *)&metamap, "esc prefix"}, - {(KEYMAP *)&cXmap, "c-x prefix"}, - {(KEYMAP *)&cX4map, "c-x 4 prefix"}, - {(KEYMAP *)&extramap1, "extra prefix 1"}, - {(KEYMAP *)&extramap2, "extra prefix 2"}, - {(KEYMAP *)&extramap3, "extra prefix 3"}, - {(KEYMAP *)&extramap4, "extra prefix 4"}, - {(KEYMAP *)&extramap5, "extra prefix 5"}, + {(KEYMAP *) & notabmap, "notab"}, +#endif + {(KEYMAP *) & overwmap, "overwrite"}, + {(KEYMAP *) & metamap, "esc prefix"}, + {(KEYMAP *) & cXmap, "c-x prefix"}, + {(KEYMAP *) & cX4map, "c-x 4 prefix"}, + {(KEYMAP *) & extramap1, "extra prefix 1"}, + {(KEYMAP *) & extramap2, "extra prefix 2"}, + {(KEYMAP *) & extramap3, "extra prefix 3"}, + {(KEYMAP *) & extramap4, "extra prefix 4"}, + {(KEYMAP *) & extramap5, "extra prefix 5"}, #ifndef NO_HELP - {(KEYMAP *)&helpmap, "help"}, + {(KEYMAP *) & helpmap, "help"}, #endif #ifndef NO_DIRED - {(KEYMAP *)&diredmap, "dired"}, + {(KEYMAP *) & diredmap, "dired"}, #endif }; #define NMAPS (sizeof map_table/sizeof(MAPS)) -int nmaps = NMAPS; /* for use by rebind in extend.c */ +int nmaps = NMAPS; /* for use by rebind in extend.c */ -char *map_name(map) -KEYMAP *map; +char * +map_name(map) + KEYMAP *map; { - MAPS *mp = &map_table[0]; + MAPS *mp = &map_table[0]; do { - if(mp->p_map == map) return mp->p_name; - } while(++mp < &map_table[NMAPS]); - return (char *)NULL; + if (mp->p_map == map) + return mp->p_name; + } while (++mp < &map_table[NMAPS]); + return (char *) NULL; } -MAPS *name_mode(name) -char *name; +MAPS * +name_mode(name) + char *name; { - MAPS *mp = &map_table[0]; + MAPS *mp = &map_table[0]; do { - if(strcmp(mp->p_name,name)==0) return mp; - } while(++mp < &map_table[NMAPS]); - return (MAPS *)NULL; + if (strcmp(mp->p_name, name) == 0) + return mp; + } while (++mp < &map_table[NMAPS]); + return (MAPS *) NULL; } -KEYMAP *name_map(name) -char *name; +KEYMAP * +name_map(name) + char *name; { - MAPS *mp; - return (mp=name_mode(name))==NULL ? (KEYMAP *)NULL : mp->p_map; + MAPS *mp; + return (mp = name_mode(name)) == NULL ? (KEYMAP *) NULL : mp->p_map; } -/* Warning: functnames MUST be in alphabetical order! (due to binary - * search in name_function.) If the function is prefix, it must be listed - * with the same name in the map_table above. +/* + * Warning: functnames MUST be in alphabetical order! (due to binary search + * in name_function.) If the function is prefix, it must be listed with the + * same name in the map_table above. */ -FUNCTNAMES functnames[] = { +FUNCTNAMES functnames[] = { #ifdef AMIGA #ifdef DO_ICONIFY - {tticon, "amiga-iconify"}, + {tticon, "amiga-iconify"}, #endif #ifdef DO_MENU - {amigamenu, "amiga-menu"}, + {amigamenu, "amiga-menu"}, #endif #ifdef CHANGE_COLOR - {modebackground,"amiga-mode-background"}, - {modeforeground,"amiga-mode-foreground"}, - {ttmode, "amiga-mode-rendition"}, + {modebackground, "amiga-mode-background"}, + {modeforeground, "amiga-mode-foreground"}, + {ttmode, "amiga-mode-rendition"}, #endif #ifdef CHANGE_FONT - {setfont, "amiga-set-font"}, + {setfont, "amiga-set-font"}, #endif #ifdef CHANGE_COLOR - {textbackground,"amiga-text-background"}, - {textforeground,"amiga-text-foreground"}, - {tttext, "amiga-text-rendition"}, + {textbackground, "amiga-text-background"}, + {textforeground, "amiga-text-foreground"}, + {tttext, "amiga-text-rendition"}, #endif - {togglewindow, "amiga-toggle-border"}, - {togglezooms, "amiga-zoom-mode"}, -#endif /* AMIGA */ + {togglewindow, "amiga-toggle-border"}, + {togglezooms, "amiga-zoom-mode"}, +#endif /* AMIGA */ #ifndef NO_HELP {apropos_command, "apropos"}, #endif - {fillmode, "auto-fill-mode"}, - {indentmode, "auto-indent-mode"}, - {backchar, "backward-char"}, - {delbword, "backward-kill-word"}, - {gotobop, "backward-paragraph"}, - {backword, "backward-word"}, - {gotobob, "beginning-of-buffer"}, - {gotobol, "beginning-of-line"}, - {blinkparen, "blink-matching-paren"}, - {showmatch, "blink-matching-paren-hack"}, + {fillmode, "auto-fill-mode"}, + {indentmode, "auto-indent-mode"}, + {backchar, "backward-char"}, + {delbword, "backward-kill-word"}, + {gotobop, "backward-paragraph"}, + {backword, "backward-word"}, + {gotobob, "beginning-of-buffer"}, + {gotobol, "beginning-of-line"}, + {blinkparen, "blink-matching-paren"}, + {showmatch, "blink-matching-paren-hack"}, #ifdef BSMAP - {bsmap, "bsmap-mode"}, + {bsmap, "bsmap-mode"}, #endif - {prefix, "c-x 4 prefix"}, - {prefix, "c-x prefix"}, + {prefix, "c-x 4 prefix"}, + {prefix, "c-x prefix"}, #ifndef NO_MACRO - {executemacro, "call-last-kbd-macro"}, + {executemacro, "call-last-kbd-macro"}, #endif - {capword, "capitalize-word"}, + {capword, "capitalize-word"}, #ifndef NO_DIR - {changedir, "cd"}, + {changedir, "cd"}, #endif - {copyregion, "copy-region-as-kill"}, + {copyregion, "copy-region-as-kill"}, #ifdef REGEX {cntmatchlines, "count-matches"}, - {cntnonmatchlines,"count-non-matches"}, + {cntnonmatchlines, "count-non-matches"}, #endif - {define_key, "define-key"}, - {backdel, "delete-backward-char"}, - {deblank, "delete-blank-lines"}, - {forwdel, "delete-char"}, - {delwhite, "delete-horizontal-space"}, + {define_key, "define-key"}, + {backdel, "delete-backward-char"}, + {deblank, "delete-blank-lines"}, + {forwdel, "delete-char"}, + {delwhite, "delete-horizontal-space"}, #ifdef REGEX {delmatchlines, "delete-matching-lines"}, - {delnonmatchlines,"delete-non-matching-lines"}, + {delnonmatchlines, "delete-non-matching-lines"}, #endif - {onlywind, "delete-other-windows"}, - {delwind, "delete-window"}, + {onlywind, "delete-other-windows"}, + {delwind, "delete-window"}, #ifndef NO_HELP - {wallchart, "describe-bindings"}, - {desckey, "describe-key-briefly"}, + {wallchart, "describe-bindings"}, + {desckey, "describe-key-briefly"}, #endif - {digit_argument,"digit-argument"}, + {digit_argument, "digit-argument"}, #ifndef NO_DIRED - {dired, "dired"}, - {d_undelbak, "dired-backup-unflag"}, - {d_copy, "dired-copy-file"}, - {d_expunge, "dired-do-deletions"}, - {d_findfile, "dired-find-file"}, + {dired, "dired"}, + {d_undelbak, "dired-backup-unflag"}, + {d_copy, "dired-copy-file"}, + {d_expunge, "dired-do-deletions"}, + {d_findfile, "dired-find-file"}, {d_ffotherwindow, "dired-find-file-other-window"}, - {d_del, "dired-flag-file-deleted"}, + {d_del, "dired-flag-file-deleted"}, {d_otherwindow, "dired-other-window"}, - {d_rename, "dired-rename-file"}, - {d_undel, "dired-unflag"}, + {d_rename, "dired-rename-file"}, + {d_undel, "dired-unflag"}, #endif - {lowerregion, "downcase-region"}, - {lowerword, "downcase-word"}, - {showversion, "emacs-version"}, + {lowerregion, "downcase-region"}, + {lowerword, "downcase-word"}, + {showversion, "emacs-version"}, #ifndef NO_MACRO - {finishmacro, "end-kbd-macro"}, + {finishmacro, "end-kbd-macro"}, #endif - {gotoeob, "end-of-buffer"}, - {gotoeol, "end-of-line"}, - {enlargewind, "enlarge-window"}, - {prefix, "esc prefix"}, + {gotoeob, "end-of-buffer"}, + {gotoeol, "end-of-line"}, + {enlargewind, "enlarge-window"}, + {prefix, "esc prefix"}, #ifndef NO_STARTUP - {evalbuffer, "eval-current-buffer"}, - {evalexpr, "eval-expression"}, -#endif - {swapmark, "exchange-point-and-mark"}, - {extend, "execute-extended-command"}, - {prefix, "extra prefix 1"}, - {prefix, "extra prefix 2"}, - {prefix, "extra prefix 3"}, - {prefix, "extra prefix 4"}, - {prefix, "extra prefix 5"}, - {fillpara, "fill-paragraph"}, - {filevisit, "find-file"}, - {poptofile, "find-file-other-window"}, - {forwchar, "forward-char"}, - {gotoeop, "forward-paragraph"}, - {forwword, "forward-word"}, - {bindtokey, "global-set-key"}, - {unbindtokey, "global-unset-key"}, - {gotoline, "goto-line"}, + {evalbuffer, "eval-current-buffer"}, + {evalexpr, "eval-expression"}, +#endif + {swapmark, "exchange-point-and-mark"}, + {extend, "execute-extended-command"}, + {prefix, "extra prefix 1"}, + {prefix, "extra prefix 2"}, + {prefix, "extra prefix 3"}, + {prefix, "extra prefix 4"}, + {prefix, "extra prefix 5"}, + {fillpara, "fill-paragraph"}, + {filevisit, "find-file"}, + {poptofile, "find-file-other-window"}, + {forwchar, "forward-char"}, + {gotoeop, "forward-paragraph"}, + {forwword, "forward-word"}, + {bindtokey, "global-set-key"}, + {unbindtokey, "global-unset-key"}, + {gotoline, "goto-line"}, #ifndef NO_HELP - {prefix, "help"}, - {help_help, "help-help"}, -#endif - {insert, "insert"}, - {bufferinsert, "insert-buffer"}, - {fileinsert, "insert-file"}, - {fillword, "insert-with-wrap"}, - {backisearch, "isearch-backward"}, - {forwisearch, "isearch-forward"}, - {justone, "just-one-space"}, - {ctrlg, "keyboard-quit"}, - {killbuffer, "kill-buffer"}, - {killline, "kill-line"}, - {killpara, "kill-paragraph"}, - {killregion, "kill-region"}, - {delfword, "kill-word"}, - {listbuffers, "list-buffers"}, + {prefix, "help"}, + {help_help, "help-help"}, +#endif + {insert, "insert"}, + {bufferinsert, "insert-buffer"}, + {fileinsert, "insert-file"}, + {fillword, "insert-with-wrap"}, + {backisearch, "isearch-backward"}, + {forwisearch, "isearch-forward"}, + {justone, "just-one-space"}, + {ctrlg, "keyboard-quit"}, + {killbuffer, "kill-buffer"}, + {killline, "kill-line"}, + {killpara, "kill-paragraph"}, + {killregion, "kill-region"}, + {delfword, "kill-word"}, + {listbuffers, "list-buffers"}, #ifndef NO_STARTUP - {evalfile, "load"}, + {evalfile, "load"}, #endif - {localbind, "local-set-key"}, - {localunbind, "local-unset-key"}, + {localbind, "local-set-key"}, + {localunbind, "local-unset-key"}, #ifndef NO_BACKUP - {makebkfile, "make-backup-files"}, + {makebkfile, "make-backup-files"}, #endif #ifdef DO_METAKEY - {do_meta, "meta-key-mode"}, /* better name, anyone? */ + {do_meta, "meta-key-mode"}, /* better name, anyone? */ #endif #ifdef AMIGA #ifdef MOUSE - {mgotobob, "mouse-beginning-of-buffer"}, - {mforwdel, "mouse-delete-char"}, - {mdelwhite, "mouse-delete-horizontal-space"}, - {mdelwind, "mouse-delete-window"}, - {mgotoeob, "mouse-end-of-buffer"}, - {menlargewind, "mouse-enlarge-window"}, - {mkillline, "mouse-kill-line"}, - {mkillregion, "mouse-kill-region"}, - {mdelfword, "mouse-kill-word"}, - {mreposition, "mouse-recenter"}, - {mbackpage, "mouse-scroll-down"}, - {mforwpage, "mouse-scroll-up"}, - {amigamouse, "mouse-set-point"}, - {mshrinkwind, "mouse-shrink-window"}, - {msplitwind, "mouse-split-window-vertically"}, - {myank, "mouse-yank"}, + {mgotobob, "mouse-beginning-of-buffer"}, + {mforwdel, "mouse-delete-char"}, + {mdelwhite, "mouse-delete-horizontal-space"}, + {mdelwind, "mouse-delete-window"}, + {mgotoeob, "mouse-end-of-buffer"}, + {menlargewind, "mouse-enlarge-window"}, + {mkillline, "mouse-kill-line"}, + {mkillregion, "mouse-kill-region"}, + {mdelfword, "mouse-kill-word"}, + {mreposition, "mouse-recenter"}, + {mbackpage, "mouse-scroll-down"}, + {mforwpage, "mouse-scroll-up"}, + {amigamouse, "mouse-set-point"}, + {mshrinkwind, "mouse-shrink-window"}, + {msplitwind, "mouse-split-window-vertically"}, + {myank, "mouse-yank"}, #endif #endif {negative_argument, "negative-argument"}, - {newline, "newline"}, - {indent, "newline-and-indent"}, - {forwline, "next-line"}, + {newline, "newline"}, + {indent, "newline-and-indent"}, + {forwline, "next-line"}, #ifdef NOTAB - {notabmode, "no-tab-mode"}, + {notabmode, "no-tab-mode"}, #endif - {notmodified, "not-modified"}, - {openline, "open-line"}, - {nextwind, "other-window"}, - {overwrite, "overwrite-mode"}, + {notmodified, "not-modified"}, + {openline, "open-line"}, + {nextwind, "other-window"}, + {overwrite, "overwrite-mode"}, #ifdef PREFIXREGION - {prefixregion, "prefix-region"}, + {prefixregion, "prefix-region"}, #endif - {backline, "previous-line"}, + {backline, "previous-line"}, #ifdef GOSMACS - {prevwind, "previous-window"}, + {prevwind, "previous-window"}, #endif #ifdef VMS - {spawncli, "push-to-dcl"}, + {spawncli, "push-to-dcl"}, #else - {spawncli, "push-shell"}, + {spawncli, "push-shell"}, #endif #ifndef NO_DIR - {showcwdir, "pwd"}, + {showcwdir, "pwd"}, #endif - {queryrepl, "query-replace"}, + {queryrepl, "query-replace"}, #ifdef REGEX - {re_queryrepl, "query-replace-regexp"}, + {re_queryrepl, "query-replace-regexp"}, #endif - {quote, "quoted-insert"}, + {quote, "quoted-insert"}, #ifdef REGEX - {re_searchagain,"re-search-again"}, + {re_searchagain, "re-search-again"}, {re_backsearch, "re-search-backward"}, {re_forwsearch, "re-search-forward"}, #endif - {reposition, "recenter"}, - {refresh, "redraw-display"}, - {filesave, "save-buffer"}, - {quit, "save-buffers-kill-emacs"}, - {savebuffers, "save-some-buffers"}, - {backpage, "scroll-down"}, + {reposition, "recenter"}, + {refresh, "redraw-display"}, + {filesave, "save-buffer"}, + {quit, "save-buffers-kill-emacs"}, + {savebuffers, "save-some-buffers"}, + {backpage, "scroll-down"}, #ifdef GOSMACS - {back1page, "scroll-one-line-down"}, - {forw1page, "scroll-one-line-up"}, -#endif - {pagenext, "scroll-other-window"}, - {forwpage, "scroll-up"}, - {searchagain, "search-again"}, - {backsearch, "search-backward"}, - {forwsearch, "search-forward"}, - {selfinsert, "self-insert-command"}, + {back1page, "scroll-one-line-down"}, + {forw1page, "scroll-one-line-up"}, +#endif + {pagenext, "scroll-other-window"}, + {forwpage, "scroll-up"}, + {searchagain, "search-again"}, + {backsearch, "search-backward"}, + {forwsearch, "search-forward"}, + {selfinsert, "self-insert-command"}, #ifdef REGEX - {setcasefold, "set-case-fold-search"}, + {setcasefold, "set-case-fold-search"}, #endif {set_default_mode, "set-default-mode"}, - {setfillcol, "set-fill-column"}, - {setmark, "set-mark-command"}, + {setfillcol, "set-fill-column"}, + {setmark, "set-mark-command"}, #ifdef PREFIXREGION - {setprefix, "set-prefix-string"}, + {setprefix, "set-prefix-string"}, #endif - {shrinkwind, "shrink-window"}, + {shrinkwind, "shrink-window"}, #ifdef NOTAB {space_to_tabstop, "space-to-tabstop"}, #endif - {splitwind, "split-window-vertically"}, + {splitwind, "split-window-vertically"}, #ifndef NO_MACRO - {definemacro, "start-kbd-macro"}, + {definemacro, "start-kbd-macro"}, #endif #ifdef VMS - {attachtoparent,"suspend-emacs"}, + {attachtoparent, "suspend-emacs"}, #else - {spawncli, "suspend-emacs"}, + {spawncli, "suspend-emacs"}, #endif - {usebuffer, "switch-to-buffer"}, - {poptobuffer, "switch-to-buffer-other-window"}, - {twiddle, "transpose-chars"}, + {usebuffer, "switch-to-buffer"}, + {poptobuffer, "switch-to-buffer-other-window"}, + {twiddle, "transpose-chars"}, {universal_argument, "universal-argument"}, - {upperregion, "upcase-region"}, - {upperword, "upcase-word"}, - {showcpos, "what-cursor-position"}, - {filewrite, "write-file"}, - {yank, "yank"}, + {upperregion, "upcase-region"}, + {upperword, "upcase-word"}, + {showcpos, "what-cursor-position"}, + {filewrite, "write-file"}, + {yank, "yank"}, }; #define NFUNCT (sizeof(functnames)/sizeof(FUNCTNAMES)) -int nfunct = NFUNCT; /* used by help.c */ +int nfunct = NFUNCT;/* used by help.c */ /* * The general-purpose version of ROUND2 blows osk C (2.0) out of the water. @@ -1111,24 +1078,26 @@ int nfunct = NFUNCT; /* used by help.c */ */ #define ROUND2(x) (x<128?(x<64?32:64):(x<256?128:256)) -static name_fent(fname, flag) -register char *fname; -int flag; +static +name_fent(fname, flag) + register char *fname; + int flag; { - register int try; - register int x = ROUND2(NFUNCT); - register int base = 0; - register int notit; + register int try; + register int x = ROUND2(NFUNCT); + register int base = 0; + register int notit; do { - /* + can be used instead of | here if more efficent. */ - if((try = base | x) < NFUNCT) { - if((notit = strcmp(fname, functnames[try].n_name)) >= 0) { - if(!notit) return try; - base = try; + /* + can be used instead of | here if more efficent. */ + if ((try = base | x) < NFUNCT) { + if ((notit = strcmp(fname, functnames[try].n_name)) >= 0) { + if (!notit) + return try; + base = try; + } } - } - } while((x>>=1) || (try==1 && base==0)); /* try 0 once if needed */ + } while ((x >>= 1) || (try == 1 && base == 0)); /* try 0 once if needed */ return flag ? base : -1; } @@ -1136,47 +1105,61 @@ int flag; * Translate from function name to function pointer, using binary search. */ -PF name_function(fname) -char *fname; +PF +name_function(fname) + char *fname; { - int i; - if((i = name_fent(fname, FALSE)) >= 0) return functnames[i].n_funct; - return (PF)NULL; + int i; + if ((i = name_fent(fname, FALSE)) >= 0) + return functnames[i].n_funct; + return (PF) NULL; } /* complete function name */ +int complete_function(fname, c) -register char *fname; + register char *fname; + int c; { - register int i, j, k, l; - int oj; + register int i, j, k, l; + int oj; i = name_fent(fname, TRUE); - for(j=0; (l=fname[j]) && functnames[i].n_name[j]==l; j++) {} - if(fname[j]!='\0') { - if(++i >= NFUNCT) return -2; /* no match */ - for(j=0; (l=fname[j]) && functnames[i].n_name[j]==l; j++) {} - if(fname[j]!='\0') return -2; /* no match */ + for (j = 0; (l = fname[j]) && functnames[i].n_name[j] == l; j++) { } - if(c==CCHR('M') && functnames[i].n_name[j]=='\0') return -1; - for(k=i+1; k<NFUNCT; k++) { /* find last match */ - for(l=0; functnames[k].n_name[l]==fname[l]; l++) {} - if(l<j) break; + if (fname[j] != '\0') { + if (++i >= NFUNCT) + return -2; /* no match */ + for (j = 0; (l = fname[j]) && functnames[i].n_name[j] == l; j++) { + } + if (fname[j] != '\0') + return -2; /* no match */ + } + if (c == CCHR('M') && functnames[i].n_name[j] == '\0') + return -1; + for (k = i + 1; k < NFUNCT; k++) { /* find last match */ + for (l = 0; functnames[k].n_name[l] == fname[l]; l++) { + } + if (l < j) + break; } k--; oj = j; - if(k>i) { /* multiple matches */ - while((l = functnames[i].n_name[j]) == functnames[k].n_name[j]) { - fname[j++] = l; - if(l=='-' && c==' ') break; - } - if(j==oj) return -3; /* ambiguous */ - } else { /* single match */ - while(l = functnames[i].n_name[j]) { - fname[j++] = l; - if(l=='-' && c==' ') break; - } + if (k > i) { /* multiple matches */ + while ((l = functnames[i].n_name[j]) == functnames[k].n_name[j]) { + fname[j++] = l; + if (l == '-' && c == ' ') + break; + } + if (j == oj) + return -3; /* ambiguous */ + } else { /* single match */ + while (l = functnames[i].n_name[j]) { + fname[j++] = l; + if (l == '-' && c == ' ') + break; + } } fname[j] = '\0'; return j - oj; @@ -1184,48 +1167,58 @@ register char *fname; /* list possible function name completions */ -LIST *complete_function_list(fname, c) -register char *fname; +LIST * +complete_function_list(fname, c) + register char *fname; { - register int i, j, k, l; - int oj; - LIST *current,*last; + register int i, j, k, l; + int oj; + LIST *current, *last; i = name_fent(fname, TRUE); - for(j=0; (l=fname[j]) && functnames[i].n_name[j]==l; j++) {} - if(fname[j]!='\0') { - if(++i >= NFUNCT) return NULL; /* no match */ - for(j=0; (l=fname[j]) && functnames[i].n_name[j]==l; j++) {} - if(fname[j]!='\0') return NULL; /* no match */ + for (j = 0; (l = fname[j]) && functnames[i].n_name[j] == l; j++) { } -/* - * if(c==CCHR('M') && functnames[i].n_name[j]=='\0') return -1; - */ - for(k=i+1; k<NFUNCT; k++) { /* find last match */ - for(l=0; functnames[k].n_name[l]==fname[l]; l++) {} - if(l<j) break; + if (fname[j] != '\0') { + if (++i >= NFUNCT) + return NULL; /* no match */ + for (j = 0; (l = fname[j]) && functnames[i].n_name[j] == l; j++) { + } + if (fname[j] != '\0') + return NULL; /* no match */ + } + /* + * if(c==CCHR('M') && functnames[i].n_name[j]=='\0') return -1; + */ + for (k = i + 1; k < NFUNCT; k++) { /* find last match */ + for (l = 0; functnames[k].n_name[l] == fname[l]; l++) { + } + if (l < j) + break; } k--; last = NULL; for (; k >= i; k--) { - current = (LIST *)malloc(sizeof(LIST)); - current->l_next = last; - current->l_name = functnames[k].n_name; - last = current; + current = (LIST *) malloc(sizeof(LIST)); + current->l_next = last; + current->l_name = functnames[k].n_name; + last = current; } - return(last); + return (last); } /* translate from function pointer to function name. */ -char *function_name(fpoint) -register PF fpoint; +char * +function_name(fpoint) + register PF fpoint; { - register FUNCTNAMES *fnp = &functnames[0]; + register FUNCTNAMES *fnp = &functnames[0]; - if(fpoint == prefix) return (char *)NULL; /* ambiguous */ + if (fpoint == prefix) + return (char *) NULL; /* ambiguous */ do { - if(fnp->n_funct == fpoint) return fnp->n_name; - } while(++fnp < &functnames[NFUNCT]); - return (char *)NULL; + if (fnp->n_funct == fpoint) + return fnp->n_name; + } while (++fnp < &functnames[NFUNCT]); + return (char *) NULL; } diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c index c0cad9fbda1..0c653291fee 100644 --- a/usr.bin/mg/line.c +++ b/usr.bin/mg/line.c @@ -19,25 +19,25 @@ */ #include "def.h" -/* number of bytes member is from start of structure type */ -/* should be computed at compile time */ +/* number of bytes member is from start of structure type */ +/* should be computed at compile time */ #ifndef OFFSET #define OFFSET(type,member) ((char *)&(((type *)0)->member)-(char *)((type *)0)) #endif #ifndef NBLOCK -#define NBLOCK 16 /* Line block chunk size */ +#define NBLOCK 16 /* Line block chunk size */ #endif #ifndef KBLOCK -#define KBLOCK 256 /* Kill buffer block size. */ +#define KBLOCK 256 /* Kill buffer block size. */ #endif -static char *kbufp = NULL; /* Kill buffer data. */ -static RSIZE kused = 0; /* # of bytes used in KB. */ -static RSIZE ksize = 0; /* # of bytes allocated in KB. */ -static RSIZE kstart = 0; /* # of first used byte in KB. */ +static char *kbufp = NULL; /* Kill buffer data. */ +static RSIZE kused = 0; /* # of bytes used in KB. */ +static RSIZE ksize = 0; /* # of bytes allocated in KB. */ +static RSIZE kstart = 0; /* # of first used byte in KB. */ /* * This routine allocates a block of memory large enough to hold a LINE @@ -47,19 +47,21 @@ static RSIZE kstart = 0; /* # of first used byte in KB. */ * any memory left. Print a message in the message line if no space. */ LINE * -lalloc(used) register int used; { - register LINE *lp; - register int size; +lalloc(used) + int used; +{ + LINE *lp; + int size; /* any padding at the end of the structure is used */ - if((size = used + OFFSET(LINE, l_text[0])) < sizeof(LINE)) + if ((size = used + OFFSET(LINE, l_text[0])) < sizeof(LINE)) size = sizeof(LINE); #ifdef MALLOCROUND - MALLOCROUND(size); /* round up to a size optimal to malloc */ + MALLOCROUND(size); /* round up to a size optimal to malloc */ #endif - if((lp = (LINE *)malloc((unsigned)size)) == NULL) { + if ((lp = (LINE *) malloc((unsigned) size)) == NULL) { ewprintf("Can't get %d bytes", size); - return (LINE *)NULL; + return (LINE *) NULL; } lp->l_size = size - OFFSET(LINE, l_text[0]); lp->l_used = used; @@ -73,13 +75,14 @@ lalloc(used) register int used; { */ LINE * lallocx(used) -int used; + int used; { - register int size; - register LINE *lp; + int size; + LINE *lp; - size = (NBLOCK+used) & ~(NBLOCK-1); - if((lp = lalloc(size)) != NULL) lp->l_used = used; + size = (NBLOCK + used) & ~(NBLOCK - 1); + if ((lp = lalloc(size)) != NULL) + lp->l_used = used; return lp; } @@ -94,25 +97,27 @@ int used; * here. */ VOID -lfree(lp) register LINE *lp; { +lfree(lp) + register LINE *lp; +{ register BUFFER *bp; register MGWIN *wp; - for(wp = wheadp; wp != NULL; wp = wp->w_wndp) { + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { if (wp->w_linep == lp) wp->w_linep = lp->l_fp; - if (wp->w_dotp == lp) { - wp->w_dotp = lp->l_fp; - wp->w_doto = 0; + if (wp->w_dotp == lp) { + wp->w_dotp = lp->l_fp; + wp->w_doto = 0; } if (wp->w_markp == lp) { wp->w_markp = lp->l_fp; wp->w_marko = 0; } } - for(bp = bheadp; bp != NULL; bp = bp->b_bufp) { + for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { if (bp->b_nwnd == 0) { - if (bp->b_dotp == lp) { + if (bp->b_dotp == lp) { bp->b_dotp = lp->l_fp; bp->b_doto = 0; } @@ -138,17 +143,20 @@ lfree(lp) register LINE *lp; { * updated (the "*" has to be set). */ VOID -lchange(flag) register int flag; { +lchange(flag) + register int flag; +{ register MGWIN *wp; - if ((curbp->b_flag&BFCHG) == 0) { /* First change, so */ - flag |= WFMODE; /* update mode lines. */ + if ((curbp->b_flag & BFCHG) == 0) { /* First change, so */ + flag |= WFMODE; /* update mode lines. */ curbp->b_flag |= BFCHG; } - for(wp = wheadp; wp != NULL; wp = wp->w_wndp) { + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { if (wp->w_bufp == curbp) { wp->w_flag |= flag; - if(wp != curwp) wp->w_flag |= WFHARD; + if (wp != curwp) + wp->w_flag |= WFHARD; } } } @@ -166,35 +174,35 @@ lchange(flag) register int flag; { * if all is well, and FALSE on errors. */ linsert(n, c) -int n; + int n; { - register char *cp1; - register char *cp2; - register LINE *lp1; - LINE *lp2; - LINE *lp3; - register int doto; - register RSIZE i; - MGWIN *wp; + register char *cp1; + register char *cp2; + register LINE *lp1; + LINE *lp2; + LINE *lp3; + register int doto; + register RSIZE i; + MGWIN *wp; lchange(WFEDIT); - lp1 = curwp->w_dotp; /* Current line */ - if (lp1 == curbp->b_linep) { /* At the end: special */ - /* (now should only happen in empty buffer */ + lp1 = curwp->w_dotp; /* Current line */ + if (lp1 == curbp->b_linep) { /* At the end: special */ + /* (now should only happen in empty buffer */ if (curwp->w_doto != 0) { ewprintf("bug: linsert"); return FALSE; } - if ((lp2=lallocx(n)) == NULL) /* Allocate new line */ + if ((lp2 = lallocx(n)) == NULL) /* Allocate new line */ return FALSE; - lp3 = lp1->l_bp; /* Previous line */ - lp3->l_fp = lp2; /* Link in */ + lp3 = lp1->l_bp;/* Previous line */ + lp3->l_fp = lp2;/* Link in */ lp2->l_fp = lp1; lp1->l_bp = lp2; lp2->l_bp = lp3; - for (i=0; i<n; ++i) + for (i = 0; i < n; ++i) lp2->l_text[i] = c; - for(wp = wheadp; wp != NULL; wp = wp->w_wndp) { + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { if (wp->w_linep == lp1) wp->w_linep = lp2; if (wp->w_dotp == lp1) @@ -202,20 +210,20 @@ int n; if (wp->w_markp == lp1) wp->w_markp = lp2; } - /*NOSTRICT*/ + /* NOSTRICT */ curwp->w_doto = n; return TRUE; } - doto = curwp->w_doto; /* Save for later. */ - /*NOSTRICT (2) */ - if (lp1->l_used+n > lp1->l_size) { /* Hard: reallocate */ - if ((lp2=lallocx(lp1->l_used+n)) == NULL) + doto = curwp->w_doto; /* Save for later. */ + /* NOSTRICT (2) */ + if (lp1->l_used + n > lp1->l_size) { /* Hard: reallocate */ + if ((lp2 = lallocx(lp1->l_used + n)) == NULL) return FALSE; cp1 = &lp1->l_text[0]; cp2 = &lp2->l_text[0]; while (cp1 != &lp1->l_text[doto]) *cp2++ = *cp1++; - /*NOSTRICT*/ + /* NOSTRICT */ cp2 += n; while (cp1 != &lp1->l_text[lp1->l_used]) *cp2++ = *cp1++; @@ -224,32 +232,32 @@ int n; lp1->l_fp->l_bp = lp2; lp2->l_bp = lp1->l_bp; free((char *) lp1); - } else { /* Easy: in place */ - lp2 = lp1; /* Pretend new line */ - /*NOSTRICT*/ + } else { /* Easy: in place */ + lp2 = lp1; /* Pretend new line */ + /* NOSTRICT */ lp2->l_used += n; cp2 = &lp1->l_text[lp1->l_used]; - cp1 = cp2-n; + cp1 = cp2 - n; while (cp1 != &lp1->l_text[doto]) *--cp2 = *--cp1; } - for (i=0; i<n; ++i) /* Add the characters */ - lp2->l_text[doto+i] = c; + for (i = 0; i < n; ++i) /* Add the characters */ + lp2->l_text[doto + i] = c; - for(wp = wheadp; wp != NULL; wp = wp->w_wndp) { + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { if (wp->w_linep == lp1) wp->w_linep = lp2; if (wp->w_dotp == lp1) { wp->w_dotp = lp2; - if (wp==curwp || wp->w_doto>doto) - /*NOSTRICT*/ + if (wp == curwp || wp->w_doto > doto) + /* NOSTRICT */ wp->w_doto += n; } if (wp->w_markp == lp1) { wp->w_markp = lp2; if (wp->w_marko > doto) - /*NOSTRICT*/ + /* NOSTRICT */ wp->w_marko += n; } } @@ -263,36 +271,38 @@ int n; */ lnewline() { - register LINE *lp1; - register LINE *lp2; - register int doto; - register int nlen; - MGWIN *wp; + register LINE *lp1; + register LINE *lp2; + register int doto; + register int nlen; + MGWIN *wp; lchange(WFHARD); - lp1 = curwp->w_dotp; /* Get the address and */ - doto = curwp->w_doto; /* offset of "." */ - if(doto == 0) { /* avoid unnessisary copying */ - if((lp2 = lallocx(0)) == NULL) /* new first part */ + lp1 = curwp->w_dotp; /* Get the address and */ + doto = curwp->w_doto; /* offset of "." */ + if (doto == 0) { /* avoid unnessisary copying */ + if ((lp2 = lallocx(0)) == NULL) /* new first part */ return FALSE; lp2->l_bp = lp1->l_bp; lp1->l_bp->l_fp = lp2; lp2->l_fp = lp1; lp1->l_bp = lp2; - for(wp = wheadp; wp!=NULL; wp = wp->w_wndp) - if(wp->w_linep == lp1) wp->w_linep = lp2; - return TRUE; + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) + if (wp->w_linep == lp1) + wp->w_linep = lp2; + return TRUE; } - nlen = llength(lp1) - doto; /* length of new part */ - if((lp2=lallocx(nlen)) == NULL) /* New second half line */ + nlen = llength(lp1) - doto; /* length of new part */ + if ((lp2 = lallocx(nlen)) == NULL) /* New second half line */ return FALSE; - if(nlen!=0) bcopy(&lp1->l_text[doto], &lp2->l_text[0], nlen); + if (nlen != 0) + bcopy(&lp1->l_text[doto], &lp2->l_text[0], nlen); lp1->l_used = doto; lp2->l_bp = lp1; lp2->l_fp = lp1->l_fp; lp1->l_fp = lp2; lp2->l_fp->l_bp = lp2; - for(wp = wheadp; wp != NULL; wp = wp->w_wndp) { /* Windows */ + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { /* Windows */ if (wp->w_dotp == lp1 && wp->w_doto >= doto) { wp->w_dotp = lp2; wp->w_doto -= doto; @@ -314,64 +324,70 @@ lnewline() * the buffer. The "kflag" indicates either no insertion, * or direction of insertion into the kill buffer. */ -ldelete(n, kflag) RSIZE n; { - register char *cp1; - register char *cp2; - register LINE *dotp; - register int doto; - register RSIZE chunk; - MGWIN *wp; +ldelete(n, kflag) + RSIZE n; +{ + register char *cp1; + register char *cp2; + register LINE *dotp; + register int doto; + register RSIZE chunk; + MGWIN *wp; /* * HACK - doesn't matter, and fixes back-over-nl bug for empty * kill buffers. */ - if (kused == kstart) kflag = KFORW; + if (kused == kstart) + kflag = KFORW; while (n != 0) { dotp = curwp->w_dotp; doto = curwp->w_doto; - if (dotp == curbp->b_linep) /* Hit end of buffer. */ + if (dotp == curbp->b_linep) /* Hit end of buffer. */ return FALSE; - chunk = dotp->l_used-doto; /* Size of chunk. */ + chunk = dotp->l_used - doto; /* Size of chunk. */ if (chunk > n) chunk = n; - if (chunk == 0) { /* End of line, merge. */ - if(dotp == lback(curbp->b_linep)) - return FALSE; /* End of buffer. */ + if (chunk == 0) { /* End of line, merge. */ + if (dotp == lback(curbp->b_linep)) + return FALSE; /* End of buffer. */ lchange(WFHARD); if (ldelnewline() == FALSE - || (kflag!=KNONE && kinsert('\n', kflag)==FALSE)) + || (kflag != KNONE && kinsert('\n', kflag) == FALSE)) return FALSE; --n; continue; } lchange(WFEDIT); - cp1 = &dotp->l_text[doto]; /* Scrunch text. */ + cp1 = &dotp->l_text[doto]; /* Scrunch text. */ cp2 = cp1 + chunk; if (kflag == KFORW) { while (ksize - kused < chunk) - if (kgrow(FALSE) == FALSE) return FALSE; + if (kgrow(FALSE) == FALSE) + return FALSE; bcopy(cp1, &(kbufp[kused]), (int) chunk); kused += chunk; } else if (kflag == KBACK) { while (kstart < chunk) - if (kgrow(TRUE) == FALSE) return FALSE; - bcopy(cp1, &(kbufp[kstart-chunk]), (int) chunk); + if (kgrow(TRUE) == FALSE) + return FALSE; + bcopy(cp1, &(kbufp[kstart - chunk]), (int) chunk); kstart -= chunk; - } else if (kflag != KNONE) panic("broken ldelete call"); + } else if (kflag != KNONE) + panic("broken ldelete call"); while (cp2 != &dotp->l_text[dotp->l_used]) *cp1++ = *cp2++; dotp->l_used -= (int) chunk; - for(wp = wheadp; wp != NULL; wp = wp->w_wndp ) { - if (wp->w_dotp==dotp && wp->w_doto>=doto) { - /*NOSTRICT*/ + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { + if (wp->w_dotp == dotp && wp->w_doto >= doto) { + /* NOSTRICT */ wp->w_doto -= chunk; if (wp->w_doto < doto) wp->w_doto = doto; } - if (wp->w_markp==dotp && wp->w_marko>=doto) { - /*NOSTRICT*/ + if (wp->w_markp == dotp && wp->w_marko >= doto) { + /* NOSTRICT */ wp->w_marko -= chunk; if (wp->w_marko < doto) wp->w_marko = doto; @@ -393,27 +409,28 @@ ldelete(n, kflag) RSIZE n; { * about in memory. Return FALSE on error and TRUE if all * looks ok. */ -ldelnewline() { - register LINE *lp1; - register LINE *lp2; +ldelnewline() +{ + register LINE *lp1; + register LINE *lp2; register MGWIN *wp; - LINE *lp3; + LINE *lp3; lp1 = curwp->w_dotp; lp2 = lp1->l_fp; - if (lp2 == curbp->b_linep) /* At the buffer end. */ + if (lp2 == curbp->b_linep) /* At the buffer end. */ return TRUE; if (lp2->l_used <= lp1->l_size - lp1->l_used) { bcopy(&lp2->l_text[0], &lp1->l_text[lp1->l_used], lp2->l_used); - for(wp = wheadp; wp != NULL; wp = wp->w_wndp) { + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { if (wp->w_linep == lp2) wp->w_linep = lp1; if (wp->w_dotp == lp2) { - wp->w_dotp = lp1; + wp->w_dotp = lp1; wp->w_doto += lp1->l_used; } if (wp->w_markp == lp2) { - wp->w_markp = lp1; + wp->w_markp = lp1; wp->w_marko += lp1->l_used; } } @@ -423,7 +440,7 @@ ldelnewline() { free((char *) lp2); return TRUE; } - if ((lp3=lalloc(lp1->l_used + lp2->l_used)) == NULL) + if ((lp3 = lalloc(lp1->l_used + lp2->l_used)) == NULL) return FALSE; bcopy(&lp1->l_text[0], &lp3->l_text[0], lp1->l_used); bcopy(&lp2->l_text[0], &lp3->l_text[lp1->l_used], lp2->l_used); @@ -431,19 +448,19 @@ ldelnewline() { lp3->l_fp = lp2->l_fp; lp2->l_fp->l_bp = lp3; lp3->l_bp = lp1->l_bp; - for(wp = wheadp; wp != NULL; wp = wp->w_wndp) { - if (wp->w_linep==lp1 || wp->w_linep==lp2) + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { + if (wp->w_linep == lp1 || wp->w_linep == lp2) wp->w_linep = lp3; if (wp->w_dotp == lp1) - wp->w_dotp = lp3; + wp->w_dotp = lp3; else if (wp->w_dotp == lp2) { - wp->w_dotp = lp3; + wp->w_dotp = lp3; wp->w_doto += lp1->l_used; } if (wp->w_markp == lp1) - wp->w_markp = lp3; + wp->w_markp = lp3; else if (wp->w_markp == lp2) { - wp->w_markp = lp3; + wp->w_markp = lp3; wp->w_marko += lp1->l_used; } } @@ -459,34 +476,33 @@ ldelnewline() { * case of replacement to what was there). */ lreplace(plen, st, f) -register RSIZE plen; /* length to remove */ -char *st; /* replacement string */ -int f; /* case hack disable */ + register RSIZE plen; /* length to remove */ + char *st; /* replacement string */ + int f; /* case hack disable */ { - register RSIZE rlen; /* replacement length */ - register int rtype; /* capitalization */ - register int c; /* used for random characters */ - register int doto; /* offset into line */ + register RSIZE rlen; /* replacement length */ + register int rtype; /* capitalization */ + register int c; /* used for random characters */ + register int doto; /* offset into line */ /* * Find the capitalization of the word that was found. * f says use exact case of replacement string (same thing that * happens with lowercase found), so bypass check. */ - /*NOSTRICT*/ + /* NOSTRICT */ (VOID) backchar(FFARG | FFRAND, (int) plen); rtype = _L; c = lgetc(curwp->w_dotp, curwp->w_doto); - if (ISUPPER(c)!=FALSE && f==FALSE) { - rtype = _U|_L; - if (curwp->w_doto+1 < llength(curwp->w_dotp)) { - c = lgetc(curwp->w_dotp, curwp->w_doto+1); + if (ISUPPER(c) != FALSE && f == FALSE) { + rtype = _U | _L; + if (curwp->w_doto + 1 < llength(curwp->w_dotp)) { + c = lgetc(curwp->w_dotp, curwp->w_doto + 1); if (ISUPPER(c) != FALSE) { rtype = _U; } } } - /* * make the string lengths match (either pad the line * so that it will fit, or scrunch out the excess). @@ -495,9 +511,9 @@ int f; /* case hack disable */ rlen = strlen(st); doto = curwp->w_doto; if (plen > rlen) - (VOID) ldelete((RSIZE) (plen-rlen), KNONE); + (VOID) ldelete((RSIZE) (plen - rlen), KNONE); else if (plen < rlen) { - if (linsert((int)(rlen-plen), ' ') == FALSE) + if (linsert((int) (rlen - plen), ' ') == FALSE) return FALSE; } curwp->w_doto = doto; @@ -508,9 +524,9 @@ int f; /* case hack disable */ * If inserting upper, check replacement for case. */ while ((c = CHARMASK(*st++)) != '\0') { - if ((rtype&_U)!=0 && ISLOWER(c)!=0) + if ((rtype & _U) != 0 && ISLOWER(c) != 0) c = TOUPPER(c); - if (rtype == (_U|_L)) + if (rtype == (_U | _L)) rtype = _L; if (c == CCHR('J')) { if (curwp->w_doto == llength(curwp->w_dotp)) @@ -539,7 +555,9 @@ int f; /* case hack disable */ * grown to immense size. No errors. */ VOID -kdelete() { +kdelete() +{ + if (kbufp != NULL) { free((char *) kbufp); kbufp = NULL; @@ -556,15 +574,19 @@ kdelete() { * well, and FALSE on errors. Print a message on * errors. Dir says whether to put it at back or front. */ -kinsert(c, dir) { +kinsert(c, dir) +{ if (kused == ksize && dir == KFORW && kgrow(FALSE) == FALSE) return FALSE; if (kstart == 0 && dir == KBACK && kgrow(TRUE) == FALSE) return FALSE; - if (dir == KFORW) kbufp[kused++] = c; - else if (dir == KBACK) kbufp[--kstart] = c; - else panic("broken kinsert call"); /* Oh shit! */ + if (dir == KFORW) + kbufp[kused++] = c; + else if (dir == KBACK) + kbufp[--kstart] = c; + else + panic("broken kinsert call"); /* Oh shit! */ return (TRUE); } @@ -572,24 +594,25 @@ kinsert(c, dir) { * kgrow - just get more kill buffer for the callee. back is true if * we are trying to get space at the beginning of the kill buffer. */ -kgrow(back) { - register int nstart; - register char *nbufp; +kgrow(back) +{ + register int nstart; + register char *nbufp; - if ((unsigned)(ksize+KBLOCK) <= (unsigned)ksize) { + if ((unsigned) (ksize + KBLOCK) <= (unsigned) ksize) { /* probably 16 bit unsigned */ ewprintf("Kill buffer size at maximum"); return FALSE; } - if ((nbufp=malloc((unsigned)(ksize+KBLOCK))) == NULL) { - ewprintf("Can't get %ld bytes", (long)(ksize+KBLOCK)); + if ((nbufp = malloc((unsigned) (ksize + KBLOCK))) == NULL) { + ewprintf("Can't get %ld bytes", (long) (ksize + KBLOCK)); return FALSE; } - nstart = (back == TRUE) ? (kstart + KBLOCK) : (KBLOCK / 4) ; - bcopy(&(kbufp[kstart]), &(nbufp[nstart]), (int) (kused-kstart)); + nstart = (back == TRUE) ? (kstart + KBLOCK) : (KBLOCK / 4); + bcopy(&(kbufp[kstart]), &(nbufp[nstart]), (int) (kused - kstart)); if (kbufp != NULL) free((char *) kbufp); - kbufp = nbufp; + kbufp = nbufp; ksize += KBLOCK; kused = kused - kstart + nstart; kstart = nstart; @@ -602,7 +625,8 @@ kgrow(back) { * off the end, it returns "-1". This lets the caller * just scan along until it gets a "-1" back. */ -kremove(n) { +kremove(n) +{ if (n < 0 || n + kstart >= kused) return -1; return CHARMASK(kbufp[n + kstart]); diff --git a/usr.bin/mg/macro.c b/usr.bin/mg/macro.c index 94d14e28dc8..6b4396bf78a 100644 --- a/usr.bin/mg/macro.c +++ b/usr.bin/mg/macro.c @@ -1,4 +1,4 @@ -/* keyboard macros for MicroGnuEmacs 1x */ +/* keyboard macros for Mg 2 */ #ifndef NO_MACRO #include "def.h" @@ -7,77 +7,79 @@ #define INIT(i) = (i) #include "macro.h" -/*ARGSUSED*/ +/* ARGSUSED */ definemacro(f, n) -int f, n; + int f, n; { - register LINE *lp1; - LINE *lp2; + register LINE *lp1; + LINE *lp2; macrocount = 0; - if(macrodef) { - ewprintf("already defining macro"); - return macrodef = FALSE; + if (macrodef) { + ewprintf("already defining macro"); + return macrodef = FALSE; } /* free lines allocated for string arguments */ - if(maclhead != NULL) { - for(lp1 = maclhead->l_fp; lp1 != maclhead; lp1 = lp2) { - lp2 = lp1->l_fp; - free((char *)lp1); - } - free((char *)lp1); + if (maclhead != NULL) { + for (lp1 = maclhead->l_fp; lp1 != maclhead; lp1 = lp2) { + lp2 = lp1->l_fp; + free((char *) lp1); + } + free((char *) lp1); } - if((maclhead = lp1 = lalloc(0)) == NULL) return FALSE; + if ((maclhead = lp1 = lalloc(0)) == NULL) + return FALSE; ewprintf("Defining Keyboard Macro..."); maclcur = lp1->l_fp = lp1->l_bp = lp1; return macrodef = TRUE; } -/*ARGSUSED*/ +/* ARGSUSED */ finishmacro(f, n) -int f, n; + int f, n; { - macrodef = FALSE; - ewprintf("End Keyboard Macro Definition"); - return TRUE; + macrodef = FALSE; + ewprintf("End Keyboard Macro Definition"); + return TRUE; } -/*ARGSUSED*/ +/* ARGSUSED */ executemacro(f, n) -int f, n; + int f, n; { - int i, j; - PF funct; - int universal_argument(); - int flag, num; + int i, j; + PF funct; + int universal_argument(); + int flag, num; - if(macrodef || - (macrocount >= MAXMACRO && macro[MAXMACRO].m_funct != finishmacro)) - return FALSE; - if(macrocount == 0) return TRUE; - inmacro = TRUE; - for(i = n; i > 0; i--) { - maclcur = maclhead->l_fp; - flag = 0; - num = 1; - for(j = 0; j < macrocount-1; j++) { - funct = macro[j].m_funct; - if(funct == universal_argument) { - flag = FFARG; - num = macro[++j].m_count; - continue; - } - if((*funct)(flag, num) != TRUE) { - inmacro = FALSE; + if (macrodef || + (macrocount >= MAXMACRO && macro[MAXMACRO].m_funct != finishmacro)) return FALSE; - } - lastflag = thisflag; - thisflag = 0; - flag = 0; - num = 1; + if (macrocount == 0) + return TRUE; + inmacro = TRUE; + for (i = n; i > 0; i--) { + maclcur = maclhead->l_fp; + flag = 0; + num = 1; + for (j = 0; j < macrocount - 1; j++) { + funct = macro[j].m_funct; + if (funct == universal_argument) { + flag = FFARG; + num = macro[++j].m_count; + continue; + } + if ((*funct) (flag, num) != TRUE) { + inmacro = FALSE; + return FALSE; + } + lastflag = thisflag; + thisflag = 0; + flag = 0; + num = 1; + } } - } - inmacro = FALSE; - return TRUE; + inmacro = FALSE; + return TRUE; } #endif diff --git a/usr.bin/mg/macro.h b/usr.bin/mg/macro.h index 9ce7f892f67..287c949900b 100644 --- a/usr.bin/mg/macro.h +++ b/usr.bin/mg/macro.h @@ -7,17 +7,17 @@ #define MAXMACRO 256 /* maximum functs in a macro */ -EXTERN int inmacro INIT(FALSE); -EXTERN int macrodef INIT(FALSE); -EXTERN int macrocount INIT(0); +EXTERN int inmacro INIT(FALSE); +EXTERN int macrodef INIT(FALSE); +EXTERN int macrocount INIT(0); -EXTERN union { +EXTERN union { PF m_funct; - int m_count; /* for count-prefix */ -} macro[MAXMACRO]; + int m_count; /* for count-prefix */ +} macro[MAXMACRO]; -EXTERN LINE *maclhead INIT(NULL); -EXTERN LINE *maclcur; +EXTERN LINE *maclhead INIT(NULL); +EXTERN LINE *maclcur; #undef EXTERN #undef INIT diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c index 73271ce9b6e..cb84ca4ddbf 100644 --- a/usr.bin/mg/main.c +++ b/usr.bin/mg/main.c @@ -6,48 +6,49 @@ #include "macro.h" #endif -int thisflag; /* Flags, this command */ -int lastflag; /* Flags, last command */ -int curgoal; /* Goal column */ -BUFFER *curbp; /* Current buffer */ -MGWIN *curwp; /* Current window */ -BUFFER *bheadp; /* BUFFER listhead */ -MGWIN *wheadp = (MGWIN *)NULL; /* MGWIN listhead */ -char pat[NPAT]; /* Pattern */ +int thisflag; /* Flags, this command */ +int lastflag; /* Flags, last command */ +int curgoal; /* Goal column */ +BUFFER *curbp; /* Current buffer */ +MGWIN *curwp; /* Current window */ +BUFFER *bheadp; /* BUFFER listhead */ +MGWIN *wheadp = (MGWIN *) NULL; /* MGWIN listhead */ +char pat[NPAT]; /* Pattern */ #ifndef NO_DPROMPT -extern char prompt[], *promptp; /* delayed prompting */ +extern char prompt[], *promptp; /* delayed prompting */ #endif -static VOID edinit(); +static VOID edinit(); int main(argc, argv) -int argc; -char **argv; + int argc; + char **argv; { #ifndef NO_STARTUP - char *startupfile(); + char *startupfile(); #endif - char *cp; - VOID vtinit(), makename(), eerase(); - BUFFER *findbuffer(); + char *cp; + VOID vtinit(), makename(), eerase(); + BUFFER *findbuffer(); #ifdef SYSINIT - SYSINIT; /* system dependent. */ + SYSINIT; /* system dependent. */ #endif - vtinit(); /* Virtual terminal. */ + vtinit(); /* Virtual terminal. */ #ifndef NO_DIR - dirinit(); /* Get current directory */ + dirinit(); /* Get current directory */ #endif - edinit(); /* Buffers, windows. */ - ttykeymapinit(); /* Symbols, bindings. */ - /* doing update() before reading files causes the error messages from - * the file I/O show up on the screen. (and also an extra display - * of the mode line if there are files specified on the command line.) + edinit(); /* Buffers, windows. */ + ttykeymapinit(); /* Symbols, bindings. */ + /* + * doing update() before reading files causes the error messages from + * the file I/O show up on the screen. (and also an extra display of + * the mode line if there are files specified on the command line.) */ update(); -#ifndef NO_STARTUP /* User startup file. */ - if ((cp = startupfile((char *)NULL)) != NULL) +#ifndef NO_STARTUP /* User startup file. */ + if ((cp = startupfile((char *) NULL)) != NULL) (VOID) load(cp); #endif while (--argc > 0) { @@ -56,55 +57,59 @@ char **argv; (VOID) showbuffer(curbp, curwp, 0); (VOID) readin(cp); } - thisflag = 0; /* Fake last flags. */ - for(;;) { + thisflag = 0; /* Fake last flags. */ + for (;;) { #ifndef NO_DPROMPT - *(promptp = prompt) = '\0'; - if(epresf == KPROMPT) eerase(); + *(promptp = prompt) = '\0'; + if (epresf == KPROMPT) + eerase(); #endif - update(); - lastflag = thisflag; - thisflag = 0; - switch(doin()) { - case TRUE: break; + update(); + lastflag = thisflag; + thisflag = 0; + switch (doin()) { + case TRUE: + break; case ABORT: - ewprintf("Quit"); /* and fall through */ + ewprintf("Quit"); /* and fall through */ case FALSE: default: - ttbeep(); + ttbeep(); #ifndef NO_MACRO - macrodef = FALSE; + macrodef = FALSE; #endif - } + } } } /* * Initialize default buffer and window. */ -static VOID -edinit() { +static VOID +edinit() +{ register BUFFER *bp; register MGWIN *wp; bheadp = NULL; - bp = bfind("*scratch*", TRUE); /* Text buffer. */ - wp = (MGWIN *)malloc(sizeof(MGWIN)); /* Initial window. */ - if (bp==NULL || wp==NULL) panic("edinit"); - curbp = bp; /* Current ones. */ + bp = bfind("*scratch*", TRUE); /* Text buffer. */ + wp = (MGWIN *) malloc(sizeof(MGWIN)); /* Initial window. */ + if (bp == NULL || wp == NULL) + panic("edinit"); + curbp = bp; /* Current ones. */ wheadp = wp; - curwp = wp; - wp->w_wndp = NULL; /* Initialize window. */ - wp->w_bufp = bp; - bp->b_nwnd = 1; /* Displayed. */ + curwp = wp; + wp->w_wndp = NULL; /* Initialize window. */ + wp->w_bufp = bp; + bp->b_nwnd = 1; /* Displayed. */ wp->w_linep = wp->w_dotp = bp->b_linep; - wp->w_doto = 0; + wp->w_doto = 0; wp->w_markp = NULL; wp->w_marko = 0; wp->w_toprow = 0; - wp->w_ntrows = nrow-2; /* 2 = mode, echo. */ + wp->w_ntrows = nrow - 2;/* 2 = mode, echo. */ wp->w_force = 0; - wp->w_flag = WFMODE|WFHARD; /* Full. */ + wp->w_flag = WFMODE | WFHARD; /* Full. */ } /* @@ -113,18 +118,19 @@ edinit() { * changed and not written out. Normally bound * to "C-X C-C". */ -/*ARGSUSED*/ +/* ARGSUSED */ quit(f, n) { - register int s; - VOID vttidy(); + register int s; + VOID vttidy(); - if ((s = anycb(FALSE)) == ABORT) return ABORT; + if ((s = anycb(FALSE)) == ABORT) + return ABORT; if (s == FALSE - || eyesno("Some modified buffers exist, really exit") == TRUE) { + || eyesno("Some modified buffers exist, really exit") == TRUE) { vttidy(); #ifdef SYSCLEANUP - SYSCLEANUP; + SYSCLEANUP; #endif exit(GOOD); } @@ -136,8 +142,10 @@ quit(f, n) * to abort whatever C-g is aborting these days. Currently does * nothing. */ -/*ARGSUSED*/ +/* ARGSUSED */ +int ctrlg(f, n) + int f, n; { return ABORT; } diff --git a/usr.bin/mg/match.c b/usr.bin/mg/match.c index e49268b9b54..e5eacf2465f 100644 --- a/usr.bin/mg/match.c +++ b/usr.bin/mg/match.c @@ -14,24 +14,34 @@ #include "def.h" #include "key.h" -static int balance(); -static VOID displaymatch(); +static int balance(); +static VOID displaymatch(); -/* Balance table. When balance() encounters a character - * that is to be matched, it first searches this table - * for a balancing left-side character. If the character - * is not in the table, the character is balanced by itself. +/* + * Balance table. When balance() encounters a character that is to be + * matched, it first searches this table for a balancing left-side character. + * f the character is not in the table, the character is balanced by itself. * This is to allow delimiters in Scribe documents to be matched. */ static struct balance { - char left, right; -} bal[] = { - { '(', ')' }, - { '[', ']' }, - { '{', '}' }, - { '<', '>' }, - { '\0','\0'} + char left, right; +} bal[] = { + { + '(', ')' + }, + { + '[', ']' + }, + { + '{', '}' + }, + { + '<', '>' + }, + { + '\0', '\0' + } }; /* @@ -41,13 +51,14 @@ static struct balance { showmatch(f, n) { - register int i, s; + register int i, s; - if (f & FFRAND) return FALSE; + if (f & FFRAND) + return FALSE; for (i = 0; i < n; i++) { if ((s = selfinsert(FFRAND, 1)) != TRUE) return s; - if (balance() != TRUE) /* unbalanced -- warn user */ + if (balance() != TRUE) /* unbalanced -- warn user */ ttbeep(); } return TRUE; @@ -61,16 +72,17 @@ showmatch(f, n) * is found, it uses displaymatch() to display the match. */ -static balance() +static +balance() { - register LINE *clp; - register int cbo; - int c; - int i; - int rbal, lbal; - int depth; + register LINE *clp; + register int cbo; + int c; + int i; + int rbal, lbal; + int depth; - rbal = key.k_chars[key.k_count-1]; + rbal = key.k_chars[key.k_count - 1]; /* See if there is a matching character -- default to the same */ @@ -80,7 +92,6 @@ static balance() lbal = bal[i].left; break; } - /* Move behind the inserted character. We are always guaranteed */ /* that there is at least one character on the line, since one was */ /* just self-inserted by blinkparen. */ @@ -88,19 +99,19 @@ static balance() clp = curwp->w_dotp; cbo = curwp->w_doto - 1; - depth = 0; /* init nesting depth */ + depth = 0; /* init nesting depth */ for (;;) { - if (cbo == 0) { /* beginning of line */ + if (cbo == 0) { /* beginning of line */ clp = lback(clp); if (clp == curbp->b_linep) return (FALSE); - cbo = llength(clp)+1; + cbo = llength(clp) + 1; } - if (--cbo == llength(clp)) /* end of line */ + if (--cbo == llength(clp)) /* end of line */ c = '\n'; else - c = lgetc(clp,cbo); /* somewhere in middle */ + c = lgetc(clp, cbo); /* somewhere in middle */ /* Check for a matching character. If still in a nested */ /* level, pop out of it and continue search. This check */ @@ -108,17 +119,16 @@ static balance() /* matches will work too. */ if (c == lbal) { if (depth == 0) { - displaymatch(clp,cbo); + displaymatch(clp, cbo); return (TRUE); - } - else + } else depth--; } - /* Check for another level of nesting. */ + /* Check for another level of nesting. */ if (c == rbal) depth++; } - /*NOTREACHED*/ + /* NOTREACHED */ } @@ -130,20 +140,21 @@ static balance() * sit there a while, then move back. */ -static VOID displaymatch(clp, cbo) -register LINE *clp; -register int cbo; +static VOID +displaymatch(clp, cbo) + register LINE *clp; + register int cbo; { - register LINE *tlp; - register int tbo; - register int cp; - register int bufo; - register int c; - int inwindow; - char buf[NLINE]; + register LINE *tlp; + register int tbo; + register int cp; + register int bufo; + register int c; + int inwindow; + char buf[NLINE]; - /* Figure out if matching char is in current window by */ - /* searching from the top of the window to dot. */ + /* Figure out if matching char is in current window by */ + /* searching from the top of the window to dot. */ inwindow = FALSE; for (tlp = curwp->w_linep; tlp != lforw(curwp->w_dotp); tlp = lforw(tlp)) @@ -154,36 +165,38 @@ register int cbo; tlp = curwp->w_dotp; /* save current position */ tbo = curwp->w_doto; - curwp->w_dotp = clp; /* move to new position */ - curwp->w_doto = cbo; + curwp->w_dotp = clp; /* move to new position */ + curwp->w_doto = cbo; curwp->w_flag |= WFMOVE; - update(); /* show match */ - sleep(1); /* wait a bit */ + update(); /* show match */ + sleep(1); /* wait a bit */ - curwp->w_dotp = tlp; /* return to old position */ - curwp->w_doto = tbo; - curwp->w_flag |= WFMOVE; + curwp->w_dotp = tlp; /* return to old position */ + curwp->w_doto = tbo; + curwp->w_flag |= WFMOVE; update(); - } - else { /* match not in this window so display line in echo area */ + } else { /* match not in this window so display line + * in echo area */ bufo = 0; - for (cp = 0; cp < llength(clp); cp++) { /* expand tabs */ - c = lgetc(clp,cp); + for (cp = 0; cp < llength(clp); cp++) { /* expand tabs */ + c = lgetc(clp, cp); if (c != '\t' #ifdef NOTAB - || (curbp->b_flag & BFNOTAB) + || (curbp->b_flag & BFNOTAB) #endif - ) if(ISCTRL(c)) { - buf[bufo++] = '^'; - buf[bufo++] = CCHR(c); - } else buf[bufo++] = c; + ) + if (ISCTRL(c)) { + buf[bufo++] = '^'; + buf[bufo++] = CCHR(c); + } else + buf[bufo++] = c; else do { buf[bufo++] = ' '; } while (bufo & 7); } buf[bufo++] = '\0'; - ewprintf("Matches %s",buf); + ewprintf("Matches %s", buf); } } diff --git a/usr.bin/mg/modes.c b/usr.bin/mg/modes.c index 49144f2fd6f..856bcc9d517 100644 --- a/usr.bin/mg/modes.c +++ b/usr.bin/mg/modes.c @@ -6,57 +6,60 @@ #include "def.h" #include "kbd.h" -int defb_nmodes = 0; -MAPS *defb_modes[PBMODES] = {&map_table[0]}; -int defb_flag = 0; +int defb_nmodes = 0; +MAPS *defb_modes[PBMODES] = {&map_table[0]}; +int defb_flag = 0; -static int changemode(f, n, mode) -int f, n; -char *mode; +static int +changemode(f, n, mode) + int f, n; + char *mode; { - register int i; - MAPS *m; - VOID upmodes(); + register int i; + MAPS *m; - if((m = name_mode(mode)) == NULL) { - ewprintf("Can't find mode %s", mode); - return FALSE; - } - if(!(f & FFARG)) { - for(i=0; i <= curbp->b_nmodes; i++) - if(curbp->b_modes[i] == m) { - n = 0; /* mode already set */ - break; - } - } - if(n > 0) { - for(i=0; i <= curbp->b_nmodes; i++) - if(curbp->b_modes[i] == m) return TRUE; /* mode already set */ - if(curbp->b_nmodes >= PBMODES-1) { - ewprintf("Too many modes"); - return FALSE; + if ((m = name_mode(mode)) == NULL) { + ewprintf("Can't find mode %s", mode); + return FALSE; } - curbp->b_modes[++(curbp->b_nmodes)] = m; - } else { - /* fundamental is b_modes[0] and can't be unset */ - for(i=1; i <= curbp->b_nmodes && m != curbp->b_modes[i]; i++) {} - if(i > curbp->b_nmodes) return TRUE; /* mode wasn't set */ - for(; i < curbp->b_nmodes; i++) - curbp->b_modes[i] = curbp->b_modes[i+1]; - curbp->b_nmodes--; - } - upmodes(curbp); - return TRUE; + if (!(f & FFARG)) { + for (i = 0; i <= curbp->b_nmodes; i++) + if (curbp->b_modes[i] == m) { + n = 0; /* mode already set */ + break; + } + } + if (n > 0) { + for (i = 0; i <= curbp->b_nmodes; i++) + if (curbp->b_modes[i] == m) + return TRUE; /* mode already set */ + if (curbp->b_nmodes >= PBMODES - 1) { + ewprintf("Too many modes"); + return FALSE; + } + curbp->b_modes[++(curbp->b_nmodes)] = m; + } else { + /* fundamental is b_modes[0] and can't be unset */ + for (i = 1; i <= curbp->b_nmodes && m != curbp->b_modes[i]; i++) { + } + if (i > curbp->b_nmodes) + return TRUE; /* mode wasn't set */ + for (; i < curbp->b_nmodes; i++) + curbp->b_modes[i] = curbp->b_modes[i + 1]; + curbp->b_nmodes--; + } + upmodes(curbp); + return TRUE; } indentmode(f, n) { - return changemode(f, n, "indent"); + return changemode(f, n, "indent"); } fillmode(f, n) { - return changemode(f, n, "fill"); + return changemode(f, n, "fill"); } /* @@ -64,75 +67,90 @@ fillmode(f, n) */ blinkparen(f, n) { - return changemode(f, n, "blink"); + return changemode(f, n, "blink"); } #ifdef NOTAB notabmode(f, n) { - if(changemode(f, n, "notab") == FALSE) return FALSE; - if(f & FFARG) { - if(n <= 0) curbp->b_flag &= ~BFNOTAB; - else curbp->b_flag |= BFNOTAB; - } else curbp->b_flag ^= BFNOTAB; - return TRUE; + if (changemode(f, n, "notab") == FALSE) + return FALSE; + if (f & FFARG) { + if (n <= 0) + curbp->b_flag &= ~BFNOTAB; + else + curbp->b_flag |= BFNOTAB; + } else + curbp->b_flag ^= BFNOTAB; + return TRUE; } #endif overwrite(f, n) -int f, n; + int f, n; { - if(changemode(f, n, "overwrite") == FALSE) return FALSE; - if(f & FFARG) { - if(n <= 0) curbp->b_flag &= ~BFOVERWRITE; - else curbp->b_flag |= BFOVERWRITE; - } else curbp->b_flag ^= BFOVERWRITE; - return TRUE; + if (changemode(f, n, "overwrite") == FALSE) + return FALSE; + if (f & FFARG) { + if (n <= 0) + curbp->b_flag &= ~BFOVERWRITE; + else + curbp->b_flag |= BFOVERWRITE; + } else + curbp->b_flag ^= BFOVERWRITE; + return TRUE; } set_default_mode(f, n) -int f, n; + int f, n; { - register int i; - register MAPS *m; - char mode[32]; + register int i; + register MAPS *m; + char mode[32]; - if(eread("Set Default Mode: ", mode, 32, EFNEW) != TRUE) - return ABORT; - if((m = name_mode(mode)) == NULL) { - ewprintf("can't find mode %s", mode); - return FALSE; - } - if(!(f & FFARG)) { - for(i=0; i <= defb_nmodes; i++) - if(defb_modes[i] == m) { - n = 0; /* mode already set */ - break; - } - } - if(n > 0) { - for(i=0; i <= defb_nmodes; i++) - if(defb_modes[i] == m) return TRUE; /* mode already set */ - if(defb_nmodes >= PBMODES-1) { - ewprintf("Too many modes"); - return FALSE; + if (eread("Set Default Mode: ", mode, 32, EFNEW) != TRUE) + return ABORT; + if ((m = name_mode(mode)) == NULL) { + ewprintf("can't find mode %s", mode); + return FALSE; + } + if (!(f & FFARG)) { + for (i = 0; i <= defb_nmodes; i++) + if (defb_modes[i] == m) { + n = 0; /* mode already set */ + break; + } + } + if (n > 0) { + for (i = 0; i <= defb_nmodes; i++) + if (defb_modes[i] == m) + return TRUE; /* mode already set */ + if (defb_nmodes >= PBMODES - 1) { + ewprintf("Too many modes"); + return FALSE; + } + defb_modes[++defb_nmodes] = m; + } else { + /* fundamental is defb_modes[0] and can't be unset */ + for (i = 1; i <= defb_nmodes && m != defb_modes[i]; i++) { + } + if (i > defb_nmodes) + return TRUE; /* mode wasn't set */ + for (; i < defb_nmodes; i++) + defb_modes[i] = defb_modes[i + 1]; + defb_nmodes--; } - defb_modes[++defb_nmodes] = m; - } else { - /* fundamental is defb_modes[0] and can't be unset */ - for(i=1; i <= defb_nmodes && m != defb_modes[i]; i++) {} - if(i > defb_nmodes) return TRUE; /* mode wasn't set */ - for(; i < defb_nmodes; i++) - defb_modes[i] = defb_modes[i+1]; - defb_nmodes--; - } - if(strcmp(mode, "overwrite")==0) - if(n<=0) defb_flag &= ~BFOVERWRITE; - else defb_flag |= BFOVERWRITE; + if (strcmp(mode, "overwrite") == 0) + if (n <= 0) + defb_flag &= ~BFOVERWRITE; + else + defb_flag |= BFOVERWRITE; #ifdef NOTAB - if(strcmp(mode, "notab")==0) - if(n<=0) defb_flag &= ~BFNOTAB; - else defb_flag |= BFNOTAB; + if (strcmp(mode, "notab") == 0) + if (n <= 0) + defb_flag &= ~BFNOTAB; + else + defb_flag |= BFNOTAB; #endif - return TRUE; + return TRUE; } diff --git a/usr.bin/mg/paragraph.c b/usr.bin/mg/paragraph.c index b09aa7810f3..8e1536dfe0d 100644 --- a/usr.bin/mg/paragraph.c +++ b/usr.bin/mg/paragraph.c @@ -4,7 +4,7 @@ */ #include "def.h" -static int fillcol = 70 ; +static int fillcol = 70; #define MAXWORD 256 /* @@ -12,40 +12,47 @@ static int fillcol = 70 ; * here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE> * combination to delimit the begining of a paragraph */ -/*ARGSUSED*/ +/* ARGSUSED */ gotobop(f, n) { - if (n < 0) /* the other way...*/ + if (n < 0) /* the other way... */ return gotoeop(f, -n); while (n-- > 0) { /* for each one asked for */ /* first scan back until we are in a word */ - - while (backchar(FFRAND, 1) && !inword()) {} + + while (backchar(FFRAND, 1) && !inword()) { + } curwp->w_doto = 0; /* and go to the B-O-Line */ - /* and scan back until we hit a <NL><SP> <NL><TAB> or <NL><NL> */ + /* + * and scan back until we hit a <NL><SP> <NL><TAB> or + * <NL><NL> + */ while (lback(curwp->w_dotp) != curbp->b_linep) if (llength(lback(curwp->w_dotp)) - && lgetc(curwp->w_dotp,0) != ' ' - && lgetc(curwp->w_dotp,0) != '.' - && lgetc(curwp->w_dotp,0) != '\t') + && lgetc(curwp->w_dotp, 0) != ' ' + && lgetc(curwp->w_dotp, 0) != '.' + && lgetc(curwp->w_dotp, 0) != '\t') curwp->w_dotp = lback(curwp->w_dotp); else { - if (llength(lback(curwp->w_dotp)) - && lgetc(curwp->w_dotp,0) == '.') { - curwp->w_dotp = lforw(curwp->w_dotp); - if(curwp->w_dotp == curbp->b_linep) { - /* beond end of buffer, cleanup time */ - curwp->w_dotp = lback(curwp->w_dotp); - curwp->w_doto = llength(curwp->w_dotp); - } - } - break; - } + if (llength(lback(curwp->w_dotp)) + && lgetc(curwp->w_dotp, 0) == '.') { + curwp->w_dotp = lforw(curwp->w_dotp); + if (curwp->w_dotp == curbp->b_linep) { + /* + * beond end of buffer, + * cleanup time + */ + curwp->w_dotp = lback(curwp->w_dotp); + curwp->w_doto = llength(curwp->w_dotp); + } + } + break; + } } - curwp->w_flag |= WFMOVE; /* force screen update */ + curwp->w_flag |= WFMOVE;/* force screen update */ return TRUE; } @@ -54,37 +61,38 @@ gotobop(f, n) * here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE> * combination to delimit the begining of a paragraph */ -/*ARGSUSED*/ +/* ARGSUSED */ gotoeop(f, n) { - if (n < 0) /* the other way...*/ + if (n < 0) /* the other way... */ return gotobop(f, -n); while (n-- > 0) { /* for each one asked for */ /* Find the first word on/after the current line */ curwp->w_doto = 0; - while(forwchar(FFRAND, 1) && !inword()) {} + while (forwchar(FFRAND, 1) && !inword()) { + } curwp->w_doto = 0; curwp->w_dotp = lforw(curwp->w_dotp); /* and scan forword until we hit a <NL><SP> or ... */ while (curwp->w_dotp != curbp->b_linep) { if (llength(curwp->w_dotp) - && lgetc(curwp->w_dotp,0) != ' ' - && lgetc(curwp->w_dotp,0) != '.' - && lgetc(curwp->w_dotp,0) != '\t') + && lgetc(curwp->w_dotp, 0) != ' ' + && lgetc(curwp->w_dotp, 0) != '.' + && lgetc(curwp->w_dotp, 0) != '\t') curwp->w_dotp = lforw(curwp->w_dotp); else break; } - if(curwp->w_dotp == curbp->b_linep) { + if (curwp->w_dotp == curbp->b_linep) { /* beond end of buffer, cleanup time */ curwp->w_dotp = lback(curwp->w_dotp); curwp->w_doto = llength(curwp->w_dotp); - break; + break; } } - curwp->w_flag |= WFMOVE; /* force screen update */ + curwp->w_flag |= WFMOVE;/* force screen update */ return TRUE; } @@ -92,33 +100,35 @@ gotoeop(f, n) * Fill the current paragraph according to the current * fill column */ -/*ARGSUSED*/ +/* ARGSUSED */ fillpara(f, n) { - register int c; /* current char durring scan */ - register int wordlen; /* length of current word */ - register int clength; /* position on line during fill */ - register int i; /* index during word copy */ - register int eopflag; /* Are we at the End-Of-Paragraph? */ - int firstflag; /* first word? (needs no space) */ - int newlength; /* tentative new line length */ - int eolflag; /* was at end of line */ - LINE *eopline; /* pointer to line just past EOP */ - char wbuf[MAXWORD]; /* buffer for current word */ + register int c; /* current char durring scan */ + register int wordlen;/* length of current word */ + register int clength;/* position on line during fill */ + register int i; /* index during word copy */ + register int eopflag;/* Are we at the End-Of-Paragraph? */ + int firstflag; /* first word? (needs no space) */ + int newlength; /* tentative new line length */ + int eolflag;/* was at end of line */ + LINE *eopline;/* pointer to line just past EOP */ + char wbuf[MAXWORD]; /* buffer for current word */ /* record the pointer to the line just past the EOP */ (VOID) gotoeop(FFRAND, 1); - if(curwp->w_doto != 0) { + if (curwp->w_doto != 0) { /* paragraph ends at end of buffer */ (VOID) lnewline(); eopline = lforw(curwp->w_dotp); - } else eopline = curwp->w_dotp; + } else + eopline = curwp->w_dotp; /* and back top the begining of the paragraph */ (VOID) gotobop(FFRAND, 1); /* initialize various info */ - while (!inword() && forwchar(FFRAND, 1)) {} + while (!inword() && forwchar(FFRAND, 1)) { + } clength = curwp->w_doto; wordlen = 0; @@ -127,7 +137,7 @@ fillpara(f, n) eopflag = FALSE; while (!eopflag) { /* get the next character in the paragraph */ - if (eolflag=(curwp->w_doto == llength(curwp->w_dotp))) { + if (eolflag = (curwp->w_doto == llength(curwp->w_dotp))) { c = ' '; if (lforw(curwp->w_dotp) == eopline) eopflag = TRUE; @@ -143,24 +153,26 @@ fillpara(f, n) if (wordlen < MAXWORD - 1) wbuf[wordlen++] = c; else { - /* You loose chars beyond MAXWORD if the word + /* + * You loose chars beyond MAXWORD if the word * is to long. I'm to lazy to fix it now; it - * just silently truncated the word before, so - * I get to feel smug. + * just silently truncated the word before, + * so I get to feel smug. */ ewprintf("Word too long!"); } } else if (wordlen) { /* calculate tenatitive new length with word added */ newlength = clength + 1 + wordlen; - /* if at end of line or at doublespace and previous + /* + * if at end of line or at doublespace and previous * character was one of '.','?','!' doublespace here. */ - if((eolflag || curwp->w_doto==llength(curwp->w_dotp) - || (c=lgetc(curwp->w_dotp,curwp->w_doto))==' ' - || c=='\t') - && ISEOSP(wbuf[wordlen-1]) - && wordlen<MAXWORD-1) + if ((eolflag || curwp->w_doto == llength(curwp->w_dotp) + || (c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' ' + || c == '\t') + && ISEOSP(wbuf[wordlen - 1]) + && wordlen < MAXWORD - 1) wbuf[wordlen++] = ' '; /* at a word break with a word waiting */ if (newlength <= fillcol) { @@ -171,8 +183,8 @@ fillpara(f, n) } firstflag = FALSE; } else { - if(curwp->w_doto > 0 && - lgetc(curwp->w_dotp,curwp->w_doto-1)==' ') { + if (curwp->w_doto > 0 && + lgetc(curwp->w_dotp, curwp->w_doto - 1) == ' ') { curwp->w_doto -= 1; (VOID) ldelete((RSIZE) 1, KNONE); } @@ -182,7 +194,7 @@ fillpara(f, n) } /* and add the word in in either case */ - for (i=0; i<wordlen; i++) { + for (i = 0; i < wordlen; i++) { (VOID) linsert(1, wbuf[i]); ++clength; } @@ -191,18 +203,20 @@ fillpara(f, n) } /* and add a last newline for the end of our new paragraph */ (VOID) lnewline(); - /* we realy should wind up where we started, (which is hard to keep + /* + * we realy should wind up where we started, (which is hard to keep * track of) but I think the end of the last line is better than the - * begining of the blank line. */ + * begining of the blank line. + */ (VOID) backchar(FFRAND, 1); return TRUE; } /* delete n paragraphs starting with the current one */ -/*ARGSUSED*/ +/* ARGSUSED */ killpara(f, n) { - register int status; /* returned status of functions */ + register int status; /* returned status of functions */ while (n--) { /* for each paragraph to delete */ @@ -231,52 +245,58 @@ killpara(f, n) * check to see if we're past fillcol, and if so, * justify this line. As a last step, justify the line. */ -/*ARGSUSED*/ +/* ARGSUSED */ fillword(f, n) { - register char c; - register int col, i, nce; + register char c; + register int col, i, nce; for (i = col = 0; col <= fillcol; ++i, ++col) { - if (i == curwp->w_doto) return selfinsert(f, n) ; + if (i == curwp->w_doto) + return selfinsert(f, n); c = lgetc(curwp->w_dotp, i); if (c == '\t' #ifdef NOTAB - && !(curbp->b_flag & BFNOTAB) + && !(curbp->b_flag & BFNOTAB) #endif - ) col |= 0x07; - else if (ISCTRL(c) != FALSE) ++col; + ) + col |= 0x07; + else if (ISCTRL(c) != FALSE) + ++col; } if (curwp->w_doto != llength(curwp->w_dotp)) { (VOID) selfinsert(f, n); nce = llength(curwp->w_dotp) - curwp->w_doto; - } else nce = 0; + } else + nce = 0; curwp->w_doto = i; if ((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' ' && c != '\t') do { (VOID) backchar(FFRAND, 1); } while ((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' ' - && c != '\t' && curwp->w_doto > 0); + && c != '\t' && curwp->w_doto > 0); if (curwp->w_doto == 0) do { (VOID) forwchar(FFRAND, 1); } while ((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' ' - && c != '\t' && curwp->w_doto < llength(curwp->w_dotp)); + && c != '\t' && curwp->w_doto < llength(curwp->w_dotp)); (VOID) delwhite(FFRAND, 1); (VOID) lnewline(); i = llength(curwp->w_dotp) - nce; - curwp->w_doto = i>0 ? i : 0; + curwp->w_doto = i > 0 ? i : 0; curwp->w_flag |= WFMOVE; - if (nce == 0 && curwp->w_doto != 0) return fillword(f, n); + if (nce == 0 && curwp->w_doto != 0) + return fillword(f, n); return TRUE; } /* Set fill column to n. */ -setfillcol(f, n) { - extern int getcolpos() ; +setfillcol(f, n) +{ + extern int getcolpos(); fillcol = ((f & FFARG) ? n : getcolpos()); ewprintf("Fill column set to %d", fillcol); diff --git a/usr.bin/mg/random.c b/usr.bin/mg/random.c index 297de45eba5..c10aa2d5127 100644 --- a/usr.bin/mg/random.c +++ b/usr.bin/mg/random.c @@ -16,60 +16,62 @@ * display; it does not truncate just because the screen does. * This is normally bound to "C-X =". */ -/*ARGSUSED*/ +/* ARGSUSED */ showcpos(f, n) { - register LINE *clp; - register long nchar; - long cchar; - register int nline, row; - int cline, cbyte; /* Current line/char/byte */ - int ratio; + register LINE *clp; + register long nchar; + long cchar; + register int nline, row; + int cline, cbyte; /* Current line/char/byte */ + int ratio; - clp = lforw(curbp->b_linep); /* Collect the data. */ + clp = lforw(curbp->b_linep); /* Collect the data. */ nchar = 0; nline = 0; for (;;) { - ++nline; /* Count this line */ + ++nline; /* Count this line */ if (clp == curwp->w_dotp) { - cline = nline; /* Mark line */ + cline = nline; /* Mark line */ cchar = nchar + curwp->w_doto; if (curwp->w_doto == llength(clp)) cbyte = '\n'; else cbyte = lgetc(clp, curwp->w_doto); } - nchar += llength(clp); /* Now count the chars */ + nchar += llength(clp); /* Now count the chars */ clp = lforw(clp); - if (clp == curbp->b_linep) break; - nchar++; /* count the newline */ + if (clp == curbp->b_linep) + break; + nchar++; /* count the newline */ } - row = curwp->w_toprow + 1; /* Determine row. */ + row = curwp->w_toprow + 1; /* Determine row. */ clp = curwp->w_linep; - while (clp!=curbp->b_linep && clp!=curwp->w_dotp) { + while (clp != curbp->b_linep && clp != curwp->w_dotp) { ++row; clp = lforw(clp); } - /*NOSTRICT*/ - ratio = nchar ? (100L*cchar) / nchar : 100; + /* NOSTRICT */ + ratio = nchar ? (100L * cchar) / nchar : 100; ewprintf("Char: %c (0%o) point=%ld(%d%%) line=%d row=%d col=%d", - cbyte, cbyte, cchar, ratio, cline, row, getcolpos()); + cbyte, cbyte, cchar, ratio, cline, row, getcolpos()); return TRUE; } -getcolpos() { - register int col, i, c; +getcolpos() +{ + register int col, i, c; - col = 1; /* Determine column. */ - for (i=0; i<curwp->w_doto; ++i) { + col = 1; /* Determine column. */ + for (i = 0; i < curwp->w_doto; ++i) { c = lgetc(curwp->w_dotp, i); if (c == '\t' #ifdef NOTAB - && !(curbp->b_flag & BFNOTAB) + && !(curbp->b_flag & BFNOTAB) #endif ) { - col |= 0x07; - ++col; + col |= 0x07; + ++col; } else if (ISCTRL(c) != FALSE) ++col; ++col; @@ -86,24 +88,26 @@ getcolpos() { * to "C-T". This always works within a line, so * "WFEDIT" is good enough. */ -/*ARGSUSED*/ +/* ARGSUSED */ twiddle(f, n) { - register LINE *dotp; - register int doto; - register int cr; - VOID lchange(); + register LINE *dotp; + register int doto; + register int cr; + VOID lchange(); dotp = curwp->w_dotp; doto = curwp->w_doto; - if(doto==llength(dotp)) { - if(--doto<=0) return FALSE; + if (doto == llength(dotp)) { + if (--doto <= 0) + return FALSE; } else { - if(doto==0) return FALSE; + if (doto == 0) + return FALSE; ++curwp->w_doto; } cr = lgetc(dotp, doto--); - lputc(dotp, doto+1, lgetc(dotp, doto)); + lputc(dotp, doto + 1, lgetc(dotp, doto)); lputc(dotp, doto, cr); lchange(WFEDIT); return TRUE; @@ -116,22 +120,22 @@ twiddle(f, n) * procerssors. They even handle the looping. Normally * this is bound to "C-O". */ -/*ARGSUSED*/ +/* ARGSUSED */ openline(f, n) { - register int i; - register int s; + register int i; + register int s; if (n < 0) return FALSE; if (n == 0) return TRUE; - i = n; /* Insert newlines. */ + i = n; /* Insert newlines. */ do { s = lnewline(); - } while (s==TRUE && --i); - if (s == TRUE) /* Then back up overtop */ - s = backchar(f | FFRAND, n); /* of them all. */ + } while (s == TRUE && --i); + if (s == TRUE) /* Then back up overtop */ + s = backchar(f | FFRAND, n); /* of them all. */ return s; } @@ -147,25 +151,26 @@ openline(f, n) * as critical if screen update were a lot * more efficient. */ -/*ARGSUSED*/ +/* ARGSUSED */ newline(f, n) { - register LINE *lp; - register int s; + register LINE *lp; + register int s; - if (n < 0) return FALSE; + if (n < 0) + return FALSE; while (n--) { lp = curwp->w_dotp; #ifdef undef if (llength(lp) == curwp->w_doto - && lforw(lp) != curbp->b_linep - && llength(lforw(lp)) == 0) { - if ((s=forwchar(FFRAND, 1)) != TRUE) + && lforw(lp) != curbp->b_linep + && llength(lforw(lp)) == 0) { + if ((s = forwchar(FFRAND, 1)) != TRUE) return s; } else #endif - if ((s=lnewline()) != TRUE) - return s; + if ((s = lnewline()) != TRUE) + return s; } return TRUE; } @@ -180,56 +185,59 @@ newline(f, n) * blank lines after the line. Normally this command * is bound to "C-X C-O". Any argument is ignored. */ -/*ARGSUSED*/ +/* ARGSUSED */ deblank(f, n) { - register LINE *lp1; - register LINE *lp2; - register RSIZE nld; + register LINE *lp1; + register LINE *lp2; + register RSIZE nld; lp1 = curwp->w_dotp; - while (llength(lp1)==0 && (lp2=lback(lp1))!=curbp->b_linep) + while (llength(lp1) == 0 && (lp2 = lback(lp1)) != curbp->b_linep) lp1 = lp2; lp2 = lp1; nld = (RSIZE) 0; - while ((lp2=lforw(lp2))!=curbp->b_linep && llength(lp2)==0) + while ((lp2 = lforw(lp2)) != curbp->b_linep && llength(lp2) == 0) ++nld; if (nld == 0) return (TRUE); curwp->w_dotp = lforw(lp1); curwp->w_doto = 0; - return ldelete((RSIZE)nld, KNONE); + return ldelete((RSIZE) nld, KNONE); } /* * Delete any whitespace around dot, then insert a space. */ -justone(f, n) { +justone(f, n) +{ (VOID) delwhite(f, n); return linsert(1, ' '); } /* * Delete any whitespace around dot. */ -/*ARGSUSED*/ +/* ARGSUSED */ delwhite(f, n) { - register int col, c, s; + register int col, c, s; col = curwp->w_doto; while (((c = lgetc(curwp->w_dotp, col)) == ' ' || c == '\t') - && col < llength(curwp->w_dotp)) + && col < llength(curwp->w_dotp)) ++col; do { if (curwp->w_doto == 0) { s = FALSE; break; } - if ((s = backchar(FFRAND, 1)) != TRUE) break; + if ((s = backchar(FFRAND, 1)) != TRUE) + break; } while ((c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' ' || c == '\t'); - if (s == TRUE) (VOID) forwchar(FFRAND, 1); - (VOID) ldelete((RSIZE)(col - curwp->w_doto), KNONE); + if (s == TRUE) + (VOID) forwchar(FFRAND, 1); + (VOID) ldelete((RSIZE) (col - curwp->w_doto), KNONE); return TRUE; } /* @@ -244,19 +252,20 @@ delwhite(f, n) * of the subcomands failed. Normally bound * to "C-J". */ -/*ARGSUSED*/ +/* ARGSUSED */ indent(f, n) { - register int nicol; - register int c; - register int i; + register int nicol; + register int c; + register int i; - if (n < 0) return (FALSE); + if (n < 0) + return (FALSE); while (n--) { nicol = 0; - for (i=0; i<llength(curwp->w_dotp); ++i) { + for (i = 0; i < llength(curwp->w_dotp); ++i) { c = lgetc(curwp->w_dotp, i); - if (c!=' ' && c!='\t') + if (c != ' ' && c != '\t') break; if (c == '\t') nicol |= 0x07; @@ -264,11 +273,11 @@ indent(f, n) } if (lnewline() == FALSE || (( #ifdef NOTAB - curbp->b_flag&BFNOTAB) ? - linsert(nicol, ' ') == FALSE : ( + curbp->b_flag & BFNOTAB) ? + linsert(nicol, ' ') == FALSE : ( #endif - ((i=nicol/8)!=0 && linsert(i, '\t')==FALSE) || - ((i=nicol%8)!=0 && linsert(i, ' ')==FALSE)))) + ((i = nicol / 8) != 0 && linsert(i, '\t') == FALSE) || + ((i = nicol % 8) != 0 && linsert(i, ' ') == FALSE)))) return FALSE; } return TRUE; @@ -283,13 +292,13 @@ indent(f, n) * loss of text if typed with a big argument. * Normally bound to "C-D". */ -/*ARGSUSED*/ +/* ARGSUSED */ forwdel(f, n) { if (n < 0) return backdel(f | FFRAND, -n); - if (f & FFARG) { /* Really a kill. */ - if ((lastflag&CFKILL) == 0) + if (f & FFARG) { /* Really a kill. */ + if ((lastflag & CFKILL) == 0) kdelete(); thisflag |= CFKILL; } @@ -303,19 +312,19 @@ forwdel(f, n) * Like delete forward, this actually does a kill * if presented with an argument. */ -/*ARGSUSED*/ +/* ARGSUSED */ backdel(f, n) { - register int s; + register int s; if (n < 0) return forwdel(f | FFRAND, -n); - if (f & FFARG) { /* Really a kill. */ - if ((lastflag&CFKILL) == 0) + if (f & FFARG) { /* Really a kill. */ + if ((lastflag & CFKILL) == 0) kdelete(); thisflag |= CFKILL; } - if ((s=backchar(f | FFRAND, n)) == TRUE) + if ((s = backchar(f | FFRAND, n)) == TRUE) s = ldelete((RSIZE) n, (f & FFARG) ? KFORW : KNONE); return s; } @@ -331,38 +340,39 @@ backdel(f, n) * kills any text before dot on the current line, * then it kills back abs(arg) lines. */ -/*ARGSUSED*/ -killline(f, n) { - register RSIZE chunk; - register LINE *nextp; - register int i, c; - VOID kdelete(); +/* ARGSUSED */ +killline(f, n) +{ + register RSIZE chunk; + register LINE *nextp; + register int i, c; + VOID kdelete(); - if ((lastflag&CFKILL) == 0) /* Clear kill buffer if */ - kdelete(); /* last wasn't a kill. */ + if ((lastflag & CFKILL) == 0) /* Clear kill buffer if */ + kdelete(); /* last wasn't a kill. */ thisflag |= CFKILL; if (!(f & FFARG)) { for (i = curwp->w_doto; i < llength(curwp->w_dotp); ++i) if ((c = lgetc(curwp->w_dotp, i)) != ' ' && c != '\t') break; if (i == llength(curwp->w_dotp)) - chunk = llength(curwp->w_dotp)-curwp->w_doto + 1; + chunk = llength(curwp->w_dotp) - curwp->w_doto + 1; else { - chunk = llength(curwp->w_dotp)-curwp->w_doto; + chunk = llength(curwp->w_dotp) - curwp->w_doto; if (chunk == 0) chunk = 1; } } else if (n > 0) { - chunk = llength(curwp->w_dotp)-curwp->w_doto+1; + chunk = llength(curwp->w_dotp) - curwp->w_doto + 1; nextp = lforw(curwp->w_dotp); i = n; while (--i) { if (nextp == curbp->b_linep) break; - chunk += llength(nextp)+1; + chunk += llength(nextp) + 1; nextp = lforw(nextp); } - } else { /* n <= 0 */ + } else { /* n <= 0 */ chunk = curwp->w_doto; curwp->w_doto = 0; i = n; @@ -371,14 +381,14 @@ killline(f, n) { break; curwp->w_dotp = lback(curwp->w_dotp); curwp->w_flag |= WFMOVE; - chunk += llength(curwp->w_dotp)+1; + chunk += llength(curwp->w_dotp) + 1; } } /* * KFORW here is a bug. Should be KBACK/KFORW, but we need to * rewrite the ldelete code (later)? */ - return (ldelete(chunk, KFORW)); + return (ldelete(chunk, KFORW)); } /* @@ -396,21 +406,22 @@ killline(f, n) { * the window (nothing moves, because all of the new * text landed off screen). */ -/*ARGSUSED*/ +/* ARGSUSED */ yank(f, n) { - register int c; - register int i; - register LINE *lp; - register int nline; - VOID isetmark(); + register int c; + register int i; + register LINE *lp; + register int nline; + VOID isetmark(); - if (n < 0) return FALSE; - nline = 0; /* Newline counting. */ + if (n < 0) + return FALSE; + nline = 0; /* Newline counting. */ while (n--) { - isetmark(); /* mark around last yank */ + isetmark(); /* mark around last yank */ i = 0; - while ((c=kremove(i)) >= 0) { + while ((c = kremove(i)) >= 0) { if (c == '\n') { if (newline(FFRAND, 1) == FALSE) return FALSE; @@ -422,23 +433,25 @@ yank(f, n) ++i; } } - lp = curwp->w_linep; /* Cosmetic adjustment */ - if (curwp->w_dotp == lp) { /* if offscreen insert. */ - while (nline-- && lback(lp)!=curbp->b_linep) + lp = curwp->w_linep; /* Cosmetic adjustment */ + if (curwp->w_dotp == lp) { /* if offscreen insert. */ + while (nline-- && lback(lp) != curbp->b_linep) lp = lback(lp); - curwp->w_linep = lp; /* Adjust framing. */ + curwp->w_linep = lp; /* Adjust framing. */ curwp->w_flag |= WFHARD; } return TRUE; } #ifdef NOTAB -/*ARGSUSED*/ +/* ARGSUSED */ space_to_tabstop(f, n) -int f, n; + int f, n; { - if(n<0) return FALSE; - if(n==0) return TRUE; - return linsert((n<<3) - (curwp->w_doto & 7), ' '); + if (n < 0) + return FALSE; + if (n == 0) + return TRUE; + return linsert((n << 3) - (curwp->w_doto & 7), ' '); } #endif diff --git a/usr.bin/mg/re_search.c b/usr.bin/mg/re_search.c index 4be7c271c82..bfd1b8f1864 100644 --- a/usr.bin/mg/re_search.c +++ b/usr.bin/mg/re_search.c @@ -1,12 +1,11 @@ /* - * regular expression search commands for - * MicroGnuEmacs + * regular expression search commands for Mg * * This file contains functions to implement several of gnuemacs' - * regular expression functions for MicroGnuEmacs. Several of - * the routines below are just minor rearrangements of the MicroGnuEmacs - * non-regular expression search functions. Hence some of them date back - * in essential structure to the original MicroEMACS; others are modifications + * regular expression functions for Mg. Several of the routines + * below are just minor rearrangements of the Mg non-regular + * expression search functions. Hence some of them date back in + * essential structure to the original MicroEMACS; others are modifications * of Rich Ellison's code. I, Peter Newton, wrote about half from scratch. */ @@ -18,55 +17,55 @@ #include "def.h" #include "macro.h" -#define SRCH_BEGIN (0) /* Search sub-codes. */ +#define SRCH_BEGIN (0) /* Search sub-codes. */ #define SRCH_FORW (-1) #define SRCH_BACK (-2) #define SRCH_NOPR (-3) #define SRCH_ACCM (-4) #define SRCH_MARK (-5) -#define RE_NMATCH 10 /* max number of matches */ +#define RE_NMATCH 10 /* max number of matches */ -char re_pat[NPAT]; /* Regex pattern */ -int re_srch_lastdir = SRCH_NOPR; /* Last search flags. */ -int casefoldsearch = TRUE; /* Does search ignore case ? */ +char re_pat[NPAT]; /* Regex pattern */ +int re_srch_lastdir = SRCH_NOPR; /* Last search flags. */ +int casefoldsearch = TRUE; /* Does search ignore case ? */ /* Indexed by a character, gives the upper case equivalent of the character */ -static char upcase[0400] = - { 000, 001, 002, 003, 004, 005, 006, 007, - 010, 011, 012, 013, 014, 015, 016, 017, - 020, 021, 022, 023, 024, 025, 026, 027, - 030, 031, 032, 033, 034, 035, 036, 037, - 040, 041, 042, 043, 044, 045, 046, 047, - 050, 051, 052, 053, 054, 055, 056, 057, - 060, 061, 062, 063, 064, 065, 066, 067, - 070, 071, 072, 073, 074, 075, 076, 077, - 0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107, - 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117, - 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127, - 0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137, - 0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107, - 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117, - 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127, - 0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177, - 0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207, - 0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217, - 0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227, - 0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237, - 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247, - 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257, - 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, - 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, - 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307, - 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317, - 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327, - 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, - 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347, - 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357, - 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, - 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377 - }; +static char upcase[0400] = +{000, 001, 002, 003, 004, 005, 006, 007, + 010, 011, 012, 013, 014, 015, 016, 017, + 020, 021, 022, 023, 024, 025, 026, 027, + 030, 031, 032, 033, 034, 035, 036, 037, + 040, 041, 042, 043, 044, 045, 046, 047, + 050, 051, 052, 053, 054, 055, 056, 057, + 060, 061, 062, 063, 064, 065, 066, 067, + 070, 071, 072, 073, 074, 075, 076, 077, + 0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107, + 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117, + 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127, + 0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137, + 0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107, + 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117, + 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127, + 0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177, + 0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207, + 0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217, + 0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227, + 0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237, + 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247, + 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257, + 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, + 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, + 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307, + 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317, + 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327, + 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, + 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347, + 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357, + 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, + 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377 +}; /* * Search forward. @@ -75,11 +74,12 @@ static char upcase[0400] = * matched characters, and display does all the hard stuff. * If not found, it just prints a message. */ -/*ARGSUSED*/ -re_forwsearch(f, n) { - register int s; +/* ARGSUSED */ +re_forwsearch(f, n) +{ + register int s; - if ((s=re_readpattern("RE Search")) != TRUE) + if ((s = re_readpattern("RE Search")) != TRUE) return (s); if (re_forwsrch() == FALSE) { ewprintf("Search failed: \"%s\"", re_pat); @@ -96,11 +96,12 @@ re_forwsearch(f, n) { * pointing at the first character of the pattern [the last character that * was matched]. */ -/*ARGSUSED*/ -re_backsearch(f, n) { - register int s; +/* ARGSUSED */ +re_backsearch(f, n) +{ + register int s; - if ((s=re_readpattern("RE Search backward")) != TRUE) + if ((s = re_readpattern("RE Search backward")) != TRUE) return (s); if (re_backsrch() == FALSE) { ewprintf("Search failed: \"%s\"", re_pat); @@ -118,55 +119,58 @@ re_backsearch(f, n) { * has been saved in "srch_lastdir", so you know which way * to go. */ -/*ARGSUSED*/ -/* This code has problems-- some incompatibility(?) with - extend.c causes match to fail when it should not. +/* ARGSUSED */ +/* + * This code has problems-- some incompatibility(?) with extend.c causes + * match to fail when it should not. */ -re_searchagain(f, n) { - - if (re_srch_lastdir == SRCH_NOPR) { - ewprintf("No last search"); - return (FALSE); - } - - if (re_srch_lastdir == SRCH_FORW) { - if (re_forwsrch() == FALSE) { - ewprintf("Search failed: \"%s\"", re_pat); - return (FALSE); - } - return (TRUE); - } - if (re_srch_lastdir == SRCH_BACK) { - if (re_backsrch() == FALSE) { - ewprintf("Search failed: \"%s\"", re_pat); - return (FALSE); - } - return (TRUE); - } +re_searchagain(f, n) +{ + + if (re_srch_lastdir == SRCH_NOPR) { + ewprintf("No last search"); + return (FALSE); + } + if (re_srch_lastdir == SRCH_FORW) { + if (re_forwsrch() == FALSE) { + ewprintf("Search failed: \"%s\"", re_pat); + return (FALSE); + } + return (TRUE); + } + if (re_srch_lastdir == SRCH_BACK) { + if (re_backsrch() == FALSE) { + ewprintf("Search failed: \"%s\"", re_pat); + return (FALSE); + } + return (TRUE); + } } /* Compiled regex goes here-- changed only when new pattern read */ -static regex_t re_buff; +static regex_t re_buff; static regmatch_t re_match[RE_NMATCH]; /* * Re-Query Replace. * Replace strings selectively. Does a search and replace operation. */ -/*ARGSUSED*/ -re_queryrepl(f, n) { - register int s; - register int rcnt = 0; /* Replacements made so far */ - register int plen; /* length of found string */ - char news[NPAT]; /* replacement string */ +/* ARGSUSED */ +re_queryrepl(f, n) +{ + register int s; + register int rcnt = 0; /* Replacements made so far */ + register int plen; /* length of found string */ + char news[NPAT]; /* replacement string */ /* Casefold check */ - if (!casefoldsearch) f = TRUE; + if (!casefoldsearch) + f = TRUE; - if ((s=re_readpattern("RE Query replace")) != TRUE) + if ((s = re_readpattern("RE Query replace")) != TRUE) return (s); - if ((s=ereply("Query replace %s with: ",news, NPAT, re_pat)) == ABORT) + if ((s = ereply("Query replace %s with: ", news, NPAT, re_pat)) == ABORT) return (s); if (s == FALSE) news[0] = '\0'; @@ -179,7 +183,7 @@ re_queryrepl(f, n) { */ while (re_forwsrch() == TRUE) { - retry: +retry: update(); switch (getkey(FALSE)) { case ' ': @@ -196,9 +200,9 @@ re_queryrepl(f, n) { rcnt++; goto stopsearch; - case CCHR('G'): /* ^G */ + case CCHR('G'):/* ^G */ (VOID) ctrlg(FFRAND, 0); - case CCHR('['): /* ESC */ + case CCHR('['):/* ESC */ case '`': goto stopsearch; @@ -211,11 +215,11 @@ re_queryrepl(f, n) { } while (re_forwsrch() == TRUE); goto stopsearch; - case CCHR('?'): /* To not replace */ + case CCHR('?'):/* To not replace */ break; default: -ewprintf("<SP> replace, [.] rep-end, <DEL> don't, [!] repl rest <ESC> quit"); + ewprintf("<SP> replace, [.] rep-end, <DEL> don't, [!] repl rest <ESC> quit"); goto retry; } } @@ -235,93 +239,100 @@ stopsearch: -/* Routine re_doreplace calls lreplace to make replacements needed by - * re_query replace. Its reason for existence is to deal with \1, - * \2. etc. +/* + * Routine re_doreplace calls lreplace to make replacements needed by + * re_query replace. Its reason for existence is to deal with \1, \2. etc. */ /* Maximum length of replacement string */ #define REPLEN 256 re_doreplace(plen, st, f) - register RSIZE plen; /* length to remove */ - char *st; /* replacement string */ - int f; /* case hack disable */ + register RSIZE plen; /* length to remove */ + char *st; /* replacement string */ + int f; /* case hack disable */ { - int s; - int num, k; - register int j; - int more, state; - LINE *clp; - char repstr[REPLEN]; - - clp = curwp->w_dotp; - more = TRUE; - j = 0; - state = 0; - - /* The following FSA parses the replacement string */ - while (more) { - switch (state) { - - case 0: if (*st == '\\') { - st++; - state = 1; - } - else if (*st == '\0') - more = FALSE; - else { - repstr[j] = *st; - j++; if (j >= REPLEN) return(FALSE); - st++; - } - break; - case 1: if (*st >= '0' && *st <= '9') { - num = *st - '0'; - st++; - state = 2; - } - else if (*st == '\0') - more = FALSE; - else { - repstr[j] = *st; - j++; if (j >= REPLEN) return(FALSE); - st++; - state = 0; - } - break; - case 2: if (*st >= '0' && *st <= '9') { - num = 10*num + *st - '0'; - st++; - } - else { - if (num >= RE_NMATCH) return(FALSE); - k = re_match[num].rm_eo - re_match[num].rm_so; - if (j+k >= REPLEN) return(FALSE); - bcopy(&(clp->l_text[re_match[num].rm_so]), &repstr[j], k); - j += k; - if (*st == '\0') - more = FALSE; - if (*st == '\\') { - st++; - state = 1; - } - else { - repstr[j] = *st; - j++; if (j >= REPLEN) return(FALSE); - st++; - state = 0; - } - } - break; - } /* end case */ - } /* end while */ - - repstr[j] = '\0'; - - s = lreplace(plen, repstr, f); - - return(s); + int s; + int num, k; + register int j; + int more, state; + LINE *clp; + char repstr[REPLEN]; + + clp = curwp->w_dotp; + more = TRUE; + j = 0; + state = 0; + + /* The following FSA parses the replacement string */ + while (more) { + switch (state) { + + case 0: + if (*st == '\\') { + st++; + state = 1; + } else if (*st == '\0') + more = FALSE; + else { + repstr[j] = *st; + j++; + if (j >= REPLEN) + return (FALSE); + st++; + } + break; + case 1: + if (*st >= '0' && *st <= '9') { + num = *st - '0'; + st++; + state = 2; + } else if (*st == '\0') + more = FALSE; + else { + repstr[j] = *st; + j++; + if (j >= REPLEN) + return (FALSE); + st++; + state = 0; + } + break; + case 2: + if (*st >= '0' && *st <= '9') { + num = 10 * num + *st - '0'; + st++; + } else { + if (num >= RE_NMATCH) + return (FALSE); + k = re_match[num].rm_eo - re_match[num].rm_so; + if (j + k >= REPLEN) + return (FALSE); + bcopy(&(clp->l_text[re_match[num].rm_so]), &repstr[j], k); + j += k; + if (*st == '\0') + more = FALSE; + if (*st == '\\') { + st++; + state = 1; + } else { + repstr[j] = *st; + j++; + if (j >= REPLEN) + return (FALSE); + st++; + state = 0; + } + } + break; + } /* end case */ + } /* end while */ + + repstr[j] = '\0'; + + s = lreplace(plen, repstr, f); + + return (s); } @@ -333,48 +344,49 @@ re_doreplace(plen, st, f) * is notified of the change, and TRUE is returned. If the * string isn't found, FALSE is returned. */ -re_forwsrch() { - - register LINE *clp; - register int tbo; - int error, plen; - - clp = curwp->w_dotp; - tbo = curwp->w_doto; - - if (tbo == clp->l_used) - /* Don't start matching off end of line-- must - * move to beginning of next line, unless at end - */ - if (clp != curbp->b_linep) { - clp = lforw(clp); - tbo = 0; - } - +re_forwsrch() +{ - /* Note this loop does not process the last line, but this editor - always makes the last line empty so this is good. - */ + register LINE *clp; + register int tbo; + int error, plen; + + clp = curwp->w_dotp; + tbo = curwp->w_doto; + + if (tbo == clp->l_used) + /* + * Don't start matching off end of line-- must move to + * beginning of next line, unless at end + */ + if (clp != curbp->b_linep) { + clp = lforw(clp); + tbo = 0; + } + /* + * Note this loop does not process the last line, but this editor + * always makes the last line empty so this is good. + */ - while (clp != (curbp->b_linep)) { + while (clp != (curbp->b_linep)) { - re_match[0].rm_so = tbo; - re_match[0].rm_eo = llength(clp); - error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND); + re_match[0].rm_so = tbo; + re_match[0].rm_eo = llength(clp); + error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND); - if (error) { - clp = lforw(clp); - tbo = 0; - } else { - curwp->w_doto = re_match[0].rm_eo; - curwp->w_dotp = clp; - curwp->w_flag |= WFMOVE; - return (TRUE); - } + if (error) { + clp = lforw(clp); + tbo = 0; + } else { + curwp->w_doto = re_match[0].rm_eo; + curwp->w_dotp = clp; + curwp->w_flag |= WFMOVE; + return (TRUE); + } - } + } - return(FALSE); + return (FALSE); } @@ -386,59 +398,61 @@ re_forwsrch() { * is notified of the change, and TRUE is returned. If the * string isn't found, FALSE is returned. */ -re_backsrch() { - - register LINE *clp; - register int tbo; - regmatch_t lastmatch; - char m[1]; - - clp = curwp->w_dotp; - tbo = curwp->w_doto; - - /* Start search one position to the left of dot */ - tbo = tbo - 1; - if (tbo < 0) { - /* must move up one line */ - clp = lback(clp); - tbo = llength(clp); - } - - /* Note this loop does not process the last line, but this editor - always makes the last line empty so this is good. - */ - - while (clp != (curbp->b_linep)) { - - re_match[0].rm_so = 0; - re_match[0].rm_eo = llength(clp); - lastmatch.rm_so = -1; - /* Keep searching until we don't match any longer. Assumes a non-match - does not modify the re_match array. We have to do this - character-by-character after the first match since POSIX regexps don't - give you a way to do reverse matches. - */ - while (!regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND) && - re_match[0].rm_so < tbo) { - memcpy(&lastmatch, &re_match[0], sizeof(regmatch_t)); - re_match[0].rm_so++; - re_match[0].rm_eo = llength(clp); - } - - if (lastmatch.rm_so == -1) { - clp = lback(clp); - tbo = llength(clp); - } else { - memcpy(&re_match[0], &lastmatch, sizeof(regmatch_t)); - curwp->w_doto = re_match[0].rm_so; - curwp->w_dotp = clp; - curwp->w_flag |= WFMOVE; - return (TRUE); - } - - } - - return(FALSE); +re_backsrch() +{ + + register LINE *clp; + register int tbo; + regmatch_t lastmatch; + char m[1]; + + clp = curwp->w_dotp; + tbo = curwp->w_doto; + + /* Start search one position to the left of dot */ + tbo = tbo - 1; + if (tbo < 0) { + /* must move up one line */ + clp = lback(clp); + tbo = llength(clp); + } + /* + * Note this loop does not process the last line, but this editor + * always makes the last line empty so this is good. + */ + + while (clp != (curbp->b_linep)) { + + re_match[0].rm_so = 0; + re_match[0].rm_eo = llength(clp); + lastmatch.rm_so = -1; + /* + * Keep searching until we don't match any longer. Assumes a + * non-match does not modify the re_match array. We have to + * do this character-by-character after the first match since + * POSIX regexps don't give you a way to do reverse matches. + */ + while (!regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, + REG_STARTEND) && re_match[0].rm_so < tbo) { + memcpy(&lastmatch, &re_match[0], sizeof(regmatch_t)); + re_match[0].rm_so++; + re_match[0].rm_eo = llength(clp); + } + + if (lastmatch.rm_so == -1) { + clp = lback(clp); + tbo = llength(clp); + } else { + memcpy(&re_match[0], &lastmatch, sizeof(regmatch_t)); + curwp->w_doto = re_match[0].rm_so; + curwp->w_dotp = clp; + curwp->w_flag |= WFMOVE; + return (TRUE); + } + + } + + return (FALSE); } @@ -451,215 +465,231 @@ re_backsrch() { * Display the old pattern, in the style of Jeff Lomicka. There is * some do-it-yourself control expansion. */ -re_readpattern(prompt) char *prompt; { - int s; - int flags; - int error; - char tpat[NPAT]; - static int dofree = 0; +re_readpattern(prompt) + char *prompt; +{ + int s; + int flags; + int error; + char tpat[NPAT]; + static int dofree = 0; - if (re_pat[0] == '\0') s = ereply("%s: ", tpat, NPAT, prompt); - else s = ereply("%s: (default %s) ", tpat, NPAT, prompt, re_pat); + if (re_pat[0] == '\0') + s = ereply("%s: ", tpat, NPAT, prompt); + else + s = ereply("%s: (default %s) ", tpat, NPAT, prompt, re_pat); if (s == TRUE) { - /* New pattern given */ - (VOID) strcpy(re_pat, tpat); - if (casefoldsearch) - flags = REG_EXTENDED|REG_ICASE; - else - flags = REG_EXTENDED; - if (dofree) - regfree(&re_buff); - error = regcomp(&re_buff, re_pat, flags); - if (error) { - char message[256]; - regerror(error, &re_buff, message, sizeof(message)); - ewprintf("Regex Error: %s", message); - re_pat[0] = '\0'; - return(FALSE); - } - dofree = 1; - } - else if (s==FALSE && re_pat[0]!='\0') - /* Just using old pattern */ - s = TRUE; + /* New pattern given */ + (VOID) strcpy(re_pat, tpat); + if (casefoldsearch) + flags = REG_EXTENDED | REG_ICASE; + else + flags = REG_EXTENDED; + if (dofree) + regfree(&re_buff); + error = regcomp(&re_buff, re_pat, flags); + if (error) { + char message[256]; + regerror(error, &re_buff, message, sizeof(message)); + ewprintf("Regex Error: %s", message); + re_pat[0] = '\0'; + return (FALSE); + } + dofree = 1; + } else if (s == FALSE && re_pat[0] != '\0') + /* Just using old pattern */ + s = TRUE; return (s); } -/* Cause case to not matter in searches. This is the default. If - * called with argument cause case to matter. +/* + * Cause case to not matter in searches. This is the default. If called + * with argument cause case to matter. */ -setcasefold(f, n) { +setcasefold(f, n) +{ - if (f & FFARG) { - casefoldsearch = FALSE; - ewprintf("Case-fold-search unset"); - } - else { - casefoldsearch = TRUE; - ewprintf("Case-fold-search set"); - } + if (f & FFARG) { + casefoldsearch = FALSE; + ewprintf("Case-fold-search unset"); + } else { + casefoldsearch = TRUE; + ewprintf("Case-fold-search set"); + } - /* Invalidate the regular expression pattern since I'm too lazy - * to recompile it. - */ + /* + * Invalidate the regular expression pattern since I'm too lazy to + * recompile it. + */ - re_pat[0] = '\0'; + re_pat[0] = '\0'; - return(TRUE); + return (TRUE); -} /* end setcasefold */ +} /* end setcasefold */ -/* Delete all lines after dot that contain a string matching regex +/* + * Delete all lines after dot that contain a string matching regex */ -delmatchlines(f, n) { - int s; +delmatchlines(f, n) +{ + int s; - if ((s=re_readpattern("Flush lines (containing match for regexp)")) != TRUE) - return (s); + if ((s = re_readpattern("Flush lines (containing match for regexp)")) != TRUE) + return (s); - s = killmatches(TRUE); + s = killmatches(TRUE); - return(s); + return (s); } -/* Delete all lines after dot that don't contain a string matching regex +/* + * Delete all lines after dot that don't contain a string matching regex */ -delnonmatchlines(f, n) { - int s; +delnonmatchlines(f, n) +{ + int s; - if ((s=re_readpattern("Keep lines (containing match for regexp)")) != TRUE) - return (s); + if ((s = re_readpattern("Keep lines (containing match for regexp)")) != TRUE) + return (s); - s = killmatches(FALSE); + s = killmatches(FALSE); - return(s); + return (s); } /* This function does the work of deleting matching lines */ killmatches(cond) - int cond; + int cond; { - int s, error; - int count = 0; - LINE *clp; - - clp = curwp->w_dotp; - if (curwp->w_doto == llength(clp)) - /* Consider dot on next line */ - clp = lforw(clp); - - while (clp != (curbp->b_linep)) { - - /* see if line matches */ - re_match[0].rm_so = 0; - re_match[0].rm_eo = llength(clp); - error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND); - - /* Delete line when appropriate */ - if ((cond == FALSE && error) || (cond == TRUE && !error)) { - curwp->w_doto = 0; - curwp->w_dotp = clp; - count++; - s = ldelete(llength(clp)+1, KNONE); - clp = curwp->w_dotp; - curwp->w_flag |= WFMOVE; - if (s == FALSE) return(FALSE); - } - else - clp = lforw(clp); - } - - ewprintf("%d line(s) deleted", count); - if (count > 0) curwp->w_flag |= WFMOVE; - - return(TRUE); + int s, error; + int count = 0; + LINE *clp; + + clp = curwp->w_dotp; + if (curwp->w_doto == llength(clp)) + /* Consider dot on next line */ + clp = lforw(clp); + + while (clp != (curbp->b_linep)) { + + /* see if line matches */ + re_match[0].rm_so = 0; + re_match[0].rm_eo = llength(clp); + error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND); + + /* Delete line when appropriate */ + if ((cond == FALSE && error) || (cond == TRUE && !error)) { + curwp->w_doto = 0; + curwp->w_dotp = clp; + count++; + s = ldelete(llength(clp) + 1, KNONE); + clp = curwp->w_dotp; + curwp->w_flag |= WFMOVE; + if (s == FALSE) + return (FALSE); + } else + clp = lforw(clp); + } + + ewprintf("%d line(s) deleted", count); + if (count > 0) + curwp->w_flag |= WFMOVE; + + return (TRUE); } -petersfunc(f, n) { +petersfunc(f, n) +{ - int s; - LINE *clp; - char c; + int s; + LINE *clp; + char c; - curwp->w_doto = 0; - s = ldelete(llength(curwp->w_dotp)+1, KNONE); - curwp->w_flag |= WFMOVE; - return(s); + curwp->w_doto = 0; + s = ldelete(llength(curwp->w_dotp) + 1, KNONE); + curwp->w_flag |= WFMOVE; + return (s); } -/* Count lines matching regex +/* + * Count lines matching regex */ -cntmatchlines(f, n) { - int s; +cntmatchlines(f, n) +{ + int s; - if ((s=re_readpattern("Count lines (matching regexp)")) != TRUE) - return (s); + if ((s = re_readpattern("Count lines (matching regexp)")) != TRUE) + return (s); - s = countmatches(TRUE); + s = countmatches(TRUE); - return(s); + return (s); } -/* Count lines that fail to match regex +/* + * Count lines that fail to match regex */ -cntnonmatchlines(f, n) { - int s; +cntnonmatchlines(f, n) +{ + int s; - if ((s=re_readpattern("Count lines (not matching regexp)")) != TRUE) - return (s); + if ((s = re_readpattern("Count lines (not matching regexp)")) != TRUE) + return (s); - s = countmatches(FALSE); + s = countmatches(FALSE); - return(s); + return (s); } /* This function does the work of counting matching lines */ countmatches(cond) - int cond; + int cond; { - int s, error; - int count = 0; - LINE *clp; - - clp = curwp->w_dotp; - if (curwp->w_doto == llength(clp)) - /* Consider dot on next line */ - clp = lforw(clp); - - while (clp != (curbp->b_linep)) { - - /* see if line matches */ - re_match[0].rm_so = 0; - re_match[0].rm_eo = llength(clp); - error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND); - - /* Count line when appropriate */ - if ((cond == FALSE && error) || (cond == TRUE && !error)) count++; - clp = lforw(clp); - } + int s, error; + int count = 0; + LINE *clp; + + clp = curwp->w_dotp; + if (curwp->w_doto == llength(clp)) + /* Consider dot on next line */ + clp = lforw(clp); + + while (clp != (curbp->b_linep)) { + + /* see if line matches */ + re_match[0].rm_so = 0; + re_match[0].rm_eo = llength(clp); + error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND); + + /* Count line when appropriate */ + if ((cond == FALSE && error) || (cond == TRUE && !error)) + count++; + clp = lforw(clp); + } - if (cond) - ewprintf("Number of lines matching: %d", count); - else - ewprintf("Number of lines not matching: %d", count); + if (cond) + ewprintf("Number of lines matching: %d", count); + else + ewprintf("Number of lines not matching: %d", count); - return(TRUE); + return (TRUE); } #endif diff --git a/usr.bin/mg/region.c b/usr.bin/mg/region.c index 8112296f81a..0c3395150c0 100644 --- a/usr.bin/mg/region.c +++ b/usr.bin/mg/region.c @@ -13,17 +13,17 @@ * to figure out the bounds of the region. * Move "." to the start, and kill the characters. */ -/*ARGSUSED*/ +/* ARGSUSED */ killregion(f, n) { - register int s; - REGION region; + register int s; + REGION region; - if ((s=getregion(®ion)) != TRUE) + if ((s = getregion(®ion)) != TRUE) return (s); - if ((lastflag&CFKILL) == 0) /* This is a kill type */ - kdelete(); /* command, so do magic */ - thisflag |= CFKILL; /* kill buffer stuff. */ + if ((lastflag & CFKILL) == 0) /* This is a kill type */ + kdelete(); /* command, so do magic */ + thisflag |= CFKILL; /* kill buffer stuff. */ curwp->w_dotp = region.r_linep; curwp->w_doto = region.r_offset; return (ldelete(region.r_size, KFORW)); @@ -35,30 +35,30 @@ killregion(f, n) * at all. This is a bit like a kill region followed * by a yank. */ -/*ARGSUSED*/ +/* ARGSUSED */ copyregion(f, n) { - register LINE *linep; - register int loffs; - register int s; - REGION region; - VOID kdelete(); + register LINE *linep; + register int loffs; + register int s; + REGION region; + VOID kdelete(); - if ((s=getregion(®ion)) != TRUE) + if ((s = getregion(®ion)) != TRUE) return s; - if ((lastflag&CFKILL) == 0) /* Kill type command. */ + if ((lastflag & CFKILL) == 0) /* Kill type command. */ kdelete(); thisflag |= CFKILL; - linep = region.r_linep; /* Current line. */ - loffs = region.r_offset; /* Current offset. */ + linep = region.r_linep; /* Current line. */ + loffs = region.r_offset;/* Current offset. */ while (region.r_size--) { - if (loffs == llength(linep)) { /* End of line. */ - if ((s=kinsert('\n', KFORW)) != TRUE) + if (loffs == llength(linep)) { /* End of line. */ + if ((s = kinsert('\n', KFORW)) != TRUE) return (s); linep = lforw(linep); loffs = 0; - } else { /* Middle of line. */ - if ((s=kinsert(lgetc(linep, loffs), KFORW)) != TRUE) + } else { /* Middle of line. */ + if ((s = kinsert(lgetc(linep, loffs), KFORW)) != TRUE) return s; ++loffs; } @@ -73,16 +73,16 @@ copyregion(f, n) * doing the changes. Call "lchange" to ensure that * redisplay is done in all buffers. */ -/*ARGSUSED*/ +/* ARGSUSED */ lowerregion(f, n) { - register LINE *linep; - register int loffs; - register int c; - register int s; - REGION region; + register LINE *linep; + register int loffs; + register int c; + register int s; + REGION region; - if ((s=getregion(®ion)) != TRUE) + if ((s = getregion(®ion)) != TRUE) return s; lchange(WFHARD); linep = region.r_linep; @@ -108,17 +108,17 @@ lowerregion(f, n) * doing the changes. Call "lchange" to ensure that * redisplay is done in all buffers. */ -/*ARGSUSED*/ +/* ARGSUSED */ upperregion(f, n) { - register LINE *linep; - register int loffs; - register int c; - register int s; - REGION region; - VOID lchange(); + register LINE *linep; + register int loffs; + register int c; + register int s; + REGION region; + VOID lchange(); - if ((s=getregion(®ion)) != TRUE) + if ((s = getregion(®ion)) != TRUE) return s; lchange(WFHARD); linep = region.r_linep; @@ -150,60 +150,65 @@ upperregion(f, n) * get an ABORT status, because I might add a "if regions is big, * ask before clobberring" flag. */ -getregion(rp) register REGION *rp; { - register LINE *flp; - register LINE *blp; - register long fsize; /* Long now. */ - register long bsize; +getregion(rp) + register REGION *rp; +{ + register LINE *flp; + register LINE *blp; + register long fsize; /* Long now. */ + register long bsize; if (curwp->w_markp == NULL) { ewprintf("No mark set in this window"); return (FALSE); } - if (curwp->w_dotp == curwp->w_markp) { /* "r_size" always ok. */ + if (curwp->w_dotp == curwp->w_markp) { /* "r_size" always ok. */ rp->r_linep = curwp->w_dotp; if (curwp->w_doto < curwp->w_marko) { rp->r_offset = curwp->w_doto; - rp->r_size = (RSIZE) (curwp->w_marko-curwp->w_doto); + rp->r_size = (RSIZE) (curwp->w_marko - curwp->w_doto); } else { rp->r_offset = curwp->w_marko; - rp->r_size = (RSIZE) (curwp->w_doto-curwp->w_marko); + rp->r_size = (RSIZE) (curwp->w_doto - curwp->w_marko); } return TRUE; } - flp = blp = curwp->w_dotp; /* Get region size. */ + flp = blp = curwp->w_dotp; /* Get region size. */ bsize = curwp->w_doto; - fsize = llength(flp)-curwp->w_doto+1; - while (lforw(flp)!=curbp->b_linep || lback(blp)!=curbp->b_linep) { + fsize = llength(flp) - curwp->w_doto + 1; + while (lforw(flp) != curbp->b_linep || lback(blp) != curbp->b_linep) { if (lforw(flp) != curbp->b_linep) { flp = lforw(flp); if (flp == curwp->w_markp) { rp->r_linep = curwp->w_dotp; rp->r_offset = curwp->w_doto; return (setsize(rp, - (RSIZE) (fsize+curwp->w_marko))); + (RSIZE) (fsize + curwp->w_marko))); } - fsize += llength(flp)+1; + fsize += llength(flp) + 1; } if (lback(blp) != curbp->b_linep) { blp = lback(blp); - bsize += llength(blp)+1; + bsize += llength(blp) + 1; if (blp == curwp->w_markp) { rp->r_linep = blp; rp->r_offset = curwp->w_marko; return (setsize(rp, - (RSIZE) (bsize-curwp->w_marko))); + (RSIZE) (bsize - curwp->w_marko))); } } } - ewprintf("Bug: lost mark"); /* Gak! */ + ewprintf("Bug: lost mark"); /* Gak! */ return FALSE; } /* * Set size, and check for overflow. */ -setsize(rp, size) register REGION *rp; register RSIZE size; { +setsize(rp, size) + register REGION *rp; + register RSIZE size; +{ rp->r_size = size; if (rp->r_size != size) { @@ -223,7 +228,7 @@ setsize(rp, size) register REGION *rp; register RSIZE size; { */ #define PREFIXLENGTH 40 -static char prefix_string[PREFIXLENGTH] = { '>', '\0' }; +static char prefix_string[PREFIXLENGTH] = {'>', '\0'}; /* * Prefix the region with whatever is in prefix_string. @@ -232,14 +237,14 @@ static char prefix_string[PREFIXLENGTH] = { '>', '\0' }; * line prefix string. */ -/*ARGSUSED*/ +/* ARGSUSED */ prefixregion(f, n) { - register int s; - register LINE *first, *last; - register int nline; - REGION region; - char *prefix = prefix_string; + register int s; + register LINE *first, *last; + register int nline; + REGION region; + char *prefix = prefix_string; if ((f == TRUE) && ((s = setprefix(FFRAND, 1)) != TRUE)) return s; @@ -252,7 +257,7 @@ prefixregion(f, n) for (nline = 1; first != last; nline++) first = lforw(first); - /*move to beginning of region */ + /* move to beginning of region */ curwp->w_dotp = region.r_linep; curwp->w_doto = region.r_offset; @@ -271,20 +276,20 @@ prefixregion(f, n) * Set prefix string. */ -/*ARGSUSED*/ +/* ARGSUSED */ setprefix(f, n) { - char buf[PREFIXLENGTH]; - register int s; + char buf[PREFIXLENGTH]; + register int s; if (prefix_string[0] == '\0') - s = ereply("Prefix string: ",buf,sizeof buf); + s = ereply("Prefix string: ", buf, sizeof buf); else s = ereply("Prefix string (default %s): ", - buf,sizeof buf,prefix_string); + buf, sizeof buf, prefix_string); if (s == TRUE) (VOID) strcpy(prefix_string, buf); - if ((s == FALSE) && (prefix_string[0] != '\0')) /* CR -- use old one */ + if ((s == FALSE) && (prefix_string[0] != '\0')) /* CR -- use old one */ s = TRUE; return s; } diff --git a/usr.bin/mg/search.c b/usr.bin/mg/search.c index 3d127ce1f02..ac384539222 100644 --- a/usr.bin/mg/search.c +++ b/usr.bin/mg/search.c @@ -13,33 +13,33 @@ #include "macro.h" #endif -#define SRCH_BEGIN (0) /* Search sub-codes. */ +#define SRCH_BEGIN (0) /* Search sub-codes. */ #define SRCH_FORW (-1) #define SRCH_BACK (-2) #define SRCH_NOPR (-3) #define SRCH_ACCM (-4) #define SRCH_MARK (-5) -typedef struct { - int s_code; - LINE *s_dotp; - int s_doto; -} SRCHCOM; +typedef struct { + int s_code; + LINE *s_dotp; + int s_doto; +} SRCHCOM; -static SRCHCOM cmds[NSRCH]; -static int cip; +static SRCHCOM cmds[NSRCH]; +static int cip; -int srch_lastdir = SRCH_NOPR; /* Last search flags. */ +int srch_lastdir = SRCH_NOPR; /* Last search flags. */ -static VOID is_cpush(); -static VOID is_lpush(); -static VOID is_pop(); -static int is_peek(); -static VOID is_undo(); -static int is_find(); -static VOID is_prompt(); -static VOID is_dspl(); -static int eq(); +static VOID is_cpush(); +static VOID is_lpush(); +static VOID is_pop(); +static int is_peek(); +static VOID is_undo(); +static int is_find(); +static VOID is_prompt(); +static VOID is_dspl(); +static int eq(); /* * Search forward. @@ -48,12 +48,12 @@ static int eq(); * matched characters, and display does all the hard stuff. * If not found, it just prints a message. */ -/*ARGSUSED*/ +/* ARGSUSED */ forwsearch(f, n) { - register int s; + register int s; - if ((s=readpattern("Search")) != TRUE) + if ((s = readpattern("Search")) != TRUE) return s; if (forwsrch() == FALSE) { ewprintf("Search failed: \"%s\"", pat); @@ -70,12 +70,12 @@ forwsearch(f, n) * pointing at the first character of the pattern [the last character that * was matched]. */ -/*ARGSUSED*/ +/* ARGSUSED */ backsearch(f, n) { - register int s; + register int s; - if ((s=readpattern("Search backward")) != TRUE) + if ((s = readpattern("Search backward")) != TRUE) return (s); if (backsrch() == FALSE) { ewprintf("Search failed: \"%s\"", pat); @@ -91,7 +91,7 @@ backsearch(f, n) * has been saved in "srch_lastdir", so you know which way * to go. */ -/*ARGSUSED*/ +/* ARGSUSED */ searchagain(f, n) { if (srch_lastdir == SRCH_FORW) { @@ -116,7 +116,7 @@ searchagain(f, n) * Use incremental searching, initially in the forward direction. * isearch ignores any explicit arguments. */ -/*ARGSUSED*/ +/* ARGSUSED */ forwisearch(f, n) { return isearch(SRCH_FORW); @@ -126,7 +126,7 @@ forwisearch(f, n) * Use incremental searching, initially in the reverse direction. * isearch ignores any explicit arguments. */ -/*ARGSUSED*/ +/* ARGSUSED */ backisearch(f, n) { return isearch(SRCH_BACK); @@ -143,22 +143,23 @@ backisearch(f, n) * other ^ exit search, don't set mark * else accumulate into search string */ -isearch(dir) { - register int c; - register LINE *clp; - register int cbo; - register int success; - int pptr; - char opat[NPAT]; - VOID ungetkey(); +isearch(dir) +{ + register int c; + register LINE *clp; + register int cbo; + register int success; + int pptr; + char opat[NPAT]; + VOID ungetkey(); #ifndef NO_MACRO - if(macrodef) { - ewprintf("Can't isearch in macro"); - return FALSE; + if (macrodef) { + ewprintf("Can't isearch in macro"); + return FALSE; } #endif - for (cip=0; cip<NSRCH; cip++) + for (cip = 0; cip < NSRCH; cip++) cmds[cip].s_code = SRCH_NOPR; (VOID) strcpy(opat, pat); cip = 0; @@ -203,12 +204,13 @@ isearch(dir) { is_cpush(SRCH_FORW); success = TRUE; } - if (success==FALSE && dir==SRCH_FORW) + if (success == FALSE && dir == SRCH_FORW) break; is_lpush(); pptr = strlen(pat); (VOID) forwchar(FFRAND, 1); - if (is_find(SRCH_FORW) != FALSE) is_cpush(SRCH_MARK); + if (is_find(SRCH_FORW) != FALSE) + is_cpush(SRCH_MARK); else { (VOID) backchar(FFRAND, 1); ttbeep(); @@ -224,12 +226,13 @@ isearch(dir) { is_cpush(SRCH_BACK); success = TRUE; } - if (success==FALSE && dir==SRCH_BACK) + if (success == FALSE && dir == SRCH_BACK) break; is_lpush(); pptr = strlen(pat); (VOID) backchar(FFRAND, 1); - if (is_find(SRCH_BACK) != FALSE) is_cpush(SRCH_MARK); + if (is_find(SRCH_BACK) != FALSE) + is_cpush(SRCH_MARK); else { (VOID) forwchar(FFRAND, 1); ttbeep(); @@ -241,17 +244,18 @@ isearch(dir) { case CCHR('H'): case CCHR('?'): is_undo(&pptr, &dir); - if (is_peek() != SRCH_ACCM) success = TRUE; + if (is_peek() != SRCH_ACCM) + success = TRUE; is_prompt(dir, pptr < 0, success); break; case CCHR('\\'): case CCHR('Q'): c = (char) getkey(FALSE); - goto addchar; + goto addchar; case CCHR('M'): c = CCHR('J'); - goto addchar; + goto addchar; default: if (ISCTRL(c)) { @@ -260,11 +264,11 @@ isearch(dir) { curwp->w_marko = cbo; ewprintf("Mark set"); curwp->w_flag |= WFMOVE; - return TRUE; + return TRUE; } /* and continue */ case CCHR('I'): case CCHR('J'): - addchar: + addchar: if (pptr == -1) pptr = 0; if (pptr == 0) @@ -289,21 +293,24 @@ isearch(dir) { is_prompt(dir, FALSE, success); } } - /*NOTREACHED*/ + /* NOTREACHED */ } -static VOID -is_cpush(cmd) register int cmd; { +static VOID +is_cpush(cmd) + register int cmd; +{ if (++cip >= NSRCH) cip = 0; cmds[cip].s_code = cmd; } -static VOID -is_lpush() { - register int ctp; +static VOID +is_lpush() +{ + register int ctp; - ctp = cip+1; + ctp = cip + 1; if (ctp >= NSRCH) ctp = 0; cmds[ctp].s_code = SRCH_NOPR; @@ -311,27 +318,32 @@ is_lpush() { cmds[ctp].s_dotp = curwp->w_dotp; } -static VOID -is_pop() { +static VOID +is_pop() +{ if (cmds[cip].s_code != SRCH_NOPR) { - curwp->w_doto = cmds[cip].s_doto; - curwp->w_dotp = cmds[cip].s_dotp; + curwp->w_doto = cmds[cip].s_doto; + curwp->w_dotp = cmds[cip].s_dotp; curwp->w_flag |= WFMOVE; cmds[cip].s_code = SRCH_NOPR; } if (--cip <= 0) - cip = NSRCH-1; + cip = NSRCH - 1; } static int -is_peek() { +is_peek() +{ return cmds[cip].s_code; } /* this used to always return TRUE (the return value was checked) */ -static VOID -is_undo(pptr, dir) register int *pptr; register int *dir; { - register int redo = FALSE ; +static VOID +is_undo(pptr, dir) + register int *pptr; + register int *dir; +{ + register int redo = FALSE; switch (cmds[cip].s_code) { case SRCH_BEGIN: case SRCH_NOPR: @@ -358,19 +370,22 @@ is_undo(pptr, dir) register int *pptr; register int *dir; { break; } is_pop(); - if (redo) is_undo(pptr, dir); + if (redo) + is_undo(pptr, dir); } static int -is_find(dir) register int dir; { - register int plen, odoto; - register LINE *odotp ; +is_find(dir) + register int dir; +{ + register int plen, odoto; + register LINE *odotp; odoto = curwp->w_doto; odotp = curwp->w_dotp; plen = strlen(pat); if (plen != 0) { - if (dir==SRCH_FORW) { + if (dir == SRCH_FORW) { (VOID) backchar(FFARG | FFRAND, plen); if (forwsrch() == FALSE) { curwp->w_doto = odoto; @@ -379,7 +394,7 @@ is_find(dir) register int dir; { } return TRUE; } - if (dir==SRCH_BACK) { + if (dir == SRCH_BACK) { (VOID) forwchar(FFARG | FFRAND, plen); if (backsrch() == FALSE) { curwp->w_doto = odoto; @@ -402,8 +417,9 @@ is_find(dir) register int dir; { * of the callers looked at the status, so I just * made the checking vanish. */ -static VOID -is_prompt(dir, flag, success) { +static VOID +is_prompt(dir, flag, success) +{ if (dir == SRCH_FORW) { if (success != FALSE) is_dspl("I-search", flag); @@ -414,7 +430,8 @@ is_prompt(dir, flag, success) { is_dspl("I-search backward", flag); else is_dspl("Failing I-search backward", flag); - } else ewprintf("Broken call to is_prompt"); + } else + ewprintf("Broken call to is_prompt"); } /* @@ -422,8 +439,10 @@ is_prompt(dir, flag, success) { * The "prompt" is just a string. The "flag" determines * whether pat should be printed. */ -static VOID -is_dspl(prompt, flag) char *prompt; { +static VOID +is_dspl(prompt, flag) + char *prompt; +{ if (flag != FALSE) ewprintf("%s: ", prompt); @@ -435,23 +454,23 @@ is_dspl(prompt, flag) char *prompt; { * Query Replace. * Replace strings selectively. Does a search and replace operation. */ -/*ARGSUSED*/ +/* ARGSUSED */ queryrepl(f, n) { - register int s; - register int rcnt = 0; /* Replacements made so far */ - register int plen; /* length of found string */ - char news[NPAT]; /* replacement string */ + register int s; + register int rcnt = 0; /* Replacements made so far */ + register int plen; /* length of found string */ + char news[NPAT]; /* replacement string */ #ifndef NO_MACRO - if(macrodef) { - ewprintf("Can't query replace in macro"); - return FALSE; + if (macrodef) { + ewprintf("Can't query replace in macro"); + return FALSE; } #endif - if ((s=readpattern("Query replace")) != TRUE) + if ((s = readpattern("Query replace")) != TRUE) return (s); - if ((s=ereply("Query replace %s with: ",news, NPAT, pat)) == ABORT) + if ((s = ereply("Query replace %s with: ", news, NPAT, pat)) == ABORT) return (s); if (s == FALSE) news[0] = '\0'; @@ -465,7 +484,7 @@ queryrepl(f, n) */ while (forwsrch() == TRUE) { - retry: +retry: update(); switch (getkey(FALSE)) { case ' ': @@ -480,7 +499,7 @@ queryrepl(f, n) rcnt++; goto stopsearch; - case CCHR('G'): /* ^G or ESC */ + case CCHR('G'):/* ^G or ESC */ (VOID) ctrlg(FFRAND, 0); case CCHR('['): goto stopsearch; @@ -494,11 +513,11 @@ queryrepl(f, n) goto stopsearch; case CCHR('H'): - case CCHR('?'): /* To not replace */ + case CCHR('?'):/* To not replace */ break; default: -ewprintf("<SP> replace, [.] rep-end, <DEL> don't, [!] repl rest <ESC> quit"); + ewprintf("<SP> replace, [.] rep-end, <DEL> don't, [!] repl rest <ESC> quit"); goto retry; } } @@ -521,19 +540,21 @@ stopsearch: * is notified of the change, and TRUE is returned. If the * string isn't found, FALSE is returned. */ -forwsrch() { - register LINE *clp; - register int cbo; - register LINE *tlp; - register int tbo; - char *pp; - register int c; +forwsrch() +{ + register LINE *clp; + register int cbo; + register LINE *tlp; + register int tbo; + char *pp; + register int c; clp = curwp->w_dotp; cbo = curwp->w_doto; - for(;;) { + for (;;) { if (cbo == llength(clp)) { - if((clp = lforw(clp)) == curbp->b_linep) break; + if ((clp = lforw(clp)) == curbp->b_linep) + break; cbo = 0; c = CCHR('J'); } else @@ -541,7 +562,7 @@ forwsrch() { if (eq(c, pat[0]) != FALSE) { tlp = clp; tbo = cbo; - pp = &pat[1]; + pp = &pat[1]; while (*pp != 0) { if (tbo == llength(tlp)) { tlp = lforw(tlp); @@ -554,12 +575,12 @@ forwsrch() { if (eq(c, *pp++) == FALSE) goto fail; } - curwp->w_dotp = tlp; - curwp->w_doto = tbo; + curwp->w_dotp = tlp; + curwp->w_doto = tbo; curwp->w_flag |= WFMOVE; return TRUE; } - fail: ; +fail: ; } return FALSE; } @@ -571,17 +592,17 @@ forwsrch() { * is notified of the change, and TRUE is returned. If the * string isn't found, FALSE is returned. */ -backsrch() { - register LINE *clp; - register int cbo; - register LINE *tlp; - register int tbo; - register int c; - register char *epp; - register char *pp; - - for (epp = &pat[0]; epp[1] != 0; ++epp) - ; +backsrch() +{ + register LINE *clp; + register int cbo; + register LINE *tlp; + register int tbo; + register int c; + register char *epp; + register char *pp; + + for (epp = &pat[0]; epp[1] != 0; ++epp); clp = curwp->w_dotp; cbo = curwp->w_doto; for (;;) { @@ -589,38 +610,38 @@ backsrch() { clp = lback(clp); if (clp == curbp->b_linep) return FALSE; - cbo = llength(clp)+1; + cbo = llength(clp) + 1; } if (--cbo == llength(clp)) c = CCHR('J'); else - c = lgetc(clp,cbo); + c = lgetc(clp, cbo); if (eq(c, *epp) != FALSE) { tlp = clp; tbo = cbo; - pp = epp; + pp = epp; while (pp != &pat[0]) { if (tbo == 0) { tlp = lback(tlp); if (tlp == curbp->b_linep) goto fail; - tbo = llength(tlp)+1; + tbo = llength(tlp) + 1; } if (--tbo == llength(tlp)) c = CCHR('J'); else - c = lgetc(tlp,tbo); + c = lgetc(tlp, tbo); if (eq(c, *--pp) == FALSE) goto fail; } - curwp->w_dotp = tlp; - curwp->w_doto = tbo; + curwp->w_dotp = tlp; + curwp->w_doto = tbo; curwp->w_flag |= WFMOVE; return TRUE; } - fail: ; +fail: ; } - /*NOTREACHED*/ + /* NOTREACHED */ } /* @@ -631,13 +652,16 @@ backsrch() { */ static int eq(bc, pc) -register int bc, pc; + register int bc, pc; { bc = CHARMASK(bc); pc = CHARMASK(pc); - if (bc == pc) return TRUE; - if (ISUPPER(bc)) return TOLOWER(bc) == pc; - if (ISUPPER(pc)) return bc == TOLOWER(pc); + if (bc == pc) + return TRUE; + if (ISUPPER(bc)) + return TOLOWER(bc) == pc; + if (ISUPPER(pc)) + return bc == TOLOWER(pc); return FALSE; } @@ -649,16 +673,20 @@ register int bc, pc; * Display the old pattern, in the style of Jeff Lomicka. There is * some do-it-yourself control expansion. */ -readpattern(prompt) char *prompt; { - register int s; - char tpat[NPAT]; +readpattern(prompt) + char *prompt; +{ + register int s; + char tpat[NPAT]; - if (tpat[0] == '\0') s = ereply("%s: ", tpat, NPAT, prompt); - else s = ereply("%s: (default %s) ", tpat, NPAT, prompt, pat); + if (tpat[0] == '\0') + s = ereply("%s: ", tpat, NPAT, prompt); + else + s = ereply("%s: (default %s) ", tpat, NPAT, prompt, pat); - if (s == TRUE) /* Specified */ + if (s == TRUE) /* Specified */ (VOID) strcpy(pat, tpat); - else if (s==FALSE && pat[0]!=0) /* CR, but old one */ + else if (s == FALSE && pat[0] != 0) /* CR, but old one */ s = TRUE; return s; } diff --git a/usr.bin/mg/spawn.c b/usr.bin/mg/spawn.c index 800592d68bc..e8708064522 100644 --- a/usr.bin/mg/spawn.c +++ b/usr.bin/mg/spawn.c @@ -6,6 +6,7 @@ #include <signal.h> #include <termios.h> +#include <term.h> /* * This causes mg to send itself a stop signal. diff --git a/usr.bin/mg/sysdef.h b/usr.bin/mg/sysdef.h index b2964fbc179..794d15d1d41 100644 --- a/usr.bin/mg/sysdef.h +++ b/usr.bin/mg/sysdef.h @@ -6,13 +6,13 @@ #include <stdlib.h> #include <string.h> -#define KBLOCK 8192 /* Kill grow. */ -#define GOOD 0 /* Good exit status. */ -#define SYMBLINK 1 /* Handle symbolic links */ -#define MAXPATH PATH_MAX /* Maximum length of path for chdir */ +#define KBLOCK 8192 /* Kill grow. */ +#define GOOD 0 /* Good exit status. */ +#define SYMBLINK 1 /* Handle symbolic links */ +#define MAXPATH PATH_MAX /* Maximum length of path for chdir */ -typedef int RSIZE; /* Type for file/region sizes */ -typedef short KCHAR; /* Type for internal keystrokes */ +typedef int RSIZE; /* Type for file/region sizes */ +typedef short KCHAR; /* Type for internal keystrokes */ /* * Macros used by the buffer name making code. @@ -22,15 +22,15 @@ typedef short KCHAR; /* Type for internal keystrokes */ * stops at end of string (or at the next BDC3 character, * if defined). BDC2 and BDC3 are mainly for VMS. */ -#define BDC1 '/' /* Buffer names. */ +#define BDC1 '/' /* Buffer names. */ -#define MALLOCROUND(m) (m+=7,m&=~7) /* round up to 8 byte boundry */ +#define MALLOCROUND(m) (m+=7,m&=~7) /* round up to 8 byte boundry */ -#define fncmp strcmp /* file name comparison */ -#define gettermtype() getenv("TERM") /* determine terminal type */ +#define fncmp strcmp /* file name comparison */ +#define gettermtype() getenv("TERM") /* determine terminal type */ struct fileinfo { - mode_t fi_mode; - uid_t fi_uid; - gid_t short fi_gid; + mode_t fi_mode; + uid_t fi_uid; + gid_t short fi_gid; }; diff --git a/usr.bin/mg/tty.c b/usr.bin/mg/tty.c index 7cf082667bc..e976f608ca7 100644 --- a/usr.bin/mg/tty.c +++ b/usr.bin/mg/tty.c @@ -6,66 +6,65 @@ * this as a reasonable way to allow for widly varying and ever changing * varieties of terminal types. This should be used where practical. */ -/* Known problems: - * If you have a terminal with no clear to end of screen and - * memory of lines below the ones visible on the screen, display - * will be wrong in some cases. I doubt that any such terminal - * was ever made, but I thought everyone with delete line would - * have clear to end of screen too... +/* + * Known problems: If you have a terminal with no clear to end of screen and + * memory of lines below the ones visible on the screen, display will be + * wrong in some cases. I doubt that any such terminal was ever made, but I + * thought everyone with delete line would have clear to end of screen too... * - * Code for terminals without clear to end of screen and/or clear - * to end of line has not been extensivly tested. + * Code for terminals without clear to end of screen and/or clear to end of line + * has not been extensivly tested. * - * Cost calculations are very rough. Costs of insert/delete line - * may be far from the truth. This is accentuated by display.c - * not knowing about multi-line insert/delete. + * Cost calculations are very rough. Costs of insert/delete line may be far + * from the truth. This is accentuated by display.c not knowing about + * multi-line insert/delete. * - * Using scrolling region vs insert/delete line should probably - * be based on cost rather than the assuption that scrolling - * region operations look better. + * Using scrolling region vs insert/delete line should probably be based on cost + * rather than the assuption that scrolling region operations look better. */ #include "def.h" -#include <curses.h> #include <term.h> -extern int ttrow; -extern int ttcol; -extern int tttop; -extern int ttbot; -extern int tthue; +extern int ttrow; +extern int ttcol; +extern int tttop; +extern int ttbot; +extern int tthue; -extern int ttputc(); +extern int ttputc(); -int tceeol; /* Costs are set later */ -int tcinsl; -int tcdell; +int tceeol; /* Costs are set later */ +int tcinsl; +int tcdell; -static int insdel; /* Do we have both insert & delete line? */ -static char * scroll_fwd; /* How to scroll forward. */ +static int insdel; /* Do we have both insert & delete line? */ +static char *scroll_fwd; /* How to scroll forward. */ #ifdef NO_RESIZE -static setttysize(); +static setttysize(); #endif /* * Initialize the terminal when the editor * gets started up. */ -ttinit() { - char *tv_stype; - char *t, *p; +VOID +ttinit() +{ + char *tv_stype; + char *t, *p; #ifndef gettermtype /* (avoid declaration if #define) */ - char *gettermtype(); /* system dependent function to determin terminal type */ + char *gettermtype(); /* system dependent function to + * determin terminal type */ #endif if ((tv_stype = gettermtype()) == NULL) panic("Could not determine terminal type"); - if (setupterm(tv_stype, 1, NULL) == ERR) { + if (setupterm(tv_stype, 1, NULL)) { (void) asprintf(&p, "Unknown terminal type: %s", tv_stype); panic(p); } - scroll_fwd = scroll_forward; if (!scroll_fwd || !*scroll_fwd) { /* this is what GNU Emacs does */ @@ -73,10 +72,9 @@ ttinit() { if (!scroll_fwd || !*scroll_fwd) scroll_fwd = "\n"; } - if (!cursor_address || !cursor_up) panic("This terminal is to stupid to run mg"); - ttresize(); /* set nrow & ncol */ + ttresize(); /* set nrow & ncol */ if (!clr_eol) tceeol = ncol; @@ -85,8 +83,8 @@ ttinit() { /* Estimate cost of inserting a line */ if (change_scroll_region && scroll_reverse) - tcinsl = charcost(change_scroll_region)*2 + - charcost(scroll_reverse); + tcinsl = charcost(change_scroll_region) * 2 + + charcost(scroll_reverse); else if (parm_insert_line) tcinsl = charcost(parm_insert_line); else if (insert_line) @@ -96,20 +94,20 @@ ttinit() { /* Estimate cost of deleting a line */ if (change_scroll_region) - tcdell = charcost(change_scroll_region)*2 + - charcost(scroll_fwd); + tcdell = charcost(change_scroll_region) * 2 + + charcost(scroll_fwd); else if (parm_delete_line) tcdell = charcost(parm_delete_line); else if (delete_line) tcdell = charcost(delete_line); - else + else tcdell = NROW * NCOL; /* make this cost high enough */ /* Flag to indicate that we can both insert and delete lines */ insdel = (insert_line || parm_insert_line) && (delete_line || parm_delete_line); if (enter_ca_mode) - putpad(enter_ca_mode, 1); /* init the term */ + putpad(enter_ca_mode, 1); /* enter application mode */ setttysize(); } @@ -118,7 +116,9 @@ ttinit() { * Re-initialize the terminal when the editor is resumed. * The keypad_xmit doesn't really belong here but... */ -ttreinit() { +VOID +ttreinit() +{ if (enter_ca_mode) putpad(enter_ca_mode, 1); /* enter application mode */ if (keypad_xmit) @@ -135,14 +135,16 @@ ttreinit() { * query the display for the increment, and put it * back to what it was. */ -tttidy() { +VOID +tttidy() +{ - /* set the term back to normal mode */ - if (exit_ca_mode) - putpad(exit_ca_mode, 1); #ifdef XKEYS ttykeymaptidy(); #endif + /* set the term back to normal mode */ + if (exit_ca_mode) + putpad(exit_ca_mode, 1); } /* @@ -152,25 +154,29 @@ tttidy() { * have left the cursor in the right * location last time! */ -ttmove(row, col) { - char *tgoto(); - - if (ttrow != row || ttcol !=col) { - putpad(tgoto(cursor_address, col, row), 1); - ttrow = row; - ttcol = col; - } +VOID +ttmove(row, col) +{ + char *tgoto(); + + if (ttrow != row || ttcol != col) { + putpad(tgoto(cursor_address, col, row), 1); + ttrow = row; + ttcol = col; + } } /* * Erase to end of line. */ -tteeol() { +VOID +tteeol() +{ if (clr_eol) putpad(clr_eol, 1); else { - int i = ncol - ttcol; + int i = ncol - ttcol; while (i--) ttputc(' '); ttrow = ttcol = HUGE; @@ -180,8 +186,10 @@ tteeol() { /* * Erase to end of page. */ -tteeop() { - int line; +VOID +tteeop() +{ + int line; if (clr_eos) putpad(clr_eos, nrow - ttrow); @@ -202,7 +210,9 @@ tteeop() { /* * Make a noise. */ -ttbeep() { +VOID +ttbeep() +{ putpad(bell, 1); ttflush(); } @@ -215,31 +225,33 @@ ttbeep() { * If no scrolling region, use a set * of insert and delete line sequences */ -ttinsl(row, bot, nchunk) { - int i, nl; +VOID +ttinsl(row, bot, nchunk) +{ + int i, nl; - if (row == bot) { /* Case of one line insert is */ - ttmove(row, 0); /* special */ + if (row == bot) { /* Case of one line insert is */ + ttmove(row, 0); /* special */ tteeol(); return; } if (change_scroll_region && scroll_reverse) { - /* Use scroll region and back index */ + /* Use scroll region and back index */ nl = bot - row; - ttwindow(row,bot); + ttwindow(row, bot); ttmove(row, 0); while (nchunk--) putpad(scroll_reverse, nl); ttnowindow(); return; } else if (insdel) { - ttmove(1+bot-nchunk, 0); + ttmove(1 + bot - nchunk, 0); nl = nrow - ttrow; if (parm_delete_line) putpad(tgoto(parm_delete_line, 0, nchunk), nl); else - /* For all lines in the chunk */ - for (i=0; i<nchunk; i++) + /* For all lines in the chunk */ + for (i = 0; i < nchunk; i++) putpad(delete_line, nl); ttmove(row, 0); nl = nrow - ttrow; /* ttmove() changes ttrow */ @@ -247,7 +259,7 @@ ttinsl(row, bot, nchunk) { putpad(tgoto(parm_insert_line, 0, nchunk), nl); else /* For all lines in the chunk */ - for (i=0; i<nchunk; i++) + for (i = 0; i < nchunk; i++) putpad(insert_line, nl); ttrow = HUGE; ttcol = HUGE; @@ -263,39 +275,39 @@ ttinsl(row, bot, nchunk) { * lines. The presence of the echo area makes a * boundry condition go away. */ +VOID ttdell(row, bot, nchunk) { - int i, nl; + int i, nl; - if (row == bot) { /* One line special case */ + if (row == bot) { /* One line special case */ ttmove(row, 0); tteeol(); return; } - if (change_scroll_region) { /* scrolling region */ + if (change_scroll_region) { /* scrolling region */ nl = bot - row; ttwindow(row, bot); ttmove(bot, 0); while (nchunk--) putpad(scroll_fwd, nl); ttnowindow(); - } - else if (insdel) { - ttmove(row, 0); /* Else use insert/delete line */ + } else if (insdel) { + ttmove(row, 0); /* Else use insert/delete line */ nl = nrow - ttrow; if (parm_delete_line) putpad(tgoto(parm_delete_line, 0, nchunk), nl); else - /* For all lines in the chunk */ - for (i=0; i<nchunk; i++) + /* For all lines in the chunk */ + for (i = 0; i < nchunk; i++) putpad(delete_line, nl); - ttmove(1+bot-nchunk,0); + ttmove(1 + bot - nchunk, 0); nl = nrow - ttrow; /* ttmove() changes ttrow */ if (parm_insert_line) putpad(tgoto(parm_insert_line, 0, nchunk), nl); else /* For all lines in the chunk */ - for (i=0; i<nchunk; i++) + for (i = 0; i < nchunk; i++) putpad(insert_line, nl); ttrow = HUGE; ttcol = HUGE; @@ -315,13 +327,14 @@ ttdell(row, bot, nchunk) * moves the cursor). * */ +VOID ttwindow(top, bot) { if (change_scroll_region && (tttop != top || ttbot != bot)) { putpad(tgoto(change_scroll_region, bot, top), nrow - ttrow); - ttrow = HUGE; /* Unknown. */ + ttrow = HUGE; /* Unknown. */ ttcol = HUGE; - tttop = top; /* Remember region. */ + tttop = top; /* Remember region. */ ttbot = bot; } } @@ -336,14 +349,15 @@ ttwindow(top, bot) * This behavior seems to work right on systems * where you can set your terminal size. */ +VOID ttnowindow() { if (change_scroll_region) { putpad(tgoto(change_scroll_region, - (nrow > lines ? nrow : lines) - 1, 0), nrow - ttrow); - ttrow = HUGE; /* Unknown. */ + (nrow > lines ? nrow : lines) - 1, 0), nrow - ttrow); + ttrow = HUGE; /* Unknown. */ ttcol = HUGE; - tttop = HUGE; /* No scroll region. */ + tttop = HUGE; /* No scroll region. */ ttbot = HUGE; } } @@ -357,16 +371,17 @@ ttnowindow() * line by line basis, so don't bother sending * out the color shift. */ +VOID ttcolor(color) - int color; + int color; { if (color != tthue) { - if (color == CTEXT) /* Normal video. */ - putpad(exit_standout_mode, 1); - else if (color == CMODE) /* Reverse video. */ - putpad(enter_standout_mode, 1); - tthue = color; /* Save the color. */ + if (color == CTEXT) /* Normal video. */ + putpad(exit_standout_mode, 1); + else if (color == CMODE) /* Reverse video. */ + putpad(enter_standout_mode, 1); + tthue = color; /* Save the color. */ } } @@ -379,11 +394,13 @@ ttcolor(color) * with a screen NROW by NCOL. Look in "window.c" to * see how the caller deals with a change. */ -ttresize() { +VOID +ttresize() +{ - setttysize(); /* found in "ttyio.c", */ - /* ask OS for tty size */ - if (nrow < 1) /* Check limits. */ + setttysize(); /* found in "ttyio.c", */ + /* ask OS for tty size */ + if (nrow < 1) /* Check limits. */ nrow = 1; else if (nrow > NROW) nrow = NROW; @@ -394,24 +411,28 @@ ttresize() { } #ifdef NO_RESIZE -static setttysize() { +static +setttysize() +{ nrow = lines; ncol = columns; } #endif -static int cci; +static int cci; -/*ARGSUSED*/ -static int /* fake char output for charcost() */ +/* ARGSUSED */ +static int /* fake char output for charcost() */ fakec(c) -char c; + char c; { cci++; } /* calculate the cost of doing string s */ -charcost (s) char *s; { +charcost(s) + char *s; +{ cci = 0; tputs(s, nrow, fakec); diff --git a/usr.bin/mg/ttydef.h b/usr.bin/mg/ttydef.h index fbbec4ca70e..848fff2f7f4 100644 --- a/usr.bin/mg/ttydef.h +++ b/usr.bin/mg/ttydef.h @@ -1,16 +1,16 @@ /* - * Termcap terminal file, nothing special, just make it big + * Terminfo terminal file, nothing special, just make it big * enough for windowing systems. */ -#define GOSLING /* Compile in fancy display. */ -/* #define MEMMAP */ /* Not memory mapped video. */ +#define GOSLING /* Compile in fancy display. */ +/* #define MEMMAP *//* Not memory mapped video. */ -#define NROW 66 /* (maximum) Rows. */ -#define NCOL 132 /* (maximum) Columns. */ -/* #define MOVE_STANDOUT */ /* don't move in standout mode */ -#define STANDOUT_GLITCH /* possible standout glitch */ -#define TERMCAP /* for possible use in ttyio.c */ +#define NROW 66 /* (maximum) Rows. */ +#define NCOL 132 /* (maximum) Columns. */ +/* #define MOVE_STANDOUT *//* don't move in standout mode */ +#define STANDOUT_GLITCH /* possible standout glitch */ +#define TERMCAP /* for possible use in ttyio.c */ #define getkbd() (ttgetc()) @@ -18,7 +18,6 @@ #define ttykeymapinit() {} #endif -extern int tputs(); #define putpad(str, num) tputs(str, num, ttputc) #define KFIRST K00 diff --git a/usr.bin/mg/ttyio.c b/usr.bin/mg/ttyio.c index 40136b48ab8..8df4fe0dc0e 100644 --- a/usr.bin/mg/ttyio.c +++ b/usr.bin/mg/ttyio.c @@ -28,19 +28,6 @@ struct termios newtty; int nrow; /* Terminal size, rows. */ int ncol; /* Terminal size, columns. */ -/* XXX - move most of these to def.h? */ -void ttopen __P((void)); -int ttraw __P((void)); -void ttclose __P((void)); -int ttcooked __P((void)); -void ttputc __P((int)); -void ttflush __P((void)); -int ttgetc __P((void)); -void setttysize __P((void)); -int typeahead __P((void)); -void panic __P((char *)); -int ttwait __P((void)); - /* * This function gets called once, to set up the terminal. * On systems w/o TCSASOFT we turn off off flow control, @@ -128,7 +115,7 @@ ttcooked() * Write character to the display. Characters are buffered up, * to make things a little bit more efficient. */ -void +int ttputc(c) int c; { @@ -136,6 +123,7 @@ ttputc(c) if (nobuf >= NOBUF) ttflush(); obuf[nobuf++] = c; + return(c); } /* @@ -209,7 +197,7 @@ typeahead() /* * panic - just exit, as quickly as we can. */ -void +VOID panic(s) char *s; { diff --git a/usr.bin/mg/ttykbd.c b/usr.bin/mg/ttykbd.c index f4a16799a34..b10712f5c46 100644 --- a/usr.bin/mg/ttykbd.c +++ b/usr.bin/mg/ttykbd.c @@ -17,7 +17,7 @@ * extend.c. */ -char *keystrings[] = { NULL } ; +char *keystrings[] = {NULL}; #endif /* @@ -25,12 +25,12 @@ char *keystrings[] = { NULL } ; * available. The keys file is located in the same manner as the startup * file is, depending on what startupfile() does on your system. */ -extern int ttputc(); +extern int ttputc(); ttykeymapinit() { - extern int dobindkey(); /* XXX */ - char *cp; + extern int dobindkey(); /* XXX */ + char *cp; #ifdef FKEYS /* Bind keypad function keys. */ if (key_left) @@ -54,13 +54,13 @@ ttykeymapinit() #endif #ifndef NO_STARTUP if (cp = gettermtype()) { - extern char *startupfile(); + extern char *startupfile(); if (((cp = startupfile(cp)) != NULL) - && (load(cp) != TRUE)) + && (load(cp) != TRUE)) ewprintf("Error reading key initialization file"); } #endif - if (keypad_xmit) /* turn on keypad */ + if (keypad_xmit) /* turn on keypad */ putpad(keypad_xmit, 1); } @@ -71,7 +71,7 @@ ttykeymaptidy() { if (keypad_local) - putpad(keypad_local, 1); /* turn off keypad */ + putpad(keypad_local, 1); /* turn off keypad */ } #endif diff --git a/usr.bin/mg/version.c b/usr.bin/mg/version.c index 0f3a9e7562f..846c873e87f 100644 --- a/usr.bin/mg/version.c +++ b/usr.bin/mg/version.c @@ -3,17 +3,18 @@ * out by the emacs-version command. */ -#define TRUE 1 /* include "def.h" when things get more complicated */ +#define TRUE 1 /* include "def.h" when things get more + * complicated */ -char version[] = "Mg 2a (formerly MicroGnuEmacs)"; +char version[] = "Mg 2a"; /* * Display the version. All this does * is copy the version string onto the echo line. */ -/*ARGSUSED*/ +/* ARGSUSED */ showversion(f, n) -int f, n; + int f, n; { ewprintf(version); return TRUE; diff --git a/usr.bin/mg/window.c b/usr.bin/mg/window.c index 18e944fcd0c..e9a9c17f1db 100644 --- a/usr.bin/mg/window.c +++ b/usr.bin/mg/window.c @@ -13,11 +13,11 @@ * If GOSREC is defined, with no argument it defaults to 1 * and works like in Gosling. */ -/*ARGSUSED*/ +/* ARGSUSED */ reposition(f, n) { #ifndef GOSREC - curwp->w_force = (f & FFARG) ? (n>=0 ? n+1 : n) : 0; + curwp->w_force = (f & FFARG) ? (n >= 0 ? n + 1 : n) : 0; #else curwp->w_force = n; #endif @@ -41,25 +41,25 @@ reposition(f, n) * the window bigger again, and send another command, * everything will get fixed! */ -/*ARGSUSED*/ +/* ARGSUSED */ refresh(f, n) { register MGWIN *wp; - register int oldnrow; - register int oldncol; + register int oldnrow; + register int oldncol; oldnrow = nrow; oldncol = ncol; ttresize(); - if (nrow!=oldnrow || ncol!=oldncol) { - wp = wheadp; /* Find last. */ + if (nrow != oldnrow || ncol != oldncol) { + wp = wheadp; /* Find last. */ while (wp->w_wndp != NULL) wp = wp->w_wndp; - if (nrow < wp->w_toprow+3) { /* Check if too small. */ + if (nrow < wp->w_toprow + 3) { /* Check if too small. */ ewprintf("Display unusable"); return (FALSE); } - wp->w_ntrows = nrow-wp->w_toprow-2; + wp->w_ntrows = nrow - wp->w_toprow - 2; sgarbf = TRUE; update(); ewprintf("New size %d by %d", nrow, ncol); @@ -76,12 +76,12 @@ refresh(f, n) * nothing if there is only 1 window on * the screen. */ -/*ARGSUSED*/ +/* ARGSUSED */ nextwind(f, n) { register MGWIN *wp; - if ((wp=curwp->w_wndp) == NULL) + if ((wp = curwp->w_wndp) == NULL) wp = wheadp; curwp = wp; curbp = wp->w_bufp; @@ -97,7 +97,7 @@ nextwind(f, n) * although the command does not do a lot * if there is 1 window. */ -/*ARGSUSED*/ +/* ARGSUSED */ prevwind(f, n) { register MGWIN *wp1; @@ -126,19 +126,19 @@ prevwind(f, n) * distruction of a window makes a buffer * become undisplayed. */ -/*ARGSUSED*/ +/* ARGSUSED */ onlywind(f, n) { register MGWIN *wp; - register LINE *lp; - register int i; + register LINE *lp; + register int i; while (wheadp != curwp) { wp = wheadp; wheadp = wp->w_wndp; if (--wp->w_bufp->b_nwnd == 0) { - wp->w_bufp->b_dotp = wp->w_dotp; - wp->w_bufp->b_doto = wp->w_doto; + wp->w_bufp->b_dotp = wp->w_dotp; + wp->w_bufp->b_doto = wp->w_doto; wp->w_bufp->b_markp = wp->w_markp; wp->w_bufp->b_marko = wp->w_marko; } @@ -148,23 +148,23 @@ onlywind(f, n) wp = curwp->w_wndp; curwp->w_wndp = wp->w_wndp; if (--wp->w_bufp->b_nwnd == 0) { - wp->w_bufp->b_dotp = wp->w_dotp; - wp->w_bufp->b_doto = wp->w_doto; + wp->w_bufp->b_dotp = wp->w_dotp; + wp->w_bufp->b_doto = wp->w_doto; wp->w_bufp->b_markp = wp->w_markp; wp->w_bufp->b_marko = wp->w_marko; } free((char *) wp); } lp = curwp->w_linep; - i = curwp->w_toprow; - while (i!=0 && lback(lp)!=curbp->b_linep) { + i = curwp->w_toprow; + while (i != 0 && lback(lp) != curbp->b_linep) { --i; lp = lback(lp); } curwp->w_toprow = 0; - curwp->w_ntrows = nrow-2; /* 2 = mode, echo. */ - curwp->w_linep = lp; - curwp->w_flag |= WFMODE|WFHARD; + curwp->w_ntrows = nrow - 2; /* 2 = mode, echo. */ + curwp->w_linep = lp; + curwp->w_flag |= WFMODE | WFHARD; return TRUE; } @@ -175,34 +175,34 @@ onlywind(f, n) * a "malloc" failure allocating the structure * for the new window. */ -/*ARGSUSED*/ +/* ARGSUSED */ splitwind(f, n) { register MGWIN *wp; - register LINE *lp; - register int ntru; - register int ntrd; - int ntrl; - MGWIN *wp1, *wp2; + register LINE *lp; + register int ntru; + register int ntrd; + int ntrl; + MGWIN *wp1, *wp2; if (curwp->w_ntrows < 3) { ewprintf("Cannot split a %d line window", curwp->w_ntrows); return (FALSE); } - if ((wp = (MGWIN *)malloc(sizeof(MGWIN))) == NULL) { + if ((wp = (MGWIN *) malloc(sizeof(MGWIN))) == NULL) { ewprintf("Can't get %d", sizeof(MGWIN)); return (FALSE); } - ++curbp->b_nwnd; /* Displayed twice. */ - wp->w_bufp = curbp; - wp->w_dotp = curwp->w_dotp; - wp->w_doto = curwp->w_doto; + ++curbp->b_nwnd; /* Displayed twice. */ + wp->w_bufp = curbp; + wp->w_dotp = curwp->w_dotp; + wp->w_doto = curwp->w_doto; wp->w_markp = curwp->w_markp; wp->w_marko = curwp->w_marko; - wp->w_flag = 0; + wp->w_flag = 0; wp->w_force = 0; - ntru = (curwp->w_ntrows-1) / 2; /* Upper size */ - ntrl = (curwp->w_ntrows-1) - ntru; /* Lower size */ + ntru = (curwp->w_ntrows - 1) / 2; /* Upper size */ + ntrl = (curwp->w_ntrows - 1) - ntru; /* Lower size */ lp = curwp->w_linep; ntrd = 0; while (lp != curwp->w_dotp) { @@ -210,15 +210,15 @@ splitwind(f, n) lp = lforw(lp); } lp = curwp->w_linep; - if (ntrd <= ntru) { /* Old is upper window. */ - if (ntrd == ntru) /* Hit mode line. */ + if (ntrd <= ntru) { /* Old is upper window. */ + if (ntrd == ntru) /* Hit mode line. */ lp = lforw(lp); curwp->w_ntrows = ntru; wp->w_wndp = curwp->w_wndp; curwp->w_wndp = wp; - wp->w_toprow = curwp->w_toprow+ntru+1; + wp->w_toprow = curwp->w_toprow + ntru + 1; wp->w_ntrows = ntrl; - } else { /* Old is lower window */ + } else { /* Old is lower window */ wp1 = NULL; wp2 = wheadp; while (wp2 != curwp) { @@ -229,19 +229,19 @@ splitwind(f, n) wheadp = wp; else wp1->w_wndp = wp; - wp->w_wndp = curwp; + wp->w_wndp = curwp; wp->w_toprow = curwp->w_toprow; wp->w_ntrows = ntru; - ++ntru; /* Mode line. */ + ++ntru; /* Mode line. */ curwp->w_toprow += ntru; - curwp->w_ntrows = ntrl; + curwp->w_ntrows = ntrl; while (ntru--) lp = lforw(lp); } - curwp->w_linep = lp; /* Adjust the top lines */ - wp->w_linep = lp; /* if necessary. */ - curwp->w_flag |= WFMODE|WFHARD; - wp->w_flag |= WFMODE|WFHARD; + curwp->w_linep = lp; /* Adjust the top lines */ + wp->w_linep = lp; /* if necessary. */ + curwp->w_flag |= WFMODE | WFHARD; + wp->w_flag |= WFMODE | WFHARD; return TRUE; } @@ -253,12 +253,12 @@ splitwind(f, n) * hard work. You don't just set "force reframe" * because dot would move. */ -/*ARGSUSED*/ +/* ARGSUSED */ enlargewind(f, n) { register MGWIN *adjwp; - register LINE *lp; - register int i; + register LINE *lp; + register int i; if (n < 0) return shrinkwind(f, -n); @@ -266,7 +266,7 @@ enlargewind(f, n) ewprintf("Only one window"); return FALSE; } - if ((adjwp=curwp->w_wndp) == NULL) { + if ((adjwp = curwp->w_wndp) == NULL) { adjwp = wheadp; while (adjwp->w_wndp != curwp) adjwp = adjwp->w_wndp; @@ -275,23 +275,23 @@ enlargewind(f, n) ewprintf("Impossible change"); return FALSE; } - if (curwp->w_wndp == adjwp) { /* Shrink below. */ + if (curwp->w_wndp == adjwp) { /* Shrink below. */ lp = adjwp->w_linep; - for (i=0; i<n && lp!=adjwp->w_bufp->b_linep; ++i) + for (i = 0; i < n && lp != adjwp->w_bufp->b_linep; ++i) lp = lforw(lp); - adjwp->w_linep = lp; + adjwp->w_linep = lp; adjwp->w_toprow += n; - } else { /* Shrink above. */ + } else { /* Shrink above. */ lp = curwp->w_linep; - for (i=0; i<n && lback(lp)!=curbp->b_linep; ++i) + for (i = 0; i < n && lback(lp) != curbp->b_linep; ++i) lp = lback(lp); - curwp->w_linep = lp; + curwp->w_linep = lp; curwp->w_toprow -= n; } curwp->w_ntrows += n; adjwp->w_ntrows -= n; - curwp->w_flag |= WFMODE|WFHARD; - adjwp->w_flag |= WFMODE|WFHARD; + curwp->w_flag |= WFMODE | WFHARD; + adjwp->w_flag |= WFMODE | WFHARD; return TRUE; } @@ -304,8 +304,8 @@ enlargewind(f, n) shrinkwind(f, n) { register MGWIN *adjwp; - register LINE *lp; - register int i; + register LINE *lp; + register int i; if (n < 0) return enlargewind(f, -n); @@ -317,32 +317,32 @@ shrinkwind(f, n) * Bit of flakiness - KRANDOM means it was an internal call, and * to be trusted implicitly about sizes. */ - if ( !(f & FFRAND) && curwp->w_ntrows <= n) { + if (!(f & FFRAND) && curwp->w_ntrows <= n) { ewprintf("Impossible change"); return (FALSE); } - if ((adjwp=curwp->w_wndp) == NULL) { + if ((adjwp = curwp->w_wndp) == NULL) { adjwp = wheadp; while (adjwp->w_wndp != curwp) adjwp = adjwp->w_wndp; } - if (curwp->w_wndp == adjwp) { /* Grow below. */ + if (curwp->w_wndp == adjwp) { /* Grow below. */ lp = adjwp->w_linep; - for (i=0; i<n && lback(lp)!=adjwp->w_bufp->b_linep; ++i) + for (i = 0; i < n && lback(lp) != adjwp->w_bufp->b_linep; ++i) lp = lback(lp); - adjwp->w_linep = lp; + adjwp->w_linep = lp; adjwp->w_toprow -= n; - } else { /* Grow above. */ + } else { /* Grow above. */ lp = curwp->w_linep; - for (i=0; i<n && lp!=curbp->b_linep; ++i) + for (i = 0; i < n && lp != curbp->b_linep; ++i) lp = lforw(lp); - curwp->w_linep = lp; + curwp->w_linep = lp; curwp->w_toprow += n; } curwp->w_ntrows -= n; adjwp->w_ntrows += n; - curwp->w_flag |= WFMODE|WFHARD; - adjwp->w_flag |= WFMODE|WFHARD; + curwp->w_flag |= WFMODE | WFHARD; + adjwp->w_flag |= WFMODE | WFHARD; return (TRUE); } @@ -350,29 +350,31 @@ shrinkwind(f, n) * Delete current window. Call shrink-window to do the screen * updating, then throw away the window. */ -/*ARGSUSED*/ +/* ARGSUSED */ delwind(f, n) { register MGWIN *wp, *nwp; - wp = curwp; /* Cheap... */ + wp = curwp; /* Cheap... */ /* shrinkwind returning false means only one window... */ if (shrinkwind(FFRAND, wp->w_ntrows + 1) == FALSE) return FALSE; if (--wp->w_bufp->b_nwnd == 0) { - wp->w_bufp->b_dotp = wp->w_dotp; - wp->w_bufp->b_doto = wp->w_doto; + wp->w_bufp->b_dotp = wp->w_dotp; + wp->w_bufp->b_doto = wp->w_doto; wp->w_bufp->b_markp = wp->w_markp; wp->w_bufp->b_marko = wp->w_marko; } /* since shrinkwind did't crap out, we know we have a second window */ - if (wp == wheadp) wheadp = curwp = wp->w_wndp; - else if ((curwp = wp->w_wndp) == NULL) curwp = wheadp; + if (wp == wheadp) + wheadp = curwp = wp->w_wndp; + else if ((curwp = wp->w_wndp) == NULL) + curwp = wheadp; curbp = curwp->w_bufp; for (nwp = wheadp; nwp != NULL; nwp = nwp->w_wndp) if (nwp->w_wndp == wp) { nwp->w_wndp = wp->w_wndp; - break ; + break; } free((char *) wp); return TRUE; @@ -385,15 +387,16 @@ delwind(f, n) * might be better. Return a pointer, or * NULL on error. */ -MGWIN * -wpopup() { +MGWIN * +wpopup() +{ register MGWIN *wp; if (wheadp->w_wndp == NULL - && splitwind(FFRAND, 0) == FALSE) + && splitwind(FFRAND, 0) == FALSE) return NULL; - wp = wheadp; /* Find window to use */ - while (wp!=NULL && wp==curwp) + wp = wheadp; /* Find window to use */ + while (wp != NULL && wp == curwp) wp = wp->w_wndp; return wp; } diff --git a/usr.bin/mg/word.c b/usr.bin/mg/word.c index e06b4cab2a8..859d904f331 100644 --- a/usr.bin/mg/word.c +++ b/usr.bin/mg/word.c @@ -13,10 +13,11 @@ * are performed by the "backchar" and "forwchar" * routines. */ -/*ARGSUSED*/ +/* ARGSUSED */ backword(f, n) { - if (n < 0) return forwword(f | FFRAND, -n); + if (n < 0) + return forwword(f | FFRAND, -n); if (backchar(FFRAND, 1) == FALSE) return FALSE; while (n--) { @@ -37,7 +38,7 @@ backword(f, n) * the specified number of words. All of the * motion is done by "forwchar". */ -/*ARGSUSED*/ +/* ARGSUSED */ forwword(f, n) { if (n < 0) @@ -60,12 +61,13 @@ forwword(f, n) * the specified number of words. As you move, * convert any characters to upper case. */ -/*ARGSUSED*/ +/* ARGSUSED */ upperword(f, n) { - register int c; + register int c; - if (n < 0) return FALSE; + if (n < 0) + return FALSE; while (n--) { while (inword() == FALSE) { if (forwchar(FFRAND, 1) == FALSE) @@ -90,12 +92,13 @@ upperword(f, n) * the specified number of words. As you move * convert characters to lower case. */ -/*ARGSUSED*/ +/* ARGSUSED */ lowerword(f, n) { - register int c; + register int c; - if (n < 0) return FALSE; + if (n < 0) + return FALSE; while (n--) { while (inword() == FALSE) { if (forwchar(FFRAND, 1) == FALSE) @@ -122,13 +125,14 @@ lowerword(f, n) * case, and subsequent characters to lower case. Error * if you try and move past the end of the buffer. */ -/*ARGSUSED*/ +/* ARGSUSED */ capword(f, n) { - register int c; - VOID lchange(); + register int c; + VOID lchange(); - if (n < 0) return FALSE; + if (n < 0) + return FALSE; while (n--) { while (inword() == FALSE) { if (forwchar(FFRAND, 1) == FALSE) @@ -161,16 +165,16 @@ capword(f, n) /* * Kill forward by "n" words. */ -/*ARGSUSED*/ +/* ARGSUSED */ delfword(f, n) { - register RSIZE size; - register LINE *dotp; - register int doto; + register RSIZE size; + register LINE *dotp; + register int doto; if (n < 0) return FALSE; - if ((lastflag&CFKILL) == 0) /* Purge kill buffer. */ + if ((lastflag & CFKILL) == 0) /* Purge kill buffer. */ kdelete(); thisflag |= CFKILL; dotp = curwp->w_dotp; @@ -179,12 +183,12 @@ delfword(f, n) while (n--) { while (inword() == FALSE) { if (forwchar(FFRAND, 1) == FALSE) - goto out; /* Hit end of buffer. */ + goto out; /* Hit end of buffer. */ ++size; } while (inword() != FALSE) { if (forwchar(FFRAND, 1) == FALSE) - goto out; /* Hit end of buffer. */ + goto out; /* Hit end of buffer. */ ++size; } } @@ -206,34 +210,35 @@ out: * be wierd. Normally this is bound to "M-Rubout" and * to "M-Backspace". */ -/*ARGSUSED*/ +/* ARGSUSED */ delbword(f, n) { - register RSIZE size; - VOID kdelete(); + register RSIZE size; + VOID kdelete(); - if (n < 0) return FALSE; - if ((lastflag&CFKILL) == 0) /* Purge kill buffer. */ + if (n < 0) + return FALSE; + if ((lastflag & CFKILL) == 0) /* Purge kill buffer. */ kdelete(); thisflag |= CFKILL; if (backchar(FFRAND, 1) == FALSE) - return (TRUE); /* Hit buffer start. */ - size = 1; /* One deleted. */ + return (TRUE); /* Hit buffer start. */ + size = 1; /* One deleted. */ while (n--) { while (inword() == FALSE) { if (backchar(FFRAND, 1) == FALSE) - goto out; /* Hit buffer start. */ + goto out; /* Hit buffer start. */ ++size; } while (inword() != FALSE) { if (backchar(FFRAND, 1) == FALSE) - goto out; /* Hit buffer start. */ + goto out; /* Hit buffer start. */ ++size; } } if (forwchar(FFRAND, 1) == FALSE) return FALSE; - --size; /* Undo assumed delete. */ + --size; /* Undo assumed delete. */ out: return ldelete(size, KBACK); } @@ -244,9 +249,9 @@ out: * part of a word. The word character list is hard * coded. Should be setable. */ -inword() { -/* can't use lgetc in ISWORD due to bug in OSK cpp */ - return curwp->w_doto != llength(curwp->w_dotp) && +inword() +{ + /* can't use lgetc in ISWORD due to bug in OSK cpp */ + return curwp->w_doto != llength(curwp->w_dotp) && ISWORD(curwp->w_dotp->l_text[curwp->w_doto]); } - |