Rearrange the python scripting support a bit.
[screen-lua.git] / src / term.sh
blobf5dfc4ad3d81bdf4e550c57698ae688f08b41a11
1 #! /bin/sh
3 if test -z "$AWK"; then
4 AWK=awk
5 fi
6 if test -z "$srcdir"; then
7 srcdir=.
8 fi
10 LC_ALL=C
11 export LC_ALL
13 rm -f term.h
14 cat << EOF > term.h
16 * This file is automagically created from term.c -- DO NOT EDIT
19 #define T_FLG 0
20 #define T_NUM 1
21 #define T_STR 2
23 struct term
25 char *tcname;
26 int type;
29 union tcu
31 int flg;
32 int num;
33 char *str;
36 EOF
39 # SCO-Unix sufferers may need to use the following lines:
40 # perl -p < ${srcdir}/term.c \
41 # -e 's/"/"C/ if /"[A-Z]."/;' \
42 # -e 'y/[a-z]/[A-Z]/ if /"/;' \
44 sed < ${srcdir}/term.c \
45 -e '/"[A-Z]."/s/"/"C/' \
46 -e '/"/y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
47 | $AWK '
48 /^ [{] ".*KMAPDEF[(].*$/{
49 if (min == 0) min = s
50 max = s;
52 /^ [{] ".*KMAPADEF[(].*$/{
53 if (amin == 0) amin = s
54 amax = s;
56 /^ [{] ".*KMAPMDEF[(].*$/{
57 if (mmin == 0) mmin = s
58 mmax = s;
60 /^ [{] ".*$/{
61 a=substr($2,2,length($2)-3);
62 b=substr($3,3,3);
63 if (nolist == 0) {
64 printf "#define d_%s d_tcs[%d].%s\n",a,s,b
65 printf "#define D_%s (D_tcs[%d].%s)\n",a,s,b
67 s++;
69 /\/* define/{
70 printf "#define %s %d\n",$3,s
72 /\/* nolist/{
73 nolist = 1;
75 /\/* list/{
76 nolist = 0;
78 END {
79 printf "\n#ifdef MAPKEYS\n"
80 printf "# define KMAPDEFSTART %d\n", min
81 printf "# define NKMAPDEF %d\n", max-min+1
82 printf "# define KMAPADEFSTART %d\n", amin
83 printf "# define NKMAPADEF %d\n", amax-amin+1
84 printf "# define KMAPMDEFSTART %d\n", mmin
85 printf "# define NKMAPMDEF %d\n", mmax-mmin+1
86 printf "#endif\n"
88 ' | sed -e s/NUM/num/ -e s/STR/str/ -e s/FLG/flg/ \
89 >> term.h
91 rm -f kmapdef.c
92 cat << EOF > kmapdef.c
94 * This file is automagically created from term.c -- DO NOT EDIT
97 #include "config.h"
99 #ifdef MAPKEYS
103 $AWK < ${srcdir}/term.c '
104 /^ [{] ".*KMAP.*$/{
105 for (i = 0; i < 3; i++) {
106 q = $(5+i)
107 if (substr(q, 1, 5) == "KMAPD") {
108 if (min == 0) min = s
109 max = s
110 arr[s] = substr(q, 9, length(q)-9)
112 if (substr(q, 1, 5) == "KMAPA") {
113 if (amin == 0) amin = s
114 amax = s
115 anarr[s] = substr(q, 10, length(q)-10)
117 if (substr(q, 1, 5) == "KMAPM") {
118 if (mmin == 0) mmin = s
119 mmax = s
120 mnarr[s] = substr(q, 10, length(q)-10)
124 /^ [{] ".*$/{
125 s++;
127 END {
128 printf "char *kmapdef[] = {\n"
129 for (s = min; s <= max; s++) {
130 if (arr[s])
131 printf "%s", arr[s]
132 else
133 printf "0"
134 if (s < max)
135 printf ",\n"
136 else
137 printf "\n"
139 printf "};\n\n"
140 printf "char *kmapadef[] = {\n"
141 for (s = amin; s <= amax; s++) {
142 if (anarr[s])
143 printf "%s", anarr[s]
144 else
145 printf "0"
146 if (s < amax)
147 printf ",\n"
148 else
149 printf "\n"
151 printf "};\n\n"
152 printf "char *kmapmdef[] = {\n"
153 for (s = mmin; s <= mmax; s++) {
154 if (mnarr[s])
155 printf "%s", mnarr[s]
156 else
157 printf "0"
158 if (s < mmax)
159 printf ",\n"
160 else
161 printf "\n"
163 printf "};\n\n#endif\n"
165 ' >> kmapdef.c
167 chmod a-w kmapdef.c
168 chmod a-w term.h