Panda3D
lwoScan.cxx
1 // Filename: lwoScan.cxx
2 // Created by: drose (24Apr01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "lwoScan.h"
16 
17 #include "lwoInputFile.h"
18 #include "lwoChunk.h"
19 #include "config_lwo.h"
20 #include "pystub.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: LwoScan::Constructor
24 // Access: Public
25 // Description:
26 ////////////////////////////////////////////////////////////////////
27 LwoScan::
28 LwoScan() {
29  clear_runlines();
30  add_runline("[opts] input.lwo");
31 
32  set_program_brief("describe the contents of a Lightwave object file");
33  set_program_description
34  ("This program simply reads a Lightwave object file and dumps its "
35  "contents to standard output. It's mainly useful for debugging "
36  "problems with lwo2egg.");
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: LwoScan::run
41 // Access: Public
42 // Description:
43 ////////////////////////////////////////////////////////////////////
44 void LwoScan::
45 run() {
46  LwoInputFile in;
47  if (!in.open_read(_input_filename)) {
48  nout << "Unable to open " << _input_filename << "\n";
49  exit(1);
50  }
51 
52  PT(IffChunk) chunk = in.get_chunk();
53  if (chunk == (IffChunk *)NULL) {
54  nout << "Unable to read file.\n";
55  } else {
56  while (chunk != (IffChunk *)NULL) {
57  chunk->write(cout, 0);
58  chunk = in.get_chunk();
59  }
60  }
61 }
62 
63 ////////////////////////////////////////////////////////////////////
64 // Function: LwoScan::handle_args
65 // Access: Protected, Virtual
66 // Description:
67 ////////////////////////////////////////////////////////////////////
68 bool LwoScan::
69 handle_args(ProgramBase::Args &args) {
70  if (args.empty()) {
71  nout << "You must specify the Lightwave object file to read on the command line.\n";
72  return false;
73  }
74  if (args.size() != 1) {
75  nout << "You may specify only one Lightwave object file to read on the command line.\n";
76  return false;
77  }
78 
79  _input_filename = args[0];
80 
81  return true;
82 }
83 
84 
85 int
86 main(int argc, char *argv[]) {
87  // A call to pystub() to force libpystub.so to be linked in.
88  pystub();
89 
90  init_liblwo();
91  LwoScan prog;
92  prog.parse_command_line(argc, argv);
93  prog.run();
94  return 0;
95 }
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_...
bool open_read(Filename filename)
Attempts to open the indicated filename for reading.
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on...
Definition: iffChunk.h:32
A program to read a Lightwave file and report its structure and contents.
Definition: lwoScan.h:26
A specialization of IffInputFile to handle reading a Lightwave Object file.
Definition: lwoInputFile.h:29