gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gawk-diffs] [SCM] gawk branch, extgawk, updated. e4945f9ecab4d2a143f9e4


From: Arnold Robbins
Subject: [gawk-diffs] [SCM] gawk branch, extgawk, updated. e4945f9ecab4d2a143f9e41b6a112bb2d36fa7c1
Date: Thu, 26 Jul 2012 20:08:20 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, extgawk has been updated
       via  e4945f9ecab4d2a143f9e41b6a112bb2d36fa7c1 (commit)
       via  ce63a9b40865adeaa643208d9c645bd5ac5575e3 (commit)
       via  dfff2221d2d36ef3fba2a3970440079e2415f8b2 (commit)
       via  11cdf30aa3c7b397ba0702a043f5a44f3607b218 (commit)
       via  652a11e5fbe9862a2b8e961b32b9748b3c2c418b (commit)
       via  c3d3c83b0a60454c7b1bc335c022051b58f393e3 (commit)
      from  ca83de0ec92b56c712f7a7376b21a1a1337b3107 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=e4945f9ecab4d2a143f9e41b6a112bb2d36fa7c1

commit e4945f9ecab4d2a143f9e41b6a112bb2d36fa7c1
Author: Arnold D. Robbins <address@hidden>
Date:   Thu Jul 26 23:07:52 2012 +0300

    Add os_isreadable function for future use.

diff --git a/ChangeLog b/ChangeLog
index a7368de..44de58f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2012-07-26         Arnold D. Robbins     <address@hidden>
 
        * awk.h (set_RT_to_null, set_RT): Declare functions.
+       (os_isreadable): Declare function.
        * io.c (set_RT_to_null, set_RT): New functions.
        (iop_close): Init ret to zero.
        * gawkapi.c (api_register_input_parser): Check for null pointer.
diff --git a/awk.h b/awk.h
index ebdbe77..3b7129f 100644
--- a/awk.h
+++ b/awk.h
@@ -1532,6 +1532,7 @@ extern int os_devopen(const char *name, int flag);
 extern void os_close_on_exec(int fd, const char *name, const char *what, const 
char *dir);
 extern int os_isatty(int fd);
 extern int os_isdir(int fd);
+extern int os_isreadable(int fd);
 extern int os_is_setuid(void);
 extern int os_setbinmode(int fd, int mode);
 extern void os_restore_mode(int fd);
diff --git a/pc/ChangeLog b/pc/ChangeLog
index 1eb5181..4322192 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,7 @@
+2012-07-26         Arnold D. Robbins     <address@hidden>
+
+       * gawkmisc.pc (os_isreadable): New function.
+
 2012-05-06         Eli Zaretskii  <address@hidden>
 
        * config.sed: Update DJGPP -> __DJGPP__.
diff --git a/pc/gawkmisc.pc b/pc/gawkmisc.pc
index b368e81..999167c 100644
--- a/pc/gawkmisc.pc
+++ b/pc/gawkmisc.pc
@@ -232,6 +232,31 @@ int fd;
        return (fstat(fd, &sbuf) == 0 && S_ISDIR(sbuf.st_mode));
 }
 
+/* os_isreadable --- fd can be read from */
+
+int
+os_isreadable(int fd)
+{
+       struct stat sbuf;
+
+       if (fstat(fd, &sbuf) != 0)
+               return false;
+
+       switch (sbuf.st_mode & S_IFMT) {
+       case S_IFREG:
+       case S_IFCHR:   /* ttys, /dev/null, .. */
+#ifdef S_IFSOCK
+       case S_IFSOCK:
+#endif
+#ifdef S_IFIFO
+       case S_IFIFO:
+#endif
+               return true;
+       default:
+               return false;
+       }
+}
+
 /* os_is_setuid --- true if running setuid root */
 
 int
diff --git a/posix/ChangeLog b/posix/ChangeLog
index bf36414..a3ee87d 100644
--- a/posix/ChangeLog
+++ b/posix/ChangeLog
@@ -1,3 +1,7 @@
+2012-07-26         Arnold D. Robbins     <address@hidden>
+
+       * gawkmisc.c (os_isreadable): New function.
+
 2012-05-11         Arnold D. Robbins     <address@hidden>
 
        * gawkmisc.c: Use `bool', `true', and `false' everywhere.
