aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-12-05 00:08:43 +0100
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-12-05 00:08:43 +0100
commit9c1d3565058799f21b6985c100ccf1abe045d3da (patch)
tree6c0bd31bf0b9454879dc7ad208bdcfed70f99dc6
parent8d794525b3232dbe326043ee3d219ecabee04636 (diff)
downloadadvtrains-9c1d3565058799f21b6985c100ccf1abe045d3da.tar.gz
advtrains-9c1d3565058799f21b6985c100ccf1abe045d3da.tar.bz2
advtrains-9c1d3565058799f21b6985c100ccf1abe045d3da.zip
Add inverse ARS rules
!RC foo !LN bar will match all trains except those matching RC foo or LN bar. This can be useful to exclude one specific service from a component.
-rw-r--r--advtrains_interlocking/ars.lua31
1 files changed, 25 insertions, 6 deletions
diff --git a/advtrains_interlocking/ars.lua b/advtrains_interlocking/ars.lua
index 5bb56fa..434ae2c 100644
--- a/advtrains_interlocking/ars.lua
+++ b/advtrains_interlocking/ars.lua
@@ -30,12 +30,16 @@ function il.ars_to_text(arstab)
end
local txt = {}
-
+
for i, arsent in ipairs(arstab) do
+ local n = ""
+ if arsent.n then
+ n = "!"
+ end
if arsent.ln then
- txt[#txt+1] = "LN "..arsent.ln
+ txt[#txt+1] = n.."LN "..arsent.ln
elseif arsent.rc then
- txt[#txt+1] = "RC "..arsent.rc
+ txt[#txt+1] = n.."RC "..arsent.rc
elseif arsent.c then
txt[#txt+1] = "#"..arsent.c
end
@@ -58,13 +62,18 @@ function il.text_to_ars(t)
if line=="*" then
arstab.default = true
else
- local c, v = string.match(line, "^(..)%s(.*)$")
+ local c, v = string.match(line, "^(...?)%s(.*)$")
if c and v then
+ local n = nil
+ if string.sub(c,1,1) == "!" then
+ n = true
+ c = string.sub(c,2)
+ end
local tt=string.upper(c)
if tt=="LN" then
- arstab[#arstab+1] = {ln=v}
+ arstab[#arstab+1] = {ln=v, n=n}
elseif tt=="RC" then
- arstab[#arstab+1] = {rc=v}
+ arstab[#arstab+1] = {rc=v, n=n}
end
else
local ct = string.match(line, "^#(.*)$")
@@ -101,6 +110,16 @@ function il.ars_check_rule_match(ars, train)
local routingcode = train.routingcode
for arskey, arsent in ipairs(ars) do
--atdebug(arsent, line, routingcode)
+ if arsent.n then
+ -- rule is inverse...
+ if arsent.ln and (not line or arsent.ln ~= line) then
+ return arskey
+ elseif arsent.rc and (not routingcode or not string.find(" "..routingcode.." ", " "..arsent.rc.." ", nil, true)) then
+ return arskey
+ end
+ return nil
+ end
+
if arsent.ln and line and arsent.ln == line then
return arskey
elseif arsent.rc and routingcode and string.find(" "..routingcode.." ", " "..arsent.rc.." ", nil, true) then