-
Notifications
You must be signed in to change notification settings - Fork 0
/
TRNSLAT.cob
227 lines (191 loc) · 7.5 KB
/
TRNSLAT.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
*=========================== TRNSLAT ============================*
* Authors: Brian D Pead
*
* Description: Subroutine to convert character-set of specified
* fields in a COBOL record.
*
* License: MIT
*
* Date Version Description
* ---- ------- -----------
* 2020-02-08 1.0 First release
*================================================================*
IDENTIFICATION DIVISION.
*========================
PROGRAM-ID. TRNSLAT.
ENVIRONMENT DIVISION.
*=====================
CONFIGURATION SECTION.
*----------------------
SOURCE-COMPUTER.
IBM-Z15.
* IBM-Z15 DEBUGGING MODE.
INPUT-OUTPUT SECTION.
*---------------------
FILE-CONTROL.
/
DATA DIVISION.
*==============
FILE SECTION.
*-------------
WORKING-STORAGE SECTION.
*------------------------
01 W-SUB-1 PIC S9(04) COMP.
01 W-SUB-2 PIC S9(04) COMP.
01 FILLER PIC X(01) VALUE 'Y'.
88 W-FIRST-CALL VALUE 'Y'.
88 W-NOT-FIRST-CALL VALUE 'N'.
01 W-COMPILED-DATE.
05 W-COMPILED-DATE-YYYY
PIC X(04).
05 W-COMPILED-DATE-MM PIC X(02).
05 W-COMPILED-DATE-DD PIC X(02).
05 W-COMPILED-TIME-HH PIC X(02).
05 W-COMPILED-TIME-MM PIC X(02).
05 W-COMPILED-TIME-SS PIC X(02).
05 FILLER PIC X(07).
01 W-CHAR-BIN PIC S9(04) COMP.
01 FILLER REDEFINES W-CHAR-BIN.
05 FILLER PIC X(01) VALUE X'00'.
05 W-CHAR-BIN-2 PIC X(01).
01 W-CONVERSION-TABLE-HEX VALUE LOW-VALUES.
05 FILLER OCCURS 256.
10 FILLER OCCURS 2.
15 W-CONV-HEX PIC X(01).
15 W-CONV-DIG REDEFINES W-CONV-HEX
PIC 9(01).
01 FILLER.
05 W-HEX-VALUE PIC S9(04) COMP OCCURS 2.
01 W-CONVERSION-TABLE-BIN.
05 FILLER OCCURS 256.
10 W-CONV-BIN PIC S9(04) COMP.
10 FILLER REDEFINES W-CONV-BIN.
15 FILLER PIC X(01).
15 W-CONV-CHAR PIC X(01).
/
LINKAGE SECTION.
*----------------
01 L-CONTROL. COPY TRNSLATL.
01 L-RECORD-TO-TRANSLATE.
05 L-REC-CHAR PIC X(01) OCCURS 32768
INDEXED LR-DX.
01 L-CONVERSION-TABLE.
05 FILLER PIC X(02) OCCURS 256.
/
PROCEDURE DIVISION
*==================
USING L-CONTROL
L-RECORD-TO-TRANSLATE
L-CONVERSION-TABLE.
MAIN.
*-----
PERFORM SUB-1000-START-UP THRU SUB-1000-EXIT
IF NOT TC-RESPONSE-GOOD
GO TO MAIN-EXIT
END-IF
PERFORM SUB-2000-PROCESS THRU SUB-2000-EXIT
VARYING TCF-DX FROM 1 BY 1
UNTIL TCF-DX > TC-FIELD-CNT
OR NOT TC-RESPONSE-GOOD
.
MAIN-EXIT.
GOBACK.
/
SUB-1000-START-UP.
*------------------
SET TC-RESPONSE-GOOD TO TRUE
MOVE SPACES TO TC-RESPONSE-MSG
IF W-CONVERSION-TABLE-HEX NOT = L-CONVERSION-TABLE
MOVE L-CONVERSION-TABLE
TO W-CONVERSION-TABLE-HEX
PERFORM SUB-1100-CONVERT-HEX-TO-BIN THRU SUB-1100-EXIT
VARYING W-SUB-1 FROM 1 BY 1
UNTIL W-SUB-1 > 256
END-IF
IF W-NOT-FIRST-CALL
GO TO SUB-1000-EXIT
END-IF
SET W-NOT-FIRST-CALL TO TRUE
MOVE FUNCTION WHEN-COMPILED
TO W-COMPILED-DATE
DISPLAY 'TRNSLAT compiled on '
W-COMPILED-DATE-YYYY '/'
W-COMPILED-DATE-MM '/'
W-COMPILED-DATE-DD ' at '
W-COMPILED-TIME-HH ':'
W-COMPILED-TIME-MM ':'
W-COMPILED-TIME-SS
.
SUB-1000-EXIT.
EXIT.
/
SUB-1100-CONVERT-HEX-TO-BIN.
*----------------------------
PERFORM VARYING W-SUB-2 FROM 1 BY 1
UNTIL W-SUB-2 > 2
OR NOT TC-RESPONSE-GOOD
IF W-CONV-HEX(W-SUB-1 W-SUB-2) NUMERIC
MOVE W-CONV-DIG(W-SUB-1 W-SUB-2)
TO W-HEX-VALUE(W-SUB-2)
ELSE
EVALUATE W-CONV-HEX(W-SUB-1 W-SUB-2)
WHEN 'A'
MOVE 10 TO W-HEX-VALUE(W-SUB-2)
WHEN 'B'
MOVE 11 TO W-HEX-VALUE(W-SUB-2)
WHEN 'C'
MOVE 12 TO W-HEX-VALUE(W-SUB-2)
WHEN 'D'
MOVE 13 TO W-HEX-VALUE(W-SUB-2)
WHEN 'E'
MOVE 14 TO W-HEX-VALUE(W-SUB-2)
WHEN 'F'
MOVE 15 TO W-HEX-VALUE(W-SUB-2)
WHEN OTHER
SET TC-RESPONSE-TABLE-ERROR
TO TRUE
MOVE 'Invalid hex character in conv table: '
TO TC-RESPONSE-MSG
MOVE W-CONV-HEX(W-SUB-1 W-SUB-2)
TO TC-RESPONSE-MSG(38 : 1)
END-EVALUATE
END-IF
END-PERFORM
IF NOT TC-RESPONSE-GOOD
GO TO SUB-1100-EXIT
END-IF
COMPUTE W-CONV-BIN(W-SUB-1)
= W-HEX-VALUE(1)
* 16
+ W-HEX-VALUE(2)
D DISPLAY 'W-CONV-BIN('
D W-SUB-1
D ') = '
D W-CONV-BIN(W-SUB-1)
.
SUB-1100-EXIT.
EXIT.
/
SUB-2000-PROCESS.
*-----------------
IF TC-FIELD-POS(TCF-DX) + TC-FIELD-LEN(TCF-DX) - 1 >
LENGTH OF L-RECORD-TO-TRANSLATE
SET TC-RESPONSE-RECLEN-ERROR
TO TRUE
MOVE 'Field pos + len > 32K'
TO TC-RESPONSE-MSG
GO TO SUB-2000-EXIT
END-IF
SET LR-DX TO TC-FIELD-POS(TCF-DX)
PERFORM TC-FIELD-LEN(TCF-DX) TIMES
MOVE L-REC-CHAR(LR-DX)
TO W-CHAR-BIN-2
ADD 1
W-CHAR-BIN GIVING W-SUB-2
MOVE W-CONV-CHAR(W-SUB-2)
TO L-REC-CHAR(LR-DX)
SET LR-DX UP BY 1
END-PERFORM
.
SUB-2000-EXIT.
EXIT.