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