Bell 32V development
[unix-history] / usr / src / cmd / uucp / imsg.c
CommitLineData
da6efb07
TL
1#include "uucp.h"
2
3
4char Msync[2] = "\020";
5/*******
6 * imsg(msg, fn)
7 * char *msg;
8 * int fn;
9 *
10 * imsg - this is the initial read message routine -
11 * used before a protocol is agreed upon.
12 *
13 * return codes:
14 * EOF - no more messages
15 * 0 - message returned
16 */
17
18imsg(msg, fn)
19char *msg;
20int fn;
21{
22 int ret;
23 DEBUG(7, "imsg %s>", "");
24 while ((ret = read(fn, msg, 1)) == 1) {
25 DEBUG(7, "%c", (*msg > 037) ? *msg : '-');
26 if (*msg == Msync[0])
27 break;
28 }
29 DEBUG(7, "%s\n", "<");
30 if (ret < 1)
31 return(EOF);
32 while (read(fn, msg, 1) == 1) {
33 DEBUG(7, "%c", (*msg > 037) ? *msg : '-');
34 if (*msg == '\n')
35 break;
36 if (*msg == '\0')
37 break;
38 msg++;
39 }
40 *msg = '\0';
41 return(0);
42}
43
44
45/***
46 * omsg(type, msg, fn)
47 * char type, *msg;
48 * int fn;
49 *
50 * omsg - this is the initial write message routine -
51 * used before a protocol is agreed upon.
52 *
53 * return code: always 0
54 */
55
56omsg(type, msg, fn)
57char *msg, type;
58int fn;
59{
60 char buf[BUFSIZ], *c;
61
62 c = buf;
63 *c++ = Msync[0];
64 *c++ = type;
65 while (*msg)
66 *c++ = *msg++;
67 *c++ = '\0';
68 write(fn, buf, strlen(buf) + 1);
69 return(0);
70}