summaryrefslogtreecommitdiff
path: root/l10ntools/source/gConvXhp.cxx
blob: 6f7cdb7f2a2005026c00d51c0d45c03d36f80d4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * 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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#include <string>
#include <vector>
using namespace std;

#include "gL10nMem.hxx"
#include "gConvXhp.hxx"



convert_xhp::convert_xhp(l10nMem& crMemory)
                        : convert_gen(crMemory),
                          meExpectValue(VALUE_NOT_USED),
                          msLangText(nullptr),
                          mcOutputFiles(nullptr),
                          miCntLanguages(0)
{
    // xhp files are written through a local routine
    mbLoadMode = true;
}



convert_xhp::~convert_xhp()
{
    if (mcOutputFiles) {
        for (int i = 0; i < miCntLanguages; ++i)
            mcOutputFiles[i].close();
        delete[] mcOutputFiles;
    }
    if (msLangText)
        delete[] msLangText;
}



void convert_xhp::doExecute()
{
    string sLang;
    string sFile, sFile2;

    // prepare list with languages
    miCntLanguages = mcMemory.prepareMerge();
    if (mbMergeMode) {
        mcOutputFiles  = new ofstream[miCntLanguages];
        msLangText     = new string[miCntLanguages];

        for (int i = 0; mcMemory.getMergeLang(sLang, sFile); ++i) {
            sFile2 = sLang + "/text/" + mcMemory.getModuleName().substr(5) + "/" + msSourceFile;
            sFile  = msTargetPath + sFile2;
            mcOutputFiles[i].open(sFile.c_str(), ios::binary);
            if (!mcOutputFiles[i].is_open()) {
                if (!createDir(msTargetPath, sFile2))
                    throw l10nMem::showError("Cannot create missing directories (" + sFile + ") for writing");

                mcOutputFiles[i].open(sFile.c_str(), ios::binary);
                if (!mcOutputFiles[i].is_open())
                    throw l10nMem::showError("Cannot open file (" + sFile + ") for writing");
            }
            msLangText[i] = "xml-lang=\"" + sLang + "\"";
        }
    }

    // run analyzer
    xhplex();

    // dump last line
    copySourceSpecial(nullptr,3);
}



void convert_xhp::setString(char *yytext)
{
    copySourceSpecial(yytext, 0);
}



void convert_xhp::openTag(char *yytext)
{
    if (meExpectValue == VALUE_IS_VALUE) {
        meExpectValue  = VALUE_IS_VALUE_TAG;
    //FIX    msCollector   += "\\";
    }
    copySourceSpecial(yytext, 0);
}



void convert_xhp::closeTag(char *yytext)
{
    STATE newState = meExpectValue;

    switch (meExpectValue) {
        case VALUE_IS_VALUE_TAG:
             newState = VALUE_IS_VALUE;
             //FIX         msCollector   += "\\";
             break;

        case VALUE_IS_TAG_TRANS:
             if (msKey.size())
                 newState = VALUE_IS_VALUE;
             break;

        case VALUE_IS_TAG:
             msKey.clear();
             newState = VALUE_NOT_USED;
             break;

        case VALUE_NOT_USED:
        case VALUE_IS_VALUE:
             break;
    }
    copySourceSpecial(yytext, 0);
    meExpectValue = newState;
}



void convert_xhp::closeTagNOvalue(char *yytext)
{
    copySourceSpecial(yytext, 0);
    if (meExpectValue == VALUE_IS_VALUE_TAG)
        meExpectValue = VALUE_IS_VALUE;
    else
        meExpectValue = VALUE_NOT_USED;
}



void convert_xhp::setId(char *yytext)
{
    int          nL, nE;
    string& sText = copySourceSpecial(yytext, 0);


    nL = sText.find("\"");
    nE = sText.find("\"", nL+1);
    if (nL == (int)string::npos || nE == (int)string::npos)
        return;

    switch (meExpectValue) {
        case VALUE_IS_TAG:
        case VALUE_IS_TAG_TRANS:
             msKey = sText.substr(nL+1, nE - nL -1) + msKey;
             break;

        case VALUE_IS_VALUE_TAG:
        case VALUE_NOT_USED:
        case VALUE_IS_VALUE:
             break;
    }
}



