2005-05-31 11:50:56 -04:00
|
|
|
/*
|
|
|
|
* uEmacs/PK 4.0
|
|
|
|
*
|
|
|
|
* based on
|
|
|
|
*
|
|
|
|
* MicroEMACS 3.9
|
|
|
|
* written by Dave G. Conroy.
|
|
|
|
* substatially modified by Daniel M. Lawrence
|
|
|
|
* modified by Petri Kutvonen
|
|
|
|
*
|
|
|
|
* MicroEMACS 3.9 (C)opyright 1987 by Daniel M. Lawrence
|
|
|
|
*
|
|
|
|
* Original statement of copying policy:
|
|
|
|
*
|
|
|
|
* MicroEMACS 3.9 can be copied and distributed freely for any
|
|
|
|
* non-commercial purposes. MicroEMACS 3.9 can only be incorporated
|
|
|
|
* into commercial software with the permission of the current author.
|
|
|
|
*
|
|
|
|
* No copyright claimed for modifications made by Petri Kutvonen.
|
|
|
|
*
|
|
|
|
* MAIN.C
|
|
|
|
*
|
|
|
|
* This file contains the main driving routine, and some keyboard
|
|
|
|
* processing code.
|
|
|
|
*
|
|
|
|
* REVISION HISTORY:
|
|
|
|
*
|
|
|
|
* 1.0 Steve Wilhite, 30-Nov-85
|
|
|
|
*
|
|
|
|
* 2.0 George Jones, 12-Dec-85
|
|
|
|
*
|
|
|
|
* 3.0 Daniel Lawrence, 29-Dec-85
|
|
|
|
*
|
|
|
|
* 3.2-3.6 Daniel Lawrence, Feb...Apr-86
|
|
|
|
*
|
|
|
|
* 3.7 Daniel Lawrence, 14-May-86
|
|
|
|
*
|
|
|
|
* 3.8 Daniel Lawrence, 18-Jan-87
|
|
|
|
*
|
|
|
|
* 3.9 Daniel Lawrence, 16-Jul-87
|
|
|
|
*
|
|
|
|
* 3.9e Daniel Lawrence, 16-Nov-87
|
|
|
|
*
|
|
|
|
* After that versions 3.X and Daniel Lawrence went their own ways.
|
|
|
|
* A modified 3.9e/PK was heavily used at the University of Helsinki
|
|
|
|
* for several years on different UNIX, VMS, and MSDOS platforms.
|
|
|
|
*
|
|
|
|
* This modified version is now called eEmacs/PK.
|
|
|
|
*
|
|
|
|
* 4.0 Petri Kutvonen, 1-Sep-91
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/* make global definitions not external */
|
|
|
|
#define maindef
|
|
|
|
|
|
|
|
#include "estruct.h" /* global structures and defines */
|
|
|
|
#include "edef.h" /* global definitions */
|
2005-10-01 01:52:45 -04:00
|
|
|
#include "efunc.h" /* function declarations and name table */
|
2005-05-31 11:50:56 -04:00
|
|
|
#include "ebind.h" /* default key bindings */
|
|
|
|
|
|
|
|
/* for MSDOS, increase the default stack space */
|
|
|
|
|
|
|
|
#if MSDOS & TURBO
|
|
|
|
#if PKCODE
|
|
|
|
extern unsigned _stklen = 20000;
|
|
|
|
#else
|
|
|
|
extern unsigned _stklen = 32766;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if VMS
|
|
|
|
#include <ssdef.h>
|
|
|
|
#define GOOD (SS$_NORMAL)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GOOD
|
|
|
|
#define GOOD 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if UNIX
|
|
|
|
#include <signal.h>
|
2005-10-01 04:09:22 -04:00
|
|
|
static void emergencyexit(int);
|
2005-05-31 11:58:59 -04:00
|
|
|
#ifdef SIGWINCH
|
2005-10-01 04:09:22 -04:00
|
|
|
extern void sizesignal(int);
|
2005-05-31 11:58:59 -04:00
|
|
|
#endif
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CALLED
|
2005-09-30 19:34:11 -04:00
|
|
|
int emacs(int argc, char **argv)
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2005-09-30 19:34:11 -04:00
|
|
|
int main(int argc, char **argv)
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
{
|
2005-10-01 02:52:55 -04:00
|
|
|
register int c = -1; /* command character */
|
2005-09-30 18:26:09 -04:00
|
|
|
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 */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if CRYPT
|
2005-09-30 18:26:09 -04:00
|
|
|
int cryptflag; /* encrypting on the way in? */
|
|
|
|
char ekey[NPAT]; /* startup encryption key */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
int newc;
|
|
|
|
|
|
|
|
#if PKCODE & VMS
|
|
|
|
(void) umask(-1); /* use old protection (this is at wrong place) */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if PKCODE & BSD
|
|
|
|
sleep(1); /* time for window manager */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if UNIX
|
|
|
|
#ifdef SIGWINCH
|
|
|
|
signal(SIGWINCH, sizesignal);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* initialize the editor */
|
2005-09-30 18:26:09 -04:00
|
|
|
vtinit(); /* Display */
|
|
|
|
edinit("main"); /* Buffers, windows */
|
2005-05-31 11:50:56 -04:00
|
|
|
varinit(); /* user variables */
|
|
|
|
|
|
|
|
viewflag = FALSE; /* view mode defaults off in command line */
|
|
|
|
gotoflag = FALSE; /* set to off to begin with */
|
|
|
|
searchflag = FALSE; /* set to off to begin with */
|
|
|
|
firstfile = TRUE; /* no file to edit yet */
|
|
|
|
startflag = FALSE; /* startup file not executed yet */
|
|
|
|
errflag = FALSE; /* not doing C error parsing */
|
|
|
|
#if CRYPT
|
|
|
|
cryptflag = FALSE; /* no encryption by default */
|
|
|
|
#endif
|
|
|
|
#if CALLED
|
|
|
|
eexitflag = FALSE; /* not time to exit yet */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Parse the command line */
|
|
|
|
for (carg = 1; carg < argc; ++carg) {
|
|
|
|
|
|
|
|
/* Process Switches */
|
|
|
|
#if PKCODE
|
|
|
|
if (argv[carg][0] == '+') {
|
|
|
|
gotoflag = TRUE;
|
|
|
|
gline = atoi(&argv[carg][1]);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (argv[carg][0] == '-') {
|
|
|
|
switch (argv[carg][1]) {
|
|
|
|
/* Process Startup macroes */
|
2005-09-30 18:26:09 -04:00
|
|
|
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;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if CRYPT
|
2005-09-30 18:26:09 -04:00
|
|
|
case 'k': /* -k<key> for code key */
|
|
|
|
case 'K':
|
|
|
|
cryptflag = TRUE;
|
|
|
|
strcpy(ekey, &argv[carg][2]);
|
|
|
|
break;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#if PKCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
case 'n': /* -n accept null chars */
|
|
|
|
case 'N':
|
|
|
|
nullflag = TRUE;
|
|
|
|
break;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
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;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
} else if (argv[carg][0] == '@') {
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* Process Startup macroes */
|
|
|
|
if (startup(&argv[carg][1]) == TRUE)
|
|
|
|
/* don't execute emacs.rc */
|
|
|
|
startflag = TRUE;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* Process an input file */
|
|
|
|
|
|
|
|
/* set up a buffer for this file */
|
2005-09-30 18:26:09 -04:00
|
|
|
makename(bname, argv[carg]);
|
2005-05-31 11:50:56 -04:00
|
|
|
unqname(bname);
|
|
|
|
|
|
|
|
/* set this to inactive */
|
|
|
|
bp = bfind(bname, TRUE, 0);
|
|
|
|
strcpy(bp->b_fname, argv[carg]);
|
|
|
|
bp->b_active = FALSE;
|
|
|
|
if (firstfile) {
|
|
|
|
firstbp = bp;
|
|
|
|
firstfile = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the modes appropriatly */
|
|
|
|
if (viewflag)
|
|
|
|
bp->b_mode |= MDVIEW;
|
|
|
|
#if CRYPT
|
|
|
|
if (cryptflag) {
|
|
|
|
bp->b_mode |= MDCRYPT;
|
2005-09-30 18:26:09 -04:00
|
|
|
crypt((char *) NULL, 0);
|
2005-05-31 11:50:56 -04:00
|
|
|
crypt(ekey, strlen(ekey));
|
|
|
|
strncpy(bp->b_key, ekey, NPAT);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if UNIX
|
2005-09-30 18:26:09 -04:00
|
|
|
signal(SIGHUP, emergencyexit);
|
2005-05-31 11:50:56 -04:00
|
|
|
signal(SIGTERM, emergencyexit);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* if we are C error parsing... run it! */
|
|
|
|
if (errflag) {
|
|
|
|
if (startup("error.cmd") == TRUE)
|
|
|
|
startflag = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if invoked with no other startup files,
|
|
|
|
run the system startup file here */
|
|
|
|
if (startflag == FALSE) {
|
|
|
|
startup("");
|
|
|
|
startflag = TRUE;
|
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
discmd = TRUE; /* P.K. */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* if there are any files to read, read the first one! */
|
|
|
|
bp = bfind("main", FALSE, 0);
|
|
|
|
if (firstfile == FALSE && (gflags & GFREAD)) {
|
|
|
|
swbuffer(firstbp);
|
|
|
|
zotbuf(bp);
|
|
|
|
} else
|
|
|
|
bp->b_mode |= gmode;
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
/* Deal with startup gotos and searches */
|
|
|
|
if (gotoflag && searchflag) {
|
|
|
|
update(FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
mlwrite("(Can not search and goto at the same time!)");
|
2005-09-30 18:26:09 -04:00
|
|
|
} else if (gotoflag) {
|
|
|
|
if (gotoline(TRUE, gline) == FALSE) {
|
|
|
|
update(FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
mlwrite("(Bogus goto argument)");
|
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
} else if (searchflag) {
|
|
|
|
if (forwhunt(FALSE, 0) == FALSE)
|
|
|
|
update(FALSE);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* setup to process commands */
|
2005-09-30 18:26:09 -04:00
|
|
|
lastflag = 0; /* Fake last flags. */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
loop:
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if CALLED
|
|
|
|
/* if we were called as a subroutine and want to leave, do so */
|
|
|
|
if (eexitflag)
|
2005-09-30 18:26:09 -04:00
|
|
|
return (eexitval);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* execute the "command" macro...normally null */
|
|
|
|
saveflag = lastflag; /* preserve lastflag through this */
|
2005-09-30 18:26:09 -04:00
|
|
|
execute(META | SPEC | 'C', FALSE, 1);
|
2005-05-31 11:50:56 -04:00
|
|
|
lastflag = saveflag;
|
|
|
|
|
|
|
|
#if TYPEAH && PKCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
if (typahead()) {
|
2005-05-31 11:50:56 -04:00
|
|
|
newc = getcmd();
|
|
|
|
update(FALSE);
|
2005-09-30 18:26:09 -04:00
|
|
|
do {
|
2005-10-01 01:52:45 -04:00
|
|
|
fn_t execfunc;
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
if (c == newc && (execfunc = getbind(c)) != NULL
|
2005-10-01 03:22:55 -04:00
|
|
|
&& execfunc != insert_newline
|
|
|
|
&& execfunc != insert_tab)
|
2005-05-31 11:50:56 -04:00
|
|
|
newc = getcmd();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
} while (typahead());
|
|
|
|
c = newc;
|
2005-09-30 18:26:09 -04:00
|
|
|
} else {
|
2005-05-31 11:50:56 -04:00
|
|
|
update(FALSE);
|
|
|
|
c = getcmd();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Fix up the screen */
|
2005-09-30 18:26:09 -04:00
|
|
|
update(FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* get the next command from the keyboard */
|
|
|
|
c = getcmd();
|
|
|
|
#endif
|
|
|
|
/* if there is something on the command line, clear it */
|
2005-09-30 18:26:09 -04:00
|
|
|
if (mpresf != FALSE) {
|
|
|
|
mlerase();
|
|
|
|
update(FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
#if CLRMSG
|
2005-09-30 18:26:09 -04:00
|
|
|
if (c == ' ') /* ITS EMACS does this */
|
|
|
|
goto loop;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
|
|
|
f = FALSE;
|
|
|
|
n = 1;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* do META-# processing if needed */
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
basec = c & ~META; /* strip meta char off if there */
|
2005-05-31 11:50:56 -04:00
|
|
|
if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) {
|
2005-09-30 18:26:09 -04:00
|
|
|
f = TRUE; /* there is a # arg */
|
|
|
|
n = 0; /* start with a zero default */
|
|
|
|
mflag = 1; /* current minus flag */
|
|
|
|
c = basec; /* strip the META */
|
2005-05-31 11:50:56 -04:00
|
|
|
while ((c >= '0' && c <= '9') || (c == '-')) {
|
|
|
|
if (c == '-') {
|
|
|
|
/* already hit a minus or digit? */
|
|
|
|
if ((mflag == -1) || (n != 0))
|
|
|
|
break;
|
|
|
|
mflag = -1;
|
|
|
|
} else {
|
|
|
|
n = n * 10 + (c - '0');
|
|
|
|
}
|
|
|
|
if ((n == 0) && (mflag == -1)) /* lonely - */
|
|
|
|
mlwrite("Arg:");
|
|
|
|
else
|
2005-09-30 18:26:09 -04:00
|
|
|
mlwrite("Arg: %d", n * mflag);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
c = getcmd(); /* get the next key */
|
|
|
|
}
|
|
|
|
n = n * mflag; /* figure in the sign */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do ^U repeat argument processing */
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (c == reptc) { /* ^U, start argument */
|
|
|
|
f = TRUE;
|
|
|
|
n = 4; /* with argument of 4 */
|
|
|
|
mflag = 0; /* that can be discarded. */
|
|
|
|
mlwrite("Arg: 4");
|
2005-10-01 02:52:55 -04:00
|
|
|
while (((c = getcmd()) >= '0' && c <= '9') || c == reptc
|
2005-09-30 18:26:09 -04:00
|
|
|
|| 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;
|
|
|
|
}
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* and execute the command */
|
2005-09-30 18:26:09 -04:00
|
|
|
execute(c, f, n);
|
|
|
|
goto loop;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize all of the buffers and windows. The buffer name is passed down
|
|
|
|
* as an argument, because the main routine may have been told to read in a
|
|
|
|
* file by default, and we want the buffer name to be right.
|
|
|
|
*/
|
2005-10-01 02:52:55 -04:00
|
|
|
void edinit(char *bname)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
register BUFFER *bp;
|
2005-10-01 03:02:32 -04:00
|
|
|
register window_t *wp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
bp = bfind(bname, TRUE, 0); /* First buffer */
|
|
|
|
blistp = bfind("*List*", TRUE, BFINVS); /* Buffer list buffer */
|
2005-10-01 03:02:32 -04:00
|
|
|
wp = (window_t *) malloc(sizeof(window_t)); /* First window */
|
2005-09-30 18:26:09 -04:00
|
|
|
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;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if COLOR
|
|
|
|
/* initalize colors to global defaults */
|
|
|
|
wp->w_fcolor = gfcolor;
|
|
|
|
wp->w_bcolor = gbcolor;
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
wp->w_ntrows = term.t_nrow - 1; /* "-1" for mode line. */
|
|
|
|
wp->w_force = 0;
|
|
|
|
wp->w_flag = WFMODE | WFHARD; /* Full. */
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the general command execution routine. It handles the fake binding
|
|
|
|
* of all the keys to "self-insert". It also clears out the "thisflag" word,
|
|
|
|
* and arranges to move it to the "lastflag", so that the next command can
|
|
|
|
* look at it. Return the status of command.
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
int execute(int c, int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
register int status;
|
2005-10-01 01:52:45 -04:00
|
|
|
fn_t execfunc;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* if the keystroke is a bound function...do it */
|
|
|
|
execfunc = getbind(c);
|
2005-09-30 18:26:09 -04:00
|
|
|
if (execfunc != NULL) {
|
2005-05-31 11:50:56 -04:00
|
|
|
thisflag = 0;
|
2005-09-30 18:26:09 -04:00
|
|
|
status = (*execfunc) (f, n);
|
2005-05-31 11:50:56 -04:00
|
|
|
lastflag = thisflag;
|
|
|
|
return (status);
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
/*
|
|
|
|
* 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,
|
2005-05-31 11:50:56 -04:00
|
|
|
* and we are not read-only, perform word wrap.
|
2005-09-30 18:26:09 -04:00
|
|
|
*/
|
|
|
|
if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 &&
|
2005-05-31 11:50:56 -04:00
|
|
|
n >= 0 && getccol(FALSE) > fillcol &&
|
|
|
|
(curwp->w_bufp->b_mode & MDVIEW) == FALSE)
|
2005-09-30 18:26:09 -04:00
|
|
|
execute(META | SPEC | 'W', FALSE, 1);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if PKCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((c >= 0x20 && c <= 0x7E) /* Self inserting. */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if IBMPC
|
2005-09-30 18:26:09 -04:00
|
|
|
|| (c >= 0x80 && c <= 0xFE)) {
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
#if VMS || BSD || USG /* 8BIT P.K. */
|
|
|
|
|| (c >= 0xA0 && c <= 0xFE)) {
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
) {
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((c >= 0x20 && c <= 0xFF)) { /* Self inserting. */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
if (n <= 0) { /* Fenceposts. */
|
|
|
|
lastflag = 0;
|
|
|
|
return (n < 0 ? FALSE : TRUE);
|
|
|
|
}
|
|
|
|
thisflag = 0; /* For the future. */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* if we are in overwrite mode, not at eol,
|
|
|
|
and next char is not a tab or we are at a tab stop,
|
2005-09-30 18:26:09 -04:00
|
|
|
delete a char forword */
|
2005-05-31 11:50:56 -04:00
|
|
|
if (curwp->w_bufp->b_mode & MDOVER &&
|
|
|
|
curwp->w_doto < curwp->w_dotp->l_used &&
|
2005-09-30 18:26:09 -04:00
|
|
|
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
|
|
|
|
(curwp->w_doto) % 8 == 7))
|
|
|
|
ldelete(1L, FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* do the appropriate insertion */
|
|
|
|
if (c == '}' && (curbp->b_mode & MDCMOD) != 0)
|
2005-09-30 18:26:09 -04:00
|
|
|
status = insbrace(n, c);
|
|
|
|
else if (c == '#' && (curbp->b_mode & MDCMOD) != 0)
|
|
|
|
status = inspound();
|
|
|
|
else
|
|
|
|
status = linsert(n, c);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if CFENCE
|
|
|
|
/* check for CMODE fence matching */
|
|
|
|
if ((c == '}' || c == ')' || c == ']') &&
|
2005-09-30 18:26:09 -04:00
|
|
|
(curbp->b_mode & MDCMOD) != 0)
|
2005-05-31 11:50:56 -04:00
|
|
|
fmatch(c);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check auto-save mode */
|
|
|
|
if (curbp->b_mode & MDASAVE)
|
|
|
|
if (--gacount == 0) {
|
|
|
|
/* and save the file if needed */
|
|
|
|
upscreen(FALSE, 0);
|
|
|
|
filesave(FALSE, 0);
|
|
|
|
gacount = gasave;
|
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
lastflag = thisflag;
|
|
|
|
return (status);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
TTbeep();
|
2005-09-30 18:26:09 -04:00
|
|
|
mlwrite("(Key not bound)"); /* complain */
|
|
|
|
lastflag = 0; /* Fake last flags. */
|
|
|
|
return (FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fancy quit command, as implemented by Norm. If the any buffer has
|
|
|
|
* changed do a write on that buffer and exit emacs, otherwise simply exit.
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
int quickexit(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
register BUFFER *bp; /* scanning pointer to buffers */
|
2005-09-30 18:26:09 -04:00
|
|
|
register BUFFER *oldcb; /* original current buffer */
|
2005-05-31 11:50:56 -04:00
|
|
|
register int status;
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
oldcb = curbp; /* save in case we fail */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
bp = bheadp;
|
|
|
|
while (bp != NULL) {
|
2005-09-30 18:26:09 -04:00
|
|
|
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);
|
2005-05-31 11:50:56 -04:00
|
|
|
#if PKCODE
|
|
|
|
#else
|
|
|
|
mlwrite("\n");
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((status = filesave(f, n)) != TRUE) {
|
|
|
|
curbp = oldcb; /* restore curbp */
|
|
|
|
return (status);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
bp = bp->b_bufp; /* on to the next buffer */
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
quit(f, n); /* conditionally quit */
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
static void emergencyexit(int signr)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
quickexit(FALSE, 0);
|
2005-09-30 18:26:09 -04:00
|
|
|
quit(TRUE, 0);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Quit command. If an argument, always quit. Otherwise confirm if a buffer
|
|
|
|
* has been changed and not written out. Normally bound to "C-X C-C".
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
int quit(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
register int s;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (f != FALSE /* Argument forces it. */
|
|
|
|
|| anycb() == FALSE /* All buffers clean. */
|
|
|
|
/* User says it's OK. */
|
|
|
|
|| (s =
|
|
|
|
mlyesno("Modified buffers exist. Leave anyway")) == TRUE) {
|
2005-05-31 11:50:56 -04:00
|
|
|
#if (FILOCK && BSD) || SVR4
|
|
|
|
if (lockrel() != TRUE) {
|
|
|
|
TTputc('\n');
|
|
|
|
TTputc('\r');
|
|
|
|
TTclose();
|
|
|
|
TTkclose();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
vttidy();
|
2005-05-31 11:50:56 -04:00
|
|
|
if (f)
|
|
|
|
exit(n);
|
|
|
|
else
|
2005-09-30 18:26:09 -04:00
|
|
|
exit(GOOD);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
mlwrite("");
|
2005-09-30 18:26:09 -04:00
|
|
|
return (s);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Begin a keyboard macro.
|
|
|
|
* Error if not at the top level in keyboard processing. Set up variables and
|
|
|
|
* return.
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
int ctlxlp(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
if (kbdmode != STOP) {
|
|
|
|
mlwrite("%%Macro already active");
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
mlwrite("(Start macro)");
|
2005-05-31 11:50:56 -04:00
|
|
|
kbdptr = &kbdm[0];
|
|
|
|
kbdend = kbdptr;
|
2005-09-30 18:26:09 -04:00
|
|
|
kbdmode = RECORD;
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* End keyboard macro. Check for the same limit conditions as the above
|
|
|
|
* routine. Set up the variables and return to the caller.
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
int ctlxrp(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
if (kbdmode == STOP) {
|
|
|
|
mlwrite("%%Macro not active");
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
if (kbdmode == RECORD) {
|
2005-09-30 18:26:09 -04:00
|
|
|
mlwrite("(End macro)");
|
|
|
|
kbdmode = STOP;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Execute a macro.
|
|
|
|
* The command argument is the number of times to loop. Quit as soon as a
|
|
|
|
* command gets an error. Return TRUE if all ok, else FALSE.
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
int ctlxe(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
if (kbdmode != STOP) {
|
|
|
|
mlwrite("%%Macro already active");
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
if (n <= 0)
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
kbdrep = n; /* remember how many times to execute */
|
|
|
|
kbdmode = PLAY; /* start us in play mode */
|
|
|
|
kbdptr = &kbdm[0]; /* at the beginning */
|
2005-09-30 18:26:09 -04:00
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Abort.
|
|
|
|
* Beep the beeper. Kill off any keyboard macro, etc., that is in progress.
|
|
|
|
* Sometimes called as a routine, to do general aborting of stuff.
|
|
|
|
*/
|
2005-09-30 19:34:11 -04:00
|
|
|
int ctrlg(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
TTbeep();
|
2005-05-31 11:50:56 -04:00
|
|
|
kbdmode = STOP;
|
|
|
|
mlwrite("(Aborted)");
|
2005-09-30 18:26:09 -04:00
|
|
|
return (ABORT);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* tell the user that this command is illegal while we are in
|
|
|
|
* VIEW (read-only) mode
|
|
|
|
*/
|
|
|
|
int rdonly(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
TTbeep();
|
|
|
|
mlwrite("(Key illegal in VIEW mode)");
|
2005-09-30 18:26:09 -04:00
|
|
|
return (FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
int resterr(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
TTbeep();
|
|
|
|
mlwrite("(That command is RESTRICTED)");
|
2005-09-30 18:26:09 -04:00
|
|
|
return (FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 02:52:55 -04:00
|
|
|
/* user function that does NOTHING */
|
2005-09-30 19:34:11 -04:00
|
|
|
int nullproc(int f, int n)
|
2005-10-01 02:52:55 -04:00
|
|
|
{
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 02:52:55 -04:00
|
|
|
/* dummy function for binding to meta prefix */
|
2005-10-01 03:22:55 -04:00
|
|
|
int metafn(int f, int n)
|
2005-10-01 02:52:55 -04:00
|
|
|
{
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 02:52:55 -04:00
|
|
|
/* dummy function for binding to control-x prefix */
|
2005-09-30 19:34:11 -04:00
|
|
|
int cex(int f, int n)
|
2005-10-01 02:52:55 -04:00
|
|
|
{
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 02:52:55 -04:00
|
|
|
/* dummy function for binding to universal-argument */
|
2005-09-30 19:34:11 -04:00
|
|
|
int unarg(int f, int n)
|
2005-10-01 02:52:55 -04:00
|
|
|
{
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/***** Compiler specific Library functions ****/
|
|
|
|
|
|
|
|
#if RAMSIZE
|
|
|
|
/* These routines will allow me to track memory usage by placing
|
|
|
|
a layer on top of the standard system malloc() and free() calls.
|
|
|
|
with this code defined, the environment variable, $RAM, will
|
|
|
|
report on the number of bytes allocated via malloc.
|
|
|
|
|
|
|
|
with SHOWRAM defined, the number is also posted on the
|
|
|
|
end of the bottom mode line and is updated whenever it is changed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef malloc
|
|
|
|
#undef free
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
char *allocate(nbytes)
|
|
|
|
/* allocate nbytes and track */
|
|
|
|
unsigned nbytes; /* # of bytes to allocate */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
char *mp; /* ptr returned from malloc */
|
2005-05-31 11:50:56 -04:00
|
|
|
char *malloc();
|
|
|
|
|
|
|
|
mp = malloc(nbytes);
|
|
|
|
if (mp) {
|
|
|
|
envram += nbytes;
|
|
|
|
#if RAMSHOW
|
|
|
|
dspram();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
return (mp);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
release(mp)
|
|
|
|
/* release malloced memory and track */
|
|
|
|
char *mp; /* chunk of RAM to release */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
unsigned *lp; /* ptr to the long containing the block size */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
if (mp) {
|
|
|
|
/* update amount of ram currently malloced */
|
2005-09-30 18:26:09 -04:00
|
|
|
lp = ((unsigned *) mp) - 1;
|
|
|
|
envram -= (long) *lp - 2;
|
2005-05-31 11:50:56 -04:00
|
|
|
free(mp);
|
|
|
|
#if RAMSHOW
|
|
|
|
dspram();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if RAMSHOW
|
2005-09-30 18:26:09 -04:00
|
|
|
dspram()
|
|
|
|
{ /* display the amount of RAM currently malloced */
|
2005-05-31 11:50:56 -04:00
|
|
|
char mbuf[20];
|
|
|
|
char *sp;
|
|
|
|
|
|
|
|
TTmove(term.t_nrow - 1, 70);
|
|
|
|
#if COLOR
|
|
|
|
TTforg(7);
|
|
|
|
TTbacg(0);
|
|
|
|
#endif
|
|
|
|
sprintf(mbuf, "[%lu]", envram);
|
|
|
|
sp = &mbuf[0];
|
|
|
|
while (*sp)
|
|
|
|
TTputc(*sp++);
|
|
|
|
TTmove(term.t_nrow, 0);
|
|
|
|
movecursor(term.t_nrow, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* On some primitave operation systems, and when emacs is used as
|
|
|
|
a subprogram to a larger project, emacs needs to de-alloc its
|
|
|
|
own used memory
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if CLEAN
|
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
/*
|
|
|
|
* cexit()
|
|
|
|
*
|
|
|
|
* int status; return status of emacs
|
|
|
|
*/
|
|
|
|
int cexit(int status)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
register BUFFER *bp; /* buffer list pointer */
|
2005-10-01 03:02:32 -04:00
|
|
|
register window_t *wp; /* window list pointer */
|
|
|
|
register window_t *tp; /* temporary window pointer */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* first clean up the windows */
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp) {
|
|
|
|
tp = wp->w_wndp;
|
|
|
|
free(wp);
|
|
|
|
wp = tp;
|
|
|
|
}
|
|
|
|
wheadp = NULL;
|
|
|
|
|
|
|
|
/* then the buffers */
|
|
|
|
bp = bheadp;
|
|
|
|
while (bp) {
|
|
|
|
bp->b_nwnd = 0;
|
|
|
|
bp->b_flag = 0; /* don't say anything about a changed buffer! */
|
|
|
|
zotbuf(bp);
|
|
|
|
bp = bheadp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and the kill buffer */
|
|
|
|
kdelete();
|
|
|
|
|
|
|
|
/* and the video buffers */
|
|
|
|
vtfree();
|
|
|
|
|
|
|
|
/* and now.. we leave [pick the return if we are a subprogram] */
|
|
|
|
#if CALLED
|
|
|
|
eexitflag = TRUE; /* flag a program exit */
|
|
|
|
eexitval = status;
|
2005-09-30 18:26:09 -04:00
|
|
|
return (status);
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
|
|
|
#undef exit
|
|
|
|
exit(status);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|