diff options
Diffstat (limited to 'extension')
-rw-r--r-- | extension/ChangeLog | 18 | ||||
-rw-r--r-- | extension/Makefile.am | 8 | ||||
-rw-r--r-- | extension/Makefile.in | 21 | ||||
-rw-r--r-- | extension/arrayparm.c | 83 | ||||
-rw-r--r-- | extension/configh.in | 21 | ||||
-rwxr-xr-x | extension/configure | 117 | ||||
-rw-r--r-- | extension/configure.ac | 6 | ||||
-rw-r--r-- | extension/dl.c | 92 | ||||
-rwxr-xr-x | extension/doit | 1 | ||||
-rw-r--r-- | extension/foo.awk | 9 | ||||
-rwxr-xr-x | extension/steps | 23 | ||||
-rw-r--r-- | extension/testarg.awk | 7 | ||||
-rw-r--r-- | extension/testarg.c | 55 | ||||
-rw-r--r-- | extension/testarrayparm.awk | 10 | ||||
-rw-r--r-- | extension/testff.awk | 30 | ||||
-rw-r--r-- | extension/testfork.awk | 20 | ||||
-rw-r--r-- | extension/testordchr.awk | 6 | ||||
-rw-r--r-- | extension/time.c | 167 |
18 files changed, 345 insertions, 349 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog index 140aea50..5e513f8e 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,3 +1,21 @@ +2012-06-10 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * Makefile.am: Add time extension. + * configure.ac: To support time extension, check for some headers + and functions that are needed. + * time.c: New file implementing sleep and gettimeofday. + +2012-06-10 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * Makefile.am: Remove comment referring to deleted test extensions + arrayparm, dl (zaxxon) and testarg. + +2012-06-10 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * arrayparm.c, dl.c, doit, foo.awk, steps, testarg.awk, testarg.c, + testarrayparm.awk, testff.awk, testfork.awk, testordchr.awk: Remove + unused (obsolete) files. + 2012-06-06 Arnold D. Robbins <arnold@skeeve.com> * filefuncs.c (do_stat): Make `type' const char *. diff --git a/extension/Makefile.am b/extension/Makefile.am index 81612236..f2b30ede 100644 --- a/extension/Makefile.am +++ b/extension/Makefile.am @@ -29,16 +29,14 @@ AM_CPPFLAGS = -I$(srcdir)/.. # correctly after changing configure.ac ACLOCAL_AMFLAGS = -I m4 -# The arrayparm, zaxxon (dl), and testarg libraries do not do anything useful, -# so do not build or install them. - # Note: rwarray does not currently compile. pkgextension_LTLIBRARIES = \ filefuncs.la \ fork.la \ ordchr.la \ - readfile.la + readfile.la \ + time.la MY_MODULE_FLAGS = -module -avoid-version -no-undefined @@ -50,6 +48,8 @@ ordchr_la_SOURCES = ordchr.c ordchr_la_LDFLAGS = $(MY_MODULE_FLAGS) readfile_la_SOURCES = readfile.c readfile_la_LDFLAGS = $(MY_MODULE_FLAGS) +time_la_SOURCES = time.c +time_la_LDFLAGS = $(MY_MODULE_FLAGS) #rwarray_la_SOURCES = rwarray.c #rwarray_la_LDFLAGS = $(MY_MODULE_FLAGS) diff --git a/extension/Makefile.in b/extension/Makefile.in index c90a0b4c..59528912 100644 --- a/extension/Makefile.in +++ b/extension/Makefile.in @@ -154,6 +154,12 @@ readfile_la_OBJECTS = $(am_readfile_la_OBJECTS) readfile_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(readfile_la_LDFLAGS) $(LDFLAGS) -o $@ +time_la_LIBADD = +am_time_la_OBJECTS = time.lo +time_la_OBJECTS = $(am_time_la_OBJECTS) +time_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(time_la_LDFLAGS) \ + $(LDFLAGS) -o $@ DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp am__depfiles_maybe = depfiles @@ -168,9 +174,9 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ SOURCES = $(filefuncs_la_SOURCES) $(fork_la_SOURCES) \ - $(ordchr_la_SOURCES) $(readfile_la_SOURCES) + $(ordchr_la_SOURCES) $(readfile_la_SOURCES) $(time_la_SOURCES) DIST_SOURCES = $(filefuncs_la_SOURCES) $(fork_la_SOURCES) \ - $(ordchr_la_SOURCES) $(readfile_la_SOURCES) + $(ordchr_la_SOURCES) $(readfile_la_SOURCES) $(time_la_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -317,15 +323,13 @@ AM_CPPFLAGS = -I$(srcdir)/.. # correctly after changing configure.ac ACLOCAL_AMFLAGS = -I m4 -# The arrayparm, zaxxon (dl), and testarg libraries do not do anything useful, -# so do not build or install them. - # Note: rwarray does not currently compile. pkgextension_LTLIBRARIES = \ filefuncs.la \ fork.la \ ordchr.la \ - readfile.la + readfile.la \ + time.la MY_MODULE_FLAGS = -module -avoid-version -no-undefined filefuncs_la_SOURCES = filefuncs.c @@ -336,6 +340,8 @@ ordchr_la_SOURCES = ordchr.c ordchr_la_LDFLAGS = $(MY_MODULE_FLAGS) readfile_la_SOURCES = readfile.c readfile_la_LDFLAGS = $(MY_MODULE_FLAGS) +time_la_SOURCES = time.c +time_la_LDFLAGS = $(MY_MODULE_FLAGS) #rwarray_la_SOURCES = rwarray.c #rwarray_la_LDFLAGS = $(MY_MODULE_FLAGS) EXTRA_DIST = \ @@ -441,6 +447,8 @@ ordchr.la: $(ordchr_la_OBJECTS) $(ordchr_la_DEPENDENCIES) $(EXTRA_ordchr_la_DEPE $(ordchr_la_LINK) -rpath $(pkgextensiondir) $(ordchr_la_OBJECTS) $(ordchr_la_LIBADD) $(LIBS) readfile.la: $(readfile_la_OBJECTS) $(readfile_la_DEPENDENCIES) $(EXTRA_readfile_la_DEPENDENCIES) $(readfile_la_LINK) -rpath $(pkgextensiondir) $(readfile_la_OBJECTS) $(readfile_la_LIBADD) $(LIBS) +time.la: $(time_la_OBJECTS) $(time_la_DEPENDENCIES) $(EXTRA_time_la_DEPENDENCIES) + $(time_la_LINK) -rpath $(pkgextensiondir) $(time_la_OBJECTS) $(time_la_LIBADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -452,6 +460,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fork.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordchr.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readfile.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Plo@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/extension/arrayparm.c b/extension/arrayparm.c deleted file mode 100644 index 02b8c2e4..00000000 --- a/extension/arrayparm.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * arrayparm.c --- figure out how to make a parameter be an array - * - * Arnold Robbins - * arnold@skeeve.com - * 10/2001 - * - * Revised 7/2003 - * Revised 6/2004 - */ - -/* - * Copyright (C) 2001, 2003, 2004, 2011 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 - */ - -#include "awk.h" - -int plugin_is_GPL_compatible; - -/* do_mkarray --- turn a variable into an array */ - -/* - * From awk, call - * - * mkarray(var, sub, val) - */ - -static NODE * -do_mkarray(int nargs) -{ - int ret = -1; - NODE *var, *sub, *val; - NODE **elemval; - - if (do_lint && nargs > 3) - lintwarn("mkarray: called with too many arguments"); - - var = get_array_argument(0, false); - sub = get_scalar_argument(1, false); - val = get_scalar_argument(2, false); - - printf("var->type = %s\n", nodetype2str(var->type)); - printf("sub->type = %s\n", nodetype2str(sub->type)); - printf("val->type = %s\n", nodetype2str(val->type)); - - assoc_clear(var); - - elemval = assoc_lookup(var, sub); - *elemval = dupnode(val); - ret = 0; - - /* Set the return value */ - return make_number((AWKNUM) ret); -} - -/* dlload --- load new builtins in this library */ - -NODE * -dlload(tree, dl) -NODE *tree; -void *dl; -{ - make_builtin("mkarray", do_mkarray, 3); - - return make_number((AWKNUM) 0); -} diff --git a/extension/configh.in b/extension/configh.in index e0beaf25..519f8ea3 100644 --- a/extension/configh.in +++ b/extension/configh.in @@ -3,12 +3,24 @@ /* Define to 1 if you have the <dlfcn.h> header file. */ #undef HAVE_DLFCN_H +/* Define to 1 if you have the `GetSystemTimeAsFileTime' function. */ +#undef HAVE_GETSYSTEMTIMEASFILETIME + +/* Define to 1 if you have the `gettimeofday' function. */ +#undef HAVE_GETTIMEOFDAY + /* Define to 1 if you have the <inttypes.h> header file. */ #undef HAVE_INTTYPES_H /* Define to 1 if you have the <memory.h> header file. */ #undef HAVE_MEMORY_H +/* Define to 1 if you have the `nanosleep' function. */ +#undef HAVE_NANOSLEEP + +/* Define to 1 if you have the `select' function. */ +#undef HAVE_SELECT + /* Define to 1 if you have the <stdint.h> header file. */ #undef HAVE_STDINT_H @@ -21,12 +33,21 @@ /* Define to 1 if you have the <string.h> header file. */ #undef HAVE_STRING_H +/* Define to 1 if you have the <sys/select.h> header file. */ +#undef HAVE_SYS_SELECT_H + /* Define to 1 if you have the <sys/stat.h> header file. */ #undef HAVE_SYS_STAT_H +/* Define to 1 if you have the <sys/time.h> header file. */ +#undef HAVE_SYS_TIME_H + /* Define to 1 if you have the <sys/types.h> header file. */ #undef HAVE_SYS_TYPES_H +/* Define to 1 if you have the <time.h> header file. */ +#undef HAVE_TIME_H + /* Define to 1 if you have the <unistd.h> header file. */ #undef HAVE_UNISTD_H diff --git a/extension/configure b/extension/configure index 7333bdad..30b162a8 100755 --- a/extension/configure +++ b/extension/configure @@ -1754,6 +1754,97 @@ $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func + +# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists, giving a warning if it cannot be compiled using +# the include files in INCLUDES and setting the cache variable VAR +# accordingly. +ac_fn_c_check_header_mongrel () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if eval \${$3+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +else + # Is the header compilable? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 +$as_echo_n "checking $2 usability... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_header_compiler=yes +else + ac_header_compiler=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } + +# Is the header present? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 +$as_echo_n "checking $2 presence... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <$2> +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + ac_header_preproc=yes +else + ac_header_preproc=no +fi +rm -f conftest.err conftest.i conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( + yes:no: ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} + ;; + no:yes:* ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} +( $as_echo "## ------------------------------- ## +## Report this to bug-gawk@gnu.org ## +## ------------------------------- ##" + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=\$ac_header_compiler" +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_header_mongrel cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. @@ -11371,6 +11462,32 @@ then CFLAGS="$CFLAGS -Wall -Wextra" fi +for ac_header in time.h sys/time.h sys/select.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +for ac_func in nanosleep select gettimeofday GetSystemTimeAsFileTime +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5 $as_echo_n "checking for inline... " >&6; } diff --git a/extension/configure.ac b/extension/configure.ac index 461826e6..838350cf 100644 --- a/extension/configure.ac +++ b/extension/configure.ac @@ -45,9 +45,9 @@ then CFLAGS="$CFLAGS -Wall -Wextra" fi -dnl AC_CHECK_HEADERS(stdarg.h) -dnl AC_CHECK_FUNCS(snprintf) -dnl AC_FUNC_VPRINTF +AC_CHECK_HEADERS(time.h sys/time.h sys/select.h) + +AC_CHECK_FUNCS(nanosleep select gettimeofday GetSystemTimeAsFileTime) dnl checks for compiler characteristics AC_C_INLINE diff --git a/extension/dl.c b/extension/dl.c deleted file mode 100644 index ee3b08fe..00000000 --- a/extension/dl.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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, 2011 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 - */ - -#include "awk.h" -#include <dlfcn.h> - -int plugin_is_GPL_compatible; - -static void *sdl = NULL; - -static NODE * -zaxxon(int nargs) -{ - NODE *obj; - int i; - int comma = 0; - - /* - * Print the arguments - */ - printf("External linkage zaxxon("); - - for (i = 0; i < nargs; i++) { - - obj = get_scalar_argument(i, true); - - if (obj == NULL) - break; - - force_string(obj); - - printf(comma ? ", %s" : "%s", obj->stptr); - comma = 1; - } - - printf(");\n"); - - /* - * Do something useful - */ - obj = get_scalar_argument(0, false); - - 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; - } - } - - /* Set the return value */ - return make_number((AWKNUM) 3.14); -} - -NODE * -dlload(tree, dl) -NODE *tree; -void *dl; -{ - sdl = dl; - make_builtin("zaxxon", zaxxon, 4); - return make_number((AWKNUM) 0); -} diff --git a/extension/doit b/extension/doit deleted file mode 100755 index 29dff7d8..00000000 --- a/extension/doit +++ /dev/null @@ -1 +0,0 @@ -../gawk -f foo.awk diff --git a/extension/foo.awk b/extension/foo.awk deleted file mode 100644 index 00a89e5b..00000000 --- a/extension/foo.awk +++ /dev/null @@ -1,9 +0,0 @@ -BEGIN { - extension("./dl.so","dlload") - zaxxon("hi there", "this is", "a test", "of argument passing") - zaxxon(1) - zaxxon(1,2) - z = zaxxon(1,2,3,4) - z = zaxxon(1,zaxxon(zaxxon("foo")),3,4) - print z -} diff --git a/extension/steps b/extension/steps deleted file mode 100755 index a6696ddc..00000000 --- a/extension/steps +++ /dev/null @@ -1,23 +0,0 @@ -# what to do under linux to make dl.so -# Tue Nov 24 15:04:14 EST 1998 -# Sun Aug 26 16:03:58 IDT 2001 -# Sun Apr 28 15:59:57 IDT 2002 -# Mon Jun 21 17:03:37 IDT 2004 -# Fri May 15 15:48:45 IDT 2009 - -gcc -fPIC -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. dl.c -gcc -fPIC -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. filefuncs.c -gcc -fPIC -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. fork.c -gcc -fPIC -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. ordchr.c -gcc -fPIC -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. arrayparm.c -gcc -fPIC -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. readfile.c -gcc -fPIC -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. testarg.c -gcc -fPIC -shared -Wall -DHAVE_CONFIG_H -c -O -g -I.. rwarray.c -ld -o dl.so -shared dl.o -ld -o filefuncs.so -shared filefuncs.o -ld -o fork.so -shared fork.o -ld -o ordchr.so -shared ordchr.o -ld -o arrayparm.so -shared arrayparm.o -ld -o readfile.so -shared readfile.o -ld -o testarg.so -shared testarg.o -ld -o rwarray.so -shared rwarray.o diff --git a/extension/testarg.awk b/extension/testarg.awk deleted file mode 100644 index a91df1a9..00000000 --- a/extension/testarg.awk +++ /dev/null @@ -1,7 +0,0 @@ -BEGIN { - extension("./testarg.so", "dlload") - check_arg(x, a); - check_arg(y, b, z); - check_arg(u, v, u=1); - check_arg(p, q, r, s); -} diff --git a/extension/testarg.c b/extension/testarg.c deleted file mode 100644 index 32481b33..00000000 --- a/extension/testarg.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "awk.h" - -int plugin_is_GPL_compatible; - -static NODE * -do_check_arg(int nargs) -{ - int ret = 0; - NODE *arg1, *arg2, *arg3; - - printf("arg count: defined = 3, supplied = %d\n", nargs); - - arg1 = get_scalar_argument(0, false); - arg2 = get_array_argument(1, false); - arg3 = get_scalar_argument(2, true); /* optional */ - if (nargs > 3) { - /* try to use an extra arg */ - NODE *arg4; - arg4 = get_array_argument(3, true); - printf("Shouldn't see this line\n"); - } - if (arg3 != NULL) { - printf("3rd arg present\n"); - if (arg3->type != Node_val) - printf("3nd arg type = %s (*** NOT OK ***)\n", nodetype2str(arg3->type)); - } else - printf("no 3rd arg\n"); - - if (arg2 != NULL) { - if (arg2->type != Node_var_array) - printf("2nd arg type = %s (*** NOT OK ***)\n", nodetype2str(arg2->type)); - } else - printf("2nd arg missing (NULL) (*** NOT OK ***)\n"); - - if (arg1 != NULL) { - if (arg1->type != Node_val) - printf("1st arg type = %s (*** NOT OK ***)\n", nodetype2str(arg1->type)); - } else - printf("1st arg missing (NULL) (*** NOT OK ***)\n"); - printf("\n"); - - /* Set the return value */ - return make_number((AWKNUM) ret); -} - -/* dlload --- load new builtins in this library */ - -NODE * -dlload(tree, dl) -NODE *tree; -void *dl; -{ - make_builtin("check_arg", do_check_arg, 3); - return make_number((AWKNUM) 0); -} diff --git a/extension/testarrayparm.awk b/extension/testarrayparm.awk deleted file mode 100644 index 08178f3e..00000000 --- a/extension/testarrayparm.awk +++ /dev/null @@ -1,10 +0,0 @@ -#! /bin/awk -f - -BEGIN { - extension("./arrayparm.so", "dlload") - - mkarray(newvar, "hi", "hello") - - for (i in newvar) - printf ("newvar[\"%s\"] = \"%s\"\n", i, newvar[i]) -} diff --git a/extension/testff.awk b/extension/testff.awk deleted file mode 100644 index 0a0a9b2f..00000000 --- a/extension/testff.awk +++ /dev/null @@ -1,30 +0,0 @@ -BEGIN { - extension("./filefuncs.so", "dlload") - -# printf "before: " -# fflush() -# system("pwd") -# -# chdir("..") -# -# printf "after: " -# fflush() -# system("pwd") - - chdir(".") - - data[1] = 1 - print "Info for testff.awk" - ret = stat("testff.awk", data) - print "ret =", ret - for (i in data) - printf "data[\"%s\"] = %s\n", i, data[i] - print "testff.awk modified:", strftime("%m %d %y %H:%M:%S", data["mtime"]) - - print "\nInfo for JUNK" - ret = stat("JUNK", data) - print "ret =", ret - for (i in data) - printf "data[\"%s\"] = %s\n", i, data[i] - print "JUNK modified:", strftime("%m %d %y %H:%M:%S", data["mtime"]) -} diff --git a/extension/testfork.awk b/extension/testfork.awk deleted file mode 100644 index ca00dca8..00000000 --- a/extension/testfork.awk +++ /dev/null @@ -1,20 +0,0 @@ -BEGIN { - extension("./fork.so", "dlload") - - printf "before fork, pid = %d, ppid = %d\n", PROCINFO["pid"], - PROCINFO["ppid"] - - fflush() - ret = fork() - if (ret < 0) - printf("ret = %d, ERRNO = %s\n", ret, ERRNO) - else if (ret == 0) - printf "child, pid = %d, ppid = %d\n", PROCINFO["pid"], - PROCINFO["ppid"] - else { - system("sleep 3") - printf "parent, ret = %d\n", ret - printf "parent, pid = %d, ppid = %d\n", PROCINFO["pid"], - PROCINFO["ppid"] - } -} diff --git a/extension/testordchr.awk b/extension/testordchr.awk deleted file mode 100644 index 64e53d16..00000000 --- a/extension/testordchr.awk +++ /dev/null @@ -1,6 +0,0 @@ -BEGIN { - extension("./ordchr.so", "dlload") - - print "ord(\"a\") is", ord("a") - print "chr(65) is", chr(65) -} diff --git a/extension/time.c b/extension/time.c new file mode 100644 index 00000000..4f590c88 --- /dev/null +++ b/extension/time.c @@ -0,0 +1,167 @@ +/* + * time.c - Builtin functions that provide time-related functions. + * + */ + +/* + * Copyright (C) 2012 + * 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 + */ + +#include <stdio.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include "config.h" +#include "gawkapi.h" + +static const gawk_api_t *api; /* for convenience macros to work */ +static awk_ext_id_t *ext_id; + +int plugin_is_GPL_compatible; + +#if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) +#include <sys/time.h> +#endif +#if defined(HAVE_SELECT) && defined(HAVE_SYS_SELECT_H) +#include <sys/select.h> +#endif +#if defined(HAVE_NANOSLEEP) && defined(HAVE_TIME_H) +#include <time.h> +#endif + +#define RETURN return tmp_number((AWKNUM) 0) + +/* + * Returns time since 1/1/1970 UTC as a floating point value; should + * have sub-second precision, but the actual precision will vary based + * on the platform + */ +static awk_value_t * +do_gettimeofday(int nargs, awk_value_t *result) +{ + double curtime; + + if (do_lint && nargs > 0) + lintwarn(ext_id, "gettimeofday: ignoring arguments"); + +#if defined(HAVE_GETTIMEOFDAY) + { + struct timeval tv; + gettimeofday(&tv,NULL); + curtime = tv.tv_sec+(tv.tv_usec/1000000.0); + } +#elif defined(HAVE_GETSYSTEMTIMEASFILETIME) + /* based on perl win32/win32.c:win32_gettimeofday() implementation */ + { + union { + unsigned __int64 ft_i64; + FILETIME ft_val; + } ft; + + /* # of 100-nanosecond intervals since January 1, 1601 (UTC) */ + GetSystemTimeAsFileTime(&ft.ft_val); +#ifdef __GNUC__ +#define Const64(x) x##LL +#else +#define Const64(x) x##i64 +#endif +/* Number of 100 nanosecond units from 1/1/1601 to 1/1/1970 */ +#define EPOCH_BIAS Const64(116444736000000000) + curtime = (ft.ft_i64 - EPOCH_BIAS)/10000000.0; +#undef Const64 + } +#else + /* no way to retrieve system time on this platform */ + curtime = -1; + update_ERRNO_string("gettimeofday: not supported on this platform", 1); +#endif + + return make_number(curtime, result); +} + +/* + * Returns 0 if successful in sleeping the requested time; + * returns -1 if there is no platform support, or if the sleep request + * did not complete successfully (perhaps interrupted) + */ +static awk_value_t * +do_sleep(int nargs, awk_value_t *result) +{ + awk_value_t num; + double secs; + int rc; + + if (do_lint && nargs > 1) + lintwarn(ext_id, "sleep: called with too many arguments"); + + + if (get_curfunc_param(0, AWK_NUMBER, &num) == NULL) { + update_ERRNO_string("sleep: missing required numeric argument", 1); + return make_number(-1, result); + } + secs = num.num_value; + + if (secs < 0) { + update_ERRNO_string("sleep: argument is negative", 1); + return make_number(-1, result); + } + +#if defined(HAVE_NANOSLEEP) + { + struct timespec req; + + req.tv_sec = secs; + req.tv_nsec = (secs-(double)req.tv_sec)*1000000000.0; + if ((rc = nanosleep(&req,NULL)) < 0) + /* probably interrupted */ + update_ERRNO_int(errno); + } +#elif defined(HAVE_SELECT) + { + struct timeval timeout; + + timeout.tv_sec = secs; + timeout.tv_usec = (secs-(double)timeout.tv_sec)*1000000.0; + if ((rc = select(0,NULL,NULL,NULL,&timeout)) < 0) + /* probably interrupted */ + update_ERRNO_int(errno); + } +#else + /* no way to sleep on this platform */ + rc = -1; + set_ERRNO("sleep: not supported on this platform"); +#endif + + return make_number(rc, result); +} + +static awk_ext_func_t func_table[] = { + { "gettimeofday", do_gettimeofday, 0 }, + { "sleep", do_sleep, 1 }, +}; + +/* define the dl_load function using the boilerplate macro */ + +dl_load_func(func_table, time, "") |