blob: 02b36ed739b24f0cf358a0f88f48795974ce7338 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301#!/bin/sh
2##############################################################################
micky3879b9f5e72025-07-08 18:04:53 -04003# Copyright 2020,2023 Thomas E. Dickey #
4# Copyright 1998-2019,2020 Free Software Foundation, Inc. #
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05305# #
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##############################################################################
micky3879b9f5e72025-07-08 18:04:53 -040030# $Id: MKfallback.sh,v 1.26 2023/04/22 15:12:57 tom Exp $
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053031#
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
Steve Kondikae271bc2015-11-15 02:50:53 +010046tic_path=$1
micky3879b9f5e72025-07-08 18:04:53 -040047test -z "$tic_path" && tic_path=tic
Steve Kondikae271bc2015-11-15 02:50:53 +010048shift
49
micky3879b9f5e72025-07-08 18:04:53 -040050infocmp_path=$1
51test -z "$infocmp_path" && infocmp_path=infocmp
52shift
53
54case "$tic_path" in #(vi
Steve Kondikae271bc2015-11-15 02:50:53 +010055/*)
56 tic_head=`echo "$tic_path" | sed -e 's,/[^/]*$,,'`
57 PATH=$tic_head:$PATH
58 export PATH
59 ;;
60esac
61
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053062if 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
micky3879b9f5e72025-07-08 18:04:53 -040072 "$tic_path" -x "$terminfo_src" >&2
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053073else
74 tmp_info=
75fi
76
77cat <<EOF
micky3879b9f5e72025-07-08 18:04:53 -040078/* This file was generated by $0 */
79
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053080/*
micky3879b9f5e72025-07-08 18:04:53 -040081 * DO NOT EDIT THIS FILE BY HAND!
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053082 */
83
84#include <curses.priv.h>
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053085
86EOF
87
88if [ "$*" ]
89then
90 cat <<EOF
91#include <tic.h>
92
93/* fallback entries for: $* */
94EOF
micky3879b9f5e72025-07-08 18:04:53 -040095 for x in "$@"
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053096 do
97 echo "/* $x */"
micky3879b9f5e72025-07-08 18:04:53 -040098 "$infocmp_path" -E "$x" | sed -e 's/\<short\>/NCURSES_INT2/g'
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053099 done
100
101 cat <<EOF
micky3879b9f5e72025-07-08 18:04:53 -0400102static const TERMTYPE2 fallbacks[$#] =
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530103{
104EOF
105 comma=""
micky3879b9f5e72025-07-08 18:04:53 -0400106 for x in "$@"
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530107 do
108 echo "$comma /* $x */"
micky3879b9f5e72025-07-08 18:04:53 -0400109 "$infocmp_path" -e "$x"
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530110 comma=","
111 done
112
113 cat <<EOF
114};
115
116EOF
117fi
118
119cat <<EOF
micky3879b9f5e72025-07-08 18:04:53 -0400120NCURSES_EXPORT(const TERMTYPE2 *)
121_nc_fallback2 (const char *name GCC_UNUSED)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530122{
123EOF
124
125if [ "$*" ]
126then
127 cat <<EOF
micky3879b9f5e72025-07-08 18:04:53 -0400128 const TERMTYPE2 *tp;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530129
130 for (tp = fallbacks;
micky3879b9f5e72025-07-08 18:04:53 -0400131 tp < fallbacks + sizeof(fallbacks)/sizeof(TERMTYPE2);
132 tp++) {
133 if (_nc_name_match(tp->term_names, name, "|")) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530134 return(tp);
micky3879b9f5e72025-07-08 18:04:53 -0400135 }
136 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530137EOF
138else
139 echo " /* the fallback list is empty */";
140fi
141
142cat <<EOF
micky3879b9f5e72025-07-08 18:04:53 -0400143 return((const TERMTYPE2 *)0);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530144}
micky3879b9f5e72025-07-08 18:04:53 -0400145
146#if NCURSES_EXT_NUMBERS
147#undef _nc_fallback
148
149NCURSES_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 Kachhape6a01f52011-07-20 11:45:59 +0530162EOF
163
164if test -n "$tmp_info" ; then
165 echo removing temporary terminfo directory... >&2
166 rm -rf $tmp_info
167fi