summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/support/macrosub.ada
blob: 81204fb0770854943dc149bab1e2481293f91162 (plain)
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
-- MACROSUB.ADA
--
--                             Grant of Unlimited Rights
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained 
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making 
--     this public release, the Government intends to confer upon all 
--     recipients unlimited rights  equal to those held by the Government.  
--     These rights include rights to use, duplicate, release or disclose the 
--     released technical data and computer software in whole or in part, in 
--     any manner and for any purpose whatsoever, and to have or permit others 
--     to do so.
--
--                                    DISCLAIMER
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED 
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE 
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-----------------------------------------------------------------------
--                                                                   --
--   THIS PROGRAM IS CALLED MACROSUB.  IT IS USED TO REPLACE THE     --
--   MACROS IN THE ACVC TEST SUITE WITH THEIR PROPER VALUES.  THE    --
--   STEPS LISTED BELOW SHOULD BE FOLLOWED TO ENSURE PROPER RUNNING  --
--   OF THE MACROSUB PROGRAM:                                        --
--                                                                   --
--           1) Edit the file MACRO.DFS (included with the testtape) --
--              and insert your macro values.  The macros which use  --
--              the value of MAX_IN_LEN are calculated automatically --
--              and do not need to be entered.                       --
--                                                                   --
--           2) Create a file called TSTTESTS.DAT which includes all --
--              of the .TST test file names and their directory      --
--              specifications, if necessary.  If a different name   --
--              other than TSTTESTS.DAT is used, this name must be   --
--              substituted in the MACROSUB.ADA file.                --
--                                                                   --
--           3) Compile and link MACROSUB.                           --
--                                                                   --
--           4) Run the MACROSUB program.                            --
--                                                                   --
--   WHEN THE PROGRAM FINISHES RUNNING, THE MACROS WILL HAVE BEEN    --
--   REPLACED WITH THE APPROPRIATE VALUES FROM MACRO.DFS.            --
--                                                                   --
--                                                                   --
--                                                                   --
-- HISTORY:                                                          --
--     BCB 04/17/90  CHANGED MODE OF CALC_MAX_VALS TO OUT.  CHANGED  --
--                   VALUE OF MAX_VAL_LENGTH FROM 512 TO 400.  ADDED --
--                   EXCEPTION HANDLER SO PROGRAM DOES NOT CRASH IF  --
--                   AN EXCEPTION IS RAISED.  ADDED MESSAGES TO      --
--                   REPORT PROGRESS OF PROGRAM.  CHANGED PROGRAM SO --
--                   IT DOES NOT ABORT IF A FILE CANNOT BE FOUND.    --
--                   MODIFIED PROGRAM SO IT ACCEPTS FILENAMES WITH   --
--                   VERSION NUMBERS.                                --
-----------------------------------------------------------------------

WITH TEXT_IO;
USE TEXT_IO;

PACKAGE DEFS IS

-----------------------------------------------------------------------
--                                                                   --
--   THIS PACKAGE IS USED BY MACROSUB.ADA, PARSEMAC.ADA, AND BY      --
--   GETSUBS.ADA.  THE PACKAGE CONTAINS VARIABLE DECLARATIONS WHICH  --
--   NEED TO BE KNOWN BY ALL OF THE PROCEDURES AND PACKAGES WHICH    --
--   MAKE UP THE PROGRAM.                                            --
--                                                                   --
-----------------------------------------------------------------------

     MAX_VAL_LENGTH : CONSTANT INTEGER := 400;

     SUBTYPE VAL_STRING IS STRING (1..MAX_VAL_LENGTH);

     TYPE REC_TYPE IS RECORD
          MACRO_NAME : STRING (1..80);
          NAME_LENGTH, VALUE_LENGTH : INTEGER;
          MACRO_VALUE : VAL_STRING;
     END RECORD;

     TYPE TABLE_TYPE IS ARRAY (1..100) OF REC_TYPE;

     SYMBOL_TABLE : TABLE_TYPE;

     NUM_MACROS : INTEGER;

END DEFS;

WITH TEXT_IO;
USE TEXT_IO;
WITH DEFS;
USE DEFS;

PACKAGE GETSUBS IS

