home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume18 / bibview / part11 < prev    next >
Encoding:
Text File  |  1992-08-26  |  50.2 KB  |  1,533 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: v18i109: bibview - BibTeX GUI, Part11/20
  5. Message-ID: <1992Aug27.161609.25703@msi.com>
  6. Date: 27 Aug 92 16:16:09 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: 1519
  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 109
  16. Archive-name: bibview/part11
  17.  
  18. #!/bin/sh
  19. # this is part.11 (part 11 of a multipart archive)
  20. # do not concatenate these parts, unpack them in order with /bin/sh
  21. # file ctl_serv.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" != 11; 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_serv.c'
  37. else
  38. echo 'x - continuing file ctl_serv.c'
  39. sed 's/^X//' << 'SHAR_EOF' >> 'ctl_serv.c' &&
  40. /*             - Menu function Collate                               */
  41. /*                                                                   */
  42. /*  Author:  Holger Martin,  martinh@informatik.tu-muenchen.de       */
  43. /*           Peter M. Urban, urban@informatik.tu-muenchen.de         */
  44. /*                                                                   */
  45. /*  History:                                                         */
  46. /*    26.02.92  PMU  created                                         */
  47. /*    05.26.92       Version 1.0 released                            */
  48. /*                                                                   */
  49. /*  Copyright 1992 TU MUENCHEN                                       */
  50. /*    See ./Copyright for complete rights and liability information. */
  51. /*                                                                   */
  52. /*********************************************************************/
  53. X
  54. #include <stdio.h>
  55. /* #include <stdlib.h> */
  56. #include <X11/Intrinsic.h>
  57. #include <X11/StringDefs.h>
  58. #include <X11/Shell.h>
  59. #include <X11/Xaw/Cardinals.h>
  60. #include <X11/Xaw/Command.h>
  61. #include <X11/Xaw/Dialog.h>
  62. #include <X11/Xaw/Box.h>
  63. #include "FileNom.h"
  64. #include "bibview.h"
  65. X
  66. X
  67. /* macros and definitions */
  68. /* ---------------------- */
  69. X
  70. X
  71. /* imported global variables */
  72. /* ------------------------- */
  73. extern XtAppContext app_context;
  74. extern Widget topLevel, mainMenu, desktop;
  75. extern Pixmap questPixmap;
  76. X
  77. X
  78. /* exported global variables */
  79. /* ------------------------- */
  80. X
  81. X
  82. /* local function prototypes */
  83. /* ------------------------- */
  84. static Errcode cseCollateSrc (BibPtr bp);
  85. static Errcode cseCollateDest (BibPtr bp);
  86. static void cancelCheck (Widget w, XtPointer clientData, XtPointer callData);
  87. static Errcode checkBibFile (BibPtr bp);
  88. static void CancelLoad (Widget w, XtPointer clientData, XtPointer callData);
  89. static void confirmMacroQuit (BibPtr bp);
  90. static void macroQuitOkCmd (Widget w, XtPointer clientData, XtPointer callData);
  91. static void saveMacroQuitCmd (Widget w, XtPointer clientData, XtPointer callData);
  92. static void LoadCfgFile (Widget w, XtPointer clientData, XtPointer callData);
  93. X
  94. X
  95. /* local global variables */
  96. /* ---------------------- */
  97. static BibPtr gbp = NULL;
  98. static chkOkMsg = True;
  99. X
  100. X
  101. /*********************************************************************/
  102. /* COLLATE (MERGE) BIBLIOGRAPHY FUNCTIONS                            */
  103. /*********************************************************************/
  104. X
  105. /*********************************************************************/
  106. /* cseCollateBibCmd:                                                 */
  107. /*    Callback function for command collate in service menu          */
  108. /*********************************************************************/
  109. void
  110. cseCollateBibCmd (Widget w, XtPointer clientData, XtPointer callData)
  111. {
  112. Errcode status;
  113. X
  114. X   if ((status = guwSelectBib("collSrcHead", cseCollateSrc)) != OK)
  115. X      guwWarning(status);
  116. }
  117. X
  118. X
  119. /*********************************************************************/
  120. /* cseCollateSrc:                                                    */
  121. /*    Collate bibs with source bp                                    */
  122. /*********************************************************************/
  123. static Errcode
  124. cseCollateSrc (BibPtr bp)
  125. {
  126. Errcode status;
  127. X
  128. X   gbp = bp;
  129. X   if ((status = guwSelectBib("collDestHead", cseCollateDest)) != OK)
  130. X      guwWarning(status);
  131. X   return(OK);
  132. }
  133. X
  134. X
  135. /*********************************************************************/
  136. /* cseCollateDest:                                                   */
  137. /*    Collate bibs with dest in bp, src in gbp                       */
  138. /*********************************************************************/
  139. static Errcode
  140. cseCollateDest (BibPtr bp)
  141. {
  142. int status;
  143. X
  144. X   if ((status = cseCollateBibs(gbp, bp)) != OK)
  145. X      guwError(status);
  146. X
  147. X   return(OK);
  148. }
  149. X
  150. X
  151. /*********************************************************************/
  152. /* cseCollateBibs:                                                   */
  153. /*    Collate two bibs, src is inserted to dest                      */
  154. /*********************************************************************/
  155. Errcode
  156. cseCollateBibs (BibPtr sbp, BibPtr dbp)
  157. {
  158. CardListNode *clp, *cl = NULL;
  159. char wcKey[] = ".";
  160. CardData *wcCard;
  161. Errcode status;
  162. X
  163. X   /* check bibs: can't be equal */
  164. X   if (sbp->treeIdx == dbp->treeIdx) {
  165. X      return(ERR_COLL_SAME_BIB);
  166. X   }
  167. X
  168. X   /* make list of all cards in src bib */
  169. X   if ((status = dbtMakeCard(&wcCard)) != DBT_OK) {
  170. X      return(status);
  171. X   }
  172. X   wcCard->mainkey = glbNewString(".");
  173. X   if ((status = dbtSearchList(sbp->treeIdx, wcCard, &cl)) != DBT_OK) {
  174. X      return(status);
  175. X   }
  176. X
  177. X   /* add all cards from list to dest bib */
  178. X   for (clp = cl; clp != NULL; clp = clp->next) {
  179. X      if ((status = dbtInsert(dbp->treeIdx, clp->data)) != DBT_OK)
  180. X     guwError(status);
  181. X   }
  182. X   /* !!! HOLGER: Liste wegschmeissen */
  183. X
  184. X   return(OK);
  185. }
  186. X
  187. X
  188. X
  189. /*********************************************************************/
  190. /* CHECK BIBLIOGRAPHY FUNCTIONS                                      */
  191. /*********************************************************************/
  192. X
  193. /*********************************************************************/
  194. /* cseCheckBibCmd:                                                   */
  195. /*    Callback function for command check in services menu           */
  196. /*********************************************************************/
  197. void
  198. cseCheckBibCmd (Widget w, XtPointer clientData, XtPointer callData)
  199. {
  200. Errcode status;
  201. X
  202. X   if ((status = guwSelectBib("checkHead", checkBibFile)) != OK)
  203. X      guwWarning(status);
  204. }
  205. X
  206. X
  207. /*********************************************************************/
  208. /* cseCheckBib:                                                      */
  209. /*    Checks opened bibliography for inconsistencies                 */
  210. /*********************************************************************/
  211. Errcode
  212. cseCheckBib (BibPtr bp, Boolean sayOkMsg)
  213. {
  214. Errcode status;
  215. X
  216. X   chkOkMsg = sayOkMsg;
  217. X   if ((status = checkBibFile(bp)) != OK)
  218. X      guwWarning(status);
  219. X   chkOkMsg = True;
  220. X
  221. X   return(status);
  222. }
  223. X
  224. X
  225. /*********************************************************************/
  226. /* checkBibFile:                                                     */
  227. /*    Callback function for OK button in file select box             */
  228. /*********************************************************************/
  229. static Errcode
  230. checkBibFile (BibPtr bp)
  231. {
  232. CardListNode *cl = NULL;
  233. Errcode status;
  234. X
  235. X   /* search for illegal cards */
  236. X   if ((status = dbtCheckAllCards(bp->treeIdx, &cl)) != DBT_OK) {
  237. X      /* HOLGER: Liste wegschmeissen */
  238. X      return(status);
  239. X   }
  240. X
  241. X   /* check for illegal cards found */
  242. X   if (cl == NULL) {
  243. X      if (chkOkMsg) guwNotice(ERR_NO_ILLEGAL_CARDS);
  244. X      return(OK);
  245. X   }
  246. X   else {
  247. X      guwWarning(ERR_ILLEGAL_CARDS);
  248. X      if (gulListWinExists(bp)) 
  249. X     gulCloseListWin(bp);
  250. X      if ((status = gulOpenListWin(bp, cl)) != OK) {
  251. X     /* HOLGER: Liste wegschmeissen */
  252. X     return(status);
  253. X      }
  254. X   }
  255. X
  256. X   return(OK);
  257. }
  258. X
  259. X
  260. X
  261. /*********************************************************************/
  262. /* EDIT MACRO COMMAND FUNCTIONS                                      */
  263. /*********************************************************************/
  264. X
  265. /*********************************************************************/
  266. /* cseEditMacrosCmd:                                                 */
  267. /*    Callback function for command macros in services menu          */
  268. /*********************************************************************/
  269. void
  270. cseEditMacrosCmd (Widget w, XtPointer clientData, XtPointer callData)
  271. {
  272. Errcode status;
  273. X
  274. X   if ((status = guwSelectBib("macroHead", cseEditMacros)) != OK)
  275. X      guwWarning(status);
  276. }
  277. X
  278. X
  279. /*********************************************************************/
  280. /* cseMacrosCmd:                                                     */
  281. /*    Callback function for command macros in bib window             */
  282. /*********************************************************************/
  283. void
  284. cseMacrosCmd (Widget w, XtPointer clientData, XtPointer callData)
  285. {
  286. BibPtr bp = (BibPtr)clientData;
  287. Errcode status;
  288. X
  289. X   if ((status = cseEditMacros(bp)) != OK)
  290. X      guwWarning(status);
  291. }
  292. X
  293. X
  294. /*********************************************************************/
  295. /* cseEditMacros:                                                    */
  296. /*    Open shell to edit temp file containing macros                 */
  297. /*********************************************************************/
  298. Errcode
  299. cseEditMacros (BibPtr bp)
  300. {
  301. Errcode status;
  302. int fh;
  303. X
  304. X   /* window opened already? */
  305. X   if (gueMacroWinExists(bp)) {
  306. X      if (XtIsRealized(bp->mw->macShell)) {
  307. X     XRaiseWindow(XtDisplay(bp->mw->macShell),
  308. X              XtWindow(bp->mw->macShell));
  309. X      }
  310. X      return(OK);
  311. X   }
  312. X
  313. X   /* open new temp file? */
  314. X   if (bp->macrofile == NULL) {
  315. X      if ((bp->macrofile = (char *)tempnam(NULL, NULL)) == NULL)
  316. X     return(ERR_NOMALLOC);
  317. X      if ((fh = creat(bp->macrofile, 0700)) == -1)
  318. X     return(ERR_NO_OPEN_TMP);
  319. X      close(fh);
  320. X   }
  321. X
  322. X   /* open macro window, widget takes care of file handling */
  323. X   if ((status = gueOpenMacroWin(bp)) != OK)
  324. X      return(status);
  325. X
  326. X   return(OK);
  327. }
  328. X
  329. X
  330. /*********************************************************************/
  331. /* cseSetMacroChangeFlag:                                            */
  332. /*    Callback of text widget, sets flags when buffer changes        */
  333. /*********************************************************************/
  334. void
  335. cseSetMacroChangeFlag (Widget w, XtPointer clientData, XtPointer callData)
  336. {
  337. BibPtr bp = (BibPtr)clientData;
  338. X
  339. X   bp->changed = TRUE;
  340. X   bp->mw->changed = TRUE;
  341. }
  342. X
  343. X
  344. /*********************************************************************/
  345. /* cseSaveMacrosCmd:                                                 */
  346. /*    Callback for save  command in macro window                     */
  347. /*********************************************************************/
  348. void
  349. cseSaveMacrosCmd (Widget w, XtPointer clientData, XtPointer callData)
  350. {
  351. BibPtr bp = (BibPtr)clientData;
  352. Errcode status;
  353. X
  354. X   if ((status = gueSaveMacrosToFile(bp)) != OK) {
  355. X      guwError(status);
  356. X      return;
  357. X   }
  358. X   bp->mw->changed = FALSE;
  359. }
  360. X
  361. X
  362. /*********************************************************************/
  363. /* cseQuitMacrosCmd:                                                 */
  364. /*    Callback for close command in macro window                     */
  365. /*********************************************************************/
  366. void
  367. cseQuitMacrosCmd (Widget w, XtPointer clientData, XtPointer callData)
  368. {
  369. BibPtr bp = (BibPtr)clientData;
  370. Errcode status;
  371. X
  372. X   /* macros changed, confirm close w/o saving */
  373. X   if (bp->mw->changed) {
  374. X      confirmMacroQuit(bp);
  375. X      return;
  376. X   }
  377. X
  378. X   if ((status = gueCloseMacroWin(bp)) != OK)
  379. X      guwError(status);
  380. }
  381. X
  382. X
  383. /*********************************************************************/
  384. /* confirmMacroQuit:                                                 */
  385. /*    Opens dialogbox for user to confirm closing without saving     */
  386. /*********************************************************************/
  387. static void
  388. confirmMacroQuit (BibPtr bp)
  389. {
  390. static Widget conShell, conDialog, conSaveButton, conQuitButton;
  391. Position dx, dy, x, y;
  392. int status;
  393. X
  394. X   XtVaGetValues(desktop,
  395. X                 XtNx, &dx,
  396. X                 XtNy, &dy, NULL);
  397. X   XtTranslateCoords(desktop,
  398. X                     (Position)dx + SUBWIN_MARGIN,
  399. X                     (Position)dy + SUBWIN_MARGIN,
  400. X                     &x, &y);
  401. X   conShell = XtVaCreatePopupShell("confirmMacQuitShell",
  402. X            transientShellWidgetClass, topLevel, 
  403. X        XtNx, x, XtNy, y, NULL);
  404. X   conDialog = XtVaCreateManagedWidget("confirmMacQuitBox",
  405. X             dialogWidgetClass, conShell, 
  406. X         XtNicon, questPixmap, NULL);
  407. X   conSaveButton = XtVaCreateManagedWidget("save",
  408. X                 commandWidgetClass, conDialog, NULL);
  409. X   conQuitButton = XtVaCreateManagedWidget("quit",
  410. X                 commandWidgetClass, conDialog, NULL);
  411. X   XtAddCallback(conSaveButton, XtNcallback, saveMacroQuitCmd, conShell);
  412. X   XtAddCallback(conQuitButton, XtNcallback, macroQuitOkCmd, conShell);
  413. X
  414. X   XtSetSensitive(mainMenu, FALSE);
  415. X   gubSetSensitive(NULL, FALSE);
  416. X   gbp = bp;
  417. X   XtPopup(conShell, XtGrabNonexclusive);
  418. }
  419. X
  420. X
  421. /*********************************************************************/
  422. /* saveMacroQuitCmd:                                                 */
  423. /*    Callback function for SAVE & QUIT butoon in confirm box        */
  424. /*********************************************************************/
  425. static void
  426. saveMacroQuitCmd (Widget w, XtPointer clientData, XtPointer callData)
  427. {
  428. Widget shell = (Widget)clientData;
  429. Errcode status;
  430. X
  431. X   /* remove confirm shell */
  432. X   XtPopdown(shell);
  433. X
  434. X   /* save and close macro editing window */
  435. X   if ((status = gueSaveMacrosToFile(gbp)) != OK)
  436. X      guwError(status);
  437. X   if ((status = gueCloseMacroWin(gbp)) != OK)
  438. X      guwError(status);
  439. X   gbp = NULL;
  440. X
  441. X   /* enable menus */
  442. X   XtSetSensitive(mainMenu, TRUE);
  443. X   gubSetSensitive(NULL, TRUE);
  444. }
  445. X
  446. X
  447. /*********************************************************************/
  448. /* macroQuitOkCmd:                                                   */
  449. /*    Callback function for OK button in confirm box                 */
  450. /*********************************************************************/
  451. static void
  452. macroQuitOkCmd (Widget w, XtPointer clientData, XtPointer callData)
  453. {
  454. Widget shell = (Widget)clientData;
  455. Errcode status;
  456. X
  457. X   /* remove confirm shell */
  458. X   XtPopdown(shell);
  459. X
  460. X   /* close macro editing window */
  461. X   if ((status = gueCloseMacroWin(gbp)) != OK)
  462. X      guwError(status);
  463. X   gbp = NULL;
  464. X
  465. X   /* enable menus */
  466. X   XtSetSensitive(mainMenu, TRUE);
  467. X   gubSetSensitive(NULL, TRUE);
  468. }
  469. X
  470. X
  471. X
  472. /*********************************************************************/
  473. /* LOAD C0NFIGURATION FUNCTIONS                                      */
  474. /*********************************************************************/
  475. X
  476. /*********************************************************************/
  477. /* cseLoadConfigCmd:                                                 */
  478. /*    Callback function for menu load config in services menu        */
  479. /*********************************************************************/
  480. void
  481. cseLoadConfigCmd (Widget w, XtPointer clientData, XtPointer callData)
  482. {
  483. static Widget fsbShell, fsbBox, fsbLabel, fsbDialog;
  484. char fname[MAX_FILEPATHLEN];
  485. Position dx, dy, x, y;
  486. int status;
  487. X
  488. X   XtVaGetValues(desktop,
  489. X                 XtNx, &dx,
  490. X                 XtNy, &dy, NULL);
  491. X   XtTranslateCoords(desktop,
  492. X                     (Position)dx + SUBWIN_MARGIN,
  493. X                     (Position)dy + SUBWIN_MARGIN,
  494. X                     &x, &y);
  495. X   fsbShell  = XtVaCreatePopupShell("fileSelectBoxShell",
  496. X             topLevelShellWidgetClass, desktop, 
  497. X          XtNx, x, XtNy, y, NULL);
  498. X   fsbBox    = XtVaCreateManagedWidget("fileSelectBox",
  499. X                 boxWidgetClass, fsbShell, NULL);
  500. X   fsbLabel  = XtVaCreateManagedWidget("configLoadHead",
  501. X                 labelWidgetClass, fsbBox,
  502. X                 XtNborderWidth, 0, NULL);
  503. X   fsbDialog = XtVaCreateManagedWidget("loadFileBoxShell",
  504. X                fileNominatorWidgetClass, fsbBox,
  505. X                XtNborderWidth, 0, NULL);
  506. X
  507. X   XtAddCallback(fsbDialog, XtNcancelCallback, CancelLoad, fsbShell);
  508. X   XtAddCallback(fsbDialog, XtNselectCallback, LoadCfgFile, fsbDialog);
  509. X
  510. X   XtSetSensitive(mainMenu, FALSE);
  511. X   gubSetSensitive(NULL, FALSE);
  512. X   XtPopup(fsbShell, XtGrabNonexclusive);
  513. }
  514. X
  515. X
  516. /*********************************************************************/
  517. /* CancelLoad:                                                       */
  518. /*    Callback function for CANCEL button in file select box         */
  519. /*********************************************************************/
  520. static void
  521. CancelLoad (Widget w, XtPointer clientData, XtPointer callData)
  522. {
  523. Widget dialog = (Widget)clientData;
  524. X
  525. X   XtSetSensitive(mainMenu, TRUE);
  526. X   gubSetSensitive(NULL, TRUE);
  527. X   XtPopdown(dialog);
  528. X
  529. }
  530. X
  531. X
  532. /*********************************************************************/
  533. /* LoadConfigFile:                                                   */
  534. /*    Callback function for OK button in file select box             */
  535. /*********************************************************************/
  536. static void
  537. LoadCfgFile (Widget w, XtPointer clientData, XtPointer callData)
  538. {
  539. Widget dialog = (Widget)clientData;
  540. String filepath;
  541. int status;
  542. X
  543. X   /* get and keep filename */
  544. X   filepath = (String)FileNominatorGetFullFileName(dialog);
  545. X
  546. X   /* remove file select box */
  547. X   XtSetSensitive(mainMenu, TRUE);
  548. X   gubSetSensitive(NULL, TRUE);
  549. X   XtPopdown(XtParent(XtParent(dialog)));
  550. X
  551. X   /* read config file */
  552. X   if ((status = rcfReadCfgFile(filepath)) != OK)
  553. X      guwError(status);
  554. X
  555. }
  556. X
  557. X
  558. X
  559. SHAR_EOF
  560. echo 'File ctl_serv.c is complete' &&
  561. chmod 0644 ctl_serv.c ||
  562. echo 'restore of ctl_serv.c failed'
  563. Wc_c="`wc -c < 'ctl_serv.c'`"
  564. test 17259 -eq "$Wc_c" ||
  565.     echo 'ctl_serv.c: original size 17259, current size' "$Wc_c"
  566. rm -f _shar_wnt_.tmp
  567. fi
  568. # ============= ctl_srch.c ==============
  569. if test -f 'ctl_srch.c' -a X"$1" != X"-c"; then
  570.     echo 'x - skipping ctl_srch.c (File already exists)'
  571.     rm -f _shar_wnt_.tmp
  572. else
  573. > _shar_wnt_.tmp
  574. echo 'x - extracting ctl_srch.c (Text)'
  575. sed 's/^X//' << 'SHAR_EOF' > 'ctl_srch.c' &&
  576. /*********************************************************************/
  577. /*  bibView: Administration of bibTex-Databases                      */
  578. /*           (Verwaltung von bibTeX-Literaturdatenbanken)            */
  579. /*                                                                   */
  580. /*  Module:  ctl_srch.c                                              */
  581. /*                                                                   */
  582. /*             Search commands                                       */
  583. /*             - Search for specified items                          */
  584. /*             - Display all items in a list                         */
  585. /*                                                                   */
  586. /*  Author:  Holger Martin,  martinh@informatik.tu-muenchen.de       */
  587. /*           Peter M. Urban, urban@informatik.tu-muenchen.de         */
  588. /*                                                                   */
  589. /*  History:                                                         */
  590. /*    12.16.91  PMU  created                                         */
  591. /*    05.26.92       Version 1.0 released                            */
  592. /*                                                                   */
  593. /*  Copyright 1992 TU MUENCHEN                                       */
  594. /*    See ./Copyright for complete rights and liability information. */
  595. /*                                                                   */
  596. /*********************************************************************/
  597. X
  598. #include <stdio.h>
  599. #include <X11/Intrinsic.h>
  600. #include <X11/StringDefs.h>
  601. #include <X11/Xaw/Paned.h>
  602. #include <X11/Xaw/Form.h>
  603. #include <X11/Xaw/Box.h>
  604. #include <X11/Xaw/List.h>
  605. #include <X11/Xaw/Command.h>
  606. #include <X11/Xaw/Viewport.h>
  607. #include <X11/Xaw/MenuButton.h>
  608. #include <X11/Xaw/SimpleMenu.h>
  609. #include <X11/Xaw/SmeBSB.h>
  610. #include <X11/Xaw/SmeLine.h>
  611. #include "bibview.h"
  612. #include "ComboBo.h"
  613. X
  614. X
  615. /* imported global variables */
  616. /* ------------------------- */
  617. extern Widget topLevel, desktop, mainMenu;
  618. extern PredefLists predefLst;
  619. X
  620. X
  621. /* macros and definitions */
  622. /* ---------------------- */
  623. X
  624. /* structure for searches */
  625. typedef struct {
  626. X   BibPtr bp;                  /* bib to search in */
  627. X   Widget srchShell,           /* window widgets */
  628. X      srchWin,
  629. X      cmdBox,
  630. X      cancel,
  631. X      ok,
  632. X      fldVport,
  633. X      fields,
  634. X      cbAddress,           /* widgets for search fields */
  635. X      cbAnnote, 
  636. X          cbAuthor,
  637. X      cbBooktitle,
  638. X      cbChapter,
  639. X      cbEdition,
  640. X      cbEditor,
  641. X      cbHowpublished,
  642. X      cbInstitution,
  643. X      cbJournal,
  644. X      cbKey,
  645. X      cbMonth,
  646. X      cbNote,
  647. X      cbNumber,
  648. X      cbOrganization,
  649. X      cbPages,
  650. X      cbPublisher,
  651. X      cbSchool,
  652. X      cbSeries,
  653. X      cbTitle,
  654. X      cbType,
  655. X      cbVolume,
  656. X      cbYear,
  657. X      cbCardtype,
  658. X      cbCategory,
  659. X      cbCrossref,
  660. X      cbMainkey;
  661. } SearchWin, *SearchWinPtr;
  662. X
  663. X
  664. /* local function prototypes */
  665. /* ------------------------- */
  666. static void srchOkCmd(Widget widget, XtPointer clientData, XtPointer callData);
  667. static void srchQuitCmd(Widget widget, XtPointer clientData, XtPointer callData);
  668. X
  669. X
  670. /* exported variables */
  671. /* ------------------ */
  672. X
  673. X
  674. /* local global variables */
  675. /* ---------------------- */
  676. X
  677. X
  678. /*********************************************************************/
  679. /* csrSearchCmd:                                                     */
  680. /*    Callback function for search menu entry                        */
  681. /*********************************************************************/
  682. void 
  683. csrSearchCmd (Widget w, XtPointer clientData, XtPointer callData)
  684. {
  685. BibPtr bp = (BibPtr)clientData;
  686. SearchWinPtr sw;
  687. CardListNode *cl;
  688. Position x, y;
  689. Errcode status;
  690. X
  691. X   if ((sw = (SearchWinPtr) malloc(sizeof(SearchWin))) == NULL) {
  692. X      guwError(ERR_NOMALLOC);
  693. X      return;
  694. X   }
  695. X
  696. X   XtTranslateCoords(bp->bw->bibdesk,
  697. X             SUBWIN_MARGIN, SUBWIN_MARGIN,
  698. X             &x, &y);
  699. X
  700. X   sw->bp = bp;
  701. X   sw->srchShell      = XtVaCreatePopupShell("srchShell", 
  702. X                      topLevelShellWidgetClass, topLevel, 
  703. X                      XtNx, x, XtNy, y, NULL);
  704. X   sw->srchWin        = XtVaCreateManagedWidget("srchWin", 
  705. X                      panedWidgetClass, sw->srchShell, NULL);
  706. X   sw->cmdBox         = XtVaCreateManagedWidget("commandBox", 
  707. X                      boxWidgetClass, sw->srchWin, NULL);
  708. X   sw->ok             = XtVaCreateManagedWidget("ok", 
  709. X                      commandWidgetClass, sw->cmdBox, NULL);
  710. X   sw->cancel         = XtVaCreateManagedWidget("cancel", 
  711. X                      commandWidgetClass, sw->cmdBox, NULL);
  712. X   sw->fldVport       = XtVaCreateManagedWidget("srchVport", 
  713. X                      viewportWidgetClass, sw->srchWin,
  714. X                  XtNallowVert, True, NULL);
  715. X   sw->fields         = XtVaCreateManagedWidget("srchFlds", 
  716. X                      boxWidgetClass, sw->fldVport, NULL);
  717. X
  718. /* 
  719. X   sw->cbCardtype     = XtVaCreateManagedWidget("cbCardtype", 
  720. X                  comboBoxWidgetClass, sw->fields,
  721. X                  XtNrcList,  predefLst.cardtype, NULL); 
  722. */
  723. X   sw->cbTitle        = XtVaCreateManagedWidget("cbTitle",
  724. X                  comboBoxWidgetClass, sw->fields,
  725. X                  XtNrcList,  predefLst.title, NULL); 
  726. X   sw->cbAuthor       = XtVaCreateManagedWidget("cbAuthor", 
  727. X                  comboBoxWidgetClass, sw->fields,
  728. X                  XtNrcList,  predefLst.author, NULL); 
  729. X   sw->cbCategory     = XtVaCreateManagedWidget("cbCategory", 
  730. X                  comboBoxWidgetClass, sw->fields,
  731. X                  XtNrcList,  predefLst.category, NULL); 
  732. X   sw->cbMonth        = XtVaCreateManagedWidget("cbMonth", 
  733. X                  comboBoxWidgetClass, sw->fields,
  734. X                  XtNrcList,  predefLst.month, NULL); 
  735. X   sw->cbYear         = XtVaCreateManagedWidget("cbYear", 
  736. X                  comboBoxWidgetClass, sw->fields,
  737. X                  XtNrcList,  predefLst.year, NULL); 
  738. X   sw->cbNote         = XtVaCreateManagedWidget("cbNote", 
  739. X                  comboBoxWidgetClass, sw->fields,
  740. X                  XtNrcList,  predefLst.note, NULL); 
  741. X   sw->cbAnnote       = XtVaCreateManagedWidget("cbAnnote", 
  742. X                  comboBoxWidgetClass, sw->fields,
  743. X                  XtNrcList,  predefLst.annote, NULL); 
  744. X   sw->cbJournal      = XtVaCreateManagedWidget("cbJournal", 
  745. X                  comboBoxWidgetClass, sw->fields,
  746. X                  XtNrcList,  predefLst.journal, NULL); 
  747. X   sw->cbEditor       = XtVaCreateManagedWidget("cbEditor", 
  748. X                  comboBoxWidgetClass, sw->fields,
  749. X                  XtNrcList,  predefLst.editor, NULL); 
  750. X   sw->cbOrganization = XtVaCreateManagedWidget("cbOrganization",
  751. X                  comboBoxWidgetClass, sw->fields,
  752. X                  XtNrcList,  predefLst.organization, NULL); 
  753. X   sw->cbInstitution  = XtVaCreateManagedWidget("cbInstitution",
  754. X                  comboBoxWidgetClass, sw->fields,
  755. X                  XtNrcList,  predefLst.institution, NULL); 
  756. X   sw->cbPublisher    = XtVaCreateManagedWidget("cbPublisher",
  757. X                  comboBoxWidgetClass, sw->fields,
  758. X                  XtNrcList,  predefLst.publisher, NULL); 
  759. X   sw->cbSchool       = XtVaCreateManagedWidget("cbSchool", 
  760. X                  comboBoxWidgetClass, sw->fields,
  761. X                  XtNrcList,  predefLst.school, NULL); 
  762. /*
  763. X   sw->cbAddress      = XtVaCreateManagedWidget("cbAddress", 
  764. X                  comboBoxWidgetClass, sw->fields,
  765. X                  XtNrcList,  predefLst.address, NULL); 
  766. */
  767. X   sw->cbEdition      = XtVaCreateManagedWidget("cbEdition", 
  768. X                  comboBoxWidgetClass, sw->fields,
  769. X                  XtNrcList,  predefLst.edition, NULL); 
  770. X   sw->cbChapter      = XtVaCreateManagedWidget("cbChapter", 
  771. X                  comboBoxWidgetClass, sw->fields,
  772. X                  XtNrcList,  predefLst.chapter, NULL); 
  773. X   sw->cbSeries       = XtVaCreateManagedWidget("cbSeries", 
  774. X                  comboBoxWidgetClass, sw->fields,
  775. X                  XtNrcList,  predefLst.series, NULL); 
  776. X   sw->cbPages        = XtVaCreateManagedWidget("cbPages", 
  777. X                  comboBoxWidgetClass, sw->fields,
  778. X                  XtNrcList,  predefLst.pages, NULL); 
  779. X   sw->cbVolume       = XtVaCreateManagedWidget("cbVolume", 
  780. X                  comboBoxWidgetClass, sw->fields,
  781. X                  XtNrcList,  predefLst.volume, NULL); 
  782. X   sw->cbNumber       = XtVaCreateManagedWidget("cbNumber", 
  783. X                  comboBoxWidgetClass, sw->fields,
  784. X                  XtNrcList,  predefLst.number, NULL); 
  785. X   sw->cbBooktitle    = XtVaCreateManagedWidget("cbBooktitle", 
  786. X                  comboBoxWidgetClass, sw->fields,
  787. X                  XtNrcList,  predefLst.booktitle, NULL); 
  788. /*
  789. X   sw->cbHowpublished = XtVaCreateManagedWidget("cbHowpublished", 
  790. X                  comboBoxWidgetClass, sw->fields,
  791. X                  XtNrcList,  predefLst.howpublished, NULL); 
  792. X   sw->cbType         = XtVaCreateManagedWidget("cbType", 
  793. X                  comboBoxWidgetClass, sw->fields,
  794. X                  XtNrcList,  predefLst.type, NULL); 
  795. */
  796. X   sw->cbKey          = XtVaCreateManagedWidget("cbKey", 
  797. X                  comboBoxWidgetClass, sw->fields,
  798. X                  XtNrcList,  predefLst.key, NULL); 
  799. X   sw->cbMainkey      = XtVaCreateManagedWidget("cbMainkey", 
  800. X                  comboBoxWidgetClass, sw->fields,
  801. X                  XtNrcList,  predefLst.mainkey, NULL); 
  802. X   sw->cbCrossref     = XtVaCreateManagedWidget("cbCrossref", 
  803. X                  comboBoxWidgetClass, sw->fields,
  804. X                  XtNrcList,  predefLst.crossref, NULL); 
  805. X
  806. X   XtAddCallback(sw->ok, XtNcallback, srchOkCmd, (XtPointer)sw);
  807. X   XtAddCallback(sw->cancel, XtNcallback, srchQuitCmd, (XtPointer)sw);
  808. X
  809. X   XtSetSensitive(mainMenu, FALSE);
  810. X   gubSetSensitive(NULL, FALSE);
  811. X   XtPopup(sw->srchShell, XtGrabNone);
  812. }
  813. X
  814. X
  815. /*********************************************************************/
  816. /* csrListCmd:                                                       */
  817. /*    Callback function for list menu entry                          */
  818. /*********************************************************************/
  819. void 
  820. csrListCmd (Widget w, XtPointer clientData, XtPointer callData)
  821. {
  822. BibPtr bp = (BibPtr) clientData;
  823. CardListNode *cl = NULL;
  824. int status;
  825. char wcKey[] = ".";
  826. CardData *wcCard;
  827. X
  828. X   /* build list with wildcard search */
  829. X   if ((status = (int)dbtMakeCard(&wcCard)) != OK) {
  830. X      guwError(status);
  831. X   }
  832. X   wcCard->mainkey = glbNewString(".");
  833. X   if ((status = dbtSearchList(bp->treeIdx, wcCard, &cl)) != OK) {
  834. X      guwError(status); 
  835. X      return;
  836. X   }
  837. X
  838. X   /* display list */
  839. X   if (cl == NULL) {
  840. X      guwNotice(DBT_ENOMATCH);
  841. X      return;
  842. X   }
  843. X   /* display list */
  844. X   if (gulListWinExists(bp)) {
  845. X      if ((status = gulReplaceListData(bp, cl)) != OK) {
  846. X     guwError(status);
  847. X      }
  848. X      if (XtIsRealized(bp->lw->lstShell)) {
  849. X         XRaiseWindow(XtDisplay(bp->lw->lstShell),
  850. X              XtWindow(bp->lw->lstShell));
  851. X      }
  852. X   }
  853. X   else {
  854. X      if ((status = gulOpenListWin(bp, cl)) != OK) {
  855. X     guwError(status);
  856. X      }
  857. X   }
  858. }
  859. X
  860. X
  861. X
  862. /*********************************************************************/
  863. /* csrDisplayCardCmd:                                                */
  864. /*    Callback for list entries                                      */
  865. /*********************************************************************/
  866. void
  867. csrDisplayCardCmd (Widget w, XtPointer clientData, XtPointer callData)
  868. {
  869. XXawListReturnStruct *item = (XawListReturnStruct*)callData;
  870. BibPtr bp = (BibPtr)clientData;
  871. CardListNode *cn = bp->lw->cardLst;
  872. CardPtr cp;
  873. Errcode status;
  874. int i;
  875. X
  876. X   XawListUnhighlight(bp->lw->list);
  877. X
  878. X   for (i=0; i < item->list_index; i++)
  879. X      cn = cn->next;
  880. X
  881. X   /* check if card displayed already */
  882. X   if ((cp = glbFindCard(bp, cn->data)) != NULL) {
  883. X      if (XtIsRealized(cp->cw->cardShell)) {
  884. X     XRaiseWindow(XtDisplay(cp->cw->cardShell),
  885. X              XtWindow(cp->cw->cardShell));
  886. X      }
  887. X      return;
  888. X   }
  889. X
  890. X
  891. X   /* create new internal data for a card window */
  892. X   if ((status = glbNewCardListEl(bp, &cp, cn->data)) != OK) {
  893. X      guwError(status);
  894. X      return;
  895. X   }
  896. X
  897. X   /* open the window */
  898. X   if ((status = gucOpenCardWin(bp, cp, FALSE)) != OK)
  899. X      guwError(status);
  900. }
  901. X
  902. X
  903. /*********************************************************************/
  904. /*  LOCAL FUNCTIONS                                                  */
  905. /*********************************************************************/
  906. X
  907. /*********************************************************************/
  908. /*  srchOkCmd:                                                       */
  909. /*    Callback for ok-button in search window                        */
  910. /*********************************************************************/
  911. static void
  912. srchOkCmd (Widget widget, XtPointer clientData, XtPointer callData)
  913. {
  914. SearchWinPtr sw = (SearchWinPtr)clientData;
  915. BibPtr bp = sw->bp;
  916. CardListNode *cl = NULL;
  917. CardData *wcCard = NULL;
  918. String s;
  919. Errcode status;
  920. X
  921. X   /* make new search card */
  922. X   if ((status = (int)dbtMakeCard(&wcCard)) != OK) {
  923. X     guwError(status);
  924. X     return;
  925. X   }
  926. X
  927. X   /* retrieve data from search window */
  928. /*
  929. X   if ((s = ComboBoxGetString(sw->cardtype)) != NULL)
  930. X      wcCard->cardtype = glbNewString(s);
  931. */
  932. X   if ((s = ComboBoxGetString(sw->cbTitle)) != NULL)
  933. X      wcCard->title = glbNewString(s);
  934. X   if ((s = ComboBoxGetString(sw->cbAuthor)) != NULL)
  935. X      wcCard->author = glbNewString(s);
  936. X   if ((s = ComboBoxGetString(sw->cbCategory)) != NULL)
  937. X      wcCard->category = glbNewString(s);
  938. X   if ((s = ComboBoxGetString(sw->cbMonth)) != NULL)
  939. X      wcCard->month = glbNewString(s);
  940. X   if ((s = ComboBoxGetString(sw->cbYear)) != NULL)
  941. X      wcCard->year = glbNewString(s);
  942. X   if ((s = ComboBoxGetString(sw->cbNote)) != NULL)
  943. X      wcCard->note = glbNewString(s);
  944. X   if ((s = ComboBoxGetString(sw->cbAnnote)) != NULL)
  945. X      wcCard->annote = glbNewString(s);
  946. X   if ((s = ComboBoxGetString(sw->cbJournal)) != NULL)
  947. X      wcCard->journal = glbNewString(s);
  948. X   if ((s = ComboBoxGetString(sw->cbEditor)) != NULL)
  949. X      wcCard->editor = glbNewString(s);
  950. X   if ((s = ComboBoxGetString(sw->cbOrganization)) != NULL)
  951. X      wcCard->organization = glbNewString(s);
  952. X   if ((s = ComboBoxGetString(sw->cbInstitution)) != NULL)
  953. X      wcCard->institution = glbNewString(s);
  954. X   if ((s = ComboBoxGetString(sw->cbPublisher)) != NULL)
  955. X      wcCard->publisher = glbNewString(s);
  956. X   if ((s = ComboBoxGetString(sw->cbSchool)) != NULL)
  957. X      wcCard->school = glbNewString(s);
  958. /*
  959. X   if ((s = ComboBoxGetString(sw->cbAddress)) != NULL)
  960. X      wcCard->address = glbNewString(s);
  961. */
  962. X   if ((s = ComboBoxGetString(sw->cbEdition)) != NULL)
  963. X      wcCard->edition = glbNewString(s);
  964. X   if ((s = ComboBoxGetString(sw->cbChapter)) != NULL)
  965. X      wcCard->chapter = glbNewString(s);
  966. X   if ((s = ComboBoxGetString(sw->cbSeries)) != NULL)
  967. X      wcCard->series = glbNewString(s);
  968. X   if ((s = ComboBoxGetString(sw->cbPages)) != NULL)
  969. X      wcCard->pages = glbNewString(s);
  970. X   if ((s = ComboBoxGetString(sw->cbVolume)) != NULL)
  971. X      wcCard->volume = glbNewString(s);
  972. X   if ((s = ComboBoxGetString(sw->cbNumber)) != NULL)
  973. X      wcCard->number = glbNewString(s);
  974. X   if ((s = ComboBoxGetString(sw->cbBooktitle)) != NULL)
  975. X      wcCard->booktitle = glbNewString(s);
  976. /*
  977. X   if ((s = ComboBoxGetString(sw->cbHowpublished)) != NULL)
  978. X      wcCard->howpublished = glbNewString(s);
  979. X   if ((s = ComboBoxGetString(sw->cbType)) != NULL)
  980. X      wcCard->type = glbNewString(s);
  981. */
  982. X   if ((s = ComboBoxGetString(sw->cbKey)) != NULL)
  983. X      wcCard->key = glbNewString(s);
  984. X   if ((s = ComboBoxGetString(sw->cbMainkey)) != NULL)
  985. X      wcCard->mainkey = glbNewString(s);
  986. X   if ((s = ComboBoxGetString(sw->cbCrossref)) != NULL)
  987. X      wcCard->crossref = glbNewString(s);
  988. X
  989. X   /* enable menus */
  990. X   XtSetSensitive(mainMenu, TRUE);
  991. X   gubSetSensitive(NULL, TRUE);
  992. X   XtPopdown(sw->srchShell);
  993. X   free(sw);
  994. X
  995. X   /* build list with wildcard search */
  996. X   if ((status = dbtSearchList(bp->treeIdx, wcCard, &cl)) != OK) {
  997. X      guwError(status); 
  998. X      return;
  999. X   }
  1000. X
  1001. X   dbtDeleteCard(&wcCard);  
  1002. X
  1003. X   if (cl == NULL) {
  1004. X      guwNotice(DBT_ENOMATCH);
  1005. X      return;
  1006. X   }
  1007. X
  1008. X   /* display list */
  1009. X   if (gulListWinExists(bp)) {
  1010. X      if ((status = gulReplaceListData(bp, cl)) != OK) {
  1011. X     guwError(status);
  1012. X      }
  1013. X      if (XtIsRealized(bp->lw->lstShell)) {
  1014. X         XRaiseWindow(XtDisplay(bp->lw->lstShell),
  1015. X              XtWindow(bp->lw->lstShell));
  1016. X      }
  1017. X   }
  1018. X   else {
  1019. X      if ((status = gulOpenListWin(bp, cl)) != OK) {
  1020. X     guwError(status);
  1021. X      }
  1022. X   }
  1023. }
  1024. X
  1025. X
  1026. /*********************************************************************/
  1027. /*  srchQuitCmd:                                                     */
  1028. /*    Callback for cancel-button in search window                    */
  1029. /*********************************************************************/
  1030. static void
  1031. srchQuitCmd (Widget widget, XtPointer clientData, XtPointer callData)
  1032. {
  1033. SearchWinPtr sw = (SearchWinPtr)clientData;
  1034. X
  1035. X   XtSetSensitive(mainMenu, TRUE);
  1036. X   gubSetSensitive(NULL, TRUE);
  1037. X
  1038. X   XtPopdown(sw->srchShell);
  1039. X   free(sw);
  1040. }
  1041. X
  1042. X
  1043. SHAR_EOF
  1044. chmod 0644 ctl_srch.c ||
  1045. echo 'restore of ctl_srch.c failed'
  1046. Wc_c="`wc -c < 'ctl_srch.c'`"
  1047. test 16389 -eq "$Wc_c" ||
  1048.     echo 'ctl_srch.c: original size 16389, current size' "$Wc_c"
  1049. rm -f _shar_wnt_.tmp
  1050. fi
  1051. # ============= db_tree.c ==============
  1052. if test -f 'db_tree.c' -a X"$1" != X"-c"; then
  1053.     echo 'x - skipping db_tree.c (File already exists)'
  1054.     rm -f _shar_wnt_.tmp
  1055. else
  1056. > _shar_wnt_.tmp
  1057. echo 'x - extracting db_tree.c (Text)'
  1058. sed 's/^X//' << 'SHAR_EOF' > 'db_tree.c' &&
  1059. /*********************************************************************/
  1060. /*  bibView: Administration of bibTex-Databases                      */
  1061. /*           (Verwaltung von bibTeX-Literaturdatenbanken)            */
  1062. /*                                                                   */
  1063. /*  Module:  db_tree.c                                               */
  1064. /*                                                                   */
  1065. /*             - AVL-Baeume                                          */
  1066. /*             - String-Listen                                       */
  1067. /*             - Karten-Listen                                       */
  1068. /*                                                                   */
  1069. /*  Author:  Holger Martin,  martinh@informatik.tu-muenchen.de       */
  1070. /*           Peter M. Urban, urban@informatik.tu-muenchen.de         */
  1071. /*                                                                   */
  1072. /*  History:                                                         */
  1073. /*    22.11.91   HBM  created                                        */
  1074. /*    18.01.92   HBM  UserFld-Funktionen                             */
  1075. /*    05.26.92       Version 1.0 released                            */
  1076. /*                                                                   */
  1077. /*  Copyright 1992 TU MUENCHEN                                       */
  1078. /*    See ./Copyright for complete rights and liability information. */
  1079. /*                                                                   */
  1080. /*********************************************************************/
  1081. X
  1082. X
  1083. #include <stdio.h>
  1084. #include <X11/Intrinsic.h> 
  1085. #define _WCHAR_T
  1086. /*
  1087. X #include <string.h>
  1088. */
  1089. #include "bibview.h"
  1090. X
  1091. X
  1092. #define INIT        register char *sp = instring;
  1093. #define GETC()      (*sp++)
  1094. #define PEEKC()     (*sp)
  1095. #define UNGETC(c)   (--sp)
  1096. #define RETURN(c)   return(c);
  1097. #define ERROR(c)    
  1098. #include <regexp.h>
  1099. X
  1100. X
  1101. X
  1102. /*********************************************************************/
  1103. /*  Include / Define                                                 */
  1104. /*********************************************************************/
  1105. X
  1106. #define KEY_EQUAL    0
  1107. #define KEY_GREATER  1
  1108. #define KEY_LESS    -1
  1109. X
  1110. #define LEFT_TREE_GREATER  -1
  1111. #define RIGHT_TREE_GREATER  1
  1112. #define TREES_EQUAL         0
  1113. X
  1114. #define TREE_BIGGER  1
  1115. #define TREE_SMALLER -1
  1116. #define TREE_LIKE_BEFORE 0
  1117. X
  1118. #define MAXREGSIZE    5000
  1119. X
  1120. extern PredefLists predefLst;
  1121. X
  1122. /**************************
  1123. X * Struktur fuer AVL-Baum *
  1124. X **************************/
  1125. typedef struct _AvlNode {
  1126. X                         CardData *data;
  1127. X                         int      balance;
  1128. X                         struct _AvlNode *left, 
  1129. X                                         *right;
  1130. } AvlNode;
  1131. X
  1132. X
  1133. X
  1134. X
  1135. /*****************************************
  1136. X * Array mit Pointern auf versch. Baeume *
  1137. X *****************************************/
  1138. AvlNode *TreeRoots[MAXTREEROOTS];
  1139. X
  1140. X
  1141. X
  1142. /*********************
  1143. X * Lokale Funktionen *
  1144. X *********************/
  1145. Errcode Scalloc(String *s1, String s2);
  1146. Errcode CopyCard(CardData **c, CardData *c2);
  1147. int     KeyCompare(char *s1, char *s2);
  1148. Errcode Insert(int treeIdx, AvlNode **tree, CardData *card, int *h);
  1149. Errcode Search(AvlNode *tree, CardData **card, int *calls);
  1150. Errcode BalanceLeft(int treeIdx, AvlNode **tree, int *h);
  1151. Errcode BalanceRight(int treeIdx, AvlNode **tree, int *h);
  1152. Errcode Del(AvlNode **tree, AvlNode **delnode, int *h);
  1153. void    AvlGoDown(AvlNode *baum, ListNode **list);
  1154. Errcode MakeListNode(ListNode **list);
  1155. Errcode ListAppend(ListNode **list, String word);
  1156. Errcode MakeCardListNode(CardListNode **list);
  1157. Errcode CardListAppend(CardListNode **list, CardData *card);
  1158. Errcode SearchList(AvlNode *baum, CardData *reg, CardListNode **list);
  1159. Errcode RegCompCard(CardData *card, CardData *reg);
  1160. Errcode MakeRegCard(CardData *card, CardData *reg);
  1161. Errcode DeleteTree(AvlNode *baum);
  1162. static void StrToLower(char *text);
  1163. static int StringIsEmpty(char *text);
  1164. static int StringPeteIsEmpty(char *text);
  1165. X
  1166. static Errcode checkCards (AvlNode *tree, CardListNode **list);
  1167. X
  1168. /*********************************************************************/
  1169. /*  Errcode Scalloc(String *s1, String s2):                          */
  1170. /*  Platz fuer s1 bereitstellen und s2 nach s1 kopieren              */
  1171. /*********************************************************************/
  1172. X
  1173. Errcode Scalloc(String *s1, String s2)
  1174. {
  1175. X if (s2 != NULL){
  1176. X   *s1 = (String)calloc(1,strlen(s2)+1);
  1177. X   if (*s1 == NULL) return DBT_ECALLOC;
  1178. X   strcpy(*s1, s2);
  1179. X }
  1180. X return DBT_OK;
  1181. }
  1182. X
  1183. X
  1184. /*********************************************************************/
  1185. /*  StrToLower(char *text):                                          */
  1186. /*********************************************************************/
  1187. X
  1188. static void StrToLower(char *text)
  1189. {
  1190. X while (*text != '\0') {
  1191. X   *text++ = tolower(*text);
  1192. X }
  1193. }
  1194. X
  1195. X
  1196. /*********************************************************************/
  1197. /*  StringIsEmpty(char *text):                                       */
  1198. /*********************************************************************/
  1199. X
  1200. static int StringIsEmpty(char *text)
  1201. {
  1202. X int erg;
  1203. X char *hp;
  1204. X
  1205. X hp = text;
  1206. X while (*hp != '\0') {
  1207. X  if (*hp != ' ') return 0;
  1208. X  hp++;
  1209. X }
  1210. X return 1;
  1211. }
  1212. X
  1213. X
  1214. /*********************************************************************/
  1215. /*  StringPeteIsEmpty(char *text):                                   */
  1216. /*********************************************************************/
  1217. X
  1218. static int StringPeteIsEmpty(char *text)
  1219. {
  1220. X if (text == NULL || *text == '\0') return 1;
  1221. X if (StringIsEmpty(text)) return 1;
  1222. X return 0;
  1223. }
  1224. X
  1225. X
  1226. /*********************************************************************/
  1227. /*  Errcode dbtGetFreeTreeIdx(int *treeIdx):                         */
  1228. /*  liefert naechsten freien Listenindex zurueck und markiert diesen */
  1229. /*  mit 1 als besetzt.                                               */
  1230. /*********************************************************************/
  1231. X
  1232. Errcode dbtGetFreeTreeIdx(int *treeIdx)
  1233. {
  1234. X int h;
  1235. X
  1236. X h = 0;
  1237. X while (TreeRoots[h] && h < MAXTREEROOTS) h++;
  1238. X if (h == MAXTREEROOTS) return DBT_ROOTSFULL;
  1239. X *treeIdx = h;
  1240. X TreeRoots[h] = (AvlNode *)1;   /* Markierung */
  1241. X return DBT_OK;
  1242. }
  1243. X
  1244. X
  1245. /**************************************************************************/
  1246. /* Errcode dbtMakeUserFld(UserFld **list):                                */
  1247. /* neuen Knoten fuer Benutzerfeld-Liste erstellen.                        */
  1248. /**************************************************************************/
  1249. X
  1250. Errcode dbtMakeUserFld(UserFld **list)
  1251. {
  1252. X  UserFld *hlist;
  1253. X
  1254. X  hlist = *list;
  1255. X  if ( hlist == NULL) {
  1256. X    hlist = (UserFld *)calloc(1,sizeof(UserFld));
  1257. X    if (hlist == NULL) return DBT_ECALLOC; 
  1258. X    hlist->next = NULL;
  1259. X    *list = hlist;
  1260. X    return DBT_OK; 
  1261. X  }
  1262. X  return DBT_OK; 
  1263. }
  1264. X
  1265. X
  1266. X
  1267. /**************************************************************************/
  1268. /* Errcode dbtDeleteAllUserFld(UserFld **list):                           */
  1269. /* Benutzerfeld-Liste loeschen.                                           */
  1270. /**************************************************************************/
  1271. X
  1272. Errcode dbtDeleteAllUserFld(UserFld **list)
  1273. {
  1274. X UserFld *h;
  1275. X
  1276. X h = *list;
  1277. X if (h) {
  1278. X   if (h->fldName != NULL) free(h->fldName);
  1279. X   if (h->fldData != NULL) free(h->fldData);
  1280. X   if (h->next != NULL) dbtDeleteAllUserFld(&h->next);
  1281. X   free(h);
  1282. X   *list = NULL; 
  1283. X   return DBT_OK;
  1284. X }
  1285. X return DBT_OK; 
  1286. }
  1287. X
  1288. X
  1289. X
  1290. X
  1291. /**************************************************************************/
  1292. /* Errcode dbtAppendUserFld(UserFld **list, UserFld *obj):                */
  1293. /* obj an list anhaengen (kopieren).                                      */
  1294. /**************************************************************************/
  1295. X
  1296. Errcode dbtAppendUserFld(UserFld **list, UserFld *obj)
  1297. {
  1298. X  UserFld *hlist, *anker; 
  1299. X  Errcode erg;
  1300. X
  1301. X  hlist = *list;
  1302. X  anker = hlist;
  1303. X  if (hlist == NULL) {
  1304. X    erg = dbtMakeUserFld(&hlist);
  1305. X    Scalloc(&hlist->fldName, obj->fldName); 
  1306. X    Scalloc(&hlist->fldData, obj->fldData); 
  1307. X    hlist->fldLabel =  obj->fldLabel;
  1308. X    hlist->fldText = obj->fldText;
  1309. X    *list = hlist; 
  1310. X    return erg;
  1311. X  }
  1312. X  else dbtAppendUserFld(&hlist->next, obj);
  1313. }
  1314. X
  1315. X
  1316. X
  1317. /**************************************************************************/
  1318. /* Errcode dbtMakeAndCopyUserFld(UserFld **nlist, UserFld *olist):        */
  1319. /* olist nach nlist kopieren.                                             */
  1320. /**************************************************************************/
  1321. X
  1322. Errcode dbtMakeAndCopyUserFld(UserFld **nlist, UserFld *olist)
  1323. {
  1324. X Errcode erg;
  1325. X UserFld *h, *hnode;
  1326. X
  1327. X erg = DBT_OK;
  1328. X h = olist;
  1329. X hnode = NULL;            /* wegen dbtAppendUserFld */
  1330. X while (h != NULL) {
  1331. X   erg = dbtAppendUserFld(&hnode, h);
  1332. X   h = h->next;
  1333. X }
  1334. X *nlist = hnode;
  1335. X return(erg);
  1336. }
  1337. X
  1338. X
  1339. X
  1340. X
  1341. /*********************************************************************/
  1342. /* Errcode dbtMakeCard(CardData **card):                             */
  1343. /* Anlegen einer neuen Karte                                         */
  1344. /*********************************************************************/
  1345. X
  1346. Errcode dbtMakeCard(CardData **card)
  1347. {
  1348. X  CardData *h;
  1349. X
  1350. X  h = (CardData *)calloc(1,sizeof(CardData));
  1351. X  if (h == NULL) return DBT_ECALLOC;
  1352. X  h->cardtypestr = NULL;
  1353. X  h->mainkey = NULL;   /* NEU */
  1354. X  h->crossref = NULL;   /* NEU */
  1355. X  h->address = NULL;
  1356. X  h->annote = NULL;
  1357. X  h->author = NULL;
  1358. X  h->booktitle = NULL;
  1359. X  h->chapter = NULL;
  1360. X  h->edition = NULL;
  1361. X  h->editor = NULL;
  1362. X  h->howpublished = NULL;
  1363. X  h->institution = NULL;
  1364. X  h->journal = NULL;
  1365. X  h->key = NULL;
  1366. X  h->month = NULL;
  1367. X  h->note = NULL;
  1368. X  h->number = NULL;
  1369. X  h->organization = NULL;
  1370. X  h->pages = NULL;
  1371. X  h->publisher = NULL;
  1372. X  h->school = NULL;
  1373. X  h->series = NULL;
  1374. X  h->title = NULL;
  1375. X  h->type = NULL;
  1376. X  h->volume = NULL;
  1377. X  h->year = NULL;
  1378. X  h->category = NULL;
  1379. X  h->ufield = NULL;
  1380. X  *card = h; 
  1381. X  return DBT_OK;
  1382. X
  1383. X
  1384. /*********************************************************************/
  1385. /* Errcode dbtDeleteCard(CardData **card):                           */
  1386. /* Speicherplatz fuer eine Karte freigeben                           */
  1387. /*********************************************************************/
  1388. X
  1389. Errcode dbtDeleteCard(CardData **card)
  1390. {
  1391. X   CardData *h;
  1392. X   
  1393. X   h = *card;
  1394. X   if (h) {
  1395. X     if (h->cardtypestr != NULL) free(h->cardtypestr); 
  1396. X     if (h->mainkey != NULL) free(h->mainkey);  /* NEU */
  1397. X     if (h->crossref != NULL) free(h->crossref);  /* NEU */
  1398. X     if (h->address != NULL) free(h->address);
  1399. X     if (h->annote != NULL) free(h->annote);
  1400. X     if (h->author != NULL) free(h->author);
  1401. X     if (h->booktitle != NULL) free(h->booktitle);
  1402. X     if (h->chapter != NULL) free(h->chapter);
  1403. X     if (h->edition != NULL) free(h->edition);
  1404. X     if (h->editor != NULL) free(h->editor);
  1405. X     if (h->howpublished != NULL) free(h->howpublished);
  1406. X     if (h->institution != NULL) free(h->institution);
  1407. X     if (h->journal != NULL) free(h->journal);
  1408. X     if (h->key != NULL) free(h->key);
  1409. X     if (h->month != NULL) free(h->month);
  1410. X     if (h->note != NULL) free(h->note);
  1411. X     if (h->number != NULL) free(h->number);
  1412. X     if (h->organization != NULL) free(h->organization);
  1413. X     if (h->pages != NULL) free(h->pages);
  1414. X     if (h->publisher != NULL) free(h->publisher);
  1415. X     if (h->school != NULL) free(h->school);
  1416. X     if (h->series != NULL) free(h->series);
  1417. X     if (h->title != NULL) free(h->title);
  1418. X     if (h->type != NULL) free(h->type);
  1419. X     if (h->volume != NULL) free(h->volume);
  1420. X     if (h->year != NULL) free(h->year);
  1421. X     if (h->category != NULL) free(h->category);
  1422. X     if (h->ufield != NULL) dbtDeleteAllUserFld(&h->ufield); 
  1423. X     free(h); 
  1424. X     *card = NULL;
  1425. X     return DBT_OK;
  1426. X   }
  1427. X   return DBT_OK;
  1428. }
  1429. X
  1430. X
  1431. X
  1432. X
  1433. /*********************************************************************/
  1434. /* Errcode dbtDeleteTree(int treeIdx):                               */
  1435. /* Speicherplatz von einem Baum freigeben.                           */
  1436. /*********************************************************************/
  1437. Errcode dbtDeleteTree(int treeIdx) 
  1438. {
  1439. X Errcode erg;
  1440. X
  1441. X if (TreeRoots[treeIdx] == (AvlNode *)1) {
  1442. X   TreeRoots[treeIdx] = 0;
  1443. X   return DBT_OK;
  1444. X }
  1445. X erg = DeleteTree(TreeRoots[treeIdx]);
  1446. X if (erg == DBT_OK) TreeRoots[treeIdx] = 0;
  1447. X return erg;
  1448. }
  1449. X                              
  1450. X
  1451. /*********************************************************************/
  1452. /* Errcode DeleteTree(AvlNode *baum):                                */
  1453. /* Speicherplatz von einem Baum freigeben.                           */
  1454. /*********************************************************************/
  1455. Errcode DeleteTree(AvlNode *baum)
  1456. {
  1457. X  Errcode erg, ende;
  1458. X  CardData *tree;
  1459. X
  1460. X  if (baum) {  
  1461. X
  1462. X    tree = baum->data;
  1463. X    if (baum->left) {
  1464. X       if ((erg = DeleteTree(baum->left)) != DBT_OK) return erg; 
  1465. X    }
  1466. X    ende = dbtDeleteCard(&tree); 
  1467. X    if (ende != DBT_OK) { 
  1468. X       return ende;
  1469. X    } 
  1470. X    if (baum->right) {
  1471. X       if ((erg = DeleteTree(baum->right)) != DBT_OK) return erg; 
  1472. X    }
  1473. X    return DBT_OK;
  1474. X  }
  1475. X  return DBT_OK;
  1476. }
  1477. X
  1478. X
  1479. /*********************************************************************/
  1480. /* CHECK FUNCTIONS                                                   */
  1481. /*********************************************************************/
  1482. X
  1483. /*********************************************************************/
  1484. /* Errcode dbtTestCard(CardData *c):                                 */
  1485. /* prueft, ob die zwingenden Felder ausgefuellt sind.                */
  1486. /*********************************************************************/
  1487. Errcode 
  1488. dbtTestCard (CardData *c)
  1489. {
  1490. X if (c == NULL) return DBT_ENOCARD;
  1491. X switch (c->cardtype) {
  1492. X       case article:
  1493. X               if (StringPeteIsEmpty(c->author)) return DBT_EAUTHOR;
  1494. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  1495. X               if (StringPeteIsEmpty(c->journal)) return DBT_EJOURNAL;
  1496. X               if (StringPeteIsEmpty(c->year)) return DBT_EYEAR;
  1497. X               break;
  1498. X         case book:
  1499. X               if (StringPeteIsEmpty(c->author) &&
  1500. X                   StringPeteIsEmpty(c->editor)) return DBT_EAUTHOR_EDITOR;
  1501. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  1502. X               if (StringPeteIsEmpty(c->publisher)) return DBT_EPUBLISHER;
  1503. X               if (StringPeteIsEmpty(c->year)) return DBT_EYEAR;
  1504. X               break;
  1505. X         case booklet:
  1506. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  1507. X               break;
  1508. X         case conference:
  1509. X               if (StringPeteIsEmpty(c->author)) return DBT_EAUTHOR;
  1510. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  1511. X               if (StringPeteIsEmpty(c->booktitle)) return DBT_EBOOKTITLE;
  1512. X               if (StringPeteIsEmpty(c->year)) return DBT_EYEAR;
  1513. X               break;
  1514. X         case inbook:
  1515. X               if (StringPeteIsEmpty(c->author) &&
  1516. X                   StringPeteIsEmpty(c->editor)) return DBT_EAUTHOR_EDITOR;
  1517. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  1518. X               if (StringPeteIsEmpty(c->chapter) &&
  1519. X                   StringPeteIsEmpty(c->pages)) return DBT_ECHAPTER_PAGES;
  1520. SHAR_EOF
  1521. true || echo 'restore of db_tree.c failed'
  1522. fi
  1523. echo 'End of  part 11'
  1524. echo 'File db_tree.c is continued in part 12'
  1525. echo 12 > _shar_seq_.tmp
  1526. exit 0
  1527. -- 
  1528. Senior Systems Scientist        mail: dcmartin@msi.com
  1529. Molecular Simulations, Inc.        uucp: uunet!dcmartin
  1530. 796 North Pastoria Avenue        at&t: 408/522-9236
  1531. Sunnyvale, California 94086        fax: 408/732-0831
  1532.