lsfontdir.c revision 6a46240f
1/* lsfontdir [<font path entry> ...]
2 *
3 * Lists entries from fonts.dir file in given directory paths.
4 * Defaults to "catalogue:/etc/X11/fontpath.d" & "built-ins" if no paths given.
5 */
6
7/*
8 * Copyright (c) 2015, 2019, Oracle and/or its affiliates.
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice (including the next
18 * paragraph) shall be included in all copies or substantial portions of the
19 * Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
28 */
29
30#include "font-test-utils.h"
31#include <stdio.h>
32#include <assert.h>
33#ifdef HAVE_ERR_H
34#include <err.h>
35#endif
36#include "src/util/replace.h"
37
38int
39main(int argc, char **argv)
40{
41    FontPathElementPtr *fpe_list;
42    xfont2_fpe_funcs_rec const **fpe_functions;
43    int fpe_function_count, fpe_list_count;
44    int i, n;
45
46    fpe_functions = init_font_handlers(&fpe_function_count);
47
48    fpe_list_count = argc - 1;
49    fpe_list = init_font_paths((const char **) argv + 1, &fpe_list_count);
50
51    for (i = 0; i < fpe_list_count; i++) {
52	FontPathElementPtr fpe = fpe_list[i];
53	FontNamesPtr names;
54	const int max_names_count = 8192;
55	const char *pattern = "*";
56	int result;
57
58	/* Don't allocate max size up front to allow testing expansion code */
59	names = xfont2_make_font_names_record(max_names_count / 16);
60	assert(names != NULL);
61
62	result = (*fpe_functions[fpe->type]->list_fonts)
63	    (NULL, fpe, pattern, strlen(pattern), max_names_count, names);
64	if (result != Successful)
65	    err(result, "list_font failed for font path %s: error %d",
66		fpe->name, result);
67
68	printf("--- %s:\n", fpe->name);
69	for (n = 0 ; n < names->nnames; n++) {
70	    printf("%s\n", names->names[n]);
71	}
72
73	xfont2_free_font_names(names);
74    }
75
76    return 0;
77}
78