Annotation of researchv9/X11/src/X.V11R1/util/vtobdf/vtobdf.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char rcsid[] =
                      3:     "@(#) $Header: vtobdf.c,v 1.1 87/09/11 08:16:28 toddb Exp $ (LBL)";
                      4: #endif
                      5: 
                      6: #include <stdio.h>
                      7: #include <strings.h>
                      8: #include <ctype.h>
                      9: #include <sys/file.h>
                     10: /*
                     11: #include <sys/param.h>
                     12: */
                     13: #include <sys/types.h>
                     14: #include <sys/stat.h>
                     15: #include <vfont.h>
                     16: 
                     17: #define SPACE                  32      /* space index */
                     18: #define DELETE                 127     /* delete index */
                     19: #define LAST_CHAR              127     /* delete */
                     20: #define FIRST_CHAR             0       /* null */
                     21: #define NUM_CHAR               128     /* total number of characters */
                     22: 
                     23: static void
                     24: punt(str)
                     25: caddr_t        str;
                     26: {
                     27:        fprintf(stderr, "%s\n", str);
                     28:        perror("vtobdf");
                     29:        exit(1);
                     30: }
                     31: 
                     32: static void
                     33: vtobdf(vfile, bdffile, bdfname)
                     34:        FILE *vfile, *bdffile;
                     35:        char *bdfname;
                     36: {
                     37:        int             i;
                     38:        int j;
                     39:        struct stat             stb;
                     40:        struct header           header;
                     41:        struct dispatch         dispatch[NUM_DISPATCH];
                     42:        int                     bitmapWidth;
                     43:        int                     maxUp, maxDown, maxWidth, maxHeight;
                     44:        int                     fixed;
                     45:        int fontsize;
                     46:        register char *cp;
                     47:        char buf[2048];
                     48:        int num_chars;
                     49: 
                     50: #define FONTBASE       (sizeof(header) + sizeof(dispatch))
                     51: 
                     52:        /* read vfont header */
                     53:        if (read(fileno(vfile), (caddr_t) &header, sizeof(header)) != sizeof(header))
                     54:                punt("Error reading vfont header.");
                     55: 
                     56:        /* check magic number */
                     57:        if (header.magic != VFONT_MAGIC)
                     58:                punt("Not VFONT_MAGIC.");
                     59: 
                     60:        /* read vfont dispatch */
                     61:        if (read(fileno(vfile), (caddr_t) dispatch, sizeof(dispatch)) != 
                     62:                sizeof(dispatch))
                     63:                punt("Error reading vfont dispatch table.");
                     64: 
                     65:        /* stat the file descriptor to check file size */
                     66:        if (fstat(fileno(vfile), &stb) < 0) {
                     67:                perror(vfile);
                     68:                exit(1);
                     69:        }
                     70: 
                     71:        /* check file size */
                     72:        if (stb.st_size != FONTBASE + header.size)
                     73:                punt("Invalid file size.");
                     74: 
                     75:        /* Figure out font size */
                     76:        fontsize = 6;   /* default */
                     77:        cp = rindex(bdfname, '-');
                     78:        if (cp) {
                     79:                cp++;
                     80:                if (sscanf(cp, "%d", &i) == 1 && i > 0)
                     81:                        fontsize = i;
                     82:        }
                     83: 
                     84:         /* initialize */
                     85:         num_chars = maxWidth = maxUp = maxDown = 0;
                     86:         /* determine maximum width, up and down for font */
                     87:        for (i = 0, bitmapWidth = 0, fixed = 0; i < NUM_CHAR; i++) {
                     88:                register struct dispatch        *d;
                     89:                register int                    width;
                     90: 
                     91:                d = &dispatch[i + FIRST_CHAR];
                     92: 
                     93:                if (d->nbytes)
                     94:                        num_chars++;
                     95: 
                     96:                width = d->left + d->right;
                     97:                if (i == 0)
                     98:                        fixed = width;
                     99:                else if (width != fixed)
                    100:                        fixed = 0;
                    101:                if (width > maxWidth)
                    102:                        maxWidth = width;
                    103:                if (d->up > maxUp)
                    104:                        maxUp = d->up;
                    105:                if (d->down > maxDown)
                    106:                        maxDown = d->down;
                    107:                bitmapWidth += width;
                    108:        }
                    109:        maxHeight = maxUp + maxDown;
                    110: 
                    111:        /* Start spewing stuff out */
                    112:        fprintf(bdffile, "STARTFONT 2.1\n");
                    113:        fprintf(bdffile, "FONT %s\n", bdfname);
                    114:        fprintf(bdffile, "SIZE %d 78 78\n", fontsize);
                    115:        fprintf(bdffile, "FONTBOUNDINGBOX %d %d %d %d\n",
                    116:            header.maxx, header.maxy, 0, -maxDown);
                    117:        fprintf(bdffile, "STARTPROPERTIES 3\n");
                    118:        fprintf(bdffile, "FONT_ASCENT %d\n", maxUp);
                    119:        fprintf(bdffile, "FONT_DESCENT %d\n", maxDown);
                    120:        fprintf(bdffile, "DEFAULT_CHAR %d\n", 040);
                    121:        fprintf(bdffile, "ENDPROPERTIES\n");
                    122:        fprintf(bdffile, "CHARS %d\n", num_chars);
                    123: 
                    124:        for (i = 0; i < NUM_CHAR; i++) {
                    125:                struct dispatch         *d;
                    126:                int                     width, height;
                    127: 
                    128:                /* entry in dispatch array */
                    129:                d = &dispatch[i + FIRST_CHAR];
                    130: 
                    131:                /* check to see if this character is defined */
                    132:                if (d->nbytes == 0)
                    133:                        continue;
                    134: 
                    135:                if (isprint(i) && !isspace(i))
                    136:                        fprintf(bdffile, "STARTCHAR %c\n", i);
                    137:                else
                    138:                        fprintf(bdffile, "STARTCHAR C%03o\n", i);
                    139:                fprintf(bdffile, "ENCODING %d\n", i);
                    140: 
                    141:                /* width in pixels */
                    142:                width = d->left + d->right;
                    143: 
                    144:                fprintf(bdffile, "SWIDTH %d %d\n", fontsize * width, 0);
                    145:                fprintf(bdffile, "DWIDTH %d %d\n", width, 0);
                    146: 
                    147:                /* height in pixels */
                    148:                height = d->up + d->down;
                    149: 
                    150:                fprintf(bdffile, "BBX %d %d %d %d\n",
                    151:                    width, height, d->left, -d->down);
                    152: 
                    153:                fprintf(bdffile, "BITMAP\n");
                    154: 
                    155:                if (d->addr > sizeof(buf)) {
                    156:                        fprintf(stderr, "d->addr is %d, bufsize is %d",
                    157:                            d->addr, sizeof(buf));
                    158:                        punt("foo");
                    159:                }
                    160:                if (lseek(fileno(vfile), FONTBASE + d->addr, 0) < 0)
                    161:                        punt("Can't seek in vfont file.");
                    162:                if (read(fileno(vfile), buf, d->nbytes) != d->nbytes)
                    163:                        punt("Error reading vfont data.");
                    164:                cp = buf;
                    165:                for (j = d->nbytes; j > 0; j--) {
                    166:                        int k;
                    167:                        k = (unsigned char)*cp;
                    168:                        cp++;
                    169:                        fprintf(bdffile, "%02x\n", k);
                    170:                }
                    171: 
                    172:                fprintf(bdffile, "ENDCHAR\n");
                    173:        }
                    174: 
                    175:        fprintf(bdffile, "ENDFONT\n");
                    176: 
                    177: }
                    178: 
                    179: main(argc, argv)
                    180:        int argc;
                    181:        char **argv;
                    182: {
                    183:        char *vname, *bdfname;
                    184:        FILE *vfile, *bdffile;
                    185: 
                    186:        if (argc != 3) {
                    187:                fprintf(stderr, "vtobdf: vname bdfname\n");
                    188:                exit(1);
                    189:        }
                    190: 
                    191:        vname = argv[1];
                    192:        bdfname = argv[2];
                    193: 
                    194:        if ((vfile = fopen(vname, "r")) == NULL) {
                    195:                perror(vname);
                    196:                exit(1);
                    197:        }
                    198: 
                    199:        if ((bdffile = fopen(bdfname, "w")) == NULL) {
                    200:                perror(bdfname);
                    201:                exit(1);
                    202:        }
                    203: 
                    204:        vtobdf(vfile, bdffile, bdfname);
                    205: 
                    206:        fclose(vfile);
                    207:        fclose(bdffile);
                    208: 
                    209:        exit(0);
                    210: }

unix.superglobalmegacorp.com

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