]> git.ozlabs.org Git - bitfield/blobdiff - bitfield
Add support for aliased definitions.
[bitfield] / bitfield
index 8aab6f8b617bd868264f50f12a392f4bf7c43285..71e495813fb2bc788f1460e08959e00fdf761e49 100644 (file)
--- a/bitfield
+++ b/bitfield
@@ -15,8 +15,9 @@ from getopt import getopt, GetoptError
 
 # List of paths to look for configuration files. If a directory is specified,
 # it will be (recursively) scanned for .conf files.
 
 # List of paths to look for configuration files. If a directory is specified,
 # it will be (recursively) scanned for .conf files.
-configs = [os.path.join(os.getenv("HOME"), ".bitfields.conf"),
-               os.path.join(os.getenv("HOME"), ".bitfields.d")]
+configs = ["/etc/bitfield.d", "/etc/bitfield",
+               os.path.join(os.getenv("HOME"), ".bitfield.d"),
+               os.path.join(os.getenv("HOME"), ".bitfield.conf")]
 
 class bitfield:
        def __init__(self, bits, name):
 
 class bitfield:
        def __init__(self, bits, name):
@@ -129,6 +130,7 @@ def parse_config(bnf, regs, file):
                # default to 64 bit registers
                width = 64
                name = None
                # default to 64 bit registers
                width = 64
                name = None
+               alias_id = None
                fields = []
 
                for t in ts:
                fields = []
 
                for t in ts:
@@ -153,6 +155,22 @@ def parse_config(bnf, regs, file):
                                                "Invalid value in %s" % id)
 
                                fields[-1].add_value(v[0], v[1])
                                                "Invalid value in %s" % id)
 
                                fields[-1].add_value(v[0], v[1])
+                       elif t[0] == 'alias':
+                               alias_id = t[1].strip()
+
+               if alias_id is not None:
+                       if name is not None or fields != []:
+                               raise ConfigurationError(file, ("Definiton " \
+                                       + "for %s is an alias, but has other " \
+                                       + "attributes") % id)
+
+                       if not regs.has_key(alias_id):
+                               raise ConfigurationError(file, "Aliasing "
+                                       "non-existent register %s (from %s)" \
+                                       % (alias_id, id))
+
+                       regs[id] = regs[alias_id]
+                       continue
 
                if name is None or name == '':
                        raise ConfigurationError(file,
 
                if name is None or name == '':
                        raise ConfigurationError(file,