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();
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) {

View file

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

View file

@ -289,7 +289,7 @@ fmt = function(...)
if type(arg[i]) == 'string' then
local s = stead.string.gsub(arg[i],'[\t ]+',' ');
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);
end
end
@ -389,7 +389,8 @@ function obj_xref(self,str)
if not isObject(self) then
return str;
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;
end
@ -2019,6 +2020,7 @@ iface = {
stead.state = false; -- changed state (main screen)
local a = { };
local cmd;
RAW_TEXT = nil
PLAYER_MOVED = nil
cmd,a = stead.getcmd(inp);
if cmd == '' then cmd = 'look' end
@ -2077,7 +2079,6 @@ iface = {
end
if v == false then
RAW_TEXT = nil
return stead.cat(r, '\n'), false;
end

View file

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