Documentation / cmd-list.perlon commit Merge branch 'db/vcs-svn-incremental' into svn-fe (9ecfa8a)
   1#!/usr/bin/perl -w
   2
   3use File::Compare qw(compare);
   4
   5sub format_one {
   6        my ($out, $nameattr) = @_;
   7        my ($name, $attr) = @$nameattr;
   8        my ($state, $description);
   9        $state = 0;
  10        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) - (.*)/)) {
  30                print $out "linkgit:$name\[1\]::\n\t";
  31                if ($attr =~ / deprecated /) {
  32                        print $out "(deprecated) ";
  33                }
  34                print $out "$text.\n\n";
  35        }
  36        else {
  37                die "Description does not match $name: $description";
  38        }
  39}
  40
  41my %cmds = ();
  42for (sort <>) {
  43        next if /^#/;
  44
  45        chomp;
  46        my ($name, $cat, $attr) = /^(\S+)\s+(.*?)(?:\s+(.*))?$/;
  47        $attr = '' unless defined $attr;
  48        push @{$cmds{$cat}}, [$name, " $attr "];
  49}
  50
  51for my $cat (qw(ancillaryinterrogators
  52                ancillarymanipulators
  53                mainporcelain
  54                plumbinginterrogators
  55                plumbingmanipulators
  56                synchingrepositories
  57                foreignscminterface
  58                purehelpers
  59                synchelpers)) {
  60        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;
  66
  67        if (-f "$out" && compare("$out", "$out+") == 0) {
  68                unlink "$out+";
  69        }
  70        else {
  71                print STDERR "$out\n";
  72                rename "$out+", "$out";
  73        }
  74}