bringing SDL 1.2.14 from vendor into the main branch
[AROS-Contrib.git] / regina / rexxbif.c
blob127d35d6a2f7686c0e6367283b2235850cc3a176
2 #include <stdio.h>
3 #include "rexxbif.h"
5 #ifdef EXTERNAL_TO_REGINA
6 #define exiterror __regina_exiterror
7 void DropStreng( streng *str )
9 if ( str )
10 free( str );
13 streng *MakeStreng( int num )
15 streng *out = (streng *)malloc( sizeof(streng) + num );
16 if ( out != NULL )
18 out->len = out->max = num;
19 if ( num )
21 memset( out->value, '$', num );
24 if ( out == NULL ) fprintf(stderr,"ERROR allocating RXSTRING\n");
25 return out;
27 void exiterror( int errorno, int suberrorno, ... )
30 #endif
32 int Rexx_x2d( const tsd_t *TSD, streng *hex )
34 int dec=0,i;
35 char c;
37 TSD = TSD; /* keep compiler happy */
39 for ( i = 0; i < PSTRENGLEN(hex); i++ )
41 dec <<= 4;
42 c = hex->value[i];
43 if ( c >='0'&& c<='9')
44 dec += c-'0';
45 else if ( c >= 'A' &&c <= 'F' )
46 dec += c-'A'+10;
47 else if( c >='a' && c <='f' )
48 dec += c-'a'+10;
49 else
51 dec = -1;
52 break;
55 return dec;
58 streng *Rexx_right( const tsd_t *TSD, streng *str, int length, char padch )
60 streng *out = MAKESTRENG( length );
61 int i,j;
62 if ( out )
64 for ( j = 0; PSTRENGLEN(str) > j; j++) ;
65 for (i=length-1,j--;(i>=0)&&(j>=0);out->value[i--]=str->value[j--]) ;
66 for (;i>=0;out->value[i--]=padch) ;
67 out->len = length;
69 return out;
72 streng *Rexx_d2x( const tsd_t *TSD, int num )
74 streng *out;
75 out = MAKESTRENG( (2+(num/16)) );
76 if ( out )
78 sprintf( PSTRENGVAL(out), "%X", num );
79 out->len = strlen( PSTRENGVAL(out) );
81 return out;