Advertisement
Yesideez

FDtoI

Aug 21st, 2024 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | Source Code | 0 0
  1. -> $VER: FDtoI.e v1.00 by Zeb/SLP (21-Aug-2024)
  2.  
  3. MODULE 'dos'
  4.  
  5. ENUM ER_USAGE
  6.  
  7. DEF source[255]:STRING,target[255]:STRING,txt[255]:STRING,tmp[255]:STRING,
  8. srcfileptr=NIL:PTR TO LONG,trgfileptr=NIL:PTR TO LONG,err,lvo=0,
  9. intTemp=0,done=0,lc=0,hide=0,private=0,dec=0,flen=0,quiet=0,die=20,comments=TRUE
  10.  
  11. PROC main() HANDLE
  12. DEF options:PTR TO LONG,rdargs
  13. options:=[0,0,0,0,0,0,0]
  14. IF rdargs:=ReadArgs('FROM/A,TARGET/A,DEC/S,NOPRIVATE/S,QUIET/S,NODIE/S,NOCOMMENTS/S',options,NIL)
  15. StrCopy(source,options[0]) ->Source .fd file to read in
  16. StrCopy(target,options[1]) ->Target .i file to create
  17. dec:=options[2] ->Show the offsets as decimal
  18. private:=options[3] ->Hide the private functions
  19. quiet:=options[4] ->Suppress output to stdout
  20. IF options[5] THEN die:=5 ->5=WARN, 20=FATAL ERROR
  21. IF options[6] THEN comments:=FALSE ->Hide comments
  22. IF private THEN hide:=TRUE ELSE hide:=FALSE
  23. FreeArgs(rdargs)
  24. ENDIF
  25. WriteF('Comments: \s\n',IF comments THEN 'YES' ELSE 'NO')
  26. IF StrLen(source)=0 THEN Raise(ER_USAGE)
  27. IF StrLen(target)=0 THEN Raise(ER_USAGE)
  28. flen:=FileLength(source)
  29. srcfileptr:=Open(source,OLDFILE)
  30. IF (flen=-1) OR (srcfileptr=NIL)
  31. WriteF('ERROR: File "\s" not found!\n',source)
  32. CleanUp(die)
  33. ELSE
  34. trgfileptr:=Open(target,NEWFILE)
  35. IF (trgfileptr=NIL)
  36. WriteF('ERROR: Unable to create "\s"\n',target)
  37. Close(srcfileptr)
  38. CleanUp(die)
  39. ELSE
  40. IF NOT quiet THEN WriteF('Processing "\s"...',source)
  41. REPEAT
  42. done:=FALSE
  43. err:=ReadStr(srcfileptr,txt)
  44. lc++
  45. IF StrCmp(txt,'##base',6) ->We'll include the base address for the library if specified but won't use it
  46. MidStr(tmp,txt,7,StrLen(txt)-5)
  47. StringF(tmp,';\s:\tdc.l\t0\n',tmp)
  48. Write(trgfileptr,tmp,StrLen(tmp))
  49. done:=TRUE
  50. ENDIF
  51. IF StrCmp(txt,'*',1) ->Are we a comment?
  52. IF comments
  53. IF (StrLen(txt)=1) THEN StrCopy(tmp,'') ELSE MidStr(tmp,txt,1,StrLen(txt)-1)
  54. StringF(tmp,'; \s\n',tmp)
  55. Write(trgfileptr,tmp,StrLen(tmp))
  56. ENDIF
  57. done:=TRUE
  58. ENDIF
  59. IF StrCmp(txt,'##bias',6) ->Are we setting a new offset value?
  60. ->MidStr(tmp,txt,7,StrLen(txt)-5)
  61. lvo:=Val(txt+7,NIL)
  62. ->StringF(tmp,'; SETTING LVO BASE TO \d ($\h)\n',lvo,lvo)
  63. ->Write(trgfileptr,tmp,StrLen(tmp))
  64. done:=TRUE
  65. ENDIF
  66. IF StrCmp(txt,'##private',9)
  67. IF NOT private
  68. Write(trgfileptr,'; PRIVATE FUNCTIONS\n',STRLEN)
  69. ELSE
  70. hide:=TRUE
  71. ENDIF
  72. done:=TRUE
  73. ENDIF
  74. IF StrCmp(txt,'##public',8)
  75. IF NOT private
  76. Write(trgfileptr,'; PUBLIC FUNCTIONS\n',STRLEN)
  77. ENDIF
  78. hide:=FALSE
  79. done:=TRUE
  80. ENDIF
  81. IF StrCmp(txt,'##end',5)
  82. Write(trgfileptr,'; END\n',STRLEN)
  83. done:=TRUE
  84. ENDIF
  85. intTemp:=InStr(txt,'(',0)
  86. IF (intTemp>-1) AND (done=FALSE)
  87. IF NOT hide
  88. MidStr(tmp,txt,0,intTemp)
  89. IF dec THEN StringF(tmp,'_LVO\s\tequ\t-\d\n',tmp,lvo) ELSE StringF(tmp,'_LVO\s\tequ\t-$\h\n',tmp,lvo)
  90. Write(trgfileptr,tmp,StrLen(tmp))
  91. ENDIF
  92. INC lvo,6
  93. ENDIF
  94. IF CtrlC()
  95. Write(trgfileptr,'***BREAK (Interrupted with CTRL-C)\n',STRLEN)
  96. err:=TRUE
  97. ENDIF
  98. UNTIL err
  99. IF NOT quiet THEN WriteF('done (\d lines)\n',lc-1)
  100. ENDIF
  101. IF trgfileptr THEN Close(trgfileptr)
  102. IF srcfileptr THEN Close(srcfileptr)
  103. ENDIF
  104. CleanUp(0)
  105. EXCEPT DO
  106. SELECT exception
  107. CASE ER_USAGE;information()
  108. ENDSELECT
  109. ENDPROC
  110.  
  111. PROC information()
  112. WriteF('\e[0;1;4mFDtoI v1.oo by Zeb/SLP (21-Aug-2o24)\e[0m\n\n')
  113. WriteF('Usage: FDtoI <src> <trg> [DEC] [NOPRIVATE] [QUIET] [NODIE] [NOCOMMENTS]\n\n')
  114. WriteF('Where <src> is the name of the .fd file to read,\n')
  115. WriteF(' <trg> is the name of the .i file to write,\n')
  116. WriteF(' DEC is a switch to use decimal values instead of hex,\n')
  117. WriteF(' NOPRIVATE to hide private functions,\n')
  118. WriteF(' QUIET to suppress output,\n')
  119. WriteF(' NODIE to set RC to 5 instead of 20 on file errors (handy for scripts)\n')
  120. WriteF(' and NOCOMMENTS to suppress the comments.\n\n')
  121. WriteF('If you want to use this with a script...\n')
  122. WriteF('\tlist >ram:tr #?.fd lformat "fdtoi %n %m.i private nodie"\n')
  123. WriteF('You can then just "execute ram:tr" which will convert all .fd files.\n')
  124. ENDPROC
  125.  
  126. CHAR '$VER: FDtoI v1.00 by Zeb/SLP (21-Aug-2024)',0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement