From: Nick Bowler Date: Thu, 15 Sep 2011 01:10:19 +0000 (-0400) Subject: Enable i18n in Bison. X-Git-Tag: v1~110 X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/commitdiff_plain/0876ef2649dfc1d1c1fe86a0d56e9506806b37b9 Enable i18n in Bison. This makes us require library initialization. To avoid requiring an explicit call, we implicitly initialize the library when it is first required. Bring in Gnulib's threading library to do this in a thread-safe manner when available. --- diff --git a/.gitignore b/.gitignore index fca2b49..cfb9fa6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ Makefile.in /ltmain.sh /depcomp /missing +/compile /stamp-h1 /install-sh /arg-nonnull.h diff --git a/Makefile.am b/Makefile.am index a638422..094c309 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,6 +9,7 @@ ACLOCAL_AMFLAGS = -I m4 SUBDIRS = lib . AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src \ -I$(top_builddir)/lib -I$(top_srcdir)/lib \ + -DBISON_LOCALEDIR=\"$(BISON_LOCALEDIR)\" \ -DLOCALEDIR=\"$(localedir)\" MAINTAINERCLEANFILES = src/scan.c src/scan.h src/scan.stamp \ @@ -23,15 +24,15 @@ EXTRA_DIST = m4/gnulib-cache.m4 src/types.lst src/typenames.sed \ dist_man_MANS = doc/man/cdecl99.1 doc/man/libcdecl.3 include_HEADERS = src/cdecl.h -noinst_HEADERS = src/typemap.h src/output.h src/scan.h src/parse.h +noinst_HEADERS = src/typemap.h src/output.h src/scan.h src/parse.h src/i18n.h noinst_DATA = $(MOFILES) lib_LTLIBRARIES = libcdecl.la libcdecl_la_LDFLAGS = -export-symbols-regex '^cdecl_[[:lower:]]' libcdecl_la_SOURCES = src/scan.c src/parse.c src/parse-decl.c src/typemap.c \ - src/output.c src/explain.c src/declare.c -libcdecl_la_LIBADD = $(LTLIBINTL) + src/output.c src/explain.c src/declare.c src/i18n.c +libcdecl_la_LIBADD = $(LTLIBINTL) $(LTLIBTHREAD) bin_PROGRAMS = cdecl99 cdecl99_SOURCES = src/cdecl99.c diff --git a/configure.ac b/configure.ac index 5752441..103bae2 100644 --- a/configure.ac +++ b/configure.ac @@ -32,6 +32,7 @@ AC_CHECK_PROGS([FLEX], [flex], [flex]) AC_ARG_VAR([BISON], [Command to invoke GNU Bison. Defaults to bison.]) AC_ARG_VAR([BISONFLAGS], [Additional options to pass to Bison.]) AC_CHECK_PROGS([BISON], [bison], [bison]) +BISON_I18N AC_CONFIG_FILES([ lib/Makefile diff --git a/doc/man/libcdecl.3 b/doc/man/libcdecl.3 index 7b6c791..97fc41a 100644 --- a/doc/man/libcdecl.3 +++ b/doc/man/libcdecl.3 @@ -26,8 +26,8 @@ manual page. .Pp .Nm is intended to be portable to any system with a working C implementation that -at least makes an effort to support C99. The library maintains no global state -and thus all functions should be safe for use in a multi-threaded environment. +at least makes an effort to support C99. The library is thread-safe when +appropriate facilities exist and are enabled at build time. .Sh ABSTRACT SYNTAX TREE The functions in .Nm diff --git a/m4/.gitignore b/m4/.gitignore index b75134e..c23c58b 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -46,6 +46,7 @@ stdint.m4 stdint_h.m4 stdio_h.m4 stdlib_h.m4 +thread.m4 threadlib.m4 uintmax_t.m4 unistd_h.m4 diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 index ce8339d..6acb89f 100644 --- a/m4/gnulib-cache.m4 +++ b/m4/gnulib-cache.m4 @@ -15,13 +15,14 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --conditional-dependencies --libtool --macro-prefix=gl --no-vc-files getopt-gnu gettext readline +# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --conditional-dependencies --libtool --macro-prefix=gl --no-vc-files getopt-gnu gettext lock readline # Specification in the form of a few gnulib-tool.m4 macro invocations: gl_LOCAL_DIR([]) gl_MODULES([ getopt-gnu gettext + lock readline ]) gl_AVOID([]) diff --git a/src/i18n.c b/src/i18n.c new file mode 100644 index 0000000..9e64252 --- /dev/null +++ b/src/i18n.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include +#include "i18n.h" + +static void initialize(void) +{ + bindtextdomain(PACKAGE, LOCALEDIR); + bindtextdomain("bison-runtime", BISON_LOCALEDIR); +} + +void cdecl__init_i18n(void) +{ + gl_once_define(static, initialized); + + int err = glthread_once(&initialized, initialize); + assert(err == 0); +} diff --git a/src/i18n.h b/src/i18n.h new file mode 100644 index 0000000..e1b5503 --- /dev/null +++ b/src/i18n.h @@ -0,0 +1,11 @@ +#ifndef CDECL_I18N_H_ +#define CDECL_I18N_H_ + +#include + +#define _(s) dgettext(PACKAGE, s) +#define N_(s) s + +void cdecl__init_i18n(void); + +#endif diff --git a/src/parse-decl.c b/src/parse-decl.c index 3ffb102..dc187c0 100644 --- a/src/parse-decl.c +++ b/src/parse-decl.c @@ -23,6 +23,7 @@ #include "typemap.h" #include "parse.h" #include "scan.h" +#include "i18n.h" /* * Determine if a declarator declares an identifier (other than a function @@ -391,6 +392,8 @@ struct cdecl *cdecl_parse_decl(const char *declstr) struct cdecl *decl; int rc; + cdecl__init_i18n(); + rc = cdecl__yylex_init(&scanner); if (rc != 0) return NULL; @@ -437,6 +440,8 @@ struct cdecl *cdecl_parse_english(const char *english) struct cdecl *decl; int rc; + cdecl__init_i18n(); + rc = cdecl__yylex_init_extra(true, &scanner); if (rc != 0) return NULL; diff --git a/src/parse.y b/src/parse.y index cd88d2f..f90013a 100644 --- a/src/parse.y +++ b/src/parse.y @@ -27,6 +27,7 @@ %locations %{ +#include #include #include