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

#define		iskanji(x)		(((x)>=0x81 && (x)<=0x9F)||((x)>=0xE0 && (x)<=0xFC))

int
main( int argc, char *argv[] )
{
	FILE	*src ;
	FILE	*dst ;
	int		index ;
	char	fn[ 256 ], buf[ 256 ] ;

	if ( argc <= 1 ) {
		printf( "Usage:\n\t%s original-file\n", argv[0] ) ;
		return 1 ;
	}
	src = fopen( argv[1], "r" ) ;
	if ( src == NULL ) {
		return 1 ;
	}
	fgets( buf, sizeof buf, src ) ;
	while ( !feof( src ) ) {
		if ( iskanji( (unsigned char) *buf ) ) {
			index = (unsigned char) *(buf + 1) ;
			index &= 0x0F ;
		} else {
			index = 0 ;
		}
		sprintf( fn, "%s%02X", argv[1], index ) ;
		dst = fopen( fn, "a" ) ;
		if ( dst != NULL ) {
			fputs( buf, dst ) ;
			fclose( dst ) ;
		}
		fgets( buf, sizeof buf, src ) ;
	}
	fclose( src ) ;
	return 0 ;
}
