"Fossies" - the Fresh Open Source Software Archive 
Member "c_count-7.20/porting/wildcard.c" (22 Nov 2002, 2379 Bytes) of package /linux/privat/c_count-7.20.tgz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "wildcard.c" see the
Fossies "Dox" file reference documentation.
1 #ifndef NO_IDENT
2 static char *Id = "$Id: wildcard.c,v 1.4 2002/11/22 22:07:45 tom Exp $";
3 #endif
4
5 /*
6 * wildcard.c - perform wildcard expansion for non-UNIX configurations
7 */
8
9 #include "system.h"
10
11 #if HAVE_STDLIB_H
12 # include <stdlib.h>
13 #endif
14
15 #if HAVE_STRING_H
16 # include <string.h>
17 #endif
18
19 #if SYS_MSDOS || SYS_OS2
20 # if SYS_MSDOS
21 # include <dos.h>
22 # include <dir.h> /* defines MAXPATH */
23 # define FILENAME_MAX MAXPATH
24 # endif
25 # define DeclareFind(p) struct find_t p
26 # define DirEntryStr(p) p.name
27 # define DirFindFirst(path,p) (!_dos_findfirst(path, 0, &p))
28 # define DirFindNext(p) (!_dos_findnext(&p))
29 #endif
30
31 #if SYS_VMS
32
33 #include <starlet.h> /* DEC-C (e.g., sys$parse) */
34 #include <stdio.h> /* perror */
35
36 #include <rms.h>
37 #include <descrip.h>
38
39 #endif /* SYS_VMS */
40
41 int
42 has_wildcard(char *path)
43 {
44 #if SYS_VMS
45 return (strstr(path, "...") != 0
46 || strchr(path, '*') != 0
47 || strchr(path, '?') != 0);
48 #else /* SYS_MSDOS, SYS_OS2 */
49 return (strchr(path, '*') != 0
50 || strchr(path, '?') != 0);
51 #endif
52 }
53
54 int
55 expand_wildcard(char *path, int initiate)
56 {
57 #if SYS_MSDOS || SYS_OS2
58 static DeclareFind(p);
59 static char temp[FILENAME_MAX + 1];
60 register char *leaf;
61
62 if ((leaf = strchr(path, '/')) == 0
63 && (leaf = strchr(path, '\\')) == 0)
64 leaf = path;
65 else
66 leaf++;
67
68 if ((initiate && DirFindFirst(strcpy(temp, path), p))
69 || DirFindNext(p)) {
70 (void) strcpy(leaf, DirEntryStr(p));
71 return TRUE;
72 }
73 #endif /* SYS_MSDOS || SYS_OS2 */
74 #if SYS_VMS
75 static struct FAB zfab;
76 static struct NAM znam;
77 static char my_esa[NAM$C_MAXRSS]; /* expanded: SYS$PARSE */
78 static char my_rsa[NAM$C_MAXRSS]; /* expanded: SYS$SEARCH */
79
80 if (initiate) {
81 zfab = cc$rms_fab;
82 zfab.fab$l_fop = FAB$M_NAM;
83 zfab.fab$l_nam = &znam; /* FAB => NAM block */
84 zfab.fab$l_dna = "*.*;"; /* Default-selection */
85 zfab.fab$b_dns = strlen(zfab.fab$l_dna);
86
87 zfab.fab$l_fna = path;
88 zfab.fab$b_fns = strlen(path);
89
90 znam = cc$rms_nam;
91 znam.nam$b_ess = sizeof(my_esa);
92 znam.nam$l_esa = my_esa;
93 znam.nam$b_rss = sizeof(my_rsa);
94 znam.nam$l_rsa = my_rsa;
95
96 if (sys$parse(&zfab) != RMS$_NORMAL) {
97 perror(path);
98 exit(EXIT_FAILURE);
99 }
100 }
101 if (sys$search(&zfab) == RMS$_NORMAL) {
102 strncpy(path, my_rsa, znam.nam$b_rsl)[znam.nam$b_rsl] = '\0';
103 return (TRUE);
104 }
105 #endif /* SYS_VMS */
106 #if SYS_MSDOS
107 #endif
108 return FALSE;
109 }