From ca6d92ece51042024ae99e3e52cfb89801db97b0 Mon Sep 17 00:00:00 2001
From: Camil Staps
Date: Tue, 18 Oct 2016 23:52:49 +0200
Subject: Template file

---
 iclean.icl | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

(limited to 'iclean.icl')

diff --git a/iclean.icl b/iclean.icl
index 6b64d98..7683619 100644
--- a/iclean.icl
+++ b/iclean.icl
@@ -36,6 +36,7 @@ temp_path :== "/tmp/"
 temp_module :== "iclean"
 readline_history :== "/home/.iclean_history"
 template :== map ((+++) "import ") ["StdEnv", "StdDynamic", "genLibTest"]
+template_file :== "/home/.iclean_template"
 // END SETTINGS
 
 temp_file :== temp_path +++ temp_module +++ ".icl"
@@ -54,7 +55,8 @@ Start w
 # w = setReadLineName "iClean" w
 # w = usingHistory w
 # w = checkedWorldFunc readHistory "Couldn't read history" readline_history w
-# w = loop template True w
+# (more_template,w) = readTemplate template_file w
+# w = loop (template ++ more_template) True w
 # w = checkedWorldFunc writeHistory "Couldn't write history" readline_history w
 = w
 where
@@ -83,6 +85,22 @@ where
 	undef :: !String !String -> Bool
 	undef n h = not (matches (n +++ " ") h)
 
+	readTemplate :: !String !*World -> *([String], *World)
+	readTemplate f w
+	# (ok,f,w)  = fopen f FReadText w
+	| not ok    = ([], w)
+	# (lines,f) = readLines f
+	# (ok,w)    = fclose f w
+	= (lines, w)
+	where
+		readLines :: !*File -> *([String], *File)
+		readLines f
+		# (end,f)   = fend f
+		| end       = ([], f)
+		# (line,f)  = freadline f
+		# (lines,f) = readLines f
+		= ([line % (0,size line - 2):lines], f)
+
 // iClean functions
 checkedWorldFunc :: (a *World -> (Bool, *World)) !String !a !*World -> *World
 checkedWorldFunc f err s w
-- 
cgit v1.2.3