1 #include <stdio.h>
2 #include "sqcom.h"
3 #include "sq.h"
4 #define ERROR -1
5 
6 #ifdef TOPS20
7 static int incnt = 0;
8 #endif
9 
10 /* Get next byte from file and update checksum */
11 
12 int
getc_crc(ib)13 getc_crc(ib)
14 FILE *ib;
15 {
16 	int c;
17 
18 #ifdef TOPS20
19 	if ((c = fgetc(ib)) == EOF) {
20 	    if (incnt & 0x7F) {
21 		c = (bytsiz != 7) ? 0 : 0x1A;
22 	    } else {
23 		return (c = EOF);
24 	    }
25 	}
26 	++incnt;
27 	c &= 0xFF;
28 	crc += c;
29 	crc &= 0xFFFF;
30 	return (c);
31 #else
32 	c = getc(ib);
33 	if (c != EOF)
34 		crc += c;		/* checksum */
35 	return (c);
36 #endif
37 }
38 
39 /* Output functions with error reporting */
40 
41 static char obuf[128];
42 static int oblen = 0;
43 
putce(c,iob)44 putce(c,  iob)
45 int c;
46 FILE *iob;
47 {
48 /*	obuf[oblen++] = c;	*/
49 	obuf[oblen++] = (c & 0xff);	/*rev 3.3*/
50 	if (oblen >= sizeof(obuf)) oflush(iob);
51 }
52 
putwe(w,iob)53 putwe(w,  iob)
54 int w;
55 FILE *iob;
56 {
57 /*	obuf[oblen++] = w;	*/
58 	obuf[oblen++] = (w & 0xff);	/*rev 3.3*/
59 	if (oblen >= sizeof(obuf)) oflush(iob);
60 /*	obuf[oblen++] = w >> 8;	*/
61 	obuf[oblen++] = (w >> 8) & 0xff;/*rev 3.3*/
62 	if (oblen >= sizeof(obuf)) oflush(iob);
63 }
64 
oflush(iob)65 oflush(iob)				/* flush output buffer */
66 FILE *iob;
67 {
68 	if (oblen && !fwrite(obuf, oblen, 1, iob)) {
69 		printf("Error writing output file\n");
70 		exit(1);
71 	}
72 	oblen = 0;
73 #ifdef COMMENT
74 	int i;
75 
76 	if (oblen)
77 		for (i = 0; i < sizeof(obuf); ++i)
78 			fputc (obuf[i], iob);
79 	oblen = 0;
80 	fflush(iob);
81 #endif
82 }
83