2013-10-11 02:09:29 -04:00
|
|
|
/* main.c -- */
|
|
|
|
|
|
|
|
#define CLRMSG 0 /* space clears the message line with no insert */
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/*
|
2010-08-12 23:19:22 -04:00
|
|
|
* main.c
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
* uEmacs/PK 4.0
|
|
|
|
*
|
2010-08-12 23:19:22 -04:00
|
|
|
* Based on:
|
2005-05-31 11:50:56 -04:00
|
|
|
*
|
|
|
|
* MicroEMACS 3.9
|
2010-08-12 23:19:22 -04:00
|
|
|
* Written by Dave G. Conroy.
|
2010-09-13 05:18:00 -04:00
|
|
|
* Substantially modified by Daniel M. Lawrence
|
2010-08-12 23:19:22 -04:00
|
|
|
* Modified by Petri Kutvonen
|
|
|
|
*
|
|
|
|
* MicroEMACS 3.9 (c) Copyright 1987 by Daniel M. Lawrence
|
2005-05-31 11:50:56 -04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2013-04-30 21:21:16 -04:00
|
|
|
* This modified version is now called uEmacs/rf.
|
|
|
|
*
|
|
|
|
* 4.1 Renaud Fivet, 1-May-13
|
|
|
|
*
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
|
|
|
|
2010-08-12 23:19:22 -04:00
|
|
|
#include <stdio.h>
|
2013-10-08 21:43:15 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-09 02:56:43 -04:00
|
|
|
#include "estruct.h" /* Global structures and defines. */
|
|
|
|
#if UNIX
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
2013-05-30 03:05:19 -04:00
|
|
|
#include "basic.h"
|
|
|
|
#include "bind.h"
|
2013-06-04 23:48:40 -04:00
|
|
|
#include "bindable.h"
|
2013-05-30 03:05:19 -04:00
|
|
|
#include "buffer.h"
|
2013-06-05 21:28:34 -04:00
|
|
|
#include "display.h"
|
2013-05-30 03:05:19 -04:00
|
|
|
#include "eval.h"
|
2013-06-03 23:52:28 -04:00
|
|
|
#include "execute.h"
|
2013-05-30 03:05:19 -04:00
|
|
|
#include "file.h"
|
2013-06-05 21:28:34 -04:00
|
|
|
#include "input.h"
|
2013-06-01 01:42:09 -04:00
|
|
|
#include "lock.h"
|
2013-06-14 05:35:35 -04:00
|
|
|
#include "log.h"
|
2013-05-30 03:05:19 -04:00
|
|
|
#include "random.h"
|
|
|
|
#include "search.h"
|
2013-09-25 09:45:05 -04:00
|
|
|
#include "terminal.h"
|
2013-06-05 21:28:34 -04:00
|
|
|
#include "termio.h"
|
|
|
|
#include "version.h"
|
2013-09-20 06:10:30 -04:00
|
|
|
#include "window.h"
|
2013-05-30 03:05:19 -04:00
|
|
|
|
2010-08-12 23:19:22 -04:00
|
|
|
/* For MSDOS, increase the default stack space. */
|
|
|
|
#if MSDOS & TURBO
|
|
|
|
#if PKCODE
|
2005-05-31 11:50:56 -04:00
|
|
|
extern unsigned _stklen = 20000;
|
|
|
|
#else
|
|
|
|
extern unsigned _stklen = 32766;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2010-08-12 23:19:22 -04:00
|
|
|
#if UNIX
|
2013-06-04 23:48:40 -04:00
|
|
|
static void emergencyexit(int signr)
|
|
|
|
{
|
|
|
|
quickexit(FALSE, 0);
|
|
|
|
quit(TRUE, 0);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
2013-05-31 23:18:29 -04:00
|
|
|
static void edinit( char *bname) ;
|
|
|
|
|
2013-04-30 21:21:16 -04:00
|
|
|
static void version( void) {
|
2013-05-16 22:34:01 -04:00
|
|
|
fputs( PROGRAM_NAME_LONG " version " VERSION "\n", stdout) ;
|
2013-04-30 21:21:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void usage( void) {
|
2013-06-07 02:00:56 -04:00
|
|
|
fputs( "Usage: " PROGRAM_NAME " [OPTION].. [FILE]..\n\n"
|
|
|
|
" + start at the end of file\n"
|
|
|
|
" +<n> start at line <n>\n"
|
|
|
|
" --help display this help and exit\n"
|
|
|
|
" --version output version information and exit\n"
|
2013-06-07 22:23:55 -04:00
|
|
|
" @cmdfile execute command file\n"
|
2013-06-07 02:00:56 -04:00
|
|
|
" -a|A process error file\n"
|
|
|
|
" -e|E edit file\n"
|
|
|
|
" -g|G<n> go to line <n>\n"
|
2013-06-10 01:30:06 -04:00
|
|
|
#if CRYPT
|
2013-06-07 02:00:56 -04:00
|
|
|
" -k|K<key> use code key\n"
|
2013-06-10 01:30:06 -04:00
|
|
|
#endif
|
2013-06-07 02:00:56 -04:00
|
|
|
" -r|R restrictive use\n"
|
|
|
|
" -s|S<string> search string\n"
|
|
|
|
" -v|V view file\n"
|
|
|
|
, stdout) ;
|
2010-08-14 23:11:27 -04:00
|
|
|
}
|
|
|
|
|
2013-05-16 22:34:01 -04:00
|
|
|
|
2005-09-30 19:34:11 -04:00
|
|
|
int main(int argc, char **argv)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
int c = -1; /* command character */
|
|
|
|
int f; /* default flag */
|
|
|
|
int n; /* numeric repeat count */
|
|
|
|
int mflag; /* negative flag on repeat */
|
|
|
|
struct buffer *bp; /* temp buffer pointer */
|
|
|
|
int firstfile; /* first file flag */
|
|
|
|
int carg; /* current arg to scan */
|
|
|
|
int startflag; /* startup executed flag */
|
2010-02-15 21:09:42 -05:00
|
|
|
struct buffer *firstbp = NULL; /* ptr to first buffer in cmd line */
|
2005-09-30 18:26:09 -04:00
|
|
|
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? */
|
2010-08-28 18:38:52 -04:00
|
|
|
int gline = 0; /* if so, what line? */
|
2005-09-30 18:26:09 -04:00
|
|
|
int searchflag; /* Do we need to search at start? */
|
|
|
|
int saveflag; /* temp store for lastflag */
|
|
|
|
int errflag; /* C error processing? */
|
2014-05-30 06:08:58 -04:00
|
|
|
bname_t bname ; /* 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? */
|
2014-06-02 02:22:05 -04:00
|
|
|
ekey_t ekey ; /* startup encryption key */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
int newc;
|
|
|
|
|
|
|
|
#if PKCODE & VMS
|
2010-08-14 23:11:27 -04:00
|
|
|
(void) umask(-1); /* Use old protection (this is at wrong place). */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if PKCODE & BSD
|
2010-08-14 23:11:27 -04:00
|
|
|
sleep(1); /* Time for window manager. */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if UNIX
|
|
|
|
#ifdef SIGWINCH
|
|
|
|
signal(SIGWINCH, sizesignal);
|
|
|
|
#endif
|
|
|
|
#endif
|
2013-04-30 21:21:16 -04:00
|
|
|
if( argc == 2) {
|
|
|
|
if( strcmp( argv[ 1], "--help") == 0) {
|
|
|
|
usage() ;
|
|
|
|
exit( EXIT_SUCCESS) ;
|
2010-08-14 23:11:27 -04:00
|
|
|
}
|
2013-04-30 21:21:16 -04:00
|
|
|
|
|
|
|
if( strcmp( argv[ 1], "--version") == 0) {
|
|
|
|
version() ;
|
|
|
|
exit( EXIT_SUCCESS) ;
|
2010-08-12 23:19:22 -04:00
|
|
|
}
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2010-08-14 23:11:27 -04:00
|
|
|
/* Initialize the editor. */
|
2005-09-30 18:26:09 -04:00
|
|
|
vtinit(); /* Display */
|
2015-01-21 08:30:01 -05:00
|
|
|
writefmt = mlwrite ;
|
2005-09-30 18:26:09 -04:00
|
|
|
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
|
|
|
|
|
2015-01-23 09:13:21 -05:00
|
|
|
/* Insure screen is initialized before startup and goto/search */
|
|
|
|
update( FALSE) ;
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/* 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;
|
2014-06-02 02:22:05 -04:00
|
|
|
strncpy( ekey, &argv[ carg][ 2], sizeof ekey - 1) ;
|
2014-05-27 05:28:57 -04:00
|
|
|
ekey[ sizeof ekey - 1] = 0 ;
|
2005-09-30 18:26:09 -04:00
|
|
|
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;
|
2014-06-02 03:16:18 -04:00
|
|
|
strncpy( pat, &argv[ carg][ 2], sizeof pat - 1) ;
|
|
|
|
pat[ sizeof pat -1] = 0 ;
|
2005-09-30 18:26:09 -04:00
|
|
|
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);
|
2014-05-30 03:27:56 -04:00
|
|
|
strncpy( bp->b_fname, argv[ carg], sizeof bp->b_fname - 1) ; /* max filename length limited to NFILEN - 1 (79) */
|
|
|
|
bp->b_fname[ sizeof bp->b_fname - 1] = 0 ;
|
2005-05-31 11:50:56 -04:00
|
|
|
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;
|
2014-06-02 02:22:05 -04:00
|
|
|
strncpy( bp->b_key, ekey, sizeof ekey) ;
|
2013-06-10 05:03:32 -04:00
|
|
|
cryptbufferkey( bp) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if UNIX
|
2014-06-18 02:59:40 -04:00
|
|
|
#ifdef SIGHUP
|
2005-09-30 18:26:09 -04:00
|
|
|
signal(SIGHUP, emergencyexit);
|
2014-06-18 02:59:40 -04:00
|
|
|
#endif
|
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);
|
2015-01-10 03:23:19 -05:00
|
|
|
if (firstfile == FALSE && readfirst_f()) {
|
2005-05-31 11:50:56 -04:00
|
|
|
swbuffer(firstbp);
|
|
|
|
zotbuf(bp);
|
|
|
|
} else
|
|
|
|
bp->b_mode |= gmode;
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
/* Deal with startup gotos and searches */
|
2015-01-23 09:13:21 -05:00
|
|
|
if( gotoflag && searchflag)
|
2015-01-21 08:30:01 -05:00
|
|
|
writestr( "(Can not search and goto at the same time!)") ;
|
2015-01-23 09:13:21 -05:00
|
|
|
else if( gotoflag) {
|
|
|
|
if( gotoline( TRUE, gline) == FALSE)
|
2015-01-21 08:30:01 -05:00
|
|
|
writestr( "(Bogus goto argument)") ;
|
2015-01-23 09:13:21 -05:00
|
|
|
} else if( searchflag)
|
|
|
|
if( forwhunt( FALSE, 0))
|
|
|
|
writefmt( "Found on line %d", getcline()) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2010-08-29 22:28:34 -04:00
|
|
|
/* Setup to process commands. */
|
|
|
|
lastflag = 0; /* Fake last flags. */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
loop:
|
2010-08-29 22:28:34 -04:00
|
|
|
/* 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;
|
|
|
|
|
2010-08-29 22:28:34 -04:00
|
|
|
#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 - */
|
2015-01-21 08:30:01 -05:00
|
|
|
writestr( "Arg:") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
else
|
2015-01-21 08:30:01 -05:00
|
|
|
writefmt( "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. */
|
2015-01-21 08:30:01 -05:00
|
|
|
writestr( "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';
|
|
|
|
}
|
2015-01-21 08:30:01 -05:00
|
|
|
writefmt( "Arg: %d", (mflag >= 0) ? n : (n ? -n : -1)) ;
|
2005-09-30 18:26:09 -04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-05-31 23:18:29 -04:00
|
|
|
static void edinit(char *bname)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
struct buffer *bp;
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *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 */
|
2010-08-01 17:37:28 -04:00
|
|
|
wp = (struct window *)malloc(sizeof(struct window)); /* 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
|
|
|
}
|
|
|
|
|
|
|
|
/***** 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.
|
|
|
|
*/
|
|
|
|
|
2013-10-11 03:36:36 -04:00
|
|
|
static void dspram( void) ;
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
#undef malloc
|
|
|
|
#undef free
|
2013-10-11 03:36:36 -04:00
|
|
|
#if 0
|
2005-09-30 18:26:09 -04:00
|
|
|
char *allocate(nbytes)
|
|
|
|
/* allocate nbytes and track */
|
|
|
|
unsigned nbytes; /* # of bytes to allocate */
|
2013-10-11 03:36:36 -04:00
|
|
|
#endif
|
|
|
|
void *allocate( size_t nbytes)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
char *mp; /* ptr returned from malloc */
|
2013-10-11 03:36:36 -04:00
|
|
|
/* char *malloc(); */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
mp = malloc(nbytes);
|
|
|
|
if (mp) {
|
|
|
|
envram += nbytes;
|
|
|
|
#if RAMSHOW
|
|
|
|
dspram();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-08-29 06:03:55 -04:00
|
|
|
return mp;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2013-10-11 03:36:36 -04:00
|
|
|
#if 0
|
2005-09-30 18:26:09 -04:00
|
|
|
release(mp)
|
|
|
|
/* release malloced memory and track */
|
|
|
|
char *mp; /* chunk of RAM to release */
|
2013-10-11 03:36:36 -04:00
|
|
|
#endif
|
|
|
|
void release( void *mp)
|
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
|
2013-10-11 03:36:36 -04:00
|
|
|
static void dspram( void)
|
2005-09-30 18:26:09 -04:00
|
|
|
{ /* 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
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
struct buffer *bp; /* buffer list pointer */
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *wp; /* window list pointer */
|
|
|
|
struct window *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();
|
|
|
|
|
|
|
|
#undef exit
|
|
|
|
exit(status);
|
|
|
|
}
|
|
|
|
#endif
|