fileio.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <sys/stat.h>
  26. #include <sys/types.h>
  27. #include <fcntl.h>
  28. #include <unistd.h>
  29. #include <Dt/Icon.h>
  30. #include <stdlib.h>
  31. #include "dtcreate.h"
  32. #include "cmnrtns.h"
  33. #include "fileio.h"
  34. #include "parser.h"
  35. #include "ErrorDialog.h"
  36. #define COMMENT_CHAR '#'
  37. #define MAX_KEY 10000
  38. #define MAX_KEY_SIZE 5
  39. #define MAX_HEADER_LINES 13
  40. /*****************************************************************************/
  41. /* */
  42. /* CalculateMagicCookie */
  43. /* */
  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. */
  49. /* */
  50. /* input: pointer to FILE */
  51. /* output: integer - magic cookie */
  52. /* */
  53. /*****************************************************************************/
  54. int CalculateMagicCookie(FILE *fp)
  55. {
  56. #define PRIME1 2999
  57. #define PRIME2 353
  58. #define PRIME3 113
  59. long save_offset, file_id;
  60. int c, prev_c, char_sum, nline, nword, nchar, inword;
  61. /**************************************************************************/
  62. /* Since we will be traversing the file, we save the file-offset */
  63. /* so that we can restore it before returning */
  64. /**************************************************************************/
  65. save_offset = ftell( fp );
  66. inword = FALSE;
  67. char_sum = nline = nword = nchar = 0;
  68. prev_c = '0'; /* This is arbitrary, but '0' not '\0' IS intended */
  69. while ( (c = fgetc( fp )) != EOF ) {
  70. if ( c == COMMENT_CHAR ) {
  71. while ( (c = fgetc( fp )) != EOF && c != '\n' )
  72. ; /* skip characters to end of line */
  73. } else {
  74. char_sum += (c * (prev_c%10));
  75. prev_c = c;
  76. ++nchar;
  77. if (c == '\n') {
  78. ++nline;
  79. }
  80. if ( c == ' ' || c == '\n' || c == '\t' ) {
  81. inword = FALSE;
  82. } else if ( inword == FALSE ) {
  83. inword = TRUE;
  84. ++nword;
  85. }
  86. }
  87. }
  88. file_id = PRIME1 * nline + PRIME2 * nword + PRIME3 * nchar + char_sum;
  89. #ifdef DEBUG
  90. printf( "nline = %d nword = %d nchar = %d char_sum = %d\n",
  91. nline, nword, nchar, char_sum );
  92. printf( "file_id = %ld\n", file_id );
  93. #endif
  94. /**************************************************************************/
  95. /* We restore the file-offset to its previous value */
  96. /**************************************************************************/
  97. (void) fseek( fp, save_offset, 0 );
  98. return ( file_id % MAX_KEY );
  99. }
  100. /****************************************************************************/
  101. /* */
  102. /* SetCookie - find the location in the file to write the magic cookie */
  103. /* and update the file with the magic cookie. */
  104. /* */
  105. /* input - file pointer */
  106. /* output - none */
  107. /* */
  108. /****************************************************************************/
  109. void SetCookie(FILE *fp)
  110. {
  111. int iCookie;
  112. long lSave_offset;
  113. char buffer[256];
  114. char *keystr;
  115. char *retbuf;
  116. fpos_t filepos;
  117. char *mc_pos;
  118. char *mc_clrpos;
  119. int i;
  120. int size;
  121. /**************************************************************************/
  122. /* Save file pointer initial setting */
  123. /**************************************************************************/
  124. lSave_offset = ftell (fp);
  125. /**************************************************************************/
  126. /* Set file pointer to beginning of file */
  127. /**************************************************************************/
  128. fseek(fp, 0, SEEK_SET);
  129. /**************************************************************************/
  130. /* Calculate magic cookie */
  131. /**************************************************************************/
  132. iCookie = CalculateMagicCookie(fp);
  133. #ifdef DEBUG
  134. printf("Magic Cookie: %d\n", iCookie);
  135. #endif
  136. /**************************************************************************/
  137. /* Find location in header and store cookie */
  138. /**************************************************************************/
  139. keystr = (char *)NULL;
  140. retbuf = buffer;
  141. i = 0;
  142. while ( !keystr && retbuf && (i < MAX_HEADER_LINES) ) {
  143. fgetpos(fp, &filepos);
  144. retbuf = fgets(buffer, 80, fp);
  145. keystr = strstr (buffer, "$KEY:");
  146. i++;
  147. }
  148. if (!keystr) {
  149. #ifdef DEBUG
  150. printf("No '$KEY' keyword in file. Magic Cookie not written to file.\n");
  151. #endif
  152. return;
  153. }
  154. mc_pos = strchr(keystr, ':');
  155. if (mc_pos) {
  156. mc_pos += 2;
  157. sprintf(mc_pos, "%i", iCookie);
  158. size = strlen(mc_pos);
  159. if (size < MAX_KEY_SIZE) {
  160. mc_clrpos = mc_pos + size;
  161. for (i=size; i < MAX_KEY_SIZE; i++) {
  162. *mc_clrpos = ' ';
  163. mc_clrpos++;
  164. }
  165. }
  166. }
  167. fsetpos (fp, &filepos);
  168. fputs (buffer, fp);
  169. /**************************************************************************/
  170. /* Set file pointer back to initial setting */
  171. /**************************************************************************/
  172. fseek (fp, lSave_offset, SEEK_SET);
  173. return;
  174. }
  175. /****************************************************************************/
  176. /* */
  177. /* CheckCookie - check if the magic cookie exists in the file and is the */
  178. /* correct value. */
  179. /* */
  180. /* input - file pointer */
  181. /* output - boolean indicating if correct value or not, TRUE = good */
  182. /* */
  183. /****************************************************************************/
  184. Boolean CheckCookie(FILE *fp)
  185. {
  186. int iNewCookie, iOldCookie;
  187. long lSave_offset;
  188. char buffer[256];
  189. char *msgPtr, *errPtr;
  190. char *keystr;
  191. char *retbuf;
  192. fpos_t filepos;
  193. char *mc_pos;
  194. int i;
  195. Boolean bGoodCookie = TRUE;
  196. /**************************************************************************/
  197. /* Save file pointer initial setting */
  198. /**************************************************************************/
  199. lSave_offset = ftell (fp);
  200. /**************************************************************************/
  201. /* Set file pointer to beginning of file */
  202. /**************************************************************************/
  203. fseek (fp, 0, SEEK_SET);
  204. /**************************************************************************/
  205. /* Calculate magic cookie */
  206. /**************************************************************************/
  207. iNewCookie = CalculateMagicCookie(fp);
  208. #ifdef DEBUG
  209. printf("New Magic Cookie: %d\n", iNewCookie);
  210. #endif
  211. /**************************************************************************/
  212. /* Find location in header of old cookie and retrieve it. */
  213. /**************************************************************************/
  214. keystr = (char *)NULL;
  215. retbuf = buffer;
  216. i = 0;
  217. while ( !keystr && retbuf && (i < MAX_HEADER_LINES) ) {
  218. fgetpos(fp, &filepos);
  219. retbuf = fgets(buffer, 80, fp);
  220. keystr = strstr (buffer, "$KEY:");
  221. i++;
  222. }
  223. if (!keystr) {
  224. #ifdef DEBUG
  225. printf("No '$KEY' keyword in file header. File is invalid.\n");
  226. #endif
  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);
  232. XtFree(errPtr);
  233. bGoodCookie = FALSE;
  234. fseek (fp, lSave_offset, SEEK_SET);
  235. return(bGoodCookie);
  236. }
  237. mc_pos = strchr(keystr, ':');
  238. mc_pos += 2;
  239. sscanf(mc_pos, "%i", &iOldCookie);
  240. #ifdef DEBUG
  241. printf("Old Magic Cookie: %d\n", iOldCookie);
  242. #endif
  243. /**************************************************************************/
  244. /* Check if cookies are the same. */
  245. /**************************************************************************/
  246. #ifdef DEBUG
  247. if (iOldCookie == iNewCookie) {
  248. printf("Cookies are good = %i\n", iNewCookie);
  249. }
  250. #endif
  251. if (iOldCookie != iNewCookie) {
  252. #ifdef DEBUG
  253. printf("Cookies are bad; n=%i, o=%i\n", iNewCookie, iOldCookie);
  254. #endif
  255. msgPtr = GETMESSAGE(5, 66,
  256. "Could not load the file because it has been altered by some\n\
  257. other means other than Create Action. This could have been caused\n\
  258. by modifying the file with a text editor or some other tool.");
  259. errPtr = XtNewString(msgPtr);
  260. display_error_message(CreateActionAppShell, errPtr);
  261. XtFree(errPtr);
  262. bGoodCookie = FALSE;
  263. }
  264. /**************************************************************************/
  265. /* Set file pointer back to initial setting */
  266. /**************************************************************************/
  267. fseek (fp, lSave_offset, SEEK_SET);
  268. return(bGoodCookie);
  269. }
  270. /*****************************************************************************/
  271. /* */
  272. /* MakeExecString */
  273. /* */
  274. /* return codes: */
  275. /* */
  276. /* ptr good */
  277. /* 0 bad */
  278. /* */
  279. /*****************************************************************************/
  280. char * MakeExecString(char *pszCmd, char *pszPrompt)
  281. {
  282. char *pszExecString;
  283. char *pArgSrc = (char *)NULL;
  284. char *pArgDst = (char *)NULL;
  285. char *pTmp;
  286. char pszArgStr[10];
  287. int size = 0;
  288. int cArgs = 0;
  289. int val;
  290. Boolean bDidPrompt = FALSE;
  291. #define ARGSIZE 7 /* sizeof "%Arg_n%" */
  292. pArgSrc = pszCmd;
  293. while (pArgSrc = strchr(pArgSrc, '$')) {
  294. #ifdef DEBUG
  295. printf("%d pArgSrc = %s\n", cArgs, pArgSrc);
  296. #endif
  297. pArgSrc++;
  298. val = *pArgSrc;
  299. switch (val) {
  300. case '1': case '2': case '3': case '4': case '5':
  301. case '6': case '7': case '8': case '9': case '*':
  302. cArgs++;
  303. break;
  304. }
  305. }
  306. #ifdef DEBUG
  307. printf("Args found = %d\n", cArgs);
  308. #endif
  309. size = 1;
  310. size += cArgs * ARGSIZE;
  311. size += strlen(pszCmd);
  312. if (pszPrompt) {
  313. size += strlen(pszPrompt) + 2;
  314. }
  315. pszExecString = (char *)XtMalloc(size);
  316. strcpy(pszExecString, pszCmd);
  317. pArgSrc = pszCmd;
  318. pTmp = pszExecString;
  319. while (pArgSrc = strchr(pArgSrc, '$')) {
  320. pArgDst = strchr(pTmp, '$');
  321. pTmp = pArgDst;
  322. *pArgDst = '\0';
  323. pTmp++;
  324. val = *pTmp;
  325. switch (val) {
  326. case '1': case '2': case '3': case '4': case '5':
  327. case '6': case '7': case '8': case '9': case '*':
  328. pArgSrc+=2;
  329. if (*pTmp == '*') {
  330. strcat(pszExecString, "%Args");
  331. } else {
  332. sprintf(pszArgStr, "%%Arg_%c", *pTmp);
  333. strcat(pszExecString, pszArgStr);
  334. }
  335. if ((pszPrompt) && (!bDidPrompt)) {
  336. strcat(pszExecString, "\"");
  337. strcat(pszExecString, pszPrompt);
  338. strcat(pszExecString, "\"");
  339. bDidPrompt = TRUE;
  340. }
  341. strcat(pszExecString, "%");
  342. break;
  343. }
  344. if (*pArgSrc) {
  345. strcat(pszExecString, pArgSrc);
  346. pArgSrc++;
  347. }
  348. }
  349. #ifdef DEBUG
  350. printf("EXEC_STRING = '%s'\n", pszExecString);
  351. #endif
  352. return(pszExecString);
  353. }
  354. /*****************************************************************************/
  355. /* */
  356. /* WriteDefinitionFile */
  357. /* */
  358. /* return codes: */
  359. /* */
  360. /* 0 successful */
  361. /* 1 could not open file */
  362. /* */
  363. /*****************************************************************************/
  364. ushort WriteDefinitionFile(char *pszFile, ActionData *pAD)
  365. {
  366. FILE *fp = (FILE *)NULL;
  367. int i;
  368. FiletypeData *pFtD;
  369. char buffer[MAXBUFSIZE];
  370. char *ptr;
  371. char *msgPtr, *fmtPtr, *errPtr;
  372. if (!pszFile)
  373. return 1;
  374. /***************************************************************************/
  375. /* Open action and filetypes definition file for writing. */
  376. /***************************************************************************/
  377. if ((fp = fopen(pszFile, "w+")) == NULL) {
  378. #ifdef DEBUG
  379. printf("Can not open file.\n"); /* debug */
  380. #endif
  381. msgPtr = GETMESSAGE(5, 55, "Could not create the following file:");
  382. fmtPtr = "%s\n %s";
  383. errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
  384. strlen(pszFile) + 1) * sizeof(char));
  385. sprintf(errPtr, fmtPtr, msgPtr, pszFile);
  386. display_error_message(CreateActionAppShell, errPtr);
  387. XtFree(errPtr);
  388. return(1);
  389. }
  390. #ifdef DEBUG
  391. printf("database file = %s\n", pszFile); /* debug */
  392. #endif
  393. /***************************************************************************/
  394. /* Write comment area of action and filetype definition file, including */
  395. /* revision number and magic cookie. */
  396. /***************************************************************************/
  397. fprintf(fp, "######################################################################\n");
  398. fprintf(fp, "#\n");
  399. fprintf(fp, "# Common Desktop Environment (CDE)\n");
  400. fprintf(fp, "#\n");
  401. fprintf(fp, "# Action and DataType Definition File\n");
  402. fprintf(fp, "#\n");
  403. fprintf(fp, "# Generated by the CreateAction tool\n");
  404. fprintf(fp, "#\n");
  405. fprintf(fp, "# $Revision: 1.0\n");
  406. fprintf(fp, "#\n");
  407. fprintf(fp, "# $KEY: nnnnn \n");
  408. fprintf(fp, "#\n");
  409. fprintf(fp, "######################################################################\n");
  410. fprintf(fp, "#\n");
  411. fprintf(fp, "# WARNING:\n");
  412. fprintf(fp, "#\n");
  413. fprintf(fp, "# This file was generated by the CDE CreateAction tool.\n");
  414. fprintf(fp, "# If this file is modified by some other tool, such as vi,\n");
  415. fprintf(fp, "# the CreateAction tool will no longer be able to load and\n");
  416. fprintf(fp, "# update this file. For this reason, changes to this file\n");
  417. fprintf(fp, "# should be handled through CreateAction whenever possible.\n");
  418. fprintf(fp, "#\n");
  419. fprintf(fp, "######################################################################\n");
  420. fprintf(fp, "\n");
  421. /***************************************************************************/
  422. /* Write the main Action definition. */
  423. /***************************************************************************/
  424. ptr = GetCoreName(pszFile);
  425. fprintf(fp, "ACTION %s\n", ptr);
  426. free(ptr);
  427. fprintf(fp, "{\n");
  428. fprintf(fp, " LABEL %s\n", pAD->pszName);
  429. fprintf(fp, " TYPE COMMAND\n");
  430. ptr = MakeExecString(AD.pszCmd, AD.pszPrompt);
  431. if (ptr) {
  432. fprintf(fp, " EXEC_STRING %s\n", ptr);
  433. XtFree(ptr);
  434. }
  435. if (pAD->pszIcon) {
  436. #ifdef OLDICON
  437. fprintf(fp, " LARGE_ICON %s.m\n", pAD->pszIcon);
  438. fprintf(fp, " SMALL_ICON %s.t\n", pAD->pszIcon);
  439. #else
  440. if (ActionHasIcon()) {
  441. fprintf(fp, " ICON %s\n", pAD->pszName);
  442. } else {
  443. fprintf(fp, " ICON %s\n", pAD->pszIcon);
  444. }
  445. #endif
  446. }
  447. #ifdef DEBUG
  448. printf("CA flags = %X\n", pAD->fsFlags);
  449. #endif
  450. if (pAD->fsFlags & CA_WT_TERM) fprintf(fp, " WINDOW_TYPE TERMINAL\n");
  451. else if (pAD->fsFlags & CA_WT_PERMTERM) fprintf(fp, " WINDOW_TYPE PERM_TERMINAL\n");
  452. else if (pAD->fsFlags & CA_WT_SHELLTERM) fprintf(fp, " WINDOW_TYPE SHELL_TERMINAL\n");
  453. else fprintf(fp, " WINDOW_TYPE NO_STDIO\n");
  454. if ((pAD->papFiletypes) && (pAD->fsFlags & CA_DF_ONLYFTFILES)) {
  455. fprintf(fp, " ARG_TYPE %s", (pAD->papFiletypes[0])->pszName);
  456. for (i=1; i < pAD->cFiletypes; i++) {
  457. pFtD = pAD->papFiletypes[i];
  458. fprintf(fp, ",%s", pFtD->pszName);
  459. }
  460. fprintf(fp, "\n");
  461. }
  462. if (pAD->pszHelp) {
  463. fprintf(fp, " DESCRIPTION %s\n", pAD->pszHelp);
  464. }
  465. fprintf(fp, "}\n");
  466. fprintf(fp, "\n");
  467. /***************************************************************************/
  468. /* Write the filetype definitions. */
  469. /***************************************************************************/
  470. if (pAD->papFiletypes) {
  471. for (i=0; i < pAD->cFiletypes; i++) {
  472. pFtD = pAD->papFiletypes[i];
  473. /***********************************************************************/
  474. /* Write the data attributes declaration. */
  475. /***********************************************************************/
  476. fprintf(fp, "DATA_ATTRIBUTES %s\n", pFtD->pszName);
  477. fprintf(fp, "{\n");
  478. fprintf(fp, " ACTIONS Open");
  479. if (pFtD->pszPrintCmd) {
  480. fprintf(fp, ",Print");
  481. }
  482. fprintf(fp, "\n");
  483. if (pFtD->pszIcon) {
  484. #ifdef OLDICON
  485. fprintf(fp, " LARGE_ICON %s.m\n", pFtD->pszIcon);
  486. fprintf(fp, " SMALL_ICON %s.t\n", pFtD->pszIcon);
  487. #else
  488. if (FiletypeHasIcon(pFtD)) {
  489. fprintf(fp, " ICON %s\n", pFtD->pszName);
  490. } else {
  491. fprintf(fp, " ICON %s\n", pFtD->pszIcon);
  492. }
  493. #endif
  494. }
  495. if (pFtD->pszHelp) {
  496. fprintf(fp, " DESCRIPTION %s\n", pFtD->pszHelp);
  497. }
  498. fprintf(fp, "}\n");
  499. fprintf(fp, "\n");
  500. /***********************************************************************/
  501. /* Write the data criteria declaration. */
  502. /***********************************************************************/
  503. fprintf(fp, "DATA_CRITERIA %sA\n", pFtD->pszName);
  504. fprintf(fp, "{\n");
  505. fprintf(fp, " DATA_ATTRIBUTES_NAME %s\n", pFtD->pszName);
  506. if (pFtD->pszPermissions) {
  507. fprintf(fp, " MODE %s\n", pFtD->pszPermissions);
  508. }
  509. if (pFtD->pszPattern) {
  510. fprintf(fp, " PATH_PATTERN %s\n", pFtD->pszPattern);
  511. }
  512. if (pFtD->pszContents) {
  513. if (pFtD->fsFlags & CA_FT_CNTSTRING)
  514. strcpy(buffer, "string");
  515. else if (pFtD->fsFlags & CA_FT_CNTBYTE)
  516. strcpy(buffer, "byte");
  517. else if (pFtD->fsFlags & CA_FT_CNTSHORT)
  518. strcpy(buffer, "short");
  519. else if (pFtD->fsFlags & CA_FT_CNTLONG)
  520. strcpy(buffer, "long");
  521. fprintf(fp, " CONTENT %d %s %s\n", pFtD->sStart, buffer, pFtD->pszContents);
  522. }
  523. fprintf(fp, "}\n");
  524. fprintf(fp, "\n");
  525. /***********************************************************************/
  526. /* Write the Open MAP action. */
  527. /***********************************************************************/
  528. fprintf(fp, "ACTION Open\n");
  529. fprintf(fp, "{\n");
  530. fprintf(fp, " ARG_TYPE %s\n", pFtD->pszName);
  531. fprintf(fp, " TYPE MAP\n");
  532. fprintf(fp, " MAP_ACTION %s\n", pAD->pszName);
  533. fprintf(fp, " LABEL %s\n", GETMESSAGE(7, 30, "Open"));
  534. fprintf(fp, "}\n");
  535. fprintf(fp, "\n");
  536. /***********************************************************************/
  537. /* Write the Print filetype action and MAP action. */
  538. /***********************************************************************/
  539. if (pFtD->pszPrintCmd) {
  540. /*********************************************************************/
  541. /* First write the print filetype action. */
  542. /*********************************************************************/
  543. fprintf(fp, "ACTION %s_PRINT\n", pFtD->pszName);
  544. fprintf(fp, "{\n");
  545. fprintf(fp, " TYPE COMMAND\n");
  546. ptr = MakeExecString(pFtD->pszPrintCmd, NULL);
  547. if (ptr) {
  548. fprintf(fp, " EXEC_STRING %s\n", ptr);
  549. /*fprintf(fp, " EXEC_STRING %s\n", pFtD->pszPrintCmd);*/
  550. XtFree(ptr);
  551. }
  552. fprintf(fp, " WINDOW_TYPE NO_STDIO\n");
  553. fprintf(fp, "}\n");
  554. fprintf(fp, "\n");
  555. /*********************************************************************/
  556. /* Now writhe the Print MAP action. */
  557. /*********************************************************************/
  558. fprintf(fp, "ACTION Print\n");
  559. fprintf(fp, "{\n");
  560. fprintf(fp, " ARG_TYPE %s\n", pFtD->pszName);
  561. fprintf(fp, " TYPE MAP\n");
  562. fprintf(fp, " MAP_ACTION %s_PRINT\n", pFtD->pszName);
  563. fprintf(fp, " LABEL %s\n", GETMESSAGE(7, 31, "Print"));
  564. fprintf(fp, "}\n");
  565. fprintf(fp, "\n");
  566. }
  567. }
  568. }
  569. SetCookie(fp);
  570. if (fp)
  571. fclose(fp);
  572. chmod(pszFile, 0644);
  573. return(0);
  574. }
  575. /*****************************************************************************/
  576. /* */
  577. /* WriteActionFile */
  578. /* */
  579. /* return codes: */
  580. /* */
  581. /* 0 successful */
  582. /* 1 could not open file */
  583. /* */
  584. /*****************************************************************************/
  585. ushort WriteActionFile(ActionData *pAD)
  586. {
  587. FILE *fp = (FILE *)NULL;
  588. char *pszFile;
  589. char *newName;
  590. char *pszEnvVar;
  591. char *msgPtr, *fmtPtr, *errPtr;
  592. /***************************************************************************/
  593. /* Open action file for writing. */
  594. /***************************************************************************/
  595. newName = ReplaceSpaces(AD.pszName);
  596. pszEnvVar = getenv("HOME");
  597. pszFile = NULL;
  598. if ( pszEnvVar && strlen(pszEnvVar) ) {
  599. pszFile = XtMalloc(strlen(pszEnvVar) + strlen(newName) + 10);
  600. if (pszFile) sprintf(pszFile, "%s/%s", pszEnvVar, newName);
  601. } else {
  602. pszFile = XtMalloc(strlen(newName) + 10);
  603. if (pszFile) sprintf(pszFile, "/tmp/%s", newName);
  604. }
  605. free(newName);
  606. /***************************************************************************/
  607. /* Open action file for writing. */
  608. /***************************************************************************/
  609. if (pszFile == NULL || (fp = fopen(pszFile, "w")) == NULL) {
  610. #ifdef DEBUG
  611. printf("Can not open file.\n"); /* debug */
  612. #endif
  613. msgPtr = GETMESSAGE(5, 55, "Could not create the following file:");
  614. fmtPtr = "%s\n %s";
  615. errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
  616. strlen(pszFile) + 1) * sizeof(char));
  617. sprintf(errPtr, fmtPtr, msgPtr, pszFile);
  618. display_error_message(CreateActionAppShell, errPtr);
  619. XtFree(errPtr);
  620. XtFree(pszFile);
  621. return(1);
  622. }
  623. #ifdef DEBUG
  624. printf("action file = %s\n", pszFile); /* debug */
  625. #endif
  626. /***************************************************************************/
  627. /* Write action file contents. */
  628. /***************************************************************************/
  629. fprintf(fp, "################################################\n");
  630. fprintf(fp, "#\n");
  631. fprintf(fp, "# action\n");
  632. fprintf(fp, "#\n");
  633. fprintf(fp, "# Common Desktop Environment (CDE)\n");
  634. fprintf(fp, "#\n");
  635. fprintf(fp, "# $TOG: fileio.c /main/9 1998/10/26 17:18:19 mgreess $\n");
  636. fprintf(fp, "#\n");
  637. fprintf(fp, "################################################\n");
  638. fprintf(fp, "\n");
  639. fprintf(fp, "# This file represents a CDE Dt action. The contents of the file do\n");
  640. fprintf(fp, "# not matter; however, the file must have executable permission and the\n");
  641. fprintf(fp, "# name of the file must match an entry in the action database (*.dt files).\n");
  642. fprintf(fp, "#\n");
  643. fprintf(fp, "# For more information on Dt actions, see the CDE Dt manuals.\n");
  644. fprintf(fp, "\n");
  645. fprintf(fp, "echo \"Common Desktop Environment Dt action\"\n");
  646. fprintf(fp, "\n");
  647. fclose(fp);
  648. chmod(pszFile, 0755);
  649. return(0);
  650. }
  651. /******************************************************************************/
  652. /* check_file_exists - check if the file exists that is passed in, if not */
  653. /* display error dialog. */
  654. /* */
  655. /* INPUT: filename - name of file to check if it exists or not. */
  656. /* */
  657. /* OUTPUT: TRUE - file exists */
  658. /* FALSE - file does not exist */
  659. /* */
  660. /******************************************************************************/
  661. Boolean check_file_exists (char *pszFileName)
  662. {
  663. FILE *exists;
  664. /***************************************/
  665. /* see if file exists */
  666. /***************************************/
  667. exists = fopen (pszFileName, "r");
  668. /***************************************/
  669. /* if exists, return good return code */
  670. /***************************************/
  671. if (exists) {
  672. fclose (exists);
  673. return(TRUE);
  674. } else {
  675. #ifdef DEBUG
  676. printf("File '%s' does not exist!\n", pszFileName);
  677. #endif
  678. return(FALSE);
  679. }
  680. }
  681. /*****************************************************************************/
  682. /* */
  683. /* OpenDefinitionFile */
  684. /* */
  685. /* return codes: */
  686. /* */
  687. /* 0 successful */
  688. /* 1 error */
  689. /* */
  690. /*****************************************************************************/
  691. int OpenDefinitionFile(char *pszFile, ActionData *pAD)
  692. {
  693. FILE *fp = (FILE *)NULL;
  694. int rc = 1;
  695. char *msgPtr, *fmtPtr, *errPtr;
  696. /***************************************************************************/
  697. /* Open action and filetypes definition file for reading. */
  698. /***************************************************************************/
  699. if ((fp = fopen(pszFile, "r+")) == NULL) {
  700. #ifdef DEBUG
  701. printf("Can not open file.\n"); /* debug */
  702. #endif
  703. msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
  704. fmtPtr = "%s\n %s";
  705. errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
  706. strlen(pszFile) + 1) * sizeof(char));
  707. sprintf(errPtr, fmtPtr, msgPtr, pszFile);
  708. display_error_message(CreateActionAppShell, errPtr);
  709. XtFree(errPtr);
  710. return(1);
  711. }
  712. #ifdef DEBUG
  713. printf("Opened database file = %s\n", pszFile); /* debug */
  714. #endif
  715. /***************************************************************************/
  716. /* If magic cookie is good, then parse the file. */
  717. /***************************************************************************/
  718. if (CheckCookie(fp)) {
  719. #ifdef DEBUG
  720. printf("Cookie good, call parse code\n");
  721. #endif
  722. rc = GetActionData(fp, pAD);
  723. /************************************************************************/
  724. /* If error, display error message. */
  725. /************************************************************************/
  726. if (rc) {
  727. msgPtr = GETMESSAGE(5, 90, "Could not parse the following file:");
  728. fmtPtr = "%s\n %s";
  729. errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
  730. strlen(pszFile) + 1) * sizeof(char));
  731. sprintf(errPtr, fmtPtr, msgPtr, pszFile);
  732. display_error_message(CreateActionAppShell, errPtr);
  733. XtFree(errPtr);
  734. fclose(fp);
  735. return(1);
  736. }
  737. }
  738. fclose(fp);
  739. return(rc);
  740. }
  741. /******************************************************************************/
  742. /* CheckDirtyIcon - check if icon has a DirtyBit set */
  743. /* */
  744. /* INPUT: Icon Widget - widget id of icon gadget to check */
  745. /* */
  746. /* OUTPUT: TRUE - dirty bit is set */
  747. /* FALSE - dirty bit is not set */
  748. /* */
  749. /******************************************************************************/
  750. Boolean CheckDirtyIcon (Widget wid)
  751. {
  752. IconData *pIconData;
  753. pIconData = GetIconDataFromWid(wid);
  754. if (pIconData) {
  755. if ( (pIconData->pmDirtyBit) || (pIconData->bmDirtyBit) ) {
  756. return(True);
  757. }
  758. }
  759. return(False);
  760. }
  761. /*****************************************************************************/
  762. /* */
  763. /* CreateIconName */
  764. /* */
  765. /* return codes: */
  766. /* */
  767. /* 0 successful */
  768. /* 1 could not open file */
  769. /* */
  770. /*****************************************************************************/
  771. char * CreateIconName(char *pszDirName, char *pszBaseName, enum icon_size_range enumSize, char *pszType, Boolean bIsMask)
  772. {
  773. char *pszName;
  774. char pszSize[MAX_EXT_SIZE];
  775. switch (enumSize) {
  776. case Large_Icon :
  777. strcpy(pszSize, LARGE_EXT);
  778. break;
  779. case Medium_Icon :
  780. strcpy(pszSize, MEDIUM_EXT);
  781. break;
  782. case Small_Icon :
  783. strcpy(pszSize, SMALL_EXT);
  784. break;
  785. case Tiny_Icon :
  786. strcpy(pszSize, TINY_EXT);
  787. break;
  788. case None_Selected :
  789. pszSize[0] = 0;
  790. }
  791. if (bIsMask) {
  792. strcat(pszSize, "_m");
  793. }
  794. if (pszDirName) {
  795. pszName = XtMalloc(strlen(pszDirName) + strlen(pszBaseName) + strlen(pszSize) + strlen(pszType) + 1);
  796. if (pszName) {
  797. sprintf(pszName, "%s%s%s%s", pszDirName, pszBaseName, pszSize, pszType);
  798. }
  799. } else {
  800. pszName = XtMalloc(strlen(pszBaseName) + strlen(pszSize) + strlen(pszType) + 1);
  801. if (pszName) {
  802. sprintf(pszName, "%s%s%s", pszBaseName, pszSize, pszType);
  803. }
  804. }
  805. return(pszName);
  806. }
  807. /*****************************************************************************/
  808. /* */
  809. /* CopyFile */
  810. /* */
  811. /* return codes: */
  812. /* */
  813. /* 0 successful */
  814. /* 1 could not open file */
  815. /* */
  816. /*****************************************************************************/
  817. ushort CopyFile(char *pszSource, char *pszDest)
  818. {
  819. int fdSource;
  820. int fdDest;
  821. int len;
  822. int rlen;
  823. ushort usRc = 0;
  824. char *buffer;
  825. char *msgPtr, *fmtPtr, *errPtr;
  826. fdSource = open(pszSource, O_RDONLY);
  827. if (fdSource == -1) {
  828. msgPtr = GETMESSAGE(5, 60, "Could not open the following file:");
  829. fmtPtr = "%s\n %s";
  830. errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
  831. strlen(pszSource) + 1) * sizeof(char));
  832. sprintf(errPtr, fmtPtr, msgPtr, pszSource);
  833. display_error_message(CreateActionAppShell, errPtr);
  834. XtFree(errPtr);
  835. usRc = 1;
  836. } else {
  837. /************************************************************/
  838. /* Find out how big a buffer is needed */
  839. /************************************************************/
  840. len = lseek(fdSource, 0, SEEK_END);
  841. (void) lseek(fdSource, 0, SEEK_SET);
  842. buffer = XtMalloc((Cardinal) (len + 1));
  843. if ((rlen = read(fdSource, buffer, len)) != len) {
  844. /*********************************************************/
  845. /* Didn't read whole file! */
  846. /*********************************************************/
  847. } else {
  848. fdDest = creat(pszDest, 0644);
  849. /*fdDest = open(pszDest, O_WRONLY);*/
  850. if (fdDest == -1) {
  851. msgPtr = GETMESSAGE(5, 55, "Could not create the following file:");
  852. fmtPtr = "%s\n %s";
  853. errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
  854. strlen(pszDest) + 1) * sizeof(char));
  855. sprintf(errPtr, fmtPtr, msgPtr, pszDest);
  856. display_error_message(CreateActionAppShell, errPtr);
  857. XtFree(errPtr);
  858. usRc = 1;
  859. } else {
  860. if ((rlen = write(fdDest, buffer, len)) != len) {
  861. /***************************************************/
  862. /* Didn't write the whole file! */
  863. /***************************************************/
  864. }
  865. close(fdDest);
  866. }
  867. }
  868. XtFree(buffer);
  869. close(fdSource);
  870. }
  871. return(usRc);
  872. }
  873. /*****************************************************************************/
  874. /* */
  875. /* CreateDirName */
  876. /* */
  877. /* return codes: */
  878. /* */
  879. /* NULL error has occurred */
  880. /* not NULL name of directory to store icons */
  881. /* */
  882. /*****************************************************************************/
  883. char * CreateDirName(void)
  884. {
  885. char *pszNewName = (char *)NULL;
  886. char *pszDirName = (char *)NULL;
  887. char *pszEnvVar;
  888. char *msgPtr, *errPtr;
  889. pszEnvVar = getenv("HOME");
  890. if ( pszEnvVar && strlen(pszEnvVar) ) {
  891. pszDirName = XtMalloc(strlen(pszEnvVar) + strlen("/.dt/icons/") + 1);
  892. sprintf(pszDirName, "%s/.dt/icons/", pszEnvVar);
  893. } else {
  894. msgPtr = GETMESSAGE(5, 170, "The HOME environment variable is not set.\n\
  895. The HOME environment variable must be set in order\n\
  896. for this action to be saved.");
  897. errPtr = XtNewString(msgPtr);
  898. display_error_message(CreateActionAppShell, errPtr);
  899. XtFree(errPtr);
  900. }
  901. return(pszDirName);
  902. }
  903. /*****************************************************************************/
  904. /* */
  905. /* CopyFilesFromWid */
  906. /* */
  907. /* return codes: */
  908. /* */
  909. /* 0 successful */
  910. /* 1 could not open file */
  911. /* */
  912. /*****************************************************************************/
  913. ushort CopyFilesFromWid(ActionData *pAD, Widget wid)
  914. {
  915. IconData *pIconData;
  916. char *pszDirName = (char *)NULL;
  917. Boolean bHaveError = FALSE;
  918. char *pszIconName = (char *)NULL;
  919. char *pszNewName = (char *)NULL;
  920. char *pszMaskName = (char *)NULL;
  921. pszDirName = CreateDirName();
  922. if (!pszDirName) bHaveError = True;
  923. pIconData = GetIconDataFromWid(wid);
  924. pszNewName = ReplaceSpaces(pAD->pszName);
  925. if ((!bHaveError) && (pIconData)) {
  926. pszIconName = CreateIconName(pszDirName, pszNewName, pIconData->size, PIXMAP_EXT, FALSE);
  927. if ((!pszIconName) || (CopyFile(pIconData->pmFileName, pszIconName))) {
  928. bHaveError = True;
  929. }
  930. if (pszIconName) XtFree(pszIconName);
  931. }
  932. if ((!bHaveError) && (pIconData)) {
  933. pszIconName = CreateIconName(pszDirName, pszNewName, pIconData->size, BITMAP_EXT, FALSE);
  934. if ((!pszIconName) || (CopyFile(pIconData->bmFileName, pszIconName))) {
  935. bHaveError = True;
  936. }
  937. if (pszIconName) XtFree(pszIconName);
  938. /**********************************************/
  939. /* Now see if it has a mask file. */
  940. /**********************************************/
  941. if (!bHaveError) {
  942. pszMaskName = CreateMaskName(pIconData->bmFileName);
  943. if ((pszMaskName) && (check_file_exists(pszMaskName))) {
  944. #ifdef DEBUG
  945. printf("Mask file exists = %s\n", pszMaskName); /* debug */
  946. #endif
  947. pszIconName = CreateIconName(pszDirName, pszNewName, pIconData->size, BITMAP_EXT, TRUE);
  948. if ((!pszIconName) || (CopyFile(pszMaskName, pszIconName))) {
  949. bHaveError = True;
  950. }
  951. if (pszIconName) XtFree(pszIconName);
  952. XtFree(pszMaskName);
  953. }
  954. }
  955. }
  956. if (pszNewName) XtFree(pszNewName);
  957. if (pszDirName) XtFree(pszDirName);
  958. if (bHaveError) {
  959. return(1);
  960. } else {
  961. return(0);
  962. }
  963. }
  964. /******************************************************************************/
  965. /* ActionHasIcon - check if any of the main action's icons have dirty bit set */
  966. /* */
  967. /* INPUT: none */
  968. /* */
  969. /* OUTPUT: TRUE - action has icon */
  970. /* FALSE - no icon for this action */
  971. /* */
  972. /******************************************************************************/
  973. Boolean ActionHasIcon (void)
  974. {
  975. if ( CheckDirtyIcon(CA_LRG_IconGadget) ||
  976. CheckDirtyIcon(CA_MED_IconGadget) ||
  977. CheckDirtyIcon(CA_TINY_IconGadget) ) {
  978. return(True);
  979. } else {
  980. return(False);
  981. }
  982. }
  983. /******************************************************************************/
  984. /* FiletypeHasIcon - check if the filetype has modified icons. */
  985. /* */
  986. /* INPUT: Filetype data structure pointer */
  987. /* */
  988. /* OUTPUT: TRUE - action has icon */
  989. /* FALSE - no icon for this action */
  990. /* */
  991. /******************************************************************************/
  992. Boolean FiletypeHasIcon (FiletypeData *pFtD)
  993. {
  994. if ( (pFtD->pszMedPmIcon) ||
  995. (pFtD->pszMedBmIcon) ||
  996. (pFtD->pszTinyPmIcon) ||
  997. (pFtD->pszTinyBmIcon) ) {
  998. return(True);
  999. } else {
  1000. return(False);
  1001. }
  1002. }
  1003. /*****************************************************************************/
  1004. /* */
  1005. /* CopyIconFiles */
  1006. /* */
  1007. /* return codes: */
  1008. /* */
  1009. /* 0 successful */
  1010. /* 1 could not open file */
  1011. /* */
  1012. /*****************************************************************************/
  1013. ushort CopyIconFiles(ActionData *pAD)
  1014. {
  1015. Boolean bHaveError = FALSE;
  1016. FiletypeData *pFtD;
  1017. int i;
  1018. char *pszDirName = (char *)NULL;
  1019. char *pszNewIconName;
  1020. char *pszNewIconMask;
  1021. char *pszOldIconName;
  1022. char *ptr;
  1023. char buffer[MAXFILENAME];
  1024. #define CIF_ERROR 1
  1025. #define CIF_SUCCESS 0
  1026. if (ActionHasIcon()) {
  1027. if ( !bHaveError && (CopyFilesFromWid(pAD, CA_LRG_IconGadget) != 0) ) {
  1028. bHaveError = TRUE;
  1029. }
  1030. if ( !bHaveError && (CopyFilesFromWid(pAD, CA_MED_IconGadget) != 0) ) {
  1031. bHaveError = TRUE;
  1032. }
  1033. if ( !bHaveError && (CopyFilesFromWid(pAD, CA_TINY_IconGadget) != 0) ) {
  1034. bHaveError = TRUE;
  1035. }
  1036. }
  1037. if (!bHaveError && (pAD->papFiletypes)) {
  1038. pszDirName = CreateDirName();
  1039. for (i=0; i < pAD->cFiletypes; i++) {
  1040. pFtD = pAD->papFiletypes[i];
  1041. if (FiletypeHasIcon(pFtD)) {
  1042. FIND_ICONGADGET_ICON(pFtD->pszIcon, pszOldIconName, DtMEDIUM);
  1043. if (pszOldIconName) {
  1044. ptr = strstr(pszOldIconName, MEDIUM_EXT);
  1045. if (ptr) *ptr = '\0';
  1046. }
  1047. /*****************************************************************/
  1048. /* Medium Pixmap */
  1049. /*****************************************************************/
  1050. pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Medium_Icon, PIXMAP_EXT, FALSE);
  1051. if (pszNewIconName) {
  1052. if (pFtD->pszMedPmIcon) {
  1053. CopyFile(pFtD->pszMedPmIcon, pszNewIconName);
  1054. } else {
  1055. ptr = CreateIconName((char *)NULL, pszOldIconName, Medium_Icon, PIXMAP_EXT, FALSE);
  1056. if (ptr) {
  1057. CopyFile(ptr, pszNewIconName);
  1058. XtFree(ptr);
  1059. }
  1060. }
  1061. if (pszNewIconName) XtFree(pszNewIconName);
  1062. }
  1063. /*****************************************************************/
  1064. /* Medium Bitmap */
  1065. /*****************************************************************/
  1066. pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Medium_Icon, BITMAP_EXT, FALSE);
  1067. pszNewIconMask = CreateIconName(pszDirName, pFtD->pszName, Medium_Icon, BITMAP_EXT, TRUE);
  1068. if (pszNewIconName) {
  1069. if (pFtD->pszMedBmIcon) {
  1070. CopyFile(pFtD->pszMedBmIcon, pszNewIconName);
  1071. /****************************/
  1072. /* Now do the mask file. */
  1073. /****************************/
  1074. sprintf(buffer, "%s_m", pFtD->pszMedBmIcon);
  1075. if (pszNewIconMask && check_file_exists(buffer)) {
  1076. CopyFile(buffer, pszNewIconMask);
  1077. }
  1078. } else {
  1079. ptr = CreateIconName((char *)NULL, pszOldIconName, Medium_Icon, BITMAP_EXT, FALSE);
  1080. if (ptr) {
  1081. CopyFile(ptr, pszNewIconName);
  1082. XtFree(ptr);
  1083. }
  1084. /****************************/
  1085. /* Now do the mask file. */
  1086. /****************************/
  1087. ptr = CreateIconName((char *)NULL, pszOldIconName, Medium_Icon, BITMAP_EXT, TRUE);
  1088. if (ptr && check_file_exists(ptr) && pszNewIconMask) {
  1089. CopyFile(ptr, pszNewIconMask);
  1090. XtFree(ptr);
  1091. }
  1092. }
  1093. if (pszNewIconName) XtFree(pszNewIconName);
  1094. if (pszNewIconMask) XtFree(pszNewIconMask);
  1095. }
  1096. /*****************************************************************/
  1097. /* Tiny Pixmap */
  1098. /*****************************************************************/
  1099. pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Tiny_Icon, PIXMAP_EXT, FALSE);
  1100. if (pszNewIconName) {
  1101. if (pFtD->pszTinyPmIcon) {
  1102. CopyFile(pFtD->pszTinyPmIcon, pszNewIconName);
  1103. } else {
  1104. ptr = CreateIconName((char *)NULL, pszOldIconName, Tiny_Icon, PIXMAP_EXT, FALSE);
  1105. if (ptr) {
  1106. CopyFile(ptr, pszNewIconName);
  1107. XtFree(ptr);
  1108. }
  1109. }
  1110. if (pszNewIconName) XtFree(pszNewIconName);
  1111. }
  1112. /*****************************************************************/
  1113. /* Tiny Bitmap */
  1114. /*****************************************************************/
  1115. pszNewIconName = CreateIconName(pszDirName, pFtD->pszName, Tiny_Icon, BITMAP_EXT, FALSE);
  1116. pszNewIconMask = CreateIconName(pszDirName, pFtD->pszName, Tiny_Icon, BITMAP_EXT, TRUE);
  1117. if (pszNewIconName) {
  1118. if (pFtD->pszTinyBmIcon) {
  1119. CopyFile(pFtD->pszTinyBmIcon, pszNewIconName);
  1120. /****************************/
  1121. /* Now do the mask file. */
  1122. /****************************/
  1123. sprintf(buffer, "%s_m", pFtD->pszTinyBmIcon);
  1124. if (pszNewIconMask && check_file_exists(buffer)) {
  1125. CopyFile(buffer, pszNewIconMask);
  1126. }
  1127. } else {
  1128. ptr = CreateIconName((char *)NULL, pszOldIconName, Tiny_Icon, BITMAP_EXT, FALSE);
  1129. if (ptr) {
  1130. CopyFile(ptr, pszNewIconName);
  1131. XtFree(ptr);
  1132. }
  1133. /****************************/
  1134. /* Now do the mask file. */
  1135. /****************************/
  1136. ptr = CreateIconName((char *)NULL, pszOldIconName, Tiny_Icon, BITMAP_EXT, TRUE);
  1137. if (ptr && check_file_exists(ptr) && pszNewIconMask) {
  1138. CopyFile(ptr, pszNewIconMask);
  1139. XtFree(ptr);
  1140. }
  1141. }
  1142. if (pszNewIconName) XtFree(pszNewIconName);
  1143. if (pszNewIconMask) XtFree(pszNewIconMask);
  1144. }
  1145. }
  1146. }
  1147. }
  1148. return(CIF_SUCCESS);
  1149. }