po.cxx 17.2 KB
Newer Older
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 6 7 8
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
9

10
#include <rtl/ustring.hxx>
11
#include <rtl/crc.h>
12
#include <sal/log.hxx>
13 14

#include <cstring>
15
#include <ctime>
Zolnai Tamás's avatar
Zolnai Tamás committed
16 17
#include <cassert>

18
#include <vector>
Zolnai Tamás's avatar
Zolnai Tamás committed
19 20
#include <string>

21 22
#include <po.hxx>
#include <helper.hxx>
23

24
/** Container of po entry
25

26 27 28
    Provide all file operations related to LibreOffice specific
    po entry and store it's attributes.
*/
29 30 31
class GenPoEntry
{
private:
32
    OStringBuffer m_sExtractCom;
33
    std::vector<OString>    m_sReferences;
34 35
    OString    m_sMsgCtxt;
    OString    m_sMsgId;
36
    OString    m_sMsgIdPlural;
37
    OString    m_sMsgStr;
38
    std::vector<OString>    m_sMsgStrPlural;
39
    bool       m_bFuzzy;
40
    bool       m_bCFormat;
41 42 43
    bool       m_bNull;

public:
44
    GenPoEntry();
45

46
    const std::vector<OString>& getReference() const    { return m_sReferences; }
47 48 49
    const OString& getMsgCtxt() const      { return m_sMsgCtxt; }
    const OString& getMsgId() const        { return m_sMsgId; }
    const OString& getMsgStr() const       { return m_sMsgStr; }
50 51 52 53
    bool        isFuzzy() const         { return m_bFuzzy; }
    bool        isNull() const          { return m_bNull; }

    void        setExtractCom(const OString& rExtractCom)
54 55 56
                        {
                            m_sExtractCom = rExtractCom;
                        }
57
    void        setReference(const OString& rReference)
58
                        {
59
                            m_sReferences.push_back(rReference);
60
                        }
61
    void        setMsgCtxt(const OString& rMsgCtxt)
62 63 64
                        {
                            m_sMsgCtxt = rMsgCtxt;
                        }
65
    void        setMsgId(const OString& rMsgId)
66 67 68
                        {
                            m_sMsgId = rMsgId;
                        }
69
    void        setMsgStr(const OString& rMsgStr)
70 71 72
                        {
                            m_sMsgStr = rMsgStr;
                        }
73

74 75
    void        writeToFile(std::ofstream& rOFStream) const;
    void        readFromFile(std::ifstream& rIFStream);
76 77
};

78 79
namespace
{
Zolnai Tamás's avatar
Zolnai Tamás committed
80
    // Convert a normal string to msg/po output string
Tor Lillqvist's avatar
Tor Lillqvist committed
81
    OString lcl_GenMsgString(const OString& rString)
82
    {
83 84
        if ( rString.isEmpty() )
            return "\"\"";
85

86 87 88 89
        OString sResult =
            "\"" +
            helper::escapeAll(rString,"\n""\t""\r""\\""\"","\\n""\\t""\\r""\\\\""\\\"") +
            "\"";
90 91 92
        sal_Int32 nIndex = 0;
        while((nIndex=sResult.indexOf("\\n",nIndex))!=-1)
        {
93
            if( !sResult.match("\\\\n", nIndex-1) &&
94 95 96 97 98 99
                nIndex!=sResult.getLength()-3)
            {
               sResult = sResult.replaceAt(nIndex,2,"\\n\"\n\"");
            }
            ++nIndex;
        }
100

101 102
        if ( sResult.indexOf('\n') != -1 )
            return "\"\"\n" +  sResult;
103

104 105 106
        return sResult;
    }

Zolnai Tamás's avatar
Zolnai Tamás committed
107
    // Convert msg string to normal form
Tor Lillqvist's avatar
Tor Lillqvist committed
108
    OString lcl_GenNormString(const OString& rString)
109
    {
110 111 112 113 114
        return
            helper::unEscapeAll(
                rString.copy(1,rString.getLength()-2),
                "\\n""\\t""\\r""\\\\""\\\"",
                "\n""\t""\r""\\""\"");
115
    }
116 117
}

