libxconv/test.c

73 lines
1.0 KiB
C
Raw Permalink Normal View History

2017-03-09 14:55:16 +00:00
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdint.h>
#include "xconv.h"
2017-03-09 14:55:16 +00:00
char *teststr[] = {
"The House That \243100k Built",
"home d\302ecor",
"home made p\303at\302e",
"scene at \251Odette\271 that",
"Sealgairean Sp\xc3\xacrsail/History Hunters",
"Ben & Hoilidh san R\xc3\xb2oghachd Bhig",
2017-03-09 14:55:16 +00:00
NULL
};
static void
hexdump(uint8_t *s, uint32_t len)
{
uint16_t off;
if (!s)
return;
if (!len)
len = strlen((char *)s);
for (off = 0; off < len; off += 16)
{
uint32_t i;
printf("%08lx: ", (unsigned long)off);
for (i = off; i - off < 16; i++)
{
if (i < len)
printf("%02x ", s[i] & 0xff);
else
printf(" ");
}
printf(" ");
for (i = off; i < len && i - off < 16; i++)
printf("%c", isprint((int)s[i]) ? s[i] : '.');
printf("\n");
}
}
int
main()
{
char buf[0x200];
int i, l;
2017-03-09 14:55:16 +00:00
for (i = 0; teststr[i]; i++)
{
hexdump(teststr[i], 0);
if ((l = xconv(teststr[i], buf, sizeof(buf))))
hexdump(buf, l);
else
printf("Unchanged.\n");
2017-03-09 14:55:16 +00:00
printf("\n\n");
}
return 0;
}