]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/MKlib_gen.sh
ncurses 5.9 - patch 20150328
[ncurses.git] / ncurses / base / MKlib_gen.sh
index c4319bf09f181bea993d2c5bf6e76611afdbf8ce..b91398c740a266f10edbbce19f19c52b9709556f 100755 (executable)
@@ -2,10 +2,10 @@
 #
 # MKlib_gen.sh -- generate sources from curses.h macro definitions
 #
-# ($Id: MKlib_gen.sh,v 1.42 2011/01/01 22:06:52 tom Exp $)
+# ($Id: MKlib_gen.sh,v 1.47 2014/12/06 18:56:25 tom Exp $)
 #
 ##############################################################################
-# Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.                #
+# Copyright (c) 1998-2011,2014 Free Software Foundation, Inc.                #
 #                                                                            #
 # Permission is hereby granted, free of charge, to any person obtaining a    #
 # copy of this software and associated documentation files (the "Software"), #
@@ -410,10 +410,45 @@ BEGIN             {
                print "#undef vwprintw"
                }
 /^DECLARATIONS/        {start = 1; next;}
-               {if (start) print \$0;}
+               {
+               if (start) {
+                       if ( "$USE" == "generated" ) {
+                               print \$0;
+                       } else if ( \$0 ~ /^[{}]?\$/ ) {
+                               print \$0;
+                       } else if ( \$0 ~ /;/ ) {
+                               print \$0;
+                       } else {
+                               calls[start] = \$0;
+                               print \$0;
+                               start++;
+                       }
+               }
+               }
 END            {
                if ( "$USE" != "generated" ) {
-                       print "int main(void) { return 0; }"
+                       print "int main(void)"
+                       print "{"
+                       for (n = 1; n < start; ++n) {
+                               value = calls[n];
+                               if ( value !~ /P_POUNDC/ ) {
+                                       gsub(/[[:blank:]]+/," ",value);
+                                       sub(/^[[:alnum:]_]+ /,"",value);
+                                       sub(/^\* /,"",value);
+                                       gsub(/[[:alnum:]_]+ \* /,"",value);
+                                       gsub(/ (const) /," ",value);
+                                       gsub(/ (int|short|attr_t|chtype|wchar_t|NCURSES_BOOL|NCURSES_OUTC|NCURSES_OUTC_sp|va_list) /," ",value);
+                                       gsub(/ void /,"",value);
+                                       sub(/^/,"call_",value);
+                                       gsub(/ (a[[:digit:]]|z) /, " 0 ", value);
+                                       gsub(/ int[[:blank:]]*[(][^)]+[)][(][^)]+[)]/, "0", value);
+                                       printf "\t%s;\n", value;
+                               } else {
+                                       print value;
+                               }
+                       }
+                       print " return 0;"
+                       print "}"
                }
                }
 EOF1
@@ -422,6 +457,8 @@ cat >$TMP <<EOF
 #include <ncurses_cfg.h>
 #undef NCURSES_NOMACROS
 #include <curses.h>
+#include <term.h>
+#include <unctrl.h>
 
 DECLARATIONS
 
@@ -437,11 +474,22 @@ sed -n -f $ED1 \
        -e 's/gen_$//' \
        -e 's/  / /g' >>$TMP
 
+cat >$ED1 <<EOF
+s/  / /g
+s/^ //
+s/ $//
+s/P_NCURSES_BOOL/NCURSES_BOOL/g
+EOF
+
+# A patch discussed here:
+#      https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02185.html
+# introduces spurious #line markers.  Work around that by ignoring the system's
+# attempt to define "bool" and using our own symbol here.
+sed -e 's/bool/P_NCURSES_BOOL/g' $TMP > $ED2
+cat $ED2 >$TMP
+
 $preprocessor $TMP 2>/dev/null \
-| sed \
-       -e 's/  / /g' \
-       -e 's/^ //' \
-       -e 's/_Bool/NCURSES_BOOL/g' \
+| sed -f $ED1 \
 | $AWK -f $AW2 \
 | sed -f $ED3 \
 | sed \