!FOURWAY - set up 4-way application program interface
*Use this program in conjunction with a collector window
*and an application program. Collector window must expect
*@PSEUDO, on input, to contain option characters in field 1
*and other arguments from the TCL command line, in order, in
*succeeding fields. Application program must expect the
*same format in @RECORD. Command line options are considered
*to be all characters between the last left parenthesis and
*the next right parenthesis or end of line. Note that AREV
*will process options P,D,B automatically (see RUN command
*in Technical Reference). A hyphen (-) command option will
*be stripped out and cause the window to be bypassed
*completely in favor of direct execution of the
*application program. Any select list active when FOURWAY is
*executed will still be available to the application
*program. FOURWAY must be cataloged under the
*name of the collector window. The application program must
*be cataloged under a different name. Certain collector
*parameters in the window must be set as follows:
*Setup Type:   1
*Save Type:    1
*Save Code:    S
*Save Command: catalog name of the application program
*Exit Type:    1, if window should return at program end

*TCL example: APP ARG1 ARG2 ARG3 (V-)
*APP is name of collector window
*Each ARGn will be passed to window as @PSEUDO<n+1>
*V is application program option, passed as @PSEUDO<1>
*Hyphen option means bypass collector window

DECLARE SUBROUTINE MSG,WINDOW
*Preserve any active select list for application program
IF @LIST.ACTIVE THEN @SAVE.SELECT=1
@PSEUDO=@SENTENCE;*@PSEUDO will be passed to window
OPTIONS=@PSEUDO[-1,'B('];*extract option characters
IDX=COL1()
OPTIONS=OPTIONS[1,')']
@PSEUDO[IDX,LEN(OPTIONS)+2]='';*strip options from @PSEUDO
GOFLG=INDEX(OPTIONS,'-',1);*true means bypass window
CONVERT '-' TO '' IN OPTIONS;*strip bypass flag
@PSEUDO=TRIM(@PSEUDO)
CONVERT ' ' TO @FM IN @PSEUDO
WINDOWNAME=@PSEUDO<1>;*extract collector window name
@PSEUDO<1>=OPTIONS;*Put options at beginning of @PSEUDO
IF GOFLG THEN
*If window is to be bypassed
 OPEN 'TEMPLATES' TO FILE THEN
  READ @RECORD FROM FILE,WINDOWNAME THEN
   *Extract program name from window parameter record
   PROGNAME=FIELD(@RECORD,\F7\,13)<5>
   *load @RECORD from @PSEUDO since window won't do it
   @RECORD=@PSEUDO
   *run application program
   CHAIN PROGNAME
  END ELSE MSG("Can't read %1% in TEMPLATES 
table",'','',WINDOWNAME)
 END ELSE MSG("Can't open TEMPLATES table",'','','')
END ELSE
*If collector window is to run
 @SENTENCE='. ':WINDOWNAME;*tells WINDOW name of window
 WINDOW();*run collector window, which calls program at end
END
