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

  1. /* 
  2. Usage: Whichis [ <command> | 0xnnnnnn | n] 
  3. Version 1.00  02-Nov-88
  4.  
  5. Identifies the CLI process associated with a given command, task number
  6. or task address
  7. */
  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 name '0x' tsk .
  19. NULL = "00000000"x
  20.  
  21. if (name = '?') then
  22.    do
  23.    do i = 2 to 6
  24.       'd "'||strip(sourceline(i),'T',"0a"x) '"'
  25.    end
  26.    exit(0)
  27.    end
  28. else if (name ~= '') then
  29.    do
  30.    if datatype(name, 'W') then
  31.       do
  32.       clinum = name
  33.       name = 'Process' name
  34.       end
  35.    else
  36.       cliname = name
  37.    end
  38. else if (tsk ~= '') then
  39.    do
  40.    name = right(tsk,8,'0')
  41.    taskbase = x2c(name)
  42.    name = '0x'||name
  43.    end
  44. else
  45.    do
  46.    'd "No task given to locate"'
  47.    exit(0)
  48.    end
  49.  
  50.  
  51. /* Show all CLI tasks */
  52. dosbase   = findlib("dos.library")
  53. rootnode  = import(offset(dosbase,34),4)
  54. tasktable = d2c(c2d(import(rootnode,4))*4,4)
  55. taskcount = c2d(import(tasktable,4))
  56. do tasknum = 1 to taskcount
  57.    proc = import(offset(tasktable,tasknum*4),4)
  58.    if (proc ~= NULL) then
  59.       do
  60.       proc = offset(proc,-92)
  61.       cli = d2c(c2d(import(offset(proc,172),4))*4,4)
  62.       command = 'No command loaded'
  63.       args = ''
  64.       module = ''
  65.       if (cli ~= NULL) then
  66.          do
  67.          cmdname = d2c(c2d(import(offset(cli,16),4))*4,4)
  68.          cmdlen = c2d(import(cmdname, 1))
  69.          module = import(offset(cmdname,1), cmdlen)
  70.          if cmdlen ~= 0 then
  71.             do
  72.             command = 'Command:' import(offset(cmdname,1), cmdlen)
  73.             cis = d2c(c2d(import(offset(cli,32),4))*4,4)
  74.             cptr = d2c(c2d(import(offset(cis,12),4))*4,4)
  75.             args = import(cptr,80)
  76.             args = translate(args,"'"||'0a0a'x,'"'||'0d00'x)
  77.             y = pos('0a'x, args)
  78.             if (y ~= 0) then args = left(args,y-1)
  79.             end
  80.          end
  81.       if (proc = taskbase | module = cliname | tasknum = clinum) then
  82.          do
  83.          'd "Process' tasknum||': 0x'||c2x(proc) command args'"'
  84.          exit(0)
  85.          end
  86.       end
  87. end
  88. 'd "Unable to find' name '"'
  89. exit(0)
  90.  
  91. /* Find a given library in the system */
  92. findlib:
  93. parse arg tofind
  94. execbase = next("00000004"x)
  95. liboff   = 378
  96. nodebase = import(offset(execbase, liboff), 4)
  97.  
  98. do while(import(nodebase,4) ~= NULL)
  99.    namestr = import(import(offset(nodebase,10),4))
  100.    if namestr = tofind then return nodebase
  101.    nodebase = import(nodebase,4)
  102. end
  103.  
  104. 'd "Could not find' tofind||'"'
  105. exit(0)
  106.