home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / BIPL.ZIP / PROCS.ZIP / READLINE.ICN < prev    next >
Encoding:
Text File  |  1992-09-28  |  1.6 KB  |  63 lines

  1. ############################################################################
  2. #
  3. #    File:     readline.icn
  4. #
  5. #    Subject:  Procedures to read and write lines in pieces
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     February 27, 1992
  10. #
  11. ###########################################################################
  12. #
  13. #  readline(file) assembles backslash-continued lines from the specified
  14. #  file into a single line.  If the last line in a file ends in a backslash,
  15. #  that character is included in the last line read.
  16. #
  17. #  splitline(file, line, limit) splits line into pieces at first blank after
  18. #  the limit, appending a backslash to identify split lines (if a line ends in
  19. #  a backslash already, that's too bad). The pieces are written to the
  20. #  specified file.
  21. #
  22. ############################################################################
  23.  
  24. procedure splitline(file,line,limit)
  25.    local i, j
  26.  
  27.    if *line = 0 then {            # don't fail to write empty line
  28.       write(file,line)
  29.       return
  30.       }
  31.    while *line > limit do {
  32.       line ?:= {
  33.          i := j := 0
  34.          every i := find(" ") do {    # find a point to split
  35.             if i >= limit then break
  36.             else j := i
  37.             }
  38.          if j = 0 then {        # can't split
  39.             write(file,line)
  40.             return
  41.             }
  42.          write(file,tab(j + 1),"\\")
  43.          tab(0)                # update line
  44.          }
  45.       }
  46.    if *line > 0 then write(file,line)    # the rest
  47.  
  48.    return
  49.  
  50. end
  51.  
  52. procedure readline(file)
  53.    local line
  54.  
  55.    line := read(file) | fail
  56.  
  57.    while line[-1] == "\\" do
  58.       line := line[1:-1] || read(file) | break
  59.  
  60.    return line
  61.  
  62. end
  63.