Initial commit of the synergy trunk sources from sf.net

This commit is contained in:
Sorin Sbarnea 2009-02-27 11:54:59 +00:00
commit 958fa80d1d
429 changed files with 96848 additions and 0 deletions

86
lib/common/BasicTypes.h Normal file
View file

@ -0,0 +1,86 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef BASICTYPES_H
#define BASICTYPES_H
#include "common.h"
//
// pick types of particular sizes
//
#if !defined(TYPE_OF_SIZE_1)
# if SIZEOF_CHAR == 1
# define TYPE_OF_SIZE_1 char
# endif
#endif
#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)
// Carbon defines SInt32 and UInt32 in terms of long
# if SIZEOF_INT == 4 && !defined(__APPLE__)
# 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

31
lib/common/IInterface.h Normal file
View file

@ -0,0 +1,31 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef IINTERFACE_H
#define IINTERFACE_H
#include "common.h"
//! Base class of interfaces
/*!
This is the base class of all interface classes. An interface class has
only pure virtual methods.
*/
class IInterface {
public:
//! Interface destructor does nothing
virtual ~IInterface() { }
};
#endif

View file

@ -0,0 +1,8 @@
//
// Prefix header for all source files of the 'deleteme' target in the 'deleteme' project.
//
#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_2
#include <Carbon/Carbon.h>

48
lib/common/Makefile.am Normal file
View file

@ -0,0 +1,48 @@
# synergy -- mouse and keyboard sharing utility
# Copyright (C) 2002 Chris Schoeneman
#
# This package is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# found in the file COPYING that should have accompanied this file.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
## Process this file with automake to produce Makefile.in
NULL =
EXTRA_DIST = \
Makefile.win \
BasicTypes.h \
IInterface.h \
MacOSXPrecomp.h \
common.h \
stdbitset.h \
stddeque.h \
stdfstream.h \
stdistream.h \
stdlist.h \
stdmap.h \
stdostream.h \
stdpost.h \
stdpre.h \
stdset.h \
stdsstream.h \
stdstring.h \
stdvector.h \
$(NULL)
MAINTAINERCLEANFILES = \
Makefile.in \
$(NULL)
noinst_LIBRARIES = libcommon.a
libcommon_a_SOURCES = \
Version.cpp \
Version.h \
$(NULL)
INCLUDES = \
$(NULL)

53
lib/common/Makefile.win Normal file
View file

@ -0,0 +1,53 @@
# synergy -- mouse and keyboard sharing utility
# Copyright (C) 2007 Chris Schoeneman
#
# This package is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# found in the file COPYING that should have accompanied this file.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
LIB_COMMON_SRC = lib\common
LIB_COMMON_DST = $(BUILD_DST)\$(LIB_COMMON_SRC)
LIB_COMMON_LIB = "$(LIB_COMMON_DST)\common.lib"
LIB_COMMON_CPP = \
Version.cpp \
$(NULL)
LIB_COMMON_OBJ = \
"$(LIB_COMMON_DST)\Version.obj" \
$(NULL)
LIB_COMMON_INC = \
$(NULL)
CPP_FILES = $(CPP_FILES) $(LIB_COMMON_CPP)
OBJ_FILES = $(OBJ_FILES) $(LIB_COMMON_OBJ)
LIB_FILES = $(LIB_FILES) $(LIB_COMMON_LIB)
# Dependency rules
$(LIB_COMMON_OBJ): $(AUTODEP)
!if EXIST($(LIB_COMMON_DST)\deps.mak)
!include $(LIB_COMMON_DST)\deps.mak
!endif
# Build rules. Use batch-mode rules if possible.
!if DEFINED(_NMAKE_VER)
{$(LIB_COMMON_SRC)\}.cpp{$(LIB_COMMON_DST)\}.obj::
!else
{$(LIB_COMMON_SRC)\}.cpp{$(LIB_COMMON_DST)\}.obj:
!endif
@$(ECHO) Compile in $(LIB_COMMON_SRC)
-@$(MKDIR) $(LIB_COMMON_DST) 2>NUL:
$(cpp) $(cppdebug) $(cppflags) $(cppvarsmt) /showIncludes \
$(LIB_COMMON_INC) \
/Fo$(LIB_COMMON_DST)\ \
/Fd$(LIB_COMMON_LIB:.lib=.pdb) \
$< | $(AUTODEP) $(LIB_COMMON_SRC) $(LIB_COMMON_DST)
$(LIB_COMMON_LIB): $(LIB_COMMON_OBJ)
@$(ECHO) Link $(@F)
$(implib) $(ildebug) $(ilflags) \
/out:$@ \
$**
$(AUTODEP) $(LIB_COMMON_SRC) $(LIB_COMMON_DST) $(**:.obj=.d)

