summaryrefslogtreecommitdiffstats
path: root/lib/parser.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-09-19 18:26:06 +0000
committerTed Trask <ttrask01@yahoo.com>2008-09-19 18:26:06 +0000
commit1259e8e34d5a182c9c57e3ce82508603d3761505 (patch)
treea079e1d9bb93d595015242752acd8cfa9c62cf17 /lib/parser.lua
parentb167d7758dbcc813730800def07dedbc1198902e (diff)
downloadacf-core-1259e8e34d5a182c9c57e3ce82508603d3761505.tar.bz2
acf-core-1259e8e34d5a182c9c57e3ce82508603d3761505.tar.xz
Modified format library to operate on strings rather than files - makes it more flexible. Removed dependencies and unnecessary _to_string functions - use table.concat instead. Changed remove_blanks_comments to parse_lines. Added parse_linesandwords, replace_line, insert_line, and get_line functions from parser.lua and removed parser.lua. Made slight changes to squid and devtools to reflect library changes.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1479 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib/parser.lua')
-rw-r--r--lib/parser.lua79
1 files changed, 0 insertions, 79 deletions
diff --git a/lib/parser.lua b/lib/parser.lua
deleted file mode 100644
index 7c6af67..0000000
--- a/lib/parser.lua
+++ /dev/null
@@ -1,79 +0,0 @@
-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