From c8b0fc89c210734002f04d1ec912dac4c7c36d79 Mon Sep 17 00:00:00 2001 From: Chris Love Date: Sat, 4 Sep 2021 13:47:59 -0700 Subject: [PATCH] Support building spdlog_udp on Windows --- spdlog_udp/CMakeLists.txt | 2 +- spdlog_udp/udp.cpp | 77 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/spdlog_udp/CMakeLists.txt b/spdlog_udp/CMakeLists.txt index 1bc1e34..5318f48 100644 --- a/spdlog_udp/CMakeLists.txt +++ b/spdlog_udp/CMakeLists.txt @@ -10,5 +10,5 @@ set (spdlog_udp_SRC add_executable( spdlog_udp ${spdlog_udp_SRC}) -target_link_libraries( spdlog_udp spdlog::spdlog pthread ) +target_link_libraries( spdlog_udp spdlog::spdlog Threads::Threads ) diff --git a/spdlog_udp/udp.cpp b/spdlog_udp/udp.cpp index 4cb0b4e..8e75fd3 100644 --- a/spdlog_udp/udp.cpp +++ b/spdlog_udp/udp.cpp @@ -5,7 +5,9 @@ #include #include #include +#ifndef WIN32 #include +#endif class TraceMethod { @@ -84,6 +86,81 @@ void usage() << "spdlog_console [-l ][-i ][-p ]\n"; } +#ifdef WIN32 +#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 */ +} +#endif + int main(int argc, char **argv) { int logLevel = spdlog::level::trace;