"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2bExport.cpp" (12 Feb 2021, 2737 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 "c2bExport.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 "c2bExport.h"
    8 
    9 #include "c2b.h"
   10 
   11 #include <cb2bib_parameters.h>
   12 
   13 
   14 c2bExport::c2bExport(QObject* parento) : QObject(parento) {}
   15 
   16 c2bExport::~c2bExport() {}
   17 
   18 
   19 void c2bExport::exportEntries(const export_data& ed)
   20 {
   21     // Note. Assume caller performs export_data validity check for files and directories.
   22     // Prefer replacing filenames to a full BibTeX parsing: This will preserve the
   23     // original entry and possibly available non cb2Bib tags.
   24     bibParser* bp = c2b::bibParser();
   25     QStringList fields;
   26     if (ed.copy_documents)
   27         fields.append("file");
   28     QRegExp filere("\\bfile\\s*=\\s*[\\{\"](.*)[\\}\"]", Qt::CaseInsensitive);
   29     filere.setMinimal(true);
   30     QString export_contents("\n\n");
   31     QString export_log;
   32     bibReference ref;
   33     bp->initReferenceParsing(ed.bibtex_fn, fields, &ref);
   34     while (bp->referencesIn(ed.bibtex_contents, &ref))
   35     {
   36         if (!ed.bibtex_keys.contains(ref.citeidName, Qt::CaseSensitive))
   37             continue;
   38         if (ed.copy_documents)
   39         {
   40             const QString sfn(ref.value("file"));
   41             if (!sfn.isEmpty())
   42             {
   43                 const QString dfn(c2bUtils::documentAbsoluteName(ed.relative_dir, ed.export_fn, ed.documents_dir, sfn));
   44                 QFile source(sfn);
   45                 if (!source.copy(dfn))
   46                     export_log += tr("% Unable to copy file %1 to %2. %3.\n").arg(sfn, dfn, source.errorString());
   47                 if (QFileInfo::exists(dfn))
   48                 {
   49                     const int pos(filere.indexIn(ref.rawReference, 0));
   50                     if (pos > -1)
   51                     {
   52                         QString line(filere.cap(0));
   53                         const QString file(filere.cap(1));
   54                         line.replace(file,
   55                                      c2bUtils::documentFilename(ed.relative_dir, ed.export_fn, ed.documents_dir, sfn));
   56                         ref.rawReference.replace(pos, filere.matchedLength(), line);
   57                     }
   58                 }
   59             }
   60         }
   61         export_contents += ref.rawReference + "\n\n";
   62     }
   63     if (!export_log.isEmpty())
   64         export_contents = "% cb2Bib " + C2B_VERSION + " / Export Error Log\n" + export_log + export_contents;
   65     if (!c2bUtils::stringToFile(export_contents, ed.export_fn))
   66         c2bUtils::warn(tr("Unable to write file %1").arg(ed.export_fn));
   67 }