-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils
4194 lines (4132 loc) · 128 KB
/
utils
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
S %I=$I R B X B U 0 C %I D ^%C K ^$R("%C") W !,"Done",! Q
F R R Q:R="" U 0 W R,! U %I K A F I=1:1 R A(I) I A(I)="" M ^$R(R)=A Q
%BLKDMP
%BLKDMP ;Dump a block to $IO formatted
W:$X ! F R "Block No: ",BLK,! Q:'BLK D INT(BLK)
Q
INT(BLK,XX,%,F,I,G,LI,D,BUF,CCC,UCC,K,KET,DATA,ZR) N $ET
;NOTE: If DO INT^%BLKDMP(0,"^GLOB") will set content to ^GLOB
S ZR="INT^%BLKDMP",BUF="",$ET="D EXIT^%BLKDMP"
I BLK V -1:BLK ;Note: BLK=0 means BLK is already in View Buffer
S %=$V(-1,0) I '% W "Block not in use",! V -1:0 G EXIT
I '$D(XX) W "Block: ",$S(BLK:BLK,1:"")," belongs to UCI# ",%#64," "
S F=^$S("VOL",1,"UCI",%#64) I '$D(XX) W:$L(F) "(",F,") "
S D=%\64,G=$&E($V(-1,12,8),"C") I $D(XX),'D G EXIT
I '$D(XX) W $S(D:"data",1:"pointer")," block",!
S:G="$GLOBAL" D=0
I '$D(XX) W "Right: ",$V(-1,4,4)," Global: ",G,! W "Index Contains",!
S LI=$V(-1,8,2)*2,I=20
F D S I=I+2 Q:I>LI
.S F=$V(-1,I,2)*4 I 'F W $J(I,5)_" ..." Q
.S CCC=$V(-1,F+2),UCC=$V(-1,F+3),%=UCC S:%=1!(%=2) %=3 S:%=4 %=5
.S:UCC $E(BUF,CCC+1,999)=$E($V(-1,F+4,%),1,UCC) S K=BUF,F=F+UCC+4
.S KEY="" S:$L(BUF) KEY="(" F S KEY=KEY_$$UNKEY() Q:'$L(K) S KEY=KEY_","
.S:$L(BUF) KEY=KEY_")"
.I '$D(XX) W $J(I,5)_" "_KEY_"="
.I 'D S:F#4 F=F\4+1*4 W:'$D(XX) $V(-1,F,4),! Q
.S K=$V(-1,F,2),F=F+2 I 'K S DATA=""""""
.E D
..I K<5,K'=3 S DA="" F %=1:1:K S DA=DA_$C($V(-1,F+%-1))
..E S DA=$V(-1,F,K)
..S DATA=$$DISP^%U(DA)
.I '$D(XX) W """",DATA,"""",! Q
.S @(XX_KEY_"=DATA")
;---
EXIT I BLK V -1:0 ;Free the GBD if we allocated it
Q
;
UNKEY(C,T,X) I $E(K,1,2)=$C(0,0) S K=$E(K,3,999) Q """"""
;Get string from key - check null
I $A(K)=128 S C=""""_$P($E(K,2,999),$C(0))_"""",K=$P(K,$C(0),2,999) Q C
;Check for a string
S C=$A(K),K=$E(K,2,999)
;Get count
I C=64&'K S K=$E(K,2,999) Q "0"
;Check for "0"
I C<64 S C=63-C,T=$TR($P(K,$C(255)),"0123456789","9876543210"),K=$P(K,$C(255),2,999)
;If it's negative, do the complementing
E S T=$P(K,$C(0)),K=$P(K,$C(0),2,999)
;Extract this (positive) subscript
Q $S(C<64:"-",1:"")_$E(T,1,C#64)_$S($L(T)>(C#64):"."_$E(T,C#64+1,999),1:"")
;Quit with the number
%C
%C ;^%C contents
S ^%C="MCL Version 0.9"
S ^%C("CD")="D CD^%U(CCL)"
S ^%C("CD",1)="Change directory (UCI)"
S ^%C("CLEAR")="W $C(27)_""[H""_$C(27)_""[J"""
S ^%C("CLEAR",1)="Clear the screen."
S ^%C("COPY")="M ^$R($P(CCL,"" "",2))=^$R($P(CCL,"" ""))"
S ^%C("COPY",1)="Copy fromrou torou"
S ^%C("DCHANGE")="D INT^%DED(CCL)"
S ^%C("DCHANGE",1)="Edit a document using your favourite editor."
S ^%C("DDIRECT")="D INT^%DD(CCL)"
S ^%C("DDIRECT",1)="Obtain a Document Directory"
S ^%C("DELETE")="D DEL^%RD(CCL,SW)"
S ^%C("DELETE",1)="Delete [/NOQuery] routine spec"
S ^%C("DIRECTORY")="X ^%C(""RDIRECTORY"")"
S ^%C("DIRECTORY",1)="Obtain a list of routines - same as RDIRECTORY."
S ^%C("DSCAN")="D INT^%DED(CCL,1)"
S ^%C("DSCAN",1)="Scan a document - read only"
S ^%C("DUMP")="D INT^%BLKDMP(CCL)"
S ^%C("DUMP",1)="Dump a block (formatted)"
S ^%C("EDIT")="D INT^%ED(CCL)"
S ^%C("EDIT",1)="Edit a routine using your favourite editor."
S ^%C("ERROR")="D ^%ETDISP"
S ^%C("ERROR",1)="Display logged errors."
S ^%C("EXIT")="internal %M command"
S ^%C("EXIT",1)="Exit from MCL to either M> or shell."
S ^%C("GDIRECTORY")="D INT^%GD(0,CCL)"
S ^%C("GDIRECTORY",1)="Global Directory spec"
S ^%C("GEFFICIENCY")="D INT^%GE(CCL)"
S ^%C("GEFFICIENCY",1)="Display storage efficiency of a global."
S ^%C("GRESTORE")="D INT^%GR(CCL)"
S ^%C("GRESTORE",1)="Global restore filename"
S ^%C("GSAVE")="D INT^%GS($P(CCL,"" ""),$P(CCL,"" "",2),$P(CCL,"" "",3,99))"
S ^%C("GSAVE",1)="Global Save spec filename header text"
S ^%C("HELP")="internal %M command"
S ^%C("HELP",1)="This text is displayed."
S ^%C("LIST")="D INT^%GL(CCL,SW)"
S ^%C("LIST",1)="List global /D=data only, /L=max level, /M=max lines"
S ^%C("OS")="S:CCL="""" CCL=""exec $SHELL"" S %=$&%SPAWN(""stty onlcr""_$C(59)_CCL_$C(59)_""stty -onlcr"")"
S ^%C("OS",1)="Execute O/S (unix) command - shell"
S ^%C("RDIRECTORY")="D INT^%RD($S(SW[""L"":1,SW[""U"":2,1:0),CCL)"
S ^%C("RDIRECTORY",1)="Routine Directory /FL (first line) or /FU (full) spec"
S ^%C("ROUCHECK")="D RC^%RD(CCL)"
S ^%C("ROUCHECK",1)="Check the compile syntax on routine_spec."
S ^%C("RRESTORE")="D INT^%RR(CCL)"
S ^%C("RRESTORE",1)="Routine restore filename"
S ^%C("RSAVE")="D INT^%RS($P(CCL,"" ""),$P(CCL,"" "",2),$P(CCL,"" "",3,99))"
S ^%C("RSAVE",1)="Routine Save spec filename header text"
S ^%C("SCAN")="D INT^%ED(CCL,1)"
S ^%C("SCAN",1)="Scan a routine - read only"
S ^%C("SHOW")="D INT^%SS(CCL)"
S ^%C("SHOW",1)="Show LOCKS, SYS or job#"
S ^%C("STATUS")="D INT^%STA(CCL)"
S ^%C("STATUS",1)="Show system statistics, specify interval, eg. STA 15"
S ^%C("SYSTAT")="D ^%SS"
S ^%C("SYSTAT",1)="Obtain a system status."
S ^%C("TYPE")="D 0^%TYP(CCL)"
S ^%C("TYPE",1)="Type out a routine (like more)."
%D
%D ;Convert %D to printable date
S:$D(%D)#2=0 %D=+$H S %D=$$D(%D) Q
D(D,M,Y,ZR) S ZR="D^%D" I D<1!(D>423316) Q ""
S:D>21608 D=D+1 S M=1,Y=D\1461*4+1841,D=D#1461
S:'D D=1461,Y=Y-4 F %=1:1:3 Q:D<366 S Y=Y+1,D=D-365
F %=31,28+(Y#4=0),31,30,31,30,31,31,30,31,30,31 Q:D'>% S M=M+1,D=D-%
S M=$P("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",",",M)
Q $TR($J(D,2)," ",0)_" "_M_" "_Y
%DD
%DD ;Do a document directory
D INT(".E") Q
INT(PAT,ST,END,G,%,%D,%V,F,R,ZR) S ZR="INT^%DD"
S FL=$G(FL),PAT=$G(PAT,".E")
S:PAT="" PAT=".E" I $E(PAT)'=".",$E(PAT)'?1N S PAT=$$PAT^%U(PAT)
W "Document Directory matching '"_PAT_"'.",!! S R=" "
F ST=0:1 S R=$O(^%D(R)) Q:R="" I R?@PAT D
.W R,?30 S END="" S:R["." END=$&E($P(R,".",$L(R,".")))
.S %D=^%D(R),%V=0 F Q:'$O(^%D(%D,%V)) S %V=$O(^(%V))
.S F=0,%=0 I END="JPG"!(END="GIF")!(END="CLASS") D Q
..F S %=$O(^%D(%D,%V,%)) Q:'% S F=F+$L(^(%))
..W $J(F,10)," bytes",!
.F F=0:1 S %=$O(^%D(%D,%V,%)) Q:'%
.W $J(F,10)," lines",!
Q
%DED
%DED ;Edit a document using $EDITOR
R !,"Document: ",DOC,! Q:DOC="" D INT(DOC) Q
INT(DOC,RO,FILE,F,UI,%D,%V,%L,%,ZR) S ZR="^%DED",RO=$G(RO) I $G(DOC)="" Q
S %D=$G(^%D(DOC)) G CONT:%D
;Get the index, continue if OK
S %D=$O(^%D(" "),-1)+1,^(%D,0)=DOC,^(1,1)="",^%D(DOC)=%D
;Create if it doesn't exist
CONT S %=$O(^%D(%D,0)),%V=$O(^(%)) I '%V S %V=%+1 D
;Look for a version
.S %1=0 F %L=1:1 S %1=$O(^%D(%D,%,%1)) Q:'%1 S ^%D(%D,%V,%L)=^%D(%D,%,%1)
;.Create a new version
I 'RO L +^%D(%D):1 E W !,"?Can't lock document "_DOC,! Q
;Attempt to lock if reqd
S UI=$$UI^%U(),FILE=DOC_"."_UI O 1:(FILE:"W")
;Setup the file name
I 'RO U 1 W "Editing "_DOC,!,"Remove above to NOT save document.",! U 0
S %=0 U 1 F S %=$O(^%D(%D,%V,%)) Q:'% W ^(%),!
U 0 C 1
S F=$&%GETENV("EDITOR") S:F="" F="vi" S F=F_" "_FILE
I $E(F)="x",RO S F=F_"&"
I $P(F," ")="vi" S F="stty onlcr;"_F_";stty -onlcr"
S %=$&%SPAWN(F)
I RO H 4 O 1:(FILE:"W") C 1 Q
W !,"Saving edit...",!
O 1:(FILE:"R") U 1 R F,% U 0
I "Editing "_DOC'=F W "Edit NOT saved!",! G EXIT
U 1 S %V=%V+1 F %L=1:1 R F Q:$A($K)=255 S ^%D(%D,%V,%L)=F
;Save the data
S %V=$O(^%D(%D,""),-1),%V=$O(^(%V),-1) I %V S %=$O(^(%V),-1) I % K ^(%)
;Remove an old version - done
EXIT U 0 C 1 O 1:(FILE:"W") C 1 L -^%D(%D) Q
%ED
%ED ;Edit a routine using $EDITOR
R !,"Routine: ",ROU,! Q:ROU="" D INT(ROU) Q
INT(ROU,RO,UI,FILE,F,%,ZR) S ZR="^%ED",RO=$G(RO) I $G(ROU)="" Q
G CONT:ROU?1A.7AN,CONT:ROU?1"%".7AN&(^$J($J,"ROUTINE")=1) Q
CONT I 'RO L +^$R(ROU):1 E W !,"?Can't lock routine "_ROU,! Q
I RO,'$D(^$R(ROU)) W !,"?No such routine "_ROU,! Q
S UI=$$UI^%U(),FILE=ROU_"."_UI O 1:(FILE:"W")
I 'RO U 1 W "Editing "_ROU,!,"Remove above to NOT save routine.",!,ROU,! U 0
I '$D(^$R(ROU)) W !,"Creating routine "_ROU,! U 1 W ROU_" ;New routine",!
E S %=0 U 1 F S %=$O(^$R(ROU,%)) Q:'% W ^$R(ROU,%),!
W !! U 0 C 1
S F=$&%GETENV("EDITOR") S:F="" F="vi" S F=F_" "_FILE
I $E(F)="x",RO S F=F_"&"
I $P(F," ")="vi" S F="stty onlcr;"_F_";stty -onlcr"
S %=$&%SPAWN(F)
I RO H 4 O 1:(FILE:"W") C 1 Q
W !,"Saving edit...",!
O 1:(FILE:"R") K ^UTILITY(UI) U 1 R F,%,% U 0
I "Editing "_ROU'=F W "Edit NOT saved!",! G EXIT
U 1 F %=1:1 R ^UTILITY(UI,%) Q:^UTILITY(UI,%)="" Q:$A($K)=255
M ^$R(ROU)=^UTILITY(UI) K ^UTILITY(UI)
EXIT U 0 C 1 O 1:(FILE:"W") C 1 L -^$R(ROU) Q
%ET
%ET ;MUMPS V1 Error Trapper
N $ET S $ET=""
;Don't error trap in here
K ZZ S ZZ("$T")=$T,ZZ("$ECODE")=$E($EC,1,255) I '$D(ZF(1)) D
;Save $Truth and $EC - If we don't have a file, get it
.S ZZ("$H")=$H,ZZ("$I")=$I,ZZ("$J")=$J,ZZ("$P")=$P,ZZ("$X")=$X,ZZ("$Y")=$Y,ZZ("$R")=$R
;.Store permanent junk
.L +^ERT S ZF(1)=$G(^ERT)+1,^ERT=ZF(1) L -^ERT
;.Get next number
.S ZF(1)="^ERT("_ZF(1)_",",ZZ=$P(ZZ("$ECODE"),",",2)
;.Setup the global ref
.I $L(ZZ) S ZZ("$ZE")=$&%ERRMSG(ZZ)
;.Set '$ZE' as reason
S ZZ("$STACK")=$ST-1,ZZ("$STACK(-1)")=$ST(-1),ZZ("$ESTACK")=$ES-1
;Command stack. Store current context and maximum (or current) context level
S ZF(2)=ZZ("$STACK")
;Save here too
S ZZ("$STACK("_ZF(2)_")")=$ST(ZF(2))
;Store $STACK($STACK)
S ZF(1)=$P(ZF(1),",")_","_ZZ("$ESTACK")_")" M @ZF(1)=ZZ K ZZ S ZF=$&%ZWRITE(ZF(1))
;Save where we are up to
F ZZ="PLACE","MCODE","ECODE" S ZZ("$"_ZZ_"()")=$ST(ZF(2),ZZ)
;Store remaining information
S ZZ=$P($P($ST(ZF(2),"PLACE"),"^",2)," ") D
;Get the routine name
.I $L(ZZ) S ZZ="+1^"_ZZ,ZZ("$ROUTINE")=$T(@ZZ)
;.Try to get the first line
.I '$L($QS(ZZ("$R"),$QL(ZZ("$R")))) Q
;.Quit if last subscript null
.S ZZ("$D(@$R)")=$D(@ZZ("$R")) I ZZ("$D(@$R)")#2 S ZZ("@$R")=@ZZ("$R")
;.Get extra $R information
I $E(ZF(1))="^" M @ZF(1)=ZZ K ZZ
;If MUMPS, save some more of this
Q
;Quit leaving $EC set
ZT S $EC="" Q
;The final Trap entry point - clear $ECODE and exit
%ETDISP
%ETDISP ;MUMPS V1 Error Display
N CS,QV,G,ZR,TER,$ET S ZR="^%ETDISP",$ET="D Z^%ET"
;Save Command Stack, locks etc - set errortrap to do nothing
S EG="^ERT"
W !,?10,"MUMPS Version 1 - Error display utility",!!
I '$G(@EG) S %=$O(@EG@("Z"),-1) I % S @EG=%
;Check for transfered errors
I '$G(@EG) K @EG W ?20,"No errors recorded.",! Q
;Check for any errors
S %="" F N=0:1 S ER=%,%=$O(@EG@(%)) Q:'%
I 'N K @EG W ?20,"No errors recorded.",! Q
G D1:N=1 W N_" error"_$S(N>1:"s",1:0)_" recorded.",!
ER R "Err#: ",ER W ! Q:ER?1A.E
I ER="?"!(ER="HELP") D G ER
.W ! S ER="" F S ER=$O(@EG@(ER)) Q:'ER D S1
.W ?4,"Enter error number, <Return> for last error, E to EXIT.",!
.W ?4,"/D to delete the entire error trap global and exit.",!!
I $&E(ER)="/D" K @EG W !,"deleted...",! Q
;Check for a global /D
I ER="" S ER=$O(@EG@("z"),-1) S:ER="" ER=" "
I '$D(@EG@(ER)) W "?No such error number.",! G ER
;------------------------------------------------------------------------------
D1 W ! D S1
;Display 1 error passed in ER
W $G(@EG@(ER,TER,"$ROUTINE")),!,$G(@EG@(ER,TER,"$MCODE()")),!
;Say what
DV W:$X ! R "Variable: ",V W !
S V=$&E(V) I $E(V,1,2)="/D" D S V="/D"
.S ERR=$G(@EG@(ER,TER,"$EC"))_": "_$P($G(^("$ZE")),",",1,2)
;.Fetch the current $ZE for the /A switch
.K @EG@(ER) I V["/A" S %=0 F S %=$O(@EG@(%)) Q:'% D
..S %1=$O(@EG@(%,"z"),-1) I '%1 K @EG@(%) Q
;..Get Top ERror - just dong if no such
..I $G(@EG@(%,%1,"$EC"))_": "_$P($G(^("$ZE")),",",1,2)=ERR K @EG@(%)
;.Dong it - then dong all the same if /A specified
.K:'$O(@EG@(0)) @EG Q
;.If there are no errors left, dong the whole thing - unlock and quit
I V="/D" S ER=$O(@EG@(ER),-1) S:'ER ER=$O(^(0)) Q:'ER G D1
;See if there are more errors
Q:ER="EXIT" G ER:V=""
I V="HELP" W ! D G DV
.W ?5,"Enter variable to display. Wild card characters ? and * may be used.",!
.W ?5,"/D to delete error, /D/A to delete all of this type.",!
.W ?5,"Press <Return> for 'Err#:' prompt.",!
.W ?5,"*$R* will display all information about the last global reference.",!
.W ?5,"$ST* will display the call stack.",!
.W ?5,"<Help> or HELP for help. EXIT to exit.",!
.W ?5,"To examine variables HELP and EXIT, use HEL? and EXI? respectively.",!!
S PAT="" I V'["?",V'["*" D V1 G DV
F %=1:1:$L(V) S F=$E(V,%),PAT=PAT_$S(F="*":".E",F="?":"1E",F="""":"1""""""""",1:"1"""_F_"""")
;go through supplied Pattern char by char and treat ?*" specially
S V="" F S V=$O(@EG@(ER,TER,V)) G DV:V="" I V?@PAT D V1
;Scan all variables at Top ERror
V1 W V,?9," = ",$S($D(@EG@(ER,TER,V)):$$CC(^(V)),1:"<UNDEF>"),!
;Write out this level
F %=TER-1:-1:0 I $D(@EG@(ER,%,V)) W " @ lev-",%,?9," = ",$$CC(@EG@(ER,%,V)),!
;Display at other levels
Q
D0 W !?10,"No "_$S(%=89:"previous",1:"next")_" error - select by number.",!
G ER
;------------------------------------------------------------------------------
CC(D,F,%,X) I D?.E1C.E S D=$$DISP^%U(D)
Q """"_D_""""
;------------------------------------------------------------------------------
S1 S TER=$O(@EG@(ER,"z"),-1),%DT=$G(@EG@(ER,TER,"$H"))
;Summarise the error in ER
W $J(ER,3),?4,$$D^%D(+%DT)_" "_$$T^%T($P(%DT,",",2)),?25
S %=$G(@EG@(ER,TER,"$ECODE"))_": "_$G(^("$ZE")) W $E(%,1,55),! Q
%G
%G ;Global Extended Lister [ 06/09/2018 13:37 PM ]
N ;General Stack
S $ET="D ERR^%G" F D RGLB Q:%G="" W ! D GO
EXIT W ! Q
ERR S ER=$P($EC,",",2) W !,"Error: ",ER," ",$&%ERRMSG(ER),! S $EC="" Q
GO S $ET="D ERR^%G",%HN=%N I %HN?1"^[".E S %HN="^"_$P(%HN,"]",$L(%HN,"]"))
S HGDIFF=$L(%N)-$L(%HN),LWLH=0,LWLEV=0,LWLENG=0
I '%M,%N_"("=%G,$D(@%N)'=10 W %HN W !,@%N,!
I $O(@%N@(""))="" Q
S SHOLEV=%L-(%E>1),GREF=%N_"(",HREF=%HN_"(" D CHILDREN(1) Q
CHILDREN(LEV) N LENGTH,SUBSCR,Z ;Stack Important !
S $ET="D ERR^%G"
S LENGTH=$L(GREF),SUBSCR=$S(LEV'>%L:%B(LEV),1:"")
I SUBSCR'="",$D(^(SUBSCR))
E S SUBSCR=$O(^(SUBSCR))
F Q:$$PASTEND D ACHILD I SUBSCR'="" S SUBSCR=$O(^(SUBSCR))
Q
ACHILD S $ET="D ERR^%G"
S Subs=$$QS(SUBSCR),GREF=GREF_Subs,HREF=HREF_Subs,%D=$D(^(SUBSCR))
I LEV>SHOLEV,(%D'=10)!(%E=2) D SHOWREF W:%D=10 "pointer" W:%D'=10 "="_^(SUBSCR) W !
I %D>9,(%E'=2)!(LEV<%L) D DESCEND
S GREF=$E(GREF,1,LENGTH),HREF=$E(HREF,1,LENGTH-HGDIFF)
S:LEV'>%M SUBSCR="" Q
PASTEND() I SUBSCR="" Q 1
I LEV>%L Q 0
I %C(LEV)="" Q (%B(LEV)'="")&(%B(LEV)'=SUBSCR)
I SUBSCR=%C(LEV) Q 0
I SUBSCR'["E",SUBSCR=+SUBSCR G GSE
I %C(LEV)'["E",%C(LEV)=+%C(LEV) Q 1
Q SUBSCR]%C(LEV)
GSE I %C(LEV)'["E",%C(LEV)=+%C(LEV) Q SUBSCR>%C(LEV)
Q 0
SHOWREF ; Show global reference (KEY)
I LWLEV=LEV W ?LWLH-$L(HREF)+LWLENG,$E(HREF,LWLENG+1,999)
E W HREF S LWLH=$L(HREF),LWLEV=LEV
W ")" S LWLENG=LENGTH-HGDIFF Q
DESCEND S GREF=GREF_",",HREF=HREF_",",DUMMY=$O(^(SUBSCR,""))
D CHILDREN(LEV+1) S DUMMY=$O(@($E(GREF,1,$L(GREF)-1)_")"))
S LWLEV=0,LWLENG=0 Q
QS(STR) S oet=$ET,$ET="qserr^%G"
I STR'["E",STR=+STR Q STR
notcn S $ET=oet,TEMP=STR,STR=""
F PIECE=1:1:$L(TEMP,"""") S STR=STR_""""""_$P(TEMP,"""",PIECE)
S STR=$E(STR,3,999)
Q """"_STR_""""
qserr S $EC="" G notcn
;READ Global KEY-Mask...
;======================================================
RGLB F D READ Q:%G="" Q:%M'<0
Q
READ R !,"Global ^",%G Q:%G="" I %G="?" D ^%GD S %M=-2 Q
D PROC I %M=-2 W *7," [Invalid global reference]" Q
D GDEF I %M=-2 W *7," [Invalid global reference]" Q
GDEF S $ET="DERR^%G" I '$D(@%N) W " ???" S %M=-2
Q
DERR S ER=$P($EC,",",2) W:$&%ERRMSG(ER)'["<SYNTAX>" !,$EC S %M=-2,$EC="" Q
PROC I $E(%G)'="^" S %G="^"_%G
S %F=0 I %G?1"^(".E Q
S %F=2 I %G'["(" S %G=%G_"("
I %G?.E1"," S %E=1
E I %G?.E1")" S %E=2,%G=$E(%G,1,$L(%G)-1)_","
E S %E=3
I '%F S %M=-2 Q
K %B,%A S %X=$P(%G,"(",2,256) S %N=$P(%G,"("),%NFULL=%N
S %GLO=$P(%N,"^",2,$L(%N,"^")) D R Q
R S %M=1,%B=1,%L=0,%P=0 G RT:%X=""
RRR S %A="" I $E(%X,%M)="," S %X=$E(%X,1,%M-1)_""""""_$E(%X,%M,999)
RR I $E(%X,%M)="""" F %I=1:1 S %M=%M+1 Q:%M>$L(%X) I $E(%X,%M)="""" S %M=%M+1 G RR
I $E(%X,%M)="(" S %P=%P+1,%M=%M+1 G RR
I $E(%X,%M)=")",%P S %P=%P-1,%M=%M+1 G RR
I ":,)"'[$E(%X,%M),$E(%X,%M)'?1C S %M=%M+1 G RR
I $E(%X,%M)?1P,%P S %M=%M+1 G RR
I $E(%X,%M)=":" G RE:%A]"" S %A=1_$E(%X,%B,%M-1),%M=%M+1,%B=%M G RR
I $E(%X,%M)'=",",$E(%X,%M)'=")",$E(%X,%M)]"" G RE
S %L=%L+1,%B(%L)=$E(%X,%B,%M-1),%M=%M+1,%B=%M
D S Q:%M=-2 G RRR:%M'>$L(%X)
RT F %I=1:1:%L Q:%B(%I)=""!(%C(%I)]"")
S %M=%I-1 Q
RE S %M=-2 Q
S S %C(%L)="" I %A]"" DO G S1
.D S1 S %C(%L)=$S(%B(%L)]"":%B(%L),1:$C(255,255)),%B(%L)=$E(%A,2,999)
S1 I %B(%L)'["E",%B(%L)=+%B(%L) Q
I %P=1,%E=2,%M'<$L(%X) DO
.S:%B(%L)?.E1"," %B(%L)=$E(%B(%L),1,$L(%B(%L))-1),%M=%M-1
.S %E=3,%B(%L)=%B(%L)_")"
Q:%B(%L)=""
S $ET="S1ERR^%G" I %B(%L)["%" N %A,%C,%D,%E,%F,%G,%I,%M,%N,%P,%X,%ZT
S @("%B(%L)="_%B(%L)) Q
S1ERR S ER=$P($EC,",",2) W " "_$P($&%ERRMSG(ER),">")_"> in ",%B(%L) S %M=-2,$EC="" Q
%GD
%GD ;Do a global directory for current uci
D INT(0,".E") Q
INT(FL,PAT,UCI,ST,END,G,%,F,L,ZR) S ZR="INT^%GD"
S FL=$G(FL),PAT=$G(PAT,".E"),UCI=$G(UCI,^$J($J,"GLOBAL"))
S:PAT="" PAT=".E" I $E(PAT)'=".",$E(PAT)'?1N S PAT=$$PAT^%U(PAT)
S ST=$G(ST),END=$G(END,"z"),L=ST I UCI S UCI=^$S("VOL",1,"UCI",UCI)
I FL=3,'$D(G) S G="SEL"
I FL-3 W "Global Directory of ["_UCI_"] matching '"_PAT_"'.",!!
F S L=$O(^[UCI]$G(L)) Q:L=""!($E(L)]END) I L?@PAT D
.I 'FL W:$X>70 ! W L,?$X\10+1*10 Q
.I FL=3,$E(L)'="$" S @G@(L)=""
Q
%GE
%GE ;Global efficiency
R !,"Global: ^",G,! Q:G="" D INT(G) Q
INT(G,%,UCI,B,NB,ALL,FRE,L,TA,TU,SIZ,ISD,ZR) S ZR="INT^%GE"
S G=$TR(G,"^"),UCI="",A=0,SIZ=^$S("VOL",1,"BLOCK")
I G["]" S UCI=$P(G,"]")_"]",G=$P(G,"]",2)
S %="^"_UCI_"$GLOBAL("""_G_""")",TA=0,TU=0
I '$D(@%) W "Global ^",UCI,G," does not exist",! Q
S B=@% W "Global efficiency for ^",UCI,G," (",B,")",!
F L=1:1 V -1:B S ISD=$V(-1,0)>64 D Q:ISD S B=NB
;Get all levels
.I 'ISD S %=$V(-1,20,2)*4+2,%=$V(-1,%+1)+2+% S:%#4 %=%\4+1*4 S NB=$V(-1,%,4)
.W "Level",$J(L,3),": " S FRE=0
.F ALL=0:1 Q:'B V -1:B S B=$V(-1,4,4),FRE=$V(-1,10,2)*2+1-$V(-1,8,2)*2+FRE
.S ALL=ALL*SIZ,FRE=ALL-FRE W $J(FRE,8)," bytes used of ",$J(ALL,8)
.W $J(FRE/ALL*100,7,2),"%",! S TA=TA+ALL,TU=TU+FRE
W "Total: ",$J(TU,8)," bytes used of ",$J(TA,8),$J(TU/TA*100,7,2),"%",!
Q
%GL
%GL ;List global
R "Global: ",CCL,! Q:CCL="" D INT(CCL,"/M") Q
INT(CCL,SW) S GL=CCL I CCL["/" S Q=0 D
.F %=1:1:$L(CCL) S:$E(CCL,%)="""" Q='Q I 'Q,$E(CCL,%)="/" S SW=$G(SW)_$E(CCL,%,999),GL=$E(CCL,1,%-1)
I $E(GL)'="^" S GL="^"_GL
I $P(GL,"(")["$" W "?Can't list an SSVN",! Q
S STOP=$E(GL,$L(GL))=")" S:STOP GL=$E(GL,1,$L(GL)-1)
S F=$P(GL,"(",2,999),GL=$P(GL,"(")_$S(GL["(":"(",1:""),Q=0 G NA:F=""
I $E(F)'="""" S GL=GL_""""
F %=1:1:$L(F) D
.I $E(F,%)="""" S Q='Q,GL=GL_"""" Q
.I $E(F,%)'=","!Q S GL=GL_$E(F,%) Q
.S GL=GL_$S($E(F,%-1)="""":"",1:"""")_","_$S($E(F,%+1)="""":"",1:"""")
S:$E(GL,$L(GL))'="""" GL=GL_"""" S GL=GL_")"
NA S GL=$NA(@GL,999)
S NS=$QL(GL),LS=$QS(GL,NS),L1="" S:NS L1=$NA(@GL,NS-1)
S MAX=100,LEV=999,DO=0,NC=0
I SW["/D" S DO=1
I SW["/L" S LEV=+$E($P(SW,"/L",2),2,99)
I SW["/N" S NC=1
I SW["/M" S MAX=+$E($P(SW,"/M",2),2,99)
S CNT=0 I $D(@GL)#10 W GL,"=",@GL,! S CNT=1
;
F S GL=$Q(@GL) Q:GL="" D Q:STOP>1
.I STOP,$NA(@GL,NS-1)'=L1!($QS(GL,NS)]]LS) S STOP=2 Q
.Q:$QL(GL)>LEV
.S F=@GL S:F?.E1C.E&'NC F=$$DISP^%U(F) W:'DO GL,"=" W F,!
.S CNT=CNT+1 I CNT=MAX S STOP=2
W:CNT=MAX "** "_MAX_" nodes printed **",! Q
%GR
%GR ;Global Restore from file
R "Restore from file: ",FILE,! Q:FILE=""
D INT(FILE,0) Q
INT(FILE,NOSAY,%,G,S,ZR) N $ET S ZR="INT^%GR",NOSAY=$G(NOSAY),$ET="D EX^%GR"
O 1:(FILE:"R") U 1 R G,% U 0 S G=$TR(G,$C(13)),%=$TR(%,$C(13))
I NOSAY<2 W !,G,!,%,!
I 'NOSAY R "Restore N> ",%,! I $E($&E(%))'="Y" C 1 W "ABORTED",! Q
U 1 F R G,% S G=$TR(G,$C(13)),%=$TR(%,$C(13)) Q:$E(G)="*" D Q:$A($K)=255
.S @G=% I NOSAY<2 U 0 W:$X>70 ! W G,?$X\10+1*10 U 1
.F R S,% S S=$TR(S,$C(13)),%=$TR(%,$C(13)) Q:$E(S)="*" S:$E(S)="^" G="" S @(G_S)=%
EX U 0 W:NOSAY<2 ! C 1 Q
%GS
%GS ;Global Save
R !,"Global(s): ",GLO Q:GLO=""
R !,"Filename: ",FILE G %RS:FILE=""
R !,"Header Txt: ",HEAD,! S:HEAD="" HEAD=GLO
D INT(GLO,FILE,HEAD) Q
INT(GLO,FILE,HEAD,%,VOL,UCI,G,ZR) N $ET S ZR="INT^%GS",$ET="D EX^%GS"
S HEAD=$G(HEAD,GLO)
S UI=$$UI^%U() K ^UTILITY(UI) S GLO=$$PAT^%U(GLO)
D INT^%GD(3,GLO,^$J($J,"GLOBAL"),"","z","^UTILITY("_UI_")")
I $O(^UTILITY(UI,""))="" W !,"?No globals selected.",! Q
S %=^$J($J,"GLOBAL_VOL"),VOL=^$S("VOL",%,"NAME")
S UCI=^$S("VOL",%,"UCI",^$J($J,"GLOBAL"))
O 1:(FILE:"W") U 1 W "Saved by %GS from ["_UCI_","_VOL_"] on "
W $$D^%D($H)," at ",$$T^%T($P($H,",",2)),!,HEAD,!
S GLO="" F S GLO=$O(^UTILITY(UI,GLO)) Q:GLO="" S G="^"_GLO D
.U 0 W:$X>70 ! W GLO,?$X\10+1*10 U 1
.W G,!,$G(@G),! F S G=$Q(@G) Q:G="" W "("_$P(G,"(",2,999),!,@G,!
.W "*",!,"*",!
W "**",!,"**",! U 0
EX C 1 W ! Q
%LCSEND
%LCSEND ;Local Controller - Send to ONE ; V 3.0 29 Sep 2004 07:09 AM
L +^%LC("sender"):1 E H
;Ensure we are the only copy running
S $ET="D ^%2ET",U="|",^$J($J,"OWNER_ID")=1023,%=$$USER^%0SYUSER,JOB=$J
;Set current user to ONE
;;;
%LCSRV
%LCSRV ;Local Controller ; V 3.0 28 Sep 2004 11:58 AM
L +^%LC("server"):1 E H
;Ensure we are the only copy running
S $ET="D ^%2ET",U="|",^$J($J,"OWNER_ID")=1023,%=$$USER^%0SYUSER,JOB=$J
;Set current user to ONE
S NOS=^$J/2
;Get number of servers to use
S PORT4=1948,NOS="S="_NOS F S PORT=13 C PORT D Q:PORT
.N $ET S $ET="D ERROR^%LCSRV" O PORT:(PORT4:NOS) U PORT:("TERMINATOR="_$C(10))
;Open our port in server mode - ensure the terminator is <LF>
;---
LOOP U PORT R CMD
;Get a command, which should be of the form:
;444[4][4],username
I $J=JOB W "No ports available",! H 1 U PORT:("DISCONNECT") G LOOP
;Check for no server slots - quit if none
I $E(CMD,1,3)-444 H
;Someone is trying to spoof us
G ^%LCSRV0
;------------------------------------------------------------------------------
ERROR Q:$EC'["Z248" S $EC="",PORT=0 H 60 Q
;allow for the "Address already in use" error
%LCSRV0
%LCSRV0 ;Local Controller - Individual ; V 3.0 29 Sep 2004 10:31 AM
I $G(^DEBUG) S %=$O(^DEBUG(""),-1)+1,^DEBUG(%)="In: "_CMD
;Check for logging
I ^$S("VOL",1,"WRITELOCK") W "NO Disk locked",! H 1 H
;Disconnect if disk is write locked
S %=$G(^%AUTH("NOLOGIN")) I $L(%) S:$P(%," ")'="NO" %="NO "_% W %,! H 1 H
;Check for no logins
S USR=$P(CMD,",",2),FROMIP=$P($P($D,",",3)," "),U="|"
;Extract some variables
I FROMIP'?1"10.10.10."1N W "NO Invalid...",! H 1 H
;If it's not a valid machine
L +^%LC("user",USR):1 E W "NO Already logged in",! H 1 H
;Check to see if already there
S ^%LC("user",$J)=USR_U_FROMIP,WHOAMI=USR_"@"_^$S("VOL",1,"NAME")
;Save the name here and here
;
;; CONNECT TO ONE GOES HERE???
;
LOOP R CMD:3600 E K ^%LC("user") H
;Live only for an hour
I $G(^DEBUG) S %=$O(^DEBUG(""),-1)+1,^DEBUG(%)="In: "_CMD
;Log it if required
S C=$P(CMD," ") I C="LOGOUT" K ^%LC("user") H
;Done
G GET:C="GET",READ:C="READ",WRIT:C="WRITE"
;Dispatch on command
I "|MODIFY|CREATE|ADDNOTES|ASSIGN|REFUND|RECEIVE|"[(U_C_U) G SAVE
;The 'update' commands
W "NO Invalid command sent",! H 1 G LOOP
;or complain
;------------------------------------------------------------------------------
GET G PARAM:$P(CMD," ",2)="PARAMETERS",NOTES:$P(CMD," ",2)="NOTES"
G KEY:$P(CMD," ",2)="CUSTOMER",DEVLST:$P(CMD," ",2)="DEVICE"
I $P(CMD," ",2)'?1.N W "NO Invalid request received",! H 1 G LOOP
;
READ ;
WRIT ;
SAVE L +^%LC("z"):2 E W "NO System failure!!!",! H 1 G LOOP
S ^("z")=^("z")+1,N=^("z") L -^%LC("z")
S ^("z",N)=CMD,^(N,0)=WHOAMI W "OK",! G LOOP
;------------------------------------------------------------------------------
PARAM ;
NOTES ;
KEY ;
DEVLST ;
%LPC
%LPC ;WAA-Longitudinal Parity Check ; 15-June-2000
;;%LPC Version 1.0
LRC(DATA) ; Main Entry point
N I,X,CHAR,COUNT,ARRAY,LONGSUM,BITE,LBITE
S X=0
F I=1:1:$L(DATA) S CHAR=$E(DATA,I),CHAR=$A(CHAR),CHAR=$$CKBYTE(CHAR),ARRAY(I)=CHAR
F I=8:-1:1 D
. N J,CNT
. S J=0,CNT=0
. F S J=$O(ARRAY(J)) Q:J<1 D
.. S CNT=CNT+$E(ARRAY(J),I)
.. Q
. S COUNT(I)=(CNT#2)
. Q
F I=1:1:7 I COUNT(I) S X=X+$S(I=1:64,I=2:32,I=3:16,I=4:8,I=5:4,I=6:2,I=7:1,1:0)
Q X
CKBYTE(X) ; convert to byte and checkbit
N Y,I,CK
S Y="",CK=0
S Y=$$BYTE(X)
F I=7:-1:1 I $E(Y,I) S CK=CK+1
S Y=Y_('(CK#2))
Q Y
BYTE(Y) ; convert to byte
N BYTE
S BYTE=""
D LOOP
Q BYTE
LOOP ; main loop to convert to bit
N BIT
I Y=0 Q
S BIT=Y#2
S BYTE=BIT_BYTE
I BIT=0 S Y=Y/2
I BIT=1 S Y=Y\2
G LOOP
%M
%M ;The MUMPS Command Language
S $EC="",$ET="" K CS
S WID="TERMINATOR="_$C(1,2,4,5,6,7,9,10,11,12,13,14,15,16,18,20)
S WID=WID_$C(21,22,23,24,25,26,28,29,30,31)
U 0:("CONTROLC":"DELETE=BOTH":"ESCAPE":"ECHO":WID)
W $&V(99,1),!,$C(27)_"[6n" R A S BL=+$E($K,3,9) ;Work out Bottom Line
START U 0 N $ET S $ET="D ERROR^%M" D READ I $G(CMD)'="EXIT" G START
S $EC="" Q
READ S PMT="MCL> ",WID=80,%PMT=$L(PMT),E=$C(27),K=E_"[K"
N $ES W $&V(BL,1),!,PMT
S CST=$G(CS)+1 R CMD S KEY=$K,P=$L(CMD)+%PMT+1 D KEY G K
AD W $&V(BL+($L(CMD)+%PMT\WID-(P\WID)),P-1#80+1)
RS R *A S KEY=$K I A=127!(A=8) S KEY=127,A=0
I A,A<32 S KEY=$C(A),A=0
I 'A D KEY G K
I P>($L(CMD)+%PMT) W $C(A) S CMD=CMD_$C(A),P=P+1 G RS
S CMD=$E(CMD,1,P-%PMT-1)_$C(A)_$E(CMD,P-%PMT,9999),KEY=55,P=P+1
K I KEY=42!(KEY=45) G DOIT
I KEY=33 S P=%PMT+1 G AD ;<Ctrl><A>
I KEY=81,CST>1 S CST=CST-1,CMD=CS(CST),KEY=55,P=%PMT+1+$L(CMD) ;<Up>
I KEY=82,CST<$G(CS) S CST=CST+1,CMD=CS(CST),KEY=55,P=%PMT+1+$L(CMD) ;<Down>
I KEY=36 S CMD=$E(CMD,1,P-%PMT-1),KEY=55,P=$L(CMD)+%PMT+1 ;<Ctrl><D>
I KEY=37 S P=$L(CMD)+%PMT+1 G AD ;<Ctrl><E>
I KEY=53 S CMD=$E(CMD,P-%PMT,9999),KEY=55,P=%PMT+1 ;<Ctrl><U>
I KEY=55 W $&V(BL,1),PMT,CMD,E_"[K" G AD ;<Ctrl><W>
I KEY=58 S CMD="EXIT" G DOIT ;<Ctrl><Z>
I KEY=83,P'>($L(CMD)+%PMT) S P=P+1 G AD ;<Right>
I KEY=84,P>(%PMT+1) S P=P-1 G AD ;<Left>
I KEY=112 S CMD="HELP" G DOIT
I KEY'=127 W $C(7) G RS
I P'>(%PMT+1) W $C(7) G RS
W E_"[D"_E_"[K" S CMD=$E(CMD,1,P-%PMT-2)_$E(CMD,P-%PMT,9999),P=P-1
W $E(CMD,P-%PMT,9999) G AD
DOIT W:P'>($L(CMD)+%PMT) $&V($L(CMD)+%PMT\WID+1+BL,1) W !
INT S CMD=$&E(CMD,"B"),CCL=$P(CMD," ",2,999),C=$&E($P(CMD," ")) Q:C=""
I $G(CS(+$G(CS)))'=CMD S CS=$G(CS)+1,CS(CS)=CMD
I C?1U D:C="K" X CMD Q
.Q:CMD["("!($E(CCL)'="^") I $&E(CCL)="^$J" W "Use ^SSD please.",! S CMD="Q" Q
.W "KILL entire global: N> "
.R %,! I $E($&E(%))'="Y" S CMD="Q"
I C=$E("EXIT",1,$L(C)) S CMD="EXIT" Q
I C=$E("HELP",1,$L(C)) G ^%MH
S SW=$P(C,"/",2,9),C=$P(C,"/") S:$L(SW) SW="/"_SW
S %=C S:'$D(^%C(C)) %=$O(^%C(C)) I $E(%,1,$L(C))=C N $ET,BL X ^(%) Q
W "?No such MCL command - try HELP",! Q
KEY I KEY=127 Q
I $L(KEY)=1 S KEY=$A(KEY)+32 Q
I $L(KEY)=3 S KEY=$A(KEY,3)+16 Q
S KEY=$E(KEY,3,4)+84 Q
ERROR U 0 I $ES<2 S $EC="" G %M
Q:$ST-$ST(-1) S S=$ST-1 I $EC[",Z51," W:$X ! W "^C",! Q
S ER=$P($EC,",",2) W:$X ! I $L(ER) W "Error: ",ER," ",$&%ERRMSG(ER),!
W "$ST=",S,?10,$ST(S),?20,$ST(S,"PLACE"),!
W "Code:",?10,$ST(S,"MCODE"),! Q
%MH
%MH ;Help on MCL
W "Enter any MUMPS command (initial only) or one of:",!
S %="@" F S %=$O(^%C(%)) Q:%'?1U.E W %,?12,^%C(%,1),!
W "Key usage is: <Help> this message.",!
W " <Up> and <Down> move through entered lines.",!
W " <Left> and <Right> move in current command.",!
W " <Ctrl><A> move to begining of line.",!
W " <Ctrl><D> delete to end of line.",!
W " <Ctrl><E> move to end of line.",!
W " <Ctrl><U> delete to begining of line.",!
W " <Ctrl><W> referesh screen.",!
W " <Ctrl><Z> exit MCL.",!
Q
%RD
%RD ;Do a routine directory for current uci or MGR %
D INT(0,".E") Q
LIB D INT(0,"1""%"".E",1,"%","%") Q
INT(FL,PAT,UCI,ST,END,G,%,F,R,ZR) S ZR="INT^%RD"
S WEB=$P($D,",",2)=2
S FL=$G(FL),PAT=$G(PAT,".E"),UCI=$G(UCI,^$J($J,"ROUTINE"))
S:PAT="" PAT=".E" I $E(PAT)'=".",$E(PAT)'?1N S PAT=$$PAT^%U(PAT)
S ST=$G(ST),END=$G(END,"z"),R=ST I UCI S UCI=^$S("VOL",1,"UCI",UCI)
I FL=3,'$D(G) S G="SEL"
I FL-3 W "Routine Directory of ["_UCI_"] matching '"_PAT_"'.",!!
I FL=2 W "Routine",?10," Size",?20,"Owner",?30,"Compiled",!!
F S R=$O(^[UCI]$R(R)) Q:R=""!($E(R)]END) I R?@PAT D
.I 'FL W:$X>70 ! W R,?$X\10+1*10 Q
.I FL=1 W R,?10,^[UCI]$R(R,1),! Q
.I FL=2 S F=^[UCI]$R(R,0),%=R D Q
..I $E(R)="%" S %="%25"_$E(R,2,9)
..I WEB W "<A HREF=""?$$WWW^%25M&CMD=TYP%20"_%_""">"_R_"</A>" S $X=$L(R)
..E W R
..W ?10,$J($L(F),5),?20,$A(F,4)*256+$A(F,3),?30
..S %=$A(F,8)*256+$A(F,7)*256+$A(F,6)*256+$A(F,5) W $$D^%D(%)," at "
..S %=$A(F,12)*256+$A(F,11)*256+$A(F,10)*256+$A(F,9) W $$T^%T(%),!
.I FL=3 S @G@(R)=""
Q
DEL(CCL,SW,%,R,SEL,OK,ZR) S ZR="DEL^%RD",SW=$G(SW)["/NOQ"
D INT(3,CCL) S R="",OK=1
F S R=$O(SEL(R)) Q:R="" D:'SW I OK K ^$R(R) I SW W:$X>70 ! W R,?$X\10+1*10
.W "Delete "_R R " OK: N> ",%,! S OK=$E($&E(%))="Y"
W ! Q
RC(CCL,%,R,SEL,ZR) S ZR="RC^%RD"
D INT(3,CCL) S R=""
F S R=$O(SEL(R)) Q:R="" W:$X ! W R,! S %=$&%ROUCHK(R)
Q
%RECOMP
%RECOMP ;Recompile ALL routines
W !,"Recompiling ALL routines in the current environment (UCI)",!
S R="" F S R=$O(^$R(R)) Q:R="" W:$X>70 ! W R,?$X\10+1*10 M ^$R(R)=^$R(R)
W !,"Done",! Q
%RR
%RR ;Routine Restore from file
R "Restore from file: ",FILE,! Q:FILE=""
D INT(FILE,0) Q
INT(FILE,NOSAY,%,A,R,ZR) N $ET S ZR="INT^%RR",NOSAY=$G(NOSAY),$ET="D EX^%RR"
O 1:(FILE:"R") U 1 R A,R U 0 S A=$TR(A,$C(13)),R=$TR(R,$C(13))
I NOSAY<2 W !,A,!,R,!
I 'NOSAY R "Restore N> ",%,! I $E($&E(%))'="Y" C 1 W "ABORTED",! Q
U 1 F R R S R=$TR(R,$C(13)) Q:R="" D Q:$A($K)=255
.I NOSAY<2 U 0 W:$X>70 ! W R,?$X\10+1*10 U 1
.K A F %=1:1 R A(%) S A(%)=$TR(A(%),$C(13)) Q:A(%)="" Q:$A($K)=255
.M ^$R(R)=A
EX U 0 W:NOSAY<2 ! C 1 Q
%RS
%RS ;Routine Save
R !,"Routine(s): ",ROU Q:ROU=""
R !,"Filename: ",FILE G %RS:FILE=""
R !,"Header Txt: ",HEAD,! S:HEAD="" HEAD=ROU
D INT(ROU,FILE,HEAD) Q
INT(ROU,FILE,HEAD,%,VOL,UCI,R,ZR) N $ET S ZR="INT^%RS",$ET="D EX^%RS"
S HEAD=$G(HEAD,ROU)
S UI=$$UI^%U() K ^UTILITY(UI) S ROU=$$PAT^%U(ROU)
D INT^%RD(3,ROU,^$J($J,"ROUTINE"),"","z","^UTILITY("_UI_")")
I $O(^UTILITY(UI,""))="" W !,"?No routines selected.",! Q
S %=^$J($J,"ROUTINE_VOL"),VOL=^$S("VOL",%,"NAME")
S UCI=^$S("VOL",%,"UCI",^$J($J,"ROUTINE"))
O 1:(FILE:"W") U 1 W "Saved by %RS from ["_UCI_","_VOL_"] on "
W $$D^%D($H)," at ",$$T^%T($P($H,",",2)),!,HEAD,!
S R="" F S R=$O(^UTILITY(UI,R)) Q:R="" D
.U 0 W:$X>70 ! W R,?$X\10+1*10 U 1 W R,!
.S %=0 F S %=$O(^$R(R,%)) Q:%="" W ^$R(R,%),!
.W !
EX W ! U 0 C 1 W ! Q
%SS
%SS ;System Status
W "Job",?5,"Pid",?15,"User",?25,"Pri",?30,"Routine",?40,"Commands",?50
W "GlobRefs",?60,"Where",!
S J=0 F S J=$O(^$J(J)) Q:'J D W !
.N $ET S $ET="S $EC="""""
.W J,?5,^$J(J,"PID"),?15,^$J(J,"OWNER"),?25,$J(^$J(J,"PRIORITY"),3)
.W ?30,^$J(J,"ROUTINE_NAME"),?40,$J(^$J(J,"COMMANDS"),8),?50
.W $J(^$J(J,"GREFS"),8),?60,$E(^$J(J,"$IO",0),1,20)
W ! Q
INT(J,%,ZR) S ZR="INT^%SS",J=$&E(J) I $E("LOCKS",1,$L(J))=J D Q
.W "Job Count Reference",! S J=""
.F S J=$O(^$L(J)) Q:J="" S %=^$L(J) W $J(+%,3),$J($P(%,",",2),6)," ",J,!
;End of SHOW LOCKS
I $E("SYSTEM",1,$L(J))=J D Q
.W "$SYSTEM=",$SY,!,"UCI# Name",!
.F %=1:1:64 S J=^$S("VOL",1,"UCI",%) I $L(J) W $J(%,3)," ",J,!
;.Dump the UCIs
.W "Max: ",^$J," jobs",!
.W "Vol: ",^$S("VOL",1,"NAME")," in file ",^$S("VOL",1,"FILE"),!
.W ^$S("VOL",1,"SIZE")," x ",^$S("VOL",1,"BLOCK")," kb Blocks, "
.W ^$S("VOL",1,"FREE")," Free.",!
.S J=^$S("VOL",1,"LOGRD"),%=^$S("VOL",1,"PHYRD")
.W "Database reads - Logical: ",J," Physical: ",%
.W:J " Cache hits: ",$J((J-%)/J*100,0,2),"%" W !
;End of SHOW SYSTEM
W " Job: "_J I '$D(^$J(J)) W " No such job",! Q
W " PID: "_^$J(J,"PID")_" User: "_^$J(J,"OWNER")
W " Priority: "_^$J(J,"PRIORITY"),! S %=^$J(J,"PROCESS_START")
W "Started at: "_$$T^%T($P(%,",",2))," on ",$$D^%D(%)
W " UCI Global: "_^$J(J,"GLOBAL")_" Lock: "_^$J(J,"LOCK")
W " Routine: "_^$J(J,"ROUTINE"),!
W " Routine: "_^$J(J,"ROUTINE_NAME")," Commands: ",^$J(J,"COMMANDS")
W " Grefs: ",^$J(J,"GREFS"),!
S %=^$J(J,"$REFERENCE") I $L(%) W " Global: ",%,!
S %=^$J(J,"$STACK",^$J(J,"$STACK"),"MCODE") I $L(%) W " Code: ",%,!
W " Stack: ",^$J(J,"$STACK",^$J(J,"$STACK"),"PLACE")," (Current)",!
F %=^$J(J,"$STACK")-1:-1:1 W $J(%,10),": ",^$J(J,"$STACK",%,"PLACE"),!
Q
%STA
%STA ;System Statistics ; V 3.0 05 Jan 2000 10:44 AM
R !,"Interval: ",INT,! Q:INT<1 D INT(INT) Q
INT(INT,%,O,N,EX,I,LS,ZR) N $ET S ZR="INT^STA",$ET="D ERR^STA",EX=0
S LS="dbget,dbset,dbkil,dbdat,dbord,dbqry,lasttry,lastok,logrd,phyrd,logwt,phywt"
W $&V(1,1),$C(27)_"[J" S:'INT INT=1
D GET Q:EX M O=N F D GET Q:EX D PRT M O=N Q:EX R *%:INT
W $&V(23,1),! Q
ERR G ^%ET:$EC'["Z51" S $EC="",EX=1 Q
GET F I=1:1:$L(LS,",") S N($P(LS,",",I))=^$S("VOL",1,$P(LS,",",I))
S N=$H Q
PRT W $&V(1,1),"System Statistics - ",$$T^%T($P($H,",",2))
W " (",$P(N,",",2)-$P(O,",",2)," secs)",!
W "Volume: ",^$S("VOL",1,"NAME")
W " in file: ",^$S("VOL",1,"FILE"),!
W ^$S("VOL",1,"SIZE")," x ",^$S("VOL",1,"BLOCK")/1024,"kb blocks - "
W ^$S("VOL",1,"FREE")," available ("
W $J(^$S("VOL",1,"FREE")/^$S("VOL",1,"SIZE")*100,0,2),"%)",!!
W ?15,$J("Total",10),?30,$J("Increment",10),!
F I=1:1:$L(LS,",") S %=$P(LS,",",I) W %,?15,$J(N(%),10),?30,$J(N(%)-O(%),10),!
W "cache",?15,$J(N("logrd")-N("phyrd")/N("logrd")*100,10,2),"%",?30
S %=N("logrd")-O("logrd") I '% W $J("",11),!
E W $J(%-(N("phyrd")-O("phyrd"))/%*100,10,2),"%",!
Q
%T
%T ;Convert %T to printable time
S:$D(%T)#2=0 %T=$P($H,",",2) S %T=$$T(%T) Q
T(H,M,S,%,ZR) S ZR="T^%T" I H<0!(H>86399) Q ""
I 'H Q "12:00:00 PM"
S S=H#60,H=H\60,M=H#60,H=H\60
S %=$S(H<12:"AM",M!S:"PM",1:"M ")
Q $TR($J(H,2)," ",0)_":"_$TR($J(M,2)," ",0)_":"_$TR($J(S,2)," ",0)_" "_%
%TYP
%TYP ;Type a routine
0(ROU,%,%1,F,L,W,S,STOP,ZR) S STOP=0,E=$C(27)
;Type routine ROU
I '$D(^$R(ROU)) W "?No such routine as "_ROU,! Q
;Check it
S S=$O(^$R(ROU,""),-1)
;Get the size
S L=99999,W=999,$Y=1 I $P($D,",",2)=4 S L=24,W=80
;Get term setup - clear $Y (there needs to be a better way)
F %=1:1 Q:'$D(^$R(ROU,%)) S F=^$R(ROU,%) D Q:STOP
;Get each line in turn
.S:$E(F)'=";" %1=$P($P(F," "),"("),F=%1_$J("",9-$L(%1))_$P(F,$S($L(%1):%1,1:" "),2,9999)
;.Format it
.F Q:$E(F,2,99)?." " D:$Y'<L Q:STOP W $E(F,1,W),! S F="_"_$E(F,W+1,9999)
;.For each bit
..N $ET S $ET="S $EC="""",STOP=1"
;..See if we need a continue - setup for a ^C
..W E_"[7m"_ROU_" ("_$J(%/S*100,0,0)_"%)"_E_"[0m" R *%1
;..Do a fancy prompt and get a response
..W *13,E,"[K" I %1=13!(%1=10) Q
;..Check for a return
..I %1=81!(%1=113)!(%1=26) S STOP=1 Q
;..Check for a Quit (or ^Z)
..S $Y=1
;..All else is another page
Q
%U
%U ;General Utilities
UI(%,ZR) S ZR="UI^%U"
L +^%AUTH("ui") S %=$G(^%AUTH("ui"))+1,^("ui")=% L -^%AUTH("ui") Q %
DISP(S,%,C,F,ZR) S ZR="DISP^%U",F=""
;Return S (which contains control characters) as displayable string
F %=1:1:$L(S) S C=$A(S,%) D I $L(F)>500 S F=F_"..." Q
;Process each character in the input string
.I C>31,C<127 S F=F_$C(C) Q
;.If it's a normal printable character, add to F and quit
.I C<32 S F=F_"<"_$S('C:"Nul",C=8:"Tab",C=10:"LF",C=12:"FF",C=13:"CR",1:"^"_$C(C+64))_">" Q
;.Look after the normal controls
.I C=127 S F=F_"<Del>" Q
;.and delete - all below 128 now done
.I C<140 S F=F_$C(171)_"^"_$C(C+64)_$C(187) Q
;.For control characters 128 to 139, enclose in << >>
.S F=F_$C(C)
;.Assume a "normal" eight bit character
Q F
;Quit with result
PAT(STR,S,N,C,P,ZR) S ZR="PAT^%U"
;Create a pattern match from wildcards
S P="" F Q:STR="" S S=$P(STR,","),STR=$P(STR,",",2,99) I $L(S) S P=P_"," D
.F N=1:1:$L(S) S C=$E(S,N),P=P_$S(C="*":".E",C="?":"1E",C="""":"1""""""""",1:"1"""_C_"""")
S P=$E(P,2,999) S:P["," P="1("_P_")" Q P
CD(UCI,%,ZR) S ZR="CD^%U"
I 'UCI F %=1:1:64 I ^$S("VOL",1,"UCI",%)=UCI S UCI=% Q
;Make it into a number if possible
G CDE:UCI<1!(UCI>64),CDE:'$L(^$S("VOL",1,"UCI",UCI))
;Validate it
F %="GLOBAL","LOCK","ROUTINE" S ^$J($J,%)=UCI
;Set all the bits
Q
CDE W "?Invalid uci specified",! Q
%WWW
%WWW ;WWW Stuf
S $ET="D ^%ET",MJN=$J O 10:(80:"S=5")
;Open the server port - allow for 5 jobs
READ D RECV^%WWW1(.AA)
;Get a message
F %=1:1 G ERR:'$D(AA(%)) I $E(AA(%),1,5)="GET /" Q
;Look for a GET
S FILE=$P($E(AA(%),6,99999)," HTTP/1.") S:FILE="" FILE="index.html"
;Extract file specification
S %=$G(^WWWLOG) I % S %=%+1,^WWWLOG=%,^WWWLOG(%)=$H_","_$P(DEVICE,",",3)_","_FILE
;Log it if applicable
I $E(FILE)="?" G EXT
;Look after extrinsics elsewhere
FILE I FILE["%" S FILE=$$REMP(FILE)
;Check for % characters
S F=$P(FILE,"/",$L(FILE,"/")),EXT="" S:F["." EXT=$&E($P(F,".",$L(F,".")))
;Extract just the file name, also get the extension (in upper case)
S REF=$$GETFILE(F) I REF="" D ERR^%WWW1() H:MJN-$J G READ
;Get the reference, if nosuch, give error and exit
D SEND^%WWW1(REF,EXT) H:MJN-$J G READ
;Send it
;---
EXT S FUN=$P($E(FILE,2,999),"&"),FUN=$$REMP(FUN),FILE=$P(FILE,"&",2,9999)
;Extrinsic functions - extract the function name
K BB F Q:FILE="" S F=$P(FILE,"&"),FILE=$P(FILE,"&",2,9999) D
;Extract the fields
.S I=$P(F,"="),F=$P(F,"=",2,999),I=$$REMP(I) S:$L(I) BB(I)=$$REMP(F)
;.Store one field
S FUN="RET="_FUN_"(.AA,.BB)" D I $L(RET) D ERR^%WWW1(RET) H
;Setup the extrinsic and execute it
.N $ET S $ET="D %ET^%WWW",@FUN
;.Saving the error trap
I $G(AA)'="" S FILE=AA G FILE
;Display a file if required
H:MJN-$J G READ
;Done
;---
%ET S F=$P($EC,",",2),F="MUMPS Error: "_F_" "_$&%ERRMSG(F) D ERR^%WWW1(F)
;Extrinsic error trap
G ^%ET
;---
ERR D ERR^%WWW1("Invalid http message received") U 10:("DISCONNECT") H:MJN-$J G READ
;Give error and halt
;---
GETFILE(F,%,V,ZR) S ZR="GETFILE^%WWW"
;Lookup a file in %D
S %=$G(^%D(FILE)) Q:'% ""
;Lookup the file
S V=$O(^%D(%,""),-1) Q:'V ""
;Get the version
Q "^%D("_%_","_V_")"
;Quit with the ref
;---
REMP(F,%,X,ZR) S ZR="REMP^%WWW",X=""
;Remove %nn stuff from a string
F S %=$F(F,"%") Q:'% S X=X_$E(F,1,%-2)_$$CC($E(F,%,%+1)),F=$E(F,%+2,99999)
;Doit
Q X_F
;and quit
CC(H,%,ZR) S ZR="CC^%WWW",H=$&E(H)
;Convert Hex to Character
F %=0:1:15 S %(%)=% S:%>9 %($C(55+%))=%
;Setup the 'HEX' array 0 -> F
Q $C(%($E(H))*16+%($E(H,2)))
;Quit with decimal value
%WWW1
%WWW1 ;WWW Stuf - subroutines
RECV(D,%,N,TO,ZR) S ZR="RECV^%WWW1" K D S TO=10,D=1 U 10
;Get into D which must be passed by ref, number of lines returned in D
R D(1) S DEVICE=$D I D(1)'="" F D=2:1 R D(D):TO Q:D(D)=""
;Read first (no timeout) then the rest
S N=$G(^WWW) I N F %=1:1 Q:'$D(D(%)) S ^WWW(%+N)=D(%)
I N S ^WWW=N+%
Q
;and exit
;---
SEND(REF,TYP,%,L,ZR) N $ET S ZR="SEND^%WWW1",$ET="D X^%WWW1",TYP=$G(TYP),L=0
; REF -> Global ref to send, sends @REF@(n)
; TYP -> TXT = text/html (default)
; JPG = image/jpeg
; GIF = image/gif
; CLASS = class
; HTTP/1.0 200 Document follows
; Content-type: (as above)
; Content-Length: (omit for text/html)
; <blank line>
; file
U 10 S TYP=$S(TYP="JPG":"image/jpeg",TYP="GIF":"image/gif",TYP="CLASS":"class",1:"text/html")
;Get TYP into browser format
W "HTTP/1.0 200 Document follows",!,"Server: MUMPS",!,"Content-type: "_TYP,!
I $E(TYP)'="t" D W "Content-Length: "_L,!
;Not a text file - get the size
.S %=0 F S %=$O(@REF@(%)) Q:'% S L=L+$L(^(%))
;Calculate the total length
W ! S %=0 F S %=$O(@REF@(%)) Q:'% W @REF@(%) W:'L !
;Terminate header, output file (terminate text lines with CrLf)
Q
;and exit
X I $G(MJN)=$J S $EC="" Q
H:$EC["Z47" G ^%ET
;---
ERR(ERR,%,MSG,ZR) S ZR="ERR^%WWW",ERR=$G(ERR,"File not found")
;Send an error message - ensure there is a message