]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/toolutil/writesrc.c
2 *******************************************************************************
4 * Copyright (C) 2005, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: writesrc.c
10 * tab size: 8 (not used)
13 * created on: 2005apr23
14 * created by: Markus W. Scherer
16 * Helper functions for writing source code for data.
21 #include "unicode/utypes.h"
22 #include "unicode/putil.h"
27 U_CAPI
FILE * U_EXPORT2
28 usrc_create(const char *path
, const char *filename
) {
38 /* concatenate path and filename, with U_FILE_SEP_CHAR in between if necessary */
39 uprv_strcpy(buffer
, path
);
40 q
=buffer
+uprv_strlen(buffer
);
41 if(q
>buffer
&& (c
=*(q
-1))!=U_FILE_SEP_CHAR
&& c
!=U_FILE_ALT_SEP_CHAR
) {
44 uprv_strcpy(q
, filename
);
56 strftime(year
, sizeof(year
), "%Y", lt
);
57 strftime(buffer
, sizeof(buffer
), "%Y-%m-%d", lt
);
61 " * Copyright (C) 1999-%s, International Business Machines\n"
62 " * Corporation and others. All Rights Reserved.\n"
66 " * machine-generated on: %s\n"
74 "usrc_create(%s, %s): unable to create file\n",
75 path
!=NULL
? path
: NULL
, filename
);
81 usrc_writeArray(FILE *f
,
83 const void *p
, int32_t width
, int32_t length
,
84 const char *postfix
) {
96 p8
=(const uint8_t *)p
;
99 p16
=(const uint16_t *)p
;
102 p32
=(const uint32_t *)p
;
105 fprintf(stderr
, "usrc_writeArray(width=%ld) unrecognized width\n", (long)width
);
109 fprintf(f
, prefix
, (long)length
);
111 for(i
=col
=0; i
<length
; ++i
, ++col
) {
131 value
=0; /* unreachable */
134 fprintf(f
, value
<=9 ? "%lu" : "0x%lx", (unsigned long)value
);
141 U_CAPI
void U_EXPORT2
142 usrc_writeUTrieArrays(FILE *f
,
143 const char *indexPrefix
, const char *dataPrefix
,
145 const char *postfix
) {
146 if(pTrie
->data32
==NULL
) {
148 usrc_writeArray(f
, indexPrefix
, pTrie
->index
, 16, pTrie
->indexLength
+pTrie
->dataLength
, postfix
);
151 usrc_writeArray(f
, indexPrefix
, pTrie
->index
, 16, pTrie
->indexLength
, postfix
);
152 usrc_writeArray(f
, dataPrefix
, pTrie
->data32
, 32, pTrie
->dataLength
, postfix
);
156 U_CAPI
void U_EXPORT2
157 usrc_writeUTrieStruct(FILE *f
,
160 const char *indexName
, const char *dataName
,
161 const char *getFoldingOffsetName
,
162 const char *postfix
) {
169 if(getFoldingOffsetName
==NULL
) {
170 getFoldingOffsetName
="utrie_defaultGetFoldingOffset";
183 getFoldingOffsetName
,
184 (long)pTrie
->indexLength
, (long)pTrie
->dataLength
,
185 (unsigned long)pTrie
->initialValue
,
186 pTrie
->isLatin1Linear
? "TRUE" : "FALSE");