summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMike Mason <ms13sp@gmail.com>2007-11-15 19:43:42 +0000
committerMike Mason <ms13sp@gmail.com>2007-11-15 19:43:42 +0000
commit46e0d09051fbe104d31d7cfe8a74537c71404a2a (patch)
treee2cd161097f1719f7c2131fb3a582f632a09c926 /lib
parent95cb7d3fe2bb50735757d9b69119d1c19bcec791 (diff)
downloadacf-core-46e0d09051fbe104d31d7cfe8a74537c71404a2a.tar.bz2
acf-core-46e0d09051fbe104d31d7cfe8a74537c71404a2a.tar.xz
adding more functions to fs. May need to go into a file.lua
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@307 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib')
-rw-r--r--lib/fs.lua40
1 files changed, 37 insertions, 3 deletions
diff --git a/lib/fs.lua b/lib/fs.lua
index 45901be..c27f613 100644
--- a/lib/fs.lua
+++ b/lib/fs.lua
@@ -51,10 +51,30 @@ function read_file_as_array ( path )
return f
end
+-- find all return characters and removes them, may get this from a browser
+-- that is why didn't do file specific
+
+function dostounix ( a )
+local data = string.gsub(a, "\r", "")
+return data
+
+end
+
+-- read a file without blank lines and commented lines
+
+function remove_blanks_comments ( path )
+local f = io.open(path)
+local lines = {}
+for line in f:lines() do
+local c = string.match(line, "^$") or string.match(line, "^%#")
+if c == nil then lines[#lines + 1] = line end
+end
+-- returns a table to iterate over without the blank or commented lines
+return lines
+end
-
-
--- write a string to a file
+-- write a string to a file !! MM-will replace file contents
+
function write_file ( path, str )
local file = io.open(path, "w")
if ( file ) then
@@ -63,6 +83,20 @@ function write_file ( path, str )
end
end
+-- this could do more than a line
+-- fs.write_line_file ("filename", "Line1 \nLines2 \nLines3")
+
+function write_line_file ( path, str )
+ local file = io.open(path)
+ if ( file) then
+ local c = file:read("*a")
+ file:close()
+ local d = (c .. "\n" .. str .. "\n")
+ -- include a friendly newline for EOF
+ fs.write_file(path,d)
+ end
+end
+
-- iterator function for finding dir entries matching filespec (what)
-- starting at where, or currentdir if not specified.