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. 0f2e51f9b18a1c4e203e0b


From: Arnold Robbins
Subject: [gawk-diffs] [SCM] gawk branch, extgawk, updated. 0f2e51f9b18a1c4e203e0bd0ac3c68db9faa9b6d
Date: Wed, 16 May 2012 19:56:16 +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  0f2e51f9b18a1c4e203e0bd0ac3c68db9faa9b6d (commit)
      from  85458962f4ca247b4c263a5588150960ee6f3e42 (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=0f2e51f9b18a1c4e203e0bd0ac3c68db9faa9b6d

commit 0f2e51f9b18a1c4e203e0bd0ac3c68db9faa9b6d
Author: Arnold D. Robbins <address@hidden>
Date:   Wed May 16 22:55:58 2012 +0300

    More progress on extension API.

diff --git a/gawkapi.c b/gawkapi.c
index d4d6503..2eb071c 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -86,10 +86,11 @@ api_lintwarn(awk_ext_id_t id, const char *format, ...)
 }
 
 /* Register an open hook; for opening files read-only */
-static awk_bool_t
+
+static void
 api_register_open_hook(awk_ext_id_t id, void* (*open_func)(IOBUF *))
 {
-       return true;    /* for now */
+       register_open_hook(open_func);
 }
 
 /* Functions to update ERRNO */
@@ -174,6 +175,37 @@ api_awk_atexit(awk_ext_id_t id,
  *     - Use sym_update() to change a value, including from UNDEFINED
  *       to scalar or array. 
  */
+static const awk_value_t *const
+node_to_awk_value(NODE *node)
+{
+       static awk_value_t val;
+
+       memset(& val, 0, sizeof(val));
+       switch (node->type) {
+       case Node_var_new:
+               val.val_type = AWK_UNDEFINED;
+               break;
+       case Node_var:
+               if ((node->var_value->flags & NUMBER) != 0) {
+                       val.val_type = AWK_NUMBER;
+                       val.num_value = get_number_d(node->var_value);
+               } else {
+                       val.val_type = AWK_STRING;
+                       val.str_value.str = node->var_value->stptr;
+                       val.str_value.len = node->var_value->stlen;
+               }
+               break;
+       case Node_var_array:
+               val.val_type = AWK_ARRAY;
+               val.array_cookie = node;
+               break;
+       default:
+               return NULL;
+       }
+
+       return & val;
+}
+
 /*
  * Lookup a variable, return its value. No messing with the value
  * returned. Return value is NULL if the variable doesn't exist.
@@ -181,7 +213,12 @@ api_awk_atexit(awk_ext_id_t id,
 static const awk_value_t *const
 api_sym_lookup(awk_ext_id_t id, const char *name)
 {
-       return NULL;    /* for now */
+       NODE *node;
+
+       if (name == NULL || (node = lookup(name)) == NULL)
+               return NULL;
+
+       return node_to_awk_value(node);
 }
 
 /*
@@ -236,7 +273,13 @@ static awk_bool_t
 api_get_element_count(awk_ext_id_t id,
                awk_array_t a_cookie, size_t *count)
 {
-       return true;    /* for now */
+       NODE *node = (NODE *) a_cookie;
+
+       if (node == NULL || node->type != Node_var_array)
+               return false;
+
+       *count = node->array_size;
+       return true;
 }
 
 /* Create a new array cookie to which elements may be added */
@@ -250,7 +293,13 @@ api_create_array(awk_ext_id_t id)
 static awk_bool_t
 api_clear_array(awk_ext_id_t id, awk_array_t a_cookie)
 {
-       return true;    /* for now */
+       NODE *node = (NODE *) a_cookie;
+
+       if (node == NULL || node->type != Node_var_array)
+               return false;
+
+       assoc_clear(node);
+       return true;
 }
 
 /* Flatten out an array so that it can be looped over easily. */
diff --git a/gawkapi.h b/gawkapi.h
index c3ddc38..335e962 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -201,7 +201,7 @@ typedef struct gawk_api {
        void (*api_lintwarn)(awk_ext_id_t id, const char *format, ...);
 
        /* Register an open hook; for opening files read-only */
-       awk_bool_t (*register_open_hook)(awk_ext_id_t id, void* 
(*open_func)(IOBUF *));
+       void (*register_open_hook)(awk_ext_id_t id, void* (*open_func)(IOBUF 
*));
 
        /* Functions to update ERRNO */
        void (*update_ERRNO_int)(awk_ext_id_t id, int errno_val);

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

Summary of changes:
 gawkapi.c |   59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 gawkapi.h |    2 +-
 2 files changed, 55 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

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