File: pntreplace.cpp

package info (click to toggle)
marble 4%3A25.08.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 159,996 kB
  • sloc: cpp: 191,890; xml: 39,908; ansic: 7,204; python: 2,190; sh: 1,187; makefile: 235; perl: 218; ruby: 97; java: 66
file content (103 lines) | stat: -rw-r--r-- 3,185 bytes parent folder | download | duplicates (2)
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
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// SPDX-FileCopyrightText: 2012 Torsten Rahn <tackat@kde.org>
//

#include "svgxmlhandler.h"
#include <QApplication>
#include <QDataStream>
#include <QDebug>
#include <QFile>
#include <QXmlInputSource>
#include <QXmlSimpleReader>

void parseSvg(const QString &svgFilename, QDataStream *out, const QString &path, int header)
{
    SVGXmlHandler handler(out, path, header);
    QFile xmlFile(svgFilename);
    QXmlInputSource inputSource(&xmlFile);
    QXmlSimpleReader reader;

    reader.setContentHandler(&handler);
    reader.parse(inputSource);
}

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    qDebug(" Syntax: pntreplace [-i pnt-sourcefile -o pnt-targetfile -s svg-replacementfile -id pntidNumber -path svgpathid] ");

    QString inputFilename("PDIFFBORDERS.PNT");
    int inputIndex = app.arguments().indexOf("-i");
    if (inputIndex > 0 && inputIndex + 1 < argc)
        inputFilename = app.arguments().at(inputIndex + 1);

    QString outputFilename("NEW.PNT");
    int outputIndex = app.arguments().indexOf("-o");
    if (outputIndex > 0 && outputIndex + 1 < argc)
        outputFilename = app.arguments().at(outputIndex + 1);

    QString svgFilename("output.svg");
    int svgIndex = app.arguments().indexOf("-s");
    if (svgIndex > 0 && svgIndex + 1 < argc)
        svgFilename = app.arguments().at(svgIndex + 1);

    QString path("id_path");
    int pathIndex = app.arguments().indexOf("-path");
    if (pathIndex > 0 && pathIndex + 1 < argc)
        path = app.arguments().at(pathIndex + 1);

    int delIndex = -1;
    int idIndex = app.arguments().indexOf("-id");
    if (idIndex > 0 && idIndex + 1 < argc)
        delIndex = app.arguments().at(idIndex + 1).toInt();

    qDebug() << "input filename:" << inputFilename;
    qDebug() << "output filename:" << outputFilename;
    qDebug() << "svg replacement filename:" << svgFilename;
    qDebug() << "replace index:" << delIndex;
    qDebug() << "replacement:" << path;

    // INPUT
    QFile file(inputFilename);

    if (file.open(QIODevice::ReadOnly)) {
        QDataStream stream(&file); // read the data serialized from the file
        stream.setByteOrder(QDataStream::LittleEndian);

        // OUTPUT
        QFile data(outputFilename);

        if (data.open(QFile::WriteOnly | QFile::Truncate)) {
            QDataStream out(&data);
            out.setByteOrder(QDataStream::LittleEndian);

            short header;
            short iLat;
            short iLon;

            bool skip = false;

            while (!stream.atEnd()) {
                stream >> header >> iLat >> iLon;
                if (header == delIndex) {
                    parseSvg(svgFilename, &out, path, delIndex);
                    skip = true;
                } else if (header > 5)
                    skip = false;

                if (!skip)
                    out << header << iLat << iLon;
            }
            data.close();
        } else {
            qDebug() << "ERROR: Couldn't write output file to disc!";
        }
        file.close();
    } else {
        qDebug() << "ERROR: Source file not found!";
    }

    app.exit();
}