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

Diff of /bibulus/Bibulus.pm

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

revision 1.12 by twid, Fri Jul 11 20:17:11 2003 UTC revision 1.13 by twid, Sat Jul 12 15:31:59 2003 UTC
# Line 62  sub inlinecrossref { Line 62  sub inlinecrossref {
62  sub doinlinecrossref {  sub doinlinecrossref {
63    my $self = shift;    my $self = shift;
64    
65      my %willdie;
66    
67    $self->{CITEALL} and return;    $self->{CITEALL} and return;
68    
69    foreach my $n (0..$#{$self->{EL}}) {    foreach my $n (0..$#{$self->{EL}}) {
# Line 93  sub doinlinecrossref { Line 95  sub doinlinecrossref {
95          }          }
96    
97          # mark for deletion:          # mark for deletion:
98          $self->{EL}[$n] = 0;          $willdie{$self->{EL}[$n]} = 1;
99            print "This entry will be removed.\n" if $DEBUG;
100        }        }
101      }      }
102    }    }
103    # prune inlined titles:    # prune inlined titles:
104    @{$self->{EL}} = grep {$_} @{$self->{EL}};    @{$self->{EL}} = grep {!defined($willdie{$_})} @{$self->{EL}};
105  }  }
106    
107  # main program logic  # main program logic
# Line 499  sub formatentry { Line 502  sub formatentry {
502    my $attr = $e->atts;    my $attr = $e->atts;
503    
504    $self->setstate('beforeall');    $self->setstate('beforeall');
505      $self->{DIDWRITESOMETHING} = 0;
506    
507    unless (defined($attr->{id})) {  # an entry must have an id    unless (defined($attr->{id})) {  # an entry must have an id
508      warn "No ID for entry.\n";      warn "No ID for entry.\n";
# Line 562  sub formatentry { Line 566  sub formatentry {
566  sub formatauthors {  sub formatauthors {
567    my $self = shift;    my $self = shift;
568    
569    
570    my $i = $self->{CUREL}->first_child('author');    my $i = $self->{CUREL}->first_child('author');
571    unless (defined($i)) {    unless (defined($i)) {
572      warn "No author for id = ", $self->{CUREL}->atts->{id}, ".\n";      warn "No author for id = ", $self->{CUREL}->atts->{id}, ".\n";
573      return;      return;
574    }    }
575    
576    $self->{CURR} .= $self->formatnames($i);    $self->outputtext($self->formatnames($i));
   $self->outputnonnull;  
577  }  }
578    
579  sub formateditors {  sub formateditors {
580    my $self = shift;    my $self = shift;
581    
582    
583    my $i = $self->{CUREL}->first_child('editor');    my $i = $self->{CUREL}->first_child('editor');
584    unless (defined($i)) {    unless (defined($i)) {
585      warn "No editor for id = ", $self->{CUREL}->atts->{id}, ".\n";      warn "No editor for id = ", $self->{CUREL}->atts->{id}, ".\n";
586      return;      return;
587    }    }
588    
589    $self->{CURR} .= $self->formatnames($i) . ' (editor)';    $self->outputtext($self->formatnames($i) . ' (editor)');
   $self->outputnonnull;  
590  }  }
591    
592  sub formatnames {  sub formatnames {
# Line 649  sub formatnewblock { Line 653  sub formatnewblock {
653    
654    $self->getstate ne 'beforeall'    $self->getstate ne 'beforeall'
655      and $self->setstate('afterblock');      and $self->setstate('afterblock');
656    
657      $self->{DIDWRITESOMETHING} = 0;
658  }  }
659    
660  sub newsentence {  sub newsentence {
# Line 657  sub newsentence { Line 663  sub newsentence {
663    $self->getstate ne 'afterblock'    $self->getstate ne 'afterblock'
664      and $self->getstate ne 'beforeall'      and $self->getstate ne 'beforeall'
665        and $self->setstate('aftersentence');        and $self->setstate('aftersentence');
666      $self->{DIDWRITESOMETHING} = 0;
667  }  }
668    
669  sub finentry {  sub finentry {
# Line 666  sub finentry { Line 673  sub finentry {
673  }  }
674    
675  # Taken from BibTeX:  # Taken from BibTeX:
676    sub output {
677      my $self = shift;
678      my $s = shift;
679      $s and $self->outputnonnull($s);
680    }
681    
682    sub outputcheck {
683      my $self = shift;
684      my $f = shift;
685      my $s = $self->getfield($f);
686      if ($s) {
687        $self->outputnonnull($s);
688      } else {
689        warn "Empty <$f> for id = ", $self->{CUREL}->atts->{id}, ".\n";
690      }
691    }
692    
693  sub outputnonnull {  sub outputnonnull {
694    my $self = shift;    my $self = shift;
695    
# Line 673  sub outputnonnull { Line 697  sub outputnonnull {
697    print STDERR "CURR is <<$self->{CURR}>>.\n" if $DEBUG;    print STDERR "CURR is <<$self->{CURR}>>.\n" if $DEBUG;
698    
699    if ($self->getstate eq 'midsentence') {    if ($self->getstate eq 'midsentence') {
700      $self->{CURR} .= $self->comma;      $self->{CURR} .= $self->comma if $self->{DIDWRITESOMETHING};
701    } else {    } else {
702      if ($self->getstate eq 'afterblock') {      if ($self->getstate eq 'afterblock') {
703        $self->{CURR} .= $self->fullstop if $self->canaddperiod;        $self->{CURR} .= $self->fullstop if $self->canaddperiod;
# Line 701  sub formattitle { Line 725  sub formattitle {
725    my $self = shift;    my $self = shift;
726    my $type = shift;    my $type = shift;
727    
   $self->outputnonnull;  
728    
729    my $t = $self->getfield('title', 1);    my $t = $self->getfield('title', 1);
730    
731      $t = $self->language($self->{CUREL}->inherit_att('xml:lang'), $t);
732    
733      # This approach:
734    defined($type) and $type eq 'emph' and $t = $self->emph($t);    defined($type) and $type eq 'emph' and $t = $self->emph($t);
735      # conflicts with this one:
736      if (defined($self->{STYLE}{titlefont})) {
737        if ($self->{STYLE}{titlefont} eq 'emph') {
738          $t = $self->emph($t);
739        } elsif ($self->{STYLE}{titlefont} eq 'bold') {
740          $t = $self->bold($t);
741        }
742      }
743    
744    $self->{CURR} .= $t;    $self->outputtext($t);
745  }  }
746    
747  sub formatjournal {  sub formatjournal {
748    my $self = shift;    my $self = shift;
749    my $type = shift;    my $type = shift;
750    
   $self->outputnonnull;  
751    
752    my $t = $self->getfield('journal', 1);    my $t = $self->getfield('journal', 1);
753    
754    $t = $self->emph($t);    $t = $self->emph($t);
755    
756    $self->{CURR} .= $t;    $self->outputtext($t);
757  }  }
758    
759  sub formatvolnumpages {  sub formatvolnumpages {
760    my $self = shift;    my $self = shift;
761    
   $self->outputnonnull;  
762    
763    my $vol = $self->getfield('volume');    my $volume = $self->getfield('volume');
764    my $num = $self->getfield('number');    my $number = $self->getfield('number');
765    my $pages = $self->getfield('pages');    my $pages = $self->getfield('pages');
766    
767    ($vol or $num or $pages) and    my $t = '';
768      $self->{CURR} .= $self->comma . $vol . $num . $pages;    $t .= $volume if $volume;
769    
770      if ($number) {
771        $t .= "($number)";
772        $volume or warn "There's a number but no volume";
773      }
774    
775      if ($pages) {
776        if ($t) {
777          $t .= ":$pages";
778        } else {
779          $t = $pages;
780        }
781      }
782      $self->outputtext($t);
783    }
784    
785    sub outputtext {
786      my $self = shift;
787      my $t = shift;
788      if ($t) {
789        $self->outputnonnull;
790        $self->{CURR} .= $t;
791        $self->{DIDWRITESOMETHING} = 1;
792      } else {
793    #    $self->{DIDWRITESOMETHING} = 0;
794      }
795  }  }
796    
797  sub formatvolume {  sub formatvolume {
798    my $self = shift;    my $self = shift;
799    
   $self->outputnonnull;  
800    
801    my $t = $self->getfield('volume', 1);    my $t = $self->getfield('volume', 1);
802    $t and $self->{CURR} .= $self->comma . $t;  
803      $self->outputtext($t);
804  }  }
805    
806  sub formatdate {  sub formatdate {
807    my $self = shift;    my $self = shift;
808    
   $self->outputnonnull;  
809    
810    my $t = $self->getfield('year', 1);    my $t = $self->getfield('year', 1);
811    $t and $self->{CURR} .= $self->comma . $t;  
812      $self->outputtext($t);
813  }  }
814    
815  sub formatedition {  sub formatedition {
816    my $self = shift;    my $self = shift;
817    
   $self->outputnonnull;  
818    
819    my $t = $self->getfield('edition');    my $t = $self->getfield('edition');
820    $t and $self->{CURR} .= $self->comma . $t;  
821      $self->outputtext($t);
822  }  }
823    
824  sub formatpublisheraddress {  sub formatpublisheraddress {
825    my $self = shift;    my $self = shift;
826    
   $self->outputnonnull;  
   
827    my $t = $self->getfield('publisher');    my $t = $self->getfield('publisher');
828    $t and $self->{CURR} .= $self->comma . $t;    $self->outputtext($t);
829    
830    $t = $self->getfield('place');    $t = $self->getfield('place');
831    $t and $self->{CURR} .= $self->comma . $t;    $self->outputtext($t);
832  }  }
833    
834  sub formatcrossref {  sub formatcrossref {
835    my $self = shift;    my $self = shift;
836    
   $self->outputnonnull;  
   
837    my $i = $self->{CUREL}->first_child('crossref');    my $i = $self->{CUREL}->first_child('crossref');
838    unless (defined($i)) {    unless (defined($i)) {
839      warn "No crossref for id = ", $self->{CUREL}->atts->{id}, ".\n";      warn "No crossref for id = ", $self->{CUREL}->atts->{id}, ".\n";
# Line 788  sub formatcrossref { Line 842  sub formatcrossref {
842    
843    my $t = $i->atts->{id};    my $t = $i->atts->{id};
844    
845    $self->{CURR} .= $self->in($self->outputcite($t));    $self->outputtext($self->in($self->outputcite($t)));
846  }  }
847    
848  sub formatpages {  sub formatpages {
849    my $self = shift;    my $self = shift;
850    
   $self->outputnonnull;  
851    
852    my $i = $self->{CUREL}->first_child('pages');    my $i = $self->{CUREL}->first_child('pages');
853    unless (defined($i)) {    unless (defined($i)) {
# Line 804  sub formatpages { Line 857  sub formatpages {
857    
858    my $t = $i->text;    my $t = $i->text;
859    
860    $self->{CURR} .= $self->comma . $t;    $self->outputtext($t);
861  }  }
862    
863  sub formatrest {  sub formatrest {
864    my $self = shift;    my $self = shift;
865    
   $self->outputnonnull;  
   
866    # handle notes, annotations, ISBN & ISSN numbers etc. here    # handle notes, annotations, ISBN & ISSN numbers etc. here
867    
868    my $i = $self->{CUREL}->first_child('note');    my $i = $self->{CUREL}->first_child('note');
869    if (defined($i)) {    if (defined($i)) {
870      my $t = $i->text;      my $t = $i->text;
871      $self->{CURR} .= $t;      $self->outputtext($t);
872    }    }
873  }  }
874    
875  sub author {  sub oldauthor {
876    my $self = shift;    my $self = shift;
877    my ($e, $attr) = @_;    my ($e, $attr) = @_;
878    
# Line 847  sub author { Line 898  sub author {
898    return join(' and ', @res);    return join(' and ', @res);
899  }  }
900    
 sub title {  
   my $self = shift;  
   my ($e, $attr) = @_;  
   
   my $title = $e->field('title');  
   
   $title or warn "Title missing for entry $attr->{id}.", return;  
   
   my $t = '';  
   
   $t = $self->language($e->inherit_att('xml:lang'), $title);  
   
   if (defined($self->{STYLE}{titlefont})) {  
     if ($self->{STYLE}{titlefont} eq 'emph') {  
       return $self->emph($t);  
     } elsif ($self->{STYLE}{titlefont} eq 'bold') {  
       return $self->bold($t);  
     }  
   }  
   
   return $t;  
 }  
   
901  sub journal {  sub journal {
902    my $self = shift;    my $self = shift;
903    my ($e, $attr) = @_;    my ($e, $attr) = @_;
# Line 881  sub journal { Line 909  sub journal {
909    return $self->emph($journal);    return $self->emph($journal);
910  }  }
911    
 sub volnumpages {  
   my $self = shift;  
   my ($e, $attr) = @_;  
   
   my $volume = $e->field('volume');  
   my $number = $e->field('number');  
   my $pages = $e->field('pages');  
   
   my $t = '';  
   $t .= $volume if $volume;  
   if ($number) {  
     $t .= "($number)";  
     $volume or warn "There's a number but no volume in $attr->{id}";  
   }  
   if ($pages) {  
     if ($t) {  
       $t .= ":$pages";  
     } else {  
       $t = $pages;  
     }  
   }  
   
   return $t;  
 }  
   
912  sub field {  sub field {
913    my $self = shift;    my $self = shift;
914    my ($type, $e, $attr) = @_;    my ($type, $e, $attr) = @_;
# Line 916  sub field { Line 919  sub field {
919    
920    return $t;    return $t;
921  }  }
   
 sub article_crossref {  
   my $self = shift;  
   my ($e, $attr) = @_;  
   
   my $key = $e->field('key');  
   my $journal = $e->field('journal');  
   my $crossref = $e->field('crossref');  
   
   my $t = '';  
   
   if (!$key) {  
     if (!$journal) {  
       warn "need key or journal for $attr->{id} to crossref $crossref";  
     } else {  
       $t .= "In " . $self->emph($journal);  
     }  
   } else {  
     $t .= "In $key";  
   }  
   $t .= " \\cite{$crossref}";  
   
   return $t;  
 }  
922    
923  # Output primitives.  They should normally be redefined.  # Output primitives.  They should normally be redefined.
924    

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

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