diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2017-02-23 20:50:30 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2017-02-23 20:50:30 +0200 |
commit | 6985181ce58fa980f3007e866aa3a30b4c54048c (patch) | |
tree | 6aec92fcbb9945e73475be1f24475bafcfc21e0c | |
parent | 9ed206b61dc20af209ceca5b26c536bdb7b2edad (diff) | |
download | gawk-easter-eggs/detect-local.tar.gz |
Add extension/islocal.c (oops); small fix in gawkapi.h.easter-eggs/detect-local
-rw-r--r-- | extension/islocal.c | 77 | ||||
-rw-r--r-- | gawkapi.h | 2 |
2 files changed, 78 insertions, 1 deletions
diff --git a/extension/islocal.c b/extension/islocal.c new file mode 100644 index 00000000..da05ce21 --- /dev/null +++ b/extension/islocal.c @@ -0,0 +1,77 @@ +/* + * islocal.c - Return true if a parameter came from a local variable. + */ + +/* + * Copyright (C) 2017 the Free Software Foundation, Inc. + * + * This file is part of GAWK, the GNU implementation of the + * AWK Programming Language. + * + * GAWK is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GAWK is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <assert.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <sys/types.h> +#include <sys/stat.h> + +#include "gawkapi.h" + +#include "gettext.h" +#define _(msgid) gettext(msgid) +#define N_(msgid) msgid + +static const gawk_api_t *api; /* for convenience macros to work */ +static awk_ext_id_t *ext_id; +static const char *ext_version = "islocal extension: version 1.0"; +static awk_bool_t (*init_func)(void) = NULL; + +int plugin_is_GPL_compatible; + +/* do_islocal --- check if a variable is local or not */ + +static awk_value_t * +do_islocal(int nargs, awk_value_t *result, struct awk_ext_func *unused) +{ + awk_value_t param; + int ret = -1; + + assert(result != NULL); + + if (get_argument(0, AWK_UNDEFINED, ¶m)) { + ret = param.is_local; + } + + /* Set the return value */ + return make_number(ret, result); +} + +static awk_ext_func_t func_table[] = { + { "islocal", do_islocal, 1, 1, awk_false, NULL }, +}; + +/* define the dl_load function using the boilerplate macro */ + +dl_load_func(func_table, islocal, "") @@ -326,7 +326,7 @@ typedef struct awk_value { awk_scalar_t scl; awk_value_cookie_t vc; } u; - int is_local; /* true if parameter was a truly local variable */ + awk_bool_t is_local; /* true if parameter was a truly local variable */ #define str_value u.s #define strnum_value str_value #define regex_value str_value |