home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / pmsw.zip / PMSW / PMSWALL.ZIP / OS2 / BOOK / PMSW.INF (.txt) < prev   
OS/2 Help File  |  1994-08-10  |  13KB  |  344 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Function and Command Line Syntax ΓòÉΓòÉΓòÉ
  3.  
  4. Version 2, August 1994 
  5. This version has the ability to "switch focus to self", meaning that it can 
  6. switch focus to that session that is invoking it.  This is useful when running 
  7. REXX programs in several sessions such as with the author's RXMP package 
  8. (RXMSGBOX pop-up message), and focus will be switched more than once.  Using a 
  9. single asterisk as the operand to PMSW or PMSW2 is a request to switch to self. 
  10.  
  11. The PMSW application is presented in two forms: 
  12.  
  13. o PMSW.EXE 
  14.  
  15. o PMSW2.DLL 
  16.  
  17. PMSW* is invoked with two arguments: 
  18.  
  19.  1. Name mask of task in switch list 
  20.  
  21.  2. Optional "/r" switch to suppress actual focus change 
  22.  
  23. If the string passed as the first argument matches a name in the WorkPlace 
  24. Shell "Switch List" that is made the focus with the Ctrl+Esc keys, then that 
  25. task is given the focus with a call to WinSwitchToProgram.  The name mask may 
  26. contain - usually does contain - wild card characters.  These characters are 
  27. the asterisk and question mark, and they have their usual DOS command line 
  28. meanings. 
  29.  
  30. o * wild card matches zero or more characters 
  31.  
  32. o ? wild card matches exactly one character 
  33.  
  34. Version 2:  if the first operand is an asterisk, then the second operand is 
  35. ignored, and focus will switch to this session that invoked PMSW.  Return codes 
  36. with this request are only:  0/FOCUS: or 2/ERROR: and no test return without 
  37. focus switch can be done. 
  38.  
  39. Mask=*ABC*
  40. This mask matches a name containing the letters ABC. 
  41.  
  42. Mask=*A*B*C*
  43. This mask matches a name containing the letters A, B, C, but not necessarily 
  44. next to each other. 
  45.  
  46.  
  47. ΓòÉΓòÉΓòÉ 2. Sample Application ΓòÉΓòÉΓòÉ
  48.  
  49. The PMSW application is used in OS/2 .CMD files that are batch command files or 
  50. REXX programs.  The .CMD file can invoke PMSW to test if a named task is 
  51. already active and to switch focus to that task, or it can launch a task and 
  52. change focus to that task once that task is available.  The REXX can contain 
  53. logic such that, if the target DOS application is already active when the REXX 
  54. begins, the DOS application receives the focus instead of the REXX starting 
  55. another DOS application window.  This is important to PC LAN administrators who 
  56. want to place central applications on the LAN but who need to provide OS/2 
  57. users with the tools to automatically acquire LAN connection to the 
  58. application, tailoring the DOS startup parameters for the target application so 
  59. that its environment, PATH, etc. are properly initialized. 
  60.  
  61. At a customer site, the CCMAIL application resides on the LAN.  A MAIL program 
  62. folder can be defined on the desktop that invokes the MAIL.CMD REXX program. 
  63. This program tests to see if the target CCMAIL application is now active, and 
  64. switches focus to it if so.  If the CCMAIL application is not active, then 
  65. MAIL.CMD REXX checks to see if the user is now logged onto the LAN (a LOGON 
  66. command has been done), and if the CCMAIL LAN drive has been connected before 
  67. issuing a START command for CCMAIL and switching focus to it. 
  68.  
  69.  
  70. ΓòÉΓòÉΓòÉ 2.1. Sample MAIL.CMD for PMSW Program Call ΓòÉΓòÉΓòÉ
  71.  
  72. /* REXX MAIL.CMD Uses PMSW.EXE program calls */
  73. 'SETLOCAL'
  74. 'C:'
  75. 'CD \CCMAIL'
  76. if 0 < RxFuncQuery('SysLoadFuncs') then
  77.    do
  78.       Call rxfuncadd 'SysLoadFuncs','REXXUTIL','SysLoadFuncs'
  79.       Call SysLoadFuncs
  80.    end
  81. CCMAIL='CCMAIL';
  82. FirstName=""; LastName=""; ProcOpts=""; UserPassWord="";
  83. parse upper arg FirstName LastName UserPassWord;
  84. CCMAILServer='ccmail';
  85. MDRIVE.0=0;
  86. RC.0='FOCUS:'; RC.1='READY:'; RC.2='ERROR:';
  87. irc=SysFileTree('M:\CCMAIL\MAIL.*','MDRIVE','FSO');
  88. if MDRIVE.0<1 then
  89.    do
  90.       '@NET USE M: ' CCMAILServer;
  91.       RRC=RC;
  92.    end
  93. else RRC=0
  94.  
  95. IF RRC=0 then
  96.    do
  97.    bREADY=0;
  98.    'PMSW' ccmail '/R';
  99.    Result=RC.RC
  100.    if Result\='READY:' then
  101.       'START "CCMAIL" /C /MIN /WIN c:\CCMAIL\CCMAIL.BAT' FirstName LastName UserPassword;
  102.    else
  103.       do
  104.          'PMSW' ccmail; Result=RC.RC;
  105.          if Result='FOCUS:' then bREADY=1;
  106.       end;
  107.    do while (bREADY<1);
  108.       'PMSW' ccmail '/R'
  109.       Result=RC.RC;
  110.       if Result='READY:' then
  111.          do
  112.             'PMSW' ccmail
  113.             Result=RC.RC;
  114.             if Result='FOCUS:' then
  115.                bREADY=1;
  116.          end;
  117.       else Call SysSleep(2);
  118.    end;
  119. END;
  120. else
  121.    do
  122.       if RRC=2 then
  123.          'net use m: /d';
  124.       say "UNABLE TO ACCESS CCMAIL"
  125.    end;
  126. byby:;
  127. '@EXIT';
  128.  
  129.  
  130. ΓòÉΓòÉΓòÉ 2.2. Sample MAIL.CMD for PMSW2 REXX Function ΓòÉΓòÉΓòÉ
  131.  
  132. /* REXX MAIL.CMD */
  133. 'SETLOCAL'
  134. 'C:'
  135. 'CD \CCMAIL'
  136. if 0 < RxFuncQuery('SysLoadFuncs') THEN DO;
  137.    Call rxfuncadd 'SysLoadFuncs','REXXUTIL','SysLoadFuncs';
  138.    Call SysLoadFuncs;
  139. END;
  140. CCMAIL='CCMAIL';
  141. RC=RXFUNCADD('PMSW2','PMSW2','PMSW2');
  142. FirstName=""; LastName=""; ProcOpts=""; UserPassWord="";
  143. parse upper arg FirstName LastName UserPassWord;
  144. CCMAILServer='ccmail';
  145. MDRIVE.0=0;
  146. irc=SysFileTree('M:\CCMAIL\MAIL.*','MDRIVE','FSO');
  147. if MDRIVE.0<1 then do;
  148.    '@NET USE M: ' CCMAILServer;
  149.    RRC=RC;
  150. end;
  151. else do;
  152.   RRC=0;
  153. end;
  154. IF RRC=0 THEN DO; bREADY=0;
  155.    Result=PMSW2(ccmail,'/r');
  156.    if Result\='READY:' then do;
  157.       'START "CCMAIL" /C /MIN /WIN c:\CCMAIL\CCMAIL.BAT' FirstName LastName UserPassword;
  158.    end;
  159.    else do;
  160.       Result=PMSW2(ccmail); if Result='FOCUS:' then bREADY=1;
  161.    end;
  162.    do while (bREADY<1);
  163.       Result=PMSW2(ccmail,'/r');
  164.       if Result='READY:' then do;
  165.          Result=PMSW2(ccmail);
  166.          if Result='FOCUS:' then do;
  167.             bREADY=1;
  168.          end;
  169.       end;
  170.       else Call SysSleep(2);
  171.    end;
  172. END;
  173. else do;
  174.    if RRC=2 then do;
  175.       'net use m: /d';
  176.    end;
  177.    say "UNABLE TO ACCESS CCMAIL"
  178. end;
  179. byby:;
  180. RC=RXFUNCDROP('PMSW2');
  181. '@EXIT';
  182.  
  183.  
  184. ΓòÉΓòÉΓòÉ 2.3. Sample CCMAIL.BAT DOS Batch File ΓòÉΓòÉΓòÉ
  185.  
  186. @ECHO OFF
  187. C:
  188. CD \CCMAIL
  189. CD M:\CCMAIL
  190. SET CCCONFIG=C:\CCMAIL\CCMAIL.INI
  191. SET PATH=M:\CCMAIL;%PATH%
  192. SET TEMP=C:\
  193. SET WP=/D-C:\WP51/PF-C:\WP51/M-VIEW
  194. IF X==X%1 GOTO NONAME
  195. IF X==X%3 GOTO NOPASS
  196. M:MAIL /N"%1 %2" /P"%3"
  197. GOTO EXIT
  198. :NOPASS
  199. M:MAIL /N"%1 %2"
  200. GOTO EXIT
  201. :NONAME
  202. M:MAIL
  203. :EXIT
  204. EXIT
  205.  
  206.  
  207. ΓòÉΓòÉΓòÉ 3. Technical Details ΓòÉΓòÉΓòÉ
  208.  
  209. Processing outline: 
  210.  
  211.  1. PMSW2 is defined as a Rexx function handler .DLL, and PMSW as an OS/2 .EXE 
  212.     program 
  213.  
  214.  2. PMSW/PMSW2 examines the input parameters to see if there is a task name and 
  215.     optional /r flag. 
  216.  
  217.  3. It requests a count of items in the switch list using WinQuerySwitchList. 
  218.  
  219.  4. It allocates memory to hold the full switch list array. 
  220.  
  221.  5. It requests return of items in the switch list using WinQuerySwitchList. 
  222.  
  223.  6. It scans the entries in the switch list array and matches the name mask 
  224.     given against each item. 
  225.  
  226.  7. The MSKCHK function supports use of multiple "*" and "?" wild cards with 
  227.     the usual meanings 
  228.  
  229.  8. On finding a name match, if the /r switch was used, the REXX return string 
  230.     value is set to READY:, else the REXX return string value is set to FOCUS:. 
  231.     PMSW returns values 1 and 0 instead. 
  232.  
  233.  9. If FOCUS:, then call WinSwitchToProgram using the switch list entry handle 
  234.     in the SWCNTRL structure of the matching switch list entry. 
  235.  
  236. 10. RETURN from PMSW2 to the REXX program that invoked it, or return from 
  237.     PMSW.EXE to the .CMD file or other caller. 
  238.  
  239. Note that return is immediate, regardless of change in focus.  The calling .CMD 
  240. continues execution while the user sees the focus change to the target task. To 
  241. the person at the keyboard, it appears as though the .CMD window, if visible, 
  242. has been replaced by the target application window, which now has the keyboard 
  243. focus. 
  244.  
  245.  
  246. ΓòÉΓòÉΓòÉ 3.1. MSKCHK Function ΓòÉΓòÉΓòÉ
  247.  
  248. This function is a handy piece of code developed from the author's IBM 370 
  249. assembler code (that form of the code is available on Compuserve in the 
  250. consultants' forum).  The function can match a mask string which contains 
  251. multiple wild cards equivalent to "*" and "?" (the wild card characters can be 
  252. specified, to avoid problems with strings that contain "*" and "?"). 
  253.  
  254. The arguments passed to MSKCHK are: 
  255.  
  256. o Ptr to mask string 
  257.  
  258. o Length of mask string (hold-over from non-ASCIIZ assembler, and also supports 
  259.   mask containing nulls, by the way) 
  260.  
  261. o Ptr to area to scan 
  262.  
  263. o Length of area to scan 
  264.  
  265. o Ptr to "?" substitute character 
  266.  
  267. o Ptr to "*" substitute character 
  268.  
  269. The code now skips leading and trailing blanks in the area to scan, but a block 
  270. of code could be selectively suppressed to permit using leading and trailing 
  271. blanks in both mask string and in area to scan, if appropriate.  The code could 
  272. also accept another substitute character that would be the character to remove 
  273. if leading or trailing in the area to scan, with the default stripped character 
  274. being the blank. 
  275.  
  276. To ignore case in letters scanned, it's best to translate both mask and area to 
  277. the same case prior to calling MSKCHK, as this is more efficient than 
  278. translating characters as the scan proceeds, unless you choose to use in-line 
  279. macro expansion code to do the single character translation.  Without altering 
  280. the code in MSKCHK, you could still support case-insensitive national language 
  281. support (NLS) translation by doing a translation prior to invoking MSKCHK. It 
  282. is usually not sufficient to add a constant to a character value to translate 
  283. from lower to upper or the reverse, when NLS translation must be done. 
  284.  
  285. The use of multiple wild card characters in MSKCHK means that it provides 
  286. powerful pattern recognition function.  An appropriate mask can detect the 
  287. presence of two or more "floating" substrings within scanned data. The mask 
  288. value of "*ABC*DEF*" will detect if an area contains both of the 3-letter 
  289. strings and "ABC" precedes "DEF". 
  290.  
  291. A mask string can be longer than the area scanned, as long as the total length 
  292. of constant characters and "?" characters is less than or equal to the length 
  293. of the area to scan. 
  294.  
  295. MSKCHK returns 0 for match and 8 for non-match. 
  296.  
  297.  
  298. ΓòÉΓòÉΓòÉ 4. Author & Legal Stuff ΓòÉΓòÉΓòÉ
  299.  
  300.  
  301. ΓòÉΓòÉΓòÉ 4.1. Copyright ΓòÉΓòÉΓòÉ
  302.  
  303. Copyright (C) 1993,1994 by Bruce E. H╨ñgman. All Rights Reserved. 
  304.  
  305. License to use: 
  306.  
  307. PMSW and PMSW2 may be used by any person, corporation, or government agency 
  308. without cost.  PMSW and PMSW2 may be distributed by any computer bulletin board 
  309. service (BBS), including but not limited to Compuserve, BIX, and Prodigy, 
  310. provided that no fees are charged for this distribution other than usual and 
  311. customary line or session connect charges, or charges usual and customary for 
  312. shipping and handling of magnetic media and documentation. 
  313.  
  314. Specific permission is granted International Business Machines Corporation 
  315. (IBM) to distribute this software, including C and REXX source programs as 
  316. sample programs in any IBM product. 
  317.  
  318.  
  319. ΓòÉΓòÉΓòÉ 4.2. Author ΓòÉΓòÉΓòÉ
  320.  
  321. PMSW and PMSW2 were developed originally for the US Dept of Energy, Energy 
  322. Information Administration (EIA), Washington DC by Bruce E. H╨ñgman of 
  323. Electronic Data Systems Corporation (EDS).  The author can be reached via 
  324. Compuserve 72050,1327 or at the mailing address: 1338 Avocado Isle, Fort 
  325. Lauderdale FL 33315-1344. 
  326.  
  327. The author was an instructor in computer sciences while on active duty with the 
  328. Air Force during the Vietnam years, and has been programming since 1965 on 
  329. every type of weird iron, stranger operating systems, and most popular and 
  330. arcane programming languages.  He's proudest of having taught US Marines at 
  331. Quantico Virginia. 
  332.  
  333.  
  334. ΓòÉΓòÉΓòÉ 4.3. Warranty ΓòÉΓòÉΓòÉ
  335.  
  336. This software is provided without warranty as a public service by the author. 
  337. Neither the author, nor the federal government or EDS Corporation makes any 
  338. guarantee as to the usefulness of this software or its correct operation. 
  339.  
  340.  
  341. ΓòÉΓòÉΓòÉ <hidden>  ΓòÉΓòÉΓòÉ
  342.  
  343. The "*" means zero or more characters in this position, and "?" means exactly 
  344. one character in this