1#!/bin/sh 2############################################################################## 3# Copyright 2020-2023,2025 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.32 2025/09/20 18:24:34 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 40terminfo_dir=$1 41shift 42 43terminfo_src=$1 44shift 45 46tic_path=$1 47[ -z "$tic_path" ] && tic_path=tic 48shift 49 50infocmp_path=$1 51[ -z "$infocmp_path" ] && infocmp_path=infocmp 52shift 53 54case "$tic_path" in #(vi 55/*) 56 tic_head=`echo "$tic_path" | sed -e 's,/[^/]*$,,'` 57 PATH=$tic_head:$PATH 58 export PATH 59 ;; 60esac 61 62if [ $# != 0 ]; then 63 tmp_info=`pwd`/tmp_info 64 echo creating temporary terminfo directory... >&2 65 66 rm -rf "$tmp_info" 67 mkdir -p "$tmp_info" 68 69 "$tic_path" -o $tmp_info -x "$terminfo_src" >&2 70else 71 tmp_info= 72fi 73 74cat <<EOF 75/* This file was generated by $0 */ 76 77/* 78 * DO NOT EDIT THIS FILE BY HAND! 79 */ 80 81#include <curses.priv.h> 82 83EOF 84 85if [ "$*" ] 86then 87 opt_info= 88 [ -n "$tmp_info" ] && opt_info="-A $tmp_info" 89 cat <<EOF 90#include <tic.h> 91 92/* fallback entries for: $* */ 93EOF 94 for x in "$@" 95 do 96 echo "/* $x */" 97 "$infocmp_path" -x $opt_info -E "$x" | sed -e 's/[ ]short[ ]/ NCURSES_INT2 /g' 98 done 99 100 cat <<EOF 101static const TERMTYPE2 fallbacks[$#] = 102{ 103EOF 104 comma="" 105 for x in "$@" 106 do 107 echo "$comma /* $x */" 108 "$infocmp_path" -x $opt_info -e "$x" 109 comma="," 110 done 111 112 cat <<EOF 113}; 114 115EOF 116fi 117 118cat <<EOF 119NCURSES_EXPORT(const TERMTYPE2 *) 120_nc_fallback2 (const char *name GCC_UNUSED) 121{ 122EOF 123 124if [ "$*" ] 125then 126 cat <<EOF 127 const TERMTYPE2 *tp; 128 129 for (tp = fallbacks; 130 tp < fallbacks + sizeof(fallbacks)/sizeof(TERMTYPE2); 131 tp++) { 132 if (_nc_name_match(tp->term_names, name, "|")) { 133 return(tp); 134 } 135 } 136EOF 137else 138 echo " /* the fallback list is empty */"; 139fi 140 141cat <<EOF 142 return((const TERMTYPE2 *)0); 143} 144 145#if NCURSES_EXT_NUMBERS 146#undef _nc_fallback 147 148NCURSES_EXPORT(const TERMTYPE *) 149_nc_fallback (const char *name) 150{ 151 const TERMTYPE2 *tp = _nc_fallback2(name); 152 const TERMTYPE *result = NULL; 153 if (tp != NULL) { 154 static TERMTYPE temp; 155 _nc_export_termtype2(&temp, tp); 156 result = &temp; 157 } 158 return result; 159} 160#endif 161EOF 162 163if [ -n "$tmp_info" ] ; then 164 echo removing temporary terminfo directory... >&2 165 rm -rf "$tmp_info" 166fi 167