Cover V04, I04
Article
Listing 1

jul95.tar


Listing 1: buildinfo script

#!/bin/sh
#
#       buildinfo
#
#       Build a new terminfo.src from the binary terminfo files
#       present in the /usr/share/lib/terminfo directories.  If
#       entries are already present, keep them without change.  If
#       a new entry is found, append it to the source file.
#
#       Copyright 1995, by Lawrence S Reznick -- 1995Apr29

usage ()
{
echo "usage: $0 [-hqv] [-d terminfodir] [-o sourcefile]\n"
echo "Update terminfo source file ($TIOUT)"
echo "from $MASTERDIR directory entries.\n"
echo "Options:"
echo "-h\tHelp: See this usage message."
echo "-q\tQuiet: Show no output."
echo "-v\tVerbose: Tell all new & old entries."
echo "-d\tSet terminfo directory to scan."
echo "-o\tSet terminfo source file name to add entries."
}

# Set defaults.

MASTERDIR=/usr/share/lib/terminfo
TIOUT=terminfo.src

# Find out what the user prefers.
# Default (no -v and no -q) shows current terminfo name under
# examination.  Scroll its name back if it gets added to the
# source file.  Otherwise:
#       -v      announce names found in the source file (kept).
#       -q      don't show adding messages.
#       -v -q   show only kept names.

while getopts "hqvd:o:" OP
do
case $OP in
v)      # TRUE = Tell about existing entries
VERBOSE=t
;;

q)      # TRUE = Don't tell about add entries
QUIET=t
;;

d)      # Use another dir for compiled terminfo entries
MASTERDIR=$OPTARG
;;

o)      # Use another source file name for results
TIOUT=$OPTARG
;;

h | \?)
usage
exit 1
;;
esac
done

# Make sure the output file is present without destroying it.

touch $TIOUT

# Make sure all temp files are removed

trap "rm -f *.$$; exit" 0 1 2 3 15

# Collect list of already present terminfo definitions.  Definition
# lines begin at the left margin, excluding comments.  Any line
# starting with a space or tab can't be a definition line.

LISTFILE=tilist.$$
egrep '^[^ #    ]' $TIOUT >$LISTFILE

# Step through each terminfo directory.  Assume that most terminfo
# names start with a lowercase letter.  Most of the rest start with
# either digits or uppercase letters.  Catch whatever remains in
# ASCII order.

for TIDIR in ${MASTERDIR}/[a-z] ${MASTERDIR}/[!a-z]
do
# Check each file in this directory

for TIPATH in $TIDIR/*
do
TIFILE=`basename $TIPATH`
test -n "$QUIET" || echo "$TIFILE\t\t\r\c"

# Some terminfo aliases contain plus signs.  These
# conflict with an egrep RE char unless escaped.
# Double backslashes deliver one backslash.  Double the
# doubling to deliver a double backslash to TIFILE.

T=`echo "$TIFILE" | sed 's/+/\\\\+/g'`

# Be sure to match only terminfo names.  They are always
# followed by a vertical bar.  If a bar isn't present, a
# trailing comma at the end of the line signals a single
# name without an alias.  Can't put a ? after both
# escaped bars or egrep might match a coincidental word
# in the description phrase.

MATCHSTR="\|?${T}\||^${T},$"

if `egrep "$MATCHSTR" $LISTFILE >/dev/null 2>&1`
then
test -n "$VERBOSE" && echo Kept $TIFILE.
else
# Add new name's definition

infocmp $TIFILE |
tee -a $TIOUT |
egrep '^[^ #    ]' >>$LISTFILE

test -n "$QUIET" || echo Added $TIFILE.
fi
done
done

egrep '^[^ #    ]' $TIOUT |
sort |
uniq -c |
egrep -v '^ *1 ' >duplist.$$

if [ -s duplist.$$ ]
then
echo "Duplicates found:"
cat duplist.$$
fi