Deleted Added
full compact
MKlib_gen.sh (184989) MKlib_gen.sh (262629)
1#!/bin/sh
2#
3# MKlib_gen.sh -- generate sources from curses.h macro definitions
4#
1#!/bin/sh
2#
3# MKlib_gen.sh -- generate sources from curses.h macro definitions
4#
5# ($Id: MKlib_gen.sh,v 1.34 2008/08/30 19:20:50 tom Exp $)
5# ($Id: MKlib_gen.sh,v 1.43 2011/01/22 19:47:29 tom Exp $)
6#
7##############################################################################
6#
7##############################################################################
8# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. #
8# Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. #
9# #
10# Permission is hereby granted, free of charge, to any person obtaining a #
11# copy of this software and associated documentation files (the "Software"), #
12# to deal in the Software without restriction, including without limitation #
13# the rights to use, copy, modify, merge, publish, distribute, distribute #
14# with modifications, sublicense, and/or sell copies of the Software, and to #
15# permit persons to whom the Software is furnished to do so, subject to the #
16# following conditions: #

--- 29 unchanged lines hidden (view full) ---

46#
47# 1. sed: extract prototypes of generated functions
48# 2. sed: decorate prototypes with generated arguments a1. a2,...z
49# 3. awk: generate the calls with args matching the formals
50# 4. sed: prefix function names in prototypes so the preprocessor won't expand
51# them.
52# 5. cpp: macro-expand the file so the macro calls turn into C calls
53# 6. awk: strip the expansion junk off the front and add the new header
9# #
10# Permission is hereby granted, free of charge, to any person obtaining a #
11# copy of this software and associated documentation files (the "Software"), #
12# to deal in the Software without restriction, including without limitation #
13# the rights to use, copy, modify, merge, publish, distribute, distribute #
14# with modifications, sublicense, and/or sell copies of the Software, and to #
15# permit persons to whom the Software is furnished to do so, subject to the #
16# following conditions: #

--- 29 unchanged lines hidden (view full) ---

46#
47# 1. sed: extract prototypes of generated functions
48# 2. sed: decorate prototypes with generated arguments a1. a2,...z
49# 3. awk: generate the calls with args matching the formals
50# 4. sed: prefix function names in prototypes so the preprocessor won't expand
51# them.
52# 5. cpp: macro-expand the file so the macro calls turn into C calls
53# 6. awk: strip the expansion junk off the front and add the new header
54# 7. sed: squeeze spaces, strip off gen_ prefix, create needed #undef
54# 7. sed: squeeze spaces, strip off gen_ prefix.
55#
56
57# keep the editing independent of locale:
58if test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi
59if test "${LANG+set}" = set; then LANG=C; export LANG; fi
60if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
61if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
62if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi

--- 14 unchanged lines hidden (view full) ---

77trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP" 0 1 2 5 15
78
79ALL=$USE
80if test "$USE" = implemented ; then
81 CALL="call_"
82 cat >$ED1 <<EOF1
83/^extern.*implemented/{
84 h
55#
56
57# keep the editing independent of locale:
58if test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi
59if test "${LANG+set}" = set; then LANG=C; export LANG; fi
60if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
61if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
62if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi

--- 14 unchanged lines hidden (view full) ---

77trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP" 0 1 2 5 15
78
79ALL=$USE
80if test "$USE" = implemented ; then
81 CALL="call_"
82 cat >$ED1 <<EOF1
83/^extern.*implemented/{
84 h
85 s/NCURSES_SP_NAME(\([^)]*\))/NCURSES_SP_NAME___\1/
86 h
85 s/^.*implemented:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
86 g
87 s/^extern \([^;]*\);.*/\1/p
88 g
89 s/^.*implemented:\([^ *]*\).*/P_POUNDCendif/p
90}
91/^extern.*generated/{
92 h

--- 53 unchanged lines hidden (view full) ---

146 b done
147}
148 s/ */ /g
149 s/ */ /g
150 s/ ,/,/g
151 s/( /(/g
152 s/ )/)/g
153 s/ gen_/ /
87 s/^.*implemented:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
88 g
89 s/^extern \([^;]*\);.*/\1/p
90 g
91 s/^.*implemented:\([^ *]*\).*/P_POUNDCendif/p
92}
93/^extern.*generated/{
94 h

--- 53 unchanged lines hidden (view full) ---

148 b done
149}
150 s/ */ /g
151 s/ */ /g
152 s/ ,/,/g
153 s/( /(/g
154 s/ )/)/g
155 s/ gen_/ /
154 s/^M_/#undef /
155 s/^[ ]*@[ ]*@[ ]*/ /
156:done
157EOF3
158
159if test "$USE" = generated ; then
160cat >$ED4 <<EOF
156 s/^[ ]*@[ ]*@[ ]*/ /
157:done
158EOF3
159
160if test "$USE" = generated ; then
161cat >$ED4 <<EOF
161 s/^\(.*\) \(.*\) (\(.*\))\$/NCURSES_EXPORT(\1) \2 (\3)/
162 s/^\(.*\) \(.*\) (\(.*\))\$/NCURSES_EXPORT(\1) (\2) (\3)/
162EOF
163else
164cat >$ED4 <<EOF
165/^\(.*\) \(.*\) (\(.*\))\$/ {
166 h
167 s/^\(.*\) \(.*\) (\(.*\))\$/extern \1 call_\2 (\3);/
168 p
169 g
170 s/^\(.*\) \(.*\) (\(.*\))\$/\1 call_\2 (\3)/
171 }
163EOF
164else
165cat >$ED4 <<EOF
166/^\(.*\) \(.*\) (\(.*\))\$/ {
167 h
168 s/^\(.*\) \(.*\) (\(.*\))\$/extern \1 call_\2 (\3);/
169 p
170 g
171 s/^\(.*\) \(.*\) (\(.*\))\$/\1 call_\2 (\3)/
172 }
173s/\([^_]\)NCURSES_SP_NAME___\([a-zA-Z][a-zA-Z_]*\)/\1NCURSES_SP_NAME(\2)/g
172EOF
173fi
174
175cat >$AW1 <<\EOF1
176BEGIN {
177 skip=0;
178 }
179/^P_POUNDCif/ {

--- 13 unchanged lines hidden (view full) ---

193 first=$1
194 for (i = 1; i <= NF; i++) {
195 if ( $i != "NCURSES_CONST" ) {
196 first = i;
197 break;
198 }
199 }
200 second = first + 1;
174EOF
175fi
176
177cat >$AW1 <<\EOF1
178BEGIN {
179 skip=0;
180 }
181/^P_POUNDCif/ {

--- 13 unchanged lines hidden (view full) ---

195 first=$1
196 for (i = 1; i <= NF; i++) {
197 if ( $i != "NCURSES_CONST" ) {
198 first = i;
199 break;
200 }
201 }
202 second = first + 1;
203 returnCast = "";
201 if ( $first == "chtype" ) {
204 if ( $first == "chtype" ) {
202 returnType = "Char";
205 returnType = "Chtype";
203 } else if ( $first == "SCREEN" ) {
204 returnType = "SP";
205 } else if ( $first == "WINDOW" ) {
206 returnType = "Win";
207 } else if ( $first == "attr_t" || $second == "attrset" || $second == "standout" || $second == "standend" || $second == "wattrset" || $second == "wstandout" || $second == "wstandend" ) {
206 } else if ( $first == "SCREEN" ) {
207 returnType = "SP";
208 } else if ( $first == "WINDOW" ) {
209 returnType = "Win";
210 } else if ( $first == "attr_t" || $second == "attrset" || $second == "standout" || $second == "standend" || $second == "wattrset" || $second == "wstandout" || $second == "wstandend" ) {
208 returnType = "Attr";
211 returnType = "IntAttr";
212 returnCast = "(attr_t)";
209 } else if ( $first == "bool" || $first == "NCURSES_BOOL" ) {
210 returnType = "Bool";
211 } else if ( $second == "*" ) {
212 returnType = "Ptr";
213 } else {
214 returnType = "Code";
215 }
216 myfunc = second;
217 for (i = second; i <= NF; i++) {
218 if ($i != "*") {
219 myfunc = i;
220 break;
221 }
222 }
213 } else if ( $first == "bool" || $first == "NCURSES_BOOL" ) {
214 returnType = "Bool";
215 } else if ( $second == "*" ) {
216 returnType = "Ptr";
217 } else {
218 returnType = "Code";
219 }
220 myfunc = second;
221 for (i = second; i <= NF; i++) {
222 if ($i != "*") {
223 myfunc = i;
224 break;
225 }
226 }
223 if (using == "generated") {
224 print "M_" $myfunc
225 }
226 print $0;
227 print "{";
228 argcount = 1;
229 check = NF - 1;
230 if ($check == "void")
231 argcount = 0;
232 if (argcount != 0) {
233 for (i = 1; i <= NF; i++)

--- 8 unchanged lines hidden (view full) ---

242 dotrace = 0;
243 if ($myfunc ~ /innwstr/)
244 dotrace = 0;
245
246 # workaround functions that we do not parse properly
247 if ($myfunc ~ /ripoffline/) {
248 dotrace = 0;
249 argcount = 2;
227 print $0;
228 print "{";
229 argcount = 1;
230 check = NF - 1;
231 if ($check == "void")
232 argcount = 0;
233 if (argcount != 0) {
234 for (i = 1; i <= NF; i++)

--- 8 unchanged lines hidden (view full) ---

243 dotrace = 0;
244 if ($myfunc ~ /innwstr/)
245 dotrace = 0;
246
247 # workaround functions that we do not parse properly
248 if ($myfunc ~ /ripoffline/) {
249 dotrace = 0;
250 argcount = 2;
251 if ($myfunc ~ /NCURSES_SP_NAME/) {
252 argcount = 3;
253 }
250 }
251 if ($myfunc ~ /wunctrl/) {
252 dotrace = 0;
253 }
254
255 call = "@@T((T_CALLED(\""
256 args = ""
257 comma = ""
258 num = 0;
259 pointer = 0;
260 va_list = 0;
261 varargs = 0;
262 argtype = ""
263 for (i = myfunc; i <= NF; i++) {
264 ch = $i;
254 }
255 if ($myfunc ~ /wunctrl/) {
256 dotrace = 0;
257 }
258
259 call = "@@T((T_CALLED(\""
260 args = ""
261 comma = ""
262 num = 0;
263 pointer = 0;
264 va_list = 0;
265 varargs = 0;
266 argtype = ""
267 for (i = myfunc; i <= NF; i++) {
268 ch = $i;
265 if ( ch == "*" )
269 if ( ch == "*" ) {
266 pointer = 1;
270 pointer = 1;
267 else if ( ch == "va_list" )
271 } else if ( ch == "va_list" ) {
268 va_list = 1;
272 va_list = 1;
269 else if ( ch == "..." )
273 } else if ( ch == "..." ) {
270 varargs = 1;
274 varargs = 1;
271 else if ( ch == "char" )
275 } else if ( ch == "char" ) {
272 argtype = "char";
276 argtype = "char";
273 else if ( ch == "int" )
277 } else if ( ch == "int" ) {
274 argtype = "int";
278 argtype = "int";
275 else if ( ch == "short" )
279 } else if ( ch == "short" ) {
276 argtype = "short";
280 argtype = "short";
277 else if ( ch == "chtype" )
281 } else if ( ch == "chtype" ) {
278 argtype = "chtype";
282 argtype = "chtype";
279 else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" )
283 } else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" ) {
280 argtype = "attr";
284 argtype = "attr";
285 }
281
282 if ( ch == "," || ch == ")" ) {
286
287 if ( ch == "," || ch == ")" ) {
288 argcast = "";
283 if (va_list) {
284 call = call "%s"
285 } else if (varargs) {
286 call = call "%s"
287 } else if (pointer) {
288 if ( argtype == "char" ) {
289 call = call "%s"
290 comma = comma "_nc_visbuf2(" num ","
291 pointer = 0;
289 if (va_list) {
290 call = call "%s"
291 } else if (varargs) {
292 call = call "%s"
293 } else if (pointer) {
294 if ( argtype == "char" ) {
295 call = call "%s"
296 comma = comma "_nc_visbuf2(" num ","
297 pointer = 0;
292 } else
298 } else {
293 call = call "%p"
299 call = call "%p"
300 comma = comma "(const void *)"
301 }
294 } else if (argcount != 0) {
295 if ( argtype == "int" || argtype == "short" ) {
296 call = call "%d"
297 argtype = ""
298 } else if ( argtype != "" ) {
299 call = call "%s"
300 comma = comma "_trace" argtype "2(" num ","
302 } else if (argcount != 0) {
303 if ( argtype == "int" || argtype == "short" ) {
304 call = call "%d"
305 argtype = ""
306 } else if ( argtype != "" ) {
307 call = call "%s"
308 comma = comma "_trace" argtype "2(" num ","
309 if (argtype == "attr") {
310 argcast = "(chtype)";
311 }
301 } else {
302 call = call "%#lx"
303 comma = comma "(long)"
304 }
305 }
306 if (ch == ",") {
307 args = args comma "a" ++num;
308 } else if ( argcount != 0 ) {
309 if ( va_list ) {
310 args = args comma "\"va_list\""
311 } else if ( varargs ) {
312 args = args comma "\"...\""
313 } else {
312 } else {
313 call = call "%#lx"
314 comma = comma "(long)"
315 }
316 }
317 if (ch == ",") {
318 args = args comma "a" ++num;
319 } else if ( argcount != 0 ) {
320 if ( va_list ) {
321 args = args comma "\"va_list\""
322 } else if ( varargs ) {
323 args = args comma "\"...\""
324 } else {
314 args = args comma "z"
325 args = args comma argcast "z"
315 }
316 }
317 call = call ch
318 if (pointer == 0 && argcount != 0 && argtype != "" )
319 args = args ")"
320 if (args != "")
321 comma = ", "
322 pointer = 0;
323 argtype = ""
324 }
326 }
327 }
328 call = call ch
329 if (pointer == 0 && argcount != 0 && argtype != "" )
330 args = args ")"
331 if (args != "")
332 comma = ", "
333 pointer = 0;
334 argtype = ""
335 }
325 if ( i == 2 || ch == "(" )
336 if ( i == myfunc || ch == "(" )
326 call = call ch
327 }
328 call = call "\")"
329 if (args != "")
330 call = call ", " args
331 call = call ")); "
332
333 if (dotrace)
334 printf "%s", call
335
337 call = call ch
338 }
339 call = call "\")"
340 if (args != "")
341 call = call ", " args
342 call = call ")); "
343
344 if (dotrace)
345 printf "%s", call
346
336 if (match($0, "^void"))
347 if (match($0, "^void")) {
337 call = ""
348 call = ""
338 else if (dotrace)
349 } else if (dotrace) {
339 call = sprintf("return%s( ", returnType);
350 call = sprintf("return%s( ", returnType);
340 else
351 if (returnCast != "") {
352 call = call returnCast;
353 }
354 } else {
341 call = "@@return ";
355 call = "@@return ";
356 }
342
343 call = call $myfunc "(";
344 for (i = 1; i < argcount; i++) {
345 if (i != 1)
346 call = call ", ";
347 call = call "a" i;
348 }
349 if ( argcount != 0 && $check != "..." ) {
350 if (argcount != 1)
351 call = call ", ";
352 call = call "z";
353 }
354 if (!match($0, "^void"))
355 call = call ") ";
357
358 call = call $myfunc "(";
359 for (i = 1; i < argcount; i++) {
360 if (i != 1)
361 call = call ", ";
362 call = call "a" i;
363 }
364 if ( argcount != 0 && $check != "..." ) {
365 if (argcount != 1)
366 call = call ", ";
367 call = call "z";
368 }
369 if (!match($0, "^void"))
370 call = call ") ";
356 if (dotrace)
371 if (dotrace) {
357 call = call ")";
372 call = call ")";
373 }
358 print call ";"
359
360 if (match($0, "^void"))
361 print "@@returnVoid;"
362 print "}";
363}
364EOF1
365

--- 10 unchanged lines hidden (view full) ---

376 print " *"
377 print " * It will never be linked unless you call one of the entry"
378 print " * points with its normal macro definition disabled. In that"
379 print " * case, if you have no shared libraries, it will indirectly"
380 print " * pull most of the rest of the library into your link image."
381 }
382 print " */"
383 print "#define NCURSES_ATTR_T int"
374 print call ";"
375
376 if (match($0, "^void"))
377 print "@@returnVoid;"
378 print "}";
379}
380EOF1
381

