diff --git a/reactos/lib/3rdparty/mingw/_wgetopt.c b/reactos/lib/3rdparty/mingw/_wgetopt.c new file mode 100644 index 00000000000..91efed4d702 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/_wgetopt.c @@ -0,0 +1,15 @@ +/* $Id$ +*/ +/* + tgetopt -- POSIX-compliant implementation of getopt() with string-type-generic + semantics + + This is public domain software +*/ + +#include + +#define _UNICODE +#include "getopt.c" + +/* EOF */ diff --git a/reactos/lib/3rdparty/mingw/getopt.c b/reactos/lib/3rdparty/mingw/getopt.c new file mode 100644 index 00000000000..3b0bfedfec4 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/getopt.c @@ -0,0 +1,137 @@ +/* $Id$ +*/ +/* + tgetopt -- POSIX-compliant implementation of getopt() with string-type-generic + semantics + + This is public domain software +*/ + +#include +#include +#include + +#include "tgetopt.h" + +int _topterr = 1; +int _toptind = 1; +int _toptopt; +_TCHAR * _toptarg; + +int _tgetopt(int argc, _TCHAR * const argv[], const _TCHAR * optstring) +{ + static int s_nArgChar = 0; + _TCHAR * pcOptChar; + + /* we're done */ + if(_toptind >= argc) return -1; + + /* last time we reached the end of argv[_toptind] */ + if(s_nArgChar != 0 && argv[_toptind][s_nArgChar] == 0) + { + /* scan the next argument */ + ++ _toptind; + + /* we're done */ + if(_toptind >= argc) return -1; + + s_nArgChar = 0; + } + + /* first time we scan argv[_toptind] */ + if(s_nArgChar == 0) + { + /* argument is NULL - we're done */ + if(argv[_toptind] == NULL) + return (int)-1; + /* argument is empty - we're done */ + else if(argv[_toptind][0] == 0) + return (int)-1; + /* argument begins with '-' */ + else if(argv[_toptind][0] == _T('-')) + { + /* argument is "--" */ + if(argv[_toptind][1] == _T('-')) + { + /* increment optind */ + ++ _toptind; + s_nArgChar = 0; + + /* we're done */ + return (int)-1; + } + /* argument is "-" */ + else if(argv[_toptind][1] == 0) + { + /* we're done */ + return (int)-1; + } + /* possible option */ + else + ++ s_nArgChar; + } + /* argument doesn't begin with a dash - we're done */ + else + return (int)-1; + } + + /* return the current character */ + _toptopt = argv[_toptind][s_nArgChar]; + + /* advance to the next character */ + ++ s_nArgChar; + + /* unrecognized option */ + if(_toptopt == _T(':') || (pcOptChar = _tcschr(optstring, _toptopt)) == NULL) + { + /* print an error message */ + if(_topterr && optstring[0] != _T(':')) + _ftprintf(stderr, _T("%s: illegal option -- %c\n"), argv[0], _toptopt); + + /* return an error */ + return _T('?'); + } + + /* the option requires an argument */ + if(pcOptChar[1] == _T(':')) + { + /* we are at the end of the argument */ + if(argv[_toptind][s_nArgChar] == 0) + { + /* the argument of the option is the next argument */ + ++ _toptind; + s_nArgChar = 0; + + /* this is the last argument */ + if(_toptind >= argc) + { + /* print an error message */ + if(_topterr && optstring[0] != _T(':')) + { + _ftprintf + ( + stderr, + _T("%s: option requires an argument -- %c\n"), + argv[0], + _toptopt + ); + } + + /* return an error */ + return ((optstring[0] == _T(':')) ? _T(':') : _T('?')); + } + + /* return the argument */ + _toptarg = argv[_toptind]; + ++ _toptind; + } + /* the rest of the argument is the argument of the option */ + else + _toptarg = argv[_toptind] + s_nArgChar; + } + + /* success */ + return _toptopt; +} + +/* EOF */ diff --git a/reactos/lib/3rdparty/mingw/mingw.rbuild b/reactos/lib/3rdparty/mingw/mingw.rbuild index 5ff3c242f53..1ae99126f67 100644 --- a/reactos/lib/3rdparty/mingw/mingw.rbuild +++ b/reactos/lib/3rdparty/mingw/mingw.rbuild @@ -4,21 +4,30 @@ include - CRT_fp10.c + _newmode.c + _wgetopt.c + argv.c atonexit.c + binmode.c charmax.c cinitexe.c + CRT_fp10.c + crtdll.c + dllentry.c + dllmain.c gccmain.c + getopt.c gs_support.c merr.c mingw_helpers.c natstart.c - _newmode.c pesect.c - wildcard.c - xtxtmode.c - xncommod.c pseudo-reloc.c + tlssup.c + wildcard.c + xncommod.c + xthdloc.c + xtxtmode.c include diff --git a/reactos/lib/3rdparty/mingw/tgetopt.h b/reactos/lib/3rdparty/mingw/tgetopt.h new file mode 100644 index 00000000000..01e0b1ee489 --- /dev/null +++ b/reactos/lib/3rdparty/mingw/tgetopt.h @@ -0,0 +1,90 @@ +#ifndef _GETOPT_H +#define _GETOPT_H 1 + +#include + +#ifdef _UNICODE +#define _toption _woption +#define _toptarg _woptarg +#define _toptind _woptind +#define _topterr _wopterr +#define _toptopt _woptopt +#define _tgetopt _wgetopt +#define _tgetopt_long _wgetopt_long +#define _tgetopt_long_only _wgetopt_long_only +#define _tgetopt_internal _wgetopt_internal +#else +#define _toption option +#define _toptarg optarg +#define _toptind optind +#define _topterr opterr +#define _toptopt optopt +#define _tgetopt getopt +#define _tgetopt_long getopt_long +#define _tgetopt_long_only getopt_long_only +#define _tgetopt_internal _getopt_internal +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern char *optarg; +extern int optind; +extern int opterr; +extern int optopt; + +extern wchar_t *_woptarg; +extern int _woptind; +extern int _wopterr; +extern int _woptopt; + +struct option +{ + const char *name; + int has_arg; + int *flag; + int val; +}; + +struct _woption +{ + const wchar_t *name; + int has_arg; + int *flag; + int val; +}; + +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +extern int getopt (int argc, char *const *argv, const char *shortopts); +extern int getopt_long (int argc, char *const *argv, const char *shortopts, + const struct option *longopts, int *longind); +extern int getopt_long_only (int argc, char *const *argv, + const char *shortopts, const struct option *longopts, int *longind); + +extern int _wgetopt (int argc, wchar_t *const *argv, const wchar_t *shortopts); +extern int _wgetopt_long (int argc, wchar_t *const *argv, const wchar_t *shortopts, + const struct _woption *longopts, int *longind); +extern int _wgetopt_long_only (int argc, wchar_t *const *argv, + const wchar_t *shortopts, + const struct _woption *longopts, int *longind); + +extern int _getopt_internal (int argc, char *const *argv, + const char *shortopts, const struct option *longopts, int *longind, + int long_only); + +extern int _wgetopt_internal (int argc, wchar_t *const *argv, + const wchar_t *shortopts, + const struct _woption *longopts, int *longind, + int long_only); + +#ifdef __cplusplus +} +#endif + +#endif /* _GETOPT_H */ +