[BACK]Return to MKtermsort.sh CVS log [TXT][DIR] Up to [local] / src / usr.bin / tic

Annotation of src/usr.bin/tic/MKtermsort.sh, Revision 1.6

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