summaryrefslogtreecommitdiff
path: root/fc-list
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2008-12-28 04:58:14 -0500
committerBehdad Esfahbod <behdad@behdad.org>2009-02-13 16:54:02 -0800
commitf26062b277e1781876a30d3170fca8bbba2409ab (patch)
tree8062e3f518c983e095b9c6d6ab0e0f066afcc641 /fc-list
parent00c0972acae849ca3b18a7c76894c078185d3be4 (diff)
Implement fc-list --quiet ala grep (bug #17141)
Exits 1 if no fonts matched, 0 otherwise.
Diffstat (limited to 'fc-list')
-rw-r--r--fc-list/fc-list.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/fc-list/fc-list.c b/fc-list/fc-list.c
index 97baea4c..89f4167b 100644
--- a/fc-list/fc-list.c
+++ b/fc-list/fc-list.c
@@ -49,6 +49,7 @@
const struct option longopts[] = {
{"version", 0, 0, 'V'},
{"verbose", 0, 0, 'v'},
+ {"quiet", 0, 0, 'q'},
{"help", 0, 0, 'h'},
{NULL,0,0,0},
};
@@ -64,20 +65,22 @@ usage (char *program, int error)
{
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
@@ -88,6 +91,8 @@ int
main (int argc, char **argv)
{
int verbose = 0;
+ int quiet = 0;
+ int nfont = 0;
int i;
FcObjectSet *os = 0;
FcFontSet *fs;
@@ -96,9 +101,9 @@ main (int argc, char **argv)
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) {
@@ -109,6 +114,9 @@ main (int argc, char **argv)
case 'v':
verbose = 1;
break;
+ case 'q':
+ quiet = 1;
+ break;
case 'h':
usage (argv[0], 0);
default:
@@ -138,7 +146,8 @@ main (int argc, char **argv)
}
else
pat = FcPatternCreate ();
-
+ if (quiet && !os)
+ os = FcObjectSetCreate ();
if (!verbose && !os)
os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
fs = FcFontList (0, pat, os);
@@ -147,7 +156,7 @@ main (int argc, char **argv)
if (pat)
FcPatternDestroy (pat);
- if (fs)
+ if (!quiet && fs)
{
int j;
@@ -167,10 +176,14 @@ main (int argc, char **argv)
free (font);
}
}
+ }
+
+ if (fs) {
+ nfont = fs->nfont;
FcFontSetDestroy (fs);
}
FcFini ();
- return 0;
+ return quiet ? (nfont == 0 ? 1 : 0) : 0;
}