1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*******************************************************************************
3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius*   Copyright (C) 2003-2012, International Business Machines
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   Corporation and others.  All Rights Reserved.
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*******************************************************************************
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   file name:  gensprep.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: 2003-02-06
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   created by: Ram Viswanadha
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   This program reads the Profile.txt files,
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   parses them, and extracts the data for StringPrep profile.
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   It then preprocesses it and writes a binary file for efficient use
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   in various StringPrep conversion processes.
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define USPREP_TYPE_NAMES_ARRAY 1
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h>
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h>
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cmemory.h"
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cstring.h"
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unewdata.h"
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uoptions.h"
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uparse.h"
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "sprpimpl.h"
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
3454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#include "unicode/uclean.h"
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/udata.h"
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/putil.h"
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CDECL_BEGIN
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "gensprep.h"
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CDECL_END
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUBool beVerbose=FALSE, haveCopyright=TRUE;
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define NORM_CORRECTIONS_FILE_NAME "NormalizationCorrections.txt"
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
4885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#define NORMALIZE_DIRECTIVE "normalize"
4985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#define NORMALIZE_DIRECTIVE_LEN 9
5085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#define CHECK_BIDI_DIRECTIVE "check-bidi"
5185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#define CHECK_BIDI_DIRECTIVE_LEN 10
5285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* prototypes --------------------------------------------------------------- */
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruparseMappings(const char *filename, UBool reportError, UErrorCode *pErrorCode);
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruparseNormalizationCorrections(const char *filename, UErrorCode *pErrorCode);
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* -------------------------------------------------------------------------- */
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UOption options[]={
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UOPTION_HELP_H,
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UOPTION_HELP_QUESTION_MARK,
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UOPTION_VERBOSE,
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UOPTION_COPYRIGHT,
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UOPTION_DESTDIR,
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UOPTION_SOURCEDIR,
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UOPTION_ICUDATADIR,
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UOPTION_BUNDLE_NAME,
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    { "normalization", NULL, NULL, NULL, 'n', UOPT_REQUIRES_ARG, 0 },
7485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    { "norm-correction", NULL, NULL, NULL, 'm', UOPT_REQUIRES_ARG, 0 },
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    { "check-bidi", NULL, NULL, NULL,  'k', UOPT_NO_ARG, 0},
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    { "unicode", NULL, NULL, NULL, 'u', UOPT_REQUIRES_ARG, 0 },
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruenum{
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    HELP,
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    HELP_QUESTION_MARK,
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    VERBOSE,
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    COPYRIGHT,
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    DESTDIR,
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    SOURCEDIR,
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ICUDATADIR,
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    BUNDLE_NAME,
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    NORMALIZE,
8985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    NORM_CORRECTION_DIR,
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    CHECK_BIDI,
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UNICODE_VERSION
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int printHelp(int argc, char* argv[]){
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Broken into chucks because the C89 standard says the minimum
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * required supported string length is 509 bytes.
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fprintf(stderr,
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "Usage: %s [-options] [file_name]\n"
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\n"
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "Read the files specified and\n"
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "create a binary file [package-name]_[bundle-name]." DATA_TYPE " with the StringPrep profile data\n"
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\n",
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        argv[0]);
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fprintf(stderr,
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "Options:\n"
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\t-h or -? or --help       print this usage text\n"
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\t-v or --verbose          verbose output\n"
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\t-c or --copyright        include a copyright notice\n");
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fprintf(stderr,
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\t-d or --destdir          destination directory, followed by the path\n"
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\t-s or --sourcedir        source directory of ICU data, followed by the path\n"
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\t-b or --bundle-name      generate the ouput data file with the name specified\n"
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\t-i or --icudatadir       directory for locating any needed intermediate data files,\n"
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\t                         followed by path, defaults to %s\n",
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_getDataDirectory());
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fprintf(stderr,
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\t-n or --normalize        turn on the option for normalization and include mappings\n"
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\t                         from NormalizationCorrections.txt from the given path,\n"
12185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        "\t                         e.g: /test/icu/source/data/unidata\n");
12285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    fprintf(stderr,
12385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        "\t-m or --norm-correction  use NormalizationCorrections.txt from the given path\n"
12485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        "\t                         when the input file contains a normalization directive.\n"
12585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        "\t                         unlike -n/--normalize, this option does not force the\n"
12685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        "\t                         normalization.\n");
12785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    fprintf(stderr,
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\t-k or --check-bidi       turn on the option for checking for BiDi in the profile\n"
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\t-u or --unicode          version of Unicode to be used with this profile followed by the version\n"
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        );
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruextern int
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querumain(int argc, char* argv[]) {
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_IDNA
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char* filename = NULL;
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *srcDir=NULL, *destDir=NULL, *icuUniDataDir=NULL;
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *bundleName=NULL, *inputFileName = NULL;
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *basename=NULL;
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t sprepOptions = 0;
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode=U_ZERO_ERROR;
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    U_MAIN_INIT_ARGS(argc, argv);
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* preset then read command line options */
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    options[DESTDIR].value=u_getDataDirectory();
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    options[SOURCEDIR].value="";
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    options[UNICODE_VERSION].value="0"; /* don't assume the unicode version */
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    options[BUNDLE_NAME].value = DATA_NAME;
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    options[NORMALIZE].value = "";
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* error handling, printing usage message */
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(argc<0) {
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fprintf(stderr,
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "error in command line argument \"%s\"\n",
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            argv[-argc]);
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(argc<0 || options[HELP].doesOccur || options[HELP_QUESTION_MARK].doesOccur) {
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return printHelp(argc, argv);
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* get the options values */
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    beVerbose=options[VERBOSE].doesOccur;
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    haveCopyright=options[COPYRIGHT].doesOccur;
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    srcDir=options[SOURCEDIR].value;
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    destDir=options[DESTDIR].value;
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    bundleName = options[BUNDLE_NAME].value;
17585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if(options[NORMALIZE].doesOccur) {
17685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        icuUniDataDir = options[NORMALIZE].value;
17785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    } else {
17885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        icuUniDataDir = options[NORM_CORRECTION_DIR].value;
17985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(argc<2) {
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* print the help message */
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return printHelp(argc, argv);
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        inputFileName = argv[1];
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(!options[UNICODE_VERSION].doesOccur){
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return printHelp(argc, argv);
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(options[ICUDATADIR].doesOccur) {
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_setDataDirectory(options[ICUDATADIR].value);
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if UCONFIG_NO_IDNA
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fprintf(stderr,
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "gensprep writes dummy " U_ICUDATA_NAME "_" DATA_NAME "." DATA_TYPE
197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        " because UCONFIG_NO_IDNA is set, \n"
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "see icu/source/common/unicode/uconfig.h\n");
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    generateData(destDir, bundleName);
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#else
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    setUnicodeVersion(options[UNICODE_VERSION].value);
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    filename = (char* ) uprv_malloc(uprv_strlen(srcDir) + 300); /* hopefully this should be enough */
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* prepare the filename beginning with the source dir */
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(uprv_strchr(srcDir,U_FILE_SEP_CHAR) == NULL && uprv_strchr(srcDir,U_FILE_ALT_SEP_CHAR) == NULL){
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        filename[0] = '.';
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        filename[1] = U_FILE_SEP_CHAR;
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uprv_strcpy(filename+2,srcDir);
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }else{
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uprv_strcpy(filename, srcDir);
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    basename=filename+uprv_strlen(filename);
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(basename>filename && *(basename-1)!=U_FILE_SEP_CHAR) {
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        *basename++=U_FILE_SEP_CHAR;
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* initialize */
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    init();
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* process the file */
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uprv_strcpy(basename,inputFileName);
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    parseMappings(filename,FALSE, &errorCode);
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode)) {
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fprintf(stderr, "Could not open file %s for reading. Error: %s \n", filename, u_errorName(errorCode));
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return errorCode;
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
23185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if(options[NORMALIZE].doesOccur){ /* this option might be set by @normalize;; in the source file */
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* set up directory for NormalizationCorrections.txt */
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uprv_strcpy(filename,icuUniDataDir);
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        basename=filename+uprv_strlen(filename);
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(basename>filename && *(basename-1)!=U_FILE_SEP_CHAR) {
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            *basename++=U_FILE_SEP_CHAR;
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        *basename++=U_FILE_SEP_CHAR;
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uprv_strcpy(basename,NORM_CORRECTIONS_FILE_NAME);
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        parseNormalizationCorrections(filename,&errorCode);
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(errorCode)){
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            fprintf(stderr,"Could not open file %s for reading \n", filename);
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return errorCode;
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sprepOptions |= _SPREP_NORMALIZATION_ON;
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
25085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if(options[CHECK_BIDI].doesOccur){ /* this option might be set by @check-bidi;; in the source file */
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sprepOptions |= _SPREP_CHECK_BIDI_ON;
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    setOptions(sprepOptions);
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* process parsed data */
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(errorCode)) {
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* write the data file */
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        generateData(destDir, bundleName);
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        cleanUpData();
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uprv_free(filename);
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
26654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    u_cleanup();
26754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return errorCode;
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_IDNA
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void U_CALLCONV
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerunormalizationCorrectionsLineFn(void *context,
277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    char *fields[][2], int32_t fieldCount,
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    UErrorCode *pErrorCode) {
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t mapping[40];
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *end, *s;
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t code;
282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t length;
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UVersionInfo version;
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UVersionInfo thisVersion;
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* get the character code, field 0 */
287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    code=(uint32_t)uprv_strtoul(fields[0][0], &end, 16);
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(*pErrorCode)) {
289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fprintf(stderr, "gensprep: error parsing NormalizationCorrections.txt mapping at %s\n", fields[0][0]);
290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        exit(*pErrorCode);
291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Original (erroneous) decomposition */
293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    s = fields[1][0];
294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* parse the mapping string */
296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    length=u_parseCodePoints(s, mapping, sizeof(mapping)/4, pErrorCode);
297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* ignore corrected decomposition */
299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_versionFromString(version,fields[3][0] );
301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_versionFromString(thisVersion, "3.2.0");
302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(*pErrorCode)) {
306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fprintf(stderr, "gensprep error parsing NormalizationCorrections.txt of U+%04lx - %s\n",
307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                (long)code, u_errorName(*pErrorCode));
308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        exit(*pErrorCode);
309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* store the mapping */
312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if( version[0] > thisVersion[0] ||
313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ((version[0]==thisVersion[0]) && (version[1] > thisVersion[1]))
314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ){
315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        storeMapping(code,mapping, length, USPREP_MAP, pErrorCode);
316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    setUnicodeVersionNC(version);
318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruparseNormalizationCorrections(const char *filename, UErrorCode *pErrorCode) {
322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *fields[4][2];
323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_parseDelimitedFile(filename, ';', fields, 4, normalizationCorrectionsLineFn, NULL, pErrorCode);
329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* fprintf(stdout,"Number of code points that have NormalizationCorrections mapping with length >1 : %i\n",len); */
331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(*pErrorCode) && ( *pErrorCode!=U_FILE_ACCESS_ERROR)) {
333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fprintf(stderr, "gensprep error: u_parseDelimitedFile(\"%s\") failed - %s\n", filename, u_errorName(*pErrorCode));
334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        exit(*pErrorCode);
335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void U_CALLCONV
339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerustrprepProfileLineFn(void *context,
340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru              char *fields[][2], int32_t fieldCount,
341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru              UErrorCode *pErrorCode) {
342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t mapping[40];
343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *end, *map;
344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t code;
345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t length;
346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   /*UBool* mapWithNorm = (UBool*) context;*/
347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* typeName;
348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t rangeStart=0,rangeEnd =0;
349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* filename = (const char*) context;
35085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    const char *s;
35185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
35285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    s = u_skipWhitespace(fields[0][0]);
35385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (*s == '@') {
35485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* special directive */
35585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        s++;
35685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        length = fields[0][1] - s;
35785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (length >= NORMALIZE_DIRECTIVE_LEN
35885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            && uprv_strncmp(s, NORMALIZE_DIRECTIVE, NORMALIZE_DIRECTIVE_LEN) == 0) {
35985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            options[NORMALIZE].doesOccur = TRUE;
36085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            return;
36185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
36285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        else if (length >= CHECK_BIDI_DIRECTIVE_LEN
36385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            && uprv_strncmp(s, CHECK_BIDI_DIRECTIVE, CHECK_BIDI_DIRECTIVE_LEN) == 0) {
36485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            options[CHECK_BIDI].doesOccur = TRUE;
36585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            return;
36685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
36785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        else {
36885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            fprintf(stderr, "gensprep error parsing a directive %s.", fields[0][0]);
36985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
37085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
37185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    typeName = fields[2][0];
373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    map = fields[1][0];
374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(uprv_strstr(typeName, usprepTypeNames[USPREP_UNASSIGNED])!=NULL){
376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
37785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        u_parseCodePointRange(s, &rangeStart,&rangeEnd, pErrorCode);
378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(*pErrorCode)){
379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            fprintf(stderr, "Could not parse code point range. Error: %s\n",u_errorName(*pErrorCode));
380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return;
381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* store the range */
384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        storeRange(rangeStart,rangeEnd,USPREP_UNASSIGNED, pErrorCode);
385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }else if(uprv_strstr(typeName, usprepTypeNames[USPREP_PROHIBITED])!=NULL){
387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
38885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        u_parseCodePointRange(s, &rangeStart,&rangeEnd, pErrorCode);
389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(*pErrorCode)){
390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            fprintf(stderr, "Could not parse code point range. Error: %s\n",u_errorName(*pErrorCode));
391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return;
392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* store the range */
395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        storeRange(rangeStart,rangeEnd,USPREP_PROHIBITED, pErrorCode);
396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }else if(uprv_strstr(typeName, usprepTypeNames[USPREP_MAP])!=NULL){
398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* get the character code, field 0 */
40085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        code=(uint32_t)uprv_strtoul(s, &end, 16);
40185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if(end<=s || end!=fields[0][1]) {
402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            fprintf(stderr, "gensprep: syntax error in field 0 at %s\n", fields[0][0]);
403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            *pErrorCode=U_PARSE_ERROR;
404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            exit(U_PARSE_ERROR);
405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* parse the mapping string */
408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        length=u_parseCodePoints(map, mapping, sizeof(mapping)/4, pErrorCode);
409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* store the mapping */
411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        storeMapping(code,mapping, length,USPREP_MAP, pErrorCode);
412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }else{
414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        *pErrorCode = U_INVALID_FORMAT_ERROR;
415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(*pErrorCode)) {
418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fprintf(stderr, "gensprep error parsing  %s line %s at %s. Error: %s\n",filename,
419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru               fields[0][0],fields[2][0],u_errorName(*pErrorCode));
420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        exit(*pErrorCode);
421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruparseMappings(const char *filename, UBool reportError, UErrorCode *pErrorCode) {
427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *fields[3][2];
428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_parseDelimitedFile(filename, ';', fields, 3, strprepProfileLineFn, (void*)filename, pErrorCode);
434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*fprintf(stdout,"Number of code points that have mappings with length >1 : %i\n",len);*/
436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(*pErrorCode) && (reportError || *pErrorCode!=U_FILE_ACCESS_ERROR)) {
438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fprintf(stderr, "gensprep error: u_parseDelimitedFile(\"%s\") failed - %s\n", filename, u_errorName(*pErrorCode));
439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        exit(*pErrorCode);
440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_IDNA */
445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Hey, Emacs, please set the following:
448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Local Variables:
450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * indent-tabs-mode: nil
451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * End:
452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
454