-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnumeronym.cob
60 lines (53 loc) · 1.76 KB
/
numeronym.cob
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
identification division.
program-id. numeronym-main.
data division.
working-storage section.
01 ws-word pic A(50).
01 ws-res-word pic A(4).
procedure division.
main-line.
move "internationalization" to ws-word
perform display-numeronym
move "hey" to ws-word
perform display-numeronym
move "I" to ws-word
perform display-numeronym
move "record" to ws-word
perform display-numeronym
goback
.
display-numeronym.
call "calculate-numeronym"
using content ws-word, reference ws-res-word
display ws-res-word
.
end program numeronym-main.
identification division.
program-id. calculate-numeronym.
data division.
local-storage section.
* implem details:
01 ws-count-glob.
05 ws-count-spc pic 99.
05 ws-bare-count pic 99.
05 ws-count pic 99.
05 ws-count-str redefines ws-count pic AA.
linkage section.
01 ws-word pic A(50) value "internationalization".
01 ws-res-word pic A(4).
procedure division using ws-word, ws-res-word.
inspect ws-word tallying ws-count-spc for trailing space.
compute ws-bare-count =
function length(ws-word) - ws-count-spc
compute ws-count = ws-bare-count - 2
if ws-count <= 1 then
move ws-word to ws-res-word
else
* remove 2, leading + trailing
string ws-word(1:1)
ws-count-str
ws-word(ws-bare-count:ws-bare-count)
into ws-res-word
end-if
.
goback.