|
|
1.1 ! root 1: char xxxmakei10[] ="@(#)makei10.c 1.1"; ! 2: ! 3: #include <stdio.h> ! 4: #include "dev.h" ! 5: ! 6: ! 7: #define NON_FATAL 0 ! 8: #define FATAL 1 ! 9: #define NO 0 ! 10: #define YES 1 ! 11: ! 12: #define FNAME 4 /* longest allowed font name - at least 3 */ ! 13: #define DNAME 11 /* longest accepted device name */ ! 14: #define CLENGTH 2 /* max length of special char strings */ ! 15: #define FONTDIR 100 /* max length of *fontdir string */ ! 16: #define LINE_LENGTH 100 /* longest line in ASCII tables */ ! 17: #define MAXWIDTH 255 /* maximum number of width entries */ ! 18: #define MAXSYNS 75 /* no more synonyms than this */ ! 19: #define MAXBUILD 75 /* largest 'build' list */ ! 20: #define MAXFONTS 60 /* can map this many fonts */ ! 21: #define NFONT 10 /* search at most this many fonts */ ! 22: #define BMASK 0377 /* mask for lower eight bits */ ! 23: ! 24: #define FONTSIZE 3 * MAXWIDTH + nchtab + (128 - 32) + sizeof(struct Font) ! 25: #define PATHLENGTH FONTDIR + 2 * DNAME + FNAME + 5 ! 26: #define TARGDIR FONTDIR + DNAME + 5 ! 27: ! 28: ! 29: ! 30: char mdev[DNAME+1] = ""; /* raster tbls assume this device */ ! 31: char tdev[DNAME+1] = "i10"; /* target typesetter - Imagen */ ! 32: char *ndev; /* make ASCII tables for this device */ ! 33: ! 34: struct dev dev; /* *mdev DESC.out header goes here */ ! 35: struct Font *fontbase[NFONT]; /* each font's .out header stuff */ ! 36: ! 37: int nchtab; /* number of special chars in chtab */ ! 38: short *pstab; /* point size table - not needed */ ! 39: short *chtab; /* char's index in chname array */ ! 40: char *chname; /* special character strings */ ! 41: char *fontstart; /* can load fonts starting here */ ! 42: char *widthtab[NFONT]; /* font's width table - not needed */ ! 43: char *codetab[NFONT]; /* *mdev's codes for characters */ ! 44: char *fitab[NFONT]; /* position of characters on a font */ ! 45: ! 46: char mapped[MAXFONTS][FNAME+1]; /* mapped these fonts - ASCII names */ ! 47: char fmap[NFONT+1][FNAME+1]; /* names of *mdev's fonts that we search */ ! 48: char new[MAXSYNS][CLENGTH+1]; /* synonym for corresponding char in old[][] */ ! 49: char old[MAXSYNS][CLENGTH+1]; /* old character name */ ! 50: char bldlist[MAXBUILD+1][CLENGTH+1]; /* these chars will be built up */ ! 51: ! 52: int mapcount; /* mapped this many of *ndev's fonts */ ! 53: int syncount = 0; /* number of synonyms in *fontmap */ ! 54: int bldcount = 0; /* number of build chars in *fontmap */ ! 55: int fcount; /* number of original default fonts */ ! 56: int acount = 0; /* add this many fonts to default */ ! 57: int iname; /* internal name for 'related' fonts */ ! 58: int nfonts; /* number of *mdev's fonts to check */ ! 59: int fsize; /* all fonts given this much room */ ! 60: ! 61: char *fontdir = ".."; /* troff's font directory */ ! 62: char *srcdir = ".."; /* ASCII font files kept here */ ! 63: char targdir[TARGDIR] = "."; /* target device's font directory */ ! 64: char *rastdev = "RASTERDEV"; /* device name is in this file */ ! 65: char *fontmap = "FONTMAP"; /* font map file for device *ndev */ ! 66: ! 67: char addfont[(NFONT-1)*MAXFONTS*(FNAME+1)] = ""; /* additional default fonts */ ! 68: ! 69: char path[PATHLENGTH]; /* build file pathnames up here */ ! 70: ! 71: FILE *descin; /* *ndev's real ASCII DESC file */ ! 72: FILE *descout; /* new ASCII DESC file for *ndev */ ! 73: FILE *fontin; /* read font data from this ASCII file */ ! 74: FILE *fontout[NFONT+1]; /* ASCII output files for this font */ ! 75: FILE *fp_map; /* file pointer for *fontmap file */ ! 76: FILE *fp_error = stderr; /* error messages */ ! 77: ! 78: char **argv; /* so everyone can use them */ ! 79: int argc; ! 80: ! 81: int silent = NO; ! 82: ! 83: ! 84: ! 85: /*****************************************************************************/ ! 86: ! 87: ! 88: main(agc, agv) ! 89: ! 90: ! 91: int agc; ! 92: char *agv[]; ! 93: ! 94: ! 95: { ! 96: ! 97: ! 98: /******************************************************************** ! 99: * * ! 100: * This program takes troff's ASCII font and device tables for * ! 101: * one or more typesetters and converts them into a form that can * ! 102: * be used with the raster tables located in the target device's * ! 103: * font directory. These new tables are written into appropriate * ! 104: * 'dev' directories located in the *targdir directory. * ! 105: * * ! 106: * The program expects to find a file called RASTERDEV in * ! 107: * *targdir. The first string in this file is the name of the * ! 108: * device whose tables were used to make the raster files - the * ! 109: * rest of the file is skipped. In addition each new device must * ! 110: * have an appropriate 'dev' directory in *targdir, and each of * ! 111: * these directories must contain a file called FONTMAP, that * ! 112: * tells the program how to map *ndev's fonts. * ! 113: * * ! 114: * After the command line options are processed, the name of * ! 115: * the master device is read from the file *rastdev, provided the * ! 116: * string *mdev hasn't already been set. Then this device name is * ! 117: * used, in combination with *fontdir, to locate *mdev's binary * ! 118: * '.out' tables. Routine getdesc() reads the entire DESC.out * ! 119: * into memory, and then alloctes enough additional memory to hold * ! 120: * NFONT binary font files. Once this initialization stuff is done * ! 121: * the program enters a loop that treats the rest of the command * ! 122: * line arguments as device names. Each of these devices will have * ! 123: * a new set of ASCII font tables written out to the appropriate * ! 124: * 'dev' directory in *targdir. * ! 125: * * ! 126: * The first step for each new device is to essentially copy * ! 127: * the first part of its real ASCII DESC file from *fontdir to the * ! 128: * appropriate 'dev' directory in *targdir. Routine startdesc() * ! 129: * handles this job, but it only reads up to the default font * ! 130: * count in the real DESC file. Once it has the default font count * ! 131: * startdesc() has really finished its job. It doesn't even write * ! 132: * this number out to the new DESC file, because we are probably * ! 133: * going to be adding some default fonts to the new DESC file. * ! 134: * * ! 135: ********************************************************************/ ! 136: ! 137: ! 138: argv = agv; /* global so everyone can use them */ ! 139: argc = agc; ! 140: ! 141: getoptions(); ! 142: getmdev(); /* get 'master' device name */ ! 143: getdesc(); /* get *mdev's DESC.out file */ ! 144: ! 145: if ( silent == NO ) ! 146: printf("master device = %s\n\n", mdev); ! 147: ! 148: while ( --argc > 0 ) { /* got another device */ ! 149: ndev = *++argv; /* make tables for this guy */ ! 150: if ( silent == NO ) ! 151: printf("making tables for device %s\n", ndev); ! 152: startdesc(); /* up to default font list */ ! 153: makefonts(); /* for all fonts listed in FONTMAP */ ! 154: finishdesc(); /* complete *ndev's new DESC file */ ! 155: } /* End while */ ! 156: ! 157: } /* End of main */ ! 158: ! 159: ! 160: /*****************************************************************************/ ! 161: ! 162: ! 163: getoptions() ! 164: ! 165: ! 166: { ! 167: ! 168: ! 169: /******************************************************************** ! 170: * * ! 171: * Called from the main program to handle the command line * ! 172: * options. * ! 173: * * ! 174: ********************************************************************/ ! 175: ! 176: ! 177: while ( argc > 1 && argv[1][0] == '-' ) { ! 178: ! 179: switch ( argv[1][1] ) { ! 180: ! 181: case 's': ! 182: silent = YES; ! 183: break; ! 184: ! 185: case 'm': ! 186: strcpy(mdev, &argv[1][2]); ! 187: if ( strlen(mdev) > DNAME ) ! 188: error(FATAL, "device name %s too long", mdev); ! 189: break; ! 190: ! 191: case 'F': ! 192: fontdir = &argv[1][2]; ! 193: break; ! 194: ! 195: case 'S': ! 196: srcdir = &argv[1][2]; ! 197: break; ! 198: ! 199: default: ! 200: error(NON_FATAL, "illegal option %c", argv[1][1]); ! 201: break; ! 202: ! 203: } /* End switch */ ! 204: ! 205: argv++; ! 206: argc--; ! 207: ! 208: } /* End while */ ! 209: ! 210: } /* End of getoptions */ ! 211: ! 212: ! 213: /*****************************************************************************/ ! 214: ! 215: ! 216: getmdev() ! 217: ! 218: ! 219: { ! 220: ! 221: ! 222: FILE *fd; /* used for *rastdev file */ ! 223: ! 224: ! 225: /******************************************************************** ! 226: * * ! 227: * Called from the main program to get the name of the device * ! 228: * that was used to make the raster tables for the target device. * ! 229: * If the string *mdev has already been set, possibly by an * ! 230: * option, nothing is done. Otherwise we expect to find the name * ! 231: * as the first string in the file *targdir/*rastdev. * ! 232: * * ! 233: ********************************************************************/ ! 234: ! 235: ! 236: if ( *mdev != '\0' ) return; /* got the name somewhere else */ ! 237: ! 238: sprintf(path, "%s/%s", targdir, rastdev); ! 239: if ( (fd = fopen(path, "r")) == NULL ) ! 240: error(FATAL, "can't open file %s", path); ! 241: ! 242: if ( fscanf(fd, "%14s", mdev) != 1 ) ! 243: error(FATAL, "no device name in file %s", rastdev); ! 244: ! 245: if ( strlen(mdev) > DNAME ) ! 246: error(FATAL, "master device name %s too long", mdev); ! 247: ! 248: fclose(fd); /* won't need this file again */ ! 249: ! 250: } /* End of getmdev */ ! 251: ! 252: ! 253: /*****************************************************************************/ ! 254: ! 255: ! 256: getdesc() ! 257: ! 258: ! 259: { ! 260: ! 261: ! 262: int fin; /* DESC.out's file descriptor */ ! 263: char *filebase; /* memory block for DESC.out file */ ! 264: char *malloc(); /* memory allocation routine */ ! 265: ! 266: ! 267: /******************************************************************** ! 268: * * ! 269: * Called from the main program to read in the DESC.out file * ! 270: * for typesetter *mdev. Even though we only will use a small part * ! 271: * of this file, the whole thing is read into memory. I also * ! 272: * decided not to use the font space that is already allocated in * ! 273: * the DESC.out file. If you want to use this space just change * ! 274: * the initialization of fontstart. * ! 275: * * ! 276: ********************************************************************/ ! 277: ! 278: ! 279: sprintf(path, "%s/dev%s/DESC.out", fontdir, mdev); ! 280: if ( (fin = open(path, 0)) < 0 ) ! 281: error(FATAL, "can't open file %s", path); ! 282: ! 283: read(fin, &dev, sizeof(struct dev)); /* struct dev comes first */ ! 284: ! 285: nchtab = dev.nchtab; /* FONTSIZE needs this number */ ! 286: fsize = FONTSIZE; /* space given to each font */ ! 287: ! 288: if ( (filebase = malloc(dev.filesize)) == NULL ) ! 289: error(FATAL, "no memory available"); ! 290: ! 291: read(fin, filebase, dev.filesize); /* get rest of the DESC.out file */ ! 292: pstab = (short *) filebase; /* this table is never used */ ! 293: chtab = pstab + dev.nsizes + 1; ! 294: chname = (char *) (chtab + dev.nchtab); ! 295: ! 296: if ( (fontstart = malloc(NFONT * fsize)) == NULL ) ! 297: error(FATAL, "no memory available"); ! 298: ! 299: close(fin); /* won't need this guy again */ ! 300: ! 301: } /* End of getdesc */ ! 302: ! 303: ! 304: /*****************************************************************************/ ! 305: ! 306: ! 307: startdesc() ! 308: ! 309: ! 310: { ! 311: ! 312: ! 313: char cmd[LINE_LENGTH]; /* DESC file commands go here */ ! 314: int c; /* used as a character */ ! 315: ! 316: ! 317: /******************************************************************** ! 318: * * ! 319: * Called from main() to begin making *ndev's ASCII DESC file. * ! 320: * The real DESC file is read up to the default font list. Later * ! 321: * routine finishdesc() is called to complete the new DESC file. * ! 322: * I did things this way because we need to know the original * ! 323: * number of default fonts for device *ndev before we make the * ! 324: * new font tables, and we can't write the default font list out * ! 325: * to the new DESC file until we have built all the new font * ! 326: * tables for *ndev. * ! 327: * * ! 328: * Since I have claimed dev.spare2 in routine finishdesc() we * ! 329: * should probably check if the command we just read was 'spare2'. * ! 330: * I'll take care of this later on. * ! 331: * * ! 332: ********************************************************************/ ! 333: ! 334: ! 335: sprintf(path, "%s/dev%s/DESC", srcdir, ndev); ! 336: if ( (descin = fopen(path, "r")) == NULL ) ! 337: error(FATAL, "can't open file %s", path); ! 338: ! 339: sprintf(path, "%s/dev%s/DESC", targdir, ndev); ! 340: if ( (descout = fopen(path, "w")) == NULL ) ! 341: error(FATAL, "can't write file %s", path); ! 342: ! 343: while ( fscanf(descin, "%s", cmd) != EOF ) { ! 344: fprintf(descout, "%s", cmd); ! 345: if ( strcmp(cmd, "fonts") == 0 ) { ! 346: fscanf(descin, "%s", cmd); ! 347: fcount = atoi(cmd); ! 348: return; ! 349: } else if ( strcmp(cmd, "charset") == 0 ) ! 350: error(FATAL, "bad DESC file format"); ! 351: else while ( putc(c=getc(descin), descout) != '\n' && c != EOF ) ; ! 352: } /* End while */ ! 353: ! 354: error(FATAL, "bad DESC file"); /* shouldn't get here! */ ! 355: ! 356: } /* End of startdesc */ ! 357: ! 358: ! 359: /*****************************************************************************/ ! 360: ! 361: ! 362: finishdesc() ! 363: ! 364: ! 365: { ! 366: ! 367: ! 368: char fname[FNAME+1]; /* names of the default fonts */ ! 369: int i, j; /* for loop indices */ ! 370: int c; /* used as a char with getc() */ ! 371: ! 372: ! 373: /******************************************************************** ! 374: * * ! 375: * Called from the main program after all the fonts for *ndev * ! 376: * have been mapped. Routine startdesc() read *descin up to the * ! 377: * first default font name, and it wrote *descout up to the count * ! 378: * part of the default font list. Most likely we will now have * ! 379: * more default fonts than we started with, so dev.spare2 can be * ! 380: * used by post-processors to get at the original number. * ! 381: * * ! 382: ********************************************************************/ ! 383: ! 384: ! 385: fprintf(descout, " %d", fcount + acount); /* new default font count */ ! 386: ! 387: for ( i = 0; i < fcount; i++ ) { /* check each default font */ ! 388: fscanf(descin, "%s", fname); ! 389: fprintf(descout, " %s", fname); ! 390: for ( j = 0; j < mapcount; j++ ) /* did we map this font? */ ! 391: if ( strcmp(fname, &mapped[j][0]) == 0 ) ! 392: break; ! 393: if ( j >= mapcount ) /* didn't find it */ ! 394: error(NON_FATAL, "missing default font file %s", fname); ! 395: } /* End for */ ! 396: ! 397: fprintf(descout, "%s", addfont); /* finish the default font list */ ! 398: fprintf(descout, "\nspare2 %d", fcount); /* post-processor can use it */ ! 399: ! 400: while ( (c = getc(descin)) != EOF ) putc(c, descout); ! 401: ! 402: fclose(descin); /* may have more devices */ ! 403: fclose(descout); ! 404: ! 405: } /* End of finishdesc */ ! 406: ! 407: ! 408: /*****************************************************************************/ ! 409: ! 410: ! 411: makefonts() ! 412: ! 413: ! 414: { ! 415: ! 416: ! 417: char cmd[LINE_LENGTH]; /* font file commands go here */ ! 418: int c; /* used as a character */ ! 419: int i; /* for loop index */ ! 420: ! 421: ! 422: /******************************************************************** ! 423: * * ! 424: * Called from main() to make all the ASCII font files listed * ! 425: * in *ndev's FONTMAP file. All the stuff up to the charset part * ! 426: * of each ASCII font file is essentially copied into the new * ! 427: * font file. The name field is changed to the name of the second * ! 428: * font from appropriate lines in the FONTMAP file. All 'related' * ! 429: * fonts are given the same internal number. The lower eight bits * ! 430: * of this number contains the font position where post-processors * ! 431: * can expect to find related fonts to search if a character is * ! 432: * not found on the primary font. This additional search should be * ! 433: * done before checking the special fonts. The ligature stuff is * ! 434: * not really needed - leave it in for now. * ! 435: * * ! 436: ********************************************************************/ ! 437: ! 438: ! 439: mapcount = 0; /* fonts mapped so far for *ndev */ ! 440: ! 441: sprintf(path, "%s/dev%s/%s", targdir, ndev, fontmap); ! 442: if ( (fp_map = fopen(path, "r")) == NULL ) ! 443: error(FATAL, "can't open file %s", path); ! 444: ! 445: while ( readmap() != 0 ) { /* not done with FONTMAP file yet */ ! 446: ! 447: if ( silent == NO ) ! 448: printf("font %s\n", &mapped[mapcount][0]); ! 449: ! 450: for ( i = 1; i < NFONT + 1; i++ ) ! 451: fontout[i] = NULL; ! 452: ! 453: sprintf(path, "%s/dev%s/%s", srcdir, ndev, &mapped[mapcount][0]); ! 454: if ( (fontin = fopen(path, "r")) == NULL ) ! 455: error(FATAL, "can't open file %s", path); ! 456: ! 457: sprintf(path, "%s/dev%s/%s", targdir, ndev, &mapped[mapcount][0]); ! 458: if ( (fontout[0] = fopen(path, "w")) == NULL ) ! 459: error(FATAL, "can't open file %s", path); ! 460: ! 461: for ( i = 0; i < nfonts; i++ ) /* get the '.out' font files */ ! 462: loadfont(&fmap[i][0], i); ! 463: ! 464: iname = (mapcount * (BMASK + 1)) + fcount + acount + 1; ! 465: ! 466: while ( fscanf(fontin, "%s", cmd) == 1) { ! 467: fprintf(fontout[0], "%s", cmd); ! 468: if ( strcmp(cmd, "name") == 0 ) { ! 469: fprintf(fontout[0], " %s\n", &fmap[0][0]); ! 470: while ( (c = getc(fontin)) != '\n' && c != EOF ) ; ! 471: } else if ( strcmp(cmd, "internalname") == 0 ) { ! 472: fprintf(fontout[0], " %d\n", iname); ! 473: while ( (c = getc(fontin)) != '\n' && c != EOF ) ; ! 474: } else if ( strcmp(cmd, "ligatures") == 0 ) { ! 475: get_ligs(); ! 476: while ( (c = getc(fontin)) != '\n' && c != EOF ) ; ! 477: } else if ( strcmp(cmd, "charset") == 0 ) ! 478: copy_chars(); ! 479: else while ( putc(c=getc(fontin), fontout[0]) != '\n' && c != EOF ) ; ! 480: } /* End while */ ! 481: ! 482: mapcount++; /* finished mapping this font */ ! 483: ! 484: fclose(fontin); ! 485: for ( i = 0; i < NFONT + 1; i++ ) ! 486: if ( fontout[i] != NULL ) ! 487: fclose(fontout[i]); ! 488: ! 489: } /* End while */ ! 490: ! 491: fclose(fp_map); ! 492: ! 493: } /* End of makefonts */ ! 494: ! 495: ! 496: /*****************************************************************************/ ! 497: ! 498: ! 499: readmap() ! 500: ! 501: ! 502: { ! 503: ! 504: ! 505: char buff[20]; ! 506: int c; /* used as a character */ ! 507: ! 508: ! 509: /******************************************************************** ! 510: * * ! 511: * This routine continues reading the FONTMAP file until it * ! 512: * has processed the next font mapping instruction. Any 'build' * ! 513: * lists that are encountered replace the last list, and will * ! 514: * therefore apply to the next font map. The first font mentioned * ! 515: * in a font map line is the name of the primary font for the * ! 516: * current mapping instruction. This is *ndev's ASCII font file * ! 517: * that we will be reading and usually writing. The rest of the * ! 518: * fonts following the 'into' are the names of *mdev's fonts that * ! 519: * are searched when we do the character lookups. These searches * ! 520: * are done using the '.out' font files, which are read in from * ! 521: * *mdev's normal font directory. * ! 522: * * ! 523: ********************************************************************/ ! 524: ! 525: ! 526: if ( mapcount >= MAXFONTS ) ! 527: error(FATAL, "too many fonts in %s file", fontmap); ! 528: ! 529: while ( fscanf(fp_map, "%19s", buff) == 1 ) { ! 530: if ( strcmp(buff, "synonyms") == 0 ) ! 531: readsyns(); ! 532: else if ( strcmp(buff, "build") == 0 ) ! 533: readbuild(); ! 534: else if ( strcmp(buff, "nobuild") == 0 ) ! 535: bldcount = 0; ! 536: else if ( strcmp(buff, "map") == 0 ) ! 537: return(readfonts()); ! 538: else if ( buff[0] = '#' ) ! 539: while ( (c = getc(fp_map)) != '\n' && c != EOF ) ; ! 540: else error(FATAL, "don't know command %s", buff); ! 541: } /* End while */ ! 542: ! 543: return(0); ! 544: ! 545: } /* End of readmap */ ! 546: ! 547: ! 548: /*****************************************************************************/ ! 549: ! 550: ! 551: readfonts() ! 552: ! 553: ! 554: { ! 555: ! 556: ! 557: int c; /* character used with getc() */ ! 558: ! 559: ! 560: /******************************************************************** ! 561: * * ! 562: * Called from readmap() to read the next font map line for * ! 563: * device *ndev from the file *fp_map. * ! 564: * * ! 565: ********************************************************************/ ! 566: ! 567: ! 568: nfonts = 0; ! 569: ! 570: if ( fscanf(fp_map, "%s into", &mapped[mapcount][0]) != 1 ) ! 571: error(FATAL, "map file synatx error"); ! 572: ! 573: if ( FNAME < 3 ) /* we may have trouble later on */ ! 574: error(FATAL, "constant FNAME less than 3"); ! 575: ! 576: if ( strlen(&mapped[mapcount][0]) > FNAME ) ! 577: error(FATAL, "font name %s too long", &mapped[mapcount][0]); ! 578: ! 579: while ( nfonts < NFONT ) { ! 580: while ( (c = getc(fp_map)) == ' ' || c == '\t') ; ! 581: if ( c == '\n' || c == EOF ) ! 582: break; ! 583: ungetc(c, fp_map); ! 584: fscanf(fp_map, "%s", &fmap[nfonts][0]); ! 585: if ( strlen(&fmap[nfonts++][0]) > FNAME ) ! 586: error(FATAL, "font name %s too long", &fmap[nfonts-1][0]); ! 587: } /* End while */ ! 588: ! 589: if ( nfonts >= NFONT ) ! 590: while ( (c = getc(fp_map)) != '\n' && c != EOF ) ; ! 591: ! 592: strcpy(&fmap[nfonts][0], "bld"); ! 593: ! 594: return(nfonts); ! 595: ! 596: } /* End of readfonts */ ! 597: ! 598: ! 599: /*****************************************************************************/ ! 600: ! 601: ! 602: readbuild() ! 603: ! 604: ! 605: { ! 606: ! 607: ! 608: /******************************************************************** ! 609: * * ! 610: * Called from readmap() to read a 'build' list from *fontmap. * ! 611: * This list consists of those characters that will be built up * ! 612: * by the post-processor. They will be written out to a special * ! 613: * font file named *fmap[0].bld with a character code of 0. The * ! 614: * list is terminated by the string "end". * ! 615: * * ! 616: ********************************************************************/ ! 617: ! 618: ! 619: bldcount = 0; /* throw the last copy list out */ ! 620: ! 621: while ( bldcount < MAXBUILD ) { ! 622: if ( fscanf(fp_map, "%s", &bldlist[bldcount][0]) != 1 ) ! 623: error(FATAL, "bad build list format"); ! 624: ! 625: if ( strcmp(&bldlist[bldcount][0], "end") == 0 ) ! 626: return; ! 627: ! 628: if ( strlen(&bldlist[bldcount][0]) > CLENGTH ) ! 629: error(FATAL, "copy name %s too long", &bldlist[bldcount][0]); ! 630: ! 631: bldcount++; ! 632: } /* End while */ ! 633: ! 634: error(FATAL, "too many build characters"); ! 635: ! 636: } /* End of readbuild */ ! 637: ! 638: ! 639: /*****************************************************************************/ ! 640: ! 641: ! 642: readsyns() ! 643: ! 644: ! 645: { ! 646: ! 647: ! 648: /******************************************************************** ! 649: * * ! 650: * Called from readmap() to read a synonym list from the * ! 651: * *fontmap. The list is terminated by any pair of identical * ! 652: * character strings whose length is no more than CLENGTH. * ! 653: * This synonym stuff is probably not needed. It was added to the * ! 654: * program early on. * ! 655: * * ! 656: ********************************************************************/ ! 657: ! 658: ! 659: syncount = 0; /* throw the last list out */ ! 660: ! 661: while ( syncount < MAXSYNS ) { ! 662: if ( fscanf(fp_map, "%s %s", &new[syncount][0], &old[syncount][0]) != 2 ) ! 663: error(FATAL, "bad synonym list format"); ! 664: ! 665: if ( strlen(&new[syncount][0]) > CLENGTH ) ! 666: error(FATAL, "synonym name %s too long", &new[syncount][0]); ! 667: ! 668: if ( strlen(&old[syncount][0]) > CLENGTH ) ! 669: error(FATAL, "synonym name %s too long", &old[syncount][0]); ! 670: ! 671: if ( strcmp(&new[syncount][0], &old[syncount][0]) == 0 ) ! 672: return; ! 673: ! 674: syncount++; /* its a real synonym */ ! 675: } /* End while */ ! 676: ! 677: error(FATAL, "too many synonyms"); ! 678: ! 679: } /* End of readsyns */ ! 680: ! 681: ! 682: /*****************************************************************************/ ! 683: ! 684: ! 685: get_ligs() ! 686: ! 687: ! 688: { ! 689: ! 690: ! 691: char lig; ! 692: ! 693: ! 694: /******************************************************************** ! 695: * * ! 696: * Called from makefonts() to build up an appropriate ligature * ! 697: * list for the current font. This routine should not be needed * ! 698: * because the new tables will probably only be used by post- * ! 699: * processors, and they usually won't look at the font.ligfont * ! 700: * field. It is the right way to do things, so I decided to leave * ! 701: * the routine in for now - just in case. * ! 702: * * ! 703: ********************************************************************/ ! 704: ! 705: ! 706: lig = fontbase[0]->ligfont; ! 707: ! 708: if ( lig & LFI ) ! 709: fprintf(fontout[0], " fi"); ! 710: if ( lig & LFL ) ! 711: fprintf(fontout[0], " fl"); ! 712: if ( lig & LFF ) ! 713: fprintf(fontout[0], " ff"); ! 714: if ( lig & LFFI ) ! 715: fprintf(fontout[0], " ffi"); ! 716: if ( lig & LFFL ) ! 717: fprintf(fontout[0], " ffl"); ! 718: ! 719: fprintf(fontout[0], " 0\n"); ! 720: ! 721: } /* End of get_ligs */ ! 722: ! 723: ! 724: /*****************************************************************************/ ! 725: ! 726: ! 727: copy_chars() ! 728: ! 729: ! 730: { ! 731: ! 732: ! 733: char ch[10]; /* standard stuff from makedev */ ! 734: char width[10]; ! 735: char kern[10]; ! 736: char code[10]; ! 737: char nch[10]; /* look this char up - synonym */ ! 738: char buff[LINE_LENGTH]; /* next line from charset part */ ! 739: int index; /* found character on this font */ ! 740: int i; /* for loop index */ ! 741: ! 742: ! 743: /******************************************************************** ! 744: * * ! 745: * Called from makefonts() to copy the charset portion of the * ! 746: * current font file to the appropriate place in the *tdev * ! 747: * directory. * ! 748: * * ! 749: ********************************************************************/ ! 750: ! 751: ! 752: index = -1; /* needed because of synonyms */ ! 753: putc('\n', fontout[0]); /* comes after 'charset' command */ ! 754: ! 755: while ( fgets(buff, sizeof(buff), fontin) != NULL ) { ! 756: ! 757: if ( sscanf(buff, "%s %s %s %s", ch, width, kern, code) < 2 ) ! 758: continue; ! 759: ! 760: if ( width[0] == '"' ) { ! 761: if ( index >= 0 ) ! 762: fprintf(fontout[index], "%s\t%s\n", ch, width); ! 763: continue; ! 764: } /* End if */ ! 765: ! 766: strcpy(nch, ch); ! 767: for ( i = 0; i < syncount; i++ ) ! 768: if ( strcmp(ch, &old[i][0]) == 0 ) { ! 769: strcpy(nch, &new[i][0]); ! 770: break; ! 771: } /* End if */ ! 772: ! 773: if ( (index = lookup(code, nch)) < 0 ) { ! 774: if ( silent == NO ) ! 775: printf(" char %s not found\n", ch); ! 776: continue; ! 777: } else if ( fontout[index] == NULL ) ! 778: startfont(index); ! 779: ! 780: fprintf(fontout[index], "%s\t%s\t%s\t%s\n", ch, width, kern, code); ! 781: ! 782: } /* End while */ ! 783: ! 784: } /* End of copy_chars */ ! 785: ! 786: ! 787: /*****************************************************************************/ ! 788: ! 789: ! 790: startfont(index) ! 791: ! 792: ! 793: int index; /* font's name is in fmap[index] */ ! 794: ! 795: ! 796: { ! 797: ! 798: ! 799: char *nfont[2*FNAME+1]; /* name of the new font */ ! 800: ! 801: ! 802: /******************************************************************** ! 803: * * ! 804: * When this routine is called, we have found a character * ! 805: * from font mapped[mapcount] on fmap[index]. It is the first * ! 806: * time we needed this font so we have to create a new font file * ! 807: * with all the appropriate header stuff. This routine will never * ! 808: * be called with index equal to 0, since when a character is * ! 809: * found on fmap[0] it is written to *ndev's new ASCII font file * ! 810: * called mapped[mapcount][0]. This string is set in readfonts() * ! 811: * to the name of the first font in the current 'map' line in file * ! 812: * *fp_map, and the appropriate ASCII output file has already been * ! 813: * opened for writing in routine makefonts(). * ! 814: * * ! 815: ********************************************************************/ ! 816: ! 817: ! 818: strcat(strcat(strcpy(nfont, &mapped[mapcount][0]), "."), &fmap[index][0]); ! 819: ! 820: sprintf(path, "%s/dev%s/%s", targdir, ndev, nfont); ! 821: if ( (fontout[index] = fopen(path, "w")) == NULL ) ! 822: error(FATAL, "can't write file %s", path); ! 823: ! 824: fprintf(fontout[index], "name %s\n", index != nfonts ? &fmap[index][0] : &fmap[0][0]); ! 825: fprintf(fontout[index], "internalname %d\n", iname); ! 826: fprintf(fontout[index], "charset\n"); ! 827: ! 828: acount++; ! 829: strcat(strcat(addfont, " "), nfont); /* will be a default font */ ! 830: ! 831: } /* End of startfont */ ! 832: ! 833: ! 834: /*****************************************************************************/ ! 835: ! 836: ! 837: lookup(code, ch) ! 838: ! 839: ! 840: char *code; /* use this device code */ ! 841: char *ch; /* for this character */ ! 842: ! 843: ! 844: { ! 845: ! 846: ! 847: int buildit; /* did we find it in the build list? */ ! 848: int c; /* ch's index */ ! 849: int j; /* found on this font */ ! 850: int i; /* chars index on font j */ ! 851: ! 852: ! 853: /******************************************************************** ! 854: * * ! 855: * Called from copy_chars() to lookup the device code for the * ! 856: * character ch. If *ch isn't found we return -1, otherwise we * ! 857: * return the font's index where *ch was found. * ! 858: * * ! 859: ********************************************************************/ ! 860: ! 861: ! 862: buildit = 0; /* not in the build list */ ! 863: for ( i = 0; i < bldcount; i++ ) /* check the build list */ ! 864: if ( strcmp(ch, &bldlist[i][0]) == 0 ) { ! 865: strcpy(code, "0"); ! 866: buildit = 1; ! 867: } /* End if */ ! 868: ! 869: if ( ch[1] == '\0' ) /* ASCII character */ ! 870: c = ch[0]; ! 871: else { /* special troff character string */ ! 872: for ( c = 0; c < nchtab; c++ ) ! 873: if ( strcmp(&chname[chtab[c]], ch) == 0 ) ! 874: break; ! 875: if ( c >= nchtab ) ! 876: return(buildit == 0 ? -1 : nfonts); ! 877: c += 128; /* special chars start at 128 */ ! 878: } /* End if */ ! 879: ! 880: c -= 32; /* forget non-graphic characters */ ! 881: j = 0; ! 882: ! 883: while ( j < nfonts && (i = fitab[j][c] & BMASK) == 0 ) ! 884: j++; ! 885: ! 886: if ( j >= nfonts || i == 0 ) /* didn't find it on any font */ ! 887: return(buildit == 0 ? -1 : nfonts); ! 888: ! 889: sprintf(code, "%d", codetab[j][i] & BMASK); ! 890: return(j); ! 891: ! 892: } /* End of lookup */ ! 893: ! 894: ! 895: /*****************************************************************************/ ! 896: ! 897: ! 898: loadfont(str, pos) ! 899: ! 900: ! 901: char *str; /* name of the font to load */ ! 902: int pos; /* read font data into this position */ ! 903: ! 904: ! 905: { ! 906: ! 907: ! 908: char *fontpos; /* this font's position */ ! 909: int fin; /* font's .out file descriptor */ ! 910: int nw; /* number of width entries for font */ ! 911: ! 912: ! 913: /******************************************************************** ! 914: * * ! 915: * Called from makefonts() to load the .out file for font *str * ! 916: * from the 'master' device's real font directory. * ! 917: * * ! 918: ********************************************************************/ ! 919: ! 920: ! 921: sprintf(path, "%s/dev%s/%s.out", fontdir, mdev, str); ! 922: if ( (fin = open(path, 0)) < 0 ) ! 923: error(FATAL, "can't open file %s", path); ! 924: ! 925: fontpos = fontstart + (fsize * pos); ! 926: read(fin, fontpos, fsize); ! 927: ! 928: fontbase[pos] = (struct Font *) fontpos; ! 929: nw = fontbase[pos]->nwfont & BMASK; ! 930: ! 931: widthtab[pos] = (char *) fontpos + sizeof(struct Font); ! 932: codetab[pos] = (char *) widthtab[pos] + 2 * nw; ! 933: fitab[pos] = (char *) widthtab[pos] + 3 * nw; ! 934: ! 935: close(fin); ! 936: ! 937: } /* End of loadfont */ ! 938: ! 939: ! 940: /*****************************************************************************/ ! 941: ! 942: ! 943: error(kind, str, a1, a2) ! 944: ! 945: ! 946: int kind; ! 947: char *str; ! 948: unsigned a1, a2; ! 949: ! 950: ! 951: { ! 952: ! 953: ! 954: /******************************************************************** ! 955: * * ! 956: * Print the error message *str, and quit if the error was * ! 957: * FATAL. * ! 958: * * ! 959: ********************************************************************/ ! 960: ! 961: ! 962: fprintf(fp_error, "make%s: ", tdev); ! 963: ! 964: if ( kind == NON_FATAL ) ! 965: fprintf(fp_error, "warning - "); ! 966: ! 967: fprintf(fp_error, str, a1); ! 968: putc('\n', fp_error); ! 969: ! 970: if ( kind == FATAL ) ! 971: exit(1); ! 972: ! 973: } /* End of error */ ! 974: ! 975: ! 976: /*****************************************************************************/
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.