diff options
-rw-r--r-- | db.lua | 17 | ||||
-rwxr-xr-x | fromdb.lua | 24 |
2 files changed, 41 insertions, 0 deletions
@@ -12,6 +12,7 @@ local pcall = pcall local io = require "io" local iostdout = io.stdout +local iostdin = io.stdin local common = require "common" local common_status = common.status @@ -22,10 +23,25 @@ local errorln = common.errorln local noiseln = common.noiseln local debugln = common.debugln +local json_internalize = function (jsdata) + local jsdec = cjson.new () + local parsed = jsdec.decode (jsdata) + if parsed == nil then return status_error end + return status_ok, parsed +end + ------------------------------------------------------------------------------- --- API ------------------------------------------------------------------------------- +local read_json_db = function (cal, fh) + fh = fh or iostdin + local jsdata = fh:read "*all" + fh:close () + if jsdata == nil then return status_error end + return json_internalize (jsdata) +end + local output_calendar = function (cal, fh) fh = fh or iostdout local jsenc = cjson.new () @@ -39,5 +55,6 @@ local output_calendar = function (cal, fh) end return { output_calendar = output_calendar + , read_json_db = read_json_db } diff --git a/fromdb.lua b/fromdb.lua new file mode 100755 index 0000000..cd17406 --- /dev/null +++ b/fromdb.lua @@ -0,0 +1,24 @@ +#!/usr/bin/env lua +local rem = require "rem" +local db = require "db" +local common = require "common" + +local status = common.status +local status_ok = status.codes.ok +local status_error = status.codes.error + +common.set_verbosity (1) + +local main = function (argv) + local st, parsed = db.read_json_db () + if st ~= status_ok then + return -1 + end + + local st = rem.output_calendar (parsed) + + return st == status_ok and 0 or -1 +end + +os.exit (main ()) + |