Debian Codegraph @

src/chkJson

raw
1 -- -*- lua -*-
2 local sys_lua_path = "@sys_lua_path@"
3 if (sys_lua_path:sub(1,1) == "@") then
4 sys_lua_path = package.path
5 end
6
7 local sys_lua_cpath = "@sys_lua_cpath@"
8 if (sys_lua_cpath:sub(1,1) == "@") then
9 sys_lua_cpath = package.cpath
10 end
11
12 package.path = sys_lua_path
13 package.cpath = sys_lua_cpath
14
15 local arg_0 = arg[0]
16 _G._DEBUG = false
17 local posix = require("posix")
18 local readlink = posix.readlink
19 local stat = posix.stat
20
21 local st = stat(arg_0)
22 while (st.type == "link") do
23 local lnk = readlink(arg_0)
24 if (arg_0:find("/") and (lnk:find("^/") == nil)) then
25 local dir = arg_0:gsub("/[^/]*$","")
26 lnk = dir .. "/" .. lnk
27 end
28 arg_0 = lnk
29 st = stat(arg_0)
30 end
31
32 local ia,ja = arg_0:find(".*/")
33 local LuaCommandName = false
34 local LuaCommandName_dir = "./"
35 if (ia) then
36 LuaCommandName_dir = arg_0:sub(1,ja)
37 LuaCommandName = arg_0:sub(ja+1)
38 end
39
40 package.path = LuaCommandName_dir .. "?.lua;" ..
41 LuaCommandName_dir .. "../tools/?.lua;" ..
42 LuaCommandName_dir .. "../tools/?/init.lua;" ..
43 LuaCommandName_dir .. "../shells/?.lua;" ..
44 LuaCommandName_dir .. "?/init.lua;" ..
45 sys_lua_path
46 package.cpath = LuaCommandName_dir .. "../lib/?.so;"..
47 sys_lua_cpath
48
49 require("strict")
50 require("serializeTbl")
51 if ( _VERSION ~= "Lua 5.1" ) then
52 require("declare")
53 declare("loadstring")
54 loadstring = load
55 end
56 local Dbg = require("Dbg")
57 local json = require("json")
58
59 function main()
60
61 local configT = {
62 lmodV = { rule = "have"},
63 lfsV = { rule = "have"},
64 lua_term_A = { rule = "have"},
65 luaV = { rule = "have"},
66 mpath_init = { rule = "have"},
67 modRC = { rule = "have"},
68 siteName = { rule = "have"},
69 sysName = { rule = "have"},
70 syshost = { rule = "have"},
71 uname = { rule = "have"},
72 z01_admin = { rule = "have"},
73 prefix_site = { rule = "have"},
74 path_hash = { rule = "have"},
75 allowTCL = { rule = "match", value = "yes"},
76 autoSwap = { rule = "match", value = "yes"},
77 case = { rule = "match", value = "no"},
78 colorize = { rule = "match", value = "yes"},
79 disable1N = { rule = "match", value = "no"},
80 dot_files = { rule = "match", value = "yes"},
81 dupPaths = { rule = "match", value = "no"},
82 exactMatch = { rule = "match", value = "no"},
83 expMCmd = { rule = "match", value = "yes"},
84 hiddenItalic = { rule = "match", value = "no"},
85 lang = { rule = "match", value = "en"},
86 lang_site = { rule = "match", value = "<empty>"},
87 ld_lib_path = { rule = "match", value = "<empty>"},
88 ld_preload = { rule = "match", value = "<empty>"},
89 lua_cpath = { rule = "match", value = "@sys_lua_cpath@"},
90 lua_path = { rule = "match", value = "@sys_lua_path@"},
91 lua_term = { rule = "match", value = "no"},
92 mpath_av = { rule = "match", value = "no"},
93 mpath_root = { rule = "match", value = ""},
94 numSC = { rule = "match", value = 0},
95 pager = { rule = "match", value = "less"},
96 pager_opts = { rule = "match", value = "-XqMREF"},
97 path_lua = { rule = "match", value = "lua"},
98 pin_v = { rule = "match", value = "no"},
99 pkg = { rule = "match", value = "Pkg"},
100 prefix = { rule = "match", value = "@PREFIX@"},
101 prpnd_blk = { rule = "match", value = "normal"},
102 redirect = { rule = "match", value = "no"},
103 settarg = { rule = "match", value = "no"},
104 shell = { rule = "match", value = "bash"},
105 sitePkg = { rule = "match", value = "standard"},
106 spdr_ignore = { rule = "match", value = "no"},
107 spdr_loads = { rule = "match", value = "no"},
108 tm_ancient = { rule = "match", value = 86400},
109 tm_short = { rule = "match", value = 2},
110 tm_threshold = { rule = "match", value = 1},
111 tmod_rule = { rule = "match", value = "no"},
112 tmod_find1st = { rule = "match", value = "no"},
113 tracing = { rule = "match", value = "no"},
114 }
115
116 local s = io.read()
117 local t = json.decode(s)
118
119 local match = true
120 for k, v in pairs(configT) do
121 local testV = t.configT[k]
122 if (testV == nil) then
123 io.stderr:write("Json is missing key: ",k,"\n")
124 match = false
125 elseif (v.rule == "match" and testV ~= v.value) then
126 io.stderr:write("Json key: ",k," has the wrong value: testV: ",testV,", v.value: ",v.value,"\n")
127 match = false
128 end
129 end
130
131 if (match) then
132 io.stderr:write("configT matches\n")
133 end
134
135 if (type(t.rcfileA) == "table") then
136 io.stderr:write("rcfileA is a table\n")
137 if (#t.rcfileA == 2) then
138 io.stderr:write("rcfileA has two entries\n")
139 end
140 else
141 io.stderr:write("rcfileA is not a table\n")
142 end
143
144
145 if (type(t.propT) == "table") then
146 io.stderr:write("propT is a table\n")
147 else
148 io.stderr:write("propT is not a table\n")
149 end
150 end
151
152
153 main()