'=========================================================================== ' Subject: TEXT 2 SELF EXTRACTING .BAS Date: 11-08-96 (15:35) ' Author: Daniel Garlans Code: QB, QBasic, PDS ' Origin: thegarlans@geocities.com Packet: TEXT.ABC '=========================================================================== 'TxtoBas 1.2 'Changes: neater and more commented :) 'Takes a text file and creates a "self extracting" .BAS file that creates 'the origional text like it was. 'This program was tested with WORMHOLE.BAS by..err..someone, and was inspired 'by complaints that line-lengths were a problem for most browsers '---Constants CONST maxwid = 70 '70 character maximum length in output file '---Code PRINT "TxtoBas 1.2 by Daniel Garlans" 'header INPUT "File to convert:", a$ IF a$ = "" THEN END inputted$ = a$ INPUT "File to write to:", out$ IF out$ = "" THEN END OPEN a$ FOR INPUT AS #1 PRINT "File exists." 'if we're here, the file opened :) PRINT "Starting..."; v$ = ENVIRON$("TEMP") 'get tempfile directory IF LEN(v$) = 0 THEN v$ = "c:" 'if there's no "TEMP" set, make the temp dir=c: tfile$ = v$ + "\@t2btemp.034" 'one temp file tfile2$ = v$ + "\@t2btemp.043" 'two temp files OPEN tfile$ FOR OUTPUT AS #2 'temp file: First step tot = 0 'line count... DO WHILE NOT EOF(1) 'keep it comin' LINE INPUT #1, a$ 'get a line fin$ = "" 'to write=nothing yet FOR b = 1 TO LEN(a$) 'letter by letter c$ = MID$(a$, b, 1) 'get a letter 'requirements.. IF ASC(c$) < 127 THEN 'below 127 IF c$ <> CHR$(94) THEN 'not an exponent symbol (this is used for CR/LF's IF c$ = CHR$(34) THEN fin$ = fin$ + CHR$(125) 'fix the quotation mark bug (change to curleybrace) ELSE fin$ = fin$ + c$ 'we are only here if the character is accepted END IF END IF END IF NEXT b fin$ = fin$ + CHR$(94) 'add a line-end character, because it has to be :) tot = tot + 1 'line count..prolly not needed PRINT #2, fin$; 'NO CR/LF's! (a CR/LF is converted to the exp symbol LOOP CLOSE 'close files PRINT "..."; 'let you know you're still alive OPEN tfile$ FOR BINARY AS #1 'temp file with chr(94) for cr/lf's :) OPEN tfile2$ FOR OUTPUT AS #2 'temp file with DATA's tot2 = 0 'linecount 2 DO WHILE NOT EOF(1) 'keep it comin' v$ = STRING$(maxwid, " ") 'an area to get GET #1, , v$ 'get a run of letters PRINT #2, "DATA " + CHR$(34) + v$ + CHR$(34) 'assemble a DATA command tot2 = tot2 + 1 'increase linecount LOOP 'PRINT #2, CHR$(34) CLOSE PRINT "..."; 'still alive :) OPEN tfile2$ FOR INPUT AS #1 'DATA command tempfile OPEN out$ FOR OUTPUT AS #2 'final file with extractor info t = 0 DO WHILE NOT EOF(1) 'another line count... LINE INPUT #1, a$ t = t + 1 LOOP SEEK #1, 1 'go to first spot 'write extractor code PRINT #2, "' Text 2 Bas Extractor Code..." PRINT #2, "lines="; t PRINT #2, "outlines="; tot PRINT #2, "ON ERROR GOTO 20" PRINT #2, "FOR a = 1 TO lines: READ b$: NEXT a" PRINT #2, "RESTORE" PRINT #2, "INPUT "; CHR$(34); "Output File"; CHR$(34); "; a$" PRINT #2, "OPEN a$ FOR OUTPUT AS #1" PRINT #2, "FOR b = 1 TO lines" PRINT #2, "READ c$" PRINT #2, "FOR d = 1 TO LEN(c$)" PRINT #2, "e$ = MID$(c$, d, 1)" PRINT #2, "IF e$ = CHR$(94) THEN" PRINT #2, "PRINT #1, "; CHR$(34); CHR$(34) PRINT #2, "ELSEIF e$ = CHR$(125) THEN" PRINT #2, "PRINT #1, CHR$(34);" PRINT #2, "ELSE" PRINT #2, "PRINT #1, e$;" PRINT #2, "END IF" PRINT #2, "NEXT d" PRINT #2, "NEXT b" PRINT #2, "PRINT "; CHR$(34); " Extraction Complete."; CHR$(34) PRINT #2, "CLOSE : END" PRINT #2, "20 PRINT "; CHR$(34); "Text 2 Bas Data Corrupted!"; CHR$(34); ": END" 'the plus CHR$(34) is 'cause you can't do: PRINT " print "Hello World!"" :) PRINT #2, "' Text 2 Bas Extractor Data..." 'remark for clarity FOR a = 1 TO t 'copy in the data commands in the temp file 2 LINE INPUT #1, d$ PRINT #2, d$ NEXT a PRINT #2, "' End of Text 2 Bas Extractor Data" 'clarity CLOSE 'finish up PRINT "Tx2bas Complete!" 'info KILL tfile$ 'temp file erase KILL tfile2$ 'again END