From 8970970f3f3bc3d757fe491e90e608366fb7e604 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Fri, 24 Aug 2012 13:25:52 +0300 Subject: Add output and two-way processors to API. Update Mac config stuff. --- extension/revoutput.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 extension/revoutput.c (limited to 'extension/revoutput.c') diff --git a/extension/revoutput.c b/extension/revoutput.c new file mode 100644 index 00000000..c1ea1ddc --- /dev/null +++ b/extension/revoutput.c @@ -0,0 +1,136 @@ +/* + * revoutput.c --- Provide an output wrapper that reverses lines. + * + * Arnold Robbins + * arnold@skeeve.com + * Written 8/2012 + */ + +/* + * 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 +#include +#include +#include + +#include +#include + +#include "config.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 awk_bool_t init_revout(void); +static awk_bool_t (*init_func)(void) = init_revout; + +int plugin_is_GPL_compatible; + +/* rev_fwrite --- write out characters in reverse order */ + +static size_t +rev_fwrite(const void *buf, size_t size, size_t count, FILE *fp, void *opaque) +{ + const char *cp = buf; + int nbytes = size * count; + + (void) opaque; + + for (; nbytes >= 1; nbytes--) + putc(cp[nbytes-1], fp); + + return (size * count); +} + + +/* revout_can_take_file --- return true if we want the file */ + +static int +revout_can_take_file(const awk_output_buf_t *outbuf) +{ + awk_value_t value; + + if (outbuf == NULL) + return 0; + + if (! sym_lookup("REVOUT", AWK_NUMBER, & value)) + return 0; + + return (value.num_value != 0); +} + +/* + * revout_take_control_of --- set up output wrapper. + * We can assume that revout_can_take_file just returned true, + * and no state has changed since then. + */ + +static int +revout_take_control_of(awk_output_buf_t *outbuf) +{ + if (outbuf == NULL) + return 0; + + outbuf->gawk_fwrite = rev_fwrite; + outbuf->redirected = 1; + return 1; +} + +static awk_output_wrapper_t output_wrapper = { + "revout", + revout_can_take_file, + revout_take_control_of, + NULL +}; + +/* init_revout --- set things ups */ + +static awk_bool_t +init_revout() +{ + awk_value_t value; + + register_output_wrapper(& output_wrapper); + + make_number(0.0, & value); /* init to false */ + if (! sym_update("REVOUT", & value)) { + warning(ext_id, _("revout: could not initialize REVOUT variable")); + + return 0; + } + + return 1; +} + +static awk_ext_func_t func_table[] = { + { NULL, NULL, 0 } +}; + +/* define the dl_load function using the boilerplate macro */ + +dl_load_func(func_table, revout, "") -- cgit v1.2.3 From 759f2234c9bfa689151277fd2215bc0927cfc9c3 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Fri, 24 Aug 2012 13:40:22 +0300 Subject: Add facility to get vesion info from extensions. --- extension/revoutput.c | 1 + 1 file changed, 1 insertion(+) (limited to 'extension/revoutput.c') diff --git a/extension/revoutput.c b/extension/revoutput.c index c1ea1ddc..bb195a29 100644 --- a/extension/revoutput.c +++ b/extension/revoutput.c @@ -45,6 +45,7 @@ static const gawk_api_t *api; /* for convenience macros to work */ static awk_ext_id_t *ext_id; +static const char *ext_version = "revoutput extension: version 1.0"; static awk_bool_t init_revout(void); static awk_bool_t (*init_func)(void) = init_revout; -- cgit v1.2.3 From 0b4ff99fec136012af7a54f179bdf601e55e6274 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 26 Aug 2012 21:52:12 +0300 Subject: Use config.h properly. Add AC_SYS_LARGEFILE. --- extension/revoutput.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'extension/revoutput.c') diff --git a/extension/revoutput.c b/extension/revoutput.c index bb195a29..7430e61b 100644 --- a/extension/revoutput.c +++ b/extension/revoutput.c @@ -27,6 +27,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -35,8 +39,6 @@ #include #include -#include "config.h" - #include "gawkapi.h" #include "gettext.h" -- cgit v1.2.3 From a892293556960b0813098ede7da7a34774da7d3c Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 14 Oct 2012 18:56:06 +0200 Subject: API cleanups and doc additions. --- extension/revoutput.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'extension/revoutput.c') diff --git a/extension/revoutput.c b/extension/revoutput.c index 7430e61b..0366672b 100644 --- a/extension/revoutput.c +++ b/extension/revoutput.c @@ -49,8 +49,8 @@ static const gawk_api_t *api; /* for convenience macros to work */ static awk_ext_id_t *ext_id; static const char *ext_version = "revoutput extension: version 1.0"; -static awk_bool_t init_revout(void); -static awk_bool_t (*init_func)(void) = init_revout; +static awk_bool_t init_revoutput(void); +static awk_bool_t (*init_func)(void) = init_revoutput; int plugin_is_GPL_compatible; @@ -71,10 +71,10 @@ rev_fwrite(const void *buf, size_t size, size_t count, FILE *fp, void *opaque) } -/* revout_can_take_file --- return true if we want the file */ +/* revoutput_can_take_file --- return true if we want the file */ -static int -revout_can_take_file(const awk_output_buf_t *outbuf) +static awk_bool_t +revoutput_can_take_file(const awk_output_buf_t *outbuf) { awk_value_t value; @@ -88,13 +88,13 @@ revout_can_take_file(const awk_output_buf_t *outbuf) } /* - * revout_take_control_of --- set up output wrapper. - * We can assume that revout_can_take_file just returned true, + * revoutput_take_control_of --- set up output wrapper. + * We can assume that revoutput_can_take_file just returned true, * and no state has changed since then. */ -static int -revout_take_control_of(awk_output_buf_t *outbuf) +static awk_bool_t +revoutput_take_control_of(awk_output_buf_t *outbuf) { if (outbuf == NULL) return 0; @@ -105,16 +105,16 @@ revout_take_control_of(awk_output_buf_t *outbuf) } static awk_output_wrapper_t output_wrapper = { - "revout", - revout_can_take_file, - revout_take_control_of, + "revoutput", + revoutput_can_take_file, + revoutput_take_control_of, NULL }; -/* init_revout --- set things ups */ +/* init_revoutput --- set things ups */ static awk_bool_t -init_revout() +init_revoutput() { awk_value_t value; @@ -122,7 +122,7 @@ init_revout() make_number(0.0, & value); /* init to false */ if (! sym_update("REVOUT", & value)) { - warning(ext_id, _("revout: could not initialize REVOUT variable")); + warning(ext_id, _("revoutput: could not initialize REVOUT variable")); return 0; } @@ -136,4 +136,4 @@ static awk_ext_func_t func_table[] = { /* define the dl_load function using the boilerplate macro */ -dl_load_func(func_table, revout, "") +dl_load_func(func_table, revoutput, "") -- cgit v1.2.3