Debian Codegraph @

gcc/testsuite/cobol.dg/group2/INSPECT_ISO_Example_1.cob

raw
1 *> { dg-do run }
2 *> { dg-output-file "group2/INSPECT_ISO_Example_1.out" }
3 Identification Division.
4 Program-Id. Clouseau.
5 Data Division.
6 Working-Storage Section.
7 01 rows pic 99 value 3.
8 01 counts pic 99 value 5.
9
10 01 rowlim pic 99.
11 01 ncount pic 99.
12
13 01 inputs.
14 05 row occurs 6 times indexed by counter.
15 10 star PIC X.
16 10 input PIC X(20).
17 10 count PIC 99 occurs 5 times.
18 10 output PIC X(20).
19 77 len PIC 9(8).
20 Procedure Division.
21 *> Odd-numbered rows are "read only" and contain the inputs and expected
22 *> outputs.
23 *> Even-numbered rows are modified by the INSPECT statements and contain
24 *> the observed outputs
25 Move ' EFABDBCGABEFGG 0301010005TUXYXVWRXYZZPZ' to row(1).
26 Move ' BABABC 0200000101SXYXYZ' to row(3).
27 Move ' BBBC 0001000200SSVW' to row(5).
28
29 compute rowlim = 2*rows - 1
30
31 Display ' INPUT C0 C1 C2 C3 C4 OUTPUT'
32 Display ' -------------------- -- -- -- -- -- ----------------'
33 Perform Example-1 with test after
34 varying counter from 1 by 2 until counter >= rowlim.
35
36 Goback.
37
38 Inspection Section.
39 Example-1.
40 Move row(counter) to row(counter + 1)
41
42 perform varying ncount from 1 by 1 until ncount > counts
43 Move Zero to count(counter + 1 ncount)
44 end-perform
45
46 Move function length( function trim(input(counter)) ) to len.
47 MOVE INPUT(COUNTER) TO OUTPUT(COUNTER + 1)
48 INSPECT INPUT(COUNTER)(1:len) TALLYING
49 COUNT(counter + 1 1) FOR ALL "AB", ALL "D"
50 COUNT(counter + 1 2) FOR ALL "BC"
51 COUNT(counter + 1 3) FOR LEADING "EF"
52 COUNT(counter + 1 4) FOR LEADING "B"
53 COUNT(counter + 1 5) FOR CHARACTERS
54 INSPECT OUTPUT(COUNTER + 1)(1:len) REPLACING
55 ALL "AB" BY "XY", "D" BY "X"
56 ALL "BC" BY "VW"
57 LEADING "EF" BY "TU"
58 LEADING "B" BY "S"
59 FIRST "G" BY "R"
60 FIRST "G" BY "P"
61 CHARACTERS BY "Z"
62
63 If row(counter) = row(counter + 1) then
64 Move '*' to star(counter + 1)
65 Else
66 Move '!' to star(counter + 1).
67
68 Display star(counter) ' '
69 input(counter) ' ' with no advancing
70 perform varying ncount from 1 by 1 until ncount > counts
71 Display count(counter ncount) ' ' with no advancing
72 end-perform
73 display function trim (output(counter))
74
75 Display star(1 + counter) ' '
76 input(1 + counter) ' ' with no advancing
77 perform varying ncount from 1 by 1 until ncount > counts
78 Display count(1 + counter ncount) ' ' with no advancing
79 end-perform
80 display function trim (output(1 + counter))
81 continue.
82 end program Clouseau.
83