Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: DBAGO

DBAGO.m

Go to the documentation of this file.
  1. DBAGO ;DUMP GLOBALS IN ZWR FORMAT
  1. ;dump Cache globals to a file in GTM's ZWR format
  1. ;mlp 18nov01 New routine
  1. ;mlp 07jan02 Update to encode some chars > 127; limit $C args to 256.
  1. ; Use LF instead of ! to end lines.
  1. ;wb 20Sep02 save each global to a separate file in "/data/" %ZWRSEP
  1. ;WB 19OCT03 INTEGRATE $$EXIST FROM EXTERNAL ROUTINE
  1. ;wb 04Jan04 Add output directory query
  1. ;
  1. W !!,"DUMPS GLOBALS IN ZWR FORMAT",!!
  1. ; D OUT^%IS Q:$G(IO)="" ;request output dev
  1. r !,"Output directory? ",ZOUTDIR
  1. D ^%SYS.GSET Q:$G(%G)<1 ;request globals to dump
  1. ;
  1. ASK R !!,"Comment ? ",COM,! I COM?1"?".E D G ASK
  1. . W "Enter a comment to save with the file. ",!
  1. S H=$H,LF=$C(10),QT="""",C255=$C(255),SKIP=$T(SKIP)
  1. S GN=0 F S GN=$O(^UTILITY("GLO",GN)) Q:GN="" D
  1. . S GNN="^"_GN
  1. . s IOP=GN_".zwr",IOPAR="WNS"
  1. . I SKIP[(";"_GNN_";") w "Skipping ",IOP," - in exclusion set",! Q
  1. . ;i $$exist(IOP) w "Skipping ",IOP," - already exists",! Q
  1. . w "Opening ",IOP,!
  1. . d OPEN^%ZISH("OUTFILE",ZOUTDIR,IOP,"W")
  1. . I POP W !,"Failed to open" Q
  1. . U IO
  1. . W COM,LF
  1. . W "Cache "_$TR($ZD(H,2)," ","-")_" "_$ZT($P(H,",",2))_" ZWR",LF
  1. . s cnt=0
  1. . D WALK(GNN)
  1. . d CLOSE^%ZISH("OUTFILE")
  1. W !,"Done.",!
  1. Q
  1. ;
  1. WALK(G) ;walk through global G, convert subscripts and values as necessary, dump out
  1. Q:'$D(@G) Q:G["(" ; chk if @G defined, and must be a top-level name
  1. I $D(@G)#2 D ; handle case where top-level node has data
  1. . S NAME=$NA(@G)
  1. . S VAL=$$CGV(@G)
  1. . W NAME_"="_VAL,LF
  1. F S G=$Q(@G) Q:G="" D ;handle rest of global G
  1. . S NAME=$NA(@G)
  1. . S NAME=$$RCC(NAME) D
  1. . . N P ;Remove initial ""_ or final _""
  1. . . S P=$F(NAME,"(") I P,$E(NAME,P,P+2)="""""_" S $E(NAME,P,P+2)=""
  1. . . S P=$L(NAME) S:$E(NAME,P-3,P-1)="_""""" $E(NAME,P-3,P-1)=""
  1. . S VAL=$$CGV(@G)
  1. . W NAME_"="_VAL,LF
  1. . s cnt=cnt+1
  1. . i cnt#10000=0 u $p w "." u IO
  1. Q
  1. ;
  1. RCC(NA) ;Replace control chars in NA with $C( ). Returns encoded string.
  1. Q:'$$CCC(NA) NA ;No embedded ctrl chars
  1. N OUT S OUT="" ;holds output name
  1. N CC S CC=0 ;count ctrl chars in $C(
  1. N C ;temp hold each char
  1. F I=1:1:$L(NA) S C=$E(NA,I) D ;for each char C in NA
  1. . I C'?1C,C'=C255 D S OUT=OUT_C Q ;not a ctrl char
  1. . . I CC S OUT=OUT_")_""",CC=0 ;close up $C(... if one is open
  1. . I CC D
  1. . . I CC=256 S OUT=OUT_")_$C("_$A(C),CC=0 ;max args in one $C(
  1. . . E S OUT=OUT_","_$A(C) ;add next ctrl char to $C(
  1. . E S OUT=OUT_"""_$C("_$A(C)
  1. . S CC=CC+1
  1. . Q
  1. Q OUT
  1. ;
  1. CGV(V) ;Convert Global Value.
  1. ;If no encoding required, then return as quoted string.
  1. ;Otherwise, return as an expression with $C()'s and strings.
  1. I $F(V,QT) D ;chk if V contains any Quotes
  1. . S P=0 ;position pointer into V
  1. . F S P=$F(V,QT,P) Q:'P D ;find next "
  1. . . S $E(V,P-1)=QT_QT ;double each "
  1. . . S P=P+1 ;skip over new "
  1. I $$CCC(V) D Q V
  1. . S V=$$RCC(QT_V_QT)
  1. . S:$E(V,1,3)="""""_" $E(V,1,3)=""
  1. . S L=$L(V) S:$E(V,L-2,L)="_""""" $E(V,L-2,L)=""
  1. Q QT_V_QT
  1. ;
  1. CCC(S) ;test if S Contains a Control Character or $C(255).
  1. Q:S?.E1C.E 1
  1. Q:$F(S,$C(255)) 1
  1. Q 0
  1. SKIP ;;^%ZOSF;^CacheTempNodes;^ROUTINE;^TMP;^UTILITY;^XTMP;^XUTL;^mcq;^mterm;^oddDEF;^rINDEX;rINDEXCLASS;^rOBJ;
  1. exist(fn)
  1. n %
  1. s %=$zu(140,4,fn)
  1. q (%=0)
  1. ;