/* ----------------------- ue15.c ------------------------- */

#include "uedit.h"

#asm
  XREF  _msgList
  XREF  _AllocMem
  XREF  _args
  XREF  _buf
  XREF  _bufPtrArgs
  XREF  _canChange
  XREF  _charMappings
  XREF  _Close
  XREF  _CloseDevice
  XREF  _columnar
  XREF  _curCol
  XREF  _curSplit
  XREF  _curTable
  XREF  _DeleteExtIO
  XREF  _DeletePort
  XREF  _display
  XREF  _displayFlag
  XREF  _DoIO
  XREF  _doSaving
  XREF  _eol
  XREF  _Examine
  XREF  _fastB
  XREF  _fastP
  XREF  _fB
  XREF  _fdprt
  XREF  _findFile
  XREF  _fixSOF
  XREF  _fixString
  XREF  _fP
  XREF  _freeBuf
  XREF  _FreeMem
  XREF  _gB
  XREF  _getBP
  XREF  _getBuf
  XREF  _GetMsg
  XREF  _gP
  XREF  _incFast
  XREF  _Lock
  XREF  _longPtrArgs
  XREF  _memoryMsg
  XREF  _movdat
  XREF  _newBlock
  XREF  _newBuf
  XREF  _noMemory
  XREF  _oneMsg
  XREF  _openPrt
  XREF  _packBuf
  XREF  _passiveMsg
  XREF  _pop
  XREF  _popFast
  XREF  _prefPrint
  XREF  _printBuf
  XREF  _printByte
  XREF  _printChoice
  XREF  _printLen
  XREF  _prints
  XREF  _printTabs
  XREF  _prtMsg
  XREF  _prtOpen
  XREF  _prtPort
  XREF  _ptrArgs
  XREF  _push
  XREF  _pushFast
  XREF  _Read
  XREF  _readFile
  XREF  _safeMem
  XREF  _saveBuf
  XREF  _saveFd
  XREF  _saves
  XREF  _Seek
  XREF  _SetComment
  XREF  _SetProtection
  XREF  _setTitle
  XREF  _slowPrint
  XREF  _splitBlock
  XREF  _splitFlag
  XREF  _sStack
  XREF  _startFile
  XREF  _stop
  XREF  _stopPause
  XREF  _stopSave
  XREF  _strcmp
  XREF  _strcpy
  XREF  _strlen
  XREF  _switchFast
  XREF  _tabCalc
  XREF  _tiny
  XREF  _toLower
  XREF  _UnLock
  XREF  _uport
  XREF  _Write
  XREF  _yesNo
#endasm

/* =========== spell checker ========== */

#ifdef ISSPELL

#define ADDSTAT 28

static UCHAR	*fspell = NULL;
static UCHAR	*statt = NULL;
static long	tbsize,udsize = 0L;
static unsigned short *ctable = NULL;
static unsigned long  *tb,*tbb = NULL;
static short	inram = 0;

static short	llen;
static UCHAR	*pp;
static UCHAR	*q,*pbuf,*seekBuf;

static struct CB  *suppBuf;

static long	nextlloc,lloc;

static short	numWords,listLen;
static UCHAR	badWord[36],tryWord[36],*wordBlock;
static UCHAR	*alpha = (UCHAR *)"abcdefghijklmnopqrstuvwxyz'";

/* -----------------------------------
FspellerUp()
{
	return( (tb==NULL) ? FALSE : TRUE);
}
----------------- */

#asm
  XREF  _inram
  XREF  _llen
  XREF  _lloc
  XREF  _seekBuf
  XREF  _nextlloc

	xdef  _FspellerUp
_FspellerUp:
	move.l  _tb,d0
	beq FUP
	moveq	#1,d0
FUP:
	rts
#endasm

Fspell()
{
register struct CB  *bufPtr;
register short  rtn,bufnum;
UCHAR	spellBuf[256];

	rtn = FALSE;
	bufPtr = bufPtrArgs[1];
	if (bufPtr==NULL || tb==NULL) goto RTN;

	if (args[2]!=buf_) suppBuf = NULL;
	else suppBuf = bufPtrArgs[2];

	pushFast(bufPtr,&(bufPtr->Block),&(bufPtr->Ptr));
	displayFlag |= SHOWCURSOR_; /* splitFlag(bufPtr->BufNum, SHOWCURSOR_); */

	seekBuf = spellBuf;

AGAIN:
	rtn = lookup(0);
	if (!rtn) {
		rtn = lookupSupp();
		if (rtn) goto AGAIN;
	}

	if (!rtn && inram && !stopPause && args[0]==buf_) {
		bufnum = longArgs[0];
		takeFast();
		display();
		saveFast();
		if (fixBuf(bufnum)) getChoices(buf[bufnum]);
		unsaveFast();
	}

	takeFast();
	popFast();
RTN:
	return(rtn);
}

void cvtWord(register UCHAR *q)
{
	while (*q) {
		if (*q==1) *q=39;
		else *q += ('A' - 2);
		q++;
	}
}

lookupSupp()
{
register UCHAR  	*b,*c;
register UCHAR  	c0,cc0,c1,cc1;
struct DB			*sB;
UCHAR				*sP;
UCHAR				newWord[36];

	if (suppBuf==NULL) return(FALSE);

	/*  ASSUME ALPHABETIC list.  make all upper case.  */
	c = z;
	b = newWord;
	strcpy(b,badWord);

	cvtWord(b);
	c0 = *b;
	c1 = b[1];

	sP = fastP;
	sB = fastB;
	fastB = suppBuf->NextBlock;
	fastP = fastB->Data;
	while (1) {
		if (!skipSpace()) goto BRTN;
		getWord(FALSE);
		cc0 = *c;
		cc1 = c[1];
		if (cc0<c0) continue;
		if (cc0>c0) goto BRTN;
		if (cc1<c1) continue;
		if (cc1>c1) goto BRTN;
		if (strcmp(c,b)==0) break;
	}
	fastB = sB; fastP = sP;
	return(TRUE);
BRTN:
	fastB = sB; fastP = sP;
	return(FALSE);
}

storeWord(UCHAR wordList[21][36])
{
register UCHAR  *q;
register UCHAR  *p;
register short  i,wds,newlen;
UCHAR				newWord[36];

	q = newWord;
	p = tryWord;
	newlen = 1;
	wds = numWords;
	while (1) {
		i = *p;
		if (i==EOFILE) break;
		if (i) {
			*(q++) = i;
			newlen++;
		}
		p++;
	}
	q[0] = ' ';
	q[1] = 0x00;
	q = newWord;
	i = 0;
	while (1) {
		if (i>=wds) break;
		if (strcmp(q,wordList[i])==0) return(1);
		i++;
	}
	i = newlen + listLen;
	if (i<(DATASIZE-1)) {
		strcpy(wordList[wds],q);
		p = wordBlock;
		strcat(p,q);
		listLen = i;
		oneMsg(p);
		numWords = ++wds;
	}
	if (wds>=21 || i>=(DATASIZE-1)) return(0);
	return(1);
}

getChoices(struct CB *bufPtr)
{
register UCHAR  *p,*q,j,i;
register short  badlen;
register long	endpoint;
long			tail;
UCHAR			wordList[21][36];

	bufPtr->Flags |= NEEDPACK;
	wordBlock = bufPtr->NextBlock->Data;
	wordBlock[0] = 0x00;
	numWords = 0;
	listLen = 0;

	q = badWord;
	cvtWord(q);
	badlen = (short)strlen(q);
	if (badlen<2) goto GETOUT;

	p = tryWord;
	strcpy(p,q);
	p[badlen] = EOFILE;
	storeWord(wordList);			/* store the bad word as 1st */
	toLower(p);
	tail = (long)p + badlen - 1;
	endpoint = (long)p;

	p = (UCHAR *)tail;
	q = p - 1;
	while (1) { 										/* reversal */
		j = *p;
		i = *q;
		if (i!=j) {
			*p = i; *q = j;
			if ((lookup(1) || lookupSupp()) && !storeWord(wordList)) goto GETOUT;
			if (stopPause) goto GETOUT;
			*q = i; *p = j;
		}
		if (q==(UCHAR *)endpoint) break;
		p = q;
		q--;
	}

	if(badlen>2) {
		p = (UCHAR *)tail;
		q = tryWord;
		while (1) { 									/* omission */
			j = *p;
			*p = 0x00;
			if ((lookup(1) || lookupSupp()) && !storeWord(wordList)) goto GETOUT;
			if (stopPause) goto GETOUT;
			*p = j;
			if (p==q) break;
			p--;
		}
	}
	p = (UCHAR *)tail;
	while (1) { 										/* passive ? */
		j = *p;
		q = alpha;
		while (1) {
			i = *q;
			if (i==0) break;
			*p = i;
			if (i!=j) {
				if ((lookup(1) || lookupSupp()) && !storeWord(wordList)) goto GETOUT;
				if (stopPause) goto GETOUT;
if (!execLearn && FinputWaiting()) goto GETOUT;
			}
			q++;
		}
		*p = j;
		if (p==(UCHAR *)endpoint) break;
		p--;
	}
	p = (UCHAR *)tail+ 1;
	p[1] = EOFILE;
	while (1) { 										/* active ? */
		q = alpha;
		while (1) {
			i = *q;
			if (i==0) break;
			*p = i;
			if ((lookup(1) || lookupSupp()) && !storeWord(wordList)) goto GETOUT;
			if (stopPause) goto GETOUT;
			if (!execLearn && FinputWaiting()) goto GETOUT;
			q++;
		}
		if (p==(UCHAR *)endpoint) break;
		*p = *(p-1);
		p--;
	}

GETOUT:
	wordBlock[listLen] = EOFILE;
}

#ifdef USEC

lookup(short flag)
{
register short  	c1,c2,c3,n;
register UCHAR  	*p;
register unsigned long  *s;

	if (flag) fastP = tryWord;
	while (1) { 					/* look up the words, MAKE CAPS */
    	if (msgList->lh_Head->ln_Succ) {
			if (stop()) goto BADRTN;
		}
		c2 = 0;
		n = flag;
		p = badWord;
		c1 = *fastP;
		while (1) {
			if (c1 == EOFILE) break;
			if (c1>='a' && c1<='z') { c1 -= ('a' - 2); goto TAKE1; }
			if (c1>='A' && c1<='Z') { c1 -= ('A' - 2); goto TAKE1; }
			if (c1==39) { c1 = 1; goto TAKE1; }
			if (c2) break;
			goto BUMP1;

TAKE1:  	*(p++) = c1;
			if (++c2>=32) break;
BUMP1:
			fastP++;
			c1 = *fastP;
			if (c1<EOFILE) {
				if (n) goto BUMP1;
				fastP--;
				c1 = *incFast();
			}
		}
		*(p++) = 0x00;
		if (c2==0) { if (c1==EOFILE) return(TRUE); }
		if (c2==1) continue;
		llen = c2;
		p = badWord;
		c1 = *(p++);
		c2 = *(p++);
		c3 = *(p++);

		c2 += ((c1 << 5) - (c1 << 2));  				/* c1 * 28 */
		n = *(ctable + c2); 	/* c2 is NONZERO here for sure !!! */
		if (n==0) goto BADRTN;
		s = tbb + n - 1;
		n =  *s & 0x0700;
		if (c3==0) {
			if (!(n & 0x0400)) goto BADRTN;
			goto FOUND;
		}
		while (1) {
			c1 = *s & 0xff;

			if (c1<c3) goto BUMPS;
			if (c1==c3) {
				lloc =  (*s >> 11L);
				if ((n & 0x0200) && llen==3) goto FOUND;
				goto LOOKUP;
			}
			goto BADRTN;
BUMPS:
			s++;
			n =  *s & 0x0700;
			if (n & 0x0100) goto BADRTN;			/* end of table */
		}
FOUND:
		continue;									/* get next word */
LOOKUP: 										/* must look it up */

		if (!inram) {
			Seek((BPTR)fspell,lloc,(long)OFFSET_BEGINNING);
			pbuf = seekBuf;
			llen = Read((BPTR)fspell,pbuf,64L) + 1;
			if (llen<2) goto BADRTN;
		} else {
			pbuf = fspell + lloc;
		}
		s++;
		nextlloc = (*s >> 11L);
		n = 0;  					/* don't skip to next null */
		pp = p;

SEARCH:
		if (lloc>=nextlloc) goto BADRTN;
		if (!inram) {
			if (--llen<=0) {
				pbuf = seekBuf;
				llen = Read((BPTR)fspell,pbuf,256L);
				if (llen<1) goto BADRTN;
			}
		}
		lloc++;
		c1 = *(pbuf++);
		c2 = 256;
		if (c1>=ADDSTAT) {
			c1 -= ADDSTAT;
			q = statt + (c1 << 1);
			c1 = *(q++);
			c2 = *q;
		}
		if (n) {								/* skipping to next word */
			if (c1==0 || c2==0) { p = pp; n = 0; }  /* stop skipping */
			goto SEARCH;
		}
		c3 = *(p++);
		if (c1<c3) {
			if (c1==0 || c2==0) { p = pp; goto SEARCH; }
			n = 1;
			goto SEARCH;
		}													/* skip fwd */
		if (c1==c3) {
			if (c3==0) continue;						/* found it */
			if (c2 != 256) {
				c3 = *(p++);
				if (c2<c3) {
					if (c2==0) { p = pp; goto SEARCH; }
					n = 1;
					goto SEARCH;
				}
				if (c2==c3) {
					if (c2==0) continue;				/* found it */
					goto SEARCH;					/* still matching */
				}
				goto BADRTN;						/* missed it */
			}
			goto SEARCH;						/* continue matching */
		}
		goto BADRTN;
	}
BADRTN:
	return(FALSE);
}

#endif