diff --git a/posix/gawkmisc.c b/posix/gawkmisc.c
index 3baf852..87a6747 100644
--- a/posix/gawkmisc.c
+++ b/posix/gawkmisc.c
@@ -204,6 +204,31 @@ os_isdir(int fd)
        return (fstat(fd, &sbuf) == 0 && S_ISDIR(sbuf.st_mode));
 }
 
+/* os_isreadable --- fd can be read from */
+
+int
+os_isreadable(int fd)
+{
+       struct stat sbuf;
+
+       if (fstat(fd, &sbuf) != 0)
+               return false;
+
+       switch (sbuf.st_mode & S_IFMT) {
+       case S_IFREG:
+       case S_IFCHR:   /* ttys, /dev/null, .. */
+#ifdef S_IFSOCK
+       case S_IFSOCK:
+#endif
+#ifdef S_IFIFO
+       case S_IFIFO:
+#endif
+               return true;
+       default:
+               return false;
+       }
+}
+
 /* os_is_setuid --- true if running setuid root */
 
 int
diff --git a/vms/ChangeLog b/vms/ChangeLog
index 9988d34..c4cb6ed 100644
--- a/vms/ChangeLog
+++ b/vms/ChangeLog
@@ -1,3 +1,7 @@
+2012-07-26         Arnold D. Robbins     <address@hidden>
+
+       * gawkmisc.vms (os_isreadable): New function.
+
 2012-03-29         Arnold D. Robbins     <address@hidden>
 
        * config.h: Add definition for _Noreturn.
diff --git a/vms/gawkmisc.vms b/vms/gawkmisc.vms
index 90b2530..f373b5f 100644
--- a/vms/gawkmisc.vms
+++ b/vms/gawkmisc.vms
@@ -144,6 +144,31 @@ int fd;
        return (fstat(fd, &sbuf) == 0 && S_ISDIR(sbuf.st_mode));
 }
 
+/* os_isreadable --- fd can be read from */
+
+int
+os_isreadable(int fd)
+{
+       struct stat sbuf;
+
+       if (fstat(fd, &sbuf) != 0)
+               return false;
+
+       switch (sbuf.st_mode & S_IFMT) {
+       case S_IFREG:
+       case S_IFCHR:   /* ttys, /dev/null, .. */
+#ifdef S_IFSOCK
+       case S_IFSOCK:
+#endif
+#ifdef S_IFIFO
+       case S_IFIFO:
+#endif
+               return true;
+       default:
+               return false;
+       }
+}
+
 /* os_is_setuid --- true if running setuid root */
 
 int

http://git.sv.gnu.org/cgit/gawk.git/commit/?id=ce63a9b40865adeaa643208d9c645bd5ac5575e3

commit ce63a9b40865adeaa643208d9c645bd5ac5575e3
Author: Arnold D. Robbins <address@hidden>
Date:   Thu Jul 26 23:03:58 2012 +0300

    Documentation update.

diff --git a/TODO.xgawk b/TODO.xgawk
index 6e14929..d11fad6 100644
--- a/TODO.xgawk
+++ b/TODO.xgawk
@@ -3,56 +3,10 @@ To-do list for xgawk enhancements:
 - Attempting to load the same file with -f and -i (or @include) should
   be a fatal error.
 
