Tidy up test code formatting

This commit is contained in:
Laurence Withers 2009-10-13 11:32:08 +00:00
parent 26e3c57b04
commit a46f5cc2ee
2 changed files with 26 additions and 16 deletions

View File

@ -12,15 +12,18 @@
void writeout(const wchar_t* x, int amt)
void
writeout(const wchar_t* x, int amt)
{
fwrite(x, sizeof(wchar_t), amt, stdout);
int dummy;
dummy = fwrite(x, sizeof(wchar_t), amt, stdout);
}
enum utf8_decode_error_action error_callback(
const struct utf8_decode_state* ctx, enum utf8_decode_error error, wchar_t* newch)
enum
utf8_decode_error_action error_callback(const struct utf8_decode_state* ctx,
enum utf8_decode_error error, wchar_t* newch)
{
fprintf(stderr, "Line %d, col %d (char %d, byte %d): ",
ctx->line + 1, ctx->col + 1, ctx->char_offset, ctx->byte_offset);
@ -52,7 +55,8 @@ enum utf8_decode_error_action error_callback(
int main(int argc, char* argv[])
int
main(int argc, char* argv[])
{
char inbuf[1024];
wchar_t outbuf[1024];
@ -69,19 +73,19 @@ int main(int argc, char* argv[])
return 1;
}
// set up ctx structure
/* set up ctx structure */
memset(&ctx, 0, sizeof(ctx));
ctx.wr = outbuf;
ctx.wr_size = sizeof(outbuf) / sizeof(wchar_t);
ctx.error_callback = error_callback;
// loop over input
/* loop over input */
while(!feof(stdin)) {
// read input
/* read input */
ctx.rd_remain = fread(inbuf, 1, sizeof(inbuf), stdin);
ctx.rd = inbuf;
// decode it
/* decode it */
while(ctx.rd_remain) {
if(!utf8_decoder(&ctx)) {
perror("utf8_decoder");
@ -90,7 +94,7 @@ int main(int argc, char* argv[])
return 1;
}
// write output
/* write output */
writeout(outbuf, ctx.written);
}
}

View File

@ -15,7 +15,8 @@
void make_rand(wchar_t* buf, int ch)
void
make_rand(wchar_t* buf, int ch)
{
int fd = open("/dev/urandom", O_RDONLY);
if(fd < 0) {
@ -37,7 +38,8 @@ void make_rand(wchar_t* buf, int ch)
int do_encode(char* dest, size_t size, wchar_t* src, size_t amt)
int
do_encode(char* dest, size_t size, wchar_t* src, size_t amt)
{
struct utf8_encode_state ctx;
memset(&ctx, 0, sizeof(ctx));
@ -65,14 +67,16 @@ int do_encode(char* dest, size_t size, wchar_t* src, size_t amt)
int MIN(int x, int y)
int
MIN(int x, int y)
{
return (x < y) ? x : y;
}
void do_decode_easy(wchar_t* dest, size_t size, const char* src, size_t amt)
void
do_decode_easy(wchar_t* dest, size_t size, const char* src, size_t amt)
{
struct utf8_decode_state ctx;
memset(&ctx, 0, sizeof(ctx));
@ -100,7 +104,8 @@ void do_decode_easy(wchar_t* dest, size_t size, const char* src, size_t amt)
void do_decode(wchar_t* dest, size_t size, const char* src, size_t amt)
void
do_decode(wchar_t* dest, size_t size, const char* src, size_t amt)
{
struct utf8_decode_state ctx;
memset(&ctx, 0, sizeof(ctx));
@ -131,7 +136,8 @@ void do_decode(wchar_t* dest, size_t size, const char* src, size_t amt)
int main(int argc, char* argv[])
int
main(int argc, char* argv[])
{
wchar_t wbuf[1024], wbuf2[1025];
char cbuf[8192];