#ifndef USEC
#asm

	xdef  _lookup
_lookup:
	movem.l d2-d7/a2/a3,-(sp)
	moveq	#0,d4
	moveq	#0,d5
	moveq	#0,d6
	tst.w	36(sp)  	; if (flag) fastP = tryWord;
	beq SPLABEL6
	lea _tryWord,a0
	move.l  a0,_fastP
SPLABEL6:					;while (1) {
	
    move.l  _msgList,a0
    move.l  (a0),a0
    tst.l   (a0)
    beq SPLABEL8
    jsr _stop
    bne SPLABEL9

SPLABEL8:					;}
	moveq	#0,d5			;c2 = 0;
	move.w  36(sp),d7		;n = flag;
	lea _badWord,a2 	;p = badWord;
	move.l  _fastP,a0		;c1 = *fastP;
	moveq	#0,d4
	move.b  (a0),d4
SPLABEL10:  			;while (1) {
	cmp.w	#3,d4			;if (c1 == EOFILE) break;
	beq SPLABEL11
	cmp.w	#97,d4  ;if (c1>='a' && c1<='z') { c1 -= ('a' - 2); goto TAK
	blt SPLABEL12
	cmp.w	#122,d4
	bgt SPLABEL12
	sub.b	#95,d4
	bra SPLABEL13			;
SPLABEL12:
	cmp.w	#65,d4  ;if (c1>='A' && c1<='Z') { c1 -= ('A' - 2); goto TAK
	blt SPLABEL14
	cmp.w	#90,d4
	bgt SPLABEL14
	sub.b	#63,d4
	bra SPLABEL13			;
SPLABEL14:
	cmp.w	#39,d4  	;if (c1==39) { c1 = 1; goto TAKE1; }
	bne SPLABEL15
	moveq	#1,d4
	bra SPLABEL13
SPLABEL15:
	tst.w	d5
	bne SPLABEL11			;if (c2) break;
	bra SPLABEL16			;goto BUMP1;
SPLABEL13:  			;TAKE1:
	move.b  d4,(a2)+		;*(p++) = c1;

	addq.w  #1,d5			;if (++c2>=32) break;
	cmp.w	#32,d5
	bge SPLABEL11
SPLABEL16:  			;BUMP1:
	move.l  _fastP,a0		;fastP++;
	addq.w  #1,a0
	move.l  a0,_fastP
	moveq	#0,d4
	move.b  (a0),d4 	;c1 = *fastP;

	cmp.w	#3,d4			;if (c1<EOFILE) {
	bge SPLABEL10
	tst.w	d7  		;if (n) goto BUMP1;
	bne SPLABEL16
	subq.l  #1,_fastP		;fastP--;
	jsr _incFast			;c1 = *incFast();
	moveq	#0,d4
	move.b  (a1),d4 	; NOTE: incFast leaves fastP in a1
	bra SPLABEL10			;}   }
SPLABEL11:
	move.b  #0,(a2)+		;*(p++) = 0x00;
	tst.w	d5  		;if (c2==0) { if (c1==EOFILE) return(TRUE); }
	bne SPLABEL19
	cmp.w	#3,d4
	bne SPLABEL19
	moveq	#1,d0
SPLABEL20:
	movem.l (sp)+,d2-d7/a2/a3
	rts
SPLABEL19:
	cmp.w	#1,d5			;if (c2==1) continue;
	beq SPLABEL6
	move.w  d5,_llen		;len = c2;

	lea _badWord,a2 	;p = badWord;
;move.l  a2,_pp 	;pp = p to calculate match len
	moveq	#0,d4
	moveq	#0,d5
	moveq	#0,d6
	move.b  (a2)+,d4		;c1 = *(p++);
	move.b  (a2)+,d5		;c2 = *(p++);
	move.b  (a2)+,d6		;c3 = *(p++);

	move.w  d4,d0			;c2 += ((c1 << 5) - (c1 << 2));
	asl.w	#5,d0
	move.w  d4,d1
;;;	asl.w	#2,d1
	add.w	d1,d1
	add.w	d1,d1
	sub.w	d1,d0
	add.w	d0,d5

	move.w  d5,d0	;n = *(ctable + c2);
	ext.l	d0
	add.l	d0,d0		;asl.l   #1,d0
	move.l  _ctable,a0
	move.w  (a0,d0.l),d7
	tst.w	d7  		;;;;if (n==0) goto BADRTN;
	beq SPLABEL9
	move.w  d7,d0			;s = tbb + n - 1;
	ext.l	d0
	asl.l	#2,d0
	add.l	_tbb,d0
	move.l  d0,a3
	subq.w  #4,a3
	move.l  (a3),d0 	;n =  *s & 0x0700;
	and.l	#1792,d0
	move.w  d0,d7
	tst.w	d6  		;if (c3==0) {
	bne SPLABEL21
	btst.l  #10,d7  	;if (!(n & 0x0400)) goto BADRTN;
	beq SPLABEL9
	bra SPLABEL6		;goto FOUND;
SPLABEL21:  			;while (1) {
	move.l  (a3),d0 	;c1 = *s & 0xff;
	and.l	#255,d0
	move.w  d0,d4
	cmp.w	d6,d4			;if (c1<c3) goto BUMPS;
	blt SPLABEL25
	cmp.w	d6,d4			;if (c1==c3) {
	bne SPLABEL9			;goto BADRTN;
	move.l  (a3),d2 	;lloc =  (*s >> 11L);
	moveq	#11,d1
	lsr.l	d1,d2
	btst.l  #9,d7			;if ((n & 0x0200) && len==3) goto FOUND;
	beq SPLABEL28
	cmp.w	#3,_llen
	beq SPLABEL6
	bra SPLABEL28			;goto LOOKUP;
SPLABEL25:  			;BUMPS:
	addq.w  #4,a3			;s++;
	move.l  (a3),d0 	;n =  *s & 0x0700;
	and.l	#1792,d0
	move.w  d0,d7
	btst.l  #8,d7			;if (n & 0x0100) goto BADRTN;
	bne SPLABEL9			; endd of table */
	bra SPLABEL21			;}  continue;
SPLABEL28:  			;LOOKUP:
	tst.w	_inram  	;if (!inram) {
	bne SPLABEL29
	move.l  d2,_lloc		; SAVING it during i/o
	pea -1  			; Seek(fspell,lloc,(long)OFFSET_BEGINNING);
	move.l  d2,-(sp)
	move.l  _fspell,-(sp)
	jsr _Seek
	move.l  _seekBuf,a1 ;pbuf = seekBuf;
	pea 64  			; len = Read(fspell,pbuf,64L) + 1;
	move.l  a1,-(sp)
	move.l  _fspell,-(sp)
	jsr _Read
	lea 24(sp),sp
	move.l  _lloc,d2		; UNSAVING it during i/o
	move.l  _seekBuf,a1 ;pbuf = seekBuf;
	addq.l  #1,d0
	move.w  d0,_llen
	cmp.w	#2,d0			;if (len<2) goto BADRTN;
	blt SPLABEL9
	bra SPLABEL30			;} else {
SPLABEL29:
	move.l  _fspell,a1  ;pbuf = fspell + lloc;
	add.l	d2,a1
SPLABEL30:  			;}
	addq.w  #4,a3			;s++;
	move.l  (a3),d3 	;nextlloc = (*s >> 11L);
	moveq  #11,d1
	lsr.l	d1,d3

	moveq	#0,d7			;n = 0;
	move.l  a2,_pp  	;pp = p;
SPLABEL31:  			;SEARCH:
	cmp.l	d3,d2			;if (lloc>=nextlloc) goto BADRTN;
	bge SPLABEL9
	tst.w	_inram  	;if (!inram) {
	bne SPLABEL33
	subq.w  #1,_llen		;if (--len<=0) {
	tst.w	_llen
	bgt SPLABEL33
	move.l  d3,_nextlloc	; SAVING it for read
	move.l  d2,_lloc		; SAVING it for read
	move.l  _seekBuf,a1 ;pbuf = seekBuf;
	pea 256 			;len = Read(fspell,pbuf,256L);
	move.l  a1,-(sp)
	move.l  _fspell,-(sp)
	jsr _Read
	lea 12(sp),sp
	move.l  _seekBuf,a1 ; pbuf = seekBuf;
	move.l  _lloc,d2		; UNSAVING it from read
	move.l  _nextlloc,d3	; UNSAVING it from read
	move.w  d0,_llen
	cmp.l	#1,d0			;if (len<1) goto BADRTN;
	blt SPLABEL9			;}
SPLABEL33:  			;}
	addq.l  #1,d2			;lloc++;
	moveq	#0,d4
	move.b  (a1)+,d4		;c1 = *(pbuf++);

	move.w  #256,d5 	;c2 = 256;
	cmp.w	#28,d4  	;if (c1>=ADDSTAT) {
	blt SPLABEL34
	moveq	#0,d0
	sub.w	#28,d4  	;c1 -= ADDSTAT;
	move.w  d4,d0			;q = stat + (c1 << 1);
	add.l	d0,d0	;asl.l   #1,d0
	add.l	_statt,d0
	move.l  d0,a0
	moveq	#0,d4			;c1 = *(q++);
	move.b  (a0)+,d4
	moveq	#0,d5			;c2 = *q;
	move.b  (a0),d5
SPLABEL34:  			;}
	tst.w	d7  		;if (n) {
	beq SPLABEL35
	tst.w	d4  		;if (c1==0 || c2==0) { p = pp; n = 0; }
	beq SPLABEL37			;
	tst.w	d5
	bne SPLABEL31			;goto SEARCH;
SPLABEL37:
	move.l  _pp,a2
	moveq	#0,d7
	bra SPLABEL31			;}
SPLABEL35:
	moveq	#0,d6
	move.b  (a2)+,d6		;c3 = *(p++);

	cmp.w	d6,d4			;if (c1<c3) {
	bge SPLABEL38
	tst.w	d4  	;if (c1==0 || c2==0) { p = pp; goto SEARCH; }
	beq SPLABEL40
	tst.w	d5
	bne SPLABEL39
SPLABEL40:
	move.l  _pp,a2
	bra SPLABEL31
SPLABEL39:
	moveq	#1,d7			;n = 1;
	bra SPLABEL31			;goto SEARCH;
SPLABEL38:  			;}
	cmp.w	d6,d4			;if (c1==c3) {
	bne SPLABEL9
	tst.w	d6  		;if (c3==0) continue;
	beq SPLABEL6
	cmp.w	#256,d5 	;if (c2 != 256) {
	beq SPLABEL31
	moveq	#0,d6
	move.b  (a2)+,d6		;c3 = *(p++);

	cmp.w	d6,d5			;if (c2<c3) {
	bge SPLABEL43
	tst.w	d5  		;if (c2==0) { p = pp; goto SEARCH; }
	bne SPLABEL44
	move.l  _pp,a2
	bra SPLABEL31
SPLABEL44:
	moveq	#1,d7			;n = 1;
	bra SPLABEL31			;goto SEARCH;
SPLABEL43:  			;}
	cmp.w	d6,d5			;if (c2==c3) {
	bne SPLABEL9

	tst.w	d5  		;if (c2==0) continue;
	beq SPLABEL6
	bra SPLABEL31			;goto SEARCH;
SPLABEL9:					;BADRTN:	}
	moveq	#0,d0			;return(FALSE);
	bra SPLABEL20			;}
;SPLABEL3:  equ 0
#endasm
#endif

FstopSpell()
{
	if (tb==NULL) goto BRTN;
	FreeMem(tb,tbsize);
	if (fspell!=NULL) {
		if (!inram) Close((BPTR)fspell);
		else FreeMem((void *)fspell,udsize);
	}
	tb = NULL;
	fspell = NULL;
	inram = FALSE;
	return(TRUE);
BRTN:
	return(FALSE);
}

FstartSpell()
{
register UCHAR *fd,*x;
register long  i;

	if (tb!=NULL) goto BRTN;
	x = fixString(' ',0,NAMELEN - 4);
	fd = openOld(x);
	if (fd==NULL) goto BADOUT;
	i = getSize(fd,&tb);

	if (tb==NULL) { Close((BPTR)fd); goto BADOUT; }
	Read((BPTR)fd,tb,i);
	Close((BPTR)fd);
	tbsize = i;
	ctable = (unsigned short *)tb;
	if (*ctable!=65533) goto BADOUT;
	statt = (UCHAR *)tb;
	statt += 1568;
	tbb = tb + 506;  /* (456 + 1568)/4 */

	x = fixString(' ',1,NAMELEN - 4);
	fd = openOld(x);
	if (fd==NULL) goto BADOUT;
	if (*(longPtrArgs[2])!=0L) {
		i = getSize(fd,&fspell);
		if (fspell!=NULL) {
			inram = TRUE;
			Read((BPTR)fd,fspell,i);
			Close((BPTR)fd);
			fd = fspell;
			udsize = i;
		}
	}
	fspell = fd;
	return(TRUE);
BADOUT:
	FstopSpell();
BRTN:
	return(FALSE);
}

long getSize(	register UCHAR *fd,
				register UCHAR **x)
{
register long size,avail;

	Seek((BPTR)fd,0L,(long)OFFSET_END);
	size = Seek((BPTR)fd,0L,(long)OFFSET_CURRENT);
	Seek((BPTR)fd,0L,(long)OFFSET_BEGINNING);
	avail = AvailMem((long)MEMF_LARGEST);
	*x = NULL;
	if (size>0L && (size + 10240L)<avail)
			*x = (UCHAR *)AllocMem(size,(long)MEMF_CLEAR);
	return(size);
}

#else

spellmsg()
{
	oneOk("Not the spell-checking Uedit.");
	return(FALSE);
}

FstopSpell() { return(FALSE); }

#endif

static short printCol;
static UCHAR *printT;
static short printTable[MAXTABS + 1];

