~ubuntu-branches/ubuntu/trusty/lifelines/trusty

« back to all changes in this revision

Viewing changes to src/gedlib/keytonod.c

  • Committer: Bazaar Package Importer
  • Author(s): Felipe Augusto van de Wiel (faw)
  • Date: 2007-08-14 00:02:04 UTC
  • mfrom: (1.1.4 upstream) (3.1.4 gutsy)
  • Revision ID: james.westby@ubuntu.com-20070814000204-mpv5faygl0dgq3qi
Tags: 3.0.61-1
* New upstream release. (Closes: #387856).
* Fixing documentation build problems also fixes FTBFS if built twice in a
  row. (Closes: #424543).
* Adding lynx as a build dependency. This is necessary to generate txt files
  from html, discovered while fixing #424543.
* Upstream fix: charset for gedcom file in unicode. (Closes: #396206).
* Upstream fim: updating documentation about desc-tex2. (Closes: #405501).
* Bumping Standards-Version to 3.7.2 without package changes.
* Dropping local debian patches added upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
        CACHEEL c_prev;   /* previous el */
59
59
        CACHEEL c_next;   /* next el */
60
60
        STRING c_key;     /* record key */
61
 
        INT c_lock;       /* locked? */
 
61
        INT c_lock;       /* lock count (includes report locks) */
 
62
        INT c_rptlock;    /* report lock count */
62
63
        RECORD c_record;
63
64
};
64
 
#define cnode(e) ((e)->c_node)
65
 
#define cprev(e) ((e)->c_prev)
66
 
#define cnext(e) ((e)->c_next)
67
 
#define ckey(e)  ((e)->c_key)
68
 
#define cclock(e) ((e)->c_lock)
69
 
#define crecord(e) ((e)->c_record)
 
65
#define cnode(e)      ((e)->c_node)
 
66
#define cprev(e)      ((e)->c_prev)
 
67
#define cnext(e)      ((e)->c_next)
 
68
#define ckey(e)       ((e)->c_key)
 
69
#define cclock(e)     ((e)->c_lock)
 
70
#define ccrptlock(e)  ((e)->c_rptlock)
 
71
#define crecord(e)    ((e)->c_record)
70
72
 
71
73
/*==============================
72
74
 * CACHE -- Internal cache type.
608
610
{
609
611
        CACHEEL prev = cprev(cel);
610
612
        CACHEEL next = cnext(cel);
611
 
        ASSERT(cache && cel);
 
613
        ASSERT(cache);
 
614
        ASSERT(cel);
612
615
        if (prev) cnext(prev) = next;
613
616
        if (next) cprev(next) = prev;
614
617
        if (!prev) cacfirstdir(cache) = next;
622
625
first_direct (CACHE cache, CACHEEL cel)
623
626
{
624
627
        CACHEEL frst = cacfirstdir(cache);
625
 
        ASSERT(cache && cel);
 
628
        ASSERT(cache);
 
629
        ASSERT(cel);
626
630
        cacsizedir(cache)++;
627
631
        cprev(cel) = NULL;
628
632
        cnext(cel) = frst;
636
640
static void
637
641
direct_to_first (CACHE cache, CACHEEL cel)
638
642
{
639
 
        ASSERT(cache && cel);
 
643
        ASSERT(cache);
 
644
        ASSERT(cel);
640
645
        if (cel == cacfirstdir(cache)) return;
641
646
        remove_direct(cache, cel);
642
647
        first_direct(cache, cel);
660
665
        RECORD rec=0;
661
666
        int i, j;
662
667
 
663
 
        ASSERT(cache && key);
 
668
        ASSERT(cache);
 
669
        ASSERT(key);
664
670
        rec = NULL;
665
671
        if ((rawrec = retrieve_raw_record(key, &len))) 
666
672
                /* 2003-11-22, we should use string_to_node here */
667
673
                rec = string_to_record(rawrec, key, len);
668
674
        if (!rec)
669
675
        {
 
676
                ZSTR zstr=zs_newn(256);
670
677
                if(listbadkeys) {
671
678
                        if(strlen(badkeylist) < 80 - strlen(key) - 2) {
672
679
                                if (badkeylist[0])
676
683
                        return(NULL);
677
684
                }
678
685
                if (reportmode) return(NULL);
679
 
                crashlog("key %s is not in database. Use \"btedit <database> <key>\" to fix.\n", (char *) key);
680
 
                crashlog("where <key> is probably one of the following:\n");
 
686
                crashlogn(_("Database error caused by reference to nonexisting key <%s>."), (char *)key);
 
687
                crashlogn(_("It might be possible to fix this with btedit."));
 
688
                zs_sets(zstr, _("Neighboring keys include:"));
681
689
                for(i = 0; i < 10; i++)
682
690
                {
683
691
                        j = keyidx + i;
684
692
                        if(j >= 10) j -= 10;
685
 
                        if (keybuf[j][0])
686
 
                                crashlog(" %s", (char *)keybuf[j]);
 
693
                        if (keybuf[j][0]) {
 
694
                                zs_appc(zstr, ' ');
 
695
                                zs_apps(zstr, keybuf[j]);
 
696
                        }
687
697
                }
688
 
                crashlog("\n");
 
698
                crashlogn(zs_str(zstr));
 
699
                zs_free(&zstr);
689
700
                /* deliberately fall through to let ASSERT(rec) fail */
690
701
        }
691
702
        ASSERT(rec);
740
751
key_typed_to_node (CACHE cache, CNSTRING key, STRING tag)
741
752
{
742
753
        CACHEEL cel;
743
 
        ASSERT(cache && key);
 
754
        ASSERT(cache);
 
755
        ASSERT(key);
744
756
        if (!(cel = key_to_cacheel(cache, key, tag, FALSE)))
745
757
                return NULL;
746
758
        return cnode(cel);
754
766
key_typed_to_record (CACHE cache, CNSTRING key, STRING tag)
755
767
{
756
768
        CACHEEL cel;
757
 
        ASSERT(cache && key);
 
769
        ASSERT(cache);
 
770
        ASSERT(key);
758
771
        if (!(cel = key_to_cacheel(cache, key, tag, FALSE)))
759
772
                return NULL;
760
773
        return get_record_for_cel(cel);
817
830
        CACHEEL cel=0;
818
831
        RECORD rec=0;
819
832
 
820
 
        ASSERT(cache && key);
 
833
        ASSERT(cache);
 
834
        ASSERT(key);
821
835
        if (!(cel = key_to_cacheel(cache, key, tag, TRUE)))
822
836
                return NULL;
823
837
        rec = get_record_for_cel(cel);
830
844
lock_cache (CACHEEL cel)
831
845
{
832
846
        ASSERT(cnode(cel)); /* must be in direct */
833
 
        cclock(cel)++;
834
 
        ASSERT(cclock(cel)>0);
 
847
        ++cclock(cel);
 
848
        ASSERT(cclock(cel)>0);
 
849
}
 
850
/*======================================
 
851
 * lockrpt_cache -- Lock CACHEEL into direct cache (for report program)
 
852
 *====================================*/
 
853
void
 
854
lockrpt_cache (CACHEEL cel)
 
855
{
 
856
        ASSERT(cnode(cel)); /* must be in direct */
 
857
        /* put real lock on to actually lock it */
 
858
        ++cclock(cel);
 
859
        /* put report lock on, so we can free orphaned report locks */
 
860
        ++ccrptlock(cel);
 
861
        ASSERT(cclock(cel)>0);
 
862
}
 
863
/*======================================
 
864
 * cel_rptlocks -- return report lock count for specified cache element
 
865
 *====================================*/
 
866
INT
 
867
cel_rptlocks (CACHEEL cel)
 
868
{
 
869
        return ccrptlock(cel);
835
870
}
836
871
/*======================================
837
872
 * lock_record_in_cache -- Load record into cache & lock it
853
888
void
854
889
unlock_cache (CACHEEL cel)
855
890
{
856
 
        ASSERT(cclock(cel)>0);
857
 
        ASSERT(cnode(cel));
858
 
        cclock(cel)--;
 
891
        ASSERT(cclock(cel) > 0);
 
892
        ASSERT(cnode(cel));
 
893
        --cclock(cel);
 
894
}
 
895
/*==========================================
 
896
 * unlockrpt_cache -- Unlock CACHEEL from direct cache (report program call)
 
897
 *========================================*/
 
898
void
 
899
unlockrpt_cache (CACHEEL cel)
 
900
{
 
901
        ASSERT(cclock(cel) > 0);
 
902
        ASSERT(ccrptlock(cel) > 0);
 
903
        ASSERT(cnode(cel));
 
904
        --cclock(cel);
 
905
        --ccrptlock(cel);
859
906
}
860
907
/*======================================
861
908
 * unlock_record_from_cache -- Remove lock on record
872
919
}
873
920
/*=========================================
874
921
 * cache_get_lock_counts -- Fill in lock counts
 
922
 * does not include report locks (but, this isn't
 
923
 *  called during reports anyway)
875
924
 *=======================================*/
876
925
static void
877
926
cache_get_lock_counts (CACHE ca, INT * locks)
988
1037
        CACHEEL cel=0;
989
1038
        ASSERT(cache);
990
1039
        ASSERT(top);
991
 
        ASSERT(!nparent(top) && !nsibling(top)); /* should be a root */
 
1040
        ASSERT(!nparent(top));  /* should be a root */
 
1041
        ASSERT(!nsibling(top)); /* should be a root */
992
1042
        if (nestr(cacname(cache), "OTHR")) {
993
1043
                /* only INDI records in INDI cache, etc */
994
1044
                if (!eqstr(cacname(cache), ntag(top))) {
1019
1069
                for (cel = caclastdir(cache); cel && cclock(cel); cel = cprev(cel)) {
1020
1070
                }
1021
1071
                if (!cel) {
1022
 
                        llwprintf("Cache overflow! (Cache=%s, size=%d)\n", cacname(cache), cacmaxdir(cache));
 
1072
                        crashlog(_("Cache [%s] overflowed its max size (%d)"), cacname(cache), cacmaxdir(cache));
1023
1073
                        ASSERT(0);
1024
1074
                }
1025
1075
                remove_from_cache(cache, ckey(cel));
1071
1121
put_node_in_cache (CACHE cache, CACHEEL cel, NODE node, STRING key)
1072
1122
{
1073
1123
        BOOLEAN travdone = FALSE;
1074
 
        ASSERT(cache && node);
 
1124
        ASSERT(cache);
 
1125
        ASSERT(node);
1075
1126
        ASSERT(cacsizedir(cache) < cacmaxdir(cache));
1076
1127
        init_cel(cel);
1077
1128
        insert_table_ptr(cacdata(cache), key, cel);
1377
1428
qkey_to_typed_cacheel (STRING key)
1378
1429
{
1379
1430
        char ntype;
1380
 
        ASSERT(key && key[0]);
 
1431
        ASSERT(key);
 
1432
        ASSERT(key[0]);
1381
1433
        ntype = key[0];
1382
1434
        switch(ntype) {
1383
1435
        case 'I': return qkey_to_indi_cacheel(key);
1447
1499
{
1448
1500
        set_all_nodetree_to_cel(root, root->n_cel);
1449
1501
}
 
1502
/*=======================================================
 
1503
 * free_all_rprtlocks_in_cache -- Remove any rptlocks on any
 
1504
 *  elements in this cache, and return number removed
 
1505
 *=====================================================*/
 
1506
static int
 
1507
free_all_rprtlocks_in_cache (CACHE cache)
 
1508
{
 
1509
        INT ct=0;
 
1510
        CACHEEL cel=0;
 
1511
 
 
1512
        for (cel = caclastdir(cache); cel; cel = cprev(cel)) {
 
1513
                if (ccrptlock(cel)) {
 
1514
                        INT delta = ccrptlock(cel);
 
1515
                        ccrptlock(cel) = 0;
 
1516
                        ASSERT(cclock(cel) >= delta);
 
1517
                        cclock(cel) -= delta;
 
1518
                        ++ct;
 
1519
                }
 
1520
        }
 
1521
        return ct;
 
1522
}
 
1523
/*=======================================================
 
1524
 * free_all_rprtlocks -- Remove any rptlocks on any
 
1525
 *  elements in all caches, and return number removed
 
1526
 *=====================================================*/
 
1527
int
 
1528
free_all_rprtlocks (void)
 
1529
{
 
1530
        int ct=0;
 
1531
        ct += free_all_rprtlocks_in_cache(indicache);
 
1532
        ct += free_all_rprtlocks_in_cache(famcache);
 
1533
        ct += free_all_rprtlocks_in_cache(sourcache);
 
1534
        ct += free_all_rprtlocks_in_cache(sourcache);
 
1535
        ct += free_all_rprtlocks_in_cache(othrcache);
 
1536
        return ct;
 
1537
}