-- Develop a libgawk shared library for use by extensions.  Should this
-  be hosted in a separate project?
-
-  A few existing extensions use a hash API for mapping string
-  handles to structures.  In xgawk, we had this API inside array.c, but it
-  probably belongs in a separate libgawk shared library:
-
-  typedef struct _strhash strhash;
-  extern strhash *strhash_create P((size_t min_table_size));
-  /* Find an entry in the hash table.  If it is not found, the 
insert_if_missing
-     argument indicates whether a new entry should be created.  The caller
-     may set the "data" field to any desired value.  If it is a new entry,
-     "data" will be initialized to NULL. */
-  extern strhash_entry *strhash_get P((strhash *, const char *s, size_t len,
-                                      int insert_if_missing));
-  typedef void (*strhash_delete_func)(void *data, void *opaque,
-                                     strhash *, strhash_entry *);
-  extern int strhash_delete P((strhash *, const char *s, size_t len,
-                              strhash_delete_func, void *opaque));
-  extern void strhash_destroy P((strhash *, strhash_delete_func, void 
*opaque));
-
-- Review open hook implementation.  Arnold's comments on this:
-   I think the code flow in io.c needs reviewing. It's not
-   clear to me under what circumstances open hooks (a) are called, or
-   (b) should be called.  Only the XML extension uses them now, but I
-   think it'd be a nice mechanism to generalize if possible, and to
-   document.
-   
-   E.g., I can easily envision an open hook to turn directories into records
-   of the form
-  
-         type link-count mode owner group atime mtime ctime name
-   
-   I could also envision an open hook to provide an interface to libiconv
-   (somehow).  More discussion / explanation of the vision behind this
-   would be welcome.
-
-
-Separate projects for major standalone extensions.  We need to set up
-hosting for these projects:
-
-- XML
-
-- PostgreSQL
-
-- GD
-
-- MPFR.  This is probably not useful now that MPFR support has been
-  integrated into gawk.  Are there any users who need this extension?
-
+- Review open hook implementation.
+       * Mostly done.
+       * Still to go: Rework iop_alloc, interaction with open hooks, and
+         skipping command line directories.
 
 Low priority:
 
@@ -60,7 +14,6 @@ Low priority:
   And add an optional array argument to wait and waitpid in which to return
   exit status information.
 
-
 Possible future changes requiring (further) discussion:
 
 - Change from dlopen to using the libltdl library (i.e. lt_dlopen).
@@ -81,14 +34,12 @@ Possible future changes requiring (further) discussion:
   etc, I'd like to keep things simple.  But how we design this is going
   to be very important.
 
-
 Unlikely:
 
 - Include a sample rpm spec file in a new packaging subdirectory.
 
 - Patch lexer for @include and @load to make quotes optional.
 
-
 Done:
 
 - Add AWKLIBPATH with default pointing to ${libexecdir}/$PACKAGE/$VERSION
@@ -156,3 +107,36 @@ Done:
   I think this would result in complaints about shared library functions
   defined but not used.  So there should probably be an enhancement to func_use
   and ftable to indicate if it's a shared library function.
+
+- Develop a libgawk shared library for use by extensions.  Should this
+  be hosted in a separate project?
+
+  A few existing extensions use a hash API for mapping string
+  handles to structures.  In xgawk, we had this API inside array.c, but it
+  probably belongs in a separate libgawk shared library:
+
+  typedef struct _strhash strhash;
+  extern strhash *strhash_create P((size_t min_table_size));
+  /* Find an entry in the hash table.  If it is not found, the 
insert_if_missing
+     argument indicates whether a new entry should be created.  The caller
+     may set the "data" field to any desired value.  If it is a new entry,
+     "data" will be initialized to NULL. */
+  extern strhash_entry *strhash_get P((strhash *, const char *s, size_t len,
+                                      int insert_if_missing));
+  typedef void (*strhash_delete_func)(void *data, void *opaque,
+                                     strhash *, strhash_entry *);
+  extern int strhash_delete P((strhash *, const char *s, size_t len,
+                              strhash_delete_func, void *opaque));
+  extern void strhash_destroy P((strhash *, strhash_delete_func, void 
*opaque));
+
+- Separate projects for major standalone extensions.  We need to set up
+  hosting for these projects:
+
+       - XML
+
+       - PostgreSQL
+
+       - GD
+
+       - MPFR.  This is probably not useful now that MPFR support has been
+         integrated into gawk.  Are there any users who need this extension?

http://git.sv.gnu.org/cgit/gawk.git/commit/?id=dfff2221d2d36ef3fba2a3970440079e2415f8b2

commit dfff2221d2d36ef3fba2a3970440079e2415f8b2
Author: Arnold D. Robbins <address@hidden>
Date:   Thu Jul 26 23:03:08 2012 +0300

    Robustify extension/readdir.c.

diff --git a/extension/ChangeLog b/extension/ChangeLog
index 05682e5..ae0df1a 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -8,6 +8,9 @@
 
        * testext.c (valrep2str): Add AWK_VALUE_COOKIE.
 
+       * readdir.c: Add readdir_do_ftype function for systems without
+       dirent->d_type.  Clean up buffer handling.
+
 2012-07-26         Andrew J. Schorr     <address@hidden>
 
        * readdir.c (dir_get_record): No need to set *errcode to 0.
