ca_aux.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  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. /* $TOG: ca_aux.c /main/10 1999/09/17 15:44:00 mgreess $ */
  24. /******************************************************************************/
  25. /* */
  26. /* ca_aux - auxiliary functions for create action */
  27. /* */
  28. /* Functions to get/set values from/to interface. */
  29. /* Callback routines for CA interface. */
  30. /* */
  31. /******************************************************************************/
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <sys/signal.h>
  35. #include <errno.h>
  36. #include <unistd.h>
  37. #include <X11/cursorfont.h>
  38. #include <X11/Xlib.h>
  39. #include <X11/Xatom.h>
  40. #include <Xm/Xm.h>
  41. #include <Xm/TextF.h>
  42. #include <Xm/RowColumnP.h>
  43. #include <Xm/MessageB.h>
  44. #include <Xm/FileSB.h>
  45. #include <sys/stat.h>
  46. #if defined(AIXV3)
  47. # include <sys/dir.h>
  48. #else
  49. # if defined(__linux__)
  50. # include <dirent.h>
  51. # else
  52. # include <sys/dirent.h>
  53. # endif
  54. #endif
  55. #include <Dt/Icon.h>
  56. #include <Dt/IconFile.h>
  57. #include "dtcreate.h"
  58. #include "af_aux.h"
  59. #include "ca_aux.h"
  60. #include "cmncbs.h"
  61. #include "cmnrtns.h"
  62. #include "cmnutils.h"
  63. #include "CreateActionAppShell.h"
  64. #include "Confirmed.h"
  65. #include "ErrorDialog.h"
  66. #include "FileCharacteristics.h"
  67. /* from main.c */
  68. extern void RemoveTmpIconFiles( void );
  69. /******************************************************************************/
  70. /* */
  71. /* External Variables */
  72. /* */
  73. /******************************************************************************/
  74. extern XtArgVal /* Dimension */ wintypeheight, winheight, xprtheight, newheight;
  75. /******************************************************************************/
  76. /* */
  77. /* Variables */
  78. /* */
  79. /******************************************************************************/
  80. struct _ActionData *ca_local_struct;
  81. /******************************************************************************/
  82. /* readCAFromGUI - loads Action data structure with data read from */
  83. /* the GUI interface. */
  84. /* */
  85. /* */
  86. /******************************************************************************/
  87. void readCAFromGUI (struct _ActionData *ca_struct)
  88. {
  89. getCAactionName (ca_struct);
  90. getCAdblClkCmd (ca_struct);
  91. getCAactionHelpText (ca_struct);
  92. /*getCAfileTypes (ca_struct);*/
  93. getCAactionOpensText (ca_struct);
  94. /*getCAwindowType (ca_struct);*/
  95. /*getCAactionIcons (ca_struct);*/
  96. /*getCAexpertOption (ca_struct);*/
  97. return;
  98. }
  99. /******************************************************************************/
  100. /* writeCAToGUI - loads widgets with data stored in the integration */
  101. /* data structure */
  102. /* */
  103. /* */
  104. /******************************************************************************/
  105. void writeCAToGUI (struct _ActionData *pAD)
  106. {
  107. putCAactionName (pAD);
  108. putCAactionIcons (pAD);
  109. putCAdblClkCmd (pAD);
  110. putCAactionHelpText (pAD);
  111. putCAwindowType (pAD);
  112. putCAactionOpensText (pAD);
  113. putCAfileTypes (pAD);
  114. putCAdropFiletypes(pAD);
  115. return;
  116. }
  117. /******************************************************************************/
  118. /* getCAactionName - retrieves the action name text string and stores */
  119. /* the value in the ActionData structure */
  120. /* INPUT: _ActionData *ca_struct - Action data structure */
  121. /* OUTPUT: none */
  122. /******************************************************************************/
  123. void getCAactionName (struct _ActionData *ca_struct)
  124. {
  125. GetWidgetTextString(CA_ActionNameTextField, &(AD.pszName));
  126. }
  127. /******************************************************************************/
  128. /* getCAdblClkCmd - retrieves the double-click command text */
  129. /* string and stores the value in the ActionData structure */
  130. /* INPUT: _ActionData *ca_struct - Action data structure */
  131. /* OUTPUT: none */
  132. /******************************************************************************/
  133. void getCAdblClkCmd (struct _ActionData *ca_struct)
  134. {
  135. GetWidgetTextString(CA_DblClkText, &(AD.pszCmd));
  136. }
  137. /******************************************************************************/
  138. /* getCAactionHelpText - retrieves the help text string and stores */
  139. /* the value in the ActionData structure */
  140. /* INPUT: _ActionData *ca_struct - Action data structure */
  141. /* OUTPUT: none */
  142. /******************************************************************************/
  143. void getCAactionHelpText (struct _ActionData *ca_struct)
  144. {
  145. GetWidgetTextString(CA_HelpText, &(AD.pszHelp));
  146. }
  147. /******************************************************************************/
  148. /* getCAactionOpensText - retrieves the "action opens" text */
  149. /* string and stores the value in the ActionData structure */
  150. /* INPUT: _ActionData *ca_struct - Action data structure */
  151. /* OUTPUT: none */
  152. /******************************************************************************/
  153. void getCAactionOpensText (struct _ActionData *ca_struct)
  154. {
  155. GetWidgetTextString(CA_XprtActionOpenText, &(AD.pszPrompt));
  156. }
  157. /******************************************************************************/
  158. /* putCAactionName - sets the action name text field in the GUI */
  159. /* from the value in the ActionData structure */
  160. /* INPUT: _ActionData *ca_struct - Action data structure */
  161. /* OUTPUT: none */
  162. /******************************************************************************/
  163. void putCAactionName (struct _ActionData *ca_struct)
  164. {
  165. PutWidgetTextString(CA_ActionNameTextField, CA_ActionName(ca_struct));
  166. return;
  167. }
  168. /******************************************************************************/
  169. /* putCAdblClkCmd - sets the double-click command text */
  170. /* string in the GUI from the value in the ActionData structure */
  171. /* INPUT: _ActionData *ca_struct - Action data structure */
  172. /* OUTPUT: none */
  173. /******************************************************************************/
  174. void putCAdblClkCmd (struct _ActionData *ca_struct)
  175. {
  176. PutWidgetTextString(CA_DblClkText, CA_DblClkAction(ca_struct));
  177. return;
  178. }
  179. /******************************************************************************/
  180. /* putCAactionHelpText - sets the help text string in the GUI from */
  181. /* the value in the ActionData structure */
  182. /* INPUT: _ActionData *ca_struct - Action data structure */
  183. /* OUTPUT: none */
  184. /******************************************************************************/
  185. void putCAactionHelpText (struct _ActionData *ca_struct)
  186. {
  187. PutWidgetTextString(CA_HelpText, CA_ActionHelpText(ca_struct));
  188. return;
  189. }
  190. /******************************************************************************/
  191. /* putCAfileTypes - sets the list of file types in the GUI from */
  192. /* the values in the ActionData structure */
  193. /* INPUT: _ActionData *ca_struct - Action data structure */
  194. /* OUTPUT: none */
  195. /******************************************************************************/
  196. void putCAfileTypes (struct _ActionData *pAD)
  197. {
  198. pFiletypeData pFtD;
  199. int i;
  200. if (pAD->cFiletypes) {
  201. for (i=0; i < pAD->cFiletypes; i++) {
  202. if (!XmListItemExists(CA_FiletypesList,
  203. XmStringCreateSimple((pAD->papFiletypes[i])->pszName))) {
  204. XmListAddItem(CA_FiletypesList,
  205. XmStringCreateSimple((pAD->papFiletypes[i])->pszName), i+1);
  206. }
  207. }
  208. }
  209. return;
  210. }
  211. /******************************************************************************/
  212. /* putCAactionOpensText - sets the "action opens" text string in */
  213. /* the GUE from the value in the ActionData structure */
  214. /* INPUT: _ActionData *ca_struct - Action data structure */
  215. /* OUTPUT: none */
  216. /******************************************************************************/
  217. void putCAactionOpensText (struct _ActionData *ca_struct)
  218. {
  219. PutWidgetTextString(CA_XprtActionOpenText, CA_ActionOpensText(ca_struct));
  220. return;
  221. }
  222. /******************************************************************************/
  223. /* putCAwindowType - sets the window type toggle status in the GUI */
  224. /* from the value in the ActionData structure */
  225. /* INPUT: _ActionData *ca_struct - Action data structure */
  226. /* OUTPUT: none */
  227. /******************************************************************************/
  228. void putCAwindowType (struct _ActionData *ca_struct)
  229. {
  230. if (ca_struct->fsFlags & CA_WT_XWINDOWS) {
  231. /*
  232. XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeNoOutput,NULL);
  233. */
  234. XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
  235. } else if (ca_struct->fsFlags & CA_WT_TERM) {
  236. XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeAutoClose,NULL);
  237. } else if (ca_struct->fsFlags & CA_WT_PERMTERM) {
  238. XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeManualClose,NULL);
  239. } else {
  240. /*XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeNoOutput,NULL);*/
  241. XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
  242. }
  243. return;
  244. }
  245. /******************************************************************************/
  246. /* putCAactionIcons - */
  247. /* GUI from the value in the ActionData structure */
  248. /* INPUT: _ActionData *ca_struct - Action data structure */
  249. /* OUTPUT: none */
  250. /******************************************************************************/
  251. void putCAactionIcons (ActionData *pAD)
  252. {
  253. char *pszIconFileName = (char *)NULL;
  254. char *ptr;
  255. char *msgPtr, *fmtPtr, *errPtr;
  256. /**************************************************************************/
  257. /* Since we only have the base name, we must find the icon within the */
  258. /* icon path, strip off the size and type extension, then set the icon */
  259. /* data and gadget with this new name - base name and path. */
  260. /**************************************************************************/
  261. FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtLARGE);
  262. if (pszIconFileName) {
  263. ptr = strstr(pszIconFileName, LARGE_EXT);
  264. if (ptr) *ptr = '\0';
  265. SetIconData(CA_LRG_IconGadget, pszIconFileName, Large_Icon);
  266. XtFree(pszIconFileName);
  267. } else {
  268. msgPtr = GETMESSAGE(5, 95,
  269. "Could not find the following icon file within the icon\n\
  270. search path:");
  271. fmtPtr = "%s\n %s";
  272. errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
  273. strlen(pAD->pszIcon) + 1) * sizeof(char));
  274. sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
  275. display_error_message(CreateActionAppShell, errPtr);
  276. XtFree(errPtr);
  277. }
  278. FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtMEDIUM);
  279. if (pszIconFileName) {
  280. ptr = strstr(pszIconFileName, MEDIUM_EXT);
  281. if (ptr) *ptr = '\0';
  282. SetIconData(CA_MED_IconGadget, pszIconFileName, Medium_Icon);
  283. XtFree(pszIconFileName);
  284. } else {
  285. msgPtr = GETMESSAGE(5, 95,
  286. "Could not find the following icon file within the icon\n\
  287. search path:");
  288. fmtPtr = "%s\n %s";
  289. errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
  290. strlen(pAD->pszIcon) + 1) * sizeof(char));
  291. sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
  292. display_error_message(CreateActionAppShell, errPtr);
  293. XtFree(errPtr);
  294. }
  295. FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtTINY);
  296. if (pszIconFileName) {
  297. ptr = strstr(pszIconFileName, TINY_EXT);
  298. if (ptr) *ptr = '\0';
  299. SetIconData(CA_TINY_IconGadget, pszIconFileName, Tiny_Icon);
  300. XtFree(pszIconFileName);
  301. } else {
  302. msgPtr = GETMESSAGE(5, 95,
  303. "Could not find the following icon file within the icon\n\
  304. search path:");
  305. fmtPtr = "%s\n %s";
  306. errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
  307. strlen(pAD->pszIcon) + 1) * sizeof(char));
  308. sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
  309. display_error_message(CreateActionAppShell, errPtr);
  310. XtFree(errPtr);
  311. }
  312. }
  313. /******************************************************************************/
  314. /* putCAdropFiletypes - */
  315. /* */
  316. /* INPUT: _ActionData *ca_struct - Action data structure */
  317. /* OUTPUT: none */
  318. /******************************************************************************/
  319. void putCAdropFiletypes (ActionData *pAD)
  320. {
  321. Boolean set = FALSE;
  322. if (pAD->fsFlags & CA_DF_ONLYFTFILES) {
  323. set = TRUE;
  324. }
  325. SET_TOGGLEBUTTON(CA_FiletypesInListToggle, set);
  326. SET_TOGGLEBUTTON(CA_AllFiletypesToggle, !set);
  327. return;
  328. }
  329. /******************************************************************************/
  330. /* set_ca_dialog_height - adjusts height of create action dialog to exclude */
  331. /* height used by expert option section. */
  332. /* INPUT: none */
  333. /* OUTPUT: none */
  334. /******************************************************************************/
  335. void set_ca_dialog_height (void)
  336. {
  337. Boolean showExpert = sessiondata.useSession && sessiondata.showExpert;
  338. /* get height of window */
  339. XtVaGetValues (CreateActionAppShell, XmNheight, &winheight, NULL);
  340. /* get height of expert option form */
  341. XtVaGetValues (XprtOptionForm, XmNheight, &xprtheight, NULL);
  342. /* calculate height of window without expert option form */
  343. newheight = winheight - xprtheight;
  344. if (!showExpert)
  345. {
  346. /* remove attachment to expert option form */
  347. XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_NONE, NULL);
  348. XtUnmanageChild (XprtOptionForm);
  349. if (!sessiondata.useSession)
  350. {
  351. /* give window new height */
  352. XtVaSetValues (CreateActionAppShell, XmNheight, newheight, NULL);
  353. }
  354. XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_FORM, NULL);
  355. }
  356. else
  357. {
  358. XtVaSetValues (CA_Expand, RES_CONVERT(XmNlabelString,
  359. GETMESSAGE(3, 52, "Basic")),
  360. NULL);
  361. }
  362. return;
  363. }
  364. /******************************************************************************/
  365. /* */
  366. /* CALLBACK FUNCTIONS */
  367. /* */
  368. /******************************************************************************/
  369. /******************************************************************************/
  370. /* */
  371. /* */
  372. /* Callbacks for Create Action 'File' menu */
  373. /* */
  374. /* */
  375. /******************************************************************************/
  376. /*****************************************************************************/
  377. /* */
  378. /* initAD */
  379. /* */
  380. /* */
  381. /*****************************************************************************/
  382. void
  383. initAD( ActionData *pAD )
  384. {
  385. memset(pAD, 0, sizeof(ActionData));
  386. pAD->fsFlags |= CA_WT_XWINDOWS;
  387. pAD->pszIcon = (char *)XtMalloc(strlen(ca_icon_default) + 1);
  388. strcpy(pAD->pszIcon, ca_icon_default);
  389. }
  390. /******************************************************************************/
  391. /* FreeAndClearAD - free all fields in AD, frees filetypes and array, */
  392. /* and zero's out all of the fields of the structure. */
  393. /* INPUT: none */
  394. /* OUTPUT: none */
  395. /******************************************************************************/
  396. void FreeAndClearAD (ActionData *pAD)
  397. {
  398. FiletypeData *pFtD;
  399. int i;
  400. if (pAD->pszName) XtFree(pAD->pszName);
  401. if (pAD->pszIcon) XtFree(pAD->pszIcon);
  402. if (pAD->pszCmd) XtFree(pAD->pszCmd);
  403. if (pAD->pszHelp) XtFree(pAD->pszHelp);
  404. if (pAD->pszPrompt) XtFree(pAD->pszPrompt);
  405. if (pAD->papFiletypes) {
  406. for (i=0; i < pAD->cFiletypes; i++) {
  407. free_Filetypedata(pAD->papFiletypes[i]);
  408. }
  409. XtFree((char *)pAD->papFiletypes);
  410. }
  411. memset(pAD, 0, sizeof(ActionData));
  412. return;
  413. }
  414. /******************************************************************************/
  415. /* clear_CreateActionAppShell_fields */
  416. /* */
  417. /* INPUT: none */
  418. /* OUTPUT: none */
  419. /******************************************************************************/
  420. void clear_CreateActionAppShell_fields(void)
  421. {
  422. clear_text_field (ACTION_NAME);
  423. clear_text_field (DBL_CLK_CMND);
  424. XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
  425. clear_text_field (ACTION_OPENS_TEXT);
  426. clear_text (ACTION_HELP_TXT);
  427. delete_all_list_items (FILETYPES_FOR_ACTION);
  428. createCB_IconGadget(CA_LRG_IconGadget, True, Large_Icon);
  429. createCB_IconGadget(CA_MED_IconGadget, True, Medium_Icon);
  430. createCB_IconGadget(CA_TINY_IconGadget, True, Tiny_Icon);
  431. SET_TOGGLEBUTTON(CA_AllFiletypesToggle, TRUE);
  432. SET_TOGGLEBUTTON(CA_FiletypesInListToggle, FALSE);
  433. return;
  434. }
  435. /******************************************************************************/
  436. /* activateCB_FileNew - clears the text and list widgets on the */
  437. /* create action main panel */
  438. /* INPUT: Widget wid - widget id */
  439. /* XtPointer cdata - client data */
  440. /* XtPointer cbs - callback structur */
  441. /* OUTPUT: none */
  442. /******************************************************************************/
  443. void activateCB_FileNew (Widget wid, XtPointer cdata,
  444. XtPointer cbstruct)
  445. {
  446. char pszFile[MAXBUFSIZE];
  447. /**************************************************************************/
  448. /* Clear the fields in the gui and set fields to default. */
  449. /**************************************************************************/
  450. clear_CreateActionAppShell_fields();
  451. /**************************************************************************/
  452. /* Clear the pszFileToEdit global variable. */
  453. /**************************************************************************/
  454. pszFileToEdit = (char *)NULL;
  455. /**************************************************************************/
  456. /* Clear the fields within the ActionData structure and free any */
  457. /* FiletypeData structures. */
  458. /**************************************************************************/
  459. FreeAndClearAD(&AD);
  460. /**************************************************************************/
  461. /* Initialize fields within the ActionData structure. */
  462. /**************************************************************************/
  463. initAD(&AD);
  464. /**************************************************************************/
  465. /* Get a new copy of AD. */
  466. /**************************************************************************/
  467. FreeAndClearAD(pMyCopyAD);
  468. XtFree((char *)pMyCopyAD);
  469. pMyCopyAD = copyAD(&AD);
  470. return;
  471. }
  472. /******************************************************************************/
  473. /* activateCB_FileOpen - Callback for the Open menu bar option that is */
  474. /* located within the File submenu. This callback */
  475. /* pops up the File Selection dialog box. */
  476. /* */
  477. /* INPUT: Widget wid - widget id */
  478. /* XtPointer cdata - client data */
  479. /* XtPointer cbs - callback structure */
  480. /* */
  481. /* OUTPUT: none */
  482. /******************************************************************************/
  483. void activateCB_FileOpen(Widget wid, XtPointer cdata,
  484. XtPointer cbstruct)
  485. {
  486. Widget filter;
  487. XtVaSetValues (OpenFile, RES_CONVERT(XmNdirMask, "~/.dt/types/*.dt"),
  488. RES_CONVERT(XmNdirSpec, "~/.dt/types/"),
  489. RES_CONVERT(XmNdirectory, "~/.dt/types/"),
  490. NULL);
  491. filter = XmFileSelectionBoxGetChild (OpenFile, XmDIALOG_FILTER_TEXT);
  492. /*XtVaSetValues (filter, XmNeditable, False, NULL);*/
  493. UxPopupInterface (OpenFile, no_grab);
  494. return;
  495. }
  496. /******************************************************************************/
  497. /* */
  498. /* FreeResources */
  499. /* */
  500. /* INPUT: none */
  501. /* OUTPUT: none */
  502. /******************************************************************************/
  503. void FreeResources ( void )
  504. {
  505. /**************************************************************************/
  506. /* Clear the fields within the ActionData structure and free any */
  507. /* FiletypeData structures. */
  508. /**************************************************************************/
  509. FreeAndClearAD(&AD);
  510. /**************************************************************************/
  511. /* Free my copy of AD. */
  512. /**************************************************************************/
  513. FreeAndClearAD(pMyCopyAD);
  514. XtFree((char *)pMyCopyAD);
  515. /********************************************************************/
  516. /* Free temporary icon files */
  517. /********************************************************************/
  518. RemoveTmpIconFiles();
  519. return;
  520. }
  521. /******************************************************************************/
  522. /* activateCB_FileQuit */
  523. /* INPUT: Widget wid - widget id */
  524. /* XtPointer cdata - client data */
  525. /* XtPointer cbs - callback structur */
  526. /* OUTPUT: none */
  527. /******************************************************************************/
  528. void activateCB_FileQuit (Widget wid, XtPointer cdata,
  529. XtPointer cbstruct)
  530. {
  531. char *msgPtr;
  532. char *savePtr;
  533. char *noSavePtr;
  534. char *cancelPtr;
  535. /**************************************************************************/
  536. /* Get latest changes from main window. */
  537. /**************************************************************************/
  538. readCAFromGUI(&AD);
  539. /**************************************************************************/
  540. /* Check if anything has changed. If so ask if they really want to quit. */
  541. /**************************************************************************/
  542. if (compareAD(&AD, pMyCopyAD)) {
  543. msgPtr = GETMESSAGE(5, 150, "Your current work has not been saved.");
  544. msgPtr = XtNewString(msgPtr);
  545. /* CDExc19439 - Save GETMESSAGE results to buffers since it can */
  546. /* return an internal buffer which can be overwritten on each call. */
  547. savePtr = XtNewString(GETMESSAGE(2, 25, "Save"));
  548. noSavePtr = XtNewString(GETMESSAGE(5, 152, "Don't Save"));
  549. cancelPtr = XtNewString(GETMESSAGE(5, 154, "Cancel Close"));
  550. display_question_message(CreateActionAppShell, msgPtr,
  551. savePtr, (XtCallbackProc)saveCB_QuestionDialog,
  552. noSavePtr, nosaveCB_QuestionDialog,
  553. cancelPtr, cancelCB_QuestionDialog);
  554. XtFree(cancelPtr);
  555. XtFree(noSavePtr);
  556. XtFree(savePtr);
  557. XtFree(msgPtr);
  558. return;
  559. }
  560. FreeResources();
  561. exit(0);
  562. }
  563. /******************************************************************************/
  564. /* */
  565. /* */
  566. /* Callbacks for Create Action 'Options' menu */
  567. /* */
  568. /* */
  569. /* void activateCB_ExpertOption (); */
  570. /* */
  571. /* */
  572. /******************************************************************************/
  573. /******************************************************************************/
  574. /* activateCB_ExpertOption - turn expert option on/off */
  575. /* INPUT: Widget wid - widget id */
  576. /* XtPointer client_data - client data */
  577. /* XtPointer *cbs - callback data */
  578. /* OUTPUT: none */
  579. /* Global Variables Accessed: (other than widgets) */
  580. /* wintypeheight */
  581. /******************************************************************************/
  582. void activateCB_ExpertOption (Widget wid, XtPointer client_data,
  583. XtPointer *cbs)
  584. {
  585. XtArgVal /* Dimension */ ca_width;
  586. if (!XtIsManaged(XprtOptionForm)) {
  587. /**********************************************************************/
  588. /* Expand the window to show optional data. */
  589. /**********************************************************************/
  590. XtVaGetValues (CA_WindowTypeArea, XmNwidth, &ca_width, NULL);
  591. XtVaSetValues (CA_Expand,
  592. XmNbottomAttachment, XmATTACH_NONE,
  593. NULL);
  594. XtVaSetValues (XprtOptionForm,
  595. XmNbottomAttachment, XmATTACH_FORM,
  596. XmNleftAttachment, XmATTACH_FORM,
  597. XmNrightAttachment, XmATTACH_FORM,
  598. XmNwidth, ca_width,
  599. NULL);
  600. XtManageChild (XprtOptionForm);
  601. XtVaSetValues (CA_Expand,
  602. XmNbottomAttachment, XmATTACH_WIDGET,
  603. XmNbottomWidget, XprtOptionForm,
  604. XmNbottomOffset, 10,
  605. /*XmNlabelString, GETMESSAGE(3, 52, "Basic"),*/
  606. RES_CONVERT( XmNlabelString, GETMESSAGE(3, 52, "Basic")),
  607. NULL);
  608. XtVaSetValues (CA_HelpTextWindow, XmNheight, wintypeheight, NULL);
  609. /*XtVaSetValues (CA_WindowTypeArea, XmNheight, wintypeheight, NULL);*/
  610. } else {
  611. /**********************************************************************/
  612. /* Shrink the window to hide optional data. */
  613. /**********************************************************************/
  614. XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_NONE, NULL);
  615. XtUnmanageChild (XprtOptionForm);
  616. XtVaSetValues (CA_Expand,
  617. XmNbottomAttachment, XmATTACH_FORM,
  618. XmNbottomOffset, 15,
  619. /*XmNlabelString, GETMESSAGE(3, 50, "Advanced"),*/
  620. RES_CONVERT( XmNlabelString, GETMESSAGE(3, 50, "Advanced")),
  621. NULL);
  622. XtVaSetValues (CA_HelpTextWindow, XmNheight, wintypeheight, NULL);
  623. XtVaSetValues (CA_WindowTypeArea, XmNheight, wintypeheight, NULL);
  624. }
  625. return;
  626. }
  627. /******************************************************************************/
  628. /* */
  629. /* valueChangedCB_ColorMonoOption - turn monochrome option on/off */
  630. /* */
  631. /* INPUT: Widget wid - widget id */
  632. /* XtPointer client_data - client data */
  633. /* XmToggleButtonCallbackStruct *tcb - callback data */
  634. /* OUTPUT: none */
  635. /* */
  636. /******************************************************************************/
  637. void valueChangedCB_ColorMonoOption (Widget wid, XtPointer client_data,
  638. XmToggleButtonCallbackStruct *tcb)
  639. {
  640. int toggle_set= tcb->set;
  641. IconData *pIconData;
  642. Widget widIcon;
  643. Widget widIcons[3];
  644. int i;
  645. /***************************************************************************/
  646. /* If set then change icons from pixmaps to bitmaps. */
  647. /***************************************************************************/
  648. if (toggle_set) {
  649. bShowPixmaps = FALSE;
  650. } else {
  651. bShowPixmaps = TRUE;
  652. }
  653. /***************************************************************************/
  654. /* Change icons for CA large, med, and tiny icons */
  655. /***************************************************************************/
  656. widIcons[0] = CA_LRG_IconGadget;
  657. widIcons[1] = CA_MED_IconGadget;
  658. widIcons[2] = CA_TINY_IconGadget;
  659. for (i = 0; i < 3; i++) {
  660. pIconData = GetIconDataFromWid(widIcons[i]);
  661. if (pIconData) {
  662. if (bShowPixmaps) {
  663. SET_ICONGADGET_ICON(widIcons[i], pIconData->pmFileName);
  664. } else {
  665. SET_ICONGADGET_ICON(widIcons[i], pIconData->bmFileName);
  666. }
  667. }
  668. }
  669. }
  670. /******************************************************************************/
  671. /* */
  672. /* createCB_ColorMonoOption */
  673. /* */
  674. /* INPUT: Widget wid - widget id */
  675. /* OUTPUT: none */
  676. /* */
  677. /******************************************************************************/
  678. void createCB_ColorMonoOption (Widget wid)
  679. {
  680. bShowPixmaps = TRUE;
  681. #ifdef DEBUG
  682. printf("bShowPixmaps = %d\n", (int)bShowPixmaps);
  683. #endif
  684. return;
  685. }
  686. /******************************************************************************/
  687. /* */
  688. /* */
  689. /* Callbacks for Create Action 'Help' menu */
  690. /* */
  691. /* */
  692. /******************************************************************************/
  693. /******************************************************************************/
  694. /* */
  695. /* */
  696. /* Callbacks for Create Action Panel Buttons */
  697. /* */
  698. /* */
  699. /* void activateCB_action_icon (); */
  700. /* */
  701. /* */
  702. /******************************************************************************/
  703. /******************************************************************************/
  704. /* */
  705. /* activateCB_action_icon - */
  706. /* */
  707. /* INPUT: Widget wid - id of icon gadget */
  708. /* XtPointer client_data - not used */
  709. /* XmPushButtonCallbackStruct *cbs - not used */
  710. /* OUTPUT: none */
  711. /* */
  712. /******************************************************************************/
  713. void activateCB_action_icon (Widget wid, XtPointer client_data,
  714. DtIconCallbackStruct *cbs)
  715. {
  716. Time lts, mct = 0;
  717. static Time prev_lts = 0;
  718. if (cbs->reason == XmCR_ACTIVATE) {
  719. #ifdef DEBUG
  720. printf("In activate_action_icon callback.\n");
  721. #endif
  722. if (last_action_pushed && (last_action_pushed != wid)) {
  723. XtVaSetValues(XtParent(last_action_pushed), XmNborderWidth, 0, NULL);
  724. }
  725. XtVaSetValues(XtParent(wid), XmNborderWidth, ICON_BORDER_WIDTH, NULL);
  726. last_action_pushed = wid;
  727. /********************************************************************/
  728. /* This is the support needed to provide double-click functionality */
  729. /* to the icon gadgets. When double-clicked, the icon editor will */
  730. /* be launched. */
  731. /********************************************************************/
  732. XtVaSetValues(wid, XmNpushButtonClickTime, 0, NULL);
  733. lts = XtLastTimestampProcessed(XtDisplay(wid));
  734. mct = XtGetMultiClickTime(XtDisplay(wid));
  735. if ((prev_lts + mct) > lts) {
  736. prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
  737. } else {
  738. prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
  739. return;
  740. }
  741. #ifdef DEBUG
  742. printf("DblClick icon callback.\n");
  743. #endif
  744. activateCB_edit_icon(wid, (XtPointer)CA_ACTION_ICONS,
  745. (XmPushButtonCallbackStruct *)cbs /* unused anyway */);
  746. }
  747. return;
  748. }
  749. /******************************************************************************/
  750. /* activateCB_add_filetype - bring up the Add Filetype dialog with correct */
  751. /* dialog title. */
  752. /* INPUT: Widget wid - not used */
  753. /* XtPointer client_data - not used */
  754. /* XmPushButtonCallbackStruct *cbs - not used */
  755. /* OUTPUT: none */
  756. /******************************************************************************/
  757. void activateCB_add_filetype (Widget wid, XtPointer client_data,
  758. XmPushButtonCallbackStruct *cbs)
  759. {
  760. FiletypeData *pFtD;
  761. char *ptr;
  762. char tmpbuf[50];
  763. char *pre, *suf, *title;
  764. size_t len;
  765. if (!CreateActionAppShellCheckFields()) {
  766. #ifdef DEBUG
  767. printf("Allocating FiletypeData structure\n"); /* debug */
  768. #endif
  769. /******************************************************************/
  770. /* Allocate FiletypeData structure */
  771. /******************************************************************/
  772. pFtD = (FiletypeData *)XtMalloc(sizeof(FiletypeData));
  773. memset(pFtD, 0, sizeof(FiletypeData));
  774. /******************************************************************/
  775. /* Clear dialog fields */
  776. /******************************************************************/
  777. clear_AddFiletype_dialog_fields();
  778. clear_FileCharacteristics_dialog_fields();
  779. /******************************************************************/
  780. /* Create name for filetype */
  781. /******************************************************************/
  782. memset(tmpbuf, 0, 50);
  783. sprintf(tmpbuf, "%d", (AD.cFiletypes + 1));
  784. ptr = (char *)XmTextFieldGetString(CA_ActionNameTextField);
  785. pFtD->pszName = (char *)XtMalloc(strlen(ptr) + strlen("_FILE_") + strlen(tmpbuf) + 1);
  786. sprintf(pFtD->pszName, "%s_FILE_%d", ptr, (AD.cFiletypes + 1));
  787. XtFree(ptr);
  788. XmTextFieldSetString(AF_FileTypeNameTextField, pFtD->pszName);
  789. pFtD->pszIcon = (char *)XtMalloc(strlen(af_icon_default) + 1);
  790. strcpy(pFtD->pszIcon, af_icon_default);
  791. /******************************************************************/
  792. /* Set Open command string */
  793. /******************************************************************/
  794. /*
  795. pFtD->pszOpenCmd = (char *)XmTextGetString(CA_DblClkText);
  796. */
  797. GetWidgetTextString(CA_DblClkText, &(pFtD->pszOpenCmd));
  798. XmTextSetString(AF_OpenCmdText, pFtD->pszOpenCmd);
  799. pre = GETMESSAGE(3, 10, "Create Action");
  800. suf = GETMESSAGE(7, 10, "Add Datatype");
  801. len = strlen(pre) + strlen(suf) + 4;
  802. title = XtMalloc(len);
  803. snprintf(title,len - 1,"%s - %s", pre, suf);
  804. XtVaSetValues (AddFiletype,
  805. RES_CONVERT (XmNdialogTitle, title ),
  806. XmNuserData, pFtD,
  807. NULL);
  808. XtFree(title);
  809. UxPopupInterface (AddFiletype, no_grab);
  810. }
  811. return;
  812. }
  813. /******************************************************************************/
  814. /* activateCB_edit_filetype - bring up the Add Filetype dialog with correct */
  815. /* dialog title. */
  816. /* INPUT: Widget wid - not used */
  817. /* XtPointer client_data - not used */
  818. /* XmPushButtonCallbackStruct *cbs - not used */
  819. /* OUTPUT: none */
  820. /******************************************************************************/
  821. void activateCB_edit_filetype (Widget wid, XtPointer client_data,
  822. XmPushButtonCallbackStruct *cbs)
  823. {
  824. FiletypeData *pFtD;
  825. int *poslist, poscnt;
  826. int selecteditem;
  827. char *msgPtr1, *msgPtr2, *fmtPtr, *errPtr;
  828. char *pre, *suf, *title;
  829. size_t len;
  830. pre = GETMESSAGE(3, 10, "Create Action");
  831. suf = GETMESSAGE(7, 11, "Edit Datatype");
  832. len = strlen(pre) + strlen(suf) + 4;
  833. title = XtMalloc(len);
  834. snprintf(title,len - 1, "%s - %s", pre, suf);
  835. /**************************************************************************/
  836. /* Determine the selected list item. */
  837. /**************************************************************************/
  838. if (XmListGetSelectedPos(CA_FiletypesList, &poslist, &poscnt)) {
  839. selecteditem = *poslist;
  840. selecteditem--;
  841. if (selecteditem >= 0) {
  842. pFtD = AD.papFiletypes[selecteditem];
  843. pFtD->fsInternal |= CA_FT_EDIT;
  844. GetWidgetTextString(CA_DblClkText, &(pFtD->pszOpenCmd));
  845. clear_AddFiletype_dialog_fields();
  846. init_AddFiletype_dialog_fields(pFtD);
  847. /********************************************************************/
  848. /* Pop up the AddFiletype dialog. */
  849. /********************************************************************/
  850. XtVaSetValues (AddFiletype,
  851. RES_CONVERT (XmNdialogTitle, title),
  852. XmNuserData, pFtD,
  853. NULL);
  854. UxPopupInterface (AddFiletype, no_grab);
  855. }
  856. } else {
  857. msgPtr1 = XtNewString(GETMESSAGE(5, 120,
  858. "You have not selected a Datatype from the\n\
  859. 'Datatypes That Use This Action' list."));
  860. msgPtr2 = XtNewString(GETMESSAGE(5, 130,
  861. "Please select the Datatype you would like to Edit."));
  862. fmtPtr = "%s\n%s";
  863. len = (strlen(msgPtr1) + strlen(msgPtr2) +
  864. strlen(fmtPtr) + 3);
  865. errPtr = XtMalloc(len);
  866. snprintf(errPtr,len - 1, fmtPtr, msgPtr1, msgPtr2);
  867. XtFree(msgPtr2);
  868. XtFree(msgPtr1);
  869. display_error_message(CreateActionAppShell, errPtr);
  870. XtFree(errPtr);
  871. }
  872. XtFree(title);
  873. return;
  874. }
  875. /******************************************************************************/
  876. /* */
  877. /* get_selected_action_icon - determines which action icon is currently */
  878. /* selected. */
  879. /* */
  880. /* INPUT: none */
  881. /* OUTPUT: Widget wid - id of selected icon gadget */
  882. /* */
  883. /******************************************************************************/
  884. Widget get_selected_action_icon (void)
  885. {
  886. #if 0
  887. Widget wid;
  888. if (_DtIconGetState(CA_LRG_IconGadget)) wid = CA_LRG_IconGadget;
  889. else if (_DtIconGetState(CA_MED_IconGadget)) wid = CA_MED_IconGadget;
  890. else if (_DtIconGetState(CA_TINY_IconGadget)) wid = CA_TINY_IconGadget;
  891. else wid = CA_LRG_IconGadget;
  892. #endif
  893. if (!last_action_pushed) {
  894. last_action_pushed = CA_LRG_IconGadget;
  895. }
  896. return (last_action_pushed);
  897. }
  898. /******************************************************************************/
  899. /* */
  900. /* CreateActionAppShellCheckFields */
  901. /* */
  902. /* INPUT: none */
  903. /* OUTPUT: FALSE - no errors found */
  904. /* TRUE - found errors */
  905. /* */
  906. /******************************************************************************/
  907. Boolean CreateActionAppShellCheckFields(void)
  908. {
  909. char *ptr = (char *)NULL;
  910. char *ptrPrompt = (char *)NULL;
  911. Boolean bError = FALSE;
  912. char *msgPtr, *errPtr;
  913. /**************************************************************************/
  914. /* Check if action name is present. */
  915. /**************************************************************************/
  916. if (!bError) {
  917. ptr = (char *)NULL;
  918. GetWidgetTextString(CA_ActionNameTextField, &ptr);
  919. #ifdef DEBUG
  920. printf("Action Name = '%s'\n", ptr);
  921. #endif
  922. if (!ptr) {
  923. msgPtr = GETMESSAGE(5, 10, "The Action Name is missing.\n\
  924. Please enter a name in the 'Action Name' field.");
  925. errPtr = XtNewString(msgPtr);
  926. display_error_message(CreateActionAppShell, errPtr);
  927. XtFree(errPtr);
  928. XmProcessTraversal(CA_ActionNameTextField, XmTRAVERSE_CURRENT);
  929. bError = TRUE;
  930. } else {
  931. XtFree(ptr);
  932. }
  933. }
  934. /**************************************************************************/
  935. /* Check if execute command is present. */
  936. /**************************************************************************/
  937. if (!bError) {
  938. ptr = (char *)NULL;
  939. GetWidgetTextString(CA_DblClkText, &ptr);
  940. #ifdef DEBUG
  941. printf("Exec String = '%s'\n", ptr);
  942. #endif
  943. if (!ptr) {
  944. msgPtr = GETMESSAGE(5, 15, "The execute command is missing.\n\
  945. Please enter a command in the\n\
  946. 'Command To Execute When Double-clicked' field.");
  947. errPtr = XtNewString(msgPtr);
  948. display_error_message(CreateActionAppShell, errPtr);
  949. XtFree(errPtr);
  950. XmProcessTraversal(CA_DblClkText, XmTRAVERSE_CURRENT);
  951. bError = TRUE;
  952. } else {
  953. /********************************************************************/
  954. /* Now check to see if there is a prompt string. If so, make sure */
  955. /* there is an argument variable within the exec string. */
  956. /********************************************************************/
  957. GetWidgetTextString(CA_XprtActionOpenText, &ptrPrompt);
  958. if (ptrPrompt) {
  959. if (!strchr(ptr, '$')) {
  960. msgPtr = GETMESSAGE(5, 30, "A variable name is missing in the\n\
  961. 'Command To Execute When Double-clicked' field.\n\
  962. Add a variable name for the label you have entered\n\
  963. in the 'When Action Opens, Ask Users for' field.\n\
  964. Valid variable names are $*, $1, $2, ..., $9.");
  965. errPtr = XtNewString(msgPtr);
  966. display_error_message(CreateActionAppShell, errPtr);
  967. XtFree(errPtr);
  968. XmProcessTraversal(CA_DblClkText, XmTRAVERSE_CURRENT);
  969. bError = TRUE;
  970. }
  971. XtFree(ptrPrompt);
  972. }
  973. XtFree(ptr);
  974. }
  975. }
  976. /**************************************************************************/
  977. /* Check if droppable filetypes buttons are set correctly. */
  978. /**************************************************************************/
  979. if (!bError) {
  980. if ((AD.fsFlags & CA_DF_ONLYFTFILES) && !(AD.papFiletypes)) {
  981. msgPtr = GETMESSAGE(5, 20,
  982. "The 'Datatypes That Use This Action' list is empty.\n\
  983. You have selected 'Only Above List' in the 'Dropable\n\
  984. Datatypes' field.\n\
  985. Change the Dropable Datatype choice to 'All Datatypes'\n\
  986. or add at least one datatype to the list.");
  987. errPtr = XtNewString(msgPtr);
  988. display_error_message(CreateActionAppShell, errPtr);
  989. XtFree(errPtr);
  990. XmProcessTraversal(CA_AllFiletypesToggle, XmTRAVERSE_CURRENT);
  991. bError = TRUE;
  992. }
  993. }
  994. return(bError);
  995. }
  996. /******************************************************************************/
  997. /* */
  998. /* copyString */
  999. /* */
  1000. /* INPUT: */
  1001. /* OUTPUT: */
  1002. /* */
  1003. /* */
  1004. /******************************************************************************/
  1005. char * copyString(char *string)
  1006. {
  1007. char *newstring;
  1008. if (string) {
  1009. newstring = (char *)XtMalloc(strlen(string) + 1);
  1010. strcpy(newstring, string);
  1011. } else {
  1012. newstring = (char *)NULL;
  1013. }
  1014. return(newstring);
  1015. }
  1016. /******************************************************************************/
  1017. /* */
  1018. /* copyFtD */
  1019. /* */
  1020. /* INPUT: */
  1021. /* OUTPUT: */
  1022. /* */
  1023. /* */
  1024. /******************************************************************************/
  1025. FiletypeData * copyFtD(FiletypeData *pFtD)
  1026. {
  1027. FiletypeData *pcopyFtD;
  1028. pcopyFtD = (FiletypeData *)XtMalloc(sizeof(FiletypeData));
  1029. memset(pcopyFtD, 0, sizeof(FiletypeData));
  1030. if (pFtD->pszName) {
  1031. pcopyFtD->pszName = copyString(pFtD->pszName);
  1032. }
  1033. if (pFtD->pszIcon) {
  1034. pcopyFtD->pszIcon = copyString(pFtD->pszIcon);
  1035. }
  1036. if (pFtD->pszHelp) {
  1037. pcopyFtD->pszHelp = copyString(pFtD->pszHelp);
  1038. }
  1039. if (pFtD->pszOpenCmd) {
  1040. pcopyFtD->pszOpenCmd = copyString(pFtD->pszOpenCmd);
  1041. }
  1042. if (pFtD->pszPrintCmd) {
  1043. pcopyFtD->pszPrintCmd = copyString(pFtD->pszPrintCmd);
  1044. }
  1045. if (pFtD->pszPattern) {
  1046. pcopyFtD->pszPattern = copyString(pFtD->pszPattern);
  1047. }
  1048. if (pFtD->pszPermissions) {
  1049. pcopyFtD->pszPermissions = copyString(pFtD->pszPermissions);
  1050. }
  1051. if (pFtD->pszContents) {
  1052. pcopyFtD->pszContents = copyString(pFtD->pszContents);
  1053. }
  1054. pcopyFtD->sStart = pFtD->sStart;
  1055. pcopyFtD->sEnd = pFtD->sEnd;
  1056. pcopyFtD->fsFlags = pFtD->fsFlags;
  1057. pcopyFtD->fsInternal = pFtD->fsInternal;
  1058. return(pcopyFtD);
  1059. }
  1060. /******************************************************************************/
  1061. /* */
  1062. /* copyAD */
  1063. /* */
  1064. /* INPUT: */
  1065. /* OUTPUT: */
  1066. /* */
  1067. /* */
  1068. /******************************************************************************/
  1069. ActionData * copyAD(ActionData *pAD)
  1070. {
  1071. ActionData *pcopyAD;
  1072. int i;
  1073. pcopyAD = (ActionData *)XtMalloc(sizeof(ActionData));
  1074. if (!pcopyAD) {
  1075. return((ActionData *)NULL);
  1076. }
  1077. memset(pcopyAD, 0, sizeof(ActionData));
  1078. if (pAD->pszName) {
  1079. pcopyAD->pszName = copyString(pAD->pszName);
  1080. }
  1081. if (pAD->pszIcon) {
  1082. pcopyAD->pszIcon = copyString(pAD->pszIcon);
  1083. }
  1084. if (pAD->pszCmd) {
  1085. pcopyAD->pszCmd = copyString(pAD->pszCmd);
  1086. }
  1087. if (pAD->pszHelp) {
  1088. pcopyAD->pszHelp = copyString(pAD->pszHelp);
  1089. }
  1090. if (pAD->pszPrompt) {
  1091. pcopyAD->pszPrompt = copyString(pAD->pszPrompt);
  1092. }
  1093. if (pAD->papFiletypes) {
  1094. pcopyAD->papFiletypes = (FiletypeData **) XtMalloc(sizeof(FiletypeData *) * (pAD->cFiletypes + 1));
  1095. for (i=0; i < pAD->cFiletypes; i++) {
  1096. pcopyAD->papFiletypes[i] = copyFtD(pAD->papFiletypes[i]);
  1097. }
  1098. }
  1099. pcopyAD->cFiletypes = pAD->cFiletypes;
  1100. pcopyAD->fsFlags = pAD->fsFlags;
  1101. return(pcopyAD);
  1102. }
  1103. /******************************************************************************/
  1104. /* */
  1105. /* compareStrings */
  1106. /* */
  1107. /* INPUT: two pointers to char *'s */
  1108. /* OUTPUT: 0 they are the same */
  1109. /* 1 they are different */
  1110. /* */
  1111. /******************************************************************************/
  1112. Boolean compareStrings(char *pszStr1, char *pszStr2)
  1113. {
  1114. if (pszStr1 || pszStr2) {
  1115. if (pszStr1) {
  1116. if (pszStr2) {
  1117. if (!strcmp(pszStr1, pszStr2)) {
  1118. return(EQUAL);
  1119. } else {
  1120. return(NOT_EQUAL);
  1121. }
  1122. } else {
  1123. return(NOT_EQUAL);
  1124. }
  1125. } else {
  1126. return(NOT_EQUAL);
  1127. }
  1128. } else {
  1129. return(EQUAL);
  1130. }
  1131. }
  1132. /******************************************************************************/
  1133. /* */
  1134. /* compareFtD */
  1135. /* */
  1136. /* INPUT: two pointers to FtD structures */
  1137. /* OUTPUT: 0 they are the same */
  1138. /* 1 they are different */
  1139. /* */
  1140. /******************************************************************************/
  1141. Boolean compareFtD(FiletypeData *pFtD1, FiletypeData *pFtD2)
  1142. {
  1143. if (compareStrings(pFtD1->pszName, pFtD2->pszName)) {
  1144. return(NOT_EQUAL);
  1145. }
  1146. if (compareStrings(pFtD1->pszIcon, pFtD2->pszIcon)) {
  1147. return(NOT_EQUAL);
  1148. }
  1149. if (compareStrings(pFtD1->pszHelp, pFtD2->pszHelp)) {
  1150. return(NOT_EQUAL);
  1151. }
  1152. if (compareStrings(pFtD1->pszOpenCmd, pFtD2->pszOpenCmd)) {
  1153. return(NOT_EQUAL);
  1154. }
  1155. if (compareStrings(pFtD1->pszPrintCmd, pFtD2->pszPrintCmd)) {
  1156. return(NOT_EQUAL);
  1157. }
  1158. if (compareStrings(pFtD1->pszPattern, pFtD2->pszPattern)) {
  1159. return(NOT_EQUAL);
  1160. }
  1161. if (compareStrings(pFtD1->pszPermissions, pFtD2->pszPermissions)) {
  1162. return(NOT_EQUAL);
  1163. }
  1164. if (compareStrings(pFtD1->pszContents, pFtD2->pszContents)) {
  1165. return(NOT_EQUAL);
  1166. }
  1167. if (pFtD1->fsFlags != pFtD2->fsFlags) {
  1168. return(NOT_EQUAL);
  1169. }
  1170. if (pFtD1->sStart != pFtD2->sStart) {
  1171. return(NOT_EQUAL);
  1172. }
  1173. if (pFtD1->sEnd != pFtD2->sEnd) {
  1174. return(NOT_EQUAL);
  1175. }
  1176. return(EQUAL);
  1177. }
  1178. /******************************************************************************/
  1179. /* */
  1180. /* compareAD */
  1181. /* */
  1182. /* INPUT: two pointers to AD structures */
  1183. /* OUTPUT: 0 they are the same */
  1184. /* 1 they are different */
  1185. /* */
  1186. /******************************************************************************/
  1187. Boolean compareAD(ActionData *pAD1, ActionData *pAD2)
  1188. {
  1189. int i;
  1190. if (compareStrings(pAD1->pszName, pAD2->pszName)) {
  1191. return(NOT_EQUAL);
  1192. }
  1193. if (compareStrings(pAD1->pszIcon, pAD2->pszIcon)) {
  1194. return(NOT_EQUAL);
  1195. }
  1196. if (compareStrings(pAD1->pszCmd, pAD2->pszCmd)) {
  1197. return(NOT_EQUAL);
  1198. }
  1199. if (compareStrings(pAD1->pszHelp, pAD2->pszHelp)) {
  1200. return(NOT_EQUAL);
  1201. }
  1202. if (compareStrings(pAD1->pszPrompt, pAD2->pszPrompt)) {
  1203. return(NOT_EQUAL);
  1204. }
  1205. if (pAD1->fsFlags != pAD2->fsFlags) {
  1206. return(NOT_EQUAL);
  1207. }
  1208. if (pAD1->cFiletypes != pAD2->cFiletypes) {
  1209. return(NOT_EQUAL);
  1210. }
  1211. if (pAD1->papFiletypes) {
  1212. for (i=0; i < pAD1->cFiletypes; i++) {
  1213. if (compareFtD(pAD1->papFiletypes[i], pAD2->papFiletypes[i])) {
  1214. return(NOT_EQUAL);
  1215. }
  1216. }
  1217. }
  1218. return(EQUAL);
  1219. }