'=========================================================================== ' Subject: COMMAND BASED FILE EDITOR Date: 07-13-99 (01:37) ' Author: Kevin Everingham Code: QB, QBasic, PDS ' Origin: fortunecity.com/skyscraper/quan Packet: TEXT.ABC '=========================================================================== '$DYNAMIC DEFINT A-Z DECLARE SUB clrit () DECLARE SUB Editor (Text$, LeftCol, RightCol, KeyCode, LN) ' ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ' º QuickBASIC D O S F I L E E D I T O R º Û ' º Version 1 by Kevin Everingham (c)1998 Additional º Û ' º Program features: º Û ' º º Û ' º º Û ' ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ Û ' ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß DECLARE SUB layout () begin: COLOR 0, 0: CLS : COLOR 7 editit: VIEW PRINT: COLOR 12, 0: CLS '<-------sec below outside print range LOCATE 1, 1: PRINT TAB(17); "DOS FILE EDITOR by"; : COLOR 15: PRINT " Kevin Everingham"; : COLOR 9: PRINT TAB(65); "Editor"; STRING$(23, 32): COLOR 7 LOCATE 3, 1: COLOR 15, 0: SHELL "DIR *.*/W/O-D/P" 'LIST ALL FILES COLOR 9, 0 LeftCol = 1 ' Set left column for editing RightCol = 80 ' right column LOCATE 23, 1 COLOR 1, 0: PRINT STRING$(80, 219); : PRINT STRING$(80, 219); : LOCATE 23, 1 COLOR 3, 1: PRINT TAB(61); "" LOCATE 24: COLOR 1: PRINT STRING$(80, 219); : PRINT STRING$(80, 219); LOCATE 25, 1: COLOR 14: PRINT " ^^^^^^^^^^^^^^^^\ Name & Extension /^^^^^^^ "; LOCATE 25: PRINT TAB(50); "(? =Help)"; TAB(62); "(Exit=Quit)"; LOCATE 24, 3: COLOR 3: PRINT " File to Edit: "; : COLOR 15: INPUT file$ COLOR 1, 0: LOCATE 1, 1: PRINT STRING$(80, 219); : PRINT STRING$(80, 219); LOCATE 1, 1: COLOR 15, 1: PRINT TAB(17); "DOS FILE EDITOR by Kevin Everingham"; : COLOR 9: PRINT TAB(65); "Editor"; STRING$(23, 32): COLOR 7 COLOR 0: LOCATE 22: file$ = RTRIM$(file$): file$ = LTRIM$(file$) VIEW PRINT 3 TO 23 file$ = UCASE$(file$) ' trim spaces and capitalize. IF file$ = "?" THEN COLOR 15, 0: CLS : LOCATE 10, 20: PRINT "Help Available once you Enter a File Name": SLEEP 6: GOTO begin IF file$ = "EXIT" THEN CLOSE : CLS : END IF file$ = "END" THEN CLOSE : CLS : END tester$ = RIGHT$(file$, 4) IF LEFT$(tester$, 1) <> "." THEN file$ = file$ + ".HTM": tester$ = "": COLOR 0 ed2: IF file$ = "" THEN GOTO editit ON ERROR GOTO err1 CLOSE OPEN "I", 1, file$ ON ERROR GOTO err1 REDIM Seeks&(1 TO 16384) ' Max number of lines if 16384 CurSeek& = 1 NumLines = 0 DO UNTIL EOF(1) LINE INPUT #1, Text$ NumLines = NumLines + 1 Seeks&(NumLines) = CurSeek& ' Save starting position CurSeek& = CurSeek& + LEN(Text$) + 2 ' Next position - 2 is LOOP ' for C/R & LF CurCol = 1 ' Current Column SeekEl = 1 ' Current line Escape = false VIEW PRINT ' <----3 lines here to show file info your viewing. COLOR 9, 1: LOCATE 24, 35: PRINT "Total Lines ="; NumLines; " in File: "; file$ VIEW PRINT 3 TO 23 DO GOSUB LoadAndDisplay2 GOSUB KeyProcess2 LOOP UNTIL Escape CLOSE GOTO begin ed: ' 3 lines below tell user what line they are on and how many lines. VIEW PRINT Editor Text$, LeftCol, RightCol, KeyCode, LN linecount = 0 CLOSE ON ERROR GOTO err1 OPEN file$ FOR INPUT AS #1 '-----open user input file OPEN "temp.dat" FOR OUTPUT AS #2 '-----open temp file DO UNTIL linecount = NumLines '-----check for end of file. linecount = linecount + 1 LINE INPUT #1, Text2$ IF Pickline$ <> "yes" AND linecount = SeekEl + 20 THEN Text2$ = Text$ IF Pickline$ = "yes" AND linecount = LN THEN Text2$ = Text$: LN = 0 PRINT #2, Text2$ '-----enter Text2$ into file. LOOP Pickline$ = "no" CLOSE #1 CLOSE '-----close all open files. SHELL "copy temp.dat " + file$ '-----copy temp file to specified name. GOTO ed2 LoadAndDisplay2: SEEK #1, Seeks&(SeekEl) FOR i = 3 TO 23 IF NOT EOF(1) THEN LINE INPUT #1, Text$ ELSE Text$ = "" Strg$ = SPACE$(74) IF LEN(Text$) < CurCol THEN Text$ = Text$ + SPACE$(CurCol - LEN(Text$)) LSET Strg$ = MID$(Text$, CurCol) linum = (i + SeekEl) - 3 '<---calculate line num to display LOCATE i, 1, 0: COLOR 9, 0: PRINT USING " ###±"; linum; : COLOR 0, 7: PRINT Strg$; : COLOR 9, 0: PRINT "±"; : COLOR 0, 7 IF linum > NumLines THEN LOCATE i, 1, 0: COLOR 8, 0: PRINT USING " ###ß"; linum; : COLOR 0, 7 IF i = 23 AND linum < NumLines + 1 THEN LOCATE i, 1, 0: COLOR 9, 0: PRINT "Home"; NEXT i RETURN KeyProcess2: A$ = INKEY$: IF A$ = "" THEN GOTO KeyProcess2 IF A$ = "+" THEN GOTO addlinein ' (+) add specified line # IF A$ = "-" THEN GOTO removeline ' (-) remove specified line # IF A$ = "_" THEN GOTO removeline ' same as above IF A$ = "?" THEN CALL layout: CLOSE : GOTO ed2 IF A$ = "/" THEN CALL layout: CLOSE : GOTO ed2 SELECT CASE A$ CASE CHR$(27) Escape = true ' ESC GOTO begin CASE CHR$(8) ' Backspace Key CALL layout CASE CHR$(9) ' Tab CALL clrit ' Edit by line number Pickline$ = "yes" redoit: LOCATE 13, 26: PRINT "Enter Line Number to Edit:" COLOR 7: LOCATE 14, 50: PRINT "(0=Exit)": COLOR 15 LOCATE 14, 29: PRINT "(1 to 21) "; : INPUT " #"; LN IF LN = 0 THEN CLOSE : GOTO ed2 IF LN > 21 THEN GOTO redoit IF LN < 1 THEN GOTO redoit COLOR 0, 7 ' <--- 2 lines above print- pick # on clrit sub CLOSE Pickline$ = "yes" OPEN "I", 1, file$ ' re-open file to locate line ON ERROR GOTO err1 ' selected in LN above. REDIM Seeks&(1 TO 16384) CurSeek& = 1 NumLines = 0 DO UNTIL EOF(1) LINE INPUT #1, Text$ IF NumLines = LN - 1 THEN temp$ = Text$ NumLines = NumLines + 1 Seeks&(NumLines) = CurSeek& CurSeek& = CurSeek& + LEN(Text$) + 2 LOOP CLOSE Text$ = temp$ ' get the line requested GOTO ed CASE CHR$(0) + CHR$(72) ' Up Arrow SeekEl = SeekEl - 1 IF SeekEl < 1 THEN SeekEl = 1: GOTO KeyProcess2 CASE CHR$(0) + CHR$(80) ' Dn Arrow SeekEl = SeekEl + 1 IF SeekEl + 20 > NumLines THEN SeekEl = SeekEl - 1: GOTO KeyProcess2 CASE CHR$(0) + CHR$(77) ' Right Arrow CurCol = CurCol + 1 CASE CHR$(0) + CHR$(75) ' Left Arrow CurCol = CurCol - 1 IF CurCol < 1 THEN CurCol = 1: GOTO KeyProcess2 CASE CHR$(0) + CHR$(73) ' Page Up SeekEl = SeekEl - 20 IF SeekEl < 1 THEN SeekEl = 1 CASE CHR$(0) + CHR$(81) ' Page Dn SeekEl = SeekEl + 20 IF SeekEl > NumLines THEN SeekEl = NumLines - 20: GOTO KeyProcess2 END IF CASE CHR$(0) + CHR$(71) ' Home Key IF linum < NumLines + 1 GOTO ed ' Initiates Edit Line CASE CHR$(0) + CHR$(79) ' End Key adds blank GOTO addaline 'Escape = true ' line to end of file. CASE ELSE GOTO KeyProcess2 END SELECT RETURN CLS : END addaline: CLOSE 'add a blank line to the end of a file. OPEN file$ FOR INPUT AS #1 OPEN "temp.dat" FOR OUTPUT AS #2 DO UNTIL EOF(1) 'linecount = Numlines LINE INPUT #1, Text2$ PRINT #2, Text2$ LOOP PRINT #2, "" CLOSE #1 CLOSE SHELL "copy temp.dat " + file$ GOTO ed2 addlinein: CLOSE 'add a blank line where user wants it. CALL clrit: i = 0 LOCATE 13, 23: PRINT "Enter Line to insert a Blank": LOCATE 14, 50: PRINT "(0=Exit)" LOCATE 14, 24: PRINT "Line: ( 1 to"; NumLines; ")"; : INPUT temp IF temp = 0 THEN GOTO ed2 OPEN file$ FOR INPUT AS #1 OPEN "temp.dat" FOR OUTPUT AS #2 DO UNTIL EOF(1) 'linecount = Numlines LINE INPUT #1, Text2$ i = i + 1: IF i = temp THEN PRINT #2, "" PRINT #2, Text2$ LOOP CLOSE #1 CLOSE SHELL "copy temp.dat " + file$ GOTO ed2 removeline: CLOSE 'add a blank line where user wants it. CALL clrit: i = 0 LOCATE 13, 25: PRINT "Enter Line number to Remove ": LOCATE 14, 50: PRINT "(0=Exit)" LOCATE 14, 24: PRINT "Line: ( 1 to"; NumLines; ")"; : INPUT temp IF temp = 0 THEN GOTO ed2 OPEN file$ FOR INPUT AS #1 OPEN "temp.dat" FOR OUTPUT AS #2 DO UNTIL EOF(1) LINE INPUT #1, Text2$ i = i + 1 IF i <> temp THEN PRINT #2, Text2$ LOOP CLOSE #1 CLOSE SHELL "copy temp.dat " + file$ GOTO ed2 err1: COLOR 15, 0: CLS LOCATE 12, 35: PRINT "File Error...."; LOCATE 18, 10: COLOR 14: PRINT "press any key to continue" SLEEP CLOSE GOTO begin REM $STATIC SUB clrit COLOR 1 ' <----draw a small input box LOCATE 13, 20: PRINT STRING$(40, 219) LOCATE 14, 20: PRINT STRING$(40, 219) COLOR 7, 1 LOCATE 12, 20: PRINT CHR$(201); STRING$(38, 205); CHR$(187) LOCATE 13, 20: PRINT CHR$(186); TAB(59); CHR$(186) LOCATE 14, 20: PRINT CHR$(186); TAB(59); CHR$(186) LOCATE 15, 20: PRINT CHR$(200); STRING$(38, 205); CHR$(188) COLOR 15, 1 END SUB SUB Editor (Text$, LeftCol, RightCol, KeyCode, LN) '----- Find the cursor's size in Scan Lines DEF SEG = 0 ' Peek at low memory to see IF PEEK(&H463) = &HB4 THEN 'what type of monitor we have CsrSize = 12 'Monochrome uses 13 scan lines ELSE ' (numbered 0 to 12) CsrSize = 7 ' Color uses 8 (0 to 7) END IF Edit$ = SPACE$(RightCol - LeftCol + 1) LSET Edit$ = Text$ ' editing 'IF LN < 23 THEN Edit$ = 'TxtPos = LN - LeftCol + 1 IF LN < 23 AND LN <> 0 THEN TxtPos = LN - LeftCol + 1: GOTO skip TxtPos = POS(0) - LeftCol + 1 'Get the cursor's location to skip: IF TxtPos < 1 THEN TxtPos = 1 ' see where to begin editing IF TxtPos > LEN(Edit$) THEN TxtPos = LEN(Edit$) IF LN < 23 AND LN <> 0 THEN LOCATE LN + 2, LeftCol: GOTO skip2 LOCATE , LeftCol 'Print the editing string skip2: PRINT Edit$; DO LOCATE , LeftCol + TxtPos - 1, 1 'Locate the cursor, turn it on ' LOCATE , LeftCol + LN - 1, 1 'Locate the cursor, turn it on DO ' Wait for a key press Ky$ = INKEY$ LOOP UNTIL LEN(Ky$) IF LEN(Ky$) = 1 THEN 'Make a key code from Ky$ KeyCode = ASC(Ky$) ' Single character key ELSE KeyCode = -ASC(RIGHT$(Ky$, 1)) 'Extended keys are negative END IF SELECT CASE KeyCode CASE 8 TxtPos = TxtPos - 1 'Back up the text pointer ' LOCATE , LeftCol + LN - 1, 0 ' Locate 1 to the left LOCATE , LeftCol + TxtPos - 1, 0 ' Locate 1 to the left IF TxtPos > 0 THEN 'Still within the field? IF Insert THEN ' Truncate the string MID$(Edit$, TxtPos) = MID$(Edit$, TxtPos + 1) + " " ELSE ' Blank the letter MID$(Edit$, TxtPos) = " " END IF PRINT MID$(Edit$, TxtPos); 'Print the new part of text END IF CASE 13, 27 EXIT DO 'Bail out CASE 32 TO 254 LOCATE , , 0 'Turn the cursor off IF Insert THEN 'Expand the text string MID$(Edit$, TxtPos) = Ky$ + MID$(Edit$, TxtPos) PRINT MID$(Edit$, TxtPos); 'Print the expanded part ELSE MID$(Edit$, TxtPos) = Ky$ 'Put the new letter in string PRINT Ky$; 'Print the letter END IF TxtPos = TxtPos + 1 'Increment the text pointer CASE -75 TxtPos = TxtPos - 1 'Decrement the text pointer CASE -77 TxtPos = TxtPos + 1 'Increment the text pointer CASE -71 TxtPos = 1 'Move text pointer to 1 CASE -79 FOR N = LEN(Edit$) TO 1 STEP -1 'Look backwards for non-blank IF MID$(Edit$, N, 1) <> " " THEN EXIT FOR NEXT TxtPos = N + 1 'Set pointer to last char +1 IF TxtPos > LEN(Edit$) THEN TxtPos = LEN(Edit$) CASE -82 Insert = NOT Insert 'Toggle the Insert state IF Insert THEN 'Adjust the cursor size LOCATE , , , CsrSize \ 2, CsrSize ELSE LOCATE , , , CsrSize - 1, CsrSize END IF CASE -83 'Truncate the text MID$(Edit$, TxtPos) = MID$(Edit$, TxtPos + 1) + " " LOCATE , , 0 'Print the truncated part PRINT MID$(Edit$, TxtPos); CASE ELSE 'All other keys, EXIT DO ' bail out END SELECT LOOP UNTIL TxtPos < 1 OR TxtPos > LEN(Edit$) 'If cursor is out of field, Text$ = RTRIM$(Edit$) 'Trim the right side of text END SUB SUB layout COLOR 1, 7: PRINT : PRINT "Editing Keys:": COLOR 0 PRINT "ÚÄÄÄÄÄÄÄ¿ Edit the bottom (Home) line Jump" PRINT "³Esc ³ toggle typeover/insert text__ | Page Up" PRINT "ÀÄÄÄÄÄÄÄÙ--Exit Editor | | |" PRINT " ÚÄÄÄÄÄ¿ÚÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄ¿ÚÄÄÄÄÄÄ¿ÚÄÄÄÄÄÄÄÄ¿" PRINT " remove a line--³ - ³³ + ³ ³Backspace³ ³Insert³³ Home ³³ PageUp ³" PRINT " ÀÄÄÄÄÄÙÀÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÙÀÄÄÄÄÄÄÙÀÄÄÄÄÄÄÄÄÙ" PRINT " ÚÄÄÄÄÄ¿ insert a line____| ÚÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄ¿ÚÄÄÄÄÄÄ¿ÚÄÄÄÄÄÄÄÄ¿" PRINT " ³ Tab ³__ ³ ³ ³Delete³³ End ³³ PageDn ³" PRINT " ÀÄÄÄÄÄÙ | Save an ÚÄÄÄÄÄÄÙ ³ ÀÄÄÄÄÄÄÙÀÄÄÄÄÄÄÙÀÄÄÄÄÄÄÄÄÙ" PRINT " edit lines 1-21 edited ³ Enter ³ | | Down a Page" PRINT " line ---->ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÙ | add a" PRINT " | blank line" PRINT " further descriptons Delete Text__| to end of file." PRINT " type (Help) at the (in edit line) ÚÄÄÄÄ¿ " PRINT " main screen. ³ "; CHR$(24); " ³" PRINT " Text scrolling keys ------> ÀÄÄÄÄÙ " COLOR 14: PRINT " Press any"; : COLOR 0: PRINT " up, down, right, left ÚÄÄÄÄ¿ÚÄÄÄÄ¿ÚÄÄÄÄ¿" COLOR 14: PRINT " key to"; : COLOR 0: PRINT " -----------> ³ "; CHR$(27); " ³³ "; CHR$(25); " ³³ "; CHR$(26); " ³" COLOR 14: PRINT " Continue"; : COLOR 0: PRINT " ÀÄÄÄÄÙÀÄÄÄÄÙÀÄÄÄÄÙ" SLEEP END SUB SUB updates ' Programming Updates: Version: ' ' Updates: ' 12/97 -File Viewing options only. 1.0 ' multiple file extension viewing. ' 1/98 -Single line editing (experiments). 1.1 ' editing works but cannot save file. ' 1/98 -Edit and Save options now work while in full ' screen mode!..edit by line number or position 1.2 ' 1 remaining bug: line # edits current line + chosen ' line. +need to add addtional editing options. ' 1/21/98 work on pick line edit command started w/TAB key. ' got the line edit for lines 1-21 to work. ' Added (+ and -) keys to add or delete a specific ' code line. ' 2/15/98 re-set editor to edit any ASCII files. 1.5 ' (End of Programming by Everingham) ' let me know what you add! e-mail: abacus@pathwaynet.com ' add your updates here. END SUB