aboutsummaryrefslogtreecommitdiff
path: root/src/nameidmapping.cpp
diff options
context:
space:
mode:
authorDavid Leal <halfpacho@gmail.com>2020-04-26 14:15:05 -0500
committerGitHub <noreply@github.com>2020-04-26 21:15:05 +0200
commit2fe4641c1e00d72c1f651b83898b093a9454d43c (patch)
tree4c816a615829323216a6e92853a8f66e93db06db /src/nameidmapping.cpp
parent68f45fc130341e1b3e7d3207658947324db87d3c (diff)
downloadminetest-2fe4641c1e00d72c1f651b83898b093a9454d43c.tar.gz
minetest-2fe4641c1e00d72c1f651b83898b093a9454d43c.tar.bz2
minetest-2fe4641c1e00d72c1f651b83898b093a9454d43c.zip
Add new command /revokeme <priv> (#9584)
Diffstat (limited to 'src/nameidmapping.cpp')
0 files changed, 0 insertions, 0 deletions
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
local unescape_string
do
	local schartbl = { -- https://en.wikipedia.org/wiki/Escape_sequences_in_C
		a = "\a",
		b = "\b",
		e = string.char(0x1b),
		f = "\f",
		n = "\n",
		r = "\r",
		t = "\t",
		v = "\v",
	}
	local function replace_single(pfx, c)
		local pl = #pfx
		if pl % 2 == 0 then
			return string.sub(pfx, 1, pl/2) .. c
		end
		return string.sub(pfx, 1, math.floor(pl/2)) .. (schartbl[c] or c)
	end
	unescape_string = function(str)
		return string.gsub(str, [[(\+)([abefnrtv'"?])]], replace_single)
	end
end

local function readstring_aux(str, pos)
	local _, spos = string.find(str, [[^%s*"]], pos)
	if not spos then
		return nil
	end
	local ipos = spos
	while true do
		local _, epos, m = string.find(str, [[(\*)"]], ipos+1)
		if not epos then
			return error("String extends beyond the end of input")
		end
		ipos = epos
		if #m % 2 == 0 then
			return unescape_string(string.sub(str, spos+1, epos-1)), epos+1
		end
	end
end

local function readstring(str, pos)
	local st = {}
	local nxt = pos
	while true do
		local s, npos = readstring_aux(str, nxt)
		if not s then
			if not st[1] then
				return nil, nxt
			else
				return table.concat(st), nxt
			end
		end
		nxt = npos
		table.insert(st, s)
	end
end

local function readtoken(str, pos)
	local _, epos, tok = string.find(str, [[^%s*(%S+)]], pos)
	if epos == nil then
		return nil, pos
	end
	return tok, epos+1
end

local function readcomment_add_flags(flags, s)
	for flag in string.gmatch(s, ",%s*([^,]+)") do
		flags[flag] = true
	end
end

local function readcomment_aux(str, pos)
	local _, epos, sval = string.find(str, "^\n*#([^\n]*)", pos)
	if not epos then
		return nil
	end
	return sval, epos+1
end

local function readcomment(str, pos)
	local st = {}
	local nxt = pos
	local flags = {}
	while true do
		local s, npos = readcomment_aux(str, nxt)
		if not npos then
			local t = {
				comment = table.concat(st, "\n"),
				flags = flags,
			}
			return t, nxt
		end
		if string.sub(s, 1, 1) == "," then
			readcomment_add_flags(flags, s)
		end
		table.insert(st, s)
		nxt = npos
	end
end

local function readpo(str)
	local st = {}
	local pos = 1
	while true do
		local entry, nxt = readcomment(str, pos)
		local msglines = 0
		while true do
			local tok, npos = readtoken(str, nxt)
			if tok == nil or string.sub(tok, 1, 1) == "#" then
				break
			elseif string.sub(tok, 1, 3) ~= "msg" then
				return error("Invalid token: " .. tok)
			elseif entry[tok] ~= nil then
				break
			else
				local value, npos = readstring(str, npos)
				assert(value ~= nil, "No string provided for " .. tok)
				entry[tok] = value
				nxt = npos
				msglines = msglines+1
			end
		end
		if msglines == 0 then
			return st
		elseif entry.msgid ~= "" then
			assert(entry.msgid ~= nil, "Missing untranslated string")