------------------------------------------------------------------------
--                                                                    --
--  THIS PACKAGE IS USED BY MACROSUB.ADA FOR READING FROM MACRO.DFS   --
--  THE VALUES FOR THE MACRO SUBSTITUTIONS FOR A TEST TAPE.           --
--                                                                    --
------------------------------------------------------------------------

     MAC_FILE, LINE_LEN : EXCEPTION;

     PROCEDURE CALC_MAX_VALS(INDEX, LENGTH, MAX_IN_LEN : IN INTEGER;
                             CALCULATED : OUT BOOLEAN);

     PROCEDURE FILL_TABLE;

END GETSUBS;

PACKAGE BODY GETSUBS IS

-----------------------------------------------------------------------
--                                                                   --
--    PROCEDURE CALC_MAX_VALS CALCULATES THE VALUE FOR THE MACRO     --
--    READ FROM MACRO.DFS IF ITS LENGTH IS EQUAL OR NEARLY EQUAL TO  --
--    MAX_IN_LEN.  IT THEN RETURNS A FLAG SET TO TRUE IF A VALUE WAS --
--    CALCULATED, FALSE IF ONE WAS NOT.                              --
--                                                                   --
-----------------------------------------------------------------------

     PROCEDURE CALC_MAX_VALS(INDEX, LENGTH, MAX_IN_LEN : IN INTEGER;
                             CALCULATED : OUT BOOLEAN) IS

     BEGIN

          IF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) = "BIG_ID1"
               THEN SYMBOL_TABLE (INDEX).MACRO_VALUE (1..MAX_IN_LEN) :=
               (1..(MAX_IN_LEN-1) => 'A') & "1";
               CALCULATED := TRUE;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
               "BIG_ID2" THEN SYMBOL_TABLE (INDEX).MACRO_VALUE
               (1..MAX_IN_LEN) := (1..(MAX_IN_LEN-1) => 'A') & "2";
               CALCULATED := TRUE;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
               "BIG_ID3" THEN SYMBOL_TABLE (INDEX).MACRO_VALUE
               (1..MAX_IN_LEN) := (1..(MAX_IN_LEN + 1)/2 => 'A') & "3" &
               ((MAX_IN_LEN + 1)/2 + 2..MAX_IN_LEN => 'A');
               CALCULATED := TRUE;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
               "BIG_ID4" THEN SYMBOL_TABLE (INDEX).MACRO_VALUE
               (1..MAX_IN_LEN) := (1..(MAX_IN_LEN + 1)/2 => 'A') & "4" &
               ((MAX_IN_LEN + 1)/2 + 2..MAX_IN_LEN => 'A');
               CALCULATED := TRUE;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
               "BIG_STRING1" THEN SYMBOL_TABLE (INDEX).MACRO_VALUE
               (1..(MAX_IN_LEN + 1)/2 + 2) :=
                          '"' & (1..(MAX_IN_LEN + 1)/2 => 'A') & '"';
               CALCULATED := TRUE;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
               "BIG_STRING2" THEN SYMBOL_TABLE (INDEX).MACRO_VALUE
               (1..MAX_IN_LEN - (MAX_IN_LEN + 1)/2 + 2) :=
               '"' & (2..MAX_IN_LEN - (MAX_IN_LEN + 1)/2 => 'A') &
               '1' & '"';
               CALCULATED := TRUE;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
               "MAX_STRING_LITERAL" THEN SYMBOL_TABLE (INDEX).
               MACRO_VALUE (1..MAX_IN_LEN) := '"' &
               (1..MAX_IN_LEN-2 => 'A') & '"';
               CALCULATED := TRUE;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
               "BIG_INT_LIT" THEN SYMBOL_TABLE (INDEX).MACRO_VALUE
               (1..MAX_IN_LEN)  := (1..MAX_IN_LEN-3 => '0') & "298";
               CALCULATED := TRUE;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
               "BIG_REAL_LIT" THEN SYMBOL_TABLE (INDEX).MACRO_VALUE
               (1..MAX_IN_LEN) := (1..MAX_IN_LEN-5 => '0') & "690.0";
               CALCULATED := TRUE;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
               "MAX_LEN_INT_BASED_LITERAL" THEN
               SYMBOL_TABLE (INDEX).
               MACRO_VALUE (1..MAX_IN_LEN) := "2:" &
               (1..MAX_IN_LEN - 5 => '0') & "11:";
               CALCULATED := TRUE;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
               "MAX_LEN_REAL_BASED_LITERAL" THEN SYMBOL_TABLE (INDEX).
               MACRO_VALUE (1..MAX_IN_LEN) := "16:" &
               (1..MAX_IN_LEN - 7 => '0') & "F.E:";
               CALCULATED := TRUE;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
               "BLANKS" THEN SYMBOL_TABLE (INDEX).MACRO_VALUE
               (1..MAX_IN_LEN-20) := (1..MAX_IN_LEN-20 => ' ');
               CALCULATED := TRUE;
          ELSE
               CALCULATED := FALSE;
          END IF;
          IF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
               "BLANKS" THEN SYMBOL_TABLE (INDEX).VALUE_LENGTH :=
               MAX_IN_LEN - 20;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
                "BIG_STRING1" THEN
               SYMBOL_TABLE (INDEX).VALUE_LENGTH :=
                           (MAX_IN_LEN + 1)/2 + 2;
          ELSIF SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) =
                "BIG_STRING2" THEN
               SYMBOL_TABLE (INDEX).VALUE_LENGTH :=
                      MAX_IN_LEN - (MAX_IN_LEN + 1)/2 + 2;
          ELSE SYMBOL_TABLE (INDEX).VALUE_LENGTH := MAX_IN_LEN;
          END IF;
     END CALC_MAX_VALS;

