Use C++ linker
[oweals/cde.git] / cde / programs / dtcreate / cmnrtns.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 /* $XConsortium: cmnrtns.c /main/4 1995/11/01 16:11:08 rswiston $ */
24 /*****************************************************************************/
25 /*                                                                           */
26 /*  cmnrnts.c                                                                */
27 /*                                                                           */
28 /*   Common routines                                                         */
29 /*                                                                           */
30 /*****************************************************************************/
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <Dt/Icon.h>
34 #include <X11/cursorfont.h>
35 #include "UxXt.h"
36
37 #include "dtcreate.h"
38 #include "CreateActionAppShell.h"
39 #include "fileio.h"
40 #include "cmnrtns.h"
41
42 /*****************************************************************************/
43 /*                                                                           */
44 /*  GetBaseName                                                              */
45 /*                                                                           */
46 /*****************************************************************************/
47 char * GetBaseName(char *pszFileName)
48 {
49   char *name;
50
51   name = strrchr(pszFileName, '/');
52   if (name) {
53      name = strtok(name, "/");
54      return(name);
55   } else {
56      return(pszFileName);
57   }
58 }
59
60 /*****************************************************************************/
61 /*                                                                           */
62 /*  ReplaceSpaces                                                            */
63 /*                                                                           */
64 /*****************************************************************************/
65 char * ReplaceSpaces(char *pszName)
66 {
67   char *newName;
68   char *ptr;
69
70   newName = (char *)XtMalloc(strlen(pszName) + 1);
71   memset(newName, 0, sizeof(newName));
72   strcpy(newName, pszName);
73   ptr = strrchr(newName, ' ');
74   if (ptr) {
75      ptr = newName;
76      while ((*ptr) && (ptr = strchr(ptr, ' '))) {
77        *ptr = '_';
78        ptr++;
79      }
80   }
81   return(newName);
82 }
83
84 #if 0
85 /*****************************************************************************/
86 /*                                                                           */
87 /*  GetExtName                                                               */
88 /*                                                                           */
89 /*****************************************************************************/
90 char * GetExtName(char *pszFileName)
91 {
92   char *type;
93
94   type = strrchr(pszFileName, '.');
95   if (type) {
96      type = strtok(type, ".");
97      return(type);
98   } else {
99      return(NULL);
100   }
101 }
102 #endif
103
104 #if 0
105 /*****************************************************************************/
106 /*                                                                           */
107 /*  GetPathName                                                              */
108 /*                                                                           */
109 /*****************************************************************************/
110 char * GetPathName(char *pszFileName)
111 {
112   char *ptr;
113   char *pszPath;
114
115   pszPath = (char *)malloc(strlen(pszFileName) + 1);
116   strcpy(pszPath, pszFileName);
117   ptr = strrchr(pszPath, '/');
118   if (ptr) {
119      *ptr = '\0';
120   } else {
121      free(pszPath);
122      pszPath = (char *)NULL;
123   }
124   return(pszPath);
125 }
126 #endif
127
128 #if 0
129 /*****************************************************************************/
130 /*                                                                           */
131 /*  Change_IconGadget_IconType                                               */
132 /*                                                                           */
133 /*****************************************************************************/
134 void Change_IconGadget_IconType(Widget widIconGadget, char *pszNewType)
135 {
136   char   *pszOldName;
137   char   pszNewName[MAXBUFSIZE];
138   char   *tmpptr;
139   ushort rc;
140
141   XtVaGetValues(widIconGadget, XmNimageName, &pszOldName, NULL);
142   if (pszOldName) {
143      tmpptr = strrchr(pszOldName, '.');
144      *tmpptr = '\0';
145      sprintf(pszNewName, "%s.%s", pszOldName, pszNewType);
146 #ifdef DEBUG
147      printf("monochrome name is '%s'\n", pszNewName); /* debug */
148 #endif
149      if (check_file_exists(pszNewName)) {
150         SET_ICONGADGET_ICON(widIconGadget, pszNewName);
151      } else {
152         SET_ICONGADGET_ICON(widIconGadget, "");
153      }
154   }
155 }
156 #endif
157
158 #if 0
159 /*****************************************************************************/
160 /*                                                                           */
161 /*  Change_IconName_IconType                                                 */
162 /*                                                                           */
163 /*****************************************************************************/
164 char * Change_IconName_IconType(char *pszOldName, char *pszNewType)
165 {
166   char   *tmpptr;
167   ushort rc;
168   char   *pszNewName = (char *)NULL;
169
170   if (pszOldName) {
171      pszNewName = (char *)malloc(strlen(pszOldName) + 10);
172      tmpptr = strrchr(pszOldName, '.');
173      *tmpptr = '\0';
174      sprintf(pszNewName, "%s.%s", pszOldName, pszNewType);
175 #ifdef DEBUG
176      printf("new icon name is '%s'\n", pszNewName);
177 #endif
178      if (!check_file_exists(pszNewName)) {
179         free(pszNewName);
180         pszNewName = (char *)NULL;
181      }
182   }
183   return(pszNewName);
184 }
185 #endif
186
187 /******************************************************************************/
188 /*                                                                            */
189 /* GetCoreName                                                                */
190 /*                                                                            */
191 /******************************************************************************/
192 char * GetCoreName(char *pszFullName)
193 {
194   char *name;
195   char *ptr;
196   char *newName;
197
198   name = strrchr(pszFullName, '/');
199   if (name) {
200      name = strtok(name, "/");
201   } else {
202      name = pszFullName;
203   }
204   newName = (char *)malloc(strlen(name) + 1);
205   memset(newName, 0, sizeof(newName));
206   strcpy(newName, name);
207   ptr = strrchr(newName, '.');
208   if (ptr) {
209     *ptr = '\0';
210   }
211   return(newName);
212 }
213
214 /******************************************************************************/
215 /*                                                                            */
216 /* load_icons - puts selected icons into the appropriate icon gadget.         */
217 /*                                                                            */
218 /* INPUT: Widget wid - OK button on Open File dialog,                         */
219 /*        XtPointer client_data                                               */
220 /*        XmFileSelectionBoxCallbackStruct *cbs                               */
221 /* OUTPUT: none                                                               */
222 /*                                                                            */
223 /******************************************************************************/
224 void load_icons (Widget wid, XtPointer client_data,
225                  XmFileSelectionBoxCallbackStruct *cbs)
226 {
227   char          *full_name, *path_and_base_name, *type_name, *size_name;
228   char          *base_name;
229   char          *ptr;
230   int           iSource;
231   FiletypeData  *pFtD;
232
233   /*****************************************/
234   /* Get icon name and separate into parts */
235   /*****************************************/
236   full_name = (char *)client_data;
237   path_and_base_name = (char *)malloc(strlen(full_name)+1);
238   strcpy(path_and_base_name, full_name);
239
240   /*****************************************/
241   /* Strip off icon type extension.        */
242   /*****************************************/
243   ptr = strrchr(path_and_base_name, '.');
244   if (ptr) {
245      type_name = strtok(ptr, ".");
246      *ptr = '\0';
247   } else {
248      type_name = (char *)NULL;
249   }
250
251   /*****************************************/
252   /* Get size extention.                   */
253   /*****************************************/
254   ptr = strrchr(path_and_base_name, '.');
255   if (ptr) {
256      size_name = strtok(ptr, ".");
257      *ptr = '\0';
258   } else {
259      size_name = (char *)NULL;
260   }
261
262 #ifdef DEBUG
263     printf("path&base = %s\n", path_and_base_name); /* debug */
264     printf("type      = %s\n", type_name); /* debug */
265     printf("size      = %s\n", size_name); /* debug */
266 #endif
267
268   /* ***** cmvc 6715 *****
269   if ((!path_and_base_name) || (!type_name) || (!size_name)) {
270     printf ("'%s' is not a proper icon file name!\n", full_name);
271   }
272   else
273   */
274     {
275     XtVaGetValues(IconSelector, XmNuserData, &iSource, NULL);
276     base_name = GetBaseName(path_and_base_name);
277     ptr = XtMalloc(strlen(base_name) + 1);
278     strcpy(ptr, base_name);
279     switch (iSource) {
280       case CA_ACTION_ICONS:
281            AD.pszIcon = ptr;
282            SetIconData(CA_LRG_IconGadget, path_and_base_name, Large_Icon);
283            SetIconData(CA_MED_IconGadget, path_and_base_name, Medium_Icon);
284            SetIconData(CA_TINY_IconGadget, path_and_base_name, Tiny_Icon);
285            break;
286       case CA_FILETYPE_ICONS:
287            XtVaGetValues(AddFiletype, XmNuserData, &pFtD, NULL);
288            pFtD->pszIcon = ptr;
289            SetIconData(AF_MED_IconGadget, path_and_base_name, Medium_Icon);
290            SetIconData(AF_TINY_IconGadget, path_and_base_name, Tiny_Icon);
291            break;
292     }
293   }
294   free(path_and_base_name);
295   return;
296 }
297
298 /******************************************************************************/
299 /*                                                                            */
300 /* GetWidgetTextString                                                        */
301 /*                                                                            */
302 /* INPUT: Widget wid - TextField widget to get string from.                   */
303 /*        Pointer to variable to store string                                 */
304 /*                                                                            */
305 /* OUTPUT: none                                                               */
306 /*                                                                            */
307 /******************************************************************************/
308 void GetWidgetTextString (Widget wid, char **ppszText)
309 {
310   char *pszTmp;
311
312   if (*ppszText) {
313      XtFree(*ppszText);
314      *ppszText = (char *)NULL;
315   }
316   if (XmIsTextField(wid)) {
317      pszTmp = XmTextFieldGetString (wid);
318   } else if (XmIsText(wid)) {
319      pszTmp = XmTextGetString (wid);
320   }
321
322   if (pszTmp) {
323      if (!strcmp(pszTmp, "")) {
324         XtFree(pszTmp);
325         pszTmp = (char *)NULL;
326      }
327      *ppszText = pszTmp;
328   }
329 }
330
331 /******************************************************************************/
332 /*                                                                            */
333 /* PutWidgetTextString                                                        */
334 /*                                                                            */
335 /* INPUT: Widget wid - Widget whose text string is being set                  */
336 /*        Pointer to text string.                                             */
337 /*                                                                            */
338 /* OUTPUT: none                                                               */
339 /*                                                                            */
340 /******************************************************************************/
341 void PutWidgetTextString (Widget wid, char *pszText)
342 {
343   if (pszText) {
344      if (XmIsTextField(wid)) {
345         XmTextFieldSetString (wid, pszText);
346      } else if (XmIsText(wid)) {
347         XmTextSetString (wid, pszText);
348      }
349   }
350 }
351
352 /******************************************************************************/
353 /*                                                                            */
354 /* GetIconSearchPathList                                                      */
355 /*                                                                            */
356 /* INPUT:  none                                                               */
357 /*                                                                            */
358 /* OUTPUT: none                                                               */
359 /*                                                                            */
360 /******************************************************************************/
361 char **GetIconSearchPathList(void)
362 {
363   char    *iconpath = (char *)NULL;
364   char    *ptr;
365   char    *tmpptr;
366   char    *strip;
367   char    *path;
368   int     i;
369   int     count;
370   int     size;
371   char    **pplist;
372   char    *lang;
373   int     langsize;
374   static  char *default_list1[] = {"~/.dt/icons", "/etc/dt/appconfig/icons/C", "/usr/dt/appconfig/icons/C"};
375   static  char *default_list2[] = {"/etc/dt/appconfig/icons/C", "/usr/dt/appconfig/icons/C"};
376   char    **default_list;
377   Boolean bFound;
378   char    *pszEnvVar;
379
380   /**************************************************************************/
381   /* Get contents of icon search path environment variable.                 */
382   /**************************************************************************/
383   pszEnvVar = getenv("XMICONSEARCHPATH");
384   if ( pszEnvVar && strlen(pszEnvVar) ) {
385      iconpath = (char *)malloc(strlen(pszEnvVar) + 1);
386      strcpy(iconpath, pszEnvVar);
387   }
388
389   /**************************************************************************/
390   /* If no iconpath then return an appropriate default.                     */
391   /**************************************************************************/
392   if (!iconpath) {
393      pszEnvVar = getenv("HOME");
394      if (pszEnvVar && strlen(pszEnvVar)) {
395         default_list = default_list1;
396         count = sizeof(default_list1)/sizeof(void *);
397      } else {
398         default_list = default_list2;
399         count = sizeof(default_list2)/sizeof(void *);
400      }
401      pplist = (char **)calloc((count + 1), sizeof(void *));
402      for (i=0; i < count; i++) {
403         if (strchr(default_list[i], '~')) {
404            if (pszEnvVar && strlen(pszEnvVar)) {
405               pplist[i] = calloc(strlen(default_list[i]) + strlen(pszEnvVar) + 1, sizeof(char));
406               strcpy(pplist[i], pszEnvVar);
407            } else {
408               pplist[i] = calloc(strlen(default_list[i]) + 1, sizeof(char));
409            }
410            strcat(pplist[i], &(default_list[i][1]));
411         } else {
412            pplist[i] = calloc(strlen(default_list[i]) + 1,sizeof(char));
413            strcpy(pplist[i], default_list[i]);
414         }
415      }
416      return(pplist);
417   }
418
419 #ifdef DEBUG
420   printf("Path = %s\n", iconpath);
421 #endif
422
423   /**************************************************************************/
424   /* Iterate through the search path once to get total count of individual  */
425   /* paths within the search path.                                          */
426   /**************************************************************************/
427   count = 0;
428   ptr = iconpath;
429   while (ptr) {
430     tmpptr = ptr;
431     ptr = strchr(ptr, ':');
432     /*printf("ptr = %s\n", ptr);*/
433     if (tmpptr != ptr) {
434        count++;
435        if ((ptr) && (ptr[1] != '\0')) {
436           for (; ptr[0] == ':'; ptr++);
437        } else {
438           ptr = (char *)NULL;
439        }
440     }
441   }
442
443   /**************************************************************************/
444   /* Debug information.                                                     */
445   /**************************************************************************/
446 #ifdef DEBUG
447   printf("IconSearchPath = %s\n", iconpath);
448   printf("# of paths = %d\n", count);
449 #endif
450
451   /**************************************************************************/
452   /* Get contents of lang environment variable.                             */
453   /**************************************************************************/
454   lang = getenv("LANG");
455   if (lang) {
456      langsize = strlen(lang);
457   } else {
458      langsize = 0;
459   }
460
461   /**************************************************************************/
462   /* Allocate the array of pointers to store the individual path strings.   */
463   /**************************************************************************/
464   pplist = (char **)calloc((count+1), sizeof(void *));
465
466   /**************************************************************************/
467   /* Iterate through again to allocate space for each individual path and   */
468   /* store that path.                                                       */
469   /**************************************************************************/
470   count = 0;
471   ptr = iconpath;
472   while (ptr) {
473     tmpptr = ptr;
474     ptr = strchr(ptr, ':');
475     if (tmpptr != ptr) {
476        /*********************************************************************/
477        /* Make tmpptr the path.  Also move to the next path in the search   */
478        /* path.                                                             */
479        /*********************************************************************/
480        strip = ptr;
481        if ((ptr) && (ptr[1] != '\0')) {
482           for (; ptr[0] == ':'; ptr++);
483           *strip = '\0';
484        } else {
485           if (ptr) {
486              *strip = '\0';
487           }
488           ptr = (char *)NULL;
489        }
490
491        /*********************************************************************/
492        /* If %L in path, then add size of lang variable to it when          */
493        /* allocating array for path.                                        */
494        /*********************************************************************/
495        if (strip = strstr(tmpptr, "%L")) {
496          path = malloc(strlen(tmpptr) + langsize + 1);
497        } else {
498          path = malloc(strlen(tmpptr) + 1);
499        }
500        strcpy(path, tmpptr);
501
502        /*********************************************************************/
503        /* Strip off the /%B... stuff off of the path if there is some.      */
504        /*********************************************************************/
505        if (strip = strstr(path, "%B")) {
506           *strip = '\0';
507        }
508
509        /*********************************************************************/
510        /* Now replace %L with lang variable.                                */
511        /*********************************************************************/
512        if (strip = strstr(path, "%L")) {
513           *strip = '\0';
514           if (langsize) {
515              strcat(path, lang);
516           }
517        }
518
519        /*********************************************************************/
520        /* Remove slash from end of path if there is one.                    */
521        /*********************************************************************/
522        size = strlen(path);
523        if (size > 0) {
524           if (path[size - 1] == '/') {
525              path[size - 1] = '\0';
526           }
527
528 #ifdef DEBUG
529           printf("new path = %s\n", path);
530 #endif
531
532           /***************************************************************/
533           /* See if path is already in our list.                         */
534           /***************************************************************/
535           bFound = FALSE;
536           for (i=0; (i < count) && (!bFound); i++) {
537              if (!(strcmp(pplist[i], path))) {
538                 bFound = TRUE;
539              }
540           }
541           /***************************************************************/
542           /* If not in list, then add to list.                           */
543           /***************************************************************/
544           if (!bFound) {
545              pplist[count] = path;
546              count++;
547           /***************************************************************/
548           /* Else, just free resources.                                  */
549           /***************************************************************/
550           } else {
551              free(path);
552           }
553        }
554
555 #ifdef DEBUG
556        printf("Path%d = %s\n", count, pplist[count]);
557 #endif
558
559 #if 0
560        **** moving this up a bit in the code ****
561
562        /*********************************************************************/
563        /* Get the next path in the icon search path.                        */
564        /*********************************************************************/
565        if ((ptr) && (ptr[1] != '\0')) {
566           for (; ptr[0] == ':'; ptr++);
567        } else {
568           ptr = (char *)NULL;
569        }
570 #endif
571     }
572   }
573   free(iconpath);
574   return(pplist);
575 }
576
577 /******************************************************************************/
578 /*                                                                            */
579 /* FreeIconSearchPathList                                                     */
580 /*                                                                            */
581 /* INPUT:  none                                                               */
582 /*                                                                            */
583 /* OUTPUT: none                                                               */
584 /*                                                                            */
585 /******************************************************************************/
586 void FreeIconSearchPathList(char **pplist)
587 {
588   char *ptr;
589   int  i;
590
591   /**************************************************************************/
592   /* Iterate through the search path once to get total count of individual  */
593   /* paths within the search path.                                          */
594   /**************************************************************************/
595   if (pplist) {
596      for (i = 0; pplist[i]; free(pplist[i]), i++);
597      /*
598      i = 0;
599      while (pplist[i]) {
600        free(pplist[i]);
601      }
602      */
603      free(pplist);
604   }
605 }
606 /******************************************************************************/
607 /*                                                                            */
608 /* TurnOnHourGlassAllWindows                                                  */
609 /*                                                                            */
610 /* INPUT:  none                                                               */
611 /*                                                                            */
612 /* OUTPUT: none                                                               */
613 /*                                                                            */
614 /******************************************************************************/
615 void TurnOnHourGlassAllWindows()
616 {
617   _DtTurnOnHourGlass(CreateActionAppShell);
618   if ( (AddFiletype) &&
619        (XtIsRealized(AddFiletype)) &&
620        (XtIsManaged(AddFiletype)) ) {
621      _DtTurnOnHourGlass(AddFiletype);
622   }
623   if ( (FileCharacteristics) &&
624        (XtIsRealized(FileCharacteristics)) &&
625        (XtIsManaged(FileCharacteristics)) ) {
626      _DtTurnOnHourGlass(FileCharacteristics);
627   }
628   if ( (IconSelector) &&
629        (XtIsRealized(IconSelector)) &&
630        (XtIsManaged(IconSelector)) ) {
631      _DtTurnOnHourGlass(IconSelector);
632   }
633   if ( (OpenFile) &&
634        (XtIsRealized(OpenFile)) &&
635        (XtIsManaged(OpenFile)) ) {
636      _DtTurnOnHourGlass(OpenFile);
637   }
638 }
639 /******************************************************************************/
640 /*                                                                            */
641 /* TurnOffHourGlassAllWindows                                                 */
642 /*                                                                            */
643 /* INPUT:  none                                                               */
644 /*                                                                            */
645 /* OUTPUT: none                                                               */
646 /*                                                                            */
647 /******************************************************************************/
648 void TurnOffHourGlassAllWindows()
649 {
650   _DtTurnOffHourGlass(CreateActionAppShell);
651   if ( (AddFiletype) &&
652        (XtIsRealized(AddFiletype)) &&
653        (XtIsManaged(AddFiletype)) ) {
654      _DtTurnOffHourGlass(AddFiletype);
655   }
656   if ( (FileCharacteristics) &&
657        (XtIsRealized(FileCharacteristics)) &&
658        (XtIsManaged(FileCharacteristics)) ) {
659      _DtTurnOffHourGlass(FileCharacteristics);
660   }
661   if ( (IconSelector) &&
662        (XtIsRealized(IconSelector)) &&
663        (XtIsManaged(IconSelector)) ) {
664      _DtTurnOffHourGlass(IconSelector);
665   }
666   if ( (OpenFile) &&
667        (XtIsRealized(OpenFile)) &&
668        (XtIsManaged(OpenFile)) ) {
669      _DtTurnOffHourGlass(OpenFile);
670   }
671 }
672 /******************************************************************************/
673 /*                                                                            */
674 /* SetIconData                                                                */
675 /*                                                                            */
676 /* INPUT:  icon gadget widget id                                              */
677 /*         icon file base name                                                */
678 /*                                                                            */
679 /* OUTPUT: none                                                               */
680 /*                                                                            */
681 /******************************************************************************/
682 void SetIconData(Widget wid, char *pszIconFile, enum icon_size_range enumIconSize)
683 {
684   char      pmFileName[MAXBUFSIZE];
685   char      bmFileName[MAXBUFSIZE];
686   char      pszSize[MAX_EXT_SIZE];
687   IconData  *pIconData;
688   char      *pszName;
689
690 #if 0
691   switch (enumIconSize) {
692     case Large_Icon :
693                strcpy(pszSize, LARGE_EXT);
694                break;
695     case Medium_Icon :
696                strcpy(pszSize, MEDIUM_EXT);
697                break;
698     case Tiny_Icon :
699                strcpy(pszSize, TINY_EXT);
700                break;
701   }
702
703   sprintf(pmFileName, "%s%s%s", pszIconFile, pszSize, PIXMAP_EXT );
704   sprintf(bmFileName, "%s%s%s", pszIconFile, pszSize, BITMAP_EXT );
705 #endif
706
707   pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, PIXMAP_EXT, FALSE);
708   strcpy(pmFileName, pszName);
709   if (pszName) XtFree(pszName);
710
711   pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, BITMAP_EXT, FALSE);
712   strcpy(bmFileName, pszName);
713   if (pszName) XtFree(pszName);
714
715   pIconData = GetIconDataFromWid(wid);
716   if (pIconData) {
717      if ( (pIconData->pmDirtyBit) &&
718           (pIconData->pmFileName) &&
719           (strlen(pIconData->pmFileName)) ) {
720 #ifdef DEBUG
721         printf("SetIconData: unlink '%s'\n", pIconData->pmFileName);  /* debug */
722 #endif
723         unlink(pIconData->pmFileName);
724         pIconData->pmDirtyBit = False;
725      }
726      strcpy(pIconData->pmFileName, pmFileName);
727
728      if ( (pIconData->bmDirtyBit) &&
729           (pIconData->bmFileName) &&
730           (strlen(pIconData->bmFileName)) ) {
731 #ifdef DEBUG
732         printf("SetIconData: unlink '%s'\n", pIconData->bmFileName);  /* debug */
733 #endif
734         unlink(pIconData->bmFileName);
735         pIconData->bmDirtyBit = False;
736      }
737      strcpy(pIconData->bmFileName, bmFileName);
738
739      if (bShowPixmaps) {
740         SET_ICONGADGET_ICON(wid, pmFileName);
741      } else {
742         SET_ICONGADGET_ICON(wid, bmFileName);
743      }
744   }
745 }
746 /******************************************************************************/
747 /*                                                                            */
748 /* GetCorrectIconType                                                         */
749 /*                                                                            */
750 /* INPUT:  icon file name                                                     */
751 /*                                                                            */
752 /* OUTPUT: correct icon type of icon file name passed                         */
753 /*                                                                            */
754 /******************************************************************************/
755 char * GetCorrectIconType(char *pszIconFile)
756 {
757   char  *pszTmp;
758   char  *ptr;
759   char  pszNewType[MAX_EXT_SIZE];
760
761   if (bShowPixmaps) {
762      strcpy(pszNewType, PIXMAP_EXT);
763   } else {
764      strcpy(pszNewType, BITMAP_EXT);
765   }
766
767   if (pszIconFile) {
768      pszTmp = XtMalloc(strlen(pszIconFile) + strlen(pszNewType) + 1);
769      if (!pszTmp) return((char *)NULL);
770      strcpy(pszTmp, pszIconFile);
771      ptr = strrchr(pszTmp, '.');
772      if (ptr) {
773         strcpy(ptr, pszNewType);
774      }
775   } else {
776      pszTmp = (char *)NULL;
777   }
778   return (pszTmp);
779 }
780 /******************************************************************************/
781 /*                                                                            */
782 /* CreateMaskName                                                             */
783 /*                                                                            */
784 /* INPUT:  icon file name                                                     */
785 /*                                                                            */
786 /* OUTPUT: mask file name for icon name passed in                             */
787 /*                                                                            */
788 /******************************************************************************/
789 char * CreateMaskName(char *pszIconName)
790 {
791   char *pszTmpName;
792   char *ptr;
793   char *pszNewName;
794   char *type_name;
795   char *size_name;
796   char type_ext[MAX_EXT_SIZE + 2];
797   char size_ext[MAX_EXT_SIZE + 2];
798   int  bytesneeded = 0;
799
800   /***************************************************************/
801   /* initialize temp arrays                                      */
802   /***************************************************************/
803   type_ext[0] = '\0';
804   size_ext[0] = '\0';
805
806   /***************************************************************/
807   /* alloc memory for temporary name                             */
808   /***************************************************************/
809   pszTmpName = (char *)XtMalloc(strlen(pszIconName) + 1);
810   if (pszTmpName) {
811      strcpy(pszTmpName, pszIconName);
812   } else {
813      return((char *)NULL);
814   }
815
816   /*****************************************/
817   /* Strip off icon type extension.        */
818   /*****************************************/
819   ptr = strrchr(pszTmpName, '.');
820   if (ptr) {
821      type_name = strtok(ptr, ".");
822      *ptr = '\0';
823   } else {
824      type_name = (char *)NULL;
825   }
826
827   /*****************************************/
828   /* Get size extention.                   */
829   /*****************************************/
830   ptr = strrchr(pszTmpName, '.');
831   if (ptr) {
832      size_name = strtok(ptr, ".");
833      *ptr = '\0';
834   } else {
835      size_name = (char *)NULL;
836   }
837
838   /*****************************************/
839   /* Alloc the storage for the new name    */
840   /*****************************************/
841   bytesneeded += ((pszTmpName) ? strlen(pszTmpName) : 0);
842   bytesneeded += strlen("_m..");
843   bytesneeded += ((size_name) ? strlen(size_name) : 0);
844   bytesneeded += ((type_name) ? strlen(type_name) : 0);
845   pszNewName = (char *)XtMalloc(bytesneeded + 1);
846
847   /*****************************************/
848   /* Create extension names                */
849   /*****************************************/
850   if (size_name) {
851      sprintf(size_ext, ".%s", size_name);
852   }
853   if (type_name) {
854      sprintf(type_ext, ".%s", type_name);
855   }
856   /*****************************************/
857   /* And construct the new name from pieces*/
858   /*****************************************/
859   if (pszNewName) {
860      if (size_name) {
861         sprintf(pszNewName, "%s%s_m%s", pszTmpName, size_ext, type_ext);
862      } else {
863         sprintf(pszNewName, "%s_m%s%s", pszTmpName, size_ext, type_ext);
864      }
865   }
866   if (pszTmpName) XtFree(pszTmpName);
867
868 #ifdef DEBUG
869   printf("Mask file name = '%s'\n", pszNewName); /* debug */
870 #endif
871
872   return(pszNewName);
873 }
874