+#include "cdecl-internal.h"
+#include "errmsg.h"
+
+/* This pre-initialized error is reserved for dire out-of-memory conditions. */
+static struct cdecl_error err_no_mem;
+
+static void set_err(unsigned code, struct cdecl_error *err)
+{
+ static const char _Alignas(1) errmsgs[] = STRTAB_INITIALIZER;
+
+ switch (code) {
+ case CDECL__ENOMEM:
+ err->code = CDECL_ENOMEM;
+ break;
+ default:
+ err->code = CDECL_ENOPARSE;
+ break;
+ }
+
+ err->str = _(&errmsgs[code]);
+}
+
+static void init_once_cb(void)
+{
+#if ENABLE_NLS
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ bindtextdomain("bison-runtime", BISON_LOCALEDIR);
+#endif
+ set_err(CDECL__ENOMEM, &err_no_mem);
+}
+
+#if USE_POSIX_THREADS
+# include "thread-posix.h"
+#elif USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS
+# include "thread-stdc.h"
+#elif USE_WINDOWS_THREADS
+# include "thread-w32.h"
+#else
+static void *tls_key;
+enum { tls_key_valid = 1 };
+
+#define tls_get() tls_key
+#define tls_set(a) ((tls_key = (a)), 1)
+
+static int init_once(void)
+{
+ if (!err_no_mem.code)
+ init_once_cb();
+ return 1;
+}