home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource5
/
331_01
/
se.c
< prev
next >
Wrap
Text File
|
1990-06-12
|
21KB
|
806 lines
/*
HEADER: CUG000.00;
TITLE: SE (nee E) stack editor -- main();
DATE: 05/19/87;
DESCRIPTION: "A full screen editor descended from Gilbert's 'e'(1981)
through Haefner's qed and Tearle's ged. Similar to
Wordstar, with text stack, undo/redo, and other enhancements.
Utilizes large RAM if available, virtual memory text storage
in small systems.";
KEYWORDS: Word processing, e, editor, qed, ged, full screen editor,
text editor, program editor;
SYSTEM: MS-DOS;
FILENAME: SE.C;
SEE-ALSO: CUG133, CUG133, CUG199;
AUTHORS: G. Nigel Gilbert, James W. Haefner, Mel Tearle, G. Osborn;
COMPILERS: Microsoft 4.00;
*/
/* e/qed/ged screen editor
(C) G. Nigel Gilbert, MICROLOGY, 1981
licensed for private non-profitmaking use 1983
August-December 1981
Modified: Aug-Dec 1984: BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
March 1985: BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
May 1986: converted to ged - Mel Tearle
FUNCTIONS: main, initialise, edit, finish, dispose, xit,
askforfile, seldisk
PURPOSE: initialise; process commands;
*/
#include <stdio.h>
#include <ctype.h>
#include <setjmp.h>
#include "ged.h"
int cbreak;
int linel;
int pagingdisk;
main(argc,argv)
int argc;
char **argv;
{
int argn;
int i;
char *dig;
/* --------------------- Default option settings ---------------------*/
initjmp = 1; /* jmp to line 1*/
autoin = YES; /* auto indent [YES/NO]*/
backup = YES; /* make ".BAK" file [YES/NO]*/
ctrl = NO; /* Control characters stripped from input file */
trail = NO; /* leave trailing blanks [YES/NO]*/
charmask = 0xFF; /* allow input ASCII 0x80 to 0xFF */
tabwidth = 8; /* tab stops every n cols [number]*/
fullmem = (long) RAMSLOTS*PAGESIZE/1024;
displaypos = YES; /* display line:column at top of screen*/
blockscroll = YES; /* horizontal scroll whole page, not just current line*/
eofchar = YES; /* write ^Z end of file */
pagingdisk = 0; /* create buffer file on this disk -
set to either 0 (for currently logged-in disk)
or to desired disk letter (eg 'B') */
defext[0] = '\0'; /* default extension (.c and .doc temporarilly hard coded*/
/* ------------------ End of default option settings -------------------- */
inbufp = 0;
rax = 0x30 << 8;
/* syscall is not a library function */
syscall();
if ( ( rax & 0x00ff ) < 2 ) {
error1( "Must use MSDOS vers > 2.0" );
exit(0);
}
filename[0] = name[0] = '\0';
argn = 0;
while ( ++argn < argc )
if ( *argv[argn] == '-' ) {
dig = argv[argn]+1;
switch( toupper(*dig) ) {
case 'A' :
autoin=!autoin;
break;
case 'B' :
backup=!backup;
break;
case 'C' :
ctrl = !ctrl;
break;
case 'D' :
pagingdisk = toupper(*(dig+1));
if ( pagingdisk < 'A' || pagingdisk > 'Z' )
goto argerr;
break;
case 'H' :
blockscroll=!blockscroll;
break;
/* limit amount of RAM that will be allocated. number is in kb */
case 'M' :
i = 0;
while (*++dig)
i = i*10 + *dig - '0';
i = max(i, PAGESIZE * 3/1024);
fullmem = min(fullmem, i);
break;
case 'P':
charmask = 0x7F; /* import Wordstar document mode */
break;
case 'T' :
tabwidth=0;
while (*++dig) tabwidth=tabwidth*10+*dig-'0';
if (tabwidth < 1)
tabwidth = 1;
break;
case 'S' :
trail=!trail;
break;
case 'Z' :
eofchar = !eofchar;
break;
default :
if ( isdigit(*dig) ) {
initjmp = atoi((argv[argn]+1));
break;
}
argerr:
putstr("Illegal option: ");
putstr(argv[argn]);
exit(0);
}
}
else {
strcpy( filename[0] ? name : filename, argv[argn] );
}
ans[0] = patt[0] = opts[0] = '\0';
/* --------- start here ----------- */
/* remember state of ^C abort setting, then turn it off so that ^C can
* be used for cursor control.
*/
rax = 0x3300;
syscall();
cbreak = rdx & 0x00ff;
rax = 0x3301;
rdx = 0;
syscall();
keytranslate();
do {
initialise();
edit();
}
while (YES);
}
/* ---------- end main ------------ */
initialise()
{
int i, warn;
lastl = cursorx = charn = offset = lastoff = 0;
histptr = histcnt = ncommand = 0;
cursory = topline = findir = jmpto = 1;
blocking = isdim = repeat = NO;
replace = warn = NO;
blankedmess = YES;
goteof = YES;
fbuf = &fbuf1;
textbuf = &tbuf1;
rax = 0x19 << 8;
syscall(); /* get current disc */
curdsk = rax & 0xff;
pagingfile[0] = (pagingdisk) ? pagingdisk : ( curdsk+'A' ) ;
strcpy( pagingfile+1, ":e$$$.@@@" );
initvm();
text[0] = '\0';
cline = 1;
inject(0,text); /* create null line 1 */
terminit();
setstatusname();
if ( filename[0] ) {
curson(NO);
cleareop(0);
gotoxy(8,9);
putstr("qed screen editor version ");
putstr(VERSION);
putstr(" MICROLOGY 1983 and JWH 1985");
gotoxy(17,10);
putstr("ged 1.05 for Compaq, etc. - Mel Tearle 1986 ");
gotoxy(17,11);
putstr("Stack Editor version 1.00 G. Osborn 6-12-90");
gotoxy(18,13);
putstr("C Users' Group Public Domain Software");
gotoxy(0,21);
putstr("F1 = help");
/* open a file, if it fails then try again to
* open it using filename plus default extension
* file handle is in textbuf structure.
*/
while ( opentext(filename) == FAIL ) {
askforfile();
if ( !filename[0] ) goto newfile;
}
lastl = 0;
goteof = NO;
if ( name[0] ) {
strcpy(filename,name);
name[0] = '\0';
}
} /* end - if filename */
newfile:
format( filename );
for ( i = lastl; !(goteof); i += 1 )
readtext(i);
fclose(textbuf);
setstatusname();
gettext(1, charn);
if ( initjmp> 2) { /* (2-1) is a bad jump from line 1 */
jumpline(initjmp-cline); /* not possible to do init jump to 2*/
initjmp = 0;
}
linel = lastl;
} /* end - initialise() */
/* command processor */
edit()
{
unsigned char inkey();
unsigned char getkey();
unsigned char c;
unsigned char oldcrx, inc;
int i, j, k, to;
jmp_buf env; /* define data storage for setjmp (Microsoft) */
setjmp(env);
putstatusline(linel); /* show the flie size until editing starts */
displine = cline;
blankedmess = NO;
calp(); /* initialization call */
i = displaypos;
displaypos = NO;
putpage();
displaypos = i;
curson(YES);
linem1 = 0;
linem2 = 0;
linem3 = 0;
lastc = 0;
/* command processing loop */
nextchar:;
goodline = cline; /* restore environment */
c = getkey();
ncommand++;
storehist = YES;
switch(c) {
case UPPAGE :
case DOWNPAGE :
if (c == UPPAGE)
movepage(-1);
else
movepage(0);
/* don't let inpu