-----------------------------------------------------------------------
--                                                                   --
--    PROCEDURE FILL_TABLE READS THE MACRO NAMES AND MACRO VALUES IN --
--    FROM MACRO.DFS AND STORES THEM IN THE SYMBOL TABLE.  PROCEDURE --
--    CALC_MAX_VALS IS CALLED TO DETERMINE IF THE MACRO VALUE SHOULD --
--    BE CALCULATED OR READ FROM MACRO.DFS.                          --
--                                                                   --
-----------------------------------------------------------------------

     PROCEDURE FILL_TABLE IS

          INFILE1 : FILE_TYPE;
          MACRO_FILE : CONSTANT STRING := "MACRO.DFS";
          A_LINE : VAL_STRING;
          I, INDEX, LENGTH, HOLD, A_LENGTH, NAME : INTEGER;
          MAX_IN_LEN : INTEGER := 1;
          CALCULATED : BOOLEAN;

     BEGIN
          INDEX := 1;
          BEGIN
               OPEN (INFILE1, IN_FILE, MACRO_FILE);
          EXCEPTION
               WHEN NAME_ERROR =>
                    PUT_LINE ("** ERROR: MACRO FILE " & MACRO_FILE &
                              " NOT FOUND.");
                    RAISE MAC_FILE;
          END;
          WHILE NOT END_OF_FILE (INFILE1) LOOP
               GET_LINE (INFILE1, A_LINE, A_LENGTH);
               IF A_LENGTH > 0 AND A_LINE (1..2) /= "--" AND
                  A_LINE (1) /= ' ' AND A_LINE (1) /= ASCII.HT THEN
                    I := 1;
                    WHILE I <= A_LENGTH AND THEN
                           ((A_LINE (I) IN 'A'..'Z') OR
                            (A_LINE (I) IN '0'..'9') OR
                            A_LINE (I) = '_') LOOP
                         I := I + 1;
                    END LOOP;
                    I := I - 1;
                    LENGTH := I;
                    BEGIN
                         SYMBOL_TABLE (INDEX).MACRO_NAME (1..LENGTH) :=
                              A_LINE (1..I);
                    EXCEPTION
                         WHEN CONSTRAINT_ERROR =>
                              PUT_LINE ("** ERROR: LINE LENGTH IS " &
                                        "GREATER THAN MAX_VAL_LENGTH.");
                              RAISE LINE_LEN;
                    END;
                    SYMBOL_TABLE (INDEX).NAME_LENGTH := I;
                    CALC_MAX_VALS (INDEX, LENGTH, MAX_IN_LEN,
                                   CALCULATED);
                    IF NOT CALCULATED THEN
                         I := I + 1;
                         WHILE A_LINE (I) = ' ' OR A_LINE (I) =
                           ASCII.HT LOOP
                              I := I + 1;
                              IF SYMBOL_TABLE (INDEX).MACRO_NAME
                                   (1..LENGTH) = "BLANKS" THEN
                                   EXIT;
                              END IF;
                         END LOOP;
                         HOLD := I;

