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

Generated by: LCOV version 1.11