home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 418.lha / ShoList.rexx < prev    next >
OS/2 REXX Batch file  |  1990-09-02  |  6KB  |  195 lines

  1. /*   ShoList.rexx -  updated for ARexx Revision 1.10 - 9-October-1989 */
  2.  
  3. /*      copyright 1989 Richard Lee Stockton and Gramma Software.      */
  4. /*    This code is freely distributable as long as this copyright     */
  5. /*   notice remains, unchanged, at the start of the code. Thank you.  */
  6.  
  7. /*  'rx ShoList ?' will show USAGE. Output may be redirected to file  */
  8. /*                  ie, 'rx ShoList >ram:ports p' writes a formatted  */
  9. /*                    textfile of the current ports to a file in ram. */
  10.  
  11.  
  12. /* If the support lib not found then quit helpfully. */
  13.  
  14. CALL ADDLIB('rexxsupport.library',0,-30,0)
  15. IF ~show('L',"rexxsupport.library") THEN
  16.   DO
  17.     SAY 'libs:rexxsupport.library is not available'
  18.     EXIT 10
  19.   END
  20.  
  21.  
  22. /* These are the USAGE strings we output if we see a '?', or a bad letter */
  23.  
  24. LF     = '0A'x
  25. USAGE1 = LF"  ARexx USAGE: rx ShoList [ACDFHILMPRSTVWX?]"LF
  26. USAGE2 = ,
  27. " A=directories  C=clip list    D=devices  F=open files     H=handlers"LF,
  28. "I=interrupts   L=libraries    M=memory   P=ports          R=resources"LF,
  29. "S=semaphores   T=ready_tasks  V=volumes  W=waiting_tasks  X=REXX tasks",
  30. LF || LF"                ShoList with no argument shows ALL"
  31.  
  32.  
  33.  
  34. /************************  Program starts here  **************************/
  35.  
  36.  
  37. /* get the argument from CLI and make it all caps. (ARG=PARSE ARG UPPER) */
  38.  
  39. ARG x
  40.  
  41.  
  42. /* if no argument, give 'em everything */
  43.  
  44. IF length(x)=0 THEN x = 'ACDFHILMPRSTVWX'
  45.  
  46.  
  47. /* if '?', output USAGE stuff and die */
  48.  
  49. IF (x=='?') THEN DO
  50.                     SAY USAGE1
  51.                     SAY USAGE2
  52.                     EXIT 5
  53.                  END
  54.  
  55.  
  56. /* Take each letter in the argument, one at a time */
  57.  
  58. DO i=1 TO length(x)
  59.    y=substr(x,i,1)
  60.  
  61.  
  62. /* Select an appropriate title for this letter */
  63.  
  64.    SELECT
  65.        WHEN y='A' THEN title = 'Assigned Directories [DOS list]'
  66.        WHEN y='C' THEN title = 'Clips [AREXX list]'
  67.        WHEN y='D' THEN title = 'Device Drivers'
  68.        WHEN y='F' THEN title = 'Open Files [local]'
  69.        WHEN y='H' THEN title = 'Handlers [DOS list]'
  70.        WHEN y='I' THEN title = 'Interrupts'
  71.        WHEN y='L' THEN title = 'Libraries'
  72.        WHEN y='M' THEN title = 'MemoryList Items'
  73.        WHEN y='P' THEN title = 'Ports'
  74.        WHEN y='R' THEN title = 'Resources'
  75.        WHEN y='S' THEN title = 'Semaphores'
  76.        WHEN y='T' THEN title = 'Ready Tasks'
  77.        WHEN y='V' THEN title = 'Volumes [DOS list]'
  78.        WHEN y='W' THEN title = 'Waiting Tasks'
  79.        WHEN y='X' THEN title = 'REXX Tasks'
  80.        OTHERWISE
  81.          DO          /* Bad Letter in argument. Complain and die */
  82.            SAY
  83.            SAY '  Usage Error!'  USAGE1 ' --->' y '?'
  84.            SAY USAGE2
  85.            EXIT 10
  86.          END
  87.    END
  88.  
  89.  
  90. /* ARexx scans system lists. This is where the good stuff gets done. */
  91.  
  92.    IF y='X' THEN CALL AStatus()
  93.    ELSE IF((y='C')|(y='F')) THEN list = show(y,,';')
  94.                             ELSE list = showlist(y,,';')
  95.  
  96.  
  97. /* everything below is just formatting and printing the list to the CLI */
  98. /* based on the longest name in the list, and the number of list items. */
  99.  
  100.    listlength=length(list)    /* length in characters of the whole list */
  101.    longest=0
  102.    j=1
  103.    items=0
  104.    position=1
  105.  
  106.    DO WHILE(position>0)      /* how many total and how long is longest? */
  107.        position=pos(';',list,j) /* <-- returns 0 when the list runs out */
  108.        IF((position-j)>longest) THEN longest=position-j
  109.        IF(position>0) THEN j=position+1
  110.        items=items+1
  111.    END
  112.    IF((listlength+1-j)>longest) THEN longest=listlength+1-j /* last item */
  113.  
  114.    columns = 77%(longest+2)           /* we assume an 80 column display */
  115.    position=1
  116.    count=0
  117.    j=1
  118.    line = ""
  119.    IF(listlength==0) THEN items=0
  120.    SAY '      -*-*-*-' items title  '-*-*-*-'
  121.    IF(listlength==0) THEN ITERATE         /* no list, go to next letter */
  122.    DO WHILE(position>0)
  123.        position=pos(';',list,j)
  124.        IF(position>0) THEN
  125.          DO
  126.            nextItem = ""
  127.            nextItem = left(substr(list,j,position-j),longest)
  128.            IF LENGTH(STRIP(nextItem))==0 THEN
  129.              nextItem = left("<blank>",longest)
  130.            line = line || nextItem || '  '
  131.            j = position + 1
  132.          END
  133.        ELSE line = line || left(substr(list,j),longest)
  134.        count = count + 1
  135.        IF(count=columns) THEN
  136.          DO
  137.            SAY line
  138.            count=0
  139.            line=""
  140.          END
  141.    END
  142.    IF(count>0) THEN SAY line        /* Only print when the line is full */
  143. END
  144. EXIT
  145.  
  146. /* AStatus.rexx   ARexx task list display   by BaudMan */
  147.  
  148. AStatus:
  149. RxsBase = findlib("rexxsyslib.library")
  150. Call RxsOffsets()
  151. TaskList = import(offset(RxsBase,RxsBase.rl_TaskList),4)
  152. n=1
  153. list=""
  154. do j=1 TO 999 WHILE( import(TaskList,4) ~= NULL())
  155.     name=Import(Import(Offset(TaskList,56),4)) 
  156.     if name='' then do
  157.         name='String_'n
  158.         n=n+1
  159.     end
  160.     IF j=1 THEN list=name
  161.     ELSE list=list';'name
  162.     TaskList = import(TaskList,4)
  163. END
  164. RETURN;
  165.  
  166.  
  167. /* Find a given library in the system - copied from Status.rexx */
  168. findlib:
  169.     parse arg tofind
  170.     execbase = import('00000004'x,4)
  171.     nodebase = import(offset(execbase, 378), 4)
  172.  
  173.     do while(import(nodebase,4) ~== NULL())
  174.         if import(import(offset(nodebase,10),4)) == tofind then
  175.             return nodebase
  176.         nodebase = import(nodebase,4)
  177.     end
  178.  
  179.     say 'Could not find' tofind
  180.     exit(20)
  181.  
  182.  
  183. RxsOffsets:
  184. RxsBase.rl_TaskList =168/* List     */
  185. RxsBase.rl_NumTask  =182    /* WORD     */
  186. RxsBase.rl_LibList  =184    /* List     */
  187. RxsBase.rl_NumLib   =198    /* WORD     */
  188. RxsBase.rl_ClipList =200    /* List     */
  189. RxsBase.rl_NumClip  =214    /* WORD     */
  190. RxsBase.rl_MsgList  =216    /* List     */
  191. RxsBase.rl_NumMsg   =230    /* WORD     */
  192. RETURN;
  193.  
  194. /* end of ShoList.rexx   |   28 August 1990 */
  195.