summaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorNicolas Schodet2008-03-25 23:04:37 +0100
committerNicolas Schodet2008-03-25 23:04:37 +0100
commit55ea6889987a9ca1e7429951e0e94be0fa99d7af (patch)
tree48469a2386f302b6c7dfa814d6094b61e89d223c /tools
parent1ea652e0d5185aee5ca60182302d7bb2d4056b46 (diff)
* tools/dfagen:
- fixed warning in doc. - fixed missing newline. - added use of non default templates. - added warning about parser.g. - removed .orig file when patching.
Diffstat (limited to 'tools')
-rw-r--r--tools/dfagen/dfagen/command.py8
-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
-rw-r--r--tools/dfagen/doc/dfagen.txt12
-rw-r--r--tools/dfagen/examples/Makefile8
-rw-r--r--tools/dfagen/examples/ex2_tpl.conf6
-rw-r--r--tools/dfagen/examples/tpl/template_defs.h46
-rw-r--r--tools/dfagen/examples/tpl/template_table.h12
9 files changed, 107 insertions, 13 deletions
diff --git a/tools/dfagen/dfagen/command.py b/tools/dfagen/dfagen/command.py
index d384087e..36f4803d 100644
--- a/tools/dfagen/dfagen/command.py
+++ b/tools/dfagen/dfagen/command.py
@@ -1,4 +1,10 @@
-import dfagen.parser, dfagen.output
+import dfagen.output
+try:
+ import dfagen.parser
+except ImportError:
+ print "--> You should run yapps on parser.g!"
+ raise
+
from optparse import OptionParser
def run ():
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 ()
diff --git a/tools/dfagen/doc/dfagen.txt b/tools/dfagen/doc/dfagen.txt
index 7e2b9abd..f3d8e93a 100644
--- a/tools/dfagen/doc/dfagen.txt
+++ b/tools/dfagen/doc/dfagen.txt
@@ -124,7 +124,7 @@ The ``-o`` option chooses the output method, the ``-d`` option gives your
automaton description, the ``-c`` option gives the output configuration file,
and the ``-p`` is the prefix, which is used to name output files.
-..warning: This is subject to change.
+.. warning:: This is subject to change.
Outputs
=======
@@ -170,7 +170,13 @@ and edit the copy. Next time, you will merge new elements to your version
The ``prefix.c`` file contains a function to be called each time en event
occurs. This function will run the corresponding transition callback and will
-check its return value.
+check its return value. Its return value should indicate the next state.
+
+Changing templates
+~~~~~~~~~~~~~~~~~~
+
+If the default output does not fit your needs, you can define your own
+templates. See ``ex2_tpl`` example.
Graphviz output
---------------
@@ -178,4 +184,4 @@ Graphviz output
Output name: ``dot``
There is currently no output configuration file. Run ``dot`` (from the
-Graphviz distribution to get a graphic output of the automaton.
+Graphviz distribution) to get a graphic output of the automaton.
diff --git a/tools/dfagen/examples/Makefile b/tools/dfagen/examples/Makefile
index b78f1121..1f7b3308 100644
--- a/tools/dfagen/examples/Makefile
+++ b/tools/dfagen/examples/Makefile
@@ -1,6 +1,6 @@
CFLAGS = -O2 -Wall
-all: ex1 ex2 ex1.png ex2.png
+all: ex1 ex2 ex1.png ex2.png ex2_tpl
ex1: ex1.o ex1_cb.o
@@ -12,6 +12,7 @@ ex1.h ex1_cb_skel.c ex1_cb.h: ex1.c
ex1_cb.c: ex1_cb_skel.c ex1_cb.c.patch
cp $< $@
patch $@ ex1_cb.c.patch
+ rm -f $@.orig
ex1.o: ex1_cb.h ex1.h
ex1_cb.o: ex1_cb.h ex1.h
@@ -26,6 +27,10 @@ ex2.h ex2_cb_skel.c ex2_cb.h: ex2.c
ex2_cb.c: ex2_cb_skel.c ex2_cb.c.patch
cp $< $@
patch $@ ex2_cb.c.patch
+ rm -f $@.orig
+
+ex2_tpl: ex2.fsm ex2_tpl.conf
+ python ../dfagen.py -o c -d $(filter %.fsm, $^) -c $(filter %.conf, $^) -p $@
%.dot: %.fsm
python ../dfagen.py -o dot -d $< -p $(@:%.dot=%)
@@ -38,3 +43,4 @@ clean:
rm -f ex1.dot ex1.png
rm -f ex2 ex2.o ex2_cb.o ex2_robot.o ex2.c ex2.h ex2_cb_skel.c ex2_cb.h ex2_cb.c
rm -f ex2.dot ex2.png
+ rm -f ex2_tpl_defs.h ex2_tpl_table.h
diff --git a/tools/dfagen/examples/ex2_tpl.conf b/tools/dfagen/examples/ex2_tpl.conf
new file mode 100644
index 00000000..7d97ddbe
--- /dev/null
+++ b/tools/dfagen/examples/ex2_tpl.conf
@@ -0,0 +1,6 @@
+[user]
+template-dir = tpl
+
+[templates]
+template_defs.h = %_defs.h
+template_table.h = %_table.h
diff --git a/tools/dfagen/examples/tpl/template_defs.h b/tools/dfagen/examples/tpl/template_defs.h
new file mode 100644
index 00000000..54fabba4
--- /dev/null
+++ b/tools/dfagen/examples/tpl/template_defs.h
@@ -0,0 +1,46 @@
+#ifndef %(prefix)s_defs_h
+#define %(prefix)s_defs_h
+/*
+ * THIS IS AN AUTOMATICALLY GENERATED FILE, DO NOT EDIT!
+ *
+ * %(name)s
+ *
+%(*comments)s */
+
+/* %(name)s states. */
+enum %(prefix)s_state_t
+{
+%(states)s %(PREFIX)s_STATE_NB
+};
+typedef enum %(prefix)s_state_t %(prefix)s_state_t;
+
+/* %(name)s events. */
+enum %(prefix)s_event_t
+{
+%(events)s %(PREFIX)s_EVENT_NB
+};
+typedef enum %(prefix)s_event_t %(prefix)s_event_t;
+
+/* Only care about next state. */
+#define _BRANCH(state, event, to) (%(PREFIX)s_STATE_ ## to)
+
+/* %(name)s branches. */
+enum %(prefix)s_branch_t
+{
+%(branches)s};
+typedef enum %(prefix)s_branch_t %(prefix)s_branch_t;
+
+#undef _BRANCH
+
+/* %(name)s transition type. */
+typedef %(prefix)s_branch_t (*%(prefix)s_transition_t) (void);
+
+/* Value to return to follow the only branch. */
+#define %(prefix)s_next(state, event) \
+ %(PREFIX)s_BRANCH__ ## state ## __ ## event ## __
+
+/* Value to return to follow a given branch. */
+#define %(prefix)s_next_branch(state, event, branch) \
+ %(PREFIX)s_BRANCH__ ## state ## __ ## event ## __ ## branch
+
+#endif /* %(prefix)s_defs_h */
diff --git a/tools/dfagen/examples/tpl/template_table.h b/tools/dfagen/examples/tpl/template_table.h
new file mode 100644
index 00000000..817197fa
--- /dev/null
+++ b/tools/dfagen/examples/tpl/template_table.h
@@ -0,0 +1,12 @@
+/*
+ * THIS IS AN AUTOMATICALLY GENERATED FILE, DO NOT EDIT!
+ *
+ * %(name)s
+ *
+%(*comments)s */
+
+/* %(name)s transition table. */
+static const %(prefix)s_transition_t
+%(prefix)s_transition_table[%(PREFIX)s_STATE_NB][%(PREFIX)s_EVENT_NB] = {
+%(transition_table)s};
+