summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--win32/getopt/getopt.c129
-rw-r--r--win32/getopt/getopt.h17
-rw-r--r--win32/project/Balau.vcxproj2
-rw-r--r--win32/project/Balau.vcxproj.filters9
4 files changed, 157 insertions, 0 deletions
diff --git a/win32/getopt/getopt.c b/win32/getopt/getopt.c
new file mode 100644
index 0000000..6d74b39
--- /dev/null
+++ b/win32/getopt/getopt.c
@@ -0,0 +1,129 @@
+/*
+ I got this off net.sources from Henry Spencer.
+ It is a public domain getopt(3) like in System V.
+ I have made the following modifications:
+
+ index(s,c) was added because too many people could
+ not compile getopt without it.
+
+ A test main program was added, ifdeffed by GETOPT.
+ This main program is a public domain implementation
+ of the getopt(1) program like in System V. The getopt
+ program can be used to standardize shell option handling.
+ e.g. cc -DGETOPT getopt.c -o getopt
+*/
+#include <stdio.h>
+
+#ifndef lint
+static char sccsfid[] = "@(#) getopt.c 5.0 (UTZoo) 1985";
+#endif
+
+#define ARGCH (int)':'
+#define BADCH (int)'?'
+#define EMSG ""
+#define ENDARGS "--"
+
+/* this is included because index is not on some UNIX systems */
+static
+char *
+index (s, c)
+register char *s;
+register int c;
+ {
+ while (*s)
+ if (c == *s) return (s);
+ else s++;
+ return (NULL);
+ }
+
+/*
+ * get option letter from argument vector
+ */
+int opterr = 1, /* useless, never set or used */
+ optind = 1, /* index into parent argv vector */
+ optopt; /* character checked for validity */
+char *optarg; /* argument associated with option */
+
+#define tell(s) fputs(*nargv,stderr);fputs(s,stderr); \
+ fputc(optopt,stderr);fputc('\n',stderr);return(BADCH);
+
+
+getopt(nargc,nargv,ostr)
+int nargc;
+char **nargv,
+ *ostr;
+{
+ static char *place = EMSG; /* option letter processing */
+ register char *oli; /* option letter list index */
+ char *index();
+
+ if(!*place) { /* update scanning pointer */
+ if(optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) return(EOF);
+ if (*place == '-') { /* found "--" */
+ ++optind;
+ return(EOF);
+ }
+ } /* option letter okay? */
+ if ((optopt = (int)*place++) == ARGCH || !(oli = index(ostr,optopt))) {
+ if(!*place) ++optind;
+ tell(": illegal option -- ");
+ }
+ if (*++oli != ARGCH) { /* don't need argument */
+ optarg = NULL;
+ if (!*place) ++optind;
+ }
+ else { /* need an argument */
+ if (*place) optarg = place; /* no white space */
+ else if (nargc <= ++optind) { /* no arg */
+ place = EMSG;
+ tell(": option requires an argument -- ");
+ }
+ else optarg = nargv[optind]; /* white space */
+ place = EMSG;
+ ++optind;
+ }
+ return(optopt); /* dump back option letter */
+}
+
+
+#ifdef GETOPT
+
+#ifndef lint
+static char sccspid[] = "@(#) getopt.c 5.1 (WangInst) 6/15/85";
+#endif
+
+main (argc, argv) char **argv;
+ {
+ char *optstring = argv[1];
+ char *argv0 = argv[0];
+ extern int optind;
+ extern char *optarg;
+ int opterr = 0;
+ int C;
+ char *opi;
+ if (argc == 1)
+ {
+ fprintf (stderr, "Usage: %s optstring args\n", argv0);
+ exit (1);
+ }
+ argv++;
+ argc--;
+ argv[0] = argv0;
+ while ((C = getopt (argc, argv, optstring)) != EOF)
+ {
+ if (C == BADCH) opterr++;
+ printf ("-%c ", C);
+ opi = index (optstring, C);
+ if (opi && opi[1] == ARGCH)
+ if (optarg)
+ printf ("\"%s\" ", optarg);
+ else opterr++;
+ }
+ printf ("%s", ENDARGS);
+ while (optind < argc)
+ printf (" \"%s\"", argv[optind++]);
+ putchar ('\n');
+ exit (opterr);
+ }
+
+#endif
diff --git a/win32/getopt/getopt.h b/win32/getopt/getopt.h
new file mode 100644
index 0000000..f77cb17
--- /dev/null
+++ b/win32/getopt/getopt.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int getopt(int nargc, char ** nargv, char * ostr);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+extern int opterr = 1;
+extern int optind = 1;
+extern int optopt;
+extern char * optarg;
diff --git a/win32/project/Balau.vcxproj b/win32/project/Balau.vcxproj
index 0959a39..921b1d0 100644
--- a/win32/project/Balau.vcxproj
+++ b/win32/project/Balau.vcxproj
@@ -244,6 +244,7 @@
<ClCompile Include="..\..\src\TaskMan.cc" />
<ClCompile Include="..\..\src\Threads.cc" />
<ClCompile Include="..\..\src\ZHandle.cc" />
+ <ClCompile Include="..\getopt\getopt.c" />
<ClCompile Include="..\regex\engine.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -315,6 +316,7 @@
<ClInclude Include="..\..\src\jsoncpp\include\json\value.h" />
<ClInclude Include="..\..\src\jsoncpp\include\json\writer.h" />
<ClInclude Include="..\..\src\jsoncpp\src\json_batchallocator.h" />
+ <ClInclude Include="..\getopt\getopt.h" />
<ClInclude Include="..\regex\regex.h" />
<ClInclude Include="..\regex\regex2.h" />
</ItemGroup>
diff --git a/win32/project/Balau.vcxproj.filters b/win32/project/Balau.vcxproj.filters
index 02b4e84..cd115d4 100644
--- a/win32/project/Balau.vcxproj.filters
+++ b/win32/project/Balau.vcxproj.filters
@@ -22,6 +22,9 @@
<Filter Include="Third Party\lcrypt">
<UniqueIdentifier>{b7c1083c-5e02-4f73-b973-73dfb07f1a9f}</UniqueIdentifier>
</Filter>
+ <Filter Include="Third Party\getopt">
+ <UniqueIdentifier>{d9a98750-dc39-4eb1-9e0d-49bb1a95b104}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\Async.cc">
@@ -189,6 +192,9 @@
<ClCompile Include="..\regex\split.c">
<Filter>Third Party\regex</Filter>
</ClCompile>
+ <ClCompile Include="..\getopt\getopt.c">
+ <Filter>Third Party\getopt</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\includes\Async.h">
@@ -356,6 +362,9 @@
<ClInclude Include="..\regex\regex2.h">
<Filter>Third Party\regex</Filter>
</ClInclude>
+ <ClInclude Include="..\getopt\getopt.h">
+ <Filter>Third Party\getopt</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\jsoncpp\src\json_internalarray.inl">