2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
26 #include <sys/types.h>
37 #include "ErrorDialog.h"
39 #define COMMENT_CHAR '#'
41 #define MAX_KEY_SIZE 5
42 #define MAX_HEADER_LINES 13
44 /*****************************************************************************/
46 /* CalculateMagicCookie */
48 /* description: Calculates a integer (the "key" value) which reflects the */
49 /* contents of the given file from the current file-offset */
50 /* to the end of file. */
51 /* Comment lines (those starting with '!' or '#') are ignored */
52 /* in calculating the key value. */
54 /* input: pointer to FILE */
55 /* output: integer - magic cookie */
57 /*****************************************************************************/
58 int CalculateMagicCookie(FILE *fp)
65 long save_offset, file_id;
66 int c, prev_c, char_sum, nline, nword, nchar, inword;
68 /**************************************************************************/
69 /* Since we will be traversing the file, we save the file-offset */
70 /* so that we can restore it before returning */
71 /**************************************************************************/
72 save_offset = ftell( fp );
75 char_sum = nline = nword = nchar = 0;
76 prev_c = '0'; /* This is arbitrary, but '0' not '\0' IS intended */
78 while ( (c = fgetc( fp )) != EOF ) {
79 if ( c == COMMENT_CHAR ) {
80 while ( (c = fgetc( fp )) != EOF && c != '\n' )
81 ; /* skip characters to end of line */
83 char_sum += (c * (prev_c%10));
90 if ( c == ' ' || c == '\n' || c == '\t' ) {
92 } else if ( inword == FALSE ) {
99 file_id = PRIME1 * nline + PRIME2 * nword + PRIME3 * nchar + char_sum;
102 printf( "nline = %d nword = %d nchar = %d char_sum = %d\n",
103 nline, nword, nchar, char_sum );
104 printf( "file_id = %ld\n", file_id );
107 /**************************************************************************/
108 /* We restore the file-offset to its previous value */
109 /**************************************************************************/
110 (void) fseek( fp, save_offset, 0 );
111 return ( file_id % MAX_KEY );
114 /****************************************************************************/
116 /* SetCookie - find the location in the file to write the magic cookie */
117 /* and update the file with the magic cookie. */
119 /* input - file pointer */
122 /****************************************************************************/
123 void SetCookie(FILE *fp)
136 /**************************************************************************/
137 /* Save file pointer initial setting */
138 /**************************************************************************/
139 lSave_offset = ftell (fp);
141 /**************************************************************************/
142 /* Set file pointer to beginning of file */
143 /**************************************************************************/
144 fseek(fp, 0, SEEK_SET);
146 /**************************************************************************/
147 /* Calculate magic cookie */
148 /**************************************************************************/
149 iCookie = CalculateMagicCookie(fp);
151 printf("Magic Cookie: %d\n", iCookie);
154 /**************************************************************************/
155 /* Find location in header and store cookie */
156 /**************************************************************************/
157 keystr = (char *)NULL;
160 while ( !keystr && retbuf && (i < MAX_HEADER_LINES) ) {
161 fgetpos(fp, &filepos);
162 retbuf = fgets(buffer, 80, fp);
163 keystr = strstr (buffer, "$KEY:");
169 printf("No '$KEY' keyword in file. Magic Cookie not written to file.\n");
173 mc_pos = strchr(keystr, ':');
176 sprintf(mc_pos, "%i", iCookie);
177 size = strlen(mc_pos);
178 if (size < MAX_KEY_SIZE) {
179 mc_clrpos = mc_pos + size;
180 for (i=size; i < MAX_KEY_SIZE; i++) {
186 fsetpos (fp, &filepos);
189 /**************************************************************************/
190 /* Set file pointer back to initial setting */
191 /**************************************************************************/
192 fseek (fp, lSave_offset, SEEK_SET);
196 /****************************************************************************/
198 /* CheckCookie - check if the magic cookie exists in the file and is the */
201 /* input - file pointer */
202 /* output - boolean indicating if correct value or not, TRUE = good */
204 /****************************************************************************/
205 Boolean CheckCookie(FILE *fp)
207 int iNewCookie, iOldCookie;
210 char *msgPtr, *errPtr;
216 Boolean bGoodCookie = TRUE;
218 /**************************************************************************/
219 /* Save file pointer initial setting */
220 /**************************************************************************/
221 lSave_offset = ftell (fp);
223 /**************************************************************************/
224 /* Set file pointer to beginning of file */
225 /**************************************************************************/
226 fseek (fp, 0, SEEK_SET);
228 /**************************************************************************/
229 /* Calculate magic cookie */
230 /**************************************************************************/
231 iNewCookie = CalculateMagicCookie(fp);
233 printf("New Magic Cookie: %d\n", iNewCookie);
236 /**************************************************************************/
237 /* Find location in header of old cookie and retrieve it. */
238 /**************************************************************************/
239 keystr = (char *)NULL;
242 while ( !keystr && retbuf && (i < MAX_HEADER_LINES) ) {
243 fgetpos(fp, &filepos);
244 retbuf = fgets(buffer, 80, fp);
245 keystr = strstr (buffer, "$KEY:");
251 printf("No '$KEY' keyword in file header. File is invalid.\n");
253 msgPtr = GETMESSAGE(5, 67,
254 "Create Action can only edit files that were created\n\
255 and edited by Create Action.");
256 errPtr = XtNewString(msgPtr);
257 display_error_message(CreateActionAppShell, errPtr);
260 fseek (fp, lSave_offset, SEEK_SET);
264 mc_pos = strchr(keystr, ':');
267 sscanf(mc_pos, "%i", &iOldCookie);
269 printf("Old Magic Cookie: %d\n", iOldCookie);
273 /**************************************************************************/
274 /* Check if cookies are the same. */
275 /**************************************************************************/
277 if (iOldCookie == iNewCookie) {
278 printf("Cookies are good = %i\n", iNewCookie);
282 if (iOldCookie != iNewCookie) {
285 printf("Cookies are bad; n=%i, o=%i\n", iNewCookie, iOldCookie);
288 msgPtr = GETMESSAGE(5, 66,
289 "Could not load the file because it has been altered by some\n\
290 other means other than Create Action. This could have been caused\n\
291 by modifying the file with a text editor or some other tool.");
292 errPtr = XtNewString(msgPtr);
293 display_error_message(CreateActionAppShell, errPtr);
298 /**************************************************************************/
299 /* Set file pointer back to initial setting */
300 /**************************************************************************/
301 fseek (fp, lSave_offset, SEEK_SET);
305 /*****************************************************************************/
314 /*****************************************************************************/
315 char * MakeExecString(char *pszCmd, char *pszPrompt)
319 char *pArgSrc = (char *)NULL;
320 char *pArgDst = (char *)NULL;
326 Boolean bDidPrompt = FALSE;
327 #define ARGSIZE 7 /* sizeof "%Arg_n%" */
330 while (pArgSrc = strchr(pArgSrc, '$')) {
332 printf("%d pArgSrc = %s\n", cArgs, pArgSrc);
337 case '1': case '2': case '3': case '4': case '5':
338 case '6': case '7': case '8': case '9': case '*':
345 printf("Args found = %d\n", cArgs);
349 size += cArgs * ARGSIZE;
350 size += strlen(pszCmd);
352 size += strlen(pszPrompt) + 2;
354 pszExecString = (char *)XtMalloc(size);
356 strcpy(pszExecString, pszCmd);
358 pTmp = pszExecString;
359 while (pArgSrc = strchr(pArgSrc, '$')) {
360 pArgDst = strchr(pTmp, '$');
366 case '1': case '2': case '3': case '4': case '5':
367 case '6': case '7': case '8': case '9': case '*':
370 strcat(pszExecString, "%Args");
372 sprintf(pszArgStr, "%%Arg_%c", *pTmp);
373 strcat(pszExecString, pszArgStr);
375 if ((pszPrompt) && (!bDidPrompt)) {
376 strcat(pszExecString, "\"");
377 strcat(pszExecString, pszPrompt);
378 strcat(pszExecString, "\"");
381 strcat(pszExecString, "%");
385 strcat(pszExecString, pArgSrc);
390 printf("EXEC_STRING = '%s'\n", pszExecString);
392 return(pszExecString);
395 /*****************************************************************************/
397 /* WriteDefinitionFile */
402 /* 1 could not open file */
404 /*****************************************************************************/
405 ushort WriteDefinitionFile(char *pszFile, ActionData *pAD)
408 FILE *fp = (FILE *)NULL;
411 char buffer[MAXBUFSIZE];
413 char *msgPtr, *fmtPtr, *errPtr;
415 /***************************************************************************/
416 /* Open action and filetypes definition file for writing. */
417 /***************************************************************************/
418 if ((fp = fopen(pszFile, "w+")) == NULL) {
420 printf("Can not open file.\n"); /* debug */
422 msgPtr = GETMESSAGE(5, 55, "Could not create the following file:");
424 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
425 strlen(pszFile) + 1) * sizeof(char));
426 sprintf(errPtr, fmtPtr, msgPtr, pszFile);
427 display_error_message(CreateActionAppShell, errPtr);
432 printf("database file = %s\n", pszFile); /* debug */
435 /***************************************************************************/
436 /* Write comment area of action and filetype definition file, including */
437 /* revision number and magic cookie. */
438 /***************************************************************************/
439 fprintf(fp, "######################################################################\n");
441 fprintf(fp, "# Common Desktop Environment (CDE)\n");
443 fprintf(fp, "# Action and DataType Definition File\n");
445 fprintf(fp, "# Generated by the CreateAction tool\n");
447 fprintf(fp, "# $Revision: 1.0\n");
449 fprintf(fp, "# $KEY: nnnnn \n");
451 fprintf(fp, "######################################################################\n");
453 fprintf(fp, "# WARNING:\n");
455 fprintf(fp, "# This file was generated by the CDE CreateAction tool.\n");
456 fprintf(fp, "# If this file is modified by some other tool, such as vi,\n");
457 fprintf(fp, "# the CreateAction tool will no longer be able to load and\n");
458 fprintf(fp, "# update this file. For this reason, changes to this file\n");
459 fprintf(fp, "# should be handled through CreateAction whenever possible.\n");
461 fprintf(fp, "######################################################################\n");
464 /***************************************************************************/
465 /* Write the main Action definition. */
466 /***************************************************************************/
467 ptr = GetCoreName(pszFile);
468 fprintf(fp, "ACTION %s\n", ptr);
471 fprintf(fp, " LABEL %s\n", pAD->pszName);
472 fprintf(fp, " TYPE COMMAND\n");
473 ptr = MakeExecString(AD.pszCmd, AD.pszPrompt);
475 fprintf(fp, " EXEC_STRING %s\n", ptr);
480 fprintf(fp, " LARGE_ICON %s.m\n", pAD->pszIcon);
481 fprintf(fp, " SMALL_ICON %s.t\n", pAD->pszIcon);
483 if (ActionHasIcon()) {
484 fprintf(fp, " ICON %s\n", pAD->pszName);
486 fprintf(fp, " ICON %s\n", pAD->pszIcon);
491 printf("CA flags = %X\n", pAD->fsFlags);
493 if (pAD->fsFlags & CA_WT_TERM) fprintf(fp, " WINDOW_TYPE TERMINAL\n");
494 else if (pAD->fsFlags & CA_WT_PERMTERM) fprintf(fp, " WINDOW_TYPE PERM_TERMINAL\n");
495 else if (pAD->fsFlags & CA_WT_SHELLTERM) fprintf(fp, " WINDOW_TYPE SHELL_TERMINAL\n");
496 else fprintf(fp, " WINDOW_TYPE NO_STDIO\n");
498 if ((pAD->papFiletypes) && (pAD->fsFlags & CA_DF_ONLYFTFILES)) {
499 fprintf(fp, " ARG_TYPE %s", (pAD->papFiletypes[0])->pszName);
500 for (i=1; i < pAD->cFiletypes; i++) {
501 pFtD = pAD->papFiletypes[i];
502 fprintf(fp, ",%s", pFtD->pszName);
508 fprintf(fp, " DESCRIPTION %s\n", pAD->pszHelp);
513 /***************************************************************************/
514 /* Write the filetype definitions. */
515 /***************************************************************************/
516 if (pAD->papFiletypes) {
517 for (i=0; i < pAD->cFiletypes; i++) {
518 pFtD = pAD->papFiletypes[i];
519 /***********************************************************************/
520 /* Write the data attributes declaration. */
521 /***********************************************************************/
522 fprintf(fp, "DATA_ATTRIBUTES %s\n", pFtD->pszName);
524 fprintf(fp, " ACTIONS Open");
525 if (pFtD->pszPrintCmd) {
526 fprintf(fp, ",Print");
531 fprintf(fp, " LARGE_ICON %s.m\n", pFtD->pszIcon);
532 fprintf(fp, " SMALL_ICON %s.t\n", pFtD->pszIcon);
534 if (FiletypeHasIcon(pFtD)) {
535 fprintf(fp, " ICON %s\n", pFtD->pszName);
537 fprintf(fp, " ICON %s\n", pFtD->pszIcon);
542 fprintf(fp, " DESCRIPTION %s\n", pFtD->pszHelp);
546 /***********************************************************************/
547 /* Write the data criteria declaration. */
548 /***********************************************************************/
549 fprintf(fp, "DATA_CRITERIA %sA\n", pFtD->pszName);
551 fprintf(fp, " DATA_ATTRIBUTES_NAME %s\n", pFtD->pszName);
552 if (pFtD->pszPermissions) {
553 fprintf(fp, " MODE %s\n", pFtD->pszPermissions);
555 if (pFtD->pszPattern) {
556 fprintf(fp, " PATH_PATTERN %s\n", pFtD->pszPattern);
558 if (pFtD->pszContents) {
559 if (pFtD->fsFlags & CA_FT_CNTSTRING)
560 strcpy(buffer, "string");
561 else if (pFtD->fsFlags & CA_FT_CNTBYTE)
562 strcpy(buffer, "byte");
563 else if (pFtD->fsFlags & CA_FT_CNTSHORT)
564 strcpy(buffer, "short");
565 else if (pFtD->fsFlags & CA_FT_CNTLONG)
566 strcpy(buffer, "long");
567 fprintf(fp, " CONTENT %d %s %s\n", pFtD->sStart, buffer, pFtD->pszContents);
571 /***********************************************************************/
572 /* Write the Open MAP action. */
573 /***********************************************************************/
574 fprintf(fp, "ACTION Open\n");
576 fprintf(fp, " ARG_TYPE %s\n", pFtD->pszName);
577 fprintf(fp, " TYPE MAP\n");
578 fprintf(fp, " MAP_ACTION %s\n", pAD->pszName);
579 fprintf(fp, " LABEL %s\n", GETMESSAGE(7, 30, "Open"));
582 /***********************************************************************/
583 /* Write the Print filetype action and MAP action. */
584 /***********************************************************************/
585 if (pFtD->pszPrintCmd) {
586 /*********************************************************************/
587 /* First write the print filetype action. */
588 /*********************************************************************/
589 fprintf(fp, "ACTION %s_PRINT\n", pFtD->pszName);
591 fprintf(fp, " TYPE COMMAND\n");
592 ptr = MakeExecString(pFtD->pszPrintCmd, NULL);
594 fprintf(fp, " EXEC_STRING %s\n", ptr);
595 /*fprintf(fp, " EXEC_STRING %s\n", pFtD->pszPrintCmd);*/
598 fprintf(fp, " WINDOW_TYPE NO_STDIO\n");
601 /*********************************************************************/
602 /* Now writhe the Print MAP action. */
603 /*********************************************************************/
604 fprintf(fp, "ACTION Print\n");
606 fprintf(fp, " ARG_TYPE %s\n", pFtD->pszName);
607 fprintf(fp, " TYPE MAP\n");
608 fprintf(fp, " MAP_ACTION %s_PRINT\n", pFtD->pszName);
609 fprintf(fp, " LABEL %s\n", GETMESSAGE(7, 31, "Print"));
617 chmod(pszFile, 0644);
621 /*****************************************************************************/
623 /* WriteActionFile */
628 /* 1 could not open file */
630 /*****************************************************************************/
631 ushort WriteActionFile(ActionData *pAD)
634 FILE *fp = (FILE *)NULL;
638 char *msgPtr, *fmtPtr, *errPtr;
640 /***************************************************************************/
641 /* Open action file for writing. */
642 /***************************************************************************/
643 newName = ReplaceSpaces(AD.pszName);
644 pszEnvVar = getenv("HOME");
646 if ( pszEnvVar && strlen(pszEnvVar) ) {
647 pszFile = XtMalloc(strlen(pszEnvVar) + strlen(newName) + 10);
648 if (pszFile) sprintf(pszFile, "%s/%s", pszEnvVar, newName);
650 pszFile = XtMalloc(strlen(newName) + 10);
651 if (pszFile) sprintf(pszFile, "/tmp/%s", newName);
655 /***************************************************************************/
656 /* Open action file for writing. */
657 /***************************************************************************/
658 if (pszFile && (fp = fopen(pszFile, "w")) == NULL) {
660 printf("Can not open file.\n"); /* debug */
662 msgPtr = GETMESSAGE(5, 55, "Could not create the following file:");
664 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
665 strlen(pszFile) + 1) * sizeof(char));
666 sprintf(errPtr, fmtPtr, msgPtr, pszFile);
667 display_error_message(CreateActionAppShell, errPtr);
673 printf("action file = %s\n", pszFile); /* debug */
675 /***************************************************************************/
676 /* Write action file contents. */
677 /***************************************************************************/
678 fprintf(fp, "################################################\n");
680 fprintf(fp, "# action\n");
682 fprintf(fp, "# Common Desktop Environment (CDE)\n");
684 fprintf(fp, "# $TOG: fileio.c /main/9 1998/10/26 17:18:19 mgreess $\n");
686 fprintf(fp, "################################################\n");
688 fprintf(fp, "# This file represents a CDE Dt action. The contents of the file do\n");
689 fprintf(fp, "# not matter; however, the file must have executable permission and the\n");
690 fprintf(fp, "# name of the file must match an entry in the action database (*.dt files).\n");
692 fprintf(fp, "# For more information on Dt actions, see the CDE Dt manuals.\n");
694 fprintf(fp, "echo \"Common Desktop Environment Dt action\"\n");
698 chmod(pszFile, 0755);
702 /******************************************************************************/
703 /* check_file_exists - check if the file exists that is passed in, if not */
704 /* display error dialog. */
706 /* INPUT: filename - name of file to check if it exists or not. */
708 /* OUTPUT: TRUE - file exists */
709 /* FALSE - file does not exist */
711 /******************************************************************************/
712 Boolean check_file_exists (char *pszFileName)
716 /***************************************/
717 /* see if file exists */
718 /***************************************/
719 exists = fopen (pszFileName, "r");
721 /***************************************/
722 /* if exists, return good return code */
723 /***************************************/
729 printf("File '%s' does not exist!\n", pszFileName);
735 /*****************************************************************************/
737 /* OpenDefinitionFile */
744 /*****************************************************************************/
745 int OpenDefinitionFile(char *pszFile, ActionData *pAD)
748 FILE *fp = (FILE *)NULL;
750 char *msgPtr, *fmtPtr, *errPtr;
752 /***************************************************************************/
753 /* Open action and filetypes definition file for reading. */
754 /***************************************************************************/
755 if ((fp = fopen(pszFile, "r+")) == NULL) {
757 printf("Can not open file.\n"); /* debug */
759 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
761 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
762 strlen(pszFile) + 1) * sizeof(char));
763 sprintf(errPtr, fmtPtr, msgPtr, pszFile);
764 display_error_message(CreateActionAppShell, errPtr);
769 printf("Opened database file = %s\n", pszFile); /* debug */
772 /***************************************************************************/
773 /* If magic cookie is good, then parse the file. */
774 /***************************************************************************/
775 if (CheckCookie(fp)) {
777 printf("Cookie good, call parse code\n");
779 rc = GetActionData(fp, pAD);
781 /************************************************************************/
782 /* If error, display error message. */
783 /************************************************************************/
785 msgPtr = GETMESSAGE(5, 90, "Could not parse the following file:");
787 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
788 strlen(pszFile) + 1) * sizeof(char));
789 sprintf(errPtr, fmtPtr, msgPtr, pszFile);
790 display_error_message(CreateActionAppShell, errPtr);
799 /******************************************************************************/
800 /* CheckDirtyIcon - check if icon has a DirtyBit set */
802 /* INPUT: Icon Widget - widget id of icon gadget to check */
804 /* OUTPUT: TRUE - dirty bit is set */
805 /* FALSE - dirty bit is not set */
807 /******************************************************************************/
808 Boolean CheckDirtyIcon (Widget wid)
812 pIconData = GetIconDataFromWid(wid);
814 if ( (pIconData->pmDirtyBit) || (pIconData->bmDirtyBit) ) {
821 /*****************************************************************************/
828 /* 1 could not open file */
830 /*****************************************************************************/
831 char * CreateIconName(char *pszDirName, char *pszBaseName, enum icon_size_range enumSize, char *pszType, Boolean bIsMask)
834 char pszSize[MAX_EXT_SIZE];
838 strcpy(pszSize, LARGE_EXT);
841 strcpy(pszSize, MEDIUM_EXT);
844 strcpy(pszSize, SMALL_EXT);
847 strcpy(pszSize, TINY_EXT);
853 strcat(pszSize, "_m");
856 pszName = XtMalloc(strlen(pszDirName) + strlen(pszBaseName) + strlen(pszSize) + strlen(pszType) + 1);
858 sprintf(pszName, "%s%s%s%s", pszDirName, pszBaseName, pszSize, pszType);
861 pszName = XtMalloc(strlen(pszBaseName) + strlen(pszSize) + strlen(pszType) + 1);
863 sprintf(pszName, "%s%s%s", pszBaseName, pszSize, pszType);
869 /*****************************************************************************/
876 /* 1 could not open file */
878 /*****************************************************************************/
879 ushort CopyFile(char *pszSource, char *pszDest)
888 char *msgPtr, *fmtPtr, *errPtr;
890 fdSource = open(pszSource, O_RDONLY);
891 if (fdSource == -1) {
892 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
894 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
895 strlen(pszSource) + 1) * sizeof(char));
896 sprintf(errPtr, fmtPtr, msgPtr, pszSource);
897 display_error_message(CreateActionAppShell, errPtr);
901 /************************************************************/
902 /* Find out how big a buffer is needed */
903 /************************************************************/
904 len = lseek(fdSource, 0, SEEK_END);
905 (void) lseek(fdSource, 0, SEEK_SET);
906 buffer = XtMalloc((Cardinal) (len + 1));
907 if ((rlen = read(fdSource, buffer, len)) != len) {
908 /*********************************************************/
909 /* Didn't read whole file! */
910 /*********************************************************/
912 fdDest = creat(pszDest, 0644);
913 /*fdDest = open(pszDest, O_WRONLY);*/
915 msgPtr = GETMESSAGE(5, 55, "Could not create the following file:");
917 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
918 strlen(pszDest) + 1) * sizeof(char));
919 sprintf(errPtr, fmtPtr, msgPtr, pszDest);
920 display_error_message(CreateActionAppShell, errPtr);
924 if ((rlen = write(fdDest, buffer, len)) != len) {
925 /***************************************************/
926 /* Didn't write the whole file! */
927 /***************************************************/
940 /*****************************************************************************/
946 /* NULL error has occurred */
947 /* not NULL name of directory to store icons */
949 /*****************************************************************************/
950 char * CreateDirName(void)
952 char *pszNewName = (char *)NULL;
953 char *pszDirName = (char *)NULL;
955 char *msgPtr, *errPtr;
957 pszEnvVar = getenv("HOME");
958 if ( pszEnvVar && strlen(pszEnvVar) ) {
959 pszDirName = XtMalloc(strlen(pszEnvVar) + strlen("/.dt/icons/") + 1);
960 sprintf(pszDirName, "%s/.dt/icons/", pszEnvVar);
962 msgPtr = GETMESSAGE(5, 170, "The HOME environment variable is not set.\n\
963 The HOME environment variable must be set in order\n\
964 for this action to be saved.");
965 errPtr = XtNewString(msgPtr);
966 display_error_message(CreateActionAppShell, errPtr);
972 /*****************************************************************************/
974 /* CopyFilesFromWid */
979 /* 1 could not open file */
981 /*****************************************************************************/
982 ushort CopyFilesFromWid(ActionData *pAD, Widget wid)
986 char *pszDirName = (char *)NULL;
987 Boolean bHaveError = FALSE;
988 char *pszIconName = (char *)NULL;
989 char *pszNewName = (char *)NULL;
990 char *pszMaskName = (char *)NULL;
992 pszDirName = CreateDirName();
993 if (!pszDirName) bHaveError = True;
995 pIconData = GetIconDataFromWid(wid);
996 pszNewName = ReplaceSpaces(pAD->pszName);
998 if ((!bHaveError) && (pIconData)) {
999 pszIconName = CreateIconName(pszDirName, pszNewName, pIconData->size, PIXMAP_EXT, FALSE);
1000 if ((!pszIconName) || (CopyFile(pIconData->pmFileName, pszIconName))) {
1003 if (pszIconName) XtFree(pszIconName);
1006 if ((!bHaveError) && (pIconData)) {
1007 pszIconName = CreateIconName(pszDirName, pszNewName, pIconData->size, BITMAP_EXT, FALSE);
1008 if ((!pszIconName) || (CopyFile(pIconData->bmFileName, pszIconName))) {
1011 if (pszIconName) XtFree(pszIconName);
1013 /**********************************************/
1014 /* Now see if it has a mask file. */
1015 /**********************************************/
1017 pszMaskName = CreateMaskName(pIconData->bmFileName);
1018 if ((pszMaskName) && (check_file_exists(pszMaskName))) {
1020 printf("Mask file exists = %s\n", pszMaskName); /* debug */
1022 pszIconName = CreateIconName(pszDirName, pszNewName, pIconData->size, BITMAP_EXT, TRUE);
1023 if ((!pszIconName) || (CopyFile(pszMaskName, pszIconName))) {
1026 if (pszIconName) XtFree(pszIconName);
1027 XtFree(pszMaskName);
1032 if (pszNewName) XtFree(pszNewName);
1033 if (pszDirName) XtFree(pszDirName);
1041 /******************************************************************************/
1042 /* ActionHasIcon - check if any of the main action's icons have dirty bit set */
1046 /* OUTPUT: TRUE - action has icon */
1047 /* FALSE - no icon for this action */
1049 /******************************************************************************/
1050 Boolean ActionHasIcon (void)
1052 if ( CheckDirtyIcon(CA_LRG_IconGadget) ||
1053 CheckDirtyIcon(CA_MED_IconGadget) ||
1054 CheckDirtyIcon(CA_TINY_IconGadget) ) {
1062 /******************************************************************************/
1063 /* FiletypeHasIcon - check if the filetype has modified icons. */
1065 /* INPUT: Filetype data structure pointer */
1067 /* OUTPUT: TRUE - action has icon */
1068 /* FALSE - no icon for this action */
1070 /******************************************************************************/
1071 Boolean FiletypeHasIcon (FiletypeData *pFtD)
1073 if ( (pFtD->pszMedPmIcon) ||
1074 (pFtD->pszMedBmIcon) ||
1075 (pFtD->pszTinyPmIcon) ||
1076 (pFtD->pszTinyBmIcon) ) {
1084 /*****************************************************************************/
1091 /* 1 could not open file */
1093 /*****************************************************************************/
1094 ushort CopyIconFiles(ActionData *pAD)
1097 Boolean bHaveError = FALSE;
1100 char *pszDirName = (char *)NULL;
1101 char *pszNewIconName;
1102 char *pszNewIconMask;
1103 char *pszOldIconName;
1105 char buffer[MAXFILENAME];
1108 #define CIF_SUCCESS 0
1110 if (ActionHasIcon()) {
1111 if ( !bHaveError && (CopyFilesFromWid(pAD, CA_LRG_IconGadget) != 0) ) {
1114 if ( !bHaveError && (CopyFilesFromWid(pAD, CA_MED_IconGadget) != 0) ) {
1117 if ( !bHaveError && (CopyFilesFromWid(pAD, CA_TINY_IconGadget) != 0) ) {
1122 if (!bHaveError && (pAD->papFiletypes)) {
1123 pszDirName = CreateDirName();
1124 for (i=0; i < pAD->cFiletypes; i++) {
1125 pFtD = pAD->papFiletypes[i];
1126 if (FiletypeHasIcon(pFtD)) {
1127 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszOldIconName, DtMEDIUM);
1128 if (pszOldIconName) {
1129 ptr = strstr(pszOldIconName, MEDIUM_EXT);
1130 if (ptr) *ptr = '\0';
1133 /*****************************************************************/
1135 /*****************************************************************/
1136 pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Medium_Icon, PIXMAP_EXT, FALSE);
1137 if (pszNewIconName) {
1138 if (pFtD->pszMedPmIcon) {
1139 CopyFile(pFtD->pszMedPmIcon, pszNewIconName);
1141 ptr = CreateIconName((char *)NULL, pszOldIconName, Medium_Icon, PIXMAP_EXT, FALSE);
1143 CopyFile(ptr, pszNewIconName);
1147 if (pszNewIconName) XtFree(pszNewIconName);
1150 /*****************************************************************/
1152 /*****************************************************************/
1153 pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Medium_Icon, BITMAP_EXT, FALSE);
1154 pszNewIconMask = CreateIconName(pszDirName, pFtD->pszName, Medium_Icon, BITMAP_EXT, TRUE);
1155 if (pszNewIconName) {
1156 if (pFtD->pszMedBmIcon) {
1157 CopyFile(pFtD->pszMedBmIcon, pszNewIconName);
1158 /****************************/
1159 /* Now do the mask file. */
1160 /****************************/
1161 sprintf(buffer, "%s_m", pFtD->pszMedBmIcon);
1162 if (pszNewIconMask && check_file_exists(buffer)) {
1163 CopyFile(buffer, pszNewIconMask);
1166 ptr = CreateIconName((char *)NULL, pszOldIconName, Medium_Icon, BITMAP_EXT, FALSE);
1168 CopyFile(ptr, pszNewIconName);
1171 /****************************/
1172 /* Now do the mask file. */
1173 /****************************/
1174 ptr = CreateIconName((char *)NULL, pszOldIconName, Medium_Icon, BITMAP_EXT, TRUE);
1175 if (ptr && check_file_exists(ptr) && pszNewIconMask) {
1176 CopyFile(ptr, pszNewIconMask);
1180 if (pszNewIconName) XtFree(pszNewIconName);
1181 if (pszNewIconMask) XtFree(pszNewIconMask);
1184 /*****************************************************************/
1186 /*****************************************************************/
1187 pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Tiny_Icon, PIXMAP_EXT, FALSE);
1188 if (pszNewIconName) {
1189 if (pFtD->pszTinyPmIcon) {
1190 CopyFile(pFtD->pszTinyPmIcon, pszNewIconName);
1192 ptr = CreateIconName((char *)NULL, pszOldIconName, Tiny_Icon, PIXMAP_EXT, FALSE);
1194 CopyFile(ptr, pszNewIconName);
1198 if (pszNewIconName) XtFree(pszNewIconName);
1201 /*****************************************************************/
1203 /*****************************************************************/
1204 pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Tiny_Icon, BITMAP_EXT, FALSE);
1205 pszNewIconMask = CreateIconName(pszDirName, pFtD->pszName, Tiny_Icon, BITMAP_EXT, TRUE);
1206 if (pszNewIconName) {
1207 if (pFtD->pszTinyBmIcon) {
1208 CopyFile(pFtD->pszTinyBmIcon, pszNewIconName);
1209 /****************************/
1210 /* Now do the mask file. */
1211 /****************************/
1212 sprintf(buffer, "%s_m", pFtD->pszTinyBmIcon);
1213 if (pszNewIconMask && check_file_exists(buffer)) {
1214 CopyFile(buffer, pszNewIconMask);
1217 ptr = CreateIconName((char *)NULL, pszOldIconName, Tiny_Icon, BITMAP_EXT, FALSE);
1219 CopyFile(ptr, pszNewIconName);
1222 /****************************/
1223 /* Now do the mask file. */
1224 /****************************/
1225 ptr = CreateIconName((char *)NULL, pszOldIconName, Tiny_Icon, BITMAP_EXT, TRUE);
1226 if (ptr && check_file_exists(ptr) && pszNewIconMask) {
1227 CopyFile(ptr, pszNewIconMask);
1231 if (pszNewIconName) XtFree(pszNewIconName);
1232 if (pszNewIconMask) XtFree(pszNewIconMask);
1238 return(CIF_SUCCESS);