Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -> $VER: FDtoI.e v1.00 by Zeb/SLP (21-Aug-2024)
- MODULE 'dos'
- ENUM ER_USAGE
- DEF source[255]:STRING,target[255]:STRING,txt[255]:STRING,tmp[255]:STRING,
- srcfileptr=NIL:PTR TO LONG,trgfileptr=NIL:PTR TO LONG,err,lvo=0,
- intTemp=0,done=0,lc=0,hide=0,private=0,dec=0,flen=0,quiet=0,die=20,comments=TRUE
- PROC main() HANDLE
- DEF options:PTR TO LONG,rdargs
- options:=[0,0,0,0,0,0,0]
- IF rdargs:=ReadArgs('FROM/A,TARGET/A,DEC/S,NOPRIVATE/S,QUIET/S,NODIE/S,NOCOMMENTS/S',options,NIL)
- StrCopy(source,options[0]) ->Source .fd file to read in
- StrCopy(target,options[1]) ->Target .i file to create
- dec:=options[2] ->Show the offsets as decimal
- private:=options[3] ->Hide the private functions
- quiet:=options[4] ->Suppress output to stdout
- IF options[5] THEN die:=5 ->5=WARN, 20=FATAL ERROR
- IF options[6] THEN comments:=FALSE ->Hide comments
- IF private THEN hide:=TRUE ELSE hide:=FALSE
- FreeArgs(rdargs)
- ENDIF
- WriteF('Comments: \s\n',IF comments THEN 'YES' ELSE 'NO')
- IF StrLen(source)=0 THEN Raise(ER_USAGE)
- IF StrLen(target)=0 THEN Raise(ER_USAGE)
- flen:=FileLength(source)
- srcfileptr:=Open(source,OLDFILE)
- IF (flen=-1) OR (srcfileptr=NIL)
- WriteF('ERROR: File "\s" not found!\n',source)
- CleanUp(die)
- ELSE
- trgfileptr:=Open(target,NEWFILE)
- IF (trgfileptr=NIL)
- WriteF('ERROR: Unable to create "\s"\n',target)
- Close(srcfileptr)
- CleanUp(die)
- ELSE
- IF NOT quiet THEN WriteF('Processing "\s"...',source)
- REPEAT
- done:=FALSE
- err:=ReadStr(srcfileptr,txt)
- lc++
- IF StrCmp(txt,'##base',6) ->We'll include the base address for the library if specified but won't use it
- MidStr(tmp,txt,7,StrLen(txt)-5)
- StringF(tmp,';\s:\tdc.l\t0\n',tmp)
- Write(trgfileptr,tmp,StrLen(tmp))
- done:=TRUE
- ENDIF
- IF StrCmp(txt,'*',1) ->Are we a comment?
- IF comments
- IF (StrLen(txt)=1) THEN StrCopy(tmp,'') ELSE MidStr(tmp,txt,1,StrLen(txt)-1)
- StringF(tmp,'; \s\n',tmp)
- Write(trgfileptr,tmp,StrLen(tmp))
- ENDIF
- done:=TRUE
- ENDIF
- IF StrCmp(txt,'##bias',6) ->Are we setting a new offset value?
- ->MidStr(tmp,txt,7,StrLen(txt)-5)
- lvo:=Val(txt+7,NIL)
- ->StringF(tmp,'; SETTING LVO BASE TO \d ($\h)\n',lvo,lvo)
- ->Write(trgfileptr,tmp,StrLen(tmp))
- done:=TRUE
- ENDIF
- IF StrCmp(txt,'##private',9)
- IF NOT private
- Write(trgfileptr,'; PRIVATE FUNCTIONS\n',STRLEN)
- ELSE
- hide:=TRUE
- ENDIF
- done:=TRUE
- ENDIF
- IF StrCmp(txt,'##public',8)
- IF NOT private
- Write(trgfileptr,'; PUBLIC FUNCTIONS\n',STRLEN)
- ENDIF
- hide:=FALSE
- done:=TRUE
- ENDIF
- IF StrCmp(txt,'##end',5)
- Write(trgfileptr,'; END\n',STRLEN)
- done:=TRUE
- ENDIF
- intTemp:=InStr(txt,'(',0)
- IF (intTemp>-1) AND (done=FALSE)
- IF NOT hide
- MidStr(tmp,txt,0,intTemp)
- IF dec THEN StringF(tmp,'_LVO\s\tequ\t-\d\n',tmp,lvo) ELSE StringF(tmp,'_LVO\s\tequ\t-$\h\n',tmp,lvo)
- Write(trgfileptr,tmp,StrLen(tmp))
- ENDIF
- INC lvo,6
- ENDIF
- IF CtrlC()
- Write(trgfileptr,'***BREAK (Interrupted with CTRL-C)\n',STRLEN)
- err:=TRUE
- ENDIF
- UNTIL err
- IF NOT quiet THEN WriteF('done (\d lines)\n',lc-1)
- ENDIF
- IF trgfileptr THEN Close(trgfileptr)
- IF srcfileptr THEN Close(srcfileptr)
- ENDIF
- CleanUp(0)
- EXCEPT DO
- SELECT exception
- CASE ER_USAGE;information()
- ENDSELECT
- ENDPROC
- PROC information()
- WriteF('\e[0;1;4mFDtoI v1.oo by Zeb/SLP (21-Aug-2o24)\e[0m\n\n')
- WriteF('Usage: FDtoI <src> <trg> [DEC] [NOPRIVATE] [QUIET] [NODIE] [NOCOMMENTS]\n\n')
- WriteF('Where <src> is the name of the .fd file to read,\n')
- WriteF(' <trg> is the name of the .i file to write,\n')
- WriteF(' DEC is a switch to use decimal values instead of hex,\n')
- WriteF(' NOPRIVATE to hide private functions,\n')
- WriteF(' QUIET to suppress output,\n')
- WriteF(' NODIE to set RC to 5 instead of 20 on file errors (handy for scripts)\n')
- WriteF(' and NOCOMMENTS to suppress the comments.\n\n')
- WriteF('If you want to use this with a script...\n')
- WriteF('\tlist >ram:tr #?.fd lformat "fdtoi %n %m.i private nodie"\n')
- WriteF('You can then just "execute ram:tr" which will convert all .fd files.\n')
- ENDPROC
- CHAR '$VER: FDtoI v1.00 by Zeb/SLP (21-Aug-2024)',0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement