diff options
Diffstat (limited to 'deps/node/deps/icu-small/source/tools')
79 files changed, 0 insertions, 29283 deletions
diff --git a/deps/node/deps/icu-small/source/tools/escapesrc/cptbl.h b/deps/node/deps/icu-small/source/tools/escapesrc/cptbl.h deleted file mode 100644 index efaa9642..00000000 --- a/deps/node/deps/icu-small/source/tools/escapesrc/cptbl.h +++ /dev/null @@ -1,520 +0,0 @@ -// Copyright (C) 2016 and later: Unicode, Inc. and others. License & terms of use: http://www.unicode.org/copyright.html -// generated by tblgen. You weren't going to edit it by hand, were you? - -static const char cp1047_8859_1[256] = { - (char)0x00, /* 00 */ - (char)0x01, /* 01 */ - (char)0x02, /* 02 */ - (char)0x03, /* 03 */ - (char)0x9C, /* 04 */ - (char)0x09, /* 05 */ - (char)0x86, /* 06 */ - (char)0x7F, /* 07 */ - (char)0x97, /* 08 */ - (char)0x8D, /* 09 */ - (char)0x8E, /* 0A */ - (char)0x0B, /* 0B */ - (char)0x0C, /* 0C */ - (char)0x0D, /* 0D */ - (char)0x0E, /* 0E */ - (char)0x0F, /* 0F */ - (char)0x10, /* 10 */ - (char)0x11, /* 11 */ - (char)0x12, /* 12 */ - (char)0x13, /* 13 */ - (char)0x9D, /* 14 */ - (char)0x85, /* 15 */ - (char)0x08, /* 16 */ - (char)0x87, /* 17 */ - (char)0x18, /* 18 */ - (char)0x19, /* 19 */ - (char)0x92, /* 1A */ - (char)0x8F, /* 1B */ - (char)0x1C, /* 1C */ - (char)0x1D, /* 1D */ - (char)0x1E, /* 1E */ - (char)0x1F, /* 1F */ - (char)0x80, /* 20 */ - (char)0x81, /* 21 */ - (char)0x82, /* 22 */ - (char)0x83, /* 23 */ - (char)0x84, /* 24 */ - (char)0x0A, /* 25 */ - (char)0x17, /* 26 */ - (char)0x1B, /* 27 */ - (char)0x88, /* 28 */ - (char)0x89, /* 29 */ - (char)0x8A, /* 2A */ - (char)0x8B, /* 2B */ - (char)0x8C, /* 2C */ - (char)0x05, /* 2D */ - (char)0x06, /* 2E */ - (char)0x07, /* 2F */ - (char)0x90, /* 30 */ - (char)0x91, /* 31 */ - (char)0x16, /* 32 */ - (char)0x93, /* 33 */ - (char)0x94, /* 34 */ - (char)0x95, /* 35 */ - (char)0x96, /* 36 */ - (char)0x04, /* 37 */ - (char)0x98, /* 38 */ - (char)0x99, /* 39 */ - (char)0x9A, /* 3A */ - (char)0x9B, /* 3B */ - (char)0x14, /* 3C */ - (char)0x15, /* 3D */ - (char)0x9E, /* 3E */ - (char)0x1A, /* 3F */ - (char)0x20, /* 40 */ - (char)0xA0, /* 41 */ - (char)0xE2, /* 42 */ - (char)0xE4, /* 43 */ - (char)0xE0, /* 44 */ - (char)0xE1, /* 45 */ - (char)0xE3, /* 46 */ - (char)0xE5, /* 47 */ - (char)0xE7, /* 48 */ - (char)0xF1, /* 49 */ - (char)0xA2, /* 4A */ - (char)0x2E, /* 4B */ - (char)0x3C, /* 4C */ - (char)0x28, /* 4D */ - (char)0x2B, /* 4E */ - (char)0x7C, /* 4F */ - (char)0x26, /* 50 */ - (char)0xE9, /* 51 */ - (char)0xEA, /* 52 */ - (char)0xEB, /* 53 */ - (char)0xE8, /* 54 */ - (char)0xED, /* 55 */ - (char)0xEE, /* 56 */ - (char)0xEF, /* 57 */ - (char)0xEC, /* 58 */ - (char)0xDF, /* 59 */ - (char)0x21, /* 5A */ - (char)0x24, /* 5B */ - (char)0x2A, /* 5C */ - (char)0x29, /* 5D */ - (char)0x3B, /* 5E */ - (char)0x5E, /* 5F */ - (char)0x2D, /* 60 */ - (char)0x2F, /* 61 */ - (char)0xC2, /* 62 */ - (char)0xC4, /* 63 */ - (char)0xC0, /* 64 */ - (char)0xC1, /* 65 */ - (char)0xC3, /* 66 */ - (char)0xC5, /* 67 */ - (char)0xC7, /* 68 */ - (char)0xD1, /* 69 */ - (char)0xA6, /* 6A */ - (char)0x2C, /* 6B */ - (char)0x25, /* 6C */ - (char)0x5F, /* 6D */ - (char)0x3E, /* 6E */ - (char)0x3F, /* 6F */ - (char)0xF8, /* 70 */ - (char)0xC9, /* 71 */ - (char)0xCA, /* 72 */ - (char)0xCB, /* 73 */ - (char)0xC8, /* 74 */ - (char)0xCD, /* 75 */ - (char)0xCE, /* 76 */ - (char)0xCF, /* 77 */ - (char)0xCC, /* 78 */ - (char)0x60, /* 79 */ - (char)0x3A, /* 7A */ - (char)0x23, /* 7B */ - (char)0x40, /* 7C */ - (char)0x27, /* 7D */ - (char)0x3D, /* 7E */ - (char)0x22, /* 7F */ - (char)0xD8, /* 80 */ - (char)0x61, /* 81 */ - (char)0x62, /* 82 */ - (char)0x63, /* 83 */ - (char)0x64, /* 84 */ - (char)0x65, /* 85 */ - (char)0x66, /* 86 */ - (char)0x67, /* 87 */ - (char)0x68, /* 88 */ - (char)0x69, /* 89 */ - (char)0xAB, /* 8A */ - (char)0xBB, /* 8B */ - (char)0xF0, /* 8C */ - (char)0xFD, /* 8D */ - (char)0xFE, /* 8E */ - (char)0xB1, /* 8F */ - (char)0xB0, /* 90 */ - (char)0x6A, /* 91 */ - (char)0x6B, /* 92 */ - (char)0x6C, /* 93 */ - (char)0x6D, /* 94 */ - (char)0x6E, /* 95 */ - (char)0x6F, /* 96 */ - (char)0x70, /* 97 */ - (char)0x71, /* 98 */ - (char)0x72, /* 99 */ - (char)0xAA, /* 9A */ - (char)0xBA, /* 9B */ - (char)0xE6, /* 9C */ - (char)0xB8, /* 9D */ - (char)0xC6, /* 9E */ - (char)0xA4, /* 9F */ - (char)0xB5, /* A0 */ - (char)0x7E, /* A1 */ - (char)0x73, /* A2 */ - (char)0x74, /* A3 */ - (char)0x75, /* A4 */ - (char)0x76, /* A5 */ - (char)0x77, /* A6 */ - (char)0x78, /* A7 */ - (char)0x79, /* A8 */ - (char)0x7A, /* A9 */ - (char)0xA1, /* AA */ - (char)0xBF, /* AB */ - (char)0xD0, /* AC */ - (char)0x5B, /* AD */ - (char)0xDE, /* AE */ - (char)0xAE, /* AF */ - (char)0xAC, /* B0 */ - (char)0xA3, /* B1 */ - (char)0xA5, /* B2 */ - (char)0xB7, /* B3 */ - (char)0xA9, /* B4 */ - (char)0xA7, /* B5 */ - (char)0xB6, /* B6 */ - (char)0xBC, /* B7 */ - (char)0xBD, /* B8 */ - (char)0xBE, /* B9 */ - (char)0xDD, /* BA */ - (char)0xA8, /* BB */ - (char)0xAF, /* BC */ - (char)0x5D, /* BD */ - (char)0xB4, /* BE */ - (char)0xD7, /* BF */ - (char)0x7B, /* C0 */ - (char)0x41, /* C1 */ - (char)0x42, /* C2 */ - (char)0x43, /* C3 */ - (char)0x44, /* C4 */ - (char)0x45, /* C5 */ - (char)0x46, /* C6 */ - (char)0x47, /* C7 */ - (char)0x48, /* C8 */ - (char)0x49, /* C9 */ - (char)0xAD, /* CA */ - (char)0xF4, /* CB */ - (char)0xF6, /* CC */ - (char)0xF2, /* CD */ - (char)0xF3, /* CE */ - (char)0xF5, /* CF */ - (char)0x7D, /* D0 */ - (char)0x4A, /* D1 */ - (char)0x4B, /* D2 */ - (char)0x4C, /* D3 */ - (char)0x4D, /* D4 */ - (char)0x4E, /* D5 */ - (char)0x4F, /* D6 */ - (char)0x50, /* D7 */ - (char)0x51, /* D8 */ - (char)0x52, /* D9 */ - (char)0xB9, /* DA */ - (char)0xFB, /* DB */ - (char)0xFC, /* DC */ - (char)0xF9, /* DD */ - (char)0xFA, /* DE */ - (char)0xFF, /* DF */ - (char)0x5C, /* E0 */ - (char)0xF7, /* E1 */ - (char)0x53, /* E2 */ - (char)0x54, /* E3 */ - (char)0x55, /* E4 */ - (char)0x56, /* E5 */ - (char)0x57, /* E6 */ - (char)0x58, /* E7 */ - (char)0x59, /* E8 */ - (char)0x5A, /* E9 */ - (char)0xB2, /* EA */ - (char)0xD4, /* EB */ - (char)0xD6, /* EC */ - (char)0xD2, /* ED */ - (char)0xD3, /* EE */ - (char)0xD5, /* EF */ - (char)0x30, /* F0 */ - (char)0x31, /* F1 */ - (char)0x32, /* F2 */ - (char)0x33, /* F3 */ - (char)0x34, /* F4 */ - (char)0x35, /* F5 */ - (char)0x36, /* F6 */ - (char)0x37, /* F7 */ - (char)0x38, /* F8 */ - (char)0x39, /* F9 */ - (char)0xB3, /* FA */ - (char)0xDB, /* FB */ - (char)0xDC, /* FC */ - (char)0xD9, /* FD */ - (char)0xDA, /* FE */ - (char)0x9F, /* FF */ -}; - -static const bool oldIllegal[256] = { - false, /* U+0000 */ - false, /* U+0001 */ - false, /* U+0002 */ - false, /* U+0003 */ - false, /* U+0004 */ - false, /* U+0005 */ - false, /* U+0006 */ - false, /* U+0007 */ - false, /* U+0008 */ - false, /* U+0009 */ - false, /* U+000A */ - false, /* U+000B */ - false, /* U+000C */ - false, /* U+000D */ - false, /* U+000E */ - false, /* U+000F */ - false, /* U+0010 */ - false, /* U+0011 */ - false, /* U+0012 */ - false, /* U+0013 */ - false, /* U+0014 */ - false, /* U+0015 */ - false, /* U+0016 */ - false, /* U+0017 */ - false, /* U+0018 */ - false, /* U+0019 */ - false, /* U+001A */ - false, /* U+001B */ - false, /* U+001C */ - false, /* U+001D */ - false, /* U+001E */ - false, /* U+001F */ - true, /* U+0020 */ - true, /* U+0021 */ - true, /* U+0022 */ - true, /* U+0023 */ - false, /* U+0024 */ - true, /* U+0025 */ - true, /* U+0026 */ - true, /* U+0027 */ - true, /* U+0028 */ - true, /* U+0029 */ - true, /* U+002A */ - true, /* U+002B */ - true, /* U+002C */ - true, /* U+002D */ - true, /* U+002E */ - true, /* U+002F */ - true, /* U+0030 */ - true, /* U+0031 */ - true, /* U+0032 */ - true, /* U+0033 */ - true, /* U+0034 */ - true, /* U+0035 */ - true, /* U+0036 */ - true, /* U+0037 */ - true, /* U+0038 */ - true, /* U+0039 */ - true, /* U+003A */ - true, /* U+003B */ - true, /* U+003C */ - true, /* U+003D */ - true, /* U+003E */ - true, /* U+003F */ - false, /* U+0040 */ - true, /* U+0041 */ - true, /* U+0042 */ - true, /* U+0043 */ - true, /* U+0044 */ - true, /* U+0045 */ - true, /* U+0046 */ - true, /* U+0047 */ - true, /* U+0048 */ - true, /* U+0049 */ - true, /* U+004A */ - true, /* U+004B */ - true, /* U+004C */ - true, /* U+004D */ - true, /* U+004E */ - true, /* U+004F */ - true, /* U+0050 */ - true, /* U+0051 */ - true, /* U+0052 */ - true, /* U+0053 */ - true, /* U+0054 */ - true, /* U+0055 */ - true, /* U+0056 */ - true, /* U+0057 */ - true, /* U+0058 */ - true, /* U+0059 */ - true, /* U+005A */ - true, /* U+005B */ - false, /* U+005C */ - true, /* U+005D */ - true, /* U+005E */ - true, /* U+005F */ - false, /* U+0060 */ - true, /* U+0061 */ - true, /* U+0062 */ - true, /* U+0063 */ - true, /* U+0064 */ - true, /* U+0065 */ - true, /* U+0066 */ - true, /* U+0067 */ - true, /* U+0068 */ - true, /* U+0069 */ - true, /* U+006A */ - true, /* U+006B */ - true, /* U+006C */ - true, /* U+006D */ - true, /* U+006E */ - true, /* U+006F */ - true, /* U+0070 */ - true, /* U+0071 */ - true, /* U+0072 */ - true, /* U+0073 */ - true, /* U+0074 */ - true, /* U+0075 */ - true, /* U+0076 */ - true, /* U+0077 */ - true, /* U+0078 */ - true, /* U+0079 */ - true, /* U+007A */ - true, /* U+007B */ - true, /* U+007C */ - true, /* U+007D */ - true, /* U+007E */ - false, /* U+007F */ - false, /* U+0080 */ - false, /* U+0081 */ - false, /* U+0082 */ - false, /* U+0083 */ - false, /* U+0084 */ - false, /* U+0085 */ - false, /* U+0086 */ - false, /* U+0087 */ - false, /* U+0088 */ - false, /* U+0089 */ - false, /* U+008A */ - false, /* U+008B */ - false, /* U+008C */ - false, /* U+008D */ - false, /* U+008E */ - false, /* U+008F */ - false, /* U+0090 */ - false, /* U+0091 */ - false, /* U+0092 */ - false, /* U+0093 */ - false, /* U+0094 */ - false, /* U+0095 */ - false, /* U+0096 */ - false, /* U+0097 */ - false, /* U+0098 */ - false, /* U+0099 */ - false, /* U+009A */ - false, /* U+009B */ - false, /* U+009C */ - false, /* U+009D */ - false, /* U+009E */ - false, /* U+009F */ - false, /* U+00A0 */ - false, /* U+00A1 */ - false, /* U+00A2 */ - false, /* U+00A3 */ - false, /* U+00A4 */ - false, /* U+00A5 */ - false, /* U+00A6 */ - false, /* U+00A7 */ - false, /* U+00A8 */ - false, /* U+00A9 */ - false, /* U+00AA */ - false, /* U+00AB */ - false, /* U+00AC */ - false, /* U+00AD */ - false, /* U+00AE */ - false, /* U+00AF */ - false, /* U+00B0 */ - false, /* U+00B1 */ - false, /* U+00B2 */ - false, /* U+00B3 */ - false, /* U+00B4 */ - false, /* U+00B5 */ - false, /* U+00B6 */ - false, /* U+00B7 */ - false, /* U+00B8 */ - false, /* U+00B9 */ - false, /* U+00BA */ - false, /* U+00BB */ - false, /* U+00BC */ - false, /* U+00BD */ - false, /* U+00BE */ - false, /* U+00BF */ - false, /* U+00C0 */ - false, /* U+00C1 */ - false, /* U+00C2 */ - false, /* U+00C3 */ - false, /* U+00C4 */ - false, /* U+00C5 */ - false, /* U+00C6 */ - false, /* U+00C7 */ - false, /* U+00C8 */ - false, /* U+00C9 */ - false, /* U+00CA */ - false, /* U+00CB */ - false, /* U+00CC */ - false, /* U+00CD */ - false, /* U+00CE */ - false, /* U+00CF */ - false, /* U+00D0 */ - false, /* U+00D1 */ - false, /* U+00D2 */ - false, /* U+00D3 */ - false, /* U+00D4 */ - false, /* U+00D5 */ - false, /* U+00D6 */ - false, /* U+00D7 */ - false, /* U+00D8 */ - false, /* U+00D9 */ - false, /* U+00DA */ - false, /* U+00DB */ - false, /* U+00DC */ - false, /* U+00DD */ - false, /* U+00DE */ - false, /* U+00DF */ - false, /* U+00E0 */ - false, /* U+00E1 */ - false, /* U+00E2 */ - false, /* U+00E3 */ - false, /* U+00E4 */ - false, /* U+00E5 */ - false, /* U+00E6 */ - false, /* U+00E7 */ - false, /* U+00E8 */ - false, /* U+00E9 */ - false, /* U+00EA */ - false, /* U+00EB */ - false, /* U+00EC */ - false, /* U+00ED */ - false, /* U+00EE */ - false, /* U+00EF */ - false, /* U+00F0 */ - false, /* U+00F1 */ - false, /* U+00F2 */ - false, /* U+00F3 */ - false, /* U+00F4 */ - false, /* U+00F5 */ - false, /* U+00F6 */ - false, /* U+00F7 */ - false, /* U+00F8 */ - false, /* U+00F9 */ - false, /* U+00FA */ - false, /* U+00FB */ - false, /* U+00FC */ - false, /* U+00FD */ - false, /* U+00FE */ - false, /* U+00FF */ -}; diff --git a/deps/node/deps/icu-small/source/tools/escapesrc/escapesrc.cpp b/deps/node/deps/icu-small/source/tools/escapesrc/escapesrc.cpp deleted file mode 100644 index f51a86ea..00000000 --- a/deps/node/deps/icu-small/source/tools/escapesrc/escapesrc.cpp +++ /dev/null @@ -1,420 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html - -#include <stdio.h> -#include <string> -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <iostream> -#include <fstream> - -// We only use U8_* macros, which are entirely inline. -#include "unicode/utf8.h" - -// This contains a codepage and ISO 14882:1998 illegality table. -// Use "make gen-table" to rebuild it. -#include "cptbl.h" - -/** - * What is this? - * - * "This" is a preprocessor that makes an attempt to convert fully valid C++11 source code - * in utf-8 into something consumable by certain compilers (Solaris, xlC) - * which aren't quite standards compliant. - * - * - u"<unicode>" or u'<unicode>' gets converted to u"\uNNNN" or u'\uNNNN' - * - u8"<unicode>" gets converted to "\xAA\xBB\xCC\xDD" etc. - * (some compilers do not support the u8 prefix correctly.) - * - if the system is EBCDIC-based, that is used to correct the input characters. - * - * Usage: - * escapesrc infile.cpp outfile.cpp - * Normally this is invoked by the build stage, with a rule such as: - * - * _%.cpp: $(srcdir)/%.cpp - * @$(BINDIR)/escapesrc$(EXEEXT) $< $@ - * %.o: _%.cpp - * $(COMPILE.cc) ... $@ $< - * - * In the Makefiles, SKIP_ESCAPING=YES is used to prevent escapesrc.cpp - * from being itself escaped. - */ - - -static const char - kSPACE = 0x20, - kTAB = 0x09, - kLF = 0x0A, - kCR = 0x0D; - -// For convenience -# define cp1047_to_8859(c) cp1047_8859_1[c] - -// Our app's name -std::string prog; - -/** - * Give the usual 1-line documentation and exit - */ -void usage() { - fprintf(stderr, "%s: usage: %s infile.cpp outfile.cpp\n", prog.c_str(), prog.c_str()); -} - -/** - * Delete the output file (if any) - * We want to delete even if we didn't generate, because it might be stale. - */ -int cleanup(const std::string &outfile) { - const char *outstr = outfile.c_str(); - if(outstr && *outstr) { - int rc = std::remove(outstr); - if(rc == 0) { - fprintf(stderr, "%s: deleted %s\n", prog.c_str(), outstr); - return 0; - } else { - if( errno == ENOENT ) { - return 0; // File did not exist - no error. - } else { - perror("std::remove"); - return 1; - } - } - } - return 0; -} - -/** - * Skip across any known whitespace. - * @param p startpoint - * @param e limit - * @return first non-whitespace char - */ -inline const char *skipws(const char *p, const char *e) { - for(;p<e;p++) { - switch(*p) { - case kSPACE: - case kTAB: - case kLF: - case kCR: - break; - default: - return p; // non ws - } - } - return p; -} - -/** - * Append a byte, hex encoded - * @param outstr sstring to append to - * @param byte the byte to append - */ -void appendByte(std::string &outstr, - uint8_t byte) { - char tmp2[5]; - sprintf(tmp2, "\\x%02X", 0xFF & (int)(byte)); - outstr += tmp2; -} - -/** - * Append the bytes from 'linestr' into outstr, with escaping - * @param outstr the output buffer - * @param linestr the input buffer - * @param pos in/out: the current char under consideration - * @param chars the number of chars to consider - * @return true on failure - */ -bool appendUtf8(std::string &outstr, - const std::string &linestr, - size_t &pos, - size_t chars) { - char tmp[9]; - for(size_t i=0;i<chars;i++) { - tmp[i] = linestr[++pos]; - } - tmp[chars] = 0; - unsigned int c; - sscanf(tmp, "%X", &c); - UChar32 ch = c & 0x1FFFFF; - - // now to append \\x%% etc - uint8_t bytesNeeded = U8_LENGTH(ch); - if(bytesNeeded == 0) { - fprintf(stderr, "Illegal code point U+%X\n", ch); - return true; - } - uint8_t bytes[4]; - uint8_t *s = bytes; - size_t i = 0; - U8_APPEND_UNSAFE(s, i, ch); - for(size_t t = 0; t<i; t++) { - appendByte(outstr, s[t]); - } - return false; -} - -/** - * Fixup u8"x" - * @param linestr string to mutate. Already escaped into \u format. - * @param origpos beginning, points to 'u8"' - * @param pos end, points to " - * @return false for no-problem, true for failure! - */ -bool fixu8(std::string &linestr, size_t origpos, size_t &endpos) { - size_t pos = origpos + 3; - std::string outstr; - outstr += '\"'; // local encoding - for(;pos<endpos;pos++) { - char c = linestr[pos]; - if(c == '\\') { - char c2 = linestr[++pos]; - switch(c2) { - case '\'': - case '"': -#if (U_CHARSET_FAMILY == U_EBCDIC_FAMILY) - c2 = cp1047_to_8859(c2); -#endif - appendByte(outstr, c2); - break; - case 'u': - appendUtf8(outstr, linestr, pos, 4); - break; - case 'U': - appendUtf8(outstr, linestr, pos, 8); - break; - } - } else { -#if (U_CHARSET_FAMILY == U_EBCDIC_FAMILY) - c = cp1047_to_8859(c); -#endif - appendByte(outstr, c); - } - } - outstr += ('\"'); - - linestr.replace(origpos, (endpos-origpos+1), outstr); - - return false; // OK -} - -/** - * fix the u"x"/u'x'/u8"x" string at the position - * u8'x' is not supported, sorry. - * @param linestr the input string - * @param pos the position - * @return false = no err, true = had err - */ -bool fixAt(std::string &linestr, size_t pos) { - size_t origpos = pos; - - if(linestr[pos] != 'u') { - fprintf(stderr, "Not a 'u'?"); - return true; - } - - pos++; // past 'u' - - bool utf8 = false; - - if(linestr[pos] == '8') { // u8" - utf8 = true; - pos++; - } - - char quote = linestr[pos]; - - if(quote != '\'' && quote != '\"') { - fprintf(stderr, "Quote is '%c' - not sure what to do.\n", quote); - return true; - } - - if(quote == '\'' && utf8) { - fprintf(stderr, "Cannot do u8'...'\n"); - return true; - } - - pos ++; - - //printf("u%c…%c\n", quote, quote); - - for(; pos < linestr.size(); pos++) { - if(linestr[pos] == quote) { - if(utf8) { - return fixu8(linestr, origpos, pos); // fix u8"..." - } else { - return false; // end of quote - } - } - if(linestr[pos] == '\\') { - pos++; - if(linestr[pos] == quote) continue; // quoted quote - if(linestr[pos] == 'u') continue; // for now ... unicode escape - if(linestr[pos] == '\\') continue; - // some other escape… ignore - } else { - size_t old_pos = pos; - int32_t i = pos; -#if (U_CHARSET_FAMILY == U_EBCDIC_FAMILY) - // mogrify 1-4 bytes from 1047 'back' to utf-8 - char old_byte = linestr[pos]; - linestr[pos] = cp1047_to_8859(linestr[pos]); - // how many more? - int32_t trail = U8_COUNT_TRAIL_BYTES(linestr[pos]); - for(size_t pos2 = pos+1; trail>0; pos2++,trail--) { - linestr[pos2] = cp1047_to_8859(linestr[pos2]); - if(linestr[pos2] == 0x0A) { - linestr[pos2] = 0x85; // NL is ambiguous here - } - } -#endif - - // Proceed to decode utf-8 - const uint8_t *s = (const uint8_t*) (linestr.c_str()); - int32_t length = linestr.size(); - UChar32 c; - if(U8_IS_SINGLE((uint8_t)s[i]) && oldIllegal[s[i]]) { -#if (U_CHARSET_FAMILY == U_EBCDIC_FAMILY) - linestr[pos] = old_byte; // put it back -#endif - continue; // single code point not previously legal for \u escaping - } - - // otherwise, convert it to \u / \U - { - U8_NEXT(s, i, length, c); - } - if(c<0) { - fprintf(stderr, "Illegal utf-8 sequence at Column: %d\n", (int)old_pos); - fprintf(stderr, "Line: >>%s<<\n", linestr.c_str()); - return true; - } - - size_t seqLen = (i-pos); - - //printf("U+%04X pos %d [len %d]\n", c, pos, seqLen);fflush(stdout); - - char newSeq[20]; - if( c <= 0xFFFF) { - sprintf(newSeq, "\\u%04X", c); - } else { - sprintf(newSeq, "\\U%08X", c); - } - linestr.replace(pos, seqLen, newSeq); - pos += strlen(newSeq) - 1; - } - } - - return false; -} - -/** - * Fixup an entire line - * false = no err - * true = had err - * @param no the line number (not used) - * @param linestr the string to fix - * @return true if any err, else false - */ -bool fixLine(int /*no*/, std::string &linestr) { - const char *line = linestr.c_str(); - size_t len = linestr.size(); - - // no u' in the line? - if(!strstr(line, "u'") && !strstr(line, "u\"") && !strstr(line, "u8\"")) { - return false; // Nothing to do. No u' or u" detected - } - - // start from the end and find all u" cases - size_t pos = len = linestr.size(); - while((pos>0) && (pos = linestr.rfind("u\"", pos)) != std::string::npos) { - //printf("found doublequote at %d\n", pos); - if(fixAt(linestr, pos)) return true; - if(pos == 0) break; - pos--; - } - - // reset and find all u' cases - pos = len = linestr.size(); - while((pos>0) && (pos = linestr.rfind("u'", pos)) != std::string::npos) { - //printf("found singlequote at %d\n", pos); - if(fixAt(linestr, pos)) return true; - if(pos == 0) break; - pos--; - } - - // reset and find all u8" cases - pos = len = linestr.size(); - while((pos>0) && (pos = linestr.rfind("u8\"", pos)) != std::string::npos) { - if(fixAt(linestr, pos)) return true; - if(pos == 0) break; - pos--; - } - - //fprintf(stderr, "%d - fixed\n", no); - return false; -} - -/** - * Convert a whole file - * @param infile - * @param outfile - * @return 1 on err, 0 otherwise - */ -int convert(const std::string &infile, const std::string &outfile) { - fprintf(stderr, "escapesrc: %s -> %s\n", infile.c_str(), outfile.c_str()); - - std::ifstream inf; - - inf.open(infile.c_str(), std::ios::in); - - if(!inf.is_open()) { - fprintf(stderr, "%s: could not open input file %s\n", prog.c_str(), infile.c_str()); - cleanup(outfile); - return 1; - } - - std::ofstream outf; - - outf.open(outfile.c_str(), std::ios::out); - - if(!outf.is_open()) { - fprintf(stderr, "%s: could not open output file %s\n", prog.c_str(), outfile.c_str()); - return 1; - } - - // TODO: any platform variations of #line? - outf << "#line 1 \"" << infile << "\"" << '\n'; - - int no = 0; - std::string linestr; - while( getline( inf, linestr)) { - no++; - if(fixLine(no, linestr)) { - outf.close(); - fprintf(stderr, "%s:%d: Fixup failed by %s\n", infile.c_str(), no, prog.c_str()); - cleanup(outfile); - return 1; - } - outf << linestr << '\n'; - } - - return 0; -} - -/** - * Main function - */ -int main(int argc, const char *argv[]) { - prog = argv[0]; - - if(argc != 3) { - usage(); - return 1; - } - - std::string infile = argv[1]; - std::string outfile = argv[2]; - - return convert(infile, outfile); -} diff --git a/deps/node/deps/icu-small/source/tools/escapesrc/expect-simple.cpp b/deps/node/deps/icu-small/source/tools/escapesrc/expect-simple.cpp deleted file mode 100644 index a6019a8d..00000000 --- a/deps/node/deps/icu-small/source/tools/escapesrc/expect-simple.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html - -u"sa\u0127\u0127a"; -u'\u6587'; -u"\U000219F2"; -u"\u039C\u03C5\u03C3\u03C4\u03AE\u03C1\u03B9\u03BF"; - - u"sa\u0127\u0127a"; - u'\u6587'; u"\U000219F2"; - -"\x20\xCC\x81"; -"\xCC\x88\x20"; -"\x73\x61\xC4\xA7\xC4\xA7\x61"; -"\xE6\x96\x87"; -"\xF0\xA1\xA7\xB2"; -"\x73\x61\xC4\xA7\xC4\xA7\x61"; diff --git a/deps/node/deps/icu-small/source/tools/escapesrc/tblgen.cpp b/deps/node/deps/icu-small/source/tools/escapesrc/tblgen.cpp deleted file mode 100644 index 9bf59a9d..00000000 --- a/deps/node/deps/icu-small/source/tools/escapesrc/tblgen.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html - -#include "unicode/utypes.h" -#include "unicode/ucnv.h" -#include "unicode/uniset.h" -#include <stdio.h> - -static const char *kConverter = "ibm-1047"; - -int main(int argc, const char *argv[]) { - printf("// %s\n", U_COPYRIGHT_STRING); - printf("// generated by tblgen. You weren't going to edit it by hand, were you?\n"); - printf("\n"); - - UErrorCode status = U_ZERO_ERROR; - LocalUConverterPointer cnv(ucnv_open(kConverter, &status)); - - if(U_FAILURE(status)) { - fprintf(stderr, "Failed to open %s: %s\n", kConverter, u_errorName(status)); - return 1; - } - - printf("static const char cp1047_8859_1[256] = { \n"); - for(int i=0x00; i<0x100; i++) { - char cp1047[1]; - cp1047[0] = i; - UChar u[1]; - UChar *target = u; - const char *source = cp1047; - ucnv_toUnicode(cnv.getAlias(), &target, u+1, &source, cp1047+1, nullptr, true, &status); - if(U_FAILURE(status)) { - fprintf(stderr, "Conversion failure at #%X: %s\n", i, u_errorName(status)); - return 2; - } - printf(" (char)0x%02X, /* %02X */\n", u[0], i); - } - printf("};\n\n"); - - // - // UnicodeSet oldIllegal("[:print:]", status); // [a-zA-Z0-9_}{#)(><%:;.?*+-/^&|~!=,\\u005b\\u005d\\u005c]", status); - UnicodeSet oldIllegal("[0-9 a-z A-Z " - "_ \\{ \\} \\[ \\] # \\( \\) < > % \\: ; . " - "? * + \\- / \\^ \\& | ~ ! = , \\ \" ' ]", status); - - /* - -http://www.lirmm.fr/~ducour/Doc-objets/ISO+IEC+14882-1998.pdf ( note: 1998 ) page 10, section 2.2 says: - -1 The basic source character set consists of 96 characters: the space character, the control characters repre- 15) -senting horizontal tab, vertical tab, form feed, and new-line, plus the following 91 graphical characters: -a b c d e f g h i j k l m n opqrstuvwxyz -A B C D E F G H I J K L M N OPQRSTUVWXYZ -0 12 3 4 5 6 7 8 9 - _ { } [ ] # ( ) < > % : ; . ?*+-/^&|~!=,\" -2 The universal-character-name construct provides a way to name other characters. hex-quad: -hexadecimal-digit hexadecimal-digit hexadecimal-digit hexadecimal-digit -universal-character-name: \u hex-quad -\U hex-quad hex-quad -The character designated by the universal-character-name \UNNNNNNNN is that character whose character short name in ISO/IEC 10646 is NNNNNNNN; the character designated by the universal-character-name \uNNNN is that character whose character short name in ISO/IEC 10646 is 0000NNNN. If the hexadecimal value for a universal character name is less than 0x20 or in the range 0x7F-0x9F (inclusive), or if the uni- versal character name designates a character in the basic source character set, then the program is ill- formed. - - -So basically: printable ASCII plus 0x00-0x1F, 0x7F-0x9F, was all illegal. - -Some discussion at http://unicode.org/mail-arch/unicode-ml/y2003-m10/0471.html - - */ - - - - printf("static const bool oldIllegal[256] = { \n"); - for(UChar i=0x00; i<0x100;i++) { - printf(" %s, /* U+%04X */\n", - (oldIllegal.contains(i))?" true":"false", - i); - } - printf("};\n\n"); - - return 0; -} diff --git a/deps/node/deps/icu-small/source/tools/escapesrc/test-nochange.cpp b/deps/node/deps/icu-small/source/tools/escapesrc/test-nochange.cpp deleted file mode 100644 index 8c0d04b8..00000000 --- a/deps/node/deps/icu-small/source/tools/escapesrc/test-nochange.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html - -// This is a source file with no changes needed in it. -// In fact, the only non-ASCII character is the comment line at top. diff --git a/deps/node/deps/icu-small/source/tools/escapesrc/test-simple.cpp b/deps/node/deps/icu-small/source/tools/escapesrc/test-simple.cpp deleted file mode 100644 index b03f28f7..00000000 --- a/deps/node/deps/icu-small/source/tools/escapesrc/test-simple.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html - -u"saħħa"; -u'文'; -u"𡧲"; -u"Μυστήριο"; - - u"saħħa"; - u'文'; u"𡧲"; - -u8" \u0301"; -u8"\u0308 "; -u8"saħħa"; -u8"文"; -u8"𡧲"; -u8"saħ\u0127a"; diff --git a/deps/node/deps/icu-small/source/tools/genccode/genccode.c b/deps/node/deps/icu-small/source/tools/genccode/genccode.c deleted file mode 100644 index d35b5890..00000000 --- a/deps/node/deps/icu-small/source/tools/genccode/genccode.c +++ /dev/null @@ -1,199 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* - ******************************************************************************* - * Copyright (C) 1999-2016, International Business Machines - * Corporation and others. All Rights Reserved. - ******************************************************************************* - * file name: gennames.c - * encoding: UTF-8 - * tab size: 8 (not used) - * indentation:4 - * - * created on: 1999nov01 - * created by: Markus W. Scherer - * - * This program reads a binary file and creates a C source code file - * with a byte array that contains the data of the binary file. - * - * 12/09/1999 weiv Added multiple file handling - */ - -#include "unicode/utypes.h" - -#if U_PLATFORM_HAS_WIN32_API -# define VC_EXTRALEAN -# define WIN32_LEAN_AND_MEAN -# define NOUSER -# define NOSERVICE -# define NOIME -# define NOMCX -#include <windows.h> -#include <time.h> -#endif - -#if U_PLATFORM_IS_LINUX_BASED && U_HAVE_ELF_H -# define U_ELF -#endif - -#ifdef U_ELF -# include <elf.h> -# if defined(ELFCLASS64) -# define U_ELF64 -# endif - /* Old elf.h headers may not have EM_X86_64, or have EM_X8664 instead. */ -# ifndef EM_X86_64 -# define EM_X86_64 62 -# endif -# define ICU_ENTRY_OFFSET 0 -#endif - -#include <stdio.h> -#include <stdlib.h> -#include "unicode/putil.h" -#include "cmemory.h" -#include "cstring.h" -#include "filestrm.h" -#include "toolutil.h" -#include "unicode/uclean.h" -#include "uoptions.h" -#include "pkg_genc.h" - -enum { - kOptHelpH = 0, - kOptHelpQuestionMark, - kOptDestDir, - kOptName, - kOptEntryPoint, -#ifdef CAN_GENERATE_OBJECTS - kOptObject, - kOptMatchArch, -#endif - kOptFilename, - kOptAssembly -}; - -static UOption options[]={ -/*0*/UOPTION_HELP_H, - UOPTION_HELP_QUESTION_MARK, - UOPTION_DESTDIR, - UOPTION_DEF("name", 'n', UOPT_REQUIRES_ARG), - UOPTION_DEF("entrypoint", 'e', UOPT_REQUIRES_ARG), -#ifdef CAN_GENERATE_OBJECTS -/*5*/UOPTION_DEF("object", 'o', UOPT_NO_ARG), - UOPTION_DEF("match-arch", 'm', UOPT_REQUIRES_ARG), -#endif - UOPTION_DEF("filename", 'f', UOPT_REQUIRES_ARG), - UOPTION_DEF("assembly", 'a', UOPT_REQUIRES_ARG) -}; - -#define CALL_WRITECCODE 'c' -#define CALL_WRITEASSEMBLY 'a' -#define CALL_WRITEOBJECT 'o' -extern int -main(int argc, char* argv[]) { - UBool verbose = TRUE; - char writeCode; - - U_MAIN_INIT_ARGS(argc, argv); - - options[kOptDestDir].value = "."; - - /* read command line options */ - argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); - - /* error handling, printing usage message */ - if(argc<0) { - fprintf(stderr, - "error in command line argument \"%s\"\n", - argv[-argc]); - } - if(argc<0 || options[kOptHelpH].doesOccur || options[kOptHelpQuestionMark].doesOccur) { - fprintf(stderr, - "usage: %s [-options] filename1 filename2 ...\n" - "\tread each binary input file and \n" - "\tcreate a .c file with a byte array that contains the input file's data\n" - "options:\n" - "\t-h or -? or --help this usage text\n" - "\t-d or --destdir destination directory, followed by the path\n" - "\t-n or --name symbol prefix, followed by the prefix\n" - "\t-e or --entrypoint entry point name, followed by the name (_dat will be appended)\n" - "\t-r or --revision Specify a version\n" - , argv[0]); -#ifdef CAN_GENERATE_OBJECTS - fprintf(stderr, - "\t-o or --object write a .obj file instead of .c\n" - "\t-m or --match-arch file.o match the architecture (CPU, 32/64 bits) of the specified .o\n" - "\t ELF format defaults to i386. Windows defaults to the native platform.\n"); -#endif - fprintf(stderr, - "\t-f or --filename Specify an alternate base filename. (default: symbolname_typ)\n" - "\t-a or --assembly Create assembly file. (possible values are: "); - - printAssemblyHeadersToStdErr(); - } else { - const char *message, *filename; - /* TODO: remove void (*writeCode)(const char *, const char *); */ - - if(options[kOptAssembly].doesOccur) { - message="generating assembly code for %s\n"; - writeCode = CALL_WRITEASSEMBLY; - /* TODO: remove writeCode=&writeAssemblyCode; */ - - if (!checkAssemblyHeaderName(options[kOptAssembly].value)) { - fprintf(stderr, - "Assembly type \"%s\" is unknown.\n", options[kOptAssembly].value); - return -1; - } - } -#ifdef CAN_GENERATE_OBJECTS - else if(options[kOptObject].doesOccur) { - message="generating object code for %s\n"; - writeCode = CALL_WRITEOBJECT; - /* TODO: remove writeCode=&writeObjectCode; */ - } -#endif - else - { - message="generating C code for %s\n"; - writeCode = CALL_WRITECCODE; - /* TODO: remove writeCode=&writeCCode; */ - } - while(--argc) { - filename=getLongPathname(argv[argc]); - if (verbose) { - fprintf(stdout, message, filename); - } - - switch (writeCode) { - case CALL_WRITECCODE: - writeCCode(filename, options[kOptDestDir].value, - options[kOptName].doesOccur ? options[kOptName].value : NULL, - options[kOptFilename].doesOccur ? options[kOptFilename].value : NULL, - NULL); - break; - case CALL_WRITEASSEMBLY: - writeAssemblyCode(filename, options[kOptDestDir].value, - options[kOptEntryPoint].doesOccur ? options[kOptEntryPoint].value : NULL, - options[kOptFilename].doesOccur ? options[kOptFilename].value : NULL, - NULL); - break; -#ifdef CAN_GENERATE_OBJECTS - case CALL_WRITEOBJECT: - writeObjectCode(filename, options[kOptDestDir].value, - options[kOptEntryPoint].doesOccur ? options[kOptEntryPoint].value : NULL, - options[kOptMatchArch].doesOccur ? options[kOptMatchArch].value : NULL, - options[kOptFilename].doesOccur ? options[kOptFilename].value : NULL, - NULL); - break; -#endif - default: - /* Should never occur. */ - break; - } - /* TODO: remove writeCode(filename, options[kOptDestDir].value); */ - } - } - - return 0; -} diff --git a/deps/node/deps/icu-small/source/tools/gencmn/gencmn.c b/deps/node/deps/icu-small/source/tools/gencmn/gencmn.c deleted file mode 100644 index 77f0c20c..00000000 --- a/deps/node/deps/icu-small/source/tools/gencmn/gencmn.c +++ /dev/null @@ -1,126 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1999-2016, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: gencmn.c -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 1999nov01 -* created by: Markus W. Scherer -* -* This program reads a list of data files and combines them -* into one common, memory-mappable file. -*/ - -#include <stdio.h> -#include <stdlib.h> -#include "unicode/utypes.h" -#include "unicode/putil.h" -#include "cmemory.h" -#include "cstring.h" -#include "filestrm.h" -#include "toolutil.h" -#include "unicode/uclean.h" -#include "unewdata.h" -#include "uoptions.h" -#include "putilimp.h" -#include "pkg_gencmn.h" - -static UOption options[]={ -/*0*/ UOPTION_HELP_H, -/*1*/ UOPTION_HELP_QUESTION_MARK, -/*2*/ UOPTION_VERBOSE, -/*3*/ UOPTION_COPYRIGHT, -/*4*/ UOPTION_DESTDIR, -/*5*/ UOPTION_DEF( "comment", 'C', UOPT_REQUIRES_ARG), -/*6*/ UOPTION_DEF( "name", 'n', UOPT_REQUIRES_ARG), -/*7*/ UOPTION_DEF( "type", 't', UOPT_REQUIRES_ARG), -/*8*/ UOPTION_DEF( "source", 'S', UOPT_NO_ARG), -/*9*/ UOPTION_DEF( "entrypoint", 'e', UOPT_REQUIRES_ARG), -/*10*/UOPTION_SOURCEDIR, -}; - -extern int -main(int argc, char* argv[]) { - UBool sourceTOC, verbose; - uint32_t maxSize; - - U_MAIN_INIT_ARGS(argc, argv); - - /* preset then read command line options */ - argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); - - /* error handling, printing usage message */ - if(argc<0) { - fprintf(stderr, - "error in command line argument \"%s\"\n", - argv[-argc]); - } else if(argc<2) { - argc=-1; - } - - if(argc<0 || options[0].doesOccur || options[1].doesOccur) { - FILE *where = argc < 0 ? stderr : stdout; - - /* - * Broken into chucks because the C89 standard says the minimum - * required supported string length is 509 bytes. - */ - fprintf(where, - "%csage: %s [ -h, -?, --help ] [ -v, --verbose ] [ -c, --copyright ] [ -C, --comment comment ] [ -d, --destdir dir ] [ -n, --name filename ] [ -t, --type filetype ] [ -S, --source tocfile ] [ -e, --entrypoint name ] maxsize listfile\n", argc < 0 ? 'u' : 'U', *argv); - if (options[0].doesOccur || options[1].doesOccur) { - fprintf(where, "\n" - "Read the list file (default: standard input) and create a common data\n" - "file from specified files. Omit any files larger than maxsize, if maxsize > 0.\n"); - fprintf(where, "\n" - "Options:\n" - "\t-h, -?, --help this usage text\n" - "\t-v, --verbose verbose output\n" - "\t-c, --copyright include the ICU copyright notice\n" - "\t-C, --comment comment include a comment string\n" - "\t-d, --destdir dir destination directory\n"); - fprintf(where, - "\t-n, --name filename output filename, without .type extension\n" - "\t (default: " U_ICUDATA_NAME ")\n" - "\t-t, --type filetype type of the destination file\n" - "\t (default: \" dat \")\n" - "\t-S, --source tocfile write a .c source file with the table of\n" - "\t contents\n" - "\t-e, --entrypoint name override the c entrypoint name\n" - "\t (default: \"<name>_<type>\")\n"); - } - return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; - } - - sourceTOC=options[8].doesOccur; - - verbose = options[2].doesOccur; - - maxSize=(uint32_t)uprv_strtoul(argv[1], NULL, 0); - - createCommonDataFile(options[4].doesOccur ? options[4].value : NULL, - options[6].doesOccur ? options[6].value : NULL, - options[9].doesOccur ? options[9].value : options[6].doesOccur ? options[6].value : NULL, - options[7].doesOccur ? options[7].value : NULL, - options[10].doesOccur ? options[10].value : NULL, - options[3].doesOccur ? U_COPYRIGHT_STRING : options[5].doesOccur ? options[5].value : NULL, - argc == 2 ? NULL : argv[2], - maxSize, sourceTOC, verbose, NULL); - - return 0; -} -/* - * Hey, Emacs, please set the following: - * - * Local Variables: - * indent-tabs-mode: nil - * End: - * - */ diff --git a/deps/node/deps/icu-small/source/tools/genrb/derb.cpp b/deps/node/deps/icu-small/source/tools/genrb/derb.cpp deleted file mode 100644 index ac26d95b..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/derb.cpp +++ /dev/null @@ -1,657 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1999-2016, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: derb.cpp -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2000sep6 -* created by: Vladimir Weinstein as an ICU workshop example -* maintained by: Yves Arrouye <yves@realnames.com> -*/ - -#include "unicode/stringpiece.h" -#include "unicode/ucnv.h" -#include "unicode/unistr.h" -#include "unicode/ustring.h" -#include "unicode/putil.h" -#include "unicode/ustdio.h" - -#include "charstr.h" -#include "uresimp.h" -#include "cmemory.h" -#include "cstring.h" -#include "uoptions.h" -#include "toolutil.h" -#include "ustrfmt.h" - -#if !UCONFIG_NO_FORMATTING - -#define DERB_VERSION "1.1" - -#define DERB_DEFAULT_TRUNC 80 - -static const int32_t indentsize = 4; -static int32_t truncsize = DERB_DEFAULT_TRUNC; -static UBool opt_truncate = FALSE; - -static const char *getEncodingName(const char *encoding); -static void reportError(const char *pname, UErrorCode *status, const char *when); -static UChar *quotedString(const UChar *string); -static void printOutBundle(UFILE *out, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status); -static void printString(UFILE *out, const UChar *str, int32_t len); -static void printCString(UFILE *out, const char *str, int32_t len); -static void printIndent(UFILE *out, int32_t indent); -static void printHex(UFILE *out, uint8_t what); - -static UOption options[]={ - UOPTION_HELP_H, - UOPTION_HELP_QUESTION_MARK, -/* 2 */ UOPTION_ENCODING, -/* 3 */ { "to-stdout", NULL, NULL, NULL, 'c', UOPT_NO_ARG, 0 } , -/* 4 */ { "truncate", NULL, NULL, NULL, 't', UOPT_OPTIONAL_ARG, 0 }, -/* 5 */ UOPTION_VERBOSE, -/* 6 */ UOPTION_DESTDIR, -/* 7 */ UOPTION_SOURCEDIR, -/* 8 */ { "bom", NULL, NULL, NULL, 0, UOPT_NO_ARG, 0 }, -/* 9 */ UOPTION_ICUDATADIR, -/* 10 */ UOPTION_VERSION, -/* 11 */ { "suppressAliases", NULL, NULL, NULL, 'A', UOPT_NO_ARG, 0 }, -}; - -static UBool verbose = FALSE; -static UBool suppressAliases = FALSE; -static UFILE *ustderr = NULL; - -extern int -main(int argc, char* argv[]) { - const char *encoding = NULL; - const char *outputDir = NULL; /* NULL = no output directory, use current */ - const char *inputDir = "."; - int tostdout = 0; - int prbom = 0; - - const char *pname; - - UResourceBundle *bundle = NULL; - int32_t i = 0; - - const char* arg; - - /* Get the name of tool. */ - pname = uprv_strrchr(*argv, U_FILE_SEP_CHAR); -#if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR - if (!pname) { - pname = uprv_strrchr(*argv, U_FILE_ALT_SEP_CHAR); - } -#endif - if (!pname) { - pname = *argv; - } else { - ++pname; - } - - /* error handling, printing usage message */ - argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); - - /* error handling, printing usage message */ - if(argc<0) { - fprintf(stderr, - "%s: error in command line argument \"%s\"\n", pname, - argv[-argc]); - } - if(argc<0 || options[0].doesOccur || options[1].doesOccur) { - fprintf(argc < 0 ? stderr : stdout, - "%csage: %s [ -h, -?, --help ] [ -V, --version ]\n" - " [ -v, --verbose ] [ -e, --encoding encoding ] [ --bom ]\n" - " [ -t, --truncate [ size ] ]\n" - " [ -s, --sourcedir source ] [ -d, --destdir destination ]\n" - " [ -i, --icudatadir directory ] [ -c, --to-stdout ]\n" - " [ -A, --suppressAliases]\n" - " bundle ...\n", argc < 0 ? 'u' : 'U', - pname); - return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; - } - - if(options[10].doesOccur) { - fprintf(stderr, - "%s version %s (ICU version %s).\n" - "%s\n", - pname, DERB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); - return U_ZERO_ERROR; - } - if(options[2].doesOccur) { - encoding = options[2].value; - } - - if (options[3].doesOccur) { - if(options[2].doesOccur) { - fprintf(stderr, "%s: Error: don't specify an encoding (-e) when writing to stdout (-c).\n", pname); - return 3; - } - tostdout = 1; - } - - if(options[4].doesOccur) { - opt_truncate = TRUE; - if(options[4].value != NULL) { - truncsize = atoi(options[4].value); /* user defined printable size */ - } else { - truncsize = DERB_DEFAULT_TRUNC; /* we'll use default omitting size */ - } - } else { - opt_truncate = FALSE; - } - - if(options[5].doesOccur) { - verbose = TRUE; - } - - if (options[6].doesOccur) { - outputDir = options[6].value; - } - - if(options[7].doesOccur) { - inputDir = options[7].value; /* we'll use users resources */ - } - - if (options[8].doesOccur) { - prbom = 1; - } - - if (options[9].doesOccur) { - u_setDataDirectory(options[9].value); - } - - if (options[11].doesOccur) { - suppressAliases = TRUE; - } - - fflush(stderr); // use ustderr now. - ustderr = u_finit(stderr, NULL, NULL); - - for (i = 1; i < argc; ++i) { - static const UChar sp[] = { 0x0020 }; /* " " */ - - arg = getLongPathname(argv[i]); - - if (verbose) { - u_fprintf(ustderr, "processing bundle \"%s\"\n", argv[i]); - } - - icu::CharString locale; - UErrorCode status = U_ZERO_ERROR; - { - const char *p = findBasename(arg); - const char *q = uprv_strrchr(p, '.'); - if (q == NULL) { - locale.append(p, status); - } else { - locale.append(p, (int32_t)(q - p), status); - } - } - if (U_FAILURE(status)) { - return status; - } - - icu::CharString infile; - const char *thename = NULL; - UBool fromICUData = !uprv_strcmp(inputDir, "-"); - if (!fromICUData) { - UBool absfilename = *arg == U_FILE_SEP_CHAR; -#if U_PLATFORM_HAS_WIN32_API - if (!absfilename) { - absfilename = (uprv_strlen(arg) > 2 && isalpha(arg[0]) - && arg[1] == ':' && arg[2] == U_FILE_SEP_CHAR); - } -#endif - if (absfilename) { - thename = arg; - } else { - const char *q = uprv_strrchr(arg, U_FILE_SEP_CHAR); -#if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR - if (q == NULL) { - q = uprv_strrchr(arg, U_FILE_ALT_SEP_CHAR); - } -#endif - infile.append(inputDir, status); - if(q != NULL) { - infile.appendPathPart(icu::StringPiece(arg, (int32_t)(q - arg)), status); - } - if (U_FAILURE(status)) { - return status; - } - thename = infile.data(); - } - } - if (thename) { - bundle = ures_openDirect(thename, locale.data(), &status); - } else { - bundle = ures_open(fromICUData ? 0 : inputDir, locale.data(), &status); - } - if (U_SUCCESS(status)) { - UFILE *out = NULL; - - const char *filename = 0; - const char *ext = 0; - - if (locale.isEmpty() || !tostdout) { - filename = findBasename(arg); - ext = uprv_strrchr(filename, '.'); - if (!ext) { - ext = uprv_strchr(filename, 0); - } - } - - if (tostdout) { - out = u_get_stdout(); - } else { - icu::CharString thefile; - if (outputDir) { - thefile.append(outputDir, status); - } - thefile.appendPathPart(filename, status); - if (*ext) { - thefile.truncate(thefile.length() - (int32_t)uprv_strlen(ext)); - } - thefile.append(".txt", status); - if (U_FAILURE(status)) { - return status; - } - - out = u_fopen(thefile.data(), "w", NULL, encoding); - if (!out) { - u_fprintf(ustderr, "%s: couldn't create %s\n", pname, thefile.data()); - u_fclose(ustderr); - return 4; - } - } - - // now, set the callback. - ucnv_setFromUCallBack(u_fgetConverter(out), UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C, 0, 0, &status); - if (U_FAILURE(status)) { - u_fprintf(ustderr, "%s: couldn't configure converter for encoding\n", pname); - u_fclose(ustderr); - if(!tostdout) { - u_fclose(out); - } - return 3; - } - - if (prbom) { /* XXX: Should be done only for UTFs */ - u_fputc(0xFEFF, out); - } - u_fprintf(out, "// -*- Coding: %s; -*-\n//\n", encoding ? encoding : getEncodingName(ucnv_getDefaultName())); - u_fprintf(out, "// This file was dumped by derb(8) from "); - if (thename) { - u_fprintf(out, "%s", thename); - } else if (fromICUData) { - u_fprintf(out, "the ICU internal %s locale", locale.data()); - } - - u_fprintf(out, "\n// derb(8) by Vladimir Weinstein and Yves Arrouye\n\n"); - - if (!locale.isEmpty()) { - u_fprintf(out, "%s", locale.data()); - } else { - u_fprintf(out, "%.*s%.*S", (int32_t)(ext - filename), filename, UPRV_LENGTHOF(sp), sp); - } - printOutBundle(out, bundle, 0, pname, &status); - - if (!tostdout) { - u_fclose(out); - } - } - else { - reportError(pname, &status, "opening resource file"); - } - - ures_close(bundle); - } - - return 0; -} - -static UChar *quotedString(const UChar *string) { - int len = u_strlen(string); - int alen = len; - const UChar *sp; - UChar *newstr, *np; - - for (sp = string; *sp; ++sp) { - switch (*sp) { - case '\n': - case 0x0022: - ++alen; - break; - } - } - - newstr = (UChar *) uprv_malloc((1 + alen) * U_SIZEOF_UCHAR); - for (sp = string, np = newstr; *sp; ++sp) { - switch (*sp) { - case '\n': - *np++ = 0x005C; - *np++ = 0x006E; - break; - - case 0x0022: - *np++ = 0x005C; - U_FALLTHROUGH; - default: - *np++ = *sp; - break; - } - } - *np = 0; - - return newstr; -} - - -static void printString(UFILE *out, const UChar *str, int32_t len) { - u_file_write(str, len, out); -} - -static void printCString(UFILE *out, const char *str, int32_t len) { - if(len==-1) { - u_fprintf(out, "%s", str); - } else { - u_fprintf(out, "%.*s", len, str); - } -} - -static void printIndent(UFILE *out, int32_t indent) { - icu::UnicodeString inchar(indent, 0x20, indent); - printString(out, inchar.getBuffer(), indent); -} - -static void printHex(UFILE *out, uint8_t what) { - static const char map[] = "0123456789ABCDEF"; - UChar hex[2]; - - hex[0] = map[what >> 4]; - hex[1] = map[what & 0xf]; - - printString(out, hex, 2); -} - -static void printOutAlias(UFILE *out, UResourceBundle *parent, Resource r, const char *key, int32_t indent, const char *pname, UErrorCode *status) { - static const UChar cr[] = { 0xA }; // LF - int32_t len = 0; - const UChar* thestr = res_getAlias(&(parent->fResData), r, &len); - UChar *string = quotedString(thestr); - if(opt_truncate && len > truncsize) { - char msg[128]; - printIndent(out, indent); - sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", - (long)len, (long)truncsize/2); - printCString(out, msg, -1); - len = truncsize; - } - if(U_SUCCESS(*status)) { - static const UChar openStr[] = { 0x003A, 0x0061, 0x006C, 0x0069, 0x0061, 0x0073, 0x0020, 0x007B, 0x0020, 0x0022 }; /* ":alias { \"" */ - static const UChar closeStr[] = { 0x0022, 0x0020, 0x007D, 0x0020 }; /* "\" } " */ - printIndent(out, indent); - if(key != NULL) { - printCString(out, key, -1); - } - printString(out, openStr, UPRV_LENGTHOF(openStr)); - printString(out, string, len); - printString(out, closeStr, UPRV_LENGTHOF(closeStr)); - if(verbose) { - printCString(out, " // ALIAS", -1); - } - printString(out, cr, UPRV_LENGTHOF(cr)); - } else { - reportError(pname, status, "getting binary value"); - } - uprv_free(string); -} - -static void printOutBundle(UFILE *out, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status) -{ - static const UChar cr[] = { 0xA }; // LF - -/* int32_t noOfElements = ures_getSize(resource);*/ - int32_t i = 0; - const char *key = ures_getKey(resource); - - switch(ures_getType(resource)) { - case URES_STRING : - { - int32_t len=0; - const UChar* thestr = ures_getString(resource, &len, status); - UChar *string = quotedString(thestr); - - /* TODO: String truncation */ - if(opt_truncate && len > truncsize) { - char msg[128]; - printIndent(out, indent); - sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", - (long)len, (long)(truncsize/2)); - printCString(out, msg, -1); - len = truncsize/2; - } - printIndent(out, indent); - if(key != NULL) { - static const UChar openStr[] = { 0x0020, 0x007B, 0x0020, 0x0022 }; /* " { \"" */ - static const UChar closeStr[] = { 0x0022, 0x0020, 0x007D }; /* "\" }" */ - printCString(out, key, (int32_t)uprv_strlen(key)); - printString(out, openStr, UPRV_LENGTHOF(openStr)); - printString(out, string, len); - printString(out, closeStr, UPRV_LENGTHOF(closeStr)); - } else { - static const UChar openStr[] = { 0x0022 }; /* "\"" */ - static const UChar closeStr[] = { 0x0022, 0x002C }; /* "\"," */ - - printString(out, openStr, UPRV_LENGTHOF(openStr)); - printString(out, string, (int32_t)(u_strlen(string))); - printString(out, closeStr, UPRV_LENGTHOF(closeStr)); - } - - if(verbose) { - printCString(out, "// STRING", -1); - } - printString(out, cr, UPRV_LENGTHOF(cr)); - - uprv_free(string); - } - break; - - case URES_INT : - { - static const UChar openStr[] = { 0x003A, 0x0069, 0x006E, 0x0074, 0x0020, 0x007B, 0x0020 }; /* ":int { " */ - static const UChar closeStr[] = { 0x0020, 0x007D }; /* " }" */ - UChar num[20]; - - printIndent(out, indent); - if(key != NULL) { - printCString(out, key, -1); - } - printString(out, openStr, UPRV_LENGTHOF(openStr)); - uprv_itou(num, 20, ures_getInt(resource, status), 10, 0); - printString(out, num, u_strlen(num)); - printString(out, closeStr, UPRV_LENGTHOF(closeStr)); - - if(verbose) { - printCString(out, "// INT", -1); - } - printString(out, cr, UPRV_LENGTHOF(cr)); - break; - } - case URES_BINARY : - { - int32_t len = 0; - const int8_t *data = (const int8_t *)ures_getBinary(resource, &len, status); - if(opt_truncate && len > truncsize) { - char msg[128]; - printIndent(out, indent); - sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", - (long)len, (long)(truncsize/2)); - printCString(out, msg, -1); - len = truncsize; - } - if(U_SUCCESS(*status)) { - static const UChar openStr[] = { 0x003A, 0x0062, 0x0069, 0x006E, 0x0061, 0x0072, 0x0079, 0x0020, 0x007B, 0x0020 }; /* ":binary { " */ - static const UChar closeStr[] = { 0x0020, 0x007D, 0x0020 }; /* " } " */ - printIndent(out, indent); - if(key != NULL) { - printCString(out, key, -1); - } - printString(out, openStr, UPRV_LENGTHOF(openStr)); - for(i = 0; i<len; i++) { - printHex(out, *data++); - } - printString(out, closeStr, UPRV_LENGTHOF(closeStr)); - if(verbose) { - printCString(out, " // BINARY", -1); - } - printString(out, cr, UPRV_LENGTHOF(cr)); - } else { - reportError(pname, status, "getting binary value"); - } - } - break; - case URES_INT_VECTOR : - { - int32_t len = 0; - const int32_t *data = ures_getIntVector(resource, &len, status); - if(U_SUCCESS(*status)) { - static const UChar openStr[] = { 0x003A, 0x0069, 0x006E, 0x0074, 0x0076, 0x0065, 0x0063, 0x0074, 0x006F, 0x0072, 0x0020, 0x007B, 0x0020 }; /* ":intvector { " */ - static const UChar closeStr[] = { 0x0020, 0x007D, 0x0020 }; /* " } " */ - UChar num[20]; - - printIndent(out, indent); - if(key != NULL) { - printCString(out, key, -1); - } - printString(out, openStr, UPRV_LENGTHOF(openStr)); - for(i = 0; i < len - 1; i++) { - int32_t numLen = uprv_itou(num, 20, data[i], 10, 0); - num[numLen++] = 0x002C; /* ',' */ - num[numLen++] = 0x0020; /* ' ' */ - num[numLen] = 0; - printString(out, num, u_strlen(num)); - } - if(len > 0) { - uprv_itou(num, 20, data[len - 1], 10, 0); - printString(out, num, u_strlen(num)); - } - printString(out, closeStr, UPRV_LENGTHOF(closeStr)); - if(verbose) { - printCString(out, "// INTVECTOR", -1); - } - printString(out, cr, UPRV_LENGTHOF(cr)); - } else { - reportError(pname, status, "getting int vector"); - } - } - break; - case URES_TABLE : - case URES_ARRAY : - { - static const UChar openStr[] = { 0x007B }; /* "{" */ - static const UChar closeStr[] = { 0x007D, '\n' }; /* "}\n" */ - - UResourceBundle *t = NULL; - ures_resetIterator(resource); - printIndent(out, indent); - if(key != NULL) { - printCString(out, key, -1); - } - printString(out, openStr, UPRV_LENGTHOF(openStr)); - if(verbose) { - if(ures_getType(resource) == URES_TABLE) { - printCString(out, "// TABLE", -1); - } else { - printCString(out, "// ARRAY", -1); - } - } - printString(out, cr, UPRV_LENGTHOF(cr)); - - if(suppressAliases == FALSE) { - while(U_SUCCESS(*status) && ures_hasNext(resource)) { - t = ures_getNextResource(resource, t, status); - if(U_SUCCESS(*status)) { - printOutBundle(out, t, indent+indentsize, pname, status); - } else { - reportError(pname, status, "While processing table"); - *status = U_ZERO_ERROR; - } - } - } else { /* we have to use low level access to do this */ - Resource r; - int32_t resSize = ures_getSize(resource); - UBool isTable = (UBool)(ures_getType(resource) == URES_TABLE); - for(i = 0; i < resSize; i++) { - /* need to know if it's an alias */ - if(isTable) { - r = res_getTableItemByIndex(&resource->fResData, resource->fRes, i, &key); - } else { - r = res_getArrayItem(&resource->fResData, resource->fRes, i); - } - if(U_SUCCESS(*status)) { - if(res_getPublicType(r) == URES_ALIAS) { - printOutAlias(out, resource, r, key, indent+indentsize, pname, status); - } else { - t = ures_getByIndex(resource, i, t, status); - printOutBundle(out, t, indent+indentsize, pname, status); - } - } else { - reportError(pname, status, "While processing table"); - *status = U_ZERO_ERROR; - } - } - } - - printIndent(out, indent); - printString(out, closeStr, UPRV_LENGTHOF(closeStr)); - ures_close(t); - } - break; - default: - break; - } - -} - -static const char *getEncodingName(const char *encoding) { - UErrorCode err; - const char *enc; - - err = U_ZERO_ERROR; - if (!(enc = ucnv_getStandardName(encoding, "MIME", &err))) { - err = U_ZERO_ERROR; - if (!(enc = ucnv_getStandardName(encoding, "IANA", &err))) { - ; - } - } - - return enc; -} - -static void reportError(const char *pname, UErrorCode *status, const char *when) { - u_fprintf(ustderr, "%s: error %d while %s: %s\n", pname, *status, when, u_errorName(*status)); -} - -#else -extern int -main(int argc, char* argv[]) { - /* Changing stdio.h ustdio.h requires that formatting not be disabled. */ - return 3; -} -#endif /* !UCONFIG_NO_FORMATTING */ - -/* - * Local Variables: - * indent-tabs-mode: nil - * End: - */ diff --git a/deps/node/deps/icu-small/source/tools/genrb/errmsg.c b/deps/node/deps/icu-small/source/tools/genrb/errmsg.c deleted file mode 100644 index 603f26a1..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/errmsg.c +++ /dev/null @@ -1,73 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2011, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File error.c -* -* Modification History: -* -* Date Name Description -* 05/28/99 stephen Creation. -******************************************************************************* -*/ - -#include <stdarg.h> -#include <stdio.h> -#include "cstring.h" -#include "errmsg.h" - -U_CFUNC void error(uint32_t linenumber, const char *msg, ...) -{ - va_list va; - - va_start(va, msg); - fprintf(stderr, "%s:%u: ", gCurrentFileName, (int)linenumber); - vfprintf(stderr, msg, va); - fprintf(stderr, "\n"); - va_end(va); -} - -static UBool gShowWarning = TRUE; - -U_CFUNC void setShowWarning(UBool val) -{ - gShowWarning = val; -} - -U_CFUNC UBool getShowWarning(){ - return gShowWarning; -} - -static UBool gStrict =FALSE; -U_CFUNC UBool isStrict(){ - return gStrict; -} -U_CFUNC void setStrict(UBool val){ - gStrict = val; -} -static UBool gVerbose =FALSE; -U_CFUNC UBool isVerbose(){ - return gVerbose; -} -U_CFUNC void setVerbose(UBool val){ - gVerbose = val; -} -U_CFUNC void warning(uint32_t linenumber, const char *msg, ...) -{ - if (gShowWarning) - { - va_list va; - - va_start(va, msg); - fprintf(stderr, "%s:%u: warning: ", gCurrentFileName, (int)linenumber); - vfprintf(stderr, msg, va); - fprintf(stderr, "\n"); - va_end(va); - } -} diff --git a/deps/node/deps/icu-small/source/tools/genrb/errmsg.h b/deps/node/deps/icu-small/source/tools/genrb/errmsg.h deleted file mode 100644 index e01b9558..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/errmsg.h +++ /dev/null @@ -1,46 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2016, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File error.h -* -* Modification History: -* -* Date Name Description -* 05/28/99 stephen Creation. -******************************************************************************* -*/ - -#ifndef ERROR_H -#define ERROR_H 1 - -#include "unicode/utypes.h" - -U_CDECL_BEGIN - -extern const char *gCurrentFileName; - -U_CFUNC void error(uint32_t linenumber, const char *msg, ...); -U_CFUNC void warning(uint32_t linenumber, const char *msg, ...); - -/* Show warnings? */ -U_CFUNC void setShowWarning(UBool val); -U_CFUNC UBool getShowWarning(void); - -/* strict */ -U_CFUNC void setStrict(UBool val); -U_CFUNC UBool isStrict(void); - -/* verbosity */ -U_CFUNC void setVerbose(UBool val); -U_CFUNC UBool isVerbose(void); - -U_CDECL_END - -#endif diff --git a/deps/node/deps/icu-small/source/tools/genrb/genrb.cpp b/deps/node/deps/icu-small/source/tools/genrb/genrb.cpp deleted file mode 100644 index c4fc4620..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/genrb.cpp +++ /dev/null @@ -1,837 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2016, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File genrb.cpp -* -* Modification History: -* -* Date Name Description -* 05/25/99 stephen Creation. -* 5/10/01 Ram removed ustdio dependency -******************************************************************************* -*/ - -#include <assert.h> -#include "genrb.h" -#include "unicode/localpointer.h" -#include "unicode/uclean.h" -#include "unicode/utf16.h" -#include "charstr.h" -#include "cmemory.h" -#include "reslist.h" -#include "ucmndata.h" /* TODO: for reading the pool bundle */ - -U_NAMESPACE_USE - -/* Protos */ -void processFile(const char *filename, const char* cp, const char *inputDir, const char *outputDir, - const char *packageName, - SRBRoot *newPoolBundle, UBool omitBinaryCollation, UErrorCode &status); -static char *make_res_filename(const char *filename, const char *outputDir, - const char *packageName, UErrorCode &status); - -/* File suffixes */ -#define RES_SUFFIX ".res" -#define COL_SUFFIX ".col" - -const char *gCurrentFileName = NULL; -#ifdef XP_MAC_CONSOLE -#include <console.h> -#endif - -void ResFile::close() { - delete[] fBytes; - fBytes = NULL; - delete fStrings; - fStrings = NULL; -} - -enum -{ - HELP1, - HELP2, - VERBOSE, - QUIET, - VERSION, - SOURCEDIR, - DESTDIR, - ENCODING, - ICUDATADIR, - WRITE_JAVA, - COPYRIGHT, - JAVA_PACKAGE, - BUNDLE_NAME, - WRITE_XLIFF, - STRICT, - NO_BINARY_COLLATION, - LANGUAGE, - NO_COLLATION_RULES, - FORMAT_VERSION, - WRITE_POOL_BUNDLE, - USE_POOL_BUNDLE, - INCLUDE_UNIHAN_COLL -}; - -UOption options[]={ - UOPTION_HELP_H, - UOPTION_HELP_QUESTION_MARK, - UOPTION_VERBOSE, - UOPTION_QUIET, - UOPTION_VERSION, - UOPTION_SOURCEDIR, - UOPTION_DESTDIR, - UOPTION_ENCODING, - UOPTION_ICUDATADIR, - UOPTION_WRITE_JAVA, - UOPTION_COPYRIGHT, - UOPTION_DEF("java-package", '\x01', UOPT_REQUIRES_ARG), - UOPTION_BUNDLE_NAME, - UOPTION_DEF("write-xliff", 'x', UOPT_OPTIONAL_ARG), - UOPTION_DEF("strict", 'k', UOPT_NO_ARG), /* 14 */ - UOPTION_DEF("noBinaryCollation", 'C', UOPT_NO_ARG),/* 15 */ - UOPTION_DEF("language", 'l', UOPT_REQUIRES_ARG), /* 16 */ - UOPTION_DEF("omitCollationRules", 'R', UOPT_NO_ARG),/* 17 */ - UOPTION_DEF("formatVersion", '\x01', UOPT_REQUIRES_ARG),/* 18 */ - UOPTION_DEF("writePoolBundle", '\x01', UOPT_NO_ARG),/* 19 */ - UOPTION_DEF("usePoolBundle", '\x01', UOPT_OPTIONAL_ARG),/* 20 */ - UOPTION_DEF("includeUnihanColl", '\x01', UOPT_NO_ARG),/* 21 */ /* temporary, don't display in usage info */ - }; - -static UBool write_java = FALSE; -static UBool write_xliff = FALSE; -static const char* outputEnc =""; - -static ResFile poolBundle; - -/*added by Jing*/ -static const char* language = NULL; -static const char* xliffOutputFileName = NULL; -int -main(int argc, - char* argv[]) -{ - UErrorCode status = U_ZERO_ERROR; - const char *arg = NULL; - const char *outputDir = NULL; /* NULL = no output directory, use current */ - const char *inputDir = NULL; - const char *encoding = ""; - int i; - UBool illegalArg = FALSE; - - U_MAIN_INIT_ARGS(argc, argv); - - options[JAVA_PACKAGE].value = "com.ibm.icu.impl.data"; - options[BUNDLE_NAME].value = "LocaleElements"; - argc = u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); - - /* error handling, printing usage message */ - if(argc<0) { - fprintf(stderr, "%s: error in command line argument \"%s\"\n", argv[0], argv[-argc]); - illegalArg = TRUE; - } else if(argc<2) { - illegalArg = TRUE; - } - if(options[WRITE_POOL_BUNDLE].doesOccur && options[USE_POOL_BUNDLE].doesOccur) { - fprintf(stderr, "%s: cannot combine --writePoolBundle and --usePoolBundle\n", argv[0]); - illegalArg = TRUE; - } - if(options[FORMAT_VERSION].doesOccur) { - const char *s = options[FORMAT_VERSION].value; - if(uprv_strlen(s) != 1 || (s[0] < '1' && '3' < s[0])) { - fprintf(stderr, "%s: unsupported --formatVersion %s\n", argv[0], s); - illegalArg = TRUE; - } else if(s[0] == '1' && - (options[WRITE_POOL_BUNDLE].doesOccur || options[USE_POOL_BUNDLE].doesOccur) - ) { - fprintf(stderr, "%s: cannot combine --formatVersion 1 with --writePoolBundle or --usePoolBundle\n", argv[0]); - illegalArg = TRUE; - } else { - setFormatVersion(s[0] - '0'); - } - } - - if((options[JAVA_PACKAGE].doesOccur || options[BUNDLE_NAME].doesOccur) && - !options[WRITE_JAVA].doesOccur) { - fprintf(stderr, - "%s error: command line argument --java-package or --bundle-name " - "without --write-java\n", - argv[0]); - illegalArg = TRUE; - } - - if(options[VERSION].doesOccur) { - fprintf(stderr, - "%s version %s (ICU version %s).\n" - "%s\n", - argv[0], GENRB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); - if(!illegalArg) { - return U_ZERO_ERROR; - } - } - - if(illegalArg || options[HELP1].doesOccur || options[HELP2].doesOccur) { - /* - * Broken into chunks because the C89 standard says the minimum - * required supported string length is 509 bytes. - */ - fprintf(stderr, - "Usage: %s [OPTIONS] [FILES]\n" - "\tReads the list of resource bundle source files and creates\n" - "\tbinary version of resource bundles (.res files)\n", - argv[0]); - fprintf(stderr, - "Options:\n" - "\t-h or -? or --help this usage text\n" - "\t-q or --quiet do not display warnings\n" - "\t-v or --verbose print extra information when processing files\n" - "\t-V or --version prints out version number and exits\n" - "\t-c or --copyright include copyright notice\n"); - fprintf(stderr, - "\t-e or --encoding encoding of source files\n" - "\t-d of --destdir destination directory, followed by the path, defaults to %s\n" - "\t-s or --sourcedir source directory for files followed by path, defaults to %s\n" - "\t-i or --icudatadir directory for locating any needed intermediate data files,\n" - "\t followed by path, defaults to %s\n", - u_getDataDirectory(), u_getDataDirectory(), u_getDataDirectory()); - fprintf(stderr, - "\t-j or --write-java write a Java ListResourceBundle for ICU4J, followed by optional encoding\n" - "\t defaults to ASCII and \\uXXXX format.\n" - "\t --java-package For --write-java: package name for writing the ListResourceBundle,\n" - "\t defaults to com.ibm.icu.impl.data\n"); - fprintf(stderr, - "\t-b or --bundle-name For --write-java: root resource bundle name for writing the ListResourceBundle,\n" - "\t defaults to LocaleElements\n" - "\t-x or --write-xliff write an XLIFF file for the resource bundle. Followed by\n" - "\t an optional output file name.\n" - "\t-k or --strict use pedantic parsing of syntax\n" - /*added by Jing*/ - "\t-l or --language for XLIFF: language code compliant with BCP 47.\n"); - fprintf(stderr, - "\t-C or --noBinaryCollation do not generate binary collation image;\n" - "\t makes .res file smaller but collator instantiation much slower;\n" - "\t maintains ability to get tailoring rules\n" - "\t-R or --omitCollationRules do not include collation (tailoring) rules;\n" - "\t makes .res file smaller and maintains collator instantiation speed\n" - "\t but tailoring rules will not be available (they are rarely used)\n"); - fprintf(stderr, - "\t --formatVersion write a .res file compatible with the requested formatVersion (single digit);\n" - "\t for example, --formatVersion 1\n"); - fprintf(stderr, - "\t --writePoolBundle write a pool.res file with all of the keys of all input bundles\n" - "\t --usePoolBundle [path-to-pool.res] point to keys from the pool.res keys pool bundle if they are available there;\n" - "\t makes .res files smaller but dependent on the pool bundle\n" - "\t (--writePoolBundle and --usePoolBundle cannot be combined)\n"); - - return illegalArg ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; - } - - if(options[VERBOSE].doesOccur) { - setVerbose(TRUE); - } - - if(options[QUIET].doesOccur) { - setShowWarning(FALSE); - } - if(options[STRICT].doesOccur) { - setStrict(TRUE); - } - if(options[COPYRIGHT].doesOccur){ - setIncludeCopyright(TRUE); - } - - if(options[SOURCEDIR].doesOccur) { - inputDir = options[SOURCEDIR].value; - } - - if(options[DESTDIR].doesOccur) { - outputDir = options[DESTDIR].value; - } - - if(options[ENCODING].doesOccur) { - encoding = options[ENCODING].value; - } - - if(options[ICUDATADIR].doesOccur) { - u_setDataDirectory(options[ICUDATADIR].value); - } - /* Initialize ICU */ - u_init(&status); - if (U_FAILURE(status) && status != U_FILE_ACCESS_ERROR) { - /* Note: u_init() will try to open ICU property data. - * failures here are expected when building ICU from scratch. - * ignore them. - */ - fprintf(stderr, "%s: can not initialize ICU. status = %s\n", - argv[0], u_errorName(status)); - exit(1); - } - status = U_ZERO_ERROR; - if(options[WRITE_JAVA].doesOccur) { - write_java = TRUE; - outputEnc = options[WRITE_JAVA].value; - } - - if(options[WRITE_XLIFF].doesOccur) { - write_xliff = TRUE; - if(options[WRITE_XLIFF].value != NULL){ - xliffOutputFileName = options[WRITE_XLIFF].value; - } - } - - initParser(); - - /*added by Jing*/ - if(options[LANGUAGE].doesOccur) { - language = options[LANGUAGE].value; - } - - LocalPointer<SRBRoot> newPoolBundle; - if(options[WRITE_POOL_BUNDLE].doesOccur) { - newPoolBundle.adoptInsteadAndCheckErrorCode(new SRBRoot(NULL, TRUE, status), status); - if(U_FAILURE(status)) { - fprintf(stderr, "unable to create an empty bundle for the pool keys: %s\n", u_errorName(status)); - return status; - } else { - const char *poolResName = "pool.res"; - char *nameWithoutSuffix = static_cast<char *>(uprv_malloc(uprv_strlen(poolResName) + 1)); - if (nameWithoutSuffix == NULL) { - fprintf(stderr, "out of memory error\n"); - return U_MEMORY_ALLOCATION_ERROR; - } - uprv_strcpy(nameWithoutSuffix, poolResName); - *uprv_strrchr(nameWithoutSuffix, '.') = 0; - newPoolBundle->fLocale = nameWithoutSuffix; - } - } - - if(options[USE_POOL_BUNDLE].doesOccur) { - const char *poolResName = "pool.res"; - FileStream *poolFile; - int32_t poolFileSize; - int32_t indexLength; - /* - * TODO: Consolidate inputDir/filename handling from main() and processFile() - * into a common function, and use it here as well. - * Try to create toolutil functions for dealing with dir/filenames and - * loading ICU data files without udata_open(). - * Share code with icupkg? - * Also, make_res_filename() seems to be unused. Review and remove. - */ - CharString poolFileName; - if (options[USE_POOL_BUNDLE].value!=NULL) { - poolFileName.append(options[USE_POOL_BUNDLE].value, status); - } else if (inputDir) { - poolFileName.append(inputDir, status); - } - poolFileName.appendPathPart(poolResName, status); - if (U_FAILURE(status)) { - return status; - } - poolFile = T_FileStream_open(poolFileName.data(), "rb"); - if (poolFile == NULL) { - fprintf(stderr, "unable to open pool bundle file %s\n", poolFileName.data()); - return 1; - } - poolFileSize = T_FileStream_size(poolFile); - if (poolFileSize < 32) { - fprintf(stderr, "the pool bundle file %s is too small\n", poolFileName.data()); - return 1; - } - poolBundle.fBytes = new uint8_t[(poolFileSize + 15) & ~15]; - if (poolFileSize > 0 && poolBundle.fBytes == NULL) { - fprintf(stderr, "unable to allocate memory for the pool bundle file %s\n", poolFileName.data()); - return U_MEMORY_ALLOCATION_ERROR; - } - - UDataSwapper *ds; - const DataHeader *header; - int32_t bytesRead = T_FileStream_read(poolFile, poolBundle.fBytes, poolFileSize); - if (bytesRead != poolFileSize) { - fprintf(stderr, "unable to read the pool bundle file %s\n", poolFileName.data()); - return 1; - } - /* - * Swap the pool bundle so that a single checked-in file can be used. - * The swapper functions also test that the data looks like - * a well-formed .res file. - */ - ds = udata_openSwapperForInputData(poolBundle.fBytes, bytesRead, - U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, &status); - if (U_FAILURE(status)) { - fprintf(stderr, "udata_openSwapperForInputData(pool bundle %s) failed: %s\n", - poolFileName.data(), u_errorName(status)); - return status; - } - ures_swap(ds, poolBundle.fBytes, bytesRead, poolBundle.fBytes, &status); - udata_closeSwapper(ds); - if (U_FAILURE(status)) { - fprintf(stderr, "ures_swap(pool bundle %s) failed: %s\n", - poolFileName.data(), u_errorName(status)); - return status; - } - header = (const DataHeader *)poolBundle.fBytes; - if (header->info.formatVersion[0] < 2) { - fprintf(stderr, "invalid format of pool bundle file %s\n", poolFileName.data()); - return U_INVALID_FORMAT_ERROR; - } - const int32_t *pRoot = (const int32_t *)( - (const char *)header + header->dataHeader.headerSize); - poolBundle.fIndexes = pRoot + 1; - indexLength = poolBundle.fIndexes[URES_INDEX_LENGTH] & 0xff; - if (indexLength <= URES_INDEX_POOL_CHECKSUM) { - fprintf(stderr, "insufficient indexes[] in pool bundle file %s\n", poolFileName.data()); - return U_INVALID_FORMAT_ERROR; - } - int32_t keysBottom = 1 + indexLength; - int32_t keysTop = poolBundle.fIndexes[URES_INDEX_KEYS_TOP]; - poolBundle.fKeys = (const char *)(pRoot + keysBottom); - poolBundle.fKeysLength = (keysTop - keysBottom) * 4; - poolBundle.fChecksum = poolBundle.fIndexes[URES_INDEX_POOL_CHECKSUM]; - - for (i = 0; i < poolBundle.fKeysLength; ++i) { - if (poolBundle.fKeys[i] == 0) { - ++poolBundle.fKeysCount; - } - } - - // 16BitUnits[] begins with strings-v2. - // The strings-v2 may optionally be terminated by what looks like - // an explicit string length that exceeds the number of remaining 16-bit units. - int32_t stringUnitsLength = (poolBundle.fIndexes[URES_INDEX_16BIT_TOP] - keysTop) * 2; - if (stringUnitsLength >= 2 && getFormatVersion() >= 3) { - poolBundle.fStrings = new PseudoListResource(NULL, status); - if (poolBundle.fStrings == NULL) { - fprintf(stderr, "unable to allocate memory for the pool bundle strings %s\n", - poolFileName.data()); - return U_MEMORY_ALLOCATION_ERROR; - } - // The PseudoListResource constructor call did not allocate further memory. - assert(U_SUCCESS(status)); - const UChar *p = (const UChar *)(pRoot + keysTop); - int32_t remaining = stringUnitsLength; - do { - int32_t first = *p; - int8_t numCharsForLength; - int32_t length; - if (!U16_IS_TRAIL(first)) { - // NUL-terminated - numCharsForLength = 0; - for (length = 0; - length < remaining && p[length] != 0; - ++length) {} - } else if (first < 0xdfef) { - numCharsForLength = 1; - length = first & 0x3ff; - } else if (first < 0xdfff && remaining >= 2) { - numCharsForLength = 2; - length = ((first - 0xdfef) << 16) | p[1]; - } else if (first == 0xdfff && remaining >= 3) { - numCharsForLength = 3; - length = ((int32_t)p[1] << 16) | p[2]; - } else { - break; // overrun - } - // Check for overrun before changing remaining, - // so that it is always accurate after the loop body. - if ((numCharsForLength + length) >= remaining || - p[numCharsForLength + length] != 0) { - break; // overrun or explicitly terminated - } - int32_t poolStringIndex = stringUnitsLength - remaining; - // Maximum pool string index when suffix-sharing the last character. - int32_t maxStringIndex = poolStringIndex + numCharsForLength + length - 1; - if (maxStringIndex >= RES_MAX_OFFSET) { - // pool string index overrun - break; - } - p += numCharsForLength; - remaining -= numCharsForLength; - if (length != 0) { - StringResource *sr = - new StringResource(poolStringIndex, numCharsForLength, - p, length, status); - if (sr == NULL) { - fprintf(stderr, "unable to allocate memory for a pool bundle string %s\n", - poolFileName.data()); - return U_MEMORY_ALLOCATION_ERROR; - } - poolBundle.fStrings->add(sr); - poolBundle.fStringIndexLimit = maxStringIndex + 1; - // The StringResource constructor did not allocate further memory. - assert(U_SUCCESS(status)); - } - p += length + 1; - remaining -= length + 1; - } while (remaining > 0); - if (poolBundle.fStrings->fCount == 0) { - delete poolBundle.fStrings; - poolBundle.fStrings = NULL; - } - } - - T_FileStream_close(poolFile); - setUsePoolBundle(TRUE); - if (isVerbose() && poolBundle.fStrings != NULL) { - printf("number of shared strings: %d\n", (int)poolBundle.fStrings->fCount); - int32_t length = poolBundle.fStringIndexLimit + 1; // incl. last NUL - printf("16-bit units for strings: %6d = %6d bytes\n", - (int)length, (int)length * 2); - } - } - - if(!options[FORMAT_VERSION].doesOccur && getFormatVersion() == 3 && - poolBundle.fStrings == NULL && - !options[WRITE_POOL_BUNDLE].doesOccur) { - // If we just default to formatVersion 3 - // but there are no pool bundle strings to share - // and we do not write a pool bundle, - // then write formatVersion 2 which is just as good. - setFormatVersion(2); - } - - if(options[INCLUDE_UNIHAN_COLL].doesOccur) { - puts("genrb option --includeUnihanColl ignored: \n" - "CLDR 26/ICU 54 unihan data is small, except\n" - "the ucadata-unihan.icu version of the collation root data\n" - "is about 300kB larger than the ucadata-implicithan.icu version."); - } - - if((argc-1)!=1) { - printf("genrb number of files: %d\n", argc - 1); - } - /* generate the binary files */ - for(i = 1; i < argc; ++i) { - status = U_ZERO_ERROR; - arg = getLongPathname(argv[i]); - - CharString theCurrentFileName; - if (inputDir) { - theCurrentFileName.append(inputDir, status); - } - theCurrentFileName.appendPathPart(arg, status); - if (U_FAILURE(status)) { - break; - } - - gCurrentFileName = theCurrentFileName.data(); - if (isVerbose()) { - printf("Processing file \"%s\"\n", theCurrentFileName.data()); - } - processFile(arg, encoding, inputDir, outputDir, NULL, - newPoolBundle.getAlias(), - options[NO_BINARY_COLLATION].doesOccur, status); - } - - poolBundle.close(); - - if(U_SUCCESS(status) && options[WRITE_POOL_BUNDLE].doesOccur) { - char outputFileName[256]; - newPoolBundle->write(outputDir, NULL, outputFileName, sizeof(outputFileName), status); - if(U_FAILURE(status)) { - fprintf(stderr, "unable to write the pool bundle: %s\n", u_errorName(status)); - } - } - - u_cleanup(); - - /* Dont return warnings as a failure */ - if (U_SUCCESS(status)) { - return 0; - } - - return status; -} - -/* Process a file */ -void -processFile(const char *filename, const char *cp, - const char *inputDir, const char *outputDir, const char *packageName, - SRBRoot *newPoolBundle, - UBool omitBinaryCollation, UErrorCode &status) { - LocalPointer<SRBRoot> data; - UCHARBUF *ucbuf = NULL; - char *rbname = NULL; - char *openFileName = NULL; - char *inputDirBuf = NULL; - - char outputFileName[256]; - - int32_t dirlen = 0; - int32_t filelen = 0; - - if (U_FAILURE(status)) { - return; - } - if(filename==NULL){ - status=U_ILLEGAL_ARGUMENT_ERROR; - return; - }else{ - filelen = (int32_t)uprv_strlen(filename); - } - - if(inputDir == NULL) { - const char *filenameBegin = uprv_strrchr(filename, U_FILE_SEP_CHAR); - openFileName = (char *) uprv_malloc(dirlen + filelen + 2); - openFileName[0] = '\0'; - if (filenameBegin != NULL) { - /* - * When a filename ../../../data/root.txt is specified, - * we presume that the input directory is ../../../data - * This is very important when the resource file includes - * another file, like UCARules.txt or thaidict.brk. - */ - int32_t filenameSize = (int32_t)(filenameBegin - filename + 1); - inputDirBuf = uprv_strncpy((char *)uprv_malloc(filenameSize), filename, filenameSize); - - /* test for NULL */ - if(inputDirBuf == NULL) { - status = U_MEMORY_ALLOCATION_ERROR; - goto finish; - } - - inputDirBuf[filenameSize - 1] = 0; - inputDir = inputDirBuf; - dirlen = (int32_t)uprv_strlen(inputDir); - } - }else{ - dirlen = (int32_t)uprv_strlen(inputDir); - - if(inputDir[dirlen-1] != U_FILE_SEP_CHAR) { - openFileName = (char *) uprv_malloc(dirlen + filelen + 2); - - /* test for NULL */ - if(openFileName == NULL) { - status = U_MEMORY_ALLOCATION_ERROR; - goto finish; - } - - openFileName[0] = '\0'; - /* - * append the input dir to openFileName if the first char in - * filename is not file seperation char and the last char input directory is not '.'. - * This is to support : - * genrb -s. /home/icu/data - * genrb -s. icu/data - * The user cannot mix notations like - * genrb -s. /icu/data --- the absolute path specified. -s redundant - * user should use - * genrb -s. icu/data --- start from CWD and look in icu/data dir - */ - if( (filename[0] != U_FILE_SEP_CHAR) && (inputDir[dirlen-1] !='.')){ - uprv_strcpy(openFileName, inputDir); - openFileName[dirlen] = U_FILE_SEP_CHAR; - } - openFileName[dirlen + 1] = '\0'; - } else { - openFileName = (char *) uprv_malloc(dirlen + filelen + 1); - - /* test for NULL */ - if(openFileName == NULL) { - status = U_MEMORY_ALLOCATION_ERROR; - goto finish; - } - - uprv_strcpy(openFileName, inputDir); - - } - } - - uprv_strcat(openFileName, filename); - - ucbuf = ucbuf_open(openFileName, &cp,getShowWarning(),TRUE, &status); - if(status == U_FILE_ACCESS_ERROR) { - - fprintf(stderr, "couldn't open file %s\n", openFileName == NULL ? filename : openFileName); - goto finish; - } - if (ucbuf == NULL || U_FAILURE(status)) { - fprintf(stderr, "An error occurred processing file %s. Error: %s\n", - openFileName == NULL ? filename : openFileName, u_errorName(status)); - goto finish; - } - /* auto detected popular encodings? */ - if (cp!=NULL && isVerbose()) { - printf("autodetected encoding %s\n", cp); - } - /* Parse the data into an SRBRoot */ - data.adoptInstead(parse(ucbuf, inputDir, outputDir, filename, - !omitBinaryCollation, options[NO_COLLATION_RULES].doesOccur, &status)); - - if (data.isNull() || U_FAILURE(status)) { - fprintf(stderr, "couldn't parse the file %s. Error:%s\n", filename, u_errorName(status)); - goto finish; - } - if(options[WRITE_POOL_BUNDLE].doesOccur) { - data->fWritePoolBundle = newPoolBundle; - data->compactKeys(status); - int32_t newKeysLength; - const char *newKeys = data->getKeyBytes(&newKeysLength); - newPoolBundle->addKeyBytes(newKeys, newKeysLength, status); - if(U_FAILURE(status)) { - fprintf(stderr, "bundle_compactKeys(%s) or bundle_getKeyBytes() failed: %s\n", - filename, u_errorName(status)); - goto finish; - } - /* count the number of just-added key strings */ - for(const char *newKeysLimit = newKeys + newKeysLength; newKeys < newKeysLimit; ++newKeys) { - if(*newKeys == 0) { - ++newPoolBundle->fKeysCount; - } - } - } - - if(options[USE_POOL_BUNDLE].doesOccur) { - data->fUsePoolBundle = &poolBundle; - } - - /* Determine the target rb filename */ - rbname = make_res_filename(filename, outputDir, packageName, status); - if(U_FAILURE(status)) { - fprintf(stderr, "couldn't make the res fileName for bundle %s. Error:%s\n", - filename, u_errorName(status)); - goto finish; - } - if(write_java== TRUE){ - bundle_write_java(data.getAlias(), outputDir, outputEnc, - outputFileName, sizeof(outputFileName), - options[JAVA_PACKAGE].value, options[BUNDLE_NAME].value, &status); - }else if(write_xliff ==TRUE){ - bundle_write_xml(data.getAlias(), outputDir, outputEnc, - filename, outputFileName, sizeof(outputFileName), - language, xliffOutputFileName, &status); - }else{ - /* Write the data to the file */ - data->write(outputDir, packageName, outputFileName, sizeof(outputFileName), status); - } - if (U_FAILURE(status)) { - fprintf(stderr, "couldn't write bundle %s. Error:%s\n", outputFileName, u_errorName(status)); - } - -finish: - - if (inputDirBuf != NULL) { - uprv_free(inputDirBuf); - } - - if (openFileName != NULL) { - uprv_free(openFileName); - } - - if(ucbuf) { - ucbuf_close(ucbuf); - } - - if (rbname) { - uprv_free(rbname); - } -} - -/* Generate the target .res file name from the input file name */ -static char* -make_res_filename(const char *filename, - const char *outputDir, - const char *packageName, - UErrorCode &status) { - char *basename; - char *dirname; - char *resName; - - int32_t pkgLen = 0; /* length of package prefix */ - - - if (U_FAILURE(status)) { - return 0; - } - - if(packageName != NULL) - { - pkgLen = (int32_t)(1 + uprv_strlen(packageName)); - } - - /* setup */ - basename = dirname = resName = 0; - - /* determine basename, and compiled file names */ - basename = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename) + 1)); - if(basename == 0) { - status = U_MEMORY_ALLOCATION_ERROR; - goto finish; - } - - get_basename(basename, filename); - - dirname = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename) + 1)); - if(dirname == 0) { - status = U_MEMORY_ALLOCATION_ERROR; - goto finish; - } - - get_dirname(dirname, filename); - - if (outputDir == NULL) { - /* output in same dir as .txt */ - resName = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(dirname) - + pkgLen - + uprv_strlen(basename) - + uprv_strlen(RES_SUFFIX) + 8)); - if(resName == 0) { - status = U_MEMORY_ALLOCATION_ERROR; - goto finish; - } - - uprv_strcpy(resName, dirname); - - if(packageName != NULL) - { - uprv_strcat(resName, packageName); - uprv_strcat(resName, "_"); - } - - uprv_strcat(resName, basename); - - } else { - int32_t dirlen = (int32_t)uprv_strlen(outputDir); - int32_t basenamelen = (int32_t)uprv_strlen(basename); - - resName = (char*) uprv_malloc(sizeof(char) * (dirlen + pkgLen + basenamelen + 8)); - - if (resName == NULL) { - status = U_MEMORY_ALLOCATION_ERROR; - goto finish; - } - - uprv_strcpy(resName, outputDir); - - if(outputDir[dirlen] != U_FILE_SEP_CHAR) { - resName[dirlen] = U_FILE_SEP_CHAR; - resName[dirlen + 1] = '\0'; - } - - if(packageName != NULL) - { - uprv_strcat(resName, packageName); - uprv_strcat(resName, "_"); - } - - uprv_strcat(resName, basename); - } - -finish: - uprv_free(basename); - uprv_free(dirname); - - return resName; -} - -/* - * Local Variables: - * indent-tabs-mode: nil - * End: - */ diff --git a/deps/node/deps/icu-small/source/tools/genrb/genrb.h b/deps/node/deps/icu-small/source/tools/genrb/genrb.h deleted file mode 100644 index 019020a3..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/genrb.h +++ /dev/null @@ -1,52 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2002-2015, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File genrb.h -*/ - -#ifndef GENRB_H -#define GENRB_H - -#include <stdio.h> -#include "unicode/utypes.h" -#include "unicode/putil.h" -#include "cmemory.h" -#include "cstring.h" -#include "filestrm.h" - - -#include "ucbuf.h" -#include "errmsg.h" -#include "parse.h" -#include "rbutil.h" - -#include "toolutil.h" -#include "uoptions.h" - -#include "unicode/ucol.h" -#include "unicode/uloc.h" - -/* The version of genrb */ -#define GENRB_VERSION "56" - -U_CDECL_BEGIN - -U_CAPI void processFile( - const char *filename, - const char* cp, - const char *inputDir, - const char *outputDir, - const char *packageName, - UBool omitBinaryCollation, - UErrorCode *status); - -U_CDECL_END - -#endif diff --git a/deps/node/deps/icu-small/source/tools/genrb/parse.cpp b/deps/node/deps/icu-small/source/tools/genrb/parse.cpp deleted file mode 100644 index 1f6246d3..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/parse.cpp +++ /dev/null @@ -1,2084 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2015, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File parse.cpp -* -* Modification History: -* -* Date Name Description -* 05/26/99 stephen Creation. -* 02/25/00 weiv Overhaul to write udata -* 5/10/01 Ram removed ustdio dependency -* 06/10/2001 Dominic Ludlam <dom@recoil.org> Rewritten -******************************************************************************* -*/ - -// Safer use of UnicodeString. -#ifndef UNISTR_FROM_CHAR_EXPLICIT -# define UNISTR_FROM_CHAR_EXPLICIT explicit -#endif - -// Less important, but still a good idea. -#ifndef UNISTR_FROM_STRING_EXPLICIT -# define UNISTR_FROM_STRING_EXPLICIT explicit -#endif - -#include <assert.h> -#include "parse.h" -#include "errmsg.h" -#include "uhash.h" -#include "cmemory.h" -#include "cstring.h" -#include "uinvchar.h" -#include "read.h" -#include "ustr.h" -#include "reslist.h" -#include "rbt_pars.h" -#include "genrb.h" -#include "unicode/stringpiece.h" -#include "unicode/unistr.h" -#include "unicode/ustring.h" -#include "unicode/uscript.h" -#include "unicode/utf16.h" -#include "unicode/putil.h" -#include "charstr.h" -#include "collationbuilder.h" -#include "collationdata.h" -#include "collationdatareader.h" -#include "collationdatawriter.h" -#include "collationfastlatinbuilder.h" -#include "collationinfo.h" -#include "collationroot.h" -#include "collationruleparser.h" -#include "collationtailoring.h" -#include <stdio.h> - -/* Number of tokens to read ahead of the current stream position */ -#define MAX_LOOKAHEAD 3 - -#define CR 0x000D -#define LF 0x000A -#define SPACE 0x0020 -#define TAB 0x0009 -#define ESCAPE 0x005C -#define HASH 0x0023 -#define QUOTE 0x0027 -#define ZERO 0x0030 -#define STARTCOMMAND 0x005B -#define ENDCOMMAND 0x005D -#define OPENSQBRACKET 0x005B -#define CLOSESQBRACKET 0x005D - -using icu::CharString; -using icu::LocalMemory; -using icu::LocalPointer; -using icu::LocalUCHARBUFPointer; -using icu::StringPiece; -using icu::UnicodeString; - -struct Lookahead -{ - enum ETokenType type; - struct UString value; - struct UString comment; - uint32_t line; -}; - -/* keep in sync with token defines in read.h */ -const char *tokenNames[TOK_TOKEN_COUNT] = -{ - "string", /* A string token, such as "MonthNames" */ - "'{'", /* An opening brace character */ - "'}'", /* A closing brace character */ - "','", /* A comma */ - "':'", /* A colon */ - - "<end of file>", /* End of the file has been reached successfully */ - "<end of line>" -}; - -/* Just to store "TRUE" */ -//static const UChar trueValue[] = {0x0054, 0x0052, 0x0055, 0x0045, 0x0000}; - -typedef struct { - struct Lookahead lookahead[MAX_LOOKAHEAD + 1]; - uint32_t lookaheadPosition; - UCHARBUF *buffer; - struct SRBRoot *bundle; - const char *inputdir; - uint32_t inputdirLength; - const char *outputdir; - uint32_t outputdirLength; - const char *filename; - UBool makeBinaryCollation; - UBool omitCollationRules; -} ParseState; - -typedef struct SResource * -ParseResourceFunction(ParseState* state, char *tag, uint32_t startline, const struct UString* comment, UErrorCode *status); - -static struct SResource *parseResource(ParseState* state, char *tag, const struct UString *comment, UErrorCode *status); - -/* The nature of the lookahead buffer: - There are MAX_LOOKAHEAD + 1 slots, used as a circular buffer. This provides - MAX_LOOKAHEAD lookahead tokens and a slot for the current token and value. - When getToken is called, the current pointer is moved to the next slot and the - old slot is filled with the next token from the reader by calling getNextToken. - The token values are stored in the slot, which means that token values don't - survive a call to getToken, ie. - - UString *value; - - getToken(&value, NULL, status); - getToken(NULL, NULL, status); bad - value is now a different string -*/ -static void -initLookahead(ParseState* state, UCHARBUF *buf, UErrorCode *status) -{ - static uint32_t initTypeStrings = 0; - uint32_t i; - - if (!initTypeStrings) - { - initTypeStrings = 1; - } - - state->lookaheadPosition = 0; - state->buffer = buf; - - resetLineNumber(); - - for (i = 0; i < MAX_LOOKAHEAD; i++) - { - state->lookahead[i].type = getNextToken(state->buffer, &state->lookahead[i].value, &state->lookahead[i].line, &state->lookahead[i].comment, status); - if (U_FAILURE(*status)) - { - return; - } - } - - *status = U_ZERO_ERROR; -} - -static void -cleanupLookahead(ParseState* state) -{ - uint32_t i; - for (i = 0; i <= MAX_LOOKAHEAD; i++) - { - ustr_deinit(&state->lookahead[i].value); - ustr_deinit(&state->lookahead[i].comment); - } - -} - -static enum ETokenType -getToken(ParseState* state, struct UString **tokenValue, struct UString* comment, uint32_t *linenumber, UErrorCode *status) -{ - enum ETokenType result; - uint32_t i; - - result = state->lookahead[state->lookaheadPosition].type; - - if (tokenValue != NULL) - { - *tokenValue = &state->lookahead[state->lookaheadPosition].value; - } - - if (linenumber != NULL) - { - *linenumber = state->lookahead[state->lookaheadPosition].line; - } - - if (comment != NULL) - { - ustr_cpy(comment, &(state->lookahead[state->lookaheadPosition].comment), status); - } - - i = (state->lookaheadPosition + MAX_LOOKAHEAD) % (MAX_LOOKAHEAD + 1); - state->lookaheadPosition = (state->lookaheadPosition + 1) % (MAX_LOOKAHEAD + 1); - ustr_setlen(&state->lookahead[i].comment, 0, status); - ustr_setlen(&state->lookahead[i].value, 0, status); - state->lookahead[i].type = getNextToken(state->buffer, &state->lookahead[i].value, &state->lookahead[i].line, &state->lookahead[i].comment, status); - - /* printf("getToken, returning %s\n", tokenNames[result]); */ - - return result; -} - -static enum ETokenType -peekToken(ParseState* state, uint32_t lookaheadCount, struct UString **tokenValue, uint32_t *linenumber, struct UString *comment, UErrorCode *status) -{ - uint32_t i = (state->lookaheadPosition + lookaheadCount) % (MAX_LOOKAHEAD + 1); - - if (U_FAILURE(*status)) - { - return TOK_ERROR; - } - - if (lookaheadCount >= MAX_LOOKAHEAD) - { - *status = U_INTERNAL_PROGRAM_ERROR; - return TOK_ERROR; - } - - if (tokenValue != NULL) - { - *tokenValue = &state->lookahead[i].value; - } - - if (linenumber != NULL) - { - *linenumber = state->lookahead[i].line; - } - - if(comment != NULL){ - ustr_cpy(comment, &(state->lookahead[state->lookaheadPosition].comment), status); - } - - return state->lookahead[i].type; -} - -static void -expect(ParseState* state, enum ETokenType expectedToken, struct UString **tokenValue, struct UString *comment, uint32_t *linenumber, UErrorCode *status) -{ - uint32_t line; - - enum ETokenType token = getToken(state, tokenValue, comment, &line, status); - - if (linenumber != NULL) - { - *linenumber = line; - } - - if (U_FAILURE(*status)) - { - return; - } - - if (token != expectedToken) - { - *status = U_INVALID_FORMAT_ERROR; - error(line, "expecting %s, got %s", tokenNames[expectedToken], tokenNames[token]); - } - else - { - *status = U_ZERO_ERROR; - } -} - -static char *getInvariantString(ParseState* state, uint32_t *line, struct UString *comment, UErrorCode *status) -{ - struct UString *tokenValue; - char *result; - uint32_t count; - - expect(state, TOK_STRING, &tokenValue, comment, line, status); - - if (U_FAILURE(*status)) - { - return NULL; - } - - count = u_strlen(tokenValue->fChars); - if(!uprv_isInvariantUString(tokenValue->fChars, count)) { - *status = U_INVALID_FORMAT_ERROR; - error(*line, "invariant characters required for table keys, binary data, etc."); - return NULL; - } - - result = static_cast<char *>(uprv_malloc(count+1)); - - if (result == NULL) - { - *status = U_MEMORY_ALLOCATION_ERROR; - return NULL; - } - - u_UCharsToChars(tokenValue->fChars, result, count+1); - return result; -} - -static struct SResource * -parseUCARules(ParseState* state, char *tag, uint32_t startline, const struct UString* /*comment*/, UErrorCode *status) -{ - struct SResource *result = NULL; - struct UString *tokenValue; - FileStream *file = NULL; - char filename[256] = { '\0' }; - char cs[128] = { '\0' }; - uint32_t line; - UBool quoted = FALSE; - UCHARBUF *ucbuf=NULL; - UChar32 c = 0; - const char* cp = NULL; - UChar *pTarget = NULL; - UChar *target = NULL; - UChar *targetLimit = NULL; - int32_t size = 0; - - expect(state, TOK_STRING, &tokenValue, NULL, &line, status); - - if(isVerbose()){ - printf(" %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - - if (U_FAILURE(*status)) - { - return NULL; - } - /* make the filename including the directory */ - if (state->inputdir != NULL) - { - uprv_strcat(filename, state->inputdir); - - if (state->inputdir[state->inputdirLength - 1] != U_FILE_SEP_CHAR) - { - uprv_strcat(filename, U_FILE_SEP_STRING); - } - } - - u_UCharsToChars(tokenValue->fChars, cs, tokenValue->fLength); - - expect(state, TOK_CLOSE_BRACE, NULL, NULL, NULL, status); - - if (U_FAILURE(*status)) - { - return NULL; - } - uprv_strcat(filename, cs); - - if(state->omitCollationRules) { - return res_none(); - } - - ucbuf = ucbuf_open(filename, &cp, getShowWarning(),FALSE, status); - - if (U_FAILURE(*status)) { - error(line, "An error occurred while opening the input file %s\n", filename); - return NULL; - } - - /* We allocate more space than actually required - * since the actual size needed for storing UChars - * is not known in UTF-8 byte stream - */ - size = ucbuf_size(ucbuf) + 1; - pTarget = (UChar*) uprv_malloc(U_SIZEOF_UCHAR * size); - uprv_memset(pTarget, 0, size*U_SIZEOF_UCHAR); - target = pTarget; - targetLimit = pTarget+size; - - /* read the rules into the buffer */ - while (target < targetLimit) - { - c = ucbuf_getc(ucbuf, status); - if(c == QUOTE) { - quoted = (UBool)!quoted; - } - /* weiv (06/26/2002): adding the following: - * - preserving spaces in commands [...] - * - # comments until the end of line - */ - if (c == STARTCOMMAND && !quoted) - { - /* preserve commands - * closing bracket will be handled by the - * append at the end of the loop - */ - while(c != ENDCOMMAND) { - U_APPEND_CHAR32_ONLY(c, target); - c = ucbuf_getc(ucbuf, status); - } - } - else if (c == HASH && !quoted) { - /* skip comments */ - while(c != CR && c != LF) { - c = ucbuf_getc(ucbuf, status); - } - continue; - } - else if (c == ESCAPE) - { - c = unescape(ucbuf, status); - - if (c == (UChar32)U_ERR) - { - uprv_free(pTarget); - T_FileStream_close(file); - return NULL; - } - } - else if (!quoted && (c == SPACE || c == TAB || c == CR || c == LF)) - { - /* ignore spaces carriage returns - * and line feed unless in the form \uXXXX - */ - continue; - } - - /* Append UChar * after dissembling if c > 0xffff*/ - if (c != (UChar32)U_EOF) - { - U_APPEND_CHAR32_ONLY(c, target); - } - else - { - break; - } - } - - /* terminate the string */ - if(target < targetLimit){ - *target = 0x0000; - } - - result = string_open(state->bundle, tag, pTarget, (int32_t)(target - pTarget), NULL, status); - - - ucbuf_close(ucbuf); - uprv_free(pTarget); - T_FileStream_close(file); - - return result; -} - -static struct SResource * -parseTransliterator(ParseState* state, char *tag, uint32_t startline, const struct UString* /*comment*/, UErrorCode *status) -{ - struct SResource *result = NULL; - struct UString *tokenValue; - FileStream *file = NULL; - char filename[256] = { '\0' }; - char cs[128] = { '\0' }; - uint32_t line; - UCHARBUF *ucbuf=NULL; - const char* cp = NULL; - UChar *pTarget = NULL; - const UChar *pSource = NULL; - int32_t size = 0; - - expect(state, TOK_STRING, &tokenValue, NULL, &line, status); - - if(isVerbose()){ - printf(" %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - - if (U_FAILURE(*status)) - { - return NULL; - } - /* make the filename including the directory */ - if (state->inputdir != NULL) - { - uprv_strcat(filename, state->inputdir); - - if (state->inputdir[state->inputdirLength - 1] != U_FILE_SEP_CHAR) - { - uprv_strcat(filename, U_FILE_SEP_STRING); - } - } - - u_UCharsToChars(tokenValue->fChars, cs, tokenValue->fLength); - - expect(state, TOK_CLOSE_BRACE, NULL, NULL, NULL, status); - - if (U_FAILURE(*status)) - { - return NULL; - } - uprv_strcat(filename, cs); - - - ucbuf = ucbuf_open(filename, &cp, getShowWarning(),FALSE, status); - - if (U_FAILURE(*status)) { - error(line, "An error occurred while opening the input file %s\n", filename); - return NULL; - } - - /* We allocate more space than actually required - * since the actual size needed for storing UChars - * is not known in UTF-8 byte stream - */ - pSource = ucbuf_getBuffer(ucbuf, &size, status); - pTarget = (UChar*) uprv_malloc(U_SIZEOF_UCHAR * (size + 1)); - uprv_memset(pTarget, 0, size*U_SIZEOF_UCHAR); - -#if !UCONFIG_NO_TRANSLITERATION - size = utrans_stripRules(pSource, size, pTarget, status); -#else - size = 0; - fprintf(stderr, " Warning: writing empty transliteration data ( UCONFIG_NO_TRANSLITERATION ) \n"); -#endif - result = string_open(state->bundle, tag, pTarget, size, NULL, status); - - ucbuf_close(ucbuf); - uprv_free(pTarget); - T_FileStream_close(file); - - return result; -} -static ArrayResource* dependencyArray = NULL; - -static struct SResource * -parseDependency(ParseState* state, char *tag, uint32_t startline, const struct UString* comment, UErrorCode *status) -{ - struct SResource *result = NULL; - struct SResource *elem = NULL; - struct UString *tokenValue; - uint32_t line; - char filename[256] = { '\0' }; - char cs[128] = { '\0' }; - - expect(state, TOK_STRING, &tokenValue, NULL, &line, status); - - if(isVerbose()){ - printf(" %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - - if (U_FAILURE(*status)) - { - return NULL; - } - /* make the filename including the directory */ - if (state->outputdir != NULL) - { - uprv_strcat(filename, state->outputdir); - - if (state->outputdir[state->outputdirLength - 1] != U_FILE_SEP_CHAR) - { - uprv_strcat(filename, U_FILE_SEP_STRING); - } - } - - u_UCharsToChars(tokenValue->fChars, cs, tokenValue->fLength); - - if (U_FAILURE(*status)) - { - return NULL; - } - uprv_strcat(filename, cs); - if(!T_FileStream_file_exists(filename)){ - if(isStrict()){ - error(line, "The dependency file %s does not exist. Please make sure it exists.\n",filename); - }else{ - warning(line, "The dependency file %s does not exist. Please make sure it exists.\n",filename); - } - } - if(dependencyArray==NULL){ - dependencyArray = array_open(state->bundle, "%%DEPENDENCY", NULL, status); - } - if(tag!=NULL){ - result = string_open(state->bundle, tag, tokenValue->fChars, tokenValue->fLength, comment, status); - } - elem = string_open(state->bundle, NULL, tokenValue->fChars, tokenValue->fLength, comment, status); - - dependencyArray->add(elem); - - if (U_FAILURE(*status)) - { - return NULL; - } - expect(state, TOK_CLOSE_BRACE, NULL, NULL, NULL, status); - return result; -} -static struct SResource * -parseString(ParseState* state, char *tag, uint32_t startline, const struct UString* comment, UErrorCode *status) -{ - struct UString *tokenValue; - struct SResource *result = NULL; - -/* if (tag != NULL && uprv_strcmp(tag, "%%UCARULES") == 0) - { - return parseUCARules(tag, startline, status); - }*/ - if(isVerbose()){ - printf(" string %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - expect(state, TOK_STRING, &tokenValue, NULL, NULL, status); - - if (U_SUCCESS(*status)) - { - /* create the string now - tokenValue doesn't survive a call to getToken (and therefore - doesn't survive expect either) */ - - result = string_open(state->bundle, tag, tokenValue->fChars, tokenValue->fLength, comment, status); - if(U_SUCCESS(*status) && result) { - expect(state, TOK_CLOSE_BRACE, NULL, NULL, NULL, status); - - if (U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - } - } - - return result; -} - -static struct SResource * -parseAlias(ParseState* state, char *tag, uint32_t startline, const struct UString *comment, UErrorCode *status) -{ - struct UString *tokenValue; - struct SResource *result = NULL; - - expect(state, TOK_STRING, &tokenValue, NULL, NULL, status); - - if(isVerbose()){ - printf(" alias %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - - if (U_SUCCESS(*status)) - { - /* create the string now - tokenValue doesn't survive a call to getToken (and therefore - doesn't survive expect either) */ - - result = alias_open(state->bundle, tag, tokenValue->fChars, tokenValue->fLength, comment, status); - - expect(state, TOK_CLOSE_BRACE, NULL, NULL, NULL, status); - - if (U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - } - - return result; -} - -#if !UCONFIG_NO_COLLATION - -namespace { - -static struct SResource* resLookup(struct SResource* res, const char* key){ - if (res == res_none() || !res->isTable()) { - return NULL; - } - - TableResource *list = static_cast<TableResource *>(res); - SResource *current = list->fFirst; - while (current != NULL) { - if (uprv_strcmp(((list->fRoot->fKeys) + (current->fKey)), key) == 0) { - return current; - } - current = current->fNext; - } - return NULL; -} - -class GenrbImporter : public icu::CollationRuleParser::Importer { -public: - GenrbImporter(const char *in, const char *out) : inputDir(in), outputDir(out) {} - virtual ~GenrbImporter(); - virtual void getRules( - const char *localeID, const char *collationType, - UnicodeString &rules, - const char *&errorReason, UErrorCode &errorCode); - -private: - const char *inputDir; - const char *outputDir; -}; - -GenrbImporter::~GenrbImporter() {} - -void -GenrbImporter::getRules( - const char *localeID, const char *collationType, - UnicodeString &rules, - const char *& /*errorReason*/, UErrorCode &errorCode) { - CharString filename(localeID, errorCode); - for(int32_t i = 0; i < filename.length(); i++){ - if(filename[i] == '-'){ - filename.data()[i] = '_'; - } - } - filename.append(".txt", errorCode); - if (U_FAILURE(errorCode)) { - return; - } - CharString inputDirBuf; - CharString openFileName; - if(inputDir == NULL) { - const char *filenameBegin = uprv_strrchr(filename.data(), U_FILE_SEP_CHAR); - if (filenameBegin != NULL) { - /* - * When a filename ../../../data/root.txt is specified, - * we presume that the input directory is ../../../data - * This is very important when the resource file includes - * another file, like UCARules.txt or thaidict.brk. - */ - StringPiece dir = filename.toStringPiece(); - const char *filenameLimit = filename.data() + filename.length(); - dir.remove_suffix((int32_t)(filenameLimit - filenameBegin)); - inputDirBuf.append(dir, errorCode); - inputDir = inputDirBuf.data(); - } - }else{ - int32_t dirlen = (int32_t)uprv_strlen(inputDir); - - if((filename[0] != U_FILE_SEP_CHAR) && (inputDir[dirlen-1] !='.')) { - /* - * append the input dir to openFileName if the first char in - * filename is not file separator char and the last char input directory is not '.'. - * This is to support : - * genrb -s. /home/icu/data - * genrb -s. icu/data - * The user cannot mix notations like - * genrb -s. /icu/data --- the absolute path specified. -s redundant - * user should use - * genrb -s. icu/data --- start from CWD and look in icu/data dir - */ - openFileName.append(inputDir, dirlen, errorCode); - if(inputDir[dirlen-1] != U_FILE_SEP_CHAR) { - openFileName.append(U_FILE_SEP_CHAR, errorCode); - } - } - } - openFileName.append(filename, errorCode); - if(U_FAILURE(errorCode)) { - return; - } - // printf("GenrbImporter::getRules(%s, %s) reads %s\n", localeID, collationType, openFileName.data()); - const char* cp = ""; - LocalUCHARBUFPointer ucbuf( - ucbuf_open(openFileName.data(), &cp, getShowWarning(), TRUE, &errorCode)); - if(errorCode == U_FILE_ACCESS_ERROR) { - fprintf(stderr, "couldn't open file %s\n", openFileName.data()); - return; - } - if (ucbuf.isNull() || U_FAILURE(errorCode)) { - fprintf(stderr, "An error occurred processing file %s. Error: %s\n", openFileName.data(), u_errorName(errorCode)); - return; - } - - /* Parse the data into an SRBRoot */ - LocalPointer<SRBRoot> data( - parse(ucbuf.getAlias(), inputDir, outputDir, filename.data(), FALSE, FALSE, &errorCode)); - if (U_FAILURE(errorCode)) { - return; - } - - struct SResource *root = data->fRoot; - struct SResource *collations = resLookup(root, "collations"); - if (collations != NULL) { - struct SResource *collation = resLookup(collations, collationType); - if (collation != NULL) { - struct SResource *sequence = resLookup(collation, "Sequence"); - if (sequence != NULL && sequence->isString()) { - // No string pointer aliasing so that we need not hold onto the resource bundle. - StringResource *sr = static_cast<StringResource *>(sequence); - rules = sr->fString; - } - } - } -} - -// Quick-and-dirty escaping function. -// Assumes that we are on an ASCII-based platform. -static void -escape(const UChar *s, char *buffer) { - int32_t length = u_strlen(s); - int32_t i = 0; - for (;;) { - UChar32 c; - U16_NEXT(s, i, length, c); - if (c == 0) { - *buffer = 0; - return; - } else if (0x20 <= c && c <= 0x7e) { - // printable ASCII - *buffer++ = (char)c; // assumes ASCII-based platform - } else { - buffer += sprintf(buffer, "\\u%04X", (int)c); - } - } -} - -} // namespace - -#endif // !UCONFIG_NO_COLLATION - -static TableResource * -addCollation(ParseState* state, TableResource *result, const char *collationType, - uint32_t startline, UErrorCode *status) -{ - // TODO: Use LocalPointer for result, or make caller close it when there is a failure. - struct SResource *member = NULL; - struct UString *tokenValue; - struct UString comment; - enum ETokenType token; - char subtag[1024]; - UnicodeString rules; - UBool haveRules = FALSE; - UVersionInfo version; - uint32_t line; - - /* '{' . (name resource)* '}' */ - version[0]=0; version[1]=0; version[2]=0; version[3]=0; - - for (;;) - { - ustr_init(&comment); - token = getToken(state, &tokenValue, &comment, &line, status); - - if (token == TOK_CLOSE_BRACE) - { - break; - } - - if (token != TOK_STRING) - { - res_close(result); - *status = U_INVALID_FORMAT_ERROR; - - if (token == TOK_EOF) - { - error(startline, "unterminated table"); - } - else - { - error(line, "Unexpected token %s", tokenNames[token]); - } - - return NULL; - } - - u_UCharsToChars(tokenValue->fChars, subtag, u_strlen(tokenValue->fChars) + 1); - - if (U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - - member = parseResource(state, subtag, NULL, status); - - if (U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - if (result == NULL) - { - // Ignore the parsed resources, continue parsing. - } - else if (uprv_strcmp(subtag, "Version") == 0 && member->isString()) - { - StringResource *sr = static_cast<StringResource *>(member); - char ver[40]; - int32_t length = sr->length(); - - if (length >= UPRV_LENGTHOF(ver)) - { - length = UPRV_LENGTHOF(ver) - 1; - } - - sr->fString.extract(0, length, ver, UPRV_LENGTHOF(ver), US_INV); - u_versionFromString(version, ver); - - result->add(member, line, *status); - member = NULL; - } - else if(uprv_strcmp(subtag, "%%CollationBin")==0) - { - /* discard duplicate %%CollationBin if any*/ - } - else if (uprv_strcmp(subtag, "Sequence") == 0 && member->isString()) - { - StringResource *sr = static_cast<StringResource *>(member); - rules = sr->fString; - haveRules = TRUE; - // Defer building the collator until we have seen - // all sub-elements of the collation table, including the Version. - /* in order to achieve smaller data files, we can direct genrb */ - /* to omit collation rules */ - if(!state->omitCollationRules) { - result->add(member, line, *status); - member = NULL; - } - } - else // Just copy non-special items. - { - result->add(member, line, *status); - member = NULL; - } - res_close(member); // TODO: use LocalPointer - if (U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - } - - if (!haveRules) { return result; } - -#if UCONFIG_NO_COLLATION || UCONFIG_NO_FILE_IO - warning(line, "Not building collation elements because of UCONFIG_NO_COLLATION and/or UCONFIG_NO_FILE_IO, see uconfig.h"); - (void)collationType; -#else - // CLDR ticket #3949, ICU ticket #8082: - // Do not build collation binary data for for-import-only "private" collation rule strings. - if (uprv_strncmp(collationType, "private-", 8) == 0) { - if(isVerbose()) { - printf("Not building %s~%s collation binary\n", state->filename, collationType); - } - return result; - } - - if(!state->makeBinaryCollation) { - if(isVerbose()) { - printf("Not building %s~%s collation binary\n", state->filename, collationType); - } - return result; - } - UErrorCode intStatus = U_ZERO_ERROR; - UParseError parseError; - uprv_memset(&parseError, 0, sizeof(parseError)); - GenrbImporter importer(state->inputdir, state->outputdir); - const icu::CollationTailoring *base = icu::CollationRoot::getRoot(intStatus); - if(U_FAILURE(intStatus)) { - error(line, "failed to load root collator (ucadata.icu) - %s", u_errorName(intStatus)); - res_close(result); - return NULL; // TODO: use LocalUResourceBundlePointer for result - } - icu::CollationBuilder builder(base, intStatus); - if(uprv_strncmp(collationType, "search", 6) == 0) { - builder.disableFastLatin(); // build fast-Latin table unless search collator - } - LocalPointer<icu::CollationTailoring> t( - builder.parseAndBuild(rules, version, &importer, &parseError, intStatus)); - if(U_FAILURE(intStatus)) { - const char *reason = builder.getErrorReason(); - if(reason == NULL) { reason = ""; } - error(line, "CollationBuilder failed at %s~%s/Sequence rule offset %ld: %s %s", - state->filename, collationType, - (long)parseError.offset, u_errorName(intStatus), reason); - if(parseError.preContext[0] != 0 || parseError.postContext[0] != 0) { - // Print pre- and post-context. - char preBuffer[100], postBuffer[100]; - escape(parseError.preContext, preBuffer); - escape(parseError.postContext, postBuffer); - error(line, " error context: \"...%s\" ! \"%s...\"", preBuffer, postBuffer); - } - if(isStrict() || t.isNull()) { - *status = intStatus; - res_close(result); - return NULL; - } - } - icu::LocalMemory<uint8_t> buffer; - int32_t capacity = 100000; - uint8_t *dest = buffer.allocateInsteadAndCopy(capacity); - if(dest == NULL) { - fprintf(stderr, "memory allocation (%ld bytes) for file contents failed\n", - (long)capacity); - *status = U_MEMORY_ALLOCATION_ERROR; - res_close(result); - return NULL; - } - int32_t indexes[icu::CollationDataReader::IX_TOTAL_SIZE + 1]; - int32_t totalSize = icu::CollationDataWriter::writeTailoring( - *t, *t->settings, indexes, dest, capacity, intStatus); - if(intStatus == U_BUFFER_OVERFLOW_ERROR) { - intStatus = U_ZERO_ERROR; - capacity = totalSize; - dest = buffer.allocateInsteadAndCopy(capacity); - if(dest == NULL) { - fprintf(stderr, "memory allocation (%ld bytes) for file contents failed\n", - (long)capacity); - *status = U_MEMORY_ALLOCATION_ERROR; - res_close(result); - return NULL; - } - totalSize = icu::CollationDataWriter::writeTailoring( - *t, *t->settings, indexes, dest, capacity, intStatus); - } - if(U_FAILURE(intStatus)) { - fprintf(stderr, "CollationDataWriter::writeTailoring() failed: %s\n", - u_errorName(intStatus)); - res_close(result); - return NULL; - } - if(isVerbose()) { - printf("%s~%s collation tailoring part sizes:\n", state->filename, collationType); - icu::CollationInfo::printSizes(totalSize, indexes); - if(t->settings->hasReordering()) { - printf("%s~%s collation reordering ranges:\n", state->filename, collationType); - icu::CollationInfo::printReorderRanges( - *t->data, t->settings->reorderCodes, t->settings->reorderCodesLength); - } -#if 0 // debugging output - } else { - printf("%s~%s collation tailoring part sizes:\n", state->filename, collationType); - icu::CollationInfo::printSizes(totalSize, indexes); -#endif - } - struct SResource *collationBin = bin_open(state->bundle, "%%CollationBin", totalSize, dest, NULL, NULL, status); - result->add(collationBin, line, *status); - if (U_FAILURE(*status)) { - res_close(result); - return NULL; - } -#endif - return result; -} - -static UBool -keepCollationType(const char * /*type*/) { - return TRUE; -} - -static struct SResource * -parseCollationElements(ParseState* state, char *tag, uint32_t startline, UBool newCollation, UErrorCode *status) -{ - TableResource *result = NULL; - struct SResource *member = NULL; - struct UString *tokenValue; - struct UString comment; - enum ETokenType token; - char subtag[1024], typeKeyword[1024]; - uint32_t line; - - result = table_open(state->bundle, tag, NULL, status); - - if (result == NULL || U_FAILURE(*status)) - { - return NULL; - } - if(isVerbose()){ - printf(" collation elements %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - if(!newCollation) { - return addCollation(state, result, "(no type)", startline, status); - } - else { - for(;;) { - ustr_init(&comment); - token = getToken(state, &tokenValue, &comment, &line, status); - - if (token == TOK_CLOSE_BRACE) - { - return result; - } - - if (token != TOK_STRING) - { - res_close(result); - *status = U_INVALID_FORMAT_ERROR; - - if (token == TOK_EOF) - { - error(startline, "unterminated table"); - } - else - { - error(line, "Unexpected token %s", tokenNames[token]); - } - - return NULL; - } - - u_UCharsToChars(tokenValue->fChars, subtag, u_strlen(tokenValue->fChars) + 1); - - if (U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - - if (uprv_strcmp(subtag, "default") == 0) - { - member = parseResource(state, subtag, NULL, status); - - if (U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - - result->add(member, line, *status); - } - else - { - token = peekToken(state, 0, &tokenValue, &line, &comment, status); - /* this probably needs to be refactored or recursively use the parser */ - /* first we assume that our collation table won't have the explicit type */ - /* then, we cannot handle aliases */ - if(token == TOK_OPEN_BRACE) { - token = getToken(state, &tokenValue, &comment, &line, status); - TableResource *collationRes; - if (keepCollationType(subtag)) { - collationRes = table_open(state->bundle, subtag, NULL, status); - } else { - collationRes = NULL; - } - // need to parse the collation data regardless - collationRes = addCollation(state, collationRes, subtag, startline, status); - if (collationRes != NULL) { - result->add(collationRes, startline, *status); - } - } else if(token == TOK_COLON) { /* right now, we'll just try to see if we have aliases */ - /* we could have a table too */ - token = peekToken(state, 1, &tokenValue, &line, &comment, status); - u_UCharsToChars(tokenValue->fChars, typeKeyword, u_strlen(tokenValue->fChars) + 1); - if(uprv_strcmp(typeKeyword, "alias") == 0) { - member = parseResource(state, subtag, NULL, status); - if (U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - - result->add(member, line, *status); - } else { - res_close(result); - *status = U_INVALID_FORMAT_ERROR; - return NULL; - } - } else { - res_close(result); - *status = U_INVALID_FORMAT_ERROR; - return NULL; - } - } - - /*member = string_open(bundle, subtag, tokenValue->fChars, tokenValue->fLength, status);*/ - - /*expect(TOK_CLOSE_BRACE, NULL, NULL, status);*/ - - if (U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - } - } -} - -/* Necessary, because CollationElements requires the bundle->fRoot member to be present which, - if this weren't special-cased, wouldn't be set until the entire file had been processed. */ -static struct SResource * -realParseTable(ParseState* state, TableResource *table, char *tag, uint32_t startline, UErrorCode *status) -{ - struct SResource *member = NULL; - struct UString *tokenValue=NULL; - struct UString comment; - enum ETokenType token; - char subtag[1024]; - uint32_t line; - UBool readToken = FALSE; - - /* '{' . (name resource)* '}' */ - - if(isVerbose()){ - printf(" parsing table %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - for (;;) - { - ustr_init(&comment); - token = getToken(state, &tokenValue, &comment, &line, status); - - if (token == TOK_CLOSE_BRACE) - { - if (!readToken) { - warning(startline, "Encountered empty table"); - } - return table; - } - - if (token != TOK_STRING) - { - *status = U_INVALID_FORMAT_ERROR; - - if (token == TOK_EOF) - { - error(startline, "unterminated table"); - } - else - { - error(line, "unexpected token %s", tokenNames[token]); - } - - return NULL; - } - - if(uprv_isInvariantUString(tokenValue->fChars, -1)) { - u_UCharsToChars(tokenValue->fChars, subtag, u_strlen(tokenValue->fChars) + 1); - } else { - *status = U_INVALID_FORMAT_ERROR; - error(line, "invariant characters required for table keys"); - return NULL; - } - - if (U_FAILURE(*status)) - { - error(line, "parse error. Stopped parsing tokens with %s", u_errorName(*status)); - return NULL; - } - - member = parseResource(state, subtag, &comment, status); - - if (member == NULL || U_FAILURE(*status)) - { - error(line, "parse error. Stopped parsing resource with %s", u_errorName(*status)); - return NULL; - } - - table->add(member, line, *status); - - if (U_FAILURE(*status)) - { - error(line, "parse error. Stopped parsing table with %s", u_errorName(*status)); - return NULL; - } - readToken = TRUE; - ustr_deinit(&comment); - } - - /* not reached */ - /* A compiler warning will appear if all paths don't contain a return statement. */ -/* *status = U_INTERNAL_PROGRAM_ERROR; - return NULL;*/ -} - -static struct SResource * -parseTable(ParseState* state, char *tag, uint32_t startline, const struct UString *comment, UErrorCode *status) -{ - if (tag != NULL && uprv_strcmp(tag, "CollationElements") == 0) - { - return parseCollationElements(state, tag, startline, FALSE, status); - } - if (tag != NULL && uprv_strcmp(tag, "collations") == 0) - { - return parseCollationElements(state, tag, startline, TRUE, status); - } - if(isVerbose()){ - printf(" table %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - - TableResource *result = table_open(state->bundle, tag, comment, status); - - if (result == NULL || U_FAILURE(*status)) - { - return NULL; - } - return realParseTable(state, result, tag, startline, status); -} - -static struct SResource * -parseArray(ParseState* state, char *tag, uint32_t startline, const struct UString *comment, UErrorCode *status) -{ - struct SResource *member = NULL; - struct UString *tokenValue; - struct UString memberComments; - enum ETokenType token; - UBool readToken = FALSE; - - ArrayResource *result = array_open(state->bundle, tag, comment, status); - - if (result == NULL || U_FAILURE(*status)) - { - return NULL; - } - if(isVerbose()){ - printf(" array %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - - ustr_init(&memberComments); - - /* '{' . resource [','] '}' */ - for (;;) - { - /* reset length */ - ustr_setlen(&memberComments, 0, status); - - /* check for end of array, but don't consume next token unless it really is the end */ - token = peekToken(state, 0, &tokenValue, NULL, &memberComments, status); - - - if (token == TOK_CLOSE_BRACE) - { - getToken(state, NULL, NULL, NULL, status); - if (!readToken) { - warning(startline, "Encountered empty array"); - } - break; - } - - if (token == TOK_EOF) - { - res_close(result); - *status = U_INVALID_FORMAT_ERROR; - error(startline, "unterminated array"); - return NULL; - } - - /* string arrays are a special case */ - if (token == TOK_STRING) - { - getToken(state, &tokenValue, &memberComments, NULL, status); - member = string_open(state->bundle, NULL, tokenValue->fChars, tokenValue->fLength, &memberComments, status); - } - else - { - member = parseResource(state, NULL, &memberComments, status); - } - - if (member == NULL || U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - - result->add(member); - - /* eat optional comma if present */ - token = peekToken(state, 0, NULL, NULL, NULL, status); - - if (token == TOK_COMMA) - { - getToken(state, NULL, NULL, NULL, status); - } - - if (U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - readToken = TRUE; - } - - ustr_deinit(&memberComments); - return result; -} - -static struct SResource * -parseIntVector(ParseState* state, char *tag, uint32_t startline, const struct UString *comment, UErrorCode *status) -{ - enum ETokenType token; - char *string; - int32_t value; - UBool readToken = FALSE; - char *stopstring; - uint32_t len; - struct UString memberComments; - - IntVectorResource *result = intvector_open(state->bundle, tag, comment, status); - - if (result == NULL || U_FAILURE(*status)) - { - return NULL; - } - - if(isVerbose()){ - printf(" vector %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - ustr_init(&memberComments); - /* '{' . string [','] '}' */ - for (;;) - { - ustr_setlen(&memberComments, 0, status); - - /* check for end of array, but don't consume next token unless it really is the end */ - token = peekToken(state, 0, NULL, NULL,&memberComments, status); - - if (token == TOK_CLOSE_BRACE) - { - /* it's the end, consume the close brace */ - getToken(state, NULL, NULL, NULL, status); - if (!readToken) { - warning(startline, "Encountered empty int vector"); - } - ustr_deinit(&memberComments); - return result; - } - - string = getInvariantString(state, NULL, NULL, status); - - if (U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - - /* For handling illegal char in the Intvector */ - value = uprv_strtoul(string, &stopstring, 0);/* make intvector support decimal,hexdigit,octal digit ranging from -2^31-2^32-1*/ - len=(uint32_t)(stopstring-string); - - if(len==uprv_strlen(string)) - { - result->add(value, *status); - uprv_free(string); - token = peekToken(state, 0, NULL, NULL, NULL, status); - } - else - { - uprv_free(string); - *status=U_INVALID_CHAR_FOUND; - } - - if (U_FAILURE(*status)) - { - res_close(result); - return NULL; - } - - /* the comma is optional (even though it is required to prevent the reader from concatenating - consecutive entries) so that a missing comma on the last entry isn't an error */ - if (token == TOK_COMMA) - { - getToken(state, NULL, NULL, NULL, status); - } - readToken = TRUE; - } - - /* not reached */ - /* A compiler warning will appear if all paths don't contain a return statement. */ -/* intvector_close(result, status); - *status = U_INTERNAL_PROGRAM_ERROR; - return NULL;*/ -} - -static struct SResource * -parseBinary(ParseState* state, char *tag, uint32_t startline, const struct UString *comment, UErrorCode *status) -{ - uint32_t line; - LocalMemory<char> string(getInvariantString(state, &line, NULL, status)); - if (string.isNull() || U_FAILURE(*status)) - { - return NULL; - } - - expect(state, TOK_CLOSE_BRACE, NULL, NULL, NULL, status); - if (U_FAILURE(*status)) - { - return NULL; - } - - if(isVerbose()){ - printf(" binary %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - - uint32_t count = (uint32_t)uprv_strlen(string.getAlias()); - if (count > 0){ - if((count % 2)==0){ - LocalMemory<uint8_t> value; - if (value.allocateInsteadAndCopy(count) == NULL) - { - *status = U_MEMORY_ALLOCATION_ERROR; - return NULL; - } - - char toConv[3] = {'\0', '\0', '\0'}; - for (uint32_t i = 0; i < count; i += 2) - { - toConv[0] = string[i]; - toConv[1] = string[i + 1]; - - char *stopstring; - value[i >> 1] = (uint8_t) uprv_strtoul(toConv, &stopstring, 16); - uint32_t len=(uint32_t)(stopstring-toConv); - - if(len!=2) - { - *status=U_INVALID_CHAR_FOUND; - return NULL; - } - } - - return bin_open(state->bundle, tag, count >> 1, value.getAlias(), NULL, comment, status); - } - else - { - *status = U_INVALID_CHAR_FOUND; - error(line, "Encountered invalid binary value (length is odd)"); - return NULL; - } - } - else - { - warning(startline, "Encountered empty binary value"); - return bin_open(state->bundle, tag, 0, NULL, "", comment, status); - } -} - -static struct SResource * -parseInteger(ParseState* state, char *tag, uint32_t startline, const struct UString *comment, UErrorCode *status) -{ - struct SResource *result = NULL; - int32_t value; - char *string; - char *stopstring; - uint32_t len; - - string = getInvariantString(state, NULL, NULL, status); - - if (string == NULL || U_FAILURE(*status)) - { - return NULL; - } - - expect(state, TOK_CLOSE_BRACE, NULL, NULL, NULL, status); - - if (U_FAILURE(*status)) - { - uprv_free(string); - return NULL; - } - - if(isVerbose()){ - printf(" integer %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - - if (uprv_strlen(string) <= 0) - { - warning(startline, "Encountered empty integer. Default value is 0."); - } - - /* Allow integer support for hexdecimal, octal digit and decimal*/ - /* and handle illegal char in the integer*/ - value = uprv_strtoul(string, &stopstring, 0); - len=(uint32_t)(stopstring-string); - if(len==uprv_strlen(string)) - { - result = int_open(state->bundle, tag, value, comment, status); - } - else - { - *status=U_INVALID_CHAR_FOUND; - } - uprv_free(string); - - return result; -} - -static struct SResource * -parseImport(ParseState* state, char *tag, uint32_t startline, const struct UString* comment, UErrorCode *status) -{ - uint32_t line; - LocalMemory<char> filename(getInvariantString(state, &line, NULL, status)); - if (U_FAILURE(*status)) - { - return NULL; - } - - expect(state, TOK_CLOSE_BRACE, NULL, NULL, NULL, status); - - if (U_FAILURE(*status)) - { - return NULL; - } - - if(isVerbose()){ - printf(" import %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - - /* Open the input file for reading */ - CharString fullname; - if (state->inputdir != NULL) { - fullname.append(state->inputdir, *status); - } - fullname.appendPathPart(filename.getAlias(), *status); - if (U_FAILURE(*status)) { - return NULL; - } - - FileStream *file = T_FileStream_open(fullname.data(), "rb"); - if (file == NULL) - { - error(line, "couldn't open input file %s", filename.getAlias()); - *status = U_FILE_ACCESS_ERROR; - return NULL; - } - - int32_t len = T_FileStream_size(file); - LocalMemory<uint8_t> data; - if(data.allocateInsteadAndCopy(len) == NULL) - { - *status = U_MEMORY_ALLOCATION_ERROR; - T_FileStream_close (file); - return NULL; - } - - /* int32_t numRead = */ T_FileStream_read(file, data.getAlias(), len); - T_FileStream_close (file); - - return bin_open(state->bundle, tag, len, data.getAlias(), fullname.data(), comment, status); -} - -static struct SResource * -parseInclude(ParseState* state, char *tag, uint32_t startline, const struct UString* comment, UErrorCode *status) -{ - struct SResource *result; - int32_t len=0; - char *filename; - uint32_t line; - UChar *pTarget = NULL; - - UCHARBUF *ucbuf; - char *fullname = NULL; - int32_t count = 0; - const char* cp = NULL; - const UChar* uBuffer = NULL; - - filename = getInvariantString(state, &line, NULL, status); - count = (int32_t)uprv_strlen(filename); - - if (U_FAILURE(*status)) - { - return NULL; - } - - expect(state, TOK_CLOSE_BRACE, NULL, NULL, NULL, status); - - if (U_FAILURE(*status)) - { - uprv_free(filename); - return NULL; - } - - if(isVerbose()){ - printf(" include %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - - fullname = (char *) uprv_malloc(state->inputdirLength + count + 2); - /* test for NULL */ - if(fullname == NULL) - { - *status = U_MEMORY_ALLOCATION_ERROR; - uprv_free(filename); - return NULL; - } - - if(state->inputdir!=NULL){ - if (state->inputdir[state->inputdirLength - 1] != U_FILE_SEP_CHAR) - { - - uprv_strcpy(fullname, state->inputdir); - - fullname[state->inputdirLength] = U_FILE_SEP_CHAR; - fullname[state->inputdirLength + 1] = '\0'; - - uprv_strcat(fullname, filename); - } - else - { - uprv_strcpy(fullname, state->inputdir); - uprv_strcat(fullname, filename); - } - }else{ - uprv_strcpy(fullname,filename); - } - - ucbuf = ucbuf_open(fullname, &cp,getShowWarning(),FALSE,status); - - if (U_FAILURE(*status)) { - error(line, "couldn't open input file %s\n", filename); - return NULL; - } - - uBuffer = ucbuf_getBuffer(ucbuf,&len,status); - result = string_open(state->bundle, tag, uBuffer, len, comment, status); - - ucbuf_close(ucbuf); - - uprv_free(pTarget); - - uprv_free(filename); - uprv_free(fullname); - - return result; -} - - - - - -U_STRING_DECL(k_type_string, "string", 6); -U_STRING_DECL(k_type_binary, "binary", 6); -U_STRING_DECL(k_type_bin, "bin", 3); -U_STRING_DECL(k_type_table, "table", 5); -U_STRING_DECL(k_type_table_no_fallback, "table(nofallback)", 17); -U_STRING_DECL(k_type_int, "int", 3); -U_STRING_DECL(k_type_integer, "integer", 7); -U_STRING_DECL(k_type_array, "array", 5); -U_STRING_DECL(k_type_alias, "alias", 5); -U_STRING_DECL(k_type_intvector, "intvector", 9); -U_STRING_DECL(k_type_import, "import", 6); -U_STRING_DECL(k_type_include, "include", 7); - -/* Various non-standard processing plugins that create one or more special resources. */ -U_STRING_DECL(k_type_plugin_uca_rules, "process(uca_rules)", 18); -U_STRING_DECL(k_type_plugin_collation, "process(collation)", 18); -U_STRING_DECL(k_type_plugin_transliterator, "process(transliterator)", 23); -U_STRING_DECL(k_type_plugin_dependency, "process(dependency)", 19); - -typedef enum EResourceType -{ - RESTYPE_UNKNOWN, - RESTYPE_STRING, - RESTYPE_BINARY, - RESTYPE_TABLE, - RESTYPE_TABLE_NO_FALLBACK, - RESTYPE_INTEGER, - RESTYPE_ARRAY, - RESTYPE_ALIAS, - RESTYPE_INTVECTOR, - RESTYPE_IMPORT, - RESTYPE_INCLUDE, - RESTYPE_PROCESS_UCA_RULES, - RESTYPE_PROCESS_COLLATION, - RESTYPE_PROCESS_TRANSLITERATOR, - RESTYPE_PROCESS_DEPENDENCY, - RESTYPE_RESERVED -} EResourceType; - -static struct { - const char *nameChars; /* only used for debugging */ - const UChar *nameUChars; - ParseResourceFunction *parseFunction; -} gResourceTypes[] = { - {"Unknown", NULL, NULL}, - {"string", k_type_string, parseString}, - {"binary", k_type_binary, parseBinary}, - {"table", k_type_table, parseTable}, - {"table(nofallback)", k_type_table_no_fallback, NULL}, /* parseFunction will never be called */ - {"integer", k_type_integer, parseInteger}, - {"array", k_type_array, parseArray}, - {"alias", k_type_alias, parseAlias}, - {"intvector", k_type_intvector, parseIntVector}, - {"import", k_type_import, parseImport}, - {"include", k_type_include, parseInclude}, - {"process(uca_rules)", k_type_plugin_uca_rules, parseUCARules}, - {"process(collation)", k_type_plugin_collation, NULL /* not implemented yet */}, - {"process(transliterator)", k_type_plugin_transliterator, parseTransliterator}, - {"process(dependency)", k_type_plugin_dependency, parseDependency}, - {"reserved", NULL, NULL} -}; - -void initParser() -{ - U_STRING_INIT(k_type_string, "string", 6); - U_STRING_INIT(k_type_binary, "binary", 6); - U_STRING_INIT(k_type_bin, "bin", 3); - U_STRING_INIT(k_type_table, "table", 5); - U_STRING_INIT(k_type_table_no_fallback, "table(nofallback)", 17); - U_STRING_INIT(k_type_int, "int", 3); - U_STRING_INIT(k_type_integer, "integer", 7); - U_STRING_INIT(k_type_array, "array", 5); - U_STRING_INIT(k_type_alias, "alias", 5); - U_STRING_INIT(k_type_intvector, "intvector", 9); - U_STRING_INIT(k_type_import, "import", 6); - U_STRING_INIT(k_type_include, "include", 7); - - U_STRING_INIT(k_type_plugin_uca_rules, "process(uca_rules)", 18); - U_STRING_INIT(k_type_plugin_collation, "process(collation)", 18); - U_STRING_INIT(k_type_plugin_transliterator, "process(transliterator)", 23); - U_STRING_INIT(k_type_plugin_dependency, "process(dependency)", 19); -} - -static inline UBool isTable(enum EResourceType type) { - return (UBool)(type==RESTYPE_TABLE || type==RESTYPE_TABLE_NO_FALLBACK); -} - -static enum EResourceType -parseResourceType(ParseState* state, UErrorCode *status) -{ - struct UString *tokenValue; - struct UString comment; - enum EResourceType result = RESTYPE_UNKNOWN; - uint32_t line=0; - ustr_init(&comment); - expect(state, TOK_STRING, &tokenValue, &comment, &line, status); - - if (U_FAILURE(*status)) - { - return RESTYPE_UNKNOWN; - } - - *status = U_ZERO_ERROR; - - /* Search for normal types */ - result=RESTYPE_UNKNOWN; - while ((result=(EResourceType)(result+1)) < RESTYPE_RESERVED) { - if (u_strcmp(tokenValue->fChars, gResourceTypes[result].nameUChars) == 0) { - break; - } - } - /* Now search for the aliases */ - if (u_strcmp(tokenValue->fChars, k_type_int) == 0) { - result = RESTYPE_INTEGER; - } - else if (u_strcmp(tokenValue->fChars, k_type_bin) == 0) { - result = RESTYPE_BINARY; - } - else if (result == RESTYPE_RESERVED) { - char tokenBuffer[1024]; - u_austrncpy(tokenBuffer, tokenValue->fChars, sizeof(tokenBuffer)); - tokenBuffer[sizeof(tokenBuffer) - 1] = 0; - *status = U_INVALID_FORMAT_ERROR; - error(line, "unknown resource type '%s'", tokenBuffer); - } - - return result; -} - -/* parse a non-top-level resource */ -static struct SResource * -parseResource(ParseState* state, char *tag, const struct UString *comment, UErrorCode *status) -{ - enum ETokenType token; - enum EResourceType resType = RESTYPE_UNKNOWN; - ParseResourceFunction *parseFunction = NULL; - struct UString *tokenValue; - uint32_t startline; - uint32_t line; - - - token = getToken(state, &tokenValue, NULL, &startline, status); - - if(isVerbose()){ - printf(" resource %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); - } - - /* name . [ ':' type ] '{' resource '}' */ - /* This function parses from the colon onwards. If the colon is present, parse the - type then try to parse a resource of that type. If there is no explicit type, - work it out using the lookahead tokens. */ - switch (token) - { - case TOK_EOF: - *status = U_INVALID_FORMAT_ERROR; - error(startline, "Unexpected EOF encountered"); - return NULL; - - case TOK_ERROR: - *status = U_INVALID_FORMAT_ERROR; - return NULL; - - case TOK_COLON: - resType = parseResourceType(state, status); - expect(state, TOK_OPEN_BRACE, &tokenValue, NULL, &startline, status); - - if (U_FAILURE(*status)) - { - return NULL; - } - - break; - - case TOK_OPEN_BRACE: - break; - - default: - *status = U_INVALID_FORMAT_ERROR; - error(startline, "syntax error while reading a resource, expected '{' or ':'"); - return NULL; - } - - - if (resType == RESTYPE_UNKNOWN) - { - /* No explicit type, so try to work it out. At this point, we've read the first '{'. - We could have any of the following: - { { => array (nested) - { :/} => array - { string , => string array - - { string { => table - - { string :/{ => table - { string } => string - */ - - token = peekToken(state, 0, NULL, &line, NULL,status); - - if (U_FAILURE(*status)) - { - return NULL; - } - - if (token == TOK_OPEN_BRACE || token == TOK_COLON ||token ==TOK_CLOSE_BRACE ) - { - resType = RESTYPE_ARRAY; - } - else if (token == TOK_STRING) - { - token = peekToken(state, 1, NULL, &line, NULL, status); - - if (U_FAILURE(*status)) - { - return NULL; - } - - switch (token) - { - case TOK_COMMA: resType = RESTYPE_ARRAY; break; - case TOK_OPEN_BRACE: resType = RESTYPE_TABLE; break; - case TOK_CLOSE_BRACE: resType = RESTYPE_STRING; break; - case TOK_COLON: resType = RESTYPE_TABLE; break; - default: - *status = U_INVALID_FORMAT_ERROR; - error(line, "Unexpected token after string, expected ',', '{' or '}'"); - return NULL; - } - } - else - { - *status = U_INVALID_FORMAT_ERROR; - error(line, "Unexpected token after '{'"); - return NULL; - } - - /* printf("Type guessed as %s\n", resourceNames[resType]); */ - } else if(resType == RESTYPE_TABLE_NO_FALLBACK) { - *status = U_INVALID_FORMAT_ERROR; - error(startline, "error: %s resource type not valid except on top bundle level", gResourceTypes[resType].nameChars); - return NULL; - } - - - /* We should now know what we need to parse next, so call the appropriate parser - function and return. */ - parseFunction = gResourceTypes[resType].parseFunction; - if (parseFunction != NULL) { - return parseFunction(state, tag, startline, comment, status); - } - else { - *status = U_INTERNAL_PROGRAM_ERROR; - error(startline, "internal error: %s resource type found and not handled", gResourceTypes[resType].nameChars); - } - - return NULL; -} - -/* parse the top-level resource */ -struct SRBRoot * -parse(UCHARBUF *buf, const char *inputDir, const char *outputDir, const char *filename, - UBool makeBinaryCollation, UBool omitCollationRules, UErrorCode *status) -{ - struct UString *tokenValue; - struct UString comment; - uint32_t line; - enum EResourceType bundleType; - enum ETokenType token; - ParseState state; - uint32_t i; - - - for (i = 0; i < MAX_LOOKAHEAD + 1; i++) - { - ustr_init(&state.lookahead[i].value); - ustr_init(&state.lookahead[i].comment); - } - - initLookahead(&state, buf, status); - - state.inputdir = inputDir; - state.inputdirLength = (state.inputdir != NULL) ? (uint32_t)uprv_strlen(state.inputdir) : 0; - state.outputdir = outputDir; - state.outputdirLength = (state.outputdir != NULL) ? (uint32_t)uprv_strlen(state.outputdir) : 0; - state.filename = filename; - state.makeBinaryCollation = makeBinaryCollation; - state.omitCollationRules = omitCollationRules; - - ustr_init(&comment); - expect(&state, TOK_STRING, &tokenValue, &comment, NULL, status); - - state.bundle = new SRBRoot(&comment, FALSE, *status); - - if (state.bundle == NULL || U_FAILURE(*status)) - { - return NULL; - } - - - state.bundle->setLocale(tokenValue->fChars, *status); - - /* The following code is to make Empty bundle work no matter with :table specifer or not */ - token = getToken(&state, NULL, NULL, &line, status); - if(token==TOK_COLON) { - *status=U_ZERO_ERROR; - bundleType=parseResourceType(&state, status); - - if(isTable(bundleType)) - { - expect(&state, TOK_OPEN_BRACE, NULL, NULL, &line, status); - } - else - { - *status=U_PARSE_ERROR; - error(line, "parse error. Stopped parsing with %s", u_errorName(*status)); - } - } - else - { - /* not a colon */ - if(token==TOK_OPEN_BRACE) - { - *status=U_ZERO_ERROR; - bundleType=RESTYPE_TABLE; - } - else - { - /* neither colon nor open brace */ - *status=U_PARSE_ERROR; - bundleType=RESTYPE_UNKNOWN; - error(line, "parse error, did not find open-brace '{' or colon ':', stopped with %s", u_errorName(*status)); - } - } - - if (U_FAILURE(*status)) - { - delete state.bundle; - return NULL; - } - - if(bundleType==RESTYPE_TABLE_NO_FALLBACK) { - /* - * Parse a top-level table with the table(nofallback) declaration. - * This is the same as a regular table, but also sets the - * URES_ATT_NO_FALLBACK flag in indexes[URES_INDEX_ATTRIBUTES] . - */ - state.bundle->fNoFallback=TRUE; - } - /* top-level tables need not handle special table names like "collations" */ - assert(!state.bundle->fIsPoolBundle); - assert(state.bundle->fRoot->fType == URES_TABLE); - TableResource *rootTable = static_cast<TableResource *>(state.bundle->fRoot); - realParseTable(&state, rootTable, NULL, line, status); - if(dependencyArray!=NULL){ - rootTable->add(dependencyArray, 0, *status); - dependencyArray = NULL; - } - if (U_FAILURE(*status)) - { - delete state.bundle; - res_close(dependencyArray); - return NULL; - } - - if (getToken(&state, NULL, NULL, &line, status) != TOK_EOF) - { - warning(line, "extraneous text after resource bundle (perhaps unmatched braces)"); - if(isStrict()){ - *status = U_INVALID_FORMAT_ERROR; - return NULL; - } - } - - cleanupLookahead(&state); - ustr_deinit(&comment); - return state.bundle; -} diff --git a/deps/node/deps/icu-small/source/tools/genrb/parse.h b/deps/node/deps/icu-small/source/tools/genrb/parse.h deleted file mode 100644 index dfe3b8dd..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/parse.h +++ /dev/null @@ -1,38 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2014, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File parse.h -* -* Modification History: -* -* Date Name Description -* 05/26/99 stephen Creation. -******************************************************************************* -*/ - -#ifndef PARSE_H -#define PARSE_H 1 - -#include "unicode/utypes.h" -#include "filestrm.h" -#include "ucbuf.h" - -U_CDECL_BEGIN -/* One time parser initalisation */ -void initParser(); - -/* Parse a ResourceBundle text file */ -struct SRBRoot* parse(UCHARBUF *buf, const char* inputDir, const char* outputDir, - const char *filename, - UBool makeBinaryCollation, UBool omitCollationRules, UErrorCode *status); - -U_CDECL_END - -#endif diff --git a/deps/node/deps/icu-small/source/tools/genrb/prscmnts.cpp b/deps/node/deps/icu-small/source/tools/genrb/prscmnts.cpp deleted file mode 100644 index 5d494cd9..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/prscmnts.cpp +++ /dev/null @@ -1,247 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* - ******************************************************************************* - * Copyright (C) 2003-2014, International Business Machines - * Corporation and others. All Rights Reserved. - ******************************************************************************* - * - * File prscmnts.cpp - * - * Modification History: - * - * Date Name Description - * 08/22/2003 ram Creation. - ******************************************************************************* - */ - -// Safer use of UnicodeString. -#ifndef UNISTR_FROM_CHAR_EXPLICIT -# define UNISTR_FROM_CHAR_EXPLICIT explicit -#endif - -// Less important, but still a good idea. -#ifndef UNISTR_FROM_STRING_EXPLICIT -# define UNISTR_FROM_STRING_EXPLICIT explicit -#endif - -#include "unicode/regex.h" -#include "unicode/unistr.h" -#include "unicode/parseerr.h" -#include "prscmnts.h" -#include <stdio.h> -#include <stdlib.h> - -U_NAMESPACE_USE - -#if UCONFIG_NO_REGULAR_EXPRESSIONS==0 /* donot compile when RegularExpressions not available */ - -#define MAX_SPLIT_STRINGS 20 - -const char *patternStrings[UPC_LIMIT]={ - "^translate\\s*(.*)", - "^note\\s*(.*)" -}; - -U_CFUNC int32_t -removeText(UChar *source, int32_t srcLen, - UnicodeString patString,uint32_t options, - UnicodeString replaceText, UErrorCode *status){ - - if(status == NULL || U_FAILURE(*status)){ - return 0; - } - - UnicodeString src(source, srcLen); - - RegexMatcher myMatcher(patString, src, options, *status); - if(U_FAILURE(*status)){ - return 0; - } - UnicodeString dest; - - - dest = myMatcher.replaceAll(replaceText,*status); - - - return dest.extract(source, srcLen, *status); - -} -U_CFUNC int32_t -trim(UChar *src, int32_t srcLen, UErrorCode *status){ - srcLen = removeText(src, srcLen, UnicodeString("^[ \\r\\n]+ "), 0, UnicodeString(), status); // remove leading new lines - srcLen = removeText(src, srcLen, UnicodeString("^\\s+"), 0, UnicodeString(), status); // remove leading spaces - srcLen = removeText(src, srcLen, UnicodeString("\\s+$"), 0, UnicodeString(), status); // remvoe trailing spcaes - return srcLen; -} - -U_CFUNC int32_t -removeCmtText(UChar* source, int32_t srcLen, UErrorCode* status){ - srcLen = trim(source, srcLen, status); - UnicodeString patString("^\\s*?\\*\\s*?"); // remove pattern like " * " at the begining of the line - srcLen = removeText(source, srcLen, patString, UREGEX_MULTILINE, UnicodeString(), status); - return removeText(source, srcLen, UnicodeString("[ \\r\\n]+"), 0, UnicodeString(" "), status);// remove new lines; -} - -U_CFUNC int32_t -getText(const UChar* source, int32_t srcLen, - UChar** dest, int32_t destCapacity, - UnicodeString patternString, - UErrorCode* status){ - - if(status == NULL || U_FAILURE(*status)){ - return 0; - } - - UnicodeString stringArray[MAX_SPLIT_STRINGS]; - RegexPattern *pattern = RegexPattern::compile(UnicodeString("@"), 0, *status); - UnicodeString src (source,srcLen); - - if (U_FAILURE(*status)) { - return 0; - } - pattern->split(src, stringArray, MAX_SPLIT_STRINGS, *status); - - RegexMatcher matcher(patternString, UREGEX_DOTALL, *status); - if (U_FAILURE(*status)) { - return 0; - } - for(int32_t i=0; i<MAX_SPLIT_STRINGS; i++){ - matcher.reset(stringArray[i]); - if(matcher.lookingAt(*status)){ - UnicodeString out = matcher.group(1, *status); - - return out.extract(*dest, destCapacity,*status); - } - } - return 0; -} - - -#define AT_SIGN 0x0040 - -U_CFUNC int32_t -getDescription( const UChar* source, int32_t srcLen, - UChar** dest, int32_t destCapacity, - UErrorCode* status){ - if(status == NULL || U_FAILURE(*status)){ - return 0; - } - - UnicodeString stringArray[MAX_SPLIT_STRINGS]; - RegexPattern *pattern = RegexPattern::compile(UnicodeString("@"), UREGEX_MULTILINE, *status); - UnicodeString src(source, srcLen); - - if (U_FAILURE(*status)) { - return 0; - } - pattern->split(src, stringArray,MAX_SPLIT_STRINGS , *status); - - if(stringArray[0].indexOf((UChar)AT_SIGN)==-1){ - int32_t destLen = stringArray[0].extract(*dest, destCapacity, *status); - return trim(*dest, destLen, status); - } - return 0; -} - -U_CFUNC int32_t -getCount(const UChar* source, int32_t srcLen, - UParseCommentsOption option, UErrorCode *status){ - - if(status == NULL || U_FAILURE(*status)){ - return 0; - } - - UnicodeString stringArray[MAX_SPLIT_STRINGS]; - RegexPattern *pattern = RegexPattern::compile(UnicodeString("@"), UREGEX_MULTILINE, *status); - UnicodeString src (source, srcLen); - - - if (U_FAILURE(*status)) { - return 0; - } - int32_t retLen = pattern->split(src, stringArray, MAX_SPLIT_STRINGS, *status); - - UnicodeString patternString(patternStrings[option]); - RegexMatcher matcher(patternString, UREGEX_DOTALL, *status); - if (U_FAILURE(*status)) { - return 0; - } - int32_t count = 0; - for(int32_t i=0; i<retLen; i++){ - matcher.reset(stringArray[i]); - if(matcher.lookingAt(*status)){ - count++; - } - } - if(option == UPC_TRANSLATE && count > 1){ - fprintf(stderr, "Multiple @translate tags cannot be supported.\n"); - exit(U_UNSUPPORTED_ERROR); - } - return count; -} - -U_CFUNC int32_t -getAt(const UChar* source, int32_t srcLen, - UChar** dest, int32_t destCapacity, - int32_t index, - UParseCommentsOption option, - UErrorCode* status){ - - if(status == NULL || U_FAILURE(*status)){ - return 0; - } - - UnicodeString stringArray[MAX_SPLIT_STRINGS]; - RegexPattern *pattern = RegexPattern::compile(UnicodeString("@"), UREGEX_MULTILINE, *status); - UnicodeString src (source, srcLen); - - - if (U_FAILURE(*status)) { - return 0; - } - int32_t retLen = pattern->split(src, stringArray, MAX_SPLIT_STRINGS, *status); - - UnicodeString patternString(patternStrings[option]); - RegexMatcher matcher(patternString, UREGEX_DOTALL, *status); - if (U_FAILURE(*status)) { - return 0; - } - int32_t count = 0; - for(int32_t i=0; i<retLen; i++){ - matcher.reset(stringArray[i]); - if(matcher.lookingAt(*status)){ - if(count == index){ - UnicodeString out = matcher.group(1, *status); - return out.extract(*dest, destCapacity,*status); - } - count++; - - } - } - return 0; - -} - -U_CFUNC int32_t -getTranslate( const UChar* source, int32_t srcLen, - UChar** dest, int32_t destCapacity, - UErrorCode* status){ - UnicodeString notePatternString("^translate\\s*?(.*)"); - - int32_t destLen = getText(source, srcLen, dest, destCapacity, notePatternString, status); - return trim(*dest, destLen, status); -} - -U_CFUNC int32_t -getNote(const UChar* source, int32_t srcLen, - UChar** dest, int32_t destCapacity, - UErrorCode* status){ - - UnicodeString notePatternString("^note\\s*?(.*)"); - int32_t destLen = getText(source, srcLen, dest, destCapacity, notePatternString, status); - return trim(*dest, destLen, status); - -} - -#endif /* UCONFIG_NO_REGULAR_EXPRESSIONS */ diff --git a/deps/node/deps/icu-small/source/tools/genrb/prscmnts.h b/deps/node/deps/icu-small/source/tools/genrb/prscmnts.h deleted file mode 100644 index 82cf0dea..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/prscmnts.h +++ /dev/null @@ -1,65 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2016, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File read.h -* -* Modification History: -* -* Date Name Description -* 05/26/99 stephen Creation. -* 5/10/01 Ram removed ustdio dependency -******************************************************************************* -*/ - -#ifndef PRSCMNTS_H -#define PRSCMNTS_H 1 - -#include "unicode/utypes.h" - -#if UCONFIG_NO_REGULAR_EXPRESSIONS==0 /* donot compile when no RegularExpressions are available */ - -enum UParseCommentsOption { - UPC_TRANSLATE, - UPC_NOTE, - UPC_LIMIT -}; - -typedef enum UParseCommentsOption UParseCommentsOption; - -U_CFUNC int32_t -getNote(const UChar* source, int32_t srcLen, - UChar** dest, int32_t destCapacity, - UErrorCode* status); -U_CFUNC int32_t -removeCmtText(UChar* source, int32_t srcLen, UErrorCode* status); - -U_CFUNC int32_t -getDescription( const UChar* source, int32_t srcLen, - UChar** dest, int32_t destCapacity, - UErrorCode* status); -U_CFUNC int32_t -getTranslate( const UChar* source, int32_t srcLen, - UChar** dest, int32_t destCapacity, - UErrorCode* status); - -U_CFUNC int32_t -getAt(const UChar* source, int32_t srcLen, - UChar** dest, int32_t destCapacity, - int32_t index, - UParseCommentsOption option, - UErrorCode* status); - -U_CFUNC int32_t -getCount(const UChar* source, int32_t srcLen, - UParseCommentsOption option, UErrorCode *status); - -#endif /* UCONFIG_NO_REGULAR_EXPRESSIONS */ - -#endif diff --git a/deps/node/deps/icu-small/source/tools/genrb/rbutil.c b/deps/node/deps/icu-small/source/tools/genrb/rbutil.c deleted file mode 100644 index 808d35bb..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/rbutil.c +++ /dev/null @@ -1,113 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2008, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File util.c -* -* Modification History: -* -* Date Name Description -* 06/10/99 stephen Creation. -* 02/07/08 Spieth Correct XLIFF generation on EBCDIC platform -* -******************************************************************************* -*/ - -#include "unicode/putil.h" -#include "rbutil.h" -#include "cmemory.h" -#include "cstring.h" - - -/* go from "/usr/local/include/curses.h" to "/usr/local/include" */ -void -get_dirname(char *dirname, - const char *filename) -{ - const char *lastSlash = uprv_strrchr(filename, U_FILE_SEP_CHAR) + 1; - - if(lastSlash>filename) { - uprv_strncpy(dirname, filename, (lastSlash - filename)); - *(dirname + (lastSlash - filename)) = '\0'; - } else { - *dirname = '\0'; - } -} - -/* go from "/usr/local/include/curses.h" to "curses" */ -void -get_basename(char *basename, - const char *filename) -{ - /* strip off any leading directory portions */ - const char *lastSlash = uprv_strrchr(filename, U_FILE_SEP_CHAR) + 1; - char *lastDot; - - if(lastSlash>filename) { - uprv_strcpy(basename, lastSlash); - } else { - uprv_strcpy(basename, filename); - } - - /* strip off any suffix */ - lastDot = uprv_strrchr(basename, '.'); - - if(lastDot != NULL) { - *lastDot = '\0'; - } -} - -#define MAX_DIGITS 10 -int32_t -itostr(char * buffer, int32_t i, uint32_t radix, int32_t pad) -{ - const char digits[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; - int32_t length = 0; - int32_t num = 0; - int32_t save = i; - int digit; - int32_t j; - char temp; - - /* if i is negative make it positive */ - if(i<0){ - i=-i; - } - - do{ - digit = (int)(i % radix); - buffer[length++]= digits[digit]; - i=i/radix; - } while(i); - - while (length < pad){ - buffer[length++] = '0';/*zero padding */ - } - - /* if i is negative add the negative sign */ - if(save < 0){ - buffer[length++]='-'; - } - - /* null terminate the buffer */ - if(length<MAX_DIGITS){ - buffer[length] = 0x0000; - } - - num= (pad>=length) ? pad :length; - - - /* Reverses the string */ - for (j = 0; j < (num / 2); j++){ - temp = buffer[(length-1) - j]; - buffer[(length-1) - j] = buffer[j]; - buffer[j] = temp; - } - return length; -} diff --git a/deps/node/deps/icu-small/source/tools/genrb/rbutil.h b/deps/node/deps/icu-small/source/tools/genrb/rbutil.h deleted file mode 100644 index 9a12c509..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/rbutil.h +++ /dev/null @@ -1,33 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2016, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File rbutil.h -* -* Modification History: -* -* Date Name Description -* 06/10/99 stephen Creation. -******************************************************************************* -*/ - -#ifndef UTIL_H -#define UTIL_H 1 - -#include "unicode/utypes.h" - -U_CDECL_BEGIN - -void get_dirname(char *dirname, const char *filename); -void get_basename(char *basename, const char *filename); -int32_t itostr(char * buffer, int32_t i, uint32_t radix, int32_t pad); - -U_CDECL_END - -#endif /* ! UTIL_H */ diff --git a/deps/node/deps/icu-small/source/tools/genrb/read.c b/deps/node/deps/icu-small/source/tools/genrb/read.c deleted file mode 100644 index c20b4510..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/read.c +++ /dev/null @@ -1,476 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2012, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File read.c -* -* Modification History: -* -* Date Name Description -* 05/26/99 stephen Creation. -* 5/10/01 Ram removed ustdio dependency -******************************************************************************* -*/ - -#include "read.h" -#include "errmsg.h" -#include "unicode/ustring.h" -#include "unicode/utf16.h" - -#define OPENBRACE 0x007B -#define CLOSEBRACE 0x007D -#define COMMA 0x002C -#define QUOTE 0x0022 -#define ESCAPE 0x005C -#define SLASH 0x002F -#define ASTERISK 0x002A -#define SPACE 0x0020 -#define COLON 0x003A -#define BADBOM 0xFFFE -#define CR 0x000D -#define LF 0x000A - -static int32_t lineCount; - -/* Protos */ -static enum ETokenType getStringToken(UCHARBUF *buf, - UChar32 initialChar, - struct UString *token, - UErrorCode *status); - -static UChar32 getNextChar (UCHARBUF *buf, UBool skipwhite, struct UString *token, UErrorCode *status); -static void seekUntilNewline (UCHARBUF *buf, struct UString *token, UErrorCode *status); -static void seekUntilEndOfComment (UCHARBUF *buf, struct UString *token, UErrorCode *status); -static UBool isWhitespace (UChar32 c); -static UBool isNewline (UChar32 c); - -U_CFUNC void resetLineNumber() { - lineCount = 1; -} - -/* Read and return the next token from the stream. If the token is of - type eString, fill in the token parameter with the token. If the - token is eError, then the status parameter will contain the - specific error. This will be eItemNotFound at the end of file, - indicating that all tokens have been returned. This method will - never return eString twice in a row; instead, multiple adjacent - string tokens will be merged into one, with no intervening - space. */ -U_CFUNC enum ETokenType -getNextToken(UCHARBUF* buf, - struct UString *token, - uint32_t *linenumber, /* out: linenumber of token */ - struct UString *comment, - UErrorCode *status) { - enum ETokenType result; - UChar32 c; - - if (U_FAILURE(*status)) { - return TOK_ERROR; - } - - /* Skip whitespace */ - c = getNextChar(buf, TRUE, comment, status); - - if (U_FAILURE(*status)) { - return TOK_ERROR; - } - - *linenumber = lineCount; - - switch(c) { - case BADBOM: - return TOK_ERROR; - case OPENBRACE: - return TOK_OPEN_BRACE; - case CLOSEBRACE: - return TOK_CLOSE_BRACE; - case COMMA: - return TOK_COMMA; - case U_EOF: - return TOK_EOF; - case COLON: - return TOK_COLON; - - default: - result = getStringToken(buf, c, token, status); - } - - *linenumber = lineCount; - return result; -} - -/* Copy a string token into the given UnicodeString. Upon entry, we - have already read the first character of the string token, which is - not a whitespace character (but may be a QUOTE or ESCAPE). This - function reads all subsequent characters that belong with this - string, and copy them into the token parameter. The other - important, and slightly convoluted purpose of this function is to - merge adjacent strings. It looks forward a bit, and if the next - non comment, non whitespace item is a string, it reads it in as - well. If two adjacent strings are quoted, they are merged without - intervening space. Otherwise a single SPACE character is - inserted. */ -static enum ETokenType getStringToken(UCHARBUF* buf, - UChar32 initialChar, - struct UString *token, - UErrorCode *status) { - UBool lastStringWasQuoted; - UChar32 c; - UChar target[3] = { '\0' }; - UChar *pTarget = target; - int len=0; - UBool isFollowingCharEscaped=FALSE; - UBool isNLUnescaped = FALSE; - UChar32 prevC=0; - - /* We are guaranteed on entry that initialChar is not a whitespace - character. If we are at the EOF, or have some other problem, it - doesn't matter; we still want to validly return the initialChar - (if nothing else) as a string token. */ - - if (U_FAILURE(*status)) { - return TOK_ERROR; - } - - /* setup */ - lastStringWasQuoted = FALSE; - c = initialChar; - ustr_setlen(token, 0, status); - - if (U_FAILURE(*status)) { - return TOK_ERROR; - } - - for (;;) { - if (c == QUOTE) { - if (!lastStringWasQuoted && token->fLength > 0) { - ustr_ucat(token, SPACE, status); - - if (U_FAILURE(*status)) { - return TOK_ERROR; - } - } - - lastStringWasQuoted = TRUE; - - for (;;) { - c = ucbuf_getc(buf,status); - - /* EOF reached */ - if (c == U_EOF) { - return TOK_EOF; - } - - /* Unterminated quoted strings */ - if (U_FAILURE(*status)) { - return TOK_ERROR; - } - - if (c == QUOTE && !isFollowingCharEscaped) { - break; - } - - if (c == ESCAPE && !isFollowingCharEscaped) { - pTarget = target; - c = unescape(buf, status); - - if (c == U_ERR) { - return TOK_ERROR; - } - if(c == CR || c == LF){ - isNLUnescaped = TRUE; - } - } - - if(c==ESCAPE && !isFollowingCharEscaped){ - isFollowingCharEscaped = TRUE; - }else{ - U_APPEND_CHAR32(c, pTarget,len); - pTarget = target; - ustr_uscat(token, pTarget,len, status); - isFollowingCharEscaped = FALSE; - len=0; - if(c == CR || c == LF){ - if(isNLUnescaped == FALSE && prevC!=CR){ - lineCount++; - } - isNLUnescaped = FALSE; - } - } - - if (U_FAILURE(*status)) { - return TOK_ERROR; - } - prevC = c; - } - } else { - if (token->fLength > 0) { - ustr_ucat(token, SPACE, status); - - if (U_FAILURE(*status)) { - return TOK_ERROR; - } - } - - if(lastStringWasQuoted){ - if(getShowWarning()){ - warning(lineCount, "Mixing quoted and unquoted strings"); - } - if(isStrict()){ - return TOK_ERROR; - } - - } - - lastStringWasQuoted = FALSE; - - /* if we reach here we are mixing - * quoted and unquoted strings - * warn in normal mode and error in - * pedantic mode - */ - - if (c == ESCAPE) { - pTarget = target; - c = unescape(buf, status); - - /* EOF reached */ - if (c == U_EOF) { - return TOK_ERROR; - } - } - - U_APPEND_CHAR32(c, pTarget,len); - pTarget = target; - ustr_uscat(token, pTarget,len, status); - len=0; - - if (U_FAILURE(*status)) { - return TOK_ERROR; - } - - for (;;) { - /* DON'T skip whitespace */ - c = getNextChar(buf, FALSE, NULL, status); - - /* EOF reached */ - if (c == U_EOF) { - ucbuf_ungetc(c, buf); - return TOK_STRING; - } - - if (U_FAILURE(*status)) { - return TOK_STRING; - } - - if (c == QUOTE - || c == OPENBRACE - || c == CLOSEBRACE - || c == COMMA - || c == COLON) { - ucbuf_ungetc(c, buf); - break; - } - - if (isWhitespace(c)) { - break; - } - - if (c == ESCAPE) { - pTarget = target; - c = unescape(buf, status); - - if (c == U_ERR) { - return TOK_ERROR; - } - } - - U_APPEND_CHAR32(c, pTarget,len); - pTarget = target; - ustr_uscat(token, pTarget,len, status); - len=0; - if (U_FAILURE(*status)) { - return TOK_ERROR; - } - } - } - - /* DO skip whitespace */ - c = getNextChar(buf, TRUE, NULL, status); - - if (U_FAILURE(*status)) { - return TOK_STRING; - } - - if (c == OPENBRACE || c == CLOSEBRACE || c == COMMA || c == COLON) { - ucbuf_ungetc(c, buf); - return TOK_STRING; - } - } -} - -/* Retrieve the next character. If skipwhite is - true, whitespace is skipped as well. */ -static UChar32 getNextChar(UCHARBUF* buf, - UBool skipwhite, - struct UString *token, - UErrorCode *status) { - UChar32 c, c2; - - if (U_FAILURE(*status)) { - return U_EOF; - } - - for (;;) { - c = ucbuf_getc(buf,status); - - if (c == U_EOF) { - return U_EOF; - } - - if (skipwhite && isWhitespace(c)) { - continue; - } - - /* This also handles the get() failing case */ - if (c != SLASH) { - return c; - } - - c = ucbuf_getc(buf,status); /* "/c" */ - - if (c == U_EOF) { - return U_EOF; - } - - switch (c) { - case SLASH: /* "//" */ - seekUntilNewline(buf, NULL, status); - break; - - case ASTERISK: /* " / * " */ - c2 = ucbuf_getc(buf, status); /* "/ * c" */ - if(c2 == ASTERISK){ /* "/ * *" */ - /* parse multi-line comment and store it in token*/ - seekUntilEndOfComment(buf, token, status); - } else { - ucbuf_ungetc(c2, buf); /* c2 is the non-asterisk following "/ *". Include c2 back in buffer. */ - seekUntilEndOfComment(buf, NULL, status); - } - break; - - default: - ucbuf_ungetc(c, buf); /* "/c" - put back the c */ - /* If get() failed this is a NOP */ - return SLASH; - } - - } -} - -static void seekUntilNewline(UCHARBUF* buf, - struct UString *token, - UErrorCode *status) { - UChar32 c; - - if (U_FAILURE(*status)) { - return; - } - - do { - c = ucbuf_getc(buf,status); - /* add the char to token */ - if(token!=NULL){ - ustr_u32cat(token, c, status); - } - } while (!isNewline(c) && c != U_EOF && *status == U_ZERO_ERROR); -} - -static void seekUntilEndOfComment(UCHARBUF *buf, - struct UString *token, - UErrorCode *status) { - UChar32 c, d; - uint32_t line; - - if (U_FAILURE(*status)) { - return; - } - - line = lineCount; - - do { - c = ucbuf_getc(buf, status); - - if (c == ASTERISK) { - d = ucbuf_getc(buf, status); - - if (d != SLASH) { - ucbuf_ungetc(d, buf); - } else { - break; - } - } - /* add the char to token */ - if(token!=NULL){ - ustr_u32cat(token, c, status); - } - /* increment the lineCount */ - isNewline(c); - - } while (c != U_EOF && *status == U_ZERO_ERROR); - - if (c == U_EOF) { - *status = U_INVALID_FORMAT_ERROR; - error(line, "unterminated comment detected"); - } -} - -U_CFUNC UChar32 unescape(UCHARBUF *buf, UErrorCode *status) { - if (U_FAILURE(*status)) { - return U_EOF; - } - - /* We expect to be called after the ESCAPE has been seen, but - * u_fgetcx needs an ESCAPE to do its magic. */ - ucbuf_ungetc(ESCAPE, buf); - - return ucbuf_getcx32(buf, status); -} - -static UBool isWhitespace(UChar32 c) { - switch (c) { - /* ' ', '\t', '\n', '\r', 0x2029, 0xFEFF */ - case 0x000A: - case 0x2029: - lineCount++; - case 0x000D: - case 0x0020: - case 0x0009: - case 0xFEFF: - return TRUE; - - default: - return FALSE; - } -} - -static UBool isNewline(UChar32 c) { - switch (c) { - /* '\n', '\r', 0x2029 */ - case 0x000A: - case 0x2029: - lineCount++; - case 0x000D: - return TRUE; - - default: - return FALSE; - } -} diff --git a/deps/node/deps/icu-small/source/tools/genrb/read.h b/deps/node/deps/icu-small/source/tools/genrb/read.h deleted file mode 100644 index e5b8d155..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/read.h +++ /dev/null @@ -1,54 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2011, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File read.h -* -* Modification History: -* -* Date Name Description -* 05/26/99 stephen Creation. -* 5/10/01 Ram removed ustdio dependency -******************************************************************************* -*/ - -#ifndef READ_H -#define READ_H 1 - -#include "unicode/utypes.h" -#include "ustr.h" -#include "ucbuf.h" - -/* The types of tokens which may be returned by getNextToken. - NOTE: Keep these in sync with tokenNames in parse.c */ -enum ETokenType -{ - TOK_STRING, /* A string token, such as "MonthNames" */ - TOK_OPEN_BRACE, /* An opening brace character */ - TOK_CLOSE_BRACE, /* A closing brace character */ - TOK_COMMA, /* A comma */ - TOK_COLON, /* A colon */ - - TOK_EOF, /* End of the file has been reached successfully */ - TOK_ERROR, /* An error, such an unterminated quoted string */ - TOK_TOKEN_COUNT /* Number of "real" token types */ -}; - -U_CFUNC UChar32 unescape(UCHARBUF *buf, UErrorCode *status); - -U_CFUNC void resetLineNumber(void); - -U_CFUNC enum ETokenType -getNextToken(UCHARBUF *buf, - struct UString *token, - uint32_t *linenumber, /* out: linenumber of token */ - struct UString *comment, - UErrorCode *status); - -#endif diff --git a/deps/node/deps/icu-small/source/tools/genrb/reslist.cpp b/deps/node/deps/icu-small/source/tools/genrb/reslist.cpp deleted file mode 100644 index 0493347e..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/reslist.cpp +++ /dev/null @@ -1,1693 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2000-2015, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File reslist.cpp -* -* Modification History: -* -* Date Name Description -* 02/21/00 weiv Creation. -******************************************************************************* -*/ - -// Safer use of UnicodeString. -#ifndef UNISTR_FROM_CHAR_EXPLICIT -# define UNISTR_FROM_CHAR_EXPLICIT explicit -#endif - -// Less important, but still a good idea. -#ifndef UNISTR_FROM_STRING_EXPLICIT -# define UNISTR_FROM_STRING_EXPLICIT explicit -#endif - -#include <assert.h> -#include <stdio.h> -#include "unicode/localpointer.h" -#include "reslist.h" -#include "unewdata.h" -#include "unicode/ures.h" -#include "unicode/putil.h" -#include "errmsg.h" - -#include "uarrsort.h" -#include "uelement.h" -#include "uhash.h" -#include "uinvchar.h" -#include "ustr_imp.h" -#include "unicode/utf16.h" -/* - * Align binary data at a 16-byte offset from the start of the resource bundle, - * to be safe for any data type it may contain. - */ -#define BIN_ALIGNMENT 16 - -// This numeric constant must be at least 1. -// If StringResource.fNumUnitsSaved == 0 then the string occurs only once, -// and it makes no sense to move it to the pool bundle. -// The larger the threshold for fNumUnitsSaved -// the smaller the savings, and the smaller the pool bundle. -// We trade some total size reduction to reduce the pool bundle a bit, -// so that one can reasonably save data size by -// removing bundle files without rebuilding the pool bundle. -// This can also help to keep the pool and total (pool+local) string indexes -// within 16 bits, that is, within range of Table16 and Array16 containers. -#ifndef GENRB_MIN_16BIT_UNITS_SAVED_FOR_POOL_STRING -# define GENRB_MIN_16BIT_UNITS_SAVED_FOR_POOL_STRING 10 -#endif - -U_NAMESPACE_USE - -static UBool gIncludeCopyright = FALSE; -static UBool gUsePoolBundle = FALSE; -static UBool gIsDefaultFormatVersion = TRUE; -static int32_t gFormatVersion = 3; - -/* How do we store string values? */ -enum { - STRINGS_UTF16_V1, /* formatVersion 1: int length + UChars + NUL + padding to 4 bytes */ - STRINGS_UTF16_V2 /* formatVersion 2 & up: optional length in 1..3 UChars + UChars + NUL */ -}; - -static const int32_t MAX_IMPLICIT_STRING_LENGTH = 40; /* do not store the length explicitly for such strings */ - -static const ResFile kNoPoolBundle; - -/* - * res_none() returns the address of kNoResource, - * for use in non-error cases when no resource is to be added to the bundle. - * (NULL is used in error cases.) - */ -static SResource kNoResource; // TODO: const - -static UDataInfo dataInfo= { - sizeof(UDataInfo), - 0, - - U_IS_BIG_ENDIAN, - U_CHARSET_FAMILY, - sizeof(UChar), - 0, - - {0x52, 0x65, 0x73, 0x42}, /* dataFormat="ResB" */ - {1, 3, 0, 0}, /* formatVersion */ - {1, 4, 0, 0} /* dataVersion take a look at version inside parsed resb*/ -}; - -static const UVersionInfo gFormatVersions[4] = { /* indexed by a major-formatVersion integer */ - { 0, 0, 0, 0 }, - { 1, 3, 0, 0 }, - { 2, 0, 0, 0 }, - { 3, 0, 0, 0 } -}; -// Remember to update genrb.h GENRB_VERSION when changing the data format. -// (Or maybe we should remove GENRB_VERSION and report the ICU version number?) - -static uint8_t calcPadding(uint32_t size) { - /* returns space we need to pad */ - return (uint8_t) ((size % sizeof(uint32_t)) ? (sizeof(uint32_t) - (size % sizeof(uint32_t))) : 0); - -} - -void setIncludeCopyright(UBool val){ - gIncludeCopyright=val; -} - -UBool getIncludeCopyright(void){ - return gIncludeCopyright; -} - -void setFormatVersion(int32_t formatVersion) { - gIsDefaultFormatVersion = FALSE; - gFormatVersion = formatVersion; -} - -int32_t getFormatVersion() { - return gFormatVersion; -} - -void setUsePoolBundle(UBool use) { - gUsePoolBundle = use; -} - -// TODO: return const pointer, or find another way to express "none" -struct SResource* res_none() { - return &kNoResource; -} - -SResource::SResource() - : fType(URES_NONE), fWritten(FALSE), fRes(RES_BOGUS), fRes16(-1), fKey(-1), fKey16(-1), - line(0), fNext(NULL) { - ustr_init(&fComment); -} - -SResource::SResource(SRBRoot *bundle, const char *tag, int8_t type, const UString* comment, - UErrorCode &errorCode) - : fType(type), fWritten(FALSE), fRes(RES_BOGUS), fRes16(-1), - fKey(bundle != NULL ? bundle->addTag(tag, errorCode) : -1), fKey16(-1), - line(0), fNext(NULL) { - ustr_init(&fComment); - if(comment != NULL) { - ustr_cpy(&fComment, comment, &errorCode); - } -} - -SResource::~SResource() { - ustr_deinit(&fComment); -} - -ContainerResource::~ContainerResource() { - SResource *current = fFirst; - while (current != NULL) { - SResource *next = current->fNext; - delete current; - current = next; - } -} - -TableResource::~TableResource() {} - -// TODO: clarify that containers adopt new items, even in error cases; use LocalPointer -void TableResource::add(SResource *res, int linenumber, UErrorCode &errorCode) { - if (U_FAILURE(errorCode) || res == NULL || res == &kNoResource) { - return; - } - - /* remember this linenumber to report to the user if there is a duplicate key */ - res->line = linenumber; - - /* here we need to traverse the list */ - ++fCount; - - /* is the list still empty? */ - if (fFirst == NULL) { - fFirst = res; - res->fNext = NULL; - return; - } - - const char *resKeyString = fRoot->fKeys + res->fKey; - - SResource *current = fFirst; - - SResource *prev = NULL; - while (current != NULL) { - const char *currentKeyString = fRoot->fKeys + current->fKey; - int diff; - /* - * formatVersion 1: compare key strings in native-charset order - * formatVersion 2 and up: compare key strings in ASCII order - */ - if (gFormatVersion == 1 || U_CHARSET_FAMILY == U_ASCII_FAMILY) { - diff = uprv_strcmp(currentKeyString, resKeyString); - } else { - diff = uprv_compareInvCharsAsAscii(currentKeyString, resKeyString); - } - if (diff < 0) { - prev = current; - current = current->fNext; - } else if (diff > 0) { - /* we're either in front of the list, or in the middle */ - if (prev == NULL) { - /* front of the list */ - fFirst = res; - } else { - /* middle of the list */ - prev->fNext = res; - } - - res->fNext = current; - return; - } else { - /* Key already exists! ERROR! */ - error(linenumber, "duplicate key '%s' in table, first appeared at line %d", currentKeyString, current->line); - errorCode = U_UNSUPPORTED_ERROR; - return; - } - } - - /* end of list */ - prev->fNext = res; - res->fNext = NULL; -} - -ArrayResource::~ArrayResource() {} - -void ArrayResource::add(SResource *res) { - if (res != NULL && res != &kNoResource) { - if (fFirst == NULL) { - fFirst = res; - } else { - fLast->fNext = res; - } - fLast = res; - ++fCount; - } -} - -PseudoListResource::~PseudoListResource() {} - -void PseudoListResource::add(SResource *res) { - if (res != NULL && res != &kNoResource) { - res->fNext = fFirst; - fFirst = res; - ++fCount; - } -} - -StringBaseResource::StringBaseResource(SRBRoot *bundle, const char *tag, int8_t type, - const UChar *value, int32_t len, - const UString* comment, UErrorCode &errorCode) - : SResource(bundle, tag, type, comment, errorCode) { - if (len == 0 && gFormatVersion > 1) { - fRes = URES_MAKE_EMPTY_RESOURCE(type); - fWritten = TRUE; - return; - } - - fString.setTo(ConstChar16Ptr(value), len); - fString.getTerminatedBuffer(); // Some code relies on NUL-termination. - if (U_SUCCESS(errorCode) && fString.isBogus()) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - } -} - -StringBaseResource::StringBaseResource(SRBRoot *bundle, int8_t type, - const icu::UnicodeString &value, UErrorCode &errorCode) - : SResource(bundle, NULL, type, NULL, errorCode), fString(value) { - if (value.isEmpty() && gFormatVersion > 1) { - fRes = URES_MAKE_EMPTY_RESOURCE(type); - fWritten = TRUE; - return; - } - - fString.getTerminatedBuffer(); // Some code relies on NUL-termination. - if (U_SUCCESS(errorCode) && fString.isBogus()) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - } -} - -// Pool bundle string, alias the buffer. Guaranteed NUL-terminated and not empty. -StringBaseResource::StringBaseResource(int8_t type, const UChar *value, int32_t len, - UErrorCode &errorCode) - : SResource(NULL, NULL, type, NULL, errorCode), fString(TRUE, value, len) { - assert(len > 0); - assert(!fString.isBogus()); -} - -StringBaseResource::~StringBaseResource() {} - -static int32_t U_CALLCONV -string_hash(const UElement key) { - const StringResource *res = static_cast<const StringResource *>(key.pointer); - return res->fString.hashCode(); -} - -static UBool U_CALLCONV -string_comp(const UElement key1, const UElement key2) { - const StringResource *res1 = static_cast<const StringResource *>(key1.pointer); - const StringResource *res2 = static_cast<const StringResource *>(key2.pointer); - return res1->fString == res2->fString; -} - -StringResource::~StringResource() {} - -AliasResource::~AliasResource() {} - -IntResource::IntResource(SRBRoot *bundle, const char *tag, int32_t value, - const UString* comment, UErrorCode &errorCode) - : SResource(bundle, tag, URES_INT, comment, errorCode) { - fValue = value; - fRes = URES_MAKE_RESOURCE(URES_INT, value & RES_MAX_OFFSET); - fWritten = TRUE; -} - -IntResource::~IntResource() {} - -IntVectorResource::IntVectorResource(SRBRoot *bundle, const char *tag, - const UString* comment, UErrorCode &errorCode) - : SResource(bundle, tag, URES_INT_VECTOR, comment, errorCode), - fCount(0), fArray(new uint32_t[RESLIST_MAX_INT_VECTOR]) { - if (fArray == NULL) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - return; - } -} - -IntVectorResource::~IntVectorResource() { - delete[] fArray; -} - -void IntVectorResource::add(int32_t value, UErrorCode &errorCode) { - if (U_SUCCESS(errorCode)) { - fArray[fCount++] = value; - } -} - -BinaryResource::BinaryResource(SRBRoot *bundle, const char *tag, - uint32_t length, uint8_t *data, const char* fileName, - const UString* comment, UErrorCode &errorCode) - : SResource(bundle, tag, URES_BINARY, comment, errorCode), - fLength(length), fData(NULL), fFileName(NULL) { - if (U_FAILURE(errorCode)) { - return; - } - if (fileName != NULL && *fileName != 0){ - fFileName = new char[uprv_strlen(fileName)+1]; - if (fFileName == NULL) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - return; - } - uprv_strcpy(fFileName, fileName); - } - if (length > 0) { - fData = new uint8_t[length]; - if (fData == NULL) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - return; - } - uprv_memcpy(fData, data, length); - } else { - if (gFormatVersion > 1) { - fRes = URES_MAKE_EMPTY_RESOURCE(URES_BINARY); - fWritten = TRUE; - } - } -} - -BinaryResource::~BinaryResource() { - delete[] fData; - delete[] fFileName; -} - -/* Writing Functions */ - -void -StringResource::handlePreflightStrings(SRBRoot *bundle, UHashtable *stringSet, - UErrorCode &errorCode) { - assert(fSame == NULL); - fSame = static_cast<StringResource *>(uhash_get(stringSet, this)); - if (fSame != NULL) { - // This is a duplicate of a pool bundle string or of an earlier-visited string. - if (++fSame->fNumCopies == 1) { - assert(fSame->fWritten); - int32_t poolStringIndex = (int32_t)RES_GET_OFFSET(fSame->fRes); - if (poolStringIndex >= bundle->fPoolStringIndexLimit) { - bundle->fPoolStringIndexLimit = poolStringIndex + 1; - } - } - return; - } - /* Put this string into the set for finding duplicates. */ - fNumCopies = 1; - uhash_put(stringSet, this, this, &errorCode); - - if (bundle->fStringsForm != STRINGS_UTF16_V1) { - int32_t len = length(); - if (len <= MAX_IMPLICIT_STRING_LENGTH && - !U16_IS_TRAIL(fString[0]) && fString.indexOf((UChar)0) < 0) { - /* - * This string will be stored without an explicit length. - * Runtime will detect !U16_IS_TRAIL(s[0]) and call u_strlen(). - */ - fNumCharsForLength = 0; - } else if (len <= 0x3ee) { - fNumCharsForLength = 1; - } else if (len <= 0xfffff) { - fNumCharsForLength = 2; - } else { - fNumCharsForLength = 3; - } - bundle->f16BitStringsLength += fNumCharsForLength + len + 1; /* +1 for the NUL */ - } -} - -void -ContainerResource::handlePreflightStrings(SRBRoot *bundle, UHashtable *stringSet, - UErrorCode &errorCode) { - for (SResource *current = fFirst; current != NULL; current = current->fNext) { - current->preflightStrings(bundle, stringSet, errorCode); - } -} - -void -SResource::preflightStrings(SRBRoot *bundle, UHashtable *stringSet, UErrorCode &errorCode) { - if (U_FAILURE(errorCode)) { - return; - } - if (fRes != RES_BOGUS) { - /* - * The resource item word was already precomputed, which means - * no further data needs to be written. - * This might be an integer, or an empty string/binary/etc. - */ - return; - } - handlePreflightStrings(bundle, stringSet, errorCode); -} - -void -SResource::handlePreflightStrings(SRBRoot * /*bundle*/, UHashtable * /*stringSet*/, - UErrorCode & /*errorCode*/) { - /* Neither a string nor a container. */ -} - -int32_t -SRBRoot::makeRes16(uint32_t resWord) const { - if (resWord == 0) { - return 0; /* empty string */ - } - uint32_t type = RES_GET_TYPE(resWord); - int32_t offset = (int32_t)RES_GET_OFFSET(resWord); - if (type == URES_STRING_V2) { - assert(offset > 0); - if (offset < fPoolStringIndexLimit) { - if (offset < fPoolStringIndex16Limit) { - return offset; - } - } else { - offset = offset - fPoolStringIndexLimit + fPoolStringIndex16Limit; - if (offset <= 0xffff) { - return offset; - } - } - } - return -1; -} - -int32_t -SRBRoot::mapKey(int32_t oldpos) const { - const KeyMapEntry *map = fKeyMap; - if (map == NULL) { - return oldpos; - } - int32_t i, start, limit; - - /* do a binary search for the old, pre-compactKeys() key offset */ - start = fUsePoolBundle->fKeysCount; - limit = start + fKeysCount; - while (start < limit - 1) { - i = (start + limit) / 2; - if (oldpos < map[i].oldpos) { - limit = i; - } else { - start = i; - } - } - assert(oldpos == map[start].oldpos); - return map[start].newpos; -} - -/* - * Only called for UTF-16 v1 strings and duplicate UTF-16 v2 strings. - * For unique UTF-16 v2 strings, write16() sees fRes != RES_BOGUS - * and exits early. - */ -void -StringResource::handleWrite16(SRBRoot * /*bundle*/) { - SResource *same; - if ((same = fSame) != NULL) { - /* This is a duplicate. */ - assert(same->fRes != RES_BOGUS && same->fWritten); - fRes = same->fRes; - fWritten = same->fWritten; - } -} - -void -ContainerResource::writeAllRes16(SRBRoot *bundle) { - for (SResource *current = fFirst; current != NULL; current = current->fNext) { - bundle->f16BitUnits.append((UChar)current->fRes16); - } - fWritten = TRUE; -} - -void -ArrayResource::handleWrite16(SRBRoot *bundle) { - if (fCount == 0 && gFormatVersion > 1) { - fRes = URES_MAKE_EMPTY_RESOURCE(URES_ARRAY); - fWritten = TRUE; - return; - } - - int32_t res16 = 0; - for (SResource *current = fFirst; current != NULL; current = current->fNext) { - current->write16(bundle); - res16 |= current->fRes16; - } - if (fCount <= 0xffff && res16 >= 0 && gFormatVersion > 1) { - fRes = URES_MAKE_RESOURCE(URES_ARRAY16, bundle->f16BitUnits.length()); - bundle->f16BitUnits.append((UChar)fCount); - writeAllRes16(bundle); - } -} - -void -TableResource::handleWrite16(SRBRoot *bundle) { - if (fCount == 0 && gFormatVersion > 1) { - fRes = URES_MAKE_EMPTY_RESOURCE(URES_TABLE); - fWritten = TRUE; - return; - } - /* Find the smallest table type that fits the data. */ - int32_t key16 = 0; - int32_t res16 = 0; - for (SResource *current = fFirst; current != NULL; current = current->fNext) { - current->write16(bundle); - key16 |= current->fKey16; - res16 |= current->fRes16; - } - if(fCount > (uint32_t)bundle->fMaxTableLength) { - bundle->fMaxTableLength = fCount; - } - if (fCount <= 0xffff && key16 >= 0) { - if (res16 >= 0 && gFormatVersion > 1) { - /* 16-bit count, key offsets and values */ - fRes = URES_MAKE_RESOURCE(URES_TABLE16, bundle->f16BitUnits.length()); - bundle->f16BitUnits.append((UChar)fCount); - for (SResource *current = fFirst; current != NULL; current = current->fNext) { - bundle->f16BitUnits.append((UChar)current->fKey16); - } - writeAllRes16(bundle); - } else { - /* 16-bit count, 16-bit key offsets, 32-bit values */ - fTableType = URES_TABLE; - } - } else { - /* 32-bit count, key offsets and values */ - fTableType = URES_TABLE32; - } -} - -void -PseudoListResource::handleWrite16(SRBRoot * /*bundle*/) { - fRes = URES_MAKE_EMPTY_RESOURCE(URES_TABLE); - fWritten = TRUE; -} - -void -SResource::write16(SRBRoot *bundle) { - if (fKey >= 0) { - // A tagged resource has a non-negative key index into the parsed key strings. - // compactKeys() built a map from parsed key index to the final key index. - // After the mapping, negative key indexes are used for shared pool bundle keys. - fKey = bundle->mapKey(fKey); - // If the key index fits into a Key16 for a Table or Table16, - // then set the fKey16 field accordingly. - // Otherwise keep it at -1. - if (fKey >= 0) { - if (fKey < bundle->fLocalKeyLimit) { - fKey16 = fKey; - } - } else { - int32_t poolKeyIndex = fKey & 0x7fffffff; - if (poolKeyIndex <= 0xffff) { - poolKeyIndex += bundle->fLocalKeyLimit; - if (poolKeyIndex <= 0xffff) { - fKey16 = poolKeyIndex; - } - } - } - } - /* - * fRes != RES_BOGUS: - * The resource item word was already precomputed, which means - * no further data needs to be written. - * This might be an integer, or an empty or UTF-16 v2 string, - * an empty binary, etc. - */ - if (fRes == RES_BOGUS) { - handleWrite16(bundle); - } - // Compute fRes16 for precomputed as well as just-computed fRes. - fRes16 = bundle->makeRes16(fRes); -} - -void -SResource::handleWrite16(SRBRoot * /*bundle*/) { - /* Only a few resource types write 16-bit units. */ -} - -/* - * Only called for UTF-16 v1 strings, and for aliases. - * For UTF-16 v2 strings, preWrite() sees fRes != RES_BOGUS - * and exits early. - */ -void -StringBaseResource::handlePreWrite(uint32_t *byteOffset) { - /* Write the UTF-16 v1 string. */ - fRes = URES_MAKE_RESOURCE(fType, *byteOffset >> 2); - *byteOffset += 4 + (length() + 1) * U_SIZEOF_UCHAR; -} - -void -IntVectorResource::handlePreWrite(uint32_t *byteOffset) { - if (fCount == 0 && gFormatVersion > 1) { - fRes = URES_MAKE_EMPTY_RESOURCE(URES_INT_VECTOR); - fWritten = TRUE; - } else { - fRes = URES_MAKE_RESOURCE(URES_INT_VECTOR, *byteOffset >> 2); - *byteOffset += (1 + fCount) * 4; - } -} - -void -BinaryResource::handlePreWrite(uint32_t *byteOffset) { - uint32_t pad = 0; - uint32_t dataStart = *byteOffset + sizeof(fLength); - - if (dataStart % BIN_ALIGNMENT) { - pad = (BIN_ALIGNMENT - dataStart % BIN_ALIGNMENT); - *byteOffset += pad; /* pad == 4 or 8 or 12 */ - } - fRes = URES_MAKE_RESOURCE(URES_BINARY, *byteOffset >> 2); - *byteOffset += 4 + fLength; -} - -void -ContainerResource::preWriteAllRes(uint32_t *byteOffset) { - for (SResource *current = fFirst; current != NULL; current = current->fNext) { - current->preWrite(byteOffset); - } -} - -void -ArrayResource::handlePreWrite(uint32_t *byteOffset) { - preWriteAllRes(byteOffset); - fRes = URES_MAKE_RESOURCE(URES_ARRAY, *byteOffset >> 2); - *byteOffset += (1 + fCount) * 4; -} - -void -TableResource::handlePreWrite(uint32_t *byteOffset) { - preWriteAllRes(byteOffset); - if (fTableType == URES_TABLE) { - /* 16-bit count, 16-bit key offsets, 32-bit values */ - fRes = URES_MAKE_RESOURCE(URES_TABLE, *byteOffset >> 2); - *byteOffset += 2 + fCount * 6; - } else { - /* 32-bit count, key offsets and values */ - fRes = URES_MAKE_RESOURCE(URES_TABLE32, *byteOffset >> 2); - *byteOffset += 4 + fCount * 8; - } -} - -void -SResource::preWrite(uint32_t *byteOffset) { - if (fRes != RES_BOGUS) { - /* - * The resource item word was already precomputed, which means - * no further data needs to be written. - * This might be an integer, or an empty or UTF-16 v2 string, - * an empty binary, etc. - */ - return; - } - handlePreWrite(byteOffset); - *byteOffset += calcPadding(*byteOffset); -} - -void -SResource::handlePreWrite(uint32_t * /*byteOffset*/) { - assert(FALSE); -} - -/* - * Only called for UTF-16 v1 strings, and for aliases. For UTF-16 v2 strings, - * write() sees fWritten and exits early. - */ -void -StringBaseResource::handleWrite(UNewDataMemory *mem, uint32_t *byteOffset) { - /* Write the UTF-16 v1 string. */ - int32_t len = length(); - udata_write32(mem, len); - udata_writeUString(mem, getBuffer(), len + 1); - *byteOffset += 4 + (len + 1) * U_SIZEOF_UCHAR; - fWritten = TRUE; -} - -void -ContainerResource::writeAllRes(UNewDataMemory *mem, uint32_t *byteOffset) { - uint32_t i = 0; - for (SResource *current = fFirst; current != NULL; ++i, current = current->fNext) { - current->write(mem, byteOffset); - } - assert(i == fCount); -} - -void -ContainerResource::writeAllRes32(UNewDataMemory *mem, uint32_t *byteOffset) { - for (SResource *current = fFirst; current != NULL; current = current->fNext) { - udata_write32(mem, current->fRes); - } - *byteOffset += fCount * 4; -} - -void -ArrayResource::handleWrite(UNewDataMemory *mem, uint32_t *byteOffset) { - writeAllRes(mem, byteOffset); - udata_write32(mem, fCount); - *byteOffset += 4; - writeAllRes32(mem, byteOffset); -} - -void -IntVectorResource::handleWrite(UNewDataMemory *mem, uint32_t *byteOffset) { - udata_write32(mem, fCount); - for(uint32_t i = 0; i < fCount; ++i) { - udata_write32(mem, fArray[i]); - } - *byteOffset += (1 + fCount) * 4; -} - -void -BinaryResource::handleWrite(UNewDataMemory *mem, uint32_t *byteOffset) { - uint32_t pad = 0; - uint32_t dataStart = *byteOffset + sizeof(fLength); - - if (dataStart % BIN_ALIGNMENT) { - pad = (BIN_ALIGNMENT - dataStart % BIN_ALIGNMENT); - udata_writePadding(mem, pad); /* pad == 4 or 8 or 12 */ - *byteOffset += pad; - } - - udata_write32(mem, fLength); - if (fLength > 0) { - udata_writeBlock(mem, fData, fLength); - } - *byteOffset += 4 + fLength; -} - -void -TableResource::handleWrite(UNewDataMemory *mem, uint32_t *byteOffset) { - writeAllRes(mem, byteOffset); - if(fTableType == URES_TABLE) { - udata_write16(mem, (uint16_t)fCount); - for (SResource *current = fFirst; current != NULL; current = current->fNext) { - udata_write16(mem, current->fKey16); - } - *byteOffset += (1 + fCount)* 2; - if ((fCount & 1) == 0) { - /* 16-bit count and even number of 16-bit key offsets need padding before 32-bit resource items */ - udata_writePadding(mem, 2); - *byteOffset += 2; - } - } else /* URES_TABLE32 */ { - udata_write32(mem, fCount); - for (SResource *current = fFirst; current != NULL; current = current->fNext) { - udata_write32(mem, (uint32_t)current->fKey); - } - *byteOffset += (1 + fCount)* 4; - } - writeAllRes32(mem, byteOffset); -} - -void -SResource::write(UNewDataMemory *mem, uint32_t *byteOffset) { - if (fWritten) { - assert(fRes != RES_BOGUS); - return; - } - handleWrite(mem, byteOffset); - uint8_t paddingSize = calcPadding(*byteOffset); - if (paddingSize > 0) { - udata_writePadding(mem, paddingSize); - *byteOffset += paddingSize; - } - fWritten = TRUE; -} - -void -SResource::handleWrite(UNewDataMemory * /*mem*/, uint32_t * /*byteOffset*/) { - assert(FALSE); -} - -void SRBRoot::write(const char *outputDir, const char *outputPkg, - char *writtenFilename, int writtenFilenameLen, - UErrorCode &errorCode) { - UNewDataMemory *mem = NULL; - uint32_t byteOffset = 0; - uint32_t top, size; - char dataName[1024]; - int32_t indexes[URES_INDEX_TOP]; - - compactKeys(errorCode); - /* - * Add padding bytes to fKeys so that fKeysTop is 4-aligned. - * Safe because the capacity is a multiple of 4. - */ - while (fKeysTop & 3) { - fKeys[fKeysTop++] = (char)0xaa; - } - /* - * In URES_TABLE, use all local key offsets that fit into 16 bits, - * and use the remaining 16-bit offsets for pool key offsets - * if there are any. - * If there are no local keys, then use the whole 16-bit space - * for pool key offsets. - * Note: This cannot be changed without changing the major formatVersion. - */ - if (fKeysBottom < fKeysTop) { - if (fKeysTop <= 0x10000) { - fLocalKeyLimit = fKeysTop; - } else { - fLocalKeyLimit = 0x10000; - } - } else { - fLocalKeyLimit = 0; - } - - UHashtable *stringSet; - if (gFormatVersion > 1) { - stringSet = uhash_open(string_hash, string_comp, string_comp, &errorCode); - if (U_SUCCESS(errorCode) && - fUsePoolBundle != NULL && fUsePoolBundle->fStrings != NULL) { - for (SResource *current = fUsePoolBundle->fStrings->fFirst; - current != NULL; - current = current->fNext) { - StringResource *sr = static_cast<StringResource *>(current); - sr->fNumCopies = 0; - sr->fNumUnitsSaved = 0; - uhash_put(stringSet, sr, sr, &errorCode); - } - } - fRoot->preflightStrings(this, stringSet, errorCode); - } else { - stringSet = NULL; - } - if (fStringsForm == STRINGS_UTF16_V2 && f16BitStringsLength > 0) { - compactStringsV2(stringSet, errorCode); - } - uhash_close(stringSet); - if (U_FAILURE(errorCode)) { - return; - } - - int32_t formatVersion = gFormatVersion; - if (fPoolStringIndexLimit != 0) { - int32_t sum = fPoolStringIndexLimit + fLocalStringIndexLimit; - if ((sum - 1) > RES_MAX_OFFSET) { - errorCode = U_BUFFER_OVERFLOW_ERROR; - return; - } - if (fPoolStringIndexLimit < 0x10000 && sum <= 0x10000) { - // 16-bit indexes work for all pool + local strings. - fPoolStringIndex16Limit = fPoolStringIndexLimit; - } else { - // Set the pool index threshold so that 16-bit indexes work - // for some pool strings and some local strings. - fPoolStringIndex16Limit = (int32_t)( - ((int64_t)fPoolStringIndexLimit * 0xffff) / sum); - } - } else if (gIsDefaultFormatVersion && formatVersion == 3 && !fIsPoolBundle) { - // If we just default to formatVersion 3 - // but there are no pool bundle strings to share - // and we do not write a pool bundle, - // then write formatVersion 2 which is just as good. - formatVersion = 2; - } - - fRoot->write16(this); - if (f16BitUnits.isBogus()) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - return; - } - if (f16BitUnits.length() & 1) { - f16BitUnits.append((UChar)0xaaaa); /* pad to multiple of 4 bytes */ - } - /* all keys have been mapped */ - uprv_free(fKeyMap); - fKeyMap = NULL; - - byteOffset = fKeysTop + f16BitUnits.length() * 2; - fRoot->preWrite(&byteOffset); - - /* total size including the root item */ - top = byteOffset; - - if (writtenFilename && writtenFilenameLen) { - *writtenFilename = 0; - } - - if (writtenFilename) { - int32_t off = 0, len = 0; - if (outputDir) { - len = (int32_t)uprv_strlen(outputDir); - if (len > writtenFilenameLen) { - len = writtenFilenameLen; - } - uprv_strncpy(writtenFilename, outputDir, len); - } - if (writtenFilenameLen -= len) { - off += len; - writtenFilename[off] = U_FILE_SEP_CHAR; - if (--writtenFilenameLen) { - ++off; - if(outputPkg != NULL) - { - uprv_strcpy(writtenFilename+off, outputPkg); - off += (int32_t)uprv_strlen(outputPkg); - writtenFilename[off] = '_'; - ++off; - } - - len = (int32_t)uprv_strlen(fLocale); - if (len > writtenFilenameLen) { - len = writtenFilenameLen; - } - uprv_strncpy(writtenFilename + off, fLocale, len); - if (writtenFilenameLen -= len) { - off += len; - len = 5; - if (len > writtenFilenameLen) { - len = writtenFilenameLen; - } - uprv_strncpy(writtenFilename + off, ".res", len); - } - } - } - } - - if(outputPkg) - { - uprv_strcpy(dataName, outputPkg); - uprv_strcat(dataName, "_"); - uprv_strcat(dataName, fLocale); - } - else - { - uprv_strcpy(dataName, fLocale); - } - - uprv_memcpy(dataInfo.formatVersion, gFormatVersions + formatVersion, sizeof(UVersionInfo)); - - mem = udata_create(outputDir, "res", dataName, - &dataInfo, (gIncludeCopyright==TRUE)? U_COPYRIGHT_STRING:NULL, &errorCode); - if(U_FAILURE(errorCode)){ - return; - } - - /* write the root item */ - udata_write32(mem, fRoot->fRes); - - /* - * formatVersion 1.1 (ICU 2.8): - * write int32_t indexes[] after root and before the key strings - * to make it easier to parse resource bundles in icuswap or from Java etc. - */ - uprv_memset(indexes, 0, sizeof(indexes)); - indexes[URES_INDEX_LENGTH]= fIndexLength; - indexes[URES_INDEX_KEYS_TOP]= fKeysTop>>2; - indexes[URES_INDEX_RESOURCES_TOP]= (int32_t)(top>>2); - indexes[URES_INDEX_BUNDLE_TOP]= indexes[URES_INDEX_RESOURCES_TOP]; - indexes[URES_INDEX_MAX_TABLE_LENGTH]= fMaxTableLength; - - /* - * formatVersion 1.2 (ICU 3.6): - * write indexes[URES_INDEX_ATTRIBUTES] with URES_ATT_NO_FALLBACK set or not set - * the memset() above initialized all indexes[] to 0 - */ - if (fNoFallback) { - indexes[URES_INDEX_ATTRIBUTES]=URES_ATT_NO_FALLBACK; - } - /* - * formatVersion 2.0 (ICU 4.4): - * more compact string value storage, optional pool bundle - */ - if (URES_INDEX_16BIT_TOP < fIndexLength) { - indexes[URES_INDEX_16BIT_TOP] = (fKeysTop>>2) + (f16BitUnits.length()>>1); - } - if (URES_INDEX_POOL_CHECKSUM < fIndexLength) { - if (fIsPoolBundle) { - indexes[URES_INDEX_ATTRIBUTES] |= URES_ATT_IS_POOL_BUNDLE | URES_ATT_NO_FALLBACK; - uint32_t checksum = computeCRC((const char *)(fKeys + fKeysBottom), - (uint32_t)(fKeysTop - fKeysBottom), 0); - if (f16BitUnits.length() <= 1) { - // no pool strings to checksum - } else if (U_IS_BIG_ENDIAN) { - checksum = computeCRC(reinterpret_cast<const char *>(f16BitUnits.getBuffer()), - (uint32_t)f16BitUnits.length() * 2, checksum); - } else { - // Swap to big-endian so we get the same checksum on all platforms - // (except for charset family, due to the key strings). - UnicodeString s(f16BitUnits); - s.append((UChar)1); // Ensure that we own this buffer. - assert(!s.isBogus()); - uint16_t *p = const_cast<uint16_t *>(reinterpret_cast<const uint16_t *>(s.getBuffer())); - for (int32_t count = f16BitUnits.length(); count > 0; --count) { - uint16_t x = *p; - *p++ = (uint16_t)((x << 8) | (x >> 8)); - } - checksum = computeCRC((const char *)p, - (uint32_t)f16BitUnits.length() * 2, checksum); - } - indexes[URES_INDEX_POOL_CHECKSUM] = (int32_t)checksum; - } else if (gUsePoolBundle) { - indexes[URES_INDEX_ATTRIBUTES] |= URES_ATT_USES_POOL_BUNDLE; - indexes[URES_INDEX_POOL_CHECKSUM] = fUsePoolBundle->fChecksum; - } - } - // formatVersion 3 (ICU 56): - // share string values via pool bundle strings - indexes[URES_INDEX_LENGTH] |= fPoolStringIndexLimit << 8; // bits 23..0 -> 31..8 - indexes[URES_INDEX_ATTRIBUTES] |= (fPoolStringIndexLimit >> 12) & 0xf000; // bits 27..24 -> 15..12 - indexes[URES_INDEX_ATTRIBUTES] |= fPoolStringIndex16Limit << 16; - - /* write the indexes[] */ - udata_writeBlock(mem, indexes, fIndexLength*4); - - /* write the table key strings */ - udata_writeBlock(mem, fKeys+fKeysBottom, - fKeysTop-fKeysBottom); - - /* write the v2 UTF-16 strings, URES_TABLE16 and URES_ARRAY16 */ - udata_writeBlock(mem, f16BitUnits.getBuffer(), f16BitUnits.length()*2); - - /* write all of the bundle contents: the root item and its children */ - byteOffset = fKeysTop + f16BitUnits.length() * 2; - fRoot->write(mem, &byteOffset); - assert(byteOffset == top); - - size = udata_finish(mem, &errorCode); - if(top != size) { - fprintf(stderr, "genrb error: wrote %u bytes but counted %u\n", - (int)size, (int)top); - errorCode = U_INTERNAL_PROGRAM_ERROR; - } -} - -/* Opening Functions */ - -TableResource* table_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status) { - LocalPointer<TableResource> res(new TableResource(bundle, tag, comment, *status), *status); - return U_SUCCESS(*status) ? res.orphan() : NULL; -} - -ArrayResource* array_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status) { - LocalPointer<ArrayResource> res(new ArrayResource(bundle, tag, comment, *status), *status); - return U_SUCCESS(*status) ? res.orphan() : NULL; -} - -struct SResource *string_open(struct SRBRoot *bundle, const char *tag, const UChar *value, int32_t len, const struct UString* comment, UErrorCode *status) { - LocalPointer<SResource> res( - new StringResource(bundle, tag, value, len, comment, *status), *status); - return U_SUCCESS(*status) ? res.orphan() : NULL; -} - -struct SResource *alias_open(struct SRBRoot *bundle, const char *tag, UChar *value, int32_t len, const struct UString* comment, UErrorCode *status) { - LocalPointer<SResource> res( - new AliasResource(bundle, tag, value, len, comment, *status), *status); - return U_SUCCESS(*status) ? res.orphan() : NULL; -} - -IntVectorResource *intvector_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status) { - LocalPointer<IntVectorResource> res( - new IntVectorResource(bundle, tag, comment, *status), *status); - return U_SUCCESS(*status) ? res.orphan() : NULL; -} - -struct SResource *int_open(struct SRBRoot *bundle, const char *tag, int32_t value, const struct UString* comment, UErrorCode *status) { - LocalPointer<SResource> res(new IntResource(bundle, tag, value, comment, *status), *status); - return U_SUCCESS(*status) ? res.orphan() : NULL; -} - -struct SResource *bin_open(struct SRBRoot *bundle, const char *tag, uint32_t length, uint8_t *data, const char* fileName, const struct UString* comment, UErrorCode *status) { - LocalPointer<SResource> res( - new BinaryResource(bundle, tag, length, data, fileName, comment, *status), *status); - return U_SUCCESS(*status) ? res.orphan() : NULL; -} - -SRBRoot::SRBRoot(const UString *comment, UBool isPoolBundle, UErrorCode &errorCode) - : fRoot(NULL), fLocale(NULL), fIndexLength(0), fMaxTableLength(0), fNoFallback(FALSE), - fStringsForm(STRINGS_UTF16_V1), fIsPoolBundle(isPoolBundle), - fKeys(NULL), fKeyMap(NULL), - fKeysBottom(0), fKeysTop(0), fKeysCapacity(0), fKeysCount(0), fLocalKeyLimit(0), - f16BitUnits(), f16BitStringsLength(0), - fUsePoolBundle(&kNoPoolBundle), - fPoolStringIndexLimit(0), fPoolStringIndex16Limit(0), fLocalStringIndexLimit(0), - fWritePoolBundle(NULL) { - if (U_FAILURE(errorCode)) { - return; - } - - if (gFormatVersion > 1) { - // f16BitUnits must start with a zero for empty resources. - // We might be able to omit it if there are no empty 16-bit resources. - f16BitUnits.append((UChar)0); - } - - fKeys = (char *) uprv_malloc(sizeof(char) * KEY_SPACE_SIZE); - if (isPoolBundle) { - fRoot = new PseudoListResource(this, errorCode); - } else { - fRoot = new TableResource(this, NULL, comment, errorCode); - } - if (fKeys == NULL || fRoot == NULL || U_FAILURE(errorCode)) { - if (U_SUCCESS(errorCode)) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - } - return; - } - - fKeysCapacity = KEY_SPACE_SIZE; - /* formatVersion 1.1 and up: start fKeysTop after the root item and indexes[] */ - if (gUsePoolBundle || isPoolBundle) { - fIndexLength = URES_INDEX_POOL_CHECKSUM + 1; - } else if (gFormatVersion >= 2) { - fIndexLength = URES_INDEX_16BIT_TOP + 1; - } else /* formatVersion 1 */ { - fIndexLength = URES_INDEX_ATTRIBUTES + 1; - } - fKeysBottom = (1 /* root */ + fIndexLength) * 4; - uprv_memset(fKeys, 0, fKeysBottom); - fKeysTop = fKeysBottom; - - if (gFormatVersion == 1) { - fStringsForm = STRINGS_UTF16_V1; - } else { - fStringsForm = STRINGS_UTF16_V2; - } -} - -/* Closing Functions */ - -void res_close(struct SResource *res) { - delete res; -} - -SRBRoot::~SRBRoot() { - delete fRoot; - uprv_free(fLocale); - uprv_free(fKeys); - uprv_free(fKeyMap); -} - -/* Misc Functions */ - -void SRBRoot::setLocale(UChar *locale, UErrorCode &errorCode) { - if(U_FAILURE(errorCode)) { - return; - } - - uprv_free(fLocale); - fLocale = (char*) uprv_malloc(sizeof(char) * (u_strlen(locale)+1)); - if(fLocale == NULL) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - return; - } - - u_UCharsToChars(locale, fLocale, u_strlen(locale)+1); -} - -const char * -SRBRoot::getKeyString(int32_t key) const { - if (key < 0) { - return fUsePoolBundle->fKeys + (key & 0x7fffffff); - } else { - return fKeys + key; - } -} - -const char * -SResource::getKeyString(const SRBRoot *bundle) const { - if (fKey == -1) { - return NULL; - } - return bundle->getKeyString(fKey); -} - -const char * -SRBRoot::getKeyBytes(int32_t *pLength) const { - *pLength = fKeysTop - fKeysBottom; - return fKeys + fKeysBottom; -} - -int32_t -SRBRoot::addKeyBytes(const char *keyBytes, int32_t length, UErrorCode &errorCode) { - int32_t keypos; - - if (U_FAILURE(errorCode)) { - return -1; - } - if (length < 0 || (keyBytes == NULL && length != 0)) { - errorCode = U_ILLEGAL_ARGUMENT_ERROR; - return -1; - } - if (length == 0) { - return fKeysTop; - } - - keypos = fKeysTop; - fKeysTop += length; - if (fKeysTop >= fKeysCapacity) { - /* overflow - resize the keys buffer */ - fKeysCapacity += KEY_SPACE_SIZE; - fKeys = static_cast<char *>(uprv_realloc(fKeys, fKeysCapacity)); - if(fKeys == NULL) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - return -1; - } - } - - uprv_memcpy(fKeys + keypos, keyBytes, length); - - return keypos; -} - -int32_t -SRBRoot::addTag(const char *tag, UErrorCode &errorCode) { - int32_t keypos; - - if (U_FAILURE(errorCode)) { - return -1; - } - - if (tag == NULL) { - /* no error: the root table and array items have no keys */ - return -1; - } - - keypos = addKeyBytes(tag, (int32_t)(uprv_strlen(tag) + 1), errorCode); - if (U_SUCCESS(errorCode)) { - ++fKeysCount; - } - return keypos; -} - -static int32_t -compareInt32(int32_t lPos, int32_t rPos) { - /* - * Compare possibly-negative key offsets. Don't just return lPos - rPos - * because that is prone to negative-integer underflows. - */ - if (lPos < rPos) { - return -1; - } else if (lPos > rPos) { - return 1; - } else { - return 0; - } -} - -static int32_t U_CALLCONV -compareKeySuffixes(const void *context, const void *l, const void *r) { - const struct SRBRoot *bundle=(const struct SRBRoot *)context; - int32_t lPos = ((const KeyMapEntry *)l)->oldpos; - int32_t rPos = ((const KeyMapEntry *)r)->oldpos; - const char *lStart = bundle->getKeyString(lPos); - const char *lLimit = lStart; - const char *rStart = bundle->getKeyString(rPos); - const char *rLimit = rStart; - int32_t diff; - while (*lLimit != 0) { ++lLimit; } - while (*rLimit != 0) { ++rLimit; } - /* compare keys in reverse character order */ - while (lStart < lLimit && rStart < rLimit) { - diff = (int32_t)(uint8_t)*--lLimit - (int32_t)(uint8_t)*--rLimit; - if (diff != 0) { - return diff; - } - } - /* sort equal suffixes by descending key length */ - diff = (int32_t)(rLimit - rStart) - (int32_t)(lLimit - lStart); - if (diff != 0) { - return diff; - } - /* Sort pool bundle keys first (negative oldpos), and otherwise keys in parsing order. */ - return compareInt32(lPos, rPos); -} - -static int32_t U_CALLCONV -compareKeyNewpos(const void * /*context*/, const void *l, const void *r) { - return compareInt32(((const KeyMapEntry *)l)->newpos, ((const KeyMapEntry *)r)->newpos); -} - -static int32_t U_CALLCONV -compareKeyOldpos(const void * /*context*/, const void *l, const void *r) { - return compareInt32(((const KeyMapEntry *)l)->oldpos, ((const KeyMapEntry *)r)->oldpos); -} - -void -SRBRoot::compactKeys(UErrorCode &errorCode) { - KeyMapEntry *map; - char *keys; - int32_t i; - int32_t keysCount = fUsePoolBundle->fKeysCount + fKeysCount; - if (U_FAILURE(errorCode) || fKeysCount == 0 || fKeyMap != NULL) { - return; - } - map = (KeyMapEntry *)uprv_malloc(keysCount * sizeof(KeyMapEntry)); - if (map == NULL) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - return; - } - keys = (char *)fUsePoolBundle->fKeys; - for (i = 0; i < fUsePoolBundle->fKeysCount; ++i) { - map[i].oldpos = - (int32_t)(keys - fUsePoolBundle->fKeys) | 0x80000000; /* negative oldpos */ - map[i].newpos = 0; - while (*keys != 0) { ++keys; } /* skip the key */ - ++keys; /* skip the NUL */ - } - keys = fKeys + fKeysBottom; - for (; i < keysCount; ++i) { - map[i].oldpos = (int32_t)(keys - fKeys); - map[i].newpos = 0; - while (*keys != 0) { ++keys; } /* skip the key */ - ++keys; /* skip the NUL */ - } - /* Sort the keys so that each one is immediately followed by all of its suffixes. */ - uprv_sortArray(map, keysCount, (int32_t)sizeof(KeyMapEntry), - compareKeySuffixes, this, FALSE, &errorCode); - /* - * Make suffixes point into earlier, longer strings that contain them - * and mark the old, now unused suffix bytes as deleted. - */ - if (U_SUCCESS(errorCode)) { - keys = fKeys; - for (i = 0; i < keysCount;) { - /* - * This key is not a suffix of the previous one; - * keep this one and delete the following ones that are - * suffixes of this one. - */ - const char *key; - const char *keyLimit; - int32_t j = i + 1; - map[i].newpos = map[i].oldpos; - if (j < keysCount && map[j].oldpos < 0) { - /* Key string from the pool bundle, do not delete. */ - i = j; - continue; - } - key = getKeyString(map[i].oldpos); - for (keyLimit = key; *keyLimit != 0; ++keyLimit) {} - for (; j < keysCount && map[j].oldpos >= 0; ++j) { - const char *k; - char *suffix; - const char *suffixLimit; - int32_t offset; - suffix = keys + map[j].oldpos; - for (suffixLimit = suffix; *suffixLimit != 0; ++suffixLimit) {} - offset = static_cast<int32_t>((keyLimit - key) - (suffixLimit - suffix)); - if (offset < 0) { - break; /* suffix cannot be longer than the original */ - } - /* Is it a suffix of the earlier, longer key? */ - for (k = keyLimit; suffix < suffixLimit && *--k == *--suffixLimit;) {} - if (suffix == suffixLimit && *k == *suffixLimit) { - map[j].newpos = map[i].oldpos + offset; /* yes, point to the earlier key */ - /* mark the suffix as deleted */ - while (*suffix != 0) { *suffix++ = 1; } - *suffix = 1; - } else { - break; /* not a suffix, restart from here */ - } - } - i = j; - } - /* - * Re-sort by newpos, then modify the key characters array in-place - * to squeeze out unused bytes, and readjust the newpos offsets. - */ - uprv_sortArray(map, keysCount, (int32_t)sizeof(KeyMapEntry), - compareKeyNewpos, NULL, FALSE, &errorCode); - if (U_SUCCESS(errorCode)) { - int32_t oldpos, newpos, limit; - oldpos = newpos = fKeysBottom; - limit = fKeysTop; - /* skip key offsets that point into the pool bundle rather than this new bundle */ - for (i = 0; i < keysCount && map[i].newpos < 0; ++i) {} - if (i < keysCount) { - while (oldpos < limit) { - if (keys[oldpos] == 1) { - ++oldpos; /* skip unused bytes */ - } else { - /* adjust the new offsets for keys starting here */ - while (i < keysCount && map[i].newpos == oldpos) { - map[i++].newpos = newpos; - } - /* move the key characters to their new position */ - keys[newpos++] = keys[oldpos++]; - } - } - assert(i == keysCount); - } - fKeysTop = newpos; - /* Re-sort once more, by old offsets for binary searching. */ - uprv_sortArray(map, keysCount, (int32_t)sizeof(KeyMapEntry), - compareKeyOldpos, NULL, FALSE, &errorCode); - if (U_SUCCESS(errorCode)) { - /* key size reduction by limit - newpos */ - fKeyMap = map; - map = NULL; - } - } - } - uprv_free(map); -} - -static int32_t U_CALLCONV -compareStringSuffixes(const void * /*context*/, const void *l, const void *r) { - const StringResource *left = *((const StringResource **)l); - const StringResource *right = *((const StringResource **)r); - const UChar *lStart = left->getBuffer(); - const UChar *lLimit = lStart + left->length(); - const UChar *rStart = right->getBuffer(); - const UChar *rLimit = rStart + right->length(); - int32_t diff; - /* compare keys in reverse character order */ - while (lStart < lLimit && rStart < rLimit) { - diff = (int32_t)*--lLimit - (int32_t)*--rLimit; - if (diff != 0) { - return diff; - } - } - /* sort equal suffixes by descending string length */ - return right->length() - left->length(); -} - -static int32_t U_CALLCONV -compareStringLengths(const void * /*context*/, const void *l, const void *r) { - const StringResource *left = *((const StringResource **)l); - const StringResource *right = *((const StringResource **)r); - int32_t diff; - /* Make "is suffix of another string" compare greater than a non-suffix. */ - diff = (int)(left->fSame != NULL) - (int)(right->fSame != NULL); - if (diff != 0) { - return diff; - } - /* sort by ascending string length */ - diff = left->length() - right->length(); - if (diff != 0) { - return diff; - } - // sort by descending size reduction - diff = right->fNumUnitsSaved - left->fNumUnitsSaved; - if (diff != 0) { - return diff; - } - // sort lexically - return left->fString.compare(right->fString); -} - -void -StringResource::writeUTF16v2(int32_t base, UnicodeString &dest) { - int32_t len = length(); - fRes = URES_MAKE_RESOURCE(URES_STRING_V2, base + dest.length()); - fWritten = TRUE; - switch(fNumCharsForLength) { - case 0: - break; - case 1: - dest.append((UChar)(0xdc00 + len)); - break; - case 2: - dest.append((UChar)(0xdfef + (len >> 16))); - dest.append((UChar)len); - break; - case 3: - dest.append((UChar)0xdfff); - dest.append((UChar)(len >> 16)); - dest.append((UChar)len); - break; - default: - break; /* will not occur */ - } - dest.append(fString); - dest.append((UChar)0); -} - -void -SRBRoot::compactStringsV2(UHashtable *stringSet, UErrorCode &errorCode) { - if (U_FAILURE(errorCode)) { - return; - } - // Store the StringResource pointers in an array for - // easy sorting and processing. - // We enumerate a set of strings, so there are no duplicates. - int32_t count = uhash_count(stringSet); - LocalArray<StringResource *> array(new StringResource *[count], errorCode); - if (U_FAILURE(errorCode)) { - return; - } - for (int32_t pos = UHASH_FIRST, i = 0; i < count; ++i) { - array[i] = (StringResource *)uhash_nextElement(stringSet, &pos)->key.pointer; - } - /* Sort the strings so that each one is immediately followed by all of its suffixes. */ - uprv_sortArray(array.getAlias(), count, (int32_t)sizeof(struct SResource **), - compareStringSuffixes, NULL, FALSE, &errorCode); - if (U_FAILURE(errorCode)) { - return; - } - /* - * Make suffixes point into earlier, longer strings that contain them. - * Temporarily use fSame and fSuffixOffset for suffix strings to - * refer to the remaining ones. - */ - for (int32_t i = 0; i < count;) { - /* - * This string is not a suffix of the previous one; - * write this one and subsume the following ones that are - * suffixes of this one. - */ - StringResource *res = array[i]; - res->fNumUnitsSaved = (res->fNumCopies - 1) * res->get16BitStringsLength(); - // Whole duplicates of pool strings are already account for in fPoolStringIndexLimit, - // see StringResource::handlePreflightStrings(). - int32_t j; - for (j = i + 1; j < count; ++j) { - StringResource *suffixRes = array[j]; - /* Is it a suffix of the earlier, longer string? */ - if (res->fString.endsWith(suffixRes->fString)) { - assert(res->length() != suffixRes->length()); // Set strings are unique. - if (suffixRes->fWritten) { - // Pool string, skip. - } else if (suffixRes->fNumCharsForLength == 0) { - /* yes, point to the earlier string */ - suffixRes->fSame = res; - suffixRes->fSuffixOffset = res->length() - suffixRes->length(); - if (res->fWritten) { - // Suffix-share res which is a pool string. - // Compute the resource word and collect the maximum. - suffixRes->fRes = - res->fRes + res->fNumCharsForLength + suffixRes->fSuffixOffset; - int32_t poolStringIndex = (int32_t)RES_GET_OFFSET(suffixRes->fRes); - if (poolStringIndex >= fPoolStringIndexLimit) { - fPoolStringIndexLimit = poolStringIndex + 1; - } - suffixRes->fWritten = TRUE; - } - res->fNumUnitsSaved += suffixRes->fNumCopies * suffixRes->get16BitStringsLength(); - } else { - /* write the suffix by itself if we need explicit length */ - } - } else { - break; /* not a suffix, restart from here */ - } - } - i = j; - } - /* - * Re-sort the strings by ascending length (except suffixes last) - * to optimize for URES_TABLE16 and URES_ARRAY16: - * Keep as many as possible within reach of 16-bit offsets. - */ - uprv_sortArray(array.getAlias(), count, (int32_t)sizeof(struct SResource **), - compareStringLengths, NULL, FALSE, &errorCode); - if (U_FAILURE(errorCode)) { - return; - } - if (fIsPoolBundle) { - // Write strings that are sufficiently shared. - // Avoid writing other strings. - int32_t numStringsWritten = 0; - int32_t numUnitsSaved = 0; - int32_t numUnitsNotSaved = 0; - for (int32_t i = 0; i < count; ++i) { - StringResource *res = array[i]; - // Maximum pool string index when suffix-sharing the last character. - int32_t maxStringIndex = - f16BitUnits.length() + res->fNumCharsForLength + res->length() - 1; - if (res->fNumUnitsSaved >= GENRB_MIN_16BIT_UNITS_SAVED_FOR_POOL_STRING && - maxStringIndex < RES_MAX_OFFSET) { - res->writeUTF16v2(0, f16BitUnits); - ++numStringsWritten; - numUnitsSaved += res->fNumUnitsSaved; - } else { - numUnitsNotSaved += res->fNumUnitsSaved; - res->fRes = URES_MAKE_EMPTY_RESOURCE(URES_STRING); - res->fWritten = TRUE; - } - } - if (f16BitUnits.isBogus()) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - } - if (getShowWarning()) { // not quiet - printf("number of shared strings: %d\n", (int)numStringsWritten); - printf("16-bit units for strings: %6d = %6d bytes\n", - (int)f16BitUnits.length(), (int)f16BitUnits.length() * 2); - printf("16-bit units saved: %6d = %6d bytes\n", - (int)numUnitsSaved, (int)numUnitsSaved * 2); - printf("16-bit units not saved: %6d = %6d bytes\n", - (int)numUnitsNotSaved, (int)numUnitsNotSaved * 2); - } - } else { - assert(fPoolStringIndexLimit <= fUsePoolBundle->fStringIndexLimit); - /* Write the non-suffix strings. */ - int32_t i; - for (i = 0; i < count && array[i]->fSame == NULL; ++i) { - StringResource *res = array[i]; - if (!res->fWritten) { - int32_t localStringIndex = f16BitUnits.length(); - if (localStringIndex >= fLocalStringIndexLimit) { - fLocalStringIndexLimit = localStringIndex + 1; - } - res->writeUTF16v2(fPoolStringIndexLimit, f16BitUnits); - } - } - if (f16BitUnits.isBogus()) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - return; - } - if (fWritePoolBundle != NULL && gFormatVersion >= 3) { - PseudoListResource *poolStrings = - static_cast<PseudoListResource *>(fWritePoolBundle->fRoot); - for (i = 0; i < count && array[i]->fSame == NULL; ++i) { - assert(!array[i]->fString.isEmpty()); - StringResource *poolString = - new StringResource(fWritePoolBundle, array[i]->fString, errorCode); - if (poolString == NULL) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - break; - } - poolStrings->add(poolString); - } - } - /* Write the suffix strings. Make each point to the real string. */ - for (; i < count; ++i) { - StringResource *res = array[i]; - if (res->fWritten) { - continue; - } - StringResource *same = res->fSame; - assert(res->length() != same->length()); // Set strings are unique. - res->fRes = same->fRes + same->fNumCharsForLength + res->fSuffixOffset; - int32_t localStringIndex = (int32_t)RES_GET_OFFSET(res->fRes) - fPoolStringIndexLimit; - // Suffixes of pool strings have been set already. - assert(localStringIndex >= 0); - if (localStringIndex >= fLocalStringIndexLimit) { - fLocalStringIndexLimit = localStringIndex + 1; - } - res->fWritten = TRUE; - } - } - // +1 to account for the initial zero in f16BitUnits - assert(f16BitUnits.length() <= (f16BitStringsLength + 1)); -} diff --git a/deps/node/deps/icu-small/source/tools/genrb/reslist.h b/deps/node/deps/icu-small/source/tools/genrb/reslist.h deleted file mode 100644 index 53ade5b8..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/reslist.h +++ /dev/null @@ -1,423 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2000-2015, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File reslist.h -* -* Modification History: -* -* Date Name Description -* 02/21/00 weiv Creation. -******************************************************************************* -*/ - -#ifndef RESLIST_H -#define RESLIST_H - -#define KEY_SPACE_SIZE 65536 -#define RESLIST_MAX_INT_VECTOR 2048 - -#include "unicode/utypes.h" -#include "unicode/unistr.h" -#include "unicode/ures.h" -#include "unicode/ustring.h" -#include "cmemory.h" -#include "cstring.h" -#include "uhash.h" -#include "unewdata.h" -#include "uresdata.h" -#include "ustr.h" - -U_CDECL_BEGIN - -class PseudoListResource; - -struct ResFile { - ResFile() - : fBytes(NULL), fIndexes(NULL), - fKeys(NULL), fKeysLength(0), fKeysCount(0), - fStrings(NULL), fStringIndexLimit(0), - fChecksum(0) {} - ~ResFile() { close(); } - - void close(); - - uint8_t *fBytes; - const int32_t *fIndexes; - const char *fKeys; - int32_t fKeysLength; - int32_t fKeysCount; - - PseudoListResource *fStrings; - int32_t fStringIndexLimit; - - int32_t fChecksum; -}; - -struct SResource; - -typedef struct KeyMapEntry { - int32_t oldpos, newpos; -} KeyMapEntry; - -/* Resource bundle root table */ -struct SRBRoot { - SRBRoot(const UString *comment, UBool isPoolBundle, UErrorCode &errorCode); - ~SRBRoot(); - - void write(const char *outputDir, const char *outputPkg, - char *writtenFilename, int writtenFilenameLen, UErrorCode &errorCode); - - void setLocale(UChar *locale, UErrorCode &errorCode); - int32_t addTag(const char *tag, UErrorCode &errorCode); - - const char *getKeyString(int32_t key) const; - const char *getKeyBytes(int32_t *pLength) const; - - int32_t addKeyBytes(const char *keyBytes, int32_t length, UErrorCode &errorCode); - - void compactKeys(UErrorCode &errorCode); - - int32_t makeRes16(uint32_t resWord) const; - int32_t mapKey(int32_t oldpos) const; - -private: - void compactStringsV2(UHashtable *stringSet, UErrorCode &errorCode); - -public: - // TODO: private - - SResource *fRoot; // Normally a TableResource. - char *fLocale; - int32_t fIndexLength; - int32_t fMaxTableLength; - UBool fNoFallback; /* see URES_ATT_NO_FALLBACK */ - int8_t fStringsForm; /* default STRINGS_UTF16_V1 */ - UBool fIsPoolBundle; - - char *fKeys; - KeyMapEntry *fKeyMap; - int32_t fKeysBottom, fKeysTop; - int32_t fKeysCapacity; - int32_t fKeysCount; - int32_t fLocalKeyLimit; /* key offset < limit fits into URES_TABLE */ - - icu::UnicodeString f16BitUnits; - int32_t f16BitStringsLength; - - const ResFile *fUsePoolBundle; - int32_t fPoolStringIndexLimit; - int32_t fPoolStringIndex16Limit; - int32_t fLocalStringIndexLimit; - SRBRoot *fWritePoolBundle; -}; - -/* write a java resource file */ -// TODO: C++ify -void bundle_write_java(struct SRBRoot *bundle, const char *outputDir, const char* outputEnc, char *writtenFilename, - int writtenFilenameLen, const char* packageName, const char* bundleName, UErrorCode *status); - -/* write a xml resource file */ -// TODO: C++ify -void bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc, const char* rbname, - char *writtenFilename, int writtenFilenameLen, const char* language, const char* package, UErrorCode *status); - -/* Various resource types */ - -/* - * Return a unique pointer to a dummy object, - * for use in non-error cases when no resource is to be added to the bundle. - * (NULL is used in error cases.) - */ -struct SResource* res_none(void); - -class ArrayResource; -class TableResource; -class IntVectorResource; - -TableResource *table_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status); - -ArrayResource *array_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status); - -struct SResource *string_open(struct SRBRoot *bundle, const char *tag, const UChar *value, int32_t len, const struct UString* comment, UErrorCode *status); - -struct SResource *alias_open(struct SRBRoot *bundle, const char *tag, UChar *value, int32_t len, const struct UString* comment, UErrorCode *status); - -IntVectorResource *intvector_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status); - -struct SResource *int_open(struct SRBRoot *bundle, const char *tag, int32_t value, const struct UString* comment, UErrorCode *status); - -struct SResource *bin_open(struct SRBRoot *bundle, const char *tag, uint32_t length, uint8_t *data, const char* fileName, const struct UString* comment, UErrorCode *status); - -/* Resource place holder */ - -struct SResource { - SResource(); - SResource(SRBRoot *bundle, const char *tag, int8_t type, const UString* comment, - UErrorCode &errorCode); - virtual ~SResource(); - - UBool isTable() const { return fType == URES_TABLE; } - UBool isString() const { return fType == URES_STRING; } - - const char *getKeyString(const SRBRoot *bundle) const; - - /** - * Preflights strings. - * Finds duplicates and counts the total number of string code units - * so that they can be written first to the 16-bit array, - * for minimal string and container storage. - * - * We walk the final parse tree, rather than collecting this information while building it, - * so that we need not deal with changes to the parse tree (especially removing resources). - */ - void preflightStrings(SRBRoot *bundle, UHashtable *stringSet, UErrorCode &errorCode); - virtual void handlePreflightStrings(SRBRoot *bundle, UHashtable *stringSet, UErrorCode &errorCode); - - /** - * Writes resource values into f16BitUnits - * and determines the resource item word, if possible. - */ - void write16(SRBRoot *bundle); - virtual void handleWrite16(SRBRoot *bundle); - - /** - * Calculates ("preflights") and advances the *byteOffset - * by the size of the resource's data in the binary file and - * determines the resource item word. - * - * Most handlePreWrite() functions may add any number of bytes, but preWrite() - * will always pad it to a multiple of 4. - * The resource item type may be a related subtype of the fType. - * - * The preWrite() and write() functions start and end at the same - * byteOffset values. - * Prewriting allows bundle.write() to determine the root resource item word, - * before actually writing the bundle contents to the file, - * which is necessary because the root item is stored at the beginning. - */ - void preWrite(uint32_t *byteOffset); - virtual void handlePreWrite(uint32_t *byteOffset); - - /** - * Writes the resource's data to mem and updates the byteOffset - * in parallel. - */ - void write(UNewDataMemory *mem, uint32_t *byteOffset); - virtual void handleWrite(UNewDataMemory *mem, uint32_t *byteOffset); - - int8_t fType; /* nominal type: fRes (when != 0xffffffff) may use subtype */ - UBool fWritten; /* res_write() can exit early */ - uint32_t fRes; /* resource item word; RES_BOGUS=0xffffffff if not known yet */ - int32_t fRes16; /* Res16 version of fRes for Table, Table16, Array16; -1 if it does not fit. */ - int32_t fKey; /* Index into bundle->fKeys; -1 if no key. */ - int32_t fKey16; /* Key16 version of fKey for Table & Table16; -1 if no key or it does not fit. */ - int line; /* used internally to report duplicate keys in tables */ - SResource *fNext; /* This is for internal chaining while building */ - struct UString fComment; -}; - -class ContainerResource : public SResource { -public: - ContainerResource(SRBRoot *bundle, const char *tag, int8_t type, - const UString* comment, UErrorCode &errorCode) - : SResource(bundle, tag, type, comment, errorCode), - fCount(0), fFirst(NULL) {} - virtual ~ContainerResource(); - - virtual void handlePreflightStrings(SRBRoot *bundle, UHashtable *stringSet, UErrorCode &errorCode); -protected: - void writeAllRes16(SRBRoot *bundle); - void preWriteAllRes(uint32_t *byteOffset); - void writeAllRes(UNewDataMemory *mem, uint32_t *byteOffset); - void writeAllRes32(UNewDataMemory *mem, uint32_t *byteOffset); - -public: - // TODO: private with getter? - uint32_t fCount; - SResource *fFirst; -}; - -class TableResource : public ContainerResource { -public: - TableResource(SRBRoot *bundle, const char *tag, - const UString* comment, UErrorCode &errorCode) - : ContainerResource(bundle, tag, URES_TABLE, comment, errorCode), - fTableType(URES_TABLE), fRoot(bundle) {} - virtual ~TableResource(); - - void add(SResource *res, int linenumber, UErrorCode &errorCode); - - virtual void handleWrite16(SRBRoot *bundle); - virtual void handlePreWrite(uint32_t *byteOffset); - virtual void handleWrite(UNewDataMemory *mem, uint32_t *byteOffset); - - int8_t fTableType; // determined by table_write16() for table_preWrite() & table_write() - SRBRoot *fRoot; -}; - -class ArrayResource : public ContainerResource { -public: - ArrayResource(SRBRoot *bundle, const char *tag, - const UString* comment, UErrorCode &errorCode) - : ContainerResource(bundle, tag, URES_ARRAY, comment, errorCode), - fLast(NULL) {} - virtual ~ArrayResource(); - - void add(SResource *res); - - virtual void handleWrite16(SRBRoot *bundle); - virtual void handlePreWrite(uint32_t *byteOffset); - virtual void handleWrite(UNewDataMemory *mem, uint32_t *byteOffset); - - SResource *fLast; -}; - -/** - * List of resources for a pool bundle. - * Writes an empty table resource, rather than a container structure. - */ -class PseudoListResource : public ContainerResource { -public: - PseudoListResource(SRBRoot *bundle, UErrorCode &errorCode) - : ContainerResource(bundle, NULL, URES_TABLE, NULL, errorCode) {} - virtual ~PseudoListResource(); - - void add(SResource *res); - - virtual void handleWrite16(SRBRoot *bundle); -}; - -class StringBaseResource : public SResource { -public: - StringBaseResource(SRBRoot *bundle, const char *tag, int8_t type, - const UChar *value, int32_t len, - const UString* comment, UErrorCode &errorCode); - StringBaseResource(SRBRoot *bundle, int8_t type, - const icu::UnicodeString &value, UErrorCode &errorCode); - StringBaseResource(int8_t type, const UChar *value, int32_t len, UErrorCode &errorCode); - virtual ~StringBaseResource(); - - const UChar *getBuffer() const { return icu::toUCharPtr(fString.getBuffer()); } - int32_t length() const { return fString.length(); } - - virtual void handlePreWrite(uint32_t *byteOffset); - virtual void handleWrite(UNewDataMemory *mem, uint32_t *byteOffset); - - // TODO: private with getter? - icu::UnicodeString fString; -}; - -class StringResource : public StringBaseResource { -public: - StringResource(SRBRoot *bundle, const char *tag, const UChar *value, int32_t len, - const UString* comment, UErrorCode &errorCode) - : StringBaseResource(bundle, tag, URES_STRING, value, len, comment, errorCode), - fSame(NULL), fSuffixOffset(0), - fNumCopies(0), fNumUnitsSaved(0), fNumCharsForLength(0) {} - StringResource(SRBRoot *bundle, const icu::UnicodeString &value, UErrorCode &errorCode) - : StringBaseResource(bundle, URES_STRING, value, errorCode), - fSame(NULL), fSuffixOffset(0), - fNumCopies(0), fNumUnitsSaved(0), fNumCharsForLength(0) {} - StringResource(int32_t poolStringIndex, int8_t numCharsForLength, - const UChar *value, int32_t length, - UErrorCode &errorCode) - : StringBaseResource(URES_STRING, value, length, errorCode), - fSame(NULL), fSuffixOffset(0), - fNumCopies(0), fNumUnitsSaved(0), fNumCharsForLength(numCharsForLength) { - // v3 pool string encoded as string-v2 with low offset - fRes = URES_MAKE_RESOURCE(URES_STRING_V2, poolStringIndex); - fWritten = TRUE; - } - virtual ~StringResource(); - - int32_t get16BitStringsLength() const { - return fNumCharsForLength + length() + 1; // +1 for the NUL - } - - virtual void handlePreflightStrings(SRBRoot *bundle, UHashtable *stringSet, UErrorCode &errorCode); - virtual void handleWrite16(SRBRoot *bundle); - - void writeUTF16v2(int32_t base, icu::UnicodeString &dest); - - StringResource *fSame; // used for duplicates - int32_t fSuffixOffset; // this string is a suffix of fSame at this offset - int32_t fNumCopies; // number of equal strings represented by one stringSet element - int32_t fNumUnitsSaved; // from not writing duplicates and suffixes - int8_t fNumCharsForLength; -}; - -class AliasResource : public StringBaseResource { -public: - AliasResource(SRBRoot *bundle, const char *tag, const UChar *value, int32_t len, - const UString* comment, UErrorCode &errorCode) - : StringBaseResource(bundle, tag, URES_ALIAS, value, len, comment, errorCode) {} - virtual ~AliasResource(); -}; - -class IntResource : public SResource { -public: - IntResource(SRBRoot *bundle, const char *tag, int32_t value, - const UString* comment, UErrorCode &errorCode); - virtual ~IntResource(); - - // TODO: private with getter? - int32_t fValue; -}; - -class IntVectorResource : public SResource { -public: - IntVectorResource(SRBRoot *bundle, const char *tag, - const UString* comment, UErrorCode &errorCode); - virtual ~IntVectorResource(); - - void add(int32_t value, UErrorCode &errorCode); - - virtual void handlePreWrite(uint32_t *byteOffset); - virtual void handleWrite(UNewDataMemory *mem, uint32_t *byteOffset); - - // TODO: UVector32 - uint32_t fCount; - uint32_t *fArray; -}; - -class BinaryResource : public SResource { -public: - BinaryResource(SRBRoot *bundle, const char *tag, - uint32_t length, uint8_t *data, const char* fileName, - const UString* comment, UErrorCode &errorCode); - virtual ~BinaryResource(); - - virtual void handlePreWrite(uint32_t *byteOffset); - virtual void handleWrite(UNewDataMemory *mem, uint32_t *byteOffset); - - // TODO: CharString? - uint32_t fLength; - uint8_t *fData; - // TODO: CharString - char* fFileName; // file name for binary or import binary tags if any -}; - -// TODO: use LocalPointer or delete -void res_close(struct SResource *res); - -void setIncludeCopyright(UBool val); -UBool getIncludeCopyright(void); - -void setFormatVersion(int32_t formatVersion); - -int32_t getFormatVersion(); - -void setUsePoolBundle(UBool use); - -/* in wrtxml.cpp */ -uint32_t computeCRC(const char *ptr, uint32_t len, uint32_t lastcrc); - -U_CDECL_END -#endif /* #ifndef RESLIST_H */ diff --git a/deps/node/deps/icu-small/source/tools/genrb/rle.c b/deps/node/deps/icu-small/source/tools/genrb/rle.c deleted file mode 100644 index 08495c2b..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/rle.c +++ /dev/null @@ -1,406 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2000-2003, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File writejava.c -* -* Modification History: -* -* Date Name Description -* 01/11/02 Ram Creation. -******************************************************************************* -*/ -#include "rle.h" -/** - * The ESCAPE character is used during run-length encoding. It signals - * a run of identical chars. - */ -static const uint16_t ESCAPE = 0xA5A5; - -/** - * The ESCAPE_BYTE character is used during run-length encoding. It signals - * a run of identical bytes. - */ -static const uint8_t ESCAPE_BYTE = (uint8_t)0xA5; - -/** - * Append a byte to the given StringBuffer, packing two bytes into each - * character. The state parameter maintains intermediary data between - * calls. - * @param state A two-element array, with state[0] == 0 if this is the - * first byte of a pair, or state[0] != 0 if this is the second byte - * of a pair, in which case state[1] is the first byte. - */ -static uint16_t* -appendEncodedByte(uint16_t* buffer, uint16_t* buffLimit, uint8_t value, uint8_t state[],UErrorCode* status) { - if(!status || U_FAILURE(*status)){ - return NULL; - } - if (state[0] != 0) { - uint16_t c = (uint16_t) ((state[1] << 8) | (((int32_t) value) & 0xFF)); - if(buffer < buffLimit){ - *buffer++ = c; - }else{ - *status = U_BUFFER_OVERFLOW_ERROR; - } - state[0] = 0; - return buffer; - } - else { - state[0] = 1; - state[1] = value; - return buffer; - } -} -/** - * Encode a run, possibly a degenerate run (of < 4 values). - * @param length The length of the run; must be > 0 && <= 0xFF. - */ -static uint16_t* -encodeRunByte(uint16_t* buffer,uint16_t* bufLimit, uint8_t value, int32_t length, uint8_t state[], UErrorCode* status) { - if(!status || U_FAILURE(*status)){ - return NULL; - } - if (length < 4) { - int32_t j=0; - for (; j<length; ++j) { - if (value == ESCAPE_BYTE) { - buffer = appendEncodedByte(buffer,bufLimit, ESCAPE_BYTE, state,status); - } - buffer = appendEncodedByte(buffer,bufLimit, value, state, status); - } - } - else { - if (length == ESCAPE_BYTE) { - if (value == ESCAPE_BYTE){ - buffer = appendEncodedByte(buffer, bufLimit,ESCAPE_BYTE, state,status); - } - buffer = appendEncodedByte(buffer,bufLimit, value, state, status); - --length; - } - buffer = appendEncodedByte(buffer,bufLimit, ESCAPE_BYTE, state,status); - buffer = appendEncodedByte(buffer,bufLimit, (char)length, state, status); - buffer = appendEncodedByte(buffer,bufLimit, value, state, status); /* Don't need to escape this value*/ - } - return buffer; -} - -#define APPEND( buffer, bufLimit, value, num, status){ \ - if(buffer<bufLimit){ \ - *buffer++=(value); \ - }else{ \ - *status = U_BUFFER_OVERFLOW_ERROR; \ - } \ - num++; \ -} - -/** - * Encode a run, possibly a degenerate run (of < 4 values). - * @param length The length of the run; must be > 0 && <= 0xFFFF. - */ -static uint16_t* -encodeRunShort(uint16_t* buffer,uint16_t* bufLimit, uint16_t value, int32_t length,UErrorCode* status) { - int32_t num=0; - if (length < 4) { - int j=0; - for (; j<length; ++j) { - if (value == (int32_t) ESCAPE){ - APPEND(buffer,bufLimit,ESCAPE, num, status); - - } - APPEND(buffer,bufLimit,value,num, status); - } - } - else { - if (length == (int32_t) ESCAPE) { - if (value == (int32_t) ESCAPE){ - APPEND(buffer,bufLimit,ESCAPE,num,status); - - } - APPEND(buffer,bufLimit,value,num,status); - --length; - } - APPEND(buffer,bufLimit,ESCAPE,num,status); - APPEND(buffer,bufLimit,(uint16_t) length, num,status); - APPEND(buffer,bufLimit,(uint16_t)value, num, status); /* Don't need to escape this value */ - } - return buffer; -} - -/** - * Construct a string representing a char array. Use run-length encoding. - * A character represents itself, unless it is the ESCAPE character. Then - * the following notations are possible: - * ESCAPE ESCAPE ESCAPE literal - * ESCAPE n c n instances of character c - * Since an encoded run occupies 3 characters, we only encode runs of 4 or - * more characters. Thus we have n > 0 and n != ESCAPE and n <= 0xFFFF. - * If we encounter a run where n == ESCAPE, we represent this as: - * c ESCAPE n-1 c - * The ESCAPE value is chosen so as not to collide with commonly - * seen values. - */ -int32_t -usArrayToRLEString(const uint16_t* src,int32_t srcLen,uint16_t* buffer, int32_t bufLen,UErrorCode* status) { - uint16_t* bufLimit = buffer+bufLen; - uint16_t* saveBuffer = buffer; - if(buffer < bufLimit){ - *buffer++ = (uint16_t)(srcLen>>16); - if(buffer<bufLimit){ - uint16_t runValue = src[0]; - int32_t runLength = 1; - int i=1; - *buffer++ = (uint16_t) srcLen; - - for (; i<srcLen; ++i) { - uint16_t s = src[i]; - if (s == runValue && runLength < 0xFFFF){ - ++runLength; - }else { - buffer = encodeRunShort(buffer,bufLimit, (uint16_t)runValue, runLength,status); - runValue = s; - runLength = 1; - } - } - buffer= encodeRunShort(buffer,bufLimit,(uint16_t)runValue, runLength,status); - }else{ - *status = U_BUFFER_OVERFLOW_ERROR; - } - }else{ - *status = U_BUFFER_OVERFLOW_ERROR; - } - return (int32_t)(buffer - saveBuffer); -} - -/** - * Construct a string representing a byte array. Use run-length encoding. - * Two bytes are packed into a single char, with a single extra zero byte at - * the end if needed. A byte represents itself, unless it is the - * ESCAPE_BYTE. Then the following notations are possible: - * ESCAPE_BYTE ESCAPE_BYTE ESCAPE_BYTE literal - * ESCAPE_BYTE n b n instances of byte b - * Since an encoded run occupies 3 bytes, we only encode runs of 4 or - * more bytes. Thus we have n > 0 and n != ESCAPE_BYTE and n <= 0xFF. - * If we encounter a run where n == ESCAPE_BYTE, we represent this as: - * b ESCAPE_BYTE n-1 b - * The ESCAPE_BYTE value is chosen so as not to collide with commonly - * seen values. - */ -int32_t -byteArrayToRLEString(const uint8_t* src,int32_t srcLen, uint16_t* buffer,int32_t bufLen, UErrorCode* status) { - const uint16_t* saveBuf = buffer; - uint16_t* bufLimit = buffer+bufLen; - if(buffer < bufLimit){ - *buffer++ = ((uint16_t) (srcLen >> 16)); - - if(buffer<bufLimit){ - uint8_t runValue = src[0]; - int runLength = 1; - uint8_t state[2]= {0}; - int i=1; - *buffer++=((uint16_t) srcLen); - for (; i<srcLen; ++i) { - uint8_t b = src[i]; - if (b == runValue && runLength < 0xFF){ - ++runLength; - } - else { - buffer = encodeRunByte(buffer, bufLimit,runValue, runLength, state,status); - runValue = b; - runLength = 1; - } - } - buffer = encodeRunByte(buffer,bufLimit, runValue, runLength, state, status); - - /* We must save the final byte, if there is one, by padding - * an extra zero. - */ - if (state[0] != 0) { - buffer = appendEncodedByte(buffer,bufLimit, 0, state ,status); - } - }else{ - *status = U_BUFFER_OVERFLOW_ERROR; - } - }else{ - *status = U_BUFFER_OVERFLOW_ERROR; - } - return (int32_t) (buffer - saveBuf); -} - - -/** - * Construct an array of shorts from a run-length encoded string. - */ -int32_t -rleStringToUCharArray(uint16_t* src, int32_t srcLen, uint16_t* target, int32_t tgtLen, UErrorCode* status) { - int32_t length = 0; - int32_t ai = 0; - int i=2; - - if(!status || U_FAILURE(*status)){ - return 0; - } - /* the source is null terminated */ - if(srcLen == -1){ - srcLen = u_strlen(src); - } - if(srcLen <= 2){ - return 2; - } - length = (((int32_t) src[0]) << 16) | ((int32_t) src[1]); - - if(target == NULL){ - return length; - } - if(tgtLen < length){ - *status = U_BUFFER_OVERFLOW_ERROR; - return length; - } - - for (; i<srcLen; ++i) { - uint16_t c = src[i]; - if (c == ESCAPE) { - c = src[++i]; - if (c == ESCAPE) { - target[ai++] = c; - } else { - int32_t runLength = (int32_t) c; - uint16_t runValue = src[++i]; - int j=0; - for (; j<runLength; ++j) { - target[ai++] = runValue; - } - } - } - else { - target[ai++] = c; - } - } - - if (ai != length){ - *status = U_INTERNAL_PROGRAM_ERROR; - } - - return length; -} - -/** - * Construct an array of bytes from a run-length encoded string. - */ -int32_t -rleStringToByteArray(uint16_t* src, int32_t srcLen, uint8_t* target, int32_t tgtLen, UErrorCode* status) { - - int32_t length = 0; - UBool nextChar = TRUE; - uint16_t c = 0; - int32_t node = 0; - int32_t runLength = 0; - int32_t i = 2; - int32_t ai=0; - - if(!status || U_FAILURE(*status)){ - return 0; - } - /* the source is null terminated */ - if(srcLen == -1){ - srcLen = u_strlen(src); - } - if(srcLen <= 2){ - return 2; - } - length = (((int32_t) src[0]) << 16) | ((int32_t) src[1]); - - if(target == NULL){ - return length; - } - if(tgtLen < length){ - *status = U_BUFFER_OVERFLOW_ERROR; - return length; - } - - for (; ai<tgtLen; ) { - /* This part of the loop places the next byte into the local - * variable 'b' each time through the loop. It keeps the - * current character in 'c' and uses the boolean 'nextChar' - * to see if we've taken both bytes out of 'c' yet. - */ - uint8_t b; - if (nextChar) { - c = src[i++]; - b = (uint8_t) (c >> 8); - nextChar = FALSE; - } - else { - b = (uint8_t) (c & 0xFF); - nextChar = TRUE; - } - - /* This part of the loop is a tiny state machine which handles - * the parsing of the run-length encoding. This would be simpler - * if we could look ahead, but we can't, so we use 'node' to - * move between three nodes in the state machine. - */ - switch (node) { - case 0: - /* Normal idle node */ - if (b == ESCAPE_BYTE) { - node = 1; - } - else { - target[ai++] = b; - } - break; - case 1: - /* We have seen one ESCAPE_BYTE; we expect either a second - * one, or a run length and value. - */ - if (b == ESCAPE_BYTE) { - target[ai++] = ESCAPE_BYTE; - node = 0; - } - else { - runLength = b; - node = 2; - } - break; - case 2: - { - int j=0; - /* We have seen an ESCAPE_BYTE and length byte. We interpret - * the next byte as the value to be repeated. - */ - for (; j<runLength; ++j){ - if(ai<tgtLen){ - target[ai++] = b; - }else{ - *status = U_BUFFER_OVERFLOW_ERROR; - return ai; - } - } - node = 0; - break; - } - } - } - - if (node != 0){ - *status = U_INTERNAL_PROGRAM_ERROR; - /*("Bad run-length encoded byte array")*/ - return 0; - } - - - if (i != srcLen){ - /*("Excess data in RLE byte array string");*/ - *status = U_INTERNAL_PROGRAM_ERROR; - return ai; - } - - return ai; -} diff --git a/deps/node/deps/icu-small/source/tools/genrb/rle.h b/deps/node/deps/icu-small/source/tools/genrb/rle.h deleted file mode 100644 index 9f580733..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/rle.h +++ /dev/null @@ -1,74 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2000, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File writejava.c -* -* Modification History: -* -* Date Name Description -* 01/11/02 Ram Creation. -******************************************************************************* -*/ - -#ifndef RLE_H -#define RLE_H 1 - -#include "unicode/utypes.h" -#include "unicode/ustring.h" - -U_CDECL_BEGIN -/** - * Construct a string representing a byte array. Use run-length encoding. - * Two bytes are packed into a single char, with a single extra zero byte at - * the end if needed. A byte represents itself, unless it is the - * ESCAPE_BYTE. Then the following notations are possible: - * ESCAPE_BYTE ESCAPE_BYTE ESCAPE_BYTE literal - * ESCAPE_BYTE n b n instances of byte b - * Since an encoded run occupies 3 bytes, we only encode runs of 4 or - * more bytes. Thus we have n > 0 and n != ESCAPE_BYTE and n <= 0xFF. - * If we encounter a run where n == ESCAPE_BYTE, we represent this as: - * b ESCAPE_BYTE n-1 b - * The ESCAPE_BYTE value is chosen so as not to collide with commonly - * seen values. - */ -int32_t -byteArrayToRLEString(const uint8_t* src,int32_t srcLen, uint16_t* buffer,int32_t bufLen, UErrorCode* status); - - -/** - * Construct a string representing a char array. Use run-length encoding. - * A character represents itself, unless it is the ESCAPE character. Then - * the following notations are possible: - * ESCAPE ESCAPE ESCAPE literal - * ESCAPE n c n instances of character c - * Since an encoded run occupies 3 characters, we only encode runs of 4 or - * more characters. Thus we have n > 0 and n != ESCAPE and n <= 0xFFFF. - * If we encounter a run where n == ESCAPE, we represent this as: - * c ESCAPE n-1 c - * The ESCAPE value is chosen so as not to collide with commonly - * seen values. - */ -int32_t -usArrayToRLEString(const uint16_t* src,int32_t srcLen,uint16_t* buffer, int32_t bufLen,UErrorCode* status); - -/** - * Construct an array of bytes from a run-length encoded string. - */ -int32_t -rleStringToByteArray(uint16_t* src, int32_t srcLen, uint8_t* target, int32_t tgtLen, UErrorCode* status); -/** - * Construct an array of shorts from a run-length encoded string. - */ -int32_t -rleStringToUCharArray(uint16_t* src, int32_t srcLen, uint16_t* target, int32_t tgtLen, UErrorCode* status); - -U_CDECL_END - -#endif diff --git a/deps/node/deps/icu-small/source/tools/genrb/ustr.c b/deps/node/deps/icu-small/source/tools/genrb/ustr.c deleted file mode 100644 index f1436ae8..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/ustr.c +++ /dev/null @@ -1,219 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2012, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File ustr.c -* -* Modification History: -* -* Date Name Description -* 05/28/99 stephen Creation. -******************************************************************************* -*/ - -#include "ustr.h" -#include "cmemory.h" -#include "cstring.h" -#include "unicode/ustring.h" -#include "unicode/putil.h" -#include "unicode/utf16.h" - -/* Protos */ -static void ustr_resize(struct UString *s, int32_t len, UErrorCode *status); - -/* Macros */ -#define ALLOCATION(minSize) (minSize < 0x80 ? 0x80 : (2 * minSize + 0x80) & ~(0x80 - 1)) - -U_CFUNC void -ustr_init(struct UString *s) -{ - s->fChars = 0; - s->fLength = s->fCapacity = 0; -} - -U_CFUNC void -ustr_initChars(struct UString *s, const char* source, int32_t length, UErrorCode *status) -{ - int i = 0; - if (U_FAILURE(*status)) return; - s->fChars = 0; - s->fLength = s->fCapacity = 0; - if (length == -1) { - length = (int32_t)uprv_strlen(source); - } - if(s->fCapacity < length) { - ustr_resize(s, ALLOCATION(length), status); - if(U_FAILURE(*status)) return; - } - for (; i < length; i++) - { - UChar charToAppend; - u_charsToUChars(source+i, &charToAppend, 1); - ustr_ucat(s, charToAppend, status); - /* -#if U_CHARSET_FAMILY==U_ASCII_FAMILY - ustr_ucat(s, (UChar)(uint8_t)(source[i]), status); -#elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY - ustr_ucat(s, (UChar)asciiFromEbcdic[(uint8_t)(*cs++)], status); -#else -# error U_CHARSET_FAMILY is not valid -#endif - */ - } -} - -U_CFUNC void -ustr_deinit(struct UString *s) -{ - if (s) { - uprv_free(s->fChars); - s->fChars = 0; - s->fLength = s->fCapacity = 0; - } -} - -U_CFUNC void -ustr_cpy(struct UString *dst, - const struct UString *src, - UErrorCode *status) -{ - if(U_FAILURE(*status) || dst == src) - return; - - if(dst->fCapacity < src->fLength) { - ustr_resize(dst, ALLOCATION(src->fLength), status); - if(U_FAILURE(*status)) - return; - } - if(src->fChars == NULL || dst->fChars == NULL){ - return; - } - u_memcpy(dst->fChars, src->fChars, src->fLength); - dst->fLength = src->fLength; - dst->fChars[dst->fLength] = 0x0000; -} - -U_CFUNC void -ustr_setlen(struct UString *s, - int32_t len, - UErrorCode *status) -{ - if(U_FAILURE(*status)) - return; - - if(s->fCapacity < (len + 1)) { - ustr_resize(s, ALLOCATION(len), status); - if(U_FAILURE(*status)) - return; - } - - s->fLength = len; - s->fChars[len] = 0x0000; -} - -U_CFUNC void -ustr_cat(struct UString *dst, - const struct UString *src, - UErrorCode *status) -{ - ustr_ncat(dst, src, src->fLength, status); -} - -U_CFUNC void -ustr_ncat(struct UString *dst, - const struct UString *src, - int32_t n, - UErrorCode *status) -{ - if(U_FAILURE(*status) || dst == src) - return; - - if(dst->fCapacity < (dst->fLength + n)) { - ustr_resize(dst, ALLOCATION(dst->fLength + n), status); - if(U_FAILURE(*status)) - return; - } - - uprv_memcpy(dst->fChars + dst->fLength, src->fChars, - sizeof(UChar) * n); - dst->fLength += src->fLength; - dst->fChars[dst->fLength] = 0x0000; -} - -U_CFUNC void -ustr_ucat(struct UString *dst, - UChar c, - UErrorCode *status) -{ - if(U_FAILURE(*status)) - return; - - if(dst->fCapacity < (dst->fLength + 1)) { - ustr_resize(dst, ALLOCATION(dst->fLength + 1), status); - if(U_FAILURE(*status)) - return; - } - - uprv_memcpy(dst->fChars + dst->fLength, &c, - sizeof(UChar) * 1); - dst->fLength += 1; - dst->fChars[dst->fLength] = 0x0000; -} -U_CFUNC void -ustr_u32cat(struct UString *dst, UChar32 c, UErrorCode *status){ - if(c > 0x10FFFF){ - *status = U_ILLEGAL_CHAR_FOUND; - return; - } - if(c >0xFFFF){ - ustr_ucat(dst, U16_LEAD(c), status); - ustr_ucat(dst, U16_TRAIL(c), status); - }else{ - ustr_ucat(dst, (UChar) c, status); - } -} -U_CFUNC void -ustr_uscat(struct UString *dst, - const UChar* src,int len, - UErrorCode *status) -{ - if(U_FAILURE(*status)) - return; - - if(dst->fCapacity < (dst->fLength + len)) { - ustr_resize(dst, ALLOCATION(dst->fLength + len), status); - if(U_FAILURE(*status)) - return; - } - - uprv_memcpy(dst->fChars + dst->fLength, src, - sizeof(UChar) * len); - dst->fLength += len; - dst->fChars[dst->fLength] = 0x0000; -} - -/* Destroys data in the string */ -static void -ustr_resize(struct UString *s, - int32_t len, - UErrorCode *status) -{ - if(U_FAILURE(*status)) - return; - - /* +1 for trailing 0x0000 */ - s->fChars = (UChar*) uprv_realloc(s->fChars, sizeof(UChar) * (len + 1)); - if(s->fChars == 0) { - *status = U_MEMORY_ALLOCATION_ERROR; - s->fLength = s->fCapacity = 0; - return; - } - - s->fCapacity = len; -} diff --git a/deps/node/deps/icu-small/source/tools/genrb/ustr.h b/deps/node/deps/icu-small/source/tools/genrb/ustr.h deleted file mode 100644 index 91483d1f..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/ustr.h +++ /dev/null @@ -1,81 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2012, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File ustr.h -* -* Modification History: -* -* Date Name Description -* 05/28/99 stephen Creation. -******************************************************************************* -*/ - -#ifndef USTR_H -#define USTR_H 1 - -#include "unicode/utypes.h" - -#define U_APPEND_CHAR32(c,target,len) { \ - if (c <= 0xffff) \ - { \ - *(target)++ = (UChar) c; \ - len=1; \ - } \ - else \ - { \ - target[0] = U16_LEAD(c); \ - target[1] = U16_TRAIL(c); \ - len=2; \ - target +=2; \ - } \ -} - -#define U_APPEND_CHAR32_ONLY(c,target) { \ - if (c <= 0xffff) \ - { \ - *(target)++ = (UChar) c; \ - } \ - else \ - { \ - target[0] = U16_LEAD(c); \ - target[1] = U16_TRAIL(c); \ - target +=2; \ - } \ -} - -/* A C representation of a string "object" (to avoid realloc all the time) */ -struct UString { - UChar *fChars; - int32_t fLength; - int32_t fCapacity; -}; - -U_CFUNC void ustr_init(struct UString *s); - -U_CFUNC void -ustr_initChars(struct UString *s, const char* source, int32_t length, UErrorCode *status); - -U_CFUNC void ustr_deinit(struct UString *s); - -U_CFUNC void ustr_setlen(struct UString *s, int32_t len, UErrorCode *status); - -U_CFUNC void ustr_cpy(struct UString *dst, const struct UString *src, - UErrorCode *status); - -U_CFUNC void ustr_cat(struct UString *dst, const struct UString *src, - UErrorCode *status); - -U_CFUNC void ustr_ncat(struct UString *dst, const struct UString *src, - int32_t n, UErrorCode *status); - -U_CFUNC void ustr_ucat(struct UString *dst, UChar c, UErrorCode *status); -U_CFUNC void ustr_u32cat(struct UString *dst, UChar32 c, UErrorCode *status); -U_CFUNC void ustr_uscat(struct UString *dst, const UChar* src,int len,UErrorCode *status); -#endif diff --git a/deps/node/deps/icu-small/source/tools/genrb/wrtjava.cpp b/deps/node/deps/icu-small/source/tools/genrb/wrtjava.cpp deleted file mode 100644 index f1eb2297..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/wrtjava.cpp +++ /dev/null @@ -1,701 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2000-2015, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File wrtjava.cpp -* -* Modification History: -* -* Date Name Description -* 01/11/02 Ram Creation. -* 02/12/08 Spieth Fix errant 'new Object[][]{' insertion -* 02/19/08 Spieth Removed ICUListResourceBundle dependancy -******************************************************************************* -*/ - -#include <assert.h> -#include "unicode/unistr.h" -#include "reslist.h" -#include "unewdata.h" -#include "unicode/ures.h" -#include "errmsg.h" -#include "filestrm.h" -#include "cstring.h" -#include "unicode/ucnv.h" -#include "genrb.h" -#include "rle.h" -#include "uhash.h" -#include "uresimp.h" -#include "unicode/ustring.h" -#include "unicode/utf8.h" - -void res_write_java(struct SResource *res,UErrorCode *status); - - -static const char copyRight[] = - "/* \n" - " *******************************************************************************\n" - " *\n" - " * Copyright (C) International Business Machines\n" - " * Corporation and others. All Rights Reserved.\n" - " *\n" - " *******************************************************************************\n" - " * $" "Source: $ \n" - " * $" "Date: $ \n" - " * $" "Revision: $ \n" - " *******************************************************************************\n" - " */\n\n"; -static const char warningMsg[] = - "/*********************************************************************\n" - "######################################################################\n" - "\n" - " WARNING: This file is generated by genrb Version " GENRB_VERSION ".\n" - " If you edit this file, please make sure that, the source\n" - " of this file (XXXX.txt in LocaleElements_XXXX.java)\n" - " is also edited.\n" - "######################################################################\n" - " *********************************************************************\n" - " */\n\n"; -static const char* openBrace="{\n"; -static const char* closeClass=" };\n" - "}\n"; - -static const char* javaClass = "import java.util.ListResourceBundle;\n\n" - "public class "; - -static const char* javaClass1= " extends ListResourceBundle {\n\n" - " /**\n" - " * Overrides ListResourceBundle \n" - " */\n" - " public final Object[][] getContents() { \n" - " return contents;\n" - " }\n\n" - " private static Object[][] contents = {\n"; -/*static const char* javaClassICU= " extends ListResourceBundle {\n\n" - " public %s () {\n" - " super.contents = data;\n" - " }\n" - " static final Object[][] data = new Object[][] { \n";*/ -static int tabCount = 3; - -static FileStream* out=NULL; -static struct SRBRoot* srBundle ; -/*static const char* outDir = NULL;*/ - -static const char* bName=NULL; -static const char* pName=NULL; - -static void write_tabs(FileStream* os){ - int i=0; - for(;i<=tabCount;i++){ - T_FileStream_write(os," ",4); - } -} - -#define ZERO 0x30 - -static const char* enc =""; -static UConverter* conv = NULL; - -static int32_t -uCharsToChars(char *target, int32_t targetLen, const UChar *source, int32_t sourceLen, UErrorCode *status) { - int i=0, j=0; - char str[30]={'\0'}; - while(i<sourceLen){ - if (source[i] == '\n') { - if (j + 2 < targetLen) { - uprv_strcat(target, "\\n"); - } - j += 2; - }else if(source[i]==0x0D){ - if(j+2<targetLen){ - uprv_strcat(target,"\\f"); - } - j+=2; - }else if(source[i] == '"'){ - if(source[i-1]=='\''){ - if(j+2<targetLen){ - uprv_strcat(target,"\\"); - target[j+1]= (char)source[i]; - } - j+=2; - }else if(source[i-1]!='\\'){ - - if(j+2<targetLen){ - uprv_strcat(target,"\\"); - target[j+1]= (char)source[i]; - } - j+=2; - }else if(source[i-1]=='\\'){ - target[j++]= (char)source[i]; - } - }else if(source[i]=='\\'){ - if(i+1<sourceLen){ - switch(source[i+1]){ - case ',': - case '!': - case '?': - case '#': - case '.': - case '%': - case '&': - case ':': - case ';': - if(j+2<targetLen){ - uprv_strcat(target,"\\\\"); - } - j+=2; - break; - case '"': - case '\'': - if(j+3<targetLen){ - uprv_strcat(target,"\\\\\\"); - } - j+=3; - break; - default : - if(j<targetLen){ - target[j]=(char)source[i]; - } - j++; - break; - } - }else{ - if(j<targetLen){ - uprv_strcat(target,"\\\\"); - } - j+=2; - } - }else if(source[i]>=0x20 && source[i]<0x7F/*ASCII*/){ - if(j<targetLen){ - target[j] = (char) source[i]; - } - j++; - }else{ - if(*enc =='\0' || source[i]==0x0000){ - uprv_strcpy(str,"\\u"); - itostr(str+2,source[i],16,4); - if(j+6<targetLen){ - uprv_strcat(target,str); - } - j+=6; - }else{ - char dest[30] = {0}; - int retVal=ucnv_fromUChars(conv,dest,30,source+i,1,status); - if(U_FAILURE(*status)){ - return 0; - } - if(j+retVal<targetLen){ - uprv_strcat(target,dest); - } - j+=retVal; - } - } - i++; - } - return j; -} - - -static uint32_t -strrch(const char* source,uint32_t sourceLen,char find){ - const char* tSourceEnd =source + (sourceLen-1); - while(tSourceEnd>= source){ - if(*tSourceEnd==find){ - return (uint32_t)(tSourceEnd-source); - } - tSourceEnd--; - } - return (uint32_t)(tSourceEnd-source); -} - -static int32_t getColumnCount(int32_t len){ - int32_t columnCount = 80; - int32_t maxLines = 3000; - int32_t adjustedLen = len*5; /* assume that every codepoint is represented in \uXXXX format*/ - /* - * calculate the number of lines that - * may be required if column count is 80 - */ - if (maxLines < (adjustedLen / columnCount) ){ - columnCount = adjustedLen / maxLines; - } - return columnCount; -} -static void -str_write_java(const UChar *src, int32_t srcLen, UBool printEndLine, UErrorCode *status) { - - uint32_t length = srcLen*8; - uint32_t bufLen = 0; - uint32_t columnCount; - char* buf = (char*) malloc(sizeof(char)*length); - - if(buf == NULL) { - *status = U_MEMORY_ALLOCATION_ERROR; - return; - } - - columnCount = getColumnCount(srcLen); - memset(buf,0,length); - - bufLen = uCharsToChars(buf,length,src,srcLen,status); - // buflen accounts for extra bytes added due to multi byte encoding of - // non ASCII characters - if(printEndLine) - write_tabs(out); - - if(U_FAILURE(*status)){ - uprv_free(buf); - return; - } - - if(bufLen+(tabCount*4) > columnCount ){ - uint32_t len = 0; - char* current = buf; - uint32_t add; - while(len < bufLen){ - add = columnCount-(tabCount*4)-5/* for ", +\n */; - current = buf +len; - if (add < (bufLen-len)) { - uint32_t idx = strrch(current,add,'\\'); - if (idx > add) { - idx = add; - } else { - int32_t num =idx-1; - uint32_t seqLen; - while(num>0){ - if(current[num]=='\\'){ - num--; - }else{ - break; - } - } - if ((idx-num)%2==0) { - idx--; - } - seqLen = (current[idx+1]=='u') ? 6 : 2; - if ((add-idx) < seqLen) { - add = idx + seqLen; - } - } - } - T_FileStream_write(out,"\"",1); - uint32_t byteIndex = 0; - uint32_t trailBytes = 0; - if(len+add<bufLen){ - // check the trail bytes to be added to the output line - while (byteIndex < add) { - if (U8_IS_LEAD(*(current + byteIndex))) { - trailBytes = U8_COUNT_TRAIL_BYTES(*(current + byteIndex)); - add += trailBytes; - } - byteIndex++; - } - T_FileStream_write(out,current,add); - if (len + add < bufLen) { - T_FileStream_write(out,"\" +\n",4); - write_tabs(out); - } - }else{ - T_FileStream_write(out,current,bufLen-len); - } - len+=add; - } - }else{ - T_FileStream_write(out,"\"",1); - T_FileStream_write(out, buf,bufLen); - } - if(printEndLine){ - T_FileStream_write(out,"\",\n",3); - }else{ - T_FileStream_write(out,"\"",1); - } - uprv_free(buf); -} - -/* Writing Functions */ -static void -string_write_java(const StringResource *res,UErrorCode *status) { - (void)res->getKeyString(srBundle); - - str_write_java(res->getBuffer(), res->length(), TRUE, status); -} - -static void -array_write_java(const ArrayResource *res, UErrorCode *status) { - - uint32_t i = 0; - const char* arr ="new String[] { \n"; - struct SResource *current = NULL; - UBool allStrings = TRUE; - - if (U_FAILURE(*status)) { - return; - } - - if (res->fCount > 0) { - - current = res->fFirst; - i = 0; - while(current != NULL){ - if(!current->isString()){ - allStrings = FALSE; - break; - } - current= current->fNext; - } - - current = res->fFirst; - if(allStrings==FALSE){ - const char* object = "new Object[]{\n"; - write_tabs(out); - T_FileStream_write(out, object, (int32_t)uprv_strlen(object)); - tabCount++; - }else{ - write_tabs(out); - T_FileStream_write(out, arr, (int32_t)uprv_strlen(arr)); - tabCount++; - } - while (current != NULL) { - /*if(current->isString()){ - write_tabs(out); - }*/ - res_write_java(current, status); - if(U_FAILURE(*status)){ - return; - } - i++; - current = current->fNext; - } - T_FileStream_write(out,"\n",1); - - tabCount--; - write_tabs(out); - T_FileStream_write(out,"},\n",3); - - } else { - write_tabs(out); - T_FileStream_write(out,arr,(int32_t)uprv_strlen(arr)); - write_tabs(out); - T_FileStream_write(out,"},\n",3); - } -} - -static void -intvector_write_java(const IntVectorResource *res, UErrorCode * /*status*/) { - uint32_t i = 0; - const char* intArr = "new int[] {\n"; - /* const char* intC = "new Integer("; */ - const char* stringArr = "new String[]{\n"; - const char *resname = res->getKeyString(srBundle); - char buf[100]; - int len =0; - buf[0]=0; - write_tabs(out); - - if(resname != NULL && uprv_strcmp(resname,"DateTimeElements")==0){ - T_FileStream_write(out, stringArr, (int32_t)uprv_strlen(stringArr)); - tabCount++; - for(i = 0; i<res->fCount; i++) { - write_tabs(out); - len=itostr(buf,res->fArray[i],10,0); - T_FileStream_write(out,"\"",1); - T_FileStream_write(out,buf,len); - T_FileStream_write(out,"\",",2); - T_FileStream_write(out,"\n",1); - } - }else{ - T_FileStream_write(out, intArr, (int32_t)uprv_strlen(intArr)); - tabCount++; - for(i = 0; i<res->fCount; i++) { - write_tabs(out); - /* T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC)); */ - len=itostr(buf,res->fArray[i],10,0); - T_FileStream_write(out,buf,len); - /* T_FileStream_write(out,"),",2); */ - /* T_FileStream_write(out,"\n",1); */ - T_FileStream_write(out,",\n",2); - } - } - tabCount--; - write_tabs(out); - T_FileStream_write(out,"},\n",3); -} - -static void -int_write_java(const IntResource *res, UErrorCode * /*status*/) { - const char* intC = "new Integer("; - char buf[100]; - int len =0; - buf[0]=0; - - /* write the binary data */ - write_tabs(out); - T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC)); - len=itostr(buf, res->fValue, 10, 0); - T_FileStream_write(out,buf,len); - T_FileStream_write(out,"),\n",3 ); - -} - -static void -bytes_write_java(const BinaryResource *res, UErrorCode * /*status*/) { - const char* type = "new byte[] {"; - const char* byteDecl = "%i, "; - char byteBuffer[100] = { 0 }; - uint8_t* byteArray = NULL; - int byteIterator = 0; - int32_t srcLen=res->fLength; - if(srcLen>0 ) - { - byteArray = res->fData; - - write_tabs(out); - T_FileStream_write(out, type, (int32_t)uprv_strlen(type)); - T_FileStream_write(out, "\n", 1); - tabCount++; - - for (;byteIterator<srcLen;byteIterator++) - { - if (byteIterator%16 == 0) - { - write_tabs(out); - } - - if (byteArray[byteIterator] < 128) - { - sprintf(byteBuffer, byteDecl, byteArray[byteIterator]); - } - else - { - sprintf(byteBuffer, byteDecl, (byteArray[byteIterator]-256)); - } - - T_FileStream_write(out, byteBuffer, (int32_t)uprv_strlen(byteBuffer)); - - if (byteIterator%16 == 15) - { - T_FileStream_write(out, "\n", 1); - } - - } - - if (((byteIterator-1)%16) != 15) - { - T_FileStream_write(out, "\n", 1); - } - - tabCount--; - write_tabs(out); - T_FileStream_write(out, "},\n", 3); - - } - else - { - /* Empty array */ - write_tabs(out); - T_FileStream_write(out,type,(int32_t)uprv_strlen(type)); - T_FileStream_write(out,"},\n",3); - } - -} - -static UBool start = TRUE; - -static void -table_write_java(const TableResource *res, UErrorCode *status) { - uint32_t i = 0; - struct SResource *current = NULL; - const char* obj = "new Object[][]{\n"; - - if (U_FAILURE(*status)) { - return ; - } - - if (res->fCount > 0) { - if(start==FALSE){ - write_tabs(out); - T_FileStream_write(out, obj, (int32_t)uprv_strlen(obj)); - tabCount++; - } - start = FALSE; - current = res->fFirst; - i = 0; - - - while (current != NULL) { - const char *currentKeyString = current->getKeyString(srBundle); - - assert(i < res->fCount); - write_tabs(out); - - T_FileStream_write(out, openBrace, 2); - - - tabCount++; - - write_tabs(out); - if(currentKeyString != NULL) { - T_FileStream_write(out, "\"", 1); - T_FileStream_write(out, currentKeyString, - (int32_t)uprv_strlen(currentKeyString)); - T_FileStream_write(out, "\",\n", 2); - - T_FileStream_write(out, "\n", 1); - } - res_write_java(current, status); - if(U_FAILURE(*status)){ - return; - } - i++; - current = current->fNext; - tabCount--; - write_tabs(out); - T_FileStream_write(out, "},\n", 3); - } - if(tabCount>4){ - tabCount--; - write_tabs(out); - T_FileStream_write(out, "},\n", 3); - } - - } else { - write_tabs(out); - T_FileStream_write(out,obj,(int32_t)uprv_strlen(obj)); - - write_tabs(out); - T_FileStream_write(out,"},\n",3); - - } - -} - -void -res_write_java(struct SResource *res,UErrorCode *status) { - - if (U_FAILURE(*status)) { - return ; - } - - if (res != NULL) { - switch (res->fType) { - case URES_STRING: - string_write_java (static_cast<const StringResource *>(res), status); - return; - case URES_ALIAS: - printf("Encountered unsupported resource type %d of alias\n", res->fType); - *status = U_UNSUPPORTED_ERROR; - return; - case URES_INT_VECTOR: - intvector_write_java (static_cast<const IntVectorResource *>(res), status); - return; - case URES_BINARY: - bytes_write_java (static_cast<const BinaryResource *>(res), status); - return; - case URES_INT: - int_write_java (static_cast<const IntResource *>(res), status); - return; - case URES_ARRAY: - array_write_java (static_cast<const ArrayResource *>(res), status); - return; - case URES_TABLE: - table_write_java (static_cast<const TableResource *>(res), status); - return; - default: - break; - } - } - - *status = U_INTERNAL_PROGRAM_ERROR; -} - -void -bundle_write_java(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc, - char *writtenFilename, int writtenFilenameLen, - const char* packageName, const char* bundleName, - UErrorCode *status) { - - char fileName[256] = {'\0'}; - char className[256]={'\0'}; - /*char constructor[1000] = { 0 };*/ - /*UBool j1 =FALSE;*/ - /*outDir = outputDir;*/ - - start = TRUE; /* Reset the start indictor*/ - - bName = (bundleName==NULL) ? "LocaleElements" : bundleName; - pName = (packageName==NULL)? "com.ibm.icu.impl.data" : packageName; - - uprv_strcpy(className, bName); - srBundle = bundle; - if(uprv_strcmp(srBundle->fLocale,"root")!=0){ - uprv_strcat(className,"_"); - uprv_strcat(className,srBundle->fLocale); - } - if(outputDir){ - uprv_strcpy(fileName, outputDir); - if(outputDir[uprv_strlen(outputDir)-1] !=U_FILE_SEP_CHAR){ - uprv_strcat(fileName,U_FILE_SEP_STRING); - } - uprv_strcat(fileName,className); - uprv_strcat(fileName,".java"); - }else{ - uprv_strcat(fileName,className); - uprv_strcat(fileName,".java"); - } - - if (writtenFilename) { - uprv_strncpy(writtenFilename, fileName, writtenFilenameLen); - } - - if (U_FAILURE(*status)) { - return; - } - - out= T_FileStream_open(fileName,"w"); - - if(out==NULL){ - *status = U_FILE_ACCESS_ERROR; - return; - } - if(getIncludeCopyright()){ - T_FileStream_write(out, copyRight, (int32_t)uprv_strlen(copyRight)); - T_FileStream_write(out, warningMsg, (int32_t)uprv_strlen(warningMsg)); - } - T_FileStream_write(out,"package ",(int32_t)uprv_strlen("package ")); - T_FileStream_write(out,pName,(int32_t)uprv_strlen(pName)); - T_FileStream_write(out,";\n\n",3); - T_FileStream_write(out, javaClass, (int32_t)uprv_strlen(javaClass)); - T_FileStream_write(out, className, (int32_t)uprv_strlen(className)); - T_FileStream_write(out, javaClass1, (int32_t)uprv_strlen(javaClass1)); - - /* if(j1){ - T_FileStream_write(out, javaClass1, (int32_t)uprv_strlen(javaClass1)); - }else{ - sprintf(constructor,javaClassICU,className); - T_FileStream_write(out, constructor, (int32_t)uprv_strlen(constructor)); - } - */ - - if(outputEnc && *outputEnc!='\0'){ - /* store the output encoding */ - enc = outputEnc; - conv=ucnv_open(enc,status); - if(U_FAILURE(*status)){ - return; - } - } - res_write_java(bundle->fRoot, status); - - T_FileStream_write(out, closeClass, (int32_t)uprv_strlen(closeClass)); - - T_FileStream_close(out); - - ucnv_close(conv); -} diff --git a/deps/node/deps/icu-small/source/tools/genrb/wrtxml.cpp b/deps/node/deps/icu-small/source/tools/genrb/wrtxml.cpp deleted file mode 100644 index 58e055d5..00000000 --- a/deps/node/deps/icu-small/source/tools/genrb/wrtxml.cpp +++ /dev/null @@ -1,1217 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2002-2015, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File wrtxml.cpp -* -* Modification History: -* -* Date Name Description -* 10/01/02 Ram Creation. -* 02/07/08 Spieth Correct XLIFF generation on EBCDIC platform -* -******************************************************************************* -*/ - -// Safer use of UnicodeString. -#ifndef UNISTR_FROM_CHAR_EXPLICIT -# define UNISTR_FROM_CHAR_EXPLICIT explicit -#endif - -// Less important, but still a good idea. -#ifndef UNISTR_FROM_STRING_EXPLICIT -# define UNISTR_FROM_STRING_EXPLICIT explicit -#endif - -#include "reslist.h" -#include "unewdata.h" -#include "unicode/ures.h" -#include "errmsg.h" -#include "filestrm.h" -#include "cstring.h" -#include "unicode/ucnv.h" -#include "genrb.h" -#include "rle.h" -#include "uhash.h" -#include "uresimp.h" -#include "unicode/ustring.h" -#include "unicode/uchar.h" -#include "ustr.h" -#include "prscmnts.h" -#include "unicode/unistr.h" -#include "unicode/utf8.h" -#include "unicode/utf16.h" -#include <time.h> - -U_NAMESPACE_USE - -static int tabCount = 0; - -static FileStream* out=NULL; -static struct SRBRoot* srBundle ; -static const char* outDir = NULL; -static const char* enc =""; -static UConverter* conv = NULL; - -const char* const* ISOLanguages; -const char* const* ISOCountries; -const char* textExt = ".txt"; -const char* xliffExt = ".xlf"; - -static int32_t write_utf8_file(FileStream* fileStream, UnicodeString outString) -{ - UErrorCode status = U_ZERO_ERROR; - int32_t len = 0; - - // preflight to get the destination buffer size - u_strToUTF8(NULL, - 0, - &len, - toUCharPtr(outString.getBuffer()), - outString.length(), - &status); - - // allocate the buffer - char* dest = (char*)uprv_malloc(len); - status = U_ZERO_ERROR; - - // convert the data - u_strToUTF8(dest, - len, - &len, - toUCharPtr(outString.getBuffer()), - outString.length(), - &status); - - // write data to out file - int32_t ret = T_FileStream_write(fileStream, dest, len); - uprv_free(dest); - return (ret); -} - -/*write indentation for formatting*/ -static void write_tabs(FileStream* os){ - int i=0; - for(;i<=tabCount;i++){ - write_utf8_file(os,UnicodeString(" ")); - } -} - -/*get ID for each element. ID is globally unique.*/ -static char* getID(const char* id, const char* curKey, char* result) { - if(curKey == NULL) { - result = (char *)uprv_malloc(sizeof(char)*uprv_strlen(id) + 1); - uprv_memset(result, 0, sizeof(char)*uprv_strlen(id) + 1); - uprv_strcpy(result, id); - } else { - result = (char *)uprv_malloc(sizeof(char)*(uprv_strlen(id) + 1 + uprv_strlen(curKey)) + 1); - uprv_memset(result, 0, sizeof(char)*(uprv_strlen(id) + 1 + uprv_strlen(curKey)) + 1); - if(id[0]!='\0'){ - uprv_strcpy(result, id); - uprv_strcat(result, "_"); - } - uprv_strcat(result, curKey); - } - return result; -} - -/*compute CRC for binary code*/ -/* The code is from http://www.theorem.com/java/CRC32.java - * Calculates the CRC32 - 32 bit Cyclical Redundancy Check - * <P> This check is used in numerous systems to verify the integrity - * of information. It's also used as a hashing function. Unlike a regular - * checksum, it's sensitive to the order of the characters. - * It produces a 32 bit - * - * @author Michael Lecuyer (mjl@theorem.com) - * @version 1.1 August 11, 1998 - */ - -/* ICU is not endian portable, because ICU data generated on big endian machines can be - * ported to big endian machines but not to little endian machines and vice versa. The - * conversion is not portable across platforms with different endianess. - */ - -uint32_t computeCRC(const char *ptr, uint32_t len, uint32_t lastcrc){ - int32_t crc; - uint32_t temp1; - uint32_t temp2; - - int32_t crc_ta[256]; - int i = 0; - int j = 0; - uint32_t crc2 = 0; - -#define CRC32_POLYNOMIAL 0xEDB88320 - - /*build crc table*/ - for (i = 0; i <= 255; i++) { - crc2 = i; - for (j = 8; j > 0; j--) { - if ((crc2 & 1) == 1) { - crc2 = (crc2 >> 1) ^ CRC32_POLYNOMIAL; - } else { - crc2 >>= 1; - } - } - crc_ta[i] = crc2; - } - - crc = lastcrc; - while(len--!=0) { - temp1 = (uint32_t)crc>>8; - temp2 = crc_ta[(crc^*ptr) & 0xFF]; - crc = temp1^temp2; - ptr++; - } - return(crc); -} - -static void strnrepchr(char* src, int32_t srcLen, char s, char r){ - int32_t i = 0; - for(i=0;i<srcLen;i++){ - if(src[i]==s){ - src[i]=r; - } - } -} -/* Parse the filename, and get its language information. - * If it fails to get the language information from the filename, - * use "en" as the default value for language - */ -static char* parseFilename(const char* id, char* /*lang*/) { - int idLen = (int) uprv_strlen(id); - char* localeID = (char*) uprv_malloc(idLen); - int pos = 0; - int canonCapacity = 0; - char* canon = NULL; - int canonLen = 0; - /*int i;*/ - UErrorCode status = U_ZERO_ERROR; - const char *ext = uprv_strchr(id, '.'); - - if(ext != NULL){ - pos = (int) (ext - id); - } else { - pos = idLen; - } - uprv_memcpy(localeID, id, pos); - localeID[pos]=0; /* NUL terminate the string */ - - canonCapacity =pos*3; - canon = (char*) uprv_malloc(canonCapacity); - canonLen = uloc_canonicalize(localeID, canon, canonCapacity, &status); - - if(U_FAILURE(status)){ - fprintf(stderr, "Could not canonicalize the locale ID: %s. Error: %s\n", localeID, u_errorName(status)); - exit(status); - } - strnrepchr(canon, canonLen, '_', '-'); - return canon; -} - -static const char* xmlHeader = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; -#if 0 -static const char* bundleStart = "<xliff version = \"1.2\" " - "xmlns='urn:oasis:names:tc:xliff:document:1.2' " - "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " - "xsi:schemaLocation='urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd'>\n"; -#else -static const char* bundleStart = "<xliff version = \"1.1\" " - "xmlns='urn:oasis:names:tc:xliff:document:1.1' " - "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " - "xsi:schemaLocation='urn:oasis:names:tc:xliff:document:1.1 http://www.oasis-open.org/committees/xliff/documents/xliff-core-1.1.xsd'>\n"; -#endif -static const char* bundleEnd = "</xliff>\n"; - -void res_write_xml(struct SResource *res, const char* id, const char* language, UBool isTopLevel, UErrorCode *status); - -static char* convertAndEscape(char** pDest, int32_t destCap, int32_t* destLength, - const UChar* src, int32_t srcLen, UErrorCode* status){ - int32_t srcIndex=0; - char* dest=NULL; - char* temp=NULL; - int32_t destLen=0; - UChar32 c = 0; - - if(status==NULL || U_FAILURE(*status) || pDest==NULL || srcLen==0 || src == NULL){ - return NULL; - } - dest =*pDest; - if(dest==NULL || destCap <=0){ - destCap = srcLen * 8; - dest = (char*) uprv_malloc(sizeof(char) * destCap); - if(dest==NULL){ - *status=U_MEMORY_ALLOCATION_ERROR; - return NULL; - } - } - - dest[0]=0; - - while(srcIndex<srcLen){ - U16_NEXT(src, srcIndex, srcLen, c); - - if (U16_IS_LEAD(c) || U16_IS_TRAIL(c)) { - *status = U_ILLEGAL_CHAR_FOUND; - fprintf(stderr, "Illegal Surrogate! \n"); - uprv_free(dest); - return NULL; - } - - if((destLen+U8_LENGTH(c)) < destCap){ - - /* ASCII Range */ - if(c <=0x007F){ - switch(c) { - case '\x26': - uprv_strcpy(dest+( destLen),"\x26\x61\x6d\x70\x3b"); /* &*/ - destLen+=(int32_t)uprv_strlen("\x26\x61\x6d\x70\x3b"); - break; - case '\x3c': - uprv_strcpy(dest+(destLen),"\x26\x6c\x74\x3b"); /* <*/ - destLen+=(int32_t)uprv_strlen("\x26\x6c\x74\x3b"); - break; - case '\x3e': - uprv_strcpy(dest+(destLen),"\x26\x67\x74\x3b"); /* >*/ - destLen+=(int32_t)uprv_strlen("\x26\x67\x74\x3b"); - break; - case '\x22': - uprv_strcpy(dest+(destLen),"\x26\x71\x75\x6f\x74\x3b"); /* "*/ - destLen+=(int32_t)uprv_strlen("\x26\x71\x75\x6f\x74\x3b"); - break; - case '\x27': - uprv_strcpy(dest+(destLen),"\x26\x61\x70\x6f\x73\x3b"); /* ' */ - destLen+=(int32_t)uprv_strlen("\x26\x61\x70\x6f\x73\x3b"); - break; - - /* Disallow C0 controls except TAB, CR, LF*/ - case 0x00: - case 0x01: - case 0x02: - case 0x03: - case 0x04: - case 0x05: - case 0x06: - case 0x07: - case 0x08: - /*case 0x09:*/ - /*case 0x0A: */ - case 0x0B: - case 0x0C: - /*case 0x0D:*/ - case 0x0E: - case 0x0F: - case 0x10: - case 0x11: - case 0x12: - case 0x13: - case 0x14: - case 0x15: - case 0x16: - case 0x17: - case 0x18: - case 0x19: - case 0x1A: - case 0x1B: - case 0x1C: - case 0x1D: - case 0x1E: - case 0x1F: - *status = U_ILLEGAL_CHAR_FOUND; - fprintf(stderr, "Illegal Character \\u%04X!\n",(int)c); - uprv_free(dest); - return NULL; - default: - dest[destLen++]=(char)c; - } - }else{ - UBool isError = FALSE; - U8_APPEND((unsigned char*)dest,destLen,destCap,c,isError); - if(isError){ - *status = U_ILLEGAL_CHAR_FOUND; - fprintf(stderr, "Illegal Character \\U%08X!\n",(int)c); - uprv_free(dest); - return NULL; - } - } - }else{ - destCap += destLen; - - temp = (char*) uprv_malloc(sizeof(char)*destCap); - if(temp==NULL){ - *status=U_MEMORY_ALLOCATION_ERROR; - uprv_free(dest); - return NULL; - } - uprv_memmove(temp,dest,destLen); - destLen=0; - uprv_free(dest); - dest=temp; - temp=NULL; - } - - } - *destLength = destLen; - return dest; -} - -#define ASTERISK 0x002A -#define SPACE 0x0020 -#define CR 0x000A -#define LF 0x000D -#define AT_SIGN 0x0040 - -#if UCONFIG_NO_REGULAR_EXPRESSIONS==0 -static void -trim(char **src, int32_t *len){ - - char *s = NULL; - int32_t i = 0; - if(src == NULL || *src == NULL){ - return; - } - s = *src; - /* trim from the end */ - for( i=(*len-1); i>= 0; i--){ - switch(s[i]){ - case ASTERISK: - case SPACE: - case CR: - case LF: - s[i] = 0; - continue; - default: - break; - } - break; - - } - *len = i+1; -} - -static void -print(UChar* src, int32_t srcLen,const char *tagStart,const char *tagEnd, UErrorCode *status){ - int32_t bufCapacity = srcLen*4; - char *buf = NULL; - int32_t bufLen = 0; - - if(U_FAILURE(*status)){ - return; - } - - buf = (char*) (uprv_malloc(bufCapacity)); - if(buf==0){ - fprintf(stderr, "Could not allocate memory!!"); - exit(U_MEMORY_ALLOCATION_ERROR); - } - buf = convertAndEscape(&buf, bufCapacity, &bufLen, src, srcLen,status); - if(U_SUCCESS(*status)){ - trim(&buf,&bufLen); - write_utf8_file(out,UnicodeString(tagStart)); - write_utf8_file(out,UnicodeString(buf, bufLen, "UTF-8")); - write_utf8_file(out,UnicodeString(tagEnd)); - write_utf8_file(out,UnicodeString("\n")); - - } -} -#endif - -static void -printNoteElements(const UString *src, UErrorCode *status){ - -#if UCONFIG_NO_REGULAR_EXPRESSIONS==0 /* donot compile when no RegularExpressions are available */ - - int32_t capacity = 0; - UChar* note = NULL; - int32_t noteLen = 0; - int32_t count = 0,i; - - if(src == NULL){ - return; - } - - capacity = src->fLength; - note = (UChar*) uprv_malloc(U_SIZEOF_UCHAR * capacity); - - count = getCount(src->fChars,src->fLength, UPC_NOTE, status); - if(U_FAILURE(*status)){ - uprv_free(note); - return; - } - for(i=0; i < count; i++){ - noteLen = getAt(src->fChars,src->fLength, ¬e, capacity, i, UPC_NOTE, status); - if(U_FAILURE(*status)){ - uprv_free(note); - return; - } - if(noteLen > 0){ - write_tabs(out); - print(note, noteLen,"<note>", "</note>", status); - } - } - uprv_free(note); -#else - - fprintf(stderr, "Warning: Could not output comments to XLIFF file. ICU has been built without RegularExpression support.\n"); - -#endif /* UCONFIG_NO_REGULAR_EXPRESSIONS */ - -} - -static void printAttribute(const char *name, const char *value, int32_t /*len*/) -{ - write_utf8_file(out, UnicodeString(" ")); - write_utf8_file(out, UnicodeString(name)); - write_utf8_file(out, UnicodeString(" = \"")); - write_utf8_file(out, UnicodeString(value)); - write_utf8_file(out, UnicodeString("\"")); -} - -#if UCONFIG_NO_REGULAR_EXPRESSIONS==0 /* donot compile when no RegularExpressions are available */ -static void printAttribute(const char *name, const UnicodeString value, int32_t /*len*/) -{ - write_utf8_file(out, UnicodeString(" ")); - write_utf8_file(out, UnicodeString(name)); - write_utf8_file(out, UnicodeString(" = \"")); - write_utf8_file(out, value); - write_utf8_file(out, UnicodeString("\"")); -} -#endif - -static void -printComments(struct UString *src, const char *resName, UBool printTranslate, UErrorCode *status){ - -#if UCONFIG_NO_REGULAR_EXPRESSIONS==0 /* donot compile when no RegularExpressions are available */ - - if(status==NULL || U_FAILURE(*status)){ - return; - } - - int32_t capacity = src->fLength + 1; - char* buf = NULL; - int32_t bufLen = 0; - UChar* desc = (UChar*) uprv_malloc(U_SIZEOF_UCHAR * capacity); - UChar* trans = (UChar*) uprv_malloc(U_SIZEOF_UCHAR * capacity); - - int32_t descLen = 0, transLen=0; - if(desc==NULL || trans==NULL){ - *status = U_MEMORY_ALLOCATION_ERROR; - uprv_free(desc); - uprv_free(trans); - return; - } - // TODO: make src const, stop modifying it in-place, make printContainer() take const resource, etc. - src->fLength = removeCmtText(src->fChars, src->fLength, status); - descLen = getDescription(src->fChars,src->fLength, &desc, capacity, status); - transLen = getTranslate(src->fChars,src->fLength, &trans, capacity, status); - - /* first print translate attribute */ - if(transLen > 0){ - if(printTranslate){ - /* print translate attribute */ - buf = convertAndEscape(&buf, 0, &bufLen, trans, transLen, status); - if(U_SUCCESS(*status)){ - printAttribute("translate", UnicodeString(buf, bufLen, "UTF-8"), bufLen); - write_utf8_file(out,UnicodeString(">\n")); - } - }else if(getShowWarning()){ - fprintf(stderr, "Warning: Tranlate attribute for resource %s cannot be set. XLIFF prohibits it.\n", resName); - /* no translate attribute .. just close the tag */ - write_utf8_file(out,UnicodeString(">\n")); - } - }else{ - /* no translate attribute .. just close the tag */ - write_utf8_file(out,UnicodeString(">\n")); - } - - if(descLen > 0){ - write_tabs(out); - print(desc, descLen, "<!--", "-->", status); - } - - uprv_free(desc); - uprv_free(trans); -#else - - fprintf(stderr, "Warning: Could not output comments to XLIFF file. ICU has been built without RegularExpression support.\n"); - -#endif /* UCONFIG_NO_REGULAR_EXPRESSIONS */ - -} - -/* - * Print out a containing element, like: - * <trans-unit id = "blah" resname = "blah" restype = "x-id-alias" translate = "no"> - * <group id "calendar_gregorian" resname = "gregorian" restype = "x-icu-array"> - */ -static char *printContainer(SResource *res, const char *container, const char *restype, const char *mimetype, const char *id, UErrorCode *status) -{ - const char *resname = NULL; - char *sid = NULL; - - write_tabs(out); - - resname = res->getKeyString(srBundle); - if (resname != NULL && *resname != 0) { - sid = getID(id, resname, sid); - } else { - sid = getID(id, NULL, sid); - } - - write_utf8_file(out, UnicodeString("<")); - write_utf8_file(out, UnicodeString(container)); - printAttribute("id", sid, (int32_t) uprv_strlen(sid)); - - if (resname != NULL) { - printAttribute("resname", resname, (int32_t) uprv_strlen(resname)); - } - - if (mimetype != NULL) { - printAttribute("mime-type", mimetype, (int32_t) uprv_strlen(mimetype)); - } - - if (restype != NULL) { - printAttribute("restype", restype, (int32_t) uprv_strlen(restype)); - } - - tabCount += 1; - if (res->fComment.fLength > 0) { - /* printComments will print the closing ">\n" */ - printComments(&res->fComment, resname, TRUE, status); - } else { - write_utf8_file(out, UnicodeString(">\n")); - } - - return sid; -} - -/* Writing Functions */ - -static const char *trans_unit = "trans-unit"; -static const char *close_trans_unit = "</trans-unit>\n"; -static const char *source = "<source>"; -static const char *close_source = "</source>\n"; -static const char *group = "group"; -static const char *close_group = "</group>\n"; - -static const char *bin_unit = "bin-unit"; -static const char *close_bin_unit = "</bin-unit>\n"; -static const char *bin_source = "<bin-source>\n"; -static const char *close_bin_source = "</bin-source>\n"; -static const char *external_file = "<external-file"; -/*static const char *close_external_file = "</external-file>\n";*/ -static const char *internal_file = "<internal-file"; -static const char *close_internal_file = "</internal-file>\n"; - -static const char *application_mimetype = "application"; /* add "/octet-stream"? */ - -static const char *alias_restype = "x-icu-alias"; -static const char *array_restype = "x-icu-array"; -static const char *binary_restype = "x-icu-binary"; -static const char *integer_restype = "x-icu-integer"; -static const char *intvector_restype = "x-icu-intvector"; -static const char *table_restype = "x-icu-table"; - -static void -string_write_xml(StringResource *res, const char* id, const char* /*language*/, UErrorCode *status) { - - char *sid = NULL; - char* buf = NULL; - int32_t bufLen = 0; - - if(status==NULL || U_FAILURE(*status)){ - return; - } - - sid = printContainer(res, trans_unit, NULL, NULL, id, status); - - write_tabs(out); - - write_utf8_file(out, UnicodeString(source)); - - buf = convertAndEscape(&buf, 0, &bufLen, res->getBuffer(), res->length(), status); - - if (U_FAILURE(*status)) { - return; - } - - write_utf8_file(out, UnicodeString(buf, bufLen, "UTF-8")); - write_utf8_file(out, UnicodeString(close_source)); - - printNoteElements(&res->fComment, status); - - tabCount -= 1; - write_tabs(out); - - write_utf8_file(out, UnicodeString(close_trans_unit)); - - uprv_free(buf); - uprv_free(sid); -} - -static void -alias_write_xml(AliasResource *res, const char* id, const char* /*language*/, UErrorCode *status) { - char *sid = NULL; - char* buf = NULL; - int32_t bufLen=0; - - sid = printContainer(res, trans_unit, alias_restype, NULL, id, status); - - write_tabs(out); - - write_utf8_file(out, UnicodeString(source)); - - buf = convertAndEscape(&buf, 0, &bufLen, res->getBuffer(), res->length(), status); - - if(U_FAILURE(*status)){ - return; - } - write_utf8_file(out, UnicodeString(buf, bufLen, "UTF-8")); - write_utf8_file(out, UnicodeString(close_source)); - - printNoteElements(&res->fComment, status); - - tabCount -= 1; - write_tabs(out); - - write_utf8_file(out, UnicodeString(close_trans_unit)); - - uprv_free(buf); - uprv_free(sid); -} - -static void -array_write_xml(ArrayResource *res, const char* id, const char* language, UErrorCode *status) { - char* sid = NULL; - int index = 0; - - struct SResource *current = NULL; - - sid = printContainer(res, group, array_restype, NULL, id, status); - - current = res->fFirst; - - while (current != NULL) { - char c[256] = {0}; - char* subId = NULL; - - itostr(c, index, 10, 0); - index += 1; - subId = getID(sid, c, subId); - - res_write_xml(current, subId, language, FALSE, status); - uprv_free(subId); - subId = NULL; - - if(U_FAILURE(*status)){ - return; - } - - current = current->fNext; - } - - tabCount -= 1; - write_tabs(out); - write_utf8_file(out, UnicodeString(close_group)); - - uprv_free(sid); -} - -static void -intvector_write_xml(IntVectorResource *res, const char* id, const char* /*language*/, UErrorCode *status) { - char* sid = NULL; - char* ivd = NULL; - uint32_t i=0; - uint32_t len=0; - char buf[256] = {'0'}; - - sid = printContainer(res, group, intvector_restype, NULL, id, status); - - for(i = 0; i < res->fCount; i += 1) { - char c[256] = {0}; - - itostr(c, i, 10, 0); - ivd = getID(sid, c, ivd); - len = itostr(buf, res->fArray[i], 10, 0); - - write_tabs(out); - write_utf8_file(out, UnicodeString("<")); - write_utf8_file(out, UnicodeString(trans_unit)); - - printAttribute("id", ivd, (int32_t)uprv_strlen(ivd)); - printAttribute("restype", integer_restype, (int32_t) strlen(integer_restype)); - - write_utf8_file(out, UnicodeString(">\n")); - - tabCount += 1; - write_tabs(out); - write_utf8_file(out, UnicodeString(source)); - - write_utf8_file(out, UnicodeString(buf, len)); - - write_utf8_file(out, UnicodeString(close_source)); - tabCount -= 1; - write_tabs(out); - write_utf8_file(out, UnicodeString(close_trans_unit)); - - uprv_free(ivd); - ivd = NULL; - } - - tabCount -= 1; - write_tabs(out); - - write_utf8_file(out, UnicodeString(close_group)); - uprv_free(sid); - sid = NULL; -} - -static void -int_write_xml(IntResource *res, const char* id, const char* /*language*/, UErrorCode *status) { - char* sid = NULL; - char buf[256] = {0}; - uint32_t len = 0; - - sid = printContainer(res, trans_unit, integer_restype, NULL, id, status); - - write_tabs(out); - - write_utf8_file(out, UnicodeString(source)); - - len = itostr(buf, res->fValue, 10, 0); - write_utf8_file(out, UnicodeString(buf, len)); - - write_utf8_file(out, UnicodeString(close_source)); - - printNoteElements(&res->fComment, status); - - tabCount -= 1; - write_tabs(out); - - write_utf8_file(out, UnicodeString(close_trans_unit)); - - uprv_free(sid); - sid = NULL; -} - -static void -bin_write_xml(BinaryResource *res, const char* id, const char* /*language*/, UErrorCode *status) { - const char* m_type = application_mimetype; - char* sid = NULL; - uint32_t crc = 0xFFFFFFFF; - - char fileName[1024] ={0}; - int32_t tLen = ( outDir == NULL) ? 0 :(int32_t)uprv_strlen(outDir); - char* fn = (char*) uprv_malloc(sizeof(char) * (tLen+1024 + - (res->fFileName !=NULL ? - uprv_strlen(res->fFileName) :0))); - const char* ext = NULL; - - char* f = NULL; - - fn[0]=0; - - if(res->fFileName != NULL){ - uprv_strcpy(fileName, res->fFileName); - f = uprv_strrchr(fileName, '\\'); - - if (f != NULL) { - f++; - } else { - f = fileName; - } - - ext = uprv_strrchr(fileName, '.'); - - if (ext == NULL) { - fprintf(stderr, "Error: %s is an unknown binary filename type.\n", fileName); - exit(U_ILLEGAL_ARGUMENT_ERROR); - } - - if(uprv_strcmp(ext, ".jpg")==0 || uprv_strcmp(ext, ".jpeg")==0 || uprv_strcmp(ext, ".gif")==0 ){ - m_type = "image"; - } else if(uprv_strcmp(ext, ".wav")==0 || uprv_strcmp(ext, ".au")==0 ){ - m_type = "audio"; - } else if(uprv_strcmp(ext, ".avi")==0 || uprv_strcmp(ext, ".mpg")==0 || uprv_strcmp(ext, ".mpeg")==0){ - m_type = "video"; - } else if(uprv_strcmp(ext, ".txt")==0 || uprv_strcmp(ext, ".text")==0){ - m_type = "text"; - } - - sid = printContainer(res, bin_unit, binary_restype, m_type, id, status); - - write_tabs(out); - - write_utf8_file(out, UnicodeString(bin_source)); - - tabCount+= 1; - write_tabs(out); - - write_utf8_file(out, UnicodeString(external_file)); - printAttribute("href", f, (int32_t)uprv_strlen(f)); - write_utf8_file(out, UnicodeString("/>\n")); - tabCount -= 1; - write_tabs(out); - - write_utf8_file(out, UnicodeString(close_bin_source)); - - printNoteElements(&res->fComment, status); - tabCount -= 1; - write_tabs(out); - write_utf8_file(out, UnicodeString(close_bin_unit)); - } else { - char temp[256] = {0}; - uint32_t i = 0; - int32_t len=0; - - sid = printContainer(res, bin_unit, binary_restype, m_type, id, status); - - write_tabs(out); - write_utf8_file(out, UnicodeString(bin_source)); - - tabCount += 1; - write_tabs(out); - - write_utf8_file(out, UnicodeString(internal_file)); - printAttribute("form", application_mimetype, (int32_t) uprv_strlen(application_mimetype)); - - while(i <res->fLength){ - len = itostr(temp, res->fData[i], 16, 2); - crc = computeCRC(temp, len, crc); - i++; - } - - len = itostr(temp, crc, 10, 0); - printAttribute("crc", temp, len); - - write_utf8_file(out, UnicodeString(">")); - - i = 0; - while(i <res->fLength){ - len = itostr(temp, res->fData[i], 16, 2); - write_utf8_file(out, UnicodeString(temp)); - i += 1; - } - - write_utf8_file(out, UnicodeString(close_internal_file)); - - tabCount -= 2; - write_tabs(out); - - write_utf8_file(out, UnicodeString(close_bin_source)); - printNoteElements(&res->fComment, status); - - tabCount -= 1; - write_tabs(out); - write_utf8_file(out, UnicodeString(close_bin_unit)); - - uprv_free(sid); - sid = NULL; - } - - uprv_free(fn); -} - - - -static void -table_write_xml(TableResource *res, const char* id, const char* language, UBool isTopLevel, UErrorCode *status) { - - uint32_t i = 0; - - struct SResource *current = NULL; - char* sid = NULL; - - if (U_FAILURE(*status)) { - return ; - } - - sid = printContainer(res, group, table_restype, NULL, id, status); - - if(isTopLevel) { - sid[0] = '\0'; - } - - current = res->fFirst; - i = 0; - - while (current != NULL) { - res_write_xml(current, sid, language, FALSE, status); - - if(U_FAILURE(*status)){ - return; - } - - i += 1; - current = current->fNext; - } - - tabCount -= 1; - write_tabs(out); - - write_utf8_file(out, UnicodeString(close_group)); - - uprv_free(sid); - sid = NULL; -} - -void -res_write_xml(struct SResource *res, const char* id, const char* language, UBool isTopLevel, UErrorCode *status) { - - if (U_FAILURE(*status)) { - return ; - } - - if (res != NULL) { - switch (res->fType) { - case URES_STRING: - string_write_xml (static_cast<StringResource *>(res), id, language, status); - return; - - case URES_ALIAS: - alias_write_xml (static_cast<AliasResource *>(res), id, language, status); - return; - - case URES_INT_VECTOR: - intvector_write_xml (static_cast<IntVectorResource *>(res), id, language, status); - return; - - case URES_BINARY: - bin_write_xml (static_cast<BinaryResource *>(res), id, language, status); - return; - - case URES_INT: - int_write_xml (static_cast<IntResource *>(res), id, language, status); - return; - - case URES_ARRAY: - array_write_xml (static_cast<ArrayResource *>(res), id, language, status); - return; - - case URES_TABLE: - table_write_xml (static_cast<TableResource *>(res), id, language, isTopLevel, status); - return; - - default: - break; - } - } - - *status = U_INTERNAL_PROGRAM_ERROR; -} - -void -bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc, const char* filename, - char *writtenFilename, int writtenFilenameLen, - const char* language, const char* outFileName, UErrorCode *status) { - - char* xmlfileName = NULL; - char* outputFileName = NULL; - char* originalFileName = NULL; - const char* fileStart = "<file xml:space = \"preserve\" source-language = \""; - const char* file1 = "\" datatype = \"x-icu-resource-bundle\" "; - const char* file2 = "original = \""; - const char* file4 = "\" date = \""; - const char* fileEnd = "</file>\n"; - const char* headerStart = "<header>\n"; - const char* headerEnd = "</header>\n"; - const char* bodyStart = "<body>\n"; - const char* bodyEnd = "</body>\n"; - - const char *tool_start = "<tool"; - const char *tool_id = "genrb-" GENRB_VERSION "-icu-" U_ICU_VERSION; - const char *tool_name = "genrb"; - - char* temp = NULL; - char* lang = NULL; - const char* pos = NULL; - int32_t first, index; - time_t currTime; - char timeBuf[128]; - - outDir = outputDir; - - srBundle = bundle; - - pos = uprv_strrchr(filename, '\\'); - if(pos != NULL) { - first = (int32_t)(pos - filename + 1); - } else { - first = 0; - } - index = (int32_t)(uprv_strlen(filename) - uprv_strlen(textExt) - first); - originalFileName = (char *)uprv_malloc(sizeof(char)*index+1); - uprv_memset(originalFileName, 0, sizeof(char)*index+1); - uprv_strncpy(originalFileName, filename + first, index); - - if(uprv_strcmp(originalFileName, srBundle->fLocale) != 0) { - fprintf(stdout, "Warning: The file name is not same as the resource name!\n"); - } - - temp = originalFileName; - originalFileName = (char *)uprv_malloc(sizeof(char)* (uprv_strlen(temp)+uprv_strlen(textExt)) + 1); - uprv_memset(originalFileName, 0, sizeof(char)* (uprv_strlen(temp)+uprv_strlen(textExt)) + 1); - uprv_strcat(originalFileName, temp); - uprv_strcat(originalFileName, textExt); - uprv_free(temp); - temp = NULL; - - - if (language == NULL) { -/* lang = parseFilename(filename, lang); - if (lang == NULL) {*/ - /* now check if locale name is valid or not - * this is to cater for situation where - * pegasusServer.txt contains - * - * en{ - * .. - * } - */ - lang = parseFilename(srBundle->fLocale, lang); - /* - * Neither the file name nor the table name inside the - * txt file contain a valid country and language codes - * throw an error. - * pegasusServer.txt contains - * - * testelements{ - * .... - * } - */ - if(lang==NULL){ - fprintf(stderr, "Error: The file name and table name do not contain a valid language code. Please use -l option to specify it.\n"); - exit(U_ILLEGAL_ARGUMENT_ERROR); - } - /* }*/ - } else { - lang = (char *)uprv_malloc(sizeof(char)*uprv_strlen(language) +1); - uprv_memset(lang, 0, sizeof(char)*uprv_strlen(language) +1); - uprv_strcpy(lang, language); - } - - if(outFileName) { - outputFileName = (char *)uprv_malloc(sizeof(char)*uprv_strlen(outFileName) + 1); - uprv_memset(outputFileName, 0, sizeof(char)*uprv_strlen(outFileName) + 1); - uprv_strcpy(outputFileName,outFileName); - } else { - outputFileName = (char *)uprv_malloc(sizeof(char)*uprv_strlen(srBundle->fLocale) + 1); - uprv_memset(outputFileName, 0, sizeof(char)*uprv_strlen(srBundle->fLocale) + 1); - uprv_strcpy(outputFileName,srBundle->fLocale); - } - - if(outputDir) { - xmlfileName = (char *)uprv_malloc(sizeof(char)*(uprv_strlen(outputDir) + uprv_strlen(outputFileName) + uprv_strlen(xliffExt) + 1) +1); - uprv_memset(xmlfileName, 0, sizeof(char)*(uprv_strlen(outputDir)+ uprv_strlen(outputFileName) + uprv_strlen(xliffExt) + 1) +1); - } else { - xmlfileName = (char *)uprv_malloc(sizeof(char)*(uprv_strlen(outputFileName) + uprv_strlen(xliffExt)) +1); - uprv_memset(xmlfileName, 0, sizeof(char)*(uprv_strlen(outputFileName) + uprv_strlen(xliffExt)) +1); - } - - if(outputDir){ - uprv_strcpy(xmlfileName, outputDir); - if(outputDir[uprv_strlen(outputDir)-1] !=U_FILE_SEP_CHAR){ - uprv_strcat(xmlfileName,U_FILE_SEP_STRING); - } - } - uprv_strcat(xmlfileName,outputFileName); - uprv_strcat(xmlfileName,xliffExt); - - if (writtenFilename) { - uprv_strncpy(writtenFilename, xmlfileName, writtenFilenameLen); - } - - if (U_FAILURE(*status)) { - goto cleanup_bundle_write_xml; - } - - out= T_FileStream_open(xmlfileName,"w"); - - if(out==NULL){ - *status = U_FILE_ACCESS_ERROR; - goto cleanup_bundle_write_xml; - } - write_utf8_file(out, UnicodeString(xmlHeader)); - - if(outputEnc && *outputEnc!='\0'){ - /* store the output encoding */ - enc = outputEnc; - conv=ucnv_open(enc,status); - if(U_FAILURE(*status)){ - goto cleanup_bundle_write_xml; - } - } - write_utf8_file(out, UnicodeString(bundleStart)); - write_tabs(out); - write_utf8_file(out, UnicodeString(fileStart)); - /* check if lang and language are the same */ - if(language != NULL && uprv_strcmp(lang, srBundle->fLocale)!=0){ - fprintf(stderr,"Warning: The top level tag in the resource and language specified are not the same. Please check the input.\n"); - } - write_utf8_file(out, UnicodeString(lang)); - write_utf8_file(out, UnicodeString(file1)); - write_utf8_file(out, UnicodeString(file2)); - write_utf8_file(out, UnicodeString(originalFileName)); - write_utf8_file(out, UnicodeString(file4)); - - time(&currTime); - strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%dT%H:%M:%SZ", gmtime(&currTime)); - write_utf8_file(out, UnicodeString(timeBuf)); - write_utf8_file(out, UnicodeString("\">\n")); - - tabCount += 1; - write_tabs(out); - write_utf8_file(out, UnicodeString(headerStart)); - - tabCount += 1; - write_tabs(out); - - write_utf8_file(out, UnicodeString(tool_start)); - printAttribute("tool-id", tool_id, (int32_t) uprv_strlen(tool_id)); - printAttribute("tool-name", tool_name, (int32_t) uprv_strlen(tool_name)); - write_utf8_file(out, UnicodeString("/>\n")); - - tabCount -= 1; - write_tabs(out); - - write_utf8_file(out, UnicodeString(headerEnd)); - - write_tabs(out); - tabCount += 1; - - write_utf8_file(out, UnicodeString(bodyStart)); - - - res_write_xml(bundle->fRoot, bundle->fLocale, lang, TRUE, status); - - tabCount -= 1; - write_tabs(out); - - write_utf8_file(out, UnicodeString(bodyEnd)); - tabCount--; - write_tabs(out); - write_utf8_file(out, UnicodeString(fileEnd)); - tabCount--; - write_tabs(out); - write_utf8_file(out, UnicodeString(bundleEnd)); - T_FileStream_close(out); - - ucnv_close(conv); - -cleanup_bundle_write_xml: - uprv_free(originalFileName); - uprv_free(lang); - if(xmlfileName != NULL) { - uprv_free(xmlfileName); - } - if(outputFileName != NULL){ - uprv_free(outputFileName); - } -} diff --git a/deps/node/deps/icu-small/source/tools/icupkg/icupkg.cpp b/deps/node/deps/icu-small/source/tools/icupkg/icupkg.cpp deleted file mode 100644 index ea7be4a9..00000000 --- a/deps/node/deps/icu-small/source/tools/icupkg/icupkg.cpp +++ /dev/null @@ -1,554 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2005-2014, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: icupkg.cpp -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2005jul29 -* created by: Markus W. Scherer -* -* This tool operates on ICU data (.dat package) files. -* It takes one as input, or creates an empty one, and can remove, add, and -* extract data pieces according to command-line options. -* At the same time, it swaps each piece to a consistent set of platform -* properties as desired. -* Useful as an install-time tool for shipping only one flavor of ICU data -* and preparing data files for the target platform. -* Also for customizing ICU data (pruning, augmenting, replacing) and for -* taking it apart. -* Subsumes functionality and implementation code from -* gencmn, decmn, and icuswap tools. -* Will not work with data DLLs (shared libraries). -*/ - -#include "unicode/utypes.h" -#include "unicode/putil.h" -#include "cstring.h" -#include "toolutil.h" -#include "uoptions.h" -#include "uparse.h" -#include "filestrm.h" -#include "package.h" -#include "pkg_icu.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -U_NAMESPACE_USE - -// TODO: add --matchmode=regex for using the ICU regex engine for item name pattern matching? - -// general definitions ----------------------------------------------------- *** - -// main() ------------------------------------------------------------------ *** - -static void -printUsage(const char *pname, UBool isHelp) { - FILE *where=isHelp ? stdout : stderr; - - fprintf(where, - "%csage: %s [-h|-?|--help ] [-tl|-tb|-te] [-c] [-C comment]\n" - "\t[-a list] [-r list] [-x list] [-l [-o outputListFileName]]\n" - "\t[-s path] [-d path] [-w] [-m mode]\n" - "\t[--auto_toc_prefix] [--auto_toc_prefix_with_type] [--toc_prefix]\n" - "\tinfilename [outfilename]\n", - isHelp ? 'U' : 'u', pname); - if(isHelp) { - fprintf(where, - "\n" - "Read the input ICU .dat package file, modify it according to the options,\n" - "swap it to the desired platform properties (charset & endianness),\n" - "and optionally write the resulting ICU .dat package to the output file.\n" - "Items are removed, then added, then extracted and listed.\n" - "An ICU .dat package is written if items are removed or added,\n" - "or if the input and output filenames differ,\n" - "or if the --writepkg (-w) option is set.\n"); - fprintf(where, - "\n" - "If the input filename is \"new\" then an empty package is created.\n" - "If the output filename is missing, then it is automatically generated\n" - "from the input filename: If the input filename ends with an l, b, or e\n" - "matching its platform properties, then the output filename will\n" - "contain the letter from the -t (--type) option.\n"); - fprintf(where, - "\n" - "This tool can also be used to just swap a single ICU data file, replacing the\n" - "former icuswap tool. For this mode, provide the infilename (and optional\n" - "outfilename) for a non-package ICU data file.\n" - "Allowed options include -t, -w, -s and -d.\n" - "The filenames can be absolute, or relative to the source/dest dir paths.\n" - "Other options are not allowed in this mode.\n"); - fprintf(where, - "\n" - "Options:\n" - "\t(Only the last occurrence of an option is used.)\n" - "\n" - "\t-h or -? or --help print this message and exit\n"); - fprintf(where, - "\n" - "\t-tl or --type l output for little-endian/ASCII charset family\n" - "\t-tb or --type b output for big-endian/ASCII charset family\n" - "\t-te or --type e output for big-endian/EBCDIC charset family\n" - "\t The output type defaults to the input type.\n" - "\n" - "\t-c or --copyright include the ICU copyright notice\n" - "\t-C comment or --comment comment include a comment string\n"); - fprintf(where, - "\n" - "\t-a list or --add list add items to the package\n" - "\t-r list or --remove list remove items from the package\n" - "\t-x list or --extract list extract items from the package\n" - "\tThe list can be a single item's filename,\n" - "\tor a .txt filename with a list of item filenames,\n" - "\tor an ICU .dat package filename.\n"); - fprintf(where, - "\n" - "\t-w or --writepkg write the output package even if no items are removed\n" - "\t or added (e.g., for only swapping the data)\n"); - fprintf(where, - "\n" - "\t-m mode or --matchmode mode set the matching mode for item names with\n" - "\t wildcards\n" - "\t noslash: the '*' wildcard does not match the '/' tree separator\n"); - fprintf(where, - "\n" - "\tIn the .dat package, the Table of Contents (ToC) contains an entry\n" - "\tfor each item of the form prefix/tree/itemname .\n" - "\tThe prefix normally matches the package basename, and icupkg checks that,\n" - "\tbut this is not necessary when ICU need not find and load the package by filename.\n" - "\tICU package names end with the platform type letter, and thus differ\n" - "\tbetween platform types. This is not required for user data packages.\n"); - fprintf(where, - "\n" - "\t--auto_toc_prefix automatic ToC entries prefix\n" - "\t Uses the prefix of the first entry of the\n" - "\t input package, rather than its basename.\n" - "\t Requires a non-empty input package.\n" - "\t--auto_toc_prefix_with_type auto_toc_prefix + adjust platform type\n" - "\t Same as auto_toc_prefix but also checks that\n" - "\t the prefix ends with the input platform\n" - "\t type letter, and modifies it to the output\n" - "\t platform type letter.\n" - "\t At most one of the auto_toc_prefix options\n" - "\t can be used at a time.\n" - "\t--toc_prefix prefix ToC prefix to be used in the output package\n" - "\t Overrides the package basename\n" - "\t and --auto_toc_prefix.\n" - "\t Cannot be combined with --auto_toc_prefix_with_type.\n"); - /* - * Usage text columns, starting after the initial TAB. - * 1 2 3 4 5 6 7 8 - * 901234567890123456789012345678901234567890123456789012345678901234567890 - */ - fprintf(where, - "\n" - "\tList file syntax: Items are listed on one or more lines and separated\n" - "\tby whitespace (space+tab).\n" - "\tComments begin with # and are ignored. Empty lines are ignored.\n" - "\tLines where the first non-whitespace character is one of %s\n" - "\tare also ignored, to reserve for future syntax.\n", - U_PKG_RESERVED_CHARS); - fprintf(where, - "\tItems for removal or extraction may contain a single '*' wildcard\n" - "\tcharacter. The '*' matches zero or more characters.\n" - "\tIf --matchmode noslash (-m noslash) is set, then the '*'\n" - "\tdoes not match '/'.\n"); - fprintf(where, - "\n" - "\tItems must be listed relative to the package, and the --sourcedir or\n" - "\tthe --destdir path will be prepended.\n" - "\tThe paths are only prepended to item filenames while adding or\n" - "\textracting items, not to ICU .dat package or list filenames.\n" - "\t\n" - "\tPaths may contain '/' instead of the platform's\n" - "\tfile separator character, and are converted as appropriate.\n"); - fprintf(where, - "\n" - "\t-s path or --sourcedir path directory for the --add items\n" - "\t-d path or --destdir path directory for the --extract items\n" - "\n" - "\t-l or --list list the package items\n" - "\t (after modifying the package)\n" - "\t to stdout or to output list file\n" - "\t-o path or --outlist path path/filename for the --list output\n"); - } -} - -static UOption options[]={ - UOPTION_HELP_H, - UOPTION_HELP_QUESTION_MARK, - UOPTION_DEF("type", 't', UOPT_REQUIRES_ARG), - - UOPTION_COPYRIGHT, - UOPTION_DEF("comment", 'C', UOPT_REQUIRES_ARG), - - UOPTION_SOURCEDIR, - UOPTION_DESTDIR, - - UOPTION_DEF("writepkg", 'w', UOPT_NO_ARG), - - UOPTION_DEF("matchmode", 'm', UOPT_REQUIRES_ARG), - - UOPTION_DEF("add", 'a', UOPT_REQUIRES_ARG), - UOPTION_DEF("remove", 'r', UOPT_REQUIRES_ARG), - UOPTION_DEF("extract", 'x', UOPT_REQUIRES_ARG), - - UOPTION_DEF("list", 'l', UOPT_NO_ARG), - UOPTION_DEF("outlist", 'o', UOPT_REQUIRES_ARG), - - UOPTION_DEF("auto_toc_prefix", '\1', UOPT_NO_ARG), - UOPTION_DEF("auto_toc_prefix_with_type", '\1', UOPT_NO_ARG), - UOPTION_DEF("toc_prefix", '\1', UOPT_REQUIRES_ARG) -}; - -enum { - OPT_HELP_H, - OPT_HELP_QUESTION_MARK, - OPT_OUT_TYPE, - - OPT_COPYRIGHT, - OPT_COMMENT, - - OPT_SOURCEDIR, - OPT_DESTDIR, - - OPT_WRITEPKG, - - OPT_MATCHMODE, - - OPT_ADD_LIST, - OPT_REMOVE_LIST, - OPT_EXTRACT_LIST, - - OPT_LIST_ITEMS, - OPT_LIST_FILE, - - OPT_AUTO_TOC_PREFIX, - OPT_AUTO_TOC_PREFIX_WITH_TYPE, - OPT_TOC_PREFIX, - - OPT_COUNT -}; - -static UBool -isPackageName(const char *filename) { - int32_t len; - - len=(int32_t)strlen(filename)-4; /* -4: subtract the length of ".dat" */ - return (UBool)(len>0 && 0==strcmp(filename+len, ".dat")); -} -/* -This line is required by MinGW because it incorrectly globs the arguments. -So when \* is used, it turns into a list of files instead of a literal "*" -*/ -int _CRT_glob = 0; - -extern int -main(int argc, char *argv[]) { - const char *pname, *sourcePath, *destPath, *inFilename, *outFilename, *outComment; - char outType; - UBool isHelp, isModified, isPackage; - int result = 0; - - Package *pkg, *listPkg, *addListPkg; - - U_MAIN_INIT_ARGS(argc, argv); - - /* get the program basename */ - pname=findBasename(argv[0]); - - argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); - isHelp=options[OPT_HELP_H].doesOccur || options[OPT_HELP_QUESTION_MARK].doesOccur; - if(isHelp) { - printUsage(pname, TRUE); - return U_ZERO_ERROR; - } - - pkg=new Package; - if(pkg==NULL) { - fprintf(stderr, "icupkg: not enough memory\n"); - return U_MEMORY_ALLOCATION_ERROR; - } - isModified=FALSE; - - int autoPrefix=0; - if(options[OPT_AUTO_TOC_PREFIX].doesOccur) { - pkg->setAutoPrefix(); - ++autoPrefix; - } - if(options[OPT_AUTO_TOC_PREFIX_WITH_TYPE].doesOccur) { - if(options[OPT_TOC_PREFIX].doesOccur) { - fprintf(stderr, "icupkg: --auto_toc_prefix_with_type and also --toc_prefix\n"); - printUsage(pname, FALSE); - return U_ILLEGAL_ARGUMENT_ERROR; - } - pkg->setAutoPrefixWithType(); - ++autoPrefix; - } - if(argc<2 || 3<argc || autoPrefix>1) { - printUsage(pname, FALSE); - return U_ILLEGAL_ARGUMENT_ERROR; - } - - if(options[OPT_SOURCEDIR].doesOccur) { - sourcePath=options[OPT_SOURCEDIR].value; - } else { - // work relative to the current working directory - sourcePath=NULL; - } - if(options[OPT_DESTDIR].doesOccur) { - destPath=options[OPT_DESTDIR].value; - } else { - // work relative to the current working directory - destPath=NULL; - } - - if(0==strcmp(argv[1], "new")) { - if(autoPrefix) { - fprintf(stderr, "icupkg: --auto_toc_prefix[_with_type] but no input package\n"); - printUsage(pname, FALSE); - return U_ILLEGAL_ARGUMENT_ERROR; - } - inFilename=NULL; - isPackage=TRUE; - } else { - inFilename=argv[1]; - if(isPackageName(inFilename)) { - pkg->readPackage(inFilename); - isPackage=TRUE; - } else { - /* swap a single file (icuswap replacement) rather than work on a package */ - pkg->addFile(sourcePath, inFilename); - isPackage=FALSE; - } - } - - if(argc>=3) { - outFilename=argv[2]; - if(0!=strcmp(argv[1], argv[2])) { - isModified=TRUE; - } - } else if(isPackage) { - outFilename=NULL; - } else /* !isPackage */ { - outFilename=inFilename; - isModified=(UBool)(sourcePath!=destPath); - } - - /* parse the output type option */ - if(options[OPT_OUT_TYPE].doesOccur) { - const char *type=options[OPT_OUT_TYPE].value; - if(type[0]==0 || type[1]!=0) { - /* the type must be exactly one letter */ - printUsage(pname, FALSE); - return U_ILLEGAL_ARGUMENT_ERROR; - } - outType=type[0]; - switch(outType) { - case 'l': - case 'b': - case 'e': - break; - default: - printUsage(pname, FALSE); - return U_ILLEGAL_ARGUMENT_ERROR; - } - - /* - * Set the isModified flag if the output type differs from the - * input package type. - * If we swap a single file, just assume that we are modifying it. - * The Package class does not give us access to the item and its type. - */ - isModified|=(UBool)(!isPackage || outType!=pkg->getInType()); - } else if(isPackage) { - outType=pkg->getInType(); // default to input type - } else /* !isPackage: swap single file */ { - outType=0; /* tells extractItem() to not swap */ - } - - if(options[OPT_WRITEPKG].doesOccur) { - isModified=TRUE; - } - - if(!isPackage) { - /* - * icuswap tool replacement: Only swap a single file. - * Check that irrelevant options are not set. - */ - if( options[OPT_COMMENT].doesOccur || - options[OPT_COPYRIGHT].doesOccur || - options[OPT_MATCHMODE].doesOccur || - options[OPT_REMOVE_LIST].doesOccur || - options[OPT_ADD_LIST].doesOccur || - options[OPT_EXTRACT_LIST].doesOccur || - options[OPT_LIST_ITEMS].doesOccur - ) { - printUsage(pname, FALSE); - return U_ILLEGAL_ARGUMENT_ERROR; - } - if(isModified) { - pkg->extractItem(destPath, outFilename, 0, outType); - } - - delete pkg; - return result; - } - - /* Work with a package. */ - - if(options[OPT_COMMENT].doesOccur) { - outComment=options[OPT_COMMENT].value; - } else if(options[OPT_COPYRIGHT].doesOccur) { - outComment=U_COPYRIGHT_STRING; - } else { - outComment=NULL; - } - - if(options[OPT_MATCHMODE].doesOccur) { - if(0==strcmp(options[OPT_MATCHMODE].value, "noslash")) { - pkg->setMatchMode(Package::MATCH_NOSLASH); - } else { - printUsage(pname, FALSE); - return U_ILLEGAL_ARGUMENT_ERROR; - } - } - - /* remove items */ - if(options[OPT_REMOVE_LIST].doesOccur) { - listPkg=new Package(); - if(listPkg==NULL) { - fprintf(stderr, "icupkg: not enough memory\n"); - exit(U_MEMORY_ALLOCATION_ERROR); - } - if(readList(NULL, options[OPT_REMOVE_LIST].value, FALSE, listPkg)) { - pkg->removeItems(*listPkg); - delete listPkg; - isModified=TRUE; - } else { - printUsage(pname, FALSE); - return U_ILLEGAL_ARGUMENT_ERROR; - } - } - - /* - * add items - * use a separate Package so that its memory and items stay around - * as long as the main Package - */ - addListPkg=NULL; - if(options[OPT_ADD_LIST].doesOccur) { - addListPkg=new Package(); - if(addListPkg==NULL) { - fprintf(stderr, "icupkg: not enough memory\n"); - exit(U_MEMORY_ALLOCATION_ERROR); - } - if(readList(sourcePath, options[OPT_ADD_LIST].value, TRUE, addListPkg)) { - pkg->addItems(*addListPkg); - // delete addListPkg; deferred until after writePackage() - isModified=TRUE; - } else { - printUsage(pname, FALSE); - return U_ILLEGAL_ARGUMENT_ERROR; - } - } - - /* extract items */ - if(options[OPT_EXTRACT_LIST].doesOccur) { - listPkg=new Package(); - if(listPkg==NULL) { - fprintf(stderr, "icupkg: not enough memory\n"); - exit(U_MEMORY_ALLOCATION_ERROR); - } - if(readList(NULL, options[OPT_EXTRACT_LIST].value, FALSE, listPkg)) { - pkg->extractItems(destPath, *listPkg, outType); - delete listPkg; - } else { - printUsage(pname, FALSE); - return U_ILLEGAL_ARGUMENT_ERROR; - } - } - - /* list items */ - if(options[OPT_LIST_ITEMS].doesOccur) { - int32_t i; - if (options[OPT_LIST_FILE].doesOccur) { - FileStream *out; - out = T_FileStream_open(options[OPT_LIST_FILE].value, "w"); - if (out != NULL) { - for(i=0; i<pkg->getItemCount(); ++i) { - T_FileStream_writeLine(out, pkg->getItem(i)->name); - T_FileStream_writeLine(out, "\n"); - } - T_FileStream_close(out); - } else { - return U_ILLEGAL_ARGUMENT_ERROR; - } - } else { - for(i=0; i<pkg->getItemCount(); ++i) { - fprintf(stdout, "%s\n", pkg->getItem(i)->name); - } - } - } - - /* check dependencies between items */ - if(!pkg->checkDependencies()) { - /* some dependencies are not fulfilled */ - return U_MISSING_RESOURCE_ERROR; - } - - /* write the output .dat package if there are any modifications */ - if(isModified) { - char outFilenameBuffer[1024]; // for auto-generated output filename, if necessary - - if(outFilename==NULL || outFilename[0]==0) { - if(inFilename==NULL || inFilename[0]==0) { - fprintf(stderr, "icupkg: unable to auto-generate an output filename if there is no input filename\n"); - exit(U_ILLEGAL_ARGUMENT_ERROR); - } - - /* - * auto-generate a filename: - * copy the inFilename, - * and if the last basename character matches the input file's type, - * then replace it with the output file's type - */ - char suffix[6]="?.dat"; - char *s; - - suffix[0]=pkg->getInType(); - strcpy(outFilenameBuffer, inFilename); - s=strchr(outFilenameBuffer, 0); - if((s-outFilenameBuffer)>5 && 0==memcmp(s-5, suffix, 5)) { - *(s-5)=outType; - } - outFilename=outFilenameBuffer; - } - if(options[OPT_TOC_PREFIX].doesOccur) { - pkg->setPrefix(options[OPT_TOC_PREFIX].value); - } - result = writePackageDatFile(outFilename, outComment, NULL, NULL, pkg, outType); - } - - delete addListPkg; - delete pkg; - return result; -} - -/* - * Hey, Emacs, please set the following: - * - * Local Variables: - * indent-tabs-mode: nil - * End: - * - */ diff --git a/deps/node/deps/icu-small/source/tools/pkgdata/pkgdata.cpp b/deps/node/deps/icu-small/source/tools/pkgdata/pkgdata.cpp deleted file mode 100644 index d7e5721c..00000000 --- a/deps/node/deps/icu-small/source/tools/pkgdata/pkgdata.cpp +++ /dev/null @@ -1,2246 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/****************************************************************************** - * Copyright (C) 2000-2016, International Business Machines - * Corporation and others. All Rights Reserved. - ******************************************************************************* - * file name: pkgdata.cpp - * encoding: ANSI X3.4 (1968) - * tab size: 8 (not used) - * indentation:4 - * - * created on: 2000may15 - * created by: Steven \u24C7 Loomis - * - * This program packages the ICU data into different forms - * (DLL, common data, etc.) - */ - -// Defines _XOPEN_SOURCE for access to POSIX functions. -// Must be before any other #includes. -#include "uposixdefs.h" - -#include "unicode/utypes.h" - -#include "unicode/putil.h" -#include "putilimp.h" - -#if U_HAVE_POPEN -#if (U_PF_MINGW <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(__STRICT_ANSI__) -/* popen/pclose aren't defined in strict ANSI on Cygwin and MinGW */ -#undef __STRICT_ANSI__ -#endif -#endif - -#include "cmemory.h" -#include "cstring.h" -#include "filestrm.h" -#include "toolutil.h" -#include "unicode/uclean.h" -#include "unewdata.h" -#include "uoptions.h" -#include "package.h" -#include "pkg_icu.h" -#include "pkg_genc.h" -#include "pkg_gencmn.h" -#include "flagparser.h" -#include "filetools.h" -#include "charstr.h" - -#if U_HAVE_POPEN -# include <unistd.h> -#endif - -#include <stdio.h> -#include <stdlib.h> - -U_CDECL_BEGIN -#include "pkgtypes.h" -U_CDECL_END - -#if U_HAVE_POPEN - -using icu::LocalPointerBase; - -U_DEFINE_LOCAL_OPEN_POINTER(LocalPipeFilePointer, FILE, pclose); - -#endif - -static void loadLists(UPKGOptions *o, UErrorCode *status); - -static int32_t pkg_executeOptions(UPKGOptions *o); - -#ifdef WINDOWS_WITH_MSVC -static int32_t pkg_createWindowsDLL(const char mode, const char *gencFilePath, UPKGOptions *o); -#endif -static int32_t pkg_createSymLinks(const char *targetDir, UBool specialHandling=FALSE); -static int32_t pkg_installLibrary(const char *installDir, const char *dir, UBool noVersion); -static int32_t pkg_installFileMode(const char *installDir, const char *srcDir, const char *fileListName); -static int32_t pkg_installCommonMode(const char *installDir, const char *fileName); - -#ifdef BUILD_DATA_WITHOUT_ASSEMBLY -static int32_t pkg_createWithoutAssemblyCode(UPKGOptions *o, const char *targetDir, const char mode); -#endif - -#ifdef CAN_WRITE_OBJ_CODE -static void pkg_createOptMatchArch(char *optMatchArch); -static void pkg_destroyOptMatchArch(char *optMatchArch); -#endif - -static int32_t pkg_createWithAssemblyCode(const char *targetDir, const char mode, const char *gencFilePath); -static int32_t pkg_generateLibraryFile(const char *targetDir, const char mode, const char *objectFile, char *command = NULL, UBool specialHandling=FALSE); -static int32_t pkg_archiveLibrary(const char *targetDir, const char *version, UBool reverseExt); -static void createFileNames(UPKGOptions *o, const char mode, const char *version_major, const char *version, const char *libName, const UBool reverseExt, UBool noVersion); -static int32_t initializePkgDataFlags(UPKGOptions *o); - -static int32_t pkg_getOptionsFromICUConfig(UBool verbose, UOption *option); -static int runCommand(const char* command, UBool specialHandling=FALSE); - -#define IN_COMMON_MODE(mode) (mode == 'a' || mode == 'c') -#define IN_DLL_MODE(mode) (mode == 'd' || mode == 'l') -#define IN_STATIC_MODE(mode) (mode == 's') -#define IN_FILES_MODE(mode) (mode == 'f') - -enum { - NAME, - BLDOPT, - MODE, - HELP, - HELP_QUESTION_MARK, - VERBOSE, - COPYRIGHT, - COMMENT, - DESTDIR, - REBUILD, - TEMPDIR, - INSTALL, - SOURCEDIR, - ENTRYPOINT, - REVISION, - FORCE_PREFIX, - LIBNAME, - QUIET, - WITHOUT_ASSEMBLY, - PDS_BUILD, - UWP_BUILD, - UWP_ARM_BUILD -}; - -/* This sets the modes that are available */ -static struct { - const char *name, *alt_name; - const char *desc; -} modes[] = { - { "files", 0, "Uses raw data files (no effect). Installation copies all files to the target location." }, -#if U_PLATFORM_HAS_WIN32_API - { "dll", "library", "Generates one common data file and one shared library, <package>.dll"}, - { "common", "archive", "Generates just the common file, <package>.dat"}, - { "static", "static", "Generates one statically linked library, " LIB_PREFIX "<package>" UDATA_LIB_SUFFIX } -#else -#ifdef UDATA_SO_SUFFIX - { "dll", "library", "Generates one shared library, <package>" UDATA_SO_SUFFIX }, -#endif - { "common", "archive", "Generates one common data file, <package>.dat" }, - { "static", "static", "Generates one statically linked library, " LIB_PREFIX "<package>" UDATA_LIB_SUFFIX } -#endif -}; - -static UOption options[]={ - /*00*/ UOPTION_DEF( "name", 'p', UOPT_REQUIRES_ARG), - /*01*/ UOPTION_DEF( "bldopt", 'O', UOPT_REQUIRES_ARG), /* on Win32 it is release or debug */ - /*02*/ UOPTION_DEF( "mode", 'm', UOPT_REQUIRES_ARG), - /*03*/ UOPTION_HELP_H, /* -h */ - /*04*/ UOPTION_HELP_QUESTION_MARK, /* -? */ - /*05*/ UOPTION_VERBOSE, /* -v */ - /*06*/ UOPTION_COPYRIGHT, /* -c */ - /*07*/ UOPTION_DEF( "comment", 'C', UOPT_REQUIRES_ARG), - /*08*/ UOPTION_DESTDIR, /* -d */ - /*11*/ UOPTION_DEF( "rebuild", 'F', UOPT_NO_ARG), - /*12*/ UOPTION_DEF( "tempdir", 'T', UOPT_REQUIRES_ARG), - /*13*/ UOPTION_DEF( "install", 'I', UOPT_REQUIRES_ARG), - /*14*/ UOPTION_SOURCEDIR , - /*15*/ UOPTION_DEF( "entrypoint", 'e', UOPT_REQUIRES_ARG), - /*16*/ UOPTION_DEF( "revision", 'r', UOPT_REQUIRES_ARG), - /*17*/ UOPTION_DEF( "force-prefix", 'f', UOPT_NO_ARG), - /*18*/ UOPTION_DEF( "libname", 'L', UOPT_REQUIRES_ARG), - /*19*/ UOPTION_DEF( "quiet", 'q', UOPT_NO_ARG), - /*20*/ UOPTION_DEF( "without-assembly", 'w', UOPT_NO_ARG), - /*21*/ UOPTION_DEF("zos-pds-build", 'z', UOPT_NO_ARG), - /*22*/ UOPTION_DEF("windows-uwp-build", 'u', UOPT_NO_ARG), - /*23*/ UOPTION_DEF("windows-uwp-arm-build", 'a', UOPT_NO_ARG) -}; - -/* This enum and the following char array should be kept in sync. */ -enum { - GENCCODE_ASSEMBLY_TYPE, - SO_EXT, - SOBJ_EXT, - A_EXT, - LIBPREFIX, - LIB_EXT_ORDER, - COMPILER, - LIBFLAGS, - GENLIB, - LDICUDTFLAGS, - LD_SONAME, - RPATH_FLAGS, - BIR_FLAGS, - AR, - ARFLAGS, - RANLIB, - INSTALL_CMD, - PKGDATA_FLAGS_SIZE -}; -static const char* FLAG_NAMES[PKGDATA_FLAGS_SIZE] = { - "GENCCODE_ASSEMBLY_TYPE", - "SO", - "SOBJ", - "A", - "LIBPREFIX", - "LIB_EXT_ORDER", - "COMPILE", - "LIBFLAGS", - "GENLIB", - "LDICUDTFLAGS", - "LD_SONAME", - "RPATH_FLAGS", - "BIR_LDFLAGS", - "AR", - "ARFLAGS", - "RANLIB", - "INSTALL_CMD" -}; -static char **pkgDataFlags = NULL; - -enum { - LIB_FILE, - LIB_FILE_VERSION_MAJOR, - LIB_FILE_VERSION, - LIB_FILE_VERSION_TMP, -#if U_PLATFORM == U_PF_CYGWIN - LIB_FILE_CYGWIN, - LIB_FILE_CYGWIN_VERSION, -#elif U_PLATFORM == U_PF_MINGW - LIB_FILE_MINGW, -#elif U_PLATFORM == U_PF_OS390 - LIB_FILE_OS390BATCH_MAJOR, - LIB_FILE_OS390BATCH_VERSION, -#endif - LIB_FILENAMES_SIZE -}; -static char libFileNames[LIB_FILENAMES_SIZE][256]; - -static UPKGOptions *pkg_checkFlag(UPKGOptions *o); - -const char options_help[][320]={ - "Set the data name", -#ifdef U_MAKE_IS_NMAKE - "The directory where the ICU is located (e.g. <ICUROOT> which contains the bin directory)", -#else - "Specify options for the builder.", -#endif - "Specify the mode of building (see below; default: common)", - "This usage text", - "This usage text", - "Make the output verbose", - "Use the standard ICU copyright", - "Use a custom comment (instead of the copyright)", - "Specify the destination directory for files", - "Force rebuilding of all data", - "Specify temporary dir (default: output dir)", - "Install the data (specify target)", - "Specify a custom source directory", - "Specify a custom entrypoint name (default: short name)", - "Specify a version when packaging in dll or static mode", - "Add package to all file names if not present", - "Library name to build (if different than package name)", - "Quiet mode. (e.g. Do not output a readme file for static libraries)", - "Build the data without assembly code", - "Build PDS dataset (zOS build only)", - "Build for Universal Windows Platform (Windows build only)", - "Set DLL machine type for UWP to target windows ARM (Windows UWP build only)" -}; - -const char *progname = "PKGDATA"; - -int -main(int argc, char* argv[]) { - int result = 0; - /* FileStream *out; */ - UPKGOptions o; - CharList *tail; - UBool needsHelp = FALSE; - UErrorCode status = U_ZERO_ERROR; - /* char tmp[1024]; */ - uint32_t i; - int32_t n; - - U_MAIN_INIT_ARGS(argc, argv); - - progname = argv[0]; - - options[MODE].value = "common"; - - /* read command line options */ - argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); - - /* error handling, printing usage message */ - /* I've decided to simply print an error and quit. This tool has too - many options to just display them all of the time. */ - - if(options[HELP].doesOccur || options[HELP_QUESTION_MARK].doesOccur) { - needsHelp = TRUE; - } - else { - if(!needsHelp && argc<0) { - fprintf(stderr, - "%s: error in command line argument \"%s\"\n", - progname, - argv[-argc]); - fprintf(stderr, "Run '%s --help' for help.\n", progname); - return 1; - } - - -#if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN) - if(!options[BLDOPT].doesOccur && uprv_strcmp(options[MODE].value, "common") != 0) { - if (pkg_getOptionsFromICUConfig(options[VERBOSE].doesOccur, &options[BLDOPT]) != 0) { - fprintf(stderr, " required parameter is missing: -O is required for static and shared builds.\n"); - fprintf(stderr, "Run '%s --help' for help.\n", progname); - return 1; - } - } -#else - if(options[BLDOPT].doesOccur) { - fprintf(stdout, "Warning: You are using the -O option which is not needed for MSVC build on Windows.\n"); - } -#endif - - if(!options[NAME].doesOccur) /* -O we already have - don't report it. */ - { - fprintf(stderr, " required parameter -p is missing \n"); - fprintf(stderr, "Run '%s --help' for help.\n", progname); - return 1; - } - - if(argc == 1) { - fprintf(stderr, - "No input files specified.\n" - "Run '%s --help' for help.\n", progname); - return 1; - } - } /* end !needsHelp */ - - if(argc<0 || needsHelp ) { - fprintf(stderr, - "usage: %s [-options] [-] [packageFile] \n" - "\tProduce packaged ICU data from the given list(s) of files.\n" - "\t'-' by itself means to read from stdin.\n" - "\tpackageFile is a text file containing the list of files to package.\n", - progname); - - fprintf(stderr, "\n options:\n"); - for(i=0;i<UPRV_LENGTHOF(options);i++) { - fprintf(stderr, "%-5s -%c %s%-10s %s\n", - (i<1?"[REQ]":""), - options[i].shortName, - options[i].longName ? "or --" : " ", - options[i].longName ? options[i].longName : "", - options_help[i]); - } - - fprintf(stderr, "modes: (-m option)\n"); - for(i=0;i<UPRV_LENGTHOF(modes);i++) { - fprintf(stderr, " %-9s ", modes[i].name); - if (modes[i].alt_name) { - fprintf(stderr, "/ %-9s", modes[i].alt_name); - } else { - fprintf(stderr, " "); - } - fprintf(stderr, " %s\n", modes[i].desc); - } - return 1; - } - - /* OK, fill in the options struct */ - uprv_memset(&o, 0, sizeof(o)); - - o.mode = options[MODE].value; - o.version = options[REVISION].doesOccur ? options[REVISION].value : 0; - - o.shortName = options[NAME].value; - { - int32_t len = (int32_t)uprv_strlen(o.shortName); - char *csname, *cp; - const char *sp; - - cp = csname = (char *) uprv_malloc((len + 1 + 1) * sizeof(*o.cShortName)); - if (*(sp = o.shortName)) { - *cp++ = isalpha(*sp) ? * sp : '_'; - for (++sp; *sp; ++sp) { - *cp++ = isalnum(*sp) ? *sp : '_'; - } - } - *cp = 0; - - o.cShortName = csname; - } - - if(options[LIBNAME].doesOccur) { /* get libname from shortname, or explicit -L parameter */ - o.libName = options[LIBNAME].value; - } else { - o.libName = o.shortName; - } - - if(options[QUIET].doesOccur) { - o.quiet = TRUE; - } else { - o.quiet = FALSE; - } - - if(options[PDS_BUILD].doesOccur) { -#if U_PLATFORM == U_PF_OS390 - o.pdsbuild = TRUE; -#else - o.pdsbuild = FALSE; - fprintf(stdout, "Warning: You are using the -z option which only works on z/OS.\n"); - -#endif - } else { - o.pdsbuild = FALSE; - } - - o.verbose = options[VERBOSE].doesOccur; - - -#if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN) /* on UNIX, we'll just include the file... */ - if (options[BLDOPT].doesOccur) { - o.options = options[BLDOPT].value; - } else { - o.options = NULL; - } -#endif - if(options[COPYRIGHT].doesOccur) { - o.comment = U_COPYRIGHT_STRING; - } else if (options[COMMENT].doesOccur) { - o.comment = options[COMMENT].value; - } - - if( options[DESTDIR].doesOccur ) { - o.targetDir = options[DESTDIR].value; - } else { - o.targetDir = "."; /* cwd */ - } - - o.rebuild = options[REBUILD].doesOccur; - - if( options[TEMPDIR].doesOccur ) { - o.tmpDir = options[TEMPDIR].value; - } else { - o.tmpDir = o.targetDir; - } - - if( options[INSTALL].doesOccur ) { - o.install = options[INSTALL].value; - } else { - o.install = NULL; - } - - if( options[SOURCEDIR].doesOccur ) { - o.srcDir = options[SOURCEDIR].value; - } else { - o.srcDir = "."; - } - - if( options[ENTRYPOINT].doesOccur ) { - o.entryName = options[ENTRYPOINT].value; - } else { - o.entryName = o.cShortName; - } - - o.withoutAssembly = FALSE; - if (options[WITHOUT_ASSEMBLY].doesOccur) { -#ifndef BUILD_DATA_WITHOUT_ASSEMBLY - fprintf(stdout, "Warning: You are using the option to build without assembly code which is not supported on this platform.\n"); - fprintf(stdout, "Warning: This option will be ignored.\n"); -#else - o.withoutAssembly = TRUE; -#endif - } - - /* OK options are set up. Now the file lists. */ - tail = NULL; - for( n=1; n<argc; n++) { - o.fileListFiles = pkg_appendToList(o.fileListFiles, &tail, uprv_strdup(argv[n])); - } - - /* load the files */ - loadLists(&o, &status); - if( U_FAILURE(status) ) { - fprintf(stderr, "error loading input file lists: %s\n", u_errorName(status)); - return 2; - } - - result = pkg_executeOptions(&o); - - if (pkgDataFlags != NULL) { - for (n = 0; n < PKGDATA_FLAGS_SIZE; n++) { - if (pkgDataFlags[n] != NULL) { - uprv_free(pkgDataFlags[n]); - } - } - uprv_free(pkgDataFlags); - } - - if (o.cShortName != NULL) { - uprv_free((char *)o.cShortName); - } - if (o.fileListFiles != NULL) { - pkg_deleteList(o.fileListFiles); - } - if (o.filePaths != NULL) { - pkg_deleteList(o.filePaths); - } - if (o.files != NULL) { - pkg_deleteList(o.files); - } - - return result; -} - -static int runCommand(const char* command, UBool specialHandling) { - char *cmd = NULL; - char cmdBuffer[SMALL_BUFFER_MAX_SIZE]; - int32_t len = static_cast<int32_t>(strlen(command)); - - if (len == 0) { - return 0; - } - - if (!specialHandling) { -#if defined(USING_CYGWIN) || U_PLATFORM == U_PF_MINGW || U_PLATFORM == U_PF_OS400 - if ((len + BUFFER_PADDING_SIZE) >= SMALL_BUFFER_MAX_SIZE) { - cmd = (char *)uprv_malloc(len + BUFFER_PADDING_SIZE); - } else { - cmd = cmdBuffer; - } -#if defined(USING_CYGWIN) || U_PLATFORM == U_PF_MINGW - sprintf(cmd, "bash -c \"%s\"", command); - -#elif U_PLATFORM == U_PF_OS400 - sprintf(cmd, "QSH CMD('%s')", command); -#endif -#else - goto normal_command_mode; -#endif - } else { -#if !(defined(USING_CYGWIN) || U_PLATFORM == U_PF_MINGW || U_PLATFORM == U_PF_OS400) -normal_command_mode: -#endif - cmd = (char *)command; - } - - printf("pkgdata: %s\n", cmd); - int result = system(cmd); - if (result != 0) { - fprintf(stderr, "-- return status = %d\n", result); - } - - if (cmd != cmdBuffer && cmd != command) { - uprv_free(cmd); - } - - return result; -} - -#define LN_CMD "ln -s" -#define RM_CMD "rm -f" - -static int32_t pkg_executeOptions(UPKGOptions *o) { - int32_t result = 0; - - const char mode = o->mode[0]; - char targetDir[SMALL_BUFFER_MAX_SIZE] = ""; - char tmpDir[SMALL_BUFFER_MAX_SIZE] = ""; - char datFileName[SMALL_BUFFER_MAX_SIZE] = ""; - char datFileNamePath[LARGE_BUFFER_MAX_SIZE] = ""; - char checkLibFile[LARGE_BUFFER_MAX_SIZE] = ""; - - initializePkgDataFlags(o); - - if (IN_FILES_MODE(mode)) { - /* Copy the raw data to the installation directory. */ - if (o->install != NULL) { - uprv_strcpy(targetDir, o->install); - if (o->shortName != NULL) { - uprv_strcat(targetDir, PKGDATA_FILE_SEP_STRING); - uprv_strcat(targetDir, o->shortName); - } - - if(o->verbose) { - fprintf(stdout, "# Install: Files mode, copying files to %s..\n", targetDir); - } - result = pkg_installFileMode(targetDir, o->srcDir, o->fileListFiles->str); - } - return result; - } else /* if (IN_COMMON_MODE(mode) || IN_DLL_MODE(mode) || IN_STATIC_MODE(mode)) */ { - UBool noVersion = FALSE; - - uprv_strcpy(targetDir, o->targetDir); - uprv_strcat(targetDir, PKGDATA_FILE_SEP_STRING); - - uprv_strcpy(tmpDir, o->tmpDir); - uprv_strcat(tmpDir, PKGDATA_FILE_SEP_STRING); - - uprv_strcpy(datFileNamePath, tmpDir); - - uprv_strcpy(datFileName, o->shortName); - uprv_strcat(datFileName, UDATA_CMN_SUFFIX); - - uprv_strcat(datFileNamePath, datFileName); - - if(o->verbose) { - fprintf(stdout, "# Writing package file %s ..\n", datFileNamePath); - } - result = writePackageDatFile(datFileNamePath, o->comment, o->srcDir, o->fileListFiles->str, NULL, U_CHARSET_FAMILY ? 'e' : U_IS_BIG_ENDIAN ? 'b' : 'l'); - if (result != 0) { - fprintf(stderr,"Error writing package dat file.\n"); - return result; - } - - if (IN_COMMON_MODE(mode)) { - char targetFileNamePath[LARGE_BUFFER_MAX_SIZE] = ""; - - uprv_strcpy(targetFileNamePath, targetDir); - uprv_strcat(targetFileNamePath, datFileName); - - /* Move the dat file created to the target directory. */ - if (uprv_strcmp(datFileNamePath, targetFileNamePath) != 0) { - if (T_FileStream_file_exists(targetFileNamePath)) { - if ((result = remove(targetFileNamePath)) != 0) { - fprintf(stderr, "Unable to remove old dat file: %s\n", - targetFileNamePath); - return result; - } - } - - result = rename(datFileNamePath, targetFileNamePath); - - if (o->verbose) { - fprintf(stdout, "# Moving package file to %s ..\n", - targetFileNamePath); - } - if (result != 0) { - fprintf( - stderr, - "Unable to move dat file (%s) to target location (%s).\n", - datFileNamePath, targetFileNamePath); - return result; - } - } - - if (o->install != NULL) { - result = pkg_installCommonMode(o->install, targetFileNamePath); - } - - return result; - } else /* if (IN_STATIC_MODE(mode) || IN_DLL_MODE(mode)) */ { - char gencFilePath[SMALL_BUFFER_MAX_SIZE] = ""; - char version_major[10] = ""; - UBool reverseExt = FALSE; - -#if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN) - /* Get the version major number. */ - if (o->version != NULL) { - for (uint32_t i = 0;i < sizeof(version_major);i++) { - if (o->version[i] == '.') { - version_major[i] = 0; - break; - } - version_major[i] = o->version[i]; - } - } else { - noVersion = TRUE; - if (IN_DLL_MODE(mode)) { - fprintf(stdout, "Warning: Providing a revision number with the -r option is recommended when packaging data in the current mode.\n"); - } - } - -#if U_PLATFORM != U_PF_OS400 - /* Certain platforms have different library extension ordering. (e.g. libicudata.##.so vs libicudata.so.##) - * reverseExt is FALSE if the suffix should be the version number. - */ - if (pkgDataFlags[LIB_EXT_ORDER][uprv_strlen(pkgDataFlags[LIB_EXT_ORDER])-1] == pkgDataFlags[SO_EXT][uprv_strlen(pkgDataFlags[SO_EXT])-1]) { - reverseExt = TRUE; - } -#endif - /* Using the base libName and version number, generate the library file names. */ - createFileNames(o, mode, version_major, o->version == NULL ? "" : o->version, o->libName, reverseExt, noVersion); - - if ((o->version!=NULL || IN_STATIC_MODE(mode)) && o->rebuild == FALSE && o->pdsbuild == FALSE) { - /* Check to see if a previous built data library file exists and check if it is the latest. */ - sprintf(checkLibFile, "%s%s", targetDir, libFileNames[LIB_FILE_VERSION]); - if (T_FileStream_file_exists(checkLibFile)) { - if (isFileModTimeLater(checkLibFile, o->srcDir, TRUE) && isFileModTimeLater(checkLibFile, o->options)) { - if (o->install != NULL) { - if(o->verbose) { - fprintf(stdout, "# Installing already-built library into %s\n", o->install); - } - result = pkg_installLibrary(o->install, targetDir, noVersion); - } else { - if(o->verbose) { - printf("# Not rebuilding %s - up to date.\n", checkLibFile); - } - } - return result; - } else if (o->verbose && (o->install!=NULL)) { - fprintf(stdout, "# Not installing up-to-date library %s into %s\n", checkLibFile, o->install); - } - } else if(o->verbose && (o->install!=NULL)) { - fprintf(stdout, "# Not installing missing %s into %s\n", checkLibFile, o->install); - } - } - - if (pkg_checkFlag(o) == NULL) { - /* Error occurred. */ - return result; - } -#endif - - if (!o->withoutAssembly && pkgDataFlags[GENCCODE_ASSEMBLY_TYPE][0] != 0) { - const char* genccodeAssembly = pkgDataFlags[GENCCODE_ASSEMBLY_TYPE]; - - if(o->verbose) { - fprintf(stdout, "# Generating assembly code %s of type %s ..\n", gencFilePath, genccodeAssembly); - } - - /* Offset genccodeAssembly by 3 because "-a " */ - if (genccodeAssembly && - (uprv_strlen(genccodeAssembly)>3) && - checkAssemblyHeaderName(genccodeAssembly+3)) { - writeAssemblyCode(datFileNamePath, o->tmpDir, o->entryName, NULL, gencFilePath); - - result = pkg_createWithAssemblyCode(targetDir, mode, gencFilePath); - if (result != 0) { - fprintf(stderr, "Error generating assembly code for data.\n"); - return result; - } else if (IN_STATIC_MODE(mode)) { - if(o->install != NULL) { - if(o->verbose) { - fprintf(stdout, "# Installing static library into %s\n", o->install); - } - result = pkg_installLibrary(o->install, targetDir, noVersion); - } - return result; - } - } else { - fprintf(stderr,"Assembly type \"%s\" is unknown.\n", genccodeAssembly); - return -1; - } - } else { - if(o->verbose) { - fprintf(stdout, "# Writing object code to %s ..\n", gencFilePath); - } - if (o->withoutAssembly) { -#ifdef BUILD_DATA_WITHOUT_ASSEMBLY - result = pkg_createWithoutAssemblyCode(o, targetDir, mode); -#else - /* This error should not occur. */ - fprintf(stderr, "Error- BUILD_DATA_WITHOUT_ASSEMBLY is not defined. Internal error.\n"); -#endif - } else { -#ifdef CAN_WRITE_OBJ_CODE - /* Try to detect the arch type, use NULL if unsuccessful */ - char optMatchArch[10] = { 0 }; - pkg_createOptMatchArch(optMatchArch); - writeObjectCode(datFileNamePath, o->tmpDir, o->entryName, (optMatchArch[0] == 0 ? NULL : optMatchArch), NULL, gencFilePath); - pkg_destroyOptMatchArch(optMatchArch); -#if U_PLATFORM_IS_LINUX_BASED - result = pkg_generateLibraryFile(targetDir, mode, gencFilePath); -#elif defined(WINDOWS_WITH_MSVC) - result = pkg_createWindowsDLL(mode, gencFilePath, o); -#endif -#elif defined(BUILD_DATA_WITHOUT_ASSEMBLY) - result = pkg_createWithoutAssemblyCode(o, targetDir, mode); -#else - fprintf(stderr, "Error- neither CAN_WRITE_OBJ_CODE nor BUILD_DATA_WITHOUT_ASSEMBLY are defined. Internal error.\n"); - return 1; -#endif - } - - if (result != 0) { - fprintf(stderr, "Error generating package data.\n"); - return result; - } - } -#if !U_PLATFORM_USES_ONLY_WIN32_API - if(!IN_STATIC_MODE(mode)) { - /* Certain platforms uses archive library. (e.g. AIX) */ - if(o->verbose) { - fprintf(stdout, "# Creating data archive library file ..\n"); - } - result = pkg_archiveLibrary(targetDir, o->version, reverseExt); - if (result != 0) { - fprintf(stderr, "Error creating data archive library file.\n"); - return result; - } -#if U_PLATFORM != U_PF_OS400 - if (!noVersion) { - /* Create symbolic links for the final library file. */ -#if U_PLATFORM == U_PF_OS390 - result = pkg_createSymLinks(targetDir, o->pdsbuild); -#else - result = pkg_createSymLinks(targetDir, noVersion); -#endif - if (result != 0) { - fprintf(stderr, "Error creating symbolic links of the data library file.\n"); - return result; - } - } -#endif - } /* !IN_STATIC_MODE */ -#endif - -#if !U_PLATFORM_USES_ONLY_WIN32_API - /* Install the libraries if option was set. */ - if (o->install != NULL) { - if(o->verbose) { - fprintf(stdout, "# Installing library file to %s ..\n", o->install); - } - result = pkg_installLibrary(o->install, targetDir, noVersion); - if (result != 0) { - fprintf(stderr, "Error installing the data library.\n"); - return result; - } - } -#endif - } - } - return result; -} - -/* Initialize the pkgDataFlags with the option file given. */ -static int32_t initializePkgDataFlags(UPKGOptions *o) { - UErrorCode status = U_ZERO_ERROR; - int32_t result = 0; - int32_t currentBufferSize = SMALL_BUFFER_MAX_SIZE; - int32_t tmpResult = 0; - - /* Initialize pkgdataFlags */ - pkgDataFlags = (char**)uprv_malloc(sizeof(char*) * PKGDATA_FLAGS_SIZE); - - /* If we run out of space, allocate more */ -#if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN) - do { -#endif - if (pkgDataFlags != NULL) { - for (int32_t i = 0; i < PKGDATA_FLAGS_SIZE; i++) { - pkgDataFlags[i] = (char*)uprv_malloc(sizeof(char) * currentBufferSize); - if (pkgDataFlags[i] != NULL) { - pkgDataFlags[i][0] = 0; - } else { - fprintf(stderr,"Error allocating memory for pkgDataFlags.\n"); - /* If an error occurs, ensure that the rest of the array is NULL */ - for (int32_t n = i + 1; n < PKGDATA_FLAGS_SIZE; n++) { - pkgDataFlags[n] = NULL; - } - return -1; - } - } - } else { - fprintf(stderr,"Error allocating memory for pkgDataFlags.\n"); - return -1; - } - - if (o->options == NULL) { - return result; - } - -#if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN) - /* Read in options file. */ - if(o->verbose) { - fprintf(stdout, "# Reading options file %s\n", o->options); - } - status = U_ZERO_ERROR; - tmpResult = parseFlagsFile(o->options, pkgDataFlags, currentBufferSize, FLAG_NAMES, (int32_t)PKGDATA_FLAGS_SIZE, &status); - if (status == U_BUFFER_OVERFLOW_ERROR) { - for (int32_t i = 0; i < PKGDATA_FLAGS_SIZE; i++) { - if (pkgDataFlags[i]) { - uprv_free(pkgDataFlags[i]); - pkgDataFlags[i] = NULL; - } - } - currentBufferSize = tmpResult; - } else if (U_FAILURE(status)) { - fprintf(stderr,"Unable to open or read \"%s\" option file. status = %s\n", o->options, u_errorName(status)); - return -1; - } -#endif - if(o->verbose) { - fprintf(stdout, "# pkgDataFlags=\n"); - for(int32_t i=0;i<PKGDATA_FLAGS_SIZE;i++) { - fprintf(stdout, " [%d] %s: %s\n", i, FLAG_NAMES[i], pkgDataFlags[i]); - } - fprintf(stdout, "\n"); - } -#if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN) - } while (status == U_BUFFER_OVERFLOW_ERROR); -#endif - - return result; -} - - -/* - * Given the base libName and version numbers, generate the libary file names and store it in libFileNames. - * Depending on the configuration, the library name may either end with version number or shared object suffix. - */ -static void createFileNames(UPKGOptions *o, const char mode, const char *version_major, const char *version, const char *libName, UBool reverseExt, UBool noVersion) { - const char* FILE_EXTENSION_SEP = uprv_strlen(pkgDataFlags[SO_EXT]) == 0 ? "" : "."; - const char* FILE_SUFFIX = pkgDataFlags[LIB_EXT_ORDER][0] == '.' ? "." : ""; - -#if U_PLATFORM == U_PF_MINGW - /* MinGW does not need the library prefix when building in dll mode. */ - if (IN_DLL_MODE(mode)) { - sprintf(libFileNames[LIB_FILE], "%s", libName); - } else { - sprintf(libFileNames[LIB_FILE], "%s%s%s", - (strstr(libName, "icudt") ? "lib" : ""), - pkgDataFlags[LIBPREFIX], - libName); - } -#else - sprintf(libFileNames[LIB_FILE], "%s%s", - pkgDataFlags[LIBPREFIX], - libName); -#endif - - if(o->verbose) { - fprintf(stdout, "# libFileName[LIB_FILE] = %s\n", libFileNames[LIB_FILE]); - } - -#if U_PLATFORM == U_PF_MINGW - // Name the import library lib*.dll.a - sprintf(libFileNames[LIB_FILE_MINGW], "lib%s.dll.a", libName); -#elif U_PLATFORM == U_PF_CYGWIN - sprintf(libFileNames[LIB_FILE_CYGWIN], "cyg%s%s%s", - libName, - FILE_EXTENSION_SEP, - pkgDataFlags[SO_EXT]); - sprintf(libFileNames[LIB_FILE_CYGWIN_VERSION], "cyg%s%s%s%s", - libName, - version_major, - FILE_EXTENSION_SEP, - pkgDataFlags[SO_EXT]); - - uprv_strcat(pkgDataFlags[SO_EXT], "."); - uprv_strcat(pkgDataFlags[SO_EXT], pkgDataFlags[A_EXT]); -#elif U_PLATFORM == U_PF_OS400 || defined(_AIX) - sprintf(libFileNames[LIB_FILE_VERSION_TMP], "%s%s%s", - libFileNames[LIB_FILE], - FILE_EXTENSION_SEP, - pkgDataFlags[SOBJ_EXT]); -#elif U_PLATFORM == U_PF_OS390 - sprintf(libFileNames[LIB_FILE_VERSION_TMP], "%s%s%s%s%s", - libFileNames[LIB_FILE], - pkgDataFlags[LIB_EXT_ORDER][0] == '.' ? "." : "", - reverseExt ? version : pkgDataFlags[SOBJ_EXT], - FILE_EXTENSION_SEP, - reverseExt ? pkgDataFlags[SOBJ_EXT] : version); - - sprintf(libFileNames[LIB_FILE_OS390BATCH_VERSION], "%s%s.x", - libFileNames[LIB_FILE], - version); - sprintf(libFileNames[LIB_FILE_OS390BATCH_MAJOR], "%s%s.x", - libFileNames[LIB_FILE], - version_major); -#else - if (noVersion && !reverseExt) { - sprintf(libFileNames[LIB_FILE_VERSION_TMP], "%s%s%s", - libFileNames[LIB_FILE], - FILE_SUFFIX, - pkgDataFlags[SOBJ_EXT]); - } else { - sprintf(libFileNames[LIB_FILE_VERSION_TMP], "%s%s%s%s%s", - libFileNames[LIB_FILE], - FILE_SUFFIX, - reverseExt ? version : pkgDataFlags[SOBJ_EXT], - FILE_EXTENSION_SEP, - reverseExt ? pkgDataFlags[SOBJ_EXT] : version); - } -#endif - if (noVersion && !reverseExt) { - sprintf(libFileNames[LIB_FILE_VERSION_MAJOR], "%s%s%s", - libFileNames[LIB_FILE], - FILE_SUFFIX, - pkgDataFlags[SO_EXT]); - - sprintf(libFileNames[LIB_FILE_VERSION], "%s%s%s", - libFileNames[LIB_FILE], - FILE_SUFFIX, - pkgDataFlags[SO_EXT]); - } else { - sprintf(libFileNames[LIB_FILE_VERSION_MAJOR], "%s%s%s%s%s", - libFileNames[LIB_FILE], - FILE_SUFFIX, - reverseExt ? version_major : pkgDataFlags[SO_EXT], - FILE_EXTENSION_SEP, - reverseExt ? pkgDataFlags[SO_EXT] : version_major); - - sprintf(libFileNames[LIB_FILE_VERSION], "%s%s%s%s%s", - libFileNames[LIB_FILE], - FILE_SUFFIX, - reverseExt ? version : pkgDataFlags[SO_EXT], - FILE_EXTENSION_SEP, - reverseExt ? pkgDataFlags[SO_EXT] : version); - } - - if(o->verbose) { - fprintf(stdout, "# libFileName[LIB_FILE_VERSION] = %s\n", libFileNames[LIB_FILE_VERSION]); - } - -#if U_PF_MINGW <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN - /* Cygwin and MinGW only deals with the version major number. */ - uprv_strcpy(libFileNames[LIB_FILE_VERSION_TMP], libFileNames[LIB_FILE_VERSION_MAJOR]); -#endif - - if(IN_STATIC_MODE(mode)) { - sprintf(libFileNames[LIB_FILE_VERSION], "%s.%s", libFileNames[LIB_FILE], pkgDataFlags[A_EXT]); - libFileNames[LIB_FILE_VERSION_MAJOR][0]=0; - if(o->verbose) { - fprintf(stdout, "# libFileName[LIB_FILE_VERSION] = %s (static)\n", libFileNames[LIB_FILE_VERSION]); - } - } -} - -/* Create the symbolic links for the final library file. */ -static int32_t pkg_createSymLinks(const char *targetDir, UBool specialHandling) { - int32_t result = 0; - char cmd[LARGE_BUFFER_MAX_SIZE]; - char name1[SMALL_BUFFER_MAX_SIZE]; /* symlink file name */ - char name2[SMALL_BUFFER_MAX_SIZE]; /* file name to symlink */ - const char* FILE_EXTENSION_SEP = uprv_strlen(pkgDataFlags[SO_EXT]) == 0 ? "" : "."; - -#if U_PLATFORM != U_PF_CYGWIN - /* No symbolic link to make. */ - if (uprv_strlen(libFileNames[LIB_FILE_VERSION]) == 0 || uprv_strlen(libFileNames[LIB_FILE_VERSION_MAJOR]) == 0 || - uprv_strcmp(libFileNames[LIB_FILE_VERSION], libFileNames[LIB_FILE_VERSION_MAJOR]) == 0) { - return result; - } - - sprintf(cmd, "cd %s && %s %s && %s %s %s", - targetDir, - RM_CMD, - libFileNames[LIB_FILE_VERSION_MAJOR], - LN_CMD, - libFileNames[LIB_FILE_VERSION], - libFileNames[LIB_FILE_VERSION_MAJOR]); - result = runCommand(cmd); - if (result != 0) { - fprintf(stderr, "Error creating symbolic links. Failed command: %s\n", cmd); - return result; - } -#endif - - if (specialHandling) { -#if U_PLATFORM == U_PF_CYGWIN - sprintf(name1, "%s", libFileNames[LIB_FILE_CYGWIN]); - sprintf(name2, "%s", libFileNames[LIB_FILE_CYGWIN_VERSION]); -#elif U_PLATFORM == U_PF_OS390 - /* Create the symbolic links for the import data */ - /* Use the cmd buffer to store path to import data file to check its existence */ - sprintf(cmd, "%s/%s", targetDir, libFileNames[LIB_FILE_OS390BATCH_VERSION]); - if (T_FileStream_file_exists(cmd)) { - sprintf(cmd, "cd %s && %s %s && %s %s %s", - targetDir, - RM_CMD, - libFileNames[LIB_FILE_OS390BATCH_MAJOR], - LN_CMD, - libFileNames[LIB_FILE_OS390BATCH_VERSION], - libFileNames[LIB_FILE_OS390BATCH_MAJOR]); - result = runCommand(cmd); - if (result != 0) { - fprintf(stderr, "Error creating symbolic links. Failed command: %s\n", cmd); - return result; - } - - sprintf(cmd, "cd %s && %s %s.x && %s %s %s.x", - targetDir, - RM_CMD, - libFileNames[LIB_FILE], - LN_CMD, - libFileNames[LIB_FILE_OS390BATCH_VERSION], - libFileNames[LIB_FILE]); - result = runCommand(cmd); - if (result != 0) { - fprintf(stderr, "Error creating symbolic links. Failed command: %s\n", cmd); - return result; - } - } - - /* Needs to be set here because special handling skips it */ - sprintf(name1, "%s%s%s", libFileNames[LIB_FILE], FILE_EXTENSION_SEP, pkgDataFlags[SO_EXT]); - sprintf(name2, "%s", libFileNames[LIB_FILE_VERSION]); -#else - goto normal_symlink_mode; -#endif - } else { -#if U_PLATFORM != U_PF_CYGWIN -normal_symlink_mode: -#endif - sprintf(name1, "%s%s%s", libFileNames[LIB_FILE], FILE_EXTENSION_SEP, pkgDataFlags[SO_EXT]); - sprintf(name2, "%s", libFileNames[LIB_FILE_VERSION]); - } - - sprintf(cmd, "cd %s && %s %s && %s %s %s", - targetDir, - RM_CMD, - name1, - LN_CMD, - name2, - name1); - - result = runCommand(cmd); - - return result; -} - -static int32_t pkg_installLibrary(const char *installDir, const char *targetDir, UBool noVersion) { - int32_t result = 0; - char cmd[SMALL_BUFFER_MAX_SIZE]; - - sprintf(cmd, "cd %s && %s %s %s%s%s", - targetDir, - pkgDataFlags[INSTALL_CMD], - libFileNames[LIB_FILE_VERSION], - installDir, PKGDATA_FILE_SEP_STRING, libFileNames[LIB_FILE_VERSION] - ); - - result = runCommand(cmd); - - if (result != 0) { - fprintf(stderr, "Error installing library. Failed command: %s\n", cmd); - return result; - } - -#ifdef CYGWINMSVC - sprintf(cmd, "cd %s && %s %s.lib %s", - targetDir, - pkgDataFlags[INSTALL_CMD], - libFileNames[LIB_FILE], - installDir - ); - result = runCommand(cmd); - - if (result != 0) { - fprintf(stderr, "Error installing library. Failed command: %s\n", cmd); - return result; - } -#elif U_PLATFORM == U_PF_CYGWIN - sprintf(cmd, "cd %s && %s %s %s", - targetDir, - pkgDataFlags[INSTALL_CMD], - libFileNames[LIB_FILE_CYGWIN_VERSION], - installDir - ); - result = runCommand(cmd); - - if (result != 0) { - fprintf(stderr, "Error installing library. Failed command: %s\n", cmd); - return result; - } - -#elif U_PLATFORM == U_PF_OS390 - if (T_FileStream_file_exists(libFileNames[LIB_FILE_OS390BATCH_VERSION])) { - sprintf(cmd, "%s %s %s", - pkgDataFlags[INSTALL_CMD], - libFileNames[LIB_FILE_OS390BATCH_VERSION], - installDir - ); - result = runCommand(cmd); - - if (result != 0) { - fprintf(stderr, "Error installing library. Failed command: %s\n", cmd); - return result; - } - } -#endif - - if (noVersion) { - return result; - } else { - return pkg_createSymLinks(installDir, TRUE); - } -} - -static int32_t pkg_installCommonMode(const char *installDir, const char *fileName) { - int32_t result = 0; - char cmd[SMALL_BUFFER_MAX_SIZE] = ""; - - if (!T_FileStream_file_exists(installDir)) { - UErrorCode status = U_ZERO_ERROR; - - uprv_mkdir(installDir, &status); - if (U_FAILURE(status)) { - fprintf(stderr, "Error creating installation directory: %s\n", installDir); - return -1; - } - } -#ifndef U_WINDOWS_WITH_MSVC - sprintf(cmd, "%s %s %s", pkgDataFlags[INSTALL_CMD], fileName, installDir); -#else - sprintf(cmd, "%s %s %s %s", WIN_INSTALL_CMD, fileName, installDir, WIN_INSTALL_CMD_FLAGS); -#endif - - result = runCommand(cmd); - if (result != 0) { - fprintf(stderr, "Failed to install data file with command: %s\n", cmd); - } - - return result; -} - -#ifdef U_WINDOWS_MSVC -/* Copy commands for installing the raw data files on Windows. */ -#define WIN_INSTALL_CMD "xcopy" -#define WIN_INSTALL_CMD_FLAGS "/E /Y /K" -#endif -static int32_t pkg_installFileMode(const char *installDir, const char *srcDir, const char *fileListName) { - int32_t result = 0; - char cmd[SMALL_BUFFER_MAX_SIZE] = ""; - - if (!T_FileStream_file_exists(installDir)) { - UErrorCode status = U_ZERO_ERROR; - - uprv_mkdir(installDir, &status); - if (U_FAILURE(status)) { - fprintf(stderr, "Error creating installation directory: %s\n", installDir); - return -1; - } - } -#ifndef U_WINDOWS_WITH_MSVC - char buffer[SMALL_BUFFER_MAX_SIZE] = ""; - int32_t bufferLength = 0; - - FileStream *f = T_FileStream_open(fileListName, "r"); - if (f != NULL) { - for(;;) { - if (T_FileStream_readLine(f, buffer, SMALL_BUFFER_MAX_SIZE) != NULL) { - bufferLength = static_cast<int32_t>(uprv_strlen(buffer)); - /* Remove new line character. */ - if (bufferLength > 0) { - buffer[bufferLength-1] = 0; - } - - sprintf(cmd, "%s %s%s%s %s%s%s", - pkgDataFlags[INSTALL_CMD], - srcDir, PKGDATA_FILE_SEP_STRING, buffer, - installDir, PKGDATA_FILE_SEP_STRING, buffer); - - result = runCommand(cmd); - if (result != 0) { - fprintf(stderr, "Failed to install data file with command: %s\n", cmd); - break; - } - } else { - if (!T_FileStream_eof(f)) { - fprintf(stderr, "Failed to read line from file: %s\n", fileListName); - result = -1; - } - break; - } - } - T_FileStream_close(f); - } else { - result = -1; - fprintf(stderr, "Unable to open list file: %s\n", fileListName); - } -#else - sprintf(cmd, "%s %s %s %s", WIN_INSTALL_CMD, srcDir, installDir, WIN_INSTALL_CMD_FLAGS); - result = runCommand(cmd); - if (result != 0) { - fprintf(stderr, "Failed to install data file with command: %s\n", cmd); - } -#endif - - return result; -} - -/* Archiving of the library file may be needed depending on the platform and options given. - * If archiving is not needed, copy over the library file name. - */ -static int32_t pkg_archiveLibrary(const char *targetDir, const char *version, UBool reverseExt) { - int32_t result = 0; - char cmd[LARGE_BUFFER_MAX_SIZE]; - - /* If the shared object suffix and the final object suffix is different and the final object suffix and the - * archive file suffix is the same, then the final library needs to be archived. - */ - if (uprv_strcmp(pkgDataFlags[SOBJ_EXT], pkgDataFlags[SO_EXT]) != 0 && uprv_strcmp(pkgDataFlags[A_EXT], pkgDataFlags[SO_EXT]) == 0) { - sprintf(libFileNames[LIB_FILE_VERSION], "%s%s%s.%s", - libFileNames[LIB_FILE], - pkgDataFlags[LIB_EXT_ORDER][0] == '.' ? "." : "", - reverseExt ? version : pkgDataFlags[SO_EXT], - reverseExt ? pkgDataFlags[SO_EXT] : version); - - sprintf(cmd, "%s %s %s%s %s%s", - pkgDataFlags[AR], - pkgDataFlags[ARFLAGS], - targetDir, - libFileNames[LIB_FILE_VERSION], - targetDir, - libFileNames[LIB_FILE_VERSION_TMP]); - - result = runCommand(cmd); - if (result != 0) { - fprintf(stderr, "Error creating archive library. Failed command: %s\n", cmd); - return result; - } - - sprintf(cmd, "%s %s%s", - pkgDataFlags[RANLIB], - targetDir, - libFileNames[LIB_FILE_VERSION]); - - result = runCommand(cmd); - if (result != 0) { - fprintf(stderr, "Error creating archive library. Failed command: %s\n", cmd); - return result; - } - - /* Remove unneeded library file. */ - sprintf(cmd, "%s %s%s", - RM_CMD, - targetDir, - libFileNames[LIB_FILE_VERSION_TMP]); - - result = runCommand(cmd); - if (result != 0) { - fprintf(stderr, "Error creating archive library. Failed command: %s\n", cmd); - return result; - } - - } else { - uprv_strcpy(libFileNames[LIB_FILE_VERSION], libFileNames[LIB_FILE_VERSION_TMP]); - } - - return result; -} - -/* - * Using the compiler information from the configuration file set by -O option, generate the library file. - * command may be given to allow for a larger buffer for cmd. - */ -static int32_t pkg_generateLibraryFile(const char *targetDir, const char mode, const char *objectFile, char *command, UBool specialHandling) { - int32_t result = 0; - char *cmd = NULL; - UBool freeCmd = FALSE; - int32_t length = 0; - - (void)specialHandling; // Suppress unused variable compiler warnings on platforms where all usage - // of this parameter is #ifdefed out. - - /* This is necessary because if packaging is done without assembly code, objectFile might be extremely large - * containing many object files and so the calling function should supply a command buffer that is large - * enough to handle this. Otherwise, use the default size. - */ - if (command != NULL) { - cmd = command; - } - - if (IN_STATIC_MODE(mode)) { - if (cmd == NULL) { - length = uprv_strlen(pkgDataFlags[AR]) + uprv_strlen(pkgDataFlags[ARFLAGS]) + uprv_strlen(targetDir) + - uprv_strlen(libFileNames[LIB_FILE_VERSION]) + uprv_strlen(objectFile) + uprv_strlen(pkgDataFlags[RANLIB]) + BUFFER_PADDING_SIZE; - if ((cmd = (char *)uprv_malloc(sizeof(char) * length)) == NULL) { - fprintf(stderr, "Unable to allocate memory for command.\n"); - return -1; - } - freeCmd = TRUE; - } - sprintf(cmd, "%s %s %s%s %s", - pkgDataFlags[AR], - pkgDataFlags[ARFLAGS], - targetDir, - libFileNames[LIB_FILE_VERSION], - objectFile); - - result = runCommand(cmd); - if (result == 0) { - sprintf(cmd, "%s %s%s", - pkgDataFlags[RANLIB], - targetDir, - libFileNames[LIB_FILE_VERSION]); - - result = runCommand(cmd); - } - } else /* if (IN_DLL_MODE(mode)) */ { - if (cmd == NULL) { - length = uprv_strlen(pkgDataFlags[GENLIB]) + uprv_strlen(pkgDataFlags[LDICUDTFLAGS]) + - ((uprv_strlen(targetDir) + uprv_strlen(libFileNames[LIB_FILE_VERSION_TMP])) * 2) + - uprv_strlen(objectFile) + uprv_strlen(pkgDataFlags[LD_SONAME]) + - uprv_strlen(pkgDataFlags[LD_SONAME][0] == 0 ? "" : libFileNames[LIB_FILE_VERSION_MAJOR]) + - uprv_strlen(pkgDataFlags[RPATH_FLAGS]) + uprv_strlen(pkgDataFlags[BIR_FLAGS]) + BUFFER_PADDING_SIZE; -#if U_PLATFORM == U_PF_CYGWIN - length += uprv_strlen(targetDir) + uprv_strlen(libFileNames[LIB_FILE_CYGWIN_VERSION]); -#elif U_PLATFORM == U_PF_MINGW - length += uprv_strlen(targetDir) + uprv_strlen(libFileNames[LIB_FILE_MINGW]); -#endif - if ((cmd = (char *)uprv_malloc(sizeof(char) * length)) == NULL) { - fprintf(stderr, "Unable to allocate memory for command.\n"); - return -1; - } - freeCmd = TRUE; - } -#if U_PLATFORM == U_PF_MINGW - sprintf(cmd, "%s%s%s %s -o %s%s %s %s%s %s %s", - pkgDataFlags[GENLIB], - targetDir, - libFileNames[LIB_FILE_MINGW], - pkgDataFlags[LDICUDTFLAGS], - targetDir, - libFileNames[LIB_FILE_VERSION_TMP], -#elif U_PLATFORM == U_PF_CYGWIN - sprintf(cmd, "%s%s%s %s -o %s%s %s %s%s %s %s", - pkgDataFlags[GENLIB], - targetDir, - libFileNames[LIB_FILE_VERSION_TMP], - pkgDataFlags[LDICUDTFLAGS], - targetDir, - libFileNames[LIB_FILE_CYGWIN_VERSION], -#elif U_PLATFORM == U_PF_AIX - sprintf(cmd, "%s %s%s;%s %s -o %s%s %s %s%s %s %s", - RM_CMD, - targetDir, - libFileNames[LIB_FILE_VERSION_TMP], - pkgDataFlags[GENLIB], - pkgDataFlags[LDICUDTFLAGS], - targetDir, - libFileNames[LIB_FILE_VERSION_TMP], -#else - sprintf(cmd, "%s %s -o %s%s %s %s%s %s %s", - pkgDataFlags[GENLIB], - pkgDataFlags[LDICUDTFLAGS], - targetDir, - libFileNames[LIB_FILE_VERSION_TMP], -#endif - objectFile, - pkgDataFlags[LD_SONAME], - pkgDataFlags[LD_SONAME][0] == 0 ? "" : libFileNames[LIB_FILE_VERSION_MAJOR], - pkgDataFlags[RPATH_FLAGS], - pkgDataFlags[BIR_FLAGS]); - - /* Generate the library file. */ - result = runCommand(cmd); - -#if U_PLATFORM == U_PF_OS390 - char *env_tmp; - char PDS_LibName[512]; - char PDS_Name[512]; - - PDS_Name[0] = 0; - PDS_LibName[0] = 0; - if (specialHandling && uprv_strcmp(libFileNames[LIB_FILE],"libicudata") == 0) { - if (env_tmp = getenv("ICU_PDS_NAME")) { - sprintf(PDS_Name, "%s%s", - env_tmp, - "DA"); - strcat(PDS_Name, getenv("ICU_PDS_NAME_SUFFIX")); - } else if (env_tmp = getenv("PDS_NAME_PREFIX")) { - sprintf(PDS_Name, "%s%s", - env_tmp, - U_ICU_VERSION_SHORT "DA"); - } else { - sprintf(PDS_Name, "%s%s", - "IXMI", - U_ICU_VERSION_SHORT "DA"); - } - } else if (!specialHandling && uprv_strcmp(libFileNames[LIB_FILE],"libicudata_stub") == 0) { - if (env_tmp = getenv("ICU_PDS_NAME")) { - sprintf(PDS_Name, "%s%s", - env_tmp, - "D1"); - strcat(PDS_Name, getenv("ICU_PDS_NAME_SUFFIX")); - } else if (env_tmp = getenv("PDS_NAME_PREFIX")) { - sprintf(PDS_Name, "%s%s", - env_tmp, - U_ICU_VERSION_SHORT "D1"); - } else { - sprintf(PDS_Name, "%s%s", - "IXMI", - U_ICU_VERSION_SHORT "D1"); - } - } - - if (PDS_Name[0]) { - sprintf(PDS_LibName,"%s%s%s%s%s", - "\"//'", - getenv("LOADMOD"), - "(", - PDS_Name, - ")'\""); - sprintf(cmd, "%s %s -o %s %s %s%s %s %s", - pkgDataFlags[GENLIB], - pkgDataFlags[LDICUDTFLAGS], - PDS_LibName, - objectFile, - pkgDataFlags[LD_SONAME], - pkgDataFlags[LD_SONAME][0] == 0 ? "" : libFileNames[LIB_FILE_VERSION_MAJOR], - pkgDataFlags[RPATH_FLAGS], - pkgDataFlags[BIR_FLAGS]); - - result = runCommand(cmd); - } -#endif - } - - if (result != 0) { - fprintf(stderr, "Error generating library file. Failed command: %s\n", cmd); - } - - if (freeCmd) { - uprv_free(cmd); - } - - return result; -} - -static int32_t pkg_createWithAssemblyCode(const char *targetDir, const char mode, const char *gencFilePath) { - char tempObjectFile[SMALL_BUFFER_MAX_SIZE] = ""; - char *cmd; - int32_t result = 0; - - int32_t length = 0; - - /* Remove the ending .s and replace it with .o for the new object file. */ - uprv_strcpy(tempObjectFile, gencFilePath); - tempObjectFile[uprv_strlen(tempObjectFile)-1] = 'o'; - - length = uprv_strlen(pkgDataFlags[COMPILER]) + uprv_strlen(pkgDataFlags[LIBFLAGS]) - + uprv_strlen(tempObjectFile) + uprv_strlen(gencFilePath) + BUFFER_PADDING_SIZE; - - cmd = (char *)uprv_malloc(sizeof(char) * length); - if (cmd == NULL) { - return -1; - } - - /* Generate the object file. */ - sprintf(cmd, "%s %s -o %s %s", - pkgDataFlags[COMPILER], - pkgDataFlags[LIBFLAGS], - tempObjectFile, - gencFilePath); - - result = runCommand(cmd); - uprv_free(cmd); - if (result != 0) { - fprintf(stderr, "Error creating with assembly code. Failed command: %s\n", cmd); - return result; - } - - return pkg_generateLibraryFile(targetDir, mode, tempObjectFile); -} - -#ifdef BUILD_DATA_WITHOUT_ASSEMBLY -/* - * Generation of the data library without assembly code needs to compile each data file - * individually and then link it all together. - * Note: Any update to the directory structure of the data needs to be reflected here. - */ -enum { - DATA_PREFIX_BRKITR, - DATA_PREFIX_COLL, - DATA_PREFIX_CURR, - DATA_PREFIX_LANG, - DATA_PREFIX_RBNF, - DATA_PREFIX_REGION, - DATA_PREFIX_TRANSLIT, - DATA_PREFIX_ZONE, - DATA_PREFIX_UNIT, - DATA_PREFIX_LENGTH -}; - -const static char DATA_PREFIX[DATA_PREFIX_LENGTH][10] = { - "brkitr", - "coll", - "curr", - "lang", - "rbnf", - "region", - "translit", - "zone", - "unit" -}; - -static int32_t pkg_createWithoutAssemblyCode(UPKGOptions *o, const char *targetDir, const char mode) { - int32_t result = 0; - CharList *list = o->filePaths; - CharList *listNames = o->files; - int32_t listSize = pkg_countCharList(list); - char *buffer; - char *cmd; - char gencmnFile[SMALL_BUFFER_MAX_SIZE] = ""; - char tempObjectFile[SMALL_BUFFER_MAX_SIZE] = ""; -#ifdef USE_SINGLE_CCODE_FILE - char icudtAll[SMALL_BUFFER_MAX_SIZE] = ""; - FileStream *icudtAllFile = NULL; - - sprintf(icudtAll, "%s%s%sall.c", - o->tmpDir, - PKGDATA_FILE_SEP_STRING, - libFileNames[LIB_FILE]); - /* Remove previous icudtall.c file. */ - if (T_FileStream_file_exists(icudtAll) && (result = remove(icudtAll)) != 0) { - fprintf(stderr, "Unable to remove old icudtall file: %s\n", icudtAll); - return result; - } - - if((icudtAllFile = T_FileStream_open(icudtAll, "w"))==NULL) { - fprintf(stderr, "Unable to write to icudtall file: %s\n", icudtAll); - return result; - } -#endif - - if (list == NULL || listNames == NULL) { - /* list and listNames should never be NULL since we are looping through the CharList with - * the given size. - */ - return -1; - } - - if ((cmd = (char *)uprv_malloc((listSize + 2) * SMALL_BUFFER_MAX_SIZE)) == NULL) { - fprintf(stderr, "Unable to allocate memory for cmd.\n"); - return -1; - } else if ((buffer = (char *)uprv_malloc((listSize + 1) * SMALL_BUFFER_MAX_SIZE)) == NULL) { - fprintf(stderr, "Unable to allocate memory for buffer.\n"); - uprv_free(cmd); - return -1; - } - - for (int32_t i = 0; i < (listSize + 1); i++) { - const char *file ; - const char *name; - - if (i == 0) { - /* The first iteration calls the gencmn function and initailizes the buffer. */ - createCommonDataFile(o->tmpDir, o->shortName, o->entryName, NULL, o->srcDir, o->comment, o->fileListFiles->str, 0, TRUE, o->verbose, gencmnFile); - buffer[0] = 0; -#ifdef USE_SINGLE_CCODE_FILE - uprv_strcpy(tempObjectFile, gencmnFile); - tempObjectFile[uprv_strlen(tempObjectFile) - 1] = 'o'; - - sprintf(cmd, "%s %s -o %s %s", - pkgDataFlags[COMPILER], - pkgDataFlags[LIBFLAGS], - tempObjectFile, - gencmnFile); - - result = runCommand(cmd); - if (result != 0) { - break; - } - - sprintf(buffer, "%s",tempObjectFile); -#endif - } else { - char newName[SMALL_BUFFER_MAX_SIZE]; - char dataName[SMALL_BUFFER_MAX_SIZE]; - char dataDirName[SMALL_BUFFER_MAX_SIZE]; - const char *pSubstring; - file = list->str; - name = listNames->str; - - newName[0] = dataName[0] = 0; - for (int32_t n = 0; n < DATA_PREFIX_LENGTH; n++) { - dataDirName[0] = 0; - sprintf(dataDirName, "%s%s", DATA_PREFIX[n], PKGDATA_FILE_SEP_STRING); - /* If the name contains a prefix (indicating directory), alter the new name accordingly. */ - pSubstring = uprv_strstr(name, dataDirName); - if (pSubstring != NULL) { - char newNameTmp[SMALL_BUFFER_MAX_SIZE] = ""; - const char *p = name + uprv_strlen(dataDirName); - for (int32_t i = 0;;i++) { - if (p[i] == '.') { - newNameTmp[i] = '_'; - continue; - } - newNameTmp[i] = p[i]; - if (p[i] == 0) { - break; - } - } - sprintf(newName, "%s_%s", - DATA_PREFIX[n], - newNameTmp); - sprintf(dataName, "%s_%s", - o->shortName, - DATA_PREFIX[n]); - } - if (newName[0] != 0) { - break; - } - } - - if(o->verbose) { - printf("# Generating %s \n", gencmnFile); - } - - writeCCode(file, o->tmpDir, dataName[0] != 0 ? dataName : o->shortName, newName[0] != 0 ? newName : NULL, gencmnFile); - -#ifdef USE_SINGLE_CCODE_FILE - sprintf(cmd, "#include \"%s\"\n", gencmnFile); - T_FileStream_writeLine(icudtAllFile, cmd); - /* don't delete the file */ -#endif - } - -#ifndef USE_SINGLE_CCODE_FILE - uprv_strcpy(tempObjectFile, gencmnFile); - tempObjectFile[uprv_strlen(tempObjectFile) - 1] = 'o'; - - sprintf(cmd, "%s %s -o %s %s", - pkgDataFlags[COMPILER], - pkgDataFlags[LIBFLAGS], - tempObjectFile, - gencmnFile); - result = runCommand(cmd); - if (result != 0) { - fprintf(stderr, "Error creating library without assembly code. Failed command: %s\n", cmd); - break; - } - - uprv_strcat(buffer, " "); - uprv_strcat(buffer, tempObjectFile); - -#endif - - if (i > 0) { - list = list->next; - listNames = listNames->next; - } - } - -#ifdef USE_SINGLE_CCODE_FILE - T_FileStream_close(icudtAllFile); - uprv_strcpy(tempObjectFile, icudtAll); - tempObjectFile[uprv_strlen(tempObjectFile) - 1] = 'o'; - - sprintf(cmd, "%s %s -I. -o %s %s", - pkgDataFlags[COMPILER], - pkgDataFlags[LIBFLAGS], - tempObjectFile, - icudtAll); - - result = runCommand(cmd); - if (result == 0) { - uprv_strcat(buffer, " "); - uprv_strcat(buffer, tempObjectFile); - } else { - fprintf(stderr, "Error creating library without assembly code. Failed command: %s\n", cmd); - } -#endif - - if (result == 0) { - /* Generate the library file. */ -#if U_PLATFORM == U_PF_OS390 - result = pkg_generateLibraryFile(targetDir, mode, buffer, cmd, (o->pdsbuild && IN_DLL_MODE(mode))); -#else - result = pkg_generateLibraryFile(targetDir,mode, buffer, cmd); -#endif - } - - uprv_free(buffer); - uprv_free(cmd); - - return result; -} -#endif - -#ifdef WINDOWS_WITH_MSVC -#define LINK_CMD "link.exe /nologo /release /out:" -#define LINK_FLAGS "/DLL /NOENTRY /MANIFEST:NO /implib:" -#ifdef _WIN64 -#define LINK_EXTRA_UWP_FLAGS "/NXCOMPAT /DYNAMICBASE /APPCONTAINER " -#else -#define LINK_EXTRA_UWP_FLAGS "/NXCOMPAT /SAFESEH /DYNAMICBASE /APPCONTAINER /MACHINE:X86" -#endif -#define LINK_EXTRA_UWP_FLAGS_ARM "/NXCOMPAT /DYNAMICBASE /APPCONTAINER /MACHINE:ARM" -#define LINK_EXTRA_NO_UWP_FLAGS "/base:0x4ad00000 " -#define LIB_CMD "LIB.exe /nologo /out:" -#define LIB_FILE "icudt.lib" -#define LIB_EXT UDATA_LIB_SUFFIX -#define DLL_EXT UDATA_SO_SUFFIX - -static int32_t pkg_createWindowsDLL(const char mode, const char *gencFilePath, UPKGOptions *o) { - int32_t result = 0; - char cmd[LARGE_BUFFER_MAX_SIZE]; - if (IN_STATIC_MODE(mode)) { - char staticLibFilePath[SMALL_BUFFER_MAX_SIZE] = ""; - -#ifdef CYGWINMSVC - sprintf(staticLibFilePath, "%s%s%s%s%s", - o->targetDir, - PKGDATA_FILE_SEP_STRING, - pkgDataFlags[LIBPREFIX], - o->libName, - LIB_EXT); -#else - sprintf(staticLibFilePath, "%s%s%s%s%s", - o->targetDir, - PKGDATA_FILE_SEP_STRING, - (strstr(o->libName, "icudt") ? "s" : ""), - o->libName, - LIB_EXT); -#endif - - sprintf(cmd, "%s\"%s\" \"%s\"", - LIB_CMD, - staticLibFilePath, - gencFilePath); - } else if (IN_DLL_MODE(mode)) { - char dllFilePath[SMALL_BUFFER_MAX_SIZE] = ""; - char libFilePath[SMALL_BUFFER_MAX_SIZE] = ""; - char resFilePath[SMALL_BUFFER_MAX_SIZE] = ""; - char tmpResFilePath[SMALL_BUFFER_MAX_SIZE] = ""; - -#ifdef CYGWINMSVC - uprv_strcpy(dllFilePath, o->targetDir); -#else - uprv_strcpy(dllFilePath, o->srcDir); -#endif - uprv_strcat(dllFilePath, PKGDATA_FILE_SEP_STRING); - uprv_strcpy(libFilePath, dllFilePath); - -#ifdef CYGWINMSVC - uprv_strcat(libFilePath, o->libName); - uprv_strcat(libFilePath, ".lib"); - - uprv_strcat(dllFilePath, o->libName); - uprv_strcat(dllFilePath, o->version); -#else - if (strstr(o->libName, "icudt")) { - uprv_strcat(libFilePath, LIB_FILE); - } else { - uprv_strcat(libFilePath, o->libName); - uprv_strcat(libFilePath, ".lib"); - } - uprv_strcat(dllFilePath, o->entryName); -#endif - uprv_strcat(dllFilePath, DLL_EXT); - - uprv_strcpy(tmpResFilePath, o->tmpDir); - uprv_strcat(tmpResFilePath, PKGDATA_FILE_SEP_STRING); - uprv_strcat(tmpResFilePath, ICUDATA_RES_FILE); - - if (T_FileStream_file_exists(tmpResFilePath)) { - sprintf(resFilePath, "\"%s\"", tmpResFilePath); - } - - /* Check if dll file and lib file exists and that it is not newer than genc file. */ - if (!o->rebuild && (T_FileStream_file_exists(dllFilePath) && isFileModTimeLater(dllFilePath, gencFilePath)) && - (T_FileStream_file_exists(libFilePath) && isFileModTimeLater(libFilePath, gencFilePath))) { - if(o->verbose) { - printf("# Not rebuilding %s - up to date.\n", gencFilePath); - } - return 0; - } - - char *extraFlags = ""; -#ifdef WINDOWS_WITH_MSVC - if (options[UWP_BUILD].doesOccur) - { - if (options[UWP_ARM_BUILD].doesOccur) - { - extraFlags = LINK_EXTRA_UWP_FLAGS_ARM; - } - else - { - extraFlags = LINK_EXTRA_UWP_FLAGS; - } - } - else - { - extraFlags = LINK_EXTRA_NO_UWP_FLAGS; - } -#endif - sprintf(cmd, "%s\"%s\" %s %s\"%s\" \"%s\" %s", - LINK_CMD, - dllFilePath, - extraFlags, - LINK_FLAGS, - libFilePath, - gencFilePath, - resFilePath - ); - } - - result = runCommand(cmd, TRUE); - if (result != 0) { - fprintf(stderr, "Error creating Windows DLL library. Failed command: %s\n", cmd); - } - - return result; -} -#endif - -static UPKGOptions *pkg_checkFlag(UPKGOptions *o) { -#if U_PLATFORM == U_PF_AIX - /* AIX needs a map file. */ - char *flag = NULL; - int32_t length = 0; - char tmpbuffer[SMALL_BUFFER_MAX_SIZE]; - const char MAP_FILE_EXT[] = ".map"; - FileStream *f = NULL; - char mapFile[SMALL_BUFFER_MAX_SIZE] = ""; - int32_t start = -1; - uint32_t count = 0; - const char rm_cmd[] = "rm -f all ;"; - - flag = pkgDataFlags[GENLIB]; - - /* This portion of the code removes 'rm -f all' in the GENLIB. - * Only occurs in AIX. - */ - if (uprv_strstr(flag, rm_cmd) != NULL) { - char *tmpGenlibFlagBuffer = NULL; - int32_t i, offset; - - length = uprv_strlen(flag) + 1; - tmpGenlibFlagBuffer = (char *)uprv_malloc(length); - if (tmpGenlibFlagBuffer == NULL) { - /* Memory allocation error */ - fprintf(stderr,"Unable to allocate buffer of size: %d.\n", length); - return NULL; - } - - uprv_strcpy(tmpGenlibFlagBuffer, flag); - - offset = uprv_strlen(rm_cmd); - - for (i = 0; i < (length - offset); i++) { - flag[i] = tmpGenlibFlagBuffer[offset + i]; - } - - /* Zero terminate the string */ - flag[i] = 0; - - uprv_free(tmpGenlibFlagBuffer); - } - - flag = pkgDataFlags[BIR_FLAGS]; - length = uprv_strlen(pkgDataFlags[BIR_FLAGS]); - - for (int32_t i = 0; i < length; i++) { - if (flag[i] == MAP_FILE_EXT[count]) { - if (count == 0) { - start = i; - } - count++; - } else { - count = 0; - } - - if (count == uprv_strlen(MAP_FILE_EXT)) { - break; - } - } - - if (start >= 0) { - int32_t index = 0; - for (int32_t i = 0;;i++) { - if (i == start) { - for (int32_t n = 0;;n++) { - if (o->shortName[n] == 0) { - break; - } - tmpbuffer[index++] = o->shortName[n]; - } - } - - tmpbuffer[index++] = flag[i]; - - if (flag[i] == 0) { - break; - } - } - - uprv_memset(flag, 0, length); - uprv_strcpy(flag, tmpbuffer); - - uprv_strcpy(mapFile, o->shortName); - uprv_strcat(mapFile, MAP_FILE_EXT); - - f = T_FileStream_open(mapFile, "w"); - if (f == NULL) { - fprintf(stderr,"Unable to create map file: %s.\n", mapFile); - return NULL; - } else { - sprintf(tmpbuffer, "%s%s ", o->entryName, UDATA_CMN_INTERMEDIATE_SUFFIX); - - T_FileStream_writeLine(f, tmpbuffer); - - T_FileStream_close(f); - } - } -#elif U_PLATFORM == U_PF_CYGWIN || U_PLATFORM == U_PF_MINGW - /* Cygwin needs to change flag options. */ - char *flag = NULL; - int32_t length = 0; - - flag = pkgDataFlags[GENLIB]; - length = uprv_strlen(pkgDataFlags[GENLIB]); - - int32_t position = length - 1; - - for(;position >= 0;position--) { - if (flag[position] == '=') { - position++; - break; - } - } - - uprv_memset(flag + position, 0, length - position); -#elif U_PLATFORM == U_PF_OS400 - /* OS/400 needs to fix the ld options (swap single quote with double quote) */ - char *flag = NULL; - int32_t length = 0; - - flag = pkgDataFlags[GENLIB]; - length = uprv_strlen(pkgDataFlags[GENLIB]); - - int32_t position = length - 1; - - for(int32_t i = 0; i < length; i++) { - if (flag[i] == '\'') { - flag[i] = '\"'; - } - } -#endif - // Don't really need a return value, just need to stop compiler warnings about - // the unused parameter 'o' on platforms where it is not otherwise used. - return o; -} - -static void loadLists(UPKGOptions *o, UErrorCode *status) -{ - CharList *l, *tail = NULL, *tail2 = NULL; - FileStream *in; - char line[16384]; - char *linePtr, *lineNext; - const uint32_t lineMax = 16300; - char *tmp; - int32_t tmpLength = 0; - char *s; - int32_t ln=0; /* line number */ - - for(l = o->fileListFiles; l; l = l->next) { - if(o->verbose) { - fprintf(stdout, "# pkgdata: Reading %s..\n", l->str); - } - /* TODO: stdin */ - in = T_FileStream_open(l->str, "r"); /* open files list */ - - if(!in) { - fprintf(stderr, "Error opening <%s>.\n", l->str); - *status = U_FILE_ACCESS_ERROR; - return; - } - - while(T_FileStream_readLine(in, line, sizeof(line))!=NULL) { /* for each line */ - ln++; - if(uprv_strlen(line)>lineMax) { - fprintf(stderr, "%s:%d - line too long (over %d chars)\n", l->str, (int)ln, (int)lineMax); - exit(1); - } - /* remove spaces at the beginning */ - linePtr = line; - /* On z/OS, disable call to isspace (#9996). Investigate using uprv_isspace instead (#9999) */ -#if U_PLATFORM != U_PF_OS390 - while(isspace(*linePtr)) { - linePtr++; - } -#endif - s=linePtr; - /* remove trailing newline characters */ - while(*s!=0) { - if(*s=='\r' || *s=='\n') { - *s=0; - break; - } - ++s; - } - if((*linePtr == 0) || (*linePtr == '#')) { - continue; /* comment or empty line */ - } - - /* Now, process the line */ - lineNext = NULL; - - while(linePtr && *linePtr) { /* process space-separated items */ - while(*linePtr == ' ') { - linePtr++; - } - /* Find the next quote */ - if(linePtr[0] == '"') - { - lineNext = uprv_strchr(linePtr+1, '"'); - if(lineNext == NULL) { - fprintf(stderr, "%s:%d - missing trailing double quote (\")\n", - l->str, (int)ln); - exit(1); - } else { - lineNext++; - if(*lineNext) { - if(*lineNext != ' ') { - fprintf(stderr, "%s:%d - malformed quoted line at position %d, expected ' ' got '%c'\n", - l->str, (int)ln, (int)(lineNext-line), (*lineNext)?*lineNext:'0'); - exit(1); - } - *lineNext = 0; - lineNext++; - } - } - } else { - lineNext = uprv_strchr(linePtr, ' '); - if(lineNext) { - *lineNext = 0; /* terminate at space */ - lineNext++; - } - } - - /* add the file */ - s = (char*)getLongPathname(linePtr); - - /* normal mode.. o->files is just the bare list without package names */ - o->files = pkg_appendToList(o->files, &tail, uprv_strdup(linePtr)); - if(uprv_pathIsAbsolute(s) || s[0] == '.') { - fprintf(stderr, "pkgdata: Error: absolute path encountered. Old style paths are not supported. Use relative paths such as 'fur.res' or 'translit%cfur.res'.\n\tBad path: '%s'\n", U_FILE_SEP_CHAR, s); - exit(U_ILLEGAL_ARGUMENT_ERROR); - } - tmpLength = uprv_strlen(o->srcDir) + - uprv_strlen(s) + 5; /* 5 is to add a little extra space for, among other things, PKGDATA_FILE_SEP_STRING */ - if((tmp = (char *)uprv_malloc(tmpLength)) == NULL) { - fprintf(stderr, "pkgdata: Error: Unable to allocate tmp buffer size: %d\n", tmpLength); - exit(U_MEMORY_ALLOCATION_ERROR); - } - uprv_strcpy(tmp, o->srcDir); - uprv_strcat(tmp, o->srcDir[uprv_strlen(o->srcDir)-1] == U_FILE_SEP_CHAR ? "" : PKGDATA_FILE_SEP_STRING); - uprv_strcat(tmp, s); - o->filePaths = pkg_appendToList(o->filePaths, &tail2, tmp); - linePtr = lineNext; - } /* for each entry on line */ - } /* for each line */ - T_FileStream_close(in); - } /* for each file list file */ -} - -/* Try calling icu-config directly to get the option file. */ - static int32_t pkg_getOptionsFromICUConfig(UBool verbose, UOption *option) { -#if U_HAVE_POPEN - LocalPipeFilePointer p; - size_t n; - static char buf[512] = ""; - icu::CharString cmdBuf; - UErrorCode status = U_ZERO_ERROR; - const char cmd[] = "icu-config --incpkgdatafile"; - char dirBuf[1024] = ""; - /* #1 try the same path where pkgdata was called from. */ - findDirname(progname, dirBuf, UPRV_LENGTHOF(dirBuf), &status); - if(U_SUCCESS(status)) { - cmdBuf.append(dirBuf, status); - if (cmdBuf[0] != 0) { - cmdBuf.append( U_FILE_SEP_STRING, status ); - } - cmdBuf.append( cmd, status ); - - if(verbose) { - fprintf(stdout, "# Calling icu-config: %s\n", cmdBuf.data()); - } - p.adoptInstead(popen(cmdBuf.data(), "r")); - } - - if(p.isNull() || (n = fread(buf, 1, UPRV_LENGTHOF(buf)-1, p.getAlias())) <= 0) { - if(verbose) { - fprintf(stdout, "# Calling icu-config: %s\n", cmd); - } - - p.adoptInstead(popen(cmd, "r")); - if(p.isNull() || (n = fread(buf, 1, UPRV_LENGTHOF(buf)-1, p.getAlias())) <= 0) { - fprintf(stderr, "%s: icu-config: No icu-config found. (fix PATH or use -O option)\n", progname); - return -1; - } - } - - for (int32_t length = strlen(buf) - 1; length >= 0; length--) { - if (buf[length] == '\n' || buf[length] == ' ') { - buf[length] = 0; - } else { - break; - } - } - - if(buf[strlen(buf)-1]=='\n') - { - buf[strlen(buf)-1]=0; - } - - if(buf[0] == 0) - { - fprintf(stderr, "%s: icu-config: invalid response from icu-config (fix PATH or use -O option)\n", progname); - return -1; - } - - if(verbose) { - fprintf(stdout, "# icu-config said: %s\n", buf); - } - - option->value = buf; - option->doesOccur = TRUE; - - return 0; -#else - return -1; -#endif -} - -#ifdef CAN_WRITE_OBJ_CODE - /* Create optMatchArch for genccode architecture detection */ -static void pkg_createOptMatchArch(char *optMatchArch) { -#if !defined(WINDOWS_WITH_MSVC) || defined(USING_CYGWIN) - const char* code = "void oma(){}"; - const char* source = "oma.c"; - const char* obj = "oma.obj"; - FileStream* stream = NULL; - - stream = T_FileStream_open(source,"w"); - if (stream != NULL) { - T_FileStream_writeLine(stream, code); - T_FileStream_close(stream); - - char cmd[LARGE_BUFFER_MAX_SIZE]; - sprintf(cmd, "%s %s -o %s", - pkgDataFlags[COMPILER], - source, - obj); - - if (runCommand(cmd) == 0){ - sprintf(optMatchArch, "%s", obj); - } - else { - fprintf(stderr, "Failed to compile %s\n", source); - } - if(!T_FileStream_remove(source)){ - fprintf(stderr, "T_FileStream_remove failed to delete %s\n", source); - } - } - else { - fprintf(stderr, "T_FileStream_open failed to open %s for writing\n", source); - } -#endif -} -static void pkg_destroyOptMatchArch(char *optMatchArch) { - if(T_FileStream_file_exists(optMatchArch) && !T_FileStream_remove(optMatchArch)){ - fprintf(stderr, "T_FileStream_remove failed to delete %s\n", optMatchArch); - } -} -#endif diff --git a/deps/node/deps/icu-small/source/tools/pkgdata/pkgtypes.c b/deps/node/deps/icu-small/source/tools/pkgdata/pkgtypes.c deleted file mode 100644 index 43ee3dfb..00000000 --- a/deps/node/deps/icu-small/source/tools/pkgdata/pkgtypes.c +++ /dev/null @@ -1,302 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/************************************************************************** -* -* Copyright (C) 2000-2016, International Business Machines -* Corporation and others. All Rights Reserved. -* -*************************************************************************** -* file name: pkgdata.c -* encoding: ANSI X3.4 (1968) -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2000may16 -* created by: Steven \u24C7 Loomis -* -* common types for pkgdata -*/ - -#include <stdio.h> -#include <stdlib.h> -#include "unicode/utypes.h" -#include "unicode/putil.h" -#include "cmemory.h" -#include "cstring.h" -#include "pkgtypes.h" -#include "putilimp.h" - -const char *pkg_writeCharListWrap(FileStream *s, CharList *l, const char *delim, const char *brk, int32_t quote) -{ - int32_t ln = 0; - char buffer[1024]; - while(l != NULL) - { - if(l->str) - { - uprv_strncpy(buffer, l->str, 1020); - buffer[1019]=0; - - if(quote < 0) { /* remove quotes */ - if(buffer[uprv_strlen(buffer)-1] == '"') { - buffer[uprv_strlen(buffer)-1] = '\0'; - } - if(buffer[0] == '"') { - uprv_strcpy(buffer, buffer+1); - } - } else if(quote > 0) { /* add quotes */ - if(l->str[0] != '"') { - uprv_strcpy(buffer, "\""); - uprv_strncat(buffer, l->str,1020); - } - if(l->str[uprv_strlen(l->str)-1] != '"') { - uprv_strcat(buffer, "\""); - } - } - T_FileStream_write(s, buffer, (int32_t)uprv_strlen(buffer)); - - ln += (int32_t)uprv_strlen(l->str); - } - - if(l->next && delim) - { - if(ln > 60 && brk) { - ln = 0; - T_FileStream_write(s, brk, (int32_t)uprv_strlen(brk)); - } - T_FileStream_write(s, delim, (int32_t)uprv_strlen(delim)); - } - l = l->next; - } - return NULL; -} - - -const char *pkg_writeCharList(FileStream *s, CharList *l, const char *delim, int32_t quote) -{ - char buffer[1024]; - while(l != NULL) - { - if(l->str) - { - uprv_strncpy(buffer, l->str, 1023); - buffer[1023]=0; - if(uprv_strlen(l->str) >= 1023) - { - fprintf(stderr, "%s:%d: Internal error, line too long (greater than 1023 chars)\n", - __FILE__, __LINE__); - exit(0); - } - if(quote < 0) { /* remove quotes */ - if(buffer[uprv_strlen(buffer)-1] == '"') { - buffer[uprv_strlen(buffer)-1] = '\0'; - } - if(buffer[0] == '"') { - uprv_strcpy(buffer, buffer+1); - } - } else if(quote > 0) { /* add quotes */ - if(l->str[0] != '"') { - uprv_strcpy(buffer, "\""); - uprv_strcat(buffer, l->str); - } - if(l->str[uprv_strlen(l->str)-1] != '"') { - uprv_strcat(buffer, "\""); - } - } - T_FileStream_write(s, buffer, (int32_t)uprv_strlen(buffer)); - } - - if(l->next && delim) - { - T_FileStream_write(s, delim, (int32_t)uprv_strlen(delim)); - } - l = l->next; - } - return NULL; -} - - -/* - * Count items . 0 if null - */ -uint32_t pkg_countCharList(CharList *l) -{ - uint32_t c = 0; - while(l != NULL) - { - c++; - l = l->next; - } - - return c; -} - -/* - * Prepend string to CharList - */ -CharList *pkg_prependToList(CharList *l, const char *str) -{ - CharList *newList; - newList = uprv_malloc(sizeof(CharList)); - - /* test for NULL */ - if(newList == NULL) { - return NULL; - } - - newList->str = str; - newList->next = l; - return newList; -} - -/* - * append string to CharList. *end or even end can be null if you don't - * know it.[slow] - * Str is adopted! - */ -CharList *pkg_appendToList(CharList *l, CharList** end, const char *str) -{ - CharList *endptr = NULL, *tmp; - - if(end == NULL) - { - end = &endptr; - } - - /* FIND the end */ - if((*end == NULL) && (l != NULL)) - { - tmp = l; - while(tmp->next) - { - tmp = tmp->next; - } - - *end = tmp; - } - - /* Create a new empty list and append it */ - if(l == NULL) - { - l = pkg_prependToList(NULL, str); - } - else - { - (*end)->next = pkg_prependToList(NULL, str); - } - - /* Move the end pointer. */ - if(*end) - { - (*end) = (*end)->next; - } - else - { - *end = l; - } - - return l; -} - -char * convertToNativePathSeparators(char *path) { -#if defined(U_MAKE_IS_NMAKE) - char *itr; - while ((itr = uprv_strchr(path, U_FILE_ALT_SEP_CHAR))) { - *itr = U_FILE_SEP_CHAR; - } -#endif - return path; -} - -CharList *pkg_appendUniqueDirToList(CharList *l, CharList** end, const char *strAlias) { - char aBuf[1024]; - char *rPtr; - rPtr = uprv_strrchr(strAlias, U_FILE_SEP_CHAR); -#if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR) - { - char *aPtr = uprv_strrchr(strAlias, U_FILE_ALT_SEP_CHAR); - if(!rPtr || /* regular char wasn't found or.. */ - (aPtr && (aPtr > rPtr))) - { /* alt ptr exists and is to the right of r ptr */ - rPtr = aPtr; /* may copy NULL which is OK */ - } - } -#endif - if(!rPtr) { - return l; /* no dir path */ - } - if((rPtr-strAlias) >= UPRV_LENGTHOF(aBuf)) { - fprintf(stderr, "## ERR: Path too long [%d chars]: %s\n", (int)sizeof(aBuf), strAlias); - return l; - } - strncpy(aBuf, strAlias,(rPtr-strAlias)); - aBuf[rPtr-strAlias]=0; /* no trailing slash */ - convertToNativePathSeparators(aBuf); - - if(!pkg_listContains(l, aBuf)) { - return pkg_appendToList(l, end, uprv_strdup(aBuf)); - } else { - return l; /* already found */ - } -} - -#if 0 -static CharList * -pkg_appendFromStrings(CharList *l, CharList** end, const char *s, int32_t len) -{ - CharList *endptr = NULL; - const char *p; - char *t; - const char *targ; - if(end == NULL) { - end = &endptr; - } - - if(len==-1) { - len = uprv_strlen(s); - } - targ = s+len; - - while(*s && s<targ) { - while(s<targ&&isspace(*s)) s++; - for(p=s;s<targ&&!isspace(*p);p++); - if(p!=s) { - t = uprv_malloc(p-s+1); - uprv_strncpy(t,s,p-s); - t[p-s]=0; - l=pkg_appendToList(l,end,t); - fprintf(stderr, " P %s\n", t); - } - s=p; - } - - return l; -} -#endif - - -/* - * Delete list - */ -void pkg_deleteList(CharList *l) -{ - CharList *tmp; - while(l != NULL) - { - uprv_free((void*)l->str); - tmp = l; - l = l->next; - uprv_free(tmp); - } -} - -UBool pkg_listContains(CharList *l, const char *str) -{ - for(;l;l=l->next){ - if(!uprv_strcmp(l->str, str)) { - return TRUE; - } - } - - return FALSE; -} diff --git a/deps/node/deps/icu-small/source/tools/pkgdata/pkgtypes.h b/deps/node/deps/icu-small/source/tools/pkgdata/pkgtypes.h deleted file mode 100644 index 3297d0a2..00000000 --- a/deps/node/deps/icu-small/source/tools/pkgdata/pkgtypes.h +++ /dev/null @@ -1,172 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/************************************************************************** -* -* Copyright (C) 2000-2012, International Business Machines -* Corporation and others. All Rights Reserved. -* -*************************************************************************** -* file name: pkgdata.c -* encoding: ANSI X3.4 (1968) -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2000may16 -* created by: Steven \u24C7 Loomis -* -* common types for pkgdata -*/ - -#ifndef _PKGTYPES -#define _PKGTYPES - -/* headers */ -#include "unicode/utypes.h" -#include "filestrm.h" - -/* linked list */ -struct _CharList; - -typedef struct _CharList -{ - const char *str; - struct _CharList *next; -} CharList; - - - -/* - * write CharList 'l' into stream 's' using deliminter 'delim' (delim can be NULL). quoted: -1 remove, 0 as is, 1 add quotes - */ -const char *pkg_writeCharList(FileStream *s, CharList *l, const char *delim, int32_t quoted); - -/* - * Same, but use line breaks. quoted: -1 remove, 0 as is, 1 add quotes - */ -const char *pkg_writeCharListWrap(FileStream *s, CharList *l, const char *delim, const char *brk, int32_t quoted); - - -/* - * Count items . 0 if null - */ -uint32_t pkg_countCharList(CharList *l); - -/* - * Prepend string to CharList. Str is adopted! - */ -CharList *pkg_prependToList(CharList *l, const char *str); - -/* - * append string to CharList. *end or even end can be null if you don't - * know it.[slow] - * Str is adopted! - */ -CharList *pkg_appendToList(CharList *l, CharList** end, const char *str); - -/* - * strAlias is an alias to a full or relative path to a FILE. This function - * will search strAlias for the directory name (with strrchr). Then, it will - * determine if that directory is already in list l. If not, it will add it - * with strdup(strAlias). - * @param l list to append to , or NULL - * @param end end pointer-to-pointer. Can point to null, or be null. - * @param strAlias alias to full path string - * @return new list - */ -CharList *pkg_appendUniqueDirToList(CharList *l, CharList** end, const char *strAlias); - -/* - * does list contain string? Returns: t/f - */ -UBool pkg_listContains(CharList *l, const char *str); - -/* - * Delete list - */ -void pkg_deleteList(CharList *l); - -/* - * Mode package function - */ -struct UPKGOptions_; -typedef void (UPKGMODE)(struct UPKGOptions_ *, FileStream *s, UErrorCode *status); - -/* - * Static mode - write the readme file - * @param opt UPKGOptions - * @param libName Name of the .lib, etc file - * @param status ICU error code - */ -void pkg_sttc_writeReadme(struct UPKGOptions_ *opt, const char *libName, UErrorCode *status); - -/* - * Options to be passed throughout the program - */ - -typedef struct UPKGOptions_ -{ - CharList *fileListFiles; /* list of files containing files for inclusion in the package */ - CharList *filePaths; /* All the files, with long paths */ - CharList *files; /* All the files */ - CharList *outFiles; /* output files [full paths] */ - - const char *shortName; /* name of what we're building */ - const char *cShortName; /* name of what we're building as a C identifier */ - const char *entryName; /* special entrypoint name */ - const char *targetDir; /* dir for packaged data to go */ - const char *dataDir; /* parent of dir for package (default: tmpdir) */ - const char *tmpDir; - const char *srcDir; - const char *options; /* Options arg */ - const char *mode; /* Mode of building */ - const char *version; /* Library version */ - const char *comment; /* comment string */ - const char *install; /* Where to install to (NULL = don't install) */ - const char *icuroot; /* where does ICU lives */ - const char *libName; /* name for library (default: shortName) */ - UBool rebuild; - UBool verbose; - UBool quiet; - UBool withoutAssembly; - UBool pdsbuild; /* for building PDS in z/OS */ -} UPKGOptions; - -char * convertToNativePathSeparators(char *path); - - -/* set up common defines for library naming */ - -#if U_PLATFORM_HAS_WIN32_API -# ifndef UDATA_SO_SUFFIX -# define UDATA_SO_SUFFIX ".dll" -# endif -# define LIB_PREFIX "" -# define LIB_STATIC_PREFIX "" -# define OBJ_SUFFIX ".obj" -# define UDATA_LIB_SUFFIX ".lib" - -#elif U_PLATFORM == U_PF_CYGWIN -# define LIB_PREFIX "cyg" -# define LIB_STATIC_PREFIX "lib" -# define OBJ_SUFFIX ".o" -# define UDATA_LIB_SUFFIX ".a" - -#else /* POSIX? */ -# define LIB_PREFIX "lib" -# define LIB_STATIC_PREFIX "lib" -# define OBJ_SUFFIX ".o" -# define UDATA_LIB_SUFFIX ".a" -#endif - -#define ASM_SUFFIX ".s" - -/* defines for common file names */ -#define UDATA_CMN_PREFIX "" -#define UDATA_CMN_SUFFIX ".dat" -#define UDATA_CMN_INTERMEDIATE_SUFFIX "_dat" - -#define ICUDATA_RES_FILE "icudata.res" - -#define PKGDATA_DERIVED_PATH '\t' - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/collationinfo.cpp b/deps/node/deps/icu-small/source/tools/toolutil/collationinfo.cpp deleted file mode 100644 index 6bad90e1..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/collationinfo.cpp +++ /dev/null @@ -1,152 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* Copyright (C) 2013-2015, International Business Machines -* Corporation and others. All Rights Reserved. -******************************************************************************* -* collationinfo.cpp -* -* created on: 2013aug05 -* created by: Markus W. Scherer -*/ - -#include <stdio.h> -#include <string.h> - -#include "unicode/utypes.h" - -#if !UCONFIG_NO_COLLATION - -#include "collationdata.h" -#include "collationdatareader.h" -#include "collationinfo.h" -#include "uassert.h" -#include "uvectr32.h" - -U_NAMESPACE_BEGIN - -void -CollationInfo::printSizes(int32_t sizeWithHeader, const int32_t indexes[]) { - int32_t totalSize = indexes[CollationDataReader::IX_TOTAL_SIZE]; - if(sizeWithHeader > totalSize) { - printf(" header size: %6ld\n", (long)(sizeWithHeader - totalSize)); - } - - int32_t length = indexes[CollationDataReader::IX_INDEXES_LENGTH]; - printf(" indexes: %6ld *4 = %6ld\n", (long)length, (long)length * 4); - - length = getDataLength(indexes, CollationDataReader::IX_REORDER_CODES_OFFSET); - if(length != 0) { - printf(" reorder codes: %6ld *4 = %6ld\n", (long)length / 4, (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_REORDER_TABLE_OFFSET); - if(length != 0) { - U_ASSERT(length >= 256); - printf(" reorder table: %6ld\n", (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_TRIE_OFFSET); - if(length != 0) { - printf(" trie size: %6ld\n", (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_RESERVED8_OFFSET); - if(length != 0) { - printf(" reserved (offset 8): %6ld\n", (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_CES_OFFSET); - if(length != 0) { - printf(" CEs: %6ld *8 = %6ld\n", (long)length / 8, (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_RESERVED10_OFFSET); - if(length != 0) { - printf(" reserved (offset 10): %6ld\n", (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_CE32S_OFFSET); - if(length != 0) { - printf(" CE32s: %6ld *4 = %6ld\n", (long)length / 4, (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_ROOT_ELEMENTS_OFFSET); - if(length != 0) { - printf(" rootElements: %6ld *4 = %6ld\n", (long)length / 4, (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_CONTEXTS_OFFSET); - if(length != 0) { - printf(" contexts: %6ld *2 = %6ld\n", (long)length / 2, (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_UNSAFE_BWD_OFFSET); - if(length != 0) { - printf(" unsafeBwdSet: %6ld *2 = %6ld\n", (long)length / 2, (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_FAST_LATIN_TABLE_OFFSET); - if(length != 0) { - printf(" fastLatin table: %6ld *2 = %6ld\n", (long)length / 2, (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_SCRIPTS_OFFSET); - if(length != 0) { - printf(" scripts data: %6ld *2 = %6ld\n", (long)length / 2, (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_COMPRESSIBLE_BYTES_OFFSET); - if(length != 0) { - U_ASSERT(length >= 256); - printf(" compressibleBytes: %6ld\n", (long)length); - } - - length = getDataLength(indexes, CollationDataReader::IX_RESERVED18_OFFSET); - if(length != 0) { - printf(" reserved (offset 18): %6ld\n", (long)length); - } - - printf(" collator binary total size: %6ld\n", (long)sizeWithHeader); -} - -int32_t -CollationInfo::getDataLength(const int32_t indexes[], int32_t startIndex) { - return indexes[startIndex + 1] - indexes[startIndex]; -} - -void -CollationInfo::printReorderRanges(const CollationData &data, const int32_t *codes, int32_t length) { - UErrorCode errorCode = U_ZERO_ERROR; - UVector32 ranges(errorCode); - data.makeReorderRanges(codes, length, ranges, errorCode); - if(U_FAILURE(errorCode)) { - printf(" error building reorder ranges: %s\n", u_errorName(errorCode)); - return; - } - - int32_t start = 0; - for(int32_t i = 0; i < ranges.size(); ++i) { - int32_t pair = ranges.elementAti(i); - int32_t limit = (pair >> 16) & 0xffff; - int16_t offset = (int16_t)pair; - if(offset == 0) { - // [inclusive-start, exclusive-limit[ - printf(" [%04x, %04x[\n", start, limit); - } else if(offset > 0) { - printf(" reorder [%04x, %04x[ by offset %02x to [%04x, %04x[\n", - start, limit, offset, - start + (offset << 8), limit + (offset << 8)); - } else /* offset < 0 */ { - printf(" reorder [%04x, %04x[ by offset -%02x to [%04x, %04x[\n", - start, limit, -offset, - start + (offset << 8), limit + (offset << 8)); - } - start = limit; - } -} - -U_NAMESPACE_END - -#endif // !UCONFIG_NO_COLLATION diff --git a/deps/node/deps/icu-small/source/tools/toolutil/collationinfo.h b/deps/node/deps/icu-small/source/tools/toolutil/collationinfo.h deleted file mode 100644 index 815b89d4..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/collationinfo.h +++ /dev/null @@ -1,42 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* Copyright (C) 2013-2015, International Business Machines -* Corporation and others. All Rights Reserved. -******************************************************************************* -* collationinfo.h -* -* created on: 2013aug05 -* created by: Markus W. Scherer -*/ - -#ifndef __COLLATIONINFO_H__ -#define __COLLATIONINFO_H__ - -#include "unicode/utypes.h" - -#if !UCONFIG_NO_COLLATION - -U_NAMESPACE_BEGIN - -struct CollationData; - -/** - * Collation-related code for tools & demos. - */ -class U_TOOLUTIL_API CollationInfo /* all static */ { -public: - static void printSizes(int32_t sizeWithHeader, const int32_t indexes[]); - static void printReorderRanges(const CollationData &data, const int32_t *codes, int32_t length); - -private: - CollationInfo(); // no constructor - - static int32_t getDataLength(const int32_t indexes[], int32_t startIndex); -}; - -U_NAMESPACE_END - -#endif // !UCONFIG_NO_COLLATION -#endif // __COLLATIONINFO_H__ diff --git a/deps/node/deps/icu-small/source/tools/toolutil/dbgutil.cpp b/deps/node/deps/icu-small/source/tools/toolutil/dbgutil.cpp deleted file mode 100644 index 29bab927..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/dbgutil.cpp +++ /dev/null @@ -1,160 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/******************************************************************** - * COPYRIGHT: - * Copyright (c) 2007-2012, International Business Machines Corporation and - * others. All Rights Reserved. - ********************************************************************/ - -#include "udbgutil.h" -#include "dbgutil.h" - -#if !UCONFIG_NO_FORMATTING - -#include "unicode/unistr.h" -#include "unicode/ustring.h" -#include "util.h" -#include "ucln.h" - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -U_NAMESPACE_USE - -static UnicodeString **strs = NULL; - -static const UnicodeString& _fieldString(UDebugEnumType type, int32_t field, UnicodeString& fillin) { - const char *str = udbg_enumName(type, field); - if(str == NULL) { - return fillin.remove(); - } else { - return fillin = UnicodeString(str, ""); // optimize? - } -} - -U_CDECL_BEGIN -static void udbg_cleanup(void) { - if(strs != NULL) { - for(int t=0;t<=UDBG_ENUM_COUNT;t++) { - delete [] strs[t]; - } - delete[] strs; - strs = NULL; - } -} - -static UBool tu_cleanup(void) -{ - udbg_cleanup(); - return TRUE; -} - -static void udbg_register_cleanup(void) { - ucln_registerCleanup(UCLN_TOOLUTIL, tu_cleanup); -} -U_CDECL_END - -static void udbg_setup(void) { - if(strs == NULL) { - udbg_register_cleanup(); - //fprintf(stderr,"Initializing string cache..\n"); - //fflush(stderr); - UnicodeString **newStrs = new UnicodeString*[UDBG_ENUM_COUNT+1]; - for(int t=0;t<UDBG_ENUM_COUNT;t++) { - int32_t c = udbg_enumCount((UDebugEnumType)t); - newStrs[t] = new UnicodeString[c+1]; - for(int f=0;f<=c;f++) { - _fieldString((UDebugEnumType)t, f, newStrs[t][f]); - } - } - newStrs[UDBG_ENUM_COUNT] = new UnicodeString[1]; // empty string - - strs = newStrs; - } -} - - - -U_TOOLUTIL_API const UnicodeString& U_EXPORT2 udbg_enumString(UDebugEnumType type, int32_t field) { - if(strs == NULL ) { - udbg_setup(); - } - if(type<0||type>=UDBG_ENUM_COUNT) { - // use UDBG_ENUM_COUNT,0 to mean an empty string - //fprintf(stderr, "** returning out of range on %d\n",type); - //fflush(stderr); - return strs[UDBG_ENUM_COUNT][0]; - } - int32_t count = udbg_enumCount(type); - //fprintf(stderr, "enumString [%d,%d]: typecount %d, fieldcount %d\n", type,field,UDBG_ENUM_COUNT,count); - //fflush(stderr); - if(field<0 || field > count) { - return strs[type][count]; - } else { return strs[type][field]; - } -} - -U_CAPI int32_t U_EXPORT2 udbg_enumByString(UDebugEnumType type, const UnicodeString& string) { - if(type<0||type>=UDBG_ENUM_COUNT) { - return -1; - } - // initialize array - udbg_enumString(type,0); - // search - /// printf("type=%d\n", type); fflush(stdout); - for(int i=0;i<udbg_enumCount(type);i++) { -// printf("i=%d/%d\n", i, udbg_enumCount(type)); fflush(stdout); - if(string == (strs[type][i])) { - return i; - } - } - return -1; -} - -// from DataMap::utoi -U_CAPI int32_t -udbg_stoi(const UnicodeString &s) -{ - char ch[256]; - const UChar *u = toUCharPtr(s.getBuffer()); - int32_t len = s.length(); - u_UCharsToChars(u, ch, len); - ch[len] = 0; /* include terminating \0 */ - return atoi(ch); -} - - -U_CAPI double -udbg_stod(const UnicodeString &s) -{ - char ch[256]; - const UChar *u = toUCharPtr(s.getBuffer()); - int32_t len = s.length(); - u_UCharsToChars(u, ch, len); - ch[len] = 0; /* include terminating \0 */ - return atof(ch); -} - -U_CAPI UnicodeString * -udbg_escape(const UnicodeString &src, UnicodeString *dst) -{ - dst->remove(); - for (int32_t i = 0; i < src.length(); ++i) { - UChar c = src[i]; - if(ICU_Utility::isUnprintable(c)) { - *dst += UnicodeString("["); - ICU_Utility::escapeUnprintable(*dst, c); - *dst += UnicodeString("]"); - } - else { - *dst += c; - } - } - - return dst; -} - - - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/dbgutil.h b/deps/node/deps/icu-small/source/tools/toolutil/dbgutil.h deleted file mode 100644 index 314a9ae8..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/dbgutil.h +++ /dev/null @@ -1,45 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html - -/* -************************************************************************ -* Copyright (c) 2007-2012, International Business Machines -* Corporation and others. All Rights Reserved. -************************************************************************ -*/ - -/** C++ Utilities to aid in debugging **/ - -#ifndef _DBGUTIL_H -#define _DBGUTIL_H - -#include "unicode/utypes.h" -#include "udbgutil.h" -#include "unicode/unistr.h" - -#if !UCONFIG_NO_FORMATTING - -U_TOOLUTIL_API const icu::UnicodeString& U_EXPORT2 -udbg_enumString(UDebugEnumType type, int32_t field); - -/** - * @return enum offset, or UDBG_INVALID_ENUM on error - */ -U_CAPI int32_t U_EXPORT2 -udbg_enumByString(UDebugEnumType type, const icu::UnicodeString& string); - -/** - * Convert a UnicodeString (with ascii digits) into a number. - * @param s string - * @return numerical value, or 0 on error - */ -U_CAPI int32_t U_EXPORT2 udbg_stoi(const icu::UnicodeString &s); - -U_CAPI double U_EXPORT2 udbg_stod(const icu::UnicodeString &s); - -U_CAPI icu::UnicodeString * U_EXPORT2 -udbg_escape(const icu::UnicodeString &s, icu::UnicodeString *dst); - -#endif - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/denseranges.cpp b/deps/node/deps/icu-small/source/tools/toolutil/denseranges.cpp deleted file mode 100644 index f5e52b1b..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/denseranges.cpp +++ /dev/null @@ -1,160 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* Copyright (C) 2010, International Business Machines -* Corporation and others. All Rights Reserved. -******************************************************************************* -* file name: denseranges.cpp -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2010sep25 -* created by: Markus W. Scherer -* -* Helper code for finding a small number of dense ranges. -*/ - -#include "unicode/utypes.h" -#include "denseranges.h" - -// Definitions in the anonymous namespace are invisible outside this file. -namespace { - -/** - * Collect up to 15 range gaps and sort them by ascending gap size. - */ -class LargestGaps { -public: - LargestGaps(int32_t max) : maxLength(max<=kCapacity ? max : kCapacity), length(0) {} - - void add(int32_t gapStart, int64_t gapLength) { - int32_t i=length; - while(i>0 && gapLength>gapLengths[i-1]) { - --i; - } - if(i<maxLength) { - // The new gap is now one of the maxLength largest. - // Insert the new gap, moving up smaller ones of the previous - // length largest. - int32_t j= length<maxLength ? length++ : maxLength-1; - while(j>i) { - gapStarts[j]=gapStarts[j-1]; - gapLengths[j]=gapLengths[j-1]; - --j; - } - gapStarts[i]=gapStart; - gapLengths[i]=gapLength; - } - } - - void truncate(int32_t newLength) { - if(newLength<length) { - length=newLength; - } - } - - int32_t count() const { return length; } - int32_t gapStart(int32_t i) const { return gapStarts[i]; } - int64_t gapLength(int32_t i) const { return gapLengths[i]; } - - int32_t firstAfter(int32_t value) const { - if(length==0) { - return -1; - } - int32_t minValue=0; - int32_t minIndex=-1; - for(int32_t i=0; i<length; ++i) { - if(value<gapStarts[i] && (minIndex<0 || gapStarts[i]<minValue)) { - minValue=gapStarts[i]; - minIndex=i; - } - } - return minIndex; - } - -private: - static const int32_t kCapacity=15; - - int32_t maxLength; - int32_t length; - int32_t gapStarts[kCapacity]; - int64_t gapLengths[kCapacity]; -}; - -} // namespace - -/** - * Does it make sense to write 1..capacity ranges? - * Returns 0 if not, otherwise the number of ranges. - * @param values Sorted array of signed-integer values. - * @param length Number of values. - * @param density Minimum average range density, in 256th. (0x100=100%=perfectly dense.) - * Should be 0x80..0x100, must be 1..0x100. - * @param ranges Output ranges array. - * @param capacity Maximum number of ranges. - * @return Minimum number of ranges (at most capacity) that have the desired density, - * or 0 if that density cannot be achieved. - */ -U_CAPI int32_t U_EXPORT2 -uprv_makeDenseRanges(const int32_t values[], int32_t length, - int32_t density, - int32_t ranges[][2], int32_t capacity) { - if(length<=2) { - return 0; - } - int32_t minValue=values[0]; - int32_t maxValue=values[length-1]; // Assume minValue<=maxValue. - // Use int64_t variables for intermediate-value precision and to avoid - // signed-int32_t overflow of maxValue-minValue. - int64_t maxLength=(int64_t)maxValue-(int64_t)minValue+1; - if(length>=(density*maxLength)/0x100) { - // Use one range. - ranges[0][0]=minValue; - ranges[0][1]=maxValue; - return 1; - } - if(length<=4) { - return 0; - } - // See if we can split [minValue, maxValue] into 2..capacity ranges, - // divided by the 1..(capacity-1) largest gaps. - LargestGaps gaps(capacity-1); - int32_t i; - int32_t expectedValue=minValue; - for(i=1; i<length; ++i) { - ++expectedValue; - int32_t actualValue=values[i]; - if(expectedValue!=actualValue) { - gaps.add(expectedValue, (int64_t)actualValue-(int64_t)expectedValue); - expectedValue=actualValue; - } - } - // We know gaps.count()>=1 because we have fewer values (length) than - // the length of the [minValue..maxValue] range (maxLength). - // (Otherwise we would have returned with the one range above.) - int32_t num; - for(i=0, num=2;; ++i, ++num) { - if(i>=gaps.count()) { - // The values are too sparse for capacity or fewer ranges - // of the requested density. - return 0; - } - maxLength-=gaps.gapLength(i); - if(length>num*2 && length>=(density*maxLength)/0x100) { - break; - } - } - // Use the num ranges with the num-1 largest gaps. - gaps.truncate(num-1); - ranges[0][0]=minValue; - for(i=0; i<=num-2; ++i) { - int32_t gapIndex=gaps.firstAfter(minValue); - int32_t gapStart=gaps.gapStart(gapIndex); - ranges[i][1]=gapStart-1; - ranges[i+1][0]=minValue=(int32_t)(gapStart+gaps.gapLength(gapIndex)); - } - ranges[num-1][1]=maxValue; - return num; -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/denseranges.h b/deps/node/deps/icu-small/source/tools/toolutil/denseranges.h deleted file mode 100644 index c489ca47..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/denseranges.h +++ /dev/null @@ -1,41 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* Copyright (C) 2010, International Business Machines -* Corporation and others. All Rights Reserved. -******************************************************************************* -* file name: denseranges.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2010sep25 -* created by: Markus W. Scherer -* -* Helper code for finding a small number of dense ranges. -*/ - -#ifndef __DENSERANGES_H__ -#define __DENSERANGES_H__ - -#include "unicode/utypes.h" - -/** - * Does it make sense to write 1..capacity ranges? - * Returns 0 if not, otherwise the number of ranges. - * @param values Sorted array of signed-integer values. - * @param length Number of values. - * @param density Minimum average range density, in 256th. (0x100=100%=perfectly dense.) - * Should be 0x80..0x100, must be 1..0x100. - * @param ranges Output ranges array. - * @param capacity Maximum number of ranges. - * @return Minimum number of ranges (at most capacity) that have the desired density, - * or 0 if that density cannot be achieved. - */ -U_CAPI int32_t U_EXPORT2 -uprv_makeDenseRanges(const int32_t values[], int32_t length, - int32_t density, - int32_t ranges[][2], int32_t capacity); - -#endif // __DENSERANGES_H__ diff --git a/deps/node/deps/icu-small/source/tools/toolutil/filestrm.cpp b/deps/node/deps/icu-small/source/tools/toolutil/filestrm.cpp deleted file mode 100644 index a170c7b0..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/filestrm.cpp +++ /dev/null @@ -1,227 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -****************************************************************************** -* -* Copyright (C) 1997-2011, International Business Machines -* Corporation and others. All Rights Reserved. -* -****************************************************************************** -* -* File FILESTRM.C -* -* @author Glenn Marcy -* -* Modification History: -* -* Date Name Description -* 5/8/98 gm Created -* 03/02/99 stephen Reordered params in ungetc to match stdio -* Added wopen -* 3/29/99 helena Merged Stephen and Bertrand's changes. -* -****************************************************************************** -*/ - -#include "filestrm.h" - -#include "cmemory.h" - -#include <stdio.h> - -U_CAPI FileStream* U_EXPORT2 -T_FileStream_open(const char* filename, const char* mode) -{ - if(filename != NULL && *filename != 0 && mode != NULL && *mode != 0) { - FILE *file = fopen(filename, mode); - return (FileStream*)file; - } else { - return NULL; - } -} - -/* -U_CAPI FileStream* U_EXPORT2 -T_FileStream_wopen(const wchar_t* filename, const wchar_t* mode) -{ - // TBD: _wfopen is believed to be MS-specific? -#if U_PLATFORM_USES_ONLY_WIN32_API - FILE* result = _wfopen(filename, mode); - return (FileStream*)result; -#else - size_t fnMbsSize, mdMbsSize; - char *fn, *md; - FILE *result; - - // convert from wchar_t to char - fnMbsSize = wcstombs(NULL, filename, ((size_t)-1) >> 1); - fn = (char*)uprv_malloc(fnMbsSize+2); - wcstombs(fn, filename, fnMbsSize); - fn[fnMbsSize] = 0; - - mdMbsSize = wcstombs(NULL, mode, ((size_t)-1) >> 1); - md = (char*)uprv_malloc(mdMbsSize+2); - wcstombs(md, mode, mdMbsSize); - md[mdMbsSize] = 0; - - result = fopen(fn, md); - uprv_free(fn); - uprv_free(md); - return (FileStream*)result; -#endif -} -*/ -U_CAPI void U_EXPORT2 -T_FileStream_close(FileStream* fileStream) -{ - if (fileStream != 0) - fclose((FILE*)fileStream); -} - -U_CAPI UBool U_EXPORT2 -T_FileStream_file_exists(const char* filename) -{ - FILE* temp = fopen(filename, "r"); - if (temp) { - fclose(temp); - return TRUE; - } else - return FALSE; -} - -/*static const int32_t kEOF; -const int32_t FileStream::kEOF = EOF;*/ - -/* -U_CAPI FileStream* -T_FileStream_tmpfile() -{ - FILE* file = tmpfile(); - return (FileStream*)file; -} -*/ - -U_CAPI int32_t U_EXPORT2 -T_FileStream_read(FileStream* fileStream, void* addr, int32_t len) -{ - return static_cast<int32_t>(fread(addr, 1, len, (FILE*)fileStream)); -} - -U_CAPI int32_t U_EXPORT2 -T_FileStream_write(FileStream* fileStream, const void* addr, int32_t len) -{ - - return static_cast<int32_t>(fwrite(addr, 1, len, (FILE*)fileStream)); -} - -U_CAPI void U_EXPORT2 -T_FileStream_rewind(FileStream* fileStream) -{ - rewind((FILE*)fileStream); -} - -U_CAPI int32_t U_EXPORT2 -T_FileStream_putc(FileStream* fileStream, int32_t ch) -{ - int32_t c = fputc(ch, (FILE*)fileStream); - return c; -} - -U_CAPI int U_EXPORT2 -T_FileStream_getc(FileStream* fileStream) -{ - int c = fgetc((FILE*)fileStream); - return c; -} - -U_CAPI int32_t U_EXPORT2 -T_FileStream_ungetc(int32_t ch, FileStream* fileStream) -{ - - int32_t c = ungetc(ch, (FILE*)fileStream); - return c; -} - -U_CAPI int32_t U_EXPORT2 -T_FileStream_peek(FileStream* fileStream) -{ - int32_t c = fgetc((FILE*)fileStream); - return ungetc(c, (FILE*)fileStream); -} - -U_CAPI char* U_EXPORT2 -T_FileStream_readLine(FileStream* fileStream, char* buffer, int32_t length) -{ - return fgets(buffer, length, (FILE*)fileStream); -} - -U_CAPI int32_t U_EXPORT2 -T_FileStream_writeLine(FileStream* fileStream, const char* buffer) -{ - return fputs(buffer, (FILE*)fileStream); -} - -U_CAPI int32_t U_EXPORT2 -T_FileStream_size(FileStream* fileStream) -{ - int32_t savedPos = ftell((FILE*)fileStream); - int32_t size = 0; - - /*Changes by Bertrand A. D. doesn't affect the current position - goes to the end of the file before ftell*/ - fseek((FILE*)fileStream, 0, SEEK_END); - size = (int32_t)ftell((FILE*)fileStream); - fseek((FILE*)fileStream, savedPos, SEEK_SET); - return size; -} - -U_CAPI int U_EXPORT2 -T_FileStream_eof(FileStream* fileStream) -{ - return feof((FILE*)fileStream); -} - -/* - Warning - This function may not work consistently on all platforms - (e.g. HP-UX, FreeBSD and MacOSX don't return an error when - putc is used on a file opened as readonly) -*/ -U_CAPI int U_EXPORT2 -T_FileStream_error(FileStream* fileStream) -{ - return (fileStream == 0 || ferror((FILE*)fileStream)); -} - -/* This function doesn't work. */ -/* force the stream to set its error flag*/ -/*U_CAPI void U_EXPORT2 -T_FileStream_setError(FileStream* fileStream) -{ - fseek((FILE*)fileStream, 99999, SEEK_SET); -} -*/ - -U_CAPI FileStream* U_EXPORT2 -T_FileStream_stdin(void) -{ - return (FileStream*)stdin; -} - -U_CAPI FileStream* U_EXPORT2 -T_FileStream_stdout(void) -{ - return (FileStream*)stdout; -} - - -U_CAPI FileStream* U_EXPORT2 -T_FileStream_stderr(void) -{ - return (FileStream*)stderr; -} - -U_CAPI UBool U_EXPORT2 -T_FileStream_remove(const char* fileName){ - return (remove(fileName) == 0); -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/filestrm.h b/deps/node/deps/icu-small/source/tools/toolutil/filestrm.h deleted file mode 100644 index 86fac306..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/filestrm.h +++ /dev/null @@ -1,106 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -****************************************************************************** -* -* Copyright (C) 1997-2005, International Business Machines -* Corporation and others. All Rights Reserved. -* -****************************************************************************** -* -* File FILESTRM.H -* -* Contains FileStream interface -* -* @author Glenn Marcy -* -* Modification History: -* -* Date Name Description -* 5/8/98 gm Created. -* 03/02/99 stephen Reordered params in ungetc to match stdio -* Added wopen -* -****************************************************************************** -*/ - -#ifndef FILESTRM_H -#define FILESTRM_H - -#include "unicode/utypes.h" - -typedef struct _FileStream FileStream; - -U_CAPI FileStream* U_EXPORT2 -T_FileStream_open(const char* filename, const char* mode); - -/* -U_CAPI FileStream* U_EXPORT2 -T_FileStream_wopen(const wchar_t* filename, const wchar_t* mode); -*/ -U_CAPI void U_EXPORT2 -T_FileStream_close(FileStream* fileStream); - -U_CAPI UBool U_EXPORT2 -T_FileStream_file_exists(const char* filename); - -/* -U_CAPI FileStream* U_EXPORT2 -T_FileStream_tmpfile(void); -*/ - -U_CAPI int32_t U_EXPORT2 -T_FileStream_read(FileStream* fileStream, void* addr, int32_t len); - -U_CAPI int32_t U_EXPORT2 -T_FileStream_write(FileStream* fileStream, const void* addr, int32_t len); - -U_CAPI void U_EXPORT2 -T_FileStream_rewind(FileStream* fileStream); - -/*Added by Bertrand A. D. */ -U_CAPI char * U_EXPORT2 -T_FileStream_readLine(FileStream* fileStream, char* buffer, int32_t length); - -U_CAPI int32_t U_EXPORT2 -T_FileStream_writeLine(FileStream* fileStream, const char* buffer); - -U_CAPI int32_t U_EXPORT2 -T_FileStream_putc(FileStream* fileStream, int32_t ch); - -U_CAPI int U_EXPORT2 -T_FileStream_getc(FileStream* fileStream); - -U_CAPI int32_t U_EXPORT2 -T_FileStream_ungetc(int32_t ch, FileStream *fileStream); - -U_CAPI int32_t U_EXPORT2 -T_FileStream_peek(FileStream* fileStream); - -U_CAPI int32_t U_EXPORT2 -T_FileStream_size(FileStream* fileStream); - -U_CAPI int U_EXPORT2 -T_FileStream_eof(FileStream* fileStream); - -U_CAPI int U_EXPORT2 -T_FileStream_error(FileStream* fileStream); - -/* -U_CAPI void U_EXPORT2 -T_FileStream_setError(FileStream* fileStream); -*/ - -U_CAPI FileStream* U_EXPORT2 -T_FileStream_stdin(void); - -U_CAPI FileStream* U_EXPORT2 -T_FileStream_stdout(void); - -U_CAPI FileStream* U_EXPORT2 -T_FileStream_stderr(void); - -U_CAPI UBool U_EXPORT2 -T_FileStream_remove(const char* fileName); - -#endif /* _FILESTRM*/ diff --git a/deps/node/deps/icu-small/source/tools/toolutil/filetools.cpp b/deps/node/deps/icu-small/source/tools/toolutil/filetools.cpp deleted file mode 100644 index 6e88c94b..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/filetools.cpp +++ /dev/null @@ -1,140 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/****************************************************************************** - * Copyright (C) 2009-2013, International Business Machines - * Corporation and others. All Rights Reserved. - ******************************************************************************* - */ - -#include "unicode/platform.h" -#if U_PLATFORM == U_PF_MINGW -// *cough* - for struct stat -#ifdef __STRICT_ANSI__ -#undef __STRICT_ANSI__ -#endif -#endif - -#include "filetools.h" -#include "filestrm.h" -#include "charstr.h" -#include "cstring.h" -#include "unicode/putil.h" -#include "putilimp.h" - -#include <stdio.h> -#include <stdlib.h> -#include <sys/stat.h> -#include <time.h> -#include <string.h> - -#if U_HAVE_DIRENT_H -#include <dirent.h> -typedef struct dirent DIRENT; - -#define SKIP1 "." -#define SKIP2 ".." -#endif - -static int32_t whichFileModTimeIsLater(const char *file1, const char *file2); - -/* - * Goes through the given directory recursive to compare each file's modification time with that of the file given. - * Also can be given just one file to check against. Default value for isDir is FALSE. - */ -U_CAPI UBool U_EXPORT2 -isFileModTimeLater(const char *filePath, const char *checkAgainst, UBool isDir) { - UBool isLatest = TRUE; - - if (filePath == NULL || checkAgainst == NULL) { - return FALSE; - } - - if (isDir == TRUE) { -#if U_HAVE_DIRENT_H - DIR *pDir = NULL; - if ((pDir= opendir(checkAgainst)) != NULL) { - DIR *subDirp = NULL; - DIRENT *dirEntry = NULL; - - while ((dirEntry = readdir(pDir)) != NULL) { - if (uprv_strcmp(dirEntry->d_name, SKIP1) != 0 && uprv_strcmp(dirEntry->d_name, SKIP2) != 0) { - UErrorCode status = U_ZERO_ERROR; - icu::CharString newpath(checkAgainst, -1, status); - newpath.append(U_FILE_SEP_STRING, -1, status); - newpath.append(dirEntry->d_name, -1, status); - if (U_FAILURE(status)) { - fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, u_errorName(status)); - return FALSE; - }; - - if ((subDirp = opendir(newpath.data())) != NULL) { - /* If this new path is a directory, make a recursive call with the newpath. */ - closedir(subDirp); - isLatest = isFileModTimeLater(filePath, newpath.data(), isDir); - if (!isLatest) { - break; - } - } else { - int32_t latest = whichFileModTimeIsLater(filePath, newpath.data()); - if (latest < 0 || latest == 2) { - isLatest = FALSE; - break; - } - } - - } - } - closedir(pDir); - } else { - fprintf(stderr, "Unable to open directory: %s\n", checkAgainst); - return FALSE; - } -#endif - } else { - if (T_FileStream_file_exists(checkAgainst)) { - int32_t latest = whichFileModTimeIsLater(filePath, checkAgainst); - if (latest < 0 || latest == 2) { - isLatest = FALSE; - } - } else { - isLatest = FALSE; - } - } - - return isLatest; -} - -/* Compares the mod time of both files returning a number indicating which one is later. -1 if error ocurs. */ -static int32_t whichFileModTimeIsLater(const char *file1, const char *file2) { - int32_t result = 0; - struct stat stbuf1, stbuf2; - - if (stat(file1, &stbuf1) == 0 && stat(file2, &stbuf2) == 0) { - time_t modtime1, modtime2; - double diff; - - modtime1 = stbuf1.st_mtime; - modtime2 = stbuf2.st_mtime; - - diff = difftime(modtime1, modtime2); - if (diff < 0.0) { - result = 2; - } else if (diff > 0.0) { - result = 1; - } - - } else { - fprintf(stderr, "Unable to get stats from file: %s or %s\n", file1, file2); - result = -1; - } - - return result; -} - -/* Swap the file separater character given with the new one in the file path. */ -U_CAPI void U_EXPORT2 -swapFileSepChar(char *filePath, const char oldFileSepChar, const char newFileSepChar) { - for (int32_t i = 0, length = static_cast<int32_t>(uprv_strlen(filePath)); i < length; i++) { - filePath[i] = (filePath[i] == oldFileSepChar ) ? newFileSepChar : filePath[i]; - } -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/filetools.h b/deps/node/deps/icu-small/source/tools/toolutil/filetools.h deleted file mode 100644 index 6a25c360..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/filetools.h +++ /dev/null @@ -1,34 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2009, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: filetools.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2009jan09 -* created by: Michael Ow -* -* Contains various functions to handle files. -* Not suitable for production use. Not supported. -* Not conformant. Not efficient. -*/ - -#ifndef __FILETOOLS_H__ -#define __FILETOOLS_H__ - -#include "unicode/utypes.h" - -U_CAPI UBool U_EXPORT2 -isFileModTimeLater(const char *filePath, const char *checkAgainst, UBool isDir=FALSE); - -U_CAPI void U_EXPORT2 -swapFileSepChar(char *filePath, const char oldFileSepChar, const char newFileSepChar); - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/flagparser.cpp b/deps/node/deps/icu-small/source/tools/toolutil/flagparser.cpp deleted file mode 100644 index c8d791c6..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/flagparser.cpp +++ /dev/null @@ -1,180 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/****************************************************************************** - * Copyright (C) 2009-2015, International Business Machines - * Corporation and others. All Rights Reserved. - ******************************************************************************* - */ - -#include "flagparser.h" -#include "filestrm.h" -#include "cstring.h" -#include "cmemory.h" - -#define DEFAULT_BUFFER_SIZE 512 - -static int32_t currentBufferSize = DEFAULT_BUFFER_SIZE; - -static int32_t extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t flagSize, const char ** flagNames, int32_t numOfFlags, UErrorCode *status); -static int32_t getFlagOffset(const char *buffer, int32_t bufferSize); - -/* - * Opens the given fileName and reads in the information storing the data in flagBuffer. - */ -U_CAPI int32_t U_EXPORT2 -parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, const char ** flagNames, int32_t numOfFlags, UErrorCode *status) { - char* buffer = NULL; - char* tmpFlagBuffer = NULL; - UBool allocateMoreSpace = FALSE; - int32_t idx, i; - int32_t result = 0; - - FileStream *f = T_FileStream_open(fileName, "r"); - if (f == NULL) { - *status = U_FILE_ACCESS_ERROR; - goto parseFlagsFile_cleanup; - } - - buffer = (char *)uprv_malloc(sizeof(char) * currentBufferSize); - tmpFlagBuffer = (char *)uprv_malloc(sizeof(char) * flagBufferSize); - - if (buffer == NULL || tmpFlagBuffer == NULL) { - *status = U_MEMORY_ALLOCATION_ERROR; - goto parseFlagsFile_cleanup; - } - - do { - if (allocateMoreSpace) { - allocateMoreSpace = FALSE; - currentBufferSize *= 2; - uprv_free(buffer); - buffer = (char *)uprv_malloc(sizeof(char) * currentBufferSize); - if (buffer == NULL) { - *status = U_MEMORY_ALLOCATION_ERROR; - goto parseFlagsFile_cleanup; - } - } - for (i = 0; i < numOfFlags;) { - if (T_FileStream_readLine(f, buffer, currentBufferSize) == NULL) { - /* End of file reached. */ - break; - } - if (buffer[0] == '#') { - continue; - } - - if ((int32_t)uprv_strlen(buffer) == (currentBufferSize - 1) && buffer[currentBufferSize-2] != '\n') { - /* Allocate more space for buffer if it didnot read the entrire line */ - allocateMoreSpace = TRUE; - T_FileStream_rewind(f); - break; - } else { - idx = extractFlag(buffer, currentBufferSize, tmpFlagBuffer, flagBufferSize, flagNames, numOfFlags, status); - if (U_FAILURE(*status)) { - if (*status == U_BUFFER_OVERFLOW_ERROR) { - result = currentBufferSize; - } else { - result = -1; - } - break; - } else { - if (flagNames != NULL) { - if (idx >= 0) { - uprv_strcpy(flagBuffer[idx], tmpFlagBuffer); - } else { - /* No match found. Skip it. */ - continue; - } - } else { - uprv_strcpy(flagBuffer[i++], tmpFlagBuffer); - } - } - } - } - } while (allocateMoreSpace && U_SUCCESS(*status)); - -parseFlagsFile_cleanup: - uprv_free(tmpFlagBuffer); - uprv_free(buffer); - - T_FileStream_close(f); - - if (U_FAILURE(*status) && *status != U_BUFFER_OVERFLOW_ERROR) { - return -1; - } - - if (U_SUCCESS(*status) && result == 0) { - currentBufferSize = DEFAULT_BUFFER_SIZE; - } - - return result; -} - - -/* - * Extract the setting after the '=' and store it in flag excluding the newline character. - */ -static int32_t extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t flagSize, const char **flagNames, int32_t numOfFlags, UErrorCode *status) { - int32_t i, idx = -1; - char *pBuffer; - int32_t offset=0; - UBool bufferWritten = FALSE; - - if (buffer[0] != 0) { - /* Get the offset (i.e. position after the '=') */ - offset = getFlagOffset(buffer, bufferSize); - pBuffer = buffer+offset; - for(i = 0;;i++) { - if (i >= flagSize) { - *status = U_BUFFER_OVERFLOW_ERROR; - return -1; - } - if (pBuffer[i+1] == 0) { - /* Indicates a new line character. End here. */ - flag[i] = 0; - break; - } - - flag[i] = pBuffer[i]; - if (i == 0) { - bufferWritten = TRUE; - } - } - } - - if (!bufferWritten) { - flag[0] = 0; - } - - if (flagNames != NULL && offset>0) { - offset--; /* Move offset back 1 because of '='*/ - for (i = 0; i < numOfFlags; i++) { - if (uprv_strncmp(buffer, flagNames[i], offset) == 0) { - idx = i; - break; - } - } - } - - return idx; -} - -/* - * Get the position after the '=' character. - */ -static int32_t getFlagOffset(const char *buffer, int32_t bufferSize) { - int32_t offset = 0; - - for (offset = 0; offset < bufferSize;offset++) { - if (buffer[offset] == '=') { - offset++; - break; - } - } - - if (offset == bufferSize || (offset - 1) == bufferSize) { - offset = 0; - } - - return offset; -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/flagparser.h b/deps/node/deps/icu-small/source/tools/toolutil/flagparser.h deleted file mode 100644 index aa425471..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/flagparser.h +++ /dev/null @@ -1,32 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2009-2011, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: flagparser.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2009jan08 -* created by: Michael Ow -* -* Tiny flag file parser using ICU and intended for use in ICU tests and in build tools. -* Not suitable for production use. Not supported. -* Not conformant. Not efficient. -* But very small. -*/ - -#ifndef __FLAGPARSER_H__ -#define __FLAGPARSER_H__ - -#include "unicode/utypes.h" - -U_CAPI int32_t U_EXPORT2 -parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, const char ** flagNames, int32_t numOfFlags, UErrorCode *status); - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/package.cpp b/deps/node/deps/icu-small/source/tools/toolutil/package.cpp deleted file mode 100644 index f4e428a3..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/package.cpp +++ /dev/null @@ -1,1311 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1999-2015, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: package.cpp -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2005aug25 -* created by: Markus W. Scherer -* -* Read, modify, and write ICU .dat data package files. -* This is an integral part of the icupkg tool, moved to the toolutil library -* because parts of tool implementations tend to be later shared by -* other tools. -* Subsumes functionality and implementation code from -* gencmn, decmn, and icuswap tools. -*/ - -#include "unicode/utypes.h" -#include "unicode/putil.h" -#include "unicode/udata.h" -#include "cstring.h" -#include "uarrsort.h" -#include "ucmndata.h" -#include "udataswp.h" -#include "swapimpl.h" -#include "toolutil.h" -#include "package.h" -#include "cmemory.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - - -static const int32_t kItemsChunk = 256; /* How much to increase the filesarray by each time */ - -// general definitions ----------------------------------------------------- *** - -/* UDataInfo cf. udata.h */ -static const UDataInfo dataInfo={ - (uint16_t)sizeof(UDataInfo), - 0, - - U_IS_BIG_ENDIAN, - U_CHARSET_FAMILY, - (uint8_t)sizeof(UChar), - 0, - - {0x43, 0x6d, 0x6e, 0x44}, /* dataFormat="CmnD" */ - {1, 0, 0, 0}, /* formatVersion */ - {3, 0, 0, 0} /* dataVersion */ -}; - -U_CDECL_BEGIN -static void U_CALLCONV -printPackageError(void *context, const char *fmt, va_list args) { - vfprintf((FILE *)context, fmt, args); -} -U_CDECL_END - -static uint16_t -readSwapUInt16(uint16_t x) { - return (uint16_t)((x<<8)|(x>>8)); -} - -// platform types ---------------------------------------------------------- *** - -static const char *types="lb?e"; - -enum { TYPE_L, TYPE_B, TYPE_LE, TYPE_E, TYPE_COUNT }; - -static inline int32_t -makeTypeEnum(uint8_t charset, UBool isBigEndian) { - return 2*(int32_t)charset+isBigEndian; -} - -static inline int32_t -makeTypeEnum(char type) { - return - type == 'l' ? TYPE_L : - type == 'b' ? TYPE_B : - type == 'e' ? TYPE_E : - -1; -} - -static inline char -makeTypeLetter(uint8_t charset, UBool isBigEndian) { - return types[makeTypeEnum(charset, isBigEndian)]; -} - -static inline char -makeTypeLetter(int32_t typeEnum) { - return types[typeEnum]; -} - -static void -makeTypeProps(char type, uint8_t &charset, UBool &isBigEndian) { - int32_t typeEnum=makeTypeEnum(type); - charset=(uint8_t)(typeEnum>>1); - isBigEndian=(UBool)(typeEnum&1); -} - -U_CFUNC const UDataInfo * -getDataInfo(const uint8_t *data, int32_t length, - int32_t &infoLength, int32_t &headerLength, - UErrorCode *pErrorCode) { - const DataHeader *pHeader; - const UDataInfo *pInfo; - - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { - return NULL; - } - if( data==NULL || - (length>=0 && length<(int32_t)sizeof(DataHeader)) - ) { - *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; - return NULL; - } - - pHeader=(const DataHeader *)data; - pInfo=&pHeader->info; - if( (length>=0 && length<(int32_t)sizeof(DataHeader)) || - pHeader->dataHeader.magic1!=0xda || - pHeader->dataHeader.magic2!=0x27 || - pInfo->sizeofUChar!=2 - ) { - *pErrorCode=U_UNSUPPORTED_ERROR; - return NULL; - } - - if(pInfo->isBigEndian==U_IS_BIG_ENDIAN) { - headerLength=pHeader->dataHeader.headerSize; - infoLength=pInfo->size; - } else { - headerLength=readSwapUInt16(pHeader->dataHeader.headerSize); - infoLength=readSwapUInt16(pInfo->size); - } - - if( headerLength<(int32_t)sizeof(DataHeader) || - infoLength<(int32_t)sizeof(UDataInfo) || - headerLength<(int32_t)(sizeof(pHeader->dataHeader)+infoLength) || - (length>=0 && length<headerLength) - ) { - *pErrorCode=U_UNSUPPORTED_ERROR; - return NULL; - } - - return pInfo; -} - -static int32_t -getTypeEnumForInputData(const uint8_t *data, int32_t length, - UErrorCode *pErrorCode) { - const UDataInfo *pInfo; - int32_t infoLength, headerLength; - - /* getDataInfo() checks for illegal arguments */ - pInfo=getDataInfo(data, length, infoLength, headerLength, pErrorCode); - if(pInfo==NULL) { - return -1; - } - - return makeTypeEnum(pInfo->charsetFamily, (UBool)pInfo->isBigEndian); -} - -// file handling ----------------------------------------------------------- *** - -static void -extractPackageName(const char *filename, - char pkg[], int32_t capacity) { - const char *basename; - int32_t len; - - basename=findBasename(filename); - len=(int32_t)strlen(basename)-4; /* -4: subtract the length of ".dat" */ - - if(len<=0 || 0!=strcmp(basename+len, ".dat")) { - fprintf(stderr, "icupkg: \"%s\" is not recognized as a package filename (must end with .dat)\n", - basename); - exit(U_ILLEGAL_ARGUMENT_ERROR); - } - - if(len>=capacity) { - fprintf(stderr, "icupkg: the package name \"%s\" is too long (>=%ld)\n", - basename, (long)capacity); - exit(U_ILLEGAL_ARGUMENT_ERROR); - } - - memcpy(pkg, basename, len); - pkg[len]=0; -} - -static int32_t -getFileLength(FILE *f) { - int32_t length; - - fseek(f, 0, SEEK_END); - length=(int32_t)ftell(f); - fseek(f, 0, SEEK_SET); - return length; -} - -/* - * Turn tree separators and alternate file separators into normal file separators. - */ -#if U_TREE_ENTRY_SEP_CHAR==U_FILE_SEP_CHAR && U_FILE_ALT_SEP_CHAR==U_FILE_SEP_CHAR -#define treeToPath(s) -#else -static void -treeToPath(char *s) { - char *t; - - for(t=s; *t!=0; ++t) { - if(*t==U_TREE_ENTRY_SEP_CHAR || *t==U_FILE_ALT_SEP_CHAR) { - *t=U_FILE_SEP_CHAR; - } - } -} -#endif - -/* - * Turn file separators into tree separators. - */ -#if U_TREE_ENTRY_SEP_CHAR==U_FILE_SEP_CHAR && U_FILE_ALT_SEP_CHAR==U_FILE_SEP_CHAR -#define pathToTree(s) -#else -static void -pathToTree(char *s) { - char *t; - - for(t=s; *t!=0; ++t) { - if(*t==U_FILE_SEP_CHAR || *t==U_FILE_ALT_SEP_CHAR) { - *t=U_TREE_ENTRY_SEP_CHAR; - } - } -} -#endif - -/* - * Prepend the path (if any) to the name and run the name through treeToName(). - */ -static void -makeFullFilename(const char *path, const char *name, - char *filename, int32_t capacity) { - char *s; - - // prepend the path unless NULL or empty - if(path!=NULL && path[0]!=0) { - if((int32_t)(strlen(path)+1)>=capacity) { - fprintf(stderr, "pathname too long: \"%s\"\n", path); - exit(U_BUFFER_OVERFLOW_ERROR); - } - strcpy(filename, path); - - // make sure the path ends with a file separator - s=strchr(filename, 0); - if(*(s-1)!=U_FILE_SEP_CHAR && *(s-1)!=U_FILE_ALT_SEP_CHAR) { - *s++=U_FILE_SEP_CHAR; - } - } else { - s=filename; - } - - // turn the name into a filename, turn tree separators into file separators - if((int32_t)((s-filename)+strlen(name))>=capacity) { - fprintf(stderr, "path/filename too long: \"%s%s\"\n", filename, name); - exit(U_BUFFER_OVERFLOW_ERROR); - } - strcpy(s, name); - treeToPath(s); -} - -static void -makeFullFilenameAndDirs(const char *path, const char *name, - char *filename, int32_t capacity) { - char *sep; - UErrorCode errorCode; - - makeFullFilename(path, name, filename, capacity); - - // make tree directories - errorCode=U_ZERO_ERROR; - sep=strchr(filename, 0)-strlen(name); - while((sep=strchr(sep, U_FILE_SEP_CHAR))!=NULL) { - if(sep!=filename) { - *sep=0; // truncate temporarily - uprv_mkdir(filename, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: unable to create tree directory \"%s\"\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - } - *sep++=U_FILE_SEP_CHAR; // restore file separator character - } -} - -static uint8_t * -readFile(const char *path, const char *name, int32_t &length, char &type) { - char filename[1024]; - FILE *file; - UErrorCode errorCode; - int32_t fileLength, typeEnum; - - makeFullFilename(path, name, filename, (int32_t)sizeof(filename)); - - /* open the input file, get its length, allocate memory for it, read the file */ - file=fopen(filename, "rb"); - if(file==NULL) { - fprintf(stderr, "icupkg: unable to open input file \"%s\"\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - /* get the file length */ - fileLength=getFileLength(file); - if(ferror(file) || fileLength<=0) { - fprintf(stderr, "icupkg: empty input file \"%s\"\n", filename); - fclose(file); - exit(U_FILE_ACCESS_ERROR); - } - - /* allocate the buffer, pad to multiple of 16 */ - length=(fileLength+0xf)&~0xf; - icu::LocalMemory<uint8_t> data((uint8_t *)uprv_malloc(length)); - if(data.isNull()) { - fclose(file); - fprintf(stderr, "icupkg: malloc error allocating %d bytes.\n", (int)length); - exit(U_MEMORY_ALLOCATION_ERROR); - } - - /* read the file */ - if(fileLength!=(int32_t)fread(data.getAlias(), 1, fileLength, file)) { - fprintf(stderr, "icupkg: error reading \"%s\"\n", filename); - fclose(file); - exit(U_FILE_ACCESS_ERROR); - } - - /* pad the file to a multiple of 16 using the usual padding byte */ - if(fileLength<length) { - memset(data.getAlias()+fileLength, 0xaa, length-fileLength); - } - - fclose(file); - - // minimum check for ICU-format data - errorCode=U_ZERO_ERROR; - typeEnum=getTypeEnumForInputData(data.getAlias(), length, &errorCode); - if(typeEnum<0 || U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: not an ICU data file: \"%s\"\n", filename); -#if !UCONFIG_NO_LEGACY_CONVERSION - exit(U_INVALID_FORMAT_ERROR); -#else - fprintf(stderr, "U_INVALID_FORMAT_ERROR occurred but UCONFIG_NO_LEGACY_CONVERSION is on so this is expected.\n"); - exit(0); -#endif - } - type=makeTypeLetter(typeEnum); - - return data.orphan(); -} - -// .dat package file representation ---------------------------------------- *** - -U_CDECL_BEGIN - -static int32_t U_CALLCONV -compareItems(const void * /*context*/, const void *left, const void *right) { - U_NAMESPACE_USE - - return (int32_t)strcmp(((Item *)left)->name, ((Item *)right)->name); -} - -U_CDECL_END - -U_NAMESPACE_BEGIN - -Package::Package() - : doAutoPrefix(FALSE), prefixEndsWithType(FALSE) { - inPkgName[0]=0; - pkgPrefix[0]=0; - inData=NULL; - inLength=0; - inCharset=U_CHARSET_FAMILY; - inIsBigEndian=U_IS_BIG_ENDIAN; - - itemCount=0; - itemMax=0; - items=NULL; - - inStringTop=outStringTop=0; - - matchMode=0; - findPrefix=findSuffix=NULL; - findPrefixLength=findSuffixLength=0; - findNextIndex=-1; - - // create a header for an empty package - DataHeader *pHeader; - pHeader=(DataHeader *)header; - pHeader->dataHeader.magic1=0xda; - pHeader->dataHeader.magic2=0x27; - memcpy(&pHeader->info, &dataInfo, sizeof(dataInfo)); - headerLength=(int32_t)(4+sizeof(dataInfo)); - if(headerLength&0xf) { - /* NUL-pad the header to a multiple of 16 */ - int32_t length=(headerLength+0xf)&~0xf; - memset(header+headerLength, 0, length-headerLength); - headerLength=length; - } - pHeader->dataHeader.headerSize=(uint16_t)headerLength; -} - -Package::~Package() { - int32_t idx; - - uprv_free(inData); - - for(idx=0; idx<itemCount; ++idx) { - if(items[idx].isDataOwned) { - uprv_free(items[idx].data); - } - } - - uprv_free((void*)items); -} - -void -Package::setPrefix(const char *p) { - if(strlen(p)>=sizeof(pkgPrefix)) { - fprintf(stderr, "icupkg: --toc_prefix %s too long\n", p); - exit(U_ILLEGAL_ARGUMENT_ERROR); - } - strcpy(pkgPrefix, p); -} - -void -Package::readPackage(const char *filename) { - UDataSwapper *ds; - const UDataInfo *pInfo; - UErrorCode errorCode; - - const uint8_t *inBytes; - - int32_t length, offset, i; - int32_t itemLength, typeEnum; - char type; - - const UDataOffsetTOCEntry *inEntries; - - extractPackageName(filename, inPkgName, (int32_t)sizeof(inPkgName)); - - /* read the file */ - inData=readFile(NULL, filename, inLength, type); - length=inLength; - - /* - * swap the header - even if the swapping itself is a no-op - * because it tells us the header length - */ - errorCode=U_ZERO_ERROR; - makeTypeProps(type, inCharset, inIsBigEndian); - ds=udata_openSwapper(inIsBigEndian, inCharset, U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: udata_openSwapper(\"%s\") failed - %s\n", - filename, u_errorName(errorCode)); - exit(errorCode); - } - - ds->printError=printPackageError; - ds->printErrorContext=stderr; - - headerLength=sizeof(header); - if(length<headerLength) { - headerLength=length; - } - headerLength=udata_swapDataHeader(ds, inData, headerLength, header, &errorCode); - if(U_FAILURE(errorCode)) { - exit(errorCode); - } - - /* check data format and format version */ - pInfo=(const UDataInfo *)((const char *)inData+4); - if(!( - pInfo->dataFormat[0]==0x43 && /* dataFormat="CmnD" */ - pInfo->dataFormat[1]==0x6d && - pInfo->dataFormat[2]==0x6e && - pInfo->dataFormat[3]==0x44 && - pInfo->formatVersion[0]==1 - )) { - fprintf(stderr, "icupkg: data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as an ICU .dat package\n", - pInfo->dataFormat[0], pInfo->dataFormat[1], - pInfo->dataFormat[2], pInfo->dataFormat[3], - pInfo->formatVersion[0]); - exit(U_UNSUPPORTED_ERROR); - } - inIsBigEndian=(UBool)pInfo->isBigEndian; - inCharset=pInfo->charsetFamily; - - inBytes=(const uint8_t *)inData+headerLength; - inEntries=(const UDataOffsetTOCEntry *)(inBytes+4); - - /* check that the itemCount fits, then the ToC table, then at least the header of the last item */ - length-=headerLength; - if(length<4) { - /* itemCount does not fit */ - offset=0x7fffffff; - } else { - itemCount=udata_readInt32(ds, *(const int32_t *)inBytes); - setItemCapacity(itemCount); /* resize so there's space */ - if(itemCount==0) { - offset=4; - } else if(length<(4+8*itemCount)) { - /* ToC table does not fit */ - offset=0x7fffffff; - } else { - /* offset of the last item plus at least 20 bytes for its header */ - offset=20+(int32_t)ds->readUInt32(inEntries[itemCount-1].dataOffset); - } - } - if(length<offset) { - fprintf(stderr, "icupkg: too few bytes (%ld after header) for a .dat package\n", - (long)length); - exit(U_INDEX_OUTOFBOUNDS_ERROR); - } - /* do not modify the package length variable until the last item's length is set */ - - if(itemCount<=0) { - if(doAutoPrefix) { - fprintf(stderr, "icupkg: --auto_toc_prefix[_with_type] but the input package is empty\n"); - exit(U_INVALID_FORMAT_ERROR); - } - } else { - char prefix[MAX_PKG_NAME_LENGTH+4]; - char *s, *inItemStrings; - - if(itemCount>itemMax) { - fprintf(stderr, "icupkg: too many items, maximum is %d\n", itemMax); - exit(U_BUFFER_OVERFLOW_ERROR); - } - - /* swap the item name strings */ - int32_t stringsOffset=4+8*itemCount; - itemLength=(int32_t)(ds->readUInt32(inEntries[0].dataOffset))-stringsOffset; - - // don't include padding bytes at the end of the item names - while(itemLength>0 && inBytes[stringsOffset+itemLength-1]!=0) { - --itemLength; - } - - if((inStringTop+itemLength)>STRING_STORE_SIZE) { - fprintf(stderr, "icupkg: total length of item name strings too long\n"); - exit(U_BUFFER_OVERFLOW_ERROR); - } - - inItemStrings=inStrings+inStringTop; - ds->swapInvChars(ds, inBytes+stringsOffset, itemLength, inItemStrings, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg failed to swap the input .dat package item name strings\n"); - exit(U_INVALID_FORMAT_ERROR); - } - inStringTop+=itemLength; - - // reset the Item entries - memset(items, 0, itemCount*sizeof(Item)); - - /* - * Get the common prefix of the items. - * New-style ICU .dat packages use tree separators ('/') between package names, - * tree names, and item names, - * while old-style ICU .dat packages (before multi-tree support) - * use an underscore ('_') between package and item names. - */ - offset=(int32_t)ds->readUInt32(inEntries[0].nameOffset)-stringsOffset; - s=inItemStrings+offset; // name of the first entry - int32_t prefixLength; - if(doAutoPrefix) { - // Use the first entry's prefix. Must be a new-style package. - const char *prefixLimit=strchr(s, U_TREE_ENTRY_SEP_CHAR); - if(prefixLimit==NULL) { - fprintf(stderr, - "icupkg: --auto_toc_prefix[_with_type] but " - "the first entry \"%s\" does not contain a '%c'\n", - s, U_TREE_ENTRY_SEP_CHAR); - exit(U_INVALID_FORMAT_ERROR); - } - prefixLength=(int32_t)(prefixLimit-s); - if(prefixLength==0 || prefixLength>=UPRV_LENGTHOF(pkgPrefix)) { - fprintf(stderr, - "icupkg: --auto_toc_prefix[_with_type] but " - "the prefix of the first entry \"%s\" is empty or too long\n", - s); - exit(U_INVALID_FORMAT_ERROR); - } - if(prefixEndsWithType && s[prefixLength-1]!=type) { - fprintf(stderr, - "icupkg: --auto_toc_prefix_with_type but " - "the prefix of the first entry \"%s\" does not end with '%c'\n", - s, type); - exit(U_INVALID_FORMAT_ERROR); - } - memcpy(pkgPrefix, s, prefixLength); - pkgPrefix[prefixLength]=0; - memcpy(prefix, s, ++prefixLength); // include the / - } else { - // Use the package basename as prefix. - int32_t inPkgNameLength= static_cast<int32_t>(strlen(inPkgName)); - memcpy(prefix, inPkgName, inPkgNameLength); - prefixLength=inPkgNameLength; - - if( (int32_t)strlen(s)>=(inPkgNameLength+2) && - 0==memcmp(s, inPkgName, inPkgNameLength) && - s[inPkgNameLength]=='_' - ) { - // old-style .dat package - prefix[prefixLength++]='_'; - } else { - // new-style .dat package - prefix[prefixLength++]=U_TREE_ENTRY_SEP_CHAR; - // if it turns out to not contain U_TREE_ENTRY_SEP_CHAR - // then the test in the loop below will fail - } - } - prefix[prefixLength]=0; - - /* read the ToC table */ - for(i=0; i<itemCount; ++i) { - // skip the package part of the item name, error if it does not match the actual package name - // or if nothing follows the package name - offset=(int32_t)ds->readUInt32(inEntries[i].nameOffset)-stringsOffset; - s=inItemStrings+offset; - if(0!=strncmp(s, prefix, prefixLength) || s[prefixLength]==0) { - fprintf(stderr, "icupkg: input .dat item name \"%s\" does not start with \"%s\"\n", - s, prefix); - exit(U_INVALID_FORMAT_ERROR); - } - items[i].name=s+prefixLength; - - // set the item's data - items[i].data=(uint8_t *)inBytes+ds->readUInt32(inEntries[i].dataOffset); - if(i>0) { - items[i-1].length=(int32_t)(items[i].data-items[i-1].data); - - // set the previous item's platform type - typeEnum=getTypeEnumForInputData(items[i-1].data, items[i-1].length, &errorCode); - if(typeEnum<0 || U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: not an ICU data file: item \"%s\" in \"%s\"\n", items[i-1].name, filename); - exit(U_INVALID_FORMAT_ERROR); - } - items[i-1].type=makeTypeLetter(typeEnum); - } - items[i].isDataOwned=FALSE; - } - // set the last item's length - items[itemCount-1].length=length-ds->readUInt32(inEntries[itemCount-1].dataOffset); - - // set the last item's platform type - typeEnum=getTypeEnumForInputData(items[itemCount-1].data, items[itemCount-1].length, &errorCode); - if(typeEnum<0 || U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: not an ICU data file: item \"%s\" in \"%s\"\n", items[itemCount-1].name, filename); - exit(U_INVALID_FORMAT_ERROR); - } - items[itemCount-1].type=makeTypeLetter(typeEnum); - - if(type!=U_ICUDATA_TYPE_LETTER[0]) { - // sort the item names for the local charset - sortItems(); - } - } - - udata_closeSwapper(ds); -} - -char -Package::getInType() { - return makeTypeLetter(inCharset, inIsBigEndian); -} - -void -Package::writePackage(const char *filename, char outType, const char *comment) { - char prefix[MAX_PKG_NAME_LENGTH+4]; - UDataOffsetTOCEntry entry; - UDataSwapper *dsLocalToOut, *ds[TYPE_COUNT]; - FILE *file; - Item *pItem; - char *name; - UErrorCode errorCode; - int32_t i, length, prefixLength, maxItemLength, basenameOffset, offset, outInt32; - uint8_t outCharset; - UBool outIsBigEndian; - - extractPackageName(filename, prefix, MAX_PKG_NAME_LENGTH); - - // if there is an explicit comment, then use it, else use what's in the current header - if(comment!=NULL) { - /* get the header size minus the current comment */ - DataHeader *pHeader; - int32_t length; - - pHeader=(DataHeader *)header; - headerLength=4+pHeader->info.size; - length=(int32_t)strlen(comment); - if((int32_t)(headerLength+length)>=(int32_t)sizeof(header)) { - fprintf(stderr, "icupkg: comment too long\n"); - exit(U_BUFFER_OVERFLOW_ERROR); - } - memcpy(header+headerLength, comment, length+1); - headerLength+=length; - if(headerLength&0xf) { - /* NUL-pad the header to a multiple of 16 */ - length=(headerLength+0xf)&~0xf; - memset(header+headerLength, 0, length-headerLength); - headerLength=length; - } - pHeader->dataHeader.headerSize=(uint16_t)headerLength; - } - - makeTypeProps(outType, outCharset, outIsBigEndian); - - // open (TYPE_COUNT-2) swappers - // one is a no-op for local type==outType - // one type (TYPE_LE) is bogus - errorCode=U_ZERO_ERROR; - i=makeTypeEnum(outType); - ds[TYPE_B]= i==TYPE_B ? NULL : udata_openSwapper(TRUE, U_ASCII_FAMILY, outIsBigEndian, outCharset, &errorCode); - ds[TYPE_L]= i==TYPE_L ? NULL : udata_openSwapper(FALSE, U_ASCII_FAMILY, outIsBigEndian, outCharset, &errorCode); - ds[TYPE_LE]=NULL; - ds[TYPE_E]= i==TYPE_E ? NULL : udata_openSwapper(TRUE, U_EBCDIC_FAMILY, outIsBigEndian, outCharset, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: udata_openSwapper() failed - %s\n", u_errorName(errorCode)); - exit(errorCode); - } - for(i=0; i<TYPE_COUNT; ++i) { - if(ds[i]!=NULL) { - ds[i]->printError=printPackageError; - ds[i]->printErrorContext=stderr; - } - } - - dsLocalToOut=ds[makeTypeEnum(U_CHARSET_FAMILY, U_IS_BIG_ENDIAN)]; - - // create the file and write its contents - file=fopen(filename, "wb"); - if(file==NULL) { - fprintf(stderr, "icupkg: unable to create file \"%s\"\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - // swap and write the header - if(dsLocalToOut!=NULL) { - udata_swapDataHeader(dsLocalToOut, header, headerLength, header, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: udata_swapDataHeader(local to out) failed - %s\n", u_errorName(errorCode)); - exit(errorCode); - } - } - length=(int32_t)fwrite(header, 1, headerLength, file); - if(length!=headerLength) { - fprintf(stderr, "icupkg: unable to write complete header to file \"%s\"\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - // prepare and swap the package name with a tree separator - // for prepending to item names - if(pkgPrefix[0]==0) { - prefixLength=(int32_t)strlen(prefix); - } else { - prefixLength=(int32_t)strlen(pkgPrefix); - memcpy(prefix, pkgPrefix, prefixLength); - if(prefixEndsWithType) { - prefix[prefixLength-1]=outType; - } - } - prefix[prefixLength++]=U_TREE_ENTRY_SEP_CHAR; - prefix[prefixLength]=0; - if(dsLocalToOut!=NULL) { - dsLocalToOut->swapInvChars(dsLocalToOut, prefix, prefixLength, prefix, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: swapInvChars(output package name) failed - %s\n", u_errorName(errorCode)); - exit(errorCode); - } - - // swap and sort the item names (sorting needs to be done in the output charset) - dsLocalToOut->swapInvChars(dsLocalToOut, inStrings, inStringTop, inStrings, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: swapInvChars(item names) failed - %s\n", u_errorName(errorCode)); - exit(errorCode); - } - sortItems(); - } - - // create the output item names in sorted order, with the package name prepended to each - for(i=0; i<itemCount; ++i) { - length=(int32_t)strlen(items[i].name); - name=allocString(FALSE, length+prefixLength); - memcpy(name, prefix, prefixLength); - memcpy(name+prefixLength, items[i].name, length+1); - items[i].name=name; - } - - // calculate offsets for item names and items, pad to 16-align items - // align only the first item; each item's length is a multiple of 16 - basenameOffset=4+8*itemCount; - offset=basenameOffset+outStringTop; - if((length=(offset&15))!=0) { - length=16-length; - memset(allocString(FALSE, length-1), 0xaa, length); - offset+=length; - } - - // write the table of contents - // first the itemCount - outInt32=itemCount; - if(dsLocalToOut!=NULL) { - dsLocalToOut->swapArray32(dsLocalToOut, &outInt32, 4, &outInt32, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: swapArray32(item count) failed - %s\n", u_errorName(errorCode)); - exit(errorCode); - } - } - length=(int32_t)fwrite(&outInt32, 1, 4, file); - if(length!=4) { - fprintf(stderr, "icupkg: unable to write complete item count to file \"%s\"\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - // then write the item entries (and collect the maxItemLength) - maxItemLength=0; - for(i=0; i<itemCount; ++i) { - entry.nameOffset=(uint32_t)(basenameOffset+(items[i].name-outStrings)); - entry.dataOffset=(uint32_t)offset; - if(dsLocalToOut!=NULL) { - dsLocalToOut->swapArray32(dsLocalToOut, &entry, 8, &entry, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: swapArray32(item entry %ld) failed - %s\n", (long)i, u_errorName(errorCode)); - exit(errorCode); - } - } - length=(int32_t)fwrite(&entry, 1, 8, file); - if(length!=8) { - fprintf(stderr, "icupkg: unable to write complete item entry %ld to file \"%s\"\n", (long)i, filename); - exit(U_FILE_ACCESS_ERROR); - } - - length=items[i].length; - if(length>maxItemLength) { - maxItemLength=length; - } - offset+=length; - } - - // write the item names - length=(int32_t)fwrite(outStrings, 1, outStringTop, file); - if(length!=outStringTop) { - fprintf(stderr, "icupkg: unable to write complete item names to file \"%s\"\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - // write the items - for(pItem=items, i=0; i<itemCount; ++pItem, ++i) { - int32_t type=makeTypeEnum(pItem->type); - if(ds[type]!=NULL) { - // swap each item from its platform properties to the desired ones - udata_swap( - ds[type], - pItem->data, pItem->length, pItem->data, - &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: udata_swap(item %ld) failed - %s\n", (long)i, u_errorName(errorCode)); - exit(errorCode); - } - } - length=(int32_t)fwrite(pItem->data, 1, pItem->length, file); - if(length!=pItem->length) { - fprintf(stderr, "icupkg: unable to write complete item %ld to file \"%s\"\n", (long)i, filename); - exit(U_FILE_ACCESS_ERROR); - } - } - - if(ferror(file)) { - fprintf(stderr, "icupkg: unable to write complete file \"%s\"\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - fclose(file); - for(i=0; i<TYPE_COUNT; ++i) { - udata_closeSwapper(ds[i]); - } -} - -int32_t -Package::findItem(const char *name, int32_t length) const { - int32_t i, start, limit; - int result; - - /* do a binary search for the string */ - start=0; - limit=itemCount; - while(start<limit) { - i=(start+limit)/2; - if(length>=0) { - result=strncmp(name, items[i].name, length); - } else { - result=strcmp(name, items[i].name); - } - - if(result==0) { - /* found */ - if(length>=0) { - /* - * if we compared just prefixes, then we may need to back up - * to the first item with this prefix - */ - while(i>0 && 0==strncmp(name, items[i-1].name, length)) { - --i; - } - } - return i; - } else if(result<0) { - limit=i; - } else /* result>0 */ { - start=i+1; - } - } - - return ~start; /* not found, return binary-not of the insertion point */ -} - -void -Package::findItems(const char *pattern) { - const char *wild; - - if(pattern==NULL || *pattern==0) { - findNextIndex=-1; - return; - } - - findPrefix=pattern; - findSuffix=NULL; - findSuffixLength=0; - - wild=strchr(pattern, '*'); - if(wild==NULL) { - // no wildcard - findPrefixLength=(int32_t)strlen(pattern); - } else { - // one wildcard - findPrefixLength=(int32_t)(wild-pattern); - findSuffix=wild+1; - findSuffixLength=(int32_t)strlen(findSuffix); - if(NULL!=strchr(findSuffix, '*')) { - // two or more wildcards - fprintf(stderr, "icupkg: syntax error (more than one '*') in item pattern \"%s\"\n", pattern); - exit(U_PARSE_ERROR); - } - } - - if(findPrefixLength==0) { - findNextIndex=0; - } else { - findNextIndex=findItem(findPrefix, findPrefixLength); - } -} - -int32_t -Package::findNextItem() { - const char *name, *middle, *treeSep; - int32_t idx, nameLength, middleLength; - - if(findNextIndex<0) { - return -1; - } - - while(findNextIndex<itemCount) { - idx=findNextIndex++; - name=items[idx].name; - nameLength=(int32_t)strlen(name); - if(nameLength<(findPrefixLength+findSuffixLength)) { - // item name too short for prefix & suffix - continue; - } - if(findPrefixLength>0 && 0!=memcmp(findPrefix, name, findPrefixLength)) { - // left the range of names with this prefix - break; - } - middle=name+findPrefixLength; - middleLength=nameLength-findPrefixLength-findSuffixLength; - if(findSuffixLength>0 && 0!=memcmp(findSuffix, name+(nameLength-findSuffixLength), findSuffixLength)) { - // suffix does not match - continue; - } - // prefix & suffix match - - if(matchMode&MATCH_NOSLASH) { - treeSep=strchr(middle, U_TREE_ENTRY_SEP_CHAR); - if(treeSep!=NULL && (treeSep-middle)<middleLength) { - // the middle (matching the * wildcard) contains a tree separator / - continue; - } - } - - // found a matching item - return idx; - } - - // no more items - findNextIndex=-1; - return -1; -} - -void -Package::setMatchMode(uint32_t mode) { - matchMode=mode; -} - -void -Package::addItem(const char *name) { - addItem(name, NULL, 0, FALSE, U_ICUDATA_TYPE_LETTER[0]); -} - -void -Package::addItem(const char *name, uint8_t *data, int32_t length, UBool isDataOwned, char type) { - int32_t idx; - - idx=findItem(name); - if(idx<0) { - // new item, make space at the insertion point - ensureItemCapacity(); - // move the following items down - idx=~idx; - if(idx<itemCount) { - memmove(items+idx+1, items+idx, (itemCount-idx)*sizeof(Item)); - } - ++itemCount; - - // reset this Item entry - memset(items+idx, 0, sizeof(Item)); - - // copy the item's name - items[idx].name=allocString(TRUE, static_cast<int32_t>(strlen(name))); - strcpy(items[idx].name, name); - pathToTree(items[idx].name); - } else { - // same-name item found, replace it - if(items[idx].isDataOwned) { - uprv_free(items[idx].data); - } - - // keep the item's name since it is the same - } - - // set the item's data - items[idx].data=data; - items[idx].length=length; - items[idx].isDataOwned=isDataOwned; - items[idx].type=type; -} - -void -Package::addFile(const char *filesPath, const char *name) { - uint8_t *data; - int32_t length; - char type; - - data=readFile(filesPath, name, length, type); - // readFile() exits the tool if it fails - addItem(name, data, length, TRUE, type); -} - -void -Package::addItems(const Package &listPkg) { - const Item *pItem; - int32_t i; - - for(pItem=listPkg.items, i=0; i<listPkg.itemCount; ++pItem, ++i) { - addItem(pItem->name, pItem->data, pItem->length, FALSE, pItem->type); - } -} - -void -Package::removeItem(int32_t idx) { - if(idx>=0) { - // remove the item - if(items[idx].isDataOwned) { - uprv_free(items[idx].data); - } - - // move the following items up - if((idx+1)<itemCount) { - memmove(items+idx, items+idx+1, (itemCount-(idx+1))*sizeof(Item)); - } - --itemCount; - - if(idx<=findNextIndex) { - --findNextIndex; - } - } -} - -void -Package::removeItems(const char *pattern) { - int32_t idx; - - findItems(pattern); - while((idx=findNextItem())>=0) { - removeItem(idx); - } -} - -void -Package::removeItems(const Package &listPkg) { - const Item *pItem; - int32_t i; - - for(pItem=listPkg.items, i=0; i<listPkg.itemCount; ++pItem, ++i) { - removeItems(pItem->name); - } -} - -void -Package::extractItem(const char *filesPath, const char *outName, int32_t idx, char outType) { - char filename[1024]; - UDataSwapper *ds; - FILE *file; - Item *pItem; - int32_t fileLength; - uint8_t itemCharset, outCharset; - UBool itemIsBigEndian, outIsBigEndian; - - if(idx<0 || itemCount<=idx) { - return; - } - pItem=items+idx; - - // swap the data to the outType - // outType==0: don't swap - if(outType!=0 && pItem->type!=outType) { - // open the swapper - UErrorCode errorCode=U_ZERO_ERROR; - makeTypeProps(pItem->type, itemCharset, itemIsBigEndian); - makeTypeProps(outType, outCharset, outIsBigEndian); - ds=udata_openSwapper(itemIsBigEndian, itemCharset, outIsBigEndian, outCharset, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: udata_openSwapper(item %ld) failed - %s\n", - (long)idx, u_errorName(errorCode)); - exit(errorCode); - } - - ds->printError=printPackageError; - ds->printErrorContext=stderr; - - // swap the item from its platform properties to the desired ones - udata_swap(ds, pItem->data, pItem->length, pItem->data, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: udata_swap(item %ld) failed - %s\n", (long)idx, u_errorName(errorCode)); - exit(errorCode); - } - udata_closeSwapper(ds); - pItem->type=outType; - } - - // create the file and write its contents - makeFullFilenameAndDirs(filesPath, outName, filename, (int32_t)sizeof(filename)); - file=fopen(filename, "wb"); - if(file==NULL) { - fprintf(stderr, "icupkg: unable to create file \"%s\"\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - fileLength=(int32_t)fwrite(pItem->data, 1, pItem->length, file); - - if(ferror(file) || fileLength!=pItem->length) { - fprintf(stderr, "icupkg: unable to write complete file \"%s\"\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - fclose(file); -} - -void -Package::extractItem(const char *filesPath, int32_t idx, char outType) { - extractItem(filesPath, items[idx].name, idx, outType); -} - -void -Package::extractItems(const char *filesPath, const char *pattern, char outType) { - int32_t idx; - - findItems(pattern); - while((idx=findNextItem())>=0) { - extractItem(filesPath, idx, outType); - } -} - -void -Package::extractItems(const char *filesPath, const Package &listPkg, char outType) { - const Item *pItem; - int32_t i; - - for(pItem=listPkg.items, i=0; i<listPkg.itemCount; ++pItem, ++i) { - extractItems(filesPath, pItem->name, outType); - } -} - -int32_t -Package::getItemCount() const { - return itemCount; -} - -const Item * -Package::getItem(int32_t idx) const { - if (0 <= idx && idx < itemCount) { - return &items[idx]; - } - return NULL; -} - -void -Package::checkDependency(void *context, const char *itemName, const char *targetName) { - // check dependency: make sure the target item is in the package - Package *me=(Package *)context; - if(me->findItem(targetName)<0) { - me->isMissingItems=TRUE; - fprintf(stderr, "Item %s depends on missing item %s\n", itemName, targetName); - } -} - -UBool -Package::checkDependencies() { - isMissingItems=FALSE; - enumDependencies(this, checkDependency); - return (UBool)!isMissingItems; -} - -void -Package::enumDependencies(void *context, CheckDependency check) { - int32_t i; - - for(i=0; i<itemCount; ++i) { - enumDependencies(items+i, context, check); - } -} - -char * -Package::allocString(UBool in, int32_t length) { - char *p; - int32_t top; - - if(in) { - top=inStringTop; - p=inStrings+top; - } else { - top=outStringTop; - p=outStrings+top; - } - top+=length+1; - - if(top>STRING_STORE_SIZE) { - fprintf(stderr, "icupkg: string storage overflow\n"); - exit(U_BUFFER_OVERFLOW_ERROR); - } - if(in) { - inStringTop=top; - } else { - outStringTop=top; - } - return p; -} - -void -Package::sortItems() { - UErrorCode errorCode=U_ZERO_ERROR; - uprv_sortArray(items, itemCount, (int32_t)sizeof(Item), compareItems, NULL, FALSE, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: sorting item names failed - %s\n", u_errorName(errorCode)); - exit(errorCode); - } -} - -void Package::setItemCapacity(int32_t max) -{ - if(max<=itemMax) { - return; - } - Item *newItems = (Item*)uprv_malloc(max * sizeof(items[0])); - Item *oldItems = items; - if(newItems == NULL) { - fprintf(stderr, "icupkg: Out of memory trying to allocate %lu bytes for %d items\n", - (unsigned long)(max*sizeof(items[0])), max); - exit(U_MEMORY_ALLOCATION_ERROR); - } - if(items && itemCount>0) { - uprv_memcpy(newItems, items, (size_t)itemCount*sizeof(items[0])); - } - itemMax = max; - items = newItems; - uprv_free(oldItems); -} - -void Package::ensureItemCapacity() -{ - if((itemCount+1)>itemMax) { - setItemCapacity(itemCount+kItemsChunk); - } -} - -U_NAMESPACE_END diff --git a/deps/node/deps/icu-small/source/tools/toolutil/package.h b/deps/node/deps/icu-small/source/tools/toolutil/package.h deleted file mode 100644 index 3263c84f..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/package.h +++ /dev/null @@ -1,201 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2005-2014, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: package.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2005aug25 -* created by: Markus W. Scherer -* -* Read, modify, and write ICU .dat data package files. -*/ - -#ifndef __PACKAGE_H__ -#define __PACKAGE_H__ - -#include "unicode/utypes.h" - -#include <stdio.h> - -// .dat package file representation ---------------------------------------- *** - -#define STRING_STORE_SIZE 100000 -#define MAX_PKG_NAME_LENGTH 64 - -typedef void CheckDependency(void *context, const char *itemName, const char *targetName); - -U_NAMESPACE_BEGIN - -struct Item { - char *name; - uint8_t *data; - int32_t length; - UBool isDataOwned; - char type; -}; - -class U_TOOLUTIL_API Package { -public: - /* - * Constructor. - * Prepare this object for a new, empty package. - */ - Package(); - - /* Destructor. */ - ~Package(); - - /** - * Uses the prefix of the first entry of the package in readPackage(), - * rather than the package basename. - */ - void setAutoPrefix() { doAutoPrefix=TRUE; } - /** - * Same as setAutoPrefix(), plus the prefix must end with the platform type letter. - */ - void setAutoPrefixWithType() { - doAutoPrefix=TRUE; - prefixEndsWithType=TRUE; - } - void setPrefix(const char *p); - - /* - * Read an existing .dat package file. - * The header and item name strings are swapped into this object, - * but the items are left unswapped. - */ - void readPackage(const char *filename); - /* - * Write a .dat package file with the items in this object. - * Swap all pieces to the desired output platform properties. - * The package becomes unusable: - * The item names are swapped and sorted in the outCharset rather than the local one. - * Also, the items themselves are swapped in-place - */ - void writePackage(const char *filename, char outType, const char *comment); - - /* - * Return the input data type letter (l, b, or e). - */ - char getInType(); - - // find the item in items[], return the non-negative index if found, else the binary-not of the insertion point - int32_t findItem(const char *name, int32_t length=-1) const; - - /* - * Set internal state for following calls to findNextItem() which will return - * indexes for items whose names match the pattern. - */ - void findItems(const char *pattern); - int32_t findNextItem(); - /* - * Set the match mode for findItems() & findNextItem(). - * @param mode 0=default - * MATCH_NOSLASH * does not match a '/' - */ - void setMatchMode(uint32_t mode); - - enum { - MATCH_NOSLASH=1 - }; - - void addItem(const char *name); - void addItem(const char *name, uint8_t *data, int32_t length, UBool isDataOwned, char type); - void addFile(const char *filesPath, const char *name); - void addItems(const Package &listPkg); - - void removeItem(int32_t itemIndex); - void removeItems(const char *pattern); - void removeItems(const Package &listPkg); - - /* The extractItem() functions accept outputType=0 to mean "don't swap the item". */ - void extractItem(const char *filesPath, int32_t itemIndex, char outType); - void extractItems(const char *filesPath, const char *pattern, char outType); - void extractItems(const char *filesPath, const Package &listPkg, char outType); - - /* This variant extracts an item to a specific filename. */ - void extractItem(const char *filesPath, const char *outName, int32_t itemIndex, char outType); - - int32_t getItemCount() const; - const Item *getItem(int32_t idx) const; - - /* - * Check dependencies and return TRUE if all dependencies are fulfilled. - */ - UBool checkDependencies(); - - /* - * Enumerate all the dependencies and give the results to context and call CheckDependency callback - * @param context user context (will be passed to check function) - * @param check will be called with context and any missing items - */ - void enumDependencies(void *context, CheckDependency check); - -private: - void enumDependencies(Item *pItem, void *context, CheckDependency check); - - /** - * Default CheckDependency function used by checkDependencies() - */ - static void checkDependency(void *context, const char *itemName, const char *targetName); - - /* - * Allocate a string in inStrings or outStrings. - * The length does not include the terminating NUL. - */ - char *allocString(UBool in, int32_t length); - - void sortItems(); - - // data fields - char inPkgName[MAX_PKG_NAME_LENGTH]; - char pkgPrefix[MAX_PKG_NAME_LENGTH]; - - uint8_t *inData; - uint8_t header[1024]; - int32_t inLength, headerLength; - uint8_t inCharset; - UBool inIsBigEndian; - UBool doAutoPrefix; - UBool prefixEndsWithType; - - int32_t itemCount; - int32_t itemMax; - Item *items; - - int32_t inStringTop, outStringTop; - char inStrings[STRING_STORE_SIZE], outStrings[STRING_STORE_SIZE]; - - // match mode for findItems(pattern) and findNextItem() - uint32_t matchMode; - - // state for findItems(pattern) and findNextItem() - const char *findPrefix, *findSuffix; - int32_t findPrefixLength, findSuffixLength; - int32_t findNextIndex; - - // state for checkDependencies() - UBool isMissingItems; - - /** - * Grow itemMax to new value - */ - void setItemCapacity(int32_t max); - - /** - * Grow itemMax to at least itemCount+1 - */ - void ensureItemCapacity(); -}; - -U_NAMESPACE_END - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/pkg_genc.cpp b/deps/node/deps/icu-small/source/tools/toolutil/pkg_genc.cpp deleted file mode 100644 index 5ab0d846..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/pkg_genc.cpp +++ /dev/null @@ -1,1214 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/****************************************************************************** - * Copyright (C) 2009-2016, International Business Machines - * Corporation and others. All Rights Reserved. - ******************************************************************************* - */ -#include "unicode/utypes.h" - -#if U_PLATFORM_HAS_WIN32_API -# define VC_EXTRALEAN -# define WIN32_LEAN_AND_MEAN -# define NOUSER -# define NOSERVICE -# define NOIME -# define NOMCX -#include <windows.h> -#include <time.h> -# ifdef __GNUC__ -# define WINDOWS_WITH_GNUC -# endif -#endif - -#if U_PLATFORM_IS_LINUX_BASED && U_HAVE_ELF_H -# define U_ELF -#endif - -#ifdef U_ELF -# include <elf.h> -# if defined(ELFCLASS64) -# define U_ELF64 -# endif - /* Old elf.h headers may not have EM_X86_64, or have EM_X8664 instead. */ -# ifndef EM_X86_64 -# define EM_X86_64 62 -# endif -# define ICU_ENTRY_OFFSET 0 -#endif - -#include <stdio.h> -#include <stdlib.h> -#include "unicode/putil.h" -#include "cmemory.h" -#include "cstring.h" -#include "filestrm.h" -#include "toolutil.h" -#include "unicode/uclean.h" -#include "uoptions.h" -#include "pkg_genc.h" -#include "filetools.h" - -#define MAX_COLUMN ((uint32_t)(0xFFFFFFFFU)) - -#define HEX_0X 0 /* 0x1234 */ -#define HEX_0H 1 /* 01234h */ - -/* prototypes --------------------------------------------------------------- */ -static void -getOutFilename(const char *inFilename, const char *destdir, char *outFilename, char *entryName, const char *newSuffix, const char *optFilename); - -static uint32_t -write8(FileStream *out, uint8_t byte, uint32_t column); - -static uint32_t -write32(FileStream *out, uint32_t byte, uint32_t column); - -#if U_PLATFORM == U_PF_OS400 -static uint32_t -write8str(FileStream *out, uint8_t byte, uint32_t column); -#endif -/* -------------------------------------------------------------------------- */ - -/* -Creating Template Files for New Platforms - -Let the cc compiler help you get started. -Compile this program - const unsigned int x[5] = {1, 2, 0xdeadbeef, 0xffffffff, 16}; -with the -S option to produce assembly output. - -For example, this will generate array.s: -gcc -S array.c - -This will produce a .s file that may look like this: - - .file "array.c" - .version "01.01" -gcc2_compiled.: - .globl x - .section .rodata - .align 4 - .type x,@object - .size x,20 -x: - .long 1 - .long 2 - .long -559038737 - .long -1 - .long 16 - .ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-85)" - -which gives a starting point that will compile, and can be transformed -to become the template, generally with some consulting of as docs and -some experimentation. - -If you want ICU to automatically use this assembly, you should -specify "GENCCODE_ASSEMBLY=-a name" in the specific config/mh-* file, -where the name is the compiler or platform that you used in this -assemblyHeader data structure. -*/ -static const struct AssemblyType { - const char *name; - const char *header; - const char *beginLine; - const char *footer; - int8_t hexType; /* HEX_0X or HEX_0h */ -} assemblyHeader[] = { - /* For gcc assemblers, the meaning of .align changes depending on the */ - /* hardware, so we use .balign 16 which always means 16 bytes. */ - /* https://sourceware.org/binutils/docs/as/Pseudo-Ops.html */ - {"gcc", - ".globl %s\n" - "\t.section .note.GNU-stack,\"\",%%progbits\n" - "\t.section .rodata\n" - "\t.balign 16\n" - "#ifdef U_HIDE_DATA_SYMBOL\n" - "\t.hidden %s\n" - "#endif\n" - "\t.type %s,%%object\n" - "%s:\n\n", - - ".long ",".size %s, .-%s\n",HEX_0X - }, - {"gcc-darwin", - /*"\t.section __TEXT,__text,regular,pure_instructions\n" - "\t.section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32\n"*/ - ".globl _%s\n" - "#ifdef U_HIDE_DATA_SYMBOL\n" - "\t.private_extern _%s\n" - "#endif\n" - "\t.data\n" - "\t.const\n" - "\t.balign 16\n" - "_%s:\n\n", - - ".long ","",HEX_0X - }, - {"gcc-cygwin", - ".globl _%s\n" - "\t.section .rodata\n" - "\t.balign 16\n" - "_%s:\n\n", - - ".long ","",HEX_0X - }, - {"gcc-mingw64", - ".globl %s\n" - "\t.section .rodata\n" - "\t.balign 16\n" - "%s:\n\n", - - ".long ","",HEX_0X - }, -/* 16 bytes alignment. */ -/* http://docs.oracle.com/cd/E19641-01/802-1947/802-1947.pdf */ - {"sun", - "\t.section \".rodata\"\n" - "\t.align 16\n" - ".globl %s\n" - "%s:\n", - - ".word ","",HEX_0X - }, -/* 16 bytes alignment for sun-x86. */ -/* http://docs.oracle.com/cd/E19963-01/html/821-1608/eoiyg.html */ - {"sun-x86", - "Drodata.rodata:\n" - "\t.type Drodata.rodata,@object\n" - "\t.size Drodata.rodata,0\n" - "\t.globl %s\n" - "\t.align 16\n" - "%s:\n", - - ".4byte ","",HEX_0X - }, -/* 1<<4 bit alignment for aix. */ -/* http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.aixassem%2Fdoc%2Falangref%2Fidalangref_csect_pseudoop.htm */ - {"xlc", - ".globl %s{RO}\n" - "\t.toc\n" - "%s:\n" - "\t.csect %s{RO}, 4\n", - - ".long ","",HEX_0X - }, - {"aCC-ia64", - "\t.file \"%s.s\"\n" - "\t.type %s,@object\n" - "\t.global %s\n" - "\t.secalias .abe$0.rodata, \".rodata\"\n" - "\t.section .abe$0.rodata = \"a\", \"progbits\"\n" - "\t.align 16\n" - "%s::\t", - - "data4 ","",HEX_0X - }, - {"aCC-parisc", - "\t.SPACE $TEXT$\n" - "\t.SUBSPA $LIT$\n" - "%s\n" - "\t.EXPORT %s\n" - "\t.ALIGN 16\n", - - ".WORD ","",HEX_0X - }, -/* align 16 bytes */ -/* http://msdn.microsoft.com/en-us/library/dwa9fwef.aspx */ - { "masm", - "\tTITLE %s\n" - "; generated by genccode\n" - ".386\n" - ".model flat\n" - "\tPUBLIC _%s\n" - "ICUDATA_%s\tSEGMENT READONLY PARA PUBLIC FLAT 'DATA'\n" - "\tALIGN 16\n" - "_%s\tLABEL DWORD\n", - "\tDWORD ","\nICUDATA_%s\tENDS\n\tEND\n",HEX_0H - } -}; - -static int32_t assemblyHeaderIndex = -1; -static int32_t hexType = HEX_0X; - -U_CAPI UBool U_EXPORT2 -checkAssemblyHeaderName(const char* optAssembly) { - int32_t idx; - assemblyHeaderIndex = -1; - for (idx = 0; idx < UPRV_LENGTHOF(assemblyHeader); idx++) { - if (uprv_strcmp(optAssembly, assemblyHeader[idx].name) == 0) { - assemblyHeaderIndex = idx; - hexType = assemblyHeader[idx].hexType; /* set the hex type */ - return TRUE; - } - } - - return FALSE; -} - - -U_CAPI void U_EXPORT2 -printAssemblyHeadersToStdErr(void) { - int32_t idx; - fprintf(stderr, "%s", assemblyHeader[0].name); - for (idx = 1; idx < UPRV_LENGTHOF(assemblyHeader); idx++) { - fprintf(stderr, ", %s", assemblyHeader[idx].name); - } - fprintf(stderr, - ")\n"); -} - -U_CAPI void U_EXPORT2 -writeAssemblyCode(const char *filename, const char *destdir, const char *optEntryPoint, const char *optFilename, char *outFilePath) { - uint32_t column = MAX_COLUMN; - char entry[64]; - uint32_t buffer[1024]; - char *bufferStr = (char *)buffer; - FileStream *in, *out; - size_t i, length; - - in=T_FileStream_open(filename, "rb"); - if(in==NULL) { - fprintf(stderr, "genccode: unable to open input file %s\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - getOutFilename(filename, destdir, bufferStr, entry, ".S", optFilename); - out=T_FileStream_open(bufferStr, "w"); - if(out==NULL) { - fprintf(stderr, "genccode: unable to open output file %s\n", bufferStr); - exit(U_FILE_ACCESS_ERROR); - } - - if (outFilePath != NULL) { - uprv_strcpy(outFilePath, bufferStr); - } - -#if defined (WINDOWS_WITH_GNUC) && U_PLATFORM != U_PF_CYGWIN - /* Need to fix the file separator character when using MinGW. */ - swapFileSepChar(outFilePath, U_FILE_SEP_CHAR, '/'); -#endif - - if(optEntryPoint != NULL) { - uprv_strcpy(entry, optEntryPoint); - uprv_strcat(entry, "_dat"); - } - - /* turn dashes or dots in the entry name into underscores */ - length=uprv_strlen(entry); - for(i=0; i<length; ++i) { - if(entry[i]=='-' || entry[i]=='.') { - entry[i]='_'; - } - } - - sprintf(bufferStr, assemblyHeader[assemblyHeaderIndex].header, - entry, entry, entry, entry, - entry, entry, entry, entry); - T_FileStream_writeLine(out, bufferStr); - T_FileStream_writeLine(out, assemblyHeader[assemblyHeaderIndex].beginLine); - - for(;;) { - length=T_FileStream_read(in, buffer, sizeof(buffer)); - if(length==0) { - break; - } - if (length != sizeof(buffer)) { - /* pad with extra 0's when at the end of the file */ - for(i=0; i < (length % sizeof(uint32_t)); ++i) { - buffer[length+i] = 0; - } - } - for(i=0; i<(length/sizeof(buffer[0])); i++) { - column = write32(out, buffer[i], column); - } - } - - T_FileStream_writeLine(out, "\n"); - - sprintf(bufferStr, assemblyHeader[assemblyHeaderIndex].footer, - entry, entry, entry, entry, - entry, entry, entry, entry); - T_FileStream_writeLine(out, bufferStr); - - if(T_FileStream_error(in)) { - fprintf(stderr, "genccode: file read error while generating from file %s\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - if(T_FileStream_error(out)) { - fprintf(stderr, "genccode: file write error while generating from file %s\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - T_FileStream_close(out); - T_FileStream_close(in); -} - -U_CAPI void U_EXPORT2 -writeCCode(const char *filename, const char *destdir, const char *optName, const char *optFilename, char *outFilePath) { - uint32_t column = MAX_COLUMN; - char buffer[4096], entry[64]; - FileStream *in, *out; - size_t i, length; - - in=T_FileStream_open(filename, "rb"); - if(in==NULL) { - fprintf(stderr, "genccode: unable to open input file %s\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - if(optName != NULL) { /* prepend 'icudt28_' */ - strcpy(entry, optName); - strcat(entry, "_"); - } else { - entry[0] = 0; - } - - getOutFilename(filename, destdir, buffer, entry+uprv_strlen(entry), ".c", optFilename); - if (outFilePath != NULL) { - uprv_strcpy(outFilePath, buffer); - } - out=T_FileStream_open(buffer, "w"); - if(out==NULL) { - fprintf(stderr, "genccode: unable to open output file %s\n", buffer); - exit(U_FILE_ACCESS_ERROR); - } - - /* turn dashes or dots in the entry name into underscores */ - length=uprv_strlen(entry); - for(i=0; i<length; ++i) { - if(entry[i]=='-' || entry[i]=='.') { - entry[i]='_'; - } - } - -#if U_PLATFORM == U_PF_OS400 - /* - TODO: Fix this once the compiler implements this feature. Keep in sync with udatamem.c - - This is here because this platform can't currently put - const data into the read-only pages of an object or - shared library (service program). Only strings are allowed in read-only - pages, so we use char * strings to store the data. - - In order to prevent the beginning of the data from ever matching the - magic numbers we must still use the initial double. - [grhoten 4/24/2003] - */ - sprintf(buffer, - "#ifndef IN_GENERATED_CCODE\n" - "#define IN_GENERATED_CCODE\n" - "#define U_DISABLE_RENAMING 1\n" - "#include \"unicode/umachine.h\"\n" - "#endif\n" - "U_CDECL_BEGIN\n" - "const struct {\n" - " double bogus;\n" - " const char *bytes; \n" - "} %s={ 0.0, \n", - entry); - T_FileStream_writeLine(out, buffer); - - for(;;) { - length=T_FileStream_read(in, buffer, sizeof(buffer)); - if(length==0) { - break; - } - for(i=0; i<length; ++i) { - column = write8str(out, (uint8_t)buffer[i], column); - } - } - - T_FileStream_writeLine(out, "\"\n};\nU_CDECL_END\n"); -#else - /* Function renaming shouldn't be done in data */ - sprintf(buffer, - "#ifndef IN_GENERATED_CCODE\n" - "#define IN_GENERATED_CCODE\n" - "#define U_DISABLE_RENAMING 1\n" - "#include \"unicode/umachine.h\"\n" - "#endif\n" - "U_CDECL_BEGIN\n" - "const struct {\n" - " double bogus;\n" - " uint8_t bytes[%ld]; \n" - "} %s={ 0.0, {\n", - (long)T_FileStream_size(in), entry); - T_FileStream_writeLine(out, buffer); - - for(;;) { - length=T_FileStream_read(in, buffer, sizeof(buffer)); - if(length==0) { - break; - } - for(i=0; i<length; ++i) { - column = write8(out, (uint8_t)buffer[i], column); - } - } - - T_FileStream_writeLine(out, "\n}\n};\nU_CDECL_END\n"); -#endif - - if(T_FileStream_error(in)) { - fprintf(stderr, "genccode: file read error while generating from file %s\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - if(T_FileStream_error(out)) { - fprintf(stderr, "genccode: file write error while generating from file %s\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - T_FileStream_close(out); - T_FileStream_close(in); -} - -static uint32_t -write32(FileStream *out, uint32_t bitField, uint32_t column) { - int32_t i; - char bitFieldStr[64]; /* This is more bits than needed for a 32-bit number */ - char *s = bitFieldStr; - uint8_t *ptrIdx = (uint8_t *)&bitField; - static const char hexToStr[16] = { - '0','1','2','3', - '4','5','6','7', - '8','9','A','B', - 'C','D','E','F' - }; - - /* write the value, possibly with comma and newline */ - if(column==MAX_COLUMN) { - /* first byte */ - column=1; - } else if(column<32) { - *(s++)=','; - ++column; - } else { - *(s++)='\n'; - uprv_strcpy(s, assemblyHeader[assemblyHeaderIndex].beginLine); - s+=uprv_strlen(s); - column=1; - } - - if (bitField < 10) { - /* It's a small number. Don't waste the space for 0x */ - *(s++)=hexToStr[bitField]; - } - else { - int seenNonZero = 0; /* This is used to remove leading zeros */ - - if(hexType==HEX_0X) { - *(s++)='0'; - *(s++)='x'; - } else if(hexType==HEX_0H) { - *(s++)='0'; - } - - /* This creates a 32-bit field */ -#if U_IS_BIG_ENDIAN - for (i = 0; i < sizeof(uint32_t); i++) -#else - for (i = sizeof(uint32_t)-1; i >= 0 ; i--) -#endif - { - uint8_t value = ptrIdx[i]; - if (value || seenNonZero) { - *(s++)=hexToStr[value>>4]; - *(s++)=hexToStr[value&0xF]; - seenNonZero = 1; - } - } - if(hexType==HEX_0H) { - *(s++)='h'; - } - } - - *(s++)=0; - T_FileStream_writeLine(out, bitFieldStr); - return column; -} - -static uint32_t -write8(FileStream *out, uint8_t byte, uint32_t column) { - char s[4]; - int i=0; - - /* convert the byte value to a string */ - if(byte>=100) { - s[i++]=(char)('0'+byte/100); - byte%=100; - } - if(i>0 || byte>=10) { - s[i++]=(char)('0'+byte/10); - byte%=10; - } - s[i++]=(char)('0'+byte); - s[i]=0; - - /* write the value, possibly with comma and newline */ - if(column==MAX_COLUMN) { - /* first byte */ - column=1; - } else if(column<16) { - T_FileStream_writeLine(out, ","); - ++column; - } else { - T_FileStream_writeLine(out, ",\n"); - column=1; - } - T_FileStream_writeLine(out, s); - return column; -} - -#if U_PLATFORM == U_PF_OS400 -static uint32_t -write8str(FileStream *out, uint8_t byte, uint32_t column) { - char s[8]; - - if (byte > 7) - sprintf(s, "\\x%X", byte); - else - sprintf(s, "\\%X", byte); - - /* write the value, possibly with comma and newline */ - if(column==MAX_COLUMN) { - /* first byte */ - column=1; - T_FileStream_writeLine(out, "\""); - } else if(column<24) { - ++column; - } else { - T_FileStream_writeLine(out, "\"\n\""); - column=1; - } - T_FileStream_writeLine(out, s); - return column; -} -#endif - -static void -getOutFilename(const char *inFilename, const char *destdir, char *outFilename, char *entryName, const char *newSuffix, const char *optFilename) { - const char *basename=findBasename(inFilename), *suffix=uprv_strrchr(basename, '.'); - - /* copy path */ - if(destdir!=NULL && *destdir!=0) { - do { - *outFilename++=*destdir++; - } while(*destdir!=0); - if(*(outFilename-1)!=U_FILE_SEP_CHAR) { - *outFilename++=U_FILE_SEP_CHAR; - } - inFilename=basename; - } else { - while(inFilename<basename) { - *outFilename++=*inFilename++; - } - } - - if(suffix==NULL) { - /* the filename does not have a suffix */ - uprv_strcpy(entryName, inFilename); - if(optFilename != NULL) { - uprv_strcpy(outFilename, optFilename); - } else { - uprv_strcpy(outFilename, inFilename); - } - uprv_strcat(outFilename, newSuffix); - } else { - char *saveOutFilename = outFilename; - /* copy basename */ - while(inFilename<suffix) { - if(*inFilename=='-') { - /* iSeries cannot have '-' in the .o objects. */ - *outFilename++=*entryName++='_'; - inFilename++; - } - else { - *outFilename++=*entryName++=*inFilename++; - } - } - - /* replace '.' by '_' */ - *outFilename++=*entryName++='_'; - ++inFilename; - - /* copy suffix */ - while(*inFilename!=0) { - *outFilename++=*entryName++=*inFilename++; - } - - *entryName=0; - - if(optFilename != NULL) { - uprv_strcpy(saveOutFilename, optFilename); - uprv_strcat(saveOutFilename, newSuffix); - } else { - /* add ".c" */ - uprv_strcpy(outFilename, newSuffix); - } - } -} - -#ifdef CAN_GENERATE_OBJECTS -static void -getArchitecture(uint16_t *pCPU, uint16_t *pBits, UBool *pIsBigEndian, const char *optMatchArch) { - union { - char bytes[2048]; -#ifdef U_ELF - Elf32_Ehdr header32; - /* Elf32_Ehdr and ELF64_Ehdr are identical for the necessary fields. */ -#elif U_PLATFORM_HAS_WIN32_API - IMAGE_FILE_HEADER header; -#endif - } buffer; - - const char *filename; - FileStream *in; - int32_t length; - -#ifdef U_ELF - -#elif U_PLATFORM_HAS_WIN32_API - const IMAGE_FILE_HEADER *pHeader; -#else -# error "Unknown platform for CAN_GENERATE_OBJECTS." -#endif - - if(optMatchArch != NULL) { - filename=optMatchArch; - } else { - /* set defaults */ -#ifdef U_ELF - /* set EM_386 because elf.h does not provide better defaults */ - *pCPU=EM_386; - *pBits=32; - *pIsBigEndian=(UBool)(U_IS_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB); -#elif U_PLATFORM_HAS_WIN32_API -/* _M_IA64 should be defined in windows.h */ -# if defined(_M_IA64) - *pCPU=IMAGE_FILE_MACHINE_IA64; - *pBits = 64; -# elif defined(_M_AMD64) -// link.exe does not really care about the .obj machine type and this will -// allow us to build a dll for both ARM & x64 with an amd64 built tool -// ARM is same as x64 except for first 2 bytes of object file - *pCPU = IMAGE_FILE_MACHINE_UNKNOWN; - // *pCPU = IMAGE_FILE_MACHINE_ARMNT; // If we wanted to be explicit - // *pCPU = IMAGE_FILE_MACHINE_AMD64; // We would use one of these names - *pBits = 64; // Doesn't seem to be used for anything interesting? -# else - *pCPU=IMAGE_FILE_MACHINE_I386; // We would use one of these names - *pBits = 32; -# endif - *pIsBigEndian=FALSE; -#else -# error "Unknown platform for CAN_GENERATE_OBJECTS." -#endif - return; - } - - in=T_FileStream_open(filename, "rb"); - if(in==NULL) { - fprintf(stderr, "genccode: unable to open match-arch file %s\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - length=T_FileStream_read(in, buffer.bytes, sizeof(buffer.bytes)); - -#ifdef U_ELF - if(length<(int32_t)sizeof(Elf32_Ehdr)) { - fprintf(stderr, "genccode: match-arch file %s is too short\n", filename); - exit(U_UNSUPPORTED_ERROR); - } - if( - buffer.header32.e_ident[0]!=ELFMAG0 || - buffer.header32.e_ident[1]!=ELFMAG1 || - buffer.header32.e_ident[2]!=ELFMAG2 || - buffer.header32.e_ident[3]!=ELFMAG3 || - buffer.header32.e_ident[EI_CLASS]<ELFCLASS32 || buffer.header32.e_ident[EI_CLASS]>ELFCLASS64 - ) { - fprintf(stderr, "genccode: match-arch file %s is not an ELF object file, or not supported\n", filename); - exit(U_UNSUPPORTED_ERROR); - } - - *pBits= buffer.header32.e_ident[EI_CLASS]==ELFCLASS32 ? 32 : 64; /* only 32 or 64: see check above */ -#ifdef U_ELF64 - if(*pBits!=32 && *pBits!=64) { - fprintf(stderr, "genccode: currently only supports 32-bit and 64-bit ELF format\n"); - exit(U_UNSUPPORTED_ERROR); - } -#else - if(*pBits!=32) { - fprintf(stderr, "genccode: built with elf.h missing 64-bit definitions\n"); - exit(U_UNSUPPORTED_ERROR); - } -#endif - - *pIsBigEndian=(UBool)(buffer.header32.e_ident[EI_DATA]==ELFDATA2MSB); - if(*pIsBigEndian!=U_IS_BIG_ENDIAN) { - fprintf(stderr, "genccode: currently only same-endianness ELF formats are supported\n"); - exit(U_UNSUPPORTED_ERROR); - } - /* TODO: Support byte swapping */ - - *pCPU=buffer.header32.e_machine; -#elif U_PLATFORM_HAS_WIN32_API - if(length<sizeof(IMAGE_FILE_HEADER)) { - fprintf(stderr, "genccode: match-arch file %s is too short\n", filename); - exit(U_UNSUPPORTED_ERROR); - } - /* TODO: Use buffer.header. Keep aliasing legal. */ - pHeader=(const IMAGE_FILE_HEADER *)buffer.bytes; - *pCPU=pHeader->Machine; - /* - * The number of bits is implicit with the Machine value. - * *pBits is ignored in the calling code, so this need not be precise. - */ - *pBits= *pCPU==IMAGE_FILE_MACHINE_I386 ? 32 : 64; - /* Windows always runs on little-endian CPUs. */ - *pIsBigEndian=FALSE; -#else -# error "Unknown platform for CAN_GENERATE_OBJECTS." -#endif - - T_FileStream_close(in); -} - -U_CAPI void U_EXPORT2 -writeObjectCode(const char *filename, const char *destdir, const char *optEntryPoint, const char *optMatchArch, const char *optFilename, char *outFilePath) { - /* common variables */ - char buffer[4096], entry[96]={ 0 }; - FileStream *in, *out; - const char *newSuffix; - int32_t i, entryLength, length, size, entryOffset=0, entryLengthOffset=0; - - uint16_t cpu, bits; - UBool makeBigEndian; - - /* platform-specific variables and initialization code */ -#ifdef U_ELF - /* 32-bit Elf file header */ - static Elf32_Ehdr header32={ - { - /* e_ident[] */ - ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, - ELFCLASS32, - U_IS_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB, - EV_CURRENT /* EI_VERSION */ - }, - ET_REL, - EM_386, - EV_CURRENT, /* e_version */ - 0, /* e_entry */ - 0, /* e_phoff */ - (Elf32_Off)sizeof(Elf32_Ehdr), /* e_shoff */ - 0, /* e_flags */ - (Elf32_Half)sizeof(Elf32_Ehdr), /* eh_size */ - 0, /* e_phentsize */ - 0, /* e_phnum */ - (Elf32_Half)sizeof(Elf32_Shdr), /* e_shentsize */ - 5, /* e_shnum */ - 2 /* e_shstrndx */ - }; - - /* 32-bit Elf section header table */ - static Elf32_Shdr sectionHeaders32[5]={ - { /* SHN_UNDEF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }, - { /* .symtab */ - 1, /* sh_name */ - SHT_SYMTAB, - 0, /* sh_flags */ - 0, /* sh_addr */ - (Elf32_Off)(sizeof(header32)+sizeof(sectionHeaders32)), /* sh_offset */ - (Elf32_Word)(2*sizeof(Elf32_Sym)), /* sh_size */ - 3, /* sh_link=sect hdr index of .strtab */ - 1, /* sh_info=One greater than the symbol table index of the last - * local symbol (with STB_LOCAL). */ - 4, /* sh_addralign */ - (Elf32_Word)(sizeof(Elf32_Sym)) /* sh_entsize */ - }, - { /* .shstrtab */ - 9, /* sh_name */ - SHT_STRTAB, - 0, /* sh_flags */ - 0, /* sh_addr */ - (Elf32_Off)(sizeof(header32)+sizeof(sectionHeaders32)+2*sizeof(Elf32_Sym)), /* sh_offset */ - 40, /* sh_size */ - 0, /* sh_link */ - 0, /* sh_info */ - 1, /* sh_addralign */ - 0 /* sh_entsize */ - }, - { /* .strtab */ - 19, /* sh_name */ - SHT_STRTAB, - 0, /* sh_flags */ - 0, /* sh_addr */ - (Elf32_Off)(sizeof(header32)+sizeof(sectionHeaders32)+2*sizeof(Elf32_Sym)+40), /* sh_offset */ - (Elf32_Word)sizeof(entry), /* sh_size */ - 0, /* sh_link */ - 0, /* sh_info */ - 1, /* sh_addralign */ - 0 /* sh_entsize */ - }, - { /* .rodata */ - 27, /* sh_name */ - SHT_PROGBITS, - SHF_ALLOC, /* sh_flags */ - 0, /* sh_addr */ - (Elf32_Off)(sizeof(header32)+sizeof(sectionHeaders32)+2*sizeof(Elf32_Sym)+40+sizeof(entry)), /* sh_offset */ - 0, /* sh_size */ - 0, /* sh_link */ - 0, /* sh_info */ - 16, /* sh_addralign */ - 0 /* sh_entsize */ - } - }; - - /* symbol table */ - static Elf32_Sym symbols32[2]={ - { /* STN_UNDEF */ - 0, 0, 0, 0, 0, 0 - }, - { /* data entry point */ - 1, /* st_name */ - 0, /* st_value */ - 0, /* st_size */ - ELF64_ST_INFO(STB_GLOBAL, STT_OBJECT), - 0, /* st_other */ - 4 /* st_shndx=index of related section table entry */ - } - }; - - /* section header string table, with decimal string offsets */ - static const char sectionStrings[40]= - /* 0 */ "\0" - /* 1 */ ".symtab\0" - /* 9 */ ".shstrtab\0" - /* 19 */ ".strtab\0" - /* 27 */ ".rodata\0" - /* 35 */ "\0\0\0\0"; /* contains terminating NUL */ - /* 40: padded to multiple of 8 bytes */ - - /* - * Use entry[] for the string table which will contain only the - * entry point name. - * entry[0] must be 0 (NUL) - * The entry point name can be up to 38 characters long (sizeof(entry)-2). - */ - - /* 16-align .rodata in the .o file, just in case */ - static const char padding[16]={ 0 }; - int32_t paddingSize; - -#ifdef U_ELF64 - /* 64-bit Elf file header */ - static Elf64_Ehdr header64={ - { - /* e_ident[] */ - ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, - ELFCLASS64, - U_IS_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB, - EV_CURRENT /* EI_VERSION */ - }, - ET_REL, - EM_X86_64, - EV_CURRENT, /* e_version */ - 0, /* e_entry */ - 0, /* e_phoff */ - (Elf64_Off)sizeof(Elf64_Ehdr), /* e_shoff */ - 0, /* e_flags */ - (Elf64_Half)sizeof(Elf64_Ehdr), /* eh_size */ - 0, /* e_phentsize */ - 0, /* e_phnum */ - (Elf64_Half)sizeof(Elf64_Shdr), /* e_shentsize */ - 5, /* e_shnum */ - 2 /* e_shstrndx */ - }; - - /* 64-bit Elf section header table */ - static Elf64_Shdr sectionHeaders64[5]={ - { /* SHN_UNDEF */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }, - { /* .symtab */ - 1, /* sh_name */ - SHT_SYMTAB, - 0, /* sh_flags */ - 0, /* sh_addr */ - (Elf64_Off)(sizeof(header64)+sizeof(sectionHeaders64)), /* sh_offset */ - (Elf64_Xword)(2*sizeof(Elf64_Sym)), /* sh_size */ - 3, /* sh_link=sect hdr index of .strtab */ - 1, /* sh_info=One greater than the symbol table index of the last - * local symbol (with STB_LOCAL). */ - 4, /* sh_addralign */ - (Elf64_Xword)(sizeof(Elf64_Sym)) /* sh_entsize */ - }, - { /* .shstrtab */ - 9, /* sh_name */ - SHT_STRTAB, - 0, /* sh_flags */ - 0, /* sh_addr */ - (Elf64_Off)(sizeof(header64)+sizeof(sectionHeaders64)+2*sizeof(Elf64_Sym)), /* sh_offset */ - 40, /* sh_size */ - 0, /* sh_link */ - 0, /* sh_info */ - 1, /* sh_addralign */ - 0 /* sh_entsize */ - }, - { /* .strtab */ - 19, /* sh_name */ - SHT_STRTAB, - 0, /* sh_flags */ - 0, /* sh_addr */ - (Elf64_Off)(sizeof(header64)+sizeof(sectionHeaders64)+2*sizeof(Elf64_Sym)+40), /* sh_offset */ - (Elf64_Xword)sizeof(entry), /* sh_size */ - 0, /* sh_link */ - 0, /* sh_info */ - 1, /* sh_addralign */ - 0 /* sh_entsize */ - }, - { /* .rodata */ - 27, /* sh_name */ - SHT_PROGBITS, - SHF_ALLOC, /* sh_flags */ - 0, /* sh_addr */ - (Elf64_Off)(sizeof(header64)+sizeof(sectionHeaders64)+2*sizeof(Elf64_Sym)+40+sizeof(entry)), /* sh_offset */ - 0, /* sh_size */ - 0, /* sh_link */ - 0, /* sh_info */ - 16, /* sh_addralign */ - 0 /* sh_entsize */ - } - }; - - /* - * 64-bit symbol table - * careful: different order of items compared with Elf32_sym! - */ - static Elf64_Sym symbols64[2]={ - { /* STN_UNDEF */ - 0, 0, 0, 0, 0, 0 - }, - { /* data entry point */ - 1, /* st_name */ - ELF64_ST_INFO(STB_GLOBAL, STT_OBJECT), - 0, /* st_other */ - 4, /* st_shndx=index of related section table entry */ - 0, /* st_value */ - 0 /* st_size */ - } - }; - -#endif /* U_ELF64 */ - - /* entry[] have a leading NUL */ - entryOffset=1; - - /* in the common code, count entryLength from after the NUL */ - entryLengthOffset=1; - - newSuffix=".o"; - -#elif U_PLATFORM_HAS_WIN32_API - struct { - IMAGE_FILE_HEADER fileHeader; - IMAGE_SECTION_HEADER sections[2]; - char linkerOptions[100]; - } objHeader; - IMAGE_SYMBOL symbols[1]; - struct { - DWORD sizeofLongNames; - char longNames[100]; - } symbolNames; - - /* - * entry sometimes have a leading '_' - * overwritten if entryOffset==0 depending on the target platform - * see check for cpu below - */ - entry[0]='_'; - - newSuffix=".obj"; -#else -# error "Unknown platform for CAN_GENERATE_OBJECTS." -#endif - - /* deal with options, files and the entry point name */ - getArchitecture(&cpu, &bits, &makeBigEndian, optMatchArch); - if (optMatchArch) - { - printf("genccode: --match-arch cpu=%hu bits=%hu big-endian=%d\n", cpu, bits, makeBigEndian); - } - else - { - printf("genccode: using architecture cpu=%hu bits=%hu big-endian=%d\n", cpu, bits, makeBigEndian); - } -#if U_PLATFORM_HAS_WIN32_API - if(cpu==IMAGE_FILE_MACHINE_I386) { - entryOffset=1; - } -#endif - - in=T_FileStream_open(filename, "rb"); - if(in==NULL) { - fprintf(stderr, "genccode: unable to open input file %s\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - size=T_FileStream_size(in); - - getOutFilename(filename, destdir, buffer, entry+entryOffset, newSuffix, optFilename); - if (outFilePath != NULL) { - uprv_strcpy(outFilePath, buffer); - } - - if(optEntryPoint != NULL) { - uprv_strcpy(entry+entryOffset, optEntryPoint); - uprv_strcat(entry+entryOffset, "_dat"); - } - /* turn dashes in the entry name into underscores */ - entryLength=(int32_t)uprv_strlen(entry+entryLengthOffset); - for(i=0; i<entryLength; ++i) { - if(entry[entryLengthOffset+i]=='-') { - entry[entryLengthOffset+i]='_'; - } - } - - /* open the output file */ - out=T_FileStream_open(buffer, "wb"); - if(out==NULL) { - fprintf(stderr, "genccode: unable to open output file %s\n", buffer); - exit(U_FILE_ACCESS_ERROR); - } - -#ifdef U_ELF - if(bits==32) { - header32.e_ident[EI_DATA]= makeBigEndian ? ELFDATA2MSB : ELFDATA2LSB; - header32.e_machine=cpu; - - /* 16-align .rodata in the .o file, just in case */ - paddingSize=sectionHeaders32[4].sh_offset & 0xf; - if(paddingSize!=0) { - paddingSize=0x10-paddingSize; - sectionHeaders32[4].sh_offset+=paddingSize; - } - - sectionHeaders32[4].sh_size=(Elf32_Word)size; - - symbols32[1].st_size=(Elf32_Word)size; - - /* write .o headers */ - T_FileStream_write(out, &header32, (int32_t)sizeof(header32)); - T_FileStream_write(out, sectionHeaders32, (int32_t)sizeof(sectionHeaders32)); - T_FileStream_write(out, symbols32, (int32_t)sizeof(symbols32)); - } else /* bits==64 */ { -#ifdef U_ELF64 - header64.e_ident[EI_DATA]= makeBigEndian ? ELFDATA2MSB : ELFDATA2LSB; - header64.e_machine=cpu; - - /* 16-align .rodata in the .o file, just in case */ - paddingSize=sectionHeaders64[4].sh_offset & 0xf; - if(paddingSize!=0) { - paddingSize=0x10-paddingSize; - sectionHeaders64[4].sh_offset+=paddingSize; - } - - sectionHeaders64[4].sh_size=(Elf64_Xword)size; - - symbols64[1].st_size=(Elf64_Xword)size; - - /* write .o headers */ - T_FileStream_write(out, &header64, (int32_t)sizeof(header64)); - T_FileStream_write(out, sectionHeaders64, (int32_t)sizeof(sectionHeaders64)); - T_FileStream_write(out, symbols64, (int32_t)sizeof(symbols64)); -#endif - } - - T_FileStream_write(out, sectionStrings, (int32_t)sizeof(sectionStrings)); - T_FileStream_write(out, entry, (int32_t)sizeof(entry)); - if(paddingSize!=0) { - T_FileStream_write(out, padding, paddingSize); - } -#elif U_PLATFORM_HAS_WIN32_API - /* populate the .obj headers */ - uprv_memset(&objHeader, 0, sizeof(objHeader)); - uprv_memset(&symbols, 0, sizeof(symbols)); - uprv_memset(&symbolNames, 0, sizeof(symbolNames)); - - /* write the linker export directive */ - uprv_strcpy(objHeader.linkerOptions, "-export:"); - length=8; - uprv_strcpy(objHeader.linkerOptions+length, entry); - length+=entryLength; - uprv_strcpy(objHeader.linkerOptions+length, ",data "); - length+=6; - - /* set the file header */ - objHeader.fileHeader.Machine=cpu; - objHeader.fileHeader.NumberOfSections=2; - objHeader.fileHeader.TimeDateStamp=(DWORD)time(NULL); - objHeader.fileHeader.PointerToSymbolTable=IMAGE_SIZEOF_FILE_HEADER+2*IMAGE_SIZEOF_SECTION_HEADER+length+size; /* start of symbol table */ - objHeader.fileHeader.NumberOfSymbols=1; - - /* set the section for the linker options */ - uprv_strncpy((char *)objHeader.sections[0].Name, ".drectve", 8); - objHeader.sections[0].SizeOfRawData=length; - objHeader.sections[0].PointerToRawData=IMAGE_SIZEOF_FILE_HEADER+2*IMAGE_SIZEOF_SECTION_HEADER; - objHeader.sections[0].Characteristics=IMAGE_SCN_LNK_INFO|IMAGE_SCN_LNK_REMOVE|IMAGE_SCN_ALIGN_1BYTES; - - /* set the data section */ - uprv_strncpy((char *)objHeader.sections[1].Name, ".rdata", 6); - objHeader.sections[1].SizeOfRawData=size; - objHeader.sections[1].PointerToRawData=IMAGE_SIZEOF_FILE_HEADER+2*IMAGE_SIZEOF_SECTION_HEADER+length; - objHeader.sections[1].Characteristics=IMAGE_SCN_CNT_INITIALIZED_DATA|IMAGE_SCN_ALIGN_16BYTES|IMAGE_SCN_MEM_READ; - - /* set the symbol table */ - if(entryLength<=8) { - uprv_strncpy((char *)symbols[0].N.ShortName, entry, entryLength); - symbolNames.sizeofLongNames=4; - } else { - symbols[0].N.Name.Short=0; - symbols[0].N.Name.Long=4; - symbolNames.sizeofLongNames=4+entryLength+1; - uprv_strcpy(symbolNames.longNames, entry); - } - symbols[0].SectionNumber=2; - symbols[0].StorageClass=IMAGE_SYM_CLASS_EXTERNAL; - - /* write the file header and the linker options section */ - T_FileStream_write(out, &objHeader, objHeader.sections[1].PointerToRawData); -#else -# error "Unknown platform for CAN_GENERATE_OBJECTS." -#endif - - /* copy the data file into section 2 */ - for(;;) { - length=T_FileStream_read(in, buffer, sizeof(buffer)); - if(length==0) { - break; - } - T_FileStream_write(out, buffer, (int32_t)length); - } - -#if U_PLATFORM_HAS_WIN32_API - /* write the symbol table */ - T_FileStream_write(out, symbols, IMAGE_SIZEOF_SYMBOL); - T_FileStream_write(out, &symbolNames, symbolNames.sizeofLongNames); -#endif - - if(T_FileStream_error(in)) { - fprintf(stderr, "genccode: file read error while generating from file %s\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - if(T_FileStream_error(out)) { - fprintf(stderr, "genccode: file write error while generating from file %s\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - T_FileStream_close(out); - T_FileStream_close(in); -} -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/pkg_genc.h b/deps/node/deps/icu-small/source/tools/toolutil/pkg_genc.h deleted file mode 100644 index 5039f27d..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/pkg_genc.h +++ /dev/null @@ -1,86 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/****************************************************************************** - * Copyright (C) 2008-2011, International Business Machines - * Corporation and others. All Rights Reserved. - ******************************************************************************* - */ - -#ifndef __PKG_GENC_H__ -#define __PKG_GENC_H__ - -#include "unicode/utypes.h" -#include "toolutil.h" - -#include "unicode/putil.h" -#include "putilimp.h" - -/*** Platform #defines move here ***/ -#if U_PLATFORM_HAS_WIN32_API -#ifdef __GNUC__ -#define WINDOWS_WITH_GNUC -#else -#define WINDOWS_WITH_MSVC -#endif -#endif - - -#if !defined(WINDOWS_WITH_MSVC) -#define BUILD_DATA_WITHOUT_ASSEMBLY -#endif - -#ifndef U_DISABLE_OBJ_CODE /* testing */ -#if defined(WINDOWS_WITH_MSVC) || U_PLATFORM_IS_LINUX_BASED -#define CAN_WRITE_OBJ_CODE -#endif -#if U_PLATFORM_HAS_WIN32_API || defined(U_ELF) -#define CAN_GENERATE_OBJECTS -#endif -#endif - -#if U_PLATFORM == U_PF_CYGWIN || defined(CYGWINMSVC) -#define USING_CYGWIN -#endif - -/* - * When building the data library without assembly, - * some platforms use a single c code file for all of - * the data to generate the final data library. This can - * increase the performance of the pkdata tool. - */ -#if U_PLATFORM == U_PF_OS400 -#define USE_SINGLE_CCODE_FILE -#endif - -/* Need to fix the file seperator character when using MinGW. */ -#if defined(WINDOWS_WITH_GNUC) || defined(USING_CYGWIN) -#define PKGDATA_FILE_SEP_STRING "/" -#else -#define PKGDATA_FILE_SEP_STRING U_FILE_SEP_STRING -#endif - -#define LARGE_BUFFER_MAX_SIZE 2048 -#define SMALL_BUFFER_MAX_SIZE 512 -#define SMALL_BUFFER_FLAG_NAMES 32 -#define BUFFER_PADDING_SIZE 20 - -/** End platform defines **/ - - - -U_INTERNAL void U_EXPORT2 -printAssemblyHeadersToStdErr(void); - -U_INTERNAL UBool U_EXPORT2 -checkAssemblyHeaderName(const char* optAssembly); - -U_INTERNAL void U_EXPORT2 -writeCCode(const char *filename, const char *destdir, const char *optName, const char *optFilename, char *outFilePath); - -U_INTERNAL void U_EXPORT2 -writeAssemblyCode(const char *filename, const char *destdir, const char *optEntryPoint, const char *optFilename, char *outFilePath); - -U_INTERNAL void U_EXPORT2 -writeObjectCode(const char *filename, const char *destdir, const char *optEntryPoint, const char *optMatchArch, const char *optFilename, char *outFilePath); - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/pkg_gencmn.cpp b/deps/node/deps/icu-small/source/tools/toolutil/pkg_gencmn.cpp deleted file mode 100644 index 423e4b73..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/pkg_gencmn.cpp +++ /dev/null @@ -1,578 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/****************************************************************************** - * Copyright (C) 2008-2012, International Business Machines - * Corporation and others. All Rights Reserved. - ******************************************************************************* - */ -#include "unicode/utypes.h" - -#include <stdio.h> -#include <stdlib.h> -#include "unicode/utypes.h" -#include "unicode/putil.h" -#include "cmemory.h" -#include "cstring.h" -#include "filestrm.h" -#include "toolutil.h" -#include "unicode/uclean.h" -#include "unewdata.h" -#include "putilimp.h" -#include "pkg_gencmn.h" - -#define STRING_STORE_SIZE 200000 - -#define COMMON_DATA_NAME U_ICUDATA_NAME -#define DATA_TYPE "dat" - -/* ICU package data file format (.dat files) ------------------------------- *** - -Description of the data format after the usual ICU data file header -(UDataInfo etc.). - -Format version 1 - -A .dat package file contains a simple Table of Contents of item names, -followed by the items themselves: - -1. ToC table - -uint32_t count; - number of items -UDataOffsetTOCEntry entry[count]; - pair of uint32_t values per item: - uint32_t nameOffset; - offset of the item name - uint32_t dataOffset; - offset of the item data -both are byte offsets from the beginning of the data - -2. item name strings - -All item names are stored as char * strings in one block between the ToC table -and the data items. - -3. data items - -The data items are stored following the item names block. -Each data item is 16-aligned. -The data items are stored in the sorted order of their names. - -Therefore, the top of the name strings block is the offset of the first item, -the length of the last item is the difference between its offset and -the .dat file length, and the length of all previous items is the difference -between its offset and the next one. - ------------------------------------------------------------------------------ */ - -/* UDataInfo cf. udata.h */ -static const UDataInfo dataInfo={ - sizeof(UDataInfo), - 0, - - U_IS_BIG_ENDIAN, - U_CHARSET_FAMILY, - sizeof(UChar), - 0, - - {0x43, 0x6d, 0x6e, 0x44}, /* dataFormat="CmnD" */ - {1, 0, 0, 0}, /* formatVersion */ - {3, 0, 0, 0} /* dataVersion */ -}; - -static uint32_t maxSize; - -static char stringStore[STRING_STORE_SIZE]; -static uint32_t stringTop=0, basenameTotal=0; - -typedef struct { - char *pathname, *basename; - uint32_t basenameLength, basenameOffset, fileSize, fileOffset; -} File; - -#define CHUNK_FILE_COUNT 256 -static File *files = NULL; -static uint32_t fileCount=0; -static uint32_t fileMax = 0; - - -static char *symPrefix = NULL; - -#define LINE_BUFFER_SIZE 512 -/* prototypes --------------------------------------------------------------- */ - -static void -addFile(const char *filename, const char *name, const char *source, UBool sourceTOC, UBool verbose); - -static char * -allocString(uint32_t length); - -U_CDECL_BEGIN -static int -compareFiles(const void *file1, const void *file2); -U_CDECL_END - -static char * -pathToFullPath(const char *path, const char *source); - -/* map non-tree separator (such as '\') to tree separator ('/') inplace. */ -static void -fixDirToTreePath(char *s); -/* -------------------------------------------------------------------------- */ - -U_CAPI void U_EXPORT2 -createCommonDataFile(const char *destDir, const char *name, const char *entrypointName, const char *type, const char *source, const char *copyRight, - const char *dataFile, uint32_t max_size, UBool sourceTOC, UBool verbose, char *gencmnFileName) { - static char buffer[4096]; - char *line; - char *linePtr; - char *s = NULL; - UErrorCode errorCode=U_ZERO_ERROR; - uint32_t i, fileOffset, basenameOffset, length, nread; - FileStream *in, *file; - - line = (char *)uprv_malloc(sizeof(char) * LINE_BUFFER_SIZE); - if (line == NULL) { - fprintf(stderr, "gencmn: unable to allocate memory for line buffer of size %d\n", LINE_BUFFER_SIZE); - exit(U_MEMORY_ALLOCATION_ERROR); - } - - linePtr = line; - - maxSize = max_size; - - if (destDir == NULL) { - destDir = u_getDataDirectory(); - } - if (name == NULL) { - name = COMMON_DATA_NAME; - } - if (type == NULL) { - type = DATA_TYPE; - } - if (source == NULL) { - source = "."; - } - - if (dataFile == NULL) { - in = T_FileStream_stdin(); - } else { - in = T_FileStream_open(dataFile, "r"); - if(in == NULL) { - fprintf(stderr, "gencmn: unable to open input file %s\n", dataFile); - exit(U_FILE_ACCESS_ERROR); - } - } - - if (verbose) { - if(sourceTOC) { - printf("generating %s_%s.c (table of contents source file)\n", name, type); - } else { - printf("generating %s.%s (common data file with table of contents)\n", name, type); - } - } - - /* read the list of files and get their lengths */ - while((s != NULL && *s != 0) || (s=T_FileStream_readLine(in, (line=linePtr), - LINE_BUFFER_SIZE))!=NULL) { - /* remove trailing newline characters and parse space separated items */ - if (s != NULL && *s != 0) { - line=s; - } else { - s=line; - } - while(*s!=0) { - if(*s==' ') { - *s=0; - ++s; - break; - } else if(*s=='\r' || *s=='\n') { - *s=0; - break; - } - ++s; - } - - /* check for comment */ - - if (*line == '#') { - continue; - } - - /* add the file */ -#if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR) - { - char *t; - while((t = uprv_strchr(line,U_FILE_ALT_SEP_CHAR))) { - *t = U_FILE_SEP_CHAR; - } - } -#endif - addFile(getLongPathname(line), name, source, sourceTOC, verbose); - } - - uprv_free(linePtr); - - if(in!=T_FileStream_stdin()) { - T_FileStream_close(in); - } - - if(fileCount==0) { - fprintf(stderr, "gencmn: no files listed in %s\n", dataFile == NULL ? "<stdin>" : dataFile); - return; - } - - /* sort the files by basename */ - qsort(files, fileCount, sizeof(File), compareFiles); - - if(!sourceTOC) { - UNewDataMemory *out; - - /* determine the offsets of all basenames and files in this common one */ - basenameOffset=4+8*fileCount; - fileOffset=(basenameOffset+(basenameTotal+15))&~0xf; - for(i=0; i<fileCount; ++i) { - files[i].fileOffset=fileOffset; - fileOffset+=(files[i].fileSize+15)&~0xf; - files[i].basenameOffset=basenameOffset; - basenameOffset+=files[i].basenameLength; - } - - /* create the output file */ - out=udata_create(destDir, type, name, - &dataInfo, - copyRight == NULL ? U_COPYRIGHT_STRING : copyRight, - &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "gencmn: udata_create(-d %s -n %s -t %s) failed - %s\n", - destDir, name, type, - u_errorName(errorCode)); - exit(errorCode); - } - - /* write the table of contents */ - udata_write32(out, fileCount); - for(i=0; i<fileCount; ++i) { - udata_write32(out, files[i].basenameOffset); - udata_write32(out, files[i].fileOffset); - } - - /* write the basenames */ - for(i=0; i<fileCount; ++i) { - udata_writeString(out, files[i].basename, files[i].basenameLength); - } - length=4+8*fileCount+basenameTotal; - - /* copy the files */ - for(i=0; i<fileCount; ++i) { - /* pad to 16-align the next file */ - length&=0xf; - if(length!=0) { - udata_writePadding(out, 16-length); - } - - if (verbose) { - printf("adding %s (%ld byte%s)\n", files[i].pathname, (long)files[i].fileSize, files[i].fileSize == 1 ? "" : "s"); - } - - /* copy the next file */ - file=T_FileStream_open(files[i].pathname, "rb"); - if(file==NULL) { - fprintf(stderr, "gencmn: unable to open listed file %s\n", files[i].pathname); - exit(U_FILE_ACCESS_ERROR); - } - for(nread = 0;;) { - length=T_FileStream_read(file, buffer, sizeof(buffer)); - if(length <= 0) { - break; - } - nread += length; - udata_writeBlock(out, buffer, length); - } - T_FileStream_close(file); - length=files[i].fileSize; - - if (nread != files[i].fileSize) { - fprintf(stderr, "gencmn: unable to read %s properly (got %ld/%ld byte%s)\n", files[i].pathname, (long)nread, (long)files[i].fileSize, files[i].fileSize == 1 ? "" : "s"); - exit(U_FILE_ACCESS_ERROR); - } - } - - /* pad to 16-align the last file (cleaner, avoids growing .dat files in icuswap) */ - length&=0xf; - if(length!=0) { - udata_writePadding(out, 16-length); - } - - /* finish */ - udata_finish(out, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "gencmn: udata_finish() failed - %s\n", u_errorName(errorCode)); - exit(errorCode); - } - } else { - /* write a .c source file with the table of contents */ - char *filename; - FileStream *out; - - /* create the output filename */ - filename=s=buffer; - uprv_strcpy(filename, destDir); - s=filename+uprv_strlen(filename); - if(s>filename && *(s-1)!=U_FILE_SEP_CHAR) { - *s++=U_FILE_SEP_CHAR; - } - uprv_strcpy(s, name); - if(*(type)!=0) { - s+=uprv_strlen(s); - *s++='_'; - uprv_strcpy(s, type); - } - s+=uprv_strlen(s); - uprv_strcpy(s, ".c"); - - /* open the output file */ - out=T_FileStream_open(filename, "w"); - if (gencmnFileName != NULL) { - uprv_strcpy(gencmnFileName, filename); - } - if(out==NULL) { - fprintf(stderr, "gencmn: unable to open .c output file %s\n", filename); - exit(U_FILE_ACCESS_ERROR); - } - - /* write the source file */ - sprintf(buffer, - "/*\n" - " * ICU common data table of contents for %s.%s\n" - " * Automatically generated by icu/source/tools/gencmn/gencmn .\n" - " */\n\n" - "#include \"unicode/utypes.h\"\n" - "#include \"unicode/udata.h\"\n" - "\n" - "/* external symbol declarations for data (%d files) */\n", - name, type, fileCount); - T_FileStream_writeLine(out, buffer); - - sprintf(buffer, "extern const char\n %s%s[]", symPrefix?symPrefix:"", files[0].pathname); - T_FileStream_writeLine(out, buffer); - for(i=1; i<fileCount; ++i) { - sprintf(buffer, ",\n %s%s[]", symPrefix?symPrefix:"", files[i].pathname); - T_FileStream_writeLine(out, buffer); - } - T_FileStream_writeLine(out, ";\n\n"); - - sprintf( - buffer, - "U_EXPORT struct {\n" - " uint16_t headerSize;\n" - " uint8_t magic1, magic2;\n" - " UDataInfo info;\n" - " char padding[%lu];\n" - " uint32_t count, reserved;\n" - " struct {\n" - " const char *name;\n" - " const void *data;\n" - " } toc[%lu];\n" - "} U_EXPORT2 %s_dat = {\n" - " 32, 0xda, 0x27, {\n" - " %lu, 0,\n" - " %u, %u, %u, 0,\n" - " {0x54, 0x6f, 0x43, 0x50},\n" - " {1, 0, 0, 0},\n" - " {0, 0, 0, 0}\n" - " },\n" - " \"\", %lu, 0, {\n", - (unsigned long)32-4-sizeof(UDataInfo), - (unsigned long)fileCount, - entrypointName, - (unsigned long)sizeof(UDataInfo), - U_IS_BIG_ENDIAN, - U_CHARSET_FAMILY, - U_SIZEOF_UCHAR, - (unsigned long)fileCount - ); - T_FileStream_writeLine(out, buffer); - - sprintf(buffer, " { \"%s\", %s%s }", files[0].basename, symPrefix?symPrefix:"", files[0].pathname); - T_FileStream_writeLine(out, buffer); - for(i=1; i<fileCount; ++i) { - sprintf(buffer, ",\n { \"%s\", %s%s }", files[i].basename, symPrefix?symPrefix:"", files[i].pathname); - T_FileStream_writeLine(out, buffer); - } - - T_FileStream_writeLine(out, "\n }\n};\n"); - T_FileStream_close(out); - - uprv_free(symPrefix); - } -} - -static void -addFile(const char *filename, const char *name, const char *source, UBool sourceTOC, UBool verbose) { - char *s; - uint32_t length; - char *fullPath = NULL; - - if(fileCount==fileMax) { - fileMax += CHUNK_FILE_COUNT; - files = (File *)uprv_realloc(files, fileMax*sizeof(files[0])); /* note: never freed. */ - if(files==NULL) { - fprintf(stderr, "pkgdata/gencmn: Could not allocate %u bytes for %d files\n", (unsigned int)(fileMax*sizeof(files[0])), fileCount); - exit(U_MEMORY_ALLOCATION_ERROR); - } - } - - if(!sourceTOC) { - FileStream *file; - - if(uprv_pathIsAbsolute(filename)) { - fprintf(stderr, "gencmn: Error: absolute path encountered. Old style paths are not supported. Use relative paths such as 'fur.res' or 'translit%cfur.res'.\n\tBad path: '%s'\n", U_FILE_SEP_CHAR, filename); - exit(U_ILLEGAL_ARGUMENT_ERROR); - } - fullPath = pathToFullPath(filename, source); - /* store the pathname */ - length = (uint32_t)(uprv_strlen(filename) + 1 + uprv_strlen(name) + 1); - s=allocString(length); - uprv_strcpy(s, name); - uprv_strcat(s, U_TREE_ENTRY_SEP_STRING); - uprv_strcat(s, filename); - - /* get the basename */ - fixDirToTreePath(s); - files[fileCount].basename=s; - files[fileCount].basenameLength=length; - - files[fileCount].pathname=fullPath; - - basenameTotal+=length; - - /* try to open the file */ - file=T_FileStream_open(fullPath, "rb"); - if(file==NULL) { - fprintf(stderr, "gencmn: unable to open listed file %s\n", fullPath); - exit(U_FILE_ACCESS_ERROR); - } - - /* get the file length */ - length=T_FileStream_size(file); - if(T_FileStream_error(file) || length<=20) { - fprintf(stderr, "gencmn: unable to get length of listed file %s\n", fullPath); - exit(U_FILE_ACCESS_ERROR); - } - - T_FileStream_close(file); - - /* do not add files that are longer than maxSize */ - if(maxSize && length>maxSize) { - if (verbose) { - printf("%s ignored (size %ld > %ld)\n", fullPath, (long)length, (long)maxSize); - } - return; - } - files[fileCount].fileSize=length; - } else { - char *t; - /* get and store the basename */ - /* need to include the package name */ - length = (uint32_t)(uprv_strlen(filename) + 1 + uprv_strlen(name) + 1); - s=allocString(length); - uprv_strcpy(s, name); - uprv_strcat(s, U_TREE_ENTRY_SEP_STRING); - uprv_strcat(s, filename); - fixDirToTreePath(s); - files[fileCount].basename=s; - /* turn the basename into an entry point name and store in the pathname field */ - t=files[fileCount].pathname=allocString(length); - while(--length>0) { - if(*s=='.' || *s=='-' || *s=='/') { - *t='_'; - } else { - *t=*s; - } - ++s; - ++t; - } - *t=0; - } - ++fileCount; -} - -static char * -allocString(uint32_t length) { - uint32_t top=stringTop+length; - char *p; - - if(top>STRING_STORE_SIZE) { - fprintf(stderr, "gencmn: out of memory\n"); - exit(U_MEMORY_ALLOCATION_ERROR); - } - p=stringStore+stringTop; - stringTop=top; - return p; -} - -static char * -pathToFullPath(const char *path, const char *source) { - int32_t length; - int32_t newLength; - char *fullPath; - int32_t n; - - length = (uint32_t)(uprv_strlen(path) + 1); - newLength = (length + 1 + (int32_t)uprv_strlen(source)); - fullPath = (char *)uprv_malloc(newLength); - if(source != NULL) { - uprv_strcpy(fullPath, source); - uprv_strcat(fullPath, U_FILE_SEP_STRING); - } else { - fullPath[0] = 0; - } - n = (int32_t)uprv_strlen(fullPath); - fullPath[n] = 0; /* Suppress compiler warning for unused variable n */ - /* when conditional code below is not compiled. */ - uprv_strcat(fullPath, path); - -#if (U_FILE_ALT_SEP_CHAR != U_TREE_ENTRY_SEP_CHAR) -#if (U_FILE_ALT_SEP_CHAR != U_FILE_SEP_CHAR) - /* replace tree separator (such as '/') with file sep char (such as ':' or '\\') */ - for(;fullPath[n];n++) { - if(fullPath[n] == U_FILE_ALT_SEP_CHAR) { - fullPath[n] = U_FILE_SEP_CHAR; - } - } -#endif -#endif -#if (U_FILE_SEP_CHAR != U_TREE_ENTRY_SEP_CHAR) - /* replace tree separator (such as '/') with file sep char (such as ':' or '\\') */ - for(;fullPath[n];n++) { - if(fullPath[n] == U_TREE_ENTRY_SEP_CHAR) { - fullPath[n] = U_FILE_SEP_CHAR; - } - } -#endif - return fullPath; -} - -U_CDECL_BEGIN -static int -compareFiles(const void *file1, const void *file2) { - /* sort by basename */ - return uprv_strcmp(((File *)file1)->basename, ((File *)file2)->basename); -} -U_CDECL_END - -static void -fixDirToTreePath(char *s) -{ - (void)s; -#if (U_FILE_SEP_CHAR != U_TREE_ENTRY_SEP_CHAR) || ((U_FILE_ALT_SEP_CHAR != U_FILE_SEP_CHAR) && (U_FILE_ALT_SEP_CHAR != U_TREE_ENTRY_SEP_CHAR)) - char *t; -#endif -#if (U_FILE_SEP_CHAR != U_TREE_ENTRY_SEP_CHAR) - for(t=s;t=uprv_strchr(t,U_FILE_SEP_CHAR);) { - *t = U_TREE_ENTRY_SEP_CHAR; - } -#endif -#if (U_FILE_ALT_SEP_CHAR != U_FILE_SEP_CHAR) && (U_FILE_ALT_SEP_CHAR != U_TREE_ENTRY_SEP_CHAR) - for(t=s;t=uprv_strchr(t,U_FILE_ALT_SEP_CHAR);) { - *t = U_TREE_ENTRY_SEP_CHAR; - } -#endif -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/pkg_gencmn.h b/deps/node/deps/icu-small/source/tools/toolutil/pkg_gencmn.h deleted file mode 100644 index 23823996..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/pkg_gencmn.h +++ /dev/null @@ -1,18 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/****************************************************************************** - * Copyright (C) 2008, International Business Machines - * Corporation and others. All Rights Reserved. - ******************************************************************************* - */ - -#ifndef __PKG_GENCMN_H__ -#define __PKG_GENCMN_H__ - -#include "unicode/utypes.h" - -U_CAPI void U_EXPORT2 -createCommonDataFile(const char *destDir, const char *name, const char *entrypointName, const char *type, const char *source, const char *copyRight, - const char *dataFile, uint32_t max_size, UBool sourceTOC, UBool verbose, char *gencmnFileName); - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/pkg_icu.cpp b/deps/node/deps/icu-small/source/tools/toolutil/pkg_icu.cpp deleted file mode 100644 index ce0bfc21..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/pkg_icu.cpp +++ /dev/null @@ -1,176 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/****************************************************************************** - * Copyright (C) 2008-2015, International Business Machines - * Corporation and others. All Rights Reserved. - ******************************************************************************* - */ -#include "unicode/utypes.h" -#include "unicode/localpointer.h" -#include "unicode/putil.h" -#include "cstring.h" -#include "toolutil.h" -#include "uoptions.h" -#include "uparse.h" -#include "package.h" -#include "pkg_icu.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -// read a file list -------------------------------------------------------- *** - -U_NAMESPACE_USE - -static const struct { - const char *suffix; - int32_t length; -} listFileSuffixes[]={ - { ".txt", 4 }, - { ".lst", 4 }, - { ".tmp", 4 } -}; - -/* check for multiple text file suffixes to see if this list name is a text file name */ -static UBool -isListTextFile(const char *listname) { - const char *listNameEnd=strchr(listname, 0); - const char *suffix; - int32_t i, length; - for(i=0; i<UPRV_LENGTHOF(listFileSuffixes); ++i) { - suffix=listFileSuffixes[i].suffix; - length=listFileSuffixes[i].length; - if((listNameEnd-listname)>length && 0==memcmp(listNameEnd-length, suffix, length)) { - return TRUE; - } - } - return FALSE; -} - -/* - * Read a file list. - * If the listname ends with ".txt", then read the list file - * (in the system/ invariant charset). - * If the listname ends with ".dat", then read the ICU .dat package file. - * Otherwise, read the file itself as a single-item list. - */ -U_CAPI Package * U_EXPORT2 -readList(const char *filesPath, const char *listname, UBool readContents, Package *listPkgIn) { - Package *listPkg = listPkgIn; - FILE *file; - const char *listNameEnd; - - if(listname==NULL || listname[0]==0) { - fprintf(stderr, "missing list file\n"); - return NULL; - } - - if (listPkg == NULL) { - listPkg=new Package(); - if(listPkg==NULL) { - fprintf(stderr, "icupkg: not enough memory\n"); - exit(U_MEMORY_ALLOCATION_ERROR); - } - } - - listNameEnd=strchr(listname, 0); - if(isListTextFile(listname)) { - // read the list file - char line[1024]; - char *end; - const char *start; - - file=fopen(listname, "r"); - if(file==NULL) { - fprintf(stderr, "icupkg: unable to open list file \"%s\"\n", listname); - delete listPkg; - exit(U_FILE_ACCESS_ERROR); - } - - while(fgets(line, sizeof(line), file)) { - // remove comments - end=strchr(line, '#'); - if(end!=NULL) { - *end=0; - } else { - // remove trailing CR LF - end=strchr(line, 0); - while(line<end && (*(end-1)=='\r' || *(end-1)=='\n')) { - *--end=0; - } - } - - // check first non-whitespace character and - // skip empty lines and - // skip lines starting with reserved characters - start=u_skipWhitespace(line); - if(*start==0 || NULL!=strchr(U_PKG_RESERVED_CHARS, *start)) { - continue; - } - - // take whitespace-separated items from the line - for(;;) { - // find whitespace after the item or the end of the line - for(end=(char *)start; *end!=0 && *end!=' ' && *end!='\t'; ++end) {} - if(*end==0) { - // this item is the last one on the line - end=NULL; - } else { - // the item is terminated by whitespace, terminate it with NUL - *end=0; - } - if(readContents) { - listPkg->addFile(filesPath, start); - } else { - listPkg->addItem(start); - } - - // find the start of the next item or exit the loop - if(end==NULL || *(start=u_skipWhitespace(end+1))==0) { - break; - } - } - } - fclose(file); - } else if((listNameEnd-listname)>4 && 0==memcmp(listNameEnd-4, ".dat", 4)) { - // read the ICU .dat package - // Accept a .dat file whose name differs from the ToC prefixes. - listPkg->setAutoPrefix(); - listPkg->readPackage(listname); - } else { - // list the single file itself - if(readContents) { - listPkg->addFile(filesPath, listname); - } else { - listPkg->addItem(listname); - } - } - - return listPkg; -} - -U_CAPI int U_EXPORT2 -writePackageDatFile(const char *outFilename, const char *outComment, const char *sourcePath, const char *addList, Package *pkg, char outType) { - LocalPointer<Package> ownedPkg; - LocalPointer<Package> addListPkg; - - if (pkg == NULL) { - ownedPkg.adoptInstead(new Package); - if(ownedPkg.isNull()) { - fprintf(stderr, "icupkg: not enough memory\n"); - return U_MEMORY_ALLOCATION_ERROR; - } - pkg = ownedPkg.getAlias(); - - addListPkg.adoptInstead(readList(sourcePath, addList, TRUE, NULL)); - if(addListPkg.isValid()) { - pkg->addItems(*addListPkg); - } else { - return U_ILLEGAL_ARGUMENT_ERROR; - } - } - - pkg->writePackage(outFilename, outType, outComment); - return 0; -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/pkg_icu.h b/deps/node/deps/icu-small/source/tools/toolutil/pkg_icu.h deleted file mode 100644 index 638056e6..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/pkg_icu.h +++ /dev/null @@ -1,25 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/****************************************************************************** - * Copyright (C) 2008-2016, International Business Machines - * Corporation and others. All Rights Reserved. - ******************************************************************************* - */ - -#ifndef __PKG_ICU_H__ -#define __PKG_ICU_H__ - -#include "unicode/utypes.h" -#include "package.h" - -#define U_PKG_RESERVED_CHARS "\"%&'()*+,-./:;<=>?_" - -U_CAPI int U_EXPORT2 -writePackageDatFile(const char *outFilename, const char *outComment, - const char *sourcePath, const char *addList, icu::Package *pkg, - char outType); - -U_CAPI icu::Package * U_EXPORT2 -readList(const char *filesPath, const char *listname, UBool readContents, icu::Package *listPkgIn); - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/pkg_imp.h b/deps/node/deps/icu-small/source/tools/toolutil/pkg_imp.h deleted file mode 100644 index 29abd8d8..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/pkg_imp.h +++ /dev/null @@ -1,38 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2005-2016, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: pkg_imp.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2005sep18 -* created by: Markus W. Scherer -* -* Implementation definitions for data package functions in toolutil. -*/ - -#ifndef __PKG_IMP_H__ -#define __PKG_IMP_H__ - -#include "unicode/utypes.h" -#include "unicode/udata.h" - -/* - * Read an ICU data item with any platform type, - * return the pointer to the UDataInfo in its header, - * and set the lengths of the UDataInfo and of the whole header. - * All data remains in its platform type. - */ -U_CFUNC const UDataInfo * -getDataInfo(const uint8_t *data, int32_t length, - int32_t &infoLength, int32_t &headerLength, - UErrorCode *pErrorCode); - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/pkgitems.cpp b/deps/node/deps/icu-small/source/tools/toolutil/pkgitems.cpp deleted file mode 100644 index dd414c2f..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/pkgitems.cpp +++ /dev/null @@ -1,634 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2003-2015, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: pkgitems.cpp -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2005sep18 -* created by: Markus W. Scherer -* -* Companion file to package.cpp. Deals with details of ICU data item formats. -* Used for item dependencies. -* Contains adapted code from ucnv_bld.c (swapper code from 2003). -*/ - -#include "unicode/utypes.h" -#include "unicode/ures.h" -#include "unicode/putil.h" -#include "unicode/udata.h" -#include "cstring.h" -#include "uinvchar.h" -#include "ucmndata.h" -#include "udataswp.h" -#include "swapimpl.h" -#include "toolutil.h" -#include "package.h" -#include "pkg_imp.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -/* item formats in common */ - -#include "uresdata.h" -#include "ucnv_bld.h" -#include "ucnv_io.h" - -// general definitions ----------------------------------------------------- *** - -U_CDECL_BEGIN - -static void U_CALLCONV -printError(void *context, const char *fmt, va_list args) { - vfprintf((FILE *)context, fmt, args); -} - -U_CDECL_END - -// a data item in native-platform form ------------------------------------- *** - -U_NAMESPACE_BEGIN - -class NativeItem { -public: - NativeItem() : pItem(NULL), pInfo(NULL), bytes(NULL), swapped(NULL), length(0) {} - NativeItem(const Item *item, UDataSwapFn *swap) : swapped(NULL) { - setItem(item, swap); - } - ~NativeItem() { - delete [] swapped; - } - const UDataInfo *getDataInfo() const { - return pInfo; - } - const uint8_t *getBytes() const { - return bytes; - } - int32_t getLength() const { - return length; - } - - void setItem(const Item *item, UDataSwapFn *swap) { - pItem=item; - int32_t infoLength, itemHeaderLength; - UErrorCode errorCode=U_ZERO_ERROR; - pInfo=::getDataInfo(pItem->data, pItem->length, infoLength, itemHeaderLength, &errorCode); - if(U_FAILURE(errorCode)) { - exit(errorCode); // should succeed because readFile() checks headers - } - length=pItem->length-itemHeaderLength; - - if(pInfo->isBigEndian==U_IS_BIG_ENDIAN && pInfo->charsetFamily==U_CHARSET_FAMILY) { - bytes=pItem->data+itemHeaderLength; - } else { - UDataSwapper *ds=udata_openSwapper((UBool)pInfo->isBigEndian, pInfo->charsetFamily, U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: udata_openSwapper(\"%s\") failed - %s\n", - pItem->name, u_errorName(errorCode)); - exit(errorCode); - } - - ds->printError=printError; - ds->printErrorContext=stderr; - - swapped=new uint8_t[pItem->length]; - if(swapped==NULL) { - fprintf(stderr, "icupkg: unable to allocate memory for swapping \"%s\"\n", pItem->name); - exit(U_MEMORY_ALLOCATION_ERROR); - } - swap(ds, pItem->data, pItem->length, swapped, &errorCode); - pInfo=::getDataInfo(swapped, pItem->length, infoLength, itemHeaderLength, &errorCode); - bytes=swapped+itemHeaderLength; - udata_closeSwapper(ds); - } - } - -private: - const Item *pItem; - const UDataInfo *pInfo; - const uint8_t *bytes; - uint8_t *swapped; - int32_t length; -}; - -// check a dependency ------------------------------------------------------ *** - -/* - * assemble the target item name from the source item name, an ID - * and a suffix - */ -static void -makeTargetName(const char *itemName, const char *id, int32_t idLength, const char *suffix, - char *target, int32_t capacity, - UErrorCode *pErrorCode) { - const char *itemID; - int32_t treeLength, suffixLength, targetLength; - - // get the item basename - itemID=strrchr(itemName, '/'); - if(itemID!=NULL) { - ++itemID; - } else { - itemID=itemName; - } - - // build the target string - treeLength=(int32_t)(itemID-itemName); - if(idLength<0) { - idLength=(int32_t)strlen(id); - } - suffixLength=(int32_t)strlen(suffix); - targetLength=treeLength+idLength+suffixLength; - if(targetLength>=capacity) { - fprintf(stderr, "icupkg/makeTargetName(%s) target item name length %ld too long\n", - itemName, (long)targetLength); - *pErrorCode=U_BUFFER_OVERFLOW_ERROR; - return; - } - - memcpy(target, itemName, treeLength); - memcpy(target+treeLength, id, idLength); - memcpy(target+treeLength+idLength, suffix, suffixLength+1); // +1 includes the terminating NUL -} - -static void -checkIDSuffix(const char *itemName, const char *id, int32_t idLength, const char *suffix, - CheckDependency check, void *context, - UErrorCode *pErrorCode) { - char target[200]; - makeTargetName(itemName, id, idLength, suffix, target, (int32_t)sizeof(target), pErrorCode); - if(U_SUCCESS(*pErrorCode)) { - check(context, itemName, target); - } -} - -/* assemble the target item name from the item's parent item name */ -static void -checkParent(const char *itemName, CheckDependency check, void *context, - UErrorCode *pErrorCode) { - const char *itemID, *parent, *parentLimit, *suffix; - int32_t parentLength; - - // get the item basename - itemID=strrchr(itemName, '/'); - if(itemID!=NULL) { - ++itemID; - } else { - itemID=itemName; - } - - // get the item suffix - suffix=strrchr(itemID, '.'); - if(suffix==NULL) { - // empty suffix, point to the end of the string - suffix=strrchr(itemID, 0); - } - - // get the position of the last '_' - for(parentLimit=suffix; parentLimit>itemID && *--parentLimit!='_';) {} - - if(parentLimit!=itemID) { - // get the parent item name by truncating the last part of this item's name */ - parent=itemID; - parentLength=(int32_t)(parentLimit-itemID); - } else { - // no '_' in the item name: the parent is the root bundle - parent="root"; - parentLength=4; - if((suffix-itemID)==parentLength && 0==memcmp(itemID, parent, parentLength)) { - // the item itself is "root", which does not depend on a parent - return; - } - } - checkIDSuffix(itemName, parent, parentLength, suffix, check, context, pErrorCode); -} - -// get dependencies from resource bundles ---------------------------------- *** - -static const UChar SLASH=0x2f; - -/* - * Check for the alias from the string or alias resource res. - */ -static void -checkAlias(const char *itemName, - Resource res, const UChar *alias, int32_t length, UBool useResSuffix, - CheckDependency check, void *context, UErrorCode *pErrorCode) { - int32_t i; - - if(!uprv_isInvariantUString(alias, length)) { - fprintf(stderr, "icupkg/ures_enumDependencies(%s res=%08x) alias string contains non-invariant characters\n", - itemName, res); - *pErrorCode=U_INVALID_CHAR_FOUND; - return; - } - - // extract the locale ID from alias strings like - // locale_ID/key1/key2/key3 - // locale_ID - - // search for the first slash - for(i=0; i<length && alias[i]!=SLASH; ++i) {} - - if(res_getPublicType(res)==URES_ALIAS) { - // ignore aliases with an initial slash: - // /ICUDATA/... and /pkgname/... go to a different package - // /LOCALE/... are for dynamic sideways fallbacks and don't go to a fixed bundle - if(i==0) { - return; // initial slash ('/') - } - - // ignore the intra-bundle path starting from the first slash ('/') - length=i; - } else /* URES_STRING */ { - // the whole string should only consist of a locale ID - if(i!=length) { - fprintf(stderr, "icupkg/ures_enumDependencies(%s res=%08x) %%ALIAS contains a '/'\n", - itemName, res); - *pErrorCode=U_UNSUPPORTED_ERROR; - return; - } - } - - // convert the Unicode string to char * - char localeID[32]; - if(length>=(int32_t)sizeof(localeID)) { - fprintf(stderr, "icupkg/ures_enumDependencies(%s res=%08x) alias locale ID length %ld too long\n", - itemName, res, (long)length); - *pErrorCode=U_BUFFER_OVERFLOW_ERROR; - return; - } - u_UCharsToChars(alias, localeID, length); - localeID[length]=0; - - checkIDSuffix(itemName, localeID, -1, (useResSuffix ? ".res" : ""), check, context, pErrorCode); -} - -/* - * Enumerate one resource item and its children and extract dependencies from - * aliases. - */ -static void -ures_enumDependencies(const char *itemName, - const ResourceData *pResData, - Resource res, const char *inKey, const char *parentKey, int32_t depth, - CheckDependency check, void *context, - Package *pkg, - UErrorCode *pErrorCode) { - switch(res_getPublicType(res)) { - case URES_STRING: - { - UBool useResSuffix = TRUE; - // Check for %%ALIAS - if(depth==1 && inKey!=NULL) { - if(0!=strcmp(inKey, "%%ALIAS")) { - break; - } - } - // Check for %%DEPENDENCY - else if(depth==2 && parentKey!=NULL) { - if(0!=strcmp(parentKey, "%%DEPENDENCY")) { - break; - } - useResSuffix = FALSE; - } else { - // we ignore all other strings - break; - } - int32_t length; - const UChar *alias=res_getString(pResData, res, &length); - checkAlias(itemName, res, alias, length, useResSuffix, check, context, pErrorCode); - } - break; - case URES_ALIAS: - { - int32_t length; - const UChar *alias=res_getAlias(pResData, res, &length); - checkAlias(itemName, res, alias, length, TRUE, check, context, pErrorCode); - } - break; - case URES_TABLE: - { - /* recurse */ - int32_t count=res_countArrayItems(pResData, res); - for(int32_t i=0; i<count; ++i) { - const char *itemKey; - Resource item=res_getTableItemByIndex(pResData, res, i, &itemKey); - ures_enumDependencies( - itemName, pResData, - item, itemKey, - inKey, depth+1, - check, context, - pkg, - pErrorCode); - if(U_FAILURE(*pErrorCode)) { - fprintf(stderr, "icupkg/ures_enumDependencies(%s table res=%08x)[%d].recurse(%s: %08x) failed\n", - itemName, res, i, itemKey, item); - break; - } - } - } - break; - case URES_ARRAY: - { - /* recurse */ - int32_t count=res_countArrayItems(pResData, res); - for(int32_t i=0; i<count; ++i) { - Resource item=res_getArrayItem(pResData, res, i); - ures_enumDependencies( - itemName, pResData, - item, NULL, - inKey, depth+1, - check, context, - pkg, - pErrorCode); - if(U_FAILURE(*pErrorCode)) { - fprintf(stderr, "icupkg/ures_enumDependencies(%s array res=%08x)[%d].recurse(%08x) failed\n", - itemName, res, i, item); - break; - } - } - } - break; - default: - break; - } -} - -static void -ures_enumDependencies(const char *itemName, const UDataInfo *pInfo, - const uint8_t *inBytes, int32_t length, - CheckDependency check, void *context, - Package *pkg, - UErrorCode *pErrorCode) { - ResourceData resData; - - res_read(&resData, pInfo, inBytes, length, pErrorCode); - if(U_FAILURE(*pErrorCode)) { - fprintf(stderr, "icupkg: .res format version %02x.%02x not supported, or bundle malformed\n", - pInfo->formatVersion[0], pInfo->formatVersion[1]); - exit(U_UNSUPPORTED_ERROR); - } - - /* - * if the bundle attributes are present and the nofallback flag is not set, - * then add the parent bundle as a dependency - */ - if(pInfo->formatVersion[0]>1 || (pInfo->formatVersion[0]==1 && pInfo->formatVersion[1]>=1)) { - if(!resData.noFallback) { - /* this bundle participates in locale fallback */ - checkParent(itemName, check, context, pErrorCode); - } - } - - icu::NativeItem nativePool; - - if(resData.usesPoolBundle) { - char poolName[200]; - makeTargetName(itemName, "pool", 4, ".res", poolName, (int32_t)sizeof(poolName), pErrorCode); - if(U_FAILURE(*pErrorCode)) { - return; - } - check(context, itemName, poolName); - int32_t index=pkg->findItem(poolName); - if(index<0) { - // We cannot work with a bundle if its pool resource is missing. - // check() already printed a complaint. - return; - } - // TODO: Cache the native version in the Item itself. - nativePool.setItem(pkg->getItem(index), ures_swap); - const UDataInfo *poolInfo=nativePool.getDataInfo(); - if(poolInfo->formatVersion[0]<=1) { - fprintf(stderr, "icupkg: %s is not a pool bundle\n", poolName); - return; - } - const int32_t *poolRoot=(const int32_t *)nativePool.getBytes(); - const int32_t *poolIndexes=poolRoot+1; - int32_t poolIndexLength=poolIndexes[URES_INDEX_LENGTH]&0xff; - if(!(poolIndexLength>URES_INDEX_POOL_CHECKSUM && - (poolIndexes[URES_INDEX_ATTRIBUTES]&URES_ATT_IS_POOL_BUNDLE)) - ) { - fprintf(stderr, "icupkg: %s is not a pool bundle\n", poolName); - return; - } - if(resData.pRoot[1+URES_INDEX_POOL_CHECKSUM]==poolIndexes[URES_INDEX_POOL_CHECKSUM]) { - resData.poolBundleKeys=(const char *)(poolIndexes+poolIndexLength); - resData.poolBundleStrings=(const uint16_t *)(poolRoot+poolIndexes[URES_INDEX_KEYS_TOP]); - } else { - fprintf(stderr, "icupkg: %s has mismatched checksum for %s\n", poolName, itemName); - return; - } - } - - ures_enumDependencies( - itemName, &resData, - resData.rootRes, NULL, NULL, 0, - check, context, - pkg, - pErrorCode); -} - -// get dependencies from conversion tables --------------------------------- *** - -/* code adapted from ucnv_swap() */ -static void -ucnv_enumDependencies(const UDataSwapper *ds, - const char *itemName, const UDataInfo *pInfo, - const uint8_t *inBytes, int32_t length, - CheckDependency check, void *context, - UErrorCode *pErrorCode) { - uint32_t staticDataSize; - - const UConverterStaticData *inStaticData; - - const _MBCSHeader *inMBCSHeader; - uint8_t outputType; - - /* check format version */ - if(!( - pInfo->formatVersion[0]==6 && - pInfo->formatVersion[1]>=2 - )) { - fprintf(stderr, "icupkg/ucnv_enumDependencies(): .cnv format version %02x.%02x not supported\n", - pInfo->formatVersion[0], pInfo->formatVersion[1]); - exit(U_UNSUPPORTED_ERROR); - } - - /* read the initial UConverterStaticData structure after the UDataInfo header */ - inStaticData=(const UConverterStaticData *)inBytes; - - if( length<(int32_t)sizeof(UConverterStaticData) || - (uint32_t)length<(staticDataSize=ds->readUInt32(inStaticData->structSize)) - ) { - udata_printError(ds, "icupkg/ucnv_enumDependencies(): too few bytes (%d after header) for an ICU .cnv conversion table\n", - length); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return; - } - - inBytes+=staticDataSize; - length-=(int32_t)staticDataSize; - - /* check for supported conversionType values */ - if(inStaticData->conversionType==UCNV_MBCS) { - /* MBCS data */ - uint32_t mbcsHeaderLength, mbcsHeaderFlags, mbcsHeaderOptions; - int32_t extOffset; - - inMBCSHeader=(const _MBCSHeader *)inBytes; - - if(length<(int32_t)sizeof(_MBCSHeader)) { - udata_printError(ds, "icupkg/ucnv_enumDependencies(): too few bytes (%d after headers) for an ICU MBCS .cnv conversion table\n", - length); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return; - } - if(inMBCSHeader->version[0]==4 && inMBCSHeader->version[1]>=1) { - mbcsHeaderLength=MBCS_HEADER_V4_LENGTH; - } else if(inMBCSHeader->version[0]==5 && inMBCSHeader->version[1]>=3 && - ((mbcsHeaderOptions=ds->readUInt32(inMBCSHeader->options))& - MBCS_OPT_UNKNOWN_INCOMPATIBLE_MASK)==0 - ) { - mbcsHeaderLength=mbcsHeaderOptions&MBCS_OPT_LENGTH_MASK; - } else { - udata_printError(ds, "icupkg/ucnv_enumDependencies(): unsupported _MBCSHeader.version %d.%d\n", - inMBCSHeader->version[0], inMBCSHeader->version[1]); - *pErrorCode=U_UNSUPPORTED_ERROR; - return; - } - - mbcsHeaderFlags=ds->readUInt32(inMBCSHeader->flags); - extOffset=(int32_t)(mbcsHeaderFlags>>8); - outputType=(uint8_t)mbcsHeaderFlags; - - if(outputType==MBCS_OUTPUT_EXT_ONLY) { - /* - * extension-only file, - * contains a base name instead of normal base table data - */ - char baseName[32]; - int32_t baseNameLength; - - /* there is extension data after the base data, see ucnv_ext.h */ - if(length<(extOffset+UCNV_EXT_INDEXES_MIN_LENGTH*4)) { - udata_printError(ds, "icupkg/ucnv_enumDependencies(): too few bytes (%d after headers) for an ICU MBCS .cnv conversion table with extension data\n", - length); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return; - } - - /* swap the base name, between the header and the extension data */ - const char *inBaseName=(const char *)inBytes+mbcsHeaderLength*4; - baseNameLength=(int32_t)strlen(inBaseName); - if(baseNameLength>=(int32_t)sizeof(baseName)) { - udata_printError(ds, "icupkg/ucnv_enumDependencies(%s): base name length %ld too long\n", - itemName, baseNameLength); - *pErrorCode=U_UNSUPPORTED_ERROR; - return; - } - ds->swapInvChars(ds, inBaseName, baseNameLength+1, baseName, pErrorCode); - - checkIDSuffix(itemName, baseName, -1, ".cnv", check, context, pErrorCode); - } - } -} - -// ICU data formats -------------------------------------------------------- *** - -static const struct { - uint8_t dataFormat[4]; -} dataFormats[]={ - { { 0x52, 0x65, 0x73, 0x42 } }, /* dataFormat="ResB" */ - { { 0x63, 0x6e, 0x76, 0x74 } }, /* dataFormat="cnvt" */ - { { 0x43, 0x76, 0x41, 0x6c } } /* dataFormat="CvAl" */ -}; - -enum { - FMT_RES, - FMT_CNV, - FMT_ALIAS, - FMT_COUNT -}; - -static int32_t -getDataFormat(const uint8_t dataFormat[4]) { - int32_t i; - - for(i=0; i<FMT_COUNT; ++i) { - if(0==memcmp(dataFormats[i].dataFormat, dataFormat, 4)) { - return i; - } - } - return -1; -} - -// enumerate dependencies of a package item -------------------------------- *** - -void -Package::enumDependencies(Item *pItem, void *context, CheckDependency check) { - int32_t infoLength, itemHeaderLength; - UErrorCode errorCode=U_ZERO_ERROR; - const UDataInfo *pInfo=getDataInfo(pItem->data, pItem->length, infoLength, itemHeaderLength, &errorCode); - if(U_FAILURE(errorCode)) { - return; // should not occur because readFile() checks headers - } - - // find the data format and call the corresponding function, if any - int32_t format=getDataFormat(pInfo->dataFormat); - if(format>=0) { - switch(format) { - case FMT_RES: - { - /* - * Swap the resource bundle (if necessary) so that we can use - * the normal runtime uresdata.c code to read it. - * We do not want to duplicate that code, especially not together with on-the-fly swapping. - */ - NativeItem nrb(pItem, ures_swap); - ures_enumDependencies(pItem->name, nrb.getDataInfo(), nrb.getBytes(), nrb.getLength(), check, context, this, &errorCode); - break; - } - case FMT_CNV: - { - // TODO: share/cache swappers - UDataSwapper *ds=udata_openSwapper( - (UBool)pInfo->isBigEndian, pInfo->charsetFamily, - U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, - &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, "icupkg: udata_openSwapper(\"%s\") failed - %s\n", - pItem->name, u_errorName(errorCode)); - exit(errorCode); - } - - ds->printError=printError; - ds->printErrorContext=stderr; - - const uint8_t *inBytes=pItem->data+itemHeaderLength; - int32_t length=pItem->length-itemHeaderLength; - - ucnv_enumDependencies(ds, pItem->name, pInfo, inBytes, length, check, context, &errorCode); - udata_closeSwapper(ds); - break; - } - default: - break; - } - - if(U_FAILURE(errorCode)) { - exit(errorCode); - } - } -} - -U_NAMESPACE_END diff --git a/deps/node/deps/icu-small/source/tools/toolutil/ppucd.cpp b/deps/node/deps/icu-small/source/tools/toolutil/ppucd.cpp deleted file mode 100644 index b11efa7f..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/ppucd.cpp +++ /dev/null @@ -1,615 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* Copyright (C) 2011-2014, International Business Machines -* Corporation and others. All Rights Reserved. -******************************************************************************* -* file name: ppucd.cpp -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2011dec11 -* created by: Markus W. Scherer -*/ - -#include "unicode/utypes.h" -#include "unicode/uchar.h" -#include "charstr.h" -#include "cstring.h" -#include "ppucd.h" -#include "uassert.h" -#include "uparse.h" - -#include <stdio.h> -#include <string.h> - -U_NAMESPACE_BEGIN - -PropertyNames::~PropertyNames() {} - -int32_t -PropertyNames::getPropertyEnum(const char *name) const { - return u_getPropertyEnum(name); -} - -int32_t -PropertyNames::getPropertyValueEnum(int32_t property, const char *name) const { - return u_getPropertyValueEnum((UProperty)property, name); -} - -UniProps::UniProps() - : start(U_SENTINEL), end(U_SENTINEL), - bmg(U_SENTINEL), bpb(U_SENTINEL), - scf(U_SENTINEL), slc(U_SENTINEL), stc(U_SENTINEL), suc(U_SENTINEL), - digitValue(-1), numericValue(NULL), - name(NULL), nameAlias(NULL) { - memset(binProps, 0, sizeof(binProps)); - memset(intProps, 0, sizeof(intProps)); - memset(age, 0, 4); -} - -UniProps::~UniProps() {} - -const int32_t PreparsedUCD::kNumLineBuffers; - -PreparsedUCD::PreparsedUCD(const char *filename, UErrorCode &errorCode) - : icuPnames(new PropertyNames()), pnames(icuPnames), - file(NULL), - defaultLineIndex(-1), blockLineIndex(-1), lineIndex(0), - lineNumber(0), - lineType(NO_LINE), - fieldLimit(NULL), lineLimit(NULL) { - if(U_FAILURE(errorCode)) { return; } - - if(filename==NULL || *filename==0 || (*filename=='-' && filename[1]==0)) { - filename=NULL; - file=stdin; - } else { - file=fopen(filename, "r"); - } - if(file==NULL) { - perror("error opening preparsed UCD"); - fprintf(stderr, "error opening preparsed UCD file %s\n", filename ? filename : "\"no file name given\""); - errorCode=U_FILE_ACCESS_ERROR; - return; - } - - memset(ucdVersion, 0, 4); - lines[0][0]=0; -} - -PreparsedUCD::~PreparsedUCD() { - if(file!=stdin) { - fclose(file); - } - delete icuPnames; -} - -// Same order as the LineType values. -static const char *lineTypeStrings[]={ - NULL, - NULL, - "ucd", - "property", - "binary", - "value", - "defaults", - "block", - "cp", - "unassigned", - "algnamesrange" -}; - -PreparsedUCD::LineType -PreparsedUCD::readLine(UErrorCode &errorCode) { - if(U_FAILURE(errorCode)) { return NO_LINE; } - // Select the next available line buffer. - while(!isLineBufferAvailable(lineIndex)) { - ++lineIndex; - if (lineIndex == kNumLineBuffers) { - lineIndex = 0; - } - } - char *line=lines[lineIndex]; - *line=0; - lineLimit=fieldLimit=line; - lineType=NO_LINE; - char *result=fgets(line, sizeof(lines[0]), file); - if(result==NULL) { - if(ferror(file)) { - perror("error reading preparsed UCD"); - fprintf(stderr, "error reading preparsed UCD before line %ld\n", (long)lineNumber); - errorCode=U_FILE_ACCESS_ERROR; - } - return NO_LINE; - } - ++lineNumber; - if(*line=='#') { - fieldLimit=strchr(line, 0); - return lineType=EMPTY_LINE; - } - // Remove trailing /r/n. - char c; - char *limit=strchr(line, 0); - while(line<limit && ((c=*(limit-1))=='\n' || c=='\r')) { --limit; } - // Remove trailing white space. - while(line<limit && ((c=*(limit-1))==' ' || c=='\t')) { --limit; } - *limit=0; - lineLimit=limit; - if(line==limit) { - fieldLimit=limit; - return lineType=EMPTY_LINE; - } - // Split by ';'. - char *semi=line; - while((semi=strchr(semi, ';'))!=NULL) { *semi++=0; } - fieldLimit=strchr(line, 0); - // Determine the line type. - int32_t type; - for(type=EMPTY_LINE+1;; ++type) { - if(type==LINE_TYPE_COUNT) { - fprintf(stderr, - "error in preparsed UCD: unknown line type (first field) '%s' on line %ld\n", - line, (long)lineNumber); - errorCode=U_PARSE_ERROR; - return NO_LINE; - } - if(0==strcmp(line, lineTypeStrings[type])) { - break; - } - } - lineType=(LineType)type; - if(lineType==UNICODE_VERSION_LINE && fieldLimit<lineLimit) { - u_versionFromString(ucdVersion, fieldLimit+1); - } - return lineType; -} - -const char * -PreparsedUCD::firstField() { - char *field=lines[lineIndex]; - fieldLimit=strchr(field, 0); - return field; -} - -const char * -PreparsedUCD::nextField() { - if(fieldLimit==lineLimit) { return NULL; } - char *field=fieldLimit+1; - fieldLimit=strchr(field, 0); - return field; -} - -const UniProps * -PreparsedUCD::getProps(UnicodeSet &newValues, UErrorCode &errorCode) { - if(U_FAILURE(errorCode)) { return NULL; } - newValues.clear(); - if(!lineHasPropertyValues()) { - errorCode=U_ILLEGAL_ARGUMENT_ERROR; - return NULL; - } - firstField(); - const char *field=nextField(); - if(field==NULL) { - // No range field after the type. - fprintf(stderr, - "error in preparsed UCD: missing default/block/cp range field " - "(no second field) on line %ld\n", - (long)lineNumber); - errorCode=U_PARSE_ERROR; - return NULL; - } - UChar32 start, end; - if(!parseCodePointRange(field, start, end, errorCode)) { return NULL; } - UniProps *props; - UBool insideBlock=FALSE; // TRUE if cp or unassigned range inside the block range. - switch(lineType) { - case DEFAULTS_LINE: - // Should occur before any block/cp/unassigned line. - if(blockLineIndex>=0) { - fprintf(stderr, - "error in preparsed UCD: default line %ld after one or more block lines\n", - (long)lineNumber); - errorCode=U_PARSE_ERROR; - return NULL; - } - if(defaultLineIndex>=0) { - fprintf(stderr, - "error in preparsed UCD: second line with default properties on line %ld\n", - (long)lineNumber); - errorCode=U_PARSE_ERROR; - return NULL; - } - if(start!=0 || end!=0x10ffff) { - fprintf(stderr, - "error in preparsed UCD: default range must be 0..10FFFF, not '%s' on line %ld\n", - field, (long)lineNumber); - errorCode=U_PARSE_ERROR; - return NULL; - } - props=&defaultProps; - defaultLineIndex=lineIndex; - break; - case BLOCK_LINE: - blockProps=defaultProps; // Block inherits default properties. - props=&blockProps; - blockLineIndex=lineIndex; - break; - case CP_LINE: - case UNASSIGNED_LINE: - if(blockProps.start<=start && end<=blockProps.end) { - insideBlock=TRUE; - if(lineType==CP_LINE) { - // Code point range fully inside the last block inherits the block properties. - cpProps=blockProps; - } else { - // Unassigned line inside the block is based on default properties - // which override block properties. - cpProps=defaultProps; - newValues=blockValues; - // Except, it inherits the one blk=Block property. - int32_t blkIndex=UCHAR_BLOCK-UCHAR_INT_START; - cpProps.intProps[blkIndex]=blockProps.intProps[blkIndex]; - newValues.remove((UChar32)UCHAR_BLOCK); - } - } else if(start>blockProps.end || end<blockProps.start) { - // Code point range fully outside the last block inherits the default properties. - cpProps=defaultProps; - } else { - // Code point range partially overlapping with the last block is illegal. - fprintf(stderr, - "error in preparsed UCD: cp range %s on line %ld only " - "partially overlaps with block range %04lX..%04lX\n", - field, (long)lineNumber, (long)blockProps.start, (long)blockProps.end); - errorCode=U_PARSE_ERROR; - return NULL; - } - props=&cpProps; - break; - default: - // Will not occur because of the range check above. - errorCode=U_ILLEGAL_ARGUMENT_ERROR; - return NULL; - } - props->start=start; - props->end=end; - while((field=nextField())!=NULL) { - if(!parseProperty(*props, field, newValues, errorCode)) { return NULL; } - } - if(lineType==BLOCK_LINE) { - blockValues=newValues; - } else if(lineType==UNASSIGNED_LINE && insideBlock) { - // Unset newValues for values that are the same as the block values. - for(int32_t prop=0; prop<UCHAR_BINARY_LIMIT; ++prop) { - if(newValues.contains(prop) && cpProps.binProps[prop]==blockProps.binProps[prop]) { - newValues.remove(prop); - } - } - for(int32_t prop=UCHAR_INT_START; prop<UCHAR_INT_LIMIT; ++prop) { - int32_t index=prop-UCHAR_INT_START; - if(newValues.contains(prop) && cpProps.intProps[index]==blockProps.intProps[index]) { - newValues.remove(prop); - } - } - } - return props; -} - -static const struct { - const char *name; - int32_t prop; -} ppucdProperties[]={ - { "Name_Alias", PPUCD_NAME_ALIAS }, - { "Conditional_Case_Mappings", PPUCD_CONDITIONAL_CASE_MAPPINGS }, - { "Turkic_Case_Folding", PPUCD_TURKIC_CASE_FOLDING } -}; - -// Returns TRUE for "ok to continue parsing fields". -UBool -PreparsedUCD::parseProperty(UniProps &props, const char *field, UnicodeSet &newValues, - UErrorCode &errorCode) { - CharString pBuffer; - const char *p=field; - const char *v=strchr(p, '='); - int binaryValue; - if(*p=='-') { - if(v!=NULL) { - fprintf(stderr, - "error in preparsed UCD: mix of binary-property-no and " - "enum-property syntax '%s' on line %ld\n", - field, (long)lineNumber); - errorCode=U_PARSE_ERROR; - return FALSE; - } - binaryValue=0; - ++p; - } else if(v==NULL) { - binaryValue=1; - } else { - binaryValue=-1; - // Copy out the property name rather than modifying the field (writing a NUL). - pBuffer.append(p, (int32_t)(v-p), errorCode); - p=pBuffer.data(); - ++v; - } - int32_t prop=pnames->getPropertyEnum(p); - if(prop<0) { - for(int32_t i=0;; ++i) { - if(i==UPRV_LENGTHOF(ppucdProperties)) { - // Ignore unknown property names. - return TRUE; - } - if(0==uprv_stricmp(p, ppucdProperties[i].name)) { - prop=ppucdProperties[i].prop; - U_ASSERT(prop>=0); - break; - } - } - } - if(prop<UCHAR_BINARY_LIMIT) { - if(binaryValue>=0) { - props.binProps[prop]=(UBool)binaryValue; - } else { - // No binary value for a binary property. - fprintf(stderr, - "error in preparsed UCD: enum-property syntax '%s' " - "for binary property on line %ld\n", - field, (long)lineNumber); - errorCode=U_PARSE_ERROR; - } - } else if(binaryValue>=0) { - // Binary value for a non-binary property. - fprintf(stderr, - "error in preparsed UCD: binary-property syntax '%s' " - "for non-binary property on line %ld\n", - field, (long)lineNumber); - errorCode=U_PARSE_ERROR; - } else if (prop < UCHAR_INT_START) { - fprintf(stderr, - "error in preparsed UCD: prop value is invalid: '%d' for line %ld\n", - prop, (long)lineNumber); - errorCode=U_PARSE_ERROR; - } else if(prop<UCHAR_INT_LIMIT) { - int32_t value=pnames->getPropertyValueEnum(prop, v); - if(value==UCHAR_INVALID_CODE && prop==UCHAR_CANONICAL_COMBINING_CLASS) { - // TODO: Make getPropertyValueEnum(UCHAR_CANONICAL_COMBINING_CLASS, v) work. - char *end; - unsigned long ccc=uprv_strtoul(v, &end, 10); - if(v<end && *end==0 && ccc<=254) { - value=(int32_t)ccc; - } - } - if(value==UCHAR_INVALID_CODE) { - fprintf(stderr, - "error in preparsed UCD: '%s' is not a valid value on line %ld\n", - field, (long)lineNumber); - errorCode=U_PARSE_ERROR; - } else { - props.intProps[prop-UCHAR_INT_START]=value; - } - } else if(*v=='<') { - // Do not parse default values like <code point>, just set null values. - switch(prop) { - case UCHAR_BIDI_MIRRORING_GLYPH: - props.bmg=U_SENTINEL; - break; - case UCHAR_BIDI_PAIRED_BRACKET: - props.bpb=U_SENTINEL; - break; - case UCHAR_SIMPLE_CASE_FOLDING: - props.scf=U_SENTINEL; - break; - case UCHAR_SIMPLE_LOWERCASE_MAPPING: - props.slc=U_SENTINEL; - break; - case UCHAR_SIMPLE_TITLECASE_MAPPING: - props.stc=U_SENTINEL; - break; - case UCHAR_SIMPLE_UPPERCASE_MAPPING: - props.suc=U_SENTINEL; - break; - case UCHAR_CASE_FOLDING: - props.cf.remove(); - break; - case UCHAR_LOWERCASE_MAPPING: - props.lc.remove(); - break; - case UCHAR_TITLECASE_MAPPING: - props.tc.remove(); - break; - case UCHAR_UPPERCASE_MAPPING: - props.uc.remove(); - break; - case UCHAR_SCRIPT_EXTENSIONS: - props.scx.clear(); - break; - default: - fprintf(stderr, - "error in preparsed UCD: '%s' is not a valid default value on line %ld\n", - field, (long)lineNumber); - errorCode=U_PARSE_ERROR; - } - } else { - char c; - switch(prop) { - case UCHAR_NUMERIC_VALUE: - props.numericValue=v; - c=*v; - if('0'<=c && c<='9' && v[1]==0) { - props.digitValue=c-'0'; - } else { - props.digitValue=-1; - } - break; - case UCHAR_NAME: - props.name=v; - break; - case UCHAR_AGE: - u_versionFromString(props.age, v); // Writes 0.0.0.0 if v is not numeric. - break; - case UCHAR_BIDI_MIRRORING_GLYPH: - props.bmg=parseCodePoint(v, errorCode); - break; - case UCHAR_BIDI_PAIRED_BRACKET: - props.bpb=parseCodePoint(v, errorCode); - break; - case UCHAR_SIMPLE_CASE_FOLDING: - props.scf=parseCodePoint(v, errorCode); - break; - case UCHAR_SIMPLE_LOWERCASE_MAPPING: - props.slc=parseCodePoint(v, errorCode); - break; - case UCHAR_SIMPLE_TITLECASE_MAPPING: - props.stc=parseCodePoint(v, errorCode); - break; - case UCHAR_SIMPLE_UPPERCASE_MAPPING: - props.suc=parseCodePoint(v, errorCode); - break; - case UCHAR_CASE_FOLDING: - parseString(v, props.cf, errorCode); - break; - case UCHAR_LOWERCASE_MAPPING: - parseString(v, props.lc, errorCode); - break; - case UCHAR_TITLECASE_MAPPING: - parseString(v, props.tc, errorCode); - break; - case UCHAR_UPPERCASE_MAPPING: - parseString(v, props.uc, errorCode); - break; - case PPUCD_NAME_ALIAS: - props.nameAlias=v; - break; - case PPUCD_CONDITIONAL_CASE_MAPPINGS: - case PPUCD_TURKIC_CASE_FOLDING: - // No need to parse their values: They are hardcoded in the runtime library. - break; - case UCHAR_SCRIPT_EXTENSIONS: - parseScriptExtensions(v, props.scx, errorCode); - break; - default: - // Ignore unhandled properties. - return TRUE; - } - } - if(U_SUCCESS(errorCode)) { - newValues.add((UChar32)prop); - return TRUE; - } else { - return FALSE; - } -} - -UBool -PreparsedUCD::getRangeForAlgNames(UChar32 &start, UChar32 &end, UErrorCode &errorCode) { - if(U_FAILURE(errorCode)) { return FALSE; } - if(lineType!=ALG_NAMES_RANGE_LINE) { - errorCode=U_ILLEGAL_ARGUMENT_ERROR; - return FALSE; - } - firstField(); - const char *field=nextField(); - if(field==NULL) { - // No range field after the type. - fprintf(stderr, - "error in preparsed UCD: missing algnamesrange range field " - "(no second field) on line %ld\n", - (long)lineNumber); - errorCode=U_PARSE_ERROR; - return FALSE; - } - return parseCodePointRange(field, start, end, errorCode); -} - -UChar32 -PreparsedUCD::parseCodePoint(const char *s, UErrorCode &errorCode) { - char *end; - uint32_t value=(uint32_t)uprv_strtoul(s, &end, 16); - if(end<=s || *end!=0 || value>=0x110000) { - fprintf(stderr, - "error in preparsed UCD: '%s' is not a valid code point on line %ld\n", - s, (long)lineNumber); - errorCode=U_PARSE_ERROR; - return U_SENTINEL; - } - return (UChar32)value; -} - -UBool -PreparsedUCD::parseCodePointRange(const char *s, UChar32 &start, UChar32 &end, UErrorCode &errorCode) { - uint32_t st, e; - u_parseCodePointRange(s, &st, &e, &errorCode); - if(U_FAILURE(errorCode)) { - fprintf(stderr, - "error in preparsed UCD: '%s' is not a valid code point range on line %ld\n", - s, (long)lineNumber); - return FALSE; - } - start=(UChar32)st; - end=(UChar32)e; - return TRUE; -} - -void -PreparsedUCD::parseString(const char *s, UnicodeString &uni, UErrorCode &errorCode) { - UChar *buffer=toUCharPtr(uni.getBuffer(-1)); - int32_t length=u_parseString(s, buffer, uni.getCapacity(), NULL, &errorCode); - if(errorCode==U_BUFFER_OVERFLOW_ERROR) { - errorCode=U_ZERO_ERROR; - uni.releaseBuffer(0); - buffer=toUCharPtr(uni.getBuffer(length)); - length=u_parseString(s, buffer, uni.getCapacity(), NULL, &errorCode); - } - uni.releaseBuffer(length); - if(U_FAILURE(errorCode)) { - fprintf(stderr, - "error in preparsed UCD: '%s' is not a valid Unicode string on line %ld\n", - s, (long)lineNumber); - } -} - -void -PreparsedUCD::parseScriptExtensions(const char *s, UnicodeSet &scx, UErrorCode &errorCode) { - if(U_FAILURE(errorCode)) { return; } - scx.clear(); - CharString scString; - for(;;) { - const char *scs; - const char *scLimit=strchr(s, ' '); - if(scLimit!=NULL) { - scs=scString.clear().append(s, (int32_t)(scLimit-s), errorCode).data(); - if(U_FAILURE(errorCode)) { return; } - } else { - scs=s; - } - int32_t script=pnames->getPropertyValueEnum(UCHAR_SCRIPT, scs); - if(script==UCHAR_INVALID_CODE) { - fprintf(stderr, - "error in preparsed UCD: '%s' is not a valid script code on line %ld\n", - scs, (long)lineNumber); - errorCode=U_PARSE_ERROR; - return; - } else if(scx.contains(script)) { - fprintf(stderr, - "error in preparsed UCD: scx has duplicate '%s' codes on line %ld\n", - scs, (long)lineNumber); - errorCode=U_PARSE_ERROR; - return; - } else { - scx.add(script); - } - if(scLimit!=NULL) { - s=scLimit+1; - } else { - break; - } - } - if(scx.isEmpty()) { - fprintf(stderr, "error in preparsed UCD: empty scx= on line %ld\n", (long)lineNumber); - errorCode=U_PARSE_ERROR; - } -} - -U_NAMESPACE_END diff --git a/deps/node/deps/icu-small/source/tools/toolutil/ppucd.h b/deps/node/deps/icu-small/source/tools/toolutil/ppucd.h deleted file mode 100644 index 1f9fb295..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/ppucd.h +++ /dev/null @@ -1,181 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* Copyright (C) 2011-2013, International Business Machines -* Corporation and others. All Rights Reserved. -******************************************************************************* -* file name: ppucd.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2011dec11 -* created by: Markus W. Scherer -*/ - -#ifndef __PPUCD_H__ -#define __PPUCD_H__ - -#include "unicode/utypes.h" -#include "unicode/uniset.h" -#include "unicode/unistr.h" - -#include <stdio.h> - -/** Additions to the uchar.h enum UProperty. */ -enum { - /** Name_Alias */ - PPUCD_NAME_ALIAS=UCHAR_STRING_LIMIT, - PPUCD_CONDITIONAL_CASE_MAPPINGS, - PPUCD_TURKIC_CASE_FOLDING -}; - -U_NAMESPACE_BEGIN - -class U_TOOLUTIL_API PropertyNames { -public: - virtual ~PropertyNames(); - virtual int32_t getPropertyEnum(const char *name) const; - virtual int32_t getPropertyValueEnum(int32_t property, const char *name) const; -}; - -struct U_TOOLUTIL_API UniProps { - UniProps(); - ~UniProps(); - - int32_t getIntProp(int32_t prop) const { return intProps[prop-UCHAR_INT_START]; } - - UChar32 start, end; - UBool binProps[UCHAR_BINARY_LIMIT]; - int32_t intProps[UCHAR_INT_LIMIT-UCHAR_INT_START]; - UVersionInfo age; - UChar32 bmg, bpb; - UChar32 scf, slc, stc, suc; - int32_t digitValue; - const char *numericValue; - const char *name; - const char *nameAlias; - UnicodeString cf, lc, tc, uc; - UnicodeSet scx; -}; - -class U_TOOLUTIL_API PreparsedUCD { -public: - enum LineType { - /** No line, end of file. */ - NO_LINE, - /** Empty line. (Might contain a comment.) */ - EMPTY_LINE, - - /** ucd;6.1.0 */ - UNICODE_VERSION_LINE, - - /** property;Binary;Alpha;Alphabetic */ - PROPERTY_LINE, - /** binary;N;No;F;False */ - BINARY_LINE, - /** value;gc;Zs;Space_Separator */ - VALUE_LINE, - - /** defaults;0000..10FFFF;age=NA;bc=L;... */ - DEFAULTS_LINE, - /** block;0000..007F;age=1.1;blk=ASCII;ea=Na;... */ - BLOCK_LINE, - /** cp;0030;AHex;bc=EN;gc=Nd;na=DIGIT ZERO;... */ - CP_LINE, - /** unassigned;E01F0..E0FFF;bc=BN;CWKCF;DI;GCB=CN;NFKC_CF= */ - UNASSIGNED_LINE, - - /** algnamesrange;4E00..9FCC;han;CJK UNIFIED IDEOGRAPH- */ - ALG_NAMES_RANGE_LINE, - - LINE_TYPE_COUNT - }; - - /** - * Constructor. - * Prepare this object for a new, empty package. - */ - PreparsedUCD(const char *filename, UErrorCode &errorCode); - - /** Destructor. */ - ~PreparsedUCD(); - - /** Sets (aliases) a non-standard PropertyNames implementation. Caller retains ownership. */ - void setPropertyNames(const PropertyNames *pn) { pnames=pn; } - - /** - * Reads a line from the preparsed UCD file. - * Splits the line by replacing each ';' with a NUL. - */ - LineType readLine(UErrorCode &errorCode); - - /** Returns the number of the line read by readLine(). */ - int32_t getLineNumber() const { return lineNumber; } - - /** Returns the line's next field, or NULL. */ - const char *nextField(); - - /** Returns the Unicode version when or after the UNICODE_VERSION_LINE has been read. */ - const UVersionInfo &getUnicodeVersion() const { return ucdVersion; } - - /** Returns TRUE if the current line has property values. */ - UBool lineHasPropertyValues() const { - return DEFAULTS_LINE<=lineType && lineType<=UNASSIGNED_LINE; - } - - /** - * Parses properties from the current line. - * Clears newValues and sets UProperty codes for property values mentioned - * on the current line (as opposed to being inherited). - * Returns a pointer to the filled-in UniProps, or NULL if something went wrong. - * The returned UniProps are usable until the next line of the same type is read. - */ - const UniProps *getProps(UnicodeSet &newValues, UErrorCode &errorCode); - - /** - * Returns the code point range for the current algnamesrange line. - * Calls & parses nextField(). - * Further nextField() calls will yield the range's type & prefix string. - * Returns U_SUCCESS(errorCode). - */ - UBool getRangeForAlgNames(UChar32 &start, UChar32 &end, UErrorCode &errorCode); - -private: - UBool isLineBufferAvailable(int32_t i) { - return defaultLineIndex!=i && blockLineIndex!=i; - } - - /** Resets the field iterator and returns the line's first field (the line type field). */ - const char *firstField(); - - UBool parseProperty(UniProps &props, const char *field, UnicodeSet &newValues, - UErrorCode &errorCode); - UChar32 parseCodePoint(const char *s, UErrorCode &errorCode); - UBool parseCodePointRange(const char *s, UChar32 &start, UChar32 &end, UErrorCode &errorCode); - void parseString(const char *s, UnicodeString &uni, UErrorCode &errorCode); - void parseScriptExtensions(const char *s, UnicodeSet &scx, UErrorCode &errorCode); - - static const int32_t kNumLineBuffers=3; - - PropertyNames *icuPnames; // owned - const PropertyNames *pnames; // aliased - FILE *file; - int32_t defaultLineIndex, blockLineIndex, lineIndex; - int32_t lineNumber; - LineType lineType; - char *fieldLimit; - char *lineLimit; - - UVersionInfo ucdVersion; - UniProps defaultProps, blockProps, cpProps; - UnicodeSet blockValues; - // Multiple lines so that default and block properties can maintain pointers - // into their line buffers. - char lines[kNumLineBuffers][4096]; -}; - -U_NAMESPACE_END - -#endif // __PPUCD_H__ diff --git a/deps/node/deps/icu-small/source/tools/toolutil/swapimpl.cpp b/deps/node/deps/icu-small/source/tools/toolutil/swapimpl.cpp deleted file mode 100644 index e8850cb9..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/swapimpl.cpp +++ /dev/null @@ -1,831 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2005-2014, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: swapimpl.cpp -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2005may05 -* created by: Markus W. Scherer -* -* Data file swapping functions moved here from the common library -* because some data is hardcoded in ICU4C and needs not be swapped any more. -* Moving the functions here simplifies testing (for code coverage) because -* we need not jump through hoops (like adding snapshots of these files -* to testdata). -* -* The declarations for these functions remain in the internal header files -* in icu/source/common/ -*/ - -#include "unicode/utypes.h" -#include "unicode/putil.h" -#include "unicode/udata.h" - -/* Explicit include statement for std_string.h is needed - * for compilation on certain platforms. (e.g. AIX/VACPP) - */ -#include "unicode/std_string.h" - -#include "cmemory.h" -#include "cstring.h" -#include "uinvchar.h" -#include "uassert.h" -#include "uarrsort.h" -#include "ucmndata.h" -#include "udataswp.h" - -/* swapping implementations in common */ - -#include "uresdata.h" -#include "ucnv_io.h" -#include "uprops.h" -#include "ucase.h" -#include "ubidi_props.h" -#include "ucol_swp.h" -#include "ucnv_bld.h" -#include "unormimp.h" -#include "normalizer2impl.h" -#include "sprpimpl.h" -#include "propname.h" -#include "rbbidata.h" -#include "utrie.h" -#include "utrie2.h" -#include "dictionarydata.h" - -/* swapping implementations in i18n */ - -#if !UCONFIG_NO_NORMALIZATION -#include "uspoof_impl.h" -#endif - -U_NAMESPACE_USE - -/* definitions */ - -/* Unicode property (value) aliases data swapping --------------------------- */ - -static int32_t U_CALLCONV -upname_swap(const UDataSwapper *ds, - const void *inData, int32_t length, void *outData, - UErrorCode *pErrorCode) { - /* udata_swapDataHeader checks the arguments */ - int32_t headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode); - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { - return 0; - } - - /* check data format and format version */ - const UDataInfo *pInfo= - reinterpret_cast<const UDataInfo *>( - static_cast<const char *>(inData)+4); - if(!( - pInfo->dataFormat[0]==0x70 && /* dataFormat="pnam" */ - pInfo->dataFormat[1]==0x6e && - pInfo->dataFormat[2]==0x61 && - pInfo->dataFormat[3]==0x6d && - pInfo->formatVersion[0]==2 - )) { - udata_printError(ds, "upname_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as pnames.icu\n", - pInfo->dataFormat[0], pInfo->dataFormat[1], - pInfo->dataFormat[2], pInfo->dataFormat[3], - pInfo->formatVersion[0]); - *pErrorCode=U_UNSUPPORTED_ERROR; - return 0; - } - - const uint8_t *inBytes=static_cast<const uint8_t *>(inData)+headerSize; - uint8_t *outBytes=static_cast<uint8_t *>(outData)+headerSize; - - if(length>=0) { - length-=headerSize; - // formatVersion 2 initially has indexes[8], 32 bytes. - if(length<32) { - udata_printError(ds, "upname_swap(): too few bytes (%d after header) for pnames.icu\n", - (int)length); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return 0; - } - } - - const int32_t *inIndexes=reinterpret_cast<const int32_t *>(inBytes); - int32_t totalSize=udata_readInt32(ds, inIndexes[PropNameData::IX_TOTAL_SIZE]); - if(length>=0) { - if(length<totalSize) { - udata_printError(ds, "upname_swap(): too few bytes (%d after header, should be %d) " - "for pnames.icu\n", - (int)length, (int)totalSize); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return 0; - } - - int32_t numBytesIndexesAndValueMaps= - udata_readInt32(ds, inIndexes[PropNameData::IX_BYTE_TRIES_OFFSET]); - - // Swap the indexes[] and the valueMaps[]. - ds->swapArray32(ds, inBytes, numBytesIndexesAndValueMaps, outBytes, pErrorCode); - - // Copy the rest of the data. - if(inBytes!=outBytes) { - uprv_memcpy(outBytes+numBytesIndexesAndValueMaps, - inBytes+numBytesIndexesAndValueMaps, - totalSize-numBytesIndexesAndValueMaps); - } - - // We need not swap anything else: - // - // The ByteTries are already byte-serialized, and are fixed on ASCII. - // (On an EBCDIC machine, the input string is converted to lowercase ASCII - // while matching.) - // - // The name groups are mostly invariant characters, but since we only - // generate, and keep in subversion, ASCII versions of pnames.icu, - // and since only ICU4J uses the pnames.icu data file - // (the data is hardcoded in ICU4C) and ICU4J uses ASCII data files, - // we just copy those bytes too. - } - - return headerSize+totalSize; -} - -/* Unicode properties data swapping ----------------------------------------- */ - -static int32_t U_CALLCONV -uprops_swap(const UDataSwapper *ds, - const void *inData, int32_t length, void *outData, - UErrorCode *pErrorCode) { - const UDataInfo *pInfo; - int32_t headerSize, i; - - int32_t dataIndexes[UPROPS_INDEX_COUNT]; - const int32_t *inData32; - - /* udata_swapDataHeader checks the arguments */ - headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode); - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { - return 0; - } - - /* check data format and format version */ - pInfo=(const UDataInfo *)((const char *)inData+4); - if(!( - pInfo->dataFormat[0]==0x55 && /* dataFormat="UPro" */ - pInfo->dataFormat[1]==0x50 && - pInfo->dataFormat[2]==0x72 && - pInfo->dataFormat[3]==0x6f && - (3<=pInfo->formatVersion[0] && pInfo->formatVersion[0]<=7) && - (pInfo->formatVersion[0]>=7 || - (pInfo->formatVersion[2]==UTRIE_SHIFT && - pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT)) - )) { - udata_printError(ds, "uprops_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not a Unicode properties file\n", - pInfo->dataFormat[0], pInfo->dataFormat[1], - pInfo->dataFormat[2], pInfo->dataFormat[3], - pInfo->formatVersion[0]); - *pErrorCode=U_UNSUPPORTED_ERROR; - return 0; - } - - /* the properties file must contain at least the indexes array */ - if(length>=0 && (length-headerSize)<(int32_t)sizeof(dataIndexes)) { - udata_printError(ds, "uprops_swap(): too few bytes (%d after header) for a Unicode properties file\n", - length-headerSize); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return 0; - } - - /* read the indexes */ - inData32=(const int32_t *)((const char *)inData+headerSize); - for(i=0; i<UPROPS_INDEX_COUNT; ++i) { - dataIndexes[i]=udata_readInt32(ds, inData32[i]); - } - - /* - * comments are copied from the data format description in genprops/store.c - * indexes[] constants are in uprops.h - */ - int32_t dataTop; - if(length>=0) { - int32_t *outData32; - - /* - * In formatVersion 7, UPROPS_DATA_TOP_INDEX has the post-header data size. - * In earlier formatVersions, it is 0 and a lower dataIndexes entry - * has the top of the last item. - */ - for(i=UPROPS_DATA_TOP_INDEX; i>0 && (dataTop=dataIndexes[i])==0; --i) {} - - if((length-headerSize)<(4*dataTop)) { - udata_printError(ds, "uprops_swap(): too few bytes (%d after header) for a Unicode properties file\n", - length-headerSize); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return 0; - } - - outData32=(int32_t *)((char *)outData+headerSize); - - /* copy everything for inaccessible data (padding) */ - if(inData32!=outData32) { - uprv_memcpy(outData32, inData32, 4*(size_t)dataTop); - } - - /* swap the indexes[16] */ - ds->swapArray32(ds, inData32, 4*UPROPS_INDEX_COUNT, outData32, pErrorCode); - - /* - * swap the main properties UTrie - * PT serialized properties trie, see utrie.h (byte size: 4*(i0-16)) - */ - utrie_swapAnyVersion(ds, - inData32+UPROPS_INDEX_COUNT, - 4*(dataIndexes[UPROPS_PROPS32_INDEX]-UPROPS_INDEX_COUNT), - outData32+UPROPS_INDEX_COUNT, - pErrorCode); - - /* - * swap the properties and exceptions words - * P const uint32_t props32[i1-i0]; - * E const uint32_t exceptions[i2-i1]; - */ - ds->swapArray32(ds, - inData32+dataIndexes[UPROPS_PROPS32_INDEX], - 4*(dataIndexes[UPROPS_EXCEPTIONS_TOP_INDEX]-dataIndexes[UPROPS_PROPS32_INDEX]), - outData32+dataIndexes[UPROPS_PROPS32_INDEX], - pErrorCode); - - /* - * swap the UChars - * U const UChar uchars[2*(i3-i2)]; - */ - ds->swapArray16(ds, - inData32+dataIndexes[UPROPS_EXCEPTIONS_TOP_INDEX], - 4*(dataIndexes[UPROPS_ADDITIONAL_TRIE_INDEX]-dataIndexes[UPROPS_EXCEPTIONS_TOP_INDEX]), - outData32+dataIndexes[UPROPS_EXCEPTIONS_TOP_INDEX], - pErrorCode); - - /* - * swap the additional UTrie - * i3 additionalTrieIndex; -- 32-bit unit index to the additional trie for more properties - */ - utrie_swapAnyVersion(ds, - inData32+dataIndexes[UPROPS_ADDITIONAL_TRIE_INDEX], - 4*(dataIndexes[UPROPS_ADDITIONAL_VECTORS_INDEX]-dataIndexes[UPROPS_ADDITIONAL_TRIE_INDEX]), - outData32+dataIndexes[UPROPS_ADDITIONAL_TRIE_INDEX], - pErrorCode); - - /* - * swap the properties vectors - * PV const uint32_t propsVectors[(i6-i4)/i5][i5]==uint32_t propsVectors[i6-i4]; - */ - ds->swapArray32(ds, - inData32+dataIndexes[UPROPS_ADDITIONAL_VECTORS_INDEX], - 4*(dataIndexes[UPROPS_SCRIPT_EXTENSIONS_INDEX]-dataIndexes[UPROPS_ADDITIONAL_VECTORS_INDEX]), - outData32+dataIndexes[UPROPS_ADDITIONAL_VECTORS_INDEX], - pErrorCode); - - // swap the Script_Extensions data - // SCX const uint16_t scriptExtensions[2*(i7-i6)]; - ds->swapArray16(ds, - inData32+dataIndexes[UPROPS_SCRIPT_EXTENSIONS_INDEX], - 4*(dataIndexes[UPROPS_RESERVED_INDEX_7]-dataIndexes[UPROPS_SCRIPT_EXTENSIONS_INDEX]), - outData32+dataIndexes[UPROPS_SCRIPT_EXTENSIONS_INDEX], - pErrorCode); - } - - /* i7 reservedIndex7; -- 32-bit unit index to the top of the Script_Extensions data */ - return headerSize+4*dataIndexes[UPROPS_RESERVED_INDEX_7]; -} - -/* Unicode case mapping data swapping --------------------------------------- */ - -static int32_t U_CALLCONV -ucase_swap(const UDataSwapper *ds, - const void *inData, int32_t length, void *outData, - UErrorCode *pErrorCode) { - const UDataInfo *pInfo; - int32_t headerSize; - - const uint8_t *inBytes; - uint8_t *outBytes; - - const int32_t *inIndexes; - int32_t indexes[16]; - - int32_t i, offset, count, size; - - /* udata_swapDataHeader checks the arguments */ - headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode); - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { - return 0; - } - - /* check data format and format version */ - pInfo=(const UDataInfo *)((const char *)inData+4); - if(!( - pInfo->dataFormat[0]==UCASE_FMT_0 && /* dataFormat="cAsE" */ - pInfo->dataFormat[1]==UCASE_FMT_1 && - pInfo->dataFormat[2]==UCASE_FMT_2 && - pInfo->dataFormat[3]==UCASE_FMT_3 && - ((pInfo->formatVersion[0]==1 && - pInfo->formatVersion[2]==UTRIE_SHIFT && - pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT) || - (2<=pInfo->formatVersion[0] && pInfo->formatVersion[0]<=4)) - )) { - udata_printError(ds, "ucase_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as case mapping data\n", - pInfo->dataFormat[0], pInfo->dataFormat[1], - pInfo->dataFormat[2], pInfo->dataFormat[3], - pInfo->formatVersion[0]); - *pErrorCode=U_UNSUPPORTED_ERROR; - return 0; - } - - inBytes=(const uint8_t *)inData+headerSize; - outBytes=(uint8_t *)outData+headerSize; - - inIndexes=(const int32_t *)inBytes; - - if(length>=0) { - length-=headerSize; - if(length<16*4) { - udata_printError(ds, "ucase_swap(): too few bytes (%d after header) for case mapping data\n", - length); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return 0; - } - } - - /* read the first 16 indexes (ICU 3.2/format version 1: UCASE_IX_TOP==16, might grow) */ - for(i=0; i<16; ++i) { - indexes[i]=udata_readInt32(ds, inIndexes[i]); - } - - /* get the total length of the data */ - size=indexes[UCASE_IX_LENGTH]; - - if(length>=0) { - if(length<size) { - udata_printError(ds, "ucase_swap(): too few bytes (%d after header) for all of case mapping data\n", - length); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return 0; - } - - /* copy the data for inaccessible bytes */ - if(inBytes!=outBytes) { - uprv_memcpy(outBytes, inBytes, size); - } - - offset=0; - - /* swap the int32_t indexes[] */ - count=indexes[UCASE_IX_INDEX_TOP]*4; - ds->swapArray32(ds, inBytes, count, outBytes, pErrorCode); - offset+=count; - - /* swap the UTrie */ - count=indexes[UCASE_IX_TRIE_SIZE]; - utrie_swapAnyVersion(ds, inBytes+offset, count, outBytes+offset, pErrorCode); - offset+=count; - - /* swap the uint16_t exceptions[] and unfold[] */ - count=(indexes[UCASE_IX_EXC_LENGTH]+indexes[UCASE_IX_UNFOLD_LENGTH])*2; - ds->swapArray16(ds, inBytes+offset, count, outBytes+offset, pErrorCode); - offset+=count; - - U_ASSERT(offset==size); - } - - return headerSize+size; -} - -/* Unicode bidi/shaping data swapping --------------------------------------- */ - -static int32_t U_CALLCONV -ubidi_swap(const UDataSwapper *ds, - const void *inData, int32_t length, void *outData, - UErrorCode *pErrorCode) { - const UDataInfo *pInfo; - int32_t headerSize; - - const uint8_t *inBytes; - uint8_t *outBytes; - - const int32_t *inIndexes; - int32_t indexes[16]; - - int32_t i, offset, count, size; - - /* udata_swapDataHeader checks the arguments */ - headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode); - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { - return 0; - } - - /* check data format and format version */ - pInfo=(const UDataInfo *)((const char *)inData+4); - if(!( - pInfo->dataFormat[0]==UBIDI_FMT_0 && /* dataFormat="BiDi" */ - pInfo->dataFormat[1]==UBIDI_FMT_1 && - pInfo->dataFormat[2]==UBIDI_FMT_2 && - pInfo->dataFormat[3]==UBIDI_FMT_3 && - ((pInfo->formatVersion[0]==1 && - pInfo->formatVersion[2]==UTRIE_SHIFT && - pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT) || - pInfo->formatVersion[0]==2) - )) { - udata_printError(ds, "ubidi_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as bidi/shaping data\n", - pInfo->dataFormat[0], pInfo->dataFormat[1], - pInfo->dataFormat[2], pInfo->dataFormat[3], - pInfo->formatVersion[0]); - *pErrorCode=U_UNSUPPORTED_ERROR; - return 0; - } - - inBytes=(const uint8_t *)inData+headerSize; - outBytes=(uint8_t *)outData+headerSize; - - inIndexes=(const int32_t *)inBytes; - - if(length>=0) { - length-=headerSize; - if(length<16*4) { - udata_printError(ds, "ubidi_swap(): too few bytes (%d after header) for bidi/shaping data\n", - length); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return 0; - } - } - - /* read the first 16 indexes (ICU 3.4/format version 1: UBIDI_IX_TOP==16, might grow) */ - for(i=0; i<16; ++i) { - indexes[i]=udata_readInt32(ds, inIndexes[i]); - } - - /* get the total length of the data */ - size=indexes[UBIDI_IX_LENGTH]; - - if(length>=0) { - if(length<size) { - udata_printError(ds, "ubidi_swap(): too few bytes (%d after header) for all of bidi/shaping data\n", - length); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return 0; - } - - /* copy the data for inaccessible bytes */ - if(inBytes!=outBytes) { - uprv_memcpy(outBytes, inBytes, size); - } - - offset=0; - - /* swap the int32_t indexes[] */ - count=indexes[UBIDI_IX_INDEX_TOP]*4; - ds->swapArray32(ds, inBytes, count, outBytes, pErrorCode); - offset+=count; - - /* swap the UTrie */ - count=indexes[UBIDI_IX_TRIE_SIZE]; - utrie_swapAnyVersion(ds, inBytes+offset, count, outBytes+offset, pErrorCode); - offset+=count; - - /* swap the uint32_t mirrors[] */ - count=indexes[UBIDI_IX_MIRROR_LENGTH]*4; - ds->swapArray32(ds, inBytes+offset, count, outBytes+offset, pErrorCode); - offset+=count; - - /* just skip the uint8_t jgArray[] and jgArray2[] */ - count=indexes[UBIDI_IX_JG_LIMIT]-indexes[UBIDI_IX_JG_START]; - offset+=count; - count=indexes[UBIDI_IX_JG_LIMIT2]-indexes[UBIDI_IX_JG_START2]; - offset+=count; - - U_ASSERT(offset==size); - } - - return headerSize+size; -} - -/* Unicode normalization data swapping -------------------------------------- */ - -#if !UCONFIG_NO_NORMALIZATION - -static int32_t U_CALLCONV -unorm_swap(const UDataSwapper *ds, - const void *inData, int32_t length, void *outData, - UErrorCode *pErrorCode) { - const UDataInfo *pInfo; - int32_t headerSize; - - const uint8_t *inBytes; - uint8_t *outBytes; - - const int32_t *inIndexes; - int32_t indexes[32]; - - int32_t i, offset, count, size; - - /* udata_swapDataHeader checks the arguments */ - headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode); - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { - return 0; - } - - /* check data format and format version */ - pInfo=(const UDataInfo *)((const char *)inData+4); - if(!( - pInfo->dataFormat[0]==0x4e && /* dataFormat="Norm" */ - pInfo->dataFormat[1]==0x6f && - pInfo->dataFormat[2]==0x72 && - pInfo->dataFormat[3]==0x6d && - pInfo->formatVersion[0]==2 - )) { - udata_printError(ds, "unorm_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as unorm.icu\n", - pInfo->dataFormat[0], pInfo->dataFormat[1], - pInfo->dataFormat[2], pInfo->dataFormat[3], - pInfo->formatVersion[0]); - *pErrorCode=U_UNSUPPORTED_ERROR; - return 0; - } - - inBytes=(const uint8_t *)inData+headerSize; - outBytes=(uint8_t *)outData+headerSize; - - inIndexes=(const int32_t *)inBytes; - - if(length>=0) { - length-=headerSize; - if(length<32*4) { - udata_printError(ds, "unorm_swap(): too few bytes (%d after header) for unorm.icu\n", - length); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return 0; - } - } - - /* read the first 32 indexes (ICU 2.8/format version 2.2: _NORM_INDEX_TOP==32, might grow) */ - for(i=0; i<32; ++i) { - indexes[i]=udata_readInt32(ds, inIndexes[i]); - } - - /* calculate the total length of the data */ - size= - 32*4+ /* size of indexes[] */ - indexes[_NORM_INDEX_TRIE_SIZE]+ - indexes[_NORM_INDEX_UCHAR_COUNT]*2+ - indexes[_NORM_INDEX_COMBINE_DATA_COUNT]*2+ - indexes[_NORM_INDEX_FCD_TRIE_SIZE]+ - indexes[_NORM_INDEX_AUX_TRIE_SIZE]+ - indexes[_NORM_INDEX_CANON_SET_COUNT]*2; - - if(length>=0) { - if(length<size) { - udata_printError(ds, "unorm_swap(): too few bytes (%d after header) for all of unorm.icu\n", - length); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return 0; - } - - /* copy the data for inaccessible bytes */ - if(inBytes!=outBytes) { - uprv_memcpy(outBytes, inBytes, size); - } - - offset=0; - - /* swap the indexes[] */ - count=32*4; - ds->swapArray32(ds, inBytes, count, outBytes, pErrorCode); - offset+=count; - - /* swap the main UTrie */ - count=indexes[_NORM_INDEX_TRIE_SIZE]; - utrie_swap(ds, inBytes+offset, count, outBytes+offset, pErrorCode); - offset+=count; - - /* swap the uint16_t extraData[] and the uint16_t combiningTable[] */ - count=(indexes[_NORM_INDEX_UCHAR_COUNT]+indexes[_NORM_INDEX_COMBINE_DATA_COUNT])*2; - ds->swapArray16(ds, inBytes+offset, count, outBytes+offset, pErrorCode); - offset+=count; - - /* swap the FCD UTrie */ - count=indexes[_NORM_INDEX_FCD_TRIE_SIZE]; - if(count!=0) { - utrie_swap(ds, inBytes+offset, count, outBytes+offset, pErrorCode); - offset+=count; - } - - /* swap the aux UTrie */ - count=indexes[_NORM_INDEX_AUX_TRIE_SIZE]; - if(count!=0) { - utrie_swap(ds, inBytes+offset, count, outBytes+offset, pErrorCode); - offset+=count; - } - - /* swap the uint16_t combiningTable[] */ - count=indexes[_NORM_INDEX_CANON_SET_COUNT]*2; - ds->swapArray16(ds, inBytes+offset, count, outBytes+offset, pErrorCode); - offset+=count; - } - - return headerSize+size; -} - -#endif - -/* Swap 'Test' data from gentest */ -static int32_t U_CALLCONV -test_swap(const UDataSwapper *ds, - const void *inData, int32_t length, void *outData, - UErrorCode *pErrorCode) { - const UDataInfo *pInfo; - int32_t headerSize; - - const uint8_t *inBytes; - uint8_t *outBytes; - - int32_t offset; - - /* udata_swapDataHeader checks the arguments */ - headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode); - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { - udata_printError(ds, "test_swap(): data header swap failed %s\n", pErrorCode != NULL ? u_errorName(*pErrorCode) : "pErrorCode is NULL"); - return 0; - } - - /* check data format and format version */ - pInfo=(const UDataInfo *)((const char *)inData+4); - if(!( - pInfo->dataFormat[0]==0x54 && /* dataFormat="Norm" */ - pInfo->dataFormat[1]==0x65 && - pInfo->dataFormat[2]==0x73 && - pInfo->dataFormat[3]==0x74 && - pInfo->formatVersion[0]==1 - )) { - udata_printError(ds, "test_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as testdata\n", - pInfo->dataFormat[0], pInfo->dataFormat[1], - pInfo->dataFormat[2], pInfo->dataFormat[3], - pInfo->formatVersion[0]); - *pErrorCode=U_UNSUPPORTED_ERROR; - return 0; - } - - inBytes=(const uint8_t *)inData+headerSize; - outBytes=(uint8_t *)outData+headerSize; - - int32_t size16 = 2; // 16bit plus padding - int32_t sizeStr = 5; // 4 char inv-str plus null - int32_t size = size16 + sizeStr; - - if(length>=0) { - if(length<size) { - udata_printError(ds, "test_swap(): too few bytes (%d after header, wanted %d) for all of testdata\n", - length, size); - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; - return 0; - } - - offset =0; - /* swap a 1 entry array */ - ds->swapArray16(ds, inBytes+offset, size16, outBytes+offset, pErrorCode); - offset+=size16; - ds->swapInvChars(ds, inBytes+offset, sizeStr, outBytes+offset, pErrorCode); - } - - return headerSize+size; -} - -/* swap any data (except a .dat package) ------------------------------------ */ - -static const struct { - uint8_t dataFormat[4]; - UDataSwapFn *swapFn; -} swapFns[]={ - { { 0x52, 0x65, 0x73, 0x42 }, ures_swap }, /* dataFormat="ResB" */ -#if !UCONFIG_NO_LEGACY_CONVERSION - { { 0x63, 0x6e, 0x76, 0x74 }, ucnv_swap }, /* dataFormat="cnvt" */ -#endif -#if !UCONFIG_NO_CONVERSION - { { 0x43, 0x76, 0x41, 0x6c }, ucnv_swapAliases }, /* dataFormat="CvAl" */ -#endif -#if !UCONFIG_NO_IDNA - { { 0x53, 0x50, 0x52, 0x50 }, usprep_swap }, /* dataFormat="SPRP" */ -#endif - /* insert data formats here, descending by expected frequency of occurrence */ - { { 0x55, 0x50, 0x72, 0x6f }, uprops_swap }, /* dataFormat="UPro" */ - - { { UCASE_FMT_0, UCASE_FMT_1, UCASE_FMT_2, UCASE_FMT_3 }, - ucase_swap }, /* dataFormat="cAsE" */ - - { { UBIDI_FMT_0, UBIDI_FMT_1, UBIDI_FMT_2, UBIDI_FMT_3 }, - ubidi_swap }, /* dataFormat="BiDi" */ - -#if !UCONFIG_NO_NORMALIZATION - { { 0x4e, 0x6f, 0x72, 0x6d }, unorm_swap }, /* dataFormat="Norm" */ - { { 0x4e, 0x72, 0x6d, 0x32 }, unorm2_swap }, /* dataFormat="Nrm2" */ -#endif -#if !UCONFIG_NO_COLLATION - { { 0x55, 0x43, 0x6f, 0x6c }, ucol_swap }, /* dataFormat="UCol" */ - { { 0x49, 0x6e, 0x76, 0x43 }, ucol_swapInverseUCA },/* dataFormat="InvC" */ -#endif -#if !UCONFIG_NO_BREAK_ITERATION - { { 0x42, 0x72, 0x6b, 0x20 }, ubrk_swap }, /* dataFormat="Brk " */ - { { 0x44, 0x69, 0x63, 0x74 }, udict_swap }, /* dataFormat="Dict" */ -#endif - { { 0x70, 0x6e, 0x61, 0x6d }, upname_swap }, /* dataFormat="pnam" */ - { { 0x75, 0x6e, 0x61, 0x6d }, uchar_swapNames }, /* dataFormat="unam" */ -#if !UCONFIG_NO_NORMALIZATION - { { 0x43, 0x66, 0x75, 0x20 }, uspoof_swap }, /* dataFormat="Cfu " */ -#endif - { { 0x54, 0x65, 0x73, 0x74 }, test_swap } /* dataFormat="Test" */ -}; - -U_CAPI int32_t U_EXPORT2 -udata_swap(const UDataSwapper *ds, - const void *inData, int32_t length, void *outData, - UErrorCode *pErrorCode) { - char dataFormatChars[4]; - const UDataInfo *pInfo; - int32_t i, swappedLength; - - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { - return 0; - } - - /* - * Preflight the header first; checks for illegal arguments, too. - * Do not swap the header right away because the format-specific swapper - * will swap it, get the headerSize again, and also use the header - * information. Otherwise we would have to pass some of the information - * and not be able to use the UDataSwapFn signature. - */ - udata_swapDataHeader(ds, inData, -1, NULL, pErrorCode); - - /* - * If we wanted udata_swap() to also handle non-loadable data like a UTrie, - * then we could check here for further known magic values and structures. - */ - if(U_FAILURE(*pErrorCode)) { - return 0; /* the data format was not recognized */ - } - - pInfo=(const UDataInfo *)((const char *)inData+4); - - { - /* convert the data format from ASCII to Unicode to the system charset */ - UChar u[4]={ - pInfo->dataFormat[0], pInfo->dataFormat[1], - pInfo->dataFormat[2], pInfo->dataFormat[3] - }; - - if(uprv_isInvariantUString(u, 4)) { - u_UCharsToChars(u, dataFormatChars, 4); - } else { - dataFormatChars[0]=dataFormatChars[1]=dataFormatChars[2]=dataFormatChars[3]='?'; - } - } - - /* dispatch to the swap function for the dataFormat */ - for(i=0; i<UPRV_LENGTHOF(swapFns); ++i) { - if(0==memcmp(swapFns[i].dataFormat, pInfo->dataFormat, 4)) { - swappedLength=swapFns[i].swapFn(ds, inData, length, outData, pErrorCode); - - if(U_FAILURE(*pErrorCode)) { - udata_printError(ds, "udata_swap(): failure swapping data format %02x.%02x.%02x.%02x (\"%c%c%c%c\") - %s\n", - pInfo->dataFormat[0], pInfo->dataFormat[1], - pInfo->dataFormat[2], pInfo->dataFormat[3], - dataFormatChars[0], dataFormatChars[1], - dataFormatChars[2], dataFormatChars[3], - u_errorName(*pErrorCode)); - } else if(swappedLength<(length-15)) { - /* swapped less than expected */ - udata_printError(ds, "udata_swap() warning: swapped only %d out of %d bytes - data format %02x.%02x.%02x.%02x (\"%c%c%c%c\")\n", - swappedLength, length, - pInfo->dataFormat[0], pInfo->dataFormat[1], - pInfo->dataFormat[2], pInfo->dataFormat[3], - dataFormatChars[0], dataFormatChars[1], - dataFormatChars[2], dataFormatChars[3], - u_errorName(*pErrorCode)); - } - - return swappedLength; - } - } - - /* the dataFormat was not recognized */ - udata_printError(ds, "udata_swap(): unknown data format %02x.%02x.%02x.%02x (\"%c%c%c%c\")\n", - pInfo->dataFormat[0], pInfo->dataFormat[1], - pInfo->dataFormat[2], pInfo->dataFormat[3], - dataFormatChars[0], dataFormatChars[1], - dataFormatChars[2], dataFormatChars[3]); - - *pErrorCode=U_UNSUPPORTED_ERROR; - return 0; -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/swapimpl.h b/deps/node/deps/icu-small/source/tools/toolutil/swapimpl.h deleted file mode 100644 index 8c6474f6..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/swapimpl.h +++ /dev/null @@ -1,45 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2005, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: swapimpl.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2005jul29 -* created by: Markus W. Scherer -* -* Declarations for data file swapping functions not declared in internal -* library headers. -*/ - -#ifndef __SWAPIMPL_H__ -#define __SWAPIMPL_H__ - -#include "unicode/utypes.h" -#include "udataswp.h" - -/** - * Identifies and then transforms the ICU data piece in-place, or determines - * its length. See UDataSwapFn. - * This function handles single data pieces (but not .dat data packages) - * and internally dispatches to per-type swap functions. - * Sets a U_UNSUPPORTED_ERROR if the data format is not recognized. - * - * @see UDataSwapFn - * @see udata_openSwapper - * @see udata_openSwapperForInputData - * @internal ICU 2.8 - */ -U_CAPI int32_t U_EXPORT2 -udata_swap(const UDataSwapper *ds, - const void *inData, int32_t length, void *outData, - UErrorCode *pErrorCode); - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/toolutil.cpp b/deps/node/deps/icu-small/source/tools/toolutil/toolutil.cpp deleted file mode 100644 index 0f7d0984..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/toolutil.cpp +++ /dev/null @@ -1,357 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1999-2014, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: toolutil.c -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 1999nov19 -* created by: Markus W. Scherer -* -* 6/25/08 - Added Cygwin specific code in uprv_mkdir - Brian Rower -* -* This file contains utility functions for ICU tools like genccode. -*/ - -#include "unicode/platform.h" -#if U_PLATFORM == U_PF_MINGW -// *cough* - for struct stat -#ifdef __STRICT_ANSI__ -#undef __STRICT_ANSI__ -#endif -#endif - -#include <stdio.h> -#include <sys/stat.h> -#include "unicode/utypes.h" - -#ifndef U_TOOLUTIL_IMPLEMENTATION -#error U_TOOLUTIL_IMPLEMENTATION not set - must be set for all ICU source files in common/ - see http://userguide.icu-project.org/howtouseicu -#endif - -#if U_PLATFORM_USES_ONLY_WIN32_API -# define VC_EXTRALEAN -# define WIN32_LEAN_AND_MEAN -# define NOUSER -# define NOSERVICE -# define NOIME -# define NOMCX -# if U_PLATFORM == U_PF_MINGW -# define __NO_MINGW_LFS /* gets around missing 'off64_t' */ -# endif -# include <windows.h> -# include <direct.h> -#else -# include <sys/stat.h> -# include <sys/types.h> -#endif - -/* In MinGW environment, io.h needs to be included for _mkdir() */ -#if U_PLATFORM == U_PF_MINGW -#include <io.h> -#endif - -#include <errno.h> - -#include "unicode/errorcode.h" -#include "unicode/putil.h" -#include "cmemory.h" -#include "cstring.h" -#include "toolutil.h" -#include "unicode/ucal.h" - -U_NAMESPACE_BEGIN - -IcuToolErrorCode::~IcuToolErrorCode() { - // Safe because our handleFailure() does not throw exceptions. - if(isFailure()) { handleFailure(); } -} - -void IcuToolErrorCode::handleFailure() const { - fprintf(stderr, "error at %s: %s\n", location, errorName()); - exit(errorCode); -} - -U_NAMESPACE_END - -static int32_t currentYear = -1; - -U_CAPI int32_t U_EXPORT2 getCurrentYear() { -#if !UCONFIG_NO_FORMATTING - UErrorCode status=U_ZERO_ERROR; - UCalendar *cal = NULL; - - if(currentYear == -1) { - cal = ucal_open(NULL, -1, NULL, UCAL_TRADITIONAL, &status); - ucal_setMillis(cal, ucal_getNow(), &status); - currentYear = ucal_get(cal, UCAL_YEAR, &status); - ucal_close(cal); - } -#else - /* No formatting- no way to set the current year. */ -#endif - return currentYear; -} - - -U_CAPI const char * U_EXPORT2 -getLongPathname(const char *pathname) { -#if U_PLATFORM_USES_ONLY_WIN32_API - /* anticipate problems with "short" pathnames */ - static WIN32_FIND_DATAA info; - HANDLE file=FindFirstFileA(pathname, &info); - if(file!=INVALID_HANDLE_VALUE) { - if(info.cAlternateFileName[0]!=0) { - /* this file has a short name, get and use the long one */ - const char *basename=findBasename(pathname); - if(basename!=pathname) { - /* prepend the long filename with the original path */ - uprv_memmove(info.cFileName+(basename-pathname), info.cFileName, uprv_strlen(info.cFileName)+1); - uprv_memcpy(info.cFileName, pathname, basename-pathname); - } - pathname=info.cFileName; - } - FindClose(file); - } -#endif - return pathname; -} - -U_CAPI const char * U_EXPORT2 -findDirname(const char *path, char *buffer, int32_t bufLen, UErrorCode* status) { - if(U_FAILURE(*status)) return NULL; - const char *resultPtr = NULL; - int32_t resultLen = 0; - - const char *basename=uprv_strrchr(path, U_FILE_SEP_CHAR); -#if U_FILE_ALT_SEP_CHAR!=U_FILE_SEP_CHAR - const char *basenameAlt=uprv_strrchr(path, U_FILE_ALT_SEP_CHAR); - if(basenameAlt && (!basename || basename<basenameAlt)) { - basename = basenameAlt; - } -#endif - if(!basename) { - /* no basename - return ''. */ - resultPtr = ""; - resultLen = 0; - } else { - resultPtr = path; - resultLen = basename - path; - if(resultLen<1) { - resultLen = 1; /* '/' or '/a' -> '/' */ - } - } - - if((resultLen+1) <= bufLen) { - uprv_strncpy(buffer, resultPtr, resultLen); - buffer[resultLen]=0; - return buffer; - } else { - *status = U_BUFFER_OVERFLOW_ERROR; - return NULL; - } -} - -U_CAPI const char * U_EXPORT2 -findBasename(const char *filename) { - const char *basename=uprv_strrchr(filename, U_FILE_SEP_CHAR); - -#if U_FILE_ALT_SEP_CHAR!=U_FILE_SEP_CHAR -#if !(U_PLATFORM == U_PF_CYGWIN && U_PLATFORM_USES_ONLY_WIN32_API) - if(basename==NULL) -#endif - { - /* Use lenient matching on Windows, which can accept either \ or / - This is useful for environments like Win32+CygWin which have both. - */ - basename=uprv_strrchr(filename, U_FILE_ALT_SEP_CHAR); - } -#endif - - if(basename!=NULL) { - return basename+1; - } else { - return filename; - } -} - -U_CAPI void U_EXPORT2 -uprv_mkdir(const char *pathname, UErrorCode *status) { - - int retVal = 0; -#if U_PLATFORM_USES_ONLY_WIN32_API - retVal = _mkdir(pathname); -#else - retVal = mkdir(pathname, S_IRWXU | (S_IROTH | S_IXOTH) | (S_IROTH | S_IXOTH)); -#endif - if (retVal && errno != EEXIST) { -#if U_PF_MINGW <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN - /*if using Cygwin and the mkdir says it failed...check if the directory already exists..*/ - /* if it does...don't give the error, if it does not...give the error - Brian Rower - 6/25/08 */ - struct stat st; - - if(stat(pathname,&st) != 0) - { - *status = U_FILE_ACCESS_ERROR; - } -#else - *status = U_FILE_ACCESS_ERROR; -#endif - } -} - -#if !UCONFIG_NO_FILE_IO -U_CAPI UBool U_EXPORT2 -uprv_fileExists(const char *file) { - struct stat stat_buf; - if (stat(file, &stat_buf) == 0) { - return TRUE; - } else { - return FALSE; - } -} -#endif - -/*U_CAPI UDate U_EXPORT2 -uprv_getModificationDate(const char *pathname, UErrorCode *status) -{ - if(U_FAILURE(*status)) { - return; - } - // TODO: handle case where stat is not available - struct stat st; - - if(stat(pathname,&st) != 0) - { - *status = U_FILE_ACCESS_ERROR; - } else { - return st.st_mtime; - } -} -*/ - -/* tool memory helper ------------------------------------------------------- */ - -struct UToolMemory { - char name[64]; - int32_t capacity, maxCapacity, size, idx; - void *array; - UAlignedMemory staticArray[1]; -}; - -U_CAPI UToolMemory * U_EXPORT2 -utm_open(const char *name, int32_t initialCapacity, int32_t maxCapacity, int32_t size) { - UToolMemory *mem; - - if(maxCapacity<initialCapacity) { - maxCapacity=initialCapacity; - } - - mem=(UToolMemory *)uprv_malloc(sizeof(UToolMemory)+initialCapacity*size); - if(mem==NULL) { - fprintf(stderr, "error: %s - out of memory\n", name); - exit(U_MEMORY_ALLOCATION_ERROR); - } - mem->array=mem->staticArray; - - uprv_strcpy(mem->name, name); - mem->capacity=initialCapacity; - mem->maxCapacity=maxCapacity; - mem->size=size; - mem->idx=0; - return mem; -} - -U_CAPI void U_EXPORT2 -utm_close(UToolMemory *mem) { - if(mem!=NULL) { - if(mem->array!=mem->staticArray) { - uprv_free(mem->array); - } - uprv_free(mem); - } -} - - -U_CAPI void * U_EXPORT2 -utm_getStart(UToolMemory *mem) { - return (char *)mem->array; -} - -U_CAPI int32_t U_EXPORT2 -utm_countItems(UToolMemory *mem) { - return mem->idx; -} - - -static UBool -utm_hasCapacity(UToolMemory *mem, int32_t capacity) { - if(mem->capacity<capacity) { - int32_t newCapacity; - - if(mem->maxCapacity<capacity) { - fprintf(stderr, "error: %s - trying to use more than maxCapacity=%ld units\n", - mem->name, (long)mem->maxCapacity); - exit(U_MEMORY_ALLOCATION_ERROR); - } - - /* try to allocate a larger array */ - if(capacity>=2*mem->capacity) { - newCapacity=capacity; - } else if(mem->capacity<=mem->maxCapacity/3) { - newCapacity=2*mem->capacity; - } else { - newCapacity=mem->maxCapacity; - } - - if(mem->array==mem->staticArray) { - mem->array=uprv_malloc(newCapacity*mem->size); - if(mem->array!=NULL) { - uprv_memcpy(mem->array, mem->staticArray, (size_t)mem->idx*mem->size); - } - } else { - mem->array=uprv_realloc(mem->array, newCapacity*mem->size); - } - - if(mem->array==NULL) { - fprintf(stderr, "error: %s - out of memory\n", mem->name); - exit(U_MEMORY_ALLOCATION_ERROR); - } - mem->capacity=newCapacity; - } - - return TRUE; -} - -U_CAPI void * U_EXPORT2 -utm_alloc(UToolMemory *mem) { - char *p=NULL; - int32_t oldIndex=mem->idx; - int32_t newIndex=oldIndex+1; - if(utm_hasCapacity(mem, newIndex)) { - p=(char *)mem->array+oldIndex*mem->size; - mem->idx=newIndex; - uprv_memset(p, 0, mem->size); - } - return p; -} - -U_CAPI void * U_EXPORT2 -utm_allocN(UToolMemory *mem, int32_t n) { - char *p=NULL; - int32_t oldIndex=mem->idx; - int32_t newIndex=oldIndex+n; - if(utm_hasCapacity(mem, newIndex)) { - p=(char *)mem->array+oldIndex*mem->size; - mem->idx=newIndex; - uprv_memset(p, 0, n*mem->size); - } - return p; -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/toolutil.h b/deps/node/deps/icu-small/source/tools/toolutil/toolutil.h deleted file mode 100644 index be07787a..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/toolutil.h +++ /dev/null @@ -1,187 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1999-2013, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: toolutil.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 1999nov19 -* created by: Markus W. Scherer -* -* This file defines utility functions for ICU tools like genccode. -*/ - -#ifndef __TOOLUTIL_H__ -#define __TOOLUTIL_H__ - -#include "unicode/utypes.h" - - -#ifdef __cplusplus - -#include "unicode/errorcode.h" - -U_NAMESPACE_BEGIN - -/** - * ErrorCode subclass for use in ICU command-line tools. - * The destructor calls handleFailure() which calls exit(errorCode) when isFailure(). - */ -class U_TOOLUTIL_API IcuToolErrorCode : public ErrorCode { -public: - /** - * @param loc A short string describing where the IcuToolErrorCode is used. - */ - IcuToolErrorCode(const char *loc) : location(loc) {} - virtual ~IcuToolErrorCode(); -protected: - virtual void handleFailure() const; -private: - const char *location; -}; - -U_NAMESPACE_END - -#endif - -/* - * For Windows, a path/filename may be the short (8.3) version - * of the "real", long one. In this case, the short one - * is abbreviated and contains a tilde etc. - * This function returns a pointer to the original pathname - * if it is the "real" one itself, and a pointer to a static - * buffer (not thread-safe) containing the long version - * if the pathname is indeed abbreviated. - * - * On platforms other than Windows, this function always returns - * the input pathname pointer. - * - * This function is especially useful in tools that are called - * by a batch file for loop, which yields short pathnames on Win9x. - */ -U_CAPI const char * U_EXPORT2 -getLongPathname(const char *pathname); - -/** - * Find the basename at the end of a pathname, i.e., the part - * after the last file separator, and return a pointer - * to this part of the pathname. - * If the pathname only contains a basename and no file separator, - * then the pathname pointer itself is returned. - **/ -U_CAPI const char * U_EXPORT2 -findBasename(const char *filename); - -/** - * Find the directory name of a pathname, that is, everything - * up to but not including the last file separator. - * - * If successful, copies the directory name into the output buffer along with - * a terminating NULL. - * - * If there isn't a directory name in the path, it returns an empty string. - * @param path the full pathname to inspect. - * @param buffer the output buffer - * @param bufLen the output buffer length - * @param status error code- may return U_BUFFER_OVERFLOW_ERROR if bufLen is too small. - * @return If successful, a pointer to the output buffer. If failure or bufLen is too small, NULL. - **/ -U_CAPI const char * U_EXPORT2 -findDirname(const char *path, char *buffer, int32_t bufLen, UErrorCode* status); - -/* - * Return the current year in the Gregorian calendar. Used for copyright generation. - */ -U_CAPI int32_t U_EXPORT2 -getCurrentYear(void); - -/* - * Creates a directory with pathname. - * - * @param status Set to an error code when mkdir failed. - */ -U_CAPI void U_EXPORT2 -uprv_mkdir(const char *pathname, UErrorCode *status); - -#if !UCONFIG_NO_FILE_IO -/** - * Return TRUE if the named item exists - * @param file filename - * @return TRUE if named item (file, dir, etc) exists, FALSE otherwise - */ -U_CAPI UBool U_EXPORT2 -uprv_fileExists(const char *file); -#endif - -/** - * Return the modification date for the specified file or directory. - * Return value is undefined if there was an error. - */ -/*U_CAPI UDate U_EXPORT2 -uprv_getModificationDate(const char *pathname, UErrorCode *status); -*/ -/* - * Returns the modification - * - * @param status Set to an error code when mkdir failed. - */ - -/* - * UToolMemory is used for generic, custom memory management. - * It is allocated with enough space for count*size bytes starting - * at array. - * The array is declared with a union of large data types so - * that its base address is aligned for any types. - * If size is a multiple of a data type size, then such items - * can be safely allocated inside the array, at offsets that - * are themselves multiples of size. - */ -struct UToolMemory; -typedef struct UToolMemory UToolMemory; - -/** - * Open a UToolMemory object for allocation of initialCapacity to maxCapacity - * items with size bytes each. - */ -U_CAPI UToolMemory * U_EXPORT2 -utm_open(const char *name, int32_t initialCapacity, int32_t maxCapacity, int32_t size); - -/** - * Close a UToolMemory object. - */ -U_CAPI void U_EXPORT2 -utm_close(UToolMemory *mem); - -/** - * Get the pointer to the beginning of the array of items. - * The pointer becomes invalid after allocation of new items. - */ -U_CAPI void * U_EXPORT2 -utm_getStart(UToolMemory *mem); - -/** - * Get the current number of items. - */ -U_CAPI int32_t U_EXPORT2 -utm_countItems(UToolMemory *mem); - -/** - * Allocate one more item and return the pointer to its start in the array. - */ -U_CAPI void * U_EXPORT2 -utm_alloc(UToolMemory *mem); - -/** - * Allocate n items and return the pointer to the start of the first one in the array. - */ -U_CAPI void * U_EXPORT2 -utm_allocN(UToolMemory *mem, int32_t n); - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/ucbuf.cpp b/deps/node/deps/icu-small/source/tools/toolutil/ucbuf.cpp deleted file mode 100644 index 5269c817..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/ucbuf.cpp +++ /dev/null @@ -1,788 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2016, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File ucbuf.cpp -* -* Modification History: -* -* Date Name Description -* 05/10/01 Ram Creation. -******************************************************************************* -*/ - -#include "unicode/utypes.h" -#include "unicode/putil.h" -#include "unicode/uchar.h" -#include "unicode/ucnv.h" -#include "unicode/ucnv_err.h" -#include "unicode/ustring.h" -#include "unicode/utf16.h" -#include "filestrm.h" -#include "cstring.h" -#include "cmemory.h" -#include "ustrfmt.h" -#include "ucbuf.h" -#include <stdio.h> - -#if !UCONFIG_NO_CONVERSION - - -#define MAX_IN_BUF 1000 -#define MAX_U_BUF 1500 -#define CONTEXT_LEN 20 - -struct UCHARBUF { - UChar* buffer; - UChar* currentPos; - UChar* bufLimit; - int32_t bufCapacity; - int32_t remaining; - int32_t signatureLength; - FileStream* in; - UConverter* conv; - UBool showWarning; /* makes this API not produce any errors */ - UBool isBuffered; -}; - -U_CAPI UBool U_EXPORT2 -ucbuf_autodetect_fs(FileStream* in, const char** cp, UConverter** conv, int32_t* signatureLength, UErrorCode* error){ - char start[8]; - int32_t numRead; - - UChar target[1]={ 0 }; - UChar* pTarget; - const char* pStart; - - /* read a few bytes */ - numRead=T_FileStream_read(in, start, sizeof(start)); - - *cp = ucnv_detectUnicodeSignature(start, numRead, signatureLength, error); - - /* unread the bytes beyond what was consumed for U+FEFF */ - T_FileStream_rewind(in); - if (*signatureLength > 0) { - T_FileStream_read(in, start, *signatureLength); - } - - if(*cp==NULL){ - *conv =NULL; - return FALSE; - } - - /* open the converter for the detected Unicode charset */ - *conv = ucnv_open(*cp,error); - - /* convert and ignore initial U+FEFF, and the buffer overflow */ - pTarget = target; - pStart = start; - ucnv_toUnicode(*conv, &pTarget, target+1, &pStart, start+*signatureLength, NULL, FALSE, error); - *signatureLength = (int32_t)(pStart - start); - if(*error==U_BUFFER_OVERFLOW_ERROR) { - *error=U_ZERO_ERROR; - } - - /* verify that we successfully read exactly U+FEFF */ - if(U_SUCCESS(*error) && (pTarget!=(target+1) || target[0]!=0xfeff)) { - *error=U_INTERNAL_PROGRAM_ERROR; - } - - - return TRUE; -} -static UBool ucbuf_isCPKnown(const char* cp){ - if(ucnv_compareNames("UTF-8",cp)==0){ - return TRUE; - } - if(ucnv_compareNames("UTF-16BE",cp)==0){ - return TRUE; - } - if(ucnv_compareNames("UTF-16LE",cp)==0){ - return TRUE; - } - if(ucnv_compareNames("UTF-16",cp)==0){ - return TRUE; - } - if(ucnv_compareNames("UTF-32",cp)==0){ - return TRUE; - } - if(ucnv_compareNames("UTF-32BE",cp)==0){ - return TRUE; - } - if(ucnv_compareNames("UTF-32LE",cp)==0){ - return TRUE; - } - if(ucnv_compareNames("SCSU",cp)==0){ - return TRUE; - } - if(ucnv_compareNames("BOCU-1",cp)==0){ - return TRUE; - } - if(ucnv_compareNames("UTF-7",cp)==0){ - return TRUE; - } - return FALSE; -} - -U_CAPI FileStream * U_EXPORT2 -ucbuf_autodetect(const char* fileName, const char** cp,UConverter** conv, int32_t* signatureLength,UErrorCode* error){ - FileStream* in=NULL; - if(error==NULL || U_FAILURE(*error)){ - return NULL; - } - if(conv==NULL || cp==NULL || fileName==NULL){ - *error = U_ILLEGAL_ARGUMENT_ERROR; - return NULL; - } - /* open the file */ - in= T_FileStream_open(fileName,"rb"); - - if(in == NULL){ - *error=U_FILE_ACCESS_ERROR; - return NULL; - } - - if(ucbuf_autodetect_fs(in,cp,conv,signatureLength,error)) { - return in; - } else { - ucnv_close(*conv); - *conv=NULL; - T_FileStream_close(in); - return NULL; - } -} - -/* fill the uchar buffer */ -static UCHARBUF* -ucbuf_fillucbuf( UCHARBUF* buf,UErrorCode* error){ - UChar* pTarget=NULL; - UChar* target=NULL; - const char* source=NULL; - char carr[MAX_IN_BUF] = {'\0'}; - char* cbuf = carr; - int32_t inputRead=0; - int32_t outputWritten=0; - int32_t offset=0; - const char* sourceLimit =NULL; - int32_t cbufSize=0; - pTarget = buf->buffer; - /* check if we arrived here without exhausting the buffer*/ - if(buf->currentPos<buf->bufLimit){ - offset = (int32_t)(buf->bufLimit-buf->currentPos); - memmove(buf->buffer,buf->currentPos,offset* sizeof(UChar)); - } - -#if UCBUF_DEBUG - memset(pTarget+offset,0xff,sizeof(UChar)*(MAX_IN_BUF-offset)); -#endif - if(buf->isBuffered){ - cbufSize = MAX_IN_BUF; - /* read the file */ - inputRead=T_FileStream_read(buf->in,cbuf,cbufSize-offset); - buf->remaining-=inputRead; - - }else{ - cbufSize = T_FileStream_size(buf->in); - cbuf = (char*)uprv_malloc(cbufSize); - if (cbuf == NULL) { - *error = U_MEMORY_ALLOCATION_ERROR; - return NULL; - } - inputRead= T_FileStream_read(buf->in,cbuf,cbufSize); - buf->remaining-=inputRead; - } - - /* just to be sure...*/ - if ( 0 == inputRead ) - buf->remaining = 0; - - target=pTarget; - /* convert the bytes */ - if(buf->conv){ - /* set the callback to stop */ - UConverterToUCallback toUOldAction ; - void* toUOldContext; - void* toUNewContext=NULL; - ucnv_setToUCallBack(buf->conv, - UCNV_TO_U_CALLBACK_STOP, - toUNewContext, - &toUOldAction, - (const void**)&toUOldContext, - error); - /* since state is saved in the converter we add offset to source*/ - target = pTarget+offset; - source = cbuf; - sourceLimit = source + inputRead; - ucnv_toUnicode(buf->conv,&target,target+(buf->bufCapacity-offset), - &source,sourceLimit,NULL, - (UBool)(buf->remaining==0),error); - - if(U_FAILURE(*error)){ - char context[CONTEXT_LEN+1]; - char preContext[CONTEXT_LEN+1]; - char postContext[CONTEXT_LEN+1]; - int8_t len = CONTEXT_LEN; - int32_t start=0; - int32_t stop =0; - int32_t pos =0; - /* use erro1 to preserve the error code */ - UErrorCode error1 =U_ZERO_ERROR; - - if( buf->showWarning==TRUE){ - fprintf(stderr,"\n###WARNING: Encountered abnormal bytes while" - " converting input stream to target encoding: %s\n", - u_errorName(*error)); - } - - - /* now get the context chars */ - ucnv_getInvalidChars(buf->conv,context,&len,&error1); - context[len]= 0 ; /* null terminate the buffer */ - - pos = (int32_t)(source - cbuf - len); - - /* for pre-context */ - start = (pos <=CONTEXT_LEN)? 0 : (pos - (CONTEXT_LEN-1)); - stop = pos-len; - - memcpy(preContext,cbuf+start,stop-start); - /* null terminate the buffer */ - preContext[stop-start] = 0; - - /* for post-context */ - start = pos+len; - stop = (int32_t)(((pos+CONTEXT_LEN)<= (sourceLimit-cbuf) )? (pos+(CONTEXT_LEN-1)) : (sourceLimit-cbuf)); - - memcpy(postContext,source,stop-start); - /* null terminate the buffer */ - postContext[stop-start] = 0; - - if(buf->showWarning ==TRUE){ - /* print out the context */ - fprintf(stderr,"\tPre-context: %s\n",preContext); - fprintf(stderr,"\tContext: %s\n",context); - fprintf(stderr,"\tPost-context: %s\n", postContext); - } - - /* reset the converter */ - ucnv_reset(buf->conv); - - /* set the call back to substitute - * and restart conversion - */ - ucnv_setToUCallBack(buf->conv, - UCNV_TO_U_CALLBACK_SUBSTITUTE, - toUNewContext, - &toUOldAction, - (const void**)&toUOldContext, - &error1); - - /* reset source and target start positions */ - target = pTarget+offset; - source = cbuf; - - /* re convert */ - ucnv_toUnicode(buf->conv,&target,target+(buf->bufCapacity-offset), - &source,sourceLimit,NULL, - (UBool)(buf->remaining==0),&error1); - - } - outputWritten = (int32_t)(target - pTarget); - -#if UCBUF_DEBUG - { - int i; - target = pTarget; - for(i=0;i<numRead;i++){ - /* printf("%c", (char)(*target++));*/ - } - } -#endif - - }else{ - u_charsToUChars(cbuf,target+offset,inputRead); - outputWritten=((buf->remaining>cbufSize)? cbufSize:inputRead+offset); - } - buf->currentPos = pTarget; - buf->bufLimit=pTarget+outputWritten; - *buf->bufLimit=0; /*NUL terminate*/ - if(cbuf!=carr){ - uprv_free(cbuf); - } - return buf; -} - - - -/* get a UChar from the stream*/ -U_CAPI int32_t U_EXPORT2 -ucbuf_getc(UCHARBUF* buf,UErrorCode* error){ - if(error==NULL || U_FAILURE(*error)){ - return FALSE; - } - if(buf->currentPos>=buf->bufLimit){ - if(buf->remaining==0){ - return U_EOF; - } - buf=ucbuf_fillucbuf(buf,error); - if(U_FAILURE(*error)){ - return U_EOF; - } - } - - return *(buf->currentPos++); -} - -/* get a UChar32 from the stream*/ -U_CAPI int32_t U_EXPORT2 -ucbuf_getc32(UCHARBUF* buf,UErrorCode* error){ - int32_t retVal = (int32_t)U_EOF; - if(error==NULL || U_FAILURE(*error)){ - return FALSE; - } - if(buf->currentPos+1>=buf->bufLimit){ - if(buf->remaining==0){ - return U_EOF; - } - buf=ucbuf_fillucbuf(buf,error); - if(U_FAILURE(*error)){ - return U_EOF; - } - } - if(U16_IS_LEAD(*(buf->currentPos))){ - retVal=U16_GET_SUPPLEMENTARY(buf->currentPos[0],buf->currentPos[1]); - buf->currentPos+=2; - }else{ - retVal = *(buf->currentPos++); - } - return retVal; -} - -/* u_unescapeAt() callback to return a UChar*/ -static UChar U_CALLCONV -_charAt(int32_t offset, void *context) { - return ((UCHARBUF*) context)->currentPos[offset]; -} - -/* getc and escape it */ -U_CAPI int32_t U_EXPORT2 -ucbuf_getcx32(UCHARBUF* buf,UErrorCode* error) { - int32_t length; - int32_t offset; - UChar32 c32,c1,c2; - if(error==NULL || U_FAILURE(*error)){ - return FALSE; - } - /* Fill the buffer if it is empty */ - if (buf->currentPos >=buf->bufLimit-2) { - ucbuf_fillucbuf(buf,error); - } - - /* Get the next character in the buffer */ - if (buf->currentPos < buf->bufLimit) { - c1 = *(buf->currentPos)++; - } else { - c1 = U_EOF; - } - - c2 = *(buf->currentPos); - - /* If it isn't a backslash, return it */ - if (c1 != 0x005C) { - return c1; - } - - /* Determine the amount of data in the buffer */ - length = (int32_t)(buf->bufLimit - buf->currentPos); - - /* The longest escape sequence is \Uhhhhhhhh; make sure - we have at least that many characters */ - if (length < 10) { - - /* fill the buffer */ - ucbuf_fillucbuf(buf,error); - length = (int32_t)(buf->bufLimit - buf->buffer); - } - - /* Process the escape */ - offset = 0; - c32 = u_unescapeAt(_charAt, &offset, length, (void*)buf); - - /* check if u_unescapeAt unescaped and converted - * to c32 or not - */ - if(c32==(UChar32)0xFFFFFFFF){ - if(buf->showWarning) { - char context[CONTEXT_LEN+1]; - int32_t len = CONTEXT_LEN; - if(length < len) { - len = length; - } - context[len]= 0 ; /* null terminate the buffer */ - u_UCharsToChars( buf->currentPos, context, len); - fprintf(stderr,"Bad escape: [%c%s]...\n", (int)c1, context); - } - *error= U_ILLEGAL_ESCAPE_SEQUENCE; - return c1; - }else if(c32!=c2 || (c32==0x0075 && c2==0x0075 && c1==0x005C) /* for \u0075 c2=0x0075 and c32==0x0075*/){ - /* Update the current buffer position */ - buf->currentPos += offset; - }else{ - /* unescaping failed so we just return - * c1 and not consume the buffer - * this is useful for rules with escapes - * in resouce bundles - * eg: \' \\ \" - */ - return c1; - } - - return c32; -} - -U_CAPI UCHARBUF* U_EXPORT2 -ucbuf_open(const char* fileName,const char** cp,UBool showWarning, UBool buffered, UErrorCode* error){ - - FileStream* in = NULL; - int32_t fileSize=0; - const char* knownCp; - if(error==NULL || U_FAILURE(*error)){ - return NULL; - } - if(cp==NULL || fileName==NULL){ - *error = U_ILLEGAL_ARGUMENT_ERROR; - return FALSE; - } - if (!uprv_strcmp(fileName, "-")) { - in = T_FileStream_stdin(); - }else{ - in = T_FileStream_open(fileName, "rb"); - } - - if(in!=NULL){ - UCHARBUF* buf =(UCHARBUF*) uprv_malloc(sizeof(UCHARBUF)); - fileSize = T_FileStream_size(in); - if(buf == NULL){ - *error = U_MEMORY_ALLOCATION_ERROR; - T_FileStream_close(in); - return NULL; - } - buf->in=in; - buf->conv=NULL; - buf->showWarning = showWarning; - buf->isBuffered = buffered; - buf->signatureLength=0; - if(*cp==NULL || **cp=='\0'){ - /* don't have code page name... try to autodetect */ - ucbuf_autodetect_fs(in,cp,&buf->conv,&buf->signatureLength,error); - }else if(ucbuf_isCPKnown(*cp)){ - /* discard BOM */ - ucbuf_autodetect_fs(in,&knownCp,&buf->conv,&buf->signatureLength,error); - } - if(U_SUCCESS(*error) && buf->conv==NULL) { - buf->conv=ucnv_open(*cp,error); - } - if(U_FAILURE(*error)){ - ucnv_close(buf->conv); - uprv_free(buf); - T_FileStream_close(in); - return NULL; - } - - if((buf->conv==NULL) && (buf->showWarning==TRUE)){ - fprintf(stderr,"###WARNING: No converter defined. Using codepage of system.\n"); - } - buf->remaining=fileSize-buf->signatureLength; - if(buf->isBuffered){ - buf->bufCapacity=MAX_U_BUF; - }else{ - buf->bufCapacity=buf->remaining+buf->signatureLength+1/*for terminating nul*/; - } - buf->buffer=(UChar*) uprv_malloc(U_SIZEOF_UCHAR * buf->bufCapacity ); - if (buf->buffer == NULL) { - *error = U_MEMORY_ALLOCATION_ERROR; - ucbuf_close(buf); - return NULL; - } - buf->currentPos=buf->buffer; - buf->bufLimit=buf->buffer; - if(U_FAILURE(*error)){ - fprintf(stderr, "Could not open codepage [%s]: %s\n", *cp, u_errorName(*error)); - ucbuf_close(buf); - return NULL; - } - ucbuf_fillucbuf(buf,error); - if(U_FAILURE(*error)){ - ucbuf_close(buf); - return NULL; - } - return buf; - } - *error =U_FILE_ACCESS_ERROR; - return NULL; -} - - - -/* TODO: this method will fail if at the - * begining of buffer and the uchar to unget - * is from the previous buffer. Need to implement - * system to take care of that situation. - */ -U_CAPI void U_EXPORT2 -ucbuf_ungetc(int32_t c,UCHARBUF* buf){ - /* decrement currentPos pointer - * if not at the begining of buffer - */ - if(buf->currentPos!=buf->buffer){ - if(*(buf->currentPos-1)==c){ - buf->currentPos--; - } else { - /* ungetc failed - did not match. */ - } - } else { - /* ungetc failed - beginning of buffer. */ - } -} - -/* frees the resources of UChar* buffer */ -static void -ucbuf_closebuf(UCHARBUF* buf){ - uprv_free(buf->buffer); - buf->buffer = NULL; -} - -/* close the buf and release resources*/ -U_CAPI void U_EXPORT2 -ucbuf_close(UCHARBUF* buf){ - if(buf!=NULL){ - if(buf->conv){ - ucnv_close(buf->conv); - } - T_FileStream_close(buf->in); - ucbuf_closebuf(buf); - uprv_free(buf); - } -} - -/* rewind the buf and file stream */ -U_CAPI void U_EXPORT2 -ucbuf_rewind(UCHARBUF* buf,UErrorCode* error){ - if(error==NULL || U_FAILURE(*error)){ - return; - } - if(buf){ - buf->currentPos=buf->buffer; - buf->bufLimit=buf->buffer; - T_FileStream_rewind(buf->in); - buf->remaining=T_FileStream_size(buf->in)-buf->signatureLength; - - ucnv_resetToUnicode(buf->conv); - if(buf->signatureLength>0) { - UChar target[1]={ 0 }; - UChar* pTarget; - char start[8]; - const char* pStart; - int32_t numRead; - - /* read the signature bytes */ - numRead=T_FileStream_read(buf->in, start, buf->signatureLength); - - /* convert and ignore initial U+FEFF, and the buffer overflow */ - pTarget = target; - pStart = start; - ucnv_toUnicode(buf->conv, &pTarget, target+1, &pStart, start+numRead, NULL, FALSE, error); - if(*error==U_BUFFER_OVERFLOW_ERROR) { - *error=U_ZERO_ERROR; - } - - /* verify that we successfully read exactly U+FEFF */ - if(U_SUCCESS(*error) && (numRead!=buf->signatureLength || pTarget!=(target+1) || target[0]!=0xfeff)) { - *error=U_INTERNAL_PROGRAM_ERROR; - } - } - } -} - - -U_CAPI int32_t U_EXPORT2 -ucbuf_size(UCHARBUF* buf){ - if(buf){ - if(buf->isBuffered){ - return (T_FileStream_size(buf->in)-buf->signatureLength)/ucnv_getMinCharSize(buf->conv); - }else{ - return (int32_t)(buf->bufLimit - buf->buffer); - } - } - return 0; -} - -U_CAPI const UChar* U_EXPORT2 -ucbuf_getBuffer(UCHARBUF* buf,int32_t* len,UErrorCode* error){ - if(error==NULL || U_FAILURE(*error)){ - return NULL; - } - if(buf==NULL || len==NULL){ - *error = U_ILLEGAL_ARGUMENT_ERROR; - return NULL; - } - *len = (int32_t)(buf->bufLimit - buf->buffer); - return buf->buffer; -} - -U_CAPI const char* U_EXPORT2 -ucbuf_resolveFileName(const char* inputDir, const char* fileName, char* target, int32_t* len, UErrorCode* status){ - int32_t requiredLen = 0; - int32_t dirlen = 0; - int32_t filelen = 0; - if(status==NULL || U_FAILURE(*status)){ - return NULL; - } - - if(inputDir == NULL || fileName == NULL || len==NULL || (target==NULL && *len>0)){ - *status = U_ILLEGAL_ARGUMENT_ERROR; - return NULL; - } - - - dirlen = (int32_t)uprv_strlen(inputDir); - filelen = (int32_t)uprv_strlen(fileName); - if(inputDir[dirlen-1] != U_FILE_SEP_CHAR) { - requiredLen = dirlen + filelen + 2; - if((*len < requiredLen) || target==NULL){ - *len = requiredLen; - *status = U_BUFFER_OVERFLOW_ERROR; - return NULL; - } - - target[0] = '\0'; - /* - * append the input dir to openFileName if the first char in - * filename is not file seperation char and the last char input directory is not '.'. - * This is to support : - * genrb -s. /home/icu/data - * genrb -s. icu/data - * The user cannot mix notations like - * genrb -s. /icu/data --- the absolute path specified. -s redundant - * user should use - * genrb -s. icu/data --- start from CWD and look in icu/data dir - */ - if( (fileName[0] != U_FILE_SEP_CHAR) && (inputDir[dirlen-1] !='.')){ - uprv_strcpy(target, inputDir); - target[dirlen] = U_FILE_SEP_CHAR; - } - target[dirlen + 1] = '\0'; - } else { - requiredLen = dirlen + filelen + 1; - if((*len < requiredLen) || target==NULL){ - *len = requiredLen; - *status = U_BUFFER_OVERFLOW_ERROR; - return NULL; - } - - uprv_strcpy(target, inputDir); - } - - uprv_strcat(target, fileName); - return target; -} -/* - * Unicode TR 13 says any of the below chars is - * a new line char in a readline function in addition - * to CR+LF combination which needs to be - * handled seperately - */ -static UBool ucbuf_isCharNewLine(UChar c){ - switch(c){ - case 0x000A: /* LF */ - case 0x000D: /* CR */ - case 0x000C: /* FF */ - case 0x0085: /* NEL */ - case 0x2028: /* LS */ - case 0x2029: /* PS */ - return TRUE; - default: - return FALSE; - } -} - -U_CAPI const UChar* U_EXPORT2 -ucbuf_readline(UCHARBUF* buf,int32_t* len,UErrorCode* err){ - UChar* temp = buf->currentPos; - UChar* savePos =NULL; - UChar c=0x0000; - if(buf->isBuffered){ - /* The input is buffered we have to do more - * for returning a pointer U_TRUNCATED_CHAR_FOUND - */ - for(;;){ - c = *temp++; - if(buf->remaining==0){ - return NULL; /* end of file is reached return NULL */ - } - if(temp>=buf->bufLimit && buf->currentPos == buf->buffer){ - *err= U_TRUNCATED_CHAR_FOUND; - return NULL; - }else{ - ucbuf_fillucbuf(buf,err); - if(U_FAILURE(*err)){ - return NULL; - } - } - /* - * Accoding to TR 13 readLine functions must interpret - * CR, CR+LF, LF, NEL, PS, LS or FF as line seperators - */ - /* Windows CR LF */ - if(c ==0x0d && temp <= buf->bufLimit && *temp == 0x0a ){ - *len = (int32_t)(temp++ - buf->currentPos); - savePos = buf->currentPos; - buf->currentPos = temp; - return savePos; - } - /* else */ - - if (temp>=buf->bufLimit|| ucbuf_isCharNewLine(c)){ /* Unipad inserts 2028 line separators! */ - *len = (int32_t)(temp - buf->currentPos); - savePos = buf->currentPos; - buf->currentPos = temp; - return savePos; - } - } - }else{ - /* we know that all input is read into the internal - * buffer so we can safely return pointers - */ - for(;;){ - c = *temp++; - - if(buf->currentPos==buf->bufLimit){ - return NULL; /* end of file is reached return NULL */ - } - /* Windows CR LF */ - if(c ==0x0d && temp <= buf->bufLimit && *temp == 0x0a ){ - *len = (int32_t)(temp++ - buf->currentPos); - savePos = buf->currentPos; - buf->currentPos = temp; - return savePos; - } - /* else */ - if (temp>=buf->bufLimit|| ucbuf_isCharNewLine(c)) { /* Unipad inserts 2028 line separators! */ - *len = (int32_t)(temp - buf->currentPos); - savePos = buf->currentPos; - buf->currentPos = temp; - return savePos; - } - } - } - /* not reached */ - /* A compiler warning will appear if all paths don't contain a return statement. */ -/* return NULL;*/ -} -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/ucbuf.h b/deps/node/deps/icu-small/source/tools/toolutil/ucbuf.h deleted file mode 100644 index 48d41ef4..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/ucbuf.h +++ /dev/null @@ -1,217 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1998-2016, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* -* File ucbuf.h -* -* Modification History: -* -* Date Name Description -* 05/10/01 Ram Creation. -* -* This API reads in files and returns UChars -******************************************************************************* -*/ - -#include "unicode/localpointer.h" -#include "unicode/ucnv.h" -#include "filestrm.h" - -#if !UCONFIG_NO_CONVERSION - -#ifndef UCBUF_H -#define UCBUF_H 1 - -typedef struct UCHARBUF UCHARBUF; -/** - * End of file value - */ -#define U_EOF 0xFFFFFFFF -/** - * Error value if a sequence cannot be unescaped - */ -#define U_ERR 0xFFFFFFFE - -typedef struct ULine ULine; - -struct ULine { - UChar *name; - int32_t len; -}; - -/** - * Opens the UCHARBUF with the given file stream and code page for conversion - * @param fileName Name of the file to open. - * @param codepage The encoding of the file stream to convert to Unicode. - * If *codepoge is NULL on input the API will try to autodetect - * popular Unicode encodings - * @param showWarning Flag to print out warnings to STDOUT - * @param buffered If TRUE performs a buffered read of the input file. If FALSE reads - * the whole file into memory and converts it. - * @param err is a pointer to a valid <code>UErrorCode</code> value. If this value - * indicates a failure on entry, the function will immediately return. - * On exit the value will indicate the success of the operation. - * @return pointer to the newly opened UCHARBUF - */ -U_CAPI UCHARBUF* U_EXPORT2 -ucbuf_open(const char* fileName,const char** codepage,UBool showWarning, UBool buffered, UErrorCode* err); - -/** - * Gets a UTF-16 code unit at the current position from the converted buffer - * and increments the current position - * @param buf Pointer to UCHARBUF structure - * @param err is a pointer to a valid <code>UErrorCode</code> value. If this value - * indicates a failure on entry, the function will immediately return. - * On exit the value will indicate the success of the operation. - */ -U_CAPI int32_t U_EXPORT2 -ucbuf_getc(UCHARBUF* buf,UErrorCode* err); - -/** - * Gets a UTF-32 code point at the current position from the converted buffer - * and increments the current position - * @param buf Pointer to UCHARBUF structure - * @param err is a pointer to a valid <code>UErrorCode</code> value. If this value - * indicates a failure on entry, the function will immediately return. - * On exit the value will indicate the success of the operation. - */ -U_CAPI int32_t U_EXPORT2 -ucbuf_getc32(UCHARBUF* buf,UErrorCode* err); - -/** - * Gets a UTF-16 code unit at the current position from the converted buffer after - * unescaping and increments the current position. If the escape sequence is for UTF-32 - * code point (\\Uxxxxxxxx) then a UTF-32 codepoint is returned - * @param buf Pointer to UCHARBUF structure - * @param err is a pointer to a valid <code>UErrorCode</code> value. If this value - * indicates a failure on entry, the function will immediately return. - * On exit the value will indicate the success of the operation. - */ -U_CAPI int32_t U_EXPORT2 -ucbuf_getcx32(UCHARBUF* buf,UErrorCode* err); - -/** - * Gets a pointer to the current position in the internal buffer and length of the line. - * It imperative to make a copy of the returned buffer before performing operations on it. - * @param buf Pointer to UCHARBUF structure - * @param len Output param to receive the len of the buffer returned till end of the line - * @param err is a pointer to a valid <code>UErrorCode</code> value. If this value - * indicates a failure on entry, the function will immediately return. - * On exit the value will indicate the success of the operation. - * Error: U_TRUNCATED_CHAR_FOUND - * @return Pointer to the internal buffer, NULL if EOF - */ -U_CAPI const UChar* U_EXPORT2 -ucbuf_readline(UCHARBUF* buf,int32_t* len, UErrorCode* err); - - -/** - * Resets the buffers and the underlying file stream. - * @param buf Pointer to UCHARBUF structure - * @param err is a pointer to a valid <code>UErrorCode</code> value. If this value - * indicates a failure on entry, the function will immediately return. - * On exit the value will indicate the success of the operation. - */ -U_CAPI void U_EXPORT2 -ucbuf_rewind(UCHARBUF* buf,UErrorCode* err); - -/** - * Returns a pointer to the internal converted buffer - * @param buf Pointer to UCHARBUF structure - * @param len Pointer to int32_t to receive the lenth of buffer - * @param err is a pointer to a valid <code>UErrorCode</code> value. If this value - * indicates a failure on entry, the function will immediately return. - * On exit the value will indicate the success of the operation. - * @return Pointer to internal UChar buffer - */ -U_CAPI const UChar* U_EXPORT2 -ucbuf_getBuffer(UCHARBUF* buf,int32_t* len,UErrorCode* err); - -/** - * Closes the UCHARBUF structure members and cleans up the malloc'ed memory - * @param buf Pointer to UCHARBUF structure - */ -U_CAPI void U_EXPORT2 -ucbuf_close(UCHARBUF* buf); - -#if U_SHOW_CPLUSPLUS_API - -U_NAMESPACE_BEGIN - -/** - * \class LocalUCHARBUFPointer - * "Smart pointer" class, closes a UCHARBUF via ucbuf_close(). - * For most methods see the LocalPointerBase base class. - * - * @see LocalPointerBase - * @see LocalPointer - */ -U_DEFINE_LOCAL_OPEN_POINTER(LocalUCHARBUFPointer, UCHARBUF, ucbuf_close); - -U_NAMESPACE_END - -#endif - -/** - * Rewinds the buffer by one codepoint. Does not rewind over escaped characters. - */ -U_CAPI void U_EXPORT2 -ucbuf_ungetc(int32_t ungetChar,UCHARBUF* buf); - - -/** - * Autodetects the encoding of the file stream. Only Unicode charsets are autodectected. - * Some Unicode charsets are stateful and need byte identifiers to be converted also to bring - * the converter to correct state for converting the rest of the stream. So the UConverter parameter - * is necessary. - * If the charset was autodetected, the caller must close both the input FileStream - * and the converter. - * - * @param fileName The file name to be opened and encoding autodected - * @param conv Output param to receive the opened converter if autodetected; NULL otherwise. - * @param cp Output param to receive the detected encoding - * @param err is a pointer to a valid <code>UErrorCode</code> value. If this value - * indicates a failure on entry, the function will immediately return. - * On exit the value will indicate the success of the operation. - * @return The input FileStream if its charset was autodetected; NULL otherwise. - */ -U_CAPI FileStream * U_EXPORT2 -ucbuf_autodetect(const char* fileName, const char** cp,UConverter** conv, -int32_t* signatureLength, UErrorCode* status); - -/** - * Autodetects the encoding of the file stream. Only Unicode charsets are autodectected. - * Some Unicode charsets are stateful and need byte identifiers to be converted also to bring - * the converter to correct state for converting the rest of the stream. So the UConverter parameter - * is necessary. - * If the charset was autodetected, the caller must close the converter. - * - * @param fileStream The file stream whose encoding is to be detected - * @param conv Output param to receive the opened converter if autodetected; NULL otherwise. - * @param cp Output param to receive the detected encoding - * @param err is a pointer to a valid <code>UErrorCode</code> value. If this value - * indicates a failure on entry, the function will immediately return. - * On exit the value will indicate the success of the operation. - * @return Boolean whether the Unicode charset was autodetected. - */ - -U_CAPI UBool U_EXPORT2 -ucbuf_autodetect_fs(FileStream* in, const char** cp, UConverter** conv, int32_t* signatureLength, UErrorCode* status); - -/** - * Returns the approximate size in UChars required for converting the file to UChars - */ -U_CAPI int32_t U_EXPORT2 -ucbuf_size(UCHARBUF* buf); - -U_CAPI const char* U_EXPORT2 -ucbuf_resolveFileName(const char* inputDir, const char* fileName, char* target, int32_t* len, UErrorCode* status); - -#endif -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/ucln_tu.cpp b/deps/node/deps/icu-small/source/tools/toolutil/ucln_tu.cpp deleted file mode 100644 index 5354fe17..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/ucln_tu.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/******************************************************************** - * COPYRIGHT: - * Copyright (c) 2007-2014, International Business Machines Corporation and - * others. All Rights Reserved. - ********************************************************************/ - - -/** Auto-client **/ -#define UCLN_TYPE UCLN_TOOLUTIL -#include "ucln_imp.h" - -int uprv_dummyFunction_TU(void); -int uprv_dummyFunction_TU(void) -{ - /* this is here to prevent the compiler from complaining about an empty file */ - return 0; -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/ucm.cpp b/deps/node/deps/icu-small/source/tools/toolutil/ucm.cpp deleted file mode 100644 index 28c3f3f4..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/ucm.cpp +++ /dev/null @@ -1,1195 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2003-2013, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: ucm.c -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2003jun20 -* created by: Markus W. Scherer -* -* This file reads a .ucm file, stores its mappings and sorts them. -* It implements handling of Unicode conversion mappings from .ucm files -* for makeconv, canonucm, rptp2ucm, etc. -* -* Unicode code point sequences with a length of more than 1, -* as well as byte sequences with more than 4 bytes or more than one complete -* character sequence are handled to support m:n mappings. -*/ - -#include "unicode/utypes.h" -#include "unicode/ustring.h" -#include "cstring.h" -#include "cmemory.h" -#include "filestrm.h" -#include "uarrsort.h" -#include "ucnvmbcs.h" -#include "ucnv_bld.h" -#include "ucnv_ext.h" -#include "uparse.h" -#include "ucm.h" -#include <stdio.h> - -#if !UCONFIG_NO_CONVERSION - -/* -------------------------------------------------------------------------- */ - -static void -printMapping(UCMapping *m, UChar32 *codePoints, uint8_t *bytes, FILE *f) { - int32_t j; - - for(j=0; j<m->uLen; ++j) { - fprintf(f, "<U%04lX>", (long)codePoints[j]); - } - - fputc(' ', f); - - for(j=0; j<m->bLen; ++j) { - fprintf(f, "\\x%02X", bytes[j]); - } - - if(m->f>=0) { - fprintf(f, " |%u\n", m->f); - } else { - fputs("\n", f); - } -} - -U_CAPI void U_EXPORT2 -ucm_printMapping(UCMTable *table, UCMapping *m, FILE *f) { - printMapping(m, UCM_GET_CODE_POINTS(table, m), UCM_GET_BYTES(table, m), f); -} - -U_CAPI void U_EXPORT2 -ucm_printTable(UCMTable *table, FILE *f, UBool byUnicode) { - UCMapping *m; - int32_t i, length; - - m=table->mappings; - length=table->mappingsLength; - if(byUnicode) { - for(i=0; i<length; ++m, ++i) { - ucm_printMapping(table, m, f); - } - } else { - const int32_t *map=table->reverseMap; - for(i=0; i<length; ++i) { - ucm_printMapping(table, m+map[i], f); - } - } -} - -/* mapping comparisons ------------------------------------------------------ */ - -static int32_t -compareUnicode(UCMTable *lTable, const UCMapping *l, - UCMTable *rTable, const UCMapping *r) { - const UChar32 *lu, *ru; - int32_t result, i, length; - - if(l->uLen==1 && r->uLen==1) { - /* compare two single code points */ - return l->u-r->u; - } - - /* get pointers to the code point sequences */ - lu=UCM_GET_CODE_POINTS(lTable, l); - ru=UCM_GET_CODE_POINTS(rTable, r); - - /* get the minimum length */ - if(l->uLen<=r->uLen) { - length=l->uLen; - } else { - length=r->uLen; - } - - /* compare the code points */ - for(i=0; i<length; ++i) { - result=lu[i]-ru[i]; - if(result!=0) { - return result; - } - } - - /* compare the lengths */ - return l->uLen-r->uLen; -} - -static int32_t -compareBytes(UCMTable *lTable, const UCMapping *l, - UCMTable *rTable, const UCMapping *r, - UBool lexical) { - const uint8_t *lb, *rb; - int32_t result, i, length; - - /* - * A lexical comparison is used for sorting in the builder, to allow - * an efficient search for a byte sequence that could be a prefix - * of a previously entered byte sequence. - * - * Comparing by lengths first is for compatibility with old .ucm tools - * like canonucm and rptp2ucm. - */ - if(lexical) { - /* get the minimum length and continue */ - if(l->bLen<=r->bLen) { - length=l->bLen; - } else { - length=r->bLen; - } - } else { - /* compare lengths first */ - result=l->bLen-r->bLen; - if(result!=0) { - return result; - } else { - length=l->bLen; - } - } - - /* get pointers to the byte sequences */ - lb=UCM_GET_BYTES(lTable, l); - rb=UCM_GET_BYTES(rTable, r); - - /* compare the bytes */ - for(i=0; i<length; ++i) { - result=lb[i]-rb[i]; - if(result!=0) { - return result; - } - } - - /* compare the lengths */ - return l->bLen-r->bLen; -} - -/* compare UCMappings for sorting */ -static int32_t -compareMappings(UCMTable *lTable, const UCMapping *l, - UCMTable *rTable, const UCMapping *r, - UBool uFirst) { - int32_t result; - - /* choose which side to compare first */ - if(uFirst) { - /* Unicode then bytes */ - result=compareUnicode(lTable, l, rTable, r); - if(result==0) { - result=compareBytes(lTable, l, rTable, r, FALSE); /* not lexically, like canonucm */ - } - } else { - /* bytes then Unicode */ - result=compareBytes(lTable, l, rTable, r, TRUE); /* lexically, for builder */ - if(result==0) { - result=compareUnicode(lTable, l, rTable, r); - } - } - - if(result!=0) { - return result; - } - - /* compare the flags */ - return l->f-r->f; -} -U_CDECL_BEGIN -/* sorting by Unicode first sorts mappings directly */ -static int32_t U_CALLCONV -compareMappingsUnicodeFirst(const void *context, const void *left, const void *right) { - return compareMappings( - (UCMTable *)context, (const UCMapping *)left, - (UCMTable *)context, (const UCMapping *)right, TRUE); -} - -/* sorting by bytes first sorts the reverseMap; use indirection to mappings */ -static int32_t U_CALLCONV -compareMappingsBytesFirst(const void *context, const void *left, const void *right) { - UCMTable *table=(UCMTable *)context; - int32_t l=*(const int32_t *)left, r=*(const int32_t *)right; - return compareMappings( - table, table->mappings+l, - table, table->mappings+r, FALSE); -} -U_CDECL_END - -U_CAPI void U_EXPORT2 -ucm_sortTable(UCMTable *t) { - UErrorCode errorCode; - int32_t i; - - if(t->isSorted) { - return; - } - - errorCode=U_ZERO_ERROR; - - /* 1. sort by Unicode first */ - uprv_sortArray(t->mappings, t->mappingsLength, sizeof(UCMapping), - compareMappingsUnicodeFirst, t, - FALSE, &errorCode); - - /* build the reverseMap */ - if(t->reverseMap==NULL) { - /* - * allocate mappingsCapacity instead of mappingsLength so that - * if mappings are added, the reverseMap need not be - * reallocated each time - * (see ucm_moveMappings() and ucm_addMapping()) - */ - t->reverseMap=(int32_t *)uprv_malloc(t->mappingsCapacity*sizeof(int32_t)); - if(t->reverseMap==NULL) { - fprintf(stderr, "ucm error: unable to allocate reverseMap\n"); - exit(U_MEMORY_ALLOCATION_ERROR); - } - } - for(i=0; i<t->mappingsLength; ++i) { - t->reverseMap[i]=i; - } - - /* 2. sort reverseMap by mappings bytes first */ - uprv_sortArray(t->reverseMap, t->mappingsLength, sizeof(int32_t), - compareMappingsBytesFirst, t, - FALSE, &errorCode); - - if(U_FAILURE(errorCode)) { - fprintf(stderr, "ucm error: sortTable()/uprv_sortArray() fails - %s\n", - u_errorName(errorCode)); - exit(errorCode); - } - - t->isSorted=TRUE; -} - -/* - * remove mappings with their move flag set from the base table - * and move some of them (with UCM_MOVE_TO_EXT) to the extension table - */ -U_CAPI void U_EXPORT2 -ucm_moveMappings(UCMTable *base, UCMTable *ext) { - UCMapping *mb, *mbLimit; - int8_t flag; - - mb=base->mappings; - mbLimit=mb+base->mappingsLength; - - while(mb<mbLimit) { - flag=mb->moveFlag; - if(flag!=0) { - /* reset the move flag */ - mb->moveFlag=0; - - if(ext!=NULL && (flag&UCM_MOVE_TO_EXT)) { - /* add the mapping to the extension table */ - ucm_addMapping(ext, mb, UCM_GET_CODE_POINTS(base, mb), UCM_GET_BYTES(base, mb)); - } - - /* remove this mapping: move the last base mapping down and overwrite the current one */ - if(mb<(mbLimit-1)) { - uprv_memcpy(mb, mbLimit-1, sizeof(UCMapping)); - } - --mbLimit; - --base->mappingsLength; - base->isSorted=FALSE; - } else { - ++mb; - } - } -} - -enum { - NEEDS_MOVE=1, - HAS_ERRORS=2 -}; - -static uint8_t -checkBaseExtUnicode(UCMStates *baseStates, UCMTable *base, UCMTable *ext, - UBool moveToExt, UBool intersectBase) { - (void)baseStates; - - UCMapping *mb, *me, *mbLimit, *meLimit; - int32_t cmp; - uint8_t result; - - mb=base->mappings; - mbLimit=mb+base->mappingsLength; - - me=ext->mappings; - meLimit=me+ext->mappingsLength; - - result=0; - - for(;;) { - /* skip irrelevant mappings on both sides */ - for(;;) { - if(mb==mbLimit) { - return result; - } - - if((0<=mb->f && mb->f<=2) || mb->f==4) { - break; - } - - ++mb; - } - - for(;;) { - if(me==meLimit) { - return result; - } - - if((0<=me->f && me->f<=2) || me->f==4) { - break; - } - - ++me; - } - - /* compare the base and extension mappings */ - cmp=compareUnicode(base, mb, ext, me); - if(cmp<0) { - if(intersectBase && (intersectBase!=2 || mb->bLen>1)) { - /* - * mapping in base but not in ext, move it - * - * if ext is DBCS, move DBCS mappings here - * and check SBCS ones for Unicode prefix below - */ - mb->moveFlag|=UCM_MOVE_TO_EXT; - result|=NEEDS_MOVE; - - /* does mb map from an input sequence that is a prefix of me's? */ - } else if( mb->uLen<me->uLen && - 0==uprv_memcmp(UCM_GET_CODE_POINTS(base, mb), UCM_GET_CODE_POINTS(ext, me), 4*mb->uLen) - ) { - if(moveToExt) { - /* mark this mapping to be moved to the extension table */ - mb->moveFlag|=UCM_MOVE_TO_EXT; - result|=NEEDS_MOVE; - } else { - fprintf(stderr, - "ucm error: the base table contains a mapping whose input sequence\n" - " is a prefix of the input sequence of an extension mapping\n"); - ucm_printMapping(base, mb, stderr); - ucm_printMapping(ext, me, stderr); - result|=HAS_ERRORS; - } - } - - ++mb; - } else if(cmp==0) { - /* - * same output: remove the extension mapping, - * otherwise treat as an error - */ - if( mb->f==me->f && mb->bLen==me->bLen && - 0==uprv_memcmp(UCM_GET_BYTES(base, mb), UCM_GET_BYTES(ext, me), mb->bLen) - ) { - me->moveFlag|=UCM_REMOVE_MAPPING; - result|=NEEDS_MOVE; - } else if(intersectBase) { - /* mapping in base but not in ext, move it */ - mb->moveFlag|=UCM_MOVE_TO_EXT; - result|=NEEDS_MOVE; - } else { - fprintf(stderr, - "ucm error: the base table contains a mapping whose input sequence\n" - " is the same as the input sequence of an extension mapping\n" - " but it maps differently\n"); - ucm_printMapping(base, mb, stderr); - ucm_printMapping(ext, me, stderr); - result|=HAS_ERRORS; - } - - ++mb; - } else /* cmp>0 */ { - ++me; - } - } -} - -static uint8_t -checkBaseExtBytes(UCMStates *baseStates, UCMTable *base, UCMTable *ext, - UBool moveToExt, UBool intersectBase) { - UCMapping *mb, *me; - int32_t *baseMap, *extMap; - int32_t b, e, bLimit, eLimit, cmp; - uint8_t result; - UBool isSISO; - - baseMap=base->reverseMap; - extMap=ext->reverseMap; - - b=e=0; - bLimit=base->mappingsLength; - eLimit=ext->mappingsLength; - - result=0; - - isSISO=(UBool)(baseStates->outputType==MBCS_OUTPUT_2_SISO); - - for(;;) { - /* skip irrelevant mappings on both sides */ - for(;; ++b) { - if(b==bLimit) { - return result; - } - mb=base->mappings+baseMap[b]; - - if(intersectBase==2 && mb->bLen==1) { - /* - * comparing a base against a DBCS extension: - * leave SBCS base mappings alone - */ - continue; - } - - if(mb->f==0 || mb->f==3) { - break; - } - } - - for(;;) { - if(e==eLimit) { - return result; - } - me=ext->mappings+extMap[e]; - - if(me->f==0 || me->f==3) { - break; - } - - ++e; - } - - /* compare the base and extension mappings */ - cmp=compareBytes(base, mb, ext, me, TRUE); - if(cmp<0) { - if(intersectBase) { - /* mapping in base but not in ext, move it */ - mb->moveFlag|=UCM_MOVE_TO_EXT; - result|=NEEDS_MOVE; - - /* - * does mb map from an input sequence that is a prefix of me's? - * for SI/SO tables, a single byte is never a prefix because it - * occurs in a separate single-byte state - */ - } else if( mb->bLen<me->bLen && - (!isSISO || mb->bLen>1) && - 0==uprv_memcmp(UCM_GET_BYTES(base, mb), UCM_GET_BYTES(ext, me), mb->bLen) - ) { - if(moveToExt) { - /* mark this mapping to be moved to the extension table */ - mb->moveFlag|=UCM_MOVE_TO_EXT; - result|=NEEDS_MOVE; - } else { - fprintf(stderr, - "ucm error: the base table contains a mapping whose input sequence\n" - " is a prefix of the input sequence of an extension mapping\n"); - ucm_printMapping(base, mb, stderr); - ucm_printMapping(ext, me, stderr); - result|=HAS_ERRORS; - } - } - - ++b; - } else if(cmp==0) { - /* - * same output: remove the extension mapping, - * otherwise treat as an error - */ - if( mb->f==me->f && mb->uLen==me->uLen && - 0==uprv_memcmp(UCM_GET_CODE_POINTS(base, mb), UCM_GET_CODE_POINTS(ext, me), 4*mb->uLen) - ) { - me->moveFlag|=UCM_REMOVE_MAPPING; - result|=NEEDS_MOVE; - } else if(intersectBase) { - /* mapping in base but not in ext, move it */ - mb->moveFlag|=UCM_MOVE_TO_EXT; - result|=NEEDS_MOVE; - } else { - fprintf(stderr, - "ucm error: the base table contains a mapping whose input sequence\n" - " is the same as the input sequence of an extension mapping\n" - " but it maps differently\n"); - ucm_printMapping(base, mb, stderr); - ucm_printMapping(ext, me, stderr); - result|=HAS_ERRORS; - } - - ++b; - } else /* cmp>0 */ { - ++e; - } - } -} - -U_CAPI UBool U_EXPORT2 -ucm_checkValidity(UCMTable *table, UCMStates *baseStates) { - UCMapping *m, *mLimit; - int32_t count; - UBool isOK; - - m=table->mappings; - mLimit=m+table->mappingsLength; - isOK=TRUE; - - while(m<mLimit) { - count=ucm_countChars(baseStates, UCM_GET_BYTES(table, m), m->bLen); - if(count<1) { - ucm_printMapping(table, m, stderr); - isOK=FALSE; - } - ++m; - } - - return isOK; -} - -U_CAPI UBool U_EXPORT2 -ucm_checkBaseExt(UCMStates *baseStates, - UCMTable *base, UCMTable *ext, UCMTable *moveTarget, - UBool intersectBase) { - uint8_t result; - - /* if we have an extension table, we must always use precision flags */ - if(base->flagsType&UCM_FLAGS_IMPLICIT) { - fprintf(stderr, "ucm error: the base table contains mappings without precision flags\n"); - return FALSE; - } - if(ext->flagsType&UCM_FLAGS_IMPLICIT) { - fprintf(stderr, "ucm error: extension table contains mappings without precision flags\n"); - return FALSE; - } - - /* checking requires both tables to be sorted */ - ucm_sortTable(base); - ucm_sortTable(ext); - - /* check */ - result= - checkBaseExtUnicode(baseStates, base, ext, (UBool)(moveTarget!=NULL), intersectBase)| - checkBaseExtBytes(baseStates, base, ext, (UBool)(moveTarget!=NULL), intersectBase); - - if(result&HAS_ERRORS) { - return FALSE; - } - - if(result&NEEDS_MOVE) { - ucm_moveMappings(ext, NULL); - ucm_moveMappings(base, moveTarget); - ucm_sortTable(base); - ucm_sortTable(ext); - if(moveTarget!=NULL) { - ucm_sortTable(moveTarget); - } - } - - return TRUE; -} - -/* merge tables for rptp2ucm ------------------------------------------------ */ - -U_CAPI void U_EXPORT2 -ucm_mergeTables(UCMTable *fromUTable, UCMTable *toUTable, - const uint8_t *subchar, int32_t subcharLength, - uint8_t subchar1) { - UCMapping *fromUMapping, *toUMapping; - int32_t fromUIndex, toUIndex, fromUTop, toUTop, cmp; - - ucm_sortTable(fromUTable); - ucm_sortTable(toUTable); - - fromUMapping=fromUTable->mappings; - toUMapping=toUTable->mappings; - - fromUTop=fromUTable->mappingsLength; - toUTop=toUTable->mappingsLength; - - fromUIndex=toUIndex=0; - - while(fromUIndex<fromUTop && toUIndex<toUTop) { - cmp=compareMappings(fromUTable, fromUMapping, toUTable, toUMapping, TRUE); - if(cmp==0) { - /* equal: roundtrip, nothing to do (flags are initially 0) */ - ++fromUMapping; - ++toUMapping; - - ++fromUIndex; - ++toUIndex; - } else if(cmp<0) { - /* - * the fromU mapping does not have a toU counterpart: - * fallback Unicode->codepage - */ - if( (fromUMapping->bLen==subcharLength && - 0==uprv_memcmp(UCM_GET_BYTES(fromUTable, fromUMapping), subchar, subcharLength)) || - (subchar1!=0 && fromUMapping->bLen==1 && fromUMapping->b.bytes[0]==subchar1) - ) { - fromUMapping->f=2; /* SUB mapping */ - } else { - fromUMapping->f=1; /* normal fallback */ - } - - ++fromUMapping; - ++fromUIndex; - } else { - /* - * the toU mapping does not have a fromU counterpart: - * (reverse) fallback codepage->Unicode, copy it to the fromU table - */ - - /* ignore reverse fallbacks to Unicode SUB */ - if(!(toUMapping->uLen==1 && (toUMapping->u==0xfffd || toUMapping->u==0x1a))) { - toUMapping->f=3; /* reverse fallback */ - ucm_addMapping(fromUTable, toUMapping, UCM_GET_CODE_POINTS(toUTable, toUMapping), UCM_GET_BYTES(toUTable, toUMapping)); - - /* the table may have been reallocated */ - fromUMapping=fromUTable->mappings+fromUIndex; - } - - ++toUMapping; - ++toUIndex; - } - } - - /* either one or both tables are exhausted */ - while(fromUIndex<fromUTop) { - /* leftover fromU mappings are fallbacks */ - if( (fromUMapping->bLen==subcharLength && - 0==uprv_memcmp(UCM_GET_BYTES(fromUTable, fromUMapping), subchar, subcharLength)) || - (subchar1!=0 && fromUMapping->bLen==1 && fromUMapping->b.bytes[0]==subchar1) - ) { - fromUMapping->f=2; /* SUB mapping */ - } else { - fromUMapping->f=1; /* normal fallback */ - } - - ++fromUMapping; - ++fromUIndex; - } - - while(toUIndex<toUTop) { - /* leftover toU mappings are reverse fallbacks */ - - /* ignore reverse fallbacks to Unicode SUB */ - if(!(toUMapping->uLen==1 && (toUMapping->u==0xfffd || toUMapping->u==0x1a))) { - toUMapping->f=3; /* reverse fallback */ - ucm_addMapping(fromUTable, toUMapping, UCM_GET_CODE_POINTS(toUTable, toUMapping), UCM_GET_BYTES(toUTable, toUMapping)); - } - - ++toUMapping; - ++toUIndex; - } - - fromUTable->isSorted=FALSE; -} - -/* separate extension mappings out of base table for rptp2ucm --------------- */ - -U_CAPI UBool U_EXPORT2 -ucm_separateMappings(UCMFile *ucm, UBool isSISO) { - UCMTable *table; - UCMapping *m, *mLimit; - int32_t type; - UBool needsMove, isOK; - - table=ucm->base; - m=table->mappings; - mLimit=m+table->mappingsLength; - - needsMove=FALSE; - isOK=TRUE; - - for(; m<mLimit; ++m) { - if(isSISO && m->bLen==1 && (m->b.bytes[0]==0xe || m->b.bytes[0]==0xf)) { - fprintf(stderr, "warning: removing illegal mapping from an SI/SO-stateful table\n"); - ucm_printMapping(table, m, stderr); - m->moveFlag|=UCM_REMOVE_MAPPING; - needsMove=TRUE; - continue; - } - - type=ucm_mappingType( - &ucm->states, m, - UCM_GET_CODE_POINTS(table, m), UCM_GET_BYTES(table, m)); - if(type<0) { - /* illegal byte sequence */ - printMapping(m, UCM_GET_CODE_POINTS(table, m), UCM_GET_BYTES(table, m), stderr); - isOK=FALSE; - } else if(type>0) { - m->moveFlag|=UCM_MOVE_TO_EXT; - needsMove=TRUE; - } - } - - if(!isOK) { - return FALSE; - } - if(needsMove) { - ucm_moveMappings(ucm->base, ucm->ext); - return ucm_checkBaseExt(&ucm->states, ucm->base, ucm->ext, ucm->ext, FALSE); - } else { - ucm_sortTable(ucm->base); - return TRUE; - } -} - -/* ucm parser --------------------------------------------------------------- */ - -U_CAPI int8_t U_EXPORT2 -ucm_parseBytes(uint8_t bytes[UCNV_EXT_MAX_BYTES], const char *line, const char **ps) { - const char *s=*ps; - char *end; - uint8_t byte; - int8_t bLen; - - bLen=0; - for(;;) { - /* skip an optional plus sign */ - if(bLen>0 && *s=='+') { - ++s; - } - if(*s!='\\') { - break; - } - - if( s[1]!='x' || - (byte=(uint8_t)uprv_strtoul(s+2, &end, 16), end)!=s+4 - ) { - fprintf(stderr, "ucm error: byte must be formatted as \\xXX (2 hex digits) - \"%s\"\n", line); - return -1; - } - - if(bLen==UCNV_EXT_MAX_BYTES) { - fprintf(stderr, "ucm error: too many bytes on \"%s\"\n", line); - return -1; - } - bytes[bLen++]=byte; - s=end; - } - - *ps=s; - return bLen; -} - -/* parse a mapping line; must not be empty */ -U_CAPI UBool U_EXPORT2 -ucm_parseMappingLine(UCMapping *m, - UChar32 codePoints[UCNV_EXT_MAX_UCHARS], - uint8_t bytes[UCNV_EXT_MAX_BYTES], - const char *line) { - const char *s; - char *end; - UChar32 cp; - int32_t u16Length; - int8_t uLen, bLen, f; - - s=line; - uLen=bLen=0; - - /* parse code points */ - for(;;) { - /* skip an optional plus sign */ - if(uLen>0 && *s=='+') { - ++s; - } - if(*s!='<') { - break; - } - - if( s[1]!='U' || - (cp=(UChar32)uprv_strtoul(s+2, &end, 16), end)==s+2 || - *end!='>' - ) { - fprintf(stderr, "ucm error: Unicode code point must be formatted as <UXXXX> (1..6 hex digits) - \"%s\"\n", line); - return FALSE; - } - if((uint32_t)cp>0x10ffff || U_IS_SURROGATE(cp)) { - fprintf(stderr, "ucm error: Unicode code point must be 0..d7ff or e000..10ffff - \"%s\"\n", line); - return FALSE; - } - - if(uLen==UCNV_EXT_MAX_UCHARS) { - fprintf(stderr, "ucm error: too many code points on \"%s\"\n", line); - return FALSE; - } - codePoints[uLen++]=cp; - s=end+1; - } - - if(uLen==0) { - fprintf(stderr, "ucm error: no Unicode code points on \"%s\"\n", line); - return FALSE; - } else if(uLen==1) { - m->u=codePoints[0]; - } else { - UErrorCode errorCode=U_ZERO_ERROR; - u_strFromUTF32(NULL, 0, &u16Length, codePoints, uLen, &errorCode); - if( (U_FAILURE(errorCode) && errorCode!=U_BUFFER_OVERFLOW_ERROR) || - u16Length>UCNV_EXT_MAX_UCHARS - ) { - fprintf(stderr, "ucm error: too many UChars on \"%s\"\n", line); - return FALSE; - } - } - - s=u_skipWhitespace(s); - - /* parse bytes */ - bLen=ucm_parseBytes(bytes, line, &s); - - if(bLen<0) { - return FALSE; - } else if(bLen==0) { - fprintf(stderr, "ucm error: no bytes on \"%s\"\n", line); - return FALSE; - } else if(bLen<=4) { - uprv_memcpy(m->b.bytes, bytes, bLen); - } - - /* skip everything until the fallback indicator, even the start of a comment */ - for(;;) { - if(*s==0) { - f=-1; /* no fallback indicator */ - break; - } else if(*s=='|') { - f=(int8_t)(s[1]-'0'); - if((uint8_t)f>4) { - fprintf(stderr, "ucm error: fallback indicator must be |0..|4 - \"%s\"\n", line); - return FALSE; - } - break; - } - ++s; - } - - m->uLen=uLen; - m->bLen=bLen; - m->f=f; - return TRUE; -} - -/* general APIs ------------------------------------------------------------- */ - -U_CAPI UCMTable * U_EXPORT2 -ucm_openTable() { - UCMTable *table=(UCMTable *)uprv_malloc(sizeof(UCMTable)); - if(table==NULL) { - fprintf(stderr, "ucm error: unable to allocate a UCMTable\n"); - exit(U_MEMORY_ALLOCATION_ERROR); - } - - memset(table, 0, sizeof(UCMTable)); - return table; -} - -U_CAPI void U_EXPORT2 -ucm_closeTable(UCMTable *table) { - if(table!=NULL) { - uprv_free(table->mappings); - uprv_free(table->codePoints); - uprv_free(table->bytes); - uprv_free(table->reverseMap); - uprv_free(table); - } -} - -U_CAPI void U_EXPORT2 -ucm_resetTable(UCMTable *table) { - if(table!=NULL) { - table->mappingsLength=0; - table->flagsType=0; - table->unicodeMask=0; - table->bytesLength=table->codePointsLength=0; - table->isSorted=FALSE; - } -} - -U_CAPI void U_EXPORT2 -ucm_addMapping(UCMTable *table, - UCMapping *m, - UChar32 codePoints[UCNV_EXT_MAX_UCHARS], - uint8_t bytes[UCNV_EXT_MAX_BYTES]) { - UCMapping *tm; - UChar32 c; - int32_t idx; - - if(table->mappingsLength>=table->mappingsCapacity) { - /* make the mappings array larger */ - if(table->mappingsCapacity==0) { - table->mappingsCapacity=1000; - } else { - table->mappingsCapacity*=10; - } - table->mappings=(UCMapping *)uprv_realloc(table->mappings, - table->mappingsCapacity*sizeof(UCMapping)); - if(table->mappings==NULL) { - fprintf(stderr, "ucm error: unable to allocate %d UCMappings\n", - (int)table->mappingsCapacity); - exit(U_MEMORY_ALLOCATION_ERROR); - } - - if(table->reverseMap!=NULL) { - /* the reverseMap must be reallocated in a new sort */ - uprv_free(table->reverseMap); - table->reverseMap=NULL; - } - } - - if(m->uLen>1 && table->codePointsCapacity==0) { - table->codePointsCapacity=10000; - table->codePoints=(UChar32 *)uprv_malloc(table->codePointsCapacity*4); - if(table->codePoints==NULL) { - fprintf(stderr, "ucm error: unable to allocate %d UChar32s\n", - (int)table->codePointsCapacity); - exit(U_MEMORY_ALLOCATION_ERROR); - } - } - - if(m->bLen>4 && table->bytesCapacity==0) { - table->bytesCapacity=10000; - table->bytes=(uint8_t *)uprv_malloc(table->bytesCapacity); - if(table->bytes==NULL) { - fprintf(stderr, "ucm error: unable to allocate %d bytes\n", - (int)table->bytesCapacity); - exit(U_MEMORY_ALLOCATION_ERROR); - } - } - - if(m->uLen>1) { - idx=table->codePointsLength; - table->codePointsLength+=m->uLen; - if(table->codePointsLength>table->codePointsCapacity) { - fprintf(stderr, "ucm error: too many code points in multiple-code point mappings\n"); - exit(U_MEMORY_ALLOCATION_ERROR); - } - - uprv_memcpy(table->codePoints+idx, codePoints, (size_t)m->uLen*4); - m->u=idx; - } - - if(m->bLen>4) { - idx=table->bytesLength; - table->bytesLength+=m->bLen; - if(table->bytesLength>table->bytesCapacity) { - fprintf(stderr, "ucm error: too many bytes in mappings with >4 charset bytes\n"); - exit(U_MEMORY_ALLOCATION_ERROR); - } - - uprv_memcpy(table->bytes+idx, bytes, m->bLen); - m->b.idx=idx; - } - - /* set unicodeMask */ - for(idx=0; idx<m->uLen; ++idx) { - c=codePoints[idx]; - if(c>=0x10000) { - table->unicodeMask|=UCNV_HAS_SUPPLEMENTARY; /* there are supplementary code points */ - } else if(U_IS_SURROGATE(c)) { - table->unicodeMask|=UCNV_HAS_SURROGATES; /* there are surrogate code points */ - } - } - - /* set flagsType */ - if(m->f<0) { - table->flagsType|=UCM_FLAGS_IMPLICIT; - } else { - table->flagsType|=UCM_FLAGS_EXPLICIT; - } - - tm=table->mappings+table->mappingsLength++; - uprv_memcpy(tm, m, sizeof(UCMapping)); - - table->isSorted=FALSE; -} - -U_CAPI UCMFile * U_EXPORT2 -ucm_open() { - UCMFile *ucm=(UCMFile *)uprv_malloc(sizeof(UCMFile)); - if(ucm==NULL) { - fprintf(stderr, "ucm error: unable to allocate a UCMFile\n"); - exit(U_MEMORY_ALLOCATION_ERROR); - } - - memset(ucm, 0, sizeof(UCMFile)); - - ucm->base=ucm_openTable(); - ucm->ext=ucm_openTable(); - - ucm->states.stateFlags[0]=MBCS_STATE_FLAG_DIRECT; - ucm->states.conversionType=UCNV_UNSUPPORTED_CONVERTER; - ucm->states.outputType=-1; - ucm->states.minCharLength=ucm->states.maxCharLength=1; - - return ucm; -} - -U_CAPI void U_EXPORT2 -ucm_close(UCMFile *ucm) { - if(ucm!=NULL) { - ucm_closeTable(ucm->base); - ucm_closeTable(ucm->ext); - uprv_free(ucm); - } -} - -U_CAPI int32_t U_EXPORT2 -ucm_mappingType(UCMStates *baseStates, - UCMapping *m, - UChar32 codePoints[UCNV_EXT_MAX_UCHARS], - uint8_t bytes[UCNV_EXT_MAX_BYTES]) { - (void)codePoints; - /* check validity of the bytes and count the characters in them */ - int32_t count=ucm_countChars(baseStates, bytes, m->bLen); - if(count<1) { - /* illegal byte sequence */ - return -1; - } - - /* - * Suitable for an ICU conversion base table means: - * - a 1:1 mapping (1 Unicode code point : 1 byte sequence) - * - precision flag 0..3 - * - SBCS: any 1:1 mapping - * (the table stores additional bits to distinguish mapping types) - * - MBCS: not a |2 SUB mapping for <subchar1> - * - MBCS: not a |1 fallback to 0x00 - * - MBCS: not a multi-byte mapping with leading 0x00 bytes - * - * Further restrictions for fromUnicode tables - * are enforced in makeconv (MBCSOkForBaseFromUnicode()). - * - * All of the MBCS fromUnicode specific tests could be removed from here, - * but the ones above are for unusual mappings, and removing the tests - * from here would change canonucm output which seems gratuitous. - * (Markus Scherer 2006-nov-28) - * - * Exception: All implicit mappings (f<0) that need to be moved - * because of fromUnicode restrictions _must_ be moved here because - * makeconv uses a hack for moving mappings only for the fromUnicode table - * that only works with non-negative values of f. - */ - if( m->uLen==1 && count==1 && m->f<=3 && - (baseStates->maxCharLength==1 || - !((m->f==2 && m->bLen==1) || - (m->f==1 && bytes[0]==0) || - (m->f<=1 && m->bLen>1 && bytes[0]==0))) - ) { - return 0; /* suitable for a base table */ - } else { - return 1; /* needs to go into an extension table */ - } -} - -U_CAPI UBool U_EXPORT2 -ucm_addMappingAuto(UCMFile *ucm, UBool forBase, UCMStates *baseStates, - UCMapping *m, - UChar32 codePoints[UCNV_EXT_MAX_UCHARS], - uint8_t bytes[UCNV_EXT_MAX_BYTES]) { - int32_t type; - - if(m->f==2 && m->uLen>1) { - fprintf(stderr, "ucm error: illegal <subchar1> |2 mapping from multiple code points\n"); - printMapping(m, codePoints, bytes, stderr); - return FALSE; - } - - if(baseStates!=NULL) { - /* check validity of the bytes and count the characters in them */ - type=ucm_mappingType(baseStates, m, codePoints, bytes); - if(type<0) { - /* illegal byte sequence */ - printMapping(m, codePoints, bytes, stderr); - return FALSE; - } - } else { - /* not used - adding a mapping for an extension-only table before its base table is read */ - type=1; - } - - /* - * Add the mapping to the base table if this is requested and suitable. - * Otherwise, add it to the extension table. - */ - if(forBase && type==0) { - ucm_addMapping(ucm->base, m, codePoints, bytes); - } else { - ucm_addMapping(ucm->ext, m, codePoints, bytes); - } - - return TRUE; -} - -U_CAPI UBool U_EXPORT2 -ucm_addMappingFromLine(UCMFile *ucm, const char *line, UBool forBase, UCMStates *baseStates) { - UCMapping m={ 0, {0}, 0, 0, 0, 0 }; - UChar32 codePoints[UCNV_EXT_MAX_UCHARS]; - uint8_t bytes[UCNV_EXT_MAX_BYTES]; - - const char *s; - - /* ignore empty and comment lines */ - if(line[0]=='#' || *(s=u_skipWhitespace(line))==0 || *s=='\n' || *s=='\r') { - return TRUE; - } - - return - ucm_parseMappingLine(&m, codePoints, bytes, line) && - ucm_addMappingAuto(ucm, forBase, baseStates, &m, codePoints, bytes); -} - -U_CAPI void U_EXPORT2 -ucm_readTable(UCMFile *ucm, FileStream* convFile, - UBool forBase, UCMStates *baseStates, - UErrorCode *pErrorCode) { - char line[500]; - char *end; - UBool isOK; - - if(U_FAILURE(*pErrorCode)) { - return; - } - - isOK=TRUE; - - for(;;) { - /* read the next line */ - if(!T_FileStream_readLine(convFile, line, sizeof(line))) { - fprintf(stderr, "incomplete charmap section\n"); - isOK=FALSE; - break; - } - - /* remove CR LF */ - end=uprv_strchr(line, 0); - while(line<end && (*(end-1)=='\r' || *(end-1)=='\n')) { - --end; - } - *end=0; - - /* ignore empty and comment lines */ - if(line[0]==0 || line[0]=='#') { - continue; - } - - /* stop at the end of the mapping table */ - if(0==uprv_strcmp(line, "END CHARMAP")) { - break; - } - - isOK&=ucm_addMappingFromLine(ucm, line, forBase, baseStates); - } - - if(!isOK) { - *pErrorCode=U_INVALID_TABLE_FORMAT; - } -} -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/ucm.h b/deps/node/deps/icu-small/source/tools/toolutil/ucm.h deleted file mode 100644 index 3af93975..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/ucm.h +++ /dev/null @@ -1,301 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* - ******************************************************************************* - * Copyright (C) 2003-2013, International Business Machines - * Corporation and others. All Rights Reserved. - ******************************************************************************* - * file name: ucm.h - * encoding: UTF-8 - * tab size: 8 (not used) - * indentation:4 - * - * created on: 2003jun20 - * created by: Markus W. Scherer - * - * Definitions for the .ucm file parser and handler module ucm.c. - */ - -#ifndef __UCM_H__ -#define __UCM_H__ - -#include "unicode/utypes.h" -#include "ucnvmbcs.h" -#include "ucnv_ext.h" -#include "filestrm.h" -#include <stdio.h> - -#if !UCONFIG_NO_CONVERSION - -U_CDECL_BEGIN - -/* constants for UCMapping.moveFlag */ -enum { - UCM_MOVE_TO_EXT=1, - UCM_REMOVE_MAPPING=2 -}; - -/* - * Per-mapping data structure - * - * u if uLen==1: Unicode code point - * else index to uLen code points - * b if bLen<=4: up to 4 bytes - * else index to bLen bytes - * uLen number of code points - * bLen number of words containing left-justified bytes - * bIsMultipleChars indicates that the bytes contain more than one sequence - * according to the state table - * f flag for roundtrip (0), fallback (1), sub mapping (2), reverse fallback (3) - * or "good one-way" mapping (4). - * Same values as in the source file after | - */ -typedef struct UCMapping { - UChar32 u; - union { - uint32_t idx; - uint8_t bytes[4]; - } b; - int8_t uLen, bLen, f, moveFlag; -} UCMapping; - -/* constants for UCMTable.flagsType */ -enum { - UCM_FLAGS_INITIAL, /* no mappings parsed yet */ - UCM_FLAGS_EXPLICIT, /* .ucm file has mappings with | fallback indicators */ - UCM_FLAGS_IMPLICIT, /* .ucm file has mappings without | fallback indicators, later wins */ - UCM_FLAGS_MIXED /* both implicit and explicit */ -}; - -typedef struct UCMTable { - UCMapping *mappings; - int32_t mappingsCapacity, mappingsLength; - - UChar32 *codePoints; - int32_t codePointsCapacity, codePointsLength; - - uint8_t *bytes; - int32_t bytesCapacity, bytesLength; - - /* index map for mapping by bytes first */ - int32_t *reverseMap; - - uint8_t unicodeMask; - int8_t flagsType; /* UCM_FLAGS_INITIAL etc. */ - UBool isSorted; -} UCMTable; - -enum { - MBCS_STATE_FLAG_DIRECT=1, - MBCS_STATE_FLAG_SURROGATES, - - MBCS_STATE_FLAG_READY=16 -}; - -typedef struct UCMStates { - int32_t stateTable[MBCS_MAX_STATE_COUNT][256]; - uint32_t stateFlags[MBCS_MAX_STATE_COUNT], - stateOffsetSum[MBCS_MAX_STATE_COUNT]; - - int32_t countStates, minCharLength, maxCharLength, countToUCodeUnits; - int8_t conversionType, outputType; -} UCMStates; - -typedef struct UCMFile { - UCMTable *base, *ext; - UCMStates states; - - char baseName[UCNV_MAX_CONVERTER_NAME_LENGTH]; -} UCMFile; - -/* simple accesses ---------------------------------------------------------- */ - -#define UCM_GET_CODE_POINTS(t, m) \ - (((m)->uLen==1) ? &(m)->u : (t)->codePoints+(m)->u) - -#define UCM_GET_BYTES(t, m) \ - (((m)->bLen<=4) ? (m)->b.bytes : (t)->bytes+(m)->b.idx) - -/* APIs --------------------------------------------------------------------- */ - -U_CAPI UCMFile * U_EXPORT2 -ucm_open(void); - -U_CAPI void U_EXPORT2 -ucm_close(UCMFile *ucm); - -U_CAPI UBool U_EXPORT2 -ucm_parseHeaderLine(UCMFile *ucm, - char *line, char **pKey, char **pValue); - -/* @return -1 illegal bytes 0 suitable for base table 1 needs to go into extension table */ -U_CAPI int32_t U_EXPORT2 -ucm_mappingType(UCMStates *baseStates, - UCMapping *m, - UChar32 codePoints[UCNV_EXT_MAX_UCHARS], - uint8_t bytes[UCNV_EXT_MAX_BYTES]); - -/* add a mapping to the base or extension table as appropriate */ -U_CAPI UBool U_EXPORT2 -ucm_addMappingAuto(UCMFile *ucm, UBool forBase, UCMStates *baseStates, - UCMapping *m, - UChar32 codePoints[UCNV_EXT_MAX_UCHARS], - uint8_t bytes[UCNV_EXT_MAX_BYTES]); - -U_CAPI UBool U_EXPORT2 -ucm_addMappingFromLine(UCMFile *ucm, const char *line, UBool forBase, UCMStates *baseStates); - - -U_CAPI UCMTable * U_EXPORT2 -ucm_openTable(void); - -U_CAPI void U_EXPORT2 -ucm_closeTable(UCMTable *table); - -U_CAPI void U_EXPORT2 -ucm_resetTable(UCMTable *table); - -U_CAPI void U_EXPORT2 -ucm_sortTable(UCMTable *t); - -/* - * Remove mappings with their move flag set from the base table - * and move some of them (with UCM_MOVE_TO_EXT) to the extension table. - */ -U_CAPI void U_EXPORT2 -ucm_moveMappings(UCMTable *base, UCMTable *ext); - -/** - * Read a table from a .ucm file, from after the CHARMAP line to - * including the END CHARMAP line. - */ -U_CAPI void U_EXPORT2 -ucm_readTable(UCMFile *ucm, FileStream* convFile, - UBool forBase, UCMStates *baseStates, - UErrorCode *pErrorCode); - -/** - * Check the validity of mappings against a base table's states; - * necessary for extension-only tables that were read before their base tables. - */ -U_CAPI UBool U_EXPORT2 -ucm_checkValidity(UCMTable *ext, UCMStates *baseStates); - -/** - * Check a base table against an extension table. - * Set the moveTarget!=NULL if it is possible to move mappings from the base. - * This is the case where base and extension tables are parsed from a single file - * (moveTarget==ext) - * or when delta file mappings are subtracted from a base table. - * - * When a base table cannot be modified because a delta file is parsed in makeconv, - * then set moveTarget=NULL. - * - * if(intersectBase) then mappings that exist in the base table but not in - * the extension table are moved to moveTarget instead of showing an error. - * - * Special mode: - * If intersectBase==2 for a DBCS extension table, then SBCS mappings are - * not moved out of the base unless their Unicode input requires it. - * This helps ucmkbase generate base tables for DBCS-only extension .cnv files. - * - * For both tables in the same file, the extension table is automatically - * built. - * For separate files, the extension file can use a complete mapping table (.ucm file), - * so that common mappings need not be stripped out manually. - * - * - * Sort both tables, and then for each mapping direction: - * - * If intersectBase is TRUE and the base table contains a mapping - * that does not exist in the extension table, then this mapping is moved - * to moveTarget. - * - * - otherwise - - * - * If the base table contains a mapping for which the input sequence is - * the same as the extension input, then - * - if the output is the same: remove the extension mapping - * - else: error - * - * If the base table contains a mapping for which the input sequence is - * a prefix of the extension input, then - * - if moveTarget!=NULL: move the base mapping to the moveTarget table - * - else: error - * - * @return FALSE in case of an irreparable error - */ -U_CAPI UBool U_EXPORT2 -ucm_checkBaseExt(UCMStates *baseStates, UCMTable *base, UCMTable *ext, - UCMTable *moveTarget, UBool intersectBase); - -U_CAPI void U_EXPORT2 -ucm_printTable(UCMTable *table, FILE *f, UBool byUnicode); - -U_CAPI void U_EXPORT2 -ucm_printMapping(UCMTable *table, UCMapping *m, FILE *f); - - -U_CAPI void U_EXPORT2 -ucm_addState(UCMStates *states, const char *s); - -U_CAPI void U_EXPORT2 -ucm_processStates(UCMStates *states, UBool ignoreSISOCheck); - -U_CAPI int32_t U_EXPORT2 -ucm_countChars(UCMStates *states, - const uint8_t *bytes, int32_t length); - - -U_CAPI int8_t U_EXPORT2 -ucm_parseBytes(uint8_t bytes[UCNV_EXT_MAX_BYTES], const char *line, const char **ps); - -U_CAPI UBool U_EXPORT2 -ucm_parseMappingLine(UCMapping *m, - UChar32 codePoints[UCNV_EXT_MAX_UCHARS], - uint8_t bytes[UCNV_EXT_MAX_BYTES], - const char *line); - -U_CAPI void U_EXPORT2 -ucm_addMapping(UCMTable *table, - UCMapping *m, - UChar32 codePoints[UCNV_EXT_MAX_UCHARS], - uint8_t bytes[UCNV_EXT_MAX_BYTES]); - -/* very makeconv-specific functions ----------------------------------------- */ - -/* finalize and optimize states after the toUnicode mappings are processed */ -U_CAPI void U_EXPORT2 -ucm_optimizeStates(UCMStates *states, - uint16_t **pUnicodeCodeUnits, - _MBCSToUFallback *toUFallbacks, int32_t countToUFallbacks, - UBool verbose); - -/* moved here because it is used inside ucmstate.c */ -U_CAPI int32_t U_EXPORT2 -ucm_findFallback(_MBCSToUFallback *toUFallbacks, int32_t countToUFallbacks, - uint32_t offset); - -/* very rptp2ucm-specific functions ----------------------------------------- */ - -/* - * Input: Separate tables with mappings from/to Unicode, - * subchar and subchar1 (0 if none). - * All mappings must have flag 0. - * - * Output: fromUTable will contain the union of mappings with the correct - * precision flags, and be sorted. - */ -U_CAPI void U_EXPORT2 -ucm_mergeTables(UCMTable *fromUTable, UCMTable *toUTable, - const uint8_t *subchar, int32_t subcharLength, - uint8_t subchar1); - -U_CAPI UBool U_EXPORT2 -ucm_separateMappings(UCMFile *ucm, UBool isSISO); - -U_CDECL_END - -#endif - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/ucmstate.cpp b/deps/node/deps/icu-small/source/tools/toolutil/ucmstate.cpp deleted file mode 100644 index 27765752..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/ucmstate.cpp +++ /dev/null @@ -1,1051 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2003-2012, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: ucmstate.c -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2003oct09 -* created by: Markus W. Scherer -* -* This file handles ICU .ucm file state information as part of the ucm module. -* Most of this code used to be in makeconv.c. -*/ - -#include "unicode/utypes.h" -#include "cstring.h" -#include "cmemory.h" -#include "uarrsort.h" -#include "ucnvmbcs.h" -#include "ucnv_ext.h" -#include "uparse.h" -#include "ucm.h" -#include <stdio.h> - -#if !UCONFIG_NO_CONVERSION - -/* MBCS state handling ------------------------------------------------------ */ - -/* - * state table row grammar (ebnf-style): - * (whitespace is allowed between all tokens) - * - * row=[[firstentry ','] entry (',' entry)*] - * firstentry="initial" | "surrogates" - * (initial state (default for state 0), output is all surrogate pairs) - * entry=range [':' nextstate] ['.' action] - * range=number ['-' number] - * nextstate=number - * (0..7f) - * action='u' | 's' | 'p' | 'i' - * (unassigned, state change only, surrogate pair, illegal) - * number=(1- or 2-digit hexadecimal number) - */ -static const char * -parseState(const char *s, int32_t state[256], uint32_t *pFlags) { - const char *t; - uint32_t start, end, i; - int32_t entry; - - /* initialize the state: all illegal with U+ffff */ - for(i=0; i<256; ++i) { - state[i]=MBCS_ENTRY_FINAL(0, MBCS_STATE_ILLEGAL, 0xffff); - } - - /* skip leading white space */ - s=u_skipWhitespace(s); - - /* is there an "initial" or "surrogates" directive? */ - if(uprv_strncmp("initial", s, 7)==0) { - *pFlags=MBCS_STATE_FLAG_DIRECT; - s=u_skipWhitespace(s+7); - if(*s++!=',') { - return s-1; - } - } else if(*pFlags==0 && uprv_strncmp("surrogates", s, 10)==0) { - *pFlags=MBCS_STATE_FLAG_SURROGATES; - s=u_skipWhitespace(s+10); - if(*s++!=',') { - return s-1; - } - } else if(*s==0) { - /* empty state row: all-illegal */ - return NULL; - } - - for(;;) { - /* read an entry, the start of the range first */ - s=u_skipWhitespace(s); - start=uprv_strtoul(s, (char **)&t, 16); - if(s==t || 0xff<start) { - return s; - } - s=u_skipWhitespace(t); - - /* read the end of the range if there is one */ - if(*s=='-') { - s=u_skipWhitespace(s+1); - end=uprv_strtoul(s, (char **)&t, 16); - if(s==t || end<start || 0xff<end) { - return s; - } - s=u_skipWhitespace(t); - } else { - end=start; - } - - /* determine the state entrys for this range */ - if(*s!=':' && *s!='.') { - /* the default is: final state with valid entries */ - entry=MBCS_ENTRY_FINAL(0, MBCS_STATE_VALID_16, 0); - } else { - entry=MBCS_ENTRY_TRANSITION(0, 0); - if(*s==':') { - /* get the next state, default to 0 */ - s=u_skipWhitespace(s+1); - i=uprv_strtoul(s, (char **)&t, 16); - if(s!=t) { - if(0x7f<i) { - return s; - } - s=u_skipWhitespace(t); - entry=MBCS_ENTRY_SET_STATE(entry, i); - } - } - - /* get the state action, default to valid */ - if(*s=='.') { - /* this is a final state */ - entry=MBCS_ENTRY_SET_FINAL(entry); - - s=u_skipWhitespace(s+1); - if(*s=='u') { - /* unassigned set U+fffe */ - entry=MBCS_ENTRY_FINAL_SET_ACTION_VALUE(entry, MBCS_STATE_UNASSIGNED, 0xfffe); - s=u_skipWhitespace(s+1); - } else if(*s=='p') { - if(*pFlags!=MBCS_STATE_FLAG_DIRECT) { - entry=MBCS_ENTRY_FINAL_SET_ACTION(entry, MBCS_STATE_VALID_16_PAIR); - } else { - entry=MBCS_ENTRY_FINAL_SET_ACTION(entry, MBCS_STATE_VALID_16); - } - s=u_skipWhitespace(s+1); - } else if(*s=='s') { - entry=MBCS_ENTRY_FINAL_SET_ACTION(entry, MBCS_STATE_CHANGE_ONLY); - s=u_skipWhitespace(s+1); - } else if(*s=='i') { - /* illegal set U+ffff */ - entry=MBCS_ENTRY_FINAL_SET_ACTION_VALUE(entry, MBCS_STATE_ILLEGAL, 0xffff); - s=u_skipWhitespace(s+1); - } else { - /* default to valid */ - entry=MBCS_ENTRY_FINAL_SET_ACTION(entry, MBCS_STATE_VALID_16); - } - } else { - /* this is an intermediate state, nothing to do */ - } - } - - /* adjust "final valid" states according to the state flags */ - if(MBCS_ENTRY_FINAL_ACTION(entry)==MBCS_STATE_VALID_16) { - switch(*pFlags) { - case 0: - /* no adjustment */ - break; - case MBCS_STATE_FLAG_DIRECT: - /* set the valid-direct code point to "unassigned"==0xfffe */ - entry=MBCS_ENTRY_FINAL_SET_ACTION_VALUE(entry, MBCS_STATE_VALID_DIRECT_16, 0xfffe); - break; - case MBCS_STATE_FLAG_SURROGATES: - entry=MBCS_ENTRY_FINAL_SET_ACTION_VALUE(entry, MBCS_STATE_VALID_16_PAIR, 0); - break; - default: - break; - } - } - - /* set this entry for the range */ - for(i=start; i<=end; ++i) { - state[i]=entry; - } - - if(*s==',') { - ++s; - } else { - return *s==0 ? NULL : s; - } - } -} - -U_CAPI void U_EXPORT2 -ucm_addState(UCMStates *states, const char *s) { - const char *error; - - if(states->countStates==MBCS_MAX_STATE_COUNT) { - fprintf(stderr, "ucm error: too many states (maximum %u)\n", MBCS_MAX_STATE_COUNT); - exit(U_INVALID_TABLE_FORMAT); - } - - error=parseState(s, states->stateTable[states->countStates], - &states->stateFlags[states->countStates]); - if(error!=NULL) { - fprintf(stderr, "ucm error: parse error in state definition at '%s'\n", error); - exit(U_INVALID_TABLE_FORMAT); - } - - ++states->countStates; -} - -U_CAPI UBool U_EXPORT2 -ucm_parseHeaderLine(UCMFile *ucm, - char *line, char **pKey, char **pValue) { - UCMStates *states; - char *s, *end; - char c; - - states=&ucm->states; - - /* remove comments and trailing CR and LF and remove whitespace from the end */ - for(end=line; (c=*end)!=0; ++end) { - if(c=='#' || c=='\r' || c=='\n') { - break; - } - } - while(end>line && (*(end-1)==' ' || *(end-1)=='\t')) { - --end; - } - *end=0; - - /* skip leading white space and ignore empty lines */ - s=(char *)u_skipWhitespace(line); - if(*s==0) { - return TRUE; - } - - /* stop at the beginning of the mapping section */ - if(uprv_memcmp(s, "CHARMAP", 7)==0) { - return FALSE; - } - - /* get the key name, bracketed in <> */ - if(*s!='<') { - fprintf(stderr, "ucm error: no header field <key> in line \"%s\"\n", line); - exit(U_INVALID_TABLE_FORMAT); - } - *pKey=++s; - while(*s!='>') { - if(*s==0) { - fprintf(stderr, "ucm error: incomplete header field <key> in line \"%s\"\n", line); - exit(U_INVALID_TABLE_FORMAT); - } - ++s; - } - *s=0; - - /* get the value string, possibly quoted */ - s=(char *)u_skipWhitespace(s+1); - if(*s!='"') { - *pValue=s; - } else { - /* remove the quotes */ - *pValue=s+1; - if(end>*pValue && *(end-1)=='"') { - *--end=0; - } - } - - /* collect the information from the header field, ignore unknown keys */ - if(uprv_strcmp(*pKey, "uconv_class")==0) { - if(uprv_strcmp(*pValue, "DBCS")==0) { - states->conversionType=UCNV_DBCS; - } else if(uprv_strcmp(*pValue, "SBCS")==0) { - states->conversionType = UCNV_SBCS; - } else if(uprv_strcmp(*pValue, "MBCS")==0) { - states->conversionType = UCNV_MBCS; - } else if(uprv_strcmp(*pValue, "EBCDIC_STATEFUL")==0) { - states->conversionType = UCNV_EBCDIC_STATEFUL; - } else { - fprintf(stderr, "ucm error: unknown <uconv_class> %s\n", *pValue); - exit(U_INVALID_TABLE_FORMAT); - } - return TRUE; - } else if(uprv_strcmp(*pKey, "mb_cur_max")==0) { - c=**pValue; - if('1'<=c && c<='4' && (*pValue)[1]==0) { - states->maxCharLength=(int8_t)(c-'0'); - states->outputType=(int8_t)(states->maxCharLength-1); - } else { - fprintf(stderr, "ucm error: illegal <mb_cur_max> %s\n", *pValue); - exit(U_INVALID_TABLE_FORMAT); - } - return TRUE; - } else if(uprv_strcmp(*pKey, "mb_cur_min")==0) { - c=**pValue; - if('1'<=c && c<='4' && (*pValue)[1]==0) { - states->minCharLength=(int8_t)(c-'0'); - } else { - fprintf(stderr, "ucm error: illegal <mb_cur_min> %s\n", *pValue); - exit(U_INVALID_TABLE_FORMAT); - } - return TRUE; - } else if(uprv_strcmp(*pKey, "icu:state")==0) { - /* if an SBCS/DBCS/EBCDIC_STATEFUL converter has icu:state, then turn it into MBCS */ - switch(states->conversionType) { - case UCNV_SBCS: - case UCNV_DBCS: - case UCNV_EBCDIC_STATEFUL: - states->conversionType=UCNV_MBCS; - break; - case UCNV_MBCS: - break; - default: - fprintf(stderr, "ucm error: <icu:state> entry for non-MBCS table or before the <uconv_class> line\n"); - exit(U_INVALID_TABLE_FORMAT); - } - - if(states->maxCharLength==0) { - fprintf(stderr, "ucm error: <icu:state> before the <mb_cur_max> line\n"); - exit(U_INVALID_TABLE_FORMAT); - } - ucm_addState(states, *pValue); - return TRUE; - } else if(uprv_strcmp(*pKey, "icu:base")==0) { - if(**pValue==0) { - fprintf(stderr, "ucm error: <icu:base> without a base table name\n"); - exit(U_INVALID_TABLE_FORMAT); - } - uprv_strcpy(ucm->baseName, *pValue); - return TRUE; - } - - return FALSE; -} - -/* post-processing ---------------------------------------------------------- */ - -static int32_t -sumUpStates(UCMStates *states) { - int32_t entry, sum, state, cell, count; - UBool allStatesReady; - - /* - * Sum up the offsets for all states. - * In each final state (where there are only final entries), - * the offsets add up directly. - * In all other state table rows, for each transition entry to another state, - * the offsets sum of that state needs to be added. - * This is achieved in at most countStates iterations. - */ - allStatesReady=FALSE; - for(count=states->countStates; !allStatesReady && count>=0; --count) { - allStatesReady=TRUE; - for(state=states->countStates-1; state>=0; --state) { - if(!(states->stateFlags[state]&MBCS_STATE_FLAG_READY)) { - allStatesReady=FALSE; - sum=0; - - /* at first, add up only the final delta offsets to keep them <512 */ - for(cell=0; cell<256; ++cell) { - entry=states->stateTable[state][cell]; - if(MBCS_ENTRY_IS_FINAL(entry)) { - switch(MBCS_ENTRY_FINAL_ACTION(entry)) { - case MBCS_STATE_VALID_16: - states->stateTable[state][cell]=MBCS_ENTRY_FINAL_SET_VALUE(entry, sum); - sum+=1; - break; - case MBCS_STATE_VALID_16_PAIR: - states->stateTable[state][cell]=MBCS_ENTRY_FINAL_SET_VALUE(entry, sum); - sum+=2; - break; - default: - /* no addition */ - break; - } - } - } - - /* now, add up the delta offsets for the transitional entries */ - for(cell=0; cell<256; ++cell) { - entry=states->stateTable[state][cell]; - if(MBCS_ENTRY_IS_TRANSITION(entry)) { - if(states->stateFlags[MBCS_ENTRY_TRANSITION_STATE(entry)]&MBCS_STATE_FLAG_READY) { - states->stateTable[state][cell]=MBCS_ENTRY_TRANSITION_SET_OFFSET(entry, sum); - sum+=states->stateOffsetSum[MBCS_ENTRY_TRANSITION_STATE(entry)]; - } else { - /* that next state does not have a sum yet, we cannot finish the one for this state */ - sum=-1; - break; - } - } - } - - if(sum!=-1) { - states->stateOffsetSum[state]=sum; - states->stateFlags[state]|=MBCS_STATE_FLAG_READY; - } - } - } - } - - if(!allStatesReady) { - fprintf(stderr, "ucm error: the state table contains loops\n"); - exit(U_INVALID_TABLE_FORMAT); - } - - /* - * For all "direct" (i.e., initial) states>0, - * the offsets need to be increased by the sum of - * the previous initial states. - */ - sum=states->stateOffsetSum[0]; - for(state=1; state<states->countStates; ++state) { - if((states->stateFlags[state]&0xf)==MBCS_STATE_FLAG_DIRECT) { - int32_t sum2=sum; - sum+=states->stateOffsetSum[state]; - for(cell=0; cell<256; ++cell) { - entry=states->stateTable[state][cell]; - if(MBCS_ENTRY_IS_TRANSITION(entry)) { - states->stateTable[state][cell]=MBCS_ENTRY_TRANSITION_ADD_OFFSET(entry, sum2); - } - } - } - } - - /* round up to the next even number to have the following data 32-bit-aligned */ - return states->countToUCodeUnits=(sum+1)&~1; -} - -U_CAPI void U_EXPORT2 -ucm_processStates(UCMStates *states, UBool ignoreSISOCheck) { - int32_t entry, state, cell, count; - - if(states->conversionType==UCNV_UNSUPPORTED_CONVERTER) { - fprintf(stderr, "ucm error: missing conversion type (<uconv_class>)\n"); - exit(U_INVALID_TABLE_FORMAT); - } - - if(states->countStates==0) { - switch(states->conversionType) { - case UCNV_SBCS: - /* SBCS: use MBCS data structure with a default state table */ - if(states->maxCharLength!=1) { - fprintf(stderr, "error: SBCS codepage with max B/char!=1\n"); - exit(U_INVALID_TABLE_FORMAT); - } - states->conversionType=UCNV_MBCS; - ucm_addState(states, "0-ff"); - break; - case UCNV_MBCS: - fprintf(stderr, "ucm error: missing state table information (<icu:state>) for MBCS\n"); - exit(U_INVALID_TABLE_FORMAT); - break; - case UCNV_EBCDIC_STATEFUL: - /* EBCDIC_STATEFUL: use MBCS data structure with a default state table */ - if(states->minCharLength!=1 || states->maxCharLength!=2) { - fprintf(stderr, "error: DBCS codepage with min B/char!=1 or max B/char!=2\n"); - exit(U_INVALID_TABLE_FORMAT); - } - states->conversionType=UCNV_MBCS; - ucm_addState(states, "0-ff, e:1.s, f:0.s"); - ucm_addState(states, "initial, 0-3f:4, e:1.s, f:0.s, 40:3, 41-fe:2, ff:4"); - ucm_addState(states, "0-40:1.i, 41-fe:1., ff:1.i"); - ucm_addState(states, "0-ff:1.i, 40:1."); - ucm_addState(states, "0-ff:1.i"); - break; - case UCNV_DBCS: - /* DBCS: use MBCS data structure with a default state table */ - if(states->minCharLength!=2 || states->maxCharLength!=2) { - fprintf(stderr, "error: DBCS codepage with min or max B/char!=2\n"); - exit(U_INVALID_TABLE_FORMAT); - } - states->conversionType = UCNV_MBCS; - ucm_addState(states, "0-3f:3, 40:2, 41-fe:1, ff:3"); - ucm_addState(states, "41-fe"); - ucm_addState(states, "40"); - ucm_addState(states, ""); - break; - default: - fprintf(stderr, "ucm error: unknown charset structure\n"); - exit(U_INVALID_TABLE_FORMAT); - break; - } - } - - /* - * check that the min/max character lengths are reasonable; - * to do this right, all paths through the state table would have to be - * recursively walked while keeping track of the sequence lengths, - * but these simple checks cover most state tables in practice - */ - if(states->maxCharLength<states->minCharLength) { - fprintf(stderr, "ucm error: max B/char < min B/char\n"); - exit(U_INVALID_TABLE_FORMAT); - } - - /* count non-direct states and compare with max B/char */ - count=0; - for(state=0; state<states->countStates; ++state) { - if((states->stateFlags[state]&0xf)!=MBCS_STATE_FLAG_DIRECT) { - ++count; - } - } - if(states->maxCharLength>count+1) { - fprintf(stderr, "ucm error: max B/char too large\n"); - exit(U_INVALID_TABLE_FORMAT); - } - - if(states->minCharLength==1) { - int32_t action; - - /* - * if there are single-byte characters, - * then the initial state must have direct result states - */ - for(cell=0; cell<256; ++cell) { - entry=states->stateTable[0][cell]; - if( MBCS_ENTRY_IS_FINAL(entry) && - ((action=MBCS_ENTRY_FINAL_ACTION(entry))==MBCS_STATE_VALID_DIRECT_16 || - action==MBCS_STATE_UNASSIGNED) - ) { - break; - } - } - - if(cell==256) { - fprintf(stderr, "ucm warning: min B/char too small\n"); - } - } - - /* - * make sure that all "next state" values are within limits - * and that all next states after final ones have the "direct" - * flag of initial states - */ - for(state=states->countStates-1; state>=0; --state) { - for(cell=0; cell<256; ++cell) { - entry=states->stateTable[state][cell]; - if((uint8_t)MBCS_ENTRY_STATE(entry)>=states->countStates) { - fprintf(stderr, "ucm error: state table entry [%x][%x] has a next state of %x that is too high\n", - (int)state, (int)cell, (int)MBCS_ENTRY_STATE(entry)); - exit(U_INVALID_TABLE_FORMAT); - } - if(MBCS_ENTRY_IS_FINAL(entry) && (states->stateFlags[MBCS_ENTRY_STATE(entry)]&0xf)!=MBCS_STATE_FLAG_DIRECT) { - fprintf(stderr, "ucm error: state table entry [%x][%x] is final but has a non-initial next state of %x\n", - (int)state, (int)cell, (int)MBCS_ENTRY_STATE(entry)); - exit(U_INVALID_TABLE_FORMAT); - } else if(MBCS_ENTRY_IS_TRANSITION(entry) && (states->stateFlags[MBCS_ENTRY_STATE(entry)]&0xf)==MBCS_STATE_FLAG_DIRECT) { - fprintf(stderr, "ucm error: state table entry [%x][%x] is not final but has an initial next state of %x\n", - (int)state, (int)cell, (int)MBCS_ENTRY_STATE(entry)); - exit(U_INVALID_TABLE_FORMAT); - } - } - } - - /* is this an SI/SO (like EBCDIC-stateful) state table? */ - if(states->countStates>=2 && (states->stateFlags[1]&0xf)==MBCS_STATE_FLAG_DIRECT) { - if(states->maxCharLength!=2) { - fprintf(stderr, "ucm error: SI/SO codepages must have max 2 bytes/char (not %x)\n", (int)states->maxCharLength); - exit(U_INVALID_TABLE_FORMAT); - } - if(states->countStates<3) { - fprintf(stderr, "ucm error: SI/SO codepages must have at least 3 states (not %x)\n", (int)states->countStates); - exit(U_INVALID_TABLE_FORMAT); - } - /* are the SI/SO all in the right places? */ - if( ignoreSISOCheck || - (states->stateTable[0][0xe]==MBCS_ENTRY_FINAL(1, MBCS_STATE_CHANGE_ONLY, 0) && - states->stateTable[0][0xf]==MBCS_ENTRY_FINAL(0, MBCS_STATE_CHANGE_ONLY, 0) && - states->stateTable[1][0xe]==MBCS_ENTRY_FINAL(1, MBCS_STATE_CHANGE_ONLY, 0) && - states->stateTable[1][0xf]==MBCS_ENTRY_FINAL(0, MBCS_STATE_CHANGE_ONLY, 0)) - ) { - states->outputType=MBCS_OUTPUT_2_SISO; - } else { - fprintf(stderr, "ucm error: SI/SO codepages must have in states 0 and 1 transitions e:1.s, f:0.s\n"); - exit(U_INVALID_TABLE_FORMAT); - } - state=2; - } else { - state=1; - } - - /* check that no unexpected state is a "direct" one */ - while(state<states->countStates) { - if((states->stateFlags[state]&0xf)==MBCS_STATE_FLAG_DIRECT) { - fprintf(stderr, "ucm error: state %d is 'initial' - not supported except for SI/SO codepages\n", (int)state); - exit(U_INVALID_TABLE_FORMAT); - } - ++state; - } - - sumUpStates(states); -} - -/* find a fallback for this offset; return the index or -1 if not found */ -U_CAPI int32_t U_EXPORT2 -ucm_findFallback(_MBCSToUFallback *toUFallbacks, int32_t countToUFallbacks, - uint32_t offset) { - int32_t i; - - if(countToUFallbacks==0) { - /* shortcut: most codepages do not have fallbacks from codepage to Unicode */ - return -1; - } - - /* do a linear search for the fallback mapping (the table is not yet sorted) */ - for(i=0; i<countToUFallbacks; ++i) { - if(offset==toUFallbacks[i].offset) { - return i; - } - } - return -1; -} - -/* - * This function tries to compact toUnicode tables for 2-byte codepages - * by finding lead bytes with all-unassigned trail bytes and adding another state - * for them. - */ -static void -compactToUnicode2(UCMStates *states, - uint16_t **pUnicodeCodeUnits, - _MBCSToUFallback *toUFallbacks, int32_t countToUFallbacks, - UBool verbose) { - int32_t (*oldStateTable)[256]; - uint16_t count[256]; - uint16_t *oldUnicodeCodeUnits; - int32_t entry, offset, oldOffset, trailOffset, oldTrailOffset, savings, sum; - int32_t i, j, leadState, trailState, newState, fallback; - uint16_t unit; - - /* find the lead state */ - if(states->outputType==MBCS_OUTPUT_2_SISO) { - /* use the DBCS lead state for SI/SO codepages */ - leadState=1; - } else { - leadState=0; - } - - /* find the main trail state: the most used target state */ - uprv_memset(count, 0, sizeof(count)); - for(i=0; i<256; ++i) { - entry=states->stateTable[leadState][i]; - if(MBCS_ENTRY_IS_TRANSITION(entry)) { - ++count[MBCS_ENTRY_TRANSITION_STATE(entry)]; - } - } - trailState=0; - for(i=1; i<states->countStates; ++i) { - if(count[i]>count[trailState]) { - trailState=i; - } - } - - /* count possible savings from lead bytes with all-unassigned results in all trail bytes */ - uprv_memset(count, 0, sizeof(count)); - savings=0; - /* for each lead byte */ - for(i=0; i<256; ++i) { - entry=states->stateTable[leadState][i]; - if(MBCS_ENTRY_IS_TRANSITION(entry) && (MBCS_ENTRY_TRANSITION_STATE(entry))==trailState) { - /* the offset is different for each lead byte */ - offset=MBCS_ENTRY_TRANSITION_OFFSET(entry); - /* for each trail byte for this lead byte */ - for(j=0; j<256; ++j) { - entry=states->stateTable[trailState][j]; - switch(MBCS_ENTRY_FINAL_ACTION(entry)) { - case MBCS_STATE_VALID_16: - entry=offset+MBCS_ENTRY_FINAL_VALUE_16(entry); - if((*pUnicodeCodeUnits)[entry]==0xfffe && ucm_findFallback(toUFallbacks, countToUFallbacks, entry)<0) { - ++count[i]; - } else { - j=999; /* do not count for this lead byte because there are assignments */ - } - break; - case MBCS_STATE_VALID_16_PAIR: - entry=offset+MBCS_ENTRY_FINAL_VALUE_16(entry); - if((*pUnicodeCodeUnits)[entry]==0xfffe) { - count[i]+=2; - } else { - j=999; /* do not count for this lead byte because there are assignments */ - } - break; - default: - break; - } - } - if(j==256) { - /* all trail bytes for this lead byte are unassigned */ - savings+=count[i]; - } else { - count[i]=0; - } - } - } - /* subtract from the possible savings the cost of an additional state */ - savings=savings*2-1024; /* count bytes, not 16-bit words */ - if(savings<=0) { - return; - } - if(verbose) { - printf("compacting toUnicode data saves %ld bytes\n", (long)savings); - } - if(states->countStates>=MBCS_MAX_STATE_COUNT) { - fprintf(stderr, "cannot compact toUnicode because the maximum number of states is reached\n"); - return; - } - - /* make a copy of the state table */ - oldStateTable=(int32_t (*)[256])uprv_malloc(states->countStates*1024); - if(oldStateTable==NULL) { - fprintf(stderr, "cannot compact toUnicode: out of memory\n"); - return; - } - uprv_memcpy(oldStateTable, states->stateTable, states->countStates*1024); - - /* add the new state */ - /* - * this function does not catch the degenerate case where all lead bytes - * have all-unassigned trail bytes and the lead state could be removed - */ - newState=states->countStates++; - states->stateFlags[newState]=0; - /* copy the old trail state, turning all assigned states into unassigned ones */ - for(i=0; i<256; ++i) { - entry=states->stateTable[trailState][i]; - switch(MBCS_ENTRY_FINAL_ACTION(entry)) { - case MBCS_STATE_VALID_16: - case MBCS_STATE_VALID_16_PAIR: - states->stateTable[newState][i]=MBCS_ENTRY_FINAL_SET_ACTION_VALUE(entry, MBCS_STATE_UNASSIGNED, 0xfffe); - break; - default: - states->stateTable[newState][i]=entry; - break; - } - } - - /* in the lead state, redirect all lead bytes with all-unassigned trail bytes to the new state */ - for(i=0; i<256; ++i) { - if(count[i]>0) { - states->stateTable[leadState][i]=MBCS_ENTRY_SET_STATE(states->stateTable[leadState][i], newState); - } - } - - /* sum up the new state table */ - for(i=0; i<states->countStates; ++i) { - states->stateFlags[i]&=~MBCS_STATE_FLAG_READY; - } - sum=sumUpStates(states); - - /* allocate a new, smaller code units array */ - oldUnicodeCodeUnits=*pUnicodeCodeUnits; - if(sum==0) { - *pUnicodeCodeUnits=NULL; - if(oldUnicodeCodeUnits!=NULL) { - uprv_free(oldUnicodeCodeUnits); - } - uprv_free(oldStateTable); - return; - } - *pUnicodeCodeUnits=(uint16_t *)uprv_malloc(sum*sizeof(uint16_t)); - if(*pUnicodeCodeUnits==NULL) { - fprintf(stderr, "cannot compact toUnicode: out of memory allocating %ld 16-bit code units\n", - (long)sum); - /* revert to the old state table */ - *pUnicodeCodeUnits=oldUnicodeCodeUnits; - --states->countStates; - uprv_memcpy(states->stateTable, oldStateTable, states->countStates*1024); - uprv_free(oldStateTable); - return; - } - for(i=0; i<sum; ++i) { - (*pUnicodeCodeUnits)[i]=0xfffe; - } - - /* copy the code units for all assigned characters */ - /* - * The old state table has the same lead _and_ trail states for assigned characters! - * The differences are in the offsets, and in the trail states for some unassigned characters. - * For each character with an assigned state in the new table, it was assigned in the old one. - * Only still-assigned characters are copied. - * Note that fallback mappings need to get their offset values adjusted. - */ - - /* for each initial state */ - for(leadState=0; leadState<states->countStates; ++leadState) { - if((states->stateFlags[leadState]&0xf)==MBCS_STATE_FLAG_DIRECT) { - /* for each lead byte from there */ - for(i=0; i<256; ++i) { - entry=states->stateTable[leadState][i]; - if(MBCS_ENTRY_IS_TRANSITION(entry)) { - trailState=(uint8_t)MBCS_ENTRY_TRANSITION_STATE(entry); - /* the new state does not have assigned states */ - if(trailState!=newState) { - trailOffset=MBCS_ENTRY_TRANSITION_OFFSET(entry); - oldTrailOffset=MBCS_ENTRY_TRANSITION_OFFSET(oldStateTable[leadState][i]); - /* for each trail byte */ - for(j=0; j<256; ++j) { - entry=states->stateTable[trailState][j]; - /* copy assigned-character code units and adjust fallback offsets */ - switch(MBCS_ENTRY_FINAL_ACTION(entry)) { - case MBCS_STATE_VALID_16: - offset=trailOffset+MBCS_ENTRY_FINAL_VALUE_16(entry); - /* find the old offset according to the old state table */ - oldOffset=oldTrailOffset+MBCS_ENTRY_FINAL_VALUE_16(oldStateTable[trailState][j]); - unit=(*pUnicodeCodeUnits)[offset]=oldUnicodeCodeUnits[oldOffset]; - if(unit==0xfffe && (fallback=ucm_findFallback(toUFallbacks, countToUFallbacks, oldOffset))>=0) { - toUFallbacks[fallback].offset=0x80000000|offset; - } - break; - case MBCS_STATE_VALID_16_PAIR: - offset=trailOffset+MBCS_ENTRY_FINAL_VALUE_16(entry); - /* find the old offset according to the old state table */ - oldOffset=oldTrailOffset+MBCS_ENTRY_FINAL_VALUE_16(oldStateTable[trailState][j]); - (*pUnicodeCodeUnits)[offset++]=oldUnicodeCodeUnits[oldOffset++]; - (*pUnicodeCodeUnits)[offset]=oldUnicodeCodeUnits[oldOffset]; - break; - default: - break; - } - } - } - } - } - } - } - - /* remove temporary flags from fallback offsets that protected them from being modified twice */ - for(i=0; i<countToUFallbacks; ++i) { - toUFallbacks[i].offset&=0x7fffffff; - } - - /* free temporary memory */ - uprv_free(oldUnicodeCodeUnits); - uprv_free(oldStateTable); -} - -/* - * recursive sub-function of compactToUnicodeHelper() - * returns: - * >0 number of bytes that are used in unicodeCodeUnits[] that could be saved, - * if all sequences from this state are unassigned, returns the - * <0 there are assignments in unicodeCodeUnits[] - * 0 no use of unicodeCodeUnits[] - */ -static int32_t -findUnassigned(UCMStates *states, - uint16_t *unicodeCodeUnits, - _MBCSToUFallback *toUFallbacks, int32_t countToUFallbacks, - int32_t state, int32_t offset, uint32_t b) { - int32_t i, entry, savings, localSavings, belowSavings; - UBool haveAssigned; - - localSavings=belowSavings=0; - haveAssigned=FALSE; - for(i=0; i<256; ++i) { - entry=states->stateTable[state][i]; - if(MBCS_ENTRY_IS_TRANSITION(entry)) { - savings=findUnassigned(states, - unicodeCodeUnits, - toUFallbacks, countToUFallbacks, - MBCS_ENTRY_TRANSITION_STATE(entry), - offset+MBCS_ENTRY_TRANSITION_OFFSET(entry), - (b<<8)|(uint32_t)i); - if(savings<0) { - haveAssigned=TRUE; - } else if(savings>0) { - printf(" all-unassigned sequences from prefix 0x%02lx state %ld use %ld bytes\n", - (unsigned long)((b<<8)|i), (long)state, (long)savings); - belowSavings+=savings; - } - } else if(!haveAssigned) { - switch(MBCS_ENTRY_FINAL_ACTION(entry)) { - case MBCS_STATE_VALID_16: - entry=offset+MBCS_ENTRY_FINAL_VALUE_16(entry); - if(unicodeCodeUnits[entry]==0xfffe && ucm_findFallback(toUFallbacks, countToUFallbacks, entry)<0) { - localSavings+=2; - } else { - haveAssigned=TRUE; - } - break; - case MBCS_STATE_VALID_16_PAIR: - entry=offset+MBCS_ENTRY_FINAL_VALUE_16(entry); - if(unicodeCodeUnits[entry]==0xfffe) { - localSavings+=4; - } else { - haveAssigned=TRUE; - } - break; - default: - break; - } - } - } - if(haveAssigned) { - return -1; - } else { - return localSavings+belowSavings; - } -} - -/* helper function for finding compaction opportunities */ -static void -compactToUnicodeHelper(UCMStates *states, - uint16_t *unicodeCodeUnits, - _MBCSToUFallback *toUFallbacks, int32_t countToUFallbacks) { - int32_t state, savings; - - /* for each initial state */ - for(state=0; state<states->countStates; ++state) { - if((states->stateFlags[state]&0xf)==MBCS_STATE_FLAG_DIRECT) { - savings=findUnassigned(states, - unicodeCodeUnits, - toUFallbacks, countToUFallbacks, - state, 0, 0); - if(savings>0) { - printf(" all-unassigned sequences from initial state %ld use %ld bytes\n", - (long)state, (long)savings); - } - } - } -} - -U_CDECL_BEGIN -static int32_t U_CALLCONV -compareFallbacks(const void *context, const void *fb1, const void *fb2) { - (void)context; - return ((const _MBCSToUFallback *)fb1)->offset-((const _MBCSToUFallback *)fb2)->offset; -} -U_CDECL_END - -U_CAPI void U_EXPORT2 -ucm_optimizeStates(UCMStates *states, - uint16_t **pUnicodeCodeUnits, - _MBCSToUFallback *toUFallbacks, int32_t countToUFallbacks, - UBool verbose) { - UErrorCode errorCode; - int32_t state, cell, entry; - - /* test each state table entry */ - for(state=0; state<states->countStates; ++state) { - for(cell=0; cell<256; ++cell) { - entry=states->stateTable[state][cell]; - /* - * if the entry is a final one with an MBCS_STATE_VALID_DIRECT_16 action code - * and the code point is "unassigned" (0xfffe), then change it to - * the "unassigned" action code with bits 26..23 set to zero and U+fffe. - */ - if(MBCS_ENTRY_SET_STATE(entry, 0)==MBCS_ENTRY_FINAL(0, MBCS_STATE_VALID_DIRECT_16, 0xfffe)) { - states->stateTable[state][cell]=MBCS_ENTRY_FINAL_SET_ACTION(entry, MBCS_STATE_UNASSIGNED); - } - } - } - - /* try to compact the toUnicode tables */ - if(states->maxCharLength==2) { - compactToUnicode2(states, pUnicodeCodeUnits, toUFallbacks, countToUFallbacks, verbose); - } else if(states->maxCharLength>2) { - if(verbose) { - compactToUnicodeHelper(states, *pUnicodeCodeUnits, toUFallbacks, countToUFallbacks); - } - } - - /* sort toUFallbacks */ - /* - * It should be safe to sort them before compactToUnicode2() is called, - * because it should not change the relative order of the offset values - * that it adjusts, but they need to be sorted at some point, and - * it is safest here. - */ - if(countToUFallbacks>0) { - errorCode=U_ZERO_ERROR; /* nothing bad will happen... */ - uprv_sortArray(toUFallbacks, countToUFallbacks, - sizeof(_MBCSToUFallback), - compareFallbacks, NULL, FALSE, &errorCode); - } -} - -/* use a complete state table ----------------------------------------------- */ - -U_CAPI int32_t U_EXPORT2 -ucm_countChars(UCMStates *states, - const uint8_t *bytes, int32_t length) { - uint32_t offset; - int32_t i, entry, count; - uint8_t state; - - offset=0; - count=0; - state=0; - - if(states->countStates==0) { - fprintf(stderr, "ucm error: there is no state information!\n"); - return -1; - } - - /* for SI/SO (like EBCDIC-stateful), double-byte sequences start in state 1 */ - if(length==2 && states->outputType==MBCS_OUTPUT_2_SISO) { - state=1; - } - - /* - * Walk down the state table like in conversion, - * much like getNextUChar(). - * We assume that c<=0x10ffff. - */ - for(i=0; i<length; ++i) { - entry=states->stateTable[state][bytes[i]]; - if(MBCS_ENTRY_IS_TRANSITION(entry)) { - state=(uint8_t)MBCS_ENTRY_TRANSITION_STATE(entry); - offset+=MBCS_ENTRY_TRANSITION_OFFSET(entry); - } else { - switch(MBCS_ENTRY_FINAL_ACTION(entry)) { - case MBCS_STATE_ILLEGAL: - fprintf(stderr, "ucm error: byte sequence ends in illegal state\n"); - return -1; - case MBCS_STATE_CHANGE_ONLY: - fprintf(stderr, "ucm error: byte sequence ends in state-change-only\n"); - return -1; - case MBCS_STATE_UNASSIGNED: - case MBCS_STATE_FALLBACK_DIRECT_16: - case MBCS_STATE_VALID_DIRECT_16: - case MBCS_STATE_FALLBACK_DIRECT_20: - case MBCS_STATE_VALID_DIRECT_20: - case MBCS_STATE_VALID_16: - case MBCS_STATE_VALID_16_PAIR: - /* count a complete character and prepare for a new one */ - ++count; - state=(uint8_t)MBCS_ENTRY_FINAL_STATE(entry); - offset=0; - break; - default: - /* reserved, must never occur */ - fprintf(stderr, "ucm error: byte sequence reached reserved action code, entry: 0x%02lx\n", (unsigned long)entry); - return -1; - } - } - } - - if(offset!=0) { - fprintf(stderr, "ucm error: byte sequence too short, ends in non-final state %u\n", state); - return -1; - } - - /* - * for SI/SO (like EBCDIC-stateful), multiple-character results - * must consist of only double-byte sequences - */ - if(count>1 && states->outputType==MBCS_OUTPUT_2_SISO && length!=2*count) { - fprintf(stderr, "ucm error: SI/SO (like EBCDIC-stateful) result with %d characters does not contain all DBCS\n", (int)count); - return -1; - } - - return count; -} -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/udbgutil.cpp b/deps/node/deps/icu-small/source/tools/toolutil/udbgutil.cpp deleted file mode 100644 index 285f68a0..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/udbgutil.cpp +++ /dev/null @@ -1,754 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/******************************************************************** - * COPYRIGHT: - * Copyright (c) 2007-2016, International Business Machines Corporation and - * others. All Rights Reserved. - ********************************************************************/ - -#include "udbgutil.h" -#include <string.h> -#include "ustr_imp.h" -#include "cmemory.h" -#include "cstring.h" -#include "putilimp.h" -#include "unicode/ulocdata.h" -#include "unicode/ucnv.h" -#include "unicode/unistr.h" -#include "cstr.h" - -/* -To add a new enum type - (For example: UShoeSize with values USHOE_WIDE=0, USHOE_REGULAR, USHOE_NARROW, USHOE_COUNT) - - 0. Make sure that all lines you add are protected with appropriate uconfig guards, - such as '#if !UCONFIG_NO_SHOES'. - 1. udbgutil.h: add UDBG_UShoeSize to the UDebugEnumType enum before UDBG_ENUM_COUNT - ( The subsequent steps involve this file, udbgutil.cpp ) - 2. Find the marker "Add new enum types above this line" - 3. Before that marker, add a #include of any header file you need. - 4. Each enum type has three things in this section: a #define, a count_, and an array of Fields. - It may help to copy and paste a previous definition. - 5. In the case of the USHOE_... strings above, "USHOE_" is common to all values- six characters - " #define LEN_USHOE 6 " - 6 characters will strip off "USHOE_" leaving enum values of WIDE, REGULAR, and NARROW. - 6. Define the 'count_' variable, with the number of enum values. If the enum has a _MAX or _COUNT value, - that can be helpful for automatically defining the count. Otherwise define it manually. - " static const int32_t count_UShoeSize = USHOE_COUNT; " - 7. Define the field names, in order. - " static const Field names_UShoeSize[] = { - " FIELD_NAME_STR( LEN_USHOE, USHOE_WIDE ), - " FIELD_NAME_STR( LEN_USHOE, USHOE_REGULAR ), - " FIELD_NAME_STR( LEN_USHOE, USHOE_NARROW ), - " }; - ( The following command was usedfor converting ucol.h into partially correct entities ) - grep "^[ ]*UCOL" < unicode/ucol.h | - sed -e 's%^[ ]*\([A-Z]*\)_\([A-Z_]*\).*% FIELD_NAME_STR( LEN_\1, \1_\2 ),%g' - 8. Now, a bit farther down, add the name of the enum itself to the end of names_UDebugEnumType - ( UDebugEnumType is an enum, too!) - names_UDebugEnumType[] { ... - " FIELD_NAME_STR( LEN_UDBG, UDBG_UShoeSize ), " - 9. Find the function _udbg_enumCount and add the count macro: - " COUNT_CASE(UShoeSize) - 10. Find the function _udbg_enumFields and add the field macro: - " FIELD_CASE(UShoeSize) - 11. verify that your test code, and Java data generation, works properly. -*/ - -/** - * Structure representing an enum value - */ -struct Field { - int32_t prefix; /**< how many characters to remove in the prefix - i.e. UCHAR_ = 5 */ - const char *str; /**< The actual string value */ - int32_t num; /**< The numeric value */ -}; - -/** - * Define another field name. Used in an array of Field s - * @param y the common prefix length (i.e. 6 for "USHOE_" ) - * @param x the actual enum value - it will be copied in both string and symbolic form. - * @see Field - */ -#define FIELD_NAME_STR(y,x) { y, #x, x } - - -// TODO: Currently, this whole functionality goes away with UCONFIG_NO_FORMATTING. Should be split up. -#if !UCONFIG_NO_FORMATTING - -// Calendar -#include "unicode/ucal.h" - -// 'UCAL_' = 5 -#define LEN_UCAL 5 /* UCAL_ */ -static const int32_t count_UCalendarDateFields = UCAL_FIELD_COUNT; -static const Field names_UCalendarDateFields[] = -{ - FIELD_NAME_STR( LEN_UCAL, UCAL_ERA ), - FIELD_NAME_STR( LEN_UCAL, UCAL_YEAR ), - FIELD_NAME_STR( LEN_UCAL, UCAL_MONTH ), - FIELD_NAME_STR( LEN_UCAL, UCAL_WEEK_OF_YEAR ), - FIELD_NAME_STR( LEN_UCAL, UCAL_WEEK_OF_MONTH ), - FIELD_NAME_STR( LEN_UCAL, UCAL_DATE ), - FIELD_NAME_STR( LEN_UCAL, UCAL_DAY_OF_YEAR ), - FIELD_NAME_STR( LEN_UCAL, UCAL_DAY_OF_WEEK ), - FIELD_NAME_STR( LEN_UCAL, UCAL_DAY_OF_WEEK_IN_MONTH ), - FIELD_NAME_STR( LEN_UCAL, UCAL_AM_PM ), - FIELD_NAME_STR( LEN_UCAL, UCAL_HOUR ), - FIELD_NAME_STR( LEN_UCAL, UCAL_HOUR_OF_DAY ), - FIELD_NAME_STR( LEN_UCAL, UCAL_MINUTE ), - FIELD_NAME_STR( LEN_UCAL, UCAL_SECOND ), - FIELD_NAME_STR( LEN_UCAL, UCAL_MILLISECOND ), - FIELD_NAME_STR( LEN_UCAL, UCAL_ZONE_OFFSET ), - FIELD_NAME_STR( LEN_UCAL, UCAL_DST_OFFSET ), - FIELD_NAME_STR( LEN_UCAL, UCAL_YEAR_WOY ), - FIELD_NAME_STR( LEN_UCAL, UCAL_DOW_LOCAL ), - FIELD_NAME_STR( LEN_UCAL, UCAL_EXTENDED_YEAR ), - FIELD_NAME_STR( LEN_UCAL, UCAL_JULIAN_DAY ), - FIELD_NAME_STR( LEN_UCAL, UCAL_MILLISECONDS_IN_DAY ), - FIELD_NAME_STR( LEN_UCAL, UCAL_IS_LEAP_MONTH ), -}; - - -static const int32_t count_UCalendarMonths = UCAL_UNDECIMBER+1; -static const Field names_UCalendarMonths[] = -{ - FIELD_NAME_STR( LEN_UCAL, UCAL_JANUARY ), - FIELD_NAME_STR( LEN_UCAL, UCAL_FEBRUARY ), - FIELD_NAME_STR( LEN_UCAL, UCAL_MARCH ), - FIELD_NAME_STR( LEN_UCAL, UCAL_APRIL ), - FIELD_NAME_STR( LEN_UCAL, UCAL_MAY ), - FIELD_NAME_STR( LEN_UCAL, UCAL_JUNE ), - FIELD_NAME_STR( LEN_UCAL, UCAL_JULY ), - FIELD_NAME_STR( LEN_UCAL, UCAL_AUGUST ), - FIELD_NAME_STR( LEN_UCAL, UCAL_SEPTEMBER ), - FIELD_NAME_STR( LEN_UCAL, UCAL_OCTOBER ), - FIELD_NAME_STR( LEN_UCAL, UCAL_NOVEMBER ), - FIELD_NAME_STR( LEN_UCAL, UCAL_DECEMBER ), - FIELD_NAME_STR( LEN_UCAL, UCAL_UNDECIMBER) -}; - -#include "unicode/udat.h" - -#define LEN_UDAT 5 /* "UDAT_" */ -static const int32_t count_UDateFormatStyle = UDAT_SHORT+1; -static const Field names_UDateFormatStyle[] = -{ - FIELD_NAME_STR( LEN_UDAT, UDAT_FULL ), - FIELD_NAME_STR( LEN_UDAT, UDAT_LONG ), - FIELD_NAME_STR( LEN_UDAT, UDAT_MEDIUM ), - FIELD_NAME_STR( LEN_UDAT, UDAT_SHORT ), - /* end regular */ - /* - * negative enums.. leave out for now. - FIELD_NAME_STR( LEN_UDAT, UDAT_NONE ), - FIELD_NAME_STR( LEN_UDAT, UDAT_PATTERN ), - */ -}; - -#endif - -#include "unicode/uloc.h" - -#define LEN_UAR 12 /* "ULOC_ACCEPT_" */ -static const int32_t count_UAcceptResult = 3; -static const Field names_UAcceptResult[] = -{ - FIELD_NAME_STR( LEN_UAR, ULOC_ACCEPT_FAILED ), - FIELD_NAME_STR( LEN_UAR, ULOC_ACCEPT_VALID ), - FIELD_NAME_STR( LEN_UAR, ULOC_ACCEPT_FALLBACK ), -}; - -#if !UCONFIG_NO_COLLATION -#include "unicode/ucol.h" -#define LEN_UCOL 5 /* UCOL_ */ -static const int32_t count_UColAttributeValue = UCOL_ATTRIBUTE_VALUE_COUNT; -static const Field names_UColAttributeValue[] = { - FIELD_NAME_STR( LEN_UCOL, UCOL_PRIMARY ), - FIELD_NAME_STR( LEN_UCOL, UCOL_SECONDARY ), - FIELD_NAME_STR( LEN_UCOL, UCOL_TERTIARY ), -// FIELD_NAME_STR( LEN_UCOL, UCOL_CE_STRENGTH_LIMIT ), - FIELD_NAME_STR( LEN_UCOL, UCOL_QUATERNARY ), - // gap - FIELD_NAME_STR( LEN_UCOL, UCOL_IDENTICAL ), -// FIELD_NAME_STR( LEN_UCOL, UCOL_STRENGTH_LIMIT ), - FIELD_NAME_STR( LEN_UCOL, UCOL_OFF ), - FIELD_NAME_STR( LEN_UCOL, UCOL_ON ), - // gap - FIELD_NAME_STR( LEN_UCOL, UCOL_SHIFTED ), - FIELD_NAME_STR( LEN_UCOL, UCOL_NON_IGNORABLE ), - // gap - FIELD_NAME_STR( LEN_UCOL, UCOL_LOWER_FIRST ), - FIELD_NAME_STR( LEN_UCOL, UCOL_UPPER_FIRST ), -}; - -#endif - - -#if UCONFIG_ENABLE_PLUGINS -#include "unicode/icuplug.h" - -#define LEN_UPLUG_REASON 13 /* UPLUG_REASON_ */ -static const int32_t count_UPlugReason = UPLUG_REASON_COUNT; -static const Field names_UPlugReason[] = { - FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_QUERY ), - FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_LOAD ), - FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_UNLOAD ), -}; - -#define LEN_UPLUG_LEVEL 12 /* UPLUG_LEVEL_ */ -static const int32_t count_UPlugLevel = UPLUG_LEVEL_COUNT; -static const Field names_UPlugLevel[] = { - FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_INVALID ), - FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_UNKNOWN ), - FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_LOW ), - FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_HIGH ), -}; -#endif - -#define LEN_UDBG 5 /* "UDBG_" */ -static const int32_t count_UDebugEnumType = UDBG_ENUM_COUNT; -static const Field names_UDebugEnumType[] = -{ - FIELD_NAME_STR( LEN_UDBG, UDBG_UDebugEnumType ), -#if !UCONFIG_NO_FORMATTING - FIELD_NAME_STR( LEN_UDBG, UDBG_UCalendarDateFields ), - FIELD_NAME_STR( LEN_UDBG, UDBG_UCalendarMonths ), - FIELD_NAME_STR( LEN_UDBG, UDBG_UDateFormatStyle ), -#endif -#if UCONFIG_ENABLE_PLUGINS - FIELD_NAME_STR( LEN_UDBG, UDBG_UPlugReason ), - FIELD_NAME_STR( LEN_UDBG, UDBG_UPlugLevel ), -#endif - FIELD_NAME_STR( LEN_UDBG, UDBG_UAcceptResult ), -#if !UCONFIG_NO_COLLATION - FIELD_NAME_STR( LEN_UDBG, UDBG_UColAttributeValue ), -#endif -}; - - -// --- Add new enum types above this line --- - -#define COUNT_CASE(x) case UDBG_##x: return (actual?count_##x:UPRV_LENGTHOF(names_##x)); -#define COUNT_FAIL_CASE(x) case UDBG_##x: return -1; - -#define FIELD_CASE(x) case UDBG_##x: return names_##x; -#define FIELD_FAIL_CASE(x) case UDBG_##x: return NULL; - -// low level - -/** - * @param type type of item - * @param actual TRUE: for the actual enum's type (UCAL_FIELD_COUNT, etc), or FALSE for the string count - */ -static int32_t _udbg_enumCount(UDebugEnumType type, UBool actual) { - switch(type) { - COUNT_CASE(UDebugEnumType) -#if !UCONFIG_NO_FORMATTING - COUNT_CASE(UCalendarDateFields) - COUNT_CASE(UCalendarMonths) - COUNT_CASE(UDateFormatStyle) -#endif -#if UCONFIG_ENABLE_PLUGINS - COUNT_CASE(UPlugReason) - COUNT_CASE(UPlugLevel) -#endif - COUNT_CASE(UAcceptResult) -#if !UCONFIG_NO_COLLATION - COUNT_CASE(UColAttributeValue) -#endif - // COUNT_FAIL_CASE(UNonExistentEnum) - default: - return -1; - } -} - -static const Field* _udbg_enumFields(UDebugEnumType type) { - switch(type) { - FIELD_CASE(UDebugEnumType) -#if !UCONFIG_NO_FORMATTING - FIELD_CASE(UCalendarDateFields) - FIELD_CASE(UCalendarMonths) - FIELD_CASE(UDateFormatStyle) -#endif -#if UCONFIG_ENABLE_PLUGINS - FIELD_CASE(UPlugReason) - FIELD_CASE(UPlugLevel) -#endif - FIELD_CASE(UAcceptResult) - // FIELD_FAIL_CASE(UNonExistentEnum) -#if !UCONFIG_NO_COLLATION - FIELD_CASE(UColAttributeValue) -#endif - default: - return NULL; - } -} - -// implementation - -int32_t udbg_enumCount(UDebugEnumType type) { - return _udbg_enumCount(type, FALSE); -} - -int32_t udbg_enumExpectedCount(UDebugEnumType type) { - return _udbg_enumCount(type, TRUE); -} - -const char * udbg_enumName(UDebugEnumType type, int32_t field) { - if(field<0 || - field>=_udbg_enumCount(type,FALSE)) { // also will catch unsupported items - return NULL; - } else { - const Field *fields = _udbg_enumFields(type); - if(fields == NULL) { - return NULL; - } else { - return fields[field].str + fields[field].prefix; - } - } -} - -int32_t udbg_enumArrayValue(UDebugEnumType type, int32_t field) { - if(field<0 || - field>=_udbg_enumCount(type,FALSE)) { // also will catch unsupported items - return -1; - } else { - const Field *fields = _udbg_enumFields(type); - if(fields == NULL) { - return -1; - } else { - return fields[field].num; - } - } -} - -int32_t udbg_enumByName(UDebugEnumType type, const char *value) { - if(type<0||type>=_udbg_enumCount(UDBG_UDebugEnumType, TRUE)) { - return -1; // type out of range - } - const Field *fields = _udbg_enumFields(type); - if (fields != NULL) { - for(int32_t field = 0;field<_udbg_enumCount(type, FALSE);field++) { - if(!strcmp(value, fields[field].str + fields[field].prefix)) { - return fields[field].num; - } - } - // try with the prefix - for(int32_t field = 0;field<_udbg_enumCount(type, FALSE);field++) { - if(!strcmp(value, fields[field].str)) { - return fields[field].num; - } - } - } - // fail - return -1; -} - -/* platform info */ -/** - * Print the current platform - */ -U_CAPI const char *udbg_getPlatform(void) -{ -#if U_PLATFORM_USES_ONLY_WIN32_API - return "Windows"; -#elif U_PLATFORM == U_PF_CYGWIN - return "Cygwin"; -#elif U_PLATFORM == U_PF_UNKNOWN - return "unknown"; -#elif U_PLATFORM == U_PF_DARWIN - return "Darwin"; -#elif U_PLATFORM == U_PF_BSD - return "BSD"; -#elif U_PLATFORM == U_PF_QNX - return "QNX"; -#elif U_PLATFORM == U_PF_LINUX - return "Linux"; -#elif U_PLATFORM == U_PF_ANDROID - return "Android"; -#elif U_PLATFORM == U_PF_CLASSIC_MACOS - return "MacOS (Classic)"; -#elif U_PLATFORM == U_PF_OS390 - return "IBM z"; -#elif U_PLATFORM == U_PF_OS400 - return "IBM i"; -#else - return "Other (POSIX-like)"; -#endif -} - -struct USystemParams; - -typedef int32_t U_CALLCONV USystemParameterCallback(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status); - -struct USystemParams { - const char *paramName; - USystemParameterCallback *paramFunction; - const char *paramStr; - int32_t paramInt; -}; - -/* parameter types */ -U_CAPI int32_t -paramEmpty(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) { - if(U_FAILURE(*status))return 0; - return u_terminateChars(target, targetCapacity, 0, status); -} - -U_CAPI int32_t -paramStatic(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status) { - if(param->paramStr==NULL) return paramEmpty(param,target,targetCapacity,status); - if(U_FAILURE(*status))return 0; - int32_t len = static_cast<int32_t>(uprv_strlen(param->paramStr)); - if(target!=NULL) { - uprv_strncpy(target,param->paramStr,uprv_min(len,targetCapacity)); - } - return u_terminateChars(target, targetCapacity, len, status); -} - -static const char *nullString = "(null)"; - -static int32_t stringToStringBuffer(char *target, int32_t targetCapacity, const char *str, UErrorCode *status) { - if(str==NULL) str=nullString; - - int32_t len = static_cast<int32_t>(uprv_strlen(str)); - if (U_SUCCESS(*status)) { - if(target!=NULL) { - uprv_strncpy(target,str,uprv_min(len,targetCapacity)); - } - } else { - const char *s = u_errorName(*status); - len = static_cast<int32_t>(uprv_strlen(s)); - if(target!=NULL) { - uprv_strncpy(target,s,uprv_min(len,targetCapacity)); - } - } - return u_terminateChars(target, targetCapacity, len, status); -} - -static int32_t integerToStringBuffer(char *target, int32_t targetCapacity, int32_t n, int32_t radix, UErrorCode *status) { - if(U_FAILURE(*status)) return 0; - char str[300]; - T_CString_integerToString(str,n,radix); - return stringToStringBuffer(target,targetCapacity,str,status); -} - -U_CAPI int32_t -paramInteger(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status) { - if(U_FAILURE(*status))return 0; - if(param->paramStr==NULL || param->paramStr[0]=='d') { - return integerToStringBuffer(target,targetCapacity,param->paramInt, 10,status); - } else if(param->paramStr[0]=='x') { - return integerToStringBuffer(target,targetCapacity,param->paramInt, 16,status); - } else if(param->paramStr[0]=='o') { - return integerToStringBuffer(target,targetCapacity,param->paramInt, 8,status); - } else if(param->paramStr[0]=='b') { - return integerToStringBuffer(target,targetCapacity,param->paramInt, 2,status); - } else { - *status = U_INTERNAL_PROGRAM_ERROR; - return 0; - } -} - - -U_CAPI int32_t -paramCldrVersion(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) { - if(U_FAILURE(*status))return 0; - char str[200]=""; - UVersionInfo icu; - - ulocdata_getCLDRVersion(icu, status); - if(U_SUCCESS(*status)) { - u_versionToString(icu, str); - return stringToStringBuffer(target,targetCapacity,str,status); - } else { - return 0; - } -} - - -#if !UCONFIG_NO_FORMATTING -U_CAPI int32_t -paramTimezoneDefault(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) { - if(U_FAILURE(*status))return 0; - UChar buf[100]; - char buf2[100]; - int32_t len; - - len = ucal_getDefaultTimeZone(buf, 100, status); - if(U_SUCCESS(*status)&&len>0) { - u_UCharsToChars(buf, buf2, len+1); - return stringToStringBuffer(target,targetCapacity, buf2,status); - } else { - return 0; - } -} -#endif - -U_CAPI int32_t -paramLocaleDefaultBcp47(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) { - if(U_FAILURE(*status))return 0; - const char *def = uloc_getDefault(); - return uloc_toLanguageTag(def,target,targetCapacity,FALSE,status); -} - - -/* simple 1-liner param functions */ -#define STRING_PARAM(func, str) U_CAPI int32_t \ - func(const USystemParams *, char *target, int32_t targetCapacity, UErrorCode *status) \ - { return stringToStringBuffer(target,targetCapacity,(str),status); } - -STRING_PARAM(paramIcudataPath, u_getDataDirectory()) -STRING_PARAM(paramPlatform, udbg_getPlatform()) -STRING_PARAM(paramLocaleDefault, uloc_getDefault()) -#if !UCONFIG_NO_CONVERSION -STRING_PARAM(paramConverterDefault, ucnv_getDefaultName()) -#endif - -#if !UCONFIG_NO_FORMATTING -STRING_PARAM(paramTimezoneVersion, ucal_getTZDataVersion(status)) -#endif - -static const USystemParams systemParams[] = { - { "copyright", paramStatic, U_COPYRIGHT_STRING,0 }, - { "product", paramStatic, "icu4c",0 }, - { "product.full", paramStatic, "International Components for Unicode for C/C++",0 }, - { "version", paramStatic, U_ICU_VERSION,0 }, - { "version.unicode", paramStatic, U_UNICODE_VERSION,0 }, - { "platform.number", paramInteger, "d",U_PLATFORM}, - { "platform.type", paramPlatform, NULL ,0}, - { "locale.default", paramLocaleDefault, NULL, 0}, - { "locale.default.bcp47", paramLocaleDefaultBcp47, NULL, 0}, -#if !UCONFIG_NO_CONVERSION - { "converter.default", paramConverterDefault, NULL, 0}, -#endif - { "icudata.name", paramStatic, U_ICUDATA_NAME, 0}, - { "icudata.path", paramIcudataPath, NULL, 0}, - - { "cldr.version", paramCldrVersion, NULL, 0}, - -#if !UCONFIG_NO_FORMATTING - { "tz.version", paramTimezoneVersion, NULL, 0}, - { "tz.default", paramTimezoneDefault, NULL, 0}, -#endif - - { "cpu.bits", paramInteger, "d", (sizeof(void*))*8}, - { "cpu.big_endian", paramInteger, "b", U_IS_BIG_ENDIAN}, - { "os.wchar_width", paramInteger, "d", U_SIZEOF_WCHAR_T}, - { "os.charset_family", paramInteger, "d", U_CHARSET_FAMILY}, -#if defined (U_HOST) - { "os.host", paramStatic, U_HOST, 0}, -#endif -#if defined (U_BUILD) - { "build.build", paramStatic, U_BUILD, 0}, -#endif -#if defined (U_CC) - { "build.cc", paramStatic, U_CC, 0}, -#endif -#if defined (U_CXX) - { "build.cxx", paramStatic, U_CXX, 0}, -#endif -#if defined (CYGWINMSVC) - { "build.cygwinmsvc", paramInteger, "b", 1}, -#endif - { "uconfig.internal_digitlist", paramInteger, "b", 1}, /* always 1 */ - { "uconfig.have_parseallinput", paramInteger, "b", UCONFIG_HAVE_PARSEALLINPUT}, - - -}; - -#define U_SYSPARAM_COUNT UPRV_LENGTHOF(systemParams) - -U_CAPI const char *udbg_getSystemParameterNameByIndex(int32_t i) { - if(i>=0 && i < (int32_t)U_SYSPARAM_COUNT) { - return systemParams[i].paramName; - } else { - return NULL; - } -} - - -U_CAPI int32_t udbg_getSystemParameterValueByIndex(int32_t i, char *buffer, int32_t bufferCapacity, UErrorCode *status) { - if(i>=0 && i< (int32_t)U_SYSPARAM_COUNT) { - return systemParams[i].paramFunction(&(systemParams[i]),buffer,bufferCapacity,status); - } else { - return 0; - } -} - -U_CAPI void udbg_writeIcuInfo(FILE *out) { - char str[2000]; - /* todo: API for writing DTD? */ - fprintf(out, " <icuSystemParams type=\"icu4c\">\n"); - const char *paramName; - for(int32_t i=0;(paramName=udbg_getSystemParameterNameByIndex(i))!=NULL;i++) { - UErrorCode status2 = U_ZERO_ERROR; - udbg_getSystemParameterValueByIndex(i, str,2000,&status2); - if(U_SUCCESS(status2)) { - fprintf(out," <param name=\"%s\">%s</param>\n", paramName,str); - } else { - fprintf(out," <!-- n=\"%s\" ERROR: %s -->\n", paramName, u_errorName(status2)); - } - } - fprintf(out, " </icuSystemParams>\n"); -} - -#define ICU_TRAC_URL "http://bugs.icu-project.org/trac/ticket/" -#define CLDR_TRAC_URL "http://unicode.org/cldr/trac/ticket/" -#define CLDR_TICKET_PREFIX "cldrbug:" - -U_CAPI char *udbg_knownIssueURLFrom(const char *ticket, char *buf) { - if( ticket==NULL ) { - return NULL; - } - - if( !strncmp(ticket, CLDR_TICKET_PREFIX, strlen(CLDR_TICKET_PREFIX)) ) { - strcpy( buf, CLDR_TRAC_URL ); - strcat( buf, ticket+strlen(CLDR_TICKET_PREFIX) ); - } else { - strcpy( buf, ICU_TRAC_URL ); - strcat( buf, ticket ); - } - return buf; -} - - -#include <set> -#include <map> -#include <string> -#include <ostream> -#include <iostream> - -class KnownIssues { -public: - KnownIssues(); - ~KnownIssues(); - void add(const char *ticket, const char *where, const UChar *msg, UBool *firstForTicket, UBool *firstForWhere); - void add(const char *ticket, const char *where, const char *msg, UBool *firstForTicket, UBool *firstForWhere); - UBool print(); -private: - std::map< std::string, - std::map < std::string, std::set < std::string > > > fTable; -}; - -KnownIssues::KnownIssues() - : fTable() -{ -} - -KnownIssues::~KnownIssues() -{ -} - -void KnownIssues::add(const char *ticket, const char *where, const UChar *msg, UBool *firstForTicket, UBool *firstForWhere) -{ - if(fTable.find(ticket) == fTable.end()) { - if(firstForTicket!=NULL) *firstForTicket = TRUE; - fTable[ticket] = std::map < std::string, std::set < std::string > >(); - } else { - if(firstForTicket!=NULL) *firstForTicket = FALSE; - } - if(where==NULL) return; - - if(fTable[ticket].find(where) == fTable[ticket].end()) { - if(firstForWhere!=NULL) *firstForWhere = TRUE; - fTable[ticket][where] = std::set < std::string >(); - } else { - if(firstForWhere!=NULL) *firstForWhere = FALSE; - } - if(msg==NULL || !*msg) return; - - const icu::UnicodeString ustr(msg); - - fTable[ticket][where].insert(std::string(icu::CStr(ustr)())); -} - -void KnownIssues::add(const char *ticket, const char *where, const char *msg, UBool *firstForTicket, UBool *firstForWhere) -{ - if(fTable.find(ticket) == fTable.end()) { - if(firstForTicket!=NULL) *firstForTicket = TRUE; - fTable[ticket] = std::map < std::string, std::set < std::string > >(); - } else { - if(firstForTicket!=NULL) *firstForTicket = FALSE; - } - if(where==NULL) return; - - if(fTable[ticket].find(where) == fTable[ticket].end()) { - if(firstForWhere!=NULL) *firstForWhere = TRUE; - fTable[ticket][where] = std::set < std::string >(); - } else { - if(firstForWhere!=NULL) *firstForWhere = FALSE; - } - if(msg==NULL || !*msg) return; - - std::string str(msg); - fTable[ticket][where].insert(str); -} - -UBool KnownIssues::print() -{ - if(fTable.empty()) { - return FALSE; - } - - std::cout << "KNOWN ISSUES" << std::endl; - for( std::map< std::string, - std::map < std::string, std::set < std::string > > >::iterator i = fTable.begin(); - i != fTable.end(); - i++ ) { - char URL[1024]; - std::cout << '#' << (*i).first << " <" << udbg_knownIssueURLFrom( (*i).first.c_str(), URL ) << ">" << std::endl; - - for( std::map< std::string, std::set < std::string > >::iterator ii = (*i).second.begin(); - ii != (*i).second.end(); - ii++ ) { - std::cout << " " << (*ii).first << std::endl; - for ( std::set < std::string >::iterator iii = (*ii).second.begin(); - iii != (*ii).second.end(); - iii++ ) { - std::cout << " " << '"' << (*iii) << '"' << std::endl; - } - } - } - return TRUE; -} - -U_CAPI void *udbg_knownIssue_openU(void *ptr, const char *ticket, char *where, const UChar *msg, UBool *firstForTicket, - UBool *firstForWhere) { - KnownIssues *t = static_cast<KnownIssues*>(ptr); - if(t==NULL) { - t = new KnownIssues(); - } - - t->add(ticket, where, msg, firstForTicket, firstForWhere); - - return static_cast<void*>(t); -} - -U_CAPI void *udbg_knownIssue_open(void *ptr, const char *ticket, char *where, const char *msg, UBool *firstForTicket, - UBool *firstForWhere) { - KnownIssues *t = static_cast<KnownIssues*>(ptr); - if(t==NULL) { - t = new KnownIssues(); - } - - t->add(ticket, where, msg, firstForTicket, firstForWhere); - - return static_cast<void*>(t); -} - -U_CAPI UBool udbg_knownIssue_print(void *ptr) { - KnownIssues *t = static_cast<KnownIssues*>(ptr); - if(t==NULL) { - return FALSE; - } else { - t->print(); - return TRUE; - } -} - -U_CAPI void udbg_knownIssue_close(void *ptr) { - KnownIssues *t = static_cast<KnownIssues*>(ptr); - delete t; -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/udbgutil.h b/deps/node/deps/icu-small/source/tools/toolutil/udbgutil.h deleted file mode 100644 index 2f186e6e..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/udbgutil.h +++ /dev/null @@ -1,155 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -************************************************************************ -* Copyright (c) 2008-2015, International Business Machines -* Corporation and others. All Rights Reserved. -************************************************************************ -*/ - -/** C Utilities to aid in debugging **/ - -#ifndef _UDBGUTIL_H -#define _UDBGUTIL_H - -#include "unicode/utypes.h" -#include <stdio.h> - -enum UDebugEnumType { - UDBG_UDebugEnumType = 0, /* Self-referential, strings for UDebugEnumType. Count=ENUM_COUNT. */ -#if !UCONFIG_NO_FORMATTING - UDBG_UCalendarDateFields, /* UCalendarDateFields. Count=UCAL_FIELD_COUNT. Unsupported if UCONFIG_NO_FORMATTING. */ - UDBG_UCalendarMonths, /* UCalendarMonths. Count= (UCAL_UNDECIMBER+1) */ - UDBG_UDateFormatStyle, /* Count = UDAT_SHORT=1 */ -#endif -#if UCONFIG_ENABLE_PLUGINS - UDBG_UPlugReason, /* Count = UPLUG_REASON_COUNT */ - UDBG_UPlugLevel, /* COUNT = UPLUG_LEVEL_COUNT */ -#endif - UDBG_UAcceptResult, /* Count = ULOC_ACCEPT_FALLBACK+1=3 */ - - /* All following enums may be discontiguous. */ - -#if !UCONFIG_NO_COLLATION - UDBG_UColAttributeValue, /* UCOL_ATTRIBUTE_VALUE_COUNT */ -#endif - UDBG_ENUM_COUNT, - UDBG_HIGHEST_CONTIGUOUS_ENUM = UDBG_UAcceptResult, /**< last enum in this list with contiguous (testable) values. */ - UDBG_INVALID_ENUM = -1 /** Invalid enum value **/ -}; - -typedef enum UDebugEnumType UDebugEnumType; - -/** - * @param type the type of enum - * Print how many enums are contained for this type. - * Should be equal to the appropriate _COUNT constant or there is an error. Return -1 if unsupported. - */ -U_CAPI int32_t U_EXPORT2 udbg_enumCount(UDebugEnumType type); - -/** - * Convert an enum to a string - * @param type type of enum - * @param field field number - * @return string of the format "ERA", "YEAR", etc, or NULL if out of range or unsupported - */ -U_CAPI const char * U_EXPORT2 udbg_enumName(UDebugEnumType type, int32_t field); - -/** - * for consistency checking - * @param type the type of enum - * Print how many enums should be contained for this type. - * This is equal to the appropriate _COUNT constant or there is an error. Returns -1 if unsupported. - */ -U_CAPI int32_t U_EXPORT2 udbg_enumExpectedCount(UDebugEnumType type); - -/** - * For consistency checking, returns the expected enum ordinal value for the given index value. - * @param type which type - * @param field field number - * @return should be equal to 'field' or -1 if out of range. - */ -U_CAPI int32_t U_EXPORT2 udbg_enumArrayValue(UDebugEnumType type, int32_t field); - -/** - * Locate the specified field value by name. - * @param type which type - * @param name name of string (case sensitive) - * @return should be a field value or -1 if not found. - */ -U_CAPI int32_t U_EXPORT2 udbg_enumByName(UDebugEnumType type, const char *name); - - -/** - * Return the Platform (U_PLATFORM) as a string - */ -U_CAPI const char *udbg_getPlatform(void); - -/** - * Get the nth system parameter's name - * @param i index of name, starting from zero - * @return name, or NULL if off the end - * @see udbg_getSystemParameterValue - */ -U_CAPI const char *udbg_getSystemParameterNameByIndex(int32_t i); - -/** - * Get the nth system parameter's value, in a user supplied buffer - * @parameter i index of value, starting from zero - * @param status error status - * @return length written (standard termination rules) - * @see udbg_getSystemParameterName - */ -U_CAPI int32_t udbg_getSystemParameterValueByIndex(int32_t i, char *buffer, int32_t bufferCapacity, UErrorCode *status); - -/** - * Write ICU info as XML - */ -U_CAPI void udbg_writeIcuInfo(FILE *f); - -/** - * \def UDBG_KNOWNISSUE_LEN - * Length of output buffer for udbg_knownIssueURLFrom - */ -#define UDBG_KNOWNISSUE_LEN 255 - -/** - * Convert a "known issue" string into a URL - * @param ticket ticket string such as "10245" or "cldrbug:5013" - * @param buf output buffer - must be UDBG_KNOWNISSUE_LEN in size - * @return pointer to output buffer, or NULL on err - */ -U_CAPI char *udbg_knownIssueURLFrom(const char *ticket, char *buf); - -/** - * Open (or reopen) a 'known issue' table. - * @param ptr pointer to 'table'. Opaque. - * @return new or existing ptr - */ -U_CAPI void *udbg_knownIssue_openU(void *ptr, const char *ticket, char *where, const UChar *msg, UBool *firstForTicket, - UBool *firstForWhere); - - -/** - * Open (or reopen) a 'known issue' table. - * @param ptr pointer to 'table'. Opaque. - * @return new or existing ptr - */ -U_CAPI void *udbg_knownIssue_open(void *ptr, const char *ticket, char *where, const char *msg, UBool *firstForTicket, - UBool *firstForWhere); - -/** - * Print 'known issue' table, to std::cout. - * @param ptr pointer from udbg_knownIssue - * @return TRUE if there were any issues. - */ -U_CAPI UBool udbg_knownIssue_print(void *ptr); - -/** - * Close 'known issue' table. - * @param ptr - */ -U_CAPI void udbg_knownIssue_close(void *ptr); - - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/unewdata.cpp b/deps/node/deps/icu-small/source/tools/toolutil/unewdata.cpp deleted file mode 100644 index 22d85408..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/unewdata.cpp +++ /dev/null @@ -1,275 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1999-2010, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: unewdata.c -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 1999oct25 -* created by: Markus W. Scherer -*/ - -#include <stdio.h> -#include "unicode/utypes.h" -#include "unicode/putil.h" -#include "unicode/ustring.h" -#include "cmemory.h" -#include "cstring.h" -#include "filestrm.h" -#include "unicode/udata.h" -#include "unewdata.h" - -struct UNewDataMemory { - FileStream *file; - uint16_t headerSize; - uint8_t magic1, magic2; -}; - -U_CAPI UNewDataMemory * U_EXPORT2 -udata_create(const char *dir, const char *type, const char *name, - const UDataInfo *pInfo, - const char *comment, - UErrorCode *pErrorCode) { - UNewDataMemory *pData; - uint16_t headerSize, commentLength; - char filename[512]; - uint8_t bytes[16]; - int32_t length; - - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { - return NULL; - } else if(name==NULL || *name==0 || pInfo==NULL) { - *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; - return NULL; - } - - /* allocate the data structure */ - pData=(UNewDataMemory *)uprv_malloc(sizeof(UNewDataMemory)); - if(pData==NULL) { - *pErrorCode=U_MEMORY_ALLOCATION_ERROR; - return NULL; - } - - /* Check that the full path won't be too long */ - length = 0; /* Start with nothing */ - if(dir != NULL && *dir !=0) /* Add directory length if one was given */ - { - length += static_cast<int32_t>(strlen(dir)); - - /* Add 1 if dir doesn't end with path sep */ - if (dir[strlen(dir) - 1]!= U_FILE_SEP_CHAR) { - length++; - } - } - length += static_cast<int32_t>(strlen(name)); /* Add the filename length */ - - if(type != NULL && *type !=0) { /* Add directory length if given */ - length += static_cast<int32_t>(strlen(type)); - } - - - /* LDH buffer Length error check */ - if(length > ((int32_t)sizeof(filename) - 1)) - { - *pErrorCode = U_BUFFER_OVERFLOW_ERROR; - uprv_free(pData); - return NULL; - } - - /* open the output file */ - if(dir!=NULL && *dir!=0) { /* if dir has a value, we prepend it to the filename */ - char *p=filename+strlen(dir); - uprv_strcpy(filename, dir); - if (*(p-1)!=U_FILE_SEP_CHAR) { - *p++=U_FILE_SEP_CHAR; - *p=0; - } - } else { /* otherwise, we'll output to the current dir */ - filename[0]=0; - } - uprv_strcat(filename, name); - if(type!=NULL && *type!=0) { - uprv_strcat(filename, "."); - uprv_strcat(filename, type); - } - pData->file=T_FileStream_open(filename, "wb"); - if(pData->file==NULL) { - uprv_free(pData); - *pErrorCode=U_FILE_ACCESS_ERROR; - return NULL; - } - - /* write the header information */ - headerSize=(uint16_t)(pInfo->size+4); - if(comment!=NULL && *comment!=0) { - commentLength=(uint16_t)(uprv_strlen(comment)+1); - headerSize+=commentLength; - } else { - commentLength=0; - } - - /* write the size of the header, take padding into account */ - pData->headerSize=(uint16_t)((headerSize+15)&~0xf); - pData->magic1=0xda; - pData->magic2=0x27; - T_FileStream_write(pData->file, &pData->headerSize, 4); - - /* write the information data */ - T_FileStream_write(pData->file, pInfo, pInfo->size); - - /* write the comment */ - if(commentLength>0) { - T_FileStream_write(pData->file, comment, commentLength); - } - - /* write padding bytes to align the data section to 16 bytes */ - headerSize&=0xf; - if(headerSize!=0) { - headerSize=(uint16_t)(16-headerSize); - uprv_memset(bytes, 0, headerSize); - T_FileStream_write(pData->file, bytes, headerSize); - } - - return pData; -} - -U_CAPI uint32_t U_EXPORT2 -udata_finish(UNewDataMemory *pData, UErrorCode *pErrorCode) { - uint32_t fileLength=0; - - if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { - return 0; - } - - if(pData!=NULL) { - if(pData->file!=NULL) { - /* fflush(pData->file);*/ - fileLength=T_FileStream_size(pData->file); - if(T_FileStream_error(pData->file)) { - *pErrorCode=U_FILE_ACCESS_ERROR; - } else { - fileLength-=pData->headerSize; - } - T_FileStream_close(pData->file); - } - uprv_free(pData); - } - - return fileLength; -} - -/* dummy UDataInfo cf. udata.h */ -static const UDataInfo dummyDataInfo = { - sizeof(UDataInfo), - 0, - - U_IS_BIG_ENDIAN, - U_CHARSET_FAMILY, - U_SIZEOF_UCHAR, - 0, - - { 0, 0, 0, 0 }, /* dummy dataFormat */ - { 0, 0, 0, 0 }, /* dummy formatVersion */ - { 0, 0, 0, 0 } /* dummy dataVersion */ -}; - -U_CAPI void U_EXPORT2 -udata_createDummy(const char *dir, const char *type, const char *name, UErrorCode *pErrorCode) { - if(U_SUCCESS(*pErrorCode)) { - udata_finish(udata_create(dir, type, name, &dummyDataInfo, NULL, pErrorCode), pErrorCode); - if(U_FAILURE(*pErrorCode)) { - fprintf(stderr, "error %s writing dummy data file %s" U_FILE_SEP_STRING "%s.%s\n", - u_errorName(*pErrorCode), dir, name, type); - exit(*pErrorCode); - } - } -} - -U_CAPI void U_EXPORT2 -udata_write8(UNewDataMemory *pData, uint8_t byte) { - if(pData!=NULL && pData->file!=NULL) { - T_FileStream_write(pData->file, &byte, 1); - } -} - -U_CAPI void U_EXPORT2 -udata_write16(UNewDataMemory *pData, uint16_t word) { - if(pData!=NULL && pData->file!=NULL) { - T_FileStream_write(pData->file, &word, 2); - } -} - -U_CAPI void U_EXPORT2 -udata_write32(UNewDataMemory *pData, uint32_t wyde) { - if(pData!=NULL && pData->file!=NULL) { - T_FileStream_write(pData->file, &wyde, 4); - } -} - -U_CAPI void U_EXPORT2 -udata_writeBlock(UNewDataMemory *pData, const void *s, int32_t length) { - if(pData!=NULL && pData->file!=NULL) { - if(length>0) { - T_FileStream_write(pData->file, s, length); - } - } -} - -U_CAPI void U_EXPORT2 -udata_writePadding(UNewDataMemory *pData, int32_t length) { - static const uint8_t padding[16]={ - 0xaa, 0xaa, 0xaa, 0xaa, - 0xaa, 0xaa, 0xaa, 0xaa, - 0xaa, 0xaa, 0xaa, 0xaa, - 0xaa, 0xaa, 0xaa, 0xaa - }; - if(pData!=NULL && pData->file!=NULL) { - while(length>=16) { - T_FileStream_write(pData->file, padding, 16); - length-=16; - } - if(length>0) { - T_FileStream_write(pData->file, padding, length); - } - } -} - -U_CAPI void U_EXPORT2 -udata_writeString(UNewDataMemory *pData, const char *s, int32_t length) { - if(pData!=NULL && pData->file!=NULL) { - if(length==-1) { - length=(int32_t)uprv_strlen(s); - } - if(length>0) { - T_FileStream_write(pData->file, s, length); - } - } -} - -U_CAPI void U_EXPORT2 -udata_writeUString(UNewDataMemory *pData, const UChar *s, int32_t length) { - if(pData!=NULL && pData->file!=NULL) { - if(length==-1) { - length=u_strlen(s); - } - if(length>0) { - T_FileStream_write(pData->file, s, length*sizeof(UChar)); - } - } -} - -/* - * Hey, Emacs, please set the following: - * - * Local Variables: - * indent-tabs-mode: nil - * End: - * - */ diff --git a/deps/node/deps/icu-small/source/tools/toolutil/unewdata.h b/deps/node/deps/icu-small/source/tools/toolutil/unewdata.h deleted file mode 100644 index 137fb495..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/unewdata.h +++ /dev/null @@ -1,113 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 1999-2010, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: unewdata.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 1999oct25 -* created by: Markus W. Scherer -*/ - -#ifndef __UNEWDATA_H__ -#define __UNEWDATA_H__ - -#include "unicode/utypes.h" -#include "unicode/udata.h" - -/* API for writing data -----------------------------------------------------*/ - -/** @memo Forward declaration of the data memory creation type. */ -typedef struct UNewDataMemory UNewDataMemory; - -/** - * Create a new binary data file. - * The file-writing <code>udata_</code> functions facilitate writing - * binary data files that can be read by ICU's <code>udata</code> API. - * This function opens a new file with a filename determined from its - * parameters - of the form "name.type". - * It then writes a short header, followed by the <code>UDataInfo</code> - * structure and, optionally, by the comment string. - * It then writes padding bytes to round up to a multiple of 16 bytes. - * Subsequent write operations will thus start at an offset in the file - * that is a multiple of 16. <code>udata_getMemory()</code> will return - * a pointer to this same starting offset. - * - * See udata.h . - * - * @param dir A string that specifies the directory where the data will be - * written. If <code>NULL</code>, then - * <code>u_getDataDirectory</code> is used. - * @param type A string that specifies the type of data to be written. - * For example, resource bundles are written with type "res", - * conversion tables with type "cnv". - * This may be <code>NULL</code> or empty. - * @param name A string that specifies the name of the data. - * @param pInfo A pointer to a correctly filled <code>UDataInfo</code> - * structure that will be copied into the file. - * @param comment A string (e.g., a copyright statement) that will be - * copied into the file if it is not <code>NULL</code> - * or empty. This string serves only as a comment in the binary - * file. It will not be accessible by any API. - * @param pErrorCode An ICU UErrorCode parameter. It must not be <code>NULL</code>. - */ -U_CAPI UNewDataMemory * U_EXPORT2 -udata_create(const char *dir, const char *type, const char *name, - const UDataInfo *pInfo, - const char *comment, - UErrorCode *pErrorCode); - -/** @memo Close a newly written binary file. */ -U_CAPI uint32_t U_EXPORT2 -udata_finish(UNewDataMemory *pData, UErrorCode *pErrorCode); - -/** @memo Write a dummy data file. */ -U_CAPI void U_EXPORT2 -udata_createDummy(const char *dir, const char *type, const char *name, UErrorCode *pErrorCode); - -/** @memo Write an 8-bit byte to the file. */ -U_CAPI void U_EXPORT2 -udata_write8(UNewDataMemory *pData, uint8_t byte); - -/** @memo Write a 16-bit word to the file. */ -U_CAPI void U_EXPORT2 -udata_write16(UNewDataMemory *pData, uint16_t word); - -/** @memo Write a 32-bit word to the file. */ -U_CAPI void U_EXPORT2 -udata_write32(UNewDataMemory *pData, uint32_t wyde); - -/** @memo Write a block of bytes to the file. */ -U_CAPI void U_EXPORT2 -udata_writeBlock(UNewDataMemory *pData, const void *s, int32_t length); - -/** @memo Write a block of arbitrary padding bytes to the file. */ -U_CAPI void U_EXPORT2 -udata_writePadding(UNewDataMemory *pData, int32_t length); - -/** @memo Write a <code>char*</code> string of platform "invariant characters" to the file. */ -U_CAPI void U_EXPORT2 -udata_writeString(UNewDataMemory *pData, const char *s, int32_t length); - -/** @memo Write a <code>UChar*</code> string of Unicode character code units to the file. */ -U_CAPI void U_EXPORT2 -udata_writeUString(UNewDataMemory *pData, const UChar *s, int32_t length); - - -/* - * Hey, Emacs, please set the following: - * - * Local Variables: - * indent-tabs-mode: nil - * End: - * - */ - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/uoptions.cpp b/deps/node/deps/icu-small/source/tools/toolutil/uoptions.cpp deleted file mode 100644 index 53a77bcc..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/uoptions.cpp +++ /dev/null @@ -1,133 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2000-2015, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: uoptions.c -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2000apr17 -* created by: Markus W. Scherer -* -* This file provides a command line argument parser. -*/ - -#include "unicode/utypes.h" -#include "cstring.h" -#include "uoptions.h" - -U_CAPI int U_EXPORT2 -u_parseArgs(int argc, char* argv[], - int optionCount, UOption options[]) { - char *arg; - int i=1, remaining=1; - char c, stopOptions=0; - - while(i<argc) { - arg=argv[i]; - if(!stopOptions && *arg=='-' && (c=arg[1])!=0) { - /* process an option */ - UOption *option=NULL; - arg+=2; - if(c=='-') { - /* process a long option */ - if(*arg==0) { - /* stop processing options after "--" */ - stopOptions=1; - } else { - /* search for the option string */ - int j; - for(j=0; j<optionCount; ++j) { - if(options[j].longName && uprv_strcmp(arg, options[j].longName)==0) { - option=options+j; - break; - } - } - if(option==NULL) { - /* no option matches */ - return -i; - } - option->doesOccur=1; - - if(option->hasArg!=UOPT_NO_ARG) { - /* parse the argument for the option, if any */ - if(i+1<argc && !(argv[i+1][0]=='-' && argv[i+1][1]!=0)) { - /* argument in the next argv[], and there is not an option in there */ - option->value=argv[++i]; - } else if(option->hasArg==UOPT_REQUIRES_ARG) { - /* there is no argument, but one is required: return with error */ - option->doesOccur=0; - return -i; - } - } - - if(option->optionFn!=NULL && option->optionFn(option->context, option)<0) { - /* the option function was called and returned an error */ - option->doesOccur=0; - return -i; - } - } - } else { - /* process one or more short options */ - do { - /* search for the option letter */ - int j; - for(j=0; j<optionCount; ++j) { - if(c==options[j].shortName) { - option=options+j; - break; - } - } - if(option==NULL) { - /* no option matches */ - return -i; - } - option->doesOccur=1; - - if(option->hasArg!=UOPT_NO_ARG) { - /* parse the argument for the option, if any */ - if(*arg!=0) { - /* argument following in the same argv[] */ - option->value=arg; - /* do not process the rest of this arg as option letters */ - break; - } else if(i+1<argc && !(argv[i+1][0]=='-' && argv[i+1][1]!=0)) { - /* argument in the next argv[], and there is not an option in there */ - option->value=argv[++i]; - /* this break is redundant because we know that *arg==0 */ - break; - } else if(option->hasArg==UOPT_REQUIRES_ARG) { - /* there is no argument, but one is required: return with error */ - option->doesOccur=0; - return -i; - } - } - - if(option->optionFn!=NULL && option->optionFn(option->context, option)<0) { - /* the option function was called and returned an error */ - option->doesOccur=0; - return -i; - } - - /* get the next option letter */ - option=NULL; - c=*arg++; - } while(c!=0); - } - - /* go to next argv[] */ - ++i; - } else { - /* move a non-option up in argv[] */ - argv[remaining++]=arg; - ++i; - } - } - return remaining; -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/uoptions.h b/deps/node/deps/icu-small/source/tools/toolutil/uoptions.h deleted file mode 100644 index a7a2e96c..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/uoptions.h +++ /dev/null @@ -1,143 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2000-2011, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: uoptions.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2000apr17 -* created by: Markus W. Scherer -* -* This file provides a command line argument parser. -*/ - -#ifndef __UOPTIONS_H__ -#define __UOPTIONS_H__ - -#include "unicode/utypes.h" - -/* This should usually be called before calling u_parseArgs */ -/*#if U_PLATFORM == U_PF_OS390 && (U_CHARSET_FAMILY == U_ASCII_FAMILY)*/ - /* translate args from EBCDIC to ASCII */ -/*# define U_MAIN_INIT_ARGS(argc, argv) __argvtoascii_a(argc, argv)*/ -/*#elif defined(XP_MAC_CONSOLE)*/ -#if defined(XP_MAC_CONSOLE) -# include <console.h> - /* Get the arguments from the GUI, since old Macs don't have a console Window. */ -# define U_MAIN_INIT_ARGS(argc, argv) argc = ccommand((char***)&argv) -#else - /* Normally we do nothing. */ -# define U_MAIN_INIT_ARGS(argc, argv) -#endif - - - -/* forward declarations for the function declaration */ -struct UOption; -typedef struct UOption UOption; - -/* function to be called for a command line option */ -typedef int UOptionFn(void *context, UOption *option); - -/* values of UOption.hasArg */ -enum { UOPT_NO_ARG, UOPT_REQUIRES_ARG, UOPT_OPTIONAL_ARG }; - -/* structure describing a command line option */ -struct UOption { - const char *longName; /* "foo" for --foo */ - const char *value; /* output placeholder, will point to the argument string, if any */ - UOptionFn *optionFn; /* function to be called when this option occurs */ - void *context; /* parameter for the function */ - char shortName; /* 'f' for -f */ - char hasArg; /* enum value: option takes no/requires/may have argument */ - char doesOccur; /* boolean for "this one occured" */ -}; - -/* macro for an entry in a declaration of UOption[] */ -#define UOPTION_DEF(longName, shortName, hasArg) \ - { longName, NULL, NULL, NULL, shortName, hasArg, 0 } - -/* ICU Tools option definitions */ -#define UOPTION_HELP_H UOPTION_DEF("help", 'h', UOPT_NO_ARG) -#define UOPTION_HELP_QUESTION_MARK UOPTION_DEF("help", '?', UOPT_NO_ARG) -#define UOPTION_VERBOSE UOPTION_DEF("verbose", 'v', UOPT_NO_ARG) -#define UOPTION_QUIET UOPTION_DEF("quiet", 'q', UOPT_NO_ARG) -#define UOPTION_VERSION UOPTION_DEF("version", 'V', UOPT_NO_ARG) -#define UOPTION_COPYRIGHT UOPTION_DEF("copyright", 'c', UOPT_NO_ARG) - -#define UOPTION_DESTDIR UOPTION_DEF("destdir", 'd', UOPT_REQUIRES_ARG) -#define UOPTION_SOURCEDIR UOPTION_DEF("sourcedir", 's', UOPT_REQUIRES_ARG) -#define UOPTION_ENCODING UOPTION_DEF("encoding", 'e', UOPT_REQUIRES_ARG) -#define UOPTION_ICUDATADIR UOPTION_DEF("icudatadir", 'i', UOPT_REQUIRES_ARG) -#define UOPTION_WRITE_JAVA UOPTION_DEF("write-java", 'j', UOPT_OPTIONAL_ARG) -#define UOPTION_PACKAGE_NAME UOPTION_DEF("package-name", 'p', UOPT_REQUIRES_ARG) -#define UOPTION_BUNDLE_NAME UOPTION_DEF("bundle-name", 'b', UOPT_REQUIRES_ARG) - -/** - * C Command line argument parser. - * - * This function takes the argv[argc] command line and a description of - * the program's options in form of an array of UOption structures. - * Each UOption defines a long and a short name (a string and a character) - * for options like "--foo" and "-f". - * - * Each option is marked with whether it does not take an argument, - * requires one, or optionally takes one. The argument may follow in - * the same argv[] entry for short options, or it may always follow - * in the next argv[] entry. - * - * An argument is in the next argv[] entry for both long and short name - * options, except it is taken from directly behind the short name in - * its own argv[] entry if there are characters following the option letter. - * An argument in its own argv[] entry must not begin with a '-' - * unless it is only the '-' itself. There is no restriction of the - * argument format if it is part of the short name options's argv[] entry. - * - * The argument is stored in the value field of the corresponding - * UOption entry, and the doesOccur field is set to 1 if the option - * is found at all. - * - * Short name options without arguments can be collapsed into a single - * argv[] entry. After an option letter takes an argument, following - * letters will be taken as its argument. - * - * If the same option is found several times, then the last - * argument value will be stored in the value field. - * - * For each option, a function can be called. This could be used - * for options that occur multiple times and all arguments are to - * be collected. - * - * All options are removed from the argv[] array itself. If the parser - * is successful, then it returns the number of remaining non-option - * strings (including argv[0]). - * argv[0], the program name, is never read or modified. - * - * An option "--" ends option processing; everything after this - * remains in the argv[] array. - * - * An option string "-" alone is treated as a non-option. - * - * If an option is not recognized or an argument missing, then - * the parser returns with the negative index of the argv[] entry - * where the error was detected. - * - * The OS/400 compiler requires that argv either be "char* argv[]", - * or "const char* const argv[]", and it will not accept, - * "const char* argv[]" as a definition for main(). - * - * @param argv This parameter is modified - * @param options This parameter is modified - */ -U_CAPI int U_EXPORT2 -u_parseArgs(int argc, char* argv[], - int optionCount, UOption options[]); - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/uparse.cpp b/deps/node/deps/icu-small/source/tools/toolutil/uparse.cpp deleted file mode 100644 index a932c171..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/uparse.cpp +++ /dev/null @@ -1,383 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2000-2012, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: uparse.c -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2000apr18 -* created by: Markus W. Scherer -* -* This file provides a parser for files that are delimited by one single -* character like ';' or TAB. Example: the Unicode Character Properties files -* like UnicodeData.txt are semicolon-delimited. -*/ - -#include "unicode/utypes.h" -#include "unicode/uchar.h" -#include "unicode/ustring.h" -#include "unicode/utf16.h" -#include "cstring.h" -#include "filestrm.h" -#include "uparse.h" -#include "ustr_imp.h" - -#include <stdio.h> - -U_CAPI const char * U_EXPORT2 -u_skipWhitespace(const char *s) { - while(U_IS_INV_WHITESPACE(*s)) { - ++s; - } - return s; -} - -U_CAPI char * U_EXPORT2 -u_rtrim(char *s) { - char *end=uprv_strchr(s, 0); - while(s<end && U_IS_INV_WHITESPACE(*(end-1))) { - *--end = 0; - } - return end; -} - -/* - * If the string starts with # @missing: then return the pointer to the - * following non-whitespace character. - * Otherwise return the original pointer. - * Unicode 5.0 adds such lines in some data files to document - * default property values. - * Poor man's regex for variable amounts of white space. - */ -static const char * -getMissingLimit(const char *s) { - const char *s0=s; - if( - *(s=u_skipWhitespace(s))=='#' && - *(s=u_skipWhitespace(s+1))=='@' && - 0==strncmp((s=u_skipWhitespace(s+1)), "missing", 7) && - *(s=u_skipWhitespace(s+7))==':' - ) { - return u_skipWhitespace(s+1); - } else { - return s0; - } -} - -U_CAPI void U_EXPORT2 -u_parseDelimitedFile(const char *filename, char delimiter, - char *fields[][2], int32_t fieldCount, - UParseLineFn *lineFn, void *context, - UErrorCode *pErrorCode) { - FileStream *file; - char line[10000]; - char *start, *limit; - int32_t i, length; - - if(U_FAILURE(*pErrorCode)) { - return; - } - - if(fields==NULL || lineFn==NULL || fieldCount<=0) { - *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; - return; - } - - if(filename==NULL || *filename==0 || (*filename=='-' && filename[1]==0)) { - filename=NULL; - file=T_FileStream_stdin(); - } else { - file=T_FileStream_open(filename, "r"); - } - if(file==NULL) { - *pErrorCode=U_FILE_ACCESS_ERROR; - return; - } - - while(T_FileStream_readLine(file, line, sizeof(line))!=NULL) { - /* remove trailing newline characters */ - length=(int32_t)(u_rtrim(line)-line); - - /* - * detect a line with # @missing: - * start parsing after that, or else from the beginning of the line - * set the default warning for @missing lines - */ - start=(char *)getMissingLimit(line); - if(start==line) { - *pErrorCode=U_ZERO_ERROR; - } else { - *pErrorCode=U_USING_DEFAULT_WARNING; - } - - /* skip this line if it is empty or a comment */ - if(*start==0 || *start=='#') { - continue; - } - - /* remove in-line comments */ - limit=uprv_strchr(start, '#'); - if(limit!=NULL) { - /* get white space before the pound sign */ - while(limit>start && U_IS_INV_WHITESPACE(*(limit-1))) { - --limit; - } - - /* truncate the line */ - *limit=0; - } - - /* skip lines with only whitespace */ - if(u_skipWhitespace(start)[0]==0) { - continue; - } - - /* for each field, call the corresponding field function */ - for(i=0; i<fieldCount; ++i) { - /* set the limit pointer of this field */ - limit=start; - while(*limit!=delimiter && *limit!=0) { - ++limit; - } - - /* set the field start and limit in the fields array */ - fields[i][0]=start; - fields[i][1]=limit; - - /* set start to the beginning of the next field, if any */ - start=limit; - if(*start!=0) { - ++start; - } else if(i+1<fieldCount) { - *pErrorCode=U_PARSE_ERROR; - limit=line+length; - i=fieldCount; - break; - } - } - - /* too few fields? */ - if(U_FAILURE(*pErrorCode)) { - break; - } - - /* call the field function */ - lineFn(context, fields, fieldCount, pErrorCode); - if(U_FAILURE(*pErrorCode)) { - break; - } - } - - if(filename!=NULL) { - T_FileStream_close(file); - } -} - -/* - * parse a list of code points - * store them as a UTF-32 string in dest[destCapacity] - * return the number of code points - */ -U_CAPI int32_t U_EXPORT2 -u_parseCodePoints(const char *s, - uint32_t *dest, int32_t destCapacity, - UErrorCode *pErrorCode) { - char *end; - uint32_t value; - int32_t count; - - if(U_FAILURE(*pErrorCode)) { - return 0; - } - if(s==NULL || destCapacity<0 || (destCapacity>0 && dest==NULL)) { - *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; - return 0; - } - - count=0; - for(;;) { - s=u_skipWhitespace(s); - if(*s==';' || *s==0) { - return count; - } - - /* read one code point */ - value=(uint32_t)uprv_strtoul(s, &end, 16); - if(end<=s || (!U_IS_INV_WHITESPACE(*end) && *end!=';' && *end!=0) || value>=0x110000) { - *pErrorCode=U_PARSE_ERROR; - return 0; - } - - /* append it to the destination array */ - if(count<destCapacity) { - dest[count++]=value; - } else { - *pErrorCode=U_BUFFER_OVERFLOW_ERROR; - } - - /* go to the following characters */ - s=end; - } -} - -/* - * parse a list of code points - * store them as a string in dest[destCapacity] - * set the first code point in *pFirst - * @return The length of the string in numbers of UChars. - */ -U_CAPI int32_t U_EXPORT2 -u_parseString(const char *s, - UChar *dest, int32_t destCapacity, - uint32_t *pFirst, - UErrorCode *pErrorCode) { - char *end; - uint32_t value; - int32_t destLength; - - if(U_FAILURE(*pErrorCode)) { - return 0; - } - if(s==NULL || destCapacity<0 || (destCapacity>0 && dest==NULL)) { - *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; - return 0; - } - - if(pFirst!=NULL) { - *pFirst=0xffffffff; - } - - destLength=0; - for(;;) { - s=u_skipWhitespace(s); - if(*s==';' || *s==0) { - if(destLength<destCapacity) { - dest[destLength]=0; - } else if(destLength==destCapacity) { - *pErrorCode=U_STRING_NOT_TERMINATED_WARNING; - } else { - *pErrorCode=U_BUFFER_OVERFLOW_ERROR; - } - return destLength; - } - - /* read one code point */ - value=(uint32_t)uprv_strtoul(s, &end, 16); - if(end<=s || (!U_IS_INV_WHITESPACE(*end) && *end!=';' && *end!=0) || value>=0x110000) { - *pErrorCode=U_PARSE_ERROR; - return 0; - } - - /* store the first code point */ - if(pFirst!=NULL) { - *pFirst=value; - pFirst=NULL; - } - - /* append it to the destination array */ - if((destLength+U16_LENGTH(value))<=destCapacity) { - U16_APPEND_UNSAFE(dest, destLength, value); - } else { - destLength+=U16_LENGTH(value); - } - - /* go to the following characters */ - s=end; - } -} - -/* read a range like start or start..end */ -U_CAPI int32_t U_EXPORT2 -u_parseCodePointRangeAnyTerminator(const char *s, - uint32_t *pStart, uint32_t *pEnd, - const char **terminator, - UErrorCode *pErrorCode) { - char *end; - uint32_t value; - - if(U_FAILURE(*pErrorCode)) { - return 0; - } - if(s==NULL || pStart==NULL || pEnd==NULL) { - *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; - return 0; - } - - /* read the start code point */ - s=u_skipWhitespace(s); - value=(uint32_t)uprv_strtoul(s, &end, 16); - if(end<=s || value>=0x110000) { - *pErrorCode=U_PARSE_ERROR; - return 0; - } - *pStart=*pEnd=value; - - /* is there a "..end"? */ - s=u_skipWhitespace(end); - if(*s!='.' || s[1]!='.') { - *terminator=end; - return 1; - } - s=u_skipWhitespace(s+2); - - /* read the end code point */ - value=(uint32_t)uprv_strtoul(s, &end, 16); - if(end<=s || value>=0x110000) { - *pErrorCode=U_PARSE_ERROR; - return 0; - } - *pEnd=value; - - /* is this a valid range? */ - if(value<*pStart) { - *pErrorCode=U_PARSE_ERROR; - return 0; - } - - *terminator=end; - return value-*pStart+1; -} - -U_CAPI int32_t U_EXPORT2 -u_parseCodePointRange(const char *s, - uint32_t *pStart, uint32_t *pEnd, - UErrorCode *pErrorCode) { - const char *terminator; - int32_t rangeLength= - u_parseCodePointRangeAnyTerminator(s, pStart, pEnd, &terminator, pErrorCode); - if(U_SUCCESS(*pErrorCode)) { - terminator=u_skipWhitespace(terminator); - if(*terminator!=';' && *terminator!=0) { - *pErrorCode=U_PARSE_ERROR; - return 0; - } - } - return rangeLength; -} - -U_CAPI int32_t U_EXPORT2 -u_parseUTF8(const char *source, int32_t sLen, char *dest, int32_t destCapacity, UErrorCode *status) { - const char *read = source; - int32_t i = 0; - unsigned int value = 0; - if(sLen == -1) { - sLen = (int32_t)strlen(source); - } - - while(read < source+sLen) { - sscanf(read, "%2x", &value); - if(i < destCapacity) { - dest[i] = (char)value; - } - i++; - read += 2; - } - return u_terminateChars(dest, destCapacity, i, status); -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/uparse.h b/deps/node/deps/icu-small/source/tools/toolutil/uparse.h deleted file mode 100644 index df0e79a2..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/uparse.h +++ /dev/null @@ -1,153 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2000-2010, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: uparse.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2000apr18 -* created by: Markus W. Scherer -* -* This file provides a parser for files that are delimited by one single -* character like ';' or TAB. Example: the Unicode Character Properties files -* like UnicodeData.txt are semicolon-delimited. -*/ - -#ifndef __UPARSE_H__ -#define __UPARSE_H__ - -#include "unicode/utypes.h" - -/** - * Is c an invariant-character whitespace? - * @param c invariant character - */ -#define U_IS_INV_WHITESPACE(c) ((c)==' ' || (c)=='\t' || (c)=='\r' || (c)=='\n') - -U_CDECL_BEGIN - -/** - * Skip space ' ' and TAB '\t' characters. - * - * @param s Pointer to characters. - * @return Pointer to first character at or after s that is not a space or TAB. - */ -U_CAPI const char * U_EXPORT2 -u_skipWhitespace(const char *s); - -/** - * Trim whitespace (including line endings) from the end of the string. - * - * @param s Pointer to the string. - * @return Pointer to the new end of the string. - */ -U_CAPI char * U_EXPORT2 -u_rtrim(char *s); - -/** Function type for u_parseDelimitedFile(). */ -typedef void U_CALLCONV -UParseLineFn(void *context, - char *fields[][2], - int32_t fieldCount, - UErrorCode *pErrorCode); - -/** - * Parser for files that are similar to UnicodeData.txt: - * This function opens the file and reads it line by line. It skips empty lines - * and comment lines that start with a '#'. - * All other lines are separated into fields with one delimiter character - * (semicolon for Unicode Properties files) between two fields. The last field in - * a line does not need to be terminated with a delimiter. - * - * For each line, after segmenting it, a line function is called. - * It gets passed the array of field start and limit pointers that is - * passed into this parser and filled by it for each line. - * For each field i of the line, the start pointer in fields[i][0] - * points to the beginning of the field, while the limit pointer in fields[i][1] - * points behind the field, i.e., to the delimiter or the line end. - * - * The context parameter of the line function is - * the same as the one for the parse function. - * - * The line function may modify the contents of the fields including the - * limit characters. - * - * If the file cannot be opened, or there is a parsing error or a field function - * sets *pErrorCode, then the parser returns with *pErrorCode set to an error code. - */ -U_CAPI void U_EXPORT2 -u_parseDelimitedFile(const char *filename, char delimiter, - char *fields[][2], int32_t fieldCount, - UParseLineFn *lineFn, void *context, - UErrorCode *pErrorCode); - -/** - * Parse a string of code points like 0061 0308 0300. - * s must end with either ';' or NUL. - * - * @return Number of code points. - */ -U_CAPI int32_t U_EXPORT2 -u_parseCodePoints(const char *s, - uint32_t *dest, int32_t destCapacity, - UErrorCode *pErrorCode); - -/** - * Parse a list of code points like 0061 0308 0300 - * into a UChar * string. - * s must end with either ';' or NUL. - * - * Set the first code point in *pFirst. - * - * @param s Input char * string. - * @param dest Output string buffer. - * @param destCapacity Capacity of dest in numbers of UChars. - * @param pFirst If pFirst!=NULL the *pFirst will be set to the first - * code point in the string. - * @param pErrorCode ICU error code. - * @return The length of the string in numbers of UChars. - */ -U_CAPI int32_t U_EXPORT2 -u_parseString(const char *s, - UChar *dest, int32_t destCapacity, - uint32_t *pFirst, - UErrorCode *pErrorCode); - -/** - * Parse a code point range like - * 0085 or - * 4E00..9FA5. - * - * s must contain such a range and end with either ';' or NUL. - * - * @return Length of code point range, end-start+1 - */ -U_CAPI int32_t U_EXPORT2 -u_parseCodePointRange(const char *s, - uint32_t *pStart, uint32_t *pEnd, - UErrorCode *pErrorCode); - -/** - * Same as u_parseCodePointRange() but the range may be terminated by - * any character. The position of the terminating character is returned via - * the *terminator output parameter. - */ -U_CAPI int32_t U_EXPORT2 -u_parseCodePointRangeAnyTerminator(const char *s, - uint32_t *pStart, uint32_t *pEnd, - const char **terminator, - UErrorCode *pErrorCode); - -U_CAPI int32_t U_EXPORT2 -u_parseUTF8(const char *source, int32_t sLen, char *dest, int32_t destCapacity, UErrorCode *status); - -U_CDECL_END - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/writesrc.cpp b/deps/node/deps/icu-small/source/tools/toolutil/writesrc.cpp deleted file mode 100644 index 1a1dd396..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/writesrc.cpp +++ /dev/null @@ -1,345 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2005-2012, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: writesrc.c -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2005apr23 -* created by: Markus W. Scherer -* -* Helper functions for writing source code for data. -*/ - -#include <stdio.h> -#include <time.h> -#include "unicode/utypes.h" -#include "unicode/putil.h" -#include "unicode/ucptrie.h" -#include "utrie2.h" -#include "cstring.h" -#include "writesrc.h" - -static FILE * -usrc_createWithHeader(const char *path, const char *filename, - const char *header, const char *generator) { - char buffer[1024]; - const char *p; - char *q; - FILE *f; - char c; - - if(path==NULL) { - p=filename; - } else { - /* concatenate path and filename, with U_FILE_SEP_CHAR in between if necessary */ - uprv_strcpy(buffer, path); - q=buffer+uprv_strlen(buffer); - if(q>buffer && (c=*(q-1))!=U_FILE_SEP_CHAR && c!=U_FILE_ALT_SEP_CHAR) { - *q++=U_FILE_SEP_CHAR; - } - uprv_strcpy(q, filename); - p=buffer; - } - - f=fopen(p, "w"); - if(f!=NULL) { - const struct tm *lt; - time_t t; - - time(&t); - lt=localtime(&t); - if(generator==NULL) { - strftime(buffer, sizeof(buffer), "%Y-%m-%d", lt); - fprintf(f, header, filename, buffer); - } else { - fprintf(f, header, filename, generator); - } - } else { - fprintf( - stderr, - "usrc_create(%s, %s): unable to create file\n", - path!=NULL ? path : "", filename); - } - return f; -} - -U_CAPI FILE * U_EXPORT2 -usrc_create(const char *path, const char *filename, int32_t copyrightYear, const char *generator) { - const char *header; - char buffer[200]; - if(copyrightYear<=2016) { - header= - "// © 2016 and later: Unicode, Inc. and others.\n" - "// License & terms of use: http://www.unicode.org/copyright.html\n" - "//\n" - "// Copyright (C) 1999-2016, International Business Machines\n" - "// Corporation and others. All Rights Reserved.\n" - "//\n" - "// file name: %s\n" - "//\n" - "// machine-generated by: %s\n" - "\n\n"; - } else { - sprintf(buffer, - "// © %d and later: Unicode, Inc. and others.\n" - "// License & terms of use: http://www.unicode.org/copyright.html\n" - "//\n" - "// file name: %%s\n" - "//\n" - "// machine-generated by: %%s\n" - "\n\n", - (int)copyrightYear); - header=buffer; - } - return usrc_createWithHeader(path, filename, header, generator); -} - -U_CAPI FILE * U_EXPORT2 -usrc_createTextData(const char *path, const char *filename, const char *generator) { - // TODO: Add parameter for the first year this file was generated, not before 2016. - static const char *header= - "# Copyright (C) 2016 and later: Unicode, Inc. and others.\n" - "# License & terms of use: http://www.unicode.org/copyright.html\n" - "# Copyright (C) 1999-2016, International Business Machines\n" - "# Corporation and others. All Rights Reserved.\n" - "#\n" - "# file name: %s\n" - "#\n" - "# machine-generated by: %s\n" - "\n\n"; - return usrc_createWithHeader(path, filename, header, generator); -} - -U_CAPI void U_EXPORT2 -usrc_writeArray(FILE *f, - const char *prefix, - const void *p, int32_t width, int32_t length, - const char *postfix) { - const uint8_t *p8; - const uint16_t *p16; - const uint32_t *p32; - uint32_t value; - int32_t i, col; - - p8=NULL; - p16=NULL; - p32=NULL; - switch(width) { - case 8: - p8=(const uint8_t *)p; - break; - case 16: - p16=(const uint16_t *)p; - break; - case 32: - p32=(const uint32_t *)p; - break; - default: - fprintf(stderr, "usrc_writeArray(width=%ld) unrecognized width\n", (long)width); - return; - } - if(prefix!=NULL) { - fprintf(f, prefix, (long)length); - } - for(i=col=0; i<length; ++i, ++col) { - if(i>0) { - if(col<16) { - fputc(',', f); - } else { - fputs(",\n", f); - col=0; - } - } - switch(width) { - case 8: - value=p8[i]; - break; - case 16: - value=p16[i]; - break; - case 32: - value=p32[i]; - break; - default: - value=0; /* unreachable */ - break; - } - fprintf(f, value<=9 ? "%lu" : "0x%lx", (unsigned long)value); - } - if(postfix!=NULL) { - fputs(postfix, f); - } -} - -U_CAPI void U_EXPORT2 -usrc_writeUTrie2Arrays(FILE *f, - const char *indexPrefix, const char *data32Prefix, - const UTrie2 *pTrie, - const char *postfix) { - if(pTrie->data32==NULL) { - /* 16-bit trie */ - usrc_writeArray(f, indexPrefix, pTrie->index, 16, pTrie->indexLength+pTrie->dataLength, postfix); - } else { - /* 32-bit trie */ - usrc_writeArray(f, indexPrefix, pTrie->index, 16, pTrie->indexLength, postfix); - usrc_writeArray(f, data32Prefix, pTrie->data32, 32, pTrie->dataLength, postfix); - } -} - -U_CAPI void U_EXPORT2 -usrc_writeUTrie2Struct(FILE *f, - const char *prefix, - const UTrie2 *pTrie, - const char *indexName, const char *data32Name, - const char *postfix) { - if(prefix!=NULL) { - fputs(prefix, f); - } - if(pTrie->data32==NULL) { - /* 16-bit trie */ - fprintf( - f, - " %s,\n" /* index */ - " %s+%ld,\n" /* data16 */ - " NULL,\n", /* data32 */ - indexName, - indexName, - (long)pTrie->indexLength); - } else { - /* 32-bit trie */ - fprintf( - f, - " %s,\n" /* index */ - " NULL,\n" /* data16 */ - " %s,\n", /* data32 */ - indexName, - data32Name); - } - fprintf( - f, - " %ld,\n" /* indexLength */ - " %ld,\n" /* dataLength */ - " 0x%hx,\n" /* index2NullOffset */ - " 0x%hx,\n" /* dataNullOffset */ - " 0x%lx,\n" /* initialValue */ - " 0x%lx,\n" /* errorValue */ - " 0x%lx,\n" /* highStart */ - " 0x%lx,\n" /* highValueIndex */ - " NULL, 0, FALSE, FALSE, 0, NULL\n", - (long)pTrie->indexLength, (long)pTrie->dataLength, - (short)pTrie->index2NullOffset, (short)pTrie->dataNullOffset, - (long)pTrie->initialValue, (long)pTrie->errorValue, - (long)pTrie->highStart, (long)pTrie->highValueIndex); - if(postfix!=NULL) { - fputs(postfix, f); - } -} - -U_CAPI void U_EXPORT2 -usrc_writeUCPTrieArrays(FILE *f, - const char *indexPrefix, const char *dataPrefix, - const UCPTrie *pTrie, - const char *postfix) { - usrc_writeArray(f, indexPrefix, pTrie->index, 16, pTrie->indexLength, postfix); - int32_t width= - pTrie->valueWidth==UCPTRIE_VALUE_BITS_16 ? 16 : - pTrie->valueWidth==UCPTRIE_VALUE_BITS_32 ? 32 : - pTrie->valueWidth==UCPTRIE_VALUE_BITS_8 ? 8 : 0; - usrc_writeArray(f, dataPrefix, pTrie->data.ptr0, width, pTrie->dataLength, postfix); -} - -U_CAPI void U_EXPORT2 -usrc_writeUCPTrieStruct(FILE *f, - const char *prefix, - const UCPTrie *pTrie, - const char *indexName, const char *dataName, - const char *postfix) { - if(prefix!=NULL) { - fputs(prefix, f); - } - fprintf( - f, - " %s,\n" // index - " { %s },\n", // data (union) - indexName, - dataName); - fprintf( - f, - " %ld, %ld,\n" // indexLength, dataLength - " 0x%lx, 0x%x,\n" // highStart, shifted12HighStart - " %d, %d,\n" // type, valueWidth - " 0, 0,\n" // reserved32, reserved16 - " 0x%x, 0x%lx,\n" // index3NullOffset, dataNullOffset - " 0x%lx,\n", // nullValue - (long)pTrie->indexLength, (long)pTrie->dataLength, - (long)pTrie->highStart, pTrie->shifted12HighStart, - pTrie->type, pTrie->valueWidth, - pTrie->index3NullOffset, (long)pTrie->dataNullOffset, - (long)pTrie->nullValue); - if(postfix!=NULL) { - fputs(postfix, f); - } -} - -U_CAPI void U_EXPORT2 -usrc_writeUCPTrie(FILE *f, const char *name, const UCPTrie *pTrie) { - int32_t width= - pTrie->valueWidth==UCPTRIE_VALUE_BITS_16 ? 16 : - pTrie->valueWidth==UCPTRIE_VALUE_BITS_32 ? 32 : - pTrie->valueWidth==UCPTRIE_VALUE_BITS_8 ? 8 : 0; - char line[100], line2[100], line3[100]; - sprintf(line, "static const uint16_t %s_trieIndex[%%ld]={\n", name); - sprintf(line2, "static const uint%d_t %s_trieData[%%ld]={\n", (int)width, name); - usrc_writeUCPTrieArrays(f, line, line2, pTrie, "\n};\n\n"); - sprintf(line, "static const UCPTrie %s_trie={\n", name); - sprintf(line2, "%s_trieIndex", name); - sprintf(line3, "%s_trieData", name); - usrc_writeUCPTrieStruct(f, line, pTrie, line2, line3, "};\n\n"); -} - -U_CAPI void U_EXPORT2 -usrc_writeArrayOfMostlyInvChars(FILE *f, - const char *prefix, - const char *p, int32_t length, - const char *postfix) { - int32_t i, col; - int prev2, prev, c; - - if(prefix!=NULL) { - fprintf(f, prefix, (long)length); - } - prev2=prev=-1; - for(i=col=0; i<length; ++i, ++col) { - c=(uint8_t)p[i]; - if(i>0) { - /* Break long lines. Try to break at interesting places, to minimize revision diffs. */ - if( - /* Very long line. */ - col>=32 || - /* Long line, break after terminating NUL. */ - (col>=24 && prev2>=0x20 && prev==0) || - /* Medium-long line, break before non-NUL, non-character byte. */ - (col>=16 && (prev==0 || prev>=0x20) && 0<c && c<0x20) - ) { - fputs(",\n", f); - col=0; - } else { - fputc(',', f); - } - } - fprintf(f, c<0x20 ? "%u" : "'%c'", c); - prev2=prev; - prev=c; - } - if(postfix!=NULL) { - fputs(postfix, f); - } -} diff --git a/deps/node/deps/icu-small/source/tools/toolutil/writesrc.h b/deps/node/deps/icu-small/source/tools/toolutil/writesrc.h deleted file mode 100644 index 35ba2567..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/writesrc.h +++ /dev/null @@ -1,122 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2005-2012, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: writesrc.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2005apr23 -* created by: Markus W. Scherer -* -* Helper functions for writing source code for data. -*/ - -#ifndef __WRITESRC_H__ -#define __WRITESRC_H__ - -#include <stdio.h> -#include "unicode/utypes.h" -#include "unicode/ucptrie.h" -#include "utrie2.h" - -/** - * Creates a source text file and writes a header comment with the ICU copyright. - * Writes a C/Java-style comment with the generator name. - */ -U_CAPI FILE * U_EXPORT2 -usrc_create(const char *path, const char *filename, int32_t copyrightYear, const char *generator); - -/** - * Creates a source text file and writes a header comment with the ICU copyright. - * Writes the comment with # lines, as used in scripts and text data. - */ -U_CAPI FILE * U_EXPORT2 -usrc_createTextData(const char *path, const char *filename, const char *generator); - -/** - * Writes the contents of an array of 8/16/32-bit words. - * The prefix and postfix are optional (can be NULL) and are written first/last. - * The prefix may contain a %ld or similar field for the array length. - * The {} and declaration etc. need to be included in prefix/postfix or - * printed before and after the array contents. - */ -U_CAPI void U_EXPORT2 -usrc_writeArray(FILE *f, - const char *prefix, - const void *p, int32_t width, int32_t length, - const char *postfix); - -/** - * Calls usrc_writeArray() for the index and data arrays of a frozen UTrie2. - * Only the index array is written for a 16-bit UTrie2. In this case, dataPrefix - * is ignored and can be NULL. - */ -U_CAPI void U_EXPORT2 -usrc_writeUTrie2Arrays(FILE *f, - const char *indexPrefix, const char *dataPrefix, - const UTrie2 *pTrie, - const char *postfix); - -/** - * Writes the UTrie2 struct values. - * The {} and declaration etc. need to be included in prefix/postfix or - * printed before and after the array contents. - */ -U_CAPI void U_EXPORT2 -usrc_writeUTrie2Struct(FILE *f, - const char *prefix, - const UTrie2 *pTrie, - const char *indexName, const char *dataName, - const char *postfix); - -/** - * Calls usrc_writeArray() for the index and data arrays of a UCPTrie. - */ -U_CAPI void U_EXPORT2 -usrc_writeUCPTrieArrays(FILE *f, - const char *indexPrefix, const char *dataPrefix, - const UCPTrie *pTrie, - const char *postfix); - -/** - * Writes the UCPTrie struct values. - * The {} and declaration etc. need to be included in prefix/postfix or - * printed before and after the array contents. - */ -U_CAPI void U_EXPORT2 -usrc_writeUCPTrieStruct(FILE *f, - const char *prefix, - const UCPTrie *pTrie, - const char *indexName, const char *dataName, - const char *postfix); - -/** - * Writes the UCPTrie arrays and struct values. - */ -U_CAPI void U_EXPORT2 -usrc_writeUCPTrie(FILE *f, const char *name, const UCPTrie *pTrie); - -/** - * Writes the contents of an array of mostly invariant characters. - * Characters 0..0x1f are printed as numbers, - * others as characters with single quotes: '%c'. - * - * The prefix and postfix are optional (can be NULL) and are written first/last. - * The prefix may contain a %ld or similar field for the array length. - * The {} and declaration etc. need to be included in prefix/postfix or - * printed before and after the array contents. - */ -U_CAPI void U_EXPORT2 -usrc_writeArrayOfMostlyInvChars(FILE *f, - const char *prefix, - const char *p, int32_t length, - const char *postfix); - -#endif diff --git a/deps/node/deps/icu-small/source/tools/toolutil/xmlparser.cpp b/deps/node/deps/icu-small/source/tools/toolutil/xmlparser.cpp deleted file mode 100644 index ae7ef170..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/xmlparser.cpp +++ /dev/null @@ -1,826 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2004-2010, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: xmlparser.cpp -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2004jul21 -* created by: Andy Heninger -*/ - -#include <stdio.h> -#include "unicode/uchar.h" -#include "unicode/ucnv.h" -#include "unicode/regex.h" -#include "filestrm.h" -#include "xmlparser.h" - -#if !UCONFIG_NO_REGULAR_EXPRESSIONS && !UCONFIG_NO_CONVERSION - -// character constants -enum { - x_QUOT=0x22, - x_AMP=0x26, - x_APOS=0x27, - x_LT=0x3c, - x_GT=0x3e, - x_l=0x6c -}; - -#define XML_SPACES "[ \\u0009\\u000d\\u000a]" - -// XML #4 -#define XML_NAMESTARTCHAR "[[A-Z]:_[a-z][\\u00c0-\\u00d6][\\u00d8-\\u00f6]" \ - "[\\u00f8-\\u02ff][\\u0370-\\u037d][\\u037F-\\u1FFF][\\u200C-\\u200D]" \ - "[\\u2070-\\u218F][\\u2C00-\\u2FEF][\\u3001-\\uD7FF][\\uF900-\\uFDCF]" \ - "[\\uFDF0-\\uFFFD][\\U00010000-\\U000EFFFF]]" - -// XML #5 -#define XML_NAMECHAR "[" XML_NAMESTARTCHAR "\\-.[0-9]\\u00b7[\\u0300-\\u036f][\\u203f-\\u2040]]" - -// XML #6 -#define XML_NAME XML_NAMESTARTCHAR "(?:" XML_NAMECHAR ")*" - -U_NAMESPACE_BEGIN - -UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UXMLParser) -UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UXMLElement) - -// -// UXMLParser constructor. Mostly just initializes the ICU regexes that are -// used for parsing. -// -UXMLParser::UXMLParser(UErrorCode &status) : - // XML Declaration. XML Production #23. - // example: "<?xml version=1.0 encoding="utf-16" ?> - // This is a sloppy implementation - just look for the leading <?xml and the closing ?> - // allow for a possible leading BOM. - mXMLDecl(UnicodeString("(?s)\\uFEFF?<\\?xml.+?\\?>", -1, US_INV), 0, status), - - // XML Comment production #15 - // example: "<!-- whatever --> - // note, does not detect an illegal "--" within comments - mXMLComment(UnicodeString("(?s)<!--.+?-->", -1, US_INV), 0, status), - - // XML Spaces - // production [3] - mXMLSP(UnicodeString(XML_SPACES "+", -1, US_INV), 0, status), - - // XML Doctype decl production #28 - // example "<!DOCTYPE foo SYSTEM "somewhere" > - // or "<!DOCTYPE foo [internal dtd]> - // TODO: we don't actually parse the DOCTYPE or internal subsets. - // Some internal dtd subsets could confuse this simple-minded - // attempt at skipping over them, specifically, occcurences - // of closeing square brackets. These could appear in comments, - // or in parameter entity declarations, for example. - mXMLDoctype(UnicodeString( - "(?s)<!DOCTYPE.*?(>|\\[.*?\\].*?>)", -1, US_INV - ), 0, status), - - // XML PI production #16 - // example "<?target stuff?> - mXMLPI(UnicodeString("(?s)<\\?.+?\\?>", -1, US_INV), 0, status), - - // XML Element Start Productions #40, #41 - // example <foo att1='abc' att2="d e f" > - // capture #1: the tag name - // - mXMLElemStart (UnicodeString("(?s)<(" XML_NAME ")" // match "<tag_name" - "(?:" - XML_SPACES "+" XML_NAME XML_SPACES "*=" XML_SPACES "*" // match "ATTR_NAME = " - "(?:(?:\\\'[^<\\\']*?\\\')|(?:\\\"[^<\\\"]*?\\\"))" // match '"attribute value"' - ")*" // * for zero or more attributes. - XML_SPACES "*?>", -1, US_INV), 0, status), // match " >" - - // XML Element End production #42 - // example </foo> - mXMLElemEnd (UnicodeString("</(" XML_NAME ")" XML_SPACES "*>", -1, US_INV), 0, status), - - // XML Element Empty production #44 - // example <foo att1="abc" att2="d e f" /> - mXMLElemEmpty (UnicodeString("(?s)<(" XML_NAME ")" // match "<tag_name" - "(?:" - XML_SPACES "+" XML_NAME XML_SPACES "*=" XML_SPACES "*" // match "ATTR_NAME = " - "(?:(?:\\\'[^<\\\']*?\\\')|(?:\\\"[^<\\\"]*?\\\"))" // match '"attribute value"' - ")*" // * for zero or more attributes. - XML_SPACES "*?/>", -1, US_INV), 0, status), // match " />" - - - // XMLCharData. Everything but '<'. Note that & will be dealt with later. - mXMLCharData(UnicodeString("(?s)[^<]*", -1, US_INV), 0, status), - - // Attribute name = "value". XML Productions 10, 40/41 - // Capture group 1 is name, - // 2 is the attribute value, including the quotes. - // - // Note that attributes are scanned twice. The first time is with - // the regex for an entire element start. There, the attributes - // are checked syntactically, but not separted out one by one. - // Here, we match a single attribute, and make its name and - // attribute value available to the parser code. - mAttrValue(UnicodeString(XML_SPACES "+(" XML_NAME ")" XML_SPACES "*=" XML_SPACES "*" - "((?:\\\'[^<\\\']*?\\\')|(?:\\\"[^<\\\"]*?\\\"))", -1, US_INV), 0, status), - - - mAttrNormalizer(UnicodeString(XML_SPACES, -1, US_INV), 0, status), - - // Match any of the new-line sequences in content. - // All are changed to \u000a. - mNewLineNormalizer(UnicodeString("\\u000d\\u000a|\\u000d\\u0085|\\u000a|\\u000d|\\u0085|\\u2028", -1, US_INV), 0, status), - - // & char references - // We will figure out what we've got based on which capture group has content. - // The last one is a catchall for unrecognized entity references.. - // 1 2 3 4 5 6 7 8 - mAmps(UnicodeString("&(?:(amp;)|(lt;)|(gt;)|(apos;)|(quot;)|#x([0-9A-Fa-f]{1,8});|#([0-9]{1,8});|(.))"), - 0, status), - - fNames(status), - fElementStack(status), - fOneLF((UChar)0x0a) // Plain new-line string, used in new line normalization. - { - } - -UXMLParser * -UXMLParser::createParser(UErrorCode &errorCode) { - if (U_FAILURE(errorCode)) { - return NULL; - } else { - return new UXMLParser(errorCode); - } -} - -UXMLParser::~UXMLParser() {} - -UXMLElement * -UXMLParser::parseFile(const char *filename, UErrorCode &errorCode) { - char bytes[4096], charsetBuffer[100]; - FileStream *f; - const char *charset, *pb; - UnicodeString src; - UConverter *cnv; - UChar *buffer, *pu; - int32_t fileLength, bytesLength, length, capacity; - UBool flush; - - if(U_FAILURE(errorCode)) { - return NULL; - } - - f=T_FileStream_open(filename, "rb"); - if(f==NULL) { - errorCode=U_FILE_ACCESS_ERROR; - return NULL; - } - - bytesLength=T_FileStream_read(f, bytes, (int32_t)sizeof(bytes)); - if(bytesLength<(int32_t)sizeof(bytes)) { - // we have already read the entire file - fileLength=bytesLength; - } else { - // get the file length - fileLength=T_FileStream_size(f); - } - - /* - * get the charset: - * 1. Unicode signature - * 2. treat as ISO-8859-1 and read XML encoding="charser" - * 3. default to UTF-8 - */ - charset=ucnv_detectUnicodeSignature(bytes, bytesLength, NULL, &errorCode); - if(U_SUCCESS(errorCode) && charset!=NULL) { - // open converter according to Unicode signature - cnv=ucnv_open(charset, &errorCode); - } else { - // read as Latin-1 and parse the XML declaration and encoding - cnv=ucnv_open("ISO-8859-1", &errorCode); - if(U_FAILURE(errorCode)) { - // unexpected error opening Latin-1 converter - goto exit; - } - - buffer=toUCharPtr(src.getBuffer(bytesLength)); - if(buffer==NULL) { - // unexpected failure to reserve some string capacity - errorCode=U_MEMORY_ALLOCATION_ERROR; - goto exit; - } - pb=bytes; - pu=buffer; - ucnv_toUnicode( - cnv, - &pu, buffer+src.getCapacity(), - &pb, bytes+bytesLength, - NULL, TRUE, &errorCode); - src.releaseBuffer(U_SUCCESS(errorCode) ? (int32_t)(pu-buffer) : 0); - ucnv_close(cnv); - cnv=NULL; - if(U_FAILURE(errorCode)) { - // unexpected error in conversion from Latin-1 - src.remove(); - goto exit; - } - - // parse XML declaration - if(mXMLDecl.reset(src).lookingAt(0, errorCode)) { - int32_t declEnd=mXMLDecl.end(errorCode); - // go beyond <?xml - int32_t pos=src.indexOf((UChar)x_l)+1; - - mAttrValue.reset(src); - while(pos<declEnd && mAttrValue.lookingAt(pos, errorCode)) { // loop runs once per attribute on this element. - UnicodeString attName = mAttrValue.group(1, errorCode); - UnicodeString attValue = mAttrValue.group(2, errorCode); - - // Trim the quotes from the att value. These are left over from the original regex - // that parsed the attribue, which couldn't conveniently strip them. - attValue.remove(0,1); // one char from the beginning - attValue.truncate(attValue.length()-1); // and one from the end. - - if(attName==UNICODE_STRING("encoding", 8)) { - length=attValue.extract(0, 0x7fffffff, charsetBuffer, (int32_t)sizeof(charsetBuffer)); - charset=charsetBuffer; - break; - } - pos = mAttrValue.end(2, errorCode); - } - - if(charset==NULL) { - // default to UTF-8 - charset="UTF-8"; - } - cnv=ucnv_open(charset, &errorCode); - } - } - - if(U_FAILURE(errorCode)) { - // unable to open the converter - goto exit; - } - - // convert the file contents - capacity=fileLength; // estimated capacity - src.getBuffer(capacity); - src.releaseBuffer(0); // zero length - flush=FALSE; - for(;;) { - // convert contents of bytes[bytesLength] - pb=bytes; - for(;;) { - length=src.length(); - buffer=toUCharPtr(src.getBuffer(capacity)); - if(buffer==NULL) { - // unexpected failure to reserve some string capacity - errorCode=U_MEMORY_ALLOCATION_ERROR; - goto exit; - } - - pu=buffer+length; - ucnv_toUnicode( - cnv, &pu, buffer+src.getCapacity(), - &pb, bytes+bytesLength, - NULL, FALSE, &errorCode); - src.releaseBuffer(U_SUCCESS(errorCode) ? (int32_t)(pu-buffer) : 0); - if(errorCode==U_BUFFER_OVERFLOW_ERROR) { - errorCode=U_ZERO_ERROR; - capacity=(3*src.getCapacity())/2; // increase capacity by 50% - } else { - break; - } - } - - if(U_FAILURE(errorCode)) { - break; // conversion error - } - - if(flush) { - break; // completely converted the file - } - - // read next block - bytesLength=T_FileStream_read(f, bytes, (int32_t)sizeof(bytes)); - if(bytesLength==0) { - // reached end of file, convert once more to flush the converter - flush=TRUE; - } - }; - -exit: - ucnv_close(cnv); - T_FileStream_close(f); - - if(U_SUCCESS(errorCode)) { - return parse(src, errorCode); - } else { - return NULL; - } -} - -UXMLElement * -UXMLParser::parse(const UnicodeString &src, UErrorCode &status) { - if(U_FAILURE(status)) { - return NULL; - } - - UXMLElement *root = NULL; - fPos = 0; // TODO use just a local pos variable and pass it into functions - // where necessary? - - // set all matchers to work on the input string - mXMLDecl.reset(src); - mXMLComment.reset(src); - mXMLSP.reset(src); - mXMLDoctype.reset(src); - mXMLPI.reset(src); - mXMLElemStart.reset(src); - mXMLElemEnd.reset(src); - mXMLElemEmpty.reset(src); - mXMLCharData.reset(src); - mAttrValue.reset(src); - mAttrNormalizer.reset(src); - mNewLineNormalizer.reset(src); - mAmps.reset(src); - - // Consume the XML Declaration, if present. - if (mXMLDecl.lookingAt(fPos, status)) { - fPos = mXMLDecl.end(status); - } - - // Consume "misc" [XML production 27] appearing before DocType - parseMisc(status); - - // Consume a DocType declaration, if present. - if (mXMLDoctype.lookingAt(fPos, status)) { - fPos = mXMLDoctype.end(status); - } - - // Consume additional "misc" [XML production 27] appearing after the DocType - parseMisc(status); - - // Get the root element - if (mXMLElemEmpty.lookingAt(fPos, status)) { - // Root is an empty element (no nested elements or content) - root = createElement(mXMLElemEmpty, status); - fPos = mXMLElemEmpty.end(status); - } else { - if (mXMLElemStart.lookingAt(fPos, status) == FALSE) { - error("Root Element expected", status); - goto errorExit; - } - root = createElement(mXMLElemStart, status); - UXMLElement *el = root; - - // - // This is the loop that consumes the root element of the document, - // including all nested content. Nested elements are handled by - // explicit pushes/pops of the element stack; there is no recursion - // in the control flow of this code. - // "el" always refers to the current element, the one to which content - // is being added. It is above the top of the element stack. - for (;;) { - // Nested Element Start - if (mXMLElemStart.lookingAt(fPos, status)) { - UXMLElement *t = createElement(mXMLElemStart, status); - el->fChildren.addElement(t, status); - t->fParent = el; - fElementStack.push(el, status); - el = t; - continue; - } - - // Text Content. String is concatenated onto the current node's content, - // but only if it contains something other than spaces. - UnicodeString s = scanContent(status); - if (s.length() > 0) { - mXMLSP.reset(s); - if (mXMLSP.matches(status) == FALSE) { - // This chunk of text contains something other than just - // white space. Make a child node for it. - replaceCharRefs(s, status); - el->fChildren.addElement(s.clone(), status); - } - mXMLSP.reset(src); // The matchers need to stay set to the main input string. - continue; - } - - // Comments. Discard. - if (mXMLComment.lookingAt(fPos, status)) { - fPos = mXMLComment.end(status); - continue; - } - - // PIs. Discard. - if (mXMLPI.lookingAt(fPos, status)) { - fPos = mXMLPI.end(status); - continue; - } - - // Element End - if (mXMLElemEnd.lookingAt(fPos, status)) { - fPos = mXMLElemEnd.end(0, status); - const UnicodeString name = mXMLElemEnd.group(1, status); - if (name != *el->fName) { - error("Element start / end tag mismatch", status); - goto errorExit; - } - if (fElementStack.empty()) { - // Close of the root element. We're done with the doc. - el = NULL; - break; - } - el = (UXMLElement *)fElementStack.pop(); - continue; - } - - // Empty Element. Stored as a child of the current element, but not stacked. - if (mXMLElemEmpty.lookingAt(fPos, status)) { - UXMLElement *t = createElement(mXMLElemEmpty, status); - el->fChildren.addElement(t, status); - continue; - } - - // Hit something within the document that doesn't match anything. - // It's an error. - error("Unrecognized markup", status); - break; - } - - if (el != NULL || !fElementStack.empty()) { - // We bailed out early, for some reason. - error("Root element not closed.", status); - goto errorExit; - } - } - - // Root Element parse is complete. - // Consume the annoying xml "Misc" that can appear at the end of the doc. - parseMisc(status); - - // We should have reached the end of the input - if (fPos != src.length()) { - error("Extra content at the end of the document", status); - goto errorExit; - } - - // Success! - return root; - -errorExit: - delete root; - return NULL; -} - -// -// createElement -// We've just matched an element start tag. Create and fill in a UXMLElement object -// for it. -// -UXMLElement * -UXMLParser::createElement(RegexMatcher &mEl, UErrorCode &status) { - // First capture group is the element's name. - UXMLElement *el = new UXMLElement(this, intern(mEl.group(1, status), status), status); - - // Scan for attributes. - int32_t pos = mEl.end(1, status); // The position after the end of the tag name - - while (mAttrValue.lookingAt(pos, status)) { // loop runs once per attribute on this element. - UnicodeString attName = mAttrValue.group(1, status); - UnicodeString attValue = mAttrValue.group(2, status); - - // Trim the quotes from the att value. These are left over from the original regex - // that parsed the attribue, which couldn't conveniently strip them. - attValue.remove(0,1); // one char from the beginning - attValue.truncate(attValue.length()-1); // and one from the end. - - // XML Attribue value normalization. - // This is one of the really screwy parts of the XML spec. - // See http://www.w3.org/TR/2004/REC-xml11-20040204/#AVNormalize - // Note that non-validating parsers must treat all entities as type CDATA - // which simplifies things some. - - // Att normalization step 1: normalize any newlines in the attribute value - mNewLineNormalizer.reset(attValue); - attValue = mNewLineNormalizer.replaceAll(fOneLF, status); - - // Next change all xml white space chars to plain \u0020 spaces. - mAttrNormalizer.reset(attValue); - UnicodeString oneSpace((UChar)0x0020); - attValue = mAttrNormalizer.replaceAll(oneSpace, status); - - // Replace character entities. - replaceCharRefs(attValue, status); - - // Save the attribute name and value in our document structure. - el->fAttNames.addElement((void *)intern(attName, status), status); - el->fAttValues.addElement(attValue.clone(), status); - pos = mAttrValue.end(2, status); - } - fPos = mEl.end(0, status); - return el; -} - -// -// parseMisc -// Consume XML "Misc" [production #27] -// which is any combination of space, PI and comments -// Need to watch end-of-input because xml MISC stuff is allowed after -// the document element, so we WILL scan off the end in this function -// -void -UXMLParser::parseMisc(UErrorCode &status) { - for (;;) { - if (fPos >= mXMLPI.input().length()) { - break; - } - if (mXMLPI.lookingAt(fPos, status)) { - fPos = mXMLPI.end(status); - continue; - } - if (mXMLSP.lookingAt(fPos, status)) { - fPos = mXMLSP.end(status); - continue; - } - if (mXMLComment.lookingAt(fPos, status)) { - fPos = mXMLComment.end(status); - continue; - } - break; - } -} - -// -// Scan for document content. -// -UnicodeString -UXMLParser::scanContent(UErrorCode &status) { - UnicodeString result; - if (mXMLCharData.lookingAt(fPos, status)) { - result = mXMLCharData.group((int32_t)0, status); - // Normalize the new-lines. (Before char ref substitution) - mNewLineNormalizer.reset(result); - result = mNewLineNormalizer.replaceAll(fOneLF, status); - - // TODO: handle CDATA - fPos = mXMLCharData.end(0, status); - } - - return result; -} - -// -// replaceCharRefs -// -// replace the char entities < & { ካ etc. in a string -// with the corresponding actual character. -// -void -UXMLParser::replaceCharRefs(UnicodeString &s, UErrorCode &status) { - UnicodeString result; - UnicodeString replacement; - int i; - - mAmps.reset(s); - // See the initialization for the regex matcher mAmps. - // Which entity we've matched is determined by which capture group has content, - // which is flaged by start() of that group not being -1. - while (mAmps.find()) { - if (mAmps.start(1, status) != -1) { - replacement.setTo((UChar)x_AMP); - } else if (mAmps.start(2, status) != -1) { - replacement.setTo((UChar)x_LT); - } else if (mAmps.start(3, status) != -1) { - replacement.setTo((UChar)x_GT); - } else if (mAmps.start(4, status) != -1) { - replacement.setTo((UChar)x_APOS); - } else if (mAmps.start(5, status) != -1) { - replacement.setTo((UChar)x_QUOT); - } else if (mAmps.start(6, status) != -1) { - UnicodeString hexString = mAmps.group(6, status); - UChar32 val = 0; - for (i=0; i<hexString.length(); i++) { - val = (val << 4) + u_digit(hexString.charAt(i), 16); - } - // TODO: some verification that the character is valid - replacement.setTo(val); - } else if (mAmps.start(7, status) != -1) { - UnicodeString decimalString = mAmps.group(7, status); - UChar32 val = 0; - for (i=0; i<decimalString.length(); i++) { - val = val*10 + u_digit(decimalString.charAt(i), 10); - } - // TODO: some verification that the character is valid - replacement.setTo(val); - } else { - // An unrecognized &entity; Leave it alone. - // TODO: check that it really looks like an entity, and is not some - // random & in the text. - replacement = mAmps.group((int32_t)0, status); - } - mAmps.appendReplacement(result, replacement, status); - } - mAmps.appendTail(result); - s = result; -} - -void -UXMLParser::error(const char *message, UErrorCode &status) { - // TODO: something better here... - const UnicodeString &src=mXMLDecl.input(); - int line = 0; - int ci = 0; - while (ci < fPos && ci>=0) { - ci = src.indexOf((UChar)0x0a, ci+1); - line++; - } - fprintf(stderr, "Error: %s at line %d\n", message, line); - if (U_SUCCESS(status)) { - status = U_PARSE_ERROR; - } -} - -// intern strings like in Java - -const UnicodeString * -UXMLParser::intern(const UnicodeString &s, UErrorCode &errorCode) { - const UHashElement *he=fNames.find(s); - if(he!=NULL) { - // already a known name, return its hashed key pointer - return (const UnicodeString *)he->key.pointer; - } else { - // add this new name and return its hashed key pointer - fNames.puti(s, 0, errorCode); - he=fNames.find(s); - return (const UnicodeString *)he->key.pointer; - } -} - -const UnicodeString * -UXMLParser::findName(const UnicodeString &s) const { - const UHashElement *he=fNames.find(s); - if(he!=NULL) { - // a known name, return its hashed key pointer - return (const UnicodeString *)he->key.pointer; - } else { - // unknown name - return NULL; - } -} - -// UXMLElement ------------------------------------------------------------- *** - -UXMLElement::UXMLElement(const UXMLParser *parser, const UnicodeString *name, UErrorCode &errorCode) : - fParser(parser), - fName(name), - fAttNames(errorCode), - fAttValues(errorCode), - fChildren(errorCode), - fParent(NULL) -{ -} - -UXMLElement::~UXMLElement() { - int i; - // attribute names are owned by the UXMLParser, don't delete them here - for (i=fAttValues.size()-1; i>=0; i--) { - delete (UObject *)fAttValues.elementAt(i); - } - for (i=fChildren.size()-1; i>=0; i--) { - delete (UObject *)fChildren.elementAt(i); - } -} - -const UnicodeString & -UXMLElement::getTagName() const { - return *fName; -} - -UnicodeString -UXMLElement::getText(UBool recurse) const { - UnicodeString text; - appendText(text, recurse); - return text; -} - -void -UXMLElement::appendText(UnicodeString &text, UBool recurse) const { - const UObject *node; - int32_t i, count=fChildren.size(); - for(i=0; i<count; ++i) { - node=(const UObject *)fChildren.elementAt(i); - const UnicodeString *s=dynamic_cast<const UnicodeString *>(node); - if(s!=NULL) { - text.append(*s); - } else if(recurse) /* must be a UXMLElement */ { - ((const UXMLElement *)node)->appendText(text, recurse); - } - } -} - -int32_t -UXMLElement::countAttributes() const { - return fAttNames.size(); -} - -const UnicodeString * -UXMLElement::getAttribute(int32_t i, UnicodeString &name, UnicodeString &value) const { - if(0<=i && i<fAttNames.size()) { - name.setTo(*(const UnicodeString *)fAttNames.elementAt(i)); - value.setTo(*(const UnicodeString *)fAttValues.elementAt(i)); - return &value; // or return (UnicodeString *)fAttValues.elementAt(i); - } else { - return NULL; - } -} - -const UnicodeString * -UXMLElement::getAttribute(const UnicodeString &name) const { - // search for the attribute name by comparing the interned pointer, - // not the string contents - const UnicodeString *p=fParser->findName(name); - if(p==NULL) { - return NULL; // no such attribute seen by the parser at all - } - - int32_t i, count=fAttNames.size(); - for(i=0; i<count; ++i) { - if(p==(const UnicodeString *)fAttNames.elementAt(i)) { - return (const UnicodeString *)fAttValues.elementAt(i); - } - } - return NULL; -} - -int32_t -UXMLElement::countChildren() const { - return fChildren.size(); -} - -const UObject * -UXMLElement::getChild(int32_t i, UXMLNodeType &type) const { - if(0<=i && i<fChildren.size()) { - const UObject *node=(const UObject *)fChildren.elementAt(i); - if(dynamic_cast<const UXMLElement *>(node)!=NULL) { - type=UXML_NODE_TYPE_ELEMENT; - } else { - type=UXML_NODE_TYPE_STRING; - } - return node; - } else { - return NULL; - } -} - -const UXMLElement * -UXMLElement::nextChildElement(int32_t &i) const { - if(i<0) { - return NULL; - } - - const UObject *node; - int32_t count=fChildren.size(); - while(i<count) { - node=(const UObject *)fChildren.elementAt(i++); - const UXMLElement *elem=dynamic_cast<const UXMLElement *>(node); - if(elem!=NULL) { - return elem; - } - } - return NULL; -} - -const UXMLElement * -UXMLElement::getChildElement(const UnicodeString &name) const { - // search for the element name by comparing the interned pointer, - // not the string contents - const UnicodeString *p=fParser->findName(name); - if(p==NULL) { - return NULL; // no such element seen by the parser at all - } - - const UObject *node; - int32_t i, count=fChildren.size(); - for(i=0; i<count; ++i) { - node=(const UObject *)fChildren.elementAt(i); - const UXMLElement *elem=dynamic_cast<const UXMLElement *>(node); - if(elem!=NULL) { - if(p==elem->fName) { - return elem; - } - } - } - return NULL; -} - -U_NAMESPACE_END - -#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */ diff --git a/deps/node/deps/icu-small/source/tools/toolutil/xmlparser.h b/deps/node/deps/icu-small/source/tools/toolutil/xmlparser.h deleted file mode 100644 index 72f7ec8f..00000000 --- a/deps/node/deps/icu-small/source/tools/toolutil/xmlparser.h +++ /dev/null @@ -1,247 +0,0 @@ -// © 2016 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html -/* -******************************************************************************* -* -* Copyright (C) 2004-2005, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -* file name: xmlparser.h -* encoding: UTF-8 -* tab size: 8 (not used) -* indentation:4 -* -* created on: 2004jul21 -* created by: Andy Heninger -* -* Tiny XML parser using ICU and intended for use in ICU tests and in build tools. -* Not suitable for production use. Not supported. -* Not conformant. Not efficient. -* But very small. -*/ - -#ifndef __XMLPARSER_H__ -#define __XMLPARSER_H__ - -#include "unicode/uobject.h" -#include "unicode/unistr.h" -#include "unicode/regex.h" -#include "uvector.h" -#include "hash.h" - -#if !UCONFIG_NO_REGULAR_EXPRESSIONS && !UCONFIG_NO_CONVERSION - -enum UXMLNodeType { - /** Node type string (text contents), stored as a UnicodeString. */ - UXML_NODE_TYPE_STRING, - /** Node type element, stored as a UXMLElement. */ - UXML_NODE_TYPE_ELEMENT, - UXML_NODE_TYPE_COUNT -}; - -U_NAMESPACE_BEGIN - -class UXMLParser; - -/** - * This class represents an element node in a parsed XML tree. - */ -class U_TOOLUTIL_API UXMLElement : public UObject { -public: - /** - * Destructor. - */ - virtual ~UXMLElement(); - - /** - * Get the tag name of this element. - */ - const UnicodeString &getTagName() const; - /** - * Get the text contents of the element. - * Append the contents of all text child nodes. - * @param recurse If TRUE, also recursively appends the contents of all - * text child nodes of element children. - * @return The text contents. - */ - UnicodeString getText(UBool recurse) const; - /** - * Get the number of attributes. - */ - int32_t countAttributes() const; - /** - * Get the i-th attribute. - * @param i Index of the attribute. - * @param name Output parameter, receives the attribute name. - * @param value Output parameter, receives the attribute value. - * @return A pointer to the attribute value (may be &value or a pointer to an - * internal string object), or NULL if i is out of bounds. - */ - const UnicodeString *getAttribute(int32_t i, UnicodeString &name, UnicodeString &value) const; - /** - * Get the value of the attribute with the given name. - * @param name Attribute name to be looked up. - * @return A pointer to the attribute value, or NULL if this element - * does not have this attribute. - */ - const UnicodeString *getAttribute(const UnicodeString &name) const; - /** - * Get the number of child nodes. - */ - int32_t countChildren() const; - /** - * Get the i-th child node. - * @param i Index of the child node. - * @param type The child node type. - * @return A pointer to the child node object, or NULL if i is out of bounds. - */ - const UObject *getChild(int32_t i, UXMLNodeType &type) const; - /** - * Get the next child element node, skipping non-element child nodes. - * @param i Enumeration index; initialize to 0 before getting the first child element. - * @return A pointer to the next child element, or NULL if there is none. - */ - const UXMLElement *nextChildElement(int32_t &i) const; - /** - * Get the immediate child element with the given name. - * If there are multiple child elements with this name, then return - * the first one. - * @param name Element name to be looked up. - * @return A pointer to the element node, or NULL if this element - * does not have this immediate child element. - */ - const UXMLElement *getChildElement(const UnicodeString &name) const; - - /** - * ICU "poor man's RTTI", returns a UClassID for the actual class. - */ - virtual UClassID getDynamicClassID() const; - - /** - * ICU "poor man's RTTI", returns a UClassID for this class. - */ - static UClassID U_EXPORT2 getStaticClassID(); - -private: - // prevent default construction etc. - UXMLElement(); - UXMLElement(const UXMLElement &other); - UXMLElement &operator=(const UXMLElement &other); - - void appendText(UnicodeString &text, UBool recurse) const; - - friend class UXMLParser; - - UXMLElement(const UXMLParser *parser, const UnicodeString *name, UErrorCode &errorCode); - - const UXMLParser *fParser; - const UnicodeString *fName; // The tag name of this element (owned by the UXMLParser) - UnicodeString fContent; // The text content of this node. All element content is - // concatenated even when there are intervening nested elements - // (which doesn't happen with most xml files we care about) - // Sections of content containing only white space are dropped, - // which gets rid the bogus white space content from - // elements which are primarily containers for nested elements. - UVector fAttNames; // A vector containing the names of this element's attributes - // The names are UnicodeString objects, owned by the UXMLParser. - UVector fAttValues; // A vector containing the attribute values for - // this element's attributes. The order is the same - // as that of the attribute name vector. - - UVector fChildren; // The child nodes of this element (a Vector) - - UXMLElement *fParent; // A pointer to the parent element of this element. -}; - -/** - * A simple XML parser; it is neither efficient nor conformant and only useful for - * restricted types of XML documents. - * - * The parse methods parse whole documents and return the parse trees via their - * root elements. - */ -class U_TOOLUTIL_API UXMLParser : public UObject { -public: - /** - * Create an XML parser. - */ - static UXMLParser *createParser(UErrorCode &errorCode); - /** - * Destructor. - */ - virtual ~UXMLParser(); - - /** - * Parse an XML document, create the entire document tree, and - * return a pointer to the root element of the parsed tree. - * The caller must delete the element. - */ - UXMLElement *parse(const UnicodeString &src, UErrorCode &errorCode); - /** - * Parse an XML file, create the entire document tree, and - * return a pointer to the root element of the parsed tree. - * The caller must delete the element. - */ - UXMLElement *parseFile(const char *filename, UErrorCode &errorCode); - - /** - * ICU "poor man's RTTI", returns a UClassID for the actual class. - */ - virtual UClassID getDynamicClassID() const; - - /** - * ICU "poor man's RTTI", returns a UClassID for this class. - */ - static UClassID U_EXPORT2 getStaticClassID(); - -private: - // prevent default construction etc. - UXMLParser(); - UXMLParser(const UXMLParser &other); - UXMLParser &operator=(const UXMLParser &other); - - // constructor - UXMLParser(UErrorCode &status); - - void parseMisc(UErrorCode &status); - UXMLElement *createElement(RegexMatcher &mEl, UErrorCode &status); - void error(const char *message, UErrorCode &status); - UnicodeString scanContent(UErrorCode &status); - void replaceCharRefs(UnicodeString &s, UErrorCode &status); - - const UnicodeString *intern(const UnicodeString &s, UErrorCode &errorCode); -public: - // public for UXMLElement only - const UnicodeString *findName(const UnicodeString &s) const; -private: - - // There is one ICU regex matcher for each of the major XML syntax items - // that are recognized. - RegexMatcher mXMLDecl; - RegexMatcher mXMLComment; - RegexMatcher mXMLSP; - RegexMatcher mXMLDoctype; - RegexMatcher mXMLPI; - RegexMatcher mXMLElemStart; - RegexMatcher mXMLElemEnd; - RegexMatcher mXMLElemEmpty; - RegexMatcher mXMLCharData; - RegexMatcher mAttrValue; - RegexMatcher mAttrNormalizer; - RegexMatcher mNewLineNormalizer; - RegexMatcher mAmps; - - Hashtable fNames; // interned element/attribute name strings - UStack fElementStack; // Stack holds the parent elements when nested - // elements are being parsed. All items on this - // stack are of type UXMLElement. - int32_t fPos; // String index of the current scan position in - // xml source (in fSrc). - UnicodeString fOneLF; -}; - -U_NAMESPACE_END -#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */ - -#endif |