1
/* -*- Mode: C++; coding: utf-8; tab-width: 3; indent-tabs-mode: tab; c-basic-offset: 3 -*-
2
*******************************************************************************
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
* Copyright create3000, Scheffelstra�e 31a, Leipzig, Germany 2011.
8
* All rights reserved. Holger Seelig <holger.seelig@yahoo.de>.
10
* THIS IS UNPUBLISHED SOURCE CODE OF create3000.
12
* The copyright notice above does not evidence any actual of intended
13
* publication of such source code, and is an unpublished work by create3000.
14
* This material contains CONFIDENTIAL INFORMATION that is the property of
17
* No permission is granted to copy, distribute, or create derivative works from
18
* the contents of this software, in whole or in part, without the prior written
19
* permission of create3000.
21
* NON-MILITARY USE ONLY
23
* All create3000 software are effectively free software with a non-military use
24
* restriction. It is free. Well commented source is provided. You may reuse the
25
* source in any way you please with the exception anything that uses it must be
26
* marked to indicate is contains 'non-military use only' components.
28
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
30
* Copyright 1999, 2016 Holger Seelig <holger.seelig@yahoo.de>.
32
* This file is part of the Titania Project.
34
* Titania is free software: you can redistribute it and/or modify it under the
35
* terms of the GNU General Public License version 3 only, as published by the
36
* Free Software Foundation.
38
* Titania is distributed in the hope that it will be useful, but WITHOUT ANY
39
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
40
* A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more
41
* details (a copy is included in the LICENSE file that accompanied this code).
43
* You should have received a copy of the GNU General Public License version 3
44
* along with Titania. If not, see <http://www.gnu.org/licenses/gpl.html> for a
45
* copy of the GPLv3 License.
47
* For Silvio, Joy and Adi.
49
******************************************************************************/
51
#ifndef __TITANIA_TIDY_H__
52
#define __TITANIA_TIDY_H__
54
#include <Titania/OS/cwd.h>
55
#include <Titania/String/to_string.h>
56
#include <Titania/X3D.h>
64
/// It never hurts to be tidy.
71
main (const ApplicationOptions & options)
75
X3D::Generator::Style (options .exportStyle);
77
auto browser = X3D::getBrowser ();
79
basic::uri uri (options .filename);
81
if (uri .is_relative ())
82
uri = basic::uri (os::cwd ()) .transform (uri);
84
if (options .exportFilename == "-")
86
if (uri .suffix () == ".x3d")
87
std::cout << X3D::XMLEncode (browser -> createX3DFromURL ({ uri .str () }));
89
else if (uri .suffix () == ".json")
90
std::cout << X3D::JSONEncode (browser -> createX3DFromURL ({ uri .str () }));
93
std::cout << browser -> createX3DFromURL ({ uri .str () });
97
basic::uri out (options .exportFilename);
99
if (out .is_relative ())
100
out = basic::uri (os::cwd ()) .transform (out);
102
std::string tmpFilename = "/tmp/x3dtidy." + basic::to_string (getpid (), std::locale::classic ()) + out .suffix ();
106
std::ofstream file (tmpFilename);
110
if (out .suffix () == ".x3d")
111
file << X3D::XMLEncode (browser -> createX3DFromURL ({ uri .str () }));
113
else if (out .suffix () == ".json")
114
file << X3D::JSONEncode (browser -> createX3DFromURL ({ uri .str () }));
117
file << browser -> createX3DFromURL ({ uri .str () });
121
rename (tmpFilename .c_str (), out .path () .c_str ());
125
unlink (tmpFilename .c_str ());
130
catch (const X3D::X3DError & error)
132
std::cerr << error .what () << std::endl;