Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
utils.cpp
- Committer:
- klauss
- Date:
- 2015-04-16
- Revision:
- 113:db67ae00550e
- Parent:
- 112:6ae726539ab9
- Child:
- 114:472502b31a12
File content as of revision 113:db67ae00550e:
#include "utils.h" int ls_comp( const void * a, const void * b ){ return( *( int * )a - *( int * )b ); } void reverse( char str[], int length ){ int start = 0; int end = length -1; while (start < end){ swap(*(str+start), *(str+end)); start++; end--; } } char* itoa(int num, char* str, int base){ int i = 0; bool isNegative = false; if( num == 0 ){ str[i++] = '0'; str[i] = '\0'; return str; } if( num < 0 && base == 10 ){ isNegative = true; num = -num; } while( num != 0 ){ int rem = num % base; str[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0'; num = num/base; } if( isNegative ) str[i++] = '-'; str[i] = '\0'; // Append string terminator reverse( str, i ); return( str ); } int convert_ext_to_port( int ext ){ if( ext < 1000 ) return ext; else{ int aux = 0; aux = ( ext / 1000 ) * 1000; ext -= aux; aux += ext % 100; return( aux ); } } void xstrcpy(uint8_t * dest, const uint8_t * src ){ while (*src) *dest++ = *src++; *dest = 0; } void xmemcpy(uint8_t * dest, const uint8_t * src, uint16_t size ){ while (size--) *dest++ = *src++; } void xmemcpy32(uint32_t * dest, uint32_t * src, uint16_t size){ size >>= 2; while (size--) *dest++ = *src++; } uint8_t xstrmatch(const uint8_t * s1, const uint8_t * s2){ while (*s1) { if (*s1++ != *s2++) return 0; /* does not match */ } if ( *s2 == 0 ) return 1; /* matches */ else return 0; /* does not match */ } uint8_t xmemmatch(const uint8_t * s1, const uint8_t * s2, uint16_t size){ while (size--) { if (*s1++ != *s2++) return 0; /* does not match */ } return 1; /* matches */ }