home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 529a.lha / offset / offset.rexx < prev    next >
OS/2 REXX Batch file  |  1991-07-02  |  2KB  |  87 lines

  1. /* offset.rexx $VER: v1.1a_1991-04-20 E.Lundevall */
  2. parse arg lib funcs
  3.  
  4. private = ''
  5. if lib = '' then do
  6.     say 'Usage: offset library [ function | offset ][function | offset ]...'
  7.     exit
  8.     end
  9.  
  10. pos = index(lib,'.library')
  11. if pos = 0 then do
  12.     pos = index(lib,'.resource')
  13.     if pos = 0 then
  14.         pos = index(lib,'.device')
  15.     end
  16.  
  17. if pos ~= 0 then lib = left(lib,pos-1)    /* Strip extension */
  18.  
  19. filename = 'FD:' || lib || '_lib.fd'
  20.  
  21. if ~open(fdfil,filename,'R') then do
  22.     say 'Could not open fd file -' filename
  23.     exit 20
  24.     end
  25.  
  26. if funcs = '' then loopend = 1
  27. else loopend = words(funcs)
  28.  
  29. do loop = 1 to loopend
  30.         bang = 0
  31.     func = word(funcs,loop)
  32.         if left(func,1) = '!' then do     /* Search for substring */
  33.         func = right(func,length(func)-1)
  34.         bang = 1
  35.         end
  36.     else if index(func,'$') ~= 0 then do  /* Translate hex offset to decimal */
  37.         func = translate(func,'','$')
  38.         if index(func,'-') = 1 then func = 0 - x2d(right(func,length(func)-2))
  39.         else func = x2d(func) - 65536
  40.         end
  41.  
  42.     call seek(fdfil,0,'B')        /* Go to start of fd file */
  43.     do until word(line,1) = '##bias'
  44.         line = readln(fdfil)
  45.         end
  46.  
  47.     offset = 0 - word(line,2)     /* Initial offset */
  48.  
  49.     if datatype(func) = NUM then do /* Look for an offset value */
  50.         offset = offset + 6
  51.         do until offset = func | eof(fdfil)
  52.             line = readln(fdfil)
  53.             if left(line,1) = '*' then iterate
  54.             if left(line,2) = '##' then do
  55.                 if word(line,1) = '##public' then private = ''
  56.                 else if word(line,1) = '##private' then private = '*private*'
  57.                 iterate
  58.                 end
  59.             offset = offset - 6
  60.             end
  61.         if ~eof(fdfil) then say '$'d2x(offset,4) '-$'d2x(0-offset) offset line private
  62.         end
  63.     else do
  64.         func = upper(func)
  65.         do until word(line,1) = '##end' /* Look for a function, or all functions */
  66.             line = readln(fdfil)
  67.             if left(line,1) = '*' then iterate
  68.             if left(line,2) = '##' then do
  69.                 if word(line,1) = '##public' then private = ''
  70.                 else if word(line,1) = '##private' then private = '*private*'
  71.                 iterate
  72.                 end
  73.             parse var line name '(' dummy
  74.                 if bang = 1 & index(upper(name),func) ~= 0 | func = '' then
  75.                 say '$'d2x(offset,4) '-$'d2x(0-offset) offset line private
  76.             else if func = upper(name) then do
  77.                 say '$'d2x(offset,4) '-$'d2x(0-offset) offset line private
  78.                 leave
  79.                 end
  80.             offset = offset - 6
  81.             end
  82.         end
  83.     end
  84. call close(fdfil)
  85.  
  86.  
  87.