1/* 2 * xfsinfo -- report info about a font server 3 */ 4 5/* 6 7Portions Copyright 1987, 1998 The Open Group 8 9Permission to use, copy, modify, distribute, and sell this software and its 10documentation for any purpose is hereby granted without fee, provided that 11the above copyright notice appear in all copies and that both that 12copyright notice and this permission notice appear in supporting 13documentation. 14 15The above copyright notice and this permission notice shall be included 16in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 22OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24OTHER DEALINGS IN THE SOFTWARE. 25 26Except as contained in this notice, the name of The Open Group shall 27not be used in advertising or otherwise to promote the sale, use or 28other dealings in this Software without prior written authorization 29from The Open Group. 30 31*/ 32 33/* 34 * Copyright 1990 Network Computing Devices; 35 * Portions Copyright 1987 by Digital Equipment Corporation 36 * 37 * Permission to use, copy, modify, distribute, and sell this software and its 38 * documentation for any purpose is hereby granted without fee, provided that 39 * the above copyright notice appear in all copies and that both that 40 * copyright notice and this permission notice appear in supporting 41 * documentation, and that the names of Network Computing Devices 42 * or Digital not be used in advertising or 43 * publicity pertaining to distribution of the software without specific, 44 * written prior permission. Network Computing Devices and Digital 45 * make no representations about the 46 * suitability of this software for any purpose. It is provided "as is" 47 * without express or implied warranty. 48 * 49 * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH 50 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 51 * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE 52 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 53 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 54 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 55 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 56 * 57 */ 58 59#ifdef HAVE_CONFIG_H 60# include "config.h" 61#endif 62 63#include <stdio.h> 64#include <stdlib.h> 65#include <X11/Xos.h> 66#include <X11/fonts/FSlib.h> 67 68static void print_server_info(FSServer *svr); 69static void print_catalogue_info(FSServer *svr); 70static void print_extension_info(FSServer *svr); 71static void print_alternate_info(FSServer *svr); 72 73static char *progname; 74 75static void _X_NORETURN _X_COLD 76usage(void) 77{ 78 fprintf(stderr, "usage: %s [-server server_name] [-version]\n", progname); 79 exit(-1); 80} 81 82int 83main(int argc, char *argv[]) 84{ 85 FSServer *svr; 86 char *servername = NULL; 87 88 progname = argv[0]; 89 90 for (int i = 1; i < argc; i++) { 91 if (strncmp(argv[i], "-s", 2) == 0) { 92 if (++i >= argc) { 93 fprintf (stderr, "%s: %s requires an argument\n", 94 progname, argv[i-1]); 95 usage(); 96 } 97 servername = argv[i]; 98 } else if (strcmp(argv[i], "-version") == 0) { 99 puts(PACKAGE_STRING); 100 exit(0); 101 } else { 102 fprintf (stderr, "%s: unrecognized argument %s\n", 103 progname, argv[i]); 104 usage(); 105 } 106 } 107 108 svr = FSOpenServer(servername); 109 110 if (!svr) { 111 if (FSServerName(servername) == NULL) { 112 if ((svr = FSOpenServer("unix/:-1")) == NULL) { 113 fprintf(stderr, "%s: no font server defined\n", progname); 114 exit(1); 115 } 116 } 117 if (!svr) { 118 fprintf(stderr, "%s: unable to open server \"%s\"\n", 119 progname, FSServerName(servername)); 120 exit(1); 121 } 122 } 123 print_server_info(svr); 124 FSCloseServer(svr); 125 exit(0); 126} 127 128static void 129print_server_info(FSServer *svr) 130{ 131 printf("name of server: %s\n", FSServerString(svr)); 132 printf("version number: %d\n", FSProtocolVersion(svr)); 133 printf("vendor string: %s\n", FSServerVendor(svr)); 134 printf("vendor release number: %d\n", FSVendorRelease(svr)); 135 if (strstr(FSServerVendor(svr), "X.Org")) { 136 int vendrel = FSVendorRelease(svr); 137 138 printf("X.Org xfs version: "); 139 printf("%d.%d.%d", vendrel / 10000000, 140 (vendrel / 100000) % 100, 141 (vendrel / 1000) % 100); 142 if (vendrel % 1000) 143 printf(".%d", vendrel % 1000); 144 printf("\n"); 145 } 146 printf("maximum request size: %ld words (%ld bytes)\n", 147 FSMaxRequestSize(svr), FSMaxRequestSize(svr) * sizeof(CARD32)); 148 print_catalogue_info(svr); 149 print_alternate_info(svr); 150 print_extension_info(svr); 151} 152 153static void 154print_catalogue_info(FSServer *svr) 155{ 156 int n = 0; 157 char **cats = FSListCatalogues(svr, "*", 1000, &n); 158 159 printf("number of catalogues: %d\n", n); 160 if (cats) { 161 for (int i = 0; i < n; i++) { 162 printf(" %s\n", cats[i]); 163 } 164 FSFreeCatalogues(cats); 165 } 166} 167 168static void 169print_extension_info(FSServer *svr) 170{ 171 int n = 0; 172 char **extlist = FSListExtensions(svr, &n); 173 174 printf("number of extensions: %d\n", n); 175 if (extlist) { 176 for (int i = 0; i < n; i++) { 177 printf(" %s\n", extlist[i]); 178 } 179 FSFreeExtensionList(extlist); 180 } 181} 182 183static void 184print_alternate_info(FSServer *svr) 185{ 186 int num; 187 188 num = FSNumAlternateServers(svr); 189 printf("Number of alternate servers: %d\n", num); 190 if (num) { 191 AlternateServer *alts = FSAlternateServers(svr); 192 193 for (int i = 0; i < num; i++) { 194 printf(" #%1d\t%s%s\n", i, alts[i].name, 195 (alts[i].subset) ? "(subset)" : ""); 196 } 197 } 198} 199