Skip to content

Commit

Permalink
[skip ci] Tools: add XML format tool
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 28, 2023
1 parent 4c97acd commit 3956205
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Tools/xmlformat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.14)

project(xmlformat LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Xml REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Xml REQUIRED)

add_executable(xmlformat
main.cpp
)
target_link_libraries(xmlformat Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Xml)
60 changes: 60 additions & 0 deletions src/Tools/xmlformat/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: LGPL-2.1-or-later

/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/

#include <QCoreApplication>
#include <QFile>
#include <QDomDocument>
#include <iostream>

int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
QStringList args = QCoreApplication::arguments();
if (args.size() != 2) {
std::cerr << "Requires input file\n";
return -1;
}

QFile file(args[1]);
if (!file.open(QFile::ReadOnly)) {
std::cerr << "Failed to read file\n";
return -1;
}

QDomDocument xml;
if (!xml.setContent(&file)) {
std::cerr << "Invalid XML content\n";
return -1;
}
file.close();

if (!file.open(QFile::WriteOnly)) {
std::cerr << "Failed to write file\n";
return -1;
}

file.write(xml.toByteArray(4));
file.close();

return 0;
}

0 comments on commit 3956205

Please sign in to comment.