123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* $XConsortium: cmnrtns.c /main/4 1995/11/01 16:11:08 rswiston $ */
- /*****************************************************************************/
- /* */
- /* cmnrnts.c */
- /* */
- /* Common routines */
- /* */
- /*****************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <Dt/Icon.h>
- #include <X11/cursorfont.h>
- #include "UxXt.h"
- #include <libgen.h>
- #include <Dt/HourGlass.h>
- #include "dtcreate.h"
- #include "CreateActionAppShell.h"
- #include "fileio.h"
- #include "cmnrtns.h"
- /*****************************************************************************/
- /* */
- /* ReplaceSpaces */
- /* */
- /*****************************************************************************/
- char * ReplaceSpaces(char *pszName)
- {
- char *newName;
- char *ptr;
- newName = (char *)XtMalloc(strlen(pszName) + 1);
- memset(newName, 0, strlen(pszName) + 1);
- strcpy(newName, pszName);
- ptr = strrchr(newName, ' ');
- if (ptr) {
- ptr = newName;
- while ((*ptr) && (ptr = strchr(ptr, ' '))) {
- *ptr = '_';
- ptr++;
- }
- }
- return(newName);
- }
- #if 0
- /*****************************************************************************/
- /* */
- /* GetExtName */
- /* */
- /*****************************************************************************/
- char * GetExtName(char *pszFileName)
- {
- char *type;
- type = strrchr(pszFileName, '.');
- if (type) {
- type = strtok(type, ".");
- return(type);
- } else {
- return(NULL);
- }
- }
- #endif
- #if 0
- /*****************************************************************************/
- /* */
- /* GetPathName */
- /* */
- /*****************************************************************************/
- char * GetPathName(char *pszFileName)
- {
- char *ptr;
- char *pszPath;
- pszPath = (char *)malloc(strlen(pszFileName) + 1);
- strcpy(pszPath, pszFileName);
- ptr = strrchr(pszPath, '/');
- if (ptr) {
- *ptr = '\0';
- } else {
- free(pszPath);
- pszPath = (char *)NULL;
- }
- return(pszPath);
- }
- #endif
- #if 0
- /*****************************************************************************/
- /* */
- /* Change_IconGadget_IconType */
- /* */
- /*****************************************************************************/
- void Change_IconGadget_IconType(Widget widIconGadget, char *pszNewType)
- {
- char *pszOldName;
- char pszNewName[MAXBUFSIZE];
- char *tmpptr;
- ushort rc;
- XtVaGetValues(widIconGadget, XmNimageName, &pszOldName, NULL);
- if (pszOldName) {
- tmpptr = strrchr(pszOldName, '.');
- *tmpptr = '\0';
- sprintf(pszNewName, "%s.%s", pszOldName, pszNewType);
- #ifdef DEBUG
- printf("monochrome name is '%s'\n", pszNewName); /* debug */
- #endif
- if (check_file_exists(pszNewName)) {
- SET_ICONGADGET_ICON(widIconGadget, pszNewName);
- } else {
- SET_ICONGADGET_ICON(widIconGadget, "");
- }
- }
- }
- #endif
- #if 0
- /*****************************************************************************/
- /* */
- /* Change_IconName_IconType */
- /* */
- /*****************************************************************************/
- char * Change_IconName_IconType(char *pszOldName, char *pszNewType)
- {
- char *tmpptr;
- ushort rc;
- char *pszNewName = (char *)NULL;
- if (pszOldName) {
- pszNewName = (char *)malloc(strlen(pszOldName) + 10);
- tmpptr = strrchr(pszOldName, '.');
- *tmpptr = '\0';
- sprintf(pszNewName, "%s.%s", pszOldName, pszNewType);
- #ifdef DEBUG
- printf("new icon name is '%s'\n", pszNewName);
- #endif
- if (!check_file_exists(pszNewName)) {
- free(pszNewName);
- pszNewName = (char *)NULL;
- }
- }
- return(pszNewName);
- }
- #endif
- /******************************************************************************/
- /* */
- /* GetCoreName */
- /* */
- /******************************************************************************/
- char * GetCoreName(char *pszFullName)
- {
- char *name;
- char *ptr;
- char *newName;
- name = strrchr(pszFullName, '/');
- if (name) {
- name = strtok(name, "/");
- } else {
- name = pszFullName;
- }
- newName = (char *)malloc(strlen(name) + 1);
- memset(newName, 0, strlen(name) + 1);
- strcpy(newName, name);
- ptr = strrchr(newName, '.');
- if (ptr) {
- *ptr = '\0';
- }
- return(newName);
- }
- /******************************************************************************/
- /* */
- /* load_icons - puts selected icons into the appropriate icon gadget. */
- /* */
- /* INPUT: Widget wid - OK button on Open File dialog, */
- /* XtPointer client_data */
- /* XmFileSelectionBoxCallbackStruct *cbs */
- /* OUTPUT: none */
- /* */
- /******************************************************************************/
- void load_icons (Widget wid, XtPointer client_data,
- XmFileSelectionBoxCallbackStruct *cbs)
- {
- char *full_name, *path_and_base_name, *type_name, *size_name;
- char *base_name;
- char *ptr;
- XtArgVal /* int */ iSource;
- FiletypeData *pFtD;
- /*****************************************/
- /* Get icon name and separate into parts */
- /*****************************************/
- full_name = (char *)client_data;
- path_and_base_name = (char *)malloc(strlen(full_name)+1);
- strcpy(path_and_base_name, full_name);
- /*****************************************/
- /* Strip off icon type extension. */
- /*****************************************/
- ptr = strrchr(path_and_base_name, '.');
- if (ptr) {
- type_name = strtok(ptr, ".");
- *ptr = '\0';
- } else {
- type_name = (char *)NULL;
- }
- /*****************************************/
- /* Get size extention. */
- /*****************************************/
- ptr = strrchr(path_and_base_name, '.');
- if (ptr) {
- size_name = strtok(ptr, ".");
- *ptr = '\0';
- } else {
- size_name = (char *)NULL;
- }
- #ifdef DEBUG
- printf("path&base = %s\n", path_and_base_name); /* debug */
- printf("type = %s\n", type_name); /* debug */
- printf("size = %s\n", size_name); /* debug */
- #endif
- /* ***** cmvc 6715 *****
- if ((!path_and_base_name) || (!type_name) || (!size_name)) {
- printf ("'%s' is not a proper icon file name!\n", full_name);
- }
- else
- */
- {
- XtVaGetValues(IconSelector, XmNuserData, &iSource, NULL);
- base_name = basename(path_and_base_name);
- ptr = XtMalloc(strlen(base_name) + 1);
- strcpy(ptr, base_name);
- switch (iSource) {
- case CA_ACTION_ICONS:
- AD.pszIcon = ptr;
- SetIconData(CA_LRG_IconGadget, path_and_base_name, Large_Icon);
- SetIconData(CA_MED_IconGadget, path_and_base_name, Medium_Icon);
- SetIconData(CA_TINY_IconGadget, path_and_base_name, Tiny_Icon);
- break;
- case CA_FILETYPE_ICONS:
- XtVaGetValues(AddFiletype, XmNuserData, &pFtD, NULL);
- pFtD->pszIcon = ptr;
- SetIconData(AF_MED_IconGadget, path_and_base_name, Medium_Icon);
- SetIconData(AF_TINY_IconGadget, path_and_base_name, Tiny_Icon);
- break;
- }
- }
- free(path_and_base_name);
- return;
- }
- /******************************************************************************/
- /* */
- /* GetWidgetTextString */
- /* */
- /* INPUT: Widget wid - TextField widget to get string from. */
- /* Pointer to variable to store string */
- /* */
- /* OUTPUT: none */
- /* */
- /******************************************************************************/
- void GetWidgetTextString (Widget wid, char **ppszText)
- {
- char *pszTmp = NULL;
- if (*ppszText) {
- XtFree(*ppszText);
- *ppszText = (char *)NULL;
- }
- if (XmIsTextField(wid)) {
- pszTmp = XmTextFieldGetString (wid);
- } else if (XmIsText(wid)) {
- pszTmp = XmTextGetString (wid);
- }
- if (pszTmp) {
- if (!strcmp(pszTmp, "")) {
- XtFree(pszTmp);
- pszTmp = (char *)NULL;
- }
- *ppszText = pszTmp;
- }
- }
- /******************************************************************************/
- /* */
- /* PutWidgetTextString */
- /* */
- /* INPUT: Widget wid - Widget whose text string is being set */
- /* Pointer to text string. */
- /* */
- /* OUTPUT: none */
- /* */
- /******************************************************************************/
- void PutWidgetTextString (Widget wid, char *pszText)
- {
- if (pszText) {
- if (XmIsTextField(wid)) {
- XmTextFieldSetString (wid, pszText);
- } else if (XmIsText(wid)) {
- XmTextSetString (wid, pszText);
- }
- }
- }
- /******************************************************************************/
- /* */
- /* GetIconSearchPathList */
- /* */
- /* INPUT: none */
- /* */
- /* OUTPUT: none */
- /* */
- /******************************************************************************/
- char **GetIconSearchPathList(void)
- {
- char *iconpath = (char *)NULL;
- char *ptr;
- char *tmpptr;
- char *strip;
- char *path;
- int i;
- int count;
- int size;
- char **pplist;
- char *lang;
- int langsize;
- static char *default_list1[] = {"~/.dt/icons", "/etc/dt/appconfig/icons/C", "/usr/dt/appconfig/icons/C"};
- static char *default_list2[] = {"/etc/dt/appconfig/icons/C", "/usr/dt/appconfig/icons/C"};
- char **default_list;
- Boolean bFound;
- char *pszEnvVar;
- /**************************************************************************/
- /* Get contents of icon search path environment variable. */
- /**************************************************************************/
- pszEnvVar = getenv("XMICONSEARCHPATH");
- if ( pszEnvVar && strlen(pszEnvVar) ) {
- iconpath = (char *)malloc(strlen(pszEnvVar) + 1);
- strcpy(iconpath, pszEnvVar);
- }
- /**************************************************************************/
- /* If no iconpath then return an appropriate default. */
- /**************************************************************************/
- if (!iconpath) {
- pszEnvVar = getenv("HOME");
- if (pszEnvVar && strlen(pszEnvVar)) {
- default_list = default_list1;
- count = sizeof(default_list1)/sizeof(void *);
- } else {
- default_list = default_list2;
- count = sizeof(default_list2)/sizeof(void *);
- }
- pplist = (char **)calloc((count + 1), sizeof(void *));
- for (i=0; i < count; i++) {
- if (strchr(default_list[i], '~')) {
- if (pszEnvVar && strlen(pszEnvVar)) {
- pplist[i] = calloc(strlen(default_list[i]) + strlen(pszEnvVar) + 1, sizeof(char));
- strcpy(pplist[i], pszEnvVar);
- } else {
- pplist[i] = calloc(strlen(default_list[i]) + 1, sizeof(char));
- }
- strcat(pplist[i], &(default_list[i][1]));
- } else {
- pplist[i] = calloc(strlen(default_list[i]) + 1,sizeof(char));
- strcpy(pplist[i], default_list[i]);
- }
- }
- return(pplist);
- }
- #ifdef DEBUG
- printf("Path = %s\n", iconpath);
- #endif
- /**************************************************************************/
- /* Iterate through the search path once to get total count of individual */
- /* paths within the search path. */
- /**************************************************************************/
- count = 0;
- ptr = iconpath;
- while (ptr) {
- tmpptr = ptr;
- ptr = strchr(ptr, ':');
- /*printf("ptr = %s\n", ptr);*/
- if (tmpptr != ptr) {
- count++;
- if ((ptr) && (ptr[1] != '\0')) {
- for (; ptr[0] == ':'; ptr++);
- } else {
- ptr = (char *)NULL;
- }
- }
- }
- /**************************************************************************/
- /* Debug information. */
- /**************************************************************************/
- #ifdef DEBUG
- printf("IconSearchPath = %s\n", iconpath);
- printf("# of paths = %d\n", count);
- #endif
- /**************************************************************************/
- /* Get contents of lang environment variable. */
- /**************************************************************************/
- lang = getenv("LANG");
- if (lang) {
- langsize = strlen(lang);
- } else {
- langsize = 0;
- }
- /**************************************************************************/
- /* Allocate the array of pointers to store the individual path strings. */
- /**************************************************************************/
- pplist = (char **)calloc((count+1), sizeof(void *));
- /**************************************************************************/
- /* Iterate through again to allocate space for each individual path and */
- /* store that path. */
- /**************************************************************************/
- count = 0;
- ptr = iconpath;
- while (ptr) {
- tmpptr = ptr;
- ptr = strchr(ptr, ':');
- if (tmpptr != ptr) {
- /*********************************************************************/
- /* Make tmpptr the path. Also move to the next path in the search */
- /* path. */
- /*********************************************************************/
- strip = ptr;
- if ((ptr) && (ptr[1] != '\0')) {
- for (; ptr[0] == ':'; ptr++);
- *strip = '\0';
- } else {
- if (ptr) {
- *strip = '\0';
- }
- ptr = (char *)NULL;
- }
- /*********************************************************************/
- /* If %L in path, then add size of lang variable to it when */
- /* allocating array for path. */
- /*********************************************************************/
- if (strip = strstr(tmpptr, "%L")) {
- path = malloc(strlen(tmpptr) + langsize + 1);
- } else {
- path = malloc(strlen(tmpptr) + 1);
- }
- strcpy(path, tmpptr);
- /*********************************************************************/
- /* Strip off the /%B... stuff off of the path if there is some. */
- /*********************************************************************/
- if (strip = strstr(path, "%B")) {
- *strip = '\0';
- }
- /*********************************************************************/
- /* Now replace %L with lang variable. */
- /*********************************************************************/
- if (strip = strstr(path, "%L")) {
- *strip = '\0';
- if (langsize) {
- strcat(path, lang);
- }
- }
- /*********************************************************************/
- /* Remove slash from end of path if there is one. */
- /*********************************************************************/
- size = strlen(path);
- if (size > 0) {
- if (path[size - 1] == '/') {
- path[size - 1] = '\0';
- }
- #ifdef DEBUG
- printf("new path = %s\n", path);
- #endif
- /***************************************************************/
- /* See if path is already in our list. */
- /***************************************************************/
- bFound = FALSE;
- for (i=0; (i < count) && (!bFound); i++) {
- if (!(strcmp(pplist[i], path))) {
- bFound = TRUE;
- }
- }
- /***************************************************************/
- /* If not in list, then add to list. */
- /***************************************************************/
- if (!bFound) {
- pplist[count] = path;
- count++;
- /***************************************************************/
- /* Else, just free resources. */
- /***************************************************************/
- } else {
- free(path);
- }
- }
- #ifdef DEBUG
- printf("Path%d = %s\n", count, pplist[count]);
- #endif
- #if 0
- **** moving this up a bit in the code ****
- /*********************************************************************/
- /* Get the next path in the icon search path. */
- /*********************************************************************/
- if ((ptr) && (ptr[1] != '\0')) {
- for (; ptr[0] == ':'; ptr++);
- } else {
- ptr = (char *)NULL;
- }
- #endif
- }
- }
- free(iconpath);
- return(pplist);
- }
- /******************************************************************************/
- /* */
- /* FreeIconSearchPathList */
- /* */
- /* INPUT: none */
- /* */
- /* OUTPUT: none */
- /* */
- /******************************************************************************/
- void FreeIconSearchPathList(char **pplist)
- {
- char *ptr;
- int i;
- /**************************************************************************/
- /* Iterate through the search path once to get total count of individual */
- /* paths within the search path. */
- /**************************************************************************/
- if (pplist) {
- for (i = 0; pplist[i]; free(pplist[i]), i++);
- /*
- i = 0;
- while (pplist[i]) {
- free(pplist[i]);
- }
- */
- free(pplist);
- }
- }
- /******************************************************************************/
- /* */
- /* TurnOnHourGlassAllWindows */
- /* */
- /* INPUT: none */
- /* */
- /* OUTPUT: none */
- /* */
- /******************************************************************************/
- void TurnOnHourGlassAllWindows(void)
- {
- _DtTurnOnHourGlass(CreateActionAppShell);
- if ( (AddFiletype) &&
- (XtIsRealized(AddFiletype)) &&
- (XtIsManaged(AddFiletype)) ) {
- _DtTurnOnHourGlass(AddFiletype);
- }
- if ( (FileCharacteristics) &&
- (XtIsRealized(FileCharacteristics)) &&
- (XtIsManaged(FileCharacteristics)) ) {
- _DtTurnOnHourGlass(FileCharacteristics);
- }
- if ( (IconSelector) &&
- (XtIsRealized(IconSelector)) &&
- (XtIsManaged(IconSelector)) ) {
- _DtTurnOnHourGlass(IconSelector);
- }
- if ( (OpenFile) &&
- (XtIsRealized(OpenFile)) &&
- (XtIsManaged(OpenFile)) ) {
- _DtTurnOnHourGlass(OpenFile);
- }
- }
- /******************************************************************************/
- /* */
- /* TurnOffHourGlassAllWindows */
- /* */
- /* INPUT: none */
- /* */
- /* OUTPUT: none */
- /* */
- /******************************************************************************/
- void TurnOffHourGlassAllWindows(void)
- {
- _DtTurnOffHourGlass(CreateActionAppShell);
- if ( (AddFiletype) &&
- (XtIsRealized(AddFiletype)) &&
- (XtIsManaged(AddFiletype)) ) {
- _DtTurnOffHourGlass(AddFiletype);
- }
- if ( (FileCharacteristics) &&
- (XtIsRealized(FileCharacteristics)) &&
- (XtIsManaged(FileCharacteristics)) ) {
- _DtTurnOffHourGlass(FileCharacteristics);
- }
- if ( (IconSelector) &&
- (XtIsRealized(IconSelector)) &&
- (XtIsManaged(IconSelector)) ) {
- _DtTurnOffHourGlass(IconSelector);
- }
- if ( (OpenFile) &&
- (XtIsRealized(OpenFile)) &&
- (XtIsManaged(OpenFile)) ) {
- _DtTurnOffHourGlass(OpenFile);
- }
- }
- /******************************************************************************/
- /* */
- /* SetIconData */
- /* */
- /* INPUT: icon gadget widget id */
- /* icon file base name */
- /* */
- /* OUTPUT: none */
- /* */
- /******************************************************************************/
- void SetIconData(Widget wid, char *pszIconFile, enum icon_size_range enumIconSize)
- {
- char pmFileName[MAXBUFSIZE];
- char bmFileName[MAXBUFSIZE];
- char pszSize[MAX_EXT_SIZE];
- IconData *pIconData;
- char *pszName;
- #if 0
- switch (enumIconSize) {
- case Large_Icon :
- strcpy(pszSize, LARGE_EXT);
- break;
- case Medium_Icon :
- strcpy(pszSize, MEDIUM_EXT);
- break;
- case Tiny_Icon :
- strcpy(pszSize, TINY_EXT);
- break;
- }
- sprintf(pmFileName, "%s%s%s", pszIconFile, pszSize, PIXMAP_EXT );
- sprintf(bmFileName, "%s%s%s", pszIconFile, pszSize, BITMAP_EXT );
- #endif
- pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, PIXMAP_EXT, FALSE);
- snprintf(pmFileName, sizeof(pmFileName), "%s", pszName);
- XtFree(pszName);
- pszName = CreateIconName((char *)NULL, pszIconFile, enumIconSize, BITMAP_EXT, FALSE);
- snprintf(bmFileName, sizeof(bmFileName), "%s", pszName);
- XtFree(pszName);
- pIconData = GetIconDataFromWid(wid);
- if (pIconData) {
- if ( (pIconData->pmDirtyBit) &&
- (pIconData->pmFileName) &&
- (strlen(pIconData->pmFileName)) ) {
- #ifdef DEBUG
- printf("SetIconData: unlink '%s'\n", pIconData->pmFileName); /* debug */
- #endif
- unlink(pIconData->pmFileName);
- pIconData->pmDirtyBit = False;
- }
- strcpy(pIconData->pmFileName, pmFileName);
- if ( (pIconData->bmDirtyBit) &&
- (strlen(pIconData->bmFileName)) ) {
- #ifdef DEBUG
- printf("SetIconData: unlink '%s'\n", pIconData->bmFileName); /* debug */
- #endif
- unlink(pIconData->bmFileName);
- pIconData->bmDirtyBit = False;
- }
- strcpy(pIconData->bmFileName, bmFileName);
- if (bShowPixmaps) {
- SET_ICONGADGET_ICON(wid, pmFileName);
- } else {
- SET_ICONGADGET_ICON(wid, bmFileName);
- }
- }
- }
- /******************************************************************************/
- /* */
- /* GetCorrectIconType */
- /* */
- /* INPUT: icon file name */
- /* */
- /* OUTPUT: correct icon type of icon file name passed */
- /* */
- /******************************************************************************/
- char * GetCorrectIconType(char *pszIconFile)
- {
- char *pszTmp;
- char *ptr;
- char pszNewType[MAX_EXT_SIZE];
- if (bShowPixmaps) {
- strcpy(pszNewType, PIXMAP_EXT);
- } else {
- strcpy(pszNewType, BITMAP_EXT);
- }
- if (pszIconFile) {
- pszTmp = XtMalloc(strlen(pszIconFile) + strlen(pszNewType) + 1);
- if (!pszTmp) return((char *)NULL);
- strcpy(pszTmp, pszIconFile);
- ptr = strrchr(pszTmp, '.');
- if (ptr) {
- strcpy(ptr, pszNewType);
- }
- } else {
- pszTmp = (char *)NULL;
- }
- return (pszTmp);
- }
- /******************************************************************************/
- /* */
- /* CreateMaskName */
- /* */
- /* INPUT: icon file name */
- /* */
- /* OUTPUT: mask file name for icon name passed in */
- /* */
- /******************************************************************************/
- char * CreateMaskName(char *pszIconName)
- {
- char *pszTmpName;
- char *ptr;
- char *pszNewName;
- char *type_name;
- char *size_name;
- char type_ext[MAX_EXT_SIZE + 2];
- char size_ext[MAX_EXT_SIZE + 2];
- int bytesneeded = 0;
- /***************************************************************/
- /* initialize temp arrays */
- /***************************************************************/
- type_ext[0] = '\0';
- size_ext[0] = '\0';
- /***************************************************************/
- /* alloc memory for temporary name */
- /***************************************************************/
- pszTmpName = (char *)XtMalloc(strlen(pszIconName) + 1);
- if (pszTmpName) {
- strcpy(pszTmpName, pszIconName);
- } else {
- return((char *)NULL);
- }
- /*****************************************/
- /* Strip off icon type extension. */
- /*****************************************/
- ptr = strrchr(pszTmpName, '.');
- if (ptr) {
- type_name = strtok(ptr, ".");
- *ptr = '\0';
- } else {
- type_name = (char *)NULL;
- }
- /*****************************************/
- /* Get size extention. */
- /*****************************************/
- ptr = strrchr(pszTmpName, '.');
- if (ptr) {
- size_name = strtok(ptr, ".");
- *ptr = '\0';
- } else {
- size_name = (char *)NULL;
- }
- /*****************************************/
- /* Alloc the storage for the new name */
- /*****************************************/
- bytesneeded += ((pszTmpName) ? strlen(pszTmpName) : 0);
- bytesneeded += strlen("_m..");
- bytesneeded += ((size_name) ? strlen(size_name) : 0);
- bytesneeded += ((type_name) ? strlen(type_name) : 0);
- pszNewName = (char *)XtMalloc(bytesneeded + 1);
- /*****************************************/
- /* Create extension names */
- /*****************************************/
- if (size_name) {
- sprintf(size_ext, ".%s", size_name);
- }
- if (type_name) {
- sprintf(type_ext, ".%s", type_name);
- }
- /*****************************************/
- /* And construct the new name from pieces*/
- /*****************************************/
- if (pszNewName) {
- if (size_name) {
- sprintf(pszNewName, "%s%s_m%s", pszTmpName, size_ext, type_ext);
- } else {
- sprintf(pszNewName, "%s_m%s%s", pszTmpName, size_ext, type_ext);
- }
- }
- if (pszTmpName) XtFree(pszTmpName);
- #ifdef DEBUG
- printf("Mask file name = '%s'\n", pszNewName); /* debug */
- #endif
- return(pszNewName);
- }
|