Merge lp:~jontai/openvista-gtm-integration/bug370653 into lp:openvista-gtm-integration

Proposed by Jon Tai
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jontai/openvista-gtm-integration/bug370653
Merge into: lp:openvista-gtm-integration
Diff against target: None lines
To merge this branch: bzr merge lp:~jontai/openvista-gtm-integration/bug370653
Reviewer Review Type Date Requested Status
jeff.apple Approve
Review via email: mp+7867@code.launchpad.net
To post a comment you must log in.
65. By Jon Tai

bump last-modified date

Revision history for this message
jeff.apple (jeff-apple) wrote :

I don't see anything wrong, though I haven't tested.
One small note: some of the new labels used by the switch are 9 characters long. SAC (2.2.4) only allows for 8. However, since this is a GT.M only module I would think it's OK since GT.M will never have a problem with it.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mumps/ZCD.m'
2--- mumps/ZCD.m 2009-05-21 00:49:08 +0000
3+++ mumps/ZCD.m 2009-06-25 00:10:38 +0000
4@@ -1,4 +1,4 @@
5-ZCD ; MSC/JKT,JDS ; "Namespace" utilities for GT.M/Unix ; 01/30/2009
6+ZCD ; MSC/JKT,JDS ; "Namespace" utilities for GT.M/Unix ; 16JUN2009
7 ;;8.0;KERNEL;**MSC**;April 21 2009
8 ; This routine assumes that your global directory file exists one
9 ; directory below the root of the instance, e.g.,
10@@ -12,163 +12,128 @@
11 ; The actual file name of the global directory file and the actual name
12 ; of the parent directory are never checked, so their names do not
13 ; matter.
14- G CD
15- ;
16-CURRENT()
17- ; return the name of the current OpenVista instance
18- Q $P($ZG,"/",$L($ZG,"/")-2)
19- ;
20-PATH()
21- ; return the path to the current OpenVista instance
22- N I,X S X=""
23- S X=$P($ZG,"/",1,$L($ZG,"/")-2)
24- Q X
25- ;
26-ROOT()
27- ; return the path where all OpenVista instances live
28- N I,X S X=""
29- S X=$P($ZG,"/",1,$L($ZG,"/")-3)
30- Q X
31- ;
32-LIST()
33- ; returns an array (Y) of OpenVista instances on this system
34- ;
35- ; FIXME: a "user friendly" version of this list should screen out the
36- ; current instance name and any instances that the current user
37- ; should not be allowed to switch to (they must have access
38- ; code and primary menu option in the target instance to switch)
39- ;
40- ; FIXME: this routine currently requires GT.M V5.3003 because it uses
41- ; PIPE I/O. We many want to make it compatible with older
42- ; versions of GT.M by falling back to using temporary files,
43- ; but on versions of GT.M V5.3003 and later, we definitely want
44- ; to use PIPEs to avoid temporary files moving forward.
45- N P,I,X
46- K Y
47- S P="ls"
48- O P:(COMMAND="ls --color=none -1 "_$$ROOT():READONLY)::"PIPE"
49- U P
50- N ROOT,GT S ROOT=$$ROOT,GF=$P($P($ZG,ROOT,2),"/",3,99)
51- F I=1:1 R X Q:X="" I $ZSEARCH(ROOT_"/"_X_"/"_GF)'="" S Y(I)=X,Y("B",X)=""
52- U $P
53- C P
54- Q
55- ;
56-GTMPATH(INSTANCE)
57- ; return the path to the version of GT.M this instance uses
58- ;
59- ; FIXME: handle the case when INSTANCE is bogus
60- ;
61- N P,X
62- S P="readlink"
63- O P:(COMMAND="readlink "_$$ROOT()_"/"_INSTANCE_"/gtm":READONLY)::"PIPE"
64- U P
65- R X
66- U $P
67- C P
68- Q X
69- ;
70-SWITCH(INSTANCE)
71- ; switch to another OpenVista instance by setting $ZG and $ZRO
72- ;
73- ; there are several ways to do this; try them in order until
74- ; one succeeds
75- ;
76- ; FIXME: we may want to allow this entry point to be called using DO
77- Q:$$SWITCH1(INSTANCE) 1
78- Q:$$SWITCH2(INSTANCE) 1
79- Q:$$SWITCH3(INSTANCE) 1
80- Q 0
81- ;
82-SWITCH1(INSTANCE)
83- ; private entry point
84- ;
85- ; look for new values of $ZG and $ZRO in env directory of
86- ; target instance
87- N ZG,ZRO,G,RO
88- ;
89- ; FIXME: if file does not exist or is unreadable (permission
90- ; denied), Q 0
91- ;S G=$$ROOT()_"/"_INSTANCE_"/env/gtmgbldir"
92- ;O G:READONLY U G R ZG U $P C G
93- N I,A S A="/"_$$CURRENT()_"/",ZG=""
94- F I=1:1:$L($ZG,A) S ZG=ZG_$P($ZG,A,I)_$S(I=$L($ZG,A):"",1:"/"_INSTANCE_"/")
95- ;
96- ; FIXME: if file does not exist or is unreadable (permission
97- ; denied), Q 0
98- ;S RO=$$ROOT()_"/"_INSTANCE_"/env/gtmroutines"
99- ;O RO:READONLY U RO R ZRO U $P C RO
100- S ZRO=""
101- F I=1:1:$L($ZRO,A) S ZRO=ZRO_$P($ZRO,A,I)_$S(I=$L($ZRO,A):"",1:"/"_INSTANCE_"/")
102- ;
103- S $ZG=ZG,$ZRO=ZRO
104- ;
105- ;zlink the buffer
106- X "Q"
107- N I
108- S I=$view("rtnnext","")
109-NEXT F S I=$VIEW("rtnnext",I) Q:I="" I I'="GTM$DMOD" D
110- .I I="ZCD" Q
111- .I $E(I)="%" Q:($E(I,2)'="Z")
112- .K %ZR D SILENT^%RSEL(I) I $D(%ZR(I)) S A=$TR(I,"%","_") N $ET S $ET="G NEXT^ZCD" ZLINK A_".m" Q
113- .N DIE,X,B S X=I,B(1,0)=I_" ;",B(2,0)=" ZMESSAGE 150374338:$PIECE($ZPOSITION,""^"",2)",B(3,0)=" QUIT"
114- .S DIE="B(",XCN=0 N I D SAVE(X)
115- ; FIXME: do we need to set $ZINTERRUPT and $PATH?
116- Q 1
117- ;
118-SWITCH2(INSTANCE)
119- ; private entry point
120- ;
121- ; look for new values of $ZG and $ZRO in env file of target instance
122- ;
123- ; if the env file does not exist or is unreadable (permission denied)
124- ; or unparsable, Q 0 without setting $ZG and $ZRO
125- ;
126- ; FIXME: implement this
127- ;
128- ; FIXME: do we need to set $ZINTERRUPT and $PATH?
129- Q 0
130- ;
131-SWITCH3(INSTANCE)
132- ; private entry point
133- ;
134- ; get new values of $ZG and $ZRO by replacing $$PATH() with
135- ; $$ROOT()_"/"_INSTANCE. Q 0 without setting $ZG and $ZRO if the
136- ; resulting paths don't actually exist or we do not have permission to
137- ; access them
138- ;
139- ; FIXME: implement this
140- ;
141- ; FIXME: do we need to set $ZINTERRUPT and $PATH?
142- Q 0
143- ;
144-CD ;Interactive
145+ ;
146+CD ; interactive
147 N Y,DIR
148- R !,"Namespace: ",DIR
149+ S:'$D(DTIME) DTIME=300
150+ R !,"Namespace: ",DIR:DTIME
151 I DIR["^"!(DIR="") Q
152- D LIST()
153+ D LIST
154 I DIR["?" G HELP
155 I '$D(Y("B",DIR)) W !,"Invalid Namespace" G CD
156 I $$GTMPATH($$CURRENT())'=$$GTMPATH(DIR) W !,"Inconsistent GTM versions",! G CD
157- S $ZPROMPT=DIR_">"
158- S A=$$SWITCH1(DIR)
159+ S A=$$SWITCH(DIR)
160 Q
161+ ;
162 HELP N A S A=""
163 F S A=$O(Y("B",A)) Q:A="" W !,A
164 W ! G CD
165 Q
166-SAVE(RN) ;Save a routine
167- N %,%F,%I,%N,SP,$ETRAP
168- S $ETRAP="S $ECODE="""" Q"
169- S %I=$I,SP=" ",%F="/tmp/"_$J_"/"_RN_".m"
170- ZSYSTEM "mkdir /tmp/"_$J
171- O %F:(newversion:noreadonly:blocksize=2048:recordsize=2044) U %F
172- F S XCN=$O(@(DIE_XCN_")")) Q:XCN'>0 S %=@(DIE_XCN_",0)") Q:$E(%,1)="$" I $E(%)'=";" W $P(%,SP)_$C(9)_$P(%,SP,2,99999),!
173- C %F ;S %N=$$NULL
174- S ZR=$ZRO,$ZRO=$ZRO_" /tmp/"_$J_"/"
175- ZLINK RN
176- ZSYSTEM "rm -r /tmp/"_$J
177- S $ZRO=ZR
178- ;C %N
179- U %I
180+ ;
181+ROOT() ; return path where all OpenVista instances live
182+ Q $P($ZG,"/",1,$L($ZG,"/")-3)
183+ ;
184+CURRENT() ; return name of the current OpenVista instance
185+ Q $P($ZG,"/",$L($ZG,"/")-2)
186+ ;
187+PATH(INSTANCE) ; return path to an OpenVista instance
188+ Q $$ROOT()_"/"_INSTANCE
189+ ;
190+GTMPATH(INSTANCE) ; return the path to the version of GT.M this instance uses
191+ N %PIPE,%I S %PIPE="readlink",%I=$I
192+ O %PIPE:(COMMAND="readlink "_$$PATH(INSTANCE)_"/gtm":READONLY)::"PIPE" U %PIPE
193+ N %PATH R %PATH
194+ U %I
195+ C %PIPE
196+ Q %PATH
197+ ;
198+LIST ; return an array (Y) of OpenVista instances on this system
199+ N %PIPE,%I S %PIPE="ls",%I=$I
200+ O %PIPE:(COMMAND="ls --color=none -1 "_$$ROOT():READONLY)::"PIPE" U %PIPE
201+ N I,%NAME K Y
202+ F I=1:1 R %NAME Q:%NAME="" I $$GTMPATH(%NAME)'="" S Y(I)=%NAME,Y("B",%NAME)=""
203+ U %I
204+ C %PIPE
205+ Q
206+ ;
207+SWITCH(INSTANCE) ; switch to another OpenVista instance
208+ ;
209+ ; don't allow switching if GT.M versions aren't the same
210+ Q:$$GTMPATH($$CURRENT())'=$$GTMPATH(INSTANCE) 0
211+ ;
212+ ; there are several ways to determine new values of $ZG and $ZRO
213+ ; try each method until one succeeds
214+ N %ZG,%ZRO,%METHOD S %ZG="",%ZRO=""
215+ F %METHOD="ENV","CAT","REP" Q:$$@("SWITCH"_%METHOD)(INSTANCE)
216+ I %ZG="",%ZRO="" Q 0
217+ ;
218+ ; FIXME: set gtm_dist="$root/$instance/gtm"
219+ N %TEMPDIR S %TEMPDIR=$$MKTEMP() S $ZG=%ZG,$ZRO=%ZRO_" "_%TEMPDIR
220+ N X,Y S X=INSTANCE X ^%ZOSF("UPPERCASE") S $ZPROMPT=Y_">"
221+ ; FIXME: set GTMXC_openvista="$root/$instance/gtm/openvista.xc"
222+ ; FIXME: set PATH="$PATH:$root/$instance/gtm"
223+ ;
224+ ; re-ZLINK routines that have been loaded in our current image
225+ X "Q" ; equivalent to ZGOTO so that you can recompile a routine you are using
226+ N %ROUTINE,%FILENAME S %ROUTINE=""
227+NEXT F S %ROUTINE=$VIEW("rtnnext",%ROUTINE) Q:%ROUTINE="" D
228+ . Q:%ROUTINE="GTM$DMOD"
229+ . Q:%ROUTINE="ZCD"
230+ . ;
231+ . ; The only % routines that we ship start with %Z other % routines are allocated to the
232+ . ; vendor (GTM) and do not need to be recompiled (and may only have object code)
233+ . Q:$E(%ROUTINE)="%"&($E(%ROUTINE,2)'="Z")
234+ . ;
235+ . ; If the routine exists in the target instance, ZLINK it. This replaces the
236+ . ; old version in our current image with the new version from the target instance.
237+ . ; If the routine does not exist in the target instance, we have to "kill" the routine
238+ . ; in our current image by creating a dummy routine that throws a GTM-E-FILENOTFND error
239+ . ; and ZLINKing the dummy routine. See http://groups.google.com/group/Hardhats/msg/a213981e1503db79
240+ . S %FILENAME=$TR(%ROUTINE,"%","_")_".m"
241+ . K %ZR D SILENT^%RSEL(%ROUTINE) I '$D(%ZR(%ROUTINE)) D WRITEROU(%TEMPDIR_"/"_%FILENAME,%ROUTINE)
242+ . ZLINK %FILENAME
243+ ;
244+ ; cleanup and return
245+ S $ZRO=%ZRO ; remove temporary directory from $ZRO
246+ ZSY "rm -rf "_%TEMPDIR
247+ Q:'$Q
248+ Q 1
249+ ;
250+SWITCHENV(INSTANCE) ; private entry point to be used by $$SWITCH only
251+ ; set new $ZG and $ZRO by parsing env file in target instance
252+ ;
253+ ; FIXME: implement this
254+ Q 0
255+ ;
256+SWITCHCAT(INSTANCE) ; private entry point to be used by $$SWITCH only
257+ ; set new $ZG and $ZRO by concatenating conventional names to $$ROOT
258+ ;
259+ S %ZG=$$PATH(INSTANCE)_"/globals/mumps.gld"
260+ S %ZRO=$$PATH(INSTANCE)_"/objects("_$$PATH(INSTANCE)_"/routines) "_$$PATH(INSTANCE)_"/gtm"
261+ ;
262+ ; FIXME: check that %ZG actually exists and that all pieces of %ZRO exist
263+ Q 1
264+ ;
265+SWITCHREP(INSTANCE) ; private entry point to be used by $$SWITCH only
266+ ; set new $ZG and $ZRO by replacing $$PATH($$CURRENT()) with $$PATH(INSTANCE)
267+ ;
268+ ; FIXME: implement this
269+ Q 0
270+ ;
271+MKTEMP() ; create a secure temporary directory, returns path to new directory
272+ N %PIPE,%I S %PIPE="mktemp",%I=$I
273+ O %PIPE:(COMMAND="mktemp -d -t .zcd.XXXXXXXXXX":READONLY)::"PIPE" U %PIPE
274+ N %TEMPDIR R %TEMPDIR
275+ U %I
276+ C %PIPE
277+ Q %TEMPDIR
278+ ;
279+WRITEROU(PATH,ROUTINE) ; write out dummy routine
280+ N %I S %I=$I
281+ O PATH:(NEWVERSION:NOREADONLY:VARIABLE) U PATH
282+ W ROUTINE,!
283+ W " ZMESSAGE 150374338:$PIECE($ZPOSITION,""^"",2)",!
284+ W " QUIT",!
285+ U %I
286+ C PATH
287 Q

Subscribers

People subscribed via source and target branches