Debian Codegraph @

gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_5-f.cob

raw
1 *> { dg-do run }
2 *> { dg-output-file "group2/INSPECT_ISO_Example_5-f.out" }
3
4 Identification Division.
5 Program-Id. Clouseau.
6 *> Note: Although modeled on Example-5 in Appendix D of the ISO 2023
7 *> specification, all three of the samples are incorrect. This code
8 *> modifies the problem to make it somewhat more interesting, and, of
9 *> course, changes the answers so that they are correct for the problem.
10 Data Division.
11 Working-Storage Section.
12 01 rows pic 99 value 3.
13 01 counts pic 99 value 3.
14
15 01 rowlim pic 99.
16 01 ncount pic 99.
17
18 01 inputs.
19 05 row occurs 6 times indexed by counter.
20 10 star PIC X.
21 10 input PIC X(20).
22 10 count PIC 99 occurs 3 times.
23 10 output PIC X(20).
24 77 len PIC 9(8).
25 Procedure Division.
26 *> Odd-numbered rows are "read only" and contain the inputs and expected
27 *> outputs.
28 *> Even-numbered rows are modified by the INSPECT statements and contain
29 *> the observed outputs
30 Move ' ABABBCAB 000106ABABBCXY' to row(1).
31 Move ' ABDBABC 000001AVDBABC' to row(3).
32 Move ' BCABCABD 010000BCABCAVD' to row(5).
33
34 compute rowlim = 2*rows - 1
35
36 Display ' INPUT C0 C1 C2 OUTPUT'
37 Display ' -------------------- -- -- -- ----------------'
38 Perform Example-1 with test after
39 varying counter from 1 by 2 until counter >= rowlim.
40
41 Goback.
42
43 Inspection Section.
44 Example-1.
45 Move row(counter) to row(counter + 1)
46
47 perform varying ncount from 1 by 1 until ncount > counts
48 Move Zero to count(counter + 1 ncount)
49 end-perform
50
51 Move function length( function trim(input(counter)) ) to len.
52 MOVE INPUT(COUNTER) TO OUTPUT(COUNTER + 1)
53 INSPECT BACKWARD INPUT(COUNTER)(1:len) TALLYING
54 COUNT(counter + 1 1) FOR ALL "AB" BEFORE "BC"
55 COUNT(counter + 1 2) FOR LEADING "B"
56 COUNT(counter + 1 3) FOR CHARACTERS AFTER "A" BEFORE "D"
57 INSPECT BACKWARD OUTPUT(COUNTER + 1)(1:len) REPLACING
58 ALL "AB" BY "XY" BEFORE "BC"
59 LEADING "B" BY "V" AFTER "D"
60
61 If row(counter) = row(counter + 1) then
62 Move '*' to star(counter + 1)
63 Else
64 Move '!' to star(counter + 1).
65
66 Display star(counter) ' '
67 input(counter) ' ' with no advancing
68 perform varying ncount from 1 by 1 until ncount > counts
69 Display count(counter ncount) ' ' with no advancing
70 end-perform
71 display function trim(output(counter))
72
73 Display star(1 + counter) ' '
74 input(1 + counter) ' ' with no advancing
75 perform varying ncount from 1 by 1 until ncount > counts
76 Display count(1 + counter ncount) ' ' with no advancing
77 end-perform
78 display function trim(output(1 + counter))
79 continue.
80 end program Clouseau.
81