From 3956205a265411c119e2c3b992e3d5e1953650ee Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 28 Oct 2023 16:02:29 +0200 Subject: [PATCH] [skip ci] Tools: add XML format tool --- src/Tools/xmlformat/CMakeLists.txt | 17 +++++++++ src/Tools/xmlformat/main.cpp | 60 ++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/Tools/xmlformat/CMakeLists.txt create mode 100644 src/Tools/xmlformat/main.cpp diff --git a/src/Tools/xmlformat/CMakeLists.txt b/src/Tools/xmlformat/CMakeLists.txt new file mode 100644 index 0000000000..b06e4d0798 --- /dev/null +++ b/src/Tools/xmlformat/CMakeLists.txt @@ -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) diff --git a/src/Tools/xmlformat/main.cpp b/src/Tools/xmlformat/main.cpp new file mode 100644 index 0000000000..527a7a9132 --- /dev/null +++ b/src/Tools/xmlformat/main.cpp @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +/*************************************************************************** + * Copyright (c) 2023 Werner Mayer * + * * + * 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 * + * . * + * * + **************************************************************************/ + +#include +#include +#include +#include + +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; +}