summaryrefslogtreecommitdiff
path: root/scripts/checkopts.pl
blob: ec823433991636ee9d6a7d8d31385441a0011526 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env perl
## Copyright © 2010 by Daniel Friesel <derf@derf.homelinux.org>
## License: WTFPL <http://sam.zoy.org/wtfpl>
use strict;
use warnings;

my $options;

open(my $c_fh, '<', 'src/options.c') or die("Can't read options.c: $!");
while (my $line = <$c_fh>) {

	if ($line =~ /\{"(?<long>[\w-]+)"\s*,.*,\s*(?:'(?<short>.)'|(?<short>\d+))\}/o) {
		push(@{$options->{$+{long}}}, ['source', $+{short}]);
	}
}
close($c_fh);

open(my $h_fh, '<', 'src/help.raw') or die("Can't read help.raw: $!");
while (my $line = <$h_fh>) {

	if ($line =~ /^ (?:\-(?<short>.), |\s*)--(?<long>[\w-]+) /) {
		push(@{$options->{$+{long}}}, ['help', $+{short}]);
	}
}
close($h_fh);

open(my $man_fh, '<', 'man/feh.1') or die("Can't read feh.1: $!");
while (my $line = <$man_fh>) {

	if ($line =~ /^\.It Cm (?:-(?<short>.) , )?--(?<long>[\w-]+)/) {
		push(@{$options->{$+{long}}}, ['manual', $+{short}]);
	}

}
close($man_fh);

foreach my $option (keys %{$options}) {
	my $last;
	my $count = 0;

	if ($option =~ / ^ action\d | help /x) {
		next;
	}

	foreach my $source (@{$options->{$option}}) {
		my $name = $source->[0];
		my $short = $source->[1] // '';
		$short = '' if ($short =~ /^\d+$/);

		if (not defined $last) {
			$last = $short;
		}

		if ($last ne $short) {
			last;
		}

		$last = $short;
		$count++;
	}

	if ($count == 3) {
		next;
	}

	foreach my $source (@{$options->{$option}}) {
		my $name = $source->[0];
		my $short = $source->[1] // '';
		print "$option: $name ($short)\n";
	}
}