]> git.draconx.ca Git - cdecl99.git/commitdiff
Enable i18n in Bison.
authorNick Bowler <nbowler@draconx.ca>
Thu, 15 Sep 2011 01:10:19 +0000 (21:10 -0400)
committerNick Bowler <nbowler@draconx.ca>
Wed, 21 Sep 2011 23:25:04 +0000 (19:25 -0400)
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.

.gitignore
Makefile.am
configure.ac
doc/man/libcdecl.3
m4/.gitignore
m4/gnulib-cache.m4
src/i18n.c [new file with mode: 0644]
src/i18n.h [new file with mode: 0644]
src/parse-decl.c
src/parse.y

index fca2b495c70bbdf6aaf0eb22649e721276ba8bcb..cfb9fa62d0d4aaba7d20bd123a5830adfed0fc3b 100644 (file)
@@ -15,6 +15,7 @@ Makefile.in
 /ltmain.sh
 /depcomp
 /missing
+/compile
 /stamp-h1
 /install-sh
 /arg-nonnull.h
index a63842203eef7d2726f2f337f3a0cc41690477e5..094c3099a297c3189a32680d8b1a421795e03136 100644 (file)
@@ -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
index 575244131ef74155aa49742c46ba98428fa969dc..103bae2253fe0caa874c87fdadef91f958d32f23 100644 (file)
@@ -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
index 7b6c791da7df8a50e44b80e80cddfc26a26a41d0..97fc41a568bf19c99bcc9f11078e67030c470366 100644 (file)
@@ -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
index b75134eb37a99a24ff3b9f6d2b9c81ea0d0d5a40..c23c58be18b5385b9110d22abb07748d82c64b9c 100644 (file)
@@ -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
index ce8339da08b10a559776ba4288032cf095d840e6..6acb89f9d2aa6b4d8e469deab9e11ad809521c71 100644 (file)
 
 
 # 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 (file)
index 0000000..9e64252
--- /dev/null
@@ -0,0 +1,20 @@
+#include <config.h>
+#include <stdio.h>
+#include <assert.h>
+#include <glthread/lock.h>
+#include <gettext.h>
+#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 (file)
index 0000000..e1b5503
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef CDECL_I18N_H_
+#define CDECL_I18N_H_
+
+#include <gettext.h>
+
+#define _(s) dgettext(PACKAGE, s)
+#define N_(s) s
+
+void cdecl__init_i18n(void);
+
+#endif
index 3ffb1029ae181b596da102f367130f5f84bd83c4..dc187c00b00c440eb5b059781b376f4e3ffdf712 100644 (file)
@@ -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;
index cd88d2fa6bef511810561fba32a941802b63b465..f90013a44c458989e890dde1c04a323b5176676f 100644 (file)
@@ -27,6 +27,7 @@
 %locations
 
 %{
+#include <config.h>
 #include <assert.h>
 #include <stdbool.h>