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

/*
#include "inc.h"
*/


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

unchar	test_tbl[MOJISU]= {'E','l','l','e','\0',' ','t','r','o','u',
                           'v',0xe9,' ','\0','a','h','a','s','r','a',
                           'h','l','a','\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);
        }

	for(i=0;i<MOJISU;i++){
		if(test_tbl[i]==0x20){
			test_tbl[i]=0x40;
		}
	}

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

        fclose(rfp1);

}
