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



void usage(void){
	printf("\tUsage: print-chars [output] [input]\n");


	exit(1);
}


/*

struct translation_structure{
        //char tablestr[100];

	unsigned char series[100];	
        unsigned char a;
        unsigned char b;

	

}table[]={
        //256 entire char set
        {"", 0, 0},
        {"", 0, 1},
        {"", 0, 2},
        {"3", 3},
        {"4", 4},
        {"5", 5},
        {"6", 6},
        {"7", 7},  
        {"8", 8},
        {"9", 9},
        {"10", 10},
};


*/




int main(int argc, char **argv){
	FILE *output;
	FILE *input;
	int character;
	int counter1, counter2;
	int lines = 0;
	int num1, num2, num3;
	int set = 1;
	char outstr[100];
	char linestring[100];
	if(argc != 3){
		usage();
		//printf("error\n");
		//exit(1);
	}

        //outstr = (char *)malloc( strlen(argv[2])*sizeof(char) );
        //(void)sprintf(input_file, "%s", argv[2]);
	
	char semicolon = 59;
	char string1[100];

	output = fopen(argv[1], "w");

	
        if( ( input = fopen( argv[2], "r" ) ) == NULL ) {
                fprintf( stderr, "Error opening %s\n", argv[2] );
                exit( 1 );
        }

        while( fgets(linestring, sizeof(linestring), input) != NULL)
        {       
		lines++;
	}
	fclose(input);

	//strcpy("struct", string1);
	fprintf(output, "struct translation_structure{\n");
	fprintf(output, "\tunsigned char *series%c\n", semicolon);
	fprintf(output, "\tunsigned char a%c\n", semicolon);
	fprintf(output, "\tunsigned char b%c\n", semicolon);
	fprintf(output, "}table[]={\n");

	
	num1 = 0;
	num2 = 100;
	num3 = 0;
	counter1=25600;


        if( ( input = fopen( argv[2], "r" ) ) == NULL ) {
                fprintf( stderr, "Error opening %s\n", argv[2] );
                exit( 1 );
        }

	
        while( fgets(linestring, sizeof(linestring), input) != NULL && counter1 < 65536)
        {

		strcpy(outstr, linestring);
		outstr[strlen(outstr)-1]='\0';
		num3++;
		//39926 //156
		//for(counter1=25600; counter1<65536; counter1++){

		if(num3 != lines){
			fprintf(output, "\t{\"%s\", %d, %d},\n", outstr, num1, num2 );
		}else{
			fprintf(output, "\t{\"%s\", %d, %d}\n", outstr, num1, num2 );
		}
		//}
		counter1++;
		if(num1 == 255){
			num1 = 0;
			num2++;
		}else{
			num1++;
		}	
	}
	
	
	fprintf(output, "}%c\n", semicolon);

	fclose(input);
	fclose(output);



return 0;
}
