.; File:  [11,45]BUILDEXT.CMD    Last Edit: 17-NOV-1987 09:56:45 
.;
.; HISTORY:  CREATED  21-SEP-82  PHIL HANNAY
.;           MOVED TO LB:[11,44] FROM LB:[22,10]  11-JAN-83  PHIL HANNAY
.;           Revised to use Pascal 2.1  19-Oct-83  Phil Hannay
.;           Changed to use P3EXT task in LB:[22,310] rather than [11,44]
.;               5-Feb-87.  Philip Hannay.
.;           Modified to delete TRANEXT.DAT;* file(s) used by P3EXT on 
.;               exit, and ignore lines beginning with "&" character
.;               (used by PRINTSRC.CMD).
.;
.;
.;  COMMAND FILE WILL RUN UNDER MCR OR DCL CLI
.;
.;
.; GENERIC EXTERNAL (INCLUDE FILE) BUILD PROCEDURE
.;
.ENABLE SUBSTITUTION
.DISABLE QUIET
.SETF BADEND
.SETF DOLST
.SETS SPDEV1 ""
.SETS SPDEV ""
.SETS LSW ""
.SETS LDEV ""
.SETS ESW ""
.SETS ETI ""
.SETS DUM1 ""
.SETS DUM2 ""
.SETS EXTDEV ""
.SETS HDNAME ""
.SETF REMOTE
.SETF NOINPT
.SETF ERRX
.SETF ERRC
.SETF ERRP
.SETS ANUM "0123456789"
.SETN ERRNUM 0
.SETN ERRMAX 1
.;
.TEST P1
.IF <STRLEN> EQ 0 .GOTO NOREM
.SETS MODNAM P1
.; Invoked with parameters, may be remote, or suppressed input mode
.;
.; Determine listing option 'P2'
.SETS TST "L"
.IF P2 EQ TST .SETT DOLST
.;
.; Determine listing device 'P3'
.SETS TST "T"
.SETS TST1 P3[1:1]
.IF TST1 EQ TST .SETS SPDEV P3+"="
.;
.; Determine the error option 'P4'
.SETS TST "X"
.SETS TST1 P4[1:1]
.IF TST1 NE TST .GOTO 1
.SETT ERRX
.TEST P4
.IF <STRLEN> LT 2 .GOTO 1
.IF <STRLEN> GT 3 .GOTO 1
.IF <STRLEN> EQ 3 .GOTO TWODGT
.;
.SETS TST1 P4[2:2]
.GOSUB NUMOUT
.IF COUNT NE 0 .DEC COUNT
.SETN ERRMAX COUNT
.IF ERRMAX LT 1 .SETN ERRMAX 1
.GOTO 1
.;
.TWODGT:
.SETS TST1 P4[2:2]
.GOSUB NUMOUT
.IF COUNT NE 0 .DEC COUNT
.SETN TCOUNT COUNT
.SETS TST1 P4[3:3]
.GOSUB NUMOUT
.IF COUNT NE 0 .DEC COUNT
.SETN ERRMAX TCOUNT*10.+COUNT
.IF ERRMAX LT 1 .SETN ERRMAX 1
.GOTO 1
.;
.;
.; SUBROUTINE NUMOUT:
.;
.NUMOUT:
.SETN COUNT 1
.LPNEXT:
.IF TST1 EQ ANUM[COUNT:COUNT] .RETURN
.INC COUNT
.IF COUNT LT 11 .GOTO LPNEXT
.SETN COUNT 0
.RETURN
.;
.; END SUBROUTINE
.;
.;
.1:
.SETS TST "C"
.IF P4 EQ TST .SETT ERRC
.SETS TST "P"
.IF P4 EQ TST .SETT ERRP
.IFF ERRC .IFF ERRP .SETT ERRX
.;
.; Determine effective TI: 'P5'
.TEST P5
.IF <STRLEN> NE 0 .GOTO SETRMT
.; just mod name supplied, not remote but suppressed input mode
.SETT NOINPT
.GOTO NOREM
.;
.SETRMT:
.SETT REMOTE
.ENABLE QUIET
.SETS ETI P5
.SETS TST "T"
.SETS TST1 ETI[1:1]
.IF TST NE TST1 .EXIT
.;We must have an EDI to work with.
.; now skip the interactive questions....
.GOTO START:
.;
.;
.NOREM:
;
; Externals build begun '<DATE>' at '<TIME>'
;
;
.IFT NOINPT .GOTO START
;
; Command file to extract external headers from specified modules, and
; place them into a specified device and ufd.  Listings are optionally
; generated and, if generated, deleted after printing.  This command file
; uses the same .MOD file used to build a library.  If there is not library,
; a .MOD file is created just the same for this routine to handle.
;
; SUPPRESSED INPUT MODE exists -- description is in .CMD file
; REMOTE MODE exists -- description is listed in .CMD file
;
.; SUPPRESSED INPUT MODE:
.; This file may be called from another command file or buffer stuffer
.; using the parameters to initialize certain variables.  This will
.; eliminate the need to query the operator for this information.
.; This is useful when this command file is called by another command
.; file that will be take two hours doing other work before getting
.; around to calling this one.  Thus the operator can take a nap and
.; not have to wait around to answer the questions the variables 
.; need initialization.
.;
.; REMOTE MODE:
.; This file may be run from a different terminal, if you have 
.; access to a buffer stuffer. When this is done, the command
.; file does no interaction with its TI: (which you can't readily
.; get at). Instead, BRO is used to notify the specified terminal
.; of errors and completion. 
.;
.; For either mode, use the following command line.  Leave out <eti>
.; for SUPPRESSED INPUT mode, and specify <eti> for REMOTE mode.
.; The <modfil> parameter must be specified, while the others are
.; optional, and default values will be used.  Note that there can be
.; no ommissions between specified parameters, even if the default is
.; desired for that parameter in between.  Ommissions can only occur
.; when no further specified parameters follow.
.;
.; Invoke with commandline @BUILDEXT <modfil> <lsw> <ldev> <esw> <eti>.
.;
.; <modfil> = dev:[uic]library  (p1) 
.;    This is the .MOD (text) file name.  The device, uic and name of the file
.;    is specified (normal file spec defaults apply).  Do not specify the
.;    extention or version.  This command file will append the .MOD extention
.;    and the latest version will be used.  The .MOD file will contain the name
.;    of the library, into which insertion will occur, in the first line.
.;    The library extention or version should not be specified, only
.;    device, uic, and name, with normal file spec defaults valid.
.;    The second line and onward will contain the names of the source
.;    modules to be compiled (assembled) and inserted into the library.
.;    The extention MUST be specifed.  Normal file spec defaults apply.
.;
.; <lsw> = listing control switch   (p2)
.;	L = generate normal 132-column listings
.;	X = generate no listings (default)
.;
.; <ldev> = spooler device   (p3)
.;	TTx: = PRI TTx:=file...
.;	X = print to default spool device   PRI file...   (default)
.;	any other letter = print to default spool device
.;
.; <esw> = error control switch   (p4)
.;	Xn = terminate after n errors  (default and n=1)  Specify n
.;            as a 1 or 2 digit number (thus 1 thru 99) with no
.;            space between it and the letter X.  Execution will
.;            continue until n errors have occurred.  If n is not
.;            specified, or a non-numeric string used, n will
.;            default to 1.
.;            
.;	C = continue on errors
.;	any other letter = notify and pause (type UNS ...at. or
.;	       UNS ATTxx at YOUR terminal to resume).
.;
.; <eti> = effective ti   (p5 - remote mode only) (no default as that
.;          would mean suppress input mode and not remote mode)
.;	TTx: = this required switch specifies the tt: to receive 
.;	       nofitication of errors and completion.
.;
.; Interactive mode configuration questions
;
.ASKS MODNAM Enter name of MOD file (1 to 9 char)
.ASK DOLST Generate and spool listings
.IFT DOLST .ASKS SPDEV1 Spooling device (as TTxx: or <CR>)
.IF <STRLEN> NE 0 .SETS SPDEV SPDEV1+"="
;
;
.START:
.; Common configuration completion.
.; if REMOTE, tell him we got this far
.IFT REMOTE BRO 'ETI' @BUILDLBR for 'MODNAM' begun at '<DATE>' '<TIME>'.
.; Open the module filespec list.
.TESTFILE 'MODNAM'.MOD
.IF <FILERR> EQ 1 .GOTO 8
.IFF REMOTE ; File 'MODNAM'.MOD could not be opened. 
.IFT REMOTE BRO 'ETI' File 'MODNAM'.MOD could not be opened. 
.SETT BADEND
.GOTO SHUTUP
.8:
.OPENR #3 'MODNAM'.MOD
.7:
.READ #3 LIBNAM
.IFT <EOF> .SETT BADEND
.IFT <EOF> .GOTO FINISH
.TEST LIBNAM
.IF <STRLEN> EQ 0 .GOTO 7
.SETS SIGN LIBNAM[1:1]
.IF SIGN EQ ";" .GOTO 7
.IF SIGN EQ "&" .GOTO 7
.IF SIGN EQ " " .GOTO 7
.;
.; Open a log file
PIP 'MODNAM'.XLG;*/DE/NM
.OPEN #1 'MODNAM'.XLG
.DATA #1        
.DATA #1   
.DATA #1 'LIBNAM' external headers rebuild begun '<DATE>' at '<TIME>'.
.DATA #1 The following modules (and extractions) were handled:
.DATA #1        
.;
.; Get next filespec.
.10: 
.READ #3 FSPEC
.IFT <EOF> .GOTO FINISH
.11:
.TEST FSPEC
.IF <STRLEN> EQ 0 .GOTO 10
.SETS SIGN FSPEC[1:1]
.IF SIGN EQ ";" .GOTO 10
.IF SIGN EQ "&" .GOTO 10
.IF SIGN EQ " " .GOTO 10
.; Parse filespec to determine extension.
.PARSE FSPEC ".;" FNAM EXT VER
.;
.IFF REMOTE ;
.IFF REMOTE ;   ---------<<< 'FNAM' >>>----------
.IFF REMOTE ;
.DATA #1   
.DATA #1 'FSPEC'
.;
.RDHEAD:
.READ #3 HEADER
.IFT <EOF> .GOTO FINISH
.TEST HEADER
.IF <STRLEN> EQ 0 .GOTO RDHEAD
.SETS SIGN HEADER[1:1]
.IF SIGN EQ ";" .GOTO RDHEAD
.IF SIGN EQ "&" .GOTO RDHEAD
.IF SIGN EQ " " .GOTO RDHEAD
.IF SIGN EQ "%" .GOTO 20
.; no header to extract, we read another file spec, so backtrack
.SETS FSPEC HEADER
.GOTO 11:
.;
.20:
.; we are commanded to extract a header, lets parse it out
.PARSE HEADER "%]" DUM1 EXTDEV DUM2
.IF DUM2 EQ "" .GOTO 21
.SETS EXTDEV EXTDEV+"]"
.PARSE HEADER "]." DUM1 HDNAME DUM2
.GOTO 22
.;
.21:
.; no device or uic precedes external header name
.SETS EXTDEV ""
.PARSE HEADER "%." DUM1 HDNAME DUM2
.;
.22:
.; EXTDEV is the device to put EXT file, HDNAME is the procedure or
.;  function name to extract
.;
.OPEN #2 TRANEXT.DAT;1
.DATA #2 'FSPEC'
.DATA #2 'HDNAME'
.DATA #2 'EXTDEV'
.CLOSE #2
RUN LB:[22,310]P3EXT
.IF <EXSTAT> EQ 1 .GOTO 23
.SETS CURJOB "P3EXT extraction"
.GOTO FUBAR
.;
.23:
.IFT DOLST PRI 'SPDEV''EXTDEV''HDNAME'.EXT;1
.IFF REMOTE ;  'EXTDEV''HDNAME'.EXT;1 extracted from 'FSPEC'
.IFF REMOTE ;
.DATA #1     'EXTDEV''HDNAME'.EXT;1
.GOTO RDHEAD
.;
.FUBAR:
.DATA #1 <'EXTDEV''HDNAME'.EXT from 'FSPEC' skipped -- error in 'CURJOB'>
.IFF REMOTE ; 
.IFF REMOTE ; Error in <'FSPEC'> (in 'CURJOB') -- EXT file not updated.
.IFT REMOTE BRO 'ETI' Error in <'FSPEC'> (in 'CURJOB') -- EXT file not updated.
.IFT REMOTE .GOTO 15
.IFT NOINPT .GOTO 15
.ASKS GOON Enter C to continue, P to pause, X to exit
.IF GOON EQ "C" .GOTO RDHEAD
.IF GOON EQ "P" .PAUSE
.IF GOON NE "X" .GOTO RDHEAD
.SETT BADEND
.GOTO FINISH
.;
.15:
.IFT ERRX .GOTO 16
.IFT ERRC .GOTO RDHEAD
.;ERRP MUST BE TRUE
.IFT REMOTE BRO 'ETI' PAUSING TYPE UNS ..XXXX TO CONTINUE
.PAUSE
.;
.16:
.INC ERRNUM
.IF ERRNUM LT ERRMAX .GOTO RDHEAD
.IFF REMOTE ;
.IFF REMOTE ; Exiting command file prematurely after 'ERRMAX' error(s).
.IFF REMOTE ;
.IFT REMOTE BRO 'ETI' EXITING AFTER 'ERRMAX' ERROR(S).
.DATA #1  
.DATA #1 <Exiting command file prematurely after 'ERRMAX' error(s).>
.SETT BADEND
.GOTO FINISH
.;
.FINISH:
.CLOSE #3
.DATA #1      
.DATA #1 Finished at '<DATE>' '<TIME>'.
.DATA #1   
.DATA #1   
.CLOSE #1
.SHUTUP:
PIP TRANEXT.DAT;*/DE/NM
.IFF REMOTE ; Operation complete
.IFT REMOTE BRO 'ETI' @BUILDLBR for 'MODNAM' complete at '<DATE>' '<TIME>'.
.IFT BADEND .EXIT 4