void convert_xhp::setLang(char *yytext)
{
    int          nL, nE;
    string  sLang;
    string& sText = copySourceSpecial(yytext, 1);


    nL = sText.find("\"");
    nE = sText.find("\"", nL+1);
    if (nL == (int)string::npos || nE == (int)string::npos)
        return;

    switch (meExpectValue) {
        case VALUE_IS_TAG:
             sLang = sText.substr(nL+1, nE - nL -1);
             if (sLang == "en-US")
                 meExpectValue = VALUE_IS_TAG_TRANS;
             else
                 l10nMem::showError(sLang + " is no en-US language");
             break;

        case VALUE_IS_VALUE_TAG:
             msCollector.erase(msCollector.size() - sText.size() -1);
             break;

        case VALUE_NOT_USED:
        case VALUE_IS_TAG_TRANS:
        case VALUE_IS_VALUE:
             break;
    }
}



void convert_xhp::setRef(char *yytext)
{
    int          nL, nE;
    string& sText = copySourceSpecial(yytext, 0);


    nL = sText.find("\"");
    nE = sText.find("\"", nL+1);
    if (nL == (int)string::npos || nE == (int)string::npos)
        return;

    switch (meExpectValue) {
        case VALUE_IS_TAG:
        case VALUE_IS_TAG_TRANS:
             msKey += "." + sText.substr(nL+1, nE - nL -1);
             break;

        case VALUE_IS_VALUE_TAG:
        case VALUE_NOT_USED:
        case VALUE_IS_VALUE:
             break;
    }
}



void convert_xhp::openTransTag(char *yytext)
{
    copySourceSpecial(yytext, 0);
    msKey.clear();
    meExpectValue = VALUE_IS_TAG;
}



void convert_xhp::closeTransTag(char *yytext)
{
    int iType = 0;


    if (meExpectValue == VALUE_IS_VALUE || meExpectValue == VALUE_IS_VALUE_TAG) {
        if (msCollector.size() && msCollector != "-") {
            string newString(msCollector);
            if (newString[newString.length() - 1] == ' ')
                newString = newString.substr(0, newString.length() - 1);
            mcMemory.setSourceKey(miLineNo, msSourceFile, msKey, newString, "", "help", "", mbMergeMode);
        }
        msKey.clear();
        iType = 2;
    }
    meExpectValue = VALUE_NOT_USED;
    copySourceSpecial(yytext, iType);
}



void convert_xhp::stopTransTag(char *yytext)
{
    copySourceSpecial(yytext, 0);
    meExpectValue = VALUE_NOT_USED;
}



void convert_xhp::startComment(char *yytext)
{
    mePushValue   = meExpectValue;
    msPushCollect = msCollector;
    meExpectValue = VALUE_NOT_USED;
    copySourceSpecial(yytext, 0);
}



void convert_xhp::stopComment(char *yytext)
{
    copySourceSpecial(yytext, 0);
    meExpectValue = mePushValue;
    msCollector   = msPushCollect;
}



void convert_xhp::handleSpecial(char *yytext)
{
    if (meExpectValue != VALUE_IS_VALUE || meExpectValue != VALUE_IS_VALUE_TAG) {
        string sText(yytext);
        mcMemory.convertFromInetString(sText);
        msCollector += sText;
    }
    else
        copySourceSpecial(yytext, 0);
}



void convert_xhp::handleDataEnd(char *yytext)
{
    int nX = msCollector.size();
    copySourceSpecial(yytext, 0);

    if (meExpectValue == VALUE_IS_VALUE || meExpectValue == VALUE_IS_VALUE_TAG)
        msCollector.erase(nX);
}



void convert_xhp::duplicate(char *yytext)
{
    copySourceSpecial(yytext, 0);

    if (meExpectValue == VALUE_IS_VALUE || meExpectValue == VALUE_IS_VALUE_TAG)
        msCollector += msCollector[msCollector.size()-1];
}



