]> sjero.net Git - wget/blob - util/freeopts
NEWS: cite --start-pos
[wget] / util / freeopts
1 #!/usr/bin/perl -n
2 # NOTE the use of -n above; this script is called in a loop.
3 use warnings;
4 use strict;
5
6 our $scanning;
7 our %used_chars;
8 BEGIN {
9     $scanning = 0;
10     %used_chars = ();
11
12     open STDIN, "../src/main.c" or die "main.c: $!\n";
13 }
14
15 if (/^static struct cmdline_option option_data/) {
16     $scanning = 1;
17 }
18 elsif (/[}];/) {
19     $scanning = 0;
20 }
21 elsif (
22     $scanning &&
23     /^[\t ]*\{ "[^"]*", '(.)', OPT_[A-Z0-9_]*, /
24 ) {
25     $used_chars{$1} = 1;
26 }
27
28 END {
29     my $cols = 0;
30     my $max_cols = 13;
31     my $opt_chars =
32     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
33     print "Free chars:\n\t";
34     for (my $i = 0; $i < length $opt_chars; ++$i, ++$cols) {
35         if ($cols == $max_cols) {
36             $cols = 0;
37             print "\n\t";
38         }
39         my $opt = substr($opt_chars,$i,1);
40         print ' ';
41         if (!$used_chars{ $opt }) {
42             print "-$opt";
43         } else {
44             print '  ';
45         }
46     }
47     print "\n";
48 }