LCOV - code coverage report
Current view: top level - i18npool/source/indexentry - genindex_data.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 70 78 89.7 %
Date: 2014-11-03 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          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/ustring.hxx>
      28             : 
      29             : #define MAX_ADDRESS 0x30000
      30             : #define MAX_INDEX MAX_ADDRESS/0x100
      31             : 
      32             : /* Main Procedure */
      33             : 
      34          20 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
      35             : {
      36             :     FILE *fp;
      37             : 
      38          10 :     if (argc < 4) exit(-1);
      39             : 
      40          10 :     fp = fopen(argv[1], "rb");  // open the source file for read;
      41          10 :     if (fp == NULL) {
      42           0 :         fprintf(stderr, "Opening the rule source file %s for reading failed: %s\n", argv[1], strerror(errno));
      43           0 :         exit(1);
      44             :     }
      45             : 
      46             : 
      47             :     sal_Int32 i, j, k;
      48             :     sal_Int32 address[MAX_ADDRESS];
      49          10 :     for (i=0; i<MAX_ADDRESS; i++) address[i]=-1;
      50          10 :     OUString sep=OUString('|');
      51          20 :     OUString result=sep;
      52          10 :     sal_Int32 max=0;
      53             : 
      54             :     sal_Char str[1024];
      55      211809 :     while (fgets(str, 1024, fp)) {
      56             :         // don't convert last new line character to Ostr.
      57      211789 :         sal_Int32 len = strlen(str) - 1;
      58             :         // skip comment line
      59      211789 :         if (len == 0 || str[0] == '#')
      60           0 :             continue;
      61             : 
      62             :         // input file is in UTF-8 encoding
      63      211789 :         OUString Ostr = OUString((const sal_Char *)str, len, RTL_TEXTENCODING_UTF8);
      64      211789 :         len = Ostr.getLength();
      65      211789 :         if (len == 0)
      66           0 :             continue; // skip empty line.
      67             : 
      68      211789 :         sal_Int32 nPos=0;
      69      211789 :         sal_uInt32 nChar = Ostr.iterateCodePoints(&nPos, 2);
      70      211789 :         if (nChar >= MAX_ADDRESS) {
      71           0 :             printf("Code point 0x%lx exceeds MAX_ADDRESS 0x%x, Please increase MAX_ADDRESS", static_cast<long unsigned int>(nChar), MAX_ADDRESS);
      72           0 :             exit(1);
      73             :         }
      74      423578 :         OUString key=Ostr.copy(nPos)+sep;
      75      211789 :         sal_Int32 idx = result.indexOf(key);
      76      211789 :         if (key.getLength() > max) max=key.getLength();
      77      211789 :         if (idx >= 0) {
      78      199303 :             address[nChar]=idx;
      79             :         } else {
      80       12486 :             address[nChar]=result.getLength();
      81       12486 :             result+=key;
      82             :         }
      83      211789 :     }
      84          10 :     fclose(fp);
      85             : 
      86          10 :     fp = fopen(argv[2], "wb");
      87          10 :     if (fp == NULL) {
      88           0 :         fprintf(stderr, "Opening %s for writing failed: %s\n", argv[2], strerror(errno));
      89           0 :         exit(1);
      90             :     }
      91             : 
      92          10 :     fprintf(fp, "/*\n");
      93          10 :     fprintf(fp, " * Copyright(c) 1999 - 2006, Sun Microsystems, Inc.\n");
      94          10 :     fprintf(fp, " * All Rights Reserved.\n");
      95          10 :     fprintf(fp, " */\n\n");
      96          10 :     fprintf(fp, "/* !!!The file is generated automatically. DONOT edit the file manually!!! */\n\n");
      97          10 :     fprintf(fp, "#include <sal/types.h>\n");
      98          10 :     fprintf(fp, "\nextern \"C\" {\n");
      99             : 
     100             :     sal_Int32 index[MAX_INDEX];
     101          10 :     sal_Int32 max_index=0;
     102        7690 :     for (i=k=0; i<MAX_INDEX; i++) {
     103        7680 :         index[i] = 0xFFFF;
     104     1718852 :         for (j=0; j<0x100; j++) {
     105     1712176 :             if (address[i*0x100+j] >=0) {
     106        1004 :                 max_index=i;
     107        1004 :                 index[i]=0x100*k++;
     108        1004 :                 break;
     109             :             }
     110             :         }
     111             :     }
     112             : 
     113          10 :     fprintf(fp, "\nstatic const sal_uInt16 idx1[] = {");
     114        2156 :     for (i = k = 0; i <= max_index;  i++) {
     115        2146 :         if (k++ % 16 == 0) fprintf(fp, "\n\t");
     116             :         fprintf(
     117        2146 :             fp, "0x%04lx, ", sal::static_int_cast< unsigned long >(index[i]));
     118             :     }
     119          10 :     fprintf(fp, "\n};\n\n");
     120             : 
     121          10 :     sal_Int32 len=result.getLength();
     122          10 :     const sal_Unicode *ustr=result.getStr();
     123          10 :     fprintf(fp, "\nstatic const sal_uInt16 idx2[] = {");
     124        2156 :     for (i = k = 0; i <= max_index; i++) {
     125        2146 :         if (index[i] != 0xFFFF) {
     126      258028 :             for (j = 0; j<0x100; j++) {
     127      257024 :                 if (k++ % 16 == 0) fprintf(fp, "\n\t");
     128      257024 :                 sal_Int32 ad=address[i*0x100+j];
     129             :                 fprintf(
     130             :                     fp, "0x%04lx, ",
     131             :                     sal::static_int_cast< unsigned long >(
     132      257024 :                         ad == -1 ? 0 : max == 2 ? ustr[ad] : ad));
     133             :             }
     134        1004 :             fprintf(fp, "\n\t");
     135             :         }
     136             :     }
     137          10 :     fprintf(fp, "\n};\n\n");
     138             : 
     139          10 :     if (max == 2) {
     140           4 :         fprintf(fp, "\nstatic const sal_uInt16 *idx3 = NULL;\n\n");
     141             :     } else {
     142           6 :         fprintf(fp, "\nstatic const sal_uInt16 idx3[] = {");
     143        4605 :         for (i = k = 0; i < len;  i++) {
     144        4599 :             if (k++ % 16 == 0) fprintf(fp, "\n\t");
     145        4599 :             fprintf(fp, "0x%04x, ", (sep.toChar() == ustr[i]) ? 0 : ustr[i]);
     146             :         }
     147           6 :         fprintf(fp, "\n};\n\n");
     148             :     }
     149             : 
     150          10 :     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));
     151          10 :     fprintf (fp, "}\n");
     152             : 
     153          10 :     fclose(fp);
     154          20 :     return 0;
     155             : }   // End of main
     156             : 
     157             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10