diff options
Diffstat (limited to 'extension')
-rw-r--r-- | extension/ChangeLog | 10 | ||||
-rw-r--r-- | extension/Makefile.am | 7 | ||||
-rw-r--r-- | extension/Makefile.in | 22 | ||||
-rw-r--r-- | extension/testext.c | 124 | ||||
-rw-r--r-- | extension/time.c | 2 |
5 files changed, 137 insertions, 28 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog index 6c4ea84a..4d504fb1 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,5 +1,7 @@ 2012-06-12 Arnold D. Robbins <arnold@skeeve.com> + Revise API: + * filefuncs.c (do_chdir): Replace get_curfunc_param with get_argument. (format_mode): Use unsigned masks. (do_stat): Replace get_curfunc_param with get_argument. @@ -10,6 +12,14 @@ * time.c (do_sleep): Replace get_curfunc_param with get_argument. Replace set_ERRNO with update_ERRNO_str for no way to sleep case. + Work on testext.c: + + * Makefile.am: Add stuff to make testext. Remove doit and steps + from EXTRA_DIST. + * testext.c: Fill in many of the test routines. Still more to do. + Fix up test scripts for each routine. + * time.c (do_sleep): Fix use of get_argument to be boolean. + 2012-06-10 Andrew J. Schorr <aschorr@telemetry-investments.com> * Makefile.am: Add time extension. diff --git a/extension/Makefile.am b/extension/Makefile.am index f2b30ede..bdb1bd19 100644 --- a/extension/Makefile.am +++ b/extension/Makefile.am @@ -36,6 +36,7 @@ pkgextension_LTLIBRARIES = \ fork.la \ ordchr.la \ readfile.la \ + testext.la \ time.la MY_MODULE_FLAGS = -module -avoid-version -no-undefined @@ -50,12 +51,12 @@ readfile_la_SOURCES = readfile.c readfile_la_LDFLAGS = $(MY_MODULE_FLAGS) time_la_SOURCES = time.c time_la_LDFLAGS = $(MY_MODULE_FLAGS) +testext_la_SOURCES = testext.c +testext_la_LDFLAGS = $(MY_MODULE_FLAGS) #rwarray_la_SOURCES = rwarray.c #rwarray_la_LDFLAGS = $(MY_MODULE_FLAGS) EXTRA_DIST = \ ChangeLog \ ChangeLog.0 \ - *.awk \ - doit \ - steps + *.awk diff --git a/extension/Makefile.in b/extension/Makefile.in index 59528912..202989a9 100644 --- a/extension/Makefile.in +++ b/extension/Makefile.in @@ -154,6 +154,12 @@ readfile_la_OBJECTS = $(am_readfile_la_OBJECTS) readfile_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(readfile_la_LDFLAGS) $(LDFLAGS) -o $@ +testext_la_LIBADD = +am_testext_la_OBJECTS = testext.lo +testext_la_OBJECTS = $(am_testext_la_OBJECTS) +testext_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(testext_la_LDFLAGS) $(LDFLAGS) -o $@ time_la_LIBADD = am_time_la_OBJECTS = time.lo time_la_OBJECTS = $(am_time_la_OBJECTS) @@ -174,9 +180,11 @@ 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) $(time_la_SOURCES) + $(ordchr_la_SOURCES) $(readfile_la_SOURCES) \ + $(testext_la_SOURCES) $(time_la_SOURCES) DIST_SOURCES = $(filefuncs_la_SOURCES) $(fork_la_SOURCES) \ - $(ordchr_la_SOURCES) $(readfile_la_SOURCES) $(time_la_SOURCES) + $(ordchr_la_SOURCES) $(readfile_la_SOURCES) \ + $(testext_la_SOURCES) $(time_la_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -329,6 +337,7 @@ pkgextension_LTLIBRARIES = \ fork.la \ ordchr.la \ readfile.la \ + testext.la \ time.la MY_MODULE_FLAGS = -module -avoid-version -no-undefined @@ -342,14 +351,14 @@ readfile_la_SOURCES = readfile.c readfile_la_LDFLAGS = $(MY_MODULE_FLAGS) time_la_SOURCES = time.c time_la_LDFLAGS = $(MY_MODULE_FLAGS) +testext_la_SOURCES = testext.c +testext_la_LDFLAGS = $(MY_MODULE_FLAGS) #rwarray_la_SOURCES = rwarray.c #rwarray_la_LDFLAGS = $(MY_MODULE_FLAGS) EXTRA_DIST = \ ChangeLog \ ChangeLog.0 \ - *.awk \ - doit \ - steps + *.awk all: config.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -447,6 +456,8 @@ ordchr.la: $(ordchr_la_OBJECTS) $(ordchr_la_DEPENDENCIES) $(EXTRA_ordchr_la_DEPE $(ordchr_la_LINK) -rpath $(pkgextensiondir) $(ordchr_la_OBJECTS) $(ordchr_la_LIBADD) $(LIBS) readfile.la: $(readfile_la_OBJECTS) $(readfile_la_DEPENDENCIES) $(EXTRA_readfile_la_DEPENDENCIES) $(readfile_la_LINK) -rpath $(pkgextensiondir) $(readfile_la_OBJECTS) $(readfile_la_LIBADD) $(LIBS) +testext.la: $(testext_la_OBJECTS) $(testext_la_DEPENDENCIES) $(EXTRA_testext_la_DEPENDENCIES) + $(testext_la_LINK) -rpath $(pkgextensiondir) $(testext_la_OBJECTS) $(testext_la_LIBADD) $(LIBS) time.la: $(time_la_OBJECTS) $(time_la_DEPENDENCIES) $(EXTRA_time_la_DEPENDENCIES) $(time_la_LINK) -rpath $(pkgextensiondir) $(time_la_OBJECTS) $(time_la_LIBADD) $(LIBS) @@ -460,6 +471,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fork.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordchr.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readfile.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testext.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Plo@am__quote@ .c.o: diff --git a/extension/testext.c b/extension/testext.c index 5b171e84..fa8dbf64 100644 --- a/extension/testext.c +++ b/extension/testext.c @@ -50,18 +50,20 @@ int plugin_is_GPL_compatible; */ /* -@load testext -BEGIN { - dump_procinfo() -} +#@load "testext" +#BEGIN { +# dump_procinfo() +#} */ static awk_value_t * dump_procinfo(int nargs, awk_value_t *result) { /* get PROCINFO as flat array and print it */ + return result; } /* +@load "testext" BEGIN { testvar = "One Adam Twelve" ret = var_test("testvar") @@ -72,19 +74,45 @@ BEGIN { static awk_value_t * var_test(int nargs, awk_value_t *result) { - awk_value_t value; + awk_value_t value, value2; + awk_value_t *valp; - if (nargs != 1 || result == NULL) + if (nargs != 1 || result == NULL) { + printf("var_test: nargs not right (%d should be 1) or result == NULL\n", nargs); return NULL; + } /* look up a reserved variable - should fail */ - if (sym_lookup("ARGC", & value, AWK_NUMBER) != NULL) + if (sym_lookup("ARGC", AWK_NUMBER, & value)) printf("var_test: sym_lookup of ARGC failed - got a value!\n"); else printf("var_test: sym_lookup of ARGC passed\n"); /* look up variable whose name is passed in, should pass */ - /* change the value, should be reflected in awk script */ + if (get_argument(0, AWK_STRING, & value)) { + if (sym_lookup(value.str_value.str, AWK_STRING, & value2)) { + /* change the value, should be reflected in awk script */ + valp = make_number(42.0, & value2); + + if (sym_update(value.str_value.str, valp)) { + printf("var_test: sym_update(\"%s\") succeeded\n", value.str_value.str); + } else { + printf("var_test: sym_update(\"%s\") failed\n", value.str_value.str); + return NULL; + } + } else { + printf("var_test: sym_lookup(\"%s\") failed\n", value.str_value.str); + return NULL; + } + } else { + printf("var_test: get_argument() failed\n"); + return NULL; + } + + result->val_type = AWK_NUMBER; + result->num_value = 1.0; + + return result; } /* @@ -97,7 +125,17 @@ BEGIN { static awk_value_t * test_errno(int nargs, awk_value_t *result) { + if (nargs != 0 || result == NULL) { + printf("test_errno: nargs not right (%d should be 0) or result == NULL\n", nargs); + return NULL; + } + update_ERRNO_int(ECHILD); + + result->val_type = AWK_NUMBER; + result->num_value = 1.0; + + return result; } /* @@ -105,7 +143,7 @@ BEGIN { for (i = 1; i <= 10; i++) test_array[i] = i + 2 - printf ("length of test_array is %d, should be 10\n", length(test_array) + printf ("length of test_array is %d, should be 10\n", length(test_array)) ret = test_array_size(test_array); printf "test_array_size() returned %d, length is now %d\n", ret, length(test_array) } @@ -114,24 +152,62 @@ BEGIN { static awk_value_t * test_array_size(int nargs, awk_value_t *result) { + awk_value_t value; + size_t count = 0; + + if (nargs != 1 || result == NULL) { + printf("test_array_size: nargs not right (%d should be 0) or result == NULL\n", nargs); + return NULL; + } + /* get element count and print it; should match length(array) from awk script */ + if (! get_argument(0, AWK_ARRAY, & value)) { + printf("test_array_size: get_argument failed\n"); + return NULL; + } + + if (! get_element_count(value.array_cookie, & count)) { + printf("test_array_size: get_element_count failed\n"); + return NULL; + } + + printf("test_array_size: incoming size is %lu\n", (unsigned long) count); + /* clear array - length(array) should then go to zero in script */ + if (! clear_array(value.array_cookie)) { + printf("test_array_size: clear_array failed\n"); + return NULL; + } + + result->val_type = AWK_NUMBER; + result->num_value = 1.0; + + return result; } /* -BEGIN { - n = split("one two three four five six", test_array2) - ret = test_array_elem(test_array2, "3") - printf "test_array_elem() returned %d, test_array2[3] = %g\n", ret, test_array2[3] -} +#BEGIN { +# n = split("one two three four five six", test_array2) +# ret = test_array_elem(test_array2, "3") +# printf "test_array_elem() returned %d, test_array2[3] = %g\n", ret, test_array2[3] +# if ("5" in test_array2) +# printf "error: test_array_elem did not remove element \"5\"\n" +# else +# printf "test_array_elem did remove element \"5\"\n" +#} */ static awk_value_t * test_array_elem(int nargs, awk_value_t *result) { + if (nargs != 2 || result == NULL) { + printf("test_array_elem: nargs not right (%d should be 2) or result == NULL\n", nargs); + return NULL; + } /* look up an array element and print the value */ - /* change the element */ - /* delete another element */ + /* change the element - "3" */ + /* delete another element - "5" */ /* change and deletion should be reflected in awk script */ + return result; } /* @@ -148,7 +224,17 @@ BEGIN { static awk_value_t * print_do_lint(int nargs, awk_value_t *result) { + if (nargs != 0 || result == NULL) { + printf("print_do_lint: nargs not right (%d should be 0) or result == NULL\n", nargs); + return NULL; + } + printf("print_do_lint: lint = %d\n", do_lint); + + result->val_type = AWK_NUMBER; + result->num_value = 1.0; + + return result; } static void at_exit0(void *data, int exit_status) @@ -157,7 +243,7 @@ static void at_exit0(void *data, int exit_status) if (data) printf(" data = %p,", data); else - printf(" data = <null>,"); + printf(" data = NULL,"); printf(" exit_status = %d\n", exit_status); } @@ -173,7 +259,7 @@ static void at_exit1(void *data, int exit_status) else printf(" (data is NOT & data_for_1),"); } else - printf(" data = <null>,"); + printf(" data = NULL,"); printf(" exit_status = %d\n", exit_status); } @@ -183,7 +269,7 @@ static void at_exit2(void *data, int exit_status) if (data) printf(" data = %p,", data); else - printf(" data = <null>,"); + printf(" data = NULL,"); printf(" exit_status = %d\n", exit_status); } diff --git a/extension/time.c b/extension/time.c index 09e71d0e..a12a05d6 100644 --- a/extension/time.c +++ b/extension/time.c @@ -116,7 +116,7 @@ do_sleep(int nargs, awk_value_t *result) if (do_lint && nargs > 1) lintwarn(ext_id, "sleep: called with too many arguments"); - if (get_argument(0, AWK_NUMBER, &num) == NULL) { + if (! get_argument(0, AWK_NUMBER, &num)) { update_ERRNO_string("sleep: missing required numeric argument", 1); return make_number(-1, result); } |