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


void usage(void){
	printf("\n\tlsa-file [output file] [input file]\n\n");

}

struct custom{
        unsigned word : 12;
};

//struct custom long_char;

//char *table[4096];

struct translation_structure{
	char instring[16];
	unsigned longchar : 12;

}table[]={
	//256 entire char set
	{"0", 0},
	{"1", 1},
	{"2", 2},
	{"3", 3},
	{"4", 4},
	{"5", 5},
	{"6", 6},
	{"7", 7},
	{"8", 8},
	{"9", 9},
	{"10", 10},
	{"01210288110934", 11}
	//2048 repeats of all chars up to 8x
	
	//1792 common sequences
};


/*
static struct long_char table_lookup(char *string){

	struct long_char return_val;
	int element = 0;
	while(element < 4096){
 		if( strcmp(sting, table[element]) ){
			return_val.word = element;
		}

	}


}





int pattern_match(char current_char){

	static char last_char;
	if( strcmp(last_char, current_char) == 0){
		
		return((int)1);
	}else{
		
		return((int)0);
	}


}
*/

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

	char *input_file;
	char *output_file;
	FILE *file_handle1;
	FILE *file_handle2;
	int counter1, counter2;
	char character[16];
	struct custom long_char;

	if(argc != 3){
		usage();
		exit(1);
	}else{
		input_file = (char *)malloc( strlen(argv[2])*sizeof(char) );
		output_file = (char *)malloc( strlen(argv[1])*sizeof(char) );

		//input_file = (const char *)calloc(strlen(argv[1]), sizeof(char));
		//output_file = (const char *)calloc(strlen(argv[2]), sizeof(char));
		//strcpy(input_file, argv[1]);
		//strcpy(output_file, argv[2]);
		(void)sprintf(input_file, "%s", argv[2]);
		(void)sprintf(output_file, "%s", argv[1]);

		//input_file = argv[1];
		//output_file = argv[2];

	}

	printf("input_file: %s %d %d\n", input_file, (int)strlen(argv[2]), (int)strlen(input_file));
	printf("output_file: %s %d %d\n", output_file, (int)strlen(argv[1]), (int)strlen(output_file));

                file_handle1 = fopen(input_file , "r");
                if(file_handle1 != NULL){  

			file_handle2 = fopen(output_file,"w");
			if(file_handle2 != NULL){        

				for(counter2=0; counter2 < 16 && character[counter2] != EOF; counter2++){
					character[counter2]=getc(file_handle1);
				}

				//counter2 = 0;
				//for(character[0]=getc(file_handle1); character[0] != EOF; character[0]=getc(file_handle1)){
				//	counter2++;
				//}
				//printf("input file is %d Bytes\n", counter2);

				//if(counter2 > 15){
					//character=getc(file_handle1);
					
					for(counter1=0; counter1<11; counter1++){
						if( table[counter1].instring[0] == character ){
							printf("match");
							long_char.word = table[counter1].longchar;
							//fprintf(file_handle2, "%c", long_char.word);
						}
					}
					//printf("writing");
                                	fprintf(file_handle2, "%c", long_char.word);                                
				                        		
				
				//}

				fclose(file_handle1);
                        	fclose(file_handle2);
			}else{
				printf("error opening output file!\n");
				exit(1);
			}
                }else{
			printf("error opening input file!\n");
			exit(1);
		}



	return 0;
}
