Panda3D

Loading...
Searching...
No Matches
xFileTrans.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file xFileTrans.cxx
10 * @author drose
11 * @date 2004-10-03
12 */
13
14#include "xFileTrans.h"
15#include "xFile.h"
16
17/**
18 *
19 */
20XFileTrans::
21XFileTrans() :
22 WithOutputFile(true, false, true)
23{
24 // Indicate the extension name we expect the user to supply for output
25 // files.
26 _preferred_extension = ".x";
27
28 set_program_brief("reads and writes DirectX .x files");
29 set_program_description
30 ("This program reads a DirectX retained-mode file (.x) and writes an "
31 "essentially equivalent .x file. It is primarily useful for "
32 "debugging the X file parser that is part of the Pandatool library.");
33
34 clear_runlines();
35 add_runline("[opts] input.x output.x");
36 add_runline("[opts] -o output.x input.x");
37
38 add_option
39 ("o", "filename", 0,
40 "Specify the filename to which the resulting .x file will be written. "
41 "If this option is omitted, the last parameter name is taken to be the "
42 "name of the output file.",
43 &XFileTrans::dispatch_filename, &_got_output_filename, &_output_filename);
44}
45
46
47/**
48 *
49 */
50 void XFileTrans::
51run() {
52 nout << "Reading " << _input_filename << "\n";
53
54 XFile file;
55 if (!file.read(_input_filename)) {
56 nout << "Unable to read.\n";
57 exit(1);
58 }
59
60 if (!file.write(get_output())) {
61 nout << "Unable to write.\n";
62 exit(1);
63 }
64}
65
66
67/**
68 *
69 */
70 bool XFileTrans::
71handle_args(ProgramBase::Args &args) {
72 if (!check_last_arg(args, 1)) {
73 return false;
74 }
75
76 if (args.empty()) {
77 nout << "You must specify the .x file to read on the command line.\n";
78 return false;
79
80 } else if (args.size() != 1) {
81 nout << "You must specify only one .x file to read on the command line.\n";
82 return false;
83 }
84
85 _input_filename = args[0];
86
87 return true;
88}
89
90
91 int main(int argc, char *argv[]) {
92 XFileTrans prog;
93 prog.parse_command_line(argc, argv);
94 prog.run();
95 return 0;
96}
ProgramBase::parse_command_line
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
Definition programBase.cxx:286
WithOutputFile
This is the bare functionality (intended to be inherited from along with ProgramBase or some derivati...
Definition withOutputFile.h:29
WithOutputFile::get_output
std::ostream & get_output()
Returns an output stream that corresponds to the user's intended egg file output–either stdout,...
Definition withOutputFile.cxx:50
XFileTrans
A program to read a X file and output an essentially similar X file.
Definition xFileTrans.h:26
XFile::read
bool read(Filename filename)
Opens and reads the indicated .x file by name.
Definition xFile.cxx:73
XFile::write
bool write(Filename filename) const
Opens the indicated filename for output and writes a parseable description of all the known distribut...
Definition xFile.cxx:130
xFileTrans.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
xFile.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.