LCOV - code coverage report
Current view: top level - i18npool/source/localedata - filewriter.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 113 114 99.1 %
Date: 2014-11-03 Functions: 21 21 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             : #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         241 : OFileWriter::OFileWriter(const char *pcFile, const char *locale ) {
      28             : 
      29         241 :     strncpy( m_pcFile , pcFile, sizeof(m_pcFile) );
      30         241 :     m_pcFile[sizeof(m_pcFile)-1] = 0;
      31         241 :     printf("file generated=%s\n", m_pcFile);
      32         241 :     m_f = fopen( m_pcFile , "w" );
      33         241 :     strncpy( theLocale, locale, sizeof(theLocale) );
      34         241 :     theLocale[sizeof(theLocale)-1] = 0;
      35         241 : }
      36             : 
      37         241 : OFileWriter::~OFileWriter() {
      38         241 :     if(m_f)
      39           0 :         fclose( m_f );
      40         241 : }
      41             : 
      42      170745 : void OFileWriter::writeInt(sal_Int16 nb) const
      43             : {
      44      170745 :     fprintf(m_f, "%d", nb);
      45      170745 : }
      46             : 
      47      397028 : void OFileWriter::writeAsciiString(const char* str) const
      48             : {
      49      397028 :     fprintf(m_f, "%s", str);
      50      397028 : }
      51             : 
      52      101719 : void OFileWriter::writeStringCharacters(const OUString& str) const
      53             : {
      54      623767 :     for(int i = 0; i < str.getLength(); i++)
      55      522048 :         fprintf(m_f, "0x%x, ", str[i]);
      56      101719 : }
      57             : 
      58        2340 : void OFileWriter::writeFunction(const char *func, const char *count, const char *array) const
      59             : {
      60        2340 :     fprintf(m_f, "sal_Unicode **  SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
      61        2340 :     fprintf(m_f, "\tcount = %s;\n", count);
      62        2340 :     fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
      63        2340 : }
      64             : 
      65        1275 : void OFileWriter::writeRefFunction(const char *func, const OUString& useLocale) const
      66             : {
      67        1275 :     OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
      68        1275 :     const char* locale = aRefLocale.getStr();
      69        1275 :     fprintf(m_f, "extern sal_Unicode **  SAL_CALL %s%s(sal_Int16& count);\n", func, locale);
      70        1275 :     fprintf(m_f, "sal_Unicode **  SAL_CALL %s%s(sal_Int16& count)\n{\n", func, theLocale);
      71        1275 :     fprintf(m_f, "\treturn %s%s(count);\n}\n", func, locale);
      72        1275 : }
      73             : 
      74         159 : void OFileWriter::writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const
      75             : {
      76         159 :     fprintf(m_f, "sal_Unicode const * const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale);
      77         159 :     fprintf(m_f, "\tcount = %s;\n", count);
      78         159 :     fprintf(m_f, "\tfrom = %s;\n", from);
      79         159 :     fprintf(m_f, "\tto = %s;\n", to);
      80         159 :     fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array);
      81         159 : }
      82             : 
      83          83 : void OFileWriter::writeRefFunction(const char *func, const OUString& useLocale, const char *to) const
      84             : {
      85          83 :     OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
      86          83 :     const char* locale = aRefLocale.getStr();
      87          83 :     fprintf(m_f, "extern sal_Unicode const * const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to);\n", func, locale);
      88          83 :     fprintf(m_f, "sal_Unicode const * const * SAL_CALL %s%s(sal_Int16& count, const sal_Unicode*& from, const sal_Unicode*& to)\n{\n", func, theLocale);
      89          83 :     fprintf(m_f, "\tto = %s;\n", to);
      90          83 :     fprintf(m_f, "\tconst sal_Unicode* tmp;\n");
      91          83 :     fprintf(m_f, "\treturn %s%s(count, from, tmp);\n}\n", func, locale);
      92          83 : }
      93             : 
      94          76 : void OFileWriter::writeFunction2(const char *func, const char *style, const char* attr, const char *array) const
      95             : {
      96          76 :     fprintf(m_f, "const sal_Unicode ***  SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nAttributes )\n{\n", func, theLocale);
      97          76 :     fprintf(m_f, "\tnStyles     = %s;\n", style);
      98          76 :     fprintf(m_f, "\tnAttributes = %s;\n", attr);
      99          76 :     fprintf(m_f, "\treturn %s;\n}\n", array);
     100          76 : }
     101             : 
     102         165 : void OFileWriter::writeRefFunction2(const char *func, const OUString& useLocale) const
     103             : {
     104         165 :     OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
     105         165 :     const char* locale = aRefLocale.getStr();
     106         165 :     fprintf(m_f, "extern const sal_Unicode ***  SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes);\n", func, locale);
     107         165 :     fprintf(m_f, "const sal_Unicode ***  SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nAttributes)\n{\n", func, theLocale);
     108         165 :     fprintf(m_f, "\treturn %s%s(nStyles, nAttributes);\n}\n", func, locale);
     109         165 : }
     110             : 
     111          29 : void OFileWriter::writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const
     112             : {
     113          29 :     fprintf(m_f, "const sal_Unicode ****  SAL_CALL %s%s( sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes )\n{\n", func, theLocale);
     114          29 :     fprintf(m_f, "\tnStyles     = %s;\n", style);
     115          29 :     fprintf(m_f, "\tnLevels     = %s;\n", levels);
     116          29 :     fprintf(m_f, "\tnAttributes = %s;\n", attr);
     117          29 :     fprintf(m_f, "\treturn %s;\n}\n", array);
     118          29 : }
     119             : 
     120         212 : void OFileWriter::writeRefFunction3(const char *func, const OUString& useLocale) const
     121             : {
     122         212 :     OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) );
     123         212 :     const char* locale = aRefLocale.getStr();
     124         212 :     fprintf(m_f, "extern const sal_Unicode ****  SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes);\n", func, locale);
     125         212 :     fprintf(m_f, "const sal_Unicode ****  SAL_CALL %s%s(sal_Int16& nStyles, sal_Int16& nLevels, sal_Int16& nAttributes)\n{\n", func, theLocale);
     126         212 :     fprintf(m_f, "\treturn %s%s(nStyles, nLevels, nAttributes);\n}\n", func, locale);
     127         212 : }
     128             : 
     129        8039 : void OFileWriter::writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const
     130             : {
     131        8039 :     fprintf(m_f, "static const sal_Unicode %s%d[] = {%d};\n", pAsciiStr, count, val);
     132        8039 : }
     133             : 
     134        9062 : bool OFileWriter::writeDefaultParameter(const sal_Char* pAsciiStr, const OUString& str, sal_Int16 count) const
     135             : {
     136        9062 :     bool bBool = str == "true";
     137        9062 :     fprintf(m_f,"static const sal_Unicode default%s%d[] = {%d};\n", pAsciiStr, count, bBool);
     138        9062 :     return bBool;
     139             : }
     140             : 
     141        5963 : void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const OUString& aChars) const
     142             : {
     143        5963 :     fprintf(m_f, "static const sal_Unicode %s[] = {", pAsciiStr);
     144        5963 :     writeStringCharacters(aChars);
     145        5963 :     fprintf(m_f, "0x0};\n");
     146        5963 : }
     147             : 
     148       44217 : void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count) const
     149             : {
     150       44217 :     fprintf(m_f, "static const sal_Unicode %s%d[] = {", pAsciiStr, count);
     151       44217 :     writeStringCharacters(aChars);
     152       44217 :     fprintf(m_f, "0x0};\n");
     153       44217 : }
     154             : 
     155        8912 : void OFileWriter::writeParameter(const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
     156             : {
     157        8912 :     fprintf(m_f, "static const sal_Unicode %s%d%d[] = {", pAsciiStr, count0, count1);
     158        8912 :     writeStringCharacters(aChars);
     159        8912 :     fprintf(m_f, "0x0};\n");
     160        8912 : }
     161             : 
     162        3090 : void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const OUString& aChars, const sal_Int16 count) const
     163             : {
     164        3090 :     fprintf(m_f, "static const sal_Unicode %s%s%d[] = {", pTagStr, pAsciiStr, count);
     165        3090 :     writeStringCharacters(aChars);
     166        3090 :     fprintf(m_f, "0x0};\n");
     167        3090 : }
     168             : 
     169       39537 : void OFileWriter::writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const
     170             : {
     171       39537 :     fprintf(m_f, "static const sal_Unicode %s%s%d%d[] = {", pTagStr, pAsciiStr, count0, count1);
     172       39537 :     writeStringCharacters(aChars);
     173       39537 :     fprintf(m_f, "0x0};\n");
     174       39537 : }
     175             : 
     176         482 : void OFileWriter::closeOutput(void) const
     177             : {
     178         482 :     if(m_f)
     179             :     {
     180         241 :         fclose( m_f );
     181         241 :         const_cast< OFileWriter * > ( this )->m_f = 0;
     182             :     }
     183         482 : }
     184             : 
     185             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10