diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2010-07-16 13:09:56 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2010-07-16 13:09:56 +0300 |
commit | bc70de7b3302d5a81515b901cae376b8b51d2004 (patch) | |
tree | d36d6743e65697f6923b79d0ea8f9f9bf4ef7398 /extension/dl.c | |
parent | b9e4a1fd4c8c8753ab8a9887bab55f03efe1e3e2 (diff) | |
download | egawk-bc70de7b3302d5a81515b901cae376b8b51d2004.tar.gz egawk-bc70de7b3302d5a81515b901cae376b8b51d2004.tar.bz2 egawk-bc70de7b3302d5a81515b901cae376b8b51d2004.zip |
Move to gawk-3.1.0.
Diffstat (limited to 'extension/dl.c')
-rw-r--r-- | extension/dl.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/extension/dl.c b/extension/dl.c new file mode 100644 index 00000000..0f1e1c5c --- /dev/null +++ b/extension/dl.c @@ -0,0 +1,96 @@ +/* + * dl.c - Example of adding a new builtin function to gawk. + * + * Christos Zoulas, Thu Jun 29 17:40:41 EDT 1995 + * Arnold Robbins, update for 3.1, Wed Sep 13 09:38:56 2000 + */ + +/* + * Copyright (C) 1995 - 2001 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "awk.h" +#include <dlfcn.h> + +static void *sdl = NULL; + +static NODE * +zaxxon(tree) +NODE *tree; +{ + NODE *obj; + int i; + int comma = 0; + + /* + * Print the arguments + */ + printf("External linkage %s(", tree->param); + + for (i = 0; i < tree->param_cnt; i++) { + + obj = get_argument(tree, i); + + if (obj == NULL) + break; + + force_string(obj); + + printf(comma ? ", %s" : "%s", obj->stptr); + free_temp(obj); + comma = 1; + } + + printf(");\n"); + + /* + * Do something useful + */ + obj = get_argument(tree, 0); + + if (obj != NULL) { + force_string(obj); + if (strcmp(obj->stptr, "unload") == 0 && sdl) { + /* + * XXX: How to clean up the function? + * I would like the ability to remove a function... + */ + dlclose(sdl); + sdl = NULL; + } + free_temp(obj); + } + + /* Set the return value */ + set_value(tmp_number((AWKNUM) 3.14)); + + /* Just to make the interpreter happy */ + return tmp_number((AWKNUM) 0); +} + +NODE * +dlload(tree, dl) +NODE *tree; +void *dl; +{ + sdl = dl; + make_builtin("zaxxon", zaxxon, 4); + return tmp_number((AWKNUM) 0); +} |