fstobdf.c revision a5c37dfe
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#include	<stdio.h>
47#include	<stdlib.h>
48#include        <string.h>
49#include	"fstobdf.h"
50
51
52static void _X_NORETURN
53usage(char *progName)
54{
55    fprintf(stderr, "Usage: %s [-s <font server>] -fn <font name>\n",
56	    progName);
57    exit(0);
58}
59
60static void _X_NORETURN
61Fail(char *progName)
62{
63    fprintf(stderr, "%s: unable to dump font\n", progName);
64    exit(1);
65}
66
67int
68main(int argc, char *argv[])
69{
70    FSServer   *fontServer;
71    Font        fontID,
72                dummy;
73    FSBitmapFormat bitmapFormat;
74    FSXFontInfoHeader fontHeader;
75    FSPropInfo  propInfo;
76    FSPropOffset *propOffsets;
77    unsigned char *propData;
78
79    FILE       *outFile;
80    char       *fontName;
81    char       *serverName;
82    int         i;
83
84    fontName = NULL;
85    serverName = NULL;
86    outFile = stdout;
87
88    for (i = 1; i < argc; i++) {
89	if (!strncmp(argv[i], "-s", 2)) {
90	    if (argv[++i])
91		serverName = argv[i];
92	    else
93		usage(argv[0]);
94	} else if (!strncmp(argv[i], "-fn", 3)) {
95	    if (argv[++i])
96		fontName = argv[i];
97	    else
98		usage(argv[0]);
99	}
100    }
101
102    if (fontName == NULL)
103	usage(argv[0]);
104
105    fontServer = FSOpenServer(serverName);
106    if (!fontServer) {
107	const char *sn = FSServerName(serverName);
108	if (sn)
109	    fprintf(stderr, "%s: can't open font server \"%s\"\n",
110	      	    argv[0], sn);
111	else
112	    fprintf(stderr, "%s:  No font server specified.\n",
113		    argv[0]);
114	exit(0);
115    }
116    bitmapFormat = 0;
117    fontID = FSOpenBitmapFont(fontServer, bitmapFormat, (FSBitmapFormatMask) 0,
118			      fontName, &dummy);
119    if (!fontID) {
120	printf("can't open font \"%s\"\n", fontName);
121	exit(0);
122    }
123    FSQueryXInfo(fontServer, fontID, &fontHeader, &propInfo, &propOffsets,
124		 &propData);
125
126    if (!EmitHeader(outFile, &fontHeader, &propInfo, propOffsets, propData))
127	Fail(argv[0]);
128    if (!EmitProperties(outFile, &fontHeader, &propInfo, propOffsets, propData))
129	Fail(argv[0]);
130    if (!EmitCharacters(outFile, fontServer, &fontHeader, fontID))
131	Fail(argv[0]);
132    fprintf(outFile, "ENDFONT\n");
133
134    FSFree((char *) propOffsets);
135    FSFree((char *) propData);
136    exit (0);
137}
138