binpac: Adapted binpac to compile with MSVC for Windows environment.

This commit is contained in:
Elad Solomon 2021-04-22 17:36:41 +03:00 committed by Tim Wojtulewicz
parent dd3737b5c8
commit faa1b7abbf
5 changed files with 29 additions and 13 deletions

View file

@ -3,7 +3,9 @@
#ifndef binpac_h #ifndef binpac_h
#define binpac_h #define binpac_h
#ifndef _MSC_VER
#include <sys/param.h> #include <sys/param.h>
#endif
#cmakedefine HOST_BIGENDIAN #cmakedefine HOST_BIGENDIAN
#ifdef HOST_BIGENDIAN #ifdef HOST_BIGENDIAN
@ -136,7 +138,7 @@ inline string strfmt(const char* format, ...)
} // anonymous namespace } // anonymous namespace
#define binpac_fmt(x...) strfmt(x).c_str() #define binpac_fmt(...) strfmt(__VA_ARGS__).c_str()
class RefCount class RefCount
{ {

View file

@ -1,11 +1,11 @@
#include <vector> #include <vector>
class RE_Matcher; namespace zeek { class RE_Matcher; }
namespace binpac namespace binpac
{ {
std::vector<RE_Matcher*>* uncompiled_re_matchers = 0; std::vector<zeek::RE_Matcher*>* uncompiled_re_matchers = 0;
} }

View file

@ -4,7 +4,12 @@ bison_target(PACParser pac_parse.yy ${BinPAC_BINARY_DIR}/src/pac_parse.cc
COMPILE_FLAGS "--debug") COMPILE_FLAGS "--debug")
flex_target(PACScanner pac_scan.ll ${BinPAC_BINARY_DIR}/pac_scan.cc) flex_target(PACScanner pac_scan.ll ${BinPAC_BINARY_DIR}/pac_scan.cc)
add_flex_bison_dependency(PACScanner PACParser) 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 include_directories(${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src) ${PROJECT_BINARY_DIR}/src)
@ -100,6 +105,10 @@ set(binpac_SRCS
add_executable(binpac ${binpac_SRCS}) add_executable(binpac ${binpac_SRCS})
if ( MSVC )
target_link_libraries(binpac PRIVATE zeek_windows)
endif()
install(TARGETS binpac DESTINATION bin) install(TARGETS binpac DESTINATION bin)
# This is set to assist superprojects that want to build BinPac # This is set to assist superprojects that want to build BinPac

View file

@ -7,8 +7,6 @@
extern bool FLAGS_pac_debug; extern bool FLAGS_pac_debug;
#define ASSERT(x) assert(x) #define ASSERT(x) assert(x)
#define DEBUG_MSG(x...) \ #define DEBUG_MSG(...) if ( FLAGS_pac_debug ) fprintf(stderr, __VA_ARGS__)
if ( FLAGS_pac_debug ) \
fprintf(stderr, x)
#endif /* pac_dbg_h */ #endif /* pac_dbg_h */

View file

@ -20,8 +20,10 @@
#include "pac_record.h" #include "pac_record.h"
#include "pac_type.h" #include "pac_type.h"
#include "pac_utils.h" #include "pac_utils.h"
#include <libgen.h>
#include <errno.h> #include <errno.h>
#include <filesystem>
#include <string_view>
int line_number = 1; int line_number = 1;
@ -42,6 +44,11 @@ int char_token(int tok)
void include_file(const char *filename); void include_file(const char *filename);
string dirname(std::string_view path)
{
return std::filesystem::path(path).parent_path().string();
}
%} %}
/* EC -- embedded code state */ /* EC -- embedded code state */
@ -334,10 +341,10 @@ void include_file(const char *filename)
{ {
char* tmp = new char[strlen(input_filename.c_str()) + 1]; char* tmp = new char[strlen(input_filename.c_str()) + 1];
strcpy(tmp, input_filename.c_str()); strcpy(tmp, input_filename.c_str());
char* dir = dirname(tmp); string dir = dirname(tmp);
if ( dir ) if ( ! dir.empty() )
full_filename = string(dir) + "/" + filename; full_filename = dir + "/" + filename;
else else
{ {
fprintf(stderr, "%s:%d error: cannot include file \"%s\": %s\n", fprintf(stderr, "%s:%d error: cannot include file \"%s\": %s\n",