fstobdf.c revision 21c2f794
1/* $Xorg: fstobdf.c,v 1.4 2001/02/09 02:05:30 xorgcvs Exp $ */
2/*
3
4Copyright 1990, 1998  The Open Group
5
6Permission to use, copy, modify, distribute, and sell this software and its
7documentation for any purpose is hereby granted without fee, provided that
8the above copyright notice appear in all copies and that both that
9copyright notice and this permission notice appear in supporting
10documentation.
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall not be
23used in advertising or otherwise to promote the sale, use or other dealings
24in this Software without prior written authorization from The Open Group.
25
26 * Copyright 1990 Network Computing Devices;
27 * Portions Copyright 1987 by Digital Equipment Corporation
28 *
29 * Permission to use, copy, modify, distribute, and sell this software and
30 * its documentation for any purpose is hereby granted without fee, provided
31 * that the above copyright notice appear in all copies and that both that
32 * copyright notice and this permission notice appear in supporting
33 * documentation, and that the names of Network Computing Devices, or Digital
34 * not be used in advertising or publicity pertaining to distribution
35 * of the software without specific, written prior permission.
36 *
37 * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH
38 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
39 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES,
40 * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
41 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
42 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
43 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
44 * THIS SOFTWARE.
45 */
46/* $XFree86: xc/programs/fstobdf/fstobdf.c,v 1.6tsi Exp $ */
47
48#include	<stdio.h>
49#include	<stdlib.h>
50#include        <string.h>
51#include	"fstobdf.h"
52static void
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
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	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