dtcreate: fix exit with TT_ERR_PTYPE and fix several sprintf related segfaults.
[oweals/cde.git] / cde / programs / dtcreate / ca_aux.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $TOG: ca_aux.c /main/10 1999/09/17 15:44:00 mgreess $ */
24 /******************************************************************************/
25 /*                                                                            */
26 /* ca_aux - auxiliary functions for create action                             */
27 /*                                                                            */
28 /* Functions to get/set values from/to interface.                             */
29 /* Callback routines for CA interface.                                        */
30 /*                                                                            */
31 /******************************************************************************/
32
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <sys/signal.h>
37 #include <errno.h>
38 #include <unistd.h>
39 #include <X11/cursorfont.h>
40 #include <X11/Xlib.h>
41 #include <X11/Xatom.h>
42 #include <Xm/Xm.h>
43 #include <Xm/TextF.h>
44 #include <Xm/RowColumnP.h>
45 #include <Xm/MessageB.h>
46 #include <Xm/FileSB.h>
47 #include <sys/stat.h>
48 #if defined(AIXV3)
49 #    include <sys/dir.h>
50 #else
51 #  if defined(__osf__) || defined(linux)
52 #    include <dirent.h>
53 #  else
54 #    include <sys/dirent.h>
55 #  endif
56 #endif
57
58 #include <Dt/Icon.h>
59 #include <Dt/IconFile.h>
60
61 #include "dtcreate.h"
62 #include "ca_aux.h"
63 #include "cmnutils.h"
64 #include "cmnrtns.h"
65 #include "CreateActionAppShell.h"
66 #include "Confirmed.h"
67
68 /******************************************************************************/
69 /*                                                                            */
70 /*  External Variables                                                        */
71 /*                                                                            */
72 /******************************************************************************/
73 extern Dimension wintypeheight, winheight, xprtheight, newheight;
74
75 /******************************************************************************/
76 /*                                                                            */
77 /*  Variables                                                                 */
78 /*                                                                            */
79 /******************************************************************************/
80 struct _ActionData *ca_local_struct;
81
82 /******************************************************************************/
83 /* readCAFromGUI - loads Action data structure with data read from            */
84 /*                 the GUI interface.                                         */
85 /*                                                                            */
86 /*                                                                            */
87 /******************************************************************************/
88 void readCAFromGUI (struct _ActionData *ca_struct)
89 {
90   getCAactionName (ca_struct);
91   getCAdblClkCmd (ca_struct);
92   getCAactionHelpText (ca_struct);
93      /*getCAfileTypes (ca_struct);*/
94   getCAactionOpensText (ca_struct);
95      /*getCAwindowType (ca_struct);*/
96      /*getCAactionIcons (ca_struct);*/
97      /*getCAexpertOption (ca_struct);*/
98   return;
99 }
100
101
102 /******************************************************************************/
103 /* writeCAToGUI - loads widgets with data stored in the integration           */
104 /*                data structure                                              */
105 /*                                                                            */
106 /*                                                                            */
107 /******************************************************************************/
108 void writeCAToGUI (struct _ActionData *pAD)
109 {
110   putCAactionName (pAD);
111   putCAactionIcons (pAD);
112   putCAdblClkCmd (pAD);
113   putCAactionHelpText (pAD);
114   putCAwindowType (pAD);
115   putCAactionOpensText (pAD);
116   putCAfileTypes (pAD);
117   putCAdropFiletypes(pAD);
118   return;
119 }
120
121
122 /******************************************************************************/
123 /* getCAactionName - retrieves the action name text string and stores         */
124 /*      the value in the ActionData structure                                 */
125 /* INPUT: _ActionData *ca_struct - Action data structure                      */
126 /* OUTPUT: none                                                               */
127 /******************************************************************************/
128 void getCAactionName (struct _ActionData *ca_struct)
129 {
130   GetWidgetTextString(CA_ActionNameTextField, &(AD.pszName));
131 }
132
133
134 /******************************************************************************/
135 /* getCAdblClkCmd - retrieves the double-click command text                   */
136 /*      string and stores the value in the ActionData structure               */
137 /* INPUT: _ActionData *ca_struct - Action data structure                      */
138 /* OUTPUT: none                                                               */
139 /******************************************************************************/
140 void getCAdblClkCmd (struct _ActionData *ca_struct)
141 {
142   GetWidgetTextString(CA_DblClkText, &(AD.pszCmd));
143 }
144
145
146 /******************************************************************************/
147 /* getCAactionHelpText - retrieves the help text string and stores            */
148 /*      the value in the ActionData structure                                 */
149 /* INPUT: _ActionData *ca_struct - Action data structure                      */
150 /* OUTPUT: none                                                               */
151 /******************************************************************************/
152 void getCAactionHelpText (struct _ActionData *ca_struct)
153 {
154   GetWidgetTextString(CA_HelpText, &(AD.pszHelp));
155 }
156
157 /******************************************************************************/
158 /* getCAactionOpensText - retrieves the "action opens" text                   */
159 /*      string and stores the value in the ActionData structure               */
160 /* INPUT: _ActionData *ca_struct - Action data structure                      */
161 /* OUTPUT: none                                                               */
162 /******************************************************************************/
163 void getCAactionOpensText (struct _ActionData *ca_struct)
164 {
165   GetWidgetTextString(CA_XprtActionOpenText, &(AD.pszPrompt));
166 }
167
168 /******************************************************************************/
169 /* putCAactionName - sets the action name text field in the GUI               */
170 /*       from the value in the ActionData structure                           */
171 /* INPUT: _ActionData *ca_struct - Action data structure                      */
172 /* OUTPUT: none                                                               */
173 /******************************************************************************/
174 void putCAactionName (struct _ActionData *ca_struct)
175 {
176   PutWidgetTextString(CA_ActionNameTextField, CA_ActionName(ca_struct));
177   return;
178 }
179
180 /******************************************************************************/
181 /* putCAdblClkCmd - sets the double-click command text                        */
182 /*      string in the GUI from the value in the ActionData structure          */
183 /* INPUT: _ActionData *ca_struct - Action data structure                      */
184 /* OUTPUT: none                                                               */
185 /******************************************************************************/
186 void putCAdblClkCmd (struct _ActionData *ca_struct)
187 {
188   PutWidgetTextString(CA_DblClkText, CA_DblClkAction(ca_struct));
189   return;
190 }
191
192 /******************************************************************************/
193 /* putCAactionHelpText - sets the help text string in the GUI from            */
194 /*      the value in the ActionData structure                                 */
195 /* INPUT: _ActionData *ca_struct - Action data structure                      */
196 /* OUTPUT: none                                                               */
197 /******************************************************************************/
198 void putCAactionHelpText (struct _ActionData *ca_struct)
199 {
200   PutWidgetTextString(CA_HelpText, CA_ActionHelpText(ca_struct));
201   return;
202 }
203
204 /******************************************************************************/
205 /* putCAfileTypes - sets the list of file types in the GUI from               */
206 /*      the values in the ActionData structure                                */
207 /* INPUT: _ActionData *ca_struct - Action data structure                      */
208 /* OUTPUT: none                                                               */
209 /******************************************************************************/
210 void putCAfileTypes (struct _ActionData *pAD)
211 {
212  pFiletypeData  pFtD;
213  int            i;
214
215   if (pAD->cFiletypes) {
216      for (i=0; i < pAD->cFiletypes; i++) {
217        if (!XmListItemExists(CA_FiletypesList,
218               XmStringCreateSimple((pAD->papFiletypes[i])->pszName))) {
219           XmListAddItem(CA_FiletypesList,
220             XmStringCreateSimple((pAD->papFiletypes[i])->pszName), i+1);
221        }
222      }
223   }
224
225   return;
226 }
227
228 /******************************************************************************/
229 /* putCAactionOpensText - sets the "action opens" text string in              */
230 /*      the GUE from the value in the ActionData structure                    */
231 /* INPUT: _ActionData *ca_struct - Action data structure                      */
232 /* OUTPUT: none                                                               */
233 /******************************************************************************/
234 void putCAactionOpensText (struct _ActionData *ca_struct)
235 {
236   PutWidgetTextString(CA_XprtActionOpenText, CA_ActionOpensText(ca_struct));
237   return;
238 }
239
240 /******************************************************************************/
241 /* putCAwindowType - sets the window type toggle status in the GUI            */
242 /*       from the value in the ActionData structure                           */
243 /* INPUT: _ActionData *ca_struct - Action data structure                      */
244 /* OUTPUT: none                                                               */
245 /******************************************************************************/
246 void putCAwindowType (struct _ActionData *ca_struct)
247 {
248   if (ca_struct->fsFlags & CA_WT_XWINDOWS) {
249      /*
250      XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeNoOutput,NULL);
251      */
252      XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
253   } else if (ca_struct->fsFlags & CA_WT_TERM) {
254      XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeAutoClose,NULL);
255   } else if (ca_struct->fsFlags & CA_WT_PERMTERM) {
256      XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeManualClose,NULL);
257   } else {
258      /*XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeNoOutput,NULL);*/
259      XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
260   }
261   return;
262 }
263
264 /******************************************************************************/
265 /* putCAactionIcons -                                                         */
266 /*       GUI from the value in the ActionData structure                       */
267 /* INPUT: _ActionData *ca_struct - Action data structure                      */
268 /* OUTPUT: none                                                               */
269 /******************************************************************************/
270 void putCAactionIcons (ActionData *pAD)
271 {
272   char   *pszIconFileName = (char *)NULL;
273   char   *ptr;
274   char   *msgPtr, *fmtPtr, *errPtr;
275
276   /**************************************************************************/
277   /* Since we only have the base name, we must find the icon within the     */
278   /* icon path, strip off the size and type extension, then set the icon    */
279   /* data and gadget with this new name - base name and path.               */
280   /**************************************************************************/
281   FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtLARGE);
282   if (pszIconFileName) {
283      ptr = strstr(pszIconFileName, LARGE_EXT);
284      if (ptr) *ptr = '\0';
285      SetIconData(CA_LRG_IconGadget, pszIconFileName, Large_Icon);
286      XtFree(pszIconFileName);
287   } else {
288      msgPtr = GETMESSAGE(5, 95,
289        "Could not find the following icon file within the icon\n\
290 search path:");
291      fmtPtr = "%s\n   %s";
292      errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
293                         strlen(pAD->pszIcon) + 1) * sizeof(char));
294      sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
295      display_error_message(CreateActionAppShell, errPtr);
296      XtFree(errPtr);
297   }
298
299   FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtMEDIUM);
300   if (pszIconFileName) {
301      ptr = strstr(pszIconFileName, MEDIUM_EXT);
302      if (ptr) *ptr = '\0';
303      SetIconData(CA_MED_IconGadget, pszIconFileName, Medium_Icon);
304      XtFree(pszIconFileName);
305   } else {
306      msgPtr = GETMESSAGE(5, 95,
307        "Could not find the following icon file within the icon\n\
308 search path:");
309      fmtPtr = "%s\n   %s";
310      errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
311                         strlen(pAD->pszIcon) + 1) * sizeof(char));
312      sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
313      display_error_message(CreateActionAppShell, errPtr);
314      XtFree(errPtr);
315   }
316
317   FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtTINY);
318   if (pszIconFileName) {
319      ptr = strstr(pszIconFileName, TINY_EXT);
320      if (ptr) *ptr = '\0';
321      SetIconData(CA_TINY_IconGadget, pszIconFileName, Tiny_Icon);
322      XtFree(pszIconFileName);
323   } else {
324      msgPtr = GETMESSAGE(5, 95,
325        "Could not find the following icon file within the icon\n\
326 search path:");
327      fmtPtr = "%s\n   %s";
328      errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
329                         strlen(pAD->pszIcon) + 1) * sizeof(char));
330      sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
331      display_error_message(CreateActionAppShell, errPtr);
332      XtFree(errPtr);
333   }
334 }
335
336 /******************************************************************************/
337 /* putCAdropFiletypes -                                                       */
338 /*                                                                            */
339 /* INPUT: _ActionData *ca_struct - Action data structure                      */
340 /* OUTPUT: none                                                               */
341 /******************************************************************************/
342 void putCAdropFiletypes (ActionData *pAD)
343 {
344   Boolean  set = FALSE;
345
346   if (pAD->fsFlags & CA_DF_ONLYFTFILES) {
347      set = TRUE;
348   }
349   SET_TOGGLEBUTTON(CA_FiletypesInListToggle, set);
350   SET_TOGGLEBUTTON(CA_AllFiletypesToggle, !set);
351
352   return;
353 }
354
355 /******************************************************************************/
356 /* set_ca_dialog_height - adjusts height of create action dialog to exclude   */
357 /*                        height used by expert option section.               */
358 /* INPUT: none                                                                */
359 /* OUTPUT: none                                                               */
360 /******************************************************************************/
361 void set_ca_dialog_height (void)
362 {
363   Boolean showExpert = sessiondata.useSession && sessiondata.showExpert;
364
365   /* get height of window */
366   XtVaGetValues (CreateActionAppShell, XmNheight, &winheight, NULL);
367   /* get height of expert option form */
368   XtVaGetValues (XprtOptionForm, XmNheight, &xprtheight, NULL);
369   /* calculate height of window without expert option form */
370   newheight = winheight - xprtheight;
371
372   if (!showExpert)
373   {
374     /* remove attachment to expert option form */
375     XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_NONE, NULL);
376     XtUnmanageChild (XprtOptionForm);
377
378     if (!sessiondata.useSession)
379     {
380       /* give window new height */
381       XtVaSetValues (CreateActionAppShell, XmNheight, newheight, NULL);
382     }
383
384     XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_FORM, NULL);
385   }
386   else
387   {
388     XtVaSetValues (CA_Expand, RES_CONVERT(XmNlabelString,
389                                           GETMESSAGE(3, 52, "Basic")),
390                    NULL);
391   }
392
393   return;
394 }
395
396 /******************************************************************************/
397 /*                                                                            */
398 /*         CALLBACK FUNCTIONS                                                 */
399 /*                                                                            */
400 /******************************************************************************/
401
402 /******************************************************************************/
403 /*                                                                            */
404 /*                                                                            */
405 /*      Callbacks for Create Action 'File' menu                               */
406 /*                                                                            */
407 /*                                                                            */
408 /******************************************************************************/
409
410 /*****************************************************************************/
411 /*                                                                           */
412 /*  initAD                                                                   */
413 /*                                                                           */
414 /*                                                                           */
415 /*****************************************************************************/
416 void
417 initAD( ActionData *pAD )
418 {
419   memset(pAD, 0, sizeof(ActionData));
420   pAD->fsFlags |= CA_WT_XWINDOWS;
421   pAD->pszIcon = (char *)XtMalloc(strlen(ca_icon_default) + 1);
422   strcpy(pAD->pszIcon, ca_icon_default);
423 }
424
425 /******************************************************************************/
426 /* FreeAndClearAD - free all fields in AD, frees filetypes and array,         */
427 /*                  and zero's out all of the fields of the structure.        */
428 /* INPUT:  none                                                               */
429 /* OUTPUT: none                                                               */
430 /******************************************************************************/
431 void FreeAndClearAD (ActionData *pAD)
432 {
433   FiletypeData  *pFtD;
434   int           i;
435
436   if (pAD->pszName) XtFree(pAD->pszName);
437   if (pAD->pszIcon) XtFree(pAD->pszIcon);
438   if (pAD->pszCmd) XtFree(pAD->pszCmd);
439   if (pAD->pszHelp) XtFree(pAD->pszHelp);
440   if (pAD->pszPrompt) XtFree(pAD->pszPrompt);
441
442   if (pAD->papFiletypes) {
443      for (i=0; i < pAD->cFiletypes; i++) {
444         free_Filetypedata(pAD->papFiletypes[i]);
445      }
446      XtFree((char *)pAD->papFiletypes);
447   }
448   memset(pAD, 0, sizeof(ActionData));
449   return;
450
451 }
452
453 /******************************************************************************/
454 /* clear_CreateActionAppShell_fields                                          */
455 /*                                                                            */
456 /* INPUT:  none                                                               */
457 /* OUTPUT: none                                                               */
458 /******************************************************************************/
459 void clear_CreateActionAppShell_fields(void)
460 {
461   clear_text_field (ACTION_NAME);
462   clear_text_field (DBL_CLK_CMND);
463
464   XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
465
466   clear_text_field (ACTION_OPENS_TEXT);
467   clear_text (ACTION_HELP_TXT);
468   delete_all_list_items (FILETYPES_FOR_ACTION);
469
470   createCB_IconGadget(CA_LRG_IconGadget, True, Large_Icon);
471   createCB_IconGadget(CA_MED_IconGadget, True, Medium_Icon);
472   createCB_IconGadget(CA_TINY_IconGadget, True, Tiny_Icon);
473
474   SET_TOGGLEBUTTON(CA_AllFiletypesToggle, TRUE);
475   SET_TOGGLEBUTTON(CA_FiletypesInListToggle, FALSE);
476
477   return;
478 }
479
480 /******************************************************************************/
481 /* activateCB_FileNew - clears the text and list widgets on the               */
482 /*                                create action main panel                    */
483 /* INPUT:  Widget wid - widget id                                             */
484 /*         XtPointer cdata - client data                                      */
485 /*         XtPointer cbs - callback structur                                  */
486 /* OUTPUT: none                                                               */
487 /******************************************************************************/
488 void activateCB_FileNew (Widget wid, XtPointer cdata,
489                          XtPointer cbstruct)
490 {
491   char          pszFile[MAXBUFSIZE];
492
493   /**************************************************************************/
494   /* Clear the fields in the gui and set fields to default.                 */
495   /**************************************************************************/
496   clear_CreateActionAppShell_fields();
497
498   /**************************************************************************/
499   /* Clear the pszFileToEdit global variable.                               */
500   /**************************************************************************/
501   pszFileToEdit = (char *)NULL;
502
503   /**************************************************************************/
504   /* Clear the fields within the ActionData structure and free any          */
505   /* FiletypeData structures.                                               */
506   /**************************************************************************/
507   FreeAndClearAD(&AD);
508
509   /**************************************************************************/
510   /* Initialize fields within the ActionData structure.                     */
511   /**************************************************************************/
512   initAD(&AD);
513
514   /**************************************************************************/
515   /* Get a new copy of AD.                                                  */
516   /**************************************************************************/
517   FreeAndClearAD(pMyCopyAD);
518   XtFree((char *)pMyCopyAD);
519   pMyCopyAD = copyAD(&AD);
520
521   return;
522 }
523
524
525 /******************************************************************************/
526 /* activateCB_FileOpen  -  Callback for the Open menu bar option that is      */
527 /*                         located within the File submenu.  This callback    */
528 /*                         pops up the File Selection dialog box.             */
529 /*                                                                            */
530 /* INPUT:  Widget wid - widget id                                             */
531 /*         XtPointer cdata - client data                                      */
532 /*         XtPointer cbs - callback structure                                 */
533 /*                                                                            */
534 /* OUTPUT: none                                                               */
535 /******************************************************************************/
536 void  activateCB_FileOpen(Widget wid, XtPointer cdata,
537                           XtPointer cbstruct)
538 {
539   Widget filter;
540
541   XtVaSetValues (OpenFile, RES_CONVERT(XmNdirMask, "~/.dt/types/*.dt"),
542                  RES_CONVERT(XmNdirSpec, "~/.dt/types/"),
543                  RES_CONVERT(XmNdirectory, "~/.dt/types/"),
544                  NULL);
545
546   filter = XmFileSelectionBoxGetChild (OpenFile, XmDIALOG_FILTER_TEXT);
547   /*XtVaSetValues (filter, XmNeditable, False, NULL);*/
548   UxPopupInterface (OpenFile, no_grab);
549   return;
550 }
551
552 /******************************************************************************/
553 /*                                                                            */
554 /* FreeResources                                                              */
555 /*                                                                            */
556 /* INPUT:  none                                                               */
557 /* OUTPUT: none                                                               */
558 /******************************************************************************/
559 void FreeResources ( void )
560 {
561   /**************************************************************************/
562   /* Clear the fields within the ActionData structure and free any          */
563   /* FiletypeData structures.                                               */
564   /**************************************************************************/
565   FreeAndClearAD(&AD);
566
567   /**************************************************************************/
568   /* Free my copy of AD.                                                    */
569   /**************************************************************************/
570   FreeAndClearAD(pMyCopyAD);
571   XtFree((char *)pMyCopyAD);
572
573   /********************************************************************/
574   /* Free temporary icon files                                        */
575   /********************************************************************/
576   RemoveTmpIconFiles();
577
578   return;
579 }
580
581 /******************************************************************************/
582 /*  activateCB_FileQuit                                                       */
583 /* INPUT:  Widget wid - widget id                                             */
584 /*         XtPointer cdata - client data                                      */
585 /*         XtPointer cbs - callback structur                                  */
586 /*  OUTPUT: none                                                              */
587 /******************************************************************************/
588 void activateCB_FileQuit (Widget wid, XtPointer cdata,
589                           XtPointer cbstruct)
590 {
591   char    *msgPtr;
592   char    *savePtr;
593   char    *noSavePtr;
594   char    *cancelPtr;
595
596   /**************************************************************************/
597   /* Get latest changes from main window.                                   */
598   /**************************************************************************/
599   readCAFromGUI(&AD);
600
601   /**************************************************************************/
602   /* Check if anything has changed.  If so ask if they really want to quit. */
603   /**************************************************************************/
604   if (compareAD(&AD, pMyCopyAD)) {
605      msgPtr = GETMESSAGE(5, 150, "Your current work has not been saved.");
606      msgPtr = XtNewString(msgPtr);
607
608      /* CDExc19439 - Save GETMESSAGE results to buffers since it can */
609      /* return an internal buffer which can be overwritten on each call. */
610      savePtr = XtNewString(GETMESSAGE(2, 25, "Save"));
611      noSavePtr = XtNewString(GETMESSAGE(5, 152, "Don't Save"));
612      cancelPtr = XtNewString(GETMESSAGE(5, 154, "Cancel Close"));
613
614      display_question_message(CreateActionAppShell, msgPtr,
615                              savePtr, (XtCallbackProc)saveCB_QuestionDialog,
616                              noSavePtr, nosaveCB_QuestionDialog,
617                              cancelPtr, cancelCB_QuestionDialog);
618
619      XtFree(cancelPtr);
620      XtFree(noSavePtr);
621      XtFree(savePtr);
622      XtFree(msgPtr);
623      return;
624   }
625
626   FreeResources();
627
628   exit(0);
629 }
630
631 /******************************************************************************/
632 /*                                                                            */
633 /*                                                                            */
634 /*      Callbacks for Create Action 'Options' menu                            */
635 /*                                                                            */
636 /*                                                                            */
637 /* void activateCB_ExpertOption ();                                           */
638 /*                                                                            */
639 /*                                                                            */
640 /******************************************************************************/
641
642
643 /******************************************************************************/
644 /* activateCB_ExpertOption - turn expert option on/off                        */
645 /* INPUT: Widget wid - widget id                                              */
646 /*        XtPointer client_data - client data                                 */
647 /*        XtPointer *cbs - callback data                                      */
648 /* OUTPUT: none                                                               */
649 /* Global Variables Accessed: (other than widgets)                            */
650 /* wintypeheight                                                              */
651 /******************************************************************************/
652 void activateCB_ExpertOption (Widget wid, XtPointer client_data,
653                               XtPointer *cbs)
654 {
655   Dimension  ca_width;
656
657   if (!XtIsManaged(XprtOptionForm)) {
658      /**********************************************************************/
659      /* Expand the window to show optional data.                           */
660      /**********************************************************************/
661      XtVaGetValues (CA_WindowTypeArea, XmNwidth, &ca_width, NULL);
662      XtVaSetValues (CA_Expand,
663                     XmNbottomAttachment, XmATTACH_NONE,
664                     NULL);
665      XtVaSetValues (XprtOptionForm,
666                     XmNbottomAttachment, XmATTACH_FORM,
667                     XmNleftAttachment, XmATTACH_FORM,
668                     XmNrightAttachment, XmATTACH_FORM,
669                     XmNwidth, ca_width,
670                     NULL);
671      XtManageChild (XprtOptionForm);
672      XtVaSetValues (CA_Expand,
673                     XmNbottomAttachment, XmATTACH_WIDGET,
674                     XmNbottomWidget, XprtOptionForm,
675                     XmNbottomOffset, 10,
676                   /*XmNlabelString, GETMESSAGE(3, 52, "Basic"),*/
677                     RES_CONVERT( XmNlabelString, GETMESSAGE(3, 52, "Basic")),
678                     NULL);
679      XtVaSetValues (CA_HelpTextWindow, XmNheight, wintypeheight, NULL);
680      /*XtVaSetValues (CA_WindowTypeArea, XmNheight, wintypeheight, NULL);*/
681   } else {
682      /**********************************************************************/
683      /* Shrink the window to hide optional data.                           */
684      /**********************************************************************/
685      XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_NONE, NULL);
686      XtUnmanageChild (XprtOptionForm);
687      XtVaSetValues (CA_Expand,
688                     XmNbottomAttachment, XmATTACH_FORM,
689                     XmNbottomOffset, 15,
690                   /*XmNlabelString, GETMESSAGE(3, 50, "Advanced"),*/
691                     RES_CONVERT( XmNlabelString, GETMESSAGE(3, 50, "Advanced")),
692                     NULL);
693      XtVaSetValues (CA_HelpTextWindow, XmNheight, wintypeheight, NULL);
694      XtVaSetValues (CA_WindowTypeArea, XmNheight, wintypeheight, NULL);
695   }
696   return;
697 }
698
699 /******************************************************************************/
700 /*                                                                            */
701 /* valueChangedCB_ColorMonoOption - turn monochrome option on/off             */
702 /*                                                                            */
703 /* INPUT: Widget wid - widget id                                              */
704 /*        XtPointer client_data - client data                                 */
705 /*        XmToggleButtonCallbackStruct *tcb - callback data                   */
706 /* OUTPUT: none                                                               */
707 /*                                                                            */
708 /******************************************************************************/
709 void valueChangedCB_ColorMonoOption (Widget wid, XtPointer client_data,
710                               XmToggleButtonCallbackStruct *tcb)
711 {
712   int        toggle_set= tcb->set;
713   IconData   *pIconData;
714   Widget     widIcon;
715   Widget     widIcons[3];
716   int        i;
717
718   /***************************************************************************/
719   /* If set then change icons from pixmaps to bitmaps.                       */
720   /***************************************************************************/
721   if (toggle_set) {
722      bShowPixmaps = FALSE;
723   } else {
724      bShowPixmaps = TRUE;
725   }
726
727   /***************************************************************************/
728   /* Change icons for CA large, med, and tiny icons                          */
729   /***************************************************************************/
730   widIcons[0] = CA_LRG_IconGadget;
731   widIcons[1] = CA_MED_IconGadget;
732   widIcons[2] = CA_TINY_IconGadget;
733   for (i = 0; i < 3; i++) {
734      pIconData = GetIconDataFromWid(widIcons[i]);
735      if (pIconData) {
736         if (bShowPixmaps) {
737            SET_ICONGADGET_ICON(widIcons[i], pIconData->pmFileName);
738         } else {
739            SET_ICONGADGET_ICON(widIcons[i], pIconData->bmFileName);
740         }
741      }
742   }
743
744 }
745
746 /******************************************************************************/
747 /*                                                                            */
748 /* createCB_ColorMonoOption                                                   */
749 /*                                                                            */
750 /* INPUT: Widget wid - widget id                                              */
751 /* OUTPUT: none                                                               */
752 /*                                                                            */
753 /******************************************************************************/
754 void createCB_ColorMonoOption (Widget wid)
755 {
756   bShowPixmaps = TRUE;
757 #ifdef DEBUG
758   printf("bShowPixmaps = %d\n", (int)bShowPixmaps);
759 #endif
760   return;
761 }
762
763 /******************************************************************************/
764 /*                                                                            */
765 /*                                                                            */
766 /*      Callbacks for Create Action 'Help' menu                               */
767 /*                                                                            */
768 /*                                                                            */
769 /******************************************************************************/
770
771 /******************************************************************************/
772 /*                                                                            */
773 /*                                                                            */
774 /*      Callbacks for Create Action Panel Buttons                             */
775 /*                                                                            */
776 /*                                                                            */
777 /* void activateCB_action_icon ();                                            */
778 /*                                                                            */
779 /*                                                                            */
780 /******************************************************************************/
781
782 /******************************************************************************/
783 /*                                                                            */
784 /* activateCB_action_icon -                                                  */
785 /*                                                                            */
786 /* INPUT: Widget wid - id of icon gadget                                      */
787 /*        XtPointer client_data - not used                                    */
788 /*        XmPushButtonCallbackStruct *cbs - not used                          */
789 /* OUTPUT: none                                                               */
790 /*                                                                            */
791 /******************************************************************************/
792 void activateCB_action_icon (Widget wid, XtPointer client_data,
793                              DtIconCallbackStruct *cbs)
794 {
795   Time    lts, mct = 0;
796   static  Time prev_lts = 0;
797
798   if (cbs->reason == XmCR_ACTIVATE) {
799
800 #ifdef DEBUG
801     printf("In activate_action_icon callback.\n");
802 #endif
803     if (last_action_pushed && (last_action_pushed != wid)) {
804        XtVaSetValues(XtParent(last_action_pushed), XmNborderWidth, 0, NULL);
805     }
806     XtVaSetValues(XtParent(wid), XmNborderWidth, ICON_BORDER_WIDTH, NULL);
807
808     last_action_pushed = wid;
809
810     /********************************************************************/
811     /* This is the support needed to provide double-click functionality */
812     /* to the icon gadgets.  When double-clicked, the icon editor will  */
813     /* be launched.                                                     */
814     /********************************************************************/
815     XtVaSetValues(wid, XmNpushButtonClickTime, 0, NULL);
816
817     lts = XtLastTimestampProcessed(XtDisplay(wid));
818     mct = XtGetMultiClickTime(XtDisplay(wid));
819
820     if ((prev_lts + mct) > lts) {
821        prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
822     } else {
823        prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
824        return;
825     }
826
827 #ifdef DEBUG
828     printf("DblClick icon callback.\n");
829 #endif
830
831     activateCB_edit_icon(wid, CA_ACTION_ICONS, cbs);
832
833   }
834   return;
835 }
836
837 /******************************************************************************/
838 /* activateCB_add_filetype - bring up the Add Filetype dialog with correct    */
839 /*              dialog title.                                                 */
840 /* INPUT: Widget wid - not used                                               */
841 /*        XtPointer client_data - not used                                    */
842 /*        XmPushButtonCallbackStruct *cbs - not used                          */
843 /* OUTPUT: none                                                               */
844 /******************************************************************************/
845 void activateCB_add_filetype (Widget wid, XtPointer client_data,
846                               XmPushButtonCallbackStruct *cbs)
847 {
848   FiletypeData *pFtD;
849   char         *ptr;
850   char          tmpbuf[50];
851   char         *pre, *suf, *title;
852   size_t       len;
853
854   if (!CreateActionAppShellCheckFields()) {
855
856 #ifdef DEBUG
857     printf("Allocating FiletypeData structure\n"); /* debug */
858 #endif
859
860     /******************************************************************/
861     /* Allocate FiletypeData structure                                */
862     /******************************************************************/
863     pFtD = (FiletypeData *)XtMalloc(sizeof(FiletypeData));
864     memset(pFtD, 0, sizeof(FiletypeData));
865
866     /******************************************************************/
867     /* Clear dialog fields                                            */
868     /******************************************************************/
869     clear_AddFiletype_dialog_fields();
870     clear_FileCharacteristics_dialog_fields();
871
872     /******************************************************************/
873     /* Create name for filetype                                       */
874     /******************************************************************/
875     memset(tmpbuf, 0, 50);
876     sprintf(tmpbuf, "%d", (AD.cFiletypes + 1));
877     ptr = (char *)XmTextFieldGetString(CA_ActionNameTextField);
878     pFtD->pszName = (char *)XtMalloc(strlen(ptr) + strlen("_FILE_") + strlen(tmpbuf) + 1);
879     sprintf(pFtD->pszName, "%s_FILE_%d", ptr, (AD.cFiletypes + 1));
880     XtFree(ptr);
881     XmTextFieldSetString(AF_FileTypeNameTextField, pFtD->pszName);
882
883     pFtD->pszIcon = (char *)XtMalloc(strlen(af_icon_default) + 1);
884     strcpy(pFtD->pszIcon, af_icon_default);
885
886     /******************************************************************/
887     /* Set Open command string                                        */
888     /******************************************************************/
889     /*
890     pFtD->pszOpenCmd = (char *)XmTextGetString(CA_DblClkText);
891     */
892     GetWidgetTextString(CA_DblClkText, &(pFtD->pszOpenCmd));
893     XmTextSetString(AF_OpenCmdText, pFtD->pszOpenCmd);
894
895     pre = GETMESSAGE(3, 10, "Create Action");
896     suf = GETMESSAGE(7, 10, "Add Datatype");
897     len = strlen(pre) + strlen(suf) + 4;
898     title = XtMalloc(len);
899     snprintf(title,len - 1,"%s - %s", pre, suf);
900
901     XtVaSetValues (AddFiletype,
902                    RES_CONVERT (XmNdialogTitle, title ),
903                    XmNuserData, pFtD,
904                    NULL);
905
906     XtFree(title);
907     UxPopupInterface (AddFiletype, no_grab);
908   }
909   return;
910 }
911
912
913 /******************************************************************************/
914 /* activateCB_edit_filetype - bring up the Add Filetype dialog with correct   */
915 /*              dialog title.                                                 */
916 /* INPUT: Widget wid - not used                                               */
917 /*        XtPointer client_data - not used                                    */
918 /*        XmPushButtonCallbackStruct *cbs - not used                          */
919 /* OUTPUT: none                                                               */
920 /******************************************************************************/
921 void activateCB_edit_filetype (Widget wid, XtPointer client_data,
922                               XmPushButtonCallbackStruct *cbs)
923 {
924   FiletypeData *pFtD;
925   int          *poslist, poscnt;
926   int          selecteditem;
927   char         *msgPtr1, *msgPtr2, *fmtPtr, *errPtr;
928   char         *pre, *suf, *title;
929   size_t len;
930
931   pre = GETMESSAGE(3, 10, "Create Action");
932   suf = GETMESSAGE(7, 11, "Edit Datatype");
933   len = strlen(pre) + strlen(suf) + 4;
934   title = XtMalloc(len);
935   snprintf(title,len - 1, "%s - %s", pre, suf);
936
937   /**************************************************************************/
938   /* Determine the selected list item.                                      */
939   /**************************************************************************/
940   if (XmListGetSelectedPos(CA_FiletypesList, &poslist, &poscnt)) {
941      selecteditem = *poslist;
942      selecteditem--;
943      if (selecteditem >= 0) {
944         pFtD = AD.papFiletypes[selecteditem];
945         pFtD->fsInternal |= CA_FT_EDIT;
946         GetWidgetTextString(CA_DblClkText, &(pFtD->pszOpenCmd));
947         clear_AddFiletype_dialog_fields();
948         init_AddFiletype_dialog_fields(pFtD);
949
950         /********************************************************************/
951         /* Pop up the AddFiletype dialog.                                   */
952         /********************************************************************/
953         XtVaSetValues (AddFiletype,
954                        RES_CONVERT (XmNdialogTitle, title),
955                        XmNuserData, pFtD,
956                        NULL);
957         UxPopupInterface (AddFiletype, no_grab);
958      }
959   } else {
960      msgPtr1 = XtNewString(GETMESSAGE(5, 120,
961                   "You have not selected a Datatype from the\n\
962 'Datatypes That Use This Action' list."));
963      msgPtr2 = XtNewString(GETMESSAGE(5, 130,
964                   "Please select the Datatype you would like to Edit."));
965      fmtPtr = "%s\n%s";
966      len = (strlen(msgPtr1) + strlen(msgPtr2) +
967              strlen(fmtPtr) + 3);
968      errPtr = XtMalloc(len);
969      snprintf(errPtr,len - 1, fmtPtr, msgPtr1, msgPtr2);
970      XtFree(msgPtr2);
971      XtFree(msgPtr1);
972      display_error_message(CreateActionAppShell, errPtr);
973      XtFree(errPtr);
974   }
975   XtFree(title);
976   return;
977 }
978
979 /******************************************************************************/
980 /*                                                                            */
981 /* get_selected_action_icon - determines which action icon is currently       */
982 /*                            selected.                                       */
983 /*                                                                            */
984 /* INPUT: none                                                                */
985 /* OUTPUT: Widget wid - id of selected icon gadget                            */
986 /*                                                                            */
987 /******************************************************************************/
988 Widget get_selected_action_icon (void)
989 {
990 #if 0
991   Widget wid;
992
993   if (_DtIconGetState(CA_LRG_IconGadget)) wid = CA_LRG_IconGadget;
994   else if (_DtIconGetState(CA_MED_IconGadget)) wid = CA_MED_IconGadget;
995   else if (_DtIconGetState(CA_TINY_IconGadget)) wid = CA_TINY_IconGadget;
996   else wid = CA_LRG_IconGadget;
997 #endif
998
999   if (!last_action_pushed) {
1000     last_action_pushed = CA_LRG_IconGadget;
1001   }
1002   return (last_action_pushed);
1003 }
1004
1005 /******************************************************************************/
1006 /*                                                                            */
1007 /* CreateActionAppShellCheckFields                                            */
1008 /*                                                                            */
1009 /* INPUT:  none                                                               */
1010 /* OUTPUT: FALSE  - no errors found                                           */
1011 /*         TRUE   - found errors                                              */
1012 /*                                                                            */
1013 /******************************************************************************/
1014 Boolean CreateActionAppShellCheckFields(void)
1015 {
1016
1017   char    *ptr = (char *)NULL;
1018   char    *ptrPrompt = (char *)NULL;
1019   Boolean bError = FALSE;
1020   char    *msgPtr, *errPtr;
1021
1022   /**************************************************************************/
1023   /* Check if action name is present.                                       */
1024   /**************************************************************************/
1025   if (!bError) {
1026      ptr = (char *)NULL;
1027      GetWidgetTextString(CA_ActionNameTextField, &ptr);
1028 #ifdef DEBUG
1029      printf("Action Name = '%s'\n", ptr);
1030 #endif
1031      if (!ptr) {
1032         msgPtr = GETMESSAGE(5, 10, "The Action Name is missing.\n\
1033 Please enter a name in the 'Action Name' field.");
1034         errPtr = XtNewString(msgPtr);
1035         display_error_message(CreateActionAppShell, errPtr);
1036         XtFree(errPtr);
1037         XmProcessTraversal(CA_ActionNameTextField, XmTRAVERSE_CURRENT);
1038         bError = TRUE;
1039      } else {
1040         XtFree(ptr);
1041      }
1042   }
1043
1044   /**************************************************************************/
1045   /* Check if execute command is present.                                   */
1046   /**************************************************************************/
1047   if (!bError) {
1048      ptr = (char *)NULL;
1049      GetWidgetTextString(CA_DblClkText, &ptr);
1050 #ifdef DEBUG
1051      printf("Exec String = '%s'\n", ptr);
1052 #endif
1053      if (!ptr) {
1054         msgPtr = GETMESSAGE(5, 15, "The execute command is missing.\n\
1055 Please enter a command in the\n\
1056 'Command To Execute When Double-clicked' field.");
1057         errPtr = XtNewString(msgPtr);
1058         display_error_message(CreateActionAppShell, errPtr);
1059         XtFree(errPtr);
1060         XmProcessTraversal(CA_DblClkText, XmTRAVERSE_CURRENT);
1061         bError = TRUE;
1062      } else {
1063         /********************************************************************/
1064         /* Now check to see if there is a prompt string.  If so, make sure  */
1065         /* there is an argument variable within the exec string.            */
1066         /********************************************************************/
1067         GetWidgetTextString(CA_XprtActionOpenText, &ptrPrompt);
1068         if (ptrPrompt) {
1069            if (!strchr(ptr, '$')) {
1070               msgPtr = GETMESSAGE(5, 30, "A variable name is missing in the\n\
1071 'Command To Execute When Double-clicked' field.\n\
1072 Add a variable name for the label you have entered\n\
1073 in the 'When Action Opens, Ask Users for' field.\n\
1074 Valid variable names are $*, $1, $2, ..., $9.");
1075               errPtr = XtNewString(msgPtr);
1076               display_error_message(CreateActionAppShell, errPtr);
1077               XtFree(errPtr);
1078               XmProcessTraversal(CA_DblClkText, XmTRAVERSE_CURRENT);
1079               bError = TRUE;
1080            }
1081            XtFree(ptrPrompt);
1082         }
1083         XtFree(ptr);
1084      }
1085   }
1086
1087   /**************************************************************************/
1088   /* Check if droppable filetypes buttons are set correctly.                */
1089   /**************************************************************************/
1090   if (!bError) {
1091      if ((AD.fsFlags & CA_DF_ONLYFTFILES) && !(AD.papFiletypes)) {
1092         msgPtr = GETMESSAGE(5, 20,
1093                 "The 'Datatypes That Use This Action' list is empty.\n\
1094 You have selected 'Only Above List' in the 'Dropable\n\
1095 Datatypes' field.\n\
1096 Change the Dropable Datatype choice to 'All Datatypes'\n\
1097 or add at least one datatype to the list.");
1098         errPtr = XtNewString(msgPtr);
1099         display_error_message(CreateActionAppShell, errPtr);
1100         XtFree(errPtr);
1101         XmProcessTraversal(CA_AllFiletypesToggle, XmTRAVERSE_CURRENT);
1102         bError = TRUE;
1103      }
1104   }
1105
1106   return(bError);
1107 }
1108
1109 /******************************************************************************/
1110 /*                                                                            */
1111 /* copyString                                                                 */
1112 /*                                                                            */
1113 /* INPUT:                                                                     */
1114 /* OUTPUT:                                                                    */
1115 /*                                                                            */
1116 /*                                                                            */
1117 /******************************************************************************/
1118 char * copyString(char *string)
1119 {
1120   char *newstring;
1121
1122   if (string) {
1123      newstring = (char *)XtMalloc(strlen(string) + 1);
1124      strcpy(newstring, string);
1125   } else {
1126      newstring = (char *)NULL;
1127   }
1128   return(newstring);
1129 }
1130
1131 /******************************************************************************/
1132 /*                                                                            */
1133 /* copyFtD                                                                    */
1134 /*                                                                            */
1135 /* INPUT:                                                                     */
1136 /* OUTPUT:                                                                    */
1137 /*                                                                            */
1138 /*                                                                            */
1139 /******************************************************************************/
1140 FiletypeData * copyFtD(FiletypeData *pFtD)
1141 {
1142   FiletypeData *pcopyFtD;
1143
1144   pcopyFtD = (FiletypeData *)XtMalloc(sizeof(FiletypeData));
1145   memset(pcopyFtD, 0, sizeof(FiletypeData));
1146
1147   if (pFtD->pszName) {
1148      pcopyFtD->pszName = copyString(pFtD->pszName);
1149   }
1150   if (pFtD->pszIcon) {
1151      pcopyFtD->pszIcon = copyString(pFtD->pszIcon);
1152   }
1153   if (pFtD->pszHelp) {
1154      pcopyFtD->pszHelp = copyString(pFtD->pszHelp);
1155   }
1156   if (pFtD->pszOpenCmd) {
1157      pcopyFtD->pszOpenCmd = copyString(pFtD->pszOpenCmd);
1158   }
1159   if (pFtD->pszPrintCmd) {
1160      pcopyFtD->pszPrintCmd = copyString(pFtD->pszPrintCmd);
1161   }
1162   if (pFtD->pszPattern) {
1163      pcopyFtD->pszPattern = copyString(pFtD->pszPattern);
1164   }
1165   if (pFtD->pszPermissions) {
1166      pcopyFtD->pszPermissions = copyString(pFtD->pszPermissions);
1167   }
1168   if (pFtD->pszContents) {
1169      pcopyFtD->pszContents = copyString(pFtD->pszContents);
1170   }
1171
1172   pcopyFtD->sStart = pFtD->sStart;
1173   pcopyFtD->sEnd = pFtD->sEnd;
1174   pcopyFtD->fsFlags = pFtD->fsFlags;
1175   pcopyFtD->fsInternal = pFtD->fsInternal;
1176
1177   return(pcopyFtD);
1178 }
1179
1180 /******************************************************************************/
1181 /*                                                                            */
1182 /* copyAD                                                                     */
1183 /*                                                                            */
1184 /* INPUT:                                                                     */
1185 /* OUTPUT:                                                                    */
1186 /*                                                                            */
1187 /*                                                                            */
1188 /******************************************************************************/
1189 ActionData * copyAD(ActionData *pAD)
1190 {
1191   ActionData *pcopyAD;
1192   int i;
1193
1194   pcopyAD = (ActionData *)XtMalloc(sizeof(ActionData));
1195   if (!pcopyAD) {
1196      return((ActionData *)NULL);
1197   }
1198   memset(pcopyAD, 0, sizeof(ActionData));
1199
1200   if (pAD->pszName) {
1201      pcopyAD->pszName = copyString(pAD->pszName);
1202   }
1203   if (pAD->pszIcon) {
1204      pcopyAD->pszIcon = copyString(pAD->pszIcon);
1205   }
1206   if (pAD->pszCmd) {
1207      pcopyAD->pszCmd = copyString(pAD->pszCmd);
1208   }
1209   if (pAD->pszHelp) {
1210      pcopyAD->pszHelp = copyString(pAD->pszHelp);
1211   }
1212   if (pAD->pszPrompt) {
1213      pcopyAD->pszPrompt = copyString(pAD->pszPrompt);
1214   }
1215   if (pAD->papFiletypes) {
1216      pcopyAD->papFiletypes = (FiletypeData **) XtMalloc(sizeof(FiletypeData *) * (pAD->cFiletypes + 1));
1217      for (i=0; i < pAD->cFiletypes; i++) {
1218         pcopyAD->papFiletypes[i] = copyFtD(pAD->papFiletypes[i]);
1219      }
1220   }
1221   pcopyAD->cFiletypes = pAD->cFiletypes;
1222   pcopyAD->fsFlags = pAD->fsFlags;
1223   return(pcopyAD);
1224 }
1225 /******************************************************************************/
1226 /*                                                                            */
1227 /* compareStrings                                                             */
1228 /*                                                                            */
1229 /* INPUT:  two pointers to char *'s                                           */
1230 /* OUTPUT: 0  they are the same                                               */
1231 /*         1  they are different                                              */
1232 /*                                                                            */
1233 /******************************************************************************/
1234 Boolean compareStrings(char *pszStr1, char *pszStr2)
1235 {
1236   if (pszStr1 || pszStr2) {
1237      if (pszStr1) {
1238         if (pszStr2) {
1239            if (!strcmp(pszStr1, pszStr2)) {
1240               return(EQUAL);
1241            } else {
1242               return(NOT_EQUAL);
1243            }
1244         } else {
1245            return(NOT_EQUAL);
1246         }
1247      } else {
1248         return(NOT_EQUAL);
1249      }
1250   } else {
1251      return(EQUAL);
1252   }
1253 }
1254
1255 /******************************************************************************/
1256 /*                                                                            */
1257 /* compareFtD                                                                 */
1258 /*                                                                            */
1259 /* INPUT:  two pointers to FtD structures                                     */
1260 /* OUTPUT: 0  they are the same                                               */
1261 /*         1  they are different                                              */
1262 /*                                                                            */
1263 /******************************************************************************/
1264 Boolean compareFtD(FiletypeData *pFtD1, FiletypeData *pFtD2)
1265 {
1266   if (compareStrings(pFtD1->pszName, pFtD2->pszName)) {
1267      return(NOT_EQUAL);
1268   }
1269   if (compareStrings(pFtD1->pszIcon, pFtD2->pszIcon)) {
1270      return(NOT_EQUAL);
1271   }
1272   if (compareStrings(pFtD1->pszHelp, pFtD2->pszHelp)) {
1273      return(NOT_EQUAL);
1274   }
1275   if (compareStrings(pFtD1->pszOpenCmd, pFtD2->pszOpenCmd)) {
1276      return(NOT_EQUAL);
1277   }
1278   if (compareStrings(pFtD1->pszPrintCmd, pFtD2->pszPrintCmd)) {
1279      return(NOT_EQUAL);
1280   }
1281   if (compareStrings(pFtD1->pszPattern, pFtD2->pszPattern)) {
1282      return(NOT_EQUAL);
1283   }
1284   if (compareStrings(pFtD1->pszPermissions, pFtD2->pszPermissions)) {
1285      return(NOT_EQUAL);
1286   }
1287   if (compareStrings(pFtD1->pszContents, pFtD2->pszContents)) {
1288      return(NOT_EQUAL);
1289   }
1290   if (pFtD1->fsFlags != pFtD2->fsFlags) {
1291      return(NOT_EQUAL);
1292   }
1293   if (pFtD1->sStart != pFtD2->sStart) {
1294      return(NOT_EQUAL);
1295   }
1296   if (pFtD1->sEnd != pFtD2->sEnd) {
1297      return(NOT_EQUAL);
1298   }
1299
1300   return(EQUAL);
1301 }
1302
1303 /******************************************************************************/
1304 /*                                                                            */
1305 /* compareAD                                                                  */
1306 /*                                                                            */
1307 /* INPUT:  two pointers to AD structures                                      */
1308 /* OUTPUT: 0  they are the same                                               */
1309 /*         1  they are different                                              */
1310 /*                                                                            */
1311 /******************************************************************************/
1312 Boolean compareAD(ActionData *pAD1, ActionData *pAD2)
1313 {
1314   int i;
1315
1316   if (compareStrings(pAD1->pszName, pAD2->pszName)) {
1317      return(NOT_EQUAL);
1318   }
1319   if (compareStrings(pAD1->pszIcon, pAD2->pszIcon)) {
1320      return(NOT_EQUAL);
1321   }
1322   if (compareStrings(pAD1->pszCmd, pAD2->pszCmd)) {
1323      return(NOT_EQUAL);
1324   }
1325   if (compareStrings(pAD1->pszHelp, pAD2->pszHelp)) {
1326      return(NOT_EQUAL);
1327   }
1328   if (compareStrings(pAD1->pszPrompt, pAD2->pszPrompt)) {
1329      return(NOT_EQUAL);
1330   }
1331   if (pAD1->fsFlags != pAD2->fsFlags) {
1332      return(NOT_EQUAL);
1333   }
1334   if (pAD1->cFiletypes != pAD2->cFiletypes) {
1335      return(NOT_EQUAL);
1336   }
1337
1338   if (pAD1->papFiletypes) {
1339      for (i=0; i < pAD1->cFiletypes; i++) {
1340         if (compareFtD(pAD1->papFiletypes[i], pAD2->papFiletypes[i])) {
1341            return(NOT_EQUAL);
1342         }
1343      }
1344   }
1345
1346   return(EQUAL);
1347 }