/* Digital Mars DMDScript source code. * Copyright (c) 2000-2002 by Chromium Communications * D version Copyright (c) 2004-2005 by Digital Mars * All Rights Reserved * written by Walter Bright * www.digitalmars.com * Use at your own risk. There is no warranty, express or implied. * License for redistribution is by the GNU General Public License in gpl.txt. * * A binary, non-exclusive license for commercial use can be * purchased from www.digitalmars.com/dscript/buy.html. * * DMDScript is implemented in the D Programming Language, * www.digitalmars.com/d/ * * For a C++ implementation of DMDScript, including COM support, * see www.digitalmars.com/dscript/cpp.html. */ module gtkds; import std.path; import std.file; import std.stdio; import std.c.stdlib; import dmdscript.script; import dmdscript.program; import dmdscript.errmsgs; import dmdscript.SrcFile; enum { EXITCODE_INIT_ERROR = 1, EXITCODE_INVALID_ARGS = 2, EXITCODE_RUNTIME_ERROR = 3, } version (Windows) { pragma(lib, "dmdscript"); } /************************************************** Usage: ds will run test.ds ds foo will run foo.ds ds foo.js will run foo.js ds foo1 foo2 foo.bar will run foo1.ds, foo2.ds, foo.bar * Flags: * * -r "some code ...." * Run some code * -i ??? * Depreciate? * -L/somepath/ * Include path for 'include statements. (should be import??) * * -v * Verbose ??? * -d * Show the opcodes * -p * Profile calls * -l * Lex only * -U * Enable Unicode String support.. * */ int main(char[][] args) { // //std.gc.disable(); // we really need to mark our pointers ... uint errors = 0; char[][] includes; char[][] libdirs; char[] runcode; SrcFile[] srcfiles; int result; bool verbose; ErrInfo errinfo; int debugLevel =0; int lexOnly = 0; uint profileOn =0; uint unicodeStrings =0; //fwritefln(stderr, dmdscript.script.banner()); for (size_t i = 1; i < args.length; i++) { char[] p = args[i]; if (p[0] == '-') { if (p[1] == '-') { break; } switch (p[1]) { case 'r': runcode = args[i+1]; i++; break; case 'i': if (p[2]) includes ~= p[2 .. length]; break; case 'L': if (p[2]) libdirs ~= p[2 .. length]; break; case 'v': verbose = 1; break; case 'p': profileOn = 1; break; case 'd': debugLevel = 1; break; case 'l': lexOnly = 1; break; case 'U': unicodeStrings = 1; break; default: writefln(errmsgtbl[ERR_BAD_SWITCH],p); errors++; break; } } else { // single file includes as we do not need more.. if (srcfiles.length == 0) { srcfiles ~= new SrcFile(p, includes ,args); includes = null; } } } if (errors) return EXITCODE_INVALID_ARGS; if (!runcode.length && !srcfiles.length) { throw new Exception("No source files or code specified"); //srcfiles ~= new SrcFile("test", null); } // fwritefln(stderr, "%d source files", srcfiles.length); if (runcode.length) { auto program = new Program(); program.debugLevel = debugLevel; program.lexOnly= lexOnly; program.libDirs = libdirs; program.profileOn = profileOn; foreach(reg;dmdscriptRegister) { reg(program.callcontext, args); } //Register_Gtk(program.callcontext); program.compile("stdin", runcode, null); program.execute(args); return EXIT_SUCCESS; } // this is pretty dumb, we should only have one source file!!!! // Read files, parse them, execute them foreach (SrcFile m; srcfiles) { if (verbose) writefln("read %s:", m.srcfile); m.program.debugLevel = debugLevel; m.program.lexOnly= lexOnly; m.program.libDirs= libdirs; m.program.profileOn= profileOn; m.program.unicodeStrings = unicodeStrings; m.read(); if (verbose) writefln("compile %s:", m.srcfile); m.compile(); if (verbose) writefln("execute %s:", m.srcfile); m.execute(); m.program.dumpProfile(); } return EXIT_SUCCESS; }