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