Fix warnings on FreeBSD
[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
42 #if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
43 #include <fstream>
44 #include <strstream>
45 #else
46 #include <fstream.h>
47 #include <strstream.h>
48 #endif
49
50 #include "DtTt.h"
51 #include "ttsnoop_ui.h"
52
53 /*
54  * There is no public header file for this function (only an
55  * internal header XmStringI.h).
56  */
57 extern "C" {
58 extern XtPointer _XmStringUngenerate (XmString string,
59                         XmStringTag tag,
60                         XmTextType tag_type,
61                         XmTextType output_type);
62 }
63
64 extern std::ofstream snoopStream;
65 extern int      globalTimeout;
66
67 typedef struct _FileChooserInfo {
68         _DtFileChooserAction    choice;
69         void *                  entity;
70 } FileChooserInfo;
71
72 void
73 _DtFileChooserSet(
74         _DtFileChooserAction    choice,
75         void *                  entity
76 )
77 {
78         char *okString;
79         char *title;
80         char *valueLabel;
81         switch (choice) {
82             case _DtFileChoosePatternAdd:
83                 okString = "Add";
84                 title = "tt_pattern_file_add";
85                 break;
86             case _DtFileChooseMessageSet:
87                 okString = "Set";
88                 title = "tt_message_file_set";
89                 break;
90             case _DtFileChooseJoin:
91                 okString = "Join";
92                 title = "tt_file_join";
93                 break;
94             case _DtFileChooseDtJoin:
95                 okString = "Join";
96                 title = "ttdt_file_join";
97                 break;
98             case _DtFileChooseQuit:
99                 okString = "Quit";
100                 title = "tt_file_quit";
101                 break;
102             case _DtFileChooseDefault:
103                 okString = "Set";
104                 title = "tt_default_file_set";
105                 break;
106             case _DtFileChooseGetModified:
107                 okString = "Get";
108                 title = "ttdt_Get_Modified";
109                 break;
110             case _DtFileChooseSave:
111                 okString = "Save";
112                 title = "ttdt_Save";
113                 break;
114             case _DtFileChooseRevert:
115                 okString = "Revert";
116                 title = "ttdt_Revert";
117                 break;
118             case _DtFileChooseNetfile:
119                 okString = "Netfile";
120                 title = "tt_file_netfile";
121                 break;
122             case _DtFileChooseChdir:
123                 okString = "chdir";
124                 title = "chdir(2)";
125                 break;
126             case _DtFileChooseTypesLoad:
127                 okString = "Load";
128                 title = "tt_session_types_load";
129                 break;
130             default:
131                 return;
132         }
133         DtbFileChooserFchooserInfo instance =
134                 &dtb_file_chooser_fchooser;
135         if (! instance->initialized) {
136                 dtb_file_chooser_fchooser_initialize(
137                         instance, dtb_ttsnoop_ttsnoop_win.ttsnoopWin );
138         }
139         XmString okXmString = XmStringCreateLocalized( okString );
140         XtVaSetValues( instance->fchooser, XmNokLabelString, okXmString, NULL );
141         XmStringFree( okXmString );
142         XtVaSetValues( instance->fchooser_shell, XmNtitle, title, NULL );
143
144         // Remember dialog mode, entity
145         FileChooserInfo *info = new FileChooserInfo;
146         info->choice = choice;
147         info->entity = entity;
148         XtVaSetValues( instance->fchooser, XmNuserData, info, NULL );
149
150         XtManageChild( instance->fchooser );
151 }
152
153 static Tt_message
154 snoopFileMsg(
155         Tt_message      msg,
156         Tttk_op         op,
157         char *          pathname,
158         void *          clientData,
159         int             trust,
160         int             isMe
161 )
162 {
163         tt_free( pathname );
164         DtTtCreated( DTTT_MESSAGE, msg );
165         snoopIt( "Ttdt_file_cb", (void *) snoopFileMsg, msg );
166         if (   (tt_message_class( msg ) == TT_REQUEST)
167             && (tt_message_state( msg ) == TT_SENT))
168         {
169                 // Let user fill in the answer
170                 Widget newWidget = DtTtMessageWidgetCreate(
171                                     dtb_ttsnoop_ttsnoop_win.ttsnoopWin,
172                                     msg, DtTtMessageWidgetUpdate );
173                 if (! tt_is_err( tt_ptr_error( newWidget ) )) {
174                         XRaiseWindow( XtDisplay( newWidget ),
175                                       XtWindow( newWidget ));
176                 }
177         }
178         return 0;
179 }
180
181 /*** DTB_USER_CODE_END
182  ***
183  *** End of user code section
184  ***
185  **************************************************************************/
186
187
188
189 void 
190 fileOkayed(
191     Widget widget,
192     XtPointer clientData,
193     XtPointer callData
194 )
195 {
196     /*** DTB_USER_CODE_START vvv Add C variables and code below vvv ***/
197     /*** DTB_USER_CODE_END   ^^^ Add C variables and code above ^^^ ***/
198     
199     /*** DTB_USER_CODE_START vvv Add C code below vvv ***/
200     DtbFileChooserFchooserInfo instance =
201             (DtbFileChooserFchooserInfo)clientData;
202     XmFileSelectionBoxCallbackStruct *cbRec =
203             (XmFileSelectionBoxCallbackStruct *)callData;
204     char *path;
205     
206     path = (char *) _XmStringUngenerate((XmString) cbRec->value, NULL,
207                                         XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
208
209     if (!path) {
210             abort();
211             return;
212     }
213     if ((path != 0) && (path[0] == '\0')) {
214             path = 0;
215     }
216     XtPointer xtPtr;
217     XtVaGetValues( instance->fchooser, XmNuserData, &xtPtr, NULL );
218     FileChooserInfo *info = (FileChooserInfo *)xtPtr;
219     Widget label = dtb_ttsnoop_ttsnoop_win.ttsnoopWin_label;
220     std::ostrstream script;
221     switch (info->choice) {
222             Tt_pattern *pats;
223             Tt_message msg;
224             Tt_status status;
225             int ival;
226             char *sess, *val;
227         case _DtFileChoosePatternAdd:
228             _DtTtPatternUpdate( (Tt_pattern)info->entity, info->choice, path );
229             break;
230         case _DtFileChooseMessageSet:
231             _DtTtMessageUpdate( (Tt_message)info->entity, info->choice, path );
232             break;
233         case _DtFileChooseJoin:
234             status = tt_file_join( path );
235             DtTtSetLabel( label, "tt_file_join()", status );
236             break;
237         case _DtFileChooseDtJoin:
238             pats = ttdt_file_join( path, TT_SCOPE_NONE, 1, snoopFileMsg, 0 );
239             status = DtTtSetLabel( label, "ttdt_file_join()", pats );
240             if ((status == TT_OK) && (pats != 0)) {
241                     DtTtCreated( DTTT_DTFILE, pats, path );
242             }
243             break;
244         case _DtFileChooseQuit:
245             status = tt_file_quit( path );
246             DtTtSetLabel( label, "tt_file_quit()", status );
247             break;
248         case _DtFileChooseDefault:
249             status = tt_default_file_set( path );
250             DtTtSetLabel( label, "tt_default_file_set()", status );
251             break;
252         case _DtFileChooseGetModified:
253             DtTtSetLabel( label, "ttdt_Get_Modified() = ..." );
254             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, False );
255             ival = ttdt_Get_Modified( 0, path, TT_BOTH,
256                                       XtWidgetToApplicationContext( label ),
257                                       globalTimeout );
258             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, True );
259             DtTtSetLabel( label, "ttdt_Get_Modified()", ival );
260             break;
261         case _DtFileChooseSave:
262             DtTtSetLabel( label, "ttdt_Save() = ..." );
263             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, False );
264             status = ttdt_Save( 0, path, TT_BOTH,
265                                 XtWidgetToApplicationContext( label ),
266                                 globalTimeout );
267             // XXX Put up watch cursor; disable dialogs?
268             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, True );
269             DtTtSetLabel( label, "ttdt_Save()", status );
270             break;
271         case _DtFileChooseRevert:
272             DtTtSetLabel( label, "ttdt_Revert() = ..." );
273             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, False );
274             ival = ttdt_Revert( 0, path, TT_BOTH,
275                                 XtWidgetToApplicationContext( label ),
276                                 globalTimeout );
277             XtSetSensitive( dtb_ttsnoop_ttsnoop_win.ttsnoopWin, True );
278             DtTtSetLabel( label, "ttdt_Revert()", ival );
279             break;
280         case _DtFileChooseNetfile:
281             val = tt_file_netfile( path );
282             DtTtSetLabel( label, "tt_file_netfile()", val );
283             if (! tt_is_err( tt_ptr_error( val ))) {
284                     snoopStream << "tt_file_netfile( \"" << val
285                             << "\" ) = \"" << val << "\"" << endl;
286             }
287             break;
288         case _DtFileChooseChdir:
289             ival = chdir( path );
290             DtTtSetLabel( label, "chdir()", ival );
291             break;
292         case _DtFileChooseTypesLoad:
293             //
294             // Validate types file, with tt_type_comp -p
295             // (A corrupt file could crash ttsession.)
296             //
297             script << "numChars=`tt_type_comp -p \"" << path;
298             script << "\" | wc -c`; if [ $numChars = 0 ]; "
299                       "then exit 1; else exit 0; fi" << endl;
300             ival = system( script.str() );
301             delete script.str();
302             if (! WIFEXITED( ival )) {
303                     DtTtSetLabel( label,
304                         "system( \"tt_type_comp -p\" )", ival );
305                     break;
306             }
307             if (WEXITSTATUS( ival ) != 0) {
308                     std::ostrstream diagnosis;
309                     diagnosis << "tt_type_comp -p: syntax error in "
310                             << path << ends;
311                     DtTtSetLabel( label, diagnosis.str() );
312                     delete diagnosis.str();
313                     break;
314             }
315             sess = tt_default_session();
316             status = tt_session_types_load( sess, path );
317             tt_free( sess );
318             DtTtSetLabel( label, "tt_session_types_load()", status );
319             break;
320         default:
321             break;
322     }
323     XtUnmanageChild( instance->fchooser_shell );
324     /*** DTB_USER_CODE_END   ^^^ Add C code above ^^^ ***/
325 }
326
327
328
329 /**************************************************************************
330  *** DTB_USER_CODE_START
331  ***
332  *** All automatically-generated data and functions have been defined.
333  ***
334  *** Add new functions here, or at the top of the file.
335  ***/
336
337 /*** DTB_USER_CODE_END
338  ***
339  *** End of user code section
340  ***
341  **************************************************************************/
342
343