118
GenPoEntry::GenPoEntry()
119
    : m_sExtractCom( OString() )
120
    , m_sReferences( std::vector<OString>() )
121 122
    , m_sMsgCtxt( OString() )
    , m_sMsgId( OString() )
123
    , m_sMsgIdPlural( OString() )
124
    , m_sMsgStr( OString() )
125
    , m_sMsgStrPlural( std::vector<OString>() )
Zolnai Tamás's avatar
Zolnai Tamás committed
126
    , m_bFuzzy( false )
127
    , m_bCFormat( false )
128
    , m_bNull( false )
129 130 131
{
}

Zolnai Tamás's avatar
Zolnai Tamás committed
132
void GenPoEntry::writeToFile(std::ofstream& rOFStream) const
133
{
134
    if ( rOFStream.tellp() != std::ofstream::pos_type( 0 ))
135
        rOFStream << std::endl;
136
    if ( !m_sExtractCom.isEmpty() )
137 138
        rOFStream
            << "#. "
139
            << m_sExtractCom.toString().replaceAll("\n","\n#. ") << std::endl;
140 141
    for(const auto& rReference : m_sReferences)
        rOFStream << "#: " << rReference << std::endl;
Zolnai Tamás's avatar
Zolnai Tamás committed
142
    if ( m_bFuzzy )
143
        rOFStream << "#, fuzzy" << std::endl;
144 145
    if ( m_bCFormat )
        rOFStream << "#, c-format" << std::endl;
146
    if ( !m_sMsgCtxt.isEmpty() )
147
        rOFStream << "msgctxt "
148
                  << lcl_GenMsgString(m_sMsgCtxt)
149
                  << std::endl;
150
    rOFStream << "msgid "
151
              << lcl_GenMsgString(m_sMsgId) << std::endl;
152 153 154 155 156 157 158 159 160 161
    if ( !m_sMsgIdPlural.isEmpty() )
        rOFStream << "msgid_plural "
                  << lcl_GenMsgString(m_sMsgIdPlural)
                  << std::endl;
    if ( !m_sMsgStrPlural.empty() )
        for(auto & line : m_sMsgStrPlural)
            rOFStream << line.copy(0,10) << lcl_GenMsgString(line.copy(10)) << std::endl;
    else
        rOFStream << "msgstr "
                  << lcl_GenMsgString(m_sMsgStr) << std::endl;
162 163
}

