diff --git a/Makefile b/Makefile index e665a6ef..7be43bea 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,8 @@ ifdef HOST_BOOST_NEEDS_MT HOST_BOOST_POSTFIX=-mt endif -LDFLAGS = -pthread -lboost_iostreams$(BOOST_LIB_POSTFIX) -lboost_filesystem$(BOOST_LIB_POSTFIX) -lboost_system$(BOOST_LIB_POSTFIX) -lboost_regex$(BOOST_LIB_POSTFIX) -lz $(USER_LDFLAGS) +LDFLAGS = -pthread -lboost_iostreams$(BOOST_LIB_POSTFIX) -lboost_filesystem$(BOOST_LIB_POSTFIX) -lboost_system$(BOOST_LIB_POSTFIX) -lz $(USER_LDFLAGS) +HOSTHELPER_LDFLAGS = ifeq ($(THREADS), NATIVE) CFLAGS += -DNATIVE_THREADS @@ -33,6 +34,14 @@ $(error "Bad value for THREADS (expected NATIVE or BOOST)") endif endif +ifeq ($(REGEX), BOOST) +CFLAGS += -DUSE_BOOST_REGEX +LDFLAGS += -lboost_regex$(BOOST_LIB_POSTFIX) +HOSTHELPER_LDFLAGS += -lboost_regex$(HOST_BOOST_POSTFIX) +endif +HOSTHELPER_LDFLAGS += -lboost_system$(HOST_BOOST_POSTFIX) + + ifdef NEED_LIBICONV LDFLAGS += -liconv endif diff --git a/options.build b/options.build index ac76eb14..ab6d89d6 100644 --- a/options.build +++ b/options.build @@ -66,6 +66,12 @@ FONT_SRC=unifontfull-5.1.20080820.hex # - Default value is 'lua'. LUA=lua +# Regex package to use. +# Currently supported: +# - NATIVE: std::thread +# - BOOST: boost_thread +REGEX=NATIVE + # Threading package to use. # Currently supported: # - NATIVE: std::thread diff --git a/src/cmdhelp/Makefile b/src/cmdhelp/Makefile index 9a27d199..08966092 100644 --- a/src/cmdhelp/Makefile +++ b/src/cmdhelp/Makefile @@ -10,10 +10,10 @@ __all__.files: $(JSON_OBJECTS) inverselist.$(OBJECT_SUFFIX) touch $(ALLFLAGS) mkstubs$(DOT_EXECUTABLE_SUFFIX): mkstubs.cpp ../library/json.cpp ../library/utf8.cpp ../library/string.cpp ../library/hex.cpp ../library/eatarg.cpp ../library/int24.cpp - $(HOSTCC) -g -std=gnu++0x -I../../include/library -o $@ $^ -lboost_regex$(HOST_BOOST_POSTFIX) -lboost_system$(HOST_BOOST_POSTFIX) -Wall + $(HOSTCC) -g -std=gnu++0x -I../../include/library -o $@ $^ $(HOSTHELPER_LDFLAGS) -Wall mkstubsi$(DOT_EXECUTABLE_SUFFIX): mkstubsi.cpp ../library/json.cpp ../library/utf8.cpp ../library/string.cpp ../library/hex.cpp ../library/eatarg.cpp ../library/int24.cpp - $(HOSTCC) -g -std=gnu++0x -I../../include/library -o $@ $^ -lboost_regex$(HOST_BOOST_POSTFIX) -lboost_system$(HOST_BOOST_POSTFIX) -Wall + $(HOSTCC) -g -std=gnu++0x -I../../include/library -o $@ $^ $(HOSTHELPER_LDFLAGS) -Wall inverselist.cpp: $(JSON_FILES) mkstubsi$(DOT_EXECUTABLE_SUFFIX) ./mkstubsi$(DOT_EXECUTABLE_SUFFIX) $^ diff --git a/src/emulation/Makefile b/src/emulation/Makefile index 8464066a..8b50fcf3 100644 --- a/src/emulation/Makefile +++ b/src/emulation/Makefile @@ -9,7 +9,7 @@ __all__.files: $(CORES_FILES) cat $(CORES_FLAGS) >$(ALLFLAGS) make-ports$(DOT_EXECUTABLE_SUFFIX): make-ports.cpp ../library/json.cpp ../library/utf8.cpp ../library/string.cpp ../library/portctrl-parse.cpp ../library/portctrl-data.cpp ../library/sha256.cpp ../library/assembler.cpp ../library/hex.cpp ../library/eatarg.cpp ../library/int24.cpp ../library/binarystream.cpp ../library/integer-pool.cpp - $(HOSTCC) -g -std=gnu++0x -I../../include/library -o $@ $^ -lboost_regex$(HOST_BOOST_POSTFIX) -lboost_system$(HOST_BOOST_POSTFIX) -Wall -DNO_ASM_GENERATION + $(HOSTCC) -g -std=gnu++0x -I../../include/library -o $@ $^ $(HOSTHELPER_LDFLAGS) -Wall -DNO_ASM_GENERATION bsnes-legacy/$(ALLFILES): forcelook make-ports$(DOT_EXECUTABLE_SUFFIX) $(MAKE) -C bsnes-legacy diff --git a/src/library/string.cpp b/src/library/string.cpp index ef592935..6f0c0f7a 100644 --- a/src/library/string.cpp +++ b/src/library/string.cpp @@ -3,9 +3,17 @@ #include "threads.hpp" #include "eatarg.hpp" #include -#include #include "map-pointer.hpp" +#ifdef USE_BOOST_REGEX +#include +namespace regex_ns = boost; +#else +#include +namespace regex_ns = std; +#endif + + std::string strip_CR(const std::string& str) { std::string x = str; @@ -88,11 +96,11 @@ regex_results regex(const std::string& regexp, const std::string& str, const cha { static threads::lock m; threads::alock h(m); - static std::map> regexps; + static std::map> regexps; if(!regexps.count(regexp)) { - boost::regex* y = NULL; + regex_ns::regex* y = NULL; try { - y = new boost::regex(regexp, boost::regex::extended & ~boost::regex::collate); + y = new regex_ns::regex(regexp, regex_ns::regex::extended & ~regex_ns::regex::collate); regexps[regexp] = y; } catch(std::bad_alloc& e) { delete y; @@ -102,8 +110,8 @@ regex_results regex(const std::string& regexp, const std::string& str, const cha } } - boost::smatch matches; - bool x = boost::regex_match(str.begin(), str.end(), matches, *(regexps[regexp])); + regex_ns::smatch matches; + bool x = regex_ns::regex_match(str.begin(), str.end(), matches, *(regexps[regexp])); if(x) { std::vector res; std::vector> mch; @@ -123,7 +131,7 @@ bool regex_match(const std::string& regexp, const std::string& str, enum regex_m throw(std::bad_alloc, std::runtime_error) { static threads::lock m; - static std::map> regexps; + static std::map> regexps; static std::map , std::pair> transform_cache; std::string _regexp; bool icase = false; @@ -176,12 +184,12 @@ transformed: transform_cache[key] = std::make_pair(_regexp, icase); if(!regexps.count(regexp)) { - boost::regex* y = NULL; - auto flags = boost::regex::extended & ~boost::regex::collate; - flags |= boost::regex::nosubs; - if(icase) flags |= boost::regex::icase; + regex_ns::regex* y = NULL; + auto flags = regex_ns::regex::extended & ~regex_ns::regex::collate; + flags |= regex_ns::regex::nosubs; + if(icase) flags |= regex_ns::regex::icase; try { - y = new boost::regex(_regexp, flags); + y = new regex_ns::regex(_regexp, flags); regexps[_regexp] = y; } catch(std::bad_alloc& e) { delete y; @@ -190,7 +198,7 @@ transformed: throw std::runtime_error(e.what()); } } - return boost::regex_match(str.begin(), str.end(), *(regexps[_regexp])); + return regex_ns::regex_match(str.begin(), str.end(), *(regexps[_regexp])); } namespace