1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

ttsnoop: drag into a modern C++ century

This program has never worked very well, and it may still not work
very well.  This commit removes the ancient C++ headers and uses
modern replacements with some changes required due to the different
interfaces.

It builds a lot cleaner, and no longer does stupid things like
deleteing char *, ostream.str()'s, and the like.

This program could be really useful if it worked well. Some thought
should be givien in the future to decouple this SW from dtappbuilder
and maybe just rewrite from scratch.
This commit is contained in:
Jon Trulson 2018-06-29 13:25:00 -06:00
parent 780ec11b8a
commit af6c2fd881
10 changed files with 72 additions and 145 deletions

View file

@ -34,11 +34,7 @@
#include <fcntl.h>
#include <unistd.h>
#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
#include <strstream>
#else
#include <strstream.h>
#endif
#include <sstream>
#include <Xm/TextF.h>
#include <Dt/SpinBox.h>
@ -468,11 +464,10 @@ DtTtSetLabel(
)
{
Tt_status status = tt_ptr_error( val );
std::ostrstream errStream;
std::ostringstream errStream;
errStream << func << " = " << val << " (" << status << ")" << ends;
char *label = errStream.str();
const char *label = errStream.str().c_str();
DtTtSetLabel( labelWidget, label );
delete label;
return status;
}
@ -483,11 +478,10 @@ DtTtSetLabel(
Tt_status status
)
{
std::ostrstream errStream;
std::ostringstream errStream;
errStream << func << " = " << status << ends;
char *label = errStream.str();
const char *label = errStream.str().c_str();
DtTtSetLabel( labelWidget, label );
delete label;
return status;
}
@ -498,11 +492,10 @@ DtTtSetLabel(
int returnVal
)
{
std::ostrstream errStream;
std::ostringstream errStream;
errStream << func << " = " << returnVal << ends;
char *label = errStream.str();
const char *label = errStream.str().c_str();
DtTtSetLabel( labelWidget, label );
delete label;
return returnVal;
}
@ -519,7 +512,7 @@ _DtTtChoices(
return 0;
}
for (int i = 0; i < count; i++) {
std::ostrstream itemStream;
std::ostringstream itemStream;
itemStream << (void *)pPats[ i ];
char *name = (char *)
tt_pattern_user( *pPats[ i ], _DtTtPatsNameKey );
@ -528,9 +521,8 @@ _DtTtChoices(
tt_free( name );
}
itemStream << ends;
char *string = itemStream.str();
char *string = const_cast<char *>(itemStream.str().c_str());
items[ i ] = XmStringCreateLocalized( string );
delete string;
}
return items;
}
@ -566,7 +558,7 @@ _DtTtChoices(
}
*itemCount = dtTtMessagesCount;
for (i = 0; i < dtTtMessagesCount; i++) {
std::ostrstream itemStream;
std::ostringstream itemStream;
itemStream << (void *)dtTtMessages[ i ];
char *op = tt_message_op( dtTtMessages[ i ] );
if (! tt_is_err( tt_ptr_error( op ))) {
@ -579,9 +571,8 @@ _DtTtChoices(
tt_free( id );
}
itemStream << ends;
char *string = itemStream.str();
char *string = const_cast<char *>(itemStream.str().c_str());
items[ i ] = XmStringCreateLocalized( string );
delete string;
}
return items;
case DTTT_PATTERN:
@ -592,11 +583,10 @@ _DtTtChoices(
}
*itemCount = dtTtPatternsCount;
for (i = 0; i < dtTtPatternsCount; i++) {
std::ostrstream itemStream;
std::ostringstream itemStream;
itemStream << (void *)dtTtPatterns[ i ] << ends;
items[ i ] = XmStringCreateLocalized(
itemStream.str() );
delete itemStream.str();
const_cast<char *>(itemStream.str().c_str()) );
}
return items;
case DTTT_DTSESSION:
@ -636,23 +626,19 @@ _DtOpen(
)
{
char *file = tempnam( 0, AIX_CONST_STRING tempnamTemplate );
std::ostrstream cmdStream;
std::ostringstream cmdStream;
cmdStream << cmd << " > " << file << ends;
int sysStat = system( cmdStream.str() );
int sysStat = system( cmdStream.str().c_str() );
if (! WIFEXITED( sysStat )) {
std::ostrstream func;
std::ostringstream func;
func << "system( \"" << cmdStream.str() << "\" )" << ends;
DtTtSetLabel( label, func.str(), sysStat );
delete cmdStream.str();
delete func.str();
DtTtSetLabel( label, func.str().c_str(), sysStat );
return;
}
if (WEXITSTATUS( sysStat ) != 0) {
DtTtSetLabel( label, cmdStream.str(), WEXITSTATUS( sysStat ));
delete cmdStream.str();
DtTtSetLabel( label, cmdStream.str().c_str(), WEXITSTATUS( sysStat ));
return;
}
delete cmdStream.str();
_DtOpen( label, file );
}
@ -662,17 +648,15 @@ _DtOpen(
const char * file
)
{
std::ostrstream labelStream;
std::ostringstream labelStream;
labelStream << "dtaction Open " << file << ends;
DtTtSetLabel( label, labelStream.str() );
delete labelStream.str();
DtTtSetLabel( label, labelStream.str().c_str() );
std::ostrstream cmd;
std::ostringstream cmd;
cmd << "( unset TT_TRACE_SCRIPT; if dtaction Open " << file
<< "; then :; else textedit " << file << "; fi; sleep 600; rm -f "
<< file << " ) &" << ends;
system( cmd.str() );
delete cmd.str();
system( cmd.str().c_str() );
}
void
@ -699,16 +683,14 @@ _DtMan(
const char * topic
)
{
std::ostrstream labelStream;
std::ostringstream labelStream;
labelStream << "dtaction Dtmanpageview " << topic << ends;
DtTtSetLabel( label, labelStream.str() );
delete labelStream.str();
DtTtSetLabel( label, labelStream.str().c_str() );
std::ostrstream cmd;
std::ostringstream cmd;
cmd << "unset TT_TRACE_SCRIPT; if dtaction Dtmanpageview " << topic
<< "; then :; else cmdtool -c man " << topic << "; fi &" << ends;
system( cmd.str() );
delete cmd.str();
system( cmd.str().c_str() );
}
Boolean