164 165
void GenPoEntry::readFromFile(std::ifstream& rIFStream)
{
166
    *this = GenPoEntry();
167
    OString* pLastMsg = nullptr;
168 169 170
    std::string sTemp;
    getline(rIFStream,sTemp);
    if( rIFStream.eof() || sTemp.empty() )
171 172 173 174
    {
        m_bNull = true;
        return;
    }
175 176 177
    while(!rIFStream.eof())
    {
        OString sLine = OString(sTemp.data(),sTemp.length());
178
        if (sLine.startsWith("#. "))
179
        {
180 181
            if( !m_sExtractCom.isEmpty() )
            {
182
                m_sExtractCom.append("\n");
183
            }
184
            m_sExtractCom.append(sLine.copy(3));
185
        }
186
        else if (sLine.startsWith("#: "))
187
        {
188
            m_sReferences.push_back(sLine.copy(3));
189
        }
190
        else if (sLine.startsWith("#, fuzzy"))
191 192 193
        {
            m_bFuzzy = true;
        }
194 195 196 197
        else if (sLine.startsWith("#, c-format"))
        {
            m_bCFormat = true;
        }
198
        else if (sLine.startsWith("msgctxt "))
199
        {
200 201
            m_sMsgCtxt = lcl_GenNormString(sLine.copy(8));
            pLastMsg = &m_sMsgCtxt;
202
        }
203
        else if (sLine.startsWith("msgid "))
204
        {
205 206
            m_sMsgId = lcl_GenNormString(sLine.copy(6));
            pLastMsg = &m_sMsgId;
207
        }
208 209 210 211 212
        else if (sLine.startsWith("msgid_plural "))
        {
            m_sMsgIdPlural = lcl_GenNormString(sLine.copy(13));
            pLastMsg = &m_sMsgIdPlural;
        }
213
        else if (sLine.startsWith("msgstr "))
214
        {
215 216
            m_sMsgStr = lcl_GenNormString(sLine.copy(7));
            pLastMsg = &m_sMsgStr;
217
        }
218 219 220 221 222 223
        else if (sLine.startsWith("msgstr["))
        {
            // assume there are no more than 10 plural forms...
            // and that plural strings are never split to multi-line in po
            m_sMsgStrPlural.push_back(sLine.copy(0,10) + lcl_GenNormString(sLine.copy(10)));
        }
224
        else if (sLine.startsWith("\"") && pLastMsg)
225
        {
226 227 228 229 230 231 232 233 234
            OString sReference;
            if (!m_sReferences.empty())
            {
                sReference = m_sReferences.front();
            }
            if (pLastMsg != &m_sMsgCtxt || sLine != "\"" + sReference + "\\n\"")
            {
                *pLastMsg += lcl_GenNormString(sLine);
            }
235 236 237 238 239 240 241 242
        }
        else
            break;
        getline(rIFStream,sTemp);
    }
 }

PoEntry::PoEntry()
Noel Grandin's avatar
Noel Grandin committed
243
    : m_bIsInitialized( false )
244 245 246
{
}

247 248 249 250
PoEntry::PoEntry(
    const OString& rSourceFile, const OString& rResType, const OString& rGroupId,
    const OString& rLocalId, const OString& rHelpText,
    const OString& rText, const TYPE eType )
Noel Grandin's avatar
Noel Grandin committed
251
    : m_bIsInitialized( false )
252
{
253 254 255 256 257 258 259 260 261 262
    if( rSourceFile.isEmpty() )
        throw NOSOURCFILE;
    else if ( rResType.isEmpty() )
        throw NORESTYPE;
    else if ( rGroupId.isEmpty() )
        throw NOGROUPID;
    else if ( rText.isEmpty() )
        throw NOSTRING;
    else if ( rHelpText.getLength() == 5 )
        throw WRONGHELPTEXT;
263

Noel Grandin's avatar
Noel Grandin committed
264
    m_pGenPo.reset( new GenPoEntry() );
265 266
    OString sReference = rSourceFile.copy(rSourceFile.lastIndexOf('/')+1);
    m_pGenPo->setReference(sReference);
267

268
    OString sMsgCtxt =
269
        sReference + "\n" +
270
        rGroupId + "\n" +
271
        (rLocalId.isEmpty() ? OString() : rLocalId + "\n") +
272
        rResType;
273 274
    switch(eType){
    case TTEXT:
275
        sMsgCtxt += ".text"; break;
276
    case TQUICKHELPTEXT:
277
        sMsgCtxt += ".quickhelptext"; break;
278
    case TTITLE:
279
        sMsgCtxt += ".title"; break;
Zolnai Tamás's avatar
Zolnai Tamás committed
280
    // Default case is unneeded because the type of eType has only three element
281
    }
282
    m_pGenPo->setMsgCtxt(sMsgCtxt);
283
    m_pGenPo->setMsgId(rText);
284
    m_pGenPo->setExtractCom(
285
        ( !rHelpText.isEmpty() ?  rHelpText + "\n" : OString()) +
286
        genKeyId( m_pGenPo->getReference().front() + rGroupId + rLocalId + rResType + rText ) );
Zolnai Tamás's avatar
Zolnai Tamás committed
287
    m_bIsInitialized = true;
288 289 290
}

