500 likes | 653 Views
MPE/iX Command File Tips and Techniques by Jack Bailie. MPE/iX Command File Tips and Techniques. Style Techniques Examples Parameters Predefined variables Help Functions Errors Debugging. Style. PARM fileset=@ LISTFILE !fileset, DISC Meaningful parameter names
E N D
MPE/iX Command File Tips and Techniques • Style • Techniques • Examples • Parameters • Predefined variables • Help • Functions • Errors • Debugging
Style • PARM fileset=@ • LISTFILE !fileset, DISC • Meaningful parameter names • Keywords and Commands in Upper Case • Variables in lower case • Blank lines
Documentation • PARM fileset=@ • COMMENT Title: LISTFILE a file set • COMMENT File: L.CMD • COMMENT By: J.D. Bailie • COMMENT Rev: 3/12/91 • LISTFILE !fileset, DISC • Comments to document command files • Save command files in a special group (CMD)
HPPATH • SETVAR HPPATH “CMD.CAPS,CMDD.CAPS,PUB,!!hpgroup,PUB.SYS” • HPPATH is a system predefined variable • Change the HPPATH in a logon UDC • Order for searching : • CMD.CAPS • CMDD.CAPS • Account PUB • Current group • PUB.SYS
Parameters • PARM fileset=@ • PARM format=DISC • LISTFILE !fileset, !format • Put each parameter on a separate line • Example use : • :L C@ • :L C@, 3 • :L FILESET=C@ • :L FORMAT=DETAIL, FILESET=@
ANYPARM • PARM fileset=@ • ANYPARM format=DISC • LISTFILE !fileset, !format • May only have one • Must be the last parameter • Reads everything else, including punctuation • May have default value :L C@, DETAIL;PASS
MPE HELP :HELP L • USER DEFINED COMMAND FILE: L.CMD.CAPS • PARM fileset=@ • ANYPARM format=DISC • LISTFILE !fileset, !format • Shows the name of file • Lists contents of file • Can be very complex • Not very useful to a user • USER DEFINED COMMAND FILE: L.CMD.CAPS • PARM fileset=@ • ANYPARM format=DISC • LISTFILE !fileset, !format
MPE HELP • PARM fileset=@ • ANYPARM format=DISC • COMMENT • COMMENT L LISTFILE a fileset • COMMENT • COMMENT Syntax • COMMENT :L fileset [,format] • COMMENT • COMMENT Parameters • COMMENT :L fileset [,format] • COMMENT • COMMENT Parameters • COMMENT fileset The file[set] to LISTF; default @ • COMMENT format The LISTFILE format; default DISC • COMMENT • LISTFILE !fileset,!format • Use COMMENTs to describe command
MPE HELP • USER DEFINED COMMAND FILE: L.CMD.CAPS • PARM fileset=@ • ANYPARM format=DISC • COMMENT • COMMENT L LISTFILE a fileset • COMMENT • COMMENT Syntax • COMMENT :L fileset [,format] • COMMENT • COMMENT Parameters • COMMENT :L fileset [,format] • COMMENT • COMMENT Parameters • COMMENT fileset The file[set] to LISTF; default @ • COMMENT format The LISTFILE format; default DISC • COMMENT • LISTFILE !fileset,!format • USER DEFINED COMMAND FILE: L.CMD.CAPS • PARM fileset=@ • ANYPARM format=DISC • COMMENT • COMMENT L LISTFILE a fileset • COMMENT • COMMENT Syntax • COMMENT :L fileset [,format] • COMMENT • COMMENT Parameters • COMMENT :L fileset [,format] • COMMENT • COMMENT Parameters • COMMENT fileset The file[set] to LISTF; default @ • COMMENT format The LISTFILE format; default DISC • COMMENT • LISTFILE !fileset,!format • Gives user information • Still lists all commands • Cluttered
ECHO HELP • PARM fileset=? • ANYPARM format=DISC • IF "!fileset" = "?" THEN • ECHO • ECHO L LISTFILE a fileset • ECHO • ECHO Syntax • ECHO :L fileset [,format] • ECHO • ECHO Parameters • ECHO fileset The file[set] to LISTF; default @ • ECHO format The LISTFILE format; default DISC • ECHO • ELSE • LISTFILE !fileset, !format • ENDIF Use • ECHO command • "?" default parameter
ECHO HELP :L • L LISTFILE a fileset • Syntax • :L fileset [,format] • Parameters • fileset The file[set] to LISTF; default @ • format The LISTFILE format; default DISC • Clearer yet • Only information the user needs • L LISTFILE a fileset • Syntax • :L fileset [,format] • Parameters • fileset The file[set] to LISTF; default @ • format The LISTFILE format; default DISC
Fancier ECHO HELP • IF "!fileset" = "?" THEN • SETVAR S CHR(14) • SETVAR B CHR(14)+':'+CHR(15) • ECHO • ECHO ![S+'R,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,T'] • ECHO ![B+' L LISTFILE a fileset '+B] • ECHO ![S+'@9999999999999999999999999999999999999999999999999['] • ECHO ![B+' Syntax '+B] • ECHO ![B+' :L fileset [,format] '+B] • ECHO ![B+' '+B] • ECHO ![B+' Parameters '+B] • ECHO ![B+' fileset The file[set] name to LISTF, @ '+B] • ECHO ![B+' format The LISTFILE format; DISC '+B] • ECHO ![S+'F,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,G'] • DELETEVAR S,B • ELSE • LISTFILE !fileset,!format • ENDIF • Use line drawing characters
Fancier ECHO HELP :L • L LISTFILE a fileset • Syntax • :L fileset [,format] • Parameters • fileset The file[set] name to LISTF; @ • format The LISTFILE format; DISC • Help information is outlined • L LISTFILE a fileset • Syntax • :L fileset [,format] • Parameters • fileset The file[set] name to LISTF; @ • format The LISTFILE format; DISC
VARIABLES • PARM file • SETVAR _find_creator FINFO('!file','CREATOR') • LISTFILE !file, QUALIFY • ECHO Creator is !_find_creator • DELETEVAR _find_@ • Set variables • Use unique names for variables • Delete variables when done
FINFO • PARM file • SETVAR _find_creator FINFO('!file','CREATOR') • LISTFILE !file, QUALIFY • ECHO Creator is !_find_creator • DELETEVAR _find_@ • FINFO - find out 44 different things about a file, ie. EOF, Exists, Creator, Various Dates, Size, • 1st argument of FINFO is Command file parameter • Use option names with FINFO not numbers
Prompt for Parameters • PARM file=' ' • IF '!file' = ' ' THEN • INPUT _find_file;PROMPT='Enter a file name ';WAIT=60 • ELSE • SETVAR _find_file '!file' • ENDIF • SETVAR _find_creator FINFO(_find_file,'CREATOR') • LISTFILE !_find_file, QUALIFY • ECHO Creator is !_find_creator • DELETEVAR _find_@ • Prompt if parameter is not entered • Alternative or in addition to help • INPUT with WAIT • 1st argument of FINFO is variable
INPUT from a file • PARM file • SETVAR _find_creator FINFO('!file','CREATOR') • INPUT _find_line < !file • LISTFILE !file, QUALIFY • ECHO Creator is !_find_creator • ECHO First line is • ECHO !_find_line • DELETEVAR _find_@ • INPUT Command reads only the first line of file
INPUT from message file • PARM fileset • FILE FINDTEMP;MSG • LISTFILE !fileset,QUALIFY > *FINDTEMP • RESET FINDTEMP • WHILE (FINFO('FINDTEMP','EOF') > 0) DO • INPUT _find_file < FINDTEMP • SETVAR _find_file RTRIM(_find_file) • SETVAR _find_creator FINFO(_find_file,'CREATOR') • ECHO !_find_file !_find_creator • ENDWHILE • DELETEVAR _find_@ • PURGE FINDTEMP,TEMP • Write LISTF to a message file • 1st argument of FINFO is the filename • Read from message file, one line at a time • Trim blanks from right end of input line
Style • PARM fileset • FILE FINDTEMP;MSG • LISTFILE !fileset,QUALIFY > *FINDTEMP • RESET FINDTEMP • WHILE (FINFO('FINDTEMP','EOF') > 0) DO INPUT _find_file < FINDTEMP SETVAR _find_file RTRIM(_find_file) SETVAR _find_creator FINFO(_find_file,'CREATOR') ECHO !_find_file !_find_creator • ENDWHILE • DELETEVAR _find_@ • PURGE FINDTEMP,TEMP • Parenthesis around WHILE statement conditions • Indent WHILE statement logic • DO is optional • Clean up after yourself
INPUT from a Flat File • PARM fileset=@ • LISTFILE !fileset,QUALIFY > FINDTEMP • XEQ FINDIT < FINDTEMP • PURGE FINDTEMP,TEMP • LISTF to a flat file • Execute another command file and give it the flat file as input
INPUT from a Flat File • SETVAR _find_I 1 • SETVAR _find_eof FINFO('FINDTEMP','EOF') • WHILE (_find_i <= _find_eof) DO SETVAR _find_file INPUT() SETVAR _find_file RTRIM(_find_file) SETVAR _find_creator FINFO(_find_file,'CREATOR') ECHO !_find_file !_find_creator SETVAR _find_i _find_i + 1 • ENDWHILE • DELETEVAR _find_@ • Called from another command file • No parameters • Input from file created by the other command • 3 times faster than message files • Requires two command files
Entry Points • PARM fileset=@ • PARM entry=MAIN • IF ('!entry' = 'MAIN') THEN • LISTFILE !fileset,QUALIFY > FINDTEMP • XEQ FIND ENTRY='NOTMAIN' < FINDTEMP • PURGE FINDTEMP,TEMP • ELSE • SETVAR _find_i 1 • SETVAR _find_eof FINFO('FINDTEMP','EOF') • WHILE (_find_i <= _find_eof) DO • SETVAR _find_file INPUT() • SETVAR _find_file RTRIM(_find_file) • SETVAR _find_creator FINFO(_find_file,'CREATOR') • ECHO !_find_file !_find_creator • SETVAR _find_i _find_i + 1 • ENDWHILE • ENDIF • Use an "ENTRY POINT" of the same file • Do not need multiple command files
Handle Error Conditions • PARM fileset • LISTFILE !fileset,QUALIFY > FINDTEMP • IF (FINFO('FINDTEMP','EXISTS')) THEN • ... • ... • ELSE • ECHO • ECHO No files in the fileset !fileset • ECHO • ENDIF • Handle all possible conditions • Test command files
Handle Error Conditions • PARM fileset • ERRCLEAR • LISTFILE !fileset,QUALIFY > FINDTEMP • IF (HPCIERR = 0) THEN • ... • ... • ELSE • ECHO • ECHO No files in the fileset !fileset • ECHO • ENDIF • Another way to handle errors • ERRCLEAR zeros predefined error variables
Fancy Error Messages • ECHO • ECHO ![CHR(27)+"&dB"] No files !fileset ![CHR(27)+"&d@"] • ECHO • ![CHR(27)+"&dB"] Turns on highlighting • ![CHR(27)+"&d@"] Turns it off
Fancy Error Messages • SETVAR ON CHR(27)+"&dB" • SETVAR OFF CHR(27)+"&d@" • ECHO • ECHO !on No files in ![UPS("!fileset")] !off • ECHO • SETVARs easier (shorter) to use and reuse • ON Turns on highlighting • OFF Turns off highlighting • UPS upshifts the input No files in X@.CMD
Handle Error Conditions • DELETEVAR _find_@ • DELETEVAR with no VARS to delete "NO MATCH FOUND FOR THIS VARIABLE SET"
Handle Error Conditions • DELETEVAR _find_@ > $NULL • Redirect command output to $NULL • No error message
Continuation Lines • PARM what=" " • SETVAR _S_WHAT UPS("!what") • IF ("!_s_what" = " " & • OR "!_s_what" = "S" & • OR "!_s_what" = "J") THEN • SHOWJOB JOB=@!_s_what • ELSEIF ("!_s_what" = "M") THEN • SHOWME • ELSEIF ("!_s_what" = "O") THEN • SPOOLF @;SHOW • ENDIF • Continuation lines • ELSEIF • Multiple commands in a single command file
Purging Files • ... • PURGE !file • ... • Error message if file does not exist
Purging Files • ... • SETVAR _find_savemsg HPMSGFENCE • SETVAR HPMSGFENCE 2 • PURGE !file • SETVAR HPMSGFENCE _find_savmsg • ... • No error message if file does not exist • Suppresses all error messages • If command is aborted it leaves messages off
Purging Files • ... • IF (FINFO("!file","EXISTS")) THEN • PURGE !file • ENDIF • No error message if file does not exist
Purging Files • ... • PURGE !file > $NULL • ... • Simpler
Debugging • SETVAR HPCMDTRACE TRUE • Can set it interactively • Lists every command executed • Be sure to turn it off
Debugging • OPTION LIST • Add to command file • Lists commands executed • Use LIST and NOLIST to list selected parts
Debugging • ... • PARM debug=0 • ... • IF (!debug > 0) THEN • SETVAR HPCMDTRACE TRUE • SETVAR HPMSGFENCE 0 • ELSE • ... • IF !debug = 0 THEN • PURGE FINDTEMP,TEMP > $NULL • ENDIF • Add a debug parameter • Reference it as a keyword parameter :FIND C@, DEBUG=1 • Most users do not know it exists • Skip file purge in debug mode
Documentation • DESCR List files in a fileset with FSEDIT Descriptions • Syntax • :DESCR [fileset] [,find-string] • Parameters • fileset The HP fileset desired; default @.CMD • find-string A string to search for • Command file to list descriptions of commands • Keyword search feature
Documentation :DESCR A@.CMD • Files in the fileset A@.CMD with FSEDIT Descriptions • A - ABORT Command file • ACCTINFO - Formatted output of System Accounting Structure • ADDR - Print address labels • AJ - ABORTJOB • AS - Alter spool file PRI to 12 so it will print • ... • Descriptions are in the file User Label • Enter descriptions with FSEDIT or GSCAN
SETVAR Function in WHILE • PARM fileset=@ • PARM entry=MAIN • IF ('!entry' = 'MAIN') THEN • LISTFILE !fileset,QUALIFY > FINDTEMP • XEQ FIND ENTRY='NOTMAIN' < FINDTEMP • PURGE FINDTEMP,TEMP • ELSE • SETVAR _find_i 0 • SETVAR _find_eof FINFO('FINDTEMP','EOF') • WHILE (SETVAR(_find_i,_find_i+1) <= _find_eof) DO • SETVAR _find_file INPUT() • SETVAR _find_file RTRIM(_find_file) • SETVAR _find_creator FINFO(_find_file,'CREATOR') • ECHO !_find_file !_find_creator • ENDWHILE • ENDIF • Use SETVAR Function to increment index within the WHILE statement
FINFO Function in WHILE • PARM fileset=@ • PARM entry=MAIN • IF ('!entry' = 'MAIN') THEN • LISTFILE !fileset,QUALIFY > FINDTEMP • XEQ FIND ENTRY='NOTMAIN' < FINDTEMP • PURGE FINDTEMP,TEMP • ELSE • SETVAR _find_i 0 • WHILE SETVAR(_find_i,_find_i+1) <= FINFO('FINDTEMP','EOF') • SETVAR _find_file INPUT() • SETVAR _find_file RTRIM(_find_file) • SETVAR _find_creator FINFO(_find_file,'CREATOR') • ECHO !_find_file !_find_creator • ENDWHILE • ENDIF • Use the FINFO in the WHILE statement too • Shorter command files • Not as easy to follow • Has the command file name in it
Choose Your Own Name • SETVAR _my_name "!-1" • "! 1" gives the last command executed • As 1st command in file it gives name of file
Choose Your Own Name • SETVAR _my_name "!-1" • SETVAR _my_name UPS(_my_name) • IF POS("XEQ ",_my_name) > 0 THEN • SETVAR _my_name _my_name "XEQ " • ENDIF • SETVAR _my_name LTRIM(_my_name) • IF POS(" ",_my_name) > 1 THEN • SETVAR _my_name LFT(_my_name,POS(" ",_my_name)-1) • ENDIF • Clean it up to use it • Upshift • Strip off "XEQ" • Strip off leading blanks • Strip off trailing parameters
Choose Your Own Name • ... • IF ('!entry' = 'MAIN') THEN • LISTFILE !fileset,QUALIFY > FINDTEMP • XEQ !_my_name, ENTRY="NOTMAIN" < FINDTEMP • PURGE FINDTEMP,TEMP • ELSE • ... • Substitute line in FIND command file • Use it to call other entry point • I'll call it FIND • You can call it WHEREIS
Choose Your Own Name • ... • ECHO !_my_name LISTF a fileset with Creators name • ... • Can even use it in help
System Message Spacing • CHKDAT.COMMAND.CSLXL • SHOWDEV !ldev > CKTEMP • ... • SETVAR _chkdat_avail STR(_chkdat_ckin,11,1) • SETVAR _chkdat_vol STR(_chkdat_ckin,43,1) • SETVAR _chkdat_den STR(_chkdat_ckin,57,1) • IF _chkdat_avail = "A" AND _chkdat_vol ="(" AND & • ( _chkdat_den = "1" OR _chkdat_den = "6") THEN • Depends on spacing in SHOWDEV command • Changed from 3.1 to 4.0 • Expect changes with 5.0
Documentation • PARM fileset="@.CMD", find =" ", entry=MAIN • IF "!fileset" = "?" then • SETVAR S,CHR(14) • SETVAR B CHR(14)+':'+CHR(15) • ECHO ![S+'R,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,T'], • ECHO ![B+' DESCR List files in a fileset with FSEDIT Description'+B] • ECHO ![S+'@9999999999999999999999999999999999999999999999999999999999['] • ECHO ![B+' '+B] • ECHO ![B+' Syntax '+B] • ECHO ![B+' :DESCR fileset [,find_string] '+B] • ECHO ![B+' '+B] • ECHO ![B+' Parameters '+B] • ECHO ![B+' fileset The fileset to look at; default @.CMD '+B] • ECHO ![B+' find_string a string to search for '+B] • ECHO ![B+' '+B] • ECHO ![S+'F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;G'] • DELETEVAR S,B • RETURN • ENDIF • IF '!entry' = 'MAIN' THEN • ERRCLEAR • SETVAR _descr_find '!find' • LISTFILE !fileset,QUALIFY > DESCRTMP • SETVAR _descr_i 0 • IF HPCIERR = 0 THEN • SETVAR _descr_eof FINFO('DESCRTMP','EOF') • ECHO Files in the fileset !fileset with FSEDIT Descriptions • ECHO • XEQ DESCR ENTRY='NOTMAIN' < DESCRTMP • ELSE • ECHO File !fileset NOT found • ENDIF • PURGE DESCRTMP,TEMP • DELETEVAR _descr_@ • ELSE • Documentation • WHILE SETVAR(_descr_i,_descr_i+1) <=_descr_eof DO • SETVAR _descr_file INPUT() • COMMENT Does it have User Labels Written? • IF FINFO(_descr_file,10) > 0 THEN • COMMENT Yes, read the fisrt user label • SETVAR _descr_file_descr RHT(FINFO(_descr_file,25),64) • IF LFT(_descr_file_descr,1) < " " OR & • LFT(_descr_file_descr,1) >= "}" THEN • SETVAR _descr_file_descr RPT(".",64) • ENDIF • SETVAR _descr_len 9-POS(".",_descr_file) • SETVAR _descr_file_descr RTRIM(_descr_file)+ & • RPT(" ",_descr_len)+" "+_descr_file_descr • IF _descr_find <> " " THEN • IF POS(UPS(_descr_find),UPS(_descr_file_descr)) <> 0 THEN • ECHO !_descr_file_descr • ENDIF • ELSE • ECHO !_descr_file_descr • ENDIF • ENDIF • ENDWHILE • ENDIF
Further Research • @.COMMAND.CSLXL • AUTOPAT.PATCHXL.TELESUP • TREELIST.PUBXL.TELESUP • MKACCT.PUB.SYS • Lots of examples • Very complex • AUTOPAT stores STREAM file data in bottom of file • MKACCT uses MKMSGS.MPEXL for messages
References • MPE XL Commands Reference Manual 32650-90003 • CI Access and Variables Programmers Guide 32650-90011 • INTERACT Page Title / Author • Nov 88 44 New Features of MPE XL User Interface • Thomas Shem & Jeff Vance • Sept 89 26 Life of an MPE XL Command • Scott Cressler & Jeff Vance • Mar 90 96 Programming with MPE XL • Heikki Tsakinen • Feb 91 83 Advanced CI Programming, The 2.1 Story • Scott Cressler, Jeff Vance, Steve Elmer • Sept 91 86 MPE XL Command Files • Fred Ochs, Jr. • Nov 92 26 Creating Command Files • Rene Martinez • Nov 92 78 What the Manuals Don't Say • John Dunlop