1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 1989 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*0Sstevel@tonic-gate /* All Rights Reserved */ 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate /* 34*0Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 35*0Sstevel@tonic-gate * The Regents of the University of California 36*0Sstevel@tonic-gate * All Rights Reserved 37*0Sstevel@tonic-gate * 38*0Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 39*0Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 40*0Sstevel@tonic-gate * contributors. 41*0Sstevel@tonic-gate */ 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate /* Note added 9/25/83 44*0Sstevel@tonic-gate Setting the parameter biggestfont in the DESC file 45*0Sstevel@tonic-gate to be at least as big as the number of characters 46*0Sstevel@tonic-gate in the largest font for a particular device 47*0Sstevel@tonic-gate eliminates the "font X too big for position Y" 48*0Sstevel@tonic-gate message from troff. 49*0Sstevel@tonic-gate Thanks to Dave Stephens, WECo. 50*0Sstevel@tonic-gate */ 51*0Sstevel@tonic-gate /* 52*0Sstevel@tonic-gate makedev: 53*0Sstevel@tonic-gate read text info about a particular device 54*0Sstevel@tonic-gate (e.g., cat, 202, aps5) from file, convert 55*0Sstevel@tonic-gate it into internal (binary) form suitable for 56*0Sstevel@tonic-gate fast reading by troff initialization (ptinit()). 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate Usage: 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate makedev DESC [ F ... ] 61*0Sstevel@tonic-gate uses DESC to create a description file 62*0Sstevel@tonic-gate using the information therein. 63*0Sstevel@tonic-gate It creates the file DESC.out. 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate makedev F ... 66*0Sstevel@tonic-gate makes the font tables for fonts F only, 67*0Sstevel@tonic-gate creates files F.out. 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate DESC.out contains: 70*0Sstevel@tonic-gate dev structure with fundamental sizes 71*0Sstevel@tonic-gate list of sizes (nsizes+1) terminated by 0, as short's 72*0Sstevel@tonic-gate indices of char names (nchtab * sizeof(short)) 73*0Sstevel@tonic-gate char names as hy\0em\0... (lchname) 74*0Sstevel@tonic-gate nfonts occurrences of 75*0Sstevel@tonic-gate widths (nwidth) 76*0Sstevel@tonic-gate kerning (nwidth) [ascender+descender only so far] 77*0Sstevel@tonic-gate codes (nwidth) to drive actual typesetter 78*0Sstevel@tonic-gate fitab (nchtab+128-32) 79*0Sstevel@tonic-gate each of these is an array of char. 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate dev.filesize contains the number of bytes 82*0Sstevel@tonic-gate in the file, excluding the dev part itself. 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate F.out contains the font header, width, kern, codes, and fitab. 85*0Sstevel@tonic-gate Width, kern and codes are parallel arrays. 86*0Sstevel@tonic-gate (Which suggests that they ought to be together?) 87*0Sstevel@tonic-gate Later, we might allow for codes which are actually 88*0Sstevel@tonic-gate sequences of formatting info so characters can be drawn. 89*0Sstevel@tonic-gate */ 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate #include "stdio.h" 92*0Sstevel@tonic-gate #include "dev.h" 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate #define BYTEMASK 0377 95*0Sstevel@tonic-gate #define skipline(f) while(getc(f) != '\n') 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate struct dev dev; 98*0Sstevel@tonic-gate struct Font font; 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate #define NSIZE 100 /* maximum number of sizes */ 101*0Sstevel@tonic-gate short size[NSIZE]; 102*0Sstevel@tonic-gate #define NCH 256 /* max number of characters with funny names */ 103*0Sstevel@tonic-gate char chname[5*NCH]; /* character names, including \0 for each */ 104*0Sstevel@tonic-gate short chtab[NCH]; /* index of character in chname */ 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate #define NFITAB (NCH + 128-32) /* includes ascii chars, but not non-graphics */ 107*0Sstevel@tonic-gate char fitab[NFITAB]; /* font index table: position of char i on this font. */ 108*0Sstevel@tonic-gate /* zero if not there */ 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate #define FSIZE 256 /* size of a physical font (e.g., 102 for cat) */ 111*0Sstevel@tonic-gate char width[FSIZE]; /* width table for a physical font */ 112*0Sstevel@tonic-gate char kern[FSIZE]; /* ascender+descender info */ 113*0Sstevel@tonic-gate char code[FSIZE]; /* actual device codes for a physical font */ 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate #define NFONT 60 /* max number of default fonts */ 116*0Sstevel@tonic-gate char fname[NFONT][10]; /* temp space to hold default font names */ 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate int fflag = 0; /* on if font table to be written */ 119*0Sstevel@tonic-gate int fdout; /* output file descriptor */ 120*0Sstevel@tonic-gate char *fout = "DESC.out"; 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate int main(int argc, char *argv[]) 123*0Sstevel@tonic-gate { 124*0Sstevel@tonic-gate FILE *fin; 125*0Sstevel@tonic-gate char cmd[100], *p; 126*0Sstevel@tonic-gate int i, totfont, v; 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate if (argc < 2) { 129*0Sstevel@tonic-gate fprintf(stderr, "Usage: makedev [DESC] [fonts]\n"); 130*0Sstevel@tonic-gate exit(1); 131*0Sstevel@tonic-gate } 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate if ((fin = fopen("DESC", "r")) == NULL) { 134*0Sstevel@tonic-gate fprintf(stderr, "makedev: can't open %s\n", argv[1]); 135*0Sstevel@tonic-gate exit(1); 136*0Sstevel@tonic-gate } 137*0Sstevel@tonic-gate while (fscanf(fin, "%s", cmd) != EOF) { 138*0Sstevel@tonic-gate if (cmd[0] == '#') /* comment */ 139*0Sstevel@tonic-gate skipline(fin); 140*0Sstevel@tonic-gate else if (strcmp(cmd, "res") == 0) { 141*0Sstevel@tonic-gate fscanf(fin, "%hd", &dev.res); 142*0Sstevel@tonic-gate } else if (strcmp(cmd, "hor") == 0) { 143*0Sstevel@tonic-gate fscanf(fin, "%hd", &dev.hor); 144*0Sstevel@tonic-gate } else if (strcmp(cmd, "vert") == 0) { 145*0Sstevel@tonic-gate fscanf(fin, "%hd", &dev.vert); 146*0Sstevel@tonic-gate } else if (strcmp(cmd, "unitwidth") == 0) { 147*0Sstevel@tonic-gate fscanf(fin, "%hd", &dev.unitwidth); 148*0Sstevel@tonic-gate } else if (strcmp(cmd, "sizescale") == 0) { 149*0Sstevel@tonic-gate fscanf(fin, "%hd", &dev.sizescale); 150*0Sstevel@tonic-gate } else if (strcmp(cmd, "paperwidth") == 0) { 151*0Sstevel@tonic-gate fscanf(fin, "%hd", &dev.paperwidth); 152*0Sstevel@tonic-gate } else if (strcmp(cmd, "paperlength") == 0) { 153*0Sstevel@tonic-gate fscanf(fin, "%hd", &dev.paperlength); 154*0Sstevel@tonic-gate } else if (strcmp(cmd, "biggestfont") == 0) { 155*0Sstevel@tonic-gate fscanf(fin, "%hd", &dev.biggestfont); 156*0Sstevel@tonic-gate } else if (strcmp(cmd, "spare2") == 0) { 157*0Sstevel@tonic-gate fscanf(fin, "%hd", &dev.spare2); 158*0Sstevel@tonic-gate } else if (strcmp(cmd, "sizes") == 0) { 159*0Sstevel@tonic-gate dev.nsizes = 0; 160*0Sstevel@tonic-gate while (fscanf(fin, "%d", &v) != EOF && v != 0) 161*0Sstevel@tonic-gate size[dev.nsizes++] = v; 162*0Sstevel@tonic-gate size[dev.nsizes] = 0; /* need an extra 0 at the end */ 163*0Sstevel@tonic-gate } else if (strcmp(cmd, "fonts") == 0) { 164*0Sstevel@tonic-gate fscanf(fin, "%hd", &dev.nfonts); 165*0Sstevel@tonic-gate for (i = 0; i < dev.nfonts; i++) 166*0Sstevel@tonic-gate fscanf(fin, "%s", fname[i]); 167*0Sstevel@tonic-gate } else if (strcmp(cmd, "charset") == 0) { 168*0Sstevel@tonic-gate p = chname; 169*0Sstevel@tonic-gate dev.nchtab = 0; 170*0Sstevel@tonic-gate while (fscanf(fin, "%s", p) != EOF) { 171*0Sstevel@tonic-gate chtab[dev.nchtab++] = p - chname; 172*0Sstevel@tonic-gate while (*p++) /* skip to end of name */ 173*0Sstevel@tonic-gate ; 174*0Sstevel@tonic-gate } 175*0Sstevel@tonic-gate dev.lchname = p - chname; 176*0Sstevel@tonic-gate chtab[dev.nchtab++] = 0; /* terminate properly */ 177*0Sstevel@tonic-gate } else 178*0Sstevel@tonic-gate fprintf(stderr, "makedev: unknown command %s\n", cmd); 179*0Sstevel@tonic-gate } 180*0Sstevel@tonic-gate if (argc > 0 && strcmp(argv[1], "DESC") == 0) { 181*0Sstevel@tonic-gate fdout = creat(fout, 0666); 182*0Sstevel@tonic-gate if (fdout < 0) { 183*0Sstevel@tonic-gate fprintf(stderr, "makedev: can't open %s\n", fout); 184*0Sstevel@tonic-gate exit(1); 185*0Sstevel@tonic-gate } 186*0Sstevel@tonic-gate write(fdout, &dev, sizeof(struct dev)); 187*0Sstevel@tonic-gate write(fdout, size, (dev.nsizes+1) * sizeof(size[0])); /* we need a 0 on the end */ 188*0Sstevel@tonic-gate write(fdout, chtab, dev.nchtab * sizeof(chtab[0])); 189*0Sstevel@tonic-gate write(fdout, chname, dev.lchname); 190*0Sstevel@tonic-gate totfont = 0; 191*0Sstevel@tonic-gate for (i = 0; i < dev.nfonts; i++) { 192*0Sstevel@tonic-gate totfont += dofont(fname[i]); 193*0Sstevel@tonic-gate write(fdout, &font, sizeof(struct Font)); 194*0Sstevel@tonic-gate write(fdout, width, font.nwfont & BYTEMASK); 195*0Sstevel@tonic-gate write(fdout, kern, font.nwfont & BYTEMASK); 196*0Sstevel@tonic-gate write(fdout, code, font.nwfont & BYTEMASK); 197*0Sstevel@tonic-gate write(fdout, fitab, dev.nchtab+128-32); 198*0Sstevel@tonic-gate } 199*0Sstevel@tonic-gate lseek(fdout, 0L, 0); /* back to beginning to install proper size */ 200*0Sstevel@tonic-gate dev.filesize = /* excluding dev struct itself */ 201*0Sstevel@tonic-gate (dev.nsizes+1) * sizeof(size[0]) 202*0Sstevel@tonic-gate + dev.nchtab * sizeof(chtab[0]) 203*0Sstevel@tonic-gate + dev.lchname * sizeof(char) 204*0Sstevel@tonic-gate + totfont * sizeof(char); 205*0Sstevel@tonic-gate write(fdout, &dev, sizeof(struct dev)); 206*0Sstevel@tonic-gate close(fdout); 207*0Sstevel@tonic-gate argc--; 208*0Sstevel@tonic-gate argv++; 209*0Sstevel@tonic-gate } 210*0Sstevel@tonic-gate for (i = 1; i < argc; i++) 211*0Sstevel@tonic-gate dofont(argv[i]); 212*0Sstevel@tonic-gate exit(0); 213*0Sstevel@tonic-gate } 214*0Sstevel@tonic-gate 215*0Sstevel@tonic-gate dofont(name) /* create fitab and width tab for font */ 216*0Sstevel@tonic-gate char *name; 217*0Sstevel@tonic-gate { 218*0Sstevel@tonic-gate FILE *fin; 219*0Sstevel@tonic-gate int fdout; 220*0Sstevel@tonic-gate int i, nw, spacewidth, n, v; 221*0Sstevel@tonic-gate char buf[100], ch[10], s1[10], s2[10], s3[10], cmd[30]; 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate if ((fin = fopen(name, "r")) == NULL) { 224*0Sstevel@tonic-gate fprintf(stderr, "makedev: can't open font %s\n", name); 225*0Sstevel@tonic-gate exit(2); 226*0Sstevel@tonic-gate } 227*0Sstevel@tonic-gate sprintf(cmd, "%s.out", name); 228*0Sstevel@tonic-gate fdout = creat(cmd, 0666); 229*0Sstevel@tonic-gate for (i = 0; i < NFITAB; i++) 230*0Sstevel@tonic-gate fitab[i] = 0; 231*0Sstevel@tonic-gate for (i = 0; i < FSIZE; i++) 232*0Sstevel@tonic-gate width[i] = kern[i] = code[i] = 0; 233*0Sstevel@tonic-gate font.specfont = font.ligfont = spacewidth = 0; 234*0Sstevel@tonic-gate while (fscanf(fin, "%s", cmd) != EOF) { 235*0Sstevel@tonic-gate if (cmd[0] == '#') 236*0Sstevel@tonic-gate skipline(fin); 237*0Sstevel@tonic-gate else if (strcmp(cmd, "name") == 0) 238*0Sstevel@tonic-gate fscanf(fin, "%s", font.namefont); 239*0Sstevel@tonic-gate else if (strcmp(cmd, "internalname") == 0) 240*0Sstevel@tonic-gate fscanf(fin, "%s", font.intname); 241*0Sstevel@tonic-gate else if (strcmp(cmd, "special") == 0) 242*0Sstevel@tonic-gate font.specfont = 1; 243*0Sstevel@tonic-gate else if (strcmp(cmd, "spare1") == 0) 244*0Sstevel@tonic-gate fscanf(fin, "%1s", &font.spare1); 245*0Sstevel@tonic-gate else if (strcmp(cmd, "ligatures") == 0) { 246*0Sstevel@tonic-gate font.ligfont = getlig(fin); 247*0Sstevel@tonic-gate } else if (strcmp(cmd, "spacewidth") == 0) { 248*0Sstevel@tonic-gate fscanf(fin, "%d", &spacewidth); 249*0Sstevel@tonic-gate width[0] = spacewidth; /* width of space on this font */ 250*0Sstevel@tonic-gate } else if (strcmp(cmd, "charset") == 0) { 251*0Sstevel@tonic-gate skipline(fin); 252*0Sstevel@tonic-gate nw = 0; 253*0Sstevel@tonic-gate /* widths are origin 1 so fitab==0 can mean "not there" */ 254*0Sstevel@tonic-gate while (fgets(buf, 100, fin) != NULL) { 255*0Sstevel@tonic-gate sscanf(buf, "%s %s %s %s", ch, s1, s2, s3); 256*0Sstevel@tonic-gate if (s1[0] != '"') { /* it's a genuine new character */ 257*0Sstevel@tonic-gate nw++; 258*0Sstevel@tonic-gate width[nw] = atoi(s1); 259*0Sstevel@tonic-gate kern[nw] = atoi(s2); 260*0Sstevel@tonic-gate /* temporarily, pick up one byte as code */ 261*0Sstevel@tonic-gate if (s3[0] == '0') 262*0Sstevel@tonic-gate sscanf(s3, "%o", &i); 263*0Sstevel@tonic-gate else 264*0Sstevel@tonic-gate sscanf(s3, "%d", &i); 265*0Sstevel@tonic-gate code[nw] = i; 266*0Sstevel@tonic-gate } 267*0Sstevel@tonic-gate /* otherwise it's a synonym for previous character, 268*0Sstevel@tonic-gate /* so leave previous values intact 269*0Sstevel@tonic-gate */ 270*0Sstevel@tonic-gate if (strlen(ch) == 1) /* it's ascii */ 271*0Sstevel@tonic-gate fitab[ch[0] - 32] = nw; /* fitab origin omits non-graphics */ 272*0Sstevel@tonic-gate else { /* it has a funny name */ 273*0Sstevel@tonic-gate for (i = 0; i < dev.nchtab; i++) 274*0Sstevel@tonic-gate if (strcmp(&chname[chtab[i]], ch) == 0) { 275*0Sstevel@tonic-gate fitab[i + 128-32] = nw; /* starts after the ascii */ 276*0Sstevel@tonic-gate break; 277*0Sstevel@tonic-gate } 278*0Sstevel@tonic-gate if (i >= dev.nchtab) 279*0Sstevel@tonic-gate fprintf(stderr, "makedev: font %s: %s not in charset\n", name, ch); 280*0Sstevel@tonic-gate } 281*0Sstevel@tonic-gate } 282*0Sstevel@tonic-gate nw++; 283*0Sstevel@tonic-gate if (dev.biggestfont >= nw) 284*0Sstevel@tonic-gate n = dev.biggestfont; 285*0Sstevel@tonic-gate else { 286*0Sstevel@tonic-gate if (dev.biggestfont > 0) 287*0Sstevel@tonic-gate fprintf(stderr, "font %s too big\n", name); 288*0Sstevel@tonic-gate n = nw; 289*0Sstevel@tonic-gate } 290*0Sstevel@tonic-gate font.nwfont = n; 291*0Sstevel@tonic-gate } 292*0Sstevel@tonic-gate } 293*0Sstevel@tonic-gate if (spacewidth == 0) 294*0Sstevel@tonic-gate width[0] = dev.res * dev.unitwidth / 72 / 3; 295*0Sstevel@tonic-gate fclose(fin); 296*0Sstevel@tonic-gate 297*0Sstevel@tonic-gate write(fdout, &font, sizeof(struct Font)); 298*0Sstevel@tonic-gate write(fdout, width, font.nwfont & BYTEMASK); 299*0Sstevel@tonic-gate write(fdout, kern, font.nwfont & BYTEMASK); 300*0Sstevel@tonic-gate write(fdout, code, font.nwfont & BYTEMASK); 301*0Sstevel@tonic-gate write(fdout, fitab, dev.nchtab+128-32); 302*0Sstevel@tonic-gate close(fdout); 303*0Sstevel@tonic-gate v = sizeof(struct Font) + 3 * n + dev.nchtab + 128-32; 304*0Sstevel@tonic-gate fprintf(stderr, "%3s: %3d chars, width %3d, size %3d\n", 305*0Sstevel@tonic-gate font.namefont, nw, width[0], v); 306*0Sstevel@tonic-gate return v; 307*0Sstevel@tonic-gate } 308*0Sstevel@tonic-gate 309*0Sstevel@tonic-gate getlig(fin) /* pick up ligature list */ 310*0Sstevel@tonic-gate FILE *fin; 311*0Sstevel@tonic-gate { 312*0Sstevel@tonic-gate int lig; 313*0Sstevel@tonic-gate char temp[100]; 314*0Sstevel@tonic-gate 315*0Sstevel@tonic-gate lig = 0; 316*0Sstevel@tonic-gate while (fscanf(fin, "%s", temp) != EOF && strcmp(temp, "0") != 0) { 317*0Sstevel@tonic-gate if (strcmp(temp, "fi") == 0) 318*0Sstevel@tonic-gate lig |= LFI; 319*0Sstevel@tonic-gate else if (strcmp(temp, "fl") == 0) 320*0Sstevel@tonic-gate lig |= LFL; 321*0Sstevel@tonic-gate else if (strcmp(temp, "ff") == 0) 322*0Sstevel@tonic-gate lig |= LFF; 323*0Sstevel@tonic-gate else if (strcmp(temp, "ffi") == 0) 324*0Sstevel@tonic-gate lig |= LFFI; 325*0Sstevel@tonic-gate else if (strcmp(temp, "ffl") == 0) 326*0Sstevel@tonic-gate lig |= LFFL; 327*0Sstevel@tonic-gate else 328*0Sstevel@tonic-gate fprintf(stderr, "illegal ligature %s\n", temp); 329*0Sstevel@tonic-gate } 330*0Sstevel@tonic-gate skipline(fin); 331*0Sstevel@tonic-gate return lig; 332*0Sstevel@tonic-gate } 333