PoEntry::~PoEntry()
291 292 293 294
{
}

PoEntry::PoEntry( const PoEntry& rPo )
295
    : m_pGenPo( rPo.m_pGenPo ? new GenPoEntry( *(rPo.m_pGenPo) ) : nullptr )
296
    , m_bIsInitialized( rPo.m_bIsInitialized )
297 298 299
{
}

300 301 302 303 304 305 306 307 308 309 310 311 312 313
PoEntry& PoEntry::operator=(const PoEntry& rPo)
{
    if( this == &rPo )
    {
        return *this;
    }
    if( rPo.m_pGenPo )
    {
        if( m_pGenPo )
        {
            *m_pGenPo = *(rPo.m_pGenPo);
        }
        else
        {
Noel Grandin's avatar
Noel Grandin committed
314
            m_pGenPo.reset( new GenPoEntry( *(rPo.m_pGenPo) ) );
315 316 317 318
        }
    }
    else
    {
Noel Grandin's avatar
Noel Grandin committed
319
        m_pGenPo.reset();
320 321 322 323 324
    }
    m_bIsInitialized = rPo.m_bIsInitialized;
    return *this;
}

325 326 327
PoEntry& PoEntry::operator=(PoEntry&& rPo)
{
    m_pGenPo = std::move(rPo.m_pGenPo);
328
    m_bIsInitialized = std::move(rPo.m_bIsInitialized);
329 330 331
    return *this;
}

332
OString const & PoEntry::getSourceFile() const
333
{
Zolnai Tamás's avatar
Zolnai Tamás committed
334
    assert( m_bIsInitialized );
335
    return m_pGenPo->getReference().front();
336
}
337

338 339
OString PoEntry::getGroupId() const
{
Zolnai Tamás's avatar
Zolnai Tamás committed
340
    assert( m_bIsInitialized );
341
    return m_pGenPo->getMsgCtxt().getToken(0,'\n');
342 343 344 345
}

OString PoEntry::getLocalId() const
{
Zolnai Tamás's avatar
Zolnai Tamás committed
346
    assert( m_bIsInitialized );
347 348
    const OString sMsgCtxt = m_pGenPo->getMsgCtxt();
    if (sMsgCtxt.indexOf('\n')==sMsgCtxt.lastIndexOf('\n'))
349 350
        return OString();
    else
351
        return sMsgCtxt.getToken(1,'\n');
352 353 354 355
}

OString PoEntry::getResourceType() const
{
Zolnai Tamás's avatar
Zolnai Tamás committed
356
    assert( m_bIsInitialized );
357 358
    const OString sMsgCtxt = m_pGenPo->getMsgCtxt();
    if (sMsgCtxt.indexOf('\n')==sMsgCtxt.lastIndexOf('\n'))
359
        return sMsgCtxt.getToken(1,'\n').getToken(0,'.');
360
    else
361
        return sMsgCtxt.getToken(2,'\n').getToken(0,'.');
362 363 364 365
}

PoEntry::TYPE PoEntry::getType() const
{
366
    assert( m_bIsInitialized );
367 368
    const OString sMsgCtxt = m_pGenPo->getMsgCtxt();
    const OString sType = sMsgCtxt.copy( sMsgCtxt.lastIndexOf('.') + 1 );
369
    assert(
Zolnai Tamás's avatar
Zolnai Tamás committed
370 371
        (sType == "text" || sType == "quickhelptext" || sType == "title") );
    if ( sType == "text" )
372
        return TTEXT;
Zolnai Tamás's avatar
Zolnai Tamás committed
373
    else if ( sType == "quickhelptext" )
374
        return TQUICKHELPTEXT;
Zolnai Tamás's avatar
Zolnai Tamás committed
375
    else
376
        return TTITLE;
377 378
}

