forked from azac/cobol-on-wheelchair
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cowtemplate.cbl
151 lines (111 loc) · 4.73 KB
/
cowtemplate.cbl
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
*> ***********************************************
identification division.
program-id. cowtemplate.
environment division.
input-output section.
file-control.
select readfile
assign to readfile-name
file status is readfile-status
organization is line sequential.
data division.
file section.
fd readfile.
01 readline pic x(1024).
working-storage section.
01 readfile-name pic x(255).
01 readfile-status pic x(2).
01 templine pic x(1024).
01 the-var pic x(100).
01 what-we-change pic x(100).
01 counter PIC 9(4).
linkage section.
01 the-vars.
03 COW-vars OCCURS 99 times.
05 COW-varname pic x(99).
05 COW-varvalue pic x(99).
01 template-filename pic x(255).
procedure division using the-vars template-filename.
move
function concatenate("views/",function trim(template-filename))
to readfile-name.
start-readfile.
open input readfile
call 'checkfilestatus' using readfile-name readfile-status
read readfile
perform until readfile-status = '10'
move function trim(readline) to templine
PERFORM VARYING counter FROM 1 BY 1 UNTIL counter > 99
move
function concatenate(
'{{' function trim(COW-varname(counter)) '}}'
)
to
what-we-change
move
function SUBSTITUTE(
templine,
function trim(what-we-change),
function trim(COW-varvalue(counter)))
to templine
END-PERFORM
display function trim(templine)
read readfile
end-perform
close readfile.
identification division.
program-id. checkfilestatus.
data division.
working-storage section.
01 status-message pic x(72).
01 display-message pic x(72) value spaces.
linkage section.
01 file-name pic x(64).
01 file-status pic x(2).
procedure division using file-name file-status.
start-checkfilestatus.
if file-status = '00'
goback
end-if
evaluate file-status
when 00 move 'SUCCESS.' TO status-message
when 02 move 'SUCCESS DUPLICATE.' TO status-message
when 04 move 'SUCCESS INCOMPLETE.' TO status-message
when 05 move 'SUCCESS OPTIONAL.' TO status-message
when 07 move 'SUCCESS NO UNIT.' TO status-message
when 10 move 'END OF FILE.' TO status-message
when 14 move 'OUT OF KEY RANGE.' TO status-message
when 21 move 'KEY INVALID.' TO status-message
when 22 move 'KEY EXISTS.' TO status-message
when 23 move 'KEY NOT EXISTS.' TO status-message
when 30 move 'PERMANENT ERROR.' TO status-message
when 31 move 'INCONSISTENT FILENAME.' TO status-message
when 34 move 'BOUNDARY VIOLATION.' TO status-message
when 35 move 'FILE NOT FOUND.' TO status-message
when 37 move 'PERMISSION DENIED.' TO status-message
when 38 move 'CLOSED WITH LOCK.' TO status-message
when 39 move 'CONFLICT ATTRIBUTE.' TO status-message
when 41 move 'ALREADY OPEN.' TO status-message
when 42 move 'NOT OPEN.' TO status-message
when 43 move 'READ NOT DONE.' TO status-message
when 44 move 'RECORD OVERFLOW.' TO status-message
when 46 move 'READ ERROR.' TO status-message
when 47 move 'INPUT DENIED.' TO status-message
when 48 move 'OUTPUT DENIED.' TO status-message
when 49 move 'I/O DENIED.' TO status-message
when 51 move 'RECORD LOCKED.' TO status-message
when 52 move 'END-OF-PAGE.' TO status-message
when 57 move 'I/O LINAGE.' TO status-message
when 61 move 'FILE SHARING FAILURE.' TO status-message
when 91 move 'FILE NOT AVAILABLE.' TO status-message
end-evaluate
string 'ERROR ' delimited by size
file-name delimited by space
space delimited by size
status-message delimited by '.'
into display-message
display display-message
stop run
.
end program checkfilestatus.
end program cowtemplate.