forked from FreeCAD/FreeCAD
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skip ci] Tools: add XML format tool
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |