/***********************************************
 *                                             *
 *  PAL ZELDA MESSAGE FRAGMENTS COUNT PROGRAM  *
 *                                             *
 *   ┏   ふらんす語　＆　どいつ語版     ┓    *
 *   ┗  『１単語用』　テストバージョン  ┛    *
 *                                             *
 ***********************************************/

/*
#include "inc.h"
*/


#include	"stdio.h"
#define		unshort	  unsigned short
#define		unchar	  unsigned char


unchar	test_tbl[20]=	{'H','i','\0','d','\0','\0','\0','W','e','i',
			 's','e','n','\0','\0','\0','\0','\0','\0','\0'};
unshort	test_cnt=0;


main(argc,argv)
int	argc;
char	*argv[];
{
	FILE *rfp1;
	FILE *rfp2;

	unshort i,j;
	unchar	*r_pnt;
	unchar	r_buf[150];
	unshort	mojisu;

	char    name_buf[20];

	if((rfp1=fopen("Tmsgtbl.TBL","r"))==NULL){
		printf("OPEN ERROR  [ Tmsgtbl.TBL ] !!\n");
		exit(1);
	}

	mojisu=strlen(test_tbl);
	printf("\n              文字数 -->  %3d\n",mojisu);

	while(fgets(name_buf,20,rfp1)!=NULL){

		name_buf[11]='\0';
j=0;
		if((rfp2=fopen(name_buf,"r"))==NULL){
			printf("OPEN ERROR  [ %s ] !!\n",name_buf);
			exit(1);
		}

		while(fgets(r_buf,150,rfp2)!=NULL){
j++;
			r_pnt=r_buf;

			while((char)(*r_pnt)!='\0'){

				for(i=0;i<mojisu;i++){
					if(*(r_pnt+i)!=test_tbl[i])
					break;
				}

				if(i==mojisu){
					test_cnt++;
					r_pnt+=mojisu;

/*　サ−チして抜ける場合，以下の４行の文を消去する　*/
printf("\n＜＜＜　サ−チ　ＯＫ　！！　＞＞＞\n");
printf("　該当ファイル名  --->  %s\n",name_buf);
printf("　 ライン　Ｎｏ． --->  %d\n\n",j);
exit(1);

				}
				else
					r_pnt++;
			}
		}
		fclose(rfp2);
	}

	printf("%20s --> %4d   * %3d  =  %3d\n\n",test_tbl,test_cnt,(strlen(test_tbl)-1),(test_cnt*(strlen(test_tbl)-1)));

	fclose(rfp1);

}
