]> git.saurik.com Git - apple/icu.git/blob - icuSources/tools/gentest/genres32.c
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / tools / gentest / genres32.c
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 *
6 * Copyright (C) 2003-2006, International Business Machines
7 * Corporation and others. All Rights Reserved.
8 *
9 *******************************************************************************
10 * file name: genres32.c
11 * encoding: UTF-8
12 * tab size: 8 (not used)
13 * indentation:4
14 *
15 * created on: 2003sep10
16 * created by: Markus W. Scherer
17 *
18 * Write an ICU resource bundle with a table whose
19 * number of key characters and number of items both exceed 64k.
20 * Writing it as the root table tests also that
21 * the new table type is recognized for the root resource by the reader code.
22 */
23 #include <stdio.h>
24 #include "unicode/putil.h"
25 #include "cstring.h"
26 #include "gentest.h"
27
28 static void
29 incKey(char *key, char *limit) {
30 char c;
31
32 while(limit>key) {
33 c=*--limit;
34 if(c=='o') {
35 *limit='1';
36 break;
37 } else {
38 *limit='o';
39 }
40 }
41 }
42
43 U_CFUNC int
44 genres32(const char *prog, const char *path) {
45 /*
46 * key string, gets incremented binary numbers
47 * letter 'o'=0 and digit '1'=1 so that data swapping can be tested
48 * with reordering (ASCII: '1'<'o' EBCDIC: '1'>'o')
49 *
50 * need 17 digits for >64k unique items
51 */
52 char key[20]="ooooooooooooooooo";
53 char *limit;
54 int i;
55 char file[512];
56 FILE *out;
57
58 uprv_strcpy(file,path);
59 if(file[strlen(file)-1]!=U_FILE_SEP_CHAR) {
60 uprv_strcat(file,U_FILE_SEP_STRING);
61 }
62 uprv_strcat(file,"testtable32.txt");
63 out = fopen(file, "w");
64 /*puts(file);*/
65 puts("Generating testtable32.txt");
66 if(out == NULL) {
67 fprintf(stderr, "%s: Couldn't create resource test file %s\n",
68 prog, file);
69 return 1;
70 }
71
72 /* find the limit of the key string */
73 for(limit=key; *limit!=0; ++limit) {
74 }
75
76 /* output the beginning of the bundle */
77 fputs(
78 "testtable32 {", out
79 );
80
81 /* output the table entries */
82 for(i=0; i<66000; ++i) {
83 if(i%10==0) {
84 /*
85 * every 10th entry contains a string with
86 * the entry index as its code point
87 */
88 fprintf(out, "%s{\"\\U%08x\"}\n", key, i);
89 } else {
90 /* other entries contain their index as an integer */
91 fprintf(out, "%s:int{%d}\n", key, i);
92 }
93
94 incKey(key, limit);
95 }
96
97 /* output the end of the bundle */
98 fputs(
99 "}", out
100 );
101
102 fclose(out);
103 return 0;
104 }