1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 *
6 *   Copyright (C) 2005-2012, International Business Machines
7 *   Corporation and others.  All Rights Reserved.
8 *
9 *******************************************************************************
10 *   file name:  writesrc.h
11 *   encoding:   UTF-8
12 *   tab size:   8 (not used)
13 *   indentation:4
14 *
15 *   created on: 2005apr23
16 *   created by: Markus W. Scherer
17 *
18 *   Helper functions for writing source code for data.
19 */
20 
21 #ifndef __WRITESRC_H__
22 #define __WRITESRC_H__
23 
24 #include <stdio.h>
25 #include "unicode/utypes.h"
26 #include "unicode/ucptrie.h"
27 #include "utrie2.h"
28 
29 /**
30  * Creates a source text file and writes a header comment with the ICU copyright.
31  * Writes a C/Java-style comment with the generator name.
32  */
33 U_CAPI FILE * U_EXPORT2
34 usrc_create(const char *path, const char *filename, int32_t copyrightYear, const char *generator);
35 
36 /**
37  * Creates a source text file and writes a header comment with the ICU copyright.
38  * Writes the comment with # lines, as used in scripts and text data.
39  */
40 U_CAPI FILE * U_EXPORT2
41 usrc_createTextData(const char *path, const char *filename, const char *generator);
42 
43 /**
44  * Writes the contents of an array of 8/16/32-bit words.
45  * The prefix and postfix are optional (can be NULL) and are written first/last.
46  * The prefix may contain a %ld or similar field for the array length.
47  * The {} and declaration etc. need to be included in prefix/postfix or
48  * printed before and after the array contents.
49  */
50 U_CAPI void U_EXPORT2
51 usrc_writeArray(FILE *f,
52                 const char *prefix,
53                 const void *p, int32_t width, int32_t length,
54                 const char *postfix);
55 
56 /**
57  * Calls usrc_writeArray() for the index and data arrays of a frozen UTrie2.
58  * Only the index array is written for a 16-bit UTrie2. In this case, dataPrefix
59  * is ignored and can be NULL.
60  */
61 U_CAPI void U_EXPORT2
62 usrc_writeUTrie2Arrays(FILE *f,
63                        const char *indexPrefix, const char *dataPrefix,
64                        const UTrie2 *pTrie,
65                        const char *postfix);
66 
67 /**
68  * Writes the UTrie2 struct values.
69  * The {} and declaration etc. need to be included in prefix/postfix or
70  * printed before and after the array contents.
71  */
72 U_CAPI void U_EXPORT2
73 usrc_writeUTrie2Struct(FILE *f,
74                        const char *prefix,
75                        const UTrie2 *pTrie,
76                        const char *indexName, const char *dataName,
77                        const char *postfix);
78 
79 /**
80  * Calls usrc_writeArray() for the index and data arrays of a UCPTrie.
81  */
82 U_CAPI void U_EXPORT2
83 usrc_writeUCPTrieArrays(FILE *f,
84                         const char *indexPrefix, const char *dataPrefix,
85                         const UCPTrie *pTrie,
86                         const char *postfix);
87 
88 /**
89  * Writes the UCPTrie struct values.
90  * The {} and declaration etc. need to be included in prefix/postfix or
91  * printed before and after the array contents.
92  */
93 U_CAPI void U_EXPORT2
94 usrc_writeUCPTrieStruct(FILE *f,
95                         const char *prefix,
96                         const UCPTrie *pTrie,
97                         const char *indexName, const char *dataName,
98                         const char *postfix);
99 
100 /**
101  * Writes the UCPTrie arrays and struct values.
102  */
103 U_CAPI void U_EXPORT2
104 usrc_writeUCPTrie(FILE *f, const char *name, const UCPTrie *pTrie);
105 
106 /**
107  * Writes the contents of an array of mostly invariant characters.
108  * Characters 0..0x1f are printed as numbers,
109  * others as characters with single quotes: '%c'.
110  *
111  * The prefix and postfix are optional (can be NULL) and are written first/last.
112  * The prefix may contain a %ld or similar field for the array length.
113  * The {} and declaration etc. need to be included in prefix/postfix or
114  * printed before and after the array contents.
115  */
116 U_CAPI void U_EXPORT2
117 usrc_writeArrayOfMostlyInvChars(FILE *f,
118                                 const char *prefix,
119                                 const char *p, int32_t length,
120                                 const char *postfix);
121 
122 #endif
123