xref: /csrg-svn/usr.bin/uucp/uucico/imsg.c (revision 13657)
1*13657Ssam #ifndef lint
2*13657Ssam static char sccsid[] = "@(#)imsg.c	5.1 (Berkeley) 07/02/83";
3*13657Ssam #endif
4*13657Ssam 
5*13657Ssam #include "uucp.h"
6*13657Ssam 
7*13657Ssam char Msync[2] = "\020";
8*13657Ssam /*******
9*13657Ssam  *	imsg(msg, fn)
10*13657Ssam  *	char *msg;
11*13657Ssam  *	int fn;
12*13657Ssam  *
13*13657Ssam  *	imsg  -  this is the initial read message routine -
14*13657Ssam  *	used before a protocol is agreed upon.
15*13657Ssam  *
16*13657Ssam  *	return codes:
17*13657Ssam  *		EOF - no more messages
18*13657Ssam  *		0 - message returned
19*13657Ssam  */
20*13657Ssam 
21*13657Ssam imsg(msg, fn)
22*13657Ssam register char *msg;
23*13657Ssam register int fn;
24*13657Ssam {
25*13657Ssam 	register int ret;
26*13657Ssam 	DEBUG(7, "imsg %s>", "");
27*13657Ssam 	while ((ret = read(fn, msg, 1)) == 1) {
28*13657Ssam 		*msg &= 0177;	/* Turn off parity bit (mhb5b!smb) */
29*13657Ssam 		DEBUG(7, (*msg>037) ? "%c" : "\\%03o", *msg & 0377);
30*13657Ssam 		if (*msg == Msync[0])
31*13657Ssam 			break;
32*13657Ssam 	}
33*13657Ssam 	DEBUG(7, "%s\n", "<");
34*13657Ssam 	if (ret < 1)
35*13657Ssam 		return(EOF);
36*13657Ssam 	while (read(fn, msg, 1) == 1) {
37*13657Ssam 		*msg &= 0177;
38*13657Ssam 		DEBUG(7, (*msg>037) ? "%c" : "\\%03o", *msg & 0377);
39*13657Ssam 		if (*msg == '\n')
40*13657Ssam 			break;
41*13657Ssam 		if (*msg == '\0')
42*13657Ssam 			break;
43*13657Ssam 		msg++;
44*13657Ssam 	}
45*13657Ssam 	*msg = '\0';
46*13657Ssam 	return(0);
47*13657Ssam }
48*13657Ssam 
49*13657Ssam 
50*13657Ssam /***
51*13657Ssam  *	omsg(type, msg, fn)
52*13657Ssam  *	char type, *msg;
53*13657Ssam  *	int fn;
54*13657Ssam  *
55*13657Ssam  *	omsg  -  this is the initial write message routine -
56*13657Ssam  *	used before a protocol is agreed upon.
57*13657Ssam  *
58*13657Ssam  *	return code:  always 0
59*13657Ssam  */
60*13657Ssam 
61*13657Ssam omsg(type, msg, fn)
62*13657Ssam register char *msg;
63*13657Ssam char type;
64*13657Ssam int fn;
65*13657Ssam {
66*13657Ssam 	char buf[BUFSIZ];
67*13657Ssam 	register char *c;
68*13657Ssam 
69*13657Ssam 	c = buf;
70*13657Ssam 	*c++ = Msync[0];
71*13657Ssam 	*c++ = type;
72*13657Ssam 	while (*msg)
73*13657Ssam 		*c++ = *msg++;
74*13657Ssam 	*c++ = '\0';
75*13657Ssam 	write(fn, buf, strlen(buf) + 1);
76*13657Ssam 	return(0);
77*13657Ssam }
78