From a32d41c5d0b878e312174f4c438e5bf40d170b60 Mon Sep 17 00:00:00 2001 From: Micah Cowan Date: Sat, 25 Oct 2008 06:49:35 -0700 Subject: [PATCH] How many options remain available? --- util/freeopts | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 util/freeopts diff --git a/util/freeopts b/util/freeopts new file mode 100755 index 00000000..0df22a79 --- /dev/null +++ b/util/freeopts @@ -0,0 +1,48 @@ +#!/usr/bin/perl -n +# NOTE the use of -n above; this script is called in a loop. +use warnings; +use strict; + +our $scanning; +our %used_chars; +BEGIN { + $scanning = 0; + %used_chars = (); + + open STDIN, "../src/main.c" or die "main.c: $!\n"; +} + +if (/^static struct cmdline_option option_data/) { + $scanning = 1; +} +elsif (/[}];/) { + $scanning = 0; +} +elsif ( + $scanning && + /^[\t ]*\{ "[^"]*", '(.)', OPT_[A-Z0-9_]*, / +) { + $used_chars{$1} = 1; +} + +END { + my $cols = 0; + my $max_cols = 13; + my $opt_chars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%+/"; + print "Free chars:\n\t"; + for (my $i = 0; $i < length $opt_chars; ++$i, ++$cols) { + if ($cols == $max_cols) { + $cols = 0; + print "\n\t"; + } + my $opt = substr($opt_chars,$i,1); + print ' '; + if (!$used_chars{ $opt }) { + print $opt; + } else { + print ' '; + } + } + print "\n"; +} -- 2.39.2