langsmoke/ref_apl

118 lines
3.6 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

sim←{
←0.5
code←{
(2⊃¨v/⍨x)@(⍸x←∊⊃¨v←⎕VFI¨⍵)⊢⍵
}¨' '(≠⊆⊢)¨⊃⎕NGET ⍵ 1
ind←⊃¨srt←code[⍋⊃¨code]
sys←{⍵/⍨(2|⎕DR)¨⍵}↑,/2↓¨srt
vrf←sys∊⍥∊ind
0=∧/vrf:(∊eunderspec(⍕sys/⍨~vrf))⎕SIGNAL 8
(≢≠⊃∘⌽)ind:enoint ⎕SIGNAL 8
leds←⍸(⊂'LED')≡¨2⊃¨srt
unpref←{'x'≠1↑⍵:(epref ⍵)⎕SIGNAL 8 ⋄ 1↓⍵}
load←{∊'v[',(⍕⍵),']'}
fmt←{{⍵/⍨(\∧∘⌽∨\∘⌽)' '≠⍵}∊('⍝'(≠⊆⊢)∊' '' '),¨⍵,⊂⍬}
state←⎕NS ⍬ ⋄ state.v←0⍨≢srt ⋄ state.t←0
}
AddCentury←{
←→ Century Window, Century Anchor Year
⍝ ⍵ ←→Decimal time number 60
⍝ ← ←→ ⍵ with added century
f w t←
1∊'YYYY'⍷f:⍵
y←⌊⍵÷10*4
b←y<100
~/b:⍵
w>999:⍵+b×w×10*4
s x←0 100w-⍨t
c←b×s+y<x
⍵+c×10*6
}
BasicFormats←{
⍝ ⍵ ←→ Time Strings
⍝ ← ←→ Potential appropriate format strngs
m←↑⍵
w←1⊃m
toWide←w∘{⍵/⍨⍺≥≢¨⍵}
noDays←{⍵/⍨~'D'∊¨⍵}
hasDays←{⍵/⍨'D'∊¨⍵}
i←⊂¨⍋¨,33
sn←1∊∊(↓MonthNames'')⍷¨⊂⎕C m
fp←,i∘.⌷((4sn 1)/(4 3 2)(4 2 2)(2 3 2)2)/¨¨⊂'YMD'
fp←fp,fp~¨⊂⊂'DD'
fd←1↓¨∊¨'/',¨¨fp
fu←{⍵/⍨~/'MMM'⍷↑⍵}∊¨fp
v←i∘.⌷⊂'YMD'
v,←sn/(1+2×v='M')/¨v
v,←v~¨'D'
b←⎕D∊⍨' ',m
r←+/2</b ⍝ Digit runs
d←+/~b[0;] ⍝ Number of delims
fw←1=≢b ⍝ Fixed width
1∧.≥r:fu,⊂'excel' ⍝ toWide fu ⍝ No delimiters
fw∧(d=1)∧2∧.=r:noDays toWide fd ⍝ Fixed without days
fw∧(d=2)∧3∧.=r:hasDays toWide fd ⍝ Fixed with days
z←toWide fu,fd,v
z←z[⍒≢¨z] ⍝ Preference for longer format.
z[⍒+/¨'YMD'∘∊¨z] ⍝ Preference for more elements
}
FixedMMM←{
b←'MMM'⍷⍺
~1∊b:
i←⍸b
f←' '@i⊢
m←⍵
n←MonthNames''
m[;i+3]←'ZI3'⎕FMT 1+n⎕C m[;i+3]
f m
}
∇ {r}←{level}Log msg;ts
:Access public overridable
:If Logging>0∊msg
ts←fmtTS ⎕TS
:If 1=≢msg←⍕msg
:OrIf 1=⊃msg
r←ts,' - ',msg
:Else
r←ts,∊(⎕UCS 13),msg
:EndIf
⎕←r
:EndIf
∇ r←New arg
⍝ create a new instance of Jarvis
:Access public shared
:If 0∊arg
r←##.⎕NEW ⎕THIS
:Else
r←##.⎕NEW ⎕THIS arg
:EndIf
∇ make
:Access public
:Implements constructor
MakeCommon
∇ r←args default defaults
args←,⊆args
r←(≢defaults)↑args,(≢args)↓defaults
∇ Close
:Implements destructor
{0:: ⋄ {}LDRC.Close ServerName}⍬
∇ (rc msg)←Pause
:Access public
→0 If~_started⊣(rc msg)←¯1 'Server is not running'
→0 If 2=⊃2⊃LDRC.GetProp ServerName'Pause'⊣(rc msg)←¯2 Error'Server is already paused'
→0 If 0≠rc←⊃LDRC.SetProp ServerName'Pause' 2⊣msg←'Error attempting to pause server'
Log'Pausing server...'
(rc msg)←0 'Server paused'
∇s