[fc-match/fc-list/fc-query/fc-scan] Add --brief that is like --verbose without charset

This commit is contained in:
Behdad Esfahbod 2017-09-15 01:11:34 -04:00
parent dc8326d3f1
commit 2a41738fd7
4 changed files with 66 additions and 16 deletions

View File

@ -49,6 +49,7 @@
#include <getopt.h>
const struct option longopts[] = {
{"verbose", 0, 0, 'v'},
{"brief", 0, 0, 'b'},
{"format", 1, 0, 'f'},
{"quiet", 0, 0, 'q'},
{"version", 0, 0, 'V'},
@ -67,22 +68,24 @@ usage (char *program, int error)
{
FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
fprintf (file, "usage: %s [-vqVh] [-f FORMAT] [--verbose] [--format=FORMAT] [--quiet] [--version] [--help] [pattern] {element ...} \n",
fprintf (file, "usage: %s [-vbqVh] [-f FORMAT] [--verbose] [--brief] [--format=FORMAT] [--quiet] [--version] [--help] [pattern] {element ...} \n",
program);
#else
fprintf (file, "usage: %s [-vqVh] [-f FORMAT] [pattern] {element ...} \n",
fprintf (file, "usage: %s [-vbqVh] [-f FORMAT] [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 verbosely\n");
fprintf (file, " -b, --brief display entire font pattern briefly\n");
fprintf (file, " -f, --format=FORMAT use the given output format\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 verbosely\n");
fprintf (file, " -b (brief) display entire font pattern briefly\n");
fprintf (file, " -f FORMAT (format) use the given output format\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");
@ -95,6 +98,7 @@ int
main (int argc, char **argv)
{
int verbose = 0;
int brief = 0;
int quiet = 0;
const FcChar8 *format = NULL;
int nfont = 0;
@ -106,15 +110,18 @@ main (int argc, char **argv)
int c;
#if HAVE_GETOPT_LONG
while ((c = getopt_long (argc, argv, "vf:qVh", longopts, NULL)) != -1)
while ((c = getopt_long (argc, argv, "vbf:qVh", longopts, NULL)) != -1)
#else
while ((c = getopt (argc, argv, "vf:qVh")) != -1)
while ((c = getopt (argc, argv, "vbf:qVh")) != -1)
#endif
{
switch (c) {
case 'v':
verbose = 1;
break;
case 'b':
brief = 1;
break;
case 'f':
format = (FcChar8 *) strdup (optarg);
break;
@ -155,7 +162,7 @@ main (int argc, char **argv)
pat = FcPatternCreate ();
if (quiet && !os)
os = FcObjectSetCreate ();
if (!verbose && !format && !os)
if (!verbose && !brief && !format && !os)
os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, FC_FILE, (char *) 0);
if (!format)
format = (const FcChar8 *) "%{=fclist}\n";
@ -171,8 +178,13 @@ main (int argc, char **argv)
for (j = 0; j < fs->nfont; j++)
{
if (verbose)
if (verbose || brief)
{
if (brief)
{
FcPatternDel (fs->fonts[j], FC_CHARSET);
FcPatternDel (fs->fonts[j], FC_LANG);
}
FcPatternPrint (fs->fonts[j]);
}
else

View File

@ -52,6 +52,7 @@ static const struct option longopts[] = {
{"sort", 0, 0, 's'},
{"all", 0, 0, 'a'},
{"verbose", 0, 0, 'v'},
{"brief", 0, 0, 'b'},
{"format", 1, 0, 'f'},
{"version", 0, 0, 'V'},
{"help", 0, 0, 'h'},
@ -69,7 +70,7 @@ usage (char *program, int error)
{
FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
fprintf (file, "usage: %s [-savVh] [-f FORMAT] [--sort] [--all] [--verbose] [--format=FORMAT] [--version] [--help] [pattern] {element...}\n",
fprintf (file, "usage: %s [-savbVh] [-f FORMAT] [--sort] [--all] [--verbose] [--brief] [--format=FORMAT] [--version] [--help] [pattern] {element...}\n",
program);
#else
fprintf (file, "usage: %s [-savVh] [-f FORMAT] [pattern] {element...}\n",
@ -81,6 +82,7 @@ usage (char *program, int error)
fprintf (file, " -s, --sort display sorted list of matches\n");
fprintf (file, " -a, --all display unpruned sorted list of matches\n");
fprintf (file, " -v, --verbose display entire font pattern verbosely\n");
fprintf (file, " -b, --brief display entire font pattern briefly\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");
@ -88,6 +90,7 @@ usage (char *program, int error)
fprintf (file, " -s, (sort) display sorted list of matches\n");
fprintf (file, " -a (all) display unpruned sorted list of matches\n");
fprintf (file, " -v (verbose) display entire font pattern verbosely\n");
fprintf (file, " -b (brief) display entire font pattern briefly\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");
@ -99,6 +102,7 @@ int
main (int argc, char **argv)
{
int verbose = 0;
int brief = 0;
int sort = 0, all = 0;
const FcChar8 *format = NULL;
int i;
@ -110,9 +114,9 @@ main (int argc, char **argv)
int c;
#if HAVE_GETOPT_LONG
while ((c = getopt_long (argc, argv, "asvf:Vh", longopts, NULL)) != -1)
while ((c = getopt_long (argc, argv, "asvbf:Vh", longopts, NULL)) != -1)
#else
while ((c = getopt (argc, argv, "asvf:Vh")) != -1)
while ((c = getopt (argc, argv, "asvbf:Vh")) != -1)
#endif
{
switch (c) {
@ -125,6 +129,9 @@ main (int argc, char **argv)
case 'v':
verbose = 1;
break;
case 'b':
brief = 1;
break;
case 'f':
format = (FcChar8 *) strdup (optarg);
break;
@ -218,8 +225,13 @@ main (int argc, char **argv)
font = FcPatternFilter (fs->fonts[j], os);
if (verbose)
if (verbose || brief)
{
if (brief)
{
FcPatternDel (font, FC_CHARSET);
FcPatternDel (font, FC_LANG);
}
FcPatternPrint (font);
}
else

View File

@ -53,6 +53,7 @@
#include <getopt.h>
static const struct option longopts[] = {
{"index", 1, 0, 'i'},
{"brief", 0, 0, 'b'},
{"format", 1, 0, 'f'},
{"version", 0, 0, 'V'},
{"help", 0, 0, 'h'},
@ -70,21 +71,23 @@ usage (char *program, int error)
{
FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
fprintf (file, "usage: %s [-Vh] [-i index] [-f FORMAT] [--index index] [--format FORMAT] [--version] [--help] font-file...\n",
fprintf (file, "usage: %s [-bVh] [-i index] [-f FORMAT] [--index index] [--brief] [--format FORMAT] [--version] [--help] font-file...\n",
program);
#else
fprintf (file, "usage: %s [-Vh] [-i index] [-f FORMAT] font-file...\n",
fprintf (file, "usage: %s [-bVh] [-i index] [-f FORMAT] font-file...\n",
program);
#endif
fprintf (file, "Query font files and print resulting pattern(s)\n");
fprintf (file, "\n");
#if HAVE_GETOPT_LONG
fprintf (file, " -i, --index INDEX display the INDEX face of each font file only\n");
fprintf (file, " -b, --brief display font pattern briefly\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, " -i INDEX (index) display the INDEX face of each font file only\n");
fprintf (file, " -b (brief) display font pattern briefly\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");
@ -96,6 +99,7 @@ int
main (int argc, char **argv)
{
unsigned int id = (unsigned int) -1;
int brief = 0;
FcFontSet *fs;
FcChar8 *format = NULL;
int err = 0;
@ -104,15 +108,18 @@ main (int argc, char **argv)
int c;
#if HAVE_GETOPT_LONG
while ((c = getopt_long (argc, argv, "i:f:Vh", longopts, NULL)) != -1)
while ((c = getopt_long (argc, argv, "i:bf:Vh", longopts, NULL)) != -1)
#else
while ((c = getopt (argc, argv, "i:f:Vh")) != -1)
while ((c = getopt (argc, argv, "i:bf:Vh")) != -1)
#endif
{
switch (c) {
case 'i':
id = (unsigned int) strtol (optarg, NULL, 0); /* strtol() To handle -1. */
break;
case 'b':
brief = 1;
break;
case 'f':
format = (FcChar8 *) strdup (optarg);
break;
@ -149,6 +156,12 @@ main (int argc, char **argv)
{
FcPattern *pat = fs->fonts[i];
if (brief)
{
FcPatternDel (pat, FC_CHARSET);
FcPatternDel (pat, FC_LANG);
}
if (format)
{
FcChar8 *s;

View File

@ -52,6 +52,7 @@
#define _GNU_SOURCE
#include <getopt.h>
static const struct option longopts[] = {
{"brief", 0, 0, 'b'},
{"format", 1, 0, 'f'},
{"version", 0, 0, 'V'},
{"help", 0, 0, 'h'},
@ -69,19 +70,21 @@ usage (char *program, int error)
{
FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG
fprintf (file, "usage: %s [-Vh] [-f FORMAT] [--format FORMAT] [--version] [--help] font-file...\n",
fprintf (file, "usage: %s [-bVh] [-f FORMAT] [--brief] [--format FORMAT] [--version] [--help] font-file...\n",
program);
#else
fprintf (file, "usage: %s [-Vh] [-f FORMAT] font-file...\n",
fprintf (file, "usage: %s [-bVh] [-f FORMAT] font-file...\n",
program);
#endif
fprintf (file, "Scan font files and directories, and print resulting pattern(s)\n");
fprintf (file, "\n");
#if HAVE_GETOPT_LONG
fprintf (file, " -b, --brief display font pattern briefly\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, " -b (brief) display font pattern briefly\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");
@ -92,6 +95,7 @@ usage (char *program, int error)
int
main (int argc, char **argv)
{
int brief = 0;
FcChar8 *format = NULL;
int i;
FcFontSet *fs;
@ -105,6 +109,9 @@ main (int argc, char **argv)
#endif
{
switch (c) {
case 'b':
brief = 1;
break;
case 'f':
format = (FcChar8 *) strdup (optarg);
break;
@ -152,6 +159,12 @@ main (int argc, char **argv)
{
FcPattern *pat = fs->fonts[i];
if (brief)
{
FcPatternDel (pat, FC_CHARSET);
FcPatternDel (pat, FC_LANG);
}
if (format)
{
FcChar8 *s;