Browse Source

added posix compat layer for NT

master
despair 1 year ago
parent
commit
05b2db8a4f

+ 7
- 1
NTMakefile View File

@@ -83,7 +83,7 @@ netrunner.res.o: netrunner.rc
windres $^ -o $@
@rm favicon.ico
netrunner: $(OBJECTS) $(OBJDIR)/tlsf.o $(OBJDIR)/slre.o netrunner.res.o
netrunner: $(OBJECTS) $(OBJDIR)/tlsf.o $(OBJDIR)/slre.o netrunner.res.o $(OBJDIR)/glob.o $(OBJDIR)/fnmatch.o
$(LINK) $(LDFLAGS) -o $@ $^ $(LIBS)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
@@ -98,6 +98,12 @@ $(OBJDIR)/tlsf.o: $(SRCDIR)/tlsf.c
$(OBJDIR)/slre.o: $(SRCDIR)/slre.c
$(CC) $(INCPATH) $(CWARN) -c -o $@ $<
$(OBJDIR)/glob.o: $(SRCDIR)/glob.c
$(CC) $(INCPATH) $(CWARN) -c -o $@ $<
$(OBJDIR)/fnmatch.o: $(SRCDIR)/fnmatch.c
$(CC) $(INCPATH) $(CWARN) -c -o $@ $<
$(DEPDIR)/%d: ;
.PRECIOUS: $(DEPDIR)/%.d

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

@@ -0,0 +1,53 @@
#ifndef __DIR_H
#define __DIR_H

#include <direct.h>

#ifndef MAX_PATH
#define MAX_PATH 260
#endif
#ifndef MAXPATH
#define MAXPATH MAX_PATH
#endif

#ifndef FA_NORMAL
#define FA_NORMAL 0x00 /* Normal file, no attributes */
#define FA_RDONLY 0x01 /* Read only attribute */
#define FA_HIDDEN 0x02 /* Hidden file */
#define FA_SYSTEM 0x04 /* System file */
#define FA_LABEL 0x08 /* Volume label */
#define FA_DIREC 0x10 /* Directory */
#define FA_ARCH 0x00 /* Archive */
#endif /* FA_NORMAL */

#ifndef _FFBLK_DEF
#define _FFBLK_DEF
struct ffblk {
long ff_reserved;
long ff_fsize;
unsigned long ff_attrib;
unsigned short ff_ftime;
unsigned short ff_fdate;
char ff_name[MAXPATH];
};
#endif

#define getdisk() (_getdrive() + 1)


#ifdef __cplusplus
extern "C" {
#endif

int findfirst( const char *__path,
struct ffblk *__ffblk,
int __attrib );
int findnext( struct ffblk *__ffblk );
int findclose( struct ffblk *__ffblk );

#ifdef __cplusplus
}
#endif


#endif /* __DIR_H */

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

@@ -0,0 +1,43 @@
/* vi: set ts=8 sw=4 : */
/********************************************************************\
*File : dirent.h
*
*Subject:
* Substitution of Unix dirent.h for Win32
*
*Authors:
* SAA Anatoli Soltan
*
*HISTORY:
* Feb 18 1997 SAA
* initial implementation; struct dirent has only
* one field: d_name
* Mar 15 2000 SAA added __cplusplus condition
*********************************************************************/

#ifndef __DIRENT_H
#define __DIRENT_H

#include <stdlib.h> /* _MAX_FNAME */

#ifdef __cplusplus
extern "C" {
#endif

struct dirent
{
char d_name[_MAX_FNAME];
};

struct _DIR;
typedef struct _DIR DIR;

DIR* opendir(const char* name);
struct dirent* readdir(DIR* dir);
int closedir(DIR* dir);

#ifdef __cplusplus
}
#endif

#endif /* __DIRENT_H */

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

@@ -0,0 +1,22 @@
#ifndef __FNMATCH_H
#define __FNMATCH_H

#ifdef __cplusplus
extern "C" {
#endif

#define FNM_NOESCAPE 0x01
#define FNM_PATHNAME 0x02
#define FNM_PERIOD 0x04
#define FNM_NOCASE 0x08

#define FNM_NOMATCH 1
#define FNM_ERROR 2

int fnmatch(const char *_pattern, const char *_string, int _flags);

#ifdef __cplusplus
}
#endif

#endif /* __FNMATCH_H */

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

@@ -0,0 +1,112 @@
/* Declarations for getopt.
Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
Copyright (C) 2000, 01, 2002 Salvador E. Tropea.

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */

#ifndef HEADER_GETOPT_H
#define HEADER_GETOPT_H 1

#ifdef __cplusplus
extern "C" {
#endif

/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */

extern char *CLY_optarg;

/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.

On entry to `getopt', zero means this is the first call; initialize.

When `getopt' returns EOF, this is the index of the first of the
non-option elements that the caller should itself scan.

Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */

extern int CLY_optind;

/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */

extern int CLY_opterr;

/* Set to an option character which was unrecognized. */

extern int CLY_optopt;

/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
zero.

The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.

If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.

To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */

struct CLY_option
{
const char *name;
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
};

/* Names for the values of the `has_arg' field of `struct option'. */

#define CLY_no_argument 0
#define CLY_required_argument 1
#define CLY_optional_argument 2

extern int CLY_getopt(int argc, char *const *argv, const char *shortopts);
extern int CLY_getopt_long(int argc, char *const *argv, const char *shortopts,
const struct CLY_option *longopts, int *longind);
extern int CLY_getopt_long_only(int argc, char *const *argv,
const char *shortopts,
const struct CLY_option *longopts,
int *longind);
/* Internal only. Users should not call this directly. */
extern int CLY_getopt_internal(int argc, char *const *argv,
const char *shortopts,
const struct CLY_option *longopts,
int *longind,
int long_only);

#ifdef __cplusplus
}
#endif

