.MCall .Module .Module KEDCM2 RELEASE=V02 VERSION=16 COMMENT=,IDENT=NO,AUDIT=NO,GLOBAL=.KEDC2 ; Copyright (c) 1998 by Mentec, Inc., Nashua, NH. ; All rights reserved ; ; This software is furnished under a license for use only on a ; single computer system and may be copied only with the ; inclusion of the above copyright notice. This software, or ; any other copies thereof, may not be provided or otherwise ; made available to any other person except for use on such ; system and to one who agrees to these license terms. Title ; to and ownership of the software shall at all times remain ; in Mentec, Inc. ; ; The information in this document is subject to change without ; notice and should not be construed as a commitment by Digital ; Equipment Corporation, or Mentec, Inc. ; ; Digital and Mentec assume no responsibility for the use or ; reliability of its software on equipment which is not supplied ; by Digital or Mentec, and listed in the Software Product ; Description. ;+ ;COND ; $KED$ controls .page and .sbttl for text extracted and ; placed in KEDERR and KEDHLP ; ; no conditional assembly that affects generated code ;- ; ;MODULE: KEDCM2 ; ;ABSTRACT: ; ; This command module contains routines to implement word fill ; and the cut and paste related commands. ; ;AUTHOR: Darrell Duffy ; ;DATE: 3-July-1979 ; ;REVISION HISTORY: ; .Enable LC .Enable GBL .SbTtl Error Macro Definitions ;+ ;ERROR ; .IIf NDF,$KED$, .Page .IIf NDF,$KED$, .SbTtl Errors from KEDCM2 module ; ; Module: KEDCM2 ; ; Define the error messages for this module ; .MCall ErrDef ErrDef C2,ERROR ;- ;+ ;HELPER ; .IIf NDF,$KED$, .Page .IIf NDF,$KED$, .SbTtl Help from KEDCM2 module ; ; Module: KEDCM2 ; ; Define the help macros for this module ; .MCall HlpDef HlpDef C2 ;- .SbTtl .SbTtl WFILL - Word fill .SbTtl C.FILL - ;++ ;WFILL, C.FILL ; ;FUNCTIONAL DESCRIPTION: ; ; Word fill the select range by wrapping it to the specified column ; ;INPUT: ; Select range active ; ;OUTPUT: ; Lines filled with words and wrapped to column set in WRAPC ; CR'S ignored, LF'S changed to spaces, FF and VT to CRLF FF or VT ; cursor at end of range. ;-- .Enable LSB C.Fill:: ;~x~ EndChk ;~x~Validate command line termination WFill:: ;~x~ Tst Inspct ;Inspect mode Bne 140$ ;~x~Inspect mode enabled Tst SlctQ ;Select range enabled Beq 150$ ;~x~Nope Mov SP,SlctQ ;Save the stack pointer Clr Un$Blk ;Turn off undelete saving Mov SlctC,R3 ;Get select range counter Mov SlctC+2,R4 ; Bgt 10$ ;~x~Move to beginning Blt 30$ ;~x~We are at beginning Tst R3 ;Small counts Beq 150$ ;~x~No count 10$: Mov R4,R2 ;~x~Go to beginning Mov R3,R1 20$: Call MvBkw ;~x~Back to start Bcs FilErr ;~x~Too bad Sob R1,20$ ;~x~Til count exhausted Dec R2 ;High part Bpl 20$ ;~x~ Br 50$ ;~x~ ........... 30$: Neg R4 ;~x~Make count plus Neg R3 ;The easy way Sbc R4 Br 50$ ;~x~Start by counting ........... 40$: Call FMvFwd ;~x~Advance and count 50$: Call Count ;~x~Count our present column 60$: MovB @FCP,R0 ;~x~Get next char to look at CmpB R0,# ;Space is magic Blo 70$ ;~x~Control chars are special Beq 120$ ;~x~Delete multiple spaces Cmp R2,WrapC ;Time to wrap?? Blo 130$ ;~x~Nope Call WrapIt ;~x~Wrap the line Bcs FilErr ;~x~Report error Tst R1 ;Did we wrap a word? Beq 100$ ;~x~Yes so strip leading spaces Br 40$ ;~x~Advance over the character .......... 70$: CmpB R0,# ;~x~If CR Bne 90$ ;~x~Nope 80$: Call FDlChr ;~x~Delete it Br 60$ ;~x~And go get the next char ........ 90$: CmpB R0,# ;~x~If tab Blo 130$ ;~x~Control chars are one column Beq 110$ ;~x~Get rid of it CmpB R0,# ;If LF Beq 110$ ;~x~Get rid of it CmpB R0,# ;FF and VT are special too Bhi 130$ ;~x~Recount on all other control chars Call FNewL ;~x~Insert a CRLF Call FMvFwd ;~x~Move over terminator 100$: CmpB @FCP,# ;~x~Strip off leading spaces from next Bne 50$ ;~x~Done Call FDlChr ;~x~Delete a space Br 100$ ;~x~And another ......... 110$: MovB #,@FCP ;~x~Make LF a space 120$: CmpB @BCP,# ;~x~If prevous char a space Beq 80$ ;~x~Then delete it 130$: Call FMvFwd ;~x~Move over one char Inc R2 ;Count one more column Br 60$ ;~x~Carry on to next char ........ 140$: ;~x~ Jmp NoInsp ;~x~then tell operation is invalid .............. 150$: ;~x~ ;+ ;HELPER HELPER ;~x~ ;- .Dsabl LSB .SbTtl FNEWL - Insert a newline character for fill ;++ ;FNEWL ; ;FUNCTIONAL DESCRIPTION: ; ; Insert a newline character for word fill routines ; ;INPUT: NONE ; ;OUTPUT: ; CR LF inserted unless error signaled ;-- .Enable LSB FNewL: Call InsNL ;~x~Insert a newline Bcc 20$ ;~x~Ok Call 40$ ;~x~Signal error Br 30$ ;~x~ ........... .SbTtl FMVFWD - Move forward for fill ;++ ;FMVFWD ; ;FUNCTIONAL DESCRIPTION: ; ; Move forward for fill routines ; ;INPUT: NONE ; ;OUTPUT: ; Move forward one character and signal error ; properly for fill routines ;-- FMvFwd: Call MvFwd ;~x~Move forward Br 10$ ;~x~Count the char ........... .SbTtl FDLCHR - Delete character right for fill ;++ ;FDLCHR ; ;FUNCTIONAL DESCRIPTION: ; ; Delete a character to the right for fill routines ; ;INPUT: NONE ; ;OUTPUT: ; One character deleted to the right or error signaled ;-- FDlChr: Call DlChr ;~x~Delete right a char 10$: Bcs FilErr ;~x~Error Dec R3 ;Keep count Bne 20$ ;~x~Ok Dec R4 Bmi 30$ ;~x~All done 20$: Return ;~x~ ...... .SbTtl FILERR - Signal error for fill ;++ ;FILERR ; ;FUNCTIONAL DESCRIPTION: ; ; Signal error for fill routines ; ;INPUT: ; SLCTQ = stack pointer to restore ; ;OUTPUT: ; SLCTQ cleared to remove select range ;-- FilErr: Call 50$ ;~x~Error of the first kind 30$: Mov SlctQ,SP ;~x~*C* Restore stack Bic SP,SlctQ ;*C* Clear selectq Return ;~x~*C* ...... ; ; Error messages for fill routines ; 40$: ;~x~ ;+ ;HELPER HELPER ;~x~ ;- 50$: ;~x~ ;+ ;HELPER HELPER ;~x~ ;- .Dsabl LSB .SbTtl C.CCAS - Change case of select range ; ; C.CCAS -- change case of select range ; .Enable LSB C.CCas:: ;~x~ Mov #SWCase,XCase ;~x~indicate Switch case request Br 10$ ;~x~ ........... C.UCas:: ;~x~ Mov #UPCase,XCase ;~x~indicate uppercase request Br 10$ ;~x~ ........... C.LCas:: ;~x~ Mov #DNCase,XCase ;indicate lowercase request 10$: ;~x~ Tst Inspct ;Inspect mode? Bne 110$ ;~x~If so, illegal function? Call SetRng ;~x~Setup a range Bcc 20$ ;~x~Br if range setup Tst SlctQ ;Else check for empty select range Bne 100$ ;~x~Error if so Br 120$ ;~x~Else change current character ........... ;>>> consider moving 120$ code to here 20$: Mov SlctC,R1 ;~x~Get range Mov SlctC+2,R2 ;As a dp number Call CanSlc ;~x~Clear range Tst R2 ;Set CC's on high order count Bpl 50$ ;~x~Backward Neg R2 ;Make dp count plus Neg R1 ;With some dp magic Sbc R2 ;That works Mov R2,R4 ;Save the count for move back here Mov R1,R3 ;To leave cursor in same place 30$: MovB @FCP,-(SP) ;~x~Save char to change Call MvFwd ;~x~Move to see if its ok MovB (SP)+,R0 ;Get char from safe place Bcs 90$ ;~x~LOgic error - select range ;inconsistant Call @XCase ;~x~do requested casing operation MovB R0,@BCP ;Put char back in buffer at ;correct place Sob R1,30$ ;~x~A quick and dirty double prec count Dec R2 ;Dec high order Bpl 30$ ;~x~And go back if there are more 40$: Call MvBkw ;~x~Now move back where we were Bcs 90$ ;~x~Logic error or Ctrl/C Sob R3,40$ ;~x~A quick and dirty double prec count Dec R4 ;High word Bpl 40$ ;~x~Many many more Br 80$ ;~x~Now go home ........... 50$: Mov R1,R3 ;~x~Save count for return Mov R2,R4 ;To here after work 60$: MovB @BCP,-(SP) ;~x~Save char to switch Call MvBkw ;~x~Move back a char MovB (SP)+,R0 ;Get the char Bcs 90$ ;~x~Logic error or Ctrl/C stop Call @XCase ;~x~do requested casing operation MovB R0,@FCP ;Store char in text buffer Sob R1,60$ ;~x~A quick and dirty double prec count Dec R2 ;Reduce high order Bpl 60$ ;~x~Still lots more to go 70$: Call MvFwd ;~x~Move back to where we were Bcs 90$ ;~x~Stopped or logic error Sob R3,70$ ;~x~A quick and dirty double prec count Dec R4 ;Thing and then doing a change case ;on it Bpl 70$ ;~x~Keep going ... 80$: Clc ;~x~Return no error Return ;~x~ ...... 90$: ;~x~ ;+ ;HELPER HELPER ;~x~ ;This entry will be taken by logic errors in change case and select mode ;as well as CTRL/C stops by the user. The main command processor will ;cause the CTRL/c message to override this message however in the case of ;a CTRL/C stop so this message will only appear in the case of a logic error. ;- 100$: ;~x~ ;+ ;HELPER HELPER ;~x~ ; ;Select is active but the select range is empty. Change case acts on a ;select range if there is a valid one, on a search target if there is ;no select range, and on the current character if there is no select range ;or search target. ;- 110$: ;~x~ Jmp NoInsp ;~x~then tell operation is invalid .............. ; ;If no select range, change case of current character and move cursor ;one character position in current direction. ; 120$: Repeat ;~x~Allow for repeat Cmp FCP,PlyEnd ;End of playground? Bhis 140$ ;~x~Error if so MovB @FCP,R0 ;Else get character to change Call @XCase ;~x~do requested casing operation MovB R0,@FCP ;Update the buffer Tst Advanc ;Check direction Beq 130$ ;~x~Move forward Jmp CC.Lft ;~x~Else move backward .............. 130$: Jmp CC.Rht ;~x~Long way to move forward .............. ;Return from there 140$: ;~x~ ;+ ;HELPER ; HELPER ;~x~ ; ;There is no defined select range and the cursor is currently positioned ;at the end of file so there is no character to change case. ;- .Dsabl LSB PSect IMPURE XCase: .BlkW 1 ;~d~ TgtSlt::.BlkW 1 ;~d~Target=select flag RetTNF::.Word 77777 ;~d~Return if target not found flag PSect KEDCMD .SbTtl C.SLCT - Set select enabled ; ; C.SLCT -- set select mode enabled ;zero select count and set select flag to true. ; .Enable LSB C.Slct:: ;~x~ Mov SP,SlctQ ;Flag to true 10$: Clr SlctC ;~x~Select count to zero Clr SlctC+2 Return ;~x~ ...... .SbTtl CANSLC - Cancel select mode ; ; CANSLC -- cancel select mode ;zero count and set flag to false ; CanSlc:: ;~x~ Clr SlctQ ;Mode off Br 10$ ;~x~Clear count ........... .Dsabl LSB .SbTtl C.SSLT,C.NSLT - SET SEARCH [NO]SELECT ;++ ;C.SSLT,C.NSLT ; ;FUNCTIONAL DESCRIPTION: ; ; Turn on/off flag to select the search target as default ;-- .Enabl LSB C.NSlt:: ;~x~ Clr R3 ;clear flag C.SSlt:: ;~x~R3<>0 EndChk ;~x~ Mov R3,TgtSlt ;Turn on/off target=select Return ;~x~ ...... .Dsabl LSB .SBTTL C.NRTN,C.RTRN - SET SEARCH [NO]RETURN ;++ ;C.NRTN,C.RTRN ; ;FUNCTIONAL DESCRIPTION: ; ; Turn on/off flag to stay at the current position if search target ;is not found. ;-- .Enabl LSB C.NRtn:: ;~x~ Clr R3 ;Set Search NoReturn C.Rtrn:: ;~x~R3<>0 EndChk ;~x~ Mov R3,RetTNF ;SET SEARCH [no]RETURN Return ;~x~ ...... .Dsabl LSB .SbTtl SETRNG - Setup a select range ;++ ;SETRNG ; ;FUNCTIONAL DESCRIPTION: ; ; Setup a select range of either the defined range ; or the search target if we are on it ; ;OUTPUT: ; SLCTC,+2 set to proper count ; SLCTQ set non zero if we have a count ; C set if no range to set ;-- .Enable LSB SetRng: ;~x~ Tst SlctQ ;Select range set? Bne 10$ ;~x~Fine cut it Tst TgtSlt ;Should be use the search target? Beq 30$ ;~x~Nope Call StrSet ;~x~Do we even have a search arg? Beq 30$ ;~x~Nope Call SLook1 ;~x~Are we at it? Bne 30$ ;~x~Nope- cause error Sub R3,R4 ;Make length of search model Clr SlctC+2 ;High count Mov R4,SlctC ;Low count Mov SP,SlctQ ;Set for a range Tst SrplC ;Which way is it Bne 10$ ;~x~At end fine we need + count Neg SlctC+2 ;Make the count dp minus Neg SlctC ;With some special magic Sbc SlctC+2 ;Adjust high word of count 10$: Tst SlctC ;~x~Low order nonzero? Bne 20$ ;~x~OK Tst SlctC+2 ;High order non zero? Beq 30$ ;~x~Both zero- error 20$: Return ;~x~Return no error ...... 30$: Sec ;~x~Return error for no range to set Return ;~x~ ...... .Dsabl LSB .SbTtl C.RPLC - Cut text and paste buffer ; ; C.RPLC -- cut text and paste buffer to file ; ; If no select range, use search target ; .Enable LSB C.Rplc:: ;~x~ Tst Inspct ;Inspect mode? Bne 40$ ;~x~Yes Tst SlctQ ;Select range set? Beq 30$ ;~x~Nope- use search argument Mov SP,CutQ ;Cut text Clr SavQ ;Do not save it Call CutRng ;~x~CUt the range 10$: Bcs 20$ ;~x~Error Call Paste ;~x~Paste the buffer in 20$: Return ;~x~ ...... 30$: Call C.DArg ;~x~Delete search argument Br 10$ ;~x~And paste the stuff next ........... 40$: Jmp NoInsp ;~x~then tell operation is invalid .............. .Dsabl LSB .SbTtl C.SUBS - Substitute paste for search target ; ; C.SUBS -- SUBSTITUTE ; if target is here, delete it, paste buffer, and find next ; else error ; ;we have to be careful or we will hangup or miss an occurance ;of the thing we are substituting. The worst case is to replace ;FOO with FOO. ;There are four cases. look means look for target before moving ;cursor. move means move backward over pasted text before looking. ; ; forward backward ; ; search begin no move back move back ; look no look ; ; end no move back move back ; no look look ; .Enable LSB C.Subs:: ;~x~ Mov Df$Pag,SrLins ;Setup in case its a line bounded ;search. Lines to counter Repeat ;~x~Global search and destroy Call C.DArg ;~x~Delete search target if here Bcs 60$ ;~x~Not here Call Paste ;~x~Paste buffer in here Bcs 60$ ;~x~Not possible Call StrSet ;~x~Look for string first here Tst Advanc ;Advance or backup mode? Beq 70$ ;~x~Advance Mov PasPtr,R1 ;Make length of pasted string Sub PasBuf,R1 ;As diff between start and end Beq 20$ ;~x~Avoid crash 10$: Call MvBkw ;~x~Backup over string Bcs 80$ ;~x~Report logic error in subs Sob R1,10$ ;~x~Keep going til done 20$: Tst SrplC ;~x~Which end to stop at Beq 40$ ;~x~End 30$: Call SLook1 ;~x~Is it here? Beq 50$ ;~x~Yes so stay here 40$: Call FndNxt ;~x~Now find next ; Bcs ;Error Return ;~x~ ...... 50$: Clc ;~x~No error 60$: Return ;~x~Return possibly error ...... 70$: Tst SrplC ;~x~Advance- beginning or end? Beq 30$ ;~x~Begin Br 40$ ;~x~End ........... 80$: ;~x~ ;+ ;HELPER HELPER ;~x~ ;search string is zero length or unable to move ;- .Dsabl LSB .SbTtl C.PSCL - Clear paste buffer ; ; C.PSCL -- command routine to clear paste buffer ; .Enabl LSB C.PsCl:: ;~x~ EndChk ;~x~Validate command line termination .Br PasClr ;Go do it .SbTtl PASSET - Initialize paste buffer .SbTtl PASCLR - ; ; PASSET -- initialize paste buffer stuff ; PASCLR -- clear paste buffer ;these are really the same thing since the paste buffer is allocated ;by the allocation routines in the io module. ;PASBUF and PASSIZ are set appropriately by the $ALLOC routine ; PasSet:: ;~x~ PasClr: ;~x~ Mov PasBuf,PasPtr ;Set for no data Mov PasSiz,PasSpc ;Set for all empty Return ;~x~ ...... .Dsabl LSB .SbTtl C.CUT - Cut text to paste buffer .SbTtl C.APND - Cut text and append to buffer ; ; C.CUT -- cut text to paste buffer ; C.APND -- cut text and append to text buffer ; ; Select range is moved to text buffer ; .Enable LSB C.Cut:: ;~x~ Call SetRng ;~x~Setup a select range Bcs 10$ ;~x~No range to use Call PasClr ;~x~Clear the paste buffer Br 10$ ;~x~ ........... C.Apnd:: ;~x~ Call SetRng ;~x~Setup a select range 10$: Mov SP,CutQ ;~x~Delete text Mov SP,SavQ ;Save text in buffer .Br CutRnG ;Cut select range .Dsabl LSB .SbTtl CUTRNG - Cut select range ;++ ;CUTRNG ; ;FUNCTIONAL DESCRIPTION: ; ; Cut select range to paste buffer ; ;Select range is cut (if CUTQ is nonzero) and placed in paste ;buffer (if SAVQ is nonzero). ; ;INPUT: ; SLCTQ select flag ; SLCTC(+2) select count (double precision) ; PASPTR paste data end ; PASSIZ paste space left ; CUTQ nonzero for delete ; SAVQ nonzero for add to paste buffer ; ;OUTPUT: ; Select range saved in paste buffer and deleted ; paste buffer data updated ; R0-R4 destroyed ; C set on error ;-- .Enable LSB CutRng: ;~x~ Tst SlctQ ;Select range on? Beq 140$ ;~x~Nope error Clr Un$Blk ;Do not capture for undelete Mov SlctC,R1 ;Select count to R1-R2 Mov SlctC+2,R2 ; Bne 10$ ;~x~A large count Tst R1 ;Nonzero count? Beq 140$ ;~x~No- issue error 10$: ;~x~ Mov PasPtr,R3 ;Next free pastebuffer byte Mov PasSpc,R5 ;free byte count Tst Inspct ;Inspect mode?? Beq 20$ ;~x~Nope Clr CutQ ;Yes- do not delete 20$: Tst R2 ;~x~Which way did he say?? Bpl 70$ ;~x~Right Neg R2 ;Make + double prec count Neg R1 ;By neg the whole thing Sbc R2 ;Carry to fix high word Call ChPast ;~x~Check paste buffer size 30$: ;~x~ Dec R5 ;reduce space count Tst CutQ ;Delete the text? Beq 40$ ;~x~Nope Call DlChr ;~x~Delete a single char Br 50$ ;~x~Carry on .......... 40$: ;~x~ MovB @FCP,-(SP) ;Save char at FCP Call MvFwd ;~x~A single char MovB (SP)+,R0 ;Restore it 50$: Bcs 150$ ;~x~Error in move or delete Tst SavQ ;Save text?? Beq 60$ ;~x~Nope MovB R0,(R3)+ ;Nope 60$: Sob R1,30$ ;~x~A quick and dirty double prec count Dec R2 ;Top part Bpl 30$ ;~x~Lots more to go Br 120$ ;~x~R3 is next free byte ............ ; ; Take care of a right range ; which is to our left, that is behind us 70$: Call ChPast ;~x~Check size of paste buffer Add R1,R3 ;Point to next free byte after cut Mov R3,R4 ;Save pointer to end 80$: MovB @BCP,-(SP) ;~x~Save the byte for later Dec R5 ;decrement space counter Tst CutQ ;Delete it? Beq 90$ ;~x~No Call RbChR ;~x~Delete a single char Br 100$ ;~x~Carry on ........... 90$: Call MvBkw ;~x~Move back over one physical char 100$: MovB (SP)+,R0 ;~x~Char back from limbo Bcs 150$ ;~x~Error Tst SavQ ;Save it?? Beq 110$ ;~x~Nope MovB R0,-(R3) ;Stuff in buffer backward 110$: Sob R1,80$ ;~x~A quick and dirty double prec count Dec R2 ;Any more Bpl 80$ ;~x~Not much now Mov R4,R3 ;Get next free byte to use 120$: Tst SavQ ;~x~Did we save text? Beq 130$ ;~x~No- do not update data Mov R3,PasPtr ;Save end pointer Mov R5,PasSpc ;save the size 130$: Clc ;~x~Return no error Return ;~x~ ...... 140$: ;~x~ ;+ ;HELPER HELPER ;~x~ ;the select range was not defined on entry to cutrng ;which is called by cut, replace, append. ;the message will not appear however for cut since SETRNG checks ;first in this case and reports the error ;- 150$: ;~x~ ;+ ;HELPER HELPER ;~x~ ;A logic error in dealing with select counts internally by the ;program caused this error. ;- .Dsabl LSB .SbTtl CKPAST - Check paste buffer size ;++ ;CKPAST ; ;FUNCTIONAL DESCRIPTION: ; ; Check paste buffer size ; ;INPUT: ; R1-R2 select range size ; ;OUTPUT: ; Return is cut is ok ;-- .Enable LSB ChPast: Tst SavQ ;~x~Save text? Beq 10$ ;~x~Nope Tst R2 ;Enough space?? Bne 20$ ;~x~Nope Cmp PasSpc,R1 ;Ok? Blo 20$ ;~x~Nope 10$: CallR CanSlc ;~x~Cancel select range now .............. ;in case error 20$: Pop <> ;~x~dump return so we go to ;caller's caller ;+ ;HELPER HELPER