aboutsummaryrefslogtreecommitdiff
path: root/sys/fio/glongline.x
blob: 6350cb3eea1e8c8b648543d3b4ec0b99c49bd0ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

# GETLONGLINE -- Get a long line, i.e., a logical line possibly spanning
# several physical lines with the newlines escaped at the ends.  Skip
# comment lines and .help sections.  Blank lines are not skipped.
# Lines not terminated by newlines are joined to form a longer line.
# MAXCH must be at least SZ_LINE characters greater than the size of the
# longest line to be read.

int procedure getlongline (fd, obuf, maxch, linenum)

int	fd			#I input file
char	obuf[ARB]		#O output buffer
int	maxch			#I max chars out
int	linenum			#U line number counter

int	op, status
int	getline(), strncmp()
errchk	getline

begin
	op = 1

	while (maxch - op + 1 >= SZ_LINE) {
	    # Get next non-comment line.
	    repeat {
		status = getline (fd, obuf[op])
		if (status > 0 && obuf[op+status-1] == '\n')
		    linenum = linenum + 1

		if (status == EOF) {
		    break
		} else if (obuf[op] == '#') {
		    next
		} else if (obuf[op] == '.') {
		    # Skip help sections.
		    if (strncmp (obuf[op], ".help", 5) == 0) {
			repeat {
			    status = getline (fd, obuf[op])
			    linenum = linenum + 1
			    if (status == EOF)
				break
			    if (strncmp (obuf[op], ".endhelp", 8) == 0)
				break
			}
		    } else
			break
		} else
		    break
	    }

	    if (status == EOF) {
		if (op == 1)
		    return (EOF)
		else
		    return (op - 1)
	    } else
		op = op + status

	    # If the last physical line read ends in a newline we are done,
	    # unless the newline is escaped.  If there is no newline we get
	    # another line, thereby reconstructing long lines broken by the
	    # SZ_LINE limit of getline().

	    if (obuf[op-1] == '\n')
		if (obuf[op-2] == '\\')
		    op = op - 2
		else
		    break
	}

	return (op - 1)
end