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