openPrt(register short prefs)
{
register UCHAR *xx;
register short rtn;

	rtn = FALSE;

	printCol = 1;
	printT = tabTables[printTable[0]];

	if (prefs<2) {
			if (prefs==1) xx = (UCHAR *)"SER:";
			else xx = (UCHAR *)"PAR:";
			fdprt=openOld(xx);
			if (fdprt!=NULL) rtn = TRUE;
	} else {
		prtPort = (struct Port *)CreatePort("ueprt",0L);
		if (prtPort!=NULL) {
			prtMsg =  CreateExtIO(prtPort,(long)sizeof(struct IODRPReq));
			if (prtMsg!=NULL
				&& OpenDevice("printer.device",0L,prtMsg,0L)==0L) rtn = TRUE;
		}
		prtOpen=rtn;
	}
	if (!rtn) {  oneMsg("Can't get printer"); closePrt(); }
	return(rtn);
}

slowPrint()
{
register UCHAR  *y;
register short  rtn,i;
register ULONG  mapit;
UCHAR				ch,*x,z[8];
struct CB  *bf;

	rtn = FALSE;
	bf = bufPtrArgs[0];
	printTable[0] = bf->tabTable;
	if (!openPrt((short)prefPrint)) goto RTN;
	getBP(bf,1);
	pushFast(bf,&fB,&fP);
	y = fastP;
	mapit = bf->Flags & MAPCHARS;
	printChoice[0] = prefPrint & 3;
	while (1) {
		if (stop()) goto FALSERTN;
		if (fastB==gB && y>=gP) break;
		ch = *y;
		if (ch>127 && mapit) ch = unMapIt((short)ch);
		if (prtOpen && ch==ESC) {
			x = y;
			y = incFast();
			for (i=0; i<4; i++) {
				if (*y==ESC) {
					if (i==0) goto KEEPIT;
					z[i] = 0x00;
					z[i+1] = 0x00;
					transPrint(z);
					goto NEXT;
				}
				if (*y<' ') goto KEEPIT;
				z[i] = *y - ' ';
				y = incFast();
			}
KEEPIT: 	while (y!=x) y = decFast();
		}
		if (!printRaw(&ch)) goto FALSERTN;
NEXT:
		y = incFast();
	}
	rtn=TRUE;
FALSERTN:
	closePrt();
	popFast();
RTN:
	return(rtn);
}

static struct FileInfoBlock   *fbb;

void getname(register UCHAR *x)
{
register struct FileInfoBlock	*fb;
register long					lock,z,y;
register UCHAR 					i;

	if (!findFile(x)) return;
	allocFb();
	fb = fbb;
	if (fb==NULL) return;
    y = (BPTR)x;
	lock = (long)Lock((BPTR)y,(long)SHARED_LOCK);
	if (Examine((BPTR)lock,fb)) {
		UnLock((BPTR)lock);
		if (fb->fib_EntryType<0L) {
			z = 0L;
			i = *x;
			y = (long)x;
			while (i) {
				if (i==':' || i=='/') z = (long)x;
				x++;
				i = *x;
			}
			x = (UCHAR *)y;
			if (z) x = (UCHAR *)z + 1;
			if (*x) strcpy(x,fb->fib_FileName); /* overwrite filename */
		}
	}
	freeFb();
}

startFile(UCHAR *x)  								/* file name */
{
register UCHAR  		*fd;
register struct CB  	*bufPtr;
register short  		k,curFile,emptyBuf;
register ULONG  		fileFlag;
UCHAR					y[NAMELEN+2],z[NAMELEN+2];
struct DB				*block;

	fileFlag = 0;
	emptyBuf = 1;
	fd = x;
	if (fd==NULL || fd==(UCHAR *)4L || *fd<=' ' || *fd=='*') {
		if (noMemory==0 && fd==NULL) fd = (UCHAR *)"NoName";
		else { if (*fd!='*') fd = (UCHAR *)"Empty"; emptyBuf = 2; }
		x = fd;
	} else {
		while (*fd>=' ') fd++;
		*fd = 0x00;
		fd = x;
		strncpy(z,fd,(size_t)NAMELEN);
		toLower(z);
		for (k=0; k<MAXFILES; k++) if (buf[k]!=NULL) {
			strncpy(y,buf[k]->FileName,(size_t)NAMELEN);
			toLower(y);
			if (strcmp(z,y)==0) {
/*  			  if (edScreen) ScreenToFront(edScreen);
*/
				if (yesNo(fd," present.  Want read-only copy?"))
						fileFlag = READONLY;
				else goto BADOUT;
			}
		}
	}
	if ((curFile = newBuf(-1,&block))<0) goto BADOUT;
	bufPtr = (struct CB *)block;
	bufPtr->Flags |= fileFlag;
	if (!readFile(fd,bufPtr,NULL,emptyBuf)) { /* true means put eof */
BADOUT:
		return(-1);
	}
	curBuf = bufPtr;
	splitBufNum[curSplit] = curBuf->BufNum;

getname(fd);

	strncpy(bufPtr->FileName,fd,(size_t)(NAMELEN-4));
	fixSOF(bufPtr);
	switchFast();  /* does a popFast */
	fixSplit();
	FrefreshDisplay();
	return(curFile);
}

readFile(	UCHAR				*x,
			register struct CB  *bufPtr,
			struct DB			*block,
			register short  	newBuff)
{
register UCHAR  *fd;
register long	i;
UCHAR			buff[1024],*ptr;

	if (x==NULL) goto FRTN;
	if (newBuff==0) {
		if (!splitBlock(bufPtr,block,block->Data))  goto FRTN;
	} else {
		if (!newBlock(bufPtr,&block,block)) goto FRTN;
	}
	ptr = block->Data;
	block->eols = 0;
	if (newBuff==2) goto TRUERTN;  /* want Empty buffer */
	fd = openOld(x);
	if (fd==NULL) {
		if (newBuff==0) goto FRTN;
		goto TRUERTN;
	}
	/* ===== now looking at empty spot or eof ==== */
	passiveMsg("Loading",x,0L);

	while (1) {
		if (stop()) goto BOMBOUT;
		i = Read((BPTR)fd,buff,1024L);
		if (!importStr(bufPtr,&block,&ptr,buff,i)) {
BOMBOUT:
				Close((BPTR)fd);
				oneMsg("Load aborted");
				if (newBuff) freeBuf(bufPtr->BufNum);
				goto FRTN;
		}
		if (i<1L) break;
	}
	Close((BPTR)fd);
TRUERTN:
	clearMsg();
	if (newBuff) *ptr = EOFILE;
	return(TRUE);
FRTN:
	return(FALSE);
}

/* -------------------- file saving ----------------- */

static UCHAR	protectComment[80];
static UCHAR	*protectFile = NULL;
static long	protect;

void doSaving()
{
struct CB *bufPtr;
register UCHAR     *x,*zz;
register UCHAR     i;
register short     j,k;
register ULONG     flags;
UCHAR			   *zBuf,z[512];

	bufPtr = saveBuf;
	if (bufPtr==NULL || !(bufPtr->Flags & LOCKED)) {
		getSave();
		bufPtr = saveBuf;
	}
	if (bufPtr==NULL) return;
	flags = bufPtr->Flags;
	if (flags & NEEDPACK) {
		packBuf(bufPtr,noMemory);
		return;
	}
	if (saveFd==NULL) {
		getProtect(bufPtr->FileName);
		if ((flags & AUTOBACKUP) && !(flags & BACKEDUP)) {
			bufPtr->Flags |= BACKEDUP;
			x=fileName(bufPtr->FileName,"BAK");
			DeleteFile(x);
			Rename(bufPtr->FileName,x);
			info(x);
		}
		x = bufPtr->FileName;

		Rename(x,x);
		if ((saveFd = openNew(x))==NULL) {
BADSAVE:
			bufPtr->Flags &= ~(LOCKED | READONLY);
			bufPtr->Flags |= CHANGED;

			DeleteFile(x);
			badSave(x);
			stopPause = TRUE;
			return;
		}
		info(x);
		saveBlock = bufPtr->NextBlock;
		savePtr = saveBlock->Data;
		return;
	}

	flags &= MAPCHARS;

	k = maxSaveSize;
	if (k<512) k = 512;
	maxSaveSize = k;

	k = saveSize;
	k <<= 1;

	if (k>maxSaveSize || k<=0) k = maxSaveSize;
	zBuf = NULL;
	if (k<=512) x = z;
	else {
		x = (UCHAR *)AllocMem((long)k,0L);
		if (x==NULL) {
			k = 512;
			x = z;
		} else zBuf = x;
	}

	j = 0;
	saveSize = k;
	zz = savePtr;
	while (1) {
NEWHIT:
		i = *(zz++);
		if (i>EOFILE) goto FASTER;
		if (i==EOB) {
			saveBlock = saveBlock->NextBlock;
			zz = saveBlock->Data;
			goto NEWHIT;
		}
		if (i==EOFILE) {
			bufPtr->Flags &= ~(READONLY | LOCKED | CHANGED);
			if (bufPtr==curBuf) updateMenus();
			break;
		}
FASTER:
		if (i>127 && flags) i = unMapIt((short)i);
		*(x++) = i;
		if (++j>=k) break;
	}

	if (zBuf) x = zBuf;
	else x = z;

	savePtr = zz;
	if (j && Write((BPTR)saveFd,x,(long)j)!=j) {
ABORTSAVE:
			stopSave = FALSE;
			x = bufPtr->FileName;
			Close((BPTR)saveFd);
			saveFd = NULL;
			if (zBuf) FreeMem(zBuf,(long)saveSize);
			goto BADSAVE;
	}
	if (stopSave) goto ABORTSAVE;

	if (zBuf) FreeMem(zBuf,(long)saveSize);

	if (i==EOFILE) {
		Close((BPTR)saveFd);
		setProtect();
		saveFd = NULL;
		return;
	}

	if (mouseDown || collectRaw()) saveSize = 4;
}

/* =================== AREXX interface stuff ===================== */

#include <rexx/errors.h>
#include <rexx/rexxio.h>
#include <rexx/rxslib.h>
#include <rexx/storage.h>

#define AMESSAGE		0L
#define AREPLY  	1L

#define REXXOKAY		0L
#define REXXNOTUP		-1L
#define NOMEMORNOMSG	-2L
#define REXXMSGTOOBIG	-3L
#define NOREXXMSG		-4L
#define AWAITREPLY  -5L

struct RexxArg  *CreateArgstring();
struct RexxMsg  *CreateRexxMsg();
long   IsRexxMsg(), LengthArgString();

void replyRexx(), rexxWork(), delRexxMsg();
long bufToRexx();

static struct MsgPort  *inRexxPort = NULL;
static struct MsgPort  rPort;
static struct RexxMsg  *myRexxMsg = NULL;
struct RexxMsg  *rexxMsgIn,*rexxReplyMsg = NULL;
static struct RexxArg  *tArg=NULL;

static UCHAR *rexxPortName = (UCHAR *)"URexx";

FrexxOut()  	/* FrexxOut(oBuf,oRgn,ActionResult,flag,returncode) */
{
register struct RexxMsg *rMsg;
register long				*retPtr;
register long				actRes;
register short  		flag,sendString;
register long				retn;

	retPtr = longPtrArgs[4];

	if (!upRexx()) { NOREXX: *retPtr = REXXNOTUP; goto FRTN; }
	rexxWork();

	actRes = *longPtrArgs[2];					/* actionResult */
	flag   = *longPtrArgs[3];
	sendString = FALSE; 					/* don't send string */
	if (flag==AMESSAGE) {										/* cmd */
		if (myRexxMsg!=NULL || rexxReplyMsg!=NULL) {
			*retPtr = AWAITREPLY;		/* get reply to last msg 1st */
			goto FRTN;
		}
		if (!newRexxMsg()) { *retPtr=NOMEMORNOMSG; goto FRTN; }
		rMsg = myRexxMsg;
		sendString = TRUE;  	/* always send argString for MSG */
	} else {									/* REPLYING to their msg */
		rMsg = rexxMsgIn;
		if (rMsg==NULL) {
			*retPtr = NOREXXMSG;
			goto FRTN;
		}							/* OK result & they wanted argString */
		if (actRes==0L && (rMsg->rm_Action & RXFF_RESULT)) sendString = TRUE;
		else rMsg->rm_Result2 = 0L;
	}
	if (sendString) {								/* sending argString */
		retn = bufToRexx(); 		/* returns flag, str in tArg */
		if (retn!=REXXOKAY) {
			*retPtr = retn;
			if (flag==AREPLY) replyRexx(10L);		/* replies Fail */
			else delRexxMsg();
			goto FRTN;
		}
		if (flag==AMESSAGE) rMsg->rm_Args[0] = (STRPTR)tArg;
										/* sendString FALSE if NO-RESULT */
		else rMsg->rm_Result2 = (long)tArg;
		tArg = NULL;
	}
	if (flag==AMESSAGE) {							/* sending message */
		if (actRes==0L) actRes = RXCOMM;
		else if (actRes==1L) actRes = RXCOMM | RXFF_RESULT;
		else if (actRes==2L) actRes = RXCOMM | RXFF_NONRET;
		rMsg->rm_Action = actRes;
		if (!outMsg()) goto NOREXX;
	} else replyRexx(actRes);				/* sets result1 to action */
	*retPtr = 0L;
	return(TRUE);
FRTN:
	return(FALSE);
}

