/*-
 * Copyright (c) 2001
 * Tatsuya Kudoh(CDR/TK),ROYALPANDA.    All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#include<stdio.h>


static int dump( FILE *fp )
{
	int len;
	unsigned char buf[1024];
	int i,j;
	short s;
	int size;

	printf("--- user's dictinary\n\n");

	size = 0;

	while( (len = fgetc(fp)) != 0 ){
		if( len == EOF )
			return -1;
		if( fread(buf,len,1,fp) != 1 )
			return -1;
		buf[len] = 0;
		printf("%s /",buf);
		size += len + 1;
		while( (len = fgetc(fp)) != 0 ){
			if( len == EOF )
				return -1;
			if( fread(buf,len,1,fp) != 1 )
				return -1;
			buf[len] = 0;
			printf("%s/",buf);
			size += len + 1;
		}
		size++;
		putchar('\n');
	}
	printf("\nuse %d byte(s)\n",size);

	printf("\n--- frequency infomatin\n\n");

	for( i = 0 ; i < 128 ; i++ ){
		if( fread(buf,10,1,fp) != 1 )
			return -1;
		if( buf[0] == 0 )
			break;
		buf[10] = 0;
		printf("%s : ",buf);
		for( j = 0 ; j < 3 ; j++ ){
			if( fread(buf,2,1,fp) != 1 )
				return -1;
			s = buf[0] | (int)buf[1] << 8;
			printf("%3d ",s);
		}
		putchar('\n');
	}
	return 0;
}







int main( int argc, char **argv )
{
	FILE *fp;

	if( argc > 1 ){
		fp = fopen(argv[1],"r");
		if( fp == NULL ){
			fprintf(stderr,"cannot open '%s'.\n",argv[1]);
			return 1;
		}
	}else{
		fp = stdin;
	}

	if( dump(fp) < 0 ){
		fprintf(stderr,"\n*** file reading error.\n");
		return 1;
	}
	if( fp != stdin )
		fclose(fp);
	return 0;
}
