Annotation of src/usr.bin/tic/MKtermsort.sh, Revision 1.5
1.1 millert 1: #!/bin/sh
1.5 ! nicm 2: # $OpenBSD$
! 3: # $Id: MKtermsort.sh,v 1.10 2008/07/12 20:22:54 tom Exp $
1.1 millert 4: #
5: # MKtermsort.sh -- generate indirection vectors for the various sort methods
6: #
1.5 ! nicm 7: ##############################################################################
! 8: # Copyright (c) 1998-2003,2008 Free Software Foundation, Inc. #
! 9: # #
! 10: # Permission is hereby granted, free of charge, to any person obtaining a #
! 11: # copy of this software and associated documentation files (the "Software"), #
! 12: # to deal in the Software without restriction, including without limitation #
! 13: # the rights to use, copy, modify, merge, publish, distribute, distribute #
! 14: # with modifications, sublicense, and/or sell copies of the Software, and to #
! 15: # permit persons to whom the Software is furnished to do so, subject to the #
! 16: # following conditions: #
! 17: # #
! 18: # The above copyright notice and this permission notice shall be included in #
! 19: # all copies or substantial portions of the Software. #
! 20: # #
! 21: # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
! 22: # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
! 23: # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
! 24: # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
! 25: # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
! 26: # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
! 27: # DEALINGS IN THE SOFTWARE. #
! 28: # #
! 29: # Except as contained in this notice, the name(s) of the above copyright #
! 30: # holders shall not be used in advertising or otherwise to promote the sale, #
! 31: # use or other dealings in this Software without prior written #
! 32: # authorization. #
! 33: ##############################################################################
! 34: #
1.1 millert 35: # The output of this script is C source for nine arrays that list three sort
36: # orders for each of the three different classes of terminfo capabilities.
37: #
1.4 millert 38: # keep the order independent of locale:
1.5 ! nicm 39: if test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi
! 40: if test "${LANG+set}" = set; then LANG=C; export LANG; fi
! 41: if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
! 42: if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
! 43: if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
! 44: if test "${LC_COLLATE+set}" = set; then LC_COLLATE=C; export LC_COLLATE; fi
1.2 millert 45: #
1.1 millert 46: AWK=${1-awk}
47: DATA=${2-../include/Caps}
48:
1.5 ! nicm 49: data=data$$
! 50: trap 'rm -f $data' 1 2 5 15
! 51: sed -e 's/[ ][ ]*/ /g' < $DATA >$data
! 52: DATA=$data
! 53:
1.1 millert 54: echo "/*";
55: echo " * termsort.c --- sort order arrays for use by infocmp.";
56: echo " *";
1.3 millert 57: echo " * Note: this file is generated using MKtermsort.sh, do not edit by hand.";
1.1 millert 58: echo " */";
59:
1.5 ! nicm 60: echo "static const PredIdx bool_terminfo_sort[] = {";
1.1 millert 61: $AWK <$DATA '
62: BEGIN {i = 0;}
63: /^#/ {next;}
64: $3 == "bool" {printf("%s\t%d\n", $2, i++);}
65: ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
66: echo "};";
67: echo "";
68:
1.5 ! nicm 69: echo "static const PredIdx num_terminfo_sort[] = {";
1.1 millert 70: $AWK <$DATA '
71: BEGIN {i = 0;}
72: /^#/ {next;}
73: $3 == "num" {printf("%s\t%d\n", $2, i++);}
74: ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
75: echo "};";
76: echo "";
77:
1.5 ! nicm 78: echo "static const PredIdx str_terminfo_sort[] = {";
1.1 millert 79: $AWK <$DATA '
80: BEGIN {i = 0;}
81: /^#/ {next;}
82: $3 == "str" {printf("%s\t%d\n", $2, i++);}
83: ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
84: echo "};";
85: echo "";
86:
1.5 ! nicm 87: echo "static const PredIdx bool_variable_sort[] = {";
1.1 millert 88: $AWK <$DATA '
89: BEGIN {i = 0;}
90: /^#/ {next;}
91: $3 == "bool" {printf("%s\t%d\n", $1, i++);}
92: ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
93: echo "};";
94: echo "";
95:
1.5 ! nicm 96: echo "static const PredIdx num_variable_sort[] = {";
1.1 millert 97: $AWK <$DATA '
98: BEGIN {i = 0;}
99: /^#/ {next;}
100: $3 == "num" {printf("%s\t%d\n", $1, i++);}
101: ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
102: echo "};";
103: echo "";
104:
1.5 ! nicm 105: echo "static const PredIdx str_variable_sort[] = {";
1.1 millert 106: $AWK <$DATA '
107: BEGIN {i = 0;}
108: /^#/ {next;}
109: $3 == "str" {printf("%s\t%d\n", $1, i++);}
110: ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
111: echo "};";
112: echo "";
113:
1.5 ! nicm 114: echo "static const PredIdx bool_termcap_sort[] = {";
1.1 millert 115: $AWK <$DATA '
116: BEGIN {i = 0;}
117: /^#/ {next;}
118: $3 == "bool" {printf("%s\t%d\n", $4, i++);}
119: ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
120: echo "};";
121: echo "";
122:
1.5 ! nicm 123: echo "static const PredIdx num_termcap_sort[] = {";
1.1 millert 124: $AWK <$DATA '
125: BEGIN {i = 0;}
126: /^#/ {next;}
127: $3 == "num" {printf("%s\t%d\n", $4, i++);}
128: ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
129: echo "};";
130: echo "";
131:
1.5 ! nicm 132: echo "static const PredIdx str_termcap_sort[] = {";
1.1 millert 133: $AWK <$DATA '
134: BEGIN {i = 0;}
135: /^#/ {next;}
136: $3 == "str" {printf("%s\t%d\n", $4, i++);}
137: ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
138: echo "};";
139: echo "";
140:
1.3 millert 141: echo "static const bool bool_from_termcap[] = {";
1.1 millert 142: $AWK <$DATA '
1.5 ! nicm 143: $3 == "bool" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */";}
! 144: $3 == "bool" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */";}
1.1 millert 145: '
146: echo "};";
147: echo "";
148:
1.3 millert 149: echo "static const bool num_from_termcap[] = {";
1.1 millert 150: $AWK <$DATA '
1.5 ! nicm 151: $3 == "num" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */";}
! 152: $3 == "num" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */";}
1.1 millert 153: '
154: echo "};";
155: echo "";
156:
1.3 millert 157: echo "static const bool str_from_termcap[] = {";
1.1 millert 158: $AWK <$DATA '
1.5 ! nicm 159: $3 == "str" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */";}
! 160: $3 == "str" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */";}
1.1 millert 161: '
162: echo "};";
163: echo "";
1.5 ! nicm 164:
! 165: rm -f $data