home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource3
/
199_01
/
ged.c
< prev
next >
Wrap
Text File
|
1987-12-17
|
19KB
|
754 lines
/*
Header: CUG199;
Title: Module 0 of ged editor;
Last Updated: 12/06/87;
Description: "PURPOSE: initialise; process commands";
Keywords: e, editor, qed, ged, DeSmet, MSDOS;
Filename: ged.c;
Warnings: "O file must be present during link of ged";
Authors: G. Nigel Gilbert, James W. Haefner, and Mel Tearle;
Compilers: DeSmet 3.0;
References:
Endref;
*/
/*
e/qed/ged screen editor
(C) G. Nigel Gilbert, MICROLOGY, 1981 - 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: qed converted to ged (Mel Tearle)
August 1987: ged converted to MSC 4.0 (Mel Tearle)
File: ged.c
Functions: main, initialise, edit, finish, dispose, xit,
askforfile, seldisk
*/
#include "ged.h"
#ifdef MSC
jmp_buf mark;
#endif
void main(argc,argv)
char **argv;
int argc;
{
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] */
/***********************************************************************/
/*** DON'T CHANGE *** DON'T CHANGE *** DON'T CHANGE *** DON'T CHANGE ***/
/***********************************************************************/
readall = YES; /* read as much text as possible up to memory */
/***********************************************************************/
/*** DON'T CHANGE *** DON'T CHANGE *** DON'T CHANGE *** DON'T CHANGE ***/
/***********************************************************************/
trail = NO; /* don't strip trailing blanks [YES/NO] */
tabwidth = 4; /* tab stops every n cols [number] */
blockscroll = YES; /* don't horizontal scroll whole page, just current line */
pagingdisk = 0; /* create buffer file on this disk -
set to either 0 (for currently logged-in disk)
or to desired disk letter (eg 'B') */
rtmarg = REFORM; /* default for reformat only - no wordwrap */
defext[0] = '\0'; /* default extension */
window = WINDOW;
/* ------------------ End of default option settings -------------------- */
if ( ( _os( VERNO, 0 ) & 0x00ff ) < 2 ) {
putstr( "Ged Error: Must use MSDOS vers 2.x with 'ged'" );
exit(0);
}
inbufp = 0;
filename[0] = name[0] = '\0';
argn = 0;
while ( ++argn < argc )
if ( *argv[argn] == '-' ) {
dig = argv[argn]+1;
switch( toupper(*dig) ) {
case 'A' :
autoin = ( char ) !autoin;
break;
case 'B' :
backup = ( char ) !backup;
break;
case 'Q' :
readall = ( char ) !readall;
break;
case 'H' :
blockscroll = ( char ) !blockscroll;
break;
case 'T' :
tabwidth = 0;
while (*++dig) tabwidth = tabwidth*10+*dig-'0';
break;
case 'S' :
trail = ( char ) !trail;
break;
case 'D' :
pagingdisk = toupper(*(dig+1));
if ( pagingdisk >= 'A' && pagingdisk <= 'P' )
break;
default :
if ( isdigit( *dig ) ) {
initjmp = atoi( (argv[argn]+1 ) );
break;
}
putstr( "Ged Error: Illegal option: " );
putstr( argv[argn] );
exit(1);
}
}
else strcpy( filename[0] ? name : filename, argv[argn] );
ans[0] = patt[0] = changeto[0] = opts[0] = '\0';
/* ---------------------- start here -------------------- */
keytranslate();
do {
initialise();
edit();
}
while (YES);
}
/* ----------------------- end main ------------------- */
void initialise()
{
int i;
cursorx = charn = offset = lastoff = from = 0;
histptr = histcnt = ncommand = to = 0;
cursory = cline = topline = lastread = lastl = findir = jmpto = 1;
changed = blocking = isdim = repeat = NO;
replace = blankedmess = NO;
screen = NO;
if ( overtype ) ; else NO;
altered = goteof = YES;
errmess = '\0';
lastgraph = NULL;
pfirst = -100; text[0] = '\0';
curdsk = _os( CURDSK, 0 );
initvm();
scr_setup();
scr_cursoff();
if ( filename[0] ) {
scr_clr();
scr_putstr( 11, 10,
"╔═════════════════════════════════════════════════════════╗", RSFW );
scr_putstr( 11, 11,
"║ qed editor version 4.6b MICROLOGY 1983 - JWH 1985 ║", RSFW );
scr_putstr( 11, 12,
"║ m/ged version 2.00 Mel Tearle 1987 ║", RSFW );
scr_putstr( 11, 13,
"║ » ged - 12/06/87 « ║", RSFW );
scr_putstr( 11, 14,
"╚═════════════════════════════════════════════════════════╝", RSFW );
scr_delete( 0,24 );
/* open a file, if it fails then try again to
* open it using filename plus default extension
*/
while ( opentext( filename ) == FAIL ) {
askforfile();
if ( !filename[0] ) goto newfile;
}
lastl = UNKNOWN; lastread = 0; goteof = NO;
if ( name[0] ) {
strcpy( filename, name );
name[0] = '\0';
}
} /* end - if filename */
newfile:
errmess = NULL;
format( filename );
/* read as much text to fill memory or end of file
*/
if ( readall )
for ( i = 1; (! ( usage[slotsinmem-1] ) && ( !( goteof ) ) ); i += 100 )
readtext(i);
gettext(1);
scr_clr();
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;
}
else
putpage();
setstatusname();
putstatusline( cline );
show_fkeys();
} /* end - initialise */
/* command processor
*/
void edit()
{
unsigned char c;
int inc, i, to, oldcrx;
#ifdef MSC
setjmp( mark );
#else
setjmp(0);
#endif
while ( YES ) {
goodline = cline; /* restore environment */
storehist = YES; /* makesure we're saving history */
unmess(); /* check if topline has changed */
if ( blankedmess ) {
putstatusline( cline );
blankedmess = NO;
}
else
putlineno( cline );
resetcursor();
scr_curson();
c = getkey();
if ( ( ncommand++ % 32 ) == 0 ) show_time();
if ( errmess != NULL ) errmess = NULL;
switch(c) {
case UPPAGE :
movepage(-1);
break;
case DOWNPAGE :
movepage(0);
break;
case DOWNKEY :
moveline(1);
break;
case UPKEY :
moveline(-1);
break;
case SCRLDNKEY :
oldcrx = cursorx;
to = plast - cline;
moveline(to);
inc = ( ( moveline(1) == YES ) ? 1 : 0 );
cursorx = oldcrx;
moveline( ( ( cline - to ) <= pfirst )
? ( topline - cursory ) : ( -to - inc ) );
break;
case SCRLUPKEY :
oldcrx = cursorx; /* save current cursorx */
to = topline - cursory;
moveline(to);
inc = ( ( moveline(-1) == YES ) ? 1 : 0 );
cursorx = oldcrx;
moveline( ( ( cline - to ) >= plast )
? ( SHEIGHT - cursory ) : ( -to + inc ) );
break;
case DELLNKEY :
changed = YES;
text[0] = '\0';
crdelete( ( cline == lastl ? -1 : 0 ) );
break;
case BLOCKKEY :
switch ( to = blockops() ) {
case YES : return;
/* break; */
case 'x' :
case 'q' : if