View file

@ -41,13 +41,8 @@
*** Add include files, types, macros, externs, and user functions here.
***/
#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
#include <fstream>
#include <strstream>
#else
#include <fstream.h>
#include <strstream.h>
#endif
#include <sstream>
#include "DtTt.h"

View file

@ -39,13 +39,8 @@
#include <sys/wait.h>
#include <Xm/TextF.h>
#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
#include <fstream>
#include <strstream>
#else
#include <fstream.h>
#include <strstream.h>
#endif
#include <sstream>
#include "DtTt.h"
#include "ttsnoop_ui.h"
@ -217,7 +212,7 @@ fileOkayed(
XtVaGetValues( instance->fchooser, XmNuserData, &xtPtr, NULL );
FileChooserInfo *info = (FileChooserInfo *)xtPtr;
Widget label = dtb_ttsnoop_ttsnoop_win.ttsnoopWin_label;
std::ostrstream script;
std::ostringstream script;
switch (info->choice) {
Tt_pattern *pats;
Tt_message msg;
@ -297,19 +292,17 @@ fileOkayed(
script << "numChars=`tt_type_comp -p \"" << path;
script << "\" | wc -c`; if [ $numChars = 0 ]; "
"then exit 1; else exit 0; fi" << endl;
ival = system( script.str() );
delete script.str();
ival = system( script.str().c_str() );
if (! WIFEXITED( ival )) {
DtTtSetLabel( label,
"system( \"tt_type_comp -p\" )", ival );
break;
}
if (WEXITSTATUS( ival ) != 0) {
std::ostrstream diagnosis;
std::ostringstream diagnosis;
diagnosis << "tt_type_comp -p: syntax error in "
<< path << ends;
DtTtSetLabel( label, diagnosis.str() );
delete diagnosis.str();
DtTtSetLabel( label, diagnosis.str().c_str() );
break;
}
sess = tt_default_session();

View file

@ -41,11 +41,7 @@
*** Add include files, types, macros, externs, and user functions here.
***/
#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
#include <strstream>
#else
#include <strstream.h>
#endif
#include <sstream>
#include <Xm/TextF.h>
#include <Dt/SpinBox.h>
@ -621,12 +617,11 @@ DtTtMessageWidgetCreate(
}
}
std::ostrstream labelStream;
std::ostringstream labelStream;
labelStream << "Tt_message " << (void *)msg;
XtVaSetValues( instance->messageProps,
XmNtitle, labelStream.str(),
XmNtitle, labelStream.str().c_str(),
NULL );
delete labelStream.str();
_DtTtMessageWidgetUpdate( instance, msg, _DtTtMessageFullUpdate );
@ -1409,7 +1404,7 @@ msgGenAction(
/*** DTB_USER_CODE_END ^^^ Add C variables and code above ^^^ ***/
/*** DTB_USER_CODE_START vvv Add C code below vvv ***/
std::ostrstream action; // XXX when to delete .str()?
std::ostringstream action;
DtbMessagePropsMessagePropsInfo instance =
(DtbMessagePropsMessagePropsInfo)clientData;
Tt_message msg = messageProps2Msg( instance );
@ -1457,10 +1452,9 @@ msgGenAction(
}
// XXX emit commented warnings for e.g. TT_OFFER, TT_HANDLER
action << "}\n";
// XtVaSetValues( instance->messageText, XmNvalue, action.str(), 0 );
_DtOpen( instance->messageFooterLabel, (void *)action.str(),
action.pcount(), "actio" );
delete action.str();
// XtVaSetValues( instance->messageText, XmNvalue, action.str().c_str(), 0 );
_DtOpen( instance->messageFooterLabel, (void *)action.str().c_str(),
action.str().size(), "actio" );
/*** DTB_USER_CODE_END ^^^ Add C code above ^^^ ***/
}
@ -1476,7 +1470,7 @@ msgGenC(
/*** DTB_USER_CODE_END ^^^ Add C variables and code above ^^^ ***/
/*** DTB_USER_CODE_START vvv Add C code below vvv ***/
std::ostrstream code; // XXX when to delete .str()?
std::ostringstream code;
DtbMessagePropsMessagePropsInfo instance =
(DtbMessagePropsMessagePropsInfo)clientData;
Tt_message msg = messageProps2Msg( instance );
@ -1602,10 +1596,9 @@ msgGenC(
code << "}\n";
}
tt_free( op );
// XtVaSetValues( instance->messageText, XmNvalue, code.str(), 0 );
_DtOpen( instance->messageFooterLabel, (void *)code.str(),
code.pcount(), "msgC" );
delete code.str();
// XtVaSetValues( instance->messageText, XmNvalue, code.str().c_str(), 0 );
_DtOpen( instance->messageFooterLabel, (void *)code.str().c_str(),
code.str().size(), "msgC" );
/*** DTB_USER_CODE_END ^^^ Add C code above ^^^ ***/
}
@ -1879,7 +1872,7 @@ genObserver(
/*** DTB_USER_CODE_END ^^^ Add C variables and code above ^^^ ***/
/*** DTB_USER_CODE_START vvv Add C code below vvv ***/
std::ostrstream ptype; // XXX when to delete .str()?
std::ostringstream ptype;
DtbMessagePropsMessagePropsInfo instance =
(DtbMessagePropsMessagePropsInfo)clientData;
Tt_message msg = messageProps2Msg( instance );
@ -1941,10 +1934,9 @@ genObserver(
ptype << "\t\t\t) => start opnum=1;\n";
ptype << "};\n";
// XXX contexts
// XtVaSetValues( instance->messageText, XmNvalue, ptype.str(), 0 );
_DtOpen( instance->messageFooterLabel, (void *)ptype.str(),
ptype.pcount(), "ptype" );
delete ptype.str();
// XtVaSetValues( instance->messageText, XmNvalue, ptype.str().c_str(), 0 );
_DtOpen( instance->messageFooterLabel, (void *)ptype.str().c_str(),
ptype.str().size(), "ptype" );
/*** DTB_USER_CODE_END ^^^ Add C code above ^^^ ***/
}

View file

@ -41,11 +41,7 @@
*** Add include files, types, macros, externs, and user functions here.
***/
#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
#include <strstream>
#else
#include <strstream.h>
#endif
#include <sstream>
#include <Tt/tttk.h>
#include "DtTt.h"
@ -372,12 +368,11 @@ DtTtPatternWidgetCreate(
}
}
std::ostrstream labelStream;
std::ostringstream labelStream;
labelStream << "Tt_pattern " << (void *)pat << ends;
XtVaSetValues( instance->patternProps,
XmNtitle, labelStream.str(),
XmNtitle, labelStream.str().c_str(),
NULL );
delete labelStream.str();
_DtTtPatternWidgetUpdate( instance, pat );

View file

@ -42,13 +42,8 @@
#include <Xm/TextF.h>
#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
#include <fstream>
#include <strstream>
#else
#include <fstream.h>
#include <strstream.h>
#endif
#include <sstream>
#include "DtTt.h"

View file

@ -42,11 +42,7 @@
#include <Xm/TextF.h>
#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
#include <fstream>
#else
#include <fstream.h>
#endif
#include "DtTt.h"

View file

@ -43,11 +43,7 @@
#include <stdio.h>
#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
#include <strstream>
#else
#include <strstream.h>
#endif
#include <sstream>
#include <Xm/TextF.h>
#include <Xm/List.h>
@ -214,12 +210,11 @@ _DtTtChooserSet(
XmTextFieldSetString( instance->chooserText, 0 );
XtVaSetValues( instance->chooser, XmNtitle, title, NULL );
std::ostrstream valuesStream;
std::ostringstream valuesStream;
valuesStream << itemCount << " " << valuesLabel;
if (itemCount != 1) valuesStream << "s";
valuesStream << ends;
DtTtSetLabel( instance->chooserList_label, valuesStream.str() );
delete valuesStream.str();
DtTtSetLabel( instance->chooserList_label, valuesStream.str().c_str() );
// Remember dialog mode, entity
XtVaSetValues( instance->chooserOkButton, XmNuserData, choice, NULL );
@ -315,14 +310,13 @@ choiceSelected(
break;
}
void *entity = DtTtNth( type, info->item_position - 1 );
std::ostrstream entityName;
std::ostringstream entityName;
if (isString) {
entityName << (char *)entity << ends;
} else {
entityName << entity << ends;
}
XmTextFieldSetString( instance->chooserText, entityName.str() );
delete entityName.str();
XmTextFieldSetString( instance->chooserText, const_cast<char *>(entityName.str().c_str()) );
/*** DTB_USER_CODE_END ^^^ Add C code above ^^^ ***/
}

View file

@ -63,15 +63,9 @@
#include <sys/stat.h>
#include <time.h>
#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
#include <iostream>
#include <strstream>
#include <sstream>
#include <fstream>
#else
#include <iostream.h>
#include <strstream.h>
#include <fstream.h>
#endif
#include <Dt/Term.h>
#include <Tt/tt_c.h>
@ -95,7 +89,7 @@ char * snoopFile = 0;
Boolean unlinkSnoopFile = True;
char * traceFile = 0;
Boolean unlinkTraceFile = True;
char * traceScript = 0;
const char * traceScript = 0;
int globalTimeout = 20000;
unsigned int globalSaveLines = 5000;
const char * globalVersionString = "1.0";
@ -112,7 +106,7 @@ unsigned int snoopedArgsCount = 0;
char * optTraceScript = 0;
String apiTracerArgv[ 10 ];
String snooperArgv[ 10 ];
std::ostrstream tttraceCmd;
std::ostringstream tttraceCmd;
std::ofstream snoopStream;
// Xt squats on -tf ?! XXX
@ -188,7 +182,7 @@ signalHandler(
if ((child > 0) && WIFEXITED( status )) {
snoopStream << endl << endl << "SIGCHLD: WEXITSTATUS=="
<< WEXITSTATUS(status) << ": "
<< tttraceCmd.str() << endl << endl;
<< tttraceCmd.str().c_str() << endl << endl;
}
break;
case SIGCONT:
@ -666,14 +660,14 @@ main(int argc, char **argv)
installSignalHandler();
if (snoopedArgsCount > 0) {
DtTtSetLabel( dtb_ttsnoop_ttsnoop_win.ttsnoopWin_label,
tttraceCmd.str() );
tttraceCmd.str().c_str() );
}
Tt_status status;
snoopStream.open( snoopFile, ios::app );
std::ostrstream envStr;
std::ostringstream envStr;
envStr << "TT_TRACE_SCRIPT=> ";
envStr << traceFile << ends;
traceScript = envStr.str();
traceScript = envStr.str().c_str();
if (optImmediateTracing) {
turnOnTracing( 0, 0, 0 );
}

View file

@ -37,13 +37,8 @@
#include <unistd.h>
#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
#include <fstream>
#include <strstream>
#else
#include <fstream.h>
#include <strstream.h>
#endif
#include <sstream>
#include "apiTracer_ui.h"
#include "DtTt.h"
@ -93,13 +88,12 @@ fork_tttrace(
/*** DTB_USER_CODE_START vvv Add C code below vvv ***/
DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
std::ostrstream tttraceCmd;
std::ostringstream 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();
system( tttraceCmd.str().c_str() );
/*** DTB_USER_CODE_END ^^^ Add C code above ^^^ ***/
}
@ -659,15 +653,14 @@ libcPause(
/*** DTB_USER_CODE_START vvv Add C code below vvv ***/
DtbTtsnoopTtsnoopWinInfo instance = (DtbTtsnoopTtsnoopWinInfo)clientData;
std::ostrstream advice;
std::ostringstream advice;
advice << "pause(); /* kill -CONT " << getpid() << " */";
DtTtSetLabel( instance->ttsnoopWin_label, advice.str() );
delete advice.str();
DtTtSetLabel( instance->ttsnoopWin_label, advice.str().c_str() );
//
// run "(if dterror.ds blah blah; then kill -CONT pid; fi)&"
//
std::ostrstream script;
std::ostringstream script;
script << "(if dterror.ds ";
// arg 1: text
script << "\"kill -CONT " << getpid() << "\" ";
@ -677,8 +670,7 @@ libcPause(
script << "CONT; then ";
// After confirmation, invoke kill(1)
script << "kill -CONT " << getpid() << "; fi)&";
system( script.str() );
delete script.str();
system( script.str().c_str() );
// Run the event loop a few laps, to paint the footer
tttk_block_while( XtWidgetToApplicationContext( widget ), 0, 50 );
@ -1343,10 +1335,9 @@ toggleSnooping(
if (! tt_is_err( status )) {
snoopPatIsRegistered = ! snoopPatIsRegistered;
}
std::ostrstream stream;
std::ostringstream stream;
stream << func << (void *)snoopPat << ")" << ends;
DtTtSetLabel( instance->ttsnoopWin_label, stream.str(), status );
delete stream.str();
DtTtSetLabel( instance->ttsnoopWin_label, stream.str().c_str(), status );
DtTtSetLabel( instance->menubar_Snoop_item_Snoop_menu_items.Off_item,
snoopPatIsRegistered ? "Off" : "On" );
/*** DTB_USER_CODE_END ^^^ Add C code above ^^^ ***/