-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUPNODES.PAS
1591 lines (1531 loc) · 77.3 KB
/
UPNODES.PAS
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
PROGRAM updnodes(oldbase,delta,newbase,sysprint);
(*- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -*)
(* *)
(*COPYRIGHT: *)
(* Gesellschaft fuer Mathematik und Datenverarbeitung mbH *)
(* Institut fuer informationstechnische Infrastrukturen *)
(* Bereich Bonn *)
(* D-5300 Bonn 2 *)
(* *)
(* This program is written to support the EARN network, it may *)
(* be used and copied freely in the network and any other non *)
(* commercial network as long as this header remains intact. *)
(* The program may NOT be used to support any military activities *)
(* in any way. *)
(* *)
(*DISCLAIMER: *)
(* Although the program has been tested by the author and other *)
(* people, no warranty is made by the author or by GMD about *)
(* correct function of the program. The author or GMD cannot be *)
(* held for any damage the program may cause. *)
(* *)
(* Maintenance or developments may or may not be available. No *)
(* promise of such support or enhancement can be deduced anyhow. *)
(* *)
(* *)
(*NAME: *)
(* *)
(* U P D N O D E S *)
(* *)
(* *)
(* *)
(*FUNCTION/OPERATION: Most of the following is stolen from B. Pasch *)
(* *)
(* UPDNODES is a tool for the EARN node management. *)
(* *)
(* GENODUPD at a central site to build an update file, and *)
(* UPDNODES to apply the updates to the old version nodes file at *)
(* various sites in the network. *)
(* *)
(* Processing is as follows (see also examples below): *)
(* *)
(* 1) At a central site a new nodes file is built using already *)
(* available programs. An old version of the nodes file is also *)
(* available. Both versions contain checksums in their entries *)
(* and both do also contain a VERSyymm entry which describes the *)
(* version of its file. The version entries must contain *)
(* checksums for themselves and a total checksum for the entire *)
(* file they belong to. *)
(* *)
(* 2) GENODUPD is used to build the 'delta' file VERSyymm UPDNOD by *)
(* comparing the old and new version nodes file and writing the *)
(* differences into the 'delta' file: *)
(* *)
(* a) An UPDNODES statement that requires a certain level of the *)
(* UPDNODES program. *)
(* b) The version number of the new file (name of version entry) *)
(* is placed into a NEWVERSION or NEWBASE statement generated *)
(* by GENODUPD. The version numbers found in the update *)
(* history of the old file are used to define the *)
(* prerequisites for the update. *)
(* c) A DEL statement for the old VERSyymm entry is written. *)
(* d) A new VERSyymm entry with the new version number is built *)
(* and written as an ADD request. This VERSyymm entry contains *)
(* a checksum for itself (:cks tag) plus a total checksum *)
(* (:totcks tag) for the entire new nodes file. It contains *)
(* also an updated history. *)
(* e) The old and new nodes file are compared, entry by entry, *)
(* and if a difference is found appropriate update information *)
(* is written into the update file. The VERSyymm entries in *)
(* old and new file are ignored in this compare process. *)
(* *)
(* ADD statements plus the complete information about an entry *)
(* are written for new nodes. *)
(* REP statements with only the changed tags are written for *)
(* nodes which have been updated. *)
(* DEL statements with the node tag only, are written for *)
(* deleted entries. *)
(* The ADD and REP statements contain also the new checksum *)
(* value for the corresponding entry. *)
(* *)
(* 3) The update file is shipped to all locations which have a need *)
(* for it. *)
(* *)
(* 4) These sites use the UPDNODES program to apply the updates to *)
(* their copy of the old version nodes file. *)
(* *)
(* 5) When the UPDNODES program is run it performs the following: *)
(* *)
(* a) Reads any "prologue" statements: Currently only UPDNODES *)
(* is supported. The program checks whether it runs at least *)
(* at the requested maintenance level. This feature is not *)
(* available in version 1.2. PLease ensure that your UPDNODES *)
(* programs runs at least at level 1.3. *)
(* a) Reads the NEWVERSION or NEWBASE control statement in the *)
(* update file. Compares the prerequisites defined in this *)
(* statement with the information found in the VERSyymm entry *)
(* of the old nodes file (update history). If the *)
(* prerequisites are not fulfilled the update is terminated. *)
(* *)
(* Note: In the current version of UPDNODES this is not done. *)
(* The initial action(s) up to the first DEL/ADD for the *)
(* version entry are ignored. *)
(* Instead of that it is assumed that the first two node *)
(* entry may be VERSnnnn and/or LINKSnnn. *)
(* *)
(* b) Reads the entire old nodes file and does a checksum *)
(* verification on all entries (including the VERSyymm entry *)
(* which is also check- sum protected). It builds also a total *)
(* checksum over all entries and compares this value with the *)
(* one saved in the VERSyymm entry. If there is an error in *)
(* the checksum verification the update is cancelled. *)
(* c) Adds and deletes complete entries as specified in the *)
(* update file. For replace requests: adds, replaces or *)
(* deletes the individual tags specified with the REP request. *)
(* The version entry is placed at the beginning of the file. *)
(* Note: In the current version of UPDNODES b) and c) are done *)
(* in one pass. If the program finds a wrong checksum, the *)
(* program warns about that, and continues. The new entry will *)
(* contain the computed checksum. *)
(* *)
(* d) Verifies in the newly established file the checksum of each *)
(* entry as well as the total checksum to ensure that the *)
(* update was ok and no unallowed modifications were made to *)
(* the update file. *)
(* *)
(* For the format of version entries and update statements see the *)
(* following examples. *)
(* *)
(* Example: *)
(* *)
(* 'old' contains: *)
(* --------------- *)
(* :node.VERS8603 ...... *)
(* :remark1.BASE(8601) 86/01/14 12:47:15 *)
(* :remark2.VERSION(8602) PRE(8601) 86/02/09 17:18:09 *)
(* :remark3.VERSION(8603) PRE(8601 8602) 86/03/11 11:27:18 *)
(* :cks.11111 :totcks.22222 *)
(* :node.nodename ----- (normal node entries) ----- :cks.nnnnn *)
(* *)
(* 'new' contains: *)
(* --------------- *)
(* :node.VERS8604 ...... *)
(* :cks.33333 :totcks.44444 *)
(* :node.nodename ----- (normal node entries) ----- :cks.nnnnn *)
(* *)
(* After running GENODUPD with option NEWVERS 'delta' will contain: *)
(* ---------------------------------------------------------------- *)
(* UPDNODES(1.3) *)
(* NEWVERSION(8604) PRE(8601 8602 8603) *)
(* DEL VERS8603 *)
(* ADD VERS8604 ...... *)
(* :remark1.BASE(8601) 86/01/14 12:47:15 *)
(* :remark2.VERSION(8602) PRE(8601) 86/02/09 17:18:09 *)
(* :remark3.VERSION(8603) PRE(8601 8602) 86/03/11 11:27:18 *)
(* :remark4.VERSION(8604) PRE(8601 8602 8603) 86/04/11 12:43:17 *)
(* :cks.55555 :totcks.44444 *)
(* ADD nodename --- (for new nodes in 'new') --- :cks.nnnnn *)
(* REP nodename --- (for changed nodes in 'new') --- :cks.nnnnn *)
(* DEL nodename (for nodes missing in 'new') *)
(* *)
(* After running UPDNODES with 'delta' against 'old' (VERS8603) *)
(* to create a 'new' file, 'new' will contain: *)
(* ------------------------------------------ *)
(* :node.VERS8604 ...... *)
(* :remark1.BASE(8601) 86/01/14 12:47:15 *)
(* :remark2.VERSION(8602) PRE(8601) 86/02/09 17:18:09 *)
(* :remark3.VERSION(8603) PRE(8601 8602) 86/03/11 11:27:18 *)
(* :remark4.VERSION(8604) PRE(8601 8602 8603) 86/04/11 12:43:17 *)
(* :cks.55555 :totcks.44444 *)
(* :node.nodename ----- (normal node entries) ----- :cks.nnnnn *)
(* *)
(* Next month this 'new' will be used as 'old' and so on. *)
(* *)
(* If GENODUPD is called with option NEWBASE 'delta' will contain: *)
(* --------------------------------------------------------------- *)
(* UPDNODES(1.3) *)
(* NEWBASE(8604) PRE(8601 8602 8603) *)
(* DEL VERS8603 *)
(* ADD VERS8604 ...... *)
(* :remark1.BASE(8604) 86/04/11 12:43:17 *)
(* :cks.66666 :totcks.44444 *)
(* ADD nodename --- (for new nodes in 'newfile') --- :cks.nnnnn *)
(* REP nodename --- (for changed nodes in 'newfile') --- :cks.nnnnn*)
(* DEL nodename (for nodes missing in 'newfile') *)
(* *)
(* After running UPDNODES with this 'delta', 'new' will contain: *)
(* ------------------------------------------------------------- *)
(* :node.VERS8604 ...... *)
(* :remark1.BASE(8604) 86/04/11 12:43:17 *)
(* :cks.66666 :totcks.44444 *)
(* :node.nodename --- (normal node entries) --- :cks.nnnnn *)
(* *)
(* *)
(* *)
(* Description of the update statements in the 'delta' file: *)
(* --------------------------------------------------------- *)
(* *)
(* The ADD statements will always contain a full entry, i.e. all *)
(* tags which got data assigned plus the checksum tag for this *)
(* entry. *)
(* *)
(* The REP statements in the 'delta' file will not contain the full *)
(* entry which is to be replaced but will contain only the tags *)
(* which changed. New tags and changed tags will be placed together *)
(* with their corresponding data in the REP statement. Deleted *)
(* tags will be represented by a tagname without data (null-string). *)
(* There will also be a checksum tag with the checksum for the *)
(* replaced entry. *)
(* *)
(* The DEL statements require nothing but the nodename. *)
(* *)
(* Note: The :node. tag identifier does not appear in the update *)
(* statements. The nodename is always the first word after *)
(* ADD, REP or DEL. This allows to use the update file also *)
(* if the nodename is identified by some other tag (e.g. :nick.). *)
(* *)
(* Checksums: *)
(* --------- *)
(* *)
(* Since this update concept is sensitive to unallowed modifications *)
(* in the old nodes file and in the update file, the entries in the *)
(* file must be checked before and after the updates are applied in *)
(* order to detect such modifications. For this purpose a checksum *)
(* per entry and a total checksum are maintained in the file and new *)
(* checksums are delivered with the update file. *)
(* *)
(* The checksum per entry includes the nodename and all tags of this *)
(* entry except the checksum tag (:cks tag). The checksum of each *)
(* tag is calculated individually. It includes tagname and *)
(* tagvalue, e.g. ':site.Univ. of Heidelberg', except for the *)
(* nodename where only the tagdata is checksummed but not the tag *)
(* identifier (:node.). All blanks in the tagdata are counted. *)
(* Trailing blanks are ignored. *)
(* *)
(* The checksum is built after an algorithm which ensures that data *)
(* modifications, bit errors and exchange of characters or words *)
(* is detected with a high probablity (we use a 16 bit checksum, *)
(* probability of undetected error = 1/65535). The checksum of the *)
(* complete entry is then built by combining the checksums of each *)
(* tag via Exclusive Or. The result is converted to decimal *)
(* (0-65535) and stored in the :cks tag. *)
(* *)
(* The total checksum is built by calculating the checksum of only *)
(* the nodename of each entry (without the tag identifier :node.) *)
(* and combining them all via Exclusive Or. The decimal equivalent *)
(* of this total checksum is stored in the :totcks tag of the *)
(* version entry. *)
(* *)
(* Note the :cks and :totcks tags are never included in checksum *)
(* construction. *)
(* *)
(* *)
(* *)
(* *)
(*ENTRY POINTS: *)
(* UPDNODES *)
(* The program can be called as a CMS command processor (VM), *)
(* or as an MVS-"main-program". *)
(* *)
(* *)
(*INPUT: *)
(* The program accepts "invocation parameters": *)
(* In CMS the parameters as specified as positional parameters *)
(* in the command invocation, under MVS the parameters *)
(* are specified in the OS parameter list. *)
(* *)
(* The value controls the level of information produced on *)
(* FILE SYSPRINT: *)
(* *)
(* Default processing is that error messages will be written *)
(* on SYSPRINT. *)
(* *)
(* QUIET *)
(* Do not produce any output on SYSPRINT. *)
(* *)
(* SERMON *)
(* Create a detailed processing log *)
(* *)
(* *)
(* (I'm still working on some parameters to control the *)
(* amount of work done by the program. Any comments are *)
(* welcome.) *)
(* *)
(*OUTPUT: *)
(* If running in "quiet" mode no extra output (except to *)
(* file NEW, of course) is procuded. If running in "sermon" *)
(* mode, a log of all actions is created on file SYSPRINT, *)
(* if not running in "quiet" mode, error messages are *)
(* written to file SYSPRINT. *)
(* *)
(*DD-STATEMENTS/DATA SETS: *)
(* OLD : contains the old data base *)
(* NEW : will contain the new data base *)
(* DELTA : contains the update requests *)
(* *)
(* *)
(*NORMAL EXIT: *)
(* Standard PASCAL Return *)
(* *)
(* *)
(*ERROR EXIT: *)
(* NONE *)
(* *)
(* *)
(*RETURN CODES: *)
(* 0 Function successful *)
(* 1 Delta empty *)
(* 2 Invalid total checksum *)
(* 3 Invalid checksum in major *)
(* 4 Major tag not at beginning *)
(* 5 Minor identical to major *)
(* 6 Value missing for action *)
(* 7 No major in data base *)
(* 8 Major tag too long *)
(* 9 Old base out of sort order *)
(* 10 Delta out of sort order *)
(* 11 Action invalid *)
(* 12 Invalid delta start *)
(* 13 Updnodes not smart enough *)
(* *)
(* *)
(*EXTERNAL ROUTINES: *)
(* CHKSUM A program to generate checksums *)
(* *)
(* *)
(*RELATED PROGRAMS: *)
(* GENODUPD A program that creates a delta file *)
(* *)
(* *)
(*STORAGE: *)
(* PROGRAM: 70K *)
(* DYNAMIC: Not calculated *)
(* *)
(* *)
(*LOAD MODULE CREATION: *)
(* SOURCE LANGUAGE : PASCAL/VS *)
(* COMPILE LIBRARIES : None *)
(* COMPILE PARAMETERS : *)
(* *)
(* *)
(* DESTINATION LIBRARIES: The program is available from NETSERV *)
(* as UPDNODES MODULE (CMS-version) *)
(* or UPDNODES OBJ (MVS-version). *)
(* *)
(* GENERATING DECK : The program is generated using the *)
(* PASCALVS and PASCMOD execs/clists *)
(* *)
(* *)
(*STATUS: *)
(* CHANGE LEVEL - 1.0 June 1986 *)
(* 1.1 Some uninitialized variable )-: 860814*)
(* 1.2 Enhanced "error recovery" 860816*)
(* 1.3 Error when adding HIGH nodes 870515*)
(* Small enhancements *)
(* *)
(* *)
(*NOTES: The following "invocation tools" are available from *)
(* NETSERV: *)
(* *)
(* UPDNODES EXEC : A CMS REXX program *)
(* For MVS no tools are available. The number of *)
(* required actions is trivial compared to the possible *)
(* variations to do that: It seems superfluous to the *)
(* author of UPDNODES to write a CLIST, a JCL-PROC that *)
(* contains a set of variables for all DD-statements. *)
(* Default reactions to error return codes are also *)
(* trivial. Another reason not to "support" MVS is the *)
(* note at the end of paragraph "INPUT". *)
(* *)
(* The CMS-EXEC is only one hint of how to invoke the *)
(* program, too, taken from a NETSERV internal procedure. *)
(* *)
(* Caution: When you RECEIVE the UPDNODES OBJ file *)
(* with TSO/E, don't forget to specify a parameter that *)
(* matches the maximum BLKSIZE for the MVS linkage editor. *)
(* (3120 is the value, isn't it.) *)
(* *)
(* NETSERV does not send a BLKSIZE NETDATA tag in the *)
(* file and the TSO/E RECEIVE default is a bad value. *)
(* *)
(* *)
(*AUTHOR: Peter Sylvester <GRZ027@DBNGMD21> *)
(* Gesellschaft fuer Mathematik und Datenverarbeitung mbH *)
(* Riemenschneiderstrasse 11 *)
(* D-5300 Bonn 2 *)
(* Federal Republic of Germany *)
(* *)
(* *)
(*- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -*)
%page ;
(*********************************************************************)
(* *)
(* environment definitions *)
(* *)
(*********************************************************************)
STATIC copyright : STRING(255) ;
VALUE copyright :=
'Copyright GMD Bonn 1986, 1987 all rights reserved';
STATIC name_version_date : STRING(255) ;
VALUE name_version_date := 'UPDNODES Version 1.3-15MAY87';
STATIC this_updnodes : STRING(3) ;
VALUE this_updnodes := '1.3';
CONST function_successful = 0;
delta_empty = 1;
invalid_total_checksum = 2;
invalid_checksum_in_major = 3;
major_tag_not_at_beginning = 4;
minor_identical_to_major = 5;
value_missing_for_action = 6;
no_major_in_data_base = 7;
major_tag_too_long = 8;
old_base_out_of_sort_order = 9;
delta_out_of_sort_order = 10;
action_invalid = 11;
invalid_delta_start = 12;
updnodes_not_smart_enough = 13;
VAR highest_retcode :INTEGER ;
maximum_retcode :INTEGER ;
VAR sysprint : TEXT ;
VAR sermon: BOOLEAN ;
quiet: BOOLEAN ;
trace: BOOLEAN ;
infolinemax: INTEGER ;
(*********************************************************************)
(* *)
(* This PROCEDURE initializes processing parameters. *)
(* *)
(* Note: This is still temporary. *)
(* *)
(*********************************************************************)
PROCEDURE init_environment;
BEGIN
infolinemax := 240; (* due to some reason that only Bert knows*)
(* change it to 1 if you want one tag per line *)
trace := FALSE; (* (PARMS = 'TRACE') *) ;
sermon := trace | (PARMS = 'SERMON') ;
quiet := (PARMS = 'QUIET') ;
highest_retcode := 0;
maximum_retcode := 999 ;
END (* init_environment *);
(*********************************************************************)
(* *)
(* This PROCEDURE logs the highest error code and sets it into *)
(* the external environment. *)
(* *)
(*********************************************************************)
PROCEDURE set_retcode;
BEGIN
IF (^quiet & (sermon | (highest_retcode > 0))) THEN
BEGIN
IF highest_retcode = 0 THEN
Writeln(sysprint,' :No errors found')
ELSE
Writeln(sysprint,highest_retcode:2,' was highest error code');
END ;
retcode(highest_retcode);
END ;
(*********************************************************************)
(* *)
(* This PROCEDURE logs a line if SERMON is active *)
(* *)
(*********************************************************************)
PROCEDURE sermon_line(line:STRING(255));
BEGIN
IF sermon THEN Writeln(sysprint,' :'||line) ;
END (* sermon_line *);
(*********************************************************************)
(* *)
(* This PROCEDURE logs an error line (and may abort program) *)
(* *)
(*********************************************************************)
LABEL abort_updnodes ;
PROCEDURE showerror(line:STRING(255);rc:INTEGER);
BEGIN
IF ^quiet THEN
IF rc = 0 THEN Writeln(sysprint,' :'||line)
ELSE Writeln(sysprint,rc:2,':'||line);
IF rc > highest_retcode THEN
highest_retcode := rc ;
IF Rc >= maximum_retcode THEN GOTO abort_updnodes
END;
(*********************************************************************)
(* *)
(* This PROCEDURE is not used at all. *)
(* *)
(*********************************************************************)
PROCEDURE traceline(line:STRING(255));
BEGIN
IF trace THEN Writeln(sysprint,'***'||line)
END;
(*********************************************************************)
(* *)
(* This FUNCTION returns a string of at least 10 characters. *)
(* *)
(*********************************************************************)
FUNCTION tn( name : STRING(64) ) : STRING(64) ;
BEGIN
IF length(name) >= 10 THEN tn := name
ELSE tn := SUBSTR(name||' ',1,10) ;
END (* tn *) ;
%page ;
(*********************************************************************)
(* *)
(* The data base contains a two level chain of data. *)
(* *)
(*********************************************************************)
TYPE
major_pointer = -> major ;
minor_pointer = -> minor ;
major = RECORD
next : major_pointer ;
name : STRING(64) ; (* major tag name *)
first : minor_pointer ; (* first minor tag *)
checksum : INTEGER
END ;
minor = RECORD
next : minor_pointer;
name : STRING(12); (* tag *)
minvalue : STRINGPTR (* value *)
END ;
VAR major_tag : STRING(64) ;
major_tag_length : INTEGER;
%page ;
(*********************************************************************)
(* *)
(* This FUNCTION searches for a minor entry with name *)
(* IF it doe not exist, a new entry is inserted appended. *)
(* *)
(* Note: minors are NOT in alphabetic order for now. *)
(* *)
(*********************************************************************)
FUNCTION misearch( inlist : major_pointer;
name : STRING(12) ;
minvalue : STRING(255)
) : minor_pointer ;
VAR
min : minor_pointer;
pred : minor_pointer;
BEGIN
min := [email protected] ;
pred := nil;
WHILE (min ^= nil)
& ([email protected] ^= name) DO
BEGIN
pred := min; (* keep that in mind *)
min := [email protected]; (* try the next one *)
END;
IF min = nil THEN
BEGIN (* create new element in chain *)
new(min) ;
[email protected] := name;
[email protected] := nil ;
IF pred ^= nil THEN BEGIN
[email protected] := min ;
END ELSE BEGIN
[email protected] := min ;
END ;
END (* existing: forget value *)
ELSE BEGIN
dispose([email protected]);
END ;
new([email protected],length(minvalue)); (* allocate storage and *)
[email protected]@ := minvalue ; (* set new value *)
misearch := min ;
END (* misearch *) ;
%page ;
(*********************************************************************)
(* *)
(* This FUNCTION deletes a minor entry and returns the next element *)
(* *)
(*********************************************************************)
FUNCTION mindel (min : minor_pointer ): minor_pointer;
BEGIN
mindel := [email protected] ;
dispose([email protected]); (* dispose the value first *)
dispose(min) (* and then the element *)
END (* of mindel *) ;
(*********************************************************************)
(* *)
(* This FUNCTION tries to find a minor with name and pattern *)
(* *)
(* IF pattern is '' no value match is necessary. This is not *)
(* a restriction because the data base NEVER contains empty tags. *)
(* *)
(*********************************************************************)
FUNCTION minfind( inlist : major_pointer;
name : STRING(12);
pattern: STRING(255)
) : minor_pointer;
VAR
min : minor_pointer;
BEGIN
minfind := nil;
IF inlist ^= nil THEN BEGIN
min := [email protected] ;
WHILE min ^= nil DO
IF trim([email protected]) = trim(name) THEN BEGIN (* name found *)
IF (pattern = '') |
(trim([email protected]@) = trim(pattern))
THEN minfind := min ; (* return min entry *)
LEAVE
END ELSE min := [email protected]; (* try the next one *)
END
END (* minfind *) ;
%page ;
(*********************************************************************)
(* *)
(* This FUNCTION searches for a major entry with name. *)
(* IF it doesn't exist, a new entry is inserted in alphabetic order*)
(* *)
(*********************************************************************)
FUNCTION masearch( VAR inlist : major_pointer;
name : STRING(64)
) : major_pointer ;
VAR
maj : major_pointer;
pred : major_pointer;
BEGIN
maj := inlist;
pred := nil;
WHILE maj ^= nil DO
IF [email protected] = name THEN LEAVE (* ok, have it *)
ELSE IF [email protected] > name THEN
maj := nil (* too far in the alphabet ==> *)
ELSE BEGIN
pred := maj ;
maj := [email protected] ; (* try the next one *)
END;
IF maj = NIL THEN
BEGIN (* create new element in chain *)
new(maj);
[email protected] := name;
[email protected] := nil;
[email protected] := -1;
IF pred ^= nil THEN BEGIN
[email protected] := maj ;
END ELSE BEGIN
[email protected] := inlist ;
inlist := maj ;
END ;
END ;
masearch := maj ;
END (* masearch *) ;
%page ;
(*********************************************************************)
(* *)
(* This PROCEDURE deletes a major entry IF it exists (or the first *)
(* in list IF name = '' *)
(* *)
(*********************************************************************)
PROCEDURE majdel( VAR inlist : major_pointer;
name : STRING(12)
);
VAR
maj : major_pointer;
pred : major_pointer;
min : minor_pointer;
BEGIN
maj := inlist ;
pred := nil;
IF name ^= '' THEN
WHILE (maj ^= nil)
& ([email protected] ^= name) DO
BEGIN (* too far in the alphabet ==> *)
pred := maj; (* keep that in mind *)
maj := [email protected]; (* try the next one *)
END;
IF maj ^= nil THEN
BEGIN
IF pred ^= nil THEN
[email protected] := [email protected] (* unchain in list *)
ELSE IF inlist ^= nil THEN
inlist := [email protected] ; (* or unchain first (IF any) *)
min := [email protected]; (* dispose chain *)
WHILE min ^= nil DO
min := mindel(min);
dispose(maj); (* and then the entry itself *)
END
END (* majdel *) ;
%page ;
(*********************************************************************)
(* *)
(* This PROCEDURE computes a checksum. *)
(* *)
(* oldsum and newsum can be the same variable. *)
(* *)
(*********************************************************************)
PROCEDURE chksum(const osum:INTEGER;
const dSTRING:STRING(255);
var nsum:INTEGER); fortran;
(*********************************************************************)
(* *)
(* The following PROCEDURE validates one major entry and compares *)
(* the checksum. *)
(* *)
(* Note: A new checksum is assigned IF it does not yet exist. *)
(* *)
(*********************************************************************)
PROCEDURE val_maj(maj : major_pointer ;(* major entry to be validated*)
ofbase:STRING(255); (* text to describe the data *)
VAR totalsum: INTEGER (* an overall checksum *)
);
VAR
min : minor_pointer ;
checksum: INTEGER ;
tag : STRING(255) ;
BEGIN
IF maj = Nil THEN RETURN;
(* Primary tag included in sum*)
tag := ':'||major_tag||'.'||[email protected]||' ' ;
chksum(totalsum,[email protected],totalsum);
chksum(0,[email protected],checksum);
min := [email protected] ; (* start with first tag *)
WHILE min ^= nil DO (* loop thru all minor tags *)
BEGIN
IF [email protected] ^= 'cks' THEN BEGIN (* checksum key not included *)
IF ([email protected] ^= 'totcks')&
([email protected]@ ^= '')THEN BEGIN (* ignore empty keys *)
tag := ':'||[email protected]||'.'||[email protected]@||' ';
chksum(checksum,tag,checksum);
END
END
ELSE IF (*[email protected] = -1*)
(ltrim([email protected]@) ^= 'NOCKS') THEN
(* extract previous sum *)
Readstr([email protected]@,[email protected]) ;
min := [email protected]
END ;
(* see what we have, report *)
IF [email protected] ^= checksum THEN
BEGIN
IF [email protected] ^= -1 THEN
BEGIN
Writestr(tag,[email protected]:-5);
showerror('Checksum '||tag
||' for entry '||[email protected]||' '||ofbase
||' is incorrect,',
invalid_checksum_in_major);
END ;
Writestr(tag,checksum:-5);
showerror('new checksum '||ltrim(tag)
||' assigned for entry '||[email protected]||' '||ofbase,0)
END ;
[email protected] := checksum; (* assign new checksum *)
END (* val_maj *) ;
%page ;
(*********************************************************************)
(* *)
(* The following procedure validates the total check sum against *)
(* the totalcks field in the version entry. *)
(* *)
(* Note: A new checksum is assigned IF it does not yet exist. *)
(* Currently this CANNOT be used because the new version entry *)
(* is already written out (one pass only!!!) *)
(* *)
(*********************************************************************)
PROCEDURE valtotal(versionp:major_pointer;
checksum:INTEGER;
ofbase:STRING(255));
VAR
min : minor_pointer ;
totalsum : INTEGER ;
cks : STRING(5);
cks2 : STRING(5);
BEGIN
IF versionp = NIL THEN RETURN ;
min := minfind(versionp,'totcks','');
IF (min ^= NIL) & (ltrim([email protected]@) ^= 'NOCKS') THEN
BEGIN
Readstr([email protected]@,totalsum) ;
IF (totalsum ^= checksum) THEN
BEGIN
Writestr(cks,checksum:-5);
Writestr(cks2,totalsum:-5);
showerror('Total checksum '||ofbase||' '||cks2||
' is incorrect, computed value is: '||cks,
invalid_total_checksum);
END
END ELSE BEGIN
Writestr(cks,checksum:-5);
showerror('Total checksum '||ofbase||' is: '||cks,0);
(* just inform *)
END ;
END (* valtotal *) ;
%page ;
(*********************************************************************)
(* *)
(* The following PROCEDURE creates an entry in the new network file*)
(* *)
(* It is assumed that a tag with value is never longer than the *)
(* output line length. *)
(* An cks tag will be added if there was no previous one. *)
(* The checksum written is always the computed one. *)
(* It is assumed the output file is already reset. *)
(* *)
(*********************************************************************)
VAR
newbase : TEXT ; (* output file *)
PROCEDURE show_maj(maj : major_pointer);
VAR
min : minor_pointer ;
line : STRING(255) ;
tag : STRING(255) ;
checksum_needed : BOOLEAN;
BEGIN
checksum_needed := TRUE; (* still need checksum *)
IF maj = nil THEN RETURN;
line := ':'||major_tag||'.'
||[email protected]; (* init line with major tag *)
min := [email protected] ; (* start with first minor *)
WHILE min ^= nil DO (* loop thru all tags *)
BEGIN
IF [email protected]@ ^= '' THEN (* empty tags not shown *)
BEGIN
IF [email protected] = 'cks' THEN
BEGIN
Writestr(tag,' :cks.',[email protected]:-5);
tag:=trim(tag);
checksum_needed := FALSE (* Don't show it twice *)
END ELSE
(* create tag image *)
tag := ' :'||[email protected]||'.'||[email protected]@;
IF length(line) + length(tag) >= infolinemax THEN
BEGIN (* doesn't fit in line *)
Writeln(newbase,line) ; (* dump previous tags first *)
line := ' ' ; (* init new line *)
END ;
line := line||tag ; (* append tag to line *)
END ;
min := [email protected] (* try next tag *)
END ;
(* add a cks if needed *)
IF checksum_needed THEN
BEGIN
Writestr(tag,' :cks.',[email protected]:-5); tag:=trim(tag);
IF length(line) + length(tag) >= infolinemax THEN
BEGIN
Writeln(newbase,line) ; (* checksum needs some place*)
line := ' ';
END ;
END
ELSE tag := '';
Writeln(newbase,line,tag) ; (* last line and end *)
(* sermon_line('Entry '||tn([email protected]),1,8)||' done'); *)
END (* show_maj *) ;
(*********************************************************************)
(* *)
(* This PROCEDURE reports the status of a major *)
(* *)
(*********************************************************************)
PROCEDURE report_maj(maj:major_pointer;message:STRING(255));
BEGIN
IF maj ^= Nil THEN
sermon_line('Entry '||tn([email protected])||' '||message);
END (* report_maj *);
%page ;
(*********************************************************************)
(* *)
(* The following FUNCTION parses a line and merges minor entries. *)
(* Most of the code has been stolen from Roland Wolf's *)
(* GENROUTS program. *)
(* *)
(*********************************************************************)
FUNCTION parselin(VAR line : STRING(255);maj : major_pointer):BOOLEAN;
VAR
tag : STRING(255); (* "tag" of an entry *)
tagend : INTEGER; (* marks END of tag *)
tagstart : INTEGER; (* marks start of tag *)
tagval : STRING(255); (* value of the tag *)
tagvalend : INTEGER; (* marks END of that value *)
min : minor_pointer;
BEGIN
tagvalend:= 2;
parselin := True;
REPEAT (* parse a line *)
IF line = '' THEN LEAVE;
IF tagvalend = 2 THEN (* parse ':tag.tagvalue' *)
tagstart := index(substr(line,1,length(line)),':')
ELSE
tagstart := index(substr(line,tagvalend-1,length(line)
- tagvalend + 2),' :') + tagvalend - 1;
tagend := index(substr(line,tagstart,length(line)
- tagstart + 1),'.') + tagstart - 1;
tagvalend:= index(substr(line,tagend ,length(line)
- tagend + 1),' :') + tagend;
IF tagvalend = tagend THEN tagvalend := length(line) + 1;
tag := substr(line,tagstart+1,tagend-tagstart-1);
IF tagend = length(line) THEN tagval := '' ELSE
tagval := substr(line,tagend+1,tagvalend-tagend-1);
(* OK, we have 'tag' and 'tagval' *)
tagval := trim(tagval) ;
IF tag = major_tag THEN
BEGIN
parselin := False;
RETURN;
END ;
min := misearch(maj,tag,tagval);
UNTIL tagvalend = length(line) + 1;
line := ''
END (* parselin *) ;
%page ;
(*********************************************************************)
(* *)
(* The following routines support parsing the base file. *)
(* *)
(*********************************************************************)
VAR
oldbase : TEXT ; (* inputfile *)
baseline : STRING(255) ;
(*********************************************************************)
(* *)
(* The following FUNCTION checks for a major tag. *)
(* It is aclled only at "line start". *)
(* *)
(*********************************************************************)
FUNCTION havenick(line:STRING(255)):BOOLEAN;
BEGIN
havenick:=(length(line) >= major_tag_length+2)
& (substr(line,1,1) = ':')
& (substr(line,2,major_tag_length) = major_tag)
& ((substr(line,2+major_tag_length,1) = '.')
|(substr(line,2+major_tag_length,1) = ' '))
END (*have nick*) ;
(*********************************************************************)
(* *)
(* The following PROCEDURE read a line from the base. *)
(* *)
(*********************************************************************)
PROCEDURE getbase;
BEGIN
IF NOT Eof(oldbase) THEN Readln(oldbase,baseline);
baseline := trim(ltrim(baseline))
END ;
(*********************************************************************)
(* *)
(* The following FUNCTION merges all minor tags *)
(* into a data base entry. In fact the "merge" may just an addition*)
(* because only new entries are added. BUT: if the base would *)
(* contain DUPLICATE minor tags the last one would be used. *)
(* *)
(*********************************************************************)
FUNCTION mrgebase(maj:major_pointer):BOOLEAN;
VAR lineok: BOOLEAN;
BEGIN
lineok:= parselin(baseline,maj) ;
WHILE (lineok & NOT Eof(oldbase)) DO
BEGIN
getbase;
IF havenick(baseline) THEN LEAVE ;
lineok:= parselin(baseline,maj) ;
END ;
IF ^lineok THEN
showerror('Major tag not at beginning of line in old base',
major_tag_not_at_beginning);
mrgebase:=lineok ;
END (*mrgebase*);
(*********************************************************************)
(* *)
(* The following PROCEDURE skips minor tags from the base file *)
(* up to the next major. *)
(* *)
(*********************************************************************)
PROCEDURE skipbase;
BEGIN
WHILE (NOT Eof(oldbase) & NOT havenick(baseline)) DO