xfsinfo.c revision aea1d7ff
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#include	<stdio.h>
60#include	<stdlib.h>
61#include	<X11/Xos.h>
62#include	<X11/fonts/FSlib.h>
63
64static void print_server_info(FSServer *svr);
65static void print_catalogue_info(FSServer *svr);
66static void print_extension_info(FSServer *svr);
67static void print_alternate_info(FSServer *svr);
68
69static char *progname;
70
71static void _X_NORETURN
72usage(void)
73{
74    fprintf(stderr, "usage:  %s [-server server_name]\n", progname);
75    exit(-1);
76}
77
78int
79main(int argc, char *argv[])
80{
81    FSServer   *svr;
82    char       *servername = NULL;
83    int         i;
84
85    progname = argv[0];
86
87    for (i = 1; i < argc; i++) {
88	if (strncmp(argv[i], "-s", 2) == 0) {
89	    if (++i > argc)
90		usage();
91	    servername = argv[i];
92	} else {
93	    usage();
94	}
95    }
96
97    svr = FSOpenServer(servername);
98
99    if (!svr) {
100	if (FSServerName(servername) == NULL) {
101	    if ((svr = FSOpenServer("unix/:-1")) == NULL) {
102		fprintf(stderr, "%s: no font server defined\n", progname);
103		exit(1);
104	    }
105	}
106	if (!svr) {
107	    fprintf(stderr, "%s:  unable to open server \"%s\"\n",
108		    progname, FSServerName(servername));
109	    exit(1);
110	}
111    }
112    print_server_info(svr);
113    FSCloseServer(svr);
114    exit(0);
115}
116
117static void
118print_server_info(FSServer *svr)
119{
120    printf("name of server:	%s\n", FSServerString(svr));
121    printf("version number:	%d\n", FSProtocolVersion(svr));
122    printf("vendor string:	%s\n", FSServerVendor(svr));
123    printf("vendor release number:	%d\n", FSVendorRelease(svr));
124    if (strstr(FSServerVendor(svr), "X.Org")) {
125	int vendrel = FSVendorRelease(svr);
126
127	printf("X.Org xfs version: ");
128	printf("%d.%d.%d", vendrel / 10000000,
129	       (vendrel /   100000) % 100,
130	       (vendrel /     1000) % 100);
131	if (vendrel % 1000)
132	    printf(".%d", vendrel % 1000);
133	printf("\n");
134    }
135    printf("maximum request size:	%ld longwords (%ld bytes)\n",
136	   FSMaxRequestSize(svr), FSMaxRequestSize(svr) * sizeof(long));
137    print_catalogue_info(svr);
138    print_alternate_info(svr);
139    print_extension_info(svr);
140}
141
142static void
143print_catalogue_info(FSServer *svr)
144{
145    int         n = 0;
146    char      **cats = FSListCatalogues(svr, "*", 1000, &n);
147
148    printf("number of catalogues:	%d\n", n);
149    if (cats) {
150	int         i;
151
152	for (i = 0; i < n; i++) {
153	    printf("	%s\n", cats[i]);
154	}
155	FSFreeCatalogues(cats);
156    }
157}
158
159static void
160print_extension_info(FSServer *svr)
161{
162    int         n = 0;
163    char      **extlist = FSListExtensions(svr, &n);
164
165    printf("number of extensions:	%d\n", n);
166    if (extlist) {
167	int         i;
168
169	for (i = 0; i < n; i++) {
170	    printf("	%s\n", extlist[i]);
171	}
172	FSFreeExtensionList(extlist);
173    }
174}
175
176static void
177print_alternate_info(FSServer *svr)
178{
179    AlternateServer *alts;
180    int         i,
181                num;
182
183    num = FSNumAlternateServers(svr);
184    printf("Number of alternate servers: %d\n", num);
185    if (num) {
186	alts = FSAlternateServers(svr);
187	for (i = 0; i < num; i++) {
188	    printf("    #%1d\t%s%s\n", i, alts[i].name,
189		   (alts[i].subset) ? "(subset)" : "");
190	}
191    }
192}
193