From 686e4ca59fd8bf0fbd53dcdfeb5544e2c1d14baf Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 27 Aug 2004 20:03:32 +0000 Subject: [PATCH] Added a getopt() capability for WINMSC --- tools/testtools/csvdiff.cpp | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tools/testtools/csvdiff.cpp b/tools/testtools/csvdiff.cpp index f0f329b27..3fbe55edf 100644 --- a/tools/testtools/csvdiff.cpp +++ b/tools/testtools/csvdiff.cpp @@ -36,7 +36,15 @@ #include #include #include +#include "../../config.h" +#ifndef WINMSVC #include +#else +#include +#endif +using namespace std; + + #if defined(__CYGWIN__) #include @@ -65,6 +73,62 @@ double gatol = 1.0E-9; * First iteration towards getting this variable */ int Max_Input_Str_Ln = MAX_INPUT_STR_LN; +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ + +#ifdef WINMSVC +/* + * Windows doesn't have getopt(). This is an incomplete version that + * does enough to handle required functionality. + */ +int optind = -1; + +int getopt(int argc, char **argv, const char *) { + static int currArg = 1; + string tok; + static int charPos = 0; + int rc = -1; + if (currArg >= argc) { + return -rc; + } + tok = string(argv[currArg]); + size_t len = strlen(tok.c_str()); + if (charPos == 0) { + bool found = false; + do { + tok = string(argv[currArg]); + len = strlen(tok.c_str()); + if (len > 1 && tok[0] == '-') { + found = true; + charPos = 1; + if (len > 2 && tok[1] == '-') { + charPos = 2; + } + } else { + if (optind == -1) { + optind = currArg; + } + } + if (!found) { + if (currArg < (argc-1)) { + currArg++; + } else { + return -1; + } + } + } while (!found); + } + + rc = tok[charPos]; + if (charPos < static_cast(len - 1)) { + charPos++; + } else { + charPos = 0; + } + return rc; +} +#endif /*****************************************************************************/ /*****************************************************************************/