LCOV - code coverage report
Current view: top level - i18npool/source/localedata - filewriter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 113 126 89.7 %
Date: 2012-08-25 Functions: 21 25 84.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 26 48 54.2 %

           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                 :            : #include <stdio.h>
      21                 :            : #include <string.h>
      22                 :            : #include "LocaleNode.hxx"
      23                 :            : //-----------------------------------------
      24                 :            : // The document handler, which is needed for the saxparser
      25                 :            : // The Documenthandler for reading sax
      26                 :            : //-----------------------------------------
      27                 :        197 : OFileWriter::OFileWriter(const char *pcFile, const char *locale ) {
      28                 :            : 
      29                 :        197 :     strncpy( m_pcFile , pcFile, sizeof(m_pcFile) );
      30                 :        197 :     m_pcFile[sizeof(m_pcFile)-1] = 0;
      31                 :        197 :     printf("file generated=%s\n", m_pcFile);
      32                 :        197 :     m_f = fopen( m_pcFile , "w" );
      33                 :        197 :     strncpy( theLocale, locale, sizeof(theLocale) );
      34                 :        197 :     theLocale[sizeof(theLocale)-1] = 0;
      35                 :        197 : }
      36                 :            : 
      37                 :        197 : OFileWriter::~OFileWriter() {
      38         [ -  + ]:        197 :     if(m_f)
      39                 :          0 :         fclose( m_f );
      40         [ -  + ]:        197 : }
      41                 :            : 
      42                 :     149923 : void OFileWriter::writeInt(sal_Int16 nb) const
      43                 :            : {
      44                 :     149923 :     fprintf(m_f, "%d", nb);
      45                 :     149923 : }
      46                 :            : 
      47                 :     349031 : void OFileWriter::writeAsciiString(const char* str) const
      48                 :            : {
      49                 :     349031 :     fprintf(m_f, "%s", str);
      50                 :     349031 : }
      51                 :            : 
      52                 :      89204 : void OFileWriter::writeStringCharacters(const ::rtl::OUString& str) const
      53                 :            : {
      54         [ +  + ]:     550160 :     for(int i = 0; i < str.getLength(); i++)
      55                 :     460956 :         fprintf(m_f, "0x%x, ", str[i]);
      56                 :      89204 : }
      57                 :            : 
      58                 :       1867 : void OFileWriter::writeFunction(const char *func, const char *count, const char *array) const
      59                 :            : {
      60                 :       1867 :     fprintf(m_f, "sal_Unicode **  SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
      61                 :       1867 :     fprintf(m_f, "\tcount = %s;\n", count);
      62                 :       1867 :     fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
      63                 :       1867 : }
      64                 :            : 
      65                 :       1088 : void OFileWriter::writeRefFunction(const char *func, const ::rtl::OUString& useLocale) const
      66                 :            : {
      67         [ +  - ]:       1088 :     OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
      68                 :       1088 :     const char* locale = aRefLocale.getStr();
      69         [ +  - ]:       1088 :     fprintf(m_f, "extern sal_Unicode **  SAL_CALL %s%s(sal_Int16& count);\n", func, locale);
      70         [ +  - ]:       1088 :     fprintf(m_f, "sal_Unicode **  SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
      71         [ +  - ]:       1088 :     fprintf(m_f, "\treturn %s%s(count);\n}\n", func, locale);
      72                 :       1088 : }
      73                 :            : 
      74                 :        147 : void OFileWriter::writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const
      75                 :            : {
      76                 :        147 :     fprintf(m_f, "sal_Unicode **  SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale);
      77                 :        147 :     fprintf(m_f, "\tcount = %s;\n", count);
      78                 :        147 :     fprintf(m_f, "\tfrom = %s;\n", from);
      79                 :        147 :     fprintf(m_f, "\tto = %s;\n", to);
      80                 :        147 :     fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
      81                 :        147 : }
      82                 :            : 
      83                 :         51 : void OFileWriter::writeRefFunction(const char *func, const ::rtl::OUString& useLocale, const char *to) const
      84                 :            : {
      85         [ +  - ]:         51 :     OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
      86                 :         51 :     const char* locale = aRefLocale.getStr();
      87         [ +  - ]:         51 :     fprintf(m_f, "extern sal_Unicode **  SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to);\n", func, locale);
      88         [ +  - ]:         51 :     fprintf(m_f, "sal_Unicode **  SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale);
      89         [ +  - ]:         51 :     fprintf(m_f, "\tto = %s;\n", to);
      90         [ +  - ]:         51 :     fprintf(m_f, "\tconst sal_Unicode* tmp;\n");
      91         [ +  - ]:         51 :     fprintf(m_f, "\treturn %s%s(count, from, tmp);\n}\n", func, locale);
      92                 :         51 : }
      93                 :            : 
      94                 :         67 : void OFileWriter::writeFunction2(const char *func, const char *style, const char* attr, const char *array) const
      95                 :            : {
      96                 :         67 :     fprintf(m_f, "const sal_Unicode ***  SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nAttributes )\n{\n", func, theLocale);
      97                 :         67 :     fprintf(m_f, "\tnStyles     = %s;\n", style);
      98                 :         67 :     fprintf(m_f, "\tnAttributes = %s;\n", attr);
      99                 :         67 :     fprintf(m_f, "\treturn %s;\n}\n", array);
     100                 :         67 : }
     101                 :            : 
     102                 :        130 : void OFileWriter::writeRefFunction2(const char *func, const ::rtl::OUString& useLocale) const
     103                 :            : {
     104         [ +  - ]:        130 :     OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
     105                 :        130 :     const char* locale = aRefLocale.getStr();
     106         [ +  - ]:        130 :     fprintf(m_f, "extern const sal_Unicode ***  SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes);\n", func, locale);
     107         [ +  - ]:        130 :     fprintf(m_f, "const sal_Unicode ***  SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes)\n{\n", func, theLocale);
     108         [ +  - ]:        130 :     fprintf(m_f, "\treturn %s%s(nStyles, nAttributes);\n}\n", func, locale);
     109                 :        130 : }
     110                 :            : 
     111                 :         27 : void OFileWriter::writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const
     112                 :            : {
     113                 :         27 :     fprintf(m_f, "const sal_Unicode ****  SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes )\n{\n", func, theLocale);
     114                 :         27 :     fprintf(m_f, "\tnStyles     = %s;\n", style);
     115                 :         27 :     fprintf(m_f, "\tnLevels     = %s;\n", levels);
     116                 :         27 :     fprintf(m_f, "\tnAttributes = %s;\n", attr);
     117                 :         27 :     fprintf(m_f, "\treturn %s;\n}\n", array);
     118                 :         27 : }
     119                 :            : 
     120                 :        170 : void OFileWriter::writeRefFunction3(const char *func, const ::rtl::OUString& useLocale) const
     121                 :            : {
     122         [ +  - ]:        170 :     OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
     123                 :        170 :     const char* locale = aRefLocale.getStr();
     124         [ +  - ]:        170 :     fprintf(m_f, "extern const sal_Unicode ****  SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes);\n", func, locale);
     125         [ +  - ]:        170 :     fprintf(m_f, "const sal_Unicode ****  SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes)\n{\n", func, theLocale);
     126         [ +  - ]:        170 :     fprintf(m_f, "\treturn %s%s(nStyles, nLevels, nAttributes);\n}\n", func, locale);
     127                 :        170 : }
     128                 :            : 
     129                 :       7398 : void OFileWriter::writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const
     130                 :            : {
     131                 :       7398 :     fprintf(m_f, "static const sal_Unicode %s%d[] = {%d};\n", pAsciiStr, count, val);
     132                 :       7398 : }
     133                 :            : 
     134                 :       8272 : bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str, sal_Int16 count) const
     135                 :            : {
     136         [ +  + ]:       8272 :     bool bBool = (str == "true" ? 1 : 0);
     137                 :       8272 :     fprintf(m_f,"static const sal_Unicode default%s%d[] = {%d};\n", pAsciiStr, count, bBool);
     138                 :       8272 :     return bBool;
     139                 :            : }
     140                 :            : 
     141                 :          0 : bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str) const
     142                 :            : {
     143         [ #  # ]:          0 :     bool bBool = (str == "true" ? 1 : 0);
     144                 :          0 :     fprintf(m_f,"static const sal_Unicode default%s[] = {%d};\n", pAsciiStr, bBool);
     145                 :          0 :     return bBool;
     146                 :            : }
     147                 :            : 
     148                 :       4859 : void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const
     149                 :            : {
     150                 :       4859 :     fprintf(m_f, "static const sal_Unicode %s[] = {", pAsciiStr);
     151                 :       4859 :     writeStringCharacters(aChars);
     152                 :       4859 :     fprintf(m_f, "0x0};\n");
     153                 :       4859 : }
     154                 :            : 
     155                 :      40098 : void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count) const
     156                 :            : {
     157                 :      40098 :     fprintf(m_f, "static const sal_Unicode %s%d[] = {", pAsciiStr, count);
     158                 :      40098 :     writeStringCharacters(aChars);
     159                 :      40098 :     fprintf(m_f, "0x0};\n");
     160                 :      40098 : }
     161                 :            : 
     162                 :       7382 : void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
     163                 :            : {
     164                 :       7382 :     fprintf(m_f, "static const sal_Unicode %s%d%d[] = {", pAsciiStr, count0, count1);
     165                 :       7382 :     writeStringCharacters(aChars);
     166                 :       7382 :     fprintf(m_f, "0x0};\n");
     167                 :       7382 : }
     168                 :            : 
     169                 :       2730 : void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, const sal_Int16 count) const
     170                 :            : {
     171                 :       2730 :     fprintf(m_f, "static const sal_Unicode %s%s%d[] = {", pTagStr, pAsciiStr, count);
     172                 :       2730 :     writeStringCharacters(aChars);
     173                 :       2730 :     fprintf(m_f, "0x0};\n");
     174                 :       2730 : }
     175                 :            : 
     176                 :          0 : void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const
     177                 :            : {
     178                 :          0 :     fprintf(m_f, "static const sal_Unicode %s%s[] = {", pTagStr, pAsciiStr);
     179                 :          0 :     writeStringCharacters(aChars);
     180                 :          0 :     fprintf(m_f, "0x0};\n");
     181                 :          0 : }
     182                 :            : 
     183                 :      34135 : void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
     184                 :            : {
     185                 :      34135 :     fprintf(m_f, "static const sal_Unicode %s%s%d%d[] = {", pTagStr, pAsciiStr, count0, count1);
     186                 :      34135 :     writeStringCharacters(aChars);
     187                 :      34135 :     fprintf(m_f, "0x0};\n");
     188                 :      34135 : }
     189                 :            : 
     190                 :          0 : void OFileWriter::flush(void) const
     191                 :            : {
     192                 :          0 :     fflush( m_f );
     193                 :          0 : }
     194                 :            : 
     195                 :        394 : void OFileWriter::closeOutput(void) const
     196                 :            : {
     197         [ +  + ]:        394 :     if(m_f)
     198                 :            :     {
     199                 :        197 :         fclose( m_f );
     200                 :        197 :         const_cast< OFileWriter * > ( this )->m_f = 0;
     201                 :            :     }
     202                 :        394 : }
     203                 :            : 
     204                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10