Annotation of researchv10no/cmd/uucp/imsg.c, revision 1.1

1.1     ! root        1: /*     /sccs/src/cmd/uucp/s.imsg.c
        !             2:        imsg.c  1.1     8/30/84 17:37:29
        !             3: */
        !             4: #include "uucp.h"
        !             5: VERSION(@(#)imsg.c     1.1);
        !             6: 
        !             7: #define MSYNC  '\020'
        !             8: /* maximum likely message - make sure you don't get run away input */
        !             9: #define MAXIMSG        256
        !            10: 
        !            11: /*
        !            12:  * read message routine used before a
        !            13:  * protocol is agreed upon.
        !            14:  *     msg     -> address of input buffer
        !            15:  *     fn      -> input file descriptor 
        !            16:  * returns:
        !            17:  *     EOF     -> no more messages
        !            18:  *     0       -> message returned
        !            19:  */
        !            20: imsg(msg, fn)
        !            21: register char *msg;
        !            22: register int fn;
        !            23: {
        !            24:        register char c;
        !            25:        short fndsync;
        !            26:        char *bmsg;
        !            27:        extern jmp_buf Sjbuf;
        !            28:        extern int errno;
        !            29: 
        !            30:        fndsync = 0;
        !            31:        bmsg = msg;
        !            32:        CDEBUG(7, "imsg %s>", "");
        !            33:        errno = 0;      /* only for debugging */
        !            34:        while (read(fn, msg, sizeof(char)) == sizeof(char)) {
        !            35:                *msg &= 0177;
        !            36:                c = *msg;
        !            37:                CDEBUG(7, "%s", c < 040 ? "^" : "");
        !            38:                CDEBUG(7, "%c", c < 040 ? c | 0100 : c);
        !            39:                if (c == MSYNC) { /* look for sync character */
        !            40:                        msg = bmsg;
        !            41:                        fndsync = 1;
        !            42:                        continue;
        !            43:                }
        !            44:                if (!fndsync)
        !            45:                        continue;
        !            46: 
        !            47:                if (c == '\0' || c == '\n') {
        !            48:                        *msg = '\0';
        !            49:                        return(0);
        !            50:                }
        !            51:                else
        !            52:                        msg++;
        !            53: 
        !            54:                if (msg - bmsg > MAXIMSG)       /* unlikely */
        !            55:                        return(FAIL);
        !            56:        }
        !            57:        CDEBUG(7, "\nread failed (%d)\n", errno);
        !            58:        /* have not found sync or end of message */
        !            59:        longjmp(Sjbuf, 1);
        !            60: }
        !            61: 
        !            62: /*
        !            63:  * initial write message routine -
        !            64:  * used before a protocol is agreed upon.
        !            65:  *     type    -> message type
        !            66:  *     msg     -> message body address
        !            67:  *     fn      -> file descriptor
        !            68:  * return: 
        !            69:  *     Must always return 0 - wmesg (WMESG) looks for zero
        !            70:  */
        !            71: omsg(type, msg, fn)
        !            72: register char *msg;
        !            73: register char type;
        !            74: int fn;
        !            75: {
        !            76:        char buf[BUFSIZ];
        !            77: 
        !            78:        (void) sprintf(buf, "%c%c%s", MSYNC, type, msg);
        !            79:        CDEBUG(7, "omsg >%s<\n", buf);
        !            80:        write(fn, buf, strlen(buf) + 1);
        !            81:        return(0);
        !            82: }

unix.superglobalmegacorp.com

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