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