Initial import of the CDE 2.1.30 sources from the Open Group.
This commit is contained in:
37
cde/lib/tt/demo/CoEd/CoEd.types
Normal file
37
cde/lib/tt/demo/CoEd/CoEd.types
Normal file
@@ -0,0 +1,37 @@
|
||||
ptype Sun_CoEd {
|
||||
start "CoEd";
|
||||
handle:
|
||||
/*
|
||||
* Display ISO_Latin_1
|
||||
*/
|
||||
session Display( in ISO_Latin_1 contents ) => start opnum = 1;
|
||||
session Display( in ISO_Latin_1 contents,
|
||||
in messageID counterfoil ) => start opnum = 2;
|
||||
session Display( in ISO_Latin_1 contents,
|
||||
in title docName ) => start opnum = 3;
|
||||
session Display( in ISO_Latin_1 contents,
|
||||
in messageID counterfoil,
|
||||
in title docName ) => start opnum = 4;
|
||||
/*
|
||||
* Edit ISO_Latin_1
|
||||
*/
|
||||
session Edit( inout ISO_Latin_1 contents ) => start opnum = 101;
|
||||
session Edit( inout ISO_Latin_1 contents,
|
||||
in messageID counterfoil ) => start opnum = 102;
|
||||
session Edit( inout ISO_Latin_1 contents,
|
||||
in title docName ) => start opnum = 103;
|
||||
session Edit( inout ISO_Latin_1 contents,
|
||||
in messageID counterfoil,
|
||||
in title docName ) => start opnum = 104;
|
||||
/*
|
||||
* Compose ISO_Latin_1
|
||||
*/
|
||||
session Edit( out ISO_Latin_1 contents ) => start opnum = 201;
|
||||
session Edit( out ISO_Latin_1 contents,
|
||||
in messageID counterfoil ) => start opnum = 202;
|
||||
session Edit( out ISO_Latin_1 contents,
|
||||
in title docName ) => start opnum = 203;
|
||||
session Edit( out ISO_Latin_1 contents,
|
||||
in messageID counterfoil,
|
||||
in title docName ) => start opnum = 204;
|
||||
};
|
||||
156
cde/lib/tt/demo/CoEd/CoEd/CoEd.C
Normal file
156
cde/lib/tt/demo/CoEd/CoEd/CoEd.C
Normal file
@@ -0,0 +1,156 @@
|
||||
//%% (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:04:04 rswiston $
|
||||
/*
|
||||
* CoEd.cc
|
||||
*
|
||||
* Copyright (c) 1991,1993 by Sun Microsystems.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <Tt/tttk.h>
|
||||
#include <CoEd.h>
|
||||
#include "CoEditor.h"
|
||||
#include "CoEdTextBuffer.h"
|
||||
|
||||
XtAppContext myContext;
|
||||
Widget myTopWidget = 0;
|
||||
Display *myDpy;
|
||||
char *myAltMediaType = "ISO_Latin_1";
|
||||
int abortCode = 0;
|
||||
Tt_pattern *sessPats = 0;
|
||||
int timeOutFactor = 1000;
|
||||
int maxBuffers = 1000;
|
||||
int *pArgc;
|
||||
char **globalArgv;
|
||||
|
||||
const char *ToolName = "CoEd";
|
||||
const char *usage =
|
||||
"Usage: CoEd [-p01] [-w n] [-t n] [-m media_type] [file]\n"
|
||||
" -p print ToolTalk procid\n"
|
||||
" -0 do not open an initial composition window\n"
|
||||
" -1 be a single-buffer editor\n"
|
||||
" -w sleep for n seconds before coming up\n"
|
||||
" -t use n as timeout factor, in milliseconds (default: 1000)\n"
|
||||
" -m set the alternate media type (default: ISO_Latin_1)\n"
|
||||
;
|
||||
|
||||
void
|
||||
main(
|
||||
int argc,
|
||||
char **argv
|
||||
)
|
||||
{
|
||||
static const char *here = "main()";
|
||||
int delay = 0;
|
||||
int printid = 0;
|
||||
int daemon = 0;
|
||||
char *file = 0;
|
||||
|
||||
XtToolkitInitialize();
|
||||
myContext = XtCreateApplicationContext();
|
||||
//
|
||||
// This display may get closed, and another opened, inside
|
||||
// CoEditor::_init(), if e.g. our parent is on a different screen
|
||||
//
|
||||
pArgc = &argc;
|
||||
globalArgv = argv;
|
||||
myDpy = XtOpenDisplay( myContext, 0, 0, "CoEd", 0, 0, &argc, argv );
|
||||
|
||||
int c;
|
||||
while ((c = getopt( argc, argv, "p01w:t:m:" )) != -1) {
|
||||
switch (c) {
|
||||
case 'p':
|
||||
printid = 1;
|
||||
break;
|
||||
case '0':
|
||||
daemon = 1;
|
||||
break;
|
||||
case '1':
|
||||
maxBuffers = 1;
|
||||
break;
|
||||
case 'w':
|
||||
delay = atoi( optarg );
|
||||
break;
|
||||
case 't':
|
||||
timeOutFactor = atoi( optarg );
|
||||
break;
|
||||
case 'm':
|
||||
myAltMediaType = optarg;
|
||||
break;
|
||||
default:
|
||||
fputs( usage, stderr );
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
if (optind < argc) {
|
||||
file = argv[ optind ];
|
||||
}
|
||||
while (delay > 0) {
|
||||
sleep( 1 );
|
||||
delay--;
|
||||
}
|
||||
|
||||
int myTtFd;
|
||||
char *myProcID = ttdt_open( &myTtFd, ToolName, "SunSoft", "%I", 1 );
|
||||
Tt_status status = tt_ptr_error( myProcID );
|
||||
if (status != TT_OK) {
|
||||
fprintf( stderr, "ttdt_open(): %s\n",
|
||||
tt_status_message(status) );
|
||||
myProcID = 0;
|
||||
} else {
|
||||
if (printid) {
|
||||
printf( "%s\n", myProcID );
|
||||
}
|
||||
|
||||
XtAppAddInput( myContext, myTtFd, (XtPointer)XtInputReadMask,
|
||||
tttk_Xt_input_handler, myProcID );
|
||||
|
||||
ttmedia_ptype_declare( "Sun_CoEd", 0, CoEditor::loadISOLatin1_,
|
||||
(void *)&myTopWidget, 1 );
|
||||
|
||||
// Process the message that started us, if any
|
||||
tttk_Xt_input_handler( 0, 0, 0 );
|
||||
if (abortCode != 0) {
|
||||
// Error in message that caused us to start.
|
||||
exit( abortCode );
|
||||
}
|
||||
}
|
||||
|
||||
if (CoEditor::numEditors == 0) {
|
||||
// started by hand, not by ToolTalk
|
||||
if (file == 0) {
|
||||
if (! daemon) {
|
||||
new CoEditor( &myTopWidget );
|
||||
}
|
||||
} else {
|
||||
new CoEditor( &myTopWidget, file );
|
||||
}
|
||||
}
|
||||
//
|
||||
// If sessPats is unset, then we have no joined the desktop
|
||||
// session yet. So join it.
|
||||
//
|
||||
if (sessPats == 0) {
|
||||
Widget session_shell = CoEditor::editors[0]->shell;
|
||||
if (maxBuffers > 1) {
|
||||
//
|
||||
// In multi-window mode, no single window is the
|
||||
// distinguished window.
|
||||
//
|
||||
session_shell = myTopWidget;
|
||||
}
|
||||
sessPats = ttdt_session_join( 0, CoEditor::contractCB_,
|
||||
session_shell, CoEditor::editors[0], 1 );
|
||||
}
|
||||
|
||||
while (daemon || (CoEditor::numEditors > 0)) {
|
||||
XEvent event;
|
||||
XtAppNextEvent( myContext, &event );
|
||||
XtDispatchEvent( &event );
|
||||
}
|
||||
ttdt_close( 0, 0, 1 );
|
||||
}
|
||||
87
cde/lib/tt/demo/CoEd/CoEd/CoEdTextBuffer.C
Normal file
87
cde/lib/tt/demo/CoEd/CoEd/CoEdTextBuffer.C
Normal file
@@ -0,0 +1,87 @@
|
||||
//%% (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: CoEdTextBuffer.C /main/3 1995/10/20 17:04:13 rswiston $
|
||||
/*
|
||||
* CoEdTextBuffer.c
|
||||
*
|
||||
* 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 "CoEdTextBuffer.h"
|
||||
|
||||
CoEdTextBuffer::
|
||||
CoEdTextBuffer( XmTextBlock *textBuffer )
|
||||
{
|
||||
_textBuffer = textBuffer;
|
||||
_insertingText = 0;
|
||||
}
|
||||
|
||||
CoEdStatus CoEdTextBuffer::
|
||||
insertText( long start, long end, const char *text )
|
||||
{
|
||||
#ifdef FIXUP
|
||||
TextLocation _start = LocationOfPosition( _textBuffer,
|
||||
(TextPosition)start );
|
||||
TextLocation _end = LocationOfPosition( _textBuffer,
|
||||
(TextPosition)end );
|
||||
if ( (start == 0) && (end != 0) && (text == 0)
|
||||
&& (end == LastTextBufferPosition( _textBuffer )))
|
||||
{
|
||||
fprintf( stderr, "CoEd: warning: deleting all the text "
|
||||
"in an OLIT TextBuffer may exercise OLIT bug "
|
||||
"#1071428\n" );
|
||||
}
|
||||
_insertingText = 1;
|
||||
EditResult err = ReplaceBlockInTextBuffer( _textBuffer, &_start, &_end,
|
||||
(char *)text,
|
||||
(TextUpdateFunction)0, 0 );
|
||||
_insertingText = 0;
|
||||
if (err == EDIT_SUCCESS) {
|
||||
return CoEdOK;
|
||||
} else {
|
||||
return CoEdErrFailure;
|
||||
}
|
||||
#endif /*FIXUP*/
|
||||
return CoEdOK;
|
||||
}
|
||||
|
||||
CoEdStatus CoEdTextBuffer::
|
||||
save()
|
||||
{
|
||||
return CoEdOK;
|
||||
}
|
||||
|
||||
CoEdStatus CoEdTextBuffer::
|
||||
revert()
|
||||
{
|
||||
return CoEdOK;
|
||||
}
|
||||
|
||||
CoEdStatus CoEdTextBuffer::
|
||||
rename( const char * /* newPath */ )
|
||||
{
|
||||
return CoEdOK;
|
||||
}
|
||||
59
cde/lib/tt/demo/CoEd/CoEd/CoEdTextBuffer.h
Normal file
59
cde/lib/tt/demo/CoEd/CoEd/CoEdTextBuffer.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*%% (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: CoEdTextBuffer.h /main/3 1995/10/20 17:04:22 rswiston $ */
|
||||
/* -*-C++-*-
|
||||
*
|
||||
* CoEd_TextBuffer.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 CoEd_TextBuffer_h
|
||||
#define CoEd_TextBuffer_h
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <X11/StringDefs.h>
|
||||
#include <Xm/Xm.h>
|
||||
#include <Xm/Text.h>
|
||||
#include <CoEd.h>
|
||||
|
||||
class CoEdTextBuffer {
|
||||
public:
|
||||
CoEdTextBuffer( XmTextBlock *textBuffer );
|
||||
|
||||
CoEdStatus insertText( long start, long end,
|
||||
const char *text );
|
||||
CoEdStatus save();
|
||||
CoEdStatus revert();
|
||||
CoEdStatus rename( const char *newPath );
|
||||
int insertingText() const { return _insertingText; }
|
||||
|
||||
private:
|
||||
XmTextBlock *_textBuffer;
|
||||
int _insertingText;
|
||||
};
|
||||
|
||||
#endif CoEd_TextBuffer_h
|
||||
1440
cde/lib/tt/demo/CoEd/CoEd/CoEditor.C
Normal file
1440
cde/lib/tt/demo/CoEd/CoEd/CoEditor.C
Normal file
File diff suppressed because it is too large
Load Diff
225
cde/lib/tt/demo/CoEd/CoEd/CoEditor.h
Normal file
225
cde/lib/tt/demo/CoEd/CoEd/CoEditor.h
Normal file
@@ -0,0 +1,225 @@
|
||||
/*%% (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: CoEditor.h /main/3 1995/10/20 17:04:44 rswiston $ */
|
||||
#ifndef CoEditor_h
|
||||
#define CoEditor_h
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <Xm/Xm.h>
|
||||
#include <Xm/Text.h>
|
||||
#include <Tt/tttk.h>
|
||||
|
||||
class CoEditor {
|
||||
public:
|
||||
CoEditor(
|
||||
Widget *parent
|
||||
);
|
||||
CoEditor(
|
||||
Widget *parent,
|
||||
const char *file
|
||||
);
|
||||
CoEditor(
|
||||
Widget *parent,
|
||||
Tt_message msg,
|
||||
const char *docname,
|
||||
Tt_status &status
|
||||
);
|
||||
CoEditor(
|
||||
Widget *parent,
|
||||
Tt_message msg,
|
||||
int readOnly,
|
||||
const char *file,
|
||||
const char *docname,
|
||||
Tt_status &status
|
||||
);
|
||||
CoEditor(
|
||||
Widget *parent,
|
||||
Tt_message msg,
|
||||
int readOnly,
|
||||
unsigned char *contents,
|
||||
int len,
|
||||
const char *docname,
|
||||
Tt_status &status
|
||||
);
|
||||
~CoEditor();
|
||||
|
||||
static Tt_message loadISOLatin1_(
|
||||
Tt_message msg,
|
||||
void *clientData,
|
||||
Tttk_op op,
|
||||
Tt_status diagnosis,
|
||||
unsigned char *contents,
|
||||
int len,
|
||||
char *file,
|
||||
char *docname
|
||||
);
|
||||
static Tt_message contractCB_(
|
||||
Tt_message msg,
|
||||
void *coEditor,
|
||||
Tt_message contract
|
||||
);
|
||||
Tt_message _contractCB(
|
||||
Tt_message msg,
|
||||
Tt_message contract
|
||||
);
|
||||
static Tt_message subContractCB_(
|
||||
Tt_message msg,
|
||||
void *coEditor,
|
||||
Tt_message subContract
|
||||
);
|
||||
Tt_message _subContractCB(
|
||||
Tt_message msg,
|
||||
Tt_message subContract
|
||||
);
|
||||
|
||||
private:
|
||||
void _init();
|
||||
Tt_status _init(
|
||||
Tt_message msg
|
||||
);
|
||||
void _init(
|
||||
Widget *parent
|
||||
);
|
||||
Tt_status _unload();
|
||||
Tt_status _load(
|
||||
const char *file
|
||||
);
|
||||
Tt_status _load(
|
||||
unsigned char *contents,
|
||||
int len
|
||||
);
|
||||
Tt_status _save();
|
||||
Tt_status _revert();
|
||||
static void _destroyCB_(
|
||||
Widget w,
|
||||
XtPointer coEditor,
|
||||
XtPointer call_data
|
||||
);
|
||||
void _destroyCB(
|
||||
Widget w,
|
||||
XtPointer call_data
|
||||
);
|
||||
int _quit(
|
||||
int silent = 0,
|
||||
int force = 0
|
||||
);
|
||||
static int _quitAll(
|
||||
int silent,
|
||||
int force
|
||||
);
|
||||
static void _wmProtocolCB_(
|
||||
Widget w,
|
||||
XtPointer coEditor,
|
||||
XmAnyCallbackStruct *cbs
|
||||
);
|
||||
void _wmProtocolCB();
|
||||
static void _fileButsCB_(
|
||||
Widget button,
|
||||
XtPointer coEditor,
|
||||
XtPointer call_data
|
||||
);
|
||||
void _fileButsCB(
|
||||
Widget button,
|
||||
XtPointer call_data
|
||||
);
|
||||
static void _editButsCB_(
|
||||
Widget button,
|
||||
XtPointer coEditor,
|
||||
XtPointer call_data
|
||||
);
|
||||
void _editButsCB(
|
||||
Widget button,
|
||||
XtPointer call_data
|
||||
);
|
||||
char *_contents(
|
||||
int *len
|
||||
);
|
||||
char *_selection(
|
||||
int *len
|
||||
);
|
||||
Tt_status _acceptContract(
|
||||
Tt_message msg
|
||||
);
|
||||
static Tt_message _mediaLoadMsgCB_(
|
||||
Tt_message msg,
|
||||
void *clientData,
|
||||
Tttk_op op,
|
||||
unsigned char *contents,
|
||||
int len,
|
||||
char *file
|
||||
);
|
||||
Tt_message _mediaLoadMsgCB(
|
||||
Tt_message msg,
|
||||
Tttk_op op,
|
||||
unsigned char *contents,
|
||||
int len,
|
||||
char *file
|
||||
);
|
||||
static void _textUpdateCB_(
|
||||
Widget coEditor,
|
||||
XtPointer pTextBuffer,
|
||||
XmTextVerifyCallbackStruct *cbs
|
||||
);
|
||||
void _textUpdateCB();
|
||||
static Tt_message _fileCB_(
|
||||
Tt_message msg,
|
||||
Tttk_op op,
|
||||
char *pathname,
|
||||
void *clientData,
|
||||
int trust,
|
||||
int me
|
||||
);
|
||||
Tt_message _fileCB(
|
||||
Tt_message msg,
|
||||
Tttk_op op,
|
||||
char *pathname,
|
||||
int trust,
|
||||
int me
|
||||
);
|
||||
static void _textModifyCB_(
|
||||
Widget text,
|
||||
XtPointer ,
|
||||
XmTextVerifyCallbackStruct *mod
|
||||
);
|
||||
void _textModifyCB(
|
||||
XmTextVerifyCallbackStruct *mod
|
||||
);
|
||||
void _adviseUser(
|
||||
const char *msg,
|
||||
Tt_status status
|
||||
);
|
||||
Tt_status _read_file(
|
||||
Widget widget,
|
||||
char *file
|
||||
);
|
||||
Tt_status _write_file(
|
||||
Widget widget,
|
||||
char *file
|
||||
);
|
||||
public:
|
||||
Widget shell;
|
||||
static CoEditor *editors[];
|
||||
static int numEditors;
|
||||
|
||||
private:
|
||||
Widget _baseFrame;
|
||||
Widget _controls;
|
||||
Widget _fileBut;
|
||||
Widget _editBut;
|
||||
Widget _text;
|
||||
Boolean _modifiedByMe;
|
||||
int _modifiedByOther; // >1 == user has been asked
|
||||
Tt_message _contract;
|
||||
Tt_message _subContract;
|
||||
Tt_pattern *_contractPats;
|
||||
Tt_pattern *_filePats;
|
||||
char *_file; // free w/ free()
|
||||
int _x; // geometry of parent
|
||||
int _y;
|
||||
int _w;
|
||||
int _h;
|
||||
};
|
||||
|
||||
#endif
|
||||
47
cde/lib/tt/demo/CoEd/CoEd/IMakeFile
Normal file
47
cde/lib/tt/demo/CoEd/CoEd/IMakeFile
Normal 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: IMakeFile /main/3 1995/10/20 17:04:55 rswiston $
|
||||
#ifdef HideFromImake
|
||||
#
|
||||
# IMakeFile 1.7 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
|
||||
|
||||
.KEEP_STATE:
|
||||
|
||||
default: all
|
||||
|
||||
All:: $(MAKEFILE)s all
|
||||
all: DynamicDebugProg(CoEd)
|
||||
|
||||
CoEd_SOURCES.C = CoEdTextBuffer.C CoEditor.C CoEd.C
|
||||
|
||||
RUN_PATH = -R /tt/proto/lib:/usr/dt/lib:$(OPENWINHOME)/lib:/opt/SUNWspro/lib
|
||||
|
||||
ProgramDynamicOptimized(CoEd)
|
||||
ProgramDynamicDebug(CoEd)
|
||||
SourceHygiene(CoEd)
|
||||
|
||||
SaberProg(CoEd)
|
||||
|
||||
AppendVal(CPPFLAGS,-I../../../proto/include -I/usr/dt/include -I$(OPENWINHOME)/include -I../libCoEd)
|
||||
|
||||
AppendVal(LDFLAGS,-L../../../proto/lib -L/usr/dt/lib -L$(OPENWINHOME)/lib -L../libCoEd/$(OEUVRE)/pdc/O)
|
||||
|
||||
#AppendVal(LDLIBS,-ltt-g -lXm -lXt -lX11 -Bstatic -lCoEd -Bdynamic)
|
||||
AppendVal(LDLIBS,-ltt -lXm -lXt -lX11 -Bstatic -lCoEd -Bdynamic)
|
||||
loc_LDLIBS_SunOS4 = -lce -lX -lI18N -ldl
|
||||
loc_LDLIBS_SunOS5 = -lnsl -lsocket -lintl -lgen
|
||||
AppendVal(LDLIBS,$(loc_LDLIBS_$(OS)))
|
||||
62
cde/lib/tt/demo/CoEd/CoEd/Makefile.shipped
Normal file
62
cde/lib/tt/demo/CoEd/CoEd/Makefile.shipped
Normal file
@@ -0,0 +1,62 @@
|
||||
# %% (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/20 17:05:10 rswiston $
|
||||
# If OPENWINHOME is set, then use that location to
|
||||
# search for the include files and library files. If
|
||||
# it is not set, then use /usr/openwin.
|
||||
WIN_HOME:sh = \
|
||||
( \
|
||||
case ${OPENWINHOME} \
|
||||
in ?*) echo ${OPENWINHOME};; \
|
||||
*) echo "/usr/openwin";; \
|
||||
esac; \
|
||||
)
|
||||
|
||||
OS_VERSION:sh = (uname -r | sed 's/\..*//')
|
||||
|
||||
OBJ_FORMAT_4 = sun
|
||||
OBJ_FORMAT_5 = elf
|
||||
OBJ_FORMAT = $(OBJ_FORMAT_$(OS_VERSION))
|
||||
|
||||
# Parameters.
|
||||
|
||||
PROGRAM = CoEd
|
||||
SOURCES.cc = CoEdTextBuffer.cc CoEditor.cc CoEd.cc
|
||||
SOURCES.h = CoEdTextBuffer.h
|
||||
|
||||
# Derived parameters.
|
||||
|
||||
SOURCES = \
|
||||
$(SOURCES.h) \
|
||||
$(SOURCES.cc)
|
||||
|
||||
OBJECTS = \
|
||||
$(SOURCES.cc:%.cc=%.o)
|
||||
|
||||
# Compiler flags.
|
||||
|
||||
CC=CC
|
||||
CFLAGS += -g
|
||||
CPPFLAGS += -I$(WIN_HOME)/include -I../libCoEd
|
||||
LDFLAGS += \
|
||||
-L$(WIN_HOME)/lib \
|
||||
-L../libCoEd/$(OBJ_FORMAT)_g
|
||||
LDLIBS_5 = -lXol -lXt -lX11 -Bstatic -lCoEd \
|
||||
-Bdynamic -ltt -lnsl -lsocket -lc -ldl -lintl -lw -Bstatic
|
||||
LDLIBS_4 = -lXol -lXt -lX11 -Bstatic -lCoEd \
|
||||
-Bdynamic -ltt -lce -lI18N -lc -Bstatic
|
||||
LDLIBS += $(LDLIBS_$(OS_VERSION))
|
||||
|
||||
# Standard targets.
|
||||
|
||||
.MAKE_STATE:
|
||||
|
||||
all: $(PROGRAM)
|
||||
|
||||
$(PROGRAM): $(OBJECTS)
|
||||
LD_RUN_PATH=$(WIN_HOME)/lib $(LINK.cc) -o $@ $(OBJECTS) $(LDLIBS)
|
||||
|
||||
%.i: %.c
|
||||
cpp $(CPPFLAGS) $< > $@
|
||||
12
cde/lib/tt/demo/CoEd/CoEd/Makefile.test
Normal file
12
cde/lib/tt/demo/CoEd/CoEd/Makefile.test
Normal 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/20 17:05:19 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
|
||||
58
cde/lib/tt/demo/CoEd/CoEd/SunMakefile
Normal file
58
cde/lib/tt/demo/CoEd/CoEd/SunMakefile
Normal 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: SunMakefile /main/3 1995/10/20 17:05:29 rswiston $
|
||||
# @(#)SunMakefile 1.10 93/08/20
|
||||
#
|
||||
# The ToolTalk demo makefile
|
||||
#
|
||||
# Copyright (c) 1992 by Sun Microsystems, Inc.
|
||||
#
|
||||
|
||||
TT_DIR = ../../..
|
||||
THIS_DIR = CoEd
|
||||
|
||||
include $(TT_DIR)/SunMakefile-head.mk
|
||||
|
||||
DEMO_SOURCES = \
|
||||
CoEditor.h \
|
||||
CoEditor.C \
|
||||
CoEdTextBuffer.C \
|
||||
CoEdTextBuffer.h \
|
||||
CoEd.C
|
||||
|
||||
# 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,
|
||||
# make shipped
|
||||
|
||||
# To make the demos using the ToolTalk in $(TT_DIR)/proto, run
|
||||
# make test
|
||||
|
||||
|
||||
all::
|
||||
|
||||
DEMO_DIR = share/src/tooltalk/demo/CoEd/CoEd
|
||||
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 $@
|
||||
|
||||
shipped test:
|
||||
MAKE="$(MAKE) -f Makefile.$@" $(MAKE) -f Makefile.$@
|
||||
|
||||
shippedclean:
|
||||
MAKE="$(MAKE) -f Makefile.shipped" $(MAKE) -f Makefile.shipped clean
|
||||
|
||||
include $(TT_DIR)/SunMakefile-tail.mk
|
||||
29
cde/lib/tt/demo/CoEd/IMakeFile
Normal file
29
cde/lib/tt/demo/CoEd/IMakeFile
Normal file
@@ -0,0 +1,29 @@
|
||||
# %% (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/20 17:03:28 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 = ../..
|
||||
SUB-DIRS = libCoEd CoEd
|
||||
|
||||
include $(TT_DIR)/Make.macros
|
||||
|
||||
default: all
|
||||
|
||||
All:: $(MAKEFILE)s
|
||||
All all clean cleaner clean.mk::
|
||||
for dir in $(SUB-DIRS) ; do \
|
||||
(cd $$dir; $(MAKE) $(MAKE_FLAGS) $@) \
|
||||
done
|
||||
14
cde/lib/tt/demo/CoEd/Makefile.shipped
Normal file
14
cde/lib/tt/demo/CoEd/Makefile.shipped
Normal file
@@ -0,0 +1,14 @@
|
||||
# %% (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/20 17:03:37 rswiston $
|
||||
all:
|
||||
(cd libCoEd; ${MAKE} g.a)
|
||||
(cd CoEd; ${MAKE})
|
||||
tt_type_comp CoEd.types
|
||||
|
||||
clean:
|
||||
(cd libCoEd; ${MAKE} -i clean)
|
||||
(cd CoEd; ${MAKE} -i clean)
|
||||
$(RM) CoEd.types.deps
|
||||
12
cde/lib/tt/demo/CoEd/Makefile.test
Normal file
12
cde/lib/tt/demo/CoEd/Makefile.test
Normal 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/20 17:03:45 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
|
||||
80
cde/lib/tt/demo/CoEd/README
Normal file
80
cde/lib/tt/demo/CoEd/README
Normal file
@@ -0,0 +1,80 @@
|
||||
/* $XConsortium: README /main/2 1996/07/15 14:07:37 drk $ */
|
||||
This is CoEd, a shared text editor. Building CoEd requires DevGuide,
|
||||
C++, and ToolTalk (which is part of OpenWindows). CoEd is known to
|
||||
build with DevGuide 3.0.1, C++ from SPARCompilers 2.0.1, and either
|
||||
OpenWindows 3.1 or OpenWindows 3.2.
|
||||
|
||||
NOTE: The libgolit in DevGuide 3.0.1 was based on the OW3.0.1/3.1 OLIT
|
||||
libraries, and has some incompatibilites with the OW3.2 OLIT
|
||||
libraries. A CoEd built with with libgolit 3.0.1 and running under
|
||||
OW3.2 will crash, e.g., if you press MENU or HELP over the OLIT
|
||||
textedit widget embedded in CoEd. However, the basic features of
|
||||
editing, selecting, copy/paste, drag-and-drop, and scrolling seem to
|
||||
work.
|
||||
|
||||
Run it with "CoEd <filename>". (Of course, the ToolTalk dbserver must
|
||||
be installed on the machine that owns the file. See the ToolTalk
|
||||
Setup And Administration Guide.)
|
||||
|
||||
Basically, it's an editor that uses ToolTalk so that multiple
|
||||
instances of the editor can edit the same file at the same time,
|
||||
and have all the changes keep in sync. It has some serious limitations:
|
||||
|
||||
- CoEd has no facility for saving the edited file to disk.
|
||||
|
||||
- All the CoEd's must come up before any typing occurs. We haven't
|
||||
implemented the part of the protocol where newcomers can request
|
||||
the current state of the file. CoEd's can quit at any time without
|
||||
messing up the others. Here's a sketch for the rest of
|
||||
the protocol, in case anyone is interested in completely implementing
|
||||
the dOPT algorithm (cf. C.A. Ellis and S.J. Gibbs,
|
||||
"Concurrency Control in Groupware Systems", Proc. 1989 ACM SIGMOD,
|
||||
Int. Conf. on the Mgt. of Data).
|
||||
|
||||
* CoEd protocol
|
||||
* Notices every editor should register for
|
||||
* Text_File_Changed(
|
||||
in CoEdTextVersion appliesTo,
|
||||
in int changeNum,
|
||||
in int start,
|
||||
in int end,
|
||||
in string text )
|
||||
* Text_File_Poll_Version()
|
||||
* Used by the moderator to detect quiescence.
|
||||
* Text_File_Saved()
|
||||
* Text_File_Reverted()
|
||||
* Text_File_Renamed(
|
||||
in string newName )
|
||||
* Requests every editor should register to handle
|
||||
* Text_File_New_Moderator()
|
||||
* Sent by the Moderator when closing the file. Whoever
|
||||
handles it must register for the Moderator requests and
|
||||
act as the new Moderator.
|
||||
* Point-to-point notices the Moderator should be ready for
|
||||
* Text_File_Version_Vote(
|
||||
in CoEdTextVersion myVersion )
|
||||
* When a Text_File_Poll_Version notice is received,
|
||||
this notice is sent directly to the party that called
|
||||
for the version vote.
|
||||
* Requests the moderator should register to handle
|
||||
* Text_File_Join(
|
||||
out CoEdSiteIDList coEditors )
|
||||
* Sent every time an editor opens a file. If the request
|
||||
fails, then no one is editing the file and the requestor
|
||||
should become the Moderator -- i.e., register to handle
|
||||
this request. If the request succeeds, then issue a
|
||||
Text_File_Poll_Version notice, and wait until each
|
||||
coEditor responds with a Text_File_Version_Vote.
|
||||
Then send a Text_File_Update_Me request to catch up on
|
||||
what you've missed.
|
||||
* Text_File_Update_Me(
|
||||
inout CoEdTextVersion version,
|
||||
out string text )
|
||||
* Sent by new coEditors after they've received a
|
||||
Text_File_Version_Vote from each coEditor they learned
|
||||
about when they did their Text_File_Join. In the
|
||||
request, <version> is the earliest version of the text
|
||||
that would not leave the requestor with missing changes
|
||||
from any of the coEditors. In the reply, <version> is
|
||||
identical to or later than the requested version, and
|
||||
corresponds to the <text> in the reply.
|
||||
64
cde/lib/tt/demo/CoEd/SunMakefile
Normal file
64
cde/lib/tt/demo/CoEd/SunMakefile
Normal file
@@ -0,0 +1,64 @@
|
||||
# %% (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/20 17:03:53 rswiston $
|
||||
#
|
||||
#
|
||||
# @(#)SunMakefile 1.16 93/08/20
|
||||
#
|
||||
# The ToolTalk demo makefile
|
||||
#
|
||||
# Copyright (c) 1992,1993 by Sun Microsystems, Inc.
|
||||
#
|
||||
|
||||
TT_DIR = ../..
|
||||
THIS_DIR = CoEd
|
||||
|
||||
DEMO_SOURCES = \
|
||||
CoEd.types \
|
||||
README
|
||||
|
||||
include $(TT_DIR)/SunMakefile-head.mk
|
||||
|
||||
# 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,
|
||||
# make shipped
|
||||
|
||||
# To make the demos using the ToolTalk in $(TT_DIR)/proto, run
|
||||
# make test
|
||||
|
||||
SUBDIRS = CoEd libCoEd
|
||||
DEMO_DIR = share/src/tooltalk/demo/CoEd
|
||||
INSTALL_DEMOS = $(DEMO_SOURCES:%=$(INSTALL_DIR)/$(DEMO_DIR)/%)
|
||||
INSTALL_MAKEFILE = $(INSTALL_DIR)/$(DEMO_DIR)/Makefile
|
||||
|
||||
all::
|
||||
|
||||
$(INSTALL_TARGETS):: $$(INSTALL_DEMOS) $$(INSTALL_MAKEFILE)
|
||||
|
||||
$(INSTALL_MAKEFILE): Makefile.shipped
|
||||
$(TTINSTALL) $(@D) Makefile.shipped;\
|
||||
rm -f $@;\
|
||||
mv $(@D)/Makefile.shipped $@
|
||||
|
||||
$(INSTALL_DEMOS): $$(@F)
|
||||
$(TTINSTALL) $(INSTALL_DIR)/$(DEMO_DIR) $(@F)
|
||||
|
||||
shipped test:
|
||||
MAKE="$(MAKE) -f Makefile.$@" $(MAKE) -f Makefile.$@
|
||||
|
||||
shippedclean:
|
||||
MAKE="$(MAKE) -f Makefile.shipped" $(MAKE) -f Makefile.shipped clean
|
||||
|
||||
clean: FRC
|
||||
cd CoEd; ${MAKE} -i -f Makefile.shipped clean; cd ..; \
|
||||
cd libCoEd; ${MAKE} -i -f Makefile.shipped clean; cd ..
|
||||
|
||||
include $(TT_DIR)/SunMakefile-tail.mk
|
||||
|
||||
FRC:
|
||||
|
||||
264
cde/lib/tt/demo/CoEd/libCoEd/CoEd.C
Normal file
264
cde/lib/tt/demo/CoEd/libCoEd/CoEd.C
Normal 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;
|
||||
}
|
||||
123
cde/lib/tt/demo/CoEd/libCoEd/CoEd.h
Normal file
123
cde/lib/tt/demo/CoEd/libCoEd/CoEd.h
Normal 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
|
||||
128
cde/lib/tt/demo/CoEd/libCoEd/CoEdChangeHistory.C
Normal file
128
cde/lib/tt/demo/CoEd/libCoEd/CoEdChangeHistory.C
Normal 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;
|
||||
}
|
||||
|
||||
51
cde/lib/tt/demo/CoEd/libCoEd/CoEdChangeHistory.h
Normal file
51
cde/lib/tt/demo/CoEd/libCoEd/CoEdChangeHistory.h
Normal 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
|
||||
58
cde/lib/tt/demo/CoEd/libCoEd/CoEdChangeQueue.C
Normal file
58
cde/lib/tt/demo/CoEd/libCoEd/CoEdChangeQueue.C
Normal 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;
|
||||
}
|
||||
47
cde/lib/tt/demo/CoEd/libCoEd/CoEdChangeQueue.h
Normal file
47
cde/lib/tt/demo/CoEd/libCoEd/CoEdChangeQueue.h
Normal 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
|
||||
612
cde/lib/tt/demo/CoEd/libCoEd/CoEdFile.C
Normal file
612
cde/lib/tt/demo/CoEd/libCoEd/CoEdFile.C
Normal 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;
|
||||
}
|
||||
60
cde/lib/tt/demo/CoEd/libCoEd/CoEdFile.h
Normal file
60
cde/lib/tt/demo/CoEd/libCoEd/CoEdFile.h
Normal 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
|
||||
47
cde/lib/tt/demo/CoEd/libCoEd/CoEdGlobals.h
Normal file
47
cde/lib/tt/demo/CoEd/libCoEd/CoEdGlobals.h
Normal 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
|
||||
258
cde/lib/tt/demo/CoEd/libCoEd/CoEdSiteID.C
Normal file
258
cde/lib/tt/demo/CoEd/libCoEd/CoEdSiteID.C
Normal 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;
|
||||
}
|
||||
}
|
||||
90
cde/lib/tt/demo/CoEd/libCoEd/CoEdSiteID.h
Normal file
90
cde/lib/tt/demo/CoEd/libCoEd/CoEdSiteID.h
Normal 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 ©( 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
|
||||
539
cde/lib/tt/demo/CoEd/libCoEd/CoEdTextChange.C
Normal file
539
cde/lib/tt/demo/CoEd/libCoEd/CoEdTextChange.C
Normal 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;
|
||||
}
|
||||
}
|
||||
115
cde/lib/tt/demo/CoEd/libCoEd/CoEdTextChange.h
Normal file
115
cde/lib/tt/demo/CoEd/libCoEd/CoEdTextChange.h
Normal 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
|
||||
148
cde/lib/tt/demo/CoEd/libCoEd/CoEdTextVersion.C
Normal file
148
cde/lib/tt/demo/CoEd/libCoEd/CoEdTextVersion.C
Normal 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;
|
||||
}
|
||||
54
cde/lib/tt/demo/CoEd/libCoEd/CoEdTextVersion.h
Normal file
54
cde/lib/tt/demo/CoEd/libCoEd/CoEdTextVersion.h
Normal 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
|
||||
39
cde/lib/tt/demo/CoEd/libCoEd/IMakeFile
Normal file
39
cde/lib/tt/demo/CoEd/libCoEd/IMakeFile
Normal 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
|
||||
282
cde/lib/tt/demo/CoEd/libCoEd/Makefile.shipped
Normal file
282
cde/lib/tt/demo/CoEd/libCoEd/Makefile.shipped
Normal 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
|
||||
12
cde/lib/tt/demo/CoEd/libCoEd/Makefile.test
Normal file
12
cde/lib/tt/demo/CoEd/libCoEd/Makefile.test
Normal 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
|
||||
378
cde/lib/tt/demo/CoEd/libCoEd/SiteChange.C
Normal file
378
cde/lib/tt/demo/CoEd/libCoEd/SiteChange.C
Normal 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;
|
||||
}
|
||||
}
|
||||
100
cde/lib/tt/demo/CoEd/libCoEd/SiteChange.h
Normal file
100
cde/lib/tt/demo/CoEd/libCoEd/SiteChange.h
Normal 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 ©( const SiteChangeList *list );
|
||||
void print( FILE *f ) const;
|
||||
|
||||
private:
|
||||
SiteChange *_head;
|
||||
SiteChange *_tail;
|
||||
int _count;
|
||||
|
||||
void _flush();
|
||||
};
|
||||
|
||||
#endif SiteChange_h
|
||||
63
cde/lib/tt/demo/CoEd/libCoEd/SunMakefile
Normal file
63
cde/lib/tt/demo/CoEd/libCoEd/SunMakefile
Normal 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
|
||||
34
cde/lib/tt/demo/Makefile.shipped
Normal file
34
cde/lib/tt/demo/Makefile.shipped
Normal file
@@ -0,0 +1,34 @@
|
||||
# $XConsortium: Makefile.shipped /main/6 1996/05/13 12:03:47 drk $
|
||||
# %% (c) Copyright 1993, 1994 Hewlett-Packard Company
|
||||
# %% (c) Copyright 1993, 1994 International Business Machines Corp.
|
||||
# %% (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
|
||||
# %% (c) Copyright 1993, 1994 Novell, Inc.
|
||||
|
||||
|
||||
OPENWINHOME=/usr/openwin
|
||||
MOTIFHOME=/usr/dt
|
||||
|
||||
CFLAGS += -g
|
||||
CPPFLAGS += -I$(OPENWINHOME)/include
|
||||
LDFLAGS += -L$(OPENWINHOME)/lib
|
||||
LDLIBS += -lxview -lolgx -ltt -lX
|
||||
DEMO_DIR = demo
|
||||
|
||||
.KEEP_STATE:
|
||||
|
||||
DEMO_SOURCE_DIRS = edit_demo ttsample
|
||||
|
||||
all: $(DEMO_SOURCE_DIRS)
|
||||
|
||||
edit_demo: FRC
|
||||
cd edit_demo; ${MAKE}; cd ..
|
||||
|
||||
ttsample: FRC
|
||||
cd ttsample; ${MAKE}; cd ..
|
||||
|
||||
clean: FRC
|
||||
cd edit_demo; ${MAKE} -i clean; cd ..; \
|
||||
cd ttsample; ${MAKE} -i clean; cd ..; \
|
||||
|
||||
FRC:
|
||||
|
||||
12
cde/lib/tt/demo/Makefile.test
Normal file
12
cde/lib/tt/demo/Makefile.test
Normal 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/20 17:03:08 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
|
||||
62
cde/lib/tt/demo/SunMakefile
Normal file
62
cde/lib/tt/demo/SunMakefile
Normal file
@@ -0,0 +1,62 @@
|
||||
# %% (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/20 17:03:17 rswiston $
|
||||
#
|
||||
#
|
||||
# @(#)SunMakefile 1.15 26 Oct 1993
|
||||
#
|
||||
# The ToolTalk demo makefile
|
||||
#
|
||||
# Copyright (c) 1992 by Sun Microsystems, Inc.
|
||||
#
|
||||
|
||||
TT_DIR = ..
|
||||
THIS_DIR = demo
|
||||
|
||||
include $(TT_DIR)/SunMakefile-head.mk
|
||||
|
||||
# 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,
|
||||
# make shipped
|
||||
|
||||
# To make the demos using the ToolTalk in $(TT_DIR)/proto, run
|
||||
# make test
|
||||
|
||||
SUBDIRS =
|
||||
# We only need to descend into the subdirectories when installing or doing
|
||||
# "make shipped" or "make test".
|
||||
install-% shipped test := SUBDIRS = CoEd
|
||||
|
||||
DEMO_DIR = share/src/tooltalk/demo
|
||||
|
||||
INSTALL_MAKEFILE = $(INSTALL_DIR)/$(DEMO_DIR)/Makefile
|
||||
|
||||
all::
|
||||
|
||||
$(INSTALL_TARGETS):: $$(INSTALL_MAKEFILE)
|
||||
|
||||
$(INSTALL_MAKEFILE): Makefile.shipped
|
||||
$(TTINSTALL) $(@D) Makefile.shipped;\
|
||||
rm -f $@;\
|
||||
mv $(@D)/Makefile.shipped $@
|
||||
|
||||
shipped test:
|
||||
if [ ! -w CoEd/CoEd_main/CoEd_stubs.c ]; then \
|
||||
echo golit needs CoEd/CoEd_main/CoEd_stubs.c to be writable.; \
|
||||
echo Check it out, build, and then uncheck it out.; \
|
||||
exit 1; \
|
||||
fi
|
||||
MAKE="$(MAKE) -f Makefile.$@" $(MAKE) -f Makefile.$@
|
||||
|
||||
shippedclean:
|
||||
MAKE="$(MAKE) -f Makefile.shipped" $(MAKE) -f Makefile.shipped clean
|
||||
|
||||
include $(TT_DIR)/SunMakefile-tail.mk
|
||||
|
||||
FRC:
|
||||
|
||||
33
cde/lib/tt/demo/edit_demo/Makefile
Normal file
33
cde/lib/tt/demo/edit_demo/Makefile
Normal file
@@ -0,0 +1,33 @@
|
||||
# $XConsortium: Makefile /main/6 1996/05/13 12:04:04 drk $
|
||||
# %% (c) Copyright 1993, 1994 Hewlett-Packard Company
|
||||
# %% (c) Copyright 1993, 1994 International Business Machines Corp.
|
||||
# %% (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
|
||||
# %% (c) Copyright 1993, 1994 Novell, Inc.
|
||||
|
||||
OPENWINHOME=/usr/openwin
|
||||
MOTIFHOME=/usr/dt
|
||||
|
||||
CFLAGS += -g
|
||||
CPPFLAGS += -I$(MOTIFHOME)/include -I$(OPENWINHOME)/include
|
||||
LDFLAGS += -L$(MOTIFHOME)/lib -L$(OPENWINHOME)/lib
|
||||
LDLIBS += -lXm -lXt -ltt -lX11 -lgen
|
||||
|
||||
.KEEP_STATE:
|
||||
|
||||
Sun_EditDemo: cntl edit edit.types
|
||||
|
||||
edit:
|
||||
LD_RUN_PATH=$(MOTIFHOME)/lib:$(OPENWINHOME)/lib $(LINK.c) -o $@ edit.c $(LDLIBS)
|
||||
cntl:
|
||||
LD_RUN_PATH=$(MOTIFHOME)/lib:$(OPENWINHOME)/lib $(LINK.c) -o $@ cntl.c $(LDLIBS)
|
||||
|
||||
edit.types: edit.types.model
|
||||
tt_type_comp '-DTOOLTALK_DEMO_DIR=\"`pwd`\"' edit.types.model
|
||||
@echo ToolTalk types installed for Sun_EditDemo.
|
||||
@echo Remember to \"kill -USR2\" the ttsession process so the new
|
||||
@echo types will be active.
|
||||
|
||||
clean:
|
||||
rm -f cntl edit core edit.types
|
||||
|
||||
FRC:
|
||||
23
cde/lib/tt/demo/edit_demo/Sun_EditDemo_opnums.h
Normal file
23
cde/lib/tt/demo/edit_demo/Sun_EditDemo_opnums.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*%% (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: Sun_EditDemo_opnums.h /main/3 1995/10/23 09:46:15 rswiston $ */
|
||||
/*
|
||||
*
|
||||
* Sun_EditDemo_opnums.h
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Symbolic definitions for all the opnums used by edit.c. This allows
|
||||
* both the edit.types file and edit.c file to share the same
|
||||
* definitions.
|
||||
*/
|
||||
#define SUN_EDITDEMO_EDIT 0
|
||||
#define SUN_EDITDEMO_SAVE 1
|
||||
#define SUN_EDITDEMO_SAVE_AS 2
|
||||
#define SUN_EDITDEMO_CLOSE 3
|
||||
#define SUN_EDITDEMO_HILITE_OBJ 4
|
||||
|
||||
955
cde/lib/tt/demo/edit_demo/cntl.c
Normal file
955
cde/lib/tt/demo/edit_demo/cntl.c
Normal file
@@ -0,0 +1,955 @@
|
||||
/*%% (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. */
|
||||
/*%% $TOG: cntl.c /main/4 1998/05/18 16:55:06 rafi $ */
|
||||
/*
|
||||
* cntl.c
|
||||
*
|
||||
* Copyright (c) 1993 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* An example controller for the remote-control editor defined in edit.c.
|
||||
* Puts up a simple panel with a text field to enter the filename to
|
||||
* operate on and sends out ToolTalk messages to start up an editor to
|
||||
* carry out the operations. Also allows browsing any sub-file specs
|
||||
* defined in the file.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <Xm/Xm.h>
|
||||
#include <Xm/MainW.h>
|
||||
#include <Xm/CascadeB.h>
|
||||
#include <Xm/DialogS.h>
|
||||
#include <Xm/Form.h>
|
||||
#include <Xm/Label.h>
|
||||
#include <Xm/List.h>
|
||||
#include <Xm/PushB.h>
|
||||
#include <Xm/Text.h>
|
||||
#include <Xm/Protocols.h>
|
||||
#include <desktop/tt_c.h>
|
||||
|
||||
#define TITLE_LINE_HEIGHT 25
|
||||
|
||||
Display *dpy;
|
||||
XtAppContext app;
|
||||
|
||||
Widget cntl_ui_base_window;
|
||||
Widget cntl_ui_base_controls;
|
||||
Widget cntl_ui_file_button;
|
||||
Widget cntl_ui_file_label;
|
||||
Widget cntl_ui_file_field;
|
||||
Widget cntl_ui_message;
|
||||
Widget cntl_ui_file_menu;
|
||||
|
||||
Widget cntl_ui_saveas_popup;
|
||||
Widget cntl_ui_saveas_controls;
|
||||
Widget cntl_ui_save_as_dlabel;
|
||||
Widget cntl_ui_save_as_directory;
|
||||
Widget cntl_ui_new_flabel;
|
||||
Widget cntl_ui_new_filename;
|
||||
Widget cntl_ui_save_as_button;
|
||||
|
||||
Widget cntl_ui_obj_popup;
|
||||
Widget cntl_ui_obj_controls;
|
||||
Widget cntl_ui_olist_label;
|
||||
Widget cntl_ui_olist;
|
||||
Widget cntl_ui_hilite_button;
|
||||
Widget cntl_ui_obj_field;
|
||||
|
||||
char *cntl_objid = (char *)0;
|
||||
|
||||
Tt_scope msg_scope = TT_FILE_IN_SESSION;
|
||||
|
||||
void
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
void cntl_ui_initialize();
|
||||
|
||||
/*
|
||||
* Initialize Motif.
|
||||
*/
|
||||
XtToolkitInitialize();
|
||||
app = XtCreateApplicationContext();
|
||||
dpy = XtOpenDisplay(app, 0, 0, "cntl", 0, 0, &argc, argv);
|
||||
/*
|
||||
* Initialize user interface components.
|
||||
*/
|
||||
cntl_ui_initialize();
|
||||
|
||||
if (! cntl_init_tt()) {
|
||||
fprintf(stderr,"%s: Can't initialize ToolTalk\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
/*
|
||||
* Turn control over to Motif.
|
||||
*/
|
||||
XtAppMainLoop(app);
|
||||
tt_close();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
is_window_showing(widget)
|
||||
Widget widget;
|
||||
{
|
||||
return(XtIsManaged(widget)) ;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
get_screen_size(widget, width, height)
|
||||
Widget widget;
|
||||
int *width, *height;
|
||||
{
|
||||
Display *dpy = XtDisplay(widget);
|
||||
int screen = DefaultScreen(dpy);
|
||||
|
||||
*width = DisplayWidth(dpy, screen);
|
||||
*height = DisplayHeight(dpy, screen);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
force_popup_on_screen(popup, px, py)
|
||||
Widget popup;
|
||||
int *px, *py;
|
||||
{
|
||||
Dimension popup_width, popup_height;
|
||||
Position left, top;
|
||||
int n, x, y, screen_width, screen_height;
|
||||
|
||||
x = *px;
|
||||
y = *py;
|
||||
|
||||
/* Get the screen size. */
|
||||
|
||||
get_screen_size(popup, &screen_width, &screen_height);
|
||||
|
||||
XtVaGetValues(popup,
|
||||
XmNwidth, &popup_width,
|
||||
XmNheight, &popup_height,
|
||||
0);
|
||||
|
||||
/* Make sure frame does not go off side of screen. */
|
||||
|
||||
n = x + (int) popup_width;
|
||||
if (n > screen_width) x -= (n - screen_width);
|
||||
else if (x < 0) x = 0;
|
||||
|
||||
/* Make sure frame doen't go off top or bottom. */
|
||||
|
||||
n = y + (int) popup_height;
|
||||
if (n > screen_height) y -= n - screen_height;
|
||||
else if (y < 0) y = 0;
|
||||
|
||||
/* Set location and return. */
|
||||
|
||||
left = (Position) x;
|
||||
top = (Position) y;
|
||||
XtVaSetValues(popup,
|
||||
XmNx, left,
|
||||
XmNy, top,
|
||||
0);
|
||||
|
||||
*px = x;
|
||||
*py = y;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
position_popup(base, popup)
|
||||
Widget base, popup;
|
||||
{
|
||||
int bw, bx, by, px, py;
|
||||
int screen_width, screen_height;
|
||||
Position base_x, base_y, popup_x, popup_y;
|
||||
Dimension base_width, base_height, popup_width, popup_height;
|
||||
|
||||
XtVaGetValues(base,
|
||||
XmNx, &base_x,
|
||||
XmNy, &base_y,
|
||||
XmNwidth, &base_width,
|
||||
XmNheight, &base_height,
|
||||
0);
|
||||
bx = (int) base_x;
|
||||
by = (int) base_y;
|
||||
bw = (int) base_width;
|
||||
|
||||
XtVaGetValues(popup,
|
||||
XmNx, &popup_x,
|
||||
XmNy, &popup_y,
|
||||
XmNwidth, &popup_width,
|
||||
XmNheight, &popup_height,
|
||||
0);
|
||||
|
||||
px = (int) popup_x;
|
||||
py = (int) popup_y;
|
||||
|
||||
get_screen_size(popup, &screen_width, &screen_height);
|
||||
px = bx + bw + 5;
|
||||
py = by - TITLE_LINE_HEIGHT;
|
||||
force_popup_on_screen(popup, &px, &py);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
show_popup(widget)
|
||||
Widget widget;
|
||||
{
|
||||
if (!is_window_showing(widget))
|
||||
position_popup(cntl_ui_base_window, widget) ;
|
||||
XtMapWidget(widget);
|
||||
XtManageChild(widget);
|
||||
XtPopup(XtParent(widget), XtGrabNone);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dismiss_popup(widget, client_data, cbs)
|
||||
Widget widget;
|
||||
XtPointer client_data;
|
||||
XmAnyCallbackStruct *cbs;
|
||||
{
|
||||
XtUnmapWidget(widget);
|
||||
XtUnmanageChild(widget);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
add_delete_callback(widget)
|
||||
Widget widget;
|
||||
{
|
||||
Atom WM_DELETE_WINDOW;
|
||||
|
||||
WM_DELETE_WINDOW = XmInternAtom(XtDisplay(widget),
|
||||
"WM_DELETE_WINDOW", False);
|
||||
XmAddWMProtocolCallback(widget, WM_DELETE_WINDOW,
|
||||
(XtCallbackProc) dismiss_popup, NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
write_footer(message)
|
||||
char *message;
|
||||
{
|
||||
XmString label;
|
||||
|
||||
label = XmStringCreateSimple(message);
|
||||
XtVaSetValues(cntl_ui_message, XmNlabelString, label, 0);
|
||||
XmStringFree(label);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize our ToolTalk environment.
|
||||
*/
|
||||
int
|
||||
cntl_init_tt()
|
||||
{
|
||||
char *procid = tt_open();
|
||||
int ttfd;
|
||||
void cntl_receive_tt_message();
|
||||
Tt_pattern pat;
|
||||
Tt_callback_action cntl_update_obj_panel_callback();
|
||||
|
||||
|
||||
if (tt_pointer_error(procid) != TT_OK) {
|
||||
return 0;
|
||||
}
|
||||
ttfd = tt_fd();
|
||||
|
||||
/* register a dynamic pattern to catch whenever the remote */
|
||||
/* editor creates a sub-file object so that we can update our */
|
||||
/* object query panel. */
|
||||
|
||||
pat = tt_pattern_create();
|
||||
tt_pattern_op_add(pat, "Sun_EditDemo_new_object");
|
||||
tt_pattern_scope_add(pat, msg_scope);
|
||||
tt_pattern_category_set(pat, TT_OBSERVE);
|
||||
tt_pattern_callback_add(pat, cntl_update_obj_panel_callback);
|
||||
if (tt_pattern_register(pat) != TT_OK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
XtAppAddInput(app, ttfd, (XtPointer) XtInputReadMask,
|
||||
cntl_receive_tt_message, 0);
|
||||
|
||||
tt_session_join(tt_default_session());
|
||||
|
||||
tt_free(procid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Handle any incoming ToolTalk messages. Since all the messages we send
|
||||
* out have callback functions, no further action is required after doing
|
||||
* a tt_message_receive.
|
||||
*/
|
||||
void
|
||||
cntl_receive_tt_message(client_data, fid, id)
|
||||
XtPointer client_data;
|
||||
int *fid;
|
||||
XtInputId *id;
|
||||
{
|
||||
Tt_message msg;
|
||||
|
||||
msg = tt_message_receive();
|
||||
if (msg != NULL && tt_pointer_error(msg) == TT_ERR_NOMP) {
|
||||
fprintf(stderr,"ToolTalk server down.\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Callback for our dynamic pattern informing us when an object has
|
||||
* been added to a file. We use this information to update the file
|
||||
* objects panel if it is up.
|
||||
*/
|
||||
Tt_callback_action
|
||||
cntl_update_obj_panel_callback(m, p)
|
||||
Tt_message m;
|
||||
Tt_pattern p;
|
||||
{
|
||||
int mark;
|
||||
|
||||
mark = tt_mark();
|
||||
|
||||
if (cntl_is_same_file(tt_message_file(m),
|
||||
XmTextGetString(cntl_ui_file_field))) {
|
||||
|
||||
/* update the objects panel if it's showing */
|
||||
/* objects for the same file as the one in the */
|
||||
/* message. */
|
||||
cntl_update_obj_panel();
|
||||
}
|
||||
|
||||
/*
|
||||
* no further action required for this message. Destroy it
|
||||
* and return TT_CALLBACK_PROCESSED so no other callbacks will
|
||||
* be run for the message.
|
||||
*/
|
||||
tt_message_destroy(m);
|
||||
tt_release(mark);
|
||||
return TT_CALLBACK_PROCESSED;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Default callback for all the ToolTalk messages we send.
|
||||
*/
|
||||
Tt_callback_action
|
||||
cntl_msg_callback(m, p)
|
||||
Tt_message m;
|
||||
Tt_pattern p;
|
||||
{
|
||||
int mark;
|
||||
char msg[255];
|
||||
char *errstr;
|
||||
|
||||
|
||||
mark = tt_mark();
|
||||
switch (tt_message_state(m)) {
|
||||
case TT_STARTED:
|
||||
write_footer("Starting editor...");
|
||||
break;
|
||||
case TT_HANDLED:
|
||||
write_footer("");
|
||||
break;
|
||||
case TT_FAILED:
|
||||
errstr = tt_message_status_string(m);
|
||||
if (tt_pointer_error(errstr) == TT_OK && errstr) {
|
||||
sprintf(msg,"%s failed: %s", tt_message_op(m), errstr);
|
||||
} else if (tt_message_status(m) == TT_ERR_NO_MATCH) {
|
||||
sprintf(msg,"%s failed: Couldn't contact editor",
|
||||
tt_message_op(m),
|
||||
tt_status_message(tt_message_status(m)));
|
||||
} else {
|
||||
sprintf(msg,"%s failed: %s",
|
||||
tt_message_op(m),
|
||||
tt_status_message(tt_message_status(m)));
|
||||
}
|
||||
write_footer(msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* no further action required for this message. Destroy it
|
||||
* and return TT_CALLBACK_PROCESSED so no other callbacks will
|
||||
* be run for the message.
|
||||
*/
|
||||
tt_message_destroy(m);
|
||||
tt_release(mark);
|
||||
return TT_CALLBACK_PROCESSED;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Handle the edit actions by sending out a message to Sun_EditDemo to
|
||||
* start an editing session.
|
||||
*/
|
||||
void
|
||||
cntl_edit(file)
|
||||
char *file;
|
||||
{
|
||||
Tt_message msg;
|
||||
|
||||
write_footer("");
|
||||
msg = tt_prequest_create(msg_scope, "Sun_EditDemo_edit");
|
||||
tt_message_file_set(msg, file);
|
||||
tt_message_callback_add(msg, cntl_msg_callback);
|
||||
tt_message_send(msg);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Handle the save actions by sending out a message to the Sun_EditDemo
|
||||
* editing this file to save the file.
|
||||
*/
|
||||
void
|
||||
cntl_save(file)
|
||||
char *file;
|
||||
{
|
||||
Tt_message msg;
|
||||
|
||||
write_footer("");
|
||||
msg = tt_prequest_create(msg_scope, "Sun_EditDemo_save");
|
||||
tt_message_file_set(msg, file);
|
||||
tt_message_callback_add(msg, cntl_msg_callback);
|
||||
tt_message_send(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Shut down the Sun_EditDemo that is editing this file.
|
||||
*/
|
||||
void
|
||||
cntl_close(file)
|
||||
char *file;
|
||||
{
|
||||
Tt_message msg;
|
||||
|
||||
write_footer("");
|
||||
msg = tt_prequest_create(msg_scope, "Sun_EditDemo_close");
|
||||
tt_message_file_set(msg, file);
|
||||
tt_message_callback_add(msg, cntl_msg_callback);
|
||||
tt_message_send(msg);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Instruct the Sun_EditDemo that is editing this file to save the file
|
||||
* under a new name.
|
||||
*/
|
||||
void
|
||||
cntl_save_as(file, dir, newfile)
|
||||
char *file;
|
||||
char *dir;
|
||||
char *newfile;
|
||||
{
|
||||
Tt_message msg;
|
||||
char buf[255];
|
||||
int dirlen;
|
||||
|
||||
msg = tt_prequest_create(msg_scope, "Sun_EditDemo_save_as");
|
||||
|
||||
/* construct new filename out of directory and new file */
|
||||
/* fields. */
|
||||
|
||||
dirlen = strlen(dir);
|
||||
if (dirlen > 0 && dir[dirlen - 1] == '/') {
|
||||
sprintf(buf,"%s%s", dir, newfile);
|
||||
} else {
|
||||
sprintf(buf,"%s/%s", dir, newfile);
|
||||
}
|
||||
|
||||
tt_message_arg_add(msg, TT_IN, "string", buf);
|
||||
tt_message_file_set(msg, file);
|
||||
tt_message_callback_add(msg, cntl_msg_callback);
|
||||
tt_message_send(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Handler for `file_menu (Edit)'.
|
||||
*/
|
||||
void
|
||||
cntl_ui_edit(widget, client_data, call_data)
|
||||
Widget widget;
|
||||
XtPointer client_data, call_data;
|
||||
{
|
||||
write_footer("");
|
||||
cntl_edit(XmTextGetString(cntl_ui_file_field));
|
||||
}
|
||||
|
||||
/*
|
||||
* Handler for `file_menu (Save)'.
|
||||
*/
|
||||
void
|
||||
cntl_ui_save(widget, client_data, call_data)
|
||||
Widget widget;
|
||||
XtPointer client_data, call_data;
|
||||
{
|
||||
write_footer("");
|
||||
cntl_save(XmTextGetString(cntl_ui_file_field));
|
||||
}
|
||||
|
||||
/*
|
||||
* Handler for `file_menu (Save as...)'.
|
||||
*/
|
||||
cntl_ui_save_as(widget, client_data, call_data)
|
||||
Widget widget;
|
||||
XtPointer client_data, call_data;
|
||||
{
|
||||
write_footer("");
|
||||
show_popup(cntl_ui_saveas_popup);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handler for `file_menu (Close)'.
|
||||
*/
|
||||
cntl_ui_close(widget, client_data, call_data)
|
||||
Widget widget;
|
||||
XtPointer client_data, call_data;
|
||||
{
|
||||
write_footer("");
|
||||
cntl_close(XmTextGetString(cntl_ui_file_field));
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback function for `save_as_button'.
|
||||
*/
|
||||
void
|
||||
cntl_ui_save_as_button_handler(widget, client_data, call_data)
|
||||
Widget widget;
|
||||
XtPointer client_data, call_data;
|
||||
{
|
||||
write_footer("");
|
||||
cntl_save_as(XmTextGetString(cntl_ui_file_field),
|
||||
XmTextGetString(cntl_ui_save_as_directory),
|
||||
XmTextGetString(cntl_ui_new_filename));
|
||||
}
|
||||
|
||||
/*
|
||||
* Function to insert the objid given into the scrolling lists of objects
|
||||
* for a file. Used inside tt_file_objects_query as it iterates through
|
||||
* all the ToolTalk objects in a file.
|
||||
*/
|
||||
Tt_filter_action
|
||||
cntl_gather_specs(objid, list_count, acc)
|
||||
char *objid;
|
||||
void *list_count;
|
||||
void *acc;
|
||||
{
|
||||
int *i = (int *)list_count;
|
||||
XmString label;
|
||||
|
||||
label = XmStringCreateSimple(objid);
|
||||
XmListAddItem(cntl_ui_olist, label, *i);
|
||||
XmStringFree(label);
|
||||
|
||||
*i = (*i + 1);
|
||||
|
||||
/* continue processing */
|
||||
return TT_FILTER_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Called to update the scrolling list of objects for a file. Uses
|
||||
* tt_file_objects_query to find all the ToolTalk objects.
|
||||
*/
|
||||
int
|
||||
cntl_update_obj_panel()
|
||||
{
|
||||
static int list_item = 0;
|
||||
char *file;
|
||||
int i;
|
||||
|
||||
cntl_objid = (char *)0;
|
||||
|
||||
for (i = list_item; i >= 0; i--) {
|
||||
XmListDeletePos(cntl_ui_olist, i);
|
||||
}
|
||||
|
||||
list_item = 0;
|
||||
file = XmTextGetString(cntl_ui_file_field);
|
||||
if (tt_file_objects_query(file,
|
||||
(Tt_filter_function)cntl_gather_specs,
|
||||
&list_item, NULL) != TT_OK) {
|
||||
write_footer("Couldn't query objects for file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Callback function for "File objects..." menu item.
|
||||
*/
|
||||
void
|
||||
cntl_ui_file_objects(widget, client_data, call_data)
|
||||
Widget widget;
|
||||
XtPointer client_data, call_data;
|
||||
{
|
||||
char *string;
|
||||
|
||||
write_footer("");
|
||||
string = XmTextGetString(cntl_ui_file_field);
|
||||
if (cntl_update_obj_panel()) {
|
||||
(void) tt_file_join(XmTextGetString(cntl_ui_file_field));
|
||||
show_popup(cntl_ui_obj_popup);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Notify callback function for `cntl_ui_olist'.
|
||||
*/
|
||||
void
|
||||
cntl_ui_olist_handler(widget, client_data, cbs)
|
||||
Widget widget;
|
||||
XtPointer client_data;
|
||||
XmListCallbackStruct *cbs;
|
||||
{
|
||||
char *string;
|
||||
|
||||
string = XmStringUnparse(cbs->item, NULL, XmCHARSET_TEXT, XmCHARSET_TEXT,
|
||||
NULL, 0, XmOUTPUT_ALL);
|
||||
cntl_objid = strdup(string);
|
||||
XtFree (string);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Notify callback function for `cntl_ui_hilite_button'.
|
||||
*/
|
||||
void
|
||||
cntl_ui_hilite_button_handler(widget, client_data, call_data)
|
||||
Widget widget;
|
||||
XtPointer client_data, call_data;
|
||||
{
|
||||
Tt_message msg;
|
||||
|
||||
if (cntl_objid == (char *)0) {
|
||||
write_footer("No object id selected");
|
||||
return;
|
||||
}
|
||||
msg = tt_orequest_create(cntl_objid, "hilite_obj");
|
||||
tt_message_arg_add(msg, TT_IN, "string", cntl_objid);
|
||||
tt_message_callback_add(msg, cntl_msg_callback);
|
||||
tt_message_send(msg);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize ui environment.
|
||||
*/
|
||||
void
|
||||
cntl_ui_initialize()
|
||||
{
|
||||
Arg args[20];
|
||||
int n;
|
||||
Widget but;
|
||||
XmString label;
|
||||
void cntl_ui_saveas_popup_initialize();
|
||||
void cntl_ui_obj_popup_initialize();
|
||||
|
||||
cntl_ui_base_window = XtAppCreateShell(0, "base_frame",
|
||||
applicationShellWidgetClass, dpy, 0, 0 );
|
||||
XtVaSetValues(cntl_ui_base_window,
|
||||
XmNwidth, 339,
|
||||
XmNheight, 100,
|
||||
XmNtitle, "Sun_EditDemo_cntl",
|
||||
0);
|
||||
|
||||
cntl_ui_base_controls = XtVaCreateManagedWidget("controls",
|
||||
xmFormWidgetClass, cntl_ui_base_window, 0 );
|
||||
|
||||
n = 0;
|
||||
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNleftOffset, 5); n++;
|
||||
XtSetArg(args[n], XmNrightOffset, 5); n++;
|
||||
XtSetArg(args[n], XmNtopOffset, 5); n++;
|
||||
cntl_ui_file_menu = (Widget) XmCreateMenuBar(cntl_ui_base_controls,
|
||||
"menubar", args, n);
|
||||
|
||||
cntl_ui_file_button = (Widget) XmCreatePulldownMenu(cntl_ui_file_menu,
|
||||
"File", NULL, 0);
|
||||
label = XmStringCreateSimple("File");
|
||||
XtVaCreateManagedWidget("File",
|
||||
xmCascadeButtonWidgetClass, cntl_ui_file_menu,
|
||||
XmNlabelString, label,
|
||||
XmNmnemonic, 'F',
|
||||
XmNsubMenuId, cntl_ui_file_button,
|
||||
0);
|
||||
XmStringFree(label);
|
||||
but = XtVaCreateManagedWidget("Edit",
|
||||
xmPushButtonWidgetClass, cntl_ui_file_button, 0);
|
||||
XtAddCallback(but, XmNactivateCallback,
|
||||
(XtCallbackProc) cntl_ui_edit, 0);
|
||||
but = XtVaCreateManagedWidget("Save",
|
||||
xmPushButtonWidgetClass, cntl_ui_file_button, 0);
|
||||
XtAddCallback(but, XmNactivateCallback,
|
||||
(XtCallbackProc) cntl_ui_save, 0);
|
||||
but = XtVaCreateManagedWidget("Save as...",
|
||||
xmPushButtonWidgetClass, cntl_ui_file_button, 0);
|
||||
XtAddCallback(but, XmNactivateCallback,
|
||||
(XtCallbackProc) cntl_ui_save_as, 0);
|
||||
but = XtVaCreateManagedWidget("File Objects...",
|
||||
xmPushButtonWidgetClass, cntl_ui_file_button, 0);
|
||||
XtAddCallback(but, XmNactivateCallback,
|
||||
(XtCallbackProc) cntl_ui_file_objects, 0);
|
||||
but = XtVaCreateManagedWidget("Close",
|
||||
xmPushButtonWidgetClass, cntl_ui_file_button, 0);
|
||||
XtAddCallback(but, XmNactivateCallback,
|
||||
(XtCallbackProc) cntl_ui_close, 0);
|
||||
XtManageChild(cntl_ui_file_menu);
|
||||
|
||||
cntl_ui_file_label = XtVaCreateManagedWidget("File:",
|
||||
xmLabelWidgetClass, cntl_ui_base_controls,
|
||||
XmNtopAttachment, XmATTACH_WIDGET,
|
||||
XmNtopWidget, cntl_ui_file_menu,
|
||||
XmNtopOffset, 5,
|
||||
XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNleftOffset, 5,
|
||||
0);
|
||||
label = XmStringCreateSimple("File:");
|
||||
XtVaSetValues(cntl_ui_file_label, XmNlabelString, label, 0);
|
||||
XmStringFree(label);
|
||||
|
||||
cntl_ui_file_field = XtVaCreateManagedWidget("text",
|
||||
xmTextWidgetClass, cntl_ui_base_controls,
|
||||
XmNtopAttachment, XmATTACH_WIDGET,
|
||||
XmNtopWidget, cntl_ui_file_menu,
|
||||
XmNtopOffset, 5,
|
||||
XmNleftAttachment, XmATTACH_WIDGET,
|
||||
XmNleftWidget, cntl_ui_file_label,
|
||||
XmNleftOffset, 5,
|
||||
XmNrightAttachment, XmATTACH_FORM,
|
||||
XmNrightOffset, 5,
|
||||
0);
|
||||
label = XmStringCreateSimple("");
|
||||
XtVaSetValues(cntl_ui_file_field, XmNlabelString, label, 0);
|
||||
XmStringFree(label);
|
||||
|
||||
cntl_ui_message = XtVaCreateManagedWidget("message",
|
||||
xmLabelWidgetClass, cntl_ui_base_controls,
|
||||
XmNtopAttachment, XmATTACH_WIDGET,
|
||||
XmNtopWidget, cntl_ui_file_field,
|
||||
XmNtopOffset, 10,
|
||||
XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNleftOffset, 5,
|
||||
XmNrightAttachment, XmATTACH_FORM,
|
||||
XmNrightOffset, 5,
|
||||
XmNbottomAttachment, XmATTACH_FORM,
|
||||
XmNbottomOffset, 5,
|
||||
0);
|
||||
label = XmStringCreateSimple("");
|
||||
XtVaSetValues(cntl_ui_message, XmNlabelString, label, 0);
|
||||
XmStringFree(label);
|
||||
|
||||
XtRealizeWidget(cntl_ui_base_window);
|
||||
|
||||
cntl_ui_saveas_popup_initialize();
|
||||
cntl_ui_obj_popup_initialize();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
cntl_ui_saveas_popup_initialize()
|
||||
{
|
||||
Arg args[10];
|
||||
int n;
|
||||
XmString label;
|
||||
|
||||
n = 0;
|
||||
XtSetArg(args[n], XmNtitle, "Sun_EditMenu_cntl: Save As"); n++;
|
||||
XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
|
||||
XtSetArg(args[n], XmNdeleteResponse, XmDO_NOTHING); n++;
|
||||
cntl_ui_saveas_popup = XmCreateDialogShell(cntl_ui_base_window,
|
||||
"saveas", args, n);
|
||||
|
||||
cntl_ui_saveas_controls = XtVaCreateManagedWidget("controls",
|
||||
xmFormWidgetClass, cntl_ui_saveas_popup,
|
||||
XmNrubberPositioning, False,
|
||||
XmNresizePolicy, XmRESIZE_ANY,
|
||||
XmNautoUnmanage, False,
|
||||
XmNwidth, 350,
|
||||
XmNheight, 120,
|
||||
0);
|
||||
|
||||
label = XmStringCreateSimple("Directory:");
|
||||
cntl_ui_save_as_dlabel = XtVaCreateManagedWidget("dlabel",
|
||||
xmLabelWidgetClass, cntl_ui_saveas_controls,
|
||||
XmNtopAttachment, XmATTACH_FORM,
|
||||
XmNtopOffset, 5,
|
||||
XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNleftOffset, 5,
|
||||
XmNlabelString, label,
|
||||
0);
|
||||
XmStringFree(label);
|
||||
|
||||
cntl_ui_save_as_directory = XtVaCreateManagedWidget("text",
|
||||
xmTextWidgetClass, cntl_ui_saveas_controls,
|
||||
XmNcolumns, 35,
|
||||
XmNtopAttachment, XmATTACH_FORM,
|
||||
XmNtopOffset, 5,
|
||||
XmNleftAttachment, XmATTACH_WIDGET,
|
||||
XmNleftWidget, cntl_ui_save_as_dlabel,
|
||||
XmNleftOffset, 5,
|
||||
XmNrightAttachment, XmATTACH_FORM,
|
||||
XmNrightOffset, 5,
|
||||
0);
|
||||
|
||||
label = XmStringCreateSimple("Filename:");
|
||||
cntl_ui_new_flabel = XtVaCreateManagedWidget("flabel",
|
||||
xmLabelWidgetClass, cntl_ui_saveas_controls,
|
||||
XmNtopAttachment, XmATTACH_WIDGET,
|
||||
XmNtopWidget, cntl_ui_save_as_directory,
|
||||
XmNtopOffset, 5,
|
||||
XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNleftOffset, 5,
|
||||
XmNlabelString, label,
|
||||
0);
|
||||
XmStringFree(label);
|
||||
|
||||
label = XmStringCreateSimple("");
|
||||
cntl_ui_new_filename = XtVaCreateManagedWidget("text",
|
||||
xmTextWidgetClass, cntl_ui_saveas_controls,
|
||||
XmNcolumns, 35,
|
||||
XmNlabelString, label,
|
||||
XmNtopAttachment, XmATTACH_WIDGET,
|
||||
XmNtopWidget, cntl_ui_save_as_directory,
|
||||
XmNtopOffset, 5,
|
||||
XmNleftAttachment, XmATTACH_WIDGET,
|
||||
XmNleftWidget, cntl_ui_save_as_dlabel,
|
||||
XmNleftOffset, 5,
|
||||
XmNrightAttachment, XmATTACH_FORM,
|
||||
XmNrightOffset, 5,
|
||||
0);
|
||||
XmStringFree(label);
|
||||
|
||||
label = XmStringCreateSimple("Save");
|
||||
cntl_ui_save_as_button = XtVaCreateManagedWidget("button",
|
||||
xmPushButtonWidgetClass, cntl_ui_saveas_controls,
|
||||
XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNleftOffset, 5,
|
||||
XmNtopAttachment, XmATTACH_WIDGET,
|
||||
XmNtopWidget, cntl_ui_new_filename,
|
||||
XmNtopOffset, 5,
|
||||
XmNbottomAttachment, XmATTACH_FORM,
|
||||
XmNbottomOffset, 5,
|
||||
XmNlabelString, label,
|
||||
0);
|
||||
XmStringFree(label);
|
||||
XtAddCallback(cntl_ui_save_as_button,
|
||||
XmNactivateCallback, cntl_ui_save_as_button_handler, 0);
|
||||
XtManageChild(cntl_ui_saveas_controls);
|
||||
add_delete_callback(cntl_ui_saveas_popup);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
cntl_ui_obj_popup_initialize()
|
||||
{
|
||||
int n;
|
||||
Arg args[20];
|
||||
XmString label;
|
||||
|
||||
n = 0;
|
||||
XtSetArg(args[n], XmNtitle, "Sun_EditMenu_cntl: File Objects"); n++;
|
||||
XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
|
||||
XtSetArg(args[n], XmNdeleteResponse, XmDO_NOTHING); n++;
|
||||
cntl_ui_obj_popup = XmCreateDialogShell(cntl_ui_base_window,
|
||||
"object", args, n);
|
||||
|
||||
cntl_ui_obj_controls = XtVaCreateManagedWidget("controls",
|
||||
xmFormWidgetClass, cntl_ui_obj_popup,
|
||||
XmNrubberPositioning, False,
|
||||
XmNresizePolicy, XmRESIZE_ANY,
|
||||
XmNautoUnmanage, False,
|
||||
XmNwidth, 350,
|
||||
XmNheight, 120,
|
||||
0);
|
||||
|
||||
n = 0;
|
||||
label = XmStringCreateSimple("File Objects:");
|
||||
XtSetArg(args[n], XmNlabelString, label); n++;
|
||||
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNleftOffset, 5); n++;
|
||||
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNtopOffset, 5); n++;
|
||||
cntl_ui_olist_label =
|
||||
XmCreateLabel(cntl_ui_obj_controls, "label", args, n);
|
||||
XmStringFree(label);
|
||||
XtManageChild(cntl_ui_olist_label);
|
||||
|
||||
n = 0;
|
||||
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNtopOffset, 5); n++;
|
||||
XtSetArg(args[n], XmNvisibleItemCount, 4); n++;
|
||||
XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
|
||||
XtSetArg(args[n], XmNleftWidget, cntl_ui_olist_label); n++;
|
||||
XtSetArg(args[n], XmNleftOffset, 5); n++;
|
||||
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNrightOffset, 5); n++;
|
||||
XtSetArg(args[n], XmNresizable, True); n++;
|
||||
cntl_ui_olist =
|
||||
XmCreateScrolledList(cntl_ui_obj_controls, "olist", args, n);
|
||||
XtAddCallback(cntl_ui_olist,
|
||||
XmNsingleSelectionCallback, cntl_ui_olist_handler, 0);
|
||||
XtManageChild(cntl_ui_olist);
|
||||
|
||||
label = XmStringCreateSimple("Display");
|
||||
cntl_ui_hilite_button = XtVaCreateManagedWidget("button",
|
||||
xmPushButtonWidgetClass, cntl_ui_obj_controls,
|
||||
XmNtopAttachment, XmATTACH_WIDGET,
|
||||
XmNtopWidget, cntl_ui_olist,
|
||||
XmNtopOffset, 5,
|
||||
XmNbottomAttachment, XmATTACH_FORM,
|
||||
XmNbottomOffset, 5,
|
||||
XmNlabelString, label,
|
||||
0);
|
||||
XmStringFree(label);
|
||||
XtAddCallback(cntl_ui_hilite_button,
|
||||
XmNactivateCallback, cntl_ui_hilite_button_handler, 0);
|
||||
XtManageChild(cntl_ui_obj_controls);
|
||||
add_delete_callback(cntl_ui_obj_popup);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
cntl_is_same_file(f1, f2)
|
||||
char *f1;
|
||||
char *f2;
|
||||
{
|
||||
struct stat f1_stat;
|
||||
struct stat f2_stat;
|
||||
|
||||
if (!strcmp(f1,f2)) {
|
||||
return(1);
|
||||
}
|
||||
|
||||
return((0 == stat(f1, &f1_stat)) &&
|
||||
(0 == stat(f2, &f2_stat)) &&
|
||||
(f1_stat.st_ino == f2_stat.st_ino) &&
|
||||
(f1_stat.st_dev == f2_stat.st_dev));
|
||||
}
|
||||
774
cde/lib/tt/demo/edit_demo/edit.c
Normal file
774
cde/lib/tt/demo/edit_demo/edit.c
Normal file
@@ -0,0 +1,774 @@
|
||||
/*%% (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: edit.c /main/3 1995/10/23 09:46:34 rswiston $ */
|
||||
/*
|
||||
* edit.c
|
||||
*
|
||||
* Copyright (c) 1993 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Implementation of a simple "remote-control" editor. Accepts requests
|
||||
* to edit, save, and close files as well as hilite "objects" created in
|
||||
* the file. Objects are kept track of by wrapping them in C-style
|
||||
* comments with their respective object ids.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <Xm/Xm.h>
|
||||
#include <Xm/Label.h>
|
||||
#include <Xm/Form.h>
|
||||
#include <Xm/PushB.h>
|
||||
#include <Xm/Text.h>
|
||||
#include <desktop/tt_c.h>
|
||||
#include "Sun_EditDemo_opnums.h"
|
||||
|
||||
Display *dpy;
|
||||
XtAppContext app;
|
||||
char current_file[MAXPATHLEN];
|
||||
int do_close = 0;
|
||||
int text_modified = -1;
|
||||
|
||||
Widget edit_ui_base_window;
|
||||
Widget edit_ui_textpane;
|
||||
Widget edit_ui_panel;
|
||||
Widget edit_ui_obj_button;
|
||||
Widget edit_ui_message;
|
||||
|
||||
|
||||
void
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
char *dfile;
|
||||
|
||||
/*
|
||||
* Initialize Motif.
|
||||
*/
|
||||
XtToolkitInitialize();
|
||||
app = XtCreateApplicationContext();
|
||||
dpy = XtOpenDisplay(app, 0, 0, "edit", 0, 0, &argc, argv );
|
||||
|
||||
/*
|
||||
* Initialize user interface components.
|
||||
*/
|
||||
edit_ui_initialize();
|
||||
if (! edit_init_tt()) {
|
||||
fprintf(stderr,"%s: Can't initialize ToolTalk\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
/*
|
||||
* Turn control over to Motif.
|
||||
*/
|
||||
while (! do_close) {
|
||||
XEvent event;
|
||||
XtAppNextEvent(app, &event);
|
||||
XtDispatchEvent(&event);
|
||||
}
|
||||
if ((dfile = tt_default_file()) != (char *)0) {
|
||||
tt_file_quit(dfile);
|
||||
}
|
||||
tt_close();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
write_footer(message)
|
||||
char *message;
|
||||
{
|
||||
XmString label;
|
||||
|
||||
label = XmStringCreateSimple(message);
|
||||
XtVaSetValues(edit_ui_message, XmNlabelString, label, 0);
|
||||
XmStringFree(label);
|
||||
}
|
||||
|
||||
|
||||
Tt_status
|
||||
read_file(widget, file)
|
||||
Widget widget;
|
||||
char *file;
|
||||
{
|
||||
char buf[BUFSIZ], *text;
|
||||
struct stat statb;
|
||||
int len;
|
||||
FILE *fp;
|
||||
Tt_status status;
|
||||
|
||||
/*
|
||||
* Make sure the file is a regular text file and open it.
|
||||
*/
|
||||
|
||||
if (stat(file, &statb) == -1 || (statb.st_mode & S_IFMT) != S_IFREG ||
|
||||
!(fp = fopen(file, "r"))) {
|
||||
perror(file);
|
||||
return TT_ERR_FILE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Put the contents of the file in the Text widget by allocating
|
||||
* enough space for the entire file, reading the file into the space,
|
||||
* and using XmTextSetString() to show the file.
|
||||
*/
|
||||
|
||||
strcpy(current_file, file);
|
||||
len = (int) statb.st_size;
|
||||
if (!(text = XtMalloc((unsigned)(len+1)))) {
|
||||
sprintf(buf, "%s: XtMalloc(%ld) failed", file, len);
|
||||
XmTextSetString(widget, buf);
|
||||
} else {
|
||||
if (fread(text, sizeof(char), len, fp) != len) {
|
||||
status = TT_ERR_FILE;
|
||||
} else {
|
||||
status = TT_OK;
|
||||
text[len] = 0;
|
||||
XmTextSetString(widget, text);
|
||||
}
|
||||
}
|
||||
XtFree(text);
|
||||
fclose(fp);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/* Write the contents of a text widget to a file. */
|
||||
|
||||
Tt_status
|
||||
write_file(widget, file)
|
||||
Widget widget;
|
||||
char *file;
|
||||
{
|
||||
char *text;
|
||||
int len;
|
||||
FILE *fp;
|
||||
Tt_status status;
|
||||
|
||||
if (!(fp = fopen(file, "w"))) {
|
||||
perror(file);
|
||||
return TT_ERR_FILE;
|
||||
}
|
||||
|
||||
/* Saving -- get text from the text widget. */
|
||||
|
||||
text = XmTextGetString(widget);
|
||||
len = (int) XmTextGetLastPosition(widget);
|
||||
|
||||
/* Write it to file (check for error). */
|
||||
|
||||
if (fwrite(text, sizeof(char), len, fp) != len) {
|
||||
status = TT_ERR_FILE;
|
||||
} else {
|
||||
status = TT_OK;
|
||||
}
|
||||
fclose(fp);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize our ToolTalk environment.
|
||||
*/
|
||||
int
|
||||
edit_init_tt()
|
||||
{
|
||||
int mark;
|
||||
char *procid = tt_open();
|
||||
int ttfd;
|
||||
void edit_receive_tt_message();
|
||||
|
||||
mark = tt_mark();
|
||||
|
||||
if (tt_pointer_error(procid) != TT_OK) {
|
||||
return 0;
|
||||
}
|
||||
if (tt_ptype_declare("Sun_EditDemo") != TT_OK) {
|
||||
fprintf(stderr,"Sun_EditDemo is not an installed ptype.\n");
|
||||
return 0;
|
||||
}
|
||||
ttfd = tt_fd();
|
||||
XtAppAddInput(app, ttfd, (XtPointer) XtInputReadMask,
|
||||
edit_receive_tt_message, 0);
|
||||
|
||||
tt_session_join(tt_default_session());
|
||||
|
||||
/*
|
||||
* Note that without tt_mark() and tt_release(), the above
|
||||
* combination would leak storage -- tt_default_session() returns
|
||||
* a copy owned by the application, but since we don't assign the
|
||||
* pointer to a variable we could not free it explicitly.
|
||||
*/
|
||||
|
||||
tt_release(mark);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Handle any incoming ToolTalk messages.
|
||||
*/
|
||||
void
|
||||
edit_receive_tt_message(client_data, fid, id)
|
||||
XtPointer client_data;
|
||||
int *fid;
|
||||
XtInputId *id;
|
||||
{
|
||||
Tt_message msg_in;
|
||||
int opnum;
|
||||
int opstatus;
|
||||
char *file;
|
||||
|
||||
msg_in = tt_message_receive();
|
||||
if (msg_in == NULL) return;
|
||||
if (tt_pointer_error(msg_in) == TT_ERR_NOMP) {
|
||||
fprintf(stderr,"ToolTalk server down.\n");
|
||||
exit(0);
|
||||
}
|
||||
switch (tt_message_opnum(msg_in)) {
|
||||
case SUN_EDITDEMO_EDIT:
|
||||
opstatus = edit_edit(msg_in);
|
||||
break;
|
||||
case SUN_EDITDEMO_SAVE:
|
||||
opstatus = edit_save(msg_in);
|
||||
break;
|
||||
case SUN_EDITDEMO_SAVE_AS:
|
||||
opstatus = edit_save(msg_in);
|
||||
break;
|
||||
case SUN_EDITDEMO_CLOSE:
|
||||
opstatus = edit_close(msg_in);
|
||||
break;
|
||||
case SUN_EDITDEMO_HILITE_OBJ:
|
||||
opstatus = edit_hilite_obj(msg_in);
|
||||
break;
|
||||
default:
|
||||
/* don't know what else to do with this message */
|
||||
tt_message_reject(msg_in);
|
||||
break;
|
||||
}
|
||||
if (opstatus == 0) {
|
||||
tt_message_fail(msg_in);
|
||||
} else {
|
||||
tt_message_reply(msg_in);
|
||||
}
|
||||
tt_message_destroy(msg_in);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Handle the "edit" op.
|
||||
*/
|
||||
int
|
||||
edit_edit(msg)
|
||||
Tt_message msg;
|
||||
{
|
||||
int mark = tt_mark();
|
||||
char *file = tt_message_file(msg);
|
||||
char *dfile = tt_default_file();
|
||||
char buf[255];
|
||||
|
||||
if (access(file, R_OK) != 0) {
|
||||
tt_message_status_set(msg, TT_ERR_FILE);
|
||||
tt_message_status_string_set(msg,"Can't open file for read.");
|
||||
tt_release(mark);
|
||||
return 0;
|
||||
} else {
|
||||
if (dfile == (char *)0 || 0 != strcmp(dfile, file)) {
|
||||
/* if not already editing this file, load it */
|
||||
/* in. */
|
||||
tt_default_file_set(file);
|
||||
tt_file_join(file);
|
||||
read_file(edit_ui_textpane, file);
|
||||
sprintf(buf,"Sun_EditDemo_edit: (%s)", file);
|
||||
XtVaSetValues(edit_ui_base_window,
|
||||
XmNtitle, buf, 0);
|
||||
}
|
||||
tt_release(mark);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Handle the "save" op.
|
||||
*/
|
||||
int
|
||||
edit_save(msg)
|
||||
Tt_message msg;
|
||||
{
|
||||
int mark = tt_mark();
|
||||
char *new_file;
|
||||
|
||||
if (text_modified == 0) {
|
||||
/* no save is needed */
|
||||
tt_release(mark);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (tt_message_opnum(msg) == SUN_EDITDEMO_SAVE) {
|
||||
if (write_file(edit_ui_textpane, current_file) == TT_OK) {
|
||||
text_modified = 0;
|
||||
tt_message_reply(msg);
|
||||
tt_release(mark);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
/* handle SAVE_AS */
|
||||
new_file = tt_message_arg_val(msg, 0);
|
||||
if (write_file(edit_ui_textpane, new_file) == TT_OK) {
|
||||
tt_file_quit(tt_default_file());
|
||||
tt_default_file_set(new_file);
|
||||
tt_file_join(new_file);
|
||||
read_file(edit_ui_textpane, new_file);
|
||||
tt_release(mark);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* couldn't complete operation */
|
||||
tt_message_status_set(msg, TT_ERR_FILE);
|
||||
tt_message_status_string_set(msg, "Couldn't save file");
|
||||
tt_release(mark);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Handle the "close" op.
|
||||
*/
|
||||
int
|
||||
edit_close(msg)
|
||||
Tt_message msg;
|
||||
{
|
||||
Atom wmchs;
|
||||
Window w;
|
||||
XClientMessageEvent xev;
|
||||
|
||||
if (text_modified > 0) {
|
||||
tt_message_status_set(msg, TT_ERR_FILE);
|
||||
tt_message_status_string_set(msg, "File has been modified");
|
||||
return 0;
|
||||
} else {
|
||||
do_close = 1;
|
||||
|
||||
/* Send an event to force the event loop to "click on" and quit the program. */
|
||||
|
||||
w = XtWindow(edit_ui_base_window);
|
||||
wmchs = XInternAtom(dpy, "WM_CHANGE_STATE", True);
|
||||
xev.type = ClientMessage;
|
||||
xev.message_type = wmchs;
|
||||
xev.window = w;
|
||||
xev.format = 32;
|
||||
xev.data.l[0] = IconicState;
|
||||
XSendEvent(dpy, w, True, (SubstructureRedirectMask |
|
||||
SubstructureNotifyMask), &xev) ;
|
||||
XFlush(dpy);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle the "hilite_obj" op.
|
||||
*/
|
||||
int
|
||||
edit_hilite_obj(msg)
|
||||
Tt_message msg;
|
||||
{
|
||||
int mark = tt_mark();
|
||||
char *objid = tt_message_arg_val(msg, 0);
|
||||
char obj_start_text[100];
|
||||
char obj_end_text[100];
|
||||
|
||||
if (tt_message_status(msg) == TT_WRN_START_MESSAGE
|
||||
&& edit_edit(msg) == 0) {
|
||||
/* we were started to hilite an object but couldn't load the */
|
||||
/* file into the textpane. */
|
||||
tt_release(mark);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* expect objects to be wrapped by appropiately formatted */
|
||||
/* C-style comments. */
|
||||
|
||||
sprintf(obj_start_text," /* begin_object(%s) */", objid);
|
||||
sprintf(obj_end_text," /* end_object(%s) */", objid);
|
||||
|
||||
if (select_region(edit_ui_textpane,
|
||||
obj_start_text,
|
||||
obj_end_text) == 1) {
|
||||
tt_release(mark);
|
||||
return 1;
|
||||
} else {
|
||||
tt_message_status_set(msg, TT_ERR_OBJID);
|
||||
tt_message_status_string_set(msg,"Couldn't find object");
|
||||
|
||||
tt_release(mark);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Make a ToolTalk spec out of the selected text in this textpane. Once
|
||||
* the spec is succesfully created and written to a database, wrap the
|
||||
* text with C-style comments in order to delimit the object and send out
|
||||
* a notification that an object has been created in this file.
|
||||
*/
|
||||
void
|
||||
edit_ui_make_object(widget, client_data, call_data)
|
||||
Widget widget;
|
||||
XtPointer client_data, call_data;
|
||||
{
|
||||
int mark = tt_mark();
|
||||
char *objid;
|
||||
char *file;
|
||||
char *sel;
|
||||
XmTextPosition first, last;
|
||||
char obj_start_text[100];
|
||||
char obj_end_text[100];
|
||||
Tt_message msg;
|
||||
|
||||
if (! get_selection(edit_ui_textpane, &sel, &first, &last)) {
|
||||
write_footer("First select some text");
|
||||
tt_release(mark);
|
||||
return;
|
||||
}
|
||||
file = tt_default_file();
|
||||
|
||||
if (file == (char *)0) {
|
||||
write_footer("Not editing any file");
|
||||
tt_release(mark);
|
||||
return;
|
||||
}
|
||||
|
||||
/* create a new spec */
|
||||
|
||||
objid = tt_spec_create(tt_default_file());
|
||||
if (tt_pointer_error(objid) != TT_OK) {
|
||||
write_footer("Couldn't create object");
|
||||
tt_release(mark);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* set its otype */
|
||||
|
||||
tt_spec_type_set(objid, "Sun_EditDemo_object");
|
||||
if (tt_spec_write(objid) != TT_OK) {
|
||||
write_footer("Couldn't write out object");
|
||||
tt_release(mark);
|
||||
return;
|
||||
}
|
||||
|
||||
/* wrap spec's contents (the selected text) with C-style */
|
||||
/* comments. */
|
||||
|
||||
sprintf(obj_start_text," /* begin_object(%s) */", objid);
|
||||
sprintf(obj_end_text," /* end_object(%s) */", objid);
|
||||
(void)wrap_selection(edit_ui_textpane,
|
||||
obj_start_text, obj_end_text);
|
||||
|
||||
/* now send out a notification that we've added a new object */
|
||||
|
||||
msg = tt_pnotice_create(TT_FILE_IN_SESSION,"Sun_EditDemo_new_object");
|
||||
tt_message_file_set(msg, file);
|
||||
tt_message_send(msg);
|
||||
|
||||
tt_release(mark);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Get the current selection. Returns 1 if the selection is in the passed
|
||||
* in textsw.
|
||||
*/
|
||||
int
|
||||
get_selection(widget, selection, first_ptr, last_ptr)
|
||||
Widget widget;
|
||||
char **selection;
|
||||
XmTextPosition *first_ptr, *last_ptr;
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
ptr = XmTextGetSelection(widget);
|
||||
if (ptr == NULL) return 0;
|
||||
*selection = malloc(strlen(ptr) + 1);
|
||||
if (*selection == (char *)0) {
|
||||
return -1;
|
||||
}
|
||||
(void)strcpy(*selection, ptr);
|
||||
XmTextGetSelectionPosition(widget, first_ptr, last_ptr);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
reverse_str(str)
|
||||
char *str;
|
||||
{
|
||||
char c;
|
||||
int i, n;
|
||||
|
||||
n = strlen(str);
|
||||
for (i = 0; i < n/2; i++) {
|
||||
c = str[i];
|
||||
str[i] = str[n-i];
|
||||
str[n-i] = c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
text_find_bytes(widget, first, last, str, reverse)
|
||||
Widget widget;
|
||||
XmTextPosition *first, *last;
|
||||
int reverse;
|
||||
char *str;
|
||||
{
|
||||
char *ptr, *text;
|
||||
int n;
|
||||
|
||||
text = XmTextGetString(widget);
|
||||
if (reverse) {
|
||||
reverse_str(text);
|
||||
reverse_str(str);
|
||||
}
|
||||
ptr = strstr(&text[*first], str);
|
||||
if (ptr == NULL) return -1;
|
||||
n = strlen(str);
|
||||
if (reverse) {
|
||||
*last = (XmTextPosition) ptr;
|
||||
*first = (XmTextPosition) ptr - n;
|
||||
} else {
|
||||
*first = (XmTextPosition) ptr;
|
||||
*last = (XmTextPosition) ptr + n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Selects region between "begin" and "end" in textsw. Returns 1 if
|
||||
* successful.
|
||||
*/
|
||||
int
|
||||
select_region(widget, begin, end)
|
||||
Widget widget;
|
||||
char *begin;
|
||||
char *end;
|
||||
{
|
||||
XmTextPosition bfirst, blast, efirst, elast;
|
||||
XmTextPosition inspoint;
|
||||
int status;
|
||||
|
||||
inspoint = XmTextGetInsertionPosition(widget);
|
||||
/* Find the "begin" text */
|
||||
|
||||
/* first search forward */
|
||||
bfirst = inspoint;
|
||||
status = text_find_bytes(widget, &bfirst, &blast, begin, 0);
|
||||
if (status == -1) {
|
||||
bfirst = inspoint;
|
||||
/* search failed, search backwards */
|
||||
status = text_find_bytes(widget, &bfirst, &blast, begin, 1);
|
||||
if (status == -1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the "end" text */
|
||||
|
||||
efirst = inspoint;
|
||||
/* first search forward */
|
||||
status = text_find_bytes(widget, &efirst, &elast, end, 0);
|
||||
if (status == -1) {
|
||||
efirst = inspoint;
|
||||
/* search failed, search backwards */
|
||||
status = text_find_bytes(widget, &efirst, &elast, end, 1);
|
||||
if (status == -1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
XmTextSetSelection(widget,
|
||||
(inspoint = (blast < elast) ? blast : elast),
|
||||
(efirst > bfirst) ? efirst : bfirst,
|
||||
CurrentTime);
|
||||
|
||||
XmTextSetInsertionPosition(widget, inspoint);
|
||||
XmTextShowPosition(widget, inspoint);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wraps the selected text in textsw with the begin and end strings
|
||||
* supplied. Returns 1 if successful.
|
||||
*/
|
||||
int
|
||||
wrap_selection(widget, begin, end)
|
||||
Widget widget;
|
||||
char *begin;
|
||||
char *end;
|
||||
{
|
||||
char *buf;
|
||||
char *sel;
|
||||
XmTextPosition sel_first, sel_last;
|
||||
int sel_status;
|
||||
|
||||
if (! (sel_status = get_selection(widget,
|
||||
&sel, &sel_first, &sel_last))) {
|
||||
return sel_status;
|
||||
}
|
||||
|
||||
buf = malloc(strlen(sel) + strlen(begin) + strlen(end) + 3);
|
||||
if (buf == (char *)0) {
|
||||
return -1;
|
||||
}
|
||||
sprintf(buf,"%s\n%s\n%s", begin, sel, end);
|
||||
XmTextReplace(widget, sel_first, sel_last + 1, buf);
|
||||
free(buf);
|
||||
free(sel);
|
||||
|
||||
return sel_status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Increment a flag every time this routine is called. Note that it's
|
||||
* called once, when the text is initially loaded, so the flag is initially
|
||||
* -1, to counter this.
|
||||
*/
|
||||
text_modify(widget, client_data, cbs)
|
||||
Widget widget;
|
||||
XtPointer client_data;
|
||||
XmTextVerifyCallbackStruct *cbs;
|
||||
{
|
||||
text_modified++;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize our ui environment.
|
||||
*/
|
||||
edit_ui_initialize()
|
||||
{
|
||||
Arg args[20];
|
||||
Pixmap icon;
|
||||
XmString label;
|
||||
int n, screen;
|
||||
|
||||
static unsigned short icon_bits[] = {
|
||||
0x3FFF,0xFF00,
|
||||
0x2000,0x0180,
|
||||
0x2000,0x0140,
|
||||
0x2000,0x0120,
|
||||
0x2000,0x0110,
|
||||
0x2000,0x0108,
|
||||
0x2000,0x0104,
|
||||
0x2000,0x01FE,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x2000,0x0006,
|
||||
0x3FFF,0xFFFE,
|
||||
0x1FFF,0xFFFE
|
||||
};
|
||||
|
||||
edit_ui_base_window = XtAppCreateShell(0, "base_frame",
|
||||
applicationShellWidgetClass, dpy, 0, 0 );
|
||||
screen = DefaultScreen(dpy);
|
||||
icon = XCreatePixmapFromBitmapData(dpy, RootWindow(dpy, screen),
|
||||
(char *) icon_bits, 32, 32, 1, 0, 1);
|
||||
XtVaSetValues(edit_ui_base_window,
|
||||
XmNwidth, 509,
|
||||
XmNheight, 420,
|
||||
XmNtitle, "Sun_EditDemo_edit",
|
||||
XmNiconName, "Sun_EditDemo_edit",
|
||||
XmNiconPixmap, icon,
|
||||
0);
|
||||
|
||||
edit_ui_panel = XtVaCreateManagedWidget("panel",
|
||||
xmFormWidgetClass, edit_ui_base_window, 0);
|
||||
|
||||
label = XmStringCreateSimple("Make object");
|
||||
edit_ui_obj_button = XtVaCreateManagedWidget("button",
|
||||
xmPushButtonWidgetClass, edit_ui_panel,
|
||||
XmNtopAttachment, XmATTACH_FORM,
|
||||
XmNtopOffset, 5,
|
||||
XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNleftOffset, 5,
|
||||
XmNlabelString, label,
|
||||
0);
|
||||
XmStringFree(label);
|
||||
XtAddCallback(edit_ui_obj_button,
|
||||
XmNactivateCallback, edit_ui_make_object, 0);
|
||||
|
||||
XtManageChild(edit_ui_panel);
|
||||
|
||||
n = 0;
|
||||
XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
|
||||
XtSetArg(args[n], XmNresizable, True); n++;
|
||||
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
|
||||
XtSetArg(args[n], XmNtopWidget, edit_ui_obj_button); n++;
|
||||
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNleftOffset, 5); n++;
|
||||
XtSetArg(args[n], XmNrightOffset, 5); n++;
|
||||
XtSetArg(args[n], XmNtopOffset, 5); n++;
|
||||
XtSetArg(args[n], XmNrows, 24); n++;
|
||||
XtSetArg(args[n], XmNcolumns, 80); n++;
|
||||
edit_ui_textpane = XmCreateScrolledText(edit_ui_panel, "textpane",
|
||||
args, n);
|
||||
|
||||
XtAddCallback(edit_ui_textpane, XmNmodifyVerifyCallback,
|
||||
text_modify, 0);
|
||||
edit_ui_message = XtVaCreateManagedWidget("message",
|
||||
xmLabelWidgetClass, edit_ui_panel,
|
||||
XmNtopAttachment, XmATTACH_WIDGET,
|
||||
XmNtopWidget, edit_ui_textpane,
|
||||
XmNtopOffset, 10,
|
||||
XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNleftOffset, 5,
|
||||
XmNrightAttachment, XmATTACH_FORM,
|
||||
XmNrightOffset, 5,
|
||||
XmNbottomAttachment, XmATTACH_FORM,
|
||||
XmNbottomOffset, 5,
|
||||
0);
|
||||
label = XmStringCreateSimple("");
|
||||
XtVaSetValues(edit_ui_message, XmNlabelString, label, 0);
|
||||
XmStringFree(label);
|
||||
|
||||
XtManageChild(edit_ui_textpane);
|
||||
XtRealizeWidget(edit_ui_base_window);
|
||||
}
|
||||
39
cde/lib/tt/demo/edit_demo/edit.types.model
Normal file
39
cde/lib/tt/demo/edit_demo/edit.types.model
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
*
|
||||
* edit.types
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This files shows the ptype and otype definitions used by edit.c
|
||||
*/
|
||||
#include "Sun_EditDemo_opnums.h"
|
||||
|
||||
ptype Sun_EditDemo {
|
||||
start TOOLTALK_DEMO_DIR "/edit";
|
||||
handle:
|
||||
/* edit file named in message, start editor if necessary */
|
||||
file_in_session Sun_EditDemo_edit(void)
|
||||
=> start opnum=SUN_EDITDEMO_EDIT;
|
||||
|
||||
/* tell editor viewing file in message to save file */
|
||||
file_in_session Sun_EditDemo_save(void)
|
||||
=> opnum=SUN_EDITDEMO_SAVE;
|
||||
|
||||
/* save file named in message to new filename */
|
||||
file_in_session Sun_EditDemo_save_as(in string new_filename)
|
||||
=> opnum=SUN_EDITDEMO_SAVE_AS;
|
||||
|
||||
/* bring down editor viewing file in message */
|
||||
file_in_session Sun_EditDemo_close(void)
|
||||
=> opnum=SUN_EDITDEMO_CLOSE;
|
||||
};
|
||||
|
||||
|
||||
otype Sun_EditDemo_object {
|
||||
handle:
|
||||
/* hilite object given by objid, starts an editor if necessary */
|
||||
hilite_obj(in string objid)
|
||||
=> Sun_EditDemo file_in_session start opnum=SUN_EDITDEMO_HILITE_OBJ;
|
||||
};
|
||||
1
cde/lib/tt/demo/edit_demo/edit.types.model.deps
Normal file
1
cde/lib/tt/demo/edit_demo/edit.types.model.deps
Normal file
@@ -0,0 +1 @@
|
||||
: ./Sun_EditDemo_opnums.h
|
||||
23
cde/lib/tt/demo/ttsample/Makefile
Normal file
23
cde/lib/tt/demo/ttsample/Makefile
Normal file
@@ -0,0 +1,23 @@
|
||||
# $XConsortium: Makefile /main/6 1996/05/13 12:04:22 drk $
|
||||
# %% (c) Copyright 1993, 1994 Hewlett-Packard Company
|
||||
# %% (c) Copyright 1993, 1994 International Business Machines Corp.
|
||||
# %% (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
|
||||
# %% (c) Copyright 1993, 1994 Novell, Inc.
|
||||
|
||||
OPENWINHOME=/usr/openwin
|
||||
MOTIFHOME=/usr/dt
|
||||
|
||||
CFLAGS += -g
|
||||
CPPFLAGS += -I$(MOTIFHOME)/include -I$(OPENWINHOME)/include
|
||||
LDFLAGS += -L$(MOTIFHOME)/lib -L$(OPENWINHOME)/lib
|
||||
LDLIBS += -lXm -lXt -ltt -lX11 -lgen
|
||||
|
||||
.KEEP_STATE:
|
||||
|
||||
ttsample1:
|
||||
LD_RUN_PATH=$(MOTIFHOME)/lib:$(OPENWINHOME)/lib $(LINK.c) -o $@ ttsample1.c $(LDLIBS)
|
||||
|
||||
clean:
|
||||
rm -f ttsample1
|
||||
|
||||
FRC:
|
||||
249
cde/lib/tt/demo/ttsample/ttsample1.c
Normal file
249
cde/lib/tt/demo/ttsample/ttsample1.c
Normal file
@@ -0,0 +1,249 @@
|
||||
/*%% (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: ttsample1.c /main/3 1995/10/23 09:46:53 rswiston $ */
|
||||
/*
|
||||
* ttsample1 -- dynamic pattern, procedural notification
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <Xm/Xm.h>
|
||||
#include <Xm/Label.h>
|
||||
#include <Xm/MainW.h>
|
||||
#include <Xm/Form.h>
|
||||
#include <Xm/PushB.h>
|
||||
#include <Xm/Scale.h>
|
||||
#include <Xm/MwmUtil.h>
|
||||
|
||||
#include <Tt/tt_c.h>
|
||||
|
||||
Widget toplevel, base_frame, controls, slider, gauge, button;
|
||||
char *my_procid;
|
||||
|
||||
void broadcast_value();
|
||||
void receive_tt_message();
|
||||
void create_ui_components();
|
||||
|
||||
|
||||
void
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int ttfd;
|
||||
Tt_pattern pat;
|
||||
XtAppContext app;
|
||||
|
||||
/*
|
||||
* Initialize Motif and create ui components
|
||||
*/
|
||||
toplevel = XtVaAppInitialize(&app, "ttsample1", NULL, 0,
|
||||
&argc, argv, NULL, NULL);
|
||||
XtVaSetValues(toplevel, XmNtitle, "ToolTalk Sample 1", 0);
|
||||
create_ui_components();
|
||||
|
||||
/*
|
||||
* Initialize ToolTalk, using the initial default session, and
|
||||
* obtain the file descriptor that will become active whenever
|
||||
* ToolTalk has a message for this process.
|
||||
*/
|
||||
|
||||
my_procid = tt_open();
|
||||
ttfd = tt_fd();
|
||||
|
||||
/*
|
||||
* Arrange for Motif to call receive_tt_message when the ToolTalk
|
||||
* file descriptor becomes active.
|
||||
*/
|
||||
|
||||
XtAppAddInput(app, ttfd, (XtPointer) XtInputReadMask,
|
||||
receive_tt_message, 0);
|
||||
|
||||
/*
|
||||
* Create and register a pattern so ToolTalk knows we are interested
|
||||
* in "ttsample1_value" messages within the session we join.
|
||||
*/
|
||||
|
||||
pat = tt_pattern_create();
|
||||
tt_pattern_category_set(pat, TT_OBSERVE);
|
||||
tt_pattern_scope_add(pat, TT_SESSION);
|
||||
tt_pattern_op_add(pat, "ttsample1_value");
|
||||
tt_pattern_register(pat);
|
||||
|
||||
/*
|
||||
* Join the default session
|
||||
*/
|
||||
|
||||
tt_session_join(tt_default_session());
|
||||
|
||||
/*
|
||||
* Turn control over to Motif.
|
||||
*/
|
||||
XtRealizeWidget(toplevel);
|
||||
XtAppMainLoop(app);
|
||||
|
||||
/*
|
||||
* Before leaving, allow ToolTalk to clean up.
|
||||
*/
|
||||
tt_close();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* When the button is pressed, broadcast the new slider value.
|
||||
*/
|
||||
void
|
||||
broadcast_value(widget, client_data, call_data)
|
||||
Widget widget;
|
||||
XtPointer client_data, call_data;
|
||||
{
|
||||
int slider_value;
|
||||
Tt_message msg_out;
|
||||
|
||||
/*
|
||||
* Create and send a ToolTalk notice message
|
||||
* ttsample1_value(in int <new value)
|
||||
*/
|
||||
|
||||
XtVaGetValues(slider, XmNvalue, &slider_value, 0);
|
||||
msg_out = tt_pnotice_create(TT_SESSION, "ttsample1_value");
|
||||
tt_message_arg_add(msg_out, TT_IN, "integer", NULL);
|
||||
tt_message_arg_ival_set(msg_out, 0, slider_value);
|
||||
tt_message_send(msg_out);
|
||||
|
||||
/*
|
||||
* Since this message is a notice, we don't expect a reply, so
|
||||
* there's no reason to keep a handle for the message.
|
||||
*/
|
||||
|
||||
tt_message_destroy(msg_out);
|
||||
}
|
||||
|
||||
/*
|
||||
* When a ToolTalk message is available, receive it; if it's a
|
||||
* ttsample1_value message, update the gauge with the new value.
|
||||
*/
|
||||
void
|
||||
receive_tt_message(client_data, fid, id)
|
||||
XtPointer client_data;
|
||||
int *fid;
|
||||
XtInputId *id;
|
||||
{
|
||||
Tt_message msg_in;
|
||||
int mark;
|
||||
int val_in;
|
||||
char *op;
|
||||
Tt_status err;
|
||||
|
||||
msg_in = tt_message_receive();
|
||||
|
||||
/*
|
||||
* It's possible that the file descriptor would become active
|
||||
* even though ToolTalk doesn't really have a message for us.
|
||||
* The returned message handle is NULL in this case.
|
||||
*/
|
||||
|
||||
if (msg_in == NULL) return;
|
||||
|
||||
|
||||
/*
|
||||
* Get a storage mark so we can easily free all the data
|
||||
* ToolTalk returns to us.
|
||||
*/
|
||||
|
||||
mark = tt_mark();
|
||||
|
||||
op = tt_message_op(msg_in);
|
||||
err = tt_ptr_error(op);
|
||||
if (err > TT_WRN_LAST) {
|
||||
printf( "tt_message_op(): %s\n", tt_status_message(err));
|
||||
} else if (op != 0) {
|
||||
if (0==strcmp("ttsample1_value", tt_message_op(msg_in))) {
|
||||
tt_message_arg_ival(msg_in, 0, &val_in);
|
||||
XtVaSetValues(gauge, XmNvalue, val_in, 0);
|
||||
}
|
||||
}
|
||||
|
||||
tt_message_destroy(msg_in);
|
||||
tt_release(mark);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Straight Motif calls for creating the ui elements. No
|
||||
* ToolTalk-specific code here.
|
||||
*/
|
||||
void
|
||||
create_ui_components()
|
||||
{
|
||||
int decor;
|
||||
Widget glabel, slabel;
|
||||
XmString label;
|
||||
|
||||
base_frame = XtVaCreateManagedWidget("base_frame",
|
||||
xmMainWindowWidgetClass, toplevel,
|
||||
XmNwidth, 269,
|
||||
XmNheight, 104,
|
||||
0);
|
||||
XtVaGetValues(base_frame, XmNmwmDecorations, &decor, 0);
|
||||
decor &= ~MWM_DECOR_RESIZEH;
|
||||
XtVaSetValues(base_frame, XmNmwmDecorations, &decor, 0);
|
||||
|
||||
controls = XtVaCreateManagedWidget("controls",
|
||||
xmFormWidgetClass, base_frame, NULL, 0, 0);
|
||||
|
||||
slabel = XtVaCreateManagedWidget("Send:",
|
||||
xmLabelWidgetClass, controls,
|
||||
XmNx, 51,
|
||||
XmNy, 16,
|
||||
0);
|
||||
slider = XtVaCreateManagedWidget("slider",
|
||||
xmScaleWidgetClass, controls,
|
||||
XmNleftAttachment, XmATTACH_WIDGET,
|
||||
XmNleftWidget, slabel,
|
||||
XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
|
||||
XmNtopWidget, slabel,
|
||||
XmNscaleWidth, 120,
|
||||
XmNscaleHeight, 18,
|
||||
XmNminimum, 0,
|
||||
XmNmaximum, 100,
|
||||
XmNorientation, XmHORIZONTAL,
|
||||
0);
|
||||
|
||||
glabel = XtVaCreateManagedWidget("Received:",
|
||||
xmLabelWidgetClass, controls,
|
||||
XmNx, 23,
|
||||
XmNy, 42,
|
||||
0);
|
||||
gauge = XtVaCreateManagedWidget("gauge",
|
||||
xmScaleWidgetClass, controls,
|
||||
XmNleftAttachment, XmATTACH_WIDGET,
|
||||
XmNleftWidget, glabel,
|
||||
XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
|
||||
XmNtopWidget, glabel,
|
||||
XmNorientation, XmHORIZONTAL,
|
||||
XmNscaleWidth, 125,
|
||||
XmNscaleHeight, 18,
|
||||
XmNminimum, 0,
|
||||
XmNmaximum, 100,
|
||||
XmNshowValue, TRUE,
|
||||
0);
|
||||
|
||||
label = XmStringCreateSimple("Broadcast");
|
||||
button = XtVaCreateManagedWidget("button",
|
||||
xmPushButtonWidgetClass, controls,
|
||||
XmNx, 96,
|
||||
XmNy, 78,
|
||||
XmNwidth, 76,
|
||||
XmNheight, 19,
|
||||
XmNlabelString, label,
|
||||
0);
|
||||
XmStringFree(label);
|
||||
XtAddCallback(button, XmNactivateCallback, broadcast_value, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user