31 #include <sys/types.h>
35 #ifdef HAVE_FINITE_IEEEFP_H
44 #ifdef HAVE_SYS_TIME_H
49 #define WIN32_LEAN_AND_MEAN
67 #define COB_LIB_EXPIMP
74 #define CB_IMSG_SIZE 24
75 #define CB_IVAL_SIZE (80 - CB_IMSG_SIZE - 4)
78 #define CB_STRINGIFY(s) #s
79 #define CB_XSTRINGIFY(s) CB_STRINGIFY(s)
83 #define OC_C_VERSION_PRF ""
84 #define OC_C_VERSION CB_XSTRINGIFY(__VERSION__)
85 #elif defined(__xlc__)
86 #define OC_C_VERSION_PRF "(IBM) "
87 #define OC_C_VERSION CB_XSTRINGIFY(__xlc__)
88 #elif defined(_MSC_VER)
89 #define OC_C_VERSION_PRF "(Microsoft) "
90 #define OC_C_VERSION CB_XSTRINGIFY(_MSC_VER)
91 #elif defined(__BORLANDC__)
92 #define OC_C_VERSION_PRF "(Borland) "
93 #define OC_C_VERSION CB_XSTRINGIFY(__BORLANDC__)
94 #elif defined(__WATCOMC__)
95 #define OC_C_VERSION_PRF "(Watcom) "
96 #define OC_C_VERSION CB_XSTRINGIFY(__WATCOMC__)
97 #elif defined(__INTEL_COMPILER)
98 #define OC_C_VERSION_PRF "(Intel) "
99 #define OC_C_VERSION CB_XSTRINGIFY(__INTEL_COMPILER)
101 #define OC_C_VERSION_PRF ""
102 #define OC_C_VERSION "unknown"
120 #define COB_ERRBUF_SIZE 1024
167 #if defined(HAVE_SIGNAL_H) && defined(HAVE_SIG_ATOMIC_T)
168 static volatile sig_atomic_t sig_is_handled = 0;
174 #if defined(_MSC_VER) && COB_USE_VC2008_OR_GREATER
175 static VOID (WINAPI *time_as_filetime_func) (LPFILETIME) =
NULL;
179 #define COB_EXCEPTION(code,tag,name,critical) name,
187 #define COB_EXCEPTION(code,tag,name,critical) 0x##code,
196 #define EXCEPTION_TAB_SIZE sizeof(cob_exception_tab_code) / sizeof(int)
199 #define COB_SWITCH_MAX 36
215 static const char *
setting_group[] = {
" hidden setting ",
"Call environment",
216 "File I/O",
"Screen I/O",
"Miscellaneous",
217 "System environment"};
259 #if !defined(_WIN32) || defined (__MINGW32__)
261 #if defined(__linux__) || defined(__CYGWIN__) || defined(__MINGW32__)
266 #if defined(_WIN32) && !defined(__MINGW32__)
283 #define NUM_CONFIG (sizeof(gc_conf)/sizeof(struct config_tbl)-1)
284 #define FUNC_NAME_IN_DEFAULT NUM_CONFIG + 1
303 #ifdef HAVE_SETLOCALE
345 for (p = basext; p;) {
358 for (x = cob_alloc_base; x;) {
388 if ((gc_conf[i].data_type &
ENV_STR)
389 || (gc_conf[i].data_type &
ENV_PATH)) {
390 data = (
void*)((
char *)cobsetptr + gc_conf[i].
data_loc);
391 memcpy(&str,data,
sizeof(
char *));
395 memcpy(data,&str,
sizeof(
char *));
431 cob_sig_handler_ex (
int sig)
435 (*cob_ext_sighdl) (sig);
439 if (sig == SIGSEGV) {
453 cob_sig_handler (
int sig)
455 const char *signal_name;
457 #if defined(HAVE_SIGACTION) && !defined(SA_RESETHAND)
461 #ifdef HAVE_SIG_ATOMIC_T
462 if (sig_is_handled) {
463 cob_sig_handler_ex(sig);
471 signal_name =
"SIGINT";
476 signal_name =
"SIGHUP";
481 signal_name =
"SIGQUIT";
486 signal_name =
"SIGTERM";
491 signal_name =
"SIGPIPE";
496 signal_name =
"SIGSEGV";
500 signal_name =
"unkown";
501 fprintf(stderr,
"Caught wrong signal: %d\n", sig);
505 #ifdef HAVE_SIGACTION
507 memset (&sa, 0,
sizeof(sa));
508 sa.sa_handler = SIG_DFL;
509 (void)sigemptyset (&sa.sa_mask);
510 (void)sigaction (sig, &sa,
NULL);
513 (void)signal (sig, SIG_DFL);
525 if (sig == SIGSEGV) {
526 fprintf (stderr,
_(
"Attempt to reference unallocated memory"));
528 fprintf (stderr,
_(
"Caught Signal"));
531 fprintf (stderr,
_(
"Caught Signal"));
533 fprintf (stderr,
" (");
534 fprintf (stderr,
_(
"Signal %s"), signal_name);
535 fprintf (stderr,
")\n");
539 fprintf (stderr,
_(
"Abnormal termination - File contents may be incorrect"));
544 cob_sig_handler_ex(sig);
553 #ifdef HAVE_SIGACTION
555 struct sigaction osa;
557 memset (&sa, 0,
sizeof(sa));
558 sa.sa_handler = cob_sig_handler;
560 sa.sa_flags = SA_RESETHAND;
565 sa.sa_flags |= SA_NOCLDSTOP;
569 (void)sigaction (SIGINT,
NULL, &osa);
570 if (osa.sa_handler != SIG_IGN) {
571 (void)sigemptyset (&sa.sa_mask);
572 (void)sigaction (SIGINT, &sa,
NULL);
576 (void)sigaction (SIGHUP,
NULL, &osa);
577 if (osa.sa_handler != SIG_IGN) {
578 (void)sigemptyset (&sa.sa_mask);
579 (void)sigaction (SIGHUP, &sa,
NULL);
583 (void)sigaction (SIGQUIT,
NULL, &osa);
584 if (osa.sa_handler != SIG_IGN) {
585 (void)sigemptyset (&sa.sa_mask);
586 (void)sigaction (SIGQUIT, &sa,
NULL);
590 (void)sigaction (SIGTERM,
NULL, &osa);
591 if (osa.sa_handler != SIG_IGN) {
592 (void)sigemptyset (&sa.sa_mask);
593 (void)sigaction (SIGTERM, &sa,
NULL);
597 (void)sigaction (SIGPIPE,
NULL, &osa);
598 if (osa.sa_handler != SIG_IGN) {
599 (void)sigemptyset (&sa.sa_mask);
600 (void)sigaction (SIGPIPE, &sa,
NULL);
605 (void)sigemptyset (&sa.sa_mask);
606 (void)sigaction (SIGSEGV, &sa,
NULL);
612 if (signal (SIGINT, SIG_IGN) != SIG_IGN) {
613 (void)signal (SIGINT, cob_sig_handler);
617 if (signal (SIGHUP, SIG_IGN) != SIG_IGN) {
618 (void)signal (SIGHUP, cob_sig_handler);
622 if (signal (SIGQUIT, SIG_IGN) != SIG_IGN) {
623 (void)signal (SIGQUIT, cob_sig_handler);
627 if (signal (SIGTERM, SIG_IGN) != SIG_IGN) {
628 (void)signal (SIGTERM, cob_sig_handler);
632 if (signal (SIGPIPE, SIG_IGN) != SIG_IGN) {
633 (void)signal (SIGPIPE, cob_sig_handler);
638 (void)signal (SIGSEGV, cob_sig_handler);
653 #ifdef COB_EBCDIC_MACHINE
656 *p = (
unsigned char)
'0';
659 *p = (
unsigned char)
'1';
662 *p = (
unsigned char)
'2';
665 *p = (
unsigned char)
'3';
668 *p = (
unsigned char)
'4';
671 *p = (
unsigned char)
'5';
674 *p = (
unsigned char)
'6';
677 *p = (
unsigned char)
'7';
680 *p = (
unsigned char)
'8';
683 *p = (
unsigned char)
'9';
686 *p = (
unsigned char)
'0';
689 if (*p >= (
unsigned char)
'p' && *p <= (
unsigned char)
'y') {
693 *p = (
unsigned char)
'0';
701 #ifdef COB_EBCDIC_MACHINE
704 *p = (
unsigned char)
'p';
707 *p = (
unsigned char)
'q';
710 *p = (
unsigned char)
'r';
713 *p = (
unsigned char)
's';
716 *p = (
unsigned char)
't';
719 *p = (
unsigned char)
'u';
722 *p = (
unsigned char)
'v';
725 *p = (
unsigned char)
'w';
728 *p = (
unsigned char)
'x';
731 *p = (
unsigned char)
'y';
734 *p = (
unsigned char)
'0';
751 *p = (
unsigned char)
'0';
754 *p = (
unsigned char)
'1';
757 *p = (
unsigned char)
'2';
760 *p = (
unsigned char)
'3';
763 *p = (
unsigned char)
'4';
766 *p = (
unsigned char)
'5';
769 *p = (
unsigned char)
'6';
772 *p = (
unsigned char)
'7';
775 *p = (
unsigned char)
'8';
778 *p = (
unsigned char)
'9';
781 *p = (
unsigned char)
'0';
784 *p = (
unsigned char)
'1';
787 *p = (
unsigned char)
'2';
790 *p = (
unsigned char)
'3';
793 *p = (
unsigned char)
'4';
796 *p = (
unsigned char)
'5';
799 *p = (
unsigned char)
'6';
802 *p = (
unsigned char)
'7';
805 *p = (
unsigned char)
'8';
808 *p = (
unsigned char)
'9';
812 *p = (
unsigned char)(
'0' + (*p & 0x0F));
813 if (*p > (
unsigned char)
'9') {
814 *p = (
unsigned char)
'0';
826 *p = (
unsigned char)
'}';
829 *p = (
unsigned char)
'J';
832 *p = (
unsigned char)
'K';
835 *p = (
unsigned char)
'L';
838 *p = (
unsigned char)
'M';
841 *p = (
unsigned char)
'N';
844 *p = (
unsigned char)
'O';
847 *p = (
unsigned char)
'P';
850 *p = (
unsigned char)
'Q';
853 *p = (
unsigned char)
'R';
857 *p = (
unsigned char)
'{';
863 *p = (
unsigned char)
'{';
866 *p = (
unsigned char)
'A';
869 *p = (
unsigned char)
'B';
872 *p = (
unsigned char)
'C';
875 *p = (
unsigned char)
'D';
878 *p = (
unsigned char)
'E';
881 *p = (
unsigned char)
'F';
884 *p = (
unsigned char)
'G';
887 *p = (
unsigned char)
'H';
890 *p = (
unsigned char)
'I';
894 *p = (
unsigned char)
'{';
901 const size_t size,
const unsigned char *col)
907 for (i = 0; i < size; ++i) {
908 if ((ret = col[s1[i]] - col[c]) != 0) {
913 for (i = 0; i < size; ++i) {
914 if ((ret = s1[i] - c) != 0) {
924 const size_t size,
const unsigned char *col)
930 for (i = 0; i < size; ++i) {
931 if ((ret = col[s1[i]] - col[s2[i]]) != 0) {
936 for (i = 0; i < size; ++i) {
937 if ((ret = s1[i] - s2[i]) != 0) {
949 const unsigned char *s;
963 while (size >= f2->
size) {
984 const unsigned char *s;
1026 f1 = f2 = *sort_keys[i].
field;
1027 f1.
data = (
unsigned char *)data1 + sort_keys[i].offset;
1028 f2.
data = (
unsigned char *)data2 + sort_keys[i].offset;
1076 if (strlen(s) == 1 && (*s ==
'Y' || *s ==
'y' || *s ==
'1'))
return 1;
1077 if (strcasecmp(s,
"YES") == 0 || strcasecmp(s,
"ON") == 0 ||
1078 strcasecmp(s,
"TRUE") == 0) {
1089 if (strlen(s) == 1 && (*s ==
'N' || *s ==
'n' || *s ==
'0'))
return 1;
1090 if (strcasecmp(s,
"NO") == 0 || strcasecmp(s,
"NONE") == 0 ||
1091 strcasecmp(s,
"OFF") == 0 || strcasecmp(s,
"FALSE") == 0) {
1102 char *env, *sv_src_file;
1109 if(gc_conf[i].env_name
1110 && (env = getenv(gc_conf[i].env_name)) !=
NULL) {
1119 (void)unsetenv(gc_conf[i].env_name);
1121 env =
cob_malloc(strlen(gc_conf[i].env_name)+2);
1122 sprintf(env,
"%s=",gc_conf[i].env_name);
1126 if(gc_conf[i].env_group ==
GRP_HIDE) {
1129 && gc_conf[i].data_loc == gc_conf[j].data_loc) {
1149 return ((zero_indexed_from_sunday + 6) % 7) + 1;
1159 #if defined(_MSC_VER) && COB_USE_VC2008_OR_GREATER
1161 set_cob_time_ns_from_filetime (
const FILETIME filetime,
struct cob_time *cb_time)
1163 ULONGLONG filetime_int;
1165 filetime_int = (((ULONGLONG) filetime.dwHighDateTime) << 32)
1166 + filetime.dwLowDateTime;
1168 cb_time->
nanosecond = (filetime_int % (ULONGLONG) 10000000) * 100;
1173 #if defined (_WIN32) && !defined (__CYGWIN__)
1175 set_cob_time_offset (
struct cob_time *cb_time)
1177 DWORD time_zone_result;
1178 TIME_ZONE_INFORMATION time_zone_info;
1180 time_zone_result = GetTimeZoneInformation (&time_zone_info);
1181 if (time_zone_result != TIME_ZONE_ID_INVALID) {
1254 mptr = calloc ((
size_t)1, size);
1271 return realloc (optr, nsize);
1274 mptr = calloc ((
size_t)1, nsize);
1278 memcpy (mptr, optr, osize);
1300 mptr = malloc (size);
1315 memcpy (mptr, p, len);
1331 cob_alloc_base = cache_ptr;
1345 for (; cache_ptr; cache_ptr = cache_ptr->
next) {
1347 if (size <= cache_ptr->size) {
1372 for (; cache_ptr; cache_ptr = cache_ptr->
next) {
1375 if (cache_ptr == cob_alloc_base) {
1376 cob_alloc_base = cache_ptr->
next;
1383 prev_ptr = cache_ptr;
1389 const char *csect,
const char *cpara,
1390 const char *cstatement)
1420 "Program-Id: %-16s Statement: %-21.21s Line: %u\n",
1421 s, cstatement ? (
char *)cstatement :
"Unknown",
1478 memcpy (&tmptr, srcptr,
sizeof (
void *));
1487 memcpy (&tmptr, srcptr,
sizeof (
void *));
1504 if (f->
data[i] && f->
data[i] != (
unsigned char)
' ') {
1513 if (count > maxsize) {
1516 s = (
unsigned char *)str;
1517 for (i = 0; i < count; ++i) {
1564 vsprintf (p, fmt, ap);
1572 h->
proc ((
char *)
_(
"Malloc error"));
1588 fputs (
"libcob: ", stderr);
1592 vfprintf (stderr, fmt, ap);
1596 putc (
'\n', stderr);
1604 unsigned char *file_status;
1608 switch (fatal_error) {
1650 msg =
_(
"End of file");
1653 msg =
_(
"Key out of range");
1656 msg =
_(
"Key order not ascending");
1659 msg =
_(
"Record key already exists");
1662 msg =
_(
"Record key does not exist");
1665 msg =
_(
"Permanent file error");
1668 msg =
_(
"File does not exist");
1671 msg =
_(
"Permission denied");
1674 msg =
_(
"File already open");
1677 msg =
_(
"File not open");
1680 msg =
_(
"READ must be executed first");
1683 msg =
_(
"Record overflow");
1686 msg =
_(
"Failed to READ");
1689 msg =
_(
"READ/START not allowed");
1692 msg =
_(
"WRITE not allowed");
1695 msg =
_(
"DELETE/REWRITE not allowed");
1698 msg =
_(
"Record locked by another file connector");
1701 msg =
_(
"LINAGE values invalid");
1704 msg =
_(
"File sharing conflict");
1707 msg =
_(
"Runtime library is not configured for this operation");
1710 msg =
_(
"Unknown file error");
1717 msg, status, err_cause);
1733 const char *name =
NULL;
1750 fputs(
_(
"Configuration Error"), stderr);
1762 fprintf(stderr,
"%s",
_(
"environment variables"));
1763 fprintf(stderr,
": ");
1771 va_start(args, fmt);
1772 vfprintf(stderr, fmt, args);
1776 if (!finish_error) {
1797 const int auto_init)
1836 const int eparams, ...)
1844 numparams = eparams;
1854 fl->
data =
cob_malloc (
sizeof(
void *) * ((
size_t)numparams + 1U));
1866 va_start (args, eparams);
1867 for (n = 0; n < numparams; ++n) {
1911 funcname, numparms);
1920 unsigned char *
data;
1939 if (*p !=
'+' && *p !=
'-') {
2003 if(!*p || *p ==
' ') {
2026 *p =
'1' + (*p -
'A');
2037 *p =
'1' + (*p -
'J');
2081 for (i = 0, p = data; i < size; ++i, ++p) {
2099 if ((*p & 0x0F) <= 9) {
2100 *p = (*p & 0x0F) +
'0';
2111 unsigned char *
data;
2127 if (*p !=
'+' && *p !=
'-') {
2194 for (i = 0; i < size; ++i) {
2195 if (!isdigit (data[i])) {
2220 return (*p ==
'-') ? -1 : 1;
2222 if (*p >= (
unsigned char)
'0' && *p <= (
unsigned char)
'9') {
2227 *p = (
unsigned char)
'0';
2240 return ((*p & 0x0F) == 0x0D) ? -1 : 1;
2268 }
else if (sign < 0) {
2278 *p = (*p & 0xF0) | 0x0D;
2280 *p = (*p & 0xF0) | 0x0C;
2312 }
else if (flag == 1) {
2322 unsigned char buff[256];
2328 if (f2->
size == 1 && f2->
data[0] ==
'0' &&
2335 if (f1->
size == 1 && f1->
data[0] ==
'0' &&
2388 memcpy (&fval.fpf, f->
data,
sizeof(
float));
2389 return !finite ((
double)fval.fpf);
2391 memcpy (&fval.fpd, f->
data,
sizeof(
double));
2392 return !finite (fval.fpd);
2395 for (i = 0; i < f->
size - 1; ++i) {
2396 if ((f->
data[i] & 0xF0) > 0x90 ||
2397 (f->
data[i] & 0x0F) > 0x09) {
2402 if ((f->
data[i] & 0xF0) > 0x90) {
2408 if ((f->
data[i] & 0x0F) > 0x09) {
2415 sign = f->
data[i] & 0x0F;
2417 if (sign == 0x0C || sign == 0x0D) {
2424 }
else if (sign == 0x0F) {
2431 #ifdef WORDS_BIGENDIAN
2432 return (f->
data[0] & 0x78U) != 0x78U;
2434 return (f->
data[7] & 0x78U) != 0x78U;
2437 #ifdef WORDS_BIGENDIAN
2438 return (f->
data[0] & 0x78U) != 0x78U;
2440 return (f->
data[15] & 0x78U) != 0x78U;
2443 for (i = 0; i < f->
size; ++i) {
2444 if (!isdigit (f->
data[i])) {
2457 for (i = 0; i < f->
size; ++i) {
2458 if (!isalpha (f->
data[i]) && f->
data[i] != (
unsigned char)
' ') {
2470 for (i = 0; i < f->
size; ++i) {
2471 if (!isupper (f->
data[i]) && f->
data[i] != (
unsigned char)
' ') {
2483 for (i = 0; i < f->
size; ++i) {
2484 if (!islower (f->
data[i]) && f->
data[i] != (
unsigned char)
' ') {
2498 if (collating_sequence) {
2507 const unsigned int offset)
2539 switch(check_type) {
2554 unsigned char *data;
2563 for (i = 0; i < f->
size; ++i) {
2564 if (isprint (data[i])) {
2567 p += sprintf (p,
"\\%03o", data[i]);
2579 const int max,
const char *name)
2582 if (i < min || max < i) {
2591 const int max,
const char *name)
2594 if (i < min || max < i) {
2603 const int size,
const char *name)
2606 if (offset < 1 || offset > size) {
2613 if (length < 1 || offset + length - 1 > size) {
2626 for (eptr = basext; eptr; eptr = eptr->
next) {
2627 if (!strcmp (exname, eptr->
ename)) {
2628 if (exlength > eptr->
esize) {
2629 cob_runtime_error (
_(
"EXTERNAL item '%s' previously allocated with size %d, requested size is %d"),
2630 exname, eptr->
esize, exlength);
2639 eptr->
esize = exlength;
2641 strcpy (eptr->
ename, exname);
2653 return (
int) (digit -
'0');
2656 #if defined (_WIN32) && !defined (__CYGWIN__)
2660 SYSTEMTIME local_time;
2661 #if defined(_MSC_VER) && COB_USE_VC2008_OR_GREATER
2663 SYSTEMTIME utc_time;
2667 #if defined(_MSC_VER) && COB_USE_VC2008_OR_GREATER
2668 (time_as_filetime_func) (&filetime);
2670 if (!(FileTimeToSystemTime (&filetime, &utc_time) &&
2671 SystemTimeToTzSpecificLocalTime (
NULL, &utc_time, &local_time))) {
2672 GetLocalTime (&local_time);
2675 GetLocalTime (&local_time);
2678 cb_time.
year = local_time.wYear;
2679 cb_time.
month = local_time.wMonth;
2682 cb_time.
hour = local_time.wHour;
2683 cb_time.
minute = local_time.wMinute;
2684 cb_time.
second = local_time.wSecond;
2685 cb_time.
nanosecond = local_time.wMilliseconds;
2689 #if defined(_MSC_VER) && COB_USE_VC2008_OR_GREATER
2690 set_cob_time_ns_from_filetime (filetime, &cb_time);
2693 set_cob_time_offset (&cb_time);
2701 #if defined (HAVE_CLOCK_GETTIME)
2702 struct timespec time_spec;
2703 #elif defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY)
2709 #if defined(COB_STRFTIME)
2710 char iso_timezone[6] = {
'\0' };
2714 #if defined (HAVE_CLOCK_GETTIME)
2715 clock_gettime (CLOCK_REALTIME, &time_spec);
2716 curtime = time_spec.tv_sec;
2717 #elif defined (HAVE_SYS_TIME_H) && defined (HAVE_GETTIMEOFDAY)
2718 gettimeofday(&tmv,
NULL);
2719 curtime = tmv.tv_sec;
2721 curtime = time (
NULL);
2723 tmptr = localtime (&curtime);
2725 if (tmptr->tm_sec >= 60) {
2729 cb_time.
year = tmptr->tm_year + 1900;
2730 cb_time.
month = tmptr->tm_mon + 1;
2733 cb_time.
hour = tmptr->tm_hour;
2734 cb_time.
minute = tmptr->tm_min;
2735 cb_time.
second = tmptr->tm_sec;
2741 #if defined (HAVE_CLOCK_GETTIME)
2743 #elif defined (HAVE_SYS_TIME_H) && defined (HAVE_GETTIMEOFDAY)
2750 #if defined (COB_STRFTIME)
2751 strftime (iso_timezone, (
size_t) 6,
"%z", tmptr);
2753 if (iso_timezone[0] ==
'0') {
2759 cob_ctoi (iso_timezone[1]) * 60 * 10
2763 if (iso_timezone[0] ==
'-') {
2767 #elif defined (HAVE_TIMEZONE)
2787 strftime (s, (
size_t)7,
"%y%m%d", localtime (&t));
2798 strftime (s, (
size_t)9,
"%Y%m%d", localtime (&t));
2809 strftime (s, (
size_t)6,
"%y%j", localtime (&t));
2820 strftime (s, (
size_t)8,
"%Y%j", localtime (&t));
2832 tm = localtime (&t);
2833 if (tm->tm_wday == 0) {
2834 s[0] = (
unsigned char)
'7';
2836 s[0] = (
unsigned char)(tm->tm_wday +
'0');
2845 char str[9] = {
'\0' };
2848 snprintf (str, 9,
"%2.2d%2.2d%2.2d%2.2d", time.
hour, time.
minute,
2884 for (i = 1; i < (size_t)
cob_argc; ++i) {
2885 size += (strlen (
cob_argv[i]) + 1);
2886 if (size > f->
size) {
2893 for (i = 1; i < (size_t)
cob_argc; ++i) {
2895 memcpy (buff + size,
cob_argv[i], len);
2900 if (size > f->
size) {
2918 temp.
data = (
unsigned char *)&n;
2938 temp.
data = (
unsigned char *)&n;
2963 if (cob_local_env_size < f->size) {
3031 if (envname->
size == 0 || envval->
size == 0) {
3039 for (size = 0; size < strlen (buff); ++size) {
3040 if (!isalnum ((
int)buff[size])) {
3057 const char *p =
NULL;
3074 memset (data,
' ', size);
3075 if (parm <= (
size_t)
cob_argc - 1) {
3078 memcpy (data,
cob_argv[parm], len);
3080 memcpy (data,
cob_argv[parm], size);
3083 memset (data,
' ', size);
3103 mptr = malloc ((
size_t)fsize);
3109 temp.
size = (size_t)fsize;
3114 memset (mptr, 0, (
size_t)fsize);
3117 cache_ptr->
size = (size_t)fsize;
3119 cob_alloc_base = cache_ptr;
3126 *(
void **)(retptr->
data) = mptr;
3141 if (ptr1 && *ptr1) {
3143 for (; cache_ptr; cache_ptr = cache_ptr->
next) {
3146 if (cache_ptr == cob_alloc_base) {
3147 cob_alloc_base = cache_ptr->
next;
3155 prev_ptr = cache_ptr;
3160 if (ptr2 && *(
void **)ptr2) {
3161 for (; cache_ptr; cache_ptr = cache_ptr->
next) {
3164 if (cache_ptr == cob_alloc_base) {
3165 cob_alloc_base = cache_ptr->
next;
3170 *(
void **)ptr2 =
NULL;
3173 prev_ptr = cache_ptr;
3199 if (name && strchr (name,
'=')) {
3218 if ((tmpdir = getenv (
"TMPDIR")) ==
NULL) {
3221 if ((tmpdir = getenv (
"TEMP")) ==
NULL &&
3222 (tmpdir = getenv (
"TMP")) ==
NULL &&
3223 (tmpdir = getenv (
"USERPROFILE")) ==
NULL) {
3229 if ((tmpdir = getenv (
"TMP")) ==
NULL &&
3230 (tmpdir = getenv (
"TEMP")) ==
NULL) {
3232 strcpy (tmp,
"/tmp");
3237 (void)setenv(
"TMPDIR", tmpdir, 1);
3240 sprintf (put,
"TMPDIR=%s", tmpdir);
3246 tmpdir = getenv (
"TMPDIR");
3257 snprintf (filename, (
size_t)
COB_FILE_MAX,
"%s%ccob%d_%d%s",
3260 snprintf (filename, (
size_t)
COB_FILE_MAX,
"%s%ccobsort%d_%d",
3280 char ***penvp,
char **pname)
3296 if (pargc && pargv) {
3340 const unsigned char *x;
3345 memcpy (&p, &pptr,
sizeof (
void *));
3354 if (h->
proc == *p) {
3369 if (*x != 0 && *x != 2 && *x != 3) {
3385 const unsigned char *x;
3390 memcpy (&p, &pptr,
sizeof (
void *));
3399 if (h->
proc == *p) {
3442 for (; i >= 0; --i) {
3443 if (cmd[i] !=
' ' && cmd[i] != 0) {
3449 memcpy (buff, cmd, (
size_t)(i + 1));
3467 const char *name = var;
3479 if ((i == 4) && !strncmp (name,
"argc", 4)) {
3483 if ((i == 4) && !strncmp (name,
"argv", 4)) {
3487 if ((i == 5) && !strncmp (name,
"stdin", 5)) {
3488 *((FILE **)data) = stdin;
3491 if ((i == 6) && !strncmp (name,
"stdout", 6)) {
3492 *((FILE **)data) = stdout;
3495 if ((i == 6) && !strncmp (name,
"stderr", 6)) {
3496 *((FILE **)data) = stderr;
3499 if ((i == 5) && !strncmp (name,
"errno", 5)) {
3500 *((
int **)data) = &errno;
3503 #if defined(HAVE_TIMEZONE)
3504 if ((i == 6) && !strncmp (name,
"tzname", 6)) {
3505 *((
char ***)data) = tzname;
3508 if ((i == 8) && !strncmp (name,
"timezone", 8)) {
3509 *((
long *)data) = timezone;
3512 if ((i == 8) && !strncmp (name,
"daylight", 8)) {
3513 *((
int *)data) = daylight;
3533 for (n = 0; n < (size_t)length; ++n) {
3534 data_2[n] &= data_1[n];
3551 for (n = 0; n < (size_t)length; ++n) {
3552 data_2[n] |= data_1[n];
3569 for (n = 0; n < (size_t)length; ++n) {
3570 data_2[n] = ~(data_1[n] | data_2[n]);
3587 for (n = 0; n < (size_t)length; ++n) {
3588 data_2[n] ^= data_1[n];
3605 for (n = 0; n < (size_t)length; ++n) {
3606 data_2[n] = (~data_1[n]) | data_2[n];
3623 for (n = 0; n < (size_t)length; ++n) {
3624 data_2[n] = data_1[n] & (~data_2[n]);
3641 for (n = 0; n < (size_t)length; ++n) {
3642 data_2[n] = ~(data_1[n] ^ data_2[n]);
3658 for (n = 0; n < (size_t)length; ++n) {
3659 data_1[n] = ~data_1[n];
3674 for (n = 0; n < 8; ++n) {
3675 *data_1 |= (data_2[n] & 1) << (7 - n);
3689 for (n = 0; n < 8; ++n) {
3690 data_2[n] = (*data_1 & (1 << (7 - n))) ? 1 : 0;
3708 for (i = 0; i < 8; ++i, ++p) {
3711 }
else if (*p == 1) {
3720 for (i = 0; i < 8; ++i, ++p) {
3746 for (n = 0; n < (size_t)length; ++n) {
3747 if (islower (data[n])) {
3748 data[n] = (
cob_u8_t)toupper (data[n]);
3764 for (n = 0; n < (size_t)length; ++n) {
3765 if (isupper (data[n])) {
3766 data[n] = (
cob_u8_t)tolower (data[n]);
3777 #if defined(_WIN32) || defined(__370__) || defined(__OS400__)
3779 #elif defined(HAVE_NANO_SLEEP)
3780 struct timespec tsec;
3793 msecs = (
unsigned int)(nsecs / 1000000);
3797 #elif defined(__370__) || defined(__OS400__)
3798 msecs = (
unsigned int)(nsecs / 1000000000);
3802 #elif defined(HAVE_NANO_SLEEP)
3803 tsec.tv_sec = nsecs / 1000000000;
3804 tsec.tv_nsec = nsecs % 1000000000;
3805 nanosleep (&tsec,
NULL);
3807 msecs = (
unsigned int)(nsecs / 1000000000);
3854 memset (data,
' ', size);
3877 if (n > 0 && n <= COB_MODULE_PTR->module_num_params) {
3895 size_t opt_val_size = 0;
3900 unsigned int lo_amount;
3907 struct option* longoptions;
3965 for (i = 0; i < lo_amount; i++) {
3966 j =
sizeof(l->
name) - 1;
3967 while (j >= 0 && l->
name[j] == 0x20) {
3977 longoptions = longoptions + 1;
3986 longoptions->
val = 0;
3990 longoptions -= lo_amount;
3993 temp = (
char*) &return_value;
3998 if (temp[0] ==
'?' || temp[0] ==
':' || temp[0] ==
'W'
3999 || temp[0] == -1 || temp[0] == 0) exit_status =
return_value;
4000 else exit_status = 3;
4002 for(i = 3; i > 0; i--) {
4003 if(temp[i] == 0x00) temp[i] = 0x20;
4008 memcpy (return_char, &return_value, 4);
4011 memset (opt_val, 0x00, opt_val_size);
4014 if (optlen > opt_val_size) {
4016 optlen = opt_val_size;
4041 if (n > 0 && n < 3600*24*7) {
4045 sleep ((
unsigned int)n);
4056 unsigned char *dotptr;
4059 unsigned char dotrep;
4070 va_start (args, p1);
4071 dotptr = va_arg (args,
unsigned char *);
4075 dotrep = (
unsigned char)
'.';
4077 for (n = 0; n < datalen; ++n) {
4078 if (!isprint (data[n])) {
4089 unsigned char *direction;
4109 if (data[0] !=
' ' && data[datalen - 1] !=
' ') {
4112 for (left = 0; left < datalen; ++left) {
4113 if (data[left] !=
' ') {
4117 if (left == datalen) {
4121 for (n = datalen - 1; ; --n, ++right) {
4122 if (data[n] !=
' ') {
4129 movelen = datalen - left - right;
4132 va_start (args, p1);
4133 direction = va_arg (args,
unsigned char *);
4135 if (*direction ==
'L') {
4137 }
else if (*direction ==
'C') {
4143 memmove (data, &data[left], movelen);
4144 memset (&data[movelen],
' ', datalen - movelen);
4147 centrelen = (left + right) / 2;
4148 memmove (&data[centrelen], &data[left], movelen);
4149 memset (data,
' ', centrelen);
4150 if ((left + right) % 2) {
4151 memset (&data[centrelen + movelen],
' ', centrelen + 1);
4153 memset (&data[centrelen + movelen],
' ', centrelen);
4157 memmove (&data[left + right], &data[left], movelen);
4158 memset (data,
' ', datalen - movelen);
4167 #ifdef HAVE_SETLOCALE
4173 if (locale->
size == 0) {
4184 p = setlocale (LC_COLLATE, buff);
4187 p = setlocale (LC_CTYPE, buff);
4191 p = setlocale (LC_MESSAGES, buff);
4195 p = setlocale (LC_MONETARY, buff);
4198 p = setlocale (LC_NUMERIC, buff);
4201 p = setlocale (LC_TIME, buff);
4204 p = setlocale (LC_ALL, buff);
4209 (void)setlocale (LC_NUMERIC,
"C");
4225 p = setlocale (LC_ALL,
NULL);
4240 if (!number)
return NULL;
4241 sprintf (number,
"%i", i);
4251 if (!number)
return NULL;
4255 if (i > (1024 * 1024)) {
4256 d = i / 1024.0 / 1024.0;
4257 strB = (
char*)
"MB";
4258 }
else if (i > 1024) {
4260 strB = (
char*)
"kB";
4265 sprintf (number,
"%3.2f %s", d, strB);
4273 char *temp1, *temp2;
4275 l = strlen (str1) + strlen (str2) + 1;
4297 sprintf (
strbuff,
"%s%s", temp1, temp2);
4307 if(!strarray || size <= 0 || !separator)
return NULL;
4309 result = strarray[0];
4310 for (i = 1; i < size; i++) {
4321 if (!env_val)
return NULL;
4325 strcpy(env_var, env_val);
4331 var_print (
const char *msg,
const char *val,
const char *default_val,
4332 const unsigned int format)
4345 printf(
" %s: ",
_(
"env"));
4347 printf(
"%-*.*s : ", lablen, lablen, msg);
4361 if (!val && !default_val) {
4364 }
else if (val && default_val && ((format != 2 && val[0] == 0x30) || strcmp(val, default_val) == 0)) {
4365 val =
cob_strcat((
char*) default_val, (
char*)
_(
" (default)"));
4366 }
else if (!val && default_val) {
4380 token = strtok (p,
" ");
4381 for (; token; token = strtok (
NULL,
" ")) {
4382 toklen = (int)strlen (token) + 1;
4385 if (format == 2 || format == 3)
4393 printf (
"%s%s", (n ?
" " :
""), token);
4408 unsigned int i,j,k,envlen = 1280;
4409 char *env,*str = strval;
4410 char ename[128],*penv;
4413 for (j=k=0; strval[k] != 0; k++) {
4414 if(j >= (envlen-128)) {
4418 if (strval[k] ==
'$'
4419 && strval[k+1] ==
'{') {
4421 for (i=0; strval[k] !=
'}'
4423 && strval[k] !=
':'; k++) {
4424 ename[i++] = strval[k];
4427 penv = getenv(ename);
4429 if(strval[k] ==
':') {
4431 if (strval[k] ==
'-') k++;
4432 while (strval[k] !=
'}' && strval[k] != 0) {
4433 if(j >= (envlen-50)) {
4437 env[j++] = strval[k++];
4439 }
else if(strcmp(ename,
"COB_CONFIG_DIR") == 0) {
4441 }
else if(strcmp(ename,
"COB_COPY_DIR") == 0) {
4446 if((j + strlen(penv)) > (
unsigned int)(envlen - 128)) {
4447 env =
cob_realloc(env,envlen, strlen(penv) + 256);
4448 envlen = (
unsigned int)strlen(penv) + 256;
4450 j += sprintf(&env[j],
"%s",penv);
4453 while(strval[k] !=
'}' && strval[k] != 0)
4455 if(strval[k] ==
'}')
4458 }
else if (!isspace ((
unsigned char)strval[k])) {
4459 env[j++] = strval[k];
4475 if(len ==
sizeof(
int)) {
4476 *(
int*)data = (
int)val;
4477 }
else if(len ==
sizeof(
short)) {
4478 *(
short*)data = (
short)val;
4479 }
else if(len ==
sizeof(
long)) {
4482 *(
char*)data = (
char)val;
4490 if(len ==
sizeof(
int)) {
4491 return (
long)*(
int*)data;
4492 }
else if(len ==
sizeof(
short)) {
4493 return (
long)*(
short*)data;
4494 }
else if(len ==
sizeof(
long)) {
4495 return (
long)*(
long*)data;
4497 return (
long)*(
char*)data;
4506 char *ptr =
value,*str;
4507 unsigned long numval = 0;
4508 int i,data_type,data_loc,data_len,slen;
4514 data = (
void*)((
char *)cobsetptr + data_loc);
4516 if(gc_conf[pos].enums) {
4519 if (strcasecmp(value,gc_conf[pos].enums[i].match) == 0) {
4520 ptr = value = (
char*)gc_conf[pos].enums[i].value;
4523 if ((data_type &
ENV_ENUMVAL) && strcasecmp(value,gc_conf[pos].enums[i].value) == 0) {
4530 fprintf(stderr,
_(
"should be one of the following values: %s"),
"");
4536 fprintf (stderr,
"%s", (
char*)gc_conf[pos].enums[i].match);
4537 if (data_type & ENV_ENUMVAL) {
4538 fprintf (stderr,
"(%s)", (
char*)gc_conf[pos].enums[i].value);
4541 putc (
'\n', stderr);
4549 for (; *ptr != 0 && (isdigit((
unsigned char)*ptr) || *ptr ==
' '); ptr++) {
4551 numval = (numval * 10) + (*ptr -
'0');
4554 if((data_type & ENV_SIZE)
4556 switch(toupper((
unsigned char)*ptr)) {
4558 numval = numval * 1024;
4561 if (numval < 4001) {
4562 numval = numval * 1024 * 1024;
4564 numval = 4294967295;
4569 numval = numval * 1024 * 1024 * 1024;
4571 numval = 4294967295;
4576 if(gc_conf[pos].min_value > 0
4577 && numval < gc_conf[pos].min_value) {
4582 if(gc_conf[pos].max_value > 0
4583 && numval > gc_conf[pos].max_value) {
4588 set_value((
char *)data,data_len,numval);
4590 }
else if((data_type &
ENV_BOOL)) {
4592 if(isdigit((
unsigned char)*ptr)) {
4595 if(strcasecmp(ptr,
"true") == 0
4596 || strcasecmp(ptr,
"t") == 0
4597 || strcasecmp(ptr,
"on") == 0
4598 || strcasecmp(ptr,
"yes") == 0
4599 || strcasecmp(ptr,
"y") == 0) {
4602 if(strcasecmp(ptr,
"false") == 0
4603 || strcasecmp(ptr,
"f") == 0
4604 || strcasecmp(ptr,
"off") == 0
4605 || strcasecmp(ptr,
"no") == 0
4606 || strcasecmp(ptr,
"n") == 0) {
4619 set_value((
char *)data,data_len,numval);
4622 }
else if((data_type &
ENV_STR)
4624 memcpy(&str,data,
sizeof(
char *));
4629 memcpy(data,&str,
sizeof(
char *));
4631 }
else if((data_type &
ENV_CHAR)) {
4632 memset(data,0,data_len);
4633 slen = (int)strlen(value);
4634 if (slen > data_len) {
4637 memcpy(data,value,slen);
4650 if (!strcmp(gc_conf[i].conf_name,name)) {
4671 int i,data_type,data_loc,data_len;
4677 data = (
void*)((
char *)cobsetptr + data_loc);
4679 strcpy(value,
"Unknown");
4680 strcpy(orgvalue,
"");
4682 numval =
get_value((
char *)data,data_len);
4683 sprintf(value,
"%ld",numval);
4685 }
else if((data_type &
ENV_SIZE)) {
4686 numval =
get_value((
char *)data,data_len);
4688 if(numval > (1024 * 1024 * 1024)) {
4689 if((numval % (1024 * 1024 * 1024)) == 0)
4690 sprintf(value,
"%ld GB",numval/(1024 * 1024 * 1024));
4692 sprintf(value,
"%.2f GB",dval/(1024.0 * 1024.0 * 1024.0));
4693 }
else if(numval > (1024 * 1024)) {
4694 if((numval % (1024 * 1024)) == 0)
4695 sprintf(value,
"%ld MB",numval/(1024 * 1024));
4697 sprintf(value,
"%.2f MB",dval/(1024.0 * 1024.0));
4698 }
else if(numval > 1024) {
4699 if((numval % 1024) == 0)
4700 sprintf(value,
"%ld KB",numval/1024);
4702 sprintf(value,
"%.2f KB",dval/1024.0);
4704 sprintf(value,
"%ld",numval);
4707 }
else if((data_type &
ENV_BOOL)) {
4708 numval =
get_value((
char *)data,data_len);
4712 strcpy(value,
"true");
4714 strcpy(value,
"false");
4716 }
else if((data_type &
ENV_STR)) {
4717 memcpy(&str,data,
sizeof(
char *));
4719 sprintf(value,
"%s",
"not set");
4721 sprintf(value,
"'%s'",str);
4723 }
else if((data_type &
ENV_PATH)) {
4724 memcpy(&str,data,
sizeof(
char *));
4726 sprintf(value,
"%s",
"not set");
4728 sprintf(value,
"%s",str);
4730 }
else if((data_type &
ENV_CHAR)) {
4731 if(*(
char*)data == 0) {
4732 strcpy(value,
"Nul");
4733 }
else if(isprint(*(
unsigned char*)data)) {
4734 sprintf(value,
"'%s'",(
char*)data);
4736 sprintf(value,
"0x%02X",*(
char*)data);
4740 if(gc_conf[pos].enums) {
4742 if(strcasecmp(value,gc_conf[pos].enums[i].value) == 0) {
4743 if(strcmp(value,
"0") != 0
4744 && strcmp(value,gc_conf[pos].default_val) != 0)
4745 strcpy(orgvalue,value);
4746 strcpy(value,gc_conf[pos].enums[i].match);
4759 if(gc_conf[i].conf_name
4760 && strcasecmp(keyword,gc_conf[i].conf_name) == 0) {
4763 if(gc_conf[i].env_name
4764 && strcasecmp(keyword,gc_conf[i].env_name) == 0) {
4774 int i,j,k, old_type;
4781 for (j=(
int)strlen(buf); buf[j-1] ==
'\r' || buf[j-1] ==
'\n'; )
4784 for (i=0; isspace((
unsigned char)buf[i]); i++);
4786 for (j=0; buf[i] != 0 && buf[i] !=
':' && !isspace((
unsigned char)buf[i]) && buf[i] !=
'=' && buf[i] !=
'#'; )
4787 keyword[j++] = buf[i++];
4790 while (buf[i] != 0 && ( isspace((
unsigned char)buf[i]) || buf[i] ==
':' || buf[i] ==
'=')) i++;
4792 || buf[i] ==
'\'') {
4794 for (j=0; buf[i] != qt && buf[i] != 0; )
4795 value[j++] = buf[i++];
4797 for (j=0; !isspace((
unsigned char)buf[i]) && buf[i] !=
'#' && buf[i] != 0; )
4798 value[j++] = buf[i++];
4803 if (strcasecmp (keyword,
"setenv") == 0 ) {
4807 k = 0;
while (value[k] !=
'=' && value[k] !=
':' && value[k] !=
'"' && value[k] !=
'\'' && value[k] != 0) k++;
4808 if (value[k] ==
'=' || value[k] ==
':') {
4809 i = i - (int)strlen(value + k);
4812 while(isspace((
unsigned char)buf[i]) || buf[i] ==
':' || buf[i] ==
'=') i++;
4814 || buf[i] ==
'\'') {
4816 for (j=0; buf[i] != qt && buf[i] != 0; )
4817 value2[j++] = buf[i++];
4819 for (j=0; !isspace((
unsigned char)buf[i]) && buf[i] !=
'#' && buf[i] != 0; )
4820 value2[j++] = buf[i++];
4823 if (strcmp(value2,
"") == 0) {
4829 env =
cob_malloc(strlen(value)+strlen(str)+2);
4830 sprintf(env,
"%s=%s",value,str);
4834 if(gc_conf[i].env_name
4835 && strcasecmp(value,gc_conf[i].env_name) == 0) {
4843 if (strcasecmp (keyword,
"unsetenv") == 0) {
4844 if (strcmp(value,
"") == 0) {
4848 if ( (env = getenv(value)) !=
NULL ) {
4850 if(gc_conf[i].env_name
4851 && strcasecmp(value,gc_conf[i].env_name) == 0) {
4857 (void)unsetenv(value);
4860 sprintf(env,
"%s=",value);
4868 if (strcasecmp (keyword,
"include") == 0 ||
4869 strcasecmp (keyword,
"includeif") == 0) {
4870 if (strcmp(value,
"") == 0) {
4877 if (strcasecmp (keyword,
"include") == 0) {
4884 if (strcasecmp (keyword,
"reset") == 0) {
4894 if(gc_conf[i].default_val) {
4896 }
else if ((gc_conf[i].data_type &
ENV_STR)
4897 || (gc_conf[i].data_type &
ENV_PATH)) {
4898 data = (
void*)((
char *)cobsetptr + gc_conf[i].
data_loc);
4899 memcpy(&str,data,
sizeof(
char *));
4915 if (strcmp(value,
"") == 0) {
4926 if(gc_conf[i].env_group ==
GRP_HIDE) {
4929 && gc_conf[i].data_loc == gc_conf[j].data_loc) {
4953 for (i=0; config_file[i] != 0 && config_file[i] !=
SLASH_CHAR; i++);
4954 if (config_file[i] == 0) {
4955 if (access(config_file,
F_OK) != 0) {
4960 for (i = (
int)strlen(buff); i != 0 && buff[i] !=
SLASH_CHAR; i--);
4964 if (access(filename,
F_OK) == 0) {
4965 config_file = filename;
4971 if (filename[0] == 0) {
4973 penv = getenv(
"COB_CONFIG_DIR");
4979 if (access(filename,
F_OK) == 0) {
4980 config_file = filename;
4998 conf_fd = fopen (config_file,
"r");
4999 if (conf_fd ==
NULL && !isoptional) {
5007 if (conf_fd !=
NULL) {
5022 while ( (conf_fd !=
NULL)
5025 for (i=0; isspace((
unsigned char)buff[i]); i++);
5036 if (sub_ret == 1 || sub_ret == 3) {
5047 if (sub_ret < ret) ret = sub_ret;
5067 int isoptional = 1, sts, i, j;
5071 if ((env = getenv (
"COB_RUNTIME_CONFIG")) !=
NULL && env[0]) {
5072 strcpy (conf_file, env);
5076 if ((env = getenv(
"COB_CONFIG_DIR")) !=
NULL && env[0]) {
5095 if (gc_conf[i].default_val
5100 && gc_conf[i].data_loc == gc_conf[j].data_loc)
5103 if(j < NUM_CONFIG) {
5104 if(!(gc_conf[j].data_type & STS_CNFSET)
5105 && !(gc_conf[j].data_type & STS_ENVSET)) {
5123 int status, day, year;
5127 memset (month, 0,
sizeof(month));
5130 status = sscanf (__DATE__,
"%s %d %d", month, &day, &year);
5133 "%s %2.2d %4.4d %s", month, day, year, __TIME__);
5136 "%s %s", __DATE__, __TIME__);
5139 printf (
"libcob (%s) %s.%d\n",
5141 puts (
"Copyright (C) 2001-2012, 2014-2016 Free Software Foundation, Inc.");
5142 printf (
_(
"Written by %s\n"),
"Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch");
5143 puts (
_(
"This is free software; see the source for copying conditions. There is NO\n\
5144 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."));
5145 printf (
_(
"Built %s"), cob_build_stamp);
5160 puts (
_(
"Build information"));
5171 puts (
_(
"GnuCOBOL information"));
5179 #if defined(USE_LIBDL) || defined(_WIN32)
5180 var_print (
_(
"Dynamic loading"),
_(
"System"),
"", 0);
5182 var_print (
_(
"Dynamic loading"),
_(
"Libtool"),
"", 0);
5185 #ifdef COB_PARAM_CHECK
5186 var_print (
"\"CBL_\" param check",
_(
"Enabled"),
"", 0);
5188 var_print (
"\"CBL_\" param check",
_(
"Disabled"),
"", 0);
5191 if (
sizeof (
void *) > 4U) {
5198 var_print (
"BINARY-C-LONG",
_(
"8 bytes"),
"", 0);
5200 var_print (
"BINARY-C-LONG",
_(
"4 bytes"),
"", 0);
5206 var_print (
_(
"Variable format"), buff,
"", 0);
5207 if ((s = getenv (
"COB_VARSEQ_FORMAT")) !=
NULL) {
5208 var_print (
"COB_VARSEQ_FORMAT", s,
"", 1);
5211 #ifdef WITH_SEQRA_EXTFH
5212 var_print (
_(
"Sequential handler"),
_(
"External"),
"", 0);
5214 var_print (
_(
"Sequential handler"),
_(
"Internal"),
"", 0);
5217 #if defined (WITH_INDEX_EXTFH)
5218 var_print (
_(
"ISAM handler"),
_(
"External"),
"", 0);
5219 #elif defined (WITH_DB)
5221 #elif defined (WITH_CISAM)
5222 var_print (
_(
"ISAM handler"),
"C-ISAM" "", 0);
5223 #elif defined (WITH_DISAM)
5224 var_print (
_(
"ISAM handler"),
"D-ISAM",
"", 0);
5225 #elif defined (WITH_VBISAM)
5226 var_print (
_(
"ISAM handler"),
"VBISAM",
"", 0);
5228 var_print (
_(
"ISAM handler"),
_(
"Not available"),
"", 0);
5236 unsigned int i,j,k,vl,dohdg,hdlen,plen;
5240 puts (
_(
"runtime environment"));
5242 strcpy(value,
_(
"via"));
5243 hdlen = (
unsigned int)strlen(value) + 3;
5246 printf(
" %s ", value);
5249 vl = (
unsigned int)strlen(value);
5250 for (k = 0; vl > plen; vl -= plen, k += plen) {
5251 printf(
"%.*s\n%-*s", plen, &value[k], hdlen,
"");
5253 printf(
"%s\n", &value[k]);
5257 printf(
"%*d ", hdlen - 2, i);
5259 vl = (
unsigned int)strlen(value);
5260 for (k = 0; vl > plen; vl -= plen, k += plen) {
5261 printf(
"%.*s\n%-*s", plen, &value[k], hdlen,
"");
5263 printf(
"%s\n", &value[k]);
5268 strcpy(value,
"todo");
5271 j = (
unsigned int)strlen(gc_conf[i].env_name);
5274 j = (
unsigned int)strlen(gc_conf[i].conf_name);
5282 if(gc_conf[i].env_group == j) {
5295 if (gc_conf[i].data_type & STS_FNCSET) {
5297 }
else if ((gc_conf[i].data_type &
STS_CNFSET)) {
5302 printf(
": %-*s : ",hdlen,gc_conf[i].env_name);
5303 }
else if((gc_conf[i].data_type &
STS_CNFSET)) {
5304 if (gc_conf[i].config_num > 0) {
5305 printf(
" %d ", gc_conf[i].config_num);
5309 if (gc_conf[i].set_by > 0) {
5310 printf(
": %-*s : ", hdlen, gc_conf[i].env_name);
5312 printf(
": %-*s : ", hdlen, gc_conf[i].conf_name);
5314 }
else if(gc_conf[i].env_name) {
5315 if(gc_conf[i].config_num > 0){
5316 printf(
" %d ",gc_conf[i].config_num);
5320 printf(
": %-*s : ",hdlen,gc_conf[i].env_name);
5322 printf(
" : %-*s : ",hdlen,gc_conf[i].conf_name);
5324 vl = (
unsigned int)strlen(value);
5326 for (k = 0; vl > plen; vl -= plen, k += plen) {
5327 printf(
"%.*s\n %-*s : ", plen, &value[k], hdlen,
"");
5329 printf(
"%s",&value[k]);
5330 if (orgvalue[0] >
' ') {
5331 printf(
" (%s)", orgvalue);
5333 if (gc_conf[i].set_by > 0) {
5336 printf(
_(
"(set by %s)"), gc_conf[gc_conf[i].set_by].env_name);
5338 printf(
_(
"(set by %s)"), gc_conf[i].default_val);
5341 if(!(gc_conf[i].data_type & STS_ENVSET)
5342 && !(gc_conf[i].data_type & STS_CNFSET)
5343 && !(gc_conf[i].data_type & STS_FNCSET)) {
5345 if ((gc_conf[i].data_type &
STS_RESET)) {
5346 printf(
_(
"(reset)"));
5347 }
else if (strcmp(value,
not_set) != 0) {
5348 printf(
_(
"(default)"));
5354 puts(
_(
"... removed from environment"));
5371 #ifdef HAVE_SETLOCALE
5372 printf(
" : %-*s : %s\n",hdlen,
"LC_CTYPE", (
char*) setlocale (LC_CTYPE,
NULL));
5373 printf(
" : %-*s : %s\n",hdlen,
"LC_NUMERIC", (
char*) setlocale (LC_NUMERIC,
NULL));
5374 printf(
" : %-*s : %s\n",hdlen,
"LC_COLLATE", (
char*) setlocale (LC_COLLATE,
NULL));
5376 printf(
" : %-*s : %s\n",hdlen,
"LC_MESSAGES", (
char*) setlocale (LC_MESSAGES,
NULL));
5378 printf(
" : %-*s : %s\n",hdlen,
"LC_MONETARY", (
char*) setlocale (LC_MONETARY,
NULL));
5379 printf(
" : %-*s : %s\n",hdlen,
"LC_TIME", (
char*) setlocale (LC_TIME,
NULL));
5393 #if defined(HAVE_READLINK) || defined(HAVE_GETEXECNAME)
5397 const char* localedir;
5399 #if defined(_MSC_VER) && COB_USE_VC2008_OR_GREATER
5400 HMODULE kernel32_handle;
5413 cob_alloc_base =
NULL;
5448 #ifdef HAVE_SETLOCALE
5450 s = setlocale (LC_ALL,
"");
5454 s = setlocale (LC_CTYPE,
NULL);
5458 s = setlocale (LC_COLLATE,
NULL);
5463 s = setlocale (LC_MESSAGES,
NULL);
5468 s = setlocale (LC_MONETARY,
NULL);
5472 s = setlocale (LC_NUMERIC,
NULL);
5476 s = setlocale (LC_TIME,
NULL);
5481 setlocale (LC_NUMERIC,
"C");
5482 setlocale (LC_CTYPE,
"C");
5484 s = setlocale (LC_ALL,
NULL);
5492 localedir = getenv(
"LOCALEDIR");
5493 if (localedir !=
NULL) {
5504 if ((s = getenv(
"COB_UNIX_LF")) !=
NULL) {
5508 (void)_setmode (_fileno (stdin), _O_BINARY);
5509 (void)_setmode (_fileno (stdout), _O_BINARY);
5510 (void)_setmode (_fileno (stderr), _O_BINARY);
5540 if (s && (*s ==
'1' || strcasecmp (s,
"ON") == 0)) {
5549 #if defined (_WIN32) && (!defined(_MSC_VER) || COB_USE_VC2008_OR_GREATER)
5554 #elif !defined(__OS400__)
5562 #if defined(_MSC_VER) && COB_USE_VC2008_OR_GREATER
5564 kernel32_handle = GetModuleHandle (TEXT (
"kernel32.dll"));
5565 if (kernel32_handle !=
NULL) {
5566 time_as_filetime_func = (VOID (WINAPI *) (LPFILETIME))
5567 GetProcAddress (kernel32_handle,
"GetSystemTimePreciseAsFileTime");
5569 if (time_as_filetime_func ==
NULL) {
5570 time_as_filetime_func = GetSystemTimeAsFileTime;
5580 if (i > 0 && i < COB_LARGE_BUFF) {
5586 #elif defined(HAVE_READLINK)
5588 if (!access (
"/proc/self/exe",
R_OK)) {
5589 path =
"/proc/self/exe";
5590 }
else if (!access (
"/proc/curproc/file",
R_OK)) {
5591 path =
"/proc/curproc/file";
5592 }
else if (!access (
"/proc/self/path/a.out",
R_OK)) {
5593 path =
"/proc/self/path/a.out";
5598 if (i > 0 && i < COB_LARGE_BUFF) {
5607 #ifdef HAVE_GETEXECNAME
5608 path = getexecname ();
5610 #ifdef HAVE_REALPATH
5612 if (realpath (path, s) !=
NULL) {
5625 if (argc && argv && argv[0]) {
5629 #elif defined(HAVE_CANONICALIZE_FILE_NAME)
5632 #elif defined(HAVE_REALPATH)
5634 if (realpath (argv[0], s) !=
NULL) {
int cob_sys_toupper(void *p1, const int length)
struct cob_time cob_get_current_date_and_time(void)
#define COB_STATUS_42_NOT_OPEN
void cob_accept_time(cob_field *field)
char * cob_locale_monetary
static void cob_memcpy(cob_field *dst, const void *src, const size_t size)
void cob_free(void *mptr)
struct exit_handlerlist * next
static FILE * cob_trace_file
static void cob_put_sign_ebcdic(unsigned char *p, const int sign)
static struct cob_alloc_cache * cob_alloc_base
int cob_sys_justify(void *p1,...)
#define COB_STATUS_10_END_OF_FILE
unsigned int cob_orig_line
static struct cob_external * basext
int cob_is_omitted(const cob_field *f)
#define COB_STATUS_41_ALREADY_OPEN
void cob_init_numeric(cob_global *)
#define COB_FERROR_CODEGEN
char return_value_pointer[sizeof(char *)]
static int common_cmps(const unsigned char *s1, const unsigned char *s2, const size_t size, const unsigned char *col)
static char * get_config_val(char *value, int pos, char *orgvalue)
void cob_accept_day_of_week(cob_field *f)
char * cob_locale_numeric
cob_file * cob_error_file
void cob_set_environment(const cob_field *f1, const cob_field *f2)
void cob_correct_numeric(cob_field *f)
static cob_file_key * sort_keys
#define COB_FIELD_IS_NUMDISP(f)
int cob_sys_xor(const void *p1, void *p2, const int length)
static int common_cmpc(const unsigned char *s1, const unsigned int c, const size_t size, const unsigned char *col)
int cob_getopt_long_long(const int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, const int long_only)
static void set_value(char *data, int len, long val)
void cob_allocate(unsigned char **dataptr, cob_field *retptr, cob_field *sizefld, cob_field *initialize)
void cob_check_version(const char *prog, const char *packver, const int patchlev)
void cob_accept_user_name(cob_field *f)
int cob_sys_xf5(const void *p1, void *p2)
static const char * cob_gettmpdir(void)
static struct config_enum beepopts[]
void * cob_command_line(int flags, int *pargc, char ***pargv, char ***penvp, char **pname)
#define COB_TYPE_NUMERIC_PACKED
static int cb_lookup_config(char *keyword)
void cob_exit_fileio(void)
int cob_sys_system(const void *cmdline)
#define COB_STATUS_14_OUT_OF_KEY_RANGE
#define COB_FIELD_IS_NUMERIC(f)
#define COB_STATUS_23_KEY_NOT_EXISTS
void cob_move(cob_field *, cob_field *)
static cob_module * module
#define COB_TYPE_ALPHANUMERIC
const char * cob_get_exception_name(void)
#define COB_CHK_PARMS(x, z)
void cob_init_intrinsic(cob_global *)
#define COB_STATUS_61_FILE_SHARING
void cob_display_environment(const cob_field *f)
void cob_set_switch(const int n, const int flag)
int cob_sys_getopt_long_long(void *so, void *lo, void *idx, const int long_only, void *return_char, void *opt_val)
void cob_chain_setup(void *data, const size_t parm, const size_t size)
#define COB_FIELD_TYPE(f)
static int cob_get_sign_ascii(unsigned char *p)
void cob_accept_day(cob_field *f)
static int cob_check_numdisp(const cob_field *f)
static void var_print(const char *msg, const char *val, const char *default_val, const unsigned int format)
#define COB_FERROR_CANCEL
void cob_check_linkage(const unsigned char *x, const char *name, const int check_type)
static struct exit_handlerlist * exit_hdlrs
#define COB_STATUS_35_NOT_EXISTS
void cob_cache_free(void *ptr)
void cob_restore_func(struct cob_func_loc *fl)
static struct config_enum syncopts[]
int cob_real_get_sign(cob_field *f)
struct cob_external * next
void * cob_get_prog_pointer(const void *srcptr)
#define COB_FERROR_FUNCTION
void cob_check_ref_mod(const int offset, const int length, const int size, const char *name)
void cob_check_based(const unsigned char *x, const char *name)
#define bindtextdomain(Domainname, Dirname)
int cob_is_lower(const cob_field *f)
void conf_runtime_error(const int finish_error, const char *fmt,...)
const char * cob_orig_paragraph
void cob_get_environment(const cob_field *envname, cob_field *envval)
static unsigned int cob_source_line
#define COB_ATTR_INIT(u, v, x, y, z)
#define COB_FERROR_RECURSIVE
static cob_field * numval(cob_field *srcfield, cob_field *currency, const enum numval_type type)
void cob_accept_arg_number(cob_field *f)
void cob_table_sort(cob_field *f, const int n)
void cob_real_put_sign(cob_field *f, const int sign)
static cob_settings * cobsetptr
void cob_accept_day_yyyyddd(cob_field *f)
void cob_check_numeric(const cob_field *f, const char *name)
static const char * last_runtime_error_file
static int cob_process_id
void cob_display_arg_number(cob_field *f)
int cob_get_switch(const int n)
#define COB_STATUS_44_RECORD_OVERFLOW
void * cob_save_func(cob_field **savefld, const int params, const int eparams,...)
static unsigned char * commlnptr
unsigned char * file_status
char * cob_strjoin(char **strarray, int size, char *separator)
#define COB_FLAG_HAVE_SIGN
#define COB_FERROR_GLOBAL
void cob_init_fileio(cob_global *, cob_settings *)
static struct config_tbl gc_conf[]
#define COB_FIELD_SIGN_SEPARATE(f)
#define textdomain(Domainname)
void cob_accept_arg_value(cob_field *f)
#define COB_STATUS_22_KEY_EXISTS
int cob_get_int(cob_field *)
static const char * cob_last_sfile
int cob_check_env_true(char *s)
#define COB_FERROR_MODULE
int cob_putenv(char *name)
void * cob_realloc(void *optr, const size_t osize, const size_t nsize)
char * cob_int_to_formatted_bytestring(int i, char *number)
void cob_parameter_check(const char *funcname, const int numparms)
static const char *const cob_exception_tab_name[]
int cob_sys_xf4(void *p1, const void *p2)
#define COB_TYPE_NUMERIC_FP_DEC64
void cob_accept_date_yyyymmdd(cob_field *f)
#define COB_FIELD_NO_SIGN_NIBBLE(f)
strict implicit external value
void cob_fatal_error(const int fatal_error)
void cob_module_leave(cob_module *module)
static void cob_rescan_env_vals(void)
int cob_cmp_int(cob_field *, const int)
int cob_sys_eq(const void *p1, void *p2, const int length)
unsigned int cob_physical_cancel
static struct handlerlist * hdlrs
static void(* cob_ext_sighdl)(int)
unsigned char * cob_term_buff
int cob_numeric_cmp(cob_field *, cob_field *)
#define EXCEPTION_TAB_SIZE
struct cob_alloc_cache * next
#define COB_STATUS_46_READ_ERROR
#define COB_TYPE_NUMERIC_FLOAT
void cob_set_location(const char *sfile, const unsigned int sline, const char *csect, const char *cpara, const char *cstatement)
unsigned char * cob_get_pointer(const void *srcptr)
int cob_sys_sleep(const void *data)
void cob_accept_date(cob_field *f)
char * cob_getenv(const char *name)
char * cob_int_to_string(int i, char *number)
void cob_display_command_line(cob_field *f)
struct handlerlist * next
void cob_accept_environment(cob_field *f)
static struct config_enum varseqopts[]
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
char * cob_locale_collate
void cob_init(const int argc, char **argv)
int cob_check_env_false(char *s)
int cob_sys_or(const void *p1, void *p2, const int length)
int cob_sys_error_proc(const void *dispo, const void *pptr)
#define COB_STATUS_48_OUTPUT_DENIED
int cob_is_upper(const cob_field *f)
#define COB_STATUS_30_PERMANENT_ERROR
int cob_sys_not(void *p1, const int length)
int cob_sys_nor(const void *p1, void *p2, const int length)
static size_t cob_local_env_size
static struct config_enum lwrupr[]
static void cob_exit_common(void)
void cob_accept_command_line(cob_field *f)
#define COB_TYPE_NUMERIC_BINARY
static int set_config_val_by_name(char *value, const char *name, const char *func)
void cob_set_exception(const int id)
#define COB_FERROR_CHAINING
unsigned int cob_line_trace
int cob_sys_and(const void *p1, void *p2, const int length)
int cob_load_config(void)
static int cb_config_entry(char *buf, int line)
int cob_is_alpha(const cob_field *f)
void cob_init_strings(void)
static char varseq_dflt[8]
#define COB_TYPE_NUMERIC_DISPLAY
int cob_sys_exit_proc(const void *dispo, const void *pptr)
void cob_ready_trace(void)
static const char * cob_current_paragraph
void cob_set_int(cob_field *, const int)
#define COB_PUT_SIGN(f, s)
int cob_sys_nimp(const void *p1, void *p2, const int length)
static long get_value(char *data, int len)
#define COB_TYPE_ALPHANUMERIC_ALL
int cob_sys_printable(void *p1,...)
void cob_table_sort_init_key(cob_field *field, const int flag, const unsigned int offset)
int cob_cmp(cob_field *f1, cob_field *f2)
static int set_config_val(char *value, int pos)
const char * cob_orig_section
#define COB_STATUS_21_KEY_INVALID
#define COB_STATUS_43_READ_NOT_DONE
void cob_check_odo(const int i, const int min, const int max, const char *name)
void cob_init_move(cob_global *, cob_settings *)
#define FUNC_NAME_IN_DEFAULT
const char * cob_orig_statement
unsigned int cob_got_exception
static int cob_get_sign_ebcdic(unsigned char *p)
void cob_field_to_string(const cob_field *f, void *str, const size_t maxsize)
unsigned int cob_screen_initialized
static int cob_temp_iteration
#define COB_STATUS_49_I_O_DENIED
char * cob_expand_env_string(char *strval)
void cob_init_screenio(cob_global *, cob_settings *)
void cob_exit_screen(void)
void cob_set_locale(cob_field *locale, const int category)
#define COB_FERROR_INITIALIZED
#define COB_STATUS_57_I_O_LINAGE
#define COB_STATUS_51_RECORD_LOCKED
if fold fold static computed alternate extra correct stack on syntax debugging line
#define COB_TYPE_NUMERIC_DOUBLE
static const char * cob_current_program_id
static int one_indexed_day_of_week_from_monday(int zero_indexed_from_sunday)
const char * cob_main_argv0
int cob_extern_init(void)
void cob_incr_temp_iteration(void)
void cob_module_enter(cob_module **module, cob_global **mglobal, const int auto_init)
void cob_display_env_value(const cob_field *f)
int cob_sys_oc_nanosleep(const void *data)
static int cob_load_config_file(const char *config_file, int isoptional)
void cob_screen_set_mode(const cob_u32_t)
static const char * cob_source_file
const cob_field_attr * attr
void cob_exit_numeric(void)
void cob_check_subscript(const int i, const int min, const int max, const char *name)
char * cob_strcat(char *str1, char *str2)
int cob_sys_hosted(void *p, const void *var)
Return some hosted C variables, argc, argv, stdin, stdout, stderr.
int cob_get_exception_code(void)
static int cob_initialized
cob_field ** save_proc_parms
#define COB_STATUS_47_INPUT_DENIED
unsigned int cob_extended_status
void cob_init_termio(cob_global *, cob_settings *)
void cob_exit_intrinsic(void)
void cob_accept_exception_status(cob_field *f)
static int cob_cmp_alnum(cob_field *f1, cob_field *f2)
static const char * cob_source_statement
void * cob_malloc(const size_t size)
void cob_table_sort_init(const size_t nkeys, const unsigned char *collating_sequence)
char * cob_locale_messages
static void cob_put_sign_ascii(unsigned char *p)
static int sort_compare(const void *data1, const void *data2)
const char * cob_orig_program_id
char * cob_save_env_value(char *env_var, char *env_val)
unsigned int cob_env_mangle
#define COB_FIELD_HAVE_SIGN(f)
void cob_exit_strings(void)
int cob_ctoi(const char digit)
static unsigned int conf_runtime_error_displayed
void * cob_fast_malloc(const size_t size)
static int cob_cmp_all(cob_field *f1, cob_field *f2)
static cob_global * cobglobptr
static char * cob_local_env
int cob_sys_imp(const void *p1, void *p2, const int length)
void cob_reg_sighnd(void(*sighnd)(int))
static void cob_set_signal(void)
static void set_unknown_offset(struct cob_time *time)
static const char * cob_current_section
int cob_sys_tolower(void *p1, const int length)
void cob_reset_trace(void)
#define COB_TYPE_NUMERIC_FP_DEC128
unsigned int cob_config_num
int cob_sys_return_args(void *data)
static struct config_enum timeopts[]
void conf_runtime_error_value(char *value, const int conf_pos)
struct config_enum * enums
static void cob_check_trace_file(void)
int cob_sys_parameter_size(void *data)
#define COB_FIELD_DIGITS(f)
char * cob_trace_filename
void cob_free_alloc(unsigned char **ptr1, unsigned char *ptr2)
static const int cob_exception_tab_code[]
#define COB_STATUS_91_NOT_AVAILABLE
cob_settings * cob_get_settings_ptr()
static void cob_terminate_routines(void)
void cob_trace_section(const char *para, const char *source, const int line)
static int cob_switch[36+1]
static const char * setting_group[]
#define COB_STATUS_37_PERMISSION_DENIED
strict implicit external call params
void cob_init_call(cob_global *lptr, cob_settings *sptr)
static unsigned int last_runtime_error_line
int cob_sys_x91(void *p1, const void *p2, void *p3)
static const unsigned char * sort_collate
#define COB_FERROR_MEMORY
void cob_runtime_error(const char *fmt,...)
static char * runtime_err_str
cob_global * cob_get_global_ptr(void)
unsigned int cob_physical_cancel
#define COB_FIELD_SIGN_LEADING(f)
void * cob_cache_realloc(void *ptr, const size_t size)
void * cob_external_addr(const char *exname, const int exlength)
void * cob_cache_malloc(const size_t size)
int cob_sys_calledby(void *data)
void cob_temp_name(char *filename, const char *ext)
long long cob_get_llint(cob_field *)
static const cob_field_attr const_alpha_attr
void cob_stop_run(const int status)
char * cob_strdup(const char *p)
int cob_is_numeric(const cob_field *f)
unsigned int cob_config_cur