]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/toolutil/writesrc.c
2 *******************************************************************************
4 * Copyright (C) 2005-2010, 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"
28 usrc_createWithHeader(const char *path
, const char *filename
, const char *header
) {
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
);
58 fprintf(f
, header
, year
, filename
, buffer
);
62 "usrc_create(%s, %s): unable to create file\n",
63 path
!=NULL
? path
: "", filename
);
68 U_CAPI
FILE * U_EXPORT2
69 usrc_create(const char *path
, const char *filename
) {
72 " * Copyright (C) 1999-%s, International Business Machines\n"
73 " * Corporation and others. All Rights Reserved.\n"
77 " * machine-generated on: %s\n"
79 return usrc_createWithHeader(path
, filename
, header
);
82 U_CAPI
FILE * U_EXPORT2
83 usrc_createTextData(const char *path
, const char *filename
) {
85 "# Copyright (C) 1999-%s, International Business Machines\n"
86 "# Corporation and others. All Rights Reserved.\n"
90 "# machine-generated on: %s\n"
92 return usrc_createWithHeader(path
, filename
, header
);
96 usrc_writeArray(FILE *f
,
98 const void *p
, int32_t width
, int32_t length
,
99 const char *postfix
) {
111 p8
=(const uint8_t *)p
;
114 p16
=(const uint16_t *)p
;
117 p32
=(const uint32_t *)p
;
120 fprintf(stderr
, "usrc_writeArray(width=%ld) unrecognized width\n", (long)width
);
124 fprintf(f
, prefix
, (long)length
);
126 for(i
=col
=0; i
<length
; ++i
, ++col
) {
146 value
=0; /* unreachable */
149 fprintf(f
, value
<=9 ? "%lu" : "0x%lx", (unsigned long)value
);
156 U_CAPI
void U_EXPORT2
157 usrc_writeUTrie2Arrays(FILE *f
,
158 const char *indexPrefix
, const char *data32Prefix
,
160 const char *postfix
) {
161 if(pTrie
->data32
==NULL
) {
163 usrc_writeArray(f
, indexPrefix
, pTrie
->index
, 16, pTrie
->indexLength
+pTrie
->dataLength
, postfix
);
166 usrc_writeArray(f
, indexPrefix
, pTrie
->index
, 16, pTrie
->indexLength
, postfix
);
167 usrc_writeArray(f
, data32Prefix
, pTrie
->data32
, 32, pTrie
->dataLength
, postfix
);
171 U_CAPI
void U_EXPORT2
172 usrc_writeUTrie2Struct(FILE *f
,
175 const char *indexName
, const char *data32Name
,
176 const char *postfix
) {
180 if(pTrie
->data32
==NULL
) {
185 " %s+%ld,\n" /* data16 */
186 " NULL,\n", /* data32 */
189 (long)pTrie
->indexLength
);
195 " NULL,\n" /* data16 */
196 " %s,\n", /* data32 */
202 " %ld,\n" /* indexLength */
203 " %ld,\n" /* dataLength */
204 " 0x%hx,\n" /* index2NullOffset */
205 " 0x%hx,\n" /* dataNullOffset */
206 " 0x%lx,\n" /* initialValue */
207 " 0x%lx,\n" /* errorValue */
208 " 0x%lx,\n" /* highStart */
209 " 0x%lx,\n" /* highValueIndex */
210 " NULL, 0, FALSE, FALSE, 0, NULL\n",
211 (long)pTrie
->indexLength
, (long)pTrie
->dataLength
,
212 (short)pTrie
->index2NullOffset
, (short)pTrie
->dataNullOffset
,
213 (long)pTrie
->initialValue
, (long)pTrie
->errorValue
,
214 (long)pTrie
->highStart
, (long)pTrie
->highValueIndex
);