/* Print a buffer up to 16 bytes long in formatted hex with ascii * translation, e.g., * 0000: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>? */ static void fmtline( FILE *fp, uint addr, uint8 *buf, uint len) { char line[80]; char *aptr,*cptr; uint8 c; memset(line,' ',sizeof(line)); ctohex(line,(uint)hibyte(addr)); ctohex(line+2,(uint)lobyte(addr)); aptr = &line[6]; cptr = &line[55]; while(len-- != 0){ c = *buf++; ctohex(aptr,(uint)c); aptr += 3; *cptr++ = isprint(c) ? c : '.'; } *cptr++ = '\n'; fwrite(line,1,(unsigned)(cptr-line),fp); }
C_RESULT vp_com_str_to_address(const char* address, bdaddr_t* addr) { int i = 5; while(*address) { if(*address == ':') address++; addr->b[i] = ctohex(*address++) << 4; addr->b[i] |= ctohex(*address++); i --; } return VP_COM_OK; }
/** * Initialize an array to mark which characters are to be encoded. Store the hex * string for that character to save time later. If the character shouldn't be * encoded, then store null. */ void codec_init() { for (int c = 0; c < 0xFF; c++) { if ((c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A)) { hex[c] = NULL; } else { hex[c] = ctohex((char) c); } } }
char UrlDecodeChar(char **psrc) { char *src; char c; assert(psrc != NULL); assert(*psrc != NULL); src = *psrc; c = *src++; if (c == '+') c = ' '; else if (c == '%') { assert(isxdigit(*src)); assert(isxdigit(*(src+1))); c = ctohex(*src) * 16 + ctohex(*(src+1)); src += 2; } *psrc = src; return(c); }