Skip to content

Commit

Permalink
Support building spdlog_udp on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
CJLove committed Sep 4, 2021
1 parent 6ee5d16 commit c8b0fc8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion spdlog_udp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

77 changes: 77 additions & 0 deletions spdlog_udp/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <chrono>
#include <iostream>
#include <memory>
#ifndef WIN32
#include <unistd.h>
#endif

class TraceMethod
{
Expand Down Expand Up @@ -84,6 +86,81 @@ void usage()
<< "spdlog_console [-l <logLevel>][-i <ipAddr>][-p <port>]\n";
}

#ifdef WIN32
#include <string.h>
#include <stdio.h>

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;
Expand Down

0 comments on commit c8b0fc8

Please sign in to comment.