diff --git a/extension/configh.in b/extension/configh.in
index 179b586..7307d38 100644
--- a/extension/configh.in
+++ b/extension/configh.in
@@ -1,8 +1,14 @@
 /* configh.in.  Generated from configure.ac by autoheader.  */
 
+/* Define to 1 if you have the <dirent.h> header file. */
+#undef HAVE_DIRENT_H
+
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
+/* Define to 1 if you have the `fdopendir' function. */
+#undef HAVE_FDOPENDIR
+
 /* Define to 1 if you have the `fnmatch' function. */
 #undef HAVE_FNMATCH
 
diff --git a/extension/configure b/extension/configure
index 94be75b..4fa61f3 100755
--- a/extension/configure
+++ b/extension/configure
@@ -11462,7 +11462,7 @@ then
        CFLAGS="$CFLAGS -Wall -Wextra"
 fi
 
-for ac_header in fnmatch.h time.h sys/time.h sys/select.h
+for ac_header in dirent.h fnmatch.h time.h sys/time.h sys/select.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" 
"$ac_includes_default"
@@ -11476,7 +11476,7 @@ fi
 done
 
 
-for ac_func in fnmatch gettimeofday nanosleep select GetSystemTimeAsFileTime
+for ac_func in fdopendir fnmatch gettimeofday nanosleep select 
GetSystemTimeAsFileTime
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/extension/configure.ac b/extension/configure.ac
index 4583962..8f67477 100644
--- a/extension/configure.ac
+++ b/extension/configure.ac
@@ -45,9 +45,9 @@ then
        CFLAGS="$CFLAGS -Wall -Wextra"
 fi
 
-AC_CHECK_HEADERS(fnmatch.h time.h sys/time.h sys/select.h)
+AC_CHECK_HEADERS(dirent.h fnmatch.h time.h sys/time.h sys/select.h)
 
-AC_CHECK_FUNCS(fnmatch gettimeofday nanosleep select GetSystemTimeAsFileTime)
+AC_CHECK_FUNCS(fdopendir fnmatch gettimeofday nanosleep select 
GetSystemTimeAsFileTime)
 
 dnl checks for compiler characteristics
 AC_C_INLINE
diff --git a/extension/readdir.c b/extension/readdir.c
index a0a82a2..f2a1602 100644
--- a/extension/readdir.c
+++ b/extension/readdir.c
@@ -1,5 +1,5 @@
 /*
- * readdir.c --- Provide an open hook to read directories
+ * readdir.c --- Provide an input parser to read directories
  *
  * Arnold Robbins
  * address@hidden
@@ -37,16 +37,35 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <dirent.h>
 
 #include "config.h"
+
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#else
+#error Cannot compile the dirent extension on this system!
+#endif
+
 #include "gawkapi.h"
 
+#include "gettext.h"
+#define _(msgid)  gettext(msgid)
+#define N_(msgid) msgid
+
 static const gawk_api_t *api;  /* for convenience macros to work */
 static awk_ext_id_t *ext_id;
 
+static awk_bool_t init_readdir(void);
+static awk_bool_t (*init_func)(void) = init_readdir;
+
 int plugin_is_GPL_compatible;
 
+#ifdef DT_BLK
+static const int do_ftype = 1;
+#else
+static int do_ftype;
+#endif
+
 /* ftype --- return type of file as a single character string */
 
 static const char *
@@ -93,6 +112,11 @@ ftype(struct dirent *entry)
 }
 
 
+typedef struct open_directory {
+       DIR *dp;
+       char *buf;
+} open_directory_t;
+
 /* dir_get_record --- get one record at a time out of a directory */
 
 static int
