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