[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP Pascal for OpenVMS
|
Previous | Contents | Index |
When you use OPEN to open a file, RMS applies certain defaults when attempting to locate the physical file. Table 7-1 presents these defaults.
Element | Default |
---|---|
Node | Local computer |
Device | Current user device |
Directory | Current user directory |
File name | HP Pascal file variable name or its logical name translation |
File type | .DAT |
Version number (history) |
OLD: highest current number
NEW: highest current number + 1 |
The OPEN procedure includes a default file-name parameter. Using this parameter, you can access the RMS default file-name parameter to set file-specification defaults. Consider the following example:
VAR My_File : VARYING [20] OF CHAR; My_File_Var : TEXT; BEGIN My_File := 'foo.bar'; OPEN( FILE_NAME := My_File, FILE_VARIABLE := My_File_Var, DEFAULT := '[another.dir]' ); |
The OPEN statement in the previous example opens the file called [ANOTHER.DIR]FOO.BAR. RMS applies the defaults in Table 7-1 to determine the node, the device, and the version number of the file.
Table 7-2 presents the status of RMS FAB fields when you call the OPEN procedure. If a field is not included in the following tables, it is initialized to zero.
Field | Name | OPEN Parameters and Value |
---|---|---|
FAB$L_CTX | Context | Reserved to Hewlett-Packard. |
FAB$L_DEV | Device characteristics | Returned by RMS. |
FAB$L_DNA |
Default file specification
string address |
DEFAULT parameter value, if specified; else, .DAT. |
FAB$L_DNS |
Default file specification
string size |
Set to length of default file name string. |
FAB$B_FAC | File access options | |
FAB$V_DEL | Allow deletions | 1, if not HISTORY:=READONLY. |
FAB$V_GET | Allow reads | 1 |
FAB$V_PUT | Allow writes | 1, if not HISTORY:=READONLY. |
FAB$V_TRN | Allow truncations | 1, if not HISTORY:=READONLY. |
FAB$V_UPD | Allow updates | 1, if not HISTORY:=READONLY. |
FAB$L_FNA | File specification string address | FILE_NAME if specified, name of file variable if external file, else 0. |
FAB$B_FNS | File specification string size | Set to length of file name string. |
FAB$L_FOP | File processing options | |
FAB$V_CIF | Create if nonexistent | 1, if HISTORY := UNKNOWN. |
FAB$V_DFW | Deferred write | 1 |
FAB$V_DLT | Delete on close service | Set when file is closed, depends on DISPOSITION. |
FAB$V_NAM | Name block inputs |
1, if terminal file reopened to enable
prompting. |
FAB$V_SFC |
Submit command file
(when closed) |
Set when file is closed, depends on DISPOSITION. |
FAB$V_SQO | Sequential only | 1, if ACCESS_METHOD:=SEQUENTIAL (default). |
FAB$V_TEF | Truncate at end of file | Initialized to 0, set to 1 after REWRITE or TRUNCATE of a sequential organization file. |
FAB$V_TMD | Temporary (marked for deletion) | 1, if nonexternal file with no FILE_NAME specified and DISPOSITION:=DELETE specified or implied. |
FAB$B_FSZ | Fixed control area size | 2, if terminal file enabled for prompting. |
FAB$W_IFI | Internal file identifier | Returned by RMS. |
FAB$W_MRS | Maximum record size | RECORD_LENGTH if specified; file component size if ORGANIZATION is not SEQUENTIAL or if RECORD_TYPE:=FIXED. |
FAB$L_NAM 1 | Name block address | Set to address of name block (the expanded and resultant string areas are set up, but the related file name string is not). |
FAB$B_ORG | File organization |
FAB$C_REL if ORGANIZATION:=RELATIVE;
FAB$C_IDX if ORGANIZATION:=INDEXED; FAB$C_SEQ in all other cases. |
FAB$B_RAT | Record attributes | |
FAB$V_FTN | FORTRAN carriage control | 1, if CARRIAGE_CONTROL:=FORTRAN. |
FAB$V_CR | Add LF and CR | 1, if CARRIAGE_CONTROL:=LIST (default for TEXT and VARYING OF CHAR files). |
FAB$V_PRN | Print file format | 1, if terminal file enabled for prompting. |
FAB$B_RFM | Record format |
FAB$C_FIX if RECORD_TYPE:=FIXED or if file component is of fixed size;
FAB$C_VAR if RECORD_TYPE:=VARIABLE or file is VARYING or TEXT; FAB$C_STM if RECORD_TYPE:=STREAM; FAB$C_STMCR if RECORD_TYPE:=STREAM_CR; FAB$C_STMLF if RECORD_TYPE:=STREAM_LF; FAB$C_VFC if a terminal file enabled for prompting. |
FAB$L_SDC |
Spooling device
characteristics |
Returned by RMS. |
FAB$L_XAB 2 | Extended attribute block address | The XAB chain always has a File Header Characteristics (FHC) extended attribute block in order to get the longest record length (XAB$W_LRL). If ACCESS_METHOD:=KEYED, key index definition blocks are also present. Hewlett-Packard may add additional XABs in the future. Your user-action function may insert XABs anywhere in the chain. This field is only valid during execution of user-action functions; HP Pascal places 0 in this field after the call to OPEN. |
FAB$B_SHR | File sharing | |
FAB$V_SHRPUT | Allow other PUTs | 1, if SHARING:=READWRITE. |
FAB$V_SHRGET | Allow other GETs | 1, if SHARING is not NONE (default if HISTORY:=READONLY). |
FAB$V_SHRDEL | Allow other DELETEs | 1, if SHARING:=READWRITE. |
FAB$V_SHRUPD | Allow other UPDATEs | 1, if SHARING:=READWRITE. |
FAB$V_NIL | Allow no other operations | 1, if SHARING:=NONE (default if HISTORY is not READONLY). |
Table 7-3 presents the status of RMS RAB fields when you call the OPEN procedure. If a field is not included in the following table, it is initialized to zero.
Field | Name | OPEN Parameters and Value |
---|---|---|
RAB$L_CTX | Context | Reserved to Hewlett-Packard. |
RAB$L_FAB 1 | FAB address |
Set to address of FAB (allocated by
HP Pascal RTL). |
RAB$W_ISI | Internal stream identifier | Returned by RMS. |
RAB$L_KBF | Key buffer address | May be modified for individual file operations after the file is opened. |
RAB$B_KRF | Key of reference | May be modified for individual file operations after the file is opened. |
RAB$B_KSZ | Key size | May be modified for individual file operations after the file is opened. |
RAB$B_RAC | Record access mode | May be modified for individual file operations after the file is opened. |
RAB$L_RBF | Record address | May be modified for individual file operations after the file is opened. |
RAB$L_RHB | Record header buffer | Set to address of 2-byte carriage-control information for terminal files enabled for prompting. |
RAB$L_ROP | Record options | |
RAB$V_NLK | No lock | May be modified for individual file operations after the file is opened. |
RAB$V_RAH | Read ahead | 1 |
RAB$V_TPT | Truncate file often PUT | May be modified for individual file operations after the file is opened. |
RAB$V_UIF | Update if record exists | 1, if ACCESS:=DIRECT. |
RAB$V_WBH | Write behind | 1 |
RAB$W_RSZ | Record size | May be modified for individual file operations after the file is opened. |
RAB$L_STS | Completion status code | Returned by RMS. |
RAB$L_UBF 1 | User record area address |
Set to buffer address after file is opened
(HP Pascal RTL allocates buffer). |
RAB$W_USZ 1 | User record area size | Set to size of record area; for files other than TEXT, the size is equal to the size of the component type; for TEXT files, the size is equal to the value of RECORD_LENGTH; otherwise, 255. |
Table 7-4 presents the status of RMS XAB fields when you call the OPEN procedure. If a field is not included in the following table, it is initialized to zero.
Field | Name | PASCAL OPEN Keyword and Value |
---|---|---|
XAB$B_DTP | Data type of key | Set to data type of key |
XAB$B_FLG | Key option flags | |
XAB$V_CHG | Changes allowed | 0 if key is 0, else 1 |
XAB$V_DUP | Duplicates allowed | 0 if key is 0, else 1 |
XAB$W_POS0 | Key position | Position of key in indexed file |
XAB$B_REF | Key of reference | Primary key is 0, first alternate key is 1, second alternate key is 2, and so on |
XAB$B_SIZ0 | Key size | Size of key |
Table 7-5 presents the status of RMS Name Block fields when you call the OPEN procedure. If a field is not included in the following table, it is initialized to zero.
Field | Name | OPEN Keyword and Value |
---|---|---|
NAM$L_ESA 1 | Expanded string area | Address of RTL buffer |
NAM$B_ESS 1 | Expanded string area | NAM$C_MAXRSS |
NAM$L_RSA | Expanded string area | Address of RTL buffer |
NAM$B_RSS | Expanded string area | NAM$C_MAXRSS |
HP Pascal determines a default line limit for TEXT files by translating the logical name PAS$LINELIMIT as a string of decimal digits. If this logical name has not been defined, there is no default line limit. You can override the default by calling the LINELIMIT procedure.
The user-action parameter of the OPEN procedure allows you to access RMS facilities not explicitly available in the HP Pascal language by writing a function that controls the opening of the file. Inclusion of the user-action parameter causes the run-time library to call your function to open the file instead of calling RMS to open it according to its normal defaults.
The user-action parameter of the CLOSE procedure is similar to that of the OPEN procedure. It allows you to access RMS facilities not directly available in HP Pascal by writing a function that controls the closing of the file. Including the user-action parameter causes the run-time library to call your function to close the file instead of calling RMS to close it according to its normal defaults.
When an OPEN or CLOSE procedure is executed, the run-time library uses the procedure's parameters to establish the RMS file access block (FAB) and the record access block (RAB), as well as to establish its own internal data structures. These blocks are used to transmit requests for file and record operations to RMS; they are also used to return the data contents of files, information about file characteristics, and status codes.
In order, the three parameters passed to a user-action function by the run-time library are as follows:
A user-action function is usually written in HP Pascal and includes the following:
Modification of any of the RMS file access blocks provided by the run-time library may interfere with the normal operation of the library. |
Example 7-1 shows an HP Pascal program that copies one file into another. The program features two user-action functions, which allow the output file to be created with the same size as the input file and to be given contiguous allocation on the storage media.
Example 7-1 User-Action Function |
---|
[INHERIT( 'SYS$LIBRARY:STARLET' )] PROGRAM Contiguous_Copy( F_In, F_Out ); { The input file F_In is copied to the output file F_Out. F_Out has the same size as F_In and has contiguous allocation. } TYPE FType = FILE OF VARYING[133] OF CHAR; VAR F_In, F_Out : FType; Alloc_Quantity : UNSIGNED; FUNCTION User_Open( VAR FAB : FAB$TYPE; VAR RAB : RAB$TYPE; VAR F : FType) : INTEGER; VAR Status : INTEGER; BEGIN { Function User_Open } {Open file and remember allocation quantity } Status := $OPEN( FAB ); IF ODD( Status ) THEN Status := $CONNECT( RAB ); Alloc_Quantity := FAB.FAB$L_ALQ; User_Open := Status; END; { Function User_Open } FUNCTION User_Create( VAR FAB : FAB$TYPE; VAR RAB : RAB$TYPE; VAR F : FType ) : INTEGER; VAR Status : INTEGER; BEGIN { Function User_Create } { Set up contiguous allocation } FAB.FAB$L_ALQ := Alloc_Quantity; FAB.FAB$V_CBT := FALSE; FAB.FAB$V_CTG := TRUE; Status := $CREATE( FAB ); IF ODD( Status ) THEN Status := $CONNECT( RAB ); User_Create := Status; END; { Function User_Create } BEGIN { main program } { Open files } OPEN( F_In, HISTORY := READONLY, USER_ACTION := User_Open ); RESET(F_In ); OPEN( F_Out, HISTORY := NEW, USER_ACTION := User_Create ); REWRITE( F_Out ); { Copy F_In to F_Out } WHILE NOT EOF( F_In ) DO BEGIN WRITE( F_Out, F_In_^ ); GET( F_In ); END; { Close files } CLOSE( F_In ); CLOSE( F_Out ); END. { main program } |
In this example, the record types FAB$TYPE and RAB$TYPE are defined in SYS$LIBRARY:STARLET, which the program inherits. The function User_Open is called as a result of the OPEN procedure for the input file F_In. The function begins by opening the file with the RMS service $OPEN. If $OPEN succeeds, the value of Status is odd; in that case, $CONNECT is performed. The allocation quantity contained in the FAB.FAB$L_ALQ field of the FAB is assigned to a variable so that this value can be used in the second user-action function. User_Open is then assigned the value of Status (in this case, TRUE), which is returned to the main program.
The function User_Create is called as a result of the OPEN procedure for the output file F_Out. The function assigns the allocation quantity of the input file to the FAB.FAB$L_ALQ field of the FAB, which contains the allocation size for the output file. The FAB field FAB.FAB$V_CBT is set to FALSE to disable the request that file storage be allocated contiguously on a best try basis. Then, the FAB field FAB.FAB$V_CTG is set to TRUE so that contiguous storage allocation is mandatory. Finally, the RMS service $CREATE is performed. If $CREATE is successful, $CONNECT will be done and the function return value will be that of $CREATE.
Once the OPEN procedures have been performed successfully, the program can then accomplish its main task, copying the input file F_In to the output file F_Out, which is the same size as F_In and has contiguous allocation. The last step in the program is to close the files.
Previous | Next | Contents | Index |