2015-05-04 07:30:57 +02:00
|
|
|
#include "bstr.h"
|
|
|
|
#include "format.h"
|
|
|
|
|
|
|
|
|
2022-08-13 09:47:12 +02:00
|
|
|
bstr16_t bstr16_create_from_str(const char *s)
|
2015-05-04 07:30:57 +02:00
|
|
|
{
|
2018-03-17 12:32:40 +01:00
|
|
|
uint8_t * mem;
|
|
|
|
int msize;
|
|
|
|
int l;
|
|
|
|
l = strlen(s);
|
2015-05-04 07:30:57 +02:00
|
|
|
if (s[0]!='.')
|
|
|
|
return bstr16_create((uint8_t*)s,l);
|
|
|
|
|
|
|
|
if (l<=2)
|
|
|
|
return bstr16_create((uint8_t*)s,l);
|
|
|
|
|
|
|
|
if (s[1]=='.')
|
|
|
|
return bstr16_create((uint8_t*)s+1,l-1);
|
|
|
|
|
|
|
|
if (s[1]!='x')
|
|
|
|
return bstr16_create((uint8_t*)s,l);
|
|
|
|
|
|
|
|
/* the string starts with ".x" - read hexbytes */
|
|
|
|
l-=2;
|
2018-03-17 12:32:40 +01:00
|
|
|
msize=l/2;
|
2015-05-04 07:30:57 +02:00
|
|
|
if(l&1)
|
|
|
|
msize++;
|
2018-03-17 12:32:40 +01:00
|
|
|
mem = malloc(2+msize);
|
2015-05-04 07:30:57 +02:00
|
|
|
*((uint16_t*)mem)=msize;
|
2018-03-06 18:28:31 +01:00
|
|
|
cw_format_scan_hex_bytes(mem+2,s+2,l);
|
2015-05-04 07:30:57 +02:00
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|