@@ -100,28 +124,37 @@ dir_get_record(char **out, struct iobuf_public *iobuf, 
int *errcode)
 {
        DIR *dp;
        struct dirent *dirent;
-       char buf[1000];
        size_t len;
-       static const awk_value_t null_val = { AWK_UNDEFINED };
-
-       if (out == NULL || iobuf == NULL || iobuf->opaque == NULL)
-               return EOF;
+       open_directory_t *the_dir;
+       static const awk_value_t null_val = { AWK_UNDEFINED, { { 0, 0 } } };
 
        /*
         * The caller sets *errcode to 0, so we should set it only if an
-        * error occurs.
+        * error occurs. Except that the compiler complains that it
+        * is unused, so we set it anyways.
         */
+       *errcode = 0;   /* keep the compiler happy */
+
+       if (out == NULL || iobuf == NULL || iobuf->opaque == NULL)
+               return EOF;
 
        set_RT((awk_value_t *) & null_val);
-       dp = (DIR *) iobuf->opaque;
+       the_dir = (open_directory_t *) iobuf->opaque;
+       dp = the_dir->dp;
        dirent = readdir(dp);
        if (dirent == NULL)
                return EOF;
 
-       sprintf(buf, "%ld/%s/%s", dirent->d_ino, dirent->d_name, ftype(dirent));
-       len = strlen(buf);
-       emalloc(*out, char *, len + 1, "dir_get_record");
-       strcpy(*out, buf);
+       if (do_ftype)
+               sprintf(the_dir->buf, "%ld/%s/%s",
+                               dirent->d_ino, dirent->d_name, ftype(dirent));
+       else
+               sprintf(the_dir->buf, "%ld/%s",
+                               dirent->d_ino, dirent->d_name);
+
+       *out = the_dir->buf;
+       len = strlen(the_dir->buf);
+
        return len;
 }
 
@@ -130,13 +163,17 @@ dir_get_record(char **out, struct iobuf_public *iobuf, 
int *errcode)
 static void
 dir_close(struct iobuf_public *iobuf)
 {
-       DIR *dp;
+       open_directory_t *the_dir;
 
        if (iobuf == NULL || iobuf->opaque == NULL)
                return;
 
-       dp = (DIR *) iobuf->opaque;
-       closedir(dp);
+       the_dir = (open_directory_t *) iobuf->opaque;
+
+       closedir(the_dir->dp);
+       free(the_dir->buf);
+       free(the_dir);
+
        iobuf->fd = -1;
 }
 
