diff src/main.d @ 1:4a9dcbd9e54f

-files of 0.13 beta -fixes so that it now compiles with the current dmd version
author marton@basel.hu
date Tue, 05 Apr 2011 20:44:01 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main.d	Tue Apr 05 20:44:01 2011 +0200
@@ -0,0 +1,117 @@
+/*  Ddbg - Win32 Debugger for the D programming language
+ *  Copyright (c) 2007 Jascha Wetzel
+ *  All rights reserved. See LICENSE.TXT for details.
+ */
+
+import cli.userinterface;
+import cli.ddbgcli;
+import cli.gdbcli;
+import cli.gdbmicli;
+import debugger;
+
+import std.string;
+import std.stdio;
+
+import util;
+
+/**************************************************************************************************
+
+**************************************************************************************************/
+int main(string[] args)
+{
+    debug domain(args);
+    else
+    {
+        try domain(args);
+        catch ( DebuggerException e )
+        {
+            writefln("%s", e.msg);
+            return 1;
+        }
+        catch ( Object o )
+        {
+            writefln("\n\n----------------------------------------\nUnhandled exception in %s:\n"~
+                    "%s\n\nPlease report this problem!\nSee the http://ddbg.mainia.de/releases.html for details.\nThank you!",
+                    VERSION_STRING, o
+            );
+            return 1;
+        }
+    }
+	return 0;
+}
+
+void domain(string[] args)
+{
+    string[string] options = parseArgs(args);
+
+    UserInterface cli;
+    if ( ("cli" in options) !is null )
+    {
+        if ( options["cli"] == "gdb" )
+            cli	= new GDBCLI;
+        else if ( options["cli"] == "gdbmi" )
+            cli	= new GDBMICLI;
+        else {
+            DbgIO.println("Unknown CLI mode \"%s\"", options["cli"]);
+            return;
+        }
+    }
+    else
+        cli	= new DdbgCLI;
+    cli.init(args);
+
+    if ( "cmd" in options )
+    {
+        string cmd_string = strip(options["cmd"]);
+        if ( cmd_string[0] == '"' && cmd_string[$-1] == '"' )
+            cmd_string = cmd_string[1..$-1];
+        cli.runCommands(cmd_string);
+    }
+
+    cli.start();
+}
+
+string[string] parseArgs(inout string[] args)
+{
+    string[string]    options;
+
+    for ( int i=1; i < args.length; )
+    {
+        string arg = args[i];
+
+        uint optend;
+        for ( optend = 1; optend < arg.length; ++optend )
+        {
+            if ( !inPattern(arg[optend], "a-zA-Z0-9") )
+                break;
+        }
+        string option = arg[0..optend];
+        switch ( option )
+        {
+            case "-cli":
+            case "-cmd":
+                string value;
+                if ( optend >= arg.length ) {
+                    args = args[0..i]~args[i+1..$];
+                    value = args[i];
+                }
+                else
+                    value = arg[optend..$];
+                if ( value.length <= 0 ) {
+                    DbgIO.println("ERROR: -%s=<value> or -%s <value> expected", option, option);
+                    break;
+                }
+                if ( value[0] == '=' )
+                    value = value[1..$];
+                options[option[1..$]] = value;
+                args = args[0..i]~args[i+1..$];
+                break;
+            default:
+                ++i;
+                if ( option[0] != '-' )
+                    return options;
+                break;
+        }
+    }
+    return options;
+}