; LINE EDIT WORDS FOR SFS ; CREATED 7/7/05 LAST MOD 7/19/05 ; (comments modified 9/5/08) ; ; This collection of words allows line-by-line editing of ; text files. All edit commands operate on buffer 0. ; The file being edited remains open even through restart ; until closed, 0 RELEASE to abandon the edit. Existing files ; must be plain text with a CRLF after every line, lines should ; not exceed roughly 76 characters to avoid stack overflow or ; incompatibility with other things. ; ; Special note... until I figure out fast techniques the ; INSERT and DCF functions use brute force byte-by-byte ; copy which is very slow on large files. On real hardware ; it may take some time before the system will accept the ; next line... the IPL/SFS byte copies should be replaced with ; machine code to copy/shift the bytes but so long as lines ; with odd byte counts are supported it's a slow process no ; matter how it's done. ; ; Editing words... ; "file" FOPEN - open specified file, create if not found ; PCL - print current line ; NL PL - next line, previous line ; [-]count MCL - move current line by specified #lines ; BF EF - beginning of file, end of file ; DCL - delete current line ; CHOP - delete current line and rest of file ; APPEND - append text at end of file ; INSERT - insert lines at current line ; LS - list 10 lines from current line ; LI - list 10 lines and increment current line ; FCLOSE - close file, writing changes ; ; When appending and inserting lines, end entry by entering ; an empty line. Enter at least one space to add blank lines. ; ; Until edited to clean up, words are "raw" EXPLAIN output, ; produced by doing 0 >FILE >MS EXPLAIN WORD followed by ; CONSOLE to cancel the redirection. ; ;--------------------- OCTAL DEFINE FOPEN #0 DRV GET $VOL DIRExxxxx #0 $DUP OPEN FSS GET DEC DEC IFZ " creating..." $PRIxx #0 $DUP CNF #0 $DUP OPEN ENDIx $DROx END ;--------------------- OCTAL DEFINE FCLOSE #0 CLOSx #0 RELExxx END ;--------------------- OCTAL DEFINE BF FPA #0 PUT END ;--------------------- OCTAL DEFINE EF FPA FSA GET PUT END ;--------------------- OCTAL DEFINE PCL CWA GET #1 AND IFNZ FPA GET FSA GET SUB IFNZ MS_Sxxx FPA GET #0 000000 #1 SWAP +DO NL +LOOx < 000000 2CPL #1 SWAP +DO PL +LOOx DEFAxxx DROP ENDCxxx END ;--------------------- OCTAL DEFINE APPEND CWA GET #1 AND IFNZ EF MS_SXXX #0 >FILX DO $IN $LEN IFZ $DROX #1 ELSE MS$OXX MSCRXX #0 ENDIX UNTIX MS_RXXXXXX ENDIF END ;--------------------- OCTAL DEFINE INSERT FPA GET FSA GET SUB IFZ APPExx ELSE CWA GET #1 AND IFNZ MS_Sxxx #0 FILx DO $IN $LEN DUP IFZ DROP $DROx #1 ELSE INC FPA GET S>Z 177777 >STEx FSA GET DEC FPA GET +DO #0 INDEx SEEK MSBIx OVER FPA GET ADD #0 SWAP SEEK MSBOxx +LOOx FPA Z>S PUT MS$Oxx MSCRxx DROP #0 ENDIx UNTIx MS_Rxxxxxx ENDIx ENDIx END ;--------------------- OCTAL DEFINE CHOP FSA FPA GET PUT END ;--------------------- OCTAL DEFINE DCL FPA GET FSA GET SUB IFNZ CWA GET #1 AND IFNZ MS_Sxxx FPA GET S>Z #0 FILx MS$Ix $LEN $DROx FPA GET FSA GET SUB IFZ PL CHOP DROP ELSE INC INC FPA GET FSA GET DEC +DO FPA INDEx PUT MSBIx OVER INDEx SWAP SUB FPA SWAP PUT MSBOxx +LOOx FSA GET SWAP SUB FSA SWAP PUT ENDIx FPA Z>S PUT MS_Rxxxxxx ENDIx ENDIx END ;--------------------- OCTAL DEFINE LIST CWA GET #1 AND IFNZ ;if file is open FSA GET IFNZ ;and not empty MS_SAVE ;save current MS vectors FPA GET S>Z ;save ptr on Z #0 S PUT ;restore ptr MS_RESTORE ;restore MS vectors ENDIF ENDIF END ;---------------------- CONSOLE ~TERMINATE~