Panda3D
|
00001 // Filename: xFileTrans.cxx 00002 // Created by: drose (03Oct04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "xFileTrans.h" 00016 #include "xFile.h" 00017 #include "pystub.h" 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: XFileTrans::Constructor 00021 // Access: Public 00022 // Description: 00023 //////////////////////////////////////////////////////////////////// 00024 XFileTrans:: 00025 XFileTrans() : 00026 WithOutputFile(true, false, true) 00027 { 00028 // Indicate the extension name we expect the user to supply for 00029 // output files. 00030 _preferred_extension = ".x"; 00031 00032 set_program_description 00033 ("This program reads a DirectX retained-mode file (.x) and writes an " 00034 "essentially equivalent .x file. It is primarily useful for " 00035 "debugging the X file parser that is part of the Pandatool library."); 00036 00037 clear_runlines(); 00038 add_runline("[opts] input.x output.x"); 00039 add_runline("[opts] -o output.x input.x"); 00040 00041 add_option 00042 ("o", "filename", 0, 00043 "Specify the filename to which the resulting .x file will be written. " 00044 "If this option is omitted, the last parameter name is taken to be the " 00045 "name of the output file.", 00046 &XFileTrans::dispatch_filename, &_got_output_filename, &_output_filename); 00047 } 00048 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: XFileTrans::run 00052 // Access: Public 00053 // Description: 00054 //////////////////////////////////////////////////////////////////// 00055 void XFileTrans:: 00056 run() { 00057 nout << "Reading " << _input_filename << "\n"; 00058 00059 XFile file; 00060 if (!file.read(_input_filename)) { 00061 nout << "Unable to read.\n"; 00062 exit(1); 00063 } 00064 00065 if (!file.write(get_output())) { 00066 nout << "Unable to write.\n"; 00067 exit(1); 00068 } 00069 } 00070 00071 00072 //////////////////////////////////////////////////////////////////// 00073 // Function: XFileTrans::handle_args 00074 // Access: Protected, Virtual 00075 // Description: 00076 //////////////////////////////////////////////////////////////////// 00077 bool XFileTrans:: 00078 handle_args(ProgramBase::Args &args) { 00079 if (!check_last_arg(args, 1)) { 00080 return false; 00081 } 00082 00083 if (args.empty()) { 00084 nout << "You must specify the .x file to read on the command line.\n"; 00085 return false; 00086 00087 } else if (args.size() != 1) { 00088 nout << "You must specify only one .x file to read on the command line.\n"; 00089 return false; 00090 } 00091 00092 _input_filename = args[0]; 00093 00094 return true; 00095 } 00096 00097 00098 int main(int argc, char *argv[]) { 00099 // A call to pystub() to force libpystub.so to be linked in. 00100 pystub(); 00101 00102 XFileTrans prog; 00103 prog.parse_command_line(argc, argv); 00104 prog.run(); 00105 return 0; 00106 }