#include "config.h"
#include "util.h"

/* Convert from ASCII hex.  Returns
   the value, or 16 if it was space/newline, or
   32 if some other character. */
uint8_t from_hex(uint8_t ch)
{
	if(ch==' ' || ch=='\r' || ch=='\n')
		return 16;

	if(ch < '0')
		goto bad;
	if(ch <= '9')
		return ch - '0';
	ch |= 0x20;
	if(ch < 'a')
		goto bad;
	if(ch <= 'f')
		return ch - 'a' + 10;
 bad:
	return 32;
}

const uint8_t hex[16]={'0','1','2','3','4','5','6','7',
		       '8','9','a','b','c','d','e','f'};
