Patches by Jens B. Jorgensen with small mods by me:
- Converted the templates to use ANSI C prototypes (finally!)
- Use re in stead of deprecated regex
diff --git a/Tools/modulator/varsubst.py b/Tools/modulator/varsubst.py
index 06e9683..71a2b26 100644
--- a/Tools/modulator/varsubst.py
+++ b/Tools/modulator/varsubst.py
@@ -2,37 +2,33 @@
 # Variable substitution. Variables are $delimited$
 #
 import string
-import regex
-import regsub
+import re
 
 error = 'varsubst.error'
 
 class Varsubst:
     def __init__(self, dict):
         self.dict = dict
-        self.prog = regex.compile('\$[a-zA-Z0-9_]*\$')
+        self.prog = re.compile('\$([a-zA-Z0-9_]*)\$')
         self.do_useindent = 0
 
     def useindent(self, onoff):
         self.do_useindent = onoff
         
-    def subst(self, str):
+    def subst(self, s):
         rv = ''
         while 1:
-            pos = self.prog.search(str)
-            if pos < 0:
-                return rv + str
-            if pos:
-                rv = rv + str[:pos]
-                str = str[pos:]
-            len = self.prog.match(str)
-            if len == 2:
+            m = self.prog.search(s)
+            if not m:
+                return rv + s
+            rv = rv + s[:m.start()]
+            s = s[m.end():]
+            if m.end() - m.start() == 2:
                 # Escaped dollar
                 rv = rv + '$'
-                str = str[2:]
+                s = s[2:]
                 continue
-            name = str[1:len-1]
-            str = str[len:]
+            name = m.group(1)
             if not self.dict.has_key(name):
                 raise error, 'No such variable: '+name
             value = self.dict[name]
@@ -44,7 +40,7 @@
         lastnl = string.rfind(old, '\n', 0) + 1
         lastnl = len(old) - lastnl
         sub = '\n' + (' '*lastnl)
-        return regsub.gsub('\n', sub, value)
+        return re.sub('\n', sub, value)
 
 def _test():
     import sys