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