Home | History | Annotate | Line # | Download | only in dist
      1 /*
      2 
      3 Copyright 1990, 1998  The Open Group
      4 
      5 Permission to use, copy, modify, distribute, and sell this software and its
      6 documentation for any purpose is hereby granted without fee, provided that
      7 the above copyright notice appear in all copies and that both that
      8 copyright notice and this permission notice appear in supporting
      9 documentation.
     10 
     11 The above copyright notice and this permission notice shall be included in
     12 all copies or substantial portions of the Software.
     13 
     14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
     18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     20 
     21 Except as contained in this notice, the name of The Open Group shall not be
     22 used in advertising or otherwise to promote the sale, use or other dealings
     23 in 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 #ifdef HAVE_CONFIG_H
     47 #include "config.h"
     48 #endif
     49 
     50 #include	<stdio.h>
     51 #include	<stdlib.h>
     52 #include        <string.h>
     53 #include	"fstobdf.h"
     54 
     55 
     56 static void _X_NORETURN _X_COLD
     57 usage(const char *progName, const char *msg)
     58 {
     59     if (msg)
     60         fprintf(stderr, "%s: %s\n", progName, msg);
     61     fprintf(stderr,
     62             "Usage: %s [-server <font server>] -fn <font name>\n"
     63             "	or: %s -version\n", progName, progName);
     64     exit(0);
     65 }
     66 
     67 static void _X_NORETURN _X_COLD
     68 Fail(const char *progName)
     69 {
     70     fprintf(stderr, "%s: unable to dump font\n", progName);
     71     exit(1);
     72 }
     73 
     74 int
     75 main(int argc, char *argv[])
     76 {
     77     FSServer *fontServer;
     78     Font fontID, dummy;
     79     FSBitmapFormat bitmapFormat;
     80     FSXFontInfoHeader fontHeader;
     81     FSPropInfo propInfo;
     82     FSPropOffset *propOffsets;
     83     unsigned char *propData;
     84 
     85     FILE *outFile;
     86     char *fontName;
     87     char *serverName;
     88     int i;
     89 
     90     fontName = NULL;
     91     serverName = NULL;
     92     outFile = stdout;
     93 
     94     for (i = 1; i < argc; i++) {
     95         if (!strncmp(argv[i], "-s", 2)) {
     96             if (argv[++i])
     97                 serverName = argv[i];
     98             else
     99                 usage(argv[0], "-server requires an argument");
    100         }
    101         else if (!strncmp(argv[i], "-fn", 3)) {
    102             if (argv[++i])
    103                 fontName = argv[i];
    104             else
    105                 usage(argv[0], "-fn requires an argument");
    106         }
    107         else if (!strcmp(argv[i], "-version")) {
    108             printf("%s\n", PACKAGE_STRING);
    109             exit(0);
    110         }
    111         else {
    112             fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], argv[i]);
    113             usage(argv[0], NULL);
    114         }
    115     }
    116 
    117     if (fontName == NULL)
    118         usage(argv[0], "No font name specified");
    119 
    120     fontServer = FSOpenServer(serverName);
    121     if (!fontServer) {
    122         const char *sn = FSServerName(serverName);
    123 
    124         if (sn)
    125             fprintf(stderr, "%s: can't open font server \"%s\"\n", argv[0], sn);
    126         else
    127             usage(argv[0], "No font server specified.");
    128         exit(0);
    129     }
    130     bitmapFormat = 0;
    131     fontID = FSOpenBitmapFont(fontServer, bitmapFormat, (FSBitmapFormatMask) 0,
    132                               fontName, &dummy);
    133     if (!fontID) {
    134         printf("can't open font \"%s\"\n", fontName);
    135         exit(0);
    136     }
    137     FSQueryXInfo(fontServer, fontID, &fontHeader, &propInfo, &propOffsets,
    138                  &propData);
    139 
    140     if (!EmitHeader(outFile, &fontHeader, &propInfo, propOffsets, propData))
    141         Fail(argv[0]);
    142     if (!EmitProperties(outFile, &fontHeader, &propInfo, propOffsets, propData))
    143         Fail(argv[0]);
    144     if (!EmitCharacters(outFile, fontServer, &fontHeader, fontID))
    145         Fail(argv[0]);
    146     fprintf(outFile, "ENDFONT\n");
    147 
    148     FSFree((char *) propOffsets);
    149     FSFree((char *) propData);
    150     exit(0);
    151 }
    152