blob: f0ac0452e8ef909d0f0ef626d586a8909374e351 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301#!/bin/sh
2#
3# MKlib_gen.sh -- generate sources from curses.h macro definitions
4#
micky3879b9f5e72025-07-08 18:04:53 -04005# ($Id: MKlib_gen.sh,v 1.73 2022/10/01 13:14:20 tom Exp $)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05306#
7##############################################################################
micky3879b9f5e72025-07-08 18:04:53 -04008# Copyright 2018-2021,2022 Thomas E. Dickey #
9# Copyright 1998-2016,2017 Free Software Foundation, Inc. #
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053010# #
11# Permission is hereby granted, free of charge, to any person obtaining a #
12# copy of this software and associated documentation files (the "Software"), #
13# to deal in the Software without restriction, including without limitation #
14# the rights to use, copy, modify, merge, publish, distribute, distribute #
15# with modifications, sublicense, and/or sell copies of the Software, and to #
16# permit persons to whom the Software is furnished to do so, subject to the #
17# following conditions: #
18# #
19# The above copyright notice and this permission notice shall be included in #
20# all copies or substantial portions of the Software. #
21# #
22# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
23# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
24# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
25# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
26# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
27# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
28# DEALINGS IN THE SOFTWARE. #
29# #
30# Except as contained in this notice, the name(s) of the above copyright #
31# holders shall not be used in advertising or otherwise to promote the sale, #
32# use or other dealings in this Software without prior written #
33# authorization. #
34##############################################################################
35#
36# The XSI Curses standard requires all curses entry points to exist as
37# functions, even though many definitions would normally be shadowed
38# by macros. Rather than hand-hack all that code, we actually
39# generate functions from the macros.
40#
41# This script accepts a file of prototypes on standard input. It discards
42# any that don't have a `generated' comment attached. It then parses each
43# prototype (relying on the fact that none of the macros take function
44# pointer or array arguments) and generates C source from it.
45#
46# Here is what the pipeline stages are doing:
47#
48# 1. sed: extract prototypes of generated functions
49# 2. sed: decorate prototypes with generated arguments a1. a2,...z
50# 3. awk: generate the calls with args matching the formals
51# 4. sed: prefix function names in prototypes so the preprocessor won't expand
52# them.
53# 5. cpp: macro-expand the file so the macro calls turn into C calls
54# 6. awk: strip the expansion junk off the front and add the new header
Steve Kondikae271bc2015-11-15 02:50:53 +010055# 7. sed: squeeze spaces, strip off gen_ prefix.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053056#
57
58# keep the editing independent of locale:
59if test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi
60if test "${LANG+set}" = set; then LANG=C; export LANG; fi
61if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
62if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
63if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
64if test "${LC_COLLATE+set}" = set; then LC_COLLATE=C; export LC_COLLATE; fi
65
micky3879b9f5e72025-07-08 18:04:53 -040066preprocessor="$1 -DNCURSES_WATTR_MACROS -DNCURSES_INTERNALS -I../include"
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053067AWK="$2"
68USE="$3"
69
Steve Kondikae271bc2015-11-15 02:50:53 +010070# A patch discussed here:
71# https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02185.html
micky3879b9f5e72025-07-08 18:04:53 -040072#
Steve Kondikae271bc2015-11-15 02:50:53 +010073# introduces spurious #line markers into the preprocessor output. The result
74# appears in gcc 5.0 and (with modification) in 5.1, making it necessary to
75# determine if we are using gcc, and if so, what version because the proposed
76# solution uses a nonstandard option.
micky3879b9f5e72025-07-08 18:04:53 -040077#
78# As illustrated in
79# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60723
80#
81# gcc developers chose to ignore the problems with this, and summarized those
82# as "intriguing problems" in
83# https://gcc.gnu.org/gcc-5/porting_to.html
84
85PRG=`echo "$1" | "$AWK" '{ sub(/^[ ]*/,""); sub(/[ ].*$/, ""); print; }' || exit 0`
86FSF=`("$PRG" --version 2>/dev/null || exit 0) | ${FGREP-grep -F} "Free Software Foundation" | head -n 1`
Steve Kondikae271bc2015-11-15 02:50:53 +010087ALL=`"$PRG" -dumpversion 2>/dev/null || exit 0`
micky3879b9f5e72025-07-08 18:04:53 -040088ONE=`echo "$ALL" | sed -e 's/[^0-9].*$//'`
Steve Kondikae271bc2015-11-15 02:50:53 +010089if test -n "$FSF" && test -n "$ALL" && test -n "$ONE" ; then
micky3879b9f5e72025-07-08 18:04:53 -040090 if test "$ONE" -ge 5 ; then
Steve Kondikae271bc2015-11-15 02:50:53 +010091 echo ".. adding -P option to work around $PRG $ALL" >&2
92 preprocessor="$preprocessor -P"
93 fi
94fi
95
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053096PID=$$
97ED1=sed1_${PID}.sed
98ED2=sed2_${PID}.sed
99ED3=sed3_${PID}.sed
100ED4=sed4_${PID}.sed
101AW1=awk1_${PID}.awk
102AW2=awk2_${PID}.awk
103TMP=gen__${PID}.c
micky3879b9f5e72025-07-08 18:04:53 -0400104trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP; exit 1" 1 2 3 15
105trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP" 0
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530106
107ALL=$USE
108if test "$USE" = implemented ; then
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530109 cat >$ED1 <<EOF1
110/^extern.*implemented/{
111 h
micky3879b9f5e72025-07-08 18:04:53 -0400112 s/GCC_DEPRECATED([^)]*)//
Steve Kondikae271bc2015-11-15 02:50:53 +0100113 s/NCURSES_SP_NAME(\([^)]*\))/NCURSES_SP_NAME___\1/
114 h
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530115 s/^.*implemented:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
116 g
117 s/^extern \([^;]*\);.*/\1/p
118 g
119 s/^.*implemented:\([^ *]*\).*/P_POUNDCendif/p
120}
121/^extern.*generated/{
122 h
123 s/^.*generated:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
124 g
125 s/^extern \([^;]*\);.*/\1/p
126 g
127 s/^.*generated:\([^ *]*\).*/P_POUNDCendif/p
128}
129EOF1
130else
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530131 cat >$ED1 <<EOF1
132/^extern.*${ALL}/{
133 h
134 s/^.*${ALL}:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
135 g
136 s/^extern \([^;]*\);.*/\1/p
137 g
138 s/^.*${ALL}:\([^ *]*\).*/P_POUNDCendif/p
139}
140EOF1
141fi
142
143cat >$ED2 <<EOF2
144/^P_/b nc
145/(void)/b nc
146 s/,/ a1% /
147 s/,/ a2% /
148 s/,/ a3% /
149 s/,/ a4% /
150 s/,/ a5% /
151 s/,/ a6% /
152 s/,/ a7% /
153 s/,/ a8% /
154 s/,/ a9% /
155 s/,/ a10% /
156 s/,/ a11% /
157 s/,/ a12% /
158 s/,/ a13% /
159 s/,/ a14% /
160 s/,/ a15% /
161 s/*/ * /g
162 s/%/ , /g
163 s/)/ z)/
164 s/\.\.\. z)/...)/
165:nc
166 s/(/ ( /
167 s/)/ )/
168EOF2
169
170cat >$ED3 <<EOF3
171/^P_/{
172 s/^P_POUNDCif_/#if /
173 s/^P_POUNDCendif/#endif/
174 s/^P_//
175 b done
176}
177 s/ */ /g
178 s/ */ /g
179 s/ ,/,/g
180 s/( /(/g
181 s/ )/)/g
182 s/ gen_/ /
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530183 s/^[ ]*@[ ]*@[ ]*/ /
184:done
185EOF3
186
187if test "$USE" = generated ; then
188cat >$ED4 <<EOF
micky3879b9f5e72025-07-08 18:04:53 -0400189 s/^\(.*\) \(.*\) (\(.*\))\$/NCURSES_EXPORT(\1) \2 (\3)/
190 /attr_[sg]et.* z)/s,z),z GCC_UNUSED),
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530191EOF
192else
193cat >$ED4 <<EOF
194/^\(.*\) \(.*\) (\(.*\))\$/ {
195 h
196 s/^\(.*\) \(.*\) (\(.*\))\$/extern \1 call_\2 (\3);/
197 p
198 g
199 s/^\(.*\) \(.*\) (\(.*\))\$/\1 call_\2 (\3)/
200 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100201s/\([^_]\)NCURSES_SP_NAME___\([a-zA-Z][a-zA-Z_]*\)/\1NCURSES_SP_NAME(\2)/g
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530202EOF
203fi
204
205cat >$AW1 <<\EOF1
206BEGIN {
207 skip=0;
208 }
209/^P_POUNDCif/ {
210 print "\n"
211 print $0
212 skip=0;
213}
214/^P_POUNDCendif/ {
215 print $0
216 skip=1;
217}
218$0 !~ /^P_/ {
219 if (skip)
220 print "\n"
221 skip=1;
222
223 first=$1
224 for (i = 1; i <= NF; i++) {
225 if ( $i != "NCURSES_CONST" ) {
226 first = i;
227 break;
228 }
229 }
230 second = first + 1;
Steve Kondikae271bc2015-11-15 02:50:53 +0100231 returnCast = "";
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530232 if ( $first == "chtype" ) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100233 returnType = "Chtype";
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530234 } else if ( $first == "SCREEN" ) {
235 returnType = "SP";
236 } else if ( $first == "WINDOW" ) {
237 returnType = "Win";
238 } else if ( $first == "attr_t" || $second == "attrset" || $second == "standout" || $second == "standend" || $second == "wattrset" || $second == "wstandout" || $second == "wstandend" ) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100239 returnType = "IntAttr";
240 returnCast = "(attr_t)";
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530241 } else if ( $first == "bool" || $first == "NCURSES_BOOL" ) {
242 returnType = "Bool";
243 } else if ( $second == "*" ) {
micky3879b9f5e72025-07-08 18:04:53 -0400244 returnType = ($1 == "NCURSES_CONST") ? "CPtr" : "Ptr";
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530245 } else {
246 returnType = "Code";
247 }
248 myfunc = second;
249 for (i = second; i <= NF; i++) {
250 if ($i != "*") {
251 myfunc = i;
252 break;
253 }
254 }
micky3879b9f5e72025-07-08 18:04:53 -0400255 if (using == "implemented") {
256 printf "#undef %s\n", $myfunc;
257 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530258 print $0;
259 print "{";
260 argcount = 1;
261 check = NF - 1;
262 if ($check == "void")
263 argcount = 0;
264 if (argcount != 0) {
265 for (i = 1; i <= NF; i++)
266 if ($i == ",")
267 argcount++;
268 }
269
270 # suppress trace-code for functions that we cannot do properly here,
271 # since they return data.
272 dotrace = 1;
273 if ($myfunc ~ /innstr/)
274 dotrace = 0;
275 if ($myfunc ~ /innwstr/)
276 dotrace = 0;
277
278 # workaround functions that we do not parse properly
279 if ($myfunc ~ /ripoffline/) {
280 dotrace = 0;
281 argcount = 2;
Steve Kondikae271bc2015-11-15 02:50:53 +0100282 if ($myfunc ~ /NCURSES_SP_NAME/) {
283 argcount = 3;
284 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530285 }
286 if ($myfunc ~ /wunctrl/) {
287 dotrace = 0;
288 }
289
micky3879b9f5e72025-07-08 18:04:53 -0400290 do_getstr = 0;
291 if ($myfunc ~ /get[n]?str/) {
292 do_getstr = 1;
293 }
294
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530295 call = "@@T((T_CALLED(\""
296 args = ""
297 comma = ""
298 num = 0;
299 pointer = 0;
300 va_list = 0;
301 varargs = 0;
302 argtype = ""
303 for (i = myfunc; i <= NF; i++) {
304 ch = $i;
Steve Kondikae271bc2015-11-15 02:50:53 +0100305 if ( ch == "*" ) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530306 pointer = 1;
Steve Kondikae271bc2015-11-15 02:50:53 +0100307 } else if ( ch == "va_list" ) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530308 va_list = 1;
Steve Kondikae271bc2015-11-15 02:50:53 +0100309 } else if ( ch == "..." ) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530310 varargs = 1;
Steve Kondikae271bc2015-11-15 02:50:53 +0100311 } else if ( ch == "char" ) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530312 argtype = "char";
Steve Kondikae271bc2015-11-15 02:50:53 +0100313 } else if ( ch == "int" ) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530314 argtype = "int";
Steve Kondikae271bc2015-11-15 02:50:53 +0100315 } else if ( ch == "short" ) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530316 argtype = "short";
Steve Kondikae271bc2015-11-15 02:50:53 +0100317 } else if ( ch == "chtype" ) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530318 argtype = "chtype";
Steve Kondikae271bc2015-11-15 02:50:53 +0100319 } else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" ) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530320 argtype = "attr";
Steve Kondikae271bc2015-11-15 02:50:53 +0100321 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530322
323 if ( ch == "," || ch == ")" ) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100324 argcast = "";
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530325 if (va_list) {
326 call = call "%s"
327 } else if (varargs) {
328 call = call "%s"
329 } else if (pointer) {
330 if ( argtype == "char" ) {
micky3879b9f5e72025-07-08 18:04:53 -0400331 if (do_getstr) {
332 call = call "%p"
333 } else {
334 call = call "%s"
335 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530336 comma = comma "_nc_visbuf2(" num ","
337 pointer = 0;
Steve Kondikae271bc2015-11-15 02:50:53 +0100338 } else {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530339 call = call "%p"
Steve Kondikae271bc2015-11-15 02:50:53 +0100340 comma = comma "(const void *)"
341 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530342 } else if (argcount != 0) {
343 if ( argtype == "int" || argtype == "short" ) {
344 call = call "%d"
345 argtype = ""
346 } else if ( argtype != "" ) {
347 call = call "%s"
348 comma = comma "_trace" argtype "2(" num ","
Steve Kondikae271bc2015-11-15 02:50:53 +0100349 if (argtype == "attr") {
350 argcast = "(chtype)";
351 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530352 } else {
353 call = call "%#lx"
354 comma = comma "(long)"
355 }
356 }
357 if (ch == ",") {
358 args = args comma "a" ++num;
359 } else if ( argcount != 0 ) {
360 if ( va_list ) {
361 args = args comma "\"va_list\""
362 } else if ( varargs ) {
363 args = args comma "\"...\""
364 } else {
Steve Kondikae271bc2015-11-15 02:50:53 +0100365 args = args comma argcast "z"
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530366 }
367 }
368 call = call ch
369 if (pointer == 0 && argcount != 0 && argtype != "" )
370 args = args ")"
371 if (args != "")
372 comma = ", "
373 pointer = 0;
374 argtype = ""
375 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100376 if ( i == myfunc || ch == "(" )
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530377 call = call ch
378 }
379 call = call "\")"
380 if (args != "")
381 call = call ", " args
382 call = call ")); "
383
384 if (dotrace)
micky3879b9f5e72025-07-08 18:04:53 -0400385 printf "%s\n\t@@", call
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530386
Steve Kondikae271bc2015-11-15 02:50:53 +0100387 if (match($0, "^void")) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530388 call = ""
Steve Kondikae271bc2015-11-15 02:50:53 +0100389 } else if (dotrace) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530390 call = sprintf("return%s( ", returnType);
Steve Kondikae271bc2015-11-15 02:50:53 +0100391 if (returnCast != "") {
392 call = call returnCast;
393 }
394 } else {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530395 call = "@@return ";
Steve Kondikae271bc2015-11-15 02:50:53 +0100396 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530397
398 call = call $myfunc "(";
399 for (i = 1; i < argcount; i++) {
400 if (i != 1)
401 call = call ", ";
402 call = call "a" i;
403 }
404 if ( argcount != 0 && $check != "..." ) {
405 if (argcount != 1)
406 call = call ", ";
407 call = call "z";
408 }
409 if (!match($0, "^void"))
410 call = call ") ";
Steve Kondikae271bc2015-11-15 02:50:53 +0100411 if (dotrace) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530412 call = call ")";
Steve Kondikae271bc2015-11-15 02:50:53 +0100413 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530414 print call ";"
415
416 if (match($0, "^void"))
417 print "@@returnVoid;"
418 print "}";
419}
420EOF1
421
422cat >$AW2 <<EOF1
423BEGIN {
micky3879b9f5e72025-07-08 18:04:53 -0400424 printf "/* This file was generated by $0 $USE */\n"
425 print ""
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530426 print "/*"
427 print " * DO NOT EDIT THIS FILE BY HAND!"
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530428 if ( "$USE" == "generated" ) {
429 print " *"
430 print " * This is a file of trivial functions generated from macro"
431 print " * definitions in curses.h to satisfy the XSI Curses requirement"
432 print " * that every macro also exist as a callable function."
433 print " *"
434 print " * It will never be linked unless you call one of the entry"
435 print " * points with its normal macro definition disabled. In that"
436 print " * case, if you have no shared libraries, it will indirectly"
437 print " * pull most of the rest of the library into your link image."
438 }
439 print " */"
440 print "#define NCURSES_ATTR_T int"
Steve Kondikae271bc2015-11-15 02:50:53 +0100441 print "#include <ncurses_cfg.h>"
442 print ""
443 print "#undef NCURSES_NOMACROS /* _this_ file uses macros */"
micky3879b9f5e72025-07-08 18:04:53 -0400444 print "#define NCURSES_NOMACROS 1"
Steve Kondikae271bc2015-11-15 02:50:53 +0100445 print ""
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530446 print "#include <curses.priv.h>"
447 print ""
448 }
449/^DECLARATIONS/ {start = 1; next;}
Steve Kondikae271bc2015-11-15 02:50:53 +0100450 {
451 if (start) {
452 if ( "$USE" == "generated" ) {
453 print \$0;
454 } else if ( \$0 ~ /^[{}]?\$/ ) {
455 print \$0;
456 } else if ( \$0 ~ /;/ ) {
457 print \$0;
458 } else {
459 calls[start] = \$0;
460 print \$0;
461 start++;
462 }
463 }
464 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530465END {
466 if ( "$USE" != "generated" ) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100467 print "int main(void)"
468 print "{"
469 for (n = 1; n < start; ++n) {
470 value = calls[n];
471 if ( value !~ /P_POUNDC/ ) {
micky3879b9f5e72025-07-08 18:04:53 -0400472 gsub(/[ \t]+/," ",value);
473 sub(/^[0-9a-zA-Z_]+ /,"",value);
474 sub(/^[*][ \t]*/,"",value);
475 gsub("struct[ \t]*[0-9a-zA-Z_]+[ \t]*[*]","",value);
476 gsub(/[0-9a-zA-Z_]+[ \t]*[*][ \t]*/,"",value);
Steve Kondikae271bc2015-11-15 02:50:53 +0100477 gsub(/ (const) /," ",value);
478 gsub(/ (int|short|attr_t|chtype|wchar_t|NCURSES_BOOL|NCURSES_OUTC|NCURSES_OUTC_sp|va_list) /," ",value);
479 gsub(/ void /,"",value);
480 sub(/^/,"call_",value);
micky3879b9f5e72025-07-08 18:04:53 -0400481 gsub(/ (a[0-9]|z) /, " 0 ", value);
482 gsub(/ int[ \t]*[(][^)]+[)][(][^)]+[)]/, "0", value);
Steve Kondikae271bc2015-11-15 02:50:53 +0100483 printf "\t%s;\n", value;
484 } else {
485 print value;
486 }
487 }
488 print " return 0;"
489 print "}"
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530490 }
491 }
492EOF1
493
494cat >$TMP <<EOF
495#include <ncurses_cfg.h>
496#undef NCURSES_NOMACROS
497#include <curses.h>
Steve Kondikae271bc2015-11-15 02:50:53 +0100498#include <term.h>
499#include <unctrl.h>
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530500
501DECLARATIONS
502
503EOF
504
505sed -n -f $ED1 \
506| sed -e 's/NCURSES_EXPORT(\(.*\)) \(.*\) (\(.*\))/\1 \2(\3)/' \
507| sed -f $ED2 \
micky3879b9f5e72025-07-08 18:04:53 -0400508| "$AWK" -f $AW1 using="$USE" \
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530509| sed \
510 -e 's/ [ ]*$//g' \
511 -e 's/^\([a-zA-Z_][a-zA-Z_]*[ *]*\)/\1 gen_/' \
512 -e 's/gen_$//' \
513 -e 's/ / /g' >>$TMP
514
515$preprocessor $TMP 2>/dev/null \
516| sed \
517 -e 's/ / /g' \
518 -e 's/^ //' \
519 -e 's/_Bool/NCURSES_BOOL/g' \
micky3879b9f5e72025-07-08 18:04:53 -0400520| "$AWK" -f $AW2 \
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530521| sed -f $ED3 \
522| sed \
523 -e 's/^.*T_CALLED.*returnCode( \([a-z].*) \));/ return \1;/' \
524 -e 's/^.*T_CALLED.*returnCode( \((wmove.*) \));/ return \1;/' \
525 -e 's/gen_//' \
526 -e 's/^[ ]*#/#/' \
527 -e '/#ident/d' \
528 -e '/#line/d' \
529| sed -f $ED4