|
|
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: ! 29: fndsync = 0; ! 30: bmsg = msg; ! 31: CDEBUG(7, "imsg %s>", ""); ! 32: while (read(fn, msg, sizeof(char)) == sizeof(char)) { ! 33: *msg &= 0177; ! 34: c = *msg; ! 35: CDEBUG(7, "%s", c < 040 ? "^" : ""); ! 36: CDEBUG(7, "%c", c < 040 ? c | 0100 : c); ! 37: if (c == MSYNC) { /* look for sync character */ ! 38: msg = bmsg; ! 39: fndsync = 1; ! 40: continue; ! 41: } ! 42: if (!fndsync) ! 43: continue; ! 44: ! 45: if (c == '\0' || c == '\n') { ! 46: *msg = '\0'; ! 47: return(0); ! 48: } ! 49: else ! 50: msg++; ! 51: ! 52: if (msg - bmsg > MAXIMSG) /* unlikely */ ! 53: return(FAIL); ! 54: } ! 55: /* have not found sync or end of message */ ! 56: longjmp(Sjbuf, 1); ! 57: } ! 58: ! 59: /* ! 60: * initial write message routine - ! 61: * used before a protocol is agreed upon. ! 62: * type -> message type ! 63: * msg -> message body address ! 64: * fn -> file descriptor ! 65: * return: ! 66: * Must always return 0 - wmesg (WMESG) looks for zero ! 67: */ ! 68: omsg(type, msg, fn) ! 69: register char *msg; ! 70: register char type; ! 71: int fn; ! 72: { ! 73: char buf[BUFSIZ]; ! 74: ! 75: (void) sprintf(buf, "%c%c%s", MSYNC, type, msg); ! 76: write(fn, buf, strlen(buf) + 1); ! 77: return(0); ! 78: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.