22
lib/common/Version.cpp Normal file
View file

@ -0,0 +1,22 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2004 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "Version.h"
const char* kApplication = "Synergy";
const char* kCopyright = "Copyright (C) 2002 Chris Schoeneman";
const char* kContact = "Chris Schoeneman, crs23@bigfoot.com";
const char* kWebsite = "http://synergy2.sourceforge.net/";
const char* kVersion = VERSION;
const char* kAppVersion = "Synergy " VERSION;

45
lib/common/Version.h Normal file
View file

@ -0,0 +1,45 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef VERSION_H
#define VERSION_H
#include "common.h"
// set version macro if not set yet
#if !defined(VERSION)
# define VERSION "1.3.2"
#endif
// important strings
extern const char* kApplication;
extern const char* kCopyright;
extern const char* kContact;
extern const char* kWebsite;
// build version. follows linux kernel style: an even minor number implies
// a release version, odd implies development version.
extern const char* kVersion;
// application version
extern const char* kAppVersion;
// exit codes
static const int kExitSuccess = 0; // successful completion
static const int kExitFailed = 1; // general failure
static const int kExitTerminated = 2; // killed by signal
static const int kExitArgs = 3; // bad arguments
static const int kExitConfig = 4; // cannot read configuration
#endif

135
lib/common/common.h Normal file
View file

@ -0,0 +1,135 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef COMMON_H
#define COMMON_H
// this file should be included, directly or indirectly by every other.
#if HAVE_CONFIG_H
# include "config.h"
// don't use poll() on mac
# if defined(__APPLE__)
# undef HAVE_POLL
# endif
#else
// we may not have run configure on win32
# if defined(_WIN32)
# define SYSAPI_WIN32 1
# define WINAPI_MSWINDOWS 1
# endif
// we may not have run configure on OS X
# if defined(__APPLE__)
# define SYSAPI_UNIX 1
# define WINAPI_CARBON 1
# define HAVE_CXX_BOOL 1
# define HAVE_CXX_CASTS 1
# define HAVE_CXX_EXCEPTIONS 1
# define HAVE_CXX_MUTABLE 1
# define HAVE_CXX_STDLIB 1
# define HAVE_GETPWUID_R 1
# define HAVE_GMTIME_R 1
# define HAVE_INET_ATON 1
# define HAVE_INTTYPES_H 1
# define HAVE_ISTREAM 1
# define HAVE_MEMORY_H 1
# define HAVE_NANOSLEEP 1
# define HAVE_OSTREAM 1
# define HAVE_POSIX_SIGWAIT 1
# define HAVE_PTHREAD 1
# define HAVE_PTHREAD_SIGNAL 1
# include <sys/types.h>
# include <sys/socket.h>
# if defined(_SOCKLEN_T)
# define HAVE_SOCKLEN_T 1
# endif
# define HAVE_SSTREAM 1
# define HAVE_STDINT_H 1
# define HAVE_STDLIB_H 1
# define HAVE_STRINGS_H 1
# define HAVE_STRING_H 1
# define HAVE_SYS_SELECT_H 1
# define HAVE_SYS_SOCKET_H 1
# define HAVE_SYS_STAT_H 1
# define HAVE_SYS_TIME_H 1
# define HAVE_SYS_TYPES_H 1
# define HAVE_SYS_UTSNAME_H 1
# define HAVE_UNISTD_H 1
# define HAVE_VSNPRINTF 1
/* disable this so we can build with the 10.2.8 SDK */
/*# define HAVE_WCHAR_H 1*/
# define SELECT_TYPE_ARG1 int
# define SELECT_TYPE_ARG234 (fd_set *)
# define SELECT_TYPE_ARG5 (struct timeval *)
# define SIZEOF_CHAR 1
# define SIZEOF_INT 4
# define SIZEOF_LONG 4
# define SIZEOF_SHORT 2
# define STDC_HEADERS 1
# define TIME_WITH_SYS_TIME 1
# define X_DISPLAY_MISSING 1
# endif
#endif
// VC++ specific
#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) // variable maybe used uninitialized
# endif
#endif // (_MSC_VER >= 1200)
// VC++ has built-in sized types
#if defined(_MSC_VER)
# include <wchar.h>
# 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
// FIXME -- including fp.h from Carbon.h causes a undefined symbol error
// on my build system. the symbol is scalb. since we don't need any
// math functions we define __FP__, the include guard macro for fp.h, to
// prevent fp.h from being included.
#if defined(__APPLE__)
#define __FP__
#endif
// define NULL
#include <stddef.h>
// make assert available since we use it a lot
#include <assert.h>
#endif

