home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 19 / AACD19.BIN / AACD / Programming / YAEC / testsrc / FD2Module.e < prev    next >
Encoding:
Text File  |  2001-02-23  |  5.9 KB  |  193 lines

  1.  
  2. -> slightly edited for YAEC1.4a
  3. -> turned Out()s into Write()s
  4. -> else YAECs buffered Out() would mess up the unbuffered Write()s.
  5.  
  6. /*
  7.  
  8. fd2module V1.0
  9. Alex McCracken Mar 1994
  10.  
  11. This program is heavily based on Wouter van Oortmerssen's pragma2module.
  12. In fact about 90% of the code belongs to Wouter, so I claim no credit for
  13. this. However, since Wouter's praga2module works very well for files in
  14. the correct format, I must state that if this fails it is most probably my
  15. fault.  You may use this program as you see fit, however should it fail and
  16. eat your dog, cause your telly to explode, or cause any problems
  17. what-so-ever, I will not be held responsible.  In other word use this at
  18. your own risk.  I have made every effort to ensure it works, but I cannot
  19. guarantee to have found all the niggly little ones that plauge almost all
  20. programs.
  21.  
  22. Usage
  23.  
  24. The program in invoked by typing (CLI only):
  25.  
  26.         fd2module <libname>
  27.  
  28. where libname is the name of the fd file minus the _lib.fd extension.
  29. This will produce a file <libname>.m .  At the moment the program echos the
  30. fd file as it reads it, but this may change in a future release.  You will
  31. need to give the program the name of the library explicitly, again this may
  32. change.
  33.  
  34. Distribution
  35.  
  36. This may be distributed by any means fit. However I retain the right to update
  37.  the package without informing anyone.  This distribution should contain:
  38.         fd2module               The executable
  39.         fd2module.doc           This document
  40.  
  41. Reaching me
  42.  
  43. I can be reached in the following ways:
  44.  
  45. Snail Mail:
  46.         Alex McCracken
  47.         11 Charles Street
  48.         Kilmarnock
  49.         Ayrshire
  50.         KA1 2DX
  51.         Scotland
  52.  
  53. Internet email:
  54.         mccracal@dcs.gla.ac.uk
  55.  
  56. I only use my email account during term time so over the summer it is probally
  57. best to write to me by snail mail.  The email address should remain valid until
  58. summer '95.
  59.  
  60. */
  61.  
  62. /* FD2Module
  63.    convert a library fd file to an E module.
  64.    Usage: fd2module <file>
  65.    converts <file_lib.fd> to <file.m>                                  */
  66.  
  67. ENUM INPUT_ERROR=10,OUTPUT_ERROR,FORMAT_ERROR
  68.  
  69. DEF cfh,efh,eof,done,gotbase=0,public=-1,offset=30
  70. DEF    cfile[200]:STRING, efile[200]:STRING, cstring[200]:STRING
  71.  
  72. PROC main()
  73.   StrCopy(cfile,arg,ALL)
  74.   StrAdd(cfile,'_lib.fd',ALL)
  75.   StrCopy(efile,arg,ALL)
  76.   StrAdd(efile,'.m',ALL)
  77.   PrintF('Amiga E FD2Module\nconverting: \"\s\" to \"\s\"\n',cfile,efile)
  78.   IF (cfh:=Open(cfile,OLDFILE))=0 THEN closeall(INPUT_ERROR)
  79.   IF (efh:=Open(efile,NEWFILE))=0 THEN closeall(OUTPUT_ERROR)
  80.   REPEAT
  81.     eof:=ReadStr(cfh,cstring)
  82.     done:=convert(cstring)
  83.   UNTIL eof OR done
  84.   PrintF('last offset: -\d\n',offset)
  85.   Write(efh, [$FF]:CHAR, 1) ->Out(efh,$FF)
  86.   PrintF('Done.\n')
  87.   closeall(0)
  88. ENDPROC
  89.  
  90. PROC closeall(er)
  91.   IF cfh<>0 THEN Close(cfh)
  92.   IF efh<>0 THEN Close(efh)
  93.   SELECT er
  94.     CASE INPUT_ERROR;  PrintF('Could not open input file!\n')
  95.     CASE OUTPUT_ERROR; PrintF('Could not open output file!\n')
  96.     CASE FORMAT_ERROR; PrintF('Function definition file format error!\n')
  97.   ENDSELECT
  98.   Raise(er) -> CleanUp(er)
  99. ENDPROC
  100.  
  101.  
  102. PROC convert(str)
  103. DEF     pos,pos2,off2,len,narg,a,empty,dstr[50]:STRING,basestr[50]:STRING
  104. DEF     funcstr[50]:STRING,regstr[20]:STRING,libstr[50]:STRING
  105. DEF     tstr[80]:STRING,t2str[80]:STRING,t3str[80]:STRING,reg,check
  106.  
  107.  
  108.   MidStr(tstr,str,TrimStr(str)-str,ALL)
  109.   LowerStr(tstr)
  110.   PrintF('\s\n',str)
  111.   IF StrCmp(tstr,'##base ',STRLEN) OR StrCmp(tstr,'##base\t',STRLEN)
  112.     pos:=STRLEN
  113.     pos2:=InStr(tstr,'_')
  114.     IF pos2=-1 THEN closeall(FORMAT_ERROR)
  115.     IF gotbase=FALSE
  116.       gotbase:=TRUE
  117.       MidStr(basestr,str,(pos2+1),ALL)
  118.       LowerStr(basestr)
  119.       PrintF('Base will be: \s\n',basestr)
  120.       PrintF('Correct name of this library (with the \".library\" or \".device\"):\n>')
  121.       ReadStr(stdout,libstr)
  122.       Write(efh,["EM","OD",6]:INT,6)
  123.       Write(efh,libstr,EstrLen(libstr)+1)
  124.       Write(efh,basestr,EstrLen(basestr)+1)
  125.     ENDIF
  126.   ELSEIF StrCmp(tstr,'##bias ',STRLEN) OR StrCmp(tstr,'##bias\t',STRLEN)
  127.     pos:=STRLEN
  128.     MidStr(t2str,tstr,pos,ALL)
  129.     pos2:=TrimStr(t2str)
  130.     MidStr(t3str,t2str,pos2-t2str,ALL)
  131.     off2:=Val(t3str)
  132.     IF off2=0 THEN closeall(FORMAT_ERROR)
  133.     WHILE off2<>offset
  134.       Write(efh,'Dum',3)                     /* "empty function slots" */
  135.       Write(efh, [16]:CHAR, 1) ->Out(efh,16)
  136.       IF offset>off2 THEN closeall(FORMAT_ERROR)
  137.       offset:=offset+6
  138.     ENDWHILE
  139.   ELSEIF StrCmp(tstr,'##private',ALL)
  140.     public:=FALSE
  141.   ELSEIF StrCmp(tstr,'##public',ALL)
  142.     public:=TRUE
  143.   ELSEIF StrCmp(tstr,'##end',ALL)
  144.     RETURN TRUE
  145.   ELSEIF StrCmp(tstr,'*',STRLEN)
  146.   ELSE
  147.     IF public
  148.       pos:=0
  149.       pos2:=InStr(str,'(',pos)
  150.       IF pos2=-1 THEN closeall(FORMAT_ERROR)
  151.       MidStr(funcstr,str,pos,pos2-pos)
  152.       IF funcstr[0] >= "a" THEN funcstr[0] := funcstr[0]-32
  153.       IF funcstr[1] < "a" THEN funcstr[1] := funcstr[1]+32
  154.       Write(efh,funcstr,EstrLen(funcstr))
  155.       pos:=pos2+1
  156.       pos2:=InStr(str,'(',pos)
  157.       IF pos2=-1 THEN closeall(FORMAT_ERROR)
  158.       narg:=0
  159.       MidStr(dstr,str,pos2+1,ALL)
  160.       UpperStr(dstr)
  161.       WHILE StrCmp(dstr,')',1)=FALSE
  162.         IF EstrLen(dstr)<2 THEN closeall(FORMAT_ERROR)
  163.         MidStr(regstr,dstr,0,2)
  164.         IF StrCmp(regstr,'D',1) OR StrCmp(regstr,'A',1)
  165.           IF StrCmp(regstr,'D',1)
  166.             reg:=0
  167.           ELSEIF StrCmp(regstr,'A',1)
  168.             reg:=8
  169.           ENDIF
  170.           MidStr(regstr,regstr,1,ALL)
  171.           reg:=reg+Val(regstr)
  172.           check := D1 -> yaec-note : secondreturnvalue trick for now
  173.           IF check<1 THEN closeall(FORMAT_ERROR)
  174.         ELSE
  175.           closeall(FORMAT_ERROR)
  176.         ENDIF
  177.         MidStr(dstr,dstr,2,ALL)
  178.         IF StrCmp(dstr,',',1) OR StrCmp(dstr,'/',1)
  179.           MidStr(dstr,dstr,1,ALL)
  180.         ENDIF
  181.         Write(efh, [reg]:CHAR, 1) ->Out(efh,reg)
  182.         narg++
  183.       ENDWHILE
  184.       IF narg=0 THEN Write(efh, [16]:CHAR, 1) ->Out(efh,16)
  185.       offset:=offset+6
  186.     ELSE
  187.       Write(efh,'Dum',3)
  188.       Write(efh, [16]:CHAR, 1) ->Out(efh,16)
  189.       offset:=offset+6
  190.     ENDIF
  191.   ENDIF
  192. ENDPROC FALSE
  193.