12e5b6d6dSopenharmony_ci// © 2016 and later: Unicode, Inc. and others.
22e5b6d6dSopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html
32e5b6d6dSopenharmony_ci/*
42e5b6d6dSopenharmony_ci*******************************************************************************
52e5b6d6dSopenharmony_ci*
62e5b6d6dSopenharmony_ci*   Copyright (C) 2003-2006, International Business Machines
72e5b6d6dSopenharmony_ci*   Corporation and others.  All Rights Reserved.
82e5b6d6dSopenharmony_ci*
92e5b6d6dSopenharmony_ci*******************************************************************************
102e5b6d6dSopenharmony_ci*   file name:  genres32.c
112e5b6d6dSopenharmony_ci*   encoding:   UTF-8
122e5b6d6dSopenharmony_ci*   tab size:   8 (not used)
132e5b6d6dSopenharmony_ci*   indentation:4
142e5b6d6dSopenharmony_ci*
152e5b6d6dSopenharmony_ci*   created on: 2003sep10
162e5b6d6dSopenharmony_ci*   created by: Markus W. Scherer
172e5b6d6dSopenharmony_ci*
182e5b6d6dSopenharmony_ci*   Write an ICU resource bundle with a table whose
192e5b6d6dSopenharmony_ci*   number of key characters and number of items both exceed 64k.
202e5b6d6dSopenharmony_ci*   Writing it as the root table tests also that
212e5b6d6dSopenharmony_ci*   the new table type is recognized for the root resource by the reader code.
222e5b6d6dSopenharmony_ci*/
232e5b6d6dSopenharmony_ci#include <stdio.h>
242e5b6d6dSopenharmony_ci#include "unicode/putil.h"
252e5b6d6dSopenharmony_ci#include "cstring.h"
262e5b6d6dSopenharmony_ci#include "gentest.h"
272e5b6d6dSopenharmony_ci
282e5b6d6dSopenharmony_cistatic void
292e5b6d6dSopenharmony_ciincKey(char *key, char *limit) {
302e5b6d6dSopenharmony_ci    char c;
312e5b6d6dSopenharmony_ci
322e5b6d6dSopenharmony_ci    while(limit>key) {
332e5b6d6dSopenharmony_ci        c=*--limit;
342e5b6d6dSopenharmony_ci        if(c=='o') {
352e5b6d6dSopenharmony_ci            *limit='1';
362e5b6d6dSopenharmony_ci            break;
372e5b6d6dSopenharmony_ci        } else {
382e5b6d6dSopenharmony_ci            *limit='o';
392e5b6d6dSopenharmony_ci        }
402e5b6d6dSopenharmony_ci    }
412e5b6d6dSopenharmony_ci}
422e5b6d6dSopenharmony_ci
432e5b6d6dSopenharmony_ciU_CFUNC int
442e5b6d6dSopenharmony_cigenres32(const char *prog, const char *path) {
452e5b6d6dSopenharmony_ci    /*
462e5b6d6dSopenharmony_ci     * key string, gets incremented binary numbers
472e5b6d6dSopenharmony_ci     * letter 'o'=0 and digit '1'=1 so that data swapping can be tested
482e5b6d6dSopenharmony_ci     * with reordering (ASCII: '1'<'o' EBCDIC: '1'>'o')
492e5b6d6dSopenharmony_ci     *
502e5b6d6dSopenharmony_ci     * need 17 digits for >64k unique items
512e5b6d6dSopenharmony_ci     */
522e5b6d6dSopenharmony_ci    char key[20]="ooooooooooooooooo";
532e5b6d6dSopenharmony_ci    char *limit;
542e5b6d6dSopenharmony_ci    int i;
552e5b6d6dSopenharmony_ci    char file[512];
562e5b6d6dSopenharmony_ci    FILE *out;
572e5b6d6dSopenharmony_ci
582e5b6d6dSopenharmony_ci    uprv_strcpy(file,path);
592e5b6d6dSopenharmony_ci    if(file[strlen(file)-1]!=U_FILE_SEP_CHAR) {
602e5b6d6dSopenharmony_ci        uprv_strcat(file,U_FILE_SEP_STRING);
612e5b6d6dSopenharmony_ci    }
622e5b6d6dSopenharmony_ci    uprv_strcat(file,"testtable32.txt");
632e5b6d6dSopenharmony_ci    out = fopen(file, "w");
642e5b6d6dSopenharmony_ci    /*puts(file);*/
652e5b6d6dSopenharmony_ci    puts("Generating testtable32.txt");
662e5b6d6dSopenharmony_ci    if(out == NULL) {
672e5b6d6dSopenharmony_ci        fprintf(stderr, "%s: Couldn't create resource test file %s\n",
682e5b6d6dSopenharmony_ci                prog, file);
692e5b6d6dSopenharmony_ci        return 1;
702e5b6d6dSopenharmony_ci    }
712e5b6d6dSopenharmony_ci
722e5b6d6dSopenharmony_ci    /* find the limit of the key string */
732e5b6d6dSopenharmony_ci    for(limit=key; *limit!=0; ++limit) {
742e5b6d6dSopenharmony_ci    }
752e5b6d6dSopenharmony_ci
762e5b6d6dSopenharmony_ci    /* output the beginning of the bundle */
772e5b6d6dSopenharmony_ci    fputs(
782e5b6d6dSopenharmony_ci          "testtable32 {", out
792e5b6d6dSopenharmony_ci    );
802e5b6d6dSopenharmony_ci
812e5b6d6dSopenharmony_ci    /* output the table entries */
822e5b6d6dSopenharmony_ci    for(i=0; i<66000; ++i) {
832e5b6d6dSopenharmony_ci        if(i%10==0) {
842e5b6d6dSopenharmony_ci            /*
852e5b6d6dSopenharmony_ci             * every 10th entry contains a string with
862e5b6d6dSopenharmony_ci             * the entry index as its code point
872e5b6d6dSopenharmony_ci             */
882e5b6d6dSopenharmony_ci            fprintf(out, "%s{\"\\U%08x\"}\n", key, i);
892e5b6d6dSopenharmony_ci        } else {
902e5b6d6dSopenharmony_ci            /* other entries contain their index as an integer */
912e5b6d6dSopenharmony_ci            fprintf(out, "%s:int{%d}\n", key, i);
922e5b6d6dSopenharmony_ci        }
932e5b6d6dSopenharmony_ci
942e5b6d6dSopenharmony_ci        incKey(key, limit);
952e5b6d6dSopenharmony_ci    }
962e5b6d6dSopenharmony_ci
972e5b6d6dSopenharmony_ci    /* output the end of the bundle */
982e5b6d6dSopenharmony_ci    fputs(
992e5b6d6dSopenharmony_ci          "}", out
1002e5b6d6dSopenharmony_ci    );
1012e5b6d6dSopenharmony_ci
1022e5b6d6dSopenharmony_ci    fclose(out);
1032e5b6d6dSopenharmony_ci    return 0;
1042e5b6d6dSopenharmony_ci}
105