File:  [ELWIX - Embedded LightWeight unIX -] / gpl / axl / test / gen-table.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 8 07:09:12 2011 UTC (13 years, 4 months ago) by misho
Branches: axl, MAIN
CVS tags: HEAD, AXL0_6_7, AXL0_6_1
3th party - XML

    1: #include <stdio.h>
    2: 
    3: int main (int argc, char ** argv)
    4: {
    5: 	FILE * file;
    6: 	FILE * file2;
    7: 	char   buffer[2];
    8: 	char   buffer2[4];
    9: 	int    iterator;
   10: 
   11: 	if (argc != 3) {
   12: 		printf ("Please provide two files ORIGINAL and UTF-8-TRANSLATE..\n");
   13: 		return -1;
   14: 	}
   15: 
   16: 	file = fopen (argv[1], "r");
   17: 	if (file == NULL) {
   18: 		printf ("failed to open: %s..\n", argv[1]);
   19: 		return -1;
   20: 	}
   21: 
   22: 	file2 = fopen (argv[2], "r");
   23: 	if (file2 == NULL) {
   24: 		printf ("failed to open: %s..\n", argv[2]);
   25: 		return -1;
   26: 	}
   27: 	
   28: 	/* foreach item at the original array do */
   29: 	iterator = 0;
   30: 	while (fread (buffer, 1, 1, file) == 1) {
   31: 
   32: 		/* read the terminator */
   33: 		if (fread (&(buffer[1]), 1, 1, file) != 1) {
   34: 			break;
   35: 		}
   36: 		 
   37: 		if (buffer[1] != '\n') {
   38: 			printf ("Expected to find new line character at=%d..\n", iterator);
   39: 			return -1;
   40: 		}   
   41: 
   42: 
   43: 		if (fread (buffer2, 1, 1, file2) != 1) {
   44: 			printf ("failed to read utf-8 file (while handling buffer[0]='%c' (%u)..\n", iterator, buffer[0], (unsigned char) buffer[0]);
   45: 			return -1;
   46: 		} /* end if */
   47: 
   48: 		if (fread (&(buffer2[1]), 1, 1, file2) != 1) {
   49: 			printf ("failed to read utf-8 file (while handling buffer[0]='%c'..\n", iterator);
   50: 			return -1;
   51: 		} /* end if */
   52: 
   53: 		if (buffer2[1] == '\n') {
   54: 			printf ("/* store item associated to code %d */\n", iterator);
   55: 			printf ("table[%d].size      = 1;\n", iterator);
   56: 			printf ("table[%d].buffer[0] = (unsigned char) %d; /* 0x%x */\n\n", iterator, (unsigned char) iterator, (unsigned char) iterator);
   57: 			iterator++;
   58: 			continue;
   59: 		}
   60: 
   61: 		if (fread (&(buffer2[2]), 1, 1, file2) != 1) {
   62: 			printf ("failed to read utf-8 file (2 type unit)..\n");
   63: 			return -1;
   64: 		} /* end if */
   65: 		
   66: 		if (buffer2[2] == '\n') {
   67: 			printf ("/* store item associated to code %d */\n", iterator);
   68: 			printf ("table[%d].size      = 2;\n", iterator);
   69: 			printf ("table[%d].buffer[0] = (unsigned char) %u; /* 0x%x */\n", iterator, (unsigned char) buffer2[0], (unsigned char) buffer2[0]);
   70: 			printf ("table[%d].buffer[1] = (unsigned char) %u; /* 0x%x */\n\n", iterator, (unsigned char) buffer2[1], (unsigned char) buffer2[1]);
   71: 			iterator++;
   72: 			continue;
   73: 		}
   74: 
   75: 		if (fread (&(buffer2[3]), 1, 1, file2) != 1) {
   76: 			printf ("failed to read utf-8 file (3 type unit)..\n");
   77: 			return -1;
   78: 		} /* end if */
   79: 
   80: 		printf ("/* store item associated to code %d */\n", iterator);
   81: 		printf ("table[%d].size      = 3;\n", iterator);
   82: 		printf ("table[%d].buffer[0] = (unsigned char) %u; /* 0x%x */\n",   iterator, (unsigned char) buffer2[0], (unsigned char) buffer2[0]);
   83: 		printf ("table[%d].buffer[1] = (unsigned char) %u; /* 0x%x */\n",   iterator, (unsigned char) buffer2[1], (unsigned char) buffer2[1]);
   84: 		printf ("table[%d].buffer[2] = (unsigned char) %u; /* 0x%x */\n\n", iterator, (unsigned char) buffer2[2], (unsigned char) buffer2[2]);
   85: 		iterator++;
   86: 		continue;
   87: 		
   88: 	}
   89: 	fclose (file);
   90: 	return 0;
   91: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>