]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/MKfallback.sh
ncurses 6.2 - patch 20210821
[ncurses.git] / ncurses / tinfo / MKfallback.sh
1 #!/bin/sh
2 ##############################################################################
3 # Copyright 2020 Thomas E. Dickey                                            #
4 # Copyright 1998-2019,2020 Free Software Foundation, Inc.                    #
5 #                                                                            #
6 # Permission is hereby granted, free of charge, to any person obtaining a    #
7 # copy of this software and associated documentation files (the "Software"), #
8 # to deal in the Software without restriction, including without limitation  #
9 # the rights to use, copy, modify, merge, publish, distribute, distribute    #
10 # with modifications, sublicense, and/or sell copies of the Software, and to #
11 # permit persons to whom the Software is furnished to do so, subject to the  #
12 # following conditions:                                                      #
13 #                                                                            #
14 # The above copyright notice and this permission notice shall be included in #
15 # all copies or substantial portions of the Software.                        #
16 #                                                                            #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
20 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
23 # DEALINGS IN THE SOFTWARE.                                                  #
24 #                                                                            #
25 # Except as contained in this notice, the name(s) of the above copyright     #
26 # holders shall not be used in advertising or otherwise to promote the sale, #
27 # use or other dealings in this Software without prior written               #
28 # authorization.                                                             #
29 ##############################################################################
30 # $Id: MKfallback.sh,v 1.25 2020/08/16 15:58:44 tom Exp $
31 #
32 # MKfallback.sh -- create fallback table for entry reads
33 #
34 # This script generates source code for a custom version of read_entry.c
35 # that (instead of reading capabilities for an argument terminal type
36 # from an on-disk terminfo tree) tries to match the type with one of a
37 # specified list of types generated in.
38 #
39
40 terminfo_dir=$1
41 shift
42
43 terminfo_src=$1
44 shift
45
46 tic_path=$1
47 test -z "$tic_path" && tic_path=tic
48 shift
49
50 infocmp_path=$1
51 test -z "$infocmp_path" && infocmp_path=infocmp
52 shift
53
54 case "$tic_path" in #(vi
55 /*)
56         tic_head=`echo "$tic_path" | sed -e 's,/[^/]*$,,'`
57         PATH=$tic_head:$PATH
58         export PATH
59         ;;
60 esac
61
62 if test $# != 0 ; then
63         tmp_info=tmp_info
64         echo creating temporary terminfo directory... >&2
65
66         TERMINFO=`pwd`/$tmp_info
67         export TERMINFO
68
69         TERMINFO_DIRS=$TERMINFO:$terminfo_dir
70         export TERMINFO_DIRS
71
72         "$tic_path" -x "$terminfo_src" >&2
73 else
74         tmp_info=
75 fi
76
77 cat <<EOF
78 /* This file was generated by $0 */
79
80 /*
81  * DO NOT EDIT THIS FILE BY HAND!
82  */
83
84 #include <curses.priv.h>
85
86 EOF
87
88 if [ "$*" ]
89 then
90         cat <<EOF
91 #include <tic.h>
92
93 /* fallback entries for: $* */
94 EOF
95         for x in "$@"
96         do
97                 echo "/* $x */"
98                 "$infocmp_path" -E "$x" | sed -e 's/\<short\>/NCURSES_INT2/g'
99         done
100
101         cat <<EOF
102 static const TERMTYPE2 fallbacks[$#] =
103 {
104 EOF
105         comma=""
106         for x in "$@"
107         do
108                 echo "$comma /* $x */"
109                 "$infocmp_path" -e "$x"
110                 comma=","
111         done
112
113         cat <<EOF
114 };
115
116 EOF
117 fi
118
119 cat <<EOF
120 NCURSES_EXPORT(const TERMTYPE2 *)
121 _nc_fallback2 (const char *name GCC_UNUSED)
122 {
123 EOF
124
125 if [ "$*" ]
126 then
127         cat <<EOF
128     const TERMTYPE2     *tp;
129
130     for (tp = fallbacks;
131          tp < fallbacks + sizeof(fallbacks)/sizeof(TERMTYPE2);
132          tp++) {
133         if (_nc_name_match(tp->term_names, name, "|")) {
134             return(tp);
135         }
136     }
137 EOF
138 else
139         echo "  /* the fallback list is empty */";
140 fi
141
142 cat <<EOF
143     return((const TERMTYPE2 *)0);
144 }
145
146 #if NCURSES_EXT_NUMBERS
147 #undef _nc_fallback
148
149 /*
150  * This entrypoint is used by tack 1.07
151  */
152 NCURSES_EXPORT(const TERMTYPE *)
153 _nc_fallback (const char *name)
154 {
155     const TERMTYPE2 *tp = _nc_fallback2(name);
156     const TERMTYPE *result = 0;
157     if (tp != 0) {
158         static TERMTYPE temp;
159         _nc_export_termtype2(&temp, tp);
160         result = &temp;
161     }
162     return result;
163 }
164 #endif
165 EOF
166
167 if test -n "$tmp_info" ; then
168         echo removing temporary terminfo directory... >&2
169         rm -rf $tmp_info
170 fi