.; MENU.CMD
.; This command file handles the menu system for ogc/2

.; written by paul plum, 3/22/84

	.ENABLE SUBSTITUTION
	.ENABLE QUIET

.; Don't let 'em get mcr

	SET /FDX=TI:
	SET /TYPEAHEAD=TI:
	SET /ESCSEQ=TI:
.;	SET /SLAVE=TI:

.; Open the form library
.; it should be in <LOGUIC> but it could be in <UIC>
.; Figure out our UIC GROUP for UFD rotation

	.SETS UIC <LOGUIC>
	.PARSE UIC "[,]" A1 GROUP MEMBER
	.SETS FORMLB "'UIC'MENUFORMS.FLB"

	.TESTFILE 'FORMLB'
	.IF <FILERR> EQ 1 .GOTO FRMOPN

	.SETS UIC <UIC>
	.PARSE UIC "[,]" A1 GROUP MEMBER
	.SETS FORMLB "'UIC'MENUFORMS.FLB"

	.TESTFILE 'FORMLB'
	.IF <FILERR> EQ 1 .GOTO FRMOPN
	;
	; Error ****** No menu to speak of
	;
	.EXIT
.FRMOPN:
	.FORM OPN,FORMLB

.; Define a few necessary variables

	.SETN VSUCC 1.		! Successful completion of I/O
	.SETS PASWRD ""		! Hold the entered password
	.SETS FLDVAL ""		! Hold the field values from data entry
	.SETS CONTRL ""		! Control character
	.SETS B ""		! Additional arguements
	.SETS C ""
	.SETS D ""
	.SETS E ""
	.SETS TERM ""
	.SETS JUNK ""
	.SETS NEWMEM "0"
	.SETN NUM 0.
.; See if parameter was passed or first time

.RESTRT:
	.PARSE COMMAN " " A P1
	.IF P1 EQ "" .SETS P1 "MAINMU"
	.SETS MENU P1

.; Display the screen
.; Get the range string to put on line 24
.; Put the string on line 24

	.FORM CSH,MENU
	.FORM DAT,"RANGE",,RANGE
	.FORM LST,RANGE

.INPUT:

.; Prompt for the selection field from the screen

	.FORM GET,"SELECT",,,,SELECT
	.IF SELECT EQ "0" .GOTO ENDMEN

.; Use the string the entered to get a control string

	.FORM DAT,SELECT,,STR

.; <FILERR> is not 1 if not found

	.IF VSUCC NE '<FILERR>' .FORM LST,RANGE
	.IF VSUCC NE '<FILERR>' .GOTO INPUT

.; Found - Parse out the data in the string

	.SETS B ""
	.SETS C ""
	.SETS D ""
	.SETS E ""
	.PARSE STR ";;;;;;" CONTRL B C D E F

.; B=Batch command

	.IF CONTRL EQ "B" .GOTO BEGBAT

.; D=Display a new menu

	.IF CONTRL EQ "D" .GOTO NEWMEN

.; I=Execute an interactive command

	.IF CONTRL EQ "I" .GOTO INTERA

.; M=Print this message on line 24

	.IF CONTRL EQ "M" .GOTO MESSAG

.; Go again

	.GOTO INPUT

.; End of main program

.ENDMEN:

 	.IF NUM EQ 0 .FORM CSH,"CLRSCR"
	.IF NUM EQ 0 SET /NOSLAVE=TI:
	.IF NUM EQ 0 .EXIT
	.RETURN

.INTERA:

.; EXECUTE INTERACTIVE COMMAND SUBROUTINE
.; syntax:	I;<MCR command>;

.; This routine executes an interactive command
.;  'B' is some valid MCR command

.; Erase menu off of the screen

	.IF B EQ "" .GOTO ENDINT
	.FORM CSH,"CLRSCR"

.; Execute the command

	'B'
	.PARSE B " " D E
	.IF D EQ "RUN" .WAIT

.; Redisplay the current menu

	.FORM CSH,MENU
.ENDINT:
	.SETS CONTRL ""
	.GOTO INPUT
.;	.RETURN











.MESSAG:

.; DISPLAY A MESSAGE SUBROUTINE
.; syntax:	M;<string>;

.;  This routine displays the string 'B' on the screen
.;   on line 24

	.IF B NE "" .FORM LST,B
	.SETS CONTRL ""
	.GOTO INPUT
.;	.RETURN

.NEWMEN:

.; NEW MENU COMMAND SUBROUTINE
.; syntax:	D;[<password>];<menu form name>;

.; This routine suspends this menu and starts another

.; 'B' = Optional password if not a null string
.; 'C' = Menu name

	.IF B NE "" .; Request a password

