[Scummvm-cvs-logs] SF.net SVN: scummvm:[41642] tools/branches/gsoc2009-decompiler/decompiler

kjdf at users.sourceforge.net kjdf at users.sourceforge.net
Thu Jun 18 21:03:48 CEST 2009


Revision: 41642
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41642&view=rev
Author:   kjdf
Date:     2009-06-18 19:03:48 +0000 (Thu, 18 Jun 2009)

Log Message:
-----------
decompiler: commandline parsing with boost::program_options

Modified Paths:
--------------
    tools/branches/gsoc2009-decompiler/decompiler/Makefile
    tools/branches/gsoc2009-decompiler/decompiler/decompiler.cc

Modified: tools/branches/gsoc2009-decompiler/decompiler/Makefile
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/Makefile	2009-06-18 18:57:17 UTC (rev 41641)
+++ tools/branches/gsoc2009-decompiler/decompiler/Makefile	2009-06-18 19:03:48 UTC (rev 41642)
@@ -6,7 +6,7 @@
 #	g++ -Wall -g -c $< -o $@
 
 decompiler: decompiler.o $(DEPS)
-	g++ -Wall -g $^ -o $@
+	g++ -Wall -g  -lboost_program_options $^ -o $@
 
 decompiler.o: decompiler.cc misc.h instruction.h parser.h reader.h cfg.h
 	g++ -Wall -g -c decompiler.cc -o decompiler.o

Modified: tools/branches/gsoc2009-decompiler/decompiler/decompiler.cc
===================================================================
--- tools/branches/gsoc2009-decompiler/decompiler/decompiler.cc	2009-06-18 18:57:17 UTC (rev 41641)
+++ tools/branches/gsoc2009-decompiler/decompiler/decompiler.cc	2009-06-18 19:03:48 UTC (rev 41642)
@@ -1,46 +1,59 @@
-#include <cstdio>
-#include <cstring>
-#include <vector>
+#include <iostream>
 
-using namespace std;
+#include <boost/program_options.hpp>
 
 #include "parser.h"
-#include "instruction.h"
 #include "cfg.h"
 
-bool g_disasm = false;
-bool g_blocks = false;
-bool g_graph = false;
+using namespace std;
+using namespace boost::program_options;
 
-int main(int argc, char **argv) {
-	int argno = 1;
-	if (argno >= argc) {
-		printf("decompiler [-disasm] [-blocks] [-graph] file.dmp\n");
-		return 0;
+
+variables_map parseArgs(int argc, char **argv) {
+	variables_map vars;
+	options_description visible("Allowed options");
+	visible.add_options()
+		("help", "this message")
+		("disasm", "print disassembly and exit")
+		("blocks", "print basic blocks and exit")
+		("graph",  "print graph and exit");
+	options_description options("Allowed options");
+	options.add(visible).add_options()
+		("inputfile", value<string>(), "input file");
+	positional_options_description pos;
+	pos.add("inputfile", 1);
+	try {
+		store(command_line_parser(argc, argv).options(options).positional(pos).run(), vars);
+		notify(vars);
+	} catch (error) {
 	}
-	while (true) {
-		if (0 == strcmp("-disasm", argv[argno])) {
-			g_disasm = true;
-			argno++;
-		} else if (0 == strcmp("-blocks", argv[argno])) {
-			g_blocks = true;
-			argno++;
-		} else if (0 == strcmp("-graph", argv[argno])) {
-			g_graph = true;
-			argno++;
-		} else
-			break;
+	if (vars.count("help") || !vars.count("inputfile")) {
+		cout << argv[0] << " [option...] file" << endl << endl;
+		cout << visible;
+		exit(0);
 	}
-	Script script(new Scumm6Parser(), argv[argno]);
-	if (g_disasm)
-		for (index_t i = 0; i < script.size(); i++)
+	return vars;
+}
+
+
+int main(int argc, char **argv) {
+	variables_map vars = parseArgs(argc, argv);
+	Script script(new Scumm6Parser, vars["inputfile"].as<string>().c_str());
+	if (vars.count("disasm")) {
+		for (size_t i = 0; i < script.size(); i++)
 			script.print(i);
+		exit(0);
+	}
 	CFG cfg(script);
-	if (g_blocks)
+	if (vars.count("blocks")) {
 		cfg.printBasicBlocks();
+		exit(0);
+	}
 	cfg.removeJumpsToJumps();
 	cfg.removeDeadBlocks();
-	if (g_graph)
+	if (vars.count("graph")) {
 		cfg.printDot();
+		exit(0);
+	}
 	return 0;
 }


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