[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
OpenVMS User's Manual
15.2.2 Changing Default File ProtectionYou may want to change the default file protection within a command procedure. The following command procedure changes the default protection associated with files created while the procedure is executing. The procedure restores the original default file protection before terminating.
Note that the F$ENVIRONMENT function returns the default protection
code using the syntax required by the SET PROTECTION command. This lets
you use the symbol SAVE_PROT with the SET PROTECTION command to restore
the original default file protection.
You can use the following lexical functions to obtain information about the system:
15.3.1 Determining Your OpenVMS Cluster Node NameIf your system is part of an OpenVMS Cluster environment where you can log in to many different nodes, you can set the DCL prompt to indicate which node you are currently using. To do this, include the F$GETSYI function in your login command procedure to determine the node name. Then use the SET PROMPT command to set a unique prompt for the node. If you want to use only a portion of the node name in your prompt string, use the F$EXTRACT function to extract the appropriate characters. See Section 15.6.2 for more information on extracting characters. In the following example, the symbol NODE is defined as FF$GETSYI("NODENAME") and then the node name is used as the prompt:
15.3.2 Obtaining Queue InformationYou can use the F$GETQUI function to get many types of information about batch and print queues. You must have read access to the job, SYSPRV privilege, or OPER privilege to obtain information about jobs and files in queues. The following example shows how to determine if the batch queue VAX1_BATCH is in a stopped state. The value returned is either true or false. If the queue is not stopped, the command procedure submits a job to the queue.
15.3.3 Obtaining Process InformationYou can use the F$PID function to get the process identification (PID) number for all processes that you are allowed to examine. You can obtain PID numbers:
After you obtain a PID number, you can use the F$GETJPI function to obtain specific information about the process. The following example shows how to obtain and display the PID numbers for the processes you are allowed to examine:
The system uses the symbol CONTEXT to hold a pointer into the system list of PID numbers. Each time through the loop, the system changes the pointer to locate the next PID number in the list. The procedure exits after all PID numbers have been displayed. In the following example, the procedure displays the PID number and the UIC for each process:
Note that you can shorten this command procedure by including the F$GETJPI function within the WRITE command, as follows:
15.3.4 F$CONTEXT Lexical FunctionTo obtain information about processes from any node in an OpenVMS Cluster system, use the F$CONTEXT function. In the following example, F$CONTEXT is called three times to set up selection criteria:
As you examine the example, note the following:
15.4 Obtaining Information About Files and DevicesYou can use the following lexical functions to obtain information about files and devices:
15.4.1 Searching for DevicesTo get information on a particular device by using the system service $GETDVI, you must provide the device name to the service. If you do not know the device name, you can find it by using the lexical function F$DEVICE. The F$DEVICE function allows wildcard searches based on the device name, the device class, or the device type. To do a search based on device type, you must also specify a device class. You can use the F$DEVICE function in a loop in a command procedure to return device names that match the specified selection criteria. Each time the F$DEVICE function is executed, it returns the next device on the system that matches the selection criteria. Note that devices are returned in no particular order. After the last device name is returned, the next F$DEVICE function call returns a null string. This command procedure displays the device names of all the RA60s on a unit numbered 0:
15.4.2 Searching for a File in a DirectoryBefore processing a file, a command procedure should use the F$SEARCH function to test whether the file exists. For example, the following command procedure uses F$PARSE to apply a device and directory string to the file STATS.DAT. Then the procedure uses the F$SEARCH function to determine whether STATS.DAT is present in DISK3:[JONES.WORK]. If it is, the command procedure processes the file. Otherwise, the command procedure prompts for another input file.
After determining that a file exists, the procedure can use the F$PARSE or the F$FILE_ATTRIBUTES function to get additional information about the file. For example:
15.4.3 Deleting Old Versions of FilesIf a command procedure creates files that you do not need after the procedure terminates, delete or purge these files before you exit from the procedure. Use the PURGE command to delete all versions except the most recent one. Use the DELETE command with a version number to delete a specific version of the file or with a wildcard character in the version field to delete all versions of the file. To avoid error messages when using the DELETE command within a command procedure, use the F$SEARCH function to verify that a file exists before you try to delete it. For example, you can write a command procedure that creates a file named TEMP.DAT only if certain modules are executed. The following line issues the DELETE command only if TEMP.DAT exists:
15.5 Translating Logical NamesYou can use the following lexical functions to translate logical names:
In some situations, you may want to use logical names rather than symbols as variables in command procedures. Programs can access logical names more easily than they can access DCL symbols. Therefore, to pass information to a program that you run from a command procedure, obtain the information using a symbol. Then use the DEFINE or ASSIGN command to equate the value of the symbol to a logical name. You can also use the F$TRNLNM function to determine the value of a logical name and then assign the value to a symbol. The following example tests whether the logical name NAMES has been defined. If it has, the procedure runs PAYROLL.EXE. Otherwise, the procedure obtains a value for the symbol FILE and uses this value to create the logical name NAMES. PAYROLL.EXE uses the logical name NAMES to refer to the file of employee names.
This command procedure defines a logical name that is used in the program PAYROLL:
At the end of the procedure, the WRITE command displays a message
indicating that the file was processed.
You can use the following lexical functions to manipulate character strings:
15.6.1 Determining Presence of Strings or CharactersOne common reason for examining strings is to determine whether a character (or substring) is present within a character string. To do this, use the F$LENGTH and the F$LOCATE functions. If the value returned by the F$LOCATE function equals the value returned by the F$LENGTH function, then the character you are looking for is not present. The following procedure requires a file name that includes the version number. To determine whether a version number is present, the procedure tests whether a semicolon (;), which precedes a version number in a file name, is included in the file name that the user enters.
The F$LOCATE function returns the offset for the semicolon. Offsets
start with 0; thus, if the semicolon were the first character in the
string, the F$LOCATE function would return the integer 0. If the
semicolon is not present within the string, the F$LOCATE function
returns an offset that is one more than the offset of the last
character in the string. This value is the same as the length returned
by F$LENGTH, which measures the length of the string starting with the
number 1.
To extract a portion of a string, use either the F$EXTRACT function or the F$ELEMENT function. Use the F$EXTRACT function to extract a substring that starts at a defined offset. Use the F$ELEMENT function to extract part of a string between two delimiters. To use either of these functions, you must know the general format of the string you are parsing. Note that you do not need to use F$EXTRACT or F$ELEMENT to parse file specifications or time strings. Instead, use F$PARSE or F$CVTIME to extract the desired portions of file specifications or time strings. You can also determine the length of the group name at the same time you extract it. If a string contains a delimiter that separates different parts of the string, use the F$ELEMENT function to extract the part that you want. You can use F$ELEMENT to obtain different types of access by extracting the portions of the string between the commas. To determine system access, obtain the first element; to determine owner access, obtain the second element; and so on. Note that when you use the F$ELEMENT function, element numbers start with zero. For this reason, use the integer 3 to specify the fourth element. The following command procedure uses the F$EXTRACT function to extract the group portion of the UIC. This allows the procedure to execute a different set of commands depending on the user's UIC group.
First, the procedure determines the UIC with the F$USER function. Next, the procedure determines the length of the group name by using F$LOCATE to locate the offset of the comma. The comma separates the group from the user portion of a UIC. Everything between the left bracket and the comma is part of the group name. For example, the group name from the UIC [WRITERS,SMITH] is WRITERS. After determining the length, the procedure extracts the name of the group with the F$EXTRACT function. The name starts with offset 1 and ends with the character before the comma. Finally, the procedure directs execution to the appropriate label. The following example shows how to determine the length of a group name at the same time it is being extracted:
The following example shows how each type of access in a protection code is separated by a comma:
The commands in this example extract the world access portion (the fourth element) from the default protection code:
The F$ELEMENT function returns everything between the third comma and the end of the string. Thus, if your default protection allowed read access for world users, the string "WORLD=R" would be returned. After you obtain the world access string, you may need to examine it further. For example:
|