The second batch
[git.git] / Documentation / cmd-list.perl
blob755a110bc48d7e2b596651ca13664c01192d966c
1 #!/usr/bin/perl -w
3 use File::Compare qw(compare);
5 sub format_one {
6 my ($out, $nameattr) = @_;
7 my ($name, $attr) = @$nameattr;
8 my ($state, $description);
9 my $mansection;
10 $state = 0;
11 open I, '<', "$name.txt" or die "No such file $name.txt";
12 while (<I>) {
13 if (/^(?:git|scalar)[a-z0-9-]*\(([0-9])\)$/) {
14 $mansection = $1;
15 next;
17 if (/^NAME$/) {
18 $state = 1;
19 next;
21 if ($state == 1 && /^----$/) {
22 $state = 2;
23 next;
25 next if ($state != 2);
26 chomp;
27 $description = $_;
28 last;
30 close I;
31 if (!defined $description) {
32 die "No description found in $name.txt";
34 if (my ($verify_name, $text) = ($description =~ /^($name) - (.*)/)) {
35 print $out "linkgit:$name\[$mansection\]::\n\t";
36 if ($attr =~ / deprecated /) {
37 print $out "(deprecated) ";
39 print $out "$text.\n\n";
41 else {
42 die "Description does not match $name: $description";
46 my ($input, @categories) = @ARGV;
48 open IN, "<$input";
49 while (<IN>) {
50 last if /^### command list/;
53 my %cmds = ();
54 for (sort <IN>) {
55 next if /^#/;
57 chomp;
58 my ($name, $cat, $attr) = /^(\S+)\s+(.*?)(?:\s+(.*))?$/;
59 $attr = '' unless defined $attr;
60 push @{$cmds{$cat}}, [$name, " $attr "];
62 close IN;
64 for my $out (@categories) {
65 my ($cat) = $out =~ /^cmds-(.*)\.txt$/;
66 open O, '>', "$out+" or die "Cannot open output file $out+";
67 for (@{$cmds{$cat}}) {
68 format_one(\*O, $_);
70 close O;
72 if (-f "$out" && compare("$out", "$out+") == 0) {
73 unlink "$out+";
75 else {
76 print STDERR "$out\n";
77 rename "$out+", "$out";