xref: /original-bsd/lib/libplot/hp2648/subr.c (revision bafc759a)
1 /*-
2  * Copyright (c) 1980 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)subr.c	5.2 (Berkeley) 04/22/91";
10 #endif /* not lint */
11 
12 #include <sgtty.h>
13 #include "hp2648.h"
14 
15 handshake()
16 {
17 	int i;
18 	char ch;
19 
20 	if( shakehands != TRUE )
21 		return;
22 	ch = ' ';
23 	putchar(ENQ);
24 	fflush(stdout);
25 	while(1){
26 		i = read(fildes, &ch, 1);
27 		if(i < 0)
28 			continue;
29 		if(ch == ACK)
30 			break;
31 		putchar('Z');
32 		fflush(stdout);
33 		stty(fildes, &sarg);
34 		exit(0);
35 	}
36 }
37 
38 buffready(n)
39 int n;
40 {
41 	buffcount = buffcount + n;
42 	if(buffcount >= 80){
43 		handshake();
44 		putchar(ESC);
45 		putchar(GRAPHIC);
46 		putchar(PLOT);
47 		putchar(BINARY);
48 		buffcount = n+4;
49 	}
50 }
51 
52 itoa(num,byte1,byte2)
53 int num;
54 char *byte1,*byte2;
55 {
56 	*byte1 = (num & 037) | 040;
57 	*byte2 = ((num>>5) & 037) | 040;
58 }
59