9 date 93.08.25.17.29.53; author jromine; state Exp;
14 date 92.12.15.00.20.22; author jromine; state Exp;
19 date 92.10.20.22.43.58; author jromine; state Exp;
24 date 92.10.20.15.36.28; author jromine; state Exp;
29 date 92.05.12.21.52.22; author jromine; state Exp;
34 date 92.05.12.21.51.35; author jromine; state Exp;
39 date 92.02.10.20.25.09; author jromine; state Exp;
44 date 92.01.31.22.29.16; author jromine; state Exp;
49 date 90.04.05.15.02.58; author sources; state Exp;
54 date 90.02.06.13.34.37; author sources; state Exp;
59 date 90.02.06.13.33.43; author sources; state Exp;
70 @off_t fixes for BSD44
73 @/* vmhsbr.c - routines to help vmh along */
75 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.10 1992/12/15 00:20:22 jromine Exp jromine $";
79 INI: include width of windows
83 #include "../h/vmhsbr.h"
88 static char *types[] = {
90 "INI", "ACK", "ERR", "CMD", "QRY", "TTY", "WIN", "DATA", "EOF", "FIN",
94 static FILE *fp = NULL;
96 static int PEERrfd = NOTOK;
97 static int PEERwfd = NOTOK;
103 extern char *sys_errlist[];
109 int rcinit (rfd, wfd)
119 if ((cp = getenv ("MHVDEBUG")) && *cp) {
120 (void) sprintf (buffer, "%s.out", invo_name);
121 if (fp = fopen (buffer, "w")) {
122 (void) fseek (fp, 0L, 2);
123 fprintf (fp, "%d: rcinit (%d, %d)\n", getpid (), rfd, wfd);
133 if (PEERrfd != NOTOK)
134 (void) close (PEERrfd);
135 if (PEERwfd != NOTOK)
136 (void) close (PEERwfd);
147 int rc2rc (code, len, data, rc)
153 if (rc2peer (code, len, data) == NOTOK)
160 int str2rc (code, str, rc)
165 return rc2rc (code, str ? strlen (str) : 0, str, rc);
171 register struct record *rc;
174 free (rc -> rc_data);
176 if (read (PEERrfd, (char *) rc_head (rc), RHSIZE (rc)) != RHSIZE (rc))
177 return rclose (rc, "read from peer lost(1)");
179 if ((rc -> rc_data = malloc ((unsigned) rc -> rc_len + 1)) == NULL)
180 return rclose (rc, "malloc of %d lost", rc -> rc_len + 1);
181 if (read (PEERrfd, rc -> rc_data, rc -> rc_len) != rc -> rc_len)
182 return rclose (rc, "read from peer lost(2)");
183 rc -> rc_data[rc -> rc_len] = 0;
186 rc -> rc_data = NULL;
189 (void) fseek (fp, 0L, 2);
190 fprintf (fp, "%d: <--- %s %d: \"%*.*s\"\n", getpid (),
191 types[rc -> rc_type], rc -> rc_len,
192 rc -> rc_len, rc -> rc_len, rc -> rc_data);
196 return rc -> rc_type;
201 int rc2peer (code, len, data)
207 register struct record *rc = &rcs;
209 rc -> rc_type = code;
213 (void) fseek (fp, 0L, 2);
214 fprintf (fp, "%d: ---> %s %d: \"%*.*s\"\n", getpid (),
215 types[rc -> rc_type], rc -> rc_len,
216 rc -> rc_len, rc -> rc_len, data);
220 if (write (PEERwfd, (char *) rc_head (rc), RHSIZE (rc)) != RHSIZE (rc))
221 return rclose (rc, "write to peer lost(1)");
224 if (write (PEERwfd, data, rc -> rc_len) != rc -> rc_len)
225 return rclose (rc, "write to peer lost(2)");
232 int str2peer (code, str)
236 return rc2peer (code, str ? strlen (str) : 0, str);
242 int fmt2peer (code, fmt, a, b, c, d, e, f)
252 return err2peer (code, NULLCP, fmt, a, b, c, d, e, f);
259 int err2peer (code, what, fmt, a, b, c, d, e, f)
272 char buffer[BUFSIZ * 2];
274 (void) sprintf (buffer, fmt, a, b, c, d, e, f);
275 bp = buffer + strlen (buffer);
278 (void) sprintf (bp, " %s: ", what);
281 if (eindex > 0 && eindex < sys_nerr)
282 (void) strcpy (bp, sys_errlist[eindex]);
284 (void) sprintf (bp, "Error %d", eindex);
288 return rc2peer (code, bp - buffer, buffer);
295 static int rclose (rc, fmt, a, b, c, d, e, f)
296 register struct record *rc;
305 static char buffer[BUFSIZ * 2];
307 (void) sprintf (buffer, fmt, a, b, c, d, e, f);
309 rc -> rc_len = strlen (rc -> rc_data = getcpy (buffer));
310 return (rc -> rc_type = RC_XXX);
322 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.9 1992/10/20 22:43:58 jromine Exp jromine $";
335 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.8 1992/10/20 15:36:28 jromine Exp jromine $";
347 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.7 1992/05/12 21:52:22 jromine Exp jromine $";
350 if ((rc -> rc_data = malloc ((unsigned) (rc -> rc_len + 1)) == NULL)
361 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.6 1992/05/12 21:51:35 jromine Exp jromine $";
364 if ((rc -> rc_data = malloc ((unsigned) rc -> rc_len + 1) == NULL)
375 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.5 1992/02/10 20:25:09 jromine Exp jromine $";
378 if ((rc -> rc_data = malloc (((unsigned) rc -> rc_len) + 1) == NULL)
379 return rclose (rc, "malloc of %d lost", rc -> rc_len);
390 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.4 1992/01/31 22:29:16 jromine Exp jromine $";
393 if ((rc -> rc_data = malloc ((unsigned) rc -> rc_len) + 1) == NULL)
404 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.3 1990/04/05 15:02:58 sources Exp jromine $";
407 if ((rc -> rc_data = malloc ((unsigned) rc -> rc_len)) == NULL)
418 static char ident[] = "@@(#)$Id:$";
421 if ((cp = getenv ("MHVDEBUG"))
423 && (fp = fopen (sprintf (buffer, "%s.out", invo_name), "w"))) {
424 (void) fseek (fp, 0L, 2);
425 fprintf (fp, "%d: rcinit (%d, %d)\n", getpid (), rfd, wfd);
429 rc -> rc_data[rc -> rc_len] = NULL;