ncurses 6.0 - patch 20170114
[ncurses.git] / ncurses / tinfo / MKnames.awk
index a61c648ddf37108a262f01bd25473ca769b5512f..7685d1831ef04733c4a487a478f997422b72c4f1 100644 (file)
@@ -1,5 +1,5 @@
 ##############################################################################
-# Copyright (c) 2007 Free Software Foundation, Inc.                          #
+# Copyright (c) 2007-2008,2009 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"), #
@@ -25,7 +25,7 @@
 # use or other dealings in this Software without prior written               #
 # authorization.                                                             #
 ##############################################################################
-# $Id: MKnames.awk,v 1.16 2007/08/18 21:37:52 tom Exp $
+# $Id: MKnames.awk,v 1.22 2009/03/21 21:03:39 tom Exp $
 function large_item(value) {
        result = sprintf("%d,", offset);
        offset = offset + length(value) + 1;
@@ -62,7 +62,7 @@ function print_offsets(name,value) {
        printf "%s",  value
        print  "};"
        print  ""
-       printf "static char ** ptr_%s = 0;\n", name
+       printf "static NCURSES_CONST char ** ptr_%s = 0;\n", name
        print  ""
 }
 
@@ -107,8 +107,6 @@ END {
                print  ""
                print  "#if BROKEN_LINKER || USE_REENTRANT"
                print  ""
-               print  "#include <term.h>"
-               print  ""
                if (bigstrings) {
                        printf "static const char _nc_name_blob[] = \n"
                        printf "%s;\n", bigstr;
@@ -120,20 +118,20 @@ END       {
                        print_offsets("strnames", large_strnames);
                        print  ""
                        print  "static IT *"
-                       print  "alloc_array(char ***value, const short *offsets, unsigned size)"
+                       print  "alloc_array(NCURSES_CONST char ***value, const short *offsets, unsigned size)"
                        print  "{"
                        print  "        if (*value == 0) {"
-                       print  "                if ((*value = typeCalloc(char *, size + 1)) != 0) {"
+                       print  "                if ((*value = typeCalloc(NCURSES_CONST char *, size + 1)) != 0) {"
                        print  "                        unsigned n;"
                        print  "                        for (n = 0; n < size; ++n) {"
-                       print  "                                (*value)[n] = _nc_name_blob + offsets[n];"
+                       print  "                                (*value)[n] = (NCURSES_CONST char *) _nc_name_blob + offsets[n];"
                        print  "                        }"
                        print  "                }"
                        print  "        }"
                        print  "        return *value;"
                        print  "}"
                        print  ""
-                       print  "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return alloc_array(&ptr_##it, _nc_offset_##it, SIZEOF(_nc_offset_##it)); }"
+                       print  "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API NCURSES_PUBLIC_VAR(it)(void) { return alloc_array(&ptr_##it, _nc_offset_##it, SIZEOF(_nc_offset_##it)); }"
                } else {
                        print  "#define DCL(it) static IT data##it[]"
                        print  ""
@@ -143,9 +141,18 @@ END        {
                        print_strings("numfnames", small_numfnames);
                        print_strings("strnames", small_strnames);
                        print_strings("strfnames", small_strfnames);
-                       print  "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return data##it; }"
+                       print  "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API NCURSES_PUBLIC_VAR(it)(void) { return data##it; }"
                }
                print  ""
+               print  "/* remove public definition which conflicts with FIX() */"
+               print  "#undef boolnames"
+               print  "#undef boolfnames"
+               print  "#undef numnames"
+               print  "#undef numfnames"
+               print  "#undef strnames"
+               print  "#undef strfnames"
+               print  ""
+               print  "/* add local definition */"
                print  "FIX(boolnames)"
                print  "FIX(boolfnames)"
                print  "FIX(numnames)"
@@ -153,6 +160,31 @@ END        {
                print  "FIX(strnames)"
                print  "FIX(strfnames)"
                print  ""
+               print  "/* restore the public definition */"
+               print  "#define boolnames  NCURSES_PUBLIC_VAR(boolnames())"
+               print  "#define boolfnames NCURSES_PUBLIC_VAR(boolfnames())"
+               print  "#define numnames   NCURSES_PUBLIC_VAR(numnames())"
+               print  "#define numfnames  NCURSES_PUBLIC_VAR(numfnames())"
+               print  "#define strnames   NCURSES_PUBLIC_VAR(strnames())"
+               print  "#define strfnames  NCURSES_PUBLIC_VAR(strfnames())"
+               print  ""
+               print  "#define FREE_FIX(it) if (ptr_##it) { FreeAndNull(ptr_##it); }"
+               print  ""
+               print  "#if NO_LEAKS"
+               print  "NCURSES_EXPORT(void)"
+               print  "_nc_names_leaks(void)"
+               print  "{"
+               if (bigstrings) {
+               print  "FREE_FIX(boolnames)"
+               print  "FREE_FIX(boolfnames)"
+               print  "FREE_FIX(numnames)"
+               print  "FREE_FIX(numfnames)"
+               print  "FREE_FIX(strnames)"
+               print  "FREE_FIX(strfnames)"
+               }
+               print  "}"
+               print  "#endif"
+               print  ""
                print  "#else"
                print  ""
                print  "#define DCL(it) NCURSES_EXPORT_VAR(IT) it[]"