string& convert_xhp::copySourceSpecial(char *yytext, int iType)
{
    bool         doingValue = (meExpectValue == VALUE_IS_VALUE || meExpectValue == VALUE_IS_VALUE_TAG);
    string& sText      = copySource(yytext, !doingValue);
    string  sLang;
    int          i;


    // Do NOT write data while collecting a value (will be replaced by language text)
    if (doingValue)
        return sText;

    // Handling depends o
    switch (iType) {
        case 0: // Used for tokens that are to be copied 1-1,
             if (mbMergeMode) {
                 msLine += yytext;
                 if (*yytext == '\n') {
                     for (i = 0; i < miCntLanguages; ++i)
                         writeSourceFile(msLine, i);
                     msLine.clear();
                 }
             }
             break;

        case 1: // Used for language token, are to replaced with languages
             if (mbMergeMode) {
                 for (i = 0; i < miCntLanguages; ++i) {
                     writeSourceFile(msLine, i);
                     writeSourceFile(msLangText[i], i);
                 }
                 msLine.clear();
             }
             break;

        case 2: // Used for token at end of value, language text are to be inserted and then token written
             if (mbMergeMode) {
                 mcMemory.prepareMerge();
                 for (i = 0; i < miCntLanguages; ++i) {
                     writeSourceFile(msLine, i);
                     mcMemory.getMergeLang(sLang, sText);
                     writeSourceFile(sText,i);
                     string sYY(yytext);
                     writeSourceFile(sYY, i);
                 }
                 msLine.clear();
             }
             break;

        case 3: // Used for EOF
             if (mbMergeMode) {
                 for (i = 0; i < miCntLanguages; ++i)
                     writeSourceFile(msLine, i);
             }
             break;
    }
    return sText;
}



