Avoids unnecessary reformatting of subject pages again.
-# mksubj.pl: Create the subject index pages
+# mksubj.pl: Update the subject index pages
#
# Known contributors to this file:
# Ken Stevens (when it was still info.pl)
#
# Known contributors to this file:
# Ken Stevens (when it was still info.pl)
#
# Usage: mksubj.pl SUBJECT... INFO-FILE...
#
#
# Usage: mksubj.pl SUBJECT... INFO-FILE...
#
-# Read the INFO-FILE..., create info/SUBJECT.t for each SUBJECT.
+# Read the INFO-FILE..., update info/SUBJECT.t for each SUBJECT.
use strict;
use warnings;
use File::stat;
use strict;
use warnings;
use File::stat;
-use Fcntl qw(O_WRONLY O_EXCL O_CREAT);
-
# The chapters, in order
my @Chapters = qw/Introduction Concept Command Server/;
# The chapters, in order
my @Chapters = qw/Introduction Concept Command Server/;
+for (keys %Subjects) {
+ update_subj($_);
+}
# Parse an info file
# Set $filename, $filename{TOPIC}, $long{TOPIC}, $chapter{TOPIC},
# Parse an info file
# Set $filename, $filename{TOPIC}, $long{TOPIC}, $chapter{TOPIC},
$largest{$sub} = $topic if length $topic > length $largest{$sub};
}
$largest{$sub} = $topic if length $topic > length $largest{$sub};
}
-# Create a Subject.t file
-sub create_subj {
+# Update a Subject.t file
+sub update_subj {
my ($subj) = @_;
my $fname = "info/$subj.t";
my ($subj) = @_;
my $fname = "info/$subj.t";
my ($any_topic, $any_basic, $any_obsolete, $any_long);
my ($any_topic, $any_basic, $any_obsolete, $any_long);
- sysopen(SUBJ, $fname, O_WRONLY | O_EXCL | O_CREAT)
- or die "Unable to create $fname: $!\n";
-
- print SUBJ '.\" DO NOT EDIT THIS FILE. It was automatically generated by mksubj.pl'."\n";
- print SUBJ ".TH Subject \U$subj\n";
+ $out .= '.\" DO NOT EDIT THIS FILE. It was automatically generated by mksubj.pl'."\n";
+ $out .= ".TH Subject \U$subj\n";
$largest{$subj} =~ s/-/M/g;
$largest{$subj} =~ s/-/M/g;
- print SUBJ ".in \\w'$largest{$subj}XX\\0\\0\\0\\0'u\n";
+ $out .= ".in \\w'$largest{$subj}XX\\0\\0\\0\\0'u\n";
for my $chap (@Chapters) {
next unless exists $subject{$subj}{$chap};
for my $chap (@Chapters) {
next unless exists $subject{$subj}{$chap};
for my $topic (split(/\n/, $subject{$subj}{$chap})) {
$any_topic = 1;
my $flags = "";
for my $topic (split(/\n/, $subject{$subj}{$chap})) {
$any_topic = 1;
my $flags = "";
$any_long = 1;
}
$flags = sprintf("%-2s", $flags);
$any_long = 1;
}
$flags = sprintf("%-2s", $flags);
- print SUBJ ".L \"$topic $flags\"\n";
- print SUBJ "$desc{$topic}\n";
+ $out .= ".L \"$topic $flags\"\n";
+ $out .= "$desc{$topic}\n";
}
}
unless ($any_topic) {
print STDERR "$0: Subject $subj has no topics\n";
exit 1;
}
}
}
unless ($any_topic) {
print STDERR "$0: Subject $subj has no topics\n";
exit 1;
}
. ".in 0\n"
. "For info on a particular subject, type \"info <subject>\" where <subject> is\n"
. "one of the subjects listed above.\n";
. ".in 0\n"
. "For info on a particular subject, type \"info <subject>\" where <subject> is\n"
. "one of the subjects listed above.\n";
- print SUBJ "Subjects marked by * are the most important and should be read by new players.\n"
+ $out .= "Subjects marked by * are the most important and should be read by new players.\n"
- print SUBJ "Subjects marked by + are obsolete.\n"
+ $out .= "Subjects marked by + are obsolete.\n"
- print SUBJ "Unusually long subjects are marked with a !.\n"
+ $out .= "Unusually long subjects are marked with a !.\n"
+
+ return if (same_contents($fname, $out));
+ open(SUBJ, ">$fname")
+ or die "Can't open $fname for writing: $!";
+ print SUBJ $out;
-# Remove the old Subject.t files and create new ones
-sub create_subjects {
- my (@subj);
+sub same_contents {
+ my ($fname, $contents) = @_;
+ local $/;
- for (keys %Subjects) {
- unlink "info/$_.t";
- }
-
- @subj = sort keys %subject;
-
- for my $subj (@subj) {
- create_subj($subj);
+ if (!open(SUBJ, "<$fname")) {
+ return 0 if ($!{ENOENT});
+ die "Can't open $fname for reading: $!";
+ my $old = <SUBJ>;
+ close SUBJ;
+ return $contents eq $old;
}
# Print an integrity error message and exit with code 1
}
# Print an integrity error message and exit with code 1