| 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 |
#ifndef GCOBOLIO_H_ |
| 31 |
#define GCOBOLIO_H_ |
| 32 |
|
| 33 |
#include <cstdio> |
| 34 |
|
| 35 |
#include <map> |
| 36 |
#include <unordered_map> |
| 37 |
#include <vector> |
| 38 |
|
| 39 |
// RUNTIME structures *must* match the ones created in structs.c and initialized |
| 40 |
// and used in genapi.c. It's actually not all that important to emphasize that |
| 41 |
// fact, since the compiled executable will crash and burn quickly if they don't |
| 42 |
// match precisely. |
| 43 |
|
| 44 |
// Note that it must match the same structure in the GDB-COBOL debugger |
| 45 |
|
| 46 |
typedef struct cblc_field_t |
| 47 |
{ |
| 48 |
// This structure must match the code in structs.cc |
| 49 |
unsigned char *data; // The runtime data. There is no null terminator |
| 50 |
size_t capacity; // The size of "data" |
| 51 |
size_t allocated; // The number of bytes available for capacity |
| 52 |
size_t offset; // Offset from our ancestor (see note below) |
| 53 |
char *name; // The null-terminated name of this variable |
| 54 |
char *picture; // The null-terminated picture string. |
| 55 |
char *initial; // The null_terminated initial value |
| 56 |
struct cblc_field_t *parent;// This field's immediate parent field |
| 57 |
size_t occurs_lower; // non-zero for a table |
| 58 |
size_t occurs_upper; // non-zero for a table |
| 59 |
unsigned long long attr; // See cbl_field_attr_t |
| 60 |
signed char type; // A one-byte copy of cbl_field_type_t |
| 61 |
signed char level; // This variable's level in the naming heirarchy |
| 62 |
signed char digits; // Digits specified in PIC string; e.g. 5 for 99v999 |
| 63 |
signed char rdigits; // Digits to the right of the decimal point. 3 for 99v999 |
| 64 |
int dummy; // GCC seems to want an even number of 32-bit values |
| 65 |
} cblc_field_t; |
| 66 |
|
| 67 |
/* |
| 68 |
* Implementation details |
| 69 |
*/ |
| 70 |
|
| 71 |
class supplemental_t; |
| 72 |
|
| 73 |
enum cblc_file_prior_op_t |
| 74 |
{ |
| 75 |
file_op_none, |
| 76 |
file_op_open, |
| 77 |
file_op_start, |
| 78 |
file_op_read, |
| 79 |
file_op_write, |
| 80 |
file_op_rewrite, |
| 81 |
file_op_delete, |
| 82 |
file_op_close, |
| 83 |
}; |
| 84 |
|
| 85 |
/* end implementation details */ |
| 86 |
|
| 87 |
enum cblc_file_flags_t |
| 88 |
{ |
| 89 |
file_flag_none_e = 0x00000, |
| 90 |
file_flag_optional_e = 0x00001, |
| 91 |
file_flag_existed_e = 0x00002, |
| 92 |
file_name_quoted_e = 0x00004, |
| 93 |
file_flag_initialized_e = 0x00008, |
| 94 |
}; |
| 95 |
|
| 96 |
typedef struct cblc_file_t |
| 97 |
{ |
| 98 |
// This structure must match the code in structs.cc |
| 99 |
char *name; // This is the name of the structure; might be the name of an environment variable |
| 100 |
size_t symbol_table_index; // of the related cbl_field_t structure |
| 101 |
char *filename; // The name of the file to be opened |
| 102 |
FILE *file_pointer; // The FILE *pointer |
| 103 |
cblc_field_t *default_record; // The record_area |
| 104 |
size_t record_area_min; // The size of the smallest 01 record in the FD |
| 105 |
size_t record_area_max; // The size of the largest 01 record in the FD |
| 106 |
cblc_field_t **keys; // For relative and indexed files. The first is the primary key. Null-terminated. |
| 107 |
int *key_numbers; // One per key -- each key has a number. This table is key_number + 1 |
| 108 |
int *uniques; // One per key |
| 109 |
cblc_field_t *password; // |
| 110 |
cblc_field_t *status; // This must exist, and is the cbl_field_t version of io_status |
| 111 |
cblc_field_t *user_status; // This might exist, and is another copy See 2014 standard, section 9.1.12 |
| 112 |
cblc_field_t *vsam_status; // |
| 113 |
cblc_field_t *record_length; // |
| 114 |
supplemental_t *supplemental; // |
| 115 |
void *implementation; // reserved for any implementation |
| 116 |
size_t reserve; // From I-O section RESERVE clause |
| 117 |
long prior_read_location; // Location of immediately preceding successful read |
| 118 |
cbl_file_org_t org; // from ORGANIZATION clause |
| 119 |
cbl_file_access_t access; // from ACCESS MODE clause |
| 120 |
int mode_char; // 'r', 'w', '+', or 'a' from FILE OPEN statement |
| 121 |
int errnum; // most recent errno; can't reuse "errno" as the name |
| 122 |
file_status_t io_status; // See 2014 standard, section 9.1.12 |
| 123 |
int padding; // Actually a char |
| 124 |
int delimiter; // ends a record; defaults to '\n'. |
| 125 |
int flags; // cblc_file_flags_t |
| 126 |
int recent_char; // This is the most recent char sent to the file |
| 127 |
int recent_key; |
| 128 |
cblc_file_prior_op_t prior_op; // run-time type is INT |
| 129 |
int dummy; |
| 130 |
} cblc_file_t; |
| 131 |
|
| 132 |
|
| 133 |
/* In various arithmetic routines implemented in libgcobol, it is oftent the |
| 134 |
case that complicates lists of variables need to be conveyed. For example, |
| 135 |
"ADD A B C D GIVING E" and "ADD A TO B C D" are valid instructions. |
| 136 |
|
| 137 |
These treeplets (triplets of trees) were created to handle that. */ |
| 138 |
|
| 139 |
extern cblc_field_t ** __gg__treeplet_1f; |
| 140 |
extern size_t * __gg__treeplet_1o; |
| 141 |
extern size_t * __gg__treeplet_1s; |
| 142 |
extern cblc_field_t ** __gg__treeplet_2f; |
| 143 |
extern size_t * __gg__treeplet_2o; |
| 144 |
extern size_t * __gg__treeplet_2s; |
| 145 |
extern cblc_field_t ** __gg__treeplet_3f; |
| 146 |
extern size_t * __gg__treeplet_3o; |
| 147 |
extern size_t * __gg__treeplet_3s; |
| 148 |
extern cblc_field_t ** __gg__treeplet_4f; |
| 149 |
extern size_t * __gg__treeplet_4o; |
| 150 |
extern size_t * __gg__treeplet_4s; |
| 151 |
|
| 152 |
extern int * __gg__fourplet_flags; |
| 153 |
|
| 154 |
#endif |