diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2015-05-28 22:20:20 -0400 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2015-05-28 22:20:20 -0400 |
commit | 53d7134462df2933d997f7dd403510d2e27c1540 (patch) | |
tree | efe0d2a4b79728f29a19259d0b61527981724e62 | |
parent | 0b876113d778d77543fd8bafef4e37fc2af72bc8 (diff) | |
download | gawk-53d7134462df2933d997f7dd403510d2e27c1540.tar.gz |
Add nl_langinfo extension.
-rw-r--r-- | extension/Makefile.am | 5 | ||||
-rw-r--r-- | extension/Makefile.in | 21 | ||||
-rw-r--r-- | extension/configh.in | 3 | ||||
-rwxr-xr-x | extension/configure | 2 | ||||
-rw-r--r-- | extension/configure.ac | 2 | ||||
-rw-r--r-- | extension/nl_langinfo.awk | 6 | ||||
-rw-r--r-- | extension/nl_langinfo.c | 201 |
7 files changed, 236 insertions, 4 deletions
diff --git a/extension/Makefile.am b/extension/Makefile.am index 92f5637b..cbfeefec 100644 --- a/extension/Makefile.am +++ b/extension/Makefile.am @@ -39,6 +39,7 @@ pkgextension_LTLIBRARIES = \ fnmatch.la \ fork.la \ inplace.la \ + nl_langinfo.la \ ordchr.la \ readdir.la \ readfile.la \ @@ -69,6 +70,10 @@ inplace_la_SOURCES = inplace.c inplace_la_LDFLAGS = $(MY_MODULE_FLAGS) inplace_la_LIBADD = $(MY_LIBS) +nl_langinfo_la_SOURCES = nl_langinfo.c +nl_langinfo_la_LDFLAGS = $(MY_MODULE_FLAGS) +nl_langinfo_la_LIBADD = $(MY_LIBS) + ordchr_la_SOURCES = ordchr.c ordchr_la_LDFLAGS = $(MY_MODULE_FLAGS) ordchr_la_LIBADD = $(MY_LIBS) diff --git a/extension/Makefile.in b/extension/Makefile.in index 4c148361..e9dfd200 100644 --- a/extension/Makefile.in +++ b/extension/Makefile.in @@ -186,6 +186,13 @@ inplace_la_OBJECTS = $(am_inplace_la_OBJECTS) inplace_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(inplace_la_LDFLAGS) $(LDFLAGS) -o $@ +nl_langinfo_la_DEPENDENCIES = $(am__DEPENDENCIES_1) +am_nl_langinfo_la_OBJECTS = nl_langinfo.lo +nl_langinfo_la_OBJECTS = $(am_nl_langinfo_la_OBJECTS) +nl_langinfo_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(AM_CFLAGS) $(CFLAGS) $(nl_langinfo_la_LDFLAGS) $(LDFLAGS) -o \ + $@ ordchr_la_DEPENDENCIES = $(am__DEPENDENCIES_1) am_ordchr_la_OBJECTS = ordchr.lo ordchr_la_OBJECTS = $(am_ordchr_la_OBJECTS) @@ -269,12 +276,14 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = SOURCES = $(filefuncs_la_SOURCES) $(fnmatch_la_SOURCES) \ - $(fork_la_SOURCES) $(inplace_la_SOURCES) $(ordchr_la_SOURCES) \ + $(fork_la_SOURCES) $(inplace_la_SOURCES) \ + $(nl_langinfo_la_SOURCES) $(ordchr_la_SOURCES) \ $(readdir_la_SOURCES) $(readfile_la_SOURCES) \ $(revoutput_la_SOURCES) $(revtwoway_la_SOURCES) \ $(rwarray_la_SOURCES) $(testext_la_SOURCES) $(time_la_SOURCES) DIST_SOURCES = $(filefuncs_la_SOURCES) $(fnmatch_la_SOURCES) \ - $(fork_la_SOURCES) $(inplace_la_SOURCES) $(ordchr_la_SOURCES) \ + $(fork_la_SOURCES) $(inplace_la_SOURCES) \ + $(nl_langinfo_la_SOURCES) $(ordchr_la_SOURCES) \ $(readdir_la_SOURCES) $(readfile_la_SOURCES) \ $(revoutput_la_SOURCES) $(revtwoway_la_SOURCES) \ $(rwarray_la_SOURCES) $(testext_la_SOURCES) $(time_la_SOURCES) @@ -510,6 +519,7 @@ pkgextension_LTLIBRARIES = \ fnmatch.la \ fork.la \ inplace.la \ + nl_langinfo.la \ ordchr.la \ readdir.la \ readfile.la \ @@ -536,6 +546,9 @@ fork_la_LIBADD = $(MY_LIBS) inplace_la_SOURCES = inplace.c inplace_la_LDFLAGS = $(MY_MODULE_FLAGS) inplace_la_LIBADD = $(MY_LIBS) +nl_langinfo_la_SOURCES = nl_langinfo.c +nl_langinfo_la_LDFLAGS = $(MY_MODULE_FLAGS) +nl_langinfo_la_LIBADD = $(MY_LIBS) ordchr_la_SOURCES = ordchr.c ordchr_la_LDFLAGS = $(MY_MODULE_FLAGS) ordchr_la_LIBADD = $(MY_LIBS) @@ -676,6 +689,9 @@ fork.la: $(fork_la_OBJECTS) $(fork_la_DEPENDENCIES) $(EXTRA_fork_la_DEPENDENCIES inplace.la: $(inplace_la_OBJECTS) $(inplace_la_DEPENDENCIES) $(EXTRA_inplace_la_DEPENDENCIES) $(AM_V_CCLD)$(inplace_la_LINK) -rpath $(pkgextensiondir) $(inplace_la_OBJECTS) $(inplace_la_LIBADD) $(LIBS) +nl_langinfo.la: $(nl_langinfo_la_OBJECTS) $(nl_langinfo_la_DEPENDENCIES) $(EXTRA_nl_langinfo_la_DEPENDENCIES) + $(AM_V_CCLD)$(nl_langinfo_la_LINK) -rpath $(pkgextensiondir) $(nl_langinfo_la_OBJECTS) $(nl_langinfo_la_LIBADD) $(LIBS) + ordchr.la: $(ordchr_la_OBJECTS) $(ordchr_la_DEPENDENCIES) $(EXTRA_ordchr_la_DEPENDENCIES) $(AM_V_CCLD)$(ordchr_la_LINK) -rpath $(pkgextensiondir) $(ordchr_la_OBJECTS) $(ordchr_la_LIBADD) $(LIBS) @@ -711,6 +727,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fork.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gawkfts.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inplace.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nl_langinfo.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordchr.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readdir.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readfile.Plo@am__quote@ diff --git a/extension/configh.in b/extension/configh.in index d3f7361e..4b2ff462 100644 --- a/extension/configh.in +++ b/extension/configh.in @@ -45,6 +45,9 @@ /* Define to 1 if you have the <inttypes.h> header file. */ #undef HAVE_INTTYPES_H +/* Define to 1 if you have the <langinfo.h> header file. */ +#undef HAVE_LANGINFO_H + /* Define to 1 if you have the <limits.h> header file. */ #undef HAVE_LIMITS_H diff --git a/extension/configure b/extension/configure index 3a89c9ab..dac13944 100755 --- a/extension/configure +++ b/extension/configure @@ -12509,7 +12509,7 @@ else $as_echo "no" >&6; } fi -for ac_header in fnmatch.h limits.h sys/time.h sys/select.h sys/param.h +for ac_header in fnmatch.h limits.h langinfo.h sys/time.h sys/select.h sys/param.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" diff --git a/extension/configure.ac b/extension/configure.ac index 4da226a1..139f055a 100644 --- a/extension/configure.ac +++ b/extension/configure.ac @@ -63,7 +63,7 @@ else AC_MSG_RESULT([no]) fi -AC_CHECK_HEADERS(fnmatch.h limits.h sys/time.h sys/select.h sys/param.h) +AC_CHECK_HEADERS(fnmatch.h limits.h langinfo.h sys/time.h sys/select.h sys/param.h) AC_HEADER_DIRENT AC_HEADER_MAJOR AC_HEADER_TIME diff --git a/extension/nl_langinfo.awk b/extension/nl_langinfo.awk new file mode 100644 index 00000000..641cba19 --- /dev/null +++ b/extension/nl_langinfo.awk @@ -0,0 +1,6 @@ +@load "nl_langinfo" + +BEGIN { + for (i in LANGINFO) + print i, LANGINFO[i], nl_langinfo(LANGINFO[i]) +} diff --git a/extension/nl_langinfo.c b/extension/nl_langinfo.c new file mode 100644 index 00000000..e918fb9d --- /dev/null +++ b/extension/nl_langinfo.c @@ -0,0 +1,201 @@ +/* + * nl_langinfo.c - Provide an interface to nl_langinfo(3) routine + * + * Arnold Robbins + * arnold@skeeve.com + * Written 5/2015, cloned off fnmatch.c. + */ + +/* + * Copyright (C) 2012, 2013, 2015 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 <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 + +#define _GNU_SOURCE 1 /* use GNU extensions if they're there */ + +#ifdef HAVE_LANGINFO_H +#include <langinfo.h> +#endif + +static const gawk_api_t *api; /* for convenience macros to work */ +static awk_ext_id_t *ext_id; +static const char *ext_version = "nl_langinfo extension: version 1.0"; + +static awk_bool_t init_nl_langinfo(void); +static awk_bool_t (*init_func)(void) = init_nl_langinfo; + +int plugin_is_GPL_compatible; + + +/* do_nl_langinfo --- implement the nl_langinfo interface */ + +static awk_value_t * +do_nl_langinfo(int nargs, awk_value_t *result) +{ + awk_value_t val_to_get; + char *val; + +#ifdef HAVE_LANGINFO_H + make_null_string(result); /* default return */ + if (nargs < 1) { + warning(ext_id, _("nl_langinfo: called with no arguments")); + goto out; + } else if (do_lint && nargs > 1) + lintwarn(ext_id, _("nl_langinfo: called with more than one argument")); + + if (! get_argument(0, AWK_NUMBER, & val_to_get)) { + warning(ext_id, _("nl_langinfo: could not get argument")); + goto out; + } + + val = nl_langinfo((nl_item) val_to_get.num_value); + + /* DO THE STUFF HERE */ + make_const_string(val, strlen(val), result); +out: +#else + fatal(ext_id, _("nl_langinfo is not implemented on this system\n")); +#endif + return result; +} + +#define ENTRY(x) { #x, x } + +static struct langinfo_flags { + const char *name; + int value; +} flagtable[] = { + ENTRY(CODESET), + ENTRY(D_T_FMT), + ENTRY(D_FMT), + ENTRY(T_FMT), + ENTRY(T_FMT_AMPM), + ENTRY(AM_STR), + ENTRY(PM_STR), + ENTRY(DAY_1), + ENTRY(DAY_2), + ENTRY(DAY_3), + ENTRY(DAY_4), + ENTRY(DAY_5), + ENTRY(DAY_6), + ENTRY(DAY_7), + ENTRY(ABDAY_1), + ENTRY(ABDAY_2), + ENTRY(ABDAY_3), + ENTRY(ABDAY_4), + ENTRY(ABDAY_5), + ENTRY(ABDAY_6), + ENTRY(ABDAY_7), + ENTRY(MON_1), + ENTRY(MON_2), + ENTRY(MON_3), + ENTRY(MON_4), + ENTRY(MON_5), + ENTRY(MON_6), + ENTRY(MON_7), + ENTRY(MON_8), + ENTRY(MON_9), + ENTRY(MON_10), + ENTRY(MON_11), + ENTRY(MON_12), + ENTRY(ABMON_1), + ENTRY(ABMON_2), + ENTRY(ABMON_3), + ENTRY(ABMON_4), + ENTRY(ABMON_5), + ENTRY(ABMON_6), + ENTRY(ABMON_7), + ENTRY(ABMON_8), + ENTRY(ABMON_9), + ENTRY(ABMON_10), + ENTRY(ABMON_11), + ENTRY(ABMON_12), + ENTRY(RADIXCHAR), + ENTRY(ERA), + ENTRY(ERA_D_FMT), + ENTRY(ERA_D_T_FMT), + ENTRY(ERA_T_FMT), + ENTRY(ALT_DIGITS), + ENTRY(THOUSEP), + ENTRY(YESEXPR), + ENTRY(NOEXPR), + ENTRY(CRNCYSTR), + { NULL, 0 } +}; + +/* init_nl_langinfo --- load array with flags */ + +static awk_bool_t +init_nl_langinfo(void) +{ + int errors = 0; +#ifdef HAVE_LANGINFO_H + awk_value_t index, value, the_array; + awk_array_t new_array; + int i; + + new_array = create_array(); + for (i = 0; flagtable[i].name != NULL; i++) { + (void) make_const_string(flagtable[i].name, + strlen(flagtable[i].name), & index); + (void) make_number(flagtable[i].value, & value); + if (! set_array_element(new_array, & index, & value)) { + warning(ext_id, _("nl_langinfo init: could not set array element %s"), + flagtable[i].name); + errors++; + } + } + + the_array.val_type = AWK_ARRAY; + the_array.array_cookie = new_array; + + if (! sym_update("LANGINFO", & the_array)) { + warning(ext_id, _("nl_langinfo init: could not install LANGINFO array")); + errors++; + } + +#endif + return errors == 0; +} + +static awk_ext_func_t func_table[] = { + { "nl_langinfo", do_nl_langinfo, 3 }, +}; + +/* define the dl_load function using the boilerplate macro */ + +dl_load_func(func_table, nl_langinfo, "") |