1#!/bin/sh
2# $Id: MKtermsort.sh,v 1.6 2000/01/25 11:35:36 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
18echo "/*";
19echo " * termsort.c --- sort order arrays for use by infocmp.";
20echo " *";
21echo " * Note: this file is generated using MKtermsort.sh, do not edit by hand.";
22echo " */";
23
24echo "static const int bool_terminfo_sort[] = {";
25$AWK <$DATA '
26BEGIN           {i = 0;}
27/^#/            {next;}
28$3 == "bool"    {printf("%s\t%d\n", $2, i++);}
29' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
30echo "};";
31echo "";
32
33echo "static const int num_terminfo_sort[] = {";
34$AWK <$DATA '
35BEGIN           {i = 0;}
36/^#/            {next;}
37$3 == "num"     {printf("%s\t%d\n", $2, i++);}
38' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
39echo "};";
40echo "";
41
42echo "static const int str_terminfo_sort[] = {";
43$AWK <$DATA '
44BEGIN           {i = 0;}
45/^#/            {next;}
46$3 == "str"     {printf("%s\t%d\n", $2, i++);}
47' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
48echo "};";
49echo "";
50
51echo "static const int bool_variable_sort[] = {";
52$AWK <$DATA '
53BEGIN           {i = 0;}
54/^#/            {next;}
55$3 == "bool"    {printf("%s\t%d\n", $1, i++);}
56' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
57echo "};";
58echo "";
59
60echo "static const int num_variable_sort[] = {";
61$AWK <$DATA '
62BEGIN           {i = 0;}
63/^#/            {next;}
64$3 == "num"     {printf("%s\t%d\n", $1, i++);}
65' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
66echo "};";
67echo "";
68
69echo "static const int str_variable_sort[] = {";
70$AWK <$DATA '
71BEGIN           {i = 0;}
72/^#/            {next;}
73$3 == "str"     {printf("%s\t%d\n", $1, i++);}
74' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
75echo "};";
76echo "";
77
78echo "static const int bool_termcap_sort[] = {";
79$AWK <$DATA '
80BEGIN           {i = 0;}
81/^#/            {next;}
82$3 == "bool"    {printf("%s\t%d\n", $4, i++);}
83' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
84echo "};";
85echo "";
86
87echo "static const int num_termcap_sort[] = {";
88$AWK <$DATA '
89BEGIN           {i = 0;}
90/^#/            {next;}
91$3 == "num"     {printf("%s\t%d\n", $4, i++);}
92' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
93echo "};";
94echo "";
95
96echo "static const int str_termcap_sort[] = {";
97$AWK <$DATA '
98BEGIN           {i = 0;}
99/^#/            {next;}
100$3 == "str"     {printf("%s\t%d\n", $4, i++);}
101' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
102echo "};";
103echo "";
104
105echo "static const bool bool_from_termcap[] = {";
106$AWK <$DATA '
107$3 == "bool" && substr($5, 1, 1) == "-"       {print "\tFALSE,\t/* ", $2, " */";}
108$3 == "bool" && substr($5, 1, 1) == "Y"       {print "\tTRUE,\t/* ", $2, " */";}
109'
110echo "};";
111echo "";
112
113echo "static const bool num_from_termcap[] = {";
114$AWK <$DATA '
115$3 == "num" && substr($5, 1, 1) == "-"        {print "\tFALSE,\t/* ", $2, " */";}
116$3 == "num" && substr($5, 1, 1) == "Y"        {print "\tTRUE,\t/* ", $2, " */";}
117'
118echo "};";
119echo "";
120
121echo "static const bool str_from_termcap[] = {";
122$AWK <$DATA '
123$3 == "str" && substr($5, 1, 1) == "-"        {print "\tFALSE,\t/* ", $2, " */";}
124$3 == "str" && substr($5, 1, 1) == "Y"        {print "\tTRUE,\t/* ", $2, " */";}
125'
126echo "};";
127echo "";
128