#include <stdio.h>
#include <stdlib.h>
#include <xmms/plugin.h>
#include <string.h>

#include "xmmsgcc.h"

VisPlugin xgcc_vtable = {
	0, //Handle
	0, //Filename

	0, //Session ID
	"XMMS-GCC Plugin", //Description

	0, //PCM channels used for render_pcm
	1, //PCM channels used for render_freq

	xgcc_init,
	xgcc_cleanup,
	xgcc_about,
	xgcc_configure,
	0, //Disable plugin
	xgcc_start,
	xgcc_stop,
	0, //Render PCM data
	xgcc_render_freq //Render freq data
};


//XMMS entry
VisPlugin *get_vplugin_info(void) {

	return &xgcc_vtable;

}


static void xgcc_init(void) {

}


static void xgcc_cleanup(void) {

}


static void xgcc_about(void) {

}


static void xgcc_configure(void) {

}


static void xgcc_start(void) {

	int i;

	printf("checking build system type... i686-pc-linux-gnu \n" \
		"checking host system type... i686-pc-linux-gnu \n" \
		"checking target system type... i686-pc-linux-gnu \n" \
		"checking for a BSD-compatible install... /usr/bin/install -c \n" \
		"checking whether build environment is sane... yes\n" \
		"checking whether make sets $(MAKE)... yes\n" \
		"checking for working aclocal-1.4... found\n" \
		"checking for working autoconf... found\n" \
		"checking for working automake-1.4... found\n" \
		"checking for working autoheader... found\n" \
		"checking for working makeinfo... found\n" \
		"checking for gcc... gcc\n" \
		"checking for C compiler default output file name... a.out\n" \
		"checking whether the C compiler works... yes\n" \
		"checking whether we are cross compiling... no\n" \
		"checking for suffix of executables...\n" \
		"checking for suffix of object files... o\n" \
		"checking whether we are using the GNU C compiler... yes\n" \
		"checking whether gcc accepts -g... yes\n" \
		"checking for gcc option to accept ANSI C... none needed\n" \
		"checking how to run the C preprocessor... gcc -E\n" \
		"checking for gcc option to accept ANSI C... none needed\n" \
		"checking for egrep... grep -E\n" \
		"checking for ANSI C header files... yes\n" \
		"checking for a BSD-compatible install... /usr/bin/install -c\n" \
		"checking for a sed that does not truncate output... /bin/sed\n" \
		"checking for ld used by gcc... /usr/bin/ld\n" \
		"checking if the linker (/usr/bin/ld) is GNU ld... yes\n" \
		"checking for /usr/bin/ld option to reload object files... -r\n" \
		"checking for BSD-compatible nm... /usr/bin/nm -B\n" \
		"checking whether ln -s works... yes\n" \
		"checking how to recognise dependent libraries... pass_all\n" \
		"checking for sys/types.h... yes\n" \
		"checking for sys/stat.h... yes\n" \
		"checking for stdlib.h... yes\n" \
		"checking for string.h... yes\n" \
		"checking for memory.h... yes\n" \
		"checking for strings.h... yes\n" \
		"checking for inttypes.h... yes\n" \
		"checking for stdint.h... yes\n" \
		"checking for unistd.h... yes\n" \
		"checking dlfcn.h usability... yes\n" \
		"checking dlfcn.h presence... yes\n" \
		"checking for dlfcn.h... yes\n");

}


static void xgcc_stop(void) {

}


static void xgcc_render_freq(gint16 freq_data[2][256]) {

	int channel, bucket, i;
	long long diff, average = 0, total = 0;
	
	for(channel = 0; channel < 2; channel++) {
		for(bucket = 0; bucket < 256; bucket++) {
			total += freq_data[channel][bucket];
		}
	}

	for(i = 0; i < 29; i++) {
		last_thirty[i] = last_thirty[i + 1];
	}
	last_thirty[29] = total;

	for(i = 0; i < 30; i++) {
		average += last_thirty[i];
	}
	average /= 30;

	diff = total - average;
	
	if(diff > 1000) {
		printgcc(diff);
	}

}


static void printgcc(int value) {

	switch(value / 5000) {
		case 0:
			//printf("/bin/sh if\n");
			//break;
		case 1:
			printf("[warning] singer stoned.\n");
			break;
		case 2:
			printf("ld artists.o studio.o mixer.o -o album\n");
			break;
		case 4:
			printf("make[1]: Nothing to be done for `your-taste-in-music'.\n");
			break;
		case 5:
			printf("[warning] speakers are deprecated in favour of livePerformance\n");
			break;
		case 6:
			printf("then mv .deps/roadie.Po .dpes/bar.Tpo; else rm -f .deps/roadie.Po; fi\n");
			break;
		case 7:
			printf("make[1]: Entering directory `/mount/network/woodstock/xmmsgcc/sex_drugs_rocknroll/'\n");
			break;
		case 8:
			printf("gcc -D_LINUX -Wall -c something.c -o somethingelse -Leardrums -Laudio -Lspeakers -funroll-loops -O 2 -g\n");
			break;
		case 9:
			printf("g++ -c laser_show.c -o laser_show -LSDL -LGL -LGLU -D_LINUX -Wall -g -I/usr/include/SDL -I/usr/include/GL -O 0 -D_PRETTY_LIGHTS\n");
			break;
		case 10:
			printf("/bin/sh ./libtool --mode=compile gcc -DHAVE_CONFIG_H -Wall -I/usr/include/xmms -I/usr/lib/glib/include -I/usr/X11R6/include -g -c gig.c -o audience.o\n");
			break;
		default:
			printf("gcc -shared .libs/xmmsgcc.o -L/usr/X11R6/lib /usr/lib/libgtk.so /usr/lib/libglib.so -ldl -lXi -lXext -lX11 -lm /usr/lib/libxmms.so  -Wl,-soname -o .libs/libxmmsgcc.so\n");
			break;
	}

}

