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

Defined functions

cvt defined in line 78; used 1 times
  • in line 66
main defined in line 23; never used

Defined variables

chp defined in line 20; used 3 times
sccsid defined in line 8; never used
Last modified: 1985-05-15
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1143
Valid CSS Valid XHTML 1.0 Strict