Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ptsfa!pacbell!att-ih!ihnp4!inuxc!iuvax!pur-ee!uiucdcs!uiucdcsm!hartman From: hartman@uiucdcsm.cs.uiuc.edu Newsgroups: comp.os.vms Subject: Re: Wild card expansion under VAX11-C: Message-ID: <28200002@uiucdcsm> Date: 2 Mar 88 02:51:00 GMT References: <5361@ames.arpa> Lines: 72 Nf-ID: #R:ames.arpa:5361:uiucdcsm:28200002:000:2423 Nf-From: uiucdcsm.cs.uiuc.edu!hartman Mar 1 20:51:00 1988 /* 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 #include #include #include 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); } }