.; Display the password screen

	.IF B NE "" .FORM CSH,"PASWRD"

.; Get the password from operator

	.IF B NE "" .FORM GET,"PASSWD",,,,PASWRD

.; If it don't match, tel'em

	.IF B NE "" .IF B NE PASWRD .FORM LST,"Sorry no match!"
	.IF B NE "" .IF B NE PASWRD .GOTO ENDNMN

.; If no password needed or password matched

	.IF C NE "" .; Execute the 'C' Menu

.; Save the old menu name

	.INC NUM
	.SETS MENU'NUM' MENU

.; Start up the new menu
.; bye calling ourselves again with a new menu and incremented NUM

	.IF C NE "" .GOSUB RESTRT MENU 'C'

.; Restore the old menu

	.SETS MENU MENU'NUM'
	.DEC NUM

.ENDNMN:

.; Redisplay this menu

	.FORM CSH,MENU
	.SETS CONTRL ""
	.GOTO INPUT
.;	.RETURN

.BEGBAT:

.; BATCH COMMAND SUBROUTINE
.;
.; syntax: B;[<dataentry program>;<title for screen>];<@X.CMD>;[<batch queue>];

.; Quit if there is no command
.;  depending on the state of B, the command could be in either
.;  C if there is no data entry or D if there is data entry

	.IF B NE "" .IF D EQ "" .GOTO ENDBAT
	.IF B EQ "" .IF C EQ "" .GOTO ENDBAT
	.IF B EQ "" .SETS E D
	.IF B EQ "" .SETS D C
	.IF B EQ "" .SETS C B

.; Get the next member in line 

.GTNEXM:

.; GET NEXT MEMBER NUMBER SUBROUTINE


.; Open our next member number file

	.OPENR NEXTMEMBR.SEQ

.; Read the newmember number out of the file

	.READ NEWMEM

.; Close the old file

	.CLOSE

.; Delete the file 

	PIP NEXTMEMBR.SEQ;*/DE

.; Create an new nextmember file 

	.BEGIN
		.SETN NXTMEM 0
		.OPEN NEXTMEMBR.SEQ
		.SETN NXTMEM 'NEWMEM'+1
		.IF NXTMEM GT 77 .SETN NXTMEM 2
		.DATA 'NXTMEM'
		.CLOSE
	.END
.; end-GTNEXM

.; Open the batch command file if we can
.;  this .ONERR will keep the command file going in case of error

	.ONERR OPNERR
	.OPEN ['GROUP','NEWMEM']BATCHJOB.CMD

.OPNERR:
	.IF VSUCC EQ <FILERR> .GOTO OPNOK

.; No can open file???

	.FORM LST,"Cannot open batch file '<FILERR>'"
	.GOTO BATERR
.OPNOK:

.; Put in job control cards

	.DATA $JOB/TIME:(71:59) BATCH'NEWMEM' ['GROUP'/1]
	.DATA $!Created by the Menu system

.; Set the uic to the allocated one, remember that this
.;  batch file will execute in [,1] by default! and we don't want that.

	.DATA $ SET /UIC=['GROUP','NEWMEM']

.; Execute the command in batch command file

	.DATA $'D'

.; use the form 'B' to enter data first 

	.IF B EQ "" .GOTO NOPRMT

.; execute data entry program for input
	.FORM CSH,"CLRSCR"

.;	RUN 'B' /CMD="'C'"  ! TEMPORARILY REMOVED
	SET /UIC=['GROUP','NEWMEM']
	'B' 'C'
	SET /UIC='UIC'
.;
.NOPRMT:

.; Finish up the job control cards

	.TESTFILE TI:
	.PARSE <FILSPC> ":" TERM JUNK
	.DATA $BRO 'TERM': 'C' Completed - "BATCH'NEWMEM'"
	.DATA $!
	.DATA $EOJ

.; close the batch command file

	.CLOSE

.; Position the cursor on the last line, for submit message to show

	.FORM LST," "

.; Submit the command to the batch processor

.IF E EQ "" SUB BATCH'NEWMEM'/PRIN:BATCHP=['GROUP','NEWMEM']BATCHJOB.CMD/DE
.IF E NE "" SUB 'E':BATCH'NEWMEM'/PRIN:BATCHP=['GROUP','NEWMEM']BATCHJOB.CMD/DE
.ENDBAT:

.; Redisplay the current menu

	.FORM CSH,MENU
	.FORM LST,"'C' submitted, see BATCH'NEWMEM'"
.BATERR:

	.SETS CONTRL ""
	.GOTO INPUT
.;	.RETURN


