summaryrefslogtreecommitdiffhomepage
path: root/tools/dfagen/dfagen/output
diff options
context:
space:
mode:
Diffstat (limited to 'tools/dfagen/dfagen/output')
-rw-r--r--tools/dfagen/dfagen/output/__init__.py7
-rw-r--r--tools/dfagen/dfagen/output/c.py19
-rw-r--r--tools/dfagen/dfagen/output/dot.py2
3 files changed, 20 insertions, 8 deletions
diff --git a/tools/dfagen/dfagen/output/__init__.py b/tools/dfagen/dfagen/output/__init__.py
index be71aef7..bbb8365a 100644
--- a/tools/dfagen/dfagen/output/__init__.py
+++ b/tools/dfagen/dfagen/output/__init__.py
@@ -8,10 +8,17 @@ class UserConfig:
cp.readfp (f)
f.close ()
self.dict = dict (cp.items ('user'))
+ if cp.has_section ('templates'):
+ self.templates = dict (cp.items ('templates'))
+ else:
+ self.templates = dict ()
def __getitem__ (self, key):
return self.dict[key]
+ def __contains__ (self, key):
+ return key in self.dict
+
import c
import dot
diff --git a/tools/dfagen/dfagen/output/c.py b/tools/dfagen/dfagen/output/c.py
index e19ca713..8c9b7dbb 100644
--- a/tools/dfagen/dfagen/output/c.py
+++ b/tools/dfagen/dfagen/output/c.py
@@ -141,14 +141,19 @@ class Writer:
o.close ()
def write (self):
- self.write_template ('template.h', self.data.prefix + '.h')
- self.write_template ('template.c', self.data.prefix + '.c')
- self.write_template ('template_cb.h', self.data.prefix + '_cb.h')
- self.write_template ('template_cb_skel.c',
- self.data.prefix + '_cb_skel.c')
+ templates = self.data.user.templates
+ if not templates:
+ templates = {
+ 'template.h': '%.h',
+ 'template.c': '%.c',
+ 'template_cb.h': '%_cb.h',
+ 'template_cb_skel.c': '%_cb_skel.c',
+ }
+ for (t, f) in templates.iteritems ():
+ self.write_template (t, f.replace ('%', self.data.prefix))
def write (prefix, automaton, user):
- w = Writer (WriterData (prefix, automaton, user),
- os.path.splitext (__file__)[0])
+ w = Writer (WriterData (prefix, automaton, user), 'template-dir' in user
+ and user['template-dir'] or os.path.splitext (__file__)[0])
w.write ()
diff --git a/tools/dfagen/dfagen/output/dot.py b/tools/dfagen/dfagen/output/dot.py
index 100cbb8f..be346b10 100644
--- a/tools/dfagen/dfagen/output/dot.py
+++ b/tools/dfagen/dfagen/output/dot.py
@@ -15,5 +15,5 @@ def write (prefix, automaton, user):
to = (br.to and br.to.name or s.name),
)
)
- o.write ('}')
+ o.write ('}\n')
o.close ()