1*13945Ssam #ifndef lint 2*13945Ssam static char sccsid[] = "@(#)rotate.c 4.2 (Berkeley) 07/16/83"; 3*13945Ssam #endif 4*13945Ssam 512085Sralph /* 612085Sralph * Rotate a Varian/Versatec font. 712085Sralph */ 812085Sralph 912085Sralph #include <stdio.h> 1012085Sralph #include <vfont.h> 1112085Sralph #include <sys/types.h> 1212085Sralph #include <sys/stat.h> 1312085Sralph 1412085Sralph char *chp; 1512085Sralph char *sbrk(); 1612085Sralph 1712085Sralph main(argc,argv) 1812085Sralph char **argv; 1912085Sralph { 2012085Sralph struct header h; 2112085Sralph struct dispatch d[256], nd; 2212085Sralph struct stat stb; 2312085Sralph off_t tell(); 2412085Sralph int i,size; 2512085Sralph int beg; 2612085Sralph char scr[2048]; 2712085Sralph 2812085Sralph argc--, argv++; 2912085Sralph if (argc > 0) { 3012085Sralph close(0); 3112085Sralph if (open(argv[0], 0) < 0) 3212085Sralph perror(argv[0]), exit(1); 3312085Sralph } 3412085Sralph if (read(0, &h, sizeof(h)) != sizeof(h)) { 3512085Sralph fprintf(stderr, "header read error\n"); 3612085Sralph exit(1); 3712085Sralph } 3812085Sralph if (h.magic != 0436) { 3912085Sralph fprintf(stderr, "bad magic number\n"); 4012085Sralph exit(1); 4112085Sralph } 4212085Sralph if (read(0, d, sizeof(d)) != sizeof(d)) { 4312085Sralph fprintf(stderr, "dispatch read error\n"); 4412085Sralph exit(1); 4512085Sralph } 4612085Sralph fstat(0, &stb); 4712085Sralph size = stb.st_size - tell(0); 4812085Sralph fprintf(stderr, "%d bytes of characters\n", size); 4912085Sralph chp = sbrk(size + 1024); 5012085Sralph read(0, chp, size); 5112085Sralph write(1, &h, sizeof (h)); 5212085Sralph write(1, d, sizeof (d)); 5312085Sralph beg = tell(1); 5412085Sralph for (i = 0; i < 256; i++) 5512085Sralph if (d[i].nbytes) { 5612085Sralph if (d[i].addr + d[i].nbytes > size) { 5712085Sralph fprintf(stderr, "char %d out of range\n", i); 5812085Sralph continue; 5912085Sralph } 6012085Sralph cvt(&d[i], chp+d[i].addr, &nd, scr); 6112085Sralph d[i] = nd; 6212085Sralph d[i].addr = tell(1) - beg; 6312085Sralph write(1, scr, d[i].nbytes); 6412085Sralph } 6512085Sralph fprintf(stderr, "done, new size %d\n", tell(1) - beg); 6612085Sralph h.size = tell(1) - beg; 6712085Sralph lseek(1, 0, 0); 6812085Sralph write(1, &h, sizeof (h)); 6912085Sralph write(1, d, sizeof (d)); 7012085Sralph } 7112085Sralph 7212085Sralph cvt(odp, ocp, dp, cp) 7312085Sralph struct dispatch *odp, *dp; 7412085Sralph register char *ocp, *cp; 7512085Sralph { 7612085Sralph int max; 7712085Sralph int bpl; 7812085Sralph int row,byte,bit; 7912085Sralph register char *ep; 8012085Sralph register int bitoff; 8112085Sralph register int bits; 8212085Sralph int extra; 8312085Sralph 8412085Sralph max = (odp->up+odp->down+7)/8; 8512085Sralph extra = max*8 - (odp->down+odp->up); 8612085Sralph dp->down = odp->down; 8712085Sralph dp->up = odp->up; 8812085Sralph dp->left = odp->left; 8912085Sralph dp->right = odp->right; 9012085Sralph dp->nbytes = max*(dp->right+dp->left); 9112085Sralph ep = cp; 9212085Sralph for (byte = 0; byte < dp->nbytes; byte++) 9312085Sralph *ep++ = 0; 9412085Sralph bpl = (dp->right+dp->left+7)/8; 9512085Sralph for (row = 0; row < odp->up+odp->down; row++) { 9612085Sralph for (byte = 0; byte < bpl; byte++) { 9712085Sralph bits = *ocp++; 9812085Sralph for (bit = 0; bit < 8; bit++) { 9912085Sralph if (bits & 0x80) { 10012085Sralph ep = cp + max*(byte*8+bit); 10112085Sralph bitoff = max*8 - row - 1 - extra; 10212085Sralph ep += (bitoff/8); 10312085Sralph *ep |= 0x80 >> (bitoff%8); 10412085Sralph } 10512085Sralph bits <<= 1; 10612085Sralph } 10712085Sralph } 10812085Sralph } 10912085Sralph } 110