def c_chop(lines):
    """Chops the text, counting on filenames being given in the form
          !<filename>
    as the first line of each file.
    Returns a list of tuples of the form (basename, contents)
    """
    results = []
    current_filename = None
    current_contents = []
    for j in lines:
        if j.startswith('!'):
            if current_filename:
                results.append((current_filename, '\n'.join(current_contents)))
                current_contents = []
            current_filename = j[1:]
        else:
            current_contents.append(j)
    if current_filename:
        results.append((current_filename, '\n'.join(current_contents)))
    return results