From 0f53423b1973cf31a44fafe6b2a28e37061527f7 Mon Sep 17 00:00:00 2001
From: eb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Date: Thu, 3 Aug 2006 23:34:56 +0000
Subject: merged interim/pmt changes r2243:2248 into the trunk

git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3127 221aa14e-8319-0410-a670-987f0aec2ac5
---
 pmt/src/lib/generate_unv.py | 138 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 138 insertions(+)
 create mode 100755 pmt/src/lib/generate_unv.py

(limited to 'pmt/src/lib/generate_unv.py')

diff --git a/pmt/src/lib/generate_unv.py b/pmt/src/lib/generate_unv.py
new file mode 100755
index 0000000000..46a168a1de
--- /dev/null
+++ b/pmt/src/lib/generate_unv.py
@@ -0,0 +1,138 @@
+#!/usr/bin/env python
+#
+# Copyright 2006 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio 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, or (at your option)
+# any later version.
+# 
+# GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+# 
+
+"""
+Generate code for uniform numeric vectors
+"""
+
+import re, os, os.path
+
+
+unv_types = (
+    ('u8', 'uint8_t'),
+    ('s8', 'int8_t'),
+    ('u16', 'uint16_t'),
+    ('s16', 'int16_t'),
+    ('u32', 'uint32_t'),
+    ('s32', 'int32_t'),
+    ('u64', 'uint64_t'),
+    ('s64', 'int64_t'),
+    ('f32', 'float'),
+    ('f64', 'double'),
+    ('c32', 'std::complex<float>'),
+    ('c64', 'std::complex<double>')
+    )
+
+header = """\
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio 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, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+"""
+
+guard_head = """
+#ifndef INCLUDED_PMT_UNV_INT_H
+#define INCLUDED_PMT_UNV_INT_H
+"""
+
+guard_tail = """
+#endif
+"""
+
+includes = """
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <vector>
+#include <pmt.h>
+#include "pmt_int.h"
+
+"""
+
+
+# set srcdir to the directory that contains Makefile.am
+try:
+    srcdir = os.environ['srcdir']
+except KeyError, e:
+    srcdir = "."
+srcdir = srcdir + '/'
+
+
+def open_src (name, mode):
+    global srcdir
+    return open(os.path.join (srcdir, name), mode)
+
+
+def do_substitution (d, input, out_file):
+    def repl (match_obj):
+        key = match_obj.group (1)
+        # print key
+        return d[key]
+    
+    out = re.sub (r"@([a-zA-Z0-9_]+)@", repl, input)
+    out_file.write (out)
+
+
+def generate_h():
+    template = open_src('unv_template.h.t', 'r').read()
+    output = open('pmt_unv_int.h', 'w')
+    output.write(header)
+    output.write(guard_head)
+    for tag, typ in unv_types:
+        d = { 'TAG' : tag, 'TYPE' : typ }
+        do_substitution(d, template, output)
+    output.write(guard_tail)
+
+
+def generate_cc():
+    template = open_src('unv_template.cc.t', 'r').read()
+    output = open('pmt_unv.cc', 'w')
+    output.write(header)
+    output.write(includes)
+    for tag, typ in unv_types:
+        d = { 'TAG' : tag, 'TYPE' : typ }
+        do_substitution(d, template, output)
+
+
+def main():
+    generate_h()
+    generate_cc()
+
+if __name__ == '__main__':
+    main()
-- 
cgit v1.2.3