1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <stdio.h>
#include "rexxbif.h"
#ifdef EXTERNAL_TO_REGINA
#define exiterror __regina_exiterror
void DropStreng( streng *str )
{
if ( str )
free( str );
}
streng *MakeStreng( int num )
{
streng *out = (streng *)malloc( sizeof(streng) + num );
if ( out != NULL )
{
out->len = out->max = num;
if ( num )
{
memset( out->value, '$', num );
}
}
if ( out == NULL ) fprintf(stderr,"ERROR allocating RXSTRING\n");
return out;
}
void exiterror( int errorno, int suberrorno, ... )
{
}
#endif
int Rexx_x2d( const tsd_t *TSD, streng *hex )
{
int dec=0,i;
char c;
TSD = TSD; /* keep compiler happy */
for ( i = 0; i < PSTRENGLEN(hex); i++ )
{
dec <<= 4;
c = hex->value[i];
if ( c >='0'&& c<='9')
dec += c-'0';
else if ( c >= 'A' &&c <= 'F' )
dec += c-'A'+10;
else if( c >='a' && c <='f' )
dec += c-'a'+10;
else
{
dec = -1;
break;
}
}
return dec;
}
streng *Rexx_right( const tsd_t *TSD, streng *str, int length, char padch )
{
streng *out = MAKESTRENG( length );
int i,j;
if ( out )
{
for ( j = 0; PSTRENGLEN(str) > j; j++) ;
for (i=length-1,j--;(i>=0)&&(j>=0);out->value[i--]=str->value[j--]) ;
for (;i>=0;out->value[i--]=padch) ;
out->len = length;
}
return out;
}
streng *Rexx_d2x( const tsd_t *TSD, int num )
{
streng *out;
out = MAKESTRENG( (2+(num/16)) );
if ( out )
{
sprintf( PSTRENGVAL(out), "%X", num );
out->len = strlen( PSTRENGVAL(out) );
}
return out;
}
|