Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

C function to check for valid openVMS path specifcation

 
Highlighted
Occasional Contributor

C function to check for valid openVMS path specifcation

Hi all,

I want to know whether there is any C library function, which I can use to check whether a given string is a valid OpenVMS path format or not.
Though I can write one, but if there already exists one such function (may be a DECC function), then I would not want to devote any time in writing that part of code.

I tried to google this out, but it would not give any desirable result.

Thanks in advance!

Cheers,
Almond
20 REPLIES 20
Highlighted
Honored Contributor

Re: C function to check for valid openVMS path specifcation

I'd vote for the $PARSE system service.

HELP SYSTEM_SERVICES $PARSE

is not very informative, other than to
suggest the manual to read. If an example
might be helpful, then you might look
through, say, the Info-ZIP Zip source code
for "sys$parse". ("[vms]vms.c" is one
place.) As usual, calling a system service
like this one tends to involve some
relatively messy code elements, such as
string descriptors, and, because it involves
the file system(s), various RMS structures
(FAB, NAM[L]). The addition of ODS5 and the
NAML structure added some complications for a
program like Zip, which can still be built on
VMS VAX V5.4 (ODS2-only), but if you steal
enough code, it should work. If you don't
demand so much portability, then the code
could be streamlined some. (I didn't see
your VMS version in your original problem
statement.) A Web search for "sys$parse"
should find more examples, of course.

> [...] Though I can write one, [...]

While it might seem to be easier to write
your own code, $PARSE is the gold standard
for what's good and what's bad.
Highlighted
Honored Contributor

Re: C function to check for valid openVMS path specifcation

Do you mean syntactically valid, or whether or not the file or directory exists?

Because standard C doesn't know a whole lot about VMS-format specifications, you're going to have to call out to extensions or more often to VMS calls, if you want to work with VMS-format file specifications.

For a syntactically valid VMS specification, yes, call $parse with the NAM$V_SYNCHK flag set. This won't catch missing directories, et al.; valid specifications that won't necessarily work.

This discussion borders on various obscure areas of C on VMS, as the rules are somewhat arcane, and also given that valid C paths can also be Unix-format paths, and both Unix and VMS specifications can be equally valid, but quite different.

There are all sorts of corner cases scattered around here, too, with the conversions, and with details such as ODS-2 and ODS-5 support and settings.

I generally recommend sticking with Unix-format specifications, as they're easier to parse and deal with.

If not, try it. That's the standard and best test. See if it works. (The same holds for testing permissions. Try it.)

I don't know if off-hand if there's a C call akin to sys$parse. Usually, most anything other than / and \0 are accepted in a filename.

If you want or have to use C specifications but also need to work with VMS format specifications, then there are routines (decc$to_vms and decc$from_vms) that convert these from and to VMS-format specifications. There are (were) examples of both in the C library reference manual.

The compatibility was described in /Symbolic Links and POSIX Pathname Support/ in recent C documentation.

As for rolling your own, you can be assured that home-grown to parse filenames will very likely be wrong. (I don't mean that to be offensive, either.) And should there be changes to how VMS works in this area (and there have been) your code then differs from VMS. There are still applications that insist on ODS-2 specifications, and even VMS itself can't manage <> syntax in various of its own tools.

Here's what POSIX has to say about portable specs:

http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html

And POSIX defines upper and lowercase alphabetic, numeric, underscore, hyphen and dot as the portable characters.

Various Unix implementations and file systems can deal with a whole lot more than that, and VMS adds the $, and pretty soon you're finished with your tea and down the rabbit hole. And VMS has also added UTF-8 and VTF-7 characters, just for "fun".

Beyond "try it", there isn't a simple answer.
Highlighted
Honored Contributor

Re: C function to check for valid openVMS path specifcation

>>> I don't know if off-hand if there's a C call akin to sys$parse. Usually, most anything other than / and \0 are accepted in a filename.
<<<
realpath(). But is has no equivalent flag for NAM$V_SYNCHK. In Posix it checks if all the intermediate directories exist. And yes, a Posix path is a C-style string, which excludes only the \0.

>>> And VMS has also added UTF-8 and VTF-7 characters, just for "fun".
<<<
UTF-8 is just an encoding for up to four UNICODE charactes with ISL-2 characters. SYS$PARSE supports ISL-2 characters, so it supports UTF-8. The CRTL supports UTF-8. VTF-7 is just an encoding for UCS-2 characters. The CRTL only supports VTF-7 in the VMS file name space.
Highlighted
Honored Contributor

Re: C function to check for valid openVMS path specifcation

>UTF-8 is just an encoding for up to four UNICODE charactes with ISL-2 characters. SYS$PARSE supports ISL-2 characters, so it supports UTF-8. The CRTL supports UTF-8. VTF-7 is just an encoding for UCS-2 characters. The CRTL only supports VTF-7 in the VMS file name space.


I rest my case, your honor.
Highlighted
Trusted Contributor

Re: C function to check for valid openVMS path specifcation

You'll probably find useful information in chapter 12 ('Symbolic links and POSIX pathname support') of the C Runtime Library Reference manual.

URL: http://h71000.www7.hp.com/doc/83final/5763/OVMS_83_CRTL_REF.PDF
Highlighted
Honored Contributor

Re: C function to check for valid openVMS path specifcation

The VMS implementation of extended filename encoding, um, quite bizarre. (And it doesn't get to character encoding within the files, as that's largely a non-starter.)

For some discussions of UTF-8 and VTF-7 encoding and of porting code involving UTF-8, see:

http://snow.hoffmanlabs.net/node/1481

And for grins, also see

sys$examples:filename_compare.c

(I'd also suggest testing whether the above works with the UTF-8 encoding, as there's no mention of it there.)

The VTF-7 stuff seems entirely undocumented, and looks like it might have been some early version or variant of encoding, or a DEC-internal spec that was never released.

And thanks for the pointer to the C manuals, I'd completely forgotten to mention the forest of C logical names that can be in play. Depending on what you're up to, change one or two of these and the application can fall down in odd ways.

All of which goes back to my original comment: you really don't want to drop down this rabbit hole if you can avoid it. You may end up more than late for your tea. Use the existing calls, and (best you can) stay away from trying to judge what characters are permissible or not.

Reposting as ITRC is being ITRC again today.
Highlighted
Honored Contributor

Re: C function to check for valid openVMS path specifcation

Ah, nuts. Corrected URL...

http://labs.hoffmanlabs.com/node/1481
Highlighted
Honored Contributor

Re: C function to check for valid openVMS path specifcation

There is a rather gnarly example of calling sys$parse in the Perl sources here:

http://perl5.git.perl.org/perl.git/blob/HEAD:/vms/vms.c#l5400

The "int_rmsexpand" function takes input in either Unix or VMS format and attempts to handle older and newer maximum filename lengths as well as some of the DECC$* features. It explicitly punts on UTF-8. All in all, reading (or maintaining) this code can certainly feel like falling down a rabbit hole.
Highlighted
Occasional Contributor

Re: C function to check for valid openVMS path specifcation

Hi all,

Thanks for overwhelming responses ..
I will try the various options that have been mentioned by you all...

(and just to add, I was just looking to syntactically validate a string for a valid openVMS path.)

Thanks again

Thanks,
Almond