1: /* $Header: iolin.c,v 1.1 85/03/14 15:38:25 nicklin Exp $ */
2:
3: /*
4: * Author: Peter J. Nicklin
5: */
6: #include <stdio.h>
7: #include "yesno.h"
8:
9: char IOBUF[BUFSIZ]; /* I/O line buffer */
10: short CONTINUE; /* does the line continue? */
11:
12: /*
13: * getlin() stores a line from input stream in IOBUF. The string is terminated
14: * by a newline character which is replaced by a null character. getlin()
15: * returns IOBUF, or null pointer upon end of file.
16: */
17: char *
18: getlin(stream)
19: register FILE *stream; /* input stream */
20: {
21: register int c; /* current character */
22: register char *iop; /* IOBUF pointer */
23:
24: iop = IOBUF;
25: while ((c = getc(stream)) != '\n' && c != EOF)
26: *iop++ = c;
27: if (c == EOF && iop == IOBUF)
28: return(NULL);
29: if (iop != IOBUF && iop[-1] == '\\')
30: {
31: iop[-1] = '\0';
32: CONTINUE = YES;
33: }
34: else {
35: iop[0] = '\0';
36: CONTINUE = NO;
37: }
38: return(IOBUF);
39: }
40:
41:
42:
43: /*
44: * purgcontinue() eats up continuation lines from an input stream.
45: */
46: void
47: purgcontinue(stream)
48: register FILE *stream; /* input stream */
49: {
50: register int c; /* current character */
51: register int lastc; /* previous character */
52:
53: if (CONTINUE == YES)
54: {
55: for (;;)
56: {
57: while ((c = getc(stream)) != '\n' && c != EOF)
58: lastc = c;
59: if (c == EOF || (c == '\n' && lastc != '\\'))
60: break;
61: }
62: CONTINUE = NO;
63: }
64: }
65:
66:
67:
68: /*
69: * putlin() writes IOBUF to stream and appends a newline character. If
70: * IOBUF holds a CONTINUE line, a `\' precedes the newline.
71: */
72: void
73: putlin(stream)
74: register FILE *stream; /* output stream */
75: {
76: register int c; /* current character */
77: register char *iop; /* IOBUF pointer */
78:
79: iop = IOBUF;
80: while (c = *iop++)
81: putc(c, stream);
82: if (CONTINUE == YES)
83: putc('\\', stream);
84: putc('\n', stream);
85: }
Defined functions
Defined variables
IOBUF
defined in line
9; used 10 times