| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | #include <fontconfig/fontconfig.h> |
| 26 | #include <stdio.h> |
| 27 | #include <unistd.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #ifdef HAVE_CONFIG_H1 |
| 31 | #include <config.h> |
| 32 | #else |
| 33 | #ifdef linux |
| 34 | #define HAVE_GETOPT_LONG1 1 |
| 35 | #endif |
| 36 | #define HAVE_GETOPT1 1 |
| 37 | #endif |
| 38 | |
| 39 | #ifndef HAVE_GETOPT1 |
| 40 | #define HAVE_GETOPT1 0 |
| 41 | #endif |
| 42 | #ifndef HAVE_GETOPT_LONG1 |
| 43 | #define HAVE_GETOPT_LONG1 0 |
| 44 | #endif |
| 45 | |
| 46 | #if HAVE_GETOPT_LONG1 |
| 47 | #undef _GNU_SOURCE |
| 48 | #define _GNU_SOURCE |
| 49 | #include <getopt.h> |
| 50 | const struct option longopts[] = { |
| 51 | {"verbose", 0, 0, 'v'}, |
| 52 | {"format", 1, 0, 'f'}, |
| 53 | {"quiet", 0, 0, 'q'}, |
| 54 | {"version", 0, 0, 'V'}, |
| 55 | {"help", 0, 0, 'h'}, |
| 56 | {NULL((void *)0),0,0,0}, |
| 57 | }; |
| 58 | #else |
| 59 | #if HAVE_GETOPT1 |
| 60 | extern char *optarg; |
| 61 | extern int optind, opterr, optopt; |
| 62 | #endif |
| 63 | #endif |
| 64 | |
| 65 | static void |
| 66 | usage (char *program, int error) |
| 67 | { |
| 68 | FILE *file = error ? stderr__stderrp : stdout__stdoutp; |
| 69 | #if HAVE_GETOPT_LONG1 |
| 70 | fprintf (file, "usage: %s [-vqVh] [-f FORMAT] [--verbose] [--format=FORMAT] [--quiet] [--version] [--help] [pattern] {element ...} \n", |
| 71 | program); |
| 72 | #else |
| 73 | fprintf (file, "usage: %s [-vqVh] [-f FORMAT] [pattern] {element ...} \n", |
| 74 | program); |
| 75 | #endif |
| 76 | fprintf (file, "List fonts matching [pattern]\n"); |
| 77 | fprintf (file, "\n"); |
| 78 | #if HAVE_GETOPT_LONG1 |
| 79 | fprintf (file, " -v, --verbose display entire font pattern verbosely\n"); |
| 80 | fprintf (file, " -f, --format=FORMAT use the given output format\n"); |
| 81 | fprintf (file, " -q, --quiet suppress all normal output, exit 1 if no fonts matched\n"); |
| 82 | fprintf (file, " -V, --version display font config version and exit\n"); |
| 83 | fprintf (file, " -h, --help display this help and exit\n"); |
| 84 | #else |
| 85 | fprintf (file, " -v (verbose) display entire font pattern verbosely\n"); |
| 86 | fprintf (file, " -f FORMAT (format) use the given output format\n"); |
| 87 | fprintf (file, " -q, (quiet) suppress all normal output, exit 1 if no fonts matched\n"); |
| 88 | fprintf (file, " -V (version) display font config version and exit\n"); |
| 89 | fprintf (file, " -h (help) display this help and exit\n"); |
| 90 | #endif |
| 91 | exit (error); |
| 92 | } |
| 93 | |
| 94 | int |
| 95 | main (int argc, char **argv) |
| 96 | { |
| 97 | int verbose = 0; |
| 98 | int quiet = 0; |
| 99 | const FcChar8 *format = NULL((void *)0); |
| 100 | int nfont = 0; |
| 101 | int i; |
| 102 | FcObjectSet *os = 0; |
| 103 | FcFontSet *fs; |
| 104 | FcPattern *pat; |
| 105 | #if HAVE_GETOPT_LONG1 || HAVE_GETOPT1 |
| 106 | int c; |
| 107 | |
| 108 | #if HAVE_GETOPT_LONG1 |
| 109 | while ((c = getopt_long (argc, argv, "vf:qVh", longopts, NULL((void *)0))) != -1) |
| 1 | Loop condition is true. Entering loop body | |
|
| 5 | | Loop condition is false. Execution continues on line 134 | |
|
| 110 | #else |
| 111 | while ((c = getopt (argc, argv, "vf:qVh")) != -1) |
| 112 | #endif |
| 113 | { |
| 114 | switch (c) { |
| 2 | | Control jumps to 'case 102:' at line 118 | |
|
| 115 | case 'v': |
| 116 | verbose = 1; |
| 117 | break; |
| 118 | case 'f': |
| 119 | format = (FcChar8 *) strdup (optarg); |
| |
| 120 | break; |
| 4 | | Execution continues on line 109 | |
|
| 121 | case 'q': |
| 122 | quiet = 1; |
| 123 | break; |
| 124 | case 'V': |
| 125 | fprintf (stderr__stderrp, "fontconfig version %d.%d.%d\n", |
| 126 | FC_MAJOR2, FC_MINOR11, FC_REVISION95); |
| 127 | exit (0); |
| 128 | case 'h': |
| 129 | usage (argv[0], 0); |
| 130 | default: |
| 131 | usage (argv[0], 1); |
| 132 | } |
| 133 | } |
| 134 | i = optind; |
| 135 | #else |
| 136 | i = 1; |
| 137 | #endif |
| 138 | |
| 139 | if (argv[i]) |
| |
| 140 | { |
| 141 | pat = FcNameParse ((FcChar8 *) argv[i]); |
| 142 | if (!pat) |
| |
| |
| 143 | { |
| 144 | fputs ("Unable to parse the pattern\n", stderr__stderrp); |
| 9 | | Potential leak of memory pointed to by 'format' |
|
| 145 | return 1; |
| 146 | } |
| 147 | while (argv[++i]) |
| 148 | { |
| 149 | if (!os) |
| 150 | os = FcObjectSetCreate (); |
| 151 | FcObjectSetAdd (os, argv[i]); |
| 152 | } |
| 153 | } |
| 154 | else |
| 155 | pat = FcPatternCreate (); |
| 156 | if (quiet && !os) |
| 157 | os = FcObjectSetCreate (); |
| 158 | if (!verbose && !format && !os) |
| 159 | os = FcObjectSetBuild (FC_FAMILY"family", FC_STYLE"style", FC_FILE"file", (char *) 0); |
| 160 | if (!format) |
| 161 | format = (const FcChar8 *) "%{=fclist}\n"; |
| 162 | fs = FcFontList (0, pat, os); |
| 163 | if (os) |
| 164 | FcObjectSetDestroy (os); |
| 165 | if (pat) |
| 166 | FcPatternDestroy (pat); |
| 167 | |
| 168 | if (!quiet && fs) |
| 169 | { |
| 170 | int j; |
| 171 | |
| 172 | for (j = 0; j < fs->nfont; j++) |
| 173 | { |
| 174 | if (verbose) |
| 175 | { |
| 176 | FcPatternPrint (fs->fonts[j]); |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | FcChar8 *s; |
| 181 | |
| 182 | s = FcPatternFormat (fs->fonts[j], format); |
| 183 | if (s) |
| 184 | { |
| 185 | printf ("%s", s); |
| 186 | FcStrFree (s); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | if (fs) { |
| 193 | nfont = fs->nfont; |
| 194 | FcFontSetDestroy (fs); |
| 195 | } |
| 196 | |
| 197 | FcFini (); |
| 198 | |
| 199 | return quiet ? (nfont == 0 ? 1 : 0) : 0; |
| 200 | } |