/*** DTB_USER_CODE_START vvv Add file header below vvv ***/
//%%  (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: ttsnoop_stubs.C.src /main/3 1995/11/06 17:14:48 rswiston $
/*** DTB_USER_CODE_END   ^^^ Add file header above ^^^ ***/

/*
 * File: ttsnoop_stubs.c
 * Contains: Module callbacks and connection functions
 *
 * This file was generated by dtcodegen, from module ttsnoop
 *
 * Any text may be added between the DTB_USER_CODE_START and
 * DTB_USER_CODE_END comments (even non-C code). Descriptive comments
 * are provided only as an aid.
 *
 *  ** EDIT ONLY WITHIN SECTIONS MARKED WITH DTB_USER_CODE COMMENTS.  **
 *  ** ALL OTHER MODIFICATIONS WILL BE OVERWRITTEN. DO NOT MODIFY OR  **
 *  ** DELETE THE GENERATED COMMENTS!                                 **
 */

#include <stdio.h>
#include <Xm/Xm.h>
#include "dtb_utils.h"
#include "ttsnoop_ui.h"


/**************************************************************************
 *** DTB_USER_CODE_START
 ***
 *** All necessary header files have been included.
 ***
 *** Add include files, types, macros, externs, and user functions here.
 ***/

#include <unistd.h>

#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
#include <fstream>
#include <strstream>
#else
#include <fstream.h>
#include <strstream.h>
#endif

#include "apiTracer_ui.h"
#include "DtTt.h"

extern "C" { const char *_tt_lib_version; };

extern std::ofstream	snoopStream;
extern unsigned int	globalSaveLines;
extern char *		traceScript;
extern const char *	globalVersionString;
extern Tt_pattern	snoopPat;
extern Boolean		snoopPatIsRegistered;

/*** DTB_USER_CODE_END
 ***
 *** End of user code section
 ***
 **************************************************************************/