#endif /* HEADER_GETOPT_H */

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

@@ -0,0 +1,37 @@
#ifndef __GLOB_H
#define __GLOB_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h>
#include <sys/types.h>

typedef struct {
size_t gl_pathc;
char **gl_pathv;
size_t gl_offs;
} glob_t;

#define GLOB_APPEND 0x01
#define GLOB_DOOFFS 0x02
#define GLOB_ERR 0x04
#define GLOB_MARK 0x08
#define GLOB_NOCHECK 0x10
#define GLOB_NOESCAPE 0x20
#define GLOB_NOSORT 0x40
#define GLOB_TILDE (1 << 12) /* Expand ~user and ~ to home directories. */
#define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error if the user name is not available. */
#define GLOB_ABORTED 1
#define GLOB_NOMATCH 2
#define GLOB_NOSPACE 3

int glob(const char *_pattern, int _flags, int (*_errfunc)(const char *_epath, int _eerrno), glob_t *_pglob);
void globfree(glob_t *_pglob);

#ifdef __cplusplus
}
#endif

#endif /* __GLOB_H */

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

@@ -0,0 +1,157 @@
/**[txh]********************************************************************

Description:
This header defines which functions must be defined for each supported
compiler.@p

Copyright (c) 2000-2005 by Salvador E. Tropea
Covered by the GPL license.

***************************************************************************/

#define TVOS_Win32
#define TVOSf_
#define TVCPU_x86
#define TVComp_GCC
#define TVCompf_MinGW

#ifdef TVComp_GCC
// GNU c is supported for various OSs:
#define NEEDS_GETCURDIR
// Win32 MinGW
#ifdef TVCompf_MinGW
#define NEEDS_FIXPATH
#define NEEDS_GLOB
#define NEEDS_FNMATCH
#define NEEDS_REGEX
#define NEEDS_GETOPT
#define NEEDS_MKSTEMP
#define NEEDS_NL_LANGINFO
#define NEEDS_GETLINE
// Internal implementation is broken. Is the same provided by MSVC.
#define NEEDS_SNPRINTF
#endif
// Win32 Cygwin
#ifdef TVCompf_Cygwin
#define NEEDS_FIXPATH
#define NEEDS_FILELENGTH
#define NEEDS_NL_LANGINFO
#define NEEDS_FNMATCH
#define NEEDS_ITOA
#define NEEDS_GETLINE
#endif
// DOS djgpp
#ifdef TVCompf_djgpp
#define NEEDS_GETOPT
#define NEEDS_NL_LANGINFO
#define NEEDS_GETLINE
#define NEEDS_SNPRINTF
#endif
// Linux
#ifdef TVOSf_Linux
// Strings
#define NEEDS_STRLWR
#define NEEDS_STRUPR
#define NEEDS_FIXPATH
#define NEEDS_FILELENGTH
#define NEEDS_ITOA
#endif
// Solaris
#ifdef TVOSf_Solaris
// Strings
#define NEEDS_STRLWR
#define NEEDS_STRUPR
#define NEEDS_GETOPT
#define NEEDS_FIXPATH
#define NEEDS_FILELENGTH
#define NEEDS_ITOA
#define NEEDS_NL_LANGINFO
#define NEEDS_GETLINE
#define NEEDS_SNPRINTF
#endif

#ifdef TVOSf_QNX4
#define NEEDS_SNPRINTF
#endif // TVOSf_QNX4

#ifdef TVOSf_Darwin
#define NEEDS_SNPRINTF
#endif

// Generic UNIX system
#if defined(TVOS_UNIX) && !defined(TVOSf_Linux) && !defined(TVOSf_Solaris)
// Strings
#define NEEDS_STRLWR
#define NEEDS_STRUPR
#define NEEDS_FIXPATH
#define NEEDS_FILELENGTH
#define NEEDS_ITOA
#define NEEDS_NL_LANGINFO
#define NEEDS_GETLINE
#if defined(TVOSf_FreeBSD) || defined(TVOSf_QNXRtP) || defined(TVOSf_QNX4) \
|| defined(TVOSf_Darwin)
// Not for OpenBSD and NetBSD
#define NEEDS_GETOPT
#endif
#endif
#endif


// BC++ 5.5 for Win32 is supported
#ifdef TVComp_BCPP
#define NEEDS_FIXPATH
#define NEEDS_GLOB
#define NEEDS_FNMATCH
#define NEEDS_UNC
#define NEEDS_REGEX
#define NEEDS_GETOPT
#define NEEDS_OPENDIR
#define NEEDS_MKSTEMP
#define NEEDS_NL_LANGINFO
#define NEEDS_IFSTREAMGETLINE
#define NEEDS_GETLINE
#endif


// MSVC will be supported if volunteers tests it or Microsoft decides to
// give it for free ;-). After all Borland released BC++ 5.5.
#if (defined(_MSVC) || defined(__MSC_VER)) && !defined(_MSC_VER)
#define _MSC_VER 100
#endif