17
lib/common/stdbitset.h Normal file
View file

@ -0,0 +1,17 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stdpre.h"
#include <bitset>
#include "stdpost.h"

17
lib/common/stddeque.h Normal file
View file

@ -0,0 +1,17 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stdpre.h"
#include <deque>
#include "stdpost.h"

18
lib/common/stdfstream.h Normal file
View file

@ -0,0 +1,18 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stdpre.h"
#include <fstream>
#include "stdpost.h"
#include "stdistream.h"

43
lib/common/stdistream.h Normal file
View file

@ -0,0 +1,43 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stdpre.h"
#if HAVE_ISTREAM
#include <istream>
#else
#include <iostream>
#endif
#include "stdpost.h"
#if defined(_MSC_VER) && _MSC_VER <= 1200
// VC++6 istream has no overloads for __int* types, .NET does
inline
std::istream& operator>>(std::istream& s, SInt8& i)
{ return s >> (signed char&)i; }
inline
std::istream& operator>>(std::istream& s, SInt16& i)
{ return s >> (short&)i; }
inline
std::istream& operator>>(std::istream& s, SInt32& i)
{ return s >> (int&)i; }
inline
std::istream& operator>>(std::istream& s, UInt8& i)
{ return s >> (unsigned char&)i; }
inline
std::istream& operator>>(std::istream& s, UInt16& i)
{ return s >> (unsigned short&)i; }
inline
std::istream& operator>>(std::istream& s, UInt32& i)
{ return s >> (unsigned int&)i; }
#endif

17
lib/common/stdlist.h Normal file
View file

@ -0,0 +1,17 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stdpre.h"
#include <list>
#include "stdpost.h"

17
lib/common/stdmap.h Normal file
View file

@ -0,0 +1,17 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stdpre.h"
#include <map>
#include "stdpost.h"

21
lib/common/stdostream.h Normal file
View file

@ -0,0 +1,21 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stdpre.h"
#if HAVE_OSTREAM
#include <ostream>
#else
#include <iostream>
#endif
#include "stdpost.h"

17
lib/common/stdpost.h Normal file
View file

@ -0,0 +1,17 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#if defined(_MSC_VER)
#pragma warning(pop)
#endif

27
lib/common/stdpre.h Normal file
View file

