1 /* 2 * xfsinfo -- report info about a font server 3 */ 4 5 /* 6 7 Portions Copyright 1987, 1998 The Open Group 8 9 Permission to use, copy, modify, distribute, and sell this software and its 10 documentation for any purpose is hereby granted without fee, provided that 11 the above copyright notice appear in all copies and that both that 12 copyright notice and this permission notice appear in supporting 13 documentation. 14 15 The above copyright notice and this permission notice shall be included 16 in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 OTHER DEALINGS IN THE SOFTWARE. 25 26 Except as contained in this notice, the name of The Open Group shall 27 not be used in advertising or otherwise to promote the sale, use or 28 other dealings in this Software without prior written authorization 29 from 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 68 static void print_server_info(FSServer *svr); 69 static void print_catalogue_info(FSServer *svr); 70 static void print_extension_info(FSServer *svr); 71 static void print_alternate_info(FSServer *svr); 72 73 static char *progname; 74 75 static void _X_NORETURN _X_COLD 76 usage(int exitstatus) 77 { 78 fprintf(stderr, "usage: %s [-server server_name] [-help|-version]\n", 79 progname); 80 exit(exitstatus); 81 } 82 83 int 84 main(int argc, char *argv[]) 85 { 86 FSServer *svr; 87 char *servername = NULL; 88 89 progname = argv[0]; 90 91 for (int i = 1; i < argc; i++) { 92 if (strncmp(argv[i], "-s", 2) == 0) { 93 if (++i >= argc) { 94 fprintf (stderr, "%s: %s requires an argument\n", 95 progname, argv[i-1]); 96 usage(EXIT_FAILURE); 97 } 98 servername = argv[i]; 99 } else if ((strcmp(argv[i], "-version") == 0) || 100 (strcmp(argv[i], "--version") == 0)) { 101 puts(PACKAGE_STRING); 102 exit(EXIT_SUCCESS); 103 } else if ((strcmp(argv[i], "-help") == 0) || 104 (strcmp(argv[i], "--help") == 0)) { 105 usage(EXIT_SUCCESS); 106 } else { 107 fprintf (stderr, "%s: unrecognized argument %s\n", 108 progname, argv[i]); 109 usage(EXIT_FAILURE); 110 } 111 } 112 113 svr = FSOpenServer(servername); 114 115 if (!svr) { 116 if (FSServerName(servername) == NULL) { 117 if ((svr = FSOpenServer("unix/:-1")) == NULL) { 118 fprintf(stderr, "%s: no font server defined\n", progname); 119 exit(1); 120 } 121 } 122 if (!svr) { 123 fprintf(stderr, "%s: unable to open server \"%s\"\n", 124 progname, FSServerName(servername)); 125 exit(1); 126 } 127 } 128 print_server_info(svr); 129 FSCloseServer(svr); 130 exit(0); 131 } 132 133 static void 134 print_server_info(FSServer *svr) 135 { 136 printf("name of server: %s\n", FSServerString(svr)); 137 printf("version number: %d\n", FSProtocolVersion(svr)); 138 printf("vendor string: %s\n", FSServerVendor(svr)); 139 printf("vendor release number: %d\n", FSVendorRelease(svr)); 140 if (strstr(FSServerVendor(svr), "X.Org")) { 141 int vendrel = FSVendorRelease(svr); 142 143 printf("X.Org xfs version: "); 144 printf("%d.%d.%d", vendrel / 10000000, 145 (vendrel / 100000) % 100, 146 (vendrel / 1000) % 100); 147 if (vendrel % 1000) 148 printf(".%d", vendrel % 1000); 149 printf("\n"); 150 } 151 printf("maximum request size: %ld words (%ld bytes)\n", 152 FSMaxRequestSize(svr), FSMaxRequestSize(svr) * sizeof(CARD32)); 153 print_catalogue_info(svr); 154 print_alternate_info(svr); 155 print_extension_info(svr); 156 } 157 158 static void 159 print_catalogue_info(FSServer *svr) 160 { 161 int n = 0; 162 char **cats = FSListCatalogues(svr, "*", 1000, &n); 163 164 printf("number of catalogues: %d\n", n); 165 if (cats) { 166 for (int i = 0; i < n; i++) { 167 printf(" %s\n", cats[i]); 168 } 169 FSFreeCatalogues(cats); 170 } 171 } 172 173 static void 174 print_extension_info(FSServer *svr) 175 { 176 int n = 0; 177 char **extlist = FSListExtensions(svr, &n); 178 179 printf("number of extensions: %d\n", n); 180 if (extlist) { 181 for (int i = 0; i < n; i++) { 182 printf(" %s\n", extlist[i]); 183 } 184 FSFreeExtensionList(extlist); 185 } 186 } 187 188 static void 189 print_alternate_info(FSServer *svr) 190 { 191 int num; 192 193 num = FSNumAlternateServers(svr); 194 printf("Number of alternate servers: %d\n", num); 195 if (num) { 196 AlternateServer *alts = FSAlternateServers(svr); 197 198 for (int i = 0; i < num; i++) { 199 printf(" #%1d\t%s%s\n", i, alts[i].name, 200 (alts[i].subset) ? "(subset)" : ""); 201 } 202 } 203 } 204