HP OpenVMS Systemsask the wizard |
The Question is: When using Lib.Find_File in VAX Ada, the Resultant_Filespec data is returned as a 'string' but with no information about the number of valid characters put into the string by Find_File. Languages such as VAX Pascal allow us to play around with the descriptor used to pass information to LIB$Find_File (so we can use a CLASS_VS descriptor instead of CLASS_S). What is the recommended (VAX Ada) way of determining the number of valid characters in the Resultant_Filespec? Search for trailing whitespace characters? TIA The Answer is :
Lib.Find_File is merely a entry in the Ada Predefined Library for the
system service routine.
You could write your own wrapper based on the LIB package's declaration,
if you want to use class VS descriptors, since Ada's import pragmas
do not appear to support that particular class (LRM 13.9a.1.1).
You could also write a jacket routine for LIB.FIND_FILE in a language
that supports dynamic descriptors with an interface that adds a
"returned-length" argument.
Or you could use RMS services $PARSE and $SEARCH directly, instead of
FIND_FILE
The simplest is to trim trailing whitespace from your resultant
filename - LIB$FIND_FILE will always fill the remainder of a fixed
length string with spaces. You can also be sure that even under ODS-5,
no valid OpenVMS file spec contains trailing spaces.
procedure print_directory is
FILENAME : STRING (1..255);
RESNAME : STRING (1..255);
STAT : CONDITION_HANDLING.COND_VALUE_TYPE;
CTX : SYSTEM.UNSIGNED_LONGWORD;
LENGTH : INTEGER;
RESLEN : SYSTEM.UNSIGNED_WORD;
begin
TEXT_IO.PUT_LINE ("Enter a filename: ");
TEXT_IO.GET_LINE (FILENAME, LENGTH);
CTX := 0;
STAT := 1;
while (STAT /= STARLET.RMS_NMF) loop
LIB.FIND_FILE(STAT,FILENAME(1..LENGTH),RESNAME,CTX);
if ((not CONDITION_HANDLING.SUCCESS(STAT))
and (STAT /= STARLET.RMS_NMF)) then
CONDITION_HANDLING.SIGNAL(STAT);
end if;
if (STAT /= STARLET.RMS_NMF) then
STR.TRIM (STAT, RESNAME,RESNAME,RESLEN);
TEXT_IO.PUT_LINE (RESNAME(1..INTEGER(RESLEN)));
TEXT_IO.NEW_LINE;
end if;
end loop;
LIB.FIND_FILE_END (STAT,CT);
if (not CONDITION_HANDLING.SUCCESS(ISTAT)) then
CONDITION_HANDLING.SIGNAL(ISTAT);
end if;
end print_directory;
|