From:	CSBVAX::MRGATE!info-vax-request@kl.sri.com@SMTP  5-MAR-1988 14:27
To:	ARISIA::EVERHART
Subj:	Re: Wild card expansion under VAX11-C:


Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Thu 3 Mar 88 08:26:49-PST
Received: by ucbvax.Berkeley.EDU (5.58/1.26)
	id AA05814; Thu, 3 Mar 88 08:15:52 PST
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 2 Mar 88 02:51:00 GMT
From: hartman@m.cs.uiuc.edu
Subject: Re: Wild card expansion under VAX11-C:
Message-Id: <28200002@uiucdcsm>
References: <5361@ames.arpa>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com


/* 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);
	}
}
