"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2b/bibPreparser.cpp" (12 Feb 2021, 2374 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "bibPreparser.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #include "bibPreparser.h"
    8 
    9 #include "cb2bib_utilities.h"
   10 #include "settings.h"
   11 
   12 #include <QProcess>
   13 
   14 
   15 bibPreparser::bibPreparser(QObject* parento) : QObject(parento)
   16 {
   17     settings* settingsP = settings::instance();
   18     m_inp_file = settingsP->tempPath() + "/cb2bib_clipborad_inp.tmp_" + settingsP->applicationPid();
   19     m_out_file = settingsP->tempPath() + "/cb2bib_clipborad_out.tmp_" + settingsP->applicationPid();
   20 }
   21 
   22 
   23 void bibPreparser::preparse(const QString& text, QString* out_text)
   24 {
   25     out_text->clear();
   26     if (!c2bUtils::stringToFile(text + '\n', m_inp_file))
   27     {
   28         emit statusMessage(tr("Unable to open the file %1 for writing.").arg(m_inp_file));
   29         return;
   30     }
   31 
   32     // External preparsing
   33     QStringList arguments;
   34     arguments.append(m_inp_file);
   35     arguments.append(m_out_file);
   36     QProcess preparser;
   37     preparser.start(settings::instance()->fileName("cb2Bib/PreparserBin"), arguments);
   38     if (!preparser.waitForFinished(2000))
   39     {
   40         preparser.kill();
   41         QFile ifile(m_inp_file);
   42         ifile.remove();
   43         QFile ofile(m_out_file);
   44         ofile.remove();
   45         emit statusMessage(tr("Failed to call %1.").arg(settings::instance()->fileName("cb2Bib/PreparserBin")));
   46         return;
   47     }
   48 
   49     QFile ifile(m_inp_file);
   50     ifile.remove();
   51     (*out_text) = c2bUtils::fileToString(m_out_file, true);
   52     if (out_text->isEmpty())
   53     {
   54         emit statusMessage(tr("External Parsing ended. Input string remains unchanged."));
   55         (*out_text) = text;
   56     }
   57     else
   58         emit statusMessage(tr("External Parsing ended."));
   59     if (settings::instance()->value("cb2Bib/PreparserShowLog").toBool())
   60     {
   61         QString log_string(QString::fromUtf8(preparser.readAllStandardOutput()) + '\n');
   62         log_string += QString::fromUtf8(preparser.readAllStandardError()) + '\n';
   63         log_string += QString("Input[\n%1\n]\n").arg(text);
   64         log_string += QString("Output[\n%1\n]\n").arg(*out_text);
   65         emit preparserLogAvailable(log_string);
   66     }
   67 }