The fourth batch
[git.git] / Documentation / cmd-list.perl
blobe260a989774071b66d2b56c56c5045b84a508c5c
1 #!/usr/bin/perl -w
3 use File::Compare qw(compare);
5 sub format_one {
6 my ($source_dir, $out, $nameattr) = @_;
7 my ($name, $attr) = @$nameattr;
8 my ($path) = "$source_dir/Documentation/$name.txt";
9 my ($state, $description);
10 my $mansection;
11 $state = 0;
12 open I, '<', "$path" or die "No such file $path.txt";
13 while (<I>) {
14 if (/^(?:git|scalar)[a-z0-9-]*\(([0-9])\)$/) {
15 $mansection = $1;
16 next;
18 if (/^NAME$/) {
19 $state = 1;
20 next;
22 if ($state == 1 && /^----$/) {
23 $state = 2;
24 next;
26 next if ($state != 2);
27 chomp;
28 $description = $_;
29 last;
31 close I;
32 if (!defined $description) {
33 die "No description found in $path.txt";
35 if (my ($verify_name, $text) = ($description =~ /^($name) - (.*)/)) {
36 print $out "linkgit:$name\[$mansection\]::\n\t";
37 if ($attr =~ / deprecated /) {
38 print $out "(deprecated) ";
40 print $out "$text.\n\n";
42 else {
43 die "Description does not match $name: $description";
47 my ($source_dir, $build_dir, @categories) = @ARGV;
49 open IN, "<$source_dir/command-list.txt";
50 while (<IN>) {
51 last if /^### command list/;
54 my %cmds = ();
55 for (sort <IN>) {
56 next if /^#/;
58 chomp;
59 my ($name, $cat, $attr) = /^(\S+)\s+(.*?)(?:\s+(.*))?$/;
60 $attr = '' unless defined $attr;
61 push @{$cmds{$cat}}, [$name, " $attr "];
63 close IN;
65 for my $out (@categories) {
66 my ($cat) = $out =~ /^cmds-(.*)\.txt$/;
67 my ($path) = "$build_dir/$out";
68 open O, '>', "$path+" or die "Cannot open output file $out+";
69 for (@{$cmds{$cat}}) {
70 format_one($source_dir, \*O, $_);
72 close O;
74 if (-f "$path" && compare("$path", "$path+") == 0) {
75 unlink "$path+";
77 else {
78 rename "$path+", "$path";