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