]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/MKlib_gen.sh
ncurses 5.9 - patch 20150418
[ncurses.git] / ncurses / base / MKlib_gen.sh
index decf3c6a5ffc6ad75d38c79e5f1e317cc68e8690..b91398c740a266f10edbbce19f19c52b9709556f 100755 (executable)
@@ -2,10 +2,10 @@
 #
 # MKlib_gen.sh -- generate sources from curses.h macro definitions
 #
-# ($Id: MKlib_gen.sh,v 1.41 2010/12/19 00:39:24 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"), #
@@ -200,6 +200,7 @@ $0 !~ /^P_/ {
                }
        }
        second = first + 1;
+       returnCast = "";
        if ( $first == "chtype" ) {
                returnType = "Chtype";
        } else if ( $first == "SCREEN" ) {
@@ -207,7 +208,8 @@ $0 !~ /^P_/ {
        } else if ( $first == "WINDOW" ) {
                returnType = "Win";
        } else if ( $first == "attr_t" || $second == "attrset" || $second == "standout" || $second == "standend" || $second == "wattrset" || $second == "wstandout" || $second == "wstandend" ) {
-               returnType = "Attr";
+               returnType = "IntAttr";
+               returnCast = "(attr_t)";
        } else if ( $first == "bool" || $first == "NCURSES_BOOL" ) {
                returnType = "Bool";
        } else if ( $second == "*" ) {
@@ -283,6 +285,7 @@ $0 !~ /^P_/ {
                }
 
                if ( ch == "," || ch == ")" ) {
+                       argcast = "";
                        if (va_list) {
                                call = call "%s"
                        } else if (varargs) {
@@ -303,6 +306,9 @@ $0 !~ /^P_/ {
                                } else if ( argtype != "" ) {
                                        call = call "%s"
                                        comma = comma "_trace" argtype "2(" num ","
+                                       if (argtype == "attr") {
+                                               argcast = "(chtype)";
+                                       }
                                } else {
                                        call = call "%#lx"
                                        comma = comma "(long)"
@@ -316,7 +322,7 @@ $0 !~ /^P_/ {
                                } else if ( varargs ) {
                                        args = args comma "\"...\""
                                } else {
-                                       args = args comma "z"
+                                       args = args comma argcast "z"
                                }
                        }
                        call = call ch
@@ -338,12 +344,16 @@ $0 !~ /^P_/ {
        if (dotrace)
                printf "%s", call
 
-       if (match($0, "^void"))
+       if (match($0, "^void")) {
                call = ""
-       else if (dotrace)
+       } else if (dotrace) {
                call = sprintf("return%s( ", returnType);
-       else
+               if (returnCast != "") {
+                       call = call returnCast;
+               }
+       } else {
                call = "@@return ";
+       }
 
        call = call $myfunc "(";
        for (i = 1; i < argcount; i++) {
@@ -358,8 +368,9 @@ $0 !~ /^P_/ {
        }
        if (!match($0, "^void"))
                call = call ") ";
-       if (dotrace)
+       if (dotrace) {
                call = call ")";
+       }
        print call ";"
 
        if (match($0, "^void"))
@@ -399,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
@@ -411,6 +457,8 @@ cat >$TMP <<EOF
 #include <ncurses_cfg.h>
 #undef NCURSES_NOMACROS
 #include <curses.h>
+#include <term.h>
+#include <unctrl.h>
 
 DECLARATIONS
 
@@ -426,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 \