fstobdf.c revision a5c37dfe
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 4621c2f794Smrg#include <stdio.h> 4721c2f794Smrg#include <stdlib.h> 4821c2f794Smrg#include <string.h> 4921c2f794Smrg#include "fstobdf.h" 50a5c37dfeSmrg 51a5c37dfeSmrg 52a5c37dfeSmrgstatic void _X_NORETURN 5321c2f794Smrgusage(char *progName) 5421c2f794Smrg{ 5521c2f794Smrg fprintf(stderr, "Usage: %s [-s <font server>] -fn <font name>\n", 5621c2f794Smrg progName); 5721c2f794Smrg exit(0); 5821c2f794Smrg} 5921c2f794Smrg 60a5c37dfeSmrgstatic void _X_NORETURN 6121c2f794SmrgFail(char *progName) 6221c2f794Smrg{ 6321c2f794Smrg fprintf(stderr, "%s: unable to dump font\n", progName); 6421c2f794Smrg exit(1); 6521c2f794Smrg} 6621c2f794Smrg 6721c2f794Smrgint 6821c2f794Smrgmain(int argc, char *argv[]) 6921c2f794Smrg{ 7021c2f794Smrg FSServer *fontServer; 7121c2f794Smrg Font fontID, 7221c2f794Smrg dummy; 7321c2f794Smrg FSBitmapFormat bitmapFormat; 7421c2f794Smrg FSXFontInfoHeader fontHeader; 7521c2f794Smrg FSPropInfo propInfo; 7621c2f794Smrg FSPropOffset *propOffsets; 7721c2f794Smrg unsigned char *propData; 7821c2f794Smrg 7921c2f794Smrg FILE *outFile; 8021c2f794Smrg char *fontName; 8121c2f794Smrg char *serverName; 8221c2f794Smrg int i; 8321c2f794Smrg 8421c2f794Smrg fontName = NULL; 8521c2f794Smrg serverName = NULL; 8621c2f794Smrg outFile = stdout; 8721c2f794Smrg 8821c2f794Smrg for (i = 1; i < argc; i++) { 8921c2f794Smrg if (!strncmp(argv[i], "-s", 2)) { 9021c2f794Smrg if (argv[++i]) 9121c2f794Smrg serverName = argv[i]; 9221c2f794Smrg else 9321c2f794Smrg usage(argv[0]); 9421c2f794Smrg } else if (!strncmp(argv[i], "-fn", 3)) { 9521c2f794Smrg if (argv[++i]) 9621c2f794Smrg fontName = argv[i]; 9721c2f794Smrg else 9821c2f794Smrg usage(argv[0]); 9921c2f794Smrg } 10021c2f794Smrg } 10121c2f794Smrg 10221c2f794Smrg if (fontName == NULL) 10321c2f794Smrg usage(argv[0]); 10421c2f794Smrg 10521c2f794Smrg fontServer = FSOpenServer(serverName); 10621c2f794Smrg if (!fontServer) { 1077d7e1abdSmrg const char *sn = FSServerName(serverName); 10821c2f794Smrg if (sn) 10921c2f794Smrg fprintf(stderr, "%s: can't open font server \"%s\"\n", 11021c2f794Smrg argv[0], sn); 11121c2f794Smrg else 11221c2f794Smrg fprintf(stderr, "%s: No font server specified.\n", 11321c2f794Smrg argv[0]); 11421c2f794Smrg exit(0); 11521c2f794Smrg } 11621c2f794Smrg bitmapFormat = 0; 11721c2f794Smrg fontID = FSOpenBitmapFont(fontServer, bitmapFormat, (FSBitmapFormatMask) 0, 11821c2f794Smrg fontName, &dummy); 11921c2f794Smrg if (!fontID) { 12021c2f794Smrg printf("can't open font \"%s\"\n", fontName); 12121c2f794Smrg exit(0); 12221c2f794Smrg } 12321c2f794Smrg FSQueryXInfo(fontServer, fontID, &fontHeader, &propInfo, &propOffsets, 12421c2f794Smrg &propData); 12521c2f794Smrg 12621c2f794Smrg if (!EmitHeader(outFile, &fontHeader, &propInfo, propOffsets, propData)) 12721c2f794Smrg Fail(argv[0]); 12821c2f794Smrg if (!EmitProperties(outFile, &fontHeader, &propInfo, propOffsets, propData)) 12921c2f794Smrg Fail(argv[0]); 13021c2f794Smrg if (!EmitCharacters(outFile, fontServer, &fontHeader, fontID)) 13121c2f794Smrg Fail(argv[0]); 13221c2f794Smrg fprintf(outFile, "ENDFONT\n"); 13321c2f794Smrg 13421c2f794Smrg FSFree((char *) propOffsets); 13521c2f794Smrg FSFree((char *) propData); 13621c2f794Smrg exit (0); 13721c2f794Smrg} 138