13 #define COMMENT_CHAR '#'
15 #define MAX_KEY_SIZE 5
16 #define MAX_HEADER_LINES 13
18 /*****************************************************************************/
20 /* CalculateMagicCookie */
22 /* description: Calculates a integer (the "key" value) which reflects the */
23 /* contents of the given file from the current file-offset */
24 /* to the end of file. */
25 /* Comment lines (those starting with '!' or '#') are ignored */
26 /* in calculating the key value. */
28 /* input: pointer to FILE */
29 /* output: integer - magic cookie */
31 /*****************************************************************************/
32 int CalculateMagicCookie(FILE *fp)
39 long save_offset, file_id;
40 int c, prev_c, char_sum, nline, nword, nchar, inword;
42 /**************************************************************************/
43 /* Since we will be traversing the file, we save the file-offset */
44 /* so that we can restore it before returning */
45 /**************************************************************************/
46 save_offset = ftell( fp );
49 char_sum = nline = nword = nchar = 0;
50 prev_c = '0'; /* This is arbitrary, but '0' not '\0' IS intended */
52 while ( (c = fgetc( fp )) != EOF ) {
53 if ( c == COMMENT_CHAR ) {
54 while ( (c = fgetc( fp )) != EOF && c != '\n' )
55 ; /* skip characters to end of line */
57 char_sum += (c * (prev_c%10));
64 if ( c == ' ' || c == '\n' || c == '\t' ) {
66 } else if ( inword == FALSE ) {
73 file_id = PRIME1 * nline + PRIME2 * nword + PRIME3 * nchar + char_sum;
76 printf( "nline = %d nword = %d nchar = %d char_sum = %d\n",
77 nline, nword, nchar, char_sum );
78 printf( "file_id = %ld\n", file_id );
81 /**************************************************************************/
82 /* We restore the file-offset to its previous value */
83 /**************************************************************************/
84 (void) fseek( fp, save_offset, 0 );
85 return ( file_id % MAX_KEY );
88 /****************************************************************************/
90 /* SetCookie - find the location in the file to write the magic cookie */
91 /* and update the file with the magic cookie. */
93 /* input - file pointer */
96 /****************************************************************************/
97 void SetCookie(FILE *fp)
110 /**************************************************************************/
111 /* Save file pointer initial setting */
112 /**************************************************************************/
113 lSave_offset = ftell (fp);
115 /**************************************************************************/
116 /* Set file pointer to beginning of file */
117 /**************************************************************************/
118 fseek(fp, 0, SEEK_SET);
120 /**************************************************************************/
121 /* Calculate magic cookie */
122 /**************************************************************************/
123 iCookie = CalculateMagicCookie(fp);
125 printf("Magic Cookie: %d\n", iCookie);
128 /**************************************************************************/
129 /* Find location in header and store cookie */
130 /**************************************************************************/
131 keystr = (char *)NULL;
134 while ( !keystr && retbuf && (i < MAX_HEADER_LINES) ) {
135 fgetpos(fp, &filepos);
136 retbuf = fgets(buffer, 80, fp);
137 keystr = strstr (buffer, "$KEY:");
143 printf("No '$KEY' keyword in file. Magic Cookie not written to file.\n");
147 mc_pos = strchr(keystr, ':');
150 sprintf(mc_pos, "%i", iCookie);
151 size = strlen(mc_pos);
152 if (size < MAX_KEY_SIZE) {
153 mc_clrpos = mc_pos + size;
154 for (i=size; i < MAX_KEY_SIZE; i++) {
160 fsetpos (fp, &filepos);
163 /**************************************************************************/
164 /* Set file pointer back to initial setting */
165 /**************************************************************************/
166 fseek (fp, lSave_offset, SEEK_SET);
170 /****************************************************************************/
172 /* CheckCookie - check if the magic cookie exists in the file and is the */
175 /* input - file pointer */
176 /* output - boolean indicating if correct value or not, TRUE = good */
178 /****************************************************************************/
179 Boolean CheckCookie(FILE *fp)
181 int iNewCookie, iOldCookie;
184 char *msgPtr, *errPtr;
190 Boolean bGoodCookie = TRUE;
192 /**************************************************************************/
193 /* Save file pointer initial setting */
194 /**************************************************************************/
195 lSave_offset = ftell (fp);
197 /**************************************************************************/
198 /* Set file pointer to beginning of file */
199 /**************************************************************************/
200 fseek (fp, 0, SEEK_SET);
202 /**************************************************************************/
203 /* Calculate magic cookie */
204 /**************************************************************************/
205 iNewCookie = CalculateMagicCookie(fp);
207 printf("New Magic Cookie: %d\n", iNewCookie);
210 /**************************************************************************/
211 /* Find location in header of old cookie and retrieve it. */
212 /**************************************************************************/
213 keystr = (char *)NULL;
216 while ( !keystr && retbuf && (i < MAX_HEADER_LINES) ) {
217 fgetpos(fp, &filepos);
218 retbuf = fgets(buffer, 80, fp);
219 keystr = strstr (buffer, "$KEY:");
225 printf("No '$KEY' keyword in file header. File is invalid.\n");
227 msgPtr = GETMESSAGE(5, 67,
228 "Create Action can only edit files that were created\n\
229 and edited by Create Action.");
230 errPtr = XtNewString(msgPtr);
231 display_error_message(CreateActionAppShell, errPtr);
234 fseek (fp, lSave_offset, SEEK_SET);
238 mc_pos = strchr(keystr, ':');
241 sscanf(mc_pos, "%i", &iOldCookie);
243 printf("Old Magic Cookie: %d\n", iOldCookie);
247 /**************************************************************************/
248 /* Check if cookies are the same. */
249 /**************************************************************************/
251 if (iOldCookie == iNewCookie) {
252 printf("Cookies are good = %i\n", iNewCookie);
256 if (iOldCookie != iNewCookie) {
259 printf("Cookies are bad; n=%i, o=%i\n", iNewCookie, iOldCookie);
262 msgPtr = GETMESSAGE(5, 66,
263 "Could not load the file because it has been altered by some\n\
264 other means other than Create Action. This could have been caused\n\
265 by modifying the file with a text editor or some other tool.");
266 errPtr = XtNewString(msgPtr);
267 display_error_message(CreateActionAppShell, errPtr);
272 /**************************************************************************/
273 /* Set file pointer back to initial setting */
274 /**************************************************************************/
275 fseek (fp, lSave_offset, SEEK_SET);
279 /*****************************************************************************/
288 /*****************************************************************************/
289 char * MakeExecString(char *pszCmd, char *pszPrompt)
293 char *pArgSrc = (char *)NULL;
294 char *pArgDst = (char *)NULL;
300 Boolean bDidPrompt = FALSE;
301 #define ARGSIZE 7 /* sizeof "%Arg_n%" */
304 while (pArgSrc = strchr(pArgSrc, '$')) {
306 printf("%d pArgSrc = %s\n", cArgs, pArgSrc);
311 case '1': case '2': case '3': case '4': case '5':
312 case '6': case '7': case '8': case '9': case '*':
319 printf("Args found = %d\n", cArgs);
323 size += cArgs * ARGSIZE;
324 size += strlen(pszCmd);
326 size += strlen(pszPrompt) + 2;
328 pszExecString = (char *)XtMalloc(size);
330 strcpy(pszExecString, pszCmd);
332 pTmp = pszExecString;
333 while (pArgSrc = strchr(pArgSrc, '$')) {
334 pArgDst = strchr(pTmp, '$');
340 case '1': case '2': case '3': case '4': case '5':
341 case '6': case '7': case '8': case '9': case '*':
344 strcat(pszExecString, "%Args");
346 sprintf(pszArgStr, "%%Arg_%c", *pTmp);
347 strcat(pszExecString, pszArgStr);
349 if ((pszPrompt) && (!bDidPrompt)) {
350 strcat(pszExecString, "\"");
351 strcat(pszExecString, pszPrompt);
352 strcat(pszExecString, "\"");
355 strcat(pszExecString, "%");
359 strcat(pszExecString, pArgSrc);
364 printf("EXEC_STRING = '%s'\n", pszExecString);
366 return(pszExecString);
369 /*****************************************************************************/
371 /* WriteDefinitionFile */
376 /* 1 could not open file */
378 /*****************************************************************************/
379 ushort WriteDefinitionFile(char *pszFile, ActionData *pAD)
382 FILE *fp = (FILE *)NULL;
385 char buffer[MAXBUFSIZE];
387 char *msgPtr, *fmtPtr, *errPtr;
389 /***************************************************************************/
390 /* Open action and filetypes definition file for writing. */
391 /***************************************************************************/
392 if ((fp = fopen(pszFile, "w+")) == NULL) {
394 printf("Can not open file.\n"); /* debug */
396 msgPtr = GETMESSAGE(5, 55, "Could not create the following file:");
398 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
399 strlen(pszFile) + 1) * sizeof(char));
400 sprintf(errPtr, fmtPtr, msgPtr, pszFile);
401 display_error_message(CreateActionAppShell, errPtr);
406 printf("database file = %s\n", pszFile); /* debug */
409 /***************************************************************************/
410 /* Write comment area of action and filetype definition file, including */
411 /* revision number and magic cookie. */
412 /***************************************************************************/
413 fprintf(fp, "######################################################################\n");
415 fprintf(fp, "# Common Desktop Environment (CDE)\n");
417 fprintf(fp, "# Action and DataType Definition File\n");
419 fprintf(fp, "# Generated by the CreateAction tool\n");
421 fprintf(fp, "# $Revision: 1.0\n");
423 fprintf(fp, "# $KEY: nnnnn \n");
425 fprintf(fp, "######################################################################\n");
427 fprintf(fp, "# WARNING:\n");
429 fprintf(fp, "# This file was generated by the CDE CreateAction tool.\n");
430 fprintf(fp, "# If this file is modified by some other tool, such as vi,\n");
431 fprintf(fp, "# the CreateAction tool will no longer be able to load and\n");
432 fprintf(fp, "# update this file. For this reason, changes to this file\n");
433 fprintf(fp, "# should be handled through CreateAction whenever possible.\n");
435 fprintf(fp, "######################################################################\n");
438 /***************************************************************************/
439 /* Write the main Action definition. */
440 /***************************************************************************/
441 ptr = GetCoreName(pszFile);
442 fprintf(fp, "ACTION %s\n", ptr);
445 fprintf(fp, " LABEL %s\n", pAD->pszName);
446 fprintf(fp, " TYPE COMMAND\n");
447 ptr = MakeExecString(AD.pszCmd, AD.pszPrompt);
449 fprintf(fp, " EXEC_STRING %s\n", ptr);
454 fprintf(fp, " LARGE_ICON %s.m\n", pAD->pszIcon);
455 fprintf(fp, " SMALL_ICON %s.t\n", pAD->pszIcon);
457 if (ActionHasIcon()) {
458 fprintf(fp, " ICON %s\n", pAD->pszName);
460 fprintf(fp, " ICON %s\n", pAD->pszIcon);
465 printf("CA flags = %X\n", pAD->fsFlags);
467 if (pAD->fsFlags & CA_WT_TERM) fprintf(fp, " WINDOW_TYPE TERMINAL\n");
468 else if (pAD->fsFlags & CA_WT_PERMTERM) fprintf(fp, " WINDOW_TYPE PERM_TERMINAL\n");
469 else if (pAD->fsFlags & CA_WT_SHELLTERM) fprintf(fp, " WINDOW_TYPE SHELL_TERMINAL\n");
470 else fprintf(fp, " WINDOW_TYPE NO_STDIO\n");
472 if ((pAD->papFiletypes) && (pAD->fsFlags & CA_DF_ONLYFTFILES)) {
473 fprintf(fp, " ARG_TYPE %s", (pAD->papFiletypes[0])->pszName);
474 for (i=1; i < pAD->cFiletypes; i++) {
475 pFtD = pAD->papFiletypes[i];
476 fprintf(fp, ",%s", pFtD->pszName);
482 fprintf(fp, " DESCRIPTION %s\n", pAD->pszHelp);
487 /***************************************************************************/
488 /* Write the filetype definitions. */
489 /***************************************************************************/
490 if (pAD->papFiletypes) {
491 for (i=0; i < pAD->cFiletypes; i++) {
492 pFtD = pAD->papFiletypes[i];
493 /***********************************************************************/
494 /* Write the data attributes declaration. */
495 /***********************************************************************/
496 fprintf(fp, "DATA_ATTRIBUTES %s\n", pFtD->pszName);
498 fprintf(fp, " ACTIONS Open");
499 if (pFtD->pszPrintCmd) {
500 fprintf(fp, ",Print");
505 fprintf(fp, " LARGE_ICON %s.m\n", pFtD->pszIcon);
506 fprintf(fp, " SMALL_ICON %s.t\n", pFtD->pszIcon);
508 if (FiletypeHasIcon(pFtD)) {
509 fprintf(fp, " ICON %s\n", pFtD->pszName);
511 fprintf(fp, " ICON %s\n", pFtD->pszIcon);
516 fprintf(fp, " DESCRIPTION %s\n", pFtD->pszHelp);
520 /***********************************************************************/
521 /* Write the data criteria declaration. */
522 /***********************************************************************/
523 fprintf(fp, "DATA_CRITERIA %sA\n", pFtD->pszName);
525 fprintf(fp, " DATA_ATTRIBUTES_NAME %s\n", pFtD->pszName);
526 if (pFtD->pszPermissions) {
527 fprintf(fp, " MODE %s\n", pFtD->pszPermissions);
529 if (pFtD->pszPattern) {
530 fprintf(fp, " PATH_PATTERN %s\n", pFtD->pszPattern);
532 if (pFtD->pszContents) {
533 if (pFtD->fsFlags & CA_FT_CNTSTRING)
534 strcpy(buffer, "string");
535 else if (pFtD->fsFlags & CA_FT_CNTBYTE)
536 strcpy(buffer, "byte");
537 else if (pFtD->fsFlags & CA_FT_CNTSHORT)
538 strcpy(buffer, "short");
539 else if (pFtD->fsFlags & CA_FT_CNTLONG)
540 strcpy(buffer, "long");
541 fprintf(fp, " CONTENT %d %s %s\n", pFtD->sStart, buffer, pFtD->pszContents);
545 /***********************************************************************/
546 /* Write the Open MAP action. */
547 /***********************************************************************/
548 fprintf(fp, "ACTION Open\n");
550 fprintf(fp, " ARG_TYPE %s\n", pFtD->pszName);
551 fprintf(fp, " TYPE MAP\n");
552 fprintf(fp, " MAP_ACTION %s\n", pAD->pszName);
553 fprintf(fp, " LABEL %s\n", GETMESSAGE(7, 30, "Open"));
556 /***********************************************************************/
557 /* Write the Print filetype action and MAP action. */
558 /***********************************************************************/
559 if (pFtD->pszPrintCmd) {
560 /*********************************************************************/
561 /* First write the print filetype action. */
562 /*********************************************************************/
563 fprintf(fp, "ACTION %s_PRINT\n", pFtD->pszName);
565 fprintf(fp, " TYPE COMMAND\n");
566 ptr = MakeExecString(pFtD->pszPrintCmd, NULL);
568 fprintf(fp, " EXEC_STRING %s\n", ptr);
569 /*fprintf(fp, " EXEC_STRING %s\n", pFtD->pszPrintCmd);*/
572 fprintf(fp, " WINDOW_TYPE NO_STDIO\n");
575 /*********************************************************************/
576 /* Now writhe the Print MAP action. */
577 /*********************************************************************/
578 fprintf(fp, "ACTION Print\n");
580 fprintf(fp, " ARG_TYPE %s\n", pFtD->pszName);
581 fprintf(fp, " TYPE MAP\n");
582 fprintf(fp, " MAP_ACTION %s_PRINT\n", pFtD->pszName);
583 fprintf(fp, " LABEL %s\n", GETMESSAGE(7, 31, "Print"));
591 chmod(pszFile, 0644);
595 /*****************************************************************************/
597 /* WriteActionFile */
602 /* 1 could not open file */
604 /*****************************************************************************/
605 ushort WriteActionFile(ActionData *pAD)
608 FILE *fp = (FILE *)NULL;
612 char *msgPtr, *fmtPtr, *errPtr;
614 /***************************************************************************/
615 /* Open action file for writing. */
616 /***************************************************************************/
617 newName = ReplaceSpaces(AD.pszName);
618 pszEnvVar = getenv("HOME");
620 if ( pszEnvVar && strlen(pszEnvVar) ) {
621 pszFile = XtMalloc(strlen(pszEnvVar) + strlen(newName) + 10);
622 if (pszFile) sprintf(pszFile, "%s/%s", pszEnvVar, newName);
624 pszFile = XtMalloc(strlen(newName) + 10);
625 if (pszFile) sprintf(pszFile, "/tmp/%s", newName);
629 /***************************************************************************/
630 /* Open action file for writing. */
631 /***************************************************************************/
632 if (pszFile && (fp = fopen(pszFile, "w")) == NULL) {
634 printf("Can not open file.\n"); /* debug */
636 msgPtr = GETMESSAGE(5, 55, "Could not create the following file:");
638 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
639 strlen(pszFile) + 1) * sizeof(char));
640 sprintf(errPtr, fmtPtr, msgPtr, pszFile);
641 display_error_message(CreateActionAppShell, errPtr);
647 printf("action file = %s\n", pszFile); /* debug */
649 /***************************************************************************/
650 /* Write action file contents. */
651 /***************************************************************************/
652 fprintf(fp, "################################################\n");
654 fprintf(fp, "# action\n");
656 fprintf(fp, "# Common Desktop Environment (CDE)\n");
658 fprintf(fp, "# $TOG: fileio.c /main/9 1998/10/26 17:18:19 mgreess $\n");
660 fprintf(fp, "################################################\n");
662 fprintf(fp, "# This file represents a CDE Dt action. The contents of the file do\n");
663 fprintf(fp, "# not matter; however, the file must have executable permission and the\n");
664 fprintf(fp, "# name of the file must match an entry in the action database (*.dt files).\n");
666 fprintf(fp, "# For more information on Dt actions, see the CDE Dt manuals.\n");
668 fprintf(fp, "echo \"Common Desktop Environment Dt action\"\n");
672 chmod(pszFile, 0755);
676 /******************************************************************************/
677 /* check_file_exists - check if the file exists that is passed in, if not */
678 /* display error dialog. */
680 /* INPUT: filename - name of file to check if it exists or not. */
682 /* OUTPUT: TRUE - file exists */
683 /* FALSE - file does not exist */
685 /******************************************************************************/
686 Boolean check_file_exists (char *pszFileName)
690 /***************************************/
691 /* see if file exists */
692 /***************************************/
693 exists = fopen (pszFileName, "r");
695 /***************************************/
696 /* if exists, return good return code */
697 /***************************************/
703 printf("File '%s' does not exist!\n", pszFileName);
709 /*****************************************************************************/
711 /* OpenDefinitionFile */
718 /*****************************************************************************/
719 int OpenDefinitionFile(char *pszFile, ActionData *pAD)
722 FILE *fp = (FILE *)NULL;
724 char *msgPtr, *fmtPtr, *errPtr;
726 /***************************************************************************/
727 /* Open action and filetypes definition file for reading. */
728 /***************************************************************************/
729 if ((fp = fopen(pszFile, "r+")) == NULL) {
731 printf("Can not open file.\n"); /* debug */
733 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
735 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
736 strlen(pszFile) + 1) * sizeof(char));
737 sprintf(errPtr, fmtPtr, msgPtr, pszFile);
738 display_error_message(CreateActionAppShell, errPtr);
743 printf("Opened database file = %s\n", pszFile); /* debug */
746 /***************************************************************************/
747 /* If magic cookie is good, then parse the file. */
748 /***************************************************************************/
749 if (CheckCookie(fp)) {
751 printf("Cookie good, call parse code\n");
753 rc = GetActionData(fp, pAD);
755 /************************************************************************/
756 /* If error, display error message. */
757 /************************************************************************/
759 msgPtr = GETMESSAGE(5, 90, "Could not parse 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);
773 /******************************************************************************/
774 /* CheckDirtyIcon - check if icon has a DirtyBit set */
776 /* INPUT: Icon Widget - widget id of icon gadget to check */
778 /* OUTPUT: TRUE - dirty bit is set */
779 /* FALSE - dirty bit is not set */
781 /******************************************************************************/
782 Boolean CheckDirtyIcon (Widget wid)
786 pIconData = GetIconDataFromWid(wid);
788 if ( (pIconData->pmDirtyBit) || (pIconData->bmDirtyBit) ) {
795 /*****************************************************************************/
802 /* 1 could not open file */
804 /*****************************************************************************/
805 char * CreateIconName(char *pszDirName, char *pszBaseName, enum icon_size_range enumSize, char *pszType, Boolean bIsMask)
808 char pszSize[MAX_EXT_SIZE];
812 strcpy(pszSize, LARGE_EXT);
815 strcpy(pszSize, MEDIUM_EXT);
818 strcpy(pszSize, TINY_EXT);
822 strcat(pszSize, "_m");
825 pszName = XtMalloc(strlen(pszDirName) + strlen(pszBaseName) + strlen(pszSize) + strlen(pszType) + 1);
827 sprintf(pszName, "%s%s%s%s", pszDirName, pszBaseName, pszSize, pszType);
830 pszName = XtMalloc(strlen(pszBaseName) + strlen(pszSize) + strlen(pszType) + 1);
832 sprintf(pszName, "%s%s%s", pszBaseName, pszSize, pszType);
838 /*****************************************************************************/
845 /* 1 could not open file */
847 /*****************************************************************************/
848 ushort CopyFile(char *pszSource, char *pszDest)
857 char *msgPtr, *fmtPtr, *errPtr;
859 fdSource = open(pszSource, O_RDONLY);
860 if (fdSource == -1) {
861 msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
863 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
864 strlen(pszSource) + 1) * sizeof(char));
865 sprintf(errPtr, fmtPtr, msgPtr, pszSource);
866 display_error_message(CreateActionAppShell, errPtr);
870 /************************************************************/
871 /* Find out how big a buffer is needed */
872 /************************************************************/
873 len = lseek(fdSource, 0, SEEK_END);
874 (void) lseek(fdSource, 0, SEEK_SET);
875 buffer = XtMalloc((Cardinal) (len + 1));
876 if ((rlen = read(fdSource, buffer, len)) != len) {
877 /*********************************************************/
878 /* Didn't read whole file! */
879 /*********************************************************/
881 fdDest = creat(pszDest, 0644);
882 /*fdDest = open(pszDest, O_WRONLY);*/
884 msgPtr = GETMESSAGE(5, 55, "Could not create the following file:");
886 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
887 strlen(pszDest) + 1) * sizeof(char));
888 sprintf(errPtr, fmtPtr, msgPtr, pszDest);
889 display_error_message(CreateActionAppShell, errPtr);
893 if ((rlen = write(fdDest, buffer, len)) != len) {
894 /***************************************************/
895 /* Didn't write the whole file! */
896 /***************************************************/
909 /*****************************************************************************/
915 /* NULL error has occurred */
916 /* not NULL name of directory to store icons */
918 /*****************************************************************************/
919 char * CreateDirName(void)
921 char *pszNewName = (char *)NULL;
922 char *pszDirName = (char *)NULL;
924 char *msgPtr, *errPtr;
926 pszEnvVar = getenv("HOME");
927 if ( pszEnvVar && strlen(pszEnvVar) ) {
928 pszDirName = XtMalloc(strlen(pszEnvVar) + strlen("/.dt/icons/") + 1);
929 sprintf(pszDirName, "%s/.dt/icons/", pszEnvVar);
931 msgPtr = GETMESSAGE(5, 170, "The HOME environment variable is not set.\n\
932 The HOME environment variable must be set in order\n\
933 for this action to be saved.");
934 errPtr = XtNewString(msgPtr);
935 display_error_message(CreateActionAppShell, errPtr);
941 /*****************************************************************************/
943 /* CopyFilesFromWid */
948 /* 1 could not open file */
950 /*****************************************************************************/
951 ushort CopyFilesFromWid(ActionData *pAD, Widget wid)
955 char *pszDirName = (char *)NULL;
956 Boolean bHaveError = FALSE;
957 char *pszIconName = (char *)NULL;
958 char *pszNewName = (char *)NULL;
959 char *pszMaskName = (char *)NULL;
961 pszDirName = CreateDirName();
962 if (!pszDirName) bHaveError = True;
964 pIconData = GetIconDataFromWid(wid);
965 pszNewName = ReplaceSpaces(pAD->pszName);
967 if ((!bHaveError) && (pIconData)) {
968 pszIconName = CreateIconName(pszDirName, pszNewName, pIconData->size, PIXMAP_EXT, FALSE);
969 if ((!pszIconName) || (CopyFile(pIconData->pmFileName, pszIconName))) {
972 if (pszIconName) XtFree(pszIconName);
975 if ((!bHaveError) && (pIconData)) {
976 pszIconName = CreateIconName(pszDirName, pszNewName, pIconData->size, BITMAP_EXT, FALSE);
977 if ((!pszIconName) || (CopyFile(pIconData->bmFileName, pszIconName))) {
980 if (pszIconName) XtFree(pszIconName);
982 /**********************************************/
983 /* Now see if it has a mask file. */
984 /**********************************************/
986 pszMaskName = CreateMaskName(pIconData->bmFileName);
987 if ((pszMaskName) && (check_file_exists(pszMaskName))) {
989 printf("Mask file exists = %s\n", pszMaskName); /* debug */
991 pszIconName = CreateIconName(pszDirName, pszNewName, pIconData->size, BITMAP_EXT, TRUE);
992 if ((!pszIconName) || (CopyFile(pszMaskName, pszIconName))) {
995 if (pszIconName) XtFree(pszIconName);
1001 if (pszNewName) XtFree(pszNewName);
1002 if (pszDirName) XtFree(pszDirName);
1010 /******************************************************************************/
1011 /* ActionHasIcon - check if any of the main action's icons have dirty bit set */
1015 /* OUTPUT: TRUE - action has icon */
1016 /* FALSE - no icon for this action */
1018 /******************************************************************************/
1019 Boolean ActionHasIcon (void)
1021 if ( CheckDirtyIcon(CA_LRG_IconGadget) ||
1022 CheckDirtyIcon(CA_MED_IconGadget) ||
1023 CheckDirtyIcon(CA_TINY_IconGadget) ) {
1031 /******************************************************************************/
1032 /* FiletypeHasIcon - check if the filetype has modified icons. */
1034 /* INPUT: Filetype data structure pointer */
1036 /* OUTPUT: TRUE - action has icon */
1037 /* FALSE - no icon for this action */
1039 /******************************************************************************/
1040 Boolean FiletypeHasIcon (FiletypeData *pFtD)
1042 if ( (pFtD->pszMedPmIcon) ||
1043 (pFtD->pszMedBmIcon) ||
1044 (pFtD->pszTinyPmIcon) ||
1045 (pFtD->pszTinyBmIcon) ) {
1053 /*****************************************************************************/
1060 /* 1 could not open file */
1062 /*****************************************************************************/
1063 ushort CopyIconFiles(ActionData *pAD)
1066 Boolean bHaveError = FALSE;
1069 char *pszDirName = (char *)NULL;
1070 char *pszNewIconName;
1071 char *pszNewIconMask;
1072 char *pszOldIconName;
1074 char buffer[MAXFILENAME];
1077 #define CIF_SUCCESS 0
1079 if (ActionHasIcon()) {
1080 if ( !bHaveError && (CopyFilesFromWid(pAD, CA_LRG_IconGadget) != 0) ) {
1083 if ( !bHaveError && (CopyFilesFromWid(pAD, CA_MED_IconGadget) != 0) ) {
1086 if ( !bHaveError && (CopyFilesFromWid(pAD, CA_TINY_IconGadget) != 0) ) {
1091 if (!bHaveError && (pAD->papFiletypes)) {
1092 pszDirName = CreateDirName();
1093 for (i=0; i < pAD->cFiletypes; i++) {
1094 pFtD = pAD->papFiletypes[i];
1095 if (FiletypeHasIcon(pFtD)) {
1096 FIND_ICONGADGET_ICON(pFtD->pszIcon, pszOldIconName, DtMEDIUM);
1097 if (pszOldIconName) {
1098 ptr = strstr(pszOldIconName, MEDIUM_EXT);
1099 if (ptr) *ptr = '\0';
1102 /*****************************************************************/
1104 /*****************************************************************/
1105 pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Medium_Icon, PIXMAP_EXT, FALSE);
1106 if (pszNewIconName) {
1107 if (pFtD->pszMedPmIcon) {
1108 CopyFile(pFtD->pszMedPmIcon, pszNewIconName);
1110 ptr = CreateIconName((char *)NULL, pszOldIconName, Medium_Icon, PIXMAP_EXT, FALSE);
1112 CopyFile(ptr, pszNewIconName);
1116 if (pszNewIconName) XtFree(pszNewIconName);
1119 /*****************************************************************/
1121 /*****************************************************************/
1122 pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Medium_Icon, BITMAP_EXT, FALSE);
1123 pszNewIconMask = CreateIconName(pszDirName, pFtD->pszName, Medium_Icon, BITMAP_EXT, TRUE);
1124 if (pszNewIconName) {
1125 if (pFtD->pszMedBmIcon) {
1126 CopyFile(pFtD->pszMedBmIcon, pszNewIconName);
1127 /****************************/
1128 /* Now do the mask file. */
1129 /****************************/
1130 sprintf(buffer, "%s_m", pFtD->pszMedBmIcon);
1131 if (pszNewIconMask && check_file_exists(buffer)) {
1132 CopyFile(buffer, pszNewIconMask);
1135 ptr = CreateIconName((char *)NULL, pszOldIconName, Medium_Icon, BITMAP_EXT, FALSE);
1137 CopyFile(ptr, pszNewIconName);
1140 /****************************/
1141 /* Now do the mask file. */
1142 /****************************/
1143 ptr = CreateIconName((char *)NULL, pszOldIconName, Medium_Icon, BITMAP_EXT, TRUE);
1144 if (ptr && check_file_exists(ptr) && pszNewIconMask) {
1145 CopyFile(ptr, pszNewIconMask);
1149 if (pszNewIconName) XtFree(pszNewIconName);
1150 if (pszNewIconMask) XtFree(pszNewIconMask);
1153 /*****************************************************************/
1155 /*****************************************************************/
1156 pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Tiny_Icon, PIXMAP_EXT, FALSE);
1157 if (pszNewIconName) {
1158 if (pFtD->pszTinyPmIcon) {
1159 CopyFile(pFtD->pszTinyPmIcon, pszNewIconName);
1161 ptr = CreateIconName((char *)NULL, pszOldIconName, Tiny_Icon, PIXMAP_EXT, FALSE);
1163 CopyFile(ptr, pszNewIconName);
1167 if (pszNewIconName) XtFree(pszNewIconName);
1170 /*****************************************************************/
1172 /*****************************************************************/
1173 pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Tiny_Icon, BITMAP_EXT, FALSE);
1174 pszNewIconMask = CreateIconName(pszDirName, pFtD->pszName, Tiny_Icon, BITMAP_EXT, TRUE);
1175 if (pszNewIconName) {
1176 if (pFtD->pszTinyBmIcon) {
1177 CopyFile(pFtD->pszTinyBmIcon, pszNewIconName);
1178 /****************************/
1179 /* Now do the mask file. */
1180 /****************************/
1181 sprintf(buffer, "%s_m", pFtD->pszTinyBmIcon);
1182 if (pszNewIconMask && check_file_exists(buffer)) {
1183 CopyFile(buffer, pszNewIconMask);
1186 ptr = CreateIconName((char *)NULL, pszOldIconName, Tiny_Icon, BITMAP_EXT, FALSE);
1188 CopyFile(ptr, pszNewIconName);
1191 /****************************/
1192 /* Now do the mask file. */
1193 /****************************/
1194 ptr = CreateIconName((char *)NULL, pszOldIconName, Tiny_Icon, BITMAP_EXT, TRUE);
1195 if (ptr && check_file_exists(ptr) && pszNewIconMask) {
1196 CopyFile(ptr, pszNewIconMask);
1200 if (pszNewIconName) XtFree(pszNewIconName);
1201 if (pszNewIconMask) XtFree(pszNewIconMask);
1207 return(CIF_SUCCESS);