MKfallback.sh revision 302408
1184257Slulf#!/bin/sh
2184257Slulf##############################################################################
3184257Slulf# Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.                #
4184257Slulf#                                                                            #
5184257Slulf# Permission is hereby granted, free of charge, to any person obtaining a    #
6184257Slulf# copy of this software and associated documentation files (the "Software"), #
7184257Slulf# to deal in the Software without restriction, including without limitation  #
8184257Slulf# the rights to use, copy, modify, merge, publish, distribute, distribute    #
9184257Slulf# with modifications, sublicense, and/or sell copies of the Software, and to #
10184257Slulf# permit persons to whom the Software is furnished to do so, subject to the  #
11184257Slulf# following conditions:                                                      #
12184257Slulf#                                                                            #
13184257Slulf# The above copyright notice and this permission notice shall be included in #
14184257Slulf# all copies or substantial portions of the Software.                        #
15184257Slulf#                                                                            #
16184257Slulf# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
17184257Slulf# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
18184257Slulf# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
19184257Slulf# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
20184257Slulf# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
21184257Slulf# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
22184257Slulf# DEALINGS IN THE SOFTWARE.                                                  #
23184257Slulf#                                                                            #
24184257Slulf# Except as contained in this notice, the name(s) of the above copyright     #
25184257Slulf# holders shall not be used in advertising or otherwise to promote the sale, #
26184257Slulf# use or other dealings in this Software without prior written               #
27184257Slulf# authorization.                                                             #
28184257Slulf##############################################################################
29184257Slulf# $Id: MKfallback.sh,v 1.15 2010/08/07 20:32:34 tom Exp $
30184257Slulf#
31184257Slulf# MKfallback.sh -- create fallback table for entry reads
32184257Slulf#
33184257Slulf# This script generates source code for a custom version of read_entry.c
34184257Slulf# that (instead of reading capabilities for an argument terminal type
35184257Slulf# from an on-disk terminfo tree) tries to match the type with one of a
36184257Slulf# specified list of types generated in.
37184257Slulf#
38184257Slulf
39184257Slulfterminfo_dir=$1
40184257Slulfshift
41184257Slulf
42184257Slulfterminfo_src=$1
43184257Slulfshift
44184257Slulf
45184257Slulftic_path=$1
46184257Slulfshift
47184257Slulf
48184257Slulfcase $tic_path in #(vi
49184257Slulf/*)
50184257Slulf	tic_head=`echo "$tic_path" | sed -e 's,/[^/]*$,,'`
51184257Slulf	PATH=$tic_head:$PATH
52184257Slulf	export PATH
53184257Slulf	;;
54184257Slulfesac
55184257Slulf
56184257Slulfif test $# != 0 ; then
57184257Slulf	tmp_info=tmp_info
58184257Slulf	echo creating temporary terminfo directory... >&2
59184257Slulf
60184257Slulf	TERMINFO=`pwd`/$tmp_info
61184257Slulf	export TERMINFO
62184257Slulf
63184257Slulf	TERMINFO_DIRS=$TERMINFO:$terminfo_dir
64184257Slulf	export TERMINFO_DIRS
65184257Slulf
66184257Slulf	$tic_path -x $terminfo_src >&2
67184257Slulfelse
68184257Slulf	tmp_info=
69184257Slulffi
70185130Slulf
71184257Slulfcat <<EOF
72184257Slulf/*
73184257Slulf * DO NOT EDIT THIS FILE BY HAND!  It is generated by MKfallback.sh.
74185130Slulf */
75184257Slulf
76184257Slulf#include <curses.priv.h>
77184257Slulf
78184257SlulfEOF
79184257Slulf
80185094Slulfif [ "$*" ]
81184257Slulfthen
82184257Slulf	cat <<EOF
83184257Slulf#include <tic.h>
84184257Slulf
85184257Slulf/* fallback entries for: $* */
86184257SlulfEOF
87184257Slulf	for x in $*
88184257Slulf	do
89185130Slulf		echo "/* $x */"
90184257Slulf		infocmp -E $x
91184257Slulf	done
92184257Slulf
93184257Slulf	cat <<EOF
94184257Slulfstatic const TERMTYPE fallbacks[$#] =
95184257Slulf{
96184257SlulfEOF
97184257Slulf	comma=""
98184257Slulf	for x in $*
99184257Slulf	do
100184257Slulf		echo "$comma /* $x */"
101184257Slulf		infocmp -e $x
102184257Slulf		comma=","
103184257Slulf	done
104184257Slulf
105184257Slulf	cat <<EOF
106184257Slulf};
107184257Slulf
108184257SlulfEOF
109184257Slulffi
110184257Slulf
111184257Slulfcat <<EOF
112184257SlulfNCURSES_EXPORT(const TERMTYPE *) _nc_fallback (const char *name GCC_UNUSED)
113184257Slulf{
114184257SlulfEOF
115184257Slulf
116184257Slulfif [ "$*" ]
117184257Slulfthen
118184257Slulf	cat <<EOF
119185130Slulf    const TERMTYPE	*tp;
120184257Slulf
121184257Slulf    for (tp = fallbacks;
122184257Slulf	 	tp < fallbacks + sizeof(fallbacks)/sizeof(TERMTYPE);
123184257Slulf	 	tp++)
124184257Slulf	if (_nc_name_match(tp->term_names, name, "|"))
125184257Slulf	    return(tp);
126184257SlulfEOF
127184257Slulfelse
128184257Slulf	echo "	/* the fallback list is empty */";
129184257Slulffi
130184257Slulf
131184257Slulfcat <<EOF
132184257Slulf	return((TERMTYPE *)0);
133184257Slulf}
134184257SlulfEOF
135184257Slulf
136184257Slulfif test -n "$tmp_info" ; then
137184257Slulf	echo removing temporary terminfo directory... >&2
138184257Slulf	rm -rf $tmp_info
139184257Slulffi
140184257Slulf