#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

/*
 * For double byte chars,
 *   >> First Byte:			0x81 ~ 0xFE
 *   >> Second Byte:		0x40 ~ 0x7E
 *   						0x80 ~ 0xFE
 * For four byte chars,
 *   >> First, third byte:	0x81 ~ 0xFE
 *   >> Second, forth byte:	0x30 ~ 0x39
 */

void printRange (FILE *fp, unsigned int start, unsigned int end)
{
	unsigned int cnt;
	printf (" Range: %#X - %#X ", start, end);
	fprintf (fp, "Range: %#X - %#X\n", start, end);
	for (cnt = start; cnt <= end; cnt++)
	{
		int numOfByte,x;
		fprintf (fp, "%#X", cnt);
		fprintf (fp, "%s", " -> ");

		if ((char)(cnt >> 24) && 0x80)
			numOfByte = 4;
		else
			numOfByte = 2;

		for (x = (numOfByte-1)*8; x > 0; x -= 8)
			fprintf (fp, "%c", (char)(cnt >> x));
		fprintf (fp, "%c", (char)cnt);

		fprintf (fp, "%c", '\n');
	}
}

int main (int argc, char **argv)
{
	FILE *fp;
	fp = fopen (argv[1], "w");
	if (fp == NULL)
		exit (EXIT_FAILURE);

	printf ("Printing ...");
	printRange (fp, 0x9140, 0x914F);
	printf ("finished.\n");

	printf ("Printing ...");
	printRange (fp, 0x8230C030, 0x8230C039);
	printf ("finished.\n");

	fclose (fp);
	exit (EXIT_SUCCESS);
}
