From: Ian Jackson Date: Sat, 7 Jan 2012 17:09:48 +0000 (+0000) Subject: option parsing X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/xfonts-traditional/commitdiff_plain/a2d36db5774da9722b063932449f89db4955bd73 option parsing --- diff --git a/utility b/utility index 26ed243..8cff135 100755 --- a/utility +++ b/utility @@ -2,8 +2,12 @@ use strict; use POSIX; use IO::File; +use Getopt::Long; -our @rulespath=('.'); +our $package='xfonts-traditional'; +our $sharedir="/usr/share/$package"; +our @rulespath; +our $mode; sub loadrules ($) { my ($key) = @_; @@ -79,9 +83,34 @@ sub processbdf ($$) { die unless $state eq 'idle'; } -processbdf((new IO::File '<&STDIN'), - (new IO::File '>&STDOUT')); +our (@options)=( + 'R|rules-include=s@' => \@rulespath, + 'share-dir=s' => \$sharedir, + ); +sub define_mode ($$) { + my ($optname,$f) = @_; + push @options, $optname, sub { + die "only one mode may be specified\n" if defined $mode; + $mode=$f; + }; +} + +define_mode('bdf-filter', sub { + die if @ARGV; + + processbdf((new IO::File '<&STDIN'), + (new IO::File '>&STDOUT')); +}); + +Getopt::Long::Configure(qw(bundling)); +GetOptions(@options) or exit 127; + +push @rulespath, "$sharedir/rules" unless @rulespath; + +die "need a mode\n" unless $mode; + +$mode->(); # 70 zcat /usr/share/fonts/X11/misc/6x13.pcf.gz |pcf2bdf >in.bdf # 71 ./utility out.bdf