1 /*
2 
3   varexp based findfile class
4 
5   copyright (c) 2004, 2005 squell <squell@alumina.nl>
6 
7   use, modification, copying and distribution of this software is permitted
8   under the conditions described in the file 'COPYING'.
9 
10   Usage:
11 
12   find::glob() to look for files matching the wildcard spec, and call the
13   overridden members as appropriate: file() for each file, dir() for each dir
14   files are searched in. After a call to dir(), all successive calls to file()
15   are for files to that dir.
16 
17   glob() searches for files matching the wildcard spec like a POSIX shell
18   would. if the second parameter is true, path seperators ('/') will also
19   match wildcards; if it is false or omitted, they will not. During a single
20   glob(), the record argument will always refer to the same object.
21 
22   dir() should return true or false, indicating whether to process the
23   directory passed as an argument. file() should return true or false
24   depending on the result of the operation.
25 
26   The first argument to file() aliasses with the associated record::path,
27   pointing to the start of the actual filename sans directory prefix.
28 
29   Example:
30 
31   struct showfiles : fileexp::find {
32       bool file(const char*, const fileexp::record& rec)
33       { return puts(rec.path), true; }
34   };
35 
36   int main(int argc, char* argv[])
37   {
38       showfiles ls;
39       for(int x=1; x<argc; ++x)
40           ls.glob(argv[x]) || puts("ffind: none found!");
41   }
42 
43 */
44 
45 #ifndef __ZF_FILEEXP
46 #define __ZF_FILEEXP
47 
48 #include <climits>
49 #include <vector>
50 #include <string>
51 #if defined(_WIN32) && !defined(PATH_MAX)
52 #  include <windows.h>
53 #  define PATH_MAX MAX_PATH
54 #endif
55 
56  // multi-directory wildcard search class
57 
58 namespace fileexp {
59 
60     struct record {
61         std::vector<std::string> var;         // contains matched vars
62         char path[PATH_MAX];                  // contains full file path
63     };
64 
65     struct find {
66         bool glob(const char* filemask, bool wildslash = false);
67 
68         virtual bool file(const char* name, const record&) = 0;
dirfind69         virtual bool dir (const record&)
70         { return 1; }
71 
~findfind72         virtual ~find() { }
73     };
74 
75 }
76 
77 #endif
78 
79