aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--extension/ChangeLog5
-rw-r--r--extension/testext.c59
-rw-r--r--test/ChangeLog4
-rw-r--r--test/testext.ok15
4 files changed, 83 insertions, 0 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 69827582..f62f37a1 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,8 @@
+2012-07-15 Arnold D. Robbins <arnold@skeeve.com>
+
+ * testext.c (test_scalar): New function and new tests.
+ (init_testext): Add a new variable.
+
2012-07-13 Arnold D. Robbins <arnold@skeeve.com>
* filefuncs.c (fill_stat_array): New function to do the work
diff --git a/extension/testext.c b/extension/testext.c
index 0eff62b7..44b6a87f 100644
--- a/extension/testext.c
+++ b/extension/testext.c
@@ -483,6 +483,59 @@ out:
return result;
}
+/*
+BEGIN {
+ n = split("1 3 5 7 9 11", nums)
+ m = split("the quick brown fox jumps over the lazy dog", strings)
+ for (i in nums) {
+ ret = test_scalar(nums[i] + 0)
+ printf("test_scalar(%d) returned %d, the_scalar is %d\n", nums[i], ret, the_scalar)
+ }
+ for (i in strings) {
+ ret = test_scalar(strings[i])
+ printf("test_scalar(%s) returned %d, the_scalar is %s\n", strings[i], ret, the_scalar)
+ }
+}
+*/
+
+/* test_scalar --- test scalar cookie */
+
+static awk_value_t *
+test_scalar(int nargs, awk_value_t *result)
+{
+ awk_value_t new_value, new_value2;
+ awk_value_t the_scalar;
+
+ make_number(0.0, result);
+
+ if (! sym_lookup("the_scalar", AWK_SCALAR, & the_scalar)) {
+ printf("test_scalar: could not get scalar cookie\n");
+ goto out;
+ }
+
+ if (! get_argument(0, AWK_UNDEFINED, & new_value)) {
+ printf("test_scalar: could not get argument\n");
+ goto out;
+ } else if (new_value.val_type != AWK_STRING && new_value.val_type != AWK_NUMBER) {
+ printf("test_scalar: argument is not a scalar\n");
+ goto out;
+ }
+
+ if (new_value.val_type == AWK_STRING) {
+ make_const_string(new_value.str_value.str, new_value.str_value.len, & new_value2);
+ } else {
+ new_value2 = new_value;
+ }
+
+ if (! sym_update_scalar(the_scalar.scalar_cookie, & new_value2)) {
+ }
+
+ make_number(1.0, result);
+
+out:
+ return result;
+}
+
/* fill_in_array --- fill in a new array */
static void
@@ -574,6 +627,7 @@ static awk_ext_func_t func_table[] = {
{ "test_array_elem", test_array_elem, 2 },
{ "test_array_param", test_array_param, 1 },
{ "print_do_lint", print_do_lint, 0 },
+ { "test_scalar", test_scalar, 1 },
};
/* init_testext --- additional initialization function */
@@ -582,6 +636,7 @@ static awk_bool_t init_testext(void)
{
awk_value_t value;
static const char message[] = "hello, world"; /* of course */
+ static const char message2[] = "i am a scalar";
/* add at_exit functions */
awk_atexit(at_exit0, NULL);
@@ -606,6 +661,10 @@ BEGIN {
make_const_string(message, strlen(message), & value)))
printf("testext: sym_update(\"answer_num\") failed!\n");
+ if (! sym_update("the_scalar",
+ make_const_string(message2, strlen(message2), & value)))
+ printf("testext: sym_update(\"the_scalar\") failed!\n");
+
create_new_array();
return 1;
diff --git a/test/ChangeLog b/test/ChangeLog
index 50dcd27c..bb270e91 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
+2012-07-15 Arnold D. Robbins <arnold@skeeve.com>
+
+ * testext.ok: Update contents.
+
2012-07-12 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (fnmatch): New test.
diff --git a/test/testext.ok b/test/testext.ok
index 619d97ba..132179c2 100644
--- a/test/testext.ok
+++ b/test/testext.ok
@@ -42,6 +42,21 @@ Changed value of LINT is 1
print_do_lint: lint = 1
print_do_lint() returned 1
+test_scalar(1) returned 1, the_scalar is 1
+test_scalar(3) returned 1, the_scalar is 3
+test_scalar(5) returned 1, the_scalar is 5
+test_scalar(7) returned 1, the_scalar is 7
+test_scalar(9) returned 1, the_scalar is 9
+test_scalar(11) returned 1, the_scalar is 11
+test_scalar(the) returned 1, the_scalar is the
+test_scalar(quick) returned 1, the_scalar is quick
+test_scalar(brown) returned 1, the_scalar is brown
+test_scalar(fox) returned 1, the_scalar is fox
+test_scalar(jumps) returned 1, the_scalar is jumps
+test_scalar(over) returned 1, the_scalar is over
+test_scalar(the) returned 1, the_scalar is the
+test_scalar(lazy) returned 1, the_scalar is lazy
+test_scalar(dog) returned 1, the_scalar is dog
answer_num = 42
message_string = hello, world
new_array["hello"] = "world"