2 * Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc.
3 * See COPYING file for license information
7 * Copyright (c) 1998 Cobite, Inc. All Rights Reserved.
9 * @created Fri Nov 6 14:33:29 1998
10 * @version $Revision: 1.9 $$Date: 2001/10/25 18:36:11 $
17 #include "text_util.h"
20 RCSID("$Id: text_util.c,v 1.9 2001/10/25 18:36:11 adam Exp $");
25 char* p
= src
+ strlen(src
) - 1;
29 if ( *p
== '\n' || *p
== '\r' )
51 if ( isdigit( *check
) )
65 lower_case( char* src
)
82 int len
= strlen( src
);
85 for( i
= len
/ 2; --i
>= 0; )
88 src
[ i
] = src
[ len
- i
- 1 ];
89 src
[ len
- i
- 1 ] = tmp
;
98 char *p
= src
+ strlen(src
) - 1;
100 while( p
>= src
&& isspace(*p
) )
107 upper_case( char* src
)
121 strrcmp( const char* haystack
, const char* needle
)
123 int hlen
= strlen( haystack
);
124 int nlen
= strlen( needle
);
128 return( strcmp( haystack
+ hlen
- nlen
, needle
) );
132 * Finding a - anywhere in the string makes it money negative.
133 * all characters other than digits, '-', and '.' are ignored, so:
135 * This is fair, I think, if we don't want to reject anything as
136 * improperly formatted.
139 money2cents( const char* money
)
142 int decimal_places
= -1;
145 while( *money
&& decimal_places
< 2 )
147 if ( isdigit( *money
) )
149 if ( decimal_places
>= 0 )
153 retval
+= (*money
) - '0';
156 else if ( *money
== '.' )
159 else if ( *money
== '-' )
165 if ( decimal_places
== 1 )
168 else if ( decimal_places
<= 0 )
171 return( neg
? -retval
: retval
);
175 cents2money( long cents
)
177 static char buff
[ 64 ];
183 strcpy( buff
, "0.00" );
186 else if ( cents
< 100 )
188 sprintf( buff
, "0.%2.2ld", cents
);
195 *d
++ = '0' + ( cents
% 10 );
203 else if ( cents
> 0 && ( idx
- 1 ) % 3 == 0 )
219 void trim_zeros_after_decimal( char* src
)
221 char * end
= src
+ strlen( src
) - 1;
227 else if( *end
== '.' )
240 extern void *memfrob(void *, size_t);
242 static void * memfrob(void * mem
, size_t len
)
245 char *c
= (char *)mem
;
247 for (i
= 0; i
< len
; i
++)
257 // simple functions to obfuscate strings in a binary
258 char* frobstr( char* src
)
260 char* retval
= (char*)malloc( strlen(src
) * 2 + 1 );
262 memfrob( src
, strlen( src
) );
263 str2hex( retval
, src
, 0 );
264 memfrob( src
, strlen( src
) );
269 char* unfrobstr( char* src
)
271 int slen
= strlen( src
) / 2;
272 char* retval
= (char*)malloc( slen
+ 1 );
274 hex2str( retval
, src
, 0 );
275 memfrob( retval
, slen
);
280 void str2hex( char* dest
, const char* src
, int slen
)
286 slen
= strlen( src
);
288 for ( i
= 0; i
< slen
; i
++ )
290 sprintf( p
, "%02x", src
[i
] );
297 void hex2str( char* dest
, const char* src
, int slen
)
304 slen
= strlen( src
);
308 for( i
= 0; i
< slen
; i
++ )
310 sscanf( p
, "%02x", &v
);