fstobdf.c revision a8918085
121c2f794Smrg/* 2a5c37dfeSmrg 321c2f794SmrgCopyright 1990, 1998 The Open Group 421c2f794Smrg 521c2f794SmrgPermission to use, copy, modify, distribute, and sell this software and its 621c2f794Smrgdocumentation for any purpose is hereby granted without fee, provided that 721c2f794Smrgthe above copyright notice appear in all copies and that both that 821c2f794Smrgcopyright notice and this permission notice appear in supporting 921c2f794Smrgdocumentation. 1021c2f794Smrg 1121c2f794SmrgThe above copyright notice and this permission notice shall be included in 1221c2f794Smrgall copies or substantial portions of the Software. 1321c2f794Smrg 1421c2f794SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1521c2f794SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1621c2f794SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1721c2f794SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1821c2f794SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1921c2f794SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2021c2f794Smrg 2121c2f794SmrgExcept as contained in this notice, the name of The Open Group shall not be 2221c2f794Smrgused in advertising or otherwise to promote the sale, use or other dealings 2321c2f794Smrgin this Software without prior written authorization from The Open Group. 2421c2f794Smrg 2521c2f794Smrg * Copyright 1990 Network Computing Devices; 26a5c37dfeSmrg * Portions Copyright 1987 by Digital Equipment Corporation 2721c2f794Smrg * 2821c2f794Smrg * Permission to use, copy, modify, distribute, and sell this software and 2921c2f794Smrg * its documentation for any purpose is hereby granted without fee, provided 3021c2f794Smrg * that the above copyright notice appear in all copies and that both that 3121c2f794Smrg * copyright notice and this permission notice appear in supporting 3221c2f794Smrg * documentation, and that the names of Network Computing Devices, or Digital 3321c2f794Smrg * not be used in advertising or publicity pertaining to distribution 3421c2f794Smrg * of the software without specific, written prior permission. 3521c2f794Smrg * 3621c2f794Smrg * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH 3721c2f794Smrg * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF 3821c2f794Smrg * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, 3921c2f794Smrg * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 4021c2f794Smrg * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 4121c2f794Smrg * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 4221c2f794Smrg * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 4321c2f794Smrg * THIS SOFTWARE. 4421c2f794Smrg */ 4521c2f794Smrg 46a8918085Smrg#ifdef HAVE_CONFIG_H 47a8918085Smrg# include "config.h" 48a8918085Smrg#endif 49a8918085Smrg 5021c2f794Smrg#include <stdio.h> 5121c2f794Smrg#include <stdlib.h> 5221c2f794Smrg#include <string.h> 5321c2f794Smrg#include "fstobdf.h" 54a5c37dfeSmrg 55a5c37dfeSmrg 56a8918085Smrgstatic void _X_NORETURN _X_COLD 57a8918085Smrgusage(const char *progName, const char *msg) 5821c2f794Smrg{ 59a8918085Smrg if (msg) 60a8918085Smrg fprintf(stderr, "%s: %s\n", progName, msg); 61a8918085Smrg fprintf(stderr, 62a8918085Smrg "Usage: %s [-server <font server>] -fn <font name>\n" 63a8918085Smrg " or: %s -version\n", 64a8918085Smrg progName, progName); 6521c2f794Smrg exit(0); 6621c2f794Smrg} 6721c2f794Smrg 68a8918085Smrgstatic void _X_NORETURN _X_COLD 69a8918085SmrgFail(const char *progName) 7021c2f794Smrg{ 7121c2f794Smrg fprintf(stderr, "%s: unable to dump font\n", progName); 7221c2f794Smrg exit(1); 7321c2f794Smrg} 7421c2f794Smrg 7521c2f794Smrgint 7621c2f794Smrgmain(int argc, char *argv[]) 7721c2f794Smrg{ 7821c2f794Smrg FSServer *fontServer; 7921c2f794Smrg Font fontID, 8021c2f794Smrg dummy; 8121c2f794Smrg FSBitmapFormat bitmapFormat; 8221c2f794Smrg FSXFontInfoHeader fontHeader; 8321c2f794Smrg FSPropInfo propInfo; 8421c2f794Smrg FSPropOffset *propOffsets; 8521c2f794Smrg unsigned char *propData; 8621c2f794Smrg 8721c2f794Smrg FILE *outFile; 8821c2f794Smrg char *fontName; 8921c2f794Smrg char *serverName; 9021c2f794Smrg int i; 9121c2f794Smrg 9221c2f794Smrg fontName = NULL; 9321c2f794Smrg serverName = NULL; 9421c2f794Smrg outFile = stdout; 9521c2f794Smrg 9621c2f794Smrg for (i = 1; i < argc; i++) { 9721c2f794Smrg if (!strncmp(argv[i], "-s", 2)) { 9821c2f794Smrg if (argv[++i]) 9921c2f794Smrg serverName = argv[i]; 10021c2f794Smrg else 101a8918085Smrg usage(argv[0], "-server requires an argument"); 10221c2f794Smrg } else if (!strncmp(argv[i], "-fn", 3)) { 10321c2f794Smrg if (argv[++i]) 10421c2f794Smrg fontName = argv[i]; 10521c2f794Smrg else 106a8918085Smrg usage(argv[0], "-fn requires an argument"); 107a8918085Smrg } 108a8918085Smrg else if (!strcmp(argv[i], "-version")) { 109a8918085Smrg printf("%s\n", PACKAGE_STRING); 110a8918085Smrg exit(0); 111a8918085Smrg } 112a8918085Smrg else { 113a8918085Smrg fprintf(stderr, "%s: unrecognized option '%s'\n", 114a8918085Smrg argv[0], argv[i]); 115a8918085Smrg usage(argv[0], NULL); 11621c2f794Smrg } 11721c2f794Smrg } 11821c2f794Smrg 11921c2f794Smrg if (fontName == NULL) 120a8918085Smrg usage(argv[0], "No font name specified"); 12121c2f794Smrg 12221c2f794Smrg fontServer = FSOpenServer(serverName); 12321c2f794Smrg if (!fontServer) { 1247d7e1abdSmrg const char *sn = FSServerName(serverName); 12521c2f794Smrg if (sn) 12621c2f794Smrg fprintf(stderr, "%s: can't open font server \"%s\"\n", 12721c2f794Smrg argv[0], sn); 12821c2f794Smrg else 129a8918085Smrg usage(argv[0], "No font server specified."); 13021c2f794Smrg exit(0); 13121c2f794Smrg } 13221c2f794Smrg bitmapFormat = 0; 13321c2f794Smrg fontID = FSOpenBitmapFont(fontServer, bitmapFormat, (FSBitmapFormatMask) 0, 13421c2f794Smrg fontName, &dummy); 13521c2f794Smrg if (!fontID) { 13621c2f794Smrg printf("can't open font \"%s\"\n", fontName); 13721c2f794Smrg exit(0); 13821c2f794Smrg } 13921c2f794Smrg FSQueryXInfo(fontServer, fontID, &fontHeader, &propInfo, &propOffsets, 14021c2f794Smrg &propData); 14121c2f794Smrg 14221c2f794Smrg if (!EmitHeader(outFile, &fontHeader, &propInfo, propOffsets, propData)) 14321c2f794Smrg Fail(argv[0]); 14421c2f794Smrg if (!EmitProperties(outFile, &fontHeader, &propInfo, propOffsets, propData)) 14521c2f794Smrg Fail(argv[0]); 14621c2f794Smrg if (!EmitCharacters(outFile, fontServer, &fontHeader, fontID)) 14721c2f794Smrg Fail(argv[0]); 14821c2f794Smrg fprintf(outFile, "ENDFONT\n"); 14921c2f794Smrg 15021c2f794Smrg FSFree((char *) propOffsets); 15121c2f794Smrg FSFree((char *) propData); 15221c2f794Smrg exit (0); 15321c2f794Smrg} 154