summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/filedetails-html.lsp1
-rw-r--r--lib/Makefile1
-rw-r--r--lib/parser.lua79
3 files changed, 81 insertions, 0 deletions
diff --git a/app/filedetails-html.lsp b/app/filedetails-html.lsp
index 5b51500..4c1f116 100644
--- a/app/filedetails-html.lsp
+++ b/app/filedetails-html.lsp
@@ -25,6 +25,7 @@ displayitem(form.value.mtime)
<%= html.html_escape(form.value.filecontent.value) %>
</textarea>
<% if form.value.filecontent.errtxt then %><P CLASS='error'><%= string.gsub(form.value.filecontent.errtxt, "\n", "<BR>") %></P><% end %>
+<% if form.value.filecontent.descr then %><P CLASS='descr'><%= string.gsub(form.value.filecontent.descr, "\n", "<BR>") %></P><% end %>
<% if form.type == "form" then %>
<H3>Save</H3>
diff --git a/lib/Makefile b/lib/Makefile
index 23a1a31..eb5c0fd 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -24,6 +24,7 @@ LIB_DIST=fs.lua\
modelfunctions.lua\
cfe.lua\
apk.lua\
+ parser.lua\
EXTRA_DIST=README Makefile
DISTFILES=$(LIB_DIST) $(EXTRA_DIST)
diff --git a/lib/parser.lua b/lib/parser.lua
new file mode 100644
index 0000000..7c6af67
--- /dev/null
+++ b/lib/parser.lua
@@ -0,0 +1,79 @@
+module(..., package.seeall)
+
+function parseconfigfile(file)
+ file = file or ""
+ local retval = {commented={}}
+ local linenum=0
+ for line in string.gmatch(file, "([^\n]*)\n?") do
+ linenum=linenum+1
+ if not string.match(line, "^[%s#]*$") then
+ local linetable = {linenum=linenum, line=line}
+ if string.match(line, "^%s*#") then
+ table.insert(retval.commented, linetable)
+ line = string.match(line, "^%s*#(.*)")
+ else
+ table.insert(retval, linetable)
+ end
+ -- Iterate through each word, being careful about quoted strings and comments
+ local offset = 1
+ while string.find(line, "%S+", offset) do
+ local word = string.match(line, "%S+", offset)
+ local endword = select(2, string.find(line, "%S+", offset))
+ if string.find(word, "^#") then
+ break
+ elseif string.find(word, "^\"") then
+ endword = select(2, string.find(line, "\"[^\"]*\"", offset))
+ word = string.sub(line, string.find(line, "\"", offset), endword)
+ end
+ table.insert(linetable, word)
+ offset = endword + 1
+ end
+ end
+ end
+ return retval
+end
+
+-- Removes the linenum line from file and replaces it with line.
+-- Do nothing if doesn't exist
+function replaceline(file, linenum, line)
+ -- Split the file to remove the line
+ local startchar, endchar = string.match(file, "^" .. string.rep("[^\n]*\n", linenum-1) .. "()[^\n]*\n?()")
+ if startchar and endchar then
+ local lines = {}
+ lines[1] = string.sub(file, 1, startchar-1)
+ lines[2] = string.sub(file, endchar, -1)
+ if line then
+ table.insert(lines, 2, line .. "\n")
+ end
+ file = table.concat(lines)
+ end
+ return file
+end
+
+-- Inserts the line into the file after the linenum (or at the end)
+function insertline(file, linenum, line)
+ -- Split the file to remove the line
+ local startchar = string.match(file, "^" .. string.rep("[^\n]*\n", linenum) .. "()")
+ local lines = {}
+ if startchar then
+ lines[1] = string.sub(file, 1, startchar-1)
+ lines[2] = string.sub(file, startchar, -1)
+ else
+ lines[1] = file
+ end
+ if line then
+ table.insert(lines, 2, line .. "\n")
+ end
+ file = table.concat(lines)
+ return file
+end
+
+function getline(file, linenum)
+ -- Split the file to remove the line
+ local startchar, endchar = string.match(file, "^" .. string.rep("[^\n]*\n", linenum-1) .. "()[^\n]*()")
+ local line
+ if startchar and endchar then
+ line = string.sub(file, startchar, endchar-1)
+ end
+ return line
+end