home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netdor3.zip / DISK_12 / IMAGE11.ZIP / ADMTOOLS / QDESKTOP.CMD < prev    next >
OS/2 REXX Batch file  |  1993-08-20  |  5KB  |  154 lines

  1. /****************************************************************************
  2.  *          QDESKTOP - Determine directory of active OS/2 desktop           *
  3.  *                      Tom Bridgman (CORE at WATSON)                       *
  4.  *****************************************************************************
  5.  *                    Licensed Materials-Property of IBM                     *
  6.  *               5604-472 (c) Copyright IBM Corporation, 1993                *
  7.  *                           All rights reserved.                            *
  8.  *                  US Government Users Restricted Rights -                  *
  9.  *                 Use, duplication or disclosure restricted                 *
  10.  *                by GSA ADP Schedule Contract with IBM Corp.                *
  11.  ****************************************************************************
  12.  * Acknowledgements:                                                        *
  13.  * Code to locate the desktop directory adapted from code by Georg Haschek  *
  14.  * (61804212 at VIEVMA).                                                    *
  15.  ****************************************************************************/
  16. trace 'O'
  17. signal on syntax
  18. signal on novalue
  19. parse upper source . How Me
  20. parse upper arg Opt Extra
  21. Valid = 'SWITCH'
  22. if (Opt <> '' & wordpos(Opt, Valid) = 0) | Extra <> ''
  23.   then signal Tell
  24. call RxFuncAdd 'SYSLOADFUNCS', 'REXXUTIL', 'SYSLOADFUNCS'
  25. SynRef = 'SYSLOADFUNCS'
  26. call SysLoadFuncs
  27. drop SynRef
  28. Cmd = (How = 'COMMAND')
  29. if pos('\', Me) > 0
  30.   then do
  31.     MyPath = left(Me, max(3, lastpos('\', Me)-1))
  32.     call setlocal
  33.     call value 'PATH', MyPath';'value('PATH',,'OS2ENVIRONMENT'), 'OS2ENVIRONMENT'
  34.   end
  35. Desktop = GetPath('<WP_DESKTOP>')
  36. if Desktop = ''   /* Second attempt if first fails */
  37.   then do
  38.     SynRef = 'BOOTDRIVE'
  39.     BDr = SysBootDrive()
  40.     SynRef = 'QFOLDER'
  41.     Desktop = 'QFOLDER'('OS/2 2.0 Desktop', BDr'\')
  42.     if Desktop = ''   /* Third attempt (for 2.1 systems) if 3rd fails */
  43.       then Desktop = 'QFOLDER'('Desktop', BDr'\')
  44.     drop SynRef
  45.   end
  46. call endlocal
  47. if Cmd
  48.   then if Desktop = ''
  49.     then say 'The active OS/2 desktop directory could not be located!'
  50.     else do
  51.       say 'The active OS/2 desktop directory is "'Desktop'".'
  52.       if Opt = 'SWITCH'
  53.         then call directory Desktop
  54.     end
  55. return Desktop
  56.  
  57. GetPath: procedure 
  58. parse arg ObjId
  59. GpiNode = substr(sysIni('USER', 'PM_Workplace:Location', ObjId), 1, 2)
  60. if GetNodes() <> 0
  61.   then say 'Warning: Could not locate the node table.'
  62. GP = ''
  63. do GPI = 1 to Nodes.0
  64.   if substr(Nodes.GPI, 7, 2) = GpiNode
  65.     then do
  66.       GP = substr(Nodes.GPI, 33, length(Nodes.GPI)-33)  /* Name of desktop */
  67.       GPParent = substr(Nodes.GPI, 9, 2)
  68.       do until GPParent = '0000'x
  69.         do GPL = 1 to Nodes.0
  70.           if substr(Nodes.GPL, 7, 2) = GPParent
  71.             then do                               /* Qualified name of desktop */
  72.               GP = substr(Nodes.GPL, 33, length(Nodes.GPL)-33)'\'GP 
  73.               GPParent = substr(Nodes.GPL, 9, 2)
  74.               leave GPL
  75.             end
  76.         end
  77.       end
  78.       leave GPI
  79.     end
  80. end
  81. return GP
  82.  
  83. GetNodes: procedure expose Nodes.
  84. Handles = sysIni('SYSTEM', 'PM_Workplace:ActiveHandles', 'HandlesAppName')
  85. if abbrev(Handles, 'ERROR:')    /* No service pack */
  86.   then Handles = 'PM_Workplace:Handles'
  87. Block1 = ''
  88. parse value '0' with 1 Nodes. 1 I 1 L
  89. do I = 1 to 999
  90.   Block = sysIni('SYSTEM', Handles, 'BLOCK'I)
  91.   if abbrev(Block, 'ERROR:')
  92.     then if I = 1
  93.       then return 10  /* could not locate NODE table */
  94.       else leave
  95.     else Block1 = Block1||Block
  96. end I
  97. do until L >= length(Block1)
  98.   if substr(Block1, L+5, 4) = 'DRIV'
  99.     then do
  100.       XL = pos('00'x||'NODE'||'01'x, Block1, L+5) - L
  101.       if XL <= 0
  102.         then leave
  103.       L = L + XL
  104.       iterate
  105.     end
  106.     else if substr(Block1, L+1, 4) = 'DRIV'
  107.       then do
  108.         XL = pos('00'x||'NODE'||'01'x, Block1, L+1) - L
  109.         if XL <= 0
  110.           then leave
  111.         L = L + XL
  112.         iterate
  113.       end
  114.       else do
  115.         Data = substr(Block1, L+1, 32)
  116.         XL = c2d(substr(Block1, L+31, 1))
  117.         if XL <= 0
  118.           then leave
  119.         Data = Data||substr(Block1, L+33, XL+1)
  120.         L = L + length(Data)
  121.       end
  122.   I = I + 1
  123.   Nodes.I = Data
  124. end
  125. Nodes.0 = I
  126. return 0
  127.  
  128. Tell:
  129. say
  130. say ' QDESKTOP  [SWITCH]'
  131. say
  132. say ' Returns the name of the directory corresponding to the active'
  133. say ' OS/2 Desktop.  If "SWITCH" is specified, the desktop directory'
  134. say ' will be made active.'
  135. exit 0
  136.  
  137. Syntax:
  138. signal off novalue
  139. select
  140.   when SynRef = 'SYSLOADFUNCS'
  141.     then say 'REXXUTIL.DLL could not be initialized.'
  142.   when SynRef = 'BOOTDRIVE'
  143.     then say Me 'requires the IUO version of REXXUTIL.DLL.'
  144.   when SynRef = 'QFOLDER'
  145.     then say 'QFOLDER.CMD has to be in the PATH or the same directory as' Me'.'
  146.   otherwise
  147.     say 'Syntax error' rc '('errortext(rc)') raised in line' sigl'.'
  148. end
  149. exit 2
  150.  
  151. Novalue:
  152. say 'Novalue error ('condition('D')') raised in line' sigl'.'
  153. exit 2
  154.