#ifdef TVComp_MSC
#define NEEDS_GETCURDIR
#define NEEDS_FIXPATH
#define NEEDS_GLOB
#define NEEDS_FNMATCH
#define NEEDS_REGEX
#define NEEDS_GETOPT
#define NEEDS_MKSTEMP
#define NEEDS_NL_LANGINFO
#define NEEDS_GETLINE
#define NEEDS_OPENDIR
// Internal implementation is broken.
#define NEEDS_SNPRINTF
#define NEEDS_UNC
#endif

// Open Watcom for Win32 is supported
#ifdef TVComp_Watcom
#define NEEDS_FIXPATH
#define NEEDS_GLOB
#define NEEDS_FNMATCH
#define NEEDS_UNC
#define NEEDS_GETOPT
#define NEEDS_OPENDIR
#define NEEDS_NL_LANGINFO
#define NEEDS_IFSTREAMGETLINE
#define NEEDS_GETLINE
#define NEEDS_GETCURDIR
#endif


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

@@ -0,0 +1,499 @@
/* Definitions for data structures and routines for the regular
expression library, version 0.12.

Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */

#ifndef __REGEXP_LIBRARY_H__
#define __REGEXP_LIBRARY_H__

/* POSIX says that <sys/types.h> must be included (by the caller) before
<regex.h>. */

#ifdef VMS
/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
should be there. */
#include <stddef.h>
#endif

#include <stddef.h>

/* The following bits are used to determine the regexp syntax we
recognize. The set/not-set meanings are chosen so that Emacs syntax
remains the value 0. The bits are given in alphabetical order, and
the definitions shifted by one from the previous bit; thus, when we
add or remove a bit, only one other definition need change. */
typedef unsigned reg_syntax_t;

/* If this bit is not set, then \ inside a bracket expression is literal.
If set, then such a \ quotes the following character. */
#define RE_BACKSLASH_ESCAPE_IN_LISTS (1)

/* If this bit is not set, then + and ? are operators, and \+ and \? are
literals.
If set, then \+ and \? are operators and + and ? are literals. */
#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)

/* If this bit is set, then character classes are supported. They are:
[:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
[:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
If not set, then character classes are not supported. */
#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)

/* If this bit is set, then ^ and $ are always anchors (outside bracket
expressions, of course).
If this bit is not set, then it depends:
^ is an anchor if it is at the beginning of a regular
expression or after an open-group or an alternation operator;
$ is an anchor if it is at the end of a regular expression, or
before a close-group or an alternation operator.

This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
POSIX draft 11.2 says that * etc. in leading positions is undefined.
We already implemented a previous draft which made those constructs
invalid, though, so we haven't changed the code back. */
#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)

/* If this bit is set, then special characters are always special
regardless of where they are in the pattern.
If this bit is not set, then special characters are special only in
some contexts; otherwise they are ordinary. Specifically,
* + ? and intervals are only special when not after the beginning,
open-group, or alternation operator. */
#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)

/* If this bit is set, then *, +, ?, and { cannot be first in an re or
immediately after an alternation or begin-group operator. */
#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)

/* If this bit is set, then . matches newline.
If not set, then it doesn't. */
#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)

/* If this bit is set, then . doesn't match NUL.
If not set, then it does. */
#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)

/* If this bit is set, nonmatching lists [^...] do not match newline.
If not set, they do. */
#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)

/* If this bit is set, either \{...\} or {...} defines an
interval, depending on RE_NO_BK_BRACES.
If not set, \{, \}, {, and } are literals. */
#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)

/* If this bit is set, +, ? and | aren't recognized as operators.
If not set, they are. */
#define RE_LIMITED_OPS (RE_INTERVALS << 1)

/* If this bit is set, newline is an alternation operator.
If not set, newline is literal. */
#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)

/* If this bit is set, then `{...}' defines an interval, and \{ and \}
are literals.
If not set, then `\{...\}' defines an interval. */
#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)

/* If this bit is set, (...) defines a group, and \( and \) are literals.
If not set, \(...\) defines a group, and ( and ) are literals. */
#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)

/* If this bit is set, then \<digit> matches <digit>.
If not set, then \<digit> is a back-reference. */
#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)

/* If this bit is set, then | is an alternation operator, and \| is literal.
If not set, then \| is an alternation operator, and | is literal. */
#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)

/* If this bit is set, then an ending range point collating higher
than the starting range point, as in [z-a], is invalid.
If not set, then when ending range point collates higher than the
starting range point, the range is ignored. */
#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)

/* If this bit is set, then an unmatched ) is ordinary.
If not set, then an unmatched ) is invalid. */
#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)

/* This global variable defines the particular regexp syntax to use (for
some interfaces). When a regexp is compiled, the syntax used is
stored in the pattern buffer, so changing this does not affect
already-compiled regexps. */
extern reg_syntax_t re_syntax_options;
/* Define combinations of the above bits for the standard possibilities.
(The [[[ comments delimit what gets put into the Texinfo file, so
don't delete them!) */
/* [[[begin syntaxes]]] */
#define RE_SYNTAX_EMACS 0

#define RE_SYNTAX_AWK \
(RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
| RE_NO_BK_PARENS | RE_NO_BK_REFS \
| RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
| RE_UNMATCHED_RIGHT_PAREN_ORD)

#define RE_SYNTAX_POSIX_AWK \
(RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)

#define RE_SYNTAX_GREP \
(RE_BK_PLUS_QM | RE_CHAR_CLASSES \
| RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
| RE_NEWLINE_ALT)