FrexxIn()			/* FrexxIn(iBuf,iLoc,ActionResult,flag,returncode) */
{
register struct RexxMsg *rMsg;
register long				*retPtr;
long						*flagPtr;
register long				len,actionResult,argString;
register short  		rtn;

	rtn = FALSE;
	flagPtr = longPtrArgs[3];						/* msg/reply flag */
	retPtr = longPtrArgs[4];					/* error return code */
	if (!upRexx()) { *retPtr = REXXNOTUP; goto RTN; }
	rexxWork(); 								/* get msg if any */

	argString = 0L;
	if (rexxReplyMsg!=NULL) {
		rMsg = rexxReplyMsg;
		*flagPtr = AREPLY;
		actionResult = rMsg->rm_Result1;
		if (actionResult==0L && (rMsg->rm_Action & RXFF_RESULT))
					argString = rMsg->rm_Result2;
	} else if (rexxMsgIn!=NULL) {
		rMsg = rexxMsgIn;
		*flagPtr = AMESSAGE;
		actionResult = rMsg->rm_Action;
		argString	= (long)(rMsg->rm_Args[0]);
	} else {
		*retPtr = NOREXXMSG;
		goto RTN;
	}
	if (argString && args[0]==buf_) {				/* fetch stringarg */
		len = LengthArgstring(argString);
		if (len>0L && !rexxToBuf((void *)argString,len)) {
			*retPtr = NOMEMORNOMSG;
			if (*flagPtr==AMESSAGE) replyRexx(10L);
			goto RTN2;
		}
	}
	*longPtrArgs[2] = actionResult;
	rtn = TRUE;
	*retPtr = 0L;
RTN2:									/* sets rexxReplyMsg==NULL also */
	if (*flagPtr==AREPLY) delRexxMsg();
RTN:
	return(rtn);
}

upRexx()
{
	if (FindPort("REXX")==NULL) goto FRTN;
	if (RexxSysBase==0L) {
		RexxSysBase = (long)OpenLibrary("rexxsyslib.library",0L);
		if (RexxSysBase == 0L) goto FRTN;
	}
	if (inRexxPort==NULL) {
		inRexxPort = &rPort;
		nullify(inRexxPort,(long)sizeof(struct MsgPort));
		InitPort(inRexxPort,rexxPortName);
		AddPort(inRexxPort);
	}
	return(TRUE);
FRTN:
	return(FALSE);
}

downRexx()
{
	if (myRexxMsg!=NULL) {
		oneOk("Wait for Rexx reply");
		goto FRTN;
	}
	if (inRexxPort) {
		rexxWork();
		replyRexx(10L);
		RemPort(inRexxPort);
		FreePort(inRexxPort);
		inRexxPort = NULL;
	}
	delRexxMsg();
	if (RexxSysBase) CloseLibrary((void *)RexxSysBase);
	RexxSysBase = 0L;
	return(TRUE);
FRTN:
	return(FALSE);
}

void delRexxMsg()
{
register struct RexxMsg *rMsg;
register long			pa;

	rMsg = myRexxMsg;
	if (rMsg==NULL) rMsg = rexxReplyMsg;
	if (rMsg!=NULL) {
		pa = rMsg->rm_Result2;
		if (pa!=0L && (rMsg->rm_Action & RXFF_RESULT)) DeleteArgstring(pa);
		pa = (long)rMsg->rm_Args[0];
		if (pa!=0L) {
			DeleteArgstring(pa);
			rMsg->rm_Args[0]=NULL;
		}
		DeleteRexxMsg(rMsg);
		myRexxMsg = rexxReplyMsg = NULL;
	}
}

newRexxMsg()
{
	myRexxMsg  = CreateRexxMsg(inRexxPort,rexxPortName,rexxPortName);
	if (myRexxMsg!=NULL) return(TRUE);
	return(FALSE);
}

void rexxWork()
{
register struct RexxMsg *rMsg;

	if (upRexx() && rexxMsgIn==NULL && rexxReplyMsg==NULL) {
AGAIN:
		rMsg = (struct RexxMsg *)GetMsg(inRexxPort);
		if (rMsg!=NULL) {
			if (rMsg==myRexxMsg) {
				rexxReplyMsg = rMsg;
				myRexxMsg	= NULL;
			} else {
				if (IsRexxMsg(rMsg)) rexxMsgIn = rMsg;
				else { ReplyMsg(rMsg); goto AGAIN; }
			}
			if (tiny) gChar = ESC;
		}
	}
}

outMsg()
{
register struct MsgPort *outRexxPort;
register short rtn;

	rtn = TRUE;
	Forbid();
	if ((outRexxPort=FindPort("REXX"))!=NULL) PutMsg(outRexxPort,myRexxMsg);
	else { rtn = FALSE; delRexxMsg(); }
	Permit();								/* don't expect reply!! */
	if (myRexxMsg->rm_Action & RXFF_NONRET) myRexxMsg = NULL;
	return(rtn);
}

void replyRexx(register long reply)
{
register struct RexxMsg  *rMsg;

	rMsg = rexxMsgIn;
	if (rMsg!=NULL) {
		if (!(rMsg->rm_Action & RXFF_NONRET)) {
			rMsg->rm_Result1 = reply;
			if (reply!=0L) rMsg->rm_Result2=0L;/* no string on fail */
			ReplyMsg(rMsg);
		} else {
			rMsg = myRexxMsg;
			myRexxMsg = rexxMsgIn;
			delRexxMsg();
			myRexxMsg = rMsg;
		}
	}
	rexxMsgIn = NULL;
}

long bufToRexx()
{
register UCHAR  	*x;
register long			rtn;
long					len;

	rtn = NOMEMORNOMSG;
	x = exportStr(&len);
	if (x==NULL) goto RTN;
	if (len>65535L) {
		FreeMem(x,len);
		rtn = REXXMSGTOOBIG;
		goto RTN;
	}
	tArg = (struct RexxArg *)CreateArgstring(x,len);
	if (tArg!=NULL) rtn = REXXOKAY;
	FreeMem(x,len);
RTN:
	return(rtn);
}

rexxToBuf(  struct RexxArg  *argString,
			long			len)
{
register struct CB  *bufPtr;
register short  bufNum;

	bufNum = longArgs[0];
	if (!getBuf(bufNum)) goto FRTN;
	bufPtr = buf[bufNum];
	if (!canChange(bufPtr)) goto FRTN;
	splitFlag(bufNum,PAGE_ | SHOWCURSOR_);
	getBP(bufPtr,1);							/* loc to insert data */
	if (gB==NULL || !splitBlock(bufPtr,gB,gP)) goto FRTN;
	gB->eols = 255;
	return(importStr(bufPtr,&gB,&gP,argString,len));
FRTN:
	return(FALSE);
}

/* ===================== REXX GLUE ASM =========== */

#asm
		INCLUDE  "rexx/storage.i"
		INCLUDE  "rexx/rxslib.i"

		XREF	_RexxSysBase

* First calling convention:
* 1, 2, or 3 parameters in (A0,A1,D0), return value in D0.

		; msgptr = CreateRexxMsg(&replyport,&fileext,&hostname)

		XDEF	_CreateRexxMsg
_CreateRexxMsg:
		move.w   #_LVOCreateRexxMsg,d1
		bra.s	 CallSeq1

		; DeleteArgstring(argptr)

		XDEF	_DeleteArgstring
_DeleteArgstring:
		move.w   #_LVODeleteArgstring,d1
		bra.s	 CallSeq1

		; DeleteRexxMsg(msgptr)

		XDEF	_DeleteRexxMsg
_DeleteRexxMsg:
		move.w   #_LVODeleteRexxMsg,d1
		bra.s	 CallSeq1

		; FreePort(&msgport)

		XDEF	_FreePort
_FreePort:
		move.w   #_LVOFreePort,d1
		bra.s	 CallSeq1

		; signal = InitPort(&replyport)

		XDEF	_InitPort
_InitPort:
		move.w   #_LVOInitPort,d1
		bra.s	 CallSeq1

	; boolean = IsRexxMsg(msgptr)

		XDEF	_IsRexxMsg
_IsRexxMsg:
		move.w   #_LVOIsRexxMsg,d1
		bra.s	 CallSeq1

		; length = LengthArgstring(argptr)

		XDEF	_LengthArgstring
_LengthArgstring:
		move.w   #_LVOLengthArgstring,d1

		; Load three arguments into (A0,A1,D0)

CallSeq1 movea.l  4(sp),a0
		movea.l  8(sp),a1
		move.l   12(sp),d0

		; Call the library function

CallFunc move.l   a6,-(sp)
		movea.l  _RexxSysBase,a6
		jsr 0(a6,d1.w)
		movea.l  (sp)+,a6
		rts

* Second calling convention:  2 parameters in (A0,D0), return value in D0.

		; argptr = CreateArgstring(&string,length)

		XDEF	_CreateArgstring
_CreateArgstring:
		moveq	 #_LVOCreateArgstring,d1

		movea.l  4(sp),a0
		move.l   8(sp),d0
		bra CallFunc

#endasm


/* %% */

#ifdef USEC

 		/* this overwrites EOFILE */
importStr(  struct CB			*bufPtr,
			struct DB			**block,
			UCHAR				**ptr,
			register UCHAR  	*buff,
			register long		i)
{
register UCHAR  *p;
register ULONG  flag,mapFlag;
register UCHAR  ch;
struct DB		*b;
short			j;

	flag = (bufPtr->Flags & READONLY);
	p = *ptr;
	b = *block;
	mapFlag = bufPtr->Flags & MAPCHARS;
	goto HITME; 			/* p is pointing to eof if newbuf */
TOP:
		ch = *(buff++);
		if (ch>13) goto BUMP;
		if (ISWEIRD(ch)) {
			if (mapFlag) {
				ch = charMappings[ch];
				goto BUMP;
			}
			if (!flag) {
				if (!yesNo("Must wipe illegal chars."," Load anyway?"))
							goto FRTN;
				flag = READONLY;
			}
			ch = '@';
			goto BUMP;
		}
		if (ch==eol) {
			if (b->eols<255) b->eols++;
			goto BUMP;
		}
		if (ch==12) b->eols = 255;
BUMP:
		*(p++) = ch;
		i--;
HITME:
		if (*p==EOB) {
			if (!newBlock(bufPtr,&b,b)) {
				if (noMemory && saves) {
						j = saves - 1;
						while (j!=saves) doSaving();
						noMemory = stopPause = 0;
						goto HITME;
				}
				goto FRTN;
			}
			p = b->Data;
		}
		if (i>0L) goto TOP;

	bufPtr->Flags |= flag;
	*block = b;
	*ptr = p;
	return(TRUE);
FRTN:
	return(FALSE);
}

#endif

#ifdef USEC

saveFile(register struct CB *bufPtr)
{

	if (bufPtr==NULL) goto FRTN;
	if (bufPtr->Flags & LOCKED) goto FRTN;
	if (bufPtr->Flags & READONLY) {
MSG:
	oneMsg("Read-only, empty, or bad name");
	goto FRTN;
	}
	if (ISWEIRD(*(bufPtr->NextBlock->Data))) goto MSG;
	if (*(bufPtr->FileName)<=' ') goto MSG;
	if (!push(&sStack,(long)bufPtr)) goto FRTN;
		saves++;
		bufPtr->Flags |= LOCKED /* ===== (LOCKED | READONLY) */;
		bufPtr->Flags &= ~CHANGED;/* so they can close it freely */
		setTitle();
		return(TRUE);
FRTN:
	return(FALSE);
}

void allocFb()
{
	fbb = (struct FileInfoBlock *)
		AllocMem((long)sizeof(struct FileInfoBlock),(long)MEMF_CLEAR);
}

void freeFb()
{
	if (fbb!=NULL) FreeMem(fbb,(long)sizeof(struct FileInfoBlock));
	fbb = NULL;
}

void setProtect()
{
register struct FileInfoBlock	*fb;
register UCHAR  				*y;
register long					val,x;

	x = (long)protectFile;
	if (x!=0L) {
		allocFb();
		fb = fbb;
		if (fb==NULL) goto NOPROT;
		val = (long)Lock((BPTR)x,(long)SHARED_LOCK);
		if (Examine((BPTR)val,fb)) {
			UnLock((BPTR)val);
			if (fb->fib_EntryType<0L) {
				y = protectComment;
				y[79] = 0x00;
				SetComment((UCHAR *)x,y);
				SetProtection((UCHAR *)x,protect);
			}
		}
		freeFb();
	}
NOPROT:
	protectFile = NULL;
}

FsaveFile()
{
	return(saveFile(bufPtrArgs[0]));		 /* saveFile protects! */
}

void badSave(UCHAR *x)
{
	passiveMsg("File save error/abort ",x,0L);
}

void getSave()
{
register short i;
register ULONG flags;

	if (saveBuf!=NULL) goto SEEIT;
GETNEXT:
	if (!pop(&sStack,&saveBuf)) return;
	if (saveBuf==NULL) return;
	saveBuf->Flags |= READONLY;
SEEIT:
	flags = saveBuf->Flags;
	if (flags & CHANGED) {
		if (flags & DELETEIT) goto RETACH;
		passiveMsg("NOT saved: ",saveBuf->FileName,0L);
		goto NEXT1;
	}
	if (flags & LOCKED) return; /* already queued? */
	if (saveFd!=NULL) { Close((BPTR)saveFd); saveFd = NULL; }
	if (!(flags & DELETEIT)) {  						/* not locked */
NEXT1:
		saveBuf->Flags &= ~(ULONG)(DELETEIT | LOCKED | READONLY /* | CHANGED */);
NEXT2:
		saves--;
		setTitle();
		saveBuf = NULL;
		goto GETNEXT;
	}
	if (!(flags & READONLY)) {  				/* delete & good save */
DELIT:
		saveBuf->Flags = 0;
		buf[ALLBUFS] = saveBuf;
		freeBuf(ALLBUFS);
		goto NEXT2;
	}
RETACH:
	/* delete & bad save */
	for (i=0; i<ALLBUFS; i++) if (buf[i]==NULL) {
		buf[i] = saveBuf;
		saveBuf->BufNum = i;
		switchFast();
		displayFlag |= (PAGE_ << curSplit);
		display();
		badSave(saveBuf->FileName);
		stopPause = TRUE;
		goto NEXT1;
	}
	goto DELIT;
}

