Initial import of the CDE 2.1.30 sources from the Open Group.

This commit is contained in:
Peter Howkins
2012-03-10 18:21:40 +00:00
commit 83b6996daa
18978 changed files with 3945623 additions and 0 deletions

View File

@@ -0,0 +1,264 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: CoEd.C /main/3 1995/10/20 17:05:50 rswiston $
/*
* CoEd.cc
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <desktop/tt_c.h>
#define InLibCoEd
#include "CoEd.h"
#include "CoEdFile.h"
#include "CoEdGlobals.h"
//#include "../libticccm/eclipse.h"
char *coEdProcID = 0;
CoEdSiteID *coEdSiteID = 0;
int coEdTtFd = -1;
int coEdTtStackMark = 0;
CoEdFileList *coEdFiles = 0;
const char *
coEdStatusMessage(
CoEdStatus status
)
{
switch (status) {
case CoEdWarnTimeout:
return "Timed out";
case CoEdErrFile:
return "Invalid file";
case CoEdErrNoMem:
return "Out of memory";
case CoEdErrBadPointer:
return "Invalid pointer";
case CoEdErrXDR:
return "XDR failed";
case CoEdErrBadMsg:
return "Invalid message";
case CoEdErrFailure:
return "System error";
default:
if ((status >= TT_OK) && (status < TT_ERR_APPFIRST)) {
return tt_status_message( (Tt_status)status );
} else {
return "Invalid CoEdStatus";
}
}
}
CoEdStatus
coEdInit( char* &returnProcID, int &pFd2Watch )
{
if (coEdProcID != 0) {
return CoEdOK;
}
coEdFiles = new CoEdFileList;
if (coEdFiles == 0) {
return CoEdErrNoMem;
}
//
// Initialize ToolTalk
//
coEdProcID = tt_open();
Tt_status err = tt_ptr_error( coEdProcID );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_open(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
returnProcID = strdup(coEdProcID);
coEdSiteID = new CoEdSiteID( coEdProcID );
if (coEdSiteID == 0) {
return CoEdErrNoMem;
}
//
// Get the file descriptor that ToolTalk will use to tell us
// of new messages.
//
coEdTtFd = tt_fd();
err = tt_int_error( coEdTtFd );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_fd(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
if (pFd2Watch == 0) {
return CoEdErrBadPointer;
}
pFd2Watch = coEdTtFd;
//
// Register a file-scoped pattern for the notices in the
// CoEd protocol.
//
Tt_pattern pat = tt_pattern_create();
err = tt_ptr_error( pat );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_create(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_op_add( pat, "Text_File_Changed" );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_op_add(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_op_add( pat, "Text_File_Poll_Version" );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_op_add(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_op_add( pat, "Text_File_Quiesce" );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_op_add(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_op_add( pat, "Text_File_Saved" );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_op_add(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_op_add( pat, "Text_File_Reverted" );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_op_add(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_op_add( pat, "Text_File_Renamed" );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_op_add(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_scope_add( pat, TT_FILE );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_scope_add(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_category_set( pat, TT_OBSERVE );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_category_set(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_register( pat );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_register(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
//
// Register a file-scoped pattern for the requests in the
// CoEd protocol.
//
Tt_pattern pat2 = tt_pattern_create();
err = tt_ptr_error( pat2 );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_create(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_op_add( pat2, "Text_File_Version_Vote" );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_op_add(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_scope_add( pat2, TT_FILE );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_scope_add(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_category_set( pat2, TT_HANDLE );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_category_set(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
err = tt_pattern_register( pat2 );
if (tt_is_err( err )) {
fprintf( stderr, "libCoEd: tt_pattern_register(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
return CoEdOK;
}
CoEdStatus
coEdFini()
{
delete coEdFiles;
tt_close();
return CoEdOK;
}
CoEdStatus
coEdHandleActiveFD( int )
{
Tt_status status;
// TtDtProcIDEclipse eclipse( coEdProcID, &status );
// if (status != TT_OK) {
// return (CoEdStatus)status;
// }
Tt_message msg = tt_message_receive();
if (msg == 0) {
return CoEdOK;
}
status = tt_ptr_error( msg );
if (tt_is_err( status )) {
fprintf( stderr, "libCoEd: tt_message_receive(): %s\n",
tt_status_message( status ));
return (CoEdStatus)CoEdOK;
}
char *msgFile = tt_message_file( msg );
status = tt_ptr_error( msgFile );
if (tt_is_err( status )) {
fprintf( stderr, "libCoEd: tt_message_file(): %s\n",
tt_status_message( status ));
return (CoEdStatus)CoEdOK;
}
if (msgFile == 0) {
return CoEdOK;
}
CoEdStatus retVal = coEdFiles->handleMsg( msgFile, msg );
tt_free( msgFile );
return retVal;
}

View File

@@ -0,0 +1,123 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: CoEd.h /main/3 1995/10/20 17:06:02 rswiston $ */
/* -*-C++-*-
*
* CoEd.h
*
* Copyright (c) 1991,1993 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#ifndef CoEd_h
#define CoEd_h
#include <desktop/tt_c.h>
typedef enum {
CoEdOK = TT_OK,
CoEdWarnTimeout = TT_WRN_APPFIRST, // 512
CoEdErrFile = TT_ERR_APPFIRST, // 1536
CoEdErrNoMem,
CoEdErrBadPointer,
CoEdErrXDR,
CoEdErrBadMsg,
CoEdErrFailure
} CoEdStatus;
#ifdef InLibCoEd
//
// CoEdTextBuffer is a class that clients of libCoEd implement.
// libCoEd invokes appropriate CoEdTextBuffer methods when it detects
// operations on the CoEdTextBuffer's associated text file.
//
class CoEdTextBuffer {
public:
CoEdStatus insertText( long start, long end, const char *text );
CoEdStatus save();
CoEdStatus revert();
CoEdStatus rename( const char *newPath );
};
#else
class CoEdTextBuffer;
#endif InLibCoEd
class CoEdTextVersion;
class CoEdChangeHistory;
class CoEdChangeQueue;
class CoEdTextChange;
class CoEdSiteIDList;
//
// CoEdFile is the class that libCoEd implements for its clients.
// Clients invoke appropriate CoEdFile methods after they have
// performed the corresponding user operation on the file.
//
class CoEdFile {
friend class CoEdFileList;
public:
CoEdFile( const char *path, CoEdTextBuffer *textBuf,
CoEdStatus &status, int timeOutSec = 0 );
~CoEdFile();
CoEdStatus insertText( long start, long end, const char *text );
CoEdStatus save();
CoEdStatus revert();
CoEdStatus rename( const char *newPath );
private:
char *_path;
CoEdTextBuffer *_textBuf;
CoEdTextVersion *_version;
CoEdTextVersion *_versionInQ;
CoEdSiteIDList *_coEditors;
CoEdChangeHistory *_appliedChanges;
CoEdChangeQueue *_unAppliedChanges;
int _numLocalChanges;
int _joining;
CoEdFile *_next;
CoEdFile *_prev;
CoEdStatus _handleMsg( Tt_message msg );
CoEdStatus _handleRequest( Tt_message msg );
CoEdStatus _handleJoin( Tt_message msg );
CoEdStatus _handleVersionVote( Tt_message msg );
CoEdStatus _handleNotice( Tt_message msg );
CoEdStatus _handleChanged( Tt_message msg );
CoEdStatus _handlePollVersion( Tt_message msg );
CoEdStatus _handleChange( CoEdTextChange *change,
int changeIsFromQueue = 0 );
};
CoEdStatus coEdInit( char* &returnProcID, int &pFd2Watch );
CoEdStatus coEdFini();
CoEdStatus coEdHandleActiveFD( int fd );
const char *coEdStatusMessage( CoEdStatus status );
#endif CoEd_h

View File

@@ -0,0 +1,128 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: CoEdChangeHistory.C /main/3 1995/10/20 17:06:11 rswiston $
/*
* CoEdChangeHistory.cc
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#include <string.h>
#include "CoEdChangeHistory.h"
CoEdChangeHistory::
CoEdChangeHistory() : CoEdTextChangeList()
{
}
void CoEdChangeHistory::
insert( CoEdTextChange *change )
{
CoEdTextChange *curr = _tail;
//
// Find the most recent change in the history that the
// incoming change knows of.
//
while (curr != 0) {
if (change->knowsOf( *curr )) {
break;
}
curr = curr->_prev;
}
//
// Bump curr to point to the first change that the incoming
// change doesn't know of.
//
if (curr == 0) {
curr = _head;
} else {
curr = curr->_next;
}
//
// The rest of the changes are mutually ignorant with the incoming
// change. Find the first one with a greater site id, and
// stick this change in front of it.
//
while (curr != 0) {
if (*change->_causer < *curr->_causer) {
break;
}
curr = curr->_next;
}
if (curr == 0) {
append( change );
} else {
insertBefore( change, curr );
}
}
CoEdTextChange *CoEdChangeHistory::
translate( CoEdTextChange &change )
{
_translateOverEarlierChgs( change );
return _translateOverLaterChgs( change );
}
//
// Modify <change> so that it takes into account any changes ahead of
// it in the change history that it does not know about.
//
void CoEdChangeHistory::
_translateOverEarlierChgs( CoEdTextChange &change )
{
CoEdTextChange *curr = _head;
while (curr != &change) {
if (! change.knowsOf( *curr )) {
change.translateOver( *curr );
}
curr = curr->_next;
}
}
//
// Take <change>, which is assumed to have been inserted into this
// ChangeHistory, and adjust the remaining changes in the history
// so that they take into account the change inserted ahead of them.
// Also, return a new CoEdTextChange that is a translated version
// of <change>, suitable for application to a textbuffer that
// has already had the remaining changes in the history applied to it.
//
CoEdTextChange *CoEdChangeHistory::
_translateOverLaterChgs( const CoEdTextChange &change )
{
CoEdTextChange *xlatdChng = new CoEdTextChange( change );
if (xlatdChng == 0) {
return 0;
}
CoEdTextChange *curr = change._next;
while (curr != 0) {
curr->interTranslate( *xlatdChng );
curr = curr->_next;
}
return xlatdChng;
}

View File

@@ -0,0 +1,51 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: CoEdChangeHistory.h /main/3 1995/10/20 17:06:20 rswiston $ */
/* -*-C++-*-
*
* CoEdChangeHistory.h
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#ifndef CoEdChangeHistory_h
#define CoEdChangeHistory_h
#include "CoEdTextChange.h"
class CoEdChangeHistory : private CoEdTextChangeList {
public:
CoEdChangeHistory();
void insert( CoEdTextChange *change );
CoEdTextChange *translate( CoEdTextChange &change );
private:
void _translateOverEarlierChgs( CoEdTextChange &change );
CoEdTextChange *_translateOverLaterChgs( const CoEdTextChange &change);
};
#endif CoEdChangeHistory_h

View File

@@ -0,0 +1,58 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: CoEdChangeQueue.C /main/3 1995/10/20 17:06:28 rswiston $
/*
* CoEdChangeQueue.cc
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#include <string.h>
#include "CoEdChangeQueue.h"
CoEdChangeQueue::
CoEdChangeQueue() : CoEdTextChangeList()
{
}
void CoEdChangeQueue::
insert( CoEdTextChange *change )
{
append( change );
}
CoEdTextChange *CoEdChangeQueue::
deQEligibleChng( const CoEdTextVersion &version )
{
CoEdTextChange *curr = _head;
while (curr != 0) {
if (! curr->knowsOfNewerChangesThan( version )) {
return remove( curr );
}
curr = curr->_next;
}
return 0;
}

View File

@@ -0,0 +1,47 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: CoEdChangeQueue.h /main/3 1995/10/20 17:06:37 rswiston $ */
/* -*-C++-*-
*
* CoEdChangeQueue.h
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#ifndef CoEdChangeQueue_h
#define CoEdChangeQueue_h
#include "CoEdTextChange.h"
class CoEdChangeQueue : private CoEdTextChangeList {
public:
CoEdChangeQueue();
void insert( CoEdTextChange *change );
CoEdTextChange *deQEligibleChng( const CoEdTextVersion &version );
};
#endif CoEdChangeQueue_h

View File

@@ -0,0 +1,612 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: CoEdFile.C /main/3 1995/10/20 17:06:45 rswiston $
/*
* CoEdFile.cc
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <sys/param.h>
#include <stdlib.h>
#include <poll.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "CoEdFile.h"
#include "CoEdGlobals.h"
#include "CoEdChangeHistory.h"
#include "CoEdChangeQueue.h"
#include "CoEdTextVersion.h"
#undef DEBUG
CoEdFile::
CoEdFile( const char *path, CoEdTextBuffer *textBuf, CoEdStatus &status,
int timeOutSec )
{
Tt_status err;
_next = 0;
_numLocalChanges = 0;
_joining = 1;
if (path == 0) {
fprintf( stderr, "libCoEd: can't join null file\n" );
status = CoEdErrFile;
return;
}
_appliedChanges = new CoEdChangeHistory;
if (_appliedChanges == 0) {
status = CoEdErrNoMem;
return;
}
_textBuf = textBuf;
if (_textBuf == 0) {
status = CoEdErrBadPointer;
return;
}
_unAppliedChanges = new CoEdChangeQueue;
if (_unAppliedChanges == 0) {
status = CoEdErrNoMem;
return;
}
_version = new CoEdTextVersion;
if (_version == 0) {
status = CoEdErrNoMem;
return;
}
_versionInQ = new CoEdTextVersion;
if (_versionInQ == 0) {
status = CoEdErrNoMem;
return;
}
_coEditors = new CoEdSiteIDList;
if (_coEditors == 0) {
status = CoEdErrNoMem;
return;
}
//
// Join the file.
//
err = tt_file_join( path );
if (err != TT_OK) {
fprintf( stderr, "libCoEd: %s: %s\n", path,
tt_status_message( err ));
status = (CoEdStatus)err;
return;
}
//
// Trick ToolTalk into translating the path into the canonical
// path that it will use to label messages about this file.
//
char *oldDefaultFile = tt_default_file();
err = tt_ptr_error( oldDefaultFile );
if (err != TT_OK) {
fprintf( stderr, "libCoEd: tt_default_file(): %s\n",
tt_status_message( err ));
status = (CoEdStatus)err;
return;
}
err = tt_default_file_set( path );
if (err != TT_OK) {
fprintf( stderr, "libCoEd: tt_default_file_set(\"%s\"): %s\n",
path, tt_status_message( err ));
status = (CoEdStatus)err;
return;
}
char *temp = tt_default_file();
err = tt_ptr_error( temp );
if (err != TT_OK) {
fprintf( stderr, "libCoEd: tt_default_file(): %s\n",
tt_status_message( err ));
status = (CoEdStatus)err;
return;
}
_path = strdup( temp );
if (_path == 0) {
status = CoEdErrNoMem;
return;
}
tt_free( temp );
if (oldDefaultFile != 0) {
//
// Reset the default file to what it was.
//
Tt_status err = tt_default_file_set( oldDefaultFile );
if (err != TT_OK) {
fprintf( stderr, "libCoEd: tt_default_file_set(\"%s\")"
": %s\n", oldDefaultFile,
tt_status_message( err ));
status = (CoEdStatus)err;
return;
}
}
tt_free( oldDefaultFile );
//
// Ask to join the file.
//
Tt_message msg = tt_prequest_create( TT_FILE, "Text_File_Join" );
Tt_status ttErr = tt_ptr_error( msg );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_prequest_create(): %s\n",
tt_status_message( ttErr ));
status = (CoEdStatus)ttErr;
return;
}
//
// Set the file of the message.
//
ttErr = tt_message_file_set( msg, _path );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_file_set(): %s\n",
tt_status_message( ttErr ));
status = (CoEdStatus)ttErr;
return;
}
//
// Send the message.
//
ttErr = tt_message_send( msg );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_send(): %s\n",
tt_status_message( ttErr ));
status = (CoEdStatus)ttErr;
return;
}
//
// Add ourselves to the list of files joined.
//
coEdFiles->append( this );
//
// Wait for the reply.
//
status = CoEdOK;
time_t start = time(0);
struct rlimit nofile;
getrlimit( RLIMIT_NOFILE, &nofile );
struct pollfd fds[ 1 ];
fds[ 0 ].fd = coEdTtFd;
fds[ 0 ].events = POLLIN;
while (_joining && (status == CoEdOK)) {
if ((timeOutSec > 0) && (time(0) - start > timeOutSec)) {
status = CoEdWarnTimeout;
break;
}
int activeFDs = poll( fds, 1, (1000*timeOutSec) );
if (activeFDs > 0) {
if (fds[ 0 ].revents & POLLIN) {
status = coEdHandleActiveFD( coEdTtFd );
}
} else if (activeFDs == 0) {
status = CoEdWarnTimeout;
} else {
perror( "libCoEd" );
status = CoEdErrFailure;
}
}
}
CoEdFile::
~CoEdFile()
{
// XXX unjoin from the file, remove from coEdFiles
if (_appliedChanges != 0) {
delete _appliedChanges;
}
if (_unAppliedChanges != 0) {
delete _unAppliedChanges;
}
if (_version != 0) {
delete _version;
}
if (_versionInQ != 0) {
delete _versionInQ;
}
if (_path != 0) {
free( _path );
}
}
CoEdStatus CoEdFile::
insertText( long start, long end, const char *text )
{
CoEdTextChange *change;
_numLocalChanges++;
change = new CoEdTextChange( start, end, text, _version, coEdSiteID,
_numLocalChanges );
_version ->update( *coEdSiteID, _numLocalChanges );
_versionInQ->update( *coEdSiteID, _numLocalChanges );
if (change == 0) {
return CoEdErrNoMem;
}
_appliedChanges->insert( change );
return change->broadcast( _path );
}
CoEdStatus CoEdFile::
_handleMsg( Tt_message msg )
{
Tt_class theClass = tt_message_class( msg );
Tt_status err = tt_int_error( theClass );
if (err != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_class(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
switch (theClass) {
case TT_REQUEST:
return _handleRequest( msg );
case TT_NOTICE:
return _handleNotice( msg );
default:
fprintf( stderr, "libCoEd: bad Tt_class!\n" );
return CoEdOK;
}
}
CoEdStatus CoEdFile::
_handleRequest( Tt_message msg )
{
CoEdStatus val2Return;
char *op = tt_message_op( msg );
Tt_status err = tt_ptr_error( op );
if (err != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_op(): %s\n",
tt_status_message( err ));
val2Return = (CoEdStatus)err;
}
if (op == 0) {
fprintf( stderr, "libCoEd: msg has null op!\n" );
val2Return = CoEdErrBadMsg;
}
if (! strcmp( op, "Text_File_Join" )) {
val2Return = _handleJoin( msg );
} else if (! strcmp( op, "Text_File_Version_Vote" )) {
//val2Return = _handleVersionVote( msg );
} else {
fprintf( stderr, "libCoEd: unknown msg op \"%s\"\n", op );
val2Return = CoEdErrBadMsg;
}
return val2Return;
}
CoEdStatus CoEdFile::
_handleJoin( Tt_message msg )
{
Tt_status ttErr;
Tt_state state = tt_message_state( msg );
ttErr = tt_int_error( state );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_state(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
switch (state) {
char *sender;
Tt_status ttErr;
case TT_FAILED:
//
// Nobody handled our request, so we must be the
// first process to have joined the file.
//
_joining = 0;
return CoEdOK;
case TT_SENT:
//
// If the Text_File_Join request was sent by us, we
// don't care about it.
//
sender = tt_message_sender( msg );
ttErr = tt_ptr_error( sender );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_sender(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
if (sender == 0) {
return CoEdErrBadMsg;
}
if (! strcmp( sender, coEdProcID )) {
tt_free( sender );
//
// The request was made by us, so we reject it, in
// order to give someone in the know a chance to
// handle it.
//
ttErr = tt_message_reject( msg );
if (ttErr != TT_OK) {
fprintf( stderr,
"libCoEd: tt_message_reject(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
return CoEdOK;
}
tt_free( sender );
// XXX Quiesce the file, and ship 'em a copy.
tt_message_fail( msg );
return CoEdOK;
default:
fprintf( stderr, "msg state: %d!\n", (int)state );
tt_message_reject( msg );
break;
}
return CoEdOK;
} /* CoEdFile::_handleJoin() */
CoEdStatus CoEdFile::
_handleNotice( Tt_message msg )
{
Tt_state state = tt_message_state( msg );
Tt_status err = tt_int_error( state );
if (err != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_state(): %s\n",
tt_status_message( err ));
return (CoEdStatus)err;
}
if (state != TT_SENT) {
return CoEdOK;
}
CoEdStatus val2Return;
char *op = tt_message_op( msg );
err = tt_ptr_error( op );
if (err != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_op(): %s\n",
tt_status_message( err ));
val2Return = (CoEdStatus)err;
}
if (op == 0) {
fprintf( stderr, "libCoEd: msg has null op!\n" );
val2Return = CoEdErrBadMsg;
}
if (! strcmp( op, "Text_File_Changed" )) {
val2Return = _handleChanged( msg );
} else if (! strcmp( op, "Text_File_Poll_Version" )) {
val2Return = _handlePollVersion( msg );
} else {
fprintf( stderr, "libCoEd: unknown msg op \"%s\"\n", op );
val2Return = CoEdErrBadMsg;
}
tt_message_destroy( msg );
return val2Return;
}
CoEdStatus CoEdFile::
_handleChanged( Tt_message msg )
{
if (_joining) {
fprintf( stderr, "libCoEd: warning: got a change while "
"joining \"%s\"\n", _path );
return CoEdOK;
}
//
// If the Text_File_Changed notice was sent by us, we don't care
// about it.
//
char *sender = tt_message_sender( msg );
Tt_status ttErr = tt_ptr_error( sender );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_sender(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
if (sender == 0) {
return CoEdErrBadMsg;
}
if (! strcmp( sender, coEdProcID )) {
tt_free( sender );
return CoEdOK;
}
tt_free( sender );
//
// It was not sent by us. Process it.
//
CoEdStatus err;
CoEdTextChange *change = new CoEdTextChange( msg, err );
if (err != CoEdOK) {
return CoEdOK;
}
return _handleChange( change );
}
CoEdStatus CoEdFile::
_handlePollVersion( Tt_message msg )
{
//
// If the Text_File_Changed notice was sent by us, we don't care
// about it.
//
char *sender = tt_message_sender( msg );
Tt_status ttErr = tt_ptr_error( sender );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_sender(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
if (sender == 0) {
return CoEdErrBadMsg;
}
if (! strcmp( sender, coEdProcID )) {
tt_free( sender );
return CoEdOK;
}
tt_free( sender );
//
// It was not sent by us. Respond.
//
Tt_message response = tt_prequest_create( TT_FILE,
"Text_File_Version_Vote" );
ttErr = tt_ptr_error( response );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_prequest_create(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
//
// Set the file of the response.
//
ttErr = tt_message_file_set( response, _path );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_file_set(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
//
// Aim the response back at the sender
//
ttErr = tt_message_handler_set( response, sender );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_handler_set(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
//
// Send the message.
//
ttErr = tt_message_send( response );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_send(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
//
// We don't expect or care about a reply, so destroy the
// message now.
//
return CoEdOK;
}
CoEdStatus CoEdFile::
_handleChange( CoEdTextChange *change, int changeIsFromQueue )
{
if (change->knowsOfNewerChangesThan( *_version )) {
if (changeIsFromQueue) {
fprintf( stderr, "Re-queuing change!\n" );
abort();
}
_unAppliedChanges->insert( change );
_versionInQ->update( change->causer(), change->changeNum() );
} else {
_appliedChanges->insert( change );
CoEdTextChange *translatedChange =
_appliedChanges->translate( *change );
if (translatedChange != 0) {
CoEdStatus err;
err = _textBuf->insertText( translatedChange->start(),
translatedChange->end(),
translatedChange->text() );
if (err != CoEdOK) {
fprintf( stderr, "libCoEd: CoEdTextBuffer::"
"insertText(): %d! Failed change: ");
translatedChange->print( stderr );
}
delete translatedChange;
}
_version->update( change->causer(), change->changeNum() );
if (! changeIsFromQueue) {
_versionInQ->update( change->causer(),
change->changeNum() );
}
}
CoEdTextChange *newlyEligibleChange =
_unAppliedChanges->deQEligibleChng( *_version );
if (newlyEligibleChange != 0) {
return _handleChange( newlyEligibleChange, 1 );
} else {
return CoEdOK;
}
}
CoEdFileList::
CoEdFileList()
{
_head = 0;
_tail = 0;
_count = 0;
}
CoEdFileList::
~CoEdFileList()
{
CoEdFile *curr = _head;
CoEdFile *prev;
while (curr != 0) {
prev = curr;
curr = curr->_next;
delete prev;
}
}
void CoEdFileList::
push( CoEdFile *file )
{
file->_next = _head;
file->_prev = 0;
if (_tail == 0) {
_tail = file;
} else {
_head->_prev = file;
}
_head = file;
_count++;
}
void CoEdFileList::
append( CoEdFile *file )
{
file->_next = 0;
file->_prev = _tail;
if (_head == 0) {
_head = file;
} else {
_tail->_next = file;
}
_tail = file;
_count++;
}
CoEdStatus CoEdFileList::
handleMsg( const char *path, Tt_message msg )
{
if (path == 0) {
fprintf( stderr, "libCoEd: got msg for null file!\n" );
return CoEdErrFile;
}
CoEdFile *curr = _head;
while (curr != 0) {
if ((curr->_path != 0) && (! strcmp( path, curr->_path))) {
return curr->_handleMsg( msg );
}
curr = curr->_next;
}
fprintf( stderr, "libCoEd: \"%s\" is not a file being CoEdited.\n",
path );
return CoEdErrFile;
}

View File

@@ -0,0 +1,60 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: CoEdFile.h /main/3 1995/10/20 17:06:55 rswiston $ */
/* -*-C++-*-
*
* CoEdFile.h
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#ifndef CoEdFile_h
#define CoEdFile_h
#include <desktop/tt_c.h>
#define InLibCoEd
#include "CoEd.h"
class CoEdFileList {
public:
CoEdFileList();
~CoEdFileList();
void push( CoEdFile *change );
void append( CoEdFile *change );
CoEdStatus handleMsg( const char *path, Tt_message msg );
private:
CoEdFile *_head;
CoEdFile *_tail;
int _count;
};
#include "CoEd.h"
#endif CoEdFile_h

View File

@@ -0,0 +1,47 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: CoEdGlobals.h /main/3 1995/10/20 17:07:02 rswiston $ */
/*
* CoEdGlobals.h
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#ifndef CoEdGlobals_h
#define CoEdGlobals_h
#include "CoEd.h"
#include "CoEdSiteID.h"
extern char *coEdProcID;
extern int coEdTtFd;
extern int coEdTtStackMark;
extern CoEdFileList *coEdFiles;
extern CoEdSiteID *coEdSiteID;
int coEdSelect( int fd, long timeoutSec = 0, long timeoutUSec = 0 );
#endif CoEdGlobals_h

View File

@@ -0,0 +1,258 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: CoEdSiteID.C /main/3 1995/10/20 17:07:11 rswiston $
/*
* CoEdSiteID.cc
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#include <string.h>
#include <malloc.h>
#include "CoEdSiteID.h"
CoEdSiteID::
CoEdSiteID()
{
_procID = 0;
_next = 0;
_prev = 0;
}
CoEdSiteID::
CoEdSiteID( const char *procID )
{
if (procID == 0) {
_procID = 0;
} else {
_procID = strdup( procID );
}
_next = 0;
_prev = 0;
}
CoEdSiteID::
CoEdSiteID( const CoEdSiteID &id )
{
if (id._procID == 0) {
_procID = 0;
} else {
_procID = strdup( id._procID );
}
_next = 0;
_prev = 0;
}
CoEdSiteID::
~CoEdSiteID()
{
if (_procID != 0) {
free( _procID );
}
}
bool_t CoEdSiteID::
xdr( XDR *xdrStream )
{
#ifndef WRAPSTRING_FIXED
int len;
switch (xdrStream->x_op) {
case XDR_ENCODE:
if (_procID == 0) {
len = 0;
} else {
len = strlen(_procID);
}
if (! xdr_int( xdrStream, &len )) {
return FALSE;
}
if (_procID != 0) {
if (! xdr_vector( xdrStream, _procID, (u_int)len,
sizeof(char), (xdrproc_t)xdr_char ))
{
return FALSE;
}
}
break;
case XDR_DECODE:
if (! xdr_int( xdrStream, &len )) {
return FALSE;
}
if (_procID != 0) {
free( _procID );
}
_procID = 0;
if (len > 0) {
_procID = (char *)malloc( len + 1 );
if (_procID == 0) {
return FALSE;
}
if (! xdr_vector( xdrStream, _procID, (u_int)len,
sizeof(char), (xdrproc_t)xdr_char ))
{
free( _procID );
return FALSE;
}
_procID[ len ] = '\0';
}
break;
}
return TRUE;
#else
char *string;
if (! xdr_wrapstring( xdrStream, &string )) {
return FALSE;
}
_procID = strdup( string );
xdr_free( xdr_wrapstring, string );
return TRUE;
#endif
}
CoEdSiteID *CoEdSiteID::
copy() const
{
return new CoEdSiteID( _procID );
}
CoEdSiteID &CoEdSiteID::
copy( const CoEdSiteID *id2Copy )
{
if (_procID != 0) {
free( _procID );
}
if (id2Copy->_procID == 0) {
_procID = 0;
} else {
_procID = strdup( id2Copy->_procID );
}
return *this;
}
int CoEdSiteID::
cmp( const CoEdSiteID &id ) const
{
if (_procID == id._procID) {
return 0;
}
if (_procID == 0) {
return -1;
}
if (id._procID == 0) {
return 1;
}
return strcmp( _procID, id._procID );
}
void CoEdSiteID::
print( FILE *f ) const
{
if (_procID != 0) {
fprintf( f, "%-3.3s", _procID );
}
}
CoEdSiteIDList::
CoEdSiteIDList()
{
_head = 0;
_tail = 0;
_count = 0;
}
CoEdSiteIDList::
~CoEdSiteIDList()
{
_flush();
}
void CoEdSiteIDList::
push( CoEdSiteID *site )
{
site->_next = _head;
site->_prev = 0;
if (_tail == 0) {
_tail = site;
} else {
_head->_prev = site;
}
_head = site;
_count++;
}
void CoEdSiteIDList::
append( CoEdSiteID *site )
{
site->_next = 0;
site->_prev = _tail;
if (_head == 0) {
_head = site;
} else {
_tail->_next = site;
}
_tail = site;
_count++;
}
void CoEdSiteIDList::
insertBefore( CoEdSiteID *site1, CoEdSiteID *site2 )
{
if (_head == site2) {
push( site1 );
return;
}
site1->_next = site2;
site1->_prev = site2->_prev;
site2->_prev->_next = site1;
site2->_prev = site1;
_count++;
}
void CoEdSiteIDList::
insertAfter( CoEdSiteID *site2, CoEdSiteID *site1 )
{
if (_tail == site1) {
append( site2 );
return;
}
site2->_next = site1->_next;
site2->_prev = site1;
site1->_next->_prev = site2;
site1->_next = site2;
_count++;
}
void CoEdSiteIDList::
_flush()
{
CoEdSiteID *curr = _head;
CoEdSiteID *prev;
while (curr != 0) {
prev = curr;
curr = curr->_next;
delete prev;
}
}

View File

@@ -0,0 +1,90 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: CoEdSiteID.h /main/3 1995/10/20 17:07:21 rswiston $ */
/* -*-C++-*-
*
* CoEdSiteID.h
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#ifndef CoEdSiteID_h
#define CoEdSiteID_h
#include <rpc/types.h>
#include <rpc/xdr.h>
class CoEdSiteID {
friend class CoEdSiteIDList;
friend class SiteChangeList;
friend class CoEdTextVersion;
public:
CoEdSiteID();
CoEdSiteID( const char *procID );
CoEdSiteID( const CoEdSiteID &id );
~CoEdSiteID();
bool_t xdr( XDR *xdrStream );
CoEdSiteID *copy() const;
CoEdSiteID &copy( const CoEdSiteID *id2Copy );
int cmp( const CoEdSiteID &id ) const;
int operator==( const CoEdSiteID &id ) const
{ return (cmp( id ) == 0); }
int operator<( const CoEdSiteID &id ) const
{ return (cmp( id ) < 0); }
void print( FILE *f ) const;
private:
char *_procID;
CoEdSiteID *_next;
CoEdSiteID *_prev;
};
class CoEdSiteIDList {
public:
CoEdSiteIDList();
~CoEdSiteIDList();
void push( CoEdSiteID *change );
void append( CoEdSiteID *change );
void insertBefore( CoEdSiteID *change1,
CoEdSiteID *change2 );
void insertAfter( CoEdSiteID *change2,
CoEdSiteID *change1 );
int isEmpty() const
{ return (_count == 0); }
private:
CoEdSiteID *_head;
CoEdSiteID *_tail;
int _count;
void _flush();
};
#endif CoEdSiteID_h

View File

@@ -0,0 +1,539 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: CoEdTextChange.C /main/3 1995/10/20 17:07:30 rswiston $
/*
* CoEdTextChange.cc
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <limits.h>
#include "CoEdTextVersion.h"
#include "CoEdTextChange.h"
#undef DEBUG
CoEdTextChange::
CoEdTextChange()
{
_start = 0;
_end = 0;
_text = 0;
_appliesTo = 0;
_causer = 0;
_changeNum = 0;
_charsAdded = 0;
_next = 0;
_prev = 0;
}
CoEdTextChange::
CoEdTextChange( long start, long end, const char *text,
const CoEdTextVersion *appliesTo, const CoEdSiteID *causer,
int changeNum )
{
_next = 0;
_prev = 0;
_start = start;
_end = end;
if (text != 0) {
_text = strdup( text );
} else {
_text = 0;
}
_charsAdded = ((_text == 0) ? 0 : strlen( _text ))
- (_end - _start);
_appliesTo = appliesTo->copy();
_causer = causer->copy();
_changeNum = changeNum;
}
CoEdTextChange::
CoEdTextChange( const CoEdTextChange &change )
{
_next = 0;
_prev = 0;
_start = change._start;
_end = change._end;
if (change._text != 0) {
_text = strdup( change._text );
} else {
_text = 0;
}
_charsAdded = change._charsAdded;
_appliesTo = change._appliesTo->copy();
_causer = change._causer->copy();
_changeNum = change._changeNum;
}
CoEdTextChange::
CoEdTextChange( Tt_message msg, CoEdStatus &status )
{
unsigned char *data;
int len;
_next = 0;
_prev = 0;
_charsAdded = 0;
//
// Extract arg 0: CoEdTextVersion
//
Tt_status ttErr = tt_message_arg_bval( msg, 0, &data, &len );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_arg_bval(): %s\n",
tt_status_message( ttErr ));
status = (CoEdStatus)ttErr;
return;
}
_appliesTo = new CoEdTextVersion( data, len, status );
if (status != CoEdOK) {
return;
}
//
// Extract arg 1: changeNum
//
int argVal;
ttErr = tt_message_arg_ival( msg, 1, &argVal );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_arg_ival(): %s\n",
tt_status_message( ttErr ));
status = (CoEdStatus)ttErr;
return;
}
_changeNum = argVal;
//
// Extract arg 2: start
//
ttErr = tt_message_arg_ival( msg, 2, &argVal );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_arg_ival(): %s\n",
tt_status_message( ttErr ));
status = (CoEdStatus)ttErr;
return;
}
_start = argVal;
//
// Extract arg 3: end
//
ttErr = tt_message_arg_ival( msg, 3, &argVal );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_arg_ival(): %s\n",
tt_status_message( ttErr ));
status = (CoEdStatus)ttErr;
return;
}
_end = argVal;
//
// Extract arg 4: text
//
char *temp = tt_message_arg_val( msg, 4 );
ttErr = tt_ptr_error( temp );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_arg_val(): %s\n",
tt_status_message( ttErr ));
status = (CoEdStatus)ttErr;
return;
}
if (temp == 0) {
_text = 0;
} else {
_text = strdup( temp );
if (_text == 0) {
fprintf( stderr, "libCoEd: ran out of memory!\n" );
status = CoEdErrNoMem;
return;
}
tt_free( temp );
}
_charsAdded = _end - _start
+ ((_text == 0) ? 0 : strlen( _text ));
//
// Extract who caused the change.
//
temp = tt_message_sender( msg );
ttErr = tt_ptr_error( temp );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_sender(): %s\n",
tt_status_message( ttErr ));
status = (CoEdStatus)ttErr;
return;
}
_causer = new CoEdSiteID( temp );
if (_causer == 0) {
fprintf( stderr, "libCoEd: ran out of memory!\n" );
status = CoEdErrNoMem;
return;
}
tt_free( temp );
status = CoEdOK;
}
CoEdTextChange::
~CoEdTextChange()
{
if (_text != 0) {
free( (char *)_text );
}
if (_appliesTo != 0) {
delete _appliesTo;
}
if (_causer != 0) {
delete _causer;
}
}
CoEdStatus CoEdTextChange::
broadcast( const char *path ) const
{
//
// Create the message.
//
Tt_message msg = tt_pnotice_create( TT_FILE, "Text_File_Changed" );
Tt_status ttErr = tt_ptr_error( msg );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_pnotice_create(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
//
// Set the file of the message.
//
ttErr = tt_message_file_set( msg, path );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_file_set(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
//
// Add arg 0: CoEdTextVersion
//
unsigned long len;
unsigned char *data;
CoEdStatus err = _appliesTo->serialize( &data, &len );
if (err != CoEdOK) {
fprintf( stderr, "libCoEd: CoEdTextVersion::serialize(): %d\n",
(int)err );
return err;
}
ttErr = tt_message_barg_add( msg, TT_IN, "CoEdTextVersion", data,
(int)len );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_barg_add(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
//
// Add arg 1: changeNum
//
ttErr = tt_message_iarg_add( msg, TT_IN, "int", (int)_changeNum );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_iarg_add(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
//
// Add arg 2: start
//
ttErr = tt_message_iarg_add( msg, TT_IN, "int", (int)_start );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_iarg_add(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
//
// Add arg 3: end
//
ttErr = tt_message_iarg_add( msg, TT_IN, "int", (int)_end );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_iarg_add(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
//
// Add arg 4: text
//
if (_text == 0) {
ttErr = tt_message_arg_add( msg, TT_IN, "string", "" );
} else {
ttErr = tt_message_arg_add( msg, TT_IN, "string", _text );
}
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_arg_add(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
//
// Send the message.
//
#ifdef DEBUG
static Tt_message oldMsg = 0;
if (oldMsg == 0) {
oldMsg = msg;
return CoEdOK;
} else {
ttErr = tt_message_send( oldMsg );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_send(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
ttErr = tt_message_destroy( oldMsg );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_destroy(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
oldMsg = 0;
}
#endif DEBUG
ttErr = tt_message_send( msg );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_send(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
ttErr = tt_message_destroy( msg );
if (ttErr != TT_OK) {
fprintf( stderr, "libCoEd: tt_message_destroy(): %s\n",
tt_status_message( ttErr ));
return (CoEdStatus)ttErr;
}
return CoEdOK;
}
//
// This method serves two purposes. First, it takes chng2Xlate,
// and adjusts it forward in time over this change, so that we
// will be able to apply the modified chng2Xlate to our local
// text (to which this change has already been applied).
// Second, since the _un_modified chng2Xlate is being put into the
// history list _before_ this change, we need to modify this
// change so that it makes sense when applied to a text that
// has already had the unmodified chng2Xlate applied to it.
//
void CoEdTextChange::
interTranslate( CoEdTextChange &chng2Xlate )
{
//
// First, adjust chng2Xlate forward in time over this change.
//
int directionToLean = (chng2Xlate._end > _end) ? 1 : 0;
long xlatdStart = adjustPt( chng2Xlate._start, *chng2Xlate._causer,
directionToLean );
directionToLean = (chng2Xlate._start < _start) ? -1 : 0;
long xlatdEnd = adjustPt( chng2Xlate._end, *chng2Xlate._causer,
directionToLean );
//
// Second, adjust this change into a form that makes
// sense if chng2Xlate had already been applied when
// it was time to apply this change.
//
directionToLean = (_end > chng2Xlate._end) ? 1 : 0;
long _startNew = chng2Xlate.adjustPt( _start, *_causer,
directionToLean );
directionToLean = (_start < chng2Xlate._start) ? -1 : 0;
long _endNew = chng2Xlate.adjustPt( _end, *_causer, directionToLean );
//
// Now, modify this change and chng2Xlate, as calculated.
//
_start = _startNew;
_end = _endNew;
//_appliesTo->update( *chng2Xlate._causer, chng2Xlate._changeNum );
chng2Xlate._start = xlatdStart;
chng2Xlate._end = xlatdEnd;
//chng2Xlate._appliesTo->update( *_causer, _changeNum );
}
void CoEdTextChange::
translateOver( const CoEdTextChange &chng2Hurdle )
{
int directionToLean = (_end > chng2Hurdle._end) ? 1 : 0;
long newStart = chng2Hurdle.adjustPt( _start, *_causer,
directionToLean );
directionToLean = (_start < chng2Hurdle._start) ? -1 : 0;
long newEnd = chng2Hurdle.adjustPt( _end, *_causer,
directionToLean );
//_appliesTo->update( *chng2Hurdle._causer, chng2Hurdle._changeNum );
_start = newStart;
_end = newEnd;
}
long CoEdTextChange::
adjustPt( long pt, const CoEdSiteID &ptOwner, int directionToLean ) const
{
if (pt < _start) {
return pt;
}
if (pt > _end) {
return pt + charsAddedBy();
}
//
// pt lies within our change, so it needs to be adjusted to
// one end of our change. First, check if the caller has
// a preference.
//
if (directionToLean < 0) {
return _start;
} else if (directionToLean > 0) {
return _start + charsAddedBy();
} else {
//
// The caller has no preference, so decide by order
// of CoEdSiteID.
//
if (*_causer < ptOwner) {
return _start + charsAddedBy();
} else {
return _start;
}
}
}
void CoEdTextChange::
print( FILE *f )
{
fprintf( f, "[%3d, %3d] %2d: <", _start, _end, _charsAdded );
if (_text == 0) {
fprintf( f, "%6s", ">" );
} else {
fprintf( f, "%-5.5s>", _text );
}
fprintf( f, " #%2d ", _changeNum );
_causer->print( f );
fputs( " ", f );
_appliesTo->print( f );
fputs( "\n", f );
}
CoEdTextChangeList::
CoEdTextChangeList()
{
_head = 0;
_tail = 0;
_count = 0;
}
CoEdTextChangeList::
~CoEdTextChangeList()
{
CoEdTextChange *curr = _head;
CoEdTextChange *prev;
while (curr != 0) {
prev = curr;
curr = curr->_next;
delete prev;
}
}
void CoEdTextChangeList::
push( CoEdTextChange *change )
{
change->_next = _head;
change->_prev = 0;
if (_tail == 0) {
_tail = change;
} else {
_head->_prev = change;
}
_head = change;
_count++;
}
void CoEdTextChangeList::
append( CoEdTextChange *change )
{
change->_next = 0;
change->_prev = _tail;
if (_head == 0) {
_head = change;
} else {
_tail->_next = change;
}
_tail = change;
_count++;
}
void CoEdTextChangeList::
insertBefore( CoEdTextChange *change1, CoEdTextChange *change2 )
{
if (_head == change2) {
push( change1 );
return;
}
change1->_next = change2;
change1->_prev = change2->_prev;
change2->_prev->_next = change1;
change2->_prev = change1;
_count++;
}
void CoEdTextChangeList::
insertAfter( CoEdTextChange *change2, CoEdTextChange *change1 )
{
if (_tail == change1) {
append( change2 );
return;
}
change2->_next = change1->_next;
change2->_prev = change1;
change1->_next->_prev = change2;
change1->_next = change2;
_count++;
}
CoEdTextChange *CoEdTextChangeList::
remove( CoEdTextChange *change )
{
if (change == _head) {
_head = change->_next;
} else {
change->_prev->_next = change->_next;
}
if (change == _tail) {
_tail = change->_prev;
} else {
change->_next->_prev = change->_prev;
}
change->_next = 0;
change->_prev = 0;
_count--;
return change;
}
void CoEdTextChangeList::
print( FILE *f, char *indent )
{
CoEdTextChange *curr = _head;
while (curr != 0) {
fprintf( f, indent );
curr->print( f );
curr = curr->_next;
}
}

View File

@@ -0,0 +1,115 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: CoEdTextChange.h /main/3 1995/10/23 09:43:46 rswiston $ */
/* -*-C++-*-
*
* CoEdTextChange.h
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#ifndef CoEdTextChange_h
#define CoEdTextChange_h
#define InLibCoEd
#include "CoEd.h"
#include "CoEdTextVersion.h"
class CoEdTextChange {
friend class CoEdTextChangeList;
friend class CoEdChangeHistory;
friend class CoEdChangeQueue;
public:
CoEdTextChange();
CoEdTextChange( long start, long end, const char *text,
const CoEdTextVersion *appliesTo,
const CoEdSiteID *causer, int changeNum );
CoEdTextChange( const CoEdTextChange &change );
CoEdTextChange( Tt_message msg, CoEdStatus &status );
~CoEdTextChange();
CoEdStatus broadcast( const char *path ) const;
int knowsOfNewerChangesThan(
const CoEdTextVersion &version ) const
{ return _appliesTo->knowsOfNewerChangesThan(
version ); }
int knowsOfNewerChangesThan(
const CoEdTextChange &change ) const
{ return _appliesTo->knowsOfNewerChangesThan(
*change._appliesTo ); }
int knowsOf( const CoEdTextChange &change ) const
{ return _appliesTo->knowsOf( *change._causer,
change._changeNum ); }
void interTranslate( CoEdTextChange &chng2Xlate );
void translateOver( const CoEdTextChange &chng2Hurdle );
long adjustPt( long pt, const CoEdSiteID &ptOwner,
int directionToLean ) const;
void print( FILE *f );
long charsAddedBy() const { return _charsAdded; }
long start() const { return _start; }
long end() const { return _end; }
const char *text() const { return _text; }
const CoEdSiteID &causer() const { return *_causer; }
int changeNum() const { return _changeNum; }
private:
long _start;
long _end;
const char *_text;
CoEdTextVersion *_appliesTo;
CoEdSiteID *_causer;
int _changeNum;
long _charsAdded;
CoEdTextChange *_next;
CoEdTextChange *_prev;
};
class CoEdTextChangeList {
friend class CoEdChangeHistory;
friend class CoEdChangeQueue;
public:
CoEdTextChangeList();
~CoEdTextChangeList();
void push( CoEdTextChange *change );
void append( CoEdTextChange *change );
void insertBefore( CoEdTextChange *change1,
CoEdTextChange *change2 );
void insertAfter( CoEdTextChange *change2,
CoEdTextChange *change1 );
CoEdTextChange *remove( CoEdTextChange *change );
void print( FILE *f, char *indent = "" );
private:
CoEdTextChange *_head;
CoEdTextChange *_tail;
int _count;
};
#endif CoEdTextChange_h

View File

@@ -0,0 +1,148 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: CoEdTextVersion.C /main/3 1995/10/23 09:43:59 rswiston $
/*
* CoEdTextVersion.cc
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#include "CoEdTextVersion.h"
CoEdTextVersion::
CoEdTextVersion() : SiteChangeList()
{
}
CoEdTextVersion::
CoEdTextVersion( unsigned char *data, int len, CoEdStatus &status )
: SiteChangeList( data, len, status )
{
}
void CoEdTextVersion::
update( const CoEdSiteID &site, int numChanges )
{
SiteChange *curr = _head;
int found = 0;
while (curr != 0) {
if ( *(CoEdSiteID *)curr == site ) {
curr->_changeNum = numChanges;
found = 1;
}
curr = (SiteChange *)curr->_next;
}
if (! found) {
curr = new SiteChange( site, numChanges );
insert( curr );
}
}
CoEdTextVersion *CoEdTextVersion::
copy() const
{
CoEdTextVersion *newVersion = new CoEdTextVersion;
newVersion->SiteChangeList::copy( (const SiteChangeList *)this );
return newVersion;
}
//
// This method assumes that the CoEdSiteID of <change> is _not_ already
// in the list of SiteChanges!
//
void CoEdTextVersion::
insert( SiteChange *change )
{
SiteChange *curr = _head;
int inserted = 0;
while ((curr != 0) && (! inserted)) {
if (*change < *curr) {
insertBefore( change, curr );
inserted = 1;
}
curr = (SiteChange *)curr->_next;
}
if (! inserted) {
append( change );
}
}
int CoEdTextVersion::
knowsOfNewerChangesThan( const CoEdTextVersion &version ) const
{
SiteChange *curr1 = _head;
SiteChange *curr2 = version._head;
while ((curr1 != 0) && (curr2 != 0)) {
int wait = 0;
int diff = curr1->cmp( *curr2 );
switch (diff) {
case -2:
// I know of a change from a site that he
// has not even heard from.
case 1:
// I know of a change from this site that
// is later than the one he knows.
return 1;
case -1:
// He knows of a change from this site that
// is later than the one I know. Big deal.
break;
case 2:
// He knows of a change from a site that I
// have not even heard from. So wait until
// my next site comes up in his list.
wait = 1;
break;
case 0:
break;
}
if (! wait) {
curr1 = (SiteChange *)curr1->_next;
}
curr2 = (SiteChange *)curr2->_next;
}
if ((curr1 != 0) && (curr2 == 0)) {
//
// I still have a change from a site that he has
// never even heard from.
//
return 1;
}
return 0;
}
int CoEdTextVersion::
knowsOf( const CoEdSiteID &site, int numChanges ) const
{
SiteChange *curr = _head;
while (curr != 0) {
if ( *(CoEdSiteID *)curr == site ) {
return (curr->_changeNum >= numChanges);
}
curr = (SiteChange *)curr->_next;
}
return 0;
}

View File

@@ -0,0 +1,54 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: CoEdTextVersion.h /main/3 1995/10/23 09:44:08 rswiston $ */
/* -*-C++-*-
*
* CoEdTextVersion.h
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#ifndef CoEdTextVersion_h
#define CoEdTextVersion_h
#include "SiteChange.h"
class CoEdTextVersion : public SiteChangeList {
public:
CoEdTextVersion();
CoEdTextVersion( unsigned char *data, int len, CoEdStatus &status );
void update( const CoEdSiteID &site,
int numChanges );
void insert( SiteChange *change );
CoEdTextVersion *copy() const;
int knowsOfNewerChangesThan(
const CoEdTextVersion &version) const;
int knowsOf( const CoEdSiteID &site,
int numChanges ) const;
};
#endif CoEdTextVersion_h

View File

@@ -0,0 +1,39 @@
# %% (c) Copyright 1993, 1994 Hewlett-Packard Company
# %% (c) Copyright 1993, 1994 International Business Machines Corp.
# %% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
# %% (c) Copyright 1993, 1994 Novell, Inc.
# %% $XConsortium: IMakeFile /main/3 1995/10/23 09:44:17 rswiston $
#ifdef HideFromImake
#
# IMakeFile 1.2 17 Nov 1994
#
# This preamble turns this imakefile into a shell script which will
# create/update this directory's makefile when invoked as follows:
# % sh IMakeFile [[GNU]MakeFile]
#
IMAKEDIR=../../../imake; export IMAKEDIR
exec make -f $IMAKEDIR/Boot.mk ${1+"$@"}
#endif HideFromImake
TT_DIR = ../../..
include $(TT_DIR)/Make.macros
CoEd_SOURCES.C = \
CoEd.C \
CoEdFile.C \
CoEdSiteID.C \
CoEdTextChange.C \
CoEdTextVersion.C \
CoEdChangeHistory.C \
CoEdChangeQueue.C \
SiteChange.C
all: StaticOptimizedLib(CoEd)
LibraryStaticOptimized(CoEd)
SourceHygiene(CoEd)
AppendVal(CPPFLAGS,-I$(OPENWINHOME)/include)
All:: $(MAKEFILE)s

View File

@@ -0,0 +1,282 @@
# %% (c) Copyright 1993, 1994 Hewlett-Packard Company
# %% (c) Copyright 1993, 1994 International Business Machines Corp.
# %% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
# %% (c) Copyright 1993, 1994 Novell, Inc.
# %% $XConsortium: Makefile.shipped /main/3 1995/10/23 09:44:25 rswiston $
# Makefile generated by imake - do not edit!
# $XConsortium: Makefile.shipped /main/3 1995/10/23 09:44:25 rswiston $
#
# The cpp used on this machine replaces all newlines and multiple tabs and
# spaces in a macro expansion with a single space. Imake tries to compensate
# for this, but is not always successful.
#
ARCH = $(TARGET_ARCH:-%=%)
OS_VERSION:sh = uname -r | sed 's/\..*//'
OS5x_5 = OS5x
OS5x = $(OS5x_$(OS_VERSION))
OBJ_FORMAT_4 = sun
OBJ_FORMAT_5 = elf
OBJ_FORMAT = $(OBJ_FORMAT_$(OS_VERSION))
PICCOMPILE.cc = $(CCC) $(CCFLAGS) -pic $(CPPFLAGS) $($(OS5x)TARGET_ARCH) -c
LINKSO_5 = ld -G -z text -h $(LD_LIB_NAME) $(LDFLAGS)
LINKSO_4 = ld -assert pure-text $(LDFLAGS)
LINKSO = $(LINKSO_$(OS_VERSION))
RANLIB_5 = true
RANLIB_4 = ranlib
RANLIB = $(RANLIB_$(OS_VERSION))
INDENT = indent -st -bap
CCC += $(CCC_OPTIONS)
SABER_CPPFLAGS = -I/usr/dist/local/sun4/lang/SC1.0/include/CC
CoEd_SOURCES.cc = \
CoEd.cc \
CoEdFile.cc \
CoEdSiteID.cc \
CoEdTextChange.cc \
CoEdTextVersion.cc \
CoEdChangeHistory.cc \
CoEdChangeQueue.cc \
SiteChange.cc
CoEd_HEADERS = \
CoEd.h \
CoEdChangeHistory.h \
CoEdChangeQueue.h \
CoEdFile.h \
CoEdGlobals.h \
CoEdSiteID.h \
CoEdTextChange.h \
CoEdTextVersion.h \
SiteChange.h
CoEd_CPPFLAGS = -I$(OPENWINHOME)/include
CoEd_MAJOR_VERSION = 1
CoEd_MINOR_VERSION = 1
CoEdX_5 = .$(CoEd_MAJOR_VERSION)
CoEdX_4 = .$(CoEd_MAJOR_VERSION).$(CoEd_MINOR_VERSION)
CoEdX = $(CoEdX_$(OS_VERSION))
debug:: g.so
optimized:: O
CoEd_SOURCES.cc~ = $(CoEd_SOURCES.cc:%.cc=%.cc~)
CoEd_HEADERS~ = $(CoEd_HEADERS:%.h=%.h~)
CoEd_c_SOURCES.cc = $(CoEd_SOURCES.cc:%.cc=c/%.c)
CoEd_i_SOURCES.cc = $(CoEd_SOURCES.cc:%.cc=i/%.cc)
CoEd_OBJECTS_O = $(CoEd_SOURCES.cc:%.cc=$(OBJ_FORMAT)_O/%.o)
CoEd_OBJECTS_g = $(CoEd_SOURCES.cc:%.cc=$(OBJ_FORMAT)_g/%.o)
CoEd_PIC_OBJECTS_O = \
$(CoEd_SOURCES.cc:%.cc=$(OBJ_FORMAT)_pic_O/%.o)
CoEd_PIC_OBJECTS_g = \
$(CoEd_SOURCES.cc:%.cc=$(OBJ_FORMAT)_pic_g/%.o)
CoEd_i_PIC_OBJECTS_g = \
$(CoEd_SOURCES.cc:%.cc=i_$(OBJ_FORMAT)_pic_g/%.o)
CoEd_SOURCES.i = $(CoEd_SOURCES.cc:%.cc=%.i) \
$(CoEd_i_SOURCES.cc)
$(CoEd_OBJECTS_O) $(CoEd_OBJECTS_g) \
$(CoEd_PIC_OBJECTS_O) $(CoEd_PIC_OBJECTS_g) \
$(CoEd_i_PIC_OBJECTS_g) \
$(CoEd_SOURCES.cc:%.cc=%.i) $(CoEd_SOURCES.cc:%.cc=%.c) \
$(CoEd_SOURCES.cc:%.cc=%.s) $(CoEd_SOURCES.cc:%.cc=%.files) \
$(CoEd_c_SOURCES.cc) libCoEd_saber++ \
libCoEd_i_saber++ $(CoEd_SOURCES.cc:%.cc=%.saber++) \
:= CPPFLAGS += $(CoEd_CPPFLAGS)
$(CoEd_SOURCES.cc:%.cc=%.saber++) \
:= CPPFLAGS += $(SABER_CPPFLAGS)
$(CoEd_OBJECTS_O) $(CoEd_PIC_OBJECTS_O) := CCFLAGS += -O
$(CoEd_OBJECTS_g) $(CoEd_PIC_OBJECTS_g) \
$(CoEd_i_PIC_OBJECTS_g) \
:= CCFLAGS += -g
$(OBJ_FORMAT)_pic_O/libCoEd.so$(CoEdX) \
$(OBJ_FORMAT)_pic_g/libCoEd.so$(CoEdX) \
i_$(OBJ_FORMAT)_pic_g/libCoEd.so$(CoEdX) := \
LD_LIB_NAME = libCoEd.so$(CoEdX)
$(OBJ_FORMAT)_pic_O/libCoEd.so$(CoEdX): \
$(CoEd_PIC_OBJECTS_O)
$(LINKSO) -o $@ $(CoEd_PIC_OBJECTS_O)
$(OBJ_FORMAT)_pic_g/libCoEd.so$(CoEdX): \
$(CoEd_PIC_OBJECTS_g)
$(LINKSO) -o $@ $(CoEd_PIC_OBJECTS_g)
i_$(OBJ_FORMAT)_pic_g/libCoEd.so$(CoEdX): \
$(CoEd_i_PIC_OBJECTS_g)
$(LINKSO) -o $@ $(CoEd_i_PIC_OBJECTS_g)
$(OBJ_FORMAT)_O/libCoEd.a: $(CoEd_OBJECTS_O)
$(RM) $@; $(AR) $(ARFLAGS) $@ $(CoEd_OBJECTS_O); \
$(RANLIB) $@
$(OBJ_FORMAT)_g/libCoEd.a: $(CoEd_OBJECTS_g)
$(RM) $@; $(AR) $(ARFLAGS) $@ $(CoEd_OBJECTS_g); \
$(RANLIB) $@
libCoEd.tar: Makefile $(CoEd_SOURCES.cc) $(CoEd_HEADERS)
tar cf $@ Makefile $(CoEd_SOURCES.cc) $(CoEd_HEADERS)
libCoEd_saber++: $(CoEd_SOURCES.cc)
#load $(SABER_CPPFLAGS) $(CPPFLAGS) $(CoEd_SOURCES.cc)
libCoEd_i_saber++: $(CoEd_i_SOURCES.cc)
#load $(SABER_CPPFLAGS) $(CPPFLAGS) $(CoEd_i_SOURCES.cc)
libCoEd_saber: $(CoEd_c_SOURCES.cc)
#load $(CPPFLAGS) $(CoEd_c_SOURCES.cc)
all:: $(OBJ_FORMAT)_pic_O/libCoEd.so$(CoEdX) \
$(OBJ_FORMAT)_pic_g/libCoEd.so$(CoEdX) \
$(OBJ_FORMAT)_O/libCoEd.a \
$(OBJ_FORMAT)_g/libCoEd.a
All:: i_$(OBJ_FORMAT)_pic_g/libCoEd.so$(CoEdX)
g.so:: $(OBJ_FORMAT)_pic_g/libCoEd.so$(CoEdX)
O.a:: $(OBJ_FORMAT)_O/libCoEd.a
g.a:: $(OBJ_FORMAT)_g/libCoEd.a
ig:: i_$(OBJ_FORMAT)_pic_g/libCoEd.so$(CoEdX)
O:: $(OBJ_FORMAT)_pic_O/libCoEd.so$(CoEdX)
clean~::
$(RM) $(CoEd_SOURCES.cc~) $(CoEd_HEADERS~)
clean::
$(RM) $(OBJ_FORMAT)_pic_O/libCoEd.so$(CoEdX) \
$(OBJ_FORMAT)_pic_g/libCoEd.so$(CoEdX) \
$(OBJ_FORMAT)_O/libCoEd.a \
$(OBJ_FORMAT)_g/libCoEd.a \
i_$(OBJ_FORMAT)_pic_g/libCoEd.so$(CoEdX) \
libCoEd.tar
clean.o.O::
$(RM) $(CoEd_OBJECTS_O) $(CoEd_PIC_OBJECTS_O)
clean.o.g::
$(RM) $(CoEd_OBJECTS_g) $(CoEd_PIC_OBJECTS_g)
clean.o.pic::
$(RM) $(CoEd_PIC_OBJECTS_O) $(CoEd_PIC_OBJECTS_g)
clean.o.a::
$(RM) $(CoEd_OBJECTS_O) $(CoEd_OBJECTS_g)
clean.i::
$(RM) $(CoEd_SOURCES.i) \
$(CoEd_SOURCES.cc:%.cc=%.c) \
$(CoEd_SOURCES.cc:%.cc=%.c++) \
$(CoEd_SOURCES.cc:%.cc=%.s) \
$(CoEd_SOURCES.cc:%.cc=%.s++) \
$(CoEd_SOURCES.cc:%.cc=%.files)
clean.i.o::
$(RM) $(CoEd_i_PIC_OBJECTS_g)
clean.c::
$(RM) $(CoEd_c_SOURCES.cc)
$(OBJ_FORMAT)_O/.dir \
$(OBJ_FORMAT)_g/.dir \
$(OBJ_FORMAT)_pic_O/.dir \
$(OBJ_FORMAT)_pic_g/.dir \
i_$(OBJ_FORMAT)_g/.dir \
i_$(OBJ_FORMAT)_pic_g/.dir \
m_$(OBJ_FORMAT)_O/.dir \
m_$(OBJ_FORMAT)_g/.dir \
c/.dir \
c_$(OBJ_FORMAT)_O/.dir \
c_$(OBJ_FORMAT)_pic_O/.dir:
if [ ! -d $@ ]; then mkdir -p $@; fi
$(OBJ_FORMAT)_O/%.o: %.cc $(OBJ_FORMAT)_O/.dir
$(COMPILE.cc) $(OUTPUT_OPTION) $< -o $@
$(OBJ_FORMAT)_g/%.o: %.cc $(OBJ_FORMAT)_g/.dir
$(COMPILE.cc) $(OUTPUT_OPTION) $< -o $@
$(OBJ_FORMAT)_pic_O/%.o: %.cc $(OBJ_FORMAT)_pic_O/.dir
$(PICCOMPILE.cc) $(OUTPUT_OPTION) $< -o $@
$(OBJ_FORMAT)_pic_g/%.o: %.cc $(OBJ_FORMAT)_pic_g/.dir
$(PICCOMPILE.cc) $(OUTPUT_OPTION) $< -o $@
m_$(OBJ_FORMAT)_O/%.o: %.cc m_$(OBJ_FORMAT)_O/.dir
$(COMPILE.cc) $(OUTPUT_OPTION) $< -o $@
m_$(OBJ_FORMAT)_g/%.o: %.cc m_$(OBJ_FORMAT)_g/.dir
$(COMPILE.cc) $(OUTPUT_OPTION) $< -o $@
i/%.cc: i %.cc
$(CCC) -E -Qoption acpp -P $(CPPFLAGS) $*.cc | \
sed -e '/^[ ]*\/\//D' | \
$(INDENT) | sed -e 's/: :/::/' -e '/^#/d' > $@
i_$(OBJ_FORMAT)_g/%.o: i/%.cc i_$(OBJ_FORMAT)_g
$(COMPILE.cc) $(OUTPUT_OPTION) $< -o $@
i_$(OBJ_FORMAT)_pic_g/%.o: i/%.cc i_$(OBJ_FORMAT)_pic_g
$(PICCOMPILE.cc) $(OUTPUT_OPTION) $< -o $@
c/%.c: c %.cc
$(CCC) -F $(CPPFLAGS) $*.cc | $(INDENT) | sed '/^#/d' > $@
.SUFFIXES:
.SUFFIXES: .files .c++ .c .i .s++ .s .saber++ $(SUFFIXES)
.cc.files:
$(CCC) -E -H $(CPPFLAGS) $< 1> /dev/null 2> $*.files
.cc.i:
$(CCC) -E $(CPPFLAGS) $< > $*.i
.cc.c:
$(CCC) -F $(CPPFLAGS) $< | \
sed -e '/^#/d' -e '/^\/\* the end \*\/$$/d' | \
$(INDENT) > $*.c
.c.c++:
c++filt < $*.c > $*.c++
.cc.s:
$(CCC) $(CFLAGS) $(CPPFLAGS) -Qproduce .s $(OUTPUT_OPTION) $<
.s.s++:
c++filt < $< > $*.s++
.cc.saber++:
#load $(CPPFLAGS) $<
All:: all
g:: g.so g.a
clean.o:: clean.o.O clean.o.g clean.o.pic clean.o.a clean.i.o clean_m.o
if test -d $(OBJ_FORMAT)_O; then $(RM) -rf $(OBJ_FORMAT)_O; fi
if test -d $(OBJ_FORMAT)_g; then $(RM) -rf $(OBJ_FORMAT)_g; fi
if test -d $(OBJ_FORMAT)_pic_O; then $(RM) -rf $(OBJ_FORMAT)_pic_O; fi
if test -d $(OBJ_FORMAT)_pic_g; then $(RM) -rf $(OBJ_FORMAT)_pic_g; fi
clean.i.o::
if test -d i_$(OBJ_FORMAT)_g; then $(RM) -rf i_$(OBJ_FORMAT)_g; fi
if test -d i_$(OBJ_FORMAT)_pic_g; then $(RM) -rf i_$(OBJ_FORMAT)_pic_g; fi
clean.i:: clean.i.o
if test -d i; then $(RM) -rf i; fi
clean_m:: clean_m.o
$(RM) mallomar.out
clean_m.o::
if test -d m_$(OBJ_FORMAT)_O; then $(RM) -rf m_$(OBJ_FORMAT)_O; fi
if test -d m_$(OBJ_FORMAT)_g; then $(RM) -rf m_$(OBJ_FORMAT)_g; fi
clean:: clean.o clean.i clean_m

View File

@@ -0,0 +1,12 @@
# %% (c) Copyright 1993, 1994 Hewlett-Packard Company
# %% (c) Copyright 1993, 1994 International Business Machines Corp.
# %% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
# %% (c) Copyright 1993, 1994 Novell, Inc.
# %% $XConsortium: Makefile.test /main/3 1995/10/23 09:44:34 rswiston $
# Use this Makefile to build the demos against the system in
# $(TT_DIR)/proto.
CPPFLAGS += -I../../proto/include
LDFLAGS += -L../../proto/lib
include Makefile.shipped

View File

@@ -0,0 +1,378 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: SiteChange.C /main/3 1995/10/23 09:44:43 rswiston $
/*
* SiteChange.cc
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#include <malloc.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <memory.h>
#include "SiteChange.h"
bool_t
coEdPutLong( XDR *xdrStream, long *)
{
xdrStream->x_handy += 4;
return 1;
}
bool_t
coEdPutBytes( XDR *xdrStream, caddr_t, int len )
{
xdrStream->x_handy += RNDUP(len);
return 1;
}
long *
coEdInline( XDR *xdrStream, int len )
{
//
// Be paranoid -- some code really expects inline to
// always succeed, so we keep a small buffer around
// just in case. Not too paranoid, though -- it's
// legal to not support inline!
//
if ((len > 0) && (len < (int)xdrStream->x_base)) {
xdrStream->x_handy += RNDUP(len);
return (long *)xdrStream->x_private;
} else {
return 0;
}
}
unsigned long
coEdXdrSizeOf( xdrproc_t f, void *data )
{
static long sizeBuf[ 5 ];
#ifdef __SABER__
static struct xdr_ops sizeOps;
sizeOps.x_putlong = (int (*)(...))coEdPutLong;
sizeOps.x_putbytes = (int (*)(...))coEdPutBytes;
sizeOps.x_inline = (long *(*)(...))coEdInline;
static XDR xdrSizeStream;
xdrSizeStream.x_op = XDR_ENCODE;
xdrSizeStream.x_ops = &sizeOps;
xdrSizeStream.x_public = 0;
xdrSizeStream.x_private = (caddr_t)sizeBuf;
xdrSizeStream.x_base = (caddr_t)sizeof sizeBuf;
xdrSizeStream.x_handy = 0;
#elif defined(sun) && defined(_rpc_xdr_h)
// the old Sun C++ rpc/xdr.h include had bogus declarations of
// the xdr functions. Fortunately we can detect its existence
// because its file guard was lowercase!
static struct XDR::xdr_ops sizeOps = { 0, (int (*)(...))coEdPutLong, 0,
(int (*)(...))coEdPutBytes, 0, 0,
(long *(*)(...))coEdInline, 0 };
static XDR xdrSizeStream = { XDR_ENCODE, &sizeOps, 0, (caddr_t)sizeBuf,
(caddr_t)sizeof sizeBuf, 0 };
#else
static struct XDR::xdr_ops sizeOps = { 0, coEdPutLong, 0,
coEdPutBytes, 0, 0,
coEdInline, 0 };
static XDR xdrSizeStream = { XDR_ENCODE, &sizeOps, 0, (caddr_t)sizeBuf,
(caddr_t)sizeof sizeBuf, 0 };
#endif
xdrSizeStream.x_handy = 0;
if ((*(bool_t(*)(XDR *, void *))f) (&xdrSizeStream, (void *)data) == 1) {
return (unsigned long)xdrSizeStream.x_handy;
} else {
return 0;
}
}
SiteChange::
SiteChange() : CoEdSiteID()
{
_changeNum = 0;
}
SiteChange::
SiteChange( const char *procID ) : CoEdSiteID( procID )
{
_changeNum = 0;
}
SiteChange::
SiteChange( const CoEdSiteID &id, int numChanges ) : CoEdSiteID( id )
{
_changeNum = numChanges;
}
bool_t SiteChange::
xdr( XDR *xdrStream )
{
if (! CoEdSiteID::xdr( xdrStream )) {
return FALSE;
}
if (! xdr_int( xdrStream, &_changeNum )) {
return FALSE;
}
return TRUE;
}
SiteChange *SiteChange::
copy() const
{
SiteChange *newSiteChange = new SiteChange;
newSiteChange->CoEdSiteID::copy( (CoEdSiteID *)this );
newSiteChange->_changeNum = _changeNum;
return newSiteChange;
}
int SiteChange::
cmp( const SiteChange &change ) const
{
int idCmp = CoEdSiteID::cmp( (const CoEdSiteID &)change );
if (idCmp != 0) {
return 2*idCmp;
}
if (_changeNum == change._changeNum) {
return 0;
} else if (_changeNum < change._changeNum) {
return -1;
} else {
return 1;
}
}
void SiteChange::
print( FILE *f ) const
{
fprintf( f, "(%2d, ", _changeNum );
CoEdSiteID::print( f );
fputs( ")", f );
}
SiteChangeList::
SiteChangeList()
{
_head = 0;
_tail = 0;
_count = 0;
}
SiteChangeList::
SiteChangeList( unsigned char *data, int len, CoEdStatus &status )
{
_head = 0;
_tail = 0;
_count = 0;
status = deSerialize( data, (unsigned long)len );
}
SiteChangeList::
~SiteChangeList()
{
_flush();
}
void SiteChangeList::
push( SiteChange *change )
{
change->_next = _head;
change->_prev = 0;
if (_tail == 0) {
_tail = change;
} else {
_head->_prev = change;
}
_head = change;
_count++;
}
void SiteChangeList::
append( SiteChange *change )
{
change->_next = 0;
change->_prev = _tail;
if (_head == 0) {
_head = change;
} else {
_tail->_next = change;
}
_tail = change;
_count++;
}
void SiteChangeList::
insertBefore( SiteChange *change1, SiteChange *change2 )
{
if (_head == change2) {
push( change1 );
return;
}
change1->_next = change2;
change1->_prev = change2->_prev;
change2->_prev->_next = change1;
change2->_prev = change1;
_count++;
}
void SiteChangeList::
insertAfter( SiteChange *change2, SiteChange *change1 )
{
if (_tail == change1) {
append( change2 );
return;
}
change2->_next = change1->_next;
change2->_prev = change1;
change1->_next->_prev = change2;
change1->_next = change2;
_count++;
}
bool_t
xdrSiteChangeList( XDR *xdrStream, caddr_t *data )
{
return ((SiteChangeList *)(data))->xdr( xdrStream );
}
CoEdStatus SiteChangeList::
serialize( unsigned char **pData, unsigned long *pLen ) const
{
XDR xdrStream;
*pLen = coEdXdrSizeOf( (xdrproc_t)xdrSiteChangeList, (void *)this );
if (*pLen == 0) {
return CoEdErrXDR;
}
*pData = (unsigned char *)malloc( (unsigned int)*pLen );
xdrmem_create( &xdrStream, (caddr_t)*pData, (unsigned int)*pLen,
XDR_ENCODE );
if (! xdrSiteChangeList( &xdrStream, (caddr_t *)this )) {
return CoEdErrXDR;
}
return CoEdOK;
}
CoEdStatus SiteChangeList::
deSerialize( unsigned char *data, unsigned long len )
{
XDR xdrStream;
_flush();
if ((data == 0) || (len == 0)) {
return CoEdOK;
}
xdrmem_create( &xdrStream, (caddr_t)data, (unsigned int)len,
XDR_DECODE );
if (! xdrSiteChangeList( &xdrStream, (caddr_t *)this )) {
return CoEdErrXDR;
}
return CoEdOK;
}
bool_t SiteChangeList::
xdr( XDR *xdrStream )
{
if (! xdr_int( xdrStream, &_count )) {
return FALSE;
}
switch (xdrStream->x_op) {
case XDR_ENCODE:
{
SiteChange *curr = _head;
while (curr != 0) {
if (! curr->xdr( xdrStream )) {
return FALSE;
}
curr = (SiteChange *)curr->_next;
}
}
break;
case XDR_DECODE:
{
int howMany = _count;
_count = 0;
for (int i = 0; i < howMany; i++) {
SiteChange *newChange = new SiteChange();
if (! newChange->xdr( xdrStream )) {
return FALSE;
}
append( newChange );
}
}
break;
}
return TRUE;
}
SiteChangeList *SiteChangeList::
copy() const
{
SiteChangeList *newList = new SiteChangeList;
SiteChange *curr = _head;
while (curr != 0) {
newList->append( curr->copy() );
curr = (SiteChange *)curr->_next;
}
return newList;
}
SiteChangeList &SiteChangeList::
copy( const SiteChangeList *list )
{
_flush();
SiteChange *curr = list->_head;
while (curr != 0) {
append( curr->copy() );
curr = (SiteChange *)curr->_next;
}
return *this;
}
void SiteChangeList::
print( FILE *f ) const
{
SiteChange *curr = _head;
fprintf( f, "(" );
while (curr != 0) {
curr->print( f );
if (curr->_next != 0) {
fprintf( f, ", " );
}
curr = (SiteChange *)curr->_next;
}
fprintf( f, ")" );
}
void SiteChangeList::
_flush()
{
SiteChange *curr = _head;
SiteChange *prev;
while (curr != 0) {
prev = curr;
curr = (SiteChange *)curr->_next;
delete prev;
}
}

View File

@@ -0,0 +1,100 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: SiteChange.h /main/3 1995/10/23 09:44:55 rswiston $ */
/* -*-C++-*-
*
* SiteChange.h - A SiteChange is a record that associates a SiteID
* with an integer indicating how many changes from that site
* have been seen so far.
*
* Copyright (c) 1991 by Sun Microsystems. All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of Sun
* Microsystems and its subsidiaries not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. Sun Microsystems and its
* subsidiaries make no representations about the suitability of this
* software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Sun Microsystems and its subsidiaries disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness. In no event shall Sun Microsystems or
* its subsidiaries be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss
* of use, data or profits, whether in an action of contract,
* negligence or other tortious action, arising out of or in
* connection with the use or performance of this software.
*/
#ifndef SiteChange_h
#define SiteChange_h
#include <rpc/types.h>
#include <rpc/xdr.h>
#define InLibCoEd
#include "CoEd.h"
#include "CoEdSiteID.h"
class SiteChange : public CoEdSiteID {
friend class SiteChangeList;
friend class CoEdTextVersion;
public:
SiteChange();
SiteChange( const char *procID );
SiteChange( const CoEdSiteID &id, int numChanges );
bool_t xdr( XDR *xdrStream );
SiteChange *copy() const;
int cmp( const SiteChange &change ) const;
int operator==( const SiteChange &change ) const
{ return (cmp( change ) == 0); }
int operator<( const SiteChange &change ) const
{ return (cmp( change ) < 0); }
void print( FILE *f ) const;
private:
int _changeNum;
};
class SiteChangeList {
friend class CoEdTextVersion;
public:
SiteChangeList();
SiteChangeList( unsigned char *data, int len, CoEdStatus &status );
~SiteChangeList();
void push( SiteChange *change );
void append( SiteChange *change );
void insertBefore( SiteChange *change1,
SiteChange *change2 );
void insertAfter( SiteChange *change2,
SiteChange *change1 );
CoEdStatus serialize( unsigned char **pData,
unsigned long *pLen ) const;
CoEdStatus deSerialize( unsigned char *data,
unsigned long len );
bool_t xdr( XDR *xdrStream );
SiteChangeList *copy() const;
SiteChangeList &copy( const SiteChangeList *list );
void print( FILE *f ) const;
private:
SiteChange *_head;
SiteChange *_tail;
int _count;
void _flush();
};
#endif SiteChange_h

View File

@@ -0,0 +1,63 @@
# %% (c) Copyright 1993, 1994 Hewlett-Packard Company
# %% (c) Copyright 1993, 1994 International Business Machines Corp.
# %% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
# %% (c) Copyright 1993, 1994 Novell, Inc.
# %% $XConsortium: SunMakefile /main/3 1995/10/23 09:45:17 rswiston $
# @(#)SunMakefile 1.8 93/08/23
# The ToolTalk demo makefile
#
# Copyright (c) 1992 by Sun Microsystems, Inc.
#
TT_DIR = ../../..
THIS_DIR = libCoEd
include $(TT_DIR)/SunMakefile-head.mk
DEMO_SOURCES = \
CoEd.C \
CoEdFile.C \
CoEdSiteID.C \
CoEdTextChange.C \
CoEdTextVersion.C \
CoEdChangeHistory.C \
CoEdChangeQueue.C \
SiteChange.C \
CoEd.h \
CoEdChangeHistory.h \
CoEdChangeQueue.h \
CoEdFile.h \
CoEdGlobals.h \
CoEdSiteID.h \
CoEdTextChange.h \
CoEdTextVersion.h \
SiteChange.h
# The default target, all, doesn't make anything. install copies
# the source to the install directory, renaming Makefile.shipped
# to Makefile.
# To actually make the demos using the ToolTalk in OPENWINHOME,
# run "make -f Makefile.shipped"
# To make the demos using the ToolTalk in $(TT_DIR)/proto, run
# "make -f Makefile.test".
all::
DEMO_DIR = share/src/tooltalk/demo/CoEd/libCoEd
INSTALL_DEMOS = $(DEMO_SOURCES:%=$(INSTALL_DIR)/$(DEMO_DIR)/%)
INSTALL_MAKEFILE = $(INSTALL_DIR)/$(DEMO_DIR)/Makefile
$(INSTALL_TARGETS):: $$(INSTALL_DEMOS) $$(INSTALL_MAKEFILE)
$(INSTALL_DEMOS): $$(@F)
$(TTINSTALL) $(INSTALL_DIR)/$(DEMO_DIR) $(@F)
$(INSTALL_MAKEFILE): Makefile.shipped
$(TTINSTALL) $(@D) Makefile.shipped;\
rm -f $@;\
mv $(@D)/Makefile.shipped $@
include $(TT_DIR)/SunMakefile-tail.mk