gmk unpacker: better event export
[gaemu.git] / gaem / utils / cliarg.d
blob206ec567296f0faf855b8a6623ce787fe7a00a6b
1 /* GML utils
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 module gaem.utils.cliarg is aliced;
20 import gaem.parser;
21 import gaem.utils.loader;
22 import gaem.ungmk;
25 // ////////////////////////////////////////////////////////////////////////// //
26 NodeFunc[] cliProcessArgs(Opts...) (ref string[] args, void delegate (Gmk gmk) procgmk=null) {
27 NodeFunc[] funcs;
28 bool nomore = false;
29 string[] scargs;
30 bool doScripts = true;
31 bool doActions = true;
32 bool dumpFileNames = false;
33 foreach (string fname; args[1..$]) {
34 import std.file;
35 import std.path;
36 if (nomore) {
37 scargs ~= fname;
38 } else {
39 if (fname.length == 0) continue;
40 if (fname == "--") { nomore = true; continue; }
41 if (fname == "-S") { doScripts = false; continue; }
42 if (fname == "-A") { doActions = false; continue; }
43 if (fname == "-d") { dumpFileNames = true; continue; }
44 bool found = false;
45 foreach (immutable idx, immutable val; Opts) {
46 static if (idx%2 == 0) {
47 if (fname == Opts[idx]) { found = true; Opts[idx+1](fname); break; }
50 if (found) continue;
51 if (fname[0] == '-') throw new Exception("invalid option: '"~fname~"'");
52 if (fname[0] == '@') {
53 if (fname.length < 2) assert(0, "gmk file?");
54 if (dumpFileNames) { import std.stdio; writeln("loading '", fname[1..$], "'..."); }
55 auto gmk = new Gmk(fname[1..$]);
56 funcs ~= gmkLoadScripts(gmk, doScripts:doScripts, doActions:doActions);
57 if (procgmk !is null) procgmk(gmk);
58 continue;
60 if (isDir(fname)) {
61 foreach (auto de; dirEntries(fname, "*.gm[lx]", SpanMode.breadth)) {
62 bool doit = true;
63 foreach (auto pt; pathSplitter(de.dirName)) {
64 if (pt.length && pt[0] == '_') { doit = false; break; }
66 if (doit) {
67 if (dumpFileNames) { import std.stdio; writeln("loading '", de.name, "'..."); }
68 funcs ~= loadScript(de.name, true);
71 } else {
72 if (dumpFileNames) { import std.stdio; writeln("loading '", fname, "'..."); }
73 funcs ~= loadScript(fname, true);
77 args = scargs;
78 return funcs;