getrecord.rexx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* getrecord.rexx
  2. This is a rexxscript to scan for pascal records.
  3. I made this one to check my translation of
  4. cheaders to fpc units. It will write two
  5. files one pascalfile and one cfile.
  6. The pascalfile you can almost everytime just
  7. compile with fpc. In the cfile you have to
  8. make some changes, just put in a line that
  9. include the cheader for you testprogram.
  10. So if you translate a cheader to fpc just
  11. let this script check it out, if you get
  12. the same result from both program you have
  13. probably made the translation correct.
  14. Usage:
  15. rx getrecord yourunit.pas
  16. [email protected]
  17. */
  18. SIGNAL ON BREAK_C
  19. SIGNAL ON SYNTAX
  20. parse arg name
  21. if name = '' then do
  22. say 'Input filename to scan for records'
  23. parse pull name end
  24. if name = '' then do
  25. say 'Error no filename'
  26. exit 20
  27. end
  28. end
  29. k = 1
  30. thesource = name
  31. if index(name,'.') > 0 then do
  32. parse var name thesource '.' extension
  33. end
  34. pasname = thesource || 'rec1.pas'
  35. cname = thesource || 'rec2.c'
  36. IF ~Open('textfile',name,'READ') THEN DO
  37. say 'File not found'
  38. exit 20
  39. end
  40. else do
  41. say 'Scanning ' || name
  42. i = 1
  43. DO WHILE ~eof('textfile')
  44. line.i = ReadLn('textfile')
  45. line.i = Strip(line.i)
  46. myproc = Word(line.i,3)
  47. myproc = Upper(myproc)
  48. IF myproc = "RECORD" THEN DO
  49. CALL CheckLine(line.i)
  50. SAY "Doing line :" || i
  51. END
  52. i = i +1
  53. END
  54. CALL Close('textfile')
  55. if k > 1 then do
  56. call writepasfile
  57. call writecfile
  58. say 'Done'
  59. end
  60. else say 'No records found'
  61. END
  62. EXIT
  63. pasheader:
  64. writeln('outfile','Program testrecords;')
  65. writeln('outfile','')
  66. writeln('outfile','uses exec,' || thesource || ';')
  67. writeln('outfile','')
  68. writeln('outfile','begin')
  69. return
  70. writepasfile:
  71. if ~Open('outfile',pasname,'W') then do
  72. say 'Can not create file'
  73. exit 20
  74. end
  75. else do
  76. SAY "Working on " || pasname
  77. call pasheader
  78. do j = 1 to k-1
  79. thename = record.j
  80. towrite = 'writeln(' || "'" || thename || "',' ':30-length(" || "'" ||thename || "'),"
  81. towrite = towrite || "':'"
  82. towrite = towrite || ',sizeof(' || thename || '));'
  83. writeln('outfile',towrite)
  84. end j
  85. writeln('outfile','end.')
  86. writeln('outfile','')
  87. CALL Close('outfile')
  88. RETURN
  89. cheader:
  90. writeln('outfile','');
  91. writeln('outfile','#include ' || '"stdio.h"')
  92. writeln('outfile','')
  93. writeln('outfile','main()')
  94. writeln('outfile','{')
  95. return
  96. writecfile:
  97. if ~Open('outfile',cname,'W') then do
  98. say 'Can not create file'
  99. exit 20
  100. end
  101. else do
  102. SAY "Working on " || cname
  103. call cheader
  104. do j = 1 to k-1
  105. thename = record.j
  106. towrite = 'printf(' || '"%-30s:%d\n","' || thename || '",'
  107. towrite = towrite || 'sizeof(struct ' || right(thename,length(thename)-1) ||'));'
  108. writeln('outfile',towrite)
  109. end j
  110. writeln('outfile','}')
  111. writeln('outfile','')
  112. CALL Close('outfile')
  113. return
  114. CheckLine:
  115. PARSE ARG theline
  116. parse var theline thename thesep therecord therest
  117. if thesep = '=' then do
  118. thename = strip(thename)
  119. record.k = thename
  120. k = k +1
  121. end
  122. RETURN
  123. BREAK_C:
  124. SYNTAX:
  125. SAY "Sorry, error line" SIGL ":" ErrorText(RC) ":-("
  126. EXIT