summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mg/Makefile3
-rw-r--r--usr.bin/mg/basic.c2
-rw-r--r--usr.bin/mg/buffer.c22
-rw-r--r--usr.bin/mg/def.h14
-rw-r--r--usr.bin/mg/dir.c7
-rw-r--r--usr.bin/mg/dired.c4
-rw-r--r--usr.bin/mg/display.c28
-rw-r--r--usr.bin/mg/file.c8
-rw-r--r--usr.bin/mg/line.c12
-rw-r--r--usr.bin/mg/main.c8
-rw-r--r--usr.bin/mg/sysdef.h2
-rw-r--r--usr.bin/mg/tty.c388
-rw-r--r--usr.bin/mg/ttyio.c53
-rw-r--r--usr.bin/mg/ttykbd.c82
-rw-r--r--usr.bin/mg/window.c28
15 files changed, 323 insertions, 338 deletions
diff --git a/usr.bin/mg/Makefile b/usr.bin/mg/Makefile
index 7bfc53659b9..17a81285ee4 100644
--- a/usr.bin/mg/Makefile
+++ b/usr.bin/mg/Makefile
@@ -9,6 +9,7 @@ DPADD+= ${LIBCURSES}
#
# DO_METAKEY -- if bit 7 is set for a key, treat like a META key
# STARTUP -- look for and handle initialization file
+# FKEYS -- add support for function key sequences.
# XKEYS -- use termcap function key definitions. Warning -
# XKEYS and bsmap mode do _not_ get along.
# BACKUP -- enable "make-backup-files"
@@ -16,7 +17,7 @@ DPADD+= ${LIBCURSES}
# REGEX -- create regular expression functions
#
CDEFS = -DDO_METAKEY
-CDEFS+= -DDO_METAKEY -DPREFIXREGION -DXKEYS -DBACKUP
+CDEFS+= -DDO_METAKEY -DPREFIXREGION -DXKEYS -DFKEYS -DBACKUP
CFLAGS+=$(CDEFS)
SRCS= cinfo.c fileio.c spawn.c ttyio.c tty.c ttykbd.c \
diff --git a/usr.bin/mg/basic.c b/usr.bin/mg/basic.c
index b35e1defeef..c4095800c0d 100644
--- a/usr.bin/mg/basic.c
+++ b/usr.bin/mg/basic.c
@@ -338,7 +338,7 @@ int f, n;
*/
pagenext(f, n)
{
- register WINDOW *wp;
+ register MGWIN *wp;
if (wheadp->w_wndp == NULL) {
ewprintf("No other window");
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c
index b4244086bf7..6f0f920fee2 100644
--- a/usr.bin/mg/buffer.c
+++ b/usr.bin/mg/buffer.c
@@ -43,10 +43,10 @@ usebuffer(f, n)
poptobuffer(f, n)
{
register BUFFER *bp;
- register WINDOW *wp;
+ register MGWIN *wp;
register int s;
char bufn[NBUFN];
- WINDOW *popbuf();
+ MGWIN *popbuf();
/* Get buffer to use from user */
if ((curbp->b_altb == NULL)
@@ -80,7 +80,7 @@ killbuffer(f, n)
register BUFFER *bp;
register BUFFER *bp1;
register BUFFER *bp2;
- WINDOW *wp;
+ MGWIN *wp;
register int s;
char bufn[NBUFN];
@@ -160,9 +160,9 @@ savebuffers(f, n)
listbuffers(f, n)
{
register BUFFER *bp;
- register WINDOW *wp;
+ register MGWIN *wp;
BUFFER *makelist();
- WINDOW *popbuf();
+ MGWIN *popbuf();
if ((bp=makelist()) == NULL || (wp=popbuf(bp)) == NULL)
return FALSE;
@@ -423,9 +423,9 @@ bclear(bp) register BUFFER *bp; {
* Display the given buffer in the given window. Flags indicated
* action on redisplay.
*/
-showbuffer(bp, wp, flags) register BUFFER *bp; register WINDOW *wp; {
+showbuffer(bp, wp, flags) register BUFFER *bp; register MGWIN *wp; {
register BUFFER *obp;
- WINDOW *owp;
+ MGWIN *owp;
if (wp->w_bufp == bp) { /* Easy case! */
wp->w_flag |= flags;
@@ -468,9 +468,9 @@ showbuffer(bp, wp, flags) register BUFFER *bp; register WINDOW *wp; {
* Pop the buffer we got passed onto the screen.
* Returns a status.
*/
-WINDOW *
+MGWIN *
popbuf(bp) register BUFFER *bp; {
- register WINDOW *wp;
+ register MGWIN *wp;
if (bp->b_nwnd == 0) { /* Not on screen yet. */
if ((wp=wpopup()) == NULL) return NULL;
@@ -545,7 +545,7 @@ bufferinsert(f, n)
/*ARGSUSED*/
notmodified(f, n)
{
- register WINDOW *wp;
+ register MGWIN *wp;
curbp->b_flag &= ~BFCHG;
wp = wheadp; /* Update mode lines. */
@@ -567,7 +567,7 @@ notmodified(f, n)
popbuftop(bp)
register BUFFER *bp;
{
- register WINDOW *wp;
+ register MGWIN *wp;
bp->b_dotp = lforw(bp->b_linep);
bp->b_doto = 0;
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 5fc2cbedc03..bf8acb24b8b 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -170,7 +170,7 @@ typedef struct LINE {
*/
typedef struct LIST {
union {
- struct WINDOW *l_wp;
+ struct MGWIN *l_wp;
struct BUFFER *x_bp; /* l_bp is used by LINE */
struct LIST *l_nxt;
} l_p;
@@ -192,7 +192,7 @@ typedef struct LIST {
* terms of decoupling, the full blown redisplay is just too
* expensive to run for every input character.
*/
-typedef struct WINDOW {
+typedef struct MGWIN {
LIST w_list; /* List header */
struct BUFFER *w_bufp; /* Buffer displayed in window */
struct LINE *w_linep; /* Top line in the window */
@@ -204,7 +204,7 @@ typedef struct WINDOW {
char w_ntrows; /* # of rows of text in window */
char w_force; /* If NZ, forcing row. */
char w_flag; /* Flags. */
-} WINDOW;
+} MGWIN;
#define w_wndp w_list.l_p.l_wp
#define w_name w_list.l_name
@@ -279,14 +279,14 @@ extern int curgoal;
extern int epresf;
extern int sgarbf;
extern int mode;
-extern WINDOW *curwp;
+extern MGWIN *curwp;
extern BUFFER *curbp;
-extern WINDOW *wheadp;
+extern MGWIN *wheadp;
extern BUFFER *bheadp;
extern char pat[];
extern BUFFER *bfind();
-extern WINDOW *popbuf();
-extern WINDOW *wpopup();
+extern MGWIN *popbuf();
+extern MGWIN *wpopup();
extern LINE *lalloc();
extern LINE *lallocx();
extern VOID ewprintf();
diff --git a/usr.bin/mg/dir.c b/usr.bin/mg/dir.c
index b8f40f973ee..d96e6552473 100644
--- a/usr.bin/mg/dir.c
+++ b/usr.bin/mg/dir.c
@@ -8,9 +8,6 @@
#include "def.h"
#ifndef NO_DIR
-#ifndef getwd /* may be a #define */
-char *getwd();
-#endif
char *wdir;
static char cwd[NFILEN];
@@ -19,7 +16,7 @@ static char cwd[NFILEN];
*/
dirinit()
{
- if (!(wdir = getwd(cwd)))
+ if (!(wdir = getcwd(cwd, sizeof(cwd))))
panic("Can't get current directory!");
}
@@ -40,7 +37,7 @@ changedir(f, n)
ewprintf("Can't change dir to %s", bufc);
return(FALSE);
} else {
- if (!(wdir = getwd(cwd)))
+ if (!(wdir = getcwd(cwd, sizeof(cwd))))
panic("Can't get current directory!");
ewprintf("Current directory is now %s", wdir);
return(TRUE);
diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c
index 2d3aedbbb4e..4c7ce9d3372 100644
--- a/usr.bin/mg/dired.c
+++ b/usr.bin/mg/dired.c
@@ -28,7 +28,7 @@ int f, n;
{
char dirname[NFILEN];
BUFFER *bp;
- WINDOW *wp;
+ MGWIN *wp;
dirname[0] = '\0';
if(eread("Dired other window: ", dirname, NFILEN, EFNEW | EFCR) == ABORT)
@@ -112,7 +112,7 @@ int f, n;
char fname[NFILEN];
register BUFFER *bp;
register int s;
- register WINDOW *wp;
+ register MGWIN *wp;
BUFFER *findbuffer();
if((s = d_makename(curwp->w_dotp, fname)) == ABORT) return FALSE;
diff --git a/usr.bin/mg/display.c b/usr.bin/mg/display.c
index 40fd1935a19..24341c28579 100644
--- a/usr.bin/mg/display.c
+++ b/usr.bin/mg/display.c
@@ -28,7 +28,7 @@
#endif
#ifdef STANDOUT_GLITCH
-extern int SG; /* number of standout glitches */
+#include <term.h>
#endif
/*
@@ -262,7 +262,7 @@ vteeol() {
VOID
update() {
register LINE *lp;
- register WINDOW *wp;
+ register MGWIN *wp;
register VIDEO *vp1;
VIDEO *vp2;
register int i;
@@ -547,16 +547,18 @@ VOID uline(row, vvp, pvp) VIDEO *vvp; VIDEO *pvp; {
if (vvp->v_color != pvp->v_color) { /* Wrong color, do a */
ttmove(row, 0); /* full redraw. */
#ifdef STANDOUT_GLITCH
- if (pvp->v_color != CTEXT && SG >= 0) tteeol();
+ if (pvp->v_color != CTEXT && magic_cookie_glitch >= 0)
+ tteeol();
#endif
ttcolor(vvp->v_color);
#ifdef STANDOUT_GLITCH
- cp1 = &vvp->v_text[SG > 0 ? SG : 0];
- /* the odd code for SG==0 is to avoid putting the invisable
+ cp1 = &vvp->v_text[magic_cookie_glitch > 0 ? magic_cookie_glitch : 0];
+ /* the odd code for magic_cookie_glitch==0
+ * is to avoid putting the invisable
* glitch character on the next line.
* (Hazeltine executive 80 model 30)
*/
- cp2 = &vvp->v_text[ncol - (SG >= 0 ? (SG!=0 ? SG : 1) : 0)];
+ cp2 = &vvp->v_text[ncol - (magic_cookie_glitch >= 0 ? (magic_cookie_glitch!=0 ? magic_cookie_glitch : 1) : 0)];
#else
cp1 = &vvp->v_text[0];
cp2 = &vvp->v_text[ncol];
@@ -598,10 +600,10 @@ VOID uline(row, vvp, pvp) VIDEO *vvp; VIDEO *pvp; {
/* Alcyon hack */
ttmove(row, (int)(cp1-&vvp->v_text[0]));
#ifdef STANDOUT_GLITCH
- if (vvp->v_color != CTEXT && SG > 0) {
- if(cp1 < &vvp->v_text[SG]) cp1 = &vvp->v_text[SG];
- if(cp5 > &vvp->v_text[ncol-SG]) cp5 = &vvp->v_text[ncol-SG];
- } else if (SG < 0)
+ if (vvp->v_color != CTEXT && magic_cookie_glitch > 0) {
+ if(cp1 < &vvp->v_text[magic_cookie_glitch]) cp1 = &vvp->v_text[magic_cookie_glitch];
+ if(cp5 > &vvp->v_text[ncol-magic_cookie_glitch]) cp5 = &vvp->v_text[ncol-magic_cookie_glitch];
+ } else if (magic_cookie_glitch < 0)
#endif
ttcolor(vvp->v_color);
while (cp1 != cp5) {
@@ -621,11 +623,11 @@ VOID uline(row, vvp, pvp) VIDEO *vvp; VIDEO *pvp; {
* change the modeline format by hacking at
* this routine. Called by "update" any time
* there is a dirty window.
- * Note that if STANDOUT_GLITCH is defined, first and last SG characters
- * may never be seen.
+ * Note that if STANDOUT_GLITCH is defined, first and last
+ * magic_cookie_glitch characters may never be seen.
*/
VOID
-modeline(wp) register WINDOW *wp; {
+modeline(wp) register MGWIN *wp; {
register int n;
register BUFFER *bp;
int mode;
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c
index f75aa6a7e3a..508b4727d25 100644
--- a/usr.bin/mg/file.c
+++ b/usr.bin/mg/file.c
@@ -59,7 +59,7 @@ filevisit(f, n)
poptofile(f, n)
{
register BUFFER *bp;
- register WINDOW *wp;
+ register MGWIN *wp;
int s;
char fname[NFILEN];
char *adjf;
@@ -126,7 +126,7 @@ unsigned num;
*/
readin(fname) char *fname; {
register int status;
- register WINDOW *wp;
+ register MGWIN *wp;
if (bclear(curbp) != TRUE) /* Might be old. */
return TRUE;
@@ -166,7 +166,7 @@ static int linesize = 0;
insertfile(fname, newname, needinfo) char fname[], newname[]; {
register LINE *lp1;
register LINE *lp2;
- register WINDOW *wp;
+ register MGWIN *wp;
int nbytes;
LINE *olp; /* Line we started at */
int opos; /* and offset into it */
@@ -475,7 +475,7 @@ writeout(bp, fn) register BUFFER *bp; char *fn; {
*/
VOID
upmodes(bp) register BUFFER *bp; {
- register WINDOW *wp;
+ register MGWIN *wp;
for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
if (bp == NULL || curwp->w_bufp == bp) wp->w_flag |= WFMODE;
diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c
index 3c892c706b1..c0cad9fbda1 100644
--- a/usr.bin/mg/line.c
+++ b/usr.bin/mg/line.c
@@ -96,7 +96,7 @@ int used;
VOID
lfree(lp) register LINE *lp; {
register BUFFER *bp;
- register WINDOW *wp;
+ register MGWIN *wp;
for(wp = wheadp; wp != NULL; wp = wp->w_wndp) {
if (wp->w_linep == lp)
@@ -139,7 +139,7 @@ lfree(lp) register LINE *lp; {
*/
VOID
lchange(flag) register int flag; {
- register WINDOW *wp;
+ register MGWIN *wp;
if ((curbp->b_flag&BFCHG) == 0) { /* First change, so */
flag |= WFMODE; /* update mode lines. */
@@ -175,7 +175,7 @@ int n;
LINE *lp3;
register int doto;
register RSIZE i;
- WINDOW *wp;
+ MGWIN *wp;
lchange(WFEDIT);
lp1 = curwp->w_dotp; /* Current line */
@@ -267,7 +267,7 @@ lnewline()
register LINE *lp2;
register int doto;
register int nlen;
- WINDOW *wp;
+ MGWIN *wp;
lchange(WFHARD);
lp1 = curwp->w_dotp; /* Get the address and */
@@ -320,7 +320,7 @@ ldelete(n, kflag) RSIZE n; {
register LINE *dotp;
register int doto;
register RSIZE chunk;
- WINDOW *wp;
+ MGWIN *wp;
/*
* HACK - doesn't matter, and fixes back-over-nl bug for empty
@@ -396,7 +396,7 @@ ldelete(n, kflag) RSIZE n; {
ldelnewline() {
register LINE *lp1;
register LINE *lp2;
- register WINDOW *wp;
+ register MGWIN *wp;
LINE *lp3;
lp1 = curwp->w_dotp;
diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c
index e14fb6095f1..73271ce9b6e 100644
--- a/usr.bin/mg/main.c
+++ b/usr.bin/mg/main.c
@@ -10,9 +10,9 @@ int thisflag; /* Flags, this command */
int lastflag; /* Flags, last command */
int curgoal; /* Goal column */
BUFFER *curbp; /* Current buffer */
-WINDOW *curwp; /* Current window */
+MGWIN *curwp; /* Current window */
BUFFER *bheadp; /* BUFFER listhead */
-WINDOW *wheadp = (WINDOW *)NULL; /* WINDOW listhead */
+MGWIN *wheadp = (MGWIN *)NULL; /* MGWIN listhead */
char pat[NPAT]; /* Pattern */
#ifndef NO_DPROMPT
extern char prompt[], *promptp; /* delayed prompting */
@@ -85,11 +85,11 @@ char **argv;
static VOID
edinit() {
register BUFFER *bp;
- register WINDOW *wp;
+ register MGWIN *wp;
bheadp = NULL;
bp = bfind("*scratch*", TRUE); /* Text buffer. */
- wp = (WINDOW *)malloc(sizeof(WINDOW)); /* Initial window. */
+ wp = (MGWIN *)malloc(sizeof(MGWIN)); /* Initial window. */
if (bp==NULL || wp==NULL) panic("edinit");
curbp = bp; /* Current ones. */
wheadp = wp;
diff --git a/usr.bin/mg/sysdef.h b/usr.bin/mg/sysdef.h
index 50639e63566..33d112cdd47 100644
--- a/usr.bin/mg/sysdef.h
+++ b/usr.bin/mg/sysdef.h
@@ -1,5 +1,5 @@
/*
- * System V system header file
+ * POSIX system header file
*/
#include <stdio.h>
#include <unistd.h>
diff --git a/usr.bin/mg/tty.c b/usr.bin/mg/tty.c
index 3ec5c434629..aca60e8a3ad 100644
--- a/usr.bin/mg/tty.c
+++ b/usr.bin/mg/tty.c
@@ -1,8 +1,8 @@
/*
- * Termcap/terminfo display driver
+ * Terminfo display driver
*
- * Termcap is a terminal information database and routines to describe
- * terminals on most UNIX systems. Many other systems have adopted
+ * Terminfo is a terminal information database and routines to describe
+ * terminals on most modern UNIX systems. Many other systems have adopted
* this as a reasonable way to allow for widly varying and ever changing
* varieties of terminal types. This should be used where practical.
*/
@@ -26,7 +26,8 @@
*/
#include "def.h"
-#define BEL 0x07 /* BEL character. */
+#include <curses.h>
+#include <term.h>
extern int ttrow;
extern int ttcol;
@@ -34,150 +35,81 @@ extern int tttop;
extern int ttbot;
extern int tthue;
+extern int ttputc();
+
int tceeol; /* Costs are set later */
int tcinsl;
int tcdell;
static int insdel; /* Do we have both insert & delete line? */
+static char * scroll_fwd; /* How to scroll forward. */
#ifdef NO_RESIZE
static setttysize();
#endif
-char *tgetstr();
-char *tgoto();
-int ttputc();
-
-#define TCAPSLEN 1024
-
-char tcapbuf[TCAPSLEN];
-
-/* PC, UP, and BC are used by termlib, so must be extern and have these
- * names unless you have a non-standard termlib.
- */
-
-int LI; /* standard # lines */
-char PC,
- *CM,
- *CE,
- *UP,
- *BC,
- *IM, /* insert mode */
- *IC, /* insert a single space */
- *EI, /* end insert mode */
- *DC,
- *AL, /* add line */
- *DL, /* del line */
- *pAL, /* parameterized add line */
- *pDL, /* parameterized delete line */
- *TI, /* term init -- start using cursor motion */
- *TE, /* term end --- end using cursor motion */
- *SO,
- *SE,
- *CD,
- *CS, /* set scroll region */
- *SF, /* forw index (used with scroll region) */
- *SR; /* back index (used with scroll region) */
-#ifdef XKEYS
-char *KS, *KE; /* enter keypad mode, exit keypad mode */
-#endif
-int SG; /* number of glitches, 0 for invisible, -1 for none */
- /* (yes virginia, there are terminals with invisible glitches) */
-
/*
* Initialize the terminal when the editor
* gets started up.
*/
-static char tcbuf[1024];
-
ttinit() {
char *tv_stype;
- char *t, *p, *tgetstr();
+ char *t, *p;
#ifndef gettermtype /* (avoid declaration if #define) */
char *gettermtype(); /* system dependent function to determin terminal type */
#endif
- if((tv_stype = gettermtype()) == NULL)
+ if ((tv_stype = gettermtype()) == NULL)
panic("Could not determine terminal type");
- if((tgetent(tcbuf, tv_stype)) != 1) {
- (VOID) strcpy(tcbuf, "Unknown terminal type ");
- (VOID) strcat(tcbuf, tv_stype);
- panic(tcbuf);
+ if (setupterm(tv_stype, 1, NULL) == ERR) {
+ (void) asprintf(&p, "Unknown terminal type: %s", tv_stype);
+ panic(p);
}
- p = tcapbuf;
- t = tgetstr("pc", &p);
- if(t) PC = *t;
-
- LI = tgetnum("li");
- CD = tgetstr("cd", &p);
- CM = tgetstr("cm", &p);
- CE = tgetstr("ce", &p);
- UP = tgetstr("up", &p);
- BC = tgetstr("bc", &p);
- IM = tgetstr("im", &p);
- IC = tgetstr("ic", &p);
- EI = tgetstr("ei", &p);
- DC = tgetstr("dc", &p);
- AL = tgetstr("al", &p);
- DL = tgetstr("dl", &p);
- pAL= tgetstr("AL", &p); /* parameterized insert and del. line */
- pDL= tgetstr("DL", &p);
- TI = tgetstr("ti", &p);
- TE = tgetstr("te", &p);
- SO = tgetstr("so", &p);
- SE = tgetstr("se", &p);
- CS = tgetstr("cs", &p); /* set scrolling region */
- SF = tgetstr("sf", &p);
- if(!SF || !*SF) { /* this is what GNU Emacs does */
- SF = tgetstr("do", &p);
- if(!SF || !*SF) {
- SF = tgetstr("nl", &p);
- if(!SF || !*SF) SF = "\n";
- }
+ scroll_fwd = scroll_forward;
+ if (!scroll_fwd || !*scroll_fwd) {
+ /* this is what GNU Emacs does */
+ scroll_fwd = parm_down_cursor;
+ if (!scroll_fwd || !*scroll_fwd)
+ scroll_fwd = "\n";
}
- SR = tgetstr("sr", &p);
- SG = tgetnum("sg"); /* standout glitch */
-#ifdef XKEYS
- KS = tgetstr("ks", &p); /* keypad start, keypad end */
- KE = tgetstr("ke", &p);
-#endif
- if(CM == NULL || UP == NULL)
- panic("This terminal is to stupid to run MicroGnuEmacs\n");
+ if (!cursor_address || !cursor_up)
+ panic("This terminal is to stupid to run mg");
ttresize(); /* set nrow & ncol */
- /* watch out for empty capabilities (sure to be wrong) */
- if (CE && !*CE) CE = NULL;
- if (CS && !*CS) CS = NULL;
- if (SR && !*SR) SR = NULL;
- if (AL && !*AL) AL = NULL;
- if (DL && !*DL) DL = NULL;
- if (pAL && !*pAL) pAL = NULL;
- if (pDL && !*pDL) pDL = NULL;
- if (CD && !*CD) CD = NULL;
-
- if(!CE) tceeol = ncol;
- else tceeol = charcost(CE);
+ if (!clr_eol)
+ tceeol = ncol;
+ else
+ tceeol = charcost(clr_eol);
/* Estimate cost of inserting a line */
- if (CS && SR) tcinsl = charcost(CS)*2 + charcost(SR);
- else if (pAL) tcinsl = charcost(pAL);
- else if (AL) tcinsl = charcost(AL);
- else tcinsl = NROW * NCOL; /* make this cost high enough */
+ if (change_scroll_region && scroll_reverse)
+ tcinsl = charcost(change_scroll_region)*2 +
+ charcost(scroll_reverse);
+ else if (parm_insert_line)
+ tcinsl = charcost(parm_insert_line);
+ else if (insert_line)
+ tcinsl = charcost(insert_line);
+ else
+ tcinsl = NROW * NCOL; /* make this cost high enough */
/* Estimate cost of deleting a line */
- if (CS) tcdell = charcost(CS)*2 + charcost(SF);
- else if (pDL) tcdell = charcost(pDL);
- else if (DL) tcdell = charcost(DL);
- else tcdell = NROW * NCOL; /* make this cost high enough */
+ if (change_scroll_region)
+ tcdell = charcost(change_scroll_region)*2 +
+ charcost(scroll_fwd);
+ else if (parm_delete_line)
+ tcdell = charcost(parm_delete_line);
+ else if (delete_line)
+ tcdell = charcost(delete_line);
+ else
+ tcdell = NROW * NCOL; /* make this cost high enough */
/* Flag to indicate that we can both insert and delete lines */
- insdel = (AL || pAL) && (DL || pDL);
+ insdel = (insert_line || parm_insert_line) && (delete_line || parm_delete_line);
- if (p >= &tcapbuf[TCAPSLEN])
- panic("Terminal description too big!\n");
- if (TI && *TI) putpad(TI, 1); /* init the term */
+ if (enter_ca_mode)
+ putpad(enter_ca_mode, 1); /* init the term */
}
/*
@@ -189,7 +121,10 @@ ttinit() {
* back to what it was.
*/
tttidy() {
- if (TE && *TE) putpad(TE, 1); /* set the term back to normal mode */
+
+ /* set the term back to normal mode */
+ if (exit_ca_mode)
+ putpad(exit_ca_mode, 1);
#ifdef XKEYS
ttykeymaptidy();
#endif
@@ -205,10 +140,10 @@ tttidy() {
ttmove(row, col) {
char *tgoto();
- if (ttrow!=row || ttcol!=col) {
- putpad(tgoto(CM, col, row), 1);
- ttrow = row;
- ttcol = col;
+ if (ttrow != row || ttcol !=col) {
+ putpad(tgoto(cursor_address, col, row), 1);
+ ttrow = row;
+ ttcol = col;
}
}
@@ -216,38 +151,44 @@ ttmove(row, col) {
* Erase to end of line.
*/
tteeol() {
- if(CE) putpad(CE, 1);
- else {
- register int i=ncol-ttcol;
- while(i--) ttputc(' ');
- ttrow = ttcol = HUGE;
- }
+
+ if (clr_eol)
+ putpad(clr_eol, 1);
+ else {
+ int i = ncol - ttcol;
+ while (i--)
+ ttputc(' ');
+ ttrow = ttcol = HUGE;
+ }
}
/*
* Erase to end of page.
*/
tteeop() {
- if(CD) putpad(CD, nrow - ttrow);
- else {
- putpad(CE, 1);
- if (insdel) ttdell(ttrow + 1, LI, LI - ttrow - 1);
- else { /* do it by hand */
- register int line;
- for (line = ttrow + 1; line <= LI; ++line) {
- ttmove(line, 0);
- tteeol();
- }
+ int line;
+
+ if (clr_eos)
+ putpad(clr_eos, nrow - ttrow);
+ else {
+ putpad(clr_eol, 1);
+ if (insdel)
+ ttdell(ttrow + 1, lines, lines - ttrow - 1);
+ else { /* do it by hand */
+ for (line = ttrow + 1; line <= lines; ++line) {
+ ttmove(line, 0);
+ tteeol();
+ }
+ }
+ ttrow = ttcol = HUGE;
}
- ttrow = ttcol = HUGE;
- }
}
/*
* Make a noise.
*/
ttbeep() {
- ttputc(BEL);
+ putpad(bell, 1);
ttflush();
}
@@ -260,34 +201,43 @@ ttbeep() {
* of insert and delete line sequences
*/
ttinsl(row, bot, nchunk) {
- register int i, nl;
+ int i, nl;
- if (row == bot) { /* Case of one line insert is */
- ttmove(row, 0); /* special */
- tteeol();
- return;
- }
- if (CS && SR) { /* Use scroll region and back index */
- nl = bot - row;
- ttwindow(row,bot);
- ttmove(row, 0);
- while (nchunk--) putpad(SR, nl);
- ttnowindow();
- return;
- } else if (insdel) {
- ttmove(1+bot-nchunk, 0);
- nl = nrow - ttrow;
- if (pDL) putpad(tgoto(pDL, 0, nchunk), nl);
- else for (i=0; i<nchunk; i++) /* For all lines in the chunk */
- putpad(DL, nl);
- ttmove(row, 0);
- nl = nrow - ttrow; /* ttmove() changes ttrow */
- if (pAL) putpad(tgoto(pAL, 0, nchunk), nl);
- else for (i=0; i<nchunk; i++) /* For all lines in the chunk */
- putpad(AL, nl);
- ttrow = HUGE;
- ttcol = HUGE;
- } else panic("ttinsl: Can't insert/delete line");
+ if (row == bot) { /* Case of one line insert is */
+ ttmove(row, 0); /* special */
+ tteeol();
+ return;
+ }
+ if (change_scroll_region && scroll_reverse) {
+ /* Use scroll region and back index */
+ nl = bot - row;
+ ttwindow(row,bot);
+ ttmove(row, 0);
+ while (nchunk--)
+ putpad(scroll_reverse, nl);
+ ttnowindow();
+ return;
+ } else if (insdel) {
+ ttmove(1+bot-nchunk, 0);
+ nl = nrow - ttrow;
+ if (parm_delete_line)
+ putpad(tgoto(parm_delete_line, 0, nchunk), nl);
+ else
+ /* For all lines in the chunk */
+ for (i=0; i<nchunk; i++)
+ putpad(delete_line, nl);
+ ttmove(row, 0);
+ nl = nrow - ttrow; /* ttmove() changes ttrow */
+ if (parm_insert_line)
+ putpad(tgoto(parm_insert_line, 0, nchunk), nl);
+ else
+ /* For all lines in the chunk */
+ for (i=0; i<nchunk; i++)
+ putpad(insert_line, nl);
+ ttrow = HUGE;
+ ttcol = HUGE;
+ } else
+ panic("ttinsl: Can't insert/delete line");
}
/*
@@ -300,34 +250,42 @@ ttinsl(row, bot, nchunk) {
*/
ttdell(row, bot, nchunk)
{
- register int i, nl;
+ int i, nl;
- if (row == bot) { /* One line special case */
- ttmove(row, 0);
- tteeol();
- return;
- }
- if (CS) { /* scrolling region */
- nl = bot - row;
- ttwindow(row, bot);
- ttmove(bot, 0);
- while (nchunk--) putpad(SF, nl);
- ttnowindow();
- }
- else if(insdel) {
- ttmove(row, 0); /* Else use insert/delete line */
- nl = nrow - ttrow;
- if (pDL) putpad(tgoto(pDL, 0, nchunk), nl);
- else for (i=0; i<nchunk; i++) /* For all lines in the chunk */
- putpad(DL, nl);
- ttmove(1+bot-nchunk,0);
- nl = nrow - ttrow; /* ttmove() changes ttrow */
- if (pAL) putpad(tgoto(pAL, 0, nchunk), nl);
- else for (i=0; i<nchunk; i++) /* For all lines in the chunk */
- putpad(AL, nl);
- ttrow = HUGE;
- ttcol = HUGE;
- } else panic("ttdell: Can't insert/delete line");
+ if (row == bot) { /* One line special case */
+ ttmove(row, 0);
+ tteeol();
+ return;
+ }
+ if (change_scroll_region) { /* scrolling region */
+ nl = bot - row;
+ ttwindow(row, bot);
+ ttmove(bot, 0);
+ while (nchunk--)
+ putpad(scroll_fwd, nl);
+ ttnowindow();
+ }
+ else if (insdel) {
+ ttmove(row, 0); /* Else use insert/delete line */
+ nl = nrow - ttrow;
+ if (parm_delete_line)
+ putpad(tgoto(parm_delete_line, 0, nchunk), nl);
+ else
+ /* For all lines in the chunk */
+ for (i=0; i<nchunk; i++)
+ putpad(delete_line, nl);
+ ttmove(1+bot-nchunk,0);
+ nl = nrow - ttrow; /* ttmove() changes ttrow */
+ if (parm_insert_line)
+ putpad(tgoto(parm_insert_line, 0, nchunk), nl);
+ else
+ /* For all lines in the chunk */
+ for (i=0; i<nchunk; i++)
+ putpad(insert_line, nl);
+ ttrow = HUGE;
+ ttcol = HUGE;
+ } else
+ panic("ttdell: Can't insert/delete line");
}
/*
@@ -344,8 +302,8 @@ ttdell(row, bot, nchunk)
*/
ttwindow(top, bot)
{
- if (CS && (tttop!=top || ttbot!=bot)) {
- putpad(tgoto(CS, bot, top), nrow - ttrow);
+ if (change_scroll_region && (tttop != top || ttbot != bot)) {
+ putpad(tgoto(change_scroll_region, bot, top), nrow - ttrow);
ttrow = HUGE; /* Unknown. */
ttcol = HUGE;
tttop = top; /* Remember region. */
@@ -359,19 +317,20 @@ ttwindow(top, bot)
* editor, and by "display.c" when it is getting ready
* to exit. This function gets to full screen scroll
* by telling the terminal to set a scrolling regin
- * that is LI or nrow rows high, whichever is larger.
+ * that is lines or nrow rows high, whichever is larger.
* This behavior seems to work right on systems
* where you can set your terminal size.
*/
ttnowindow()
{
- if (CS) {
- putpad(tgoto(CS, (nrow > LI ? nrow : LI) - 1, 0), nrow - ttrow);
- ttrow = HUGE; /* Unknown. */
- ttcol = HUGE;
- tttop = HUGE; /* No scroll region. */
- ttbot = HUGE;
- }
+ if (change_scroll_region) {
+ putpad(tgoto(change_scroll_region,
+ (nrow > lines ? nrow : lines) - 1, 0), nrow - ttrow);
+ ttrow = HUGE; /* Unknown. */
+ ttcol = HUGE;
+ tttop = HUGE; /* No scroll region. */
+ ttbot = HUGE;
+ }
}
/*
@@ -383,15 +342,17 @@ ttnowindow()
* line by line basis, so don't bother sending
* out the color shift.
*/
-ttcolor(color) register int color; {
- if (color != tthue) {
- if (color == CTEXT) { /* Normal video. */
- putpad(SE, 1);
- } else if (color == CMODE) { /* Reverse video. */
- putpad(SO, 1);
+ttcolor(color)
+ int color;
+{
+
+ if (color != tthue) {
+ if (color == CTEXT) /* Normal video. */
+ putpad(exit_standout_mode, 1);
+ else if (color == CMODE) /* Reverse video. */
+ putpad(enter_standout_mode, 1);
+ tthue = color; /* Save the color. */
}
- tthue = color; /* Save the color. */
- }
}
/*
@@ -404,6 +365,7 @@ ttcolor(color) register int color; {
* see how the caller deals with a change.
*/
ttresize() {
+
setttysize(); /* found in "ttyio.c", */
/* ask OS for tty size */
if (nrow < 1) /* Check limits. */
@@ -435,8 +397,8 @@ char c;
/* calculate the cost of doing string s */
charcost (s) char *s; {
- cci = 0;
+ cci = 0;
- tputs(s, nrow, fakec);
- return cci;
+ tputs(s, nrow, fakec);
+ return (cci);
}
diff --git a/usr.bin/mg/ttyio.c b/usr.bin/mg/ttyio.c
index 58f84eb4dfa..d13caf3e69f 100644
--- a/usr.bin/mg/ttyio.c
+++ b/usr.bin/mg/ttyio.c
@@ -1,6 +1,6 @@
/*
* Name: MicroEMACS
- * System V terminal I/O.
+ * POSIX terminal I/O.
* Version: 0
* Last edit: Tue Aug 26 23:57:57 PDT 1986
* By: gonzo!daveb
@@ -11,15 +11,14 @@
* keyboard characters, and write characters to
* the display in a barely buffered fashion.
*
- * This version goes along with tty/termcap/tty.c.
- * Terminal size is determined there, rather than here, and
- * this does not open the termcap file
+ * This version goes along with the terminfo tty.c.
*/
#include "def.h"
#include <sys/types.h>
#include <fcntl.h>
#include <termios.h>
+#include <term.h>
#define NOBUF 512 /* Output buffer size. */
@@ -77,45 +76,12 @@ ttopen()
if (tcsetattr(0, TCSAFLUSH, &nt) < 0)
abort();
- /* This really belongs in tty/termcap... */
-
- if ((cp=getenv("TERMCAP")) == NULL
- || (nrow=getvalue(cp, "li")) <= 0
- || (ncol=getvalue(cp, "co")) <= 0) {
- nrow = 24;
- ncol = 80;
- }
- if (nrow > NROW) /* Don't crash if the */
- nrow = NROW; /* termcap entry is */
- if (ncol > NCOL) /* too big. */
- ncol = NCOL;
+ setttysize();
ttyactivep = TRUE;
}
/*
- * This routine scans a string, which is
- * actually the return value of a getenv call for the TERMCAP
- * variable, looking for numeric parameter "name". Return the value
- * if found. Return -1 if not there. Assume that "name" is 2
- * characters long. This limited use of the TERMCAP lets us find
- * out the size of a window on the X display.
- */
-getvalue(cp, name)
-register char *cp;
-register char *name;
-{
- for (;;) {
- while (*cp!=0 && *cp!=':')
- ++cp;
- if (*cp++ == 0) /* Not found. */
- return (-1);
- if (cp[0]==name[0] && cp[1]==name[1] && cp[2]=='#')
- return (atoi(cp+3)); /* Stops on ":". */
- }
-}
-
-/*
* This function gets called just
* before we go back home to the shell. Put all of
* the terminal parameters back.
@@ -223,14 +189,15 @@ setttysize()
ncol = winsize . ws_col;
} else
#endif
- if ((nrow=tgetnum ("li")) <= 0
- || (ncol=tgetnum ("co")) <= 0) {
+ if ((nrow = lines) <= 0 || (ncol = columns) <= 0) {
nrow = 24;
ncol = 80;
}
- if (nrow > NROW) /* Don't crash if the */
- nrow = NROW; /* termcap entry is */
- if (ncol > NCOL) /* too big. */
+
+ /* Enforce maximum screen size. */
+ if (nrow > NROW)
+ nrow = NROW;
+ if (ncol > NCOL)
ncol = NCOL;
}
diff --git a/usr.bin/mg/ttykbd.c b/usr.bin/mg/ttykbd.c
index 13c0198a080..08c87f33573 100644
--- a/usr.bin/mg/ttykbd.c
+++ b/usr.bin/mg/ttykbd.c
@@ -1,12 +1,16 @@
/*
* Name: MG 2a
- * Termcap keyboard driver using key files
+ * Terminfo keyboard driver using key files
* Created: 22-Nov-1987 Mic Kaczmarczik (mic@emx.cc.utexas.edu)
*/
#include "def.h"
+#include "kbd.h"
#ifdef XKEYS
+#include <term.h>
+#ifdef FKEYS
+#include "key.h"
/*
* Get keyboard character. Very simple if you use keymaps and keys files.
* Bob was right -- the old XKEYS code is not the right solution.
@@ -14,31 +18,84 @@
* extend.c.
*/
-#ifdef FKEYS
char *keystrings[] = { NULL } ;
+
+int
+dobindkey(str, func)
+ char *str;
+ char *func;
+{
+ int i;
+ extern int bindkey(); /* XXX */
+
+ for (i = 0; *str && i < MAXKEY; i++) {
+ /* XXX - how to convert numbers? */
+ if (*str != '\\')
+ key.k_chars[i] = *str;
+ else {
+ switch(*++str) {
+ case 't': case 'T':
+ key.k_chars[i] = '\t';
+ break;
+ case 'n': case 'N':
+ key.k_chars[i] = '\n';
+ break;
+ case 'r': case 'R':
+ key.k_chars[i] = '\r';
+ break;
+ case 'e': case 'E':
+ key.k_chars[i] = CCHR('[');
+ break;
+ }
+ }
+ str++;
+ }
+ key.k_count = i;
+ return(bindkey(&map_table[0].p_map, func, key.k_chars, key.k_count));
+}
#endif
/*
- * Turn on function keys using KS, then load a keys file, if available.
- * The keys file is located in the same manner as the startup file is,
- * depending on what startupfile() does on your system.
+ * Turn on function keys using keypad_xmit, then load a keys file, if
+ * available. The keys file is located in the same manner as the startup
+ * file is, depending on what startupfile() does on your system.
*/
extern int ttputc();
ttykeymapinit()
{
- extern char *KS;
+ char *cp;
+#ifdef FKEYS
+ /* Bind keypad function keys. */
+ if (key_left)
+ dobindkey(key_left, "backward-char");
+ if (key_left)
+ dobindkey(key_left, "backward-char");
+ if (key_right)
+ dobindkey(key_right, "forward-char");
+ if (key_up)
+ dobindkey(key_up, "previous-line");
+ if (key_down)
+ dobindkey(key_down, "next-line");
+ if (key_beg)
+ dobindkey(key_beg, "beginning-of-line");
+ if (key_end)
+ dobindkey(key_end, "end-of-line");
+ if (key_npage)
+ dobindkey(key_npage, "scroll-up");
+ if (key_ppage)
+ dobindkey(key_ppage, "scroll-down");
+#endif
#ifndef NO_STARTUP
- char *cp, *startupfile();
-
if (cp = gettermtype()) {
+ extern char *startupfile();
if (((cp = startupfile(cp)) != NULL)
&& (load(cp) != TRUE))
ewprintf("Error reading key initialization file");
}
#endif
- if (KS && *KS) /* turn on keypad */
- putpad(KS, 1);
+ if (keypad_xmit) /* turn on keypad */
+ putpad(keypad_xmit, 1);
}
/*
@@ -46,10 +103,9 @@ ttykeymapinit()
*/
ttykeymaptidy()
{
- extern char *KE;
- if (KE && *KE)
- putpad(KE, 1); /* turn off keypad */
+ if (keypad_local)
+ putpad(keypad_local, 1); /* turn off keypad */
}
#endif
diff --git a/usr.bin/mg/window.c b/usr.bin/mg/window.c
index 25f6009ade6..18e944fcd0c 100644
--- a/usr.bin/mg/window.c
+++ b/usr.bin/mg/window.c
@@ -44,7 +44,7 @@ reposition(f, n)
/*ARGSUSED*/
refresh(f, n)
{
- register WINDOW *wp;
+ register MGWIN *wp;
register int oldnrow;
register int oldncol;
@@ -79,7 +79,7 @@ refresh(f, n)
/*ARGSUSED*/
nextwind(f, n)
{
- register WINDOW *wp;
+ register MGWIN *wp;
if ((wp=curwp->w_wndp) == NULL)
wp = wheadp;
@@ -100,8 +100,8 @@ nextwind(f, n)
/*ARGSUSED*/
prevwind(f, n)
{
- register WINDOW *wp1;
- register WINDOW *wp2;
+ register MGWIN *wp1;
+ register MGWIN *wp2;
wp1 = wheadp;
wp2 = curwp;
@@ -129,7 +129,7 @@ prevwind(f, n)
/*ARGSUSED*/
onlywind(f, n)
{
- register WINDOW *wp;
+ register MGWIN *wp;
register LINE *lp;
register int i;
@@ -178,19 +178,19 @@ onlywind(f, n)
/*ARGSUSED*/
splitwind(f, n)
{
- register WINDOW *wp;
+ register MGWIN *wp;
register LINE *lp;
register int ntru;
register int ntrd;
int ntrl;
- WINDOW *wp1, *wp2;
+ MGWIN *wp1, *wp2;
if (curwp->w_ntrows < 3) {
ewprintf("Cannot split a %d line window", curwp->w_ntrows);
return (FALSE);
}
- if ((wp = (WINDOW *)malloc(sizeof(WINDOW))) == NULL) {
- ewprintf("Can't get %d", sizeof(WINDOW));
+ if ((wp = (MGWIN *)malloc(sizeof(MGWIN))) == NULL) {
+ ewprintf("Can't get %d", sizeof(MGWIN));
return (FALSE);
}
++curbp->b_nwnd; /* Displayed twice. */
@@ -256,7 +256,7 @@ splitwind(f, n)
/*ARGSUSED*/
enlargewind(f, n)
{
- register WINDOW *adjwp;
+ register MGWIN *adjwp;
register LINE *lp;
register int i;
@@ -303,7 +303,7 @@ enlargewind(f, n)
*/
shrinkwind(f, n)
{
- register WINDOW *adjwp;
+ register MGWIN *adjwp;
register LINE *lp;
register int i;
@@ -353,7 +353,7 @@ shrinkwind(f, n)
/*ARGSUSED*/
delwind(f, n)
{
- register WINDOW *wp, *nwp;
+ register MGWIN *wp, *nwp;
wp = curwp; /* Cheap... */
/* shrinkwind returning false means only one window... */
@@ -385,9 +385,9 @@ delwind(f, n)
* might be better. Return a pointer, or
* NULL on error.
*/
-WINDOW *
+MGWIN *
wpopup() {
- register WINDOW *wp;
+ register MGWIN *wp;
if (wheadp->w_wndp == NULL
&& splitwind(FFRAND, 0) == FALSE)