#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 *generator, const char *header) {
+ const char *header, const char *generator) {
char buffer[1024];
const char *p;
char *q;
}
U_CAPI FILE * U_EXPORT2
-usrc_create(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=
- "// © 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";
- return usrc_createWithHeader(path, filename, generator, header);
+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
"#\n"
"# machine-generated by: %s\n"
"\n\n";
- return usrc_createWithHeader(path, filename, generator, header);
+ return usrc_createWithHeader(path, filename, header, generator);
}
U_CAPI void U_EXPORT2
}
}
+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,