#define RE_SYNTAX_EGREP \
(RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
| RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
| RE_NEWLINE_ALT | RE_NO_BK_PARENS \
| RE_NO_BK_VBAR)

#define RE_SYNTAX_POSIX_EGREP \
(RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)

/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC

#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC

/* Syntax bits common to both basic and extended POSIX regex syntax. */
#define _RE_SYNTAX_POSIX_COMMON \
(RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
| RE_INTERVALS | RE_NO_EMPTY_RANGES)

#define RE_SYNTAX_POSIX_BASIC \
(_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)

/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
isn't minimal, since other operators, such as \`, aren't disabled. */
#define RE_SYNTAX_POSIX_MINIMAL_BASIC \
(_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)

#define RE_SYNTAX_POSIX_EXTENDED \
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
| RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
| RE_NO_BK_PARENS | RE_NO_BK_VBAR \
| RE_UNMATCHED_RIGHT_PAREN_ORD)

/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */
#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
| RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
| RE_NO_BK_PARENS | RE_NO_BK_REFS \
| RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
/* [[[end syntaxes]]] */
/* Maximum number of duplicates an interval can allow. Some systems
(erroneously) define this in other header files, but we want our
value, so remove any previous define. */
#ifdef RE_DUP_MAX
#undef RE_DUP_MAX
#endif
#define RE_DUP_MAX ((1 << 15) - 1)


/* POSIX `cflags' bits (i.e., information for `regcomp'). */

/* If this bit is set, then use extended regular expression syntax.
If not set, then use basic regular expression syntax. */
#define REG_EXTENDED 1

/* If this bit is set, then ignore case when matching.
If not set, then case is significant. */
#define REG_ICASE (REG_EXTENDED << 1)
/* If this bit is set, then anchors do not match at newline
characters in the string.
If not set, then anchors do match at newlines. */
#define REG_NEWLINE (REG_ICASE << 1)

/* If this bit is set, then report only success or fail in regexec.
If not set, then returns differ between not matching and errors. */
#define REG_NOSUB (REG_NEWLINE << 1)


/* POSIX `eflags' bits (i.e., information for regexec). */

/* If this bit is set, then the beginning-of-line operator doesn't match
the beginning of the string (presumably because it's not the
beginning of a line).
If not set, then the beginning-of-line operator does match the
beginning of the string. */
#define REG_NOTBOL 1

/* Like REG_NOTBOL, except for the end-of-line. */
#define REG_NOTEOL (1 << 1)


/* If any error codes are removed, changed, or added, update the
`re_error_msg' table in regex.c. */
typedef enum
{
REG_NOERROR = 0, /* Success. */
REG_NOMATCH, /* Didn't find a match (for regexec). */

/* POSIX regcomp return error codes. (In the order listed in the
standard.) */
REG_BADPAT, /* Invalid pattern. */
REG_ECOLLATE, /* Not implemented. */
REG_ECTYPE, /* Invalid character class name. */
REG_EESCAPE, /* Trailing backslash. */
REG_ESUBREG, /* Invalid back reference. */
REG_EBRACK, /* Unmatched left bracket. */
REG_EPAREN, /* Parenthesis imbalance. */
REG_EBRACE, /* Unmatched \{. */
REG_BADBR, /* Invalid contents of \{\}. */
REG_ERANGE, /* Invalid range end. */
REG_ESPACE, /* Ran out of memory. */
REG_BADRPT, /* No preceding re for repetition op. */

/* Error codes we've added. */
REG_EEND, /* Premature end. */
REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
} reg_errcode_t;
/* This data structure represents a compiled pattern. Before calling
the pattern compiler, the fields `buffer', `allocated', `fastmap',
`translate', and `no_sub' can be set. After the pattern has been
compiled, the `re_nsub' field is available. All other fields are
private to the regex routines. */

struct re_pattern_buffer
{
/* [[[begin pattern_buffer]]] */
/* Space that holds the compiled pattern. It is declared as
`unsigned char *' because its elements are
sometimes used as array indexes. */
unsigned char *buffer;

/* Number of bytes to which `buffer' points. */
unsigned long allocated;

/* Number of bytes actually used in `buffer'. */
unsigned long used;

/* Syntax setting with which the pattern was compiled. */
reg_syntax_t syntax;

/* Pointer to a fastmap, if any, otherwise zero. re_search uses
the fastmap, if there is one, to skip over impossible
starting points for matches. */
char *fastmap;

/* Either a translate table to apply to all characters before
comparing them, or zero for no translation. The translation
is applied to a pattern when it is compiled and to a string
when it is matched. */
char *translate;

/* Number of subexpressions found by the compiler. */
size_t re_nsub;

/* Zero if this pattern cannot match the empty string, one else.
Well, in truth it's used only in `re_search_2', to see
whether or not we should use the fastmap, so we don't set
this absolutely perfectly; see `re_compile_fastmap' (the
`duplicate' case). */
unsigned can_be_null : 1;

/* If REGS_UNALLOCATED, allocate space in the `regs' structure
for `max (RE_NREGS, re_nsub + 1)' groups.
If REGS_REALLOCATE, reallocate space if necessary.
If REGS_FIXED, use what's there. */
#define REGS_UNALLOCATED 0
#define REGS_REALLOCATE 1
#define REGS_FIXED 2
unsigned regs_allocated : 2;

/* Set to zero when `regex_compile' compiles a pattern; set to one
by `re_compile_fastmap' if it updates the fastmap. */
unsigned fastmap_accurate : 1;

/* If set, `re_match_2' does not return information about
subexpressions. */
unsigned no_sub : 1;

/* If set, a beginning-of-line anchor doesn't match at the
beginning of the string. */
unsigned not_bol : 1;

/* Similarly for an end-of-line anchor. */
unsigned not_eol : 1;

/* If true, an anchor at a newline matches. */
unsigned newline_anchor : 1;

/* [[[end pattern_buffer]]] */
};