FabortSave()
{
	return(stopSave = (saves>0) ? TRUE : FALSE);
}

FloadFile()
{
register UCHAR  *y;

	y = fixString(' ',0,NAMELEN - 4);
	if (y!=NULL && startFile(y)>=0) return(TRUE);
	return(FALSE);
}

FinsertFile()
{
register struct CB  *bufPtr;
register struct DB  *b1;
register short  	bufnum,newBuff;
register long		z;
struct   DB 		*b2;

	bufPtr = bufPtrArgs[0];
	bufnum = (short) *longPtrArgs[0];
	z = (long)fixString(' ',2,NAMELEN - 4);
	if (!findFile((UCHAR *)z)) goto FALSERTN;
	if (bufPtr==NULL) {
		newBuff=1;
		if (newBuf(bufnum,&b2)<0) goto FALSERTN;
		bufPtr = (struct CB *)b2;
		b1 = NULL;
	} else {
		newBuff=0;
		if (!canChange(bufPtr)) goto FALSERTN;
		if (!getBuf(bufnum)) goto FALSERTN;
		getBP(bufPtr,1);/* location  at which to insert data */
		b1 = gB;
		if (b1==NULL || !splitBlock(bufPtr,b1,gP)) goto FALSERTN;
		b1 = b1->NextBlock;
	}
	if (!readFile((UCHAR *)z,bufPtr,b1,newBuff)) goto FALSERTN;/* freed there */
	splitFlag(bufnum,PAGE_);
	fixSOF(bufPtr);
	if (newBuff) {  								 /* set cursor to front */
		bufPtr->Ptr   = (UCHAR *)bufPtr->NextBlock;
		bufPtr->Block = bufPtr->NextBlock;
	}
	return(TRUE);
FALSERTN:
	return(FALSE);
}

void closePrt()
{
	if (fdprt!=NULL) Close((BPTR)fdprt);
	if (prtOpen) CloseDevice(prtMsg);
	if (prtMsg) DeleteExtIO(prtMsg /* ,(long)sizeof(struct IODRPReq) */);
	if (prtPort) DeletePort(prtPort);
	prtOpen = FALSE;
	prtMsg = NULL;
	prtPort = NULL;
	fdprt = NULL;
}

void transPrint(register UCHAR *p)
{
register struct IOPrtCmdReq *pMsg;

	pMsg = (struct IOPrtCmdReq *)prtMsg;
	pMsg->io_Command = PRD_PRTCOMMAND;
	pMsg->io_PrtCommand = p[0];
	pMsg->io_Parm0 = p[1];
	pMsg->io_Parm1 = p[2];
	pMsg->io_Parm2 = 0;
	pMsg->io_Parm3 = 0;
	DoIO(pMsg);
}

printRaw(register UCHAR *p)
{
register struct IOStdReq	*pMsg;
register short  			rtn,i,spaces,newCol,saveCol;
register long				saveColumnar;
UCHAR						ch,*saveTable;

	rtn = FALSE;

	spaces = 0;
	i = *p;
	ch = i;
	if (!printTabs) {						/* LATER change this to printTabs */
		newCol = printCol;
		if (i>=' ') { newCol++; goto DOIT; }
		if (i==eol || i==12) { newCol = 1; goto DOIT; }
		if (i!=TAB) goto DOIT;  /* don't bump newCol if other ctl char */

		saveCol = curCol; saveTable = curTable; saveColumnar = columnar;
		curCol = newCol;
		curTable = printT;
		spaces = tabCalc() & 0x00ff;
		curCol = saveCol; columnar = saveColumnar; curTable = saveTable;
		ch = ' ';
		if (spaces) newCol += spaces;
		else		newCol++;
	}

DOIT:
	if (prtOpen) {
			pMsg = (struct IOStdReq *)prtMsg;
			if (printChoice[0]==3) pMsg->io_Command = PRD_RAWWRITE;
			else pMsg->io_Command = CMD_WRITE;
			pMsg->io_Data = (APTR)&ch;
			pMsg->io_Length = 1;
			rtn = (DoIO(pMsg)==0L) ? TRUE : FALSE;
	} else if (fdprt!=NULL) {
		rtn = (Write((BPTR)fdprt,&ch,1L)==1L) ? TRUE : FALSE;
	}

	spaces--;
	if (rtn && spaces>0) goto DOIT;

	printCol = newCol;

	return(rtn);
}

void doPrinting()
{
register UCHAR    *ptr,*z;
register long	byte,len;
register short    i;

	if (prints<=0) return;
	if (fdprt==NULL && prtOpen==0 && !openPrt(printChoice[0])) {
		FabortPrint();
		return;
	}
	byte = printByte[0];
	len = printLen[0];
	if (byte>=len) goto DONE;
	z = (UCHAR *)"  ";
	ptr  = printBuf[0] + byte;
	if (prtOpen && *ptr==ESC) { 			/* going through Prefs */
		for (i=1; i<5; i++) {
			if (ptr[i]==ESC) {
				if (i==1) goto DORAW;
				z[i-1] = 0x00;
				z[i] = 0x00;
				transPrint(z);
				byte += (i + 1);
				goto DONE;
			}
			if (ptr[i]<' ') break;
			z[i-1] = ptr[i] - ' ';
		}
	}
DORAW:
	byte++;
	if (!printRaw(ptr)) {
		if (yesNo("Can't print. ","Abort prints?")) while (FabortPrint());
		byte--;
	}
DONE:
	printByte[0] = byte;
	if (byte>=len) FabortPrint();
}

FabortPrint()
{
register short i;

	closePrt();
	if (prints<=0) goto BRTN;
	prints--;
	FreeMem(printBuf[0],printLen[0]);
	for (i=0; i<(MAXPRINTS-1); i++) {
		printBuf[i] = printBuf[i+1];
		printLen[i] = printLen[i+1];
		printByte[i]	= 0L;
		printChoice[i]  = printChoice[i+1];
		printTable[i]	= printTable[i+1];
	}
	setTitle();
	return(TRUE);
BRTN:
	return(FALSE);
}

Fprint()
{
register  UCHAR 	*z;
register short  	rtn,prts;
register long		llen;
long				len;

	rtn = FALSE;
	while (prints>=MAXPRINTS) {
		if (stop()) goto GETOUT;
		doPrinting();
	}
DOMORE:
	prts = prints;
	z = exportStr(&len);
	llen = len;
	if (z==NULL) {
			if (llen>0L) {
				if (prts == 0) rtn = slowPrint();
				else {
					prts--;
					while (prts<prints) {
						if (stop()) goto GETOUT;
						doPrinting();
					}
					goto DOMORE;
				}
			}
			goto GETOUT;
	}
	printBuf[prts]   = z;
	printLen[prts]   = llen;
	printByte[prts]   = 0L;
	printChoice[prts] = prefPrint & 3;
	printTable[prts]  = bufPtrArgs[0]->tabTable;
	prints  		 = prts + 1;
	setTitle();
	rtn=TRUE;
GETOUT:
	return(rtn);
}

unMapIt(register short ch)
{
register short i;

	i = 0;
	while (i<4) {
		if (ch==charMappings[i]) return (i);
		i++;
	}
	return(ch);
}

UCHAR *exportStr(register long *len) /* assumes bufarg==0, rgnarg==1 */
{
register UCHAR  	*z,*y;
register ULONG  	mapit;
register UCHAR  	j;
register long		zz;
register long		bf;

	z = NULL;
	*len = 0L;
	if (args[0]==buf_) {
		bf = (long)bufPtrArgs[0];
		mapit = ((struct CB *)bf)->Flags & MAPCHARS;
		if (bf==NULL) goto GETOUT;
		if (((struct CB *)bf)->Flags & NEEDPACK) packBuf((struct CB *)bf,TRUE);
		getBP((struct CB *)bf,1);
		if (fB==NULL || gB==NULL || *fP==EOFILE || fP==gP) goto GETOUT;
		*len = (long)(DATASIZE)*(long)(gB->BlockNum - fB->BlockNum)
				+ (long)(gP - gB->Data) - (long)(fP - fB->Data);
		z = safeMem(*len);
		if (z==NULL) goto MEMOUT;
		y = z;
		pushFast((struct CB *)bf,&fB,&fP);
		while (1) {
			if (fastB==gB && fastP>=gP) break;
			j = *fastP;
			if (mapit && j>127) j = unMapIt((short)j);
			*(y++) = j;
			incFast();
		}
		popFast();
	} else {									 /* arg MUST be literal */
		y = (UCHAR *)ptrArgs[0];
		if (y==NULL || *y==0x00) goto GETOUT;
		*len = strlen(y);
		z = safeMem(*len);
		if (z==NULL) { MEMOUT: memoryMsg(); goto GETOUT; }
		zz = (long)z;
		while (*y) *(z++) = *(y++);
		z = (UCHAR *)zz;
	}
GETOUT:
	return(z);
}

FstringComp()
{
register UCHAR *x,*y;
register short val;

	x = fixString(0,1,127);
	y = fixString(0,2,127);
	if (x==NULL || y==NULL) goto FRTN;
	if (*(longPtrArgs[3])) {
		toLower(x);
		toLower(y);
	}
	val = strcmp(x,y);
	*(longPtrArgs[0]) = val;
	if (val==0) return(TRUE);
FRTN:
	return(FALSE);
}

#endif

/* -----------------------------------------
FgetFileDate()
{
register UCHAR  				*x;
register struct FileInfoBlock	*fb;
register long					lock;

	x = fixString(' ',0,NAMELEN-4);
	if (!findFile(x)) return(FALSE);

	allocFb();
	fb = fbb;
	if (fb==NULL) return(FALSE);
	lock = (long)Lock((BPTR)x,(long)SHARED_LOCK);
	if (Examine((BPTR)lock,fb)) {
		UnLock((BPTR)lock);
		if (fb->fib_EntryType<0L) {
			*longPtrArgs[1] = fb->fib_Date.ds_Days;
			*longPtrArgs[2] = fb->fib_Date.ds_Minute;
			*longPtrArgs[3] = fb->fib_Date.ds_Tick;
		}
	}
	freeFb();
	return(TRUE);
}
------------------------------------------- */

void getProtect(register UCHAR *x)
{
register struct FileInfoBlock	*fb;
register long					lock,y;

	protectFile = NULL;
	if (!findFile(x)) return;
	allocFb();
	fb = fbb;
	if (fb==NULL) return;
    y = (ULONG)x;
	lock = (long)Lock((BPTR)y,(long)SHARED_LOCK);
	if (Examine((BPTR)lock,fb)) {
		UnLock((BPTR)lock);
		if (fb->fib_EntryType<0L) {
			protectFile = x;
			/* ---------------------------
			z = 0L;
			i = *x;
			y = (long)x;
			while (i) {
				if (i==':' || i=='/') z = (long)x;
				x++;
				i = *x;
			}
			x = (UCHAR *)y;
			if (z) x = (UCHAR *)z + 1;
			if (*x) strcpy(x,fb->fib_FileName); 	\\* overwrite filename *\\
			--------------------------- */
			lock = fb->fib_Protection;
			lock &= ~FIBF_ARCHIVE;
			protect = lock;
			movdat((UCHAR *)fb->fib_Comment,(UCHAR *)protectComment,(short)80);
			movdat((UCHAR *)&fb->fib_Date,(UCHAR *)&ds,(short)sizeof(struct DateStamp));
		}
	}
	freeFb();
}

#ifndef USEC
#asm

	xdef	_printRaw
_printRaw:
	link	a5,#RXX84
	movem.l	d2-d7/a2/a3/a6,-(sp)			;rtn=FALSE
	moveq	#0,d5			;spaces=0
	moveq	#0,d4			;i=*p
	move.l	8(a5),a0
	moveq	#0,d0
	move.b	(a0),d0
	move.w	d0,d3			;ch=i
	move.b	d3,-1(a5)			;if(!printTabs){/*LATERchangethistoprintTabs*/
	tst.l	_printTabs
	bne	RXX10255			;newCol=printCol
	move.w	_printCol,d2			;if(i>=''){newCol++gotoDOIT}
	cmp.w	#32,d3
	blt	RXX10256
	addq.w	#1,d2
	bra	RXX10257			;if(i==eol||i==12){newCol=1gotoDOIT}
RXX10256:
	moveq	#0,d0
	move.b	_eol,d0
	cmp.w	d3,d0
	beq	RXX85
	cmp.w	#12,d3
	bne	RXX10258
RXX85:
	moveq	#1,d2
	bra	RXX10257			;if(i!=TAB)gotoDOIT/*don'tbumpnewColifotherctlchar*/
RXX10258:
	cmp.w	#9,d3
	bne	RXX10257			;saveCol=curColsaveTable=curTablesaveColumnar=columnar
	move.w	_curCol,d6
	move.l	_curTable,a3
	move.l	_columnar,d7			;curCol=newCol
	move.w	d2,_curCol  		;curTable=printT
	move.l	_printT,_curTable			;spaces=tabCalc()&0x00ff
	jsr	_tabCalc
	move.w	d0,d4
	and.w	#255,d4 		;curCol=saveColcolumnar=saveColumnarcurTable=saveTable
	move.w	d6,_curCol
	move.l	d7,_columnar
	move.l	a3,_curTable			;ch=''
	move.b	#32,-1(a5)  		;if(spaces)newCol+=spaces
	tst.w	d4
	beq	RXX10259
	add.w	d4,d2			;elsenewCol++
	bra	RXX10260
RXX10259:
	addq.w	#1,d2
RXX10260:			;}DOIT:
RXX10255:
RXX10257:			;if(prtOpen){
	tst.w	_prtOpen
	beq	RXX10261			;pMsg=(SIOStdReq*)prtMsg
	move.l	_prtMsg,a2  		;if(printChoice[0]==3)pMsg->io_Command=PRD_RAWWRITE
	cmp.w	#3,_printChoice
	bne	RXX10262
	move.w	#9,28(a2)			;elsepMsg->io_Command=CMD_WRITE
	bra	RXX10263
RXX10262:
	move.w	#3,28(a2)
RXX10263:			;pMsg->io_Data=(APTR)&ch
	lea	-1(a5),a0
	move.l	a0,40(a2)			;pMsg->io_Length=1
	move.l	#1,36(a2)			;rtn=(DoIO(pMsg)==0L)?TRUE:FALSE
	move.l	a2,a1
	move.l	_SysBase#,a6
	jsr	-456(a6)
	tst.b	d0
	bne	RXX86
	moveq	#1,d0
	bra	RXX87
RXX86:
	moveq	#0,d0
RXX87:
	move.w	d0,d5			;}elseif(fdprt!=NULL){
	bra	RXX10264
RXX10261:
	tst.l	_fdprt
	beq	RXX10265			;rtn=(Write(fdprt,&ch,1L)==1L)?TRUE:FALSE
	movem.l	d2/d3,-10(a5)
	moveq	#1,d3
	lea	-1(a5),a0
	move.l	a0,d2
	move.l	_fdprt,d1
	move.l	_DOSBase#,a6
	jsr	-48(a6)
	movem.l	-10(a5),d2/d3
	cmp.l	#1,d0
	bne	RXX88
	moveq	#1,d0
	bra	RXX89
RXX88:
	moveq	#0,d0
RXX89:
	move.w	d0,d5			;}spaces--
