Showing with 9 additions and 2 deletions.
  1. +7 −0 src/magicport.json
  2. +1 −1 src/magicport/dprinter.d
  3. +1 −1 src/magicport/magicport2.d
7 changes: 7 additions & 0 deletions src/magicport.json
Original file line number Diff line number Diff line change
Expand Up @@ -2601,6 +2601,13 @@
" enum xversion = mixin(`{ version (` ~ s ~ `) return true; else return false; }`)();",
"}",
"",
"private string stripRight(string s)",
"{",
" while (s.length && (s[$-1] == ' ' || s[$-1] == '\\n' || s[$-1] == '\\r'))",
" s = s[0 .. $-1];",
" return s;",
"}",
"",
"enum __linux__ = xversion!`linux`;",
"enum __APPLE__ = xversion!`OSX`;",
"enum __FreeBSD__ = xversion!`FreeBSD`;",
Expand Down
2 changes: 1 addition & 1 deletion src/magicport/dprinter.d
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class DPrinter : Visitor
switch(s)
{
case "NULL": print("null"); return;
case "__IMPORT__": print("\"v\" ~ import(\"verstr.h\")[1 .. 6]"); return;
case "__VERSTR__": print("('v' ~ stripRight(import(\"verstr.h\"))[1 .. $-1] ~ '\\0').ptr"); return;
case "operator ==": print("opEquals"); return;
case "import", "module", "version", "ref", "scope",
"body", "alias", "is",
Expand Down
2 changes: 1 addition & 1 deletion src/magicport/magicport2.d
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void main(string[] args)
writeln("loading -- ", fn);
assert(fn.exists(), fn ~ " does not exist");
auto pp = cast(string)read(fn);
pp = pp.replace("\"v\"\n#include \"verstr.h\"\n ;", "__IMPORT__;");
pp = pp.replace("\"v\"\n#include \"verstr.h\"\n ;", "__VERSTR__;");
auto tx = Lexer(pp, fn).array;
toks[fn] = tx;
foreach(i, t; tx)
Expand Down