--- 10 unchanged lines hidden (view full) ---

392 print " *"
393 print " * It will never be linked unless you call one of the entry"
394 print " * points with its normal macro definition disabled. In that"
395 print " * case, if you have no shared libraries, it will indirectly"
396 print " * pull most of the rest of the library into your link image."
397 }
398 print " */"
399 print "#define NCURSES_ATTR_T int"
400 print "#include <ncurses_cfg.h>"
401 print ""
402 print "#undef NCURSES_NOMACROS /* _this_ file uses macros */"
403 print ""
384 print "#include <curses.priv.h>"
385 print ""
404 print "#include <curses.priv.h>"
405 print ""
406 print "#undef vw_scanw"
407 print "#undef vwscanw"
408 print ""
409 print "#undef vw_printw"
410 print "#undef vwprintw"
386 }
387/^DECLARATIONS/ {start = 1; next;}
388 {if (start) print \$0;}
389END {
390 if ( "$USE" != "generated" ) {
391 print "int main(void) { return 0; }"
392 }
393 }

--- 36 unchanged lines hidden ---
411 }
412/^DECLARATIONS/ {start = 1; next;}
413 {if (start) print \$0;}
414END {
415 if ( "$USE" != "generated" ) {
416 print "int main(void) { return 0; }"
417 }
418 }

--- 36 unchanged lines hidden ---