From 687784bcf9f5e6a0d3ebb55832b42e24472b22fe Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Mon, 30 Jul 2018 14:36:39 +0200 Subject: [PATCH] Windows hotpatch --- README.md | 20 ++++++++++++ lib/windows_getopt.h | 74 ++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 6 ++++ src/trie_test.cpp | 1 + 4 files changed, 101 insertions(+) create mode 100644 lib/windows_getopt.h diff --git a/README.md b/README.md index 9f65c16..180d2d4 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,26 @@ I hope most of the code is portable c++11. But I may have used some c++14 features. (If this is a problem for you, please let me know.) +### Windows + +David Huistra tried to build the tool on Windows using MinGW. That did not +work. (Dynamic linker errors, probably because I am using c++11.) But it does +work with Visual Studio 2015. For this, you can instruct `cmake` to generate +a solution file: + +``` +mkdir build +cd build +cmake -G "Visual Studio 14" -DCMAKE_BUILD_TYPE=RelWithDebInfo .. +``` + +See [here](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html) +for other versions of Visual Studio (not tested). After `cmake` you can open +the solution file and build the project. NOTE: The `Debug` build does not work +properly (I will have to look into this), so I recommend building the +`RelWithDebInfo` configuration. + + ## Java For now the java code, which acts as a bridge between LearnLib and this c++ diff --git a/lib/windows_getopt.h b/lib/windows_getopt.h new file mode 100644 index 0000000..e038a1c --- /dev/null +++ b/lib/windows_getopt.h @@ -0,0 +1,74 @@ +#pragma once + +#include +#include + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* +* getopt -- +* Parse argc/argv argument vector. +*/ +int + getopt(int nargc, char * const nargv[], const char *ostr) +{ + static char *place = EMSG; /* option letter processing */ + const char *oli; /* option letter list index */ + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (-1); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = EMSG; + return (-1); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = strchr(ostr, optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means -1. + */ + if (optopt == (int)'-') + return (-1); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void)printf("illegal option -- %c\n", optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + (void)printf("option requires an argument -- %c\n", optopt); + return (BADCH); + } + else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} diff --git a/src/main.cpp b/src/main.cpp index 367d1fc..75e67e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,7 +24,13 @@ * I've installed this software several times, and it was never * easy because of its dependencies. */ +#ifdef _WIN32 +extern "C" { +#include +} +#else #include +#endif using namespace std; diff --git a/src/trie_test.cpp b/src/trie_test.cpp index fd18ea5..fb15bbe 100644 --- a/src/trie_test.cpp +++ b/src/trie_test.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include