From b661d763555286bc699a20287c645beb23c082a8 Mon Sep 17 00:00:00 2001 From: "p.kosyh@gmail.com" Date: Thu, 4 Nov 2010 08:20:40 +0000 Subject: [PATCH] more simple escaping --- src/sdl-instead/game.c | 4 +++- stead/gui.lua | 24 +++++++++++------------- stead/stead.lua | 7 ++++--- stead/xact.lua | 7 ++++--- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/sdl-instead/game.c b/src/sdl-instead/game.c index a2ccf6b..64b04e9 100644 --- a/src/sdl-instead/game.c +++ b/src/sdl-instead/game.c @@ -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) { diff --git a/stead/gui.lua b/stead/gui.lua index 9c9f621..9885bb8 100644 --- a/stead/gui.lua +++ b/stead/gui.lua @@ -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 "","\\\\>"):gsub("%^","\\%^")..">"; + return "","\\>"):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 = ""..s..""; @@ -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 diff --git a/stead/stead.lua b/stead/stead.lua index a4dd8e2..8f5ea8b 100644 --- a/stead/stead.lua +++ b/stead/stead.lua @@ -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 diff --git a/stead/xact.lua b/stead/xact.lua index 95a9f61..b79d8c9 100644 --- a/stead/xact.lua +++ b/stead/xact.lua @@ -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);