const struct option longopts[] = {
{"version", 0, 0, 'V'},
{"verbose", 0, 0, 'v'},
+ {"quiet", 0, 0, 'q'},
{"help", 0, 0, 'h'},
{NULL,0,0,0},
};
{
FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
- fprintf (file, "usage: %s [-vVh] [--verbose] [--version] [--help] [pattern] {element ...} \n",
+ fprintf (file, "usage: %s [-vqVh] [--verbose] [--quiet] [--version] [--help] [pattern] {element ...} \n",
program);
#else
- fprintf (file, "usage: %s [-vVh] [pattern] {element ...} \n",
+ fprintf (file, "usage: %s [-vqVh] [pattern] {element ...} \n",
program);
#endif
fprintf (file, "List fonts matching [pattern]\n");
fprintf (file, "\n");
#if HAVE_GETOPT_LONG
fprintf (file, " -v, --verbose display entire font pattern\n");
+ fprintf (file, " -q, --quiet suppress all normal output, exit 1 if no fonts matched\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, " -v (verbose) display entire font pattern\n");
+ fprintf (file, " -q, (quiet) suppress all normal output, exit 1 if no fonts matched\n");
fprintf (file, " -V (version) display font config version and exit\n");
fprintf (file, " -h (help) display this help and exit\n");
#endif
main (int argc, char **argv)
{
int verbose = 0;
+ int quiet = 0;
+ int nfont = 0;
int i;
FcObjectSet *os = 0;
FcFontSet *fs;
int c;
#if HAVE_GETOPT_LONG
- while ((c = getopt_long (argc, argv, "Vvh", longopts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "Vqvh", longopts, NULL)) != -1)
#else
- while ((c = getopt (argc, argv, "Vvh")) != -1)
+ while ((c = getopt (argc, argv, "Vqvh")) != -1)
#endif
{
switch (c) {
case 'v':
verbose = 1;
break;
+ case 'q':
+ quiet = 1;
+ break;
case 'h':
usage (argv[0], 0);
default:
}
else
pat = FcPatternCreate ();
-
+ if (quiet && !os)
+ os = FcObjectSetCreate ();
if (!verbose && !os)
os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
fs = FcFontList (0, pat, os);
if (pat)
FcPatternDestroy (pat);
- if (fs)
+ if (!quiet && fs)
{
int j;
free (font);
}
}
+ }
+
+ if (fs) {
+ nfont = fs->nfont;
FcFontSetDestroy (fs);
}
FcFini ();
- return 0;
+ return quiet ? (nfont == 0 ? 1 : 0) : 0;
}