LCOV - code coverage report
Current view: top level - i18npool/source/textconversion - genconv_dict.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 252 264 95.5 %
Date: 2012-08-25 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 271 388 69.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include <stdio.h>
      22                 :            : #include <string.h>
      23                 :            : #include <stdlib.h>
      24                 :            : #include <errno.h>
      25                 :            : #include <sal/main.h>
      26                 :            : #include <sal/types.h>
      27                 :            : #include <rtl/strbuf.hxx>
      28                 :            : #include <rtl/ustring.hxx>
      29                 :            : 
      30                 :            : #include <vector>
      31                 :            : 
      32                 :            : using namespace ::rtl;
      33                 :            : 
      34                 :            : void make_hhc_char(FILE *sfp, FILE *cfp);
      35                 :            : void make_stc_char(FILE *sfp, FILE *cfp);
      36                 :            : void make_stc_word(FILE *sfp, FILE *cfp);
      37                 :            : 
      38                 :            : /* Main Procedure */
      39                 :            : 
      40                 :          3 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
      41                 :            : {
      42                 :            :     FILE *sfp, *cfp;
      43                 :            : 
      44         [ -  + ]:          3 :     if (argc < 4) exit(-1);
      45                 :            : 
      46                 :            : 
      47                 :          3 :     sfp = fopen(argv[2], "rb"); // open the source file for read;
      48         [ -  + ]:          3 :     if (sfp == NULL)
      49                 :            :     {
      50                 :          0 :         fprintf(stderr, "Opening the dictionary source file %s for reading failed: %s\n", argv[1], strerror(errno));
      51                 :          0 :         exit(1);
      52                 :            :     }
      53                 :            : 
      54                 :            :     // create the C source file to write
      55                 :          3 :     cfp = fopen(argv[3], "wb");
      56         [ -  + ]:          3 :     if (cfp == NULL) {
      57                 :          0 :         fclose(sfp);
      58                 :          0 :         fprintf(stderr, "Opening %s for writing failed: %s\n", argv[3], strerror(errno));
      59                 :          0 :         exit(1);
      60                 :            :     }
      61                 :            : 
      62                 :          3 :     fprintf(cfp, "/*\n");
      63                 :          3 :     fprintf(cfp, " * Copyright(c) 1999 - 2000, Sun Microsystems, Inc.\n");
      64                 :          3 :     fprintf(cfp, " * All Rights Reserved.\n");
      65                 :          3 :     fprintf(cfp, " */\n\n");
      66                 :          3 :     fprintf(cfp, "/* !!!The file is generated automatically. DONOT edit the file manually!!! */\n\n");
      67                 :          3 :     fprintf(cfp, "#include <sal/types.h>\n");
      68                 :          3 :     fprintf(cfp, "#include <textconversion.hxx>\n");
      69                 :          3 :     fprintf(cfp, "\nextern \"C\" {\n");
      70                 :            : 
      71         [ +  + ]:          3 :     if (strcmp(argv[1], "hhc_char") == 0)
      72                 :          1 :         make_hhc_char(sfp, cfp);
      73         [ +  + ]:          2 :     else if (strcmp(argv[1], "stc_char") == 0)
      74                 :          1 :         make_stc_char(sfp, cfp);
      75         [ +  - ]:          1 :     else if (strcmp(argv[1], "stc_word") == 0)
      76                 :          1 :         make_stc_word(sfp, cfp);
      77                 :            : 
      78                 :          3 :     fprintf (cfp, "}\n");
      79                 :            : 
      80                 :          3 :     fclose(sfp);
      81                 :          3 :     fclose(cfp);
      82                 :            : 
      83                 :          3 :     return 0;
      84                 :            : } // end of main
      85                 :            : 
      86                 :            : // Hangul/Hanja character conversion
      87                 :          1 : void make_hhc_char(FILE *sfp, FILE *cfp)
      88                 :            : {
      89                 :            :     sal_Int32 count, address, i, j, k;
      90                 :            :     sal_Unicode Hanja2HangulData[0x10000];
      91         [ +  + ]:      65537 :     for (i = 0; i < 0x10000; i++) {
      92                 :      65536 :         Hanja2HangulData[i] = 0;
      93                 :            :     }
      94                 :            :     sal_uInt16 Hangul2HanjaData[10000][3];
      95                 :            : 
      96                 :            :     // generate main dict. data array
      97         [ +  - ]:          1 :     fprintf(cfp, "\nstatic const sal_Unicode Hangul2HanjaData[] = {");
      98                 :            : 
      99                 :            :     sal_Char Cstr[1024];
     100                 :          1 :     count = 0;
     101                 :          1 :     address = 0;
     102 [ +  - ][ +  + ]:        503 :     while (fgets(Cstr, 1024, sfp)) {
     103                 :            :         // input file is in UTF-8 encoding (Hangul:Hanja)
     104                 :            :         // don't convert last new line character to Ostr.
     105         [ +  - ]:        502 :         OUString Ostr((const sal_Char *)Cstr, strlen(Cstr) - 1, RTL_TEXTENCODING_UTF8);
     106                 :        502 :         const sal_Unicode *Ustr = Ostr.getStr();
     107                 :        502 :         sal_Int32  len = Ostr.getLength();
     108                 :            : 
     109                 :        502 :         Hangul2HanjaData[count][0] = Ustr[0];
     110                 :        502 :         Hangul2HanjaData[count][1] = sal::static_int_cast<sal_uInt16>( address );
     111                 :        502 :         Hangul2HanjaData[count][2] = sal::static_int_cast<sal_uInt16>( len - 2 );
     112                 :        502 :         count++;
     113                 :            : 
     114         [ +  + ]:       9536 :         for (i = 2; i < len; i++) {
     115                 :       9034 :             Hanja2HangulData[Ustr[i]] = Ustr[0];
     116         [ +  + ]:       9034 :             if (address++ % 16 == 0)
     117         [ +  - ]:        565 :                 fprintf(cfp, "\n\t");
     118         [ +  - ]:       9034 :             fprintf(cfp, "0x%04x, ", Ustr[i]);
     119                 :            :         }
     120                 :        502 :     }
     121         [ +  - ]:          1 :     fprintf(cfp, "\n};\n");
     122                 :            : 
     123         [ +  - ]:          1 :     fprintf(cfp, "\nstatic const com::sun::star::i18n::Hangul_Index Hangul2HanjaIndex[] = {\n");
     124         [ +  + ]:        503 :     for (i = 0; i < count; i++)
     125                 :            :         fprintf(cfp, "\t{ 0x%04x, 0x%04x, 0x%02x },\n",
     126                 :        502 :                         Hangul2HanjaData[i][0],
     127                 :        502 :                         Hangul2HanjaData[i][1],
     128         [ +  - ]:        502 :                         Hangul2HanjaData[i][2]);
     129         [ +  - ]:          1 :     fprintf(cfp, "};\n");
     130                 :            : 
     131         [ +  - ]:          1 :     fprintf(cfp, "\nstatic const sal_uInt16 Hanja2HangulIndex[] = {");
     132                 :            : 
     133                 :          1 :     address=0;
     134         [ +  + ]:         17 :     for (i = 0; i < 0x10; i++) {
     135         [ +  - ]:         16 :         fprintf(cfp, "\n\t");
     136         [ +  + ]:        272 :         for (j = 0; j < 0x10; j++) {
     137         [ +  + ]:      44529 :             for (k = 0; k < 0x100; k++) {
     138         [ +  + ]:      44357 :                 if (Hanja2HangulData[((i*0x10)+j)*0x100+k] != 0)
     139                 :         84 :                     break;
     140                 :            :             }
     141                 :            :             fprintf(
     142                 :            :                 cfp, "0x%04lx, ",
     143                 :            :                 sal::static_int_cast< unsigned long >(
     144 [ +  + ][ +  - ]:        256 :                     k < 0x100 ? (address++)*0x100 : 0xFFFF));
     145                 :            :         }
     146                 :            :     }
     147         [ +  - ]:          1 :     fprintf(cfp, "\n};\n");
     148                 :            : 
     149         [ +  - ]:          1 :     fprintf(cfp, "\nstatic const sal_Unicode Hanja2HangulData[] = {");
     150                 :            : 
     151         [ +  + ]:        257 :     for (i = 0; i < 0x100; i++) {
     152         [ +  + ]:      44529 :         for (j = 0; j < 0x100; j++) {
     153         [ +  + ]:      44357 :             if (Hanja2HangulData[i*0x100+j] != 0)
     154                 :         84 :                 break;
     155                 :            :         }
     156         [ +  + ]:        256 :         if (j < 0x100) {
     157         [ +  + ]:       1428 :             for (j = 0; j < 0x10; j++) {
     158         [ +  - ]:       1344 :                 fprintf(cfp, "\n\t");
     159         [ +  + ]:      22848 :                 for (k = 0; k < 0x10; k++) {
     160                 :      21504 :                     sal_Unicode c = Hanja2HangulData[((i*0x10+j)*0x10)+k];
     161 [ +  + ][ +  - ]:      21504 :                     fprintf(cfp, "0x%04x, ", c ? c : 0xFFFF);
     162                 :            :                 }
     163                 :            :             }
     164                 :            :         }
     165                 :            :     }
     166         [ +  - ]:          1 :     fprintf(cfp, "\n};\n");
     167                 :            : 
     168                 :            :     // create function to return arrays
     169         [ +  - ]:          1 :     fprintf (cfp, "\tconst sal_Unicode* getHangul2HanjaData() { return Hangul2HanjaData; }\n");
     170         [ +  - ]:          1 :     fprintf (cfp, "\tconst com::sun::star::i18n::Hangul_Index* getHangul2HanjaIndex() { return Hangul2HanjaIndex; }\n");
     171         [ +  - ]:          1 :     fprintf (cfp, "\tsal_Int16 getHangul2HanjaIndexCount() { return sizeof(Hangul2HanjaIndex) / sizeof(com::sun::star::i18n::Hangul_Index); }\n");
     172         [ +  - ]:          1 :     fprintf (cfp, "\tconst sal_uInt16* getHanja2HangulIndex() { return Hanja2HangulIndex; }\n");
     173         [ +  - ]:          1 :     fprintf (cfp, "\tconst sal_Unicode* getHanja2HangulData() { return Hanja2HangulData; }\n");
     174                 :          1 : }
     175                 :            : 
     176                 :            : // Simplified/Traditional Chinese character conversion
     177                 :          1 : void make_stc_char(FILE *sfp, FILE *cfp)
     178                 :            : {
     179                 :            :     sal_Int32 address, i, j, k;
     180                 :            :     sal_Unicode SChinese2TChineseData[0x10000];
     181                 :            :     sal_Unicode SChinese2VChineseData[0x10000];
     182                 :            :     sal_Unicode TChinese2SChineseData[0x10000];
     183         [ +  + ]:      65537 :     for (i = 0; i < 0x10000; i++) {
     184                 :      65536 :         SChinese2TChineseData[i] = 0;
     185                 :      65536 :         SChinese2VChineseData[i] = 0;
     186                 :      65536 :         TChinese2SChineseData[i] = 0;
     187                 :            :     }
     188                 :            : 
     189                 :            :     sal_Char Cstr[1024];
     190 [ +  - ][ +  + ]:       2836 :     while (fgets(Cstr, 1024, sfp)) {
     191                 :            :         // input file is in UTF-8 encoding (SChinese:TChinese)
     192                 :            :         // don't convert last new line character to Ostr.
     193         [ +  - ]:       2835 :         OUString Ostr((const sal_Char *)Cstr, strlen(Cstr) - 1, RTL_TEXTENCODING_UTF8);
     194                 :       2835 :         const sal_Unicode *Ustr = Ostr.getStr();
     195                 :       2835 :         sal_Int32  len = Ostr.getLength();
     196         [ -  + ]:       2835 :         if (Ustr[1] == sal_Unicode('v'))
     197                 :          0 :             SChinese2VChineseData[Ustr[0]] = Ustr[2];
     198                 :            :         else {
     199                 :       2835 :             SChinese2TChineseData[Ustr[0]] = Ustr[2];
     200         [ +  - ]:       2835 :             if (SChinese2VChineseData[Ustr[0]] == 0)
     201                 :       2835 :                 SChinese2VChineseData[Ustr[0]] = Ustr[2];
     202                 :            :         }
     203         [ +  + ]:       6294 :         for (i = 2; i < len; i++)
     204                 :       3459 :             TChinese2SChineseData[Ustr[i]] = Ustr[0];
     205                 :       2835 :     }
     206                 :            : 
     207         [ +  - ]:          1 :     fprintf(cfp, "\nstatic const sal_uInt16 STC_CharIndex_S2T[] = {");
     208                 :            : 
     209                 :          1 :     address=0;
     210         [ +  + ]:         17 :     for (i = 0; i < 0x10; i++) {
     211         [ +  - ]:         16 :         fprintf(cfp, "\n\t");
     212         [ +  + ]:        272 :         for (j = 0; j < 0x10; j++) {
     213         [ +  + ]:      46134 :             for (k = 0; k < 0x100; k++) {
     214         [ +  + ]:      45965 :                 if (SChinese2TChineseData[((i*0x10)+j)*0x100+k] != 0)
     215                 :         87 :                     break;
     216                 :            :             }
     217                 :            :             fprintf(
     218                 :            :                 cfp, "0x%04lx, ",
     219                 :            :                 sal::static_int_cast< unsigned long >(
     220 [ +  + ][ +  - ]:        256 :                     k < 0x100 ? (address++)*0x100 : 0xFFFF));
     221                 :            :         }
     222                 :            :     }
     223         [ +  - ]:          1 :     fprintf(cfp, "\n};\n");
     224                 :            : 
     225         [ +  - ]:          1 :     fprintf(cfp, "\nstatic const sal_Unicode STC_CharData_S2T[] = {");
     226                 :            : 
     227         [ +  + ]:        257 :     for (i = 0; i < 0x100; i++) {
     228         [ +  + ]:      46134 :         for (j = 0; j < 0x100; j++) {
     229         [ +  + ]:      45965 :             if (SChinese2TChineseData[i*0x100+j] != 0)
     230                 :         87 :                 break;
     231                 :            :         }
     232         [ +  + ]:        256 :         if (j < 0x100) {
     233         [ +  + ]:       1479 :             for (j = 0; j < 0x10; j++) {
     234         [ +  - ]:       1392 :                 fprintf(cfp, "\n\t");
     235         [ +  + ]:      23664 :                 for (k = 0; k < 0x10; k++) {
     236                 :      22272 :                     sal_Unicode c = SChinese2TChineseData[((i*0x10+j)*0x10)+k];
     237 [ +  + ][ +  - ]:      22272 :                     fprintf(cfp, "0x%04x, ", c ? c : 0xFFFF);
     238                 :            :                 }
     239                 :            :             }
     240                 :            :         }
     241                 :            :     }
     242         [ +  - ]:          1 :     fprintf(cfp, "\n};\n");
     243                 :            : 
     244         [ +  - ]:          1 :     fprintf(cfp, "\nstatic const sal_uInt16 STC_CharIndex_S2V[] = {");
     245                 :            : 
     246                 :          1 :     address=0;
     247         [ +  + ]:         17 :     for (i = 0; i < 0x10; i++) {
     248         [ +  - ]:         16 :         fprintf(cfp, "\n\t");
     249         [ +  + ]:        272 :         for (j = 0; j < 0x10; j++) {
     250         [ +  + ]:      46134 :             for (k = 0; k < 0x100; k++) {
     251         [ +  + ]:      45965 :                 if (SChinese2VChineseData[((i*0x10)+j)*0x100+k] != 0)
     252                 :         87 :                     break;
     253                 :            :             }
     254                 :            :             fprintf(
     255                 :            :                 cfp, "0x%04lx, ",
     256                 :            :                 sal::static_int_cast< unsigned long >(
     257 [ +  + ][ +  - ]:        256 :                     k < 0x100 ? (address++)*0x100 : 0xFFFF));
     258                 :            :         }
     259                 :            :     }
     260         [ +  - ]:          1 :     fprintf(cfp, "\n};\n");
     261                 :            : 
     262         [ +  - ]:          1 :     fprintf(cfp, "\nstatic const sal_Unicode STC_CharData_S2V[] = {");
     263                 :            : 
     264         [ +  + ]:        257 :     for (i = 0; i < 0x100; i++) {
     265         [ +  + ]:      46134 :         for (j = 0; j < 0x100; j++) {
     266         [ +  + ]:      45965 :             if (SChinese2VChineseData[i*0x100+j] != 0)
     267                 :         87 :                 break;
     268                 :            :         }
     269         [ +  + ]:        256 :         if (j < 0x100) {
     270         [ +  + ]:       1479 :             for (j = 0; j < 0x10; j++) {
     271         [ +  - ]:       1392 :                 fprintf(cfp, "\n\t");
     272         [ +  + ]:      23664 :                 for (k = 0; k < 0x10; k++) {
     273                 :      22272 :                     sal_Unicode c = SChinese2VChineseData[((i*0x10+j)*0x10)+k];
     274 [ +  + ][ +  - ]:      22272 :                     fprintf(cfp, "0x%04x, ", c ? c : 0xFFFF);
     275                 :            :                 }
     276                 :            :             }
     277                 :            :         }
     278                 :            :     }
     279         [ +  - ]:          1 :     fprintf(cfp, "\n};\n");
     280                 :            : 
     281         [ +  - ]:          1 :     fprintf(cfp, "\nstatic const sal_uInt16 STC_CharIndex_T2S[] = {");
     282                 :            : 
     283                 :          1 :     address=0;
     284         [ +  + ]:         17 :     for (i = 0; i < 0x10; i++) {
     285         [ +  - ]:         16 :         fprintf(cfp, "\n\t");
     286         [ +  + ]:        272 :         for (j = 0; j < 0x10; j++) {
     287         [ +  + ]:      43562 :             for (k = 0; k < 0x100; k++) {
     288         [ +  + ]:      43399 :                 if (TChinese2SChineseData[((i*0x10)+j)*0x100+k] != 0)
     289                 :         93 :                     break;
     290                 :            :             }
     291                 :            :             fprintf(
     292                 :            :                 cfp, "0x%04lx, ",
     293                 :            :                 sal::static_int_cast< unsigned long >(
     294 [ +  + ][ +  - ]:        256 :                     k < 0x100 ? (address++)*0x100 : 0xFFFF));
     295                 :            :         }
     296                 :            :     }
     297         [ +  - ]:          1 :     fprintf(cfp, "\n};\n");
     298                 :            : 
     299         [ +  - ]:          1 :     fprintf(cfp, "\nstatic const sal_Unicode STC_CharData_T2S[] = {");
     300                 :            : 
     301         [ +  + ]:        257 :     for (i = 0; i < 0x100; i++) {
     302         [ +  + ]:      43562 :         for (j = 0; j < 0x100; j++) {
     303         [ +  + ]:      43399 :             if (TChinese2SChineseData[i*0x100+j] != 0)
     304                 :         93 :                 break;
     305                 :            :         }
     306         [ +  + ]:        256 :         if (j < 0x100) {
     307         [ +  + ]:       1581 :             for (j = 0; j < 0x10; j++) {
     308         [ +  - ]:       1488 :                 fprintf(cfp, "\n\t");
     309         [ +  + ]:      25296 :                 for (k = 0; k < 0x10; k++) {
     310                 :      23808 :                     sal_Unicode c = TChinese2SChineseData[((i*0x10+j)*0x10)+k];
     311 [ +  + ][ +  - ]:      23808 :                     fprintf(cfp, "0x%04x, ", c ? c : 0xFFFF);
     312                 :            :                 }
     313                 :            :             }
     314                 :            :         }
     315                 :            :     }
     316         [ +  - ]:          1 :     fprintf(cfp, "\n};\n");
     317                 :            : 
     318                 :            :     // create function to return arrays
     319         [ +  - ]:          1 :     fprintf (cfp, "\tconst sal_uInt16* getSTC_CharIndex_S2T() { return STC_CharIndex_S2T; }\n");
     320         [ +  - ]:          1 :     fprintf (cfp, "\tconst sal_Unicode* getSTC_CharData_S2T() { return STC_CharData_S2T; }\n");
     321         [ +  - ]:          1 :     fprintf (cfp, "\tconst sal_uInt16* getSTC_CharIndex_S2V() { return STC_CharIndex_S2V; }\n");
     322         [ +  - ]:          1 :     fprintf (cfp, "\tconst sal_Unicode* getSTC_CharData_S2V() { return STC_CharData_S2V; }\n");
     323         [ +  - ]:          1 :     fprintf (cfp, "\tconst sal_uInt16* getSTC_CharIndex_T2S() { return STC_CharIndex_T2S; }\n");
     324         [ +  - ]:          1 :     fprintf (cfp, "\tconst sal_Unicode* getSTC_CharData_T2S() { return STC_CharData_T2S; }\n");
     325                 :          1 : }
     326                 :            : 
     327                 :            : 
     328                 :            : typedef struct {
     329                 :            :     sal_uInt16 address;
     330                 :            :     sal_Int32 len;
     331                 :            :     sal_Unicode *data;
     332                 :            : } Index;
     333                 :            : 
     334                 :            : extern "C" {
     335                 :      13982 : int Index_comp(const void* s1, const void* s2)
     336                 :            : {
     337                 :      13982 :     Index *p1 = (Index*)s1, *p2 = (Index*)s2;
     338                 :      13982 :     int result = p1->len - p2->len;
     339 [ +  + ][ +  + ]:      24177 :     for (int i = 0; result == 0 && i < p1->len; i++)
                 [ +  + ]
     340                 :      10195 :         result = *(p1->data+i) - *(p2->data+i);
     341                 :      13982 :     return result;
     342                 :            : }
     343                 :            : }
     344                 :            : 
     345                 :            : // Simplified/Traditional Chinese word conversion
     346                 :          1 : void make_stc_word(FILE *sfp, FILE *cfp)
     347                 :            : {
     348                 :            :     sal_Int32 count, i, length;
     349                 :            :     sal_Unicode STC_WordData[0x10000];
     350         [ +  - ]:          1 :     std::vector<Index> STC_WordEntry_S2T(0x10000);
     351         [ +  - ]:          1 :     std::vector<Index> STC_WordEntry_T2S(0x10000);
     352                 :          1 :     sal_Int32 count_S2T = 0, count_T2S = 0;
     353                 :          1 :     sal_Int32 line = 0, char_total = 0;
     354                 :            :     sal_Char Cstr[1024];
     355                 :            : 
     356 [ +  - ][ +  + ]:       1151 :     while (fgets(Cstr, 1024, sfp)) {
     357                 :            :         // input file is in UTF-8 encoding (SChinese:TChinese)
     358                 :            :         // don't convert last new line character to Ostr.
     359         [ +  - ]:       1150 :         OUString Ostr((const sal_Char *)Cstr, strlen(Cstr) - 1, RTL_TEXTENCODING_UTF8);
     360                 :       1150 :         sal_Int32  len = Ostr.getLength();
     361         [ -  + ]:       1150 :         if (char_total + len + 1 > 0xFFFF) {
     362         [ #  # ]:          0 :             fprintf(stderr, "Word Dictionary stc_word.dic is too big (line %ld)", sal::static_int_cast< long >(line));
     363                 :            :             return;
     364                 :            :         }
     365                 :       1150 :         sal_Int32 sep=-1, eq=-1, gt=-1, lt=-1;
     366 [ +  + ][ +  + ]:       1150 :         if (((sep = eq = Ostr.indexOf(sal_Unicode('='))) > 0) ||
         [ +  - ][ +  - ]
     367                 :            :             ((sep = gt = Ostr.indexOf(sal_Unicode('>'))) > 0) ||
     368                 :            :             ((sep = lt = Ostr.indexOf(sal_Unicode('<'))) > 0)) {
     369                 :            : 
     370 [ +  + ][ +  + ]:       1150 :             if (eq > 0 || gt > 0) {
     371                 :       1070 :                 STC_WordEntry_S2T[count_S2T].address = sal::static_int_cast<sal_uInt16>( char_total );
     372                 :       1070 :                 STC_WordEntry_S2T[count_S2T].len = sep;
     373                 :       1070 :                 STC_WordEntry_S2T[count_S2T++].data = &STC_WordData[char_total];
     374                 :            :             }
     375 [ +  + ][ +  + ]:       1150 :             if (eq > 0 || lt > 0) {
     376                 :        615 :                 STC_WordEntry_T2S[count_T2S].address = sal::static_int_cast<sal_uInt16>( char_total + sep + 1 );
     377                 :        615 :                 STC_WordEntry_T2S[count_T2S].len = len - sep - 1;
     378                 :        615 :                 STC_WordEntry_T2S[count_T2S++].data = &STC_WordData[char_total + sep + 1];
     379                 :            :             }
     380         [ +  + ]:       8299 :             for (i = 0; i < len; i++)
     381         [ +  + ]:       7149 :                 STC_WordData[char_total++] = (i == sep) ? 0 : Ostr[i];
     382                 :       1150 :             STC_WordData[char_total++] = 0;
     383                 :            :         } else {
     384         [ #  # ]:          0 :             fprintf(stderr, "Invalid entry in stc_word.dic (line %ld)", sal::static_int_cast< long >(line));
     385                 :            :             return;
     386                 :            :         }
     387         [ +  - ]:       2300 :         line++;
     388                 :       1150 :     }
     389                 :            : 
     390         [ +  - ]:          1 :     if (char_total > 0) {
     391         [ +  - ]:          1 :         fprintf(cfp, "\nstatic const sal_Unicode STC_WordData[] = {");
     392         [ +  + ]:       8300 :         for (i = 0; i < char_total; i++) {
     393 [ +  + ][ +  - ]:       8299 :             if (i % 32 == 0) fprintf(cfp, "\n\t");
     394         [ +  - ]:       8299 :             fprintf(cfp, "0x%04x, ", STC_WordData[i]);
     395                 :            :         }
     396         [ +  - ]:          1 :         fprintf(cfp, "\n};\n");
     397                 :            : 
     398         [ +  - ]:          1 :         fprintf(cfp, "\nstatic sal_Int32 STC_WordData_Count = %ld;\n", sal::static_int_cast< long >(char_total));
     399                 :            : 
     400                 :            :         // create function to return arrays
     401         [ +  - ]:          1 :         fprintf (cfp, "\tconst sal_Unicode* getSTC_WordData(sal_Int32& count) { count = STC_WordData_Count; return STC_WordData; }\n");
     402                 :            :     } else {
     403         [ #  # ]:          0 :         fprintf (cfp, "\tconst sal_Unicode* getSTC_WordData(sal_Int32& count) { count = 0; return NULL; }\n");
     404                 :            :     }
     405                 :            : 
     406                 :            :     sal_uInt16 STC_WordIndex[0x100];
     407                 :            : 
     408         [ +  - ]:          1 :     if (count_S2T > 0) {
     409         [ +  - ]:          1 :         qsort(&STC_WordEntry_S2T[0], count_S2T, sizeof(Index), Index_comp);
     410                 :            : 
     411         [ +  - ]:          1 :         fprintf(cfp, "\nstatic const sal_uInt16 STC_WordEntry_S2T[] = {");
     412                 :          1 :         count = 0;
     413                 :          1 :         length = 0;
     414         [ +  + ]:       1071 :         for (i = 0; i < count_S2T; i++) {
     415 [ +  + ][ +  - ]:       1070 :             if (i % 32 == 0) fprintf(cfp, "\n\t");
     416         [ +  - ]:       1070 :             fprintf(cfp, "0x%04x, ", STC_WordEntry_S2T[i].address);
     417         [ +  + ]:       1070 :             if (STC_WordEntry_S2T[i].len != length) {
     418                 :          8 :                 length = STC_WordEntry_S2T[i].len;
     419         [ +  + ]:         17 :                 while (count <= length)
     420                 :          9 :                     STC_WordIndex[count++] = sal::static_int_cast<sal_uInt16>(i);
     421                 :            :             }
     422                 :            :         }
     423         [ +  - ]:          1 :         fprintf(cfp, "\n};\n");
     424                 :          1 :         STC_WordIndex[count++] = sal::static_int_cast<sal_uInt16>(i);
     425                 :            : 
     426         [ +  - ]:          1 :         fprintf(cfp, "\nstatic const sal_uInt16 STC_WordIndex_S2T[] = {");
     427         [ +  + ]:         11 :         for (i = 0; i < count; i++) {
     428 [ +  + ][ +  - ]:         10 :             if (i % 16 == 0) fprintf(cfp, "\n\t");
     429         [ +  - ]:         10 :             fprintf(cfp, "0x%04x, ", STC_WordIndex[i]);
     430                 :            :         }
     431         [ +  - ]:          1 :         fprintf(cfp, "\n};\n");
     432                 :            : 
     433         [ +  - ]:          1 :         fprintf(cfp, "\nstatic sal_Int32 STC_WordIndex_S2T_Count = %ld;\n", sal::static_int_cast< long >(length));
     434         [ +  - ]:          1 :         fprintf (cfp, "\tconst sal_uInt16* getSTC_WordEntry_S2T() { return STC_WordEntry_S2T; }\n");
     435         [ +  - ]:          1 :         fprintf (cfp, "\tconst sal_uInt16* getSTC_WordIndex_S2T(sal_Int32& count) { count = STC_WordIndex_S2T_Count; return STC_WordIndex_S2T; }\n");
     436                 :            :     } else {
     437         [ #  # ]:          0 :         fprintf (cfp, "\tconst sal_uInt16* getSTC_WordEntry_S2T() { return NULL; }\n");
     438         [ #  # ]:          0 :         fprintf (cfp, "\tconst sal_uInt16* getSTC_WordIndex_S2T(sal_Int32& count) { count = 0; return NULL; }\n");
     439                 :            :     }
     440                 :            : 
     441         [ +  - ]:          1 :     if (count_T2S > 0) {
     442         [ +  - ]:          1 :         qsort(&STC_WordEntry_T2S[0], count_T2S, sizeof(Index), Index_comp);
     443                 :            : 
     444         [ +  - ]:          1 :         fprintf(cfp, "\nstatic const sal_uInt16 STC_WordEntry_T2S[] = {");
     445                 :          1 :         count = 0;
     446                 :          1 :         length = 0;
     447         [ +  + ]:        616 :         for (i = 0; i < count_T2S; i++) {
     448 [ +  + ][ +  - ]:        615 :             if (i % 32 == 0) fprintf(cfp, "\n\t");
     449         [ +  - ]:        615 :             fprintf(cfp, "0x%04x, ", STC_WordEntry_T2S[i].address);
     450         [ +  + ]:        615 :             if (STC_WordEntry_T2S[i].len != length) {
     451                 :         10 :                 length = STC_WordEntry_T2S[i].len;
     452         [ +  + ]:         21 :                 while (count <= length)
     453                 :         11 :                     STC_WordIndex[count++] = sal::static_int_cast<sal_uInt16>(i);
     454                 :            :             }
     455                 :            :         }
     456                 :          1 :         STC_WordIndex[count++] = sal::static_int_cast<sal_uInt16>(i);
     457         [ +  - ]:          1 :         fprintf(cfp, "\n};\n");
     458                 :            : 
     459         [ +  - ]:          1 :         fprintf(cfp, "\nstatic const sal_uInt16 STC_WordIndex_T2S[] = {");
     460         [ +  + ]:         13 :         for (i = 0; i < count; i++) {
     461 [ +  + ][ +  - ]:         12 :             if (i % 16 == 0) fprintf(cfp, "\n\t");
     462         [ +  - ]:         12 :             fprintf(cfp, "0x%04x, ",  STC_WordIndex[i]);
     463                 :            :         }
     464         [ +  - ]:          1 :         fprintf(cfp, "\n};\n");
     465                 :            : 
     466         [ +  - ]:          1 :         fprintf(cfp, "\nstatic sal_Int32 STC_WordIndex_T2S_Count = %ld;\n\n", sal::static_int_cast< long >(length));
     467         [ +  - ]:          1 :         fprintf (cfp, "\tconst sal_uInt16* getSTC_WordEntry_T2S() { return STC_WordEntry_T2S; }\n");
     468         [ +  - ]:          1 :         fprintf (cfp, "\tconst sal_uInt16* getSTC_WordIndex_T2S(sal_Int32& count) { count = STC_WordIndex_T2S_Count; return STC_WordIndex_T2S; }\n");
     469                 :            :     } else {
     470         [ #  # ]:          0 :         fprintf (cfp, "\tconst sal_uInt16* getSTC_WordEntry_T2S() { return NULL; }\n");
     471         [ #  # ]:          1 :         fprintf (cfp, "\tconst sal_uInt16* getSTC_WordIndex_T2S(sal_Int32& count) { count = 0; return NULL; }\n");
     472 [ -  + ][ +  - ]:          1 :     }
     473                 :            : }
     474                 :            : 
     475                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10