typedef struct re_pattern_buffer regex_t;


/* search.c (search_buffer) in Emacs needs this one opcode value. It is
defined both in `regex.c' and here. */
#define RE_EXACTN_VALUE 1
/* Type for byte offsets within the string. POSIX mandates this. */
typedef int regoff_t;


/* This is the structure we store register match data in. See
regex.texinfo for a full description of what registers match. */
struct re_registers
{
unsigned num_regs;
regoff_t *start;
regoff_t *end;
};


/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
`re_match_2' returns information about at least this many registers
the first time a `regs' structure is passed. */
#ifndef RE_NREGS
#define RE_NREGS 30
#endif


/* POSIX specification for registers. Aside from the different names than
`re_registers', POSIX uses an array of structures, instead of a
structure of arrays. */
typedef struct
{
regoff_t rm_so; /* Byte offset from string's start to substring's start. */
regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
} regmatch_t;
/* Declarations for routines. */

/* To avoid duplicating every routine declaration -- once with a
prototype (if we are ANSI), and once without (if we aren't) -- we
use the following macro to declare argument types. This
unfortunately clutters up the declarations a bit, but I think it's
worth it. */

#if __STDC__ || defined(__cplusplus)

#define _RE_ARGS(args) args

#else /* not __STDC__ */

#define _RE_ARGS(args) ()

#endif /* not __STDC__ */

#ifdef __cplusplus
extern "C" {
#endif

/* Sets the current default syntax to SYNTAX, and return the old syntax.
You can also simply assign to the `re_syntax_options' variable. */
extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));

/* Compile the regular expression PATTERN, with length LENGTH
and syntax given by the global `re_syntax_options', into the buffer
BUFFER. Return NULL if successful, and an error string if not. */
extern const char *re_compile_pattern
_RE_ARGS ((const char *pattern, int length,
struct re_pattern_buffer *buffer));


/* Compile a fastmap for the compiled pattern in BUFFER; used to
accelerate searches. Return 0 if successful and -2 if was an
internal error. */
extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));


/* Search in the string STRING (with length LENGTH) for the pattern
compiled into BUFFER. Start searching at position START, for RANGE
characters. Return the starting position of the match, -1 for no
match, or -2 for an internal error. Also return register
information in REGS (if REGS and BUFFER->no_sub are nonzero). */
extern int re_search
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
int length, int start, int range, struct re_registers *regs));


/* Like `re_search', but search in the concatenation of STRING1 and
STRING2. Also, stop searching at index START + STOP. */
extern int re_search_2
_RE_ARGS (( struct re_pattern_buffer *bufp,
const char *string1, const char *string2, int size1, int size2,
int startpos, int range, struct re_registers *regs, int stop ));

/* Like `re_search', but return how many characters in STRING the regexp
in BUFFER matched, starting at position START. */
extern int re_match
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
int length, int start, struct re_registers *regs));


/* Relates to `re_match' as `re_search_2' relates to `re_search'. */
extern int re_match_2
_RE_ARGS (( struct re_pattern_buffer *bufp, const char *string1,
const char *string2, int size1, int size2, int pos,
struct re_registers *regs, int stop ));


