-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTool.dyalog
More file actions
213 lines (176 loc) · 6.95 KB
/
Copy pathTool.dyalog
File metadata and controls
213 lines (176 loc) · 6.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
:Namespace Tool
⎕IO←⎕ML←1
⍝ Tool loader fo Dyalog APL
⍝ Currently supports Conga, SQAPL, RConnect, SharpPlot
⍝ ref←Tool.New 'toolname' [rarg] [larg] [minver] [target]
⍝ Returns a ref to an instance of the tool, read for use
⍝ Optional rarg is passed to constructor or initialisation function
⍝ Optional larg is passed if not ''
⍝ Optional minver is minimum version required (NOT SUPPORTED YET)
⍝ Optional target is ref to namespace to load into
⍝ ref←Tool.Prepare 'toolname' [minver] [target]
⍝ Returns a ref to the main namespace or class which implements the tool
⍝ See Tool.New for a description of arguments
∇ lc←_SetLc
:Trap 2
lc←⎕C
:Else
lc←819⌶
:EndTrap
∇
lc←_SetLc
ge←{(1000⊥⍺)≥1000⊥⍵} ⍝ compare version numbers
∇ r←isWin
r←'Win'≡3↑1⊃#.⎕WG'APLVersion'
∇
∇ r←findws ws;DYALOG;path
⍝ Look for workpace in the current directory, then in the DYALOG folder, finally search WSPATH
:If ~⎕NEXISTS r←ws,'.dws' ⍝ check current folder first
DYALOG←{⍵,'/'↓⍨'/\'∊⍨¯1↑⍵}2 ⎕NQ'.' 'GetEnvironment' 'DYALOG'
:AndIf ~⎕NEXISTS r←DYALOG,'/ws/',r ⍝ check DYALOG folder
:For path :In ':;'[1+isWin](≠⊆⊢)2 ⎕NQ'.' 'GetEnvironment' 'WSPATH'
→0⍴⍨⎕NEXISTS r←path,'/',ws,'.dws'
:EndFor
('Unable to locate workspace "',ws,'"')⎕SIGNAL 11
:EndIf
∇
∇ r←New args;module;rarg;larg;minver;target;z;ns
⍝ Initialise a Core Dyalog Application Component
⍝ args[1] - or simple argument: Conga|SQAPL|SharpPlot (more to come)
⍝ The rest are optional
⍝ args[2] - right argument to Init function of the component (default = '')
⍝ [3] - left argument to Init function (missing or '' = monadic call)
⍝ [4] - Minimum version required in the form (major minor svnrev)
⍝ [5] - Terget namespace to materialise namespaces or classes in (default = #)
(module rarg larg minver target)←args←{⍵,(≢⍵)↓'' '' ''(0 0 0)#},⊆args
:If larg≡''
z←⎕EX'larg' ⋄ larg←⊢
:EndIf
:Trap 0
ns←Prepare args[1 4 5]
:Else
(⊃⎕DMX.DM)⎕SIGNAL ⎕DMX.EN
:EndTrap
⍝ Now initialise
:Select lc module
:Case 'conga'
:If 9.2=⎕NC⊂'ns' ⍝ Instance (of Conga)
r←ns
:ElseIf 3=ns.⎕NC'FindInst' ⍝ Looks like the Conga namespace
r←larg ns.Init rarg
:ElseIf 3=ns.⎕NC'IWAAuth' ⍝ Looks like old style DRC
:If (⊃z←larg ns.Init rarg)∊0
r←ns
:Else
('DRC.Init returned: ',⍕z)⎕SIGNAL 11
:EndIf
:Else
('Unable to determine Conga version of ',ns)⎕SIGNAL 11
:EndIf
:Case 'sqapl'
:If 0=⊃z←ns.Init rarg
r←ns
:Else
('SQA.Init returned: ',⍕z)⎕SIGNAL 11
:EndIf
:Case 'sharpplot'
r←#.⎕NEW ns
:Case 'rconnect'
r←#.⎕NEW ns
{}r.init
:Else
'Supported tools are: Conga RConnect SharpPlot SQAPL'⎕SIGNAL 6
:EndSelect
∇
∇ r←Prepare args;module;minver;target
⍝ Load, but do not initialise a Core Dyalog Application Component
⍝ Return a reference to the namespace/class that was loaded
⍝ args[1] - or simple argument: Conga|SQAPL|SharpPlot|RConnect
⍝ Optional arguments:
⍝ [2] - Minimum version required in the form (major minor svnrev)
⍝ [3] - Terget namespace to materialise namespaces or classes in (default = #)
(module minver target)←{⍵,(≢⍵)↓''(0 0 0)#},⊆args
'Minimum Version not yet supported'⎕SIGNAL(0 0 0≢3↑minver)/11
:Select lc module
:Case 'conga'
r←LoadConga minver target
:Case 'sqapl'
r←LoadSQAPL minver target
:Case 'sharpplot'
r←LoadSharpPlot minver target
:Case 'rconnect'
r←LoadRConnect minver target
:Else
'Supported tools are: Conga RConnect SharpPlot SQAPL'⎕SIGNAL 6
:EndSelect
∇
∇ r←LoadRConnect(minver target)
⍝ Unable to verify version, rconnect doesn't expose one
:If 9≠target.⎕NC'R'
target.⎕CY findws'rconnect'
:EndIf
r←target.R
∇
∇ r←LoadSQAPL(minver target)
:If 9≠target.⎕NC'SQA'
'SQA'target.⎕CY findws'sqapl'
:EndIf
r←target.SQA
∇
:Section Conga
∇ r←LoadConga(minver target);ns;m;nss;copied;ws
r←copied←''
:If ∨/m←0≠target.⎕NC nss←'Conga' 'DRC'
r←target⍎ns←(m⍳1)⊃nss
:Else
(ns←'Conga')target.⎕CY ws←findws'conga'
copied←' copied from "',ws,'"'
r←target.Conga
:EndIf
⍝ :If ~r.Version ge minver
⍝ ('LoadConga: ',ns,copied,' has version ',⍕minver)⎕SIGNAL 11
⍝ :EndIf
∇
:EndSection Conga
:Section SharpPlot
∇ r←{apl}LoadSharpPlot(minver target);nc;version
⍝ note that ns may be an array of references
CAUSEWAY←⎕NULL ⍝ reference to APL ⎕CY of sharpplot
:If 0=⎕NC'apl' ⋄ apl←0 ⋄ :EndIf ⍝ do not force APL unless told to
:If apl
:OrIf 4≠⊃DotNetVersion ⍝ require .Net Framework until .NetCore has proper GDI and WinForms
target.System.Drawing←target.System←target.Causeway←GetAplCauseway
:Else
target.⎕USING,←',system.drawing.dll' ',sharpplot.dll'
:EndIf
nc←target.⎕NC⊂'Causeway.SharpPlot.Version'
:If ¯2.6=nc ⍝ .Net
:OrIf ¯2.3=nc ⍝ APL post-v3.39
version←target.Causeway.SharpPlot.Version
:ElseIf ¯3.1=⎕NC⊂'ns.Causeway.SharpPlot.GetVersion' ⍝ APL pre-v3.39
version←target.Causeway.SharpPlot.GetVersion
:Else ⍝ failed to load sharpplot !
version←''
:EndIf
r←target.Causeway.SharpPlot
∇
∇ v←DotNetVersion;⎕USING
⍝ Assumptions :
⍝ Dyalog only allows .Net Framework v4 (v1 v2 and v3 are not supported anymore)
⍝ Therefore v3 and v5 must mean .Net Core
:Trap 0 ⍝ ⎕USING← has been known to fail
⎕USING←'' ⍝ Ensure that System is present if at all possible
v←System.Environment.Version.(Major Minor)
:Else
v←0 0
:EndTrap
∇
∇ ns←GetAplCauseway ⍝ do the ⎕CY only once, if needed
:If CAUSEWAY≡⎕NULL
CAUSEWAY←#.(⎕NS'') ⍝ unnamed namespace in #
CAUSEWAY.⎕CY findws'sharpplot'
:EndIf
ns←CAUSEWAY
∇
:EndSection SharpPlot
:EndNamespace