Commit 76e0d3e4 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Grzegorz Daniluk

shell: moved fromhex/fromdec functions to lib/util.c

parent 248230af
......@@ -12,9 +12,6 @@
extern int wrc_ui_mode;
extern int wrc_stat_running;
const char *fromhex(const char *hex, int *v);
const char *fromhex64(const char *hex, int64_t *v);
const char *fromdec(const char *dec, int *v);
void decode_mac(const char *str, unsigned char *mac);
char *format_mac(char *s, const unsigned char *mac);
void decode_ip(const char *str, unsigned char *ip);
......
......@@ -43,6 +43,10 @@ int tmo_init(timeout_t *tmo, uint32_t milliseconds);
int tmo_restart(timeout_t *tmo);
int tmo_expired(timeout_t *tmo);
const char *fromhex(const char *hex, int *v);
const char *fromhex64(const char *hex, int64_t *v);
const char *fromdec(const char *dec, int *v);
static inline int within_range(int x, int minval, int maxval, int wrap)
{
int rv;
......
......@@ -143,3 +143,58 @@ int tmo_expired(timeout_t *tmo)
return (timer_get_tics() - tmo->start_tics > tmo->timeout);
}
const char *fromhex64(const char *hex, int64_t *v)
{
int64_t o = 0;
int sign = 1;
if (hex && *hex == '-') {
sign = -1;
hex++;
}
for (; hex && *hex; ++hex) {
if (*hex >= '0' && *hex <= '9') {
o = (o << 4) + (*hex - '0');
} else if (*hex >= 'A' && *hex <= 'F') {
o = (o << 4) + (*hex - 'A') + 10;
} else if (*hex >= 'a' && *hex <= 'f') {
o = (o << 4) + (*hex - 'a') + 10;
} else {
break;
}
}
*v = o * sign;
return hex;
}
const char *fromhex(const char *hex, int *v)
{
const char *ret;
int64_t v64;
ret = fromhex64(hex, &v64);
*v = (int)v64;
return ret;
}
const char *fromdec(const char *dec, int *v)
{
int o = 0, sign = 1;
if (dec && *dec == '-') {
sign = -1;
dec++;
}
for (; dec && *dec; ++dec) {
if (*dec >= '0' && *dec <= '9') {
o = (o * 10) + (*dec - '0');
} else {
break;
}
}
*v = o * sign;
return dec;
}
......@@ -246,62 +246,6 @@ int shell_interactive()
return 0;
}
const char *fromhex64(const char *hex, int64_t *v)
{
int64_t o = 0;
int sign = 1;
if (hex && *hex == '-') {
sign = -1;
hex++;
}
for (; hex && *hex; ++hex) {
if (*hex >= '0' && *hex <= '9') {
o = (o << 4) + (*hex - '0');
} else if (*hex >= 'A' && *hex <= 'F') {
o = (o << 4) + (*hex - 'A') + 10;
} else if (*hex >= 'a' && *hex <= 'f') {
o = (o << 4) + (*hex - 'a') + 10;
} else {
break;
}
}
*v = o * sign;
return hex;
}
const char *fromhex(const char *hex, int *v)
{
const char *ret;
int64_t v64;
ret = fromhex64(hex, &v64);
*v = (int)v64;
return ret;
}
const char *fromdec(const char *dec, int *v)
{
int o = 0, sign = 1;
if (dec && *dec == '-') {
sign = -1;
dec++;
}
for (; dec && *dec; ++dec) {
if (*dec >= '0' && *dec <= '9') {
o = (o * 10) + (*dec - '0');
} else {
break;
}
}
*v = o * sign;
return dec;
}
static char shell_init_cmd[] = CONFIG_INIT_COMMAND;
static int build_init_readcmd(uint8_t *cmd, int maxlen)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment