10596faeddefbf198de137d5e893708495ab1584cFredrik Roubert// © 2016 and later: Unicode, Inc. and others. 264339d36f8bd4db5025fe2988eda22b491a9219cFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************* 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 68de051c3d18a56cc126f0f44e368495a52f9148cFredrik Roubert* Copyright (C) 1999-2016 International Business Machines 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Corporation and others. All Rights Reserved. 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************* 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* file name: gencnval.c 110596faeddefbf198de137d5e893708495ab1584cFredrik Roubert* encoding: UTF-8 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* tab size: 8 (not used) 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* indentation:4 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* created on: 1999nov05 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* created by: Markus W. Scherer 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* This program reads convrtrs.txt and writes a memory-mappable 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* converter name alias table to cnvalias.dat . 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* This program currently writes version 2.1 of the data format. See 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* ucnv_io.c for more details on the format. Note that version 2.1 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* is written in such a way that a 2.0 reader will be able to use it, 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* and a 2.1 reader will be able to read 2.0. 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/putil.h" 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucnv.h" /* ucnv_compareNames() */ 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ucnv_io.h" 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cmemory.h" 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cstring.h" 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uinvchar.h" 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "filestrm.h" 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uclean.h" 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unewdata.h" 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uoptions.h" 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h> 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h> 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <ctype.h> 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* TODO: Need to check alias name length is less than UCNV_MAX_CONVERTER_NAME_LENGTH */ 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* STRING_STORE_SIZE + TAG_STORE_SIZE <= ((2^16 - 1) * 2) 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru That is the maximum size for the string stores combined 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru because the strings are index at 16-bit boundries by a 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 16-bit index, and there is only one section for the 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strings. 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define STRING_STORE_SIZE 0x1FBFE /* 130046 */ 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define TAG_STORE_SIZE 0x400 /* 1024 */ 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* The combined tag and converter count can affect the number of lists 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru created. The size of all lists must be less than (2^17 - 1) 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru because the lists are indexed as a 16-bit array with a 16-bit index. 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define MAX_TAG_COUNT 0x3F /* 63 */ 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define MAX_CONV_COUNT UCNV_CONVERTER_INDEX_MASK 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define MAX_ALIAS_COUNT 0xFFFF /* 65535 */ 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* The maximum number of aliases that a standard tag/converter combination can have. 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru At this moment 6/18/2002, IANA has 12 names for ASCII. Don't go below 15 for 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru this value. I don't recommend more than 31 for this value. 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define MAX_TC_ALIAS_COUNT 0x1F /* 31 */ 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define MAX_LINE_SIZE 0x7FFF /* 32767 */ 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define MAX_LIST_SIZE 0xFFFF /* 65535 */ 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define DATA_NAME "cnvalias" 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define DATA_TYPE "icu" /* ICU alias table */ 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define ALL_TAG_STR "ALL" 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define ALL_TAG_NUM 1 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define EMPTY_TAG_NUM 0 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* UDataInfo cf. udata.h */ 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const UDataInfo dataInfo={ 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sizeof(UDataInfo), 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0, 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_IS_BIG_ENDIAN, 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_CHARSET_FAMILY, 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sizeof(UChar), 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0, 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x43, 0x76, 0x41, 0x6c}, /* dataFormat="CvAl" */ 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {3, 0, 1, 0}, /* formatVersion */ 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {1, 4, 2, 0} /* dataVersion */ 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct { 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *store; 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t top; 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t max; 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} StringBlock; 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic char stringStore[STRING_STORE_SIZE]; 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic StringBlock stringBlock = { stringStore, 0, STRING_STORE_SIZE }; 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct { 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t aliasCount; 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t *aliases; /* Index into stringStore */ 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} AliasList; 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct { 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t converter; /* Index into stringStore */ 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t totalAliasCount; /* Total aliases in this column */ 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} Converter; 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic Converter converters[MAX_CONV_COUNT]; 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t converterCount=0; 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic char tagStore[TAG_STORE_SIZE]; 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic StringBlock tagBlock = { tagStore, 0, TAG_STORE_SIZE }; 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct { 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t tag; /* Index into tagStore */ 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t totalAliasCount; /* Total aliases in this row */ 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru AliasList aliasList[MAX_CONV_COUNT]; 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} Tag; 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Think of this as a 3D array. It's tagCount by converterCount by aliasCount */ 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic Tag tags[MAX_TAG_COUNT]; 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t tagCount = 0; 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Used for storing all aliases */ 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t knownAliases[MAX_ALIAS_COUNT]; 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t knownAliasesCount = 0; 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*static uint16_t duplicateKnownAliasesCount = 0;*/ 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Used for storing the lists section that point to aliases */ 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t aliasLists[MAX_LIST_SIZE]; 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t aliasListsSize = 0; 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Were the standard tags declared before the aliases. */ 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UBool standardTagsUsed = FALSE; 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UBool verbose = FALSE; 140c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubertstatic UBool quiet = FALSE; 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int lineNum = 1; 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UConverterAliasOptions tableOptions = { 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCNV_IO_STD_NORMALIZED, 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1 /* containsCnvOptionInfo */ 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 14885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 14985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/** 15085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * path to convrtrs.txt 15185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho */ 15285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hoconst char *path; 15385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* prototypes --------------------------------------------------------------- */ 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruparseLine(const char *line); 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruparseFile(FileStream *in); 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int32_t 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruchomp(char *line); 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruaddOfficialTaggedStandards(char *line, int32_t lineLen); 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruaddAlias(const char *alias, uint16_t standard, uint16_t converter, UBool defaultName); 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruaddConverter(const char *converter); 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic char * 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruallocString(StringBlock *block, const char *s, int32_t length); 176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruaddToKnownAliases(const char *alias); 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerucompareAliases(const void *alias1, const void *alias2); 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerugetTagNumber(const char *tag, uint16_t tagLen); 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*static void 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruaddTaggedAlias(uint16_t tag, const char *alias, uint16_t converter);*/ 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruwriteAliasTable(UNewDataMemory *out); 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* -------------------------------------------------------------------------- */ 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Presumes that you used allocString() */ 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define GET_ALIAS_STR(index) (stringStore + ((size_t)(index) << 1)) 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define GET_TAG_STR(index) (tagStore + ((size_t)(index) << 1)) 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Presumes that you used allocString() */ 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define GET_ALIAS_NUM(str) ((uint16_t)((str - stringStore) >> 1)) 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define GET_TAG_NUM(str) ((uint16_t)((str - tagStore) >> 1)) 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruenum 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru HELP1, 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru HELP2, 206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru VERBOSE, 207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru COPYRIGHT, 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru DESTDIR, 209c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert SOURCEDIR, 210c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert QUIET 211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UOption options[]={ 214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UOPTION_HELP_H, 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UOPTION_HELP_QUESTION_MARK, 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UOPTION_VERBOSE, 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UOPTION_COPYRIGHT, 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UOPTION_DESTDIR, 219c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert UOPTION_SOURCEDIR, 220c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert UOPTION_QUIET 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruextern int 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querumain(int argc, char* argv[]) { 22554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius int i, n; 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char pathBuf[512]; 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru FileStream *in; 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UNewDataMemory *out; 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode errorCode=U_ZERO_ERROR; 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_MAIN_INIT_ARGS(argc, argv); 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* preset then read command line options */ 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru options[DESTDIR].value=options[SOURCEDIR].value=u_getDataDirectory(); 2358de051c3d18a56cc126f0f44e368495a52f9148cFredrik Roubert argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* error handling, printing usage message */ 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(argc<0) { 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "error in command line argument \"%s\"\n", 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru argv[-argc]); 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(argc<0 || options[HELP1].doesOccur || options[HELP2].doesOccur) { 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "usage: %s [-options] [convrtrs.txt]\n" 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\tread convrtrs.txt and create " U_ICUDATA_NAME "_" DATA_NAME "." DATA_TYPE "\n" 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "options:\n" 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\t-h or -? or --help this usage text\n" 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\t-v or --verbose prints out extra information about the alias table\n" 250c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert "\t-q or --quiet do not display warnings and progress\n" 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\t-c or --copyright include a copyright notice\n" 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\t-d or --destdir destination directory, followed by the path\n" 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "\t-s or --sourcedir source directory, followed by the path\n", 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru argv[0]); 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(options[VERBOSE].doesOccur) { 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru verbose = TRUE; 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 262c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert if(options[QUIET].doesOccur) { 263c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert quiet = TRUE; 264c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert } 265c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(argc>=2) { 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru path=argv[1]; 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru path=options[SOURCEDIR].value; 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(path!=NULL && *path!=0) { 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *end; 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_strcpy(pathBuf, path); 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru end = uprv_strchr(pathBuf, 0); 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(*(end-1)!=U_FILE_SEP_CHAR) { 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *(end++)=U_FILE_SEP_CHAR; 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_strcpy(end, "convrtrs.txt"); 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru path=pathBuf; 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru path = "convrtrs.txt"; 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_memset(stringStore, 0, sizeof(stringStore)); 286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_memset(tagStore, 0, sizeof(tagStore)); 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_memset(converters, 0, sizeof(converters)); 288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_memset(tags, 0, sizeof(tags)); 289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_memset(aliasLists, 0, sizeof(aliasLists)); 290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_memset(knownAliases, 0, sizeof(aliasLists)); 291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru in=T_FileStream_open(path, "r"); 294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(in==NULL) { 29585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "gencnval: unable to open input file %s\n", path); 296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_FILE_ACCESS_ERROR); 297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru parseFile(in); 299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru T_FileStream_close(in); 300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* create the output file */ 302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru out=udata_create(options[DESTDIR].value, DATA_TYPE, DATA_NAME, &dataInfo, 303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru options[COPYRIGHT].doesOccur ? U_COPYRIGHT_STRING : NULL, &errorCode); 304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(errorCode)) { 305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, "gencnval: unable to open output file - error %s\n", u_errorName(errorCode)); 306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(errorCode); 307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* write the table of aliases based on a tag/converter name combination */ 310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru writeAliasTable(out); 311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* finish */ 313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_finish(out, &errorCode); 314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(errorCode)) { 315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, "gencnval: error finishing output file - %s\n", u_errorName(errorCode)); 316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(errorCode); 317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 31954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius /* clean up tags */ 32054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius for (i = 0; i < MAX_TAG_COUNT; i++) { 32154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius for (n = 0; n < MAX_CONV_COUNT; n++) { 32254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (tags[i].aliasList[n].aliases!=NULL) { 32354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius uprv_free(tags[i].aliasList[n].aliases); 32454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 32554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 32654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 32754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return 0; 329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruparseFile(FileStream *in) { 333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char line[MAX_LINE_SIZE]; 334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char lastLine[MAX_LINE_SIZE]; 335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t lineSize = 0; 336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t lastLineSize = 0; 337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool validParse = TRUE; 338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum = 0; 340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Add the empty tag, which is for untagged aliases */ 342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru getTagNumber("", 0); 343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru getTagNumber(ALL_TAG_STR, 3); 344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru allocString(&stringBlock, "", 0); 345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* read the list of aliases */ 347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while (validParse) { 348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru validParse = FALSE; 349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Read non-empty lines that don't start with a space character. */ 351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while (T_FileStream_readLine(in, lastLine, MAX_LINE_SIZE) != NULL) { 352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lastLineSize = chomp(lastLine); 353103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if (lineSize == 0 || (lastLineSize > 0 && isspace((int)*lastLine))) { 354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_strcpy(line + lineSize, lastLine); 355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineSize += lastLineSize; 356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else if (lineSize > 0) { 357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru validParse = TRUE; 358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum++; 361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (validParse || lineSize > 0) { 364103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if (isspace((int)*line)) { 36585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: cannot start an alias with a space\n", path, lineNum-1); 366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_PARSE_ERROR); 367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else if (line[0] == '{') { 368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!standardTagsUsed && line[lineSize - 1] != '}') { 36985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: alias needs to start with a converter name\n", path, lineNum); 370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_PARSE_ERROR); 371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addOfficialTaggedStandards(line, lineSize); 373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru standardTagsUsed = TRUE; 374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (standardTagsUsed) { 376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru parseLine(line); 377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 37985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: alias table needs to start a list of standard tags\n", path, lineNum); 380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_PARSE_ERROR); 381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Was the last line consumed */ 384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (lastLineSize > 0) { 385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_strcpy(line, lastLine); 386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineSize = lastLineSize; 387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineSize = 0; 390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum++; 393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* This works almost like the Perl chomp. 397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru It removes the newlines, comments and trailing whitespace (not preceding whitespace). 398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int32_t 400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruchomp(char *line) { 401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *s = line; 402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *lastNonSpace = line; 403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(*s!=0) { 404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* truncate at a newline or a comment */ 405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(*s == '\r' || *s == '\n' || *s == '#') { 406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *s = 0; 407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 409103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if (!isspace((int)*s)) { 410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lastNonSpace = s; 411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++s; 413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (lastNonSpace++ > line) { 415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *lastNonSpace = 0; 416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru s = lastNonSpace; 417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return (int32_t)(s - line); 419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruparseLine(const char *line) { 423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t pos=0, start, limit, length, cnv; 424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *converter, *alias; 425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* skip leading white space */ 427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* There is no whitespace at the beginning anymore */ 428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* while(line[pos]!=0 && isspace(line[pos])) { 429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++pos; 430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* is there nothing on this line? */ 434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(line[pos]==0) { 435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* get the converter name */ 439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru start=pos; 440103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius while(line[pos]!=0 && !isspace((int)line[pos])) { 441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++pos; 442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru limit=pos; 444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* store the converter name */ 446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length=(uint16_t)(limit-start); 447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru converter=allocString(&stringBlock, line+start, length); 448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* add the converter to the converter table */ 450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cnv=addConverter(converter); 451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* The name itself may be tagged, so let's added it to the aliases list properly */ 453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pos = start; 454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* get all the real aliases */ 456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(;;) { 457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* skip white space */ 459103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius while(line[pos]!=0 && isspace((int)line[pos])) { 460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++pos; 461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* is there no more alias name on this line? */ 464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(line[pos]==0) { 465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* get an alias name */ 469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru start=pos; 470103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius while(line[pos]!=0 && line[pos]!='{' && !isspace((int)line[pos])) { 471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++pos; 472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru limit=pos; 474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* store the alias name */ 476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length=(uint16_t)(limit-start); 477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (start == 0) { 478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* add the converter as its own alias to the alias table */ 479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru alias = converter; 480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addAlias(alias, ALL_TAG_NUM, cnv, TRUE); 481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru alias=allocString(&stringBlock, line+start, length); 484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addAlias(alias, ALL_TAG_NUM, cnv, FALSE); 485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addToKnownAliases(alias); 487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* add the alias/converter pair to the alias table */ 489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* addAlias(alias, 0, cnv, FALSE);*/ 490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* skip whitespace */ 492103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius while (line[pos] && isspace((int)line[pos])) { 493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++pos; 494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* handle tags if they are present */ 497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (line[pos] == '{') { 498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++pos; 499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru do { 500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru start = pos; 501103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius while (line[pos] && line[pos] != '}' && !isspace((int)line[pos])) { 502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++pos; 503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru limit = pos; 505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (start != limit) { 507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* add the tag to the tag table */ 508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t tag = getTagNumber(line + start, (uint16_t)(limit - start)); 509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addAlias(alias, tag, cnv, (UBool)(line[limit-1] == '*')); 510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 512103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius while (line[pos] && isspace((int)line[pos])) { 513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++pos; 514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } while (line[pos] && line[pos] != '}'); 516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (line[pos] == '}') { 518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++pos; 519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 52085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: Unterminated tag list\n", path, lineNum); 521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_UNMATCHED_BRACES); 522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addAlias(alias, EMPTY_TAG_NUM, cnv, (UBool)(tags[0].aliasList[cnv].aliasCount == 0)); 525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t 530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerugetTagNumber(const char *tag, uint16_t tagLen) { 531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *atag; 532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t t; 533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool preferredName = ((tagLen > 0) ? (tag[tagLen - 1] == '*') : (FALSE)); 534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (tagCount >= MAX_TAG_COUNT) { 53685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: too many tags\n", path, lineNum); 537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_BUFFER_OVERFLOW_ERROR); 538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (preferredName) { 541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* puts(tag);*/ 542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tagLen--; 543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (t = 0; t < tagCount; ++t) { 546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *currTag = GET_TAG_STR(tags[t].tag); 547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (uprv_strlen(currTag) == tagLen && !uprv_strnicmp(currTag, tag, tagLen)) { 548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return t; 549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* we need to add this tag */ 553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (tagCount >= MAX_TAG_COUNT) { 55485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: too many tags\n", path, lineNum); 555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_BUFFER_OVERFLOW_ERROR); 556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* allocate a new entry in the tag table */ 559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru atag = allocString(&tagBlock, tag, tagLen); 560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (standardTagsUsed) { 56285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: Tag \"%s\" is not declared at the beginning of the alias table.\n", 56385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho path, lineNum, atag); 564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(1); 565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else if (tagLen > 0 && strcmp(tag, ALL_TAG_STR) != 0) { 56785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: warning: Tag \"%s\" was added to the list of standards because it was not declared at beginning of the alias table.\n", 56885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho path, lineNum, atag); 569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* add the tag to the tag table */ 572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tags[tagCount].tag = GET_TAG_NUM(atag); 573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* The aliasList should be set to 0's already */ 574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return tagCount++; 576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*static void 579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruaddTaggedAlias(uint16_t tag, const char *alias, uint16_t converter) { 580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tags[tag].aliases[converter] = alias; 581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruaddOfficialTaggedStandards(char *line, int32_t lineLen) { 586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *atag; 58785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho char *endTagExp; 58885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho char *tag; 589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const char WHITESPACE[] = " \t"; 590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (tagCount > UCNV_NUM_RESERVED_TAGS) { 59285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: official tags already added\n", path, lineNum); 593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_BUFFER_OVERFLOW_ERROR); 594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 59585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho tag = strchr(line, '{'); 59685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (tag == NULL) { 59785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* Why were we called? */ 59885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: Missing start of tag group\n", path, lineNum); 59985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho exit(U_PARSE_ERROR); 60085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 60185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho tag++; 60285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho endTagExp = strchr(tag, '}'); 60385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (endTagExp == NULL) { 60485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: Missing end of tag group\n", path, lineNum); 60585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho exit(U_PARSE_ERROR); 60685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 60785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho endTagExp[0] = 0; 608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tag = strtok(tag, WHITESPACE); 610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while (tag != NULL) { 611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* printf("Adding original tag \"%s\"\n", tag);*/ 612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* allocate a new entry in the tag table */ 614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru atag = allocString(&tagBlock, tag, -1); 615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* add the tag to the tag table */ 617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tags[tagCount++].tag = (uint16_t)((atag - tagStore) >> 1); 618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* The aliasList should already be set to 0's */ 620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Get next tag */ 622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tag = strtok(NULL, WHITESPACE); 623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t 627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruaddToKnownAliases(const char *alias) { 628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* uint32_t idx; */ 629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* strict matching */ 630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* for (idx = 0; idx < knownAliasesCount; idx++) { 631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t num = GET_ALIAS_NUM(alias); 632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (knownAliases[idx] != num 633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru && uprv_strcmp(alias, GET_ALIAS_STR(knownAliases[idx])) == 0) 634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 63585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: warning: duplicate alias %s and %s found\n", path, 636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum, alias, GET_ALIAS_STR(knownAliases[idx])); 637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru duplicateKnownAliasesCount++; 638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else if (knownAliases[idx] != num 641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru && ucnv_compareNames(alias, GET_ALIAS_STR(knownAliases[idx])) == 0) 642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (verbose) { 64485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: information: duplicate alias %s and %s found\n", path, 645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum, alias, GET_ALIAS_STR(knownAliases[idx])); 646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru duplicateKnownAliasesCount++; 648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (knownAliasesCount >= MAX_ALIAS_COUNT) { 65385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: warning: Too many aliases defined for all converters\n", 65485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho path, lineNum); 655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_BUFFER_OVERFLOW_ERROR); 656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* TODO: We could try to unlist exact duplicates. */ 658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return knownAliases[knownAliasesCount++] = GET_ALIAS_NUM(alias); 659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru@param standard When standard is 0, then it's the "empty" tag. 663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t 665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruaddAlias(const char *alias, uint16_t standard, uint16_t converter, UBool defaultName) { 666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t idx, idx2; 667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool startEmptyWithoutDefault = FALSE; 668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru AliasList *aliasList; 669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(standard>=MAX_TAG_COUNT) { 67185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: too many standard tags\n", path, lineNum); 672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_BUFFER_OVERFLOW_ERROR); 673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(converter>=MAX_CONV_COUNT) { 67585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: too many converter names\n", path, lineNum); 676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_BUFFER_OVERFLOW_ERROR); 677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru aliasList = &tags[standard].aliasList[converter]; 679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (strchr(alias, '}')) { 68185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: unmatched } found\n", path, 682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum); 683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(aliasList->aliasCount + 1 >= MAX_TC_ALIAS_COUNT) { 68685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: too many aliases for alias %s and converter %s\n", path, 687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum, alias, GET_ALIAS_STR(converters[converter].converter)); 688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_BUFFER_OVERFLOW_ERROR); 689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Show this warning only once. All aliases are added to the "ALL" tag. */ 692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (standard == ALL_TAG_NUM && GET_ALIAS_STR(converters[converter].converter) != alias) { 693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Normally these option values are parsed at runtime, and they can 694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru be discarded when the alias is a default converter. Options should 695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru only be on a converter and not an alias. */ 696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (uprv_strchr(alias, UCNV_OPTION_SEP_CHAR) != 0) 697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, "warning(line %d): alias %s contains a \""UCNV_OPTION_SEP_STRING"\". Options are parsed at run-time and do not need to be in the alias table.\n", 699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum, alias); 700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (uprv_strchr(alias, UCNV_VALUE_SEP_CHAR) != 0) 702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, "warning(line %d): alias %s contains an \""UCNV_VALUE_SEP_STRING"\". Options are parsed at run-time and do not need to be in the alias table.\n", 704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum, alias); 705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (standard != ALL_TAG_NUM) { 709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Check for duplicate aliases for this tag on all converters */ 710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (idx = 0; idx < converterCount; idx++) { 711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (idx2 = 0; idx2 < tags[standard].aliasList[idx].aliasCount; idx2++) { 712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t aliasNum = tags[standard].aliasList[idx].aliases[idx2]; 713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (aliasNum 714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru && ucnv_compareNames(alias, GET_ALIAS_STR(aliasNum)) == 0) 715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (idx == converter) { 717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (alias, standard) duplicates are harmless if they map to the same converter. 719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Only print a warning in verbose mode, or if the alias is a precise duplicate, 720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * not just a lenient-match duplicate. 721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (verbose || 0 == uprv_strcmp(alias, GET_ALIAS_STR(aliasNum))) { 72385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: warning: duplicate aliases %s and %s found for standard %s and converter %s\n", path, 724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum, alias, GET_ALIAS_STR(aliasNum), 725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_TAG_STR(tags[standard].tag), 726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(converters[converter].converter)); 727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 72985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: warning: duplicate aliases %s and %s found for standard tag %s between converter %s and converter %s\n", path, 730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum, alias, GET_ALIAS_STR(aliasNum), 731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_TAG_STR(tags[standard].tag), 732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(converters[converter].converter), 733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(converters[idx].converter)); 734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Check for duplicate default aliases for this converter on all tags */ 741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* It's okay to have multiple standards prefer the same name */ 742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* if (verbose && !dupFound) { 743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (idx = 0; idx < tagCount; idx++) { 744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (tags[idx].aliasList[converter].aliases) { 745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t aliasNum = tags[idx].aliasList[converter].aliases[0]; 746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (aliasNum 747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru && ucnv_compareNames(alias, GET_ALIAS_STR(aliasNum)) == 0) 748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 74985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: warning: duplicate alias %s found for converter %s and standard tag %s\n", path, 750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum, alias, GET_ALIAS_STR(converters[converter].converter), GET_TAG_STR(tags[standard].tag)); 751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }*/ 756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (aliasList->aliasCount <= 0) { 759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru aliasList->aliasCount++; 760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru startEmptyWithoutDefault = TRUE; 761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru aliasList->aliases = (uint16_t *)uprv_realloc(aliasList->aliases, (aliasList->aliasCount + 1) * sizeof(aliasList->aliases[0])); 763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (startEmptyWithoutDefault) { 764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru aliasList->aliases[0] = 0; 765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (defaultName) { 767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (aliasList->aliases[0] != 0) { 76885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: Alias %s and %s cannot both be the default alias for standard tag %s and converter %s\n", path, 769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lineNum, 770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru alias, 771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(aliasList->aliases[0]), 772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_TAG_STR(tags[standard].tag), 773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(converters[converter].converter)); 774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_PARSE_ERROR); 775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru aliasList->aliases[0] = GET_ALIAS_NUM(alias); 777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru aliasList->aliases[aliasList->aliasCount++] = GET_ALIAS_NUM(alias); 779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* aliasList->converter = converter;*/ 781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru converters[converter].totalAliasCount++; /* One more to the column */ 783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tags[standard].totalAliasCount++; /* One more to the row */ 784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return aliasList->aliasCount; 786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 788ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint16_t 789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruaddConverter(const char *converter) { 790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t idx; 791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(converterCount>=MAX_CONV_COUNT) { 79285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: too many converters\n", path, lineNum); 793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_BUFFER_OVERFLOW_ERROR); 794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (idx = 0; idx < converterCount; idx++) { 797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucnv_compareNames(converter, GET_ALIAS_STR(converters[idx].converter)) == 0) { 79885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: duplicate converter %s found!\n", path, lineNum, converter); 799ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_PARSE_ERROR); 800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru converters[converterCount].converter = GET_ALIAS_NUM(converter); 805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru converters[converterCount].totalAliasCount = 0; 806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return converterCount++; 808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* resolve this alias based on the prioritization of the standard tags. */ 811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruresolveAliasToConverter(uint16_t alias, uint16_t *tagNum, uint16_t *converterNum) { 813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t idx, idx2, idx3; 814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (idx = UCNV_NUM_RESERVED_TAGS; idx < tagCount; idx++) { 816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (idx2 = 0; idx2 < converterCount; idx2++) { 817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (idx3 = 0; idx3 < tags[idx].aliasList[idx2].aliasCount; idx3++) { 818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t aliasNum = tags[idx].aliasList[idx2].aliases[idx3]; 819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (aliasNum == alias) { 820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *tagNum = idx; 821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *converterNum = idx2; 822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Do the leftovers last, just in case */ 828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* There is no need to do the ALL tag */ 829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru idx = 0; 830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (idx2 = 0; idx2 < converterCount; idx2++) { 831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (idx3 = 0; idx3 < tags[idx].aliasList[idx2].aliasCount; idx3++) { 832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t aliasNum = tags[idx].aliasList[idx2].aliases[idx3]; 833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (aliasNum == alias) { 834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *tagNum = idx; 835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *converterNum = idx2; 836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *tagNum = UINT16_MAX; 841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *converterNum = UINT16_MAX; 84285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s: warning: alias %s not found\n", 84385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho path, 844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(alias)); 845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* The knownAliases should be sorted before calling this function */ 849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic uint32_t 850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruresolveAliases(uint16_t *uniqueAliasArr, uint16_t *uniqueAliasToConverterArr, uint16_t aliasOffset) { 851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t uniqueAliasIdx = 0; 852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t idx; 853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t currTagNum, oldTagNum; 854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t currConvNum, oldConvNum; 855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *lastName; 856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resolveAliasToConverter(knownAliases[0], &oldTagNum, &currConvNum); 858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uniqueAliasToConverterArr[uniqueAliasIdx] = currConvNum; 859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru oldConvNum = currConvNum; 860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uniqueAliasArr[uniqueAliasIdx] = knownAliases[0] + aliasOffset; 861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uniqueAliasIdx++; 862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lastName = GET_ALIAS_STR(knownAliases[0]); 863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (idx = 1; idx < knownAliasesCount; idx++) { 865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resolveAliasToConverter(knownAliases[idx], &currTagNum, &currConvNum); 866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucnv_compareNames(lastName, GET_ALIAS_STR(knownAliases[idx])) == 0) { 867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* duplicate found */ 868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((currTagNum < oldTagNum && currTagNum >= UCNV_NUM_RESERVED_TAGS) 869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru || oldTagNum == 0) { 870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru oldTagNum = currTagNum; 871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uniqueAliasToConverterArr[uniqueAliasIdx - 1] = currConvNum; 872ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uniqueAliasArr[uniqueAliasIdx - 1] = knownAliases[idx] + aliasOffset; 873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (verbose) { 874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("using %s instead of %s -> %s", 875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(knownAliases[idx]), 876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lastName, 877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(converters[currConvNum].converter)); 878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (oldConvNum != currConvNum) { 879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf(" (alias conflict)"); 880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru puts(""); 882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* else ignore it */ 886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (verbose) { 887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("folding %s into %s -> %s", 888ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(knownAliases[idx]), 889ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lastName, 890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(converters[oldConvNum].converter)); 891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (oldConvNum != currConvNum) { 892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf(" (alias conflict)"); 893ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 894ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru puts(""); 895ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 896ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 897ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (oldConvNum != currConvNum) { 898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uniqueAliasToConverterArr[uniqueAliasIdx - 1] |= UCNV_AMBIGUOUS_ALIAS_MAP_BIT; 899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 900ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 902ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uniqueAliasToConverterArr[uniqueAliasIdx] = currConvNum; 903ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru oldConvNum = currConvNum; 904ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uniqueAliasArr[uniqueAliasIdx] = knownAliases[idx] + aliasOffset; 905ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uniqueAliasIdx++; 906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lastName = GET_ALIAS_STR(knownAliases[idx]); 907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru oldTagNum = currTagNum; 908ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*printf("%s -> %s\n", GET_ALIAS_STR(knownAliases[idx]), GET_ALIAS_STR(converters[currConvNum].converter));*/ 909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 910ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (uprv_strchr(GET_ALIAS_STR(converters[currConvNum].converter), UCNV_OPTION_SEP_CHAR) != NULL) { 911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uniqueAliasToConverterArr[uniqueAliasIdx-1] |= UCNV_CONTAINS_OPTION_BIT; 912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 913ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 914ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return uniqueAliasIdx; 915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 917ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 918ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerucreateOneAliasList(uint16_t *aliasArrLists, uint32_t tag, uint32_t converter, uint16_t offset) { 919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t aliasNum; 920ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru AliasList *aliasList = &tags[tag].aliasList[converter]; 921ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (aliasList->aliasCount == 0) { 923ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru aliasArrLists[tag*converterCount + converter] = 0; 924ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 926ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru aliasLists[aliasListsSize++] = aliasList->aliasCount; 927ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 928ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* write into the array area a 1's based index. */ 929ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru aliasArrLists[tag*converterCount + converter] = aliasListsSize; 930ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 931ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* printf("tag %s converter %s\n", 932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_TAG_STR(tags[tag].tag), 933ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(converters[converter].converter));*/ 934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (aliasNum = 0; aliasNum < aliasList->aliasCount; aliasNum++) { 935ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t value; 936ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* printf(" %s\n", 937ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(aliasList->aliases[aliasNum]));*/ 938ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (aliasList->aliases[aliasNum]) { 939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value = aliasList->aliases[aliasNum] + offset; 940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value = 0; 942c14898b482f76ecab9026615e2e4c6fe78358bdcFredrik Roubert if (tag != 0 && !quiet) { /* Only show the warning when it's not the leftover tag. */ 94385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s: warning: tag %s does not have a default alias for %s\n", 94485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho path, 945ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_TAG_STR(tags[tag].tag), 946ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GET_ALIAS_STR(converters[converter].converter)); 947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru aliasLists[aliasListsSize++] = value; 950ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (aliasListsSize >= MAX_LIST_SIZE) { 95185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s: error: Too many alias lists\n", path); 952ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_BUFFER_OVERFLOW_ERROR); 953ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 956ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 958ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 959ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 960ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerucreateNormalizedAliasStrings(char *normalizedStrings, const char *origStringBlock, int32_t stringBlockLength) { 961ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t currStrLen; 962ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_memcpy(normalizedStrings, origStringBlock, stringBlockLength); 963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while ((currStrLen = (int32_t)uprv_strlen(origStringBlock)) < stringBlockLength) { 964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t currStrSize = currStrLen + 1; 965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (currStrLen > 0) { 966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t normStrLen; 967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucnv_io_stripForCompare(normalizedStrings, origStringBlock); 968ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru normStrLen = uprv_strlen(normalizedStrings); 969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (normStrLen > 0) { 970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_memset(normalizedStrings + normStrLen, 0, currStrSize - normStrLen); 971ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 972ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru stringBlockLength -= currStrSize; 974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru normalizedStrings += currStrSize; 975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru origStringBlock += currStrSize; 976ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruwriteAliasTable(UNewDataMemory *out) { 981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t i, j; 982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t uniqueAliasesSize; 983ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t aliasOffset = (uint16_t)(tagBlock.top/sizeof(uint16_t)); 984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t *aliasArrLists = (uint16_t *)uprv_malloc(tagCount * converterCount * sizeof(uint16_t)); 985ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t *uniqueAliases = (uint16_t *)uprv_malloc(knownAliasesCount * sizeof(uint16_t)); 986ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t *uniqueAliasesToConverter = (uint16_t *)uprv_malloc(knownAliasesCount * sizeof(uint16_t)); 987ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 988ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru qsort(knownAliases, knownAliasesCount, sizeof(knownAliases[0]), compareAliases); 989ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uniqueAliasesSize = resolveAliases(uniqueAliases, uniqueAliasesToConverter, aliasOffset); 990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 991ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Array index starts at 1. aliasLists[0] is the size of the lists section. */ 992ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru aliasListsSize = 0; 993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 994ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* write the offsets of all the aliases lists in a 2D array, and create the lists. */ 995ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i = 0; i < tagCount; ++i) { 996ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (j = 0; j < converterCount; ++j) { 997ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru createOneAliasList(aliasArrLists, i, j, aliasOffset); 998ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 999ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1000ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1001ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Write the size of the TOC */ 1002ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (tableOptions.stringNormalizationType == UCNV_IO_UNNORMALIZED) { 1003ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write32(out, 8); 1004ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1005ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else { 1006ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write32(out, 9); 1007ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1008ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1009ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Write the sizes of each section */ 1010ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* All sizes are the number of uint16_t units, not bytes */ 1011ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write32(out, converterCount); 1012ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write32(out, tagCount); 1013ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write32(out, uniqueAliasesSize); /* list of aliases */ 1014ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write32(out, uniqueAliasesSize); /* The preresolved form of mapping an untagged the alias to a converter */ 1015ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write32(out, tagCount * converterCount); 1016ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write32(out, aliasListsSize + 1); 1017ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write32(out, sizeof(tableOptions) / sizeof(uint16_t)); 1018ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write32(out, (tagBlock.top + stringBlock.top) / sizeof(uint16_t)); 1019ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (tableOptions.stringNormalizationType != UCNV_IO_UNNORMALIZED) { 1020ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write32(out, (tagBlock.top + stringBlock.top) / sizeof(uint16_t)); 1021ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1022ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1023ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* write the table of converters */ 1024ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Think of this as the column headers */ 1025ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i=0; i<converterCount; ++i) { 1026ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write16(out, (uint16_t)(converters[i].converter + aliasOffset)); 1027ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1028ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1029ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* write the table of tags */ 1030ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Think of this as the row headers */ 1031ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i=UCNV_NUM_RESERVED_TAGS; i<tagCount; ++i) { 1032ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write16(out, tags[i].tag); 1033ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1034ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* The empty tag is considered the leftover list, and put that at the end of the priority list. */ 1035ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write16(out, tags[EMPTY_TAG_NUM].tag); 1036ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write16(out, tags[ALL_TAG_NUM].tag); 1037ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1038ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Write the unique list of aliases */ 1039ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_writeBlock(out, uniqueAliases, uniqueAliasesSize * sizeof(uint16_t)); 1040ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1041ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Write the unique list of aliases */ 1042ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_writeBlock(out, uniqueAliasesToConverter, uniqueAliasesSize * sizeof(uint16_t)); 1043ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1044ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Write the array to the lists */ 1045ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_writeBlock(out, (const void *)(aliasArrLists + (2*converterCount)), (((tagCount - 2) * converterCount) * sizeof(uint16_t))); 1046ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Now write the leftover part of the array for the EMPTY and ALL lists */ 1047ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_writeBlock(out, (const void *)aliasArrLists, (2 * converterCount * sizeof(uint16_t))); 1048ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1049ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Offset the next array to make the index start at 1. */ 1050ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_write16(out, 0xDEAD); 1051ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1052ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Write the lists */ 1053ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_writeBlock(out, (const void *)aliasLists, aliasListsSize * sizeof(uint16_t)); 1054ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1055ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Write any options for the alias table. */ 1056ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_writeBlock(out, (const void *)&tableOptions, sizeof(tableOptions)); 1057ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1058ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* write the tags strings */ 1059ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_writeString(out, tagBlock.store, tagBlock.top); 1060ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1061ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* write the aliases strings */ 1062ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_writeString(out, stringBlock.store, stringBlock.top); 1063ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1064ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* write the normalized aliases strings */ 1065ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (tableOptions.stringNormalizationType != UCNV_IO_UNNORMALIZED) { 1066ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *normalizedStrings = (char *)uprv_malloc(tagBlock.top + stringBlock.top); 1067ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru createNormalizedAliasStrings(normalizedStrings, tagBlock.store, tagBlock.top); 1068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru createNormalizedAliasStrings(normalizedStrings + tagBlock.top, stringBlock.store, stringBlock.top); 1069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Write out the complete normalized array. */ 1071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru udata_writeString(out, normalizedStrings, tagBlock.top + stringBlock.top); 1072ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_free(normalizedStrings); 1073ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 107554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius uprv_free(uniqueAliasesToConverter); 1076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_free(uniqueAliases); 107754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius uprv_free(aliasArrLists); 1078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1079ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1080ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic char * 1081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruallocString(StringBlock *block, const char *s, int32_t length) { 1082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t top; 1083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *p; 1084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1085ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(length<0) { 1086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru length=(int32_t)uprv_strlen(s); 1087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1088ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 1090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * add 1 for the terminating NUL 1091ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and round up (+1 &~1) 1092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * to keep the addresses on a 16-bit boundary 1093ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 1094ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru top=block->top + (uint32_t)((length + 1 + 1) & ~1); 1095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(top >= block->max) { 109785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: out of memory\n", path, lineNum); 1098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_MEMORY_ALLOCATION_ERROR); 1099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* get the pointer and copy the string */ 1102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru p = block->store + block->top; 1103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_memcpy(p, s, length); 1104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru p[length] = 0; /* NUL-terminate it */ 1105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if((length & 1) == 0) { 1106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru p[length + 1] = 0; /* set the padding byte */ 1107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* check for invariant characters now that we have a NUL-terminated string for easy output */ 1110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!uprv_isInvariantString(p, length)) { 111185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho fprintf(stderr, "%s:%d: error: the name %s contains not just invariant characters\n", path, lineNum, p); 1112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(U_INVALID_TABLE_FORMAT); 1113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru block->top = top; 1116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return p; 1117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int 1120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerucompareAliases(const void *alias1, const void *alias2) { 1121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Names like IBM850 and ibm-850 need to be sorted together */ 1122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int result = ucnv_compareNames(GET_ALIAS_STR(*(uint16_t*)alias1), GET_ALIAS_STR(*(uint16_t*)alias2)); 1123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!result) { 1124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Sort the shortest first */ 1125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return (int)uprv_strlen(GET_ALIAS_STR(*(uint16_t*)alias1)) - (int)uprv_strlen(GET_ALIAS_STR(*(uint16_t*)alias2)); 1126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return result; 1128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 1131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Hey, Emacs, please set the following: 1132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 1133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Local Variables: 1134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * indent-tabs-mode: nil 1135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * End: 1136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 1137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 1138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1139