summaryrefslogtreecommitdiffstats
path: root/common/win/my_getopt-1.5
diff options
context:
space:
mode:
Diffstat (limited to 'common/win/my_getopt-1.5')
-rw-r--r--common/win/my_getopt-1.5/ChangeLog22
-rw-r--r--common/win/my_getopt-1.5/LICENSE22
-rw-r--r--common/win/my_getopt-1.5/Makefile26
-rw-r--r--common/win/my_getopt-1.5/README140
-rw-r--r--common/win/my_getopt-1.5/getopt.3288
-rw-r--r--common/win/my_getopt-1.5/getopt.h56
-rw-r--r--common/win/my_getopt-1.5/getopt.txt330
-rw-r--r--common/win/my_getopt-1.5/main.c387
-rw-r--r--common/win/my_getopt-1.5/my_getopt.c281
-rw-r--r--common/win/my_getopt-1.5/my_getopt.h72
10 files changed, 1624 insertions, 0 deletions
diff --git a/common/win/my_getopt-1.5/ChangeLog b/common/win/my_getopt-1.5/ChangeLog
new file mode 100644
index 00000000..a671fdb9
--- /dev/null
+++ b/common/win/my_getopt-1.5/ChangeLog
@@ -0,0 +1,22 @@
+2006-12-09 Benjamin C. W. Sittler <bsittler@>
+
+ * my_getopt.c: add my_getopt_reset to reset the argument parser
+
+ * README: updated email address, updated for version 1.5
+
+2002-07-26 Benjamin C. W. Sittler <bsittler@knownow.com>
+
+ * README: updated for version 1.4
+
+ * my_getopt.c: now we include <sys/types.h> explicitly for those
+ systems that narrowly (mis-)interpret ANSI C and POSIX
+ (_my_getopt_internal): added an explicit cast to size_t to make
+ g++ happy
+
+ * getopt.h, my_getopt.h: added extern "C" { ... } for C++
+ compilation (thanks to Jeff Lawson <bovine@ud.com> and others)
+
+2001-08-20 Benjamin C. W. Sittler <bsittler@knownow.com>
+
+ * getopt.h (getopt_long_only): fixed typo (thanks to Justin Lee
+ <justin_lee@ud.com>)
diff --git a/common/win/my_getopt-1.5/LICENSE b/common/win/my_getopt-1.5/LICENSE
new file mode 100644
index 00000000..2224aba0
--- /dev/null
+++ b/common/win/my_getopt-1.5/LICENSE
@@ -0,0 +1,22 @@
+my_getopt - a command-line argument parser
+Copyright 1997-2001, Benjamin Sittler
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use, copy,
+modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/common/win/my_getopt-1.5/Makefile b/common/win/my_getopt-1.5/Makefile
new file mode 100644
index 00000000..083cc4aa
--- /dev/null
+++ b/common/win/my_getopt-1.5/Makefile
@@ -0,0 +1,26 @@
+all: copy
+
+# Compiler options
+#CCOPTS = -g -O3 -Wall -Werror
+CCOPTS =
+
+# Compiler
+CC = gcc -Wall -Werror
+#CC = cc
+
+# Linker
+LD = $(CC)
+
+# Utility to remove a file
+RM = rm
+
+OBJS = main.o my_getopt.o
+
+copy: $(OBJS)
+ $(LD) -o $@ $(OBJS)
+
+clean:
+ $(RM) -f copy $(OBJS) *~
+
+%.o: %.c getopt.h my_getopt.h
+ $(CC) $(CCOPTS) -o $@ -c $<
diff --git a/common/win/my_getopt-1.5/README b/common/win/my_getopt-1.5/README
new file mode 100644
index 00000000..3a9afad7
--- /dev/null
+++ b/common/win/my_getopt-1.5/README
@@ -0,0 +1,140 @@
+my_getopt - a command-line argument parser
+Copyright 1997-2006, Benjamin Sittler
+
+The author can be reached by sending email to <bsittler@gmail.com>.
+
+The version of my_getopt in this package (1.5) has a BSD-like license;
+see the file LICENSE for details. Version 1.0 of my_getopt was similar
+to the GPL'ed version of my_getopt included with SMOKE-16 Version 1,
+Release 19990717. SMOKE-16 packages are available from:
+
+ http://geocities.com/bsittler/#smoke16
+
+OVERVIEW OF THE ARGUMENT PARSER
+===============================
+
+The getopt(), getopt_long() and getopt_long_only() functions parse
+command line arguments. The argc and argv parameters passed to these
+functions correspond to the argument count and argument list passed to
+your program's main() function at program start-up. Element 0 of the
+argument list conventionally contains the name of your program. Any
+remaining arguments starting with "-" (except for "-" or "--" by
+themselves) are option arguments, some of include option values. This
+family of getopt() functions allows intermixed option and non-option
+arguments anywhere in the argument list, except that "--" by itself
+causes the remaining elements of the argument list to be treated as
+non-option arguments.
+
+[ See the parts of this document labeled "DOCUMENTATION" and
+ "WHY RE-INVENT THE WHEEL?" for a more information. ]
+
+FILES
+=====
+
+The following four files constitute the my_getopt package:
+
+ LICENSE - license and warranty information for my_getopt
+ my_getopt.c - implementation of my getopt replacement
+ my_getopt.h - interface for my getopt replacement
+ getopt.h - a header file to make my getopt look like GNU getopt
+
+USAGE
+=====
+
+To use my_getopt in your application, include the following line to
+your main program source:
+
+ #include "getopt.h"
+
+This line should appear after your standard system header files to
+avoid conflicting with your system's built-in getopt.
+
+Then compile my_getopt.c into my_getopt.o, and link my_getopt.o into
+your application:
+
+ $ cc -c my_getopt.c
+ $ ld -o app app.o ... my_getopt.o
+
+To avoid conflicting with standard library functions, the function
+names and global variables used by my_getopt all begin with `my_'. To
+ensure compatibility with existing C programs, the `getopt.h' header
+file uses the C preprocessor to redefine names like getopt, optarg,
+optind, and so forth to my_getopt, my_optarg, my_optind, etc.
+
+SAMPLE PROGRAM
+==============
+
+There is also a public-domain sample program:
+
+ main.c - main() for a sample program using my_getopt
+ Makefile - build script for the sample program (called `copy')
+
+To build and test the sample program:
+
+ $ make
+ $ ./copy -help
+ $ ./copy -version
+
+The sample program bears a slight resemblance to the UNIX `cat'
+utility, but can be used rot13-encode streams, and can redirect output
+to a file.
+
+DOCUMENTATION
+=============
+
+There is not yet any real documentation for my_getopt. For the moment,
+use the Linux manual page for getopt. It has its own copyright and
+license; view the file `getopt.3' in a text editor for more details.
+
+ getopt.3 - the manual page for GNU getopt
+ getopt.txt - preformatted copy of the manual page for GNU getopt,
+ for your convenience
+
+WHY RE-INVENT THE WHEEL?
+========================
+
+I re-implemented getopt, getopt_long, and getopt_long_only because
+there were noticable bugs in several versions of the GNU
+implementations, and because the GNU versions aren't always available
+on some systems (*BSD, for example.) Other systems don't include any
+sort of standard argument parser (Win32 with Microsoft tools, for
+example, has no getopt.)
+
+These should do all the expected Unix- and GNU-style argument
+parsing, including permution, bunching, long options with single or
+double dashes (double dashes are required if you use
+my_getopt_long,) and optional arguments for both long and short
+options. A word with double dashes all by themselves halts argument
+parsing. A required long option argument can be in the same word as
+the option name, separated by '=', or in the next word. An optional
+long option argument must be in the same word as the option name,
+separated by '='.
+
+As with the GNU versions, a '+' prefix to the short option
+specification (or the POSIXLY_CORRECT environment variable) disables
+permution, a '-' prefix to the short option specification returns 1
+for non-options, ':' after a short option indicates a required
+argument, and '::' after a short option specification indicates an
+optional argument (which must appear in the same word.) If you'd like
+to recieve ':' instead of '?' for missing option arguments, prefix the
+short option specification with ':'.
+
+The original intent was to re-implement the documented behavior of
+the GNU versions, but I have found it necessary to emulate some of
+the undocumented behavior as well. Some programs depend on it.
+
+KNOWN BUGS
+==========
+
+The GNU versions support POSIX-style -W "name=value" long
+options. Currently, my_getopt does not support these, because I
+don't have any documentation on them (other than the fact that they
+are enabled by "W;" in the short option specification.) As a
+temporary workaround, my_getopt treats "W;" in the short option
+string identically to "W:".
+
+The GNU versions support internationalized/localized
+messages. Currently, my_getopt does not.
+
+There should be re-entrant versions of all these functions so that
+multiple threads can parse arguments simultaneously.
diff --git a/common/win/my_getopt-1.5/getopt.3 b/common/win/my_getopt-1.5/getopt.3
new file mode 100644
index 00000000..a63fcd82
--- /dev/null
+++ b/common/win/my_getopt-1.5/getopt.3
@@ -0,0 +1,288 @@
+.\" (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
+.\"
+.\" Permission is granted to make and distribute verbatim copies of this
+.\" manual provided the copyright notice and this permission notice are
+.\" preserved on all copies.
+.\"
+.\" Permission is granted to copy and distribute modified versions of this
+.\" manual under the conditions for verbatim copying, provided that the
+.\" entire resulting derived work is distributed under the terms of a
+.\" permission notice identical to this one
+.\"
+.\" Since the Linux kernel and libraries are constantly changing, this
+.\" manual page may be incorrect or out-of-date. The author(s) assume no
+.\" responsibility for errors or omissions, or for damages resulting from
+.\" the use of the information contained herein. The author(s) may not
+.\" have taken the same level of care in the production of this manual,
+.\" which is licensed free of charge, as they might when working
+.\" professionally.
+.\"
+.\" Formatted or processed versions of this manual, if unaccompanied by
+.\" the source, must acknowledge the copyright and authors of this work.
+.\" License.
+.\" Modified Sat Jul 24 19:27:50 1993 by Rik Faith (faith@cs.unc.edu)
+.\" Modified Mon Aug 30 22:02:34 1995 by Jim Van Zandt <jrv@vanzandt.mv.com>
+.\" longindex is a pointer, has_arg can take 3 values, using consistent
+.\" names for optstring and longindex, "\n" in formats fixed. Documenting
+.\" opterr and getopt_long_only. Clarified explanations (borrowing heavily
+.\" from the source code).
+.TH GETOPT 3 "Aug 30, 1995" "GNU" "Linux Programmer's Manual"
+.SH NAME
+getopt \- Parse command line options
+.SH SYNOPSIS
+.nf
+.B #include <unistd.h>
+.sp
+.BI "int getopt(int " argc ", char * const " argv[] ","
+.BI " const char *" optstring ");"
+.sp
+.BI "extern char *" optarg ;
+.BI "extern int " optind ", " opterr ", " optopt ;
+.sp
+.B #include <getopt.h>
+.sp
+.BI "int getopt_long(int " argc ", char * const " argv[] ",
+.BI " const char *" optstring ,
+.BI " const struct option *" longopts ", int *" longindex ");"
+.sp
+.BI "int getopt_long_only(int " argc ", char * const " argv[] ",
+.BI " const char *" optstring ,
+.BI " const struct option *" longopts ", int *" longindex ");"
+.fi
+.SH DESCRIPTION
+The
+.B getopt()
+function parses the command line arguments. Its arguments
+.I argc
+and
+.I argv
+are the argument count and array as passed to the
+.B main()
+function on program invocation.
+An element of \fIargv\fP that starts with `-' (and is not exactly "-" or "--")
+is an option element. The characters of this element
+(aside from the initial `-') are option characters. If \fBgetopt()\fP
+is called repeatedly, it returns successively each of the option characters
+from each of the option elements.
+.PP
+If \fBgetopt()\fP finds another option character, it returns that
+character, updating the external variable \fIoptind\fP and a static
+variable \fInextchar\fP so that the next call to \fBgetopt()\fP can
+resume the scan with the following option character or
+\fIargv\fP-element.
+.PP
+If there are no more option characters, \fBgetopt()\fP returns
+\fBEOF\fP. Then \fIoptind\fP is the index in \fIargv\fP of the first
+\fIargv\fP-element that is not an option.
+.PP
+.I optstring
+is a string containing the legitimate option characters. If such a
+character is followed by a colon, the option requires an argument, so
+\fBgetopt\fP places a pointer to the following text in the same
+\fIargv\fP-element, or the text of the following \fIargv\fP-element, in
+.IR optarg .
+Two colons mean an option takes
+an optional arg; if there is text in the current \fIargv\fP-element,
+it is returned in \fIoptarg\fP, otherwise \fIoptarg\fP is set to zero.
+.PP
+By default, \fBgetargs()\fP permutes the contents of \fIargv\fP as it
+scans, so that eventually all the non-options are at the end. Two
+other modes are also implemented. If the first character of
+\fIoptstring\fP is `+' or the environment variable POSIXLY_CORRECT is
+set, then option processing stops as soon as a non-option argument is
+encountered. If the first character of \fIoptstring\fP is `-', then
+each non-option \fIargv\fP-element is handled as if it were the argument of
+an option with character code 1. (This is used by programs that were
+written to expect options and other \fIargv\fP-elements in any order
+and that care about the ordering of the two.)
+The special argument `--' forces an end of option-scanning regardless
+of the scanning mode.
+.PP
+If \fBgetopt()\fP does not recognize an option character, it prints an
+error message to stderr, stores the character in \fIoptopt\fP, and
+returns `?'. The calling program may prevent the error message by
+setting \fIopterr\fP to 0.
+.PP
+The
+.B getopt_long()
+function works like
+.B getopt()
+except that it also accepts long options, started out by two dashes.
+Long option names may be abbreviated if the abbreviation is
+unique or is an exact match for some defined option. A long option
+may take a parameter, of the form
+.B --arg=param
+or
+.BR "--arg param" .
+.PP
+.I longopts
+is a pointer to the first element of an array of
+.B struct option
+declared in
+.B <getopt.h>
+as
+.nf
+.sp
+.in 10
+struct option {
+.in 14
+const char *name;
+int has_arg;
+int *flag;
+int val;
+.in 10
+};
+.fi
+.PP
+The meanings of the different fields are:
+.TP
+.I name
+is the name of the long option.
+.TP
+.I has_arg
+is:
+\fBno_argument\fP (or 0) if the option does not take an argument,
+\fBrequired_argument\fP (or 1) if the option requires an argument, or
+\fBoptional_argument\fP (or 2) if the option takes an optional argument.
+.TP
+.I flag
+specifies how results are returned for a long option. If \fIflag\fP
+is \fBNULL\fP, then \fBgetopt_long()\fP returns \fIval\fP. (For
+example, the calling program may set \fIval\fP to the equivalent short
+option character.) Otherwise, \fBgetopt_long()\fP returns 0, and
+\fIflag\fP points to a variable which is set to \fIval\fP if the
+option is found, but left unchanged if the option is not found.
+.TP
+\fIval\fP
+is the value to return, or to load into the variable pointed
+to by \fIflag\fP.
+.PP
+The last element of the array has to be filled with zeroes.
+.PP
+If \fIlongindex\fP is not \fBNULL\fP, it
+points to a variable which is set to the index of the long option relative to
+.IR longopts .
+.PP
+\fBgetopt_long_only()\fP is like \fBgetopt_long()\fP, but `-' as well
+as `--' can indicate a long option. If an option that starts with `-'
+(not `--') doesn't match a long option, but does match a short option,
+it is parsed as a short option instead.
+.SH "RETURN VALUE"
+The
+.B getopt()
+function returns the option character if the option was found
+successfully, `:' if there was a missing parameter for one of the
+options, `?' for an unknown option character, or \fBEOF\fP
+for the end of the option list.
+.PP
+\fBgetopt_long()\fP and \fBgetopt_long_only()\fP also return the option
+character when a short option is recognized. For a long option, they
+return \fIval\fP if \fIflag\fP is \fBNULL\fP, and 0 otherwise. Error
+and EOF returns are the same as for \fBgetopt()\fP, plus `?' for an
+ambiguous match or an extraneous parameter.
+.SH "ENVIRONMENT VARIABLES"
+.TP
+.SM
+.B POSIXLY_CORRECT
+If this is set, then option processing stops as soon as a non-option
+argument is encountered.
+.SH "EXAMPLE"
+The following example program, from the source code, illustrates the
+use of
+.BR getopt_long()
+with most of its features.
+.nf
+.sp
+#include <stdio.h>
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ int c;
+ int digit_optind = 0;
+
+ while (1)
+ {
+ int this_option_optind = optind ? optind : 1;
+ int option_index = 0;
+ static struct option long_options[] =
+ {
+ {"add", 1, 0, 0},
+ {"append", 0, 0, 0},
+ {"delete", 1, 0, 0},
+ {"verbose", 0, 0, 0},
+ {"create", 1, 0, 'c'},
+ {"file", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long (argc, argv, "abc:d:012",
+ long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c)
+ {
+ case 0:
+ printf ("option %s", long_options[option_index].name);
+ if (optarg)
+ printf (" with arg %s", optarg);
+ printf ("\\n");
+ break;
+
+ case '0':
+ case '1':
+ case '2':
+ if (digit_optind != 0 && digit_optind != this_option_optind)
+ printf ("digits occur in two different argv-elements.\\n");
+ digit_optind = this_option_optind;
+ printf ("option %c\\n", c);
+ break;
+
+ case 'a':
+ printf ("option a\\n");
+ break;
+
+ case 'b':
+ printf ("option b\\n");
+ break;
+
+ case 'c':
+ printf ("option c with value `%s'\\n", optarg);
+ break;
+
+ case 'd':
+ printf ("option d with value `%s'\\n", optarg);
+ break;
+
+ case '?':
+ break;
+
+ default:
+ printf ("?? getopt returned character code 0%o ??\\n", c);
+ }
+ }
+
+ if (optind < argc)
+ {
+ printf ("non-option ARGV-elements: ");
+ while (optind < argc)
+ printf ("%s ", argv[optind++]);
+ printf ("\\n");
+ }
+
+ exit (0);
+}
+.fi
+.SH "BUGS"
+This manpage is confusing.
+.SH "CONFORMING TO"
+.TP
+\fBgetopt()\fP:
+POSIX.1, provided the environment variable POSIXLY_CORRECT is set.
+Otherwise, the elements of \fIargv\fP aren't really const, because we
+permute them. We pretend they're const in the prototype to be
+compatible with other systems.
+
diff --git a/common/win/my_getopt-1.5/getopt.h b/common/win/my_getopt-1.5/getopt.h
new file mode 100644
index 00000000..5f08ccb4
--- /dev/null
+++ b/common/win/my_getopt-1.5/getopt.h
@@ -0,0 +1,56 @@
+/*
+ * getopt.h - cpp wrapper for my_getopt to make it look like getopt.
+ * Copyright 1997, 2000, 2001, 2002, Benjamin Sittler
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef MY_WRAPPER_GETOPT_H_INCLUDED
+#define MY_WRAPPER_GETOPT_H_INCLUDED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "my_getopt.h"
+
+#undef getopt
+#define getopt my_getopt
+#undef getopt_long
+#define getopt_long my_getopt_long
+#undef getopt_long_only
+#define getopt_long_only my_getopt_long_only
+#undef _getopt_internal
+#define _getopt_internal _my_getopt_internal
+#undef opterr
+#define opterr my_opterr
+#undef optind
+#define optind my_optind
+#undef optopt
+#define optopt my_optopt
+#undef optarg
+#define optarg my_optarg
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MY_WRAPPER_GETOPT_H_INCLUDED */
diff --git a/common/win/my_getopt-1.5/getopt.txt b/common/win/my_getopt-1.5/getopt.txt
new file mode 100644
index 00000000..ae08824e
--- /dev/null
+++ b/common/win/my_getopt-1.5/getopt.txt
@@ -0,0 +1,330 @@
+
+
+
+GETOPT(3) Linux Programmer's Manual GETOPT(3)
+
+
+NAME
+ getopt - Parse command line options
+
+SYNOPSIS
+ #include <unistd.h>
+
+ int getopt(int argc, char * const argv[],
+ const char *optstring);
+
+ extern char *optarg;
+ extern int optind, opterr, optopt;
+
+ #include <getopt.h>
+
+ int getopt_long(int argc, char * const argv[],
+ const char *optstring,
+ const struct option *longopts, int *longindex);
+
+ int getopt_long_only(int argc, char * const argv[],
+ const char *optstring,
+ const struct option *longopts, int *longindex);
+
+DESCRIPTION
+ The getopt() function parses the command line arguments.
+ Its arguments argc and argv are the argument count and
+ array as passed to the main() function on program invoca-
+ tion. An element of argv that starts with `-' (and is not
+ exactly "-" or "--") is an option element. The characters
+ of this element (aside from the initial `-') are option
+ characters. If getopt() is called repeatedly, it returns
+ successively each of the option characters from each of
+ the option elements.
+
+ If getopt() finds another option character, it returns
+ that character, updating the external variable optind and
+ a static variable nextchar so that the next call to
+ getopt() can resume the scan with the following option
+ character or argv-element.
+
+ If there are no more option characters, getopt() returns
+ EOF. Then optind is the index in argv of the first argv-
+ element that is not an option.
+
+ optstring is a string containing the legitimate option
+ characters. If such a character is followed by a colon,
+ the option requires an argument, so getopt places a
+ pointer to the following text in the same argv-element, or
+ the text of the following argv-element, in optarg. Two
+ colons mean an option takes an optional arg; if there is
+ text in the current argv-element, it is returned in
+ optarg, otherwise optarg is set to zero.
+
+ By default, getargs() permutes the contents of argv as it
+ scans, so that eventually all the non-options are at the
+
+
+
+GNU Aug 30, 1995 1
+
+
+
+
+
+GETOPT(3) Linux Programmer's Manual GETOPT(3)
+
+
+ end. Two other modes are also implemented. If the first
+ character of optstring is `+' or the environment variable
+ POSIXLY_CORRECT is set, then option processing stops as
+ soon as a non-option argument is encountered. If the
+ first character of optstring is `-', then each non-option
+ argv-element is handled as if it were the argument of an
+ option with character code 1. (This is used by programs
+ that were written to expect options and other argv-ele-
+ ments in any order and that care about the ordering of the
+ two.) The special argument `--' forces an end of option-
+ scanning regardless of the scanning mode.
+
+ If getopt() does not recognize an option character, it
+ prints an error message to stderr, stores the character in
+ optopt, and returns `?'. The calling program may prevent
+ the error message by setting opterr to 0.
+
+ The getopt_long() function works like getopt() except that
+ it also accepts long options, started out by two dashes.
+ Long option names may be abbreviated if the abbreviation
+ is unique or is an exact match for some defined option. A
+ long option may take a parameter, of the form --arg=param
+ or --arg param.
+
+ longopts is a pointer to the first element of an array of
+ struct option declared in <getopt.h> as
+
+ struct option {
+ const char *name;
+ int has_arg;
+ int *flag;
+ int val;
+ };
+
+ The meanings of the different fields are:
+
+ name is the name of the long option.
+
+ 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, or optional_argument (or 2)
+ if the option takes an optional argument.
+
+ flag specifies how results are returned for a long
+ option. If flag is NULL, then getopt_long()
+ returns val. (For example, the calling program may
+ set val to the equivalent short option character.)
+ Otherwise, getopt_long() returns 0, and flag points
+ to a variable which is set to val if the option is
+ found, but left unchanged if the option is not
+ found.
+
+ val is the value to return, or to load into the
+
+
+
+GNU Aug 30, 1995 2
+
+
+
+
+
+GETOPT(3) Linux Programmer's Manual GETOPT(3)
+
+
+ variable pointed to by flag.
+
+ The last element of the array has to be filled with
+ zeroes.
+
+ If longindex is not NULL, it points to a variable which is
+ set to the index of the long option relative to longopts.
+
+ getopt_long_only() is like getopt_long(), but `-' as well
+ as `--' can indicate a long option. If an option that
+ starts with `-' (not `--') doesn't match a long option,
+ but does match a short option, it is parsed as a short
+ option instead.
+
+RETURN VALUE
+ The getopt() function returns the option character if the
+ option was found successfully, `:' if there was a missing
+ parameter for one of the options, `?' for an unknown
+ option character, or EOF for the end of the option list.
+
+ getopt_long() and getopt_long_only() also return the
+ option character when a short option is recognized. For a
+ long option, they return val if flag is NULL, and 0 other-
+ wise. Error and EOF returns are the same as for getopt(),
+ plus `?' for an ambiguous match or an extraneous parame-
+ ter.
+
+ENVIRONMENT VARIABLES
+ POSIXLY_CORRECT
+ If this is set, then option processing stops as
+ soon as a non-option argument is encountered.
+
+EXAMPLE
+ The following example program, from the source code,
+ illustrates the use of getopt_long() with most of its fea-
+ tures.
+
+ #include <stdio.h>
+
+ int
+ main (argc, argv)
+ int argc;
+ char **argv;
+ {
+ int c;
+ int digit_optind = 0;
+
+ while (1)
+ {
+ int this_option_optind = optind ? optind : 1;
+ int option_index = 0;
+ static struct option long_options[] =
+ {
+ {"add", 1, 0, 0},
+
+
+
+GNU Aug 30, 1995 3
+
+
+
+
+
+GETOPT(3) Linux Programmer's Manual GETOPT(3)
+
+
+ {"append", 0, 0, 0},
+ {"delete", 1, 0, 0},
+ {"verbose", 0, 0, 0},
+ {"create", 1, 0, 'c'},
+ {"file", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long (argc, argv, "abc:d:012",
+ long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c)
+ {
+ case 0:
+ printf ("option %s", long_options[option_index].name);
+ if (optarg)
+ printf (" with arg %s", optarg);
+ printf ("\n");
+ break;
+
+ case '0':
+ case '1':
+ case '2':
+ if (digit_optind != 0 && digit_optind != this_option_optind)
+ printf ("digits occur in two different argv-elements.\n");
+ digit_optind = this_option_optind;
+ printf ("option %c\n", c);
+ break;
+
+ case 'a':
+ printf ("option a\n");
+ break;
+
+ case 'b':
+ printf ("option b\n");
+ break;
+
+ case 'c':
+ printf ("option c with value `%s'\n", optarg);
+ break;
+
+ case 'd':
+ printf ("option d with value `%s'\n", optarg);
+ break;
+
+ case '?':
+ break;
+
+ default:
+ printf ("?? getopt returned character code 0%o ??\n", c);
+ }
+ }
+
+
+
+GNU Aug 30, 1995 4
+
+
+
+
+
+GETOPT(3) Linux Programmer's Manual GETOPT(3)
+
+
+ if (optind < argc)
+ {
+ printf ("non-option ARGV-elements: ");
+ while (optind < argc)
+ printf ("%s ", argv[optind++]);
+ printf ("\n");
+ }
+
+ exit (0);
+ }
+
+BUGS
+ This manpage is confusing.
+
+CONFORMING TO
+ getopt():
+ POSIX.1, provided the environment variable
+ POSIXLY_CORRECT is set. Otherwise, the elements of
+ argv aren't really const, because we permute them.
+ We pretend they're const in the prototype to be
+ compatible with other systems.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+GNU Aug 30, 1995 5
+
+
diff --git a/common/win/my_getopt-1.5/main.c b/common/win/my_getopt-1.5/main.c
new file mode 100644
index 00000000..25674e1c
--- /dev/null
+++ b/common/win/my_getopt-1.5/main.c
@@ -0,0 +1,387 @@
+/*
+ * copy - test program for my getopt() re-implementation
+ *
+ * This program is in the public domain.
+ */
+
+#define VERSION \
+"0.3"
+
+#define COPYRIGHT \
+"This program is in the public domain."
+
+/* for isprint(), printf(), fopen(), perror(), getenv(), strcmp(), etc. */
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* for my getopt() re-implementation */
+#include "getopt.h"
+
+/* the default verbosity level is 0 (no verbose reporting) */
+static unsigned verbose = 0;
+
+/* print version and copyright information */
+static void
+version(char *progname)
+{
+ printf("%s version %s\n"
+ "%s\n",
+ progname,
+ VERSION,
+ COPYRIGHT);
+}
+
+/* print a help summary */
+static void
+help(char *progname)
+{
+ printf("Usage: %s [options] [FILE]...\n"
+ "Options:\n"
+ "-h or -help show this message and exit\n"
+ "-append append to the output file\n"
+ "-o FILE or\n"
+ "-output FILE send output to FILE (default is stdout)\n"
+ "-r or --rotate rotate letters 13 positions (rot13)\n"
+ "-rNUM or\n"
+ "--rotate=NUM rotate letters NUM positions\n"
+ "-truncate truncate the output file "
+ "(this is the default)\n"
+ "-v or -verbose increase the level of verbosity by 1"
+ "(the default is 0)\n"
+ "-vNUM or\n"
+ "-verbose=NUM set the level of verbosity to NUM\n"
+ "-V or -version print program version and exit\n"
+ "\n"
+ "This program reads the specified FILEs "
+ "(or stdin if none are given)\n"
+ "and writes their bytes to the specified output FILE "
+ "(or stdout if none is\n"
+ "given.) It can optionally rotate letters.\n",
+ progname);
+}
+
+/* print usage information to stderr */
+static void
+usage(char *progname)
+{
+ fprintf(stderr,
+ "Summary: %s [-help] [-version] [options] [FILE]...\n",
+ progname);
+}
+
+/* input file handler -- returns nonzero or exit()s on failure */
+static int
+handle(char *progname,
+ FILE *infile, char *infilename,
+ FILE *outfile, char *outfilename,
+ int rotate)
+{
+ int c;
+ unsigned long bytes_copied = 0;
+
+ if (verbose > 2)
+ {
+ fprintf(stderr,
+ "%s: copying from `%s' to `%s'\n",
+ progname,
+ infilename,
+ outfilename);
+ }
+ while ((c = getc(infile)) != EOF)
+ {
+ if (rotate && isalpha(c))
+ {
+ const char *letters = "abcdefghijklmnopqrstuvwxyz";
+ char *match;
+ if ((match = strchr(letters, tolower(c))))
+ {
+ char rc = letters[(match - letters + rotate) % 26];
+ if (isupper(c))
+ rc = toupper(rc);
+ c = rc;
+ }
+ }
+ if (putc(c, outfile) == EOF)
+ {
+ perror(outfilename);
+ exit(1);
+ }
+ bytes_copied ++;
+ }
+ if (! feof(infile))
+ {
+ perror(infilename);
+ return 1;
+ }
+ if (verbose > 2)
+ {
+ fprintf(stderr,
+ "%s: %lu bytes copied from `%s' to `%s'\n",
+ progname,
+ bytes_copied,
+ infilename,
+ outfilename);
+ }
+ return 0;
+}
+
+/* argument parser and dispatcher */
+int
+main(int argc, char * argv[])
+{
+ /* the program name */
+ char *progname = argv[0];
+ /* during argument parsing, opt contains the return value from getopt() */
+ int opt;
+ /* the output filename is initially 0 (a.k.a. stdout) */
+ char *outfilename = 0;
+ /* the default return value is initially 0 (success) */
+ int retval = 0;
+ /* initially we truncate */
+ int append = 0;
+ /* initially we don't rotate letters */
+ int rotate = 0;
+
+ /* short options string */
+ char *shortopts = "Vho:r::v::";
+ /* long options list */
+ struct option longopts[] =
+ {
+ /* name, has_arg, flag, val */ /* longind */
+ { "append", no_argument, 0, 0 }, /* 0 */
+ { "truncate", no_argument, 0, 0 }, /* 1 */
+ { "version", no_argument, 0, 'V' }, /* 3 */
+ { "help", no_argument, 0, 'h' }, /* 4 */
+ { "output", required_argument, 0, 'o' }, /* 5 */
+ { "rotate", optional_argument, 0, 'r' }, /* 6 */
+ { "verbose", optional_argument, 0, 'v' }, /* 7 */
+ /* end-of-list marker */
+ { 0, 0, 0, 0 }
+ };
+ /* long option list index */
+ int longind = 0;
+
+ /*
+ * print a warning when the POSIXLY_CORRECT environment variable will
+ * interfere with argument placement
+ */
+ if (getenv("POSIXLY_CORRECT"))
+ {
+ fprintf(stderr,
+ "%s: "
+ "Warning: implicit argument reordering disallowed by "
+ "POSIXLY_CORRECT\n",
+ progname);
+ }
+
+ /* parse all options from the command line */
+ while ((opt =
+ getopt_long_only(argc, argv, shortopts, longopts, &longind)) != -1)
+ switch (opt)
+ {
+ case 0: /* a long option without an equivalent short option */
+ switch (longind)
+ {
+ case 0: /* -append */
+ append = 1;
+ break;
+ case 1: /* -truncate */
+ append = 0;
+ break;
+ default: /* something unexpected has happened */
+ fprintf(stderr,
+ "%s: "
+ "getopt_long_only unexpectedly returned %d for `--%s'\n",
+ progname,
+ opt,
+ longopts[longind].name);
+ return 1;
+ }
+ break;
+ case 'V': /* -version */
+ version(progname);
+ return 0;
+ case 'h': /* -help */
+ help(progname);
+ return 0;
+ case 'r': /* -rotate[=NUM] */
+ if (optarg)
+ {
+ /* we use this while trying to parse a numeric argument */
+ char ignored;
+ if (sscanf(optarg,
+ "%d%c",
+ &rotate,
+ &ignored) != 1)
+ {
+ fprintf(stderr,
+ "%s: "
+ "rotation `%s' is not a number\n",
+ progname,
+ optarg);
+ usage(progname);
+ return 2;
+ }
+ /* normalize rotation */
+ while (rotate < 0)
+ {
+ rotate += 26;
+ }
+ rotate %= 26;
+ }
+ else
+ rotate = 13;
+ break;
+ case 'o': /* -output=FILE */
+ outfilename = optarg;
+ /* we allow "-" as a synonym for stdout here */
+ if (! strcmp(optarg, "-"))
+ {
+ outfilename = 0;
+ }
+ break;
+ case 'v': /* -verbose[=NUM] */
+ if (optarg)
+ {
+ /* we use this while trying to parse a numeric argument */
+ char ignored;
+ if (sscanf(optarg,
+ "%u%c",
+ &verbose,
+ &ignored) != 1)
+ {
+ fprintf(stderr,
+ "%s: "
+ "verbosity level `%s' is not a number\n",
+ progname,
+ optarg);
+ usage(progname);
+ return 2;
+ }
+ }
+ else
+ verbose ++;
+ break;
+ case '?': /* getopt_long_only noticed an error */
+ usage(progname);
+ return 2;
+ default: /* something unexpected has happened */
+ fprintf(stderr,
+ "%s: "
+ "getopt_long_only returned an unexpected value (%d)\n",
+ progname,
+ opt);
+ return 1;
+ }
+
+ /* re-open stdout to outfilename, if requested */
+ if (outfilename)
+ {
+ if (! freopen(outfilename, (append ? "a" : "w"), stdout))
+ {
+ perror(outfilename);
+ return 1;
+ }
+ }
+ else
+ {
+ /* make a human-readable version of the output filename "-" */
+ outfilename = "stdout";
+ /* you can't truncate stdout */
+ append = 1;
+ }
+
+ if (verbose)
+ {
+ fprintf(stderr,
+ "%s: verbosity level is %u; %s `%s'; rotation %d\n",
+ progname,
+ verbose,
+ (append ? "appending to" : "truncating"),
+ outfilename,
+ rotate);
+ }
+
+ if (verbose > 1)
+ {
+ fprintf(stderr,
+ "%s: %d input file(s) were given\n",
+ progname,
+ ((argc > optind) ? (argc - optind) : 0));
+ }
+
+ if (verbose > 3)
+ {
+ fprintf(stderr,
+ "\topterr: %d\n\toptind: %d\n\toptopt: %d (%c)\n\toptarg: %s\n",
+ opterr,
+ optind,
+ optopt, optopt,
+ optarg ? optarg : "(null)");
+ }
+
+ /* handle each of the input files (or stdin, if no files were given) */
+ if (optind < argc)
+ {
+ int argindex;
+
+ for (argindex = optind; argindex < argc; argindex ++)
+ {
+ char *infilename = argv[argindex];
+ FILE *infile;
+
+ /* we allow "-" as a synonym for stdin here */
+ if (! strcmp(infilename, "-"))
+ {
+ infile = stdin;
+ infilename = "stdin";
+ }
+ else if (! (infile = fopen(infilename, "r")))
+ {
+ perror(infilename);
+ retval = 1;
+ continue;
+ }
+ if (handle(progname,
+ infile, argv[optind],
+ stdout, outfilename,
+ rotate))
+ {
+ retval = 1;
+ fclose(infile);
+ continue;
+ }
+ if ((infile != stdin) && fclose(infile))
+ {
+ perror(infilename);
+ retval = 1;
+ }
+ }
+ }
+ else
+ {
+ retval =
+ handle(progname,
+ stdin, "stdin",
+ stdout, outfilename,
+ rotate);
+ }
+
+ /* close stdout */
+ if (fclose(stdout))
+ {
+ perror(outfilename);
+ return 1;
+ }
+
+ if (verbose > 3)
+ {
+ fprintf(stderr,
+ "%s: normal return, exit code is %d\n",
+ progname,
+ retval);
+ }
+ return retval;
+}
diff --git a/common/win/my_getopt-1.5/my_getopt.c b/common/win/my_getopt-1.5/my_getopt.c
new file mode 100644
index 00000000..e3737df8
--- /dev/null
+++ b/common/win/my_getopt-1.5/my_getopt.c
@@ -0,0 +1,281 @@
+/*
+ * my_getopt.c - my re-implementation of getopt.
+ * Copyright 1997, 2000, 2001, 2002, 2006, Benjamin Sittler
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "my_getopt.h"
+
+int my_optind=1, my_opterr=1, my_optopt=0;
+char *my_optarg=0;
+
+/* reset argument parser to start-up values */
+int my_getopt_reset(void)
+{
+ my_optind = 1;
+ my_opterr = 1;
+ my_optopt = 0;
+ my_optarg = 0;
+ return 0;
+}
+
+/* this is the plain old UNIX getopt, with GNU-style extensions. */
+/* if you're porting some piece of UNIX software, this is all you need. */
+/* this supports GNU-style permution and optional arguments */
+
+int my_getopt(int argc, char * argv[], const char *opts)
+{
+ static int charind=0;
+ char mode, colon_mode;
+ int off = 0, opt = -1;
+
+ if(getenv("POSIXLY_CORRECT")) colon_mode = mode = '+';
+ else {
+ if((colon_mode = *opts) == ':') off ++;
+ if(((mode = opts[off]) == '+') || (mode == '-')) {
+ off++;
+ if((colon_mode != ':') && ((colon_mode = opts[off]) == ':'))
+ off ++;
+ }
+ }
+ my_optarg = 0;
+ if(charind) {
+ const char *s;
+ my_optopt = argv[my_optind][charind];
+ for(s=opts+off; *s; s++) if(my_optopt == *s) {
+ charind++;
+ if((*(++s) == ':') || ((my_optopt == 'W') && (*s == ';'))) {
+ if(argv[my_optind][charind]) {
+ my_optarg = &(argv[my_optind++][charind]);
+ charind = 0;
+ } else if(*(++s) != ':') {
+ charind = 0;
+ if(++my_optind >= argc) {
+ if(my_opterr) fprintf(stderr,
+ "%s: option requires an argument -- %c\n",
+ argv[0], my_optopt);
+ opt = (colon_mode == ':') ? ':' : '?';
+ goto my_getopt_ok;
+ }
+ my_optarg = argv[my_optind++];
+ }
+ }
+ opt = my_optopt;
+ goto my_getopt_ok;
+ }
+ if(my_opterr) fprintf(stderr,
+ "%s: illegal option -- %c\n",
+ argv[0], my_optopt);
+ opt = '?';
+ if(argv[my_optind][++charind] == '\0') {
+ my_optind++;
+ charind = 0;
+ }
+ my_getopt_ok:
+ if(charind && ! argv[my_optind][charind]) {
+ my_optind++;
+ charind = 0;
+ }
+ } else if((my_optind >= argc) ||
+ ((argv[my_optind][0] == '-') &&
+ (argv[my_optind][1] == '-') &&
+ (argv[my_optind][2] == '\0'))) {
+ my_optind++;
+ opt = -1;
+ } else if((argv[my_optind][0] != '-') ||
+ (argv[my_optind][1] == '\0')) {
+ char *tmp;
+ int i, j, k;
+
+ if(mode == '+') opt = -1;
+ else if(mode == '-') {
+ my_optarg = argv[my_optind++];
+ charind = 0;
+ opt = 1;
+ } else {
+ for(i=j=my_optind; i<argc; i++) if((argv[i][0] == '-') &&
+ (argv[i][1] != '\0')) {
+ my_optind=i;
+ opt=my_getopt(argc, argv, opts);
+ while(i > j) {
+ tmp=argv[--i];
+ for(k=i; k+1<my_optind; k++) argv[k]=argv[k+1];
+ argv[--my_optind]=tmp;
+ }
+ break;
+ }
+ if(i == argc) opt = -1;
+ }
+ } else {
+ charind++;
+ opt = my_getopt(argc, argv, opts);
+ }
+ if (my_optind > argc) my_optind = argc;
+ return opt;
+}
+
+/* this is the extended getopt_long{,_only}, with some GNU-like
+ * extensions. Implements _getopt_internal in case any programs
+ * expecting GNU libc getopt call it.
+ */
+
+int _my_getopt_internal(int argc, char * argv[], const char *shortopts,
+ const struct option *longopts, int *longind,
+ int long_only)
+{
+ char mode, colon_mode = *shortopts;
+ int shortoff = 0, opt = -1;
+
+ if(getenv("POSIXLY_CORRECT")) colon_mode = mode = '+';
+ else {
+ if((colon_mode = *shortopts) == ':') shortoff ++;
+ if(((mode = shortopts[shortoff]) == '+') || (mode == '-')) {
+ shortoff++;
+ if((colon_mode != ':') && ((colon_mode = shortopts[shortoff]) == ':'))
+ shortoff ++;
+ }
+ }
+ my_optarg = 0;
+ if((my_optind >= argc) ||
+ ((argv[my_optind][0] == '-') &&
+ (argv[my_optind][1] == '-') &&
+ (argv[my_optind][2] == '\0'))) {
+ my_optind++;
+ opt = -1;
+ } else if((argv[my_optind][0] != '-') ||
+ (argv[my_optind][1] == '\0')) {
+ char *tmp;
+ int i, j, k;
+
+ opt = -1;
+ if(mode == '+') return -1;
+ else if(mode == '-') {
+ my_optarg = argv[my_optind++];
+ return 1;
+ }
+ for(i=j=my_optind; i<argc; i++) if((argv[i][0] == '-') &&
+ (argv[i][1] != '\0')) {
+ my_optind=i;
+ opt=_my_getopt_internal(argc, argv, shortopts,
+ longopts, longind,
+ long_only);
+ while(i > j) {
+ tmp=argv[--i];
+ for(k=i; k+1<my_optind; k++)
+ argv[k]=argv[k+1];
+ argv[--my_optind]=tmp;
+ }
+ break;
+ }
+ } else if((!long_only) && (argv[my_optind][1] != '-'))
+ opt = my_getopt(argc, argv, shortopts);
+ else {
+ int charind, offset;
+ int found = 0, ind, hits = 0;
+
+ if(((my_optopt = argv[my_optind][1]) != '-') && ! argv[my_optind][2]) {
+ int c;
+
+ ind = shortoff;
+ while((c = shortopts[ind++])) {
+ if(((shortopts[ind] == ':') ||
+ ((c == 'W') && (shortopts[ind] == ';'))) &&
+ (shortopts[++ind] == ':'))
+ ind ++;
+ if(my_optopt == c) return my_getopt(argc, argv, shortopts);
+ }
+ }
+ offset = 2 - (argv[my_optind][1] != '-');
+ for(charind = offset;
+ (argv[my_optind][charind] != '\0') &&
+ (argv[my_optind][charind] != '=');
+ charind++);
+ for(ind = 0; longopts[ind].name && !hits; ind++)
+ if((strlen(longopts[ind].name) == (size_t) (charind - offset)) &&
+ (strncmp(longopts[ind].name,
+ argv[my_optind] + offset, charind - offset) == 0))
+ found = ind, hits++;
+ if(!hits) for(ind = 0; longopts[ind].name; ind++)
+ if(strncmp(longopts[ind].name,
+ argv[my_optind] + offset, charind - offset) == 0)
+ found = ind, hits++;
+ if(hits == 1) {
+ opt = 0;
+
+ if(argv[my_optind][charind] == '=') {
+ if(longopts[found].has_arg == 0) {
+ opt = '?';
+ if(my_opterr) fprintf(stderr,
+ "%s: option `--%s' doesn't allow an argument\n",
+ argv[0], longopts[found].name);
+ } else {
+ my_optarg = argv[my_optind] + ++charind;
+ charind = 0;
+ }
+ } else if(longopts[found].has_arg == 1) {
+ if(++my_optind >= argc) {
+ opt = (colon_mode == ':') ? ':' : '?';
+ if(my_opterr) fprintf(stderr,
+ "%s: option `--%s' requires an argument\n",
+ argv[0], longopts[found].name);
+ } else my_optarg = argv[my_optind];
+ }
+ if(!opt) {
+ if (longind) *longind = found;
+ if(!longopts[found].flag) opt = longopts[found].val;
+ else *(longopts[found].flag) = longopts[found].val;
+ }
+ my_optind++;
+ } else if(!hits) {
+ if(offset == 1) opt = my_getopt(argc, argv, shortopts);
+ else {
+ opt = '?';
+ if(my_opterr) fprintf(stderr,
+ "%s: unrecognized option `%s'\n",
+ argv[0], argv[my_optind++]);
+ }
+ } else {
+ opt = '?';
+ if(my_opterr) fprintf(stderr,
+ "%s: option `%s' is ambiguous\n",
+ argv[0], argv[my_optind++]);
+ }
+ }
+ if (my_optind > argc) my_optind = argc;
+ return opt;
+}
+
+int my_getopt_long(int argc, char * argv[], const char *shortopts,
+ const struct option *longopts, int *longind)
+{
+ return _my_getopt_internal(argc, argv, shortopts, longopts, longind, 0);
+}
+
+int my_getopt_long_only(int argc, char * argv[], const char *shortopts,
+ const struct option *longopts, int *longind)
+{
+ return _my_getopt_internal(argc, argv, shortopts, longopts, longind, 1);
+}
diff --git a/common/win/my_getopt-1.5/my_getopt.h b/common/win/my_getopt-1.5/my_getopt.h
new file mode 100644
index 00000000..2c1dd66f
--- /dev/null
+++ b/common/win/my_getopt-1.5/my_getopt.h
@@ -0,0 +1,72 @@
+/*
+ * my_getopt.h - interface to my re-implementation of getopt.
+ * Copyright 1997, 2000, 2001, 2002, 2006, Benjamin Sittler
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef MY_GETOPT_H_INCLUDED
+#define MY_GETOPT_H_INCLUDED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* reset argument parser to start-up values */
+extern int my_getopt_reset(void);
+
+/* UNIX-style short-argument parser */
+extern int my_getopt(int argc, char * argv[], const char *opts);
+
+extern int my_optind, my_opterr, my_optopt;
+extern char *my_optarg;
+
+struct option {
+ const char *name;
+ int has_arg;
+ int *flag;
+ int val;
+};
+
+/* human-readable values for has_arg */
+#undef no_argument
+#define no_argument 0
+#undef required_argument
+#define required_argument 1
+#undef optional_argument
+#define optional_argument 2
+
+/* GNU-style long-argument parsers */
+extern int my_getopt_long(int argc, char * argv[], const char *shortopts,
+ const struct option *longopts, int *longind);
+
+extern int my_getopt_long_only(int argc, char * argv[], const char *shortopts,
+ const struct option *longopts, int *longind);
+
+extern int _my_getopt_internal(int argc, char * argv[], const char *shortopts,
+ const struct option *longopts, int *longind,
+ int long_only);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MY_GETOPT_H_INCLUDED */