Emiter - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html) +--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html) +---- Forum: FB Projects (http://qbasicnews.com/newforum/forum-16.html) +---- Thread: Emiter (/thread-9343.html) |
Emiter - Peter - 05-30-2006 Just a little program to help me get my bearings with Freebasic Emiter converts plain text files into code that ought be compatible for almost evey form of BASIC out there. It should be compatible with either ASCII 10, ASCII 13, or ASCII 10+ASCII 13 line terminating schemes (but I haven't tested it much so what do I know!) I'd comment it, but the code is simple enough to follow [syntax="qbasic"] Option Explicit declare function appfiletype(filename as string,extension as string) as string dim e as string*1 dim mark as byte if len(ltrim$(command$))=0 then 'Generated automatically by EMITER PRINT "EMITER" PRINT "A tool to convert plain text to code compatible with most varients of BASIC" PRINT "" PRINT "Usage: EMITER [filename]" PRINT "*File will be outputed with the same name as FILENAME but with the file extension of FILENAME replaced with "; CHR$(34); ".BAS"; CHR$(34); "" PRINT "" PRINT "Created by Peter E. Lenz, 2006 using QuickBasic, FreeBASIC, and fbIDE" PRINT "Released as a public domain work" end end if open command$ for input as #1 open appfiletype(command$,".bas") for output as #2 PRINT #2, "'Generated automatically by EMITER" PRINT #2, "PRINT "; CHR$(34); WHILE NOT EOF(1) e = INPUT$(1, 1) SELECT CASE ASC(e) CASE 0, 26 'null characters - do not emit mark=0 CASE 9 'tab PRINT #2, CHR$(34); " "; CHR$(34); ";"; mark=0 CASE 10, 13 'new line if mark=asc(e) or mark=0 then PRINT #2, CHR$(34) PRINT #2, "PRINT "; CHR$(34); mark=asc(e) end if CASE 34 'quotation mark PRINT #2, CHR$(34); "; CHR$(34); "; CHR$(34); mark=0 CASE ELSE PRINT #2, e; mark=0 END SELECT WEND PRINT #2, CHR$(34) CLOSE END function appfiletype(filename as string,extension as string) as string dim i as integer for i=len(filename) to 1 step -1 if mid$(filename,i,1)="." then filename=left$(filename,i) exit for end if next if right$(filename,1)="." and left$(extension,1)="." then filename=left$(filename,len(filename)-1) appfiletype=filename+extension end function [/syntax] |