]> ncurses.scripts.mit.edu Git - ncurses.git/blob - progs/MKtermsort.sh
ncurses 4.1
[ncurses.git] / progs / MKtermsort.sh
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 #
8 AWK=${1-awk}
9 DATA=${2-../include/Caps}
10
11 echo "/*";
12 echo " * termsort.c --- sort order arrays for use by infocmp.";
13 echo " *";
14 echo " * Note: this file is generated using termsort.sh, do not edit by hand.";
15 echo " */";
16
17 echo "static const int bool_terminfo_sort[] = {";
18 $AWK <$DATA '
19 BEGIN           {i = 0;}
20 /^#/            {next;}
21 $3 == "bool"    {printf("%s\t%d\n", $2, i++);}
22 ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
23 echo "};";
24 echo "";
25
26 echo "static const int num_terminfo_sort[] = {";
27 $AWK <$DATA '
28 BEGIN           {i = 0;}
29 /^#/            {next;}
30 $3 == "num"     {printf("%s\t%d\n", $2, i++);}
31 ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
32 echo "};";
33 echo "";
34
35 echo "static const int str_terminfo_sort[] = {";
36 $AWK <$DATA '
37 BEGIN           {i = 0;}
38 /^#/            {next;}
39 $3 == "str"     {printf("%s\t%d\n", $2, i++);}
40 ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
41 echo "};";
42 echo "";
43
44 echo "static const int bool_variable_sort[] = {";
45 $AWK <$DATA '
46 BEGIN           {i = 0;}
47 /^#/            {next;}
48 $3 == "bool"    {printf("%s\t%d\n", $1, i++);}
49 ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
50 echo "};";
51 echo "";
52
53 echo "static const int num_variable_sort[] = {";
54 $AWK <$DATA '
55 BEGIN           {i = 0;}
56 /^#/            {next;}
57 $3 == "num"     {printf("%s\t%d\n", $1, i++);}
58 ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
59 echo "};";
60 echo "";
61
62 echo "static const int str_variable_sort[] = {";
63 $AWK <$DATA '
64 BEGIN           {i = 0;}
65 /^#/            {next;}
66 $3 == "str"     {printf("%s\t%d\n", $1, i++);}
67 ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
68 echo "};";
69 echo "";
70
71 echo "static const int bool_termcap_sort[] = {";
72 $AWK <$DATA '
73 BEGIN           {i = 0;}
74 /^#/            {next;}
75 $3 == "bool"    {printf("%s\t%d\n", $4, i++);}
76 ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
77 echo "};";
78 echo "";
79
80 echo "static const int num_termcap_sort[] = {";
81 $AWK <$DATA '
82 BEGIN           {i = 0;}
83 /^#/            {next;}
84 $3 == "num"     {printf("%s\t%d\n", $4, i++);}
85 ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
86 echo "};";
87 echo "";
88
89 echo "static const int str_termcap_sort[] = {";
90 $AWK <$DATA '
91 BEGIN           {i = 0;}
92 /^#/            {next;}
93 $3 == "str"     {printf("%s\t%d\n", $4, i++);}
94 ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
95 echo "};";
96 echo "";
97
98 echo "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 '
103 echo "};";
104 echo "";
105
106 echo "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 '
111 echo "};";
112 echo "";
113
114 echo "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 '
119 echo "};";
120 echo "";
121