OpenCOBOL 1.1pre-rel
|
00001 /* 00002 * Copyright (C) 2002-2009 Keisuke Nishida 00003 * Copyright (C) 2007-2009 Roger While 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public License 00007 * as published by the Free Software Foundation; either version 2.1, 00008 * or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; see the file COPYING.LIB. If 00017 * not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor 00018 * Boston, MA 02110-1301 USA 00019 */ 00020 00021 #ifndef COB_COMMON_H 00022 #define COB_COMMON_H 00023 00024 #ifdef _MSC_VER 00025 00026 #define _CRT_SECURE_NO_DEPRECATE 1 00027 #define inline _inline 00028 #define COB_INLINE _inline 00029 #include <malloc.h> 00030 #include <io.h> 00031 #include <fcntl.h> 00032 #pragma warning(disable: 4996) 00033 #define strncasecmp _strnicmp 00034 #define strcasecmp _stricmp 00035 #define __attribute__(x) 00036 #define __i386__ 00037 00038 #ifdef LIBCOB_EXPORTS 00039 #define DLL_EXPIMP __declspec(dllexport) 00040 #else /* LIBCOB_EXPORTS */ 00041 #define DLL_EXPIMP __declspec(dllimport) 00042 #endif /* LIBCOB_EXPORTS */ 00043 00044 #else /* _MSC_VER */ 00045 00046 #define DLL_EXPIMP 00047 00048 #ifdef __370__ 00049 #define inline __inline 00050 #define COB_INLINE __inline 00051 #elif defined(COB_HAS_INLINE) 00052 #define COB_INLINE inline 00053 #else 00054 #define COB_INLINE 00055 #endif 00056 00057 #endif /* _MSC_VER */ 00058 00059 #if defined(__GNUC__) && (__GNUC__ >= 3) 00060 #define likely(x) __builtin_expect(!!(x), 1) 00061 #define unlikely(x) __builtin_expect(!!(x), 0) 00062 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) 00063 #define COB_NOINLINE __attribute__((noinline)) 00064 #else 00065 #define COB_NOINLINE 00066 #endif 00067 #else 00068 #define likely(x) (x) 00069 #define unlikely(x) (x) 00070 #define COB_NOINLINE 00071 #endif 00072 00073 #if ' ' == 0x40 00074 #define COB_EBCDIC_MACHINE 00075 #endif 00076 00077 typedef unsigned char * ucharptr; 00078 00079 #define COB_MINI_BUFF 256 00080 #define COB_SMALL_BUFF 1024 00081 #define COB_NORMAL_BUFF 2048 00082 #define COB_MEDIUM_BUFF 8192 00083 #define COB_LARGE_BUFF 16384 00084 #define COB_MINI_MAX (COB_MINI_BUFF - 1) 00085 #define COB_SMALL_MAX (COB_SMALL_BUFF - 1) 00086 #define COB_NORMAL_MAX (COB_NORMAL_BUFF - 1) 00087 #define COB_MEDIUM_MAX (COB_MEDIUM_BUFF - 1) 00088 #define COB_LARGE_MAX (COB_LARGE_BUFF - 1) 00089 00090 #define COB_STACK_SIZE 255 00091 00092 #define COB_MAX_FIELD_PARAMS 64 00093 00094 /* 00095 * External 00096 */ 00097 00098 struct cob_external { 00099 struct cob_external *next; 00100 char *ext_alloc; 00101 char *ename; 00102 int esize; 00103 }; 00104 00105 /* 00106 * Field 00107 */ 00108 00109 /* field types */ 00110 00111 #define COB_TYPE_UNKNOWN 0x00 00112 #define COB_TYPE_GROUP 0x01 00113 #define COB_TYPE_BOOLEAN 0x02 00114 00115 #define COB_TYPE_NUMERIC 0x10 00116 #define COB_TYPE_NUMERIC_DISPLAY 0x10 00117 #define COB_TYPE_NUMERIC_BINARY 0x11 00118 #define COB_TYPE_NUMERIC_PACKED 0x12 00119 #define COB_TYPE_NUMERIC_FLOAT 0x13 00120 #define COB_TYPE_NUMERIC_DOUBLE 0x14 00121 #define COB_TYPE_NUMERIC_EDITED 0x24 00122 00123 #define COB_TYPE_ALPHANUMERIC 0x21 00124 #define COB_TYPE_ALPHANUMERIC_ALL 0x22 00125 #define COB_TYPE_ALPHANUMERIC_EDITED 0x23 00126 00127 #define COB_TYPE_NATIONAL 0x40 00128 #define COB_TYPE_NATIONAL_EDITED 0x41 00129 00130 /* field flags */ 00131 00132 #define COB_FLAG_HAVE_SIGN 0x01 00133 #define COB_FLAG_SIGN_SEPARATE 0x02 00134 #define COB_FLAG_SIGN_LEADING 0x04 00135 #define COB_FLAG_BLANK_ZERO 0x08 00136 #define COB_FLAG_JUSTIFIED 0x10 00137 #define COB_FLAG_BINARY_SWAP 0x20 00138 #define COB_FLAG_REAL_BINARY 0x40 00139 #define COB_FLAG_IS_POINTER 0x80 00140 00141 #define COB_FIELD_HAVE_SIGN(f) ((f)->attr->flags & COB_FLAG_HAVE_SIGN) 00142 #define COB_FIELD_SIGN_SEPARATE(f) ((f)->attr->flags & COB_FLAG_SIGN_SEPARATE) 00143 #define COB_FIELD_SIGN_LEADING(f) ((f)->attr->flags & COB_FLAG_SIGN_LEADING) 00144 #define COB_FIELD_BLANK_ZERO(f) ((f)->attr->flags & COB_FLAG_BLANK_ZERO) 00145 #define COB_FIELD_JUSTIFIED(f) ((f)->attr->flags & COB_FLAG_JUSTIFIED) 00146 #define COB_FIELD_BINARY_SWAP(f) ((f)->attr->flags & COB_FLAG_BINARY_SWAP) 00147 #define COB_FIELD_REAL_BINARY(f) ((f)->attr->flags & COB_FLAG_REAL_BINARY) 00148 #define COB_FIELD_IS_POINTER(f) ((f)->attr->flags & COB_FLAG_IS_POINTER) 00149 00150 #define cob_get_sign(f) (COB_FIELD_HAVE_SIGN (f) ? cob_real_get_sign (f) : 0) 00151 #define cob_put_sign(f,s) if (COB_FIELD_HAVE_SIGN (f)) cob_real_put_sign (f, s) 00152 00153 /* field attributes */ 00154 00155 typedef struct { 00156 unsigned char type; 00157 unsigned char digits; 00158 signed char scale; 00159 unsigned char flags; 00160 const char *pic; 00161 } cob_field_attr; 00162 00163 /* field structure */ 00164 00165 typedef struct { 00166 size_t size; 00167 unsigned char *data; 00168 const cob_field_attr *attr; 00169 } cob_field; 00170 00171 #define COB_FIELD_TYPE(f) ((f)->attr->type) 00172 #define COB_FIELD_DIGITS(f) ((f)->attr->digits) 00173 #define COB_FIELD_SCALE(f) ((f)->attr->scale) 00174 #define COB_FIELD_FLAGS(f) ((f)->attr->flags) 00175 #define COB_FIELD_PIC(f) ((f)->attr->pic) 00176 #define COB_FIELD_DATA(f) \ 00177 ((f)->data + \ 00178 ((COB_FIELD_SIGN_SEPARATE (f) && COB_FIELD_SIGN_LEADING (f)) ? 1 : 0)) 00179 #define COB_FIELD_SIZE(f) \ 00180 ((f)->size - (COB_FIELD_SIGN_SEPARATE (f) ? 1 : 0)) 00181 00182 #define COB_FIELD_IS_NUMERIC(f) (COB_FIELD_TYPE (f) & COB_TYPE_NUMERIC) 00183 00184 00185 /* SIGN */ 00186 00187 /* 00188 * positive: 0123456789 00189 * negative: pqrstuvwxy 00190 */ 00191 #define GET_SIGN_ASCII(x) x -= 0x40 00192 #define PUT_SIGN_ASCII(x) x += 0x40 00193 00194 #define COB_DISPLAY_SIGN_ASCII 0 00195 #define COB_DISPLAY_SIGN_EBCDIC 1 00196 00197 /* 00198 * Module 00199 */ 00200 00201 struct cob_module { 00202 struct cob_module *next; 00203 const unsigned char *collating_sequence; 00204 cob_field *crt_status; 00205 cob_field *cursor_pos; 00206 cob_field **cob_procedure_parameters; 00207 const unsigned char display_sign; 00208 const unsigned char decimal_point; 00209 const unsigned char currency_symbol; 00210 const unsigned char numeric_separator; 00211 const unsigned char flag_filename_mapping; 00212 const unsigned char flag_binary_truncate; 00213 const unsigned char flag_pretty_display; 00214 const unsigned char spare8; 00215 }; 00216 00217 /* 00218 * Exception 00219 */ 00220 00221 /* Exception identifier */ 00222 #undef COB_EXCEPTION 00223 #define COB_EXCEPTION(code,tag,name,critical) tag, 00224 00225 enum cob_exception_id { 00226 COB_EC_ZERO, 00227 #include <libcob/exception.def> 00228 COB_EC_MAX 00229 }; 00230 00231 #undef COB_EXCEPTION 00232 00233 /* 00234 * Fatal error 00235 */ 00236 00237 #define COB_FERROR_INITIALIZED 0 00238 #define COB_FERROR_CODEGEN 1 00239 #define COB_FERROR_CHAINING 2 00240 #define COB_FERROR_STACK 3 00241 00242 /* 00243 * Global variables 00244 */ 00245 00246 DLL_EXPIMP extern int cob_initialized; 00247 DLL_EXPIMP extern int cob_exception_code; 00248 00249 DLL_EXPIMP extern struct cob_module *cob_current_module; 00250 00251 DLL_EXPIMP extern int cob_call_params; 00252 DLL_EXPIMP extern int cob_save_call_params; 00253 DLL_EXPIMP extern int cob_initial_external; 00254 00255 DLL_EXPIMP extern cob_field cob_zero; /* ZERO */ 00256 DLL_EXPIMP extern cob_field cob_space; /* SPACE */ 00257 DLL_EXPIMP extern cob_field cob_high; /* HIGH-VALUE */ 00258 DLL_EXPIMP extern cob_field cob_low; /* LOW-VALUE */ 00259 DLL_EXPIMP extern cob_field cob_quote; /* QUOTE */ 00260 DLL_EXPIMP extern cob_field cob_one; /* Numeric ONE */ 00261 00262 /* convert a digit (e.g., '0') into an integer (e.g., 0) */ 00263 #define cob_d2i(x) ((x) - '0') 00264 00265 /* convert an integer (e.g., 0) into a digit (e.g., '0') */ 00266 #define cob_i2d(x) ((x) + '0') 00267 00268 00269 /* 00270 * Function declaration 00271 */ 00272 00273 /* General functions */ 00274 00275 extern void cob_init (int, char **); 00276 extern void cob_module_enter (struct cob_module *); 00277 extern void cob_module_leave (struct cob_module *); 00278 00279 #ifdef __GNUC__ 00280 extern void cobexit (int) __attribute__ ((noreturn)); 00281 extern void cob_stop_run (const int) __attribute__ ((noreturn)); 00282 extern void cob_fatal_error (const unsigned int) __attribute__ ((noreturn)); 00283 extern void cob_runtime_error (const char *, ...) 00284 __attribute__ ((format (printf, 1, 0))); 00285 extern void *cob_malloc (const size_t) __attribute__ ((malloc)); 00286 #else 00287 extern void cobexit (int); 00288 extern void cob_stop_run (const int); 00289 extern void cob_fatal_error (const unsigned int); 00290 extern void cob_runtime_error (const char *, ...); 00291 extern void *cob_malloc (const size_t); 00292 #endif 00293 00294 extern const char *cob_get_exception_name (const int); 00295 00296 extern void cob_set_exception (const int); 00297 extern void cob_check_version (const char *, const char *, const int); 00298 extern void cob_accept_date (cob_field *); 00299 extern void cob_accept_date_yyyymmdd (cob_field *); 00300 extern void cob_accept_day (cob_field *); 00301 extern void cob_accept_day_yyyyddd (cob_field *); 00302 extern void cob_accept_day_of_week (cob_field *); 00303 extern void cob_accept_time (cob_field *); 00304 extern void cob_display_command_line (cob_field *); 00305 extern void cob_accept_command_line (cob_field *); 00306 extern void cob_set_environment (cob_field *, cob_field *); 00307 extern void cob_display_environment (cob_field *); 00308 extern void cob_get_environment (cob_field *, cob_field *); 00309 extern void cob_accept_environment (cob_field *); 00310 extern void cob_display_env_value (cob_field *); 00311 extern void cob_display_arg_number (cob_field *); 00312 extern void cob_accept_arg_number (cob_field *); 00313 extern void cob_accept_arg_value (cob_field *); 00314 extern void cob_chain_setup (void *, const size_t, const size_t); 00315 extern void cob_allocate (unsigned char **, cob_field *, 00316 cob_field *); 00317 extern void cob_free_alloc (unsigned char **, unsigned char *); 00318 extern int cobinit (void); 00319 extern int cobtidy (void); 00320 extern void *cobcommandline (int, int *, char ***, 00321 char ***, char **); 00322 extern char *cobgetenv (const char *); 00323 extern int cobputenv (char *); 00324 00325 /* System routines */ 00326 extern int CBL_ERROR_PROC (unsigned char *, unsigned char *); 00327 extern int CBL_EXIT_PROC (unsigned char *, unsigned char *); 00328 extern int SYSTEM (const unsigned char *); 00329 extern int CBL_AND (unsigned char *, unsigned char *, const int); 00330 extern int CBL_OR (unsigned char *, unsigned char *, const int); 00331 extern int CBL_NOR (unsigned char *, unsigned char *, const int); 00332 extern int CBL_XOR (unsigned char *, unsigned char *, const int); 00333 extern int CBL_IMP (unsigned char *, unsigned char *, const int); 00334 extern int CBL_NIMP (unsigned char *, unsigned char *, const int); 00335 extern int CBL_EQ (unsigned char *, unsigned char *, const int); 00336 extern int CBL_NOT (unsigned char *, const int); 00337 extern int CBL_XF4 (unsigned char *, unsigned char *); 00338 extern int CBL_XF5 (unsigned char *, unsigned char *); 00339 extern int CBL_X91 (unsigned char *, const unsigned char *, 00340 unsigned char *); 00341 extern int CBL_TOUPPER (unsigned char *, const int); 00342 extern int CBL_TOLOWER (unsigned char *, const int); 00343 extern int CBL_OC_NANOSLEEP (unsigned char *); 00344 extern int cob_return_args (unsigned char *); 00345 extern int cob_parameter_size (unsigned char *); 00346 extern int cob_acuw_sleep (unsigned char *); 00347 extern int cob_acuw_justify (unsigned char *, ...); 00348 00349 /* Utilities */ 00350 00351 extern unsigned char *cob_external_addr (const char *, const int); 00352 extern unsigned char *cob_get_pointer (const unsigned char *); 00353 extern void *cob_get_prog_pointer (const unsigned char *); 00354 extern void cob_set_location (const char *, const char *, 00355 const unsigned int, const char *, 00356 const char *, const char *); 00357 extern void cob_ready_trace (void); 00358 extern void cob_reset_trace (void); 00359 00360 /* Switch */ 00361 00362 extern int cob_get_switch (const int); 00363 extern void cob_set_switch (const int, const int); 00364 00365 /* Comparison */ 00366 00367 extern int cob_cmp (cob_field *, cob_field *); 00368 00369 /* Class check */ 00370 00371 extern int cob_is_omitted (const cob_field *); 00372 extern int cob_is_numeric (cob_field *); 00373 extern int cob_is_alpha (const cob_field *); 00374 extern int cob_is_upper (const cob_field *); 00375 extern int cob_is_lower (const cob_field *); 00376 00377 /* Table sort */ 00378 00379 extern void cob_table_sort_init (const int, const unsigned char *); 00380 extern void cob_table_sort_init_key (const int, cob_field *, size_t); 00381 extern void cob_table_sort (cob_field *, const int); 00382 00383 /* Run-time error checking */ 00384 00385 extern void cob_check_numeric (cob_field *, const char *); 00386 extern void cob_check_based (const unsigned char *, 00387 const char *); 00388 extern void cob_check_odo (const int, const int, 00389 const int, const char *); 00390 extern void cob_check_subscript (const int, const int, 00391 const int, const char *); 00392 extern void cob_check_ref_mod (const int, const int, 00393 const int, const char *); 00394 00395 /* Comparison functions */ 00396 extern int cob_numeric_cmp (cob_field *, cob_field *); 00397 00398 #endif /* COB_COMMON_H */