2020-01-12 00:36:56 +01:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
use File::Compare qw(compare);
|
|
|
|
|
|
|
|
sub format_one {
|
|
|
|
my ($out, $nameattr) = @_;
|
|
|
|
my ($name, $attr) = @$nameattr;
|
|
|
|
my ($state, $description);
|
2020-11-21 19:20:35 +01:00
|
|
|
my $mansection;
|
2020-01-12 00:36:56 +01:00
|
|
|
$state = 0;
|
|
|
|
open I, '<', "$name.txt" or die "No such file $name.txt";
|
|
|
|
while (<I>) {
|
2020-11-21 19:20:35 +01:00
|
|
|
if (/^git[a-z0-9-]*\(([0-9])\)$/) {
|
|
|
|
$mansection = $1;
|
|
|
|
next;
|
|
|
|
}
|
2020-01-12 00:36:56 +01:00
|
|
|
if (/^NAME$/) {
|
|
|
|
$state = 1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if ($state == 1 && /^----$/) {
|
|
|
|
$state = 2;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
next if ($state != 2);
|
|
|
|
chomp;
|
|
|
|
$description = $_;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
close I;
|
|
|
|
if (!defined $description) {
|
|
|
|
die "No description found in $name.txt";
|
|
|
|
}
|
|
|
|
if (my ($verify_name, $text) = ($description =~ /^($name) - (.*)/)) {
|
2020-11-21 19:20:35 +01:00
|
|
|
print $out "linkgit:$name\[$mansection\]::\n\t";
|
2020-01-12 00:36:56 +01:00
|
|
|
if ($attr =~ / deprecated /) {
|
|
|
|
print $out "(deprecated) ";
|
|
|
|
}
|
|
|
|
print $out "$text.\n\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
die "Description does not match $name: $description";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 19:20:35 +01:00
|
|
|
my ($input, @categories) = @ARGV;
|
|
|
|
|
|
|
|
open IN, "<$input";
|
|
|
|
while (<IN>) {
|
2020-01-12 00:36:56 +01:00
|
|
|
last if /^### command list/;
|
|
|
|
}
|
|
|
|
|
|
|
|
my %cmds = ();
|
2020-11-21 19:20:35 +01:00
|
|
|
for (sort <IN>) {
|
2020-01-12 00:36:56 +01:00
|
|
|
next if /^#/;
|
|
|
|
|
|
|
|
chomp;
|
|
|
|
my ($name, $cat, $attr) = /^(\S+)\s+(.*?)(?:\s+(.*))?$/;
|
|
|
|
$attr = '' unless defined $attr;
|
|
|
|
push @{$cmds{$cat}}, [$name, " $attr "];
|
|
|
|
}
|
2020-11-21 19:20:35 +01:00
|
|
|
close IN;
|
2020-01-12 00:36:56 +01:00
|
|
|
|
2020-11-21 19:20:35 +01:00
|
|
|
for my $out (@categories) {
|
|
|
|
my ($cat) = $out =~ /^cmds-(.*)\.txt$/;
|
2020-01-12 00:36:56 +01:00
|
|
|
open O, '>', "$out+" or die "Cannot open output file $out+";
|
|
|
|
for (@{$cmds{$cat}}) {
|
|
|
|
format_one(\*O, $_);
|
|
|
|
}
|
|
|
|
close O;
|
|
|
|
|
|
|
|
if (-f "$out" && compare("$out", "$out+") == 0) {
|
|
|
|
unlink "$out+";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print STDERR "$out\n";
|
|
|
|
rename "$out+", "$out";
|
|
|
|
}
|
|
|
|
}
|