# Path: lib_table.py
# class LibTable:
# 
#     def __init__(self, filename):
# 
#         RE_NAME = r'\(name "?([^\)"]*)"?\)'
#         RE_TYPE = r'\(type "?([^\)"]*)"?\)'
#         RE_URI  = r'\(uri "?([^\)"]*)"?\)'
#         RE_OPT  = r'\(options "?([^\)"]*)"?\)'
#         RE_DESC = r'\(descr "?([^\)"]*)"?'
# 
#         self.entries = []
#         self.errors = []
# 
#         with open(filename, 'r') as lib_table_file:
# 
#             for line in lib_table_file:
# 
#                 # Skip lines that do not define a library
#                 if not '(lib ' in line:
#                     continue
# 
#                 re_name = re.search(RE_NAME, line)
#                 re_type = re.search(RE_TYPE, line)
#                 re_uri  = re.search(RE_URI,  line)
#                 re_opt  = re.search(RE_OPT,  line)
#                 re_desc = re.search(RE_DESC, line)
# 
#                 if re_name and re_type and re_uri and re_opt and re_desc:
#                     entry = {}
#                     entry['name'] = re_name.groups()[0]
#                     entry['type'] = re_type.groups()[0]
#                     entry['uri']  = re_uri.groups()[0]
#                     entry['opt']  = re_opt.groups()[0]
#                     entry['desc'] = re_desc.groups()[0]
# 
#                     self.entries.append(entry)
# 
#                 else:
#                     self.errors.append(line)


import argparse
import os
import sys
from lib_table import LibTable

        if lib_table_names.count(name) > 1:
            errors += 1
            print("- Library '{l}' is duplicated in table".format(l=name))

    # Check for libraries that are not in the lib_table but should be
    for name in lib_names:
        if not name in lib_table_names:
            errors += 1
            print("- Library '{l}' missing from library table".format(l=name))

    # Incorrect lines in the library table
    for error in lib_table.errors:
        errors += 1
        print("- Incorrect line found in library table:")
        print("  - '{line}'".format(line=error))

    return errors


lib_names = []

for lib in args.libs:
    lib_name = '.'.join(os.path.basename(lib).split('.')[:-1])
    lib_names.append(lib_name)

print("Checking library table - '{table}'".format(table=os.path.basename(args.table)))

print("Found {n} libraries".format(n=len(lib_names)))


# Path: lib_table.py
# class LibTable:
# 
#     def __init__(self, filename):
# 
#         RE_NAME = r'\(name "?([^\)"]*)"?\)'
#         RE_TYPE = r'\(type "?([^\)"]*)"?\)'
#         RE_URI  = r'\(uri "?([^\)"]*)"?\)'
#         RE_OPT  = r'\(options "?([^\)"]*)"?\)'
#         RE_DESC = r'\(descr "?([^\)"]*)"?'
# 
#         self.entries = []
#         self.errors = []
# 
#         with open(filename, 'r') as lib_table_file:
# 
#             for line in lib_table_file:
# 
#                 # Skip lines that do not define a library
#                 if not '(lib ' in line:
#                     continue
# 
#                 re_name = re.search(RE_NAME, line)
#                 re_type = re.search(RE_TYPE, line)
#                 re_uri  = re.search(RE_URI,  line)
#                 re_opt  = re.search(RE_OPT,  line)
#                 re_desc = re.search(RE_DESC, line)
# 
#                 if re_name and re_type and re_uri and re_opt and re_desc:
#                     entry = {}
#                     entry['name'] = re_name.groups()[0]
#                     entry['type'] = re_type.groups()[0]
#                     entry['uri']  = re_uri.groups()[0]
#                     entry['opt']  = re_opt.groups()[0]
#                     entry['desc'] = re_desc.groups()[0]
# 
#                     self.entries.append(entry)
# 
#                 else:
#                     self.errors.append(line)


# Path: check_lib_table.py
import argparse
import os
import sys
from lib_table import LibTable


        if lib_table_names.count(name) > 1:
            errors += 1
            print("- Library '{l}' is duplicated in table".format(l=name))

    # Check for libraries that are not in the lib_table but should be
    for name in lib_names:
        if not name in lib_table_names:
            errors += 1
            print("- Library '{l}' missing from library table".format(l=name))

    # Incorrect lines in the library table
    for error in lib_table.errors:
        errors += 1
        print("- Incorrect line found in library table:")
        print("  - '{line}'".format(line=error))

    return errors


lib_names = []

for lib in args.libs:
    lib_name = '.'.join(os.path.basename(lib).split('.')[:-1])
    lib_names.append(lib_name)

print("Checking library table - '{table}'".format(table=os.path.basename(args.table)))

print("Found {n} libraries".format(n=len(lib_names)))


table = LibTable(args.table)