Files
actube/src/cw/bstr16_create_from_str.c
7u83@mail.ru b668a8f4a9 Work in progress
FossilOrigin-Name: 155605fd55cbb193d4f5ac8c704930c050a11cda541f1a5cdb93c57a8c51534f
2018-03-17 11:32:40 +00:00

34 lines
563 B
C

#include "bstr.h"
#include "format.h"
uint8_t * bstr16_create_from_str(const char *s)
{
uint8_t * mem;
int msize;
int l;
l = strlen(s);
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;
msize=l/2;
if(l&1)
msize++;
mem = malloc(2+msize);
*((uint16_t*)mem)=msize;
cw_format_scan_hex_bytes(mem+2,s+2,l);
return mem;
}