GnuCOBOL  2.0
A free COBOL compiler
coblocal.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007-2012, 2014-2015 Free Software Foundation, Inc.
3  Written by Roger While, Simon Sobisch, Ron Norman
4 
5  This file is part of GnuCOBOL.
6 
7  The GnuCOBOL runtime library is free software: you can redistribute it
8  and/or modify it under the terms of the GNU Lesser General Public License
9  as published by the Free Software Foundation, either version 3 of the
10  License, or (at your option) any later version.
11 
12  GnuCOBOL is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GnuCOBOL. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #ifndef COB_LOCAL_H
23 #define COB_LOCAL_H
24 
25 #ifdef HAVE_STRINGS_H
26 #include <strings.h>
27 #endif
28 
29 /* We use this file to define/prototype things that should not be
30  exported to user space
31 */
32 
33 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
34 #include <float.h>
35 #define finite _finite
36 #endif
37 
38 #if defined(ENABLE_NLS) && defined(COB_NLS_RUNTIME)
39 #include "lib/gettext.h"
40 #define _(s) gettext(s)
41 #define N_(s) gettext_noop(s)
42 #else
43 #define _(s) s
44 #define N_(s) s
45 #endif
46 
47 
48 #if defined(_WIN32) || defined(__CYGWIN__)
49 #define COB_HIDDEN extern
50 #elif defined(__GNUC__) && __GNUC__ >= 4
51 /* Also OK for icc which defines __GNUC__ */
52 #define COB_HIDDEN extern __attribute__ ((visibility("hidden")))
53 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
54 /* Note - >= 0x590 supports gcc syntax */
55 #define COB_HIDDEN extern __hidden
56 #else
57 #define COB_HIDDEN extern
58 #endif
59 
60 #ifndef F_OK
61 #define F_OK 0
62 #endif
63 
64 #ifndef X_OK
65 #define X_OK 1
66 #endif
67 
68 #ifndef W_OK
69 #define W_OK 2
70 #endif
71 
72 #ifndef R_OK
73 #define R_OK 4
74 #endif
75 
76 /* Stacked field depth */
77 #define COB_DEPTH_LEVEL 32U
78 
79 /* Not-A-Number */
80 #define COB_DECIMAL_NAN -32768
81 
82 /* Infinity */
83 #define COB_DECIMAL_INF -32767
84 
85 /* GMP decimal default */
86 #define COB_MPZ_DEF 1024UL
87 
88 /* GMP floating precision */
89 #define COB_MPF_PREC 2048UL
90 
91 /* Complex calculation cutoff value */
92 /* This MUST be <= COB_MPF_PREC */
93 #define COB_MPF_CUTOFF 1024UL
94 
95 
96 /* Floating-decimal */
97 #ifdef WORDS_BIGENDIAN
98 #define COB_128_MSW(x) x[0]
99 #define COB_128_LSW(x) x[1]
100 #define COB_MPZ_ENDIAN 1
101 #else
102 #define COB_128_MSW(x) x[1]
103 #define COB_128_LSW(x) x[0]
104 #define COB_MPZ_ENDIAN -1
105 #endif
106 
107 /* Mask for inf/nan */
108 #define COB_DEC_SPECIAL COB_U64_C(0x7800000000000000)
109 /* Mask for extended */
110 #define COB_DEC_EXTEND COB_U64_C(0x6000000000000000)
111 /* Mask for sign */
112 #define COB_DEC_SIGN COB_U64_C(0x8000000000000000)
113 
114 #define COB_64_IS_SPECIAL(x) ((x & COB_DEC_SPECIAL) == COB_DEC_SPECIAL)
115 #define COB_128_IS_SPECIAL(x) \
116  ((COB_128_MSW(x) & COB_DEC_SPECIAL) == COB_DEC_SPECIAL)
117 #define COB_64_IS_EXTEND(x) ((x & COB_DEC_EXTEND) == COB_DEC_EXTEND)
118 #define COB_128_IS_EXTEND(x) \
119  ((COB_128_MSW(x) & COB_DEC_EXTEND) == COB_DEC_EXTEND)
120 
121 /* Exponent 1 - 10 bits after sign bit */
122 #define COB_64_EXPO_1 COB_U64_C(0x7FE0000000000000)
123 /* Significand 1 */
124 #define COB_64_SIGF_1 COB_U64_C(0x001FFFFFFFFFFFFF)
125 /* Exponent 2 - 10 bits after (sign bit + 2) */
126 #define COB_64_EXPO_2 COB_U64_C(0x1FF8000000000000)
127 /* Significand 2 */
128 #define COB_64_SIGF_2 COB_U64_C(0x0007FFFFFFFFFFFF)
129 /* Extended or bit */
130 #define COB_64_OR_EXTEND COB_U64_C(0x0020000000000000)
131 
132 /* Exponent 1 - 14 bits after sign bit */
133 #define COB_128_EXPO_1 COB_U64_C(0x7FFE000000000000)
134 /* Significand 1 */
135 #define COB_128_SIGF_1 COB_U64_C(0x0001FFFFFFFFFFFF)
136 /* Exponent 2 - 14 bits after (sign bit + 2) */
137 #define COB_128_EXPO_2 COB_U64_C(0x1FFF800000000000)
138 /* Significand 2 */
139 #define COB_128_SIGF_2 COB_U64_C(0x00007FFFFFFFFFFF)
140 /* Extended or bit */
141 #define COB_128_OR_EXTEND COB_U64_C(0x0002000000000000)
142 
143 /* Field/attribute initializers */
144 #define COB_FIELD_INIT(x,y,z) do { \
145  field.size = x; \
146  field.data = y; \
147  field.attr = z; \
148  } ONCE_COB
149 
150 #define COB_ATTR_INIT(u,v,x,y,z) do { \
151  attr.type = u; \
152  attr.digits = v; \
153  attr.scale = x; \
154  attr.flags = y; \
155  attr.pic = z; \
156  } ONCE_COB
157 
158 #define COB_GET_SIGN(f) \
159  (COB_FIELD_HAVE_SIGN (f) ? cob_real_get_sign (f) : 0)
160 #define COB_PUT_SIGN(f,s) \
161  do { if (COB_FIELD_HAVE_SIGN (f)) cob_real_put_sign (f, s); } ONCE_COB
162 
163 #ifdef COB_PARAM_CHECK
164 #define COB_CHK_PARMS(x,z) \
165  cob_parameter_check (#x, z)
166 #else
167 #define COB_CHK_PARMS(x,z)
168 #endif
169 
170 /* byte offset to structure member */
171 #if !defined(_OFFSET_OF_) && !defined(offsetof)
172 #define _OFFSET_OF_
173 #define offsetof(s_name,m_name) (int)(long)&(((s_name*)0))->m_name
174 #endif
175 
176 /* Convert a digit (e.g., '0') into an integer (e.g., 0) */
177 #define COB_D2I(x) ((x) & 0x0F)
178 #if 0 /* RXWRXW - D2I */
179 #define COB_D2I(x) ((x) - '0')
180 #endif
181 
182 /* Convert an integer (e.g., 0) into a digit (e.g., '0') */
183 #define COB_I2D(x) ((x) + '0')
184 
185 #define COB_MODULE_PTR cobglobptr->cob_current_module
186 #define COB_TERM_BUFF cobglobptr->cob_term_buff
187 #define COB_ACCEPT_STATUS cobglobptr->cob_accept_status
188 #define COB_MAX_Y_COORD cobglobptr->cob_max_y
189 #define COB_MAX_X_COORD cobglobptr->cob_max_x
190 
191 #define COB_DISP_TO_STDERR cobsetptr->cob_disp_to_stderr
192 #define COB_BEEP_VALUE cobsetptr->cob_beep_value
193 #define COB_TIMEOUT_SCALE cobsetptr->cob_timeout_scale
194 #define COB_EXTENDED_STATUS cobsetptr->cob_extended_status
195 #define COB_USE_ESC cobsetptr->cob_use_esc
196 
197 #ifdef __cplusplus
198 extern "C" {
199 #endif
200 
201 /* Global settings structure */
202 
203 typedef struct __cob_settings {
204  unsigned int cob_display_warn; /* Display warnings */
205  unsigned int cob_env_mangle; /* Mangle env names */
206  unsigned int cob_line_trace;
207  unsigned int cob_config_cur; /* Current runtime.cfg file being processed */
208  unsigned int cob_config_num; /* Number of different runtime.cfg files read */
209  char **cob_config_file; /* Keep all file names for later reporting */
212  char *cob_sys_lang; /* LANG setting from env */
213  char *cob_sys_term; /* TERM setting from env */
214  char *cob_sys_type; /* OSTYPE setting from env */
216 
217  /* call.c */
218  unsigned int cob_physical_cancel;
219  unsigned int name_convert;
222 
223  size_t* resolve_size; /* Array size of resolve_path*/
226 
227  /* fileio.c */
228  unsigned int cob_unix_lf; /* Use POSIX LF */
229  unsigned int cob_do_sync;
230  unsigned int cob_ls_uses_cr;
231  unsigned int cob_ls_nulls;
232  unsigned int cob_ls_fixed;
233  unsigned int cob_varseq_type;
235  char *bdb_home;
238 
239  /* move.c */
240  unsigned int cob_local_edit;
241 
242  /* screenio.c */
243  unsigned int cob_legacy;
244  unsigned int cob_disp_to_stderr; /* Redirect to stderr */
245  unsigned int cob_beep_value; /* Bell disposition */
246  unsigned int cob_extended_status; /* Extended status */
247  unsigned int cob_use_esc; /* Check ESC key */
248  int cob_timeout_scale; /* timeout scale */
249  int cob_insert_mode; /* insert toggle, 0=off, 1=on */
250 } cob_settings;
251 
252 
253 struct config_enum {
254  const char *match; /* Alternate word that could be used */
255  const char *value; /* Internal value for this 'word' */
256 };
257 
258 /* Format of table for capturing run-time config information */
259 
260 /* Datetime structure */
261 struct cob_time
262 {
263  int year;
264  int month; /* 1 = Jan ... 12 = Dec */
265  int day_of_month; /* 1 ... 31 */
266  int day_of_week; /* 1 = Monday ... 7 = Sunday */
267  int hour;
268  int minute;
269  int second;
272  int utc_offset; /* in minutes */
273 };
274 
275 struct config_tbl {
276  const char *env_name; /* Env Var name */
277  const char *conf_name; /* Name used in run-time config file */
278  const char *default_val; /* Default value */
279  struct config_enum *enums; /* Table of Alternate values */
280  int env_group; /* Grouping for display of run-time options */
281  int data_type; /* Data type */
282  int data_loc; /* Location within structure */
283  int data_len; /* Length of referenced field */
284  int config_num; /* Set by which runtime.cfg file */
285  int set_by; /* value set by a different keyword */
286  unsigned long min_value; /* Minium accepted value */
287  unsigned long max_value; /* Maximum accepted value */
288 };
289 
290 #define ENV_NOT (1 << 1) /* Negate True/False value setting */
291 #define ENV_INT (1 << 2) /* an 'int' */
292 #define ENV_SIZE (1 << 3) /* size; number with K - kb, M - mb, G - GB */
293 #define ENV_BOOL (1 << 4) /* int boolean; Yes, True, 1, No, False, 0, ... */
294 #define ENV_CHAR (1 << 5) /* inline 'char[]' field */
295 #define ENV_STR (1 << 6) /* a pointer to a string */
296 #define ENV_PATH (1 << 7) /* a pointer to a file system path */
297 #define ENV_ENUM (1 << 8) /* Value must in 'enum' list as match */
298 #define ENV_ENUMVAL (1 << 9) /* Value must in 'enum' list as match or value */
299 
300 #define STS_ENVSET (1 << 15) /* value set via Env Var */
301 #define STS_CNFSET (1 << 16) /* value set via config file */
302 #define STS_ENVCLR (1 << 17) /* value removed from Env Var */
303 #define STS_RESET (1 << 18) /* value was reset back to default */
304 #define STS_FNCSET (1 << 19) /* value set via function call */
305 
306 #define GRP_HIDE 0
307 #define GRP_CALL 1
308 #define GRP_FILE 2
309 #define GRP_SCREEN 3
310 #define GRP_MISC 4
311 #define GRP_SYSENV 5
312 #define GRP_MAX 6
313 
314 #define SETPOS(member) offsetof(cob_settings,member),sizeof(cobsetptr->member),0,0
315 
316 
317 /* Local function prototypes */
323 COB_HIDDEN void cob_init_strings (void);
326 
327 COB_HIDDEN void cob_exit_screen (void);
328 
329 COB_HIDDEN void cob_exit_numeric (void);
330 COB_HIDDEN void cob_exit_fileio (void);
331 COB_HIDDEN void cob_exit_call (void);
332 COB_HIDDEN void cob_exit_intrinsic (void);
333 COB_HIDDEN void cob_exit_strings (void);
334 
335 COB_HIDDEN char *cob_strdup (const char *);
336 
338 COB_HIDDEN void cob_real_put_sign (cob_field *, const int);
339 
341  const int);
343 COB_HIDDEN void cob_print_ieeedec (const cob_field *, FILE *);
344 COB_HIDDEN void cob_print_realbin (const cob_field *, FILE *,
345  const int);
346 
349 COB_HIDDEN int cob_check_env_true (char*);
350 COB_HIDDEN int cob_check_env_false (char*);
351 COB_HIDDEN const char *cob_get_exception_name (void);
352 COB_HIDDEN void cob_field_to_string (const cob_field *, void *,
353  const size_t);
354 COB_HIDDEN void cob_parameter_check (const char *, const int);
355 COB_HIDDEN void cob_runtime_error (const char *, ...) COB_A_FORMAT12;
356 
357 COB_HIDDEN char* cob_save_env_value (char*, char*);
359 
360 COB_HIDDEN int cob_ctoi (const char);
361 
363 
364 #ifdef __cplusplus
365 }
366 #endif
367 
368 #undef COB_HIDDEN
369 
370 #endif /* COB_LOCAL_H */
struct __cob_settings cob_settings
char * cob_sys_term
Definition: coblocal.h:213
void cob_init_numeric(cob_global *)
Definition: numeric.c:2671
unsigned int cob_varseq_type
Definition: coblocal.h:233
const char * match
Definition: coblocal.h:254
unsigned int cob_unix_lf
Definition: coblocal.h:228
char * cob_save_env_value(char *, char *)
Definition: common.c:4319
#define COB_HIDDEN
Definition: coblocal.h:57
unsigned long min_value
Definition: coblocal.h:286
unsigned long max_value
Definition: coblocal.h:287
int utc_offset
Definition: coblocal.h:272
#define cob_u32_t
Definition: common.h:31
char * cob_sys_lang
Definition: coblocal.h:212
int cob_insert_mode
Definition: coblocal.h:249
const char * value
Definition: coblocal.h:255
char * cob_sys_type
Definition: coblocal.h:214
const char * conf_name
Definition: coblocal.h:277
const char * default_val
Definition: coblocal.h:278
void cob_exit_fileio(void)
Definition: fileio.c:6282
int day_of_month
Definition: coblocal.h:265
unsigned int cob_legacy
Definition: coblocal.h:243
int set_by
Definition: coblocal.h:285
unsigned int cob_display_warn
Definition: coblocal.h:204
char * cob_user_name
Definition: coblocal.h:211
char * cob_file_path
Definition: coblocal.h:234
char * cob_preload_str
Definition: coblocal.h:220
size_t cob_sort_memory
Definition: coblocal.h:236
void cob_init_intrinsic(cob_global *)
Definition: intrinsic.c:6555
void cob_parameter_check(const char *, const int)
Definition: common.c:1907
void cob_print_realbin(const cob_field *, FILE *, const int)
Definition: numeric.c:1676
unsigned int cob_use_esc
Definition: coblocal.h:247
char * cob_library_path
Definition: coblocal.h:221
int cob_ctoi(const char)
Definition: common.c:2651
unsigned int cob_do_sync
Definition: coblocal.h:229
size_t cob_sort_chunk
Definition: coblocal.h:237
#define COB_A_FORMAT12
Definition: common.h:367
int data_type
Definition: coblocal.h:281
int day_of_week
Definition: coblocal.h:266
int config_num
Definition: coblocal.h:284
const char * env_name
Definition: coblocal.h:276
void cob_init_fileio(cob_global *, cob_settings *)
Definition: fileio.c:6345
unsigned int cob_ls_nulls
Definition: coblocal.h:231
size_t * resolve_size
Definition: coblocal.h:223
void cob_field_to_string(const cob_field *, void *, const size_t)
Definition: common.c:1492
int cob_check_env_false(char *)
Definition: common.c:1086
void cob_runtime_error(const char *,...) COB_A_FORMAT12
Definition: common.c:1543
const char * cob_get_exception_name(void)
Definition: common.c:1199
int year
Definition: coblocal.h:263
unsigned int cob_beep_value
Definition: coblocal.h:245
int cob_check_env_true(char *)
Definition: common.c:1073
int cob_get_exception_code(void)
Definition: common.c:1193
unsigned int cob_ls_fixed
Definition: coblocal.h:232
unsigned int cob_line_trace
Definition: coblocal.h:206
int data_loc
Definition: coblocal.h:282
char * bdb_home
Definition: coblocal.h:235
void cob_init_strings(void)
Definition: strings.c:652
unsigned int cob_ls_uses_cr
Definition: coblocal.h:230
void cob_print_ieeedec(const cob_field *, FILE *)
Definition: numeric.c:1647
char * cob_preload_env
Definition: coblocal.h:225
void cob_init_call(cob_global *, cob_settings *)
Definition: call.c:1307
void cob_init_move(cob_global *, cob_settings *)
Definition: move.c:1683
void cob_decimal_setget_fld(cob_field *, cob_field *, const int)
Definition: numeric.c:2007
void cob_init_screenio(cob_global *, cob_settings *)
Definition: screenio.c:2567
void cob_exit_call(void)
Definition: call.c:1204
void cob_exit_screen(void)
Definition: screenio.c:2401
cob_settings * cob_get_settings_ptr(void)
Definition: common.c:5384
void cob_screen_set_mode(const cob_u32_t)
Definition: screenio.c:2388
void cob_exit_numeric(void)
Definition: numeric.c:2637
struct cob_time cob_get_current_date_and_time(void)
Definition: common.c:2699
char * cob_strdup(const char *)
Definition: common.c:1308
unsigned int cob_extended_status
Definition: coblocal.h:246
void cob_init_termio(cob_global *, cob_settings *)
Definition: termio.c:343
void cob_exit_intrinsic(void)
Definition: intrinsic.c:6521
unsigned int cob_disp_to_stderr
Definition: coblocal.h:244
int minute
Definition: coblocal.h:268
int offset_known
Definition: coblocal.h:271
unsigned int cob_env_mangle
Definition: coblocal.h:205
void cob_exit_strings(void)
Definition: strings.c:634
unsigned int cob_local_edit
Definition: coblocal.h:240
int month
Definition: coblocal.h:264
int nanosecond
Definition: coblocal.h:270
int second
Definition: coblocal.h:269
void cob_decimal_move_temp(cob_field *, cob_field *)
Definition: intrinsic.c:3104
char * cob_preload_resolved
Definition: coblocal.h:224
unsigned int cob_config_num
Definition: coblocal.h:208
struct config_enum * enums
Definition: coblocal.h:279
char * cob_trace_filename
Definition: coblocal.h:210
void cob_real_put_sign(cob_field *, const int)
Definition: common.c:2246
unsigned int name_convert
Definition: coblocal.h:219
char ** cob_config_file
Definition: coblocal.h:209
char * cob_debug_log
Definition: coblocal.h:215
int data_len
Definition: coblocal.h:283
unsigned int cob_physical_cancel
Definition: coblocal.h:218
int hour
Definition: coblocal.h:267
int cob_timeout_scale
Definition: coblocal.h:248
int env_group
Definition: coblocal.h:280
int cob_real_get_sign(cob_field *)
Definition: common.c:2205
unsigned int cob_config_cur
Definition: coblocal.h:207