Imported Upstream version 2.13.0
[platform/upstream/fontconfig.git] / fc-cat / fc-cat.c
index f0131b6..dfe30d7 100644 (file)
 #include <sys/stat.h>
 #include <errno.h>
 
+#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
 #endif
@@ -148,27 +156,27 @@ usage (char *program, int error)
 {
     FILE *file = error ? stderr : stdout;
 #if HAVE_GETOPT_LONG
-    fprintf (file, "usage: %s [-rv] [--recurse] [--verbose] [*-%s" FC_CACHE_SUFFIX "|directory]...\n",
+    fprintf (file, _("usage: %s [-rv] [--recurse] [--verbose] [*-%s" FC_CACHE_SUFFIX "|directory]...\n"),
             program, FC_ARCHITECTURE);
     fprintf (file, "       %s [-Vh] [--version] [--help]\n", program);
 #else
-    fprintf (file, "usage: %s [-rvVh] [*-%s" FC_CACHE_SUFFIX "|directory]...\n",
+    fprintf (file, _("usage: %s [-rvVh] [*-%s" FC_CACHE_SUFFIX "|directory]...\n"),
             program, FC_ARCHITECTURE);
 #endif
-    fprintf (file, "Reads font information cache from:\n");
-    fprintf (file, " 1) specified fontconfig cache file\n");
-    fprintf (file, " 2) related to a particular font directory\n");
+    fprintf (file, _("Reads font information cache from:\n"));
+    fprintf (file, _(" 1) specified fontconfig cache file\n"));
+    fprintf (file, _(" 2) related to a particular font directory\n"));
     fprintf (file, "\n");
 #if HAVE_GETOPT_LONG
-    fprintf (file, "  -r, --recurse        recurse into subdirectories\n");
-    fprintf (file, "  -v, --verbose        be verbose\n");
-    fprintf (file, "  -V, --version        display font config version and exit\n");
-    fprintf (file, "  -h, --help           display this help and exit\n");
+    fprintf (file, _("  -r, --recurse        recurse into subdirectories\n"));
+    fprintf (file, _("  -v, --verbose        be verbose\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, "  -r         (recurse) recurse into subdirectories\n");
-    fprintf (file, "  -v         (verbose) be verbose\n");
-    fprintf (file, "  -V         (version) display font config version and exit\n");
-    fprintf (file, "  -h         (help)    display this help and exit\n");
+    fprintf (file, _("  -r         (recurse) recurse into subdirectories\n"));
+    fprintf (file, _("  -v         (verbose) be verbose\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);
 }
@@ -294,7 +302,7 @@ main (int argc, char **argv)
     config = FcInitLoadConfig ();
     if (!config)
     {
-       fprintf (stderr, "%s: Can't init font config library\n", argv[0]);
+       fprintf (stderr, _("%s: Can't initialize font config library\n"), argv[0]);
        return 1;
     }
     FcConfigSetCurrent (config);
@@ -303,7 +311,7 @@ main (int argc, char **argv)
     args = FcStrSetCreate ();
     if (!args)
     {
-       fprintf (stderr, "%s: malloc failure\n", argv[0]);
+       fprintf (stderr, _("%s: malloc failure\n"), argv[0]);
        return 1;
     }
     if (i < argc)
@@ -312,7 +320,7 @@ main (int argc, char **argv)
        {
            if (!FcStrSetAddFilename (args, (const FcChar8 *) argv[i]))
            {
-               fprintf (stderr, "%s: malloc failure\n", argv[0]);
+               fprintf (stderr, _("%s: malloc failure\n"), argv[0]);
                return 1;
            }
        }
@@ -324,7 +332,7 @@ main (int argc, char **argv)
        while ((arg = FcStrListNext (arglist)))
            if (!FcStrSetAdd (args, arg))
            {
-               fprintf (stderr, "%s: malloc failure\n", argv[0]);
+               fprintf (stderr, _("%s: malloc failure\n"), argv[0]);
                return 1;
            }
        FcStrListDone (arglist);
@@ -332,7 +340,7 @@ main (int argc, char **argv)
     arglist = FcStrListCreate (args);
     if (!arglist)
     {
-       fprintf (stderr, "%s: malloc failure\n", argv[0]);
+       fprintf (stderr, _("%s: malloc failure\n"), argv[0]);
        return 1;
     }
     FcStrSetDestroy (args);
@@ -342,14 +350,19 @@ main (int argc, char **argv)
        int         j;
        FcChar8     *cache_file = NULL;
        struct stat file_stat;
-       
+
+       /* reset errno */
+       errno = 0;
        if (FcFileIsDir (arg))
            cache = FcDirCacheLoad (arg, config, &cache_file);
        else
            cache = FcDirCacheLoadFile (arg, &file_stat);
        if (!cache)
        {
-           perror ((char *) arg);
+           if (errno != 0)
+               perror ((char *) arg);
+           else
+               fprintf (stderr, "%s: Unable to load the cache: %s\n", argv[0], arg);
            ret++;
            continue;
        }
@@ -367,7 +380,7 @@ main (int argc, char **argv)
        {
            if (!first)
                printf ("\n");
-           printf ("Directory: %s\nCache: %s\n--------\n",
+           printf (_("Directory: %s\nCache: %s\n--------\n"),
                    FcCacheDir(cache), cache_file ? cache_file : arg);
            first = FcFalse;
        }