GnuCOBOL  2.0
A free COBOL compiler
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
coblocal.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007-2012 Roger While
3 
4  This file is part of GNU Cobol.
5 
6  The GNU Cobol runtime library is free software: you can redistribute it
7  and/or modify it under the terms of the GNU Lesser General Public License
8  as published by the Free Software Foundation, either version 3 of the
9  License, or (at your option) any later version.
10 
11  GNU Cobol is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with GNU Cobol. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 
21 #ifndef COB_LOCAL_H
22 #define COB_LOCAL_H
23 
24 #ifdef HAVE_STRINGS_H
25 #include <strings.h>
26 #endif
27 
28 /* We use this file to define/prototype things that should not be
29  exported to user space
30 */
31 
32 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
33 #include <float.h>
34 #define finite _finite
35 #endif
36 
37 #if defined(ENABLE_NLS) && defined(COB_NLS_RUNTIME)
38 #include "lib/gettext.h"
39 #define _(s) gettext(s)
40 #define N_(s) gettext_noop(s)
41 #else
42 #define _(s) s
43 #define N_(s) s
44 #endif
45 
46 
47 #if defined(_WIN32) || defined(__CYGWIN__)
48 #define COB_HIDDEN extern
49 #elif defined(__GNUC__) && __GNUC__ >= 4
50 /* Also OK for icc which defines __GNUC__ */
51 #define COB_HIDDEN extern __attribute__ ((visibility("hidden")))
52 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
53 /* Note - >= 0x590 supports gcc syntax */
54 #define COB_HIDDEN extern __hidden
55 #else
56 #define COB_HIDDEN extern
57 #endif
58 
59 #ifndef F_OK
60 #define F_OK 0
61 #endif
62 
63 #ifndef X_OK
64 #define X_OK 1
65 #endif
66 
67 #ifndef W_OK
68 #define W_OK 2
69 #endif
70 
71 #ifndef R_OK
72 #define R_OK 4
73 #endif
74 
75 /* Stacked field depth */
76 #define COB_DEPTH_LEVEL 32U
77 
78 /* Not-A-Number */
79 #define COB_DECIMAL_NAN -32768
80 
81 /* Infinity */
82 #define COB_DECIMAL_INF -32767
83 
84 /* GMP decimal default */
85 #define COB_MPZ_DEF 1024UL
86 
87 /* GMP floating precision */
88 #define COB_MPF_PREC 2048UL
89 
90 /* Complex calculation cutoff value */
91 /* This MUST be <= COB_MPF_PREC */
92 #define COB_MPF_CUTOFF 1024UL
93 
94 
95 /* Floating-decimal */
96 #ifdef WORDS_BIGENDIAN
97 #define COB_128_MSW(x) x[0]
98 #define COB_128_LSW(x) x[1]
99 #define COB_MPZ_ENDIAN 1
100 #else
101 #define COB_128_MSW(x) x[1]
102 #define COB_128_LSW(x) x[0]
103 #define COB_MPZ_ENDIAN -1
104 #endif
105 
106 /* Mask for inf/nan */
107 #define COB_DEC_SPECIAL COB_U64_C(0x7800000000000000)
108 /* Mask for extended */
109 #define COB_DEC_EXTEND COB_U64_C(0x6000000000000000)
110 /* Mask for sign */
111 #define COB_DEC_SIGN COB_U64_C(0x8000000000000000)
112 
113 #define COB_64_IS_SPECIAL(x) ((x & COB_DEC_SPECIAL) == COB_DEC_SPECIAL)
114 #define COB_128_IS_SPECIAL(x) \
115  ((COB_128_MSW(x) & COB_DEC_SPECIAL) == COB_DEC_SPECIAL)
116 #define COB_64_IS_EXTEND(x) ((x & COB_DEC_EXTEND) == COB_DEC_EXTEND)
117 #define COB_128_IS_EXTEND(x) \
118  ((COB_128_MSW(x) & COB_DEC_EXTEND) == COB_DEC_EXTEND)
119 
120 /* Exponent 1 - 10 bits after sign bit */
121 #define COB_64_EXPO_1 COB_U64_C(0x7FE0000000000000)
122 /* Significand 1 */
123 #define COB_64_SIGF_1 COB_U64_C(0x001FFFFFFFFFFFFF)
124 /* Exponent 2 - 10 bits after (sign bit + 2) */
125 #define COB_64_EXPO_2 COB_U64_C(0x1FF8000000000000)
126 /* Significand 2 */
127 #define COB_64_SIGF_2 COB_U64_C(0x0007FFFFFFFFFFFF)
128 /* Extended or bit */
129 #define COB_64_OR_EXTEND COB_U64_C(0x0020000000000000)
130 
131 /* Exponent 1 - 14 bits after sign bit */
132 #define COB_128_EXPO_1 COB_U64_C(0x7FFE000000000000)
133 /* Significand 1 */
134 #define COB_128_SIGF_1 COB_U64_C(0x0001FFFFFFFFFFFF)
135 /* Exponent 2 - 14 bits after (sign bit + 2) */
136 #define COB_128_EXPO_2 COB_U64_C(0x1FFF800000000000)
137 /* Significand 2 */
138 #define COB_128_SIGF_2 COB_U64_C(0x00007FFFFFFFFFFF)
139 /* Extended or bit */
140 #define COB_128_OR_EXTEND COB_U64_C(0x0002000000000000)
141 
142 /* Field/attribute initializers */
143 #define COB_FIELD_INIT(x,y,z) do { \
144  field.size = x; \
145  field.data = y; \
146  field.attr = z; \
147  } while (0)
148 
149 #define COB_ATTR_INIT(u,v,x,y,z) do { \
150  attr.type = u; \
151  attr.digits = v; \
152  attr.scale = x; \
153  attr.flags = y; \
154  attr.pic = z; \
155  } while (0)
156 
157 #define COB_GET_SIGN(f) \
158  (COB_FIELD_HAVE_SIGN (f) ? cob_real_get_sign (f) : 0)
159 #define COB_PUT_SIGN(f,s) \
160  do { if (COB_FIELD_HAVE_SIGN (f)) cob_real_put_sign (f, s); } while (0)
161 
162 #ifdef COB_PARAM_CHECK
163 #define COB_CHK_PARMS(x,z) \
164  cob_parameter_check (#x, z)
165 #else
166 #define COB_CHK_PARMS(x,z)
167 #endif
168 
169 /* Convert a digit (e.g., '0') into an integer (e.g., 0) */
170 #define COB_D2I(x) ((x) & 0x0F)
171 #if 0 /* RXWRXW - D2I */
172 #define COB_D2I(x) ((x) - '0')
173 #endif
174 
175 /* Convert an integer (e.g., 0) into a digit (e.g., '0') */
176 #define COB_I2D(x) ((x) + '0')
177 
178 #define COB_MODULE_PTR cobglobptr->cob_current_module
179 
180 #define COB_TERM_BUFF cobglobptr->cob_term_buff
181 #define COB_DISP_TO_STDERR cobglobptr->cob_disp_to_stderr
182 #define COB_BEEP_VALUE cobglobptr->cob_beep_value
183 #define COB_ACCEPT_STATUS cobglobptr->cob_accept_status
184 #define COB_TIMEOUT_SCALE cobglobptr->cob_timeout_scale
185 #define COB_EXTENDED_STATUS cobglobptr->cob_extended_status
186 #define COB_USE_ESC cobglobptr->cob_use_esc
187 #define COB_MAX_Y_COORD cobglobptr->cob_max_y
188 #define COB_MAX_X_COORD cobglobptr->cob_max_x
189 
190 #ifdef __cplusplus
191 extern "C" {
192 #endif
193 
194 /* Structure with pointers to the current runtime variables. */
195 typedef struct runtime_env {
196  /* call.c */
197  unsigned int* physical_cancel;
199  unsigned int* name_convert;
201  char** resolve_path; /* COB_LIBRARY_PATH */
203  size_t* resolve_size; /* Array size of resolve_path*/
206 
207  /* fileio.c */
208  unsigned int* cob_do_sync;
210  unsigned int* cob_ls_uses_cr;
214  size_t* cob_sort_chunk;
218  unsigned int* cob_ls_nulls;
220  unsigned int* cob_ls_fixed;
225 
226  /* move.c */
227  unsigned int* cob_local_edit;
229 
230  /* screenio.c */
233 
234  /* others */
238 
239  /* others rescanned on SET ENVIRONMENT */
246 
247 } runtime_env;
248 
249 /* Local function prototypes */
255 COB_HIDDEN void cob_init_strings (void);
258 
259 COB_HIDDEN void cob_exit_screen (void);
260 
261 COB_HIDDEN void cob_exit_numeric (void);
262 COB_HIDDEN void cob_exit_fileio (void);
263 COB_HIDDEN void cob_exit_call (void);
264 COB_HIDDEN void cob_exit_intrinsic (void);
265 COB_HIDDEN void cob_exit_strings (void);
266 
267 COB_HIDDEN char *cob_strdup (const char *);
268 
270 COB_HIDDEN void cob_real_put_sign (cob_field *, const int);
271 
273  const int);
275 COB_HIDDEN void cob_print_ieeedec (const cob_field *, FILE *);
276 COB_HIDDEN void cob_print_realbin (const cob_field *, FILE *,
277  const int);
278 
279 COB_HIDDEN void cob_screen_set_mode (const cob_u32_t);
280 COB_HIDDEN void cob_set_exception (const int);
282 COB_HIDDEN int cob_check_env_true (char*);
283 COB_HIDDEN int cob_check_env_false (char*);
284 COB_HIDDEN const char *cob_get_exception_name (void);
285 COB_HIDDEN void cob_field_to_string (const cob_field *, void *,
286  const size_t);
287 COB_HIDDEN void cob_parameter_check (const char *, const int);
288 COB_HIDDEN void cob_runtime_error (const char *, ...) COB_A_FORMAT12;
289 
290 COB_HIDDEN char* cob_save_env_value (char*, char*);
291 
292 #ifdef __cplusplus
293 }
294 #endif
295 
296 #undef COB_HIDDEN
297 
298 #endif /* COB_LOCAL_H */