def records_from_db(fn):
    """Naively parse db/template files looking for record names

    Returns
    -------
    records : list
        [(record type, record name), ...]
    """
    ret = []
    for line in open(fn, 'rt').readlines():
        line = line.strip()
        if line.startswith('#'):
            continue
        if not (line.startswith('record') or line.startswith('grecord')):
            continue
        if '(' not in line:
            continue
        line = line[line.index('(') + 1:]
        if ',' not in line:
            continue
        rtype, record = line.split(',', 1)
        rtype = rtype.strip()
        record = record.strip()
        if record.startswith('"'):
            record = record[1:]
            record = record[:record.index('"')]
        else:
            in_paren = 0
            for i, c in enumerate(record):
                if c == '(':
                    in_paren += 1
                elif c == ')':
                    in_paren -= 1
                    if in_paren < 0:
                        record = record[:i]
                        break
        ret.append((rtype, record))
    return ret
