diff --git a/tools/binpac/lib/binpac.h.in b/tools/binpac/lib/binpac.h.in index b106df9f09..59dab550c3 100644 --- a/tools/binpac/lib/binpac.h.in +++ b/tools/binpac/lib/binpac.h.in @@ -3,7 +3,9 @@ #ifndef binpac_h #define binpac_h +#ifndef _MSC_VER #include +#endif #cmakedefine HOST_BIGENDIAN #ifdef HOST_BIGENDIAN @@ -136,7 +138,7 @@ inline string strfmt(const char* format, ...) } // anonymous namespace -#define binpac_fmt(x...) strfmt(x).c_str() +#define binpac_fmt(...) strfmt(__VA_ARGS__).c_str() class RefCount { diff --git a/tools/binpac/lib/binpac_regex.cc b/tools/binpac/lib/binpac_regex.cc index 9d6b890de4..22edffddcc 100644 --- a/tools/binpac/lib/binpac_regex.cc +++ b/tools/binpac/lib/binpac_regex.cc @@ -1,11 +1,11 @@ #include -class RE_Matcher; +namespace zeek { class RE_Matcher; } namespace binpac { -std::vector* uncompiled_re_matchers = 0; +std::vector* uncompiled_re_matchers = 0; } diff --git a/tools/binpac/src/CMakeLists.txt b/tools/binpac/src/CMakeLists.txt index 54ceb335c8..f239f64a9b 100644 --- a/tools/binpac/src/CMakeLists.txt +++ b/tools/binpac/src/CMakeLists.txt @@ -4,8 +4,13 @@ bison_target(PACParser pac_parse.yy ${BinPAC_BINARY_DIR}/src/pac_parse.cc COMPILE_FLAGS "--debug") flex_target(PACScanner pac_scan.ll ${BinPAC_BINARY_DIR}/pac_scan.cc) add_flex_bison_dependency(PACScanner PACParser) -set_property(SOURCE pac_scan.cc APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-sign-compare") - +if (MSVC) + set_property(SOURCE pac_scan.cc APPEND_STRING PROPERTY COMPILE_FLAGS "/wd4018") +else() + set_property(SOURCE pac_scan.cc APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-sign-compare") +endif() +include(RequireCXX17) + include_directories(${PROJECT_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}/src) @@ -100,6 +105,10 @@ set(binpac_SRCS add_executable(binpac ${binpac_SRCS}) +if ( MSVC ) + target_link_libraries(binpac PRIVATE zeek_windows) +endif() + install(TARGETS binpac DESTINATION bin) # This is set to assist superprojects that want to build BinPac diff --git a/tools/binpac/src/pac_dbg.h b/tools/binpac/src/pac_dbg.h index aebfda38fa..249a882a5c 100644 --- a/tools/binpac/src/pac_dbg.h +++ b/tools/binpac/src/pac_dbg.h @@ -6,9 +6,7 @@ extern bool FLAGS_pac_debug; -#define ASSERT(x) assert(x) -#define DEBUG_MSG(x...) \ - if ( FLAGS_pac_debug ) \ - fprintf(stderr, x) +#define ASSERT(x) assert(x) +#define DEBUG_MSG(...) if ( FLAGS_pac_debug ) fprintf(stderr, __VA_ARGS__) #endif /* pac_dbg_h */ diff --git a/tools/binpac/src/pac_scan.ll b/tools/binpac/src/pac_scan.ll index 7917fa98a1..dd90792bff 100644 --- a/tools/binpac/src/pac_scan.ll +++ b/tools/binpac/src/pac_scan.ll @@ -20,8 +20,10 @@ #include "pac_record.h" #include "pac_type.h" #include "pac_utils.h" -#include + #include +#include +#include int line_number = 1; @@ -42,6 +44,11 @@ int char_token(int tok) void include_file(const char *filename); +string dirname(std::string_view path) +{ + return std::filesystem::path(path).parent_path().string(); +} + %} /* EC -- embedded code state */ @@ -334,10 +341,10 @@ void include_file(const char *filename) { char* tmp = new char[strlen(input_filename.c_str()) + 1]; strcpy(tmp, input_filename.c_str()); - char* dir = dirname(tmp); + string dir = dirname(tmp); - if ( dir ) - full_filename = string(dir) + "/" + filename; + if ( ! dir.empty() ) + full_filename = dir + "/" + filename; else { fprintf(stderr, "%s:%d error: cannot include file \"%s\": %s\n",