HP OpenVMS Systems Documentation |
OpenVMS 用户手册
附录 B
|
$ ! 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 |
hh:mm |
IF 命令检查:(1) 输入值的长度是 5
个字符,和 (2) 第三个字符 (偏移 2) 是冒号。IF 命令包含逻辑 OR 运算符: 如果任意一个表达式为真 (即,如果长度不是 5 或者如果在第三个字符位置没有冒号),那么过程分支到标号
BADTIME。
$ SHOW TIME 10-JUN-1999 10:38:26 $ @CONVERT 12:00 SHOW WAIT_TIME = "1:22:00.00" |
SHOW TIME 命令显示当前日期和时间。CONVERT.COM 以参数 12:00 和 SHOW 执行。过程把绝对时间 12:00 转换为相对时间值,并显示在终端上。B.2 REMINDER.COM 命令过程
这个命令过程于指定时间在终端上显示提示消息。过程提示想要显示消息的时间和消息文本。过程使用 CONVERT.COM 把时间转换为相对时间。然后,过程派生一个子进程等待指定时间后显示提示消息。过程说明如何使用 F$ENVIRONMENT、F$VERIFY 和 F$GETDVI 函数。
$ ! 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 |
$ @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 |
过程提示输入时间值和消息。然后,过程派生一个显示消息的子进程。可以继续在您的终端上工作;在指定的时间,子进程响起终端的铃声,显示消息和时间。B.3 DIR.COM 命令过程
这个命令过程模仿 DCL 命令 DIRECTORY/SIZE=ALL/DATE,显示指定文件的块大小 (已使用和已分配) 和建立日期。它说明如何使用 F$PARSE、F$SEARCH、F$FILE_ATTRIBUTES 和 F$FAO 词法函数。
$ ! $ ! 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 |
$ @DIR [VERN]*.COM |
目录 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) 共 15 文件, 22/48 块。 |
过程返回在目录 [VERN] 中的所有 .COM 文件的信息。
B.4 SYS.COM 命令过程
这个命令过程返回有关当前进程、组中所有进程 (如果当前进程有组特权) 和系统中所有进程 (如果当前进程有全体用户特权) 的统计信息。这个过程说明如何使用 F$PID、F$EXTRACT 和 F$GETJPI 词法函数 。
$ ! $ ! 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 |
前页 | 后页 | 目录 | 索引 |