RXX10265:
RXX10264:
	subq.w	#1,d4			;if(rtn&&spaces>0)gotoDOIT
	tst.w	d5
	beq	RXX90
	tst.w	d4
	bgt	RXX10257
RXX90:  		;printCol=newCol
	move.w	d2,_printCol			;return(rtn)
	move.w	d5,d0
RXX91:
	movem.l	(sp)+,d2-d7/a2/a3/a6
	unlk	a5
	rts 		;}
RXX84:	equ	-10 		;voiddoPrinting(){

	xdef	_unMapIt
_unMapIt:
	movem.l	d2/d3,-(sp)
	move.w	12(sp),d3			;Rshortii=0
	moveq	#0,d2			;while(i<4){
RXX10296:
	cmp.w	#4,d2
	bge	RXX10297			;if(ch==charMappings[i])return(i)
	move.w	d3,a0
	move.w	d2,d0
	asl.w	#2,d0
	lea	_charMappings,a1
	cmp.l	(a1,d0.w),a0
	bne	RXX10298
	move.w	d2,d0
RXX97:
	movem.l	(sp)+,d2/d3
	rts 		;i++
RXX10298:
	addq.w	#1,d2			;}
	bra	RXX10296
RXX10297:			;return(ch)
	move.w	d3,d0
	bra	RXX97			;}UCHAR*exportStr(Rlong*len)/*assumesbufarg==0,rgnarg==1*/{

	xdef	_exportStr
_exportStr:
	movem.l	d2-d6/a2/a3,-(sp)
	move.l	32(sp),d4			;RUCHAR*z,*yRULONGmapitRUCHARjRlongzzRlongbfz=NULL
	sub.l	a3,a3			;*len=0L
	move.l	d4,a0
	clr.l	(a0)			;if(args[0]==buf_){
	cmp.b	#1,_args
	bne	RXX10299			;bf=(long)bufPtrArgs[0]
	move.l	_bufPtrArgs,d3  		;mapit=((SCB*)bf)->Flags&MAPCHARS
	move.l	d3,a0
	move.l	168(a0),d5
	and.l	#128,d5 		;if(bf==NULL)gotoGETOUT
	tst.l	d3
	beq	RXX10300			;if(((SCB*)bf)->Flags&NEEDPACK)packBuf((SCB*)bf,TRUE)
	move.l	d3,a0
	btst.b	#5,170(a0)
	beq	RXX10301
	move.w	#1,-(sp)
	move.l	d3,-(sp)
	jsr	_packBuf			;getBP((SCB*)bf,1)
	addq.w	#6,sp
RXX10301:
	move.w	#1,-(sp)
	move.l	d3,-(sp)
	jsr	_getBP  		;if(fB==NULL||gB==NULL||*fP==EOFILE||fP==gP)gotoGETOUT
	tst.l	_fB
	addq.w	#6,sp
	beq	RXX10300
	tst.l	_gB
	beq	RXX10300
	move.l	_fP,a0
	cmp.b	#3,(a0)
	beq	RXX10300
	move.l	_fP,a0
	cmp.l	_gP,a0
	beq	RXX10300			;*len=(long)(DATASIZE)*(long)(gB->BlockNum-fB->BlockNum)
							;+(long)(gP-gB->Data)-(long)(fP-fB->Data)
	move.l	_gB,a0
	move.l	_fB,a1
	move.w	246(a0),a0
	sub.w	246(a1),a0
	moveq	#0,d0
	move.w	a0,d0
	move.l	#244,d1
	jsr	.mulu#
	move.l	_gP,d1
	sub.l	_gB,d1
	add.l	d1,d0
	move.l	_fP,d1
	sub.l	_fB,d1
	sub.l	d1,d0
	move.l	d4,a0
	move.l	d0,(a0) 		;z=safeMem(*len)
	move.l	d4,a0
	move.l	(a0),-(sp)
	jsr	_safeMem
	move.l	d0,a3			;if(z==NULL)gotoMEMOUT
	move.l	a3,d0
	addq.w	#4,sp
	beq	RXX10302			;y=z
	move.l	a3,a2			;pushFast((SCB*)bf,&fB,&fP)
	pea	_fP
	pea	_fB
	move.l	d3,-(sp)
	jsr	_pushFast			;while(1){
	lea	12(sp),sp
RXX10303:			;if(fastB==gB&&fastP>=gP)break
	move.l	_fastB,a0
	cmp.l	_gB,a0
	bne	RXX98
	move.l	_fastP,a0
	cmp.l	_gP,a0
	bcc	RXX10304
RXX98:  		;j=*fastP
	move.l	_fastP,a0
	move.b	(a0),d2 		;if(mapit&&j>127)j=unMapIt((short)j)
	tst.l	d5
	beq	RXX10305
	cmp.b	#127,d2
	bls	RXX10305
	moveq	#0,d0
	move.b	d2,d0
	move.w	d0,-(sp)
	jsr	_unMapIt
	move.b	d0,d2			;*(y++)=j
	addq.w	#2,sp
RXX10305:
	move.b	d2,(a2)+			;incFast()
	jsr	_incFast			;}
	bra	RXX10303
RXX10304:			;popFast()
	jsr	_popFast			;}else{/*argMUSTbeliteral*/
	bra	RXX10306
RXX10299:			;y=(UCHAR*)ptrArgs[0]
	move.l	_ptrArgs,a2 		;if(y==NULL||*y==0x00)gotoGETOUT
	move.l	a2,d0
	beq	RXX10300
	tst.b	(a2)
	beq	RXX10300			;*len=strlen(y)
	move.l	a2,-(sp)
	jsr	_strlen
	move.l	d4,a0
	move.l	d0,(a0) 		;z=safeMem(*len)
	move.l	d4,a0
	move.l	(a0),-(sp)
	jsr	_safeMem
	move.l	d0,a3			;if(z==NULL){MEMOUT:memoryMsg()gotoGETOUT}
	move.l	a3,d0
	addq.w	#8,sp
	bne	RXX10307
RXX10302:
	jsr	_memoryMsg
	bra	RXX10300			;zz=(long)z
RXX10307:
	move.l	a3,d6			;while(*y)*(z++)=*(y++)
RXX10308:
	tst.b	(a2)
	beq	RXX10309
	move.b	(a2)+,(a3)+
	bra	RXX10308
RXX10309:			;z=(long)zz
	move.l	d6,a3			;}
RXX10306:			;GETOUT:
RXX10300:			;return(z)
	move.l	a3,d0
RXX99:
	movem.l	(sp)+,d2-d6/a2/a3
	rts 		;}FstringComp(){

	xdef	_Fprint
_Fprint:
	link	a5,#RXX95
	movem.l	d2-d4/a2/a6,-(sp)			;rtn=FALSE
	moveq	#0,d3			;while(prints>=MAXPRINTS){
RXX10286:
	cmp.w	#12,_prints
	blt	RXX10287			;if(stop())gotoGETOUT
	jsr	_stop
	tst.w	d0
	bne	RXX10288			;doPrinting()
	jsr	_doPrinting 		;}
	bra	RXX10286
RXX10287:			;DOMORE:
RXX10289:			;prts=prints
	move.w	_prints,d2  		;z=exportStr(&len)
	pea	-4(a5)
	jsr	_exportStr
	move.l	d0,a2			;llen=len
	move.l	-4(a5),d4			;if(z==NULL){
	move.l	a2,d0
	addq.w	#4,sp
	bne	RXX10290			;if(llen>0L){
	tst.l	d4
	ble	RXX10291			;if(prts==0)rtn=slowPrint()
	tst.w	d2
	bne	RXX10292
	jsr	_slowPrint
	move.w	d0,d3			;else{
	bra	RXX10293
RXX10292:			;prts--
	subq.w	#1,d2			;while(prts<prints){
RXX10294:
	cmp.w	_prints,d2
	bge	RXX10295			;if(stop())gotoGETOUT
	jsr	_stop
	tst.w	d0
	bne	RXX10288			;doPrinting()
	jsr	_doPrinting 		;}
	bra	RXX10294
RXX10295:			;gotoDOMORE
	bra	RXX10289			;}
RXX10293:			;}gotoGETOUT
RXX10291:
	bra	RXX10288
RXX10290:
	move.w	d2,d0			 ;}printBuf[prts]=z
	asl.w	#2,d0
	lea	_printBuf,a0
	move.l	a2,(a0,d0.w)

	lea	_printLen,a0			;printLen[prts]=llen
	move.l	d4,(a0,d0.w)

	lea	_printByte,a0			 ;printByte[prts]=0L
	clr.l	(a0,d0.w)

	move.l	_prefPrint,d0
	and.l	#3,d0
	move.w	d2,d1			;printChoice[prts]=prefPrint&3
	add.w	d1,d1
	lea	_printChoice,a0
	move.w	d0,(a0,d1.w)

	move.l	_bufPtrArgs,a0  		  ;printTable[prts]=bufPtrArgs[0]->tabTable
	lea	_printTable,a1
	move.w	176(a0),(a1,d1.w)

	move.w	d2,d0			;prints=prts+1
	addq.w	#1,d0
	move.w	d0,_prints  		;setTitle()

	jsr	_setTitle			;rtn=TRUE
	moveq	#1,d3			;GETOUT:
RXX10288:			;return(rtn)
	move.w	d3,d0
RXX96:
	movem.l	(sp)+,d2-d4/a2/a6
	unlk	a5
	rts 		;}