-- MACRO VALUE BEGINS AT POSITION HOLD.
-- NOW FIND WHERE IT ENDS BY STARTING AT THE END OF THE INPUT
-- LINE AND SEARCHING BACKWARD FOR A NON-BLANK.

                         I := A_LENGTH;
                         WHILE I > HOLD AND THEN (A_LINE (I) = ' '
                            OR A_LINE(I) = ASCII.HT) LOOP
                              I := I - 1;
                         END LOOP;
                         LENGTH := I - HOLD + 1;
                         SYMBOL_TABLE (INDEX).MACRO_VALUE (1..LENGTH)
                              := A_LINE (HOLD..I);
                         SYMBOL_TABLE (INDEX).VALUE_LENGTH := LENGTH;
                         NAME := SYMBOL_TABLE (INDEX).NAME_LENGTH;
                         IF SYMBOL_TABLE (INDEX).MACRO_NAME (1..NAME) =
                              "MAX_IN_LEN" THEN MAX_IN_LEN :=
                              INTEGER'VALUE (SYMBOL_TABLE (INDEX).
                              MACRO_VALUE (1..LENGTH));
                         END IF;
                    END IF;
                    INDEX := INDEX + 1;
               END IF;
          END LOOP;
          NUM_MACROS := INDEX - 1;
          CLOSE (INFILE1);
     END FILL_TABLE;

BEGIN
     NULL;
END GETSUBS;

WITH TEXT_IO;
USE TEXT_IO;
WITH DEFS;
USE DEFS;

PACKAGE PARSEMAC IS

------------------------------------------------------------------------
--                                                                    --
--   THIS PACKAGE IS USED BY MACROSUB.ADA FOR FINDING A MACRO TO      --
--   SUBSTITUTE.  MACRO SUBSTITUTIONS ARE MADE IN *.TST TESTS IN THE  --
--   ACVC TEST SUITE.  THIS PROCEDURE IS CURRENTLY SET UP FOR ACVC    --
--   VERSION 1.10.                                                    --
--                                                                    --
------------------------------------------------------------------------

     PROCEDURE LOOK_FOR_MACRO (A_LINE : IN STRING;
                               A_LENGTH : IN INTEGER;
                               PTR : IN OUT INTEGER;
                               MACRO : OUT STRING;
                               MACRO_LEN : IN OUT INTEGER);


     PROCEDURE WHICH_MACRO (MACRO : IN STRING;
                            MACRO_LEN : IN INTEGER;
                            TEMP_MACRO : OUT STRING;
                            TEMP_MACRO_LEN : IN OUT INTEGER);

END PARSEMAC;

PACKAGE BODY PARSEMAC IS

-----------------------------------------------------------------------
--    PROCEDURE LOOK_FOR_MACRO LOOKS FOR A DOLLAR SIGN WHICH SIGNALS --
--    THE START OF A MACRO IN THE *.TST FILES.  IT THEN COUNTS       --
--    CHARACTERS UNTIL A <LETTER>, <NUMBER>, OR <_> IS NOT FOUND.    --
--    RETURN PARAMETERS SEND THE BEGINNING POINTER AND LENGTH OF THE --
--    MACRO BACK TO THE MAIN PROGRAM.  ALSO RETURNED IS THE MACRO    --
--    STRING.                                                        --
-----------------------------------------------------------------------

     PROCEDURE LOOK_FOR_MACRO (A_LINE : IN STRING;
                               A_LENGTH : IN INTEGER;
                               PTR : IN OUT INTEGER;
                               MACRO : OUT STRING;
                               MACRO_LEN : IN OUT INTEGER) IS

     II, J : INTEGER := INTEGER'LAST;

     BEGIN
          FOR I IN PTR..A_LENGTH LOOP
               IF A_LINE (I) = '$' THEN
                    II := I+1;
                    EXIT;
               END IF;
               II := I;
          END LOOP;
          IF II < A_LENGTH THEN    -- DOLLAR SIGN IS FOUND.
               J := II;
               WHILE J <= A_LENGTH AND THEN ((A_LINE(J) IN 'A'..'Z') OR
                      (A_LINE(J) IN '0'..'9') OR
                       A_LINE(J) = '_') LOOP
                       J := J+1;
               END LOOP;
               J := J-1;
               MACRO_LEN := (J-II+1);
               MACRO (1..MACRO_LEN) := A_LINE (II .. J);
                             -- DON'T INCLUDE THE DOLLAR SIGN
               PTR := J+1;
          ELSE
               MACRO_LEN := 0;
          END IF;
     RETURN;
     END LOOK_FOR_MACRO;

