1#!/bin/sh 2# $Id: MKtermsort.sh,v 1.7 2001/05/26 23:37:57 tom Exp $ 3# 4# MKtermsort.sh -- generate indirection vectors for the various sort methods 5# 6# The output of this script is C source for nine arrays that list three sort 7# orders for each of the three different classes of terminfo capabilities. 8# 9# keep the order independent of locale: 10LANGUAGE=C 11LC_ALL=C 12export LANGUAGE 13export LC_ALL 14# 15AWK=${1-awk} 16DATA=${2-../include/Caps} 17 18data=data$$ 19trap 'rm -f $data' 1 2 5 15 20sed -e 's/[ ]\+/ /g' < $DATA >$data 21DATA=$data 22 23echo "/*"; 24echo " * termsort.c --- sort order arrays for use by infocmp."; 25echo " *"; 26echo " * Note: this file is generated using MKtermsort.sh, do not edit by hand."; 27echo " */"; 28 29echo "static const int bool_terminfo_sort[] = {"; 30$AWK <$DATA ' 31BEGIN {i = 0;} 32/^#/ {next;} 33$3 == "bool" {printf("%s\t%d\n", $2, i++);} 34' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 35echo "};"; 36echo ""; 37 38echo "static const int num_terminfo_sort[] = {"; 39$AWK <$DATA ' 40BEGIN {i = 0;} 41/^#/ {next;} 42$3 == "num" {printf("%s\t%d\n", $2, i++);} 43' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 44echo "};"; 45echo ""; 46 47echo "static const int str_terminfo_sort[] = {"; 48$AWK <$DATA ' 49BEGIN {i = 0;} 50/^#/ {next;} 51$3 == "str" {printf("%s\t%d\n", $2, i++);} 52' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 53echo "};"; 54echo ""; 55 56echo "static const int bool_variable_sort[] = {"; 57$AWK <$DATA ' 58BEGIN {i = 0;} 59/^#/ {next;} 60$3 == "bool" {printf("%s\t%d\n", $1, i++);} 61' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 62echo "};"; 63echo ""; 64 65echo "static const int num_variable_sort[] = {"; 66$AWK <$DATA ' 67BEGIN {i = 0;} 68/^#/ {next;} 69$3 == "num" {printf("%s\t%d\n", $1, i++);} 70' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 71echo "};"; 72echo ""; 73 74echo "static const int str_variable_sort[] = {"; 75$AWK <$DATA ' 76BEGIN {i = 0;} 77/^#/ {next;} 78$3 == "str" {printf("%s\t%d\n", $1, i++);} 79' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 80echo "};"; 81echo ""; 82 83echo "static const int bool_termcap_sort[] = {"; 84$AWK <$DATA ' 85BEGIN {i = 0;} 86/^#/ {next;} 87$3 == "bool" {printf("%s\t%d\n", $4, i++);} 88' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 89echo "};"; 90echo ""; 91 92echo "static const int num_termcap_sort[] = {"; 93$AWK <$DATA ' 94BEGIN {i = 0;} 95/^#/ {next;} 96$3 == "num" {printf("%s\t%d\n", $4, i++);} 97' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 98echo "};"; 99echo ""; 100 101echo "static const int str_termcap_sort[] = {"; 102$AWK <$DATA ' 103BEGIN {i = 0;} 104/^#/ {next;} 105$3 == "str" {printf("%s\t%d\n", $4, i++);} 106' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 107echo "};"; 108echo ""; 109 110echo "static const bool bool_from_termcap[] = {"; 111$AWK <$DATA ' 112$3 == "bool" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */";} 113$3 == "bool" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */";} 114' 115echo "};"; 116echo ""; 117 118echo "static const bool num_from_termcap[] = {"; 119$AWK <$DATA ' 120$3 == "num" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */";} 121$3 == "num" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */";} 122' 123echo "};"; 124echo ""; 125 126echo "static const bool str_from_termcap[] = {"; 127$AWK <$DATA ' 128$3 == "str" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */";} 129$3 == "str" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */";} 130' 131echo "};"; 132echo ""; 133 134rm -f $data 135