15f4613f2SJohn Marino#!/bin/sh 2*32bb5217SDaniel Fojt# $Id: MKtermsort.sh,v 1.13 2020/02/02 23:34:34 tom Exp $ 35f4613f2SJohn Marino# 45f4613f2SJohn Marino# MKtermsort.sh -- generate indirection vectors for the various sort methods 55f4613f2SJohn Marino# 65f4613f2SJohn Marino############################################################################## 7*32bb5217SDaniel Fojt# Copyright 2020 Thomas E. Dickey # 8*32bb5217SDaniel Fojt# Copyright 1998-2015,2017 Free Software Foundation, Inc. # 95f4613f2SJohn Marino# # 105f4613f2SJohn Marino# Permission is hereby granted, free of charge, to any person obtaining a # 115f4613f2SJohn Marino# copy of this software and associated documentation files (the "Software"), # 125f4613f2SJohn Marino# to deal in the Software without restriction, including without limitation # 135f4613f2SJohn Marino# the rights to use, copy, modify, merge, publish, distribute, distribute # 145f4613f2SJohn Marino# with modifications, sublicense, and/or sell copies of the Software, and to # 155f4613f2SJohn Marino# permit persons to whom the Software is furnished to do so, subject to the # 165f4613f2SJohn Marino# following conditions: # 175f4613f2SJohn Marino# # 185f4613f2SJohn Marino# The above copyright notice and this permission notice shall be included in # 195f4613f2SJohn Marino# all copies or substantial portions of the Software. # 205f4613f2SJohn Marino# # 215f4613f2SJohn Marino# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # 225f4613f2SJohn Marino# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # 235f4613f2SJohn Marino# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # 245f4613f2SJohn Marino# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # 255f4613f2SJohn Marino# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # 265f4613f2SJohn Marino# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # 275f4613f2SJohn Marino# DEALINGS IN THE SOFTWARE. # 285f4613f2SJohn Marino# # 295f4613f2SJohn Marino# Except as contained in this notice, the name(s) of the above copyright # 305f4613f2SJohn Marino# holders shall not be used in advertising or otherwise to promote the sale, # 315f4613f2SJohn Marino# use or other dealings in this Software without prior written # 325f4613f2SJohn Marino# authorization. # 335f4613f2SJohn Marino############################################################################## 345f4613f2SJohn Marino# 355f4613f2SJohn Marino# The output of this script is C source for nine arrays that list three sort 365f4613f2SJohn Marino# orders for each of the three different classes of terminfo capabilities. 375f4613f2SJohn Marino# 385f4613f2SJohn Marino# keep the order independent of locale: 395f4613f2SJohn Marinoif test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi 405f4613f2SJohn Marinoif test "${LANG+set}" = set; then LANG=C; export LANG; fi 415f4613f2SJohn Marinoif test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi 425f4613f2SJohn Marinoif test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi 435f4613f2SJohn Marinoif test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi 445f4613f2SJohn Marinoif test "${LC_COLLATE+set}" = set; then LC_COLLATE=C; export LC_COLLATE; fi 455f4613f2SJohn Marino# 465f4613f2SJohn MarinoAWK=${1-awk} 475f4613f2SJohn MarinoDATA=${2-../include/Caps} 485f4613f2SJohn Marino 495f4613f2SJohn Marinodata=data$$ 50*32bb5217SDaniel Fojttrap 'rm -f $data' 1 2 3 15 515f4613f2SJohn Marinosed -e 's/[ ][ ]*/ /g' < $DATA >$data 525f4613f2SJohn MarinoDATA=$data 535f4613f2SJohn Marino 545f4613f2SJohn Marinoecho "/*"; 555f4613f2SJohn Marinoecho " * termsort.c --- sort order arrays for use by infocmp."; 565f4613f2SJohn Marinoecho " *"; 575f4613f2SJohn Marinoecho " * Note: this file is generated using MKtermsort.sh, do not edit by hand."; 585f4613f2SJohn Marinoecho " */"; 595f4613f2SJohn Marino 605f4613f2SJohn Marinoecho "static const PredIdx bool_terminfo_sort[] = {"; 615f4613f2SJohn Marino$AWK <$DATA ' 625f4613f2SJohn MarinoBEGIN {i = 0;} 635f4613f2SJohn Marino/^#/ {next;} 645f4613f2SJohn Marino$3 == "bool" {printf("%s\t%d\n", $2, i++);} 655f4613f2SJohn Marino' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 665f4613f2SJohn Marinoecho "};"; 675f4613f2SJohn Marinoecho ""; 685f4613f2SJohn Marino 695f4613f2SJohn Marinoecho "static const PredIdx num_terminfo_sort[] = {"; 705f4613f2SJohn Marino$AWK <$DATA ' 715f4613f2SJohn MarinoBEGIN {i = 0;} 725f4613f2SJohn Marino/^#/ {next;} 735f4613f2SJohn Marino$3 == "num" {printf("%s\t%d\n", $2, i++);} 745f4613f2SJohn Marino' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 755f4613f2SJohn Marinoecho "};"; 765f4613f2SJohn Marinoecho ""; 775f4613f2SJohn Marino 785f4613f2SJohn Marinoecho "static const PredIdx str_terminfo_sort[] = {"; 795f4613f2SJohn Marino$AWK <$DATA ' 805f4613f2SJohn MarinoBEGIN {i = 0;} 815f4613f2SJohn Marino/^#/ {next;} 825f4613f2SJohn Marino$3 == "str" {printf("%s\t%d\n", $2, i++);} 835f4613f2SJohn Marino' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 845f4613f2SJohn Marinoecho "};"; 855f4613f2SJohn Marinoecho ""; 865f4613f2SJohn Marino 875f4613f2SJohn Marinoecho "static const PredIdx bool_variable_sort[] = {"; 885f4613f2SJohn Marino$AWK <$DATA ' 895f4613f2SJohn MarinoBEGIN {i = 0;} 905f4613f2SJohn Marino/^#/ {next;} 915f4613f2SJohn Marino$3 == "bool" {printf("%s\t%d\n", $1, i++);} 925f4613f2SJohn Marino' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 935f4613f2SJohn Marinoecho "};"; 945f4613f2SJohn Marinoecho ""; 955f4613f2SJohn Marino 965f4613f2SJohn Marinoecho "static const PredIdx num_variable_sort[] = {"; 975f4613f2SJohn Marino$AWK <$DATA ' 985f4613f2SJohn MarinoBEGIN {i = 0;} 995f4613f2SJohn Marino/^#/ {next;} 1005f4613f2SJohn Marino$3 == "num" {printf("%s\t%d\n", $1, i++);} 1015f4613f2SJohn Marino' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 1025f4613f2SJohn Marinoecho "};"; 1035f4613f2SJohn Marinoecho ""; 1045f4613f2SJohn Marino 1055f4613f2SJohn Marinoecho "static const PredIdx str_variable_sort[] = {"; 1065f4613f2SJohn Marino$AWK <$DATA ' 1075f4613f2SJohn MarinoBEGIN {i = 0;} 1085f4613f2SJohn Marino/^#/ {next;} 1095f4613f2SJohn Marino$3 == "str" {printf("%s\t%d\n", $1, i++);} 1105f4613f2SJohn Marino' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 1115f4613f2SJohn Marinoecho "};"; 1125f4613f2SJohn Marinoecho ""; 1135f4613f2SJohn Marino 1145f4613f2SJohn Marinoecho "static const PredIdx bool_termcap_sort[] = {"; 1155f4613f2SJohn Marino$AWK <$DATA ' 1165f4613f2SJohn MarinoBEGIN {i = 0;} 1175f4613f2SJohn Marino/^#/ {next;} 1185f4613f2SJohn Marino$3 == "bool" {printf("%s\t%d\n", $4, i++);} 1195f4613f2SJohn Marino' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 1205f4613f2SJohn Marinoecho "};"; 1215f4613f2SJohn Marinoecho ""; 1225f4613f2SJohn Marino 1235f4613f2SJohn Marinoecho "static const PredIdx num_termcap_sort[] = {"; 1245f4613f2SJohn Marino$AWK <$DATA ' 1255f4613f2SJohn MarinoBEGIN {i = 0;} 1265f4613f2SJohn Marino/^#/ {next;} 1275f4613f2SJohn Marino$3 == "num" {printf("%s\t%d\n", $4, i++);} 1285f4613f2SJohn Marino' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 1295f4613f2SJohn Marinoecho "};"; 1305f4613f2SJohn Marinoecho ""; 1315f4613f2SJohn Marino 1325f4613f2SJohn Marinoecho "static const PredIdx str_termcap_sort[] = {"; 1335f4613f2SJohn Marino$AWK <$DATA ' 1345f4613f2SJohn MarinoBEGIN {i = 0;} 1355f4613f2SJohn Marino/^#/ {next;} 1365f4613f2SJohn Marino$3 == "str" {printf("%s\t%d\n", $4, i++);} 1375f4613f2SJohn Marino' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}'; 1385f4613f2SJohn Marinoecho "};"; 1395f4613f2SJohn Marinoecho ""; 1405f4613f2SJohn Marino 1415f4613f2SJohn Marinoecho "static const bool bool_from_termcap[] = {"; 1425f4613f2SJohn Marino$AWK <$DATA ' 1433468e90cSJohn MarinoBEGIN { count = 0; valid = 0; } 1443468e90cSJohn Marino$3 == "bool" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */"; count++; } 1453468e90cSJohn Marino$3 == "bool" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */"; valid = count++; } 1463468e90cSJohn MarinoEND { printf "#define OK_bool_from_termcap %d\n", valid; } 1475f4613f2SJohn Marino' 1485f4613f2SJohn Marinoecho "};"; 1495f4613f2SJohn Marinoecho ""; 1505f4613f2SJohn Marino 1515f4613f2SJohn Marinoecho "static const bool num_from_termcap[] = {"; 1525f4613f2SJohn Marino$AWK <$DATA ' 1533468e90cSJohn MarinoBEGIN { count = 0; valid = 0; } 1543468e90cSJohn Marino$3 == "num" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */"; count++; } 1553468e90cSJohn Marino$3 == "num" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */"; valid = count++; } 1563468e90cSJohn MarinoEND { printf "#define OK_num_from_termcap %d\n", valid; } 1575f4613f2SJohn Marino' 1585f4613f2SJohn Marinoecho "};"; 1595f4613f2SJohn Marinoecho ""; 1605f4613f2SJohn Marino 1615f4613f2SJohn Marinoecho "static const bool str_from_termcap[] = {"; 1625f4613f2SJohn Marino$AWK <$DATA ' 1633468e90cSJohn MarinoBEGIN { count = 0; valid = 0; } 1643468e90cSJohn Marino$3 == "str" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */"; count++; } 1653468e90cSJohn Marino$3 == "str" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */"; valid = count++; } 1663468e90cSJohn MarinoEND { printf "#define OK_str_from_termcap %d\n", valid; } 1675f4613f2SJohn Marino' 1685f4613f2SJohn Marinoecho "};"; 1695f4613f2SJohn Marinoecho ""; 1705f4613f2SJohn Marino 1715f4613f2SJohn Marinorm -f $data 172