------------------------------------------------------------------------
--    PROCEDURE WHICH_MACRO COMPARES THE INPUT MACRO STRING TO A      --
--    VALUE READ FROM MACRO.DFS AND STORED IN THE SYMBOL TABLE AND    --
--    RETURNS THE MACRO SUBSTITUTION STRING BACK TO THE MAIN PROGRAM. --
------------------------------------------------------------------------

     PROCEDURE WHICH_MACRO (MACRO : IN STRING;
                            MACRO_LEN : IN INTEGER;
                            TEMP_MACRO : OUT STRING;
                            TEMP_MACRO_LEN : IN OUT INTEGER) IS

     BEGIN
          FOR INDEX IN 1 .. NUM_MACROS LOOP
               IF MACRO (1..MACRO_LEN) =
                  SYMBOL_TABLE (INDEX).MACRO_NAME
                      (1..SYMBOL_TABLE (INDEX).NAME_LENGTH) THEN
                    TEMP_MACRO_LEN :=
                      SYMBOL_TABLE (INDEX).VALUE_LENGTH;
                    TEMP_MACRO (1..TEMP_MACRO_LEN) :=
                      SYMBOL_TABLE (INDEX).MACRO_VALUE
                        (1..TEMP_MACRO_LEN);
                    EXIT;
               END IF;
               IF INDEX = NUM_MACROS THEN
                    PUT_LINE ("** ERROR: MACRO " & MACRO (1..MACRO_LEN)
                              & " NOT FOUND.  UPDATE PROGRAM.");
                    TEMP_MACRO_LEN := MACRO_LEN;
                    TEMP_MACRO (1..TEMP_MACRO_LEN) :=
                       MACRO (1..MACRO_LEN);
               END IF;
          END LOOP;

     END WHICH_MACRO;

BEGIN
     NULL;
END PARSEMAC;

WITH TEXT_IO, GETSUBS, PARSEMAC, DEFS;
USE TEXT_IO, GETSUBS, PARSEMAC, DEFS;

PROCEDURE MACROSUB IS

------------------------------------------------------------------------
--                                                                    --
--    MACROSUB IS THE MAIN PROGRAM THAT CALLS PROCEDURES IN TWO       --
--    PACKAGES, GETSUBS AND PARSEMAC.  THIS PROGRAM IS USED TO MAKE   --
--    THE MACRO SUBSTITUTIONS FOR TST TESTS IN THE ACVC TEST SUITE.   --
--                                                                    --
------------------------------------------------------------------------

     INFILE1, INFILE2, OUTFILE1     : FILE_TYPE;
     FNAME, MACRO                   : VAL_STRING;
     LENGTH, A_LENGTH, PTR,
     TEMP_MACRO_LENGTH, MACRO_LEN, FILE_COUNT : INTEGER := 0;
     A_LINE, TEMP_MACRO, TEMP_LINE, NEW_LINE : VAL_STRING;
     END_OF_LINE_SEARCH, FLAG       : BOOLEAN := FALSE;
     TESTS_FILE                     : CONSTANT STRING := "TSTTESTS.DAT";
     TSTTESTS,FILE_CRE              : EXCEPTION;

