Add `gnomesupport.awk'.
authorRaja R Harinath <harinath@src.gnome.org>
Thu, 11 Jun 1998 20:37:48 +0000 (20:37 +0000)
committerRaja R Harinath <harinath@src.gnome.org>
Thu, 11 Jun 1998 20:37:48 +0000 (20:37 +0000)
* Makefile.am (EXTRA_DIST): Add `gnomesupport.awk'.

Also, simplied `gnomesupport.awk', and really removed
`gnomesupport-h.c'.

svn path=/trunk/; revision=251

support/ChangeLog
support/Makefile.am
support/gnomesupport-h.c [deleted file]
support/gnomesupport.awk

index 245cf62..e5787d2 100644 (file)
@@ -2,6 +2,8 @@
 
        * Makefile.am (gnomesupport.h): Build with `gnomesupport.awk'.
        (CROSS_COMPILING): Remove.
+       (EXTRA_DIST): Add `gnomesupport.awk'.
+
        * gnomesupport.awk: New file, to replace `gnomesupport-h.c'.
        * gnomesupport-h.c: Removed.  Doesn't work well in cross-compiles.
 
index 84d51aa..53959a0 100644 (file)
@@ -29,4 +29,4 @@ gnomesupport.h: gnomesupport.awk $(top_builddir)/config.h
 
 endif
 
-EXTRA_DIST = argp-test.c argp.texi
+EXTRA_DIST = argp-test.c argp.texi gnomesupport.awk
diff --git a/support/gnomesupport-h.c b/support/gnomesupport-h.c
deleted file mode 100644 (file)
index 5da55bf..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-/* This program is used to generate `gnomesupport.h'.  */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-/* It emits prototypes of (some of) the functions that have been built
-   into libgnomesupport, i.e. functions that are missing on the system.
-   It should explain what appears like reverse logic.  
-   
-   Notes:
-   - The generated file SHOULD NOT refer to <config.h>.
-   - The generated file SHOULD NOT #define or use (#ifdef/#ifndef &c.) any
-     symbols in the HAVE_* namespace.
-   - The generated file prefarably should not have any #ifdefs (except for
-     the include guard and the C++ guard, which it should have).  */
-
-int main(void)
-{
-  puts("\
-/* gnomesupport.h */
-/* This is a generated file.  Please modify `gnomesupport-h.c'.  */
-
-#ifndef GNOMESUPPORT_H
-#define GNOMESUPPORT_H
-
-#ifdef __cplusplus
-extern \"C\" {
-#endif /* __cplusplus */
-
-#include <stddef.h>            /* for size_t */
-");
-  
-#if !defined HAVE_VASPRINTF || !defined HAVE_VSNPRINTF
-  puts("\
-#include <stdarg.h>
-");
-#endif
-
-#ifndef HAVE_SCANDIR
-  /* FreeBSD apparently needs this before <dirent.h>.
-     Anyway, it is a good idea to include <sys/types.h> before including
-     any other <sys/...> header.  */
-  puts("\
-#include <sys/types.h>
-");
-
-  /* The following tests and #defines are based on the tests suggested
-     for AC_HEADER_DIRENT in the autoconf manual.  */
-# if HAVE_DIRENT_H
-  puts("\
-#include <dirent.h>
-#define NAMLEN(dirent) strlen((dirent)->d_name)
-");
-# else /* not HAVE_DIRENT_H */
-  puts("\
-#define dirent direct
-#define NAMLEN(dirent) (dirent)->d_namlen
-");
-#  if HAVE_SYS_NDIR_H
-  puts("\
-#include <sys/ndir.h>
-");
-#  endif /* HAVE_SYS_NDIR_H */
-#  if HAVE_SYS_DIR_H
-  puts("\
-#include <sys/dir.h>
-");
-#  endif /* HAVE_SYS_DIR_H */
-#  if HAVE_NDIR_H
-  puts("\
-#include <ndir.h>
-");
-#  endif /* HAVE_NDIR_H */
-# endif /* not HAVE_DIRENT_H */
-#endif /* not HAVE_SCANDIR */
-
-  puts("\
-#undef PARAMS
-#if defined __cplusplus || defined __GNUC__ || __STDC__
-# define PARAMS(args) args
-#else
-# define PARAMS(args) ()
-#endif
-");
-  
-#ifndef HAVE_SCANDIR
-  puts("\
-/* Scan the directory DIR, calling SELECTOR on each directory entry.
-   Entries for which SELECTOR returns nonzero are individually malloc'd,
-   sorted using qsort with CMP, and collected in a malloc'd array in
-   *NAMELIST.  Returns the number of entries selected, or -1 on error.  */
-int scandir PARAMS((const char */*dir*/, struct dirent ***/*namelist*/,
-                   int (*/*selector*/) PARAMS ((struct dirent *)),
-                   int (*/*cmp*/) PARAMS ((const void *, const void *))));
-
-/* Function to compare two `struct dirent's alphabetically.  */
-int alphasort PARAMS((const void */*a*/, const void */*b*/));
-");
-#endif
-
-#ifndef HAVE_STRERROR
-  puts("\
-/* Return a string describing the meaning of the `errno' code in ERRNUM.  */
-extern char *strerror PARAMS((int /*errnum*/));
-");
-#endif
-  
-#ifndef HAVE_STRCASECMP
-  puts("\
-/* Compare S1 and S2, ignoring case.  */
-int strcasecmp PARAMS((const char */*s1*/, const char */*s2*/));
-");
-#endif
-
-#ifndef HAVE_STRNDUP
-  puts("\
-/* Return a malloc'd copy of at most N bytes of STRING.  The
-   resultant string is terminated even if no null terminator
-   appears before STRING[N].  */
-char * strndup PARAMS((const char */*s*/, size_t /*n*/));
-");
-#endif
-
-#ifndef HAVE_STRNLEN
-  puts("\
-/* Find the length of STRING, but scan at most MAXLEN characters.
-   If no '\\0' terminator is found in that many characters, return MAXLEN.  */
-size_t strnlen PARAMS((const char */*string*/, size_t /*maxlen*/));
-");
-#endif
-
-#ifndef HAVE_STRTOK_R
-  puts("\
-/* Divide S into tokens separated by characters in DELIM.  Information
-   passed between calls are stored in SAVE_PTR.  */
-char * strtok_r PARAMS((char */*s*/, const char */*delim*/,
-                       char **/*save_ptr*/));
-");
-#endif
-  
-#ifndef HAVE_VASPRINTF
-  puts("\
-/* Write formatted output to a string dynamically allocated with `malloc'.
-   Store the address of the string in *PTR.  */
-int vasprintf PARAMS((char **/*ptr*/, const char */*format*/,
-                     va_list /*args*/));
-int asprintf PARAMS((char **/*ptr*/, const char */*format*/, ...));
-");
-#endif
-
-#ifndef HAVE_VSNPRINTF
-  puts("\
-/* Maximum chars of output to write is MAXLEN.  */
-int vsnprintf PARAMS((char */*str*/, size_t /*maxlen*/, char */*fmt*/,
-                     va_list /*ap*/));
-int snprintf PARAMS((char */*str*/, size_t /*maxlen*/, char */*fmt*/, ...));
-");
-#endif
-
-  puts("\
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* GNOMESUPPORT_H */
-");
-  
-  return 0;
-}
index 025f519..fd38683 100644 (file)
@@ -1,10 +1,7 @@
 # This program is used to generate gnomesupport.h
 
+# Print prologue
 BEGIN {
-  have_dirent_h = have_ndir_h = have_scandir = have_strcasecmp = 0;
-  have_strerror = have_strndup = have_strnlen = have_strtok_r = 0;
-  have_sys_dir_h = have_sys_ndir_h = have_vasprintf = have_vsnprintf = 0;
-  
   print "/* gnomesupport.h */";
   print "/* This is a generated file.  Please modify `gnomesupport.awk' */";
   print "";
@@ -18,124 +15,102 @@ BEGIN {
   print "#include <stddef.h>           /* for size_t */";
 }
 
-/^\#define[ \t]+HAVE_DIRENT_H/         { have_dirent_h = 1 }
-/^\#define[ \t]+HAVE_NDIR_H/           { have_ndir_h = 1 }
-/^\#define[ \t]+HAVE_SCANDIR/          { have_scandir = 1 }
-/^\#define[ \t]+HAVE_STRCASECMP/       { have_strcasecmp = 1 }
-/^\#define[ \t]+HAVE_STRERROR/         { have_strerror = 1 }
-/^\#define[ \t]+HAVE_STRNDUP/          { have_strndup = 1 }
-/^\#define[ \t]+HAVE_STRNLEN/          { have_strnlen = 1 }
-/^\#define[ \t]+HAVE_STRTOK_R/         { have_strtok_r = 1 }
-/^\#define[ \t]+HAVE_SYS_DIR_H/                { have_sys_dir_h = 1 }
-/^\#define[ \t]+HAVE_SYS_NDIR_H/       { have_sys_ndir_h = 1 }
-/^\#define[ \t]+HAVE_VASPRINTF/                { have_vasprintf = 1 }
-/^\#define[ \t]+HAVE_VSNPRINTF/                { have_vsnprintf = 1 }
+# For each `#define HAVE_FOO 1', set def["HAVE_FOO"] = 1
+/^\#define[ \t]/ { def[$2] = 1; }
 
 END {
-  if (!have_vasprintf || !have_vsnprintf)
-    {
-      print ""
-      print "#include <stdarg.h>";
-    }
+  if (!def["HAVE_VASPRINTF"] || !def["HAVE_VSNPRINTF"]) {
+    print "";
+    print "#include <stdarg.h>";
+  }
   
-  if (!have_scandir)
-    {
-      print ""
-      print "#include <sys/types.h>";
-
-      if (have_dirent_h)
-       {
-         print "#include <dirent.h>";
-         print "#define NAMLEN(dirent) strlen((dirent)->d_name)";
-       }
-      else
-       {
-         print "#define dirent direct";
-         print "#define NAMLEN(dirent) (dirent)->d_namlen";
-
-         if (have_sys_ndir_h)
-           print "#include <sys/ndir.h>";
-         if (have_sys_dir_h)
-           print "#include <sys/dir.h>";
-         if (have_ndir_h)
-           print "#include <ndir.h>";
-       }
+  if (!def["HAVE_SCANDIR"]) {
+    print "";
+    print "#include <sys/types.h>";
 
-      print ""
-      print "/* Scan the directory DIR, calling SELECTOR on each directory";
-      print "   entry.  Entries for which SELECTOR returns nonzero are";
-      print "   individually malloc'd, sorted using qsort with CMP, and";
-      print "   collected in a malloc'd array in *NAMELIST.  Returns the";
-      print "   number of entries selected, or -1 on error.  */";
-      print "int scandir (const char */*dir*/, struct dirent ***/*namelist*/,";
-      print "             int (*/*selector*/) (struct dirent *),";
-      print "             int (*/*cmp*/) (const void *, const void *));";
-      print "";
-      print "/* Function to compare two `struct dirent's alphabetically.  */";
-      print "int alphasort (const void */*a*/, const void */*b*/);";
+    if (def["HAVE_DIRENT_H"]) {
+      print "#include <dirent.h>";
+      print "#define NAMLEN(dirent) strlen((dirent)->d_name)";
+    } else {
+      print "#define dirent direct";
+      print "#define NAMLEN(dirent) (dirent)->d_namlen";
+      
+      if (def["HAVE_SYS_NDIR_H"])
+       print "#include <sys/ndir.h>";
+      if (def["HAVE_SYS_DIR_H"])
+       print "#include <sys/dir.h>";
+      if (def["HAVE_NDIR_H"])
+       print "#include <ndir.h>";
     }
 
-  if (!have_strerror)
-    {
-      print ""
-      print "/* Return a string describing the meaning of the `errno' code";
-      print "   in ERRNUM.  */";
-      print "extern char *strerror (int /*errnum*/);";
-    }
+    print "";
+    print "/* Scan the directory DIR, calling SELECTOR on each directory";
+    print "   entry.  Entries for which SELECTOR returns nonzero are";
+    print "   individually malloc'd, sorted using qsort with CMP, and";
+    print "   collected in a malloc'd array in *NAMELIST.  Returns the";
+    print "   number of entries selected, or -1 on error.  */";
+    print "int scandir (const char */*dir*/, struct dirent ***/*namelist*/,";
+    print "             int (*/*selector*/) (struct dirent *),";
+    print "             int (*/*cmp*/) (const void *, const void *));";
+    print "";
+    print "/* Function to compare two `struct dirent's alphabetically.  */";
+    print "int alphasort (const void */*a*/, const void */*b*/);";
+  }
+  
+  if (!def["HAVE_STRERROR"]) {
+    print "";
+    print "/* Return a string describing the meaning of the `errno' code";
+    print "   in ERRNUM.  */";
+    print "extern char *strerror (int /*errnum*/);";
+  }
 
-  if (!have_strcasecmp)
-    {
-      print ""
-      print "/* Compare S1 and S2, ignoring case.  */";
-      print "int strcasecmp (const char */*s1*/, const char */*s2*/);"
-    }
+  if (!def["HAVE_STRCASECMP"]) {
+    print "";
+    print "/* Compare S1 and S2, ignoring case.  */";
+    print "int strcasecmp (const char */*s1*/, const char */*s2*/);";
+  }
 
-  if (!have_strndup)
-    {
-      print ""
-      print "/* Return a malloc'd copy of at most N bytes of STRING.  The";
-      print "   resultant string is terminated even if no null terminator";
-      print "   appears before STRING[N].  */";
-      print "char * strndup (const char */*s*/, size_t /*n*/);";
-    }
+  if (!def["HAVE_STRNDUP"]) {
+    print "";
+    print "/* Return a malloc'd copy of at most N bytes of STRING.  The";
+    print "   resultant string is terminated even if no null terminator";
+    print "   appears before STRING[N].  */";
+    print "char * strndup (const char */*s*/, size_t /*n*/);";
+  }
 
-  if (!have_strnlen)
-    {
-      print ""
-      print "/* Find the length of STRING, but scan at most MAXLEN";
-      print "   characters.  If no '\\0' terminator is found in that many";
-      print "   characters, return MAXLEN.  */";
-      print "size_t strnlen (const char */*string*/, size_t /*maxlen*/);";
-    }
+  if (!def["HAVE_STRNLEN"]) {
+    print "";
+    print "/* Find the length of STRING, but scan at most MAXLEN";
+    print "   characters.  If no '\\0' terminator is found in that many";
+    print "   characters, return MAXLEN.  */";
+    print "size_t strnlen (const char */*string*/, size_t /*maxlen*/);";
+  }
 
-  if (!have_strtok_r)
-    {
-      print "";
-      print "/* Divide S into tokens separated by characters in DELIM.";
-      print "   Information passed between calls are stored in SAVE_PTR.  */";
-      print "char * strtok_r (char */*s*/, const char */*delim*/,";
-      print "                 char **/*save_ptr*/);";
-    }
+  if (!def["HAVE_STRTOK_R"]) {
+    print "";
+    print "/* Divide S into tokens separated by characters in DELIM.";
+    print "   Information passed between calls are stored in SAVE_PTR.  */";
+    print "char * strtok_r (char */*s*/, const char */*delim*/,";
+    print "                 char **/*save_ptr*/);";
+  }
 
-  if (!have_vasprintf)
-    {
-      print "";
-      print "/* Write formatted output to a string dynamically allocated with";
-      print "`malloc'.  Store the address of the string in *PTR.  */";
-      print "int vasprintf (char **/*ptr*/, const char */*format*/,";
-      print "               va_list /*args*/);";
-      print "int asprintf (char **/*ptr*/, const char */*format*/, ...);";
-    }
+  if (!def["HAVE_VASPRINTF"]) {
+    print "";
+    print "/* Write formatted output to a string dynamically allocated with";
+    print "`malloc'.  Store the address of the string in *PTR.  */";
+    print "int vasprintf (char **/*ptr*/, const char */*format*/,";
+    print "               va_list /*args*/);";
+    print "int asprintf (char **/*ptr*/, const char */*format*/, ...);";
+  }
 
-  if (!have_vsnprintf)
-    {
-      print "";
-      print "/* Maximum chars of output to write is MAXLEN.  */";
-      print "int vsnprintf (char */*str*/, size_t /*maxlen*/,";
-      print "               char */*fmt*/, va_list /*ap*/);";
-      print "int snprintf (char */*str*/, size_t /*maxlen*/,";
-      print "              char */*fmt*/, ...);";
-    }
+  if (!def["HAVE_VSNPRINTF"]) {
+    print "";
+    print "/* Maximum chars of output to write is MAXLEN.  */";
+    print "int vsnprintf (char */*str*/, size_t /*maxlen*/,";
+    print "               char */*fmt*/, va_list /*ap*/);";
+    print "int snprintf (char */*str*/, size_t /*maxlen*/,";
+    print "              char */*fmt*/, ...);";
+  }
   
   print ""
   print "#ifdef __cplusplus";
@@ -144,5 +119,3 @@ END {
   print "";
   print "#endif /* GNOMESUPPORT_H */";
 }
-
-