Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / uip / RCS / vmhsbr.c,v
1 head    1.11;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.11
9 date    93.08.25.17.29.53;      author jromine; state Exp;
10 branches;
11 next    1.10;
12
13 1.10
14 date    92.12.15.00.20.22;      author jromine; state Exp;
15 branches;
16 next    1.9;
17
18 1.9
19 date    92.10.20.22.43.58;      author jromine; state Exp;
20 branches;
21 next    1.8;
22
23 1.8
24 date    92.10.20.15.36.28;      author jromine; state Exp;
25 branches;
26 next    1.7;
27
28 1.7
29 date    92.05.12.21.52.22;      author jromine; state Exp;
30 branches;
31 next    1.6;
32
33 1.6
34 date    92.05.12.21.51.35;      author jromine; state Exp;
35 branches;
36 next    1.5;
37
38 1.5
39 date    92.02.10.20.25.09;      author jromine; state Exp;
40 branches;
41 next    1.4;
42
43 1.4
44 date    92.01.31.22.29.16;      author jromine; state Exp;
45 branches;
46 next    1.3;
47
48 1.3
49 date    90.04.05.15.02.58;      author sources; state Exp;
50 branches;
51 next    1.2;
52
53 1.2
54 date    90.02.06.13.34.37;      author sources; state Exp;
55 branches;
56 next    1.1;
57
58 1.1
59 date    90.02.06.13.33.43;      author sources; state Exp;
60 branches;
61 next    ;
62
63
64 desc
65 @@
66
67
68 1.11
69 log
70 @off_t fixes for BSD44
71 @
72 text
73 @/* vmhsbr.c - routines to help vmh along */
74 #ifndef lint
75 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.10 1992/12/15 00:20:22 jromine Exp jromine $";
76 #endif  /* lint */
77
78 /* TODO (for vrsn 2):
79         INI: include width of windows
80  */
81
82 #include "../h/mh.h"
83 #include "../h/vmhsbr.h"
84 #include <stdio.h>
85
86 /* \f */
87
88 static char *types[] = {
89     "OK",
90     "INI", "ACK", "ERR", "CMD", "QRY", "TTY", "WIN", "DATA", "EOF", "FIN",
91     "XXX", NULL
92 };
93
94 static  FILE *fp = NULL;
95
96 static  int PEERrfd = NOTOK;
97 static  int PEERwfd = NOTOK;
98
99
100 extern int  errno;
101 #ifndef BSD44
102 extern int  sys_nerr;
103 extern char *sys_errlist[];
104 #endif
105
106 static int      rclose();
107 /* \f */
108
109 int     rcinit (rfd, wfd)
110 int     rfd,
111         wfd;
112 {
113     char   *cp,
114             buffer[BUFSIZ];
115
116     PEERrfd = rfd;
117     PEERwfd = wfd;
118
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);
124           (void) fflush (fp);
125         }
126     }
127
128     return OK;
129 }
130
131
132 int     rcdone () {
133     if (PEERrfd != NOTOK)
134         (void) close (PEERrfd);
135     if (PEERwfd != NOTOK)
136         (void) close (PEERwfd);
137
138     if (fp) {
139         (void) fclose (fp);
140         fp = NULL;
141     }
142     return OK;
143 }
144
145 /* \f */
146
147 int     rc2rc (code, len, data, rc)
148 char    code;
149 int     len;
150 char   *data;
151 struct record *rc;
152 {
153     if (rc2peer (code, len, data) == NOTOK)
154         return NOTOK;
155
156     return peer2rc (rc);
157 }
158
159
160 int     str2rc (code, str, rc)
161 char    code;
162 char   *str;
163 struct record *rc;
164 {
165     return rc2rc (code, str ? strlen (str) : 0, str, rc);
166 }
167
168 /* \f */
169
170 int     peer2rc (rc)
171 register struct record *rc;
172 {
173     if (rc -> rc_data)
174         free (rc -> rc_data);
175
176     if (read (PEERrfd, (char *) rc_head (rc), RHSIZE (rc)) != RHSIZE (rc))
177         return rclose (rc, "read from peer lost(1)");
178     if (rc -> rc_len) {
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;
184     }
185     else
186         rc -> rc_data = NULL;
187
188     if (fp) {
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);
193         (void) fflush (fp);
194     }
195
196     return rc -> rc_type;
197 }
198
199 /* \f */
200
201 int     rc2peer (code, len, data)
202 char    code;
203 int     len;
204 char   *data;
205 {
206     struct record   rcs;
207     register struct record *rc = &rcs;
208
209     rc -> rc_type = code;
210     rc -> rc_len = len;
211
212     if (fp) {
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);
217         (void) fflush (fp);
218     }
219
220     if (write (PEERwfd, (char *) rc_head (rc), RHSIZE (rc)) != RHSIZE (rc))
221         return rclose (rc, "write to peer lost(1)");
222
223     if (rc -> rc_len)
224         if (write (PEERwfd, data, rc -> rc_len) != rc -> rc_len)
225             return rclose (rc, "write to peer lost(2)");
226
227     return OK;
228 }
229
230 /* \f */
231
232 int     str2peer (code, str)
233 char    code;
234 char   *str;
235 {
236     return rc2peer (code, str ? strlen (str) : 0, str);
237 }
238
239
240 /* VARARGS2 */
241
242 int     fmt2peer (code, fmt, a, b, c, d, e, f)
243 char    code;
244 char   *fmt,
245        *a,
246        *b,
247        *c,
248        *d,
249        *e,
250        *f;
251 {
252     return err2peer (code, NULLCP, fmt, a, b, c, d, e, f);
253 }
254
255 /* \f */
256
257 /* VARARGS3 */
258
259 int     err2peer (code, what, fmt, a, b, c, d, e, f)
260 char    code;
261 char   *what,
262        *fmt,
263        *a,
264        *b,
265        *c,
266        *d,
267        *e,
268        *f;
269 {
270     int     eindex = errno;
271     register char  *bp;
272     char    buffer[BUFSIZ * 2];
273
274     (void) sprintf (buffer, fmt, a, b, c, d, e, f);
275     bp = buffer + strlen (buffer);
276     if (what) {
277         if (*what) {
278             (void) sprintf (bp, " %s: ", what);
279             bp += strlen (bp);
280         }
281         if (eindex > 0 && eindex < sys_nerr)
282             (void) strcpy (bp, sys_errlist[eindex]);
283         else
284             (void) sprintf (bp, "Error %d", eindex);
285         bp += strlen (bp);
286     }
287
288     return rc2peer (code, bp - buffer, buffer);
289 }
290
291 /* \f */
292
293 /* VARARGS2 */
294
295 static  int     rclose (rc, fmt, a, b, c, d, e, f)
296 register struct record *rc;
297 char   *fmt,
298        *a,
299        *b,
300        *c,
301        *d,
302        *e,
303        *f;
304 {
305     static char buffer[BUFSIZ * 2];
306
307     (void) sprintf (buffer, fmt, a, b, c, d, e, f);
308
309     rc -> rc_len = strlen (rc -> rc_data = getcpy (buffer));
310     return (rc -> rc_type = RC_XXX);
311 }
312 @
313
314
315 1.10
316 log
317 @endif sugar
318 @
319 text
320 @d3 1
321 a3 1
322 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.9 1992/10/20 22:43:58 jromine Exp jromine $";
323 d29 1
324 d32 1
325 @
326
327
328 1.9
329 log
330 @typo in malloc call
331 @
332 text
333 @d3 2
334 a4 2
335 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.8 1992/10/20 15:36:28 jromine Exp jromine $";
336 #endif  lint
337 @
338
339
340 1.8
341 log
342 @typo
343 @
344 text
345 @d3 1
346 a3 1
347 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.7 1992/05/12 21:52:22 jromine Exp jromine $";
348 d105 1
349 a105 1
350         if ((rc -> rc_data = malloc ((unsigned) (rc -> rc_len + 1)) == NULL)
351 @
352
353
354 1.7
355 log
356 @typo
357 @
358 text
359 @d3 1
360 a3 1
361 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.6 1992/05/12 21:51:35 jromine Exp jromine $";
362 d105 1
363 a105 1
364         if ((rc -> rc_data = malloc ((unsigned) rc -> rc_len + 1) == NULL)
365 @
366
367
368 1.6
369 log
370 @typo in malloc call
371 @
372 text
373 @d3 1
374 a3 1
375 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.5 1992/02/10 20:25:09 jromine Exp jromine $";
376 d105 2
377 a106 2
378         if ((rc -> rc_data = malloc (((unsigned) rc -> rc_len) + 1) == NULL)
379             return rclose (rc, "malloc of %d lost", rc -> rc_len);
380 @
381
382
383 1.5
384 log
385 @minor fix
386 @
387 text
388 @d3 1
389 a3 1
390 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.4 1992/01/31 22:29:16 jromine Exp jromine $";
391 d105 1
392 a105 1
393         if ((rc -> rc_data = malloc ((unsigned) rc -> rc_len) + 1) == NULL)
394 @
395
396
397 1.4
398 log
399 @kerberos
400 @
401 text
402 @d3 1
403 a3 1
404 static char ident[] = "@@(#)$Id: vmhsbr.c,v 1.3 1990/04/05 15:02:58 sources Exp jromine $";
405 d105 1
406 a105 1
407         if ((rc -> rc_data = malloc ((unsigned) rc -> rc_len)) == NULL)
408 @
409
410
411 1.3
412 log
413 @add ID
414 @
415 text
416 @d3 1
417 a3 1
418 static char ident[] = "@@(#)$Id:$";
419 d45 7
420 a51 6
421     if ((cp = getenv ("MHVDEBUG"))
422             && *cp
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);
426         (void) fflush (fp);
427 d109 1
428 a109 1
429         rc -> rc_data[rc -> rc_len] = NULL;
430 @
431
432
433 1.2
434 log
435 @ANSI Compilance
436 @
437 text
438 @d2 3
439 @
440
441
442 1.1
443 log
444 @Initial revision
445 @
446 text
447 @d29 1
448 @