source: WorldVistAEHR/trunk/r/ZZOTHER/ZWR.m@ 813

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

initial load of WorldVistAEHR

File size: 3.4 KB
RevLine 
[613]1ZWR ;DUMP GLOBALS IN ZWR FORMAT
2 ;dump Cache globals to a file in GTM's ZWR format
3 ;mlp 18nov01 New routine
4 ;mlp 07jan02 Update to encode some chars > 127; limit $C args to 256.
5 ; Use LF instead of ! to end lines.
6 ;wb 20Sep02 save each global to a separate file in "/data/" %ZWRSEP
7 ;WB 19OCT03 INTEGRATE $$EXIST FROM EXTERNAL ROUTINE
8 ;wb 04Jan04 Add output directory query
9 ;
10 W !!,"DUMPS GLOBALS IN ZWR FORMAT",!!
11 ; D OUT^%IS Q:$G(IO)="" ;request output dev
12 r !,"Output directory? ",ZOUTDIR
13 D ^%GSET Q:$G(%G)<1 ;request globals to dump
14 ;
15ASK R !!,"Comment ? ",COM,! I COM?1"?".E D G ASK
16 . W "Enter a comment to save with the file. ",!
17 S H=$H,LF=$C(10),QT="""",C255=$C(255),SKIP=$T(SKIP)
18 S GN="" F S GN=$O(^UTILITY(%JO,GN)) Q:GN="" D
19 . S GNN="^"_GN
20 . s IOP=ZOUTDIR_GN_".zwr",IOPAR="WNS"
21 . I SKIP[(";"_GNN_";") w "Skipping ",IOP," - in exclusion set",! Q
22 . i $$exist(IOP) w "Skipping ",IOP," - already exists",! Q
23 . w "Opening ",IOP,!
24 . d OUT^%IS i $G(IO)="" u $p w "error opening "_IOP,! r "Waiting for user...",junk q
25 . U IO
26 . W COM,LF
27 . W "Cache "_$TR($ZD(H,2)," ","-")_" "_$ZT($P(H,",",2))_" ZWR",LF
28 . s cnt=0
29 . D WALK(GNN)
30 . C IO U $P
31 W !,"Done.",!
32 Q
33 ;
34WALK(G) ;walk through global G, convert subscripts and values as necessary, dump out
35 Q:'$D(@G) Q:G["(" ; chk if @G defined, and must be a top-level name
36 I $D(@G)#2 D ; handle case where top-level node has data
37 . S NAME=$NA(@G)
38 . S VAL=$$CGV(@G)
39 . W NAME_"="_VAL,LF
40 F S G=$Q(@G) Q:G="" D ;handle rest of global G
41 . S NAME=$NA(@G)
42 . S NAME=$$RCC(NAME) D
43 . . N P ;Remove initial ""_ or final _""
44 . . S P=$F(NAME,"(") I P,$E(NAME,P,P+2)="""""_" S $E(NAME,P,P+2)=""
45 . . S P=$L(NAME) S:$E(NAME,P-3,P-1)="_""""" $E(NAME,P-3,P-1)=""
46 . S VAL=$$CGV(@G)
47 . W NAME_"="_VAL,LF
48 . s cnt=cnt+1
49 . i cnt#10000=0 u $p w "." u IO
50 Q
51 ;
52RCC(NA) ;Replace control chars in NA with $C( ). Returns encoded string.
53 Q:'$$CCC(NA) NA ;No embedded ctrl chars
54 N OUT S OUT="" ;holds output name
55 N CC S CC=0 ;count ctrl chars in $C(
56 N C ;temp hold each char
57 F I=1:1:$L(NA) S C=$E(NA,I) D ;for each char C in NA
58 . I C'?1C,C'=C255 D S OUT=OUT_C Q ;not a ctrl char
59 . . I CC S OUT=OUT_")_""",CC=0 ;close up $C(... if one is open
60 . I CC D
61 . . I CC=256 S OUT=OUT_")_$C("_$A(C),CC=0 ;max args in one $C(
62 . . E S OUT=OUT_","_$A(C) ;add next ctrl char to $C(
63 . E S OUT=OUT_"""_$C("_$A(C)
64 . S CC=CC+1
65 . Q
66 Q OUT
67 ;
68CGV(V) ;Convert Global Value.
69 ;If no encoding required, then return as quoted string.
70 ;Otherwise, return as an expression with $C()'s and strings.
71 I $F(V,QT) D ;chk if V contains any Quotes
72 . S P=0 ;position pointer into V
73 . F S P=$F(V,QT,P) Q:'P D ;find next "
74 . . S $E(V,P-1)=QT_QT ;double each "
75 . . S P=P+1 ;skip over new "
76 I $$CCC(V) D Q V
77 . S V=$$RCC(QT_V_QT)
78 . S:$E(V,1,3)="""""_" $E(V,1,3)=""
79 . S L=$L(V) S:$E(V,L-2,L)="_""""" $E(V,L-2,L)=""
80 Q QT_V_QT
81 ;
82CCC(S) ;test if S Contains a Control Character or $C(255).
83 Q:S?.E1C.E 1
84 Q:$F(S,$C(255)) 1
85 Q 0
86SKIP ;;^CacheTemp;^ROUTINE;^mtemp;^mtemp0;^mtemp1;^oddCOM;^oddDEF;^oddMAC;^oddMAP;^oddPROC;^rINC;^rOBJ;^%utility;^%UTILITY;^TMP;^XUTL;^UTILITY;
87
88exist(fn)
89 n %
90 s %=$zu(140,4,fn)
91 q (%=0)
92 ;
93
94
95
96
Note: See TracBrowser for help on using the repository browser.