/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
ENDS. Subsequent matches using BUFFER and REGS will use this memory
for recording register information. STARTS and ENDS must be
allocated with malloc, and must each be at least `NUM_REGS * sizeof
(regoff_t)' bytes long.

If NUM_REGS == 0, then subsequent matches should allocate their own
register data.

Unless this function is called, the first search or match using
PATTERN_BUFFER will allocate its own register data, without
freeing the old data. */
extern void re_set_registers
_RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
unsigned num_regs, regoff_t *starts, regoff_t *ends));

/* 4.2 bsd compatibility. */
extern char *re_comp _RE_ARGS ((const char *));
extern int re_exec _RE_ARGS ((const char *));

/* POSIX compatibility. */
extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags));
extern int regexec
_RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags));
extern size_t regerror
_RE_ARGS ((int errcode, const regex_t *preg, char *errbuf,
size_t errbuf_size));
extern void regfree _RE_ARGS ((regex_t *preg));

#ifdef __cplusplus
}
#endif


#endif /* not __REGEXP_LIBRARY_H__ */
/*
Local variables:
make-backup-files: t
version-control: t
trim-versions-without-asking: nil
End:
*/

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

@@ -0,0 +1,6 @@
#ifndef __STRSTREAM_H
#define __STRSTREAM_H

#include <strstrea.h>

#endif /* __STRSTREAM_H */

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

@@ -0,0 +1,26 @@
#ifndef __UNISTD_H
#define __UNISTD_H

//#define PATH_MAX MAXPATH

#ifndef F_OK
#define F_OK 0
#endif

#ifndef R_OK
#define R_OK 4
#endif

#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif

#ifndef STDOUT_FILENO
#define STDOUT_FILENO 1
#endif

#ifndef STDERR_FILENO
#define STDERR_FILENO 2
#endif

#endif /* __UNISTD_H */

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

@@ -0,0 +1,20 @@
#ifndef UTime_Included
#define UTime_Included

#ifdef __cplusplus
extern "C" {
#endif

struct utimbuf
{
time_t actime;
time_t modtime;
};

int utime(const char *file, const struct utimbuf *time);

#ifdef __cplusplus
}
#endif

#endif /* UTime_Included */

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

@@ -0,0 +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 @@
#include "interfaces/components/ButtonComponent.h"

#include <fstream>
#ifndef _WIN32
#include <glob.h>
#else
#include <cl/glob.h>
#endif

// why can't I const this?
std::unique_ptr<Scheduler> scheduler = std::make_unique<Scheduler>();

+ 150
- 0
src/fnmatch.c View File

@@ -0,0 +1,150 @@
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* Modified for Win32 by Anatoli Soltan */
#include <cl/needs.h>

#ifdef NEEDS_FNMATCH
#include <string.h>
#include <ctype.h>
#define Uses_fnmatch
#include <compatlayer.h>

#define EOS '\0'

static const char *rangematch(const char *pattern, char test, int nocase);

#define isslash(c) ((c) == '\\' || (c) == '/')

static const char *
find_slash(const char *s)
{
while (*s)
{
if (isslash(*s))
return s;
s++;
}
return 0;
}

static const char *
rangematch(const char *pattern, char test, int nocase)
{
char c, c2;
int negate, ok;

if (!!(negate = (*pattern == '!')))
++pattern;

for (ok = 0; (c = *pattern++) != ']';)
{
if (c == 0)
return 0; /* illegal pattern */
if (*pattern == '-' && (c2 = pattern[1]) != 0 && c2 != ']')
{
if (c <= test && test <= c2)
ok = 1;
if (nocase && toupper(c) <= toupper(test) && toupper(test) <= toupper(c2))
ok = 1;
pattern += 2;
}
else if (c == test)
ok = 1;
else if (nocase && (toupper(c) == toupper(test)))
ok = 1;
}
return ok == negate ? NULL : pattern;
}

int
fnmatch(const char *pattern, const char *string, int flags)
{
char c;
char test;

for (;;)
switch ((c = *pattern++))
{
case 0:
return *string == 0 ? 0 : FNM_NOMATCH;

case '?':
if ((test = *string++) == 0 ||
(isslash(test) && (flags & FNM_PATHNAME)))
return(FNM_NOMATCH);
break;
case '*':
c = *pattern;
/* collapse multiple stars */
while (c == '*')
c = *++pattern;

/* optimize for pattern with * at end or before / */
if (c == 0)
{
if (flags & FNM_PATHNAME)
return find_slash(string) ? FNM_NOMATCH : 0;
else
return 0;
}
else if (isslash(c) && flags & FNM_PATHNAME)
{
if ((string = find_slash(string)) == NULL)
return FNM_NOMATCH;
break;
}

/* general case, use recursion */
while ((test = *string) != 0)
{
if (fnmatch(pattern, string, flags) == 0)
return(0);
if (isslash(test) && flags & FNM_PATHNAME)
break;
++string;
}
return FNM_NOMATCH;
case '[':
if ((test = *string++) == 0 ||
(isslash(test) && flags & FNM_PATHNAME))
return FNM_NOMATCH;
if ((pattern = rangematch(pattern, test, flags & FNM_NOCASE)) == NULL)
return FNM_NOMATCH;
break;
case '\\':
if (!(flags & FNM_NOESCAPE) && pattern[1] && strchr("*?[\\", pattern[1]))
{
if ((c = *pattern++) == 0)
{
c = '\\';
--pattern;
}
if (c != *string++)
return FNM_NOMATCH;
break;
}
/* FALLTHROUGH */

default:
if (isslash(c) && isslash(*string))
{
string++;
break;
}
if (flags & FNM_NOCASE)
{
if (toupper(c) != toupper(*string++))
return FNM_NOMATCH;
}
else
{
if (c != *string++)
return FNM_NOMATCH;
}
break;
}
}
#endif // NEEDS_FNMATCH

+ 427
- 0
src/glob.c View File

@@ -0,0 +1,427 @@
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* Modified for Win32 by Anatoli Soltan */

#include <cl/needs.h>

#ifdef NEEDS_GLOB
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <io.h>
#include <ctype.h>
#ifndef TVComp_MSC
#include <dir.h>
#endif

#define Uses_glob
#define Uses_unistd
#define Uses_fnmatch
#define Uses_alloca
#include <compatlayer.h>

typedef struct Save {
struct Save *prev;
char *entry;
} Save;

int CLY_FileExists(const char *fname)
{
return (access(fname,R_OK)==0);
}

static Save *save_list;
static int save_count;
static int flags;
static int (*errfunc)(const char *epath, int eerno);
static char *pathbuf;
static int wildcard_nesting;
static char use_lfn;
static char preserve_case;
static char slash;

static int glob2(const char *pattern, char *epathbuf, int lower, int caseless);
static int glob_dirs(const char *rest, char *epathbuf, int first, int lower, int caseless);
static int add(const char *path);
static int str_compare(const void *va, const void *vb);

static int _preserve_fncase(void)
{
return 1;
}

static int
add(const char *path)
{
Save *sp;
for (sp=save_list; sp; sp=sp->prev)
if (stricmp(sp->entry, path) == 0)
return 0;
sp = (Save *)malloc(sizeof(Save));
if (sp == 0)
return 1;
sp->entry = (char *)malloc(strlen(path)+1);
if (sp->entry == 0)
{
free(sp);
return 1;
}
/* printf("add: `%s'\n", path); */
strcpy(sp->entry, path);
sp->prev = save_list;
save_list = sp;
save_count++;
return 0;
}

