def shorten_name(name, max_length):
    """
    Shortens a name to the given number of characters.
    """
    if len(name) <= max_length:
        return name
    q, r = divmod(max_length - 3, 2)
    return name[:q + r] + '...' + name[-q:]
