libxconv/test.c

73 lines
1.0 KiB
C

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdint.h>
#include "xconv.h"
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",
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;
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");
printf("\n\n");
}
return 0;
}