Commit | Line | Data |
2986a63f |
1 | |
2 | /* |
3 | * Copyright © 2001 Novell, Inc. All Rights Reserved. |
4 | * |
5 | * You may distribute under the terms of either the GNU General Public |
6 | * License or the Artistic License, as specified in the README file. |
7 | * |
8 | */ |
9 | |
10 | /* |
11 | * FILENAME : nwplglob.c |
12 | * DESCRIPTION : Perl globbing support for NetWare. Other platforms have usually lauched |
13 | * a separate executable for this in order to take advantage of their |
14 | * shell's capability for generating a list of files from a given |
15 | * wildcard file spec. On NetWare, we don't have that luxury. |
16 | * So we just hack the support into pipe open support (which we also had to hack). |
17 | * Author : HYAK |
18 | * Date : January 2001. |
19 | * |
20 | */ |
21 | |
22 | |
23 | |
24 | #include <nwtypes.h> |
25 | #include "stdio.h" |
26 | #include <dirent.h> |
27 | |
28 | #include "win32ish.h" |
29 | #include "nwplglob.h" |
30 | |
31 | |
32 | |
33 | /*============================================================================================ |
34 | |
35 | Function : fnDoPerlGlob |
36 | |
37 | Description : Perl globbing support: Takes an array of wildcard descriptors |
38 | and produces from it a list of files that the wildcards expand into. |
39 | The list of files is written to the temporary file named by fileName. |
40 | |
41 | Parameters : argv (IN) - Input argument vector. |
42 | fileName (IN) - Input file name for storing globed file names. |
43 | |
44 | Returns : Nothing. |
45 | |
46 | ==============================================================================================*/ |
47 | |
48 | void fnDoPerlGlob(char** argv, char* fileName) |
49 | { |
50 | FILE * redirOut = NULL; |
51 | |
52 | if (*argv) |
53 | argv++; |
54 | if (*argv == NULL) |
55 | return; |
56 | |
57 | redirOut = fopen((const char *)fileName, (const char *)"w"); |
58 | if (!redirOut) |
59 | return; |
60 | |
61 | do |
62 | { |
63 | DIR* dir = NULL; |
64 | DIR* fil = NULL; |
65 | char* pattern = NULL; |
66 | |
67 | pattern = *argv++; |
68 | |
69 | dir = opendir((const char *)pattern); |
70 | if (!dir) |
71 | continue; |
72 | |
73 | /* find the last separator in pattern, NetWare has three: /\: */ |
74 | while (fil = readdir(dir)) |
75 | { |
76 | // The below displays the files separated by tab character. |
77 | // Also, it displays only the file names and not directories. |
78 | // If any other format is desired, it needs to be done here. |
79 | fprintf(redirOut, "%s\t", fil->d_name); |
80 | } |
81 | |
82 | closedir(dir); |
83 | |
84 | } while (*argv); |
85 | |
86 | fclose(redirOut); |
87 | |
88 | return; |
89 | } |
90 | |