-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCvsClient.Mod.cvs
executable file
·1069 lines (985 loc) · 30 KB
/
CvsClient.Mod.cvs
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
%!Encoded,CvsClient0.2
%!Obj,TextGadgets.NewStyleProc,Pagebreak=F,WYSIWYG=F,Adjust=T,PrinterW=F,FrameW=F,Tabs="",Left=i00000000,Width=i00000264
%!Font,Oberon10.Scn.Fnt,0F,00
MODULE CvsClient; (* pjm %!Obj,TimeStamps.New,Color=i0000000F,Font="Oberon10.Scn.Fnt"
*)
(** Oberon client for CVS. *)
IMPORT FileDir, Files, Objects, Fonts, Reals, Texts, Display, Oberon;
CONST
Version = "CvsClient0.2";
CvsExt = ".cvs";
BakExt = ".Bak";
SambaHack = TRUE; (* Samba/FAT can only represent even seconds *)
Modify = FALSE;
TYPE
Attr = POINTER TO RECORD (Objects.AttrMsg)
next: Attr;
END;
VAR
w: Texts.Writer;
enumR: Files.Rider;
enumObj: Objects.Object;
hex: ARRAY 17 OF CHAR;
isStrCh, isPlainCh: ARRAY 256 OF BOOLEAN;
init: LONGINT;
dummy: ARRAY 1 OF CHAR;
root: Attr;
(* Append "from" to "to"; trap on overflow. *)
PROCEDURE Append(from: ARRAY OF CHAR; VAR to: ARRAY OF CHAR);
VAR i, j: LONGINT;
BEGIN
j := 0; WHILE to[j] # 0X DO INC(j) END;
i := 0; WHILE from[i] # 0X DO to[j] := from[i]; INC(i); INC(j) END;
to[j] := 0X
END Append;
(* Various ASCII file write procedures. *)
PROCEDURE WriteLn(VAR r: Files.Rider);
BEGIN
Files.Write(r, 0AX)
END WriteLn;
PROCEDURE WriteHexByte(VAR r: Files.Rider; x: CHAR);
BEGIN
Files.Write(r, hex[ORD(x) DIV 10H]);
Files.Write(r, hex[ORD(x) MOD 10H])
END WriteHexByte;
PROCEDURE WriteHex(VAR r: Files.Rider; x: LONGINT);
BEGIN
WriteHexByte(r, CHR(x DIV 1000000H MOD 100H));
WriteHexByte(r, CHR(x DIV 10000H MOD 100H));
WriteHexByte(r, CHR(x DIV 100H MOD 100H));
WriteHexByte(r, CHR(x MOD 100H))
END WriteHex;
(* Write a quoted character. *)
PROCEDURE WriteQuote(VAR r: Files.Rider; x: CHAR);
BEGIN
Files.Write(r, "%25"); WriteHexByte(r, x)
END WriteQuote;
(* Write a character, quoting special characters. *)
PROCEDURE Write(VAR r: Files.Rider; x: CHAR);
BEGIN
IF x = 0DX THEN
WriteLn(r)
ELSIF (x = 9X) OR (x >= 20X) & (x <= 7EX) & (x # "%25") THEN
Files.Write(r, x)
ELSE
WriteQuote(r, x)
END
END Write;
(* Write a string, quoting special characters. *)
PROCEDURE WriteString(VAR r: Files.Rider; s: ARRAY OF CHAR);
VAR i: LONGINT; ch: CHAR;
BEGIN
i := 0;
LOOP
ch := s[i];
IF ch = 0X THEN EXIT END;
IF isStrCh[ORD(ch)] THEN
Files.Write(r, ch)
ELSE
WriteQuote(r, ch)
END;
INC(i)
END
END WriteString;
(* Write the escape sequence. *)
PROCEDURE WriteEsc(VAR r: Files.Rider);
BEGIN
Files.Write(r, "%25"); Files.Write(r, "!")
END WriteEsc;
(* Enumerator for WriteAttr. *)
PROCEDURE EnumAttr(name: ARRAY OF CHAR);
VAR msg: Objects.AttrMsg; high, low: LONGINT;
BEGIN
msg.res := -1; msg.id := Objects.get; COPY(name, msg.name);
enumObj.handle(enumObj, msg);
IF (msg.res >= 0) & (msg.class # Objects.Inval) THEN
Write(enumR, ","); WriteString(enumR, name); Write(enumR, "=");
CASE msg.class OF
Objects.String:
Write(enumR, 22X); WriteString(enumR, msg.s); Write(enumR, 22X)
|Objects.Int:
Write(enumR, "i"); WriteHex(enumR, msg.i)
|Objects.Real:
Write(enumR, "r"); WriteHex(enumR, Reals.Int(msg.x))
|Objects.LongReal:
Write(enumR, "R"); Reals.IntL(msg.y, high, low);
WriteHex(enumR, high); WriteHex(enumR, low)
|Objects.Char:
Write(enumR, "c"); WriteHexByte(enumR, msg.c)
|Objects.Bool:
IF msg.b THEN Write(enumR, "T") ELSE Write(enumR, "F") END
END
END
END EnumAttr;
(* Write the attributes of an object. *)
PROCEDURE WriteAttr(VAR r: Files.Rider; obj: Objects.Object);
VAR msg: Objects.AttrMsg;
BEGIN
msg.res := -1; msg.id := Objects.enum; msg.Enum := EnumAttr;
enumObj := obj;
Files.Set(enumR, Files.Base(r), Files.Pos(r));
obj.handle(obj, msg);
Files.Set(r, Files.Base(r), Files.Pos(enumR));
Files.Set(enumR, NIL, 0);
enumObj := NIL
END WriteAttr;
(* Get string attribute from an object. *)
PROCEDURE GetStr(obj: Objects.Object; name: ARRAY OF CHAR; VAR val: ARRAY OF CHAR);
VAR msg: Objects.AttrMsg;
BEGIN
msg.res := -1; msg.id := Objects.get; COPY(name, msg.name);
obj.handle(obj, msg);
IF (msg.res >= 0) & (msg.class = Objects.String) THEN
COPY(msg.s, val)
ELSE
val[0] := 0X
END
END GetStr;
(* Check for objects that can be stored losslessly (no warning generated for these). *)
PROCEDURE SimpleObj(VAR gen: ARRAY OF CHAR): BOOLEAN;
BEGIN
RETURN (gen = "TextGadgets.NewStyleProc") OR (gen = "TimeStamps.New") OR (gen = "TextGadgets.NewControl")
END SimpleObj;
(* Convert a text to encoded ASCII file format. "lost" returns the number of objects converted with loss. *)
PROCEDURE ExportText(t: Texts.Text; VAR r: Files.Rider; VAR lost: LONGINT);
VAR
tr: Texts.Reader; lib: Objects.Library; obj: Objects.Object;
vofs, col: SHORTINT; ch: CHAR; gen: ARRAY 64 OF CHAR;
BEGIN
lost := 0;
lib := Fonts.Default; vofs := 0; col := Display.FG;
WriteEsc(r); WriteString(r, "Encoded"); Write(r, ","); WriteString(r, Version); WriteLn(r);
Texts.OpenReader(tr, t, 0);
Texts.Read(tr, ch);
WHILE ~tr.eot DO
IF ~((tr.lib = lib) & (tr.col = col) & (tr.voff = vofs)) THEN (* attribute change or object *)
IF tr.lib IS Fonts.Font THEN (* attribute change *)
IF (tr.lib = lib) & (tr.voff = vofs) THEN (* only color change *)
lib := tr.lib; col := tr.col; vofs := tr.voff;
WriteEsc(r); WriteString(r, "Color"); Write(r, ","); WriteHexByte(r, CHR(col));
WriteLn(r); Write(r, ch)
ELSE
lib := tr.lib; col := tr.col; vofs := tr.voff;
WriteEsc(r); WriteString(r, "Font"); Write(r, ","); WriteString(r, lib.name); Write(r, ",");
WriteHexByte(r, CHR(col)); Write(r, ","); WriteHexByte(r, CHR(vofs));
WriteLn(r); Write(r, ch)
END
ELSE (* object *)
tr.lib.GetObj(tr.lib, ORD(ch), obj);
GetStr(obj, "Gen", gen);
WriteEsc(r); WriteString(r, "Obj"); Write(r, ","); WriteString(r, gen);
WriteAttr(r, obj); WriteLn(r);
IF ~SimpleObj(gen) THEN INC(lost) END
END
ELSE
Write(r, ch)
END;
Texts.Read(tr, ch)
END
END ExportText;
(** Export Oberon texts to ASCII file format. *)
PROCEDURE ExportTexts*; (** { text ["=>" file] } ~ *)
VAR
t: Texts.Text; r: Files.Rider; time, date, lost, errors, files: LONGINT; s: Texts.Scanner;
f: Files.File; in, out: ARRAY 64 OF CHAR;
BEGIN
files := 0; errors := 0;
Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
WHILE s.class IN {Texts.Name, Texts.String} DO
COPY(s.s, in); Texts.Scan(s);
IF (s.class = Texts.Char) & (s.c = "=") THEN
Texts.Scan(s);
IF (s.class = Texts.Char) & (s.c = ">") THEN Texts.Scan(s) ELSE s.class := Texts.Inval END;
IF s.class IN {Texts.Name, Texts.String} THEN
COPY(s.s, out); Texts.Scan(s)
ELSE
s.class := Texts.Inval
END
ELSE
COPY(in, out); Append(CvsExt, out)
END;
IF s.class # Texts.Inval THEN
INC(files); Texts.WriteString(w, in);
NEW(t); Texts.Open(t, in);
IF t.len # 0 THEN
Texts.WriteString(w, " => "); Texts.WriteString(w, out);
Files.Set(r, Files.New(out), 0);
IF Files.Base(r) # NIL THEN
ExportText(t, r, lost);
Files.Register(Files.Base(r));
IF lost # 0 THEN
Texts.WriteString(w, " lost "); Texts.WriteInt(w, lost, 1);
Texts.WriteString(w, " object(s)"); INC(errors)
END;
f := Files.Old(in); Files.GetDate(f, time, date);
IF SambaHack & ODD(time) THEN
DEC(time); (* round seconds down to even *)
Files.SetDate(f, time, date); Files.Close(f)
END;
Files.SetDate(Files.Base(r), time, date); Files.Close(Files.Base(r))
ELSE
Texts.WriteString(w, " create error"); INC(errors)
END
ELSE
Texts.WriteString(w, " empty, skipped"); INC(errors)
END
ELSE
Texts.WriteString(w, "Syntax error")
END;
Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf)
END;
IF (files > 1) & (errors # 0) THEN
Texts.WriteInt(w, errors, 1); Texts.WriteString(w, " error(s)");
Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf)
END
END ExportTexts;
PROCEDURE IsHexChar(ch: CHAR): BOOLEAN;
BEGIN
RETURN ((ch >= "0") & (ch <= "9")) OR ((CAP(ch) >= "A") & (CAP(ch) <= "F"))
END IsHexChar;
PROCEDURE HexVal(ch: CHAR): LONGINT;
BEGIN
IF (ch >= "0") & (ch <= "9") THEN
RETURN ORD(ch)-ORD("0")
ELSIF (CAP(ch) >= "A") & (CAP(ch) <= "F") THEN
RETURN ORD(CAP(ch))-ORD("A")+10
ELSE
HALT(99)
END
END HexVal;
PROCEDURE GenObject(gen: ARRAY OF CHAR): Objects.Object;
VAR obj: Objects.Object; res: INTEGER;
BEGIN
Objects.NewObj := NIL;
Oberon.Call(gen, Oberon.Par, FALSE, res);
obj := Objects.NewObj; Objects.NewObj := NIL;
RETURN obj
END GenObject;
PROCEDURE ImportText(VAR r: Files.Rider; t: Texts.Text): BOOLEAN;
VAR b: Texts.Writer; i: LONGINT; ch: CHAR; ok: BOOLEAN; s: ARRAY 64 OF CHAR;
PROCEDURE Error(msg: ARRAY OF CHAR);
BEGIN
Texts.WriteString(w, msg); Texts.WriteString(w, " at ");
Texts.WriteInt(w, Files.Pos(r), 1); ok := FALSE
END Error;
PROCEDURE ReadHex2(VAR x: LONGINT);
BEGIN
x := 0;
IF IsHexChar(ch) THEN
x := HexVal(ch)*10H; Files.Read(r, ch);
IF IsHexChar(ch) THEN
INC(x, HexVal(ch)); Files.Read(r, ch)
ELSE
Error("hexadecimal character expected")
END
ELSE
Error("hexadecimal character expected")
END
END ReadHex2;
PROCEDURE ReadHInt(VAR x: LONGINT);
VAR i, j: LONGINT;
BEGIN
i := 0; x := 0;
WHILE (i # 4) & ok DO
ReadHex2(j); x := x * 100H + j;
INC(i)
END
END ReadHInt;
PROCEDURE ReadTextAttr; (* "%25!Font," already read *)
VAR col, vofs: LONGINT; font: Fonts.Font;
BEGIN
ReadString(s);
IF (s # "") & (ch = ",") THEN
Files.Read(r, ch); ReadHex2(col);
IF ok THEN
IF ch = "," THEN
Files.Read(r, ch); ReadHex2(vofs);
IF ok THEN
IF ch = 0AX THEN
Files.Read(r, ch);
font := Fonts.This(s);
IF font # NIL THEN
Texts.SetFont(b, font);
Texts.SetOffset(b, SHORT(SHORT(vofs)));
Texts.SetColor(b, SHORT(SHORT(col)))
ELSE
Error("font not found")
END
ELSE
Error("LF expected")
END
END
ELSE
Error("',' expected")
END
END
ELSE
Error("',' expected")
END
END ReadTextAttr;
PROCEDURE ReadColor; (* "%25!Color," already read *)
VAR col: LONGINT;
BEGIN
ReadHex2(col);
IF ok THEN
IF ch = 0AX THEN
Files.Read(r, ch);
Texts.SetColor(b, SHORT(SHORT(col)))
ELSE
Error("LF expected")
END
END
END ReadColor;
PROCEDURE ReadObj; (* "%25!Obj," already read *)
VAR obj: Objects.Object; low, high: LONGINT; msg: Objects.AttrMsg;
BEGIN
ReadString(s); obj := GenObject(s);
IF obj # NIL THEN
WHILE (ch = ",") & ok DO
Files.Read(r, ch); ReadString(s); COPY(s, msg.name);
IF msg.name # "" THEN
IF ch = "=" THEN
Files.Read(r, ch);
IF ch = 22X THEN (* astr *)
msg.class := Objects.String;
Files.Read(r, ch); ReadString(msg.s);
IF ch = 22X THEN Files.Read(r, ch) ELSE Texts.WriteString(w, msg.s); Error('" expected') END
ELSIF ch = "i" THEN (* aint *)
msg.class := Objects.Int; Files.Read(r, ch); ReadHInt(msg.i)
ELSIF ch = "r" THEN
msg.class := Objects.Real; Files.Read(r, ch); ReadHInt(low); msg.x := Reals.Real(low)
ELSIF ch = "R" THEN
msg.class := Objects.LongReal; Files.Read(r, ch); ReadHInt(high); ReadHInt(low);
msg.y := Reals.RealL(high, low)
ELSIF ch = "c" THEN
msg.class := Objects.Char; Files.Read(r, ch); ReadHex2(low); msg.c := CHR(low)
ELSIF (ch = "T") OR (ch = "F") THEN
msg.class := Objects.Bool; msg.b := (ch = "T"); Files.Read(r, ch)
ELSE
Error("attribute value expected")
END;
IF ok THEN
msg.id := Objects.set; msg.res := -1;
obj.handle(obj, msg);
IF msg.res < 0 THEN
Append(" attribute set error", s); Error(s)
END
END
ELSE
Error("= expected")
END
ELSE
Error("attribute name expected")
END
END;
IF ok THEN
IF ch = 0AX THEN Files.Read(r, ch) ELSE Error("LF expected") END
END;
IF ok THEN Texts.WriteObj(b, obj) END
ELSE
Append(" object not found", s); Error(s)
END
END ReadObj;
PROCEDURE ReadString(VAR s: ARRAY OF CHAR);
VAR i, x: LONGINT;
BEGIN
i := 0;
LOOP
%!Color,03
(*Texts.Write(w, "("); Texts.WriteInt(w, ORD(ch), 1); Texts.Write(w, ")");*)
%!Color,0F
IF r.eof OR (i = LEN(s)-1) OR ~ok THEN EXIT END;
IF ch = "%25" THEN
Files.Read(r, ch);
IF IsHexChar(ch) THEN (* quoted *)
ReadHex2(x); s[i] := CHR(x); INC(i)
ELSE
Error("hexadecimal character expected")
END
ELSIF ~isStrCh[ORD(ch)] THEN
EXIT
ELSE
s[i] := ch; INC(i); Files.Read(r, ch)
END
END;
%!Color,03
(*Texts.Write(w, "["); Texts.WriteString(w, s); Texts.Write(w, "]");*)
%!Color,0F
s[i] := 0X
END ReadString;
PROCEDURE ReadHeader;
BEGIN
Files.Read(r, ch); s[0] := ch; Files.Read(r, ch); s[1] := ch; s[2] := 0X;
IF s = "%25!" THEN
Files.Read(r, ch); ReadString(s);
IF s = "Encoded" THEN
IF ch = "," THEN
Files.Read(r, ch); ReadString(s);
IF s = Version THEN
IF ch = 0AX THEN
Files.Read(r, ch)
ELSE
Error("LF expected")
END
ELSE
Error("incompatible version")
END
ELSE
Error("',' expected")
END
ELSE
Error("'Encoded' expected")
END
ELSE
Error("%25! expected")
END
END ReadHeader;
BEGIN
ok := TRUE; ReadHeader;
IF ok THEN
Texts.OpenWriter(b);
WHILE ~r.eof & ok DO
IF ch = "%25" THEN (* quoted or textattr or obj *)
Files.Read(r, ch);
IF ch = "!" THEN (* textattr or color or obj *)
Files.Read(r, ch); ReadString(s);
IF ch = "," THEN
Files.Read(r, ch);
IF s = "Font" THEN (* textattr *)
ReadTextAttr
ELSIF s = "Color" THEN (* color *)
ReadColor
ELSIF s = "Obj" THEN (* obj *)
ReadObj
ELSE
Error("unknown keyword")
END
ELSE
Error("',' expected")
END
ELSIF IsHexChar(ch) THEN (* quoted *)
ReadHex2(i); Texts.Write(b, CHR(i))
ELSE
Error("unexpected character")
END
ELSIF isPlainCh[ORD(ch)] THEN
IF ch = 0AX THEN Texts.WriteLn(b) ELSE Texts.Write(b, ch) END;
Files.Read(r, ch)
ELSE
Error("plain character expected")
END
END;
Texts.Append(t, b.buf)
END;
RETURN ok
END ImportText;
(** Import Oberon texts from ASCII file format. *)
PROCEDURE ImportTexts*; (** { file ["=>" text] } ~ *)
VAR
t: Texts.Text; r: Files.Rider; time, date, i, j: LONGINT; f: Files.File; s: Texts.Scanner;
in, out: ARRAY 64 OF CHAR;
BEGIN
Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
WHILE s.class IN {Texts.Name, Texts.String} DO
COPY(s.s, in); Texts.Scan(s);
IF (s.class = Texts.Char) & (s.c = "=") THEN
Texts.Scan(s);
IF (s.class = Texts.Char) & (s.c = ">") THEN Texts.Scan(s) ELSE s.class := Texts.Inval END;
IF s.class IN {Texts.Name, Texts.String} THEN
COPY(s.s, out); Texts.Scan(s)
ELSE
s.class := Texts.Inval
END
ELSE
out := CvsExt;
i := 0; WHILE in[i] # 0X DO INC(i) END;
j := 0; WHILE out[j] # 0X DO INC(j) END;
WHILE (i # 0) & (j # 0) & (in[i] = out[j]) DO DEC(i); DEC(j) END;
IF (i # 0) & (j = 0) THEN (* Ext occurs at end of in *)
COPY(in, out); out[i] := 0X (* chop off Ext *)
ELSE
COPY(in, out); Append(".Text", out)
END
END;
IF s.class # Texts.Inval THEN
Texts.WriteString(w, in);
Files.Set(r, Files.Old(in), 0);
IF Files.Base(r) # NIL THEN
Texts.WriteString(w, " => "); Texts.WriteString(w, out); Texts.Write(w, " ");
f := Files.New(out);
IF f # NIL THEN
NEW(t); Texts.Open(t, "");
IF ImportText(r, t) THEN
Texts.Store(t, f, 0, i); (* ignore i *) %!Color,01
(* what about text document? *)
%!Color,0F
Files.Register(f);
Files.GetDate(Files.Base(r), time, date);
Files.SetDate(f, time, date); Files.Close(f)
END
ELSE
Texts.WriteString(w, " create error")
END
ELSE
Texts.WriteString(w, " not found, skipped")
END
ELSE
Texts.WriteString(w, "Syntax error")
END;
Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf)
END
END ImportTexts;
PROCEDURE Younger(l, r: Files.File): BOOLEAN;
VAR rt, rd, lt, ld: LONGINT;
BEGIN
IF l = NIL THEN
RETURN FALSE
ELSIF r = NIL THEN
RETURN TRUE
ELSE
Files.GetDate(r, rt, rd); Files.GetDate(l, lt, ld);
RETURN (ld > rd) OR ((ld = rd) & (lt > rt))
END
END Younger;
(** Synchronize external CVS working directories and internal working directory using timestamps. *)
PROCEDURE Synchronize*; (** remoteprefix localprefix { files } ~ *)
VAR
s: Texts.Scanner; rem, loc: Files.File; import, export: Texts.Writer;
t: Texts.Text; rempre, locpre, remote, local: ARRAY 64 OF CHAR;
BEGIN
Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
IF s.class IN {Texts.Name, Texts.String} THEN
COPY(s.s, rempre); Texts.Scan(s);
IF s.class IN {Texts.Name, Texts.String} THEN
COPY(s.s, locpre); Texts.Scan(s);
Texts.OpenWriter(import); Texts.WriteString(import, "CvsClient.ImportTexts");
Texts.OpenWriter(export); Texts.WriteString(export, "CvsClient.ExportTexts");
WHILE s.class IN {Texts.Name, Texts.String} DO
COPY(rempre, remote); Append(s.s, remote); Append(CvsExt, remote); rem := Files.Old(remote);
COPY(locpre, local); Append(s.s, local); loc := Files.Old(local);
IF (loc = NIL) & (rem = NIL) THEN
Texts.WriteString(w, local); Texts.WriteString(w, " and ");
Texts.WriteString(w, remote); Texts.WriteString(w, " not found");
Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf)
ELSIF Younger(loc, rem) THEN
Texts.WriteLn(export); Texts.Write(export, 9X);
Texts.WriteString(export, local);
Texts.WriteString(export, " => ");
Texts.WriteString(export, remote)
ELSIF Younger(rem, loc) THEN
Texts.WriteLn(import); Texts.Write(import, 9X);
Texts.WriteString(import, remote);
Texts.WriteString(import, " => ");
Texts.WriteString(import, local)
END;
Texts.Scan(s)
END;
Texts.WriteString(export, " ~"); Texts.WriteLn(export); Texts.WriteString(import, " ~");
NEW(t); Texts.Open(t, "");
Texts.Append(t, export.buf); Texts.Append(t, import.buf);
Oberon.OpenText("", t, 400, 400)
END
END
END Synchronize;
PROCEDURE SplitPath(full: ARRAY OF CHAR; VAR path, name, ext: ARRAY OF CHAR);
VAR i, j, k: LONGINT;
BEGIN
i := 0; j := -1; k := -1; (* find last "/" and "." *)
WHILE full[i] # 0X DO
IF full[i] = "\" THEN j := i; full[i] := "/"
ELSIF full[i] = "/" THEN j := i
ELSIF full[i] = "." THEN k := i
END;
INC(i)
END;
FOR i := 0 TO j DO path[i] := full[i] END;
INC(j); path[j] := 0X;
i := 0; WHILE (full[j] # 0X) & (j # k) DO name[i] := full[j]; INC(i); INC(j) END;
name[i] := 0X;
i := 0; WHILE full[j] # 0X DO ext[i] := full[j]; INC(i); INC(j) END;
ext[i] := 0X
END SplitPath;
(*
PROCEDURE Lower(VAR s: ARRAY OF CHAR);
VAR i: LONGINT; ch: CHAR;
BEGIN
i := 0;
LOOP
ch := s[i];
IF ch = 0X THEN EXIT END;
IF (ch >= "A") & (ch <= "Z") THEN s[i] := CHR(ORD(ch)+32) END;
INC(i)
END
END Lower;
*)
(* Enumerator for GetAttrs. *)
PROCEDURE GetEnumAttr(name: ARRAY OF CHAR);
VAR msg: Attr; prev: Attr;
BEGIN
NEW(msg);
msg.res := -1; msg.id := Objects.get; COPY(name, msg.name);
enumObj.handle(enumObj, msg^);
IF (msg.res >= 0) & (msg.class # Objects.Inval) THEN
prev := root;
WHILE (prev.next # NIL) & (name < prev.next.name) DO prev := prev.next END;
IF (prev.next = NIL) OR (name # prev.next.name) THEN
msg.next := prev.next; prev.next := msg
END
END
END GetEnumAttr;
PROCEDURE GetAttrs(obj: Objects.Object): Attr;
VAR ret: Attr; msg: Objects.AttrMsg;
BEGIN
root.next := NIL;
msg.res := -1; msg.id := Objects.enum; msg.Enum := GetEnumAttr;
enumObj := obj;
obj.handle(obj, msg);
enumObj := NIL;
ret := root.next; root.next := NIL;
RETURN ret
END GetAttrs;
PROCEDURE TextsEqual(t1, t2: Texts.Text): BOOLEAN;
VAR r1, r2: Texts.Reader; obj1, obj2: Objects.Object; attr1, attr2: Attr; ch1, ch2: CHAR; gen1, gen2: ARRAY 64 OF CHAR;
BEGIN
Texts.OpenReader(r1, t1, 0); Texts.OpenReader(r2, t2, 0);
LOOP
Texts.Read(r1, ch1); Texts.Read(r2, ch2);
IF r1.eot OR r2.eot THEN EXIT END;
IF r1.col # r2.col THEN EXIT END;
IF r1.voff # r2.voff THEN EXIT END;
IF r1.lib.name # r2.lib.name THEN EXIT END;
IF r1.lib IS Fonts.Font THEN
IF ch1 # ch2 THEN EXIT END
ELSE
r1.lib.GetObj(r1.lib, ORD(ch1), obj1);
GetStr(obj1, "Gen", gen1);
r1.lib.GetObj(r2.lib, ORD(ch2), obj2);
GetStr(obj2, "Gen", gen2);
IF gen1 # gen2 THEN EXIT END;
attr1 := GetAttrs(obj1);
attr2 := GetAttrs(obj2);
WHILE (attr1 # NIL) & (attr2 # NIL) DO
IF attr1.name # attr2.name THEN EXIT END;
IF attr1.class # attr2.class THEN EXIT END;
CASE attr1.class OF
Objects.String: IF attr1.s # attr2.s THEN EXIT END
|Objects.Int: IF attr1.i # attr2.i THEN EXIT END
|Objects.Real: IF attr1.x # attr2.x THEN EXIT END
|Objects.LongReal: IF attr1.y # attr2.y THEN EXIT END
|Objects.Char: IF attr1.c # attr2.c THEN EXIT END
|Objects.Bool: IF attr1.b # attr2.b THEN EXIT END
END;
attr1 := attr1.next; attr2 := attr2.next
END;
IF (attr1 # NIL) OR (attr2 # NIL) THEN EXIT END
END
END;
RETURN r1.eot & r2.eot
END TextsEqual;
PROCEDURE ImportUpdateCvsFile(src, dst: ARRAY OF CHAR; srctime, srcdate: LONGINT);
VAR
sf, df: Files.File; r: Files.Rider; nt, ot: Texts.Text; i, dstdate, dsttime: LONGINT; res: INTEGER;
bak: FileDir.FileName;
BEGIN
df := Files.Old(dst);
Files.GetDate(df, dsttime, dstdate);
IF (dsttime # srctime) OR (dstdate # srcdate) THEN
sf := Files.Old(src);
IF sf # NIL THEN
Files.Set(r, sf, 0);
NEW(nt); Texts.Open(nt, "");
IF ImportText(r, nt) THEN
NEW(ot); Texts.Open(ot, dst);
IF ~TextsEqual(ot, nt) THEN
df := Files.New(dst);
IF df # NIL THEN
COPY(dst, bak); Append(BakExt, bak);
IF Modify THEN Files.Rename(dst, bak, res) ELSE res := 1 END; (* ignore res *)
Texts.Store(nt, df, 0, i); (* ignore i *)
IF Modify THEN
Files.Register(df); Files.SetDate(df, srctime, srcdate); Files.Close(df)
ELSE
Texts.WriteString(w, " modify disabled")
END;
IF res = 0 THEN
Texts.WriteString(w, " ("); Texts.WriteString(w, bak);
Texts.WriteString(w, " created)")
END
ELSE
Texts.WriteString(w, " create failed")
END
ELSE
Texts.WriteString(w, " no change")
END
END
ELSE
Texts.WriteString(w, " open failed")
END
ELSE
Texts.WriteString(w, " timestamps match")
END
END ImportUpdateCvsFile;
PROCEDURE ImportNewCvsFile(src, dst: ARRAY OF CHAR; srctime, srcdate: LONGINT);
VAR sf, df: Files.File; r: Files.Rider; i: LONGINT; nt: Texts.Text;
BEGIN
sf := Files.Old(src);
IF sf # NIL THEN
Files.Set(r, sf, 0);
NEW(nt); Texts.Open(nt, "");
IF ImportText(r, nt) THEN
df := Files.New(dst);
IF df # NIL THEN
Texts.Store(nt, df, 0, i); (* ignore i *)
IF Modify THEN
Files.Register(df); Files.SetDate(df, srctime, srcdate); Files.Close(df)
ELSE
Texts.WriteString(w, " modify disabled")
END
ELSE
Texts.WriteString(w, " create failed")
END
END
ELSE
Texts.WriteString(w, " open failed")
END
END ImportNewCvsFile;
PROCEDURE FilesEqual(f1, f2: Files.File): BOOLEAN;
VAR r1, r2: Files.Rider; ch1, ch2: CHAR;
BEGIN
Files.Set(r1, f1, 0); Files.Set(r2, f2, 0);
REPEAT
Files.Read(r1, ch1); Files.Read(r2, ch2);
UNTIL r1.eof OR r2.eof OR (ch1 # ch2);
RETURN r1.eof & r2.eof
END FilesEqual;
PROCEDURE CopyFile(sf, df: Files.File);
VAR sr, dr: Files.Rider; ch: CHAR;
BEGIN
Files.Set(sr, sf, 0); Files.Set(dr, df, 0);
LOOP
Files.Read(sr, ch);
IF sr.eof THEN EXIT END;
Files.Write(dr, ch)
END
END CopyFile;
PROCEDURE ImportCopyFile(src, dst: ARRAY OF CHAR; srctime, srcdate: LONGINT);
VAR sf, df: Files.File; res: INTEGER; copy: BOOLEAN; bak: FileDir.FileName;
BEGIN
sf := Files.Old(src);
IF sf # NIL THEN
copy := TRUE;
df := Files.Old(dst);
IF df # NIL THEN
IF FilesEqual(sf, df) THEN
Texts.WriteString(w, " no change");
copy := FALSE
END
END;
IF copy THEN
df := Files.New(dst);
IF df # NIL THEN
COPY(dst, bak); Append(BakExt, bak);
IF Modify THEN Files.Rename(dst, bak, res) ELSE res := 1 END; (* ignore res *)
IF Modify THEN
CopyFile(sf, df); Files.Register(df);
Files.SetDate(df, srctime, srcdate); Files.Close(df)
ELSE
Texts.WriteString(w, " modify disabled")
END;
IF res = 0 THEN
Texts.WriteString(w, " ("); Texts.WriteString(w, bak);
Texts.WriteString(w, " created)")
END
ELSE
Texts.WriteString(w, " create failed")
END
END
ELSE
Texts.WriteString(w, " open failed")
END
END ImportCopyFile;
PROCEDURE Importer(path, name: ARRAY OF CHAR; srctime, srcdate, size: LONGINT; attr: SET);
VAR ext: ARRAY 8 OF CHAR; src, dst: FileDir.FileName;
BEGIN
IF ~(FileDir.Directory IN attr) THEN
COPY(path, src); Append("/", src); Append(name, src);
Texts.WriteString(w, src);
SplitPath(name, dummy, dst, ext);
IF ext = CvsExt THEN
Texts.WriteString(w, " => "); Texts.WriteString(w, dst);
IF Files.Old(dst) # NIL THEN
ImportUpdateCvsFile(src, dst, srctime, srcdate)
ELSE
ImportNewCvsFile(src, dst, srctime, srcdate)
END
ELSIF ext = BakExt THEN
Texts.WriteString(w, " ignored")
ELSE
Append(ext, dst);
Texts.WriteString(w, " => "); Texts.WriteString(w, dst);
ImportCopyFile(src, dst, srctime, srcdate)
END;
Texts.WriteLn(w)
END
END Importer;
PROCEDURE Import*; (** workingdir *)
VAR s: Texts.Scanner;
BEGIN
Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
IF s.class IN {Texts.Name, Texts.String} THEN
FileDir.EnumerateFiles(s.s, "*", TRUE, Importer);
Texts.Append(Oberon.Log, w.buf)
END
END Import;
PROCEDURE ExportCvsFile(src, dst: ARRAY OF CHAR; dsttime, dstdate: LONGINT);
VAR
t: Texts.Text; sf, df: Files.File; r: Files.Rider; srctime, srcdate, lost: LONGINT;
BEGIN
sf := Files.Old(src);
IF sf # NIL THEN
Files.GetDate(sf, srctime, srcdate);
IF (srctime # dsttime) OR (srcdate # dstdate) THEN
NEW(t); Texts.Open(t, src);
df := Files.New(dst);
IF df # NIL THEN
Files.Set(r, df, 0);
ExportText(t, r, lost);
IF ~FilesEqual(Files.Old(dst), df) THEN
Files.Register(df);
Files.SetDate(df, srctime, srcdate); Files.Close(df);
IF lost # 0 THEN
Texts.WriteString(w, " lost "); Texts.WriteInt(w, lost, 1);
Texts.WriteString(w, " object(s)")
END
ELSE
Files.SetDate(sf, dsttime, dstdate); Files.Close(sf);
Texts.WriteString(w, " no change")
END
ELSE
Texts.WriteString(w, " create failed")
END
ELSE
Texts.WriteString(w, " timestamps match")
END
ELSE
Texts.WriteString(w, " open failed")
END
END ExportCvsFile;
PROCEDURE Exporter(path, name: ARRAY OF CHAR; dsttime, dstdate, size: LONGINT; attr: SET);
VAR ext: ARRAY 8 OF CHAR; src, dst: FileDir.FileName;
BEGIN
IF ~(FileDir.Directory IN attr) THEN
COPY(path, dst); Append("/", dst); Append(name, dst);
SplitPath(name, dummy, src, ext);
IF ext = CvsExt THEN
Texts.WriteString(w, src); Texts.WriteString(w, " => ");
Texts.WriteString(w, dst);
ExportCvsFile(src, dst, dsttime, dstdate)
ELSIF ext = BakExt THEN
Texts.WriteString(w, name); Texts.WriteString(w, " ignored")
ELSE
Append(ext, src);
Texts.WriteString(w, src); Texts.WriteString(w, " => ");
Texts.WriteString(w, dst);
%!Color,01
Texts.WriteString(w, " todo")
%!Color,0F
END;
Texts.WriteLn(w)
END
END Exporter;
PROCEDURE Export*; (** workingdir *)
VAR s: Texts.Scanner;
BEGIN
Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
IF s.class IN {Texts.Name, Texts.String} THEN
FileDir.EnumerateFiles(s.s, "*", TRUE, Exporter);
Texts.Append(Oberon.Log, w.buf)
END
END Export;
BEGIN
NEW(root);
Texts.OpenWriter(w);
hex := "0123456789ABCDEF";
(* plain characters *)
FOR init := 0 TO 1FH DO isPlainCh[init] := FALSE END;
isPlainCh[9] := TRUE; isPlainCh[0AH] := TRUE;
FOR init := 20H TO 7EH DO isPlainCh[init] := TRUE END;
isPlainCh[25H] := FALSE;
FOR init := 7FH TO 0FFH DO isPlainCh[init] := FALSE END;
(* string characters *)
FOR init := 0 TO 20H DO isStrCh[init] := FALSE END;
FOR init := 21H TO 7EH DO isStrCh[init] := TRUE END;
isStrCh[22H] := FALSE; isStrCh[25H] := FALSE; isStrCh[2CH] := FALSE; isStrCh[3DH] := FALSE;
FOR init := 7FH TO 0FFH DO isStrCh[init] := FALSE END
END CvsClient.
(*
Assume:
o sources in repository on server (in ASCII/CvsClient format)
o CVS working directory contains local copy (in ASCII/CvsClient format)
o Oberon directory contains local copy (in Oberon format)
1. Checkout latest version
o On CVS host OS: cvs login/cvs checkout to working directory
o CvsClient.Import
o do not overwrites local changes, but give merge opportunity
CvsClient.Add:
create file in working directory
CvsClient.Delete:
delete file in working directory
CVS commands: