#!/usr/bin/env python
import tempfile
import subprocess
import os
import sys
import re
import shutil

from mako.template import Template

f = open('interpnd.pyx', 'r')
template = f.read()
f.close()

tmp_dir = tempfile.mkdtemp()
try:
    # Run templating engine
    fn = os.path.join(tmp_dir, 'interpnd.pyx')
    f = open(fn, 'w')
    f.write(Template(template).render())
    f.close()

    # Run Cython
    dst_fn = os.path.join(tmp_dir, 'interpnd.c')
    ret = subprocess.call(['cython', '-I', '../..', '-o', dst_fn, fn])
    if ret != 0:
        sys.exit(ret)

    # Strip comments
    f = open(dst_fn, 'r')
    text = f.read()
    f.close()

    r = re.compile(r'/\*(.*?)\*/', re.S)

    text = r.sub('', text)
    f = open('interpnd.c', 'w')
    f.write(text)
    f.close()
finally:
    shutil.rmtree(tmp_dir)

@@ -131,16 +131,102 @@
 mplate%0A%0A
+dotnet = False%0Aif len(sys.argv) %3E 1 and sys.argv%5B1%5D == '--dotnet':%0A    dotnet = True%0A%0A
 f = open
@@ -482,16 +482,165 @@
  Cython%0A
+    if dotnet:%0A        dst_name = 'interpnd.cpp'%0A        args_extra = %5B'--dotnet'%5D%0A    else:%0A        dst_name = 'interpnd.c'%0A        args_extra = %5B%5D%0A
     dst_
@@ -670,22 +670,23 @@
 ir, 
-'interpnd.c'
+dst_name
 )%0A
+    %0A
     
@@ -737,18 +737,34 @@
 .', '-o'
-, 
+%5D + args_extra + %5B
 dst_fn, 
@@ -972,28 +972,24 @@
  = open(
-'interpnd.c'
+dst_name
 , 'w')%0A 

Modify the interpnd cython generator to allow .NET output