[an error occurred while processing this directive]
Software  >  OpenVMS Systems > Documentation > 731final > 6489 > hanzi

HP OpenVMS Systems Documentation

Content starts here

OpenVMS �û��ֲ�


ǰҳ Ŀ¼ ����

B.9 LISTER.COM �������

��ʾ�������ݣ����и�ʽ�����ݣ���������������ļ����������˵�����ʹ�� READ �� WRITE ����Լ���ֵ�����ַ��Ӵ����Ǹ�ʽ��

����: LISTER.COM


$ ! 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

LISTER.COM ���������ע��

  1. LISTER.COM ���浱ǰУ�����ò�ͣ��У�顣
  2. OPEN ����Ϊд�뽨����ʱ�ļ���
  3. INQUIRE ������ʾ�������Ա�����ļ��������ͨ������ Return ����һ����������Ӧ INQUIRE �������ʾ����ô���̼ٶ�û�������������룬����ת�Ƶ���� FINISHED��
  4. �ڸ�ֵ������ NAME �� FILE ֮�󣬹���ʹ�ø�ֵ�����ַ������Ǹ�ʽ��������� RECORD ��ֵ���� RECORD ���� 1 �� 21��д�� NAME �ĵ�ǰֵ��������ͳ����ÿո���� NAME ��ֵʹ�䳤��Ϊָ���� 20 ���ַ���
    ͬ����RECORD �ĺ� 20 �����Ϊ FILE ��ֵ��Ȼ�󣬰� RECORD ��ֵд������ļ���
  5. ���ļ��ر�֮�󣬹�����������ļ� DATA.TMP��DEFINE ����ָʾ SORT ������������ļ� NL��������Щͳ�ƽ���ʾ���ն���:
    ����ִ����ǰ 20 �У�����������Ա������
    ��������������� DOC.SRT��
  6. ����ʹ�� OPEN ��������յ�����ļ� DOCUMENT.DAT��д���ļ��ĵ�һ���DZ����У��������⡢��������ں�ʱ����б��⡣
  7. ���̹ر��ļ� DOCUMENT.DAT���������������ļ� DOC.SRT ���ӵ�����ļ���Ȼ������ļ��Ŷӵ�ϵͳ��ӡ����
  8. ������ʾȷ���Ƿ�ɾ���м��ļ�������� INQUIRE ������ʾ��������ش� (T��t��Y �� y)����ô��ɾ���ļ� DATA.TMP �� DOC.SRT�����򣬱������ǡ�

ִ�� LISTER.COM ������̵�����


$ @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-1999 16:18:58.79

Programmer Name      File Name

ANDERSON             JUNK.J
JENKINS              MARIGOLD.DAT
MASON                SYSTEM.SRC
WATERS               CRYSTAL.CAV

B.10 CALC.COM �������

ִ���������㣬���ѽ��ֵת��Ϊʮ�����ƺ�ʮ����ֵ��

����: CALC.COM


$ ! 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

CALC.COM ���������ע��

  1. ���̽���һ�������������̵ij��������������������һ�����������صij�������ô����ת�Ƶ��������� ON �����Ŀ�ʼ�㡣
    ����û�����һ������ı���ʽ����ô�������ȷ�����̽������˳���
  2. INQUIRE ������ʾ������������ʽ�����̽��ܵı���ʽ��ʽ����:

    name = expression


    expression


    ������� Return����ô���̼ٶ����� CALC �Ի��ڲ��˳���
    �������ʽ "name = expression" ���룬��ô���̽��ڱ�� STATEMENT ����ִ�С����򣬹���ת�Ƶ���� EXPRESSION��

  3. ����ִ�и�ֵ��䣬���ѱ���ʽ�Ľ����ֵ�����š�Ȼ����̳�ȡ�����������ѷ��ŵ�ֵ��ֵ�� Q�����������ڹ��̵���һ��ѭ����ʹ�� Q �����ķ��š�Ȼ�󣬹�����ʾ�����ת�ƻر�� START��
  4. ���������ʽ��ֵ�����ѽ����ֵ������ Q�����������ڹ��̵���һ��ѭ����ʹ�� Q��Ȼ�󣬹�����ʾ�����ת�ƻر�� START��

ִ�� CALC.COM ������̵�����


$ @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]
$

�ڹ��̵�ÿ����ʾ֮���û�����һ����������ʽ�����̰�ʮ���ơ�ʮ�����ƺͰ˽��Ƹ�ʽ��ʾ�����ͨ������ Return ����һ�в������ݵĿ��У����� CALC �Ի��ڡ�

B.11 BATCH.COM �������

����һ�������ַ�����������̻�һ�����Ȼ����������ҵģʽִ����Щ���

����: BATCH.COM


$ 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

