27#include <rtl/ustring.hxx>
28#include <rtl/ustrbuf.hxx>
30#define MAX_ADDRESS 0x30000
31#define MAX_INDEX MAX_ADDRESS/0x100
39 if (argc < 4) exit(-1);
41 fp = fopen(argv[1],
"rb");
43 fprintf(stderr,
"Opening the rule source file %s for reading failed: %s\n", argv[1], strerror(errno));
52 OUStringBuffer
result(64*1024);
57 while (fgets(str, 1024, fp)) {
59 sal_Int32 len = strlen(str) - 1;
61 if (len == 0 || str[0] ==
'#')
65 OUString Ostr(str, len, RTL_TEXTENCODING_UTF8);
66 len = Ostr.getLength();
71 sal_uInt32 nChar = Ostr.iterateCodePoints(&
nPos, 2);
73 printf(
"Code point 0x%lx exceeds MAX_ADDRESS 0x%x, Please increase MAX_ADDRESS",
static_cast<long unsigned int>(nChar),
MAX_ADDRESS);
76 OUString key=Ostr.subView(
nPos)+sep;
78 if (key.getLength() >
max)
max=key.getLength();
82 address[nChar]=
result.getLength();
88 fp = fopen(argv[2],
"wb");
90 fprintf(stderr,
"Opening %s for writing failed: %s\n", argv[2], strerror(errno));
95 fprintf(fp,
" * Copyright(c) 1999 - 2006, Sun Microsystems, Inc.\n");
96 fprintf(fp,
" * All Rights Reserved.\n");
97 fprintf(fp,
" */\n\n");
98 fprintf(fp,
"/* !!!The file is generated automatically. DO NOT edit the file manually!!! */\n\n");
99 fprintf(fp,
"#include <sal/types.h>\n");
100 fprintf(fp,
"\nextern \"C\" {\n");
103 sal_Int32 max_index=0;
106 for (j=0; j<0x100; j++) {
107 if (address[
i*0x100+j] >=0) {
115 fprintf(fp,
"\nstatic const sal_uInt16 idx1[] = {");
116 for (
i = k = 0;
i <= max_index;
i++) {
117 if (k++ % 16 == 0) fprintf(fp,
"\n\t");
119 fp,
"0x%04lx, ", sal::static_int_cast< unsigned long >(
index[
i]));
121 fprintf(fp,
"\n};\n\n");
123 sal_Int32 len=
result.getLength();
124 fprintf(fp,
"\nstatic const sal_uInt16 idx2[] = {");
125 for (
i = k = 0;
i <= max_index;
i++) {
127 for (j = 0; j<0x100; j++) {
128 if (k++ % 16 == 0) fprintf(fp,
"\n\t");
129 sal_Int32 ad=address[
i*0x100+j];
132 sal::static_int_cast< unsigned long >(
133 ad == -1 ? 0 :
max == 2 ?
result[ad] : ad));
138 fprintf(fp,
"\n};\n\n");
141 fprintf(fp,
"\nstatic const sal_uInt16 *idx3 = NULL;\n\n");
143 fprintf(fp,
"\nstatic const sal_uInt16 idx3[] = {");
144 for (
i = k = 0;
i < len;
i++) {
145 if (k++ % 16 == 0) fprintf(fp,
"\n\t");
146 fprintf(fp,
"0x%04x, ", (sep.toChar() ==
result[
i]) ? 0 :
result[
i]);
148 fprintf(fp,
"\n};\n\n");
151 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));
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)