'=========================================================================== ' Subject: LITE VIEWER VERSION 1.11 Date: 11-03-97 (02:02) ' Author: Andrew S. Gibson Code: QB, QBasic, PDS ' Origin: zapf_dingbat@juno.com Packet: TEXT.ABC '=========================================================================== 'This program coverts text file into a simple self showing basic program 'that can be compiled or used in Qbasic, the final output will detect 'whether you are using a monochrome or color display and display its 'contents in the right color scheme. I've been able to use up to thirty 'kilobytes. If a file is longer than 512 lines then it is trunicated, 'files less than 25 lines are padded. The End User can press E to extract 'the document. 'Written by Andrew Gibson, E-mail me at this address: Zapf_DingBat@JUNO.COM 'You should't have to alter any code at all, in fact don't do it at all. 'Remember: Don't fix something if it ain't broke ! DEFINT A-Z DECLARE FUNCTION Reverse$ (StringVar$) DECLARE FUNCTION TrimPath$ (Strng$) DECLARE SUB ConvertTextFile (Infile$) DECLARE SUB WriteLTEViewer (LvOutFile$) CONST OutFile$ = "LTEVIEW.BAS", Version$ = "Lite Viewer Version 1.11" DIM SHARED FInput$, TextLines CLS PRINT Version$; " - a Text file to BASIC program converter." PRINT "If you have Microsoft QuickBASIC you can compile the resulting" PRINT "basic program. "; Version$; " þ Coded by Andrew Gibson": PRINT PRINT "Lines that contain Quote marks (" + CHR$(34) + ") are changed to apostrophes" PRINT "(') and form feed characters are converted to spaces.": PRINT PRINT "Text files that are less than twenty five lines long are padded during" PRINT "the conversion process. Also, some text files may not display smoothly" PRINT "(ie. they seem to jerk when viewed) this is due to the *NATURE OF THE" PRINT "INPUT FILE* and not my viewer code !": PRINT FInput$ = COMMAND$ IF FInput$ = "" THEN LINE INPUT "Text file for input]"; FInput$: FInput$ = LTRIM$(RTRIM$(UCASE$(FInput$))) IF FInput$ = "" THEN PRINT : PRINT "Conversion aborted.": GOTO Term PRINT : PRINT "Converting Text File þ "; ConvertTextFile FInput$ PRINT : PRINT "Writing SelfShowing Text file." WriteLTEViewer OutFile$ PRINT : LINE INPUT "New name for File Viewer]"; NewName$ IF NewName$ = "" THEN PRINT : PRINT "The file produced has the default name of '"; OutFile$; "'" PRINT "You should rename it to make the file UNIQUE so the next time you use" PRINT Version$; ", the old file doesn't get overwritten !" GOTO Term END IF ON ERROR GOTO HandleErrors NAME OutFile$ AS NewName$ PRINT OutFile$; " renamed to "; LTRIM$(RTRIM$(UCASE$(NewName$))) Term: END HandleErrors: CLOSE PRINT : PRINT "The following error has occurred:" SELECT CASE ERR CASE IS = 5: PRINT "Illegal Function Call." CASE IS = 6: PRINT "Math Overflow." CASE IS = 7: PRINT "Program Error: Out of memory.": PRINT "I used up all of the DGROUP space, Try again." CASE IS = 9: PRINT "Program Error: Array Subscript out of range.": PRINT "Upper limit of allocated space exceeded." CASE IS = 14: PRINT "Program Error: Out of String Space" CASE IS = 24: PRINT "Informative Error: Device timeout": PRINT "Turn on your printer or activate `on-line' mode." CASE IS = 25: PRINT "Printer Error: Device fault": PRINT "I can't talk to your printer or print que." CASE IS = 27: PRINT "Printer Error: Out of paper": PRINT "Put Paper in your printer." CASE IS = 52: PRINT "Program or User Error: Bad File Name or number": PRINT "You provided a bad file name or I tried to use a file number that doesn't exist." CASE IS = 53: PRINT "FileManager/User input Error: File not found": PRINT "I cannot find the file you requested." CASE IS = 54: PRINT "FileManager/Programmer Error: Bad file mode": PRINT "I am unable to read a file properly. Make sure the input file is a text file !" CASE IS = 55: PRINT "FileManager Error: File already open": PRINT "A file was already opened, all files are now closed." CASE IS = 57: PRINT "System Fault: Device I/O error": PRINT "I can not 'talk' to a specific device." CASE IS = 58: PRINT "Informative Error: File already exists" CASE IS = 59: PRINT "FileManager Error: Bad record length": PRINT "A database record of some sort is not long enough or is too long." CASE IS = 61: PRINT "Informative Error: Disk FULL": PRINT "Free up some disk space." CASE IS = 62: PRINT "FileManager Error: Input past end of file.": PRINT "Attempt to read beyond the end of current file." CASE IS = 63: PRINT "Program Error: Bad record number": PRINT "A database record of some sort doesn't exist." CASE IS = 64: PRINT "User Error: Bad file name": PRINT "You specifically told me to use a file name that is incorrect." CASE IS = 67: PRINT "FileManager Fault: Too many files open": PRINT "I can't open more files than listed in your CONFIG.SYS file." CASE IS = 68: PRINT "System Error: Device UNAVAILABLE": PRINT "A user serviceable device is not accessable to the computer." CASE IS = 71: PRINT "User or System Error: Disk not Ready": PRINT "Insert a diskette in the current drive. (Excepting Hardrives)" CASE IS = 72: PRINT "Serious Informative Error: Disk-Media error": PRINT "The recordable media surface of the current disk has developed a defect." CASE IS = 73: PRINT "Informative Error: Feature unavailable": PRINT "An advanced capability is not available within this computer." CASE IS = 75: PRINT "FileManager/User input Error: Path/File access error" CASE IS = 76: PRINT "FileManager/User input Error: Path not found": PRINT "The path to a file is non-existant." CASE ELSE PRINT "Error is unprintable. The Errorlevel is"; STR$(ERR); END SELECT END SUB ConvertTextFile (Infile$) TextLines = 0 ON ERROR GOTO HandleErrors OPEN Infile$ FOR INPUT AS #1 OPEN "LTEVDAT.TMP" FOR OUTPUT AS #2 FileLength& = LOF(1) DO LINE INPUT #1, A$ Temp$ = A$ WHILE INSTR(Temp$, CHR$(34)) 'Search for Quotes text and Replace Quotes = INSTR(Temp$, CHR$(34)) IF Quotes THEN MID$(Temp$, Quotes, 1) = CHR$(39) WEND WHILE INSTR(Temp$, CHR$(12)) 'Search for Form Feed and Replace Quotes = INSTR(Temp$, CHR$(12)) IF Quotes THEN MID$(Temp$, Quotes, 1) = CHR$(32) WEND A$ = Temp$ PRINT #2, "DATA " + CHR$(34) + LEFT$(A$, 80) + CHR$(34) TextLines = TextLines + 1 LOCATE CSRLIN, 24: PRINT USING "Text Lines processed ###."; TextLines; Temp$ = "": A$ = "" LOOP UNTIL TextLines = 511 OR EOF(1) IF TextLines < 25 THEN Padding = 25 - TextLines FOR PadFile = 0 TO Padding: PRINT #2, "DATA " + CHR$(34) + CHR$(34): NEXT PadFile TextLines = TextLines + Padding LOCATE CSRLIN, 24: PRINT USING "Text Lines processed ###."; TextLines; END IF PRINT #2, : PRINT #2, "' Number of lines counted:" + STR$(TextLines) CLOSE END SUB FUNCTION Reverse$ (StringVar$) C$ = MID$(StringVar$, 1, 1) IF C$ = "" THEN ' The first character is null, so return ' null--there's no more string left. Reverse$ = "" ELSE ' The reverse of a non-null string is the first character ' appended to the reverse of the remaining string. Reverse$ = Reverse$(MID$(StringVar$, 2)) + C$ END IF END FUNCTION FUNCTION TrimPath$ (Strng$) STATIC FOR Z = LEN(Strng$) TO 1 STEP -1 IF MID$(Strng$, Z, 1) = CHR$(92) THEN EXIT FOR ELSE XTemp$ = XTemp$ + MID$(Strng$, Z, 1) END IF NEXT TpTemp$ = Reverse$(XTemp$) TrimPath$ = TpTemp$: XTemp$ = "" END FUNCTION SUB WriteLTEViewer (LvOutFile$) ON ERROR GOTO HandleErrors OPEN LvOutFile$ FOR OUTPUT AS #1 PRINT #1, "DEFINT A-Z" PRINT #1, "'"; Version$; " þ Coded by Andrew Gibson - This code is free for" PRINT #1, "'compiling and mass distribution, end users should not be charged" PRINT #1, "'for this unless its part of *ShareWare* package." PRINT #1, "DECLARE FUNCTION Keycode% ()" PRINT #1, "DECLARE SUB ViewInterDoc (FileName$, LineCount%)" PRINT #1, PRINT #1, "CONST FALSE = 0: CONST TRUE = NOT FALSE" PRINT #1, "CONST UpArrow = 18432, Downarrow = 20480, PGUP = 18688, PGDN = 20736" PRINT #1, "CONST Home = 18176, Endkey = 20224, ESCape = 27, LExtract = 101, BExtract = 69" PRINT #1, "OPTION BASE 1" PRINT #1, "DIM SHARED A$(1 TO" + STR$(TextLines) + ")" PRINT #1, "FOR Idoc = 1 TO UBOUND(A$): READ DOC$: A$(Idoc) = DOC$: NEXT Idoc" PRINT #1, FiTemp$ = TrimPath$(FInput$) 'strip any path or drive specification 'from the conversion filename so the extraction 'code doesn't screw itself PRINT #1, "ViewInterDoc " + CHR$(34) + UCASE$(FiTemp$) + CHR$(34) + ", UBOUND(A$)" PRINT #1, "END" PRINT #1, PRINT #1, "InterDoc:" OPEN "LTEVDAT.TMP" FOR INPUT AS #2 DO: LINE INPUT #2, Dat$: PRINT #1, Dat$: LOOP UNTIL EOF(2) CLOSE #2 KILL "LTEVDAT.TMP" PRINT #1, PRINT #1, "FUNCTION Keycode% STATIC" PRINT #1, "DO: K$ = INKEY$: LOOP UNTIL K$ <> " + CHR$(34) + CHR$(34) + ": Keycode% = CVI(K$ + CHR$(0))" PRINT #1, "END FUNCTION" PRINT #1, PRINT #1, "SUB ViewInterDoc (FileName$, LineCount%)" PRINT #1, "DEF SEG = 0: IF PEEK(&H463) = &HB4 THEN BackGround = 0 ELSE BackGround = 1: DEF SEG" PRINT #1, "CLS : Lineptr% = 1: Extracted = FALSE" PRINT #1, "DO" PRINT #1, " COLOR 0, 3: VIEW PRINT: LOCATE 1, 1: PRINT " + CHR$(34) + "Line:" + CHR$(34) + "; LEFT$(STR$(Lineptr%) + SPACE$(7), 8);" PRINT #1, " PRINT " + CHR$(34) + "File: " + CHR$(34) + "; LEFT$(FileName$ + SPACE$(19), 19); : PRINT " + CHR$(34) + " Quit: ESC" + CHR$(34) + "; SPACE$(2);" PRINT #1, " PRINT " + CHR$(34) + "Move " + CHR$(34) + "; CHR$(24); " + CHR$(34) + " " + CHR$(34) + "; CHR$(25); " + CHR$(34) + " PGUP PGDN HOME END " + CHR$(34) + ";" PRINT #1, " COLOR 7, BackGround: VIEW PRINT 2 TO 25" PRINT #1, " FOR i% = 0 TO 23" PRINT #1, " LOCATE i% + 2, 1: PRINT LEFT$(A$(i% + Lineptr%) + SPACE$(80), 80);" PRINT #1, " NEXT i%" PRINT #1, " SELECT CASE Keycode%" PRINT #1, " CASE UpArrow" PRINT #1, " IF Lineptr% > 1 THEN" PRINT #1, " Lineptr% = Lineptr% - 1" PRINT #1, " END IF" PRINT #1, " CASE Downarrow" PRINT #1, " IF Lineptr% < LineCount% THEN" PRINT #1, " Lineptr% = Lineptr% + 1" PRINT #1, " END IF" PRINT #1, " IF Lineptr% + 24 > LineCount% THEN Lineptr% = LineCount% - 23" PRINT #1, " CASE PGUP" PRINT #1, " IF Lineptr% > 1 THEN" PRINT #1, " Lineptr% = Lineptr - 24" PRINT #1, " IF Lineptr% < 1 THEN" PRINT #1, " Lineptr% = 1" PRINT #1, " END IF" PRINT #1, " END IF" PRINT #1, " CASE PGDN" PRINT #1, " IF Lineptr% < LineCount% - 24 THEN" PRINT #1, " Lineptr% = Lineptr% + 24" PRINT #1, " END IF" PRINT #1, " IF Lineptr% + 24 > LineCount% THEN Lineptr% = LineCount% - 23" PRINT #1, " CASE Home" PRINT #1, " IF Lineptr% > 1 THEN" PRINT #1, " Lineptr% = 1" PRINT #1, " END IF" PRINT #1, " CASE Endkey" PRINT #1, " IF Lineptr% < LineCount% - 24 THEN" PRINT #1, " Lineptr% = LineCount% - 23" PRINT #1, " END IF" PRINT #1, " CASE ESCape: Quitflag% = TRUE" PRINT #1, " CASE LExtract, BExtract" PRINT #1, " IF Extracted = FALSE THEN" PRINT #1, " OPEN FileName$ FOR OUTPUT AS #1: FOR Edoc = 1 TO UBOUND(A$): PRINT #1, A$(Edoc): NEXT Edoc: CLOSE" PRINT #1, " Extracted = TRUE" PRINT #1, " ELSE" PRINT #1, " OUT 97, INP(97) OR &H3: OUT 67, 182" PRINT #1, " OUT 66, 119: OUT 66, 2: FOR ZZZ! = 0 TO 150: NEXT ZZZ!" PRINT #1, " OUT 97, INP(97) AND &HFC" PRINT #1, " END IF" PRINT #1, " CASE ELSE" PRINT #1, " OUT 97, INP(97) OR &H3: OUT 67, 182" PRINT #1, " OUT 66, 41: OUT 66, 21: FOR ZZZ! = 0 TO 300: NEXT ZZZ!" PRINT #1, " OUT 97, INP(97) AND &HFC" PRINT #1, " END SELECT" PRINT #1, "LOOP UNTIL Quitflag%" PRINT #1, "VIEW PRINT" PRINT #1, "END SUB" CLOSE END SUB