From 7cb8c5f7096be04cd65ec41a5b8f98d0ae3e890a Mon Sep 17 00:00:00 2001 From: NĂ©lio Laranjeiro Date: Sun, 23 Nov 2008 19:35:46 +0100 Subject: tools/trace: First version of the trace creator parser source file. --- tools/trace/tcreator/__init__.py | 0 tools/trace/tcreator/tcreator.py | 27 +++++++++++++++++++++++++++ tools/trace/tcreator/template.h | 33 +++++++++++++++++++++++++++++++++ tools/trace/tcreator/writer.py | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 tools/trace/tcreator/__init__.py create mode 100644 tools/trace/tcreator/tcreator.py create mode 100644 tools/trace/tcreator/template.h create mode 100644 tools/trace/tcreator/writer.py (limited to 'tools/trace/tcreator') diff --git a/tools/trace/tcreator/__init__.py b/tools/trace/tcreator/__init__.py new file mode 100644 index 00000000..e69de29b 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 -- cgit v1.2.3