[comp.os.vms] Wild card expansion under VAX11-C:

hartman@uiucdcsm.cs.uiuc.edu (03/02/88)

/* Written  1:08 pm  Feb 29, 1988 by woo@pioneer.arpa in uiucdcsm:comp.os.vms */
/* ---------- "Wild card expansion under VAX11-C:" ---------- */
How does one expand wildcards in command line arguments in
VAX11-C under VMS?  It is possible to write a *.CLD and use
DCL but there should be similar services callable from C.
If you have a code fragment which which does this, please
either post it or mail me a copy.

Thanks.

Alex
/* End of text from uiucdcsm:comp.os.vms */

The folowing code fragment should do what you want.  I just pieced it together
from a program I wrote a couple of years back, so please forgive any omissions
or typographical errors I may have just introduced.  It should handle both
"*" and "%" wildcard characters.

Pay special attention to the comment in the code about the filename strings.
The DESCRIPTOR functions do not bother to terminate returned strings with '\0'
as C expects, so you will have to do this manually.  You will also have
to pad the strings you pass to the functions with spaces, since they will
not recognize C's '\0' terminators.

-- 
Mark Hartman                     hartman@a.cs.uiuc.edu
                                 ihnp4!uiucdcs!hartman

-------------------CUT HERE--------------------
#include <stdio.h>
#include <ctype.h>
#include <descrip.h>
#include <ssdef.h>

main()
{
	static $DESCRIPTOR (generic, "");
	static $DESCRIPTOR (result_spec, "");

	char filename[40], wildcardfile[40];
	long int context = 0;

/*
 *  Set filename[] to the wildcard file specification here.
 *  Filenames must be padded to the proper length with spaces
 *  when using the descriptor functions, but terminated with
 *  '\0' when using normal C functions.
 */
	strcpy(filename, "*.c                                     ");
	generic.dsc$w_length = 40;
	generic.dsc$a_pointer = filename;

	strcpy(wildcardfile, "                                        ");
	result_spec.dsc$w_length = 40;
	result_spec.dsc$a_pointer = wildcardfile;

	if (strcspn(filename, "*") == (strcspn(filename, "%")) {
		/* No wildcard, process single file, name in "filename[]" */
		printf("%s\n", filename);
	}
	else {
		lib$find_file(&generic, &result_spec, &context);
		do {

			/* Process file, name in "wildcardname[]" */
			printf("%s\n", wildcardname);

			lib$find_file (&generic, &result_spec, &context);
		} while (strcspn(wildcardfile, "*") == strlen(wildcardfile));
		lib$find_file_end(&context);
	}
}

dhesi@bsu-cs.UUCP (Rahul Dhesi) (03/03/88)

In article <28200002@uiucdcsm> hartman@uiucdcsm.cs.uiuc.edu writes:
>/* ---------- "Wild card expansion under VAX11-C:" ---------- */

But there is one problem with wildcard expansion under VAX/VMS, and if
anybody has a solution I would like to know.

Under UNIX, if I type "echo *", I see an expanded list of filenames
without any directory prefixes.  But if I type "echo /usr/bin/*" I see
an expanded list of full pathnames.  A directory prefix is added only
if I specified one.  I like this.

But under VAX/VMS, if I expand "*.*", I always get a complete
specification of the form DEVICE:[DIRECTORY]FILENAME.EXT;v.  It would be
nice to be able to expand "*.*" to just filenames, without directory
names etc.
-- 
Rahul Dhesi         UUCP:  <backbones>!{iuvax,pur-ee,uunet}!bsu-cs!dhesi