home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / 3_1SWTOO.DMS / in.adf / wack.lha / demos / ShowStructure.wack < prev    next >
Encoding:
Text File  |  1993-09-10  |  1.8 KB  |  93 lines

  1. /* ShowStructure.wack
  2.  *
  3.  * (c) Copyright 1992-1993 Commodore-Amiga, Inc.  All rights reserved.
  4.  *
  5.  * This software is provided as-is and is subject to change; no warranties
  6.  * are made.  All use is at your own risk.  No liability or responsibility
  7.  * is assumed.
  8.  *
  9.  * Show all fields of the specified structure type at the specified or
  10.  * current address.
  11.  *
  12.  * Syntax: ShowStructure structure [address]
  13.  *
  14.  * Binding: bindrx struct ShowStructure
  15.  *
  16.  */
  17.  
  18. options results
  19. if ( arg() > 0 ) then
  20. DO
  21.     argline = arg(1)
  22.     parse var argline structure" "address
  23.     structure = strip(structure)
  24.     address = strip(address)
  25.     if ( structure = "" ) then
  26.     DO
  27.         'Print Bad syntax'
  28.         exit
  29.     END
  30.     if ( address = "" ) then
  31.     DO
  32.         CurrentAddr
  33.         address = result
  34.     END
  35.     call StructureOffset.rexx structure 'sizeof('
  36.     if ( datatype(left(result,4),'X') ) then
  37.     DO
  38.         structdata = getclip('StructureMembers')
  39.         done = 0
  40.         firstline = 1
  41.         firstpos = 1
  42.         DO until ( done ~= 0 )
  43.             nextpos = pos('0a'x, structdata, firstpos )
  44.             if ( nextpos = 0 ) then
  45.             DO
  46.                 done = 1
  47.             END
  48.             else
  49.             DO
  50.                 structline = substr(structdata,firstpos,nextpos-firstpos)
  51.                 offset = substr(structline,4,4)
  52.                 size = strip(substr(structline,16,4))
  53.                 member = substr(structline,22)
  54.  
  55.                 if ( firstline = 1 ) then
  56.                 DO
  57.                     Print structure '(at' address', size' offset')'
  58.                     firstline = 0
  59.                 END
  60.                 else
  61.                 DO
  62.                     memberaddress = d2x(x2d(address)+x2d(offset))
  63.                     if ( size = 1 ) then
  64.                     DO
  65.                         readbyte memberaddress
  66.                     END
  67.                     else if ( size = 2 ) then
  68.                     DO
  69.                         readword memberaddress
  70.                     END
  71.                     else
  72.                     DO
  73.                         readlong memberaddress
  74.                     END
  75.                     contents = result
  76.  
  77.                     Print '  +'offset' = 'memberaddress member '=' contents
  78.  
  79.                 END
  80.                 firstpos = nextpos + 1
  81.             END
  82.         END
  83.     END
  84.     else
  85.     DO
  86.         Print result
  87.     END
  88. END
  89. else
  90. DO
  91.     'Print Bad syntax'
  92. END
  93.