home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / tfflst.zip / tfflst.cmd next >
OS/2 REXX Batch file  |  1998-07-27  |  5KB  |  206 lines

  1. /* rexx */
  2. /* Trace TFF file list utility */
  3. /* R.J.Moore 4 May 1996 */
  4. /* version 1.0 */
  5. say ";TFFLST: TRACE .TFF file list utility version 1.1"
  6. say ";Author: Richard Moore - 27th July 98"
  7. say ';Copyright (C) 1995, IBM UK Ltd.'
  8. say ""
  9.  
  10. !.=""
  11. arg !.0tfffile d .
  12.  
  13. if d="DEBUG" then !.0dbg=(0=0)
  14. else !.0dbg=(0=1)
  15.  
  16. if !.0tfffile="" then do
  17.    say "TFFLST tff_file"
  18.    exit 4
  19. end  /* Do */
  20.  
  21. if right(!.0tfffile,4)¬=".TFF" then !.0tfffile=!.0tfffile|| ".TFF"
  22.  
  23. !.0tffopen=0=1
  24. signal on halt name haltexit
  25.  
  26. !.0rxcc=rxfuncadd("SysFileTree","REXXUTIL","SysFileTree")
  27. call SysFileTree !.0tfffile,"x","F"
  28. if x.0=0 then do
  29.    say "File" !.0tfffile "not found"
  30.    if !.0rxcc=0 then call rxfuncdrop "SysFileTree"
  31.    exit 4
  32. end  /* Do */
  33. if !.0rxcc=0 then call rxfuncdrop "SysFileTree"
  34.  
  35. x=tffhdr()
  36. if x<>0 then signal haltexit
  37.  
  38. do i=1 to !.0tff_rec_count
  39.    x=tffindx(i)
  40.    if x<>0 then signal haltexit
  41. end /* do */
  42.  
  43. do i=1 to !.0tff_rec_count
  44.    x=tffrecord(i)
  45.    if x<>0 then signal haltexit
  46. end /* do */
  47.  
  48. do i=1 to !.0tff_rec_count
  49.    x=tffprint(i)
  50.    if x<>0 then signal haltexit
  51. end /* do */
  52.  
  53.  
  54. haltexit: if !.0tffopen then x=lineout(!.0tfffile) /* close tfffile */
  55.  
  56. exit 0
  57.  
  58. tffhdr: procedure expose !.
  59.  
  60. /* deal with tff header */
  61.  
  62. !.0tff_signature=getbyte(0,3)
  63. if !.0tff_signature<>"TFF" then do
  64.    say "Invalid TFF file"
  65.    return 1
  66. end /* do */
  67.  
  68. !.0tff_major_code=c2d(getword(4))
  69. !.0tff_rec_count=c2d(getword(6))
  70. !.0tff_index_offset=c2d(getdword(8))
  71.  
  72. if !.0dbg then do
  73.    say "major" !.0tff_major_code
  74.    say "rec count" !.0tff_rec_count
  75.    say "index offset 0x"d2x(!.0tff_index_offset)
  76. end /* do */
  77.  
  78. parse var !.0tfffile name "."  .
  79. say 'MODNAME='name
  80. say 'MAJOR=0x'd2x(!.0tff_major_code) ';' !.0tff_major_code
  81. say ' '
  82.  
  83. return 0
  84.  
  85. tffindx: procedure expose !.
  86.  
  87. /* deal with the index portion */
  88. arg i
  89.  
  90. !.0tff.i.0minor_code=c2x(getword(!.0tff_index_offset))
  91. !.0tff.i.0rec_len=c2d(getword(!.0tff_index_offset+2))
  92. !.0tff.i.0offset=c2d(getdword(!.0tff_index_offset+4))
  93.  
  94. !.0tff_index_offset=!.0tff_index_offset+8
  95.  
  96. if !.0dbg then do
  97.    say "minor" !.0tff.i.0minor_code
  98.    say "rec length" !.0tff.i.0rec_len
  99.    say "rec offset 0x"d2x(!.0tff.i.0offset)
  100. end /* do */
  101.  
  102.  
  103. return 0
  104.  
  105.  
  106. tffrecord: procedure expose !.
  107.  
  108. /* deal with the minor tp record */
  109. arg i
  110.  
  111. x=getbyte(!.0tff.i.0offset)
  112. do while x<>"0"x
  113.    if !.0dbg then say x
  114.    !.0tff.i.0desc=!.0tff.i.0desc || x
  115.    !.0tff.i.0offset=!.0tff.i.0offset+1
  116.    x=getbyte(!.0tff.i.0offset)
  117. end /* do */
  118.  
  119. if !.0dbg then say "----------------------------------------------------------"
  120.  
  121. !.0tff.i.0offset=!.0tff.i.0offset+1
  122. x=getbyte(!.0tff.i.0offset)
  123. if x="0"x then j=0 
  124. else j=1
  125. do while x<>"0"x
  126.    if !.0dbg then say x
  127.    if x="1"x then x="%"
  128.    if x="a"x then do
  129.       !.0tff.i.0offset=!.0tff.i.0offset+1
  130.       x=getbyte(!.0tff.i.0offset)
  131.       if x<>"0"x then j=j+1
  132.       iterate
  133.    end /* do */
  134.    if x="d"x then do
  135.       !.0tff.i.0offset=!.0tff.i.0offset+1
  136.       x=getbyte(!.0tff.i.0offset)
  137.       iterate
  138.    end /* do */
  139.    !.0tff.i.0fmt.j=!.0tff.i.0fmt.j || x
  140.    !.0tff.i.0offset=!.0tff.i.0offset+1
  141.    x=getbyte(!.0tff.i.0offset)
  142. end /* do */
  143. !.0tff.i.0fmt.0=j
  144.  
  145. if !.0dbg then say "----------------------------------------------------------"
  146.  
  147. return 0     
  148.  
  149.  
  150. tffprint: procedure expose !.
  151.  
  152. /* format each minor .TFF record */
  153. arg i
  154.  
  155. say '/* start TP 0x'!.0tff.i.0minor_code '('x2d(!.0tff.i.0minor_code)') */'
  156. say ' '
  157. say 'TRACE MINOR=0x'!.0tff.i.0minor_code',' 
  158. say '      TP=@STATIC,'
  159. if !.0tff.i.0fmt.0>0 then do
  160.    say '      DESC="'!.0tff.i.0desc'",'
  161.    do j=1 to !.0tff.i.0fmt.0 -1
  162.       say '      FMT="'!.0tff.i.0fmt.j'",'
  163.    end /* do */
  164.    say '      FMT="'!.0tff.i.0fmt.j'"'
  165. end /* do */
  166. else do
  167.    SAY '      DESC="'!.0tff.i.0desc'"'
  168. end /* do */
  169. say ' '
  170. say '/* end TP 0x'!.0tff.i.0minor_code '('x2d(!.0tff.i.0minor_code)') */'
  171. say ' '
  172.  
  173. return 0
  174.  
  175.  
  176. x=getbyte(!.0tff.i.0offset)
  177. do while x<>"0"x
  178.    !.0tff.i.0fmt=!.0tff.i.0fmt || x
  179.    !.0tff.i.0offset=!.0tff.i.0offset+1
  180.    x=getbyte(!.0tff.i.0offset)
  181. end /* do */
  182.  
  183. return 0     
  184.  
  185.  
  186. getbyte: procedure expose !.
  187. /* read one or more bytes from the .tff file from given offset */
  188.  
  189. parse arg offset,length
  190. if length="" then length=1
  191. return charin(!.0tfffile,offset+1,length)
  192.  
  193. getword: procedure expose !.
  194. /* read a word from the .tff file from given offset */
  195.  
  196. parse arg offset
  197. x=charin(!.0tfffile,offset+1,2)
  198. return translate("12",x,"21")
  199.  
  200. getdword: procedure expose !.
  201. /* read a double word from the .tff file from given offset */
  202.  
  203. parse arg offset
  204. x=charin(!.0tfffile,offset+1,4)
  205. return translate("1234",x,"4321")
  206.