From a2d36db5774da9722b063932449f89db4955bd73 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 7 Jan 2012 17:09:48 +0000 Subject: [PATCH] option parsing --- utility | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) 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 -- 2.30.2