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

unix.superglobalmegacorp.com

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