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

  1. /* rexx */
  2. /* Trace TDF file list utility */
  3. /* R.J.Moore 4th May 1996 */
  4. /* version 1.2 */
  5. /*         1.1 fix MODNAME to specify dll in tdf */
  6. /*         1.2 prepare for group and type support in DTRACE */
  7. /*         1.3 suppress null group/type specification */
  8. /*             suppress redundant major code overrides */
  9. /*         1.4 fix push ecs error                      */
  10. /*         1.5 long name support + new merlin rpn commands    */
  11. /*         1.6 @SDD4 RPN command addiions                     */
  12. /*         1.7 Major and Minor in hex and decimal             */
  13. say ';TDFLST: TRACE .TDF file list utility version 1.7'
  14. say ';Author: Richard Moore - 27th July 1998'
  15. say ';Copyright (C) 1995,1996 IBM UK Ltd.'
  16. say ''
  17.  
  18. !.=''
  19. arg !.0tdffile d .
  20.  
  21. if d='DEBUG' then !.0dbg=(0=0)
  22. else !.0dbg=(0=1)
  23.  
  24. if !.0tdffile='' then do
  25.    say 'TDFLST tdf_file'
  26.    exit 4
  27. end  /* Do */
  28.  
  29. if right(!.0tdffile,4)¬='.TDF' then !.0tdffile=!.0tdffile|| '.TDF'
  30.  
  31. !.0tdfopen=0=1
  32. signal on halt name haltexit
  33.  
  34. !.0rxcc=rxfuncadd('SysFileTree','REXXUTIL','SysFileTree')
  35. call SysFileTree !.0tdffile,'x','F'
  36. if x.0=0 then do
  37.    say 'File' !.0tdffile 'not found'
  38.    if !.0rxcc=0 then call rxfuncdrop 'SysFileTree'
  39.    exit 4
  40. end  /* Do */
  41. if !.0rxcc=0 then call rxfuncdrop 'SysFileTree'
  42.  
  43. call initvars
  44.  
  45. x=tdfhdr()
  46. if x<>0 then signal haltexit
  47.  
  48. do i=1 to !.0tdf_keywd_count
  49.    x=tdfkwds(i)
  50.    if x<>0 then signal haltexit
  51. end /* do */
  52.  
  53. x=prtkwds(i)
  54. if x<>0 then signal haltexit
  55.  
  56. say ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
  57. say " "
  58.  
  59. !.0offset=!.0tdf_data_offset
  60. do i=1 to !.0tdf_trec_count
  61.    x=tdfrecord(i)
  62.    if x<>0 then signal haltexit
  63. end /* do */
  64.  
  65.  
  66. haltexit: if !.0tdfopen then x=lineout(!.0tdffile) /* close tfffile */
  67.  
  68. exit 0
  69.  
  70. tdfhdr: procedure expose !.
  71.  
  72. /* deal with tdf header */
  73.  
  74. !.0tdf_signature=getbyte(0,3)
  75. if !.0tdf_signature<>'TDF' then do
  76.    say 'Invalid TDF file'
  77.    return 1
  78. end /* do */
  79.  
  80. !.0tdf_data_lengtth=c2d(getdword(8))
  81. !.0tdf_trec_count=c2d(getdword(12))
  82. !.0tdf_data_offset=c2d(getdword(16))
  83. !.0tdf_local_data_count=c2d(getdword(20))
  84. !.0tdf_max_reclen=c2d(getdword(24))
  85. !.0tdf_major_code=c2d(getword(28))
  86. !.0tdf_mod_name=strip(getbyte(30,256),'t','0'x)
  87. !.0tdf_keywd_count=c2d(getword(286))
  88. !.0tdf_tdf_id=c2d(getword(288))
  89.  
  90. !.0offset=324
  91.  
  92. if !.0dbg then do
  93.    say 'len 0x'd2x(!.0tdf_data_lengtth)
  94.    say 'trec 0x'd2x(!.0tdf_trec_count)
  95.    say 'doff 0x'd2x(!.0tdf_data_offset)
  96.    say 'dcnt 0x'd2x(!.0tdf_local_data_count)
  97.    say 'kwd cnt 0x'd2x(!.0tdf_keywd_count)
  98. end /* do */
  99.  
  100. /*parse var !.0tdffile name '.'  .*/
  101. /*parse var !.0tdf_mod_name name '.'  . */
  102. parse var !.0tdf_mod_name name '.' ext . /* long name support */
  103. if ext='DLL' then say "name="name
  104. else say "name="!.0tdf_mod_name
  105. say "major=0x"d2x(!.0tdf_major_code) ';' !.0tdf_major_code
  106. say "logmax="!.0tdf_max_reclen
  107. say "id="!.0tdf_tdf_id
  108. say "vars="!.0tdf_local_data_count
  109. say " "
  110. !.xmajor=right(d2x(!.0tdf_major_code),4,'0')
  111.  
  112. return 0
  113.  
  114. tdfkwds: procedure expose !.
  115.  
  116. /* deal with the key words (goups and types) */
  117. arg i
  118.  
  119. keyword=strip(getbyte(!.0offset,9),'t','0'x)
  120. !.0offset=!.0offset+9
  121. keytype=getbyte(!.0offset)
  122. !.0offset=!.0offset+1
  123. keyid=c2d(getword(!.0offset))
  124. !.0offset=!.0offset+2
  125.  
  126. if !.0dbg then do
  127.    say 'keyword' keyword
  128.    say 'keytype' c2x(keytype)
  129.    say 'keyid' d2x(keyid)  
  130. end /* do */
  131.  
  132. if keytype='01'x then do
  133.    !.0group.keyid=keyword
  134.    k=!.0groups
  135.    k=k+1
  136.    !.0grplst.k=keyid
  137.    !.0groups=k
  138. end /* do */
  139. else if keytype='02'x then do 
  140.    !.0type.keyid=keyword
  141.    k=!.0types 
  142.    k=k+1
  143.    !.0typlst.k=keyid
  144.    !.0types=k
  145. end /* do */
  146. else do 
  147.    say 'Invalid keytype'
  148.    return 1
  149. end /* do */
  150.  
  151. return 0
  152.  
  153. prtkwds: procedure expose !.
  154.  
  155. /* print out the key words (goups and types) */
  156.  
  157. if !.0groups<>0 then do
  158.    k=!.0grplst.1
  159.    do i=1 to !.0groups
  160.       k=!.0grplst.i
  161.       say 'groupdef='!.0group.k','k
  162.    end /* do */
  163. end
  164. say " "
  165.  
  166. if !.0types<>0 then do
  167.    k=!.0typlst.1
  168.    do i=1 to !.0types
  169.       k=!.0typlst.i
  170.       say 'typedef='!.0type.k','k
  171.    end /* do */
  172. end /* do */
  173. say " "
  174. return 0
  175.  
  176.  
  177. tdfrecord: procedure expose !.
  178.  
  179. /* deal with the minor tp record */
  180. arg i
  181.  
  182. tp_length=c2d(getword(!.0offset))
  183. !.0offset=!.0offset+2
  184.  
  185. tp_type_id=getword(!.0offset)
  186. !.0offset=!.0offset+2
  187.  
  188. tp_group_id=c2d(getword(!.0offset))
  189. !.0offset=!.0offset+2
  190.  
  191. tp_segment=c2x(getdword(!.0offset))
  192. !.0offset=!.0offset+4
  193.  
  194. tp_offset=c2x(getdword(!.0offset))
  195. !.0offset=!.0offset+4
  196.  
  197. tp_minor=c2x(getword(!.0offset))
  198. !.0offset=!.0offset+2
  199.  
  200. tp_major=c2x(getword(!.0offset))
  201. !.0offset=!.0offset+2
  202.  
  203. tp_cmdlen=c2d(getword(!.0offset))
  204. !.0offset=!.0offset+2
  205.  
  206. tp_opcode=c2x(getbyte(!.0offset))
  207. !.0offset=!.0offset+2
  208.  
  209. if !.0dbg then do
  210.    say 'cmd len 0x'd2x(tp_cmdlen)
  211.    say 'rec len 0x'd2x(tp_length)
  212.    say 'type id 0x'c2x(tp_type_id)
  213.    say 'group id 0x'd2x(tp_group_id)
  214. end /* do */
  215.  
  216.  
  217. say "minor=0x"tp_minor ';' x2d(tp_minor)
  218. if tp_major<> !.xmajor then say "major=0x"tp_major
  219. group=!.0group.tp_group_id
  220. if group<>'' then say "group="group
  221. type=''
  222. if tp_type_id <>'0000'x then do 
  223.    do i=0 to 15
  224.       mask=d2c(2**i,2)
  225.       seltype=c2d(bitand(tp_type_id,mask))
  226.       if seltype<>0 then do
  227.          if !.0dbg then say 'selected type 0x'd2x(seltype)
  228.          if type='' then type=!.0type.seltype
  229.          else type=type'+'!.0type.seltype
  230.       end /* do */
  231.    end /* do */
  232. end /* do */
  233.  
  234. if type <>'' then say "type="type
  235. say "object=0x"tp_segment
  236. say "offset=0x"tp_offset
  237. say "opcode=0x"tp_opcode
  238.  
  239.  
  240. do i=1 to tp_cmdlen
  241.    cmd=c2d(getbyte(!.0offset))
  242.    !.0offset=!.0offset+1
  243.    if !.0dbg then say 'rpn cmd 0x'd2x(cmd)
  244.    instr=!.0instr.cmd
  245.    oplen=!.0oplen.cmd
  246.    select
  247.       when oplen=0 then say instr
  248.       when oplen=1 then do
  249.          op=c2x(getbyte(!.0offset))
  250.          say instr",0x"op
  251.          !.0offset=!.0offset+1
  252.          i=i+1
  253.       end /* do */
  254.       when oplen=2 then do
  255.          op=c2x(getword(!.0offset))
  256.          say instr",0x"op
  257.          !.0offset=!.0offset+2
  258.          i=i+2
  259.       end /* do */
  260.       when oplen=4 then do
  261.          op=c2x(getdword(!.0offset))
  262.          say instr",0x"op
  263.          !.0offset=!.0offset+4
  264.          i=i+4
  265.       end /* do */
  266.    otherwise
  267.    say 'Invalid RPN command' d2x(cmd)
  268.    return 1
  269.    end  /* select */
  270. end /* do */
  271.  
  272. say " "
  273. say ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
  274. say " "
  275.  
  276. return 0     
  277.  
  278. initvars: procedure expose !.
  279.    !.0groups=0
  280.    !.0types=0
  281.  
  282.    !.0instr.0="push eax"        
  283.    !.0instr.1="push ecx"        
  284.    !.0instr.2="push edx"        
  285.    !.0instr.3="push ebx"        
  286.    !.0instr.4="push esp"        
  287.    !.0instr.5="push ebp"        
  288.    !.0instr.6="push esi"        
  289.    !.0instr.7="push edi"        
  290.    !.0instr.8="push es"         
  291.    !.0instr.9="push cs"         
  292.    !.0instr.10="push ss"        
  293.    !.0instr.11="push ds"        
  294.    !.0instr.12="push eflags"    
  295.    !.0instr.13="push eip"
  296.    !.0instr.14="push fs"
  297.    !.0instr.15="push gs"
  298.    !.0instr.16="push w"
  299.    !.0instr.17="push oxs"
  300.    !.0instr.18="push wis"
  301.    !.0instr.19="push sis"
  302.    !.0instr.20="log wn"
  303.    !.0instr.21="log mrs"
  304.    !.0instr.22="add"
  305.    !.0instr.23="nop w17"
  306.    !.0instr.24="nop w18"
  307.    !.0instr.25="log ars"
  308.    !.0instr.26="push d"
  309.    !.0instr.27="push oxf"
  310.    !.0instr.28="push fif"
  311.    !.0instr.29="cnvrt fxs"
  312.    !.0instr.30="cnvrt sxf"
  313.    !.0instr.31="cnvrt dxs"
  314.    !.0instr.32="cnvrt sxd"
  315.    !.0instr.33="log dn"
  316.    !.0instr.34="log mrf"
  317.    !.0instr.35="log arf"
  318.    !.0instr.36="sub"
  319.    !.0instr.37="mul"
  320.    !.0instr.38="pop n"
  321.    !.0instr.39="move v"
  322.    !.0instr.40="push v"
  323.    !.0instr.41="inc v"
  324.    !.0instr.42="move vii"
  325.    !.0instr.43="push vii"
  326.    !.0instr.44="inc vii"
  327.    !.0instr.45="jmp n"
  328.    !.0instr.46="jmp zn"
  329.    !.0instr.47="jmp nn"
  330.    !.0instr.48="jmp pn"
  331.    !.0instr.49="abort"
  332.    !.0instr.50="or v"
  333.    !.0instr.51="remove"
  334.    !.0instr.52="sysdump"
  335.    !.0instr.53="and"
  336.    !.0instr.54="or"
  337.    !.0instr.55="xor"
  338.    !.0instr.56="not"
  339.    !.0instr.57="exit"
  340.    !.0instr.58="procdump"
  341.    !.0instr.59="setminw"
  342.    !.0instr.60="setmajw"
  343.    !.0instr.61="setmin"
  344.    !.0instr.62="setmaj"
  345.    !.0instr.63="xchg"           /*@sdd4*/
  346.    !.0instr.64="call kdb"       /*@sdd4*/
  347.    !.0instr.65="call dd"        /*@sdd4*/
  348.    !.0instr.66="call dbg"       /*@sdd4*/
  349.    !.0instr.67="dup n"          /*@sdd4*/
  350.    !.0instr.68="dup"            /*@sdd4*/
  351.    !.0instr.69="enter bif"      /*@sdd4*/
  352.    !.0instr.70="enter wif"      /*@sdd4*/
  353.    !.0instr.71="enter dif"      /*@sdd4*/
  354.    !.0instr.72="enter bis"      /*@sdd4*/
  355.    !.0instr.73="enter wis"      /*@sdd4*/
  356.    !.0instr.74="enter dis"      /*@sdd4*/
  357.    !.0instr.75="push bif"       /*@sdd4*/
  358.    !.0instr.76="push bis"       /*@sdd4*/
  359.    !.0instr.77="push dis"       /*@sdd4*/
  360.    !.0instr.78="push wif"       /*@sdd4*/
  361.    !.0instr.79="push tsc"       /*@sdd4*/
  362.    !.0instr.80="push tid"       /*@sdd4*/
  363.    !.0instr.81="push pid"       /*@sdd4*/
  364.    !.0instr.82="push procid"    /*@sdd4*/
  365.    !.0instr.83="push slot"      /*@sdd4*/
  366.    !.0instr.84="push pTCB"      /*@sdd4*/
  367.    !.0instr.85="push pPTDA"     /*@sdd4*/
  368.    !.0instr.86="push pPCB"      /*@sdd4*/
  369.    !.0instr.87="suspend"        /*@sdd4*/
  370.    !.0instr.88="resume"         /*@sdd4*/
  371.    !.0instr.89="rol n"          /*@sdd4*/
  372.    !.0instr.90="ror n"          /*@sdd4*/
  373.    !.0instr.91="shl n"          /*@sdd4*/
  374.    !.0instr.92="shr n"          /*@sdd4*/
  375.    !.0instr.93="rol"            /*@sdd4*/
  376.    !.0instr.94="ror"            /*@sdd4*/
  377.    !.0instr.95="shl"            /*@sdd4*/
  378.    !.0instr.96="shr"            /*@sdd4*/
  379.    !.0instr.97="vfa"            /*@sdd4*/
  380.    !.0instr.98="vsa"            /*@sdd4*/
  381.    !.0instr.99="push keax"      /*@sdd4*/
  382.    !.0instr.100="push kecx"     /*@sdd4*/
  383.    !.0instr.101="push kedx"     /*@sdd4*/
  384.    !.0instr.102="push kebx"     /*@sdd4*/
  385.    !.0instr.103="push kesp"     /*@sdd4*/
  386.    !.0instr.104="push kebp"     /*@sdd4*/
  387.    !.0instr.105="push kesi"     /*@sdd4*/
  388.    !.0instr.106="push kedi"     /*@sdd4*/
  389.    !.0instr.107="push kes"      /*@sdd4*/
  390.    !.0instr.108="push kcs"      /*@sdd4*/
  391.    !.0instr.109="pushk ss"      /*@sdd4*/
  392.    !.0instr.110="pushk ds"      /*@sdd4*/
  393.    !.0instr.111="pushk eflags"  /*@sdd4*/
  394.    !.0instr.112="pushk eip"     /*@sdd4*/
  395.    !.0instr.113="pushk fs"      /*@sdd4*/
  396.    !.0instr.114="pushk gs"      /*@sdd4*/
  397.    !.0instr.115="enter eax"     /*@sdd4*/
  398.    !.0instr.116="enter ebx"     /*@sdd4*/
  399.    !.0instr.117="enter ecx"     /*@sdd4*/
  400.    !.0instr.118="enter edx"     /*@sdd4*/
  401.    !.0instr.119="enter esi"     /*@sdd4*/
  402.    !.0instr.120="enter edi"     /*@sdd4*/
  403.    !.0instr.121="enter ebp"     /*@sdd4*/
  404.    !.0instr.122="enter ds"      /*@sdd4*/
  405.    !.0instr.123="enter es"      /*@sdd4*/
  406.    !.0instr.124="enter fs"      /*@sdd4*/
  407.    !.0instr.125="enter gs"      /*@sdd4*/
  408.    !.0instr.126="push cr0"      /*@sdd4*/
  409.    !.0instr.127="push cr2"      /*@sdd4*/
  410.    !.0instr.128="push cr3"      /*@sdd4*/
  411.    !.0instr.129="push cr4"      /*@sdd4*/
  412.    !.0instr.130="push dr0"      /*@sdd4*/
  413.    !.0instr.131="push dr1"      /*@sdd4*/
  414.    !.0instr.132="push dr2"      /*@sdd4*/
  415.    !.0instr.133="push dr3"      /*@sdd4*/
  416.    !.0instr.134="push dr6"      /*@sdd4*/
  417.    !.0instr.135="push dr7"      /*@sdd4*/
  418.    !.0instr.136="push tr"       /*@sdd4*/
  419.    !.0instr.137="push ldtr"     /*@sdd4*/
  420.    !.0instr.138="push gdtr"     /*@sdd4*/
  421.    !.0instr.139="push idtr"     /*@sdd4*/
  422.    !.0instr.140="push msr"      /*@sdd4*/
  423.    !.0instr.141="push pmc"      /*@sdd4*/
  424.    !.0instr.142="push cpuid"    /*@sdd4*/
  425.  
  426.    
  427.    !.0oplen.0=0
  428.    !.0oplen.1=0
  429.    !.0oplen.2=0
  430.    !.0oplen.3=0
  431.    !.0oplen.4=0
  432.    !.0oplen.5=0
  433.    !.0oplen.6=0
  434.    !.0oplen.7=0
  435.    !.0oplen.8=0
  436.    !.0oplen.9=0
  437.    !.0oplen.10=0
  438.    !.0oplen.11=0
  439.    !.0oplen.12=0
  440.    !.0oplen.13=0
  441.    !.0oplen.14=0
  442.    !.0oplen.15=0
  443.    !.0oplen.16=2
  444.    !.0oplen.17=1
  445.    !.0oplen.18=0
  446.    !.0oplen.19=0
  447.    !.0oplen.20=1
  448.    !.0oplen.21=0
  449.    !.0oplen.22=0
  450.    !.0oplen.23=0
  451.    !.0oplen.24=0
  452.    !.0oplen.25=0
  453.    !.0oplen.26=4
  454.    !.0oplen.27=4
  455.    !.0oplen.28=0
  456.    !.0oplen.29=0
  457.    !.0oplen.30=0
  458.    !.0oplen.31=0
  459.    !.0oplen.32=0
  460.    !.0oplen.33=1
  461.    !.0oplen.34=0
  462.    !.0oplen.35=0
  463.    !.0oplen.36=0
  464.    !.0oplen.37=0
  465.    !.0oplen.38=1
  466.    !.0oplen.39=2
  467.    !.0oplen.40=2
  468.    !.0oplen.41=2
  469.    !.0oplen.42=0
  470.    !.0oplen.43=0
  471.    !.0oplen.44=0
  472.    !.0oplen.45=2
  473.    !.0oplen.46=2
  474.    !.0oplen.47=2
  475.    !.0oplen.48=2
  476.    !.0oplen.49=0
  477.    !.0oplen.50=2
  478.    !.0oplen.51=0
  479.    !.0oplen.52=0
  480.    !.0oplen.53=0
  481.    !.0oplen.54=0
  482.    !.0oplen.55=0
  483.    !.0oplen.56=0
  484.    !.0oplen.57=0
  485.    !.0oplen.58=0
  486.    !.0oplen.59=2
  487.    !.0oplen.60=2
  488.    !.0oplen.61=0
  489.    !.0oplen.62=0
  490.    !.0oplen.63=0
  491.  
  492.  
  493. return
  494.  
  495. x=getbyte(!.0tdf.i.0offset)
  496. do while x<>'0'x
  497.    !.0tdf.i.0fmt=!.0tdf.i.0fmt || x
  498.    !.0tdf.i.0offset=!.0tdf.i.0offset+1
  499.    x=getbyte(!.0tdf.i.0offset)
  500. end /* do */
  501.  
  502. return 0     
  503.  
  504.  
  505. getbyte: procedure expose !.
  506. /* read one or more bytes from the .tff file from given offset */
  507.  
  508. parse arg offset,length
  509. if length='' then length=1
  510. return charin(!.0tdffile,offset+1,length)
  511.  
  512. getword: procedure expose !.
  513. /* read a word from the .tff file from given offset */
  514.  
  515. parse arg offset
  516. x=charin(!.0tdffile,offset+1,2)
  517. return translate('12',x,'21')
  518.  
  519. getdword: procedure expose !.
  520. /* read a double word from the .tff file from given offset */
  521.  
  522. parse arg offset
  523. x=charin(!.0tdffile,offset+1,4)
  524. return translate('1234',x,'4321')
  525.