Annotation of 41BSD/cmd/vpr/rotate.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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