1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/tools/gentest/genres32.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* 1.5 +******************************************************************************* 1.6 +* 1.7 +* Copyright (C) 2003-2006, International Business Machines 1.8 +* Corporation and others. All Rights Reserved. 1.9 +* 1.10 +******************************************************************************* 1.11 +* file name: genres32.c 1.12 +* encoding: US-ASCII 1.13 +* tab size: 8 (not used) 1.14 +* indentation:4 1.15 +* 1.16 +* created on: 2003sep10 1.17 +* created by: Markus W. Scherer 1.18 +* 1.19 +* Write an ICU resource bundle with a table whose 1.20 +* number of key characters and number of items both exceed 64k. 1.21 +* Writing it as the root table tests also that 1.22 +* the new table type is recognized for the root resource by the reader code. 1.23 +*/ 1.24 +#include <stdio.h> 1.25 +#include "unicode/putil.h" 1.26 +#include "cstring.h" 1.27 +#include "gentest.h" 1.28 + 1.29 +static void 1.30 +incKey(char *key, char *limit) { 1.31 + char c; 1.32 + 1.33 + while(limit>key) { 1.34 + c=*--limit; 1.35 + if(c=='o') { 1.36 + *limit='1'; 1.37 + break; 1.38 + } else { 1.39 + *limit='o'; 1.40 + } 1.41 + } 1.42 +} 1.43 + 1.44 +U_CFUNC int 1.45 +genres32(const char *prog, const char *path) { 1.46 + /* 1.47 + * key string, gets incremented binary numbers 1.48 + * letter 'o'=0 and digit '1'=1 so that data swapping can be tested 1.49 + * with reordering (ASCII: '1'<'o' EBCDIC: '1'>'o') 1.50 + * 1.51 + * need 17 digits for >64k unique items 1.52 + */ 1.53 + char key[20]="ooooooooooooooooo"; 1.54 + char *limit; 1.55 + int i; 1.56 + char file[512]; 1.57 + FILE *out; 1.58 + 1.59 + uprv_strcpy(file,path); 1.60 + if(file[strlen(file)-1]!=U_FILE_SEP_CHAR) { 1.61 + uprv_strcat(file,U_FILE_SEP_STRING); 1.62 + } 1.63 + uprv_strcat(file,"testtable32.txt"); 1.64 + out = fopen(file, "w"); 1.65 + /*puts(file);*/ 1.66 + puts("Generating testtable32.txt"); 1.67 + if(out == NULL) { 1.68 + fprintf(stderr, "%s: Couldn't create resource test file %s\n", 1.69 + prog, file); 1.70 + return 1; 1.71 + } 1.72 + 1.73 + /* find the limit of the key string */ 1.74 + for(limit=key; *limit!=0; ++limit) { 1.75 + } 1.76 + 1.77 + /* output the beginning of the bundle */ 1.78 + fputs( 1.79 + "testtable32 {", out 1.80 + ); 1.81 + 1.82 + /* output the table entries */ 1.83 + for(i=0; i<66000; ++i) { 1.84 + if(i%10==0) { 1.85 + /* 1.86 + * every 10th entry contains a string with 1.87 + * the entry index as its code point 1.88 + */ 1.89 + fprintf(out, "%s{\"\\U%08x\"}\n", key, i); 1.90 + } else { 1.91 + /* other entries contain their index as an integer */ 1.92 + fprintf(out, "%s:int{%d}\n", key, i); 1.93 + } 1.94 + 1.95 + incKey(key, limit); 1.96 + } 1.97 + 1.98 + /* output the end of the bundle */ 1.99 + fputs( 1.100 + "}", out 1.101 + ); 1.102 + 1.103 + fclose(out); 1.104 + return 0; 1.105 +}