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>
36 #include <strstream.h>
38 #include <Dt/SpinBox.h>
39 #include <Dt/HelpDialog.h>
42 #include "messageProps_ui.h"
43 #include "patternProps_ui.h"
45 static const char ** dtTtProcids = 0;
46 static const void ** dtTtProcidClientDatums = 0;
47 static unsigned int dtTtProcidsCount = 0;
48 static Tt_pattern * dtTtPatterns = 0;
49 static unsigned int dtTtPatternsCount = 0;
50 static Tt_message * dtTtMessages = 0;
51 static unsigned int dtTtMessagesCount = 0;
52 static Tt_pattern ** dtTtDtSessions = 0;
53 static unsigned int dtTtDtSessionsCount = 0;
54 static Tt_pattern ** dtTtDtFiles = 0;
55 static unsigned int dtTtDtFilesCount = 0;
57 int _DtTtPatsNameKey = (int)DtTtNth;
58 extern Tt_pattern snoopPat;
63 unsigned int & listCount,
68 newList = realloc( *pList, (1 + listCount) * elemSize );
82 char *s = tt_status_string( status );
83 XmString s2 = XmStringCreateLocalized( s );
92 const void * clientData
95 Tt_status status = tt_ptr_error( entity );
96 if ((tt_is_err( status )) || (entity == 0)) {
102 proc = strdup( (const char *)entity );
106 if (! listAppend( dtTtProcids, dtTtProcidsCount, const char *,
111 dtTtProcidsCount--; // shared by both lists
112 if (! listAppend( dtTtProcidClientDatums, dtTtProcidsCount,
113 const void *, clientData ))
119 if (DtTtIndex( type, entity ) >= 0) {
122 if (! listAppend( dtTtMessages, dtTtMessagesCount, Tt_message,
123 (const Tt_message)entity ))
129 if (DtTtIndex( type, entity ) >= 0) {
132 if (! listAppend( dtTtPatterns, dtTtPatternsCount, Tt_pattern,
133 (const Tt_pattern)entity ))
158 if ((tt_is_err( tt_ptr_error( entity ) )) || (entity == 0)) {
161 if ((tt_is_err( tt_ptr_error( name ) )) || (name == 0)) {
176 tt_pattern_user_set( *entity, _DtTtPatsNameKey,
178 if (DtTtIndex( type, entity ) >= 0) {
181 if (! listAppend( dtTtDtSessions, dtTtDtSessionsCount,
182 Tt_pattern *, (Tt_pattern *)entity ))
188 tt_pattern_user_set( *entity, _DtTtPatsNameKey,
190 if (DtTtIndex( type, entity ) >= 0) {
193 if (! listAppend( dtTtDtFiles, dtTtDtFilesCount,
194 Tt_pattern *, (Tt_pattern *)entity ))
200 while (*entity != 0) {
201 DtTtCreated( DTTT_PATTERN, *entity );
215 if ((n < 0) || (n >= dtTtProcidsCount)) {
218 return (void *)dtTtProcids[ n ];
220 if ((n < 0) || (n >= dtTtMessagesCount)) {
223 return dtTtMessages[ n ];
225 if ((n < 0) || (n >= dtTtPatternsCount)) {
228 return dtTtPatterns[ n ];
230 if ((n < 0) || (n >= dtTtDtSessionsCount)) {
233 return dtTtDtSessions[ n ];
235 if ((n < 0) || (n >= dtTtDtFilesCount)) {
238 return dtTtDtFiles[ n ];
240 return tttk_op_string( (Tttk_op)(n+1) );
252 if ((n < 0) || (n >= dtTtProcidsCount)) {
255 return (void *)dtTtProcidClientDatums[ n ];
263 DtTtNthClientDatumSet(
266 const void * clientData
271 if ((n < 0) || (n >= dtTtProcidsCount)) {
274 dtTtProcidClientDatums[ n ] = clientData;
287 Tt_status status = tt_ptr_error( entity );
288 if ((tt_is_err( status )) || (entity == 0)) {
294 for (i = dtTtProcidsCount - 1; i >= 0; i--) {
295 if (strcmp( dtTtProcids[i], (char *)entity) == 0) {
301 for (i = dtTtMessagesCount - 1; i >= 0; i--) {
302 if (dtTtMessages[i] == entity) {
308 for (i = dtTtPatternsCount - 1; i >= 0; i--) {
309 if (dtTtPatterns[i] == entity) {
315 for (i = dtTtDtSessionsCount - 1; i >= 0; i--) {
316 if (dtTtDtSessions[i] == entity) {
322 for (i = dtTtDtFilesCount - 1; i >= 0; i--) {
323 if (dtTtDtFiles[i] == entity) {
329 for (i = 1; i < TTDT_OP_LAST; i++) {
330 if (0 == strcmp( tttk_op_string( (Tttk_op)i ),
346 Tt_status status = tt_ptr_error( entity );
347 if ((tt_is_err( status )) || (entity == 0)) {
354 for (i = dtTtProcidsCount - 1; i >= 0; i--) {
355 if (strcmp( dtTtProcids[i], (char *)entity) == 0) {
360 return TT_WRN_NOTFOUND;
362 for (j = i; j < dtTtProcidsCount - 1; j++) {
363 dtTtProcids[j] = dtTtProcids[j+1];
365 for (j = i; j < dtTtProcidsCount - 1; j++) {
366 dtTtProcidClientDatums[j] =
367 dtTtProcidClientDatums[j+1];
372 for (i = dtTtMessagesCount - 1; i >= 0; i--) {
373 if (dtTtMessages[i] == entity) {
378 return TT_WRN_NOTFOUND;
380 for (j = i; j < dtTtMessagesCount - 1; j++) {
381 dtTtMessages[j] = dtTtMessages[j+1];
386 if (snoopPat == entity) snoopPat = 0;
387 for (i = dtTtPatternsCount - 1; i >= 0; i--) {
388 if (dtTtPatterns[i] == entity) {
393 return TT_WRN_NOTFOUND;
395 for (j = i; j < dtTtPatternsCount - 1; j++) {
396 dtTtPatterns[j] = dtTtPatterns[j+1];
401 for (i = dtTtDtSessionsCount - 1; i >= 0; i--) {
402 if (dtTtDtSessions[i] == entity) {
407 return TT_WRN_NOTFOUND;
409 pats = (Tt_pattern *)entity;
411 DtTtDestroyed( DTTT_PATTERN, *pats );
414 for (j = i; j < dtTtDtSessionsCount - 1; j++) {
415 dtTtDtSessions[j] = dtTtDtSessions[j+1];
417 dtTtDtSessionsCount--;
420 for (i = dtTtDtFilesCount - 1; i >= 0; i--) {
421 if (dtTtDtFiles[i] == entity) {
426 return TT_WRN_NOTFOUND;
428 pats = (Tt_pattern *)entity;
430 DtTtDestroyed( DTTT_PATTERN, *pats );
433 for (j = i; j < dtTtDtFilesCount - 1; j++) {
434 dtTtDtFiles[j] = dtTtDtFiles[j+1];
448 if (labelWidget == 0) {
451 XmString labelXmString = XmStringCreateLocalized( (String)string );
452 XtVaSetValues( labelWidget, XmNlabelString, labelXmString, 0 );
453 XmStringFree( labelXmString );
464 Tt_status status = tt_ptr_error( val );
465 ostrstream errStream;
466 errStream << func << " = " << val << " (" << status << ")" << ends;
467 char *label = errStream.str();
468 DtTtSetLabel( labelWidget, label );
480 ostrstream errStream;
481 errStream << func << " = " << status << ends;
482 char *label = errStream.str();
483 DtTtSetLabel( labelWidget, label );
495 ostrstream errStream;
496 errStream << func << " = " << returnVal << ends;
497 char *label = errStream.str();
498 DtTtSetLabel( labelWidget, label );
511 XmString *items = (XmString *)XtMalloc( count * sizeof( XmString ));
515 for (int i = 0; i < count; i++) {
516 ostrstream itemStream;
517 itemStream << (void *)pPats[ i ];
518 char *name = (char *)
519 tt_pattern_user( *pPats[ i ], _DtTtPatsNameKey );
520 if (! tt_is_err( tt_ptr_error( name ))) {
521 itemStream << " " << name;
525 char *string = itemStream.str();
526 items[ i ] = XmStringCreateLocalized( string );
545 XtMalloc( dtTtProcidsCount * sizeof( XmString ));
549 *itemCount = dtTtProcidsCount;
550 for (i = 0; i < dtTtProcidsCount; i++) {
551 items[ i ] = XmStringCreateLocalized(
552 (String)dtTtProcids[ i ] );
557 XtMalloc( dtTtMessagesCount * sizeof( XmString ));
561 *itemCount = dtTtMessagesCount;
562 for (i = 0; i < dtTtMessagesCount; i++) {
563 ostrstream itemStream;
564 itemStream << (void *)dtTtMessages[ i ];
565 char *op = tt_message_op( dtTtMessages[ i ] );
566 if (! tt_is_err( tt_ptr_error( op ))) {
567 itemStream << " " << op;
570 char *id = tt_message_id( dtTtMessages[ i ] );
571 if (! tt_is_err( tt_ptr_error( id ))) {
572 itemStream << " " << id;
576 char *string = itemStream.str();
577 items[ i ] = XmStringCreateLocalized( string );
583 XtMalloc( dtTtPatternsCount * sizeof( XmString ));
587 *itemCount = dtTtPatternsCount;
588 for (i = 0; i < dtTtPatternsCount; i++) {
589 ostrstream itemStream;
590 itemStream << (void *)dtTtPatterns[ i ] << ends;
591 items[ i ] = XmStringCreateLocalized(
593 delete itemStream.str();
597 *itemCount = dtTtDtSessionsCount;
598 return _DtTtChoices( dtTtDtSessions, dtTtDtSessionsCount );
600 *itemCount = dtTtDtFilesCount;
601 return _DtTtChoices( dtTtDtFiles, dtTtDtFilesCount );
603 // XXX when to free? ditto for each case
604 opCount = ((int)TTDT_OP_LAST) - 1;
606 XtMalloc( opCount * sizeof( XmString ));
610 *itemCount = opCount;
611 for (i = 1; i <= opCount; i++) {
612 items[ i-1 ] = XmStringCreateLocalized(
613 (String)tttk_op_string( (Tttk_op)i ));
620 #define AIX_CONST_STRING (char *)
622 #define AIX_CONST_STRING
629 const char * tempnamTemplate
632 char *file = tempnam( 0, AIX_CONST_STRING tempnamTemplate );
633 ostrstream cmdStream;
634 cmdStream << cmd << " > " << file << ends;
635 int sysStat = system( cmdStream.str() );
636 if (! WIFEXITED( sysStat )) {
638 func << "system( \"" << cmdStream.str() << "\" )" << ends;
639 DtTtSetLabel( label, func.str(), sysStat );
640 delete cmdStream.str();
644 if (WEXITSTATUS( sysStat ) != 0) {
645 DtTtSetLabel( label, cmdStream.str(), WEXITSTATUS( sysStat ));
646 delete cmdStream.str();
649 delete cmdStream.str();
650 _DtOpen( label, file );
659 ostrstream labelStream;
660 labelStream << "dtaction Open " << file << ends;
661 DtTtSetLabel( label, labelStream.str() );
662 delete labelStream.str();
665 cmd << "( unset TT_TRACE_SCRIPT; if dtaction Open " << file
666 << "; then :; else textedit " << file << "; fi; sleep 600; rm -f "
667 << file << " ) &" << ends;
677 const char * tempnamTemplate
680 char *file = tempnam( 0, AIX_CONST_STRING tempnamTemplate );
681 int fd = open( file, O_WRONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR );
682 if (write( fd, buf, len ) < 0) {
683 DtTtSetLabel( label, file, errno );
687 _DtOpen( label, file );
696 ostrstream labelStream;
697 labelStream << "dtaction Dtmanpageview " << topic << ends;
698 DtTtSetLabel( label, labelStream.str() );
699 delete labelStream.str();
702 cmd << "unset TT_TRACE_SCRIPT; if dtaction Dtmanpageview " << topic
703 << "; then :; else cmdtool -c man " << topic << "; fi &" << ends;
713 if (topics == 0) return False;
714 if (strchr( topics, ' ' ) != 0) {
715 // Must not be a list of man pages
727 XtVaGetValues( helpDialog, DtNstringData, &topics, 0 );
728 if (! _DtCanHelp( topics )) {
731 char *newTopics = strdup( topics );
732 const char *whiteSpace = "(12345689) \t:-,.*\n";
733 const char *topic = strtok( newTopics, whiteSpace );
736 topic = strtok( 0, whiteSpace );