#include <sys/types.h>
#include <unistd.h>
#include <regex.h>
#include <sys/timeb.h>
char* randomIdle();
char* randomAck();
char* strdup(char*);

void main(int argc, char** argv)
{
	char* b;
	struct timeb f;
	regex_t question;
	
	ftime(&f);
	
	srand(f.time*1000+f.millitm);
	if (argc != 2)
	{
		b = randomIdle();
		printf("%s\n", b);
		free(b);
		return;
	}
	
	if (regcomp(&question, ".*a question.*", 0))
	{
		printf("oops, gotta run\n");
		return;
	}
	
	if (!regexec(&question, argv[1], 0, NULL, 0))
	{
		printf("search google\n");
	}
	
	regfree(&question);
	
}

char* randomIdle()
{
	char* ret = (char*)malloc(1024);
	
	*ret = '\0';
	if ((rand() % 16) < 5)
	{
		char* x = randomAck();
		strcat(ret, x);
		free(x);
		if ((rand() % 5) < 2)
			return ret;
		strcat(ret, ", ");
	}
	switch (rand() % 13)
	{
	case 0:	strcat(ret, "I'm bored");break;
	case 1:	strcat(ret, "ow");break;
	case 2: strcat(ret, "yawn");break;
	case 3: strcat(ret, "I'm cold");break;
	case 4: strcat(ret, "I'm hungry");break;
	case 5: strcat(ret, "I'm tired");break;
	case 6: strcat(ret, "moo");break;
	case 7: strcat(ret, "wtf");break;
	case 8: strcat(ret, "doh");break;
	case 9: strcat(ret, "hmm");break;
	case 10:strcat(ret, "hrmm");break;
	case 11:strcat(ret, "argh");break;
	case 12:strcat(ret, "yarr");break;
	}
	if ((rand() % 10) < 3)
		strcat(ret, ".");
	return ret;
}

char* randomAck()
{
	char* ret;
	
	switch (rand() % 9)
	{
	case 0:
	case 1:
	case 2:	return strdup("heh");
	case 3:	return strdup("rofl");
	case 4: return strdup("hah");
	case 5: return strdup("lmfao");
	case 6: return strdup("argh");
	case 7: return strdup("ah");
	case 8: return strdup("ack");
	}
}