home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / rexx / dbstr.cpr < prev    next >
Encoding:
Text File  |  1996-12-24  |  1.2 KB  |  53 lines

  1. /* 
  2. DBSTR -- Dump memory as bytes for a given BSTR
  3.   DBSTR (<variable> | <address> | <range>)
  4.    >dbstr var         /* Dumps the BSTR pointed to by var      */
  5.    >dbstr 0x82034     /* Dumps the BSTR at location 0x002080d0 */
  6. Note that a BSTR is an address shifted right 2 pointing to a buffer
  7. with a preceeding length byte.
  8. */
  9. address 'COMMAND'
  10. 'version >nil: exec.library 36 '
  11. lrc = rc
  12.  
  13. if (rc = 0) then
  14.   check = addlib('rexxsupport.library',0,-30,0) 
  15.  
  16. address
  17.  
  18. parse arg expr
  19. if (expr = '?') then
  20.    do
  21.    do i = 2 to 7
  22.       'd "' strip(sourceline(i),'T', "0a"x) '"'
  23.    end
  24.    exit(0)
  25.    end
  26. options failat 3
  27. options results
  28. 'd ' expr '"%d"'
  29. stat = rc
  30. val = strip(result,'T',"0a"x)
  31. options
  32. if (stat ~= 0) then
  33.    do
  34.    'd "Error: can''t find' expr '"'
  35.    exit(0)
  36.    end
  37. val = strip(val)
  38. say val
  39. bptr = d2c(c2d(d2c(val))*4,4)
  40. bstr = import(offset(bptr,1),c2d(import(bptr,1)))
  41. do forever
  42.   y = verify(bstr, '"'||'0a0d00'x,'m')
  43.   if y = 0 then leave
  44.   c = substr(bstr,y,1)
  45.   if c = '"' then
  46.      bstr = left(bstr,y-1)||'\'||'05'x||substr(bstr,y+1)
  47.   else
  48.      bstr = left(bstr,y-1)||'\\'||translate(c,'nr0','0a0d00'x)||substr(bstr,y+1)
  49. end
  50. bstr = translate(bstr, '"', '05'x)
  51. 'd "0x'||c2x(bptr)||':  \"'||bstr||'\""'
  52. exit(0)
  53.