BATCH.COM ���������ע��

  1. ��� IF ������ BATCH.COM �Ƿ�ִ��������ģʽ�¡��������ص��� BATCH.COM ʱ�����ṩ (��Ϊ����) һ��Ҫִ��Ϊһ��������ҵ�������ַ�����������̡�������ṩ�κβ�������ô BATCH.COM ��ʾ�����������Щ����д��һ���ļ���Ȼ�������������ִ��Ϊһ��������ҵ���� BATCH.COM ׼��ִ��������ҵ������֮����ʹ�� SUBMIT ����ѱ����ύΪһ��������ҵ����ִ�������ҵ�е����(�����ע�� 8��) ���� BATCH.COM ����Ϊһ��������ҵʱ������ת�Ƶ���� EXECUTE_BATCH_JOB��ע�⣬���������ģʽִ�� BATCH.COM�������Ҫִ�е�������������ָ��Ϊ P1����Ĭ��Ŀ¼ָ��Ϊ P2��
  2. ��Щ����׼�� Ҫִ�е�������ҵ�����ȣ����̹���������ҵ�����������һ�������ַ�������ô BATCH.COM ʹ���䶯��������Ϊ��ҵ�����������һ��������̣���ô BATCH.COM ʹ�����ļ��������û�д��ݵ����룬��ô BATCH.COM �������ҵ����Ϊ BATCH��
  3. ������Щ���������γ�Ҫִ�е������ַ�������������ַ������������ COMMAND��
  4. SUBMIT ����ܴ��ݴ��� 255 ���ַ��IJ�������ˣ����̲��������ַ�����Ŀ¼��������С�� 255 ���ַ��ġ���������ַ�����С�� 255 ���ַ� (��������û�ȷʵ������һ�������ַ���)����ô����ת�Ƶ���� SUBMIT��
  5. ���̽���һ�� Ctrl/Y �����������������������������û����� Ctrl/Y����ִ�����������
  6. ���̽���һ����ʱ�ļ�����Ҫִ�е��������û��ṩһ�����������ַ�������ô����ת�Ƶ� WRITE_LARGE_COMMAND�������������д����ʱ�ļ������򣬹�����ʾ����Ҫִ�е����ÿ�����д����ʱ�ļ���
  7. �ڹر���ʱ�ļ�֮ǰ���ѷ��Ÿ�ֵ���д������ļ������������ʱ�ļ����ļ�����ֵ������ BATCH$DELETE_FILESPEC���ڹر������ʱ�ļ�֮�󣬹�����������Ĭ�ϵ� Ctrl/Y ��������Ȼ����̶������ COMMAND���Ա�ִ��ʱ������ COMMAND ������ʱ�������ļ���
  8. ���̰ѱ����ύΪһ��������ҵ��ʹ�ö������ҵ����(�����ע�� 2��) ����Ҳ������������: Ҫִ�е������������̣�������Ӧ�ôӴ�ִ�е�Ŀ¼��Ȼ�����ת�Ƶ���� EXIT��(�����ע�� 11��)
  9. ����ʱ�ļ�����ʱ������û����� Ctrl/Y�����ξ�ִ�����������
  10. ������ܽ�����ʱ�ļ������ξ�д�������Ϣ��
  11. ������������ԭʼ��У�����ã�Ȼ���˳���
  12. �� BATCH.COM ������ģʽ����ʱ����ִ����Щ������ȣ����� ON �������������������û���Ĭ��У�����á�Ȼ����Ĭ������Ϊ P2 ָ����Ŀ¼������ִ�� P1 ָ���������������̡��������һ����ʱ�ļ�����ô��ɾ������ļ�����ɾ�� BATCH$DELETE_FILESPEC ֮ǰ������ P1 �����״̬��������״̬ͨ�� EXIT ����ء�

ִ�� BATCH.COM ������̵�����


$ @BATCH RUN MYPROG
Job RUN (queue SYS$BATCH, entry 1715) started on SYS$BATCH

�������ʹ�� BATCH.COM ����������ҵ�еij���

B.12 COMPILE_FILE.COM �������

���롢���Ӻ������� Pascal �� FORTRAN ��д���ļ�������ʾ����Ҫ�������ļ���ȷ���ļ������� .PAS ���� .FOR������ļ����Ͳ��� .PAS �� .FOR����������ڵ�ǰĬ��Ŀ¼�в���������ļ�����ô�����������ʵ��ij�����Ϣ���������˵�����ʹ�� IF-THEN-ELSE ���Թ��졣

����: COMPILE_FILE.COM


$! 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 ���������ע��

  1. IF ����ʹ�� F$SEARCH �ʷ���������Ŀ¼������ȷ������ļ��Ƿ���ڡ�
  2. ���� THEN ����������:
    • ʹ�� F$LENGTH �ʷ�����ȷ���ļ����͵ij���
    • ȷ���ļ�����
    • ��ȥ�ļ������еľ�� 
    • ��ȥ�ļ�˵���е��ļ�������ȷ���ļ���
    • ��ȥ�ļ����еľ�� 
    • �����������������ִ�еĶ��� 
    • ת�Ƶ����� FILE_TYPE ����ı��
  3. ����� "File to process:" ��ʾ��������ļ���Ŀ¼�в����ڣ���ôִ�и��� ELSE ��������
  4. ENDIF ������� IF-THEN-ELSE �������Թ��졣
  5. ���̱������ FORTRAN ���򣬲�ת�Ƶ� LINK ��š�����ڱ����ڼ������������ô����ת�Ƶ� PRINT ��š�
  6. ������ʾ������ȷ���룬���Ӻ����г��򣬲�ת�Ƶ� CLEANUP ��š�������������������ת�Ƶ� END ��š�
  7. ���̰ѳ�����г��ļ�����Ĭ�ϴ�ӡ���С�

ִ�� COMPILE_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]


ǰҳ ��ҳ Ŀ¼ ����