379
bool PoEntry::isFuzzy() const
380
{
Zolnai Tamás's avatar
Zolnai Tamás committed
381
    assert( m_bIsInitialized );
382
    return m_pGenPo->isFuzzy();
383 384
}

385 386 387 388 389 390 391 392
// Get message context
const OString& PoEntry::getMsgCtxt() const
{
    assert( m_bIsInitialized );
    return m_pGenPo->getMsgCtxt();

}

Zolnai Tamás's avatar
Zolnai Tamás committed
393
// Get translation string in merge format
394
OString const & PoEntry::getMsgId() const
395
{
Zolnai Tamás's avatar
Zolnai Tamás committed
396
    assert( m_bIsInitialized );
397
    return m_pGenPo->getMsgId();
398 399
}

Zolnai Tamás's avatar
Zolnai Tamás committed
400
// Get translated string in merge format
401
const OString& PoEntry::getMsgStr() const
402
{
Zolnai Tamás's avatar
Zolnai Tamás committed
403
    assert( m_bIsInitialized );
404
    return m_pGenPo->getMsgStr();
405

406 407
}

408 409
bool PoEntry::IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2)
{
Zolnai Tamás's avatar
Zolnai Tamás committed
410
    assert( rPo1.m_bIsInitialized && rPo2.m_bIsInitialized );
411 412 413 414
    return ( rPo1.getSourceFile() == rPo2.getSourceFile() &&
             rPo1.getGroupId() == rPo2.getGroupId() &&
             rPo1.getLocalId() == rPo2.getLocalId() &&
             rPo1.getResourceType() == rPo2.getResourceType() );
415 416
}

417 418
OString PoEntry::genKeyId(const OString& rGenerator)
{
419
    sal_uInt32 nCRC = rtl_crc32(0, rGenerator.getStr(), rGenerator.getLength());
Zolnai Tamás's avatar
Zolnai Tamás committed
420
    // Use simple ASCII characters, exclude I, l, 1 and O, 0 to avoid confusing IDs
421
    static const char sSymbols[] =
422 423 424 425
        "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789";
    char sKeyId[6];
    for( short nKeyInd = 0; nKeyInd < 5; ++nKeyInd )
    {
426
        sKeyId[nKeyInd] = sSymbols[(nCRC & 63) % strlen(sSymbols)];
427 428 429 430 431 432
        nCRC >>= 6;
    }
    sKeyId[5] = '\0';
    return OString(sKeyId);
}

433
namespace
434
{
Zolnai Tamás's avatar
Zolnai Tamás committed
435
    // Get actual time in "YEAR-MO-DA HO:MI+ZONE" form
Tor Lillqvist's avatar
Tor Lillqvist committed
436
    OString lcl_GetTime()
437
    {
438
        time_t aNow = time(nullptr);
439 440 441
        struct tm* pNow = localtime(&aNow);
        char pBuff[50];
        strftime( pBuff, sizeof pBuff, "%Y-%m-%d %H:%M%z", pNow );
442
        return OString(pBuff);
443
    }
Zolnai Tamás's avatar
Zolnai Tamás committed
444 445
}

446 447 448 449 450 451 452 453 454 455
// when updating existing files (pocheck), reuse provided po-header
PoHeader::PoHeader( const OString& rExtSrc, const OString& rPoHeaderMsgStr )
    : m_pGenPo( new GenPoEntry() )
    , m_bIsInitialized( false )
{
    m_pGenPo->setExtractCom("extracted from " + rExtSrc);
    m_pGenPo->setMsgStr(rPoHeaderMsgStr);
    m_bIsInitialized = true;
}

456
PoHeader::PoHeader( const OString& rExtSrc )
457
    : m_pGenPo( new GenPoEntry() )
Zolnai Tamás's avatar
Zolnai Tamás committed
458
    , m_bIsInitialized( false )
