#include "common.h" static awk_value_t * do_create_variable(int nargs, awk_value_t *result) { awk_value_t name, value, v; int readonly; awk_bool_t rc; if (do_lint && (nargs > 3)) lintwarn(ext_id, _("create_variable: called with too many arguments")); if (!get_argument(0, AWK_STRING, &name)) { set_ERRNO(_("do_create_variable: 1st argument must be a variable name")); RET_NUM(-1); } if (!get_argument(1, AWK_STRING, &value)) { set_ERRNO(_("do_create_variable: 2nd argument must be a variable value")); RET_NUM(-1); } { awk_value_t x; readonly = (get_argument(2, AWK_NUMBER, &x) && x.num_value); } #if 0 fprintf(stderr, "DEBUG: name [%s] value [%s] readonly %d\n", name.str_value.str, value.str_value.str, readonly); #endif if (readonly) rc = sym_constant(name.str_value.str, make_string_malloc(value.str_value.str, value.str_value.len, &v)); else rc = sym_update(name.str_value.str, make_string_malloc(value.str_value.str, value.str_value.len, &v)); if (!rc) { /* failed, so free memory */ free(v.str_value.str); RET_NUM(-1); } RET_NUM(0); } /* Wrappers for libpq functions: */ static awk_ext_func_t func_table[] = { { "create_variable", do_create_variable, 3}, }; static awk_bool_t (*init_func)(void) = NULL; static const char ext_version[] = "CreateVariable extension: version 1.0"; dl_load_func(func_table, create_variable, "")