Annotation of researchv10no/cmd/asd/seal.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     seal - prepare a package for shipment
        !             3:  */
        !             4: 
        !             5: #include "asd.h"
        !             6: #include "seal.h"
        !             7: #include <ctype.h>
        !             8: 
        !             9: static long length;
        !            10: static unsigned long checksum;
        !            11: 
        !            12: main (argc, argv)
        !            13:        int argc;
        !            14:        char **argv;
        !            15: {
        !            16:        int rc = 0;
        !            17:        static char stdbuf[BUFSIZ];
        !            18: 
        !            19:        setbuf (stdout, stdbuf);
        !            20: 
        !            21:        length = 0;
        !            22:        checksum = 0;
        !            23: 
        !            24:        rc = getargs (argc, argv, "kK:", seal);
        !            25: 
        !            26:        printf ("!end %ld %lu\n", length, checksum);
        !            27: 
        !            28:        return rc;
        !            29: }
        !            30: 
        !            31: 
        !            32: seal (f, fname)
        !            33:        register FILE *f;
        !            34:        char *fname;
        !            35: {
        !            36:        static int first = 1;
        !            37: 
        !            38:        if (first) {
        !            39:                first = 0;
        !            40:                printf ("!<seal>\n");
        !            41:        }
        !            42: 
        !            43:        do {
        !            44:                char line[MAXLINE];
        !            45:                char outline[MAXLINE*3+10];
        !            46:                register char *p, *endl;
        !            47:                register int ch;
        !            48: 
        !            49:                /* read a line, possibly short */
        !            50:                p = line;
        !            51:                endl = line + MAXLINE;
        !            52: 
        !            53:                do {
        !            54:                        ch = getc (f);
        !            55:                        if (ch == EOF)
        !            56:                                break;
        !            57:                        *p++ = ch;
        !            58:                } while (ch != '\n' && p < endl);
        !            59: 
        !            60:                endl = p;
        !            61: 
        !            62:                /*
        !            63:                 * endl now points one past the last char
        !            64:                 * in the line we have read.  If we didn't
        !            65:                 * get any characters at all, we're done.
        !            66:                 */
        !            67: 
        !            68:                if (line == endl)
        !            69:                        return ferror (f) != 0;
        !            70: 
        !            71:                length += endl - line;
        !            72: 
        !            73:                /* now convert the line to external form */
        !            74:                ch = hrform (line, endl, outline);
        !            75:                if (ch > (endl - line + INCPW - 1) / INCPW * OUTCPW + 2)
        !            76:                        ch = mrform (line, endl, outline);
        !            77:                p = outline;
        !            78: 
        !            79:                /* if encrypting, do so */
        !            80:                if (kflag || Kflag)
        !            81:                        mangle (line, endl);
        !            82: 
        !            83:                /* accumulate the (possibly encrypted) checksum */
        !            84:                checksum = mkcsum (checksum, line, endl);
        !            85: 
        !            86:                while (--ch >= 0)
        !            87:                        putchar (*p++);
        !            88:        } while (!feof (f) && !ferror (f));
        !            89: 
        !            90:        return ferror (f) != 0;
        !            91: }
        !            92: 
        !            93: /*
        !            94:  *     convert the characters in the range (in,inend] to
        !            95:  *     storage starting at "out" -- return the number of
        !            96:  *     output characters.
        !            97:  */
        !            98: 
        !            99: int
        !           100: hrform (in, inend, out)
        !           101:        register char *in, *inend;
        !           102:        char *out;
        !           103: {
        !           104:        register char *r = out;
        !           105: 
        !           106:        /* special handling for the first character(s) */
        !           107:        if (in < inend) {
        !           108:                if (*in == '.' || *in == '!' ||
        !           109:                    (*in == 'F' && strncmp (in, "From", 4) == 0))
        !           110:                        *r++ = '\\';
        !           111: 
        !           112:                do {
        !           113:                        register int ch = (unsigned char) *in++;
        !           114: 
        !           115:                        if (isprint (ch)) {
        !           116:                                if (ch == '\\')
        !           117:                                        *r++ = '\\';
        !           118:                                *r++ = ch;
        !           119:                        } else {
        !           120:                                if (ch == ' ' || ch == '\t' || ch == '\n')
        !           121:                                        *r++ = ch;
        !           122:                                else {
        !           123:                                        *r++ = '\\';
        !           124:                                        *r++ = hextab[(ch >> 4) & 0xf];
        !           125:                                        *r++ = hextab[ch & 0xf];
        !           126:                                }
        !           127:                        }
        !           128:                } while (in < inend);
        !           129: 
        !           130:                if (r[-1] != '\n') {
        !           131:                        *r++ = '\\';
        !           132:                        *r++ = '\n';
        !           133:                }
        !           134:        }
        !           135: 
        !           136:        return r - out;
        !           137: }
        !           138: 
        !           139: int
        !           140: mrform (in, inend, out)
        !           141:        register char *in;
        !           142:        char *inend, *out;
        !           143: {
        !           144:        char *r;
        !           145:        register int len;
        !           146: 
        !           147:        len = inend - in;
        !           148:        if (len <= 0)
        !           149:                return 0;
        !           150: 
        !           151:        r = out;
        !           152: 
        !           153:        *r++ = '.';
        !           154: 
        !           155:        do {
        !           156:                register unsigned long bits;
        !           157:                register int n, outn;
        !           158:                register char *rr;
        !           159: 
        !           160:                n = len;
        !           161:                if (n > INCPW)
        !           162:                        n = INCPW;
        !           163:                len -= n;
        !           164:                outn = n + OUTCPW - INCPW;
        !           165: 
        !           166:                bits = 0;
        !           167:                do      bits = (bits << BPC) | (*in++ & BYTEMASK);
        !           168:                while (--n > 0);
        !           169: 
        !           170:                rr = r = r + outn;
        !           171:                do {
        !           172:                        *--rr = RADBASE + bits % RADIX;
        !           173:                        bits /= RADIX;
        !           174:                } while (--outn > 0);
        !           175:        } while (len > 0);
        !           176: 
        !           177:        *r++ = '\n';
        !           178: 
        !           179:        return r - out;
        !           180: }

unix.superglobalmegacorp.com

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