Imported Upstream version 2.14.2
[platform/upstream/fontconfig.git] / fc-pattern / fc-pattern.c
index 3f066c1..1e9b1ba 100644 (file)
 
 #include <fontconfig/fontconfig.h>
 #include <stdio.h>
-#include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
+#include <locale.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef ENABLE_NLS
+#include <libintl.h>
+#define _(x)           (dgettext(GETTEXT_PACKAGE, x))
+#else
+#define dgettext(d, s) (s)
+#define _(x)           (x)
+#endif
 
 #ifndef HAVE_GETOPT
 #define HAVE_GETOPT 0
@@ -68,26 +80,26 @@ usage (char *program, int error)
 {
     FILE *file = error ? stderr : stdout;
 #if HAVE_GETOPT_LONG
-    fprintf (file, "usage: %s [-cdVh] [-f FORMAT] [--config] [--default] [--verbose] [--format=FORMAT] [--version] [--help] [pattern] {element...}\n",
+    fprintf (file, _("usage: %s [-cdVh] [-f FORMAT] [--config] [--default] [--verbose] [--format=FORMAT] [--version] [--help] [pattern] {element...}\n"),
             program);
 #else
-    fprintf (file, "usage: %s [-cdVh] [-f FORMAT] [pattern] {element...}\n",
+    fprintf (file, _("usage: %s [-cdVh] [-f FORMAT] [pattern] {element...}\n"),
             program);
 #endif
-    fprintf (file, "List best font matching [pattern]\n");
+    fprintf (file, _("List best font matching [pattern]\n"));
     fprintf (file, "\n");
 #if HAVE_GETOPT_LONG
-    fprintf (file, "  -c, --config         perform config substitution on pattern\n");
-    fprintf (file, "  -d, -default         perform default substitution on pattern\n");
-    fprintf (file, "  -f, --format=FORMAT  use the given output format\n");
-    fprintf (file, "  -V, --version        display font config version and exit\n");
-    fprintf (file, "  -h, --help           display this help and exit\n");
+    fprintf (file, _("  -c, --config         perform config substitution on pattern\n"));
+    fprintf (file, _("  -d, --default        perform default substitution on pattern\n"));
+    fprintf (file, _("  -f, --format=FORMAT  use the given output format\n"));
+    fprintf (file, _("  -V, --version        display font config version and exit\n"));
+    fprintf (file, _("  -h, --help           display this help and exit\n"));
 #else
-    fprintf (file, "  -c,        (config)  perform config substitution on pattern\n");
-    fprintf (file, "  -d,        (default) perform default substitution on pattern\n");
-    fprintf (file, "  -f FORMAT  (format)  use the given output format\n");
-    fprintf (file, "  -V         (version) display font config version and exit\n");
-    fprintf (file, "  -h         (help)    display this help and exit\n");
+    fprintf (file, _("  -c,        (config)  perform config substitution on pattern\n"));
+    fprintf (file, _("  -d,        (default) perform default substitution on pattern\n"));
+    fprintf (file, _("  -f FORMAT  (format)  use the given output format\n"));
+    fprintf (file, _("  -V         (version) display font config version and exit\n"));
+    fprintf (file, _("  -h         (help)    display this help and exit\n"));
 #endif
     exit (error);
 }
@@ -103,6 +115,7 @@ main (int argc, char **argv)
 #if HAVE_GETOPT_LONG || HAVE_GETOPT
     int                c;
 
+    setlocale (LC_ALL, "");
 #if HAVE_GETOPT_LONG
     while ((c = getopt_long (argc, argv, "cdf:Vh", longopts, NULL)) != -1)
 #else
@@ -137,6 +150,11 @@ main (int argc, char **argv)
     if (argv[i])
     {
        pat = FcNameParse ((FcChar8 *) argv[i]);
+       if (!pat)
+       {
+           fprintf (stderr, _("Unable to parse the pattern\n"));
+           return 1;
+       }
        while (argv[++i])
        {
            if (!os)