home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / 3_1SWTOO.DMS / in.adf / wack.lha / demos / StructureOffset.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1993-09-10  |  2.5 KB  |  100 lines

  1. /* StructureOffset.rexx
  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.  * Rexx script to parse the Structure.offsets file to figure out the
  10.  * offset of a given structure/member.
  11.  *
  12.  * Syntax:    call StructureOffset structure member
  13.  *
  14.  * If successful, the first four characters are the member offset,
  15.  * the next four characters are the member size, and
  16.  * the rest of the string is the full member name.  If failure, the
  17.  * first four characters will be non-hexadecimal.
  18.  *
  19.  * Also sets ARexx clip variable "StructureMembers" to the lines
  20.  * of the structure-offsets file containing all the members of
  21.  * this structure.
  22.  */
  23.  
  24. options results
  25. if ( arg() > 0 ) then
  26. DO
  27.     argline = arg(1)
  28.     parse var argline structure" "member
  29.  
  30.     call open 'structfile', "HD:Structure.offs"
  31.  
  32.     done = 0
  33.     offset = 0
  34.     DO until ( done ~= 0 )
  35.         structdata = '0a'x||readch('structfile',10000)
  36.         if eof('structfile') then
  37.         DO
  38.             done = -1
  39.         END
  40.         else
  41.         DO
  42.             i = pos( '0a'x||structure":",structdata )
  43.             if ( i > 0 ) then
  44.             DO
  45.                 offset = offset + i
  46.                 done = 1
  47.             END
  48.             else
  49.             DO
  50.                 offset = offset + 9000
  51.             END
  52.             call seek('structfile',offset,'b')
  53.         END
  54.     END
  55.     if ( done > 0 ) then
  56.     DO
  57.         /* Offset is correct, so read "enough" to grab the
  58.          * whole structure, then discard everything after
  59.          * the start of the next one:
  60.          */
  61.         structdata = readch('structfile',20000)
  62.         structdata = substr(structdata,pos(":",structdata)+2)
  63.         structdata = left(structdata,pos(":",structdata))
  64.         structdata = left(structdata,lastpos("0a"x,structdata))
  65.  
  66.         /* In case someone wants to parse the whole thing */
  67.         call setclip 'StructureMembers',structdata
  68.  
  69.         i = pos(member,structdata)
  70.         if ( i > 0 ) then
  71.         DO
  72.             start = lastpos( '0a'x, structdata, i )
  73.             end = pos( '0a'x, structdata, i )
  74.             /* Special handling for the "sizeof" line */
  75.             if ( substr(structdata,start+16,7) = 'sizeof(' ) then
  76.             DO
  77.                 response = substr(structdata,start+4,4) || substr(structdata,start+10,4) || substr(structdata,start+16,end-start-16)
  78.             END
  79.             else
  80.             DO
  81.                 response = substr(structdata,start+4,4) || substr(structdata,start+16,4) || substr(structdata,start+22,end-start-22)
  82.             END
  83.         END
  84.         else
  85.         DO
  86.             response = "Couldn't find member" member "in structure" structure
  87.         END
  88.     END
  89.     else
  90.     DO
  91.         response = "Couldn't find structure" structure
  92.     END
  93. END
  94. else
  95. DO
  96.     response = "Bad syntax"
  97. END
  98.  
  99. exit response
  100.