Skip to content

Commit d7b658a

Browse files
committed
List enhanced and a bug fixed
1 parent 3d3aa5e commit d7b658a

File tree

7 files changed

+147
-5
lines changed

7 files changed

+147
-5
lines changed

APLSource/EventCodes-21.class

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@
6060

6161
∇ r←Version
6262
:Access Public Shared
63-
r←({⍵}⍕⎕THIS)'1.2.1.7' '2018-10-22'
63+
r←({⍵}⍕⎕THIS)'1.3.0.8' '2018-10-25'
6464
6565

6666
∇ History
6767
:Access Public Shared
68+
⍝ * 1.3.0
69+
⍝ * `List` now excepts a left argument: '' (the default) results in the matrix being sorted
70+
⍝ by symbolic name. `⍬` results in it being sorted by number.
71+
⍝ * Bug fix: `List` crashed on a right argument `⍬`.
6872
⍝ * 1.2.1
6973
⍝ * Fix: documentation mentioned "up to 15.0" when it's actually up to and including 17.0
7074
⍝ * 1.2.0
@@ -93,15 +97,27 @@
9397
:EndIf
9498
9599

96-
∇ __allNumbers←List __start
100+
∇ __allNumbers←{__sortType}List __start
97101
⍝ Returns a matrix with all symbolic names and their numbers in case `__start` is empty.\\
98102
⍝ In case `__start` is not empty only the symbolic names that start with `__start` are listed.\\
99-
⍝ `start` is **not** case sensitive.
103+
⍝ `start__` is **not** case sensitive.\\
104+
⍝ You can force `List` to sort the result. Default is sorting by symbolic name. Specifying `''`
105+
⍝ as the left argument has the same result. If you specify `⍬` instead the list is sorted by number.
100106
:Access Public Shared
107+
:If 0=⎕NC'__sortType'
108+
__sortType←''
109+
:EndIf
101110
__allNumbers←⎕NL-2
102111
__allNumbers←('__'∘≢¨2↑¨__allNumbers)/__allNumbers
103112
__allNumbers←__allNumbers,[1.5]⍎¨__allNumbers
104-
:If ~0∊⍴__start←{1(819⌶)⍵}__start~'*'
113+
:If ''≡__sortType
114+
__allNumbers←__allNumbers[⍋__allNumbers[;1];]
115+
:ElseIf ⍬≡__sortType
116+
__allNumbers←__allNumbers[⍋__allNumbers[;2];]
117+
:Else
118+
'Invalid sort type: either '''' (alpha) or ⍬ (numeric)'⎕SIGNAL 11
119+
:EndIf
120+
:If ~0∊⍴__start←{1(819⌶)⍕⍵}__start~'*'
105121
__allNumbers←(((⍴,__start)↑[2]↑__allNumbers[;1])∧.=__start)⌿__allNumbers
106122
:EndIf
107123
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
r←GetHighestInstalledAPL dummy;versions;ind;list
2+
⍝ Examines the Registry in order to find out which versions of
3+
⍝ Dyalog are installed on the current machine
4+
r←''
5+
:If 0≠≢list←##.WinReg.GetAllSubKeyNames'Software\Dyalog'
6+
:AndIf 0≠≢list←('Dyalog APL/W'{⍺∘≡¨(⍴⍺)↑¨⍵}list)/list
7+
:If 0∊≢list←(50<↑∘⍴¨##.WinReg.GetAllValueNames¨(⊂'Software\Dyalog\'),¨list)/list
8+
'No version of Dyalog was found'⎕SIGNAL 11
9+
:Else
10+
list←{⍵⌿⍨∨/'Dyalog APL/W'⍷↑⍵}list
11+
versions←2⊃¨' '##.APLTreeUtils.Split¨list
12+
ind←⍋versions
13+
list←list[ind]
14+
r←↑¯1↑list
15+
:EndIf
16+
:EndIf

APLSource/TestCases-11/NL-3.function

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
r←NL
2+
r←⎕UCS 13 10
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
R←Test_30(stopFlag batchFlag);⎕TRAP;errors;TEMP;html;list;version
2+
⍝ Check whether we cover all documented codes according to the latest installed version
3+
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
4+
R←∆Failed
5+
6+
version←2⊃' '##.APLTreeUtils.Split GetHighestInstalledAPL ⍬
7+
errors←∆GetErrorsFromHelpPage'http://help.dyalog.com/',version,'/Content/Language/System%20Functions/trap.htm'
8+
list←##.EventCodes.List''
9+
→PassesIf∧/list[;2]∊errors[;1]
10+
→PassesIf∧/errors[;1]∊list[;2]
11+
12+
R←∆OK
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
errors←∆GetErrorsFromHelpPage url;TEMP;html;buff;bool;codes;comment
2+
TEMP←⎕NS''
3+
TEMP.(⎕IO ⎕ML)←1 1
4+
(⊃'DRC' 'HTTPUtils')TEMP.⎕CY'Conga'
5+
html←TEMP ∆HTTPGet url
6+
html←{⍵↓⍨3⊃{⍵/⍳⍴,⍵}'<table'⍷⍵}html
7+
buff←(⍴'<td class="Dyalog">')↓¨{⍵~⎕TC}¨('<td class="Dyalog">'⍷html)⊂html
8+
bool←(⍴buff)⍴1 0
9+
codes←{⍵↑⍨¯1+⍵⍳'<'}¨bool/buff
10+
bool←~bool
11+
comment←{⍵↑⍨¯1+1⍳⍨'</td>'⍷⍵}¨bool/buff
12+
bool←{⊃⊃⎕VFI ⍵}¨codes
13+
(codes comment)←bool∘/¨codes comment
14+
codes←{⊃⊃(//)⎕VFI ⍵}¨codes
15+
bool←~codes∊0 1000
16+
(codes comment)←bool∘/¨codes comment
17+
errors←codes,[1.5]comment
18+
⍝Done
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
html←ref ∆HTTPGet url;fromutf8;h2d;getchunklen;split;found;DRC;U;p;port;host;page;request;err;cmd;chunked;chunk;buffer;chunklength;done;datalen;header;wr;rc
2+
⍝ Get an HTTP page, format [HTTP[S]://][user:pass@]url[:port][/page]
3+
⍝ `ref` must point to a namespace that contains DRC (Conga).
4+
⎕IO←1 ⋄ ⎕ML←1
5+
fromutf8←{0::(⎕AV,'?')[⎕AVU⍳⍵] ⋄ 'UTF-8'⎕UCS ⍵} ⍝ Turn raw UTF-8 input into text
6+
h2d←{⎕IO←0 ⋄ 16⊥'0123456789abcdef'⍳U.lc ⍵} ⍝ hex to decimal
7+
getchunklen←{¯1=len←¯1+⊃(NL⍷⍵)/⍳⍴⍵:¯1 ¯1 ⋄ chunklen←h2d len↑⍵ ⋄ (⍴⍵)<len+chunklen+4:¯1 ¯1 ⋄ len chunklen}
8+
split←{(p↑⍵)((p←¯1+⍵⍳⍺)↓⍵)}
9+
rc←0
10+
:If found←3=ref.⎕NC'DRC.Init'
11+
{}ref.DRC.Init'' ⍝ v3 intialisation
12+
DRC←ref.DRC
13+
:Else
14+
'Could not find Conga or DRC object'⎕SIGNAL 906
15+
:EndIf
16+
U←ref.HTTPUtils ⍝ Uses utils from same place as DRC/Conga
17+
p←{(∨/b)×1+(b←'//'⍷⍵)⍳1}url
18+
port←80
19+
url←p↓url ⍝ Remove HTTP[s]:// if present
20+
(host page)←'/'split url,(~'/'∊url)/'/' ⍝ Extract host and page from url
21+
host port←port U.HostPort host ⍝ Check for override of port number
22+
request←'GET ',page,' HTTP/1.1',NL,'Host: ',host,NL,'User-Agent: Dyalog/Conga',NL,'Accept: */*',NL ⍝ build the request
23+
:If 2=DRC.⎕NC'flate'
24+
:AndIf DRC.flate.IsAvailable ⍝ if compression is available
25+
request,←'Accept-Encoding: deflate',NL ⍝ indicate we can accept it
26+
:EndIf
27+
(err cmd)←2↑rc←DRC.Clt''host port'Text' 100000 ⍝ 100,000 is max receive buffer size
28+
:If 0=err
29+
:AndIf 0=⊃rc←DRC.Send cmd(request,NL)
30+
chunked chunk buffer chunklength←0 '' '' 0
31+
(done html datalen header)←0 ⍬ 0(0 ⍬)
32+
:Repeat
33+
:If ~done←0≠1⊃wr←DRC.Wait cmd 5000 ⍝ Wait up to 5 secs
34+
:If wr[3]∊'Block' 'BlockLast' ⍝ If we got some html
35+
:If chunked
36+
chunk←4⊃wr
37+
:ElseIf 0<⍴html,←4⊃wr
38+
:AndIf 0=1⊃header
39+
header←U.DecodeHeader html
40+
:If 0<1⊃header
41+
html←(1⊃header)↓html
42+
:If chunked←∨/'chunked'⍷(2⊃header)U.GetValue'Transfer-Encoding' ''
43+
chunk←html
44+
html←''
45+
:Else
46+
datalen←⊃((2⊃header)U.GetValue'Content-Length' 'Numeric'),¯1 ⍝ ¯1 if no content length not specified
47+
:EndIf
48+
:EndIf
49+
:EndIf
50+
:Else
51+
⎕←wr ⍝ Error?
52+
.
53+
:EndIf
54+
:If chunked
55+
buffer,←chunk
56+
:While done<¯1≠⊃(len chunklength)←getchunklen buffer
57+
:If (⍴buffer)≥4+len+chunklength
58+
html,←chunklength↑(len+2)↓buffer
59+
buffer←(chunklength+len+4)↓buffer
60+
:If done←0=chunklength ⍝ chunked transfer can add headers at the end of the transmission
61+
header[2]←⊂(2⊃header)⍪2⊃U.DecodeHeader buffer
62+
:EndIf
63+
:EndIf
64+
:EndWhile
65+
:Else
66+
done←done∨'BlockLast'≡3⊃wr ⍝ Done if socket was closed
67+
:If datalen>0
68+
done←done∨datalen≤⍴html ⍝ ... or if declared amount of html rcvd
69+
:Else
70+
done←done∨(∨/'</html>'⍷html)∨(∨/'</HTML>'⍷html)
71+
:EndIf
72+
:EndIf
73+
:EndIf
74+
:Until done
75+
:Else
76+
911 ⎕SIGNAL⍨'Connection failed ',,⍕wr
77+
:EndIf
78+
{}DRC.Close cmd

publish.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<tool name="EventCodes"> <version>1.2.1</version> <date>2018-10-22</date> <container>#._EventCodes</container> <files></files> <needs> <script>APLTreeUtils</script> <script>FilesAndDirs</script> <script>OS</script> <script>Tester</script> </needs> <scriptOnly>1</scriptOnly> <wsid>Development</wsid> <autoload>1</autoload> <buildid>7</buildid></tool>
1+
<tool name="EventCodes"> <version>1.3.0</version> <date>2018-10-25</date> <container>#._EventCodes</container> <files></files> <needs> <script>APLTreeUtils</script> <script>FilesAndDirs</script> <script>OS</script> <script>WinReg</script> <script>Tester</script> </needs> <scriptOnly>1</scriptOnly> <wsid>Development</wsid> <autoload>1</autoload> <buildid>8</buildid></tool>

0 commit comments

Comments
 (0)