Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | ############################################################################## |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 3 | # Copyright 2020,2023 Thomas E. Dickey # |
| 4 | # Copyright 1998-2019,2020 Free Software Foundation, Inc. # |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 | ############################################################################## |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 30 | # $Id: MKfallback.sh,v 1.26 2023/04/22 15:12:57 tom Exp $ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 46 | tic_path=$1 |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 47 | test -z "$tic_path" && tic_path=tic |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 48 | shift |
| 49 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 50 | infocmp_path=$1 |
| 51 | test -z "$infocmp_path" && infocmp_path=infocmp |
| 52 | shift |
| 53 | |
| 54 | case "$tic_path" in #(vi |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 55 | /*) |
| 56 | tic_head=`echo "$tic_path" | sed -e 's,/[^/]*$,,'` |
| 57 | PATH=$tic_head:$PATH |
| 58 | export PATH |
| 59 | ;; |
| 60 | esac |
| 61 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 72 | "$tic_path" -x "$terminfo_src" >&2 |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 73 | else |
| 74 | tmp_info= |
| 75 | fi |
| 76 | |
| 77 | cat <<EOF |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 78 | /* This file was generated by $0 */ |
| 79 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 80 | /* |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 81 | * DO NOT EDIT THIS FILE BY HAND! |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 82 | */ |
| 83 | |
| 84 | #include <curses.priv.h> |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 85 | |
| 86 | EOF |
| 87 | |
| 88 | if [ "$*" ] |
| 89 | then |
| 90 | cat <<EOF |
| 91 | #include <tic.h> |
| 92 | |
| 93 | /* fallback entries for: $* */ |
| 94 | EOF |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 95 | for x in "$@" |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 96 | do |
| 97 | echo "/* $x */" |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 98 | "$infocmp_path" -E "$x" | sed -e 's/\<short\>/NCURSES_INT2/g' |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 99 | done |
| 100 | |
| 101 | cat <<EOF |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 102 | static const TERMTYPE2 fallbacks[$#] = |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 103 | { |
| 104 | EOF |
| 105 | comma="" |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 106 | for x in "$@" |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 107 | do |
| 108 | echo "$comma /* $x */" |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 109 | "$infocmp_path" -e "$x" |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 110 | comma="," |
| 111 | done |
| 112 | |
| 113 | cat <<EOF |
| 114 | }; |
| 115 | |
| 116 | EOF |
| 117 | fi |
| 118 | |
| 119 | cat <<EOF |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 120 | NCURSES_EXPORT(const TERMTYPE2 *) |
| 121 | _nc_fallback2 (const char *name GCC_UNUSED) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 122 | { |
| 123 | EOF |
| 124 | |
| 125 | if [ "$*" ] |
| 126 | then |
| 127 | cat <<EOF |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 128 | const TERMTYPE2 *tp; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 129 | |
| 130 | for (tp = fallbacks; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 131 | tp < fallbacks + sizeof(fallbacks)/sizeof(TERMTYPE2); |
| 132 | tp++) { |
| 133 | if (_nc_name_match(tp->term_names, name, "|")) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 134 | return(tp); |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 135 | } |
| 136 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 137 | EOF |
| 138 | else |
| 139 | echo " /* the fallback list is empty */"; |
| 140 | fi |
| 141 | |
| 142 | cat <<EOF |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 143 | return((const TERMTYPE2 *)0); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 144 | } |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 145 | |
| 146 | #if NCURSES_EXT_NUMBERS |
| 147 | #undef _nc_fallback |
| 148 | |
| 149 | NCURSES_EXPORT(const TERMTYPE *) |
| 150 | _nc_fallback (const char *name) |
| 151 | { |
| 152 | const TERMTYPE2 *tp = _nc_fallback2(name); |
| 153 | const TERMTYPE *result = 0; |
| 154 | if (tp != 0) { |
| 155 | static TERMTYPE temp; |
| 156 | _nc_export_termtype2(&temp, tp); |
| 157 | result = &temp; |
| 158 | } |
| 159 | return result; |
| 160 | } |
| 161 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 162 | EOF |
| 163 | |
| 164 | if test -n "$tmp_info" ; then |
| 165 | echo removing temporary terminfo directory... >&2 |
| 166 | rm -rf $tmp_info |
| 167 | fi |