From 46e0d09051fbe104d31d7cfe8a74537c71404a2a Mon Sep 17 00:00:00 2001 From: Mike Mason Date: Thu, 15 Nov 2007 19:43:42 +0000 Subject: 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 --- lib/fs.lua | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'lib/fs.lua') 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. -- cgit v1.2.3