more simple escaping

This commit is contained in:
p.kosyh@gmail.com 2010-11-04 08:20:40 +00:00
parent fd937ab799
commit b661d76355
4 changed files with 22 additions and 20 deletions

View file

@ -1584,7 +1584,9 @@ int game_cmd(char *cmd)
instead_clear(); instead_clear();
if (waystr) { if (waystr) {
waystr[strcspn(waystr,"\n")] = 0; int l = strlen(waystr);
if (l && waystr[l - 1] == '\n')
waystr[l - 1] = 0;
} }
if (game_theme.gfx_mode != GFX_MODE_EMBEDDED) { if (game_theme.gfx_mode != GFX_MODE_EMBEDDED) {

View file

@ -4,7 +4,7 @@ game.showlast = true;
game.gui = { game.gui = {
fading = 4; fading = 4;
ways_delim = ' | '; ways_delim = ' | ';
inv_delim = '^'; inv_delim = '\n';
hinv_delim = ' | '; hinv_delim = ' | ';
} }
@ -62,7 +62,7 @@ end;
iface.nb = function(self, str) iface.nb = function(self, str)
if type(str) ~= 'string' then return nil end if type(str) ~= 'string' then return nil end
return "<w:"..str:gsub("\\","\\\\\\\\"):gsub(">","\\\\>"):gsub("%^","\\%^")..">"; return "<w:"..str:gsub(">","\\>"):gsub("%^","\\%^")..">";
end; end;
iface.under = function(self, str) iface.under = function(self, str)
@ -136,30 +136,27 @@ iface.ways = function(self, str)
end; end;
function get_inv(horiz) function get_inv(horiz)
RAW_TEXT = true
local str = iface:cmd("inv"); local str = iface:cmd("inv");
if str then if str then
str = stead.string.gsub(str, '\n$',''); str = stead.string.gsub(str, '\n$','');
if not horiz then if not horiz then
str = stead.string.gsub(str, '\\?[\\'.. stead.delim ..']', { [stead.delim] = game.gui.inv_delim }); str = stead.string.gsub(str, '\\?['.. stead.delim ..']',
{ [stead.delim] = game.gui.inv_delim, ['\\'..stead.delim] = stead.delim });
else else
str = stead.string.gsub(str, '\\?[\\'.. stead.delim ..']', { [stead.delim] = game.gui.hinv_delim }); str = stead.string.gsub(str, '\\?['.. stead.delim ..']',
{ [stead.delim] = game.gui.hinv_delim, ['\\'..stead.delim] = stead.delim });
end end
stead.state = false
str = stead.fmt(str);
end end
return str return str
end end
instead.get_inv = get_inv; instead.get_inv = get_inv;
function get_ways() function get_ways()
RAW_TEXT = true
local str = iface:cmd("way"); local str = iface:cmd("way");
if str and str ~= '' then if str and str ~= '' then
str = stead.string.gsub(str, '\n$',''); str = stead.string.gsub(str, '\n$','');
str = stead.string.gsub(str, '\\?[\\'.. stead.delim ..']', { [stead.delim] = game.gui.ways_delim }); str = stead.string.gsub(str, '\\?['..stead.delim ..']',
stead.state = false { [stead.delim] = game.gui.ways_delim, [ '\\'..stead.delim ] = stead.delim });
str = stead.fmt(str);
return iface:center(str); return iface:center(str);
end end
return str return str
@ -175,7 +172,8 @@ function get_title()
s = call(here(), 'nam'); s = call(here(), 'nam');
end end
if type(s) == 'string' and s ~= '' then if type(s) == 'string' and s ~= '' then
-- s = stead.string.gsub(s, '\\?[\\^]', { ['^'] = '\n' }):gsub('\\(.)', '%1'); s = stead.string.gsub(s, '\\?['..stead.delim ..']',
{ [stead.delim] = game.gui.ways_delim, [ '\\'..stead.delim ] = stead.delim });
stead.state = false stead.state = false
s = stead.fmt(s); s = stead.fmt(s);
s = "<c><b>"..s.."</b></c>"; s = "<c><b>"..s.."</b></c>";
@ -272,7 +270,7 @@ fmt = function(...)
for i=1,stead.table.maxn(arg) do for i=1,stead.table.maxn(arg) do
if type(arg[i]) == 'string' then if type(arg[i]) == 'string' then
local s = stead.string.gsub(arg[i],'\t', ' '):gsub('[\n]+', ' '); local s = stead.string.gsub(arg[i],'\t', ' '):gsub('[\n]+', ' ');
s = stead.string.gsub(s, '\\?[\\^]', { ['^'] = '\n' }):gsub('\\(.)', '%1'); s = stead.string.gsub(s, '\\?[%^]', { ['^'] = '\n', ['\\^'] = '^' });
res = stead.par('', res, s); res = stead.par('', res, s);
end end
end end

View file

@ -289,7 +289,7 @@ fmt = function(...)
if type(arg[i]) == 'string' then if type(arg[i]) == 'string' then
local s = stead.string.gsub(arg[i],'[\t ]+',' '); local s = stead.string.gsub(arg[i],'[\t ]+',' ');
s = stead.string.gsub(s, '[\n]+', ' '); s = stead.string.gsub(s, '[\n]+', ' ');
s = stead.string.gsub(s, '\\?[\\^]', { ['^'] = '\n' }):gsub('\\(.)', '%1'); s = stead.string.gsub(s, '\\?[%^]', { ['^'] = '\n', ['\\^'] = '^' });
res = stead.par('', res, s); res = stead.par('', res, s);
end end
end end
@ -389,7 +389,8 @@ function obj_xref(self,str)
if not isObject(self) then if not isObject(self) then
return str; return str;
end end
local s = stead.string.gsub(str, '\\?[\\{}]', { ['{'] = '\001', ['}'] = '\002' }):gsub('\001([^\002]+)\002', xrefrep); local s = stead.string.gsub(str, '\\?[{}]',
{ ['{'] = '\001', ['}'] = '\002', [ '\\{' ] = '{', [ '\\}' ] = '}' }):gsub('\001([^\002]+)\002', xrefrep);
return s; return s;
end end
@ -2019,6 +2020,7 @@ iface = {
stead.state = false; -- changed state (main screen) stead.state = false; -- changed state (main screen)
local a = { }; local a = { };
local cmd; local cmd;
RAW_TEXT = nil
PLAYER_MOVED = nil PLAYER_MOVED = nil
cmd,a = stead.getcmd(inp); cmd,a = stead.getcmd(inp);
if cmd == '' then cmd = 'look' end if cmd == '' then cmd = 'look' end
@ -2077,7 +2079,6 @@ iface = {
end end
if v == false then if v == false then
RAW_TEXT = nil
return stead.cat(r, '\n'), false; return stead.cat(r, '\n'), false;
end end

View file

@ -41,7 +41,7 @@ __do_xact = function(str, self)
if stead.api_version >= "1.2.2" then if stead.api_version >= "1.2.2" then
delim = stead.delim; delim = stead.delim;
end end
s = s:gsub('\\?[\\'..delim..']', { [delim] = '\001' }); s = s:gsub('\\?['..delim..']', { [ delim ] = '\001', [ '\\'..delim ] = delim });
local i = s:find('\001', 1, true); local i = s:find('\001', 1, true);
aarg = {} aarg = {}
if i then if i then
@ -75,7 +75,8 @@ __do_xact = function(str, self)
return xref(d, ref(oo, true), unpack(aarg)); return xref(d, ref(oo, true), unpack(aarg));
end end
if type(str) ~= 'string' then return end if type(str) ~= 'string' then return end
local s = stead.string.gsub(str, '\\?[\\{}]', { ['{'] = '\001', ['}'] = '\002' }):gsub('\001([^\002]+)\002',xrefrep); local s = stead.string.gsub(str, '\\?[{}]',
{ ['{'] = '\001', ['}'] = '\002' }):gsub('\001([^\002]+)\002', xrefrep);
return s; return s;
end end
@ -84,7 +85,7 @@ stead.fmt = stead.hook(stead.fmt, function(f, ...)
for i=1,stead.table.maxn(arg) do for i=1,stead.table.maxn(arg) do
if type(arg[i]) == 'string' then if type(arg[i]) == 'string' then
s = __do_xact(arg[i]); s = __do_xact(arg[i]);
res = stead.par('', res, s); res = stead.par('', res, s):gsub('\\?[{}]', { [ '\\{' ] = '{', [ '\\}' ] = '}' });
end end
end end
return f(res); return f(res);