summaryrefslogtreecommitdiff
path: root/generate-cmdlist.perl
blob: 31516e36ace57e4f46b83e4a6d2cc30cc76324cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl
use strict;
use warnings;

print <<"EOT";
/* Automatically generated by $0 */

struct cmdname_help {
	char name[16];
	char help[80];
	unsigned char group;
};

static char *common_cmd_groups[] = {
EOT

my $n = 0;
my %grp;
while (<>) {
	last if /^### command list/;
	next if (1../^### common groups/) || /^#/ || /^\s*$/;
	chop;
	my ($k, $v) = split ' ', $_, 2;
	$grp{$k} = $n++;
	print "\tN_(\"$v\"),\n";
}

print "};\n\nstatic struct cmdname_help common_cmds[] = {\n";

while (<>) {
	next if /^#/ || /^\s*$/;
	my @tags = split;
	my $cmd = shift @tags;
	for my $t (@tags) {
		if (exists $grp{$t}) {
			my $s;
			open my $f, '<', "Documentation/$cmd.txt" or die;
			while (<$f>) {
				($s) = /^$cmd - (.+)$/;
				last if $s;
			}
			close $f;
			$cmd =~ s/^git-//;
			print "\t{\"$cmd\", N_(\"$s\"), $grp{$t}},\n";
			last;
		}
	}
}

print "};\n";