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
35 #define COMMENT_CHAR '#'
37 #define MAX_KEY_SIZE 5
38 #define MAX_HEADER_LINES 13
40 /*****************************************************************************/
42 /* CalculateMagicCookie */
44 /* description: Calculates a integer (the "key" value) which reflects the */
45 /* contents of the given file from the current file-offset */
46 /* to the end of file. */
47 /* Comment lines (those starting with '!' or '#') are ignored */
48 /* in calculating the key value. */
50 /* input: pointer to FILE */
51 /* output: integer - magic cookie */
53 /*****************************************************************************/
54 int CalculateMagicCookie(FILE *fp)
61 long save_offset, file_id;
62 int c, prev_c, char_sum, nline, nword, nchar, inword;
64 /**************************************************************************/
65 /* Since we will be traversing the file, we save the file-offset */
66 /* so that we can restore it before returning */
67 /**************************************************************************/
68 save_offset = ftell( fp );
71 char_sum = nline = nword = nchar = 0;
72 prev_c = '0'; /* This is arbitrary, but '0' not '\0' IS intended */
74 while ( (c = fgetc( fp )) != EOF ) {
75 if ( c == COMMENT_CHAR ) {
76 while ( (c = fgetc( fp )) != EOF && c != '\n' )
77 ; /* skip characters to end of line */
79 char_sum += (c * (prev_c%10));
86 if ( c == ' ' || c == '\n' || c == '\t' ) {
88 } else if ( inword == FALSE ) {
95 file_id = PRIME1 * nline + PRIME2 * nword + PRIME3 * nchar + char_sum;
98 printf( "nline = %d nword = %d nchar = %d char_sum = %d\n",
99 nline, nword, nchar, char_sum );
100 printf( "file_id = %ld\n", file_id );
103 /**************************************************************************/
104 /* We restore the file-offset to its previous value */
105 /**************************************************************************/
106 (void) fseek( fp, save_offset, 0 );
107 return ( file_id % MAX_KEY );
110 /****************************************************************************/
112 /* SetCookie - find the location in the file to write the magic cookie */
113 /* and update the file with the magic cookie. */
115 /* input - file pointer */
118 /****************************************************************************/
119 void SetCookie(FILE *fp)
132 /**************************************************************************/
133 /* Save file pointer initial setting */
134 /**************************************************************************/
135 lSave_offset = ftell (fp);
137 /**************************************************************************/
138 /* Set file pointer to beginning of file */
139 /**************************************************************************/
140 fseek(fp, 0, SEEK_SET);
142 /**************************************************************************/
143 /* Calculate magic cookie */
144 /**************************************************************************/
145 iCookie = CalculateMagicCookie(fp);
147 printf("Magic Cookie: %d\n", iCookie);
150 /**************************************************************************/
151 /* Find location in header and store cookie */
152 /**************************************************************************/
153 keystr = (char *)NULL;
156 while ( !keystr && retbuf && (i < MAX_HEADER_LINES) ) {
157 fgetpos(fp, &filepos);
158 retbuf = fgets(buffer, 80, fp);
159 keystr = strstr (buffer, "$KEY:");
165 printf("No '$KEY' keyword in file. Magic Cookie not written to file.\n");
169 mc_pos = strchr(keystr, ':');
172 sprintf(mc_pos, "%i", iCookie);
173 size = strlen(mc_pos);
174 if (size < MAX_KEY_SIZE) {
175 mc_clrpos = mc_pos + size;
176 for (i=size; i < MAX_KEY_SIZE; i++) {
182 fsetpos (fp, &filepos);
185 /**************************************************************************/
186 /* Set file pointer back to initial setting */
187 /**************************************************************************/
188 fseek (fp, lSave_offset, SEEK_SET);
192 /****************************************************************************/
194 /* CheckCookie - check if the magic cookie exists in the file and is the */
197 /* input - file pointer */
198 /* output - boolean indicating if correct value or not, TRUE = good */
200 /****************************************************************************/
201 Boolean CheckCookie(FILE *fp)
203 int iNewCookie, iOldCookie;
206 char *msgPtr, *errPtr;
212 Boolean bGoodCookie = TRUE;
214 /**************************************************************************/
215 /* Save file pointer initial setting */
216 /**************************************************************************/
217 lSave_offset = ftell (fp);
219 /**************************************************************************/
220 /* Set file pointer to beginning of file */
221 /**************************************************************************/
222 fseek (fp, 0, SEEK_SET);
224 /**************************************************************************/
225 /* Calculate magic cookie */
226 /**************************************************************************/
227 iNewCookie = CalculateMagicCookie(fp);
229 printf("New Magic Cookie: %d\n", iNewCookie);
232 /**************************************************************************/
233 /* Find location in header of old cookie and retrieve it. */
234 /**************************************************************************/
235 keystr = (char *)NULL;
238 while ( !keystr && retbuf && (i < MAX_HEADER_LINES) ) {
239 fgetpos(fp, &filepos);
240 retbuf = fgets(buffer, 80, fp);
241 keystr = strstr (buffer, "$KEY:");
247 printf("No '$KEY' keyword in file header. File is invalid.\n");
249 msgPtr = GETMESSAGE(5, 67,
250 "Create Action can only edit files that were created\n\
251 and edited by Create Action.");
252 errPtr = XtNewString(msgPtr);
253 display_error_message(CreateActionAppShell, errPtr);
256 fseek (fp, lSave_offset, SEEK_SET);
260 mc_pos = strchr(keystr, ':');
263 sscanf(mc_pos, "%i", &iOldCookie);
265 printf("Old Magic Cookie: %d\n", iOldCookie);
269 /**************************************************************************/
270 /* Check if cookies are the same. */
271 /**************************************************************************/
273 if (iOldCookie == iNewCookie) {
274 printf("Cookies are good = %i\n", iNewCookie);
278 if (iOldCookie != iNewCookie) {
281 printf("Cookies are bad; n=%i, o=%i\n", iNewCookie, iOldCookie);
284 msgPtr = GETMESSAGE(5, 66,
285 "Could not load the file because it has been altered by some\n\
286 other means other than Create Action. This could have been caused\n\
287 by modifying the file with a text editor or some other tool.");
288 errPtr = XtNewString(msgPtr);
289 display_error_message(CreateActionAppShell, errPtr);
294 /**************************************************************************/
295 /* Set file pointer back to initial setting */
296 /**************************************************************************/
297 fseek (fp, lSave_offset, SEEK_SET);
301 /*****************************************************************************/
310 /*****************************************************************************/
311 char * MakeExecString(char *pszCmd, char *pszPrompt)
315 char *pArgSrc = (char *)NULL;
316 char *pArgDst = (char *)NULL;
322 Boolean bDidPrompt = FALSE;
323 #define ARGSIZE 7 /* sizeof "%Arg_n%" */
326 while (pArgSrc = strchr(pArgSrc, '$')) {
328 printf("%d pArgSrc = %s\n", cArgs, pArgSrc);
333 case '1': case '2': case '3': case '4': case '5':
334 case '6': case '7': case '8': case '9': case '*':
341 printf("Args found = %d\n", cArgs);
345 size += cArgs * ARGSIZE;
346 size += strlen(pszCmd);
348 size += strlen(pszPrompt) + 2;
350 pszExecString = (char *)XtMalloc(size);
352 strcpy(pszExecString, pszCmd);
354 pTmp = pszExecString;
355 while (pArgSrc = strchr(pArgSrc, '$')) {
356 pArgDst = strchr(pTmp, '$');
362 case '1': case '2': case '3': case '4': case '5':
363 case '6': case '7': case '8': case '9': case '*':
366 strcat(pszExecString, "%Args");
368 sprintf(pszArgStr, "%%Arg_%c", *pTmp);
369 strcat(pszExecString, pszArgStr);
371 if ((pszPrompt) && (!bDidPrompt)) {
372 strcat(pszExecString, "\"");
373 strcat(pszExecString, pszPrompt);
374 strcat(pszExecString, "\"");
377 strcat(pszExecString, "%");
381 strcat(pszExecString, pArgSrc);
386 printf("EXEC_STRING = '%s'\n", pszExecString);
388 return(pszExecString);
391 /*****************************************************************************/
393 /* WriteDefinitionFile */
398 /* 1 could not open file */
400 /*****************************************************************************/
401 ushort WriteDefinitionFile(char *pszFile, ActionData *pAD)
404 FILE *fp = (FILE *)NULL;
407 char buffer[MAXBUFSIZE];
409 char *msgPtr, *fmtPtr, *errPtr;
411 /***************************************************************************/
412 /* Open action and filetypes definition file for writing. */
413 /***************************************************************************/
414 if ((fp = fopen(pszFile, "w+")) == NULL) {
416 printf("Can not open file.\n"); /* debug */
418 msgPtr = GETMESSAGE(5, 55, "Could not create the following file:");
420 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
421 strlen(pszFile) + 1) * sizeof(char));
422 sprintf(errPtr, fmtPtr, msgPtr, pszFile);
423 display_error_message(CreateActionAppShell, errPtr);
428 printf("database file = %s\n", pszFile); /* debug */
431 /***************************************************************************/
432 /* Write comment area of action and filetype definition file, including */
433 /* revision number and magic cookie. */
434 /***************************************************************************/
435 fprintf(fp, "######################################################################\n");
437 fprintf(fp, "# Common Desktop Environment (CDE)\n");
439 fprintf(fp, "# Action and DataType Definition File\n");
441 fprintf(fp, "# Generated by the CreateAction tool\n");
443 fprintf(fp, "# $Revision: 1.0\n");
445 fprintf(fp, "# $KEY: nnnnn \n");
447 fprintf(fp, "######################################################################\n");
449 fprintf(fp, "# WARNING:\n");
451 fprintf(fp, "# This file was generated by the CDE CreateAction tool.\n");
452 fprintf(fp, "# If this file is modified by some other tool, such as vi,\n");
453 fprintf(fp, "# the CreateAction tool will no longer be able to load and\n");
454 fprintf(fp, "# update this file. For this reason, changes to this file\n");
455 fprintf(fp, "# should be handled through CreateAction whenever possible.\n");
457 fprintf(fp, "######################################################################\n");
460 /***************************************************************************/
461 /* Write the main Action definition. */
462 /***************************************************************************/
463 ptr = GetCoreName(pszFile);
464 fprintf(fp, "ACTION %s\n", ptr);
467 fprintf(fp, " LABEL %s\n", pAD->pszName);
468 fprintf(fp, " TYPE COMMAND\n");
469 ptr = MakeExecString(AD.pszCmd, AD.pszPrompt);
471 fprintf(fp, " EXEC_STRING %s\n", ptr);
476 fprintf(fp, " LARGE_ICON %s.m\n", pAD->pszIcon);
477 fprintf(fp, " SMALL_ICON %s.t\n", pAD->pszIcon);
479 if (ActionHasIcon()) {
480 fprintf(fp, " ICON %s\n", pAD->pszName);
482 fprintf(fp, " ICON %s\n", pAD->pszIcon);
487 printf("CA flags = %X\n", pAD->fsFlags);
489 if (pAD->fsFlags & CA_WT_TERM) fprintf(fp, " WINDOW_TYPE TERMINAL\n");
490 else if (pAD->fsFlags & CA_WT_PERMTERM) fprintf(fp, " WINDOW_TYPE PERM_TERMINAL\n");
491 else if (pAD->fsFlags & CA_WT_SHELLTERM) fprintf(fp, " WINDOW_TYPE SHELL_TERMINAL\n");
492 else fprintf(fp, " WINDOW_TYPE NO_STDIO\n");
494 if ((pAD->papFiletypes) && (pAD->fsFlags & CA_DF_ONLYFTFILES)) {
495 fprintf(fp, " ARG_TYPE %s", (pAD->papFiletypes[0])->pszName);
496 for (i=1; i < pAD->cFiletypes; i++) {
497 pFtD = pAD->papFiletypes[i];
498 fprintf(fp, ",%s", pFtD->pszName);
504 fprintf(fp, " DESCRIPTION %s\n", pAD->pszHelp);
509 /***************************************************************************/
510 /* Write the filetype definitions. */
511 /***************************************************************************/
512 if (pAD->papFiletypes) {
513 for (i=0; i < pAD->cFiletypes; i++) {
514 pFtD = pAD->papFiletypes[i];
515 /***********************************************************************/
516 /* Write the data attributes declaration. */
517 /***********************************************************************/
518 fprintf(fp, "DATA_ATTRIBUTES %s\n", pFtD->pszName);
520 fprintf(fp, " ACTIONS Open");
521 if (pFtD->pszPrintCmd) {
522 fprintf(fp, ",Print");
527 fprintf(fp, " LARGE_ICON %s.m\n", pFtD->pszIcon);
528 fprintf(fp, " SMALL_ICON %s.t\n", pFtD->pszIcon);
530 if (FiletypeHasIcon(pFtD)) {
531 fprintf(fp, " ICON %s\n", pFtD->pszName);
533 fprintf(fp, " ICON %s\n", pFtD->pszIcon);
538 fprintf(fp, " DESCRIPTION %s\n", pFtD->pszHelp);
542 /***********************************************************************/
543 /* Write the data criteria declaration. */
544 /***********************************************************************/
545 fprintf(fp, "DATA_CRITERIA %sA\n", pFtD->pszName);
547 fprintf(fp, " DATA_ATTRIBUTES_NAME %s\n", pFtD->pszName);
548 if (pFtD->pszPermissions) {
549 fprintf(fp, " MODE %s\n", pFtD->pszPermissions);
551 if (pFtD->pszPattern) {
552 fprintf(fp, " PATH_PATTERN %s\n", pFtD->pszPattern);
554 if (pFtD->pszContents) {
555 if (pFtD->fsFlags & CA_FT_CNTSTRING)
556 strcpy(buffer, "string");
557 else if (pFtD->fsFlags & CA_FT_CNTBYTE)
558 strcpy(buffer, "byte");
559 else if (pFtD->fsFlags & CA_FT_CNTSHORT)
560 strcpy(buffer, "short");
561 else if (pFtD->fsFlags & CA_FT_CNTLONG)
562 strcpy(buffer, "long");
563 fprintf(fp, " CONTENT %d %s %s\n", pFtD->sStart, buffer, pFtD->pszContents);
567 /***********************************************************************/
568 /* Write the Open MAP action. */
569 /***********************************************************************/
570 fprintf(fp, "ACTION Open\n");
572 fprintf(fp, " ARG_TYPE %s\n", pFtD->pszName);
573 fprintf(fp, " TYPE MAP\n");
574 fprintf(fp, " MAP_ACTION %s\n", pAD->pszName);
575 fprintf(fp, " LABEL %s\n", GETMESSAGE(7, 30, "Open"));
578 /***********************************************************************/
579 /* Write the Print filetype action and MAP action. */
580 /***********************************************************************/
581 if (pFtD->pszPrintCmd) {
582 /*********************************************************************/
583 /* First write the print filetype action. */
584 /*********************************************************************/
585 fprintf(fp, "ACTION %s_PRINT\n", pFtD->pszName);
587 fprintf(fp, " TYPE COMMAND\n");
588 ptr = MakeExecString(pFtD->pszPrintCmd, NULL);
590 fprintf(fp, " EXEC_STRING %s\n", ptr);
591 /*fprintf(fp, " EXEC_STRING %s\n", pFtD->pszPrintCmd);*/
594 fprintf(fp, " WINDOW_TYPE NO_STDIO\n");
597 /*********************************************************************/
598 /* Now writhe the Print MAP action. */
599 /*********************************************************************/
600 fprintf(fp, "ACTION Print\n");
602 fprintf(fp, " ARG_TYPE %s\n", pFtD->pszName);
603 fprintf(fp, " TYPE MAP\n");
604 fprintf(fp, " MAP_ACTION %s_PRINT\n", pFtD->pszName);
605 fprintf(fp, " LABEL %s\n", GETMESSAGE(7, 31, "Print"));
613 chmod(pszFile, 0644);
617 /*****************************************************************************/
619 /* WriteActionFile */
624 /* 1 could not open file */
626 /*****************************************************************************/
627 ushort WriteActionFile(ActionData *pAD)
630 FILE *fp = (FILE *)NULL;
634 char *msgPtr, *fmtPtr, *errPtr;
636 /***************************************************************************/
637 /* Open action file for writing. */
638 /***************************************************************************/
639 newName = ReplaceSpaces(AD.pszName);
640 pszEnvVar = getenv("HOME");
642 if ( pszEnvVar && strlen(pszEnvVar) ) {
643 pszFile = XtMalloc(strlen(pszEnvVar) + strlen(newName) + 10);
644 if (pszFile) sprintf(pszFile, "%s/%s", pszEnvVar, newName);
646 pszFile = XtMalloc(strlen(newName) + 10);
647 if (pszFile) sprintf(pszFile, "/tmp/%s", newName);
651 /***************************************************************************/
652 /* Open action file for writing. */
653 /***************************************************************************/
654 if (pszFile && (fp = fopen(pszFile, "w")) == NULL) {
656 printf("Can not open file.\n"); /* debug */
658 msgPtr = GETMESSAGE(5, 55, "Could not create the following file:");
660 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
661 strlen(pszFile) + 1) * sizeof(char));
662 sprintf(errPtr, fmtPtr, msgPtr, pszFile);
663 display_error_message(CreateActionAppShell, errPtr);
669 printf("action file = %s\n", pszFile); /* debug */
671 /***************************************************************************/
672 /* Write action file contents. */
673 /***************************************************************************/
674 fprintf(fp, "################################################\n");
676 fprintf(fp, "# action\n");
678 fprintf(fp, "# Common Desktop Environment (CDE)\n");
680 fprintf(fp, "# $TOG: fileio.c /main/9 1998/10/26 17:18:19 mgreess $\n");
682 fprintf(fp, "################################################\n");
684 fprintf(fp, "# This file represents a CDE Dt action. The contents of the file do\n");
685 fprintf(fp, "# not matter; however, the file must have executable permission and the\n");
686 fprintf(fp, "# name of the file must match an entry in the action database (*.dt files).\n");
688 fprintf(fp, "# For more information on Dt actions, see the CDE Dt manuals.\n");
690 fprintf(fp, "echo \"Common Desktop Environment Dt action\"\n");
694 chmod(pszFile, 0755);
698 /******************************************************************************/
699 /* check_file_exists - check if the file exists that is passed in, if not */
700 /* display error dialog. */
702 /* INPUT: filename - name of file to check if it exists or not. */
704 /* OUTPUT: TRUE - file exists */
705 /* FALSE - file does not exist */
707 /******************************************************************************/
708 Boolean check_file_exists (char *pszFileName)
712 /***************************************/
713 /* see if file exists */
714 /***************************************/
715 exists = fopen (pszFileName, "r");
717 /***************************************/
718 /* if exists, return good return code */
719 /***************************************/
725 printf("File '%s' does not exist!\n", pszFileName);
731 /*****************************************************************************/
733 /* OpenDefinitionFile */
740 /*****************************************************************************/
741 int OpenDefinitionFile(char *pszFile, ActionData *pAD)
744 FILE *fp = (FILE *)NULL;
746 char *msgPtr, *fmtPtr, *errPtr;
748 /***************************************************************************/
749 /* Open action and filetypes definition file for reading. */
750 /***************************************************************************/
751 if ((fp = fopen(pszFile, "r+")) == NULL) {
753 printf("Can not open file.\n"); /* debug */
755 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
757 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
758 strlen(pszFile) + 1) * sizeof(char));
759 sprintf(errPtr, fmtPtr, msgPtr, pszFile);
760 display_error_message(CreateActionAppShell, errPtr);
765 printf("Opened database file = %s\n", pszFile); /* debug */
768 /***************************************************************************/
769 /* If magic cookie is good, then parse the file. */
770 /***************************************************************************/
771 if (CheckCookie(fp)) {
773 printf("Cookie good, call parse code\n");
775 rc = GetActionData(fp, pAD);
777 /************************************************************************/
778 /* If error, display error message. */
779 /************************************************************************/
781 msgPtr = GETMESSAGE(5, 90, "Could not parse the following file:");
783 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
784 strlen(pszFile) + 1) * sizeof(char));
785 sprintf(errPtr, fmtPtr, msgPtr, pszFile);
786 display_error_message(CreateActionAppShell, errPtr);
795 /******************************************************************************/
796 /* CheckDirtyIcon - check if icon has a DirtyBit set */
798 /* INPUT: Icon Widget - widget id of icon gadget to check */
800 /* OUTPUT: TRUE - dirty bit is set */
801 /* FALSE - dirty bit is not set */
803 /******************************************************************************/
804 Boolean CheckDirtyIcon (Widget wid)
808 pIconData = GetIconDataFromWid(wid);
810 if ( (pIconData->pmDirtyBit) || (pIconData->bmDirtyBit) ) {
817 /*****************************************************************************/
824 /* 1 could not open file */
826 /*****************************************************************************/
827 char * CreateIconName(char *pszDirName, char *pszBaseName, enum icon_size_range enumSize, char *pszType, Boolean bIsMask)
830 char pszSize[MAX_EXT_SIZE];
834 strcpy(pszSize, LARGE_EXT);
837 strcpy(pszSize, MEDIUM_EXT);
840 strcpy(pszSize, TINY_EXT);
844 strcat(pszSize, "_m");
847 pszName = XtMalloc(strlen(pszDirName) + strlen(pszBaseName) + strlen(pszSize) + strlen(pszType) + 1);
849 sprintf(pszName, "%s%s%s%s", pszDirName, pszBaseName, pszSize, pszType);
852 pszName = XtMalloc(strlen(pszBaseName) + strlen(pszSize) + strlen(pszType) + 1);
854 sprintf(pszName, "%s%s%s", pszBaseName, pszSize, pszType);
860 /*****************************************************************************/
867 /* 1 could not open file */
869 /*****************************************************************************/
870 ushort CopyFile(char *pszSource, char *pszDest)
879 char *msgPtr, *fmtPtr, *errPtr;
881 fdSource = open(pszSource, O_RDONLY);
882 if (fdSource == -1) {
883 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
885 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
886 strlen(pszSource) + 1) * sizeof(char));
887 sprintf(errPtr, fmtPtr, msgPtr, pszSource);
888 display_error_message(CreateActionAppShell, errPtr);
892 /************************************************************/
893 /* Find out how big a buffer is needed */
894 /************************************************************/
895 len = lseek(fdSource, 0, SEEK_END);
896 (void) lseek(fdSource, 0, SEEK_SET);
897 buffer = XtMalloc((Cardinal) (len + 1));
898 if ((rlen = read(fdSource, buffer, len)) != len) {
899 /*********************************************************/
900 /* Didn't read whole file! */
901 /*********************************************************/
903 fdDest = creat(pszDest, 0644);
904 /*fdDest = open(pszDest, O_WRONLY);*/
906 msgPtr = GETMESSAGE(5, 55, "Could not create the following file:");
908 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
909 strlen(pszDest) + 1) * sizeof(char));
910 sprintf(errPtr, fmtPtr, msgPtr, pszDest);
911 display_error_message(CreateActionAppShell, errPtr);
915 if ((rlen = write(fdDest, buffer, len)) != len) {
916 /***************************************************/
917 /* Didn't write the whole file! */
918 /***************************************************/
931 /*****************************************************************************/
937 /* NULL error has occurred */
938 /* not NULL name of directory to store icons */
940 /*****************************************************************************/
941 char * CreateDirName(void)
943 char *pszNewName = (char *)NULL;
944 char *pszDirName = (char *)NULL;
946 char *msgPtr, *errPtr;
948 pszEnvVar = getenv("HOME");
949 if ( pszEnvVar && strlen(pszEnvVar) ) {
950 pszDirName = XtMalloc(strlen(pszEnvVar) + strlen("/.dt/icons/") + 1);
951 sprintf(pszDirName, "%s/.dt/icons/", pszEnvVar);
953 msgPtr = GETMESSAGE(5, 170, "The HOME environment variable is not set.\n\
954 The HOME environment variable must be set in order\n\
955 for this action to be saved.");
956 errPtr = XtNewString(msgPtr);
957 display_error_message(CreateActionAppShell, errPtr);
963 /*****************************************************************************/
965 /* CopyFilesFromWid */
970 /* 1 could not open file */
972 /*****************************************************************************/
973 ushort CopyFilesFromWid(ActionData *pAD, Widget wid)
977 char *pszDirName = (char *)NULL;
978 Boolean bHaveError = FALSE;
979 char *pszIconName = (char *)NULL;
980 char *pszNewName = (char *)NULL;
981 char *pszMaskName = (char *)NULL;
983 pszDirName = CreateDirName();
984 if (!pszDirName) bHaveError = True;
986 pIconData = GetIconDataFromWid(wid);
987 pszNewName = ReplaceSpaces(pAD->pszName);
989 if ((!bHaveError) && (pIconData)) {
990 pszIconName = CreateIconName(pszDirName, pszNewName, pIconData->size, PIXMAP_EXT, FALSE);
991 if ((!pszIconName) || (CopyFile(pIconData->pmFileName, pszIconName))) {
994 if (pszIconName) XtFree(pszIconName);
997 if ((!bHaveError) && (pIconData)) {
998 pszIconName = CreateIconName(pszDirName, pszNewName, pIconData->size, BITMAP_EXT, FALSE);
999 if ((!pszIconName) || (CopyFile(pIconData->bmFileName, pszIconName))) {
1002 if (pszIconName) XtFree(pszIconName);
1004 /**********************************************/
1005 /* Now see if it has a mask file. */
1006 /**********************************************/
1008 pszMaskName = CreateMaskName(pIconData->bmFileName);
1009 if ((pszMaskName) && (check_file_exists(pszMaskName))) {
1011 printf("Mask file exists = %s\n", pszMaskName); /* debug */
1013 pszIconName = CreateIconName(pszDirName, pszNewName, pIconData->size, BITMAP_EXT, TRUE);
1014 if ((!pszIconName) || (CopyFile(pszMaskName, pszIconName))) {
1017 if (pszIconName) XtFree(pszIconName);
1018 XtFree(pszMaskName);
1023 if (pszNewName) XtFree(pszNewName);
1024 if (pszDirName) XtFree(pszDirName);
1032 /******************************************************************************/
1033 /* ActionHasIcon - check if any of the main action's icons have dirty bit set */
1037 /* OUTPUT: TRUE - action has icon */
1038 /* FALSE - no icon for this action */
1040 /******************************************************************************/
1041 Boolean ActionHasIcon (void)
1043 if ( CheckDirtyIcon(CA_LRG_IconGadget) ||
1044 CheckDirtyIcon(CA_MED_IconGadget) ||
1045 CheckDirtyIcon(CA_TINY_IconGadget) ) {
1053 /******************************************************************************/
1054 /* FiletypeHasIcon - check if the filetype has modified icons. */
1056 /* INPUT: Filetype data structure pointer */
1058 /* OUTPUT: TRUE - action has icon */
1059 /* FALSE - no icon for this action */
1061 /******************************************************************************/
1062 Boolean FiletypeHasIcon (FiletypeData *pFtD)
1064 if ( (pFtD->pszMedPmIcon) ||
1065 (pFtD->pszMedBmIcon) ||
1066 (pFtD->pszTinyPmIcon) ||
1067 (pFtD->pszTinyBmIcon) ) {
1075 /*****************************************************************************/
1082 /* 1 could not open file */
1084 /*****************************************************************************/
1085 ushort CopyIconFiles(ActionData *pAD)
1088 Boolean bHaveError = FALSE;
1091 char *pszDirName = (char *)NULL;
1092 char *pszNewIconName;
1093 char *pszNewIconMask;
1094 char *pszOldIconName;
1096 char buffer[MAXFILENAME];
1099 #define CIF_SUCCESS 0
1101 if (ActionHasIcon()) {
1102 if ( !bHaveError && (CopyFilesFromWid(pAD, CA_LRG_IconGadget) != 0) ) {
1105 if ( !bHaveError && (CopyFilesFromWid(pAD, CA_MED_IconGadget) != 0) ) {
1108 if ( !bHaveError && (CopyFilesFromWid(pAD, CA_TINY_IconGadget) != 0) ) {
1113 if (!bHaveError && (pAD->papFiletypes)) {
1114 pszDirName = CreateDirName();
1115 for (i=0; i < pAD->cFiletypes; i++) {
1116 pFtD = pAD->papFiletypes[i];
1117 if (FiletypeHasIcon(pFtD)) {
1118 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszOldIconName, DtMEDIUM);
1119 if (pszOldIconName) {
1120 ptr = strstr(pszOldIconName, MEDIUM_EXT);
1121 if (ptr) *ptr = '\0';
1124 /*****************************************************************/
1126 /*****************************************************************/
1127 pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Medium_Icon, PIXMAP_EXT, FALSE);
1128 if (pszNewIconName) {
1129 if (pFtD->pszMedPmIcon) {
1130 CopyFile(pFtD->pszMedPmIcon, pszNewIconName);
1132 ptr = CreateIconName((char *)NULL, pszOldIconName, Medium_Icon, PIXMAP_EXT, FALSE);
1134 CopyFile(ptr, pszNewIconName);
1138 if (pszNewIconName) XtFree(pszNewIconName);
1141 /*****************************************************************/
1143 /*****************************************************************/
1144 pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Medium_Icon, BITMAP_EXT, FALSE);
1145 pszNewIconMask = CreateIconName(pszDirName, pFtD->pszName, Medium_Icon, BITMAP_EXT, TRUE);
1146 if (pszNewIconName) {
1147 if (pFtD->pszMedBmIcon) {
1148 CopyFile(pFtD->pszMedBmIcon, pszNewIconName);
1149 /****************************/
1150 /* Now do the mask file. */
1151 /****************************/
1152 sprintf(buffer, "%s_m", pFtD->pszMedBmIcon);
1153 if (pszNewIconMask && check_file_exists(buffer)) {
1154 CopyFile(buffer, pszNewIconMask);
1157 ptr = CreateIconName((char *)NULL, pszOldIconName, Medium_Icon, BITMAP_EXT, FALSE);
1159 CopyFile(ptr, pszNewIconName);
1162 /****************************/
1163 /* Now do the mask file. */
1164 /****************************/
1165 ptr = CreateIconName((char *)NULL, pszOldIconName, Medium_Icon, BITMAP_EXT, TRUE);
1166 if (ptr && check_file_exists(ptr) && pszNewIconMask) {
1167 CopyFile(ptr, pszNewIconMask);
1171 if (pszNewIconName) XtFree(pszNewIconName);
1172 if (pszNewIconMask) XtFree(pszNewIconMask);
1175 /*****************************************************************/
1177 /*****************************************************************/
1178 pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Tiny_Icon, PIXMAP_EXT, FALSE);
1179 if (pszNewIconName) {
1180 if (pFtD->pszTinyPmIcon) {
1181 CopyFile(pFtD->pszTinyPmIcon, pszNewIconName);
1183 ptr = CreateIconName((char *)NULL, pszOldIconName, Tiny_Icon, PIXMAP_EXT, FALSE);
1185 CopyFile(ptr, pszNewIconName);
1189 if (pszNewIconName) XtFree(pszNewIconName);
1192 /*****************************************************************/
1194 /*****************************************************************/
1195 pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Tiny_Icon, BITMAP_EXT, FALSE);
1196 pszNewIconMask = CreateIconName(pszDirName, pFtD->pszName, Tiny_Icon, BITMAP_EXT, TRUE);
1197 if (pszNewIconName) {
1198 if (pFtD->pszTinyBmIcon) {
1199 CopyFile(pFtD->pszTinyBmIcon, pszNewIconName);
1200 /****************************/
1201 /* Now do the mask file. */
1202 /****************************/
1203 sprintf(buffer, "%s_m", pFtD->pszTinyBmIcon);
1204 if (pszNewIconMask && check_file_exists(buffer)) {
1205 CopyFile(buffer, pszNewIconMask);
1208 ptr = CreateIconName((char *)NULL, pszOldIconName, Tiny_Icon, BITMAP_EXT, FALSE);
1210 CopyFile(ptr, pszNewIconName);
1213 /****************************/
1214 /* Now do the mask file. */
1215 /****************************/
1216 ptr = CreateIconName((char *)NULL, pszOldIconName, Tiny_Icon, BITMAP_EXT, TRUE);
1217 if (ptr && check_file_exists(ptr) && pszNewIconMask) {
1218 CopyFile(ptr, pszNewIconMask);
1222 if (pszNewIconName) XtFree(pszNewIconName);
1223 if (pszNewIconMask) XtFree(pszNewIconMask);
1229 return(CIF_SUCCESS);