Newsgroups: fj.sys.news,fj.lang.perl,fj.sources
Path: galaxy.trc.rwcp.or.jp!jaist-news!cs.titech!wnoc-tyo-news!sranha!sranhd!sran230!utashiro
From: utashiro@sran230.sra.co.jp (Kazumasa Utashiro)
Subject: termfix (was Re: TERMCAP(5) vs CURSES(3X))
References: <1993Feb8.212018.18699@plcri.perfect-liberty.or.jp>
Followup-To: fj.lang.perl
Organization: Software Research Associates, Inc., Japan
Date: Wed, 10 Feb 1993 04:55:18 GMT
Message-ID: <C27v0A.6sK@sran230.sra.co.jp>
Lines: 224
Xref: galaxy.trc.rwcp.or.jp fj.sys.news:2443 fj.lang.perl:210 fj.sources:3037
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.lang.perl&nb=210&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.

In article <1993Feb8.212018.18699@plcri.perfect-liberty.or.jp>
miki@plcri.perfect-liberty.or.jp (Takahito Miki) writes:
>> $B!!<+J,@lMQ$N(Btermcap$B%U%!%$%k$r:n$j!"4D6-JQ?t(BTERMCAP$B$H(B
>> TERM$B$r%;%C%H$9$k$H$3$m$^$G$O$G$-$?$O$:$J$N$G$9$,!"$=(B
>> $B$NCf$N%(%s%H%j!<$K$O!"7h$7$F(Bcs=\E[%i%d;%dr$B$O$J$$$N$K(B
>> $B$b$+$+$o$i$:!"(Bcurses$B%Q%C%1!<%8$r;H$C$F$$$k%W%m%0%i%`(B
>> $B$+$i$O!V%;%C%H%9%/%m!<%k%j!<%8%g%s!W$N%(%9%1!<%W%7!<(B
>> $B%1%s%9$,Aw$i$l$F$-$^$9!#$G$-$l$P$3$l$r;_$a$?$$$N$G$9!#(B

$B$I$N%7%9%F%`$G!"$I$&$$$&%U%!%$%k$r:n$j!"(BTERMCAP $B$H(B TERM $B$r$I(B
$B$&@_Dj$7$?$N$+$r=q$+$J$$$HEz$($k$N$OFq$7$$$H;W$$$^$9!#(B

$B<ALd$KBP$9$kD>@\E*$JEz$G$O$"$j$^$;$s$,!"0JA0(B termcap $B$rJQ99(B
$B$7$F%3%^%s%I$r5/F0$9$k$?$a$N%9%/%j%W%H$r:n$C$?$3$H$,$"$j$^$9!#(B
NEWS $B$G$7$?$i$3$l$G$&$^$/$$$/$O$:$G$9$N$G!"$h$m$7$1$l$P;n$7(B
$B$F$_$F$/$@$5$$!#(B

$B$?$H$($P(B cs $B$r;H$$$?$/$J$$$N$J$i(B

% termfix cs@ command ...

$B$N$h$&$K$G$-$^$9!#%3%^%s%I$r;XDj$7$J$1$l$PI8=`=PNO$K(B termcap
$B$N%(%s%H%j$,=PNO$5$l$k$N$G!"(B

% setenv TERMCAP "`termfix cs@`"

$B$H$9$l$P!"$:$C$H;H$($J$/$J$k$O$:$G$9!#(B

--utashiro

#!/usr/local/bin/perl
'di';
'ig00';
;#
;# termfix: fix termcap and execute command
;#
;# Copyright (c) 1992 Kazumasa Utashiro
;# Software Research Associates, Inc., Japan<utashiro@sra.co.jp>
;# InterTech Data Systems, Inc., Cupertino CA<utashiro@InterTech.COM>
;#
;# Original on 24 Mar 1992
;#
;; $rcsid = '$Id: termfix,v 1.3 1992/03/30 00:58:56 utashiro Exp $';#'
;#
;# EXAMPLES
;#termfix md@ man 5 termcap# cancel "md"
;#termfix tite@ vipw# cancel "ti" and "te"
;#termfix 'so=\E[7m' man 5 termcap# set "so"
;#termfix usue=sose man 5 termcap# set "us,ue" same as "so,se"
;#termfix usue^sose man 5 termcap# exchange "us,ue" and "so,se"
;#
;; $myname = ('termfix', split('/', $0));
;; $usage = <<_;
Usage: $myname [xx=...] [xx=yy] [xx^yy] [xx\@] [command]
xx=...set xx to ...
xx=yyset xx to yy
xx^yyexchange xx and yy
xx\@cancel xx
$rcsid
_

while ($_ = $ARGV[$[], s/^-(.+)$/$1/ && shift) {
    if (s/[fd]//) { eval "\$opt_$&++"; redo; }
    if (s/H//) { exec "nroff -man $0|".($ENV{'PAGER'}||'more')." -s"; }
    if (s/v//) { print "$rcsid\n"; exit 0; }
    if (s/.//) { print $usage; exit($& ne 'h'); }
}

($TC = `tset -IQS`) =~ s/^[\w\-]+ //# System V?  How is it pronounced?
    if $opt_f || !($TC = $ENV{'TERMCAP'}) || $TC =~ m|^/|;
$OTC = $TC;
study $OTC;

while ($_ = $ARGV[$[]) {
    if (/^(\w\w)\@$/) {
$TC =~ s/:$1[^:]*:/:/;
    }
    elsif (($a, $b) = /^(\w\w)=(\w\w)$/) {
$TC =~ s/$a([=#])[^:]*/$a$1$new/ if ($new) = ($OTC =~ /$b[=#]([^:]*)/);
    }
    elsif (($a, $b) = /^(\w\w)=(.*)$/) {
$TC =~ s/$a([=#])[^:]*/$a$1$b/;
    }
    elsif (/^(\w\w)\^(\w\w)$/) {
splice(@ARGV, 1, 0, "$1=$2", "$2=$1");
    }
    elsif (/^((\w\w){2,})([=@\^])((\w\w)*)$/) {
$L = $1; $R = $4; $op = $3; $r = '';
last if $op eq '@' && $R;
splice(@ARGV, 1, 0,
       grep((($R =~ s/^..//) && ($r = $&), s/$/$op$r/), $L =~ /../g));
    } else {
last;
    }
    print STDERR $_, "\n" if $opt_d;
    shift;
}

if (@ARGV) {
    $ENV{'TERMCAP'} = $TC;
    exec(@ARGV), die "$ARGV[0]: $!\n";
} else {
    print $TC;
    print "\n" unless $TC =~ /\n$/;
}
exit 0;

######################################################################
.00;# finish .ig
 
'di\" finish diversion--previous line must be blank
.nr nl 0-1\" fake up transition to first page again
.nr % 0\" start at page 1
';<<'.ex'; #__END__ ############# From here on it's a standard manual page #
.de XX
.ds XX \\$2
..
.XX $Date: 1992/03/30 00:58:56 $
.TH TERMFIX 1 \*(XX
.AT 3
.SH NAME
termfix \- fix termcap and execute command
.SH SYNOPSIS
.B termfix
[
.I options
]
[
.I command
]
.SH DESCRIPTION
.I Termfix
fixes current termcap temporarily and execute command
specified in arguments.  If no command is supplied, it just
prints new capability.
.PP
There are several different style options.
.IP "xx=sequence"
Specify
.I sequence
to capability
.IR xx .
Next example sets sequence ``\eE[7m'' to
.I so
and execute man command.
.nf

termfix 'so=\eE[7m' man 5 termcap

.fi
Sequence should not be two alphabetic characters.
.IP "xx=yy"
This option sets
.I xx
capability same as
.IR yy 's.
So next example sets
.I md
capability same as
.IR so .
.nf

termfix md=so man 5 termcap

.fi
Referenced capability keeps original value after any
operations.
.IP "xx^yy"
Exchange
.I xx
and
.I yy
capabilities.  Next example exchanges
.I so
and
.I us
capabilities.
.nf

termfix so^us man 5 termcap

.fi
.IP "xx@"
Disable
.I xx
capability.  Next example disables
.I te
capability.
.nf

termfix ti@ te@ man 5 termcap

.fi
.PP
If you want to replace TERMCAP environment variable with new
one, set the output of
.I termfix
to TERMCAP variable like this:
.nf

setenv TERMCAP "`termfix te@`"

.fi
.PP
Multiple capabilities can be set in one operation on every
cases.
.ne 5
.nf

        termfix mdme=sose       (md=so me=se)
        termfix sose^usue       (so^us se^ue)
        termfix mdso=us mese=ue (md=us so=us me=ue se=ue)
        termfix tite@           (ti@ te@)

.fi
If number of right values are less than left values, last
right value is used repeatedly.
.SH AUTHOR
Kazumasa Utashiro <utashiro@sra.co.jp>
.br
Software Research Associates, Inc., Japan
.SH "SEE ALSO"
tset(1), termcap(5)
.ex
