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