diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2012-12-19 15:36:57 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2012-12-19 15:36:57 +0200 |
commit | 894413cf12f347facef4de3626573644d067c3bb (patch) | |
tree | 27fde9b2b956a34a23c24e416cc5ef22de6183cd /extension/testext.c | |
parent | e468705fb6c7f2b2384c20f320e617cdbd55238c (diff) | |
download | egawk-894413cf12f347facef4de3626573644d067c3bb.tar.gz egawk-894413cf12f347facef4de3626573644d067c3bb.tar.bz2 egawk-894413cf12f347facef4de3626573644d067c3bb.zip |
Make indirectly updated vars accessable to SYMTAB, API.
Diffstat (limited to 'extension/testext.c')
-rw-r--r-- | extension/testext.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/extension/testext.c b/extension/testext.c index 9367da77..8f6735c1 100644 --- a/extension/testext.c +++ b/extension/testext.c @@ -686,6 +686,52 @@ out: return result; } +/* +BEGIN { + print "line 1" > "testexttmp.txt" + print "line 2" > "testexttmp.txt" + print "line 3" > "testexttmp.txt" + close("testexttmp.txt") + ARGV[1] = "testexttmp.txt" + ARGC = 2 + getline + getline + getline # now NR should be 3 +# system("rm testexttmp.txt") + ret = test_indirect_vars() # should get correct value of NR + printf("test_indirect_var() return %d\n", ret) + delete ARGV[1] +} +*/ + +/* test_indirect_vars --- test that access to NR, NF, get correct vales */ + +static awk_value_t * +test_indirect_vars(int nargs, awk_value_t *result) +{ + awk_value_t value; + char *name = "NR"; + + assert(result != NULL); + make_number(0.0, result); + + /* system("rm testexttmp.txt") */ + (void) unlink("testexttmp.txt"); + + if (sym_lookup(name, AWK_NUMBER, & value)) + printf("test_indirect_var: sym_lookup of %s passed\n", name); + else { + printf("test_indirect_var: sym_lookup of %s failed\n", name); + goto out; + } + + printf("test_indirect_var: value of NR is %g\n", value.num_value); + + make_number(1.0, result); +out: + return result; +} + /* fill_in_array --- fill in a new array */ static void @@ -780,6 +826,7 @@ static awk_ext_func_t func_table[] = { { "print_do_lint", print_do_lint, 0 }, { "test_scalar", test_scalar, 1 }, { "test_scalar_reserved", test_scalar_reserved, 0 }, + { "test_indirect_vars", test_indirect_vars, 0 }, }; /* init_testext --- additional initialization function */ |