BEGIN
     PUT_LINE ("BEGINNING MACRO SUBSTITUTIONS.");
     FILL_TABLE;
     BEGIN
          OPEN (INFILE2, IN_FILE, TESTS_FILE);
     EXCEPTION
          WHEN NAME_ERROR =>
               PUT_LINE ("** ERROR: ERROR DURING OPENING OF " &
                         "TSTTESTS.DAT");
               RAISE TSTTESTS;
     END;
     WHILE NOT END_OF_FILE (INFILE2) LOOP
          GET_LINE (INFILE2, FNAME, LENGTH);
          FILE_COUNT := FILE_COUNT + 1;
          BEGIN
               OPEN (INFILE1, IN_FILE, FNAME(1..LENGTH));
          EXCEPTION
               WHEN NAME_ERROR =>
                    PUT_LINE ("** ERROR: ERROR DURING OPENING OF " &
                              FNAME(1..LENGTH) & ".");
                    FLAG := TRUE;
          END;
          IF NOT FLAG THEN
               PUT_LINE ("WORKING ON " & FNAME(1..LENGTH));
               IF FILE_COUNT = 70 THEN
                    PUT_LINE ("MACRO SUBSTITUTIONS HALF COMPLETED.");
               END IF;
               FOR I IN REVERSE 1 .. LENGTH LOOP
                    IF FNAME(I) = ';' THEN
                         LENGTH := I - 1;
                         EXIT;
                    END IF;
               END LOOP;
               IF FNAME (LENGTH-2..LENGTH) = "TST" THEN
                    FNAME (LENGTH-2..LENGTH) := "ADT";
               ELSIF FNAME (LENGTH-2..LENGTH) = "tst" THEN
                    FNAME (LENGTH-2..LENGTH) := "adt";
               END IF;
               BEGIN
                    CREATE (OUTFILE1, OUT_FILE, FNAME (1..LENGTH));
               EXCEPTION
                    WHEN OTHERS =>
                         PUT_LINE ("** ERROR: EXCEPTION RAISED DURING" &
                                   " ATTEMPTED CREATION OF " &
                                   FNAME(1..LENGTH) & ".");
                         RAISE FILE_CRE;
               END;
               WHILE NOT END_OF_FILE (INFILE1) LOOP
                    GET_LINE (INFILE1, A_LINE, A_LENGTH);
                    IF A_LENGTH > 0 AND A_LINE(1..2) /= "--" THEN
                         END_OF_LINE_SEARCH := FALSE;
                         PTR := 1;
                         WHILE NOT END_OF_LINE_SEARCH LOOP
                              LOOK_FOR_MACRO (A_LINE, A_LENGTH, PTR,
                                              MACRO, MACRO_LEN);
                              IF MACRO_LEN = 0 THEN
                                   END_OF_LINE_SEARCH := TRUE;
                              ELSE --  SEE WHICH MACRO IT IS
                                   WHICH_MACRO (MACRO, MACRO_LEN,
                                       TEMP_MACRO, TEMP_MACRO_LENGTH);
                              END IF;
                              IF NOT END_OF_LINE_SEARCH THEN
                                   IF PTR-MACRO_LEN-2 > 0 THEN
                                 -- IF MACRO IS NOT FIRST ON THE LINE
                                        NEW_LINE (1..PTR-MACRO_LEN-2)
                                         := A_LINE(1..PTR-MACRO_LEN -2);
                                 -- THE OLD LINE UNTIL THE DOLLAR SIGN
                                   END IF;
                                   NEW_LINE(PTR-MACRO_LEN-1 ..
                                            TEMP_MACRO_LENGTH +
                                            (PTR-MACRO_LEN) - 2) :=
                                       TEMP_MACRO(1..TEMP_MACRO_LENGTH);
                                   IF PTR <= A_LENGTH THEN
                                 -- IF MACRO IS NOT LAST ON THE LINE
                                        NEW_LINE (TEMP_MACRO_LENGTH +
                                             PTR-MACRO_LEN - 1 ..
                                             TEMP_MACRO_LENGTH - 1 +
                                             A_LENGTH - MACRO_LEN) :=
                                             A_LINE (PTR..A_LENGTH);
                                   ELSE
                                        END_OF_LINE_SEARCH := TRUE;
                                   END IF;
                                   A_LENGTH := A_LENGTH +
                                               TEMP_MACRO_LENGTH -
                                               MACRO_LEN - 1;
                                   A_LINE (1..A_LENGTH) :=
                                          NEW_LINE (1..A_LENGTH);
                                   PTR := PTR - MACRO_LEN +
                                          TEMP_MACRO_LENGTH - 1;
                              END IF;
                         END LOOP;
                    END IF;
                    PUT_LINE (OUTFILE1, A_LINE (1..A_LENGTH));
               END LOOP;
               CLOSE (OUTFILE1);
               CLOSE (INFILE1);
          ELSE
               FLAG := FALSE;
          END IF;
     END LOOP;
     CLOSE (INFILE2);
     PUT_LINE ("MACRO SUBSTITUTIONS COMPLETED.");
EXCEPTION
     WHEN MAC_FILE | LINE_LEN | TSTTESTS | FILE_CRE =>
          NULL;
     WHEN OTHERS =>
          PUT_LINE ("UNEXPECTED EXCEPTION RAISED");
END MACROSUB;