Debian Codegraph @

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

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