Browse Source

added posix compat layer for NT

despair 1 year ago
parent
commit
05b2db8a4f

+ 7
- 1
NTMakefile View File

@@ -83,7 +83,7 @@ netrunner.res.o: netrunner.rc
83 83
 	windres $^ -o $@
84 84
 	@rm favicon.ico
85 85
 
86
-netrunner: $(OBJECTS) $(OBJDIR)/tlsf.o $(OBJDIR)/slre.o netrunner.res.o
86
+netrunner: $(OBJECTS) $(OBJDIR)/tlsf.o $(OBJDIR)/slre.o netrunner.res.o $(OBJDIR)/glob.o $(OBJDIR)/fnmatch.o
87 87
 	$(LINK) $(LDFLAGS) -o $@ $^ $(LIBS)
88 88
 
89 89
 $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
@@ -98,6 +98,12 @@ $(OBJDIR)/tlsf.o: $(SRCDIR)/tlsf.c
98 98
 $(OBJDIR)/slre.o: $(SRCDIR)/slre.c
99 99
 	$(CC) $(INCPATH) $(CWARN) -c -o $@ $<
100 100
 
101
+$(OBJDIR)/glob.o: $(SRCDIR)/glob.c
102
+	$(CC) $(INCPATH) $(CWARN) -c -o $@ $<
103
+
104
+$(OBJDIR)/fnmatch.o: $(SRCDIR)/fnmatch.c
105
+	$(CC) $(INCPATH) $(CWARN) -c -o $@ $<
106
+
101 107
 $(DEPDIR)/%d: ;
102 108
 .PRECIOUS: $(DEPDIR)/%.d
103 109
 

+ 53
- 0
deps/include/cl/dir.h View File

@@ -0,0 +1,53 @@
1
+#ifndef __DIR_H
2
+#define __DIR_H
3
+
4
+#include <direct.h>
5
+
6
+#ifndef MAX_PATH
7
+#define MAX_PATH 260
8
+#endif
9
+#ifndef MAXPATH
10
+#define MAXPATH MAX_PATH
11
+#endif 
12
+
13
+#ifndef FA_NORMAL
14
+#define FA_NORMAL   0x00        /* Normal file, no attributes */
15
+#define FA_RDONLY   0x01        /* Read only attribute */
16
+#define FA_HIDDEN   0x02        /* Hidden file */
17
+#define FA_SYSTEM   0x04        /* System file */
18
+#define FA_LABEL    0x08        /* Volume label */
19
+#define FA_DIREC    0x10        /* Directory */
20
+#define FA_ARCH     0x00        /* Archive */
21
+#endif /* FA_NORMAL */
22
+
23
+#ifndef _FFBLK_DEF
24
+#define _FFBLK_DEF
25
+struct  ffblk   {
26
+    long            ff_reserved;
27
+    long            ff_fsize;
28
+    unsigned long   ff_attrib;
29
+    unsigned short  ff_ftime;
30
+    unsigned short  ff_fdate;
31
+    char            ff_name[MAXPATH];
32
+};
33
+#endif
34
+
35
+#define getdisk() (_getdrive() + 1)
36
+
37
+
38
+#ifdef __cplusplus
39
+extern "C" {
40
+#endif
41
+
42
+int findfirst( const char *__path,
43
+               struct ffblk *__ffblk,
44
+               int __attrib );
45
+int findnext( struct ffblk *__ffblk );
46
+int findclose( struct ffblk *__ffblk );
47
+
48
+#ifdef __cplusplus
49
+}
50
+#endif
51
+
52
+
53
+#endif /* __DIR_H */

+ 43
- 0
deps/include/cl/dirent.h View File

@@ -0,0 +1,43 @@
1
+/* vi: set ts=8 sw=4 : */
2
+/********************************************************************\
3
+*File   : dirent.h
4
+*
5
+*Subject:
6
+*   Substitution of Unix dirent.h for Win32
7
+*
8
+*Authors:
9
+*   SAA	 Anatoli Soltan
10
+*
11
+*HISTORY:
12
+*   Feb 18 1997  SAA
13
+*       initial implementation; struct dirent has only
14
+*       one field: d_name
15
+*   Mar 15 2000  SAA added __cplusplus condition
16
+*********************************************************************/
17
+
18
+#ifndef __DIRENT_H
19
+#define __DIRENT_H
20
+
21
+#include <stdlib.h>	/* _MAX_FNAME */
22
+
23
+#ifdef __cplusplus
24
+extern "C" {
25
+#endif
26
+
27
+struct dirent
28
+{
29
+    char    d_name[_MAX_FNAME];
30
+};
31
+
32
+struct _DIR;
33
+typedef struct _DIR DIR;
34
+
35
+DIR* opendir(const char* name);
36
+struct dirent* readdir(DIR* dir);
37
+int closedir(DIR* dir);
38
+
39
+#ifdef __cplusplus
40
+}
41
+#endif
42
+
43
+#endif /* __DIRENT_H */

+ 22
- 0
deps/include/cl/fnmatch.h View File

@@ -0,0 +1,22 @@
1
+#ifndef __FNMATCH_H
2
+#define __FNMATCH_H
3
+
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
8
+#define FNM_NOESCAPE	0x01
9
+#define FNM_PATHNAME	0x02
10
+#define FNM_PERIOD	0x04
11
+#define FNM_NOCASE	0x08
12
+
13
+#define FNM_NOMATCH	1
14
+#define FNM_ERROR	2
15
+
16
+int fnmatch(const char *_pattern, const char *_string, int _flags);
17
+
18
+#ifdef __cplusplus
19
+}
20
+#endif
21
+
22
+#endif /* __FNMATCH_H */

+ 112
- 0
deps/include/cl/getopt.h View File

@@ -0,0 +1,112 @@
1
+/* Declarations for getopt.
2
+   Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3
+   Copyright (C) 2000, 01, 2002 Salvador E. Tropea.
4
+
5
+   This program is free software; you can redistribute it and/or modify it
6
+   under the terms of the GNU General Public License as published by the
7
+   Free Software Foundation; either version 2, or (at your option) any
8
+   later version.
9
+
10
+   This program is distributed in the hope that it will be useful,
11
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+   GNU General Public License for more details.
14
+
15
+   You should have received a copy of the GNU General Public License
16
+   along with this program; if not, write to the Free Software
17
+   Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
18
+
19
+#ifndef HEADER_GETOPT_H
20
+#define HEADER_GETOPT_H 1
21
+
22
+#ifdef	__cplusplus
23
+extern "C" {
24
+#endif
25
+
26
+/* For communication from `getopt' to the caller.
27
+   When `getopt' finds an option that takes an argument,
28
+   the argument value is returned here.
29
+   Also, when `ordering' is RETURN_IN_ORDER,
30
+   each non-option ARGV-element is returned here.  */
31
+
32
+extern char *CLY_optarg;
33
+
34
+/* Index in ARGV of the next element to be scanned.
35
+   This is used for communication to and from the caller
36
+   and for communication between successive calls to `getopt'.
37
+
38
+   On entry to `getopt', zero means this is the first call; initialize.
39
+
40
+   When `getopt' returns EOF, this is the index of the first of the
41
+   non-option elements that the caller should itself scan.
42
+
43
+   Otherwise, `optind' communicates from one call to the next
44
+   how much of ARGV has been scanned so far.  */
45
+
46
+extern int CLY_optind;
47
+
48
+/* Callers store zero here to inhibit the error message `getopt' prints
49
+   for unrecognized options.  */
50
+
51
+extern int CLY_opterr;
52
+
53
+/* Set to an option character which was unrecognized.  */
54
+
55
+extern int CLY_optopt;
56
+
57
+/* Describe the long-named options requested by the application.
58
+   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
59
+   of `struct option' terminated by an element containing a name which is
60
+   zero.
61
+
62
+   The field `has_arg' is:
63
+   no_argument       (or 0) if the option does not take an argument,
64
+   required_argument (or 1) if the option requires an argument,
65
+   optional_argument (or 2) if the option takes an optional argument.
66
+
67
+   If the field `flag' is not NULL, it points to a variable that is set
68
+   to the value given in the field `val' when the option is found, but
69
+   left unchanged if the option is not found.
70
+
71
+   To have a long-named option do something other than set an `int' to
72
+   a compiled-in constant, such as set a value from `optarg', set the
73
+   option's `flag' field to zero and its `val' field to a nonzero
74
+   value (the equivalent single-letter option character, if there is
75
+   one).  For long options that have a zero `flag' field, `getopt'
76
+   returns the contents of the `val' field.  */
77
+
78
+struct CLY_option
79
+{
80
+  const char *name;
81
+  /* has_arg can't be an enum because some compilers complain about
82
+     type mismatches in all the code that assumes it is an int.  */
83
+  int has_arg;
84
+  int *flag;
85
+  int val;
86
+};
87
+
88
+/* Names for the values of the `has_arg' field of `struct option'.  */
89
+
90
+#define CLY_no_argument        0
91
+#define CLY_required_argument  1
92
+#define CLY_optional_argument  2
93
+
94
+extern int CLY_getopt(int argc, char *const *argv, const char *shortopts);
95
+extern int CLY_getopt_long(int argc, char *const *argv, const char *shortopts,
96
+                           const struct CLY_option *longopts, int *longind);
97
+extern int CLY_getopt_long_only(int argc, char *const *argv,
98
+                                const char *shortopts,
99
+                                const struct CLY_option *longopts,
100
+                                int *longind);
101
+/* Internal only.  Users should not call this directly.  */
102
+extern int CLY_getopt_internal(int argc, char *const *argv,
103
+                               const char *shortopts,
104
+                               const struct CLY_option *longopts,
105
+                               int *longind,
106
+                               int long_only);
107
+
108
+#ifdef __cplusplus
109
+}
110
+#endif
111
+
112
+#endif /* HEADER_GETOPT_H */

