]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/MKlib_gen.sh
ncurses 4.2
[ncurses.git] / ncurses / MKlib_gen.sh
index a08dc0a0c45709db782997f52129eb2ecae7b46b..0a29c6085f62bad34fa6571e7a46ae2b437e8a70 100755 (executable)
@@ -2,7 +2,7 @@
 #
 # MKlib_gen.sh -- generate sources from curses.h macro definitions
 #
-# ($Id: MKlib_gen.sh,v 1.9 1997/05/10 23:48:19 tom Exp $)
+# ($Id: MKlib_gen.sh,v 1.11 1998/01/17 14:16:52 Juan.Jose.Garcia.Ripoll Exp $)
 #
 # The XSI Curses standard requires all curses entry points to exist as
 # functions, even though many definitions would normally be shadowed
 
 preprocessor="$1 -I../include"
 AWK="$2"
+ED1=sed1$$.sed
+ED2=sed2$$.sed
+ED3=sed3$$.sed
+AW1=awk1$$.awk
 TMP=gen$$.c
-trap "rm -f $TMP" 0 1 2 5 15
+trap "rm -f $ED1 $ED2 $ED3 $AW1 $TMP" 0 1 2 5 15
 
 (cat <<EOF
 #include <ncurses_cfg.h>
@@ -38,32 +42,76 @@ trap "rm -f $TMP" 0 1 2 5 15
 DECLARATIONS
 
 EOF
-sed -n -e "/^extern.*generated/s/^extern \([^;]*\);.*/\1/p" \
-| sed \
-       -e "/(void)/b nc" \
-       -e "s/,/ a1% /" \
-       -e "s/,/ a2% /" \
-       -e "s/,/ a3% /" \
-       -e "s/,/ a4% /" \
-       -e "s/,/ a5% /" \
-       -e "s/,/ a6% /" \
-       -e "s/,/ a7% /" \
-       -e "s/,/ a8% /" \
-       -e "s/,/ a9% /" \
-       -e "s/,/ a10% /" \
-       -e "s/,/ a11% /" \
-       -e "s/,/ a12% /" \
-       -e "s/,/ a13% /" \
-       -e "s/,/ a14% /" \
-       -e "s/,/ a15% /" \
-       -e "s/*/ * /g" \
-       -e "s/%/ , /g" \
-       -e "s/)/ z)/" \
-       -e ":nc" \
-       -e "/(/s// ( /" \
-       -e "s/)/ )/" \
-| $AWK '{
-       print "\n"
+cat >$ED1 <<EOF1
+/^extern.*generated/{
+       h
+       s/^.*generated:\([^     *]*\).*/P_#if_USE_\1_SUPPORT/p
+       g
+       s/^extern \([^;]*\);.*/\1/p
+       g
+       s/^.*generated:\([^     *]*\).*/P_#endif/p
+}
+EOF1
+
+cat >$ED2 <<EOF2
+/^P_/b nc
+/(void)/b nc
+       s/,/ a1% /
+       s/,/ a2% /
+       s/,/ a3% /
+       s/,/ a4% /
+       s/,/ a5% /
+       s/,/ a6% /
+       s/,/ a7% /
+       s/,/ a8% /
+       s/,/ a9% /
+       s/,/ a10% /
+       s/,/ a11% /
+       s/,/ a12% /
+       s/,/ a13% /
+       s/,/ a14% /
+       s/,/ a15% /
+       s/*/ * /g
+       s/%/ , /g
+       s/)/ z)/
+:nc
+       /(/s// ( /
+       s/)/ )/
+EOF2
+
+cat >$ED3 <<EOF3
+/^P_/{
+       s/^P_#if_/#if /
+       s/^P_//
+       b done
+}
+       s/              */ /g
+       s/  */ /g
+       s/ ,/,/g
+       s/ )/)/g
+       s/ gen_/ /
+       s/^M_/#undef /
+       /^%%/s//        /
+:done
+EOF3
+
+cat >$AW1 <<\EOF1
+BEGIN  {
+               skip=0;
+       }
+       /^P_#if/ {
+               print "\n"
+               print $0
+               skip=0;
+       }
+       /^P_#endif/ {
+               print $0
+               skip=1;
+       }
+       $0 !~ /^P_/ {
+       if (skip)
+               print "\n"
+       skip=1;
 
        print "M_" $2
        print $0;
@@ -171,7 +219,10 @@ sed -n -e "/^extern.*generated/s/^extern \([^;]*\);.*/\1/p" \
                print "%%returnVoid;"
        print "}";
 }
-' ) \
+EOF1
+
+sed -n -f $ED1 | sed -f $ED2 \
+| $AWK -f $AW1 ) \
 | sed \
        -e '/^\([a-z_][a-z_]*\) /s//\1 gen_/' >$TMP
   $preprocessor $TMP 2>/dev/null \
@@ -182,15 +233,13 @@ BEGIN             {
        print " * It is generated by MKlib_gen.sh."
        print " *"
        print " * This is a file of trivial functions generated from macro"
-       print " * definitions in curses.h in order to satisfy the XSI Curses"
-       print " * requirement that every macro also exist as a callable"
-       print " * function."
+       print " * definitions in curses.h to satisfy the XSI Curses requirement"
+       print " * that every macro also exist as a callable function."
        print " *"
        print " * It will never be linked unless you call one of the entry"
        print " * points with its normal macro definition disabled.  In that"
        print " * case, if you have no shared libraries, it will indirectly"
        print " * pull most of the rest of the library into your link image."
-       print " * Cope with it."
        print " */"
        print "#include <curses.priv.h>"
        print ""
@@ -198,14 +247,7 @@ BEGIN              {
 /^DECLARATIONS/        {start = 1; next;}
                {if (start) print $0;}
 ' \
-| sed \
-       -e 's/          */ /g' \
-       -e 's/  */ /g' \
-       -e 's/ ,/,/g' \
-       -e 's/ )/)/g' \
-       -e 's/ gen_/ /' \
-       -e 's/^M_/#undef /' \
-       -e '/^%%/s//    /' \
+| sed -f $ED3 \
 | sed \
        -e 's/^.*T_CALLED.*returnCode( \([a-z].*) \));/ return \1;/' \
        -e 's/^.*T_CALLED.*returnCode( \((wmove.*) \));/        return \1;/'