459
{
460
    m_pGenPo->setExtractCom("extracted from " + rExtSrc);
461
    m_pGenPo->setMsgStr(
462
        OString("Project-Id-Version: PACKAGE VERSION\n"
463
        "Report-Msgid-Bugs-To: https://bugs.libreoffice.org/enter_bug.cgi?"
464
        "product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n"
465
        "POT-Creation-Date: ") + lcl_GetTime() +
466 467 468 469 470 471
        OString("\nPO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
        "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
        "Language-Team: LANGUAGE <LL@li.org>\n"
        "MIME-Version: 1.0\n"
        "Content-Type: text/plain; charset=UTF-8\n"
        "Content-Transfer-Encoding: 8bit\n"
472 473
        "X-Accelerator-Marker: ~\n"
        "X-Generator: LibreOffice\n"));
Zolnai Tamás's avatar
Zolnai Tamás committed
474 475 476
    m_bIsInitialized = true;
}

477 478 479 480
PoHeader::~PoHeader()
{
}

Zolnai Tamás's avatar
Zolnai Tamás committed
481 482 483 484 485 486
PoOfstream::PoOfstream()
    : m_aOutPut()
    , m_bIsAfterHeader( false )
{
}

487 488 489 490 491 492 493
PoOfstream::PoOfstream(const OString& rFileName, OpenMode aMode )
    : m_aOutPut()
    , m_bIsAfterHeader( false )
{
    open( rFileName, aMode );
}

Zolnai Tamás's avatar
Zolnai Tamás committed
494 495 496 497 498 499 500 501
PoOfstream::~PoOfstream()
{
    if( isOpen() )
    {
       close();
    }
}

502
void PoOfstream::open(const OString& rFileName, OpenMode aMode )
503
{
Zolnai Tamás's avatar
Zolnai Tamás committed
504
    assert( !isOpen() );
505 506 507 508 509 510 511 512 513 514 515 516
    if( aMode == TRUNC )
    {
        m_aOutPut.open( rFileName.getStr(),
            std::ios_base::out | std::ios_base::trunc );
        m_bIsAfterHeader = false;
    }
    else if( aMode == APP )
    {
        m_aOutPut.open( rFileName.getStr(),
            std::ios_base::out | std::ios_base::app );
        m_bIsAfterHeader = m_aOutPut.tellp() != std::ofstream::pos_type( 0 );
    }
517 518
}

Zolnai Tamás's avatar
Zolnai Tamás committed
519 520 521 522 523 524 525 526 527
void PoOfstream::close()
{
    assert( isOpen() );
    m_aOutPut.close();
}

void PoOfstream::writeHeader(const PoHeader& rPoHeader)
{
    assert( isOpen() && !m_bIsAfterHeader && rPoHeader.m_bIsInitialized );
528
    rPoHeader.m_pGenPo->writeToFile( m_aOutPut );
Zolnai Tamás's avatar
Zolnai Tamás committed
529 530 531 532 533 534
    m_bIsAfterHeader = true;
}

void PoOfstream::writeEntry( const PoEntry& rPoEntry )
{
    assert( isOpen() && m_bIsAfterHeader && rPoEntry.m_bIsInitialized );
535
    rPoEntry.m_pGenPo->writeToFile( m_aOutPut );
Zolnai Tamás's avatar
Zolnai Tamás committed
536 537
}

538 539 540
namespace
{

Zolnai Tamás's avatar
Zolnai Tamás committed
541
// Check the validity of read entry
Tor Lillqvist's avatar
Tor Lillqvist committed
542
bool lcl_CheckInputEntry(const GenPoEntry& rEntry)
543
{
544
    return !rEntry.getReference().empty() &&
545 546
           !rEntry.getMsgCtxt().isEmpty() &&
           !rEntry.getMsgId().isEmpty();
547 548 549 550
}

}

Zolnai Tamás's avatar
Zolnai Tamás committed
551 552 553 554 555 556
PoIfstream::PoIfstream()
    : m_aInPut()
    , m_bEof( false )
{
}

