summaryrefslogtreecommitdiff
path: root/tools/trace/tcreator
diff options
context:
space:
mode:
authorNélio Laranjeiro2008-11-23 19:35:46 +0100
committerNélio Laranjeiro2008-11-23 19:35:46 +0100
commit7cb8c5f7096be04cd65ec41a5b8f98d0ae3e890a (patch)
tree55fdb7a143ec50712bc9cfd2c9baed9cc57f6e40 /tools/trace/tcreator
parentf5f92965f6e0df104686875b82d329a65efedd2a (diff)
tools/trace: First version of the trace creator parser source file.
Diffstat (limited to 'tools/trace/tcreator')
-rw-r--r--tools/trace/tcreator/__init__.py0
-rw-r--r--tools/trace/tcreator/tcreator.py27
-rw-r--r--tools/trace/tcreator/template.h33
-rw-r--r--tools/trace/tcreator/writer.py39
4 files changed, 99 insertions, 0 deletions
diff --git a/tools/trace/tcreator/__init__.py b/tools/trace/tcreator/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tools/trace/tcreator/__init__.py
diff --git a/tools/trace/tcreator/tcreator.py b/tools/trace/tcreator/tcreator.py
new file mode 100644
index 00000000..e0624259
--- /dev/null
+++ b/tools/trace/tcreator/tcreator.py
@@ -0,0 +1,27 @@
+import sys
+from writer import *
+
+try:
+ from lib.parser import *
+except:
+ print "--> You should run yapps on lib/parser.g"
+
+class TCreator:
+
+ def __init__(self, infile, outfile, enum_name = "trace_id_t"):
+ self.__infile = infile
+ self.__outfile = outfile
+ self.__enum_name = enum_name
+
+ def create (self):
+ infile = open (self.__infile, 'r')
+ data = parse ('parser', infile.read())
+ infile.close()
+
+ w = Writer (self.__outfile, self.__enum_name)
+ outstring = w.parse_list (data)
+
+ if self.__outfile != "":
+ w.write_file (outstring)
+ else:
+ w.print_file (outstring)
diff --git a/tools/trace/tcreator/template.h b/tools/trace/tcreator/template.h
new file mode 100644
index 00000000..579acfad
--- /dev/null
+++ b/tools/trace/tcreator/template.h
@@ -0,0 +1,33 @@
+#ifndef %%template%%
+#define %%template%%
+/* %%template%% */
+/* {{{
+ *
+ * Copyright (C) 2008 APBTeam
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+enum %%enum_name%%
+{
+%%data%%
+};
+
+#endif /* %%template%% */
diff --git a/tools/trace/tcreator/writer.py b/tools/trace/tcreator/writer.py
new file mode 100644
index 00000000..8bfaf0fb
--- /dev/null
+++ b/tools/trace/tcreator/writer.py
@@ -0,0 +1,39 @@
+import sys
+
+from lib.traceclass import *
+
+class Writer:
+
+ """Template writer"""
+ def __init__ (self, name, enum_name = "trace_id"):
+ self.__name = name
+ self.__enum_name = enum_name
+
+ def parse_list (self, event_list = None):
+ if event_list != None:
+ string = ""
+ for i in range (0, len (event_list)):
+ string += " TRACE_" + event_list[i].name() + ",\n"
+ string += " TRACE_NB"
+ return string.upper()
+
+ def __read_template__ (self, string):
+ f = open ('tcreator/template.h', 'r')
+ template = f.read()
+ f.close()
+ define = self.__name.replace('.', '_')
+ template = template.replace('%%template%%', define)
+ template = template.replace('%%enum_name%%', self.__enum_name)
+ template = template.replace('%%data%%', string)
+ return template
+
+
+ def write_file (self, string):
+ template = self.__read_template__(string)
+ f = open (self.__name, 'w')
+ f.write (template)
+ f.close()
+
+ def print_file (self, string):
+ template = self.__read_template__(string)
+ print template