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

Generated by: LCOV version 1.10