static int
glob_dirs(const char *rest, char *epathbuf, int first, /* rest is ptr to null or ptr after slash, bp after slash */
int lower, int caseless)
{
// struct ffblk ff;
HANDLE hf;
WIN32_FIND_DATA wfd;
BOOL done;

/* printf("glob_dirs[%d]: rest=`%s' %c epathbuf=`%s' %c pathbuf=`%s'\n",
wildcard_nesting, rest, *rest, epathbuf, *epathbuf, pathbuf); */

if (first)
{
if (*rest)
{
if (glob2(rest, epathbuf, lower, caseless) == GLOB_NOSPACE)
return GLOB_NOSPACE;
}
else
{
char sl = epathbuf[-1];
*epathbuf = 0;
/* printf("end, checking `%s'\n", pathbuf); */
if (epathbuf == pathbuf)
{
epathbuf[0] = '.';
epathbuf[1] = 0;
}
else
epathbuf[-1] = 0;
if (__file_exists(pathbuf))
if (add(pathbuf))
return GLOB_NOSPACE;
epathbuf[-1] = sl;
}
}

strcpy(epathbuf, "*.*");
hf = FindFirstFile(pathbuf, &wfd);
done = (hf == INVALID_HANDLE_VALUE);
while (!done)
{
if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
&& (strcmp(wfd.cFileName, ".") && strcmp(wfd.cFileName, "..")))
{
char *tp;

strcpy(epathbuf, wfd.cFileName);
tp = epathbuf + strlen(epathbuf);
*tp++ = slash;
*tp = 0;

wildcard_nesting++;
if (*rest)
{
if (glob2(rest, tp, lower, caseless) == GLOB_NOSPACE)
return GLOB_NOSPACE;
}
else
{
if (!(flags & GLOB_MARK))
tp[-1] = 0;
if (add(pathbuf))
return GLOB_NOSPACE;
tp[-1] = slash;
}
*tp = 0;
if (glob_dirs(rest, tp, 0, lower, caseless) == GLOB_NOSPACE)
return GLOB_NOSPACE;
wildcard_nesting--;
}
done = !FindNextFile(hf, &wfd);
}
FindClose(hf);
return 0;
}

static int
glob2(const char *pattern, char *epathbuf, /* both point *after* the slash */
int lower, int caseless)
{
const char *pp, *pslash;
char *bp;
HANDLE hf;
WIN32_FIND_DATA wfd;
char *my_pattern;
int done;

if (strcmp(pattern, "...") == 0)
{
return glob_dirs(pattern+3, epathbuf, 1, lower, caseless);
}
if (strncmp(pattern, "...", 3) == 0 && (pattern[3] == '\\' || pattern[3] == '/'))
{
slash = pattern[3];
return glob_dirs(pattern+4, epathbuf, 1, lower, caseless);
}

*epathbuf = 0;
/* copy as many non-wildcard segments as possible */
pp = pattern;
bp = epathbuf;
pslash = bp-1;
while (1)
{
if (*pp == ':' || *pp == '\\' || *pp == '/')
{
pslash = bp;
if (strcmp(pp+1, "...") == 0
|| (strncmp(pp+1, "...", 3) == 0 && (pp[4] == '/' || pp[4] == '\\')))
{
if (*pp != ':')
slash = *pp;
/* printf("glob2: dots at `%s'\n", pp); */
*bp++ = *pp++;
break;
}
}

else if (*pp == '*' || *pp == '?' || *pp == '[')
{
if (pslash > pathbuf)
strncpy(epathbuf, pattern, pslash - pathbuf);
pp = pattern + (pslash - epathbuf) + 1;
bp = epathbuf + (pslash - epathbuf) + 1;
break;
}

else if (*pp == 0)
{
break;
}

/* Upper-case or mixed-case patterns force case-sensitive
matches in `fnmatch' for LFN filesystems. They also
suppress downcasing 8+3 filenames (on all filesystems). */
else if (!preserve_case)
{
if (*pp >= 'A' && *pp <= 'Z')
{
if (use_lfn)
caseless = 0;
lower = 0;
}
else if (*pp >= 'a' && *pp <= 'z')
lower = 1;
}

*bp++ = *pp++;
}
*bp = 0;

if (*pp == 0) /* end of pattern? */
{
if (__file_exists(pathbuf))
{
if (flags & GLOB_MARK)
{
HANDLE _hf;
WIN32_FIND_DATA _wfd;
_hf = FindFirstFile(pathbuf, &_wfd);
//findfirst(pathbuf, &_ff, FA_RDONLY|FA_SYSTEM|FA_DIREC|FA_ARCH);
if (_hf != INVALID_HANDLE_VALUE && _wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
char *_pathbuf = pathbuf + strlen(pathbuf);
*_pathbuf++ = '/';
*_pathbuf = 0;
}
FindClose(_hf);
}
if (add(pathbuf))
return GLOB_NOSPACE;
}
return 0;
}
/* printf("glob2: initial segment is `%s'\n", pathbuf); */
if (wildcard_nesting)
{
char s = bp[-1];
bp[-1] = 0;
if (!__file_exists(pathbuf))
return 0;
bp[-1] = s;
}

for (pslash = pp; *pslash && *pslash != '\\' && *pslash != '/'; pslash++)
if (!preserve_case)
{
if (*pslash >= 'A' && *pslash <= 'Z')
{
if (use_lfn)
caseless = 0;
lower = 0;
}
else if (*pslash >= 'a' && *pslash <= 'z')
lower = 1;
}

if (*pslash)
slash = *pslash;
my_pattern = (char *)alloca(pslash - pp + 1);
if (my_pattern == 0)
return GLOB_NOSPACE;
strncpy(my_pattern, pp, pslash - pp);
my_pattern[pslash-pp] = 0;

/* printf("glob2: `%s' `%s'\n", pathbuf, my_pattern); */

if (strcmp(my_pattern, "...") == 0)
{
if (glob_dirs(*pslash ? pslash+1 : pslash, bp, 1, lower, caseless) == GLOB_NOSPACE)
return GLOB_NOSPACE;
return 0;
}

strcpy(bp, "*.*");

hf = FindFirstFile(pathbuf, &wfd);
done = (hf == INVALID_HANDLE_VALUE);
//done = findfirst(pathbuf, &ff, FA_RDONLY|FA_SYSTEM|FA_DIREC|FA_ARCH);
while (!done)
{
if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0
|| (strcmp(wfd.cFileName, ".") && strcmp(wfd.cFileName, "..")))
{
if (fnmatch(my_pattern, wfd.cFileName,
FNM_NOESCAPE|FNM_PATHNAME|(caseless ? FNM_NOCASE : 0)) == 0)
{
strcpy(bp, wfd.cFileName);
if (*pslash)
{
char *tp = bp + strlen(bp);
*tp++ = *pslash;
*tp = 0;
/* printf("nest: `%s' `%s'\n", pslash+1, pathbuf); */
wildcard_nesting++;
if (glob2(pslash+1, tp, lower, caseless) == GLOB_NOSPACE)
return GLOB_NOSPACE;
wildcard_nesting--;
}
else
{
/* printf("ffmatch: `%s' matching `%s', add `%s'\n",
wfd.cFileName, my_pattern, pathbuf); */
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && (flags & GLOB_MARK))
{
bp[strlen(bp)+1] = 0;
bp[strlen(bp)] = slash;
}
if (add(pathbuf))
return GLOB_NOSPACE;
}
}
}
done = !FindNextFile(hf, &wfd);
}

