From 9c7e863d77da76b987e71cf99988f1d091e6c4f4 Mon Sep 17 00:00:00 2001 From: crs Date: Wed, 19 Jun 2002 11:23:49 +0000 Subject: [PATCH] checkpoint. more conversion to automake. --- base/BasicTypes.h | 116 +++++++++++++++------------- base/CLog.cpp | 19 +++-- base/CLog.h | 6 +- base/CStopwatch.cpp | 42 ++++++---- base/XBase.cpp | 2 +- base/common.h | 79 ++++++++++--------- base/stdistream.h | 6 +- base/stdostream.h | 4 +- client/CClient.cpp | 8 +- client/CXWindowsSecondaryScreen.cpp | 20 +++-- client/client.cpp | 16 ++-- configure.in | 20 +++-- mt/CCondVar.cpp | 10 +-- mt/CCondVar.h | 2 +- mt/CMutex.cpp | 8 +- mt/CThread.cpp | 2 +- mt/CThread.h | 2 +- mt/CThreadRep.cpp | 84 ++++++++++---------- mt/CThreadRep.h | 23 +++--- net/CNetwork.cpp | 4 +- net/CNetwork.h | 38 ++++----- platform/CPlatform.cpp | 8 +- platform/CPlatform.h | 8 +- platform/CXWindowsClipboard.h | 6 +- platform/CXWindowsScreen.h | 6 +- platform/CXWindowsUtil.h | 6 +- server/CServer.cpp | 8 +- server/CSynergyHook.h | 9 ++- server/CXWindowsPrimaryScreen.cpp | 12 ++- server/server.cpp | 22 +++--- synergy/CProtocolUtil.h | 2 +- 31 files changed, 328 insertions(+), 270 deletions(-) diff --git a/base/BasicTypes.h b/base/BasicTypes.h index f71d15b4..0a437caa 100644 --- a/base/BasicTypes.h +++ b/base/BasicTypes.h @@ -3,64 +3,70 @@ #include "common.h" -#if defined(CONFIG_PLATFORM_LINUX) +// +// pick types of particular sizes +// -#include - -typedef int8_t SInt8; -typedef int16_t SInt16; -typedef int32_t SInt32; -typedef int64_t SInt64; - -typedef uint8_t UInt8; -typedef uint16_t UInt16; -typedef uint32_t UInt32; -typedef uint64_t UInt64; - -#endif // CONFIG_PLATFORM_LINUX - -#if defined(CONFIG_PLATFORM_SOLARIS) - -#include - -typedef int8_t SInt8; -typedef int16_t SInt16; -typedef int32_t SInt32; -typedef int64_t SInt64; - -typedef uint8_t UInt8; -typedef uint16_t UInt16; -typedef uint32_t UInt32; -typedef uint64_t UInt64; - -#endif // CONFIG_PLATFORM_SOLARIS - -#if defined(CONFIG_PLATFORM_WIN32) - -// use VC++ extensions if available -#if defined(_MSC_VER) -typedef signed __int8 SInt8; -typedef signed __int16 SInt16; -typedef signed __int32 SInt32; -typedef signed __int64 SInt64; - -typedef unsigned __int8 UInt8; -typedef unsigned __int16 UInt16; -typedef unsigned __int32 UInt32; -typedef unsigned __int64 UInt64; -#else -typedef signed char SInt8; -typedef short SInt16; -typedef int SInt32; -typedef long long SInt64; - -typedef unsigned char UInt8; -typedef unsigned short UInt16; -typedef unsigned int UInt32; -typedef unsigned long long UInt64; +#if !defined(TYPE_OF_SIZE_1) +# if SIZEOF_CHAR == 1 +# define TYPE_OF_SIZE_1 char +# endif #endif -#endif // CONFIG_PLATFORM_WIN32 +#if !defined(TYPE_OF_SIZE_2) +# if SIZEOF_INT == 2 +# define TYPE_OF_SIZE_2 int +# else +# define TYPE_OF_SIZE_2 short +# endif +#endif + +#if !defined(TYPE_OF_SIZE_4) +# if SIZEOF_INT == 4 +# define TYPE_OF_SIZE_4 int +# else +# define TYPE_OF_SIZE_4 long +# endif +#endif + +// +// verify existence of required types +// + +#if !defined(TYPE_OF_SIZE_1) +# error No 1 byte integer type +#endif +#if !defined(TYPE_OF_SIZE_2) +# error No 2 byte integer type +#endif +#if !defined(TYPE_OF_SIZE_4) +# error No 4 byte integer type +#endif + + +// +// make typedefs +// +// except for SInt8 and UInt8 these types are only guaranteed to be +// at least as big as indicated (in bits). that is, they may be +// larger than indicated. +// + +typedef signed TYPE_OF_SIZE_1 SInt8; +typedef signed TYPE_OF_SIZE_2 SInt16; +typedef signed TYPE_OF_SIZE_4 SInt32; + +typedef unsigned TYPE_OF_SIZE_1 UInt8; +typedef unsigned TYPE_OF_SIZE_2 UInt16; +typedef unsigned TYPE_OF_SIZE_4 UInt32; + +// +// clean up +// + +#undef TYPE_OF_SIZE_1 +#undef TYPE_OF_SIZE_2 +#undef TYPE_OF_SIZE_4 #endif diff --git a/base/CLog.cpp b/base/CLog.cpp index a793699f..38bcdfd6 100644 --- a/base/CLog.cpp +++ b/base/CLog.cpp @@ -3,7 +3,7 @@ #include #include -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #define WIN32_LEAN_AND_MEAN #include #define vsnprintf _vsnprintf @@ -42,6 +42,13 @@ static const int g_prioritySuffixLength = 2; static const int g_priorityPad = g_maxPriorityLength + g_prioritySuffixLength; +// platform newline sequence +#if WINDOWS_LIKE +static const char* g_newline = "\r\n"; +#else +static const char* g_newline = "\n"; +#endif + // minimum length of a newline sequence static const int g_newlineLength = 2; @@ -226,17 +233,13 @@ CLog::output(int priority, char* msg) } // put a newline at the end -#if defined(CONFIG_PLATFORM_WIN32) - strcat(msg + g_priorityPad, "\r\n"); -#else - strcat(msg + g_priorityPad, "\n"); -#endif + strcat(msg + g_priorityPad, g_newline); // print it CHoldLock lock(s_lock); if (s_outputter == NULL || !s_outputter(priority, msg + g_maxPriorityLength - n)) { -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE openConsole(); #endif fprintf(stderr, "%s", msg + g_maxPriorityLength - n); @@ -268,7 +271,7 @@ CLog::vsprint(int pad, char* buffer, int len, const char* fmt, va_list args) return buffer; } -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE static DWORD s_thread = 0; diff --git a/base/CLog.h b/base/CLog.h index 0a790929..64fd9976 100644 --- a/base/CLog.h +++ b/base/CLog.h @@ -1,8 +1,8 @@ #ifndef CLOG_H #define CLOG_H -#include "BasicTypes.h" -#include +#include "common.h" +#include class CLog { public: @@ -67,7 +67,7 @@ private: static void output(int priority, char* msg); static char* vsprint(int pad, char*, int len, const char*, va_list); static int nprint(const char*, va_list); -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE static void openConsole(); #endif diff --git a/base/CStopwatch.cpp b/base/CStopwatch.cpp index 5cd61bc7..dbbe0ba7 100644 --- a/base/CStopwatch.cpp +++ b/base/CStopwatch.cpp @@ -110,21 +110,7 @@ CStopwatch::operator double() const return getTime(); } -#if defined(CONFIG_PLATFORM_UNIX) - -#include - -double -CStopwatch::getClock() const -{ - struct timeval t; - gettimeofday(&t, NULL); - return (double)t.tv_sec + 1.0e-6 * (double)t.tv_usec; -} - -#endif // CONFIG_PLATFORM_UNIX - -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE // avoid getting a lot a crap from mmsystem.h that we don't need #define MMNODRV // Installable driver support @@ -198,4 +184,28 @@ CStopwatch::getClock() const } } -#endif // CONFIG_PLATFORM_WIN32 +#elif UNIX_LIKE + +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif +#if HAVE_UNISTD_H +# include +#endif + +double +CStopwatch::getClock() const +{ + struct timeval t; + gettimeofday(&t, NULL); + return (double)t.tv_sec + 1.0e-6 * (double)t.tv_usec; +} + +#endif // UNIX_LIKE diff --git a/base/XBase.cpp b/base/XBase.cpp index 575ca4f6..fba37293 100644 --- a/base/XBase.cpp +++ b/base/XBase.cpp @@ -2,7 +2,7 @@ #include // win32 wants a const char* argument to std::exception c'tor -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #define STDEXCEPTARG "" #endif diff --git a/base/common.h b/base/common.h index df7d0a20..00b9fd87 100644 --- a/base/common.h +++ b/base/common.h @@ -1,53 +1,58 @@ #ifndef COMMON_H #define COMMON_H -#if defined(__linux__) - -#define CONFIG_PLATFORM_LINUX -#define CONFIG_PLATFORM_UNIX -#define CONFIG_TYPES_X11 -#define CONFIG_PTHREADS - -#elif defined(__sun__) - -#define CONFIG_PLATFORM_SOLARIS -#define CONFIG_PLATFORM_UNIX -#define CONFIG_TYPES_X11 -#define CONFIG_PTHREADS - -#elif defined(_WIN32) - -#define CONFIG_PLATFORM_WIN32 - -#if (_MSC_VER >= 1200) -// work around for statement scoping bug -#define for if (false) { } else for - -// turn off bonehead warnings -#pragma warning(disable: 4786) // identifier truncated in debug info -#pragma warning(disable: 4514) // unreferenced inline function removed - -// this one's a little too aggressive -#pragma warning(disable: 4127) // conditional expression is constant - -// emitted incorrectly under release build in some circumstances -#if defined(NDEBUG) -#pragma warning(disable: 4702) // unreachable code -#pragma warning(disable: 4701) // local variable maybe used uninitialized +#if HAVE_CONFIG_H +# include "config.h" #endif -#endif // (_MSC_VER >= 1200) +// check if win32 platform +#if defined(_WIN32) || HAVE_WINDOWS_H +# define WINDOWS_LIKE 1 -#else + // VC++ specific +# if (_MSC_VER >= 1200) + // work around for statement scoping bug +# define for if (false) { } else for -#error unsupported platform + // turn off bonehead warnings +# pragma warning(disable: 4786) // identifier truncated in debug info +# pragma warning(disable: 4514) // unreferenced inline function removed + // this one's a little too aggressive +# pragma warning(disable: 4127) // conditional expression is constant + + // emitted incorrectly under release build in some circumstances +# if defined(NDEBUG) +# pragma warning(disable: 4702) // unreachable code +# pragma warning(disable: 4701) // variable maybe used uninitialized +# endif + +# endif // (_MSC_VER >= 1200) + + // VC++ has built-in sized types +# if defined(_MSC_VER) +# define TYPE_OF_SIZE_1 __int8 +# define TYPE_OF_SIZE_2 __int16 +# define TYPE_OF_SIZE_4 __int32 +# else +# define SIZE_OF_CHAR 1 +# define SIZE_OF_SHORT 2 +# define SIZE_OF_INT 4 +# define SIZE_OF_LONG 4 +# endif +#endif // defined(_WIN32) || HAVE_WINDOWS_H + +// unix-like if not like anything else +#if (!defined(WINDOWS_LIKE) || WINDOWS_LIKE == 0) +# define UNIX_LIKE 1 #endif +// define NULL #ifndef NULL #define NULL 0 #endif -#include +// make assert available since we use it a lot +#include #endif diff --git a/base/stdistream.h b/base/stdistream.h index 440a33fe..6f83b5bb 100644 --- a/base/stdistream.h +++ b/base/stdistream.h @@ -1,14 +1,12 @@ #include "stdpre.h" -#if !defined(CONFIG_PLATFORM_LINUX) +#if defined(HAVE_ISTREAM) #include #else -// some versions of libstdc++ don't have -// FIXME -- only include iostream for versions that don't have istream #include #endif #include "stdpost.h" -#if defined(CONFIG_PLATFORM_WIN32) && defined(_MSC_VER) +#if defined(_MSC_VER) // istream has no overloads for __int* types inline std::istream& operator>>(std::istream& s, SInt8& i) diff --git a/base/stdostream.h b/base/stdostream.h index fd434281..b1c37914 100644 --- a/base/stdostream.h +++ b/base/stdostream.h @@ -1,9 +1,7 @@ #include "stdpre.h" -#if !defined(CONFIG_PLATFORM_LINUX) +#if defined(HAVE_OSTREAM) #include #else -// some versions of libstdc++ don't have -// FIXME -- only include iostream for versions that don't have ostream #include #endif #include "stdpost.h" diff --git a/client/CClient.cpp b/client/CClient.cpp index 0ec793fe..5e452909 100644 --- a/client/CClient.cpp +++ b/client/CClient.cpp @@ -402,9 +402,9 @@ CClient::runSession(void*) } // FIXME -- use factory to create screen -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #include "CMSWindowsSecondaryScreen.h" -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE #include "CXWindowsSecondaryScreen.h" #endif void @@ -426,9 +426,9 @@ CClient::openSecondaryScreen() // open screen log((CLOG_DEBUG1 "creating secondary screen")); -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE m_screen = new CMSWindowsSecondaryScreen; -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE m_screen = new CXWindowsSecondaryScreen; #endif log((CLOG_DEBUG1 "opening secondary screen")); diff --git a/client/CXWindowsSecondaryScreen.cpp b/client/CXWindowsSecondaryScreen.cpp index 3f9e754d..90b14a0a 100644 --- a/client/CXWindowsSecondaryScreen.cpp +++ b/client/CXWindowsSecondaryScreen.cpp @@ -4,12 +4,20 @@ #include "CXWindowsUtil.h" #include "CThread.h" #include "CLog.h" -#include -#include -#define XK_MISCELLANY -#define XK_XKB_KEYS -#include -#include +#if defined(X_DISPLAY_MISSING) +# error X11 is required to build synergy +#else +# include +# include +# define XK_MISCELLANY +# define XK_XKB_KEYS +# include +# if defined(HAVE_X11_EXTENSIONS_XTEST_H) +# include +# else +# error The XTest extension is required to build synergy +# endif +#endif // // CXWindowsSecondaryScreen diff --git a/client/client.cpp b/client/client.cpp index 3b1418b8..9d4a13de 100644 --- a/client/client.cpp +++ b/client/client.cpp @@ -15,9 +15,9 @@ #include // platform dependent name of a daemon -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #define DAEMON_NAME "Synergy Client" -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE #define DAEMON_NAME "synergy" #endif @@ -176,7 +176,7 @@ static void help() { -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE # define PLATFORM_ARGS \ " [--install]" \ @@ -326,7 +326,7 @@ parse(int argc, const char** argv) bye(0); } -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE else if (isArg(i, argc, argv, NULL, "--install")) { s_install = true; if (s_uninstall) { @@ -338,7 +338,7 @@ parse(int argc, const char** argv) } #endif -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE else if (isArg(i, argc, argv, NULL, "--uninstall")) { s_uninstall = true; if (s_install) { @@ -404,7 +404,7 @@ parse(int argc, const char** argv) // increase default filter level for daemon. the user must // explicitly request another level for a daemon. if (s_daemon && s_logFilter == NULL) { -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE if (CPlatform::isWindows95Family()) { // windows 95 has no place for logging so avoid showing // the log console window. @@ -430,7 +430,7 @@ parse(int argc, const char** argv) // platform dependent entry points // -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #include "CMSWindowsScreen.h" @@ -605,7 +605,7 @@ WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int) return result; } -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE static int diff --git a/configure.in b/configure.in index 9c5dc38f..2fae47f5 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT(base/IInterface.h) +AC_INIT(base/common.h) AM_CONFIG_HEADER(config.h) AC_CONFIG_AUX_DIR(config) AM_INIT_AUTOMAKE(synergy, 0.5) @@ -17,13 +17,13 @@ ACX_PTHREAD(,AC_MSG_ERROR(You must have pthreads to compile synergy)) dnl checks for header files AC_HEADER_STDC +AC_HEADER_TIME +AC_CHECK_HEADERS([unistd.h sys/time.h]) +AC_CHECK_HEADERS([istream ostream]) +AC_CHECK_HEADERS([windows.h]) AC_PATH_X -if test "$no_x" = yes; then - AC_MSG_ERROR(You must have X Windows to compile synergy) -fi AC_PATH_XTRA -AC_CHECK_HEADERS(sys/time.h) -dnl AC_HEADER_TIME +AC_CHECK_HEADERS([X11/extensions/XTest.h]) dnl checks for types dnl AC_TYPE_SIZE_T @@ -32,7 +32,13 @@ dnl checks for structures AC_STRUCT_TM dnl checks for compiler characteristics - +AC_CHECK_SIZEOF(char, 1) +AC_CHECK_SIZEOF(short, 2) +AC_CHECK_SIZEOF(int, 2) +AC_CHECK_SIZEOF(long, 4) +dnl should check for bool +dnl should require template support +dnl should require exception support dnl checks for library functions dnl AC_TYPE_SIGNAL diff --git a/mt/CCondVar.cpp b/mt/CCondVar.cpp index 397388df..76035aab 100644 --- a/mt/CCondVar.cpp +++ b/mt/CCondVar.cpp @@ -7,7 +7,7 @@ CCondVarBase::CCondVarBase(CMutex* mutex) : m_mutex(mutex) -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE , m_waitCountMutex() #endif { @@ -45,7 +45,7 @@ CCondVarBase::getMutex() const return m_mutex; } -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD #include "CThread.h" #include @@ -169,9 +169,9 @@ CCondVarBase::wait(CStopwatch& timer, double timeout) const } } -#endif // CONFIG_PTHREADS +#endif // HAVE_PTHREAD -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #include "CLock.h" #include "CThreadRep.h" @@ -312,4 +312,4 @@ CCondVarBase::wait(CStopwatch& timer, double timeout) const result == WAIT_OBJECT_0 + 1); } -#endif // CONFIG_PLATFORM_WIN32 +#endif // WINDOWS_LIKE diff --git a/mt/CCondVar.h b/mt/CCondVar.h index cf0f824b..1cf9f491 100644 --- a/mt/CCondVar.h +++ b/mt/CCondVar.h @@ -56,7 +56,7 @@ private: CMutex* m_mutex; void* m_cond; -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE enum { kSignal, kBroadcast }; mutable UInt32 m_waitCount; CMutex m_waitCountMutex; diff --git a/mt/CMutex.cpp b/mt/CMutex.cpp index dfae9faf..cabb0f69 100644 --- a/mt/CMutex.cpp +++ b/mt/CMutex.cpp @@ -26,7 +26,7 @@ CMutex::operator=(const CMutex&) return *this; } -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD #include #include @@ -98,9 +98,9 @@ CMutex::unlock() const } } -#endif // CONFIG_PTHREADS +#endif // HAVE_PTHREAD -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #define WIN32_LEAN_AND_MEAN #include @@ -133,4 +133,4 @@ CMutex::unlock() const LeaveCriticalSection(reinterpret_cast(m_mutex)); } -#endif // CONFIG_PLATFORM_WIN32 +#endif // WINDOWS_LIKE diff --git a/mt/CThread.cpp b/mt/CThread.cpp index c10c0636..80637a23 100644 --- a/mt/CThread.cpp +++ b/mt/CThread.cpp @@ -99,7 +99,7 @@ CThread::wait(double timeout) const return currentRep->wait(m_rep, timeout); } -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE bool CThread::waitForEvent(double timeout) { diff --git a/mt/CThread.h b/mt/CThread.h index 81c8aef8..264bd2ba 100644 --- a/mt/CThread.h +++ b/mt/CThread.h @@ -105,7 +105,7 @@ public: // (cancellation point) bool wait(double timeout = -1.0) const; -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE // wait for a message in the queue. returns true if a message // is available. // (cancellation point) diff --git a/mt/CThreadRep.cpp b/mt/CThreadRep.cpp index cf2d4111..ad2bedca 100644 --- a/mt/CThreadRep.cpp +++ b/mt/CThreadRep.cpp @@ -6,40 +6,34 @@ #include "CLog.h" #include "IJob.h" -#if defined(CONFIG_PTHREADS) -#include -#define SIGWAKEUP SIGUSR1 -#endif +#if HAVE_PTHREAD + +# include +# define SIGWAKEUP SIGUSR1 + +#elif WINDOWS_LIKE + +# if !defined(_MT) +# error multithreading compile option is required +# endif +# include + +#else + +#error unsupported platform for multithreading -#if defined(CONFIG_PLATFORM_WIN32) -# if !defined(_MT) -# error multithreading compile option is required -# endif -#include #endif // FIXME -- temporary exception type class XThreadUnavailable { }; -#if defined(CONFIG_PLATFORM_UNIX) && !defined(NDEBUG) -#include -#include -#include -#include -static void threadDebug(int) -{ - if (fork() == 0) abort(); - else { wait(0); exit(1); } -} -#endif - // // CThreadRep // CMutex* CThreadRep::s_mutex = NULL; CThreadRep* CThreadRep::s_head = NULL; -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD pthread_t CThreadRep::s_signalThread; #endif @@ -55,10 +49,10 @@ CThreadRep::CThreadRep() : // initialize stuff init(); -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD // get main thread id m_thread = pthread_self(); -#elif defined(CONFIG_PLATFORM_WIN32) +#elif WINDOWS_LIKE // get main thread id m_thread = NULL; m_id = GetCurrentThreadId(); @@ -94,7 +88,7 @@ CThreadRep::CThreadRep(IJob* job, void* userData) : CLock lock(s_mutex); // start the thread. throw if it doesn't start. -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD // mask some signals in all threads except the main thread sigset_t sigset, oldsigset; sigemptyset(&sigset); @@ -106,7 +100,7 @@ CThreadRep::CThreadRep(IJob* job, void* userData) : if (status != 0) { throw XThreadUnavailable(); } -#elif defined(CONFIG_PLATFORM_WIN32) +#elif WINDOWS_LIKE unsigned int id; m_thread = reinterpret_cast(_beginthreadex(NULL, 0, threadFunc, (void*)this, 0, &id)); @@ -151,7 +145,7 @@ CThreadRep::initThreads() if (s_mutex == NULL) { s_mutex = new CMutex; -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD // install SIGWAKEUP handler struct sigaction act; sigemptyset(&act.sa_mask); @@ -162,18 +156,11 @@ CThreadRep::initThreads() # endif act.sa_handler = &threadCancel; sigaction(SIGWAKEUP, &act, NULL); -# ifndef NDEBUG - act.sa_handler = &threadDebug; - sigaction(SIGSEGV, &act, NULL); -# endif // set signal mask sigset_t sigset; sigemptyset(&sigset); sigaddset(&sigset, SIGWAKEUP); -# ifndef NDEBUG - sigaddset(&sigset, SIGSEGV); -# endif pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); sigemptyset(&sigset); sigaddset(&sigset, SIGPIPE); @@ -196,7 +183,7 @@ CThreadRep::initThreads() sigaddset(&sigset, SIGTERM); pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); } -#endif +#endif // HAVE_PTHREAD } } @@ -251,9 +238,9 @@ CThreadRep::getCurrentThreadRep() { assert(s_mutex != NULL); -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD const pthread_t thread = pthread_self(); -#elif defined(CONFIG_PLATFORM_WIN32) +#elif WINDOWS_LIKE const DWORD id = GetCurrentThreadId(); #endif @@ -263,11 +250,11 @@ CThreadRep::getCurrentThreadRep() // search CThreadRep* scan = s_head; while (scan != NULL) { -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD if (scan->m_thread == thread) { break; } -#elif defined(CONFIG_PLATFORM_WIN32) +#elif WINDOWS_LIKE if (scan->m_id == id) { break; } @@ -326,10 +313,19 @@ CThreadRep::doThreadFunc() m_result = result; } -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD #include "CStopwatch.h" -#include +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif void CThreadRep::init() @@ -492,7 +488,9 @@ CThreadRep::threadSignalHandler(void* vrep) } } -#elif defined(CONFIG_PLATFORM_WIN32) +#endif // HAVE_PTHREAD + +#if WINDOWS_LIKE void CThreadRep::init() @@ -713,4 +711,4 @@ CThreadRep::threadFunc(void* arg) return 0; } -#endif +#endif // WINDOWS_LIKE diff --git a/mt/CThreadRep.h b/mt/CThreadRep.h index 448d2b4d..8869492c 100644 --- a/mt/CThreadRep.h +++ b/mt/CThreadRep.h @@ -1,11 +1,11 @@ #ifndef CTHREADREP_H #define CTHREADREP_H -#include "BasicTypes.h" +#include "common.h" -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD #include -#elif defined(CONFIG_PLATFORM_WIN32) +#elif WINDOWS_LIKE #define WIN32_LEAN_AND_MEAN #include #endif @@ -43,7 +43,7 @@ public: // wait for thread to exit or for current thread to cancel bool wait(CThreadRep*, double timeout); -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE // wait for a message on the queue bool waitForEvent(double timeout); #endif @@ -62,9 +62,9 @@ public: // get the current cancellable state bool isCancellable() const; -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD bool isExited() const; -#elif defined(CONFIG_PLATFORM_WIN32) +#elif WINDOWS_LIKE HANDLE getExitEvent() const; HANDLE getCancelEvent() const; #endif @@ -88,11 +88,11 @@ private: static CThreadRep* find(); // thread functions -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD static void* threadFunc(void* arg); static void threadCancel(int); static void* threadSignalHandler(void*); -#elif defined(CONFIG_PLATFORM_WIN32) +#elif WINDOWS_LIKE static unsigned int __stdcall threadFunc(void* arg); #endif void doThreadFunc(); @@ -108,22 +108,21 @@ private: CThreadRep* m_prev; CThreadRep* m_next; - SInt32 m_refCount; + int m_refCount; IJob* m_job; void* m_userData; void* m_result; bool m_cancellable; bool m_cancelling; - UInt32 m_signals; -#if defined(CONFIG_PTHREADS) +#if HAVE_PTHREAD pthread_t m_thread; bool m_exit; bool m_cancel; static pthread_t s_signalThread; #endif -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE HANDLE m_thread; DWORD m_id; HANDLE m_exit; diff --git a/net/CNetwork.cpp b/net/CNetwork.cpp index 29b5418a..2122a74d 100644 --- a/net/CNetwork.cpp +++ b/net/CNetwork.cpp @@ -37,7 +37,7 @@ struct protoent FAR * (PASCAL FAR *CNetwork::getprotobyname)(const char FAR * na int (PASCAL FAR *CNetwork::getsockerror)(void); int (PASCAL FAR *CNetwork::gethosterror)(void); -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE int (PASCAL FAR *CNetwork::select)(int nfds, fd_set FAR *readfds, fd_set FAR *writefds, fd_set FAR *exceptfds, const struct timeval FAR *timeout); int (PASCAL FAR *CNetwork::WSACleanup)(void); @@ -297,7 +297,7 @@ CNetwork::write2(Socket s, const void FAR* buf, size_t len) #endif -#if defined(CONFIG_PLATFORM_UNIX) +#if UNIX_LIKE #include #include diff --git a/net/CNetwork.h b/net/CNetwork.h index c66d8164..cf090ea1 100644 --- a/net/CNetwork.h +++ b/net/CNetwork.h @@ -3,21 +3,23 @@ #include "BasicTypes.h" -#if defined(CONFIG_PLATFORM_WIN32) -// declare no functions in winsock2 -# define INCL_WINSOCK_API_PROTOTYPES 0 -# define INCL_WINSOCK_API_TYPEDEFS 0 -# include +#if WINDOWS_LIKE + // declare no functions in winsock2 +# define INCL_WINSOCK_API_PROTOTYPES 0 +# define INCL_WINSOCK_API_TYPEDEFS 0 +# include typedef int ssize_t; -# if !defined(SOL_TCP) -# define SOL_TCP IPPROTO_TCP -# endif +# if !defined(SOL_TCP) +# define SOL_TCP IPPROTO_TCP +# endif #else -# define FAR -# define PASCAL +# undef FAR +# undef PASCAL +# define FAR +# define PASCAL #endif -#if defined(CONFIG_PLATFORM_UNIX) +#if UNIX_LIKE # include # include # include @@ -31,7 +33,7 @@ typedef int ssize_t; class CNetwork { public: -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE typedef SOCKET Socket; typedef struct sockaddr Address; typedef int AddressLength; @@ -48,7 +50,7 @@ public: kPOLLERR = 4, kPOLLNVAL = 8 }; -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE typedef int Socket; typedef struct sockaddr Address; typedef socklen_t AddressLength; @@ -80,9 +82,9 @@ public: // getsockerror() constants enum { -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE kEADDRINUSE = WSAEADDRINUSE, -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE kEADDRINUSE = EADDRINUSE, #endif kNone = 0 @@ -90,12 +92,12 @@ public: // gethosterror() constants enum { -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE kHOST_NOT_FOUND = WSAHOST_NOT_FOUND, kNO_DATA = WSANO_DATA, kNO_RECOVERY = WSANO_RECOVERY, kTRY_AGAIN = WSATRY_AGAIN, -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE kHOST_NOT_FOUND = HOST_NOT_FOUND, kNO_DATA = NO_DATA, kNO_RECOVERY = NO_RECOVERY, @@ -137,7 +139,7 @@ public: static int (PASCAL FAR *getsockerror)(void); static int (PASCAL FAR *gethosterror)(void); -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE private: static void init2(HMODULE); static int PASCAL FAR poll2(PollEntry[], int nfds, int timeout); diff --git a/platform/CPlatform.cpp b/platform/CPlatform.cpp index 79d7a047..c579d216 100644 --- a/platform/CPlatform.cpp +++ b/platform/CPlatform.cpp @@ -1,11 +1,15 @@ #include "common.h" -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #include "CWin32Platform.cpp" -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE #include "CUnixPlatform.cpp" +#else + +#error Unsupported platform + #endif diff --git a/platform/CPlatform.h b/platform/CPlatform.h index 76d2dea6..3ec1db2f 100644 --- a/platform/CPlatform.h +++ b/platform/CPlatform.h @@ -3,16 +3,20 @@ #include "common.h" -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #include "CWin32Platform.h" typedef CWin32Platform CPlatform; -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE #include "CUnixPlatform.h" typedef CUnixPlatform CPlatform; +#else + +#error Unsupported platform + #endif #endif diff --git a/platform/CXWindowsClipboard.h b/platform/CXWindowsClipboard.h index f1d04580..92657adc 100644 --- a/platform/CXWindowsClipboard.h +++ b/platform/CXWindowsClipboard.h @@ -5,7 +5,11 @@ #include "ClipboardTypes.h" #include "stdmap.h" #include "stdlist.h" -#include +#if defined(X_DISPLAY_MISSING) +# error X11 is required to build synergy +#else +# include +#endif class CXWindowsClipboard : public IClipboard { public: diff --git a/platform/CXWindowsScreen.h b/platform/CXWindowsScreen.h index 404d77b8..b589aba6 100644 --- a/platform/CXWindowsScreen.h +++ b/platform/CXWindowsScreen.h @@ -3,7 +3,11 @@ #include "ClipboardTypes.h" #include "CMutex.h" -#include +#if defined(X_DISPLAY_MISSING) +# error X11 is required to build synergy +#else +# include +#endif class IClipboard; class CXWindowsClipboard; diff --git a/platform/CXWindowsUtil.h b/platform/CXWindowsUtil.h index 3f01b667..9e8add53 100644 --- a/platform/CXWindowsUtil.h +++ b/platform/CXWindowsUtil.h @@ -3,7 +3,11 @@ #include "CString.h" #include "BasicTypes.h" -#include +#if defined(X_DISPLAY_MISSING) +# error X11 is required to build synergy +#else +# include +#endif class CXWindowsUtil { public: diff --git a/server/CServer.cpp b/server/CServer.cpp index d4de4240..91504f52 100644 --- a/server/CServer.cpp +++ b/server/CServer.cpp @@ -1353,9 +1353,9 @@ CServer::updatePrimaryClipboard(ClipboardID id) } // FIXME -- use factory to create screen -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #include "CMSWindowsPrimaryScreen.h" -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE #include "CXWindowsPrimaryScreen.h" #endif void @@ -1377,9 +1377,9 @@ CServer::openPrimaryScreen() // open screen log((CLOG_DEBUG1 "creating primary screen")); -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE m_primary = new CMSWindowsPrimaryScreen; -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE m_primary = new CXWindowsPrimaryScreen; #endif log((CLOG_DEBUG1 "opening primary screen")); diff --git a/server/CSynergyHook.h b/server/CSynergyHook.h index 2d38d708..159144c9 100644 --- a/server/CSynergyHook.h +++ b/server/CSynergyHook.h @@ -2,18 +2,19 @@ #define CSYNERGYHOOK_H #include "BasicTypes.h" + +#if WINDOWS_LIKE #define WIN32_LEAN_AND_MEAN #include +#else +#error CSynergyHook is a win32 specific file +#endif -#if defined(CONFIG_PLATFORM_WIN32) #if defined(SYNRGYHK_EXPORTS) #define CSYNERGYHOOK_API __declspec(dllexport) #else #define CSYNERGYHOOK_API __declspec(dllimport) #endif -#else -#define CSYNERGYHOOK_API -#endif #define SYNERGY_MSG_MARK WM_APP + 0x0011 // mark id; #define SYNERGY_MSG_KEY WM_APP + 0x0012 // vk code; key data diff --git a/server/CXWindowsPrimaryScreen.cpp b/server/CXWindowsPrimaryScreen.cpp index 75e3b467..c8ba3a68 100644 --- a/server/CXWindowsPrimaryScreen.cpp +++ b/server/CXWindowsPrimaryScreen.cpp @@ -5,10 +5,14 @@ #include "CThread.h" #include "CLog.h" #include "CStopwatch.h" -#include -#include -#define XK_MISCELLANY -#include +#if defined(X_DISPLAY_MISSING) +# error X11 is required to build synergy +#else +# include +# include +# define XK_MISCELLANY +# include +#endif // // CXWindowsPrimaryScreen diff --git a/server/server.cpp b/server/server.cpp index dbbf7e0f..18f55ec0 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -14,16 +14,16 @@ #include // platform dependent name of a daemon -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #define DAEMON_NAME "Synergy Server" -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE #define DAEMON_NAME "synergyd" #endif // configuration file name -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #define CONFIG_NAME "synergy.sgc" -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE #define CONFIG_NAME "synergy.conf" #endif @@ -34,7 +34,7 @@ static const char* pname = NULL; static bool s_restartable = true; static bool s_daemon = true; -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE static bool s_install = false; static bool s_uninstall = false; #endif @@ -209,7 +209,7 @@ static void help() { -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE # define PLATFORM_ARGS \ " {--daemon|--no-daemon}" \ @@ -398,7 +398,7 @@ parse(int argc, const char** argv) bye(0); } -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE else if (isArg(i, argc, argv, NULL, "--install")) { s_install = true; if (s_uninstall) { @@ -410,7 +410,7 @@ parse(int argc, const char** argv) } #endif -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE else if (isArg(i, argc, argv, NULL, "--uninstall")) { s_uninstall = true; if (s_install) { @@ -450,7 +450,7 @@ parse(int argc, const char** argv) // increase default filter level for daemon. the user must // explicitly request another level for a daemon. if (s_daemon && s_logFilter == NULL) { -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE if (CPlatform::isWindows95Family()) { // windows 95 has no place for logging so avoid showing // the log console window. @@ -541,7 +541,7 @@ loadConfig() // platform dependent entry points // -#if defined(CONFIG_PLATFORM_WIN32) +#if WINDOWS_LIKE #include "CMSWindowsScreen.h" @@ -726,7 +726,7 @@ WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int) return result; } -#elif defined(CONFIG_PLATFORM_UNIX) +#elif UNIX_LIKE static int diff --git a/synergy/CProtocolUtil.h b/synergy/CProtocolUtil.h index d6d1bce7..9c633b81 100644 --- a/synergy/CProtocolUtil.h +++ b/synergy/CProtocolUtil.h @@ -3,7 +3,7 @@ #include "BasicTypes.h" #include "XIO.h" -#include +#include class IInputStream; class IOutputStream;