Document revision date: 15 July 2002 | |
Previous | Contents | Index |
This appendix contains complete command procedures for the concepts and techniques discussed in Chapter 13, Chapter 14, and Chapter 15. Each section in this appendix discusses one command procedure and provides the following information:
This command procedure converts an absolute time (for a time in the future) to a delta time and determines the time between the current time and the time that you specify. The procedure illustrates the use of the F$TIME and F$CVTIME lexical functions and the use of assignment statements to perform arithmetic calculations and to concatenate symbol values.
$ ! Procedure to convert an absolute time to a delta time. $ ! The delta time is returned as the global symbol WAIT_TIME. $ ! P1 is the time to be converted. $ ! P2 is an optional parameter - SHOW - that causes the $ ! procedure to display WAIT_TIME before exiting $ ! $ ! Check for inquiry $ ! $ IF P1 .EQS. "?" .OR. P1 .EQS. "" THEN GOTO TELL (1) $ ! $ ! Verify the parameter: hours must be less than 24 $ ! minutes must be less than 60 $ ! time string must contain only hours $ ! and minutes $ ! $ ! Change error and message handling to $ ! use message at BADTIME $ ! $ ON WARNING THEN GOTO BADTIME (2) $ SAVE_MESSAGE = F$ENVIRONMENT("MESSAGE") $ SET MESSAGE/NOFACILITY/NOIDENTIFICATION/NOSEVERITY/NOTEXT $ TEMP = F$CVTIME(P1) $ ! $ ! Restore default error handling and message format $ ON ERROR THEN EXIT $ SET MESSAGE'SAVE_MESSAGE' $ ! $ IF F$LENGTH(P1) .NE. 5 .OR. - (3) F$LOCATE(":",P1) .NE. 2 - THEN GOTO BADTIME $ ! $ ! Get the current time $ ! $ TIME = F$TIME() (4) $ ! $ ! Extract the hour and minute fields from both the current time $ ! value (TIME) and the future time (P1) $ ! $ MINUTES = F$CVTIME(TIME,"ABSOLUTE","MINUTE") ! Current minutes (5) $ HOURS = F$CVTIME(TIME,"ABSOLUTE","HOUR") ! Current hours $ FUTURE_MINUTES = F$CVTIME(P1,"ABSOLUTE","MINUTE") ! Minutes in future time $ FUTURE_HOURS = F$CVTIME(P1,"ABSOLUTE","HOUR") ! Hours in future time $ ! $ ! $ ! Convert both time values to minutes $ ! Note the implicit string to integer conversion being performed $ ! $ CURRENT_TIME = HOURS*60 + MINUTES (6) $ FUTURE_TIME = FUTURE_HOURS*60 + FUTURE_MINUTES $ ! $ ! Compute difference between the future time and the current time $ ! (in minutes) $ ! $ ! $ MINUTES_TO_WAIT = FUTURE_TIME - CURRENT_TIME (7) $ ! $ ! If the result is less than 0 the specified time is assumed to be $ ! for the next day; more calculation is required. $ ! $ IF MINUTES_TO_WAIT .LT. 0 THEN - (8) MINUTES_TO_WAIT = 24*60 + FUTURE_TIME - CURRENT_TIME $ ! $ ! Start looping to determine the value in hours and minutes from $ ! the value expressed all in minutes $ ! $ HOURS_TO_WAIT = 0 $ HOURS_TO_WAIT_LOOP: (9) $ IF MINUTES_TO_WAIT .LT. 60 THEN GOTO FINISH_COMPUTE $ MINUTES_TO_WAIT = MINUTES_TO_WAIT - 60 $ HOURS_TO_WAIT = HOURS_TO_WAIT + 1 $ GOTO HOURS_TO_WAIT_LOOP $ FINISH_COMPUTE: $ ! $ ! Construct the delta time string in the proper format $ ! $ WAIT_TIME == F$STRING(HOURS_TO_WAIT)+ ":" + F$STRING(MINUTES_TO_WAIT)- (10) + ":00.00" $ ! $ ! Examine the second parameter $ ! $ IF P2 .EQS. "SHOW" THEN SHOW SYMBOL WAIT_TIME (11) $ ! $ ! Normal exit $ ! $ EXIT $ ! $ BADTIME: (12) $ ! Exit taken if first parameter is not formatted correctly $ ! EXIT command returns but does not display error status $ ! $ SET MESSAGE'SAVE_MESSAGE' $ WRITE SYS$OUTPUT "Invalid time value: ",P1,", format must be hh:mm" $ WRITE SYS$OUTPUT "Hours must be less than 24; minutes must be less than 60" $ EXIT %X10000000 $ ! $ ! $ TELL: (13) $ ! Display message and exit if user enters inquiry or enters $ ! an illegal parameter $ ! $ TYPE SYS$INPUT This procedure converts an absolute time value to a delta time value. The absolute time must be in the form hh:mm and must indicate a time in the future. On return, the global symbol WAIT_TIME contains the converted time value. If you enter the keyword SHOW as the second parameter, the procedure displays the resulting value in the output stream. To invoke this procedure, use the following syntax: @CONVERT hh:mm [SHOW] $ EXIT |
Notes for CONVERT.COM Command Procedure
hh:mm |
The IF command checks (1) that the length of the entered value is 5
characters and (2) that the third character (offset of 2) is a colon.
The IF command contains the logical OR operator: if either expression
is true (that is, if the length is not 5 or if there is not a colon in
the third character position), the procedure branches to the label
BADTIME.
Sample Execution for CONVERT.COM Command Procedure
$ SHOW TIME 10-JUN-1999 10:38:26 $ @CONVERT 12:00 SHOW WAIT_TIME = "1:22:00.00" |
The SHOW TIME command displays the current date and time. CONVERT.COM
is executed with the parameters 12:00 and SHOW. The procedure converts
the absolute time 12:00 to a delta time value and displays it on the
terminal.
B.2 REMINDER.COM Command Procedure
This command procedure displays a reminder message on your terminal at a specified time. The procedure prompts for the time you want the message to be displayed and for the text of the message. The procedure uses CONVERT.COM to convert the time to a delta time. The procedure then spawns a subprocess that waits until the specified time and displays your reminder message. The procedure illustrates the use of the F$ENVIRONMENT, F$VERIFY, and F$GETDVI functions.
$ ! Procedure to obtain a reminder message and display this $ ! message on your terminal at the time you specify. $ ! $ ! Save current states for procedure and image verification $ ! Turn verification off for duration of procedure $ $ SAVE_VERIFY_IMAGE = F$ENVIRONMENT("VERIFY_IMAGE") (1) $ SAVE_VERIFY_PROC = F$VERIFY(0) $ ! $ ! Places the current process in a wait state until a specified $ ! absolute time. Then, it rings the bell on the terminal and $ ! displays a message. $ ! $ ! Prompt for absolute time $ ! $ $ GET_TIME: $ INQUIRE REMINDER_TIME "Enter time to send reminder (hh:mm)" (2) $ INQUIRE MESSAGE_TEXT "Enter message" $ ! $ ! Call the CONVERT.COM procedure to convert the absolute time $ ! to a delta time $ ! $ @DISK2:[JONES.TOOLS]CONVERT 'REMINDER_TIME' (3) $ IF .NOT. $STATUS THEN GOTO BADTIME $ ! $ ! $ ! Create a command file that will be executed $ ! in a subprocess. The subprocess will wait until $ ! the specified time and then display your message $ ! at the terminal. If you are working at a DEC_CRT $ ! terminal, the message has double size blinking $ ! characters. Otherwise, the message has normal letters. $ ! In either case, the terminal bell rings when the $ ! message is displayed. $ $ CREATE WAKEUP.COM (4) $ DECK ! Lines starting with $ are data lines $ WAIT 'WAIT_TIME' (5) $ BELL[0,7] = %X07 ! Create symbol to ring the bell $ IF F$GETDVI("SYS$OUTPUT","TT_DECCRT") .NES. "TRUE" THEN GOTO OTHER_TERM $ ! $ DEC_CRT_ONLY: $ ! Create symbols to set special graphics (for DEC_CRT terminals only) $ ! $ SET_FLASH = "<ESC>[1;5m" ! Turn on blinking characters $ SET_NOFLASH = "<ESC>[0m" ! Turn off blinking characters $ TOP = "<ESC>#3" ! Double size characters (top portion) $ BOT = "<ESC>#4" ! Double size characters (bottom portion) $ ! $ ! Write double size, blinking message to the terminal and ring the bell $ ! $ WRITE SYS$OUTPUT BELL, SET_FLASH, TOP, MESSAGE_TEXT $ WRITE SYS$OUTPUT BELL, BOT, MESSAGE_TEXT $ WRITE SYS$OUTPUT F$TIME(), SET_NOFLASH $ GOTO CLEAN_UP $ ! $ OTHER_TERM: $ WRITE SYS$OUTPUT BELL,MESSAGE_TEXT $ WRITE SYS$OUTPUT F$TIME() $ ! $ CLEAN_UP: $ DELETE WAKEUP.COM;* $ EOD $ ! $ ! Now continue executing commands. $ ! $ SPAWN/NOWAIT/INPUT=WAKEUP.COM (6) $ END: (7) $ ! Restore verification $ SAVE_VERIFY_PROC = F$VERIFY(SAVE_VERIFY_PROC, SAVE_VERIFY_IMAGE) $ EXIT $ ! $ BADTIME: $ WRITE SYS$OUTPUT "Time must be entered as hh:mm" $ GOTO GET_TIME |
Notes for REMINDER.COM Command Procedure
Sample Execution for REMINDER.COM Command Procedure
$ @REMINDER Enter time to send reminder (hh:mm): 12:00 Enter message: TIME FOR LUNCH %DCL-S-SPAWNED, process BLUTO_1 spawned $ . . . TIME FOR LUNCH 11-DEC-1999 12:00:56.99 |
The procedure prompts for a time value and for your message. Then the
procedure spawns a subprocess that displays your message. You can
continue working at your terminal; at the specified time, the
subprocess rings the terminal bell, displays your message, and displays
the time.
B.3 DIR.COM Command Procedure
This command procedure imitates the DCL command DIRECTORY/SIZE=ALL/DATE, displaying the block size (used and allocated) and creation date of the specified files. It illustrates use of the F$PARSE, F$SEARCH, F$FILE_ATTRIBUTES, and F$FAO lexical functions.
$ ! $ ! Command procedure implementation of DIRECTORY/SIZE=ALL/DATE $ ! command $ ! $ SAVE_VERIFY_IMAGE = F$ENVIRONMENT("VERIFY_IMAGE") $ SAVE_VERIFY_PROCEDURE = F$VERIFY(0) $ ! $ ! Replace any blank field of the P1 file specification with $ ! a wildcard character $ ! $ P1 = F$PARSE(P1,"*.*;*") (1) $ ! $ ! Define initial values for symbols $ ! $ FIRST_TIME = "TRUE" $ FILE_COUNT = 0 $ TOTAL_ALLOC = 0 $ TOTAL_USED = 0 $ $ LOOP: (2) $ FILESPEC = F$SEARCH(P1) $ ! Find next file in directory $ IF FILESPEC .EQS. "" THEN GOTO DONE $ ! If no more files, then done $ IF .NOT. FIRST_TIME THEN GOTO SHOW_FILE $ ! Print header only once $ ! $ ! Construct and output the header line $ ! $ FIRST_TIME = "FALSE" (3) $ DIRSPEC = F$PARSE(FILESPEC,,, "DEVICE") - +F$PARSE(FILESPEC,,, "DIRECTORY") $ WRITE SYS$OUTPUT "" $ WRITE SYS$OUTPUT "Directory ",DIRSPEC $ WRITE SYS$OUTPUT "" $ LASTDIR = DIRSPEC $ $ ! $ ! Put the file name together, get some of the file attributes, and $ ! type the information out $ ! $SHOW_FILE: $ FILE_COUNT = FILE_COUNT + 1 $ FILENAME = F$PARSE(FILESPEC,,, "NAME") - (4) + F$PARSE(FILESPEC,,, "TYPE") - + F$PARSE(FILESPEC,,, "VERSION") $ ALLOC = F$FILE_ATTRIBUTES(FILESPEC, "ALQ") $ USED = F$FILE_ATTRIBUTES(FILESPEC, "EOF") $ TOTAL_ALLOC = TOTAL_ALLOC + ALLOC $ TOTAL_USED = TOTAL_USED + USED $ REVISED = F$FILE_ATTRIBUTES(FILESPEC,"RDT") $ LINE = F$FAO("!19AS !5UL/!5<!UL!> !17AS",FILENAME,- USED, ALLOC, REVISED) $ WRITE SYS$OUTPUT LINE $ GOTO LOOP $ $ ! $ ! Output summary information, reset verification, and exit $ ! $ DONE: (5) $ WRITE SYS$OUTPUT "" $ WRITE SYS$OUTPUT "Total of ''FILE_COUNT' files, " + - "''TOTAL_USED'/''TOTAL_ALLOC' blocks." $ SAVE_VERIFY_PROCEDURE = F$VERIFY(SAVE_VERIFY_PROCEDURE,SAVE_VERIFY_IMAGE) $ EXIT |
Notes for DIR.COM Command Procedure
Sample Execution for DIR.COM Command Procedure
$ @DIR [VERN]*.COM |
Directory DISK4:[VERN] BATCH.COM;1 1/3 11-DEC-1999 11:43 CALC.COM;3 1/3 11-DEC-1999 11:30 CONVERT.COM;1 5/6 11-DEC-1999 15:23 . . . LOGIN.COM;34 2/3 11-DEC-1999 13:17 PID.COM;7 1/3 11-DEC-1999 09:49 SCRATCH.COM;6 1/3 11-DEC-1999 11:29) Total of 15 files, 22/48 blocks. |
The procedure returns information on all .COM files in the directory
[VERN].
B.4 SYS.COM Command Procedure
This command procedure returns statistics about the current process, all processes in the group (if the current process has group privilege), and all processes on the system (if the current process has world privilege). This procedure illustrates use of the F$PID, F$EXTRACT, and F$GETJPI lexical functions.
$ ! $ ! Displays information about owner, group, or system processes. $ ! $ ! Turn off verification and save current settings $ SAVE_VERIFY_IMAGE = F$ENVIRONMENT("VERIFY_IMAGE") $ SAVE_VERIFY_PROCEDURE = F$VERIFY(0) $ CONTEXT = "" ! Initialize PID search context (1) $ ! $ ! Output header line. $ ! $ WRITE SYS$OUTPUT " PID Username Term Process " + - (2) "name State Pri Image" $ ! $ ! Output process information. $ ! $LOOP: $ ! $ ! Get next PID. If null, then done. $ ! $ PID = F$PID(CONTEXT) (3) $ IF PID .EQS. "" THEN GOTO DONE $ ! $ ! Get image file specification and extract the file name. $ ! $ IMAGNAME = F$GETJPI(PID,"IMAGNAME") (4) $ IMAGNAME = F$PARSE(IMAGNAME,,,"NAME","SYNTAX_ONLY") $ ! $ ! Get terminal name. If none, then describe type of process. $ ! $ TERMINAL = F$GETJPI(PID,"TERMINAL") (5) $ IF TERMINAL .EQS. "" THEN - TERMINAL = "-"+F$EXTRACT(0,3,F$GETJPI(PID,"MODE"))+"-" $ IF TERMINAL .EQS. "-INT-" THEN TERMINAL = "-DET-" $ IF F$GETJPI(PID,"OWNER") .NE. 0 THEN TERMINAL = "-SUB-" $ ! $ ! Get more information, put process line together, $ ! and output it. $ ! $ LINE = F$FAO("!AS !12AS !7AS !15AS !5AS !2UL/!UL !10AS", - (6) PID,F$GETJPI(PID,"USERNAME"),TERMINAL,- F$GETJPI(PID,"PRCNAM"),- F$GETJPI(PID,"STATE"),F$GETJPI(PID,"PRI"),- F$GETJPI(PID,"PRIB"),IMAGNAME) $ WRITE SYS$OUTPUT LINE $ GOTO LOOP $ ! $ ! Restore verification and exit. $ ! $DONE: $ SAVE_VERIFY_PROCEDURE = F$VERIFY(SAVE_VERIFY_PROCEDURE,SAVE_VERIFY_IMAGE) $ EXIT |
Notes for SYS.COM Command Procedure
Previous | Next | Contents | Index |
privacy and legal statement | ||
6489PRO_047.HTML |