[Scummvm-cvs-logs] SF.net SVN: scummvm:[49301] tools/branches/gsoc2010-decompiler/decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Sat May 29 00:00:43 CEST 2010
Revision: 49301
http://scummvm.svn.sourceforge.net/scummvm/?rev=49301&view=rev
Author: pidgeot
Date: 2010-05-28 22:00:43 +0000 (Fri, 28 May 2010)
Log Message:
-----------
Add short options and allow disassembly dump to stdout
Modified Paths:
--------------
tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp
tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
tools/branches/gsoc2010-decompiler/decompiler/disassembler.h
Modified: tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp 2010-05-28 21:04:03 UTC (rev 49300)
+++ tools/branches/gsoc2010-decompiler/decompiler/decompiler.cpp 2010-05-28 22:00:43 UTC (rev 49301)
@@ -20,6 +20,7 @@
*
*/
+#include <fstream>
#include <iostream>
#include <boost/program_options.hpp>
@@ -41,10 +42,10 @@
po::options_description visible("Options");
visible.add_options()
- ("help", "Produce this help message.")
- ("engine", po::value<std::string>(), "Engine the script originates from.")
- ("list", "List the supported engines.")
- ("dump-disassembly", po::value<std::string>(), "Dump the disassembly to a specified file.");
+ ("help,?", "Produce this help message.")
+ ("engine,e", po::value<std::string>(), "Engine the script originates from.")
+ ("list,l", "List the supported engines.")
+ ("dump-disassembly,d", po::value<std::string>()->implicit_value(""), "Dump the disassembly to a file. Leave out filename to output to stdout.");
po::options_description args("");
args.add(visible).add_options()
@@ -55,6 +56,7 @@
po::variables_map vm;
try {
+ //FIXME: If specified as the last parameter before the input file name, -d currently requires a filename to specified. -d must be specified earlier than that if outputting to stdout.
po::store(po::command_line_parser(argc, argv).options(args).positional(fileArg).run(), vm);
po::notify(vm);
} catch (std::exception& e) {
@@ -73,7 +75,8 @@
if (vm.count("help") || !vm.count("input-file")) {
std::cout << "Usage: " << argv[0] << " [option...] file" << "\n";
- std::cout << args << "\n";
+ std::cout << visible << "\n";
+ std::cout << "Note: If outputting to stdout, -d must NOT be specified immediately before the input file.\n";
return 1;
}
@@ -94,7 +97,17 @@
std::vector<Instruction> insts = disassembler->disassemble();
if (vm.count("dump-disassembly")) {
- disassembler->dumpDisassembly(vm["dump-disassembly"].as<std::string>().c_str());
+ std::streambuf * buf;
+ std::ofstream of;
+
+ if(vm["dump-disassembly"].as<std::string>() != "") {
+ of.open(vm["dump-disassembly"].as<std::string>().c_str());
+ buf = of.rdbuf();
+ } else {
+ buf = std::cout.rdbuf();
+ }
+ std::ostream out(buf);
+ disassembler->dumpDisassembly(out);
}
delete disassembler;
Modified: tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp 2010-05-28 21:04:03 UTC (rev 49300)
+++ tools/branches/gsoc2010-decompiler/decompiler/disassembler.cpp 2010-05-28 22:00:43 UTC (rev 49301)
@@ -30,10 +30,7 @@
_f.open(filename, "rb");
}
-void Disassembler::dumpDisassembly(const char *filename) {
- Common::File _output;
- _output.open(filename, "w");
-
+void Disassembler::dumpDisassembly(std::ostream &output) {
char buf[1024];
int length;
@@ -68,7 +65,7 @@
break;
}
}
- buf[length] = '\n';
- _output.write(buf, length + 1);
+ length += sprintf(&buf[length], "\n");
+ output << buf;
}
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/disassembler.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/disassembler.h 2010-05-28 21:04:03 UTC (rev 49300)
+++ tools/branches/gsoc2010-decompiler/decompiler/disassembler.h 2010-05-28 22:00:43 UTC (rev 49301)
@@ -23,6 +23,7 @@
#ifndef DEC_DISASSEMBLER_H
#define DEC_DISASSEMBLER_H
+#include <iostream>
#include <vector>
#include "instruction.h"
@@ -57,7 +58,6 @@
* Outputs the disassembly to a file.
* @param filename The file to output the disassembly to.
*/
- virtual void dumpDisassembly(const char *filename);
+ virtual void dumpDisassembly(std::ostream &output);
};
-
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list