blob: 04f99778d81def42e9e129b2f5b2b0551a0c760f [file] [log] [blame]
Junio C Hamanod7907392007-04-05 22:17:20 -07001#!/usr/bin/perl -w
2
3use File::Compare qw(compare);
Junio C Hamano72fe6a52007-01-18 16:02:13 -08004
5sub format_one {
Junio C Hamano0bf15e72007-11-08 17:21:48 -08006 my ($out, $nameattr) = @_;
7 my ($name, $attr) = @$nameattr;
Junio C Hamano72fe6a52007-01-18 16:02:13 -08008 my ($state, $description);
Junio C Hamanod7907392007-04-05 22:17:20 -07009 $state = 0;
Junio C Hamano72fe6a52007-01-18 16:02:13 -080010 open I, '<', "$name.txt" or die "No such file $name.txt";
11 while (<I>) {
12 if (/^NAME$/) {
13 $state = 1;
14 next;
15 }
16 if ($state == 1 && /^----$/) {
17 $state = 2;
18 next;
19 }
20 next if ($state != 2);
21 chomp;
22 $description = $_;
23 last;
24 }
25 close I;
26 if (!defined $description) {
27 die "No description found in $name.txt";
28 }
29 if (my ($verify_name, $text) = ($description =~ /^($name) - (.*)/)) {
Dan McGee5162e692007-12-29 00:20:38 -060030 print $out "linkgit:$name\[1\]::\n\t";
Junio C Hamano79d30662007-12-01 23:39:19 -080031 if ($attr =~ / deprecated /) {
32 print $out "(deprecated) ";
Junio C Hamano0bf15e72007-11-08 17:21:48 -080033 }
34 print $out "$text.\n\n";
Junio C Hamano72fe6a52007-01-18 16:02:13 -080035 }
36 else {
37 die "Description does not match $name: $description";
38 }
39}
40
41my %cmds = ();
Junio C Hamano79d30662007-12-01 23:39:19 -080042for (sort <>) {
Junio C Hamano72fe6a52007-01-18 16:02:13 -080043 next if /^#/;
44
45 chomp;
Junio C Hamano0bf15e72007-11-08 17:21:48 -080046 my ($name, $cat, $attr) = /^(\S+)\s+(.*?)(?:\s+(.*))?$/;
Junio C Hamano79d30662007-12-01 23:39:19 -080047 $attr = '' unless defined $attr;
48 push @{$cmds{$cat}}, [$name, " $attr "];
Junio C Hamano72fe6a52007-01-18 16:02:13 -080049}
50
51for my $cat (qw(ancillaryinterrogators
52 ancillarymanipulators
53 mainporcelain
54 plumbinginterrogators
55 plumbingmanipulators
Junio C Hamano89bf2072007-01-18 22:32:38 -080056 synchingrepositories
57 foreignscminterface
58 purehelpers
59 synchelpers)) {
Junio C Hamano72fe6a52007-01-18 16:02:13 -080060 my $out = "cmds-$cat.txt";
61 open O, '>', "$out+" or die "Cannot open output file $out+";
62 for (@{$cmds{$cat}}) {
63 format_one(\*O, $_);
64 }
65 close O;
Junio C Hamanod7907392007-04-05 22:17:20 -070066
67 if (-f "$out" && compare("$out", "$out+") == 0) {
68 unlink "$out+";
69 }
70 else {
71 print STDERR "$out\n";
72 rename "$out+", "$out";
73 }
Junio C Hamano72fe6a52007-01-18 16:02:13 -080074}