+ 37
- 0
deps/include/cl/glob.h View File

@@ -0,0 +1,37 @@
1
+#ifndef __GLOB_H
2
+#define __GLOB_H
3
+
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
8
+#include <stddef.h>
9
+#include <sys/types.h>
10
+
11
+typedef struct {
12
+  size_t gl_pathc;
13
+  char **gl_pathv;
14
+  size_t gl_offs;
15
+} glob_t;
16
+
17
+#define GLOB_APPEND	0x01
18
+#define	GLOB_DOOFFS	0x02
19
+#define GLOB_ERR	0x04
20
+#define GLOB_MARK	0x08
21
+#define GLOB_NOCHECK	0x10
22
+#define GLOB_NOESCAPE	0x20
23
+#define GLOB_NOSORT	0x40
24
+#define GLOB_TILDE      (1 << 12) /* Expand ~user and ~ to home directories. */
25
+#define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error if the user name is not available.  */
26
+#define GLOB_ABORTED	1
27
+#define GLOB_NOMATCH	2
28
+#define GLOB_NOSPACE	3
29
+
30
+int  glob(const char *_pattern, int _flags, int (*_errfunc)(const char *_epath, int _eerrno), glob_t *_pglob);
31
+void globfree(glob_t *_pglob);
32
+
33
+#ifdef __cplusplus
34
+}
35
+#endif
36
+
37
+#endif /* __GLOB_H */

+ 157
- 0
deps/include/cl/needs.h View File

@@ -0,0 +1,157 @@
1
+/**[txh]********************************************************************
2
+
3
+  Description:
4
+  This header defines which functions must be defined for each supported
5
+compiler.@p
6
+
7
+  Copyright (c) 2000-2005 by Salvador E. Tropea
8
+  Covered by the GPL license.
9
+
10
+***************************************************************************/
11
+
12
+#define TVOS_Win32
13
+#define TVOSf_
14
+#define TVCPU_x86
15
+#define TVComp_GCC
16
+#define TVCompf_MinGW
17
+
18
+#ifdef TVComp_GCC
19
+ // GNU c is supported for various OSs:
20
+ 
21
+ #define NEEDS_GETCURDIR
22
+ 
23
+ // Win32 MinGW
24
+ #ifdef TVCompf_MinGW
25
+  #define NEEDS_FIXPATH
26
+  #define NEEDS_GLOB
27
+  #define NEEDS_FNMATCH
28
+  #define NEEDS_REGEX
29
+  #define NEEDS_GETOPT
30
+  #define NEEDS_MKSTEMP
31
+  #define NEEDS_NL_LANGINFO
32
+  #define NEEDS_GETLINE
33
+  // Internal implementation is broken. Is the same provided by MSVC.
34
+  #define NEEDS_SNPRINTF
35
+ #endif
36
+ 
37
+ // Win32 Cygwin
38
+ #ifdef TVCompf_Cygwin
39
+  #define NEEDS_FIXPATH
40
+  #define NEEDS_FILELENGTH
41
+  #define NEEDS_NL_LANGINFO
42
+  #define NEEDS_FNMATCH
43
+  #define NEEDS_ITOA
44
+  #define NEEDS_GETLINE
45
+ #endif
46
+ 
47
+ // DOS djgpp
48
+ #ifdef TVCompf_djgpp
49
+  #define NEEDS_GETOPT
50
+  #define NEEDS_NL_LANGINFO
51
+  #define NEEDS_GETLINE
52
+  #define NEEDS_SNPRINTF
53
+ #endif
54
+ 
55
+ // Linux
56
+ #ifdef TVOSf_Linux
57
+  // Strings
58
+  #define NEEDS_STRLWR
59
+  #define NEEDS_STRUPR
60
+  #define NEEDS_FIXPATH
61
+  #define NEEDS_FILELENGTH
62
+  #define NEEDS_ITOA
63
+ #endif
64
+ 
65
+ // Solaris
66
+ #ifdef TVOSf_Solaris
67
+  // Strings
68
+  #define NEEDS_STRLWR
69
+  #define NEEDS_STRUPR
70
+  #define NEEDS_GETOPT
71
+  #define NEEDS_FIXPATH
72
+  #define NEEDS_FILELENGTH
73
+  #define NEEDS_ITOA
74
+  #define NEEDS_NL_LANGINFO
75
+  #define NEEDS_GETLINE
76
+  #define NEEDS_SNPRINTF
77
+ #endif
78
+
79
+ #ifdef TVOSf_QNX4
80
+  #define NEEDS_SNPRINTF
81
+ #endif // TVOSf_QNX4
82
+
83
+ #ifdef TVOSf_Darwin
84
+  #define NEEDS_SNPRINTF
85
+ #endif
86
+
87
+ // Generic UNIX system
88
+ #if defined(TVOS_UNIX) && !defined(TVOSf_Linux) && !defined(TVOSf_Solaris)
89
+  // Strings
90
+  #define NEEDS_STRLWR
91
+  #define NEEDS_STRUPR
92
+  #define NEEDS_FIXPATH
93
+  #define NEEDS_FILELENGTH
94
+  #define NEEDS_ITOA
95
+  #define NEEDS_NL_LANGINFO
96
+  #define NEEDS_GETLINE
97
+  #if defined(TVOSf_FreeBSD) || defined(TVOSf_QNXRtP) || defined(TVOSf_QNX4) \
98
+      || defined(TVOSf_Darwin)
99
+   // Not for OpenBSD and NetBSD
100
+   #define NEEDS_GETOPT
101
+  #endif
102
+ #endif
103
+#endif
104
+
105
+
106
+// BC++ 5.5 for Win32 is supported
107
+#ifdef TVComp_BCPP
108
+ #define NEEDS_FIXPATH
109
+ #define NEEDS_GLOB
110
+ #define NEEDS_FNMATCH
111
+ #define NEEDS_UNC
112
+ #define NEEDS_REGEX
113
+ #define NEEDS_GETOPT
114
+ #define NEEDS_OPENDIR
115
+ #define NEEDS_MKSTEMP
116
+ #define NEEDS_NL_LANGINFO
117
+ #define NEEDS_IFSTREAMGETLINE
118
+ #define NEEDS_GETLINE
119
+#endif
120
+
121
+
122
+// MSVC will be supported if volunteers tests it or Microsoft decides to
123
+// give it for free ;-). After all Borland released BC++ 5.5.
124
+#if (defined(_MSVC) || defined(__MSC_VER)) && !defined(_MSC_VER)
125
+ #define _MSC_VER 100
126
+#endif
127
+
128
+#ifdef TVComp_MSC
129
+ #define NEEDS_GETCURDIR
130
+ #define NEEDS_FIXPATH
131
+ #define NEEDS_GLOB
132
+ #define NEEDS_FNMATCH
133
+ #define NEEDS_REGEX
134
+ #define NEEDS_GETOPT
135
+ #define NEEDS_MKSTEMP
136
+ #define NEEDS_NL_LANGINFO
137
+ #define NEEDS_GETLINE
138
+ #define NEEDS_OPENDIR
139
+ // Internal implementation is broken.
140
+ #define NEEDS_SNPRINTF
141
+ #define NEEDS_UNC
142
+#endif
143
+
144
+// Open Watcom for Win32 is supported
145
+#ifdef TVComp_Watcom
146
+ #define NEEDS_FIXPATH
147
+ #define NEEDS_GLOB
148
+ #define NEEDS_FNMATCH
149
+ #define NEEDS_UNC
150
+ #define NEEDS_GETOPT
151
+ #define NEEDS_OPENDIR
152
+ #define NEEDS_NL_LANGINFO
153
+ #define NEEDS_IFSTREAMGETLINE
154
+ #define NEEDS_GETLINE
155
+ #define NEEDS_GETCURDIR
156
+#endif
157
+

