/[bibulus]/bibulus/Bibulus.pm
ViewVC logotype

Diff of /bibulus/Bibulus.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by twid, Fri Apr 18 23:13:31 2003 UTC revision 1.7 by twid, Sat Apr 19 13:53:11 2003 UTC
# Line 17  sub new { Line 17  sub new {
17    my $class = shift;    my $class = shift;
18    my $self = {};    my $self = {};
19    bless($self, $class);    bless($self, $class);
20    
21      $self->inlinecrossref(1);
22    
23    return $self;    return $self;
24  }  }
25    
26    # max. number of crossrefs to an entry that will be inlined.
27    sub inlinecrossref {
28      my $self = shift;
29      $self->{INLINECROSSREF} = shift;
30    }
31    
32    sub doinlinecrossref {
33      my $self = shift;
34    
35      foreach my $n (0..$#{$self->{EL}}) {
36        my $i = $self->{EL}[$n];
37        my $id = $i->id;
38        print "$id: ";
39        if ($self->{CITES}{$id} != 0) { # crossref'ed entries
40    
41          # is it crossref'ed rarely enough?
42          if ($self->{CITES}{$id} <= $self->{INLINECROSSREF}) {
43    
44            # find entries crossref'ing $id
45          J: foreach my $j (@{$self->{EL}}) {
46              if (defined($j->first_child('crossref'))) {
47                my $idj = $j->first_child('crossref')->atts->{id};
48                $idj eq $id or next J;
49    
50                # delete the crossref:
51                $j->first_child('crossref')->delete;
52    
53                # paste in various fields --
54                # this should probably be restricted to certain fields:
55                foreach my $n ($i->children) {
56                  my $x = $n->copy;
57                  $x->paste('last_child', $j);
58                }
59              }
60            }
61    
62            # mark for deletion:
63            $self->{EL}[$n] = 0;
64          }
65        }
66      }
67      # prune inlined titles:
68      @{$self->{EL}} = grep {$_} @{$self->{EL}};
69    }
70    
71  sub getbib {  sub getbib {
72    my $self = shift;    my $self = shift;
73      $self->allfound;
74      $self->doinlinecrossref;
75    $self->gensortkeys;    $self->gensortkeys;
76    $self->sortbib;    $self->sortbib;
77    $self->labels;    $self->labels;
78    return $self->genbib;    return $self->genbib;
79  }  }
80    
81    # Check whether all cited titles were found;
82    # return 1 if all were there, 0 otherwise;
83    # print warnings for everything not found.
84    sub allfound {
85      my $self = shift;
86      my $found = 1;
87    
88      foreach my $i (keys %{$self->{CITES}}) {
89        unless (defined($self->{FOUND}{$i})) {
90          warn "Entry with id = '$i' not found.\n";
91          $found = 0;
92        }
93      }
94    
95      return $found;
96    }
97    
98  # for selecting books to cite  # for selecting books to cite
99  sub cite {  sub cite {
100    my $self = shift;    my $self = shift;
101    my (@cites) = @_;    my (@cites) = @_;
102    foreach (@cites) {    foreach (@cites) {
103      $self->{CITES}{$_} = 1;      $self->{CITES}{$_} = 0;
104    }    }
105  }  }
106    
# Line 122  sub insertentry { Line 189  sub insertentry {
189    my $self = shift;    my $self = shift;
190    my ($t, $elt) = @_;    my ($t, $elt) = @_;
191    
   # BUG: If an entry cross-references another entry, that one  
   # should also be inserted into the list here.  
   
192    if (defined($self->{CITEALL}) or defined($self->{CITES}{$elt->id})) {    if (defined($self->{CITEALL}) or defined($self->{CITES}{$elt->id})) {
193      push @{$self->{EL}}, $elt;      push @{$self->{EL}}, $elt;
194        $self->{FOUND}{$elt->id} = 1;
195    
196        # handle crossrefs:
197        if (defined($elt->first_child('crossref'))) {
198          my $id = $elt->first_child('crossref')->atts->{id};
199          if (defined($self->{CITES}{$id})) {
200            # if it has been cited on its own, don't count the crossrefs
201            $self->{CITES}{$id} == 0 or
202              ++$self->{CITES}{$id};
203          } else {
204            $self->{CITES}{$id} = 1;
205          }
206        }
207    } else {    } else {
208      $t->purge;      $t->purge;
209    }    }
# Line 163  sub sortkey_author { Line 240  sub sortkey_author {
240  sub sortkey_year {  sub sortkey_year {
241    my ($i) = @_;    my ($i) = @_;
242    my $t = $i->first_child('year');    my $t = $i->first_child('year');
243      defined($t) or return 0;
244    my $sortkey = $t->text;    my $sortkey = $t->text;
245    
246    return $sortkey;    return $sortkey;

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26