void 
ttsnoop_Help_menu_On_Item_item_CB1(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    dtb_do_onitem_help();
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fork_tttrace(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    std::ostrstream tttraceCmd;
    tttraceCmd << "unset TT_TRACE_SCRIPT; dtterm -sb -sl ";
    tttraceCmd << globalSaveLines;
    tttraceCmd << " -title tttrace -geometry 120x24 -e tttrace &";
    DtTtSetLabel( instance->ttsnoopWin_label, "tttrace" );
    system( tttraceCmd.str() );
    delete tttraceCmd.str();
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
turnOnTracing(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbApiTracerTracerInfo instance = &dtb_api_tracer_tracer;
    if (!(instance->initialized))
    {
        dtb_api_tracer_tracer_initialize(
		instance, dtb_ttsnoop_ttsnoop_win.ttsnoopWin);
    }
    DtTtSetLabel( instance->cancelButton, "Stop" );
    XtManageChild(instance->tracer_shellform);
    tt_trace_control( 0 );
    putenv( traceScript );
    tt_trace_control( 1 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
createMessage(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    Tt_message msg = tt_message_create();
    Tt_status status = DtTtSetLabel( instance->ttsnoopWin_label,
				     "tt_message_create()", msg );
    if (tt_is_err( status )) {
	    return;
    }
    DtTtCreated( DTTT_MESSAGE, msg );
    Widget newWidget = DtTtMessageWidgetCreate( instance->ttsnoopWin, msg,
					        DtTtMessageWidgetUpdate );
    status = tt_ptr_error( newWidget );
    if (tt_is_err( status )) {
	    return;
    }
    XRaiseWindow( XtDisplay( newWidget ), XtWindow( newWidget ));
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
receiveMessage(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    Tt_message msg = tt_message_receive();
    Tt_status status = DtTtSetLabel( instance->ttsnoopWin_label,
				     "tt_message_receive()", msg );
    if (tt_is_err( status )) {
	    return;
    }
    if (msg == 0) {
	    return;
    }
    DtTtCreated( DTTT_MESSAGE, msg );
    Widget newWidget = DtTtMessageWidgetCreate( instance->ttsnoopWin, msg,
					        DtTtMessageWidgetUpdate );
    status = tt_ptr_error( newWidget );
    if (tt_is_err( status )) {
	    return;
    }
    XRaiseWindow( XtDisplay( newWidget ), XtWindow( newWidget ));
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
openMessage(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserMessageOpen );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
destroyMessage(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserMessageDestroy );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
help_ttsnoop(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    _DtMan( instance->ttsnoopWin_label, "ttsnoop" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
help_tttrace(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    _DtMan( instance->ttsnoopWin_label, "tttrace" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
help_ttsession(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    _DtMan( instance->ttsnoopWin_label, "ttsession" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
help_tt_type_comp(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    _DtMan( instance->ttsnoopWin_label, "tt_type_comp" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
help_dbserver(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    _DtMan( instance->ttsnoopWin_label, "rpc.ttdbserverd" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
help_tttracefile(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    _DtMan( instance->ttsnoopWin_label, "tttracefile" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
help_tt_c(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    _DtMan( instance->ttsnoopWin_label, "Tttt_c" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
help_tttk(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    _DtMan( instance->ttsnoopWin_label, "Tttttk" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
helpUsenet(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    char *buf = "news:alt.soft-sys.tooltalk";
    _DtOpen( instance->ttsnoopWin_label, buf, strlen(buf), "altTT" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
sessionTypesLoad(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtFileChooserSet( _DtFileChooseTypesLoad, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
sessionTypesReload(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    Tt_message msg = ttdt_file_notice( 0, TTDT_SAVED, TT_BOTH,
				       "/etc/tt/types.xdr", 0 );
    Tt_status status = DtTtSetLabel( instance->ttsnoopWin_label,
				     "ttdt_file_notice()", msg );
    if (tt_is_err( status )) {
	    return;
    }
    status = tt_message_send( msg );
    if (tt_is_err( status )) {
	    DtTtSetLabel( instance->ttsnoopWin_label, "tt_message_send()",
			  status );
    }
    DtTtCreated( DTTT_MESSAGE, msg );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
dumpSource(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    _DtOpen( instance->ttsnoopWin_label, "tt_type_comp -p", "types" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
typesEnumerate(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    _DtOpen( instance->ttsnoopWin_label, "tt_type_comp -P", "types" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
createPattern(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    Tt_pattern pat = tt_pattern_create();
    Tt_status status = DtTtSetLabel( instance->ttsnoopWin_label,
				     "tt_pattern_create()", pat );
    if (tt_is_err( status )) {
	    return;
    }
    DtTtCreated( DTTT_PATTERN, pat );
    Widget newWidget = DtTtPatternWidgetCreate( instance->ttsnoopWin, pat, 0 );
    status = tt_ptr_error( newWidget );
    if (tt_is_err( status )) {
	    return;
    }
    XRaiseWindow( XtDisplay( newWidget ), XtWindow( newWidget ));
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
openPattern(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserPatternOpen );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
destroyPattern(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserPatternDestroy );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
ptypeDeclare(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtStringChooserSet( _DtStringChoosePtype2Declare, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
mediaPtypeDeclare(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtStringChooserSet( _DtStringChooseMediaPtype2Declare, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
ptypeUnDeclare(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtStringChooserSet( _DtStringChoosePtype2UnDeclare, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
ptypeSetDefault(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtStringChooserSet( _DtStringChoosePtype2SetDefault, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
ptypeExists(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtStringChooserSet( _DtStringChoosePtype2Exists, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
libcSystem(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtStringChooserSet( _DtStringChooseSystem, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
libcChdir(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtFileChooserSet( _DtFileChooseChdir, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
libcPutenv(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtStringChooserSet( _DtStringChoosePutenv, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
libcPause(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    std::ostrstream advice;
    advice << "pause(); /* kill -CONT " << getpid() << " */";
    DtTtSetLabel( instance->ttsnoopWin_label, advice.str() );
    delete advice.str();

    //
    // run "(if dterror.ds blah blah; then kill -CONT pid; fi)&"
    //
    std::ostrstream script;
    script << "(if dterror.ds ";
    // arg 1: text
    script << "\"kill -CONT " << getpid() << "\" ";
    // arg 2: window title
    script << "\"pause()\" ";
    // arg 3: confirmation button label
    script << "CONT; then ";
    // After confirmation, invoke kill(1)
    script << "kill -CONT " << getpid() << "; fi)&";
    system( script.str() );
    delete script.str();

    // Run the event loop a few laps, to paint the footer
    tttk_block_while( XtWidgetToApplicationContext( widget ), 0, 50 );

    pause();
    DtTtSetLabel( instance->ttsnoopWin_label, " " );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
libcExit(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    exit( 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
msgActions(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    _DtOpen( instance->ttsnoopWin_label,
	     "dttypes -db ACTION -w fld_name TYPE fld_value TT_MSG", "actns" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
sessionJoin(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtSessionChooserSet( _DtSessionChooseJoin, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
dtSessionJoin(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtSessionChooserSet( _DtSessionChooseDtJoin, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
sessionQuit(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtSessionChooserSet( _DtSessionChooseQuit, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
sessionSetDefault(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtSessionChooserSet( _DtSessionChooseDefault, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileJoin(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtFileChooserSet( _DtFileChooseJoin, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileDesktopJoin(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtFileChooserSet( _DtFileChooseDtJoin, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileQuit(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtFileChooserSet( _DtFileChooseQuit, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileSetDefault(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtFileChooserSet( _DtFileChooseDefault, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileUnSetDefault(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    Tt_status status = tt_default_file_set( 0 );
    DtTtSetLabel( instance->ttsnoopWin_label, "tt_default_file_set( 0 )",
		  status );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileSaved(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserDtFileSaved );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileModified(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserDtFileModified );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileReverted(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserDtFileReverted );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileGetModified(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtFileChooserSet( _DtFileChooseGetModified, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileSave(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtFileChooserSet( _DtFileChooseSave, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileRevert(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtFileChooserSet( _DtFileChooseRevert, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileNetfile(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtFileChooserSet( _DtFileChooseNetfile, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
netfileFile(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtStringChooserSet( _DtStringChooseNetfile2File, 0 );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileDesktopQuit(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserDtFileQuit );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileMoved(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserDtFileMoved );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileDeleted(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserDtFileDeleted );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
dtSessionQuit(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserDtSessionQuit );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
procidOpen(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    char *procid = tt_open();
    Widget label = instance->ttsnoopWin_label;
    DtTtSetLabel( label, "tt_open()", procid );
    int fd = tt_fd();
    Tt_status status = tt_int_error( fd );
    if (tt_is_err( status )) {
	    DtTtSetLabel( instance->ttsnoopWin_label, "tt_fd()", status );
	    return;
    }
    XtInputId id = XtAppAddInput( XtWidgetToApplicationContext( label ),
				  fd, (XtPointer)XtInputReadMask,
				  tttk_Xt_input_handler, procid );
    DtTtCreated( DTTT_PROCID, procid, (void *)id );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
procidClose(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    char *procid = tt_default_procid();
    Tt_status status = DtTtSetLabel( instance->ttsnoopWin_label,
				     "tt_default_procid()", procid );
    if (tt_is_err( status )) {
	    return;
    }
    status = tt_close();
    DtTtSetLabel( instance->ttsnoopWin_label, "tt_close()", status );
    int nth = DtTtIndex( DTTT_PROCID, procid );
    if (nth < 0) {
	    return;
    }
    XtInputId id = (XtInputId)DtTtNthClientDatum( DTTT_PROCID, nth );
    if (id != 0) {
	    XtRemoveInput( id );
    }
    DtTtDestroyed( DTTT_PROCID, procid );
    tt_free( procid );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
procidSetDefault(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserProcidSetDefault );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
procidSuspend(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserProcidSuspend );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
procidResume(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserProcidResume );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
procidDtOpen(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    int fd;
    char *procid = ttdt_open( &fd, "Ttsnoop", "CDE", globalVersionString, 1 );
    Widget label = instance->ttsnoopWin_label;
    DtTtSetLabel( label, "ttdt_open()", procid );
    if (! tt_is_err( tt_ptr_error( procid ) )) {
	    XtInputId id;
	    id = XtAppAddInput( XtWidgetToApplicationContext( label ),
				fd, (XtPointer)XtInputReadMask,
				tttk_Xt_input_handler, procid );
	    DtTtCreated( DTTT_PROCID, procid, (void *)id );
    }
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
procidDtClose(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserDtProcidClose );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
procidDefault(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    char *val = tt_default_procid();
    snoopStream << "tt_default_procid() = " << (void *)val;
    if (tt_is_err( tt_ptr_error( val ))) {
	    snoopStream << tt_ptr_error( val );
    } else if (val != 0) {
	    snoopStream << val;
    }
    snoopStream << endl;
    tt_free( val );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
ptypeDefault(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    char *val = tt_default_ptype();
    snoopStream << "tt_default_ptype() = " << (void *)val;
    if (tt_is_err( tt_ptr_error( val ))) {
	    snoopStream << tt_ptr_error( val );
    } else if (val != 0) {
	    snoopStream << val;
    }
    snoopStream << endl;
    tt_free( val );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
sessionDefault(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    char *val = tt_default_session();
    snoopStream << "tt_default_session() = " << (void *)val;
    if (tt_is_err( tt_ptr_error( val ))) {
	    snoopStream << tt_ptr_error( val );
    } else if (val != 0) {
	    snoopStream << val;
    }
    snoopStream << endl;
    tt_free( val );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
fileDefault(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    char *val = tt_default_file();
    snoopStream << "tt_default_file() = " << (void *)val;
    if (tt_is_err( tt_ptr_error( val ))) {
	    snoopStream << tt_ptr_error( val );
    } else if (val != 0) {
	    snoopStream << val;
    }
    snoopStream << endl;
    tt_free( val );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
toggleSnooping(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
    if (snoopPat == 0) {
	    DtTtSetLabel( instance->ttsnoopWin_label, "Tt_pattern == 0" );
	    XtSetSensitive(
		instance->menubar_Snoop_item_Snoop_menu_items.Off_item,
		False );
	    return;
    }
    Tt_status status;
    char *func;
    if (snoopPatIsRegistered) {
	    status = tt_pattern_unregister( snoopPat );
	    func = "tt_pattern_unregister(";
    } else {
	    status = tt_pattern_register( snoopPat );
	    func = "tt_pattern_register(";
    }
    if (! tt_is_err( status )) {
	    snoopPatIsRegistered = ! snoopPatIsRegistered;
    }
    std::ostrstream stream;
    stream << func << (void *)snoopPat << ")" << ends;
    DtTtSetLabel( instance->ttsnoopWin_label, stream.str(), status );
    delete stream.str();
    DtTtSetLabel( instance->menubar_Snoop_item_Snoop_menu_items.Off_item,
		  snoopPatIsRegistered ? "Off" : "On" );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
printVersion(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    snoopStream << "ttsnoop: " << globalVersionString << endl;
    snoopStream << "tt_c.h: " << TT_VERSION << endl;
    snoopStream << "libtt: " << _tt_lib_version << endl;
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}


void 
createStandardMessage(
    Widget widget,
    XtPointer clientData,
    XtPointer callData
)
{
    /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
    /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
    
    /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
    _DtTtChooserSet( _DtTtChooserMessageCreateStandard );
    /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
}



/**************************************************************************
 *** DTB_USER_CODE_START
 ***
 *** All automatically-generated data and functions have been defined.
 ***
 *** Add new functions here, or at the top of the file.
 ***/

/*** DTB_USER_CODE_END
 ***
 *** End of user code section
 ***
 **************************************************************************/


