From 3ad63e04d0ae1387687a9aa3fb6aee9bbba2acde Mon Sep 17 00:00:00 2001 From: Freddie Akeroyd Date: Sat, 8 Jun 2019 20:34:39 +0100 Subject: [PATCH 1/5] Define ENABLE_VIRTUAL_TERMINAL_PROCESSING if not present --- src/StreamError.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/StreamError.cc b/src/StreamError.cc index cc8d833..192a839 100644 --- a/src/StreamError.cc +++ b/src/StreamError.cc @@ -43,6 +43,11 @@ FILE *StreamDebugFile = NULL; #ifdef _WIN32 #define localtime_r(timet,tm) localtime_s(tm,timet) +/* this may not be defined if using older Windows SDKs */ +#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING +#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 +#endif + /* Enable ANSI colors in Windows console */ static int win_console_init() { DWORD dwMode = 0; From 1cc5f3fbd625027835b3b7c908cff6f9aa9c15af Mon Sep 17 00:00:00 2001 From: Freddie Akeroyd Date: Sat, 8 Jun 2019 20:44:26 +0100 Subject: [PATCH 2/5] Fix missing inttypes.h on VS2010 --- src/ChecksumConverter.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ChecksumConverter.cc b/src/ChecksumConverter.cc index c70f4e1..0317617 100644 --- a/src/ChecksumConverter.cc +++ b/src/ChecksumConverter.cc @@ -28,6 +28,12 @@ #define SCNx8 "hhx" #define uint_fast8_t uint8_t #define int_fast8_t int8_t +#elif defined(_MSC_VER) && _MSC_VER < 1700 /* Visual Studio 2010 does not have inttypes.h */ +#include +#define PRIX32 "X" +#define PRIu32 "u" +#define PRIX8 "X" +#define SCNx8 "hhx" #else #define __STDC_FORMAT_MACROS #include From 905d8a3b4adc5f48b8f738ae4c1d102f0ffd666c Mon Sep 17 00:00:00 2001 From: Freddie Akeroyd Date: Sat, 8 Jun 2019 20:46:21 +0100 Subject: [PATCH 3/5] Fix for VS2010 usage of __VA_ARGS__ --- src/MacroMagic.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/MacroMagic.h b/src/MacroMagic.h index 37170a4..210bbea 100644 --- a/src/MacroMagic.h +++ b/src/MacroMagic.h @@ -37,28 +37,35 @@ _ENUM_CAST(type) #define _NTH_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, N, ...) N +/* + * we need to use _EXPAND below to work around a problem in Visual Studio 2010 + * where __VA_ARGS__ is treated as a single argument + * See https://stackoverflow.com/questions/5134523/msvc-doesnt-expand-va-args-correctly + */ +#define _EXPAND( x ) x + #define _fe_0(_call, ...) #define _fe_1(_call, x) _call(x) -#define _fe_2(_call, x, ...) _call(x) _fe_1(_call, __VA_ARGS__) -#define _fe_3(_call, x, ...) _call(x) _fe_2(_call, __VA_ARGS__) -#define _fe_4(_call, x, ...) _call(x) _fe_3(_call, __VA_ARGS__) -#define _fe_5(_call, x, ...) _call(x) _fe_4(_call, __VA_ARGS__) -#define _fe_6(_call, x, ...) _call(x) _fe_5(_call, __VA_ARGS__) -#define _fe_7(_call, x, ...) _call(x) _fe_6(_call, __VA_ARGS__) -#define _fe_8(_call, x, ...) _call(x) _fe_7(_call, __VA_ARGS__) -#define _fe_9(_call, x, ...) _call(x) _fe_8(_call, __VA_ARGS__) -#define _fe_10(_call, x, ...) _call(x) _fe_9(_call, __VA_ARGS__) +#define _fe_2(_call, x, ...) _call(x) _EXPAND(_fe_1(_call, __VA_ARGS__)) +#define _fe_3(_call, x, ...) _call(x) _EXPAND(_fe_2(_call, __VA_ARGS__)) +#define _fe_4(_call, x, ...) _call(x) _EXPAND(_fe_3(_call, __VA_ARGS__)) +#define _fe_5(_call, x, ...) _call(x) _EXPAND(_fe_4(_call, __VA_ARGS__)) +#define _fe_6(_call, x, ...) _call(x) _EXPAND(_fe_5(_call, __VA_ARGS__)) +#define _fe_7(_call, x, ...) _call(x) _EXPAND(_fe_6(_call, __VA_ARGS__)) +#define _fe_8(_call, x, ...) _call(x) _EXPAND(_fe_7(_call, __VA_ARGS__)) +#define _fe_9(_call, x, ...) _call(x) _EXPAND(_fe_8(_call, __VA_ARGS__)) +#define _fe_10(_call, x, ...) _call(x) _EXPAND(_fe_9(_call, __VA_ARGS__)) #define MACRO_FOR_EACH(x, ...) \ - _NTH_ARG(_, ##__VA_ARGS__, \ + _EXPAND(_NTH_ARG(_, ##__VA_ARGS__, \ _fe_10, _fe_9, _fe_8, _fe_7, _fe_6, _fe_5, _fe_4, _fe_3, _fe_2, _fe_1, _fe_0) \ - (x, ##__VA_ARGS__) + (x, ##__VA_ARGS__)) /* Enum to string magic */ #define ENUM(type,...) \ enum type { __VA_ARGS__ }; \ -static inline const char* type##ToStr(int x) {switch(x){MACRO_FOR_EACH(_CASE_LINE,__VA_ARGS__) default: return "invalid";}} \ +static inline const char* type##ToStr(int x) {switch(x){_EXPAND(MACRO_FOR_EACH(_CASE_LINE,__VA_ARGS__)) default: return "invalid";}} \ _ENUM_CAST(type) #endif From 85c9a8b130e68870fca3a0ed267bd3ae3ab079eb Mon Sep 17 00:00:00 2001 From: Freddie Akeroyd Date: Sat, 8 Jun 2019 21:30:37 +0100 Subject: [PATCH 4/5] Fix linker import warning for StreamDebugFile on WIN32 --- src/StreamEpics.cc | 2 ++ src/devStream.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/StreamEpics.cc b/src/StreamEpics.cc index f5629a2..c60cf16 100644 --- a/src/StreamEpics.cc +++ b/src/StreamEpics.cc @@ -85,6 +85,8 @@ extern "C" epicsShareFunc int epicsShareAPI iocshCmd(const char *command); #include #endif +#include "epicsExport.h" + #include "devStream.h" #define Z PRINTF_SIZE_T_PREFIX diff --git a/src/devStream.h b/src/devStream.h index 95686ba..8195095 100644 --- a/src/devStream.h +++ b/src/devStream.h @@ -52,6 +52,7 @@ extern "C" { #ifdef epicsExportSharedSymbols # define devStream_epicsExportSharedSymbols # undef epicsExportSharedSymbols +# include #endif #include "dbCommon.h" @@ -65,7 +66,9 @@ extern "C" { #include "epicsMath.h" #ifdef devStream_epicsExportSharedSymbols +# undef devStream_epicsExportSharedSymbols # define epicsExportSharedSymbols +# include #endif #if defined(_WIN32) From 0e525fc893d4490de18ab126dd4cd430b7fa797b Mon Sep 17 00:00:00 2001 From: Freddie Akeroyd Date: Sat, 8 Jun 2019 21:48:54 +0100 Subject: [PATCH 5/5] Use $(CAT) for WIN32 --- src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 646f052..19c5489 100644 --- a/src/Makefile +++ b/src/Makefile @@ -110,7 +110,7 @@ endif # create stream.dbd for all record types $(COMMON_DIR)/$(LIBRARY_DEFAULT).dbd: $(addprefix $(COMMON_DIR)/, $(STREAM_DBD_FILES)) - cat $? > $@ + $(CAT) $? > $@ $(LIBRARY_DEFAULT).dbd$(DEP): echo "$(LIBRARY_DEFAULT).dbd: $(STREAM_DBD_FILES)" > $@