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

360
basic.c
View File

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

251
bind.c
View File

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

565
buffer.c
View File

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

24
crypt.c
View File

@ -13,10 +13,10 @@
static int mod95();
setkey(f, n) /* reset encryption key of current buffer */
int f; /* default flag */
int n; /* numeric argument */
setkey(f, n)
/* reset encryption key of current buffer */
int f; /* default flag */
int n; /* numeric argument */
{
register int status; /* return status */
@ -30,17 +30,17 @@ int n; /* numeric argument */
/* get the string to use as an encrytion string */
status = mlreply("Encryption String: ", key, NPAT - 1);
disinp = odisinp;
if (status != TRUE)
return(status);
if (status != TRUE)
return (status);
/* and encrypt it */
crypt((char *)NULL, 0);
crypt((char *) NULL, 0);
crypt(key, strlen(key));
/* and save it off */
strcpy(curbp->b_key, key);
mlwrite(" "); /* clear it off the bottom line */
return(TRUE);
return (TRUE);
}
/**********
@ -137,8 +137,8 @@ int n; /* numeric argument */
**********/
crypt(bptr, len)
register char *bptr; /* buffer of characters to be encrypted */
register unsigned len; /* number of characters in the buffer */
register char *bptr; /* buffer of characters to be encrypted */
register unsigned len; /* number of characters in the buffer */
{
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
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
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 */
/* 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)
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
* control-X commands.
*/
KEYTAB keytab[NBINDS] = {
{CONTROL|'A', gotobol},
{CONTROL|'B', backchar},
{CONTROL|'C', insspace},
{CONTROL|'D', forwdel},
{CONTROL|'E', gotoeol},
{CONTROL|'F', forwchar},
{CONTROL|'G', ctrlg},
{CONTROL|'H', backdel},
{CONTROL|'I', tab},
{CONTROL|'J', indent},
{CONTROL|'K', killtext},
{CONTROL|'L', refresh},
{CONTROL|'M', newline},
{CONTROL|'N', forwline},
{CONTROL|'O', openline},
{CONTROL|'P', backline},
{CONTROL|'Q', quote},
{CONTROL|'R', backsearch},
{CONTROL|'S', forwsearch},
{CONTROL|'T', twiddle},
{CONTROL|'U', unarg},
{CONTROL|'V', forwpage},
{CONTROL|'W', killregion},
{CONTROL|'X', cex},
{CONTROL|'Y', yank},
{CONTROL|'Z', backpage},
{CONTROL|']', meta},
{CTLX|CONTROL|'B', listbuffers},
{CTLX|CONTROL|'C', quit}, /* Hard quit. */
KEYTAB keytab[NBINDS] = {
{CONTROL | 'A', gotobol}
,
{CONTROL | 'B', backchar}
,
{CONTROL | 'C', insspace}
,
{CONTROL | 'D', forwdel}
,
{CONTROL | 'E', gotoeol}
,
{CONTROL | 'F', forwchar}
,
{CONTROL | 'G', ctrlg}
,
{CONTROL | 'H', backdel}
,
{CONTROL | 'I', tab}
,
{CONTROL | 'J', indent}
,
{CONTROL | 'K', killtext}
,
{CONTROL | 'L', refresh}
,
{CONTROL | 'M', newline}
,
{CONTROL | 'N', forwline}
,
{CONTROL | 'O', openline}
,
{CONTROL | 'P', backline}
,
{CONTROL | 'Q', quote}
,
{CONTROL | 'R', backsearch}
,
{CONTROL | 'S', forwsearch}
,
{CONTROL | 'T', twiddle}
,
{CONTROL | 'U', unarg}
,
{CONTROL | 'V', forwpage}
,
{CONTROL | 'W', killregion}
,
{CONTROL | 'X', cex}
,
{CONTROL | 'Y', yank}
,
{CONTROL | 'Z', backpage}
,
{CONTROL | ']', meta}
,
{CTLX | CONTROL | 'B', listbuffers}
,
{CTLX | CONTROL | 'C', quit}
, /* Hard quit. */
#if PKCODE & AEDIT
{CTLX|CONTROL|'A', detab},
{CTLX | CONTROL | 'A', detab}
,
#endif
#if PKCODE
{CTLX|CONTROL|'D', filesave}, /* alternative */
{CTLX | CONTROL | 'D', filesave}
, /* alternative */
#else
#if AEDIT
{CTLX|CONTROL|'D', detab},
{CTLX | CONTROL | 'D', detab}
,
#endif
#endif
#if AEDIT
{CTLX|CONTROL|'E', entab},
{CTLX | CONTROL | 'E', entab}
,
#endif
{CTLX|CONTROL|'F', filefind},
{CTLX|CONTROL|'I', insfile},
{CTLX|CONTROL|'L', lowerregion},
{CTLX|CONTROL|'M', delmode},
{CTLX|CONTROL|'N', mvdnwind},
{CTLX|CONTROL|'O', deblank},
{CTLX|CONTROL|'P', mvupwind},
{CTLX|CONTROL|'R', fileread},
{CTLX|CONTROL|'S', filesave},
{CTLX | CONTROL | 'F', filefind}
,
{CTLX | CONTROL | 'I', insfile}
,
{CTLX | CONTROL | 'L', lowerregion}
,
{CTLX | CONTROL | 'M', delmode}
,
{CTLX | CONTROL | 'N', mvdnwind}
,
{CTLX | CONTROL | 'O', deblank}
,
{CTLX | CONTROL | 'P', mvupwind}
,
{CTLX | CONTROL | 'R', fileread}
,
{CTLX | CONTROL | 'S', filesave}
,
#if AEDIT
{CTLX|CONTROL|'T', trim},
{CTLX | CONTROL | 'T', trim}
,
#endif
{CTLX|CONTROL|'U', upperregion},
{CTLX|CONTROL|'V', viewfile},
{CTLX|CONTROL|'W', filewrite},
{CTLX|CONTROL|'X', swapmark},
{CTLX|CONTROL|'Z', shrinkwind},
{CTLX|'?', deskey},
{CTLX|'!', spawn},
{CTLX|'@', pipecmd},
{CTLX|'#', filter},
{CTLX|'$', execprg},
{CTLX|'=', showcpos},
{CTLX|'(', ctlxlp},
{CTLX|')', ctlxrp},
{CTLX|'^', enlargewind},
{CTLX|'0', delwind},
{CTLX|'1', onlywind},
{CTLX|'2', splitwind},
{CTLX|'A', setvar},
{CTLX|'B', usebuffer},
{CTLX|'C', spawncli},
{CTLX | CONTROL | 'U', upperregion}
,
{CTLX | CONTROL | 'V', viewfile}
,
{CTLX | CONTROL | 'W', filewrite}
,
{CTLX | CONTROL | 'X', swapmark}
,
{CTLX | CONTROL | 'Z', shrinkwind}
,
{CTLX | '?', deskey}
,
{CTLX | '!', spawn}
,
{CTLX | '@', pipecmd}
,
{CTLX | '#', filter}
,
{CTLX | '$', execprg}
,
{CTLX | '=', showcpos}
,
{CTLX | '(', ctlxlp}
,
{CTLX | ')', ctlxrp}
,
{CTLX | '^', enlargewind}
,
{CTLX | '0', delwind}
,
{CTLX | '1', onlywind}
,
{CTLX | '2', splitwind}
,
{CTLX | 'A', setvar}
,
{CTLX | 'B', usebuffer}
,
{CTLX | 'C', spawncli}
,
#if BSD | __hpux | SVR4
{CTLX|'D', bktoshell},
{CTLX | 'D', bktoshell}
,
#endif
{CTLX|'E', ctlxe},
{CTLX|'F', setfillcol},
{CTLX|'K', killbuffer},
{CTLX|'M', setmode},
{CTLX|'N', filename},
{CTLX|'O', nextwind},
{CTLX|'P', prevwind},
{CTLX | 'E', ctlxe}
,
{CTLX | 'F', setfillcol}
,
{CTLX | 'K', killbuffer}
,
{CTLX | 'M', setmode}
,
{CTLX | 'N', filename}
,
{CTLX | 'O', nextwind}
,
{CTLX | 'P', prevwind}
,
#if PKCODE
{CTLX|'Q', quote}, /* alternative */
{CTLX | 'Q', quote}
, /* alternative */
#endif
#if ISRCH
{CTLX|'R', risearch},
{CTLX|'S', fisearch},
{CTLX | 'R', risearch}
,
{CTLX | 'S', fisearch}
,
#endif
{CTLX|'W', resize},
{CTLX|'X', nextbuffer},
{CTLX|'Z', enlargewind},
{CTLX | 'W', resize}
,
{CTLX | 'X', nextbuffer}
,
{CTLX | 'Z', enlargewind}
,
#if WORDPRO
{META|CONTROL|'C', wordcount},
{META | CONTROL | 'C', wordcount}
,
#endif
#if PKCODE
{META|CONTROL|'D', newsize},
{META | CONTROL | 'D', newsize}
,
#endif
#if PROC
{META|CONTROL|'E', execproc},
{META | CONTROL | 'E', execproc}
,
#endif
#if CFENCE
{META|CONTROL|'F', getfence},
{META | CONTROL | 'F', getfence}
,
#endif
{META|CONTROL|'H', delbword},
{META|CONTROL|'K', unbindkey},
{META|CONTROL|'L', reposition},
{META|CONTROL|'M', delgmode},
{META|CONTROL|'N', namebuffer},
{META|CONTROL|'R', qreplace},
{META|CONTROL|'S', newsize},
{META|CONTROL|'T', newwidth},
{META|CONTROL|'V', scrnextdw},
{META | CONTROL | 'H', delbword}
,
{META | CONTROL | 'K', unbindkey}
,
{META | CONTROL | 'L', reposition}
,
{META | CONTROL | 'M', delgmode}
,
{META | CONTROL | 'N', namebuffer}
,
{META | CONTROL | 'R', qreplace}
,
{META | CONTROL | 'S', newsize}
,
{META | CONTROL | 'T', newwidth}
,
{META | CONTROL | 'V', scrnextdw}
,
#if WORDPRO
{META|CONTROL|'W', killpara},
{META | CONTROL | 'W', killpara}
,
#endif
{META|CONTROL|'Z', scrnextup},
{META|' ', setmark},
{META|'?', help},
{META|'!', reposition},
{META|'.', setmark},
{META|'>', gotoeob},
{META|'<', gotobob},
{META|'~', unmark},
{META | CONTROL | 'Z', scrnextup}
,
{META | ' ', setmark}
,
{META | '?', help}
,
{META | '!', reposition}
,
{META | '.', setmark}
,
{META | '>', gotoeob}
,
{META | '<', gotobob}
,
{META | '~', unmark}
,
#if APROP
{META|'A', apro},
{META | 'A', apro}
,
#endif
{META|'B', backword},
{META|'C', capword},
{META|'D', delfword},
{META | 'B', backword}
,
{META | 'C', capword}
,
{META | 'D', delfword}
,
#if CRYPT
{META|'E', setkey},
{META | 'E', setkey}
,
#endif
{META|'F', forwword},
{META|'G', gotoline},
{META | 'F', forwword}
,
{META | 'G', gotoline}
,
#if PKCODE
#if WORDPRO
{META|'J', justpara},
{META | 'J', justpara}
,
#endif
#endif
{META|'K', bindtokey},
{META|'L', lowerword},
{META|'M', setgmode},
{META | 'K', bindtokey}
,
{META | 'L', lowerword}
,
{META | 'M', setgmode}
,
#if WORDPRO
{META|'N', gotoeop},
{META|'P', gotobop},
{META|'Q', fillpara},
{META | 'N', gotoeop}
,
{META | 'P', gotobop}
,
{META | 'Q', fillpara}
,
#endif
{META|'R', sreplace},
{META | 'R', sreplace}
,
#if PKCODE
{META|'S', forwsearch}, /* alternative P.K. */
{META | 'S', forwsearch}
, /* alternative P.K. */
#else
#if BSD
{META|'S', bktoshell},
{META | 'S', bktoshell}
,
#endif
#endif
{META|'U', upperword},
{META|'V', backpage},
{META|'W', copyregion},
{META|'X', namedcmd},
{META|'Z', quickexit},
{META|0x7F, delbword},
{META | 'U', upperword}
,
{META | 'V', backpage}
,
{META | 'W', copyregion}
,
{META | 'X', namedcmd}
,
{META | 'Z', quickexit}
,
{META | 0x7F, delbword}
,
#if MSDOS
{SPEC|CONTROL|'_', forwhunt},
{SPEC|CONTROL|'S', backhunt},
{SPEC|71, gotobol},
{SPEC|72, backline},
{SPEC|73, backpage},
{SPEC|75, backchar},
{SPEC|77, forwchar},
{SPEC|79, gotoeol},
{SPEC|80, forwline},
{SPEC|81, forwpage},
{SPEC|82, insspace},
{SPEC|83, forwdel},
{SPEC|115, backword},
{SPEC|116, forwword},
{SPEC | CONTROL | '_', forwhunt}
,
{SPEC | CONTROL | 'S', backhunt}
,
{SPEC | 71, gotobol}
,
{SPEC | 72, backline}
,
{SPEC | 73, backpage}
,
{SPEC | 75, backchar}
,
{SPEC | 77, forwchar}
,
{SPEC | 79, gotoeol}
,
{SPEC | 80, forwline}
,
{SPEC | 81, forwpage}
,
{SPEC | 82, insspace}
,
{SPEC | 83, forwdel}
,
{SPEC | 115, backword}
,
{SPEC | 116, forwword}
,
#if WORDPRO
{SPEC|132, gotobop},
{SPEC|118, gotoeop},
{SPEC | 132, gotobop}
,
{SPEC | 118, gotoeop}
,
#endif
{SPEC|84, cbuf1},
{SPEC|85, cbuf2},
{SPEC|86, cbuf3},
{SPEC|87, cbuf4},
{SPEC|88, cbuf5},
{SPEC|89, cbuf6},
{SPEC|90, cbuf7},
{SPEC|91, cbuf8},
{SPEC|92, cbuf9},
{SPEC|93, cbuf10},
{SPEC | 84, cbuf1}
,
{SPEC | 85, cbuf2}
,
{SPEC | 86, cbuf3}
,
{SPEC | 87, cbuf4}
,
{SPEC | 88, cbuf5}
,
{SPEC | 89, cbuf6}
,
{SPEC | 90, cbuf7}
,
{SPEC | 91, cbuf8}
,
{SPEC | 92, cbuf9}
,
{SPEC | 93, cbuf10}
,
#if PKCODE
{SPEC|117, gotoeob},
{SPEC|119, gotobob},
{SPEC|141, gotobop},
{SPEC|145, gotoeop},
{SPEC|146, yank},
{SPEC|147, killregion},
{SPEC | 117, gotoeob}
,
{SPEC | 119, gotobob}
,
{SPEC | 141, gotobop}
,
{SPEC | 145, gotoeop}
,
{SPEC | 146, yank}
,
{SPEC | 147, killregion}
,
#endif
#endif
#if VT220
{SPEC|'1', fisearch}, /* VT220 keys */
{SPEC|'2', yank},
{SPEC|'3', killregion},
{SPEC|'4', setmark},
{SPEC|'5', backpage},
{SPEC|'6', forwpage},
{SPEC|'A', backline},
{SPEC|'B', forwline},
{SPEC|'C', forwchar},
{SPEC|'D', backchar},
{SPEC|'c', meta},
{SPEC|'d', backchar},
{SPEC|'e', forwline},
{SPEC|'f', gotobob},
{SPEC|'h', help},
{SPEC|'i', cex},
{SPEC | '1', fisearch}
, /* VT220 keys */
{SPEC | '2', yank}
,
{SPEC | '3', killregion}
,
{SPEC | '4', setmark}
,
{SPEC | '5', backpage}
,
{SPEC | '6', forwpage}
,
{SPEC | 'A', backline}
,
{SPEC | 'B', forwline}
,
{SPEC | 'C', forwchar}
,
{SPEC | 'D', backchar}
,
{SPEC | 'c', meta}
,
{SPEC | 'd', backchar}
,
{SPEC | 'e', forwline}
,
{SPEC | 'f', gotobob}
,
{SPEC | 'h', help}
,
{SPEC | 'i', cex}
,
#endif
{0x7F, backdel},
{0x7F, backdel}
,
/* special internal bindings */
SPEC|META|'W', wrapword, /* called on word wrap */
SPEC|META|'C', nullproc, /* every command input */
SPEC|META|'R', nullproc, /* on file read */
SPEC|META|'X', nullproc, /* on window change P.K. */
SPEC | META | 'W', wrapword, /* called on word wrap */
SPEC | META | 'C', nullproc, /* every command input */
SPEC | META | 'R', nullproc, /* on file read */
SPEC | META | 'X', nullproc, /* on window change P.K. */
{0, NULL}
{0, NULL}
};

386
edef.h
View File

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

688
efunc.h
View File

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

23
epath.h
View File

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

455
estruct.h
View File

@ -41,14 +41,14 @@
/* make an intelligent guess about the target system */
#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
#define MSDOS 0
#endif
#if defined(BSD) || defined(sun) || defined(ultrix) || (defined(vax) && defined(unix)) || defined(ultrix) || defined(__osf__)
#ifndef BSD
#define BSD 1 /* Berkeley UNIX */
#define BSD 1 /* Berkeley UNIX */
#endif
#else
#define BSD 0
@ -61,35 +61,35 @@
#endif
#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
#define USG 0
#endif
#if defined(VMS) || (defined(vax) && ! defined(unix))
#define VMS 1 /* VAX/VMS */
#define VMS 1 /* VAX/VMS */
#else
#define VMS 0
#endif
#define V7 0 /* no more */
#define V7 0 /* no more */
#else
#define MSDOS 1 /* MS-DOS */
#define V7 0 /* V7 UNIX or Coherent or BSD4.2*/
#define BSD 0 /* UNIX BSD 4.2 and ULTRIX */
#define USG 0 /* UNIX system V */
#define VMS 0 /* VAX/VMS */
#define MSDOS 1 /* MS-DOS */
#define V7 0 /* V7 UNIX or Coherent or BSD4.2 */
#define BSD 0 /* UNIX BSD 4.2 and ULTRIX */
#define USG 0 /* UNIX system V */
#define VMS 0 /* VAX/VMS */
#endif /*autoconf */
#endif /*autoconf */
#ifndef AUTOCONF
/* Compiler definitions */
#define UNIX 0 /* a random UNIX compiler */
#define MSC 0 /* MicroSoft C compiler, versions 3 up */
#define TURBO 1 /* Turbo C/MSDOS */
#define UNIX 0 /* a random UNIX compiler */
#define MSC 0 /* MicroSoft C compiler, versions 3 up */
#define TURBO 1 /* Turbo C/MSDOS */
#else
@ -97,27 +97,27 @@
#define MSC 0
#define TURBO MSDOS
#endif /*autoconf */
#endif /*autoconf */
/* Debugging options */
#define RAMSIZE 0 /* dynamic RAM memory usage tracking */
#define RAMSHOW 0 /* auto dynamic RAM reporting */
#define RAMSIZE 0 /* dynamic RAM memory usage tracking */
#define RAMSHOW 0 /* auto dynamic RAM reporting */
#ifndef AUTOCONF
/* Special keyboard definitions */
#define VT220 0 /* Use keypad escapes P.K. */
#define VT100 0 /* Handle VT100 style keypad. */
#define VT220 0 /* Use keypad escapes P.K. */
#define VT100 0 /* Handle VT100 style keypad. */
/* Terminal Output definitions */
#define ANSI 0 /* ANSI escape sequences */
#define VMSVT 0 /* various VMS terminal entries */
#define VT52 0 /* VT52 terminal (Zenith). */
#define TERMCAP 0 /* Use TERMCAP */
#define IBMPC 1 /* IBM-PC CGA/MONO/EGA driver */
#define ANSI 0 /* ANSI escape sequences */
#define VMSVT 0 /* various VMS terminal entries */
#define VT52 0 /* VT52 terminal (Zenith). */
#define TERMCAP 0 /* Use TERMCAP */
#define IBMPC 1 /* IBM-PC CGA/MONO/EGA driver */
#else
@ -130,25 +130,25 @@
#define TERMCAP UNIX
#define IBMPC MSDOS
#endif /*autoconf */
#endif /*autoconf */
/* Configuration options */
#define CVMVAS 1 /* arguments to page forward/back in pages */
#define CLRMSG 0 /* space clears the message line with no insert */
#define CFENCE 1 /* fench matching in CMODE */
#define TYPEAH 1 /* type ahead causes update to be skipped */
#define DEBUGM 1 /* $debug triggers macro debugging */
#define VISMAC 0 /* update display during keyboard macros */
#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 NBRACE 1 /* new style brace matching command */
#define REVSTA 1 /* Status line appears in reverse video */
#define CVMVAS 1 /* arguments to page forward/back in pages */
#define CLRMSG 0 /* space clears the message line with no insert */
#define CFENCE 1 /* fench matching in CMODE */
#define TYPEAH 1 /* type ahead causes update to be skipped */
#define DEBUGM 1 /* $debug triggers macro debugging */
#define VISMAC 0 /* update display during keyboard macros */
#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 NBRACE 1 /* new style brace matching command */
#define REVSTA 1 /* Status line appears in reverse video */
#ifndef AUTOCONF
#define COLOR 1 /* color commands and windows */
#define FILOCK 0 /* file locking under unix BSD 4.2 */
#define COLOR 1 /* color commands and windows */
#define FILOCK 0 /* file locking under unix BSD 4.2 */
#else
@ -159,37 +159,37 @@
#define FILOCK BSD
#endif
#endif /* autoconf */
#endif /* autoconf */
#define ISRCH 1 /* Incremental searches like ITS EMACS */
#define WORDPRO 1 /* Advanced word processing features */
#define FNLABEL 0 /* function key label code [HP150] */
#define APROP 1 /* Add code for Apropos command */
#define CRYPT 1 /* file encryption enabled? */
#define MAGIC 1 /* include regular expression matching? */
#define AEDIT 1 /* advanced editing options: en/detabbing */
#define PROC 1 /* named procedures */
#define CLEAN 0 /* de-alloc memory on exit */
#define CALLED 0 /* is emacs a called subroutine? or stand alone */
#define ISRCH 1 /* Incremental searches like ITS EMACS */
#define WORDPRO 1 /* Advanced word processing features */
#define FNLABEL 0 /* function key label code [HP150] */
#define APROP 1 /* Add code for Apropos command */
#define CRYPT 1 /* file encryption enabled? */
#define MAGIC 1 /* include regular expression matching? */
#define AEDIT 1 /* advanced editing options: en/detabbing */
#define PROC 1 /* named procedures */
#define CLEAN 0 /* de-alloc memory on exit */
#define CALLED 0 /* is emacs a called subroutine? or stand alone */
#define ASCII 1 /* always using ASCII char sequences for now */
#define EBCDIC 0 /* later IBM mainfraim versions will use EBCDIC */
#define ASCII 1 /* always using ASCII char sequences for now */
#define EBCDIC 0 /* later IBM mainfraim versions will use EBCDIC */
#ifndef AUTOCONF
#define XONXOFF 0 /* don't disable XON-XOFF flow control P.K. */
#define NATIONL 0 /* interprete [,],\,{,},| as characters P.K. */
#define XONXOFF 0 /* don't disable XON-XOFF flow control P.K. */
#define NATIONL 0 /* interprete [,],\,{,},| as characters P.K. */
#else
#define XONXOFF (UNIX | VMS)
#define NATIONL (UNIX | VMS)
#endif /* autoconf */
#endif /* autoconf */
#define PKCODE 1 /* include my extensions P.K., define always */
#define IBMCHR MSDOS /* use IBM PC character set P.K. */
#define SCROLLCODE 1 /* scrolling code P.K. */
#define PKCODE 1 /* include my extensions P.K., define always */
#define IBMCHR MSDOS /* use IBM PC character set P.K. */
#define SCROLLCODE 1 /* scrolling code P.K. */
/* System dependant library redefinitions, structures and includes */
@ -240,24 +240,24 @@
/* internal constants */
#define NBINDS 256 /* max # of bound keys */
#define NFILEN 80 /* # of bytes, file name */
#define NBUFN 16 /* # of bytes, buffer name */
#define NLINE 256 /* # of bytes, input line */
#define NSTRING 128 /* # of bytes, string buffers */
#define NKBDM 256 /* # of strokes, keyboard macro */
#define NPAT 128 /* # of bytes, pattern */
#define HUGE 1000 /* Huge number */
#define NLOCKS 100 /* max # of file locks active */
#define NCOLORS 8 /* number of supported colors */
#define KBLOCK 250 /* sizeof kill buffer chunks */
#define NBLOCK 16 /* line block chunk size */
#define NVSIZE 10 /* max #chars in a var name */
#define NBINDS 256 /* max # of bound keys */
#define NFILEN 80 /* # of bytes, file name */
#define NBUFN 16 /* # of bytes, buffer name */
#define NLINE 256 /* # of bytes, input line */
#define NSTRING 128 /* # of bytes, string buffers */
#define NKBDM 256 /* # of strokes, keyboard macro */
#define NPAT 128 /* # of bytes, pattern */
#define HUGE 1000 /* Huge number */
#define NLOCKS 100 /* max # of file locks active */
#define NCOLORS 8 /* number of supported colors */
#define KBLOCK 250 /* sizeof kill buffer chunks */
#define NBLOCK 16 /* line block chunk size */
#define NVSIZE 10 /* max #chars in a var name */
#define CONTROL 0x0100 /* Control flag, or'ed in */
#define META 0x0200 /* Meta flag, or'ed in */
#define CTLX 0x0400 /* ^X flag, or'ed in */
#define SPEC 0x0800 /* special key (function keys) */
#define CONTROL 0x0100 /* Control flag, or'ed in */
#define META 0x0200 /* Meta flag, or'ed in */
#define CTLX 0x0400 /* ^X flag, or'ed in */
#define SPEC 0x0800 /* special key (function keys) */
#if PKCODE
#define MAXNLINE 10000000 /* max lines from one file */
@ -270,14 +270,14 @@
#undef TRUE
#endif
#define FALSE 0 /* False, no, bad, etc. */
#define TRUE 1 /* True, yes, good, etc. */
#define ABORT 2 /* Death, ^G, abort, etc. */
#define FAILED 3 /* not-quite fatal false return */
#define FALSE 0 /* False, no, bad, etc. */
#define TRUE 1 /* True, yes, good, etc. */
#define ABORT 2 /* Death, ^G, abort, etc. */
#define FAILED 3 /* not-quite fatal false return */
#define STOP 0 /* keyboard macro not in use */
#define PLAY 1 /* playing */
#define RECORD 2 /* recording */
#define STOP 0 /* keyboard macro not in use */
#define PLAY 1 /* playing */
#define RECORD 2 /* recording */
/* Directive definitions */
@ -298,23 +298,23 @@
* PTBEG, PTEND, FORWARD, and REVERSE are all toggle-able values for
* the scan routines.
*/
#define PTBEG 0 /* Leave the point at the beginning on search */
#define PTEND 1 /* Leave the point at the end on search */
#define FORWARD 0 /* forward direction */
#define REVERSE 1 /* backwards direction */
#define PTBEG 0 /* Leave the point at the beginning on search */
#define PTEND 1 /* Leave the point at the end on search */
#define FORWARD 0 /* forward direction */
#define REVERSE 1 /* backwards direction */
#define FIOSUC 0 /* File I/O, success. */
#define FIOFNF 1 /* File I/O, file not found. */
#define FIOEOF 2 /* File I/O, end of file. */
#define FIOERR 3 /* File I/O, error. */
#define FIOMEM 4 /* File I/O, out of memory */
#define FIOFUN 5 /* File I/O, eod of file/bad line*/
#define FIOSUC 0 /* File I/O, success. */
#define FIOFNF 1 /* File I/O, file not found. */
#define FIOEOF 2 /* File I/O, end of file. */
#define FIOERR 3 /* File I/O, error. */
#define FIOMEM 4 /* File I/O, out of memory */
#define FIOFUN 5 /* File I/O, eod of file/bad line */
#define CFCPCN 0x0001 /* Last command was C-P, C-N */
#define CFKILL 0x0002 /* Last command was a kill */
#define CFCPCN 0x0001 /* Last command was C-P, C-N */
#define CFKILL 0x0002 /* Last command was a kill */
#define BELL 0x07 /* a bell character */
#define TAB 0x09 /* a tab character */
#define BELL 0x07 /* a bell character */
#define TAB 0x09 /* a tab character */
#if V7 | USG | BSD
#define PATHCHR ':'
@ -326,17 +326,17 @@
/* Macro argument token types */
#define TKNUL 0 /* end-of-string */
#define TKARG 1 /* interactive argument */
#define TKBUF 2 /* buffer argument */
#define TKVAR 3 /* user variables */
#define TKENV 4 /* environment variables */
#define TKFUN 5 /* function.... */
#define TKDIR 6 /* directive */
#define TKLBL 7 /* line label */
#define TKLIT 8 /* numeric literal */
#define TKSTR 9 /* quoted string literal */
#define TKCMD 10 /* command name */
#define TKNUL 0 /* end-of-string */
#define TKARG 1 /* interactive argument */
#define TKBUF 2 /* buffer argument */
#define TKVAR 3 /* user variables */
#define TKENV 4 /* environment variables */
#define TKFUN 5 /* function.... */
#define TKDIR 6 /* directive */
#define TKLBL 7 /* line label */
#define TKLIT 8 /* numeric literal */
#define TKSTR 9 /* quoted string literal */
#define TKCMD 10 /* command name */
/* Internal defined functions */
@ -428,34 +428,34 @@
* the full blown redisplay is just too expensive to run for every input
* character.
*/
typedef struct WINDOW {
struct WINDOW *w_wndp; /* Next window */
struct BUFFER *w_bufp; /* Buffer displayed in window */
struct LINE *w_linep; /* Top line in the window */
struct LINE *w_dotp; /* Line containing "." */
short w_doto; /* Byte offset for "." */
struct LINE *w_markp; /* Line containing "mark" */
short w_marko; /* Byte offset for "mark" */
char w_toprow; /* Origin 0 top row of window */
char w_ntrows; /* # of rows of text in window */
char w_force; /* If NZ, forcing row. */
char w_flag; /* Flags. */
typedef struct WINDOW {
struct WINDOW *w_wndp; /* Next window */
struct BUFFER *w_bufp; /* Buffer displayed in window */
struct LINE *w_linep; /* Top line in the window */
struct LINE *w_dotp; /* Line containing "." */
short w_doto; /* Byte offset for "." */
struct LINE *w_markp; /* Line containing "mark" */
short w_marko; /* Byte offset for "mark" */
char w_toprow; /* Origin 0 top row of window */
char w_ntrows; /* # of rows of text in window */
char w_force; /* If NZ, forcing row. */
char w_flag; /* Flags. */
#if COLOR
char w_fcolor; /* current forground color */
char w_bcolor; /* current background color */
char w_fcolor; /* current forground color */
char w_bcolor; /* current background color */
#endif
} WINDOW;
} WINDOW;
#define WFFORCE 0x01 /* Window needs forced reframe */
#define WFMOVE 0x02 /* Movement from line to line */
#define WFEDIT 0x04 /* Editing within a line */
#define WFHARD 0x08 /* Better to a full display */
#define WFMODE 0x10 /* Update mode line. */
#define WFCOLR 0x20 /* Needs a color change */
#define WFFORCE 0x01 /* Window needs forced reframe */
#define WFMOVE 0x02 /* Movement from line to line */
#define WFEDIT 0x04 /* Editing within a line */
#define WFHARD 0x08 /* Better to a full display */
#define WFMODE 0x10 /* Update mode line. */
#define WFCOLR 0x20 /* Needs a color change */
#if SCROLLCODE
#define WFKILLS 0x40 /* something was deleted */
#define WFINS 0x80 /* something was inserted */
#define WFKILLS 0x40 /* something was deleted */
#define WFINS 0x80 /* something was inserted */
#endif
@ -470,50 +470,50 @@ typedef struct WINDOW {
* 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.
*/
typedef struct BUFFER {
struct BUFFER *b_bufp; /* Link to next BUFFER */
struct LINE *b_dotp; /* Link to "." LINE structure */
short b_doto; /* Offset of "." in above LINE */
struct LINE *b_markp; /* The same as the above two, */
short b_marko; /* but for the "mark" */
struct LINE *b_linep; /* Link to the header LINE */
char b_active; /* window activated flag */
char b_nwnd; /* Count of windows on buffer */
char b_flag; /* Flags */
int b_mode; /* editor mode of this buffer */
char b_fname[NFILEN]; /* File name */
char b_bname[NBUFN]; /* Buffer name */
typedef struct BUFFER {
struct BUFFER *b_bufp; /* Link to next BUFFER */
struct LINE *b_dotp; /* Link to "." LINE structure */
short b_doto; /* Offset of "." in above LINE */
struct LINE *b_markp; /* The same as the above two, */
short b_marko; /* but for the "mark" */
struct LINE *b_linep; /* Link to the header LINE */
char b_active; /* window activated flag */
char b_nwnd; /* Count of windows on buffer */
char b_flag; /* Flags */
int b_mode; /* editor mode of this buffer */
char b_fname[NFILEN]; /* File name */
char b_bname[NBUFN]; /* Buffer name */
#if CRYPT
char b_key[NPAT]; /* current encrypted key */
char b_key[NPAT]; /* current encrypted key */
#endif
} BUFFER;
} BUFFER;
#define BFINVS 0x01 /* Internal invisable buffer */
#define BFCHG 0x02 /* Changed since last write */
#define BFTRUNC 0x04 /* buffer was truncated when read */
#define BFINVS 0x01 /* Internal invisable buffer */
#define BFCHG 0x02 /* Changed since last write */
#define BFTRUNC 0x04 /* buffer was truncated when read */
/* mode flags */
#define NUMMODES 9 /* # of defined modes */
#define NUMMODES 9 /* # of defined modes */
#define MDWRAP 0x0001 /* word wrap */
#define MDCMOD 0x0002 /* C indentation and fence match*/
#define MDSPELL 0x0004 /* spell error parcing */
#define MDEXACT 0x0008 /* Exact matching for searches */
#define MDVIEW 0x0010 /* read-only buffer */
#define MDOVER 0x0020 /* overwrite mode */
#define MDMAGIC 0x0040 /* regular expresions in search */
#define MDCRYPT 0x0080 /* encrytion mode active */
#define MDASAVE 0x0100 /* auto-save mode */
#define MDWRAP 0x0001 /* word wrap */
#define MDCMOD 0x0002 /* C indentation and fence match */
#define MDSPELL 0x0004 /* spell error parcing */
#define MDEXACT 0x0008 /* Exact matching for searches */
#define MDVIEW 0x0010 /* read-only buffer */
#define MDOVER 0x0020 /* overwrite mode */
#define MDMAGIC 0x0040 /* regular expresions in search */
#define MDCRYPT 0x0080 /* encrytion mode active */
#define MDASAVE 0x0100 /* auto-save mode */
/*
* 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.
*/
typedef struct {
struct LINE *r_linep; /* Origin LINE address. */
short r_offset; /* Origin LINE offset. */
long r_size; /* Length in characters. */
} REGION;
typedef struct {
struct LINE *r_linep; /* Origin LINE address. */
short r_offset; /* Origin LINE offset. */
long r_size; /* Length in characters. */
} REGION;
/*
* 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
* additions will include update hints, and a list of marks into the line.
*/
typedef struct LINE {
struct LINE *l_fp; /* Link to the next line */
struct LINE *l_bp; /* Link to the previous line */
short l_size; /* Allocated size */
short l_used; /* Used size */
char l_text[1]; /* A bunch of characters. */
} LINE;
typedef struct LINE {
struct LINE *l_fp; /* Link to the next line */
struct LINE *l_bp; /* Link to the previous line */
short l_size; /* Allocated size */
short l_used; /* Used size */
char l_text[1]; /* A bunch of characters. */
} LINE;
#define lforw(lp) ((lp)->l_fp)
#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
* one terminal type.
*/
typedef struct {
short t_mrow; /* max number of rows allowable */
short t_nrow; /* current number of rows used */
short t_mcol; /* max Number of columns. */
short t_ncol; /* current Number of columns. */
short t_margin; /* min margin for extended lines*/
short t_scrsiz; /* size of scroll region " */
int t_pause; /* # times thru update to pause */
int (*t_open)(); /* Open terminal at the start. */
int (*t_close)(); /* Close terminal at end. */
int (*t_kopen)(); /* Open keyboard */
int (*t_kclose)(); /* close keyboard */
int (*t_getchar)(); /* Get character from keyboard. */
int (*t_putchar)(); /* Put character to display. */
int (*t_flush)(); /* Flush output buffers. */
int (*t_move)(); /* Move the cursor, origin 0. */
int (*t_eeol)(); /* Erase to end of line. */
int (*t_eeop)(); /* Erase to end of page. */
int (*t_beep)(); /* Beep. */
int (*t_rev)(); /* set reverse video state */
int (*t_rez)(); /* change screen resolution */
typedef struct {
short t_mrow; /* max number of rows allowable */
short t_nrow; /* current number of rows used */
short t_mcol; /* max Number of columns. */
short t_ncol; /* current Number of columns. */
short t_margin; /* min margin for extended lines */
short t_scrsiz; /* size of scroll region " */
int t_pause; /* # times thru update to pause */
int (*t_open) (); /* Open terminal at the start. */
int (*t_close) (); /* Close terminal at end. */
int (*t_kopen) (); /* Open keyboard */
int (*t_kclose) (); /* close keyboard */
int (*t_getchar) (); /* Get character from keyboard. */
int (*t_putchar) (); /* Put character to display. */
int (*t_flush) (); /* Flush output buffers. */
int (*t_move) (); /* Move the cursor, origin 0. */
int (*t_eeol) (); /* Erase to end of line. */
int (*t_eeop) (); /* Erase to end of page. */
int (*t_beep) (); /* Beep. */
int (*t_rev) (); /* set reverse video state */
int (*t_rez) (); /* change screen resolution */
#if COLOR
int (*t_setfor)(); /* set forground color */
int (*t_setback)(); /* set background color */
int (*t_setfor) (); /* set forground color */
int (*t_setback) (); /* set background color */
#endif
#if SCROLLCODE
int (*t_scroll)(); /* scroll a region of the screen */
#if SCROLLCODE
int (*t_scroll) (); /* scroll a region of the screen */
#endif
} TERM;
} TERM;
/* TEMPORARY macros for terminal I/O (to be placed in a machine
dependant place later) */
@ -599,17 +599,17 @@ typedef struct {
/* structure for the table of initial key bindings */
typedef struct {
short k_code; /* Key code */
int (*k_fp)(); /* Routine to handle it */
} KEYTAB;
typedef struct {
short k_code; /* Key code */
int (*k_fp) (); /* Routine to handle it */
} KEYTAB;
/* structure for the name binding table */
typedef struct {
char *n_name; /* name of function key */
int (*n_func)(); /* function name is bound to */
} NBIND;
int (*n_func) (); /* function name is bound to */
} NBIND;
/* The editor holds deleted text chunks in the KILL buffer. The
kill buffer is logically a stream of ascii characters, however
@ -618,7 +618,7 @@ typedef struct {
was taken up by the keycode structure)
*/
typedef struct KILL {
typedef struct KILL {
struct KILL *d_next; /* link to next chunk, NULL if last */
char d_chunk[KBLOCK]; /* deleted text */
} KILL;
@ -630,8 +630,8 @@ typedef struct KILL {
*/
typedef struct VDESC {
int v_type; /* type of variable */
int v_num; /* ordinal pointer to variable in list */
int v_type; /* type of variable */
int v_num; /* ordinal pointer to variable in list */
} VDESC;
/* The !WHILE directive in the execution language needs to
@ -642,7 +642,7 @@ typedef struct VDESC {
typedef struct WHBLOCK {
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 */
struct WHBLOCK *w_next; /* next while */
} WHBLOCK;
@ -678,30 +678,30 @@ typedef struct WHBLOCK {
* Defines for the metacharacters in the regular expression
* search routines.
*/
#define MCNIL 0 /* Like the '\0' for strings.*/
#define LITCHAR 1 /* Literal character, or string.*/
#define MCNIL 0 /* Like the '\0' for strings. */
#define LITCHAR 1 /* Literal character, or string. */
#define ANY 2
#define CCL 3
#define NCCL 4
#define BOL 5
#define EOL 6
#define DITTO 7
#define CLOSURE 256 /* An or-able value.*/
#define CLOSURE 256 /* An or-able value. */
#define MASKCL CLOSURE - 1
#define MC_ANY '.' /* 'Any' character (except newline).*/
#define MC_CCL '[' /* Character class.*/
#define MC_NCCL '^' /* Negate character class.*/
#define MC_RCCL '-' /* Range in character class.*/
#define MC_ECCL ']' /* End of character class.*/
#define MC_BOL '^' /* Beginning of line.*/
#define MC_EOL '$' /* End of line.*/
#define MC_CLOSURE '*' /* Closure - does not extend past newline.*/
#define MC_DITTO '&' /* Use matched string in replacement.*/
#define MC_ESC '\\' /* Escape - suppress meta-meaning.*/
#define MC_ANY '.' /* 'Any' character (except newline). */
#define MC_CCL '[' /* Character class. */
#define MC_NCCL '^' /* Negate character class. */
#define MC_RCCL '-' /* Range in character class. */
#define MC_ECCL ']' /* End of character class. */
#define MC_BOL '^' /* Beginning of line. */
#define MC_EOL '$' /* End of line. */
#define MC_CLOSURE '*' /* Closure - does not extend past newline. */
#define MC_DITTO '&' /* Use matched string in replacement. */
#define MC_ESC '\\' /* Escape - suppress meta-meaning. */
#define BIT(n) (1 << (n)) /* An integer with one bit set.*/
#define CHCASE(c) ((c) ^ DIFCASE) /* Toggle the case of a letter.*/
#define BIT(n) (1 << (n)) /* An integer with one bit set. */
#define CHCASE(c) ((c) ^ DIFCASE) /* Toggle the case of a letter. */
/* HICHAR - 1 is the largest character we will deal with.
* 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),
* and the meta-character structure for MAGIC mode replacment (RMC).
*/
typedef char *BITMAP;
typedef char *BITMAP;
typedef struct {
short int mc_type;
typedef struct {
short int mc_type;
union {
int lchar;
BITMAP cclmap;
int lchar;
BITMAP cclmap;
} u;
} MC;
typedef struct {
short int mc_type;
char *rstr;
typedef struct {
short int mc_type;
char *rstr;
} RMC;
#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 */
typedef struct UVAR {
char u_name[NVSIZE + 1]; /* name of user variable */
char *u_value; /* value (string) */
char u_name[NVSIZE + 1]; /* name of user variable */
char *u_value; /* value (string) */
} UVAR;
/* current user variables (This structure will probably change) */
#define MAXVARS 255
UVAR uv[MAXVARS + 1]; /* user variables */
UVAR uv[MAXVARS + 1]; /* user variables */
/* list of recognized environment variables */
@ -116,8 +116,8 @@ char *envars[] = {
/* list of recognized user functions */
typedef struct UFUNC {
char *f_name; /* name of function */
int f_type; /* 1 = monamic, 2 = dynamic */
char *f_name; /* name of function */
int f_type; /* 1 = monamic, 2 = dynamic */
} UFUNC;
#define NILNAMIC 0
@ -145,7 +145,7 @@ UFUNC funcs[] = {
"sgr", DYNAMIC, /* string logical greater than */
"ind", MONAMIC, /* evaluate indirect value */
"and", DYNAMIC, /* logical and */
"or", DYNAMIC, /* logical or */
"or", DYNAMIC, /* logical or */
"len", MONAMIC, /* string length */
"upp", MONAMIC, /* uppercase string */
"low", MONAMIC, /* lower case string */
@ -160,9 +160,9 @@ UFUNC funcs[] = {
"bin", MONAMIC, /* loopup what function name is bound to a key */
"exi", MONAMIC, /* check if a file exists */
"fin", MONAMIC, /* look for a file on the path... */
"ban", DYNAMIC, /* bitwise and 9-10-87 jwm */
"bor", DYNAMIC, /* bitwise or 9-10-87 jwm */
"bxo", DYNAMIC, /* bitwise xor 9-10-87 jwm */
"ban", DYNAMIC, /* bitwise and 9-10-87 jwm */
"bor", DYNAMIC, /* bitwise or 9-10-87 jwm */
"bxo", DYNAMIC, /* bitwise xor 9-10-87 jwm */
"bno", MONAMIC, /* bitwise not */
"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)
{
register int s;
char fname[NFILEN];
register int s;
char fname[NFILEN];
if (restflag) /* don't allow this command if restricted */
return(resterr());
if ((s=mlreply("Read file: ", fname, NFILEN)) != TRUE)
return(s);
return(readin(fname, TRUE));
return (resterr());
if ((s = mlreply("Read file: ", fname, NFILEN)) != TRUE)
return (s);
return (readin(fname, TRUE));
}
/*
@ -39,18 +39,18 @@ fileread(f, n)
*/
insfile(f, n)
{
register int s;
register int s;
char fname[NFILEN];
if (restflag) /* don't allow this command if restricted */
return(resterr());
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if ((s=mlreply("Insert file: ", fname, NFILEN)) != TRUE)
return(s);
if ((s=ifile(fname)) != TRUE)
return(s);
return(reposition(TRUE, -1));
return (resterr());
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return (rdonly()); /* we are in read only mode */
if ((s = mlreply("Insert file: ", fname, NFILEN)) != TRUE)
return (s);
if ((s = ifile(fname)) != TRUE)
return (s);
return (reposition(TRUE, -1));
}
/*
@ -64,28 +64,28 @@ insfile(f, n)
*/
filefind(f, n)
{
char fname[NFILEN]; /* file user wishes to find */
register int s; /* status return */
char fname[NFILEN]; /* file user wishes to find */
register int s; /* status return */
if (restflag) /* don't allow this command if restricted */
return(resterr());
if ((s=mlreply("Find file: ", fname, NFILEN)) != TRUE)
return(s);
return(getfile(fname, TRUE));
return (resterr());
if ((s = mlreply("Find file: ", fname, NFILEN)) != TRUE)
return (s);
return (getfile(fname, TRUE));
}
viewfile(f, n) /* visit a file in VIEW mode */
{
char fname[NFILEN]; /* file user wishes to find */
register int s; /* status return */
viewfile(f, n)
{ /* visit a file in VIEW mode */
char fname[NFILEN]; /* file user wishes to find */
register int s; /* status return */
register WINDOW *wp; /* scan for windows that need updating */
if (restflag) /* don't allow this command if restricted */
return(resterr());
if ((s=mlreply("View file: ", fname, NFILEN)) != TRUE)
return (s);
return (resterr());
if ((s = mlreply("View file: ", fname, NFILEN)) != TRUE)
return (s);
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;
/* 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;
}
}
return(s);
return (s);
}
#if CRYPT
resetkey() /* reset the encryption key if needed */
{
register int s; /* return status */
resetkey()
{ /* reset the encryption key if needed */
register int s; /* return status */
/* turn off the encryption flag */
cryptflag = FALSE;
@ -112,7 +111,7 @@ resetkey() /* reset the encryption key if needed */
if (curbp->b_key[0] == 0) {
s = setkey(FALSE, 0);
if (s != TRUE)
return(s);
return (s);
}
/* let others know... */
@ -120,72 +119,73 @@ resetkey() /* reset the encryption key if needed */
/* and set up the key to be used! */
/* de-encrypt it */
crypt((char *)NULL, 0);
crypt((char *) NULL, 0);
crypt(curbp->b_key, strlen(curbp->b_key));
/* re-encrypt it...seeding it to start */
crypt((char *)NULL, 0);
crypt((char *) NULL, 0);
crypt(curbp->b_key, strlen(curbp->b_key));
}
return(TRUE);
return (TRUE);
}
#endif
getfile(fname, lockfl)
char fname[]; /* file name to find */
int lockfl; /* check the file for locks? */
char fname[]; /* file name to find */
int lockfl; /* check the file for locks? */
{
register BUFFER *bp;
register LINE *lp;
register int i;
register int s;
char bname[NBUFN]; /* buffer name to put file */
register BUFFER *bp;
register LINE *lp;
register int i;
register int s;
char bname[NBUFN]; /* buffer name to put file */
#if MSDOS
mklower(fname); /* msdos isn't case sensitive */
#endif
for (bp=bheadp; bp!=NULL; bp=bp->b_bufp) {
if ((bp->b_flag&BFINVS)==0 && strcmp(bp->b_fname, fname)==0) {
for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
if ((bp->b_flag & BFINVS) == 0
&& strcmp(bp->b_fname, fname) == 0) {
swbuffer(bp);
lp = curwp->w_dotp;
i = curwp->w_ntrows/2;
while (i-- && lback(lp)!=curbp->b_linep)
lp = lback(lp);
curwp->w_linep = lp;
curwp->w_flag |= WFMODE|WFHARD;
lp = curwp->w_dotp;
i = curwp->w_ntrows / 2;
while (i-- && lback(lp) != curbp->b_linep)
lp = lback(lp);
curwp->w_linep = lp;
curwp->w_flag |= WFMODE | WFHARD;
cknewwindow();
mlwrite("(Old buffer)");
return (TRUE);
}
}
makename(bname, fname); /* New buffer name. */
while ((bp=bfind(bname, FALSE, 0)) != NULL) {
return (TRUE);
}
}
makename(bname, fname); /* New buffer name. */
while ((bp = bfind(bname, FALSE, 0)) != NULL) {
/* old buffer name conflict code */
s = mlreply("Buffer name: ", bname, NBUFN);
if (s == ABORT) /* ^G to just quit */
return (s);
if (s == FALSE) { /* CR to clobber it */
makename(bname, fname);
break;
}
}
if (bp==NULL && (bp=bfind(bname, TRUE, 0))==NULL) {
mlwrite("Cannot create buffer");
return (FALSE);
}
if (--curbp->b_nwnd == 0) { /* Undisplay. */
curbp->b_dotp = curwp->w_dotp;
curbp->b_doto = curwp->w_doto;
curbp->b_markp = curwp->w_markp;
curbp->b_marko = curwp->w_marko;
}
curbp = bp; /* Switch to it. */
curwp->w_bufp = bp;
curbp->b_nwnd++;
s = readin(fname, lockfl); /* Read it in. */
s = mlreply("Buffer name: ", bname, NBUFN);
if (s == ABORT) /* ^G to just quit */
return (s);
if (s == FALSE) { /* CR to clobber it */
makename(bname, fname);
break;
}
}
if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) {
mlwrite("Cannot create buffer");
return (FALSE);
}
if (--curbp->b_nwnd == 0) { /* Undisplay. */
curbp->b_dotp = curwp->w_dotp;
curbp->b_doto = curwp->w_doto;
curbp->b_markp = curwp->w_markp;
curbp->b_marko = curwp->w_marko;
}
curbp = bp; /* Switch to it. */
curwp->w_bufp = bp;
curbp->b_nwnd++;
s = readin(fname, lockfl); /* Read it in. */
cknewwindow();
return s;
}
@ -201,19 +201,19 @@ int lockfl; /* check the file for locks? */
readin(fname, lockfl)
char fname[]; /* name of file to read */
int lockfl; /* check for file locks? */
char fname[]; /* name of file to read */
int lockfl; /* check for file locks? */
{
register LINE *lp1;
register LINE *lp2;
register int i;
register WINDOW *wp;
register BUFFER *bp;
register int s;
register int nbytes;
register int nline;
int lflag; /* any lines longer than allowed? */
register LINE *lp1;
register LINE *lp2;
register int i;
register WINDOW *wp;
register BUFFER *bp;
register int s;
register int nbytes;
register int nline;
int lflag; /* any lines longer than allowed? */
char mesg[NSTRING];
#if (FILOCK && BSD) || SVR4
@ -226,62 +226,62 @@ int lockfl; /* check for file locks? */
goto out;
}
#else
return(ABORT);
return (ABORT);
#endif
#endif
#if CRYPT
s = resetkey();
if (s != TRUE)
return(s);
return (s);
#endif
bp = curbp; /* Cheap. */
if ((s=bclear(bp)) != TRUE) /* Might be old. */
return (s);
bp->b_flag &= ~(BFINVS|BFCHG);
strcpy(bp->b_fname, fname);
bp = curbp; /* Cheap. */
if ((s = bclear(bp)) != TRUE) /* Might be old. */
return (s);
bp->b_flag &= ~(BFINVS | BFCHG);
strcpy(bp->b_fname, fname);
/* 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 */
TTkclose();
if ((s=ffropen(fname)) == FIOERR) /* Hard file open. */
goto out;
if ((s = ffropen(fname)) == FIOERR) /* Hard file open. */
goto out;
if (s == FIOFNF) { /* File not found. */
if (s == FIOFNF) { /* File not found. */
mlwrite("(New file)");
goto out;
}
goto out;
}
/* read the file in */
mlwrite("(Reading file)");
nline = 0;
nline = 0;
lflag = FALSE;
while ((s=ffgetline()) == FIOSUC) {
nbytes = strlen(fline);
if ((lp1=lalloc(nbytes)) == NULL) {
s = FIOMEM; /* Keep message on the */
break; /* display. */
}
while ((s = ffgetline()) == FIOSUC) {
nbytes = strlen(fline);
if ((lp1 = lalloc(nbytes)) == NULL) {
s = FIOMEM; /* Keep message on the */
break; /* display. */
}
#if PKCODE
if (nline > MAXNLINE) {
s = FIOMEM;
break;
}
#endif
lp2 = lback(curbp->b_linep);
lp2->l_fp = lp1;
lp1->l_fp = curbp->b_linep;
lp1->l_bp = lp2;
curbp->b_linep->l_bp = lp1;
for (i=0; i<nbytes; ++i)
lputc(lp1, i, fline[i]);
++nline;
}
ffclose(); /* Ignore errors. */
lp2 = lback(curbp->b_linep);
lp2->l_fp = lp1;
lp1->l_fp = curbp->b_linep;
lp1->l_bp = lp2;
curbp->b_linep->l_bp = lp1;
for (i = 0; i < nbytes; ++i)
lputc(lp1, i, fline[i]);
++nline;
}
ffclose(); /* Ignore errors. */
strcpy(mesg, "(");
if (s==FIOERR) {
if (s == FIOERR) {
strcat(mesg, "I/O ERROR, ");
curbp->b_flag |= BFTRUNC;
}
@ -290,30 +290,30 @@ int lockfl; /* check for file locks? */
curbp->b_flag |= BFTRUNC;
}
sprintf(&mesg[strlen(mesg)], "Read %d line", nline);
if (nline != 1)
if (nline != 1)
strcat(mesg, "s");
strcat(mesg, ")");
mlwrite(mesg);
out:
TTkopen(); /* open the keyboard again */
for (wp=wheadp; wp!=NULL; wp=wp->w_wndp) {
if (wp->w_bufp == curbp) {
wp->w_linep = lforw(curbp->b_linep);
wp->w_dotp = lforw(curbp->b_linep);
wp->w_doto = 0;
wp->w_markp = NULL;
wp->w_marko = 0;
wp->w_flag |= WFMODE|WFHARD;
}
}
if (s == FIOERR || s == FIOFNF) /* False if error. */
return(FALSE);
out:
TTkopen(); /* open the keyboard again */
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
if (wp->w_bufp == curbp) {
wp->w_linep = lforw(curbp->b_linep);
wp->w_dotp = lforw(curbp->b_linep);
wp->w_doto = 0;
wp->w_markp = NULL;
wp->w_marko = 0;
wp->w_flag |= WFMODE | WFHARD;
}
}
if (s == FIOERR || s == FIOFNF) /* False if error. */
return (FALSE);
#if 0
if (s == ABORT)
return(ABORT);
return (ABORT);
#endif
return (TRUE);
return (TRUE);
}
/*
@ -324,41 +324,43 @@ out:
* a better place than a line of code.
*/
makename(bname, fname)
char bname[];
char fname[];
char bname[];
char fname[];
{
register char *cp1;
register char *cp2;
register char *cp1;
register char *cp2;
cp1 = &fname[0];
while (*cp1 != 0)
++cp1;
cp1 = &fname[0];
while (*cp1 != 0)
++cp1;
#if VMS
#if PKCODE
while (cp1!=&fname[0] && cp1[-1]!=':' && cp1[-1]!=']' && cp1[-1]!='>')
while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != ']'
&& cp1[-1] != '>')
#else
while (cp1!=&fname[0] && cp1[-1]!=':' && cp1[-1]!=']')
while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != ']')
#endif
--cp1;
--cp1;
#endif
#if MSDOS
while (cp1!=&fname[0] && cp1[-1]!=':' && cp1[-1]!='\\'&&cp1[-1]!='/')
--cp1;
while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != '\\'
&& cp1[-1] != '/')
--cp1;
#endif
#if V7 | USG | BSD
while (cp1!=&fname[0] && cp1[-1]!='/')
--cp1;
while (cp1 != &fname[0] && cp1[-1] != '/')
--cp1;
#endif
cp2 = &bname[0];
while (cp2!=&bname[NBUFN-1] && *cp1!=0 && *cp1!=';')
*cp2++ = *cp1++;
*cp2 = 0;
cp2 = &bname[0];
while (cp2 != &bname[NBUFN - 1] && *cp1 != 0 && *cp1 != ';')
*cp2++ = *cp1++;
*cp2 = 0;
}
unqname(name) /* make sure a buffer name is unique */
char *name; /* name to check on */
unqname(name)
/* make sure a buffer name is unique */
char *name; /* name to check on */
{
register char *sp;
@ -370,7 +372,7 @@ char *name; /* name to check on */
sp = name;
while (*sp)
++sp;
if (sp == name || (*(sp-1) <'0' || *(sp-1) > '8')) {
if (sp == name || (*(sp - 1) < '0' || *(sp - 1) > '8')) {
*sp++ = '0';
*sp = 0;
} else
@ -389,25 +391,25 @@ char *name; /* name to check on */
*/
filewrite(f, n)
{
register WINDOW *wp;
register int s;
char fname[NFILEN];
register WINDOW *wp;
register int s;
char fname[NFILEN];
if (restflag) /* don't allow this command if restricted */
return(resterr());
if ((s=mlreply("Write file: ", fname, NFILEN)) != TRUE)
return (s);
if ((s=writeout(fname)) == TRUE) {
strcpy(curbp->b_fname, fname);
curbp->b_flag &= ~BFCHG;
wp = wheadp; /* Update mode lines. */
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
}
return (s);
return (resterr());
if ((s = mlreply("Write file: ", fname, NFILEN)) != TRUE)
return (s);
if ((s = writeout(fname)) == TRUE) {
strcpy(curbp->b_fname, fname);
curbp->b_flag &= ~BFCHG;
wp = wheadp; /* Update mode lines. */
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
}
return (s);
}
/*
@ -420,36 +422,36 @@ filewrite(f, n)
*/
filesave(f, n)
{
register WINDOW *wp;
register int s;
register WINDOW *wp;
register int s;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if ((curbp->b_flag&BFCHG) == 0) /* Return, no changes. */
return (TRUE);
if (curbp->b_fname[0] == 0) { /* Must have a name. */
mlwrite("No file name");
return (FALSE);
}
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return (rdonly()); /* we are in read only mode */
if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */
return (TRUE);
if (curbp->b_fname[0] == 0) { /* Must have a name. */
mlwrite("No file name");
return (FALSE);
}
/* complain about truncated files */
if ((curbp->b_flag&BFTRUNC) != 0) {
if ((curbp->b_flag & BFTRUNC) != 0) {
if (mlyesno("Truncated file ... write it out") == FALSE) {
mlwrite("(Aborted)");
return(FALSE);
return (FALSE);
}
}
if ((s=writeout(curbp->b_fname)) == TRUE) {
curbp->b_flag &= ~BFCHG;
wp = wheadp; /* Update mode lines. */
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
}
return (s);
if ((s = writeout(curbp->b_fname)) == TRUE) {
curbp->b_flag &= ~BFCHG;
wp = wheadp; /* Update mode lines. */
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
}
return (s);
}
/*
@ -461,47 +463,47 @@ filesave(f, n)
* checking of some sort.
*/
writeout(fn)
char *fn;
char *fn;
{
register int s;
register LINE *lp;
register int nline;
register int s;
register LINE *lp;
register int nline;
#if CRYPT
s = resetkey();
if (s != TRUE)
return(s);
return (s);
#endif
/* turn off ALL keyboard translation in case we get a dos error */
TTkclose();
if ((s=ffwopen(fn)) != FIOSUC) { /* Open writes message. */
if ((s = ffwopen(fn)) != FIOSUC) { /* Open writes message. */
TTkopen();
return (FALSE);
}
mlwrite("(Writing...)"); /* tell us were writing */
lp = lforw(curbp->b_linep); /* First line. */
nline = 0; /* Number of lines. */
while (lp != curbp->b_linep) {
if ((s=ffputline(&lp->l_text[0], llength(lp))) != FIOSUC)
break;
++nline;
lp = lforw(lp);
}
if (s == FIOSUC) { /* No write error. */
s = ffclose();
if (s == FIOSUC) { /* No close error. */
if (nline == 1)
return (FALSE);
}
mlwrite("(Writing...)"); /* tell us were writing */
lp = lforw(curbp->b_linep); /* First line. */
nline = 0; /* Number of lines. */
while (lp != curbp->b_linep) {
if ((s = ffputline(&lp->l_text[0], llength(lp))) != FIOSUC)
break;
++nline;
lp = lforw(lp);
}
if (s == FIOSUC) { /* No write error. */
s = ffclose();
if (s == FIOSUC) { /* No close error. */
if (nline == 1)
mlwrite("(Wrote 1 line)");
else
else
mlwrite("(Wrote %d lines)", nline);
}
} else /* Ignore close error */
ffclose(); /* if a write error. */
}
} else /* Ignore close error */
ffclose(); /* if a write error. */
TTkopen();
if (s != FIOSUC) /* Some sort of error. */
return (FALSE);
return (TRUE);
if (s != FIOSUC) /* Some sort of error. */
return (FALSE);
return (TRUE);
}
/*
@ -515,26 +517,26 @@ char *fn;
*/
filename(f, n)
{
register WINDOW *wp;
register int s;
char fname[NFILEN];
register WINDOW *wp;
register int s;
char fname[NFILEN];
if (restflag) /* don't allow this command if restricted */
return(resterr());
if ((s=mlreply("Name: ", fname, NFILEN)) == ABORT)
return (s);
if (s == FALSE)
strcpy(curbp->b_fname, "");
else
strcpy(curbp->b_fname, fname);
wp = wheadp; /* Update mode lines. */
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
return (resterr());
if ((s = mlreply("Name: ", fname, NFILEN)) == ABORT)
return (s);
if (s == FALSE)
strcpy(curbp->b_fname, "");
else
strcpy(curbp->b_fname, fname);
wp = wheadp; /* Update mode lines. */
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
curbp->b_mode &= ~MDVIEW; /* no longer read only mode */
return (TRUE);
return (TRUE);
}
/*
@ -543,34 +545,34 @@ filename(f, n)
* status of the read.
*/
ifile(fname)
char fname[];
char fname[];
{
register LINE *lp0;
register LINE *lp1;
register LINE *lp2;
register int i;
register BUFFER *bp;
register int s;
register int nbytes;
register int nline;
int lflag; /* any lines longer than allowed? */
register LINE *lp0;
register LINE *lp1;
register LINE *lp2;
register int i;
register BUFFER *bp;
register int s;
register int nbytes;
register int nline;
int lflag; /* any lines longer than allowed? */
char mesg[NSTRING];
bp = curbp; /* Cheap. */
bp->b_flag |= BFCHG; /* we have changed */
bp->b_flag &= ~BFINVS; /* and are not temporary*/
if ((s=ffropen(fname)) == FIOERR) /* Hard file open. */
goto out;
if (s == FIOFNF) { /* File not found. */
bp = curbp; /* Cheap. */
bp->b_flag |= BFCHG; /* we have changed */
bp->b_flag &= ~BFINVS; /* and are not temporary */
if ((s = ffropen(fname)) == FIOERR) /* Hard file open. */
goto out;
if (s == FIOFNF) { /* File not found. */
mlwrite("(No such file)");
return(FALSE);
}
return (FALSE);
}
mlwrite("(Inserting file)");
#if CRYPT
s = resetkey();
if (s != TRUE)
return(s);
return (s);
#endif
/* back up a line and save the mark here */
curwp->w_dotp = lback(curwp->w_dotp);
@ -578,14 +580,14 @@ char fname[];
curwp->w_markp = curwp->w_dotp;
curwp->w_marko = 0;
nline = 0;
nline = 0;
lflag = FALSE;
while ((s=ffgetline()) == FIOSUC) {
nbytes = strlen(fline);
if ((lp1=lalloc(nbytes)) == NULL) {
s = FIOMEM; /* Keep message on the */
break; /* display. */
}
while ((s = ffgetline()) == FIOSUC) {
nbytes = strlen(fline);
if ((lp1 = lalloc(nbytes)) == NULL) {
s = FIOMEM; /* Keep message on the */
break; /* display. */
}
lp0 = curwp->w_dotp; /* line previous to insert */
lp2 = lp0->l_fp; /* line after insert */
@ -597,14 +599,14 @@ char fname[];
/* and advance and write out the current line */
curwp->w_dotp = lp1;
for (i=0; i<nbytes; ++i)
lputc(lp1, i, fline[i]);
++nline;
}
ffclose(); /* Ignore errors. */
for (i = 0; i < nbytes; ++i)
lputc(lp1, i, fline[i]);
++nline;
}
ffclose(); /* Ignore errors. */
curwp->w_markp = lforw(curwp->w_markp);
strcpy(mesg, "(");
if (s==FIOERR) {
if (s == FIOERR) {
strcat(mesg, "I/O ERROR, ");
curbp->b_flag |= BFTRUNC;
}
@ -613,12 +615,12 @@ char fname[];
curbp->b_flag |= BFTRUNC;
}
sprintf(&mesg[strlen(mesg)], "Inserted %d line", nline);
if (nline > 1)
if (nline > 1)
strcat(mesg, "s");
strcat(mesg, ")");
mlwrite(mesg);
out:
out:
/* advance to the next line and mark the window for changes */
curwp->w_dotp = lforw(curwp->w_dotp);
curwp->w_flag |= WFHARD | WFMODE;
@ -629,7 +631,7 @@ out:
curbp->b_markp = curwp->w_markp;
curbp->b_marko = curwp->w_marko;
if (s == FIOERR) /* False if error. */
return (FALSE);
return (TRUE);
if (s == FIOERR) /* False if error. */
return (FALSE);
return (TRUE);
}

168
fileio.c
View File

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

323
ibmpc.c
View File

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

366
input.c
View File

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

597
isearch.c
View File

@ -28,51 +28,51 @@
#if ISRCH
extern int scanner(); /* Handy search routine */
extern int eq(); /* Compare chars, match case */
extern int scanner(); /* Handy search routine */
extern int eq(); /* Compare chars, match case */
/* A couple of "own" variables for re-eat */
int (*saved_get_char)(); /* Get character routine */
int eaten_char = -1; /* Re-eaten char */
int (*saved_get_char) (); /* Get character routine */
int eaten_char = -1; /* Re-eaten char */
/* A couple more "own" variables for the command string */
int cmd_buff[CMDBUFLEN]; /* Save the command args here */
int cmd_offset; /* Current offset into command buff */
int cmd_reexecute = -1; /* > 0 if re-executing command */
int cmd_buff[CMDBUFLEN]; /* Save the command args here */
int cmd_offset; /* Current offset into command buff */
int cmd_reexecute = -1; /* > 0 if re-executing command */
/*
* Subroutine to do incremental reverse search. It actually uses the
* same code as the normal incremental search, as both can go both ways.
*/
int risearch(f, n)
{
LINE *curline; /* Current line on entry */
int curoff; /* Current offset on entry */
LINE *curline; /* Current line 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 */
curoff = curwp->w_doto; /* Save the current offset */
curline = curwp->w_dotp; /* Save the current line pointer */
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 error in search: */
curwp->w_dotp = curline; /* Reset the line pointer */
curwp->w_doto = curoff; /* and the offset to original value */
curwp->w_flag |= WFMOVE; /* Say we've moved */
update(FALSE); /* And force an update */
mlwrite ("(search failed)"); /* Say we died */
if (!(isearch(f, -n))) { /* Call ISearch backwards *//* If error in search: */
curwp->w_dotp = curline; /* Reset the line pointer */
curwp->w_doto = curoff; /* and the offset to original value */
curwp->w_flag |= WFMOVE; /* Say we've moved */
update(FALSE); /* And force an update */
mlwrite("(search failed)"); /* Say we died */
#if PKCODE
matchlen = strlen(pat);
matchlen = strlen(pat);
#endif
} else mlerase (); /* If happy, just erase the cmd line */
} else
mlerase(); /* If happy, just erase the cmd line */
#if PKCODE
matchlen = strlen(pat);
#endif
@ -82,27 +82,27 @@ int risearch(f, n)
int fisearch(f, n)
{
LINE *curline; /* Current line on entry */
int curoff; /* Current offset on entry */
LINE *curline; /* Current line 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 */
curoff = curwp->w_doto; /* Save the current offset */
curline = curwp->w_dotp; /* Save the current line pointer */
curoff = curwp->w_doto; /* Save the current offset */
/* do the search */
/* do the search */
if (!(isearch(f, n))) /* Call ISearch forwards */
{ /* If error in search: */
curwp->w_dotp = curline; /* Reset the line pointer */
curwp->w_doto = curoff; /* and the offset to original value */
curwp->w_flag |= WFMOVE; /* Say we've moved */
update(FALSE); /* And force an update */
mlwrite ("(search failed)"); /* Say we died */
if (!(isearch(f, n))) { /* Call ISearch forwards *//* If error in search: */
curwp->w_dotp = curline; /* Reset the line pointer */
curwp->w_doto = curoff; /* and the offset to original value */
curwp->w_flag |= WFMOVE; /* Say we've moved */
update(FALSE); /* And force an update */
mlwrite("(search failed)"); /* Say we died */
#if PKCODE
matchlen = strlen(pat);
matchlen = strlen(pat);
#endif
} else mlerase (); /* If happy, just erase the cmd line */
} else
mlerase(); /* If happy, just erase the cmd line */
#if PKCODE
matchlen = strlen(pat);
#endif
@ -133,139 +133,131 @@ int fisearch(f, n)
* will stall until the pattern string is edited back into something that
* exists (or until the search is aborted).
*/
isearch(f, n)
{
int status; /* Search status */
int col; /* prompt column */
register int cpos; /* character number in search string */
register int c; /* current input character */
register int expc; /* function expanded input char */
char pat_save[NPAT]; /* Saved copy of the old pattern str */
LINE *curline; /* Current line on entry */
int curoff; /* Current offset on entry */
int init_direction; /* The initial search direction */
int status; /* Search status */
int col; /* prompt column */
register int cpos; /* character number in search string */
register int c; /* current input character */
register int expc; /* function expanded input char */
char pat_save[NPAT]; /* Saved copy of the old pattern str */
LINE *curline; /* Current line on entry */
int curoff; /* Current offset on entry */
int init_direction; /* The initial search direction */
/* Initialize starting conditions */
/* Initialize starting conditions */
cmd_reexecute = -1; /* We're not re-executing (yet?) */
cmd_offset = 0; /* Start at the beginning of the buff */
cmd_buff[0] = '\0'; /* Init the command buffer */
strncpy (pat_save, pat, NPAT); /* Save the old pattern string */
curline = curwp->w_dotp; /* Save the current line pointer */
curoff = curwp->w_doto; /* Save the current offset */
init_direction = n; /* Save the initial search direction */
cmd_reexecute = -1; /* We're not re-executing (yet?) */
cmd_offset = 0; /* Start at the beginning of the buff */
cmd_buff[0] = '\0'; /* Init the command buffer */
strncpy(pat_save, pat, NPAT); /* Save the old pattern string */
curline = curwp->w_dotp; /* Save the current line pointer */
curoff = curwp->w_doto; /* Save the current offset */
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 */
col = promptpattern("ISearch: "); /* Prompt, remember the col */
/* ask the user for the text of a pattern */
col = promptpattern("ISearch: "); /* Prompt, remember the col */
cpos = 0; /* Start afresh */
status = TRUE; /* Assume everything's cool */
cpos = 0; /* Start afresh */
status = TRUE; /* Assume everything's cool */
/*
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
*/
/*
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
*/
c = ectoc(expc = get_char()); /* Get the first character */
if ((c == IS_FORWARD) ||
(c == IS_REVERSE) ||
(c == IS_VMSFORW)) /* Reuse old search string? */
{
for (cpos = 0; pat[cpos] != 0; cpos++) /* Yup, find the length */
col = echochar(pat[cpos],col); /* and re-echo the string */
if (c == IS_REVERSE) { /* forward search? */
n = -1; /* No, search in reverse */
backchar (TRUE, 1); /* Be defensive about EOB */
} else
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 */
c = ectoc(expc = get_char()); /* Get the first character */
if ((c == IS_FORWARD) || (c == IS_REVERSE) || (c == IS_VMSFORW)) { /* Reuse old search string? */
for (cpos = 0; pat[cpos] != 0; cpos++) /* Yup, find the length */
col = echochar(pat[cpos], col); /* and re-echo the string */
if (c == IS_REVERSE) { /* forward search? */
n = -1; /* No, search in reverse */
backchar(TRUE, 1); /* Be defensive about EOB */
} else
n = 1; /* Yes, search forward */
status = scanmore(pat, n); /* Do the search */
c = ectoc(expc = get_char()); /* Get another character */
}
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 {;;} */
/* 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 */
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.
*/
int checknext (chr, patrn, dir) /* Check next character in search string */
char chr; /* Next char to look for */
char *patrn; /* The entire search string (incl chr) */
int dir; /* Search direction */
int checknext(chr, patrn, dir) /* Check next character in search string */
char chr; /* Next char to look for */
char *patrn; /* The entire search string (incl chr) */
int dir; /* Search direction */
{
register LINE *curline; /* current line during scan */
register int curoff; /* position within current line */
register int buffchar; /* character at current position */
int status; /* how well things go */
register LINE *curline; /* current line during scan */
register int curoff; /* position within current line */
register int buffchar; /* character at current position */
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 */
curoff = curwp->w_doto; /* Get the offset within that line */
curline = curwp->w_dotp; /* Get the current line structure */
curoff = curwp->w_doto; /* Get the offset within that line */
if (dir > 0) /* If searching forward */
{
if (curoff == llength(curline)) /* If at end of line */
{
curline = lforw(curline); /* Skip to the next line */
if (curline == curbp->b_linep)
return (FALSE); /* Abort if at end of buffer */
curoff = 0; /* Start at the beginning of the line */
buffchar = '\n'; /* And say the next char is NL */
} else
buffchar = lgetc(curline, curoff++); /* Get the next char */
if (status = eq(buffchar, chr)) /* Is it what we're looking for? */
{
curwp->w_dotp = curline; /* Yes, set the buffer's point */
curwp->w_doto = curoff; /* to the matched character */
curwp->w_flag |= WFMOVE; /* Say that we've moved */
}
return (status); /* And return the status */
} else /* Else, if reverse search: */
return (match_pat (patrn)); /* See if we're in the right place */
if (dir > 0) { /* If searching forward */
if (curoff == llength(curline)) { /* If at end of line */
curline = lforw(curline); /* Skip to the next line */
if (curline == curbp->b_linep)
return (FALSE); /* Abort if at end of buffer */
curoff = 0; /* Start at the beginning of the line */
buffchar = '\n'; /* And say the next char is NL */
} else
buffchar = lgetc(curline, curoff++); /* Get the next char */
if (status = eq(buffchar, chr)) { /* Is it what we're looking for? */
curwp->w_dotp = curline; /* Yes, set the buffer's point */
curwp->w_doto = curoff; /* to the matched character */
curwp->w_flag |= WFMOVE; /* Say that we've moved */
}
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
* 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? */
{
rvstrcpy(tap, patrn); /* Put reversed string in tap */
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? */
rvstrcpy(tap, patrn); /* Put reversed string in tap */
sts = scanner(tap, REVERSE, PTBEG);
}
else
} else
sts = scanner(patrn, FORWARD, PTEND); /* Nope. Go forward */
if (!sts)
{
if (!sts) {
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.
*/
int match_pat (patrn) /* See if the pattern string matches string at "." */
char *patrn; /* String to match to buffer */
int match_pat(patrn) /* See if the pattern string matches string at "." */
char *patrn; /* String to match to buffer */
{
register int i; /* Generic loop index/offset */
register int buffchar; /* character at current position */
register LINE *curline; /* current line during scan */
register int curoff; /* position within current line */
register int i; /* Generic loop index/offset */
register int buffchar; /* character at current position */
register LINE *curline; /* current line during scan */
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 */
curoff = curwp->w_doto; /* Get the offset within that line */
curline = curwp->w_dotp; /* Get the current line structure */
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 */
{
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 */
if (curline == curbp->b_linep)
return (FALSE); /* Abort if at end of buffer */
buffchar = '\n'; /* And say the next char is NL */
} else
buffchar = lgetc(curline, curoff++); /* Get the next char */
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*/
for (i = 0; i < strlen(patrn); i++) { /* Loop for all characters in patrn */
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 */
if (curline == curbp->b_linep)
return (FALSE); /* Abort if at end of buffer */
buffchar = '\n'; /* And say the next char is NL */
} else
buffchar = lgetc(curline, curoff++); /* Get the next char */
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 */
}
/* Routine to prompt for I-Search string. */
@ -397,63 +381,61 @@ char *patrn; /* String to match to buffer */
int promptpattern(prompt)
char *prompt;
{
char tpat[NPAT+20];
char tpat[NPAT + 20];
strcpy(tpat, prompt); /* copy prompt to output string */
strcat(tpat, " ("); /* build new prompt string */
expandp(pat, &tpat[strlen(tpat)], NPAT/2); /* add old pattern */
strcat(tpat, ")<Meta>: ");
strcpy(tpat, prompt); /* copy prompt to output string */
strcat(tpat, " ("); /* build new prompt string */
expandp(pat, &tpat[strlen(tpat)], NPAT / 2); /* add old pattern */
strcat(tpat, ")<Meta>: ");
/* check to see if we are executing a command line */
if (!clexec) {
mlwrite(tpat);
}
return(strlen(tpat));
/* check to see if we are executing a command line */
if (!clexec) {
mlwrite(tpat);
}
return (strlen(tpat));
}
/* routine to echo i-search characters */
int echochar(c,col)
int c; /* character to be echoed */
int col; /* column to be echoed in */
int echochar(c, col)
int c; /* character to be echoed */
int col; /* column to be echoed in */
{
movecursor(term.t_nrow,col); /* Position the cursor */
if ((c < ' ') || (c == 0x7F)) /* Control character? */
{
switch (c) /* Yes, dispatch special cases*/
{
case '\n': /* Newline */
TTputc('<');
TTputc('N');
TTputc('L');
TTputc('>');
col += 3;
break;
movecursor(term.t_nrow, col); /* Position the cursor */
if ((c < ' ') || (c == 0x7F)) { /* Control character? */
switch (c) { /* Yes, dispatch special cases */
case '\n': /* Newline */
TTputc('<');
TTputc('N');
TTputc('L');
TTputc('>');
col += 3;
break;
case '\t': /* Tab */
TTputc('<');
TTputc('T');
TTputc('A');
TTputc('B');
TTputc('>');
col += 4;
break;
case '\t': /* Tab */
TTputc('<');
TTputc('T');
TTputc('A');
TTputc('B');
TTputc('>');
col += 4;
break;
case 0x7F: /* Rubout: */
TTputc('^'); /* Output a funny looking */
TTputc('?'); /* indication of Rubout */
col++; /* Count the extra char */
break;
case 0x7F: /* Rubout: */
TTputc('^'); /* Output a funny looking */
TTputc('?'); /* indication of Rubout */
col++; /* Count the extra char */
break;
default: /* Vanilla control char */
TTputc('^'); /* Yes, output prefix */
TTputc(c+0x40); /* Make it "^X" */
col++; /* Count this char */
}
} else
TTputc(c); /* Otherwise, output raw char */
TTflush(); /* Flush the output */
return(++col); /* return the new column no */
default: /* Vanilla control char */
TTputc('^'); /* Yes, output prefix */
TTputc(c + 0x40); /* Make it "^X" */
col++; /* Count this char */
}
} else
TTputc(c); /* Otherwise, output raw char */
TTflush(); /* Flush the output */
return (++col); /* return the new column no */
}
/*
@ -463,29 +445,28 @@ int col; /* column to be echoed in */
* 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 ((c = cmd_buff[cmd_reexecute++]) != 0)
return (c); /* Yes, return any character */
if (cmd_reexecute >= 0) /* Is there an offset? */
if ((c = cmd_buff[cmd_reexecute++]) != 0)
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 */
update(FALSE); /* Pretty up the screen */
if (cmd_offset >= CMDBUFLEN-1) /* If we're getting too big ... */
{
mlwrite ("? command too long"); /* Complain loudly and bitterly */
return (metac); /* And force a quit */
}
c = get1key(); /* Get the next character */
cmd_buff[cmd_offset++] = c; /* Save the char for next time */
cmd_buff[cmd_offset] = '\0';/* And terminate the buffer */
return (c); /* Return the character */
cmd_reexecute = -1; /* Say we're in real mode again */
update(FALSE); /* Pretty up the screen */
if (cmd_offset >= CMDBUFLEN - 1) { /* If we're getting too big ... */
mlwrite("? command too long"); /* Complain loudly and bitterly */
return (metac); /* And force a quit */
}
c = get1key(); /* Get the next character */
cmd_buff[cmd_offset++] = c; /* Save the char for next time */
cmd_buff[cmd_offset] = '\0'; /* And terminate the buffer */
return (c); /* Return the character */
}
/*
@ -497,22 +478,22 @@ int get_char ()
int uneat()
{
int c;
int c;
term.t_getchar = saved_get_char; /* restore the routine address */
c = eaten_char; /* Get the re-eaten char */
eaten_char = -1; /* Clear the old char */
return(c); /* and return the last char */
term.t_getchar = saved_get_char; /* restore the routine address */
c = eaten_char; /* Get the re-eaten char */
eaten_char = -1; /* Clear the old char */
return (c); /* and return the last char */
}
int reeat(c)
int c;
int c;
{
if (eaten_char != -1) /* If we've already been here */
return/*(NULL)*/; /* Don't do it again */
eaten_char = c; /* Else, save the char for later */
saved_get_char = term.t_getchar; /* Save the char get routine */
term.t_getchar = uneat; /* Replace it with ours */
if (eaten_char != -1) /* If we've already been here */
return /*(NULL) */ ; /* Don't do it again */
eaten_char = c; /* Else, save the char for later */
saved_get_char = term.t_getchar; /* Save the char get routine */
term.t_getchar = uneat; /* Replace it with ours */
}
#else
isearch()

256
line.c
View File

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

59
lock.c
View File

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

597
main.c
View File

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

View File

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

33
posix.c
View File

@ -21,16 +21,16 @@
#include <fcntl.h>
#include <errno.h>
int kbdflgs; /* saved keyboard fd flags */
int kbdpoll; /* in O_NDELAY mode */
int kbdqp; /* there is a char in kbdq */
char kbdq; /* char we've already read */
int kbdflgs; /* saved keyboard fd flags */
int kbdpoll; /* in O_NDELAY mode */
int kbdqp; /* there is a char in kbdq */
char kbdq; /* char we've already read */
struct termios otermios; /* original terminal characteristics */
struct termios ntermios; /* charactoristics to use inside */
struct termios otermios; /* original terminal characteristics */
struct termios ntermios; /* charactoristics to use inside */
#define TBUFSIZ 128
char tobuf[TBUFSIZ]; /* terminal output buffer */
char tobuf[TBUFSIZ]; /* terminal output buffer */
/*
@ -53,12 +53,13 @@ ttopen()
| INPCK | INLCR | IGNCR | ICRNL);
/* 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 */
ntermios.c_lflag &= ~(ISIG | ICANON | XCASE | ECHO | ECHOE | ECHOK
| ECHONL | NOFLSH | TOSTOP | ECHOCTL | ECHOPRT
| ECHOKE | FLUSHO | PENDIN | IEXTEN);
| ECHONL | NOFLSH | TOSTOP | ECHOCTL |
ECHOPRT | ECHOKE | FLUSHO | PENDIN | IEXTEN);
/* one character, no timeout */
ntermios.c_cc[VMIN] = 1;
@ -71,11 +72,11 @@ ttopen()
*/
setbuffer(stdout, &tobuf[0], TBUFSIZ);
kbdflgs = fcntl( 0, F_GETFL, 0 );
kbdflgs = fcntl(0, F_GETFL, 0);
kbdpoll = FALSE;
/* on all screens we are not sure of the initial position
of the cursor */
of the cursor */
ttrow = 999;
ttcol = 999;
}
@ -136,7 +137,7 @@ ttflush()
*/
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
@ -145,10 +146,10 @@ ttgetc()
typahead()
{
int x; /* holds # of pending chars */
int x; /* holds # of pending chars */
#ifdef FIONREAD
if (ioctl(0,FIONREAD,&x) < 0)
if (ioctl(0, FIONREAD, &x) < 0)
x = 0;
#else
x = 0;
@ -156,4 +157,4 @@ typahead()
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)
{
register int s;
REGION region;
register int s;
REGION region;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if ((s=getregion(&region)) != TRUE)
return (s);
if ((lastflag&CFKILL) == 0) /* This is a kill type */
kdelete(); /* command, so do magic */
thisflag |= CFKILL; /* kill buffer stuff. */
curwp->w_dotp = region.r_linep;
curwp->w_doto = region.r_offset;
return (ldelete(region.r_size, TRUE));
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return (rdonly()); /* we are in read only mode */
if ((s = getregion(&region)) != TRUE)
return (s);
if ((lastflag & CFKILL) == 0) /* This is a kill type */
kdelete(); /* command, so do magic */
thisflag |= CFKILL; /* kill buffer stuff. */
curwp->w_dotp = region.r_linep;
curwp->w_doto = region.r_offset;
return (ldelete(region.r_size, TRUE));
}
/*
@ -44,32 +44,32 @@ killregion(f, n)
*/
copyregion(f, n)
{
register LINE *linep;
register int loffs;
register int s;
REGION region;
register LINE *linep;
register int loffs;
register int s;
REGION region;
if ((s=getregion(&region)) != TRUE)
return (s);
if ((lastflag&CFKILL) == 0) /* Kill type command. */
kdelete();
thisflag |= CFKILL;
linep = region.r_linep; /* Current line. */
loffs = region.r_offset; /* Current offset. */
while (region.r_size--) {
if (loffs == llength(linep)) { /* End of line. */
if ((s=kinsert('\n')) != TRUE)
return (s);
linep = lforw(linep);
loffs = 0;
} else { /* Middle of line. */
if ((s=kinsert(lgetc(linep, loffs))) != TRUE)
return (s);
++loffs;
}
}
if ((s = getregion(&region)) != TRUE)
return (s);
if ((lastflag & CFKILL) == 0) /* Kill type command. */
kdelete();
thisflag |= CFKILL;
linep = region.r_linep; /* Current line. */
loffs = region.r_offset; /* Current offset. */
while (region.r_size--) {
if (loffs == llength(linep)) { /* End of line. */
if ((s = kinsert('\n')) != TRUE)
return (s);
linep = lforw(linep);
loffs = 0;
} else { /* Middle of line. */
if ((s = kinsert(lgetc(linep, loffs))) != TRUE)
return (s);
++loffs;
}
}
mlwrite("(region copied)");
return (TRUE);
return (TRUE);
}
/*
@ -82,31 +82,31 @@ copyregion(f, n)
*/
lowerregion(f, n)
{
register LINE *linep;
register int loffs;
register int c;
register int s;
REGION region;
register LINE *linep;
register int loffs;
register int c;
register int s;
REGION region;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if ((s=getregion(&region)) != TRUE)
return (s);
lchange(WFHARD);
linep = region.r_linep;
loffs = region.r_offset;
while (region.r_size--) {
if (loffs == llength(linep)) {
linep = lforw(linep);
loffs = 0;
} else {
c = lgetc(linep, loffs);
if (c>='A' && c<='Z')
lputc(linep, loffs, c+'a'-'A');
++loffs;
}
}
return (TRUE);
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return (rdonly()); /* we are in read only mode */
if ((s = getregion(&region)) != TRUE)
return (s);
lchange(WFHARD);
linep = region.r_linep;
loffs = region.r_offset;
while (region.r_size--) {
if (loffs == llength(linep)) {
linep = lforw(linep);
loffs = 0;
} else {
c = lgetc(linep, loffs);
if (c >= 'A' && c <= 'Z')
lputc(linep, loffs, c + 'a' - 'A');
++loffs;
}
}
return (TRUE);
}
/*
@ -119,31 +119,31 @@ lowerregion(f, n)
*/
upperregion(f, n)
{
register LINE *linep;
register int loffs;
register int c;
register int s;
REGION region;
register LINE *linep;
register int loffs;
register int c;
register int s;
REGION region;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if ((s=getregion(&region)) != TRUE)
return (s);
lchange(WFHARD);
linep = region.r_linep;
loffs = region.r_offset;
while (region.r_size--) {
if (loffs == llength(linep)) {
linep = lforw(linep);
loffs = 0;
} else {
c = lgetc(linep, loffs);
if (c>='a' && c<='z')
lputc(linep, loffs, c-'a'+'A');
++loffs;
}
}
return (TRUE);
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return (rdonly()); /* we are in read only mode */
if ((s = getregion(&region)) != TRUE)
return (s);
lchange(WFHARD);
linep = region.r_linep;
loffs = region.r_offset;
while (region.r_size--) {
if (loffs == llength(linep)) {
linep = lforw(linep);
loffs = 0;
} else {
c = lgetc(linep, loffs);
if (c >= 'a' && c <= 'z')
lputc(linep, loffs, c - 'a' + 'A');
++loffs;
}
}
return (TRUE);
}
/*
@ -160,53 +160,54 @@ upperregion(f, n)
getregion(rp)
register REGION *rp;
{
register LINE *flp;
register LINE *blp;
long fsize;
long bsize;
register LINE *flp;
register LINE *blp;
long fsize;
long bsize;
if (curwp->w_markp == NULL) {
mlwrite("No mark set in this window");
return (FALSE);
}
if (curwp->w_dotp == curwp->w_markp) {
rp->r_linep = curwp->w_dotp;
if (curwp->w_doto < curwp->w_marko) {
rp->r_offset = curwp->w_doto;
rp->r_size = (long)(curwp->w_marko-curwp->w_doto);
} else {
rp->r_offset = curwp->w_marko;
rp->r_size = (long)(curwp->w_doto-curwp->w_marko);
}
return (TRUE);
}
blp = curwp->w_dotp;
bsize = (long)curwp->w_doto;
flp = curwp->w_dotp;
fsize = (long)(llength(flp)-curwp->w_doto+1);
while (flp!=curbp->b_linep || lback(blp)!=curbp->b_linep) {
if (flp != curbp->b_linep) {
flp = lforw(flp);
if (flp == curwp->w_markp) {
rp->r_linep = curwp->w_dotp;
rp->r_offset = curwp->w_doto;
rp->r_size = fsize+curwp->w_marko;
return (TRUE);
}
fsize += llength(flp)+1;
}
if (lback(blp) != curbp->b_linep) {
blp = lback(blp);
bsize += llength(blp)+1;
if (blp == curwp->w_markp) {
rp->r_linep = blp;
rp->r_offset = curwp->w_marko;
rp->r_size = bsize - curwp->w_marko;
return (TRUE);
}
}
}
mlwrite("Bug: lost mark");
return (FALSE);
if (curwp->w_markp == NULL) {
mlwrite("No mark set in this window");
return (FALSE);
}
if (curwp->w_dotp == curwp->w_markp) {
rp->r_linep = curwp->w_dotp;
if (curwp->w_doto < curwp->w_marko) {
rp->r_offset = curwp->w_doto;
rp->r_size =
(long) (curwp->w_marko - curwp->w_doto);
} else {
rp->r_offset = curwp->w_marko;
rp->r_size =
(long) (curwp->w_doto - curwp->w_marko);
}
return (TRUE);
}
blp = curwp->w_dotp;
bsize = (long) curwp->w_doto;
flp = curwp->w_dotp;
fsize = (long) (llength(flp) - curwp->w_doto + 1);
while (flp != curbp->b_linep || lback(blp) != curbp->b_linep) {
if (flp != curbp->b_linep) {
flp = lforw(flp);
if (flp == curwp->w_markp) {
rp->r_linep = curwp->w_dotp;
rp->r_offset = curwp->w_doto;
rp->r_size = fsize + curwp->w_marko;
return (TRUE);
}
fsize += llength(flp) + 1;
}
if (lback(blp) != curbp->b_linep) {
blp = lback(blp);
bsize += llength(blp) + 1;
if (blp == curwp->w_markp) {
rp->r_linep = blp;
rp->r_offset = curwp->w_marko;
rp->r_size = bsize - curwp->w_marko;
return (TRUE);
}
}
}
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"
#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 <descrip.h>
#include <iodef.h>
extern int oldmode[3]; /* In "termio.c" */
extern int newmode[3]; /* In "termio.c" */
extern short iochan; /* In "termio.c" */
extern int oldmode[3]; /* In "termio.c" */
extern int newmode[3]; /* In "termio.c" */
extern short iochan; /* In "termio.c" */
#endif
#if V7 | USG | BSD
@ -43,50 +43,50 @@ extern void sizesignal();
spawncli(f, n)
{
#if V7 | USG | BSD
register char *cp;
char *getenv();
register char *cp;
char *getenv();
#endif
/* don't allow this command if restricted */
if (restflag)
return(resterr());
return (resterr());
#if VMS
movecursor(term.t_nrow, 0); /* In last line. */
mlputs("(Starting DCL)\r\n");
TTflush(); /* Ignore "ttcol". */
sgarbf = TRUE;
movecursor(term.t_nrow, 0); /* In last line. */
mlputs("(Starting DCL)\r\n");
TTflush(); /* Ignore "ttcol". */
sgarbf = TRUE;
sys(NULL);
sleep(1);
mlputs("\r\n(Returning from DCL)\r\n");
TTflush();
sleep(1);
return(TRUE);
return (TRUE);
#endif
#if MSDOS & (MSC | TURBO)
movecursor(term.t_nrow, 0); /* Seek to last line. */
TTflush();
movecursor(term.t_nrow, 0); /* Seek to last line. */
TTflush();
TTkclose();
shellprog("");
TTkopen();
sgarbf = TRUE;
return(TRUE);
sgarbf = TRUE;
return (TRUE);
#endif
#if V7 | USG | BSD
movecursor(term.t_nrow, 0); /* Seek to last line. */
TTflush();
TTclose(); /* stty to old settings */
if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
system(cp);
else
movecursor(term.t_nrow, 0); /* Seek to last line. */
TTflush();
TTclose(); /* stty to old settings */
if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
system(cp);
else
#if BSD
system("exec /bin/csh");
system("exec /bin/csh");
#else
system("exec /bin/sh");
system("exec /bin/sh");
#endif
sgarbf = TRUE;
sgarbf = TRUE;
sleep(2);
TTopen();
TTopen();
TTkopen();
#ifdef SIGWINCH
/*
@ -95,17 +95,17 @@ spawncli(f, n)
* -lbt
*/
chg_width = term.t_ncol;
chg_height = term.t_nrow+1;
chg_height = term.t_nrow + 1;
term.t_nrow = term.t_ncol = 0;
#endif
return(TRUE);
return (TRUE);
#endif
}
#if BSD | __hpux | SVR4
bktoshell() /* suspend MicroEMACS and wait to wake up */
{
bktoshell()
{ /* suspend MicroEMACS and wait to wake up */
int pid;
vttidy();
@ -131,62 +131,61 @@ rtfrmshell()
*/
spawn(f, n)
{
register int s;
char line[NLINE];
register int s;
char line[NLINE];
/* don't allow this command if restricted */
if (restflag)
return(resterr());
return (resterr());
#if VMS
if ((s=mlreply("!", line, NLINE)) != TRUE)
return (s);
if ((s = mlreply("!", line, NLINE)) != TRUE)
return (s);
movecursor(term.t_nrow, 0);
TTflush();
s = sys(line); /* Run the command. */
TTflush();
s = sys(line); /* Run the command. */
if (clexec == FALSE) {
mlputs("\r\n\n(End)"); /* Pause. */
mlputs("\r\n\n(End)"); /* Pause. */
TTflush();
tgetc();
}
sgarbf = TRUE;
return (s);
sgarbf = TRUE;
return (s);
#endif
#if MSDOS
if ((s=mlreply("!", line, NLINE)) != TRUE)
return(s);
if ((s = mlreply("!", line, NLINE)) != TRUE)
return (s);
movecursor(term.t_nrow, 0);
TTkclose();
shellprog(line);
shellprog(line);
TTkopen();
/* if we are interactive, pause here */
if (clexec == FALSE) {
mlputs("\r\n(End)");
tgetc();
}
sgarbf = TRUE;
return (TRUE);
mlputs("\r\n(End)");
tgetc();
}
sgarbf = TRUE;
return (TRUE);
#endif
#if V7 | USG | BSD
if ((s=mlreply("!", line, NLINE)) != TRUE)
return (s);
TTflush();
TTclose(); /* stty to old modes */
if ((s = mlreply("!", line, NLINE)) != TRUE)
return (s);
TTflush();
TTclose(); /* stty to old modes */
TTkclose();
system(line);
fflush(stdout); /* to be sure P.K. */
TTopen();
system(line);
fflush(stdout); /* to be sure P.K. */
TTopen();
if (clexec == FALSE) {
mlputs("(End)"); /* Pause. */
mlputs("(End)"); /* Pause. */
TTflush();
while ((s = tgetc()) != '\r' && s != ' ')
;
while ((s = tgetc()) != '\r' && s != ' ');
mlputs("\r\n");
}
TTkopen();
sgarbf = TRUE;
return (TRUE);
sgarbf = TRUE;
return (TRUE);
#endif
}
@ -197,58 +196,56 @@ spawn(f, n)
*/
execprg(f, n)
{
register int s;
char line[NLINE];
register int s;
char line[NLINE];
/* don't allow this command if restricted */
if (restflag)
return(resterr());
return (resterr());
#if VMS
if ((s=mlreply("!", line, NLINE)) != TRUE)
return (s);
TTflush();
s = sys(line); /* Run the command. */
mlputs("\r\n\n(End)"); /* Pause. */
TTflush();
tgetc();
sgarbf = TRUE;
return (s);
if ((s = mlreply("!", line, NLINE)) != TRUE)
return (s);
TTflush();
s = sys(line); /* Run the command. */
mlputs("\r\n\n(End)"); /* Pause. */
TTflush();
tgetc();
sgarbf = TRUE;
return (s);
#endif
#if MSDOS
if ((s=mlreply("$", line, NLINE)) != TRUE)
return(s);
if ((s = mlreply("$", line, NLINE)) != TRUE)
return (s);
movecursor(term.t_nrow, 0);
TTkclose();
execprog(line);
execprog(line);
TTkopen();
/* if we are interactive, pause here */
if (clexec == FALSE) {
mlputs("\r\n(End)");
tgetc();
}
sgarbf = TRUE;
return (TRUE);
mlputs("\r\n(End)");
tgetc();
}
sgarbf = TRUE;
return (TRUE);
#endif
#if V7 | USG | BSD
if ((s=mlreply("!", line, NLINE)) != TRUE)
return (s);
TTputc('\n'); /* Already have '\r' */
TTflush();
TTclose(); /* stty to old modes */
system(line);
fflush(stdout); /* to be sure P.K. */
TTopen();
mlputs("(End)"); /* Pause. */
TTflush();
while ((s = tgetc()) != '\r' && s != ' ')
;
sgarbf = TRUE;
return (TRUE);
if ((s = mlreply("!", line, NLINE)) != TRUE)
return (s);
TTputc('\n'); /* Already have '\r' */
TTflush();
TTclose(); /* stty to old modes */
system(line);
fflush(stdout); /* to be sure P.K. */
TTopen();
mlputs("(End)"); /* Pause. */
TTflush();
while ((s = tgetc()) != '\r' && s != ' ');
sgarbf = TRUE;
return (TRUE);
#endif
}
@ -258,10 +255,10 @@ execprg(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 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 filnam[NSTRING] = "command";
@ -271,36 +268,38 @@ pipecmd(f, n)
char *getenv();
FILE *fp;
FILE *fopen();
int len;
int len;
#endif
/* don't allow this command if restricted */
if (restflag)
return(resterr());
return (resterr());
#if MSDOS
if ((tmp = getenv("TMP")) == NULL && (tmp = getenv("TEMP")) == NULL)
if ((tmp = getenv("TMP")) == NULL
&& (tmp = getenv("TEMP")) == NULL)
strcpy(filnam, "command");
else {
strcpy(filnam, tmp);
len = strlen(tmp);
if (len <= 0 || filnam[len-1] != '\\' && filnam[len-1] != '/')
strcat(filnam,"\\");
strcat(filnam,"command");
}
if (len <= 0 || filnam[len - 1] != '\\'
&& filnam[len - 1] != '/')
strcat(filnam, "\\");
strcat(filnam, "command");
}
#endif
#if VMS
mlwrite("Not available under VMS");
return(FALSE);
return (FALSE);
#endif
/* get the command to pipe in */
if ((s=mlreply("@", line, NLINE)) != TRUE)
return(s);
if ((s = mlreply("@", line, NLINE)) != TRUE)
return (s);
/* 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 */
wp = wheadp;
while (wp != NULL) {
@ -320,17 +319,16 @@ pipecmd(f, n)
}
if (zotbuf(bp) != TRUE)
return(FALSE);
return (FALSE);
}
#if MSDOS
strcat(line," >>");
strcat(line,filnam);
strcat(line, " >>");
strcat(line, filnam);
movecursor(term.t_nrow, 0);
TTkclose();
shellprog(line);
shellprog(line);
TTkopen();
sgarbf = TRUE;
sgarbf = TRUE;
if ((fp = fopen(filnam, "r")) == NULL) {
s = FALSE;
} else {
@ -340,27 +338,27 @@ pipecmd(f, n)
#endif
#if V7 | USG | BSD
TTflush();
TTclose(); /* stty to old modes */
strcat(line,">");
strcat(line,filnam);
system(line);
TTopen();
TTflush();
sgarbf = TRUE;
s = TRUE;
TTflush();
TTclose(); /* stty to old modes */
strcat(line, ">");
strcat(line, filnam);
system(line);
TTopen();
TTflush();
sgarbf = TRUE;
s = TRUE;
#endif
if (s != TRUE)
return(s);
return (s);
/* split the current window to make room for the command output */
if (splitwind(FALSE, 1) == FALSE)
return(FALSE);
return (FALSE);
/* and read the stuff in */
if (getfile(filnam, FALSE) == FALSE)
return(FALSE);
return (FALSE);
/* make this window in VIEW mode, update all mode lines */
curwp->w_bufp->b_mode |= MDVIEW;
@ -372,7 +370,7 @@ pipecmd(f, n)
/* and get rid of the temporary file */
unlink(filnam);
return(TRUE);
return (TRUE);
}
/*
@ -380,11 +378,10 @@ pipecmd(f, n)
* Bound to ^X #
*/
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 */
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 */
static char bname1[] = "fltinp";
@ -393,19 +390,19 @@ filter(f, n)
/* don't allow this command if restricted */
if (restflag)
return(resterr());
return (resterr());
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return (rdonly()); /* we are in read only mode */
#if VMS
mlwrite("Not available under VMS");
return(FALSE);
return (FALSE);
#endif
/* get the filter name and its args */
if ((s=mlreply("#", line, NLINE)) != TRUE)
return(s);
if ((s = mlreply("#", line, NLINE)) != TRUE)
return (s);
/* setup the proper file names */
bp = curbp;
@ -416,48 +413,47 @@ filter(f, n)
if (writeout(filnam1) != TRUE) {
mlwrite("(Cannot write filter file)");
strcpy(bp->b_fname, tmpnam);
return(FALSE);
return (FALSE);
}
#if MSDOS
strcat(line," <fltinp >fltout");
strcat(line, " <fltinp >fltout");
movecursor(term.t_nrow - 1, 0);
TTkclose();
shellprog(line);
shellprog(line);
TTkopen();
sgarbf = TRUE;
sgarbf = TRUE;
s = TRUE;
#endif
#if V7 | USG | BSD
TTputc('\n'); /* Already have '\r' */
TTflush();
TTclose(); /* stty to old modes */
strcat(line," <fltinp >fltout");
system(line);
TTopen();
TTflush();
sgarbf = TRUE;
s = TRUE;
TTputc('\n'); /* Already have '\r' */
TTflush();
TTclose(); /* stty to old modes */
strcat(line, " <fltinp >fltout");
system(line);
TTopen();
TTflush();
sgarbf = TRUE;
s = TRUE;
#endif
/* on failure, escape gracefully */
if (s != TRUE || (readin(filnam2,FALSE) == FALSE)) {
if (s != TRUE || (readin(filnam2, FALSE) == FALSE)) {
mlwrite("(Execution failed)");
strcpy(bp->b_fname, tmpnam);
unlink(filnam1);
unlink(filnam2);
return(s);
return (s);
}
/* reset file 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 */
unlink(filnam1);
unlink(filnam2);
return(TRUE);
return (TRUE);
}
#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.
*/
sys(cmd)
register char *cmd;
register char *cmd;
{
struct dsc$descriptor cdsc;
struct dsc$descriptor *cdscp;
long status;
long substatus;
long iosb[2];
struct dsc$descriptor cdsc;
struct dsc$descriptor *cdscp;
long status;
long substatus;
long iosb[2];
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
oldmode, sizeof(oldmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
return (FALSE);
cdscp = NULL; /* Assume DCL. */
if (cmd != NULL) { /* Build descriptor. */
cdsc.dsc$a_pointer = cmd;
cdsc.dsc$w_length = strlen(cmd);
cdsc.dsc$b_dtype = DSC$K_DTYPE_T;
cdsc.dsc$b_class = DSC$K_CLASS_S;
cdscp = &cdsc;
}
status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
if (status != SS$_NORMAL)
substatus = status;
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
newmode, sizeof(newmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
return (FALSE);
if ((substatus&STS$M_SUCCESS) == 0) /* Command failed. */
return (FALSE);
return (TRUE);
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
oldmode, sizeof(oldmode), 0, 0, 0, 0);
if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
return (FALSE);
cdscp = NULL; /* Assume DCL. */
if (cmd != NULL) { /* Build descriptor. */
cdsc.dsc$a_pointer = cmd;
cdsc.dsc$w_length = strlen(cmd);
cdsc.dsc$b_dtype = DSC$K_DTYPE_T;
cdsc.dsc$b_class = DSC$K_CLASS_S;
cdscp = &cdsc;
}
status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
if (status != SS$_NORMAL)
substatus = status;
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
newmode, sizeof(newmode), 0, 0, 0, 0);
if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
return (FALSE);
if ((substatus & STS$M_SUCCESS) == 0) /* Command failed. */
return (FALSE);
return (TRUE);
}
#endif
@ -507,7 +503,7 @@ register char *cmd;
shellprog(cmd)
char *cmd; /* Incoming command line to execute */
char *cmd; /* Incoming command line to execute */
{
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.al = 0x00; /* get switch character */
intdos(&regs, &regs);
swchar = (char)regs.h.dl;
swchar = (char) regs.h.dl;
/* get name of system shell */
if ((shell = getenv("COMSPEC")) == NULL) {
return(FALSE); /* No shell located */
return (FALSE); /* No shell located */
}
/* trim leading whitespace off the command */
@ -543,9 +539,9 @@ char *cmd; /* Incoming command line to execute */
comline[strlen(comline)] = swchar;
strcat(comline, "c ");
strcat(comline, cmd);
return(execprog(comline));
return (execprog(comline));
} else
return(execprog(shell));
return (execprog(shell));
}
/* EXECPROG: A function to execute a named program
@ -554,7 +550,7 @@ char *cmd; /* Incoming command line to execute */
execprog(cmd)
char *cmd; /* Incoming command line to execute */
char *cmd; /* Incoming command line to execute */
{
char *sp; /* temporary string pointer */
@ -581,16 +577,16 @@ char *cmd; /* Incoming command line to execute */
/* and parse out the command tail */
while (*cmd && ((*cmd == ' ') || (*cmd == '\t')))
++cmd;
*tail = (char)(strlen(cmd)); /* record the byte length */
*tail = (char) (strlen(cmd)); /* record the byte length */
strcpy(&tail[1], cmd);
strcat(&tail[1], "\r");
/* look up the program on the path trying various extentions */
if ((sp = flook(prog, 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)
return(FALSE);
return (FALSE);
}
strcpy(prog, sp);
@ -599,17 +595,17 @@ char *cmd; /* Incoming command line to execute */
/* set up the EXEC parameter block */
pblock.envptr = 0; /* make the child inherit the parents env */
pblock.fcb1 = f1; /* point to a blank FCB */
pblock.fcb2 = f2; /* point to a blank FCB */
pblock.cline = tail; /* parameter line pointer */
pblock.fcb1 = f1; /* point to a blank FCB */
pblock.fcb2 = f2; /* point to a blank FCB */
pblock.cline = tail; /* parameter line pointer */
/* and make the call */
regs.h.ah = 0x4b; /* EXEC Load or Execute a Program */
regs.h.al = 0x00; /* load end execute function subcode */
segreg.ds = ((unsigned long)(prog) >> 16); /* program name ptr */
regs.x.dx = (unsigned int)(prog);
segreg.es = ((unsigned long)(&pblock) >> 16); /* set up param block ptr */
regs.x.bx = (unsigned int)(&pblock);
segreg.ds = ((unsigned long) (prog) >> 16); /* program name ptr */
regs.x.dx = (unsigned int) (prog);
segreg.es = ((unsigned long) (&pblock) >> 16); /* set up param block ptr */
regs.x.bx = (unsigned int) (&pblock);
#if TURBO | MSC
intdosx(&regs, &regs, &segreg);
if (regs.x.cflag == 0) {
@ -623,6 +619,6 @@ char *cmd; /* Incoming command line to execute */
rval = -_doserrno; /* failed child call */
#endif
#endif
return((rval < 0) ? FALSE : TRUE);
return ((rval < 0) ? FALSE : TRUE);
}
#endif

392
tcap.c
View File

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

351
termio.c
View File

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

292
vmsvt.c
View File

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

167
vt52.c
View File

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

601
window.c
View File

@ -16,30 +16,29 @@
* redisplay code does). With no argument it defaults to 0. Bound to M-!.
*/
reposition(f, n)
{
if (f == FALSE) /* default to 0 to center screen */
n = 0;
curwp->w_force = n;
curwp->w_flag |= WFFORCE;
return (TRUE);
}
{
if (f == FALSE) /* default to 0 to center screen */
n = 0;
curwp->w_force = n;
curwp->w_flag |= WFFORCE;
return (TRUE);
}
/*
* Refresh the screen. With no argument, it just does the refresh. With an
* argument it recenters "." in the current window. Bound to "C-L".
*/
refresh(f, n)
{
if (f == FALSE)
sgarbf = TRUE;
else
{
curwp->w_force = 0; /* Center dot. */
curwp->w_flag |= WFFORCE;
}
{
if (f == FALSE)
sgarbf = TRUE;
else {
curwp->w_force = 0; /* Center dot. */
curwp->w_flag |= WFFORCE;
}
return (TRUE);
}
return (TRUE);
}
/*
* The command make the next window (next => down the screen) the current
@ -51,11 +50,11 @@ refresh(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 int nwindows; /* total number of windows */
register int nwindows; /* total number of windows */
if (f) {
@ -68,7 +67,7 @@ int f, n; /* default flag and numeric argument */
}
/* 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)
n = nwindows + n + 1;
@ -79,11 +78,10 @@ int f, n; /* default flag and numeric argument */
wp = wp->w_wndp;
} else {
mlwrite("Window number out of range");
return(FALSE);
return (FALSE);
}
} else
if ((wp = curwp->w_wndp) == NULL)
wp = wheadp;
} else if ((wp = curwp->w_wndp) == NULL)
wp = wheadp;
curwp = wp;
curbp = wp->w_bufp;
cknewwindow();
@ -103,7 +101,7 @@ prevwind(f, n)
/* if we have an argument, we mean the nth window from the bottom */
if (f)
return(nextwind(f, -n));
return (nextwind(f, -n));
wp1 = wheadp;
wp2 = curwp;
@ -116,7 +114,7 @@ prevwind(f, n)
curwp = wp1;
curbp = wp1->w_bufp;
cknewwindow();
cknewwindow();
upmode();
return (TRUE);
}
@ -144,47 +142,43 @@ int n;
* "C-X C-P".
*/
mvupwind(f, n)
int n;
int n;
{
register LINE *lp;
register int i;
{
register LINE *lp;
register int i;
lp = curwp->w_linep;
lp = curwp->w_linep;
if (n < 0)
{
while (n++ && lp!=curbp->b_linep)
lp = lforw(lp);
}
else
{
while (n-- && lback(lp)!=curbp->b_linep)
lp = lback(lp);
}
if (n < 0) {
while (n++ && lp != curbp->b_linep)
lp = lforw(lp);
} else {
while (n-- && lback(lp) != curbp->b_linep)
lp = lback(lp);
}
curwp->w_linep = lp;
curwp->w_flag |= WFHARD; /* Mode line is OK. */
curwp->w_linep = lp;
curwp->w_flag |= WFHARD; /* Mode line is OK. */
for (i = 0; i < curwp->w_ntrows; ++i)
{
if (lp == curwp->w_dotp)
return (TRUE);
if (lp == curbp->b_linep)
break;
lp = lforw(lp);
}
for (i = 0; i < curwp->w_ntrows; ++i) {
if (lp == curwp->w_dotp)
return (TRUE);
if (lp == curbp->b_linep)
break;
lp = lforw(lp);
}
lp = curwp->w_linep;
i = curwp->w_ntrows/2;
lp = curwp->w_linep;
i = curwp->w_ntrows / 2;
while (i-- && lp != curbp->b_linep)
lp = lforw(lp);
while (i-- && lp != curbp->b_linep)
lp = lforw(lp);
curwp->w_dotp = lp;
curwp->w_doto = 0;
return (TRUE);
}
curwp->w_dotp = lp;
curwp->w_doto = 0;
return (TRUE);
}
/*
* This command makes the current window the only window on the screen. Bound
@ -195,43 +189,43 @@ mvupwind(f, n)
*/
onlywind(f, n)
{
register WINDOW *wp;
register LINE *lp;
register int i;
register WINDOW *wp;
register LINE *lp;
register int i;
while (wheadp != curwp) {
wp = wheadp;
wheadp = wp->w_wndp;
if (--wp->w_bufp->b_nwnd == 0) {
wp->w_bufp->b_dotp = wp->w_dotp;
wp->w_bufp->b_doto = wp->w_doto;
wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko;
}
free((char *) wp);
}
while (curwp->w_wndp != NULL) {
wp = curwp->w_wndp;
curwp->w_wndp = wp->w_wndp;
if (--wp->w_bufp->b_nwnd == 0) {
wp->w_bufp->b_dotp = wp->w_dotp;
wp->w_bufp->b_doto = wp->w_doto;
wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko;
}
free((char *) wp);
}
lp = curwp->w_linep;
i = curwp->w_toprow;
while (i!=0 && lback(lp)!=curbp->b_linep) {
--i;
lp = lback(lp);
}
curwp->w_toprow = 0;
curwp->w_ntrows = term.t_nrow-1;
curwp->w_linep = lp;
curwp->w_flag |= WFMODE|WFHARD;
return (TRUE);
while (wheadp != curwp) {
wp = wheadp;
wheadp = wp->w_wndp;
if (--wp->w_bufp->b_nwnd == 0) {
wp->w_bufp->b_dotp = wp->w_dotp;
wp->w_bufp->b_doto = wp->w_doto;
wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko;
}
free((char *) wp);
}
while (curwp->w_wndp != NULL) {
wp = curwp->w_wndp;
curwp->w_wndp = wp->w_wndp;
if (--wp->w_bufp->b_nwnd == 0) {
wp->w_bufp->b_dotp = wp->w_dotp;
wp->w_bufp->b_doto = wp->w_doto;
wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko;
}
free((char *) wp);
}
lp = curwp->w_linep;
i = curwp->w_toprow;
while (i != 0 && lback(lp) != curbp->b_linep) {
--i;
lp = lback(lp);
}
curwp->w_toprow = 0;
curwp->w_ntrows = term.t_nrow - 1;
curwp->w_linep = lp;
curwp->w_flag |= WFMODE | WFHARD;
return (TRUE);
}
/*
@ -239,9 +233,9 @@ onlywind(f, n)
* 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 */
@ -251,7 +245,7 @@ int f, n; /* arguments are ignored for this command */
/* if there is only one window, don't delete it */
if (wheadp->w_wndp == NULL) {
mlwrite("Can not delete this window");
return(FALSE);
return (FALSE);
}
/* find window before curwp in linked list */
@ -275,7 +269,7 @@ int f, n; /* arguments are ignored for this command */
wp = wp->w_wndp;
}
if (wp == NULL)
return(FALSE);
return (FALSE);
wp->w_toprow = 0;
wp->w_ntrows += target;
} else {
@ -287,7 +281,7 @@ int f, n; /* arguments are ignored for this command */
wp = wp->w_wndp;
}
if (wp == NULL)
return(FALSE);
return (FALSE);
wp->w_ntrows += 1 + curwp->w_ntrows;
}
@ -302,13 +296,13 @@ int f, n; /* arguments are ignored for this command */
wheadp = curwp->w_wndp;
else
lwp->w_wndp = curwp->w_wndp;
free((char *)curwp);
free((char *) curwp);
curwp = wp;
wp->w_flag |= WFHARD;
curbp = wp->w_bufp;
cknewwindow();
cknewwindow();
upmode();
return(TRUE);
return (TRUE);
}
/*
@ -322,82 +316,82 @@ for the new window. Bound to "C-X 2".
*/
splitwind(f, n)
int f, n; /* default flag and numeric argument */
int f, n; /* default flag and numeric argument */
{
register WINDOW *wp;
register LINE *lp;
register int ntru;
register int ntrl;
register int ntrd;
register WINDOW *wp1;
register WINDOW *wp2;
register WINDOW *wp;
register LINE *lp;
register int ntru;
register int ntrl;
register int ntrd;
register WINDOW *wp1;
register WINDOW *wp2;
char *malloc();
if (curwp->w_ntrows < 3) {
mlwrite("Cannot split a %d line window", curwp->w_ntrows);
return (FALSE);
}
if ((wp = (WINDOW *) malloc(sizeof(WINDOW))) == NULL) {
mlwrite("(OUT OF MEMORY)");
return (FALSE);
}
++curbp->b_nwnd; /* Displayed twice. */
wp->w_bufp = curbp;
wp->w_dotp = curwp->w_dotp;
wp->w_doto = curwp->w_doto;
wp->w_markp = curwp->w_markp;
wp->w_marko = curwp->w_marko;
wp->w_flag = 0;
wp->w_force = 0;
if (curwp->w_ntrows < 3) {
mlwrite("Cannot split a %d line window", curwp->w_ntrows);
return (FALSE);
}
if ((wp = (WINDOW *) malloc(sizeof(WINDOW))) == NULL) {
mlwrite("(OUT OF MEMORY)");
return (FALSE);
}
++curbp->b_nwnd; /* Displayed twice. */
wp->w_bufp = curbp;
wp->w_dotp = curwp->w_dotp;
wp->w_doto = curwp->w_doto;
wp->w_markp = curwp->w_markp;
wp->w_marko = curwp->w_marko;
wp->w_flag = 0;
wp->w_force = 0;
#if COLOR
/* set the colors of the new window */
wp->w_fcolor = gfcolor;
wp->w_bcolor = gbcolor;
#endif
ntru = (curwp->w_ntrows-1) / 2; /* Upper size */
ntrl = (curwp->w_ntrows-1) - ntru; /* Lower size */
lp = curwp->w_linep;
ntrd = 0;
while (lp != curwp->w_dotp) {
++ntrd;
lp = lforw(lp);
}
lp = curwp->w_linep;
if (((f == FALSE) && (ntrd <= ntru)) || ((f == TRUE) && (n == 1))) {
/* Old is upper window. */
if (ntrd == ntru) /* Hit mode line. */
lp = lforw(lp);
curwp->w_ntrows = ntru;
wp->w_wndp = curwp->w_wndp;
curwp->w_wndp = wp;
wp->w_toprow = curwp->w_toprow+ntru+1;
wp->w_ntrows = ntrl;
} else { /* Old is lower window */
wp1 = NULL;
wp2 = wheadp;
while (wp2 != curwp) {
wp1 = wp2;
wp2 = wp2->w_wndp;
}
if (wp1 == NULL)
wheadp = wp;
else
wp1->w_wndp = wp;
wp->w_wndp = curwp;
wp->w_toprow = curwp->w_toprow;
wp->w_ntrows = ntru;
++ntru; /* Mode line. */
curwp->w_toprow += ntru;
curwp->w_ntrows = ntrl;
while (ntru--)
lp = lforw(lp);
}
curwp->w_linep = lp; /* Adjust the top lines */
wp->w_linep = lp; /* if necessary. */
curwp->w_flag |= WFMODE|WFHARD;
wp->w_flag |= WFMODE|WFHARD;
return (TRUE);
ntru = (curwp->w_ntrows - 1) / 2; /* Upper size */
ntrl = (curwp->w_ntrows - 1) - ntru; /* Lower size */
lp = curwp->w_linep;
ntrd = 0;
while (lp != curwp->w_dotp) {
++ntrd;
lp = lforw(lp);
}
lp = curwp->w_linep;
if (((f == FALSE) && (ntrd <= ntru)) || ((f == TRUE) && (n == 1))) {
/* Old is upper window. */
if (ntrd == ntru) /* Hit mode line. */
lp = lforw(lp);
curwp->w_ntrows = ntru;
wp->w_wndp = curwp->w_wndp;
curwp->w_wndp = wp;
wp->w_toprow = curwp->w_toprow + ntru + 1;
wp->w_ntrows = ntrl;
} else { /* Old is lower window */
wp1 = NULL;
wp2 = wheadp;
while (wp2 != curwp) {
wp1 = wp2;
wp2 = wp2->w_wndp;
}
if (wp1 == NULL)
wheadp = wp;
else
wp1->w_wndp = wp;
wp->w_wndp = curwp;
wp->w_toprow = curwp->w_toprow;
wp->w_ntrows = ntru;
++ntru; /* Mode line. */
curwp->w_toprow += ntru;
curwp->w_ntrows = ntrl;
while (ntru--)
lp = lforw(lp);
}
curwp->w_linep = lp; /* Adjust the top lines */
wp->w_linep = lp; /* if necessary. */
curwp->w_flag |= WFMODE | WFHARD;
wp->w_flag |= WFMODE | WFHARD;
return (TRUE);
}
/*
@ -408,48 +402,48 @@ int f, n; /* default flag and numeric argument */
*/
enlargewind(f, n)
{
register WINDOW *adjwp;
register LINE *lp;
register int i;
register WINDOW *adjwp;
register LINE *lp;
register int i;
if (n < 0)
return (shrinkwind(f, -n));
if (wheadp->w_wndp == NULL) {
mlwrite("Only one window");
return (FALSE);
}
if ((adjwp=curwp->w_wndp) == NULL) {
adjwp = wheadp;
while (adjwp->w_wndp != curwp)
adjwp = adjwp->w_wndp;
}
if (adjwp->w_ntrows <= n) {
mlwrite("Impossible change");
return (FALSE);
}
if (curwp->w_wndp == adjwp) { /* Shrink below. */
lp = adjwp->w_linep;
for (i=0; i<n && lp!=adjwp->w_bufp->b_linep; ++i)
lp = lforw(lp);
adjwp->w_linep = lp;
adjwp->w_toprow += n;
} else { /* Shrink above. */
lp = curwp->w_linep;
for (i=0; i<n && lback(lp)!=curbp->b_linep; ++i)
lp = lback(lp);
curwp->w_linep = lp;
curwp->w_toprow -= n;
}
curwp->w_ntrows += n;
adjwp->w_ntrows -= n;
if (n < 0)
return (shrinkwind(f, -n));
if (wheadp->w_wndp == NULL) {
mlwrite("Only one window");
return (FALSE);
}
if ((adjwp = curwp->w_wndp) == NULL) {
adjwp = wheadp;
while (adjwp->w_wndp != curwp)
adjwp = adjwp->w_wndp;
}
if (adjwp->w_ntrows <= n) {
mlwrite("Impossible change");
return (FALSE);
}
if (curwp->w_wndp == adjwp) { /* Shrink below. */
lp = adjwp->w_linep;
for (i = 0; i < n && lp != adjwp->w_bufp->b_linep; ++i)
lp = lforw(lp);
adjwp->w_linep = lp;
adjwp->w_toprow += n;
} else { /* Shrink above. */
lp = curwp->w_linep;
for (i = 0; i < n && lback(lp) != curbp->b_linep; ++i)
lp = lback(lp);
curwp->w_linep = lp;
curwp->w_toprow -= n;
}
curwp->w_ntrows += n;
adjwp->w_ntrows -= n;
#if SCROLLCODE
curwp->w_flag |= WFMODE|WFHARD|WFINS;
adjwp->w_flag |= WFMODE|WFHARD|WFKILLS;
curwp->w_flag |= WFMODE | WFHARD | WFINS;
adjwp->w_flag |= WFMODE | WFHARD | WFKILLS;
#else
curwp->w_flag |= WFMODE|WFHARD;
adjwp->w_flag |= WFMODE|WFHARD;
curwp->w_flag |= WFMODE | WFHARD;
adjwp->w_flag |= WFMODE | WFHARD;
#endif
return (TRUE);
return (TRUE);
}
/*
@ -459,71 +453,72 @@ enlargewind(f, n)
*/
shrinkwind(f, n)
{
register WINDOW *adjwp;
register LINE *lp;
register int i;
register WINDOW *adjwp;
register LINE *lp;
register int i;
if (n < 0)
return (enlargewind(f, -n));
if (wheadp->w_wndp == NULL) {
mlwrite("Only one window");
return (FALSE);
}
if ((adjwp=curwp->w_wndp) == NULL) {
adjwp = wheadp;
while (adjwp->w_wndp != curwp)
adjwp = adjwp->w_wndp;
}
if (curwp->w_ntrows <= n) {
mlwrite("Impossible change");
return (FALSE);
}
if (curwp->w_wndp == adjwp) { /* Grow below. */
lp = adjwp->w_linep;
for (i=0; i<n && lback(lp)!=adjwp->w_bufp->b_linep; ++i)
lp = lback(lp);
adjwp->w_linep = lp;
adjwp->w_toprow -= n;
} else { /* Grow above. */
lp = curwp->w_linep;
for (i=0; i<n && lp!=curbp->b_linep; ++i)
lp = lforw(lp);
curwp->w_linep = lp;
curwp->w_toprow += n;
}
curwp->w_ntrows -= n;
adjwp->w_ntrows += n;
if (n < 0)
return (enlargewind(f, -n));
if (wheadp->w_wndp == NULL) {
mlwrite("Only one window");
return (FALSE);
}
if ((adjwp = curwp->w_wndp) == NULL) {
adjwp = wheadp;
while (adjwp->w_wndp != curwp)
adjwp = adjwp->w_wndp;
}
if (curwp->w_ntrows <= n) {
mlwrite("Impossible change");
return (FALSE);
}
if (curwp->w_wndp == adjwp) { /* Grow below. */
lp = adjwp->w_linep;
for (i = 0; i < n && lback(lp) != adjwp->w_bufp->b_linep;
++i)
lp = lback(lp);
adjwp->w_linep = lp;
adjwp->w_toprow -= n;
} else { /* Grow above. */
lp = curwp->w_linep;
for (i = 0; i < n && lp != curbp->b_linep; ++i)
lp = lforw(lp);
curwp->w_linep = lp;
curwp->w_toprow += n;
}
curwp->w_ntrows -= n;
adjwp->w_ntrows += n;
#if SCROLLCODE
curwp->w_flag |= WFMODE|WFHARD|WFKILLS;
adjwp->w_flag |= WFMODE|WFHARD|WFINS;
curwp->w_flag |= WFMODE | WFHARD | WFKILLS;
adjwp->w_flag |= WFMODE | WFHARD | WFINS;
#else
curwp->w_flag |= WFMODE|WFHARD;
adjwp->w_flag |= WFMODE|WFHARD;
curwp->w_flag |= WFMODE | WFHARD;
adjwp->w_flag |= WFMODE | WFHARD;
#endif
return (TRUE);
return (TRUE);
}
/* Resize the current window to the requested size */
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 */
if (f == FALSE)
return(TRUE);
return (TRUE);
/* find out what to do */
clines = curwp->w_ntrows;
/* already the right size? */
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
* might be better. Return a pointer, or NULL on error.
*/
WINDOW *
wpopup()
WINDOW *wpopup()
{
register WINDOW *wp;
register WINDOW *wp;
if (wheadp->w_wndp == NULL /* Only 1 window */
&& splitwind(FALSE, 0) == FALSE) /* and it won't split */
return (NULL);
wp = wheadp; /* Find window to use */
while (wp!=NULL && wp==curwp)
wp = wp->w_wndp;
return (wp);
if (wheadp->w_wndp == NULL /* Only 1 window */
&& splitwind(FALSE, 0) == FALSE) /* and it won't split */
return (NULL);
wp = wheadp; /* Find window to use */
while (wp != NULL && wp == curwp)
wp = wp->w_wndp;
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);
backpage(f, n);
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);
forwpage(f, n);
prevwind(FALSE, 1);
}
savewnd(f, n) /* save ptr to current window */
{
savewnd(f, n)
{ /* save ptr to current window */
swindow = curwp;
return(TRUE);
return (TRUE);
}
restwnd(f, n) /* restore the saved screen */
{
restwnd(f, n)
{ /* restore the saved screen */
register WINDOW *wp;
/* find the window */
@ -586,19 +576,19 @@ restwnd(f, n) /* restore the saved screen */
}
mlwrite("(No such window exists)");
return(FALSE);
return (FALSE);
}
newsize(f, n) /* resize the screen, re-writing the screen */
int f; /* default flag */
int n; /* numeric argument */
newsize(f, n)
/* resize the screen, re-writing the screen */
int f; /* default flag */
int n; /* numeric argument */
{
WINDOW *wp; /* current window being examined */
WINDOW *nextwp; /* next window to scan */
WINDOW *lastwp; /* last window scanned */
int lastline; /* screen line of last line of current window */
WINDOW *wp; /* current window being examined */
WINDOW *nextwp; /* next window to scan */
WINDOW *lastwp; /* last window scanned */
int lastline; /* screen line of last line of current window */
/* if the command defaults, assume the largest */
if (f == FALSE)
@ -607,11 +597,11 @@ int n; /* numeric argument */
/* make sure it's in range */
if (n < 3 || n > term.t_mrow + 1) {
mlwrite("%%Screen size out of range");
return(FALSE);
return (FALSE);
}
if (term.t_nrow == n - 1)
return(TRUE);
return (TRUE);
else if (term.t_nrow < n - 1) {
/* go to the last window */
@ -621,7 +611,7 @@ int n; /* numeric argument */
/* and enlarge it as needed */
wp->w_ntrows = n - wp->w_toprow - 2;
wp->w_flag |= WFHARD|WFMODE;
wp->w_flag |= WFHARD | WFMODE;
} else {
@ -632,7 +622,7 @@ int n; /* numeric argument */
while (nextwp != NULL) {
wp = nextwp;
nextwp = wp->w_wndp;
/* get rid of it if it is too low */
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_marko = wp->w_marko;
}
/* update curwp and lastwp if needed */
if (wp == curwp)
curwp = wheadp;
curbp = curwp->w_bufp;
curbp = curwp->w_bufp;
if (lastwp != NULL)
lastwp->w_wndp = NULL;
/* free the structure */
free((char *)wp);
free((char *) wp);
wp = NULL;
} else {
/* need to change this window size? */
lastline = wp->w_toprow + wp->w_ntrows - 1;
if (lastline >= n - 2) {
wp->w_ntrows = n - wp->w_toprow - 2;
wp->w_flag |= WFHARD|WFMODE;
wp->w_ntrows =
n - wp->w_toprow - 2;
wp->w_flag |= WFHARD | WFMODE;
}
}
@ -671,13 +662,13 @@ int n; /* numeric argument */
/* screen is garbage */
term.t_nrow = n - 1;
sgarbf = TRUE;
return(TRUE);
return (TRUE);
}
newwidth(f, n) /* resize the screen, re-writing the screen */
int f; /* default flag */
int n; /* numeric argument */
newwidth(f, n)
/* resize the screen, re-writing the screen */
int f; /* default flag */
int n; /* numeric argument */
{
register WINDOW *wp;
@ -689,7 +680,7 @@ int n; /* numeric argument */
/* make sure it's in range */
if (n < 10 || n > term.t_mcol) {
mlwrite("%%Screen width out of range");
return(FALSE);
return (FALSE);
}
/* otherwise, just re-width it (no big deal) */
@ -705,12 +696,11 @@ int n; /* numeric argument */
}
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 LINE *lp; /* scannile line pointer */
@ -723,11 +713,10 @@ int getwpos() /* get screen offset of current line in current window */
}
/* and return the value */
return(sline);
return (sline);
}
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)
int f; /* default flag */
int n; /* numeric argument */
int f; /* default flag */
int n; /* numeric argument */
{
register int cnt; /* size of word wrapped to next line */
register int c; /* charector temporary */
/* backup from the <NL> 1 char */
if (!backchar(0, 1))
return(FALSE);
return (FALSE);
/* back up until we aren't in a word,
make sure there is a break in the line */
cnt = 0;
while (((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' ')
&& (c != '\t')) {
&& (c != '\t')) {
cnt++;
if (!backchar(0, 1))
return(FALSE);
return (FALSE);
/* if we make it to the beginning, start a new line */
if (curwp->w_doto == 0) {
gotoeol(FALSE, 0);
return(lnewline());
return (lnewline());
}
}
/* delete the forward white space */
if (!forwdel(0, 1))
return(FALSE);
return (FALSE);
/* put in a end of line */
if (!lnewline())
return(FALSE);
return (FALSE);
/* and past the first word */
while (cnt-- > 0) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
return (FALSE);
}
return(TRUE);
return (TRUE);
}
/*
@ -105,7 +105,7 @@ forwword(f, n)
return (FALSE);
}
}
return(TRUE);
return (TRUE);
}
/*
@ -115,10 +115,10 @@ forwword(f, n)
*/
upperword(f, n)
{
register int c;
register int c;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return (rdonly()); /* we are in read only mode */
if (n < 0)
return (FALSE);
while (n--) {
@ -131,9 +131,9 @@ upperword(f, n)
#if PKCODE
if (islower(c)) {
#else
if (c>='a' && c<='z') {
if (c >= 'a' && c <= 'z') {
#endif
c -= 'a'-'A';
c -= 'a' - 'A';
lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD);
}
@ -151,10 +151,10 @@ upperword(f, n)
*/
lowerword(f, n)
{
register int c;
register int c;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return (rdonly()); /* we are in read only mode */
if (n < 0)
return (FALSE);
while (n--) {
@ -167,9 +167,9 @@ lowerword(f, n)
#if PKCODE
if (isupper(c)) {
#else
if (c>='A' && c<='Z') {
if (c >= 'A' && c <= 'Z') {
#endif
c += 'a'-'A';
c += 'a' - 'A';
lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD);
}
@ -188,10 +188,10 @@ lowerword(f, n)
*/
capword(f, n)
{
register int c;
register int c;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return (rdonly()); /* we are in read only mode */
if (n < 0)
return (FALSE);
while (n--) {
@ -204,9 +204,9 @@ capword(f, n)
#if PKCODE
if (islower(c)) {
#else
if (c>='a' && c<='z') {
if (c >= 'a' && c <= 'z') {
#endif
c -= 'a'-'A';
c -= 'a' - 'A';
lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD);
}
@ -217,10 +217,11 @@ capword(f, n)
#if PKCODE
if (isupper(c)) {
#else
if (c>='A' && c<='Z') {
if (c >= 'A' && c <= 'Z') {
#endif
c += 'a'-'A';
lputc(curwp->w_dotp, curwp->w_doto, c);
c += 'a' - 'A';
lputc(curwp->w_dotp, curwp->w_doto,
c);
lchange(WFHARD);
}
if (forwchar(FALSE, 1) == FALSE)
@ -239,21 +240,21 @@ capword(f, n)
*/
delfword(f, n)
{
register LINE *dotp; /* original cursor line */
register int doto; /* and row */
register LINE *dotp; /* original cursor line */
register int doto; /* and row */
register int c; /* temp char */
long size; /* # of chars to delete */
/* don't allow this command if we are in read only mode */
if (curbp->b_mode&MDVIEW)
return(rdonly());
if (curbp->b_mode & MDVIEW)
return (rdonly());
/* ignore the command if there is a negative argument */
if (n < 0)
return (FALSE);
/* Clear the kill buffer if last command wasn't a kill */
if ((lastflag&CFKILL) == 0)
if ((lastflag & CFKILL) == 0)
kdelete();
thisflag |= CFKILL; /* this command is a kill */
@ -267,7 +268,7 @@ delfword(f, n)
/* get us into a word.... */
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
return (FALSE);
++size;
}
@ -275,43 +276,43 @@ delfword(f, n)
/* skip one word, no whitespace! */
while (inword() == TRUE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
return (FALSE);
++size;
}
} else {
/* skip n words.... */
while (n--) {
/* if we are at EOL; skip to the beginning of the next */
while (curwp->w_doto == llength(curwp->w_dotp)) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
return (FALSE);
++size;
}
/* move forward till we are at the end of the word */
while (inword() == TRUE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
return (FALSE);
++size;
}
/* if there are more words, skip the interword stuff */
if (n != 0)
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
return (FALSE);
++size;
}
}
/* skip whitespace and newlines */
while ((curwp->w_doto == llength(curwp->w_dotp)) ||
((c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' ') ||
(c == '\t')) {
if (forwchar(FALSE, 1) == FALSE)
break;
++size;
((c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' ')
|| (c == '\t')) {
if (forwchar(FALSE, 1) == FALSE)
break;
++size;
}
}
@ -331,15 +332,15 @@ delbword(f, n)
long size;
/* don't allow this command if we are in read only mode */
if (curbp->b_mode&MDVIEW)
return(rdonly());
if (curbp->b_mode & MDVIEW)
return (rdonly());
/* ignore the command if there is a nonpositive argument */
if (n <= 0)
return (FALSE);
/* Clear the kill buffer if last command wasn't a kill */
if ((lastflag&CFKILL) == 0)
if ((lastflag & CFKILL) == 0)
kdelete();
thisflag |= CFKILL; /* this command is a kill */
@ -360,7 +361,7 @@ delbword(f, n)
}
if (forwchar(FALSE, 1) == FALSE)
return (FALSE);
bckdel: return (ldelete(size, TRUE));
bckdel:return (ldelete(size, TRUE));
}
/*
@ -369,7 +370,7 @@ bckdel: return (ldelete(size, TRUE));
*/
inword()
{
register int c;
register int c;
if (curwp->w_doto == llength(curwp->w_dotp))
return (FALSE);
@ -377,39 +378,39 @@ inword()
#if PKCODE
if (isletter(c))
#else
if (c>='a' && c<='z')
if (c >= 'a' && c <= 'z')
return (TRUE);
if (c>='A' && c<='Z')
if (c >= 'A' && c <= 'Z')
#endif
return (TRUE);
if (c>='0' && c<='9')
if (c >= '0' && c <= '9')
return (TRUE);
return (FALSE);
}
#if WORDPRO
fillpara(f, n) /* Fill the current paragraph according to the current
fill column */
int f, n; /* deFault flag and Numeric argument */
fillpara(f, n)
/* Fill the current paragraph according to the current
fill column */
int f, n; /* deFault flag and Numeric argument */
{
register int c; /* current char durring scan */
register int wordlen; /* length of current word */
register int clength; /* position on line during fill */
register int i; /* index during word copy */
register int newlength; /* tentative new line length */
register int eopflag; /* Are we at the End-Of-Paragraph? */
register int firstflag; /* first word? (needs no space) */
register LINE *eopline; /* pointer to line just past EOP */
register int dotflag; /* was the last char a period? */
char wbuf[NSTRING]; /* buffer for current word */
register int c; /* current char durring scan */
register int wordlen; /* length of current word */
register int clength; /* position on line during fill */
register int i; /* index during word copy */
register int newlength; /* tentative new line length */
register int eopflag; /* Are we at the End-Of-Paragraph? */
register int firstflag; /* first word? (needs no space) */
register LINE *eopline; /* pointer to line just past EOP */
register int dotflag; /* was the last char a period? */
char wbuf[NSTRING]; /* buffer for current word */
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return (rdonly()); /* we are in read only mode */
if (fillcol == 0) { /* no fill column set */
mlwrite("No fill column set");
return(FALSE);
return (FALSE);
}
#if PKCODE
justflag = FALSE;
@ -446,7 +447,7 @@ int f, n; /* deFault flag and Numeric argument */
/* if not a separator, just add it in */
if (c != ' ' && c != '\t') {
dotflag = (c == '.'); /* was it a dot */
dotflag = (c == '.'); /* was it a dot */
if (wordlen < NSTRING - 1)
wbuf[wordlen++] = c;
} else if (wordlen) {
@ -456,7 +457,7 @@ int f, n; /* deFault flag and Numeric argument */
if (newlength <= fillcol) {
/* add word to current line */
if (!firstflag) {
linsert(1, ' '); /* the space */
linsert(1, ' '); /* the space */
++clength;
}
firstflag = FALSE;
@ -467,7 +468,7 @@ int f, n; /* deFault flag and Numeric argument */
}
/* and add the word in in either case */
for (i=0; i<wordlen; i++) {
for (i = 0; i < wordlen; i++) {
linsert(1, wbuf[i]);
++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 */
lnewline();
return(TRUE);
return (TRUE);
}
#if PKCODE
justpara(f, n) /* Fill the current paragraph according to the current
fill column and cursor position */
int f, n; /* deFault flag and Numeric argument */
justpara(f, n)
/* Fill the current paragraph according to the current
fill column and cursor position */
int f, n; /* deFault flag and Numeric argument */
{
register int c; /* current char durring scan */
register int wordlen; /* length of current word */
register int clength; /* position on line during fill */
register int i; /* index during word copy */
register int newlength; /* tentative new line length */
register int eopflag; /* Are we at the End-Of-Paragraph? */
register int firstflag; /* first word? (needs no space) */
register LINE *eopline; /* pointer to line just past EOP */
char wbuf[NSTRING]; /* buffer for current word */
int leftmarg; /* left marginal */
register int c; /* current char durring scan */
register int wordlen; /* length of current word */
register int clength; /* position on line during fill */
register int i; /* index during word copy */
register int newlength; /* tentative new line length */
register int eopflag; /* Are we at the End-Of-Paragraph? */
register int firstflag; /* first word? (needs no space) */
register LINE *eopline; /* pointer to line just past EOP */
char wbuf[NSTRING]; /* buffer for current word */
int leftmarg; /* left marginal */
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return (rdonly()); /* we are in read only mode */
if (fillcol == 0) { /* no fill column set */
mlwrite("No fill column set");
return(FALSE);
return (FALSE);
}
justflag = TRUE;
leftmarg = curwp->w_doto;
if (leftmarg+10 > fillcol) {
if (leftmarg + 10 > fillcol) {
leftmarg = 0;
mlwrite("Column too narrow");
return(FALSE);
}
return (FALSE);
}
/* record the pointer to the line just past the EOP */
gotoeop(FALSE, 1);
@ -558,20 +559,20 @@ int f, n; /* deFault flag and Numeric argument */
if (newlength <= fillcol) {
/* add word to current line */
if (!firstflag) {
linsert(1, ' '); /* the space */
linsert(1, ' '); /* the space */
++clength;
}
firstflag = FALSE;
} else {
/* start a new line */
lnewline();
for (i=0; i<leftmarg; i++)
for (i = 0; i < leftmarg; i++)
linsert(1, ' ');
clength = leftmarg;
}
/* and add the word in in either case */
for (i=0; i<wordlen; i++) {
for (i = 0; i < wordlen; i++) {
linsert(1, wbuf[i]);
++clength;
}
@ -588,14 +589,14 @@ int f, n; /* deFault flag and Numeric argument */
curwp->w_doto = llength(curwp->w_dotp);
justflag = FALSE;
return(TRUE);
return (TRUE);
}
#endif
killpara(f, n) /* delete n paragraphs starting with the current one */
int f; /* default flag */
int n; /* # of paras to delete */
killpara(f, n)
/* delete n paragraphs starting with the current one */
int f; /* default flag */
int n; /* # of paras to delete */
{
register int status; /* returned status of functions */
@ -612,15 +613,15 @@ int n; /* # of paras to delete */
/* go to the beginning of the paragraph */
gotobop(FALSE, 1);
curwp->w_doto = 0; /* force us to the beginning of line */
/* and delete it */
if ((status = killregion(FALSE, 1)) != TRUE)
return(status);
return (status);
/* and clean up the 2 extra lines */
ldelete(2L, TRUE);
}
return(TRUE);
return (TRUE);
}
@ -630,7 +631,7 @@ int n; /* # of paras to delete */
wordcount(f, n)
int f, n; /* ignored numeric arguments */
int f, n; /* ignored numeric arguments */
{
register LINE *lp; /* current line to scan */
@ -648,16 +649,16 @@ int f, n; /* ignored numeric arguments */
#if PKCODE
struct {
long pk_1;
long pk_2;
int pk_3;
int pk_4;
long pk_1;
long pk_2;
int pk_3;
int pk_4;
} pk_mlrec;
#endif
/* make sure we have a region to count */
if ((status = getregion(&region)) != TRUE)
return(status);
return (status);
lp = region.r_linep;
offset = region.r_offset;
size = region.r_size;
@ -683,12 +684,12 @@ int f, n; /* ignored numeric arguments */
/* and tabulate it */
wordflag = (
#if PKCODE
(isletter(ch)) ||
(isletter(ch)) ||
#else
(ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
(ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
#endif
(ch >= '0' && ch <= '9'));
(ch >= '0' && ch <= '9'));
if (wordflag == TRUE && lastword == FALSE)
++nwords;
lastword = wordflag;
@ -697,7 +698,7 @@ int f, n; /* ignored numeric arguments */
/* and report on the info */
if (nwords > 0L)
avgch = (int)((100L * nchars) / nwords);
avgch = (int) ((100L * nchars) / nwords);
else
avgch = 0;
@ -706,12 +707,12 @@ int f, n; /* ignored numeric arguments */
pk_mlrec.pk_2 = nchars;
pk_mlrec.pk_3 = nlines + 1;
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);
#else
mlwrite("Words %D Chars %D Lines %d Avg chars/word %f",
nwords, nchars, nlines + 1, avgch);
#endif
return(TRUE);
return (TRUE);
}
#endif