17c478bd9Sstevel@tonic-gate#!/bin/ksh 27c478bd9Sstevel@tonic-gate# 37c478bd9Sstevel@tonic-gate# CDDL HEADER START 47c478bd9Sstevel@tonic-gate# 57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 67c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only 77c478bd9Sstevel@tonic-gate# (the "License"). You may not use this file except in compliance 87c478bd9Sstevel@tonic-gate# with the License. 97c478bd9Sstevel@tonic-gate# 107c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 117c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 127c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 137c478bd9Sstevel@tonic-gate# and limitations under the License. 147c478bd9Sstevel@tonic-gate# 157c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 167c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 177c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 187c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 197c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 207c478bd9Sstevel@tonic-gate# 217c478bd9Sstevel@tonic-gate# CDDL HEADER END 227c478bd9Sstevel@tonic-gate# 237c478bd9Sstevel@tonic-gate# 247c478bd9Sstevel@tonic-gate# Copyright 2004 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate# Use is subject to license terms. 267c478bd9Sstevel@tonic-gate# 277c478bd9Sstevel@tonic-gate# 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate# 307c478bd9Sstevel@tonic-gate# Terminal Info Generator 317c478bd9Sstevel@tonic-gate# 327c478bd9Sstevel@tonic-gate# This script generates a static terminfo database for use by mdb. For each 337c478bd9Sstevel@tonic-gate# of the terminal properties used by mdb_termio.c, this script uses tput(1) 347c478bd9Sstevel@tonic-gate# to determine the value of the given attribute for each specified terminal 357c478bd9Sstevel@tonic-gate# type. The script produces an ANSI-C source file which contains a static 367c478bd9Sstevel@tonic-gate# array for each terminal type storing the properties. An additional array 377c478bd9Sstevel@tonic-gate# is then declared containing a list of the terminal types and pointers to 387c478bd9Sstevel@tonic-gate# the previous arrays. Finally, source code for several terminfo routines 397c478bd9Sstevel@tonic-gate# are included that simply access the arrays and return the saved properties. 407c478bd9Sstevel@tonic-gate# 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gatePATH=/usr/bin; export PATH 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gatePROGNAME=$(basename "$0") 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gateusage() 477c478bd9Sstevel@tonic-gate{ 487c478bd9Sstevel@tonic-gate echo "Usage: $PROGNAME -s skel -t termio [-v] term ..." >&2 497c478bd9Sstevel@tonic-gate exit 2 507c478bd9Sstevel@tonic-gate} 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gateextract_section() 537c478bd9Sstevel@tonic-gate{ 547c478bd9Sstevel@tonic-gate typeset skel="$1" 557c478bd9Sstevel@tonic-gate typeset secname="$2" 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate nawk <$skel -v name=$secname -v skel=$skel ' 587c478bd9Sstevel@tonic-gate /\/\* [^ ]* [^ ]* \*\// && $3 == name { 597c478bd9Sstevel@tonic-gate if ($2 == "BEGIN") { 607c478bd9Sstevel@tonic-gate printing = 1; 617c478bd9Sstevel@tonic-gate printf("# %d \"%s\"\n", NR + 1, skel); 627c478bd9Sstevel@tonic-gate } else { 637c478bd9Sstevel@tonic-gate printing = 0; 647c478bd9Sstevel@tonic-gate } 657c478bd9Sstevel@tonic-gate next; 667c478bd9Sstevel@tonic-gate } 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate printing != 0 { print; } 697c478bd9Sstevel@tonic-gate ' 707c478bd9Sstevel@tonic-gate} 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gateverbose=false 737c478bd9Sstevel@tonic-gatetermio_c= 747c478bd9Sstevel@tonic-gateterminfo_skel= 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gatewhile getopts s:t:v name ; do 777c478bd9Sstevel@tonic-gate case $name in 787c478bd9Sstevel@tonic-gate v) 797c478bd9Sstevel@tonic-gate verbose=true 807c478bd9Sstevel@tonic-gate ;; 817c478bd9Sstevel@tonic-gate s) 827c478bd9Sstevel@tonic-gate terminfo_skel=$OPTARG 837c478bd9Sstevel@tonic-gate ;; 847c478bd9Sstevel@tonic-gate t) 857c478bd9Sstevel@tonic-gate termio_c=$OPTARG 867c478bd9Sstevel@tonic-gate ;; 877c478bd9Sstevel@tonic-gate ?) 887c478bd9Sstevel@tonic-gate usage 897c478bd9Sstevel@tonic-gate ;; 907c478bd9Sstevel@tonic-gate esac 917c478bd9Sstevel@tonic-gatedone 927c478bd9Sstevel@tonic-gateshift $(($OPTIND - 1)) 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate[[ -z "$terminfo_skel" || -z "$termio_c" || $# -eq 0 ]] && usage 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gatetermlist=$* 977c478bd9Sstevel@tonic-gatefor term in $termlist; do 987c478bd9Sstevel@tonic-gate tput -T $term init >/dev/null 2>&1 997c478bd9Sstevel@tonic-gate if [ $? -ne 0 ]; then 1007c478bd9Sstevel@tonic-gate echo "`basename $0`: invalid terminal -- $term" >& 2 1017c478bd9Sstevel@tonic-gate exit 1 1027c478bd9Sstevel@tonic-gate fi 1037c478bd9Sstevel@tonic-gatedone 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate# Extract the prologue from the skeleton 1067c478bd9Sstevel@tonic-gateextract_section $terminfo_skel PROLOGUE 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate# 1097c478bd9Sstevel@tonic-gate# For each terminal in the terminal list, produce a property definition array 1107c478bd9Sstevel@tonic-gate# listing each property we need in mdb_termio.c and its current value. 1117c478bd9Sstevel@tonic-gate# 1127c478bd9Sstevel@tonic-gatefor term in $termlist; do 1137c478bd9Sstevel@tonic-gate # 1147c478bd9Sstevel@tonic-gate # We don't want the compiler to blame the skeleton if it doesn't like 1157c478bd9Sstevel@tonic-gate # the array we generate here, so point the finger elsewhere 1167c478bd9Sstevel@tonic-gate # 1177c478bd9Sstevel@tonic-gate echo "# 1 \"dynamic $term data from tigen\"" 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate cterm=$(echo "$term" |tr '-' '_') 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate $verbose && echo "loading terminfo for $term ... \c" >& 2 1227c478bd9Sstevel@tonic-gate echo "static const termio_attr_t ${cterm}_attrs[] = {" 1237c478bd9Sstevel@tonic-gate 124*84441f85SGarrett D'Amore sed -n '/termio_attrs\[\] = /,/^}/p' $termio_c | \ 1257c478bd9Sstevel@tonic-gate sed -n \ 's/{ "\([a-z0-9]*\)", \([A-Z_]*\),.*/\1 \2/p' | \ 1267c478bd9Sstevel@tonic-gate while read attr type; do 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate case "$type" in 1297c478bd9Sstevel@tonic-gate TIO_ATTR_REQSTR|TIO_ATTR_STR) 1307c478bd9Sstevel@tonic-gate data="\"`tput -T $term $attr | od -bv | 1317c478bd9Sstevel@tonic-gate sed 's/^[0-9]*//;s/ /\\\\\\\\/g;/^\$/d'`\"" 1327c478bd9Sstevel@tonic-gate [ "$data" = '""' ] && data=NULL 1337c478bd9Sstevel@tonic-gate ;; 1347c478bd9Sstevel@tonic-gate TIO_ATTR_BOOL) 1357c478bd9Sstevel@tonic-gate tput -T $term $attr 1367c478bd9Sstevel@tonic-gate data=`expr 1 - $?` 1377c478bd9Sstevel@tonic-gate ;; 1387c478bd9Sstevel@tonic-gate TIO_ATTR_INT) 1397c478bd9Sstevel@tonic-gate data=`tput -T $term $attr` 1407c478bd9Sstevel@tonic-gate ;; 1417c478bd9Sstevel@tonic-gate *) 1427c478bd9Sstevel@tonic-gate echo "`basename $0`: unknown type for $attr: $type" >& 2 1437c478bd9Sstevel@tonic-gate exit 1 1447c478bd9Sstevel@tonic-gate esac 1457c478bd9Sstevel@tonic-gate echo "\t{ \"$attr\", $type, (void *)$data }," 1467c478bd9Sstevel@tonic-gate done 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate echo "\t{ NULL, NULL, NULL }" 1497c478bd9Sstevel@tonic-gate echo "};\n" 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate $verbose && echo "done" >& 2 1527c478bd9Sstevel@tonic-gatedone 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate# 1557c478bd9Sstevel@tonic-gate# For each terminal in the terminal list, produce an entry in the terminal 1567c478bd9Sstevel@tonic-gate# database array linking this terminal to its terminfo property array. 1577c478bd9Sstevel@tonic-gate# 1587c478bd9Sstevel@tonic-gateecho "# 1 \"dynamic array from tigen\"" 1597c478bd9Sstevel@tonic-gateecho "static const termio_desc_t termio_db[] = {" 1607c478bd9Sstevel@tonic-gatefor term in $termlist; do 1617c478bd9Sstevel@tonic-gate cterm=$(echo "$term" |tr '-' '_') 1627c478bd9Sstevel@tonic-gate echo "\t{ \"$term\", ${cterm}_attrs }," 1637c478bd9Sstevel@tonic-gatedone 1647c478bd9Sstevel@tonic-gateecho "\t{ NULL, NULL }\n};" 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gateextract_section $terminfo_skel EPILOGUE 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gateexit 0 169