[ 前のページ ]
[ 次のページ ]
[ 目次 ]
[ 索引 ]
[ DOC Home ]
ここでは,第15章,第16 章,および第17章で説明した概念と手法について実際のコマンド・ プロシージャを示しながら説明します。1つの節で1 つのコマンド・プロシージャを解説します。コマンド・プロシージャごとに次の内容を示します。
このコマンド・プロシージャは,(これ以降の時間の)絶対時刻をデルタ時間に変換し, 現在の時刻とユーザが指定した時刻との差を示します。このプロシージャは,F$TIME とF$CVTIMEレキシカル関数の使用方法と,割り当て文を使用して算術計算を行ったりシンボル値を連結する方法を示します。
$ ! 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
プロシージャは,F$ENVIRONMENT関数を使用して現在のメッセージ設定値をセーブしてから, 警告メッセージやエラー・メッセージが表示されないようにメッセージ形式を設定する。 時間値をチェックしたら,省略時のON 状態とメッセージ形式を復元する。
hh:mm
IFコマンドは,(1)入力された値の長さが5文字であるかどうか,(2) 3番目の文字( オフセット2)がコロンであるかどうかをチェックする。IFコマンドには論理OR 演算子が含まれているため,いずれかの式が真の場合(すなわち, 値の長さが5文字でないか,3番目の文字の位置にコロンがない場合) には,プロシージャはBADTIMEラベルに分岐する。
プロシージャは,EXITコマンドでエラー状態を明示的に指定するため,ユーザは別のプロシージャの中からCONVERT.COM を実行できる。CONVERT.COM が完了すると,呼び出し側プロシージャは時間が正しく変換されたかどうかを判別できる。
$ SHOW TIME 10-JUN-1996 10:38:26 $ @CONVERT 12:00 SHOW WAIT_TIME = "1:22:00.00"
SHOW TIMEコマンドは,現在の日時を表示します。CONVERT.COMはパラメータ12:00 とSHOWを指定して実行されます。プロシージャは,絶対時刻12:00 をデルタ値に変換して,それをターミナルに表示します。
所定の時間にターミナルに催促メッセージを表示します。このプロシージャは, メッセージを表示したい時間とメッセージのテキストを求めるプロンプトを出し,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
CONVERT.COMは,催促をデルタ時間に変換して,この時間をグローバル・ シンボルWAIT_TIMEに戻す。このデルタ時間は,現在の時間からメッセージを送信する時間までの時間間隔を示している。CONVERT.COM がエラーを戻す場合は, プロシージャはBADTIMEラベルに分岐する。
これらのシンボルを定義した後,ターミナルに3行を書き込む。1行目は, ベルを鳴らし,点滅文字をオンにしてから,メッセージの上半分を( ダブルサイズ文字を使用して)表示する。2行目は,ベルをもう一度鳴らし, メッセージの下半分を表示する。3行目は,現在の時間を書き込んで, 点滅属性をオフにしてターミナルを通常の状態に戻す。
DEC_CRTターミナルがない場合には,ターミナル・ベルを鳴らし,ユーザからのメッセージと時間を表示する。
省略時の設定では,SPAWNコマンドは,グローバル・シンボルとローカル・ シンボルを1つのサブプロセスに渡す。したがって,ユーザがREMINDER にシンボルWAIT_TIMEとMESSAGE_TEXTの値を与えるが, WAKEUP.COMもこの2つのシンボルにアクセスできる。
$ @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-1996 12:00:56.99
時間値とメッセージを求めるプロンプトを出します。次に,メッセージを表示するサブプロセスを生成します。 ユーザがターミナルで作業を継続していても, サブプロセスは,指定された時間になると,ターミナル・ベルを鳴らしたり, ユーザのメッセージを表示したり,時間を表示したりします。
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
Directory DISK4:[VERN] BATCH.COM;1 1/3 11-DEC-1996 11:43 CALC.COM;3 1/3 11-DEC-1996 11:30 CONVERT.COM;1 5/6 11-DEC-1996 15:23 . . . LOGIN.COM;34 2/3 11-DEC-1996 13:17 PID.COM;7 1/3 11-DEC-1996 09:49 SCRATCH.COM;6 1/3 11-DEC-1996 11:29) Total of 15 files, 22/48 blocks.
このプロシージャは,[VERN]ディレクトリのすべてのCOMファイルに関する情報を戻します。
現在のプロセス,グループ内のすべてのプロセス(現在のプロセスがgroup 特権を持つ場合),およびシステム上のすべてのプロセス(現在のプロセスがworld 特権を持つ場合)についての統計情報を戻します。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
$ @SYS
PID Username Term Process name State Pri Image 00050011 NETNONPRIV -NET- MAIL_14411 LEF 9/4 MAIL 00040013 STOVE RTA6: STOVE LEF 9/4 00140015 MAROT -DET- DMFB0ACP HIB 9/8 F11BAC 00080016 THOMPSON -DET- MTA0ACP HIB 12/8 MTAAACP 00070017 JUHLES TTF1: JUHLES LEF 9/4 . . . 00040018 MARCO TTA2: MARCO HIB 9/4 RTPAD 0018001A VERN RTA3: VERN LEF 9/4 0033001B YISHA RTA7: YISHA CUR 4/4 0002004A SYSTEM -DET- ERRFMT HIB 12/7 ERRFMT
このプロシージャは,システム上のすべてのプロセスに関する情報を戻します。 現在のプロセスはworld特権を持っています。
このコマンド・プロシージャは,プロシージャに渡すパラメータの数を戻します。 別のプロシージャからGETPARMS.COMを呼び出せば,呼び出し側プロシージャに渡されたパラメータの数を判別できます。
$ ! Procedure to count the number of parameters passed to a command $ ! procedure. This number is returned as the global symbol PARMCOUNT. $ ! $ SAVE_VERIFY_IMAGE = F$ENVIRONMENT("VERIFY_IMAGE") 【1】 $ SAVE_VERIFY_PROCEDURE = F$VERIFY(0) $ ! $ IF P1 .EQS. "?" THEN GOTO TELL 【2】 $ ! $ ! Loop to count the number of parameters passed. Null parameters are $ ! counted until the last non-null parameter is passed. $ ! $ COUNT = 0 【3】 $ LASTNONNULL = 0 $ LOOP: $ IF COUNT .EQ. 8 THEN GOTO END_COUNT $ COUNT = COUNT + 1 $ IF P'COUNT' .NES. "" THEN LASTNONNULL = COUNT $ GOTO LOOP $ ! $ END_COUNT: 【4】 $ ! $ ! Place the number of non-null parameters passed into PARMCOUNT. $ ! $ PARMCOUNT == LASTNONNULL $ ! $ ! Restore verification setting, if it was on, before exiting $ ! 【5】 $ SAVE_VERIFY_PROCEDURE = F$VERIFY(SAVE_VERIFY_PROCEDURE,SAVE_VERIFY_IMAGE) $ EXIT $ ! $ TELL: 【6】 $ TYPE SYS$INPUT This procedure counts the number of parameters passed to another procedure. This procedure can be called by entering the following string in any procedure: @GETPARMS 'P1 'P2 'P3 'P4 'P5 'P6 'P7 'P8 On return, the global symbol PARMCOUNT contains the number of parameters passed to the procedure. $ ! $ EXIT
IFコマンドを実行するたびに,COUNTシンボルは異なる値を持つ。1回目は,COUNT の値は1で,IFコマンドはP1をチェックし,2回目は,P2をチェックし, 以下も同様である。
SORTFILES.COMプロシージャは,3つの空以外のパラメータを渡すようにユーザに要求します。SORTFILES.COM プロシージャには,次の行が入っています。
$ @GETPARMS 'P1' 'P2' 'P3' 'P4' 'P5' 'P6' 'P7' 'P8' $ IF PARMCOUNT .NE. 3 THEN GOTO NOT_ENOUGH . . . $NOT_ENOUGH: $ WRITE SYS$OUTPUT - "Three non-null parameters required. Type SORTFILES HELP for info." $ EXIT
SORTFILES.COMプロシージャは,次のようにして起動できます。
$ @SORTFILES DEF 4 Three non-null parameters required. Type SORTFILE HELP for info.
このプロシージャを正しく起動するには,すなわち,SORTFILESに渡されたパラメータをそのままGETPARMS に渡して処理するには,シンボルP1〜P8 が1組の二重引用符で囲まれていなくてはなりません。
GETPARMSからの戻り値が3でない場合には,SORTFILESはエラー・メッセージを出力して終了します。
EDTエディタを繰り返し起動して,同じファイル・タイプを持つファイルのグループを編集します。 このプロシージャは,レキシカル関数を使用して出力からファイル名を取り出す方法を示しています。 また,コマンド・ プロシージャの中で起動されたプログラムの入力ストリームを再定義する方法も示しています。
$ ! Procedure to edit all files in a directory with a $ ! specified file type. Use P1 to indicate the file type. $ ! $ ON CONTROL_Y THEN GOTO DONE ! Ctrl/Y action 【1】 $ ON ERROR THEN GOTO DONE $ ! $ ! Check for file type parameter. If one was entered, continue; $ ! otherwise, prompt for a parameter. $ ! $ IF P1 .NES. "" THEN GOTO OKAY 【2】 $ INQUIRE P1 "Enter file type of files to edit" $ ! $ ! List all files with the specified file type and write the DIRECTORY $ ! output to a file named DIRECT.OUT $ ! $ OKAY: $ DIRECTORY/VERSIONS=1/COLUMNS=1 - 【3】 /NODATE/NOSIZE - /NOHEADING/NOTRAILING - /OUTPUT=DIRECT.OUT *.'P1' $ IF .NOT. $STATUS THEN GOTO ERROR_SEC 【4】 $ ! $ OPEN/READ/ERROR=ERROR_SEC DIRFILE DIRECT.OUT 【5】 $ ! $ ! Loop to read directory file $ ! $ NEWLINE: 【6】 $ READ/END=DONE DIRFILE NAME $ DEFINE/USER_MODE SYS$INPUT SYS$COMMAND: ! Redefine SYS$INPUT $ EDIT 'NAME' ! Edit the file $ GOTO NEWLINE $ ! $ DONE: 【7】 $ CLOSE DIRFILE/ERROR=NOTOPEN ! Close the file $ NOTOPEN: $ DELETE DIRECT.OUT;* ! Delete temp file $ EXIT $ ! $ ERROR_SEC: $ WRITE SYS$OUTPUT "Error: ",F$MESSAGE($STATUS) $ DELETE DIRECT.OUT;* $ EXIT
CLOSEコマンドは,DIRECTORYコマンドの出力ファイルをクローズし, /ERROR修飾子はファイルの中の次の行のラベルを指定する。このように/ERROR 修飾子を使用すると,ディレクトリ・ファイルがオープンされていないときに表示されるはずのエラー・ メッセージが出されなくなる。このような状況は, ディレクトリ・ファイルをオープンする前に Ctrl/Yを押した場合などに生じる。
クリーンアップ処理の2番目のステップは,一時ディレクトリ・ファイルを削除することである。
$ @EDITALL DAT * . . . %DELETE-I-FILDEL, device:[directory]DIRECT.OUT;1 deleted (x blocks)
EDITALLプロシージャがDATとして指定されたP1によって起動されます。このプロシージャは, 省略時のディレクトリにあるファイル・タイプDATを持つすべてのファイルのディレクトリ・ リストを作成し,エディタを起動してそれぞれのファイルを編集します。 ファイル・タイプDATを持つ最後のファイルを編集し終わると, 一時ファイルDIRECT.OUTを削除して,ターミナルにメッセージを表示します。
このコマンド・プロシージャは,MAILユーティリティでテキスト・エディタを起動しています。
$ ! Command procedure to invoke an editor for Mail. $ ! $ ! Inputs: $ ! $ ! P1 = Input file name. $ ! P2 = Output file name. $ ! $ ! If MAIL$EDIT is undefined, Mail will invoke the user's selected $ ! callable editor set by the mail SET EDITOR command. $ ! $ ! If MAIL$EDIT is defined to be a command procedure, Mail will create $ ! a subprocess to edit the mail, but any SET EDITOR command in Mail $ ! will override the definition of MAIL$EDIT for the remainder of that $ ! Mail session. $ ! $ ! Note that this procedure is run in the context of a subprocess. $ ! LOGIN.COM is not executed. However, all process logical names $ ! and DCL global symbols are copied. In particular, note that the $ ! user's individual definition of the symbol EDIT is used if there $ ! is one. Otherwise, the system default editor is used. $ ! $ ! The default directory is the same as the parent process $ ! $ DEFINE /USER SYS$INPUT 'F$TRNLNM("SYS$OUTPUT")' 【1】 $ IF P1 .EQS. "" THEN GOTO NOINPUT 【2】 $ EDIT /OUTPUT='P2' 'P1' 【3】 $ EXIT $NOINPUT: $ EDIT 'P2' 【4】 $ EXIT
$ RUN XYZ_EDITOR.EXE /INPUT= 'P1' /OUTPUT='P2'
$ RUN XYZ_EDITOR.EXE /INPUT= 'P2' /OUTPUT='P2'
$DEFINE MAIL$EDIT MAILEDIT.COM $MAIL MAIL> SHOW EDITOR Your editor is defined by the file MAILEDIT.COM.
FORTRANプログラムの作成,コンパイル,実行を行う会話型ユーザの,ターミナル環境を制御するシステム定義のログイン・ コマンド・プロシージャのサンプルを示します。FORTUSER.COM が,ログイン・コマンド・プロシージャとしてリストされる専用アカウントにログインした場合は, FORTUSER.COMが受け入れるコマンドしか実行できません。このプロシージャは, レキシカル関数を使用してオプション・テーブルを参照し,ユーザが入力したコマンドと有効なコマンドのリストとを比較する方法も示しています。
$ ! Procedure to create, compile, link, execute, and debug $ ! FORTRAN programs. Users can enter only the commands listed $ ! in the symbol OPTION_TABLE. $ SET NOCONTROL=Y 【1】 $ SAVE_VERIFY_IMAGE = F$ENVIRONMENT("VERIFY_IMAGE") $ SAVE_VERIFY_PROCEDURE = F$VERIFY(0) $ OPTION_TABLE = "EDIT/COMPILE/LINK/RUN/EXECUTE/DEBUG/PRINT/HELP/FILE/DONE/" 【2】 $ TYPE SYS$INPUT 【3】 VMS FORTRAN Command Interpreter Enter name of file with which you would like to work. $ ! $ ! Set up for initial prompt $ ! $ PROMPT = "INIT" 【4】 $ GOTO HELP ! Print the initial help message $ ! $ ! after the first prompting message, use the prompt: Command $ ! $ INIT: $ PROMPT = "GET_COMMAND" $ GOTO FILE ! Get initial file name $ ! $ ! Main command parsing routine. The routine compares the current $ ! command against the options in the option table. When it finds $ ! a match, it branches to the appropriate label. $ ! $ GET_COMMAND: $ ON CONTROL_Y THEN GOTO GET_COMMAND ! Ctrl/Y resets prompt 【5】 $ SET CONTROL=Y $ ON WARNING THEN GOTO GET_COMMAND ! If any, reset prompt $ INQUIRE COMMAND "Command" $ IF COMMAND .EQS. "" THEN GOTO GET_COMMAND $ IF F$LOCATE(COMMAND + "/", OPTION_TABLE) .EQ. F$LENGTH(OPTION_TABLE) - 【6】 THEN GOTO INVALID_COMMAND $ GOTO 'COMMAND' $ ! $ INVALID_COMMAND: 【7】 $ WRITE SYS$OUTPUT " Invalid command" $ ! $ HELP: 【8】 $ TYPE SYS$INPUT The commands you can enter are: FILE Name of FORTRAN program in your current default directory. Subsequent commands process this file. EDIT Edit the program. COMPILE Compile the program with FORTRAN. LINK Link the program to produce an executable image. RUN Run the program's executable image. EXECUTE Same function as COMPILE, LINK, and RUN. DEBUG Run the program under control of the debugger. PRINT Queue the most recent listing file for printing. DONE Return to interactive command level. HELP Print this help message. Enter Ctrl/Y to restart this session $ GOTO 'PROMPT' 【9】 $ EDIT: 【10】 $ DEFINE/USER_MODE SYS$INPUT SYS$COMMAND: $ EDIT 'FILE_NAME'.FOR $ GOTO GET_COMMAND $ COMPILE: $ FORTRAN 'FILE_NAME'/LIST/OBJECT/DEBUG $ GOTO GET_COMMAND $ LINK: $ LINK 'FILE_NAME'/DEBUG $ PURGE 'FILE_NAME'.*/KEEP=2 $ GOTO GET_COMMAND $ RUN: $ DEFINE/USER_MODE SYS$INPUT SYS$COMMAND: $ RUN/NODEBUG 'FILE_NAME' $ GOTO GET_COMMAND $ DEBUG: $ DEFINE/USER_MODE SYS$INPUT SYS$COMMAND: $ RUN 'FILE_NAME' $ GOTO GET_COMMAND $ EXECUTE: $ FORTRAN 'FILE_NAME'/LIST/OBJECT $ LINK/DEBUG 'FILE_NAME' $ PURGE 'FILE_NAME'.*/KEEP=2 $ RUN/NODEBUG 'FILE_NAME' $ GOTO GET_COMMAND $ PRINT: $ PRINT 'FILE_NAME' $ GOTO GET_COMMAND $ BADFILE: 【11】 $ WRITE SYS$OUTPUT "File must be in current default directory." $ FILE: $ INQUIRE FILE_NAME "File name" $ IF FILE_NAME .EQS. "" THEN GOTO FILE $ IF F$PARSE(FILE_NAME,,,"DIRECTORY") .NES. F$DIRECTORY() - 【12】 THEN GOTO BADFILE $ FILE_NAME = F$PARSE(FILE_NAME,,,"NAME") $ GOTO GET_COMMAND $ DONE: $ EXIT
この例は,このコマンド・プロシージャを専用コマンド・プロシージャとして使用する方法を示しています。
Username: CLASS30 Password: OpenVMS Version 7.1 OpenVMS FORTRAN Command Interpreter Enter name of file with which you would like to work. The commands you can enter are: FILE Name of FORTRAN program in your current default directory. Subsequent commands process this file. EDIT Edit the program. COMPILE Compile the program with VAX FORTRAN. LINK Link the program to produce an executable image. RUN Run the program's executable image. EXECUTE Same function as COMPILE, LINK and RUN. DEBUG Run the program under control of the debugger. PRINT Queue the most recent listing file for printing. DONE Return to interactive command level. HELP Print this help message. Enter Ctrl/Y to restart this session File name: AVERAGE Command: COMPILE Command: LINK Command: RUN Command: FILE File name: READFILE Command: EDIT
このサンプル実行は,CLASS30というユーザがFORTUSERコマンド・プロシージャによって制御されるアカウントにログインするときのセッションを示しています。FORTUSER コマンド・プロシージャは,ユーザが実行できるコマンドと, セッションを再開するための命令を表示します。次に,ユーザがAVERAGE ファイルを指定して,それをコンパイル,リンク,実行します。 この後,ユーザはFILEコマンドを入力して,別のファイルで作業を開始します。
入力データを求めるプロンプトを出し,データを桁揃えしてからソートし, 出力ファイルに書き込みます。このプロシージャは,READとWRITEコマンドとともに, 割り当て文の部分文字列オーバレイ形式を示しています。
$ ! Procedure to accumulate programmer names and document file names. $ ! After all programmer names and file names are entered, they are $ ! sorted in alphabetic order by programmer name and printed on $ ! the system printer. $ ! $ SAVE_VERIFY_IMAGE = F$ENVIRONMENT("VERIFY_IMAGE") 【1】 $ SAVE_VERIFY_PROCEDURE = F$VERIFY(0) $ ! $ OPEN/WRITE OUTFILE DATA.TMP ! Create output file 【2】 $ ! $ ! Loop to obtain programmers' last names and file names, $ ! and write this data to DATA.TMP. $ ! $ LOOP: 【3】 $ INQUIRE NAME "Programmer (press Return to quit)" $ IF NAME .EQS. "" THEN GOTO FINISHED $ INQUIRE FILE "Document file name" $ RECORD[0,20]:='NAME' 【4】 $ RECORD[21,20]:='FILE' $ WRITE OUTFILE RECORD $ GOTO LOOP $ FINISHED: $ CLOSE OUTFILE $ ! $ DEFINE/USER_MODE SYS$OUTPUT: NL: ! Suppress sort output $ SORT/KEY=(POSITION:1,SIZE=20) DATA.TMP DOC.SRT 【5】 $ ! $ OPEN/WRITE OUTFILE DOCUMENT.DAT 【6】 $ WRITE OUTFILE "Programmer Files as of ",F$TIME() $ WRITE OUTFILE "" $ RECORD[0,20]:="Programmer Name" $ RECORD[21,20]:="File Name" $ WRITE OUTFILE RECORD $ WRITE OUTFILE "" $ ! $ CLOSE OUTFILE 【7】 $ APPEND DOC.SRT DOCUMENT.DAT $ PRINT DOCUMENT.DAT $ ! $ INQUIRE CLEAN_UP "Delete temporary files [Y,N]" 【8】 $ IF CLEAN_UP THEN DELETE DATA.TMP;*,DOC.SRT;* $ SAVE_VERIFY_PROCEDURE = F$VERIFY(SAVE_VERIFY_PROCEDURE,SAVE_VERIFY_IMAGE) $ EXIT
同様に,RECORDの次の20桁にFILEの値が埋め込まれると,RECORDの値が出力ファイルに書き込まれる。
ソート操作は,最初の20桁,すなわちプログラマ名によって実行される。
ソート済み出力ファイルには,DOC.SRTの名前が付けられる。
$ @LISTER Programmer: WATERS Document file name: CRYSTAL.CAV Programmer: JENKINS Document file name: MARIGOLD.DAT Programmer: MASON Document file name: SYSTEM.SRC Programmer: ANDERSON Document file name: JUNK.J Programmer: <Return> Delete temporary files [Y,N]:y
このプロシージャを実行して得られる出力ファイルは次のようになります。
Programmer Files as of 31-DEC-1996 16:18:58.79 Programmer Name File Name ANDERSON JUNK.J JENKINS MARIGOLD.DAT MASON SYSTEM.SRC WATERS CRYSTAL.CAV
算術計算を行い,その結果を16進値と10進値に変換します。
$ ! Procedure to calculate expressions. If you enter an $ ! assignment statement, then CALC.COM evaluates the expression $ ! and assigns the result to the symbol you specify. In the next $ ! iteration, you can use either your symbol or the symbol Q to $ ! represent the current result. $ ! $ ! If you enter an expression, then CALC.COM evaluates the $ ! expression and assigns the result to the symbol Q. In $ ! the next iteration, you can use the symbol Q to represent $ ! the current result. $ ! $ SAVE_VERIFY_IMAGE = F$ENVIRONMENT("VERIFY_IMAGE") $ SAVE_VERIFY_PROCEDURE = F$VERIFY(0) $ START: $ ON WARNING THEN GOTO START 【1】 $ INQUIRE STRING "Calc" 【2】 $ IF STRING .EQS. "" THEN GOTO CLEAN_UP $ IF F$LOCATE("=",STRING) .EQ. F$LENGTH(STRING) THEN GOTO EXPRESSION $ ! $ ! Execute if string is in the form symbol = expression $ STATEMENT: 【3】 $ 'STRING' ! Execute assignment statements $ SYMBOL = F$EXTRACT(0,F$LOCATE("=",STRING)-1,STRING) ! get symbol name $ Q = 'SYMBOL' ! Set up q for future iterations $ LINE = F$FAO("Decimal = !SL Hex = !-!XL Octal = !-!OL",Q) $ WRITE SYS$OUTPUT LINE $ GOTO START $ ! $ ! $ ! Execute if string is an expression $ EXPRESSION: 【4】 $ Q = F$INTEGER('STRING') ! Can use Q in next iteration $ LINE = F$FAO("Decimal = !SL Hex = !-!XL Octal = !-!OL",Q) $ WRITE SYS$OUTPUT LINE $ GOTO START $ ! $ CLEAN_UP: $ SAVE_VERIFY_PROCEDURE = F$VERIFY(SAVE_VERIFY_PROCEDURE,SAVE_VERIFY_IMAGE) $ EXIT
この方法を使用すると,ユーザが式を間違って入力してもプロシージャは終了しない。
名前=式
式
ユーザがReturnを押すと,プロシージャは,CALCセッションが終わったとみなして, 終了する。
ユーザが"名前=式"形式で入力した場合は,プロシージャはSTATEMENT ラベルで実行を継続し,そうでない場合は,EXPRESSIONラベルに分岐する。
$ @CALC Calc: 2 * 30 Decimal = 60 Hex = 0000003C Octal = 00000000074 Calc: Q + 3 Decimal = 63 Hex = 0000003F Octal = 00000000077 Calc: TOTAL = Q + 4 Decimal = 67 Hex = 00000043 Octal = 00000000103 Calc: 5 + 7 Decimal = 12 Hex = 0000000C Octal = 00000000014 Calc:<Return> $
プロシージャからのプロンプトの1つ1つに,ユーザは算術式を入力します。 プロシージャはその結果を10進数,16進数,8進数で表示します。データのない行でReturn を押しただけの空の行でCALCセッションは終わりです。
コマンド文字列,コマンド・プロシージャ,コマンドのリストのうちのいずれかを受け取って, バッチ・ジョブとして実行します。
$ VERIFY_IMAGE = F$ENVIRONMENT("VERIFY_IMAGE") $ VERIFY_PROCEDURE = F$VERIFY(0) $! $! Turn off verification and save current settings. $! (This comment must appear after you turn verification $! off; otherwise it will appear in the batch job log file.) $! $! $! If this is being executed as a batch job, $! (from the SUBMIT section below) go to the EXECUTE_BATCH_JOB section $! Otherwise, get the information you need to prepare to execute the $! batch job. $! $ IF F$MODE() .EQS. "BATCH" THEN GOTO EXECUTE_BATCH_JOB 【1】 $! $! $! Prepare to submit a command (or a command procedure) as a batch job. $! First, determine a mnemonic process name for the batch job. Use the $! following rules: $! $! 1) If the user is executing a single command, then use the verb name. $! Strip off any qualifiers that were included with the command. $! 2) If the user is executing a command procedure, then use the file name. $! 3) Otherwise, use BATCH. $! $ JOB_NAME = P1 【2】 $ IF JOB_NAME .EQS. "" THEN JOB_NAME = "BATCH" $ IF F$EXTRACT(0,1,JOB_NAME) .EQS. "@" THEN JOB_NAME = F$EXTRACT(1,999,JOB_NAME) $ JOB_NAME = F$EXTRACT(0,F$LOCATE("/",JOB_NAME),JOB_NAME) $ JOB_NAME = F$PARSE(JOB_NAME,,,"NAME","SYNTAX_ONLY") $ IF JOB_NAME .EQS. "" THEN JOB_NAME = "BATCH" $! $! $! Get the current default device and directory. $! $ ORIGDIR = F$ENVIRONMENT("DEFAULT") $! $! $! Concatenate the parameters to form the command string to be executed. $! If the user did not enter a command string, the symbol COMMAND will have $! a null value. $! $ COMMAND = P1 + " " + P2 + " " + P3 + " " + P4 + " " + - 【3】 P5 + " " + P6 + " " + P7 + " " + P8 $! $! $! If the user is executing a single command and if both the command and the $! original directory specification are small enough to be passed as $! parameters to the SUBMIT command, then submit the batch job now $! $ IF (P1 .NES. "") .AND. (F$LENGTH(COMMAND) .LE. 255) .AND. - 【4】 (F$LENGTH(ORIGDIR) .LE. 255) THEN GOTO SUBMIT $! $! $! If the single command to be executed in the batch job is very large, or $! if you have to prompt for commands to execute in the batch job, then $! create a temporary command procedure to hold those commands and get the $! fully expanded name of the command procedure. $! $ CREATE_TEMP_FILE: $ ON CONTROL_Y THEN GOTO CONTROL_Y_HANDLER 【5】 $ OPEN/WRITE/ERROR=FILE_OPEN_ERROR TEMPFILE SYS$SCRATCH:'JOB_NAME'.TMP 【6】 $ FILESPEC = F$SEARCH("SYS$SCRATCH:" + JOB_NAME + ".TMP") $! $! By default, have the batch job continue if it encounters any errors. $! $ WRITE TEMPFILE "$ SET NOON" $! $! Either write the single large command to the file, or prompt for $! multiple commands and write them to the file. $! $ IF COMMAND .NES. " " THEN GOTO WRITE_LARGE_COMMAND $ $ LOOP: $ READ /END_OF_FILE=CLOSE_FILE /PROMPT="Command: " SYS$COMMAND COMMAND $ IF COMMAND .EQS. "" THEN GOTO CLOSE_FILE $ WRITE TEMPFILE "$ ",COMMAND $ GOTO LOOP $ $ WRITE_LARGE_COMMAND: $ WRITE TEMPFILE "$ ",COMMAND $ $! $! Finish the temporary file by defining a symbol so that you will know $! the name of the command procedure to delete and then close the file. $! Define the symbol COMMAND to mean "execute the command procedure $! you have just created". Then submit the batch job and execute $! this command procedure in the batch job. $! $ CLOSE_FILE: 【7】 $ WRITE TEMPFILE "$ BATCH$DELETE_FILESPEC == """,FILESPEC,"""" $ CLOSE TEMPFILE $ ON CONTROL_Y THEN EXIT $ COMMAND = "@" + FILESPEC $! $! $! Submit BATCH.COM as a batch job, and pass it two parameters. $! P1 is the command (or name of the command procedure) to execute. $! P2 is the directory from which to execute the command. $! $ SUBMIT: 【8】 $ SUBMIT/NOTIFY/NOPRINT 'F$ENVIRONMENT("PROCEDURE")' /NAME='JOB_NAME' - /PARAMETERS=("''COMMAND'","''ORIGDIR'") $ GOTO EXIT $! $! $! The user pressed Ctrl/Y while the temporary command procedure was open. $! Close the command procedure, delete it if it exists, and exit. $! $ CONTROL_Y_HANDLER: 【9】 $ CLOSE TEMPFILE $ IF F$TYPE(FILESPEC) .NES. "" THEN DELETE/NOLOG 'FILESPEC' $ WRITE SYS$OUTPUT "Ctrl/Y caused the command procedure to abort." $ GOTO EXIT $! $! $! The temporary command procedure could not be created. $! Notify the user and exit. $! $ FILE_OPEN_ERROR: 【10】 $ WRITE SYS$OUTPUT "Could not create sys$scratch:",job_name,".tmp" $ WRITE SYS$OUTPUT "Please correct the situation and try again." $! $! $! Restore the verification states and exit. $! $ EXIT: 【11】 $ VERIFY_PROCEDURE = F$VERIFY(VERIFY_PROCEDURE,VERIFY_IMAGE) $ EXIT $! $! $! BATCH.COM was invoked as a batch job. P1 contains the command $! to execute and P2 the default directory specification. $! Return a status code that indicates the termination status of P1. $! $ EXECUTE_BATCH_JOB: 【12】 $ SET NOON $ VERIFY_PROCEDURE = F$VERIFY(VERIFY_PROCEDURE,VERIFY_IMAGE) $ SET DEFAULT 'P2' $ 'P1' $ IF F$TYPE(BATCH$DELETE_FILESPEC) .EQS. "" THEN EXIT $STATUS $ STATUS = $STATUS $ DELETE /NOLOG 'BATCH$DELETE_FILESPEC' $ EXIT STATUS
バッチ・ジョブから1つまたは複数のコマンドを実行する準備が整うと, BATCH.COMはSUBMITコマンドを使用してBATCH.COM自体をバッチ・ジョブとしてキューに登録し, このジョブからコマンドを実行する(注8を参照)。 BATCH.COMをバッチ・ジョブとして起動した場合には,プロシージャはEXECUTE_BATCH_JOB ラベルに分岐する。BATCH.COMをバッチ・モードで実行するときには, 実行するコマンドまたはコマンド・プロシージャをP1として, 省略時のディレクトリをP2として指定しなければならない。
$ @BATCH RUN MYPROG Job RUN (queue SYS$BATCH, entry 1715) started on SYS$BATCH
この例は,BATCH.COMを使用して,バッチ・ジョブの中からプログラムを実行しています。
PASCALまたはFORTRANで書かれたファイルのコンパイル,リンク,実行を行います。 処理するファイルを求めるプロンプトを出し,ファイル・タイプがPAS かFORかを判別します。ファイル・タイプがPASでもFORでもない場合, またはファイルが現在の省略時のディレクトリに存在しない場合には, 該当するエラー・メッセージを出力します。このプロシージャは, IF-THEN-ELSE言語構成の使用方法を示しています。
$! This command procedure compiles, links, and runs a file written in Pascal $! or FORTRAN. $! $ ON CONTROL_Y THEN EXIT $! $ TOP: $ INQUIRE FILE "File to process" $ IF F$SEARCH(FILE) .NES. "" 【1】 $ THEN $ FILE_TYPE = F$PARSE(FILE,,,"TYPE") 【2】 ! determine file type $ FILE_TYPE = F$EXTRACT(1,F$LENGTH('FILE_TYPE'),FILE_TYPE) ! remove period $! Remove type from file specification $ PERIOD_LOC = F$LOCATE(".",FILE) $ FILE = F$EXTRACT(0,PERIOD_LOC,FILE) $ ON WARNING THEN GOTO OTHER $ GOTO 'FILE_TYPE' $ ELSE 【3】 $ WRITE SYS$OUTPUT FILE, "does not exist" $ ENDIF 【4】 $! $ GOTO END $! $! $! $ FOR: 【5】 $ ON ERROR THEN GOTO PRINT $ FORTRAN/LIST 'FILE' $ GOTO LINK $! $ PAS: $ ON ERROR THEN GOTO PRINT $ PASCAL/LIST 'FILE' $ GOTO LINK $! $ OTHER: $ WRITE SYS$OUTPUT "Can't handle files of type .''FILE_TYPE'" $ GOTO END $! $ LINK: 【6】 $ ON ERROR THEN GOTO END $ WRITE SYS$OUTPUT "Successful compilation ...." $ LINK 'FILE' $ DEFINE/USER_MODE SYS$INPUT SYS$COMMAND $ RUN 'FILE' $ GOTO CLEANUP $! $ PRINT: 【7】 $ WRITE SYS$OUTPUT "Unsuccessful compilation, printing listing file ...." $ PRINT 'FILE' $! $ CLEANUP: $ DELETE 'FILE'.OBJ; $ DELETE 'FILE'.LIS; $! $ END: $ INQUIRE/NOPUNCTUATION ANS "Process another file (Y or N)? " $ IF ANS THEN GOTO TOP $ EXIT
COMPILE_FILE.COMコマンド・プロシージャの説明
例: COMPLILE_FILE.COMコマンド・プロシージャの実行結果例
$ @COMPILE_FILE File to process: RAND.PAS Successful compilation %DELETE-I-FILDEL,WORK:[DESCH]RAND.OBJ;1 deleted (3 blocks) %DELETE-I-FILDEL,WORK:[DESCH]RAND.LIS;1 deleted (9 blocks) Process another file (Y or N)? N <Return>
[ 前のページ ]
[ 次のページ ]
[ 目次 ]
[ 索引 ]
[ DOC Home ]