[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[open-cobol-list] Bug in UNSTRING ... ON OVERFLOW or misunderstanding?
From: |
Fred Mobach |
Subject: |
[open-cobol-list] Bug in UNSTRING ... ON OVERFLOW or misunderstanding? |
Date: |
Thu, 15 Mar 2012 10:48:42 +0100 |
User-agent: |
KMail/1.9.10 |
Hello,
A problem I've encountered with UNSTRING ... ON OVERFLOW, is it a bug
that an ON OVERFLOW condition can be met more than once?
According to ISO/IEC FCD 1989:2001 the overflow condition of an unstring
operation operates like:
16) Either of the following situations causes an overflow condition:
a) An UNSTRING is initiated, and the value in the data item
referenced by identifier-7 is less than 1 or greater
than the number of character positions described for the data
item referenced by identifier-1.
b) If, during execution of an UNSTRING statement, all receiving
areas have been acted upon, and the data
item referenced by identifier-1 contains characters that have
not been examined.
and the format of UNSTRING is there:
UNSTRING identifier-1
DELIMITED BY [ ALL ] identifier-2 OR [ ALL ] identifier-3
…
literal-1 literal-2
INTO { identifier-4 [ DELIMITER IN identifier-5 ] [ COUNT IN
identifier-6 ] } ...
[ WITH POINTER identifier-7 ]
[ TALLYING IN identifier-8 ]
ON OVERFLOW imperative-statement-1
NOT ON OVERFLOW imperative-statement-2
[ END-UNSTRING ]
While my testprogram didn't work accordingly some screen output was
captured to show that the on overflow condition was encountered
repeatedly and the not on overflow condition was met once :
address@hidden:~/cob> ./unstring2
on overflow, counter=+000000000002
pointer=+000000000007
on overflow, counter=+000000000003
pointer=+000000000016
on overflow, counter=+000000000004
pointer=+000000000020
on overflow, counter=+000000000005
pointer=+000000000025
on overflow, counter=+000000000006
pointer=+000000000029
not on overflow, counter=+000000000007
pointer=+000000000129
index1=+000000000001 text=below delim=
index1=+000000000002 text=mountain delim==
index1=+000000000003 text=low delim=,
index1=+000000000004 text=high delim=,
index1=+000000000005 text=big delim=,
index1=+000000000006 text=small delim=
index1=+000000000007 text= delim=
index1=+000000000008 text= delim=
pointer=+000000000129
tallying=+000000000007
Tested on :
address@hidden:~/cob-idx> cat /etc/SuSE-release
openSUSE 12.1 (x86_64)
address@hidden:~/cob-idx> uname -a
Linux fred 3.1.0-1.2-desktop #1 SMP PREEMPT Thu Nov 3 14:45:45 UTC 2011
(187dde0) x86_64 x86_64 x86_64 GNU/Linux
OpenCOBOL version used:
/* Generated by cobc 1.1.0 */
/* Generated from unstring2.cob */
/* Generated at Mar 15 2012 10:19:30 CET */
/* OpenCOBOL build date Feb 19 2012 22:24:40 */
The source unstring2.cob tested:
<<cut here>>
>>SOURCE FORMAT IS FIXED
identification division.
program-id. x.
environment division.
data division.
working-storage section.
01 ws-variables.
03 index1 pic s9(12) comp sync.
03 string-pointer pic s9(12) comp sync.
03 string-counter pic s9(12) comp sync.
03 free-text-len-max pic s9(12) comp sync value 128.
03 free-text pic x(0128).
03 table-unstring.
05 row-unstring occurs 8.
07 text-unstring pic x(0010).
07 delim-unstr pic x(0001).
procedure division.
mainline section.
p00.
move "below mountain=low,high,big,small" to free-text
move space to table-unstring
move 1 to string-counter
move 1 to string-pointer
.
* Test 2 : unstring loop into one substring per cycle.
p50.
if string-counter < 8
* Absence of the and clause below let the RTS of OC hang
* on an input from comsole.
and string-pointer not > free-text-len-max
unstring free-text
delimited by all space or all "=" or all ","
into text-unstring (string-counter)
delimiter in delim-unstr (string-counter)
with pointer string-pointer
tallying in string-counter
on overflow
display "on overflow, counter="
string-counter
display " pointer="
string-pointer
go to p50
not on overflow
display "not on overflow, counter="
string-counter
display " pointer="
string-pointer
end-unstring
end-if
.
perform varying index1 from 1 by 1 until index1 > 8
display "index1=" index1
" text=" text-unstring (index1)
" delim=" delim-unstr (index1)
end-perform
display "pointer=" string-pointer
display "tallying=" string-counter
.
peos.
stop run.
<<cut here>>
--
Fred Mobach
website : https://fred.mobach.nl
.... In God we trust ....
.. The rest we monitor ..
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [open-cobol-list] Bug in UNSTRING ... ON OVERFLOW or misunderstanding?,
Fred Mobach <=