1 /* rotate.c 4.1 83/04/28 */ 2 /* 3 * Rotate a Varian/Versatec font. 4 */ 5 6 #include <stdio.h> 7 #include <vfont.h> 8 #include <sys/types.h> 9 #include <sys/stat.h> 10 11 char *chp; 12 char *sbrk(); 13 14 main(argc,argv) 15 char **argv; 16 { 17 struct header h; 18 struct dispatch d[256], nd; 19 struct stat stb; 20 off_t tell(); 21 int i,size; 22 int beg; 23 char scr[2048]; 24 25 argc--, argv++; 26 if (argc > 0) { 27 close(0); 28 if (open(argv[0], 0) < 0) 29 perror(argv[0]), exit(1); 30 } 31 if (read(0, &h, sizeof(h)) != sizeof(h)) { 32 fprintf(stderr, "header read error\n"); 33 exit(1); 34 } 35 if (h.magic != 0436) { 36 fprintf(stderr, "bad magic number\n"); 37 exit(1); 38 } 39 if (read(0, d, sizeof(d)) != sizeof(d)) { 40 fprintf(stderr, "dispatch read error\n"); 41 exit(1); 42 } 43 fstat(0, &stb); 44 size = stb.st_size - tell(0); 45 fprintf(stderr, "%d bytes of characters\n", size); 46 chp = sbrk(size + 1024); 47 read(0, chp, size); 48 write(1, &h, sizeof (h)); 49 write(1, d, sizeof (d)); 50 beg = tell(1); 51 for (i = 0; i < 256; i++) 52 if (d[i].nbytes) { 53 if (d[i].addr + d[i].nbytes > size) { 54 fprintf(stderr, "char %d out of range\n", i); 55 continue; 56 } 57 cvt(&d[i], chp+d[i].addr, &nd, scr); 58 d[i] = nd; 59 d[i].addr = tell(1) - beg; 60 write(1, scr, d[i].nbytes); 61 } 62 fprintf(stderr, "done, new size %d\n", tell(1) - beg); 63 h.size = tell(1) - beg; 64 lseek(1, 0, 0); 65 write(1, &h, sizeof (h)); 66 write(1, d, sizeof (d)); 67 } 68 69 cvt(odp, ocp, dp, cp) 70 struct dispatch *odp, *dp; 71 register char *ocp, *cp; 72 { 73 int max; 74 int bpl; 75 int row,byte,bit; 76 register char *ep; 77 register int bitoff; 78 register int bits; 79 int extra; 80 81 max = (odp->up+odp->down+7)/8; 82 extra = max*8 - (odp->down+odp->up); 83 dp->down = odp->down; 84 dp->up = odp->up; 85 dp->left = odp->left; 86 dp->right = odp->right; 87 dp->nbytes = max*(dp->right+dp->left); 88 ep = cp; 89 for (byte = 0; byte < dp->nbytes; byte++) 90 *ep++ = 0; 91 bpl = (dp->right+dp->left+7)/8; 92 for (row = 0; row < odp->up+odp->down; row++) { 93 for (byte = 0; byte < bpl; byte++) { 94 bits = *ocp++; 95 for (bit = 0; bit < 8; bit++) { 96 if (bits & 0x80) { 97 ep = cp + max*(byte*8+bit); 98 bitoff = max*8 - row - 1 - extra; 99 ep += (bitoff/8); 100 *ep |= 0x80 >> (bitoff%8); 101 } 102 bits <<= 1; 103 } 104 } 105 } 106 } 107