Пример #1
0
int lib$tra_ebc_asc (void * byte_integer_source_string, void * destination_string)
{
    int sts;
    sts = str$copy_dx (destination_string, byte_integer_source_string);
    if ((sts & 1) == 0)
        return sts;
    struct dsc$descriptor * dsc = destination_string;
    int i;
    char * s = dsc->dsc$a_pointer;
    for (i=0; i < dsc->dsc$w_length; i++, s++)
        *s = EBCDICtoASCII(*s);
    return SS$_NORMAL;
}
Пример #2
0
int lib$tra_asc_ebc (void * source_string, void * byte_integer_dest_string)
{
    int sts;
    sts = str$copy_dx (byte_integer_dest_string, source_string);
    if ((sts & 1) == 0)
        return sts;
    struct dsc$descriptor * dsc = byte_integer_dest_string;
    int i;
    char * s = dsc->dsc$a_pointer;
    for (i=0; i < dsc->dsc$w_length; i++, s++)
        *s = ASCIItoEBCDIC(*s);
    return SS$_NORMAL;
}
Пример #3
0
/*************************************************************
 * str$upcase
 *
 */
unsigned long str$upcase(struct dsc$descriptor_s* destination_string,
	const struct dsc$descriptor_s* source_string)
{
	char* s1_ptr;				/* Pointer to string */
	unsigned short s1_length;		/* Length of string */
	unsigned long result;			/* Working result */

	/*
	 * Copy over the string, retaining original case
	 */
	result = str$copy_dx(destination_string, source_string);

	/*
	 * Analyze destination string
	 */
	if ((result & 1) == 1)
	{
		/*
		 * Analyse the copies string
		 */
		str$analyze_sdesc(destination_string, &s1_length, &s1_ptr);

		/*
		 * Transform it to upper case
		 */
		while(s1_length > 0)
		{
			*s1_ptr = toupper(*s1_ptr);
			s1_ptr++;
			s1_length--;
		}

	}

	/*
	 * Done
	 */
	return result;
}
Пример #4
0
unsigned long str$add ( const	unsigned	long *asign,
                        const 			long *aexp,
                        const struct dsc$descriptor_s *adigits,
                        const	unsigned	long *bsign,
                        const 			long *bexp,
                        const struct dsc$descriptor_s *bdigits,
                        unsigned  	long *csign,
                        long *cexp,
                        struct dsc$descriptor_s *cdigits)
{
    unsigned short	s1_len,  s2_len,  s3_len, temp_len;
    char		*s1_ptr, *s2_ptr, *s3_ptr;
    unsigned long  	index,max_len,min_len;
    int		i,j,k;
    unsigned long	status;
    signed long	min_exp,max_exp, a_size, b_size, max_size, min_size;
    char 		ctemp;
    int		sum,carry;
    char		*a,*b,*c;

    status = STR$_NORMAL;
    index = 0;

    a = (char *) calloc(MAXSTR,1);
    b = (char *) calloc(MAXSTR,1);
    c = (char *) calloc(MAXSTR,1);

    if ( a == NULL )
    {
        status = STR$_INSVIRMEM;
    }
    if ( b == NULL )
    {
        status = STR$_INSVIRMEM;
    }
    if ( c == NULL )
    {
        status = STR$_INSVIRMEM;
    }

//	Check the sign field is 1 or 0
    if ( *asign == 1 || *asign == 0 )
        ;
    else
        status = LIB$_INVARG;

    if ( *bsign == 1  || *bsign == 0)
        ;
    else
        status = LIB$_INVARG;

//	If we have a negative sign then call str$subtract
//	c = -a + b
    if (( *asign == 1 ) && (*bsign == 0 ))
    {
        status = str$sub(asign,aexp,adigits,bsign,bexp,bdigits,csign,cexp,cdigits);
        return status;
    }
//	c = a - b
    if (( *asign == 0  ) && (*bsign == 1 ))
    {
        status = str$sub(asign,aexp,adigits,bsign,bexp,bdigits,csign,cexp,cdigits);
        return status;
    }
//	c = -a + -b
    *csign = 0;
    if (( *asign == 1 ) && ( *bsign == 1))
    {
        *csign = 1;
    }

//	Get the length of the input strings and how much room for the output
    str$analyze_sdesc (adigits, &s1_len, &s1_ptr);
    str$analyze_sdesc (bdigits, &s2_len, &s2_ptr);
    str$analyze_sdesc (cdigits, &s3_len, &s3_ptr);
    if ( s3_ptr != NULL )
    {
        str$free1_dx (cdigits);
        printf ("Destination must be NULL\n");
        return STR$_FATINTERR;
    }
// 	Quick abort
    if (status != STR$_NORMAL)
    {
        return status;
    }

//	Move in the largest number - we need to keep the alignment correct
//	char string is "right to left" alignment
//	start at location specified by the exponent
    max_exp = ( *aexp > *bexp ) ? *aexp : *bexp;	// get largest exp
    min_exp = ( *aexp > *bexp ) ? *bexp : *aexp;
    max_len = ( s1_len > s2_len ) ? s1_len : s2_len;
    min_len = ( s1_len > s2_len) ? s2_len : s1_len;
    a_size  = ( *aexp + s1_len );
    b_size  = ( *bexp + s2_len );
    max_size= ( a_size > b_size ) ? a_size : b_size;
    min_size= ( a_size > b_size ) ? b_size : a_size;

// 	The strings don't overlap just return the largest
    if ( max_size - min_size > UINT16_MAX )
    {

//Don't Overlap returning largest
        if ( *aexp > *bexp )
        {
            *cexp = *aexp;
            str$copy_dx (cdigits,adigits);
        }
        else
        {
            *cexp = *bexp;
            str$copy_dx(cdigits,bdigits);
        }
        return STR$_TRU;
    }

//	Copy input strings to working storage
    for (i = 0; i < s1_len; i++ )
    {
        a[i] = s1_ptr[i];
    }
    for (j = 0; j < s2_len; j++ )
    {
        b[j] = s2_ptr[j];
    }

//	Set the output exponent
    *cexp = min_exp;

//	Add zero's to the end of the number for remaining exponent
    if ( *aexp > *bexp )
    {
        for ( i = s1_len; i < s1_len + max_exp - min_exp; i++)
            a[i] = '0';
        s1_len += max_exp - min_exp;
    }
    if ( *aexp < *bexp )
    {
        for ( i = s2_len; i < s2_len + max_exp - min_exp; i++)
            b[i] = '0';
        s2_len += max_exp - min_exp;
    }

    sum = 0;
    carry = 0;
    ctemp = '0';
    i = s1_len;
    j = s2_len;
// 	New max string length
    max_len = ( s1_len > s2_len ) ? s1_len : s2_len ;

    for (k =(int) max_len; k > 0; k-- )
    {
        if ( i > 0 )
        {
            sum += a[i-1] - '0';
        }
        if ( j > 0 )
        {
            sum += b[j-1] - '0';
        }
        sum += carry;
        carry = 0;
        if ( sum > 9 )
        {
            carry = 1;
            sum -= 10;
        }
        ctemp = sum + '0';
        sum = 0;
        c[k-1] = ctemp;
        i--;
        j--;
    }
    if ( carry == 1 )
    {
        for (i = max_len-1; i >= 0; i-- )
        {
            c[i+1] = c[i];
        }
        c[0] = (char) (carry + '0');
        max_len++;
    }


//	Truncate output sum string to 65536 MAXUINT16
    if ( max_len > MAXUINT16 )
    {
        status = STR$_TRU;
        max_len = MAXUINT16;
    }

//	Free any memory that is passed into us.
    temp_len = max_len;
    str$free1_dx(cdigits);

    str$get1_dx(&temp_len,cdigits);
    str$analyze_sdesc (cdigits,&s3_len,&s3_ptr);

    for (i = 0; i < max_len; i++)
    {
        s3_ptr[i] = c[i];
    }

    free (a);
    free (b);
    free (c);
    str$$lzerotrim (&*cdigits);
    str$$rzerotrim (&*cdigits,&*cexp);
    str$$iszerotrim (&*cdigits,&*cexp);

    return status;
}