Link with C++ linker
[oweals/cde.git] / cde / programs / ttsnoop / fileChooser_stubs.C.src
1 /*** DTB_USER_CODE_START vvv Add file header below vvv ***/
2 //%%  (c) Copyright 1993, 1994 Hewlett-Packard Company
3 //%%  (c) Copyright 1993, 1994 International Business Machines Corp.
4 //%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
5 //%%  (c) Copyright 1993, 1994 Novell, Inc.
6 //%%  $XConsortium: fileChooser_stubs.C.src /main/4 1996/10/14 09:35:42 barstow $
7 /*** DTB_USER_CODE_END   ^^^ Add file header above ^^^ ***/
8
9 /*
10  * File: fileChooser_stubs.c
11  * Contains: Module callbacks and connection functions
12  *
13  * This file was generated by dtcodegen, from module fileChooser
14  *
15  * Any text may be added between the DTB_USER_CODE_START and
16  * DTB_USER_CODE_END comments (even non-C code). Descriptive comments
17  * are provided only as an aid.
18  *
19  *  ** EDIT ONLY WITHIN SECTIONS MARKED WITH DTB_USER_CODE COMMENTS.  **
20  *  ** ALL OTHER MODIFICATIONS WILL BE OVERWRITTEN. DO NOT MODIFY OR  **
21  *  ** DELETE THE GENERATED COMMENTS!                                 **
22  */
23
24 #include <stdio.h>
25 #include <Xm/Xm.h>
26 #include "dtb_utils.h"
27 #include "fileChooser_ui.h"
28
29
30 /**************************************************************************
31  *** DTB_USER_CODE_START
32  ***
33  *** All necessary header files have been included.
34  ***
35  *** Add include files, types, macros, externs, and user functions here.
36  ***/
37
38 #include <unistd.h>
39 #include <sys/wait.h>
40 #include <Xm/TextF.h>
41 #include <fstream.h>
42 #include <strstream.h>
43 #include "DtTt.h"
44 #include "ttsnoop_ui.h"
45
46 /*
47  * There is no public header file for this function (only an
48  * internal header XmStringI.h).
49  */
50 extern "C" {
51 extern XtPointer _XmStringUngenerate (XmString string,
52                         XmStringTag tag,
53                         XmTextType tag_type,
54                         XmTextType output_type);
55 }
56
57 extern ofstream snoopStream;
58 extern int      globalTimeout;
59
60 typedef struct _FileChooserInfo {
61         _DtFileChooserAction    choice;
62         void *                  entity;
63 } FileChooserInfo;
64
65 void
66 _DtFileChooserSet(
67         _DtFileChooserAction    choice,
68         void *                  entity
69 )
70 {
71         char *okString;
72         char *title;
73         char *valueLabel;
74         switch (choice) {
75             case _DtFileChoosePatternAdd:
76                 okString = "Add";
77                 title = "tt_pattern_file_add";
78                 break;
79             case _DtFileChooseMessageSet:
80                 okString = "Set";
81                 title = "tt_message_file_set";
82                 break;
83             case _DtFileChooseJoin:
84                 okString = "Join";
85                 title = "tt_file_join";
86                 break;
87             case _DtFileChooseDtJoin:
88                 okString = "Join";
89                 title = "ttdt_file_join";
90                 break;
91             case _DtFileChooseQuit:
92                 okString = "Quit";
93                 title = "tt_file_quit";
94                 break;
95             case _DtFileChooseDefault:
96                 okString = "Set";
97                 title = "tt_default_file_set";
98                 break;
99             case _DtFileChooseGetModified:
100                 okString = "Get";
101                 title = "ttdt_Get_Modified";
102                 break;
103             case _DtFileChooseSave:
104                 okString = "Save";
105                 title = "ttdt_Save";
106                 break;
107             case _DtFileChooseRevert:
108                 okString = "Revert";
109                 title = "ttdt_Revert";
110                 break;
111             case _DtFileChooseNetfile:
112                 okString = "Netfile";
113                 title = "tt_file_netfile";
114                 break;
115             case _DtFileChooseChdir:
116                 okString = "chdir";
117                 title = "chdir(2)";
118                 break;
119             case _DtFileChooseTypesLoad:
120                 okString = "Load";
121                 title = "tt_session_types_load";
122                 break;
123             default:
124                 return;
125         }
126         DtbFileChooserFchooserInfo instance =
127                 &dtb_file_chooser_fchooser;
128         if (! instance->initialized) {
129                 dtb_file_chooser_fchooser_initialize(
130                         instance, dtb_ttsnoop_ttsnoop_win.ttsnoopWin );
131         }
132         XmString okXmString = XmStringCreateLocalized( okString );
133         XtVaSetValues( instance->fchooser, XmNokLabelString, okXmString, 0 );
134         XmStringFree( okXmString );
135         XtVaSetValues( instance->fchooser_shell, XmNtitle, title, 0 );
136
137         // Remember dialog mode, entity
138         FileChooserInfo *info = new FileChooserInfo;
139         info->choice = choice;
140         info->entity = entity;
141         XtVaSetValues( instance->fchooser, XmNuserData, info, 0 );
142
143         XtManageChild( instance->fchooser );
144 }
145
146 static Tt_message
147 snoopFileMsg(
148         Tt_message      msg,
149         Tttk_op         op,
150         char *          pathname,
151         void *          clientData,
152         int             trust,
153         int             isMe
154 )
155 {
156         tt_free( pathname );
157         DtTtCreated( DTTT_MESSAGE, msg );
158         snoopIt( "Ttdt_file_cb", snoopFileMsg, msg );
159         if (   (tt_message_class( msg ) == TT_REQUEST)
160             && (tt_message_state( msg ) == TT_SENT))
161         {
162                 // Let user fill in the answer
163                 Widget newWidget = DtTtMessageWidgetCreate(
164                                     dtb_ttsnoop_ttsnoop_win.ttsnoopWin,
165                                     msg, DtTtMessageWidgetUpdate );
166                 if (! tt_is_err( tt_ptr_error( newWidget ) )) {
167                         XRaiseWindow( XtDisplay( newWidget ),
168                                       XtWindow( newWidget ));
169                 }
170         }
171         return 0;
172 }
173
174 /*** DTB_USER_CODE_END
175  ***
176  *** End of user code section
177  ***
178  **************************************************************************/
179
180
181
182 void 
183 fileOkayed(
184     Widget widget,
185     XtPointer clientData,
186     XtPointer callData
187 )
188 {
189     /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
190     /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
191     
192     /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
193     DtbFileChooserFchooserInfo instance =
194             (DtbFileChooserFchooserInfo)clientData;
195     XmFileSelectionBoxCallbackStruct *cbRec =
196             (XmFileSelectionBoxCallbackStruct *)callData;
197     char *path;
198     
199     path = (char *) _XmStringUngenerate((XmString) cbRec->value, NULL,
200                                         XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
201
202     if (!path) {
203             abort();
204             return;
205     }
206     if ((path != 0) && (path[0] == '\0')) {
207             path = 0;
208     }
209     XtPointer xtPtr;
210     XtVaGetValues( instance->fchooser, XmNuserData, &xtPtr, 0 );
211     FileChooserInfo *info = (FileChooserInfo *)xtPtr;
212     Widget label = dtb_ttsnoop_ttsnoop_win.ttsnoopWin_label;
213     ostrstream script;
214     switch (info->choice) {
215             Tt_pattern *pats;
216             Tt_message msg;
217             Tt_status status;
218             int ival;
219             char *sess, *val;
220         case _DtFileChoosePatternAdd:
221             _DtTtPatternUpdate( (Tt_pattern)info->entity, info->choice, path );
222             break;
223         case _DtFileChooseMessageSet:
224             _DtTtMessageUpdate( (Tt_message)info->entity, info->choice, path );
225             break;
226         case _DtFileChooseJoin:
227             status = tt_file_join( path );
228             DtTtSetLabel( label, "tt_file_join()", status );
229             break;
230         case _DtFileChooseDtJoin:
231             pats = ttdt_file_join( path, TT_SCOPE_NONE, 1, snoopFileMsg, 0 );
232             status = DtTtSetLabel( label, "ttdt_file_join()", pats );
233             if ((status == TT_OK) && (pats != 0)) {
234                     DtTtCreated( DTTT_DTFILE, pats, path );
235             }
236             break;
237         case _DtFileChooseQuit:
238             status = tt_file_quit( path );
239             DtTtSetLabel( label, "tt_file_quit()", status );
240             break;
241         case _DtFileChooseDefault:
242             status = tt_default_file_set( path );
243             DtTtSetLabel( label, "tt_default_file_set()", status );
244             break;
245         case _DtFileChooseGetModified:
246             DtTtSetLabel( label, "ttdt_Get_Modified() = ..." );
247             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, False );
248             ival = ttdt_Get_Modified( 0, path, TT_BOTH,
249                                       XtWidgetToApplicationContext( label ),
250                                       globalTimeout );
251             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, True );
252             DtTtSetLabel( label, "ttdt_Get_Modified()", ival );
253             break;
254         case _DtFileChooseSave:
255             DtTtSetLabel( label, "ttdt_Save() = ..." );
256             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, False );
257             status = ttdt_Save( 0, path, TT_BOTH,
258                                 XtWidgetToApplicationContext( label ),
259                                 globalTimeout );
260             // XXX Put up watch cursor; disable dialogs?
261             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, True );
262             DtTtSetLabel( label, "ttdt_Save()", status );
263             break;
264         case _DtFileChooseRevert:
265             DtTtSetLabel( label, "ttdt_Revert() = ..." );
266             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, False );
267             ival = ttdt_Revert( 0, path, TT_BOTH,
268                                 XtWidgetToApplicationContext( label ),
269                                 globalTimeout );
270             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, True );
271             DtTtSetLabel( label, "ttdt_Revert()", ival );
272             break;
273         case _DtFileChooseNetfile:
274             val = tt_file_netfile( path );
275             DtTtSetLabel( label, "tt_file_netfile()", val );
276             if (! tt_is_err( tt_ptr_error( val ))) {
277                     snoopStream << "tt_file_netfile( \"" << val
278                             << "\" ) = \"" << val << "\"" << endl;
279             }
280             break;
281         case _DtFileChooseChdir:
282             ival = chdir( path );
283             DtTtSetLabel( label, "chdir()", ival );
284             break;
285         case _DtFileChooseTypesLoad:
286             //
287             // Validate types file, with tt_type_comp -p
288             // (A corrupt file could crash ttsession.)
289             //
290             script << "numChars=`tt_type_comp -p \"" << path;
291             script << "\" | wc -c`; if [ $numChars = 0 ]; "
292                       "then exit 1; else exit 0; fi" << endl;
293             ival = system( script.str() );
294             delete script.str();
295             if (! WIFEXITED( ival )) {
296                     DtTtSetLabel( label,
297                         "system( \"tt_type_comp -p\" )", ival );
298                     break;
299             }
300             if (WEXITSTATUS( ival ) != 0) {
301                     ostrstream diagnosis;
302                     diagnosis << "tt_type_comp -p: syntax error in "
303                             << path << ends;
304                     DtTtSetLabel( label, diagnosis.str() );
305                     delete diagnosis.str();
306                     break;
307             }
308             sess = tt_default_session();
309             status = tt_session_types_load( sess, path );
310             tt_free( sess );
311             DtTtSetLabel( label, "tt_session_types_load()", status );
312             break;
313         default:
314             break;
315     }
316     XtUnmanageChild( instance->fchooser_shell );
317     /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
318 }
319
320
321
322 /**************************************************************************
323  *** DTB_USER_CODE_START
324  ***
325  *** All automatically-generated data and functions have been defined.
326  ***
327  *** Add new functions here, or at the top of the file.
328  ***/
329
330 /*** DTB_USER_CODE_END
331  ***
332  *** End of user code section
333  ***
334  **************************************************************************/
335
336