
/* testj.c by Kev Vance -- based on sensei by Myth */

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

//#define random(x) (rand()%(x))

char *syls[] =
{"ka", "ga", "sa", "za", "ta",
 "da", "na", "ha", "ba", "pa", "ma", "ra", "wa",
 "ki", "gi", "shi", "ji", "chi",
 "ji", "ni", "hi", "bi", "pi", "mi", "ri", "wo",
 "ku", "gu", "su", "zu", "tsu",
 "zu", "nu", "fu", "bu", "pu", "mu", "ru",
 "ke", "ge", "se", "ze", "te",
 "de", "ne", "he", "be", "pe", "me", "re",
 "ko", "go", "so", "zo", "to",
 "do", "no", "ho", "bo", "po", "mo", "ro",
 "ya", "ya", "kya", "gya", "sha", "ja", "cha",
 "ja", "nya", "hya", "bya", "pya", "mya", "rya",
 "yu", "yu", "kyu", "gyu", "shu", "ju", "chu",
 "ju", "nyu", "hyu", "byu", "pyu", "myu", "ryu",
 "yo", "yo", "kyo", "gyo", "sho", "jo", "cho",
 "jo", "nyo", "hyo", "byo", "pyo", "myo", "ryo"};

int main(int argc, char *argv[])
{

	int wordcnt = 0, spaces = 0;
	time_t t;
	int i, x;
	char *string = (char *) malloc(255);
	char *copr = "Testj by Kev Vance -- like nonsensei by Myth, but backwards.";
	string[0] = '\0';

	printf("%s\nType your string to testanalyze...\n > ", copr);
	gets(string);

	if (string[0] == '\0') {
		printf("\nTry typing a string :)    ...or should I say ^_^");
		exit(0);
	}
	for (i = 0; i < strlen(string); i++)
		if (string[i] == ' ')
			spaces++;

	for (i = 0; i < strlen(string); i++)
		if (string[i] == 'x' | string[i] == 'X')
			wordcnt -= strlen(string) / 2;

	for (i = 0; i < 104; i++)
		if (strstr(string, syls[i]))
			wordcnt += strlen(syls[i]);

	if ((wordcnt * 100) / (strlen(string) - spaces) >= 40)
		printf("\nString is japanese.\n");
	else
		printf("\nString is not japanese.\n");

	free(string);

	exit(0);
}
