source: FOIAVistA/tag/r/KERNEL-XU-A4A7-USC-XG-XLF-XNOA-XPD-XQ-XVIR-ZI-ZOSF-ZOSV-ZT-ZU-%Z-XIP--XQAB--XUC--XUR--ZIN--ZTED/ZISHGTM.m@ 1718

Last change on this file since 1718 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 6.0 KB
Line 
1%ZISH ;ISF/AC,RWF - GT.M for VMS/Unix Host file Control ;01/04/2005 10:44
2 ;;8.0;KERNEL;**275,306,385**;Jul 10, 1995;Build 3
3 ; for GT.M for Unix/VMS, version 4.3
4 ;
5OPENERR ;
6 Q 0
7 ;
8OPEN(X1,X2,X3,X4,X5,X6) ;SR. Open file
9 ;D OPEN^%ZISH([handlename],[directory],filename,[accessmode],[recsize])
10 ;X1=handle name
11 ;X2=directory, X3=filename, X4=access mode
12 ;X5=new file max record size, X6=Subtype
13 ;
14 N %,%1,%2,%IO,%I2,%P,%T,X,Y,$ETRAP
15 S $ETRAP="D OPNERR^%ZISH"
16 S U="^",X2=$$DEFDIR($G(X2)),X4=$$UP^XLFSTR(X4)
17 S Y=$S(X4["A":"append",X4["R":"readonly",X4["W":"newversion",1:"readonly")
18 S Y=Y_$S(X4["B":":fixed:nowrap:recordsize=512",$G(X5)&(X4["W"):":WIDTH="_+X5,1:"")
19 S:$E(Y)=":" Y=$E(Y,2,999) S %IO=X2_X3,%I2="%IO:"_$S($L(Y):"("_Y_")",1:"")_":3"
20 O @%I2 S %T=$T
21 I '%T S POP=1 Q
22 S IO=%IO,IO(1,IO)="",IOT="HFS",IOM=80,IOSL=60,POP=0 D SUBTYPE^%ZIS3($G(X6))
23 I $G(X1)]"" D SAVDEV^%ZISUTL(X1)
24 U IO U $P ;Enable use of $ZA to test EOF condition.
25 Q
26OPNERR ;error on open
27 S POP=1,$ECODE=""
28 U:$G(%P)]"" %P
29 Q
30 ;
31CLOSE(X) ;SR. Close HFS device not opened by %ZIS.
32 ;X1=Handle name, IO=device
33 I IO]"" C IO K IO(1,IO)
34 I $G(X)]"" D RMDEV^%ZISUTL(X)
35 I $D(IO("HOME"))!$D(^XUTL("XQ",$J,"IOS")) D HOME^%ZIS
36 Q
37DEL(%ZX1,%ZX2) ;ef,SR. Del fl(s)
38 ;S Y=$$DEL^%ZISH("dir path",$NA(array))
39 N %ZISH,%ZISHLGR,%ZX,X,%ZXDEL
40 S %ZX1=$$DEFDIR($G(%ZX1)),%ZXDEL=1,%ZISH=""
41 F S %ZISH=$O(@%ZX2@(%ZISH)) Q:%ZISH="" D
42 . N $ETRAP,$ESTACK S $ETRAP="D DELERR^%ZISH"
43 . I %ZISH["*" S %ZXDEL=0 Q ; Wild card not allowed.
44 . S %ZX=$ZSEARCH(%ZX1_%ZISH)
45 . Q:%ZX']"" ; File doesn't exist - not an error, just quit.
46 . O %ZX:READONLY:0
47 . I '$T S %ZXDEL=0 Q ; Can't open it.
48 . C %ZX:DELETE
49 . I $ZSEARCH(%ZX)]"" S %ZXDEL=0 ; Delete was not successful.
50 Q %ZXDEL
51DELERR ;Trap any $ETRAP error, unwind and return.
52 S $ETRAP="D UNWIND^%ZTER"
53 S %ZXDEL=0
54 D UNWIND^%ZTER
55 Q
56 ;
57LIST(%ZX1,%ZX2,%ZX3) ;ef,SR. Set local array holding fl names
58 ;S Y=$$LIST^ZISH("/dir/","list_root","return_root")
59 ;list_root can have XX("A*"), XX("test.com")...
60 ;Both arrays passed as $NA values (closed roots).
61 N %ZISH,%ZIX,%ZIY,POP,X
62 N $ETRAP,$ESTACK S $ETRAP="G LSTX^%ZISH",%ZX1=$$DEFDIR($G(%ZX1))
63 ;Get fls, Build listing in %ZISHDL1 with ls
64 S %ZISH=""
65 F S %ZISH=$O(@%ZX2@(%ZISH)) Q:%ZISH="" D
66 . S %ZIX=$ZPARSE(%ZX1_%ZISH) Q:%ZIX=""
67 . F S %ZIY=$ZSEARCH(%ZIX) Q:%ZIY="" S %ZIY=$ZPARSE(%ZIY,"NAME")_$ZPARSE(%ZIY,"TYPE"),@%ZX3@(%ZIY)=""
68LSTX ;
69 S $ECODE=""
70 Q ($Q(@%ZX3)]"")
71 ;
72SPAWNERR ;TRAP ERROR OF SPAWN
73 O %ZISHDL1:READONLY:1 I $T C %ZISHDL1:DELETE
74 S $ECODE=""
75 Q 0
76 ;
77MV(X1,X2,Y1,Y2) ;ef,SR. Rename a fl
78 ;S Y=$$MV^ZISH("/dir/","fl","/dir/","fl")
79 N %Z,%C
80 S X1=$$DEFDIR($G(X1)),Y1=$$DEFDIR($G(Y1))
81 S %C=$S($ZV["VMS":"RENAME ",1:"mv ")
82 ;Pbv or qit
83 I (X2="")!(Y2="") Q 0
84 ZSYSTEM %C_X1_X2_" "_Y1_Y2 ;Use system rename
85 S %Z=$ZSEARCH(Y1_Y2)
86 Q $L(%Z)>0
87 ;
88PWD() ;ef,SR. Print working directory
89 N Y
90 S Y=$$DEFDIR("")
91 S:Y="" Y=$ZDIR
92 Q Y
93 ;
94DEFDIR(DF) ;ef. Default Dir and frmt
95 S DF=$G(DF) Q:DF="." "" ;Special way to get current dir.
96 S:DF="" DF=$G(^XTV(8989.3,1,"DEV"))
97 ;Old code
98 ;Check syntax, VMS needs : or [ ]
99 I ^%ZOSF("OS")["VMS" D Q DF ;***EXIT FOR VMS/GTM
100 . N P1,P2
101 . S DF=$ZPARSE(DF)
102 . I DF[":" S P1=$P(DF,":")_":",P2=$P(DF,":",2)
103 . E S P1="",P2=DF
104 . I P1="",P2["$" S DF=P2 Q ;Assume a logical
105 . I $L(P2) S:P2'["[" P2="["_P2 S:P2'["]" P2=P2_"]"
106 . S DF=P1_P2
107 . Q
108 ;
109 ;Check syntax, Unix check leading & trailing "/"
110 S DF=$ZPARSE(DF)
111 I "./"'[$E(DF) S DF="/"_DF
112 I $E(DF,$L(DF))'="/" S DF=DF_"/"
113 Q DF
114STATUS() ;ef,SR. Return EOF status
115 U $I
116 Q $ZEOF
117 ;
118EOF(X) ;Eof flag, Pass in $ZA
119 Q X
120QL(X) ;Qlfrs
121 Q:X=""
122 S:$E(X)'="-" X="-"_X
123 Q
124FL(X) ;Fl len
125 N ZOSHP1,ZOSHP2
126 S ZOSHP1=$P(X,"."),ZOSHP2=$P(X,".",2)
127 I $L(ZOSHP1)>14 S X=4 Q
128 I $L(ZOSHP2)>8 S X=4 Q
129 Q
130 ;
131MAKEREF(HF,IX,OVF) ;Internal call to rebuild global ref.
132 ;Return %ZISHF,%ZISHO,%ZISHI,%ZISUB
133 N I,F,MX
134 S OVF=$G(OVF,"%ZISHOF")
135 S %ZISHI=$$QS^DDBRAP(HF,IX),MX=$$QL^DDBRAP(HF) ;
136 S F=$NA(@HF,IX-1) ;Get first part
137 I IX=1 S %ZISHF=F_"(%ZISHI" ;Build root, IX=1
138 I IX>1 S %ZISHF=$E(F,1,$L(F)-1)_",%ZISHI" ;Build root
139 S %ZISHO=%ZISHF_","_OVF_",%OVFCNT)" ;Make overflow
140 F I=IX+1:1:MX S %ZISHF=%ZISHF_",%ZISUB("_I_")",%ZISUB(I)=$$QS^DDBRAP(HF,I)
141 S %ZISHF=%ZISHF_")"
142 Q
143FTG(%ZX1,%ZX2,%ZX3,%ZX4,%ZX5) ;ef,SR. Unload contents of host file into global
144 ;p1=host file directory
145 ;p2=host file name
146 ;p3= $NAME REFERENCE INCLUDING STARTING SUBSCRIPT
147 ;p4=INCREMENT SUBSCRIPT
148 ;p5=Overflow subscript, defaults to "OVF"
149 N %ZA,%ZB,%ZC,%ZL,X,%OVFCNT,%CONT,%EXIT
150 N I,%ZISH,%ZISH1,%ZISHI,%ZISHL,%ZISHLGR,%ZISHOF,%ZISHOX,%ZISHS,%ZX,%ZISHY,POP,%ZISUB
151 S %ZX1=$$DEFDIR($G(%ZX1)),%ZISHOF=$G(%ZX5,"OVF")
152 D MAKEREF(%ZX3,%ZX4,"%ZISHOF")
153 D OPEN^%ZISH(,%ZX1,%ZX2,"R")
154 I POP Q 0
155 N $ETRAP S %EXIT=0,$ETRAP="S %ZA=1,%EXIT=1,$ECODE="""" Q"
156 U IO F K %XX D READNXT(.%XX) Q:$$EOF(%ZA) D
157 . S @%ZISHF=%XX
158 . I $D(%XX)>2 F %OVFCNT=1:1 Q:'$D(%XX(%OVFCNT)) S @%ZISHO=%XX(%OVFCNT)
159 . S %ZISHI=%ZISHI+1
160 . Q
161 D CLOSE() ;Normal exit
162 Q 1
163 ;
164ERREOF D CLOSE() ;Got error Reading file
165 Q 0
166 ;
167READNXT(REC) ;
168 N T,I,X,%
169 U IO R X:2 S %ZA=$ZEOF,REC=$E(X,1,255)
170 Q:$L(X)<256
171 S %=256 F I=1:1 Q:$L(X)<% S REC(I)=$E(X,%,%+254),%=%+255
172 Q
173 ;
174GTF(%ZX1,%ZX2,%ZX3,%ZX4) ;ef,SR. Load contents of global to host file.
175 ;Previously name LOAD
176 ;p1=$NAME of global reference
177 ;p2=incrementing subscript
178 ;p3=host file directory
179 ;p4=host file name
180 N %ZISHY,%ZISHLGR,%ZISHOX
181 S %ZISHY=$$MGTF(%ZX1,%ZX2,$G(%ZX3),%ZX4,"W")
182 Q %ZISHY
183 ;
184GATF(%ZX1,%ZX2,%ZX3,%ZX4) ;ef,SR. Append to host file.
185 ;
186 ;p1=$NAME of global reference
187 ;p2=incrementing subscript
188 ;p3=host file directory
189 ;p4=host file name
190 N %ZISHY
191 S %ZISHY=$$MGTF(%ZX1,%ZX2,$G(%ZX3),%ZX4,"A")
192 Q %ZISHY
193 ;
194MGTF(%ZX1,%ZX2,%ZX3,%ZX4,%ZX5) ;
195 ;p1=$NAME of global reference
196 ;p2=incrementing subscript
197 ;p3=host file directory
198 ;p4=host file name
199 N %ZISH,%ZISH1,%ZISHI,%ZISHL,%ZISHLGR,%ZISHS,%ZISHOX,IO,%ZX,Y
200 D MAKEREF(%ZX1,%ZX2)
201 D OPEN^%ZISH(,%ZX3,%ZX4,%ZX5) ;Default dir set in open
202 I POP Q 0
203 N X
204 N $ETRAP S $ETRAP="S $EC="""" D CLOSE^%ZISH() Q 0"
205 F Q:'($D(@%ZISHF)#2) S %ZX=@%ZISHF,%ZISHI=%ZISHI+1 U IO W %ZX,!
206 D CLOSE() ;Normal Exit
207 Q 1
208 ;
Note: See TracBrowser for help on using the repository browser.