2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
24 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
25 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
26 //%% (c) Copyright 1993, 1994 Novell, Inc.
27 //%% $XConsortium: DtTt.C /main/4 1996/03/19 10:47:59 barstow $
32 #include <sys/types.h>
37 #if defined(linux) || defined(CSRG_BASED) || defined(sun)
40 #include <strstream.h>
44 #include <Dt/SpinBox.h>
45 #include <Dt/HelpDialog.h>
48 #include "messageProps_ui.h"
49 #include "patternProps_ui.h"
51 static const char ** dtTtProcids = 0;
52 static const void ** dtTtProcidClientDatums = 0;
53 static unsigned int dtTtProcidsCount = 0;
54 static Tt_pattern * dtTtPatterns = 0;
55 static unsigned int dtTtPatternsCount = 0;
56 static Tt_message * dtTtMessages = 0;
57 static unsigned int dtTtMessagesCount = 0;
58 static Tt_pattern ** dtTtDtSessions = 0;
59 static unsigned int dtTtDtSessionsCount = 0;
60 static Tt_pattern ** dtTtDtFiles = 0;
61 static unsigned int dtTtDtFilesCount = 0;
63 int _DtTtPatsNameKey = (int) (long) DtTtNth;
64 extern Tt_pattern snoopPat;
69 unsigned int & listCount,
74 newList = realloc( *pList, (1 + listCount) * elemSize );
88 char *s = tt_status_string( status );
89 XmString s2 = XmStringCreateLocalized( s );
98 const void * clientData
101 Tt_status status = tt_ptr_error( entity );
102 if ((tt_is_err( status )) || (entity == 0)) {
108 proc = strdup( (const char *)entity );
112 if (! listAppend( dtTtProcids, dtTtProcidsCount, const char *,
117 dtTtProcidsCount--; // shared by both lists
118 if (! listAppend( dtTtProcidClientDatums, dtTtProcidsCount,
119 const void *, clientData ))
125 if (DtTtIndex( type, entity ) >= 0) {
128 if (! listAppend( dtTtMessages, dtTtMessagesCount, Tt_message,
129 (const Tt_message)entity ))
135 if (DtTtIndex( type, entity ) >= 0) {
138 if (! listAppend( dtTtPatterns, dtTtPatternsCount, Tt_pattern,
139 (const Tt_pattern)entity ))
164 if ((tt_is_err( tt_ptr_error( entity ) )) || (entity == 0)) {
167 if ((tt_is_err( tt_ptr_error( name ) )) || (name == 0)) {
182 tt_pattern_user_set( *entity, _DtTtPatsNameKey,
184 if (DtTtIndex( type, entity ) >= 0) {
187 if (! listAppend( dtTtDtSessions, dtTtDtSessionsCount,
188 Tt_pattern *, (Tt_pattern *)entity ))
194 tt_pattern_user_set( *entity, _DtTtPatsNameKey,
196 if (DtTtIndex( type, entity ) >= 0) {
199 if (! listAppend( dtTtDtFiles, dtTtDtFilesCount,
200 Tt_pattern *, (Tt_pattern *)entity ))
206 while (*entity != 0) {
207 DtTtCreated( DTTT_PATTERN, *entity );
221 if ((n < 0) || (n >= dtTtProcidsCount)) {
224 return (void *)dtTtProcids[ n ];
226 if ((n < 0) || (n >= dtTtMessagesCount)) {
229 return dtTtMessages[ n ];
231 if ((n < 0) || (n >= dtTtPatternsCount)) {
234 return dtTtPatterns[ n ];
236 if ((n < 0) || (n >= dtTtDtSessionsCount)) {
239 return dtTtDtSessions[ n ];
241 if ((n < 0) || (n >= dtTtDtFilesCount)) {
244 return dtTtDtFiles[ n ];
246 return tttk_op_string( (Tttk_op)(n+1) );
258 if ((n < 0) || (n >= dtTtProcidsCount)) {
261 return (void *)dtTtProcidClientDatums[ n ];
269 DtTtNthClientDatumSet(
272 const void * clientData
277 if ((n < 0) || (n >= dtTtProcidsCount)) {
280 dtTtProcidClientDatums[ n ] = clientData;
293 Tt_status status = tt_ptr_error( entity );
294 if ((tt_is_err( status )) || (entity == 0)) {
300 for (i = dtTtProcidsCount - 1; i >= 0; i--) {
301 if (strcmp( dtTtProcids[i], (char *)entity) == 0) {
307 for (i = dtTtMessagesCount - 1; i >= 0; i--) {
308 if (dtTtMessages[i] == entity) {
314 for (i = dtTtPatternsCount - 1; i >= 0; i--) {
315 if (dtTtPatterns[i] == entity) {
321 for (i = dtTtDtSessionsCount - 1; i >= 0; i--) {
322 if (dtTtDtSessions[i] == entity) {
328 for (i = dtTtDtFilesCount - 1; i >= 0; i--) {
329 if (dtTtDtFiles[i] == entity) {
335 for (i = 1; i < TTDT_OP_LAST; i++) {
336 if (0 == strcmp( tttk_op_string( (Tttk_op)i ),
352 Tt_status status = tt_ptr_error( entity );
353 if ((tt_is_err( status )) || (entity == 0)) {
360 for (i = dtTtProcidsCount - 1; i >= 0; i--) {
361 if (strcmp( dtTtProcids[i], (char *)entity) == 0) {
366 return TT_WRN_NOTFOUND;
368 for (j = i; j < dtTtProcidsCount - 1; j++) {
369 dtTtProcids[j] = dtTtProcids[j+1];
371 for (j = i; j < dtTtProcidsCount - 1; j++) {
372 dtTtProcidClientDatums[j] =
373 dtTtProcidClientDatums[j+1];
378 for (i = dtTtMessagesCount - 1; i >= 0; i--) {
379 if (dtTtMessages[i] == entity) {
384 return TT_WRN_NOTFOUND;
386 for (j = i; j < dtTtMessagesCount - 1; j++) {
387 dtTtMessages[j] = dtTtMessages[j+1];
392 if (snoopPat == entity) snoopPat = 0;
393 for (i = dtTtPatternsCount - 1; i >= 0; i--) {
394 if (dtTtPatterns[i] == entity) {
399 return TT_WRN_NOTFOUND;
401 for (j = i; j < dtTtPatternsCount - 1; j++) {
402 dtTtPatterns[j] = dtTtPatterns[j+1];
407 for (i = dtTtDtSessionsCount - 1; i >= 0; i--) {
408 if (dtTtDtSessions[i] == entity) {
413 return TT_WRN_NOTFOUND;
415 pats = (Tt_pattern *)entity;
417 DtTtDestroyed( DTTT_PATTERN, *pats );
420 for (j = i; j < dtTtDtSessionsCount - 1; j++) {
421 dtTtDtSessions[j] = dtTtDtSessions[j+1];
423 dtTtDtSessionsCount--;
426 for (i = dtTtDtFilesCount - 1; i >= 0; i--) {
427 if (dtTtDtFiles[i] == entity) {
432 return TT_WRN_NOTFOUND;
434 pats = (Tt_pattern *)entity;
436 DtTtDestroyed( DTTT_PATTERN, *pats );
439 for (j = i; j < dtTtDtFilesCount - 1; j++) {
440 dtTtDtFiles[j] = dtTtDtFiles[j+1];
454 if (labelWidget == 0) {
457 XmString labelXmString = XmStringCreateLocalized( (String)string );
458 XtVaSetValues( labelWidget, XmNlabelString, labelXmString, NULL );
459 XmStringFree( labelXmString );
470 Tt_status status = tt_ptr_error( val );
471 std::ostrstream errStream;
472 errStream << func << " = " << val << " (" << status << ")" << ends;
473 char *label = errStream.str();
474 DtTtSetLabel( labelWidget, label );
486 std::ostrstream errStream;
487 errStream << func << " = " << status << ends;
488 char *label = errStream.str();
489 DtTtSetLabel( labelWidget, label );
501 std::ostrstream errStream;
502 errStream << func << " = " << returnVal << ends;
503 char *label = errStream.str();
504 DtTtSetLabel( labelWidget, label );
517 XmString *items = (XmString *)XtMalloc( count * sizeof( XmString ));
521 for (int i = 0; i < count; i++) {
522 std::ostrstream itemStream;
523 itemStream << (void *)pPats[ i ];
524 char *name = (char *)
525 tt_pattern_user( *pPats[ i ], _DtTtPatsNameKey );
526 if (! tt_is_err( tt_ptr_error( name ))) {
527 itemStream << " " << name;
531 char *string = itemStream.str();
532 items[ i ] = XmStringCreateLocalized( string );
551 XtMalloc( dtTtProcidsCount * sizeof( XmString ));
555 *itemCount = dtTtProcidsCount;
556 for (i = 0; i < dtTtProcidsCount; i++) {
557 items[ i ] = XmStringCreateLocalized(
558 (String)dtTtProcids[ i ] );
563 XtMalloc( dtTtMessagesCount * sizeof( XmString ));
567 *itemCount = dtTtMessagesCount;
568 for (i = 0; i < dtTtMessagesCount; i++) {
569 std::ostrstream itemStream;
570 itemStream << (void *)dtTtMessages[ i ];
571 char *op = tt_message_op( dtTtMessages[ i ] );
572 if (! tt_is_err( tt_ptr_error( op ))) {
573 itemStream << " " << op;
576 char *id = tt_message_id( dtTtMessages[ i ] );
577 if (! tt_is_err( tt_ptr_error( id ))) {
578 itemStream << " " << id;
582 char *string = itemStream.str();
583 items[ i ] = XmStringCreateLocalized( string );
589 XtMalloc( dtTtPatternsCount * sizeof( XmString ));
593 *itemCount = dtTtPatternsCount;
594 for (i = 0; i < dtTtPatternsCount; i++) {
595 std::ostrstream itemStream;
596 itemStream << (void *)dtTtPatterns[ i ] << ends;
597 items[ i ] = XmStringCreateLocalized(
599 delete itemStream.str();
603 *itemCount = dtTtDtSessionsCount;
604 return _DtTtChoices( dtTtDtSessions, dtTtDtSessionsCount );
606 *itemCount = dtTtDtFilesCount;
607 return _DtTtChoices( dtTtDtFiles, dtTtDtFilesCount );
609 // XXX when to free? ditto for each case
610 opCount = ((int)TTDT_OP_LAST) - 1;
612 XtMalloc( opCount * sizeof( XmString ));
616 *itemCount = opCount;
617 for (i = 1; i <= opCount; i++) {
618 items[ i-1 ] = XmStringCreateLocalized(
619 (String)tttk_op_string( (Tttk_op)i ));
626 #define AIX_CONST_STRING (char *)
628 #define AIX_CONST_STRING
635 const char * tempnamTemplate
638 char *file = tempnam( 0, AIX_CONST_STRING tempnamTemplate );
639 std::ostrstream cmdStream;
640 cmdStream << cmd << " > " << file << ends;
641 int sysStat = system( cmdStream.str() );
642 if (! WIFEXITED( sysStat )) {
643 std::ostrstream func;
644 func << "system( \"" << cmdStream.str() << "\" )" << ends;
645 DtTtSetLabel( label, func.str(), sysStat );
646 delete cmdStream.str();
650 if (WEXITSTATUS( sysStat ) != 0) {
651 DtTtSetLabel( label, cmdStream.str(), WEXITSTATUS( sysStat ));
652 delete cmdStream.str();
655 delete cmdStream.str();
656 _DtOpen( label, file );
665 std::ostrstream labelStream;
666 labelStream << "dtaction Open " << file << ends;
667 DtTtSetLabel( label, labelStream.str() );
668 delete labelStream.str();
671 cmd << "( unset TT_TRACE_SCRIPT; if dtaction Open " << file
672 << "; then :; else textedit " << file << "; fi; sleep 600; rm -f "
673 << file << " ) &" << ends;
683 const char * tempnamTemplate
686 char *file = tempnam( 0, AIX_CONST_STRING tempnamTemplate );
687 int fd = open( file, O_WRONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR );
688 if (write( fd, buf, len ) < 0) {
689 DtTtSetLabel( label, file, errno );
693 _DtOpen( label, file );
702 std::ostrstream labelStream;
703 labelStream << "dtaction Dtmanpageview " << topic << ends;
704 DtTtSetLabel( label, labelStream.str() );
705 delete labelStream.str();
708 cmd << "unset TT_TRACE_SCRIPT; if dtaction Dtmanpageview " << topic
709 << "; then :; else cmdtool -c man " << topic << "; fi &" << ends;
719 if (topics == 0) return False;
720 if (strchr( topics, ' ' ) != 0) {
721 // Must not be a list of man pages
733 XtVaGetValues( helpDialog, DtNstringData, &topics, NULL );
734 if (! _DtCanHelp( topics )) {
737 char *newTopics = strdup( topics );
738 const char *whiteSpace = "(12345689) \t:-,.*\n";
739 const char *topic = strtok( newTopics, whiteSpace );
742 topic = strtok( 0, whiteSpace );