aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
Diffstat (limited to 'extension')
-rw-r--r--extension/ChangeLog12
-rw-r--r--extension/inplace.c44
-rw-r--r--extension/testext.c28
3 files changed, 61 insertions, 23 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog
index a1ad5efa..35b82970 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -203,6 +203,18 @@
* Makefile.am: Update copyright year.
+2017-07-20 Arnold D. Robbins <arnold@skeeve.com>
+
+ * inplace.c: Move functions into "inplace" namespace and simplify
+ the names. Update all error messages accordingly.
+
+2017-07-13 Arnold D. Robbins <arnold@skeeve.com>
+
+ * testext.c (init_test_ext): Add installation of a variable and a
+ function in a namespace, and test using them.
+ (do_test_function): New function.
+ (ns_test_func): New function entry for it.
+
2017-06-27 Arnold D. Robbins <arnold@skeeve.com>
* Makfile.am (intdiv_la_LIBADD): Add LIBMPFR for Cygwin.
diff --git a/extension/inplace.c b/extension/inplace.c
index 516edc97..d2a04118 100644
--- a/extension/inplace.c
+++ b/extension/inplace.c
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 2013-2015, 2018, the Free Software Foundation, Inc.
+ * Copyright (C) 2013-2015, 2017, 2018, the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -128,13 +128,13 @@ do_inplace_begin(int nargs, awk_value_t *result, struct awk_ext_func *unused)
fflush(stdout);
if (state.tname)
- fatal(ext_id, _("inplace_begin: in-place editing already active"));
+ fatal(ext_id, _("inplace::begin: in-place editing already active"));
if (nargs != 2)
- fatal(ext_id, _("inplace_begin: expects 2 arguments but called with %d"), nargs);
+ fatal(ext_id, _("inplace::begin: expects 2 arguments but called with %d"), nargs);
if (! get_argument(0, AWK_STRING, &filename))
- fatal(ext_id, _("inplace_begin: cannot retrieve 1st argument as a string filename"));
+ fatal(ext_id, _("inplace::begin: cannot retrieve 1st argument as a string filename"));
/*
* N.B. In the current implementation, the 2nd suffix arg is not used
@@ -142,21 +142,21 @@ do_inplace_begin(int nargs, awk_value_t *result, struct awk_ext_func *unused)
*/
if (invalid_filename(&filename.str_value)) {
- warning(ext_id, _("inplace_begin: disabling in-place editing for invalid FILENAME `%s'"),
+ warning(ext_id, _("inplace::begin: disabling in-place editing for invalid FILENAME `%s'"),
filename.str_value.str);
unset_ERRNO();
return make_number(-1, result);
}
if (stat(filename.str_value.str, & sbuf) < 0) {
- warning(ext_id, _("inplace_begin: Cannot stat `%s' (%s)"),
+ warning(ext_id, _("inplace::begin: Cannot stat `%s' (%s)"),
filename.str_value.str, strerror(errno));
update_ERRNO_int(errno);
return make_number(-1, result);
}
if (! S_ISREG(sbuf.st_mode)) {
- warning(ext_id, _("inplace_begin: `%s' is not a regular file"),
+ warning(ext_id, _("inplace::begin: `%s' is not a regular file"),
filename.str_value.str);
unset_ERRNO();
return make_number(-1, result);
@@ -167,7 +167,7 @@ do_inplace_begin(int nargs, awk_value_t *result, struct awk_ext_func *unused)
sprintf(state.tname, "%s.gawk.XXXXXX", filename.str_value.str);
if ((fd = mkstemp(state.tname)) < 0)
- fatal(ext_id, _("inplace_begin: mkstemp(`%s') failed (%s)"),
+ fatal(ext_id, _("inplace::begin: mkstemp(`%s') failed (%s)"),
state.tname, strerror(errno));
/* N.B. chown/chmod should be more portable than fchown/fchmod */
@@ -179,20 +179,20 @@ do_inplace_begin(int nargs, awk_value_t *result, struct awk_ext_func *unused)
}
if (chmod(state.tname, sbuf.st_mode) < 0)
- fatal(ext_id, _("inplace_begin: chmod failed (%s)"),
+ fatal(ext_id, _("inplace::begin: chmod failed (%s)"),
strerror(errno));
fflush(stdout);
/* N.B. fgetpos fails when stdout is a tty */
state.posrc = fgetpos(stdout, &state.pos);
if ((state.default_stdout = dup(STDOUT_FILENO)) < 0)
- fatal(ext_id, _("inplace_begin: dup(stdout) failed (%s)"),
+ fatal(ext_id, _("inplace::begin: dup(stdout) failed (%s)"),
strerror(errno));
if (dup2(fd, STDOUT_FILENO) < 0)
- fatal(ext_id, _("inplace_begin: dup2(%d, stdout) failed (%s)"),
+ fatal(ext_id, _("inplace::begin: dup2(%d, stdout) failed (%s)"),
fd, strerror(errno));
if (close(fd) < 0)
- fatal(ext_id, _("inplace_begin: close(%d) failed (%s)"),
+ fatal(ext_id, _("inplace::begin: close(%d) failed (%s)"),
fd, strerror(errno));
rewind(stdout);
return make_number(0, result);
@@ -208,30 +208,30 @@ do_inplace_end(int nargs, awk_value_t *result, struct awk_ext_func *unused)
assert(result != NULL);
if (nargs != 2)
- fatal(ext_id, _("inplace_end: expects 2 arguments but called with %d"), nargs);
+ fatal(ext_id, _("inplace::end: expects 2 arguments but called with %d"), nargs);
if (! get_argument(0, AWK_STRING, &filename))
- fatal(ext_id, _("inplace_end: cannot retrieve 1st argument as a string filename"));
+ fatal(ext_id, _("inplace::end: cannot retrieve 1st argument as a string filename"));
if (! get_argument(1, AWK_STRING, &suffix))
suffix.str_value.str = NULL;
if (! state.tname) {
if (! invalid_filename(&filename.str_value))
- warning(ext_id, _("inplace_end: in-place editing not active"));
+ warning(ext_id, _("inplace::end: in-place editing not active"));
return make_number(0, result);
}
fflush(stdout);
if (dup2(state.default_stdout, STDOUT_FILENO) < 0)
- fatal(ext_id, _("inplace_end: dup2(%d, stdout) failed (%s)"),
+ fatal(ext_id, _("inplace::end: dup2(%d, stdout) failed (%s)"),
state.default_stdout, strerror(errno));
if (close(state.default_stdout) < 0)
- fatal(ext_id, _("inplace_end: close(%d) failed (%s)"),
+ fatal(ext_id, _("inplace::end: close(%d) failed (%s)"),
state.default_stdout, strerror(errno));
state.default_stdout = -1;
if (state.posrc == 0 && fsetpos(stdout, &state.pos) < 0)
- fatal(ext_id, _("inplace_end: fsetpos(stdout) failed (%s)"),
+ fatal(ext_id, _("inplace::end: fsetpos(stdout) failed (%s)"),
strerror(errno));
if (suffix.str_value.str && suffix.str_value.str[0]) {
@@ -254,7 +254,7 @@ do_inplace_end(int nargs, awk_value_t *result, struct awk_ext_func *unused)
#endif
if (rename(state.tname, filename.str_value.str) < 0)
- fatal(ext_id, _("inplace_end: rename(`%s', `%s') failed (%s)"),
+ fatal(ext_id, _("inplace::end: rename(`%s', `%s') failed (%s)"),
state.tname, filename.str_value.str, strerror(errno));
gawk_free(state.tname);
state.tname = NULL;
@@ -262,8 +262,8 @@ do_inplace_end(int nargs, awk_value_t *result, struct awk_ext_func *unused)
}
static awk_ext_func_t func_table[] = {
- { "inplace_begin", do_inplace_begin, 2, 2, awk_false, NULL },
- { "inplace_end", do_inplace_end, 2, 2, awk_false, NULL },
+ { "begin", do_inplace_begin, 2, 2, awk_false, NULL },
+ { "end", do_inplace_end, 2, 2, awk_false, NULL },
};
static awk_bool_t init_inplace(void)
@@ -276,4 +276,4 @@ static awk_bool_t (*init_func)(void) = init_inplace;
/* define the dl_load function using the boilerplate macro */
-dl_load_func(func_table, inplace, "")
+dl_load_func(func_table, inplace, "inplace")
diff --git a/extension/testext.c b/extension/testext.c
index 6629296a..b911ec93 100644
--- a/extension/testext.c
+++ b/extension/testext.c
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 2012, 2013, 2014, 2015, 2018
+ * Copyright (C) 2012, 2013, 2014, 2015, 2017, 2018
* the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
@@ -1034,6 +1034,17 @@ static void at_exit2(void *data, int exit_status)
printf(" exit_status = %d\n", exit_status);
}
+/* do_test_function --- test function for test namespace */
+
+static awk_value_t *
+do_test_function(int nargs, awk_value_t *result, struct awk_ext_func *unused)
+{
+ printf("test::test_function() called.\n");
+ fflush(stdout);
+
+ return make_number(0.0, result);
+}
+
static awk_ext_func_t func_table[] = {
{ "dump_array_and_delete", dump_array_and_delete, 2, 2, awk_false, NULL },
{ "try_modify_environ", try_modify_environ, 0, 0, awk_false, NULL },
@@ -1051,6 +1062,10 @@ static awk_ext_func_t func_table[] = {
{ "get_file", do_get_file, 4, 4, awk_false, NULL },
};
+static awk_ext_func_t ns_test_func = {
+ "test_function", do_test_function, 0, 0, awk_false, NULL
+};
+
/* init_testext --- additional initialization function */
static awk_bool_t init_testext(void)
@@ -1058,6 +1073,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";
+ static const char message3[] = "in namespace test";
/* This is used by the getfile test */
if (sym_lookup("TESTEXT_QUIET", AWK_NUMBER, & value))
@@ -1075,6 +1091,9 @@ BEGIN {
for (i in new_array)
printf("new_array[\"%s\"] = \"%s\"\n", i, new_array[i])
print ""
+ printf("test::testval = %s\n", test::testval)
+ test::test_function()
+ print ""
}
*/
@@ -1092,6 +1111,13 @@ BEGIN {
create_new_array();
+ if (! sym_update_ns("test", "testval",
+ make_const_string(message3, strlen(message3), & value)))
+ printf("testext: sym_update_ns(\"test\", \"testval\") failed!\n");
+
+ if (! add_ext_func("test", & ns_test_func))
+ printf("testext: add_ext_func(\"test\", ns_test_func) failed!\n");
+
return awk_true;
}