| 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 | |
| 26 | |
| 27 | #ifdef HAVE_CONFIG_H1 |
| 28 | #include <config.h> |
| 29 | #else |
| 30 | #ifdef linux |
| 31 | #define HAVE_GETOPT_LONG1 1 |
| 32 | #endif |
| 33 | #define HAVE_GETOPT1 1 |
| 34 | #endif |
| 35 | |
| 36 | #include <fontconfig/fontconfig.h> |
| 37 | #include <fontconfig/fcfreetype.h> |
| 38 | #include <stdio.h> |
| 39 | #include <unistd.h> |
| 40 | #include <stdlib.h> |
| 41 | #include <string.h> |
| 42 | |
| 43 | #ifndef HAVE_GETOPT1 |
| 44 | #define HAVE_GETOPT1 0 |
| 45 | #endif |
| 46 | #ifndef HAVE_GETOPT_LONG1 |
| 47 | #define HAVE_GETOPT_LONG1 0 |
| 48 | #endif |
| 49 | |
| 50 | #if HAVE_GETOPT_LONG1 |
| 51 | #undef _GNU_SOURCE |
| 52 | #define _GNU_SOURCE |
| 53 | #include <getopt.h> |
| 54 | static const struct option longopts[] = { |
| 55 | {"ignore-blanks", 0, 0, 'b'}, |
| 56 | {"format", 1, 0, 'f'}, |
| 57 | {"version", 0, 0, 'V'}, |
| 58 | {"help", 0, 0, 'h'}, |
| 59 | {NULL((void*)0),0,0,0}, |
| 60 | }; |
| 61 | #else |
| 62 | #if HAVE_GETOPT1 |
| 63 | extern char *optarg; |
| 64 | extern int optind, opterr, optopt; |
| 65 | #endif |
| 66 | #endif |
| 67 | |
| 68 | static void |
| 69 | usage (char *program, int error) |
| 70 | { |
| 71 | FILE *file = error ? stderr__stderrp : stdout__stdoutp; |
| 72 | #if HAVE_GETOPT_LONG1 |
| 73 | fprintf (file, "usage: %s [-Vbh] [-f FORMAT] [--ignore-blanks] [--format FORMAT] [--version] [--help] font-file...\n", |
| 74 | program); |
| 75 | #else |
| 76 | fprintf (file, "usage: %s [-Vbh] [-f FORMAT] font-file...\n", |
| 77 | program); |
| 78 | #endif |
| 79 | fprintf (file, "Scan font files and directories, and print resulting pattern(s)\n"); |
| 80 | fprintf (file, "\n"); |
| 81 | #if HAVE_GETOPT_LONG1 |
| 82 | fprintf (file, " -b, --ignore-blanks ignore blanks to compute languages\n"); |
| 83 | fprintf (file, " -f, --format=FORMAT use the given output format\n"); |
| 84 | fprintf (file, " -V, --version display font config version and exit\n"); |
| 85 | fprintf (file, " -h, --help display this help and exit\n"); |
| 86 | #else |
| 87 | fprintf (file, " -b (ignore-blanks) ignore blanks to compute languages\n"); |
| 88 | fprintf (file, " -f FORMAT (format) use the given output format\n"); |
| 89 | fprintf (file, " -V (version) display font config version and exit\n"); |
| 90 | fprintf (file, " -h (help) display this help and exit\n"); |
| 91 | #endif |
| 92 | exit (error); |
| 93 | } |
| 94 | |
| 95 | int |
| 96 | main (int argc, char **argv) |
| 97 | { |
| 98 | FcChar8 *format = NULL((void*)0); |
| 99 | int i; |
| 100 | int ignore_blanks = 0; |
| 101 | FcFontSet *fs; |
| 102 | FcBlanks *blanks = NULL((void*)0); |
| 103 | #if HAVE_GETOPT_LONG1 || HAVE_GETOPT1 |
| 104 | int c; |
| 105 | |
| 106 | #if HAVE_GETOPT_LONG1 |
| 107 | while ((c = getopt_long (argc, argv, "bf:Vh", longopts, NULL((void*)0))) != -1) |
| 1 | Loop condition is true. Entering loop body | |
|
| 5 | | Loop condition is false. Execution continues on line 129 | |
|
| 108 | #else |
| 109 | while ((c = getopt (argc, argv, "bf:Vh")) != -1) |
| 110 | #endif |
| 111 | { |
| 112 | switch (c) { |
| 2 | | Control jumps to 'case 102:' at line 116 | |
|
| 113 | case 'b': |
| 114 | ignore_blanks = 1; |
| 115 | break; |
| 116 | case 'f': |
| 117 | format = (FcChar8 *) strdup (optarg); |
| |
| 118 | break; |
| 4 | | Execution continues on line 107 | |
|
| 119 | case 'V': |
| 120 | fprintf (stderr__stderrp, "fontconfig version %d.%d.%d\n", |
| 121 | FC_MAJOR2, FC_MINOR11, FC_REVISION95); |
| 122 | exit (0); |
| 123 | case 'h': |
| 124 | usage (argv[0], 0); |
| 125 | default: |
| 126 | usage (argv[0], 1); |
| 127 | } |
| 128 | } |
| 129 | i = optind; |
| 130 | #else |
| 131 | i = 1; |
| 132 | #endif |
| 133 | |
| 134 | if (i == argc) |
| |
| 135 | usage (argv[0], 1); |
| 136 | |
| 137 | fs = FcFontSetCreate (); |
| 138 | if (!ignore_blanks) |
| |
| 139 | blanks = FcConfigGetBlanks (NULL((void*)0)); |
| 140 | |
| 141 | for (; i < argc; i++) |
| 8 | | Loop condition is false. Execution continues on line 161 | |
|
| 142 | { |
| 143 | const FcChar8 *file = (FcChar8*) argv[i]; |
| 144 | |
| 145 | if (!FcFileIsDir (file)) |
| 146 | FcFileScan (fs, NULL((void*)0), NULL((void*)0), blanks, file, FcTrue1); |
| 147 | else |
| 148 | { |
| 149 | FcStrSet *dirs = FcStrSetCreate (); |
| 150 | FcStrList *strlist = FcStrListCreate (dirs); |
| 151 | do |
| 152 | { |
| 153 | FcDirScan (fs, dirs, NULL((void*)0), blanks, file, FcTrue1); |
| 154 | } |
| 155 | while ((file = FcStrListNext (strlist))); |
| 156 | FcStrListDone (strlist); |
| 157 | FcStrSetDestroy (dirs); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | for (i = 0; i < fs->nfont; i++) |
| 9 | | Loop condition is false. Execution continues on line 184 | |
|
| 162 | { |
| 163 | FcPattern *pat; |
| 164 | |
| 165 | pat = fs->fonts[i]; |
| 166 | |
| 167 | if (format) |
| 168 | { |
| 169 | FcChar8 *s; |
| 170 | |
| 171 | s = FcPatternFormat (pat, format); |
| 172 | if (s) |
| 173 | { |
| 174 | printf ("%s", s); |
| 175 | FcStrFree (s); |
| 176 | } |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | FcPatternPrint (pat); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | FcFontSetDestroy (fs); |
| 10 | | Potential leak of memory pointed to by 'format' |
|
| 185 | |
| 186 | FcFini (); |
| 187 | return i > 0 ? 0 : 1; |
| 188 | } |