;;AUTOLOAD: doline
;;AUTODOC: doline "scans all lines in a file one by one"
;; (doline (variable stream) forms...)
;;
;; Doline is a convenience macro that will read the whole stream, line per
;; line and execute forms on each one with the variable set to the line. 
;; () is returned at the end
;; stream can be:
;;    a stream
;;    () or omitted:    *standard-input* is used
;;    a string:         the systems opens the file named by the string and uses
;;                      it as input
;; The form (doline () forms...) is also accepted, in which case variable is
;; set to the symbol `line'
;;
;; EXAMPLE:
;;    (catch 'header-read
;;        (doline (line "/etc/passwd") (if (= "" line) (throw 'header-read)))
;;
;; SEE ALSO: doscan

(defmacrod doline (varlist &rest forms &aux stream var)
  (if (not (and
	(typep varlist List)
	(< (length varlist) 3)
	(or (not varlist) (typep (0 varlist) Symbol))
    ))
    (error 'Errors:BadDoSyntax)
  )
  (setq stream (1 varlist))
  (setq var (0 varlist))
  (if (not var) (setq var 'line))
  (if (not stream) (setq stream *standard-input*)
    (and (typep stream String) (not (typep stream Symbol)))
    (setq stream (open stream))
  )
  
  `(with (,var ())
    (catch 'EOF
      (while t (setq ,var (read-line ,stream))
	,@forms
    ))
    ())
)
