Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions bin/addbib
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ License:


use strict;
use warnings;
use Getopt::Std;
use vars qw($opt_a $opt_p);

Expand All @@ -35,17 +36,17 @@ my @prompts = (

if ($opt_p) {
@prompts = ();
open PROMPTFILE, $opt_p or die "can't read $opt_p: $!";
foreach (<PROMPTFILE>) {
open my $PROMPTFILE, '<', $opt_p or die "can't read $opt_p: $!";
foreach (<$PROMPTFILE>) {
if (/^\s*([^%]+)\t(%\w)/) {
push @prompts, "$1\t$2";
}
}
close(PROMPTFILE);
close($PROMPTFILE);
}

my $database = shift;
open DATABASE, ">>$database" or die "can't append to $database: $!";
open my $DATABASE, '>>', $database or die "can't append to $database: $!";

my $inst = <<_EOINST;
Addbib will prompt you for various bibliographic fields.
Expand All @@ -71,7 +72,7 @@ print "$inst" if /^y/i;
# I did it to preserve order.

while (1) {
print DATABASE "\n"; # start a new entry
print $DATABASE "\n"; # start a new entry

PROMPT: for (my $i=0; $i < @prompts; $i++) {
my ($prompt, $code) = split /\t/, $prompts[$i];
Expand All @@ -82,40 +83,40 @@ while (1) {
$i -= 2;
next PROMPT;
}
print DATABASE "$code\t";
print $DATABASE "$code\t";
while (/\\$/) {
chop; chop;
print DATABASE "$_\n";
print $DATABASE "$_\n";
print "> ";
$_ = <>;
}
print DATABASE $_;
print $DATABASE $_;
}

unless ($opt_a) {
print "Abstract: ";
$_ = <>;
next if (/^$/);
print DATABASE "%X\t$_";
print $DATABASE "%X\t$_";
while (<>) {
print DATABASE $_;
print $DATABASE $_;
}
}
} continue {
print "Continue? (y) ";
$_ = <>;
while (/^\s*(edit|ex|vi|view|emacs)\s*/) {
close DATABASE or die "can't close $database: $!";
close $DATABASE or die "can't close $database: $!";
system("$1 $database") == 0
or die "system '$1 $database' failed: $?";
open DATABASE, ">>$database" or die "can't open $database: $!";
open my $DATABASE, '>>', $database or die "can't open $database: $!";
print "Continue? (y) ";
$_ = <>;
}
last if /^(n|q)/i;
}

close DATABASE or die "can't close $database: $!";
close $DATABASE or die "can't close $database: $!";

__END__

Expand Down