X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;ds=inline;f=fc-query%2Ffc-query.c;h=f2693de59949ca2f285ebaa2fdc39d8adf4fd173;hb=247c4f3df21582260c4799bdbda2be1c13cc8901;hp=2a36bf0447f49cabbdd86a1eb6853ce3406c0f79;hpb=77c0d8bce86ca088782d5631617c0ef681d91312;p=fontconfig.git diff --git a/fc-query/fc-query.c b/fc-query/fc-query.c index 2a36bf0..f2693de 100644 --- a/fc-query/fc-query.c +++ b/fc-query/fc-query.c @@ -15,9 +15,9 @@ * representations about the suitability of this software for any purpose. It * is provided "as is" without express or implied warranty. * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR @@ -53,8 +53,9 @@ #include static const struct option longopts[] = { {"index", 1, 0, 'i'}, + {"format", 1, 0, 'f'}, {"version", 0, 0, 'V'}, - {"help", 0, 0, '?'}, + {"help", 0, 0, 'h'}, {NULL,0,0,0}, }; #else @@ -64,28 +65,31 @@ extern int optind, opterr, optopt; #endif #endif -static void usage (char *program) +static void +usage (char *program, int error) { + FILE *file = error ? stderr : stdout; #if HAVE_GETOPT_LONG - fprintf (stderr, "usage: %s [-V?] [-i index] [--index index] [--version] [--help] font-file...\n", + fprintf (file, "usage: %s [-Vh] [-i index] [-f FORMAT] [--index index] [--format FORMAT] [--version] [--help] font-file...\n", program); #else - fprintf (stderr, "usage: %s [-V?] [-i index] font-file...\n", + fprintf (file, "usage: %s [-Vh] [-i index] [-f FORMAT] font-file...\n", program); #endif - fprintf (stderr, "Query font files and print resulting pattern(s)\n"); - fprintf (stderr, "\n"); + fprintf (file, "Query font files and print resulting pattern(s)\n"); + fprintf (file, "\n"); #if HAVE_GETOPT_LONG - fprintf (stderr, " -i, --index INDEX display the INDEX face of each font file only\n"); - fprintf (stderr, " -V, --version display font config version and exit\n"); - fprintf (stderr, " -?, --help display this help and exit\n"); + fprintf (file, " -i, --index INDEX display the INDEX face of each font file only\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 (stderr, " -i INDEX (index) display the INDEX face of each font file only\n"); - fprintf (stderr, " -a (all) display unpruned sorted list of matches\n"); - fprintf (stderr, " -V (version) display font config version and exit\n"); - fprintf (stderr, " -? (help) display this help and exit\n"); + fprintf (file, " -i INDEX (index) display the INDEX face of each font file only\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 (1); + exit (error); } int @@ -93,6 +97,7 @@ main (int argc, char **argv) { int index_set = 0; int set_index = 0; + FcChar8 *format = NULL; int err = 0; int i; FcBlanks *blanks; @@ -100,9 +105,9 @@ main (int argc, char **argv) int c; #if HAVE_GETOPT_LONG - while ((c = getopt_long (argc, argv, "i:sVv?", longopts, NULL)) != -1) + while ((c = getopt_long (argc, argv, "i:f:Vh", longopts, NULL)) != -1) #else - while ((c = getopt (argc, argv, "i:asVv?")) != -1) + while ((c = getopt (argc, argv, "i:f:Vh")) != -1) #endif { switch (c) { @@ -110,12 +115,17 @@ main (int argc, char **argv) index_set = 1; set_index = atoi (optarg); break; + case 'f': + format = (FcChar8 *) strdup (optarg); + break; case 'V': fprintf (stderr, "fontconfig version %d.%d.%d\n", FC_MAJOR, FC_MINOR, FC_REVISION); exit (0); + case 'h': + usage (argv[0], 0); default: - usage (argv[0]); + usage (argv[0], 1); } } i = optind; @@ -124,7 +134,7 @@ main (int argc, char **argv) #endif if (i == argc) - usage (argv[0]); + usage (argv[0], 1); if (!FcInit ()) { @@ -147,7 +157,22 @@ main (int argc, char **argv) pat = FcFreeTypeQuery ((FcChar8 *) argv[i], index, blanks, &count); if (pat) { - FcPatternPrint (pat); + if (format) + { + FcChar8 *s; + + s = FcPatternFormat (pat, format); + if (s) + { + printf ("%s", s); + free (s); + } + } + else + { + FcPatternPrint (pat); + } + FcPatternDestroy (pat); } else