 
 
 (defn parse-ctool-run-output
-  [input file]
+  [input file & [delimiter]]
   (let [lines (clojure.string/split input #"\n")
         dir (condp = file :out "Out: " :err "Err: ")
         to-fun (fn [lines]

      (add-ctool-to-genv
        ret
        (:out bundle)
        (:err bundle)))))


(defn ctool-run-scripts

    (loop [lines lines
           idx (inc (.indexOf lines dir))
           to (to-fun lines)
           output nil
           continuation false]
      (if (= idx to)
        (let [sublines (drop (inc idx) lines)]
          (if (> (.indexOf sublines dir) -1)
            (recur sublines
                   (inc (.indexOf sublines dir))
                   (to-fun sublines)
                   (str output delimiter)
                   false)
            output))
        (let [ln (nth lines idx)]
          (recur lines
                 (inc idx)
                 to
                 (str output (if continuation
                               (str "\n" ln)
                               ln))
                 true))))))


(defn add-ctool-to-genv
  [ret & [out err delimiter]]
  (let [output (-> ret :stdout)]
    (when err
      (swap! genv
        #(assoc % (name err)
                (parse-ctool-run-output output :err delimiter))))
    (when out
      (swap! genv
        #(assoc % (name out)
                (parse-ctool-run-output output :out delimiter))))

    @(:exit-code ret)))