@@ -165,12 +202,25 @@ static int
 dir_take_control_of(IOBUF_PUBLIC *iobuf)
 {
        DIR *dp;
+       open_directory_t *the_dir;
+       size_t size;
 
+#ifdef HAVE_FDOPENDIR
        dp = fdopendir(iobuf->fd);
+#else
+       dp = opendir(iob->name);
+       if (dp != NULL)
+               iobuf->fd = dirfd(dp);
+#endif
        if (dp == NULL)
                return 0;
 
-       iobuf->opaque = dp;
+       emalloc(the_dir, open_directory_t *, sizeof(open_directory_t), 
"dir_take_control_of");
+       the_dir->dp = dp;
+       size = sizeof(struct dirent) + 20 /* max digits in inode */ + 2 /* 
slashes */;
+       emalloc(the_dir->buf, char *, size, "dir_take_control_of");
+
+       iobuf->opaque = the_dir;
        iobuf->get_record = dir_get_record;
        iobuf->close_func = dir_close;
 
@@ -193,21 +243,11 @@ static awk_input_parser_t readdir_parser2 = {
 };
 #endif
 
-int dl_load(const gawk_api_t *const api_p, awk_ext_id_t id) 
-{
-       api = api_p;
-       ext_id = id;
-
-       if (api->major_version != GAWK_API_MAJOR_VERSION
-           || api->minor_version < GAWK_API_MINOR_VERSION) {
-               fprintf(stderr, "readdir: version mismatch with gawk!\n");
-               fprintf(stderr, "\tmy version (%d, %d), gawk version (%d, 
%d)\n",
-                       GAWK_API_MAJOR_VERSION, GAWK_API_MINOR_VERSION,
-                       api->major_version, api->minor_version);
-               exit(1);
-       }
-
+/* init_readdir --- set things ups */
 
+static awk_bool_t
+init_readdir()
+{
        register_input_parser(& readdir_parser);
 #ifdef TEST_DUPLICATE
        register_input_parser(& readdir_parser2);
@@ -215,3 +255,40 @@ int dl_load(const gawk_api_t *const api_p, awk_ext_id_t id)
 
        return 1;
 }
+
+/* do_readdir_do_ftype --- enable / disable ftype where need to do stat */
+
+static awk_value_t *
+do_readdir_do_ftype(int nargs, awk_value_t *result)
+{
+       awk_value_t flag;
+
+       make_number(1.0, result);
+       if (nargs < 1) {
+               warning(ext_id, _("readdir_do_ftype: called with no 
arguments"));
+               make_number(0.0, result);
+               goto out;
+       } else if (do_lint && nargs > 3)
+               lintwarn(ext_id, _("readdir_do_ftype: called with more than one 
argument"));
+
+       if (! get_argument(0, AWK_NUMBER, & flag)) {
+               warning(ext_id, _("readdir_do_ftype: could not get argument"));
+               make_number(0.0, result);
+               goto out;
+       }
+
+#ifndef DT_BLK
+       do_ftype = (flag.num_value != 0.0);
+#endif
+
+out:
+       return result;
+}
+
+static awk_ext_func_t func_table[] = {
+       { "readdir_do_ftype", do_readdir_do_ftype, 1 },
+};
+
+/* define the dl_load function using the boilerplate macro */
+
+dl_load_func(func_table, readdir, "")

http://git.sv.gnu.org/cgit/gawk.git/commit/?id=11cdf30aa3c7b397ba0702a043f5a44f3607b218

commit 11cdf30aa3c7b397ba0702a043f5a44f3607b218
Author: Arnold D. Robbins <address@hidden>
Date:   Thu Jul 26 22:30:15 2012 +0300

    Fix warning in extension/testext.c.

diff --git a/extension/ChangeLog b/extension/ChangeLog
index 758f1b6..05682e5 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -6,6 +6,8 @@
        * readdir.c (dir_get_record): Call set_RT.
        (dir_can_take_file): Make parameter const.
 
+       * testext.c (valrep2str): Add AWK_VALUE_COOKIE.
+
 2012-07-26         Andrew J. Schorr     <address@hidden>
 
        * readdir.c (dir_get_record): No need to set *errcode to 0.
diff --git a/extension/testext.c b/extension/testext.c
index 44b6a87..d1ebac1 100644
--- a/extension/testext.c
+++ b/extension/testext.c
@@ -62,6 +62,9 @@ valrep2str(const awk_value_t *value)
        case AWK_SCALAR:
                strcpy(buf, "<scalar>");
                break;
+       case AWK_VALUE_COOKIE:
+               strcpy(buf, "<value-cookie>");
+               break;
        case AWK_STRING:
                if (value->str_value.len < size)
                        size = value->str_value.len;

http://git.sv.gnu.org/cgit/gawk.git/commit/?id=652a11e5fbe9862a2b8e961b32b9748b3c2c418b

commit 652a11e5fbe9862a2b8e961b32b9748b3c2c418b
Author: Arnold D. Robbins <address@hidden>
Date:   Thu Jul 26 22:27:54 2012 +0300

    Add set_RT to API and to readdir extension.

diff --git a/ChangeLog b/ChangeLog
index 192952b..a7368de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-07-26         Arnold D. Robbins     <address@hidden>
+
+       * awk.h (set_RT_to_null, set_RT): Declare functions.
+       * io.c (set_RT_to_null, set_RT): New functions.
+       (iop_close): Init ret to zero.
+       * gawkapi.c (api_register_input_parser): Check for null pointer.
+       (api_set_RT): New function.
+       * gawkapi.h (api_set_RT): New function.
+
 2012-07-26         Andrew J. Schorr     <address@hidden>
 
        * gawkapi.h (IOBUF_PUBLIC): Document the get_record and close_func
diff --git a/awk.h b/awk.h
index ddde04b..ebdbe77 100644
--- a/awk.h
+++ b/awk.h
@@ -1544,6 +1544,8 @@ extern void init_io(void);
 extern void register_input_parser(awk_input_parser_t *input_parser);
 extern void set_FNR(void);
 extern void set_NR(void);
+extern void set_RT_to_null(void);
+extern void set_RT(const char *str, size_t len);
 
 extern struct redirect *redirect(NODE *redir_exp, int redirtype, int *errflg);
 extern NODE *do_close(int nargs);
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 52dca76..758f1b6 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -3,6 +3,9 @@
        * configure.ac: Extremely crude hack to get the value of
        ENABLE_NLS so that gettext will work in extensions.
 
+       * readdir.c (dir_get_record): Call set_RT.
+       (dir_can_take_file): Make parameter const.
+
 2012-07-26         Andrew J. Schorr     <address@hidden>
 
        * readdir.c (dir_get_record): No need to set *errcode to 0.
diff --git a/extension/readdir.c b/extension/readdir.c
index c838ea7..a0a82a2 100644
--- a/extension/readdir.c
+++ b/extension/readdir.c
@@ -102,6 +102,7 @@ dir_get_record(char **out, struct iobuf_public *iobuf, int 
*errcode)
        struct dirent *dirent;
        char buf[1000];
        size_t len;
+       static const awk_value_t null_val = { AWK_UNDEFINED };
 
        if (out == NULL || iobuf == NULL || iobuf->opaque == NULL)
                return EOF;
@@ -111,7 +112,7 @@ dir_get_record(char **out, struct iobuf_public *iobuf, int 
*errcode)
         * error occurs.
         */
 
-       /* FIXME: Need stuff for setting RT */
+       set_RT((awk_value_t *) & null_val);
        dp = (DIR *) iobuf->opaque;
        dirent = readdir(dp);
        if (dirent == NULL)
@@ -142,7 +143,7 @@ dir_close(struct iobuf_public *iobuf)
 /* dir_can_take_file --- return true if we want the file */
 
 static int
-dir_can_take_file(IOBUF_PUBLIC *iobuf)
+dir_can_take_file(const IOBUF_PUBLIC *iobuf)
 {
        struct stat sbuf;
        int fd;
@@ -154,12 +155,15 @@ dir_can_take_file(IOBUF_PUBLIC *iobuf)
        return (fd >= 0 && fstat(fd, & sbuf) >= 0 && S_ISDIR(sbuf.st_mode));
 }
 
-/* dir_take_control_of --- set up input parser.  We can assume that 
dir_can_take_file just returned true, and no state has changed since then. */
+/*
+ * dir_take_control_of --- set up input parser.
+ * We can assume that dir_can_take_file just returned true,
+ * and no state has changed since then.
+ */
 
 static int
 dir_take_control_of(IOBUF_PUBLIC *iobuf)
 {
-       struct stat sbuf;
        DIR *dp;
 
        dp = fdopendir(iobuf->fd);
diff --git a/gawkapi.c b/gawkapi.c
index a1241df..12cd8af 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -222,9 +222,41 @@ api_register_input_parser(awk_ext_id_t id, 
awk_input_parser_t *input_parser)
 {
        (void) id;
 
+       if (input_parser == NULL)
+               return;
+
        register_input_parser(input_parser);
 }
 
+/* api_set_RT --- set RT's value */
+
+static void
+api_set_RT(awk_ext_id_t id, awk_value_t *value)
+{
+       NODE *n;
+
+       (void) id;
+
+       if (value == NULL)
+               return;
+
+       switch (value->val_type) {
+       case AWK_UNDEFINED:
+               set_RT_to_null();
+               break;
+       case AWK_ARRAY:
+       case AWK_VALUE_COOKIE:
+               break;
+       case AWK_STRING:
+       case AWK_NUMBER:
+       case AWK_SCALAR:
+               n = awk_value_to_node(value);
+               force_string(n);
+               set_RT(n->stptr, n->stlen);
+               unref(n);
+       }
+}
+
 /* Functions to update ERRNO */
 
 /* api_update_ERRNO_int --- update ERRNO with an integer value */
@@ -567,7 +599,6 @@ api_sym_update_scalar(awk_ext_id_t id,
                        awk_value_t *value)
 {
        NODE *node = (NODE *) cookie;
-       NODE *new_value;
 
        if (value == NULL
            || node == NULL
@@ -958,6 +989,7 @@ gawk_api_t api_impl = {
        api_lintwarn,
 
        api_register_input_parser,
+       api_set_RT,
 
        api_update_ERRNO_int,
        api_update_ERRNO_string,
diff --git a/gawkapi.h b/gawkapi.h
index bc7001c..db650fb 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -324,6 +324,9 @@ typedef struct gawk_api {
        /* Register an input parser; for opening files read-only */
        void (*api_register_input_parser)(awk_ext_id_t id, awk_input_parser_t 
*input_parser);
 
+       /* Set RT - pass AWK_UNDEFINED to set to null string */
+       void (*api_set_RT)(awk_ext_id_t id, awk_value_t *value);
+
        /* Functions to update ERRNO */
        void (*api_update_ERRNO_int)(awk_ext_id_t id, int errno_val);
        void (*api_update_ERRNO_string)(awk_ext_id_t id, const char *string);
@@ -504,6 +507,7 @@ typedef struct gawk_api {
 #define lintwarn       api->api_lintwarn
 
 #define register_input_parser(parser)  (api->api_register_input_parser(ext_id, 
parser))
+#define        set_RT(value)   (api->api_set_RT(ext_id, value))
 
 #define update_ERRNO_int(e)    (api->api_update_ERRNO_int(ext_id, e))
 #define update_ERRNO_string(str) \
diff --git a/io.c b/io.c
index 05e8790..f4ea286 100644
--- a/io.c
+++ b/io.c
@@ -536,7 +536,7 @@ remap_std_file(int oldfd)
 static int
 iop_close(IOBUF *iop)
 {
-       int ret;
+       int ret = 0;
 
        if (iop == NULL)
                return 0;
@@ -2667,6 +2667,30 @@ iop_alloc(int fd, const char *name, bool 
do_input_parsers)
        return iop;
 }
 
+/* set_RT_to_null --- real function for use by extension API */
+
+void
+set_RT_to_null()
+{
+       if (! do_traditional) {
+               unref(RT_node->var_value);
+               RT_node->var_value = dupnode(Nnull_string);
+       }
+}
+
+/* set_RT --- real function for use by extension API */
+
+void
+set_RT(const char *str, size_t len)
+{
+       if (! do_traditional) {
+               unref(RT_node->var_value);
+               RT_node->var_value = make_str_node(str, len, ALREADY_MALLOCED);
+       }
+}
+
+/* macros for speed in default implementation */
+
 #define set_RT_to_null() \
        (void)(! do_traditional && (unref(RT_node->var_value), \
                           RT_node->var_value = dupnode(Nnull_string)))

http://git.sv.gnu.org/cgit/gawk.git/commit/?id=c3d3c83b0a60454c7b1bc335c022051b58f393e3

commit c3d3c83b0a60454c7b1bc335c022051b58f393e3
Author: Arnold D. Robbins <address@hidden>
Date:   Thu Jul 26 22:16:40 2012 +0300

    Enable gettext in extensions.

diff --git a/extension/ChangeLog b/extension/ChangeLog
index e2e0b63..52dca76 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,8 @@
+2012-07-26         Arnold D. Robbins     <address@hidden>
+
+       * configure.ac: Extremely crude hack to get the value of
+       ENABLE_NLS so that gettext will work in extensions.
+
 2012-07-26         Andrew J. Schorr     <address@hidden>
 
        * readdir.c (dir_get_record): No need to set *errcode to 0.
diff --git a/extension/configure b/extension/configure
index 301e341..94be75b 100755
--- a/extension/configure
+++ b/extension/configure
@@ -13901,3 +13901,6 @@ if test -n "$ac_unrecognized_opts" && test 
"$enable_option_checking" != no; then
 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
 fi
 
+
+# hack
+grep ENABLE_NLS ../config.h >> config.h
diff --git a/extension/configure.ac b/extension/configure.ac
index 160d55d..4583962 100644
--- a/extension/configure.ac
+++ b/extension/configure.ac
@@ -56,3 +56,6 @@ AC_CONFIG_HEADERS([config.h:configh.in])
 
 AC_CONFIG_FILES(Makefile)
 AC_OUTPUT
+
+# hack
+grep ENABLE_NLS ../config.h >> config.h

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog              |   10 +++
 TODO.xgawk             |   90 ++++++++++++-----------------
 awk.h                  |    3 +
 extension/ChangeLog    |   13 ++++
 extension/configh.in   |    6 ++
 extension/configure    |    7 ++-
 extension/configure.ac |    7 ++-
 extension/readdir.c    |  149 +++++++++++++++++++++++++++++++++++++-----------
 extension/testext.c    |    3 +
 gawkapi.c              |   34 +++++++++++-
 gawkapi.h              |    4 +
 io.c                   |   26 ++++++++-
 pc/ChangeLog           |    4 +
 pc/gawkmisc.pc         |   25 ++++++++
 posix/ChangeLog        |    4 +
 posix/gawkmisc.c       |   25 ++++++++
 vms/ChangeLog          |    4 +
 vms/gawkmisc.vms       |   25 ++++++++
 18 files changed, 346 insertions(+), 93 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]