import std.file; import std.string; import std.stdio; import std.process; import std.array; void main(string[] args) { string imports = q{ import arsd.cgi; import std.stdio; import std.string; import std.file; import std.conv; import std.algorithm; import std.date; }; string mainf = `void dhcpmain(Cgi cgi) {`; bool inD = false; string currentLiteral = ""; string currentPrinter = ""; void addToCurrentLiteral(string s) { currentLiteral ~= s.replace("`", "`~\"`\"~`"); } void outputCurrentLiteral() { if(currentLiteral.length == 0) return; mainf ~= "cgi.write(`"~currentLiteral~"`);"; currentLiteral.length = 0; } void appendCode(string line) { outputCurrentLiteral; if(line.length > 6 && line[0..6] == "import") imports ~= line; else mainf ~= line; } foreach(ln; File(getenv("PATH_TRANSLATED")).byLine) { string line = ln.idup ~ "\n"; modeSwitch: if(line.length == 0) continue; if(!inD) { int idx = line.indexOf(""); if(end == -1) throw new Exception(" must be on one line"); end += idx + 2; outputCurrentLiteral; mainf ~= `cgi.write(`~line[idx+3..end].replace(`"`, `\"`)~`);`; line = line[end+2..$]; goto modeSwitch; break; default: addToCurrentLiteral(line); } } } else { int idx = line.indexOf("?>"); if(idx == -1) { appendCode(line); } else { appendCode(line[0..idx]); line = line[idx+2..$]; inD = false; goto modeSwitch; } } } outputCurrentLiteral; mainf ~= `} mixin GenericMain!(dhcpmain);`; std.file.write("/tmp/tempdprog.d", imports ~ mainf); system("cd /tmp; dmd tempdprog.d cgi.d 2>&1 > /dev/null; ./tempdprog"); }