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