xfsinfo.c revision e7fdea5f
1067610f1Smrg/*
2067610f1Smrg * xfsinfo -- report info about a font server
3067610f1Smrg */
4067610f1Smrg
5067610f1Smrg/*
6067610f1Smrg
7067610f1SmrgPortions Copyright 1987, 1998  The Open Group
8067610f1Smrg
9067610f1SmrgPermission to use, copy, modify, distribute, and sell this software and its
10067610f1Smrgdocumentation for any purpose is hereby granted without fee, provided that
11067610f1Smrgthe above copyright notice appear in all copies and that both that
12067610f1Smrgcopyright notice and this permission notice appear in supporting
13067610f1Smrgdocumentation.
14067610f1Smrg
15067610f1SmrgThe above copyright notice and this permission notice shall be included
16067610f1Smrgin all copies or substantial portions of the Software.
17067610f1Smrg
18067610f1SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19067610f1SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20067610f1SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21067610f1SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
22067610f1SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23067610f1SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24067610f1SmrgOTHER DEALINGS IN THE SOFTWARE.
25067610f1Smrg
26067610f1SmrgExcept as contained in this notice, the name of The Open Group shall
27067610f1Smrgnot be used in advertising or otherwise to promote the sale, use or
28067610f1Smrgother dealings in this Software without prior written authorization
29067610f1Smrgfrom The Open Group.
30067610f1Smrg
31067610f1Smrg*/
32067610f1Smrg
33067610f1Smrg/*
34067610f1Smrg * Copyright 1990 Network Computing Devices;
35067610f1Smrg * Portions Copyright 1987 by Digital Equipment Corporation
36067610f1Smrg *
37067610f1Smrg * Permission to use, copy, modify, distribute, and sell this software and its
38067610f1Smrg * documentation for any purpose is hereby granted without fee, provided that
39067610f1Smrg * the above copyright notice appear in all copies and that both that
40067610f1Smrg * copyright notice and this permission notice appear in supporting
41067610f1Smrg * documentation, and that the names of Network Computing Devices
42067610f1Smrg * or Digital not be used in advertising or
43067610f1Smrg * publicity pertaining to distribution of the software without specific,
44067610f1Smrg * written prior permission.  Network Computing Devices and Digital
45067610f1Smrg * make no representations about the
46067610f1Smrg * suitability of this software for any purpose.  It is provided "as is"
47067610f1Smrg * without express or implied warranty.
48067610f1Smrg *
49067610f1Smrg * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
50067610f1Smrg * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
51067610f1Smrg * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
52067610f1Smrg * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
53067610f1Smrg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
54067610f1Smrg * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
55067610f1Smrg * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
56067610f1Smrg *
57067610f1Smrg */
58067610f1Smrg
59e7fdea5fSmrg#ifdef HAVE_CONFIG_H
60e7fdea5fSmrg# include "config.h"
61e7fdea5fSmrg#endif
62e7fdea5fSmrg
63067610f1Smrg#include	<stdio.h>
64067610f1Smrg#include	<stdlib.h>
65067610f1Smrg#include	<X11/Xos.h>
66067610f1Smrg#include	<X11/fonts/FSlib.h>
67067610f1Smrg
68067610f1Smrgstatic void print_server_info(FSServer *svr);
69067610f1Smrgstatic void print_catalogue_info(FSServer *svr);
70067610f1Smrgstatic void print_extension_info(FSServer *svr);
71067610f1Smrgstatic void print_alternate_info(FSServer *svr);
72067610f1Smrg
737e6533d5Smrgstatic char *progname;
74067610f1Smrg
75aea1d7ffSmrgstatic void _X_NORETURN
76067610f1Smrgusage(void)
77067610f1Smrg{
78e7fdea5fSmrg    fprintf(stderr, "usage:  %s [-server server_name] [-version]\n", progname);
79067610f1Smrg    exit(-1);
80067610f1Smrg}
81067610f1Smrg
82067610f1Smrgint
83067610f1Smrgmain(int argc, char *argv[])
84067610f1Smrg{
85067610f1Smrg    FSServer   *svr;
86067610f1Smrg    char       *servername = NULL;
87067610f1Smrg    int         i;
88067610f1Smrg
89067610f1Smrg    progname = argv[0];
90067610f1Smrg
91067610f1Smrg    for (i = 1; i < argc; i++) {
92067610f1Smrg	if (strncmp(argv[i], "-s", 2) == 0) {
93e7fdea5fSmrg	    if (++i >= argc) {
94e7fdea5fSmrg		fprintf (stderr, "%s: %s requires an argument\n",
95e7fdea5fSmrg			 progname, argv[i-1]);
96067610f1Smrg		usage();
97e7fdea5fSmrg	    }
98067610f1Smrg	    servername = argv[i];
99e7fdea5fSmrg        } else if (strcmp(argv[i], "-version") == 0) {
100e7fdea5fSmrg            puts(PACKAGE_STRING);
101e7fdea5fSmrg            exit(0);
102067610f1Smrg	} else {
103e7fdea5fSmrg	    fprintf (stderr, "%s: unrecognized argument %s\n",
104e7fdea5fSmrg		     progname, argv[i]);
105067610f1Smrg	    usage();
106067610f1Smrg	}
107067610f1Smrg    }
108067610f1Smrg
109067610f1Smrg    svr = FSOpenServer(servername);
110067610f1Smrg
111067610f1Smrg    if (!svr) {
112067610f1Smrg	if (FSServerName(servername) == NULL) {
1137e6533d5Smrg	    if ((svr = FSOpenServer("unix/:-1")) == NULL) {
1147e6533d5Smrg		fprintf(stderr, "%s: no font server defined\n", progname);
1157e6533d5Smrg		exit(1);
1167e6533d5Smrg	    }
1177e6533d5Smrg	}
1187e6533d5Smrg	if (!svr) {
1197e6533d5Smrg	    fprintf(stderr, "%s:  unable to open server \"%s\"\n",
1207e6533d5Smrg		    progname, FSServerName(servername));
121067610f1Smrg	    exit(1);
122067610f1Smrg	}
123067610f1Smrg    }
124067610f1Smrg    print_server_info(svr);
125067610f1Smrg    FSCloseServer(svr);
126067610f1Smrg    exit(0);
127067610f1Smrg}
128067610f1Smrg
129067610f1Smrgstatic void
130067610f1Smrgprint_server_info(FSServer *svr)
131067610f1Smrg{
132067610f1Smrg    printf("name of server:	%s\n", FSServerString(svr));
133067610f1Smrg    printf("version number:	%d\n", FSProtocolVersion(svr));
134067610f1Smrg    printf("vendor string:	%s\n", FSServerVendor(svr));
135067610f1Smrg    printf("vendor release number:	%d\n", FSVendorRelease(svr));
136aea1d7ffSmrg    if (strstr(FSServerVendor(svr), "X.Org")) {
137aea1d7ffSmrg	int vendrel = FSVendorRelease(svr);
138aea1d7ffSmrg
139aea1d7ffSmrg	printf("X.Org xfs version: ");
140aea1d7ffSmrg	printf("%d.%d.%d", vendrel / 10000000,
141aea1d7ffSmrg	       (vendrel /   100000) % 100,
142aea1d7ffSmrg	       (vendrel /     1000) % 100);
143aea1d7ffSmrg	if (vendrel % 1000)
144aea1d7ffSmrg	    printf(".%d", vendrel % 1000);
145aea1d7ffSmrg	printf("\n");
146aea1d7ffSmrg    }
147067610f1Smrg    printf("maximum request size:	%ld longwords (%ld bytes)\n",
148067610f1Smrg	   FSMaxRequestSize(svr), FSMaxRequestSize(svr) * sizeof(long));
149067610f1Smrg    print_catalogue_info(svr);
150067610f1Smrg    print_alternate_info(svr);
151067610f1Smrg    print_extension_info(svr);
152067610f1Smrg}
153067610f1Smrg
154067610f1Smrgstatic void
155067610f1Smrgprint_catalogue_info(FSServer *svr)
156067610f1Smrg{
157067610f1Smrg    int         n = 0;
158067610f1Smrg    char      **cats = FSListCatalogues(svr, "*", 1000, &n);
159067610f1Smrg
160067610f1Smrg    printf("number of catalogues:	%d\n", n);
161067610f1Smrg    if (cats) {
162067610f1Smrg	int         i;
163067610f1Smrg
164067610f1Smrg	for (i = 0; i < n; i++) {
165067610f1Smrg	    printf("	%s\n", cats[i]);
166067610f1Smrg	}
167067610f1Smrg	FSFreeCatalogues(cats);
168067610f1Smrg    }
169067610f1Smrg}
170067610f1Smrg
171067610f1Smrgstatic void
172067610f1Smrgprint_extension_info(FSServer *svr)
173067610f1Smrg{
174067610f1Smrg    int         n = 0;
175067610f1Smrg    char      **extlist = FSListExtensions(svr, &n);
176067610f1Smrg
177067610f1Smrg    printf("number of extensions:	%d\n", n);
178067610f1Smrg    if (extlist) {
179067610f1Smrg	int         i;
180067610f1Smrg
181067610f1Smrg	for (i = 0; i < n; i++) {
182067610f1Smrg	    printf("	%s\n", extlist[i]);
183067610f1Smrg	}
184067610f1Smrg	FSFreeExtensionList(extlist);
185067610f1Smrg    }
186067610f1Smrg}
187067610f1Smrg
188067610f1Smrgstatic void
189067610f1Smrgprint_alternate_info(FSServer *svr)
190067610f1Smrg{
191067610f1Smrg    AlternateServer *alts;
192067610f1Smrg    int         i,
193067610f1Smrg                num;
194067610f1Smrg
195067610f1Smrg    num = FSNumAlternateServers(svr);
196067610f1Smrg    printf("Number of alternate servers: %d\n", num);
197067610f1Smrg    if (num) {
198067610f1Smrg	alts = FSAlternateServers(svr);
199067610f1Smrg	for (i = 0; i < num; i++) {
200067610f1Smrg	    printf("    #%1d\t%s%s\n", i, alts[i].name,
201067610f1Smrg		   (alts[i].subset) ? "(subset)" : "");
202067610f1Smrg	}
203067610f1Smrg    }
204067610f1Smrg}
205