557 558 559 560 561 562 563
PoIfstream::PoIfstream(const OString& rFileName)
    : m_aInPut()
    , m_bEof( false )
{
    open( rFileName );
}

Zolnai Tamás's avatar
Zolnai Tamás committed
564 565 566 567 568 569 570 571
PoIfstream::~PoIfstream()
{
    if( isOpen() )
    {
       close();
    }
}

572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
void PoIfstream::open( const OString& rFileName, OString& rPoHeader )
{
    assert( !isOpen() );
    m_aInPut.open( rFileName.getStr(), std::ios_base::in );

    // capture header, updating timestamp and generator
    std::string sTemp;
    std::getline(m_aInPut,sTemp);
    while( !sTemp.empty() && !m_aInPut.eof() )
    {
        std::getline(m_aInPut,sTemp);
        OString sLine = OString(sTemp.data(),sTemp.length());
        if (sLine.startsWith("\"PO-Revision-Date"))
            rPoHeader += "PO-Revision-Date: " + lcl_GetTime() + "\n";
        else if (sLine.startsWith("\"X-Generator"))
            rPoHeader += "X-Generator: LibreOffice\n";
        else if (sLine.startsWith("\""))
            rPoHeader += lcl_GenNormString(sLine);
    }
    m_bEof = false;
}

Zolnai Tamás's avatar
Zolnai Tamás committed
594 595 596 597
void PoIfstream::open( const OString& rFileName )
{
    assert( !isOpen() );
    m_aInPut.open( rFileName.getStr(), std::ios_base::in );
Zolnai Tamás's avatar
Zolnai Tamás committed
598

Zolnai Tamás's avatar
Zolnai Tamás committed
599
    // Skip header
Zolnai Tamás's avatar
Zolnai Tamás committed
600 601 602 603 604 605
    std::string sTemp;
    std::getline(m_aInPut,sTemp);
    while( !sTemp.empty() && !m_aInPut.eof() )
    {
        std::getline(m_aInPut,sTemp);
    }
Zolnai Tamás's avatar
Zolnai Tamás committed
606 607 608 609
    m_bEof = false;
}

void PoIfstream::close()
610
{
Zolnai Tamás's avatar
Zolnai Tamás committed
611 612
    assert( isOpen() );
    m_aInPut.close();
613 614
}

Zolnai Tamás's avatar
Zolnai Tamás committed
615 616
void PoIfstream::readEntry( PoEntry& rPoEntry )
{
Zolnai Tamás's avatar
Zolnai Tamás committed
617
    assert( isOpen() && !eof() );
Zolnai Tamás's avatar
Zolnai Tamás committed
618 619 620 621 622 623 624 625 626
    GenPoEntry aGenPo;
    aGenPo.readFromFile( m_aInPut );
    if( aGenPo.isNull() )
    {
        m_bEof = true;
        rPoEntry = PoEntry();
    }
    else
    {
627
        if( lcl_CheckInputEntry(aGenPo) )
Zolnai Tamás's avatar
Zolnai Tamás committed
628
        {
629 630 631 632 633 634
            if( rPoEntry.m_pGenPo )
            {
                *(rPoEntry.m_pGenPo) = aGenPo;
            }
            else
            {
Noel Grandin's avatar
Noel Grandin committed
635
                rPoEntry.m_pGenPo.reset( new GenPoEntry( aGenPo ) );
636
            }
Zolnai Tamás's avatar
Zolnai Tamás committed
637 638 639 640
            rPoEntry.m_bIsInitialized = true;
        }
        else
        {
641
            SAL_WARN("l10ntools", "Parse problem with entry: " << aGenPo.getMsgStr());
642
            throw PoIfstream::Exception();
Zolnai Tamás's avatar
Zolnai Tamás committed
643 644 645
        }
    }
}
646

647
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */