home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume18 / bibview / part12 < prev    next >
Encoding:
Internet Message Format  |  1992-08-26  |  50.2 KB

  1. Path: uunet!paladin.american.edu!gatech!swrinde!mips!msi!dcmartin
  2. From: liebla@informatik.tu-muenchen.de (Armin Liebl)
  3. Newsgroups: comp.sources.x
  4. Subject: v18i110: bibview - BibTeX GUI, Part12/20
  5. Message-ID: <1992Aug27.161631.25781@msi.com>
  6. Date: 27 Aug 92 16:16:31 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: 1568
  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 110
  16. Archive-name: bibview/part12
  17.  
  18. #!/bin/sh
  19. # this is part.12 (part 12 of a multipart archive)
  20. # do not concatenate these parts, unpack them in order with /bin/sh
  21. # file db_tree.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" != 12; 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 db_tree.c'
  37. else
  38. echo 'x - continuing file db_tree.c'
  39. sed 's/^X//' << 'SHAR_EOF' >> 'db_tree.c' &&
  40. X               if (StringPeteIsEmpty(c->publisher)) return DBT_EPUBLISHER;
  41. X               if (StringPeteIsEmpty(c->year)) return DBT_EYEAR;
  42. X               break;
  43. X         case incollection:
  44. X               if (StringPeteIsEmpty(c->author)) return DBT_EAUTHOR;
  45. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  46. X               if (StringPeteIsEmpty(c->booktitle)) return DBT_EBOOKTITLE;
  47. X               if (StringPeteIsEmpty(c->publisher)) return DBT_EPUBLISHER;
  48. X               if (StringPeteIsEmpty(c->year)) return DBT_EYEAR;
  49. X               break;
  50. X         case inproceedings:
  51. X               if (StringPeteIsEmpty(c->author)) return DBT_EAUTHOR;
  52. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  53. X               if (StringPeteIsEmpty(c->booktitle)) return DBT_EBOOKTITLE;
  54. X               if (StringPeteIsEmpty(c->year)) return DBT_EYEAR;
  55. X               break;
  56. X         case manual:
  57. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  58. X               break;
  59. X         case mastersthesis:
  60. X               if (StringPeteIsEmpty(c->author)) return DBT_EAUTHOR;
  61. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  62. X               if (StringPeteIsEmpty(c->school)) return DBT_ESCHOOL;
  63. X               if (StringPeteIsEmpty(c->year)) return DBT_EYEAR;
  64. X               break;
  65. X         case misc:
  66. X               break;
  67. X         case phdthesis:
  68. X               if (StringPeteIsEmpty(c->author)) return DBT_EAUTHOR;
  69. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  70. X               if (StringPeteIsEmpty(c->school)) return DBT_ESCHOOL;
  71. X               if (StringPeteIsEmpty(c->year)) return DBT_EYEAR;
  72. X               break;
  73. X         case proceedings:
  74. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  75. X               if (StringPeteIsEmpty(c->year)) return DBT_EYEAR;
  76. X               break;
  77. X         case techreport:
  78. X               if (StringPeteIsEmpty(c->author)) return DBT_EAUTHOR;
  79. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  80. X               if (StringPeteIsEmpty(c->institution)) return DBT_EINSTITUTION;
  81. X               if (StringPeteIsEmpty(c->year)) return DBT_EYEAR;
  82. X               break;
  83. X         case unpublished:
  84. X               if (StringPeteIsEmpty(c->author)) return DBT_EAUTHOR;
  85. X               if (StringPeteIsEmpty(c->title)) return DBT_ETITLE;
  86. X               if (StringPeteIsEmpty(c->note)) return DBT_ENOTE;
  87. X               break;
  88. X    }
  89. X    return DBT_OK;
  90. }
  91. X
  92. X
  93. /*********************************************************************/
  94. /* checkCards:                                                       */
  95. /*    Descends tree and appends illegal cards to list                */
  96. /*********************************************************************/
  97. static Errcode
  98. checkCards (AvlNode *tree, CardListNode **list)
  99. {
  100. Errcode status;
  101. X
  102. X   if ((tree !=NULL) && (tree != (AvlNode *)1)) {                 
  103. X      if (tree->left) {
  104. X         if ((status = checkCards(tree->left, list)) != DBT_OK)
  105. X        return(status);
  106. X      }
  107. X
  108. X      if (dbtTestCard(tree->data) != DBT_OK) { 
  109. X         if ((status = CardListAppend(list, tree->data)) != DBT_OK)
  110. X        return(status);
  111. X      }
  112. X
  113. X      if (tree->right) { 
  114. X         if ((status = checkCards(tree->right, list)) != DBT_OK)
  115. X        return(status);
  116. X      }
  117. X   }
  118. X   return(DBT_OK);
  119. }
  120. X
  121. X
  122. /*********************************************************************/
  123. /* dbtCheckAllCards:                                                 */
  124. /*    Checks tree and returns list of illegal cards                  */
  125. /*********************************************************************/
  126. Errcode 
  127. dbtCheckAllCards (int treeIdx, CardListNode **list)
  128. {
  129. X   return(checkCards(TreeRoots[treeIdx], list));
  130. }
  131. X
  132. X
  133. X
  134. /*********************************************************************/
  135. /* AVL - TREE FUNCTIONS                                              */
  136. /*********************************************************************/
  137. X
  138. /*********************************************************************/
  139. /* Errcode CopyCard(CardData **c, CardData *c2):                        */
  140. /* Inhalt von c2 nach c kopieren                                     */
  141. /*********************************************************************/
  142. Errcode CopyCard(CardData **c, CardData *c2)
  143. {
  144. X  CardData *c1;
  145. X
  146. X  if (*c == NULL) dbtMakeCard(c);
  147. X  else {                  /* NEU: 16.02.92 */
  148. X    dbtDeleteCard(c); 
  149. X    dbtMakeCard(c);
  150. X  }
  151. X  c1 = *c;
  152. X  c1->cardtype = c2->cardtype;
  153. X  Scalloc(&c1->cardtypestr, c2->cardtypestr); 
  154. X  Scalloc(&c1->category, c2->category);
  155. X  Scalloc(&c1->key, c2->key);
  156. X  Scalloc(&c1->mainkey, c2->mainkey);  /* NEU */
  157. X  Scalloc(&c1->crossref, c2->crossref);  /* NEU */
  158. X  Scalloc(&c1->month, c2->month);
  159. X  Scalloc(&c1->note, c2->note);
  160. X  Scalloc(&c1->annote, c2->annote);
  161. X  Scalloc(&c1->title, c2->title);
  162. X  Scalloc(&c1->year, c2->year);
  163. X  dbtMakeAndCopyUserFld(&c1->ufield, c2->ufield);
  164. X  switch (c2->cardtype) {
  165. X        case article:
  166. X               Scalloc(&c1->author, c2->author);
  167. X               Scalloc(&c1->journal, c2->journal);
  168. X               Scalloc(&c1->volume, c2->volume);
  169. X               Scalloc(&c1->number, c2->number);
  170. X               Scalloc(&c1->pages, c2->pages);
  171. X               break;
  172. X         case book:
  173. X               Scalloc(&c1->author, c2->author);
  174. X               Scalloc(&c1->editor, c2->editor);
  175. X               Scalloc(&c1->publisher, c2->publisher);
  176. X               Scalloc(&c1->volume, c2->volume);
  177. X               Scalloc(&c1->series, c2->series);
  178. X               Scalloc(&c1->address, c2->address);
  179. X               Scalloc(&c1->edition, c2->edition);
  180. X               break;
  181. X          case booklet:
  182. X               Scalloc(&c1->author, c2->author);
  183. X               Scalloc(&c1->howpublished, c2->howpublished);
  184. X               Scalloc(&c1->address, c2->address);
  185. X               break;
  186. X          case conference:
  187. X               Scalloc(&c1->author, c2->author);
  188. X               Scalloc(&c1->booktitle, c2->booktitle);
  189. X               Scalloc(&c1->editor, c2->editor);
  190. X               Scalloc(&c1->pages, c2->pages);
  191. X               Scalloc(&c1->organization, c2->organization);
  192. X               Scalloc(&c1->publisher, c2->publisher);
  193. X               Scalloc(&c1->address, c2->address);
  194. X               break;
  195. X          case inbook:
  196. X               Scalloc(&c1->author, c2->author);
  197. X               Scalloc(&c1->editor, c2->editor);
  198. X               Scalloc(&c1->chapter, c2->chapter);
  199. X               Scalloc(&c1->pages, c2->pages);
  200. X               Scalloc(&c1->publisher, c2->publisher);
  201. X               Scalloc(&c1->volume, c2->volume);
  202. X               Scalloc(&c1->series, c2->series);
  203. X               Scalloc(&c1->address, c2->address);
  204. X               Scalloc(&c1->edition, c2->edition);
  205. X               break;
  206. X          case incollection:
  207. X               Scalloc(&c1->author, c2->author);
  208. X               Scalloc(&c1->booktitle, c2->booktitle);
  209. X               Scalloc(&c1->publisher, c2->publisher);
  210. X               Scalloc(&c1->editor, c2->editor);
  211. X               Scalloc(&c1->chapter, c2->chapter);
  212. X               Scalloc(&c1->pages, c2->pages);
  213. X               Scalloc(&c1->address, c2->address);
  214. X               break;
  215. X          case inproceedings:
  216. X               Scalloc(&c1->author, c2->author);
  217. X               Scalloc(&c1->booktitle, c2->booktitle);
  218. X               Scalloc(&c1->editor, c2->editor);
  219. X               Scalloc(&c1->pages, c2->pages);
  220. X               Scalloc(&c1->organization, c2->organization);
  221. X               Scalloc(&c1->publisher, c2->publisher);
  222. X               Scalloc(&c1->address, c2->address);
  223. X               break;
  224. X          case manual:
  225. X               Scalloc(&c1->author, c2->author);
  226. X               Scalloc(&c1->organization, c2->organization);
  227. X               Scalloc(&c1->address, c2->address);
  228. X               Scalloc(&c1->edition, c2->edition);
  229. X               break;
  230. X          case mastersthesis:
  231. X               Scalloc(&c1->author, c2->author);
  232. X               Scalloc(&c1->school, c2->school);
  233. X               Scalloc(&c1->address, c2->address);
  234. X               break;
  235. X          case misc:
  236. X               Scalloc(&c1->author, c2->author);
  237. X               Scalloc(&c1->howpublished, c2->howpublished);
  238. X               break;
  239. X          case phdthesis:
  240. X               Scalloc(&c1->author, c2->author);
  241. X               Scalloc(&c1->school, c2->school);
  242. X               Scalloc(&c1->address, c2->address);
  243. X               break;
  244. X          case proceedings:
  245. X               Scalloc(&c1->editor, c2->editor);
  246. X               Scalloc(&c1->publisher, c2->publisher);
  247. X               Scalloc(&c1->organization, c2->organization);
  248. X               Scalloc(&c1->address, c2->address);
  249. X               break;
  250. X          case techreport:
  251. X               Scalloc(&c1->author, c2->author);
  252. X               Scalloc(&c1->institution, c2->institution);
  253. X               Scalloc(&c1->type, c2->type);
  254. X               Scalloc(&c1->number, c2->number);
  255. X               Scalloc(&c1->address, c2->address);
  256. X               break;
  257. X          case unpublished:
  258. X               Scalloc(&c1->author, c2->author);
  259. X               break;
  260. X  };
  261. X  return DBT_OK;
  262. }
  263. X            
  264. X
  265. /*********************************************************************/
  266. /* int KeyCompare(char *s1, char *s2):                               */
  267. /* Die Strings s1 und s2 werden verglichen                           */
  268. /*********************************************************************/
  269. X
  270. int KeyCompare(char *s1, char *s2)
  271. {
  272. X int erg;
  273. X
  274. X erg = strcmp(s1, s2);
  275. X if (erg > 0) return KEY_GREATER;
  276. X if (erg < 0) return KEY_LESS;
  277. X return KEY_EQUAL;
  278. }
  279. X
  280. X
  281. X
  282. /*********************************************************************/
  283. /*Errcode Insert(int treeIdx, AvlNode **tree, CardData *card, int *h)*/
  284. /* card wird in tree eingefuegt                                      */
  285. /*********************************************************************/
  286. Errcode Insert(int treeIdx, AvlNode **tree, CardData *card, int *h)
  287. {
  288. X  CardData *helpcard;
  289. X  AvlNode *hnode1, *hnode2, *htree;
  290. X
  291. X  htree = *tree;
  292. X  if ( htree == NULL || htree == (AvlNode *)1) {
  293. X    htree = (AvlNode *)calloc(1,sizeof(AvlNode));
  294. X    if (htree == NULL) return DBT_ECALLOC; 
  295. X    *h = TREE_BIGGER;
  296. X    htree->balance = TREES_EQUAL;
  297. X    htree->left = NULL;
  298. X    htree->right = NULL;
  299. X    htree->data = NULL;
  300. X    /* KEY generieren */
  301. X    if (StringPeteIsEmpty(card->mainkey) == 1) {
  302. X      if (card->mainkey != NULL) free(card->mainkey);
  303. X      if (StringPeteIsEmpty(card->key) == 0) {
  304. X        Scalloc(&card->mainkey, card->key);  
  305. X      }
  306. X      else {
  307. X        card->mainkey = (String)calloc(1,25);
  308. X        if (StringPeteIsEmpty(card->title) == 1) {
  309. X          if (StringPeteIsEmpty(card->author) == 0) {
  310. X            strncpy(card->key, card->author, 20);
  311. X          }
  312. X          strcpy(card->mainkey, "UNKNOWN");
  313. X        }
  314. X        else {
  315. X              strncpy(card->mainkey, card->title, 20);
  316. X        }
  317. X        strcat(card->mainkey, ":");
  318. X        if (StringPeteIsEmpty(card->year) == 0) strcat(card->mainkey, card->year);
  319. X        StrToLower(card->mainkey);
  320. X      }
  321. X    }
  322. X
  323. X
  324. X    CopyCard(&htree->data, card); 
  325. X    if(TreeRoots[treeIdx] == NULL || TreeRoots[treeIdx] == (AvlNode *)1) {
  326. X        TreeRoots[treeIdx] = htree;
  327. X    }
  328. X    *tree = htree;
  329. X  }
  330. X  else {
  331. X    helpcard = htree->data; 
  332. X    switch (KeyCompare(card->mainkey, helpcard->mainkey)) {
  333. X      case KEY_LESS:
  334. X          Insert(treeIdx, &htree->left, card, h);
  335. X          if (*h == TREE_BIGGER) {
  336. X            switch(htree->balance) {
  337. X               case RIGHT_TREE_GREATER:
  338. X                  htree->balance = TREES_EQUAL;
  339. X                  *h = TREE_LIKE_BEFORE;
  340. X                  break;
  341. X               case TREES_EQUAL:
  342. X                  htree->balance = LEFT_TREE_GREATER;
  343. X                  break;
  344. X               case LEFT_TREE_GREATER:
  345. X                  hnode1 = htree->left;
  346. X                  if (hnode1->balance == LEFT_TREE_GREATER) {
  347. X                    htree->left = hnode1->right;
  348. X                    hnode1->right = htree;
  349. X                    htree->balance = TREES_EQUAL;
  350. X                    *tree = htree = hnode1;
  351. X                  }
  352. X                  else {
  353. X                    hnode2 = hnode1->right;
  354. X                    hnode1->right = hnode2->left;
  355. X                    hnode2->left = hnode1;
  356. X                    htree->left = hnode2->right;
  357. X                    hnode2->right = htree;
  358. X                    if (hnode2->balance == LEFT_TREE_GREATER)
  359. X                      htree->balance = RIGHT_TREE_GREATER;
  360. X                    else
  361. X                      htree->balance = TREES_EQUAL;
  362. X                    if (hnode2->balance == RIGHT_TREE_GREATER)
  363. X                      hnode1->balance = LEFT_TREE_GREATER;
  364. X                    else
  365. X                      hnode1->balance = TREES_EQUAL;
  366. X                    *tree = htree = hnode2;
  367. X                  }
  368. X                  htree->balance = TREES_EQUAL;
  369. X                  *h = TREE_LIKE_BEFORE;
  370. X                  break;
  371. X           }
  372. X        }
  373. X        break;
  374. X        case KEY_GREATER:
  375. X          Insert(treeIdx, &htree->right, card, h);
  376. X          if (*h == TREE_BIGGER) {
  377. X            switch(htree->balance) {
  378. X               case LEFT_TREE_GREATER:
  379. X                  htree->balance = TREES_EQUAL;
  380. X                  *h = TREE_LIKE_BEFORE;
  381. X                  break;
  382. X               case TREES_EQUAL:
  383. X                  htree->balance = RIGHT_TREE_GREATER;
  384. X                  break;
  385. X               case RIGHT_TREE_GREATER:
  386. X                  hnode1 = htree->right;
  387. X                  if (hnode1->balance == RIGHT_TREE_GREATER) {
  388. X                    htree->right = hnode1->left;
  389. X                    hnode1->left = htree;
  390. X                    htree->balance = TREES_EQUAL;
  391. X                    *tree = htree = hnode1;
  392. X                  }
  393. X                  else {
  394. X                    hnode2 = hnode1->left;
  395. X                    hnode1->left = hnode2->right;
  396. X                    hnode2->right = hnode1;
  397. X                    htree->right = hnode2->left;
  398. X                    hnode2->left = htree;
  399. X                    if (hnode2->balance == RIGHT_TREE_GREATER)
  400. X                      htree->balance = LEFT_TREE_GREATER;
  401. X                    else
  402. X                      htree->balance = TREES_EQUAL;
  403. X                    if (hnode2->balance == LEFT_TREE_GREATER)
  404. X                      hnode1->balance = RIGHT_TREE_GREATER;
  405. X                    else
  406. X                      hnode1->balance = TREES_EQUAL;
  407. X                    *tree = htree = hnode2;
  408. X                  }
  409. X                  htree->balance = TREES_EQUAL;
  410. X                  *h = TREE_LIKE_BEFORE;
  411. X            }
  412. X          }
  413. X          break;
  414. X          case KEY_EQUAL:
  415. X              *h = TREE_LIKE_BEFORE;
  416. X          return DBT_EDUPKEY;
  417. X              break;
  418. X
  419. X    }
  420. X
  421. X  }
  422. X  return DBT_OK;
  423. }
  424. X
  425. X
  426. X
  427. /*********************************************************************/
  428. /* Errcode dbtInsert(int treeIdx, CardData *card):                   */
  429. /* card wird in den AVL-Baum mit dem Index treeIdx eingefuegt        */
  430. /*********************************************************************/
  431. X
  432. Errcode dbtInsert(int treeIdx, CardData *card)
  433. {
  434. X  int h;
  435. X  Errcode erg;
  436. X
  437. X  erg = Insert(treeIdx, &TreeRoots[treeIdx], card, &h);
  438. X  return erg;
  439. X  
  440. }
  441. X
  442. X
  443. /*********************************************************************/
  444. /* Errcode BalanceLeft(int treeIdx, AvlNode **tree, int *h):         */
  445. /* Falls der linke Teilbaum seine Hoehe veraendert hat, wird er neu  */
  446. /* balanciert                                                        */
  447. /*********************************************************************/
  448. X
  449. Errcode BalanceLeft(int treeIdx, AvlNode **tree, int *h)
  450. {
  451. X   AvlNode *hnode1, *hnode2, *htree;
  452. X   int b1, b2;
  453. X
  454. X   htree = *tree;
  455. X   switch (htree->balance) {
  456. X      case  LEFT_TREE_GREATER:
  457. X         htree->balance = TREES_EQUAL;
  458. X         break;
  459. X      case TREES_EQUAL:
  460. X         htree->balance = RIGHT_TREE_GREATER;
  461. X         *h = TREE_LIKE_BEFORE;
  462. X         break;
  463. X      case RIGHT_TREE_GREATER:
  464. X         hnode1 = htree->right;
  465. X         b1 = hnode1->balance;
  466. X         if (b1 != LEFT_TREE_GREATER) {
  467. X           htree->right = hnode1->left;
  468. X           hnode1->left = htree;
  469. X           if (b1 == TREES_EQUAL) {
  470. X             htree->balance = RIGHT_TREE_GREATER;
  471. X             hnode1->balance = LEFT_TREE_GREATER;
  472. X             *h = TREE_LIKE_BEFORE;
  473. X           }
  474. X           else {
  475. X             htree->balance = TREES_EQUAL;
  476. X             hnode1->balance = TREES_EQUAL;
  477. X           }
  478. X           htree = hnode1;   /* NEU: 16.02.92 */
  479. X         }
  480. X         else {
  481. X           hnode2 = hnode1->left;
  482. X           b2 = hnode2->balance;
  483. X           hnode1->left = hnode2->right;
  484. X           hnode2->left = htree;
  485. X           if (b2 == RIGHT_TREE_GREATER) htree->balance = LEFT_TREE_GREATER;
  486. X           else htree->balance = TREES_EQUAL;
  487. X           if (b2 == LEFT_TREE_GREATER) hnode1->balance = RIGHT_TREE_GREATER;
  488. X           else hnode1->balance = TREES_EQUAL;
  489. X           htree = hnode2;
  490. X           hnode2->balance = TREES_EQUAL;
  491. X        }
  492. X      }
  493. X      if (*tree == TreeRoots[treeIdx])
  494. X     TreeRoots[treeIdx] = htree; 
  495. X      *tree = htree;   /* NEU: 16.02.92 */
  496. X      return DBT_OK;
  497. }
  498. X
  499. X
  500. X
  501. X
  502. /*********************************************************************/
  503. /* Errcode BalanceRight(int treeIdx, AvlNode **tree, int *h):        */
  504. /* Falls der rechte Teilbaum seine Hoehe veraendert hat, wird er neu */
  505. /* balanciert                                                        */
  506. /*********************************************************************/
  507. X
  508. Errcode BalanceRight(int treeIdx, AvlNode **tree, int *h)
  509. {
  510. X   AvlNode *hnode1, *hnode2, *htree;
  511. X   int b1, b2;
  512. X
  513. X   htree = *tree;
  514. X   switch (htree->balance) {
  515. X      case RIGHT_TREE_GREATER:
  516. X            htree->balance = TREES_EQUAL;
  517. X            break;
  518. X      case TREES_EQUAL:
  519. X            htree->balance = LEFT_TREE_GREATER;
  520. X            *h = TREE_LIKE_BEFORE;
  521. X            break;
  522. X      case LEFT_TREE_GREATER:
  523. X            hnode1 = htree->left;
  524. X            b1 = hnode1->balance;
  525. X            if (b1 != RIGHT_TREE_GREATER) { 
  526. X              htree->left = hnode1->right;
  527. X              hnode1->right = htree;
  528. X              if (b1 == TREES_EQUAL) {
  529. X                htree->balance = LEFT_TREE_GREATER;
  530. X                hnode1->balance = RIGHT_TREE_GREATER;
  531. X                *h = TREE_LIKE_BEFORE;
  532. X              }
  533. X              else {
  534. X                htree->balance = TREES_EQUAL;
  535. X                hnode1->balance = TREES_EQUAL;
  536. X              }
  537. X              htree = hnode1;   /* NEU: 16.02.92 */
  538. X            }
  539. X            else {
  540. X              hnode2 = hnode1->right;
  541. X              b2 = hnode2->balance;
  542. X              hnode1->right = hnode2->left;
  543. X              hnode2->left = hnode1;
  544. X              htree->left = hnode2->right;
  545. X              hnode2->right = htree;
  546. X              if (b2 == LEFT_TREE_GREATER) htree->balance = RIGHT_TREE_GREATER;
  547. X              else htree->balance = TREES_EQUAL;
  548. X              if (b2 == RIGHT_TREE_GREATER) hnode1->balance = LEFT_TREE_GREATER;
  549. X              else hnode1->balance = TREES_EQUAL;
  550. X              htree = hnode2;
  551. X              hnode2->balance = TREES_EQUAL;
  552. X            }
  553. X       }
  554. X      if (*tree == TreeRoots[treeIdx])
  555. X     TreeRoots[treeIdx] = htree; 
  556. X       *tree = htree;   /* NEU: 16.02.92 */
  557. X       return DBT_OK;
  558. }
  559. X
  560. X    
  561. X
  562. /*********************************************************************/
  563. /* Errcode Del(AvlNode **tree, AvlNode **delnode, int *h):           */
  564. /* Hilfsfunktion fuer Delete                                         */
  565. /*********************************************************************/
  566. X
  567. Errcode Del(AvlNode **tree, AvlNode **delnode, int *h)
  568. {
  569. X  CardData *hc1, *hc2;
  570. X  AvlNode *hnode1, *hnode2;
  571. X  Errcode erg;
  572. X
  573. X  hnode1 = *tree;
  574. X  hnode2 = *delnode;
  575. X   hc1 = hnode1->data;
  576. /*  hc2 = hnode2->data; */
  577. X  if (hnode1->right != NULL) {
  578. X    erg = Del(&hnode1->right, delnode, h);
  579. X    if (erg!=DBT_OK)
  580. X       return(erg);
  581. /*    if (*h == TREE_SMALLER) BalanceRight(tree, h); */
  582. X  }
  583. X  else {
  584. X
  585. X    erg = CopyCard(&hnode2->data, hc1);
  586. X
  587. X    if (erg!=DBT_OK)
  588. X       return(erg);
  589. /*
  590. X    *delnode = *tree;       NEU:16.02.92 
  591. */
  592. X    dbtDeleteCard(&hc1);
  593. X    *tree = hnode1->left;
  594. X    free(hnode1);
  595. X    *h = TREE_SMALLER;
  596. X  }
  597. X  return DBT_OK;
  598. }
  599. X
  600. X
  601. /*********************************************************************/
  602. /*Errcode Delete(int treeIdx, AvlNode **tree, CardData *card, int *h)*/
  603. /* card wird, falls vorhanden aus tree geloescht                     */
  604. /*********************************************************************/
  605. Errcode Delete(int treeIdx, AvlNode **tree, CardData *card, int *h)
  606. {
  607. X  CardData *helpcard;
  608. X  AvlNode  *htree;
  609. X
  610. X  if ( *tree == NULL) {
  611. X    *h = TREE_LIKE_BEFORE;
  612. X  }
  613. X  else {
  614. X    htree = *tree;
  615. X    helpcard = htree->data;
  616. X    
  617. X    switch (KeyCompare(card->mainkey, helpcard->mainkey)) {
  618. X      case KEY_LESS:
  619. X            Delete(treeIdx, &htree->left, card, h);
  620. X            if (*h == TREE_SMALLER) BalanceLeft(treeIdx, tree, h);
  621. X            break;
  622. X      case KEY_GREATER:
  623. X            Delete(treeIdx, &htree->right, card, h);
  624. X            if (*h == TREE_SMALLER) BalanceRight(treeIdx, tree, h);
  625. X            break;
  626. X      case KEY_EQUAL:
  627. X            if (htree->right == NULL) {
  628. X              if (htree == TreeRoots[treeIdx])
  629. X         TreeRoots[treeIdx] = htree->left; 
  630. X              *tree = htree->left;
  631. X              dbtDeleteCard(&helpcard);
  632. X          free(htree);
  633. X              *h = TREE_SMALLER;
  634. X            } 
  635. X            else if (htree->left == NULL) {
  636. X              if (htree == TreeRoots[treeIdx])
  637. X         TreeRoots[treeIdx] = htree->right; 
  638. X              *tree = htree->right;
  639. X              dbtDeleteCard(&helpcard);
  640. X          free(htree);
  641. X              *h = TREE_SMALLER;
  642. X            }
  643. X            else {
  644. X              Del(&htree->left, &htree, h);
  645. X              if (*h == TREE_SMALLER) BalanceLeft(treeIdx, tree, h);
  646. X            }
  647. /*
  648. X            dbtDeleteCard(&helpcard);
  649. X             htree = *tree;
  650. X             helpcard = htree->data;
  651. X            free(htree);  
  652. */ 
  653. X            break;
  654. X     }
  655. X  }
  656. X  return DBT_OK;
  657. }
  658. X
  659. X
  660. /*********************************************************************/
  661. /* Errcode dbtDelete(int treeIdx, CardData *card):                   */
  662. /* card wird aus dem AVL-Baum mit dem Index treeIdx geloescht        */
  663. /*********************************************************************/
  664. X
  665. Errcode dbtDelete(int treeIdx, CardData *card)
  666. {
  667. X  int h;
  668. X  Errcode err;
  669. X
  670. X  h = TREE_LIKE_BEFORE;  /* NEU: 15.02.92 */
  671. X  err = Delete(treeIdx, &TreeRoots[treeIdx], card, &h);
  672. X  return DBT_OK;   /* nur vorerst */
  673. }
  674. X
  675. X
  676. X
  677. /*********************************************************************/
  678. /* Errcode MakeRegCard(CardData *card, CardData *reg):               */
  679. /* Die einzelnen reg. Ausdruecke in card werden compiliert und in    */
  680. /* reg gespeichert                                                   */
  681. /*********************************************************************/
  682. X
  683. Errcode MakeRegCard(CardData *card, CardData *reg)
  684. {
  685. X int length;
  686. X char *endbuf, *erg;
  687. X
  688. if (card->address != NULL) {
  689. X  reg->address = (String)calloc(1,MAXREGSIZE);
  690. X  endbuf = reg->address + MAXREGSIZE + 1;
  691. X  erg = compile(card->address, reg->address, endbuf, '\0');
  692. X  if (erg == NULL) return DBT_ECOMP;
  693. X  length = erg - reg->address + 1; 
  694. X  erg = (char *)realloc(reg->address, length); 
  695. X  reg->address = erg;
  696. }
  697. X
  698. if (card->annote != NULL) {
  699. X  reg->annote = (String)calloc(1,MAXREGSIZE);
  700. X  endbuf = reg->annote + MAXREGSIZE + 1;
  701. X  erg = compile(card->annote, reg->annote, endbuf, '\0');
  702. X  if (erg == NULL) return DBT_ECOMP;
  703. X  length = erg - reg->annote + 1; 
  704. X  erg = (char *)realloc(reg->annote, length); 
  705. X  reg->annote = erg;
  706. }
  707. X
  708. if (card->author != NULL) {
  709. X  reg->author = (String)calloc(1,MAXREGSIZE);
  710. X  endbuf = reg->author + MAXREGSIZE + 1;
  711. X  erg = compile(card->author, reg->author, endbuf, '\0');
  712. X  if (erg == NULL) return DBT_ECOMP;
  713. X  length = erg - reg->author + 1; 
  714. X  erg = (char *)realloc(reg->author, length); 
  715. X  reg->author = erg;
  716. }
  717. X
  718. if (card->booktitle != NULL) {
  719. X  reg->booktitle = (String)calloc(1,MAXREGSIZE);
  720. X  endbuf = reg->booktitle + MAXREGSIZE + 1;
  721. X  erg = compile(card->booktitle, reg->booktitle, endbuf, '\0');
  722. X  if (erg == NULL) return DBT_ECOMP;
  723. X  length = erg - reg->booktitle + 1; 
  724. X  erg = (char *)realloc(reg->booktitle, length); 
  725. X  reg->booktitle = erg;
  726. }
  727. X
  728. if (card->category != NULL) {
  729. X  reg->category = (String)calloc(1,MAXREGSIZE);
  730. X  endbuf = reg->category + MAXREGSIZE + 1;
  731. X  erg = compile(card->category, reg->category, endbuf, '\0');
  732. X  if (erg == NULL) return DBT_ECOMP;
  733. X  length = erg - reg->category + 1; 
  734. X  erg = (char *)realloc(reg->category, length); 
  735. X  reg->category = erg;
  736. }
  737. X
  738. if (card->chapter != NULL) {
  739. X  reg->chapter = (String)calloc(1,MAXREGSIZE);
  740. X  endbuf = reg->chapter + MAXREGSIZE + 1;
  741. X  erg = compile(card->chapter, reg->chapter, endbuf, '\0');
  742. X  if (erg == NULL) return DBT_ECOMP;
  743. X  length = erg - reg->chapter + 1; 
  744. X  erg = (char *)realloc(reg->chapter, length); 
  745. X  reg->chapter = erg;
  746. }
  747. X
  748. if (card->edition != NULL) {
  749. X  reg->edition = (String)calloc(1,MAXREGSIZE);
  750. X  endbuf = reg->edition + MAXREGSIZE + 1;
  751. X  erg = compile(card->edition, reg->edition, endbuf, '\0');
  752. X  if (erg == NULL) return DBT_ECOMP;
  753. X  length = erg - reg->edition + 1; 
  754. X  erg = (char *)realloc(reg->edition, length); 
  755. X  reg->edition = erg;
  756. }
  757. X
  758. if (card->editor != NULL) {
  759. X  reg->editor = (String)calloc(1,MAXREGSIZE);
  760. X  endbuf = reg->editor + MAXREGSIZE + 1;
  761. X  erg = compile(card->editor, reg->editor, endbuf, '\0');
  762. X  if (erg == NULL) return DBT_ECOMP;
  763. X  length = erg - reg->editor + 1; 
  764. X  erg = (char *)realloc(reg->editor, length); 
  765. X  reg->editor = erg;
  766. }
  767. X
  768. if (card->howpublished != NULL) {
  769. X  reg->howpublished = (String)calloc(1,MAXREGSIZE);
  770. X  endbuf = reg->howpublished + MAXREGSIZE + 1;
  771. X  erg = compile(card->howpublished, reg->howpublished, endbuf, '\0');
  772. X  if (erg == NULL) return DBT_ECOMP;
  773. X  length = erg - reg->howpublished + 1; 
  774. X  erg = (char *)realloc(reg->howpublished, length); 
  775. X  reg->howpublished = erg;
  776. }
  777. X
  778. if (card->institution != NULL) {
  779. X  reg->institution = (String)calloc(1,MAXREGSIZE);
  780. X  endbuf = reg->institution + MAXREGSIZE + 1;
  781. X  erg = compile(card->institution, reg->institution, endbuf, '\0');
  782. X  if (erg == NULL) return DBT_ECOMP;
  783. X  length = erg - reg->institution + 1; 
  784. X  erg = (char *)realloc(reg->institution, length); 
  785. X  reg->institution = erg;
  786. }
  787. X
  788. if (card->journal != NULL) {
  789. X  reg->journal = (String)calloc(1,MAXREGSIZE);
  790. X  endbuf = reg->journal + MAXREGSIZE + 1;
  791. X  erg = compile(card->journal, reg->journal, endbuf, '\0');
  792. X  if (erg == NULL) return DBT_ECOMP;
  793. X  length = erg - reg->journal + 1; 
  794. X  erg = (char *)realloc(reg->journal, length); 
  795. X  reg->journal = erg;
  796. }
  797. X
  798. if (card->key != NULL) {
  799. X  reg->key = (String)calloc(1,MAXREGSIZE);
  800. X  endbuf = reg->key + MAXREGSIZE + 1;
  801. X  erg = compile(card->key, reg->key, endbuf, '\0');
  802. X  if (erg == NULL) return DBT_ECOMP;
  803. X  length = erg - reg->key + 1; 
  804. X  erg = (char *)realloc(reg->key, length); 
  805. X  reg->key = erg;
  806. }
  807. X
  808. if (card->month != NULL) {
  809. X  reg->month = (String)calloc(1,MAXREGSIZE);
  810. X  endbuf = reg->month + MAXREGSIZE + 1;
  811. X  erg = compile(card->month, reg->month, endbuf, '\0');
  812. X  if (erg == NULL) return DBT_ECOMP;
  813. X  length = erg - reg->month + 1; 
  814. X  erg = (char *)realloc(reg->month, length); 
  815. X  reg->month = erg;
  816. }
  817. X
  818. if (card->note != NULL) {
  819. X  reg->note = (String)calloc(1,MAXREGSIZE);
  820. X  endbuf = reg->note + MAXREGSIZE + 1;
  821. X  erg = compile(card->note, reg->note, endbuf, '\0');
  822. X  if (erg == NULL) return DBT_ECOMP;
  823. X  length = erg - reg->note + 1; 
  824. X  erg = (char *)realloc(reg->note, length); 
  825. X  reg->note = erg;
  826. }
  827. X
  828. if (card->number != NULL) {
  829. X  reg->number = (String)calloc(1,MAXREGSIZE);
  830. X  endbuf = reg->number + MAXREGSIZE + 1;
  831. X  erg = compile(card->number, reg->number, endbuf, '\0');
  832. X  if (erg == NULL) return DBT_ECOMP;
  833. X  length = erg - reg->number + 1; 
  834. X  erg = (char *)realloc(reg->number, length); 
  835. X  reg->number = erg;
  836. }
  837. X
  838. if (card->organization != NULL) {
  839. X  reg->organization = (String)calloc(1,MAXREGSIZE);
  840. X  endbuf = reg->organization + MAXREGSIZE + 1;
  841. X  erg = compile(card->organization, reg->organization, endbuf, '\0');
  842. X  if (erg == NULL) return DBT_ECOMP;
  843. X  length = erg - reg->organization + 1; 
  844. X  erg = (char *)realloc(reg->organization, length); 
  845. X  reg->organization = erg;
  846. }
  847. X
  848. if (card->pages != NULL) {
  849. X  reg->pages = (String)calloc(1,MAXREGSIZE);
  850. X  endbuf = reg->pages + MAXREGSIZE + 1;
  851. X  erg = compile(card->pages, reg->pages, endbuf, '\0');
  852. X  if (erg == NULL) return DBT_ECOMP;
  853. X  length = erg - reg->pages + 1; 
  854. X  erg = (char *)realloc(reg->pages, length); 
  855. X  reg->pages = erg;
  856. }
  857. X
  858. if (card->publisher != NULL) {
  859. X  reg->publisher = (String)calloc(1,MAXREGSIZE);
  860. X  endbuf = reg->publisher + MAXREGSIZE + 1;
  861. X  erg = compile(card->publisher, reg->publisher, endbuf, '\0');
  862. X  if (erg == NULL) return DBT_ECOMP;
  863. X  length = erg - reg->publisher + 1; 
  864. X  erg = (char *)realloc(reg->publisher, length); 
  865. X  reg->publisher = erg;
  866. }
  867. X
  868. if (card->school != NULL) {
  869. X  reg->school = (String)calloc(1,MAXREGSIZE);
  870. X  endbuf = reg->school + MAXREGSIZE + 1;
  871. X  erg = compile(card->school, reg->school, endbuf, '\0');
  872. X  if (erg == NULL) return DBT_ECOMP;
  873. X  length = erg - reg->school + 1; 
  874. X  erg = (char *)realloc(reg->school, length); 
  875. X  reg->school = erg;
  876. }
  877. X
  878. if (card->series != NULL) {
  879. X  reg->series = (String)calloc(1,MAXREGSIZE);
  880. X  endbuf = reg->series + MAXREGSIZE + 1;
  881. X  erg = compile(card->series, reg->series, endbuf, '\0');
  882. X  if (erg == NULL) return DBT_ECOMP;
  883. X  length = erg - reg->series + 1; 
  884. X  erg = (char *)realloc(reg->series, length); 
  885. X  reg->series = erg;
  886. }
  887. X
  888. if (card->title != NULL) {
  889. X  reg->title = (String)calloc(1,MAXREGSIZE);
  890. X  endbuf = reg->title + MAXREGSIZE + 1;
  891. X  erg = compile(card->title, reg->title, endbuf, '\0');
  892. X  if (erg == NULL) return DBT_ECOMP;
  893. X  length = erg - reg->title + 1; 
  894. X  erg = (char *)realloc(reg->title, length); 
  895. X  reg->title = erg;
  896. }
  897. X
  898. if (card->type != NULL) {
  899. X  reg->type = (String)calloc(1,MAXREGSIZE);
  900. X  endbuf = reg->type + MAXREGSIZE + 1;
  901. X  erg = compile(card->type, reg->type, endbuf, '\0');
  902. X  if (erg == NULL) return DBT_ECOMP;
  903. X  length = erg - reg->type + 1; 
  904. X  erg = (char *)realloc(reg->type, length); 
  905. X  reg->type = erg;
  906. }
  907. X
  908. if (card->volume != NULL) {
  909. X  reg->volume = (String)calloc(1,MAXREGSIZE);
  910. X  endbuf = reg->volume + MAXREGSIZE + 1;
  911. X  erg = compile(card->volume, reg->volume, endbuf, '\0');
  912. X  if (erg == NULL) return DBT_ECOMP;
  913. X  length = erg - reg->volume + 1; 
  914. X  erg = (char *)realloc(reg->volume, length); 
  915. X  reg->volume = erg;
  916. }
  917. X
  918. if (card->year != NULL) {
  919. X  reg->year = (String)calloc(1,MAXREGSIZE);
  920. X  endbuf = reg->year + MAXREGSIZE + 1;
  921. X  erg = compile(card->year, reg->year, endbuf, '\0');
  922. X  if (erg == NULL) return DBT_ECOMP;
  923. X  length = erg - reg->year + 1; 
  924. X  erg = (char *)realloc(reg->year, length); 
  925. X  reg->year = erg;
  926. }
  927. X
  928. if (card->mainkey != NULL) {
  929. X  reg->mainkey = (String)calloc(1,MAXREGSIZE);
  930. X  endbuf = reg->mainkey + MAXREGSIZE + 1;
  931. X  erg = compile(card->mainkey, reg->mainkey, endbuf, '\0');
  932. X  if (erg == NULL) return DBT_ECOMP;
  933. X  length = erg - reg->mainkey + 1; 
  934. X  erg = (char *)realloc(reg->mainkey, length); 
  935. X  reg->mainkey = erg;
  936. }
  937. X
  938. if (card->crossref != NULL) {
  939. X  reg->crossref = (String)calloc(1,MAXREGSIZE);
  940. X  endbuf = reg->crossref + MAXREGSIZE + 1;
  941. X  erg = compile(card->crossref, reg->crossref, endbuf, '\0');
  942. X  if (erg == NULL) return DBT_ECOMP;
  943. X  length = erg - reg->crossref + 1; 
  944. X  erg = (char *)realloc(reg->crossref, length); 
  945. X  reg->crossref = erg;
  946. }
  947. X
  948. X return DBT_OK;
  949. }
  950. X
  951. X
  952. X
  953. X
  954. X
  955. /*********************************************************************/
  956. /* Errcode RegCompCard(CardData *card, CardData *reg):               */
  957. /* Die einzelnen Strings aus card werden mit den jeweiligen          */
  958. /* compilierten reg. Ausdruecken aus reg verglichen                  */
  959. /*********************************************************************/
  960. Errcode RegCompCard(CardData *card, CardData *reg)
  961. {
  962. X int flag, nbOfComp;
  963. X
  964. X flag = 1;
  965. X nbOfComp = 0;
  966. X if (flag  && reg->address) { 
  967. X   if (!card->address) return DBT_ENOMATCH;
  968. X   else {
  969. X     if (step(card->address, reg->address)) flag = 1; 
  970. X     else flag = 0;
  971. X     nbOfComp++;
  972. X   }
  973. X }
  974. X if (flag && reg->annote) {
  975. X   if (!card->annote) return DBT_ENOMATCH;
  976. X   else {
  977. X     if (step(card->annote, reg->annote)) flag = 1; 
  978. X     else flag = 0;
  979. X     nbOfComp++;
  980. X   }
  981. X }
  982. X if (flag && reg->author) {
  983. X   if (!card->author) return DBT_ENOMATCH;
  984. X   else {
  985. X     if (step(card->author, reg->author)) flag = 1; 
  986. X     else flag = 0;
  987. X     nbOfComp++;
  988. X   }
  989. X }
  990. X if (flag && reg->booktitle) {
  991. X   if (!card->booktitle) return DBT_ENOMATCH;
  992. X   else {
  993. X     if (step(card->booktitle, reg->booktitle)) flag = 1; 
  994. X     else flag = 0;
  995. X     nbOfComp++;
  996. X   }
  997. X }
  998. X if (flag && reg->category) {
  999. X   if (!card->category) return DBT_ENOMATCH;
  1000. X   else {
  1001. X     if (step(card->category, reg->category)) flag = 1; 
  1002. X     else flag = 0;
  1003. X     nbOfComp++;
  1004. X   }
  1005. X }
  1006. X if (flag && reg->chapter) {
  1007. X   if (!card->chapter) return DBT_ENOMATCH;
  1008. X   else {
  1009. X     if (step(card->chapter, reg->chapter)) flag = 1; 
  1010. X     else flag = 0;
  1011. X     nbOfComp++;
  1012. X   }
  1013. X }
  1014. X if (flag && reg->edition) {
  1015. X   if (!card->edition) return DBT_ENOMATCH;
  1016. X   else {
  1017. X     if (step(card->edition, reg->edition)) flag = 1; 
  1018. X     else flag = 0;
  1019. X     nbOfComp++;
  1020. X   }
  1021. X }
  1022. X if (flag && reg->editor) {
  1023. X   if (!card->editor) return DBT_ENOMATCH;
  1024. X   else {
  1025. X     if (step(card->editor, reg->editor)) flag = 1; 
  1026. X     else flag = 0;
  1027. X     nbOfComp++;
  1028. X   }
  1029. X }
  1030. X if (flag && card->howpublished && reg->howpublished) {
  1031. X   if (!card->howpublished) return DBT_ENOMATCH;
  1032. X   else {
  1033. X     if (step(card->howpublished, reg->howpublished)) flag = 1; 
  1034. X     else flag = 0;
  1035. X     nbOfComp++;
  1036. X   }
  1037. X }
  1038. X if (flag && reg->institution) {
  1039. X   if (!card->institution) return DBT_ENOMATCH;
  1040. X   else {
  1041. X     if (step(card->institution, reg->institution)) flag = 1; 
  1042. X     else flag = 0;
  1043. X     nbOfComp++;
  1044. X   }
  1045. X }
  1046. X if (flag && reg->journal) {
  1047. X   if (!card->journal) return DBT_ENOMATCH;
  1048. X   else {
  1049. X     if (step(card->journal, reg->journal)) flag = 1; 
  1050. X     else flag = 0;
  1051. X     nbOfComp++;
  1052. X   }
  1053. X }
  1054. X if (flag && reg->key) {
  1055. X   if (!card->key) return DBT_ENOMATCH;
  1056. X   else {
  1057. X     if (step(card->key, reg->key)) flag = 1; 
  1058. X     else flag = 0;
  1059. X     nbOfComp++;
  1060. X   }
  1061. X }
  1062. X if (flag && reg->month) {
  1063. X   if (!card->month) return DBT_ENOMATCH;
  1064. X   else {
  1065. X     if (step(card->month, reg->month)) flag = 1; 
  1066. X     else flag = 0;
  1067. X     nbOfComp++;
  1068. X   }
  1069. X }
  1070. X if (flag && reg->note) { 
  1071. X   if (!card->note) return DBT_ENOMATCH;
  1072. X   else {
  1073. X     if (step(card->note, reg->note)) flag = 1; 
  1074. X     else flag = 0;
  1075. X     nbOfComp++;
  1076. X   }
  1077. X }
  1078. X if (flag && reg->number) {
  1079. X   if (!card->number) return DBT_ENOMATCH;
  1080. X   else {
  1081. X     if (step(card->number, reg->number)) flag = 1; 
  1082. X     else flag = 0;
  1083. X     nbOfComp++;
  1084. X   }
  1085. X }
  1086. X if (flag && reg->organization) {
  1087. X   if (!card->organization) return DBT_ENOMATCH;
  1088. X   else {
  1089. X     if (step(card->organization, reg->organization)) flag = 1; 
  1090. X     else flag = 0;
  1091. X     nbOfComp++;
  1092. X   }
  1093. X }
  1094. X if (flag && reg->pages) { 
  1095. X   if (!card->pages) return DBT_ENOMATCH;
  1096. X   else {
  1097. X     if (step(card->pages, reg->pages)) flag = 1; 
  1098. X     else flag = 0;
  1099. X     nbOfComp++;
  1100. X   }
  1101. X }
  1102. X if (flag && reg->publisher) {
  1103. X   if (!card->publisher) return DBT_ENOMATCH;
  1104. X   else {
  1105. X     if (step(card->publisher, reg->publisher)) flag = 1; 
  1106. X     else flag = 0;
  1107. X     nbOfComp++;
  1108. X   }
  1109. X }
  1110. X if (flag && reg->school) {
  1111. X   if (!card->school) return DBT_ENOMATCH;
  1112. X   else {
  1113. X     if (step(card->school, reg->school)) flag = 1; 
  1114. X     else flag = 0;
  1115. X     nbOfComp++;
  1116. X   }
  1117. X }
  1118. X if (flag && reg->series) {
  1119. X   if (!card->series) return DBT_ENOMATCH;
  1120. X   else {
  1121. X     if (step(card->series, reg->series)) flag = 1; 
  1122. X     else flag = 0;
  1123. X     nbOfComp++;
  1124. X   }
  1125. X }
  1126. X if (flag && reg->title) { 
  1127. X   if (!card->title) return DBT_ENOMATCH;
  1128. X   else {
  1129. X     if (step(card->title, reg->title)) flag = 1; 
  1130. X     else flag = 0;
  1131. X     nbOfComp++;
  1132. X   }
  1133. X }
  1134. X if (flag && reg->type) {
  1135. X   if (!card->type) return DBT_ENOMATCH;
  1136. X   else {
  1137. X     if (step(card->type, reg->type)) flag = 1; 
  1138. X     else flag = 0;
  1139. X     nbOfComp++;
  1140. X   }
  1141. X }
  1142. X if (flag &®->volume) {
  1143. X   if (!card->volume) return DBT_ENOMATCH;
  1144. X   else {
  1145. X     if (step(card->volume, reg->volume)) flag = 1; 
  1146. X     else flag = 0;
  1147. X     nbOfComp++;
  1148. X   }
  1149. X }
  1150. X if (flag && reg->year) { 
  1151. X   if (!card->year) return DBT_ENOMATCH;
  1152. X   else {
  1153. X     if (step(card->year, reg->year)) {
  1154. X       flag = 1; 
  1155. X     }
  1156. X     else flag = 0;
  1157. X     nbOfComp++;
  1158. X   }
  1159. X }
  1160. X if (flag && reg->mainkey) {
  1161. X   if (!card->mainkey) return DBT_ENOMATCH;
  1162. X   else {
  1163. X     if (step(card->mainkey, reg->mainkey)) flag = 1; 
  1164. X     else flag = 0;
  1165. X     nbOfComp++;
  1166. X   }
  1167. X }
  1168. X if (flag && reg->crossref) { 
  1169. X   if (!card->crossref) return DBT_ENOMATCH;
  1170. X   else {
  1171. X     if (step(card->crossref, reg->crossref)) flag = 1; 
  1172. X     else flag = 0;
  1173. X     nbOfComp++;
  1174. X   }
  1175. X }
  1176. X if (flag == 1 && nbOfComp > 0) return DBT_OK;
  1177. X return DBT_ENOMATCH;
  1178. }
  1179. X
  1180. X
  1181. X
  1182. /*********************************************************************/
  1183. /* Errcode Search(AvlNode *tree, CardData **card, int *calls):       */
  1184. /* eine Karte mit bestimmten Schluessel suchen                       */
  1185. /*********************************************************************/
  1186. Errcode Search(AvlNode *tree, CardData **card, int *calls)
  1187. {
  1188. X  CardData *helpcard, *hcard;
  1189. X
  1190. X  helpcard = tree->data;
  1191. X  hcard = *card;
  1192. X  (*calls)++;
  1193. X  if(tree) {
  1194. X    switch(KeyCompare(hcard->mainkey,helpcard->mainkey)) {
  1195. X      case KEY_LESS:
  1196. X             Search(tree->left, card, calls);
  1197. X             break;
  1198. X      case KEY_GREATER:
  1199. X             Search(tree->right, card, calls);
  1200. X             break;
  1201. X      case KEY_EQUAL:
  1202. X             CopyCard(card, helpcard);
  1203. X             return DBT_OK;
  1204. X    }
  1205. X  }
  1206. X  else return 0;
  1207. }
  1208. X
  1209. X
  1210. X
  1211. /*********************************************************************/
  1212. /* Errcode dbtSearch(int treeIdx, CardData **card)                   */
  1213. /* eine Karte mit bestimmten Schluessel suchen                       */
  1214. /*********************************************************************/
  1215. Errcode dbtSearch(int treeIdx, CardData **card)
  1216. {
  1217. X  int calls;
  1218. X  Errcode erg;
  1219. X
  1220. X  calls = 0;
  1221. X  erg = Search(TreeRoots[treeIdx], card, &calls);
  1222. X  return erg;
  1223. X
  1224. X
  1225. X
  1226. /**************************************************************************/
  1227. /* Errcode dbtSearchList(int treeIdx, CardData *card, CardListNode **list)*/
  1228. /* die reg. Ausd. in card werden compiliert; jede Karte im Baum wird mit  */
  1229. /* dieser Karte verglichen und ggf. an list angefuegt.                    */ 
  1230. /**************************************************************************/
  1231. Errcode dbtSearchList(int treeIdx, CardData *card, CardListNode **list)
  1232. {
  1233. X  CardData *reg;
  1234. X  Errcode erg;
  1235. X
  1236. X  if (TreeRoots[treeIdx] == (AvlNode *)1) {
  1237. X    TreeRoots[treeIdx] = 0;
  1238. X    return DBT_OK;
  1239. X  }
  1240. X  if ((erg = dbtMakeCard(®)) != DBT_OK) return erg;  
  1241. X  if ((erg = MakeRegCard(card, reg)) != DBT_OK) return erg; 
  1242. X  erg = SearchList(TreeRoots[treeIdx], reg, list);
  1243. X  dbtDeleteCard(®);
  1244. X  return erg;
  1245. }
  1246. X
  1247. X
  1248. X
  1249. X
  1250. /**************************************************************************/
  1251. /* Errcode SearchList(AvlNode *baum, CardData *reg, CardListNode **list)  */
  1252. /* jede Karte im Baum wird mit reg verglichen und ggf. an list angefuegt. */
  1253. /**************************************************************************/
  1254. Errcode SearchList(AvlNode *baum, CardData *reg, CardListNode **list)
  1255. {
  1256. X  CardData *tree;
  1257. X
  1258. X  if (baum) {                 
  1259. X    tree = baum->data;
  1260. X    if (baum->left) {
  1261. X       SearchList(baum->left, reg, list); 
  1262. X    }
  1263. X    if (RegCompCard(tree, reg) == DBT_OK) { 
  1264. X      CardListAppend(list, tree); 
  1265. X    }
  1266. X    if (baum->right) {
  1267. X       SearchList(baum->right, reg, list);
  1268. X    }
  1269. X  }
  1270. X  return DBT_OK;
  1271. }
  1272. X
  1273. X
  1274. X
  1275. /**************************************************************************/
  1276. /* Errcode MakeCardListNode(CardListNode **list):                         */
  1277. /* neue Wurzel fuer Karten-Liste erstellen.                               */
  1278. /**************************************************************************/
  1279. X
  1280. Errcode MakeCardListNode(CardListNode **list)
  1281. {
  1282. X  CardListNode *hlist;
  1283. X
  1284. X  hlist = *list;
  1285. X  if ( hlist == NULL) {
  1286. X    hlist = (CardListNode *)calloc(1,sizeof(CardListNode));
  1287. X    if (hlist == NULL) return DBT_ECALLOC; 
  1288. X    hlist->next = NULL;
  1289. X    *list = hlist;
  1290. X    return DBT_OK; 
  1291. X  }
  1292. X  return DBT_OK; 
  1293. }
  1294. X
  1295. X
  1296. /**************************************************************************/
  1297. /* Errcode CardListAppend(CardListNode **list, CardData *card):           */
  1298. /* card an list anhaengen.                                                */
  1299. /**************************************************************************/
  1300. X
  1301. Errcode CardListAppend(CardListNode **list, CardData *card)
  1302. {
  1303. X  CardListNode *hlist, *anker;
  1304. X  Errcode erg;
  1305. X
  1306. X  hlist = *list;
  1307. X  anker = hlist;
  1308. X  if (hlist == NULL) {
  1309. X    erg = MakeCardListNode(&hlist);
  1310. X    CopyCard(&hlist->data, card);
  1311. X    *list = hlist; 
  1312. X    return erg;
  1313. X  }
  1314. X  else CardListAppend(&hlist->next, card);
  1315. X  return DBT_OK;
  1316. }
  1317. X
  1318. X
  1319. /**************************************************************************/
  1320. /* Errcode dbtCardListDelete(CardListNode **list):                        */
  1321. /* list wird geloescht.                                                   */
  1322. /**************************************************************************/
  1323. X
  1324. Errcode dbtCardListDelete(CardListNode **list) 
  1325. {
  1326. X Errcode erg;
  1327. X CardListNode *delList;
  1328. X
  1329. X delList = *list;
  1330. X if (delList != NULL) {
  1331. X   if ((erg = dbtCardListDelete(&delList->next)) != DBT_OK) return erg;
  1332. X }
  1333. X erg = dbtDeleteCard(&delList->data);
  1334. X free(delList);
  1335. X delList = NULL;
  1336. X *list = delList;
  1337. X return erg;
  1338. }                       
  1339. X
  1340. X
  1341. /*********************************************************************/
  1342. /* LINKED LIST FUNCTIONS                                             */
  1343. /*********************************************************************/
  1344. X
  1345. /*********************************************************************/
  1346. /* Errcode MakeListNode(ListNode **list):                            */
  1347. /* neue Wurzel fuer String-Liste erstellen.                          */
  1348. /*********************************************************************/
  1349. Errcode 
  1350. dbtMakeListNode (ListNode **list)
  1351. {
  1352. X  ListNode *hlist;
  1353. X
  1354. X  hlist = *list;
  1355. X  if ( hlist == NULL) {
  1356. X    hlist = (ListNode *)calloc(1,sizeof(ListNode));
  1357. X    if (hlist == NULL) return DBT_ECALLOC; 
  1358. X    hlist->next = NULL;
  1359. X    *list = hlist;
  1360. X    return DBT_OK; 
  1361. X  }
  1362. X  return DBT_OK; 
  1363. }
  1364. X
  1365. X
  1366. /*********************************************************************/
  1367. /* Errcode ListAppend(ListNode **list, String word):                 */
  1368. /* word an list anhaengen.                                           */
  1369. /*********************************************************************/
  1370. Errcode 
  1371. dbtListAppend (ListNode **list, String word)
  1372. {
  1373. X  ListNode *hlist;
  1374. X  Errcode erg;
  1375. X
  1376. X  hlist = *list;
  1377. X  if (hlist == NULL) {
  1378. X    erg = dbtMakeListNode(&hlist);
  1379. X    hlist->data = (String)calloc(1,strlen(word)+1);
  1380. X    strcpy(hlist->data, word);
  1381. X    *list = hlist; 
  1382. X    return erg;
  1383. X  }
  1384. X  else return(dbtListAppend(&hlist->next, word));
  1385. }
  1386. X
  1387. X
  1388. X
  1389. void AvlGoDown(AvlNode *baum, ListNode **list)
  1390. {
  1391. X  CardData *tree;
  1392. X
  1393. X  if (baum != NULL) {                 
  1394. X    tree = baum->data;
  1395. X    if (baum->left) {
  1396. X       AvlGoDown(baum->left, list); 
  1397. X    }
  1398. X    dbtListAppend(list, tree->mainkey); 
  1399. X    if (baum->right) {
  1400. X       AvlGoDown(baum->right, list);
  1401. X    }
  1402. X  }
  1403. }
  1404. X
  1405. SHAR_EOF
  1406. echo 'File db_tree.c is complete' &&
  1407. chmod 0644 db_tree.c ||
  1408. echo 'restore of db_tree.c failed'
  1409. Wc_c="`wc -c < 'db_tree.c'`"
  1410. test 57866 -eq "$Wc_c" ||
  1411.     echo 'db_tree.c: original size 57866, current size' "$Wc_c"
  1412. rm -f _shar_wnt_.tmp
  1413. fi
  1414. # ============= db_tree.h ==============
  1415. if test -f 'db_tree.h' -a X"$1" != X"-c"; then
  1416.     echo 'x - skipping db_tree.h (File already exists)'
  1417.     rm -f _shar_wnt_.tmp
  1418. else
  1419. > _shar_wnt_.tmp
  1420. echo 'x - extracting db_tree.h (Text)'
  1421. sed 's/^X//' << 'SHAR_EOF' > 'db_tree.h' &&
  1422. X
  1423. /****************************************************************
  1424. X *   db_tree.h                                                  *
  1425. X ****************************************************************/
  1426. X
  1427. #define KEY_EQUAL    0
  1428. #define KEY_GREATER  1
  1429. #define KEY_LESS    -1
  1430. X
  1431. #define LEFT_TREE_GREATER  -1
  1432. #define RIGHT_TREE_GREATER  1
  1433. #define TREES_EQUAL         0
  1434. X
  1435. #define TREE_BIGGER  1
  1436. #define TREE_SMALLER -1
  1437. #define TREE_LIKE_BEFORE 0
  1438. X
  1439. /*
  1440. X #define MAXTREEROOTS   256
  1441. */
  1442. #define MAXREGSIZE    5000
  1443. X
  1444. #define DBT_OK 1
  1445. #define DBT_ECALLOC      -1600
  1446. #define DBT_ECOMP        -1601
  1447. #define DBT_ENOMATCH     -1602
  1448. #define DBT_ENOCARD      -1603
  1449. #define DBT_EAUTHOR      -1604
  1450. #define DBT_ETITLE       -1605
  1451. #define DBT_EJOURNAL     -1606
  1452. #define DBT_EYEAR        -1607
  1453. #define DBT_EPUBLISHER   -1608
  1454. #define DBT_EBOOKTITLE   -1609 
  1455. #define DBT_ECHAPTER     -1610
  1456. #define DBT_ESCHOOL      -1611
  1457. #define DBT_EINSTITUTION -1612
  1458. #define DBT_ENOTE        -1613
  1459. #define DBT_ROOTSFULL    -1620
  1460. #define DBT_ENONODE      -1621
  1461. X
  1462. X
  1463. /*****************************************
  1464. X * Array mit Pointern auf versch. Baeume *
  1465. X *****************************************/
  1466. /*
  1467. X  AvlNode *TreeRoots[MAXTREEROOTS];     
  1468. */
  1469. X
  1470. /*********************
  1471. X * Lokale Funktionen *
  1472. X *********************/
  1473. Errcode Scalloc(String *s1, String s2);
  1474. void    CopyCard(CardData **c, CardData *c2);
  1475. int     KeyCompare(char *s1, char *s2);
  1476. Errcode Insert(int treeIdx, AvlNode **tree, CardData *card, int *h);
  1477. Errcode Search(AvlNode *tree, CardData **card, int *calls);
  1478. Errcode BalanceLeft(AvlNode **tree, int *h);
  1479. Errcode BalanceRight(AvlNode **tree, int *h);
  1480. Errcode Del(AvlNode **tree, AvlNode **delnode, int *h);
  1481. void    AvlGoDown(AvlNode *baum, ListNode **list);
  1482. Errcode MakeListNode(ListNode **list);
  1483. Errcode ListAppend(ListNode **list, String word);
  1484. Errcode MakeCardListNode(CardListNode **list);
  1485. Errcode CardListAppend(CardListNode **list, CardData *card);
  1486. Errcode SearchList(AvlNode *baum, CardData *reg, CardListNode **list);
  1487. Errcode RegCompCard(CardData *card, CardData *reg);
  1488. Errcode MakeRegCard(CardData *card, CardData *reg);
  1489. Errcode TestTree(AvlNode *baum, String *cardkey);
  1490. Errcode DeleteTree(AvlNode *baum);
  1491. static void StrToLower(char *text);
  1492. static int StringIsEmpty(char *text);
  1493. static int StringPeteIsEmpty(char *text);
  1494. SHAR_EOF
  1495. chmod 0644 db_tree.h ||
  1496. echo 'restore of db_tree.h failed'
  1497. Wc_c="`wc -c < 'db_tree.h'`"
  1498. test 2289 -eq "$Wc_c" ||
  1499.     echo 'db_tree.h: original size 2289, current size' "$Wc_c"
  1500. rm -f _shar_wnt_.tmp
  1501. fi
  1502. # ============= fb_res.h ==============
  1503. if test -f 'fb_res.h' -a X"$1" != X"-c"; then
  1504.     echo 'x - skipping fb_res.h (File already exists)'
  1505.     rm -f _shar_wnt_.tmp
  1506. else
  1507. > _shar_wnt_.tmp
  1508. echo 'x - extracting fb_res.h (Text)'
  1509. sed 's/^X//' << 'SHAR_EOF' > 'fb_res.h' &&
  1510. "BibView.title:        bibView",
  1511. "BibView.iconName:        bibView",
  1512. "BibView*font: *helvetica-bold-r-*-120-*",
  1513. "BibView*foreground:            Steelblue",
  1514. "BibView*commandBox*foreground:        SteelBlue",
  1515. "BibView*commandBox*borderColor:        Black",
  1516. "BibView*commandBox*menuLabel.foreground:    SlateBlue",
  1517. "BibView*SimpleMenu*foreground:        SteelBlue",
  1518. "BibView*SimpleMenu*line.foreground:    SlateGrey",
  1519. "BibView*mainwin.orientation:        vertical",
  1520. "BibView*mainwin.height:            175",
  1521. "BibView*mainwin.width:            500",
  1522. "BibView*mainwin*showGrip:        false",
  1523. "BibView*mainwin.commandBox.width:     500",
  1524. "BibView*mainwin.commandBox.vSpace:     0",
  1525. "BibView*mainwin.commandBox.hSpace:     0",
  1526. "BibView*mainwin.commandBox.min:     21",
  1527. "BibView*mainwin.desktop.label:",
  1528. "BibView*mainwin.desktop.width:       500",
  1529. "BibView*mainwin.desktop.height:        150",
  1530. "BibView*mainwin.desktop.min:        150",
  1531. "BibView*mainwin.desktop.fromVert:      commandBox",
  1532. "BibView*mainwin*file.label:        File",
  1533. "BibView*mainwin*file.menuName:        fileMenu",
  1534. "BibView*fileMenu.label:            File Menu",
  1535. "BibView*fileMenu*item1*label:        New",
  1536. "BibView*fileMenu*item2*label:        Open",
  1537. "BibView*fileMenu*item3*label:        Close",
  1538. "BibView*fileMenu*item4*label:        Save",
  1539. "BibView*fileMenu*item5*label:        Save as",
  1540. "BibView*fileMenu*quit*label:        Quit",
  1541. "BibView*mainwin*services.label:          Services",
  1542. "BibView*mainwin*services.menuName:    servicesMenu",
  1543. "BibView*servicesMenu.label:        Services Menu",
  1544. "BibView*servicesMenu*item1*label:    Consistency Check    ",
  1545. "BibView*servicesMenu*item2*label:    Unify",
  1546. "BibView*servicesMenu*item3*label:    Print",
  1547. "BibView*servicesMenu*item4*label:    Edit Macros",
  1548. "BibView*servicesMenu*item5*label:    Load Configuration",
  1549. "BibView*mainwin*options.label:           Options    ",
  1550. "BibView*mainwin*options.menuName:    optionsMenu",
  1551. "BibView*mainwin*options*leftMargin:     20",
  1552. "BibView*optionsMenu.label:        Options Menu",
  1553. "BibView*optionsMenu*item1*label:    Beep on Errors",
  1554. "BibView*optionsMenu*item2*label:    Backups  ",
  1555. "BibView*optionsMenu*item3*label:    Icons on Desktop  ",
  1556. "BibView*optionsMenu*item4*label:    Autom. Check",
  1557. "BibView*optionsMenu*item5*label:    Required Fields",
  1558. "BibView*mainwin*window.label:          Window",
  1559. "BibView*mainwin*window.menuName:    windowMenu",
  1560. "BibView*mainwin*window*leftMargin:     20",
  1561. "BibView*windowMenu.label:        Window Menu",
  1562. "BibView*windowMenu*item1*label:        Cascade",
  1563. "BibView*mainwin*help.label:          Help",
  1564. "BibView*mainwin*help.menuName:        helpMenu",
  1565. "BibView*helpMenu.label:            Help Menu",
  1566. "BibView*helpMenu*item1*label:        Survey",
  1567. "BibView*helpMenu*item2*label:        Main Window",
  1568. "BibView*helpMenu*item3*label:        Bibliography Window",
  1569. SHAR_EOF
  1570. true || echo 'restore of fb_res.h failed'
  1571. fi
  1572. echo 'End of  part 12'
  1573. echo 'File fb_res.h is continued in part 13'
  1574. echo 13 > _shar_seq_.tmp
  1575. exit 0
  1576. -- 
  1577. Senior Systems Scientist        mail: dcmartin@msi.com
  1578. Molecular Simulations, Inc.        uucp: uunet!dcmartin
  1579. 796 North Pastoria Avenue        at&t: 408/522-9236
  1580. Sunnyvale, California 94086        fax: 408/732-0831
  1581.