bdftopcf.c revision 29459361
129459361Smrg/* $Xorg: bdftopcf.c,v 1.4 2001/02/09 02:05:28 xorgcvs Exp $ */
229459361Smrg/*
329459361Smrg
429459361SmrgCopyright 1991, 1993, 1998  The Open Group
529459361Smrg
629459361SmrgPermission to use, copy, modify, distribute, and sell this software and its
729459361Smrgdocumentation for any purpose is hereby granted without fee, provided that
829459361Smrgthe above copyright notice appear in all copies and that both that
929459361Smrgcopyright notice and this permission notice appear in supporting
1029459361Smrgdocumentation.
1129459361Smrg
1229459361SmrgThe above copyright notice and this permission notice shall be included
1329459361Smrgin all copies or substantial portions of the Software.
1429459361Smrg
1529459361SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1629459361SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1729459361SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1829459361SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
1929459361SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2029459361SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2129459361SmrgOTHER DEALINGS IN THE SOFTWARE.
2229459361Smrg
2329459361SmrgExcept as contained in this notice, the name of The Open Group shall
2429459361Smrgnot be used in advertising or otherwise to promote the sale, use or
2529459361Smrgother dealings in this Software without prior written authorization
2629459361Smrgfrom The Open Group.
2729459361Smrg
2829459361Smrg*/
2929459361Smrg
3029459361Smrg/* $XFree86: xc/programs/bdftopcf/bdftopcf.c,v 1.4 2001/08/01 00:45:00 tsi Exp $ */
3129459361Smrg
3229459361Smrg#include <X11/X.h>
3329459361Smrg#include <X11/Xproto.h>
3429459361Smrg#include <X11/fonts/fontmisc.h>
3529459361Smrg#include <X11/fonts/fontstruct.h>
3629459361Smrg#include <X11/fonts/fntfilio.h>
3729459361Smrg#include <X11/fonts/fntfil.h>
3829459361Smrg#include <X11/fonts/bdfint.h>
3929459361Smrg#include <X11/fonts/pcf.h>
4029459361Smrg#include <stdio.h>
4129459361Smrg#include <X11/Xos.h>
4229459361Smrg
4329459361Smrgint
4429459361Smrgmain (int argc, char *argv[])
4529459361Smrg{
4629459361Smrg    FontRec font;
4729459361Smrg    FontFilePtr	input, output;
4829459361Smrg    char    *input_name = NULL, *output_name = NULL;
4929459361Smrg    char    *program_name;
5029459361Smrg    int	    bit, byte, glyph, scan;
5129459361Smrg
5229459361Smrg    bzero(&font, sizeof(FontRec));
5329459361Smrg
5429459361Smrg    FontDefaultFormat (&bit, &byte, &glyph, &scan);
5529459361Smrg    program_name = argv[0];
5629459361Smrg    argc--, argv++;
5729459361Smrg    while (argc-- > 0) {
5829459361Smrg	if (argv[0][0] == '-') {
5929459361Smrg	    switch (argv[0][1]) {
6029459361Smrg	    case 'p':
6129459361Smrg		switch (argv[0][2]) {
6229459361Smrg		case '1':
6329459361Smrg		case '2':
6429459361Smrg		case '4':
6529459361Smrg		case '8':
6629459361Smrg		    if (argv[0][3] != '\0')
6729459361Smrg			goto usage;
6829459361Smrg		    glyph = argv[0][2] - '0';
6929459361Smrg		    break;
7029459361Smrg		default:
7129459361Smrg		    goto usage;
7229459361Smrg		}
7329459361Smrg		break;
7429459361Smrg
7529459361Smrg	    case 'u':
7629459361Smrg		switch (argv[0][2]) {
7729459361Smrg		case '1':
7829459361Smrg		case '2':
7929459361Smrg		case '4':
8029459361Smrg		    if (argv[0][3] != '\0')
8129459361Smrg			goto usage;
8229459361Smrg		    scan = argv[0][2] - '0';
8329459361Smrg		    break;
8429459361Smrg		default:
8529459361Smrg		    goto usage;
8629459361Smrg		}
8729459361Smrg		break;
8829459361Smrg
8929459361Smrg	    case 'm':
9029459361Smrg		if (argv[0][2] != '\0')
9129459361Smrg		    goto usage;
9229459361Smrg		bit = MSBFirst;
9329459361Smrg		break;
9429459361Smrg
9529459361Smrg	    case 'l':
9629459361Smrg		if (argv[0][2] != '\0')
9729459361Smrg		    goto usage;
9829459361Smrg		bit = LSBFirst;
9929459361Smrg		break;
10029459361Smrg
10129459361Smrg	    case 'M':
10229459361Smrg		if (argv[0][2] != '\0')
10329459361Smrg		    goto usage;
10429459361Smrg		byte = MSBFirst;
10529459361Smrg		break;
10629459361Smrg
10729459361Smrg	    case 'L':
10829459361Smrg		if (argv[0][2] != '\0')
10929459361Smrg		    goto usage;
11029459361Smrg		byte = LSBFirst;
11129459361Smrg		break;
11229459361Smrg
11329459361Smrg	    case 't':	/* attempt to make terminal fonts if possible */
11429459361Smrg		if (argv[0][2] != '\0')
11529459361Smrg		    goto usage;
11629459361Smrg		break;
11729459361Smrg
11829459361Smrg	    case 'i':	/* inhibit ink metric computation */
11929459361Smrg		if (argv[0][2] != '\0')
12029459361Smrg		    goto usage;
12129459361Smrg		break;
12229459361Smrg	    case 'o':
12329459361Smrg		if (argv[0][2])
12429459361Smrg		    output_name = argv[0] + 2;
12529459361Smrg		else
12629459361Smrg		{
12729459361Smrg		    if (!argv[1])
12829459361Smrg			goto usage;
12929459361Smrg		    argv++;
13029459361Smrg		    argc--;
13129459361Smrg		    output_name = argv[0];
13229459361Smrg		}
13329459361Smrg		break;
13429459361Smrg	    default:
13529459361Smrg		goto usage;
13629459361Smrg	    }
13729459361Smrg	} else {
13829459361Smrg	    if (input_name)
13929459361Smrg	    {
14029459361Smrg	usage:
14129459361Smrg		fprintf(stderr,
14229459361Smrg	"usage: %s [-p#] [-u#] [-m] [-l] [-M] [-L] [-t] [-i] [-o pcf file] [bdf file]\n",
14329459361Smrg			program_name);
14429459361Smrg		fprintf(stderr,
14529459361Smrg			"       where # for -p is 1, 2, 4, or 8\n");
14629459361Smrg		fprintf(stderr,
14729459361Smrg			"       and   # for -s is 1, 2, or 4\n");
14829459361Smrg		exit(1);
14929459361Smrg	    }
15029459361Smrg	    input_name = argv[0];
15129459361Smrg	}
15229459361Smrg	argv++;
15329459361Smrg    }
15429459361Smrg    if (input_name)
15529459361Smrg    {
15629459361Smrg    	input = FontFileOpen (input_name);
15729459361Smrg    	if (!input)
15829459361Smrg    	{
15929459361Smrg	    fprintf (stderr, "%s: can't open bdf source file %s\n",
16029459361Smrg		     program_name, input_name);
16129459361Smrg	    exit (1);
16229459361Smrg    	}
16329459361Smrg    }
16429459361Smrg    else
16529459361Smrg	input = FontFileOpenFd (0);
16629459361Smrg    if (bdfReadFont (&font, input, bit, byte, glyph, scan) != Successful)
16729459361Smrg    {
16829459361Smrg	fprintf (stderr, "%s: bdf input, %s, corrupt\n",
16929459361Smrg		 program_name, input_name ? input_name : "<stdin>");
17029459361Smrg	exit (1);
17129459361Smrg    }
17229459361Smrg    if (output_name)
17329459361Smrg    {
17429459361Smrg	output = FontFileOpenWrite (output_name);
17529459361Smrg    	if (!output)
17629459361Smrg    	{
17729459361Smrg	    fprintf (stderr, "%s: can't open pcf sink file %s\n",
17829459361Smrg		     program_name, output_name);
17929459361Smrg	    exit (1);
18029459361Smrg    	}
18129459361Smrg    }
18229459361Smrg    else
18329459361Smrg	output = FontFileOpenWriteFd (1);
18429459361Smrg    if (pcfWriteFont (&font, output) != Successful)
18529459361Smrg    {
18629459361Smrg	fprintf (stderr, "%s: can't write pcf file %s\n",
18729459361Smrg		 program_name, output_name ? output_name : "<stdout>");
18829459361Smrg	if (output_name)
18929459361Smrg	    unlink (output_name);
19029459361Smrg	exit (1);
19129459361Smrg    }
19229459361Smrg    else
19329459361Smrg	FontFileClose (output);
19429459361Smrg    return (0);
19529459361Smrg}
196