aboutsummaryrefslogtreecommitdiff
path: root/libgcobol/intrinsic.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libgcobol/intrinsic.cc')
-rw-r--r--libgcobol/intrinsic.cc59
1 files changed, 41 insertions, 18 deletions
diff --git a/libgcobol/intrinsic.cc b/libgcobol/intrinsic.cc
index e3d255a..4bce481 100644
--- a/libgcobol/intrinsic.cc
+++ b/libgcobol/intrinsic.cc
@@ -44,6 +44,8 @@
#include <langinfo.h>
#include <string.h>
+#include "config.h"
+
#include "ec.h"
#include "common-defs.h"
#include "io.h"
@@ -99,7 +101,7 @@ is_zulu_format(PCHAR left, PCHAR &right)
bool retval = false;
if( right > left )
{
- retval = toupper(*(right-1)) == internal_Z;
+ retval = std::toupper((unsigned char)*(right-1)) == internal_Z;
}
return retval;
}
@@ -1984,7 +1986,8 @@ __gg__lower_case( cblc_field_t *dest,
memset(dest->data, internal_space, dest_length);
memcpy(dest->data, input->data+input_offset, std::min(dest_length, source_length));
internal_to_ascii((char *)dest->data, dest_length);
- std::transform(dest->data, dest->data + dest_length, dest->data, tolower);
+ std::transform(dest->data, dest->data + dest_length, dest->data,
+ [](unsigned char c) { return std::tolower(c); });
ascii_to_internal_str((char *)dest->data, dest_length);
}
@@ -2431,7 +2434,7 @@ numval( cblc_field_t *dest,
state = SPACE4;
break;
}
- if( tolower(ch) == 'd' )
+ if( std::tolower(ch) == 'd' )
{
if( leading_sign )
{
@@ -2439,7 +2442,7 @@ numval( cblc_field_t *dest,
}
ch = *p++;
errpos += 1;
- if( p > pend || tolower(ch) != 'b' )
+ if( p > pend || std::tolower(ch) != 'b' )
{
goto done;
}
@@ -2447,7 +2450,7 @@ numval( cblc_field_t *dest,
state = SPACE4;
break;
}
- if( tolower(ch) == 'c' )
+ if( std::tolower(ch) == 'c' )
{
if( leading_sign )
{
@@ -2455,7 +2458,7 @@ numval( cblc_field_t *dest,
}
ch = *p++;
errpos += 1;
- if( p > pend || tolower(ch) != 'r' )
+ if( p > pend || std::tolower(ch) != 'r' )
{
goto done;
}
@@ -2494,7 +2497,7 @@ numval( cblc_field_t *dest,
state = SPACE4;
break;
}
- if( tolower(ch) == 'd' )
+ if( std::tolower(ch) == 'd' )
{
if( leading_sign )
{
@@ -2502,7 +2505,7 @@ numval( cblc_field_t *dest,
}
ch = *p++;
errpos += 1;
- if( p > pend || tolower(ch) != 'b' )
+ if( p > pend || std::tolower(ch) != 'b' )
{
goto done;
}
@@ -2510,7 +2513,7 @@ numval( cblc_field_t *dest,
state = SPACE4;
break;
}
- if( tolower(ch) == 'c' )
+ if( std::tolower(ch) == 'c' )
{
if( leading_sign )
{
@@ -2518,7 +2521,7 @@ numval( cblc_field_t *dest,
}
ch = *p++;
errpos += 1;
- if( p > pend || tolower(ch) != 'r' )
+ if( p > pend || std::tolower(ch) != 'r' )
{
goto done;
}
@@ -3408,9 +3411,13 @@ __gg__trim( cblc_field_t *dest,
}
}
+#if HAVE_INITSTATE_R && HAVE_SRANDOM_R && HAVE_RANDOM_R
static struct random_data *buf = NULL;
static char *state = NULL;
static const size_t state_len = 256;
+#else
+static unsigned seed = 0;
+#endif
extern "C"
void
@@ -3419,6 +3426,9 @@ __gg__random( cblc_field_t *dest,
size_t input_offset,
size_t input_size)
{
+ int32_t retval_31;
+ int rdigits;
+#if HAVE_INITSTATE_R && HAVE_SRANDOM_R && HAVE_RANDOM_R
// This creates a thread-safe pseudo-random number generator
// using input as the seed
@@ -3435,16 +3445,21 @@ __gg__random( cblc_field_t *dest,
__gg__clock_gettime(CLOCK_REALTIME, &ts);
initstate_r( ts.tv_nsec, state, state_len, buf);
}
-
- int rdigits;
int seed = (int)__gg__binary_value_from_qualified_field(&rdigits,
input,
input_offset,
input_size);
srandom_r(seed, buf);
- int32_t retval_31;
random_r(buf, &retval_31);
+#else
+ seed = (unsigned)__gg__binary_value_from_qualified_field(&rdigits,
+ input,
+ input_offset,
+ input_size);
+ srandom (seed);
+ retval_31 = random ();
+#endif
// We are going to convert this to a value between zero and not quite one:
double retval = double(retval_31) / double(0x80000000UL);
__gg__double_to_target( dest,
@@ -3456,6 +3471,8 @@ extern "C"
void
__gg__random_next(cblc_field_t *dest)
{
+ int32_t retval_31;
+#if HAVE_INITSTATE_R && HAVE_SRANDOM_R && HAVE_RANDOM_R
// The return value is between zero and not quite one
if( !buf )
@@ -3468,9 +3485,10 @@ __gg__random_next(cblc_field_t *dest)
__gg__clock_gettime(CLOCK_REALTIME, &ts);
initstate_r( ts.tv_nsec, state, state_len, buf);
}
- int32_t retval_31;
random_r(buf, &retval_31);
-
+#else
+ retval_31 = random ();
+#endif
// We are going to convert this to a value between zero and not quite one:
double retval = double(retval_31) / double(0x80000000UL);
__gg__double_to_target( dest,
@@ -3493,6 +3511,10 @@ __gg__reverse(cblc_field_t *dest,
{
dest->data[i] = (input->data+input_offset)[source_length-1-i];
}
+ if( (dest->attr & intermediate_e) )
+ {
+ dest->capacity = std::min(dest_length, source_length);
+ }
}
extern "C"
@@ -3736,7 +3758,8 @@ __gg__upper_case( cblc_field_t *dest,
memset(dest->data, internal_space, dest_length);
memcpy(dest->data, input->data+input_offset, std::min(dest_length, source_length));
internal_to_ascii((char *)dest->data, dest_length);
- std::transform(dest->data, dest->data + dest_length, dest->data, toupper);
+ std::transform(dest->data, dest->data + dest_length, dest->data,
+ [](unsigned char c) { return std::toupper(c); });
ascii_to_internal_str((char *)dest->data, dest_length);
}
@@ -4551,7 +4574,7 @@ fill_cobol_tm(cobol_tm &ctm,
if( ch == internal_Z || ch == internal_z )
{
// This has to be the end of the road
- if( toupper(source[0]) != 'Z' )
+ if( std::toupper((unsigned char)source[0]) != 'Z' )
{
retval += 0;
break;
@@ -5054,7 +5077,7 @@ iscasematch(char *a1, char *a2, char *b1, char *b2)
bool retval = true;
while( a1 < a2 && b1 < b2 )
{
- if( tolower(*a1++) != tolower(*b1++) )
+ if( std::tolower((unsigned char)*a1++) != std::tolower((unsigned char)*b1++) )
{
retval = false;
}