X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2FMKlib_gen.sh;h=d8cc3c9751faa157d0c8cb8e16fbe4217703966b;hp=12a83e049680d88cd9a3e964ef082076c695c0db;hb=ba39fbc2e0cee4681395df4079d9e61c27262132;hpb=cf94c7485f7b40ff7870b5bf9a65e7ab87481a76 diff --git a/ncurses/base/MKlib_gen.sh b/ncurses/base/MKlib_gen.sh index 12a83e04..d8cc3c97 100755 --- a/ncurses/base/MKlib_gen.sh +++ b/ncurses/base/MKlib_gen.sh @@ -2,10 +2,10 @@ # # MKlib_gen.sh -- generate sources from curses.h macro definitions # -# ($Id: MKlib_gen.sh,v 1.40 2010/03/30 22:42:16 tom Exp $) +# ($Id: MKlib_gen.sh,v 1.46 2011/06/04 19:14:08 tom Exp $) # ############################################################################## -# Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. # +# Copyright (c) 1998-2010,2011 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 == "*" ) { @@ -264,24 +266,26 @@ $0 !~ /^P_/ { argtype = "" for (i = myfunc; i <= NF; i++) { ch = $i; - if ( ch == "*" ) + if ( ch == "*" ) { pointer = 1; - else if ( ch == "va_list" ) + } else if ( ch == "va_list" ) { va_list = 1; - else if ( ch == "..." ) + } else if ( ch == "..." ) { varargs = 1; - else if ( ch == "char" ) + } else if ( ch == "char" ) { argtype = "char"; - else if ( ch == "int" ) + } else if ( ch == "int" ) { argtype = "int"; - else if ( ch == "short" ) + } else if ( ch == "short" ) { argtype = "short"; - else if ( ch == "chtype" ) + } else if ( ch == "chtype" ) { argtype = "chtype"; - else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" ) + } else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" ) { argtype = "attr"; + } if ( ch == "," || ch == ")" ) { + argcast = ""; if (va_list) { call = call "%s" } else if (varargs) { @@ -302,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)" @@ -315,7 +322,7 @@ $0 !~ /^P_/ { } else if ( varargs ) { args = args comma "\"...\"" } else { - args = args comma "z" + args = args comma argcast "z" } } call = call ch @@ -337,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++) { @@ -357,8 +368,9 @@ $0 !~ /^P_/ { } if (!match($0, "^void")) call = call ") "; - if (dotrace) + if (dotrace) { call = call ")"; + } print call ";" if (match($0, "^void")) @@ -398,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 @@ -410,6 +457,8 @@ cat >$TMP < #undef NCURSES_NOMACROS #include +#include +#include DECLARATIONS