#!/usr/bin/perl -w use Getopt::Long; use strict; use vars qw(%seq %opt @optfmt); %seq = ( title => { type => 's', code => 2 }, T => { type => 's', code => 2 }, n => { type => 's', code => 1 }, fg => { type => 's', code => 10 }, bg => { type => 's', code => 11 }, cr => { type => 's', code => 12 }, mousefg => { type => 's', code => 13 }, mousebg => { type => 's', code => 14 }, tekfg => { type => 's', code => 15 }, tekbg => { type => 's', code => 16 }, hc => { type => 's', code => 17 }, font => { type => 's', code => 50 }, fn => { type => 's', code => 50 }, geom => { type => 's', code => '' }, geometry => { type => 's', code => '' }, iconify => { type => '', code => 2 }, restore => { type => '', code => 1 }, refresh => { type => '', code => 7 }, report => { type => '', code => '' }, help => { type => '', code => '' }, ); sub die_usage { my ($status) = @_; print <<'EOF'; xtermset.pl version 0.1 - options: [-title|T window-title] [-n icon-name] [-fg color] [-bg color] [-cr color] [-mousefg color] [-mousebg color] [-tekfg color] [-tekbg color] [-hc color] [-fn|font font-spec] [-geom size-spec] [-iconify] [-restore] [-refresh] [-help] EOF exit $status; } # The only special code right now is geometry... sub print_special_opt { local ($_) = @_; if (/^(geom|geometry)$/) { if ($opt{$_} =~ /(?:(\d+)x(\d+))?(?:\+(\d+)\+(\d+))?/) { if (defined $1 and defined $2) { print "\e[8;$2;$1t"; } if (defined $3 and defined $4) { print "\e[3;$3;$4t"; } } else { warn "couldn't find geom spec"; } } elsif (/^report/) { my $pid = fork; die "can't fork" unless defined $pid; if ($pid) { print "in parent\n"; my $foo = ; #$foo =~ tr/a-zA-Z//csd; my $len = length $foo; print "OK: $len\n"; } else { print "in child\n"; print "\e]21t"; } } else { die "special option $_ has no handler"; } } sub print_normal_opt { local ($_) = @_; if ($seq{$_}{type}) { print "\e]$seq{$_}{code};$opt{$_}\a"; } else { print "\e[$seq{$_}{code}t"; } } die_usage(1) unless @ARGV; GetOptions(\%opt, map { $seq{$_}{type} ? "$_=$seq{$_}{type}" : $_ } keys %seq); die_usage(1) unless %opt; die_usage(0) if $opt{help}; foreach (keys %opt) { if ($seq{$_}{code}) { print_normal_opt($_); } else { print_special_opt($_); } }