Run "indent -kr -i8" on the sources

Let's see how nasty it is to clean things up. For real.
This commit is contained in:
Linus Torvalds 2005-09-30 15:26:09 -07:00
parent 1f6239bfeb
commit 435dd32ae2
34 changed files with 6805 additions and 6655 deletions

213
ansi.c
View File

@ -7,7 +7,7 @@
* modified by Petri Kutvonen * modified by Petri Kutvonen
*/ */
#define termdef 1 /* don't define "term" external */ #define termdef 1 /* don't define "term" external */
#include <stdio.h> #include <stdio.h>
#include "estruct.h" #include "estruct.h"
@ -15,40 +15,40 @@
#if ANSI #if ANSI
#define NROW 25 /* Screen size. */ #define NROW 25 /* Screen size. */
#define NCOL 80 /* Edit if you want to. */ #define NCOL 80 /* Edit if you want to. */
#if PKCODE #if PKCODE
#define MROW 64 #define MROW 64
#endif #endif
#define NPAUSE 100 /* # times thru update to pause */ #define NPAUSE 100 /* # times thru update to pause */
#define MARGIN 8 /* size of minimim margin and */ #define MARGIN 8 /* size of minimim margin and */
#define SCRSIZ 64 /* scroll size for extended lines */ #define SCRSIZ 64 /* scroll size for extended lines */
#define BEL 0x07 /* BEL character. */ #define BEL 0x07 /* BEL character. */
#define ESC 0x1B /* ESC character. */ #define ESC 0x1B /* ESC character. */
extern int ttopen(); /* Forward references. */ extern int ttopen(); /* Forward references. */
extern int ttgetc(); extern int ttgetc();
extern int ttputc(); extern int ttputc();
extern int ttflush(); extern int ttflush();
extern int ttclose(); extern int ttclose();
extern int ansimove(); extern int ansimove();
extern int ansieeol(); extern int ansieeol();
extern int ansieeop(); extern int ansieeop();
extern int ansibeep(); extern int ansibeep();
extern int ansiopen(); extern int ansiopen();
extern int ansirev(); extern int ansirev();
extern int ansiclose(); extern int ansiclose();
extern int ansikopen(); extern int ansikopen();
extern int ansikclose(); extern int ansikclose();
extern int ansicres(); extern int ansicres();
#if COLOR #if COLOR
extern int ansifcol(); extern int ansifcol();
extern int ansibcol(); extern int ansibcol();
int cfcolor = -1; /* current forground color */ int cfcolor = -1; /* current forground color */
int cbcolor = -1; /* current background color */ int cbcolor = -1; /* current background color */
#endif #endif
@ -56,85 +56,85 @@ int cbcolor = -1; /* current background color */
* Standard terminal interface dispatch table. Most of the fields point into * Standard terminal interface dispatch table. Most of the fields point into
* "termio" code. * "termio" code.
*/ */
TERM term = { TERM term = {
#if PKCODE #if PKCODE
MROW-1, MROW - 1,
#else #else
NROW-1, NROW - 1,
#endif #endif
NROW-1, NROW - 1,
NCOL, NCOL,
NCOL, NCOL,
MARGIN, MARGIN,
SCRSIZ, SCRSIZ,
NPAUSE, NPAUSE,
ansiopen, ansiopen,
ansiclose, ansiclose,
ansikopen, ansikopen,
ansikclose, ansikclose,
ttgetc, ttgetc,
ttputc, ttputc,
ttflush, ttflush,
ansimove, ansimove,
ansieeol, ansieeol,
ansieeop, ansieeop,
ansibeep, ansibeep,
ansirev, ansirev,
ansicres ansicres
#if COLOR #if COLOR
, ansifcol, , ansifcol,
ansibcol ansibcol
#endif #endif
#if SCROLLCODE #if SCROLLCODE
, NULL , NULL
#endif #endif
}; };
#if COLOR #if COLOR
ansifcol(color) /* set the current output color */ ansifcol(color)
/* set the current output color */
int color; /* color to set */ int color; /* color to set */
{ {
if (color == cfcolor) if (color == cfcolor)
return; return;
ttputc(ESC); ttputc(ESC);
ttputc('['); ttputc('[');
ansiparm(color+30); ansiparm(color + 30);
ttputc('m'); ttputc('m');
cfcolor = color; cfcolor = color;
} }
ansibcol(color) /* set the current background color */ ansibcol(color)
/* set the current background color */
int color; /* color to set */ int color; /* color to set */
{ {
if (color == cbcolor) if (color == cbcolor)
return; return;
ttputc(ESC); ttputc(ESC);
ttputc('['); ttputc('[');
ansiparm(color+40); ansiparm(color + 40);
ttputc('m'); ttputc('m');
cbcolor = color; cbcolor = color;
} }
#endif #endif
ansimove(row, col) ansimove(row, col)
{ {
ttputc(ESC); ttputc(ESC);
ttputc('['); ttputc('[');
ansiparm(row+1); ansiparm(row + 1);
ttputc(';'); ttputc(';');
ansiparm(col+1); ansiparm(col + 1);
ttputc('H'); ttputc('H');
} }
ansieeol() ansieeol()
{ {
ttputc(ESC); ttputc(ESC);
ttputc('['); ttputc('[');
ttputc('K'); ttputc('K');
} }
ansieeop() ansieeop()
@ -143,14 +143,14 @@ ansieeop()
ansifcol(gfcolor); ansifcol(gfcolor);
ansibcol(gbcolor); ansibcol(gbcolor);
#endif #endif
ttputc(ESC); ttputc(ESC);
ttputc('['); ttputc('[');
ttputc('J'); ttputc('J');
} }
ansirev(state) /* change reverse video state */ ansirev(state)
/* change reverse video state */
int state; /* TRUE = reverse, FALSE = normal */ int state; /* TRUE = reverse, FALSE = normal */
{ {
#if COLOR #if COLOR
@ -159,7 +159,7 @@ int state; /* TRUE = reverse, FALSE = normal */
ttputc(ESC); ttputc(ESC);
ttputc('['); ttputc('[');
ttputc(state ? '7': '0'); ttputc(state ? '7' : '0');
ttputc('m'); ttputc('m');
#if COLOR #if COLOR
if (state == FALSE) { if (state == FALSE) {
@ -173,62 +173,59 @@ int state; /* TRUE = reverse, FALSE = normal */
#endif #endif
} }
ansicres() /* change screen resolution */ ansicres()
{ /* change screen resolution */
{ return (TRUE);
return(TRUE);
} }
spal(dummy) /* change pallette settings */ spal(dummy)
{ /* change pallette settings */
{
/* none for now */ /* none for now */
} }
ansibeep() ansibeep()
{ {
ttputc(BEL); ttputc(BEL);
ttflush(); ttflush();
} }
ansiparm(n) ansiparm(n)
register int n; register int n;
{ {
register int q,r; register int q, r;
q = n/10; q = n / 10;
if (q != 0) { if (q != 0) {
r = q/10; r = q / 10;
if (r != 0) { if (r != 0) {
ttputc((r%10)+'0'); ttputc((r % 10) + '0');
} }
ttputc((q%10) + '0'); ttputc((q % 10) + '0');
} }
ttputc((n%10) + '0'); ttputc((n % 10) + '0');
} }
ansiopen() ansiopen()
{ {
#if V7 | USG | BSD #if V7 | USG | BSD
register char *cp; register char *cp;
char *getenv(); char *getenv();
if ((cp = getenv("TERM")) == NULL) { if ((cp = getenv("TERM")) == NULL) {
puts("Shell variable TERM not defined!"); puts("Shell variable TERM not defined!");
exit(1); exit(1);
} }
if (strcmp(cp, "vt100") != 0) { if (strcmp(cp, "vt100") != 0) {
puts("Terminal type not 'vt100'!"); puts("Terminal type not 'vt100'!");
exit(1); exit(1);
} }
#endif #endif
strcpy(sres, "NORMAL"); strcpy(sres, "NORMAL");
revexist = TRUE; revexist = TRUE;
ttopen(); ttopen();
} }
ansiclose() ansiclose()
{ {
#if COLOR #if COLOR
ansifcol(7); ansifcol(7);
@ -237,24 +234,22 @@ ansiclose()
ttclose(); ttclose();
} }
ansikopen() /* open the keyboard (a noop here) */ ansikopen()
{ /* open the keyboard (a noop here) */
{
} }
ansikclose() /* close the keyboard (a noop here) */ ansikclose()
{ /* close the keyboard (a noop here) */
{
} }
#if FNLABEL #if FNLABEL
fnclabel(f, n) /* label a function key */ fnclabel(f, n)
/* label a function key */
int f,n; /* default flag, numeric argument [unused] */ int f, n; /* default flag, numeric argument [unused] */
{ {
/* on machines with no function keys...don't bother */ /* on machines with no function keys...don't bother */
return(TRUE); return (TRUE);
} }
#endif #endif
#else #else

360
basic.c
View File

@ -20,8 +20,8 @@
*/ */
gotobol(f, n) gotobol(f, n)
{ {
curwp->w_doto = 0; curwp->w_doto = 0;
return (TRUE); return (TRUE);
} }
/* /*
@ -31,23 +31,23 @@ gotobol(f, n)
* line pointer for dot changes. * line pointer for dot changes.
*/ */
backchar(f, n) backchar(f, n)
register int n; register int n;
{ {
register LINE *lp; register LINE *lp;
if (n < 0) if (n < 0)
return (forwchar(f, -n)); return (forwchar(f, -n));
while (n--) { while (n--) {
if (curwp->w_doto == 0) { if (curwp->w_doto == 0) {
if ((lp=lback(curwp->w_dotp)) == curbp->b_linep) if ((lp = lback(curwp->w_dotp)) == curbp->b_linep)
return (FALSE); return (FALSE);
curwp->w_dotp = lp; curwp->w_dotp = lp;
curwp->w_doto = llength(lp); curwp->w_doto = llength(lp);
curwp->w_flag |= WFMOVE; curwp->w_flag |= WFMOVE;
} else } else
curwp->w_doto--; curwp->w_doto--;
} }
return (TRUE); return (TRUE);
} }
/* /*
@ -55,8 +55,8 @@ register int n;
*/ */
gotoeol(f, n) gotoeol(f, n)
{ {
curwp->w_doto = llength(curwp->w_dotp); curwp->w_doto = llength(curwp->w_dotp);
return (TRUE); return (TRUE);
} }
/* /*
@ -66,47 +66,47 @@ gotoeol(f, n)
* buffer. Set the flag if the line pointer for dot changes. * buffer. Set the flag if the line pointer for dot changes.
*/ */
forwchar(f, n) forwchar(f, n)
register int n; register int n;
{ {
if (n < 0) if (n < 0)
return (backchar(f, -n)); return (backchar(f, -n));
while (n--) { while (n--) {
if (curwp->w_doto == llength(curwp->w_dotp)) { if (curwp->w_doto == llength(curwp->w_dotp)) {
if (curwp->w_dotp == curbp->b_linep) if (curwp->w_dotp == curbp->b_linep)
return (FALSE); return (FALSE);
curwp->w_dotp = lforw(curwp->w_dotp); curwp->w_dotp = lforw(curwp->w_dotp);
curwp->w_doto = 0; curwp->w_doto = 0;
curwp->w_flag |= WFMOVE; curwp->w_flag |= WFMOVE;
} else } else
curwp->w_doto++; curwp->w_doto++;
} }
return (TRUE); return (TRUE);
} }
gotoline(f, n) /* move to a particular line. gotoline(f, n)
argument (n) must be a positive integer for { /* move to a particular line.
this to actually do anything */ argument (n) must be a positive integer for
this to actually do anything */
{
register int status; /* status return */ register int status; /* status return */
char arg[NSTRING]; /* buffer to hold argument */ char arg[NSTRING]; /* buffer to hold argument */
/* get an argument if one doesnt exist */ /* get an argument if one doesnt exist */
if (f == FALSE) { if (f == FALSE) {
if ((status = mlreply("Line to GOTO: ", arg, NSTRING)) != TRUE) { if ((status =
mlreply("Line to GOTO: ", arg, NSTRING)) != TRUE) {
mlwrite("(Aborted)"); mlwrite("(Aborted)");
return(status); return (status);
} }
n = atoi(arg); n = atoi(arg);
} }
if (n < 1) /* if a bogus argument...then leave */ if (n < 1) /* if a bogus argument...then leave */
return(FALSE); return (FALSE);
/* first, we go to the start of the buffer */ /* first, we go to the start of the buffer */
curwp->w_dotp = lforw(curbp->b_linep); curwp->w_dotp = lforw(curbp->b_linep);
curwp->w_doto = 0; curwp->w_doto = 0;
return(forwline(f, n-1)); return (forwline(f, n - 1));
} }
/* /*
@ -116,10 +116,10 @@ gotoline(f, n) /* move to a particular line.
*/ */
gotobob(f, n) gotobob(f, n)
{ {
curwp->w_dotp = lforw(curbp->b_linep); curwp->w_dotp = lforw(curbp->b_linep);
curwp->w_doto = 0; curwp->w_doto = 0;
curwp->w_flag |= WFHARD; curwp->w_flag |= WFHARD;
return (TRUE); return (TRUE);
} }
/* /*
@ -129,10 +129,10 @@ gotobob(f, n)
*/ */
gotoeob(f, n) gotoeob(f, n)
{ {
curwp->w_dotp = curbp->b_linep; curwp->w_dotp = curbp->b_linep;
curwp->w_doto = 0; curwp->w_doto = 0;
curwp->w_flag |= WFHARD; curwp->w_flag |= WFHARD;
return (TRUE); return (TRUE);
} }
/* /*
@ -143,33 +143,33 @@ gotoeob(f, n)
*/ */
forwline(f, n) forwline(f, n)
{ {
register LINE *dlp; register LINE *dlp;
if (n < 0) if (n < 0)
return (backline(f, -n)); return (backline(f, -n));
/* if we are on the last line as we start....fail the command */ /* if we are on the last line as we start....fail the command */
if (curwp->w_dotp == curbp->b_linep) if (curwp->w_dotp == curbp->b_linep)
return(FALSE); return (FALSE);
/* if the last command was not note a line move, /* if the last command was not note a line move,
reset the goal column */ reset the goal column */
if ((lastflag&CFCPCN) == 0) if ((lastflag & CFCPCN) == 0)
curgoal = getccol(FALSE); curgoal = getccol(FALSE);
/* flag this command as a line move */ /* flag this command as a line move */
thisflag |= CFCPCN; thisflag |= CFCPCN;
/* and move the point down */ /* and move the point down */
dlp = curwp->w_dotp; dlp = curwp->w_dotp;
while (n-- && dlp!=curbp->b_linep) while (n-- && dlp != curbp->b_linep)
dlp = lforw(dlp); dlp = lforw(dlp);
/* reseting the current position */ /* reseting the current position */
curwp->w_dotp = dlp; curwp->w_dotp = dlp;
curwp->w_doto = getgoal(dlp); curwp->w_doto = getgoal(dlp);
curwp->w_flag |= WFMOVE; curwp->w_flag |= WFMOVE;
return (TRUE); return (TRUE);
} }
/* /*
@ -180,48 +180,48 @@ forwline(f, n)
*/ */
backline(f, n) backline(f, n)
{ {
register LINE *dlp; register LINE *dlp;
if (n < 0) if (n < 0)
return (forwline(f, -n)); return (forwline(f, -n));
/* if we are on the last line as we start....fail the command */ /* if we are on the last line as we start....fail the command */
if (lback(curwp->w_dotp) == curbp->b_linep) if (lback(curwp->w_dotp) == curbp->b_linep)
return(FALSE); return (FALSE);
/* if the last command was not note a line move, /* if the last command was not note a line move,
reset the goal column */ reset the goal column */
if ((lastflag&CFCPCN) == 0) if ((lastflag & CFCPCN) == 0)
curgoal = getccol(FALSE); curgoal = getccol(FALSE);
/* flag this command as a line move */ /* flag this command as a line move */
thisflag |= CFCPCN; thisflag |= CFCPCN;
/* and move the point up */ /* and move the point up */
dlp = curwp->w_dotp; dlp = curwp->w_dotp;
while (n-- && lback(dlp)!=curbp->b_linep) while (n-- && lback(dlp) != curbp->b_linep)
dlp = lback(dlp); dlp = lback(dlp);
/* reseting the current position */ /* reseting the current position */
curwp->w_dotp = dlp; curwp->w_dotp = dlp;
curwp->w_doto = getgoal(dlp); curwp->w_doto = getgoal(dlp);
curwp->w_flag |= WFMOVE; curwp->w_flag |= WFMOVE;
return (TRUE); return (TRUE);
} }
#if WORDPRO #if WORDPRO
gotobop(f, n) /* go back to the beginning of the current paragraph gotobop(f, n)
here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE> /* go back to the beginning of the current paragraph
combination to delimit the beginning of a paragraph */ here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE>
combination to delimit the beginning of a paragraph */
int f, n; /* default Flag & Numeric argument */ int f, n; /* default Flag & Numeric argument */
{ {
register int suc; /* success of last backchar */ register int suc; /* success of last backchar */
if (n < 0) /* the other way...*/ if (n < 0) /* the other way... */
return(gotoeop(f, -n)); return (gotoeop(f, -n));
while (n-- > 0) { /* for each one asked for */ while (n-- > 0) { /* for each one asked for */
@ -232,16 +232,16 @@ int f, n; /* default Flag & Numeric argument */
curwp->w_doto = 0; /* and go to the B-O-Line */ curwp->w_doto = 0; /* and go to the B-O-Line */
/* and scan back until we hit a <NL><NL> or <NL><TAB> /* and scan back until we hit a <NL><NL> or <NL><TAB>
or a <NL><SPACE> */ or a <NL><SPACE> */
while (lback(curwp->w_dotp) != curbp->b_linep) while (lback(curwp->w_dotp) != curbp->b_linep)
if (llength(curwp->w_dotp) != 0 && if (llength(curwp->w_dotp) != 0 &&
#if PKCODE #if PKCODE
((justflag == TRUE) || ((justflag == TRUE) ||
#endif #endif
lgetc(curwp->w_dotp, curwp->w_doto) != TAB && lgetc(curwp->w_dotp, curwp->w_doto) != TAB &&
lgetc(curwp->w_dotp, curwp->w_doto) != ' ') lgetc(curwp->w_dotp, curwp->w_doto) != ' ')
#if PKCODE #if PKCODE
) )
#endif #endif
curwp->w_dotp = lback(curwp->w_dotp); curwp->w_dotp = lback(curwp->w_dotp);
else else
@ -253,20 +253,20 @@ int f, n; /* default Flag & Numeric argument */
suc = forwchar(FALSE, 1); suc = forwchar(FALSE, 1);
} }
curwp->w_flag |= WFMOVE; /* force screen update */ curwp->w_flag |= WFMOVE; /* force screen update */
return(TRUE); return (TRUE);
} }
gotoeop(f, n) /* go forword to the end of the current paragraph gotoeop(f, n)
here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE> /* go forword to the end of the current paragraph
combination to delimit the beginning of a paragraph */ here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE>
combination to delimit the beginning of a paragraph */
int f, n; /* default Flag & Numeric argument */ int f, n; /* default Flag & Numeric argument */
{ {
register int suc; /* success of last backchar */ register int suc; /* success of last backchar */
if (n < 0) /* the other way...*/ if (n < 0) /* the other way... */
return(gotobop(f, -n)); return (gotobop(f, -n));
while (n-- > 0) { /* for each one asked for */ while (n-- > 0) { /* for each one asked for */
@ -279,16 +279,16 @@ int f, n; /* default Flag & Numeric argument */
curwp->w_dotp = lforw(curwp->w_dotp); curwp->w_dotp = lforw(curwp->w_dotp);
/* and scan forword until we hit a <NL><NL> or <NL><TAB> /* and scan forword until we hit a <NL><NL> or <NL><TAB>
or a <NL><SPACE> */ or a <NL><SPACE> */
while (curwp->w_dotp != curbp->b_linep) { while (curwp->w_dotp != curbp->b_linep) {
if (llength(curwp->w_dotp) != 0 && if (llength(curwp->w_dotp) != 0 &&
#if PKCODE #if PKCODE
((justflag == TRUE) || ((justflag == TRUE) ||
#endif #endif
lgetc(curwp->w_dotp, curwp->w_doto) != TAB && lgetc(curwp->w_dotp, curwp->w_doto) != TAB &&
lgetc(curwp->w_dotp, curwp->w_doto) != ' ') lgetc(curwp->w_dotp, curwp->w_doto) != ' ')
#if PKCODE #if PKCODE
) )
#endif #endif
curwp->w_dotp = lforw(curwp->w_dotp); curwp->w_dotp = lforw(curwp->w_dotp);
else else
@ -303,7 +303,7 @@ int f, n; /* default Flag & Numeric argument */
curwp->w_doto = llength(curwp->w_dotp); /* and to the EOL */ curwp->w_doto = llength(curwp->w_dotp); /* and to the EOL */
} }
curwp->w_flag |= WFMOVE; /* force screen update */ curwp->w_flag |= WFMOVE; /* force screen update */
return(TRUE); return (TRUE);
} }
#endif #endif
@ -313,29 +313,29 @@ int f, n; /* default Flag & Numeric argument */
* Used by "C-N" and "C-P". * Used by "C-N" and "C-P".
*/ */
getgoal(dlp) getgoal(dlp)
register LINE *dlp; register LINE *dlp;
{ {
register int c; register int c;
register int col; register int col;
register int newcol; register int newcol;
register int dbo; register int dbo;
col = 0; col = 0;
dbo = 0; dbo = 0;
while (dbo != llength(dlp)) { while (dbo != llength(dlp)) {
c = lgetc(dlp, dbo); c = lgetc(dlp, dbo);
newcol = col; newcol = col;
if (c == '\t') if (c == '\t')
newcol |= tabmask; newcol |= tabmask;
else if (c<0x20 || c==0x7F) else if (c < 0x20 || c == 0x7F)
++newcol; ++newcol;
++newcol; ++newcol;
if (newcol > curgoal) if (newcol > curgoal)
break; break;
col = newcol; col = newcol;
++dbo; ++dbo;
} }
return (dbo); return (dbo);
} }
/* /*
@ -345,11 +345,11 @@ register LINE *dlp;
* this zaps the top line in the display window, we have to do a hard update. * this zaps the top line in the display window, we have to do a hard update.
*/ */
forwpage(f, n) forwpage(f, n)
register int n; register int n;
{ {
register LINE *lp; register LINE *lp;
if (f == FALSE) { if (f == FALSE) {
#if SCROLLCODE #if SCROLLCODE
if (term.t_scroll != NULL) if (term.t_scroll != NULL)
if (overlap == 0) if (overlap == 0)
@ -358,27 +358,27 @@ register int n;
n = curwp->w_ntrows - overlap; n = curwp->w_ntrows - overlap;
else else
#endif #endif
n = curwp->w_ntrows - 2; /* Default scroll. */ n = curwp->w_ntrows - 2; /* Default scroll. */
if (n <= 0) /* Forget the overlap */ if (n <= 0) /* Forget the overlap */
n = 1; /* if tiny window. */ n = 1; /* if tiny window. */
} else if (n < 0) } else if (n < 0)
return (backpage(f, -n)); return (backpage(f, -n));
#if CVMVAS #if CVMVAS
else /* Convert from pages */ else /* Convert from pages */
n *= curwp->w_ntrows; /* to lines. */ n *= curwp->w_ntrows; /* to lines. */
#endif #endif
lp = curwp->w_linep; lp = curwp->w_linep;
while (n-- && lp!=curbp->b_linep) while (n-- && lp != curbp->b_linep)
lp = lforw(lp); lp = lforw(lp);
curwp->w_linep = lp; curwp->w_linep = lp;
curwp->w_dotp = lp; curwp->w_dotp = lp;
curwp->w_doto = 0; curwp->w_doto = 0;
#if SCROLLCODE #if SCROLLCODE
curwp->w_flag |= WFHARD|WFKILLS; curwp->w_flag |= WFHARD | WFKILLS;
#else #else
curwp->w_flag |= WFHARD; curwp->w_flag |= WFHARD;
#endif #endif
return (TRUE); return (TRUE);
} }
/* /*
@ -388,11 +388,11 @@ register int n;
* reason. * reason.
*/ */
backpage(f, n) backpage(f, n)
register int n; register int n;
{ {
register LINE *lp; register LINE *lp;
if (f == FALSE) { if (f == FALSE) {
#if SCROLLCODE #if SCROLLCODE
if (term.t_scroll != NULL) if (term.t_scroll != NULL)
if (overlap == 0) if (overlap == 0)
@ -401,27 +401,27 @@ register int n;
n = curwp->w_ntrows - overlap; n = curwp->w_ntrows - overlap;
else else
#endif #endif
n = curwp->w_ntrows - 2; /* Default scroll. */ n = curwp->w_ntrows - 2; /* Default scroll. */
if (n <= 0) /* Don't blow up if the */ if (n <= 0) /* Don't blow up if the */
n = 1; /* window is tiny. */ n = 1; /* window is tiny. */
} else if (n < 0) } else if (n < 0)
return (forwpage(f, -n)); return (forwpage(f, -n));
#if CVMVAS #if CVMVAS
else /* Convert from pages */ else /* Convert from pages */
n *= curwp->w_ntrows; /* to lines. */ n *= curwp->w_ntrows; /* to lines. */
#endif #endif
lp = curwp->w_linep; lp = curwp->w_linep;
while (n-- && lback(lp)!=curbp->b_linep) while (n-- && lback(lp) != curbp->b_linep)
lp = lback(lp); lp = lback(lp);
curwp->w_linep = lp; curwp->w_linep = lp;
curwp->w_dotp = lp; curwp->w_dotp = lp;
curwp->w_doto = 0; curwp->w_doto = 0;
#if SCROLLCODE #if SCROLLCODE
curwp->w_flag |= WFHARD|WFINS; curwp->w_flag |= WFHARD | WFINS;
#else #else
curwp->w_flag |= WFHARD; curwp->w_flag |= WFHARD;
#endif #endif
return (TRUE); return (TRUE);
} }
/* /*
@ -430,10 +430,10 @@ register int n;
*/ */
setmark(f, n) setmark(f, n)
{ {
curwp->w_markp = curwp->w_dotp; curwp->w_markp = curwp->w_dotp;
curwp->w_marko = curwp->w_doto; curwp->w_marko = curwp->w_doto;
mlwrite("(Mark set)"); mlwrite("(Mark set)");
return (TRUE); return (TRUE);
} }
/* /*
@ -444,19 +444,19 @@ setmark(f, n)
*/ */
swapmark(f, n) swapmark(f, n)
{ {
register LINE *odotp; register LINE *odotp;
register int odoto; register int odoto;
if (curwp->w_markp == NULL) { if (curwp->w_markp == NULL) {
mlwrite("No mark in this window"); mlwrite("No mark in this window");
return (FALSE); return (FALSE);
} }
odotp = curwp->w_dotp; odotp = curwp->w_dotp;
odoto = curwp->w_doto; odoto = curwp->w_doto;
curwp->w_dotp = curwp->w_markp; curwp->w_dotp = curwp->w_markp;
curwp->w_doto = curwp->w_marko; curwp->w_doto = curwp->w_marko;
curwp->w_markp = odotp; curwp->w_markp = odotp;
curwp->w_marko = odoto; curwp->w_marko = odoto;
curwp->w_flag |= WFMOVE; curwp->w_flag |= WFMOVE;
return (TRUE); return (TRUE);
} }

251
bind.c
View File

@ -12,12 +12,12 @@
#include "edef.h" #include "edef.h"
#include "epath.h" #include "epath.h"
extern int meta(), cex(), unarg(), ctrlg(); /* dummy prefix binding functions */ extern int meta(), cex(), unarg(), ctrlg(); /* dummy prefix binding functions */
help(f, n) /* give me some help!!!! help(f, n)
bring up a fake buffer and read the help file { /* give me some help!!!!
into it with view mode */ bring up a fake buffer and read the help file
{ into it with view mode */
register WINDOW *wp; /* scaning pointer to windows */ register WINDOW *wp; /* scaning pointer to windows */
register BUFFER *bp; /* buffer pointer to help */ register BUFFER *bp; /* buffer pointer to help */
char *fname; /* ptr to file returned by flook() */ char *fname; /* ptr to file returned by flook() */
@ -29,18 +29,18 @@ help(f, n) /* give me some help!!!!
fname = flook(pathname[1], FALSE); fname = flook(pathname[1], FALSE);
if (fname == NULL) { if (fname == NULL) {
mlwrite("(Help file is not online)"); mlwrite("(Help file is not online)");
return(FALSE); return (FALSE);
} }
} }
/* split the current window to make room for the help stuff */ /* split the current window to make room for the help stuff */
if (splitwind(FALSE, 1) == FALSE) if (splitwind(FALSE, 1) == FALSE)
return(FALSE); return (FALSE);
if (bp == NULL) { if (bp == NULL) {
/* and read the stuff in */ /* and read the stuff in */
if (getfile(fname, FALSE) == FALSE) if (getfile(fname, FALSE) == FALSE)
return(FALSE); return (FALSE);
} else } else
swbuffer(bp); swbuffer(bp);
@ -52,16 +52,15 @@ help(f, n) /* give me some help!!!!
wp->w_flag |= WFMODE; wp->w_flag |= WFMODE;
wp = wp->w_wndp; wp = wp->w_wndp;
} }
return(TRUE); return (TRUE);
} }
deskey(f, n) /* describe the command for a certain key */ deskey(f, n)
{ /* describe the command for a certain key */
{
register int c; /* key to describe */ register int c; /* key to describe */
register char *ptr; /* string pointer to scan output strings */ register char *ptr; /* string pointer to scan output strings */
char outseq[NSTRING]; /* output buffer for command sequence */ char outseq[NSTRING]; /* output buffer for command sequence */
int (*getbind())(); int (*getbind()) ();
/* prompt the user to type us a key to describe */ /* prompt the user to type us a key to describe */
mlwrite(": describe-key "); mlwrite(": describe-key ");
@ -86,15 +85,15 @@ deskey(f, n) /* describe the command for a certain key */
bindtokey(f, n) bindtokey(f, n)
int f, n; /* command arguments [IGNORED] */ int f, n; /* command arguments [IGNORED] */
{ {
register unsigned int c;/* command key to bind */ register unsigned int c; /* command key to bind */
register int (*kfunc)();/* ptr to the requested function to bind to */ register int (*kfunc) (); /* ptr to the requested function to bind to */
register KEYTAB *ktp; /* pointer into the command table */ register KEYTAB *ktp; /* pointer into the command table */
register int found; /* matched command flag */ register int found; /* matched command flag */
char outseq[80]; /* output buffer for keystroke sequence */ char outseq[80]; /* output buffer for keystroke sequence */
int (*getname())(); int (*getname()) ();
/* prompt the user to type in a key to bind */ /* prompt the user to type in a key to bind */
mlwrite(": bind-to-key "); mlwrite(": bind-to-key ");
@ -103,13 +102,13 @@ int f, n; /* command arguments [IGNORED] */
kfunc = getname(); kfunc = getname();
if (kfunc == NULL) { if (kfunc == NULL) {
mlwrite("(No such function)"); mlwrite("(No such function)");
return(FALSE); return (FALSE);
} }
ostring(" "); ostring(" ");
/* get the command sequence to bind */ /* get the command sequence to bind */
c = getckey((kfunc == meta) || (kfunc == cex) || c = getckey((kfunc == meta) || (kfunc == cex) ||
(kfunc == unarg) || (kfunc == ctrlg)); (kfunc == unarg) || (kfunc == ctrlg));
/* change it to something we can print as well */ /* change it to something we can print as well */
cmdstr(c, &outseq[0]); cmdstr(c, &outseq[0]);
@ -152,29 +151,29 @@ int f, n; /* command arguments [IGNORED] */
++ktp; ++ktp;
} }
if (found) { /* it exists, just change it then */ if (found) { /* it exists, just change it then */
ktp->k_fp = kfunc; ktp->k_fp = kfunc;
} else { /* otherwise we need to add it to the end */ } else { /* otherwise we need to add it to the end */
/* if we run out of binding room, bitch */ /* if we run out of binding room, bitch */
if (ktp >= &keytab[NBINDS]) { if (ktp >= &keytab[NBINDS]) {
mlwrite("Binding table FULL!"); mlwrite("Binding table FULL!");
return(FALSE); return (FALSE);
} }
ktp->k_code = c; /* add keycode */ ktp->k_code = c; /* add keycode */
ktp->k_fp = kfunc; /* and the function pointer */ ktp->k_fp = kfunc; /* and the function pointer */
++ktp; /* and make sure the next is null */ ++ktp; /* and make sure the next is null */
ktp->k_code = 0; ktp->k_code = 0;
ktp->k_fp = NULL; ktp->k_fp = NULL;
} }
return(TRUE); return (TRUE);
} }
/* unbindkey: delete a key from the key binding table */ /* unbindkey: delete a key from the key binding table */
unbindkey(f, n) unbindkey(f, n)
int f, n; /* command arguments [IGNORED] */ int f, n; /* command arguments [IGNORED] */
{ {
register int c; /* command key to unbind */ register int c; /* command key to unbind */
@ -184,7 +183,7 @@ int f, n; /* command arguments [IGNORED] */
mlwrite(": unbind-key "); mlwrite(": unbind-key ");
/* get the command sequence to unbind */ /* get the command sequence to unbind */
c = getckey(FALSE); /* get a command sequence */ c = getckey(FALSE); /* get a command sequence */
/* change it to something we can print as well */ /* change it to something we can print as well */
cmdstr(c, &outseq[0]); cmdstr(c, &outseq[0]);
@ -195,14 +194,14 @@ int f, n; /* command arguments [IGNORED] */
/* if it isn't bound, bitch */ /* if it isn't bound, bitch */
if (unbindchar(c) == FALSE) { if (unbindchar(c) == FALSE) {
mlwrite("(Key not bound)"); mlwrite("(Key not bound)");
return(FALSE); return (FALSE);
} }
return(TRUE); return (TRUE);
} }
unbindchar(c) unbindchar(c)
int c; /* command key to unbind */ int c; /* command key to unbind */
{ {
register KEYTAB *ktp; /* pointer into the command table */ register KEYTAB *ktp; /* pointer into the command table */
@ -222,50 +221,49 @@ int c; /* command key to unbind */
/* if it isn't bound, bitch */ /* if it isn't bound, bitch */
if (!found) if (!found)
return(FALSE); return (FALSE);
/* save the pointer and scan to the end of the table */ /* save the pointer and scan to the end of the table */
sktp = ktp; sktp = ktp;
while (ktp->k_fp != NULL) while (ktp->k_fp != NULL)
++ktp; ++ktp;
--ktp; /* backup to the last legit entry */ --ktp; /* backup to the last legit entry */
/* copy the last entry to the current one */ /* copy the last entry to the current one */
sktp->k_code = ktp->k_code; sktp->k_code = ktp->k_code;
sktp->k_fp = ktp->k_fp; sktp->k_fp = ktp->k_fp;
/* null out the last one */ /* null out the last one */
ktp->k_code = 0; ktp->k_code = 0;
ktp->k_fp = NULL; ktp->k_fp = NULL;
return(TRUE); return (TRUE);
} }
desbind(f, n) /* describe bindings desbind(f, n)
bring up a fake buffer and list the key bindings /* describe bindings
into it with view mode */ bring up a fake buffer and list the key bindings
into it with view mode */
#if APROP #if APROP
{ {
buildlist(TRUE, ""); buildlist(TRUE, "");
} }
apro(f, n) /* Apropos (List functions that match a substring) */ apro(f, n)
{ /* Apropos (List functions that match a substring) */
{
char mstring[NSTRING]; /* string to match cmd names to */ char mstring[NSTRING]; /* string to match cmd names to */
int status; /* status return */ int status; /* status return */
status = mlreply("Apropos string: ", mstring, NSTRING - 1); status = mlreply("Apropos string: ", mstring, NSTRING - 1);
if (status != TRUE) if (status != TRUE)
return(status); return (status);
return(buildlist(FALSE, mstring)); return (buildlist(FALSE, mstring));
} }
buildlist(type, mstring) /* build a binding list (limited or full) */ buildlist(type, mstring)
/* build a binding list (limited or full) */
int type; /* true = full list, false = partial list */ int type; /* true = full list, false = partial list */
char *mstring; /* match string if a partial list */ char *mstring; /* match string if a partial list */
#endif #endif
{ {
@ -279,34 +277,34 @@ char *mstring; /* match string if a partial list */
/* split the current window to make room for the binding list */ /* split the current window to make room for the binding list */
if (splitwind(FALSE, 1) == FALSE) if (splitwind(FALSE, 1) == FALSE)
return(FALSE); return (FALSE);
/* and get a buffer for it */ /* and get a buffer for it */
bp = bfind("*Binding list*", TRUE, 0); bp = bfind("*Binding list*", TRUE, 0);
if (bp == NULL || bclear(bp) == FALSE) { if (bp == NULL || bclear(bp) == FALSE) {
mlwrite("Can not display binding list"); mlwrite("Can not display binding list");
return(FALSE); return (FALSE);
} }
/* let us know this is in progress */ /* let us know this is in progress */
mlwrite("(Building binding list)"); mlwrite("(Building binding list)");
/* disconect the current buffer */ /* disconect the current buffer */
if (--curbp->b_nwnd == 0) { /* Last use. */ if (--curbp->b_nwnd == 0) { /* Last use. */
curbp->b_dotp = curwp->w_dotp; curbp->b_dotp = curwp->w_dotp;
curbp->b_doto = curwp->w_doto; curbp->b_doto = curwp->w_doto;
curbp->b_markp = curwp->w_markp; curbp->b_markp = curwp->w_markp;
curbp->b_marko = curwp->w_marko; curbp->b_marko = curwp->w_marko;
} }
/* connect the current window to this buffer */ /* connect the current window to this buffer */
curbp = bp; /* make this buffer current in current window */ curbp = bp; /* make this buffer current in current window */
bp->b_mode = 0; /* no modes active in binding list */ bp->b_mode = 0; /* no modes active in binding list */
bp->b_nwnd++; /* mark us as more in use */ bp->b_nwnd++; /* mark us as more in use */
wp = curwp; wp = curwp;
wp->w_bufp = bp; wp->w_bufp = bp;
wp->w_linep = bp->b_linep; wp->w_linep = bp->b_linep;
wp->w_flag = WFHARD|WFFORCE; wp->w_flag = WFHARD | WFFORCE;
wp->w_dotp = bp->b_dotp; wp->w_dotp = bp->b_dotp;
wp->w_doto = bp->b_doto; wp->w_doto = bp->b_doto;
wp->w_markp = NULL; wp->w_markp = NULL;
@ -341,7 +339,7 @@ char *mstring; /* match string if a partial list */
/* and add it as a line into the buffer */ /* and add it as a line into the buffer */
if (linstr(outseq) != TRUE) if (linstr(outseq) != TRUE)
return(FALSE); return (FALSE);
cpos = 0; /* and clear the line */ cpos = 0; /* and clear the line */
} }
@ -353,36 +351,36 @@ char *mstring; /* match string if a partial list */
outseq[cpos++] = '\n'; outseq[cpos++] = '\n';
outseq[cpos] = 0; outseq[cpos] = 0;
if (linstr(outseq) != TRUE) if (linstr(outseq) != TRUE)
return(FALSE); return (FALSE);
} }
fail: /* and on to the next name */ fail: /* and on to the next name */
++nptr; ++nptr;
} }
curwp->w_bufp->b_mode |= MDVIEW;/* put this buffer view mode */ curwp->w_bufp->b_mode |= MDVIEW; /* put this buffer view mode */
curbp->b_flag &= ~BFCHG; /* don't flag this as a change */ curbp->b_flag &= ~BFCHG; /* don't flag this as a change */
wp->w_dotp = lforw(bp->b_linep);/* back to the beginning */ wp->w_dotp = lforw(bp->b_linep); /* back to the beginning */
wp->w_doto = 0; wp->w_doto = 0;
wp = wheadp; /* and update ALL mode lines */ wp = wheadp; /* and update ALL mode lines */
while (wp != NULL) { while (wp != NULL) {
wp->w_flag |= WFMODE; wp->w_flag |= WFMODE;
wp = wp->w_wndp; wp = wp->w_wndp;
} }
mlwrite(""); /* clear the mode line */ mlwrite(""); /* clear the mode line */
return(TRUE); return (TRUE);
} }
#if APROP #if APROP
strinc(source, sub) /* does source include sub? */ strinc(source, sub)
/* does source include sub? */
char *source; /* string to search in */ char *source; /* string to search in */
char *sub; /* substring to look for */ char *sub; /* substring to look for */
{ {
char *sp; /* ptr into source */ char *sp; /* ptr into source */
char *nxtsp; /* next ptr into source */ char *nxtsp; /* next ptr into source */
char *tp; /* ptr into substring */ char *tp; /* ptr into substring */
/* for each character in the source string */ /* for each character in the source string */
sp = source; sp = source;
@ -400,12 +398,12 @@ char *sub; /* substring to look for */
/* yes, return a success */ /* yes, return a success */
if (*tp == 0) if (*tp == 0)
return(TRUE); return (TRUE);
/* no, onward */ /* no, onward */
sp++; sp++;
} }
return(FALSE); return (FALSE);
} }
#endif #endif
@ -413,16 +411,16 @@ char *sub; /* substring to look for */
unsigned int getckey(mflag) unsigned int getckey(mflag)
int mflag; /* going for a meta sequence? */ int mflag; /* going for a meta sequence? */
{ {
register unsigned int c; /* character fetched */ register unsigned int c; /* character fetched */
char tok[NSTRING]; /* command incoming */ char tok[NSTRING]; /* command incoming */
/* check to see if we are executing a command line */ /* check to see if we are executing a command line */
if (clexec) { if (clexec) {
macarg(tok); /* get the next token */ macarg(tok); /* get the next token */
return(stock(tok)); return (stock(tok));
} }
/* or the normal way */ /* or the normal way */
@ -430,17 +428,17 @@ int mflag; /* going for a meta sequence? */
c = get1key(); c = get1key();
else else
c = getcmd(); c = getcmd();
return(c); return (c);
} }
/* execute the startup file */ /* execute the startup file */
startup(sfname) startup(sfname)
char *sfname; /* name of startup file (null if default) */ char *sfname; /* name of startup file (null if default) */
{ {
char *fname; /* resulting file name to execute */ char *fname; /* resulting file name to execute */
/* look up the startup file */ /* look up the startup file */
if (*sfname != 0) if (*sfname != 0)
@ -450,10 +448,10 @@ char *sfname; /* name of startup file (null if default) */
/* if it isn't around, don't sweat it */ /* if it isn't around, don't sweat it */
if (fname == NULL) if (fname == NULL)
return(TRUE); return (TRUE);
/* otherwise, execute the sucker */ /* otherwise, execute the sucker */
return(dofile(fname)); return (dofile(fname));
} }
/* Look up the existance of a file along the normal or PATH /* Look up the existance of a file along the normal or PATH
@ -463,8 +461,8 @@ char *sfname; /* name of startup file (null if default) */
char *flook(fname, hflag) char *flook(fname, hflag)
char *fname; /* base file name to search for */ char *fname; /* base file name to search for */
int hflag; /* Look in the HOME environment variable first? */ int hflag; /* Look in the HOME environment variable first? */
{ {
register char *home; /* path to home directory */ register char *home; /* path to home directory */
@ -487,7 +485,7 @@ int hflag; /* Look in the HOME environment variable first? */
/* and try it out */ /* and try it out */
if (ffropen(fspec) == FIOSUC) { if (ffropen(fspec) == FIOSUC) {
ffclose(); ffclose();
return(fspec); return (fspec);
} }
} }
} }
@ -496,9 +494,8 @@ int hflag; /* Look in the HOME environment variable first? */
/* always try the current directory first */ /* always try the current directory first */
if (ffropen(fname) == FIOSUC) { if (ffropen(fname) == FIOSUC) {
ffclose(); ffclose();
return(fname); return (fname);
} }
#if ENVFUNC #if ENVFUNC
/* get the PATH variable */ /* get the PATH variable */
path = getenv("PATH"); path = getenv("PATH");
@ -519,7 +516,7 @@ int hflag; /* Look in the HOME environment variable first? */
/* and try it out */ /* and try it out */
if (ffropen(fspec) == FIOSUC) { if (ffropen(fspec) == FIOSUC) {
ffclose(); ffclose();
return(fspec); return (fspec);
} }
if (*path == PATHCHR) if (*path == PATHCHR)
@ -528,27 +525,27 @@ int hflag; /* Look in the HOME environment variable first? */
#endif #endif
/* look it up via the old table method */ /* look it up via the old table method */
for (i=2; i < NPNAMES; i++) { for (i = 2; i < NPNAMES; i++) {
strcpy(fspec, pathname[i]); strcpy(fspec, pathname[i]);
strcat(fspec, fname); strcat(fspec, fname);
/* and try it out */ /* and try it out */
if (ffropen(fspec) == FIOSUC) { if (ffropen(fspec) == FIOSUC) {
ffclose(); ffclose();
return(fspec); return (fspec);
} }
} }
return(NULL); /* no such luck */ return (NULL); /* no such luck */
} }
cmdstr(c, seq) /* change a key command to a string we can print out */ cmdstr(c, seq)
/* change a key command to a string we can print out */
int c; /* sequence to translate */ int c; /* sequence to translate */
char *seq; /* destination string for sequence */ char *seq; /* destination string for sequence */
{ {
char *ptr; /* pointer into current position in sequence */ char *ptr; /* pointer into current position in sequence */
ptr = seq; ptr = seq;
@ -578,28 +575,28 @@ char *seq; /* destination string for sequence */
/* and output the final sequence */ /* and output the final sequence */
*ptr++ = c & 255; /* strip the prefixes */ *ptr++ = c & 255; /* strip the prefixes */
*ptr = 0; /* terminate the string */ *ptr = 0; /* terminate the string */
} }
/* This function looks a key binding up in the binding table */ /* This function looks a key binding up in the binding table */
int (*getbind(c))() int (*getbind(c)) ()
int c; /* key to find what is bound to it */ int c; /* key to find what is bound to it */
{ {
register KEYTAB *ktp; register KEYTAB *ktp;
ktp = &keytab[0]; /* Look in key table. */ ktp = &keytab[0]; /* Look in key table. */
while (ktp->k_fp != NULL) { while (ktp->k_fp != NULL) {
if (ktp->k_code == c) if (ktp->k_code == c)
return(ktp->k_fp); return (ktp->k_fp);
++ktp; ++ktp;
} }
/* no such binding */ /* no such binding */
return(NULL); return (NULL);
} }
/* getfname: This function takes a ptr to function and gets the name /* getfname: This function takes a ptr to function and gets the name
@ -608,7 +605,7 @@ int c; /* key to find what is bound to it */
char *getfname(func) char *getfname(func)
int (*func)(); /* ptr to the requested function to bind to */ int (*func) (); /* ptr to the requested function to bind to */
{ {
register NBIND *nptr; /* pointer into the name binding table */ register NBIND *nptr; /* pointer into the name binding table */
@ -617,16 +614,16 @@ int (*func)(); /* ptr to the requested function to bind to */
nptr = &names[0]; nptr = &names[0];
while (nptr->n_func != NULL) { while (nptr->n_func != NULL) {
if (nptr->n_func == func) if (nptr->n_func == func)
return(nptr->n_name); return (nptr->n_name);
++nptr; ++nptr;
} }
return(NULL); return (NULL);
} }
int (*fncmatch(fname))() /* match fname to a function in the names table int (*fncmatch(fname)) ()
and return any match or NULL if none */ /* match fname to a function in the names table
and return any match or NULL if none */
char *fname; /* name to attempt to match */ char *fname; /* name to attempt to match */
{ {
register NBIND *ffp; /* pointer to entry in name binding table */ register NBIND *ffp; /* pointer to entry in name binding table */
@ -635,17 +632,17 @@ char *fname; /* name to attempt to match */
ffp = &names[0]; ffp = &names[0];
while (ffp->n_func != NULL) { while (ffp->n_func != NULL) {
if (strcmp(fname, ffp->n_name) == 0) if (strcmp(fname, ffp->n_name) == 0)
return(ffp->n_func); return (ffp->n_func);
++ffp; ++ffp;
} }
return(NULL); return (NULL);
} }
/* stock: String key name TO Command Key */ /* stock: String key name TO Command Key */
unsigned int stock(keyname) unsigned int stock(keyname)
char *keyname; /* name of key to translate to Command key form */ char *keyname; /* name of key to translate to Command key form */
{ {
register unsigned int c; /* key sequence to return */ register unsigned int c; /* key sequence to return */
@ -654,25 +651,25 @@ char *keyname; /* name of key to translate to Command key form */
c = 0; c = 0;
/* first, the META prefix */ /* first, the META prefix */
if (*keyname == 'M' && *(keyname+1) == '-') { if (*keyname == 'M' && *(keyname + 1) == '-') {
c = META; c = META;
keyname += 2; keyname += 2;
} }
/* next the function prefix */ /* next the function prefix */
if (*keyname == 'F' && *(keyname+1) == 'N') { if (*keyname == 'F' && *(keyname + 1) == 'N') {
c |= SPEC; c |= SPEC;
keyname += 2; keyname += 2;
} }
/* control-x as well... (but not with FN) */ /* control-x as well... (but not with FN) */
if (*keyname == '^' && *(keyname+1) == 'X'&& !(c & SPEC)) { if (*keyname == '^' && *(keyname + 1) == 'X' && !(c & SPEC)) {
c |= CTLX; c |= CTLX;
keyname += 2; keyname += 2;
} }
/* a control char? */ /* a control char? */
if (*keyname == '^' && *(keyname+1) != 0) { if (*keyname == '^' && *(keyname + 1) != 0) {
c |= CONTROL; c |= CONTROL;
++keyname; ++keyname;
} }
@ -682,27 +679,27 @@ char *keyname; /* name of key to translate to Command key form */
} }
/* make sure we are not lower case (not with function keys)*/ /* make sure we are not lower case (not with function keys) */
if (*keyname >= 'a' && *keyname <= 'z' && !(c & SPEC)) if (*keyname >= 'a' && *keyname <= 'z' && !(c & SPEC))
*keyname -= 32; *keyname -= 32;
/* the final sequence... */ /* the final sequence... */
c |= *keyname; c |= *keyname;
return(c); return (c);
} }
char *transbind(skey) /* string key name to binding name.... */ char *transbind(skey)
/* string key name to binding name.... */
char *skey; /* name of keey to get binding for */ char *skey; /* name of keey to get binding for */
{ {
char *bindname; char *bindname;
unsigned int stock(); unsigned int stock();
int (*getbind())(); int (*getbind()) ();
bindname = getfname(getbind(stock(skey))); bindname = getfname(getbind(stock(skey)));
if (bindname == NULL) if (bindname == NULL)
bindname = "ERROR"; bindname = "ERROR";
return(bindname); return (bindname);
} }

565
buffer.c
View File

@ -21,29 +21,29 @@
*/ */
usebuffer(f, n) usebuffer(f, n)
{ {
register BUFFER *bp; register BUFFER *bp;
register int s; register int s;
char bufn[NBUFN]; char bufn[NBUFN];
if ((s=mlreply("Use buffer: ", bufn, NBUFN)) != TRUE) if ((s = mlreply("Use buffer: ", bufn, NBUFN)) != TRUE)
return (s); return (s);
if ((bp=bfind(bufn, TRUE, 0)) == NULL) if ((bp = bfind(bufn, TRUE, 0)) == NULL)
return (FALSE); return (FALSE);
return(swbuffer(bp)); return (swbuffer(bp));
} }
nextbuffer(f, n) /* switch to the next buffer in the buffer list */ nextbuffer(f, n)
/* switch to the next buffer in the buffer list */
int f, n; /* default flag, numeric argument */ int f, n; /* default flag, numeric argument */
{ {
register BUFFER *bp; /* eligable buffer to switch to*/ register BUFFER *bp; /* eligable buffer to switch to */
register BUFFER *bbp; /* eligable buffer to switch to*/ register BUFFER *bbp; /* eligable buffer to switch to */
/* make sure the arg is legit */ /* make sure the arg is legit */
if (f == FALSE) if (f == FALSE)
n = 1; n = 1;
if (n < 1) if (n < 1)
return(FALSE); return (FALSE);
bbp = curbp; bbp = curbp;
while (n-- > 0) { while (n-- > 0) {
@ -59,60 +59,60 @@ int f, n; /* default flag, numeric argument */
/* don't get caught in an infinite loop! */ /* don't get caught in an infinite loop! */
if (bp == bbp) if (bp == bbp)
return(FALSE); return (FALSE);
} }
bbp = bp; bbp = bp;
} }
return(swbuffer(bp)); return (swbuffer(bp));
} }
swbuffer(bp) /* make buffer BP current */ swbuffer(bp)
/* make buffer BP current */
BUFFER *bp; BUFFER *bp;
{ {
register WINDOW *wp; register WINDOW *wp;
if (--curbp->b_nwnd == 0) { /* Last use. */ if (--curbp->b_nwnd == 0) { /* Last use. */
curbp->b_dotp = curwp->w_dotp; curbp->b_dotp = curwp->w_dotp;
curbp->b_doto = curwp->w_doto; curbp->b_doto = curwp->w_doto;
curbp->b_markp = curwp->w_markp; curbp->b_markp = curwp->w_markp;
curbp->b_marko = curwp->w_marko; curbp->b_marko = curwp->w_marko;
} }
curbp = bp; /* Switch. */ curbp = bp; /* Switch. */
if (curbp->b_active != TRUE) { /* buffer not active yet*/ if (curbp->b_active != TRUE) { /* buffer not active yet */
/* read it in and activate it */ /* read it in and activate it */
readin(curbp->b_fname, TRUE); readin(curbp->b_fname, TRUE);
curbp->b_dotp = lforw(curbp->b_linep); curbp->b_dotp = lforw(curbp->b_linep);
curbp->b_doto = 0; curbp->b_doto = 0;
curbp->b_active = TRUE; curbp->b_active = TRUE;
curbp->b_mode |= gmode; /* P.K. */ curbp->b_mode |= gmode; /* P.K. */
} }
curwp->w_bufp = bp; curwp->w_bufp = bp;
curwp->w_linep = bp->b_linep; /* For macros, ignored. */ curwp->w_linep = bp->b_linep; /* For macros, ignored. */
curwp->w_flag |= WFMODE|WFFORCE|WFHARD; /* Quite nasty. */ curwp->w_flag |= WFMODE | WFFORCE | WFHARD; /* Quite nasty. */
if (bp->b_nwnd++ == 0) { /* First use. */ if (bp->b_nwnd++ == 0) { /* First use. */
curwp->w_dotp = bp->b_dotp; curwp->w_dotp = bp->b_dotp;
curwp->w_doto = bp->b_doto; curwp->w_doto = bp->b_doto;
curwp->w_markp = bp->b_markp; curwp->w_markp = bp->b_markp;
curwp->w_marko = bp->b_marko; curwp->w_marko = bp->b_marko;
cknewwindow(); cknewwindow();
return (TRUE); return (TRUE);
} }
wp = wheadp; /* Look for old. */ wp = wheadp; /* Look for old. */
while (wp != NULL) { while (wp != NULL) {
if (wp!=curwp && wp->w_bufp==bp) { if (wp != curwp && wp->w_bufp == bp) {
curwp->w_dotp = wp->w_dotp; curwp->w_dotp = wp->w_dotp;
curwp->w_doto = wp->w_doto; curwp->w_doto = wp->w_doto;
curwp->w_markp = wp->w_markp; curwp->w_markp = wp->w_markp;
curwp->w_marko = wp->w_marko; curwp->w_marko = wp->w_marko;
break; break;
} }
wp = wp->w_wndp; wp = wp->w_wndp;
} }
cknewwindow(); cknewwindow();
return (TRUE); return (TRUE);
} }
@ -126,63 +126,63 @@ BUFFER *bp;
* line and the buffer header. Bound to "C-X K". * line and the buffer header. Bound to "C-X K".
*/ */
killbuffer(f, n) killbuffer(f, n)
{ {
register BUFFER *bp; register BUFFER *bp;
register int s; register int s;
char bufn[NBUFN]; char bufn[NBUFN];
if ((s=mlreply("Kill buffer: ", bufn, NBUFN)) != TRUE) if ((s = mlreply("Kill buffer: ", bufn, NBUFN)) != TRUE)
return(s); return (s);
if ((bp=bfind(bufn, FALSE, 0)) == NULL) /* Easy if unknown. */ if ((bp = bfind(bufn, FALSE, 0)) == NULL) /* Easy if unknown. */
return (TRUE); return (TRUE);
if(bp->b_flag & BFINVS) /* Deal with special buffers */ if (bp->b_flag & BFINVS) /* Deal with special buffers */
return (TRUE); /* by doing nothing. */ return (TRUE); /* by doing nothing. */
return(zotbuf(bp)); return (zotbuf(bp));
} }
zotbuf(bp) /* kill the buffer pointed to by bp */ zotbuf(bp)
/* kill the buffer pointed to by bp */
register BUFFER *bp; register BUFFER *bp;
{ {
register BUFFER *bp1; register BUFFER *bp1;
register BUFFER *bp2; register BUFFER *bp2;
register int s; register int s;
if (bp->b_nwnd != 0) { /* Error if on screen. */ if (bp->b_nwnd != 0) { /* Error if on screen. */
mlwrite("Buffer is being displayed"); mlwrite("Buffer is being displayed");
return (FALSE); return (FALSE);
} }
if ((s=bclear(bp)) != TRUE) /* Blow text away. */ if ((s = bclear(bp)) != TRUE) /* Blow text away. */
return (s); return (s);
free((char *) bp->b_linep); /* Release header line. */ free((char *) bp->b_linep); /* Release header line. */
bp1 = NULL; /* Find the header. */ bp1 = NULL; /* Find the header. */
bp2 = bheadp; bp2 = bheadp;
while (bp2 != bp) { while (bp2 != bp) {
bp1 = bp2; bp1 = bp2;
bp2 = bp2->b_bufp; bp2 = bp2->b_bufp;
} }
bp2 = bp2->b_bufp; /* Next one in chain. */ bp2 = bp2->b_bufp; /* Next one in chain. */
if (bp1 == NULL) /* Unlink it. */ if (bp1 == NULL) /* Unlink it. */
bheadp = bp2; bheadp = bp2;
else else
bp1->b_bufp = bp2; bp1->b_bufp = bp2;
free((char *) bp); /* Release buffer block */ free((char *) bp); /* Release buffer block */
return (TRUE); return (TRUE);
} }
namebuffer(f,n) /* Rename the current buffer */ namebuffer(f, n)
/* Rename the current buffer */
int f, n; /* default Flag & Numeric arg */ int f, n; /* default Flag & Numeric arg */
{ {
register BUFFER *bp; /* pointer to scan through all buffers */ register BUFFER *bp; /* pointer to scan through all buffers */
char bufn[NBUFN]; /* buffer to hold buffer name */ char bufn[NBUFN]; /* buffer to hold buffer name */
/* prompt for and get the new buffer name */ /* prompt for and get the new buffer name */
ask: if (mlreply("Change buffer name to: ", bufn, NBUFN) != TRUE) ask:if (mlreply("Change buffer name to: ", bufn, NBUFN) !=
return(FALSE); TRUE)
return (FALSE);
/* and check for duplicates */ /* and check for duplicates */
bp = bheadp; bp = bheadp;
@ -190,7 +190,7 @@ ask: if (mlreply("Change buffer name to: ", bufn, NBUFN) != TRUE)
if (bp != curbp) { if (bp != curbp) {
/* if the names the same */ /* if the names the same */
if (strcmp(bufn, bp->b_bname) == 0) if (strcmp(bufn, bp->b_bname) == 0)
goto ask; /* try again */ goto ask; /* try again */
} }
bp = bp->b_bufp; /* onward */ bp = bp->b_bufp; /* onward */
} }
@ -198,7 +198,7 @@ ask: if (mlreply("Change buffer name to: ", bufn, NBUFN) != TRUE)
strcpy(curbp->b_bname, bufn); /* copy buffer name to structure */ strcpy(curbp->b_bname, bufn); /* copy buffer name to structure */
curwp->w_flag |= WFMODE; /* make mode line replot */ curwp->w_flag |= WFMODE; /* make mode line replot */
mlerase(); mlerase();
return(TRUE); return (TRUE);
} }
/* /*
@ -213,38 +213,38 @@ ask: if (mlreply("Change buffer name to: ", bufn, NBUFN) != TRUE)
listbuffers(f, n) listbuffers(f, n)
{ {
register WINDOW *wp; register WINDOW *wp;
register BUFFER *bp; register BUFFER *bp;
register int s; register int s;
if ((s=makelist(f)) != TRUE) if ((s = makelist(f)) != TRUE)
return (s); return (s);
if (blistp->b_nwnd == 0) { /* Not on screen yet. */ if (blistp->b_nwnd == 0) { /* Not on screen yet. */
if ((wp=wpopup()) == NULL) if ((wp = wpopup()) == NULL)
return (FALSE); return (FALSE);
bp = wp->w_bufp; bp = wp->w_bufp;
if (--bp->b_nwnd == 0) { if (--bp->b_nwnd == 0) {
bp->b_dotp = wp->w_dotp; bp->b_dotp = wp->w_dotp;
bp->b_doto = wp->w_doto; bp->b_doto = wp->w_doto;
bp->b_markp = wp->w_markp; bp->b_markp = wp->w_markp;
bp->b_marko = wp->w_marko; bp->b_marko = wp->w_marko;
} }
wp->w_bufp = blistp; wp->w_bufp = blistp;
++blistp->b_nwnd; ++blistp->b_nwnd;
} }
wp = wheadp; wp = wheadp;
while (wp != NULL) { while (wp != NULL) {
if (wp->w_bufp == blistp) { if (wp->w_bufp == blistp) {
wp->w_linep = lforw(blistp->b_linep); wp->w_linep = lforw(blistp->b_linep);
wp->w_dotp = lforw(blistp->b_linep); wp->w_dotp = lforw(blistp->b_linep);
wp->w_doto = 0; wp->w_doto = 0;
wp->w_markp = NULL; wp->w_markp = NULL;
wp->w_marko = 0; wp->w_marko = 0;
wp->w_flag |= WFMODE|WFHARD; wp->w_flag |= WFMODE | WFHARD;
} }
wp = wp->w_wndp; wp = wp->w_wndp;
} }
return (TRUE); return (TRUE);
} }
/* /*
@ -259,28 +259,29 @@ listbuffers(f, n)
#define MAXLINE MAXCOL #define MAXLINE MAXCOL
makelist(iflag) makelist(iflag)
int iflag; /* list hidden buffer flag */ int iflag; /* list hidden buffer flag */
{ {
register char *cp1; register char *cp1;
register char *cp2; register char *cp2;
register int c; register int c;
register BUFFER *bp; register BUFFER *bp;
register LINE *lp; register LINE *lp;
register int s; register int s;
register int i; register int i;
long nbytes; /* # of bytes in current buffer */ long nbytes; /* # of bytes in current buffer */
char b[7+1]; char b[7 + 1];
char line[MAXLINE]; char line[MAXLINE];
blistp->b_flag &= ~BFCHG; /* Don't complain! */ blistp->b_flag &= ~BFCHG; /* Don't complain! */
if ((s=bclear(blistp)) != TRUE) /* Blow old text away */ if ((s = bclear(blistp)) != TRUE) /* Blow old text away */
return (s); return (s);
strcpy(blistp->b_fname, ""); strcpy(blistp->b_fname, "");
if (addline("ACT MODES Size Buffer File") == FALSE if (addline("ACT MODES Size Buffer File") == FALSE
|| addline("--- ----- ---- ------ ----") == FALSE) || addline("--- ----- ---- ------ ----") ==
return (FALSE); FALSE)
bp = bheadp; /* For all buffers */ return (FALSE);
bp = bheadp; /* For all buffers */
/* build line to report global mode settings */ /* build line to report global mode settings */
cp1 = &line[0]; cp1 = &line[0];
@ -297,36 +298,36 @@ int iflag; /* list hidden buffer flag */
*cp1++ = '.'; *cp1++ = '.';
strcpy(cp1, " Global Modes"); strcpy(cp1, " Global Modes");
if (addline(line) == FALSE) if (addline(line) == FALSE)
return(FALSE); return (FALSE);
/* output the list of buffers */ /* output the list of buffers */
while (bp != NULL) { while (bp != NULL) {
/* skip invisable buffers if iflag is false */ /* skip invisable buffers if iflag is false */
if (((bp->b_flag&BFINVS) != 0) && (iflag != TRUE)) { if (((bp->b_flag & BFINVS) != 0) && (iflag != TRUE)) {
bp = bp->b_bufp; bp = bp->b_bufp;
continue; continue;
} }
cp1 = &line[0]; /* Start at left edge */ cp1 = &line[0]; /* Start at left edge */
/* output status of ACTIVE flag (has the file been read in? */ /* output status of ACTIVE flag (has the file been read in? */
if (bp->b_active == TRUE) /* "@" if activated */ if (bp->b_active == TRUE) /* "@" if activated */
*cp1++ = '@'; *cp1++ = '@';
else else
*cp1++ = ' '; *cp1++ = ' ';
/* output status of changed flag */ /* output status of changed flag */
if ((bp->b_flag&BFCHG) != 0) /* "*" if changed */ if ((bp->b_flag & BFCHG) != 0) /* "*" if changed */
*cp1++ = '*'; *cp1++ = '*';
else else
*cp1++ = ' '; *cp1++ = ' ';
/* report if the file is truncated */ /* report if the file is truncated */
if ((bp->b_flag&BFTRUNC) != 0) if ((bp->b_flag & BFTRUNC) != 0)
*cp1++ = '#'; *cp1++ = '#';
else else
*cp1++ = ' '; *cp1++ = ' ';
*cp1++ = ' '; /* space */ *cp1++ = ' '; /* space */
/* output the mode codes */ /* output the mode codes */
for (i = 0; i < NUMMODES; i++) { for (i = 0; i < NUMMODES; i++) {
@ -335,53 +336,53 @@ int iflag; /* list hidden buffer flag */
else else
*cp1++ = '.'; *cp1++ = '.';
} }
*cp1++ = ' '; /* Gap. */ *cp1++ = ' '; /* Gap. */
nbytes = 0L; /* Count bytes in buf. */ nbytes = 0L; /* Count bytes in buf. */
lp = lforw(bp->b_linep); lp = lforw(bp->b_linep);
while (lp != bp->b_linep) { while (lp != bp->b_linep) {
nbytes += (long)llength(lp)+1L; nbytes += (long) llength(lp) + 1L;
lp = lforw(lp); lp = lforw(lp);
} }
ltoa(b, 7, nbytes); /* 6 digit buffer size. */ ltoa(b, 7, nbytes); /* 6 digit buffer size. */
cp2 = &b[0]; cp2 = &b[0];
while ((c = *cp2++) != 0) while ((c = *cp2++) != 0)
*cp1++ = c; *cp1++ = c;
*cp1++ = ' '; /* Gap. */ *cp1++ = ' '; /* Gap. */
cp2 = &bp->b_bname[0]; /* Buffer name */ cp2 = &bp->b_bname[0]; /* Buffer name */
while ((c = *cp2++) != 0) while ((c = *cp2++) != 0)
*cp1++ = c; *cp1++ = c;
cp2 = &bp->b_fname[0]; /* File name */ cp2 = &bp->b_fname[0]; /* File name */
if (*cp2 != 0) { if (*cp2 != 0) {
while (cp1 < &line[3+1+5+1+6+4+NBUFN]) while (cp1 < &line[3 + 1 + 5 + 1 + 6 + 4 + NBUFN])
*cp1++ = ' '; *cp1++ = ' ';
while ((c = *cp2++) != 0) { while ((c = *cp2++) != 0) {
if (cp1 < &line[MAXLINE-1]) if (cp1 < &line[MAXLINE - 1])
*cp1++ = c; *cp1++ = c;
} }
} }
*cp1 = 0; /* Add to the buffer. */ *cp1 = 0; /* Add to the buffer. */
if (addline(line) == FALSE) if (addline(line) == FALSE)
return (FALSE); return (FALSE);
bp = bp->b_bufp; bp = bp->b_bufp;
} }
return (TRUE); /* All done */ return (TRUE); /* All done */
} }
ltoa(buf, width, num) ltoa(buf, width, num)
char buf[]; char buf[];
int width; int width;
long num; long num;
{ {
buf[width] = 0; /* End of string. */ buf[width] = 0; /* End of string. */
while (num >= 10) { /* Conditional digits. */ while (num >= 10) { /* Conditional digits. */
buf[--width] = (int)(num%10L) + '0'; buf[--width] = (int) (num % 10L) + '0';
num /= 10L; num /= 10L;
} }
buf[--width] = (int)num + '0'; /* Always 1 digit. */ buf[--width] = (int) num + '0'; /* Always 1 digit. */
while (width != 0) /* Pad with blanks. */ while (width != 0) /* Pad with blanks. */
buf[--width] = ' '; buf[--width] = ' ';
} }
/* /*
@ -392,24 +393,24 @@ long num;
* FALSE if you ran out of room. * FALSE if you ran out of room.
*/ */
addline(text) addline(text)
char *text; char *text;
{ {
register LINE *lp; register LINE *lp;
register int i; register int i;
register int ntext; register int ntext;
ntext = strlen(text); ntext = strlen(text);
if ((lp=lalloc(ntext)) == NULL) if ((lp = lalloc(ntext)) == NULL)
return (FALSE); return (FALSE);
for (i=0; i<ntext; ++i) for (i = 0; i < ntext; ++i)
lputc(lp, i, text[i]); lputc(lp, i, text[i]);
blistp->b_linep->l_bp->l_fp = lp; /* Hook onto the end */ blistp->b_linep->l_bp->l_fp = lp; /* Hook onto the end */
lp->l_bp = blistp->b_linep->l_bp; lp->l_bp = blistp->b_linep->l_bp;
blistp->b_linep->l_bp = lp; blistp->b_linep->l_bp = lp;
lp->l_fp = blistp->b_linep; lp->l_fp = blistp->b_linep;
if (blistp->b_dotp == blistp->b_linep) /* If "." is at the end */ if (blistp->b_dotp == blistp->b_linep) /* If "." is at the end */
blistp->b_dotp = lp; /* move it to new line */ blistp->b_dotp = lp; /* move it to new line */
return (TRUE); return (TRUE);
} }
/* /*
@ -424,15 +425,16 @@ char *text;
*/ */
anycb() anycb()
{ {
register BUFFER *bp; register BUFFER *bp;
bp = bheadp; bp = bheadp;
while (bp != NULL) { while (bp != NULL) {
if ((bp->b_flag&BFINVS)==0 && (bp->b_flag&BFCHG)!=0) if ((bp->b_flag & BFINVS) == 0
return (TRUE); && (bp->b_flag & BFCHG) != 0)
bp = bp->b_bufp; return (TRUE);
} bp = bp->b_bufp;
return (FALSE); }
return (FALSE);
} }
/* /*
@ -442,34 +444,33 @@ anycb()
* and the "cflag" is TRUE, create it. The "bflag" is * and the "cflag" is TRUE, create it. The "bflag" is
* the settings for the flags in in buffer. * the settings for the flags in in buffer.
*/ */
BUFFER * BUFFER *bfind(bname, cflag, bflag)
bfind(bname, cflag, bflag) register char *bname;
register char *bname;
{ {
register BUFFER *bp; register BUFFER *bp;
register BUFFER *sb; /* buffer to insert after */ register BUFFER *sb; /* buffer to insert after */
register LINE *lp; register LINE *lp;
char *malloc(); char *malloc();
bp = bheadp; bp = bheadp;
while (bp != NULL) { while (bp != NULL) {
if (strcmp(bname, bp->b_bname) == 0) if (strcmp(bname, bp->b_bname) == 0)
return (bp); return (bp);
bp = bp->b_bufp; bp = bp->b_bufp;
} }
if (cflag != FALSE) { if (cflag != FALSE) {
if ((bp=(BUFFER *)malloc(sizeof(BUFFER))) == NULL) if ((bp = (BUFFER *) malloc(sizeof(BUFFER))) == NULL)
return (NULL); return (NULL);
if ((lp=lalloc(0)) == NULL) { if ((lp = lalloc(0)) == NULL) {
free((char *) bp); free((char *) bp);
return (NULL); return (NULL);
} }
/* find the place in the list to insert this buffer */ /* find the place in the list to insert this buffer */
if (bheadp == NULL || strcmp(bheadp->b_bname, bname) > 0) { if (bheadp == NULL || strcmp(bheadp->b_bname, bname) > 0) {
/* insert at the beginning */ /* insert at the beginning */
bp->b_bufp = bheadp; bp->b_bufp = bheadp;
bheadp = bp; bheadp = bp;
} else { } else {
sb = bheadp; sb = bheadp;
while (sb->b_bufp != NULL) { while (sb->b_bufp != NULL) {
if (strcmp(sb->b_bufp->b_bname, bname) > 0) if (strcmp(sb->b_bufp->b_bname, bname) > 0)
@ -478,29 +479,29 @@ register char *bname;
} }
/* and insert it */ /* and insert it */
bp->b_bufp = sb->b_bufp; bp->b_bufp = sb->b_bufp;
sb->b_bufp = bp; sb->b_bufp = bp;
} }
/* and set up the other buffer fields */ /* and set up the other buffer fields */
bp->b_active = TRUE; bp->b_active = TRUE;
bp->b_dotp = lp; bp->b_dotp = lp;
bp->b_doto = 0; bp->b_doto = 0;
bp->b_markp = NULL; bp->b_markp = NULL;
bp->b_marko = 0; bp->b_marko = 0;
bp->b_flag = bflag; bp->b_flag = bflag;
bp->b_mode = gmode; bp->b_mode = gmode;
bp->b_nwnd = 0; bp->b_nwnd = 0;
bp->b_linep = lp; bp->b_linep = lp;
strcpy(bp->b_fname, ""); strcpy(bp->b_fname, "");
strcpy(bp->b_bname, bname); strcpy(bp->b_bname, bname);
#if CRYPT #if CRYPT
bp->b_key[0] = 0; bp->b_key[0] = 0;
#endif #endif
lp->l_fp = lp; lp->l_fp = lp;
lp->l_bp = lp; lp->l_bp = lp;
} }
return (bp); return (bp);
} }
/* /*
@ -516,29 +517,29 @@ register char *bname;
bclear(bp) bclear(bp)
register BUFFER *bp; register BUFFER *bp;
{ {
register LINE *lp; register LINE *lp;
register int s; register int s;
if ((bp->b_flag&BFINVS) == 0 /* Not scratch buffer. */ if ((bp->b_flag & BFINVS) == 0 /* Not scratch buffer. */
&& (bp->b_flag&BFCHG) != 0 /* Something changed */ && (bp->b_flag & BFCHG) != 0 /* Something changed */
&& (s=mlyesno("Discard changes")) != TRUE) && (s = mlyesno("Discard changes")) != TRUE)
return (s); return (s);
bp->b_flag &= ~BFCHG; /* Not changed */ bp->b_flag &= ~BFCHG; /* Not changed */
while ((lp=lforw(bp->b_linep)) != bp->b_linep) while ((lp = lforw(bp->b_linep)) != bp->b_linep)
lfree(lp); lfree(lp);
bp->b_dotp = bp->b_linep; /* Fix "." */ bp->b_dotp = bp->b_linep; /* Fix "." */
bp->b_doto = 0; bp->b_doto = 0;
bp->b_markp = NULL; /* Invalidate "mark" */ bp->b_markp = NULL; /* Invalidate "mark" */
bp->b_marko = 0; bp->b_marko = 0;
return (TRUE); return (TRUE);
} }
unmark(f, n) /* unmark the current buffers change flag */ unmark(f, n)
/* unmark the current buffers change flag */
int f, n; /* unused command arguments */ int f, n; /* unused command arguments */
{ {
curbp->b_flag &= ~BFCHG; curbp->b_flag &= ~BFCHG;
curwp->w_flag |= WFMODE; curwp->w_flag |= WFMODE;
return(TRUE); return (TRUE);
} }

24
crypt.c
View File

@ -13,10 +13,10 @@
static int mod95(); static int mod95();
setkey(f, n) /* reset encryption key of current buffer */ setkey(f, n)
/* reset encryption key of current buffer */
int f; /* default flag */ int f; /* default flag */
int n; /* numeric argument */ int n; /* numeric argument */
{ {
register int status; /* return status */ register int status; /* return status */
@ -30,17 +30,17 @@ int n; /* numeric argument */
/* get the string to use as an encrytion string */ /* get the string to use as an encrytion string */
status = mlreply("Encryption String: ", key, NPAT - 1); status = mlreply("Encryption String: ", key, NPAT - 1);
disinp = odisinp; disinp = odisinp;
if (status != TRUE) if (status != TRUE)
return(status); return (status);
/* and encrypt it */ /* and encrypt it */
crypt((char *)NULL, 0); crypt((char *) NULL, 0);
crypt(key, strlen(key)); crypt(key, strlen(key));
/* and save it off */ /* and save it off */
strcpy(curbp->b_key, key); strcpy(curbp->b_key, key);
mlwrite(" "); /* clear it off the bottom line */ mlwrite(" "); /* clear it off the bottom line */
return(TRUE); return (TRUE);
} }
/********** /**********
@ -137,8 +137,8 @@ int n; /* numeric argument */
**********/ **********/
crypt(bptr, len) crypt(bptr, len)
register char *bptr; /* buffer of characters to be encrypted */ register char *bptr; /* buffer of characters to be encrypted */
register unsigned len; /* number of characters in the buffer */ register unsigned len; /* number of characters in the buffer */
{ {
register int cc; /* current character being considered */ register int cc; /* current character being considered */
@ -170,7 +170,7 @@ register unsigned len; /* number of characters in the buffer */
so that the left shift here will be more portable and the so that the left shift here will be more portable and the
mod95() faster **/ mod95() faster **/
cc = mod95((int)(key % 95) - (cc - ' ')) + ' '; cc = mod95((int) (key % 95) - (cc - ' ')) + ' ';
/** the salt will spice up the key a little bit, helping to obscure /** the salt will spice up the key a little bit, helping to obscure
any patterns in the clear text, particularly when all the any patterns in the clear text, particularly when all the
@ -202,7 +202,7 @@ register int val;
/* The mathematical MOD does not match the computer MOD */ /* The mathematical MOD does not match the computer MOD */
/* Yes, what I do here may look strange, but it gets the /* Yes, what I do here may look strange, but it gets the
job done, and portably at that. */ job done, and portably at that. */
while (val >= 9500) while (val >= 9500)
val -= 9500; val -= 9500;

1014
display.c

File diff suppressed because it is too large Load Diff

529
ebind.h
View File

@ -11,239 +11,408 @@
* characters of the command. This explains the funny location of the * characters of the command. This explains the funny location of the
* control-X commands. * control-X commands.
*/ */
KEYTAB keytab[NBINDS] = { KEYTAB keytab[NBINDS] = {
{CONTROL|'A', gotobol}, {CONTROL | 'A', gotobol}
{CONTROL|'B', backchar}, ,
{CONTROL|'C', insspace}, {CONTROL | 'B', backchar}
{CONTROL|'D', forwdel}, ,
{CONTROL|'E', gotoeol}, {CONTROL | 'C', insspace}
{CONTROL|'F', forwchar}, ,
{CONTROL|'G', ctrlg}, {CONTROL | 'D', forwdel}
{CONTROL|'H', backdel}, ,
{CONTROL|'I', tab}, {CONTROL | 'E', gotoeol}
{CONTROL|'J', indent}, ,
{CONTROL|'K', killtext}, {CONTROL | 'F', forwchar}
{CONTROL|'L', refresh}, ,
{CONTROL|'M', newline}, {CONTROL | 'G', ctrlg}
{CONTROL|'N', forwline}, ,
{CONTROL|'O', openline}, {CONTROL | 'H', backdel}
{CONTROL|'P', backline}, ,
{CONTROL|'Q', quote}, {CONTROL | 'I', tab}
{CONTROL|'R', backsearch}, ,
{CONTROL|'S', forwsearch}, {CONTROL | 'J', indent}
{CONTROL|'T', twiddle}, ,
{CONTROL|'U', unarg}, {CONTROL | 'K', killtext}
{CONTROL|'V', forwpage}, ,
{CONTROL|'W', killregion}, {CONTROL | 'L', refresh}
{CONTROL|'X', cex}, ,
{CONTROL|'Y', yank}, {CONTROL | 'M', newline}
{CONTROL|'Z', backpage}, ,
{CONTROL|']', meta}, {CONTROL | 'N', forwline}
{CTLX|CONTROL|'B', listbuffers}, ,
{CTLX|CONTROL|'C', quit}, /* Hard quit. */ {CONTROL | 'O', openline}
,
{CONTROL | 'P', backline}
,
{CONTROL | 'Q', quote}
,
{CONTROL | 'R', backsearch}
,
{CONTROL | 'S', forwsearch}
,
{CONTROL | 'T', twiddle}
,
{CONTROL | 'U', unarg}
,
{CONTROL | 'V', forwpage}
,
{CONTROL | 'W', killregion}
,
{CONTROL | 'X', cex}
,
{CONTROL | 'Y', yank}
,
{CONTROL | 'Z', backpage}
,
{CONTROL | ']', meta}
,
{CTLX | CONTROL | 'B', listbuffers}
,
{CTLX | CONTROL | 'C', quit}
, /* Hard quit. */
#if PKCODE & AEDIT #if PKCODE & AEDIT
{CTLX|CONTROL|'A', detab}, {CTLX | CONTROL | 'A', detab}
,
#endif #endif
#if PKCODE #if PKCODE
{CTLX|CONTROL|'D', filesave}, /* alternative */ {CTLX | CONTROL | 'D', filesave}
, /* alternative */
#else #else
#if AEDIT #if AEDIT
{CTLX|CONTROL|'D', detab}, {CTLX | CONTROL | 'D', detab}
,
#endif #endif
#endif #endif
#if AEDIT #if AEDIT
{CTLX|CONTROL|'E', entab}, {CTLX | CONTROL | 'E', entab}
,
#endif #endif
{CTLX|CONTROL|'F', filefind}, {CTLX | CONTROL | 'F', filefind}
{CTLX|CONTROL|'I', insfile}, ,
{CTLX|CONTROL|'L', lowerregion}, {CTLX | CONTROL | 'I', insfile}
{CTLX|CONTROL|'M', delmode}, ,
{CTLX|CONTROL|'N', mvdnwind}, {CTLX | CONTROL | 'L', lowerregion}
{CTLX|CONTROL|'O', deblank}, ,
{CTLX|CONTROL|'P', mvupwind}, {CTLX | CONTROL | 'M', delmode}
{CTLX|CONTROL|'R', fileread}, ,
{CTLX|CONTROL|'S', filesave}, {CTLX | CONTROL | 'N', mvdnwind}
,
{CTLX | CONTROL | 'O', deblank}
,
{CTLX | CONTROL | 'P', mvupwind}
,
{CTLX | CONTROL | 'R', fileread}
,
{CTLX | CONTROL | 'S', filesave}
,
#if AEDIT #if AEDIT
{CTLX|CONTROL|'T', trim}, {CTLX | CONTROL | 'T', trim}
,
#endif #endif
{CTLX|CONTROL|'U', upperregion}, {CTLX | CONTROL | 'U', upperregion}
{CTLX|CONTROL|'V', viewfile}, ,
{CTLX|CONTROL|'W', filewrite}, {CTLX | CONTROL | 'V', viewfile}
{CTLX|CONTROL|'X', swapmark}, ,
{CTLX|CONTROL|'Z', shrinkwind}, {CTLX | CONTROL | 'W', filewrite}
{CTLX|'?', deskey}, ,
{CTLX|'!', spawn}, {CTLX | CONTROL | 'X', swapmark}
{CTLX|'@', pipecmd}, ,
{CTLX|'#', filter}, {CTLX | CONTROL | 'Z', shrinkwind}
{CTLX|'$', execprg}, ,
{CTLX|'=', showcpos}, {CTLX | '?', deskey}
{CTLX|'(', ctlxlp}, ,
{CTLX|')', ctlxrp}, {CTLX | '!', spawn}
{CTLX|'^', enlargewind}, ,
{CTLX|'0', delwind}, {CTLX | '@', pipecmd}
{CTLX|'1', onlywind}, ,
{CTLX|'2', splitwind}, {CTLX | '#', filter}
{CTLX|'A', setvar}, ,
{CTLX|'B', usebuffer}, {CTLX | '$', execprg}
{CTLX|'C', spawncli}, ,
{CTLX | '=', showcpos}
,
{CTLX | '(', ctlxlp}
,
{CTLX | ')', ctlxrp}
,
{CTLX | '^', enlargewind}
,
{CTLX | '0', delwind}
,
{CTLX | '1', onlywind}
,
{CTLX | '2', splitwind}
,
{CTLX | 'A', setvar}
,
{CTLX | 'B', usebuffer}
,
{CTLX | 'C', spawncli}
,
#if BSD | __hpux | SVR4 #if BSD | __hpux | SVR4
{CTLX|'D', bktoshell}, {CTLX | 'D', bktoshell}
,
#endif #endif
{CTLX|'E', ctlxe}, {CTLX | 'E', ctlxe}
{CTLX|'F', setfillcol}, ,
{CTLX|'K', killbuffer}, {CTLX | 'F', setfillcol}
{CTLX|'M', setmode}, ,
{CTLX|'N', filename}, {CTLX | 'K', killbuffer}
{CTLX|'O', nextwind}, ,
{CTLX|'P', prevwind}, {CTLX | 'M', setmode}
,
{CTLX | 'N', filename}
,
{CTLX | 'O', nextwind}
,
{CTLX | 'P', prevwind}
,
#if PKCODE #if PKCODE
{CTLX|'Q', quote}, /* alternative */ {CTLX | 'Q', quote}
, /* alternative */
#endif #endif
#if ISRCH #if ISRCH
{CTLX|'R', risearch}, {CTLX | 'R', risearch}
{CTLX|'S', fisearch}, ,
{CTLX | 'S', fisearch}
,
#endif #endif
{CTLX|'W', resize}, {CTLX | 'W', resize}
{CTLX|'X', nextbuffer}, ,
{CTLX|'Z', enlargewind}, {CTLX | 'X', nextbuffer}
,
{CTLX | 'Z', enlargewind}
,
#if WORDPRO #if WORDPRO
{META|CONTROL|'C', wordcount}, {META | CONTROL | 'C', wordcount}
,
#endif #endif
#if PKCODE #if PKCODE
{META|CONTROL|'D', newsize}, {META | CONTROL | 'D', newsize}
,
#endif #endif
#if PROC #if PROC
{META|CONTROL|'E', execproc}, {META | CONTROL | 'E', execproc}
,
#endif #endif
#if CFENCE #if CFENCE
{META|CONTROL|'F', getfence}, {META | CONTROL | 'F', getfence}
,
#endif #endif
{META|CONTROL|'H', delbword}, {META | CONTROL | 'H', delbword}
{META|CONTROL|'K', unbindkey}, ,
{META|CONTROL|'L', reposition}, {META | CONTROL | 'K', unbindkey}
{META|CONTROL|'M', delgmode}, ,
{META|CONTROL|'N', namebuffer}, {META | CONTROL | 'L', reposition}
{META|CONTROL|'R', qreplace}, ,
{META|CONTROL|'S', newsize}, {META | CONTROL | 'M', delgmode}
{META|CONTROL|'T', newwidth}, ,
{META|CONTROL|'V', scrnextdw}, {META | CONTROL | 'N', namebuffer}
,
{META | CONTROL | 'R', qreplace}
,
{META | CONTROL | 'S', newsize}
,
{META | CONTROL | 'T', newwidth}
,
{META | CONTROL | 'V', scrnextdw}
,
#if WORDPRO #if WORDPRO
{META|CONTROL|'W', killpara}, {META | CONTROL | 'W', killpara}
,
#endif #endif
{META|CONTROL|'Z', scrnextup}, {META | CONTROL | 'Z', scrnextup}
{META|' ', setmark}, ,
{META|'?', help}, {META | ' ', setmark}
{META|'!', reposition}, ,
{META|'.', setmark}, {META | '?', help}
{META|'>', gotoeob}, ,
{META|'<', gotobob}, {META | '!', reposition}
{META|'~', unmark}, ,
{META | '.', setmark}
,
{META | '>', gotoeob}
,
{META | '<', gotobob}
,
{META | '~', unmark}
,
#if APROP #if APROP
{META|'A', apro}, {META | 'A', apro}
,
#endif #endif
{META|'B', backword}, {META | 'B', backword}
{META|'C', capword}, ,
{META|'D', delfword}, {META | 'C', capword}
,
{META | 'D', delfword}
,
#if CRYPT #if CRYPT
{META|'E', setkey}, {META | 'E', setkey}
,
#endif #endif
{META|'F', forwword}, {META | 'F', forwword}
{META|'G', gotoline}, ,
{META | 'G', gotoline}
,
#if PKCODE #if PKCODE
#if WORDPRO #if WORDPRO
{META|'J', justpara}, {META | 'J', justpara}
,
#endif #endif
#endif #endif
{META|'K', bindtokey}, {META | 'K', bindtokey}
{META|'L', lowerword}, ,
{META|'M', setgmode}, {META | 'L', lowerword}
,
{META | 'M', setgmode}
,
#if WORDPRO #if WORDPRO
{META|'N', gotoeop}, {META | 'N', gotoeop}
{META|'P', gotobop}, ,
{META|'Q', fillpara}, {META | 'P', gotobop}
,
{META | 'Q', fillpara}
,
#endif #endif
{META|'R', sreplace}, {META | 'R', sreplace}
,
#if PKCODE #if PKCODE
{META|'S', forwsearch}, /* alternative P.K. */ {META | 'S', forwsearch}
, /* alternative P.K. */
#else #else
#if BSD #if BSD
{META|'S', bktoshell}, {META | 'S', bktoshell}
,
#endif #endif
#endif #endif
{META|'U', upperword}, {META | 'U', upperword}
{META|'V', backpage}, ,
{META|'W', copyregion}, {META | 'V', backpage}
{META|'X', namedcmd}, ,
{META|'Z', quickexit}, {META | 'W', copyregion}
{META|0x7F, delbword}, ,
{META | 'X', namedcmd}
,
{META | 'Z', quickexit}
,
{META | 0x7F, delbword}
,
#if MSDOS #if MSDOS
{SPEC|CONTROL|'_', forwhunt}, {SPEC | CONTROL | '_', forwhunt}
{SPEC|CONTROL|'S', backhunt}, ,
{SPEC|71, gotobol}, {SPEC | CONTROL | 'S', backhunt}
{SPEC|72, backline}, ,
{SPEC|73, backpage}, {SPEC | 71, gotobol}
{SPEC|75, backchar}, ,
{SPEC|77, forwchar}, {SPEC | 72, backline}
{SPEC|79, gotoeol}, ,
{SPEC|80, forwline}, {SPEC | 73, backpage}
{SPEC|81, forwpage}, ,
{SPEC|82, insspace}, {SPEC | 75, backchar}
{SPEC|83, forwdel}, ,
{SPEC|115, backword}, {SPEC | 77, forwchar}
{SPEC|116, forwword}, ,
{SPEC | 79, gotoeol}
,
{SPEC | 80, forwline}
,
{SPEC | 81, forwpage}
,
{SPEC | 82, insspace}
,
{SPEC | 83, forwdel}
,
{SPEC | 115, backword}
,
{SPEC | 116, forwword}
,
#if WORDPRO #if WORDPRO
{SPEC|132, gotobop}, {SPEC | 132, gotobop}
{SPEC|118, gotoeop}, ,
{SPEC | 118, gotoeop}
,
#endif #endif
{SPEC|84, cbuf1}, {SPEC | 84, cbuf1}
{SPEC|85, cbuf2}, ,
{SPEC|86, cbuf3}, {SPEC | 85, cbuf2}
{SPEC|87, cbuf4}, ,
{SPEC|88, cbuf5}, {SPEC | 86, cbuf3}
{SPEC|89, cbuf6}, ,
{SPEC|90, cbuf7}, {SPEC | 87, cbuf4}
{SPEC|91, cbuf8}, ,
{SPEC|92, cbuf9}, {SPEC | 88, cbuf5}
{SPEC|93, cbuf10}, ,
{SPEC | 89, cbuf6}
,
{SPEC | 90, cbuf7}
,
{SPEC | 91, cbuf8}
,
{SPEC | 92, cbuf9}
,
{SPEC | 93, cbuf10}
,
#if PKCODE #if PKCODE
{SPEC|117, gotoeob}, {SPEC | 117, gotoeob}
{SPEC|119, gotobob}, ,
{SPEC|141, gotobop}, {SPEC | 119, gotobob}
{SPEC|145, gotoeop}, ,
{SPEC|146, yank}, {SPEC | 141, gotobop}
{SPEC|147, killregion}, ,
{SPEC | 145, gotoeop}
,
{SPEC | 146, yank}
,
{SPEC | 147, killregion}
,
#endif #endif
#endif #endif
#if VT220 #if VT220
{SPEC|'1', fisearch}, /* VT220 keys */ {SPEC | '1', fisearch}
{SPEC|'2', yank}, , /* VT220 keys */
{SPEC|'3', killregion}, {SPEC | '2', yank}
{SPEC|'4', setmark}, ,
{SPEC|'5', backpage}, {SPEC | '3', killregion}
{SPEC|'6', forwpage}, ,
{SPEC|'A', backline}, {SPEC | '4', setmark}
{SPEC|'B', forwline}, ,
{SPEC|'C', forwchar}, {SPEC | '5', backpage}
{SPEC|'D', backchar}, ,
{SPEC|'c', meta}, {SPEC | '6', forwpage}
{SPEC|'d', backchar}, ,
{SPEC|'e', forwline}, {SPEC | 'A', backline}
{SPEC|'f', gotobob}, ,
{SPEC|'h', help}, {SPEC | 'B', forwline}
{SPEC|'i', cex}, ,
{SPEC | 'C', forwchar}
,
{SPEC | 'D', backchar}
,
{SPEC | 'c', meta}
,
{SPEC | 'd', backchar}
,
{SPEC | 'e', forwline}
,
{SPEC | 'f', gotobob}
,
{SPEC | 'h', help}
,
{SPEC | 'i', cex}
,
#endif #endif
{0x7F, backdel}, {0x7F, backdel}
,
/* special internal bindings */ /* special internal bindings */
SPEC|META|'W', wrapword, /* called on word wrap */ SPEC | META | 'W', wrapword, /* called on word wrap */
SPEC|META|'C', nullproc, /* every command input */ SPEC | META | 'C', nullproc, /* every command input */
SPEC|META|'R', nullproc, /* on file read */ SPEC | META | 'R', nullproc, /* on file read */
SPEC|META|'X', nullproc, /* on window change P.K. */ SPEC | META | 'X', nullproc, /* on window change P.K. */
{0, NULL} {0, NULL}
}; };

386
edef.h
View File

@ -36,114 +36,116 @@ unsigned int stock();
/* initialized global definitions */ /* initialized global definitions */
int fillcol = 72; /* Current fill column */ int fillcol = 72; /* Current fill column */
short kbdm[NKBDM]; /* Macro */ short kbdm[NKBDM]; /* Macro */
char *execstr = NULL; /* pointer to string to execute */ char *execstr = NULL; /* pointer to string to execute */
char golabel[NPAT] = ""; /* current line to go to */ char golabel[NPAT] = ""; /* current line to go to */
int execlevel = 0; /* execution IF level */ int execlevel = 0; /* execution IF level */
int eolexist = TRUE; /* does clear to EOL exist */ int eolexist = TRUE; /* does clear to EOL exist */
int revexist = FALSE; /* does reverse video exist? */ int revexist = FALSE; /* does reverse video exist? */
int flickcode = FALSE; /* do flicker supression? */ int flickcode = FALSE; /* do flicker supression? */
char *modename[] = { /* name of modes */ char *modename[] = { /* name of modes */
"WRAP", "CMODE", "SPELL", "EXACT", "VIEW", "OVER", "WRAP", "CMODE", "SPELL", "EXACT", "VIEW", "OVER",
"MAGIC", "CRYPT", "ASAVE"}; "MAGIC", "CRYPT", "ASAVE"
char *mode2name[] = { /* name of modes */ };
char *mode2name[] = { /* name of modes */
"Wrap", "Cmode", "Spell", "Exact", "View", "Over", "Wrap", "Cmode", "Spell", "Exact", "View", "Over",
"Magic", "Crypt", "Asave"}; "Magic", "Crypt", "Asave"
char modecode[] = "WCSEVOMYA"; /* letters to represent modes */ };
int gmode = 0; /* global editor mode */ char modecode[] = "WCSEVOMYA"; /* letters to represent modes */
int gflags = GFREAD; /* global control flag */ int gmode = 0; /* global editor mode */
int gflags = GFREAD; /* global control flag */
#if PKCODE & IBMPC #if PKCODE & IBMPC
int gfcolor = 8; /* global forgrnd color (white) */ int gfcolor = 8; /* global forgrnd color (white) */
#else #else
int gfcolor = 7; /* global forgrnd color (white) */ int gfcolor = 7; /* global forgrnd color (white) */
#endif #endif
int gbcolor = 0; /* global backgrnd color (black)*/ int gbcolor = 0; /* global backgrnd color (black) */
int gasave = 256; /* global ASAVE size */ int gasave = 256; /* global ASAVE size */
int gacount = 256; /* count until next ASAVE */ int gacount = 256; /* count until next ASAVE */
int sgarbf = TRUE; /* TRUE if screen is garbage */ int sgarbf = TRUE; /* TRUE if screen is garbage */
int mpresf = FALSE; /* TRUE if message in last line */ int mpresf = FALSE; /* TRUE if message in last line */
int clexec = FALSE; /* command line execution flag */ int clexec = FALSE; /* command line execution flag */
int mstore = FALSE; /* storing text to macro flag */ int mstore = FALSE; /* storing text to macro flag */
int discmd = TRUE; /* display command flag */ int discmd = TRUE; /* display command flag */
int disinp = TRUE; /* display input characters */ int disinp = TRUE; /* display input characters */
struct BUFFER *bstore = NULL; /* buffer to store macro text to*/ struct BUFFER *bstore = NULL; /* buffer to store macro text to */
int vtrow = 0; /* Row location of SW cursor */ int vtrow = 0; /* Row location of SW cursor */
int vtcol = 0; /* Column location of SW cursor */ int vtcol = 0; /* Column location of SW cursor */
int ttrow = HUGE; /* Row location of HW cursor */ int ttrow = HUGE; /* Row location of HW cursor */
int ttcol = HUGE; /* Column location of HW cursor */ int ttcol = HUGE; /* Column location of HW cursor */
int lbound = 0; /* leftmost column of current line int lbound = 0; /* leftmost column of current line
being displayed */ being displayed */
int taboff = 0; /* tab offset for display */ int taboff = 0; /* tab offset for display */
int metac = CONTROL | '['; /* current meta character */ int metac = CONTROL | '['; /* current meta character */
int ctlxc = CONTROL | 'X'; /* current control X prefix char */ int ctlxc = CONTROL | 'X'; /* current control X prefix char */
int reptc = CONTROL | 'U'; /* current universal repeat char */ int reptc = CONTROL | 'U'; /* current universal repeat char */
int abortc = CONTROL | 'G'; /* current abort command char */ int abortc = CONTROL | 'G'; /* current abort command char */
int quotec = 0x11; /* quote char during mlreply() */ int quotec = 0x11; /* quote char during mlreply() */
int tabmask = 0x07; /* tabulator mask */ int tabmask = 0x07; /* tabulator mask */
char *cname[] = { /* names of colors */ char *cname[] = { /* names of colors */
"BLACK", "RED", "GREEN", "YELLOW", "BLUE", "BLACK", "RED", "GREEN", "YELLOW", "BLUE",
"MAGENTA", "CYAN", "WHITE" "MAGENTA", "CYAN", "WHITE"
#if PKCODE & IBMPC #if PKCODE & IBMPC
,"HIGH" , "HIGH"
#endif #endif
}; };
KILL *kbufp = NULL; /* current kill buffer chunk pointer */ KILL *kbufp = NULL; /* current kill buffer chunk pointer */
KILL *kbufh = NULL; /* kill buffer header pointer */ KILL *kbufh = NULL; /* kill buffer header pointer */
int kused = KBLOCK; /* # of bytes used in kill buffer */ int kused = KBLOCK; /* # of bytes used in kill buffer */
WINDOW *swindow = NULL; /* saved window pointer */ WINDOW *swindow = NULL; /* saved window pointer */
int cryptflag = FALSE; /* currently encrypting? */ int cryptflag = FALSE; /* currently encrypting? */
short *kbdptr; /* current position in keyboard buf */ short *kbdptr; /* current position in keyboard buf */
short *kbdend = &kbdm[0]; /* ptr to end of the keyboard */ short *kbdend = &kbdm[0]; /* ptr to end of the keyboard */
int kbdmode = STOP; /* current keyboard macro mode */ int kbdmode = STOP; /* current keyboard macro mode */
int kbdrep = 0; /* number of repetitions */ int kbdrep = 0; /* number of repetitions */
int restflag = FALSE; /* restricted use? */ int restflag = FALSE; /* restricted use? */
int lastkey = 0; /* last keystoke */ int lastkey = 0; /* last keystoke */
int seed = 0; /* random number seed */ int seed = 0; /* random number seed */
long envram = 0l; /* # of bytes current in use by malloc */ long envram = 0l; /* # of bytes current in use by malloc */
int macbug = FALSE; /* macro debuging flag */ int macbug = FALSE; /* macro debuging flag */
char errorm[] = "ERROR"; /* error literal */ char errorm[] = "ERROR"; /* error literal */
char truem[] = "TRUE"; /* true literal */ char truem[] = "TRUE"; /* true literal */
char falsem[] = "FALSE"; /* false litereal */ char falsem[] = "FALSE"; /* false litereal */
int cmdstatus = TRUE; /* last command status */ int cmdstatus = TRUE; /* last command status */
char palstr[49] = ""; /* palette string */ char palstr[49] = ""; /* palette string */
int saveflag = 0; /* Flags, saved with the $target var */ int saveflag = 0; /* Flags, saved with the $target var */
char *fline = NULL; /* dynamic return line */ char *fline = NULL; /* dynamic return line */
int flen = 0; /* current length of fline */ int flen = 0; /* current length of fline */
int rval = 0; /* return value of a subprocess */ int rval = 0; /* return value of a subprocess */
#if CALLED #if CALLED
int eexitflag = FALSE; /* EMACS exit flag */ int eexitflag = FALSE; /* EMACS exit flag */
int eexitval = 0; /* and the exit return value */ int eexitval = 0; /* and the exit return value */
#endif #endif
#if PKCODE #if PKCODE
int nullflag = FALSE; /* accept null characters */ int nullflag = FALSE; /* accept null characters */
int justflag = FALSE; /* justify, don't fill */ int justflag = FALSE; /* justify, don't fill */
#endif #endif
int overlap = 0; /* line overlap in forw/back page */ int overlap = 0; /* line overlap in forw/back page */
int scrollcount = 1; /* number of lines to scroll */ int scrollcount = 1; /* number of lines to scroll */
/* uninitialized global definitions */ /* uninitialized global definitions */
int currow; /* Cursor row */ int currow; /* Cursor row */
int curcol; /* Cursor column */ int curcol; /* Cursor column */
int thisflag; /* Flags, this command */ int thisflag; /* Flags, this command */
int lastflag; /* Flags, last command */ int lastflag; /* Flags, last command */
int curgoal; /* Goal for C-P, C-N */ int curgoal; /* Goal for C-P, C-N */
WINDOW *curwp; /* Current window */ WINDOW *curwp; /* Current window */
BUFFER *curbp; /* Current buffer */ BUFFER *curbp; /* Current buffer */
WINDOW *wheadp; /* Head of list of windows */ WINDOW *wheadp; /* Head of list of windows */
BUFFER *bheadp; /* Head of list of buffers */ BUFFER *bheadp; /* Head of list of buffers */
BUFFER *blistp; /* Buffer for C-X C-B */ BUFFER *blistp; /* Buffer for C-X C-B */
BUFFER *bfind(); /* Lookup a buffer by name */ BUFFER *bfind(); /* Lookup a buffer by name */
WINDOW *wpopup(); /* Pop up window creation */ WINDOW *wpopup(); /* Pop up window creation */
LINE *lalloc(); /* Allocate a line */ LINE *lalloc(); /* Allocate a line */
char sres[NBUFN]; /* current screen resolution */ char sres[NBUFN]; /* current screen resolution */
char pat[NPAT]; /* Search pattern */ char pat[NPAT]; /* Search pattern */
char tap[NPAT]; /* Reversed pattern array. */ char tap[NPAT]; /* Reversed pattern array. */
char rpat[NPAT]; /* replacement pattern */ char rpat[NPAT]; /* replacement pattern */
/* The variable matchlen holds the length of the matched /* The variable matchlen holds the length of the matched
* string - used by the replace functions. * string - used by the replace functions.
@ -152,11 +154,11 @@ char rpat[NPAT]; /* replacement pattern */
* The variables matchline and matchoff hold the line and * The variables matchline and matchoff hold the line and
* offset position of the *start* of match. * offset position of the *start* of match.
*/ */
unsigned int matchlen = 0; unsigned int matchlen = 0;
unsigned int mlenold = 0; unsigned int mlenold = 0;
char *patmatch = NULL; char *patmatch = NULL;
LINE *matchline = NULL; LINE *matchline = NULL;
int matchoff = 0; int matchoff = 0;
#if MAGIC #if MAGIC
/* /*
@ -165,11 +167,11 @@ int matchoff = 0;
* if not, then we don't have to use the slower MAGIC mode * if not, then we don't have to use the slower MAGIC mode
* search functions. * search functions.
*/ */
short int magical = FALSE; short int magical = FALSE;
short int rmagical = FALSE; short int rmagical = FALSE;
MC mcpat[NPAT]; /* the magic pattern */ MC mcpat[NPAT]; /* the magic pattern */
MC tapcm[NPAT]; /* the reversed magic pattern */ MC tapcm[NPAT]; /* the reversed magic pattern */
RMC rmcpat[NPAT]; /* the replacement magic array */ RMC rmcpat[NPAT]; /* the replacement magic array */
#endif #endif
@ -194,102 +196,102 @@ char outline[NSTRING]; /* global string to hold debug line text */
/* initialized global external declarations */ /* initialized global external declarations */
extern int fillcol; /* Fill column */ extern int fillcol; /* Fill column */
extern short kbdm[]; /* Holds kayboard macro data */ extern short kbdm[]; /* Holds kayboard macro data */
extern char pat[]; /* Search pattern */ extern char pat[]; /* Search pattern */
extern char rpat[]; /* Replacement pattern */ extern char rpat[]; /* Replacement pattern */
extern char *execstr; /* pointer to string to execute */ extern char *execstr; /* pointer to string to execute */
extern char golabel[]; /* current line to go to */ extern char golabel[]; /* current line to go to */
extern int execlevel; /* execution IF level */ extern int execlevel; /* execution IF level */
extern int eolexist; /* does clear to EOL exist? */ extern int eolexist; /* does clear to EOL exist? */
extern int revexist; /* does reverse video exist? */ extern int revexist; /* does reverse video exist? */
extern int flickcode; /* do flicker supression? */ extern int flickcode; /* do flicker supression? */
extern char *modename[]; /* text names of modes */ extern char *modename[]; /* text names of modes */
extern char *mode2name[]; /* text names of modes */ extern char *mode2name[]; /* text names of modes */
extern char modecode[]; /* letters to represent modes */ extern char modecode[]; /* letters to represent modes */
extern KEYTAB keytab[]; /* key bind to functions table */ extern KEYTAB keytab[]; /* key bind to functions table */
extern NBIND names[]; /* name to function table */ extern NBIND names[]; /* name to function table */
extern int gmode; /* global editor mode */ extern int gmode; /* global editor mode */
extern int gflags; /* global control flag */ extern int gflags; /* global control flag */
extern int gfcolor; /* global forgrnd color (white) */ extern int gfcolor; /* global forgrnd color (white) */
extern int gbcolor; /* global backgrnd color (black)*/ extern int gbcolor; /* global backgrnd color (black) */
extern int gasave; /* global ASAVE size */ extern int gasave; /* global ASAVE size */
extern int gacount; /* count until next ASAVE */ extern int gacount; /* count until next ASAVE */
extern int sgarbf; /* State of screen unknown */ extern int sgarbf; /* State of screen unknown */
extern int mpresf; /* Stuff in message line */ extern int mpresf; /* Stuff in message line */
extern int clexec; /* command line execution flag */ extern int clexec; /* command line execution flag */
extern int mstore; /* storing text to macro flag */ extern int mstore; /* storing text to macro flag */
extern int discmd; /* display command flag */ extern int discmd; /* display command flag */
extern int disinp; /* display input characters */ extern int disinp; /* display input characters */
extern struct BUFFER *bstore; /* buffer to store macro text to*/ extern struct BUFFER *bstore; /* buffer to store macro text to */
extern int vtrow; /* Row location of SW cursor */ extern int vtrow; /* Row location of SW cursor */
extern int vtcol; /* Column location of SW cursor */ extern int vtcol; /* Column location of SW cursor */
extern int ttrow; /* Row location of HW cursor */ extern int ttrow; /* Row location of HW cursor */
extern int ttcol; /* Column location of HW cursor */ extern int ttcol; /* Column location of HW cursor */
extern int lbound; /* leftmost column of current line extern int lbound; /* leftmost column of current line
being displayed */ being displayed */
extern int taboff; /* tab offset for display */ extern int taboff; /* tab offset for display */
extern int metac; /* current meta character */ extern int metac; /* current meta character */
extern int ctlxc; /* current control X prefix char */ extern int ctlxc; /* current control X prefix char */
extern int reptc; /* current universal repeat char */ extern int reptc; /* current universal repeat char */
extern int abortc; /* current abort command char */ extern int abortc; /* current abort command char */
extern int quotec; /* quote char during mlreply() */ extern int quotec; /* quote char during mlreply() */
extern int tabmask; extern int tabmask;
extern char *cname[]; /* names of colors */ extern char *cname[]; /* names of colors */
extern KILL *kbufp; /* current kill buffer chunk pointer */ extern KILL *kbufp; /* current kill buffer chunk pointer */
extern KILL *kbufh; /* kill buffer header pointer */ extern KILL *kbufh; /* kill buffer header pointer */
extern int kused; /* # of bytes used in KB */ extern int kused; /* # of bytes used in KB */
extern WINDOW *swindow; /* saved window pointer */ extern WINDOW *swindow; /* saved window pointer */
extern int cryptflag; /* currently encrypting? */ extern int cryptflag; /* currently encrypting? */
extern short *kbdptr; /* current position in keyboard buf */ extern short *kbdptr; /* current position in keyboard buf */
extern short *kbdend; /* ptr to end of the keyboard */ extern short *kbdend; /* ptr to end of the keyboard */
extern int kbdmode; /* current keyboard macro mode */ extern int kbdmode; /* current keyboard macro mode */
extern int kbdrep; /* number of repetitions */ extern int kbdrep; /* number of repetitions */
extern int restflag; /* restricted use? */ extern int restflag; /* restricted use? */
extern int lastkey; /* last keystoke */ extern int lastkey; /* last keystoke */
extern int seed; /* random number seed */ extern int seed; /* random number seed */
extern long envram; /* # of bytes current in use by malloc */ extern long envram; /* # of bytes current in use by malloc */
extern int macbug; /* macro debuging flag */ extern int macbug; /* macro debuging flag */
extern char errorm[]; /* error literal */ extern char errorm[]; /* error literal */
extern char truem[]; /* true literal */ extern char truem[]; /* true literal */
extern char falsem[]; /* false litereal */ extern char falsem[]; /* false litereal */
extern int cmdstatus; /* last command status */ extern int cmdstatus; /* last command status */
extern char palstr[]; /* palette string */ extern char palstr[]; /* palette string */
extern int saveflag; /* Flags, saved with the $target var */ extern int saveflag; /* Flags, saved with the $target var */
extern char *fline; /* dynamic return line */ extern char *fline; /* dynamic return line */
extern int flen; /* current length of fline */ extern int flen; /* current length of fline */
extern int rval; /* return value of a subprocess */ extern int rval; /* return value of a subprocess */
#if CALLED #if CALLED
extern int eexitflag; /* EMACS exit flag */ extern int eexitflag; /* EMACS exit flag */
extern int eexitval; /* and the exit return value */ extern int eexitval; /* and the exit return value */
#endif #endif
#if PKCODE #if PKCODE
extern int justflag; /* justify, don't fill */ extern int justflag; /* justify, don't fill */
#endif #endif
extern int overlap; /* line overlap in forw/back page */ extern int overlap; /* line overlap in forw/back page */
extern int scrollcount; /* number of lines to scroll */ extern int scrollcount; /* number of lines to scroll */
/* uninitialized global external declarations */ /* uninitialized global external declarations */
extern int currow; /* Cursor row */ extern int currow; /* Cursor row */
extern int curcol; /* Cursor column */ extern int curcol; /* Cursor column */
extern int thisflag; /* Flags, this command */ extern int thisflag; /* Flags, this command */
extern int lastflag; /* Flags, last command */ extern int lastflag; /* Flags, last command */
extern int curgoal; /* Goal for C-P, C-N */ extern int curgoal; /* Goal for C-P, C-N */
extern WINDOW *curwp; /* Current window */ extern WINDOW *curwp; /* Current window */
extern BUFFER *curbp; /* Current buffer */ extern BUFFER *curbp; /* Current buffer */
extern WINDOW *wheadp; /* Head of list of windows */ extern WINDOW *wheadp; /* Head of list of windows */
extern BUFFER *bheadp; /* Head of list of buffers */ extern BUFFER *bheadp; /* Head of list of buffers */
extern BUFFER *blistp; /* Buffer for C-X C-B */ extern BUFFER *blistp; /* Buffer for C-X C-B */
extern BUFFER *bfind(); /* Lookup a buffer by name */ extern BUFFER *bfind(); /* Lookup a buffer by name */
extern WINDOW *wpopup(); /* Pop up window creation */ extern WINDOW *wpopup(); /* Pop up window creation */
extern LINE *lalloc(); /* Allocate a line */ extern LINE *lalloc(); /* Allocate a line */
extern char sres[NBUFN]; /* current screen resolution */ extern char sres[NBUFN]; /* current screen resolution */
extern char pat[]; /* Search pattern */ extern char pat[]; /* Search pattern */
extern char tap[]; /* Reversed pattern array. */ extern char tap[]; /* Reversed pattern array. */
extern char rpat[]; /* replacement pattern */ extern char rpat[]; /* replacement pattern */
extern unsigned int matchlen; extern unsigned int matchlen;
extern unsigned int mlenold; extern unsigned int mlenold;
@ -300,12 +302,12 @@ extern int matchoff;
#if MAGIC #if MAGIC
extern short int magical; extern short int magical;
extern short int rmagical; extern short int rmagical;
extern MC mcpat[NPAT]; /* the magic pattern */ extern MC mcpat[NPAT]; /* the magic pattern */
extern MC tapcm[NPAT]; /* the reversed magic pattern */ extern MC tapcm[NPAT]; /* the reversed magic pattern */
extern RMC rmcpat[NPAT]; /* the replacement magic array */ extern RMC rmcpat[NPAT]; /* the replacement magic array */
#endif #endif
extern char *dname[]; /* directive name table */ extern char *dname[]; /* directive name table */
#if DEBUGM #if DEBUGM
/* vars needed for macro debugging output */ /* vars needed for macro debugging output */
@ -317,7 +319,5 @@ extern char outline[]; /* global string to hold debug line text */
/* terminal table defined only in TERM.C */ /* terminal table defined only in TERM.C */
#ifndef termdef #ifndef termdef
extern TERM term; /* Terminal information. */ extern TERM term; /* Terminal information. */
#endif #endif

688
efunc.h
View File

@ -12,203 +12,203 @@
/* External function declarations */ /* External function declarations */
extern int ctrlg(); /* Abort out of things */ extern int ctrlg(); /* Abort out of things */
extern int quit(); /* Quit */ extern int quit(); /* Quit */
extern int ctlxlp(); /* Begin macro */ extern int ctlxlp(); /* Begin macro */
extern int ctlxrp(); /* End macro */ extern int ctlxrp(); /* End macro */
extern int ctlxe(); /* Execute macro */ extern int ctlxe(); /* Execute macro */
extern int fileread(); /* Get a file, read only */ extern int fileread(); /* Get a file, read only */
extern int filefind(); /* Get a file, read write */ extern int filefind(); /* Get a file, read write */
extern int filewrite(); /* Write a file */ extern int filewrite(); /* Write a file */
extern int filesave(); /* Save current file */ extern int filesave(); /* Save current file */
extern int filename(); /* Adjust file name */ extern int filename(); /* Adjust file name */
extern int getccol(); /* Get current column */ extern int getccol(); /* Get current column */
extern int gotobol(); /* Move to start of line */ extern int gotobol(); /* Move to start of line */
extern int forwchar(); /* Move forward by characters */ extern int forwchar(); /* Move forward by characters */
extern int gotoeol(); /* Move to end of line */ extern int gotoeol(); /* Move to end of line */
extern int backchar(); /* Move backward by characters */ extern int backchar(); /* Move backward by characters */
extern int forwline(); /* Move forward by lines */ extern int forwline(); /* Move forward by lines */
extern int backline(); /* Move backward by lines */ extern int backline(); /* Move backward by lines */
extern int forwpage(); /* Move forward by pages */ extern int forwpage(); /* Move forward by pages */
extern int backpage(); /* Move backward by pages */ extern int backpage(); /* Move backward by pages */
extern int gotobob(); /* Move to start of buffer */ extern int gotobob(); /* Move to start of buffer */
extern int gotoeob(); /* Move to end of buffer */ extern int gotoeob(); /* Move to end of buffer */
extern int setfillcol(); /* Set fill column. */ extern int setfillcol(); /* Set fill column. */
extern int setmark(); /* Set mark */ extern int setmark(); /* Set mark */
extern int swapmark(); /* Swap "." and mark */ extern int swapmark(); /* Swap "." and mark */
extern int forwsearch(); /* Search forward */ extern int forwsearch(); /* Search forward */
extern int backsearch(); /* Search backwards */ extern int backsearch(); /* Search backwards */
extern int sreplace(); /* search and replace */ extern int sreplace(); /* search and replace */
extern int qreplace(); /* search and replace w/query */ extern int qreplace(); /* search and replace w/query */
extern int showcpos(); /* Show the cursor position */ extern int showcpos(); /* Show the cursor position */
extern int nextwind(); /* Move to the next window */ extern int nextwind(); /* Move to the next window */
extern int prevwind(); /* Move to the previous window */ extern int prevwind(); /* Move to the previous window */
extern int onlywind(); /* Make current window only one */ extern int onlywind(); /* Make current window only one */
extern int splitwind(); /* Split current window */ extern int splitwind(); /* Split current window */
extern int mvdnwind(); /* Move window down */ extern int mvdnwind(); /* Move window down */
extern int mvupwind(); /* Move window up */ extern int mvupwind(); /* Move window up */
extern int enlargewind(); /* Enlarge display window. */ extern int enlargewind(); /* Enlarge display window. */
extern int shrinkwind(); /* Shrink window. */ extern int shrinkwind(); /* Shrink window. */
extern int listbuffers(); /* Display list of buffers */ extern int listbuffers(); /* Display list of buffers */
extern int usebuffer(); /* Switch a window to a buffer */ extern int usebuffer(); /* Switch a window to a buffer */
extern int killbuffer(); /* Make a buffer go away. */ extern int killbuffer(); /* Make a buffer go away. */
extern int reposition(); /* Reposition window */ extern int reposition(); /* Reposition window */
extern int refresh(); /* Refresh the screen */ extern int refresh(); /* Refresh the screen */
extern int twiddle(); /* Twiddle characters */ extern int twiddle(); /* Twiddle characters */
extern int tab(); /* Insert tab */ extern int tab(); /* Insert tab */
extern int newline(); /* Insert CR-LF */ extern int newline(); /* Insert CR-LF */
extern int indent(); /* Insert CR-LF, then indent */ extern int indent(); /* Insert CR-LF, then indent */
extern int openline(); /* Open up a blank line */ extern int openline(); /* Open up a blank line */
extern int deblank(); /* Delete blank lines */ extern int deblank(); /* Delete blank lines */
extern int quote(); /* Insert literal */ extern int quote(); /* Insert literal */
extern int backword(); /* Backup by words */ extern int backword(); /* Backup by words */
extern int forwword(); /* Advance by words */ extern int forwword(); /* Advance by words */
extern int forwdel(); /* Forward delete */ extern int forwdel(); /* Forward delete */
extern int backdel(); /* Backward delete */ extern int backdel(); /* Backward delete */
extern int killtext(); /* Kill forward */ extern int killtext(); /* Kill forward */
extern int yank(); /* Yank back from killbuffer. */ extern int yank(); /* Yank back from killbuffer. */
extern int upperword(); /* Upper case word. */ extern int upperword(); /* Upper case word. */
extern int lowerword(); /* Lower case word. */ extern int lowerword(); /* Lower case word. */
extern int upperregion(); /* Upper case region. */ extern int upperregion(); /* Upper case region. */
extern int lowerregion(); /* Lower case region. */ extern int lowerregion(); /* Lower case region. */
extern int capword(); /* Initial capitalize word. */ extern int capword(); /* Initial capitalize word. */
extern int delfword(); /* Delete forward word. */ extern int delfword(); /* Delete forward word. */
extern int delbword(); /* Delete backward word. */ extern int delbword(); /* Delete backward word. */
extern int killregion(); /* Kill region. */ extern int killregion(); /* Kill region. */
extern int copyregion(); /* Copy region to kill buffer. */ extern int copyregion(); /* Copy region to kill buffer. */
extern int spawncli(); /* Run CLI in a subjob. */ extern int spawncli(); /* Run CLI in a subjob. */
extern int spawn(); /* Run a command in a subjob. */ extern int spawn(); /* Run a command in a subjob. */
#if BSD | __hpux | SVR4 #if BSD | __hpux | SVR4
extern int bktoshell(); /* suspend emacs to parent shell*/ extern int bktoshell(); /* suspend emacs to parent shell */
extern int rtfrmshell(); /* return from a suspended state*/ extern int rtfrmshell(); /* return from a suspended state */
#endif #endif
extern int quickexit(); /* low keystroke style exit. */ extern int quickexit(); /* low keystroke style exit. */
extern int setmode(); /* set an editor mode */ extern int setmode(); /* set an editor mode */
extern int delmode(); /* delete a mode */ extern int delmode(); /* delete a mode */
extern int gotoline(); /* go to a numbered line */ extern int gotoline(); /* go to a numbered line */
extern int namebuffer(); /* rename the current buffer */ extern int namebuffer(); /* rename the current buffer */
#if WORDPRO #if WORDPRO
extern int gotobop(); /* go to beginning/paragraph */ extern int gotobop(); /* go to beginning/paragraph */
extern int gotoeop(); /* go to end/paragraph */ extern int gotoeop(); /* go to end/paragraph */
extern int fillpara(); /* fill current paragraph */ extern int fillpara(); /* fill current paragraph */
#if PKCODE #if PKCODE
extern int justpara(); /* justify current paragraph */ extern int justpara(); /* justify current paragraph */
#endif #endif
#endif #endif
extern int help(); /* get the help file here */ extern int help(); /* get the help file here */
extern int deskey(); /* describe a key's binding */ extern int deskey(); /* describe a key's binding */
extern int viewfile(); /* find a file in view mode */ extern int viewfile(); /* find a file in view mode */
extern int insfile(); /* insert a file */ extern int insfile(); /* insert a file */
extern int scrnextup(); /* scroll next window back */ extern int scrnextup(); /* scroll next window back */
extern int scrnextdw(); /* scroll next window down */ extern int scrnextdw(); /* scroll next window down */
extern int bindtokey(); /* bind a function to a key */ extern int bindtokey(); /* bind a function to a key */
extern int unbindkey(); /* unbind a key's function */ extern int unbindkey(); /* unbind a key's function */
extern int namedcmd(); /* execute named command */ extern int namedcmd(); /* execute named command */
extern int desbind(); /* describe bindings */ extern int desbind(); /* describe bindings */
extern int execcmd(); /* execute a command line */ extern int execcmd(); /* execute a command line */
extern int execbuf(); /* exec commands from a buffer */ extern int execbuf(); /* exec commands from a buffer */
extern int execfile(); /* exec commands from a file */ extern int execfile(); /* exec commands from a file */
extern int nextbuffer(); /* switch to the next buffer */ extern int nextbuffer(); /* switch to the next buffer */
#if WORDPRO #if WORDPRO
extern int killpara(); /* kill the current paragraph */ extern int killpara(); /* kill the current paragraph */
#endif #endif
extern int setgmode(); /* set a global mode */ extern int setgmode(); /* set a global mode */
extern int delgmode(); /* delete a global mode */ extern int delgmode(); /* delete a global mode */
extern int insspace(); /* insert a space forword */ extern int insspace(); /* insert a space forword */
extern int forwhunt(); /* hunt forward for next match */ extern int forwhunt(); /* hunt forward for next match */
extern int backhunt(); /* hunt backwards for next match*/ extern int backhunt(); /* hunt backwards for next match */
extern int pipecmd(); /* pipe command into buffer */ extern int pipecmd(); /* pipe command into buffer */
extern int filter(); /* filter buffer through dos */ extern int filter(); /* filter buffer through dos */
extern int delwind(); /* delete the current window */ extern int delwind(); /* delete the current window */
extern int cbuf1(); /* execute numbered comd buffer */ extern int cbuf1(); /* execute numbered comd buffer */
extern int cbuf2(); extern int cbuf2();
extern int cbuf3(); extern int cbuf3();
extern int cbuf4(); extern int cbuf4();
extern int cbuf5(); extern int cbuf5();
extern int cbuf6(); extern int cbuf6();
extern int cbuf7(); extern int cbuf7();
extern int cbuf8(); extern int cbuf8();
extern int cbuf9(); extern int cbuf9();
extern int cbuf10(); extern int cbuf10();
extern int cbuf11(); extern int cbuf11();
extern int cbuf12(); extern int cbuf12();
extern int cbuf13(); extern int cbuf13();
extern int cbuf14(); extern int cbuf14();
extern int cbuf15(); extern int cbuf15();
extern int cbuf16(); extern int cbuf16();
extern int cbuf17(); extern int cbuf17();
extern int cbuf18(); extern int cbuf18();
extern int cbuf19(); extern int cbuf19();
extern int cbuf20(); extern int cbuf20();
extern int cbuf21(); extern int cbuf21();
extern int cbuf22(); extern int cbuf22();
extern int cbuf23(); extern int cbuf23();
extern int cbuf24(); extern int cbuf24();
extern int cbuf25(); extern int cbuf25();
extern int cbuf26(); extern int cbuf26();
extern int cbuf27(); extern int cbuf27();
extern int cbuf28(); extern int cbuf28();
extern int cbuf29(); extern int cbuf29();
extern int cbuf30(); extern int cbuf30();
extern int cbuf31(); extern int cbuf31();
extern int cbuf32(); extern int cbuf32();
extern int cbuf33(); extern int cbuf33();
extern int cbuf34(); extern int cbuf34();
extern int cbuf35(); extern int cbuf35();
extern int cbuf36(); extern int cbuf36();
extern int cbuf37(); extern int cbuf37();
extern int cbuf38(); extern int cbuf38();
extern int cbuf39(); extern int cbuf39();
extern int cbuf40(); extern int cbuf40();
extern int storemac(); /* store text for macro */ extern int storemac(); /* store text for macro */
extern int resize(); /* resize current window */ extern int resize(); /* resize current window */
extern int clrmes(); /* clear the message line */ extern int clrmes(); /* clear the message line */
extern int meta(); /* meta prefix dummy function */ extern int meta(); /* meta prefix dummy function */
extern int cex(); /* ^X prefix dummy function */ extern int cex(); /* ^X prefix dummy function */
extern int unarg(); /* ^U repeat arg dummy function */ extern int unarg(); /* ^U repeat arg dummy function */
extern int istring(); /* insert string in text */ extern int istring(); /* insert string in text */
extern int unmark(); /* unmark current buffer */ extern int unmark(); /* unmark current buffer */
#if ISRCH #if ISRCH
extern int fisearch(); /* forward incremental search */ extern int fisearch(); /* forward incremental search */
extern int risearch(); /* reverse incremental search */ extern int risearch(); /* reverse incremental search */
#endif #endif
#if WORDPRO #if WORDPRO
extern int wordcount(); /* count words in region */ extern int wordcount(); /* count words in region */
#endif #endif
extern int savewnd(); /* save current window */ extern int savewnd(); /* save current window */
extern int restwnd(); /* restore current window */ extern int restwnd(); /* restore current window */
extern int upscreen(); /* force screen update */ extern int upscreen(); /* force screen update */
extern int writemsg(); /* write text on message line */ extern int writemsg(); /* write text on message line */
#if FNLABEL #if FNLABEL
extern int fnclabel(); /* set function key label */ extern int fnclabel(); /* set function key label */
#endif #endif
#if APROP #if APROP
extern int apro(); /* apropos fuction */ extern int apro(); /* apropos fuction */
#endif #endif
#if CRYPT #if CRYPT
extern int setkey(); /* set encryption key */ extern int setkey(); /* set encryption key */
#endif #endif
extern int wrapword(); /* wordwrap function */ extern int wrapword(); /* wordwrap function */
#if CFENCE #if CFENCE
extern int getfence(); /* move cursor to a matching fence */ extern int getfence(); /* move cursor to a matching fence */
#endif #endif
extern int newsize(); /* change the current screen size */ extern int newsize(); /* change the current screen size */
extern int setvar(); /* set a variables value */ extern int setvar(); /* set a variables value */
extern int newwidth(); /* change the current screen width */ extern int newwidth(); /* change the current screen width */
#if AEDIT #if AEDIT
extern int trim(); /* trim whitespace from end of line */ extern int trim(); /* trim whitespace from end of line */
extern int detab(); /* detab rest of line */ extern int detab(); /* detab rest of line */
extern int entab(); /* entab rest of line */ extern int entab(); /* entab rest of line */
#endif #endif
#if PROC #if PROC
extern int storeproc(); /* store names procedure */ extern int storeproc(); /* store names procedure */
extern int execproc(); /* execute procedure */ extern int execproc(); /* execute procedure */
#endif #endif
extern int nullproc(); /* does nothing... */ extern int nullproc(); /* does nothing... */
extern int ovstring(); /* overwrite a string */ extern int ovstring(); /* overwrite a string */
extern int execprg(); /* execute a program */ extern int execprg(); /* execute a program */
extern int cknewwindow(); extern int cknewwindow();
/* Name to function binding table /* Name to function binding table
@ -217,215 +217,215 @@ extern int cknewwindow();
function. function.
*/ */
NBIND names[] = { NBIND names[] = {
{"abort-command", ctrlg}, {"abort-command", ctrlg},
{"add-mode", setmode}, {"add-mode", setmode},
{"add-global-mode", setgmode}, {"add-global-mode", setgmode},
#if APROP #if APROP
{"apropos", apro}, {"apropos", apro},
#endif #endif
{"backward-character", backchar}, {"backward-character", backchar},
{"begin-macro", ctlxlp}, {"begin-macro", ctlxlp},
{"beginning-of-file", gotobob}, {"beginning-of-file", gotobob},
{"beginning-of-line", gotobol}, {"beginning-of-line", gotobol},
{"bind-to-key", bindtokey}, {"bind-to-key", bindtokey},
{"buffer-position", showcpos}, {"buffer-position", showcpos},
{"case-region-lower", lowerregion}, {"case-region-lower", lowerregion},
{"case-region-upper", upperregion}, {"case-region-upper", upperregion},
{"case-word-capitalize", capword}, {"case-word-capitalize", capword},
{"case-word-lower", lowerword}, {"case-word-lower", lowerword},
{"case-word-upper", upperword}, {"case-word-upper", upperword},
{"change-file-name", filename}, {"change-file-name", filename},
{"change-screen-size", newsize}, {"change-screen-size", newsize},
{"change-screen-width", newwidth}, {"change-screen-width", newwidth},
{"clear-and-redraw", refresh}, {"clear-and-redraw", refresh},
{"clear-message-line", clrmes}, {"clear-message-line", clrmes},
{"copy-region", copyregion}, {"copy-region", copyregion},
#if WORDPRO #if WORDPRO
{"count-words", wordcount}, {"count-words", wordcount},
#endif #endif
{"ctlx-prefix", cex}, {"ctlx-prefix", cex},
{"delete-blank-lines", deblank}, {"delete-blank-lines", deblank},
{"delete-buffer", killbuffer}, {"delete-buffer", killbuffer},
{"delete-mode", delmode}, {"delete-mode", delmode},
{"delete-global-mode", delgmode}, {"delete-global-mode", delgmode},
{"delete-next-character", forwdel}, {"delete-next-character", forwdel},
{"delete-next-word", delfword}, {"delete-next-word", delfword},
{"delete-other-windows", onlywind}, {"delete-other-windows", onlywind},
{"delete-previous-character", backdel}, {"delete-previous-character", backdel},
{"delete-previous-word", delbword}, {"delete-previous-word", delbword},
{"delete-window", delwind}, {"delete-window", delwind},
{"describe-bindings", desbind}, {"describe-bindings", desbind},
{"describe-key", deskey}, {"describe-key", deskey},
#if AEDIT #if AEDIT
{"detab-line", detab}, {"detab-line", detab},
#endif #endif
{"end-macro", ctlxrp}, {"end-macro", ctlxrp},
{"end-of-file", gotoeob}, {"end-of-file", gotoeob},
{"end-of-line", gotoeol}, {"end-of-line", gotoeol},
#if AEDIT #if AEDIT
{"entab-line", entab}, {"entab-line", entab},
#endif #endif
{"exchange-point-and-mark", swapmark}, {"exchange-point-and-mark", swapmark},
{"execute-buffer", execbuf}, {"execute-buffer", execbuf},
{"execute-command-line", execcmd}, {"execute-command-line", execcmd},
{"execute-file", execfile}, {"execute-file", execfile},
{"execute-macro", ctlxe}, {"execute-macro", ctlxe},
{"execute-macro-1", cbuf1}, {"execute-macro-1", cbuf1},
{"execute-macro-2", cbuf2}, {"execute-macro-2", cbuf2},
{"execute-macro-3", cbuf3}, {"execute-macro-3", cbuf3},
{"execute-macro-4", cbuf4}, {"execute-macro-4", cbuf4},
{"execute-macro-5", cbuf5}, {"execute-macro-5", cbuf5},
{"execute-macro-6", cbuf6}, {"execute-macro-6", cbuf6},
{"execute-macro-7", cbuf7}, {"execute-macro-7", cbuf7},
{"execute-macro-8", cbuf8}, {"execute-macro-8", cbuf8},
{"execute-macro-9", cbuf9}, {"execute-macro-9", cbuf9},
{"execute-macro-10", cbuf10}, {"execute-macro-10", cbuf10},
{"execute-macro-11", cbuf11}, {"execute-macro-11", cbuf11},
{"execute-macro-12", cbuf12}, {"execute-macro-12", cbuf12},
{"execute-macro-13", cbuf13}, {"execute-macro-13", cbuf13},
{"execute-macro-14", cbuf14}, {"execute-macro-14", cbuf14},
{"execute-macro-15", cbuf15}, {"execute-macro-15", cbuf15},
{"execute-macro-16", cbuf16}, {"execute-macro-16", cbuf16},
{"execute-macro-17", cbuf17}, {"execute-macro-17", cbuf17},
{"execute-macro-18", cbuf18}, {"execute-macro-18", cbuf18},
{"execute-macro-19", cbuf19}, {"execute-macro-19", cbuf19},
{"execute-macro-20", cbuf20}, {"execute-macro-20", cbuf20},
{"execute-macro-21", cbuf21}, {"execute-macro-21", cbuf21},
{"execute-macro-22", cbuf22}, {"execute-macro-22", cbuf22},
{"execute-macro-23", cbuf23}, {"execute-macro-23", cbuf23},
{"execute-macro-24", cbuf24}, {"execute-macro-24", cbuf24},
{"execute-macro-25", cbuf25}, {"execute-macro-25", cbuf25},
{"execute-macro-26", cbuf26}, {"execute-macro-26", cbuf26},
{"execute-macro-27", cbuf27}, {"execute-macro-27", cbuf27},
{"execute-macro-28", cbuf28}, {"execute-macro-28", cbuf28},
{"execute-macro-29", cbuf29}, {"execute-macro-29", cbuf29},
{"execute-macro-30", cbuf30}, {"execute-macro-30", cbuf30},
{"execute-macro-31", cbuf31}, {"execute-macro-31", cbuf31},
{"execute-macro-32", cbuf32}, {"execute-macro-32", cbuf32},
{"execute-macro-33", cbuf33}, {"execute-macro-33", cbuf33},
{"execute-macro-34", cbuf34}, {"execute-macro-34", cbuf34},
{"execute-macro-35", cbuf35}, {"execute-macro-35", cbuf35},
{"execute-macro-36", cbuf36}, {"execute-macro-36", cbuf36},
{"execute-macro-37", cbuf37}, {"execute-macro-37", cbuf37},
{"execute-macro-38", cbuf38}, {"execute-macro-38", cbuf38},
{"execute-macro-39", cbuf39}, {"execute-macro-39", cbuf39},
{"execute-macro-40", cbuf40}, {"execute-macro-40", cbuf40},
{"execute-named-command", namedcmd}, {"execute-named-command", namedcmd},
#if PROC #if PROC
{"execute-procedure", execproc}, {"execute-procedure", execproc},
#endif #endif
{"execute-program", execprg}, {"execute-program", execprg},
{"exit-emacs", quit}, {"exit-emacs", quit},
#if WORDPRO #if WORDPRO
{"fill-paragraph", fillpara}, {"fill-paragraph", fillpara},
#endif #endif
{"filter-buffer", filter}, {"filter-buffer", filter},
{"find-file", filefind}, {"find-file", filefind},
{"forward-character", forwchar}, {"forward-character", forwchar},
{"goto-line", gotoline}, {"goto-line", gotoline},
#if CFENCE #if CFENCE
{"goto-matching-fence", getfence}, {"goto-matching-fence", getfence},
#endif #endif
{"grow-window", enlargewind}, {"grow-window", enlargewind},
{"handle-tab", tab}, {"handle-tab", tab},
{"hunt-forward", forwhunt}, {"hunt-forward", forwhunt},
{"hunt-backward", backhunt}, {"hunt-backward", backhunt},
{"help", help}, {"help", help},
{"i-shell", spawncli}, {"i-shell", spawncli},
#if ISRCH #if ISRCH
{"incremental-search", fisearch}, {"incremental-search", fisearch},
#endif #endif
{"insert-file", insfile}, {"insert-file", insfile},
{"insert-space", insspace}, {"insert-space", insspace},
{"insert-string", istring}, {"insert-string", istring},
#if WORDPRO #if WORDPRO
#if PKCODE #if PKCODE
{"justify-paragraph", justpara}, {"justify-paragraph", justpara},
#endif #endif
{"kill-paragraph", killpara}, {"kill-paragraph", killpara},
#endif #endif
{"kill-region", killregion}, {"kill-region", killregion},
{"kill-to-end-of-line", killtext}, {"kill-to-end-of-line", killtext},
#if FNLABEL #if FNLABEL
{"label-function-key", fnclabel}, {"label-function-key", fnclabel},
#endif #endif
{"list-buffers", listbuffers}, {"list-buffers", listbuffers},
{"meta-prefix", meta}, {"meta-prefix", meta},
{"move-window-down", mvdnwind}, {"move-window-down", mvdnwind},
{"move-window-up", mvupwind}, {"move-window-up", mvupwind},
{"name-buffer", namebuffer}, {"name-buffer", namebuffer},
{"newline", newline}, {"newline", newline},
{"newline-and-indent", indent}, {"newline-and-indent", indent},
{"next-buffer", nextbuffer}, {"next-buffer", nextbuffer},
{"next-line", forwline}, {"next-line", forwline},
{"next-page", forwpage}, {"next-page", forwpage},
#if WORDPRO #if WORDPRO
{"next-paragraph", gotoeop}, {"next-paragraph", gotoeop},
#endif #endif
{"next-window", nextwind}, {"next-window", nextwind},
{"next-word", forwword}, {"next-word", forwword},
{"nop", nullproc}, {"nop", nullproc},
{"open-line", openline}, {"open-line", openline},
{"overwrite-string", ovstring}, {"overwrite-string", ovstring},
{"pipe-command", pipecmd}, {"pipe-command", pipecmd},
{"previous-line", backline}, {"previous-line", backline},
{"previous-page", backpage}, {"previous-page", backpage},
#if WORDPRO #if WORDPRO
{"previous-paragraph", gotobop}, {"previous-paragraph", gotobop},
#endif #endif
{"previous-window", prevwind}, {"previous-window", prevwind},
{"previous-word", backword}, {"previous-word", backword},
{"query-replace-string", qreplace}, {"query-replace-string", qreplace},
{"quick-exit", quickexit}, {"quick-exit", quickexit},
{"quote-character", quote}, {"quote-character", quote},
{"read-file", fileread}, {"read-file", fileread},
{"redraw-display", reposition}, {"redraw-display", reposition},
{"resize-window", resize}, {"resize-window", resize},
{"restore-window", restwnd}, {"restore-window", restwnd},
{"replace-string", sreplace}, {"replace-string", sreplace},
#if ISRCH #if ISRCH
{"reverse-incremental-search", risearch}, {"reverse-incremental-search", risearch},
#endif #endif
#if PROC #if PROC
{"run", execproc}, {"run", execproc},
#endif #endif
{"save-file", filesave}, {"save-file", filesave},
{"save-window", savewnd}, {"save-window", savewnd},
{"scroll-next-up", scrnextup}, {"scroll-next-up", scrnextup},
{"scroll-next-down", scrnextdw}, {"scroll-next-down", scrnextdw},
{"search-forward", forwsearch}, {"search-forward", forwsearch},
{"search-reverse", backsearch}, {"search-reverse", backsearch},
{"select-buffer", usebuffer}, {"select-buffer", usebuffer},
{"set", setvar}, {"set", setvar},
#if CRYPT #if CRYPT
{"set-encryption-key", setkey}, {"set-encryption-key", setkey},
#endif #endif
{"set-fill-column", setfillcol}, {"set-fill-column", setfillcol},
{"set-mark", setmark}, {"set-mark", setmark},
{"shell-command", spawn}, {"shell-command", spawn},
{"shrink-window", shrinkwind}, {"shrink-window", shrinkwind},
{"split-current-window", splitwind}, {"split-current-window", splitwind},
{"store-macro", storemac}, {"store-macro", storemac},
#if PROC #if PROC
{"store-procedure", storeproc}, {"store-procedure", storeproc},
#endif #endif
#if BSD | __hpux | SVR4 #if BSD | __hpux | SVR4
{"suspend-emacs", bktoshell}, {"suspend-emacs", bktoshell},
#endif #endif
{"transpose-characters", twiddle}, {"transpose-characters", twiddle},
#if AEDIT #if AEDIT
{"trim-line", trim}, {"trim-line", trim},
#endif #endif
{"unbind-key", unbindkey}, {"unbind-key", unbindkey},
{"universal-argument", unarg}, {"universal-argument", unarg},
{"unmark-buffer", unmark}, {"unmark-buffer", unmark},
{"update-screen", upscreen}, {"update-screen", upscreen},
{"view-file", viewfile}, {"view-file", viewfile},
{"wrap-word", wrapword}, {"wrap-word", wrapword},
{"write-file", filewrite}, {"write-file", filewrite},
{"write-message", writemsg}, {"write-message", writemsg},
{"yank", yank}, {"yank", yank},
{"", NULL} {"", NULL}
}; };

23
epath.h
View File

@ -9,7 +9,6 @@
/* possible names and paths of help files under different OSs */ /* possible names and paths of help files under different OSs */
char *pathname[] = char *pathname[] =
#if MSDOS #if MSDOS
{ {
"emacs.rc", "emacs.rc",
@ -24,30 +23,20 @@ char *pathname[] =
#if V7 | BSD | USG #if V7 | BSD | USG
{ {
".emacsrc", ".emacsrc", "emacs.hlp",
"emacs.hlp",
#if PKCODE #if PKCODE
"/usr/global/lib/", "/usr/global/lib/", "/usr/local/bin/", "/usr/local/lib/",
"/usr/local/bin/",
"/usr/local/lib/",
#endif #endif
"/usr/local/", "/usr/local/", "/usr/lib/", ""};
"/usr/lib/",
""
};
#endif #endif
#if VMS #if VMS
{ {
"emacs.rc", "emacs.rc", "emacs.hlp", "",
"emacs.hlp",
"",
#if PKCODE #if PKCODE
"sys$login:", "sys$login:", "emacs_dir:",
"emacs_dir:",
#endif #endif
"sys$sysdevice:[vmstools]" "sys$sysdevice:[vmstools]"};
};
#endif #endif
#define NPNAMES (sizeof(pathname)/sizeof(char *)) #define NPNAMES (sizeof(pathname)/sizeof(char *))

455
estruct.h
View File

@ -41,14 +41,14 @@
/* make an intelligent guess about the target system */ /* make an intelligent guess about the target system */
#if defined(__TURBOC__) #if defined(__TURBOC__)
#define MSDOS 1 /* MS/PC DOS 3.1-4.0 with Turbo C 2.0 */ #define MSDOS 1 /* MS/PC DOS 3.1-4.0 with Turbo C 2.0 */
#else #else
#define MSDOS 0 #define MSDOS 0
#endif #endif
#if defined(BSD) || defined(sun) || defined(ultrix) || (defined(vax) && defined(unix)) || defined(ultrix) || defined(__osf__) #if defined(BSD) || defined(sun) || defined(ultrix) || (defined(vax) && defined(unix)) || defined(ultrix) || defined(__osf__)
#ifndef BSD #ifndef BSD
#define BSD 1 /* Berkeley UNIX */ #define BSD 1 /* Berkeley UNIX */
#endif #endif
#else #else
#define BSD 0 #define BSD 0
@ -61,35 +61,35 @@
#endif #endif
#if defined(SYSV) || defined(u3b2) || defined(_AIX) || (defined(i386) && defined(unix)) || defined(__hpux) #if defined(SYSV) || defined(u3b2) || defined(_AIX) || (defined(i386) && defined(unix)) || defined(__hpux)
#define USG 1 /* System V UNIX */ #define USG 1 /* System V UNIX */
#else #else
#define USG 0 #define USG 0
#endif #endif
#if defined(VMS) || (defined(vax) && ! defined(unix)) #if defined(VMS) || (defined(vax) && ! defined(unix))
#define VMS 1 /* VAX/VMS */ #define VMS 1 /* VAX/VMS */
#else #else
#define VMS 0 #define VMS 0
#endif #endif
#define V7 0 /* no more */ #define V7 0 /* no more */
#else #else
#define MSDOS 1 /* MS-DOS */ #define MSDOS 1 /* MS-DOS */
#define V7 0 /* V7 UNIX or Coherent or BSD4.2*/ #define V7 0 /* V7 UNIX or Coherent or BSD4.2 */
#define BSD 0 /* UNIX BSD 4.2 and ULTRIX */ #define BSD 0 /* UNIX BSD 4.2 and ULTRIX */
#define USG 0 /* UNIX system V */ #define USG 0 /* UNIX system V */
#define VMS 0 /* VAX/VMS */ #define VMS 0 /* VAX/VMS */
#endif /*autoconf */ #endif /*autoconf */
#ifndef AUTOCONF #ifndef AUTOCONF
/* Compiler definitions */ /* Compiler definitions */
#define UNIX 0 /* a random UNIX compiler */ #define UNIX 0 /* a random UNIX compiler */
#define MSC 0 /* MicroSoft C compiler, versions 3 up */ #define MSC 0 /* MicroSoft C compiler, versions 3 up */
#define TURBO 1 /* Turbo C/MSDOS */ #define TURBO 1 /* Turbo C/MSDOS */
#else #else
@ -97,27 +97,27 @@
#define MSC 0 #define MSC 0
#define TURBO MSDOS #define TURBO MSDOS
#endif /*autoconf */ #endif /*autoconf */
/* Debugging options */ /* Debugging options */
#define RAMSIZE 0 /* dynamic RAM memory usage tracking */ #define RAMSIZE 0 /* dynamic RAM memory usage tracking */
#define RAMSHOW 0 /* auto dynamic RAM reporting */ #define RAMSHOW 0 /* auto dynamic RAM reporting */
#ifndef AUTOCONF #ifndef AUTOCONF
/* Special keyboard definitions */ /* Special keyboard definitions */
#define VT220 0 /* Use keypad escapes P.K. */ #define VT220 0 /* Use keypad escapes P.K. */
#define VT100 0 /* Handle VT100 style keypad. */ #define VT100 0 /* Handle VT100 style keypad. */
/* Terminal Output definitions */ /* Terminal Output definitions */
#define ANSI 0 /* ANSI escape sequences */ #define ANSI 0 /* ANSI escape sequences */
#define VMSVT 0 /* various VMS terminal entries */ #define VMSVT 0 /* various VMS terminal entries */
#define VT52 0 /* VT52 terminal (Zenith). */ #define VT52 0 /* VT52 terminal (Zenith). */
#define TERMCAP 0 /* Use TERMCAP */ #define TERMCAP 0 /* Use TERMCAP */
#define IBMPC 1 /* IBM-PC CGA/MONO/EGA driver */ #define IBMPC 1 /* IBM-PC CGA/MONO/EGA driver */
#else #else
@ -130,25 +130,25 @@
#define TERMCAP UNIX #define TERMCAP UNIX
#define IBMPC MSDOS #define IBMPC MSDOS
#endif /*autoconf */ #endif /*autoconf */
/* Configuration options */ /* Configuration options */
#define CVMVAS 1 /* arguments to page forward/back in pages */ #define CVMVAS 1 /* arguments to page forward/back in pages */
#define CLRMSG 0 /* space clears the message line with no insert */ #define CLRMSG 0 /* space clears the message line with no insert */
#define CFENCE 1 /* fench matching in CMODE */ #define CFENCE 1 /* fench matching in CMODE */
#define TYPEAH 1 /* type ahead causes update to be skipped */ #define TYPEAH 1 /* type ahead causes update to be skipped */
#define DEBUGM 1 /* $debug triggers macro debugging */ #define DEBUGM 1 /* $debug triggers macro debugging */
#define VISMAC 0 /* update display during keyboard macros */ #define VISMAC 0 /* update display during keyboard macros */
#define CTRLZ 0 /* add a ^Z at end of files under MSDOS only */ #define CTRLZ 0 /* add a ^Z at end of files under MSDOS only */
#define ADDCR 0 /* ajout d'un CR en fin de chaque ligne (ST520) */ #define ADDCR 0 /* ajout d'un CR en fin de chaque ligne (ST520) */
#define NBRACE 1 /* new style brace matching command */ #define NBRACE 1 /* new style brace matching command */
#define REVSTA 1 /* Status line appears in reverse video */ #define REVSTA 1 /* Status line appears in reverse video */
#ifndef AUTOCONF #ifndef AUTOCONF
#define COLOR 1 /* color commands and windows */ #define COLOR 1 /* color commands and windows */
#define FILOCK 0 /* file locking under unix BSD 4.2 */ #define FILOCK 0 /* file locking under unix BSD 4.2 */
#else #else
@ -159,37 +159,37 @@
#define FILOCK BSD #define FILOCK BSD
#endif #endif
#endif /* autoconf */ #endif /* autoconf */
#define ISRCH 1 /* Incremental searches like ITS EMACS */ #define ISRCH 1 /* Incremental searches like ITS EMACS */
#define WORDPRO 1 /* Advanced word processing features */ #define WORDPRO 1 /* Advanced word processing features */
#define FNLABEL 0 /* function key label code [HP150] */ #define FNLABEL 0 /* function key label code [HP150] */
#define APROP 1 /* Add code for Apropos command */ #define APROP 1 /* Add code for Apropos command */
#define CRYPT 1 /* file encryption enabled? */ #define CRYPT 1 /* file encryption enabled? */
#define MAGIC 1 /* include regular expression matching? */ #define MAGIC 1 /* include regular expression matching? */
#define AEDIT 1 /* advanced editing options: en/detabbing */ #define AEDIT 1 /* advanced editing options: en/detabbing */
#define PROC 1 /* named procedures */ #define PROC 1 /* named procedures */
#define CLEAN 0 /* de-alloc memory on exit */ #define CLEAN 0 /* de-alloc memory on exit */
#define CALLED 0 /* is emacs a called subroutine? or stand alone */ #define CALLED 0 /* is emacs a called subroutine? or stand alone */
#define ASCII 1 /* always using ASCII char sequences for now */ #define ASCII 1 /* always using ASCII char sequences for now */
#define EBCDIC 0 /* later IBM mainfraim versions will use EBCDIC */ #define EBCDIC 0 /* later IBM mainfraim versions will use EBCDIC */
#ifndef AUTOCONF #ifndef AUTOCONF
#define XONXOFF 0 /* don't disable XON-XOFF flow control P.K. */ #define XONXOFF 0 /* don't disable XON-XOFF flow control P.K. */
#define NATIONL 0 /* interprete [,],\,{,},| as characters P.K. */ #define NATIONL 0 /* interprete [,],\,{,},| as characters P.K. */
#else #else
#define XONXOFF (UNIX | VMS) #define XONXOFF (UNIX | VMS)
#define NATIONL (UNIX | VMS) #define NATIONL (UNIX | VMS)
#endif /* autoconf */ #endif /* autoconf */
#define PKCODE 1 /* include my extensions P.K., define always */ #define PKCODE 1 /* include my extensions P.K., define always */
#define IBMCHR MSDOS /* use IBM PC character set P.K. */ #define IBMCHR MSDOS /* use IBM PC character set P.K. */
#define SCROLLCODE 1 /* scrolling code P.K. */ #define SCROLLCODE 1 /* scrolling code P.K. */
/* System dependant library redefinitions, structures and includes */ /* System dependant library redefinitions, structures and includes */
@ -240,24 +240,24 @@
/* internal constants */ /* internal constants */
#define NBINDS 256 /* max # of bound keys */ #define NBINDS 256 /* max # of bound keys */
#define NFILEN 80 /* # of bytes, file name */ #define NFILEN 80 /* # of bytes, file name */
#define NBUFN 16 /* # of bytes, buffer name */ #define NBUFN 16 /* # of bytes, buffer name */
#define NLINE 256 /* # of bytes, input line */ #define NLINE 256 /* # of bytes, input line */
#define NSTRING 128 /* # of bytes, string buffers */ #define NSTRING 128 /* # of bytes, string buffers */
#define NKBDM 256 /* # of strokes, keyboard macro */ #define NKBDM 256 /* # of strokes, keyboard macro */
#define NPAT 128 /* # of bytes, pattern */ #define NPAT 128 /* # of bytes, pattern */
#define HUGE 1000 /* Huge number */ #define HUGE 1000 /* Huge number */
#define NLOCKS 100 /* max # of file locks active */ #define NLOCKS 100 /* max # of file locks active */
#define NCOLORS 8 /* number of supported colors */ #define NCOLORS 8 /* number of supported colors */
#define KBLOCK 250 /* sizeof kill buffer chunks */ #define KBLOCK 250 /* sizeof kill buffer chunks */
#define NBLOCK 16 /* line block chunk size */ #define NBLOCK 16 /* line block chunk size */
#define NVSIZE 10 /* max #chars in a var name */ #define NVSIZE 10 /* max #chars in a var name */
#define CONTROL 0x0100 /* Control flag, or'ed in */ #define CONTROL 0x0100 /* Control flag, or'ed in */
#define META 0x0200 /* Meta flag, or'ed in */ #define META 0x0200 /* Meta flag, or'ed in */
#define CTLX 0x0400 /* ^X flag, or'ed in */ #define CTLX 0x0400 /* ^X flag, or'ed in */
#define SPEC 0x0800 /* special key (function keys) */ #define SPEC 0x0800 /* special key (function keys) */
#if PKCODE #if PKCODE
#define MAXNLINE 10000000 /* max lines from one file */ #define MAXNLINE 10000000 /* max lines from one file */
@ -270,14 +270,14 @@
#undef TRUE #undef TRUE
#endif #endif
#define FALSE 0 /* False, no, bad, etc. */ #define FALSE 0 /* False, no, bad, etc. */
#define TRUE 1 /* True, yes, good, etc. */ #define TRUE 1 /* True, yes, good, etc. */
#define ABORT 2 /* Death, ^G, abort, etc. */ #define ABORT 2 /* Death, ^G, abort, etc. */
#define FAILED 3 /* not-quite fatal false return */ #define FAILED 3 /* not-quite fatal false return */
#define STOP 0 /* keyboard macro not in use */ #define STOP 0 /* keyboard macro not in use */
#define PLAY 1 /* playing */ #define PLAY 1 /* playing */
#define RECORD 2 /* recording */ #define RECORD 2 /* recording */
/* Directive definitions */ /* Directive definitions */
@ -298,23 +298,23 @@
* PTBEG, PTEND, FORWARD, and REVERSE are all toggle-able values for * PTBEG, PTEND, FORWARD, and REVERSE are all toggle-able values for
* the scan routines. * the scan routines.
*/ */
#define PTBEG 0 /* Leave the point at the beginning on search */ #define PTBEG 0 /* Leave the point at the beginning on search */
#define PTEND 1 /* Leave the point at the end on search */ #define PTEND 1 /* Leave the point at the end on search */
#define FORWARD 0 /* forward direction */ #define FORWARD 0 /* forward direction */
#define REVERSE 1 /* backwards direction */ #define REVERSE 1 /* backwards direction */
#define FIOSUC 0 /* File I/O, success. */ #define FIOSUC 0 /* File I/O, success. */
#define FIOFNF 1 /* File I/O, file not found. */ #define FIOFNF 1 /* File I/O, file not found. */
#define FIOEOF 2 /* File I/O, end of file. */ #define FIOEOF 2 /* File I/O, end of file. */
#define FIOERR 3 /* File I/O, error. */ #define FIOERR 3 /* File I/O, error. */
#define FIOMEM 4 /* File I/O, out of memory */ #define FIOMEM 4 /* File I/O, out of memory */
#define FIOFUN 5 /* File I/O, eod of file/bad line*/ #define FIOFUN 5 /* File I/O, eod of file/bad line */
#define CFCPCN 0x0001 /* Last command was C-P, C-N */ #define CFCPCN 0x0001 /* Last command was C-P, C-N */
#define CFKILL 0x0002 /* Last command was a kill */ #define CFKILL 0x0002 /* Last command was a kill */
#define BELL 0x07 /* a bell character */ #define BELL 0x07 /* a bell character */
#define TAB 0x09 /* a tab character */ #define TAB 0x09 /* a tab character */
#if V7 | USG | BSD #if V7 | USG | BSD
#define PATHCHR ':' #define PATHCHR ':'
@ -326,17 +326,17 @@
/* Macro argument token types */ /* Macro argument token types */
#define TKNUL 0 /* end-of-string */ #define TKNUL 0 /* end-of-string */
#define TKARG 1 /* interactive argument */ #define TKARG 1 /* interactive argument */
#define TKBUF 2 /* buffer argument */ #define TKBUF 2 /* buffer argument */
#define TKVAR 3 /* user variables */ #define TKVAR 3 /* user variables */
#define TKENV 4 /* environment variables */ #define TKENV 4 /* environment variables */
#define TKFUN 5 /* function.... */ #define TKFUN 5 /* function.... */
#define TKDIR 6 /* directive */ #define TKDIR 6 /* directive */
#define TKLBL 7 /* line label */ #define TKLBL 7 /* line label */
#define TKLIT 8 /* numeric literal */ #define TKLIT 8 /* numeric literal */
#define TKSTR 9 /* quoted string literal */ #define TKSTR 9 /* quoted string literal */
#define TKCMD 10 /* command name */ #define TKCMD 10 /* command name */
/* Internal defined functions */ /* Internal defined functions */
@ -428,34 +428,34 @@
* the full blown redisplay is just too expensive to run for every input * the full blown redisplay is just too expensive to run for every input
* character. * character.
*/ */
typedef struct WINDOW { typedef struct WINDOW {
struct WINDOW *w_wndp; /* Next window */ struct WINDOW *w_wndp; /* Next window */
struct BUFFER *w_bufp; /* Buffer displayed in window */ struct BUFFER *w_bufp; /* Buffer displayed in window */
struct LINE *w_linep; /* Top line in the window */ struct LINE *w_linep; /* Top line in the window */
struct LINE *w_dotp; /* Line containing "." */ struct LINE *w_dotp; /* Line containing "." */
short w_doto; /* Byte offset for "." */ short w_doto; /* Byte offset for "." */
struct LINE *w_markp; /* Line containing "mark" */ struct LINE *w_markp; /* Line containing "mark" */
short w_marko; /* Byte offset for "mark" */ short w_marko; /* Byte offset for "mark" */
char w_toprow; /* Origin 0 top row of window */ char w_toprow; /* Origin 0 top row of window */
char w_ntrows; /* # of rows of text in window */ char w_ntrows; /* # of rows of text in window */
char w_force; /* If NZ, forcing row. */ char w_force; /* If NZ, forcing row. */
char w_flag; /* Flags. */ char w_flag; /* Flags. */
#if COLOR #if COLOR
char w_fcolor; /* current forground color */ char w_fcolor; /* current forground color */
char w_bcolor; /* current background color */ char w_bcolor; /* current background color */
#endif #endif
} WINDOW; } WINDOW;
#define WFFORCE 0x01 /* Window needs forced reframe */ #define WFFORCE 0x01 /* Window needs forced reframe */
#define WFMOVE 0x02 /* Movement from line to line */ #define WFMOVE 0x02 /* Movement from line to line */
#define WFEDIT 0x04 /* Editing within a line */ #define WFEDIT 0x04 /* Editing within a line */
#define WFHARD 0x08 /* Better to a full display */ #define WFHARD 0x08 /* Better to a full display */
#define WFMODE 0x10 /* Update mode line. */ #define WFMODE 0x10 /* Update mode line. */
#define WFCOLR 0x20 /* Needs a color change */ #define WFCOLR 0x20 /* Needs a color change */
#if SCROLLCODE #if SCROLLCODE
#define WFKILLS 0x40 /* something was deleted */ #define WFKILLS 0x40 /* something was deleted */
#define WFINS 0x80 /* something was inserted */ #define WFINS 0x80 /* something was inserted */
#endif #endif
@ -470,50 +470,50 @@ typedef struct WINDOW {
* Buffers may be "Inactive" which means the files associated with them * Buffers may be "Inactive" which means the files associated with them
* have not been read in yet. These get read in at "use buffer" time. * have not been read in yet. These get read in at "use buffer" time.
*/ */
typedef struct BUFFER { typedef struct BUFFER {
struct BUFFER *b_bufp; /* Link to next BUFFER */ struct BUFFER *b_bufp; /* Link to next BUFFER */
struct LINE *b_dotp; /* Link to "." LINE structure */ struct LINE *b_dotp; /* Link to "." LINE structure */
short b_doto; /* Offset of "." in above LINE */ short b_doto; /* Offset of "." in above LINE */
struct LINE *b_markp; /* The same as the above two, */ struct LINE *b_markp; /* The same as the above two, */
short b_marko; /* but for the "mark" */ short b_marko; /* but for the "mark" */
struct LINE *b_linep; /* Link to the header LINE */ struct LINE *b_linep; /* Link to the header LINE */
char b_active; /* window activated flag */ char b_active; /* window activated flag */
char b_nwnd; /* Count of windows on buffer */ char b_nwnd; /* Count of windows on buffer */
char b_flag; /* Flags */ char b_flag; /* Flags */
int b_mode; /* editor mode of this buffer */ int b_mode; /* editor mode of this buffer */
char b_fname[NFILEN]; /* File name */ char b_fname[NFILEN]; /* File name */
char b_bname[NBUFN]; /* Buffer name */ char b_bname[NBUFN]; /* Buffer name */
#if CRYPT #if CRYPT
char b_key[NPAT]; /* current encrypted key */ char b_key[NPAT]; /* current encrypted key */
#endif #endif
} BUFFER; } BUFFER;
#define BFINVS 0x01 /* Internal invisable buffer */ #define BFINVS 0x01 /* Internal invisable buffer */
#define BFCHG 0x02 /* Changed since last write */ #define BFCHG 0x02 /* Changed since last write */
#define BFTRUNC 0x04 /* buffer was truncated when read */ #define BFTRUNC 0x04 /* buffer was truncated when read */
/* mode flags */ /* mode flags */
#define NUMMODES 9 /* # of defined modes */ #define NUMMODES 9 /* # of defined modes */
#define MDWRAP 0x0001 /* word wrap */ #define MDWRAP 0x0001 /* word wrap */
#define MDCMOD 0x0002 /* C indentation and fence match*/ #define MDCMOD 0x0002 /* C indentation and fence match */
#define MDSPELL 0x0004 /* spell error parcing */ #define MDSPELL 0x0004 /* spell error parcing */
#define MDEXACT 0x0008 /* Exact matching for searches */ #define MDEXACT 0x0008 /* Exact matching for searches */
#define MDVIEW 0x0010 /* read-only buffer */ #define MDVIEW 0x0010 /* read-only buffer */
#define MDOVER 0x0020 /* overwrite mode */ #define MDOVER 0x0020 /* overwrite mode */
#define MDMAGIC 0x0040 /* regular expresions in search */ #define MDMAGIC 0x0040 /* regular expresions in search */
#define MDCRYPT 0x0080 /* encrytion mode active */ #define MDCRYPT 0x0080 /* encrytion mode active */
#define MDASAVE 0x0100 /* auto-save mode */ #define MDASAVE 0x0100 /* auto-save mode */
/* /*
* The starting position of a region, and the size of the region in * The starting position of a region, and the size of the region in
* characters, is kept in a region structure. Used by the region commands. * characters, is kept in a region structure. Used by the region commands.
*/ */
typedef struct { typedef struct {
struct LINE *r_linep; /* Origin LINE address. */ struct LINE *r_linep; /* Origin LINE address. */
short r_offset; /* Origin LINE offset. */ short r_offset; /* Origin LINE offset. */
long r_size; /* Length in characters. */ long r_size; /* Length in characters. */
} REGION; } REGION;
/* /*
* All text is kept in circularly linked lists of "LINE" structures. These * All text is kept in circularly linked lists of "LINE" structures. These
@ -523,13 +523,13 @@ typedef struct {
* and the text. The end of line is not stored as a byte; it's implied. Future * and the text. The end of line is not stored as a byte; it's implied. Future
* additions will include update hints, and a list of marks into the line. * additions will include update hints, and a list of marks into the line.
*/ */
typedef struct LINE { typedef struct LINE {
struct LINE *l_fp; /* Link to the next line */ struct LINE *l_fp; /* Link to the next line */
struct LINE *l_bp; /* Link to the previous line */ struct LINE *l_bp; /* Link to the previous line */
short l_size; /* Allocated size */ short l_size; /* Allocated size */
short l_used; /* Used size */ short l_used; /* Used size */
char l_text[1]; /* A bunch of characters. */ char l_text[1]; /* A bunch of characters. */
} LINE; } LINE;
#define lforw(lp) ((lp)->l_fp) #define lforw(lp) ((lp)->l_fp)
#define lback(lp) ((lp)->l_bp) #define lback(lp) ((lp)->l_bp)
@ -546,35 +546,35 @@ typedef struct LINE {
* "termp->t_field" style in the future, to make it possible to run more than * "termp->t_field" style in the future, to make it possible to run more than
* one terminal type. * one terminal type.
*/ */
typedef struct { typedef struct {
short t_mrow; /* max number of rows allowable */ short t_mrow; /* max number of rows allowable */
short t_nrow; /* current number of rows used */ short t_nrow; /* current number of rows used */
short t_mcol; /* max Number of columns. */ short t_mcol; /* max Number of columns. */
short t_ncol; /* current Number of columns. */ short t_ncol; /* current Number of columns. */
short t_margin; /* min margin for extended lines*/ short t_margin; /* min margin for extended lines */
short t_scrsiz; /* size of scroll region " */ short t_scrsiz; /* size of scroll region " */
int t_pause; /* # times thru update to pause */ int t_pause; /* # times thru update to pause */
int (*t_open)(); /* Open terminal at the start. */ int (*t_open) (); /* Open terminal at the start. */
int (*t_close)(); /* Close terminal at end. */ int (*t_close) (); /* Close terminal at end. */
int (*t_kopen)(); /* Open keyboard */ int (*t_kopen) (); /* Open keyboard */
int (*t_kclose)(); /* close keyboard */ int (*t_kclose) (); /* close keyboard */
int (*t_getchar)(); /* Get character from keyboard. */ int (*t_getchar) (); /* Get character from keyboard. */
int (*t_putchar)(); /* Put character to display. */ int (*t_putchar) (); /* Put character to display. */
int (*t_flush)(); /* Flush output buffers. */ int (*t_flush) (); /* Flush output buffers. */
int (*t_move)(); /* Move the cursor, origin 0. */ int (*t_move) (); /* Move the cursor, origin 0. */
int (*t_eeol)(); /* Erase to end of line. */ int (*t_eeol) (); /* Erase to end of line. */
int (*t_eeop)(); /* Erase to end of page. */ int (*t_eeop) (); /* Erase to end of page. */
int (*t_beep)(); /* Beep. */ int (*t_beep) (); /* Beep. */
int (*t_rev)(); /* set reverse video state */ int (*t_rev) (); /* set reverse video state */
int (*t_rez)(); /* change screen resolution */ int (*t_rez) (); /* change screen resolution */
#if COLOR #if COLOR
int (*t_setfor)(); /* set forground color */ int (*t_setfor) (); /* set forground color */
int (*t_setback)(); /* set background color */ int (*t_setback) (); /* set background color */
#endif #endif
#if SCROLLCODE #if SCROLLCODE
int (*t_scroll)(); /* scroll a region of the screen */ int (*t_scroll) (); /* scroll a region of the screen */
#endif #endif
} TERM; } TERM;
/* TEMPORARY macros for terminal I/O (to be placed in a machine /* TEMPORARY macros for terminal I/O (to be placed in a machine
dependant place later) */ dependant place later) */
@ -599,17 +599,17 @@ typedef struct {
/* structure for the table of initial key bindings */ /* structure for the table of initial key bindings */
typedef struct { typedef struct {
short k_code; /* Key code */ short k_code; /* Key code */
int (*k_fp)(); /* Routine to handle it */ int (*k_fp) (); /* Routine to handle it */
} KEYTAB; } KEYTAB;
/* structure for the name binding table */ /* structure for the name binding table */
typedef struct { typedef struct {
char *n_name; /* name of function key */ char *n_name; /* name of function key */
int (*n_func)(); /* function name is bound to */ int (*n_func) (); /* function name is bound to */
} NBIND; } NBIND;
/* The editor holds deleted text chunks in the KILL buffer. The /* The editor holds deleted text chunks in the KILL buffer. The
kill buffer is logically a stream of ascii characters, however kill buffer is logically a stream of ascii characters, however
@ -618,7 +618,7 @@ typedef struct {
was taken up by the keycode structure) was taken up by the keycode structure)
*/ */
typedef struct KILL { typedef struct KILL {
struct KILL *d_next; /* link to next chunk, NULL if last */ struct KILL *d_next; /* link to next chunk, NULL if last */
char d_chunk[KBLOCK]; /* deleted text */ char d_chunk[KBLOCK]; /* deleted text */
} KILL; } KILL;
@ -630,8 +630,8 @@ typedef struct KILL {
*/ */
typedef struct VDESC { typedef struct VDESC {
int v_type; /* type of variable */ int v_type; /* type of variable */
int v_num; /* ordinal pointer to variable in list */ int v_num; /* ordinal pointer to variable in list */
} VDESC; } VDESC;
/* The !WHILE directive in the execution language needs to /* The !WHILE directive in the execution language needs to
@ -642,7 +642,7 @@ typedef struct VDESC {
typedef struct WHBLOCK { typedef struct WHBLOCK {
LINE *w_begin; /* ptr to !while statement */ LINE *w_begin; /* ptr to !while statement */
LINE *w_end; /* ptr to the !endwhile statement*/ LINE *w_end; /* ptr to the !endwhile statement */
int w_type; /* block type */ int w_type; /* block type */
struct WHBLOCK *w_next; /* next while */ struct WHBLOCK *w_next; /* next while */
} WHBLOCK; } WHBLOCK;
@ -678,30 +678,30 @@ typedef struct WHBLOCK {
* Defines for the metacharacters in the regular expression * Defines for the metacharacters in the regular expression
* search routines. * search routines.
*/ */
#define MCNIL 0 /* Like the '\0' for strings.*/ #define MCNIL 0 /* Like the '\0' for strings. */
#define LITCHAR 1 /* Literal character, or string.*/ #define LITCHAR 1 /* Literal character, or string. */
#define ANY 2 #define ANY 2
#define CCL 3 #define CCL 3
#define NCCL 4 #define NCCL 4
#define BOL 5 #define BOL 5
#define EOL 6 #define EOL 6
#define DITTO 7 #define DITTO 7
#define CLOSURE 256 /* An or-able value.*/ #define CLOSURE 256 /* An or-able value. */
#define MASKCL CLOSURE - 1 #define MASKCL CLOSURE - 1
#define MC_ANY '.' /* 'Any' character (except newline).*/ #define MC_ANY '.' /* 'Any' character (except newline). */
#define MC_CCL '[' /* Character class.*/ #define MC_CCL '[' /* Character class. */
#define MC_NCCL '^' /* Negate character class.*/ #define MC_NCCL '^' /* Negate character class. */
#define MC_RCCL '-' /* Range in character class.*/ #define MC_RCCL '-' /* Range in character class. */
#define MC_ECCL ']' /* End of character class.*/ #define MC_ECCL ']' /* End of character class. */
#define MC_BOL '^' /* Beginning of line.*/ #define MC_BOL '^' /* Beginning of line. */
#define MC_EOL '$' /* End of line.*/ #define MC_EOL '$' /* End of line. */
#define MC_CLOSURE '*' /* Closure - does not extend past newline.*/ #define MC_CLOSURE '*' /* Closure - does not extend past newline. */
#define MC_DITTO '&' /* Use matched string in replacement.*/ #define MC_DITTO '&' /* Use matched string in replacement. */
#define MC_ESC '\\' /* Escape - suppress meta-meaning.*/ #define MC_ESC '\\' /* Escape - suppress meta-meaning. */
#define BIT(n) (1 << (n)) /* An integer with one bit set.*/ #define BIT(n) (1 << (n)) /* An integer with one bit set. */
#define CHCASE(c) ((c) ^ DIFCASE) /* Toggle the case of a letter.*/ #define CHCASE(c) ((c) ^ DIFCASE) /* Toggle the case of a letter. */
/* HICHAR - 1 is the largest character we will deal with. /* HICHAR - 1 is the largest character we will deal with.
* HIBYTE represents the number of bytes in the bitmap. * HIBYTE represents the number of bytes in the bitmap.
@ -713,19 +713,18 @@ typedef struct WHBLOCK {
* the meta-character structure for MAGIC mode searching (MC), * the meta-character structure for MAGIC mode searching (MC),
* and the meta-character structure for MAGIC mode replacment (RMC). * and the meta-character structure for MAGIC mode replacment (RMC).
*/ */
typedef char *BITMAP; typedef char *BITMAP;
typedef struct { typedef struct {
short int mc_type; short int mc_type;
union { union {
int lchar; int lchar;
BITMAP cclmap; BITMAP cclmap;
} u; } u;
} MC; } MC;
typedef struct { typedef struct {
short int mc_type; short int mc_type;
char *rstr; char *rstr;
} RMC; } RMC;
#endif #endif

962
eval.c

File diff suppressed because it is too large Load Diff

18
evar.h
View File

@ -9,15 +9,15 @@
/* structure to hold user variables and their definitions */ /* structure to hold user variables and their definitions */
typedef struct UVAR { typedef struct UVAR {
char u_name[NVSIZE + 1]; /* name of user variable */ char u_name[NVSIZE + 1]; /* name of user variable */
char *u_value; /* value (string) */ char *u_value; /* value (string) */
} UVAR; } UVAR;
/* current user variables (This structure will probably change) */ /* current user variables (This structure will probably change) */
#define MAXVARS 255 #define MAXVARS 255
UVAR uv[MAXVARS + 1]; /* user variables */ UVAR uv[MAXVARS + 1]; /* user variables */
/* list of recognized environment variables */ /* list of recognized environment variables */
@ -116,8 +116,8 @@ char *envars[] = {
/* list of recognized user functions */ /* list of recognized user functions */
typedef struct UFUNC { typedef struct UFUNC {
char *f_name; /* name of function */ char *f_name; /* name of function */
int f_type; /* 1 = monamic, 2 = dynamic */ int f_type; /* 1 = monamic, 2 = dynamic */
} UFUNC; } UFUNC;
#define NILNAMIC 0 #define NILNAMIC 0
@ -145,7 +145,7 @@ UFUNC funcs[] = {
"sgr", DYNAMIC, /* string logical greater than */ "sgr", DYNAMIC, /* string logical greater than */
"ind", MONAMIC, /* evaluate indirect value */ "ind", MONAMIC, /* evaluate indirect value */
"and", DYNAMIC, /* logical and */ "and", DYNAMIC, /* logical and */
"or", DYNAMIC, /* logical or */ "or", DYNAMIC, /* logical or */
"len", MONAMIC, /* string length */ "len", MONAMIC, /* string length */
"upp", MONAMIC, /* uppercase string */ "upp", MONAMIC, /* uppercase string */
"low", MONAMIC, /* lower case string */ "low", MONAMIC, /* lower case string */
@ -160,9 +160,9 @@ UFUNC funcs[] = {
"bin", MONAMIC, /* loopup what function name is bound to a key */ "bin", MONAMIC, /* loopup what function name is bound to a key */
"exi", MONAMIC, /* check if a file exists */ "exi", MONAMIC, /* check if a file exists */
"fin", MONAMIC, /* look for a file on the path... */ "fin", MONAMIC, /* look for a file on the path... */
"ban", DYNAMIC, /* bitwise and 9-10-87 jwm */ "ban", DYNAMIC, /* bitwise and 9-10-87 jwm */
"bor", DYNAMIC, /* bitwise or 9-10-87 jwm */ "bor", DYNAMIC, /* bitwise or 9-10-87 jwm */
"bxo", DYNAMIC, /* bitwise xor 9-10-87 jwm */ "bxo", DYNAMIC, /* bitwise xor 9-10-87 jwm */
"bno", MONAMIC, /* bitwise not */ "bno", MONAMIC, /* bitwise not */
"xla", TRINAMIC, /* XLATE character string translation */ "xla", TRINAMIC, /* XLATE character string translation */
}; };

424
exec.c

File diff suppressed because it is too large Load Diff

566
file.c
View File

@ -20,14 +20,14 @@
*/ */
fileread(f, n) fileread(f, n)
{ {
register int s; register int s;
char fname[NFILEN]; char fname[NFILEN];
if (restflag) /* don't allow this command if restricted */ if (restflag) /* don't allow this command if restricted */
return(resterr()); return (resterr());
if ((s=mlreply("Read file: ", fname, NFILEN)) != TRUE) if ((s = mlreply("Read file: ", fname, NFILEN)) != TRUE)
return(s); return (s);
return(readin(fname, TRUE)); return (readin(fname, TRUE));
} }
/* /*
@ -39,18 +39,18 @@ fileread(f, n)
*/ */
insfile(f, n) insfile(f, n)
{ {
register int s; register int s;
char fname[NFILEN]; char fname[NFILEN];
if (restflag) /* don't allow this command if restricted */ if (restflag) /* don't allow this command if restricted */
return(resterr()); return (resterr());
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
if ((s=mlreply("Insert file: ", fname, NFILEN)) != TRUE) if ((s = mlreply("Insert file: ", fname, NFILEN)) != TRUE)
return(s); return (s);
if ((s=ifile(fname)) != TRUE) if ((s = ifile(fname)) != TRUE)
return(s); return (s);
return(reposition(TRUE, -1)); return (reposition(TRUE, -1));
} }
/* /*
@ -64,28 +64,28 @@ insfile(f, n)
*/ */
filefind(f, n) filefind(f, n)
{ {
char fname[NFILEN]; /* file user wishes to find */ char fname[NFILEN]; /* file user wishes to find */
register int s; /* status return */ register int s; /* status return */
if (restflag) /* don't allow this command if restricted */ if (restflag) /* don't allow this command if restricted */
return(resterr()); return (resterr());
if ((s=mlreply("Find file: ", fname, NFILEN)) != TRUE) if ((s = mlreply("Find file: ", fname, NFILEN)) != TRUE)
return(s); return (s);
return(getfile(fname, TRUE)); return (getfile(fname, TRUE));
} }
viewfile(f, n) /* visit a file in VIEW mode */ viewfile(f, n)
{ { /* visit a file in VIEW mode */
char fname[NFILEN]; /* file user wishes to find */ char fname[NFILEN]; /* file user wishes to find */
register int s; /* status return */ register int s; /* status return */
register WINDOW *wp; /* scan for windows that need updating */ register WINDOW *wp; /* scan for windows that need updating */
if (restflag) /* don't allow this command if restricted */ if (restflag) /* don't allow this command if restricted */
return(resterr()); return (resterr());
if ((s=mlreply("View file: ", fname, NFILEN)) != TRUE) if ((s = mlreply("View file: ", fname, NFILEN)) != TRUE)
return (s); return (s);
s = getfile(fname, FALSE); s = getfile(fname, FALSE);
if (s) { /* if we succeed, put it in view mode */ if (s) { /* if we succeed, put it in view mode */
curwp->w_bufp->b_mode |= MDVIEW; curwp->w_bufp->b_mode |= MDVIEW;
/* scan through and update mode lines of all windows */ /* scan through and update mode lines of all windows */
@ -95,14 +95,13 @@ viewfile(f, n) /* visit a file in VIEW mode */
wp = wp->w_wndp; wp = wp->w_wndp;
} }
} }
return(s); return (s);
} }
#if CRYPT #if CRYPT
resetkey() /* reset the encryption key if needed */ resetkey()
{ /* reset the encryption key if needed */
{ register int s; /* return status */
register int s; /* return status */
/* turn off the encryption flag */ /* turn off the encryption flag */
cryptflag = FALSE; cryptflag = FALSE;
@ -112,7 +111,7 @@ resetkey() /* reset the encryption key if needed */
if (curbp->b_key[0] == 0) { if (curbp->b_key[0] == 0) {
s = setkey(FALSE, 0); s = setkey(FALSE, 0);
if (s != TRUE) if (s != TRUE)
return(s); return (s);
} }
/* let others know... */ /* let others know... */
@ -120,72 +119,73 @@ resetkey() /* reset the encryption key if needed */
/* and set up the key to be used! */ /* and set up the key to be used! */
/* de-encrypt it */ /* de-encrypt it */
crypt((char *)NULL, 0); crypt((char *) NULL, 0);
crypt(curbp->b_key, strlen(curbp->b_key)); crypt(curbp->b_key, strlen(curbp->b_key));
/* re-encrypt it...seeding it to start */ /* re-encrypt it...seeding it to start */
crypt((char *)NULL, 0); crypt((char *) NULL, 0);
crypt(curbp->b_key, strlen(curbp->b_key)); crypt(curbp->b_key, strlen(curbp->b_key));
} }
return(TRUE); return (TRUE);
} }
#endif #endif
getfile(fname, lockfl) getfile(fname, lockfl)
char fname[]; /* file name to find */ char fname[]; /* file name to find */
int lockfl; /* check the file for locks? */ int lockfl; /* check the file for locks? */
{ {
register BUFFER *bp; register BUFFER *bp;
register LINE *lp; register LINE *lp;
register int i; register int i;
register int s; register int s;
char bname[NBUFN]; /* buffer name to put file */ char bname[NBUFN]; /* buffer name to put file */
#if MSDOS #if MSDOS
mklower(fname); /* msdos isn't case sensitive */ mklower(fname); /* msdos isn't case sensitive */
#endif #endif
for (bp=bheadp; bp!=NULL; bp=bp->b_bufp) { for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
if ((bp->b_flag&BFINVS)==0 && strcmp(bp->b_fname, fname)==0) { if ((bp->b_flag & BFINVS) == 0
&& strcmp(bp->b_fname, fname) == 0) {
swbuffer(bp); swbuffer(bp);
lp = curwp->w_dotp; lp = curwp->w_dotp;
i = curwp->w_ntrows/2; i = curwp->w_ntrows / 2;
while (i-- && lback(lp)!=curbp->b_linep) while (i-- && lback(lp) != curbp->b_linep)
lp = lback(lp); lp = lback(lp);
curwp->w_linep = lp; curwp->w_linep = lp;
curwp->w_flag |= WFMODE|WFHARD; curwp->w_flag |= WFMODE | WFHARD;
cknewwindow(); cknewwindow();
mlwrite("(Old buffer)"); mlwrite("(Old buffer)");
return (TRUE); return (TRUE);
} }
} }
makename(bname, fname); /* New buffer name. */ makename(bname, fname); /* New buffer name. */
while ((bp=bfind(bname, FALSE, 0)) != NULL) { while ((bp = bfind(bname, FALSE, 0)) != NULL) {
/* old buffer name conflict code */ /* old buffer name conflict code */
s = mlreply("Buffer name: ", bname, NBUFN); s = mlreply("Buffer name: ", bname, NBUFN);
if (s == ABORT) /* ^G to just quit */ if (s == ABORT) /* ^G to just quit */
return (s); return (s);
if (s == FALSE) { /* CR to clobber it */ if (s == FALSE) { /* CR to clobber it */
makename(bname, fname); makename(bname, fname);
break; break;
} }
} }
if (bp==NULL && (bp=bfind(bname, TRUE, 0))==NULL) { if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) {
mlwrite("Cannot create buffer"); mlwrite("Cannot create buffer");
return (FALSE); return (FALSE);
} }
if (--curbp->b_nwnd == 0) { /* Undisplay. */ if (--curbp->b_nwnd == 0) { /* Undisplay. */
curbp->b_dotp = curwp->w_dotp; curbp->b_dotp = curwp->w_dotp;
curbp->b_doto = curwp->w_doto; curbp->b_doto = curwp->w_doto;
curbp->b_markp = curwp->w_markp; curbp->b_markp = curwp->w_markp;
curbp->b_marko = curwp->w_marko; curbp->b_marko = curwp->w_marko;
} }
curbp = bp; /* Switch to it. */ curbp = bp; /* Switch to it. */
curwp->w_bufp = bp; curwp->w_bufp = bp;
curbp->b_nwnd++; curbp->b_nwnd++;
s = readin(fname, lockfl); /* Read it in. */ s = readin(fname, lockfl); /* Read it in. */
cknewwindow(); cknewwindow();
return s; return s;
} }
@ -201,19 +201,19 @@ int lockfl; /* check the file for locks? */
readin(fname, lockfl) readin(fname, lockfl)
char fname[]; /* name of file to read */ char fname[]; /* name of file to read */
int lockfl; /* check for file locks? */ int lockfl; /* check for file locks? */
{ {
register LINE *lp1; register LINE *lp1;
register LINE *lp2; register LINE *lp2;
register int i; register int i;
register WINDOW *wp; register WINDOW *wp;
register BUFFER *bp; register BUFFER *bp;
register int s; register int s;
register int nbytes; register int nbytes;
register int nline; register int nline;
int lflag; /* any lines longer than allowed? */ int lflag; /* any lines longer than allowed? */
char mesg[NSTRING]; char mesg[NSTRING];
#if (FILOCK && BSD) || SVR4 #if (FILOCK && BSD) || SVR4
@ -226,62 +226,62 @@ int lockfl; /* check for file locks? */
goto out; goto out;
} }
#else #else
return(ABORT); return (ABORT);
#endif #endif
#endif #endif
#if CRYPT #if CRYPT
s = resetkey(); s = resetkey();
if (s != TRUE) if (s != TRUE)
return(s); return (s);
#endif #endif
bp = curbp; /* Cheap. */ bp = curbp; /* Cheap. */
if ((s=bclear(bp)) != TRUE) /* Might be old. */ if ((s = bclear(bp)) != TRUE) /* Might be old. */
return (s); return (s);
bp->b_flag &= ~(BFINVS|BFCHG); bp->b_flag &= ~(BFINVS | BFCHG);
strcpy(bp->b_fname, fname); strcpy(bp->b_fname, fname);
/* let a user macro get hold of things...if he wants */ /* let a user macro get hold of things...if he wants */
execute(META|SPEC|'R', FALSE, 1); execute(META | SPEC | 'R', FALSE, 1);
/* turn off ALL keyboard translation in case we get a dos error */ /* turn off ALL keyboard translation in case we get a dos error */
TTkclose(); TTkclose();
if ((s=ffropen(fname)) == FIOERR) /* Hard file open. */ if ((s = ffropen(fname)) == FIOERR) /* Hard file open. */
goto out; goto out;
if (s == FIOFNF) { /* File not found. */ if (s == FIOFNF) { /* File not found. */
mlwrite("(New file)"); mlwrite("(New file)");
goto out; goto out;
} }
/* read the file in */ /* read the file in */
mlwrite("(Reading file)"); mlwrite("(Reading file)");
nline = 0; nline = 0;
lflag = FALSE; lflag = FALSE;
while ((s=ffgetline()) == FIOSUC) { while ((s = ffgetline()) == FIOSUC) {
nbytes = strlen(fline); nbytes = strlen(fline);
if ((lp1=lalloc(nbytes)) == NULL) { if ((lp1 = lalloc(nbytes)) == NULL) {
s = FIOMEM; /* Keep message on the */ s = FIOMEM; /* Keep message on the */
break; /* display. */ break; /* display. */
} }
#if PKCODE #if PKCODE
if (nline > MAXNLINE) { if (nline > MAXNLINE) {
s = FIOMEM; s = FIOMEM;
break; break;
} }
#endif #endif
lp2 = lback(curbp->b_linep); lp2 = lback(curbp->b_linep);
lp2->l_fp = lp1; lp2->l_fp = lp1;
lp1->l_fp = curbp->b_linep; lp1->l_fp = curbp->b_linep;
lp1->l_bp = lp2; lp1->l_bp = lp2;
curbp->b_linep->l_bp = lp1; curbp->b_linep->l_bp = lp1;
for (i=0; i<nbytes; ++i) for (i = 0; i < nbytes; ++i)
lputc(lp1, i, fline[i]); lputc(lp1, i, fline[i]);
++nline; ++nline;
} }
ffclose(); /* Ignore errors. */ ffclose(); /* Ignore errors. */
strcpy(mesg, "("); strcpy(mesg, "(");
if (s==FIOERR) { if (s == FIOERR) {
strcat(mesg, "I/O ERROR, "); strcat(mesg, "I/O ERROR, ");
curbp->b_flag |= BFTRUNC; curbp->b_flag |= BFTRUNC;
} }
@ -290,30 +290,30 @@ int lockfl; /* check for file locks? */
curbp->b_flag |= BFTRUNC; curbp->b_flag |= BFTRUNC;
} }
sprintf(&mesg[strlen(mesg)], "Read %d line", nline); sprintf(&mesg[strlen(mesg)], "Read %d line", nline);
if (nline != 1) if (nline != 1)
strcat(mesg, "s"); strcat(mesg, "s");
strcat(mesg, ")"); strcat(mesg, ")");
mlwrite(mesg); mlwrite(mesg);
out: out:
TTkopen(); /* open the keyboard again */ TTkopen(); /* open the keyboard again */
for (wp=wheadp; wp!=NULL; wp=wp->w_wndp) { for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
if (wp->w_bufp == curbp) { if (wp->w_bufp == curbp) {
wp->w_linep = lforw(curbp->b_linep); wp->w_linep = lforw(curbp->b_linep);
wp->w_dotp = lforw(curbp->b_linep); wp->w_dotp = lforw(curbp->b_linep);
wp->w_doto = 0; wp->w_doto = 0;
wp->w_markp = NULL; wp->w_markp = NULL;
wp->w_marko = 0; wp->w_marko = 0;
wp->w_flag |= WFMODE|WFHARD; wp->w_flag |= WFMODE | WFHARD;
} }
} }
if (s == FIOERR || s == FIOFNF) /* False if error. */ if (s == FIOERR || s == FIOFNF) /* False if error. */
return(FALSE); return (FALSE);
#if 0 #if 0
if (s == ABORT) if (s == ABORT)
return(ABORT); return (ABORT);
#endif #endif
return (TRUE); return (TRUE);
} }
/* /*
@ -324,41 +324,43 @@ out:
* a better place than a line of code. * a better place than a line of code.
*/ */
makename(bname, fname) makename(bname, fname)
char bname[]; char bname[];
char fname[]; char fname[];
{ {
register char *cp1; register char *cp1;
register char *cp2; register char *cp2;
cp1 = &fname[0]; cp1 = &fname[0];
while (*cp1 != 0) while (*cp1 != 0)
++cp1; ++cp1;
#if VMS #if VMS
#if PKCODE #if PKCODE
while (cp1!=&fname[0] && cp1[-1]!=':' && cp1[-1]!=']' && cp1[-1]!='>') while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != ']'
&& cp1[-1] != '>')
#else #else
while (cp1!=&fname[0] && cp1[-1]!=':' && cp1[-1]!=']') while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != ']')
#endif #endif
--cp1; --cp1;
#endif #endif
#if MSDOS #if MSDOS
while (cp1!=&fname[0] && cp1[-1]!=':' && cp1[-1]!='\\'&&cp1[-1]!='/') while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != '\\'
--cp1; && cp1[-1] != '/')
--cp1;
#endif #endif
#if V7 | USG | BSD #if V7 | USG | BSD
while (cp1!=&fname[0] && cp1[-1]!='/') while (cp1 != &fname[0] && cp1[-1] != '/')
--cp1; --cp1;
#endif #endif
cp2 = &bname[0]; cp2 = &bname[0];
while (cp2!=&bname[NBUFN-1] && *cp1!=0 && *cp1!=';') while (cp2 != &bname[NBUFN - 1] && *cp1 != 0 && *cp1 != ';')
*cp2++ = *cp1++; *cp2++ = *cp1++;
*cp2 = 0; *cp2 = 0;
} }
unqname(name) /* make sure a buffer name is unique */ unqname(name)
/* make sure a buffer name is unique */
char *name; /* name to check on */ char *name; /* name to check on */
{ {
register char *sp; register char *sp;
@ -370,7 +372,7 @@ char *name; /* name to check on */
sp = name; sp = name;
while (*sp) while (*sp)
++sp; ++sp;
if (sp == name || (*(sp-1) <'0' || *(sp-1) > '8')) { if (sp == name || (*(sp - 1) < '0' || *(sp - 1) > '8')) {
*sp++ = '0'; *sp++ = '0';
*sp = 0; *sp = 0;
} else } else
@ -389,25 +391,25 @@ char *name; /* name to check on */
*/ */
filewrite(f, n) filewrite(f, n)
{ {
register WINDOW *wp; register WINDOW *wp;
register int s; register int s;
char fname[NFILEN]; char fname[NFILEN];
if (restflag) /* don't allow this command if restricted */ if (restflag) /* don't allow this command if restricted */
return(resterr()); return (resterr());
if ((s=mlreply("Write file: ", fname, NFILEN)) != TRUE) if ((s = mlreply("Write file: ", fname, NFILEN)) != TRUE)
return (s); return (s);
if ((s=writeout(fname)) == TRUE) { if ((s = writeout(fname)) == TRUE) {
strcpy(curbp->b_fname, fname); strcpy(curbp->b_fname, fname);
curbp->b_flag &= ~BFCHG; curbp->b_flag &= ~BFCHG;
wp = wheadp; /* Update mode lines. */ wp = wheadp; /* Update mode lines. */
while (wp != NULL) { while (wp != NULL) {
if (wp->w_bufp == curbp) if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE; wp->w_flag |= WFMODE;
wp = wp->w_wndp; wp = wp->w_wndp;
} }
} }
return (s); return (s);
} }
/* /*
@ -420,36 +422,36 @@ filewrite(f, n)
*/ */
filesave(f, n) filesave(f, n)
{ {
register WINDOW *wp; register WINDOW *wp;
register int s; register int s;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
if ((curbp->b_flag&BFCHG) == 0) /* Return, no changes. */ if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */
return (TRUE); return (TRUE);
if (curbp->b_fname[0] == 0) { /* Must have a name. */ if (curbp->b_fname[0] == 0) { /* Must have a name. */
mlwrite("No file name"); mlwrite("No file name");
return (FALSE); return (FALSE);
} }
/* complain about truncated files */ /* complain about truncated files */
if ((curbp->b_flag&BFTRUNC) != 0) { if ((curbp->b_flag & BFTRUNC) != 0) {
if (mlyesno("Truncated file ... write it out") == FALSE) { if (mlyesno("Truncated file ... write it out") == FALSE) {
mlwrite("(Aborted)"); mlwrite("(Aborted)");
return(FALSE); return (FALSE);
} }
} }
if ((s=writeout(curbp->b_fname)) == TRUE) { if ((s = writeout(curbp->b_fname)) == TRUE) {
curbp->b_flag &= ~BFCHG; curbp->b_flag &= ~BFCHG;
wp = wheadp; /* Update mode lines. */ wp = wheadp; /* Update mode lines. */
while (wp != NULL) { while (wp != NULL) {
if (wp->w_bufp == curbp) if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE; wp->w_flag |= WFMODE;
wp = wp->w_wndp; wp = wp->w_wndp;
} }
} }
return (s); return (s);
} }
/* /*
@ -461,47 +463,47 @@ filesave(f, n)
* checking of some sort. * checking of some sort.
*/ */
writeout(fn) writeout(fn)
char *fn; char *fn;
{ {
register int s; register int s;
register LINE *lp; register LINE *lp;
register int nline; register int nline;
#if CRYPT #if CRYPT
s = resetkey(); s = resetkey();
if (s != TRUE) if (s != TRUE)
return(s); return (s);
#endif #endif
/* turn off ALL keyboard translation in case we get a dos error */ /* turn off ALL keyboard translation in case we get a dos error */
TTkclose(); TTkclose();
if ((s=ffwopen(fn)) != FIOSUC) { /* Open writes message. */ if ((s = ffwopen(fn)) != FIOSUC) { /* Open writes message. */
TTkopen(); TTkopen();
return (FALSE); return (FALSE);
} }
mlwrite("(Writing...)"); /* tell us were writing */ mlwrite("(Writing...)"); /* tell us were writing */
lp = lforw(curbp->b_linep); /* First line. */ lp = lforw(curbp->b_linep); /* First line. */
nline = 0; /* Number of lines. */ nline = 0; /* Number of lines. */
while (lp != curbp->b_linep) { while (lp != curbp->b_linep) {
if ((s=ffputline(&lp->l_text[0], llength(lp))) != FIOSUC) if ((s = ffputline(&lp->l_text[0], llength(lp))) != FIOSUC)
break; break;
++nline; ++nline;
lp = lforw(lp); lp = lforw(lp);
} }
if (s == FIOSUC) { /* No write error. */ if (s == FIOSUC) { /* No write error. */
s = ffclose(); s = ffclose();
if (s == FIOSUC) { /* No close error. */ if (s == FIOSUC) { /* No close error. */
if (nline == 1) if (nline == 1)
mlwrite("(Wrote 1 line)"); mlwrite("(Wrote 1 line)");
else else
mlwrite("(Wrote %d lines)", nline); mlwrite("(Wrote %d lines)", nline);
} }
} else /* Ignore close error */ } else /* Ignore close error */
ffclose(); /* if a write error. */ ffclose(); /* if a write error. */
TTkopen(); TTkopen();
if (s != FIOSUC) /* Some sort of error. */ if (s != FIOSUC) /* Some sort of error. */
return (FALSE); return (FALSE);
return (TRUE); return (TRUE);
} }
/* /*
@ -515,26 +517,26 @@ char *fn;
*/ */
filename(f, n) filename(f, n)
{ {
register WINDOW *wp; register WINDOW *wp;
register int s; register int s;
char fname[NFILEN]; char fname[NFILEN];
if (restflag) /* don't allow this command if restricted */ if (restflag) /* don't allow this command if restricted */
return(resterr()); return (resterr());
if ((s=mlreply("Name: ", fname, NFILEN)) == ABORT) if ((s = mlreply("Name: ", fname, NFILEN)) == ABORT)
return (s); return (s);
if (s == FALSE) if (s == FALSE)
strcpy(curbp->b_fname, ""); strcpy(curbp->b_fname, "");
else else
strcpy(curbp->b_fname, fname); strcpy(curbp->b_fname, fname);
wp = wheadp; /* Update mode lines. */ wp = wheadp; /* Update mode lines. */
while (wp != NULL) { while (wp != NULL) {
if (wp->w_bufp == curbp) if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE; wp->w_flag |= WFMODE;
wp = wp->w_wndp; wp = wp->w_wndp;
} }
curbp->b_mode &= ~MDVIEW; /* no longer read only mode */ curbp->b_mode &= ~MDVIEW; /* no longer read only mode */
return (TRUE); return (TRUE);
} }
/* /*
@ -543,34 +545,34 @@ filename(f, n)
* status of the read. * status of the read.
*/ */
ifile(fname) ifile(fname)
char fname[]; char fname[];
{ {
register LINE *lp0; register LINE *lp0;
register LINE *lp1; register LINE *lp1;
register LINE *lp2; register LINE *lp2;
register int i; register int i;
register BUFFER *bp; register BUFFER *bp;
register int s; register int s;
register int nbytes; register int nbytes;
register int nline; register int nline;
int lflag; /* any lines longer than allowed? */ int lflag; /* any lines longer than allowed? */
char mesg[NSTRING]; char mesg[NSTRING];
bp = curbp; /* Cheap. */ bp = curbp; /* Cheap. */
bp->b_flag |= BFCHG; /* we have changed */ bp->b_flag |= BFCHG; /* we have changed */
bp->b_flag &= ~BFINVS; /* and are not temporary*/ bp->b_flag &= ~BFINVS; /* and are not temporary */
if ((s=ffropen(fname)) == FIOERR) /* Hard file open. */ if ((s = ffropen(fname)) == FIOERR) /* Hard file open. */
goto out; goto out;
if (s == FIOFNF) { /* File not found. */ if (s == FIOFNF) { /* File not found. */
mlwrite("(No such file)"); mlwrite("(No such file)");
return(FALSE); return (FALSE);
} }
mlwrite("(Inserting file)"); mlwrite("(Inserting file)");
#if CRYPT #if CRYPT
s = resetkey(); s = resetkey();
if (s != TRUE) if (s != TRUE)
return(s); return (s);
#endif #endif
/* back up a line and save the mark here */ /* back up a line and save the mark here */
curwp->w_dotp = lback(curwp->w_dotp); curwp->w_dotp = lback(curwp->w_dotp);
@ -578,14 +580,14 @@ char fname[];
curwp->w_markp = curwp->w_dotp; curwp->w_markp = curwp->w_dotp;
curwp->w_marko = 0; curwp->w_marko = 0;
nline = 0; nline = 0;
lflag = FALSE; lflag = FALSE;
while ((s=ffgetline()) == FIOSUC) { while ((s = ffgetline()) == FIOSUC) {
nbytes = strlen(fline); nbytes = strlen(fline);
if ((lp1=lalloc(nbytes)) == NULL) { if ((lp1 = lalloc(nbytes)) == NULL) {
s = FIOMEM; /* Keep message on the */ s = FIOMEM; /* Keep message on the */
break; /* display. */ break; /* display. */
} }
lp0 = curwp->w_dotp; /* line previous to insert */ lp0 = curwp->w_dotp; /* line previous to insert */
lp2 = lp0->l_fp; /* line after insert */ lp2 = lp0->l_fp; /* line after insert */
@ -597,14 +599,14 @@ char fname[];
/* and advance and write out the current line */ /* and advance and write out the current line */
curwp->w_dotp = lp1; curwp->w_dotp = lp1;
for (i=0; i<nbytes; ++i) for (i = 0; i < nbytes; ++i)
lputc(lp1, i, fline[i]); lputc(lp1, i, fline[i]);
++nline; ++nline;
} }
ffclose(); /* Ignore errors. */ ffclose(); /* Ignore errors. */
curwp->w_markp = lforw(curwp->w_markp); curwp->w_markp = lforw(curwp->w_markp);
strcpy(mesg, "("); strcpy(mesg, "(");
if (s==FIOERR) { if (s == FIOERR) {
strcat(mesg, "I/O ERROR, "); strcat(mesg, "I/O ERROR, ");
curbp->b_flag |= BFTRUNC; curbp->b_flag |= BFTRUNC;
} }
@ -613,12 +615,12 @@ char fname[];
curbp->b_flag |= BFTRUNC; curbp->b_flag |= BFTRUNC;
} }
sprintf(&mesg[strlen(mesg)], "Inserted %d line", nline); sprintf(&mesg[strlen(mesg)], "Inserted %d line", nline);
if (nline > 1) if (nline > 1)
strcat(mesg, "s"); strcat(mesg, "s");
strcat(mesg, ")"); strcat(mesg, ")");
mlwrite(mesg); mlwrite(mesg);
out: out:
/* advance to the next line and mark the window for changes */ /* advance to the next line and mark the window for changes */
curwp->w_dotp = lforw(curwp->w_dotp); curwp->w_dotp = lforw(curwp->w_dotp);
curwp->w_flag |= WFHARD | WFMODE; curwp->w_flag |= WFHARD | WFMODE;
@ -629,7 +631,7 @@ out:
curbp->b_markp = curwp->w_markp; curbp->b_markp = curwp->w_markp;
curbp->b_marko = curwp->w_marko; curbp->b_marko = curwp->w_marko;
if (s == FIOERR) /* False if error. */ if (s == FIOERR) /* False if error. */
return (FALSE); return (FALSE);
return (TRUE); return (TRUE);
} }

168
fileio.c
View File

@ -14,19 +14,19 @@
extern int nullflag; extern int nullflag;
#endif #endif
FILE *ffp; /* File pointer, all functions. */ FILE *ffp; /* File pointer, all functions. */
int eofflag; /* end-of-file flag */ int eofflag; /* end-of-file flag */
/* /*
* Open a file for reading. * Open a file for reading.
*/ */
ffropen(fn) ffropen(fn)
char *fn; char *fn;
{ {
if ((ffp=fopen(fn, "r")) == NULL) if ((ffp = fopen(fn, "r")) == NULL)
return (FIOFNF); return (FIOFNF);
eofflag = FALSE; eofflag = FALSE;
return (FIOSUC); return (FIOSUC);
} }
/* /*
@ -34,20 +34,20 @@ char *fn;
* (cannot create). * (cannot create).
*/ */
ffwopen(fn) ffwopen(fn)
char *fn; char *fn;
{ {
#if VMS #if VMS
register int fd; register int fd;
if ((fd=creat(fn, 0666, "rfm=var", "rat=cr")) < 0 if ((fd = creat(fn, 0666, "rfm=var", "rat=cr")) < 0
|| (ffp=fdopen(fd, "w")) == NULL) { || (ffp = fdopen(fd, "w")) == NULL) {
#else #else
if ((ffp=fopen(fn, "w")) == NULL) { if ((ffp = fopen(fn, "w")) == NULL) {
#endif #endif
mlwrite("Cannot open file for writing"); mlwrite("Cannot open file for writing");
return (FIOERR); return (FIOERR);
} }
return (FIOSUC); return (FIOSUC);
} }
/* /*
@ -65,16 +65,16 @@ ffclose()
#if MSDOS & CTRLZ #if MSDOS & CTRLZ
fputc(26, ffp); /* add a ^Z at the end of the file */ fputc(26, ffp); /* add a ^Z at the end of the file */
#endif #endif
#if V7 | USG | BSD | (MSDOS & (MSC | TURBO)) #if V7 | USG | BSD | (MSDOS & (MSC | TURBO))
if (fclose(ffp) != FALSE) { if (fclose(ffp) != FALSE) {
mlwrite("Error closing file"); mlwrite("Error closing file");
return(FIOERR); return (FIOERR);
} }
return(FIOSUC); return (FIOSUC);
#else #else
fclose(ffp); fclose(ffp);
return (FIOSUC); return (FIOSUC);
#endif #endif
} }
@ -84,34 +84,34 @@ ffclose()
* Check only at the newline. * Check only at the newline.
*/ */
ffputline(buf, nbuf) ffputline(buf, nbuf)
char buf[]; char buf[];
{ {
register int i; register int i;
#if CRYPT #if CRYPT
char c; /* character to translate */ char c; /* character to translate */
if (cryptflag) { if (cryptflag) {
for (i = 0; i < nbuf; ++i) { for (i = 0; i < nbuf; ++i) {
c = buf[i] & 0xff; c = buf[i] & 0xff;
crypt(&c, 1); crypt(&c, 1);
fputc(c, ffp); fputc(c, ffp);
} }
} else } else
for (i = 0; i < nbuf; ++i) for (i = 0; i < nbuf; ++i)
fputc(buf[i]&0xFF, ffp); fputc(buf[i] & 0xFF, ffp);
#else #else
for (i = 0; i < nbuf; ++i) for (i = 0; i < nbuf; ++i)
fputc(buf[i]&0xFF, ffp); fputc(buf[i] & 0xFF, ffp);
#endif #endif
fputc('\n', ffp); fputc('\n', ffp);
if (ferror(ffp)) { if (ferror(ffp)) {
mlwrite("Write I/O error"); mlwrite("Write I/O error");
return (FIOERR); return (FIOERR);
} }
return (FIOSUC); return (FIOSUC);
} }
/* /*
@ -121,15 +121,14 @@ char buf[];
* errors too. Return status. * errors too. Return status.
*/ */
ffgetline() ffgetline()
{ {
register int c; /* current character read */ register int c; /* current character read */
register int i; /* current index into fline */ register int i; /* current index into fline */
register char *tmpline; /* temp storage for expanding line */ register char *tmpline; /* temp storage for expanding line */
/* if we are at the end...return it */ /* if we are at the end...return it */
if (eofflag) if (eofflag)
return(FIOEOF); return (FIOEOF);
/* dump fline if it ended up too big */ /* dump fline if it ended up too big */
if (flen > NSTRING) { if (flen > NSTRING) {
@ -140,77 +139,76 @@ ffgetline()
/* if we don't have an fline, allocate one */ /* if we don't have an fline, allocate one */
if (fline == NULL) if (fline == NULL)
if ((fline = malloc(flen = NSTRING)) == NULL) if ((fline = malloc(flen = NSTRING)) == NULL)
return(FIOMEM); return (FIOMEM);
/* read the line in */ /* read the line in */
#if PKCODE #if PKCODE
if (!nullflag) { if (!nullflag) {
if (fgets(fline, NSTRING, ffp) == (char *)NULL) { /* EOF ? */ if (fgets(fline, NSTRING, ffp) == (char *) NULL) { /* EOF ? */
i = 0; i = 0;
c = EOF; c = EOF;
} } else {
else { i = strlen(fline);
i = strlen(fline); c = 0;
c = 0; if (i > 0) {
if (i > 0) { c = fline[i - 1];
c = fline[i-1]; i--;
i--; }
} }
} } else {
}
else {
i = 0; i = 0;
c = fgetc(ffp); c = fgetc(ffp);
} }
while (c != EOF && c != '\n') { while (c != EOF && c != '\n') {
#else #else
i = 0; i = 0;
while ((c = fgetc(ffp)) != EOF && c != '\n') { while ((c = fgetc(ffp)) != EOF && c != '\n') {
#endif #endif
#if PKCODE #if PKCODE
if (c) { if (c) {
#endif #endif
fline[i++] = c; fline[i++] = c;
/* if it's longer, get more room */ /* if it's longer, get more room */
if (i >= flen) { if (i >= flen) {
if ((tmpline = malloc(flen+NSTRING)) == NULL) if ((tmpline =
return(FIOMEM); malloc(flen + NSTRING)) == NULL)
strncpy(tmpline, fline, flen); return (FIOMEM);
flen += NSTRING; strncpy(tmpline, fline, flen);
free(fline); flen += NSTRING;
fline = tmpline; free(fline);
} fline = tmpline;
}
#if PKCODE #if PKCODE
} }
c = fgetc(ffp); c = fgetc(ffp);
#endif #endif
} }
/* test for any errors that may have occured */ /* test for any errors that may have occured */
if (c == EOF) { if (c == EOF) {
if (ferror(ffp)) { if (ferror(ffp)) {
mlwrite("File read error"); mlwrite("File read error");
return(FIOERR); return (FIOERR);
} }
if (i != 0) if (i != 0)
eofflag = TRUE; eofflag = TRUE;
else else
return(FIOEOF); return (FIOEOF);
} }
/* terminate and decrypt the string */ /* terminate and decrypt the string */
fline[i] = 0; fline[i] = 0;
#if CRYPT #if CRYPT
if (cryptflag) if (cryptflag)
crypt(fline, strlen(fline)); crypt(fline, strlen(fline));
#endif #endif
return(FIOSUC); return (FIOSUC);
} }
int fexist(fname) /* does <fname> exist on disk? */ int fexist(fname)
/* does <fname> exist on disk? */
char *fname; /* file to check for existance */ char *fname; /* file to check for existance */
{ {
FILE *fp; FILE *fp;
@ -220,9 +218,9 @@ char *fname; /* file to check for existance */
/* if it fails, just return false! */ /* if it fails, just return false! */
if (fp == NULL) if (fp == NULL)
return(FALSE); return (FALSE);
/* otherwise, close it and report true */ /* otherwise, close it and report true */
fclose(fp); fclose(fp);
return(TRUE); return (TRUE);
} }

323
ibmpc.c
View File

@ -8,7 +8,7 @@
* modified by Petri Kutvonen * modified by Petri Kutvonen
*/ */
#define termdef 1 /* don't define "term" external */ #define termdef 1 /* don't define "term" external */
#include <stdio.h> #include <stdio.h>
#include "estruct.h" #include "estruct.h"
@ -18,80 +18,80 @@
#if PKCODE #if PKCODE
#define NROW 50 #define NROW 50
#else #else
#define NROW 43 /* Max Screen size. */ #define NROW 43 /* Max Screen size. */
#endif #endif
#define NCOL 80 /* Edit if you want to. */ #define NCOL 80 /* Edit if you want to. */
#define MARGIN 8 /* size of minimim margin and */ #define MARGIN 8 /* size of minimim margin and */
#define SCRSIZ 64 /* scroll size for extended lines */ #define SCRSIZ 64 /* scroll size for extended lines */
#define NPAUSE 200 /* # times thru update to pause */ #define NPAUSE 200 /* # times thru update to pause */
#define BEL 0x07 /* BEL character. */ #define BEL 0x07 /* BEL character. */
#define ESC 0x1B /* ESC character. */ #define ESC 0x1B /* ESC character. */
#define SPACE 32 /* space character */ #define SPACE 32 /* space character */
#define SCADC 0xb8000000L /* CGA address of screen RAM */ #define SCADC 0xb8000000L /* CGA address of screen RAM */
#define SCADM 0xb0000000L /* MONO address of screen RAM */ #define SCADM 0xb0000000L /* MONO address of screen RAM */
#define SCADE 0xb8000000L /* EGA address of screen RAM */ #define SCADE 0xb8000000L /* EGA address of screen RAM */
#define MONOCRSR 0x0B0D /* monochrome cursor */ #define MONOCRSR 0x0B0D /* monochrome cursor */
#define CGACRSR 0x0607 /* CGA cursor */ #define CGACRSR 0x0607 /* CGA cursor */
#define EGACRSR 0x0709 /* EGA cursor */ #define EGACRSR 0x0709 /* EGA cursor */
#define CDCGA 0 /* color graphics card */ #define CDCGA 0 /* color graphics card */
#define CDMONO 1 /* monochrome text card */ #define CDMONO 1 /* monochrome text card */
#define CDEGA 2 /* EGA color adapter */ #define CDEGA 2 /* EGA color adapter */
#if PKCODE #if PKCODE
#define CDVGA 3 #define CDVGA 3
#endif #endif
#define CDSENSE 9 /* detect the card type */ #define CDSENSE 9 /* detect the card type */
#if PKCODE #if PKCODE
#define NDRIVE 4 #define NDRIVE 4
#else #else
#define NDRIVE 3 /* number of screen drivers */ #define NDRIVE 3 /* number of screen drivers */
#endif #endif
int dtype = -1; /* current display type */ int dtype = -1; /* current display type */
char drvname[][8] = { /* screen resolution names */ char drvname[][8] = { /* screen resolution names */
"CGA", "MONO", "EGA" "CGA", "MONO", "EGA"
#if PKCODE #if PKCODE
,"VGA" , "VGA"
#endif #endif
}; };
long scadd; /* address of screen ram */ long scadd; /* address of screen ram */
int *scptr[NROW]; /* pointer to screen lines */ int *scptr[NROW]; /* pointer to screen lines */
unsigned int sline[NCOL]; /* screen line image */ unsigned int sline[NCOL]; /* screen line image */
int egaexist = FALSE; /* is an EGA card available? */ int egaexist = FALSE; /* is an EGA card available? */
extern union REGS rg; /* cpu register for use of DOS calls */ extern union REGS rg; /* cpu register for use of DOS calls */
extern int ttopen(); /* Forward references. */ extern int ttopen(); /* Forward references. */
extern int ttgetc(); extern int ttgetc();
extern int ttputc(); extern int ttputc();
extern int ttflush(); extern int ttflush();
extern int ttclose(); extern int ttclose();
extern int ibmmove(); extern int ibmmove();
extern int ibmeeol(); extern int ibmeeol();
extern int ibmeeop(); extern int ibmeeop();
extern int ibmbeep(); extern int ibmbeep();
extern int ibmopen(); extern int ibmopen();
extern int ibmrev(); extern int ibmrev();
extern int ibmcres(); extern int ibmcres();
extern int ibmclose(); extern int ibmclose();
extern int ibmputc(); extern int ibmputc();
extern int ibmkopen(); extern int ibmkopen();
extern int ibmkclose(); extern int ibmkclose();
#if COLOR #if COLOR
extern int ibmfcol(); extern int ibmfcol();
extern int ibmbcol(); extern int ibmbcol();
extern int ibmscroll_reg(); extern int ibmscroll_reg();
int cfcolor = -1; /* current forground color */ int cfcolor = -1; /* current forground color */
int cbcolor = -1; /* current background color */ int cbcolor = -1; /* current background color */
int ctrans[] = /* ansi to ibm color translation table */ int ctrans[] = /* ansi to ibm color translation table */
#if PKCODE #if PKCODE
{0, 4, 2, 6, 1, 5, 3, 7, 15}; { 0, 4, 2, 6, 1, 5, 3, 7, 15 };
#else #else
{0, 4, 2, 6, 1, 5, 3, 7}; { 0, 4, 2, 6, 1, 5, 3, 7 };
#endif #endif
#endif #endif
@ -99,51 +99,51 @@ int ctrans[] = /* ansi to ibm color translation table */
* Standard terminal interface dispatch table. Most of the fields point into * Standard terminal interface dispatch table. Most of the fields point into
* "termio" code. * "termio" code.
*/ */
TERM term = { TERM term = {
NROW-1, NROW - 1,
NROW-1, NROW - 1,
NCOL, NCOL,
NCOL, NCOL,
MARGIN, MARGIN,
SCRSIZ, SCRSIZ,
NPAUSE, NPAUSE,
ibmopen, ibmopen,
ibmclose, ibmclose,
ibmkopen, ibmkopen,
ibmkclose, ibmkclose,
ttgetc, ttgetc,
ibmputc, ibmputc,
ttflush, ttflush,
ibmmove, ibmmove,
ibmeeol, ibmeeol,
ibmeeop, ibmeeop,
ibmbeep, ibmbeep,
ibmrev, ibmrev,
ibmcres ibmcres
#if COLOR #if COLOR
, ibmfcol, , ibmfcol,
ibmbcol ibmbcol
#endif #endif
#if SCROLLCODE #if SCROLLCODE
, ibmscroll_reg , ibmscroll_reg
#endif #endif
}; };
#if COLOR #if COLOR
ibmfcol(color) /* set the current output color */ ibmfcol(color)
/* set the current output color */
int color; /* color to set */ int color; /* color to set */
{ {
cfcolor = ctrans[color]; cfcolor = ctrans[color];
} }
ibmbcol(color) /* set the current background color */ ibmbcol(color)
/* set the current background color */
int color; /* color to set */ int color; /* color to set */
{ {
cbcolor = ctrans[color]; cbcolor = ctrans[color];
} }
#endif #endif
@ -156,14 +156,13 @@ ibmmove(row, col)
int86(0x10, &rg, &rg); int86(0x10, &rg, &rg);
} }
ibmeeol() /* erase to the end of the line */ ibmeeol()
{ /* erase to the end of the line */
{
unsigned int attr; /* attribute byte mask to place in RAM */ unsigned int attr; /* attribute byte mask to place in RAM */
unsigned int *lnptr; /* pointer to the destination line */ unsigned int *lnptr; /* pointer to the destination line */
int i; int i;
int ccol; /* current column cursor lives */ int ccol; /* current column cursor lives */
int crow; /* row */ int crow; /* row */
/* find the current cursor position */ /* find the current cursor position */
rg.h.ah = 3; /* read cursor position function code */ rg.h.ah = 3; /* read cursor position function code */
@ -182,27 +181,25 @@ ibmeeol() /* erase to the end of the line */
attr = 0x0700; attr = 0x0700;
#endif #endif
lnptr = &sline[0]; lnptr = &sline[0];
for (i=0; i < term.t_ncol; i++) for (i = 0; i < term.t_ncol; i++)
*lnptr++ = SPACE | attr; *lnptr++ = SPACE | attr;
if (flickcode && (dtype == CDCGA)) { if (flickcode && (dtype == CDCGA)) {
/* wait for vertical retrace to be off */ /* wait for vertical retrace to be off */
while ((inp(0x3da) & 8)) while ((inp(0x3da) & 8));
;
/* and to be back on */ /* and to be back on */
while ((inp(0x3da) & 8) == 0) while ((inp(0x3da) & 8) == 0);
;
} }
/* and send the string out */ /* and send the string out */
movmem(&sline[0], scptr[crow]+ccol, (term.t_ncol-ccol)*2); movmem(&sline[0], scptr[crow] + ccol, (term.t_ncol - ccol) * 2);
} }
ibmputc(ch) /* put a character at the current position in the ibmputc(ch)
current colors */ /* put a character at the current position in the
current colors */
int ch; int ch;
{ {
@ -227,10 +224,11 @@ ibmeeop()
rg.h.al = 0; /* # lines to scroll (clear it) */ rg.h.al = 0; /* # lines to scroll (clear it) */
rg.x.cx = 0; /* upper left corner of scroll */ rg.x.cx = 0; /* upper left corner of scroll */
rg.x.dx = (term.t_nrow << 8) | (term.t_ncol - 1); rg.x.dx = (term.t_nrow << 8) | (term.t_ncol - 1);
/* lower right corner of scroll */ /* lower right corner of scroll */
#if COLOR #if COLOR
if (dtype != CDMONO) if (dtype != CDMONO)
attr = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15); attr =
((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
else else
attr = 0; attr = 0;
#else #else
@ -240,27 +238,27 @@ ibmeeop()
int86(0x10, &rg, &rg); int86(0x10, &rg, &rg);
} }
ibmrev(state) /* change reverse video state */ ibmrev(state)
/* change reverse video state */
int state; /* TRUE = reverse, FALSE = normal */ int state; /* TRUE = reverse, FALSE = normal */
{ {
/* This never gets used under the IBM-PC driver */ /* This never gets used under the IBM-PC driver */
} }
ibmcres(res) /* change screen resolution */ ibmcres(res)
/* change screen resolution */
char *res; /* resolution to change to */ char *res; /* resolution to change to */
{ {
int i; /* index */ int i; /* index */
for (i = 0; i < NDRIVE; i++) for (i = 0; i < NDRIVE; i++)
if (strcmp(res, drvname[i]) == 0) { if (strcmp(res, drvname[i]) == 0) {
scinit(i); scinit(i);
return(TRUE); return (TRUE);
} }
return(FALSE); return (FALSE);
} }
#if SCROLLCODE #if SCROLLCODE
@ -272,19 +270,19 @@ ibmscroll_reg(from, to, howmany)
if (to < from) if (to < from)
for (i = 0; i < howmany; i++) for (i = 0; i < howmany; i++)
movmem(scptr[from+i], scptr[to+i], term.t_ncol*2); movmem(scptr[from + i], scptr[to + i],
else term.t_ncol * 2);
if (to > from) else if (to > from)
for (i = howmany-1; i >= 0; i--) for (i = howmany - 1; i >= 0; i--)
movmem(scptr[from+i], scptr[to+i], term.t_ncol*2); movmem(scptr[from + i], scptr[to + i],
term.t_ncol * 2);
return; return;
} }
#endif #endif
spal() /* reset the pallette registers */ spal()
{ /* reset the pallette registers */
{
/* nothin here now..... */ /* nothin here now..... */
} }
@ -297,11 +295,10 @@ ibmopen()
{ {
scinit(CDSENSE); scinit(CDSENSE);
revexist = TRUE; revexist = TRUE;
ttopen(); ttopen();
} }
ibmclose() ibmclose()
{ {
#if COLOR #if COLOR
ibmfcol(7); ibmfcol(7);
@ -318,19 +315,17 @@ ibmclose()
ttclose(); ttclose();
} }
ibmkopen() /* open the keyboard */ ibmkopen()
{ /* open the keyboard */
{
} }
ibmkclose() /* close the keyboard */ ibmkclose()
{ /* close the keyboard */
{
} }
scinit(type) /* initialize the screen head pointers */ scinit(type)
/* initialize the screen head pointers */
int type; /* type of adapter to init for */ int type; /* type of adapter to init for */
{ {
union { union {
@ -345,11 +340,11 @@ int type; /* type of adapter to init for */
/* if we have nothing to do....don't do it */ /* if we have nothing to do....don't do it */
if (dtype == type) if (dtype == type)
return(TRUE); return (TRUE);
/* if we try to switch to EGA and there is none, don't */ /* if we try to switch to EGA and there is none, don't */
if (type == CDEGA && egaexist != TRUE) if (type == CDEGA && egaexist != TRUE)
return(FALSE); return (FALSE);
/* if we had the EGA open... close it */ /* if we had the EGA open... close it */
if (dtype == CDEGA) if (dtype == CDEGA)
@ -361,26 +356,26 @@ int type; /* type of adapter to init for */
/* and set up the various parameters as needed */ /* and set up the various parameters as needed */
switch (type) { switch (type) {
case CDMONO: /* Monochrome adapter */ case CDMONO: /* Monochrome adapter */
scadd = SCADM; scadd = SCADM;
newsize(TRUE, 25); newsize(TRUE, 25);
break; break;
case CDCGA: /* Color graphics adapter */ case CDCGA: /* Color graphics adapter */
scadd = SCADC; scadd = SCADC;
newsize(TRUE, 25); newsize(TRUE, 25);
break; break;
case CDEGA: /* Enhanced graphics adapter */ case CDEGA: /* Enhanced graphics adapter */
scadd = SCADE; scadd = SCADE;
egaopen(); egaopen();
newsize(TRUE, 43); newsize(TRUE, 43);
break; break;
case CDVGA: /* Enhanced graphics adapter */ case CDVGA: /* Enhanced graphics adapter */
scadd = SCADE; scadd = SCADE;
egaopen(); egaopen();
newsize(TRUE, 50); newsize(TRUE, 50);
break; break;
} }
/* reset the $sres environment variable */ /* reset the $sres environment variable */
@ -389,10 +384,10 @@ int type; /* type of adapter to init for */
/* initialize the screen pointer array */ /* initialize the screen pointer array */
for (i = 0; i < NROW; i++) { for (i = 0; i < NROW; i++) {
addr.laddr = scadd + (long)(NCOL * i * 2); addr.laddr = scadd + (long) (NCOL * i * 2);
scptr[i] = addr.paddr; scptr[i] = addr.paddr;
} }
return(TRUE); return (TRUE);
} }
/* getboard: Determine which type of display board is attached. /* getboard: Determine which type of display board is attached.
@ -410,9 +405,8 @@ int type; /* type of adapter to init for */
*/ */
int getboard() int getboard()
{ {
int type; /* board type to return */ int type; /* board type to return */
type = CDCGA; type = CDCGA;
int86(0x11, &rg, &rg); int86(0x11, &rg, &rg);
@ -422,14 +416,13 @@ int getboard()
/* test if EGA present */ /* test if EGA present */
rg.x.ax = 0x1200; rg.x.ax = 0x1200;
rg.x.bx = 0xff10; rg.x.bx = 0xff10;
int86(0x10,&rg, &rg); /* If EGA, bh=0-1 and bl=0-3 */ int86(0x10, &rg, &rg); /* If EGA, bh=0-1 and bl=0-3 */
egaexist = !(rg.x.bx & 0xfefc); /* Yes, it's EGA */ egaexist = !(rg.x.bx & 0xfefc); /* Yes, it's EGA */
return(type); return (type);
} }
egaopen() /* init the computer to work with the EGA */ egaopen()
{ /* init the computer to work with the EGA */
{
/* put the beast into EGA 43 row mode */ /* put the beast into EGA 43 row mode */
rg.x.ax = 3; rg.x.ax = 3;
int86(16, &rg, &rg); int86(16, &rg, &rg);
@ -453,19 +446,18 @@ egaopen() /* init the computer to work with the EGA */
} }
egaclose() egaclose()
{ {
/* put the beast into 80 column mode */ /* put the beast into 80 column mode */
rg.x.ax = 3; rg.x.ax = 3;
int86(16, &rg, &rg); int86(16, &rg, &rg);
} }
scwrite(row, outstr, forg, bacg) /* write a line out*/ scwrite(row, outstr, forg, bacg)
/* write a line out */
int row; /* row of screen to place outstr on */ int row; /* row of screen to place outstr on */
char *outstr; /* string to write out (must be term.t_ncol long) */ char *outstr; /* string to write out (must be term.t_ncol long) */
int forg; /* forground color of string to write */ int forg; /* forground color of string to write */
int bacg; /* background color */ int bacg; /* background color */
{ {
unsigned int attr; /* attribute byte mask to place in RAM */ unsigned int attr; /* attribute byte mask to place in RAM */
@ -475,38 +467,38 @@ int bacg; /* background color */
/* build the attribute byte and setup the screen pointer */ /* build the attribute byte and setup the screen pointer */
#if COLOR #if COLOR
if (dtype != CDMONO) if (dtype != CDMONO)
attr = (((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) << 8; attr =
(((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) <<
8;
else else
attr = (((bacg & 15) << 4) | (forg & 15)) << 8; attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
#else #else
attr = (((bacg & 15) << 4) | (forg & 15)) << 8; attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
#endif #endif
lnptr = &sline[0]; lnptr = &sline[0];
for (i=0; i<term.t_ncol; i++) for (i = 0; i < term.t_ncol; i++)
*lnptr++ = (outstr[i] & 255) | attr; *lnptr++ = (outstr[i] & 255) | attr;
if (flickcode && (dtype == CDCGA)) { if (flickcode && (dtype == CDCGA)) {
/* wait for vertical retrace to be off */ /* wait for vertical retrace to be off */
while ((inp(0x3da) & 8)) while ((inp(0x3da) & 8));
;
/* and to be back on */ /* and to be back on */
while ((inp(0x3da) & 8) == 0) while ((inp(0x3da) & 8) == 0);
;
} }
/* and send the string out */ /* and send the string out */
movmem(&sline[0], scptr[row], term.t_ncol*2); movmem(&sline[0], scptr[row], term.t_ncol * 2);
} }
#if FNLABEL #if FNLABEL
fnclabel(f, n) /* label a function key */ fnclabel(f, n)
/* label a function key */
int f,n; /* default flag, numeric argument [unused] */ int f, n; /* default flag, numeric argument [unused] */
{ {
/* on machines with no function keys...don't bother */ /* on machines with no function keys...don't bother */
return(TRUE); return (TRUE);
} }
#endif #endif
#else #else
@ -514,4 +506,3 @@ ibmhello()
{ {
} }
#endif #endif

366
input.c
View File

@ -45,14 +45,14 @@ char *prompt;
/* get the responce */ /* get the responce */
c = tgetc(); c = tgetc();
if (c == ectoc(abortc)) /* Bail out! */ if (c == ectoc(abortc)) /* Bail out! */
return(ABORT); return (ABORT);
if (c=='y' || c=='Y') if (c == 'y' || c == 'Y')
return(TRUE); return (TRUE);
if (c=='n' || c=='N') if (c == 'n' || c == 'N')
return(FALSE); return (FALSE);
} }
} }
@ -65,10 +65,10 @@ char *prompt;
*/ */
mlreply(prompt, buf, nbuf) mlreply(prompt, buf, nbuf)
char *prompt; char *prompt;
char *buf; char *buf;
{ {
return(nextarg(prompt, buf, nbuf, ctoec('\n'))); return (nextarg(prompt, buf, nbuf, ctoec('\n')));
} }
mlreplyt(prompt, buf, nbuf, eolchar) mlreplyt(prompt, buf, nbuf, eolchar)
@ -78,7 +78,7 @@ char *buf;
int eolchar; int eolchar;
{ {
return(nextarg(prompt, buf, nbuf, eolchar)); return (nextarg(prompt, buf, nbuf, eolchar));
} }
/* ectoc: expanded character to character /* ectoc: expanded character to character
@ -92,8 +92,8 @@ int c;
if (c & CONTROL) if (c & CONTROL)
c = c & ~(CONTROL | 0x40); c = c & ~(CONTROL | 0x40);
if (c & SPEC) if (c & SPEC)
c= c & 255; c = c & 255;
return(c); return (c);
} }
/* ctoec: character to extended character /* ctoec: character to extended character
@ -104,18 +104,17 @@ ctoec(c)
int c; int c;
{ {
if (c>=0x00 && c<=0x1F) if (c >= 0x00 && c <= 0x1F)
c = CONTROL | (c+'@'); c = CONTROL | (c + '@');
return (c); return (c);
} }
/* get a command name from the command line. Command completion means /* get a command name from the command line. Command completion means
that pressing a <SPACE> will attempt to complete an unfinished command that pressing a <SPACE> will attempt to complete an unfinished command
name if it is unique. name if it is unique.
*/ */
int (*getname())() int (*getname()) ()
{ {
register int cpos; /* current column on screen output */ register int cpos; /* current column on screen output */
register int c; register int c;
@ -124,7 +123,7 @@ int (*getname())()
register NBIND *cffp; /* current ptr to entry in name binding table */ register NBIND *cffp; /* current ptr to entry in name binding table */
register NBIND *lffp; /* last ptr to entry in name binding table */ register NBIND *lffp; /* last ptr to entry in name binding table */
char buf[NSTRING]; /* buffer to hold tentative command name */ char buf[NSTRING]; /* buffer to hold tentative command name */
int (*fncmatch())(); int (*fncmatch()) ();
/* starting at the beginning of the string buffer */ /* starting at the beginning of the string buffer */
cpos = 0; cpos = 0;
@ -132,8 +131,8 @@ int (*getname())()
/* if we are executing a command line get the next arg and match it */ /* if we are executing a command line get the next arg and match it */
if (clexec) { if (clexec) {
if (macarg(buf) != TRUE) if (macarg(buf) != TRUE)
return(FALSE); return (FALSE);
return(fncmatch(&buf[0])); return (fncmatch(&buf[0]));
} }
/* build a name string from the keyboard */ /* build a name string from the keyboard */
@ -145,12 +144,12 @@ int (*getname())()
buf[cpos] = 0; buf[cpos] = 0;
/* and match it off */ /* and match it off */
return(fncmatch(&buf[0])); return (fncmatch(&buf[0]));
} else if (c == ectoc(abortc)) { /* Bell, abort */ } else if (c == ectoc(abortc)) { /* Bell, abort */
ctrlg(FALSE, 0); ctrlg(FALSE, 0);
TTflush(); TTflush();
return( (int (*)()) NULL); return ((int (*)()) NULL);
} else if (c == 0x7F || c == 0x08) { /* rubout/erase */ } else if (c == 0x7F || c == 0x08) { /* rubout/erase */
if (cpos != 0) { if (cpos != 0) {
@ -175,61 +174,80 @@ int (*getname())()
} else if (c == ' ' || c == 0x1b || c == 0x09) { } else if (c == ' ' || c == 0x1b || c == 0x09) {
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
/* attempt a completion */ /* attempt a completion */
buf[cpos] = 0; /* terminate it for us */ buf[cpos] = 0; /* terminate it for us */
ffp = &names[0]; /* scan for matches */ ffp = &names[0]; /* scan for matches */
while (ffp->n_func != NULL) { while (ffp->n_func != NULL) {
if (strncmp(buf, ffp->n_name, strlen(buf)) == 0) { if (strncmp(buf, ffp->n_name, strlen(buf))
/* a possible match! More than one? */ == 0) {
if ((ffp + 1)->n_func == NULL || /* a possible match! More than one? */
(strncmp(buf, (ffp+1)->n_name, strlen(buf)) != 0)) { if ((ffp + 1)->n_func == NULL ||
/* no...we match, print it */ (strncmp
sp = ffp->n_name + cpos; (buf, (ffp + 1)->n_name,
while (*sp) strlen(buf)) != 0)) {
TTputc(*sp++); /* no...we match, print it */
TTflush(); sp = ffp->n_name + cpos;
return(ffp->n_func); while (*sp)
} else { TTputc(*sp++);
TTflush();
return (ffp->n_func);
} else {
/* << << << << << << << << << << << << << << << << << */ /* << << << << << << << << << << << << << << << << << */
/* try for a partial match against the list */ /* try for a partial match against the list */
/* first scan down until we no longer match the current input */ /* first scan down until we no longer match the current input */
lffp = (ffp + 1); lffp = (ffp + 1);
while ((lffp+1)->n_func != NULL) { while ((lffp +
if (strncmp(buf, (lffp+1)->n_name, strlen(buf)) != 0) 1)->n_func !=
break; NULL) {
++lffp; if (strncmp
} (buf,
(lffp +
1)->n_name,
strlen(buf))
!= 0)
break;
++lffp;
}
/* and now, attempt to partial complete the string, char at a time */ /* and now, attempt to partial complete the string, char at a time */
while (TRUE) { while (TRUE) {
/* add the next char in */ /* add the next char in */
buf[cpos] = ffp->n_name[cpos]; buf[cpos] =
ffp->
n_name[cpos];
/* scan through the candidates */ /* scan through the candidates */
cffp = ffp + 1; cffp = ffp + 1;
while (cffp <= lffp) { while (cffp <=
if (cffp->n_name[cpos] != buf[cpos]) lffp) {
goto onward; if (cffp->
++cffp; n_name
} [cpos]
!=
buf
[cpos])
goto onward;
++cffp;
}
/* add the character */ /* add the character */
TTputc(buf[cpos++]); TTputc(buf
} [cpos++]);
}
/* << << << << << << << << << << << << << << << << << */ /* << << << << << << << << << << << << << << << << << */
}
}
++ffp;
} }
}
++ffp;
}
/* no match.....beep and onward */ /* no match.....beep and onward */
TTbeep(); TTbeep();
onward:; onward:;
TTflush(); TTflush();
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
} else { } else {
if (cpos < NSTRING-1 && c > ' ') { if (cpos < NSTRING - 1 && c > ' ') {
buf[cpos++] = c; buf[cpos++] = c;
TTputc(c); TTputc(c);
} }
@ -244,16 +262,15 @@ onward:;
macro action */ macro action */
int tgetc() int tgetc()
{ {
int c; /* fetched character */ int c; /* fetched character */
/* if we are playing a keyboard macro back, */ /* if we are playing a keyboard macro back, */
if (kbdmode == PLAY) { if (kbdmode == PLAY) {
/* if there is some left... */ /* if there is some left... */
if (kbdptr < kbdend) if (kbdptr < kbdend)
return((int)*kbdptr++); return ((int) *kbdptr++);
/* at the end of last repitition? */ /* at the end of last repitition? */
if (--kbdrep < 1) { if (--kbdrep < 1) {
@ -266,7 +283,7 @@ int tgetc()
/* reset the macro to the begining for the next rep */ /* reset the macro to the begining for the next rep */
kbdptr = &kbdm[0]; kbdptr = &kbdm[0];
return((int)*kbdptr++); return ((int) *kbdptr++);
} }
} }
@ -289,7 +306,7 @@ int tgetc()
} }
/* and finally give the char back */ /* and finally give the char back */
return(c); return (c);
} }
/* GET1KEY: Get one keystroke. The only prefixs legal here /* GET1KEY: Get one keystroke. The only prefixs legal here
@ -297,43 +314,41 @@ int tgetc()
*/ */
get1key() get1key()
{ {
int c; int c;
/* get a keystroke */ /* get a keystroke */
c = tgetc(); c = tgetc();
#if MSDOS #if MSDOS
if (c == 0) { /* Apply SPEC prefix */ if (c == 0) { /* Apply SPEC prefix */
c = tgetc(); c = tgetc();
if (c>=0x00 && c<=0x1F) /* control key? */ if (c >= 0x00 && c <= 0x1F) /* control key? */
c = CONTROL | (c+'@'); c = CONTROL | (c + '@');
return(SPEC | c); return (SPEC | c);
} }
#endif #endif
if (c>=0x00 && c<=0x1F) /* C0 control -> C- */ if (c >= 0x00 && c <= 0x1F) /* C0 control -> C- */
c = CONTROL | (c+'@'); c = CONTROL | (c + '@');
return (c); return (c);
} }
/* GETCMD: Get a command from the keyboard. Process all applicable /* GETCMD: Get a command from the keyboard. Process all applicable
prefix keys prefix keys
*/ */
getcmd() getcmd()
{ {
int c; /* fetched keystroke */ int c; /* fetched keystroke */
#if VT220 #if VT220
int d; /* second character P.K. */ int d; /* second character P.K. */
int cmask = 0; int cmask = 0;
#endif #endif
/* get initial character */ /* get initial character */
c = get1key(); c = get1key();
#if VT220 #if VT220
proc_metac: proc_metac:
#endif #endif
/* process META prefix */ /* process META prefix */
if (c == (CONTROL | '[')) { if (c == (CONTROL | '[')) {
@ -342,32 +357,35 @@ proc_metac:
if (c == '[' || c == 'O') { /* CSI P.K. */ if (c == '[' || c == 'O') { /* CSI P.K. */
c = get1key(); c = get1key();
if (c >= 'A' && c <= 'D') if (c >= 'A' && c <= 'D')
return(SPEC | c | cmask); return (SPEC | c | cmask);
if (c >= 'E' && c <= 'z' && c != 'i' && c != 'c') if (c >= 'E' && c <= 'z' && c != 'i' && c != 'c')
return(SPEC | c | cmask); return (SPEC | c | cmask);
d = get1key(); d = get1key();
if (d == '~') /* ESC [ n ~ P.K. */ if (d == '~') /* ESC [ n ~ P.K. */
return(SPEC | c | cmask); return (SPEC | c | cmask);
switch (c) { /* ESC [ n n ~ P.K. */ switch (c) { /* ESC [ n n ~ P.K. */
case '1': c = d + 32; case '1':
break; c = d + 32;
case '2': c = d + 48; break;
break; case '2':
case '3': c = d + 64; c = d + 48;
break; break;
default: c = '?'; case '3':
break; c = d + 64;
break;
default:
c = '?';
break;
} }
if (d != '~') /* eat tilde P.K. */ if (d != '~') /* eat tilde P.K. */
get1key(); get1key();
if (c == 'i') { /* DO key P.K. */ if (c == 'i') { /* DO key P.K. */
c = ctlxc; c = ctlxc;
goto proc_ctlxc; goto proc_ctlxc;
} } else if (c == 'c') /* ESC key P.K. */
else if (c == 'c') /* ESC key P.K. */
c = get1key(); c = get1key();
else else
return(SPEC | c | cmask); return (SPEC | c | cmask);
} }
#endif #endif
#if VT220 #if VT220
@ -376,15 +394,14 @@ proc_metac:
goto proc_metac; goto proc_metac;
} }
#endif #endif
if (islower(c)) /* Force to upper */ if (islower(c)) /* Force to upper */
c ^= DIFCASE; c ^= DIFCASE;
if (c>=0x00 && c<=0x1F) /* control key */ if (c >= 0x00 && c <= 0x1F) /* control key */
c = CONTROL | (c+'@'); c = CONTROL | (c + '@');
return(META | c ); return (META | c);
} }
#if PKCODE #if PKCODE
else else if (c == metac) {
if (c == metac) {
c = get1key(); c = get1key();
#if VT220 #if VT220
if (c == (CONTROL | '[')) { if (c == (CONTROL | '[')) {
@ -392,17 +409,17 @@ proc_metac:
goto proc_metac; goto proc_metac;
} }
#endif #endif
if (islower(c)) /* Force to upper */ if (islower(c)) /* Force to upper */
c ^= DIFCASE; c ^= DIFCASE;
if (c>=0x00 && c<=0x1F) /* control key */ if (c >= 0x00 && c <= 0x1F) /* control key */
c = CONTROL | (c+'@'); c = CONTROL | (c + '@');
return(META | c ); return (META | c);
} }
#endif #endif
#if VT220 #if VT220
proc_ctlxc: proc_ctlxc:
#endif #endif
/* process CTLX prefix */ /* process CTLX prefix */
if (c == ctlxc) { if (c == ctlxc) {
@ -413,15 +430,15 @@ proc_ctlxc:
goto proc_metac; goto proc_metac;
} }
#endif #endif
if (c>='a' && c<='z') /* Force to upper */ if (c >= 'a' && c <= 'z') /* Force to upper */
c -= 0x20; c -= 0x20;
if (c>=0x00 && c<=0x1F) /* control key */ if (c >= 0x00 && c <= 0x1F) /* control key */
c = CONTROL | (c+'@'); c = CONTROL | (c + '@');
return(CTLX | c); return (CTLX | c);
} }
/* otherwise, just return it */ /* otherwise, just return it */
return(c); return (c);
} }
/* A more generalized prompt/reply function allowing the caller /* A more generalized prompt/reply function allowing the caller
@ -430,7 +447,9 @@ proc_ctlxc:
*/ */
getstring(prompt, buf, nbuf, eolchar) getstring(prompt, buf, nbuf, eolchar)
char *prompt; char *buf; int eolchar; char *prompt;
char *buf;
int eolchar;
{ {
register int cpos; /* current character position in string */ register int cpos; /* current character position in string */
@ -447,11 +466,11 @@ char *prompt; char *buf; int eolchar;
FILE *tmpf = NULL; FILE *tmpf = NULL;
#endif #endif
ffile = (strcmp(prompt, "Find file: ") == 0 ffile = (strcmp(prompt, "Find file: ") == 0
|| strcmp(prompt, "View file: ") == 0 || strcmp(prompt, "View file: ") == 0
|| strcmp(prompt, "Insert file: ") == 0 || strcmp(prompt, "Insert file: ") == 0
|| strcmp(prompt, "Write file: ") == 0 || strcmp(prompt, "Write file: ") == 0
|| strcmp(prompt, "Read file: ") == 0 || strcmp(prompt, "Read file: ") == 0
|| strcmp(prompt, "File to execute: ") == 0); || strcmp(prompt, "File to execute: ") == 0);
#endif #endif
cpos = 0; cpos = 0;
@ -462,7 +481,7 @@ char *prompt; char *buf; int eolchar;
for (;;) { for (;;) {
#if COMPLC #if COMPLC
if (! didtry) if (!didtry)
nskip = -1; nskip = -1;
didtry = 0; didtry = 0;
#endif #endif
@ -487,9 +506,9 @@ char *prompt; char *buf; int eolchar;
/* if we default the buffer, return FALSE */ /* if we default the buffer, return FALSE */
if (buf[0] == 0) if (buf[0] == 0)
return(FALSE); return (FALSE);
return(TRUE); return (TRUE);
} }
/* change from command form back to character form */ /* change from command form back to character form */
@ -499,8 +518,8 @@ char *prompt; char *buf; int eolchar;
/* Abort the input? */ /* Abort the input? */
ctrlg(FALSE, 0); ctrlg(FALSE, 0);
TTflush(); TTflush();
return(ABORT); return (ABORT);
} else if ((c==0x7F || c==0x08) && quotef==FALSE) { } else if ((c == 0x7F || c == 0x08) && quotef == FALSE) {
/* rubout/erase */ /* rubout/erase */
if (cpos != 0) { if (cpos != 0) {
outstring("\b \b"); outstring("\b \b");
@ -536,7 +555,8 @@ char *prompt; char *buf; int eolchar;
TTflush(); TTflush();
#if COMPLC #if COMPLC
} else if ((c == 0x09 || c == ' ') && quotef == FALSE && ffile) { } else if ((c == 0x09 || c == ' ') && quotef == FALSE
&& ffile) {
/* TAB, complete file name */ /* TAB, complete file name */
char ffbuf[255]; char ffbuf[255];
#if MSDOS #if MSDOS
@ -563,14 +583,14 @@ char *prompt; char *buf; int eolchar;
iswild = 1; iswild = 1;
#if MSDOS #if MSDOS
if (lsav < 0 && (buf[cpos] == '\\' || if (lsav < 0 && (buf[cpos] == '\\' ||
buf[cpos] == '/' || buf[cpos] == '/' ||
buf[cpos] == ':' && cpos == 1)) buf[cpos] == ':'
&& cpos == 1))
lsav = cpos; lsav = cpos;
#endif #endif
} }
TTflush(); TTflush();
if (nskip < 0) if (nskip < 0) {
{
buf[ocpos] = 0; buf[ocpos] = 0;
#if UNIX #if UNIX
if (tmpf != NULL) if (tmpf != NULL)
@ -578,8 +598,8 @@ char *prompt; char *buf; int eolchar;
strcpy(tmp, "/tmp/meXXXXXX"); strcpy(tmp, "/tmp/meXXXXXX");
strcpy(ffbuf, "echo "); strcpy(ffbuf, "echo ");
strcat(ffbuf, buf); strcat(ffbuf, buf);
if (! iswild) if (!iswild)
strcat(ffbuf,"*"); strcat(ffbuf, "*");
strcat(ffbuf, " >"); strcat(ffbuf, " >");
mktemp(tmp); mktemp(tmp);
strcat(ffbuf, tmp); strcat(ffbuf, tmp);
@ -589,49 +609,47 @@ char *prompt; char *buf; int eolchar;
#endif #endif
#if MSDOS #if MSDOS
strcpy(sffbuf, buf); strcpy(sffbuf, buf);
if (! iswild) if (!iswild)
strcat(sffbuf,"*.*"); strcat(sffbuf, "*.*");
#endif #endif
nskip = 0; nskip = 0;
} }
#if UNIX #if UNIX
c = ' '; c = ' ';
for (n = nskip; n > 0; n--) for (n = nskip; n > 0; n--)
while ((c = getc(tmpf)) != EOF && c != ' '); while ((c = getc(tmpf)) != EOF
&& c != ' ');
#endif #endif
#if MSDOS #if MSDOS
if (nskip == 0) if (nskip == 0) {
{
strcpy(ffbuf, sffbuf); strcpy(ffbuf, sffbuf);
c = findfirst(ffbuf, &ffblk, FA_DIREC) ? '*' : ' '; c = findfirst(ffbuf, &ffblk,
} FA_DIREC) ? '*' : ' ';
else if (nskip > 0) } else if (nskip > 0)
c = findnext(&ffblk) ? 0 : ' '; c = findnext(&ffblk) ? 0 : ' ';
#endif #endif
nskip++; nskip++;
if (c != ' ') if (c != ' ') {
{
TTbeep(); TTbeep();
nskip = 0; nskip = 0;
} }
#if UNIX #if UNIX
while ((c = getc(tmpf)) != EOF && c != '\n' && c != ' ' && c != '*') while ((c = getc(tmpf)) != EOF && c != '\n'
&& c != ' ' && c != '*')
#endif #endif
#if MSDOS #if MSDOS
if (c == '*') if (c == '*')
fcp = sffbuf; fcp = sffbuf;
else else {
{ strncpy(buf, sffbuf, lsav + 1);
strncpy(buf, sffbuf, lsav+1); cpos = lsav + 1;
cpos = lsav+1; fcp = ffblk.ff_name;
fcp = ffblk.ff_name; }
}
while (c != 0 && (c = *fcp++) != 0 && c != '*') while (c != 0 && (c = *fcp++) != 0 && c != '*')
#endif #endif
{ {
if (cpos < nbuf-1) if (cpos < nbuf - 1)
buf[cpos++] = c; buf[cpos++] = c;
} }
#if UNIX #if UNIX
@ -639,8 +657,7 @@ char *prompt; char *buf; int eolchar;
TTbeep(); TTbeep();
#endif #endif
for (n = 0; n < cpos; n++) for (n = 0; n < cpos; n++) {
{
c = buf[n]; c = buf[n];
if ((c < ' ') && (c != '\n')) { if ((c < ' ') && (c != '\n')) {
outstring("^"); outstring("^");
@ -668,7 +685,7 @@ char *prompt; char *buf; int eolchar;
quotef = TRUE; quotef = TRUE;
} else { } else {
quotef = FALSE; quotef = FALSE;
if (cpos < nbuf-1) { if (cpos < nbuf - 1) {
buf[cpos++] = c; buf[cpos++] = c;
if ((c < ' ') && (c != '\n')) { if ((c < ' ') && (c != '\n')) {
@ -691,9 +708,9 @@ char *prompt; char *buf; int eolchar;
} }
} }
outstring(s) /* output a string of characters */ outstring(s)
/* output a string of characters */
char *s; /* string to output */ char *s; /* string to output */
{ {
if (disinp) if (disinp)
@ -701,13 +718,12 @@ char *s; /* string to output */
TTputc(*s++); TTputc(*s++);
} }
ostring(s) /* output a string of output characters */ ostring(s)
/* output a string of output characters */
char *s; /* string to output */ char *s; /* string to output */
{ {
if (discmd) if (discmd)
while (*s) while (*s)
TTputc(*s++); TTputc(*s++);
} }

597
isearch.c
View File

@ -28,51 +28,51 @@
#if ISRCH #if ISRCH
extern int scanner(); /* Handy search routine */ extern int scanner(); /* Handy search routine */
extern int eq(); /* Compare chars, match case */ extern int eq(); /* Compare chars, match case */
/* A couple of "own" variables for re-eat */ /* A couple of "own" variables for re-eat */
int (*saved_get_char)(); /* Get character routine */ int (*saved_get_char) (); /* Get character routine */
int eaten_char = -1; /* Re-eaten char */ int eaten_char = -1; /* Re-eaten char */
/* A couple more "own" variables for the command string */ /* A couple more "own" variables for the command string */
int cmd_buff[CMDBUFLEN]; /* Save the command args here */ int cmd_buff[CMDBUFLEN]; /* Save the command args here */
int cmd_offset; /* Current offset into command buff */ int cmd_offset; /* Current offset into command buff */
int cmd_reexecute = -1; /* > 0 if re-executing command */ int cmd_reexecute = -1; /* > 0 if re-executing command */
/* /*
* Subroutine to do incremental reverse search. It actually uses the * Subroutine to do incremental reverse search. It actually uses the
* same code as the normal incremental search, as both can go both ways. * same code as the normal incremental search, as both can go both ways.
*/ */
int risearch(f, n) int risearch(f, n)
{ {
LINE *curline; /* Current line on entry */ LINE *curline; /* Current line on entry */
int curoff; /* Current offset on entry */ int curoff; /* Current offset on entry */
/* remember the initial . on entry: */ /* remember the initial . on entry: */
curline = curwp->w_dotp; /* Save the current line pointer */ curline = curwp->w_dotp; /* Save the current line pointer */
curoff = curwp->w_doto; /* Save the current offset */ curoff = curwp->w_doto; /* Save the current offset */
/* Make sure the search doesn't match where we already are: */ /* Make sure the search doesn't match where we already are: */
backchar(TRUE, 1); /* Back up a character */ backchar(TRUE, 1); /* Back up a character */
if (!(isearch(f, -n))) /* Call ISearch backwards */ if (!(isearch(f, -n))) { /* Call ISearch backwards *//* If error in search: */
{ /* If error in search: */ curwp->w_dotp = curline; /* Reset the line pointer */
curwp->w_dotp = curline; /* Reset the line pointer */ curwp->w_doto = curoff; /* and the offset to original value */
curwp->w_doto = curoff; /* and the offset to original value */ curwp->w_flag |= WFMOVE; /* Say we've moved */
curwp->w_flag |= WFMOVE; /* Say we've moved */ update(FALSE); /* And force an update */
update(FALSE); /* And force an update */ mlwrite("(search failed)"); /* Say we died */
mlwrite ("(search failed)"); /* Say we died */
#if PKCODE #if PKCODE
matchlen = strlen(pat); matchlen = strlen(pat);
#endif #endif
} else mlerase (); /* If happy, just erase the cmd line */ } else
mlerase(); /* If happy, just erase the cmd line */
#if PKCODE #if PKCODE
matchlen = strlen(pat); matchlen = strlen(pat);
#endif #endif
@ -82,27 +82,27 @@ int risearch(f, n)
int fisearch(f, n) int fisearch(f, n)
{ {
LINE *curline; /* Current line on entry */ LINE *curline; /* Current line on entry */
int curoff; /* Current offset on entry */ int curoff; /* Current offset on entry */
/* remember the initial . on entry: */ /* remember the initial . on entry: */
curline = curwp->w_dotp; /* Save the current line pointer */ curline = curwp->w_dotp; /* Save the current line pointer */
curoff = curwp->w_doto; /* Save the current offset */ curoff = curwp->w_doto; /* Save the current offset */
/* do the search */ /* do the search */
if (!(isearch(f, n))) /* Call ISearch forwards */ if (!(isearch(f, n))) { /* Call ISearch forwards *//* If error in search: */
{ /* If error in search: */ curwp->w_dotp = curline; /* Reset the line pointer */
curwp->w_dotp = curline; /* Reset the line pointer */ curwp->w_doto = curoff; /* and the offset to original value */
curwp->w_doto = curoff; /* and the offset to original value */ curwp->w_flag |= WFMOVE; /* Say we've moved */
curwp->w_flag |= WFMOVE; /* Say we've moved */ update(FALSE); /* And force an update */
update(FALSE); /* And force an update */ mlwrite("(search failed)"); /* Say we died */
mlwrite ("(search failed)"); /* Say we died */
#if PKCODE #if PKCODE
matchlen = strlen(pat); matchlen = strlen(pat);
#endif #endif
} else mlerase (); /* If happy, just erase the cmd line */ } else
mlerase(); /* If happy, just erase the cmd line */
#if PKCODE #if PKCODE
matchlen = strlen(pat); matchlen = strlen(pat);
#endif #endif
@ -133,139 +133,131 @@ int fisearch(f, n)
* will stall until the pattern string is edited back into something that * will stall until the pattern string is edited back into something that
* exists (or until the search is aborted). * exists (or until the search is aborted).
*/ */
isearch(f, n) isearch(f, n)
{ {
int status; /* Search status */ int status; /* Search status */
int col; /* prompt column */ int col; /* prompt column */
register int cpos; /* character number in search string */ register int cpos; /* character number in search string */
register int c; /* current input character */ register int c; /* current input character */
register int expc; /* function expanded input char */ register int expc; /* function expanded input char */
char pat_save[NPAT]; /* Saved copy of the old pattern str */ char pat_save[NPAT]; /* Saved copy of the old pattern str */
LINE *curline; /* Current line on entry */ LINE *curline; /* Current line on entry */
int curoff; /* Current offset on entry */ int curoff; /* Current offset on entry */
int init_direction; /* The initial search direction */ int init_direction; /* The initial search direction */
/* Initialize starting conditions */ /* Initialize starting conditions */
cmd_reexecute = -1; /* We're not re-executing (yet?) */ cmd_reexecute = -1; /* We're not re-executing (yet?) */
cmd_offset = 0; /* Start at the beginning of the buff */ cmd_offset = 0; /* Start at the beginning of the buff */
cmd_buff[0] = '\0'; /* Init the command buffer */ cmd_buff[0] = '\0'; /* Init the command buffer */
strncpy (pat_save, pat, NPAT); /* Save the old pattern string */ strncpy(pat_save, pat, NPAT); /* Save the old pattern string */
curline = curwp->w_dotp; /* Save the current line pointer */ curline = curwp->w_dotp; /* Save the current line pointer */
curoff = curwp->w_doto; /* Save the current offset */ curoff = curwp->w_doto; /* Save the current offset */
init_direction = n; /* Save the initial search direction */ init_direction = n; /* Save the initial search direction */
/* This is a good place to start a re-execution: */ /* This is a good place to start a re-execution: */
start_over: start_over:
/* ask the user for the text of a pattern */ /* ask the user for the text of a pattern */
col = promptpattern("ISearch: "); /* Prompt, remember the col */ col = promptpattern("ISearch: "); /* Prompt, remember the col */
cpos = 0; /* Start afresh */ cpos = 0; /* Start afresh */
status = TRUE; /* Assume everything's cool */ status = TRUE; /* Assume everything's cool */
/* /*
Get the first character in the pattern. If we get an initial Control-S Get the first character in the pattern. If we get an initial Control-S
or Control-R, re-use the old search string and find the first occurrence or Control-R, re-use the old search string and find the first occurrence
*/ */
c = ectoc(expc = get_char()); /* Get the first character */ c = ectoc(expc = get_char()); /* Get the first character */
if ((c == IS_FORWARD) || if ((c == IS_FORWARD) || (c == IS_REVERSE) || (c == IS_VMSFORW)) { /* Reuse old search string? */
(c == IS_REVERSE) || for (cpos = 0; pat[cpos] != 0; cpos++) /* Yup, find the length */
(c == IS_VMSFORW)) /* Reuse old search string? */ col = echochar(pat[cpos], col); /* and re-echo the string */
{ if (c == IS_REVERSE) { /* forward search? */
for (cpos = 0; pat[cpos] != 0; cpos++) /* Yup, find the length */ n = -1; /* No, search in reverse */
col = echochar(pat[cpos],col); /* and re-echo the string */ backchar(TRUE, 1); /* Be defensive about EOB */
if (c == IS_REVERSE) { /* forward search? */ } else
n = -1; /* No, search in reverse */ n = 1; /* Yes, search forward */
backchar (TRUE, 1); /* Be defensive about EOB */ status = scanmore(pat, n); /* Do the search */
} else c = ectoc(expc = get_char()); /* Get another character */
n = 1; /* Yes, search forward */
status = scanmore(pat, n); /* Do the search */
c = ectoc(expc = get_char()); /* Get another character */
}
/* Top of the per character loop */
for (;;) /* ISearch per character loop */
{
/* Check for special characters first: */
/* Most cases here change the search */
if (expc == metac) /* Want to quit searching? */
return (TRUE); /* Quit searching now */
switch (c) /* dispatch on the input char */
{
case IS_ABORT: /* If abort search request */
return(FALSE); /* Quit searching again */
case IS_REVERSE: /* If backward search */
case IS_FORWARD: /* If forward search */
case IS_VMSFORW: /* of either flavor */
if (c == IS_REVERSE) /* If reverse search */
n = -1; /* Set the reverse direction */
else /* Otherwise, */
n = 1; /* go forward */
status = scanmore(pat, n); /* Start the search again */
c = ectoc(expc = get_char()); /* Get the next char */
continue; /* Go continue with the search*/
case IS_NEWLINE: /* Carriage return */
c = '\n'; /* Make it a new line */
break; /* Make sure we use it */
case IS_QUOTE: /* Quote character */
case IS_VMSQUOTE: /* of either variety */
c = ectoc(expc = get_char()); /* Get the next char */
case IS_TAB: /* Generically allowed */
case '\n': /* controlled characters */
break; /* Make sure we use it */
case IS_BACKSP: /* If a backspace: */
case IS_RUBOUT: /* or if a Rubout: */
if (cmd_offset <= 1) /* Anything to delete? */
return (TRUE); /* No, just exit */
--cmd_offset; /* Back up over the Rubout */
cmd_buff[--cmd_offset] = '\0'; /* Yes, delete last char */
curwp->w_dotp = curline; /* Reset the line pointer */
curwp->w_doto = curoff; /* and the offset */
n = init_direction; /* Reset the search direction */
strncpy (pat, pat_save, NPAT); /* Restore the old search str */
cmd_reexecute = 0; /* Start the whole mess over */
goto start_over; /* Let it take care of itself */
/* Presumably a quasi-normal character comes here */
default: /* All other chars */
if (c < ' ') /* Is it printable? */
{ /* Nope. */
reeat (c); /* Re-eat the char */
return (TRUE); /* And return the last status */
}
} /* Switch */
/* I guess we got something to search for, so search for it */
pat[cpos++] = c; /* put the char in the buffer */
if (cpos >= NPAT) /* too many chars in string? */
{ /* Yup. Complain about it */
mlwrite("? Search string too long");
return(TRUE); /* Return an error */
} }
pat[cpos] = 0; /* null terminate the buffer */
col = echochar(c,col); /* Echo the character */ /* Top of the per character loop */
if (!status) { /* If we lost last time */
TTputc(BELL); /* Feep again */ for (;;) { /* ISearch per character loop */
TTflush(); /* see that the feep feeps */ /* Check for special characters first: */
} else /* Otherwise, we must have won*/ /* Most cases here change the search */
if (!(status = checknext(c, pat, n))) /* See if match */
status = scanmore(pat, n); /* or find the next match */ if (expc == metac) /* Want to quit searching? */
c = ectoc(expc = get_char()); /* Get the next char */ return (TRUE); /* Quit searching now */
} /* for {;;} */
switch (c) { /* dispatch on the input char */
case IS_ABORT: /* If abort search request */
return (FALSE); /* Quit searching again */
case IS_REVERSE: /* If backward search */
case IS_FORWARD: /* If forward search */
case IS_VMSFORW: /* of either flavor */
if (c == IS_REVERSE) /* If reverse search */
n = -1; /* Set the reverse direction */
else /* Otherwise, */
n = 1; /* go forward */
status = scanmore(pat, n); /* Start the search again */
c = ectoc(expc = get_char()); /* Get the next char */
continue; /* Go continue with the search */
case IS_NEWLINE: /* Carriage return */
c = '\n'; /* Make it a new line */
break; /* Make sure we use it */
case IS_QUOTE: /* Quote character */
case IS_VMSQUOTE: /* of either variety */
c = ectoc(expc = get_char()); /* Get the next char */
case IS_TAB: /* Generically allowed */
case '\n': /* controlled characters */
break; /* Make sure we use it */
case IS_BACKSP: /* If a backspace: */
case IS_RUBOUT: /* or if a Rubout: */
if (cmd_offset <= 1) /* Anything to delete? */
return (TRUE); /* No, just exit */
--cmd_offset; /* Back up over the Rubout */
cmd_buff[--cmd_offset] = '\0'; /* Yes, delete last char */
curwp->w_dotp = curline; /* Reset the line pointer */
curwp->w_doto = curoff; /* and the offset */
n = init_direction; /* Reset the search direction */
strncpy(pat, pat_save, NPAT); /* Restore the old search str */
cmd_reexecute = 0; /* Start the whole mess over */
goto start_over; /* Let it take care of itself */
/* Presumably a quasi-normal character comes here */
default: /* All other chars */
if (c < ' ') { /* Is it printable? *//* Nope. */
reeat(c); /* Re-eat the char */
return (TRUE); /* And return the last status */
}
} /* Switch */
/* I guess we got something to search for, so search for it */
pat[cpos++] = c; /* put the char in the buffer */
if (cpos >= NPAT) { /* too many chars in string? *//* Yup. Complain about it */
mlwrite("? Search string too long");
return (TRUE); /* Return an error */
}
pat[cpos] = 0; /* null terminate the buffer */
col = echochar(c, col); /* Echo the character */
if (!status) { /* If we lost last time */
TTputc(BELL); /* Feep again */
TTflush(); /* see that the feep feeps */
} else /* Otherwise, we must have won */ if (!(status = checknext(c, pat, n))) /* See if match */
status = scanmore(pat, n); /* or find the next match */
c = ectoc(expc = get_char()); /* Get the next char */
} /* for {;;} */
} }
/* /*
@ -279,42 +271,39 @@ start_over:
* scanmore or something. * scanmore or something.
*/ */
int checknext (chr, patrn, dir) /* Check next character in search string */ int checknext(chr, patrn, dir) /* Check next character in search string */
char chr; /* Next char to look for */ char chr; /* Next char to look for */
char *patrn; /* The entire search string (incl chr) */ char *patrn; /* The entire search string (incl chr) */
int dir; /* Search direction */ int dir; /* Search direction */
{ {
register LINE *curline; /* current line during scan */ register LINE *curline; /* current line during scan */
register int curoff; /* position within current line */ register int curoff; /* position within current line */
register int buffchar; /* character at current position */ register int buffchar; /* character at current position */
int status; /* how well things go */ int status; /* how well things go */
/* setup the local scan pointer to current "." */ /* setup the local scan pointer to current "." */
curline = curwp->w_dotp; /* Get the current line structure */ curline = curwp->w_dotp; /* Get the current line structure */
curoff = curwp->w_doto; /* Get the offset within that line */ curoff = curwp->w_doto; /* Get the offset within that line */
if (dir > 0) /* If searching forward */ if (dir > 0) { /* If searching forward */
{ if (curoff == llength(curline)) { /* If at end of line */
if (curoff == llength(curline)) /* If at end of line */ curline = lforw(curline); /* Skip to the next line */
{ if (curline == curbp->b_linep)
curline = lforw(curline); /* Skip to the next line */ return (FALSE); /* Abort if at end of buffer */
if (curline == curbp->b_linep) curoff = 0; /* Start at the beginning of the line */
return (FALSE); /* Abort if at end of buffer */ buffchar = '\n'; /* And say the next char is NL */
curoff = 0; /* Start at the beginning of the line */ } else
buffchar = '\n'; /* And say the next char is NL */ buffchar = lgetc(curline, curoff++); /* Get the next char */
} else if (status = eq(buffchar, chr)) { /* Is it what we're looking for? */
buffchar = lgetc(curline, curoff++); /* Get the next char */ curwp->w_dotp = curline; /* Yes, set the buffer's point */
if (status = eq(buffchar, chr)) /* Is it what we're looking for? */ curwp->w_doto = curoff; /* to the matched character */
{ curwp->w_flag |= WFMOVE; /* Say that we've moved */
curwp->w_dotp = curline; /* Yes, set the buffer's point */ }
curwp->w_doto = curoff; /* to the matched character */ return (status); /* And return the status */
curwp->w_flag |= WFMOVE; /* Say that we've moved */ } else /* Else, if reverse search: */
} return (match_pat(patrn)); /* See if we're in the right place */
return (status); /* And return the status */
} else /* Else, if reverse search: */
return (match_pat (patrn)); /* See if we're in the right place */
} }
/* /*
@ -326,28 +315,25 @@ int dir; /* Search direction */
* forward searches and at the beginning of the matched string for reverse * forward searches and at the beginning of the matched string for reverse
* searches. * searches.
*/ */
int scanmore(patrn, dir) /* search forward or back for a pattern */
char *patrn; /* string to scan for */
int dir; /* direction to search */
{
int sts; /* search status */
if (dir < 0) /* reverse search? */ int scanmore(patrn, dir) /* search forward or back for a pattern */
{ char *patrn; /* string to scan for */
rvstrcpy(tap, patrn); /* Put reversed string in tap */ int dir; /* direction to search */
{
int sts; /* search status */
if (dir < 0) { /* reverse search? */
rvstrcpy(tap, patrn); /* Put reversed string in tap */
sts = scanner(tap, REVERSE, PTBEG); sts = scanner(tap, REVERSE, PTBEG);
} } else
else
sts = scanner(patrn, FORWARD, PTEND); /* Nope. Go forward */ sts = scanner(patrn, FORWARD, PTEND); /* Nope. Go forward */
if (!sts) if (!sts) {
{
TTputc(BELL); /* Feep if search fails */ TTputc(BELL); /* Feep if search fails */
TTflush(); /* see that the feep feeps */ TTflush(); /* see that the feep feeps */
} }
return(sts); /* else, don't even try */ return (sts); /* else, don't even try */
} }
/* /*
@ -360,36 +346,34 @@ int dir; /* direction to search */
* be done is match the last char input. * be done is match the last char input.
*/ */
int match_pat (patrn) /* See if the pattern string matches string at "." */ int match_pat(patrn) /* See if the pattern string matches string at "." */
char *patrn; /* String to match to buffer */ char *patrn; /* String to match to buffer */
{ {
register int i; /* Generic loop index/offset */ register int i; /* Generic loop index/offset */
register int buffchar; /* character at current position */ register int buffchar; /* character at current position */
register LINE *curline; /* current line during scan */ register LINE *curline; /* current line during scan */
register int curoff; /* position within current line */ register int curoff; /* position within current line */
/* setup the local scan pointer to current "." */ /* setup the local scan pointer to current "." */
curline = curwp->w_dotp; /* Get the current line structure */ curline = curwp->w_dotp; /* Get the current line structure */
curoff = curwp->w_doto; /* Get the offset within that line */ curoff = curwp->w_doto; /* Get the offset within that line */
/* top of per character compare loop: */ /* top of per character compare loop: */
for (i = 0; i < strlen(patrn); i++) /* Loop for all characters in patrn */ for (i = 0; i < strlen(patrn); i++) { /* Loop for all characters in patrn */
{ if (curoff == llength(curline)) { /* If at end of line */
if (curoff == llength(curline)) /* If at end of line */ curline = lforw(curline); /* Skip to the next line */
{ curoff = 0; /* Start at the beginning of the line */
curline = lforw(curline); /* Skip to the next line */ if (curline == curbp->b_linep)
curoff = 0; /* Start at the beginning of the line */ return (FALSE); /* Abort if at end of buffer */
if (curline == curbp->b_linep) buffchar = '\n'; /* And say the next char is NL */
return (FALSE); /* Abort if at end of buffer */ } else
buffchar = '\n'; /* And say the next char is NL */ buffchar = lgetc(curline, curoff++); /* Get the next char */
} else if (!eq(buffchar, patrn[i])) /* Is it what we're looking for? */
buffchar = lgetc(curline, curoff++); /* Get the next char */ return (FALSE); /* Nope, just punt it then */
if (!eq(buffchar, patrn[i])) /* Is it what we're looking for? */ }
return (FALSE); /* Nope, just punt it then */ return (TRUE); /* Everything matched? Let's celebrate */
}
return (TRUE); /* Everything matched? Let's celebrate*/
} }
/* Routine to prompt for I-Search string. */ /* Routine to prompt for I-Search string. */
@ -397,63 +381,61 @@ char *patrn; /* String to match to buffer */
int promptpattern(prompt) int promptpattern(prompt)
char *prompt; char *prompt;
{ {
char tpat[NPAT+20]; char tpat[NPAT + 20];
strcpy(tpat, prompt); /* copy prompt to output string */ strcpy(tpat, prompt); /* copy prompt to output string */
strcat(tpat, " ("); /* build new prompt string */ strcat(tpat, " ("); /* build new prompt string */
expandp(pat, &tpat[strlen(tpat)], NPAT/2); /* add old pattern */ expandp(pat, &tpat[strlen(tpat)], NPAT / 2); /* add old pattern */
strcat(tpat, ")<Meta>: "); strcat(tpat, ")<Meta>: ");
/* check to see if we are executing a command line */ /* check to see if we are executing a command line */
if (!clexec) { if (!clexec) {
mlwrite(tpat); mlwrite(tpat);
} }
return(strlen(tpat)); return (strlen(tpat));
} }
/* routine to echo i-search characters */ /* routine to echo i-search characters */
int echochar(c,col) int echochar(c, col)
int c; /* character to be echoed */ int c; /* character to be echoed */
int col; /* column to be echoed in */ int col; /* column to be echoed in */
{ {
movecursor(term.t_nrow,col); /* Position the cursor */ movecursor(term.t_nrow, col); /* Position the cursor */
if ((c < ' ') || (c == 0x7F)) /* Control character? */ if ((c < ' ') || (c == 0x7F)) { /* Control character? */
{ switch (c) { /* Yes, dispatch special cases */
switch (c) /* Yes, dispatch special cases*/ case '\n': /* Newline */
{ TTputc('<');
case '\n': /* Newline */ TTputc('N');
TTputc('<'); TTputc('L');
TTputc('N'); TTputc('>');
TTputc('L'); col += 3;
TTputc('>'); break;
col += 3;
break;
case '\t': /* Tab */ case '\t': /* Tab */
TTputc('<'); TTputc('<');
TTputc('T'); TTputc('T');
TTputc('A'); TTputc('A');
TTputc('B'); TTputc('B');
TTputc('>'); TTputc('>');
col += 4; col += 4;
break; break;
case 0x7F: /* Rubout: */ case 0x7F: /* Rubout: */
TTputc('^'); /* Output a funny looking */ TTputc('^'); /* Output a funny looking */
TTputc('?'); /* indication of Rubout */ TTputc('?'); /* indication of Rubout */
col++; /* Count the extra char */ col++; /* Count the extra char */
break; break;
default: /* Vanilla control char */ default: /* Vanilla control char */
TTputc('^'); /* Yes, output prefix */ TTputc('^'); /* Yes, output prefix */
TTputc(c+0x40); /* Make it "^X" */ TTputc(c + 0x40); /* Make it "^X" */
col++; /* Count this char */ col++; /* Count this char */
} }
} else } else
TTputc(c); /* Otherwise, output raw char */ TTputc(c); /* Otherwise, output raw char */
TTflush(); /* Flush the output */ TTflush(); /* Flush the output */
return(++col); /* return the new column no */ return (++col); /* return the new column no */
} }
/* /*
@ -463,29 +445,28 @@ int col; /* column to be echoed in */
* next character. * next character.
*/ */
int get_char () int get_char()
{ {
int c; /* A place to get a character */ int c; /* A place to get a character */
/* See if we're re-executing: */ /* See if we're re-executing: */
if (cmd_reexecute >= 0) /* Is there an offset? */ if (cmd_reexecute >= 0) /* Is there an offset? */
if ((c = cmd_buff[cmd_reexecute++]) != 0) if ((c = cmd_buff[cmd_reexecute++]) != 0)
return (c); /* Yes, return any character */ return (c); /* Yes, return any character */
/* We're not re-executing (or aren't any more). Try for a real char */ /* We're not re-executing (or aren't any more). Try for a real char */
cmd_reexecute = -1; /* Say we're in real mode again */ cmd_reexecute = -1; /* Say we're in real mode again */
update(FALSE); /* Pretty up the screen */ update(FALSE); /* Pretty up the screen */
if (cmd_offset >= CMDBUFLEN-1) /* If we're getting too big ... */ if (cmd_offset >= CMDBUFLEN - 1) { /* If we're getting too big ... */
{ mlwrite("? command too long"); /* Complain loudly and bitterly */
mlwrite ("? command too long"); /* Complain loudly and bitterly */ return (metac); /* And force a quit */
return (metac); /* And force a quit */ }
} c = get1key(); /* Get the next character */
c = get1key(); /* Get the next character */ cmd_buff[cmd_offset++] = c; /* Save the char for next time */
cmd_buff[cmd_offset++] = c; /* Save the char for next time */ cmd_buff[cmd_offset] = '\0'; /* And terminate the buffer */
cmd_buff[cmd_offset] = '\0';/* And terminate the buffer */ return (c); /* Return the character */
return (c); /* Return the character */
} }
/* /*
@ -497,22 +478,22 @@ int get_char ()
int uneat() int uneat()
{ {
int c; int c;
term.t_getchar = saved_get_char; /* restore the routine address */ term.t_getchar = saved_get_char; /* restore the routine address */
c = eaten_char; /* Get the re-eaten char */ c = eaten_char; /* Get the re-eaten char */
eaten_char = -1; /* Clear the old char */ eaten_char = -1; /* Clear the old char */
return(c); /* and return the last char */ return (c); /* and return the last char */
} }
int reeat(c) int reeat(c)
int c; int c;
{ {
if (eaten_char != -1) /* If we've already been here */ if (eaten_char != -1) /* If we've already been here */
return/*(NULL)*/; /* Don't do it again */ return /*(NULL) */ ; /* Don't do it again */
eaten_char = c; /* Else, save the char for later */ eaten_char = c; /* Else, save the char for later */
saved_get_char = term.t_getchar; /* Save the char get routine */ saved_get_char = term.t_getchar; /* Save the char get routine */
term.t_getchar = uneat; /* Replace it with ours */ term.t_getchar = uneat; /* Replace it with ours */
} }
#else #else
isearch() isearch()

256
line.c
View File

@ -17,8 +17,8 @@
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "edef.h"
KILL *ykbuf; /* ptr to current kill buffer chunk being yanked */ KILL *ykbuf; /* ptr to current kill buffer chunk being yanked */
int ykboff; /* offset into that chunk */ int ykboff; /* offset into that chunk */
/* /*
* This routine allocates a block of memory large enough to hold a LINE * This routine allocates a block of memory large enough to hold a LINE
@ -28,17 +28,17 @@ int ykboff; /* offset into that chunk */
*/ */
LINE *lalloc(used) LINE *lalloc(used)
register int used; register int used;
{ {
register LINE *lp; register LINE *lp;
register int size; register int size;
char *malloc(); char *malloc();
size = (used+NBLOCK-1) & ~(NBLOCK-1); size = (used + NBLOCK - 1) & ~(NBLOCK - 1);
if (size == 0) /* Assume that an empty */ if (size == 0) /* Assume that an empty */
size = NBLOCK; /* line is for type-in. */ size = NBLOCK; /* line is for type-in. */
if ((lp = (LINE *) malloc(sizeof(LINE)+size)) == NULL) { if ((lp = (LINE *) malloc(sizeof(LINE) + size)) == NULL) {
mlwrite("(OUT OF MEMORY)"); mlwrite("(OUT OF MEMORY)");
return (NULL); return (NULL);
} }
@ -54,7 +54,7 @@ register int used;
* conditions described in the above comments don't hold here. * conditions described in the above comments don't hold here.
*/ */
lfree(lp) lfree(lp)
register LINE *lp; register LINE *lp;
{ {
register BUFFER *bp; register BUFFER *bp;
register WINDOW *wp; register WINDOW *wp;
@ -63,9 +63,9 @@ register LINE *lp;
while (wp != NULL) { while (wp != NULL) {
if (wp->w_linep == lp) if (wp->w_linep == lp)
wp->w_linep = lp->l_fp; wp->w_linep = lp->l_fp;
if (wp->w_dotp == lp) { if (wp->w_dotp == lp) {
wp->w_dotp = lp->l_fp; wp->w_dotp = lp->l_fp;
wp->w_doto = 0; wp->w_doto = 0;
} }
if (wp->w_markp == lp) { if (wp->w_markp == lp) {
wp->w_markp = lp->l_fp; wp->w_markp = lp->l_fp;
@ -76,7 +76,7 @@ register LINE *lp;
bp = bheadp; bp = bheadp;
while (bp != NULL) { while (bp != NULL) {
if (bp->b_nwnd == 0) { if (bp->b_nwnd == 0) {
if (bp->b_dotp == lp) { if (bp->b_dotp == lp) {
bp->b_dotp = lp->l_fp; bp->b_dotp = lp->l_fp;
bp->b_doto = 0; bp->b_doto = 0;
} }
@ -100,14 +100,14 @@ register LINE *lp;
* mode line needs to be updated (the "*" has to be set). * mode line needs to be updated (the "*" has to be set).
*/ */
lchange(flag) lchange(flag)
register int flag; register int flag;
{ {
register WINDOW *wp; register WINDOW *wp;
if (curbp->b_nwnd != 1) /* Ensure hard. */ if (curbp->b_nwnd != 1) /* Ensure hard. */
flag = WFHARD; flag = WFHARD;
if ((curbp->b_flag&BFCHG) == 0) { /* First change, so */ if ((curbp->b_flag & BFCHG) == 0) { /* First change, so */
flag |= WFMODE; /* update mode lines. */ flag |= WFMODE; /* update mode lines. */
curbp->b_flag |= BFCHG; curbp->b_flag |= BFCHG;
} }
wp = wheadp; wp = wheadp;
@ -118,9 +118,9 @@ register int flag;
} }
} }
insspace(f, n) /* insert spaces forward into text */ insspace(f, n)
/* insert spaces forward into text */
int f, n; /* default flag and numeric argument */ int f, n; /* default flag and numeric argument */
{ {
linsert(n, ' '); linsert(n, ' ');
@ -132,14 +132,15 @@ int f, n; /* default flag and numeric argument */
*/ */
linstr(instr) linstr(instr)
char *instr; char *instr;
{ {
register int status = TRUE; register int status = TRUE;
char tmpc; char tmpc;
if (instr != NULL) if (instr != NULL)
while ((tmpc = *instr) && status == TRUE) { while ((tmpc = *instr) && status == TRUE) {
status = (tmpc == '\n'? lnewline(): linsert(1, tmpc)); status =
(tmpc == '\n' ? lnewline() : linsert(1, tmpc));
/* Insertion error? */ /* Insertion error? */
if (status != TRUE) { if (status != TRUE) {
@ -148,7 +149,7 @@ char *instr;
} }
instr++; instr++;
} }
return(status); return (status);
} }
/* /*
@ -163,40 +164,40 @@ char *instr;
linsert(n, c) linsert(n, c)
{ {
register char *cp1; register char *cp1;
register char *cp2; register char *cp2;
register LINE *lp1; register LINE *lp1;
register LINE *lp2; register LINE *lp2;
register LINE *lp3; register LINE *lp3;
register int doto; register int doto;
register int i; register int i;
register WINDOW *wp; register WINDOW *wp;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
lchange(WFEDIT); lchange(WFEDIT);
lp1 = curwp->w_dotp; /* Current line */ lp1 = curwp->w_dotp; /* Current line */
if (lp1 == curbp->b_linep) { /* At the end: special */ if (lp1 == curbp->b_linep) { /* At the end: special */
if (curwp->w_doto != 0) { if (curwp->w_doto != 0) {
mlwrite("bug: linsert"); mlwrite("bug: linsert");
return (FALSE); return (FALSE);
} }
if ((lp2=lalloc(n)) == NULL) /* Allocate new line */ if ((lp2 = lalloc(n)) == NULL) /* Allocate new line */
return (FALSE); return (FALSE);
lp3 = lp1->l_bp; /* Previous line */ lp3 = lp1->l_bp; /* Previous line */
lp3->l_fp = lp2; /* Link in */ lp3->l_fp = lp2; /* Link in */
lp2->l_fp = lp1; lp2->l_fp = lp1;
lp1->l_bp = lp2; lp1->l_bp = lp2;
lp2->l_bp = lp3; lp2->l_bp = lp3;
for (i=0; i<n; ++i) for (i = 0; i < n; ++i)
lp2->l_text[i] = c; lp2->l_text[i] = c;
curwp->w_dotp = lp2; curwp->w_dotp = lp2;
curwp->w_doto = n; curwp->w_doto = n;
return (TRUE); return (TRUE);
} }
doto = curwp->w_doto; /* Save for later. */ doto = curwp->w_doto; /* Save for later. */
if (lp1->l_used+n > lp1->l_size) { /* Hard: reallocate */ if (lp1->l_used + n > lp1->l_size) { /* Hard: reallocate */
if ((lp2=lalloc(lp1->l_used+n)) == NULL) if ((lp2 = lalloc(lp1->l_used + n)) == NULL)
return (FALSE); return (FALSE);
cp1 = &lp1->l_text[0]; cp1 = &lp1->l_text[0];
cp2 = &lp2->l_text[0]; cp2 = &lp2->l_text[0];
@ -210,23 +211,23 @@ linsert(n, c)
lp1->l_fp->l_bp = lp2; lp1->l_fp->l_bp = lp2;
lp2->l_bp = lp1->l_bp; lp2->l_bp = lp1->l_bp;
free((char *) lp1); free((char *) lp1);
} else { /* Easy: in place */ } else { /* Easy: in place */
lp2 = lp1; /* Pretend new line */ lp2 = lp1; /* Pretend new line */
lp2->l_used += n; lp2->l_used += n;
cp2 = &lp1->l_text[lp1->l_used]; cp2 = &lp1->l_text[lp1->l_used];
cp1 = cp2-n; cp1 = cp2 - n;
while (cp1 != &lp1->l_text[doto]) while (cp1 != &lp1->l_text[doto])
*--cp2 = *--cp1; *--cp2 = *--cp1;
} }
for (i=0; i<n; ++i) /* Add the characters */ for (i = 0; i < n; ++i) /* Add the characters */
lp2->l_text[doto+i] = c; lp2->l_text[doto + i] = c;
wp = wheadp; /* Update windows */ wp = wheadp; /* Update windows */
while (wp != NULL) { while (wp != NULL) {
if (wp->w_linep == lp1) if (wp->w_linep == lp1)
wp->w_linep = lp2; wp->w_linep = lp2;
if (wp->w_dotp == lp1) { if (wp->w_dotp == lp1) {
wp->w_dotp = lp2; wp->w_dotp = lp2;
if (wp==curwp || wp->w_doto>doto) if (wp == curwp || wp->w_doto > doto)
wp->w_doto += n; wp->w_doto += n;
} }
if (wp->w_markp == lp1) { if (wp->w_markp == lp1) {
@ -246,14 +247,14 @@ linsert(n, c)
lowrite(c) lowrite(c)
char c; /* character to overwrite on current position */ char c; /* character to overwrite on current position */
{ {
if (curwp->w_doto < curwp->w_dotp->l_used && if (curwp->w_doto < curwp->w_dotp->l_used &&
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' || (lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
((curwp->w_doto) & tabmask) == tabmask)) ((curwp->w_doto) & tabmask) == tabmask))
ldelete(1L, FALSE); ldelete(1L, FALSE);
return(linsert(1, c)); return (linsert(1, c));
} }
/* /*
@ -262,7 +263,7 @@ char c; /* character to overwrite on current position */
lover(ostr) lover(ostr)
char *ostr; char *ostr;
{ {
register int status = TRUE; register int status = TRUE;
@ -270,16 +271,18 @@ char *ostr;
if (ostr != NULL) if (ostr != NULL)
while ((tmpc = *ostr) && status == TRUE) { while ((tmpc = *ostr) && status == TRUE) {
status = (tmpc == '\n'? lnewline(): lowrite(tmpc)); status =
(tmpc == '\n' ? lnewline() : lowrite(tmpc));
/* Insertion error? */ /* Insertion error? */
if (status != TRUE) { if (status != TRUE) {
mlwrite("%%Out of memory while overwriting"); mlwrite
("%%Out of memory while overwriting");
break; break;
} }
ostr++; ostr++;
} }
return(status); return (status);
} }
/* /*
@ -292,25 +295,25 @@ char *ostr;
*/ */
lnewline() lnewline()
{ {
register char *cp1; register char *cp1;
register char *cp2; register char *cp2;
register LINE *lp1; register LINE *lp1;
register LINE *lp2; register LINE *lp2;
register int doto; register int doto;
register WINDOW *wp; register WINDOW *wp;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
#if SCROLLCODE #if SCROLLCODE
lchange(WFHARD|WFINS); lchange(WFHARD | WFINS);
#else #else
lchange(WFHARD); lchange(WFHARD);
#endif #endif
lp1 = curwp->w_dotp; /* Get the address and */ lp1 = curwp->w_dotp; /* Get the address and */
doto = curwp->w_doto; /* offset of "." */ doto = curwp->w_doto; /* offset of "." */
if ((lp2=lalloc(doto)) == NULL) /* New first half line */ if ((lp2 = lalloc(doto)) == NULL) /* New first half line */
return (FALSE); return (FALSE);
cp1 = &lp1->l_text[0]; /* Shuffle text around */ cp1 = &lp1->l_text[0]; /* Shuffle text around */
cp2 = &lp2->l_text[0]; cp2 = &lp2->l_text[0];
while (cp1 != &lp1->l_text[doto]) while (cp1 != &lp1->l_text[doto])
*cp2++ = *cp1++; *cp2++ = *cp1++;
@ -322,7 +325,7 @@ lnewline()
lp1->l_bp = lp2; lp1->l_bp = lp2;
lp2->l_bp->l_fp = lp2; lp2->l_bp->l_fp = lp2;
lp2->l_fp = lp1; lp2->l_fp = lp1;
wp = wheadp; /* Windows */ wp = wheadp; /* Windows */
while (wp != NULL) { while (wp != NULL) {
if (wp->w_linep == lp1) if (wp->w_linep == lp1)
wp->w_linep = lp2; wp->w_linep = lp2;
@ -351,43 +354,43 @@ lnewline()
*/ */
ldelete(n, kflag) ldelete(n, kflag)
long n; /* # of chars to delete */ long n; /* # of chars to delete */
int kflag; /* put killed text in kill buffer flag */ int kflag; /* put killed text in kill buffer flag */
{ {
register char *cp1; register char *cp1;
register char *cp2; register char *cp2;
register LINE *dotp; register LINE *dotp;
register int doto; register int doto;
register int chunk; register int chunk;
register WINDOW *wp; register WINDOW *wp;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
while (n != 0) { while (n != 0) {
dotp = curwp->w_dotp; dotp = curwp->w_dotp;
doto = curwp->w_doto; doto = curwp->w_doto;
if (dotp == curbp->b_linep) /* Hit end of buffer. */ if (dotp == curbp->b_linep) /* Hit end of buffer. */
return (FALSE); return (FALSE);
chunk = dotp->l_used-doto; /* Size of chunk. */ chunk = dotp->l_used - doto; /* Size of chunk. */
if (chunk > n) if (chunk > n)
chunk = n; chunk = n;
if (chunk == 0) { /* End of line, merge. */ if (chunk == 0) { /* End of line, merge. */
#if SCROLLCODE #if SCROLLCODE
lchange(WFHARD|WFKILLS); lchange(WFHARD | WFKILLS);
#else #else
lchange(WFHARD); lchange(WFHARD);
#endif #endif
if (ldelnewline() == FALSE if (ldelnewline() == FALSE
|| (kflag!=FALSE && kinsert('\n')==FALSE)) || (kflag != FALSE && kinsert('\n') == FALSE))
return (FALSE); return (FALSE);
--n; --n;
continue; continue;
} }
lchange(WFEDIT); lchange(WFEDIT);
cp1 = &dotp->l_text[doto]; /* Scrunch text. */ cp1 = &dotp->l_text[doto]; /* Scrunch text. */
cp2 = cp1 + chunk; cp2 = cp1 + chunk;
if (kflag != FALSE) { /* Kill? */ if (kflag != FALSE) { /* Kill? */
while (cp1 != cp2) { while (cp1 != cp2) {
if (kinsert(*cp1) == FALSE) if (kinsert(*cp1) == FALSE)
return (FALSE); return (FALSE);
@ -398,14 +401,14 @@ int kflag; /* put killed text in kill buffer flag */
while (cp2 != &dotp->l_text[dotp->l_used]) while (cp2 != &dotp->l_text[dotp->l_used])
*cp1++ = *cp2++; *cp1++ = *cp2++;
dotp->l_used -= chunk; dotp->l_used -= chunk;
wp = wheadp; /* Fix windows */ wp = wheadp; /* Fix windows */
while (wp != NULL) { while (wp != NULL) {
if (wp->w_dotp==dotp && wp->w_doto>=doto) { if (wp->w_dotp == dotp && wp->w_doto >= doto) {
wp->w_doto -= chunk; wp->w_doto -= chunk;
if (wp->w_doto < doto) if (wp->w_doto < doto)
wp->w_doto = doto; wp->w_doto = doto;
} }
if (wp->w_markp==dotp && wp->w_marko>=doto) { if (wp->w_markp == dotp && wp->w_marko >= doto) {
wp->w_marko -= chunk; wp->w_marko -= chunk;
if (wp->w_marko < doto) if (wp->w_marko < doto)
wp->w_marko = doto; wp->w_marko = doto;
@ -422,7 +425,6 @@ int kflag; /* put killed text in kill buffer flag */
*/ */
char *getctext() char *getctext()
{ {
register LINE *lp; /* line to copy */ register LINE *lp; /* line to copy */
register int size; /* length of line to return */ register int size; /* length of line to return */
@ -442,14 +444,14 @@ char *getctext()
while (size--) while (size--)
*dp++ = *sp++; *dp++ = *sp++;
*dp = 0; *dp = 0;
return(rline); return (rline);
} }
/* putctext: replace the current line with the passed in text */ /* putctext: replace the current line with the passed in text */
putctext(iline) putctext(iline)
char *iline; /* contents of new line */ char *iline; /* contents of new line */
{ {
register int status; register int status;
@ -457,14 +459,14 @@ char *iline; /* contents of new line */
/* delete the current line */ /* delete the current line */
curwp->w_doto = 0; /* starting at the beginning of the line */ curwp->w_doto = 0; /* starting at the beginning of the line */
if ((status = killtext(TRUE, 1)) != TRUE) if ((status = killtext(TRUE, 1)) != TRUE)
return(status); return (status);
/* insert the new line */ /* insert the new line */
if ((status = linstr(iline)) != TRUE) if ((status = linstr(iline)) != TRUE)
return(status); return (status);
status = lnewline(); status = lnewline();
backline(TRUE, 1); backline(TRUE, 1);
return(status); return (status);
} }
/* /*
@ -478,23 +480,23 @@ char *iline; /* contents of new line */
*/ */
ldelnewline() ldelnewline()
{ {
register char *cp1; register char *cp1;
register char *cp2; register char *cp2;
register LINE *lp1; register LINE *lp1;
register LINE *lp2; register LINE *lp2;
register LINE *lp3; register LINE *lp3;
register WINDOW *wp; register WINDOW *wp;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
lp1 = curwp->w_dotp; lp1 = curwp->w_dotp;
lp2 = lp1->l_fp; lp2 = lp1->l_fp;
if (lp2 == curbp->b_linep) { /* At the buffer end. */ if (lp2 == curbp->b_linep) { /* At the buffer end. */
if (lp1->l_used == 0) /* Blank line. */ if (lp1->l_used == 0) /* Blank line. */
lfree(lp1); lfree(lp1);
return (TRUE); return (TRUE);
} }
if (lp2->l_used <= lp1->l_size-lp1->l_used) { if (lp2->l_used <= lp1->l_size - lp1->l_used) {
cp1 = &lp1->l_text[lp1->l_used]; cp1 = &lp1->l_text[lp1->l_used];
cp2 = &lp2->l_text[0]; cp2 = &lp2->l_text[0];
while (cp2 != &lp2->l_text[lp2->l_used]) while (cp2 != &lp2->l_text[lp2->l_used])
@ -504,11 +506,11 @@ ldelnewline()
if (wp->w_linep == lp2) if (wp->w_linep == lp2)
wp->w_linep = lp1; wp->w_linep = lp1;
if (wp->w_dotp == lp2) { if (wp->w_dotp == lp2) {
wp->w_dotp = lp1; wp->w_dotp = lp1;
wp->w_doto += lp1->l_used; wp->w_doto += lp1->l_used;
} }
if (wp->w_markp == lp2) { if (wp->w_markp == lp2) {
wp->w_markp = lp1; wp->w_markp = lp1;
wp->w_marko += lp1->l_used; wp->w_marko += lp1->l_used;
} }
wp = wp->w_wndp; wp = wp->w_wndp;
@ -519,7 +521,7 @@ ldelnewline()
free((char *) lp2); free((char *) lp2);
return (TRUE); return (TRUE);
} }
if ((lp3=lalloc(lp1->l_used+lp2->l_used)) == NULL) if ((lp3 = lalloc(lp1->l_used + lp2->l_used)) == NULL)
return (FALSE); return (FALSE);
cp1 = &lp1->l_text[0]; cp1 = &lp1->l_text[0];
cp2 = &lp3->l_text[0]; cp2 = &lp3->l_text[0];
@ -534,18 +536,18 @@ ldelnewline()
lp3->l_bp = lp1->l_bp; lp3->l_bp = lp1->l_bp;
wp = wheadp; wp = wheadp;
while (wp != NULL) { while (wp != NULL) {
if (wp->w_linep==lp1 || wp->w_linep==lp2) if (wp->w_linep == lp1 || wp->w_linep == lp2)
wp->w_linep = lp3; wp->w_linep = lp3;
if (wp->w_dotp == lp1) if (wp->w_dotp == lp1)
wp->w_dotp = lp3; wp->w_dotp = lp3;
else if (wp->w_dotp == lp2) { else if (wp->w_dotp == lp2) {
wp->w_dotp = lp3; wp->w_dotp = lp3;
wp->w_doto += lp1->l_used; wp->w_doto += lp1->l_used;
} }
if (wp->w_markp == lp1) if (wp->w_markp == lp1)
wp->w_markp = lp3; wp->w_markp = lp3;
else if (wp->w_markp == lp2) { else if (wp->w_markp == lp2) {
wp->w_markp = lp3; wp->w_markp = lp3;
wp->w_marko += lp1->l_used; wp->w_marko += lp1->l_used;
} }
wp = wp->w_wndp; wp = wp->w_wndp;
@ -562,7 +564,7 @@ ldelnewline()
*/ */
kdelete() kdelete()
{ {
KILL *kp; /* ptr to scan kill buffer chunk list */ KILL *kp; /* ptr to scan kill buffer chunk list */
if (kbufh != NULL) { if (kbufh != NULL) {
@ -576,7 +578,7 @@ kdelete()
/* and reset all the kill buffer pointers */ /* and reset all the kill buffer pointers */
kbufh = kbufp = NULL; kbufh = kbufp = NULL;
kused = KBLOCK; kused = KBLOCK;
} }
} }
@ -587,15 +589,15 @@ kdelete()
kinsert(c) kinsert(c)
int c; /* character to insert in the kill buffer */ int c; /* character to insert in the kill buffer */
{ {
KILL *nchunk; /* ptr to newly malloced chunk */ KILL *nchunk; /* ptr to newly malloced chunk */
/* check to see if we need a new chunk */ /* check to see if we need a new chunk */
if (kused >= KBLOCK) { if (kused >= KBLOCK) {
if ((nchunk = (KILL *)malloc(sizeof(KILL))) == NULL) if ((nchunk = (KILL *) malloc(sizeof(KILL))) == NULL)
return(FALSE); return (FALSE);
if (kbufh == NULL) /* set head ptr if first time */ if (kbufh == NULL) /* set head ptr if first time */
kbufh = nchunk; kbufh = nchunk;
if (kbufp != NULL) /* point the current to this new one */ if (kbufp != NULL) /* point the current to this new one */
@ -607,7 +609,7 @@ int c; /* character to insert in the kill buffer */
/* and now insert the character */ /* and now insert the character */
kbufp->d_chunk[kused++] = c; kbufp->d_chunk[kused++] = c;
return(TRUE); return (TRUE);
} }
/* /*
@ -617,18 +619,18 @@ int c; /* character to insert in the kill buffer */
*/ */
yank(f, n) yank(f, n)
{ {
register int c; register int c;
register int i; register int i;
register char *sp; /* pointer into string to insert */ register char *sp; /* pointer into string to insert */
KILL *kp; /* pointer into kill buffer */ KILL *kp; /* pointer into kill buffer */
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
if (n < 0) if (n < 0)
return (FALSE); return (FALSE);
/* make sure there is something to yank */ /* make sure there is something to yank */
if (kbufh == NULL) if (kbufh == NULL)
return(TRUE); /* not an error, just nothing */ return (TRUE); /* not an error, just nothing */
/* for each time.... */ /* for each time.... */
while (n--) { while (n--) {

59
lock.c
View File

@ -16,14 +16,14 @@
extern int sys_nerr; /* number of system error messages defined */ extern int sys_nerr; /* number of system error messages defined */
extern int errno; /* current error */ extern int errno; /* current error */
char *lname[NLOCKS]; /* names of all locked files */ char *lname[NLOCKS]; /* names of all locked files */
int numlocks; /* # of current locks active */ int numlocks; /* # of current locks active */
/* lockchk: check a file for locking and add it to the list */ /* lockchk: check a file for locking and add it to the list */
lockchk(fname) lockchk(fname)
char *fname; /* file to check for a lock */ char *fname; /* file to check for a lock */
{ {
register int i; /* loop indexes */ register int i; /* loop indexes */
@ -32,41 +32,40 @@ char *fname; /* file to check for a lock */
/* check to see if that file is already locked here */ /* check to see if that file is already locked here */
if (numlocks > 0) if (numlocks > 0)
for (i=0; i < numlocks; ++i) for (i = 0; i < numlocks; ++i)
if (strcmp(fname, lname[i]) == 0) if (strcmp(fname, lname[i]) == 0)
return(TRUE); return (TRUE);
/* if we have a full locking table, bitch and leave */ /* if we have a full locking table, bitch and leave */
if (numlocks == NLOCKS) { if (numlocks == NLOCKS) {
mlwrite("LOCK ERROR: Lock table full"); mlwrite("LOCK ERROR: Lock table full");
return(ABORT); return (ABORT);
} }
/* next, try to lock it */ /* next, try to lock it */
status = lock(fname); status = lock(fname);
if (status == ABORT) /* file is locked, no override */ if (status == ABORT) /* file is locked, no override */
return(ABORT); return (ABORT);
if (status == FALSE) /* locked, overriden, dont add to table */ if (status == FALSE) /* locked, overriden, dont add to table */
return(TRUE); return (TRUE);
/* we have now locked it, add it to our table */ /* we have now locked it, add it to our table */
lname[++numlocks - 1] = (char *)malloc(strlen(fname) + 1); lname[++numlocks - 1] = (char *) malloc(strlen(fname) + 1);
if (lname[numlocks - 1] == NULL) { /* malloc failure */ if (lname[numlocks - 1] == NULL) { /* malloc failure */
undolock(fname); /* free the lock */ undolock(fname); /* free the lock */
mlwrite("Cannot lock, out of memory"); mlwrite("Cannot lock, out of memory");
--numlocks; --numlocks;
return(ABORT); return (ABORT);
} }
/* everthing is cool, add it to the table */ /* everthing is cool, add it to the table */
strcpy(lname[numlocks-1], fname); strcpy(lname[numlocks - 1], fname);
return(TRUE); return (TRUE);
} }
/* lockrel: release all the file locks so others may edit */ /* lockrel: release all the file locks so others may edit */
lockrel() lockrel()
{ {
register int i; /* loop index */ register int i; /* loop index */
register int status; /* status of locks */ register int status; /* status of locks */
@ -74,13 +73,13 @@ lockrel()
status = TRUE; status = TRUE;
if (numlocks > 0) if (numlocks > 0)
for (i=0; i < numlocks; ++i) { for (i = 0; i < numlocks; ++i) {
if ((s = unlock(lname[i])) != TRUE) if ((s = unlock(lname[i])) != TRUE)
status = s; status = s;
free(lname[i]); free(lname[i]);
} }
numlocks = 0; numlocks = 0;
return(status); return (status);
} }
/* lock: Check and lock a file from access by others /* lock: Check and lock a file from access by others
@ -91,7 +90,7 @@ lockrel()
lock(fname) lock(fname)
char *fname; /* file name to lock */ char *fname; /* file name to lock */
{ {
register char *locker; /* lock error message */ register char *locker; /* lock error message */
@ -102,23 +101,23 @@ char *fname; /* file name to lock */
/* attempt to lock the file */ /* attempt to lock the file */
locker = dolock(fname); locker = dolock(fname);
if (locker == NULL) /* we win */ if (locker == NULL) /* we win */
return(TRUE); return (TRUE);
/* file failed...abort */ /* file failed...abort */
if (strncmp(locker, "LOCK", 4) == 0) { if (strncmp(locker, "LOCK", 4) == 0) {
lckerror(locker); lckerror(locker);
return(ABORT); return (ABORT);
} }
/* someone else has it....override? */ /* someone else has it....override? */
strcpy(msg, "File in use by "); strcpy(msg, "File in use by ");
strcat(msg, locker); strcat(msg, locker);
strcat(msg, ", override?"); strcat(msg, ", override?");
status = mlyesno(msg); /* ask them */ status = mlyesno(msg); /* ask them */
if (status == TRUE) if (status == TRUE)
return(FALSE); return (FALSE);
else else
return(ABORT); return (ABORT);
} }
/* unlock: Unlock a file /* unlock: Unlock a file
@ -127,7 +126,7 @@ char *fname; /* file name to lock */
unlock(fname) unlock(fname)
char *fname; /* file to unlock */ char *fname; /* file to unlock */
{ {
register char *locker; /* undolock return string */ register char *locker; /* undolock return string */
@ -136,16 +135,16 @@ char *fname; /* file to unlock */
/* unclock and return */ /* unclock and return */
locker = undolock(fname); locker = undolock(fname);
if (locker == NULL) if (locker == NULL)
return(TRUE); return (TRUE);
/* report the error and come back */ /* report the error and come back */
lckerror(locker); lckerror(locker);
return(FALSE); return (FALSE);
} }
lckerror(errstr) /* report a lock error */ lckerror(errstr)
/* report a lock error */
char *errstr; /* lock error string to print out */ char *errstr; /* lock error string to print out */
{ {
char obuf[NSTRING]; /* output buffer for error message */ char obuf[NSTRING]; /* output buffer for error message */
@ -160,7 +159,7 @@ char *errstr; /* lock error string to print out */
} }
#endif #endif
#else #else
lckhello() /* dummy function */ lckhello()
{ { /* dummy function */
} }
#endif #endif

597
main.c
View File

@ -57,7 +57,7 @@
#define maindef #define maindef
#include "estruct.h" /* global structures and defines */ #include "estruct.h" /* global structures and defines */
#include "efunc.h" /* function declarations and name table */ #include "efunc.h" /* function declarations and name table */
#include "edef.h" /* global definitions */ #include "edef.h" /* global definitions */
#include "ebind.h" /* default key bindings */ #include "ebind.h" /* default key bindings */
@ -84,7 +84,7 @@ extern unsigned _stklen = 32766;
#include <signal.h> #include <signal.h>
static void emergencyexit(); static void emergencyexit();
#ifdef SIGWINCH #ifdef SIGWINCH
extern void sizesignal(); extern void sizesignal();
#endif #endif
#endif #endif
@ -93,37 +93,37 @@ emacs(argc, argv)
#else #else
main(argc, argv) main(argc, argv)
#endif #endif
int argc; /* # of arguments */ int argc; /* # of arguments */
char *argv[]; /* argument strings */ char *argv[]; /* argument strings */
{ {
register int c; /* command character */ register int c; /* command character */
register int f; /* default flag */ register int f; /* default flag */
register int n; /* numeric repeat count */ register int n; /* numeric repeat count */
register int mflag; /* negative flag on repeat */ register int mflag; /* negative flag on repeat */
register BUFFER *bp; /* temp buffer pointer */ register BUFFER *bp; /* temp buffer pointer */
register int firstfile; /* first file flag */ register int firstfile; /* first file flag */
register int carg; /* current arg to scan */ register int carg; /* current arg to scan */
register int startflag; /* startup executed flag */ register int startflag; /* startup executed flag */
BUFFER *firstbp = NULL; /* ptr to first buffer in cmd line */ BUFFER *firstbp = NULL; /* ptr to first buffer in cmd line */
int basec; /* c stripped of meta character */ int basec; /* c stripped of meta character */
int viewflag; /* are we starting in view mode? */ int viewflag; /* are we starting in view mode? */
int gotoflag; /* do we need to goto a line at start? */ int gotoflag; /* do we need to goto a line at start? */
int gline; /* if so, what line? */ int gline; /* if so, what line? */
int searchflag; /* Do we need to search at start? */ int searchflag; /* Do we need to search at start? */
int saveflag; /* temp store for lastflag */ int saveflag; /* temp store for lastflag */
int errflag; /* C error processing? */ int errflag; /* C error processing? */
char bname[NBUFN]; /* buffer name of file to read */ char bname[NBUFN]; /* buffer name of file to read */
#if CRYPT #if CRYPT
int cryptflag; /* encrypting on the way in? */ int cryptflag; /* encrypting on the way in? */
char ekey[NPAT]; /* startup encryption key */ char ekey[NPAT]; /* startup encryption key */
#endif #endif
char *strncpy(); char *strncpy();
extern *pathname[]; /* startup file path/name array */ extern *pathname[]; /* startup file path/name array */
int newc; int newc;
#if PKCODE #if PKCODE
int (*getbind())(); int (*getbind()) ();
int (*execfunc)(); /* ptr to function to execute */ int (*execfunc) (); /* ptr to function to execute */
#endif #endif
#if PKCODE & VMS #if PKCODE & VMS
@ -141,8 +141,8 @@ char *argv[]; /* argument strings */
#endif #endif
/* initialize the editor */ /* initialize the editor */
vtinit(); /* Display */ vtinit(); /* Display */
edinit("main"); /* Buffers, windows */ edinit("main"); /* Buffers, windows */
varinit(); /* user variables */ varinit(); /* user variables */
viewflag = FALSE; /* view mode defaults off in command line */ viewflag = FALSE; /* view mode defaults off in command line */
@ -171,51 +171,51 @@ char *argv[]; /* argument strings */
if (argv[carg][0] == '-') { if (argv[carg][0] == '-') {
switch (argv[carg][1]) { switch (argv[carg][1]) {
/* Process Startup macroes */ /* Process Startup macroes */
case 'a': /* process error file */ case 'a': /* process error file */
case 'A': case 'A':
errflag = TRUE; errflag = TRUE;
break; break;
case 'e': /* -e for Edit file */ case 'e': /* -e for Edit file */
case 'E': case 'E':
viewflag = FALSE; viewflag = FALSE;
break; break;
case 'g': /* -g for initial goto */ case 'g': /* -g for initial goto */
case 'G': case 'G':
gotoflag = TRUE; gotoflag = TRUE;
gline = atoi(&argv[carg][2]); gline = atoi(&argv[carg][2]);
break; break;
#if CRYPT #if CRYPT
case 'k': /* -k<key> for code key */ case 'k': /* -k<key> for code key */
case 'K': case 'K':
cryptflag = TRUE; cryptflag = TRUE;
strcpy(ekey, &argv[carg][2]); strcpy(ekey, &argv[carg][2]);
break; break;
#endif #endif
#if PKCODE #if PKCODE
case 'n': /* -n accept null chars */ case 'n': /* -n accept null chars */
case 'N': case 'N':
nullflag = TRUE; nullflag = TRUE;
break; break;
#endif #endif
case 'r': /* -r restrictive use */ case 'r': /* -r restrictive use */
case 'R': case 'R':
restflag = TRUE; restflag = TRUE;
break; break;
case 's': /* -s for initial search string */ case 's': /* -s for initial search string */
case 'S': case 'S':
searchflag = TRUE; searchflag = TRUE;
strncpy(pat,&argv[carg][2],NPAT); strncpy(pat, &argv[carg][2], NPAT);
break; break;
case 'v': /* -v for View File */ case 'v': /* -v for View File */
case 'V': case 'V':
viewflag = TRUE; viewflag = TRUE;
break; break;
default: /* unknown switch */ default: /* unknown switch */
/* ignore this for now */ /* ignore this for now */
break; break;
} }
} else if (argv[carg][0]== '@') { } else if (argv[carg][0] == '@') {
/* Process Startup macroes */ /* Process Startup macroes */
if (startup(&argv[carg][1]) == TRUE) if (startup(&argv[carg][1]) == TRUE)
@ -227,7 +227,7 @@ char *argv[]; /* argument strings */
/* Process an input file */ /* Process an input file */
/* set up a buffer for this file */ /* set up a buffer for this file */
makename(bname, argv[carg]); makename(bname, argv[carg]);
unqname(bname); unqname(bname);
/* set this to inactive */ /* set this to inactive */
@ -245,7 +245,7 @@ char *argv[]; /* argument strings */
#if CRYPT #if CRYPT
if (cryptflag) { if (cryptflag) {
bp->b_mode |= MDCRYPT; bp->b_mode |= MDCRYPT;
crypt((char *)NULL, 0); crypt((char *) NULL, 0);
crypt(ekey, strlen(ekey)); crypt(ekey, strlen(ekey));
strncpy(bp->b_key, ekey, NPAT); strncpy(bp->b_key, ekey, NPAT);
} }
@ -254,7 +254,7 @@ char *argv[]; /* argument strings */
} }
#if UNIX #if UNIX
signal(SIGHUP, emergencyexit); signal(SIGHUP, emergencyexit);
signal(SIGTERM, emergencyexit); signal(SIGTERM, emergencyexit);
#endif #endif
@ -270,7 +270,7 @@ char *argv[]; /* argument strings */
startup(""); startup("");
startflag = TRUE; startflag = TRUE;
} }
discmd = TRUE; /* P.K. */ discmd = TRUE; /* P.K. */
/* if there are any files to read, read the first one! */ /* if there are any files to read, read the first one! */
bp = bfind("main", FALSE, 0); bp = bfind("main", FALSE, 0);
@ -280,85 +280,79 @@ char *argv[]; /* argument strings */
} else } else
bp->b_mode |= gmode; bp->b_mode |= gmode;
/* Deal with startup gotos and searches */ /* Deal with startup gotos and searches */
if (gotoflag && searchflag) { if (gotoflag && searchflag) {
update(FALSE); update(FALSE);
mlwrite("(Can not search and goto at the same time!)"); mlwrite("(Can not search and goto at the same time!)");
} } else if (gotoflag) {
else if (gotoflag) { if (gotoline(TRUE, gline) == FALSE) {
if (gotoline(TRUE,gline) == FALSE) { update(FALSE);
update(FALSE);
mlwrite("(Bogus goto argument)"); mlwrite("(Bogus goto argument)");
} }
} else if (searchflag) { } else if (searchflag) {
if (forwhunt(FALSE, 0) == FALSE) if (forwhunt(FALSE, 0) == FALSE)
update(FALSE); update(FALSE);
} }
/* setup to process commands */ /* setup to process commands */
lastflag = 0; /* Fake last flags. */ lastflag = 0; /* Fake last flags. */
loop: loop:
#if CALLED #if CALLED
/* if we were called as a subroutine and want to leave, do so */ /* if we were called as a subroutine and want to leave, do so */
if (eexitflag) if (eexitflag)
return(eexitval); return (eexitval);
#endif #endif
/* execute the "command" macro...normally null */ /* execute the "command" macro...normally null */
saveflag = lastflag; /* preserve lastflag through this */ saveflag = lastflag; /* preserve lastflag through this */
execute(META|SPEC|'C', FALSE, 1); execute(META | SPEC | 'C', FALSE, 1);
lastflag = saveflag; lastflag = saveflag;
#if TYPEAH && PKCODE #if TYPEAH && PKCODE
if (typahead()) if (typahead()) {
{
newc = getcmd(); newc = getcmd();
update(FALSE); update(FALSE);
do do {
{
if (c == newc && (execfunc = getbind(c)) != NULL if (c == newc && (execfunc = getbind(c)) != NULL
&& execfunc != newline && execfunc != newline && execfunc != tab)
&& execfunc != tab)
newc = getcmd(); newc = getcmd();
else else
break; break;
} while (typahead()); } while (typahead());
c = newc; c = newc;
} } else {
else
{
update(FALSE); update(FALSE);
c = getcmd(); c = getcmd();
} }
#else #else
/* Fix up the screen */ /* Fix up the screen */
update(FALSE); update(FALSE);
/* get the next command from the keyboard */ /* get the next command from the keyboard */
c = getcmd(); c = getcmd();
#endif #endif
/* if there is something on the command line, clear it */ /* if there is something on the command line, clear it */
if (mpresf != FALSE) { if (mpresf != FALSE) {
mlerase(); mlerase();
update(FALSE); update(FALSE);
#if CLRMSG #if CLRMSG
if (c == ' ') /* ITS EMACS does this */ if (c == ' ') /* ITS EMACS does this */
goto loop; goto loop;
#endif #endif
} }
f = FALSE; f = FALSE;
n = 1; n = 1;
/* do META-# processing if needed */ /* do META-# processing if needed */
basec = c & ~META; /* strip meta char off if there */ basec = c & ~META; /* strip meta char off if there */
if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) { if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) {
f = TRUE; /* there is a # arg */ f = TRUE; /* there is a # arg */
n = 0; /* start with a zero default */ n = 0; /* start with a zero default */
mflag = 1; /* current minus flag */ mflag = 1; /* current minus flag */
c = basec; /* strip the META */ c = basec; /* strip the META */
while ((c >= '0' && c <= '9') || (c == '-')) { while ((c >= '0' && c <= '9') || (c == '-')) {
if (c == '-') { if (c == '-') {
/* already hit a minus or digit? */ /* already hit a minus or digit? */
@ -371,7 +365,7 @@ loop:
if ((n == 0) && (mflag == -1)) /* lonely - */ if ((n == 0) && (mflag == -1)) /* lonely - */
mlwrite("Arg:"); mlwrite("Arg:");
else else
mlwrite("Arg: %d",n * mflag); mlwrite("Arg: %d", n * mflag);
c = getcmd(); /* get the next key */ c = getcmd(); /* get the next key */
} }
@ -380,54 +374,56 @@ loop:
/* do ^U repeat argument processing */ /* do ^U repeat argument processing */
if (c == reptc) { /* ^U, start argument */ if (c == reptc) { /* ^U, start argument */
f = TRUE; f = TRUE;
n = 4; /* with argument of 4 */ n = 4; /* with argument of 4 */
mflag = 0; /* that can be discarded. */ mflag = 0; /* that can be discarded. */
mlwrite("Arg: 4"); mlwrite("Arg: 4");
while ((c=getcmd()) >='0' && c<='9' || c==reptc || c=='-'){ while ((c = getcmd()) >= '0' && c <= '9' || c == reptc
if (c == reptc) || c == '-') {
if ((n > 0) == ((n*4) > 0)) if (c == reptc)
n = n*4; if ((n > 0) == ((n * 4) > 0))
else n = n * 4;
n = 1; else
/* n = 1;
* If dash, and start of argument string, set arg. /*
* to -1. Otherwise, insert it. * If dash, and start of argument string, set arg.
*/ * to -1. Otherwise, insert it.
else if (c == '-') { */
if (mflag) else if (c == '-') {
break; if (mflag)
n = 0; break;
mflag = -1; n = 0;
} mflag = -1;
/* }
* If first digit entered, replace previous argument /*
* with digit and set sign. Otherwise, append to arg. * If first digit entered, replace previous argument
*/ * with digit and set sign. Otherwise, append to arg.
else { */
if (!mflag) { else {
n = 0; if (!mflag) {
mflag = 1; n = 0;
} mflag = 1;
n = 10*n + c - '0'; }
} n = 10 * n + c - '0';
mlwrite("Arg: %d", (mflag >=0) ? n : (n ? -n : -1)); }
} mlwrite("Arg: %d",
/* (mflag >= 0) ? n : (n ? -n : -1));
* Make arguments preceded by a minus sign negative and change }
* the special argument "^U -" to an effective "^U -1". /*
*/ * Make arguments preceded by a minus sign negative and change
if (mflag == -1) { * the special argument "^U -" to an effective "^U -1".
if (n == 0) */
n++; if (mflag == -1) {
n = -n; if (n == 0)
} n++;
} n = -n;
}
}
/* and execute the command */ /* and execute the command */
execute(c, f, n); execute(c, f, n);
goto loop; goto loop;
} }
/* /*
@ -436,37 +432,37 @@ loop:
* file by default, and we want the buffer name to be right. * file by default, and we want the buffer name to be right.
*/ */
edinit(bname) edinit(bname)
char bname[]; char bname[];
{ {
register BUFFER *bp; register BUFFER *bp;
register WINDOW *wp; register WINDOW *wp;
char *malloc(); char *malloc();
bp = bfind(bname, TRUE, 0); /* First buffer */ bp = bfind(bname, TRUE, 0); /* First buffer */
blistp = bfind("*List*", TRUE, BFINVS); /* Buffer list buffer */ blistp = bfind("*List*", TRUE, BFINVS); /* Buffer list buffer */
wp = (WINDOW *) malloc(sizeof(WINDOW)); /* First window */ wp = (WINDOW *) malloc(sizeof(WINDOW)); /* First window */
if (bp==NULL || wp==NULL || blistp==NULL) if (bp == NULL || wp == NULL || blistp == NULL)
exit(1); exit(1);
curbp = bp; /* Make this current */ curbp = bp; /* Make this current */
wheadp = wp; wheadp = wp;
curwp = wp; curwp = wp;
wp->w_wndp = NULL; /* Initialize window */ wp->w_wndp = NULL; /* Initialize window */
wp->w_bufp = bp; wp->w_bufp = bp;
bp->b_nwnd = 1; /* Displayed. */ bp->b_nwnd = 1; /* Displayed. */
wp->w_linep = bp->b_linep; wp->w_linep = bp->b_linep;
wp->w_dotp = bp->b_linep; wp->w_dotp = bp->b_linep;
wp->w_doto = 0; wp->w_doto = 0;
wp->w_markp = NULL; wp->w_markp = NULL;
wp->w_marko = 0; wp->w_marko = 0;
wp->w_toprow = 0; wp->w_toprow = 0;
#if COLOR #if COLOR
/* initalize colors to global defaults */ /* initalize colors to global defaults */
wp->w_fcolor = gfcolor; wp->w_fcolor = gfcolor;
wp->w_bcolor = gbcolor; wp->w_bcolor = gbcolor;
#endif #endif
wp->w_ntrows = term.t_nrow-1; /* "-1" for mode line. */ wp->w_ntrows = term.t_nrow - 1; /* "-1" for mode line. */
wp->w_force = 0; wp->w_force = 0;
wp->w_flag = WFMODE|WFHARD; /* Full. */ wp->w_flag = WFMODE | WFHARD; /* Full. */
} }
/* /*
@ -477,70 +473,70 @@ char bname[];
*/ */
execute(c, f, n) execute(c, f, n)
{ {
register int status; register int status;
int (*execfunc)(); /* ptr to function to execute */ int (*execfunc) (); /* ptr to function to execute */
int (*getbind())(); int (*getbind()) ();
/* if the keystroke is a bound function...do it */ /* if the keystroke is a bound function...do it */
execfunc = getbind(c); execfunc = getbind(c);
if (execfunc != NULL) { if (execfunc != NULL) {
thisflag = 0; thisflag = 0;
status = (*execfunc)(f, n); status = (*execfunc) (f, n);
lastflag = thisflag; lastflag = thisflag;
return (status); return (status);
} }
/* /*
* If a space was typed, fill column is defined, the argument is non- * If a space was typed, fill column is defined, the argument is non-
* negative, wrap mode is enabled, and we are now past fill column, * negative, wrap mode is enabled, and we are now past fill column,
* and we are not read-only, perform word wrap. * and we are not read-only, perform word wrap.
*/ */
if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 && if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 &&
n >= 0 && getccol(FALSE) > fillcol && n >= 0 && getccol(FALSE) > fillcol &&
(curwp->w_bufp->b_mode & MDVIEW) == FALSE) (curwp->w_bufp->b_mode & MDVIEW) == FALSE)
execute(META|SPEC|'W', FALSE, 1); execute(META | SPEC | 'W', FALSE, 1);
#if PKCODE #if PKCODE
if ((c>=0x20 && c<=0x7E) /* Self inserting. */ if ((c >= 0x20 && c <= 0x7E) /* Self inserting. */
#if IBMPC #if IBMPC
|| (c>=0x80 && c<=0xFE)) { || (c >= 0x80 && c <= 0xFE)) {
#else #else
#if VMS || BSD || USG /* 8BIT P.K. */ #if VMS || BSD || USG /* 8BIT P.K. */
|| (c>=0xA0 && c<=0xFE)) { || (c >= 0xA0 && c <= 0xFE)) {
#else #else
) { ) {
#endif #endif
#endif #endif
#else #else
if ((c>=0x20 && c<=0xFF)) { /* Self inserting. */ if ((c >= 0x20 && c <= 0xFF)) { /* Self inserting. */
#endif #endif
if (n <= 0) { /* Fenceposts. */ if (n <= 0) { /* Fenceposts. */
lastflag = 0; lastflag = 0;
return (n<0 ? FALSE : TRUE); return (n < 0 ? FALSE : TRUE);
} }
thisflag = 0; /* For the future. */ thisflag = 0; /* For the future. */
/* if we are in overwrite mode, not at eol, /* if we are in overwrite mode, not at eol,
and next char is not a tab or we are at a tab stop, and next char is not a tab or we are at a tab stop,
delete a char forword */ delete a char forword */
if (curwp->w_bufp->b_mode & MDOVER && if (curwp->w_bufp->b_mode & MDOVER &&
curwp->w_doto < curwp->w_dotp->l_used && curwp->w_doto < curwp->w_dotp->l_used &&
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' || (lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
(curwp->w_doto) % 8 == 7)) (curwp->w_doto) % 8 == 7))
ldelete(1L, FALSE); ldelete(1L, FALSE);
/* do the appropriate insertion */ /* do the appropriate insertion */
if (c == '}' && (curbp->b_mode & MDCMOD) != 0) if (c == '}' && (curbp->b_mode & MDCMOD) != 0)
status = insbrace(n, c); status = insbrace(n, c);
else if (c == '#' && (curbp->b_mode & MDCMOD) != 0) else if (c == '#' && (curbp->b_mode & MDCMOD) != 0)
status = inspound(); status = inspound();
else else
status = linsert(n, c); status = linsert(n, c);
#if CFENCE #if CFENCE
/* check for CMODE fence matching */ /* check for CMODE fence matching */
if ((c == '}' || c == ')' || c == ']') && if ((c == '}' || c == ')' || c == ']') &&
(curbp->b_mode & MDCMOD) != 0) (curbp->b_mode & MDCMOD) != 0)
fmatch(c); fmatch(c);
#endif #endif
@ -553,13 +549,13 @@ execute(c, f, n)
gacount = gasave; gacount = gasave;
} }
lastflag = thisflag; lastflag = thisflag;
return (status); return (status);
} }
TTbeep(); TTbeep();
mlwrite("(Key not bound)"); /* complain */ mlwrite("(Key not bound)"); /* complain */
lastflag = 0; /* Fake last flags. */ lastflag = 0; /* Fake last flags. */
return (FALSE); return (FALSE);
} }
/* /*
@ -569,38 +565,38 @@ execute(c, f, n)
quickexit(f, n) quickexit(f, n)
{ {
register BUFFER *bp; /* scanning pointer to buffers */ register BUFFER *bp; /* scanning pointer to buffers */
register BUFFER *oldcb; /* original current buffer */ register BUFFER *oldcb; /* original current buffer */
register int status; register int status;
oldcb = curbp; /* save in case we fail */ oldcb = curbp; /* save in case we fail */
bp = bheadp; bp = bheadp;
while (bp != NULL) { while (bp != NULL) {
if ((bp->b_flag&BFCHG) != 0 /* Changed. */ if ((bp->b_flag & BFCHG) != 0 /* Changed. */
&& (bp->b_flag&BFTRUNC) == 0 /* Not truncated P.K. */ && (bp->b_flag & BFTRUNC) == 0 /* Not truncated P.K. */
&& (bp->b_flag&BFINVS) == 0) { /* Real. */ && (bp->b_flag & BFINVS) == 0) { /* Real. */
curbp = bp; /* make that buffer cur */ curbp = bp; /* make that buffer cur */
mlwrite("(Saving %s)",bp->b_fname); mlwrite("(Saving %s)", bp->b_fname);
#if PKCODE #if PKCODE
#else #else
mlwrite("\n"); mlwrite("\n");
#endif #endif
if ((status = filesave(f, n)) != TRUE) { if ((status = filesave(f, n)) != TRUE) {
curbp = oldcb; /* restore curbp */ curbp = oldcb; /* restore curbp */
return(status); return (status);
} }
} }
bp = bp->b_bufp; /* on to the next buffer */ bp = bp->b_bufp; /* on to the next buffer */
} }
quit(f, n); /* conditionally quit */ quit(f, n); /* conditionally quit */
return(TRUE); return (TRUE);
} }
static void emergencyexit(signr) static void emergencyexit(signr)
int signr; int signr;
{ {
quickexit(FALSE, 0); quickexit(FALSE, 0);
quit(TRUE, 0); quit(TRUE, 0);
} }
/* /*
@ -609,12 +605,13 @@ int signr;
*/ */
quit(f, n) quit(f, n)
{ {
register int s; register int s;
if (f != FALSE /* Argument forces it. */ if (f != FALSE /* Argument forces it. */
|| anycb() == FALSE /* All buffers clean. */ || anycb() == FALSE /* All buffers clean. */
/* User says it's OK. */ /* User says it's OK. */
|| (s=mlyesno("Modified buffers exist. Leave anyway")) == TRUE) { || (s =
mlyesno("Modified buffers exist. Leave anyway")) == TRUE) {
#if (FILOCK && BSD) || SVR4 #if (FILOCK && BSD) || SVR4
if (lockrel() != TRUE) { if (lockrel() != TRUE) {
TTputc('\n'); TTputc('\n');
@ -624,14 +621,14 @@ quit(f, n)
exit(1); exit(1);
} }
#endif #endif
vttidy(); vttidy();
if (f) if (f)
exit(n); exit(n);
else else
exit(GOOD); exit(GOOD);
} }
mlwrite(""); mlwrite("");
return(s); return (s);
} }
/* /*
@ -641,15 +638,15 @@ quit(f, n)
*/ */
ctlxlp(f, n) ctlxlp(f, n)
{ {
if (kbdmode != STOP) { if (kbdmode != STOP) {
mlwrite("%%Macro already active"); mlwrite("%%Macro already active");
return(FALSE); return (FALSE);
} }
mlwrite("(Start macro)"); mlwrite("(Start macro)");
kbdptr = &kbdm[0]; kbdptr = &kbdm[0];
kbdend = kbdptr; kbdend = kbdptr;
kbdmode = RECORD; kbdmode = RECORD;
return (TRUE); return (TRUE);
} }
/* /*
@ -658,15 +655,15 @@ ctlxlp(f, n)
*/ */
ctlxrp(f, n) ctlxrp(f, n)
{ {
if (kbdmode == STOP) { if (kbdmode == STOP) {
mlwrite("%%Macro not active"); mlwrite("%%Macro not active");
return(FALSE); return (FALSE);
}
if (kbdmode == RECORD) {
mlwrite("(End macro)");
kbdmode = STOP;
} }
return(TRUE); if (kbdmode == RECORD) {
mlwrite("(End macro)");
kbdmode = STOP;
}
return (TRUE);
} }
/* /*
@ -676,16 +673,16 @@ ctlxrp(f, n)
*/ */
ctlxe(f, n) ctlxe(f, n)
{ {
if (kbdmode != STOP) { if (kbdmode != STOP) {
mlwrite("%%Macro already active"); mlwrite("%%Macro already active");
return(FALSE); return (FALSE);
} }
if (n <= 0) if (n <= 0)
return (TRUE); return (TRUE);
kbdrep = n; /* remember how many times to execute */ kbdrep = n; /* remember how many times to execute */
kbdmode = PLAY; /* start us in play mode */ kbdmode = PLAY; /* start us in play mode */
kbdptr = &kbdm[0]; /* at the beginning */ kbdptr = &kbdm[0]; /* at the beginning */
return(TRUE); return (TRUE);
} }
/* /*
@ -695,46 +692,43 @@ ctlxe(f, n)
*/ */
ctrlg(f, n) ctrlg(f, n)
{ {
TTbeep(); TTbeep();
kbdmode = STOP; kbdmode = STOP;
mlwrite("(Aborted)"); mlwrite("(Aborted)");
return(ABORT); return (ABORT);
} }
/* tell the user that this command is illegal while we are in /* tell the user that this command is illegal while we are in
VIEW (read-only) mode */ VIEW (read-only) mode */
rdonly() rdonly()
{ {
TTbeep(); TTbeep();
mlwrite("(Key illegal in VIEW mode)"); mlwrite("(Key illegal in VIEW mode)");
return(FALSE); return (FALSE);
} }
resterr() resterr()
{ {
TTbeep(); TTbeep();
mlwrite("(That command is RESTRICTED)"); mlwrite("(That command is RESTRICTED)");
return(FALSE); return (FALSE);
} }
nullproc() /* user function that does NOTHING */ nullproc()
{ /* user function that does NOTHING */
{
} }
meta() /* dummy function for binding to meta prefix */ meta()
{ { /* dummy function for binding to meta prefix */
} }
cex() /* dummy function for binding to control-x prefix */ cex()
{ { /* dummy function for binding to control-x prefix */
} }
unarg() /* dummy function for binding to universal-argument */ unarg()
{ { /* dummy function for binding to universal-argument */
} }
/***** Compiler specific Library functions ****/ /***** Compiler specific Library functions ****/
@ -746,12 +740,12 @@ unarg() /* dummy function for binding to universal-argument */
char *strncpy(dst, src, maxlen) char *strncpy(dst, src, maxlen)
char *dst; /* destination of copied string */ char *dst; /* destination of copied string */
char *src; /* source */ char *src; /* source */
int maxlen; /* maximum length */ int maxlen; /* maximum length */
{ {
char *dptr; /* ptr into dst */ char *dptr; /* ptr into dst */
dptr = dst; dptr = dst;
/* while (*src && (maxlen-- > 0)) /* while (*src && (maxlen-- > 0))
@ -760,11 +754,11 @@ int maxlen; /* maximum length */
*dptr++ = *src++; *dptr++ = *src++;
maxlen--; maxlen--;
} }
*dptr = 0; /* orig */ *dptr = 0; /* orig */
/* if (maxlen > 0) /* if (maxlen > 0)
*dptr = 0; */ *dptr = 0; */
return(dst); return (dst);
} }
#endif #endif
@ -781,12 +775,12 @@ int maxlen; /* maximum length */
#undef malloc #undef malloc
#undef free #undef free
char *allocate(nbytes) /* allocate nbytes and track */ char *allocate(nbytes)
/* allocate nbytes and track */
unsigned nbytes; /* # of bytes to allocate */ unsigned nbytes; /* # of bytes to allocate */
{ {
char *mp; /* ptr returned from malloc */ char *mp; /* ptr returned from malloc */
char *malloc(); char *malloc();
mp = malloc(nbytes); mp = malloc(nbytes);
@ -797,20 +791,20 @@ unsigned nbytes; /* # of bytes to allocate */
#endif #endif
} }
return(mp); return (mp);
} }
release(mp) /* release malloced memory and track */ release(mp)
/* release malloced memory and track */
char *mp; /* chunk of RAM to release */ char *mp; /* chunk of RAM to release */
{ {
unsigned *lp; /* ptr to the long containing the block size */ unsigned *lp; /* ptr to the long containing the block size */
if (mp) { if (mp) {
/* update amount of ram currently malloced */ /* update amount of ram currently malloced */
lp = ((unsigned *)mp) - 1; lp = ((unsigned *) mp) - 1;
envram -= (long)*lp - 2; envram -= (long) *lp - 2;
free(mp); free(mp);
#if RAMSHOW #if RAMSHOW
dspram(); dspram();
@ -819,9 +813,8 @@ char *mp; /* chunk of RAM to release */
} }
#if RAMSHOW #if RAMSHOW
dspram() /* display the amount of RAM currently malloced */ dspram()
{ /* display the amount of RAM currently malloced */
{
char mbuf[20]; char mbuf[20];
char *sp; char *sp;
@ -848,7 +841,7 @@ dspram() /* display the amount of RAM currently malloced */
#if CLEAN #if CLEAN
cexit(status) cexit(status)
int status; /* return status of emacs */ int status; /* return status of emacs */
{ {
register BUFFER *bp; /* buffer list pointer */ register BUFFER *bp; /* buffer list pointer */
@ -883,7 +876,7 @@ int status; /* return status of emacs */
#if CALLED #if CALLED
eexitflag = TRUE; /* flag a program exit */ eexitflag = TRUE; /* flag a program exit */
eexitval = status; eexitval = status;
return(status); return (status);
#else #else
#undef exit #undef exit
exit(status); exit(status);

View File

@ -2,7 +2,7 @@
* *
* locking routines as modified by Petri Kutvonen * locking routines as modified by Petri Kutvonen
*/ */
#include "estruct.h" #include "estruct.h"
#if (FILOCK && BSD) || SVR4 #if (FILOCK && BSD) || SVR4
@ -26,7 +26,7 @@
int gethostname(char *name, int namelen) int gethostname(char *name, int namelen)
{ {
return(sysinfo(SI_HOSTNAME, name, namelen)); return (sysinfo(SI_HOSTNAME, name, namelen));
} }
#endif #endif
@ -40,18 +40,18 @@ int gethostname(char *name, int namelen)
* *
*********************/ *********************/
char *dolock(fname) char *dolock(fname)
char *fname; char *fname;
{ {
int fd, lk, n; int fd, lk, n;
static char lname[MAXLOCK], locker[MAXNAME+1]; static char lname[MAXLOCK], locker[MAXNAME + 1];
int mask; int mask;
struct stat sbuf; struct stat sbuf;
strcat(strcpy(lname, fname), ".lock~"); strcat(strcpy(lname, fname), ".lock~");
/* check that we are not being cheated, qname must point to */ /* check that we are not being cheated, qname must point to */
/* a regular file - even this code leaves a small window of */ /* a regular file - even this code leaves a small window of */
/* vulnerability but it is rather hard to exploit it */ /* vulnerability but it is rather hard to exploit it */
#if defined(S_IFLNK) #if defined(S_IFLNK)
if (lstat(lname, &sbuf) == 0) if (lstat(lname, &sbuf) == 0)
@ -59,17 +59,16 @@ char *dolock(fname)
if (stat(lname, &sbuf) == 0) if (stat(lname, &sbuf) == 0)
#endif #endif
#if defined(S_ISREG) #if defined(S_ISREG)
if (! S_ISREG(sbuf.st_mode)) if (!S_ISREG(sbuf.st_mode))
#else #else
if (! (((sbuf.st_mode) & 070000) == 0)) /* SysV R2 */ if (!(((sbuf.st_mode) & 070000) == 0)) /* SysV R2 */
#endif #endif
return "LOCK ERROR: not a regular file"; return "LOCK ERROR: not a regular file";
mask = umask(0); mask = umask(0);
fd = open(lname, O_RDWR | O_CREAT, 0666); fd = open(lname, O_RDWR | O_CREAT, 0666);
umask(mask); umask(mask);
if (fd < 0) if (fd < 0) {
{
if (errno == EACCES) if (errno == EACCES)
return NULL; return NULL;
#ifdef EROFS #ifdef EROFS
@ -78,20 +77,19 @@ char *dolock(fname)
#endif #endif
return "LOCK ERROR: cannot access lock file"; return "LOCK ERROR: cannot access lock file";
} }
if ((n = read(fd, locker, MAXNAME)) < 1) if ((n = read(fd, locker, MAXNAME)) < 1) {
{
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
/* strcpy(locker, getlogin()); */ /* strcpy(locker, getlogin()); */
cuserid(locker); cuserid(locker);
strcat(locker+strlen(locker), "@"); strcat(locker + strlen(locker), "@");
gethostname(locker+strlen(locker), 64); gethostname(locker + strlen(locker), 64);
write(fd, locker, strlen(locker)); write(fd, locker, strlen(locker));
close(fd); close(fd);
return NULL; return NULL;
} }
locker[n > MAXNAME ? MAXNAME : n] = 0; locker[n > MAXNAME ? MAXNAME : n] = 0;
return locker; return locker;
} }
/********************* /*********************
@ -102,16 +100,15 @@ char *dolock(fname)
* if other error, returns "LOCK ERROR: explanation" * if other error, returns "LOCK ERROR: explanation"
* *
*********************/ *********************/
char *undolock(fname) char *undolock(fname)
char *fname; char *fname;
{ {
int fd, lk; int fd, lk;
static char lname[MAXLOCK]; static char lname[MAXLOCK];
strcat(strcpy(lname, fname), ".lock~"); strcat(strcpy(lname, fname), ".lock~");
if (unlink(lname) != 0) if (unlink(lname) != 0) {
{
if (errno == EACCES || errno == ENOENT) if (errno == EACCES || errno == ENOENT)
return NULL; return NULL;
#ifdef EROFS #ifdef EROFS
@ -121,5 +118,5 @@ char *undolock(fname)
return "LOCK ERROR: cannot remove lock file"; return "LOCK ERROR: cannot remove lock file";
} }
return NULL; return NULL;
} }
#endif #endif

33
posix.c
View File

@ -21,16 +21,16 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
int kbdflgs; /* saved keyboard fd flags */ int kbdflgs; /* saved keyboard fd flags */
int kbdpoll; /* in O_NDELAY mode */ int kbdpoll; /* in O_NDELAY mode */
int kbdqp; /* there is a char in kbdq */ int kbdqp; /* there is a char in kbdq */
char kbdq; /* char we've already read */ char kbdq; /* char we've already read */
struct termios otermios; /* original terminal characteristics */ struct termios otermios; /* original terminal characteristics */
struct termios ntermios; /* charactoristics to use inside */ struct termios ntermios; /* charactoristics to use inside */
#define TBUFSIZ 128 #define TBUFSIZ 128
char tobuf[TBUFSIZ]; /* terminal output buffer */ char tobuf[TBUFSIZ]; /* terminal output buffer */
/* /*
@ -53,12 +53,13 @@ ttopen()
| INPCK | INLCR | IGNCR | ICRNL); | INPCK | INLCR | IGNCR | ICRNL);
/* raw CR/NR etc output handling */ /* raw CR/NR etc output handling */
ntermios.c_oflag &= ~(OPOST | ONLCR | OLCUC | OCRNL | ONOCR | ONLRET); ntermios.c_oflag &=
~(OPOST | ONLCR | OLCUC | OCRNL | ONOCR | ONLRET);
/* No signal handling, no echo etc */ /* No signal handling, no echo etc */
ntermios.c_lflag &= ~(ISIG | ICANON | XCASE | ECHO | ECHOE | ECHOK ntermios.c_lflag &= ~(ISIG | ICANON | XCASE | ECHO | ECHOE | ECHOK
| ECHONL | NOFLSH | TOSTOP | ECHOCTL | ECHOPRT | ECHONL | NOFLSH | TOSTOP | ECHOCTL |
| ECHOKE | FLUSHO | PENDIN | IEXTEN); ECHOPRT | ECHOKE | FLUSHO | PENDIN | IEXTEN);
/* one character, no timeout */ /* one character, no timeout */
ntermios.c_cc[VMIN] = 1; ntermios.c_cc[VMIN] = 1;
@ -71,11 +72,11 @@ ttopen()
*/ */
setbuffer(stdout, &tobuf[0], TBUFSIZ); setbuffer(stdout, &tobuf[0], TBUFSIZ);
kbdflgs = fcntl( 0, F_GETFL, 0 ); kbdflgs = fcntl(0, F_GETFL, 0);
kbdpoll = FALSE; kbdpoll = FALSE;
/* on all screens we are not sure of the initial position /* on all screens we are not sure of the initial position
of the cursor */ of the cursor */
ttrow = 999; ttrow = 999;
ttcol = 999; ttcol = 999;
} }
@ -136,7 +137,7 @@ ttflush()
*/ */
ttgetc() ttgetc()
{ {
return(255 & fgetc(stdin)); /* 8BIT P.K. */ return (255 & fgetc(stdin)); /* 8BIT P.K. */
} }
/* typahead: Check to see if any characters are already in the /* typahead: Check to see if any characters are already in the
@ -145,10 +146,10 @@ ttgetc()
typahead() typahead()
{ {
int x; /* holds # of pending chars */ int x; /* holds # of pending chars */
#ifdef FIONREAD #ifdef FIONREAD
if (ioctl(0,FIONREAD,&x) < 0) if (ioctl(0, FIONREAD, &x) < 0)
x = 0; x = 0;
#else #else
x = 0; x = 0;
@ -156,4 +157,4 @@ typahead()
return x; return x;
} }
#endif /* POSIX */ #endif /* POSIX */

825
random.c

File diff suppressed because it is too large Load Diff

265
region.c
View File

@ -21,19 +21,19 @@
*/ */
killregion(f, n) killregion(f, n)
{ {
register int s; register int s;
REGION region; REGION region;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
if ((s=getregion(&region)) != TRUE) if ((s = getregion(&region)) != TRUE)
return (s); return (s);
if ((lastflag&CFKILL) == 0) /* This is a kill type */ if ((lastflag & CFKILL) == 0) /* This is a kill type */
kdelete(); /* command, so do magic */ kdelete(); /* command, so do magic */
thisflag |= CFKILL; /* kill buffer stuff. */ thisflag |= CFKILL; /* kill buffer stuff. */
curwp->w_dotp = region.r_linep; curwp->w_dotp = region.r_linep;
curwp->w_doto = region.r_offset; curwp->w_doto = region.r_offset;
return (ldelete(region.r_size, TRUE)); return (ldelete(region.r_size, TRUE));
} }
/* /*
@ -44,32 +44,32 @@ killregion(f, n)
*/ */
copyregion(f, n) copyregion(f, n)
{ {
register LINE *linep; register LINE *linep;
register int loffs; register int loffs;
register int s; register int s;
REGION region; REGION region;
if ((s=getregion(&region)) != TRUE) if ((s = getregion(&region)) != TRUE)
return (s); return (s);
if ((lastflag&CFKILL) == 0) /* Kill type command. */ if ((lastflag & CFKILL) == 0) /* Kill type command. */
kdelete(); kdelete();
thisflag |= CFKILL; thisflag |= CFKILL;
linep = region.r_linep; /* Current line. */ linep = region.r_linep; /* Current line. */
loffs = region.r_offset; /* Current offset. */ loffs = region.r_offset; /* Current offset. */
while (region.r_size--) { while (region.r_size--) {
if (loffs == llength(linep)) { /* End of line. */ if (loffs == llength(linep)) { /* End of line. */
if ((s=kinsert('\n')) != TRUE) if ((s = kinsert('\n')) != TRUE)
return (s); return (s);
linep = lforw(linep); linep = lforw(linep);
loffs = 0; loffs = 0;
} else { /* Middle of line. */ } else { /* Middle of line. */
if ((s=kinsert(lgetc(linep, loffs))) != TRUE) if ((s = kinsert(lgetc(linep, loffs))) != TRUE)
return (s); return (s);
++loffs; ++loffs;
} }
} }
mlwrite("(region copied)"); mlwrite("(region copied)");
return (TRUE); return (TRUE);
} }
/* /*
@ -82,31 +82,31 @@ copyregion(f, n)
*/ */
lowerregion(f, n) lowerregion(f, n)
{ {
register LINE *linep; register LINE *linep;
register int loffs; register int loffs;
register int c; register int c;
register int s; register int s;
REGION region; REGION region;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
if ((s=getregion(&region)) != TRUE) if ((s = getregion(&region)) != TRUE)
return (s); return (s);
lchange(WFHARD); lchange(WFHARD);
linep = region.r_linep; linep = region.r_linep;
loffs = region.r_offset; loffs = region.r_offset;
while (region.r_size--) { while (region.r_size--) {
if (loffs == llength(linep)) { if (loffs == llength(linep)) {
linep = lforw(linep); linep = lforw(linep);
loffs = 0; loffs = 0;
} else { } else {
c = lgetc(linep, loffs); c = lgetc(linep, loffs);
if (c>='A' && c<='Z') if (c >= 'A' && c <= 'Z')
lputc(linep, loffs, c+'a'-'A'); lputc(linep, loffs, c + 'a' - 'A');
++loffs; ++loffs;
} }
} }
return (TRUE); return (TRUE);
} }
/* /*
@ -119,31 +119,31 @@ lowerregion(f, n)
*/ */
upperregion(f, n) upperregion(f, n)
{ {
register LINE *linep; register LINE *linep;
register int loffs; register int loffs;
register int c; register int c;
register int s; register int s;
REGION region; REGION region;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
if ((s=getregion(&region)) != TRUE) if ((s = getregion(&region)) != TRUE)
return (s); return (s);
lchange(WFHARD); lchange(WFHARD);
linep = region.r_linep; linep = region.r_linep;
loffs = region.r_offset; loffs = region.r_offset;
while (region.r_size--) { while (region.r_size--) {
if (loffs == llength(linep)) { if (loffs == llength(linep)) {
linep = lforw(linep); linep = lforw(linep);
loffs = 0; loffs = 0;
} else { } else {
c = lgetc(linep, loffs); c = lgetc(linep, loffs);
if (c>='a' && c<='z') if (c >= 'a' && c <= 'z')
lputc(linep, loffs, c-'a'+'A'); lputc(linep, loffs, c - 'a' + 'A');
++loffs; ++loffs;
} }
} }
return (TRUE); return (TRUE);
} }
/* /*
@ -160,53 +160,54 @@ upperregion(f, n)
getregion(rp) getregion(rp)
register REGION *rp; register REGION *rp;
{ {
register LINE *flp; register LINE *flp;
register LINE *blp; register LINE *blp;
long fsize; long fsize;
long bsize; long bsize;
if (curwp->w_markp == NULL) { if (curwp->w_markp == NULL) {
mlwrite("No mark set in this window"); mlwrite("No mark set in this window");
return (FALSE); return (FALSE);
} }
if (curwp->w_dotp == curwp->w_markp) { if (curwp->w_dotp == curwp->w_markp) {
rp->r_linep = curwp->w_dotp; rp->r_linep = curwp->w_dotp;
if (curwp->w_doto < curwp->w_marko) { if (curwp->w_doto < curwp->w_marko) {
rp->r_offset = curwp->w_doto; rp->r_offset = curwp->w_doto;
rp->r_size = (long)(curwp->w_marko-curwp->w_doto); rp->r_size =
} else { (long) (curwp->w_marko - curwp->w_doto);
rp->r_offset = curwp->w_marko; } else {
rp->r_size = (long)(curwp->w_doto-curwp->w_marko); rp->r_offset = curwp->w_marko;
} rp->r_size =
return (TRUE); (long) (curwp->w_doto - curwp->w_marko);
} }
blp = curwp->w_dotp; return (TRUE);
bsize = (long)curwp->w_doto; }
flp = curwp->w_dotp; blp = curwp->w_dotp;
fsize = (long)(llength(flp)-curwp->w_doto+1); bsize = (long) curwp->w_doto;
while (flp!=curbp->b_linep || lback(blp)!=curbp->b_linep) { flp = curwp->w_dotp;
if (flp != curbp->b_linep) { fsize = (long) (llength(flp) - curwp->w_doto + 1);
flp = lforw(flp); while (flp != curbp->b_linep || lback(blp) != curbp->b_linep) {
if (flp == curwp->w_markp) { if (flp != curbp->b_linep) {
rp->r_linep = curwp->w_dotp; flp = lforw(flp);
rp->r_offset = curwp->w_doto; if (flp == curwp->w_markp) {
rp->r_size = fsize+curwp->w_marko; rp->r_linep = curwp->w_dotp;
return (TRUE); rp->r_offset = curwp->w_doto;
} rp->r_size = fsize + curwp->w_marko;
fsize += llength(flp)+1; return (TRUE);
} }
if (lback(blp) != curbp->b_linep) { fsize += llength(flp) + 1;
blp = lback(blp); }
bsize += llength(blp)+1; if (lback(blp) != curbp->b_linep) {
if (blp == curwp->w_markp) { blp = lback(blp);
rp->r_linep = blp; bsize += llength(blp) + 1;
rp->r_offset = curwp->w_marko; if (blp == curwp->w_markp) {
rp->r_size = bsize - curwp->w_marko; rp->r_linep = blp;
return (TRUE); rp->r_offset = curwp->w_marko;
} rp->r_size = bsize - curwp->w_marko;
} return (TRUE);
} }
mlwrite("Bug: lost mark"); }
return (FALSE); }
mlwrite("Bug: lost mark");
return (FALSE);
} }

1008
search.c

File diff suppressed because it is too large Load Diff

396
spawn.c
View File

@ -9,16 +9,16 @@
#include "edef.h" #include "edef.h"
#if VMS #if VMS
#define EFN 0 /* Event flag. */ #define EFN 0 /* Event flag. */
#include <ssdef.h> /* Random headers. */ #include <ssdef.h> /* Random headers. */
#include <stsdef.h> #include <stsdef.h>
#include <descrip.h> #include <descrip.h>
#include <iodef.h> #include <iodef.h>
extern int oldmode[3]; /* In "termio.c" */ extern int oldmode[3]; /* In "termio.c" */
extern int newmode[3]; /* In "termio.c" */ extern int newmode[3]; /* In "termio.c" */
extern short iochan; /* In "termio.c" */ extern short iochan; /* In "termio.c" */
#endif #endif
#if V7 | USG | BSD #if V7 | USG | BSD
@ -43,50 +43,50 @@ extern void sizesignal();
spawncli(f, n) spawncli(f, n)
{ {
#if V7 | USG | BSD #if V7 | USG | BSD
register char *cp; register char *cp;
char *getenv(); char *getenv();
#endif #endif
/* don't allow this command if restricted */ /* don't allow this command if restricted */
if (restflag) if (restflag)
return(resterr()); return (resterr());
#if VMS #if VMS
movecursor(term.t_nrow, 0); /* In last line. */ movecursor(term.t_nrow, 0); /* In last line. */
mlputs("(Starting DCL)\r\n"); mlputs("(Starting DCL)\r\n");
TTflush(); /* Ignore "ttcol". */ TTflush(); /* Ignore "ttcol". */
sgarbf = TRUE; sgarbf = TRUE;
sys(NULL); sys(NULL);
sleep(1); sleep(1);
mlputs("\r\n(Returning from DCL)\r\n"); mlputs("\r\n(Returning from DCL)\r\n");
TTflush(); TTflush();
sleep(1); sleep(1);
return(TRUE); return (TRUE);
#endif #endif
#if MSDOS & (MSC | TURBO) #if MSDOS & (MSC | TURBO)
movecursor(term.t_nrow, 0); /* Seek to last line. */ movecursor(term.t_nrow, 0); /* Seek to last line. */
TTflush(); TTflush();
TTkclose(); TTkclose();
shellprog(""); shellprog("");
TTkopen(); TTkopen();
sgarbf = TRUE; sgarbf = TRUE;
return(TRUE); return (TRUE);
#endif #endif
#if V7 | USG | BSD #if V7 | USG | BSD
movecursor(term.t_nrow, 0); /* Seek to last line. */ movecursor(term.t_nrow, 0); /* Seek to last line. */
TTflush(); TTflush();
TTclose(); /* stty to old settings */ TTclose(); /* stty to old settings */
if ((cp = getenv("SHELL")) != NULL && *cp != '\0') if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
system(cp); system(cp);
else else
#if BSD #if BSD
system("exec /bin/csh"); system("exec /bin/csh");
#else #else
system("exec /bin/sh"); system("exec /bin/sh");
#endif #endif
sgarbf = TRUE; sgarbf = TRUE;
sleep(2); sleep(2);
TTopen(); TTopen();
TTkopen(); TTkopen();
#ifdef SIGWINCH #ifdef SIGWINCH
/* /*
@ -95,17 +95,17 @@ spawncli(f, n)
* -lbt * -lbt
*/ */
chg_width = term.t_ncol; chg_width = term.t_ncol;
chg_height = term.t_nrow+1; chg_height = term.t_nrow + 1;
term.t_nrow = term.t_ncol = 0; term.t_nrow = term.t_ncol = 0;
#endif #endif
return(TRUE); return (TRUE);
#endif #endif
} }
#if BSD | __hpux | SVR4 #if BSD | __hpux | SVR4
bktoshell() /* suspend MicroEMACS and wait to wake up */ bktoshell()
{ { /* suspend MicroEMACS and wait to wake up */
int pid; int pid;
vttidy(); vttidy();
@ -131,62 +131,61 @@ rtfrmshell()
*/ */
spawn(f, n) spawn(f, n)
{ {
register int s; register int s;
char line[NLINE]; char line[NLINE];
/* don't allow this command if restricted */ /* don't allow this command if restricted */
if (restflag) if (restflag)
return(resterr()); return (resterr());
#if VMS #if VMS
if ((s=mlreply("!", line, NLINE)) != TRUE) if ((s = mlreply("!", line, NLINE)) != TRUE)
return (s); return (s);
movecursor(term.t_nrow, 0); movecursor(term.t_nrow, 0);
TTflush(); TTflush();
s = sys(line); /* Run the command. */ s = sys(line); /* Run the command. */
if (clexec == FALSE) { if (clexec == FALSE) {
mlputs("\r\n\n(End)"); /* Pause. */ mlputs("\r\n\n(End)"); /* Pause. */
TTflush(); TTflush();
tgetc(); tgetc();
} }
sgarbf = TRUE; sgarbf = TRUE;
return (s); return (s);
#endif #endif
#if MSDOS #if MSDOS
if ((s=mlreply("!", line, NLINE)) != TRUE) if ((s = mlreply("!", line, NLINE)) != TRUE)
return(s); return (s);
movecursor(term.t_nrow, 0); movecursor(term.t_nrow, 0);
TTkclose(); TTkclose();
shellprog(line); shellprog(line);
TTkopen(); TTkopen();
/* if we are interactive, pause here */ /* if we are interactive, pause here */
if (clexec == FALSE) { if (clexec == FALSE) {
mlputs("\r\n(End)"); mlputs("\r\n(End)");
tgetc(); tgetc();
} }
sgarbf = TRUE; sgarbf = TRUE;
return (TRUE); return (TRUE);
#endif #endif
#if V7 | USG | BSD #if V7 | USG | BSD
if ((s=mlreply("!", line, NLINE)) != TRUE) if ((s = mlreply("!", line, NLINE)) != TRUE)
return (s); return (s);
TTflush(); TTflush();
TTclose(); /* stty to old modes */ TTclose(); /* stty to old modes */
TTkclose(); TTkclose();
system(line); system(line);
fflush(stdout); /* to be sure P.K. */ fflush(stdout); /* to be sure P.K. */
TTopen(); TTopen();
if (clexec == FALSE) { if (clexec == FALSE) {
mlputs("(End)"); /* Pause. */ mlputs("(End)"); /* Pause. */
TTflush(); TTflush();
while ((s = tgetc()) != '\r' && s != ' ') while ((s = tgetc()) != '\r' && s != ' ');
;
mlputs("\r\n"); mlputs("\r\n");
} }
TTkopen(); TTkopen();
sgarbf = TRUE; sgarbf = TRUE;
return (TRUE); return (TRUE);
#endif #endif
} }
@ -197,58 +196,56 @@ spawn(f, n)
*/ */
execprg(f, n) execprg(f, n)
{ {
register int s; register int s;
char line[NLINE]; char line[NLINE];
/* don't allow this command if restricted */ /* don't allow this command if restricted */
if (restflag) if (restflag)
return(resterr()); return (resterr());
#if VMS #if VMS
if ((s=mlreply("!", line, NLINE)) != TRUE) if ((s = mlreply("!", line, NLINE)) != TRUE)
return (s); return (s);
TTflush(); TTflush();
s = sys(line); /* Run the command. */ s = sys(line); /* Run the command. */
mlputs("\r\n\n(End)"); /* Pause. */ mlputs("\r\n\n(End)"); /* Pause. */
TTflush(); TTflush();
tgetc(); tgetc();
sgarbf = TRUE; sgarbf = TRUE;
return (s); return (s);
#endif #endif
#if MSDOS #if MSDOS
if ((s=mlreply("$", line, NLINE)) != TRUE) if ((s = mlreply("$", line, NLINE)) != TRUE)
return(s); return (s);
movecursor(term.t_nrow, 0); movecursor(term.t_nrow, 0);
TTkclose(); TTkclose();
execprog(line); execprog(line);
TTkopen(); TTkopen();
/* if we are interactive, pause here */ /* if we are interactive, pause here */
if (clexec == FALSE) { if (clexec == FALSE) {
mlputs("\r\n(End)"); mlputs("\r\n(End)");
tgetc(); tgetc();
} }
sgarbf = TRUE; sgarbf = TRUE;
return (TRUE); return (TRUE);
#endif #endif
#if V7 | USG | BSD #if V7 | USG | BSD
if ((s=mlreply("!", line, NLINE)) != TRUE) if ((s = mlreply("!", line, NLINE)) != TRUE)
return (s); return (s);
TTputc('\n'); /* Already have '\r' */ TTputc('\n'); /* Already have '\r' */
TTflush(); TTflush();
TTclose(); /* stty to old modes */ TTclose(); /* stty to old modes */
system(line); system(line);
fflush(stdout); /* to be sure P.K. */ fflush(stdout); /* to be sure P.K. */
TTopen(); TTopen();
mlputs("(End)"); /* Pause. */ mlputs("(End)"); /* Pause. */
TTflush(); TTflush();
while ((s = tgetc()) != '\r' && s != ' ') while ((s = tgetc()) != '\r' && s != ' ');
; sgarbf = TRUE;
sgarbf = TRUE; return (TRUE);
return (TRUE);
#endif #endif
} }
@ -258,10 +255,10 @@ execprg(f, n)
*/ */
pipecmd(f, n) pipecmd(f, n)
{ {
register int s; /* return status from CLI */ register int s; /* return status from CLI */
register WINDOW *wp; /* pointer to new window */ register WINDOW *wp; /* pointer to new window */
register BUFFER *bp; /* pointer to buffer to zot */ register BUFFER *bp; /* pointer to buffer to zot */
char line[NLINE]; /* command line send to shell */ char line[NLINE]; /* command line send to shell */
static char bname[] = "command"; static char bname[] = "command";
static char filnam[NSTRING] = "command"; static char filnam[NSTRING] = "command";
@ -271,36 +268,38 @@ pipecmd(f, n)
char *getenv(); char *getenv();
FILE *fp; FILE *fp;
FILE *fopen(); FILE *fopen();
int len; int len;
#endif #endif
/* don't allow this command if restricted */ /* don't allow this command if restricted */
if (restflag) if (restflag)
return(resterr()); return (resterr());
#if MSDOS #if MSDOS
if ((tmp = getenv("TMP")) == NULL && (tmp = getenv("TEMP")) == NULL) if ((tmp = getenv("TMP")) == NULL
&& (tmp = getenv("TEMP")) == NULL)
strcpy(filnam, "command"); strcpy(filnam, "command");
else { else {
strcpy(filnam, tmp); strcpy(filnam, tmp);
len = strlen(tmp); len = strlen(tmp);
if (len <= 0 || filnam[len-1] != '\\' && filnam[len-1] != '/') if (len <= 0 || filnam[len - 1] != '\\'
strcat(filnam,"\\"); && filnam[len - 1] != '/')
strcat(filnam,"command"); strcat(filnam, "\\");
} strcat(filnam, "command");
}
#endif #endif
#if VMS #if VMS
mlwrite("Not available under VMS"); mlwrite("Not available under VMS");
return(FALSE); return (FALSE);
#endif #endif
/* get the command to pipe in */ /* get the command to pipe in */
if ((s=mlreply("@", line, NLINE)) != TRUE) if ((s = mlreply("@", line, NLINE)) != TRUE)
return(s); return (s);
/* get rid of the command output buffer if it exists */ /* get rid of the command output buffer if it exists */
if ((bp=bfind(bname, FALSE, 0)) != FALSE) { if ((bp = bfind(bname, FALSE, 0)) != FALSE) {
/* try to make sure we are off screen */ /* try to make sure we are off screen */
wp = wheadp; wp = wheadp;
while (wp != NULL) { while (wp != NULL) {
@ -320,17 +319,16 @@ pipecmd(f, n)
} }
if (zotbuf(bp) != TRUE) if (zotbuf(bp) != TRUE)
return(FALSE); return (FALSE);
} }
#if MSDOS #if MSDOS
strcat(line," >>"); strcat(line, " >>");
strcat(line,filnam); strcat(line, filnam);
movecursor(term.t_nrow, 0); movecursor(term.t_nrow, 0);
TTkclose(); TTkclose();
shellprog(line); shellprog(line);
TTkopen(); TTkopen();
sgarbf = TRUE; sgarbf = TRUE;
if ((fp = fopen(filnam, "r")) == NULL) { if ((fp = fopen(filnam, "r")) == NULL) {
s = FALSE; s = FALSE;
} else { } else {
@ -340,27 +338,27 @@ pipecmd(f, n)
#endif #endif
#if V7 | USG | BSD #if V7 | USG | BSD
TTflush(); TTflush();
TTclose(); /* stty to old modes */ TTclose(); /* stty to old modes */
strcat(line,">"); strcat(line, ">");
strcat(line,filnam); strcat(line, filnam);
system(line); system(line);
TTopen(); TTopen();
TTflush(); TTflush();
sgarbf = TRUE; sgarbf = TRUE;
s = TRUE; s = TRUE;
#endif #endif
if (s != TRUE) if (s != TRUE)
return(s); return (s);
/* split the current window to make room for the command output */ /* split the current window to make room for the command output */
if (splitwind(FALSE, 1) == FALSE) if (splitwind(FALSE, 1) == FALSE)
return(FALSE); return (FALSE);
/* and read the stuff in */ /* and read the stuff in */
if (getfile(filnam, FALSE) == FALSE) if (getfile(filnam, FALSE) == FALSE)
return(FALSE); return (FALSE);
/* make this window in VIEW mode, update all mode lines */ /* make this window in VIEW mode, update all mode lines */
curwp->w_bufp->b_mode |= MDVIEW; curwp->w_bufp->b_mode |= MDVIEW;
@ -372,7 +370,7 @@ pipecmd(f, n)
/* and get rid of the temporary file */ /* and get rid of the temporary file */
unlink(filnam); unlink(filnam);
return(TRUE); return (TRUE);
} }
/* /*
@ -380,11 +378,10 @@ pipecmd(f, n)
* Bound to ^X # * Bound to ^X #
*/ */
filter(f, n) filter(f, n)
{ {
register int s; /* return status from CLI */ register int s; /* return status from CLI */
register BUFFER *bp; /* pointer to buffer to zot */ register BUFFER *bp; /* pointer to buffer to zot */
char line[NLINE]; /* command line send to shell */ char line[NLINE]; /* command line send to shell */
char tmpnam[NFILEN]; /* place to store real file name */ char tmpnam[NFILEN]; /* place to store real file name */
static char bname1[] = "fltinp"; static char bname1[] = "fltinp";
@ -393,19 +390,19 @@ filter(f, n)
/* don't allow this command if restricted */ /* don't allow this command if restricted */
if (restflag) if (restflag)
return(resterr()); return (resterr());
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
#if VMS #if VMS
mlwrite("Not available under VMS"); mlwrite("Not available under VMS");
return(FALSE); return (FALSE);
#endif #endif
/* get the filter name and its args */ /* get the filter name and its args */
if ((s=mlreply("#", line, NLINE)) != TRUE) if ((s = mlreply("#", line, NLINE)) != TRUE)
return(s); return (s);
/* setup the proper file names */ /* setup the proper file names */
bp = curbp; bp = curbp;
@ -416,48 +413,47 @@ filter(f, n)
if (writeout(filnam1) != TRUE) { if (writeout(filnam1) != TRUE) {
mlwrite("(Cannot write filter file)"); mlwrite("(Cannot write filter file)");
strcpy(bp->b_fname, tmpnam); strcpy(bp->b_fname, tmpnam);
return(FALSE); return (FALSE);
} }
#if MSDOS #if MSDOS
strcat(line," <fltinp >fltout"); strcat(line, " <fltinp >fltout");
movecursor(term.t_nrow - 1, 0); movecursor(term.t_nrow - 1, 0);
TTkclose(); TTkclose();
shellprog(line); shellprog(line);
TTkopen(); TTkopen();
sgarbf = TRUE; sgarbf = TRUE;
s = TRUE; s = TRUE;
#endif #endif
#if V7 | USG | BSD #if V7 | USG | BSD
TTputc('\n'); /* Already have '\r' */ TTputc('\n'); /* Already have '\r' */
TTflush(); TTflush();
TTclose(); /* stty to old modes */ TTclose(); /* stty to old modes */
strcat(line," <fltinp >fltout"); strcat(line, " <fltinp >fltout");
system(line); system(line);
TTopen(); TTopen();
TTflush(); TTflush();
sgarbf = TRUE; sgarbf = TRUE;
s = TRUE; s = TRUE;
#endif #endif
/* on failure, escape gracefully */ /* on failure, escape gracefully */
if (s != TRUE || (readin(filnam2,FALSE) == FALSE)) { if (s != TRUE || (readin(filnam2, FALSE) == FALSE)) {
mlwrite("(Execution failed)"); mlwrite("(Execution failed)");
strcpy(bp->b_fname, tmpnam); strcpy(bp->b_fname, tmpnam);
unlink(filnam1); unlink(filnam1);
unlink(filnam2); unlink(filnam2);
return(s); return (s);
} }
/* reset file name */ /* reset file name */
strcpy(bp->b_fname, tmpnam); /* restore name */ strcpy(bp->b_fname, tmpnam); /* restore name */
bp->b_flag |= BFCHG; /* flag it as changed */ bp->b_flag |= BFCHG; /* flag it as changed */
/* and get rid of the temporary file */ /* and get rid of the temporary file */
unlink(filnam1); unlink(filnam1);
unlink(filnam2); unlink(filnam2);
return(TRUE); return (TRUE);
} }
#if VMS #if VMS
@ -468,36 +464,36 @@ filter(f, n)
* and the way out, because DCL does not want the channel to be in raw mode. * and the way out, because DCL does not want the channel to be in raw mode.
*/ */
sys(cmd) sys(cmd)
register char *cmd; register char *cmd;
{ {
struct dsc$descriptor cdsc; struct dsc$descriptor cdsc;
struct dsc$descriptor *cdscp; struct dsc$descriptor *cdscp;
long status; long status;
long substatus; long substatus;
long iosb[2]; long iosb[2];
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0, status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
oldmode, sizeof(oldmode), 0, 0, 0, 0); oldmode, sizeof(oldmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL) if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
return (FALSE); return (FALSE);
cdscp = NULL; /* Assume DCL. */ cdscp = NULL; /* Assume DCL. */
if (cmd != NULL) { /* Build descriptor. */ if (cmd != NULL) { /* Build descriptor. */
cdsc.dsc$a_pointer = cmd; cdsc.dsc$a_pointer = cmd;
cdsc.dsc$w_length = strlen(cmd); cdsc.dsc$w_length = strlen(cmd);
cdsc.dsc$b_dtype = DSC$K_DTYPE_T; cdsc.dsc$b_dtype = DSC$K_DTYPE_T;
cdsc.dsc$b_class = DSC$K_CLASS_S; cdsc.dsc$b_class = DSC$K_CLASS_S;
cdscp = &cdsc; cdscp = &cdsc;
} }
status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0); status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
if (status != SS$_NORMAL) if (status != SS$_NORMAL)
substatus = status; substatus = status;
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0, status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
newmode, sizeof(newmode), 0, 0, 0, 0); newmode, sizeof(newmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL) if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
return (FALSE); return (FALSE);
if ((substatus&STS$M_SUCCESS) == 0) /* Command failed. */ if ((substatus & STS$M_SUCCESS) == 0) /* Command failed. */
return (FALSE); return (FALSE);
return (TRUE); return (TRUE);
} }
#endif #endif
@ -507,7 +503,7 @@ register char *cmd;
shellprog(cmd) shellprog(cmd)
char *cmd; /* Incoming command line to execute */ char *cmd; /* Incoming command line to execute */
{ {
char *shell; /* Name of system command processor */ char *shell; /* Name of system command processor */
@ -521,11 +517,11 @@ char *cmd; /* Incoming command line to execute */
regs.h.ah = 0x37; /* get setting data */ regs.h.ah = 0x37; /* get setting data */
regs.h.al = 0x00; /* get switch character */ regs.h.al = 0x00; /* get switch character */
intdos(&regs, &regs); intdos(&regs, &regs);
swchar = (char)regs.h.dl; swchar = (char) regs.h.dl;
/* get name of system shell */ /* get name of system shell */
if ((shell = getenv("COMSPEC")) == NULL) { if ((shell = getenv("COMSPEC")) == NULL) {
return(FALSE); /* No shell located */ return (FALSE); /* No shell located */
} }
/* trim leading whitespace off the command */ /* trim leading whitespace off the command */
@ -543,9 +539,9 @@ char *cmd; /* Incoming command line to execute */
comline[strlen(comline)] = swchar; comline[strlen(comline)] = swchar;
strcat(comline, "c "); strcat(comline, "c ");
strcat(comline, cmd); strcat(comline, cmd);
return(execprog(comline)); return (execprog(comline));
} else } else
return(execprog(shell)); return (execprog(shell));
} }
/* EXECPROG: A function to execute a named program /* EXECPROG: A function to execute a named program
@ -554,7 +550,7 @@ char *cmd; /* Incoming command line to execute */
execprog(cmd) execprog(cmd)
char *cmd; /* Incoming command line to execute */ char *cmd; /* Incoming command line to execute */
{ {
char *sp; /* temporary string pointer */ char *sp; /* temporary string pointer */
@ -581,16 +577,16 @@ char *cmd; /* Incoming command line to execute */
/* and parse out the command tail */ /* and parse out the command tail */
while (*cmd && ((*cmd == ' ') || (*cmd == '\t'))) while (*cmd && ((*cmd == ' ') || (*cmd == '\t')))
++cmd; ++cmd;
*tail = (char)(strlen(cmd)); /* record the byte length */ *tail = (char) (strlen(cmd)); /* record the byte length */
strcpy(&tail[1], cmd); strcpy(&tail[1], cmd);
strcat(&tail[1], "\r"); strcat(&tail[1], "\r");
/* look up the program on the path trying various extentions */ /* look up the program on the path trying various extentions */
if ((sp = flook(prog, TRUE)) == NULL) if ((sp = flook(prog, TRUE)) == NULL)
if ((sp = flook(strcat(prog, ".exe"), TRUE)) == NULL) { if ((sp = flook(strcat(prog, ".exe"), TRUE)) == NULL) {
strcpy(&prog[strlen(prog)-4], ".com"); strcpy(&prog[strlen(prog) - 4], ".com");
if ((sp = flook(prog, TRUE)) == NULL) if ((sp = flook(prog, TRUE)) == NULL)
return(FALSE); return (FALSE);
} }
strcpy(prog, sp); strcpy(prog, sp);
@ -599,17 +595,17 @@ char *cmd; /* Incoming command line to execute */
/* set up the EXEC parameter block */ /* set up the EXEC parameter block */
pblock.envptr = 0; /* make the child inherit the parents env */ pblock.envptr = 0; /* make the child inherit the parents env */
pblock.fcb1 = f1; /* point to a blank FCB */ pblock.fcb1 = f1; /* point to a blank FCB */
pblock.fcb2 = f2; /* point to a blank FCB */ pblock.fcb2 = f2; /* point to a blank FCB */
pblock.cline = tail; /* parameter line pointer */ pblock.cline = tail; /* parameter line pointer */
/* and make the call */ /* and make the call */
regs.h.ah = 0x4b; /* EXEC Load or Execute a Program */ regs.h.ah = 0x4b; /* EXEC Load or Execute a Program */
regs.h.al = 0x00; /* load end execute function subcode */ regs.h.al = 0x00; /* load end execute function subcode */
segreg.ds = ((unsigned long)(prog) >> 16); /* program name ptr */ segreg.ds = ((unsigned long) (prog) >> 16); /* program name ptr */
regs.x.dx = (unsigned int)(prog); regs.x.dx = (unsigned int) (prog);
segreg.es = ((unsigned long)(&pblock) >> 16); /* set up param block ptr */ segreg.es = ((unsigned long) (&pblock) >> 16); /* set up param block ptr */
regs.x.bx = (unsigned int)(&pblock); regs.x.bx = (unsigned int) (&pblock);
#if TURBO | MSC #if TURBO | MSC
intdosx(&regs, &regs, &segreg); intdosx(&regs, &regs, &segreg);
if (regs.x.cflag == 0) { if (regs.x.cflag == 0) {
@ -623,6 +619,6 @@ char *cmd; /* Incoming command line to execute */
rval = -_doserrno; /* failed child call */ rval = -_doserrno; /* failed child call */
#endif #endif
#endif #endif
return((rval < 0) ? FALSE : TRUE); return ((rval < 0) ? FALSE : TRUE);
} }
#endif #endif

392
tcap.c
View File

@ -11,7 +11,7 @@
* -lbt * -lbt
*/ */
#define USE_BROKEN_OPTIMIZATION 0 #define USE_BROKEN_OPTIMIZATION 0
#define termdef 1 /* don't define "term" external */ #define termdef 1 /* don't define "term" external */
#include <stdio.h> #include <stdio.h>
#include "estruct.h" #include "estruct.h"
@ -25,37 +25,37 @@
#define MARGIN 8 #define MARGIN 8
#define SCRSIZ 64 #define SCRSIZ 64
#define NPAUSE 10 /* # times thru update to pause */ #define NPAUSE 10 /* # times thru update to pause */
#define BEL 0x07 #define BEL 0x07
#define ESC 0x1B #define ESC 0x1B
extern int ttopen(); extern int ttopen();
extern int ttgetc(); extern int ttgetc();
extern int ttputc(); extern int ttputc();
extern int tgetnum(); extern int tgetnum();
extern int ttflush(); extern int ttflush();
extern int ttclose(); extern int ttclose();
extern int tcapkopen(); extern int tcapkopen();
extern int tcapkclose(); extern int tcapkclose();
extern int tcapmove(); extern int tcapmove();
extern int tcapeeol(); extern int tcapeeol();
extern int tcapeeop(); extern int tcapeeop();
extern int tcapbeep(); extern int tcapbeep();
extern int tcaprev(); extern int tcaprev();
extern int tcapcres(); extern int tcapcres();
extern int tcapopen(); extern int tcapopen();
#if PKCODE #if PKCODE
extern int tcapclose(); extern int tcapclose();
#endif #endif
extern int tput(); extern int tput();
extern char *tgoto(); extern char *tgoto();
#if COLOR #if COLOR
extern int tcapfcol(); extern int tcapfcol();
extern int tcapbcol(); extern int tcapbcol();
#endif #endif
#if SCROLLCODE #if SCROLLCODE
extern int tcapscroll_reg(); extern int tcapscroll_reg();
extern int tcapscroll_delins(); extern int tcapscroll_delins();
#endif #endif
@ -73,155 +73,150 @@ char *CS, *DL, *AL, *SF, *SR;
#endif #endif
TERM term = { TERM term = {
0, /* these four values are set dynamically at open time */ 0, /* these four values are set dynamically at open time */
0, 0,
0, 0,
0, 0,
MARGIN, MARGIN,
SCRSIZ, SCRSIZ,
NPAUSE, NPAUSE,
tcapopen, tcapopen,
#if PKCODE #if PKCODE
tcapclose, tcapclose,
#else #else
ttclose, ttclose,
#endif #endif
tcapkopen, tcapkopen,
tcapkclose, tcapkclose,
ttgetc, ttgetc,
ttputc, ttputc,
ttflush, ttflush,
tcapmove, tcapmove,
tcapeeol, tcapeeol,
tcapeeop, tcapeeop,
tcapbeep, tcapbeep,
tcaprev, tcaprev,
tcapcres tcapcres
#if COLOR #if COLOR
, tcapfcol, , tcapfcol,
tcapbcol tcapbcol
#endif #endif
#if SCROLLCODE #if SCROLLCODE
, NULL /* set dynamically at open time */ , NULL /* set dynamically at open time */
#endif #endif
}; };
tcapopen() tcapopen()
{ {
char *getenv(); char *getenv();
char *t, *p, *tgetstr(); char *t, *p, *tgetstr();
char tcbuf[1024]; char tcbuf[1024];
char *tv_stype; char *tv_stype;
char err_str[72]; char err_str[72];
int int_col, int_row; int int_col, int_row;
#if PKCODE && USE_BROKEN_OPTIMIZATION #if PKCODE && USE_BROKEN_OPTIMIZATION
if (! term_init_ok) if (!term_init_ok) {
{
#endif #endif
if ((tv_stype = getenv("TERM")) == NULL) if ((tv_stype = getenv("TERM")) == NULL) {
{ puts("Environment variable TERM not defined!");
puts("Environment variable TERM not defined!"); exit(1);
exit(1); }
}
if ((tgetent(tcbuf, tv_stype)) != 1) if ((tgetent(tcbuf, tv_stype)) != 1) {
{ sprintf(err_str, "Unknown terminal type %s!",
sprintf(err_str, "Unknown terminal type %s!", tv_stype); tv_stype);
puts(err_str); puts(err_str);
exit(1); exit(1);
} }
/* Get screen size from system, or else from termcap. */ /* Get screen size from system, or else from termcap. */
getscreensize(&int_col, &int_row); getscreensize(&int_col, &int_row);
term.t_nrow = int_row-1; term.t_nrow = int_row - 1;
term.t_ncol = int_col; term.t_ncol = int_col;
if ((term.t_nrow <= 0) && (term.t_nrow=(short)tgetnum("li")-1) == -1){
puts("termcap entry incomplete (lines)");
exit(1);
}
if ((term.t_ncol <= 0) && (term.t_ncol=(short)tgetnum("co")) == -1){ if ((term.t_nrow <= 0)
puts("Termcap entry incomplete (columns)"); && (term.t_nrow = (short) tgetnum("li") - 1) == -1) {
exit(1); puts("termcap entry incomplete (lines)");
} exit(1);
}
if ((term.t_ncol <= 0)
&& (term.t_ncol = (short) tgetnum("co")) == -1) {
puts("Termcap entry incomplete (columns)");
exit(1);
}
#ifdef SIGWINCH #ifdef SIGWINCH
term.t_mrow = MAXROW; term.t_mrow = MAXROW;
term.t_mcol = MAXCOL; term.t_mcol = MAXCOL;
#else #else
term.t_mrow = term.t_nrow > MAXROW ? MAXROW : term.t_nrow; term.t_mrow = term.t_nrow > MAXROW ? MAXROW : term.t_nrow;
term.t_mcol = term.t_ncol > MAXCOL ? MAXCOL : term.t_ncol; term.t_mcol = term.t_ncol > MAXCOL ? MAXCOL : term.t_ncol;
#endif #endif
p = tcapbuf; p = tcapbuf;
t = tgetstr("pc", &p); t = tgetstr("pc", &p);
if(t) if (t)
PC = *t; PC = *t;
else else
PC = 0; PC = 0;
CL = tgetstr("cl", &p); CL = tgetstr("cl", &p);
CM = tgetstr("cm", &p); CM = tgetstr("cm", &p);
CE = tgetstr("ce", &p); CE = tgetstr("ce", &p);
UP = tgetstr("up", &p); UP = tgetstr("up", &p);
SE = tgetstr("se", &p); SE = tgetstr("se", &p);
SO = tgetstr("so", &p); SO = tgetstr("so", &p);
if (SO != NULL) if (SO != NULL)
revexist = TRUE; revexist = TRUE;
#if PKCODE #if PKCODE
if (tgetnum("sg") > 0) { /* can reverse be used? P.K. */ if (tgetnum("sg") > 0) { /* can reverse be used? P.K. */
revexist = FALSE; revexist = FALSE;
SE = NULL; SE = NULL;
SO = NULL; SO = NULL;
} }
TI = tgetstr("ti", &p); /* terminal init and exit */ TI = tgetstr("ti", &p); /* terminal init and exit */
TE = tgetstr("te", &p); TE = tgetstr("te", &p);
#endif #endif
if(CL == NULL || CM == NULL || UP == NULL) if (CL == NULL || CM == NULL || UP == NULL) {
{ puts("Incomplete termcap entry\n");
puts("Incomplete termcap entry\n"); exit(1);
exit(1); }
}
if (CE == NULL) /* will we be able to use clear to EOL? */ if (CE == NULL) /* will we be able to use clear to EOL? */
eolexist = FALSE; eolexist = FALSE;
#if SCROLLCODE #if SCROLLCODE
CS = tgetstr("cs", &p); CS = tgetstr("cs", &p);
SF = tgetstr("sf", &p); SF = tgetstr("sf", &p);
SR = tgetstr("sr", &p); SR = tgetstr("sr", &p);
DL = tgetstr("dl", &p); DL = tgetstr("dl", &p);
AL = tgetstr("al", &p); AL = tgetstr("al", &p);
if (CS && SR) { if (CS && SR) {
if (SF == NULL) /* assume '\n' scrolls forward */ if (SF == NULL) /* assume '\n' scrolls forward */
SF = "\n"; SF = "\n";
term.t_scroll = tcapscroll_reg; term.t_scroll = tcapscroll_reg;
} else if (DL && AL) { } else if (DL && AL) {
term.t_scroll = tcapscroll_delins; term.t_scroll = tcapscroll_delins;
} else { } else {
term.t_scroll = NULL; term.t_scroll = NULL;
} }
#endif #endif
if (p >= &tcapbuf[TCAPSLEN]) if (p >= &tcapbuf[TCAPSLEN]) {
{ puts("Terminal description too big!\n");
puts("Terminal description too big!\n"); exit(1);
exit(1); }
}
#if PKCODE && USE_BROKEN_OPTIMIZATION #if PKCODE && USE_BROKEN_OPTIMIZATION
term_init_ok = 1; term_init_ok = 1;
} }
#endif #endif
ttopen(); ttopen();
} }
#if PKCODE #if PKCODE
tcapclose() tcapclose()
{ {
putpad(tgoto(CM, 0, term.t_nrow)); putpad(tgoto(CM, 0, term.t_nrow));
putpad(TE); putpad(TE);
@ -231,7 +226,6 @@ tcapclose()
#endif #endif
tcapkopen() tcapkopen()
{ {
#if PKCODE #if PKCODE
putpad(TI); putpad(TI);
@ -241,111 +235,109 @@ tcapkopen()
} }
tcapkclose() tcapkclose()
{ {
} }
tcapmove(row, col) tcapmove(row, col)
register int row, col; register int row, col;
{ {
putpad(tgoto(CM, col, row)); putpad(tgoto(CM, col, row));
} }
tcapeeol() tcapeeol()
{ {
putpad(CE); putpad(CE);
} }
tcapeeop() tcapeeop()
{ {
putpad(CL); putpad(CL);
} }
tcaprev(state) /* change reverse video status */ tcaprev(state)
/* change reverse video status */
int state; /* FALSE = normal video, TRUE = reverse video */ int state; /* FALSE = normal video, TRUE = reverse video */
{ {
static int revstate = FALSE; static int revstate = FALSE;
if (state) { if (state) {
if (SO != NULL) if (SO != NULL)
putpad(SO); putpad(SO);
} else } else if (SE != NULL)
if (SE != NULL) putpad(SE);
putpad(SE);
} }
tcapcres() /* change screen resolution */ tcapcres()
{ /* change screen resolution */
{ return (TRUE);
return(TRUE);
} }
#if SCROLLCODE #if SCROLLCODE
/* move howmanylines lines starting at from to to */ /* move howmanylines lines starting at from to to */
tcapscroll_reg(from,to,howmanylines) tcapscroll_reg(from, to, howmanylines)
{ {
int i; int i;
if (to == from) return; if (to == from)
if (to < from) { return;
tcapscrollregion(to, from + howmanylines - 1); if (to < from) {
tcapmove(from + howmanylines - 1,0); tcapscrollregion(to, from + howmanylines - 1);
for (i = from - to; i > 0; i--) tcapmove(from + howmanylines - 1, 0);
putpad(SF); for (i = from - to; i > 0; i--)
} else { /* from < to */ putpad(SF);
tcapscrollregion(from, to + howmanylines - 1); } else { /* from < to */
tcapmove(from,0); tcapscrollregion(from, to + howmanylines - 1);
for (i = to - from; i > 0; i--) tcapmove(from, 0);
putpad(SR); for (i = to - from; i > 0; i--)
} putpad(SR);
}
tcapscrollregion(0, term.t_nrow); tcapscrollregion(0, term.t_nrow);
} }
/* move howmanylines lines starting at from to to */ /* move howmanylines lines starting at from to to */
tcapscroll_delins(from,to,howmanylines) tcapscroll_delins(from, to, howmanylines)
{ {
int i; int i;
if (to == from) return; if (to == from)
if (to < from) { return;
tcapmove(to,0); if (to < from) {
for (i = from - to; i > 0; i--) tcapmove(to, 0);
putpad(DL); for (i = from - to; i > 0; i--)
tcapmove(to+howmanylines,0); putpad(DL);
for (i = from - to; i > 0; i--) tcapmove(to + howmanylines, 0);
putpad(AL); for (i = from - to; i > 0; i--)
} else { putpad(AL);
tcapmove(from+howmanylines,0); } else {
for (i = to - from; i > 0; i--) tcapmove(from + howmanylines, 0);
putpad(DL); for (i = to - from; i > 0; i--)
tcapmove(from,0); putpad(DL);
for (i = to - from; i > 0; i--) tcapmove(from, 0);
putpad(AL); for (i = to - from; i > 0; i--)
} putpad(AL);
}
} }
/* cs is set up just like cm, so we use tgoto... */ /* cs is set up just like cm, so we use tgoto... */
tcapscrollregion(top,bot) tcapscrollregion(top, bot)
{ {
ttputc(PC); ttputc(PC);
putpad(tgoto(CS, bot, top)); putpad(tgoto(CS, bot, top));
} }
#endif #endif
spal(dummy) /* change palette string */ spal(dummy)
{ /* change palette string */
{ /* Does nothing here */
/* Does nothing here */
} }
#if COLOR #if COLOR
tcapfcol() /* no colors here, ignore this */ tcapfcol()
{ { /* no colors here, ignore this */
} }
tcapbcol() /* no colors here, ignore this */ tcapbcol()
{ { /* no colors here, ignore this */
} }
#endif #endif
@ -355,26 +347,26 @@ tcapbeep()
} }
putpad(str) putpad(str)
char *str; char *str;
{ {
tputs(str, 1, ttputc); tputs(str, 1, ttputc);
} }
putnpad(str, n) putnpad(str, n)
char *str; char *str;
{ {
tputs(str, n, ttputc); tputs(str, n, ttputc);
} }
#if FNLABEL #if FNLABEL
fnclabel(f, n) /* label a function key */ fnclabel(f, n)
/* label a function key */
int f,n; /* default flag, numeric argument [unused] */ int f, n; /* default flag, numeric argument [unused] */
{ {
/* on machines with no function keys...don't bother */ /* on machines with no function keys...don't bother */
return(TRUE); return (TRUE);
} }
#endif #endif
#else #else

351
termio.c
View File

@ -9,7 +9,7 @@
*/ */
#ifndef POSIX #ifndef POSIX
#include <stdio.h> #include <stdio.h>
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "edef.h"
@ -22,35 +22,35 @@
#include <ttdef.h> #include <ttdef.h>
#include <tt2def.h> #include <tt2def.h>
#define NIBUF 128 /* Input buffer size */ #define NIBUF 128 /* Input buffer size */
#define NOBUF 1024 /* MM says bug buffers win! */ #define NOBUF 1024 /* MM says bug buffers win! */
#define EFN 0 /* Event flag */ #define EFN 0 /* Event flag */
char obuf[NOBUF]; /* Output buffer */ char obuf[NOBUF]; /* Output buffer */
int nobuf; /* # of bytes in above */ int nobuf; /* # of bytes in above */
char ibuf[NIBUF]; /* Input buffer */ char ibuf[NIBUF]; /* Input buffer */
int nibuf; /* # of bytes in above */ int nibuf; /* # of bytes in above */
int ibufi; /* Read index */ int ibufi; /* Read index */
int oldmode[3]; /* Old TTY mode bits */ int oldmode[3]; /* Old TTY mode bits */
int newmode[3]; /* New TTY mode bits */ int newmode[3]; /* New TTY mode bits */
short iochan; /* TTY I/O channel */ short iochan; /* TTY I/O channel */
#endif #endif
#if MSDOS & (MSC | TURBO) #if MSDOS & (MSC | TURBO)
union REGS rg; /* cpu register for use of DOS calls */ union REGS rg; /* cpu register for use of DOS calls */
int nxtchar = -1; /* character held from type ahead */ int nxtchar = -1; /* character held from type ahead */
#endif #endif
#if USG /* System V */ #if USG /* System V */
#include <signal.h> #include <signal.h>
#include <termio.h> #include <termio.h>
#include <fcntl.h> #include <fcntl.h>
int kbdflgs; /* saved keyboard fd flags */ int kbdflgs; /* saved keyboard fd flags */
int kbdpoll; /* in O_NDELAY mode */ int kbdpoll; /* in O_NDELAY mode */
int kbdqp; /* there is a char in kbdq */ int kbdqp; /* there is a char in kbdq */
char kbdq; /* char we've already read */ char kbdq; /* char we've already read */
struct termio otermio; /* original terminal characteristics */ struct termio otermio; /* original terminal characteristics */
struct termio ntermio; /* charactoristics to use inside */ struct termio ntermio; /* charactoristics to use inside */
#if XONXOFF #if XONXOFF
#define XXMASK 0016000 #define XXMASK 0016000
#endif #endif
@ -59,34 +59,37 @@ struct termio ntermio; /* charactoristics to use inside */
#if V7 | BSD #if V7 | BSD
#include <sgtty.h> /* for stty/gtty functions */ #include <sgtty.h> /* for stty/gtty functions */
#include <signal.h> #include <signal.h>
struct sgttyb ostate; /* saved tty state */ struct sgttyb ostate; /* saved tty state */
struct sgttyb nstate; /* values for editor mode */ struct sgttyb nstate; /* values for editor mode */
struct tchars otchars; /* Saved terminal special character set */ struct tchars otchars; /* Saved terminal special character set */
#if XONXOFF #if XONXOFF
struct tchars ntchars = { 0xff, 0xff, 0x11, 0x13, 0xff, 0xff }; struct tchars ntchars = { 0xff, 0xff, 0x11, 0x13, 0xff, 0xff };
/* A lot of nothing and XON/XOFF */ /* A lot of nothing and XON/XOFF */
#else #else
struct tchars ntchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; struct tchars ntchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
/* A lot of nothing */ /* A lot of nothing */
#endif #endif
#if BSD & PKCODE #if BSD & PKCODE
struct ltchars oltchars; /* Saved terminal local special character set */ struct ltchars oltchars; /* Saved terminal local special character set */
struct ltchars nltchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; struct ltchars nltchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
/* A lot of nothing */ /* A lot of nothing */
#endif #endif
#if BSD #if BSD
#include <sys/ioctl.h> /* to get at the typeahead */ #include <sys/ioctl.h> /* to get at the typeahead */
extern int rtfrmshell(); /* return from suspended shell */ extern int rtfrmshell(); /* return from suspended shell */
#define TBUFSIZ 128 #define TBUFSIZ 128
char tobuf[TBUFSIZ]; /* terminal output buffer */ char tobuf[TBUFSIZ]; /* terminal output buffer */
#endif #endif
#endif #endif
#if __hpux | SVR4 #if __hpux | SVR4
extern int rtfrmshell(); /* return from suspended shell */ extern int rtfrmshell(); /* return from suspended shell */
#define TBUFSIZ 128 #define TBUFSIZ 128
char tobuf[TBUFSIZ]; /* terminal output buffer */ char tobuf[TBUFSIZ]; /* terminal output buffer */
#endif #endif
/* /*
@ -97,51 +100,51 @@ char tobuf[TBUFSIZ]; /* terminal output buffer */
ttopen() ttopen()
{ {
#if VMS #if VMS
struct dsc$descriptor idsc; struct dsc$descriptor idsc;
struct dsc$descriptor odsc; struct dsc$descriptor odsc;
char oname[40]; char oname[40];
int iosb[2]; int iosb[2];
int status; int status;
odsc.dsc$a_pointer = "TT"; odsc.dsc$a_pointer = "TT";
odsc.dsc$w_length = strlen(odsc.dsc$a_pointer); odsc.dsc$w_length = strlen(odsc.dsc$a_pointer);
odsc.dsc$b_dtype = DSC$K_DTYPE_T; odsc.dsc$b_dtype = DSC$K_DTYPE_T;
odsc.dsc$b_class = DSC$K_CLASS_S; odsc.dsc$b_class = DSC$K_CLASS_S;
idsc.dsc$b_dtype = DSC$K_DTYPE_T; idsc.dsc$b_dtype = DSC$K_DTYPE_T;
idsc.dsc$b_class = DSC$K_CLASS_S; idsc.dsc$b_class = DSC$K_CLASS_S;
do { do {
idsc.dsc$a_pointer = odsc.dsc$a_pointer; idsc.dsc$a_pointer = odsc.dsc$a_pointer;
idsc.dsc$w_length = odsc.dsc$w_length; idsc.dsc$w_length = odsc.dsc$w_length;
odsc.dsc$a_pointer = &oname[0]; odsc.dsc$a_pointer = &oname[0];
odsc.dsc$w_length = sizeof(oname); odsc.dsc$w_length = sizeof(oname);
status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc); status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc);
if (status!=SS$_NORMAL && status!=SS$_NOTRAN) if (status != SS$_NORMAL && status != SS$_NOTRAN)
exit(status); exit(status);
if (oname[0] == 0x1B) { if (oname[0] == 0x1B) {
odsc.dsc$a_pointer += 4; odsc.dsc$a_pointer += 4;
odsc.dsc$w_length -= 4; odsc.dsc$w_length -= 4;
} }
} while (status == SS$_NORMAL); } while (status == SS$_NORMAL);
status = SYS$ASSIGN(&odsc, &iochan, 0, 0); status = SYS$ASSIGN(&odsc, &iochan, 0, 0);
if (status != SS$_NORMAL) if (status != SS$_NORMAL)
exit(status); exit(status);
status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0, status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0,
oldmode, sizeof(oldmode), 0, 0, 0, 0); oldmode, sizeof(oldmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL) if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
exit(status); exit(status);
newmode[0] = oldmode[0]; newmode[0] = oldmode[0];
newmode[1] = oldmode[1] | TT$M_NOECHO; newmode[1] = oldmode[1] | TT$M_NOECHO;
#if XONXOFF #if XONXOFF
#else #else
newmode[1] &= ~(TT$M_TTSYNC|TT$M_HOSTSYNC); newmode[1] &= ~(TT$M_TTSYNC | TT$M_HOSTSYNC);
#endif #endif
newmode[2] = oldmode[2] | TT2$M_PASTHRU; newmode[2] = oldmode[2] | TT2$M_PASTHRU;
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0, status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
newmode, sizeof(newmode), 0, 0, 0, 0); newmode, sizeof(newmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL) if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
exit(status); exit(status);
term.t_nrow = (newmode[1]>>24) - 1; term.t_nrow = (newmode[1] >> 24) - 1;
term.t_ncol = newmode[0]>>16; term.t_ncol = newmode[0] >> 16;
#endif #endif
@ -155,7 +158,7 @@ ttopen()
#if USG #if USG
ioctl(0, TCGETA, &otermio); /* save old settings */ ioctl(0, TCGETA, &otermio); /* save old settings */
ntermio.c_iflag = 0; /* setup new settings */ ntermio.c_iflag = 0; /* setup new settings */
#if XONXOFF #if XONXOFF
ntermio.c_iflag = otermio.c_iflag & XXMASK; /* save XON/XOFF P.K. */ ntermio.c_iflag = otermio.c_iflag & XXMASK; /* save XON/XOFF P.K. */
#endif #endif
@ -170,46 +173,46 @@ ttopen()
#else #else
ioctl(0, TCSETA, &ntermio); /* and activate them */ ioctl(0, TCSETA, &ntermio); /* and activate them */
#endif #endif
kbdflgs = fcntl( 0, F_GETFL, 0 ); kbdflgs = fcntl(0, F_GETFL, 0);
kbdpoll = FALSE; kbdpoll = FALSE;
#endif #endif
#if V7 | BSD #if V7 | BSD
gtty(0, &ostate); /* save old state */ gtty(0, &ostate); /* save old state */
gtty(0, &nstate); /* get base of new state */ gtty(0, &nstate); /* get base of new state */
#if XONXOFF #if XONXOFF
nstate.sg_flags |= (CBREAK|TANDEM); nstate.sg_flags |= (CBREAK | TANDEM);
#else #else
nstate.sg_flags |= RAW; nstate.sg_flags |= RAW;
#endif #endif
nstate.sg_flags &= ~(ECHO|CRMOD); /* no echo for now... */ nstate.sg_flags &= ~(ECHO | CRMOD); /* no echo for now... */
stty(0, &nstate); /* set mode */ stty(0, &nstate); /* set mode */
ioctl(0, TIOCGETC, &otchars); /* Save old characters */ ioctl(0, TIOCGETC, &otchars); /* Save old characters */
ioctl(0, TIOCSETC, &ntchars); /* Place new character into K */ ioctl(0, TIOCSETC, &ntchars); /* Place new character into K */
#if BSD & PKCODE #if BSD & PKCODE
ioctl(0, TIOCGLTC, &oltchars); /* Save old local characters */ ioctl(0, TIOCGLTC, &oltchars); /* Save old local characters */
ioctl(0, TIOCSLTC, &nltchars); /* New local characters */ ioctl(0, TIOCSLTC, &nltchars); /* New local characters */
#endif #endif
#if BSD #if BSD
/* provide a smaller terminal output buffer so that /* provide a smaller terminal output buffer so that
the type ahead detection works better (more often) */ the type ahead detection works better (more often) */
setbuffer(stdout, &tobuf[0], TBUFSIZ); setbuffer(stdout, &tobuf[0], TBUFSIZ);
signal(SIGTSTP,SIG_DFL); /* set signals so that we can */ signal(SIGTSTP, SIG_DFL); /* set signals so that we can */
signal(SIGCONT,rtfrmshell); /* suspend & restart emacs */ signal(SIGCONT, rtfrmshell); /* suspend & restart emacs */
#endif #endif
#endif #endif
#if __hpux | SVR4 #if __hpux | SVR4
/* provide a smaller terminal output buffer so that /* provide a smaller terminal output buffer so that
the type ahead detection works better (more often) */ the type ahead detection works better (more often) */
setvbuf(stdout, &tobuf[0], _IOFBF, TBUFSIZ); setvbuf(stdout, &tobuf[0], _IOFBF, TBUFSIZ);
signal(SIGTSTP,SIG_DFL); /* set signals so that we can */ signal(SIGTSTP, SIG_DFL); /* set signals so that we can */
signal(SIGCONT,rtfrmshell); /* suspend & restart emacs */ signal(SIGCONT, rtfrmshell); /* suspend & restart emacs */
TTflush(); TTflush();
#endif /* __hpux */ #endif /* __hpux */
/* on all screens we are not sure of the initial position /* on all screens we are not sure of the initial position
of the cursor */ of the cursor */
ttrow = 999; ttrow = 999;
ttcol = 999; ttcol = 999;
} }
@ -222,17 +225,17 @@ ttopen()
ttclose() ttclose()
{ {
#if VMS #if VMS
int status; int status;
int iosb[1]; int iosb[1];
ttflush(); ttflush();
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0, status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
oldmode, sizeof(oldmode), 0, 0, 0, 0); oldmode, sizeof(oldmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL) if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
exit(status); exit(status);
status = SYS$DASSGN(iochan); status = SYS$DASSGN(iochan);
if (status != SS$_NORMAL) if (status != SS$_NORMAL)
exit(status); exit(status);
#endif #endif
#if MSDOS & (TURBO | (PKCODE & MSC)) #if MSDOS & (TURBO | (PKCODE & MSC))
/* restore the CONTROL-break interupt */ /* restore the CONTROL-break interupt */
@ -252,7 +255,7 @@ ttclose()
#endif #endif
#if V7 | BSD #if V7 | BSD
stty(0, &ostate); stty(0, &ostate);
ioctl(0, TIOCSETC, &otchars); /* Place old character into K */ ioctl(0, TIOCSETC, &otchars); /* Place old character into K */
#if BSD & PKCODE #if BSD & PKCODE
ioctl(0, TIOCSLTC, &oltchars); /* Place old local character into K */ ioctl(0, TIOCSLTC, &oltchars); /* Place old local character into K */
@ -269,9 +272,9 @@ ttclose()
ttputc(c) ttputc(c)
{ {
#if VMS #if VMS
if (nobuf >= NOBUF) if (nobuf >= NOBUF)
ttflush(); ttflush();
obuf[nobuf++] = c; obuf[nobuf++] = c;
#endif #endif
#if MSDOS & ~IBMPC #if MSDOS & ~IBMPC
@ -279,7 +282,7 @@ ttputc(c)
#endif #endif
#if V7 | USG | BSD #if V7 | USG | BSD
fputc(c, stdout); fputc(c, stdout);
#endif #endif
} }
@ -290,18 +293,19 @@ ttputc(c)
ttflush() ttflush()
{ {
#if VMS #if VMS
int status; int status;
int iosb[2]; int iosb[2];
status = SS$_NORMAL; status = SS$_NORMAL;
if (nobuf != 0) { if (nobuf != 0) {
status = SYS$QIOW(EFN, iochan, IO$_WRITELBLK|IO$M_NOFORMAT, status =
iosb, 0, 0, obuf, nobuf, 0, 0, 0, 0); SYS$QIOW(EFN, iochan, IO$_WRITELBLK | IO$M_NOFORMAT,
if (status == SS$_NORMAL) iosb, 0, 0, obuf, nobuf, 0, 0, 0, 0);
status = iosb[0] & 0xFFFF; if (status == SS$_NORMAL)
nobuf = 0; status = iosb[0] & 0xFFFF;
} nobuf = 0;
return (status); }
return (status);
#endif #endif
#if MSDOS #if MSDOS
@ -318,15 +322,15 @@ ttflush()
* jph, 8-Oct-1993 * jph, 8-Oct-1993
*/ */
#include <errno.h> #include <errno.h>
int status; int status;
status = fflush(stdout); status = fflush(stdout);
if (status != 0 && errno != EAGAIN) { if (status != 0 && errno != EAGAIN) {
exit(errno); exit(errno);
} }
#endif #endif
} }
@ -338,69 +342,68 @@ ttflush()
ttgetc() ttgetc()
{ {
#if VMS #if VMS
int status; int status;
int iosb[2]; int iosb[2];
int term[2]; int term[2];
while (ibufi >= nibuf) { while (ibufi >= nibuf) {
ibufi = 0; ibufi = 0;
term[0] = 0; term[0] = 0;
term[1] = 0; term[1] = 0;
status = SYS$QIOW(EFN, iochan, IO$_READLBLK|IO$M_TIMED, status = SYS$QIOW(EFN, iochan, IO$_READLBLK | IO$M_TIMED,
iosb, 0, 0, ibuf, NIBUF, 0, term, 0, 0); iosb, 0, 0, ibuf, NIBUF, 0, term, 0, 0);
if (status != SS$_NORMAL) if (status != SS$_NORMAL)
exit(status); exit(status);
status = iosb[0] & 0xFFFF; status = iosb[0] & 0xFFFF;
if (status!=SS$_NORMAL && status!=SS$_TIMEOUT && if (status != SS$_NORMAL && status != SS$_TIMEOUT &&
status!=SS$_DATAOVERUN) status != SS$_DATAOVERUN)
exit(status); exit(status);
nibuf = (iosb[0]>>16) + (iosb[1]>>16); nibuf = (iosb[0] >> 16) + (iosb[1] >> 16);
if (nibuf == 0) { if (nibuf == 0) {
status = SYS$QIOW(EFN, iochan, IO$_READLBLK, status = SYS$QIOW(EFN, iochan, IO$_READLBLK,
iosb, 0, 0, ibuf, 1, 0, term, 0, 0); iosb, 0, 0, ibuf, 1, 0, term, 0,
if (status != SS$_NORMAL 0);
|| (status = (iosb[0]&0xFFFF)) != SS$_NORMAL) if (status != SS$_NORMAL
|| (status = (iosb[0] & 0xFFFF)) != SS$_NORMAL)
if (status != SS$_DATAOVERUN) if (status != SS$_DATAOVERUN)
exit(status); exit(status);
nibuf = (iosb[0]>>16) + (iosb[1]>>16); nibuf = (iosb[0] >> 16) + (iosb[1] >> 16);
} }
} }
return (ibuf[ibufi++] & 0xFF); /* Allow multinational */ return (ibuf[ibufi++] & 0xFF); /* Allow multinational */
#endif #endif
#if MSDOS & (MSC | TURBO) #if MSDOS & (MSC | TURBO)
int c; /* character read */ int c; /* character read */
/* if a char already is ready, return it */ /* if a char already is ready, return it */
if (nxtchar >= 0) { if (nxtchar >= 0) {
c = nxtchar; c = nxtchar;
nxtchar = -1; nxtchar = -1;
return(c); return (c);
} }
/* call the dos to get a char */ /* call the dos to get a char */
rg.h.ah = 7; /* dos Direct Console Input call */ rg.h.ah = 7; /* dos Direct Console Input call */
intdos(&rg, &rg); intdos(&rg, &rg);
c = rg.h.al; /* grab the char */ c = rg.h.al; /* grab the char */
return(c & 255); return (c & 255);
#endif #endif
#if V7 | BSD #if V7 | BSD
return(255 & fgetc(stdin)); /* 8BIT P.K. */ return (255 & fgetc(stdin)); /* 8BIT P.K. */
#endif #endif
#if USG #if USG
if( kbdqp ) if (kbdqp)
kbdqp = FALSE; kbdqp = FALSE;
else else {
{ if (kbdpoll && fcntl(0, F_SETFL, kbdflgs) < 0)
if( kbdpoll && fcntl( 0, F_SETFL, kbdflgs ) < 0 )
return FALSE; return FALSE;
kbdpoll = FALSE; kbdpoll = FALSE;
while (read(0, &kbdq, 1) != 1) while (read(0, &kbdq, 1) != 1);
;
} }
return ( kbdq & 255 ); return (kbdq & 255);
#endif #endif
} }
@ -410,42 +413,40 @@ ttgetc()
*/ */
typahead() typahead()
{ {
#if MSDOS & (MSC | TURBO) #if MSDOS & (MSC | TURBO)
if (kbhit() != 0) if (kbhit() != 0)
return(TRUE); return (TRUE);
else else
return(FALSE); return (FALSE);
#endif #endif
#if BSD #if BSD
int x; /* holds # of pending chars */ int x; /* holds # of pending chars */
return((ioctl(0,FIONREAD,&x) < 0) ? 0 : x); return ((ioctl(0, FIONREAD, &x) < 0) ? 0 : x);
#endif #endif
#if PKCODE & VMS #if PKCODE & VMS
return(ibufi < nibuf); return (ibufi < nibuf);
#endif #endif
#if USG #if USG
if( !kbdqp ) if (!kbdqp) {
{ if (!kbdpoll && fcntl(0, F_SETFL, kbdflgs | O_NDELAY) < 0)
if( !kbdpoll && fcntl( 0, F_SETFL, kbdflgs | O_NDELAY ) < 0 ) return (FALSE);
return(FALSE);
#if PKCODE #if PKCODE
kbdpoll = 1; kbdpoll = 1;
#endif #endif
kbdqp = (1 == read( 0, &kbdq, 1 )); kbdqp = (1 == read(0, &kbdq, 1));
} }
return ( kbdqp ); return (kbdqp);
#endif #endif
#if !UNIX & !VMS & !MSDOS #if !UNIX & !VMS & !MSDOS
return(FALSE); return (FALSE);
#endif #endif
} }
#endif #endif
#endif /* not POSIX */ #endif /* not POSIX */

292
vmsvt.c
View File

@ -9,17 +9,17 @@
* modified by Petri Kutvonen * modified by Petri Kutvonen
*/ */
#include <stdio.h> /* Standard I/O package */ #include <stdio.h> /* Standard I/O package */
#include "estruct.h" /* Emacs' structures */ #include "estruct.h" /* Emacs' structures */
#include "edef.h" /* Emacs' definitions */ #include "edef.h" /* Emacs' definitions */
#if VMSVT #if VMSVT
#include <descrip.h> /* Descriptor definitions */ #include <descrip.h> /* Descriptor definitions */
/* These would normally come from iodef.h and ttdef.h */ /* These would normally come from iodef.h and ttdef.h */
#define IO$_SENSEMODE 0x27 /* Sense mode of terminal */ #define IO$_SENSEMODE 0x27 /* Sense mode of terminal */
#define TT$_UNKNOWN 0x00 /* Unknown terminal */ #define TT$_UNKNOWN 0x00 /* Unknown terminal */
#define TT$_VT100 96 #define TT$_VT100 96
/** Forward references **/ /** Forward references **/
@ -34,8 +34,8 @@ int vmsfcol(), vmsbcol();
#endif #endif
/** SMG stuff **/ /** SMG stuff **/
static char * begin_reverse, * end_reverse, * erase_to_end_line; static char *begin_reverse, *end_reverse, *erase_to_end_line;
static char * erase_whole_display; static char *erase_whole_display;
static int termtype; static int termtype;
#define SMG$K_BEGIN_REVERSE 0x1bf #define SMG$K_BEGIN_REVERSE 0x1bf
@ -46,7 +46,7 @@ static int termtype;
#if SCROLLCODE #if SCROLLCODE
#define SMG$K_SCROLL_FORWARD 561 /* from sys$library:smgtrmptr.h */ #define SMG$K_SCROLL_FORWARD 561 /* from sys$library:smgtrmptr.h */
#define SMG$K_SCROLL_REVERSE 562 #define SMG$K_SCROLL_REVERSE 562
#define SMG$K_SET_SCROLL_REGION 572 #define SMG$K_SET_SCROLL_REGION 572
@ -55,37 +55,39 @@ static char *scroll_forward, *scroll_reverse;
#endif #endif
/* Dispatch table. All hard fields just point into the terminal I/O code. */ /* Dispatch table. All hard fields just point into the terminal I/O code. */
TERM term = { TERM term = {
#if PKCODE #if PKCODE
MAXROW, MAXROW,
#else #else
24 - 1, /* Max number of rows allowable */ 24 - 1, /* Max number of rows allowable */
#endif #endif
/* Filled in */ - 1, /* Current number of rows used */ /* Filled in */ -1,
MAXCOL, /* Max number of columns */ /* Current number of rows used */
/* Filled in */ 0, /* Current number of columns */ MAXCOL, /* Max number of columns */
64, /* Min margin for extended lines*/ /* Filled in */ 0,
8, /* Size of scroll region */ /* Current number of columns */
100, /* # times thru update to pause */ 64, /* Min margin for extended lines */
vmsopen, /* Open terminal at the start */ 8, /* Size of scroll region */
ttclose, /* Close terminal at end */ 100, /* # times thru update to pause */
vmskopen, /* Open keyboard */ vmsopen, /* Open terminal at the start */
vmskclose, /* Close keyboard */ ttclose, /* Close terminal at end */
ttgetc, /* Get character from keyboard */ vmskopen, /* Open keyboard */
ttputc, /* Put character to display */ vmskclose, /* Close keyboard */
ttflush, /* Flush output buffers */ ttgetc, /* Get character from keyboard */
vmsmove, /* Move cursor, origin 0 */ ttputc, /* Put character to display */
vmseeol, /* Erase to end of line */ ttflush, /* Flush output buffers */
vmseeop, /* Erase to end of page */ vmsmove, /* Move cursor, origin 0 */
vmsbeep, /* Beep */ vmseeol, /* Erase to end of line */
vmsrev, /* Set reverse video state */ vmseeop, /* Erase to end of page */
vmscres /* Change screen resolution */ vmsbeep, /* Beep */
vmsrev, /* Set reverse video state */
vmscres /* Change screen resolution */
#if COLOR #if COLOR
, vmsfcol, /* Set forground color */ , vmsfcol, /* Set forground color */
vmsbcol /* Set background color */ vmsbcol /* Set background color */
#endif #endif
#if SCROLLCODE #if SCROLLCODE
, NULL , NULL
#endif #endif
}; };
@ -95,7 +97,7 @@ TERM term = {
* Nothing returned * Nothing returned
***/ ***/
ttputs(string) ttputs(string)
char * string; /* String to write */ char *string; /* String to write */
{ {
if (string) if (string)
while (*string != '\0') while (*string != '\0')
@ -109,16 +111,16 @@ char * string; /* String to write */
* Nothing returned * Nothing returned
***/ ***/
vmsmove(row, col) vmsmove(row, col)
int row; /* Row position */ int row; /* Row position */
int col; /* Column position */ int col; /* Column position */
{ {
char buffer[32]; char buffer[32];
int ret_length; int ret_length;
static int request_code = SMG$K_SET_CURSOR_ABS; static int request_code = SMG$K_SET_CURSOR_ABS;
static int max_buffer_length = sizeof(buffer); static int max_buffer_length = sizeof(buffer);
static int arg_list[3] = { 2 }; static int arg_list[3] = { 2 };
register char * cp; register char *cp;
register int i; register int i;
/* Set the arguments into the arg_list array /* Set the arguments into the arg_list array
@ -127,21 +129,22 @@ int col; /* Column position */
arg_list[1] = row + 1; arg_list[1] = row + 1;
arg_list[2] = col + 1; arg_list[2] = col + 1;
if ((smg$get_term_data( /* Get terminal data */ if ((smg$get_term_data( /* Get terminal data */
&termtype, /* Terminal table address */ &termtype, /* Terminal table address */
&request_code, /* Request code */ &request_code, /* Request code */
&max_buffer_length, /* Maximum buffer length */ &max_buffer_length, /* Maximum buffer length */
&ret_length, /* Return length */ &ret_length, /* Return length */
buffer, /* Capability data buffer */ buffer, /* Capability data buffer */
arg_list) /* Argument list array */ arg_list)
/* We'll know soon enough if this doesn't work */ /* Argument list array */
& 1) == 0) { /* We'll know soon enough if this doesn't work */
ttputs("OOPS"); &1) == 0) {
return; ttputs("OOPS");
} return;
}
/* Send out resulting sequence */ /* Send out resulting sequence */
i = ret_length; i = ret_length;
cp = buffer; cp = buffer;
while (i-- > 0) while (i-- > 0)
@ -150,35 +153,36 @@ int col; /* Column position */
#if SCROLLCODE #if SCROLLCODE
vmsscroll_reg(from,to,howmany) vmsscroll_reg(from, to, howmany)
{ {
int i; int i;
if (to == from) return; if (to == from)
if (to < from) { return;
vmsscrollregion(to, from + howmany - 1); if (to < from) {
vmsmove(from + howmany - 1,0); vmsscrollregion(to, from + howmany - 1);
for (i = from - to; i > 0; i--) vmsmove(from + howmany - 1, 0);
ttputs(scroll_forward); for (i = from - to; i > 0; i--)
} else { /* from < to */ ttputs(scroll_forward);
vmsscrollregion(from, to + howmany - 1); } else { /* from < to */
vmsmove(from,0); vmsscrollregion(from, to + howmany - 1);
for (i = to - from; i > 0; i--) vmsmove(from, 0);
ttputs(scroll_reverse); for (i = to - from; i > 0; i--)
} ttputs(scroll_reverse);
vmsscrollregion(-1, -1); }
vmsscrollregion(-1, -1);
} }
vmsscrollregion(top, bot) vmsscrollregion(top, bot)
int top; /* Top position */ int top; /* Top position */
int bot; /* Bottom position */ int bot; /* Bottom position */
{ {
char buffer[32]; char buffer[32];
int ret_length; int ret_length;
static int request_code = SMG$K_SET_SCROLL_REGION; static int request_code = SMG$K_SET_SCROLL_REGION;
static int max_buffer_length = sizeof(buffer); static int max_buffer_length = sizeof(buffer);
static int arg_list[3] = { 2 }; static int arg_list[3] = { 2 };
register char * cp; register char *cp;
register int i; register int i;
/* Set the arguments into the arg_list array /* Set the arguments into the arg_list array
@ -187,22 +191,23 @@ int bot; /* Bottom position */
arg_list[1] = top + 1; arg_list[1] = top + 1;
arg_list[2] = bot + 1; arg_list[2] = bot + 1;
if ((smg$get_term_data( /* Get terminal data */ if ((smg$get_term_data( /* Get terminal data */
&termtype, /* Terminal table address */ &termtype, /* Terminal table address */
&request_code, /* Request code */ &request_code, /* Request code */
&max_buffer_length, /* Maximum buffer length */ &max_buffer_length, /* Maximum buffer length */
&ret_length, /* Return length */ &ret_length, /* Return length */
buffer, /* Capability data buffer */ buffer, /* Capability data buffer */
arg_list) /* Argument list array */ arg_list)
/* We'll know soon enough if this doesn't work */ /* Argument list array */
& 1) == 0) { /* We'll know soon enough if this doesn't work */
ttputs("OOPS"); &1) == 0) {
return; ttputs("OOPS");
} return;
}
ttputc(0); ttputc(0);
/* Send out resulting sequence */ /* Send out resulting sequence */
i = ret_length; i = ret_length;
cp = buffer; cp = buffer;
while (i-- > 0) while (i-- > 0)
@ -216,11 +221,11 @@ int bot; /* Bottom position */
* Nothing returned * Nothing returned
***/ ***/
vmsrev(status) vmsrev(status)
int status; /* TRUE if setting reverse */ int status; /* TRUE if setting reverse */
{ {
if (status) if (status)
ttputs(begin_reverse); ttputs(begin_reverse);
else else
ttputs(end_reverse); ttputs(end_reverse);
} }
@ -232,7 +237,7 @@ int status; /* TRUE if setting reverse */
vmscres() vmscres()
{ {
/* But it could. For vt100/vt200s, one could switch from /* But it could. For vt100/vt200s, one could switch from
80 and 132 columns modes */ 80 and 132 columns modes */
} }
@ -294,56 +299,56 @@ vmsbeep()
* *
* Returns: Escape sequence * Returns: Escape sequence
* NULL No escape sequence available * NULL No escape sequence available
***/ ***/
char * vmsgetstr(request_code) char *vmsgetstr(request_code)
int request_code; /* Request code */ int request_code; /* Request code */
{ {
register char * result; register char *result;
static char seq_storage[1024]; static char seq_storage[1024];
static char * buffer = seq_storage; static char *buffer = seq_storage;
static int arg_list[2] = { 1, 1 }; static int arg_list[2] = { 1, 1 };
int max_buffer_length, ret_length; int max_buffer_length, ret_length;
/* Precompute buffer length */ /* Precompute buffer length */
max_buffer_length = (seq_storage + sizeof(seq_storage)) - buffer; max_buffer_length = (seq_storage + sizeof(seq_storage)) - buffer;
/* Get terminal commands sequence from master table */ /* Get terminal commands sequence from master table */
if ((smg$get_term_data( /* Get terminal data */ if ((smg$get_term_data( /* Get terminal data */
&termtype, /* Terminal table address */ &termtype, /* Terminal table address */
&request_code, /* Request code */ &request_code, /* Request code */
&max_buffer_length,/* Maximum buffer length */ &max_buffer_length, /* Maximum buffer length */
&ret_length, /* Return length */ &ret_length, /* Return length */
buffer, /* Capability data buffer */ buffer, /* Capability data buffer */
arg_list) /* Argument list array */ arg_list)
/* If this doesn't work, try again with no arguments */
& 1) == 0 &&
(smg$get_term_data( /* Get terminal data */ /* Argument list array */
&termtype, /* Terminal table address */ /* If this doesn't work, try again with no arguments */
&request_code, /* Request code */ &1) == 0 && (smg$get_term_data( /* Get terminal data */
&max_buffer_length,/* Maximum buffer length */ &termtype, /* Terminal table address */
&ret_length, /* Return length */ &request_code, /* Request code */
buffer) /* Capability data buffer */ &max_buffer_length, /* Maximum buffer length */
&ret_length, /* Return length */
buffer)
/* Return NULL pointer if capability is not available */
& 1) == 0) /* Capability data buffer */
return NULL; /* Return NULL pointer if capability is not available */
&1) == 0)
return NULL;
/* Check for empty result */ /* Check for empty result */
if (ret_length == 0) if (ret_length == 0)
return NULL; return NULL;
/* Save current position so we can return it to caller */ /* Save current position so we can return it to caller */
result = buffer; result = buffer;
/* NIL terminate the sequence for return */ /* NIL terminate the sequence for return */
buffer[ret_length] = 0; buffer[ret_length] = 0;
/* Advance buffer */ /* Advance buffer */
@ -356,19 +361,19 @@ int request_code; /* Request code */
/** I/O information block definitions **/ /** I/O information block definitions **/
struct iosb { /* I/O status block */ struct iosb { /* I/O status block */
short i_cond; /* Condition value */ short i_cond; /* Condition value */
short i_xfer; /* Transfer count */ short i_xfer; /* Transfer count */
long i_info; /* Device information */ long i_info; /* Device information */
}; };
struct termchar { /* Terminal characteristics */ struct termchar { /* Terminal characteristics */
char t_class; /* Terminal class */ char t_class; /* Terminal class */
char t_type; /* Terminal type */ char t_type; /* Terminal type */
short t_width; /* Terminal width in characters */ short t_width; /* Terminal width in characters */
long t_mandl; /* Terminal's mode and length */ long t_mandl; /* Terminal's mode and length */
long t_extend; /* Extended terminal characteristics */ long t_extend; /* Extended terminal characteristics */
}; };
static struct termchar tc; /* Terminal characteristics */ static struct termchar tc; /* Terminal characteristics */
/*** /***
* vmsgtty - Get terminal type from system control block * vmsgtty - Get terminal type from system control block
@ -385,18 +390,18 @@ vmsgtty()
/* Assign input to a channel */ /* Assign input to a channel */
status = sys$assign(&devnam, &fd, 0, 0); status = sys$assign(&devnam, &fd, 0, 0);
if ((status & 1) == 0) if ((status & 1) == 0)
exit (status); exit(status);
/* Get terminal characteristics */ /* Get terminal characteristics */
status = sys$qiow( /* Queue and wait */ status = sys$qiow( /* Queue and wait */
0, /* Wait on event flag zero */ 0, /* Wait on event flag zero */
fd, /* Channel to input terminal */ fd, /* Channel to input terminal */
IO$_SENSEMODE, /* Get current characteristic */ IO$_SENSEMODE, /* Get current characteristic */
&iostatus, /* Status after operation */ &iostatus, /* Status after operation */
0, 0, /* No AST service */ 0, 0, /* No AST service */
&tc, /* Terminal characteristics buf */ &tc, /* Terminal characteristics buf */
sizeof(tc), /* Size of the buffer */ sizeof(tc), /* Size of the buffer */
0, 0, 0, 0); /* P3-P6 unused */ 0, 0, 0, 0); /* P3-P6 unused */
/* De-assign the input device */ /* De-assign the input device */
if ((sys$dassgn(fd) & 1) == 0) if ((sys$dassgn(fd) & 1) == 0)
@ -421,16 +426,17 @@ vmsopen()
vmsgtty(); vmsgtty();
if (tc.t_type == TT$_UNKNOWN) { if (tc.t_type == TT$_UNKNOWN) {
printf("Terminal type is unknown!\n"); printf("Terminal type is unknown!\n");
printf("Try set your terminal type with SET TERMINAL/INQUIRE\n"); printf
("Try set your terminal type with SET TERMINAL/INQUIRE\n");
printf("Or get help on SET TERMINAL/DEVICE_TYPE\n"); printf("Or get help on SET TERMINAL/DEVICE_TYPE\n");
exit(3); exit(3);
} }
/* Access the system terminal definition table for the */ /* Access the system terminal definition table for the */
/* information of the terminal type returned by IO$_SENSEMODE */ /* information of the terminal type returned by IO$_SENSEMODE */
if ((smg$init_term_table_by_type(&tc.t_type, &termtype) & 1) == 0) if ((smg$init_term_table_by_type(&tc.t_type, &termtype) & 1) == 0)
return -1; return -1;
/* Set sizes */ /* Set sizes */
term.t_nrow = ((unsigned int) tc.t_mandl >> 24) - 1; term.t_nrow = ((unsigned int) tc.t_mandl >> 24) - 1;
term.t_ncol = tc.t_width; term.t_ncol = tc.t_width;
@ -446,8 +452,8 @@ vmsopen()
#if SCROLLCODE #if SCROLLCODE
scroll_forward = vmsgetstr(SMG$K_SCROLL_FORWARD); scroll_forward = vmsgetstr(SMG$K_SCROLL_FORWARD);
scroll_reverse = vmsgetstr(SMG$K_SCROLL_REVERSE); scroll_reverse = vmsgetstr(SMG$K_SCROLL_REVERSE);
if (tc.t_type < TT$_VT100 || scroll_reverse == NULL || if (tc.t_type < TT$_VT100 || scroll_reverse == NULL ||
scroll_forward == NULL) scroll_forward == NULL)
term.t_scroll = NULL; term.t_scroll = NULL;
else else
term.t_scroll = vmsscroll_reg; term.t_scroll = vmsscroll_reg;
@ -487,11 +493,11 @@ vmskclose()
* Nothing returned * Nothing returned
***/ ***/
#if FNLABEL #if FNLABEL
fnclabel(f, n) /* label a function key */ fnclabel(f, n) /* label a function key */
int f,n; /* default flag, numeric argument [unused] */ int f, n; /* default flag, numeric argument [unused] */
{ {
/* on machines with no function keys...don't bother */ /* on machines with no function keys...don't bother */
return(TRUE); return (TRUE);
} }
#endif #endif

167
vt52.c
View File

@ -11,7 +11,7 @@
* modified by Petri Kutvonen * modified by Petri Kutvonen
*/ */
#define termdef 1 /* don't define "term" external */ #define termdef 1 /* don't define "term" external */
#include <stdio.h> #include <stdio.h>
#include "estruct.h" #include "estruct.h"
@ -19,33 +19,33 @@
#if VT52 #if VT52
#define NROW 24 /* Screen size. */ #define NROW 24 /* Screen size. */
#define NCOL 80 /* Edit if you want to. */ #define NCOL 80 /* Edit if you want to. */
#define MARGIN 8 /* size of minimim margin and */ #define MARGIN 8 /* size of minimim margin and */
#define SCRSIZ 64 /* scroll size for extended lines */ #define SCRSIZ 64 /* scroll size for extended lines */
#define NPAUSE 100 /* # times thru update to pause */ #define NPAUSE 100 /* # times thru update to pause */
#define BIAS 0x20 /* Origin 0 coordinate bias. */ #define BIAS 0x20 /* Origin 0 coordinate bias. */
#define ESC 0x1B /* ESC character. */ #define ESC 0x1B /* ESC character. */
#define BEL 0x07 /* ascii bell character */ #define BEL 0x07 /* ascii bell character */
extern int ttopen(); /* Forward references. */ extern int ttopen(); /* Forward references. */
extern int ttgetc(); extern int ttgetc();
extern int ttputc(); extern int ttputc();
extern int ttflush(); extern int ttflush();
extern int ttclose(); extern int ttclose();
extern int vt52move(); extern int vt52move();
extern int vt52eeol(); extern int vt52eeol();
extern int vt52eeop(); extern int vt52eeop();
extern int vt52beep(); extern int vt52beep();
extern int vt52open(); extern int vt52open();
extern int vt52rev(); extern int vt52rev();
extern int vt52cres(); extern int vt52cres();
extern int vt52kopen(); extern int vt52kopen();
extern int vt52kclose(); extern int vt52kclose();
#if COLOR #if COLOR
extern int vt52fcol(); extern int vt52fcol();
extern int vt52bcol(); extern int vt52bcol();
#endif #endif
/* /*
@ -53,137 +53,132 @@ extern int vt52bcol();
* hard fields just point into the * hard fields just point into the
* terminal I/O code. * terminal I/O code.
*/ */
TERM term = { TERM term = {
NROW-1, NROW - 1,
NROW-1, NROW - 1,
NCOL, NCOL,
NCOL, NCOL,
MARGIN, MARGIN,
SCRSIZ, SCRSIZ,
NPAUSE, NPAUSE,
&vt52open, &vt52open,
&ttclose, &ttclose,
&vt52kopen, &vt52kopen,
&vt52kclose, &vt52kclose,
&ttgetc, &ttgetc,
&ttputc, &ttputc,
&ttflush, &ttflush,
&vt52move, &vt52move,
&vt52eeol, &vt52eeol,
&vt52eeop, &vt52eeop,
&vt52beep, &vt52beep,
&vt52rev, &vt52rev,
&vt52cres &vt52cres
#if COLOR #if COLOR
, &vt52fcol, , &vt52fcol,
&vt52bcol &vt52bcol
#endif #endif
#if SCROLLCODE #if SCROLLCODE
, NULL , NULL
#endif #endif
}; };
vt52move(row, col) vt52move(row, col)
{ {
ttputc(ESC); ttputc(ESC);
ttputc('Y'); ttputc('Y');
ttputc(row+BIAS); ttputc(row + BIAS);
ttputc(col+BIAS); ttputc(col + BIAS);
} }
vt52eeol() vt52eeol()
{ {
ttputc(ESC); ttputc(ESC);
ttputc('K'); ttputc('K');
} }
vt52eeop() vt52eeop()
{ {
ttputc(ESC); ttputc(ESC);
ttputc('J'); ttputc('J');
} }
vt52rev(status) /* set the reverse video state */ vt52rev(status)
/* set the reverse video state */
int status; /* TRUE = reverse video, FALSE = normal video */ int status; /* TRUE = reverse video, FALSE = normal video */
{ {
/* can't do this here, so we won't */ /* can't do this here, so we won't */
} }
vt52cres() /* change screen resolution - (not here though) */ vt52cres()
{ /* change screen resolution - (not here though) */
{ return (TRUE);
return(TRUE);
} }
spal() /* change palette string */ spal()
{ /* change palette string */
{ /* Does nothing here */
/* Does nothing here */
} }
#if COLOR #if COLOR
vt52fcol() /* set the forground color [NOT IMPLIMENTED] */ vt52fcol()
{ { /* set the forground color [NOT IMPLIMENTED] */
} }
vt52bcol() /* set the background color [NOT IMPLIMENTED] */ vt52bcol()
{ { /* set the background color [NOT IMPLIMENTED] */
} }
#endif #endif
vt52beep() vt52beep()
{ {
#ifdef BEL #ifdef BEL
ttputc(BEL); ttputc(BEL);
ttflush(); ttflush();
#endif #endif
} }
vt52open() vt52open()
{ {
#if V7 | BSD #if V7 | BSD
register char *cp; register char *cp;
char *getenv(); char *getenv();
if ((cp = getenv("TERM")) == NULL) { if ((cp = getenv("TERM")) == NULL) {
puts("Shell variable TERM not defined!"); puts("Shell variable TERM not defined!");
exit(1); exit(1);
} }
if (strcmp(cp, "vt52") != 0 && strcmp(cp, "z19") != 0) { if (strcmp(cp, "vt52") != 0 && strcmp(cp, "z19") != 0) {
puts("Terminal type not 'vt52'or 'z19' !"); puts("Terminal type not 'vt52'or 'z19' !");
exit(1); exit(1);
} }
#endif #endif
ttopen(); ttopen();
} }
vt52kopen() vt52kopen()
{ {
} }
vt52kclose() vt52kclose()
{ {
} }
#if FNLABEL #if FNLABEL
fnclabel(f, n) /* label a function key */ fnclabel(f, n)
/* label a function key */
int f,n; /* default flag, numeric argument [unused] */ int f, n; /* default flag, numeric argument [unused] */
{ {
/* on machines with no function keys...don't bother */ /* on machines with no function keys...don't bother */
return(TRUE); return (TRUE);
} }
#endif #endif
#else #else
vt52hello() vt52hello()
{ {
} }

601
window.c
View File

@ -16,30 +16,29 @@
* redisplay code does). With no argument it defaults to 0. Bound to M-!. * redisplay code does). With no argument it defaults to 0. Bound to M-!.
*/ */
reposition(f, n) reposition(f, n)
{ {
if (f == FALSE) /* default to 0 to center screen */ if (f == FALSE) /* default to 0 to center screen */
n = 0; n = 0;
curwp->w_force = n; curwp->w_force = n;
curwp->w_flag |= WFFORCE; curwp->w_flag |= WFFORCE;
return (TRUE); return (TRUE);
} }
/* /*
* Refresh the screen. With no argument, it just does the refresh. With an * Refresh the screen. With no argument, it just does the refresh. With an
* argument it recenters "." in the current window. Bound to "C-L". * argument it recenters "." in the current window. Bound to "C-L".
*/ */
refresh(f, n) refresh(f, n)
{ {
if (f == FALSE) if (f == FALSE)
sgarbf = TRUE; sgarbf = TRUE;
else else {
{ curwp->w_force = 0; /* Center dot. */
curwp->w_force = 0; /* Center dot. */ curwp->w_flag |= WFFORCE;
curwp->w_flag |= WFFORCE; }
}
return (TRUE); return (TRUE);
} }
/* /*
* The command make the next window (next => down the screen) the current * The command make the next window (next => down the screen) the current
@ -51,11 +50,11 @@ refresh(f, n)
*/ */
nextwind(f, n) nextwind(f, n)
int f, n; /* default flag and numeric argument */ int f, n; /* default flag and numeric argument */
{ {
register WINDOW *wp; register WINDOW *wp;
register int nwindows; /* total number of windows */ register int nwindows; /* total number of windows */
if (f) { if (f) {
@ -68,7 +67,7 @@ int f, n; /* default flag and numeric argument */
} }
/* if the argument is negative, it is the nth window /* if the argument is negative, it is the nth window
from the bottom of the screen */ from the bottom of the screen */
if (n < 0) if (n < 0)
n = nwindows + n + 1; n = nwindows + n + 1;
@ -79,11 +78,10 @@ int f, n; /* default flag and numeric argument */
wp = wp->w_wndp; wp = wp->w_wndp;
} else { } else {
mlwrite("Window number out of range"); mlwrite("Window number out of range");
return(FALSE); return (FALSE);
} }
} else } else if ((wp = curwp->w_wndp) == NULL)
if ((wp = curwp->w_wndp) == NULL) wp = wheadp;
wp = wheadp;
curwp = wp; curwp = wp;
curbp = wp->w_bufp; curbp = wp->w_bufp;
cknewwindow(); cknewwindow();
@ -103,7 +101,7 @@ prevwind(f, n)
/* if we have an argument, we mean the nth window from the bottom */ /* if we have an argument, we mean the nth window from the bottom */
if (f) if (f)
return(nextwind(f, -n)); return (nextwind(f, -n));
wp1 = wheadp; wp1 = wheadp;
wp2 = curwp; wp2 = curwp;
@ -116,7 +114,7 @@ prevwind(f, n)
curwp = wp1; curwp = wp1;
curbp = wp1->w_bufp; curbp = wp1->w_bufp;
cknewwindow(); cknewwindow();
upmode(); upmode();
return (TRUE); return (TRUE);
} }
@ -144,47 +142,43 @@ int n;
* "C-X C-P". * "C-X C-P".
*/ */
mvupwind(f, n) mvupwind(f, n)
int n; int n;
{ {
register LINE *lp; register LINE *lp;
register int i; register int i;
lp = curwp->w_linep; lp = curwp->w_linep;
if (n < 0) if (n < 0) {
{ while (n++ && lp != curbp->b_linep)
while (n++ && lp!=curbp->b_linep) lp = lforw(lp);
lp = lforw(lp); } else {
} while (n-- && lback(lp) != curbp->b_linep)
else lp = lback(lp);
{ }
while (n-- && lback(lp)!=curbp->b_linep)
lp = lback(lp);
}
curwp->w_linep = lp; curwp->w_linep = lp;
curwp->w_flag |= WFHARD; /* Mode line is OK. */ curwp->w_flag |= WFHARD; /* Mode line is OK. */
for (i = 0; i < curwp->w_ntrows; ++i) for (i = 0; i < curwp->w_ntrows; ++i) {
{ if (lp == curwp->w_dotp)
if (lp == curwp->w_dotp) return (TRUE);
return (TRUE); if (lp == curbp->b_linep)
if (lp == curbp->b_linep) break;
break; lp = lforw(lp);
lp = lforw(lp); }
}
lp = curwp->w_linep; lp = curwp->w_linep;
i = curwp->w_ntrows/2; i = curwp->w_ntrows / 2;
while (i-- && lp != curbp->b_linep) while (i-- && lp != curbp->b_linep)
lp = lforw(lp); lp = lforw(lp);
curwp->w_dotp = lp; curwp->w_dotp = lp;
curwp->w_doto = 0; curwp->w_doto = 0;
return (TRUE); return (TRUE);
} }
/* /*
* This command makes the current window the only window on the screen. Bound * This command makes the current window the only window on the screen. Bound
@ -195,43 +189,43 @@ mvupwind(f, n)
*/ */
onlywind(f, n) onlywind(f, n)
{ {
register WINDOW *wp; register WINDOW *wp;
register LINE *lp; register LINE *lp;
register int i; register int i;
while (wheadp != curwp) { while (wheadp != curwp) {
wp = wheadp; wp = wheadp;
wheadp = wp->w_wndp; wheadp = wp->w_wndp;
if (--wp->w_bufp->b_nwnd == 0) { if (--wp->w_bufp->b_nwnd == 0) {
wp->w_bufp->b_dotp = wp->w_dotp; wp->w_bufp->b_dotp = wp->w_dotp;
wp->w_bufp->b_doto = wp->w_doto; wp->w_bufp->b_doto = wp->w_doto;
wp->w_bufp->b_markp = wp->w_markp; wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko; wp->w_bufp->b_marko = wp->w_marko;
} }
free((char *) wp); free((char *) wp);
} }
while (curwp->w_wndp != NULL) { while (curwp->w_wndp != NULL) {
wp = curwp->w_wndp; wp = curwp->w_wndp;
curwp->w_wndp = wp->w_wndp; curwp->w_wndp = wp->w_wndp;
if (--wp->w_bufp->b_nwnd == 0) { if (--wp->w_bufp->b_nwnd == 0) {
wp->w_bufp->b_dotp = wp->w_dotp; wp->w_bufp->b_dotp = wp->w_dotp;
wp->w_bufp->b_doto = wp->w_doto; wp->w_bufp->b_doto = wp->w_doto;
wp->w_bufp->b_markp = wp->w_markp; wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko; wp->w_bufp->b_marko = wp->w_marko;
} }
free((char *) wp); free((char *) wp);
} }
lp = curwp->w_linep; lp = curwp->w_linep;
i = curwp->w_toprow; i = curwp->w_toprow;
while (i!=0 && lback(lp)!=curbp->b_linep) { while (i != 0 && lback(lp) != curbp->b_linep) {
--i; --i;
lp = lback(lp); lp = lback(lp);
} }
curwp->w_toprow = 0; curwp->w_toprow = 0;
curwp->w_ntrows = term.t_nrow-1; curwp->w_ntrows = term.t_nrow - 1;
curwp->w_linep = lp; curwp->w_linep = lp;
curwp->w_flag |= WFMODE|WFHARD; curwp->w_flag |= WFMODE | WFHARD;
return (TRUE); return (TRUE);
} }
/* /*
@ -239,9 +233,9 @@ onlywind(f, n)
* or, if it is the top window, the window below. Bound to C-X 0. * or, if it is the top window, the window below. Bound to C-X 0.
*/ */
delwind(f,n) delwind(f, n)
int f, n; /* arguments are ignored for this command */ int f, n; /* arguments are ignored for this command */
{ {
register WINDOW *wp; /* window to recieve deleted space */ register WINDOW *wp; /* window to recieve deleted space */
@ -251,7 +245,7 @@ int f, n; /* arguments are ignored for this command */
/* if there is only one window, don't delete it */ /* if there is only one window, don't delete it */
if (wheadp->w_wndp == NULL) { if (wheadp->w_wndp == NULL) {
mlwrite("Can not delete this window"); mlwrite("Can not delete this window");
return(FALSE); return (FALSE);
} }
/* find window before curwp in linked list */ /* find window before curwp in linked list */
@ -275,7 +269,7 @@ int f, n; /* arguments are ignored for this command */
wp = wp->w_wndp; wp = wp->w_wndp;
} }
if (wp == NULL) if (wp == NULL)
return(FALSE); return (FALSE);
wp->w_toprow = 0; wp->w_toprow = 0;
wp->w_ntrows += target; wp->w_ntrows += target;
} else { } else {
@ -287,7 +281,7 @@ int f, n; /* arguments are ignored for this command */
wp = wp->w_wndp; wp = wp->w_wndp;
} }
if (wp == NULL) if (wp == NULL)
return(FALSE); return (FALSE);
wp->w_ntrows += 1 + curwp->w_ntrows; wp->w_ntrows += 1 + curwp->w_ntrows;
} }
@ -302,13 +296,13 @@ int f, n; /* arguments are ignored for this command */
wheadp = curwp->w_wndp; wheadp = curwp->w_wndp;
else else
lwp->w_wndp = curwp->w_wndp; lwp->w_wndp = curwp->w_wndp;
free((char *)curwp); free((char *) curwp);
curwp = wp; curwp = wp;
wp->w_flag |= WFHARD; wp->w_flag |= WFHARD;
curbp = wp->w_bufp; curbp = wp->w_bufp;
cknewwindow(); cknewwindow();
upmode(); upmode();
return(TRUE); return (TRUE);
} }
/* /*
@ -322,82 +316,82 @@ for the new window. Bound to "C-X 2".
*/ */
splitwind(f, n) splitwind(f, n)
int f, n; /* default flag and numeric argument */ int f, n; /* default flag and numeric argument */
{ {
register WINDOW *wp; register WINDOW *wp;
register LINE *lp; register LINE *lp;
register int ntru; register int ntru;
register int ntrl; register int ntrl;
register int ntrd; register int ntrd;
register WINDOW *wp1; register WINDOW *wp1;
register WINDOW *wp2; register WINDOW *wp2;
char *malloc(); char *malloc();
if (curwp->w_ntrows < 3) { if (curwp->w_ntrows < 3) {
mlwrite("Cannot split a %d line window", curwp->w_ntrows); mlwrite("Cannot split a %d line window", curwp->w_ntrows);
return (FALSE); return (FALSE);
} }
if ((wp = (WINDOW *) malloc(sizeof(WINDOW))) == NULL) { if ((wp = (WINDOW *) malloc(sizeof(WINDOW))) == NULL) {
mlwrite("(OUT OF MEMORY)"); mlwrite("(OUT OF MEMORY)");
return (FALSE); return (FALSE);
} }
++curbp->b_nwnd; /* Displayed twice. */ ++curbp->b_nwnd; /* Displayed twice. */
wp->w_bufp = curbp; wp->w_bufp = curbp;
wp->w_dotp = curwp->w_dotp; wp->w_dotp = curwp->w_dotp;
wp->w_doto = curwp->w_doto; wp->w_doto = curwp->w_doto;
wp->w_markp = curwp->w_markp; wp->w_markp = curwp->w_markp;
wp->w_marko = curwp->w_marko; wp->w_marko = curwp->w_marko;
wp->w_flag = 0; wp->w_flag = 0;
wp->w_force = 0; wp->w_force = 0;
#if COLOR #if COLOR
/* set the colors of the new window */ /* set the colors of the new window */
wp->w_fcolor = gfcolor; wp->w_fcolor = gfcolor;
wp->w_bcolor = gbcolor; wp->w_bcolor = gbcolor;
#endif #endif
ntru = (curwp->w_ntrows-1) / 2; /* Upper size */ ntru = (curwp->w_ntrows - 1) / 2; /* Upper size */
ntrl = (curwp->w_ntrows-1) - ntru; /* Lower size */ ntrl = (curwp->w_ntrows - 1) - ntru; /* Lower size */
lp = curwp->w_linep; lp = curwp->w_linep;
ntrd = 0; ntrd = 0;
while (lp != curwp->w_dotp) { while (lp != curwp->w_dotp) {
++ntrd; ++ntrd;
lp = lforw(lp); lp = lforw(lp);
} }
lp = curwp->w_linep; lp = curwp->w_linep;
if (((f == FALSE) && (ntrd <= ntru)) || ((f == TRUE) && (n == 1))) { if (((f == FALSE) && (ntrd <= ntru)) || ((f == TRUE) && (n == 1))) {
/* Old is upper window. */ /* Old is upper window. */
if (ntrd == ntru) /* Hit mode line. */ if (ntrd == ntru) /* Hit mode line. */
lp = lforw(lp); lp = lforw(lp);
curwp->w_ntrows = ntru; curwp->w_ntrows = ntru;
wp->w_wndp = curwp->w_wndp; wp->w_wndp = curwp->w_wndp;
curwp->w_wndp = wp; curwp->w_wndp = wp;
wp->w_toprow = curwp->w_toprow+ntru+1; wp->w_toprow = curwp->w_toprow + ntru + 1;
wp->w_ntrows = ntrl; wp->w_ntrows = ntrl;
} else { /* Old is lower window */ } else { /* Old is lower window */
wp1 = NULL; wp1 = NULL;
wp2 = wheadp; wp2 = wheadp;
while (wp2 != curwp) { while (wp2 != curwp) {
wp1 = wp2; wp1 = wp2;
wp2 = wp2->w_wndp; wp2 = wp2->w_wndp;
} }
if (wp1 == NULL) if (wp1 == NULL)
wheadp = wp; wheadp = wp;
else else
wp1->w_wndp = wp; wp1->w_wndp = wp;
wp->w_wndp = curwp; wp->w_wndp = curwp;
wp->w_toprow = curwp->w_toprow; wp->w_toprow = curwp->w_toprow;
wp->w_ntrows = ntru; wp->w_ntrows = ntru;
++ntru; /* Mode line. */ ++ntru; /* Mode line. */
curwp->w_toprow += ntru; curwp->w_toprow += ntru;
curwp->w_ntrows = ntrl; curwp->w_ntrows = ntrl;
while (ntru--) while (ntru--)
lp = lforw(lp); lp = lforw(lp);
} }
curwp->w_linep = lp; /* Adjust the top lines */ curwp->w_linep = lp; /* Adjust the top lines */
wp->w_linep = lp; /* if necessary. */ wp->w_linep = lp; /* if necessary. */
curwp->w_flag |= WFMODE|WFHARD; curwp->w_flag |= WFMODE | WFHARD;
wp->w_flag |= WFMODE|WFHARD; wp->w_flag |= WFMODE | WFHARD;
return (TRUE); return (TRUE);
} }
/* /*
@ -408,48 +402,48 @@ int f, n; /* default flag and numeric argument */
*/ */
enlargewind(f, n) enlargewind(f, n)
{ {
register WINDOW *adjwp; register WINDOW *adjwp;
register LINE *lp; register LINE *lp;
register int i; register int i;
if (n < 0) if (n < 0)
return (shrinkwind(f, -n)); return (shrinkwind(f, -n));
if (wheadp->w_wndp == NULL) { if (wheadp->w_wndp == NULL) {
mlwrite("Only one window"); mlwrite("Only one window");
return (FALSE); return (FALSE);
} }
if ((adjwp=curwp->w_wndp) == NULL) { if ((adjwp = curwp->w_wndp) == NULL) {
adjwp = wheadp; adjwp = wheadp;
while (adjwp->w_wndp != curwp) while (adjwp->w_wndp != curwp)
adjwp = adjwp->w_wndp; adjwp = adjwp->w_wndp;
} }
if (adjwp->w_ntrows <= n) { if (adjwp->w_ntrows <= n) {
mlwrite("Impossible change"); mlwrite("Impossible change");
return (FALSE); return (FALSE);
} }
if (curwp->w_wndp == adjwp) { /* Shrink below. */ if (curwp->w_wndp == adjwp) { /* Shrink below. */
lp = adjwp->w_linep; 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); lp = lforw(lp);
adjwp->w_linep = lp; adjwp->w_linep = lp;
adjwp->w_toprow += n; adjwp->w_toprow += n;
} else { /* Shrink above. */ } else { /* Shrink above. */
lp = curwp->w_linep; 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); lp = lback(lp);
curwp->w_linep = lp; curwp->w_linep = lp;
curwp->w_toprow -= n; curwp->w_toprow -= n;
} }
curwp->w_ntrows += n; curwp->w_ntrows += n;
adjwp->w_ntrows -= n; adjwp->w_ntrows -= n;
#if SCROLLCODE #if SCROLLCODE
curwp->w_flag |= WFMODE|WFHARD|WFINS; curwp->w_flag |= WFMODE | WFHARD | WFINS;
adjwp->w_flag |= WFMODE|WFHARD|WFKILLS; adjwp->w_flag |= WFMODE | WFHARD | WFKILLS;
#else #else
curwp->w_flag |= WFMODE|WFHARD; curwp->w_flag |= WFMODE | WFHARD;
adjwp->w_flag |= WFMODE|WFHARD; adjwp->w_flag |= WFMODE | WFHARD;
#endif #endif
return (TRUE); return (TRUE);
} }
/* /*
@ -459,71 +453,72 @@ enlargewind(f, n)
*/ */
shrinkwind(f, n) shrinkwind(f, n)
{ {
register WINDOW *adjwp; register WINDOW *adjwp;
register LINE *lp; register LINE *lp;
register int i; register int i;
if (n < 0) if (n < 0)
return (enlargewind(f, -n)); return (enlargewind(f, -n));
if (wheadp->w_wndp == NULL) { if (wheadp->w_wndp == NULL) {
mlwrite("Only one window"); mlwrite("Only one window");
return (FALSE); return (FALSE);
} }
if ((adjwp=curwp->w_wndp) == NULL) { if ((adjwp = curwp->w_wndp) == NULL) {
adjwp = wheadp; adjwp = wheadp;
while (adjwp->w_wndp != curwp) while (adjwp->w_wndp != curwp)
adjwp = adjwp->w_wndp; adjwp = adjwp->w_wndp;
} }
if (curwp->w_ntrows <= n) { if (curwp->w_ntrows <= n) {
mlwrite("Impossible change"); mlwrite("Impossible change");
return (FALSE); return (FALSE);
} }
if (curwp->w_wndp == adjwp) { /* Grow below. */ if (curwp->w_wndp == adjwp) { /* Grow below. */
lp = adjwp->w_linep; 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;
lp = lback(lp); ++i)
adjwp->w_linep = lp; lp = lback(lp);
adjwp->w_toprow -= n; adjwp->w_linep = lp;
} else { /* Grow above. */ adjwp->w_toprow -= n;
lp = curwp->w_linep; } else { /* Grow above. */
for (i=0; i<n && lp!=curbp->b_linep; ++i) lp = curwp->w_linep;
lp = lforw(lp); for (i = 0; i < n && lp != curbp->b_linep; ++i)
curwp->w_linep = lp; lp = lforw(lp);
curwp->w_toprow += n; curwp->w_linep = lp;
} curwp->w_toprow += n;
curwp->w_ntrows -= n; }
adjwp->w_ntrows += n; curwp->w_ntrows -= n;
adjwp->w_ntrows += n;
#if SCROLLCODE #if SCROLLCODE
curwp->w_flag |= WFMODE|WFHARD|WFKILLS; curwp->w_flag |= WFMODE | WFHARD | WFKILLS;
adjwp->w_flag |= WFMODE|WFHARD|WFINS; adjwp->w_flag |= WFMODE | WFHARD | WFINS;
#else #else
curwp->w_flag |= WFMODE|WFHARD; curwp->w_flag |= WFMODE | WFHARD;
adjwp->w_flag |= WFMODE|WFHARD; adjwp->w_flag |= WFMODE | WFHARD;
#endif #endif
return (TRUE); return (TRUE);
} }
/* Resize the current window to the requested size */ /* Resize the current window to the requested size */
resize(f, n) resize(f, n)
int f, n; /* default flag and numeric argument */ int f, n; /* default flag and numeric argument */
{ {
int clines; /* current # of lines in window */ int clines; /* current # of lines in window */
/* must have a non-default argument, else ignore call */ /* must have a non-default argument, else ignore call */
if (f == FALSE) if (f == FALSE)
return(TRUE); return (TRUE);
/* find out what to do */ /* find out what to do */
clines = curwp->w_ntrows; clines = curwp->w_ntrows;
/* already the right size? */ /* already the right size? */
if (clines == n) if (clines == n)
return(TRUE); return (TRUE);
return(enlargewind(TRUE, n - clines)); return (enlargewind(TRUE, n - clines));
} }
/* /*
@ -531,46 +526,41 @@ int f, n; /* default flag and numeric argument */
* Pick the uppermost window that isn't the current window. An LRU algorithm * Pick the uppermost window that isn't the current window. An LRU algorithm
* might be better. Return a pointer, or NULL on error. * might be better. Return a pointer, or NULL on error.
*/ */
WINDOW * WINDOW *wpopup()
wpopup()
{ {
register WINDOW *wp; register WINDOW *wp;
if (wheadp->w_wndp == NULL /* Only 1 window */ if (wheadp->w_wndp == NULL /* Only 1 window */
&& splitwind(FALSE, 0) == FALSE) /* and it won't split */ && splitwind(FALSE, 0) == FALSE) /* and it won't split */
return (NULL); return (NULL);
wp = wheadp; /* Find window to use */ wp = wheadp; /* Find window to use */
while (wp!=NULL && wp==curwp) while (wp != NULL && wp == curwp)
wp = wp->w_wndp; wp = wp->w_wndp;
return (wp); return (wp);
} }
scrnextup(f, n) /* scroll the next window up (back) a page */ scrnextup(f, n)
{ /* scroll the next window up (back) a page */
{
nextwind(FALSE, 1); nextwind(FALSE, 1);
backpage(f, n); backpage(f, n);
prevwind(FALSE, 1); prevwind(FALSE, 1);
} }
scrnextdw(f, n) /* scroll the next window down (forward) a page */ scrnextdw(f, n)
{ /* scroll the next window down (forward) a page */
{
nextwind(FALSE, 1); nextwind(FALSE, 1);
forwpage(f, n); forwpage(f, n);
prevwind(FALSE, 1); prevwind(FALSE, 1);
} }
savewnd(f, n) /* save ptr to current window */ savewnd(f, n)
{ /* save ptr to current window */
{
swindow = curwp; swindow = curwp;
return(TRUE); return (TRUE);
} }
restwnd(f, n) /* restore the saved screen */ restwnd(f, n)
{ /* restore the saved screen */
{
register WINDOW *wp; register WINDOW *wp;
/* find the window */ /* find the window */
@ -586,19 +576,19 @@ restwnd(f, n) /* restore the saved screen */
} }
mlwrite("(No such window exists)"); mlwrite("(No such window exists)");
return(FALSE); return (FALSE);
} }
newsize(f, n) /* resize the screen, re-writing the screen */ newsize(f, n)
/* resize the screen, re-writing the screen */
int f; /* default flag */ int f; /* default flag */
int n; /* numeric argument */ int n; /* numeric argument */
{ {
WINDOW *wp; /* current window being examined */ WINDOW *wp; /* current window being examined */
WINDOW *nextwp; /* next window to scan */ WINDOW *nextwp; /* next window to scan */
WINDOW *lastwp; /* last window scanned */ WINDOW *lastwp; /* last window scanned */
int lastline; /* screen line of last line of current window */ int lastline; /* screen line of last line of current window */
/* if the command defaults, assume the largest */ /* if the command defaults, assume the largest */
if (f == FALSE) if (f == FALSE)
@ -607,11 +597,11 @@ int n; /* numeric argument */
/* make sure it's in range */ /* make sure it's in range */
if (n < 3 || n > term.t_mrow + 1) { if (n < 3 || n > term.t_mrow + 1) {
mlwrite("%%Screen size out of range"); mlwrite("%%Screen size out of range");
return(FALSE); return (FALSE);
} }
if (term.t_nrow == n - 1) if (term.t_nrow == n - 1)
return(TRUE); return (TRUE);
else if (term.t_nrow < n - 1) { else if (term.t_nrow < n - 1) {
/* go to the last window */ /* go to the last window */
@ -621,7 +611,7 @@ int n; /* numeric argument */
/* and enlarge it as needed */ /* and enlarge it as needed */
wp->w_ntrows = n - wp->w_toprow - 2; wp->w_ntrows = n - wp->w_toprow - 2;
wp->w_flag |= WFHARD|WFMODE; wp->w_flag |= WFHARD | WFMODE;
} else { } else {
@ -632,7 +622,7 @@ int n; /* numeric argument */
while (nextwp != NULL) { while (nextwp != NULL) {
wp = nextwp; wp = nextwp;
nextwp = wp->w_wndp; nextwp = wp->w_wndp;
/* get rid of it if it is too low */ /* get rid of it if it is too low */
if (wp->w_toprow > n - 2) { if (wp->w_toprow > n - 2) {
@ -643,24 +633,25 @@ int n; /* numeric argument */
wp->w_bufp->b_markp = wp->w_markp; wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko; wp->w_bufp->b_marko = wp->w_marko;
} }
/* update curwp and lastwp if needed */ /* update curwp and lastwp if needed */
if (wp == curwp) if (wp == curwp)
curwp = wheadp; curwp = wheadp;
curbp = curwp->w_bufp; curbp = curwp->w_bufp;
if (lastwp != NULL) if (lastwp != NULL)
lastwp->w_wndp = NULL; lastwp->w_wndp = NULL;
/* free the structure */ /* free the structure */
free((char *)wp); free((char *) wp);
wp = NULL; wp = NULL;
} else { } else {
/* need to change this window size? */ /* need to change this window size? */
lastline = wp->w_toprow + wp->w_ntrows - 1; lastline = wp->w_toprow + wp->w_ntrows - 1;
if (lastline >= n - 2) { if (lastline >= n - 2) {
wp->w_ntrows = n - wp->w_toprow - 2; wp->w_ntrows =
wp->w_flag |= WFHARD|WFMODE; n - wp->w_toprow - 2;
wp->w_flag |= WFHARD | WFMODE;
} }
} }
@ -671,13 +662,13 @@ int n; /* numeric argument */
/* screen is garbage */ /* screen is garbage */
term.t_nrow = n - 1; term.t_nrow = n - 1;
sgarbf = TRUE; sgarbf = TRUE;
return(TRUE); return (TRUE);
} }
newwidth(f, n) /* resize the screen, re-writing the screen */ newwidth(f, n)
/* resize the screen, re-writing the screen */
int f; /* default flag */ int f; /* default flag */
int n; /* numeric argument */ int n; /* numeric argument */
{ {
register WINDOW *wp; register WINDOW *wp;
@ -689,7 +680,7 @@ int n; /* numeric argument */
/* make sure it's in range */ /* make sure it's in range */
if (n < 10 || n > term.t_mcol) { if (n < 10 || n > term.t_mcol) {
mlwrite("%%Screen width out of range"); mlwrite("%%Screen width out of range");
return(FALSE); return (FALSE);
} }
/* otherwise, just re-width it (no big deal) */ /* otherwise, just re-width it (no big deal) */
@ -705,12 +696,11 @@ int n; /* numeric argument */
} }
sgarbf = TRUE; sgarbf = TRUE;
return(TRUE); return (TRUE);
} }
int getwpos() /* get screen offset of current line in current window */ int getwpos()
{ /* get screen offset of current line in current window */
{
register int sline; /* screen line from top of window */ register int sline; /* screen line from top of window */
register LINE *lp; /* scannile line pointer */ register LINE *lp; /* scannile line pointer */
@ -723,11 +713,10 @@ int getwpos() /* get screen offset of current line in current window */
} }
/* and return the value */ /* and return the value */
return(sline); return (sline);
} }
cknewwindow() cknewwindow()
{ {
execute(META|SPEC|'X', FALSE, 1); execute(META | SPEC | 'X', FALSE, 1);
} }

245
word.c
View File

@ -20,46 +20,46 @@
*/ */
wrapword(f, n) wrapword(f, n)
int f; /* default flag */ int f; /* default flag */
int n; /* numeric argument */ int n; /* numeric argument */
{ {
register int cnt; /* size of word wrapped to next line */ register int cnt; /* size of word wrapped to next line */
register int c; /* charector temporary */ register int c; /* charector temporary */
/* backup from the <NL> 1 char */ /* backup from the <NL> 1 char */
if (!backchar(0, 1)) if (!backchar(0, 1))
return(FALSE); return (FALSE);
/* back up until we aren't in a word, /* back up until we aren't in a word,
make sure there is a break in the line */ make sure there is a break in the line */
cnt = 0; cnt = 0;
while (((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' ') while (((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' ')
&& (c != '\t')) { && (c != '\t')) {
cnt++; cnt++;
if (!backchar(0, 1)) if (!backchar(0, 1))
return(FALSE); return (FALSE);
/* if we make it to the beginning, start a new line */ /* if we make it to the beginning, start a new line */
if (curwp->w_doto == 0) { if (curwp->w_doto == 0) {
gotoeol(FALSE, 0); gotoeol(FALSE, 0);
return(lnewline()); return (lnewline());
} }
} }
/* delete the forward white space */ /* delete the forward white space */
if (!forwdel(0, 1)) if (!forwdel(0, 1))
return(FALSE); return (FALSE);
/* put in a end of line */ /* put in a end of line */
if (!lnewline()) if (!lnewline())
return(FALSE); return (FALSE);
/* and past the first word */ /* and past the first word */
while (cnt-- > 0) { while (cnt-- > 0) {
if (forwchar(FALSE, 1) == FALSE) if (forwchar(FALSE, 1) == FALSE)
return(FALSE); return (FALSE);
} }
return(TRUE); return (TRUE);
} }
/* /*
@ -105,7 +105,7 @@ forwword(f, n)
return (FALSE); return (FALSE);
} }
} }
return(TRUE); return (TRUE);
} }
/* /*
@ -115,10 +115,10 @@ forwword(f, n)
*/ */
upperword(f, n) upperword(f, n)
{ {
register int c; register int c;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
if (n < 0) if (n < 0)
return (FALSE); return (FALSE);
while (n--) { while (n--) {
@ -131,9 +131,9 @@ upperword(f, n)
#if PKCODE #if PKCODE
if (islower(c)) { if (islower(c)) {
#else #else
if (c>='a' && c<='z') { if (c >= 'a' && c <= 'z') {
#endif #endif
c -= 'a'-'A'; c -= 'a' - 'A';
lputc(curwp->w_dotp, curwp->w_doto, c); lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD); lchange(WFHARD);
} }
@ -151,10 +151,10 @@ upperword(f, n)
*/ */
lowerword(f, n) lowerword(f, n)
{ {
register int c; register int c;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
if (n < 0) if (n < 0)
return (FALSE); return (FALSE);
while (n--) { while (n--) {
@ -167,9 +167,9 @@ lowerword(f, n)
#if PKCODE #if PKCODE
if (isupper(c)) { if (isupper(c)) {
#else #else
if (c>='A' && c<='Z') { if (c >= 'A' && c <= 'Z') {
#endif #endif
c += 'a'-'A'; c += 'a' - 'A';
lputc(curwp->w_dotp, curwp->w_doto, c); lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD); lchange(WFHARD);
} }
@ -188,10 +188,10 @@ lowerword(f, n)
*/ */
capword(f, n) capword(f, n)
{ {
register int c; register int c;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
if (n < 0) if (n < 0)
return (FALSE); return (FALSE);
while (n--) { while (n--) {
@ -204,9 +204,9 @@ capword(f, n)
#if PKCODE #if PKCODE
if (islower(c)) { if (islower(c)) {
#else #else
if (c>='a' && c<='z') { if (c >= 'a' && c <= 'z') {
#endif #endif
c -= 'a'-'A'; c -= 'a' - 'A';
lputc(curwp->w_dotp, curwp->w_doto, c); lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD); lchange(WFHARD);
} }
@ -217,10 +217,11 @@ capword(f, n)
#if PKCODE #if PKCODE
if (isupper(c)) { if (isupper(c)) {
#else #else
if (c>='A' && c<='Z') { if (c >= 'A' && c <= 'Z') {
#endif #endif
c += 'a'-'A'; c += 'a' - 'A';
lputc(curwp->w_dotp, curwp->w_doto, c); lputc(curwp->w_dotp, curwp->w_doto,
c);
lchange(WFHARD); lchange(WFHARD);
} }
if (forwchar(FALSE, 1) == FALSE) if (forwchar(FALSE, 1) == FALSE)
@ -239,21 +240,21 @@ capword(f, n)
*/ */
delfword(f, n) delfword(f, n)
{ {
register LINE *dotp; /* original cursor line */ register LINE *dotp; /* original cursor line */
register int doto; /* and row */ register int doto; /* and row */
register int c; /* temp char */ register int c; /* temp char */
long size; /* # of chars to delete */ long size; /* # of chars to delete */
/* don't allow this command if we are in read only mode */ /* don't allow this command if we are in read only mode */
if (curbp->b_mode&MDVIEW) if (curbp->b_mode & MDVIEW)
return(rdonly()); return (rdonly());
/* ignore the command if there is a negative argument */ /* ignore the command if there is a negative argument */
if (n < 0) if (n < 0)
return (FALSE); return (FALSE);
/* Clear the kill buffer if last command wasn't a kill */ /* Clear the kill buffer if last command wasn't a kill */
if ((lastflag&CFKILL) == 0) if ((lastflag & CFKILL) == 0)
kdelete(); kdelete();
thisflag |= CFKILL; /* this command is a kill */ thisflag |= CFKILL; /* this command is a kill */
@ -267,7 +268,7 @@ delfword(f, n)
/* get us into a word.... */ /* get us into a word.... */
while (inword() == FALSE) { while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE) if (forwchar(FALSE, 1) == FALSE)
return(FALSE); return (FALSE);
++size; ++size;
} }
@ -275,43 +276,43 @@ delfword(f, n)
/* skip one word, no whitespace! */ /* skip one word, no whitespace! */
while (inword() == TRUE) { while (inword() == TRUE) {
if (forwchar(FALSE, 1) == FALSE) if (forwchar(FALSE, 1) == FALSE)
return(FALSE); return (FALSE);
++size; ++size;
} }
} else { } else {
/* skip n words.... */ /* skip n words.... */
while (n--) { while (n--) {
/* if we are at EOL; skip to the beginning of the next */ /* if we are at EOL; skip to the beginning of the next */
while (curwp->w_doto == llength(curwp->w_dotp)) { while (curwp->w_doto == llength(curwp->w_dotp)) {
if (forwchar(FALSE, 1) == FALSE) if (forwchar(FALSE, 1) == FALSE)
return(FALSE); return (FALSE);
++size; ++size;
} }
/* move forward till we are at the end of the word */ /* move forward till we are at the end of the word */
while (inword() == TRUE) { while (inword() == TRUE) {
if (forwchar(FALSE, 1) == FALSE) if (forwchar(FALSE, 1) == FALSE)
return(FALSE); return (FALSE);
++size; ++size;
} }
/* if there are more words, skip the interword stuff */ /* if there are more words, skip the interword stuff */
if (n != 0) if (n != 0)
while (inword() == FALSE) { while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE) if (forwchar(FALSE, 1) == FALSE)
return(FALSE); return (FALSE);
++size; ++size;
} }
} }
/* skip whitespace and newlines */ /* skip whitespace and newlines */
while ((curwp->w_doto == llength(curwp->w_dotp)) || while ((curwp->w_doto == llength(curwp->w_dotp)) ||
((c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' ') || ((c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' ')
(c == '\t')) { || (c == '\t')) {
if (forwchar(FALSE, 1) == FALSE) if (forwchar(FALSE, 1) == FALSE)
break; break;
++size; ++size;
} }
} }
@ -331,15 +332,15 @@ delbword(f, n)
long size; long size;
/* don't allow this command if we are in read only mode */ /* don't allow this command if we are in read only mode */
if (curbp->b_mode&MDVIEW) if (curbp->b_mode & MDVIEW)
return(rdonly()); return (rdonly());
/* ignore the command if there is a nonpositive argument */ /* ignore the command if there is a nonpositive argument */
if (n <= 0) if (n <= 0)
return (FALSE); return (FALSE);
/* Clear the kill buffer if last command wasn't a kill */ /* Clear the kill buffer if last command wasn't a kill */
if ((lastflag&CFKILL) == 0) if ((lastflag & CFKILL) == 0)
kdelete(); kdelete();
thisflag |= CFKILL; /* this command is a kill */ thisflag |= CFKILL; /* this command is a kill */
@ -360,7 +361,7 @@ delbword(f, n)
} }
if (forwchar(FALSE, 1) == FALSE) if (forwchar(FALSE, 1) == FALSE)
return (FALSE); return (FALSE);
bckdel: return (ldelete(size, TRUE)); bckdel:return (ldelete(size, TRUE));
} }
/* /*
@ -369,7 +370,7 @@ bckdel: return (ldelete(size, TRUE));
*/ */
inword() inword()
{ {
register int c; register int c;
if (curwp->w_doto == llength(curwp->w_dotp)) if (curwp->w_doto == llength(curwp->w_dotp))
return (FALSE); return (FALSE);
@ -377,39 +378,39 @@ inword()
#if PKCODE #if PKCODE
if (isletter(c)) if (isletter(c))
#else #else
if (c>='a' && c<='z') if (c >= 'a' && c <= 'z')
return (TRUE); return (TRUE);
if (c>='A' && c<='Z') if (c >= 'A' && c <= 'Z')
#endif #endif
return (TRUE); return (TRUE);
if (c>='0' && c<='9') if (c >= '0' && c <= '9')
return (TRUE); return (TRUE);
return (FALSE); return (FALSE);
} }
#if WORDPRO #if WORDPRO
fillpara(f, n) /* Fill the current paragraph according to the current fillpara(f, n)
fill column */ /* Fill the current paragraph according to the current
fill column */
int f, n; /* deFault flag and Numeric argument */ int f, n; /* deFault flag and Numeric argument */
{ {
register int c; /* current char durring scan */ register int c; /* current char durring scan */
register int wordlen; /* length of current word */ register int wordlen; /* length of current word */
register int clength; /* position on line during fill */ register int clength; /* position on line during fill */
register int i; /* index during word copy */ register int i; /* index during word copy */
register int newlength; /* tentative new line length */ register int newlength; /* tentative new line length */
register int eopflag; /* Are we at the End-Of-Paragraph? */ register int eopflag; /* Are we at the End-Of-Paragraph? */
register int firstflag; /* first word? (needs no space) */ register int firstflag; /* first word? (needs no space) */
register LINE *eopline; /* pointer to line just past EOP */ register LINE *eopline; /* pointer to line just past EOP */
register int dotflag; /* was the last char a period? */ register int dotflag; /* was the last char a period? */
char wbuf[NSTRING]; /* buffer for current word */ char wbuf[NSTRING]; /* buffer for current word */
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
if (fillcol == 0) { /* no fill column set */ if (fillcol == 0) { /* no fill column set */
mlwrite("No fill column set"); mlwrite("No fill column set");
return(FALSE); return (FALSE);
} }
#if PKCODE #if PKCODE
justflag = FALSE; justflag = FALSE;
@ -446,7 +447,7 @@ int f, n; /* deFault flag and Numeric argument */
/* if not a separator, just add it in */ /* if not a separator, just add it in */
if (c != ' ' && c != '\t') { if (c != ' ' && c != '\t') {
dotflag = (c == '.'); /* was it a dot */ dotflag = (c == '.'); /* was it a dot */
if (wordlen < NSTRING - 1) if (wordlen < NSTRING - 1)
wbuf[wordlen++] = c; wbuf[wordlen++] = c;
} else if (wordlen) { } else if (wordlen) {
@ -456,7 +457,7 @@ int f, n; /* deFault flag and Numeric argument */
if (newlength <= fillcol) { if (newlength <= fillcol) {
/* add word to current line */ /* add word to current line */
if (!firstflag) { if (!firstflag) {
linsert(1, ' '); /* the space */ linsert(1, ' '); /* the space */
++clength; ++clength;
} }
firstflag = FALSE; firstflag = FALSE;
@ -467,7 +468,7 @@ int f, n; /* deFault flag and Numeric argument */
} }
/* and add the word in in either case */ /* and add the word in in either case */
for (i=0; i<wordlen; i++) { for (i = 0; i < wordlen; i++) {
linsert(1, wbuf[i]); linsert(1, wbuf[i]);
++clength; ++clength;
} }
@ -480,40 +481,40 @@ int f, n; /* deFault flag and Numeric argument */
} }
/* and add a last newline for the end of our new paragraph */ /* and add a last newline for the end of our new paragraph */
lnewline(); lnewline();
return(TRUE); return (TRUE);
} }
#if PKCODE #if PKCODE
justpara(f, n) /* Fill the current paragraph according to the current justpara(f, n)
fill column and cursor position */ /* Fill the current paragraph according to the current
fill column and cursor position */
int f, n; /* deFault flag and Numeric argument */ int f, n; /* deFault flag and Numeric argument */
{ {
register int c; /* current char durring scan */ register int c; /* current char durring scan */
register int wordlen; /* length of current word */ register int wordlen; /* length of current word */
register int clength; /* position on line during fill */ register int clength; /* position on line during fill */
register int i; /* index during word copy */ register int i; /* index during word copy */
register int newlength; /* tentative new line length */ register int newlength; /* tentative new line length */
register int eopflag; /* Are we at the End-Of-Paragraph? */ register int eopflag; /* Are we at the End-Of-Paragraph? */
register int firstflag; /* first word? (needs no space) */ register int firstflag; /* first word? (needs no space) */
register LINE *eopline; /* pointer to line just past EOP */ register LINE *eopline; /* pointer to line just past EOP */
char wbuf[NSTRING]; /* buffer for current word */ char wbuf[NSTRING]; /* buffer for current word */
int leftmarg; /* left marginal */ int leftmarg; /* left marginal */
if (curbp->b_mode&MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */ return (rdonly()); /* we are in read only mode */
if (fillcol == 0) { /* no fill column set */ if (fillcol == 0) { /* no fill column set */
mlwrite("No fill column set"); mlwrite("No fill column set");
return(FALSE); return (FALSE);
} }
justflag = TRUE; justflag = TRUE;
leftmarg = curwp->w_doto; leftmarg = curwp->w_doto;
if (leftmarg+10 > fillcol) { if (leftmarg + 10 > fillcol) {
leftmarg = 0; leftmarg = 0;
mlwrite("Column too narrow"); mlwrite("Column too narrow");
return(FALSE); return (FALSE);
} }
/* record the pointer to the line just past the EOP */ /* record the pointer to the line just past the EOP */
gotoeop(FALSE, 1); gotoeop(FALSE, 1);
@ -558,20 +559,20 @@ int f, n; /* deFault flag and Numeric argument */
if (newlength <= fillcol) { if (newlength <= fillcol) {
/* add word to current line */ /* add word to current line */
if (!firstflag) { if (!firstflag) {
linsert(1, ' '); /* the space */ linsert(1, ' '); /* the space */
++clength; ++clength;
} }
firstflag = FALSE; firstflag = FALSE;
} else { } else {
/* start a new line */ /* start a new line */
lnewline(); lnewline();
for (i=0; i<leftmarg; i++) for (i = 0; i < leftmarg; i++)
linsert(1, ' '); linsert(1, ' ');
clength = leftmarg; clength = leftmarg;
} }
/* and add the word in in either case */ /* and add the word in in either case */
for (i=0; i<wordlen; i++) { for (i = 0; i < wordlen; i++) {
linsert(1, wbuf[i]); linsert(1, wbuf[i]);
++clength; ++clength;
} }
@ -588,14 +589,14 @@ int f, n; /* deFault flag and Numeric argument */
curwp->w_doto = llength(curwp->w_dotp); curwp->w_doto = llength(curwp->w_dotp);
justflag = FALSE; justflag = FALSE;
return(TRUE); return (TRUE);
} }
#endif #endif
killpara(f, n) /* delete n paragraphs starting with the current one */ killpara(f, n)
/* delete n paragraphs starting with the current one */
int f; /* default flag */ int f; /* default flag */
int n; /* # of paras to delete */ int n; /* # of paras to delete */
{ {
register int status; /* returned status of functions */ register int status; /* returned status of functions */
@ -612,15 +613,15 @@ int n; /* # of paras to delete */
/* go to the beginning of the paragraph */ /* go to the beginning of the paragraph */
gotobop(FALSE, 1); gotobop(FALSE, 1);
curwp->w_doto = 0; /* force us to the beginning of line */ curwp->w_doto = 0; /* force us to the beginning of line */
/* and delete it */ /* and delete it */
if ((status = killregion(FALSE, 1)) != TRUE) if ((status = killregion(FALSE, 1)) != TRUE)
return(status); return (status);
/* and clean up the 2 extra lines */ /* and clean up the 2 extra lines */
ldelete(2L, TRUE); ldelete(2L, TRUE);
} }
return(TRUE); return (TRUE);
} }
@ -630,7 +631,7 @@ int n; /* # of paras to delete */
wordcount(f, n) wordcount(f, n)
int f, n; /* ignored numeric arguments */ int f, n; /* ignored numeric arguments */
{ {
register LINE *lp; /* current line to scan */ register LINE *lp; /* current line to scan */
@ -648,16 +649,16 @@ int f, n; /* ignored numeric arguments */
#if PKCODE #if PKCODE
struct { struct {
long pk_1; long pk_1;
long pk_2; long pk_2;
int pk_3; int pk_3;
int pk_4; int pk_4;
} pk_mlrec; } pk_mlrec;
#endif #endif
/* make sure we have a region to count */ /* make sure we have a region to count */
if ((status = getregion(&region)) != TRUE) if ((status = getregion(&region)) != TRUE)
return(status); return (status);
lp = region.r_linep; lp = region.r_linep;
offset = region.r_offset; offset = region.r_offset;
size = region.r_size; size = region.r_size;
@ -683,12 +684,12 @@ int f, n; /* ignored numeric arguments */
/* and tabulate it */ /* and tabulate it */
wordflag = ( wordflag = (
#if PKCODE #if PKCODE
(isletter(ch)) || (isletter(ch)) ||
#else #else
(ch >= 'a' && ch <= 'z') || (ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') || (ch >= 'A' && ch <= 'Z') ||
#endif #endif
(ch >= '0' && ch <= '9')); (ch >= '0' && ch <= '9'));
if (wordflag == TRUE && lastword == FALSE) if (wordflag == TRUE && lastword == FALSE)
++nwords; ++nwords;
lastword = wordflag; lastword = wordflag;
@ -697,7 +698,7 @@ int f, n; /* ignored numeric arguments */
/* and report on the info */ /* and report on the info */
if (nwords > 0L) if (nwords > 0L)
avgch = (int)((100L * nchars) / nwords); avgch = (int) ((100L * nchars) / nwords);
else else
avgch = 0; avgch = 0;
@ -706,12 +707,12 @@ int f, n; /* ignored numeric arguments */
pk_mlrec.pk_2 = nchars; pk_mlrec.pk_2 = nchars;
pk_mlrec.pk_3 = nlines + 1; pk_mlrec.pk_3 = nlines + 1;
pk_mlrec.pk_4 = avgch; pk_mlrec.pk_4 = avgch;
mlwrite("%*Words %D Chars %D Lines %d Avg chars/word %f", mlwrite("%*Words %D Chars %D Lines %d Avg chars/word %f",
&pk_mlrec); &pk_mlrec);
#else #else
mlwrite("Words %D Chars %D Lines %d Avg chars/word %f", mlwrite("Words %D Chars %D Lines %d Avg chars/word %f",
nwords, nchars, nlines + 1, avgch); nwords, nchars, nlines + 1, avgch);
#endif #endif
return(TRUE); return (TRUE);
} }
#endif #endif