home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume18 / bibview / part10 < prev    next >
Text File  |  1992-08-27  |  51KB  |  1,562 lines

  1. Path: uunet!decwrl!elroy.jpl.nasa.gov!swrinde!mips!msi!dcmartin
  2. From: liebla@informatik.tu-muenchen.de (Armin Liebl)
  3. Newsgroups: comp.sources.x
  4. Subject: v18i108: bibview - BibTeX GUI, Part10/20
  5. Message-ID: <1992Aug27.161554.25644@msi.com>
  6. Date: 27 Aug 92 16:15:54 GMT
  7. References: <csx-18i099-bibview@uunet.UU.NET>
  8. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  9. Organization: Molecular Simulations, Inc.
  10. Lines: 1548
  11. Approved: dcmartin@msi.com
  12. Originator: dcmartin@fascet
  13.  
  14. Submitted-by: Armin Liebl <liebla@informatik.tu-muenchen.de>
  15. Posting-number: Volume 18, Issue 108
  16. Archive-name: bibview/part10
  17.  
  18. #!/bin/sh
  19. # this is part.10 (part 10 of a multipart archive)
  20. # do not concatenate these parts, unpack them in order with /bin/sh
  21. # file ctl_open.c continued
  22. #
  23. if test ! -r _shar_seq_.tmp; then
  24.     echo 'Please unpack part 1 first!'
  25.     exit 1
  26. fi
  27. (read Scheck
  28.  if test "$Scheck" != 10; then
  29.     echo Please unpack part "$Scheck" next!
  30.     exit 1
  31.  else
  32.     exit 0
  33.  fi
  34. ) < _shar_seq_.tmp || exit 1
  35. if test ! -f _shar_wnt_.tmp; then
  36.     echo 'x - still skipping ctl_open.c'
  37. else
  38. echo 'x - continuing file ctl_open.c'
  39. sed 's/^X//' << 'SHAR_EOF' >> 'ctl_open.c' &&
  40. X        XtNx, x, XtNy, y, NULL);
  41. X   conDialog = XtVaCreateManagedWidget("confirmLoadBox",
  42. X             dialogWidgetClass, conShell, 
  43. X         XtNicon, questPixmap, NULL);
  44. X   conOKButton = XtVaCreateManagedWidget("ok",
  45. X               commandWidgetClass, conDialog, NULL);
  46. X   conQuitButton = XtVaCreateManagedWidget("cancel",
  47. X               commandWidgetClass, conDialog, NULL);
  48. X   XtAddCallback(conQuitButton, XtNcallback, cancelLoadCmd, conShell);
  49. X   XtAddCallback(conOKButton, XtNcallback, loadCmdOk, conShell);
  50. X
  51. X   XtSetSensitive(mainMenu, FALSE);
  52. X   gubSetSensitive(NULL, FALSE);
  53. X   gbp = bp;
  54. X   XtPopup(conShell, XtGrabNonexclusive);
  55. }
  56. X
  57. X
  58. /*********************************************************************/
  59. /* cancelLoadCmd:                                                    */
  60. /*    Callback function for CANCEL button in confirm box             */
  61. /*********************************************************************/
  62. static void
  63. cancelLoadCmd (Widget w, XtPointer clientData, XtPointer callData)
  64. {
  65. Widget shell = (Widget)clientData;
  66. X
  67. X   XtSetSensitive(mainMenu, TRUE);
  68. X   gubSetSensitive(NULL, TRUE);
  69. X   XtPopdown(shell);
  70. X   gbp = NULL;
  71. }
  72. X
  73. X
  74. /*********************************************************************/
  75. /* loadCmdOK:                                                        */
  76. /*    Callback function for OK button in confirm box                 */
  77. /*********************************************************************/
  78. static void
  79. loadCmdOk (Widget w, XtPointer clientData, XtPointer callData)
  80. {
  81. Widget shell = (Widget) clientData;
  82. BibPtr bp;
  83. int status;
  84. X
  85. X   /* make new global data struct for bib file */
  86. X   if ((status = glbNewBibListEl(&bp)) != OK) {
  87. X      guwError(status);
  88. X      return;
  89. X   }
  90. X   strcpy(bp->filepath, gbp->filepath);
  91. X   strcpy(bp->filename, gbp->filename);
  92. X
  93. X   /* delete file in memory */
  94. X   if ((status = dbtDeleteTree(gbp->treeIdx)) != DBT_OK) {
  95. X      guwError(status);
  96. X   }
  97. X   if ((status = gubCloseBibWin(gbp)) != OK) {
  98. X      guwError(status);
  99. X   }
  100. X   gbp = NULL;
  101. X
  102. X   /* remove confirm box */
  103. X   XtPopdown(shell);
  104. X   XtSetSensitive(mainMenu, TRUE);
  105. X   gubSetSensitive(NULL, TRUE);
  106. X
  107. X   /* read file and reopen window */
  108. X   if ((status = bifFileRead(bp)) != BIF_OK) {
  109. X      gueOpenBibErrWin(bp, (int)status);   
  110. /*     glbDelBibListEl(bp); */
  111. X      return;
  112. X   }
  113. X   if ((status = gubOpenBibWin(bp)) != OK) {
  114. /*      glbDelBibListEl(bp);  */
  115. X      guwError(status);
  116. X      return;
  117. X   }
  118. X
  119. X   /* check cards, if option is on */
  120. X   if (cotAutoCheckBib()) 
  121. X      cseCheckBib(bp, False);      
  122. }
  123. X
  124. X
  125. SHAR_EOF
  126. echo 'File ctl_open.c is complete' &&
  127. chmod 0644 ctl_open.c ||
  128. echo 'restore of ctl_open.c failed'
  129. Wc_c="`wc -c < 'ctl_open.c'`"
  130. test 11442 -eq "$Wc_c" ||
  131.     echo 'ctl_open.c: original size 11442, current size' "$Wc_c"
  132. rm -f _shar_wnt_.tmp
  133. fi
  134. # ============= ctl_opt.c ==============
  135. if test -f 'ctl_opt.c' -a X"$1" != X"-c"; then
  136.     echo 'x - skipping ctl_opt.c (File already exists)'
  137.     rm -f _shar_wnt_.tmp
  138. else
  139. > _shar_wnt_.tmp
  140. echo 'x - extracting ctl_opt.c (Text)'
  141. sed 's/^X//' << 'SHAR_EOF' > 'ctl_opt.c' &&
  142. /*********************************************************************/
  143. /*  bibView: Administration of bibTex-Databases                      */
  144. /*           (Verwaltung von bibTeX-Literaturdatenbanken)            */
  145. /*                                                                   */
  146. /*  Module:  ctl_opt.c                                               */
  147. /*                                                                   */
  148. /*             Options Control                                       */
  149. /*             -                                                     */
  150. /*                                                                   */
  151. /*  Author:  Holger Martin,  martinh@informatik.tu-muenchen.de       */
  152. /*           Peter M. Urban, urban@informatik.tu-muenchen.de         */
  153. /*                                                                   */
  154. /*  History:                                                         */
  155. /*    12.08.91  PMU  created                                         */
  156. /*    05.26.92       Version 1.0 released                            */
  157. /*                                                                   */
  158. /*  Copyright 1992 TU MUENCHEN                                       */
  159. /*    See ./Copyright for complete rights and liability information. */
  160. /*                                                                   */
  161. /*********************************************************************/
  162. X
  163. #define COT_OPT
  164. X
  165. #include <stdio.h>
  166. #include <X11/Intrinsic.h>
  167. #include <X11/StringDefs.h>
  168. #include <X11/Xaw/Paned.h>
  169. #include <X11/Xaw/Form.h>
  170. #include <X11/Xaw/Box.h>
  171. #include <X11/Xaw/Command.h>
  172. #include <X11/Xaw/MenuButton.h>
  173. #include <X11/Xaw/SimpleMenu.h>
  174. #include <X11/Xaw/SmeBSB.h>
  175. #include <X11/Xaw/SmeLine.h>
  176. #include "bibview.h"
  177. X
  178. X
  179. /* imported global variables */
  180. /* ------------------------- */
  181. extern Widget topLevel;
  182. extern Pixmap chkmarkPixmap;
  183. X
  184. X
  185. /* macros and definitions */
  186. /* ---------------------- */
  187. X
  188. X
  189. /* local function prototypes */
  190. /* ------------------------- */
  191. X
  192. X
  193. /* exported variables */
  194. /* ------------------ */
  195. Boolean optionsStatus[OPT_MAX_OPTION] = {
  196. X   TRUE, TRUE, FALSE, TRUE 
  197. };
  198. X
  199. X
  200. /* local global variables */
  201. /* ---------------------- */
  202. X
  203. X
  204. /*********************************************************************/
  205. /* cotOptionIconOnDeskCmd:                                           */
  206. /*    Callback function for menu entry "icon on desktop"             */
  207. /*********************************************************************/
  208. void 
  209. cotOptionIconOnDeskCmd (Widget w, XtPointer clientData, XtPointer callData)
  210. {
  211. BibPtr bp;
  212. X   if (optionsStatus[OPT_ICON_ON_DESKTOP]) { 
  213. X      /* reset: icons under wm control */
  214. X      XtVaSetValues(w, XtNleftBitmap, None, NULL);
  215. X      gubUnsetIconCoords(FALSE);
  216. X      bp = glbFirstBibListEl();
  217. X      while (bp != NULL) {
  218. X     gulUnsetIconCoords(bp, FALSE);
  219. X     gueUnsetIconCoords(bp, FALSE);
  220. X     bp = glbNextBibListEl(bp);
  221. X      }  /* endwhile */
  222. X   }
  223. X   else { 
  224. X      /* set: icons under bibview control */
  225. X      XtVaSetValues(w, XtNleftBitmap, chkmarkPixmap, NULL);
  226. X      gubSetWindowCoords(TRUE);
  227. X      gubSetIconCoords(FALSE);
  228. X      bp = glbFirstBibListEl();
  229. X      while (bp != NULL) {
  230. X     gulSetIconCoords(bp, FALSE);
  231. X     gueSetIconCoords(bp, FALSE);
  232. X     bp = glbNextBibListEl(bp);
  233. X      }  /* endwhile */
  234. X   }
  235. X   optionsStatus[OPT_ICON_ON_DESKTOP] = !optionsStatus[OPT_ICON_ON_DESKTOP];
  236. }
  237. X
  238. X
  239. /*********************************************************************/
  240. /* cotOptionsControl:                                                */
  241. /*    Callback function for all option menu entries                  */
  242. /*********************************************************************/
  243. void 
  244. cotOptionsControl (Widget w, XtPointer client_data, XtPointer call_data)
  245. {
  246. int pane_num = (int) client_data;
  247. X
  248. X   if (optionsStatus[pane_num]) 
  249. X      XtVaSetValues(w, 
  250. X                XtNleftBitmap, None,
  251. X                NULL);
  252. X    else 
  253. X        XtVaSetValues(w, 
  254. X                XtNleftBitmap, chkmarkPixmap,
  255. X                NULL);
  256. X    optionsStatus[pane_num] = !optionsStatus[pane_num];
  257. }
  258. X
  259. X
  260. SHAR_EOF
  261. chmod 0644 ctl_opt.c ||
  262. echo 'restore of ctl_opt.c failed'
  263. Wc_c="`wc -c < 'ctl_opt.c'`"
  264. test 4078 -eq "$Wc_c" ||
  265.     echo 'ctl_opt.c: original size 4078, current size' "$Wc_c"
  266. rm -f _shar_wnt_.tmp
  267. fi
  268. # ============= ctl_prt.c ==============
  269. if test -f 'ctl_prt.c' -a X"$1" != X"-c"; then
  270.     echo 'x - skipping ctl_prt.c (File already exists)'
  271.     rm -f _shar_wnt_.tmp
  272. else
  273. > _shar_wnt_.tmp
  274. echo 'x - extracting ctl_prt.c (Text)'
  275. sed 's/^X//' << 'SHAR_EOF' > 'ctl_prt.c' &&
  276. /*********************************************************************/
  277. /*  bibView: Administration of bibTex-Databases                      */
  278. /*           (Verwaltung von bibTeX-Literaturdatenbanken)            */
  279. /*                                                                   */
  280. /*  Module:  ctl_prt.c                                               */
  281. /*                                                                   */
  282. /*             Print Control                                         */
  283. /*             - Print bibTeX File                                   */
  284. /*             - Print list                                          */
  285. /*                                                                   */
  286. /*  Author:  Holger Martin,  martinh@informatik.tu-muenchen.de       */
  287. /*           Peter M. Urban, urban@informatik.tu-muenchen.de         */
  288. /*                                                                   */
  289. /*  History:                                                         */
  290. /*    18.02.92  HM   created                                         */
  291. /*    05.26.92       Version 1.0 released                            */
  292. /*                                                                   */
  293. /*  Copyright 1992 TU MUENCHEN                                       */
  294. /*    See ./Copyright for complete rights and liability information. */
  295. /*                                                                   */
  296. /*********************************************************************/
  297. X
  298. #include <stdio.h>
  299. #include <X11/Intrinsic.h>
  300. #include <X11/StringDefs.h>
  301. #include <X11/Shell.h>
  302. #include <X11/Xaw/Cardinals.h>
  303. #include <X11/Xaw/Command.h>
  304. #include <X11/Xaw/Dialog.h>
  305. #include <X11/Xaw/Box.h>
  306. #include "FileNom.h"
  307. #include "bibview.h"
  308. X
  309. X
  310. /* macros and definitions */
  311. /* ---------------------- */
  312. #define MAXTEX  5000
  313. X
  314. /* imported global variables */
  315. /* ------------------------- */
  316. extern XtAppContext app_context;
  317. extern Widget topLevel, mainMenu, desktop;
  318. extern Pixmap questPixmap;
  319. extern char *latexHeader, *latexFooter;
  320. X
  321. /* exported global variables */
  322. /* ------------------------- */
  323. X
  324. X
  325. /* local function prototypes */
  326. /* ------------------------- */
  327. static void getFilename (CardListNode *lp);
  328. static void cancelGetFname (Widget w, XtPointer clientData, XtPointer callData);
  329. static void getFnameOk (Widget w, XtPointer clientData, XtPointer callData);
  330. static void getListFilename (BibPtr bp);
  331. static void cancelListGetFname (Widget w, XtPointer clientData, XtPointer callData);
  332. static void getListFnameOk (Widget w, XtPointer clientData, XtPointer callData);
  333. X
  334. X
  335. static Errcode printBegDoc (FILE *fp, String fname);
  336. static Errcode printEndDoc (FILE *fp);
  337. static Errcode printList   (FILE *fp, CardListNode *cl);
  338. static Errcode printCard   (FILE *fp, CardDataPtr cd);
  339. static void WriteLineToArray(char *inh);
  340. X
  341. X
  342. /* local global variables */
  343. /* ---------------------- */
  344. static char texline[MAXTEX];
  345. X
  346. X
  347. /*********************************************************************/
  348. /* cprPrintBibCmd:                                                   */
  349. /*    Callback function for command print in main menu               */
  350. /*********************************************************************/
  351. void 
  352. cprPrintBibCmd (Widget widget, XtPointer clientData, XtPointer callData)
  353. {
  354. Errcode status;
  355. X
  356. X   if ((status = guwSelectBib("printHead", cprPrintBib)) != OK)
  357. X      guwWarning(status);
  358. }
  359. X
  360. X
  361. /*********************************************************************/
  362. /* cprPrintCmd:                                                      */
  363. /*    Callback function for command print in main menu               */
  364. /*********************************************************************/
  365. void 
  366. cprPrintCmd (Widget widget, XtPointer clientData, XtPointer callData)
  367. {
  368. BibPtr bp = (BibPtr)clientData;
  369. Errcode status;
  370. X
  371. X   if ((status = cprPrintBib(bp)) != OK)
  372. X      guwError(status);
  373. }
  374. X
  375. X
  376. /*********************************************************************/
  377. /* cprPrintBib:                                                      */
  378. /*    Callback function for command print in main menu               */
  379. /*********************************************************************/
  380. Errcode
  381. cprPrintBib (BibPtr bp)
  382. {
  383. CardListNode *cl = NULL;
  384. char wcKey[] = ".";
  385. CardData *wcCard;
  386. Errcode status;
  387. X
  388. X   /* make list of all cards in src bib */
  389. X   if ((status = dbtMakeCard(&wcCard)) != DBT_OK) {
  390. X      return(status);
  391. X   }
  392. X   wcCard->mainkey = glbNewString(".");
  393. X   if ((status = dbtSearchList(bp->treeIdx, wcCard, &cl)) != DBT_OK) {
  394. X      return(status);
  395. X   }
  396. X
  397. X   getFilename(cl);
  398. X   return(OK);
  399. }
  400. X
  401. X
  402. /*********************************************************************/
  403. /* cprPrintListCmd:                                                  */
  404. /*    Callback function for command print in list window             */
  405. /*********************************************************************/
  406. void 
  407. cprPrintListCmd(Widget widget, XtPointer clientData, XtPointer callData)
  408. {
  409. CardListNode *cl = (CardListNode *)clientData;
  410. X
  411. X   getFilename(cl);
  412. }
  413. X
  414. X
  415. /*********************************************************************/
  416. /* cprPrintList:                                                     */
  417. /*    Print a list of cards to file in LaTeX format                  */
  418. /*********************************************************************/
  419. Errcode
  420. cprPrintList (CardListNode *lp, String fname)
  421. {
  422. FILE *fp;
  423. Errcode status;
  424. char sysStr[2*MAX_FILEPATHLEN];
  425. X
  426. X   /* make .bak file of original */
  427. X   if (cotBackupBeforeSave()) {
  428. X      sprintf(sysStr, "rm -f %s.bak 2> /dev/null", fname);
  429. X      system(sysStr);
  430. X      sprintf(sysStr, "mv -f %s %s.bak 2> /dev/null", fname, fname);
  431. X      system(sysStr);
  432. X   }
  433. X
  434. X   if ((fp = fopen(fname, "w")) == NULL) 
  435. X      return(ERR_NO_OPEN_FILE);
  436. X   if (latexHeader != NULL) {
  437. X      fprintf(fp,"%s\n", latexHeader);
  438. X   }
  439. X   else {
  440. X     if ((status = printBegDoc(fp, fname)) != OK) {
  441. X    fclose(fp);
  442. X    return(status);
  443. X     }
  444. X   }
  445. X   if ((status = printList(fp, lp)) != OK) {
  446. X      fclose(fp);
  447. X      return(status);
  448. X   }
  449. X
  450. X   if (latexFooter != NULL) {
  451. X      fprintf(fp,"%s\n", latexFooter);
  452. X   }
  453. X   else {
  454. X     if ((status = printEndDoc(fp)) != OK) {
  455. X    fclose(fp);
  456. X    return(status);
  457. X     }
  458. X   }
  459. X
  460. X   fclose(fp);
  461. X   return(OK);
  462. }
  463. X
  464. X
  465. /*********************************************************************/
  466. /* cprSaveListCmd:                                                   */
  467. /*    Callback function for command save in list window              */
  468. /*********************************************************************/
  469. void 
  470. cprSaveListCmd(Widget widget, XtPointer clientData, XtPointer callData)
  471. {
  472. BibPtr bp = (BibPtr)clientData;
  473. X
  474. X   getListFilename(bp);
  475. }
  476. X
  477. /*********************************************************************/
  478. /* LOCAL FUNCTIONS                                                   */
  479. /*********************************************************************/
  480. X
  481. /*********************************************************************/
  482. /* getFilename:                                                      */
  483. /*    Opens dialogbox for user to enter name of file                 */
  484. /*********************************************************************/
  485. static void
  486. getFilename (CardListNode *lp)
  487. {
  488. static Widget fsbShell, fsbBox, fsbLabel, fsbDialog;
  489. char fname[MAX_FILEPATHLEN];
  490. Position dx, dy, x, y;
  491. int status;
  492. X
  493. X   XtVaGetValues(desktop,
  494. X                 XtNx, &dx,
  495. X                 XtNy, &dy, NULL);
  496. X   XtTranslateCoords(desktop,
  497. X                     (Position)dx + SUBWIN_MARGIN,
  498. X                     (Position)dy + SUBWIN_MARGIN,
  499. X                     &x, &y);
  500. X
  501. X   fsbShell  = XtVaCreatePopupShell("fileSelectBoxShell",
  502. X                 topLevelShellWidgetClass, desktop,
  503. X                 XtNx, x, XtNy, y, NULL);
  504. X   fsbBox    = XtVaCreateManagedWidget("fileSelectBox",
  505. X         boxWidgetClass, fsbShell, NULL);
  506. X   fsbLabel  = XtVaCreateManagedWidget("filePrintHead",
  507. X         labelWidgetClass, fsbBox, 
  508. X         XtNborderWidth, 0, NULL);
  509. X   fsbDialog = XtVaCreateManagedWidget("fileSelectBox",
  510. X                 fileNominatorWidgetClass, fsbBox, 
  511. X         XtNborderWidth, 0, NULL);
  512. X
  513. X   XtAddCallback(fsbDialog, XtNcancelCallback, cancelGetFname, fsbShell);
  514. X   XtAddCallback(fsbDialog, XtNselectCallback, getFnameOk, lp);
  515. X
  516. X   XtSetSensitive(mainMenu, FALSE);
  517. X   gubSetSensitive(NULL, FALSE);
  518. X   XtPopup(fsbShell, XtGrabNonexclusive);
  519. }
  520. X
  521. X
  522. /*********************************************************************/
  523. /* getListFilename:                                                  */
  524. /*    Opens dialogbox for user to enter name of file                 */
  525. /*********************************************************************/
  526. static void
  527. getListFilename (BibPtr bp)
  528. {
  529. static Widget fsbShell, fsbBox, fsbLabel, fsbDialog;
  530. char fname[MAX_FILEPATHLEN];
  531. Position dx, dy, x, y;
  532. int status;
  533. X
  534. X   XtVaGetValues(desktop,
  535. X                 XtNx, &dx,
  536. X                 XtNy, &dy, NULL);
  537. X   XtTranslateCoords(desktop,
  538. X                     (Position)dx + SUBWIN_MARGIN,
  539. X                     (Position)dy + SUBWIN_MARGIN,
  540. X                     &x, &y);
  541. X
  542. X   fsbShell  = XtVaCreatePopupShell("fileSelectBoxShell",
  543. X                 topLevelShellWidgetClass, desktop,
  544. X                 XtNx, x, XtNy, y, NULL);
  545. X   fsbBox    = XtVaCreateManagedWidget("fileSelectBox",
  546. X         boxWidgetClass, fsbShell, NULL);
  547. X   fsbLabel  = XtVaCreateManagedWidget("fileListSaveHead",
  548. X         labelWidgetClass, fsbBox, 
  549. X         XtNborderWidth, 0, NULL);
  550. X   fsbDialog = XtVaCreateManagedWidget("fileSelectBox",
  551. X                 fileNominatorWidgetClass, fsbBox, 
  552. X         XtNborderWidth, 0, NULL);
  553. X
  554. X
  555. X   XtAddCallback(fsbDialog, XtNcancelCallback, cancelListGetFname, fsbShell);
  556. X   XtAddCallback(fsbDialog, XtNselectCallback, getListFnameOk, (XtPointer)bp);
  557. X
  558. X   XtSetSensitive(mainMenu, FALSE);
  559. X   gubSetSensitive(NULL, FALSE);
  560. X   XtPopup(fsbShell, XtGrabNonexclusive);
  561. }
  562. X
  563. X
  564. /*********************************************************************/
  565. /* cancelGetFname:                                                   */
  566. /*    Callback function for CANCEL button in filename box            */
  567. /*********************************************************************/
  568. static void
  569. cancelGetFname (Widget w, XtPointer clientData, XtPointer callData)
  570. {
  571. Widget shell = (Widget)clientData;
  572. X
  573. X   XtSetSensitive(mainMenu, TRUE);
  574. X   gubSetSensitive(NULL, TRUE);
  575. X   XtPopdown(shell);
  576. }
  577. X
  578. X
  579. /*********************************************************************/
  580. /* cancelListGetFname:                                               */
  581. /*    Callback function for CANCEL button in filename box            */
  582. /*********************************************************************/
  583. static void
  584. cancelListGetFname (Widget w, XtPointer clientData, XtPointer callData)
  585. {
  586. Widget shell = (Widget)clientData;
  587. X
  588. X   XtSetSensitive(mainMenu, TRUE);
  589. X   gubSetSensitive(NULL, TRUE);
  590. X   XtPopdown(shell);
  591. }
  592. X
  593. X
  594. /*********************************************************************/
  595. /* getFnameOk:                                                       */
  596. /*    Callback function for OK button in filename box                */
  597. /*********************************************************************/
  598. static void
  599. getFnameOk (Widget w, XtPointer clientData, XtPointer callData)
  600. {
  601. CardListNode *lp = (CardListNode *) clientData;
  602. char sysStr[2*MAX_FILEPATHLEN];
  603. String prtName;
  604. int status;
  605. X
  606. X   /* get filename and rename windows */
  607. X   prtName = (String)FileNominatorGetFileName(w);
  608. X
  609. X   /* remove file select box */
  610. X   XtPopdown(XtParent(XtParent(w)));
  611. X   XtSetSensitive(mainMenu, TRUE);
  612. X   gubSetSensitive(NULL, TRUE);
  613. X
  614. X   /* write out printfile to disk */
  615. X   if ((status = cprPrintList(lp, prtName)) != OK)
  616. X      guwError(status);
  617. X
  618. /* if ((status = dbtCardListDelete(&lp)) != OK)
  619. X      guwError(status);
  620. */
  621. }
  622. X
  623. X
  624. X
  625. /*********************************************************************/
  626. /* getListFnameOk:                                                   */
  627. /*    Callback function for OK button in filename box                */
  628. /*********************************************************************/
  629. static void
  630. getListFnameOk (Widget w, XtPointer clientData, XtPointer callData)
  631. {
  632. BibPtr bp = (BibPtr)clientData;
  633. char sysStr[2*MAX_FILEPATHLEN];
  634. String prtName;
  635. int status;
  636. X
  637. X   /* get filename and rename windows */
  638. X   prtName = (String)FileNominatorGetFileName(w);
  639. X
  640. X   /* remove file select box */
  641. X   XtPopdown(XtParent(XtParent(w)));
  642. X   XtSetSensitive(mainMenu, TRUE);
  643. X   gubSetSensitive(NULL, TRUE);
  644. X
  645. X   /* make .bak file of original */
  646. X   if (cotBackupBeforeSave()) {
  647. X      sprintf(sysStr, "rm -f %s.bak 2> /dev/null", prtName);
  648. X      system(sysStr);
  649. X      sprintf(sysStr, "mv -f %s %s.bak 2> /dev/null", prtName, prtName);
  650. X      system(sysStr);
  651. X   }
  652. X
  653. X   /* write out printfile to disk */
  654. X   if ((status = bifFileListWrite(bp, bp->lw->cardLst, prtName)) != OK)
  655. X      guwError(status);
  656. }
  657. X
  658. /*********************************************************************/
  659. /* printBegDoc:                                                      */
  660. /*    Print begin of LaTeX file                                      */
  661. /*********************************************************************/
  662. static Errcode
  663. printBegDoc (FILE *fp, String fname)
  664. {
  665. #ifdef GERMAN
  666. X   fprintf(fp, "\\documentstyle[german]{article}\n");
  667. X   fprintf(fp, "\\begin{document}\n");
  668. X   fprintf(fp, "{\\large \\bf Inhalt der Datei %s -- \\today}\n", fname);
  669. #else
  670. X   fprintf(fp, "\\documentstyle{article}\n");
  671. X   fprintf(fp, "\\begin{document}\n");
  672. X   fprintf(fp, "{\\large \\bf Content of file %s -- \\today}\n", fname);
  673. #endif
  674. X   fprintf(fp, "\\begin{enumerate}\n"); 
  675. X   return(OK);
  676. }
  677. X
  678. X
  679. /*********************************************************************/
  680. /* printEndDoc:                                                      */
  681. /*    Print end   of LaTeX file                                      */
  682. /*********************************************************************/
  683. static Errcode
  684. printEndDoc (FILE *fp)
  685. {
  686. X   fprintf(fp, "\\end{enumerate}\n"); 
  687. X   fprintf(fp, "\\end{document}\n");
  688. X   return(OK);
  689. }
  690. X
  691. X
  692. /*********************************************************************/
  693. /* printList:                                                        */
  694. /*    Print list of cards to file                                    */
  695. /*********************************************************************/
  696. static Errcode
  697. printList (FILE *fp, CardListNode *list)
  698. {
  699. Errcode status;
  700. X
  701. X   while (list != NULL) {                 
  702. X      if ((status = printCard(fp, list->data)) != OK)
  703. X     return(status);
  704. X      list = list->next; 
  705. X   }
  706. X   return(OK);
  707. }
  708. X
  709. X
  710. /*********************************************************************/
  711. /* printCard:                                                        */
  712. /*    Print list of cards to file                                    */
  713. /*********************************************************************/
  714. static Errcode
  715. printCard (FILE *fp, CardData *cd)
  716. {
  717. UserFld *hufield;
  718. X
  719. X   fprintf(fp, "\\item %s  %s\n", glbNewString(glbTypeToName(cd->cardtype)),
  720. X                                 cd->mainkey); 
  721. X   fprintf(fp, "\\begin{tabbing}\n");
  722. X   fprintf(fp, "AAAAAAAAAAAAAAAAAAAA\\= \\kill\n");
  723. X
  724. X   if (!glbIsStringEmpty(cd->category)) {
  725. X      WriteLineToArray(cd->category);
  726. X      fprintf(fp, "\\bf ADDRESS \\> \\parbox[t]{25em}{%s} \\\\ \n",
  727. X          texline);
  728. X   }
  729. X   if (!glbIsStringEmpty(cd->address)) {
  730. X      WriteLineToArray(cd->address);
  731. X      fprintf(fp, "\\bf ADDRESS \\> \\parbox[t]{25em}{%s} \\\\ \n",
  732. X          texline);
  733. X   }
  734. X   if (!glbIsStringEmpty(cd->annote)) {
  735. X      WriteLineToArray(cd->annote);
  736. X      fprintf(fp, "\\bf ANNOTE \\>  \\parbox[t]{25em}{%s} \\\\ \n",
  737. X          texline);
  738. X   }
  739. X   if (!glbIsStringEmpty(cd->author)) {
  740. X      WriteLineToArray(cd->author);
  741. X      fprintf(fp, "\\bf AUTHOR \\>  \\parbox[t]{25em}{%s} \\\\ \n",
  742. X          texline);
  743. X   }
  744. X   if (!glbIsStringEmpty(cd->booktitle)) {
  745. X      WriteLineToArray(cd->booktitle);
  746. X      fprintf(fp, "\\bf BOOKTITLE \\> \\parbox[t]{25em}{%s} \\\\ \n",
  747. X          texline);
  748. X   }
  749. X   if (!glbIsStringEmpty(cd->chapter)) {
  750. X      WriteLineToArray(cd->chapter);
  751. X      fprintf(fp, "\\bf CHAPTER \\> \\parbox[t]{25em}{%s} \\\\ \n",
  752. X          texline);
  753. X   }
  754. X   if (!glbIsStringEmpty(cd->edition)) {
  755. X      WriteLineToArray(cd->edition);
  756. X      fprintf(fp, "\\bf EDITION \\> \\parbox[t]{25em}{%s} \\\\ \n",
  757. X          texline);
  758. X   }
  759. X   if (!glbIsStringEmpty(cd->editor)) {
  760. X      WriteLineToArray(cd->editor);
  761. X      fprintf(fp, "\\bf EDITON \\> \\parbox[t]{25em}{%s} \\\\ \n",
  762. X          texline);
  763. X   }
  764. X   if (!glbIsStringEmpty(cd->howpublished)) {
  765. X      WriteLineToArray(cd->howpublished);
  766. X      fprintf(fp, "\\bf HOWPUBLISHED \\> \\parbox[t]{25em}{%s} \\\\ \n",
  767. X          texline);
  768. X   }
  769. X   if (!glbIsStringEmpty(cd->institution)) {
  770. X      WriteLineToArray(cd->institution);
  771. X      fprintf(fp, "\\bf INSTITUTION \\> \\parbox[t]{25em}{%s} \\\\ \n",
  772. X          texline);
  773. X   }
  774. X   if (!glbIsStringEmpty(cd->journal)) {
  775. X      WriteLineToArray(cd->journal);
  776. X      fprintf(fp, "\\bf JOURNAL \\> \\parbox[t]{25em}{%s} \\\\ \n",
  777. X          texline);
  778. X   }
  779. X   if (!glbIsStringEmpty(cd->key)) {
  780. X      WriteLineToArray(cd->key);
  781. X      fprintf(fp, "\\bf KEY \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  782. X          texline);
  783. X   }
  784. X   if (!glbIsStringEmpty(cd->month)) {
  785. X      WriteLineToArray(cd->month);
  786. X      fprintf(fp, "\\bf MONTH \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  787. X          texline);
  788. X   }
  789. X   if (!glbIsStringEmpty(cd->note)) {
  790. X      WriteLineToArray(cd->note);
  791. X      fprintf(fp, "\\bf NOTE \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  792. X          texline);
  793. X   }
  794. X   if (!glbIsStringEmpty(cd->number)) {
  795. X      WriteLineToArray(cd->number);
  796. X      fprintf(fp, "\\bf NUMBER \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  797. X          texline);
  798. X   }
  799. X   if (!glbIsStringEmpty(cd->organization)) {
  800. X      WriteLineToArray(cd->organization);
  801. X      fprintf(fp, "\\bf ORGANIZATION \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  802. X          texline);
  803. X   }
  804. X   if (!glbIsStringEmpty(cd->pages)) {
  805. X      WriteLineToArray(cd->pages);
  806. X      fprintf(fp, "\\bf PAGES \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  807. X          texline);
  808. X   }
  809. X   if (!glbIsStringEmpty(cd->publisher)) {
  810. X      WriteLineToArray(cd->publisher);
  811. X      fprintf(fp, "\\bf PUBLISHER \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  812. X          texline);
  813. X   }
  814. X   if (!glbIsStringEmpty(cd->school)) {
  815. X      WriteLineToArray(cd->school);
  816. X      fprintf(fp, "\\bf SCHOOL \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  817. X          texline);
  818. X   }
  819. X   if (!glbIsStringEmpty(cd->series)) {
  820. X      WriteLineToArray(cd->series);
  821. X      fprintf(fp, "\\bf SERIES \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  822. X          texline);
  823. X   }
  824. X   if (!glbIsStringEmpty(cd->title)) {
  825. X      WriteLineToArray(cd->title);
  826. X      fprintf(fp, "\\bf TITLE \\>   \\parbox[t]{25em}{%s}  \\\\ \n",
  827. X          texline);
  828. X   }
  829. X   if (!glbIsStringEmpty(cd->type)) {
  830. X      WriteLineToArray(cd->type);
  831. X      fprintf(fp, "\\bf TYPE \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  832. X          texline);
  833. X   }
  834. X   if (!glbIsStringEmpty(cd->volume)) {
  835. X      WriteLineToArray(cd->volume);
  836. X      fprintf(fp, "\\bf VOLUME \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  837. X          texline);
  838. X   }
  839. X   if (!glbIsStringEmpty(cd->year)) {
  840. X      WriteLineToArray(cd->year);
  841. X      fprintf(fp, "\\bf YEAR \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  842. X          texline);
  843. X   }
  844. X   if (!glbIsStringEmpty(cd->crossref)) {
  845. X      WriteLineToArray(cd->crossref);
  846. X      fprintf(fp, "\\bf YEAR \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  847. X          texline);
  848. X   }
  849. X
  850. X   /* print userdefined fields */
  851. X   hufield = cd->ufield;
  852. X   while (hufield != NULL) {
  853. X      WriteLineToArray(hufield->fldData);
  854. X      fprintf(fp, "\\bf %s \\>  \\parbox[t]{25em}{%s}  \\\\ \n",
  855. X           hufield->fldName, texline);
  856. X      hufield = hufield->next;
  857. X   } 
  858. X   fprintf(fp, "\\end{tabbing}\n");
  859. X   return(OK);
  860. }
  861. X
  862. X
  863. /*********************************************************************/
  864. /* writeLineToArray:                                                 */
  865. /*                                                                   */
  866. /*********************************************************************/
  867. static void 
  868. WriteLineToArray (char *inh)
  869. {
  870. int idx;
  871. int makro = 2;    /* weder Makro, noch String */
  872. char *tmp;
  873. X
  874. X  idx = 0;
  875. X  while (*inh == ' ' || *inh == '\t' || *inh == '\n') {
  876. X    texline[idx] = *inh; 
  877. X    inh++;
  878. X    idx++;
  879. X  }
  880. X  if (*inh == '@') {
  881. X    texline[idx] = ' '; 
  882. X    makro = 1;
  883. X  }
  884. X  else {
  885. X    texline[idx] = '{'; 
  886. X    idx++;
  887. X    texline[idx] = *inh; 
  888. X    makro = 0;
  889. X  }
  890. X  idx++;
  891. X  inh++;
  892. X  while (*inh != '\0') {
  893. X    if (*inh == '@') {
  894. X      tmp = inh;
  895. X      tmp++;
  896. X      if (*tmp == '#') {                  /* KONKATENATION */
  897. X        if (makro == 1) {
  898. X                                          /* letzter Teil war ein MAKRO */ 
  899. X          texline[idx] = ' '; idx++; 
  900. X          texline[idx] = '\\'; idx++; 
  901. X          texline[idx] = '#'; idx++; 
  902. X          texline[idx] = ' '; idx++; 
  903. X          tmp++;
  904. X          while (*tmp == ' ' || *tmp == '\t' || *tmp == '\n') {
  905. X            texline[idx] = *tmp; 
  906. X            idx++;
  907. X            tmp++;
  908. X          }
  909. X          if (*tmp == '@') {              /* naechster Teil ist ein MAKRO */
  910. X            texline[idx] = ' '; idx++; 
  911. X            makro = 1;
  912. X          }
  913. X          else {
  914. X            texline[idx] = '{'; idx++; 
  915. X            texline[idx] = *tmp; 
  916. X            idx++;
  917. X                                          /* naechster Teil ist ein STRING */
  918. X            makro = 0;
  919. X          }
  920. X        }
  921. X        else if (makro == 0) {
  922. X                                          /* letzter Teil war ein STRING */ 
  923. X          texline[idx] = '}'; idx++; 
  924. X          texline[idx] = ' '; idx++; 
  925. X          texline[idx] = '\\'; idx++; 
  926. X          texline[idx] = '#'; idx++; 
  927. X          texline[idx] = ' '; idx++; 
  928. X          tmp++;
  929. X          while (*tmp == ' ' || *tmp == '\t' || *tmp == '\n') {
  930. X            texline[idx] = *tmp; 
  931. X            idx++;
  932. X            tmp++;
  933. X          }
  934. X          if (*tmp == '@') {              /* naechster Teil ist ein MAKRO */
  935. X            texline[idx] = ' '; idx++; 
  936. X            makro = 1;
  937. X          }
  938. X          else {
  939. X            texline[idx] = '{'; idx++; 
  940. X            texline[idx] = *tmp; 
  941. X            idx++;
  942. X            makro = 0;
  943. X          }
  944. X        }  /* else if makro == 0 */
  945. X        inh = tmp;
  946. X      }
  947. X      else {                              /* AFFE nicht schreiben */
  948. X        texline[idx] = ' '; idx++; 
  949. X        makro = 1;
  950. X      }
  951. X    }      /* if @ */
  952. X    else {
  953. X      texline[idx] = *inh; 
  954. X      idx++;
  955. X    }
  956. X    inh++;
  957. X  }  /* while */
  958. X  if (makro == 0) {
  959. X    texline[idx] = '}'; idx++; 
  960. X  }
  961. X  texline[idx] = ','; idx++; 
  962. X  texline[idx] = ' '; idx++; 
  963. X  texline[idx] = '\0'; idx++; 
  964. }
  965. X
  966. X
  967. SHAR_EOF
  968. chmod 0644 ctl_prt.c ||
  969. echo 'restore of ctl_prt.c failed'
  970. Wc_c="`wc -c < 'ctl_prt.c'`"
  971. test 22375 -eq "$Wc_c" ||
  972.     echo 'ctl_prt.c: original size 22375, current size' "$Wc_c"
  973. rm -f _shar_wnt_.tmp
  974. fi
  975. # ============= ctl_save.c ==============
  976. if test -f 'ctl_save.c' -a X"$1" != X"-c"; then
  977.     echo 'x - skipping ctl_save.c (File already exists)'
  978.     rm -f _shar_wnt_.tmp
  979. else
  980. > _shar_wnt_.tmp
  981. echo 'x - extracting ctl_save.c (Text)'
  982. sed 's/^X//' << 'SHAR_EOF' > 'ctl_save.c' &&
  983. /*********************************************************************/
  984. /*  bibView: Administration of bibTex-Databases                      */
  985. /*           (Verwaltung von bibTeX-Literaturdatenbanken)            */
  986. /*                                                                   */
  987. /*  Module:  ctl_save.c                                              */
  988. /*                                                                   */
  989. /*             Close / Save Control                                  */
  990. /*             - Menu function Save                                  */
  991. /*             - Menu function Save as                               */
  992. /*                                                                   */
  993. /*  Author:  Holger Martin,  martinh@informatik.tu-muenchen.de       */
  994. /*           Peter M. Urban, urban@informatik.tu-muenchen.de         */
  995. /*                                                                   */
  996. /*  History:                                                         */
  997. /*    18.02.92  PMU  created                                         */
  998. /*    05.26.92       Version 1.0 released                            */
  999. /*                                                                   */
  1000. /*  Copyright 1992 TU MUENCHEN                                       */
  1001. /*    See ./Copyright for complete rights and liability information. */
  1002. /*                                                                   */
  1003. /*********************************************************************/
  1004. X
  1005. #include <stdio.h>
  1006. /* #include <stdlib.h> */
  1007. #include <X11/Intrinsic.h>
  1008. #include <X11/StringDefs.h>
  1009. #include <X11/Shell.h>
  1010. #include <X11/Xaw/Cardinals.h>
  1011. #include <X11/Xaw/Command.h>
  1012. #include <X11/Xaw/Dialog.h>
  1013. #include <X11/Xaw/Box.h>
  1014. #include "FileNom.h"
  1015. #include "bibview.h"
  1016. X
  1017. X
  1018. /* macros and definitions */
  1019. /* ---------------------- */
  1020. X
  1021. X
  1022. /* imported global variables */
  1023. /* ------------------------- */
  1024. extern XtAppContext app_context;
  1025. extern Widget topLevel, mainMenu, desktop;
  1026. extern Pixmap questPixmap;
  1027. X
  1028. X
  1029. /* exported global variables */
  1030. /* ------------------------- */
  1031. X
  1032. X
  1033. /* local function prototypes */
  1034. /* ------------------------- */
  1035. static void confirmClose (BibPtr bp);
  1036. static void closeCmdOk (Widget w, XtPointer clientData, XtPointer callData);
  1037. static void cancelCloseCmd (Widget w, XtPointer clientData, XtPointer callData);
  1038. static void getFilename (BibPtr bp);
  1039. static void getFnameOk (Widget w, XtPointer clientData, XtPointer callData);
  1040. static void cancelGetFname (Widget w, XtPointer clientData, XtPointer callData);
  1041. static Errcode renameWindowTitles (BibPtr bp, String newName);
  1042. X
  1043. X
  1044. /* local global variables */
  1045. /* ---------------------- */
  1046. static BibPtr gbp = NULL;
  1047. X
  1048. X
  1049. X
  1050. /*********************************************************************/
  1051. /* csaQuitBibviewCmd:                                                */
  1052. /*    Callback function for command quit in main file menu           */
  1053. /*********************************************************************/
  1054. void
  1055. csaQuitBibviewCmd (Widget w, XtPointer clientData, XtPointer callData)
  1056. {
  1057. BibPtr bpold, bp;
  1058. CardPtr cp;
  1059. Boolean unsaved = FALSE;
  1060. X
  1061. X   /* close bibs first (checks for unsaved changes) */
  1062. X   bp = glbFirstBibListEl();
  1063. X   while (bp != NULL) {
  1064. X      /* check for unsaved changes to cards and macros */
  1065. X      cp = glbFirstCardListEl(bp);
  1066. X      while (cp != NULL) {
  1067. X     if (cp->changed || gucStdFldsChanged(cp)) {
  1068. X        unsaved = TRUE;
  1069. X        break;
  1070. X     }
  1071. X     cp = glbNextCardListEl(bp, cp);
  1072. X      }
  1073. X      if (bp->mw && bp->mw->changed)
  1074. X     unsaved = TRUE;
  1075. X      if (bp->changed)
  1076. X     unsaved = TRUE;
  1077. X
  1078. X      if (unsaved) {
  1079. X         csaCloseBib(bp);
  1080. X     return;
  1081. X      } 
  1082. X      bpold = bp;
  1083. X      bp = glbNextBibListEl(bp);
  1084. X      glbDelBibListEl(bpold); 
  1085. X   }
  1086. X  
  1087. X   exit(0);
  1088. }
  1089. X
  1090. X
  1091. /*********************************************************************/
  1092. /* csaCloseBibCmd:                                                   */
  1093. /*    Callback function for command close bib  in main menu          */
  1094. /*********************************************************************/
  1095. void
  1096. csaCloseBibCmd (Widget w, XtPointer clientData, XtPointer callData)
  1097. {
  1098. Errcode status;
  1099. X
  1100. X   if ((status = guwSelectBib("closeHead", csaCloseBib)) != OK)
  1101. X      guwWarning(status);
  1102. }
  1103. X
  1104. X
  1105. /*********************************************************************/
  1106. /* csaCloseCmd:                                                      */
  1107. /*    Callback function for command close/quit in bib win menu       */
  1108. /*********************************************************************/
  1109. void
  1110. csaCloseCmd (Widget w, XtPointer clientData, XtPointer callData)
  1111. {
  1112. BibPtr bp = (BibPtr)clientData;
  1113. X
  1114. X   csaCloseBib(bp);
  1115. }
  1116. X
  1117. X
  1118. /*********************************************************************/
  1119. /* csaCloseBib:                                                      */
  1120. /*    Close bibliography file (ask if not saved)                     */
  1121. /*********************************************************************/
  1122. Errcode
  1123. csaCloseBib (BibPtr bp)
  1124. {
  1125. CardPtr cp;
  1126. char sysStr[2*MAX_FILEPATHLEN];
  1127. Boolean unsaved = FALSE;
  1128. Errcode status;
  1129. X   
  1130. X
  1131. X   /* check for unsaved changes to cards and macros */
  1132. X   cp = glbFirstCardListEl(bp);
  1133. X   while (cp != NULL) {
  1134. X      if (!cp->changed && !gucStdFldsChanged(cp)) {
  1135. X     gucCloseCardWin(cp);
  1136. X     cp = glbFirstCardListEl(bp);
  1137. X      }
  1138. X      else
  1139. X     unsaved = TRUE;
  1140. X      cp = glbNextCardListEl(bp, cp);
  1141. X   }
  1142. X   if (bp->mw && bp->mw->changed)
  1143. X      unsaved = TRUE;
  1144. X
  1145. X   /* if opened and unsaved cards found, reorder them */
  1146. X   if (unsaved)
  1147. X      gucCascade(bp);
  1148. X
  1149. X   /* confirm trashing unsaved cards or previous changes to bib */
  1150. X   if (unsaved || bp->changed) {
  1151. X      confirmClose(bp);
  1152. X      return(OK);
  1153. X   }
  1154. X
  1155. X   /* delete database tree */
  1156. X   if ((status = dbtDeleteTree(bp->treeIdx)) != DBT_OK) {
  1157. X      guwError(status);
  1158. X      return(status);
  1159. X   }
  1160. X   if ((status = gubCloseBibWin(bp)) != OK) {
  1161. X      guwError(status);
  1162. X      return(status);
  1163. X   }
  1164. X
  1165. X   return(OK);
  1166. }
  1167. X
  1168. X
  1169. /*********************************************************************/
  1170. /* csaSaveBibCmd:                                                    */
  1171. /*    Callback function for command save in file menu                */
  1172. /*********************************************************************/
  1173. void
  1174. csaSaveBibCmd (Widget w, XtPointer clientData, XtPointer callData)
  1175. {
  1176. Errcode status;
  1177. X
  1178. X   if ((status = guwSelectBib("saveHead", csaSaveBib)) != OK)
  1179. X      guwWarning(status);
  1180. }
  1181. X
  1182. X
  1183. /*********************************************************************/
  1184. /* csaSaveCmd:                                                       */
  1185. /*    Callback function for command save in bib window menu          */
  1186. /*********************************************************************/
  1187. void
  1188. csaSaveCmd (Widget w, XtPointer clientData, XtPointer callData)
  1189. {
  1190. BibPtr bp = (BibPtr)clientData;
  1191. X
  1192. X   csaSaveBib(bp);
  1193. }
  1194. X
  1195. X
  1196. /*********************************************************************/
  1197. /* csaSaveBib:                                                       */
  1198. /*    Save bibliography to disk                                      */
  1199. /*********************************************************************/
  1200. Errcode
  1201. csaSaveBib (BibPtr bp)
  1202. {
  1203. char sysStr[2*MAX_FILEPATHLEN];
  1204. int status;
  1205. X
  1206. X   /* check whether bib has a real name */
  1207. X   if (strncmp(bp->filename, "noname", 6) == 0) {
  1208. X      getFilename(bp);
  1209. X      return(OK);
  1210. X   }
  1211. X
  1212. X   /* make .bak file of original */
  1213. X   if (cotBackupBeforeSave()) {
  1214. X      sprintf(sysStr, "rm -f %s.bak 2> /dev/null", bp->filename);
  1215. X      system(sysStr);
  1216. X      sprintf(sysStr, "mv -f %s %s.bak 2> /dev/null", bp->filename, bp->filename);
  1217. X      system(sysStr);
  1218. X   }
  1219. X
  1220. X   /* write out file to disk */
  1221. X   if ((status = bifFileWrite(bp)) != DBT_OK) {
  1222. X      guwError(status);
  1223. X      return(status);
  1224. X   }
  1225. X   bp->changed = FALSE;
  1226. X   
  1227. X   return(OK);
  1228. }
  1229. X
  1230. X
  1231. /*********************************************************************/
  1232. /* csaSaveAsBibCmd:                                                  */
  1233. /*    Callback function for command save as in file menu             */
  1234. /*********************************************************************/
  1235. void
  1236. csaSaveAsBibCmd (Widget w, XtPointer clientData, XtPointer callData)
  1237. {
  1238. Errcode status;
  1239. X
  1240. X   if ((status = guwSelectBib("saveAsHead", csaSaveAsBib)) != OK)
  1241. X      guwWarning(status);
  1242. }
  1243. X
  1244. X
  1245. /*********************************************************************/
  1246. /* csaSaveAsBib:                                                     */
  1247. /*    Save bibliography under new name to disk                       */
  1248. /*********************************************************************/
  1249. Errcode
  1250. csaSaveAsBib (BibPtr bp)
  1251. {
  1252. X   getFilename(bp);
  1253. X   return(OK);
  1254. }
  1255. X
  1256. X
  1257. X
  1258. /*********************************************************************/
  1259. /* LOCAL FUNCTIONS                                                   */
  1260. /*********************************************************************/
  1261. X
  1262. /*********************************************************************/
  1263. /* confirmClose:                                                     */
  1264. /*    Opens dialogbox for user to confirm closing without saving     */
  1265. /*********************************************************************/
  1266. static void
  1267. confirmClose (BibPtr bp)
  1268. {
  1269. static Widget conShell, conDialog, conOKButton, conQuitButton;
  1270. Position dx, dy, x, y;
  1271. int status;
  1272. X
  1273. X   XtVaGetValues(bp->bw->bibdesk,
  1274. X                 XtNx, &dx,
  1275. X                 XtNy, &dy, NULL);
  1276. X   XtTranslateCoords(desktop,
  1277. X                     (Position)dx + SUBWIN_MARGIN,
  1278. X                     (Position)dy + SUBWIN_MARGIN,
  1279. X                     &x, &y);
  1280. X   conShell = XtVaCreatePopupShell("confirmBibQuitShell",
  1281. X            transientShellWidgetClass, topLevel, 
  1282. X        XtNx, x, XtNy, y, NULL);
  1283. X   conDialog = XtVaCreateManagedWidget("confirmBibQuitBox",
  1284. X             dialogWidgetClass, conShell, 
  1285. X         XtNicon, questPixmap, NULL);
  1286. X   conOKButton = XtVaCreateManagedWidget("ok",
  1287. X               commandWidgetClass, conDialog, NULL);
  1288. X   conQuitButton = XtVaCreateManagedWidget("cancel",
  1289. X               commandWidgetClass, conDialog, NULL);
  1290. X   XtAddCallback(conQuitButton, XtNcallback, cancelCloseCmd, conDialog);
  1291. X   XtAddCallback(conOKButton, XtNcallback, closeCmdOk, conDialog);
  1292. X
  1293. X   XtSetSensitive(mainMenu, FALSE);
  1294. X   gubSetSensitive(NULL, FALSE);
  1295. X   gbp = bp;
  1296. X   XtPopup(conShell, XtGrabNonexclusive);
  1297. }
  1298. X
  1299. X
  1300. /*********************************************************************/
  1301. /* cancelCloseCmd:                                                   */
  1302. /*    Callback function for CANCEL button in confirm box             */
  1303. /*********************************************************************/
  1304. static void
  1305. cancelCloseCmd (Widget w, XtPointer clientData, XtPointer callData)
  1306. {
  1307. Widget dialog = XtParent((Widget)clientData);
  1308. X
  1309. X   XtSetSensitive(mainMenu, TRUE);
  1310. X   gubSetSensitive(NULL, TRUE);
  1311. X   XtPopdown(dialog);
  1312. X   gbp = NULL;
  1313. }
  1314. X
  1315. X
  1316. /*********************************************************************/
  1317. /* closeCmdOk:                                                       */
  1318. /*    Callback function for OK button in confirm box                 */
  1319. /*********************************************************************/
  1320. static void
  1321. closeCmdOk (Widget w, XtPointer clientData, XtPointer callData)
  1322. {
  1323. Widget dialog = (Widget) clientData;
  1324. char sysStr[2*MAX_FILEPATHLEN];
  1325. int status;
  1326. X
  1327. X   /* remove file select box */
  1328. X   XtPopdown(XtParent(dialog));
  1329. X   XtSetSensitive(mainMenu, TRUE);
  1330. X   gubSetSensitive(NULL, TRUE);
  1331. X
  1332. X   if ((status = dbtDeleteTree(gbp->treeIdx)) != DBT_OK) {
  1333. X      guwError(status);
  1334. X   }
  1335. X   if ((status = gubCloseBibWin(gbp)) != OK) {
  1336. X      guwError(status);
  1337. X   }
  1338. X   sprintf(sysStr, "rm -f %s %s 2> /dev/null", gbp->tempfile, gbp->macrofile);
  1339. X   system(sysStr);
  1340. X
  1341. X   gbp = NULL;
  1342. }
  1343. X
  1344. X
  1345. /*********************************************************************/
  1346. /* getFilename:                                                      */
  1347. /*    Opens dialogbox for user to enter name of file                 */
  1348. /*********************************************************************/
  1349. static void
  1350. getFilename (BibPtr bp)
  1351. {
  1352. static Widget fsbShell, fsbBox, fsbLabel, fsbDialog;
  1353. char fname[MAX_FILEPATHLEN];
  1354. Position dx, dy, x, y;
  1355. int status;
  1356. X
  1357. X   XtVaGetValues(desktop,
  1358. X                 XtNx, &dx,
  1359. X                 XtNy, &dy, NULL);
  1360. X   XtTranslateCoords(desktop,
  1361. X                     (Position)dx + SUBWIN_MARGIN,
  1362. X                     (Position)dy + SUBWIN_MARGIN,
  1363. X                     &x, &y);
  1364. X
  1365. X   fsbShell  = XtVaCreatePopupShell("fileSelectBoxShell",
  1366. X                 topLevelShellWidgetClass, desktop,
  1367. X                 XtNx, x, XtNy, y, NULL);
  1368. X   fsbBox    = XtVaCreateManagedWidget("fileSelectBox",
  1369. X         boxWidgetClass, fsbShell, NULL);
  1370. X   fsbLabel  = XtVaCreateManagedWidget("fileRenameHead",
  1371. X         labelWidgetClass, fsbBox, 
  1372. X         XtNborderWidth, 0, NULL);
  1373. X   fsbDialog = XtVaCreateManagedWidget("fileSelectBox",
  1374. X                 fileNominatorWidgetClass, fsbBox, 
  1375. X         XtNborderWidth, 0, NULL);
  1376. X
  1377. X   XtAddCallback(fsbDialog, XtNcancelCallback, cancelGetFname, fsbShell);
  1378. X   XtAddCallback(fsbDialog, XtNselectCallback, getFnameOk, fsbDialog);
  1379. X
  1380. X   XtSetSensitive(mainMenu, FALSE);
  1381. X   gubSetSensitive(NULL, FALSE);
  1382. X   gbp = bp;
  1383. X   XtPopup(fsbShell, XtGrabNonexclusive);
  1384. }
  1385. X
  1386. X
  1387. /*********************************************************************/
  1388. /* cancelGetFname:                                                   */
  1389. /*    Callback function for CANCEL button in filename box            */
  1390. /*********************************************************************/
  1391. static void
  1392. cancelGetFname (Widget w, XtPointer clientData, XtPointer callData)
  1393. {
  1394. Widget shell = (Widget)clientData;
  1395. X
  1396. X   XtSetSensitive(mainMenu, TRUE);
  1397. X   gubSetSensitive(NULL, TRUE);
  1398. X   XtPopdown(shell);
  1399. X   gbp = NULL;
  1400. }
  1401. X
  1402. X
  1403. /*********************************************************************/
  1404. /* getFnameOk:                                                       */
  1405. /*    Callback function for OK button in filename box                */
  1406. /*********************************************************************/
  1407. static void
  1408. getFnameOk (Widget w, XtPointer clientData, XtPointer callData)
  1409. {
  1410. Widget dialog = (Widget) clientData;
  1411. char sysStr[2*MAX_FILEPATHLEN];
  1412. String newName;
  1413. int status;
  1414. X
  1415. X   /* get filename and rename windows */
  1416. X   newName = (String)FileNominatorGetFileName(dialog);
  1417. X   strcpy(gbp->filename, newName);
  1418. X   strcpy(gbp->filepath, (String)FileNominatorGetFullFileName(dialog));
  1419. X   if ((status = renameWindowTitles(gbp, newName)) != OK)
  1420. X      guwError(status);
  1421. X
  1422. X   /* remove file select box */
  1423. X   XtPopdown(XtParent(XtParent(dialog)));
  1424. X   XtSetSensitive(mainMenu, TRUE);
  1425. X   gubSetSensitive(NULL, TRUE);
  1426. X
  1427. X   /* make .bak file of original */
  1428. X   if (cotBackupBeforeSave()) {
  1429. X      sprintf(sysStr, "rm -f %s.bak 2> /dev/null", gbp->filename);
  1430. X      system(sysStr);
  1431. X      sprintf(sysStr, "mv -f %s %s.bak 2> /dev/null", gbp->filename, gbp->filename);
  1432. X      system(sysStr);
  1433. X   }
  1434. X
  1435. X   /* write out file to disk */
  1436. X   if ((status = bifFileWrite(gbp)) != DBT_OK) {
  1437. X      guwError(status);
  1438. X      return;
  1439. X   }
  1440. X   gbp->changed = FALSE;
  1441. X   gbp = NULL;
  1442. }
  1443. X
  1444. X
  1445. /*********************************************************************/
  1446. /* renameWindowTitles:                                               */
  1447. /*    Rename titles of all open windows of a bib                     */
  1448. /*********************************************************************/
  1449. static Errcode
  1450. renameWindowTitles (BibPtr bp, String newName)
  1451. {
  1452. CardPtr cp;
  1453. X
  1454. X   strcpy(bp->filename, newName);
  1455. X
  1456. X   /* rename bib window */
  1457. X   if (bp->bw->shellName)
  1458. X      free(bp->bw->shellName);
  1459. X   if ((bp->bw->shellName =
  1460. X          (String) calloc(strlen(PROGNAME)+strlen(bp->filename)+4,
  1461. X                          sizeof(char))) != NULL) {
  1462. X      sprintf(bp->bw->shellName, "%s: %s", PROGNAME, bp->filename);
  1463. X      XtVaSetValues(bp->bw->bibShell,
  1464. X            XtNtitle, bp->bw->shellName, 
  1465. X            XtNiconName, bp->filename, NULL);
  1466. X   }
  1467. X   else
  1468. X      bp->bw->shellName = NULL;
  1469. X
  1470. X   /* rename card windows */
  1471. X   cp = glbFirstCardListEl(bp);
  1472. X   while (cp != NULL) {
  1473. X      if (cp->cw->shellName)
  1474. X          free(cp->cw->shellName);
  1475. X      if ((cp->cw->shellName = (String)calloc(strlen(bp->filename) +
  1476. X                    strlen(glbTypeToName(cp->cd->cardtype))+4,
  1477. X                    sizeof(char))) != NULL) {
  1478. X         sprintf(cp->cw->shellName, "%s: %s", bp->filename, glbTypeToName(cp->cd->cardtype));
  1479. X         XtVaSetValues(cp->cw->cardShell,
  1480. X               XtNtitle, cp->cw->shellName, NULL);
  1481. X      } /* endif */
  1482. X      else
  1483. X     cp->cw->shellName = NULL;
  1484. X      cp = glbNextCardListEl(gbp, cp);
  1485. X   } /* endwhile */
  1486. X
  1487. X   /* rename list window */
  1488. X   if (gulListWinExists(bp)) {
  1489. X      if (bp->lw->shellName)
  1490. X        free(bp->lw->shellName);
  1491. X      if ((bp->lw->shellName = (String)calloc(strlen(PROGNAME) +
  1492. X                                              strlen(bp->filename)+10,
  1493. X                                              sizeof(char))) != NULL) {
  1494. X     sprintf(bp->lw->shellName, "%s: List %s", PROGNAME, bp->filename);
  1495. X         XtVaSetValues(bp->lw->lstShell,
  1496. X               XtNtitle, bp->lw->shellName, 
  1497. X               XtNiconName, bp->filename, NULL);
  1498. X      } /* endif */
  1499. X      else
  1500. X     bp->lw->shellName = NULL;
  1501. X   } /* endif */
  1502. X
  1503. X   /* rename macro window */
  1504. X   if (gueMacroWinExists(bp)) {
  1505. X      if (bp->mw->shellName)
  1506. X        free(bp->mw->shellName);
  1507. X
  1508. X      if ((bp->mw->shellName = (String)calloc(strlen(PROGNAME) +
  1509. X                                              strlen(bp->filename)+12,
  1510. X                                              sizeof(char))) != NULL) {
  1511. X     sprintf(bp->mw->shellName, "%s: Macros %s", PROGNAME, bp->filename);
  1512. X         XtVaSetValues(bp->mw->macShell,
  1513. X               XtNtitle, bp->mw->shellName, 
  1514. X               XtNiconName, bp->filename, NULL);
  1515. X      } /* endif */
  1516. X      else
  1517. X     bp->mw->shellName = NULL;
  1518. X   } /* endif */
  1519. X
  1520. X   return(OK);
  1521. }
  1522. X
  1523. X
  1524. X
  1525. SHAR_EOF
  1526. chmod 0644 ctl_save.c ||
  1527. echo 'restore of ctl_save.c failed'
  1528. Wc_c="`wc -c < 'ctl_save.c'`"
  1529. test 17577 -eq "$Wc_c" ||
  1530.     echo 'ctl_save.c: original size 17577, current size' "$Wc_c"
  1531. rm -f _shar_wnt_.tmp
  1532. fi
  1533. # ============= ctl_serv.c ==============
  1534. if test -f 'ctl_serv.c' -a X"$1" != X"-c"; then
  1535.     echo 'x - skipping ctl_serv.c (File already exists)'
  1536.     rm -f _shar_wnt_.tmp
  1537. else
  1538. > _shar_wnt_.tmp
  1539. echo 'x - extracting ctl_serv.c (Text)'
  1540. sed 's/^X//' << 'SHAR_EOF' > 'ctl_serv.c' &&
  1541. /*********************************************************************/
  1542. /*  bibView: Administration of bibTex-Databases                      */
  1543. /*           (Verwaltung von bibTeX-Literaturdatenbanken)            */
  1544. /*                                                                   */
  1545. /*  Module:  ctl_serv.c                                              */
  1546. /*                                                                   */
  1547. /*             Services Control                                      */
  1548. /*             - Menu function Check                                 */
  1549. SHAR_EOF
  1550. true || echo 'restore of ctl_serv.c failed'
  1551. fi
  1552. echo 'End of  part 10'
  1553. echo 'File ctl_serv.c is continued in part 11'
  1554. echo 11 > _shar_seq_.tmp
  1555. exit 0
  1556. -- 
  1557. Senior Systems Scientist        mail: dcmartin@msi.com
  1558. Molecular Simulations, Inc.        uucp: uunet!dcmartin
  1559. 796 North Pastoria Avenue        at&t: 408/522-9236
  1560. Sunnyvale, California 94086        fax: 408/732-0831
  1561.