Annotation of 43BSDTahoe/new/dipress/src/bin/makextdev/makextdev.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *  makextdev - make an extended character code table for the ditroff
        !             3:  *             interpress converter.
        !             4:  *
        !             5:  * Copyright (c) 1984, 1985, 1986 Xerox Corp.
        !             6:  *
        !             7:  *  History:
        !             8:  *     24-oct-85  ed flint     close fontfiles, ran out of open file
        !             9:  *                             descriptors with large number of fonts
        !            10:  *
        !            11:  *  Some of the characters in the interpress fonts have character codes
        !            12:  *  greater than 255.  Since the ditroff character code table is an array of
        !            13:  *  char, the codes are too large.  This attempts to remedy that situation.
        !            14:  *  If the character code specified in the normal code table is 0377 (decimal
        !            15:  *  255), then the real code can be found in the extended table (which is an
        !            16:  *  array of short).  This program reads the same files that makedev reads and
        !            17:  *  build the extended code table.
        !            18:  *
        !            19:  *  To specify an extended code in a font table, use a line of the following
        !            20:  *  form:
        !            21:  *
        !            22:  *         c       www     kk      0377    xxxxx
        !            23:  *
        !            24:  *  where:  c is the one or two letter character code,
        !            25:  *         www is the character's width,
        !            26:  *         kk is the kerning information, and
        !            27:  *         xxxxx is the actual interpress code for the character.
        !            28:  *
        !            29:  *  Basically, this is just like any other line in the font table file, except
        !            30:  *  that the standard code is set to 0377 and the actual code is placed on the
        !            31:  *  line as the fifth item.  Note that a file with lines like this can still
        !            32:  *  be run thru makedev successfully -- makedev will just ignore the fifth
        !            33:  *  item on the line.
        !            34:  *
        !            35:  *  One can make the extended tables for all the loaded fonts by saying
        !            36:  *  "makextdev DESC" (just as with makedev), but makedev must be run before
        !            37:  *  doing this, since it will require looking at DESC.out.
        !            38:  */
        !            39: 
        !            40: # include "deviceinfo.h"
        !            41: # include <stdio.h>
        !            42: # include <sys/types.h>
        !            43: # include <strings.h>
        !            44: 
        !            45: # define       Line_length     256
        !            46: 
        !            47: # define       Max_chars       256     /* maximum # of funny chars */
        !            48: /* Tab_size includes all ascii characters except control characters */
        !            49: # define       Table_size      (Max_chars + 128 - 32)
        !            50: 
        !            51: # define       white(ch)       ((ch) == ' ' || (ch) == '\t' || (ch) == '\n')
        !            52: 
        !            53: /* values returned by strcmp */
        !            54: # define       Equal   0
        !            55: 
        !            56: char   char_name[5 * Max_chars];
        !            57: short  char_index_table[Max_chars];
        !            58: 
        !            59: unsigned char  font_index_table[Table_size];
        !            60: unsigned short extend_table[Table_size];
        !            61: struct device_entry device_entry;
        !            62: 
        !            63: main(argc, argv)
        !            64: 
        !            65: int  argc;
        !            66: char *argv[];
        !            67: 
        !            68: {
        !            69:     int fntcnt;
        !            70:     int descfd;
        !            71:     register char *ptr;
        !            72:     char line[Line_length];
        !            73:     char keyword[80];
        !            74:     char *fname;
        !            75:     FILE *descfile;
        !            76: 
        !            77:     if (argc < 2)
        !            78:     {
        !            79:        fprintf(stderr, "usage: makextdev font\n");
        !            80:        exit(1);
        !            81:     }
        !            82: 
        !            83:     /* First off, get the DESC.out file -- we need the information */
        !            84:     if ((descfd = open("DESC.out", 0)) == -1)
        !            85:     {
        !            86:        perror("DESC.out");
        !            87:        fprintf(stderr, "makextdev: please run \"makedev DESC\" first!\n");
        !            88:        exit(1);
        !            89:     }
        !            90: 
        !            91:     /* read struct device_entry off the front */
        !            92:     (void) read(descfd, (char *)&device_entry, sizeof(device_entry));
        !            93: 
        !            94:     /* skip over the point size table */
        !            95:     (void) lseek(descfd, (device_entry.num_sizes + 1) * sizeof(short), 1);
        !            96: 
        !            97:     /* read char_index_table and char_name arrays */
        !            98:     (void) read(descfd, (char *)char_index_table, device_entry.spec_char_num * sizeof(short));
        !            99:     (void) read(descfd, char_name, device_entry.spec_name_len);
        !           100: #ifdef DEBUG
        !           101:     for (i=0; i<device_entry.spec_char_num; i++)
        !           102:     {
        !           103:        fprintf(stderr, "%d  ", char_index_table[i]);
        !           104:     }
        !           105:     fputc('\n', stderr);
        !           106:     for (i=0; i<device_entry.spec_char_num; i++)
        !           107:     {
        !           108:        if (char_name[i] == '\0')
        !           109:        {
        !           110:            fputc(' ', stderr);
        !           111:        }
        !           112:        else
        !           113:        {
        !           114:            fputc(char_name[i], stderr);
        !           115:        }
        !           116:     }
        !           117:     fputc('\n', stderr);
        !           118: #endif
        !           119: 
        !           120:     /* step thru the arguments */
        !           121:     while (--argc > 0)
        !           122:     {
        !           123:        fname = *++argv;
        !           124: 
        !           125:        if (strcmp(fname, "DESC") == Equal)
        !           126:        {
        !           127:            /* do all the preloaded fonts */
        !           128:            if ((descfile = fopen(fname, "r")) == NULL)
        !           129:            {
        !           130:                perror(fname);
        !           131:                exit(1);
        !           132:            }
        !           133: 
        !           134:            /* scan thru DESC looking for the "fonts" keyword */
        !           135:            do
        !           136:            {
        !           137:                if (fgets(line, Line_length, descfile) == NULL)
        !           138:                {
        !           139:                    fprintf(stderr, "makextdev: no fonts listed in DESC\n");
        !           140:                    exit(1);
        !           141:                }
        !           142:                (void) sscanf(line, "%s", keyword);
        !           143:            } while (strcmp(keyword, "fonts") != Equal);
        !           144: 
        !           145:            /* found the line -- do each font listed on the line */
        !           146:            /* line looks like this:  fonts n X X X X ...        */
        !           147:            /* where n is number of fonts and X is a font name   */
        !           148:            (void) fclose(descfile);
        !           149:            ptr = line + 5;     /* 5 == strlen("fonts") */
        !           150:            while (white(*ptr))
        !           151:            {
        !           152:                ptr++;          /* never trust a macro */
        !           153:            }
        !           154: 
        !           155:            /* get font count */
        !           156:            fntcnt = atoi(ptr);
        !           157:            while (!white(*ptr))
        !           158:            {
        !           159:                ptr++;
        !           160:            }
        !           161:            while (white(*ptr))
        !           162:            {
        !           163:                ptr++;
        !           164:            }
        !           165: 
        !           166:            /* process each font on the line */
        !           167:            while (fntcnt-- > 0)
        !           168:            {
        !           169:                register char *fontname;
        !           170: 
        !           171:                fontname = ptr;
        !           172:                while (!white(*ptr))
        !           173:                {
        !           174:                    ptr++;
        !           175:                }
        !           176:                *ptr++ = '\0';
        !           177:                dofont(fontname);
        !           178:                while (white(*ptr))
        !           179:                {
        !           180:                    ptr++;
        !           181:                }
        !           182:            }
        !           183:        }
        !           184:        else
        !           185:        {
        !           186:            dofont(fname);
        !           187:        }
        !           188:     }
        !           189: }
        !           190: 
        !           191: dofont(fontname)
        !           192: 
        !           193: char *fontname;
        !           194: 
        !           195: {
        !           196:     int outfile;
        !           197:     int i;
        !           198:     int ccode;
        !           199:     unsigned int xcode;
        !           200:     char outname[20];
        !           201:     char ch[10];
        !           202:     char swid[10];
        !           203:     char skern[10];
        !           204:     char scode[10];
        !           205:     char sauxcode[10];
        !           206:     char line[Line_length];
        !           207:     char keyword[20];
        !           208:     FILE *fontfile;
        !           209:     struct font_entry font_entry;
        !           210: 
        !           211:     /* open the file that describes the font */
        !           212:     if ((fontfile = fopen(fontname, "r")) == NULL)
        !           213:     {
        !           214:        perror(fontname);
        !           215:        exit(1);
        !           216:     }
        !           217: 
        !           218:     /* find the keyword "charset" */
        !           219:     do
        !           220:     {
        !           221:        if (fgets(line, Line_length, fontfile) == NULL)
        !           222:        {
        !           223:            fprintf(stderr, "makextdev: font %s has no charset\n", fontname);
        !           224:            exit(1);
        !           225:        }
        !           226:        (void) sscanf(line, "%s", keyword);
        !           227:     } while (strcmp(keyword, "charset") != Equal);
        !           228: 
        !           229:     /* get font info from *.out file */
        !           230:     /* first, open it               */
        !           231:     (void) strcpy(outname, fontname);
        !           232:     (void) strcat(outname, ".out");
        !           233:     if ((outfile = open(outname, 0)) == -1)
        !           234:     {
        !           235:        perror(outname);
        !           236:        fprintf(stderr, "makextdev: please run \"makedev %s\" first!\n",
        !           237:                fontname);
        !           238:        exit(1);
        !           239:     }
        !           240: 
        !           241:     /* zero extend_table */
        !           242:     bzero(extend_table, sizeof(extend_table));
        !           243: 
        !           244:     /* now read the header and font_index_table */
        !           245:     (void) read(outfile, (char *)&font_entry, sizeof(font_entry));
        !           246:     (void) lseek(outfile, (off_t)((unsigned char)(font_entry.num_char_wid) * 3), 1);   /* skip width, kern, and code */
        !           247:     (void) read(outfile, (char *)font_index_table, device_entry.spec_char_num + 128 - 32);
        !           248:     (void) close(outfile);
        !           249: 
        !           250:     /* unscramble each line */
        !           251:     while (fgets(line, Line_length, fontfile) != NULL)
        !           252:     {
        !           253:        i = sscanf(line, "%s %s %s %s %s", ch, swid, skern, scode, sauxcode);
        !           254: 
        !           255:        if (swid[0] != '"')
        !           256:        {
        !           257:            /* translate scode and auxcode into actual numerical values */
        !           258:            ccode = convcode(scode);
        !           259:            xcode = convcode(sauxcode);
        !           260:        }
        !           261:        else
        !           262:        {
        !           263:            /* it's a repeat of the last character */
        !           264:            i = 5;
        !           265:        }
        !           266: 
        !           267:        /* check for extended code */
        !           268:        if (ccode == 0377)
        !           269:        {
        !           270:            if (i < 5)
        !           271:            {
        !           272:                fprintf(stderr, "%s: character %s has no extended code\n",
        !           273:                        fontname, ch);
        !           274:            }
        !           275:            else
        !           276:            {
        !           277:                /* find the findex and store the extended code in extend_table */
        !           278:                if (strlen(ch) == 1)
        !           279:                {
        !           280: /*                 fprintf(stderr, "font_index_table[%d] = %d\n", 
        !           281:                        ch[0] - 32, font_index_table[ch[0] - 32]);
        !           282: */                 extend_table[font_index_table[ch[0] - 32]] = xcode;
        !           283:                }
        !           284:                else
        !           285:                {
        !           286:                    /* it's a funny name */
        !           287:                    for (i = 0; i < device_entry.spec_char_num; i++)
        !           288:                    {
        !           289:                        if (strcmp(&char_name[char_index_table[i]], ch) == Equal)
        !           290:                        {
        !           291: /*                         fprintf(stderr, "i = %d, font_index_table[%d] = %d\n",
        !           292:                                i, i+128-32, font_index_table[i+128-32]);
        !           293: */
        !           294:                            extend_table[font_index_table[i + 128-32]] = xcode;
        !           295:                            break;
        !           296:                        }
        !           297:                    }
        !           298:                }
        !           299:            }
        !           300:        }
        !           301:     }
        !           302: 
        !           303:     /* Now, write extend_table in an appropriate file */
        !           304:     /* remember: outname currently looks like "XX.out" */
        !           305:     (void) strcat(outname, ".ext");
        !           306:     if ((outfile = creat(outname, 0666)) == -1)
        !           307:     {
        !           308:        perror(outname);
        !           309:        exit(1);
        !           310:     }
        !           311:     (void) write(outfile, (char *)extend_table, (device_entry.spec_char_num + 128-32) * sizeof(short));
        !           312:     (void) close(outfile);
        !           313:     (void) fclose(fontfile);
        !           314: }
        !           315: 
        !           316: convcode(str)
        !           317: 
        !           318: char *str;
        !           319: 
        !           320: {
        !           321:     int val;
        !           322: 
        !           323:     if (str[0] == '0')
        !           324:     {
        !           325:        (void) sscanf(str, "%o", &val);
        !           326:     }
        !           327:     else
        !           328:     {
        !           329:        val = atoi(str);
        !           330:     }
        !           331: 
        !           332:     return(val);
        !           333: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.