+ 499
- 0
deps/include/cl/regex.h View File

@@ -0,0 +1,499 @@
1
+/* Definitions for data structures and routines for the regular
2
+   expression library, version 0.12.
3
+
4
+   Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
5
+
6
+   This program is free software; you can redistribute it and/or modify
7
+   it under the terms of the GNU General Public License as published by
8
+   the Free Software Foundation; either version 2, or (at your option)
9
+   any later version.
10
+
11
+   This program is distributed in the hope that it will be useful,
12
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+   GNU General Public License for more details.
15
+
16
+   You should have received a copy of the GNU General Public License
17
+   along with this program; if not, write to the Free Software
18
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
+
20
+#ifndef __REGEXP_LIBRARY_H__
21
+#define __REGEXP_LIBRARY_H__
22
+
23
+/* POSIX says that <sys/types.h> must be included (by the caller) before
24
+   <regex.h>.  */
25
+
26
+#ifdef VMS
27
+/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
28
+   should be there.  */
29
+#include <stddef.h>
30
+#endif
31
+
32
+#include <stddef.h>
33
+
34
+/* The following bits are used to determine the regexp syntax we
35
+   recognize.  The set/not-set meanings are chosen so that Emacs syntax
36
+   remains the value 0.  The bits are given in alphabetical order, and
37
+   the definitions shifted by one from the previous bit; thus, when we
38
+   add or remove a bit, only one other definition need change.  */
39
+typedef unsigned reg_syntax_t;
40
+
41
+/* If this bit is not set, then \ inside a bracket expression is literal.
42
+   If set, then such a \ quotes the following character.  */
43
+#define RE_BACKSLASH_ESCAPE_IN_LISTS (1)
44
+
45
+/* If this bit is not set, then + and ? are operators, and \+ and \? are
46
+     literals. 
47
+   If set, then \+ and \? are operators and + and ? are literals.  */
48
+#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
49
+
50
+/* If this bit is set, then character classes are supported.  They are:
51
+     [:alpha:], [:upper:], [:lower:],  [:digit:], [:alnum:], [:xdigit:],
52
+     [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
53
+   If not set, then character classes are not supported.  */
54
+#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
55
+
56
+/* If this bit is set, then ^ and $ are always anchors (outside bracket
57
+     expressions, of course).
58
+   If this bit is not set, then it depends:
59
+        ^  is an anchor if it is at the beginning of a regular
60
+           expression or after an open-group or an alternation operator;
61
+        $  is an anchor if it is at the end of a regular expression, or
62
+           before a close-group or an alternation operator.  
63
+
64
+   This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
65
+   POSIX draft 11.2 says that * etc. in leading positions is undefined.
66
+   We already implemented a previous draft which made those constructs
67
+   invalid, though, so we haven't changed the code back.  */
68
+#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
69
+
70
+/* If this bit is set, then special characters are always special
71
+     regardless of where they are in the pattern.
72
+   If this bit is not set, then special characters are special only in
73
+     some contexts; otherwise they are ordinary.  Specifically, 
74
+     * + ? and intervals are only special when not after the beginning,
75
+     open-group, or alternation operator.  */
76
+#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
77
+
78
+/* If this bit is set, then *, +, ?, and { cannot be first in an re or
79
+     immediately after an alternation or begin-group operator.  */
80
+#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
81
+
82
+/* If this bit is set, then . matches newline.
83
+   If not set, then it doesn't.  */
84
+#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
85
+
86
+/* If this bit is set, then . doesn't match NUL.
87
+   If not set, then it does.  */
88
+#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
89
+
90
+/* If this bit is set, nonmatching lists [^...] do not match newline.
91
+   If not set, they do.  */
92
+#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
93
+
94
+/* If this bit is set, either \{...\} or {...} defines an
95
+     interval, depending on RE_NO_BK_BRACES. 
96
+   If not set, \{, \}, {, and } are literals.  */
97
+#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
98
+
99
+/* If this bit is set, +, ? and | aren't recognized as operators.
100
+   If not set, they are.  */
101
+#define RE_LIMITED_OPS (RE_INTERVALS << 1)
102
+
103
+/* If this bit is set, newline is an alternation operator.
104
+   If not set, newline is literal.  */
105
+#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
106
+
107
+/* If this bit is set, then `{...}' defines an interval, and \{ and \}
108
+     are literals.
109
+  If not set, then `\{...\}' defines an interval.  */
110
+#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
111
+
112
+/* If this bit is set, (...) defines a group, and \( and \) are literals.
113
+   If not set, \(...\) defines a group, and ( and ) are literals.  */
114
+#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
115
+
116
+/* If this bit is set, then \<digit> matches <digit>.
117
+   If not set, then \<digit> is a back-reference.  */
118
+#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
119
+
120
+/* If this bit is set, then | is an alternation operator, and \| is literal. 
121
+   If not set, then \| is an alternation operator, and | is literal.  */
122
+#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
123
+
124
+/* If this bit is set, then an ending range point collating higher
125
+     than the starting range point, as in [z-a], is invalid.
126
+   If not set, then when ending range point collates higher than the
127
+     starting range point, the range is ignored.  */
128
+#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
129
+
130
+/* If this bit is set, then an unmatched ) is ordinary.
131
+   If not set, then an unmatched ) is invalid.  */
132
+#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
133
+
134
+/* This global variable defines the particular regexp syntax to use (for
135
+   some interfaces).  When a regexp is compiled, the syntax used is
136
+   stored in the pattern buffer, so changing this does not affect
137
+   already-compiled regexps.  */
138
+extern reg_syntax_t re_syntax_options;
139
+
140
+/* Define combinations of the above bits for the standard possibilities.
141
+   (The [[[ comments delimit what gets put into the Texinfo file, so
142
+   don't delete them!)  */ 
143
+/* [[[begin syntaxes]]] */
144
+#define RE_SYNTAX_EMACS 0
145
+
146
+#define RE_SYNTAX_AWK							\
147
+  (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL			\
148
+   | RE_NO_BK_PARENS            | RE_NO_BK_REFS				\
149
+   | RE_NO_BK_VBAR               | RE_NO_EMPTY_RANGES			\
150
+   | RE_UNMATCHED_RIGHT_PAREN_ORD)
151
+
152
+#define RE_SYNTAX_POSIX_AWK 						\
153
+  (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)
154
+
155
+#define RE_SYNTAX_GREP							\
156
+  (RE_BK_PLUS_QM              | RE_CHAR_CLASSES				\
157
+   | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS				\
158
+   | RE_NEWLINE_ALT)
159
+
160
+#define RE_SYNTAX_EGREP							\
161
+  (RE_CHAR_CLASSES        | RE_CONTEXT_INDEP_ANCHORS			\
162
+   | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE			\
163
+   | RE_NEWLINE_ALT       | RE_NO_BK_PARENS				\
164
+   | RE_NO_BK_VBAR)
165
+
166
+#define RE_SYNTAX_POSIX_EGREP						\
167
+  (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
168
+
169
+/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff.  */
170
+#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
171
+
172
+#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
173
+
174
+/* Syntax bits common to both basic and extended POSIX regex syntax.  */
175
+#define _RE_SYNTAX_POSIX_COMMON						\
176
+  (RE_CHAR_CLASSES | RE_DOT_NEWLINE      | RE_DOT_NOT_NULL		\
177
+   | RE_INTERVALS  | RE_NO_EMPTY_RANGES)
178
+
179
+#define RE_SYNTAX_POSIX_BASIC						\
180
+  (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
181
+
182
+/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
183
+   RE_LIMITED_OPS, i.e., \? \+ \| are not recognized.  Actually, this
184
+   isn't minimal, since other operators, such as \`, aren't disabled.  */
185
+#define RE_SYNTAX_POSIX_MINIMAL_BASIC					\
186
+  (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
187
+
188
+#define RE_SYNTAX_POSIX_EXTENDED					\
189
+  (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS			\
190
+   | RE_CONTEXT_INDEP_OPS  | RE_NO_BK_BRACES				\
191
+   | RE_NO_BK_PARENS       | RE_NO_BK_VBAR				\
192
+   | RE_UNMATCHED_RIGHT_PAREN_ORD)
193
+
194
+/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
195
+   replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added.  */
196
+#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED				\
197
+  (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS			\
198
+   | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES				\
199
+   | RE_NO_BK_PARENS        | RE_NO_BK_REFS				\
200
+   | RE_NO_BK_VBAR	    | RE_UNMATCHED_RIGHT_PAREN_ORD)
201
+/* [[[end syntaxes]]] */
202
+
203
+/* Maximum number of duplicates an interval can allow.  Some systems
204
+   (erroneously) define this in other header files, but we want our
205
+   value, so remove any previous define.  */
206
+#ifdef RE_DUP_MAX
207
+#undef RE_DUP_MAX
208
+#endif
209
+#define RE_DUP_MAX ((1 << 15) - 1) 
210
+
211
+
212
+/* POSIX `cflags' bits (i.e., information for `regcomp').  */
213
+
214
+/* If this bit is set, then use extended regular expression syntax.
215
+   If not set, then use basic regular expression syntax.  */
216
+#define REG_EXTENDED 1
217
+
218
+/* If this bit is set, then ignore case when matching.
219
+   If not set, then case is significant.  */
220
+#define REG_ICASE (REG_EXTENDED << 1)
221
+ 
222
+/* If this bit is set, then anchors do not match at newline
223
+     characters in the string.
224
+   If not set, then anchors do match at newlines.  */
225
+#define REG_NEWLINE (REG_ICASE << 1)
226
+
227
+/* If this bit is set, then report only success or fail in regexec.
228
+   If not set, then returns differ between not matching and errors.  */
229
+#define REG_NOSUB (REG_NEWLINE << 1)
230
+
231
+
232
+/* POSIX `eflags' bits (i.e., information for regexec).  */
233
+
234
+/* If this bit is set, then the beginning-of-line operator doesn't match
235
+     the beginning of the string (presumably because it's not the
236
+     beginning of a line).
237
+   If not set, then the beginning-of-line operator does match the
238
+     beginning of the string.  */
239
+#define REG_NOTBOL 1
240
+
241
+/* Like REG_NOTBOL, except for the end-of-line.  */
242
+#define REG_NOTEOL (1 << 1)
243
+
244
+
245
+/* If any error codes are removed, changed, or added, update the
246
+   `re_error_msg' table in regex.c.  */
247
+typedef enum
248
+{
249
+  REG_NOERROR = 0,	/* Success.  */
250
+  REG_NOMATCH,		/* Didn't find a match (for regexec).  */
251
+
252
+  /* POSIX regcomp return error codes.  (In the order listed in the
253
+     standard.)  */
254
+  REG_BADPAT,		/* Invalid pattern.  */
255
+  REG_ECOLLATE,		/* Not implemented.  */
256
+  REG_ECTYPE,		/* Invalid character class name.  */
257
+  REG_EESCAPE,		/* Trailing backslash.  */
258
+  REG_ESUBREG,		/* Invalid back reference.  */
259
+  REG_EBRACK,		/* Unmatched left bracket.  */
260
+  REG_EPAREN,		/* Parenthesis imbalance.  */ 
261
+  REG_EBRACE,		/* Unmatched \{.  */
262
+  REG_BADBR,		/* Invalid contents of \{\}.  */
263
+  REG_ERANGE,		/* Invalid range end.  */
264
+  REG_ESPACE,		/* Ran out of memory.  */
265
+  REG_BADRPT,		/* No preceding re for repetition op.  */
266
+
267
+  /* Error codes we've added.  */
268
+  REG_EEND,		/* Premature end.  */
269
+  REG_ESIZE,		/* Compiled pattern bigger than 2^16 bytes.  */
270
+  REG_ERPAREN		/* Unmatched ) or \); not returned from regcomp.  */
271
+} reg_errcode_t;
272
+
273
+/* This data structure represents a compiled pattern.  Before calling
274
+   the pattern compiler, the fields `buffer', `allocated', `fastmap',
275
+   `translate', and `no_sub' can be set.  After the pattern has been
276
+   compiled, the `re_nsub' field is available.  All other fields are
277
+   private to the regex routines.  */
278
+
279
+struct re_pattern_buffer
280
+{
281
+/* [[[begin pattern_buffer]]] */
282
+	/* Space that holds the compiled pattern.  It is declared as
283
+          `unsigned char *' because its elements are
284
+           sometimes used as array indexes.  */
285
+  unsigned char *buffer;
286
+
287
+	/* Number of bytes to which `buffer' points.  */
288
+  unsigned long allocated;
289
+
290
+	/* Number of bytes actually used in `buffer'.  */
291
+  unsigned long used;	
292
+
293
+        /* Syntax setting with which the pattern was compiled.  */
294
+  reg_syntax_t syntax;
295
+
296
+        /* Pointer to a fastmap, if any, otherwise zero.  re_search uses
297
+           the fastmap, if there is one, to skip over impossible
298
+           starting points for matches.  */
299
+  char *fastmap;
300
+
301
+        /* Either a translate table to apply to all characters before
302
+           comparing them, or zero for no translation.  The translation
303
+           is applied to a pattern when it is compiled and to a string
304
+           when it is matched.  */
305
+  char *translate;
306
+
307
+	/* Number of subexpressions found by the compiler.  */
308
+  size_t re_nsub;
309
+
310
+        /* Zero if this pattern cannot match the empty string, one else.
311
+           Well, in truth it's used only in `re_search_2', to see
312
+           whether or not we should use the fastmap, so we don't set
313
+           this absolutely perfectly; see `re_compile_fastmap' (the
314
+           `duplicate' case).  */
315
+  unsigned can_be_null : 1;
316
+
317
+        /* If REGS_UNALLOCATED, allocate space in the `regs' structure
318
+             for `max (RE_NREGS, re_nsub + 1)' groups.
319
+           If REGS_REALLOCATE, reallocate space if necessary.
320
+           If REGS_FIXED, use what's there.  */
321
+#define REGS_UNALLOCATED 0
322
+#define REGS_REALLOCATE 1
323
+#define REGS_FIXED 2
324
+  unsigned regs_allocated : 2;
325
+
326
+        /* Set to zero when `regex_compile' compiles a pattern; set to one
327
+           by `re_compile_fastmap' if it updates the fastmap.  */
328
+  unsigned fastmap_accurate : 1;
329
+
330
+        /* If set, `re_match_2' does not return information about
331
+           subexpressions.  */
332
+  unsigned no_sub : 1;
333
+
334
+        /* If set, a beginning-of-line anchor doesn't match at the
335
+           beginning of the string.  */ 
336
+  unsigned not_bol : 1;
337
+
338
+        /* Similarly for an end-of-line anchor.  */
339
+  unsigned not_eol : 1;
340
+
341
+        /* If true, an anchor at a newline matches.  */
342
+  unsigned newline_anchor : 1;
343
+
344
+/* [[[end pattern_buffer]]] */
345
+};
346
+
347
+typedef struct re_pattern_buffer regex_t;
348
+
349
+
350
+/* search.c (search_buffer) in Emacs needs this one opcode value.  It is
351
+   defined both in `regex.c' and here.  */
352
+#define RE_EXACTN_VALUE 1
353
+
354
+/* Type for byte offsets within the string.  POSIX mandates this.  */
355
+typedef int regoff_t;
356
+
357
+
358
+/* This is the structure we store register match data in.  See
359
+   regex.texinfo for a full description of what registers match.  */
360
+struct re_registers
361
+{
362
+  unsigned num_regs;
363
+  regoff_t *start;
364
+  regoff_t *end;
365
+};
366
+
367
+
368
+/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
369
+   `re_match_2' returns information about at least this many registers
370
+   the first time a `regs' structure is passed.  */
371
+#ifndef RE_NREGS
372
+#define RE_NREGS 30
373
+#endif
374
+
375
+
376
+/* POSIX specification for registers.  Aside from the different names than
377
+   `re_registers', POSIX uses an array of structures, instead of a
378
+   structure of arrays.  */
379
+typedef struct
380
+{
381
+  regoff_t rm_so;  /* Byte offset from string's start to substring's start.  */
382
+  regoff_t rm_eo;  /* Byte offset from string's start to substring's end.  */
383
+} regmatch_t;
384
+
385
+/* Declarations for routines.  */
386
+
387
+/* To avoid duplicating every routine declaration -- once with a
388
+   prototype (if we are ANSI), and once without (if we aren't) -- we
389
+   use the following macro to declare argument types.  This
390
+   unfortunately clutters up the declarations a bit, but I think it's
391
+   worth it.  */
392
+
393
+#if __STDC__ || defined(__cplusplus)
394
+
395
+#define _RE_ARGS(args) args
396
+
397
+#else /* not __STDC__ */
398
+
399
+#define _RE_ARGS(args) ()
400
+
401
+#endif /* not __STDC__ */
402
+
403
+#ifdef __cplusplus
404
+extern "C" {
405
+#endif
406
+
407
+/* Sets the current default syntax to SYNTAX, and return the old syntax.
408
+   You can also simply assign to the `re_syntax_options' variable.  */
409
+extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
410
+
411
+/* Compile the regular expression PATTERN, with length LENGTH
412
+   and syntax given by the global `re_syntax_options', into the buffer
413
+   BUFFER.  Return NULL if successful, and an error string if not.  */
414
+extern const char *re_compile_pattern
415
+  _RE_ARGS ((const char *pattern, int length,
416
+             struct re_pattern_buffer *buffer));
417
+
418
+
419
+/* Compile a fastmap for the compiled pattern in BUFFER; used to
420
+   accelerate searches.  Return 0 if successful and -2 if was an
421
+   internal error.  */
422
+extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
423
+
424
+
425
+/* Search in the string STRING (with length LENGTH) for the pattern
426
+   compiled into BUFFER.  Start searching at position START, for RANGE
427
+   characters.  Return the starting position of the match, -1 for no
428
+   match, or -2 for an internal error.  Also return register
429
+   information in REGS (if REGS and BUFFER->no_sub are nonzero).  */
430
+extern int re_search
431
+  _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
432
+            int length, int start, int range, struct re_registers *regs));
433
+
434
+
435
+/* Like `re_search', but search in the concatenation of STRING1 and
436
+   STRING2.  Also, stop searching at index START + STOP.  */
437
+extern int re_search_2
438
+  _RE_ARGS (( struct re_pattern_buffer *bufp,
439
+     const char *string1, const char *string2, int size1, int size2,
440
+     int startpos, int range, struct re_registers *regs, int stop ));
441
+
442
+/* Like `re_search', but return how many characters in STRING the regexp
443
+   in BUFFER matched, starting at position START.  */
444
+extern int re_match
445
+  _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
446
+             int length, int start, struct re_registers *regs));
447
+
448
+
449
+/* Relates to `re_match' as `re_search_2' relates to `re_search'.  */
450
+extern int re_match_2 
451
+  _RE_ARGS (( struct re_pattern_buffer *bufp, const char *string1,
452
+   const char *string2, int size1, int size2, int pos,
453
+     struct re_registers *regs, int stop ));
454
+
455
+
456
+/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
457
+   ENDS.  Subsequent matches using BUFFER and REGS will use this memory
458
+   for recording register information.  STARTS and ENDS must be
459
+   allocated with malloc, and must each be at least `NUM_REGS * sizeof
460
+   (regoff_t)' bytes long.
461
+
462
+   If NUM_REGS == 0, then subsequent matches should allocate their own
463
+   register data.
464
+
465
+   Unless this function is called, the first search or match using
466
+   PATTERN_BUFFER will allocate its own register data, without
467
+   freeing the old data.  */
468
+extern void re_set_registers
469
+  _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
470
+             unsigned num_regs, regoff_t *starts, regoff_t *ends));
471
+
472
+/* 4.2 bsd compatibility.  */
473
+extern char *re_comp _RE_ARGS ((const char *));
474
+extern int re_exec _RE_ARGS ((const char *));
475
+
476
+/* POSIX compatibility.  */
477
+extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags));
478
+extern int regexec
479
+  _RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch,
480
+             regmatch_t pmatch[], int eflags));
481
+extern size_t regerror
482
+  _RE_ARGS ((int errcode, const regex_t *preg, char *errbuf,
483
+             size_t errbuf_size));
484
+extern void regfree _RE_ARGS ((regex_t *preg));
485
+
486
+#ifdef __cplusplus
487
+}
488
+#endif
489
+
490
+
491
+#endif /* not __REGEXP_LIBRARY_H__ */
492
+
493
+/*
494
+Local variables:
495
+make-backup-files: t
496
+version-control: t
497
+trim-versions-without-asking: nil
498
+End:
499
+*/

+ 6
- 0
deps/include/cl/strstream.h View File

@@ -0,0 +1,6 @@
1
+#ifndef __STRSTREAM_H
2
+#define __STRSTREAM_H
3
+
4
+#include <strstrea.h>
5
+
6
+#endif /*  __STRSTREAM_H */

+ 26
- 0
deps/include/cl/unistd.h View File

@@ -0,0 +1,26 @@
1
+#ifndef __UNISTD_H
2
+#define __UNISTD_H
3
+
4
+//#define PATH_MAX MAXPATH
5
+
6
+#ifndef F_OK
7
+ #define F_OK 0
8
+#endif
9
+
10
+#ifndef R_OK
11
+ #define R_OK 4
12
+#endif
13
+
14
+#ifndef STDIN_FILENO
15
+ #define STDIN_FILENO 0
16
+#endif
17
+
18
+#ifndef STDOUT_FILENO
19
+ #define STDOUT_FILENO 1
20
+#endif
21
+
22
+#ifndef STDERR_FILENO
23
+ #define STDERR_FILENO 2
24
+#endif
25
+
26
+#endif /*  __UNISTD_H */

+ 20
- 0
deps/include/cl/utime.h View File

@@ -0,0 +1,20 @@
1
+#ifndef UTime_Included
2
+#define UTime_Included
3
+
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
8
+struct utimbuf
9
+{
10
+ time_t actime;
11
+ time_t modtime;
12
+};
13
+
14
+int utime(const char *file, const struct utimbuf *time);
15
+
16
+#ifdef __cplusplus
17
+}
18
+#endif
19
+
20
+#endif /* UTime_Included */

+ 1
- 0
deps/include/cl/utsname.h View File

@@ -0,0 +1 @@
1
+/* just a stub */

+ 2610
- 0
deps/include/compatlayer.h
File diff suppressed because it is too large
View File


+ 4
- 0
src/browser.cpp View File

@@ -10,7 +10,11 @@
10 10
 #include "interfaces/components/ButtonComponent.h"
11 11
 
12 12
 #include <fstream>
13
+#ifndef _WIN32
13 14
 #include <glob.h>
15
+#else
16
+#include <cl/glob.h>
17
+#endif
14 18
 
15 19
 // why can't I const this?
16 20
 std::unique_ptr<Scheduler> scheduler = std::make_unique<Scheduler>();

+ 150
- 0
src/fnmatch.c View File

@@ -0,0 +1,150 @@
1
+/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
2
+/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
3
+/* Modified for Win32 by Anatoli Soltan */
4
+#include <cl/needs.h>
5
+
6
+#ifdef NEEDS_FNMATCH
7
+#include <string.h>
8
+#include <ctype.h>
9
+#define Uses_fnmatch
10
+#include <compatlayer.h>
11
+
12
+#define	EOS	'\0'
13
+
14
+static const char *rangematch(const char *pattern, char test, int nocase);
15
+
16
+#define isslash(c) ((c) == '\\' || (c) == '/')
17
+
18
+static const char *
19
+find_slash(const char *s)
20
+{
21
+  while (*s)
22
+  {
23
+    if (isslash(*s))
24
+      return s;
25
+    s++;
26
+  }
27
+  return 0;
28
+}
29
+
30
+static const char *
31
+rangematch(const char *pattern, char test, int nocase)
32
+{
33
+  char c, c2;
34
+  int negate, ok;
35
+
36
+  if (!!(negate = (*pattern == '!')))
37
+    ++pattern;
38
+
39
+  for (ok = 0; (c = *pattern++) != ']';)
40
+  {
41
+    if (c == 0)
42
+      return 0;			/* illegal pattern */
43
+    if (*pattern == '-' && (c2 = pattern[1]) != 0 && c2 != ']')
44
+    {
45
+      if (c <= test && test <= c2)
46
+	ok = 1;
47
+      if (nocase && toupper(c) <= toupper(test) && toupper(test) <= toupper(c2))
48
+	ok = 1;
49
+      pattern += 2;
50
+    }
51
+    else if (c == test)
52
+      ok = 1;
53
+    else if (nocase && (toupper(c) == toupper(test)))
54
+      ok = 1;
55
+  }
56
+  return ok == negate ? NULL : pattern;
57
+}
58
+
59
+int
60
+fnmatch(const char *pattern, const char *string, int flags)
61
+{
62
+  char c;
63
+  char test;
64
+
65
+  for (;;)
66
+    switch ((c = *pattern++))
67
+    {
68
+    case 0:
69
+      return *string == 0 ? 0 : FNM_NOMATCH;
70
+
71
+    case '?':
72
+      if ((test = *string++) == 0 ||
73
+	  (isslash(test) && (flags & FNM_PATHNAME)))
74
+	return(FNM_NOMATCH);
75
+      break;
76
+      
77
+    case '*':
78
+      c = *pattern;
79
+      /* collapse multiple stars */
80
+      while (c == '*')
81
+	c = *++pattern;
82
+
83
+      /* optimize for pattern with * at end or before / */
84
+      if (c == 0)
85
+      {
86
+	if (flags & FNM_PATHNAME)
87
+	  return find_slash(string) ? FNM_NOMATCH : 0;
88
+	else
89
+	  return 0;
90
+      }
91
+      else if (isslash(c) && flags & FNM_PATHNAME)
92
+      {
93
+	if ((string = find_slash(string)) == NULL)
94
+	  return FNM_NOMATCH;
95
+	break;
96
+      }
97
+
98
+      /* general case, use recursion */
99
+      while ((test = *string) != 0)
100
+      {
101
+	if (fnmatch(pattern, string, flags) == 0)
102
+	  return(0);
103
+	if (isslash(test) && flags & FNM_PATHNAME)
104
+	  break;
105
+	++string;
106
+      }
107
+      return FNM_NOMATCH;
108
+      
109
+    case '[':
110
+      if ((test = *string++) == 0 ||
111
+	  (isslash(test) && flags & FNM_PATHNAME))
112
+	return FNM_NOMATCH;
113
+      if ((pattern = rangematch(pattern, test, flags & FNM_NOCASE)) == NULL)
114
+	return FNM_NOMATCH;
115
+      break;
116
+      
117
+    case '\\':
118
+      if (!(flags & FNM_NOESCAPE) && pattern[1] && strchr("*?[\\", pattern[1]))
119
+      {
120
+	if ((c = *pattern++) == 0)
121
+	{
122
+	  c = '\\';
123
+	  --pattern;
124
+	}
125
+	if (c != *string++)
126
+	  return FNM_NOMATCH;
127
+	break;
128
+      }
129
+      /* FALLTHROUGH */
130
+
131
+    default:
132
+      if (isslash(c) && isslash(*string))
133
+      {
134
+	string++;
135
+	break;
136
+      }
137
+      if (flags & FNM_NOCASE)
138
+      {
139
+	if (toupper(c) != toupper(*string++))
140
+	  return FNM_NOMATCH;
141
+      }
142
+      else
143
+      {
144
+	if (c != *string++)
145
+	  return FNM_NOMATCH;
146
+      }
147
+      break;
148
+    }
149
+}
150
+#endif // NEEDS_FNMATCH

+ 427
- 0
src/glob.c View File

@@ -0,0 +1,427 @@
1
+/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
2
+/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
3
+/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
4
+/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
5
+/* Modified for Win32 by Anatoli Soltan */
6
+
7
+#include <cl/needs.h>
8
+
9
+#ifdef NEEDS_GLOB
10
+#define WIN32_LEAN_AND_MEAN
11
+#include <windows.h>
12
+#include <stdio.h>
13
+#include <string.h>
14
+#include <stdlib.h>
15
+#include <malloc.h>
16
+#include <io.h>
17
+#include <ctype.h>
18
+#ifndef TVComp_MSC
19
+ #include <dir.h>
20
+#endif
21
+
22
+#define Uses_glob
23
+#define Uses_unistd
24
+#define Uses_fnmatch
25
+#define Uses_alloca
26
+#include <compatlayer.h>
27
+
28
+typedef struct Save {
29
+  struct Save *prev;
30
+  char *entry;
31
+} Save;
32
+
33
+int CLY_FileExists(const char *fname)
34
+{
35
+ return (access(fname,R_OK)==0);
36
+}
37
+
38
+static Save *save_list;
39
+static int save_count;
40
+static int flags;
41
+static int (*errfunc)(const char *epath, int eerno);
42
+static char *pathbuf;
43
+static int wildcard_nesting;
44
+static char use_lfn;
45
+static char preserve_case;
46
+static char slash;
47
+
48
+static int glob2(const char *pattern, char *epathbuf, int lower, int caseless);
49
+static int glob_dirs(const char *rest, char *epathbuf, int first, int lower, int caseless);
50
+static int add(const char *path);
51
+static int str_compare(const void *va, const void *vb);
52
+
53
+static int _preserve_fncase(void)
54
+{
55
+  return 1;
56
+}
57
+
58
+static int
59
+add(const char *path)
60
+{
61
+  Save *sp;
62
+  for (sp=save_list; sp; sp=sp->prev)
63
+    if (stricmp(sp->entry, path) == 0)
64
+      return 0;
65
+  sp = (Save *)malloc(sizeof(Save));
66
+  if (sp == 0)
67
+    return 1;
68
+  sp->entry = (char *)malloc(strlen(path)+1);
69
+  if (sp->entry == 0)
70
+  {
71
+    free(sp);
72
+    return 1;
73
+  }
74
+/*  printf("add: `%s'\n", path); */
75
+  strcpy(sp->entry, path);
76
+  sp->prev = save_list;
77
+  save_list = sp;
78
+  save_count++;
79
+  return 0;
80
+}
81
+
82
+static int
83
+glob_dirs(const char *rest, char *epathbuf, int first, /* rest is ptr to null or ptr after slash, bp after slash */
84
+	  int lower, int caseless)
85
+{
86
+//  struct ffblk ff;
87
+  HANDLE hf;
88
+  WIN32_FIND_DATA wfd;
89
+  BOOL done;
90
+
91
+/*  printf("glob_dirs[%d]: rest=`%s' %c epathbuf=`%s' %c pathbuf=`%s'\n",
92
+	 wildcard_nesting, rest, *rest, epathbuf, *epathbuf, pathbuf); */
93
+
94
+  if (first)
95
+  {
96
+    if (*rest)
97
+    {
98
+      if (glob2(rest, epathbuf, lower, caseless) == GLOB_NOSPACE)
99
+	return GLOB_NOSPACE;
100
+    }
101
+    else
102
+    {
103
+      char sl = epathbuf[-1];
104
+      *epathbuf = 0;
105
+/*      printf("end, checking `%s'\n", pathbuf); */
106
+      if (epathbuf == pathbuf)
107
+      {
108
+	epathbuf[0] = '.';
109
+	epathbuf[1] = 0;
110
+      }
111
+      else
112
+	epathbuf[-1] = 0;
113
+      if (__file_exists(pathbuf))
114
+	if (add(pathbuf))
115
+	  return GLOB_NOSPACE;
116
+      epathbuf[-1] = sl;
117
+    }
118
+  }
119
+
120
+  strcpy(epathbuf, "*.*");
121
+  hf = FindFirstFile(pathbuf, &wfd);
122
+  done = (hf == INVALID_HANDLE_VALUE);
123
+  while (!done)
124
+  {
125
+    if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
126
+	&& (strcmp(wfd.cFileName, ".") && strcmp(wfd.cFileName, "..")))
127
+    {
128
+      char *tp;
129
+
130
+      strcpy(epathbuf, wfd.cFileName);
131
+      tp = epathbuf + strlen(epathbuf);
132
+      *tp++ = slash;
133
+      *tp = 0;
134
+
135
+      wildcard_nesting++;
136
+      if (*rest)
137
+      {
138
+	if (glob2(rest, tp, lower, caseless) == GLOB_NOSPACE)
139
+	  return GLOB_NOSPACE;
140
+      }
141
+      else
142
+      {
143
+	if (!(flags & GLOB_MARK))
144
+	  tp[-1] = 0;
145
+	if (add(pathbuf))
146
+	  return GLOB_NOSPACE;
147
+	tp[-1] = slash;
148
+      }
149
+      *tp = 0;
150
+      if (glob_dirs(rest, tp, 0, lower, caseless) == GLOB_NOSPACE)
151
+	return GLOB_NOSPACE;
152
+      wildcard_nesting--;
153
+    }
154
+    done = !FindNextFile(hf, &wfd);
155
+  }
156
+  FindClose(hf);
157
+  return 0;
158
+}
159
+
160
+static int
161
+glob2(const char *pattern, char *epathbuf,  /* both point *after* the slash */
162
+      int lower, int caseless)
163
+{
164
+  const char *pp, *pslash;
165
+  char *bp;
166
+  HANDLE hf;
167
+  WIN32_FIND_DATA wfd;
168
+  char *my_pattern;
169
+  int done;
170
+
171
+  if (strcmp(pattern, "...") == 0)
172
+  {
173
+    return glob_dirs(pattern+3, epathbuf, 1, lower, caseless);
174
+  }
175
+  if (strncmp(pattern, "...", 3) == 0 && (pattern[3] == '\\' || pattern[3] == '/'))
176
+  {
177
+    slash = pattern[3];
178
+    return glob_dirs(pattern+4, epathbuf, 1, lower, caseless);
179
+  }
180
+
181
+  *epathbuf = 0;
182
+  /* copy as many non-wildcard segments as possible */
183
+  pp = pattern;
184
+  bp = epathbuf;
185
+  pslash = bp-1;
186
+  while (1)
187
+  {
188
+    if (*pp == ':' || *pp == '\\' || *pp == '/')
189
+    {
190
+      pslash = bp;
191
+      if (strcmp(pp+1, "...") == 0
192
+	  || (strncmp(pp+1, "...", 3) == 0 && (pp[4] == '/' || pp[4] == '\\')))
193
+      {
194
+	if (*pp != ':')
195
+	  slash = *pp;
196
+/*	printf("glob2: dots at `%s'\n", pp); */
197
+	*bp++ = *pp++;
198
+	break;
199
+      }
200
+    }
201
+
202
+    else if (*pp == '*' || *pp == '?' || *pp == '[')
203
+    {
204
+      if (pslash > pathbuf)
205
+	strncpy(epathbuf, pattern, pslash - pathbuf);
206
+      pp = pattern + (pslash - epathbuf) + 1;
207
+      bp = epathbuf + (pslash - epathbuf) + 1;
208
+      break;
209
+    }
210
+
211
+    else if (*pp == 0)
212
+    {
213
+      break;
214
+    }
215
+
216
+    /* Upper-case or mixed-case patterns force case-sensitive
217
+       matches in `fnmatch' for LFN filesystems.  They also
218
+       suppress downcasing 8+3 filenames (on all filesystems).  */
219
+    else if (!preserve_case)
220
+    {
221
+      if (*pp >= 'A' && *pp <= 'Z')
222
+      {
223
+	if (use_lfn)
224
+	  caseless = 0;
225
+	lower = 0;
226
+      }
227
+      else if (*pp >= 'a' && *pp <= 'z')
228
+	lower = 1;
229
+    }
230
+
231
+    *bp++ = *pp++;
232
+  }
233
+  *bp = 0;
234
+
235
+  if (*pp == 0) /* end of pattern? */
236
+  {
237
+    if (__file_exists(pathbuf))
238
+    {
239
+      if (flags & GLOB_MARK)
240
+      {
241
+	HANDLE _hf;
242
+	WIN32_FIND_DATA _wfd;
243
+	_hf = FindFirstFile(pathbuf, &_wfd);
244
+        //findfirst(pathbuf, &_ff, FA_RDONLY|FA_SYSTEM|FA_DIREC|FA_ARCH);
245
+        if (_hf != INVALID_HANDLE_VALUE && _wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
246
+        {
247
+          char *_pathbuf = pathbuf + strlen(pathbuf);
248
+          *_pathbuf++ = '/';
249
+          *_pathbuf = 0;
250
+        }
251
+	FindClose(_hf);
252
+      }
253
+      if (add(pathbuf))
254
+	return GLOB_NOSPACE;
255
+    }
256
+    return 0;
257
+  }
258
+/*  printf("glob2: initial segment is `%s'\n", pathbuf); */
259
+  if (wildcard_nesting)
260
+  {
261
+    char s = bp[-1];
262
+    bp[-1] = 0;
263
+    if (!__file_exists(pathbuf))
264
+      return 0;
265
+    bp[-1] = s;
266
+  }
267
+
268
+  for (pslash = pp; *pslash && *pslash != '\\' && *pslash != '/';  pslash++)
269
+    if (!preserve_case)
270
+    {
271
+      if (*pslash >= 'A' && *pslash <= 'Z')
272
+      {
273
+	if (use_lfn)
274
+	  caseless = 0;
275
+	lower = 0;
276
+      }
277
+      else if (*pslash >= 'a' && *pslash <= 'z')
278
+	lower = 1;
279
+    }
280
+
281
+  if (*pslash)
282
+    slash = *pslash;
283
+  my_pattern = (char *)alloca(pslash - pp + 1);
284
+  if (my_pattern == 0)
285
+    return GLOB_NOSPACE;
286
+  strncpy(my_pattern, pp, pslash - pp);
287
+  my_pattern[pslash-pp] = 0;
288
+
289
+/*  printf("glob2: `%s' `%s'\n", pathbuf, my_pattern); */
290
+
291
+  if (strcmp(my_pattern, "...") == 0)
292
+  {
293
+    if (glob_dirs(*pslash ? pslash+1 : pslash, bp, 1, lower, caseless) == GLOB_NOSPACE)
294
+      return GLOB_NOSPACE;
295
+    return 0;
296
+  }
297
+
298
+  strcpy(bp, "*.*");
299
+
300
+  hf = FindFirstFile(pathbuf, &wfd);
301
+  done = (hf == INVALID_HANDLE_VALUE);
302
+  //done = findfirst(pathbuf, &ff, FA_RDONLY|FA_SYSTEM|FA_DIREC|FA_ARCH);
303
+  while (!done)
304
+  {
305
+    if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0
306
+	|| (strcmp(wfd.cFileName, ".") && strcmp(wfd.cFileName, "..")))
307
+    {
308
+      if (fnmatch(my_pattern, wfd.cFileName,
309
+		  FNM_NOESCAPE|FNM_PATHNAME|(caseless ? FNM_NOCASE : 0)) == 0)
310
+      {
311
+	strcpy(bp, wfd.cFileName);
312
+	if (*pslash)
313
+	{
314
+	  char *tp = bp + strlen(bp);
315
+	  *tp++ = *pslash;
316
+	  *tp = 0;
317
+/*	  printf("nest: `%s' `%s'\n", pslash+1, pathbuf); */
318
+	  wildcard_nesting++;
319
+	  if (glob2(pslash+1, tp, lower, caseless) == GLOB_NOSPACE)
320
+	    return GLOB_NOSPACE;
321
+	  wildcard_nesting--;
322
+	}
323
+	else
324
+	{
325
+/*	  printf("ffmatch: `%s' matching `%s', add `%s'\n",
326
+		 wfd.cFileName, my_pattern, pathbuf); */
327
+	  if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && (flags & GLOB_MARK))
328
+	  {
329
+	    bp[strlen(bp)+1] = 0;
330
+	    bp[strlen(bp)] = slash;
331
+	  }
332
+	  if (add(pathbuf))
333
+	    return GLOB_NOSPACE;
334
+	}
335
+      }
336
+    }
337
+    done = !FindNextFile(hf, &wfd);
338
+  } 
339
+
340
+  return 0;
341
+}
342
+
343
+static int
344
+str_compare(const void *va, const void *vb)
345
+{
346
+  return strcmp(*(const char * const *)va, *(const char * const *)vb);
347
+}
348
+
349
+int
350
+glob(const char *_pattern, int _flags, int (*_errfunc)(const char *_epath, int _eerrno), glob_t *_pglob)
351
+{
352
+  char path_buffer[2000];
353
+  int l_ofs, l_ptr;
354
+
355
+  pathbuf = path_buffer+1;
356
+  flags = _flags;
357
+  errfunc = _errfunc;
358
+  wildcard_nesting = 0;
359
+  save_count = 0;
360
+  save_list = 0;
361
+  preserve_case = (char)_preserve_fncase();
362
+  slash = '/';
363
+
364
+  if (!(_flags & GLOB_APPEND)) 
365
+    {
366
+      _pglob->gl_pathc = 0;
367
+      _pglob->gl_pathv = NULL;
368
+      if (!(flags & GLOB_DOOFFS))
369
+        _pglob->gl_offs = 0;
370
+    }
371
+  if (glob2(_pattern, pathbuf, preserve_case ? 0 : 1, /*preserve_case ? 0 :*/ 1) == GLOB_NOSPACE)
372
+    {
373
+      return GLOB_NOSPACE;
374
+    }
375
+
376
+  if (save_count == 0)
377
+  {
378
+    if (flags & GLOB_NOCHECK)
379
+    {
380
+      if (add(_pattern))
381
+	return GLOB_NOSPACE;
382
+    }
383
+    else
384
+      return GLOB_NOMATCH;
385
+  }
386
+
387
+  if (flags & GLOB_DOOFFS)
388
+    l_ofs = _pglob->gl_offs;
389
+  else
390
+    l_ofs = 0;
391
+
392
+  if (flags & GLOB_APPEND)
393
+  {
394
+    _pglob->gl_pathv = (char **)realloc(_pglob->gl_pathv, (l_ofs + _pglob->gl_pathc + save_count + 1) * sizeof(char *));
395
+    if (_pglob->gl_pathv == 0)
396
+      return GLOB_NOSPACE;
397
+    l_ptr = l_ofs + _pglob->gl_pathc;
398
+  }
399
+  else
400
+  {
401
+    _pglob->gl_pathv = (char* *)malloc((l_ofs + save_count + 1) * sizeof(char *));
402
+    if (_pglob->gl_pathv == 0)
403
+      return GLOB_NOSPACE;
404
+    l_ptr = l_ofs;
405
+    if (l_ofs)
406
+      memset(_pglob->gl_pathv, 0, l_ofs * sizeof(char *));
407
+  }
408
+
409
+  l_ptr += save_count;
410
+  _pglob->gl_pathv[l_ptr] = 0;
411
+  while (save_list)
412
+  {
413
+    Save *s = save_list;
414
+    l_ptr --;
415
+    _pglob->gl_pathv[l_ptr] = save_list->entry;
416
+    save_list = save_list->prev;
417
+    free(s);
418
+  }
419
+  if (!(flags & GLOB_NOSORT))
420
+    qsort(_pglob->gl_pathv + l_ptr, save_count, sizeof(char *), str_compare);
421
+
422
+  _pglob->gl_pathc = l_ptr + save_count;
423
+
424
+  return 0;
425
+}
426
+#endif // NEEDS_GLOB
427
+

+ 20
- 0
src/globfree.c View File

@@ -0,0 +1,20 @@
1
+/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
2
+#include <cl/needs.h>
3
+
4
+#ifdef NEEDS_GLOB
5
+#define Uses_stdlib
6
+#define Uses_glob
7
+#define Uses_free
8
+#include <compatlayer.h>
9
+
10
+void globfree(glob_t *_pglob)
11
+{
12
+  size_t i;
13
+  if (!_pglob->gl_pathv)
14
+    return;
15
+  for (i=0; i<_pglob->gl_pathc; i++)
16
+    if (_pglob->gl_pathv[i])
17
+      free(_pglob->gl_pathv[i]);
18
+  free(_pglob->gl_pathv);
19
+}
20
+#endif // NEEDS_GLOB