| 1 |
/* |
| 2 |
* Copyright (c) 2021-2025 Symas Corporation |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions are |
| 6 |
* met: |
| 7 |
* |
| 8 |
* * Redistributions of source code must retain the above copyright |
| 9 |
* notice, this list of conditions and the following disclaimer. |
| 10 |
* * Redistributions in binary form must reproduce the above |
| 11 |
* copyright notice, this list of conditions and the following disclaimer |
| 12 |
* in the documentation and/or other materials provided with the |
| 13 |
* distribution. |
| 14 |
* * Neither the name of the Symas Corporation nor the names of its |
| 15 |
* contributors may be used to endorse or promote products derived from |
| 16 |
* this software without specific prior written permission. |
| 17 |
* |
| 18 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
*/ |
| 30 |
|
| 31 |
#include <fcntl.h> |
| 32 |
#include <unistd.h> |
| 33 |
|
| 34 |
#include <cctype> |
| 35 |
#include <cerrno> |
| 36 |
#include <cmath> |
| 37 |
#include <cfenv> |
| 38 |
#include <cstdio> |
| 39 |
#include <cstdlib> |
| 40 |
#include <cstring> |
| 41 |
#include <ctime> |
| 42 |
|
| 43 |
#include <algorithm> |
| 44 |
#include <unordered_map> |
| 45 |
#include <vector> |
| 46 |
|
| 47 |
#include "ec.h" |
| 48 |
#include "io.h" |
| 49 |
#include "common-defs.h" |
| 50 |
#include "gcobolio.h" |
| 51 |
|
| 52 |
#pragma GCC diagnostic push |
| 53 |
#pragma GCC diagnostic ignored "-Wwrite-strings" |
| 54 |
#pragma GCC diagnostic ignored "-Wmissing-field-initializers" |
| 55 |
|
| 56 |
// There are global variables that need to be initialized at the point where |
| 57 |
// the very first PROGRAM-ID is executed. This flag is used to make sure that |
| 58 |
// initialization happens just once. |
| 59 |
int __gg__globals_are_initialized = 0; |
| 60 |
|
| 61 |
// We have a number of integer constants. We need two macros, one for 1-digit |
| 62 |
// names and a second for 2-digit names in order to match our mangling |
| 63 |
// convention for variable names that start with a numeric: |
| 64 |
|
| 65 |
// 4 becomes _1_4 |
| 66 |
// _ indicates this is a mangled name |
| 67 |
// 1 means it is one character long |
| 68 |
// _ terminates the 1 |
| 69 |
// 4 is the one-character name |
| 70 |
|
| 71 |
#define INTEGER_CONSTANT1(a) \ |
| 72 |
unsigned char __gg__data_##a[1] = {(a)}; \ |
| 73 |
struct cblc_field_t __gg___1_##a = { \ |
| 74 |
.data = __gg__data_##a , \ |
| 75 |
.capacity = 1 , \ |
| 76 |
.allocated = 1 , \ |
| 77 |
.offset = 0 , \ |
| 78 |
.name = #a , \ |
| 79 |
.picture = "" , \ |
| 80 |
.initial = #a , \ |
| 81 |
.parent = NULL, \ |
| 82 |
.occurs_lower = 0 , \ |
| 83 |
.occurs_upper = 0 , \ |
| 84 |
.attr = 0x80 , \ |
| 85 |
.type = FldLiteralN , \ |
| 86 |
.level = 0 , \ |
| 87 |
.digits = 0 , \ |
| 88 |
.rdigits = 0 , \ |
| 89 |
.dummy = 0 , \ |
| 90 |
}; |
| 91 |
|
| 92 |
#define INTEGER_CONSTANT2(a) \ |
| 93 |
unsigned char __gg__data_##a[1] = {(a)}; \ |
| 94 |
struct cblc_field_t __gg___2_##a = { \ |
| 95 |
.data = __gg__data_##a , \ |
| 96 |
.capacity = 1 , \ |
| 97 |
.allocate = 1 , \ |
| 98 |
.offset = 0 , \ |
| 99 |
.name = #a , \ |
| 100 |
.picture = "" , \ |
| 101 |
.initial = #a , \ |
| 102 |
.parent = NULL, \ |
| 103 |
.occurs_lower = 0 , \ |
| 104 |
.occurs_upper = 0 , \ |
| 105 |
.attr = 0x80 , \ |
| 106 |
.type = FldLiteralN , \ |
| 107 |
.level = 0 , \ |
| 108 |
.digits = 0 , \ |
| 109 |
.rdigits = 0 , \ |
| 110 |
.dummy = 0 , \ |
| 111 |
}; |
| 112 |
|
| 113 |
unsigned char __gg__data_space[1] = {' '}; |
| 114 |
struct cblc_field_t __gg__space = { |
| 115 |
.data = __gg__data_space , |
| 116 |
.capacity = sizeof(__gg__data_space) , |
| 117 |
.allocated = sizeof(__gg__data_space) , |
| 118 |
.offset = 0 , |
| 119 |
.name = "SPACE" , |
| 120 |
.picture = "" , |
| 121 |
.initial = (char *)space_value_e , |
| 122 |
.parent = NULL, |
| 123 |
.occurs_lower = 0 , |
| 124 |
.occurs_upper = 0 , |
| 125 |
.attr = 0x284 , |
| 126 |
.type = FldAlphanumeric , |
| 127 |
.level = 0 , |
| 128 |
.digits = 0 , |
| 129 |
.rdigits = 0 , |
| 130 |
.dummy = 0 , |
| 131 |
}; |
| 132 |
|
| 133 |
struct cblc_field_t __gg__spaces = { |
| 134 |
.data = __gg__data_space , |
| 135 |
.capacity = sizeof(__gg__data_space) , |
| 136 |
.allocated = sizeof(__gg__data_space) , |
| 137 |
.offset = 0 , |
| 138 |
.name = "SPACES" , |
| 139 |
.picture = "" , |
| 140 |
.initial = (char *)space_value_e , |
| 141 |
.parent = NULL, |
| 142 |
.occurs_lower = 0 , |
| 143 |
.occurs_upper = 0 , |
| 144 |
.attr = 0x284 , |
| 145 |
.type = FldAlphanumeric , |
| 146 |
.level = 0 , |
| 147 |
.digits = 0 , |
| 148 |
.rdigits = 0 , |
| 149 |
.dummy = 0 , |
| 150 |
}; |
| 151 |
|
| 152 |
unsigned char __gg__data_low_values[1] = {'\0'}; |
| 153 |
struct cblc_field_t __gg__low_values = { |
| 154 |
.data = __gg__data_low_values, |
| 155 |
.capacity = 1 , |
| 156 |
.allocated = 1 , |
| 157 |
.offset = 0 , |
| 158 |
.name = "LOW_VALUES" , |
| 159 |
.picture = "" , |
| 160 |
.initial = (char *)low_value_e , |
| 161 |
.parent = NULL, |
| 162 |
.occurs_lower = 0 , |
| 163 |
.occurs_upper = 0 , |
| 164 |
.attr = 0x281 , |
| 165 |
.type = FldAlphanumeric , |
| 166 |
.level = 0 , |
| 167 |
.digits = 0 , |
| 168 |
.rdigits = 0 , |
| 169 |
.dummy = 0 , |
| 170 |
}; |
| 171 |
|
| 172 |
unsigned char __gg__data_zeros[1] = {'0'}; |
| 173 |
struct cblc_field_t __gg__zeros = { |
| 174 |
.data = __gg__data_zeros , |
| 175 |
.capacity = 1 , |
| 176 |
.allocated = 1 , |
| 177 |
.offset = 0 , |
| 178 |
.name = "ZEROS" , |
| 179 |
.picture = "" , |
| 180 |
.initial = (char *)zero_value_e , |
| 181 |
.parent = NULL , |
| 182 |
.occurs_lower = 0 , |
| 183 |
.occurs_upper = 0 , |
| 184 |
.attr = 0x83 , |
| 185 |
.type = FldAlphanumeric , |
| 186 |
.level = 0 , |
| 187 |
.digits = 0 , |
| 188 |
.rdigits = 0 , |
| 189 |
.dummy = 0 , |
| 190 |
}; |
| 191 |
|
| 192 |
unsigned char __gg__data_high_values[1] = {0xFF}; |
| 193 |
struct cblc_field_t __gg__high_values = { |
| 194 |
.data = __gg__data_high_values , |
| 195 |
.capacity = 1 , |
| 196 |
.allocated = 1 , |
| 197 |
.offset = 0 , |
| 198 |
.name = "HIGH_VALUES" , |
| 199 |
.picture = "" , |
| 200 |
.initial = (char *)high_value_e , |
| 201 |
.parent = NULL, |
| 202 |
.occurs_lower = 0 , |
| 203 |
.occurs_upper = 0 , |
| 204 |
.attr = 0x286 , |
| 205 |
.type = FldAlphanumeric , |
| 206 |
.level = 0 , |
| 207 |
.digits = 0 , |
| 208 |
.rdigits = 0 , |
| 209 |
.dummy = 0 , |
| 210 |
}; |
| 211 |
|
| 212 |
unsigned char __gg__data_quotes[1] = {0xFF}; |
| 213 |
struct cblc_field_t __gg__quotes = { |
| 214 |
.data = __gg__data_quotes , |
| 215 |
.capacity = 1 , |
| 216 |
.allocated = 1 , |
| 217 |
.offset = 0 , |
| 218 |
.name = "QUOTES" , |
| 219 |
.picture = "" , |
| 220 |
.initial = (char *)quote_value_e , |
| 221 |
.parent = NULL, |
| 222 |
.occurs_lower = 0 , |
| 223 |
.occurs_upper = 0 , |
| 224 |
.attr = 0x285 , |
| 225 |
.type = FldAlphanumeric , |
| 226 |
.level = 0 , |
| 227 |
.digits = 0 , |
| 228 |
.rdigits = 0 , |
| 229 |
.dummy = 0 , |
| 230 |
}; |
| 231 |
|
| 232 |
unsigned char __gg__data_nulls[8] = {0,0,0,0,0,0,0,0}; |
| 233 |
struct cblc_field_t __gg__nulls = { |
| 234 |
.data = __gg__data_nulls , |
| 235 |
.capacity = 8 , |
| 236 |
.allocated = 8 , |
| 237 |
.offset = 0 , |
| 238 |
.name = "NULLS" , |
| 239 |
.picture = "" , |
| 240 |
.initial = "" , |
| 241 |
.parent = NULL, |
| 242 |
.occurs_lower = 0 , |
| 243 |
.occurs_upper = 0 , |
| 244 |
.attr = 0x280 , |
| 245 |
.type = FldPointer , |
| 246 |
.level = 0 , |
| 247 |
.digits = 0 , |
| 248 |
.rdigits = 0 , |
| 249 |
.dummy = 0 , |
| 250 |
}; |
| 251 |
|
| 252 |
unsigned char __gg__data__file_status[2] = {0,0}; |
| 253 |
struct cblc_field_t __gg___file_status = { |
| 254 |
.data = __gg__data__file_status , |
| 255 |
.capacity = 2 , |
| 256 |
.allocated = 2 , |
| 257 |
.offset = 0 , |
| 258 |
.name = "_FILE_STATUS" , |
| 259 |
.picture = "" , |
| 260 |
.initial = "" , |
| 261 |
.parent = NULL, |
| 262 |
.occurs_lower = 0 , |
| 263 |
.occurs_upper = 0 , |
| 264 |
.attr = 0x0 , |
| 265 |
.type = FldNumericDisplay , |
| 266 |
.level = 0 , |
| 267 |
.digits = 2 , |
| 268 |
.rdigits = 0 , |
| 269 |
.dummy = 0 , |
| 270 |
}; |
| 271 |
|
| 272 |
|
| 273 |
unsigned char __gg__data_linage_counter[2] = {0,0}; |
| 274 |
struct cblc_field_t __gg___14_linage_counter6 = { |
| 275 |
.data = __gg__data_linage_counter , |
| 276 |
.capacity = 2 , |
| 277 |
.allocated = 2 , |
| 278 |
.offset = 0 , |
| 279 |
.name = "LINAGE-COUNTER" , |
| 280 |
.picture = "" , |
| 281 |
.initial = "" , |
| 282 |
.parent = NULL, |
| 283 |
.occurs_lower = 0 , |
| 284 |
.occurs_upper = 0 , |
| 285 |
.attr = 0x0 , |
| 286 |
.type = FldNumericBin5 , |
| 287 |
.level = 0 , |
| 288 |
.digits = 4 , |
| 289 |
.rdigits = 0 , |
| 290 |
.dummy = 0 , |
| 291 |
}; |
| 292 |
|
| 293 |
|
| 294 |
unsigned char __gg__data_upsi_0[2] = {0,0}; |
| 295 |
struct cblc_field_t __gg__upsi = { |
| 296 |
.data = __gg__data_upsi_0 , |
| 297 |
.capacity = 2 , |
| 298 |
.allocated = 2 , |
| 299 |
.offset = 0 , |
| 300 |
.name = "UPSI-0" , |
| 301 |
.picture = "" , |
| 302 |
.initial = "" , |
| 303 |
.parent = NULL, |
| 304 |
.occurs_lower = 0 , |
| 305 |
.occurs_upper = 0 , |
| 306 |
.attr = 0x0 , |
| 307 |
.type = FldNumericBin5 , |
| 308 |
.level = 0 , |
| 309 |
.digits = 4 , |
| 310 |
.rdigits = 0 , |
| 311 |
.dummy = 0 , |
| 312 |
}; |
| 313 |
|
| 314 |
short __gg__data_return_code = 0; |
| 315 |
struct cblc_field_t __gg__return_code = { |
| 316 |
.data = (unsigned char *)&__gg__data_return_code , |
| 317 |
.capacity = 2 , |
| 318 |
.allocated = 2 , |
| 319 |
.offset = 0 , |
| 320 |
.name = "RETURN-CODE" , |
| 321 |
.picture = "" , |
| 322 |
.initial = "" , |
| 323 |
.parent = NULL, |
| 324 |
.occurs_lower = 0 , |
| 325 |
.occurs_upper = 0 , |
| 326 |
.attr = signable_e , |
| 327 |
.type = FldNumericBin5 , |
| 328 |
.level = 0 , |
| 329 |
.digits = 4 , |
| 330 |
.rdigits = 0 , |
| 331 |
.dummy = 0 , |
| 332 |
}; |
| 333 |
|
| 334 |
unsigned char __gg___data_dev_stdin[] = "/dev/stdin"; |
| 335 |
struct cblc_field_t __gg___dev_stdin = { |
| 336 |
.data = __gg___data_dev_stdin , |
| 337 |
.capacity = sizeof(__gg___data_dev_stdin)-1 , |
| 338 |
.allocated = sizeof(__gg___data_dev_stdin)-1 , |
| 339 |
.offset = 0 , |
| 340 |
.name = "_dev_stdin" , |
| 341 |
.picture = "" , |
| 342 |
.initial = "/dev/stdin" , |
| 343 |
.parent = NULL, |
| 344 |
.occurs_lower = 0 , |
| 345 |
.occurs_upper = 0 , |
| 346 |
.attr = 0x0 , |
| 347 |
.type = FldLiteralA , |
| 348 |
.level = 0 , |
| 349 |
.digits = 0 , |
| 350 |
.rdigits = 0 , |
| 351 |
.dummy = 0 , |
| 352 |
}; |
| 353 |
|
| 354 |
unsigned char __gg___data_dev_stdout[] = "/dev/stdout"; |
| 355 |
struct cblc_field_t __gg___dev_stdout = { |
| 356 |
.data = __gg___data_dev_stdout , |
| 357 |
.capacity = sizeof(__gg___data_dev_stdout)-1 , |
| 358 |
.allocated = sizeof(__gg___data_dev_stdout)-1 , |
| 359 |
.offset = 0 , |
| 360 |
.name = "_dev_stdout" , |
| 361 |
.picture = "" , |
| 362 |
.initial = "/dev/stdout" , |
| 363 |
.parent = NULL, |
| 364 |
.occurs_lower = 0 , |
| 365 |
.occurs_upper = 0 , |
| 366 |
.attr = 0x0 , |
| 367 |
.type = FldLiteralA , |
| 368 |
.level = 0 , |
| 369 |
.digits = 0 , |
| 370 |
.rdigits = 0 , |
| 371 |
.dummy = 0 , |
| 372 |
}; |
| 373 |
|
| 374 |
unsigned char __gg___data_dev_stderr[] = "/dev/stderr"; |
| 375 |
struct cblc_field_t __gg___dev_stderr = { |
| 376 |
.data = __gg___data_dev_stderr , |
| 377 |
.capacity = sizeof(__gg___data_dev_stderr)-1 , |
| 378 |
.allocated = sizeof(__gg___data_dev_stderr)-1 , |
| 379 |
.offset = 0 , |
| 380 |
.name = "_dev_stderr" , |
| 381 |
.picture = "" , |
| 382 |
.initial = "/dev/stderr" , |
| 383 |
.parent = NULL, |
| 384 |
.occurs_lower = 0 , |
| 385 |
.occurs_upper = 0 , |
| 386 |
.attr = 0x0 , |
| 387 |
.type = FldLiteralA , |
| 388 |
.level = 0 , |
| 389 |
.digits = 0 , |
| 390 |
.rdigits = 0 , |
| 391 |
.dummy = 0 , |
| 392 |
}; |
| 393 |
|
| 394 |
unsigned char __gg___data_dev_null[] = "/dev/null"; |
| 395 |
struct cblc_field_t __gg___dev_null = { |
| 396 |
.data = __gg___data_dev_null , |
| 397 |
.capacity = sizeof(__gg___data_dev_null)-1 , |
| 398 |
.allocated = sizeof(__gg___data_dev_null)-1 , |
| 399 |
.offset = 0 , |
| 400 |
.name = "_dev_null" , |
| 401 |
.picture = "" , |
| 402 |
.initial = "/dev/null" , |
| 403 |
.parent = NULL, |
| 404 |
.occurs_lower = 0 , |
| 405 |
.occurs_upper = 0 , |
| 406 |
.attr = 0x0 , |
| 407 |
.type = FldLiteralA , |
| 408 |
.level = 0 , |
| 409 |
.digits = 0 , |
| 410 |
.rdigits = 0 , |
| 411 |
.dummy = 0 , |
| 412 |
}; |
| 413 |
|
| 414 |
#pragma GCC diagnostic pop |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|