home *** CD-ROM | disk | FTP | other *** search
- ############################################################################
- #
- # File: readline.icn
- #
- # Subject: Procedures to read and write lines in pieces
- #
- # Author: Ralph E. Griswold
- #
- # Date: February 27, 1992
- #
- ###########################################################################
- #
- # readline(file) assembles backslash-continued lines from the specified
- # file into a single line. If the last line in a file ends in a backslash,
- # that character is included in the last line read.
- #
- # splitline(file, line, limit) splits line into pieces at first blank after
- # the limit, appending a backslash to identify split lines (if a line ends in
- # a backslash already, that's too bad). The pieces are written to the
- # specified file.
- #
- ############################################################################
-
- procedure splitline(file,line,limit)
- local i, j
-
- if *line = 0 then { # don't fail to write empty line
- write(file,line)
- return
- }
- while *line > limit do {
- line ?:= {
- i := j := 0
- every i := find(" ") do { # find a point to split
- if i >= limit then break
- else j := i
- }
- if j = 0 then { # can't split
- write(file,line)
- return
- }
- write(file,tab(j + 1),"\\")
- tab(0) # update line
- }
- }
- if *line > 0 then write(file,line) # the rest
-
- return
-
- end
-
- procedure readline(file)
- local line
-
- line := read(file) | fail
-
- while line[-1] == "\\" do
- line := line[1:-1] || read(file) | break
-
- return line
-
- end
-