10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
320Sstevel@tonic-gate * The Regents of the University of California
330Sstevel@tonic-gate * All Rights Reserved
340Sstevel@tonic-gate *
350Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
360Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
370Sstevel@tonic-gate * contributors.
380Sstevel@tonic-gate */
390Sstevel@tonic-gate
40*217Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
41*217Smuffin
420Sstevel@tonic-gate /* Note added 9/25/83
430Sstevel@tonic-gate Setting the parameter biggestfont in the DESC file
440Sstevel@tonic-gate to be at least as big as the number of characters
450Sstevel@tonic-gate in the largest font for a particular device
460Sstevel@tonic-gate eliminates the "font X too big for position Y"
470Sstevel@tonic-gate message from troff.
480Sstevel@tonic-gate Thanks to Dave Stephens, WECo.
490Sstevel@tonic-gate */
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate makedev:
520Sstevel@tonic-gate read text info about a particular device
530Sstevel@tonic-gate (e.g., cat, 202, aps5) from file, convert
540Sstevel@tonic-gate it into internal (binary) form suitable for
550Sstevel@tonic-gate fast reading by troff initialization (ptinit()).
560Sstevel@tonic-gate
570Sstevel@tonic-gate Usage:
580Sstevel@tonic-gate
590Sstevel@tonic-gate makedev DESC [ F ... ]
600Sstevel@tonic-gate uses DESC to create a description file
610Sstevel@tonic-gate using the information therein.
620Sstevel@tonic-gate It creates the file DESC.out.
630Sstevel@tonic-gate
640Sstevel@tonic-gate makedev F ...
650Sstevel@tonic-gate makes the font tables for fonts F only,
660Sstevel@tonic-gate creates files F.out.
670Sstevel@tonic-gate
680Sstevel@tonic-gate DESC.out contains:
690Sstevel@tonic-gate dev structure with fundamental sizes
700Sstevel@tonic-gate list of sizes (nsizes+1) terminated by 0, as short's
710Sstevel@tonic-gate indices of char names (nchtab * sizeof(short))
720Sstevel@tonic-gate char names as hy\0em\0... (lchname)
730Sstevel@tonic-gate nfonts occurrences of
740Sstevel@tonic-gate widths (nwidth)
750Sstevel@tonic-gate kerning (nwidth) [ascender+descender only so far]
760Sstevel@tonic-gate codes (nwidth) to drive actual typesetter
770Sstevel@tonic-gate fitab (nchtab+128-32)
780Sstevel@tonic-gate each of these is an array of char.
790Sstevel@tonic-gate
800Sstevel@tonic-gate dev.filesize contains the number of bytes
810Sstevel@tonic-gate in the file, excluding the dev part itself.
820Sstevel@tonic-gate
830Sstevel@tonic-gate F.out contains the font header, width, kern, codes, and fitab.
840Sstevel@tonic-gate Width, kern and codes are parallel arrays.
850Sstevel@tonic-gate (Which suggests that they ought to be together?)
860Sstevel@tonic-gate Later, we might allow for codes which are actually
870Sstevel@tonic-gate sequences of formatting info so characters can be drawn.
880Sstevel@tonic-gate */
890Sstevel@tonic-gate
900Sstevel@tonic-gate #include "stdio.h"
910Sstevel@tonic-gate #include "dev.h"
920Sstevel@tonic-gate
930Sstevel@tonic-gate #define BYTEMASK 0377
940Sstevel@tonic-gate #define skipline(f) while(getc(f) != '\n')
950Sstevel@tonic-gate
960Sstevel@tonic-gate struct dev dev;
970Sstevel@tonic-gate struct Font font;
980Sstevel@tonic-gate
990Sstevel@tonic-gate #define NSIZE 100 /* maximum number of sizes */
1000Sstevel@tonic-gate short size[NSIZE];
1010Sstevel@tonic-gate #define NCH 256 /* max number of characters with funny names */
1020Sstevel@tonic-gate char chname[5*NCH]; /* character names, including \0 for each */
1030Sstevel@tonic-gate short chtab[NCH]; /* index of character in chname */
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate #define NFITAB (NCH + 128-32) /* includes ascii chars, but not non-graphics */
1060Sstevel@tonic-gate char fitab[NFITAB]; /* font index table: position of char i on this font. */
1070Sstevel@tonic-gate /* zero if not there */
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate #define FSIZE 256 /* size of a physical font (e.g., 102 for cat) */
1100Sstevel@tonic-gate char width[FSIZE]; /* width table for a physical font */
1110Sstevel@tonic-gate char kern[FSIZE]; /* ascender+descender info */
1120Sstevel@tonic-gate char code[FSIZE]; /* actual device codes for a physical font */
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate #define NFONT 60 /* max number of default fonts */
1150Sstevel@tonic-gate char fname[NFONT][10]; /* temp space to hold default font names */
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate int fflag = 0; /* on if font table to be written */
1180Sstevel@tonic-gate int fdout; /* output file descriptor */
1190Sstevel@tonic-gate char *fout = "DESC.out";
1200Sstevel@tonic-gate
main(int argc,char * argv[])1210Sstevel@tonic-gate int main(int argc, char *argv[])
1220Sstevel@tonic-gate {
1230Sstevel@tonic-gate FILE *fin;
1240Sstevel@tonic-gate char cmd[100], *p;
1250Sstevel@tonic-gate int i, totfont, v;
1260Sstevel@tonic-gate
1270Sstevel@tonic-gate if (argc < 2) {
1280Sstevel@tonic-gate fprintf(stderr, "Usage: makedev [DESC] [fonts]\n");
1290Sstevel@tonic-gate exit(1);
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate if ((fin = fopen("DESC", "r")) == NULL) {
1330Sstevel@tonic-gate fprintf(stderr, "makedev: can't open %s\n", argv[1]);
1340Sstevel@tonic-gate exit(1);
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate while (fscanf(fin, "%s", cmd) != EOF) {
1370Sstevel@tonic-gate if (cmd[0] == '#') /* comment */
1380Sstevel@tonic-gate skipline(fin);
1390Sstevel@tonic-gate else if (strcmp(cmd, "res") == 0) {
1400Sstevel@tonic-gate fscanf(fin, "%hd", &dev.res);
1410Sstevel@tonic-gate } else if (strcmp(cmd, "hor") == 0) {
1420Sstevel@tonic-gate fscanf(fin, "%hd", &dev.hor);
1430Sstevel@tonic-gate } else if (strcmp(cmd, "vert") == 0) {
1440Sstevel@tonic-gate fscanf(fin, "%hd", &dev.vert);
1450Sstevel@tonic-gate } else if (strcmp(cmd, "unitwidth") == 0) {
1460Sstevel@tonic-gate fscanf(fin, "%hd", &dev.unitwidth);
1470Sstevel@tonic-gate } else if (strcmp(cmd, "sizescale") == 0) {
1480Sstevel@tonic-gate fscanf(fin, "%hd", &dev.sizescale);
1490Sstevel@tonic-gate } else if (strcmp(cmd, "paperwidth") == 0) {
1500Sstevel@tonic-gate fscanf(fin, "%hd", &dev.paperwidth);
1510Sstevel@tonic-gate } else if (strcmp(cmd, "paperlength") == 0) {
1520Sstevel@tonic-gate fscanf(fin, "%hd", &dev.paperlength);
1530Sstevel@tonic-gate } else if (strcmp(cmd, "biggestfont") == 0) {
1540Sstevel@tonic-gate fscanf(fin, "%hd", &dev.biggestfont);
1550Sstevel@tonic-gate } else if (strcmp(cmd, "spare2") == 0) {
1560Sstevel@tonic-gate fscanf(fin, "%hd", &dev.spare2);
1570Sstevel@tonic-gate } else if (strcmp(cmd, "sizes") == 0) {
1580Sstevel@tonic-gate dev.nsizes = 0;
1590Sstevel@tonic-gate while (fscanf(fin, "%d", &v) != EOF && v != 0)
1600Sstevel@tonic-gate size[dev.nsizes++] = v;
1610Sstevel@tonic-gate size[dev.nsizes] = 0; /* need an extra 0 at the end */
1620Sstevel@tonic-gate } else if (strcmp(cmd, "fonts") == 0) {
1630Sstevel@tonic-gate fscanf(fin, "%hd", &dev.nfonts);
1640Sstevel@tonic-gate for (i = 0; i < dev.nfonts; i++)
1650Sstevel@tonic-gate fscanf(fin, "%s", fname[i]);
1660Sstevel@tonic-gate } else if (strcmp(cmd, "charset") == 0) {
1670Sstevel@tonic-gate p = chname;
1680Sstevel@tonic-gate dev.nchtab = 0;
1690Sstevel@tonic-gate while (fscanf(fin, "%s", p) != EOF) {
1700Sstevel@tonic-gate chtab[dev.nchtab++] = p - chname;
1710Sstevel@tonic-gate while (*p++) /* skip to end of name */
1720Sstevel@tonic-gate ;
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate dev.lchname = p - chname;
1750Sstevel@tonic-gate chtab[dev.nchtab++] = 0; /* terminate properly */
1760Sstevel@tonic-gate } else
1770Sstevel@tonic-gate fprintf(stderr, "makedev: unknown command %s\n", cmd);
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate if (argc > 0 && strcmp(argv[1], "DESC") == 0) {
1800Sstevel@tonic-gate fdout = creat(fout, 0666);
1810Sstevel@tonic-gate if (fdout < 0) {
1820Sstevel@tonic-gate fprintf(stderr, "makedev: can't open %s\n", fout);
1830Sstevel@tonic-gate exit(1);
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate write(fdout, &dev, sizeof(struct dev));
1860Sstevel@tonic-gate write(fdout, size, (dev.nsizes+1) * sizeof(size[0])); /* we need a 0 on the end */
1870Sstevel@tonic-gate write(fdout, chtab, dev.nchtab * sizeof(chtab[0]));
1880Sstevel@tonic-gate write(fdout, chname, dev.lchname);
1890Sstevel@tonic-gate totfont = 0;
1900Sstevel@tonic-gate for (i = 0; i < dev.nfonts; i++) {
1910Sstevel@tonic-gate totfont += dofont(fname[i]);
1920Sstevel@tonic-gate write(fdout, &font, sizeof(struct Font));
1930Sstevel@tonic-gate write(fdout, width, font.nwfont & BYTEMASK);
1940Sstevel@tonic-gate write(fdout, kern, font.nwfont & BYTEMASK);
1950Sstevel@tonic-gate write(fdout, code, font.nwfont & BYTEMASK);
1960Sstevel@tonic-gate write(fdout, fitab, dev.nchtab+128-32);
1970Sstevel@tonic-gate }
1980Sstevel@tonic-gate lseek(fdout, 0L, 0); /* back to beginning to install proper size */
1990Sstevel@tonic-gate dev.filesize = /* excluding dev struct itself */
2000Sstevel@tonic-gate (dev.nsizes+1) * sizeof(size[0])
2010Sstevel@tonic-gate + dev.nchtab * sizeof(chtab[0])
2020Sstevel@tonic-gate + dev.lchname * sizeof(char)
2030Sstevel@tonic-gate + totfont * sizeof(char);
2040Sstevel@tonic-gate write(fdout, &dev, sizeof(struct dev));
2050Sstevel@tonic-gate close(fdout);
2060Sstevel@tonic-gate argc--;
2070Sstevel@tonic-gate argv++;
2080Sstevel@tonic-gate }
2090Sstevel@tonic-gate for (i = 1; i < argc; i++)
2100Sstevel@tonic-gate dofont(argv[i]);
2110Sstevel@tonic-gate exit(0);
212*217Smuffin
213*217Smuffin return (0);
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate
216*217Smuffin int
dofont(name)2170Sstevel@tonic-gate dofont(name) /* create fitab and width tab for font */
2180Sstevel@tonic-gate char *name;
2190Sstevel@tonic-gate {
2200Sstevel@tonic-gate FILE *fin;
2210Sstevel@tonic-gate int fdout;
2220Sstevel@tonic-gate int i, nw, spacewidth, n, v;
2230Sstevel@tonic-gate char buf[100], ch[10], s1[10], s2[10], s3[10], cmd[30];
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate if ((fin = fopen(name, "r")) == NULL) {
2260Sstevel@tonic-gate fprintf(stderr, "makedev: can't open font %s\n", name);
2270Sstevel@tonic-gate exit(2);
2280Sstevel@tonic-gate }
2290Sstevel@tonic-gate sprintf(cmd, "%s.out", name);
2300Sstevel@tonic-gate fdout = creat(cmd, 0666);
2310Sstevel@tonic-gate for (i = 0; i < NFITAB; i++)
2320Sstevel@tonic-gate fitab[i] = 0;
2330Sstevel@tonic-gate for (i = 0; i < FSIZE; i++)
2340Sstevel@tonic-gate width[i] = kern[i] = code[i] = 0;
2350Sstevel@tonic-gate font.specfont = font.ligfont = spacewidth = 0;
2360Sstevel@tonic-gate while (fscanf(fin, "%s", cmd) != EOF) {
2370Sstevel@tonic-gate if (cmd[0] == '#')
2380Sstevel@tonic-gate skipline(fin);
2390Sstevel@tonic-gate else if (strcmp(cmd, "name") == 0)
2400Sstevel@tonic-gate fscanf(fin, "%s", font.namefont);
2410Sstevel@tonic-gate else if (strcmp(cmd, "internalname") == 0)
2420Sstevel@tonic-gate fscanf(fin, "%s", font.intname);
2430Sstevel@tonic-gate else if (strcmp(cmd, "special") == 0)
2440Sstevel@tonic-gate font.specfont = 1;
2450Sstevel@tonic-gate else if (strcmp(cmd, "spare1") == 0)
2460Sstevel@tonic-gate fscanf(fin, "%1s", &font.spare1);
2470Sstevel@tonic-gate else if (strcmp(cmd, "ligatures") == 0) {
2480Sstevel@tonic-gate font.ligfont = getlig(fin);
2490Sstevel@tonic-gate } else if (strcmp(cmd, "spacewidth") == 0) {
2500Sstevel@tonic-gate fscanf(fin, "%d", &spacewidth);
2510Sstevel@tonic-gate width[0] = spacewidth; /* width of space on this font */
2520Sstevel@tonic-gate } else if (strcmp(cmd, "charset") == 0) {
2530Sstevel@tonic-gate skipline(fin);
2540Sstevel@tonic-gate nw = 0;
2550Sstevel@tonic-gate /* widths are origin 1 so fitab==0 can mean "not there" */
2560Sstevel@tonic-gate while (fgets(buf, 100, fin) != NULL) {
2570Sstevel@tonic-gate sscanf(buf, "%s %s %s %s", ch, s1, s2, s3);
2580Sstevel@tonic-gate if (s1[0] != '"') { /* it's a genuine new character */
2590Sstevel@tonic-gate nw++;
2600Sstevel@tonic-gate width[nw] = atoi(s1);
2610Sstevel@tonic-gate kern[nw] = atoi(s2);
2620Sstevel@tonic-gate /* temporarily, pick up one byte as code */
2630Sstevel@tonic-gate if (s3[0] == '0')
2640Sstevel@tonic-gate sscanf(s3, "%o", &i);
2650Sstevel@tonic-gate else
2660Sstevel@tonic-gate sscanf(s3, "%d", &i);
2670Sstevel@tonic-gate code[nw] = i;
2680Sstevel@tonic-gate }
269*217Smuffin /*
270*217Smuffin * otherwise it's a synonym for previous character,
271*217Smuffin * so leave previous values intact
2720Sstevel@tonic-gate */
2730Sstevel@tonic-gate if (strlen(ch) == 1) /* it's ascii */
2740Sstevel@tonic-gate fitab[ch[0] - 32] = nw; /* fitab origin omits non-graphics */
2750Sstevel@tonic-gate else { /* it has a funny name */
2760Sstevel@tonic-gate for (i = 0; i < dev.nchtab; i++)
2770Sstevel@tonic-gate if (strcmp(&chname[chtab[i]], ch) == 0) {
2780Sstevel@tonic-gate fitab[i + 128-32] = nw; /* starts after the ascii */
2790Sstevel@tonic-gate break;
2800Sstevel@tonic-gate }
2810Sstevel@tonic-gate if (i >= dev.nchtab)
2820Sstevel@tonic-gate fprintf(stderr, "makedev: font %s: %s not in charset\n", name, ch);
2830Sstevel@tonic-gate }
2840Sstevel@tonic-gate }
2850Sstevel@tonic-gate nw++;
2860Sstevel@tonic-gate if (dev.biggestfont >= nw)
2870Sstevel@tonic-gate n = dev.biggestfont;
2880Sstevel@tonic-gate else {
2890Sstevel@tonic-gate if (dev.biggestfont > 0)
2900Sstevel@tonic-gate fprintf(stderr, "font %s too big\n", name);
2910Sstevel@tonic-gate n = nw;
2920Sstevel@tonic-gate }
2930Sstevel@tonic-gate font.nwfont = n;
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate }
2960Sstevel@tonic-gate if (spacewidth == 0)
2970Sstevel@tonic-gate width[0] = dev.res * dev.unitwidth / 72 / 3;
2980Sstevel@tonic-gate fclose(fin);
2990Sstevel@tonic-gate
3000Sstevel@tonic-gate write(fdout, &font, sizeof(struct Font));
3010Sstevel@tonic-gate write(fdout, width, font.nwfont & BYTEMASK);
3020Sstevel@tonic-gate write(fdout, kern, font.nwfont & BYTEMASK);
3030Sstevel@tonic-gate write(fdout, code, font.nwfont & BYTEMASK);
3040Sstevel@tonic-gate write(fdout, fitab, dev.nchtab+128-32);
3050Sstevel@tonic-gate close(fdout);
3060Sstevel@tonic-gate v = sizeof(struct Font) + 3 * n + dev.nchtab + 128-32;
3070Sstevel@tonic-gate fprintf(stderr, "%3s: %3d chars, width %3d, size %3d\n",
3080Sstevel@tonic-gate font.namefont, nw, width[0], v);
3090Sstevel@tonic-gate return v;
3100Sstevel@tonic-gate }
3110Sstevel@tonic-gate
312*217Smuffin int
getlig(fin)3130Sstevel@tonic-gate getlig(fin) /* pick up ligature list */
3140Sstevel@tonic-gate FILE *fin;
3150Sstevel@tonic-gate {
3160Sstevel@tonic-gate int lig;
3170Sstevel@tonic-gate char temp[100];
3180Sstevel@tonic-gate
3190Sstevel@tonic-gate lig = 0;
3200Sstevel@tonic-gate while (fscanf(fin, "%s", temp) != EOF && strcmp(temp, "0") != 0) {
3210Sstevel@tonic-gate if (strcmp(temp, "fi") == 0)
3220Sstevel@tonic-gate lig |= LFI;
3230Sstevel@tonic-gate else if (strcmp(temp, "fl") == 0)
3240Sstevel@tonic-gate lig |= LFL;
3250Sstevel@tonic-gate else if (strcmp(temp, "ff") == 0)
3260Sstevel@tonic-gate lig |= LFF;
3270Sstevel@tonic-gate else if (strcmp(temp, "ffi") == 0)
3280Sstevel@tonic-gate lig |= LFFI;
3290Sstevel@tonic-gate else if (strcmp(temp, "ffl") == 0)
3300Sstevel@tonic-gate lig |= LFFL;
3310Sstevel@tonic-gate else
3320Sstevel@tonic-gate fprintf(stderr, "illegal ligature %s\n", temp);
3330Sstevel@tonic-gate }
3340Sstevel@tonic-gate skipline(fin);
3350Sstevel@tonic-gate return lig;
3360Sstevel@tonic-gate }
337