RXX95:	equ	-4  		;unMapIt(Rshortch){

	xdef	_importStr
_importStr:
	link	a5,#RX63
	movem.l	d2-d7/a2/a3/a6,-(sp)
	move.l	8(a5),a3
	move.l	12(a5),d6
	move.l	16(a5),d7			;flag=(bufPtr->Flags&READONLY)
	move.l	168(a3),d3
	and.l	#16,d3  		;p=*ptr
	move.l	d7,a0
	move.l	(a0),a2 		;b=*block
	move.l	d6,a0
	move.l	(a0),-4(a5) 		;mapFlag=bufPtr->Flags&MAPCHARS
	move.l	168(a3),d5
	and.l	#128,d5 		;gotoHITME/*pispointingtoeofifnewbuf*/
	bra	RX10205 		;TOP:
RX10206:			;ch=*(buff++)
	move.l	20(a5),a0
	add.l	#1,20(a5)
	move.b	(a0),d2 		;if(ch>13)gotoBUMP
	cmp.b	#13,d2
	bhi	RX10207 		;if(ISWEIRD(ch)){
	cmp.b	#3,d2
	bhi	RX10208 		;if(mapFlag){
	tst.l	d5
	beq	RX10209 		;ch=charMappings[ch]
	moveq	#0,d0
	move.b	d2,d0
	asl.l	#2,d0
	lea	_charMappings,a0
	move.b	3(a0,d0.l),d2			;gotoBUMP
	bra	RX10207 		;}if(!flag){
RX10209:
	tst.l	d3
	bne	RX10210 		;if(!yesNo("Mustwipeillegalchars.","Loadanyway?"))gotoFRTN
	pea	RX58+26
	pea	RX58+0
	jsr	_yesNo
	tst.w	d0
	addq.w	#8,sp
	beq	RX10211 		;flag=READONLY
	moveq	#16,d3  		;}ch='@'
RX10210:
	moveq	#64,d2  		;gotoBUMP
	bra	RX10207 		;}if(ch==eol){
RX10208:
	cmp.b	_eol,d2
	bne	RX10212 		;if(b->eols<255)b->eols++
	move.l	-4(a5),a0
	cmp.b	#255,245(a0)
	bcc	RX10213
	move.l	-4(a5),a0
	add.b	#1,245(a0)  		;gotoBUMP
RX10213:
	bra	RX10207 		;}if(ch==12)b->eols=255
RX10212:
	cmp.b	#12,d2
	bne	RX10214
	move.l	-4(a5),a0
	move.b	#255,245(a0)			;BUMP:
RX10214:
RX10207:			;*(p++)=ch
	move.b	d2,(a2)+			;i--
	sub.l	#1,24(a5)			;HITME:
RX10205:			;if(*p==EOB){
	cmp.b	#2,(a2)
	bne	RX10215 		;if(!newBlock(bufPtr,&b,b)){
	move.l	-4(a5),-(sp)
	pea	-4(a5)
	move.l	a3,-(sp)
	jsr	_newBlock
	tst.w	d0
	lea	12(sp),sp
	bne	RX10216 		;if(noMemory&&saves){
	tst.w	_noMemory
	beq	RX10217
	tst.w	_saves
	beq	RX10217 		;j=saves-1
	move.w	_saves,d4
	sub.w	#1,d4			;while(j!=saves)doSaving()
RX10218:
	cmp.w	_saves,d4
	beq	RX10219
	jsr	_doSaving
	bra	RX10218
RX10219:			;noMemory=stopPause=0
	clr.w	_stopPause
	clr.w	_noMemory			;gotoHITME
	bra	RX10205 		;}gotoFRTN
RX10217:
	bra	RX10211 		;}p=b->Data
RX10216:
	move.l	-4(a5),a2			;}if(i>0L)gotoTOP
RX10215:
	tst.l	24(a5)
	bgt	RX10206 		;bufPtr->Flags|=flag
	lea	168(a3),a0
	or.l	d3,(a0) 		;*block=b
	move.l	d6,a0
	move.l	-4(a5),(a0) 		;*ptr=p
	move.l	d7,a0
	move.l	a2,(a0) 		;return(TRUE)
	moveq	#1,d0
RX64:
	movem.l	(sp)+,d2-d7/a2/a3/a6
	unlk	a5
	rts 		;FRTN:
RX10211:			;return(FALSE)
	moveq	#0,d0
	bra	RX64			;}
RX63:	equ	-4
RX58:
	dc.b	77,117,115,116,32,119,105,112,101,32,105,108,108,101,103
	dc.b	97,108,32,99,104,97,114,115,46,0,87,32,76,111,97
	dc.b	100,32,97,110,121,119,97,121,63,0
	ds	0			;saveFile(RSCB*bufPtr){

	xdef	_saveFile
_saveFile:
	move.l	a2,-(sp)
	move.l	8(sp),a2			;if(bufPtr==NULL)gotoFRTN
	move.l	a2,d0
	beq	RX10220 		;if(bufPtr->Flags&LOCKED)gotoFRTN
	btst.b	#6,170(a2)
	bne	RX10220 		;if(bufPtr->Flags&READONLY){
	btst.b	#4,171(a2)
	beq	RX10221 		;MSG:
RX10222:			;oneMsg("Read-only,empty,orbadname")
	pea	RX65+0
	jsr	_oneMsg 		;gotoFRTN
	addq.w	#4,sp
	bra	RX10220 		;}if(ISWEIRD(*(bufPtr->NextBlock->Data)))gotoMSG
RX10221:
	move.l	160(a2),a0
	cmp.b	#3,(a0)
	bls	RX10222 		;if(*(bufPtr->FileName)<='')gotoMSG
	cmp.b	#32,196(a2)
	bls	RX10222 		;if(!push(&sStack,(long)bufPtr))gotoFRTN
	move.l	a2,-(sp)
	pea	_sStack
	jsr	_push
	tst.w	d0
	addq.w	#8,sp
	beq	RX10220 		;saves++
	addq.w	#1,_saves			;bufPtr->Flags|=LOCKED/*=====(LOCKED|READONLY)*/
	lea	168(a2),a0
	bset.b	#6,2(a0)			;bufPtr->Flags&=~CHANGED/*sotheycancloseitfreely*/
	lea	168(a2),a0
	bclr.b	#0,2(a0)			;setTitle()
	jsr	_setTitle			;return(TRUE)
	moveq	#1,d0
RX66:
	move.l	(sp)+,a2
	rts 		;FRTN:
RX10220:			;return(FALSE)
	moveq	#0,d0
	bra	RX66			;}
RX65:
	dc.b	82,101,97,100,45,111,110,108,121,44,32,101,109,112,116
	dc.b	121,44,32,111,114,32,98,97,100,32,110,97,109,101,0
	ds	0			;voidallocFb(){

	xdef	_allocFb
_allocFb:
	move.l	a6,-(sp)		;fbb=(SFileInfoBlock*)AllocMem((long)sizeof(SFileInfoBlock),
							;							   (long)MEMF_CLEAR)
	move.l	#65536,d1
	move.l	#260,d0
	move.l	_SysBase#,a6
	jsr	-198(a6)
	move.l	d0,_fbb 		;}
RX68:
	move.l	(sp)+,a6
	rts 		;voidfreeFb(){

	xdef	_freeFb
_freeFb:
	move.l	a6,-(sp) ;if(fbb!=NULL)FreeMem(fbb,(long)sizeof(SFileInfoBlock))
	tst.l	_fbb
	beq	RX10223
	move.l	#260,d0
	move.l	_fbb,a1
	move.l	_SysBase#,a6
	jsr	-210(a6)			;fbb=NULL
RX10223:
	clr.l	_fbb			;}
RX69:
	move.l	(sp)+,a6
	rts 		;voidsetProtect(){

	xdef	_setProtect
_setProtect:
	movem.l	d2/d3/a2/a3/a6,-(sp)			;xx=(long)protectFile
	move.l	_protectFile,d2 		;if(x!=0L){
;;;	tst.l	d2
	beq	RX10224 		;allocFb()
	jsr	_allocFb			;fb=fbb
	move.l	_fbb,a2 		;if(fb==NULL)gotoNOPROT
	move.l	a2,d0
	beq	RX10225 		;val=(long)Lock((char*)x,(long)SHARED_LOCK)
	move.l	d2,-(sp)
	moveq	#-2,d2
	move.l	0(sp),d1
	move.l	_DOSBase#,a6
	jsr	-84(a6)
	move.l	(sp)+,d2
	move.l	d0,d3			;if(Examine((UCHAR*)val,fb)){
	move.l	d2,-(sp)
	move.l	a2,d2
	move.l	d3,d1
	move.l	_DOSBase#,a6
	jsr	-102(a6)
	move.l	(sp)+,d2
	tst.l	d0
	beq	RX10226 		;UnLock((UCHAR*)val)
	move.l	d3,d1
	move.l	_DOSBase#,a6
	jsr	-90(a6) 		;if(fb->fib_EntryType<0L){
	tst.l	120(a2)
	bge	RX10227 		;y=protectComment
	lea	_protectComment,a0
	move.l	a0,a3			;y[79]=0x00
	clr.b	79(a3)  		;SetComment((UCHAR*)x,y)
	move.l	d2,-(sp)
	move.l	a3,d2
	move.l	0(sp),d1
	move.l	_DOSBase#,a6
	jsr	-180(a6)
	move.l	(sp)+,d2			;SetProtection((UCHAR*)x,protect)
	move.l	d2,-(sp)
	move.l	_protect,d2
	move.l	0(sp),d1
	move.l	_DOSBase#,a6
	jsr	-186(a6)
	move.l	(sp)+,d2			;}}
RX10227:			;freeFb()
RX10226:
	jsr	_freeFb 		;}NOPROT:
RX10224:
RX10225:			;protectFile=NULL
	clr.l	_protectFile			;}
RX70:
	movem.l	(sp)+,d2/d3/a2/a3/a6
	rts 		;FsaveFile(){

	xdef	_FsaveFile
_FsaveFile:
	                ;return(saveFile(bufPtrArgs[0]))/*saveFileprotects!*/
	move.l	_bufPtrArgs,-(sp)
	jsr	_saveFile
	addq.w	#4,sp
RX71:
	rts 		;}voidbadSave(UCHAR*x){

	xdef	_badSave
_badSave:
	                ;passiveMsg("Filesaveerror/abort",x,0L)
	clr.l	-(sp)
	move.l	12(sp),-(sp)
	pea	RX67+0
	jsr	_passiveMsg 		;}
	lea	12(sp),sp
RX72:
	rts
RX67:
	dc.b	70,105,108,101,32,115,97,118,101,32,101,114,114,111,114
	dc.b	47,97,98,111,114,116,32,0
	ds	0			;voidgetSave(){

	xdef	_getSave
_getSave:
	movem.l	d2/d3/a6,-(sp)  		;if(saveBuf!=NULL)gotoSEEIT
	tst.l	_saveBuf
	bne	RX10228 		;GETNEXT:
RX10229:			;if(!pop(&sStack,&saveBuf))return
	pea	_saveBuf
	pea	_sStack
	jsr	_pop
	tst.w	d0
	addq.w	#8,sp
	bne	RX10230
RX74:
	movem.l	(sp)+,d2/d3/a6
	rts 		;if(saveBuf==NULL)return
RX10230:
	tst.l	_saveBuf
	bne	RX10231
	bra	RX74			;saveBuf->Flags|=READONLY
RX10231:
	move.l	_saveBuf,a0
;;;	add.l	#168,a0
	bset.b	#4,171(a0)  		  ;SEEIT:
RX10228:			;flags=saveBuf->Flags
	move.l	_saveBuf,a0
	move.l	168(a0),d3  		;if(flags&CHANGED){
	btst.l	#8,d3
	beq	RX10232 		;if(flags&DELETEIT)gotoRETACH
	btst.l	#15,d3
	bne	RX10233 		;passiveMsg("NOTsaved:",saveBuf->FileName,0L)
	clr.l	-(sp)
	move.l	_saveBuf,a0
	add.l	#196,a0
	move.l	a0,-(sp)
	pea	RX73+0
	jsr	_passiveMsg 		;gotoNEXT1
	lea	12(sp),sp
	bra	RX10234 		;}if(flags&LOCKED)return/*alreadyqueued?*/
RX10232:
	btst.l	#14,d3
	beq	RX10235
	bra	RX74			;if(saveFd!=NULL){Close(saveFd)saveFd=NULL}
RX10235:
	tst.l	_saveFd
	beq	RX10236
	move.l	_saveFd,d1
	move.l	_DOSBase#,a6
	jsr	-36(a6)
	clr.l	_saveFd 		;if(!(flags&DELETEIT)){/*notlocked*/
RX10236:
	btst.l	#15,d3
	bne	RX10237 		;NEXT1:
RX10234:			;saveBuf->Flags&=~(ULONG)(DELETEIT|LOCKED|READONLY/*|CHANGED*/)
	move.l	_saveBuf,a0
;;;	add.l	#168,a0
	and.l	#-49169,168(a0) 		   ;NEXT2:
RX10238:			;saves--
	sub.w	#1,_saves			;setTitle()
	jsr	_setTitle			;saveBuf=NULL
	clr.l	_saveBuf			;gotoGETNEXT
	bra	RX10229 		;}if(!(flags&READONLY)){/*delete&goodsave*/
RX10237:
	btst.l	#4,d3
	bne	RX10239 		;DELIT:
RX10240:			;saveBuf->Flags=0
	move.l	_saveBuf,a0
	clr.l	168(a0) 		;buf[ALLBUFS]=saveBuf
	move.l	_saveBuf,_buf+400			;freeBuf(ALLBUFS)
	move.w	#100,-(sp)
	jsr	_freeBuf			;gotoNEXT2
	addq.w	#2,sp
	bra	RX10238 		;}RETACH:
RX10239:
RX10233:			;/*delete&badsave*/for(i=0i<ALLBUFSi++)if(buf[i]==NULL){
	moveq	#0,d2
	bra	RX10244
RX10243:
	move.w	d2,d0
;;;	ext.l	d0
	asl.w	#2,d0
	lea	_buf,a0
	tst.l	(a0,d0.w)
	bne	RX10245 		;buf[i]=saveBuf
;;;	move.w	d2,d0
;;;	ext.l	d0
;;;	asl.l	#2,d0
;;;	lea	_buf,a0
	move.l	_saveBuf,(a0,d0.w)  		;saveBuf->BufNum=i
	move.l	_saveBuf,a0
	move.w	d2,166(a0)  		;switchFast()
	jsr	_switchFast 		;displayFlag|=(PAGE_<<curSplit)
	moveq	#16,d0
	move.w	_curSplit,d1
	asl.w	d1,d0
	or.w	d0,_displayFlag 		;display()
	jsr	_display			;badSave(saveBuf->FileName)
	move.l	_saveBuf,a0
	add.l	#196,a0
	move.l	a0,-(sp)
	jsr	_badSave			;stopPause=TRUE
	move.w	#1,_stopPause			;gotoNEXT1
	addq.w	#4,sp
	bra	RX10234 		;}gotoDELIT
RX10245:
RX10241:
	addq.w	#1,d2
RX10244:
	cmp.w	#100,d2
	blt	RX10243
RX10242:
	bra	RX10240 		;}
RX73:
	dc.b	78,79,84,32,115,97,118,101,100,58,32,0
	ds	0			;FabortSave(){

	xdef	_FabortSave
_FabortSave:
	                ;return(stopSave=(saves>0)?TRUE:FALSE)
	tst.w	_saves
	ble	RX76
	moveq	#1,d0
	bra	RX77
RX76:
	moveq	#0,d0
RX77:
	move.w	d0,_stopSave
RX78:
	rts 		;}FloadFile(){

	xdef	_FloadFile
_FloadFile:
	move.l	a2,-(sp) 		;RUCHAR*yy=fixString('',0,NAMELEN-4)
	move.w	#76,-(sp)
	clr.w	-(sp)
	move.w	#32,-(sp)
	jsr	_fixString
	move.l	d0,a2			;if(y!=NULL&&startFile(y)>=0)return(TRUE)
	move.l	a2,d0
	addq.w	#6,sp
	beq	RX10246
	move.l	a2,-(sp)
	jsr	_startFile
	tst.w	d0
	addq.w	#4,sp
	blt	RX10246
	moveq	#1,d0
RX79:
	move.l	(sp)+,a2
	rts 		;return(FALSE)
RX10246:
	moveq	#0,d0
	bra	RX79			;}FinsertFile(){

	xdef	_FinsertFile
_FinsertFile:
	link	a5,#RX80
	movem.l	d2-d4/a2/a3/a6,-(sp) 		;bufPtr=bufPtrArgs[0]
	move.l	_bufPtrArgs,a2  		;bufnum=(short)*longPtrArgs[0]
	move.l	_longPtrArgs,a0
	move.w	2(a0),d2			;z=(long)fixString('',2,NAMELEN-4)
	move.w	#76,-(sp)
	move.w	#2,-(sp)
	move.w	#32,-(sp)
	jsr	_fixString
	move.l	d0,d4			;if(!findFile((UCHAR*)z))gotoFALSERTN
	move.l	d4,-(sp)
	jsr	_findFile
	tst.w	d0
	lea	10(sp),sp
	beq	RX10247 		;if(bufPtr==NULL){
	move.l	a2,d0
	bne	RX10248 		;newBuff=1
	moveq	#1,d3			;if(newBuf(bufnum,&b2)<0)gotoFALSERTN
	pea	-4(a5)
	move.w	d2,-(sp)
	jsr	_newBuf
	tst.w	d0
	addq.w	#6,sp
	blt	RX10247 		;bufPtr=(SCB*)b2
	move.l	-4(a5),a2			;b1=NULL
	sub.l	a3,a3			;}else{
	bra	RX10249
RX10248:			;newBuff=0
	moveq	#0,d3			;if(!canChange(bufPtr))gotoFALSERTN
	move.l	a2,-(sp)
	jsr	_canChange
	tst.w	d0
	addq.w	#4,sp
	beq	RX10247 		;if(!getBuf(bufnum))gotoFALSERTN
	move.w	d2,-(sp)
	jsr	_getBuf
	tst.w	d0
	addq.w	#2,sp
	beq	RX10247 		;getBP(bufPtr,1)/*locationatwhichtoinsertdata*/
	move.w	#1,-(sp)
	move.l	a2,-(sp)
	jsr	_getBP  		;b1=gB
	move.l	_gB,a3  		;if(b1==NULL||!splitBlock(bufPtr,b1,gP))gotoFALSERTN
	move.l	a3,d0
	addq.w	#6,sp
	beq	RX10247
	move.l	_gP,-(sp)
	move.l	a3,-(sp)
	move.l	a2,-(sp)
	jsr	_splitBlock
	tst.w	d0
	lea	12(sp),sp
	beq	RX10247 		;b1=b1->NextBlock
	move.l	252(a3),a3  		;}
RX10249:			;if(!readFile((UCHAR*)z,bufPtr,b1,newBuff))gotoFALSERTN/*freedthere*/
	move.w	d3,-(sp)
	move.l	a3,-(sp)
	move.l	a2,-(sp)
	move.l	d4,-(sp)
	jsr	_readFile
	tst.w	d0
	lea	14(sp),sp
	beq	RX10247 		;splitFlag(bufnum,PAGE_)
	move.w	#16,-(sp)
	move.w	d2,-(sp)
	jsr	_splitFlag  		;fixSOF(bufPtr)
	move.l	a2,-(sp)
	jsr	_fixSOF 		;if(newBuff){/*setcursortofront*/
	tst.w	d3
	addq.w	#8,sp
	beq	RX10250 		;bufPtr->Ptr=(UCHAR*)bufPtr->NextBlock
	move.l	160(a2),80(a2)  		;bufPtr->Block=bufPtr->NextBlock
	move.l	160(a2),(a2)			;}return(TRUE)
RX10250:
	moveq	#1,d0
RX81:
	movem.l	(sp)+,d2-d4/a2/a3/a6
	unlk	a5
	rts 		;FALSERTN:
RX10247:			;return(FALSE)
	moveq	#0,d0
	bra	RX81			;}
RX80:	equ	-4  		;voidclosePrt(){

	xdef	_closePrt
_closePrt:
	move.l	a6,-(sp)			;if(fdprt!=NULL)Close(fdprt)
	tst.l	_fdprt
	beq	RX10251
	move.l	_fdprt,d1
	move.l	_DOSBase#,a6
	jsr	-36(a6) 		;if(prtOpen)CloseDevice(prtMsg)
RX10251:
	tst.w	_prtOpen
	beq	RX10252
	move.l	_prtMsg,a1
	move.l	_SysBase#,a6
	jsr	-450(a6)			;if(prtMsg)DeleteExtIO(prtMsg,(long)sizeof(SIODRPReq))
RX10252:
	tst.l	_prtMsg
	beq	RX10253
;;;	pea	62
	move.l	_prtMsg,-(sp)
	jsr	_DeleteExtIO			;if(prtPort)DeletePort(prtPort)
    addq.w  #4,sp
;;;	addq.w	#8,sp
RX10253:
	tst.l	_prtPort
	beq	RX10254
	move.l	_prtPort,-(sp)
	jsr	_DeletePort 		;prtOpen=FALSE
	addq.w	#4,sp
RX10254:
	clr.w	_prtOpen			;prtMsg=NULL
	clr.l	_prtMsg 		;prtPort=NULL
	clr.l	_prtPort			;fdprt=NULL
	clr.l	_fdprt  		;}
RX82:
	move.l	(sp)+,a6
	rts 		;voidtransPrint(RUCHAR*p){

	xdef	_transPrint
_transPrint:
	movem.l	a2/a3/a6,-(sp)
	move.l	16(sp),a3			;RSIOPrtCmdReq*pMsgpMsg=(SIOPrtCmdReq*)prtMsg
	move.l	_prtMsg,a2  		;pMsg->io_Command=PRD_PRTCOMMAND
	move.w	#10,28(a2)  		;pMsg->io_PrtCommand=p[0]
	moveq	#0,d0
	move.b	(a3),d0
	move.w	d0,32(a2)			;pMsg->io_Parm0=p[1]
	move.b	1(a3),34(a2)			;pMsg->io_Parm1=p[2]
	move.b	2(a3),35(a2)			;pMsg->io_Parm2=0
	clr.b	36(a2)  		;pMsg->io_Parm3=0
	clr.b	37(a2)  		;DoIO(pMsg)
	move.l	a2,a1
	move.l	_SysBase#,a6
	jsr	-456(a6)			;}
RX83:
	movem.l	(sp)+,a2/a3/a6
	rts 		;printRaw(RUCHAR*p){

	xdef	_doPrinting
_doPrinting:
	movem.l	d2-d4/a2/a3,-(sp) 		;if(prints<=0)return
	tst.w	_prints
	bgt	RX10266
RX92:
	movem.l	(sp)+,d2-d4/a2/a3
	rts 		;if(fdprt==NULL&&prtOpen==0&&!openPrt(printChoice[0])){
RX10266:
	tst.l	_fdprt
	bne	RX10267
	tst.w	_prtOpen
	bne	RX10267
	move.w	_printChoice,-(sp)
	jsr	_openPrt
	tst.w	d0
	addq.w	#2,sp
	bne	RX10267 		;FabortPrint()
	jsr	_FabortPrint			;return
	bra	RX92			;}byte=printByte[0]
RX10267:
	move.l	_printByte,d3			;len=printLen[0]
	move.l	_printLen,d4			;if(byte>=len)gotoDONE
	cmp.l	d4,d3
	bge	RX10268 		;z=(UCHAR*)""
	lea	RX75,a3 		;ptr=printBuf[0]+byte
	move.l	d3,a2
	add.l	_printBuf,a2			;if(prtOpen&&*ptr==ESC){/*goingthroughPrefs*/
	tst.w	_prtOpen
	beq	RX10269
	cmp.b	#27,(a2)
	bne	RX10269 		;for(i=1i<5i++){
	moveq	#1,d2
	bra	RX10273
RX10272:			;if(ptr[i]==ESC){
	cmp.b	#27,(a2,d2.w)
	bne	RX10274 		;if(i==1)gotoDORAW
	cmp.w	#1,d2
	beq	RX10275 		;z[i-1]=0x00
	clr.b	-1(a3,d2.w) 		;z[i]=0x00
	clr.b	(a3,d2.w)			;transPrint(z)
	move.l	a3,-(sp)
	jsr	_transPrint 		;byte+=(i+1)
	move.l	d2,d0
	addq.l	#1,d0
;;;	ext.l	d0
	add.l	d0,d3			;gotoDONE
	addq.w	#4,sp
	bra	RX10268 		;}if(ptr[i]<'')break
RX10274:
	cmp.b	#32,(a2,d2.w)
	bcs	RX10271 		;z[i-1]=ptr[i]-''
	moveq	#0,d0
	move.b	(a2,d2.w),d0
	sub.w	#32,d0
;;;	add.w	#-32,d0
	move.b	d0,-1(a3,d2.w)  		;}
RX10270:
	addq.w	#1,d2
RX10273:
	cmp.w	#5,d2
	blt	RX10272
RX10271:			;}DORAW:
RX10269:
RX10275:			;byte++
	addq.l	#1,d3			;if(!printRaw(ptr)){
	move.l	a2,-(sp)
	jsr	_printRaw
	tst.w	d0
	addq.w	#4,sp
	bne	RX10276 		;if(yesNo("Can'tprint.","Abortprints?"))while(FabortPrint())
	pea	RX75+18
	pea	RX75+4
	jsr	_yesNo
	tst.w	d0
	addq.w	#8,sp
	beq	RX10277
RX10278:
	jsr	_FabortPrint
	tst.w	d0
	beq	RX10279
	bra	RX10278
RX10279:			;byte--
RX10277:
	sub.l	#1,d3			;}DONE:
RX10276:
RX10268:			;printByte[0]=byte
	move.l	d3,_printByte			;if(byte>=len)FabortPrint()
	cmp.l	d4,d3
	blt	RX10280
	jsr	_FabortPrint			;}
RX10280:
	bra	RX92
RX75:
	dc.b	32,32,0,32,67,97,110,39,116,32,112,114,105,110,116
	dc.b	46,32,0,65,98,111,114,116,32,112,114,105,110,116,115
	dc.b	63,0
	ds	0			;FabortPrint(){

	xdef	_FabortPrint
_FabortPrint:
	movem.l	d2/a6,-(sp) 		;RshorticlosePrt()
	jsr	_closePrt			;if(prints<=0)gotoBRTN
	tst.w	_prints
	ble	RX10281 		;prints--
	sub.w	#1,_prints  		;FreeMem(printBuf[0],printLen[0])
	move.l	_printLen,d0
	move.l	_printBuf,a1
	move.l	_SysBase#,a6
	jsr	-210(a6)			;for(i=0i<(MAXPRINTS-1)i++){
	moveq	#0,d2
	bra	RX10285
RX10284:			;printBuf[i]=printBuf[i+1]
	move.w	d2,d0
	addq.w	#1,d0
	asl.w	#2,d0
	lea	_printBuf,a0
	move.w	d2,d1
	asl.w	#2,d1
	move.l	(a0,d0.w),(a0,d1.w) 		;printLen[i]=printLen[i+1]

	lea	_printLen,a0
	move.l	(a0,d0.w),(a0,d1.w) 		;printChoice[i]=printChoice[i+1]

	lea	_printByte,a0		  ;printByte[i]=0L
	clr.l	(a0,d1.w)

	move.w	d2,d0
	addq.w	#1,d0
	add.w	d0,d0
	lea	_printChoice,a0
	move.w	d2,d1
	add.w	d1,d1
	move.w	(a0,d0.w),(a0,d1.w) 		;printTable[i]=printTable[i+1]

	lea	_printTable,a0
	move.w	(a0,d0.w),(a0,d1.w) 		  ;}

RX10282:
	addq.w	#1,d2
RX10285:
	cmp.w	#11,d2
	blt	RX10284
RX10283:			;setTitle()
	jsr	_setTitle			;return(TRUE)
	moveq	#1,d0
RX94:
	movem.l	(sp)+,d2/a6
	rts 		;BRTN:
RX10281:			;return(FALSE)
	moveq	#0,d0
	bra	RX94			;}Fprint(){

	xdef	_FstringComp
_FstringComp:
	movem.l	d2/a2/a3,-(sp)			;x=fixString(0,1,127)
	move.w	#127,-(sp)
	move.w	#1,-(sp)
	clr.w	-(sp)
	jsr	_fixString
	move.l	d0,a2			;y=fixString(0,2,127)
	move.w	#127,-(sp)
	move.w	#2,-(sp)
	clr.w	-(sp)
	jsr	_fixString
	move.l	d0,a3			;if(x==NULL||y==NULL)gotoFRTN
	move.l	a2,d0
	lea	12(sp),sp
	beq	RX10310
	move.l	a3,d0
	beq	RX10310 		;if(*(longPtrArgs[3])){
	move.l	_longPtrArgs+12,a0
	tst.l	(a0)
	beq	RX10311 		;toLower(x)
	move.l	a2,-(sp)
	jsr	_toLower			;toLower(y)
	move.l	a3,-(sp)
	jsr	_toLower			;}val=strcmp(x,y)
	addq.w	#8,sp
RX10311:
	move.l	a3,-(sp)
	move.l	a2,-(sp)
	jsr	_strcmp
	move.w	d0,d2			;*(longPtrArgs[0])=val
	move.w	d2,a0
	move.l	_longPtrArgs,a1
	move.l	a0,(a1) 		;if(val==0)return(TRUE)
	tst.w	d2
	addq.w	#8,sp
	bne	RX10312
	moveq	#1,d0
RX100:
	movem.l	(sp)+,d2/a2/a3
	rts 		;FRTN:
RX10312:
RX10310:			;return(FALSE)
	moveq	#0,d0
	bra	RX100			;}
#endasm
#endif