return 0;
}

static int
str_compare(const void *va, const void *vb)
{
return strcmp(*(const char * const *)va, *(const char * const *)vb);
}

int
glob(const char *_pattern, int _flags, int (*_errfunc)(const char *_epath, int _eerrno), glob_t *_pglob)
{
char path_buffer[2000];
int l_ofs, l_ptr;

pathbuf = path_buffer+1;
flags = _flags;
errfunc = _errfunc;
wildcard_nesting = 0;
save_count = 0;
save_list = 0;
preserve_case = (char)_preserve_fncase();
slash = '/';

if (!(_flags & GLOB_APPEND))
{
_pglob->gl_pathc = 0;
_pglob->gl_pathv = NULL;
if (!(flags & GLOB_DOOFFS))
_pglob->gl_offs = 0;
}
if (glob2(_pattern, pathbuf, preserve_case ? 0 : 1, /*preserve_case ? 0 :*/ 1) == GLOB_NOSPACE)
{
return GLOB_NOSPACE;
}

if (save_count == 0)
{
if (flags & GLOB_NOCHECK)
{
if (add(_pattern))
return GLOB_NOSPACE;
}
else
return GLOB_NOMATCH;
}

if (flags & GLOB_DOOFFS)
l_ofs = _pglob->gl_offs;
else
l_ofs = 0;

if (flags & GLOB_APPEND)
{
_pglob->gl_pathv = (char **)realloc(_pglob->gl_pathv, (l_ofs + _pglob->gl_pathc + save_count + 1) * sizeof(char *));
if (_pglob->gl_pathv == 0)
return GLOB_NOSPACE;
l_ptr = l_ofs + _pglob->gl_pathc;
}
else
{
_pglob->gl_pathv = (char* *)malloc((l_ofs + save_count + 1) * sizeof(char *));
if (_pglob->gl_pathv == 0)
return GLOB_NOSPACE;
l_ptr = l_ofs;
if (l_ofs)
memset(_pglob->gl_pathv, 0, l_ofs * sizeof(char *));
}

l_ptr += save_count;
_pglob->gl_pathv[l_ptr] = 0;
while (save_list)
{
Save *s = save_list;
l_ptr --;
_pglob->gl_pathv[l_ptr] = save_list->entry;
save_list = save_list->prev;
free(s);
}
if (!(flags & GLOB_NOSORT))
qsort(_pglob->gl_pathv + l_ptr, save_count, sizeof(char *), str_compare);

_pglob->gl_pathc = l_ptr + save_count;

return 0;
}
#endif // NEEDS_GLOB


+ 20
- 0
src/globfree.c View File

@@ -0,0 +1,20 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <cl/needs.h>

#ifdef NEEDS_GLOB
#define Uses_stdlib
#define Uses_glob
#define Uses_free
#include <compatlayer.h>

void globfree(glob_t *_pglob)
{
size_t i;
if (!_pglob->gl_pathv)
return;
for (i=0; i<_pglob->gl_pathc; i++)
if (_pglob->gl_pathv[i])
free(_pglob->gl_pathv[i]);
free(_pglob->gl_pathv);
}
#endif // NEEDS_GLOB

Loading…
Cancel
Save