@ -0,0 +1,27 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#if defined(_MSC_VER)
#pragma warning(disable: 4786) // identifier truncated
#pragma warning(disable: 4514) // unreferenced inline
#pragma warning(disable: 4710) // not inlined
#pragma warning(disable: 4663) // C++ change, template specialization
#pragma warning(disable: 4503) // decorated name length too long
#pragma warning(push, 3)
#pragma warning(disable: 4018) // signed/unsigned mismatch
#pragma warning(disable: 4284)
#pragma warning(disable: 4146) // unary minus on unsigned value
#pragma warning(disable: 4127) // conditional expression is constant
#pragma warning(disable: 4701) // variable possibly used uninitialized
#endif

17
lib/common/stdset.h Normal file
View file

@ -0,0 +1,17 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stdpre.h"
#include <set>
#include "stdpost.h"

371
lib/common/stdsstream.h Normal file
View file

@ -0,0 +1,371 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stdpre.h"
#if HAVE_SSTREAM || !defined(__GNUC__) || (__GNUC__ >= 3)
#include <sstream>
#elif defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 95)
// g++ 2.95 didn't ship with sstream. the following is a backport
// by Magnus Fromreide of the sstream in g++ 3.0.
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
Copyright (C) 2000 Free Software Foundation
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
/* Written by Magnus Fromreide (magfr@lysator.liu.se). */
/* seekoff and ideas for overflow is largely borrowed from libstdc++-v3 */
#include <iostream.h>
#include <streambuf.h>
#include <string>
namespace std
{
class stringbuf : public streambuf
{
public:
typedef char char_type;
typedef int int_type;
typedef streampos pos_type;
typedef streamoff off_type;
explicit
stringbuf(int which=ios::in|ios::out)
: streambuf(), mode(static_cast<ios::open_mode>(which)),
stream(NULL), stream_len(0)
{
stringbuf_init();
}
explicit
stringbuf(const string &str, int which=ios::in|ios::out)
: streambuf(), mode(static_cast<ios::open_mode>(which)),
stream(NULL), stream_len(0)
{
if (mode & (ios::in|ios::out))
{
stream_len = str.size();
stream = new char_type[stream_len];
str.copy(stream, stream_len);
}
stringbuf_init();
}
virtual
~stringbuf()
{
delete[] stream;
}
string
str() const
{
if (pbase() != 0)
return string(stream, pptr()-pbase());
else
return string();
}
void
str(const string& str)
{
delete[] stream;
stream_len = str.size();
stream = new char_type[stream_len];
str.copy(stream, stream_len);
stringbuf_init();
}
protected:
// The buffer is already in gptr, so if it ends then it is out of data.
virtual int
underflow()
{
return EOF;
}
virtual int
overflow(int c = EOF)
{
int res;
if (mode & ios::out)
{
if (c != EOF)
{
streamsize old_stream_len = stream_len;
stream_len += 1;
char_type* new_stream = new char_type[stream_len];
memcpy(new_stream, stream, old_stream_len);
delete[] stream;
stream = new_stream;
stringbuf_sync(gptr()-eback(), pptr()-pbase());
sputc(c);
res = c;
}
else
res = EOF;
}
else
res = 0;
return res;
}
virtual streambuf*
setbuf(char_type* s, streamsize n)
{
if (n != 0)
{
delete[] stream;
stream = new char_type[n];
memcpy(stream, s, n);
stream_len = n;
stringbuf_sync(0, 0);
}
return this;
}
virtual pos_type
seekoff(off_type off, ios::seek_dir way, int which = ios::in | ios::out)
{
pos_type ret = pos_type(off_type(-1));
bool testin = which & ios::in && mode & ios::in;
bool testout = which & ios::out && mode & ios::out;
bool testboth = testin && testout && way != ios::cur;
if (stream_len && ((testin != testout) || testboth))
{
char_type* beg = stream;
char_type* curi = NULL;
char_type* curo = NULL;
char_type* endi = NULL;
char_type* endo = NULL;
if (testin)
{
curi = gptr();
endi = egptr();
}
if (testout)
{
curo = pptr();
endo = epptr();
}
off_type newoffi = 0;
off_type newoffo = 0;
if (way == ios::beg)
{
newoffi = beg - curi;
newoffo = beg - curo;
}
else if (way == ios::end)
{
newoffi = endi - curi;
newoffo = endo - curo;
}
if (testin && newoffi + off + curi - beg >= 0 &&
endi - beg >= newoffi + off + curi - beg)
{
gbump(newoffi + off);
ret = pos_type(newoffi + off + curi);
}
if (testout && newoffo + off + curo - beg >= 0 &&
endo - beg >= newoffo + off + curo - beg)
{
pbump(newoffo + off);
ret = pos_type(newoffo + off + curo);
}
}
return ret;
}
virtual pos_type
seekpos(pos_type sp, int which = ios::in | ios::out)
{
pos_type ret = seekoff(sp, ios::beg, which);
return ret;
}
private:
void
stringbuf_sync(streamsize i, streamsize o)
{
if (mode & ios::in)
setg(stream, stream + i, stream + stream_len);
if (mode & ios::out)
{
setp(stream, stream + stream_len);
pbump(o);
}
}
void
stringbuf_init()
{
if (mode & ios::ate)
stringbuf_sync(0, stream_len);
else
stringbuf_sync(0, 0);
}
private:
ios::open_mode mode;
char_type* stream;
streamsize stream_len;
};
class istringstream : public istream {
public:
typedef char char_type;
typedef int int_type;
typedef streampos pos_type;
typedef streamoff off_type;
explicit
istringstream(int which=ios::in)
: istream(&sb), sb(which | ios::in)
{ }
explicit
istringstream(const string& str, int which=ios::in)
: istream(&sb), sb(str, which | ios::in)
{ }
stringbuf*
rdbuf() const
{
return const_cast<stringbuf*>(&sb);
}
string
str() const
{
return rdbuf()->str();
}
void
str(const string& s)
{
rdbuf()->str(s);
}
private:
stringbuf sb;
};
class ostringstream : public ostream {
public:
typedef char char_type;
typedef int int_type;
typedef streampos pos_type;
typedef streamoff off_type;
explicit
ostringstream(int which=ios::out)
: ostream(&sb), sb(which | ios::out)
{ }
explicit
ostringstream(const string& str, int which=ios::out)
: ostream(&sb), sb(str, which | ios::out)
{ }
stringbuf*
rdbuf() const
{
return const_cast<stringbuf*>(&sb);
}
string
str() const
{
return rdbuf()->str();
}
void str(const string& s)
{
rdbuf()->str(s);
}
private:
stringbuf sb;
};
class stringstream : public iostream {
public:
typedef char char_type;
typedef int int_type;
typedef streampos pos_type;
typedef streamoff off_type;
explicit
stringstream(int which=ios::out|ios::in)
: iostream(&sb), sb(which)
{ }
explicit
stringstream(const string& str, int which=ios::out|ios::in)
: iostream(&sb), sb(str, which)
{ }
stringbuf*
rdbuf() const
{
return const_cast<stringbuf*>(&sb);
}
string
str() const
{
return rdbuf()->str();
}
void
str(const string& s)
{
rdbuf()->str(s);
}
private:
stringbuf sb;
};
};
#else /* not g++ 2.95 and no <sstream> */
#error "Standard C++ library is missing required sstream header."
#endif /* not g++ 2.95 and no <sstream> */
#include "stdpost.h"
#include "stdistream.h"

17
lib/common/stdstring.h Normal file
View file

@ -0,0 +1,17 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stdpre.h"
#include <string>
#include "stdpost.h"

17
lib/common/stdvector.h Normal file
View file

@ -0,0 +1,17 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stdpre.h"
#include <vector>
#include "stdpost.h"