]>
git.wh0rd.org - fontconfig.git/blob - fc-scan/fc-scan.c
2 * fontconfig/fc-scan/fc-scan.c
4 * Copyright © 2003 Keith Packard
5 * Copyright © 2008 Red Hat, Inc.
6 * Red Hat Author(s): Behdad Esfahbod
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that
11 * copyright notice and this permission notice appear in supporting
12 * documentation, and that the name of Keith Packard not be used in
13 * advertising or publicity pertaining to distribution of the software without
14 * specific, written prior permission. Keith Packard makes no
15 * representations about the suitability of this software for any purpose. It
16 * is provided "as is" without express or implied warranty.
18 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24 * PERFORMANCE OF THIS SOFTWARE.
31 #define HAVE_GETOPT_LONG 1
36 #include <fontconfig/fontconfig.h>
37 #include <fontconfig/fcfreetype.h>
46 #ifndef HAVE_GETOPT_LONG
47 #define HAVE_GETOPT_LONG 0
54 static const struct option longopts
[] = {
55 {"format", 1, 0, 'f'},
56 {"version", 0, 0, 'V'},
63 extern int optind
, opterr
, optopt
;
68 usage (char *program
, int error
)
70 FILE *file
= error
? stderr
: stdout
;
72 fprintf (file
, "usage: %s [-Vh] [-f FORMAT] [--format FORMAT] [--version] [--help] font-file...\n",
75 fprintf (file
, "usage: %s [-Vh] [-f FORMAT] font-file...\n",
78 fprintf (file
, "Scan font files and directories, and print resulting pattern(s)\n");
81 fprintf (file
, " -f, --format=FORMAT use the given output format\n");
82 fprintf (file
, " -V, --version display font config version and exit\n");
83 fprintf (file
, " -h, --help display this help and exit\n");
85 fprintf (file
, " -f FORMAT (format) use the given output format\n");
86 fprintf (file
, " -V (version) display font config version and exit\n");
87 fprintf (file
, " -h (help) display this help and exit\n");
93 main (int argc
, char **argv
)
95 FcChar8
*format
= NULL
;
98 #if HAVE_GETOPT_LONG || HAVE_GETOPT
102 while ((c
= getopt_long (argc
, argv
, "f:Vh", longopts
, NULL
)) != -1)
104 while ((c
= getopt (argc
, argv
, "f:Vh")) != -1)
109 format
= (FcChar8
*) strdup (optarg
);
112 fprintf (stderr
, "fontconfig version %d.%d.%d\n",
113 FC_MAJOR
, FC_MINOR
, FC_REVISION
);
131 fprintf (stderr
, "Can't init font config library\n");
135 fs
= FcFontSetCreate ();
137 for (; i
< argc
; i
++)
139 const FcChar8
*file
= (FcChar8
*) argv
[i
];
141 if (!FcFileIsDir (file
))
142 FcFileScan (fs
, NULL
, NULL
, NULL
, file
, FcTrue
);
145 FcStrSet
*dirs
= FcStrSetCreate ();
146 FcStrList
*strlist
= FcStrListCreate (dirs
);
149 FcDirScan (fs
, dirs
, NULL
, NULL
, file
, FcTrue
);
151 while ((file
= FcStrListNext (strlist
)));
152 FcStrListDone (strlist
);
153 FcStrSetDestroy (dirs
);
157 for (i
= 0; i
< fs
->nfont
; i
++)
167 s
= FcPatternFormat (pat
, format
);
173 FcPatternPrint (pat
);
177 FcFontSetDestroy (fs
);
180 return i
> 0 ? 0 : 1;