void convert_xhp::writeSourceFile(string& sText, int inx)
{
    if (sText.size() && mcOutputFiles[inx].is_open())
        mcOutputFiles[inx].write(sText.c_str(), sText.size());
}
?id=f80b51ae441e3483a2e9b77a30b932d4e8fba192'>tdf#104734 Firebird improve XClob implementationTamas Bunth Create a more effective implementation of XClob::length() and XClob::getSubString() methods, where string is read segment-by-segment instead of reading the whole underlying blob. That way it is possible to handle big texts which would not fit into memory. Also allow reading Clob data from a resultset with getString() and writing it in a prepared statement with setString(). Implement XPreparedStatement::setClob(). Also implement a private version of setClob() for creating a clob from OUString: Allow the creation of a clob column with GUI by adding a new type in ODataBaseMetaData::getTypeInfo(). Change-Id: Ibcbbdd80e8eed5e2a3fe55b0fa196401f1bcbcdf Reviewed-on: https://gerrit.libreoffice.org/47093 Reviewed-by: Tamás Bunth <btomi96@gmail.com> Tested-by: Tamás Bunth <btomi96@gmail.com> 2017-12-28tdf#104734 Firebird: Add VARBINARY type to driverTamas Bunth Change-Id: I9a1b3aa9bde855577078fe0db2e31a9c160031d7 Reviewed-on: https://gerrit.libreoffice.org/47092 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tamás Bunth <btomi96@gmail.com> 2017-12-28tdf#104734 Firebird: Add Binary (fix) typeTamas Bunth There is no explicit binary type in Firebird. It can be accomplished using the CHAR type with a special character set, which tells the database that it is binary data and there is no collation. (called OCTETS). Because of that, we also need the character set to decide the exact column type. And also refactor some parts of the driver: - Create class to determine internal type from firebird type, subtype, scale and character set. - Use internal type (DataType::XXX) in XDatabaseMetaData::getTypeInfo() indirectly. (We want to return a Firebird type for each internal type, not in the opposite direction. Change-Id: Ica56a84d89253e11936e7012086fe1d9f61a65f0 Reviewed-on: https://gerrit.libreoffice.org/47091 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tamás Bunth <btomi96@gmail.com> 2017-01-30tdf#105101 check scale to determine subtypeTamás Bunth For computed decimal/numeric values firebird's subtype remains 0. In this case we check for the scale of column. If it is not 0 (negative), than imply numeric. Change-Id: Ie5a023d165852fe402b3b4cac817b0bbef58e7cd Reviewed-on: https://gerrit.libreoffice.org/33660 Reviewed-by: Lionel Elie Mamane <lionel@mamane.lu> Tested-by: Tamás Bunth <btomi96@gmail.com> 2017-01-26Remove dynamic exception specificationsStephan Bergmann ...(for now, from LIBO_INTERNAL_CODE only). See the mail thread starting at <https://lists.freedesktop.org/archives/libreoffice/2017-January/076665.html> "Dynamic Exception Specifications" for details. Most changes have been done automatically by the rewriting loplugin:dynexcspec (after enabling the rewriting mode, to be committed shortly). The way it only removes exception specs from declarations if it also sees a definition, it identified some dead declarations-w/o-definitions (that have been removed manually) and some cases where a definition appeared in multiple include files (which have also been cleaned up manually). There's also been cases of macro paramters (that were used to abstract over exception specs) that have become unused now (and been removed). Furthermore, some code needed to be cleaned up manually (avmedia/source/quicktime/ and connectivity/source/drivers/kab/), as I had no configurations available that would actually build that code. Missing @throws documentation has not been applied in such manual clean-up. Change-Id: I3408691256c9b0c12bc5332de976743626e13960 Reviewed-on: https://gerrit.libreoffice.org/33574 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com> 2016-12-11tdf#103074 Implement Boolean Type for FB driverWastack Change-Id: Ibed5435e23730dc901155e79152e9becd3e70566 Reviewed-on: https://gerrit.libreoffice.org/31262 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Lionel Elie Mamane <lionel@mamane.lu> 2016-11-21get table name from resultset simplyWastack There is a much simpler way to access table name in ResultSetMetadata in Firebird sdbc which I didn't notice before. Change-Id: Ib306c04acf38ec86475d8d1a22a67012fe48539e Reviewed-on: https://gerrit.libreoffice.org/30931 Reviewed-by: Lionel Elie Mamane <lionel@mamane.lu> Tested-by: Lionel Elie Mamane <lionel@mamane.lu> 2016-11-12Related tdf#70433: Use subtype to distinguish BLOB/CLOB for FirebirdJulien Nabet See http://www.firebirdfaq.org/faq48/ Change-Id: If233919daeb02b67d0b3bc42547fbd3030864c37 Reviewed-on: https://gerrit.libreoffice.org/30789 Reviewed-by: Julien Nabet <serval2412@yahoo.fr> Tested-by: Julien Nabet <serval2412@yahoo.fr> 2016-11-10WiP tdf#74172 use DECIMAL and NUMERIC data typesWastack Change-Id: I917cdf6e8d3ebfa7c9e4a52ca61adc5b8707ecfc Reviewed-on: https://gerrit.libreoffice.org/30447 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Lionel Elie Mamane <lionel@mamane.lu> 2016-08-18tdf#69949 GSoC Firebird implement autoincrementWastack Change-Id: I6fe08b575f01b986f0a3c96b341f254279427b68 Reviewed-on: https://gerrit.libreoffice.org/28062 Reviewed-by: Lionel Elie Mamane <lionel@mamane.lu> Tested-by: Jenkins <ci@libreoffice.org> 2015-12-18tdf#96572 firebird correctly transmit request for NULLLionel Elie Mamane even if column is not nullable Change-Id: I72ceda68e983125aef26c8f0aacc06320bd16b77 2015-11-10loplugin:nullptr (automatic rewrite)Stephan Bergmann Change-Id: Iefeeb51c2b101c097a8d77a4625f84baf1f2da44 2015-08-31loplugin:stringconstant: OUStringBuffer: appendAscii -> appendStephan Bergmann Change-Id: I68b02ad101c4c2165b4618ed5d97cbffc2c43d2d 2015-03-28Clean up C-style casts from pointers to voidStephan Bergmann Change-Id: I6c7c31befd61cbf0800a62c08e7395ddf78e4b30 2015-01-20Some more loplugin:cstylecast: connectivityStephan Bergmann Change-Id: Iee1d11aef454284dbe050780c4308917c1a2b36f 2014-12-09fdo#39440 reduce scope of local variablesMichael Weghorn This addresses some cppcheck warnings. Change-Id: Ib35eb591534c3f23adc3cb7b7fa9696dc5cbeabf Reviewed-on: https://gerrit.libreoffice.org/13383 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com> 2014-10-29remove unnecessary 'using namespace rtl' declarationsNoel Grandin It turns out that almost none of them were necessary. Change-Id: I1311ed28409c682b57ea8d149bcbaf2c49133e83 Reviewed-on: https://gerrit.libreoffice.org/12133 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com> 2014-10-13coverity#1158396 Uncaught exceptionCaolán McNamara Change-Id: I0306b8431641d841027b30dfe1c03ecad5df6867 2014-07-26coverity#1079093 Uncaught exceptionCaolán McNamara Change-Id: I4b09963e2daf22dcd006fee0ce0bb130c7c18342 2014-06-27fdo#80574 firebird memory management issuesNorbert Thiebaud Change-Id: I37438cd3f9c8e197e5a3aa3d9cbcc5bf3681d792