forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / regina / rexxbif.c
blob270ea4ad24eb2501d396c3d53b9ac50ff26f3f8f
2 #include <stdio.h>
3 #include <limits.h>
4 #include "rexxbif.h"
6 #ifdef EXTERNAL_TO_REGINA
7 #define exiterror __regina_exiterror
8 void DropStreng( streng *str )
10 if ( str )
11 free( str );
14 streng *MakeStreng( int num )
16 streng *out = (streng *)malloc( sizeof(streng) + num );
17 if ( out != NULL )
19 out->len = out->max = num;
20 if ( num )
22 memset( out->value, '$', num );
25 if ( out == NULL ) fprintf(stderr,"ERROR allocating RXSTRING\n");
26 return out;
28 void exiterror( int errorno, int suberrorno, ... )
31 #endif
33 int Rexx_x2d( const tsd_t *TSD, const streng *hex, int *error )
35 int dec=0,i;
36 char c;
38 TSD = TSD; /* keep compiler happy */
40 if ( PSTRENGLEN(hex) == 0 )
42 *error = 1;
43 return -1;
45 for ( i = 0; i < PSTRENGLEN(hex); i++ )
47 dec <<= 4;
48 c = hex->value[i];
49 if ( c >='0'&& c<='9')
50 dec += c-'0';
51 else if ( c >= 'A' &&c <= 'F' )
52 dec += c-'A'+10;
53 else if( c >='a' && c <='f' )
54 dec += c-'a'+10;
55 else
57 *error = 1;
58 return -1;
61 *error = 0;
62 return dec;
65 streng *Rexx_right( const tsd_t *TSD, streng *str, int length, char padch )
67 streng *out = MAKESTRENG( length );
68 int i,j;
69 if ( out )
71 for ( j = 0; PSTRENGLEN(str) > j; j++) ;
72 for (i=length-1,j--;(i>=0)&&(j>=0);out->value[i--]=str->value[j--]) ;
73 for (;i>=0;out->value[i--]=padch) ;
74 out->len = length;
76 return out;
79 streng *Rexx_d2x( const tsd_t *TSD, int num )
81 streng *out;
82 out = MAKESTRENG( 100 ); /* use 100 as the largest length of a hex value we will ever get */
83 if ( out )
85 out->len = sprintf( PSTRENGVAL(out), "%X", num );
87 return out;