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. 28daef44c3c08f16002c67


From: Arnold Robbins
Subject: [gawk-diffs] [SCM] gawk branch, extgawk, updated. 28daef44c3c08f16002c678319a30b816f6972fd
Date: Thu, 12 Jul 2012 19:45:47 +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  28daef44c3c08f16002c678319a30b816f6972fd (commit)
       via  4319d9141a56cb8ed878d44d0e74bedee51085a6 (commit)
       via  a49be44686e3d0707c43d643bfcad68d50a75b98 (commit)
       via  33b647ef23daa8a310701c767098f11ee48cf4e8 (commit)
      from  dda2495337929a86cc40017d8f1cd72a46876618 (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=28daef44c3c08f16002c678319a30b816f6972fd

commit 28daef44c3c08f16002c678319a30b816f6972fd
Author: Arnold D. Robbins <address@hidden>
Date:   Thu Jul 12 22:45:25 2012 +0300

    Allow creation of constants from extensions.

diff --git a/ChangeLog b/ChangeLog
index 04bd15d..bd444d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2012-07-12         Arnold D. Robbins     <address@hidden>
+
+       Allow creation of constants. Thanks to John Haque for the
+       implementation concept.
+
+       * gawk_api.h (api_sym_constant): Create a constant.
+       * gawk_api.h (api_sym_update_real): Renamed from api_sym_update.
+       Add is_const paramater and do the right thing if true.
+       (api_sym_update, api_sym_constant): Call api_sym_update_real
+       in the correct way.
+       (set_constant): New function.
+
 2012-07-11         Andrew J. Schorr     <address@hidden>
 
        * gawkapi.h: Fix typo in comment.
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 4eab7d7..ce8d6b7 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -4,6 +4,9 @@
        * Makefile.am: Build fnmatch extension.
        * configure.ac: Look for fnmatch.h and fnmatch function.
 
+       * fnmatch.c (init_fnmatch): Use sym_constant for FNM_NOMATCH.
+       * testext.c (dl_load): Use sym_constant for answer_num.
+
 2012-07-11         Arnold D. Robbins     <address@hidden>
 
        * filefuncs.c (array_set, do_stat): Use make_const_string.
diff --git a/extension/fnmatch.c b/extension/fnmatch.c
index 7f050dc..aa8a730 100644
--- a/extension/fnmatch.c
+++ b/extension/fnmatch.c
@@ -137,7 +137,7 @@ init_fnmatch(void)
        awk_array_t new_array;
        int i;
 
-       if (! sym_update("FNM_NOMATCH", make_number(FNM_NOMATCH, & value))) {
+       if (! sym_constant("FNM_NOMATCH", make_number(FNM_NOMATCH, & value))) {
                warning(ext_id, "fnmatch init: could not add FNM_NOMATCH 
variable");
                errors++;
        }
diff --git a/extension/testext.c b/extension/testext.c
index d446fb8..dc3002a 100644
--- a/extension/testext.c
+++ b/extension/testext.c
@@ -623,8 +623,8 @@ BEGIN {
 */
 
        /* install some variables */
-       if (! sym_update("answer_num", make_number(42, & value)))
-               printf("testext: sym_update(\"answer_num\") failed!\n");
+       if (! sym_constant("answer_num", make_number(42, & value)))
+               printf("testext: sym_constant(\"answer_num\") failed!\n");
 
        if (! sym_update("message_string",
                        make_const_string(message, strlen(message), & value)))
diff --git a/gawkapi.c b/gawkapi.c
index b6d83ac..e8d50e8 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -26,6 +26,7 @@
 #include "awk.h"
 
 static awk_bool_t node_to_awk_value(NODE *node, awk_value_t *result, 
awk_valtype_t wanted);
+static void set_constant();
 
 /*
  * Get the count'th paramater, zero-based.
@@ -460,10 +461,13 @@ api_sym_lookup_scalar(awk_ext_id_t id,
        return node_to_awk_value(node, result, wanted);
 }
 
-/* api_sym_update --- update a symbol's value, see gawkapi.h for semantics */
+/* api_sym_update_real --- update a symbol's value, see gawkapi.h for 
semantics */
 
 static awk_bool_t
-api_sym_update(awk_ext_id_t id, const char *name, awk_value_t *value)
+sym_update_real(awk_ext_id_t id,
+               const char *name,
+               awk_value_t *value,
+               bool is_const)
 {
        NODE *node;
        NODE *array_node;
@@ -503,6 +507,8 @@ api_sym_update(awk_ext_id_t id, const char *name, 
awk_value_t *value)
                                        Node_var);
                        unref(node->var_value);
                        node->var_value = awk_value_to_node(value);
+                       if (is_const)
+                               node->var_assign = set_constant;
                }
                return true;
        }
@@ -518,6 +524,9 @@ api_sym_update(awk_ext_id_t id, const char *name, 
awk_value_t *value)
                if (node->type == Node_var || node->type == Node_var_new) {
                        unref(node->var_value);
                        node->var_value = awk_value_to_node(value);
+                       /* let the extension change its own variable */
+                       if (is_const)
+                               node->var_assign = set_constant;
                } else {
                        return false;
                }
@@ -530,6 +539,26 @@ api_sym_update(awk_ext_id_t id, const char *name, 
awk_value_t *value)
        return true;
 }
 
+/* api_sym_update --- update a symbol, non-constant */
+
+static awk_bool_t
+api_sym_update(awk_ext_id_t id,
+               const char *name,
+               awk_value_t *value)
+{
+       return sym_update_real(id, name, value, false);
+}
+
+/* api_sym_update --- update a symbol, constant */
+
+static awk_bool_t
+api_sym_constant(awk_ext_id_t id,
+               const char *name,
+               awk_value_t *value)
+{
+       return sym_update_real(id, name, value, true);
+}
+
 /* api_sym_update_scalar --- update a scalar cookie */
 
 static awk_bool_t
@@ -864,6 +893,7 @@ gawk_api_t api_impl = {
        api_sym_lookup,
        api_sym_lookup_scalar,
        api_sym_update,
+       api_sym_constant,
        api_sym_update_scalar,
 
        api_get_array_element,
@@ -897,3 +927,11 @@ update_ext_api()
 {
        api_impl.do_flags[0] = (do_lint ? 1 : 0);
 }
+
+/* set_constant --- prevent awk code from changing a constant */
+
+static void
+set_constant()
+{
+       fatal(_("cannot assign to defined constant"));
+}
diff --git a/gawkapi.h b/gawkapi.h
index 50ca327..a84fbf5 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -334,7 +334,15 @@ typedef struct gawk_api {
         * In fact, using this to update an array is not allowed, either.
         * Such an attempt returns false.
         */
-       awk_bool_t (*api_sym_update)(awk_ext_id_t id, const char *name, 
awk_value_t *value);
+       awk_bool_t (*api_sym_update)(awk_ext_id_t id,
+                               const char *name,
+                               awk_value_t *value);
+       /*
+        * Install a constant value.
+        */
+       awk_bool_t (*api_sym_constant)(awk_ext_id_t id,
+                               const char *name,
+                               awk_value_t *value);
 
        /*
         * Work with a scalar cookie.
@@ -445,6 +453,8 @@ typedef struct gawk_api {
        (api->api_sym_lookup_scalar(ext_id, scalar_cookie, wanted, result))
 #define sym_update(name, value) \
        (api->api_sym_update(ext_id, name, value))
+#define sym_constant(name, value) \
+       (api->api_sym_constant(ext_id, name, value))
 #define sym_update_scalar(scalar_cookie, value) \
        (api->api_sym_update_scalar)(ext_id, scalar_cookie, value)
 
diff --git a/test/ChangeLog b/test/ChangeLog
index 019d2f3..50dcd27 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -3,6 +3,9 @@
        * Makefile.am (fnmatch): New test.
        * fnmatch.awk, fnmatch.ok: New files.
 
+       * Makefile.am (assignconst): New test.
+       * assignconst.awk, assignconst.ok: New files.
+
 2012-06-28         Andrew J. Schorr     <address@hidden>
 
        * time.awk: Avoid possibly throwing a spurious error by protecting
diff --git a/test/Makefile.am b/test/Makefile.am
index a244c6a..78fd311 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -102,6 +102,8 @@ EXTRA_DIST = \
        asort.ok \
        asorti.awk \
        asorti.ok \
+       assignconst.awk \
+       assignconst.ok \
        awkpath.ok \
        back89.awk \
        back89.in \
@@ -891,8 +893,8 @@ LOCALE_CHARSET_TESTS = \
        mbprintf1 mbprintf2 mbprintf3 rebt8b2 rtlenmb sort1 sprintfc
 
 SHLIB_TESTS = \
-       fnmatch filefuncs fork fork2 ordchr ordchr2 readfile rwarray \
-       testext time
+       assignconst fnmatch filefuncs fork fork2 ordchr ordchr2 \
+       readfile rwarray testext time
 
 # List of the tests which should be run with --lint option:
 NEED_LINT = \
@@ -1594,6 +1596,13 @@ testext::
        @$(AWK) -f testext.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
        @-$(CMP) $(srcdir)/address@hidden _$@ && rm -f _$@ testext.awk
 
+assignconst:
+       @echo $@
+       @for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; \
+       do $(AWK) -f $(srcdir)/address@hidden $$i ; \
+       done 2>&1 | grep -v at_exit > _$@
+       @-$(CMP) $(srcdir)/address@hidden _$@ && rm -f _$@
+
 # Targets generated for other tests:
 include Maketests
 
diff --git a/test/Makefile.in b/test/Makefile.in
index 61e32b1..d12139c 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -314,6 +314,8 @@ EXTRA_DIST = \
        asort.ok \
        asorti.awk \
        asorti.ok \
+       assignconst.awk \
+       assignconst.ok \
        awkpath.ok \
        back89.awk \
        back89.in \
@@ -1099,8 +1101,8 @@ LOCALE_CHARSET_TESTS = \
        mbprintf1 mbprintf2 mbprintf3 rebt8b2 rtlenmb sort1 sprintfc
 
 SHLIB_TESTS = \
-       fnmatch filefuncs fork fork2 ordchr ordchr2 readfile rwarray \
-       testext time
+       assignconst fnmatch filefuncs fork fork2 ordchr ordchr2 \
+       readfile rwarray testext time
 
 
 # List of the tests which should be run with --lint option:
@@ -1975,6 +1977,13 @@ testext::
        @$(AWK) '/^(@load|BEGIN)/,/^}/' $(top_srcdir)/extension/testext.c > 
testext.awk
        @$(AWK) -f testext.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
        @-$(CMP) $(srcdir)/address@hidden _$@ && rm -f _$@ testext.awk
+
+assignconst:
+       @echo $@
+       @for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; \
+       do $(AWK) -f $(srcdir)/address@hidden $$i ; \
+       done 2>&1 | grep -v at_exit > _$@
+       @-$(CMP) $(srcdir)/address@hidden _$@ && rm -f _$@
 Gt-dummy:
 # file Maketests, generated from Makefile.am by the Gentests program
 addcomma:
diff --git a/test/assignconst.awk b/test/assignconst.awk
new file mode 100644
index 0000000..907987c
--- /dev/null
+++ b/test/assignconst.awk
@@ -0,0 +1,58 @@
address@hidden "testext"
+
+BEGIN {
+       print ""
+       print "test:", ARGV[1]
+       switch (ARGV[1] + 0) {
+       case 1:
+               answer_num = 43
+               break
+       case 2:
+               ++answer_num
+               break
+       case 3:
+               --answer_num
+               break
+       case 4:
+               answer_num++
+               break
+       case 5:
+               answer_num--
+               break
+       case 6:
+               answer_num += 1
+               break
+       case 7:
+               answer_num -= 1
+               break
+       case 8:
+               answer_num *= 1
+               break
+       case 9:
+               answer_num /= 1
+               break
+       case 10:
+               answer_num ^= 1
+               break
+       case 11:
+               answer_num = answer_num "foo"
+               break
+       case 12:
+               sub(/2/, "3", answer_num)
+               break
+       case 13:
+               a[1] = 1
+               for (answer_num in a)
+                       print answer_num, a[answer_num]
+               break
+       case 14:
+               test_func(answer_num)
+               break
+       }
+}
+
+function test_func(val)
+{
+       val++
+       print "in test_func, val now =", val
+}
diff --git a/test/assignconst.ok b/test/assignconst.ok
new file mode 100644
index 0000000..e2bc749
--- /dev/null
+++ b/test/assignconst.ok
@@ -0,0 +1,42 @@
+
+test: 1
+gawk: ./assignconst.awk:8: fatal: cannot assign to defined constant
+
+test: 2
+gawk: ./assignconst.awk:11: fatal: cannot assign to defined constant
+
+test: 3
+gawk: ./assignconst.awk:14: fatal: cannot assign to defined constant
+
+test: 4
+gawk: ./assignconst.awk:17: fatal: cannot assign to defined constant
+
+test: 5
+gawk: ./assignconst.awk:20: fatal: cannot assign to defined constant
+
+test: 6
+gawk: ./assignconst.awk:23: fatal: cannot assign to defined constant
+
+test: 7
+gawk: ./assignconst.awk:26: fatal: cannot assign to defined constant
+
+test: 8
+gawk: ./assignconst.awk:29: fatal: cannot assign to defined constant
+
+test: 9
+gawk: ./assignconst.awk:32: fatal: cannot assign to defined constant
+
+test: 10
+gawk: ./assignconst.awk:35: fatal: cannot assign to defined constant
+
+test: 11
+gawk: ./assignconst.awk:38: fatal: cannot assign to defined constant
+
+test: 12
+gawk: ./assignconst.awk:41: fatal: cannot assign to defined constant
+
+test: 13
+gawk: ./assignconst.awk:45: fatal: cannot assign to defined constant
+
+test: 14
+in test_func, val now = 43

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

commit 4319d9141a56cb8ed878d44d0e74bedee51085a6
Author: Arnold D. Robbins <address@hidden>
Date:   Thu Jul 12 22:28:49 2012 +0300

    Minor doc updates.

diff --git a/NEWS b/NEWS
index 79fcda6..d8c6549 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,9 @@ Changes from 4.0.1 to 4.1
 5. A number of facilities from xgawk have been merged in!
 
 6. The dynamic extension interface has been completely redone! See the doc.
+
+7. The and(), or() and xor() functions now take any number of arguments,
+   with a minimum of two.
  
 Changes from 4.0.1 to 4.0.2
 ---------------------------
diff --git a/doc/gawk.1 b/doc/gawk.1
index 4a19219..c0a0a41 100644
--- a/doc/gawk.1
+++ b/doc/gawk.1
@@ -3886,7 +3886,7 @@ We thank him.
 .SH COPYING PERMISSIONS
 Copyright \(co 1989, 1991, 1992, 1993, 1994, 1995, 1996,
 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2007, 2009,
-2010, 2011
+2010, 2011, 2012
 Free Software Foundation, Inc.
 .PP
 Permission is granted to make and distribute verbatim copies of

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

commit a49be44686e3d0707c43d643bfcad68d50a75b98
Merge: 33b647e dda2495
Author: Arnold D. Robbins <address@hidden>
Date:   Thu Jul 12 21:09:14 2012 +0300

    Merge branch 'extgawk' of ssh://git.sv.gnu.org/srv/git/gawk into extgawk


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

commit 33b647ef23daa8a310701c767098f11ee48cf4e8
Author: Arnold D. Robbins <address@hidden>
Date:   Thu Jul 12 21:08:52 2012 +0300

    Add fnmatch extension.

diff --git a/extension/ChangeLog b/extension/ChangeLog
index 2ea13e3..4eab7d7 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,9 @@
+2012-07-12         Arnold D. Robbins     <address@hidden>
+
+       * fnmatch.c: New file.
+       * Makefile.am: Build fnmatch extension.
+       * configure.ac: Look for fnmatch.h and fnmatch function.
+
 2012-07-11         Arnold D. Robbins     <address@hidden>
 
        * filefuncs.c (array_set, do_stat): Use make_const_string.
diff --git a/extension/Makefile.am b/extension/Makefile.am
index 5c6532b..abe778e 100644
--- a/extension/Makefile.am
+++ b/extension/Makefile.am
@@ -33,6 +33,7 @@ ACLOCAL_AMFLAGS = -I m4
 
 pkgextension_LTLIBRARIES =     \
        filefuncs.la    \
+       fnmatch.la      \
        fork.la         \
        ordchr.la       \
        readfile.la     \
@@ -44,6 +45,8 @@ MY_MODULE_FLAGS = -module -avoid-version -no-undefined
 
 filefuncs_la_SOURCES  = filefuncs.c
 filefuncs_la_LDFLAGS  = $(MY_MODULE_FLAGS)
+fnmatch_la_SOURCES  = fnmatch.c
+fnmatch_la_LDFLAGS  = $(MY_MODULE_FLAGS)
 fork_la_SOURCES       = fork.c
 fork_la_LDFLAGS       = $(MY_MODULE_FLAGS)
 ordchr_la_SOURCES     = ordchr.c
diff --git a/extension/Makefile.in b/extension/Makefile.in
index 1747bcd..71920fe 100644
--- a/extension/Makefile.in
+++ b/extension/Makefile.in
@@ -136,6 +136,12 @@ filefuncs_la_OBJECTS = $(am_filefuncs_la_OBJECTS)
 filefuncs_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
        $(filefuncs_la_LDFLAGS) $(LDFLAGS) -o $@
+fnmatch_la_LIBADD =
+am_fnmatch_la_OBJECTS = fnmatch.lo
+fnmatch_la_OBJECTS = $(am_fnmatch_la_OBJECTS)
+fnmatch_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(fnmatch_la_LDFLAGS) $(LDFLAGS) -o $@
 fork_la_LIBADD =
 am_fork_la_OBJECTS = fork.lo
 fork_la_OBJECTS = $(am_fork_la_OBJECTS)
@@ -185,11 +191,11 @@ CCLD = $(CC)
 LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
        $(LDFLAGS) -o $@
-SOURCES = $(filefuncs_la_SOURCES) $(fork_la_SOURCES) \
-       $(ordchr_la_SOURCES) $(readfile_la_SOURCES) \
+SOURCES = $(filefuncs_la_SOURCES) $(fnmatch_la_SOURCES) \
+       $(fork_la_SOURCES) $(ordchr_la_SOURCES) $(readfile_la_SOURCES) \
        $(rwarray_la_SOURCES) $(testext_la_SOURCES) $(time_la_SOURCES)
-DIST_SOURCES = $(filefuncs_la_SOURCES) $(fork_la_SOURCES) \
-       $(ordchr_la_SOURCES) $(readfile_la_SOURCES) \
+DIST_SOURCES = $(filefuncs_la_SOURCES) $(fnmatch_la_SOURCES) \
+       $(fork_la_SOURCES) $(ordchr_la_SOURCES) $(readfile_la_SOURCES) \
        $(rwarray_la_SOURCES) $(testext_la_SOURCES) $(time_la_SOURCES)
 am__can_run_installinfo = \
   case $$AM_UPDATE_INFO_DIR in \
@@ -340,6 +346,7 @@ ACLOCAL_AMFLAGS = -I m4
 # Note: rwarray does not currently compile.
 pkgextension_LTLIBRARIES = \
        filefuncs.la    \
+       fnmatch.la      \
        fork.la         \
        ordchr.la       \
        readfile.la     \
@@ -350,6 +357,8 @@ pkgextension_LTLIBRARIES = \
 MY_MODULE_FLAGS = -module -avoid-version -no-undefined
 filefuncs_la_SOURCES = filefuncs.c
 filefuncs_la_LDFLAGS = $(MY_MODULE_FLAGS)
+fnmatch_la_SOURCES = fnmatch.c
+fnmatch_la_LDFLAGS = $(MY_MODULE_FLAGS)
 fork_la_SOURCES = fork.c
 fork_la_LDFLAGS = $(MY_MODULE_FLAGS)
 ordchr_la_SOURCES = ordchr.c
@@ -456,6 +465,8 @@ clean-pkgextensionLTLIBRARIES:
        }
 filefuncs.la: $(filefuncs_la_OBJECTS) $(filefuncs_la_DEPENDENCIES) 
$(EXTRA_filefuncs_la_DEPENDENCIES) 
        $(filefuncs_la_LINK) -rpath $(pkgextensiondir) $(filefuncs_la_OBJECTS) 
$(filefuncs_la_LIBADD) $(LIBS)
+fnmatch.la: $(fnmatch_la_OBJECTS) $(fnmatch_la_DEPENDENCIES) 
$(EXTRA_fnmatch_la_DEPENDENCIES) 
+       $(fnmatch_la_LINK) -rpath $(pkgextensiondir) $(fnmatch_la_OBJECTS) 
$(fnmatch_la_LIBADD) $(LIBS)
 fork.la: $(fork_la_OBJECTS) $(fork_la_DEPENDENCIES) 
$(EXTRA_fork_la_DEPENDENCIES) 
        $(fork_la_LINK) -rpath $(pkgextensiondir) $(fork_la_OBJECTS) 
$(fork_la_LIBADD) $(LIBS)
 ordchr.la: $(ordchr_la_OBJECTS) $(ordchr_la_DEPENDENCIES) 
$(EXTRA_ordchr_la_DEPENDENCIES) 
@@ -476,6 +487,7 @@ distclean-compile:
        -rm -f *.tab.c
 
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
address@hidden@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
diff --git a/extension/configh.in b/extension/configh.in
index 519f8ea..179b586 100644
--- a/extension/configh.in
+++ b/extension/configh.in
@@ -3,6 +3,12 @@
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
+/* Define to 1 if you have the `fnmatch' function. */
+#undef HAVE_FNMATCH
+
+/* Define to 1 if you have the <fnmatch.h> header file. */
+#undef HAVE_FNMATCH_H
+
 /* Define to 1 if you have the `GetSystemTimeAsFileTime' function. */
 #undef HAVE_GETSYSTEMTIMEASFILETIME
 
diff --git a/extension/configure b/extension/configure
index 30b162a..301e341 100755
--- a/extension/configure
+++ b/extension/configure
@@ -11462,7 +11462,7 @@ then
        CFLAGS="$CFLAGS -Wall -Wextra"
 fi
 
-for ac_header in time.h sys/time.h sys/select.h
+for ac_header in 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 nanosleep select gettimeofday GetSystemTimeAsFileTime
+for ac_func in 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 838350c..160d55d 100644
--- a/extension/configure.ac
+++ b/extension/configure.ac
@@ -45,9 +45,9 @@ then
        CFLAGS="$CFLAGS -Wall -Wextra"
 fi
 
-AC_CHECK_HEADERS(time.h sys/time.h sys/select.h)
+AC_CHECK_HEADERS(fnmatch.h time.h sys/time.h sys/select.h)
 
-AC_CHECK_FUNCS(nanosleep select gettimeofday GetSystemTimeAsFileTime)
+AC_CHECK_FUNCS(fnmatch gettimeofday nanosleep select GetSystemTimeAsFileTime)
 
 dnl checks for compiler characteristics
 AC_C_INLINE
diff --git a/extension/fnmatch.c b/extension/fnmatch.c
new file mode 100644
index 0000000..7f050dc
--- /dev/null
+++ b/extension/fnmatch.c
@@ -0,0 +1,175 @@
+/*
+ * fnmatch.c - Provide an interface to fnmatch(3) routine
+ *
+ * Arnold Robbins
+ * address@hidden
+ * Written 7/2012
+ */
+
+/*
+ * Copyright (C) 2012 the Free Software Foundation, Inc.
+ * 
+ * This file is part of GAWK, the GNU implementation of the
+ * AWK Programming Language.
+ * 
+ * GAWK is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * GAWK is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
+ */
+
+#include <stdio.h>
+#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "config.h"
+#include "gawkapi.h"
+
+#ifdef HAVE_FNMATCH_H
+#define _GNU_SOURCE    1       /* use GNU extensions if they're there */
+#include <fnmatch.h>
+#endif
+
+/* Provide GNU extensions as no-ops if not defined */
+#ifndef FNM_CASEFOLD
+#define FNM_CASEFOLD   0
+#endif
+#ifndef FNM_LEADING_DIR
+#define FNM_LEADING_DIR        0
+#endif
+#ifndef FNM_FILE_NAME
+#define FNM_FILE_NAME  0
+#endif
+
+static const gawk_api_t *api;  /* for convenience macros to work */
+static awk_ext_id_t *ext_id;
+
+static awk_bool_t init_fnmatch(void);
+static awk_bool_t (*init_func)(void) = init_fnmatch;
+
+int plugin_is_GPL_compatible;
+
+
+/* do_fnmatch --- implement the fnmatch interface */
+
+static awk_value_t *
+do_fnmatch(int nargs, awk_value_t *result)
+{
+       static int flags_mask =
+               FNM_CASEFOLD    | FNM_FILE_NAME |
+               FNM_LEADING_DIR | FNM_NOESCAPE |
+               FNM_PATHNAME    | FNM_PERIOD ;
+       awk_value_t pattern, string, flags;
+       int int_flags, retval;
+
+       make_number(-1.0, result);      /* default return */
+#ifdef HAVE_FNMATCH
+       if (nargs < 3) {
+               warning(ext_id, "fnmatch: called with less than three 
arguments");
+               goto out;
+       } else if (do_lint && nargs > 3)
+               lintwarn(ext_id, "fnmatch: called with more than three 
arguments");
+
+       if (! get_argument(0, AWK_STRING, & pattern)) {
+               warning(ext_id, "fnmatch: could not get first argument");
+               goto out;
+       }
+
+       if (! get_argument(1, AWK_STRING, & string)) {
+               warning(ext_id, "fnmatch: could not get second argument");
+               goto out;
+       }
+
+       if (! get_argument(2, AWK_NUMBER, & flags)) {
+               warning(ext_id, "fnmatch: could not get third argument");
+               goto out;
+       }
+
+       int_flags = flags.num_value;
+       int_flags &= flags_mask;
+
+       retval = fnmatch(pattern.str_value.str,
+                       string.str_value.str, int_flags);
+       make_number((double) retval, result);
+
+out:
+#else
+       fatal(ext_id, "fnmatch is not implemented on this system\n");
+#endif
+       return result;
+}
+
+static struct fnmflags {
+       const char *name;
+       int value;
+} flagtable[] = {
+       { "CASEFOLD", FNM_CASEFOLD },
+       { "FILE_NAME", FNM_FILE_NAME },
+       { "LEADING_DIR", FNM_LEADING_DIR },
+       { "NOESCAPE", FNM_NOESCAPE },
+       { "PATHNAME", FNM_PATHNAME },
+       { "PERIOD", FNM_PERIOD },
+       { NULL, 0 }
+};
+
+/* init_fnmatch --- load array with flags */
+
+static awk_bool_t
+init_fnmatch(void)
+{
+       int errors = 0;
+#ifdef HAVE_FNMATCH
+       awk_value_t index, value, the_array;
+       awk_array_t new_array;
+       int i;
+
+       if (! sym_update("FNM_NOMATCH", make_number(FNM_NOMATCH, & value))) {
+               warning(ext_id, "fnmatch init: could not add FNM_NOMATCH 
variable");
+               errors++;
+       }
+
+       new_array = create_array();
+       for (i = 0; flagtable[i].name != NULL; i++) {
+               (void) make_const_string(flagtable[i].name,
+                               strlen(flagtable[i].name), & index);
+               (void) make_number(flagtable[i].value, & value);
+               if (! set_array_element(new_array, & index, & value)) {
+                       warning(ext_id, "fnmatch init: could not set array 
element %s",
+                                       flagtable[i].name);
+                       errors++;
+               }
+       }
+
+       the_array.val_type = AWK_ARRAY;
+       the_array.array_cookie = new_array;
+
+       if (! sym_update("FNM", & the_array)) {
+               warning(ext_id, "fnmatch init: could not install FNM array");
+               errors++;
+       }
+
+#endif
+       return errors == 0;
+}
+
+static awk_ext_func_t func_table[] = {
+       { "fnmatch", do_fnmatch, 3 },
+};
+
+/* define the dl_load function using the boilerplate macro */
+
+dl_load_func(func_table, fnmatch, "")
diff --git a/test/ChangeLog b/test/ChangeLog
index 057434f..019d2f3 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2012-07-12         Arnold D. Robbins     <address@hidden>
+
+       * Makefile.am (fnmatch): New test.
+       * fnmatch.awk, fnmatch.ok: New files.
+
 2012-06-28         Andrew J. Schorr     <address@hidden>
 
        * time.awk: Avoid possibly throwing a spurious error by protecting
diff --git a/test/Makefile.am b/test/Makefile.am
index 58fddfc..a244c6a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -230,6 +230,8 @@ EXTRA_DIST = \
        fnasgnm.awk \
        fnasgnm.in \
        fnasgnm.ok \
+       fnmatch.awk \
+       fnmatch.ok \
        fnmisc.awk \
        fnmisc.ok \
        fnparydl.awk \
@@ -889,7 +891,7 @@ LOCALE_CHARSET_TESTS = \
        mbprintf1 mbprintf2 mbprintf3 rebt8b2 rtlenmb sort1 sprintfc
 
 SHLIB_TESTS = \
-       filefuncs fork fork2 ordchr ordchr2 readfile rwarray \
+       fnmatch filefuncs fork fork2 ordchr ordchr2 readfile rwarray \
        testext time
 
 # List of the tests which should be run with --lint option:
diff --git a/test/Makefile.in b/test/Makefile.in
index 3e170f8..61e32b1 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -442,6 +442,8 @@ EXTRA_DIST = \
        fnasgnm.awk \
        fnasgnm.in \
        fnasgnm.ok \
+       fnmatch.awk \
+       fnmatch.ok \
        fnmisc.awk \
        fnmisc.ok \
        fnparydl.awk \
@@ -1097,7 +1099,7 @@ LOCALE_CHARSET_TESTS = \
        mbprintf1 mbprintf2 mbprintf3 rebt8b2 rtlenmb sort1 sprintfc
 
 SHLIB_TESTS = \
-       filefuncs fork fork2 ordchr ordchr2 readfile rwarray \
+       fnmatch filefuncs fork fork2 ordchr ordchr2 readfile rwarray \
        testext time
 
 
@@ -3174,6 +3176,11 @@ sprintfc:
        @AWKPATH=$(srcdir) $(AWK) -f address@hidden  < $(srcdir)/address@hidden 
>_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
        @-$(CMP) $(srcdir)/address@hidden _$@ && rm -f _$@
 
+fnmatch:
+       @echo $@
+       @AWKPATH=$(srcdir) $(AWK) -f address@hidden  >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
+       @-$(CMP) $(srcdir)/address@hidden _$@ && rm -f _$@
+
 filefuncs:
        @echo $@
        @AWKPATH=$(srcdir) $(AWK) -f address@hidden  >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index b10e175..0a4e582 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1199,6 +1199,11 @@ sprintfc:
        @AWKPATH=$(srcdir) $(AWK) -f address@hidden  < $(srcdir)/address@hidden 
>_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
        @-$(CMP) $(srcdir)/address@hidden _$@ && rm -f _$@
 
+fnmatch:
+       @echo $@
+       @AWKPATH=$(srcdir) $(AWK) -f address@hidden  >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
+       @-$(CMP) $(srcdir)/address@hidden _$@ && rm -f _$@
+
 filefuncs:
        @echo $@
        @AWKPATH=$(srcdir) $(AWK) -f address@hidden  >_$@ 2>&1 || echo EXIT 
CODE: $$? >>_$@
diff --git a/test/fnmatch.awk b/test/fnmatch.awk
new file mode 100644
index 0000000..e8ef937
--- /dev/null
+++ b/test/fnmatch.awk
@@ -0,0 +1,10 @@
address@hidden "fnmatch"
+
+BEGIN {
+       print "FNM_NOMATCH =", FNM_NOMATCH 
+       for (i in FNM)
+               printf("FNM[\"%s\"] = %d\n", i, FNM[i])
+
+       printf("fnmatch(\"*.a\", \"foo.a\", 0)  = %d\n", fnmatch("*.a", 
"foo.a", 0) )
+       printf("fnmatch(\"*.a\", \"foo.c\", 0) = %d\n", fnmatch("*.a", "foo.c", 
0))
+}
diff --git a/test/fnmatch.ok b/test/fnmatch.ok
new file mode 100644
index 0000000..cc17c6b
--- /dev/null
+++ b/test/fnmatch.ok
@@ -0,0 +1,9 @@
+FNM_NOMATCH = 1
+FNM["LEADING_DIR"] = 8
+FNM["CASEFOLD"] = 16
+FNM["NOESCAPE"] = 2
+FNM["PERIOD"] = 4
+FNM["PATHNAME"] = 1
+FNM["FILE_NAME"] = 1
+fnmatch("*.a", "foo.a", 0)  = 0
+fnmatch("*.a", "foo.c", 0) = 1

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

Summary of changes:
 ChangeLog              |   12 +++
 NEWS                   |    3 +
 doc/gawk.1             |    2 +-
 extension/ChangeLog    |    9 +++
 extension/Makefile.am  |    3 +
 extension/Makefile.in  |   20 +++++-
 extension/configh.in   |    6 ++
 extension/configure    |    4 +-
 extension/configure.ac |    4 +-
 extension/fnmatch.c    |  175 ++++++++++++++++++++++++++++++++++++++++++++++++
 extension/testext.c    |    4 +-
 gawkapi.c              |   42 +++++++++++-
 gawkapi.h              |   12 +++-
 test/ChangeLog         |    8 ++
 test/Makefile.am       |   15 ++++-
 test/Makefile.in       |   20 +++++-
 test/Maketests         |    5 ++
 test/assignconst.awk   |   58 ++++++++++++++++
 test/assignconst.ok    |   42 ++++++++++++
 test/fnmatch.awk       |   10 +++
 test/fnmatch.ok        |    9 +++
 21 files changed, 445 insertions(+), 18 deletions(-)
 create mode 100644 extension/fnmatch.c
 create mode 100644 test/assignconst.awk
 create mode 100644 test/assignconst.ok
 create mode 100644 test/fnmatch.awk
 create mode 100644 test/fnmatch.ok


hooks/post-receive
-- 
gawk



reply via email to

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