#include "readline.h"
#include "cdecl.h"
+#define N_(x) x
+#define PN_(c, x) x
+
static const char *progname = "cdecl99";
static const char sopts[] = "qbif:e:VH";
-static const struct option lopts[] = {
- { "quiet", 0, NULL, 'q' },
- { "batch", 0, NULL, 'b' },
- { "interactive", 0, NULL, 'i' },
- { "file", 1, NULL, 'f' },
- { "execute", 1, NULL, 'e' },
- { "version", 0, NULL, 'V' },
- { "help", 0, NULL, 'H' },
- { 0 }
-};
+#define RAW_LOPTS \
+ { PN_("longopt", "quiet"), 0, NULL, 'q' }, \
+ { PN_("longopt", "batch"), 0, NULL, 'b' }, \
+ { PN_("longopt", "interactive"), 0, NULL, 'i' }, \
+ { PN_("longopt", "file"), 1, NULL, 'f' }, \
+ { PN_("longopt", "execute"), 1, NULL, 'e' }, \
+ { PN_("longopt", "version"), 0, NULL, 'V' }, \
+ { PN_("longopt", "help"), 0, NULL, 'H' }
+
+/*
+ * With NLS, we need a buffer big enough to store the translated options.
+ * The translations will be filled in at program startup.
+ */
+enum { NOPTS = sizeof (struct option[]){RAW_LOPTS} / sizeof (struct option) };
+static struct option lopts[NOPTS + !!ENABLE_NLS * NOPTS + 1] = { RAW_LOPTS };
static void print_version(void)
{
return ret;
}
+/* Initialize gettext and setup translated long options. */
+static void init_i18n(void)
+{
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+
+ if (!ENABLE_NLS)
+ return;
+
+ for (int i = 0; i < NOPTS; i++) {
+ lopts[i+NOPTS] = lopts[i];
+ lopts[i+NOPTS].name = pgettext_expr("longopt", lopts[i].name);
+ }
+}
+
int main(int argc, char **argv)
{
bool show_intro = true, interactive = true, execute = false;
if (argc > 0)
progname = argv[0];
- /* Initialize gettext. */
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
+ init_i18n();
while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
switch (opt) {