fstobdf.c revision a8918085
1/*
2
3Copyright 1990, 1998  The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24
25 * Copyright 1990 Network Computing Devices;
26 * Portions Copyright 1987 by Digital Equipment Corporation
27 *
28 * Permission to use, copy, modify, distribute, and sell this software and
29 * its documentation for any purpose is hereby granted without fee, provided
30 * that the above copyright notice appear in all copies and that both that
31 * copyright notice and this permission notice appear in supporting
32 * documentation, and that the names of Network Computing Devices, or Digital
33 * not be used in advertising or publicity pertaining to distribution
34 * of the software without specific, written prior permission.
35 *
36 * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH
37 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
38 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES,
39 * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
40 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
41 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
42 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
43 * THIS SOFTWARE.
44 */
45
46#ifdef HAVE_CONFIG_H
47# include "config.h"
48#endif
49
50#include	<stdio.h>
51#include	<stdlib.h>
52#include        <string.h>
53#include	"fstobdf.h"
54
55
56static void _X_NORETURN _X_COLD
57usage(const char *progName, const char *msg)
58{
59    if (msg)
60        fprintf(stderr, "%s: %s\n", progName, msg);
61    fprintf(stderr,
62	    "Usage: %s [-server <font server>] -fn <font name>\n"
63	    "	or: %s -version\n",
64	    progName, progName);
65    exit(0);
66}
67
68static void _X_NORETURN _X_COLD
69Fail(const char *progName)
70{
71    fprintf(stderr, "%s: unable to dump font\n", progName);
72    exit(1);
73}
74
75int
76main(int argc, char *argv[])
77{
78    FSServer   *fontServer;
79    Font        fontID,
80                dummy;
81    FSBitmapFormat bitmapFormat;
82    FSXFontInfoHeader fontHeader;
83    FSPropInfo  propInfo;
84    FSPropOffset *propOffsets;
85    unsigned char *propData;
86
87    FILE       *outFile;
88    char       *fontName;
89    char       *serverName;
90    int         i;
91
92    fontName = NULL;
93    serverName = NULL;
94    outFile = stdout;
95
96    for (i = 1; i < argc; i++) {
97	if (!strncmp(argv[i], "-s", 2)) {
98	    if (argv[++i])
99		serverName = argv[i];
100	    else
101		usage(argv[0], "-server requires an argument");
102	} else if (!strncmp(argv[i], "-fn", 3)) {
103	    if (argv[++i])
104		fontName = argv[i];
105	    else
106		usage(argv[0], "-fn requires an argument");
107	}
108	else if (!strcmp(argv[i], "-version")) {
109	    printf("%s\n", PACKAGE_STRING);
110	    exit(0);
111	}
112	else {
113	    fprintf(stderr, "%s: unrecognized option '%s'\n",
114		    argv[0], argv[i]);
115	    usage(argv[0], NULL);
116	}
117    }
118
119    if (fontName == NULL)
120	usage(argv[0], "No font name specified");
121
122    fontServer = FSOpenServer(serverName);
123    if (!fontServer) {
124	const char *sn = FSServerName(serverName);
125	if (sn)
126	    fprintf(stderr, "%s: can't open font server \"%s\"\n",
127	      	    argv[0], sn);
128	else
129	    usage(argv[0], "No font server specified.");
130	exit(0);
131    }
132    bitmapFormat = 0;
133    fontID = FSOpenBitmapFont(fontServer, bitmapFormat, (FSBitmapFormatMask) 0,
134			      fontName, &dummy);
135    if (!fontID) {
136	printf("can't open font \"%s\"\n", fontName);
137	exit(0);
138    }
139    FSQueryXInfo(fontServer, fontID, &fontHeader, &propInfo, &propOffsets,
140		 &propData);
141
142    if (!EmitHeader(outFile, &fontHeader, &propInfo, propOffsets, propData))
143	Fail(argv[0]);
144    if (!EmitProperties(outFile, &fontHeader, &propInfo, propOffsets, propData))
145	Fail(argv[0]);
146    if (!EmitCharacters(outFile, fontServer, &fontHeader, fontID))
147	Fail(argv[0]);
148    fprintf(outFile, "ENDFONT\n");
149
150    FSFree((char *) propOffsets);
151    FSFree((char *) propData);
152    exit (0);
153}
154