1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: genindex_data.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
38 #include <sal/types.h>
39 #include <rtl/ustring.hxx>
41 #define MAX_ADDRESS 0x30000
42 #define MAX_INDEX MAX_ADDRESS/0x100
44 using namespace ::rtl
;
48 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
52 if (argc
< 4) exit(-1);
54 fp
= fopen(argv
[1], "rb"); // open the source file for read;
56 printf("Open the rule source file failed.");
62 sal_Int32 address
[MAX_ADDRESS
];
63 for (i
=0; i
<MAX_ADDRESS
; i
++) address
[i
]=-1;
64 OUString sep
=OUString(sal_Unicode('|'));
69 while (fgets(str
, 1024, fp
)) {
70 // don't convert last new line character to Ostr.
71 sal_Int32 len
= strlen(str
) - 1;
73 if (len
== 0 || str
[0] == '#')
76 // input file is in UTF-8 encoding
77 OUString Ostr
= OUString((const sal_Char
*)str
, len
, RTL_TEXTENCODING_UTF8
);
78 len
= Ostr
.getLength();
80 continue; // skip empty line.
83 sal_uInt32 nChar
= Ostr
.iterateCodePoints(&nPos
, 2);
84 if (nChar
> MAX_ADDRESS
) {
85 printf("Code point 0x%lx exceeds MAX_ADDRESS 0x%x, Please increase MAX_ADDRESS", static_cast<long unsigned int>(nChar
), MAX_ADDRESS
);
88 OUString key
=Ostr
.copy(nPos
)+sep
;
89 sal_Int32 idx
= result
.indexOf(key
);
90 if (key
.getLength() > max
) max
=key
.getLength();
94 address
[nChar
]=result
.getLength();
100 fp
= fopen(argv
[2], "wb");
102 printf("Can't create the C source file.");
107 fprintf(fp
, " * Copyright(c) 1999 - 2006, Sun Microsystems, Inc.\n");
108 fprintf(fp
, " * All Rights Reserved.\n");
109 fprintf(fp
, " */\n\n");
110 fprintf(fp
, "/* !!!The file is generated automatically. DONOT edit the file manually!!! */\n\n");
111 fprintf(fp
, "#include <sal/types.h>\n");
112 fprintf(fp
, "\nextern \"C\" {\n");
114 sal_Int32 index
[MAX_INDEX
];
115 sal_Int32 max_index
=0;
116 for (i
=k
=0; i
<MAX_INDEX
; i
++) {
118 for (j
=0; j
<0x100; j
++) {
119 if (address
[i
*0x100+j
] >=0) {
127 fprintf(fp
, "\nstatic const sal_uInt16 idx1[] = {");
128 for (i
= k
= 0; i
<= max_index
; i
++) {
129 if (k
++ % 16 == 0) fprintf(fp
, "\n\t");
131 fp
, "0x%04lx, ", sal::static_int_cast
< unsigned long >(index
[i
]));
133 fprintf(fp
, "\n};\n\n");
135 sal_Int32 len
=result
.getLength();
136 const sal_Unicode
*ustr
=result
.getStr();
137 fprintf(fp
, "\nstatic const sal_uInt16 idx2[] = {");
138 for (i
= k
= 0; i
<= max_index
; i
++) {
139 if (index
[i
] != 0xFFFF) {
140 for (j
= 0; j
<0x100; j
++) {
141 if (k
++ % 16 == 0) fprintf(fp
, "\n\t");
142 sal_Int32 ad
=address
[i
*0x100+j
];
145 sal::static_int_cast
< unsigned long >(
146 ad
== -1 ? 0 : max
== 2 ? ustr
[ad
] : ad
));
151 fprintf(fp
, "\n};\n\n");
154 fprintf(fp
, "\nstatic const sal_uInt16 *idx3 = NULL;\n\n");
156 fprintf(fp
, "\nstatic const sal_uInt16 idx3[] = {");
157 for (i
= k
= 0; i
< len
; i
++) {
158 if (k
++ % 16 == 0) fprintf(fp
, "\n\t");
159 fprintf(fp
, "0x%04x, ", (sep
.toChar() == ustr
[i
]) ? 0 : ustr
[i
]);
161 fprintf(fp
, "\n};\n\n");
164 fprintf(fp
, "const sal_uInt16** get_%s(sal_Int16 &max_index)\n{\n\tstatic const sal_uInt16 *idx[]={idx1, idx2, idx3};\n\tmax_index=0x%x;\n\treturn idx;\n}\n\n", argv
[3], static_cast<unsigned int>(max_index
));