def main()

in utils/extract_introduced_gcc_style.py [0:0]


def main():

    logging.basicConfig(
        format="[%(levelname)-7s] %(asctime)s %(name)s %(message)s", level="WARNING",
    )

    # briefly check input
    if len(sys.argv) != 3:
        usage(sys.argv[0])
        sys.exit(0)

    # read files, fail early in case they cannot be found or opened
    oldf = open(sys.argv[1])
    newf = open(sys.argv[2])

    # get the actual msg output, assume style to be correct
    new_msgs = newf.readlines()
    log.info("parsed %d new info", len(new_msgs))
    old_msgs = oldf.readlines()
    log.info("parsed %d old info", len(old_msgs))

    # drop line in content
    new_lineless = drop_second_col(new_msgs)
    old_lineless = drop_second_col(old_msgs)
    log.info("new lineless: %d", len(new_lineless))
    log.info("old lineless: %d", len(old_lineless))

    # calculate actual introduced msgs (could be done quicker using e.g. sets)
    old_lineless_to_match = old_lineless[:]
    introduced_lineless = []
    for x in new_lineless:
        if x in old_lineless_to_match:
            old_lineless_to_match.remove(x)
        else:
            introduced_lineless.append(x)
    log.info(
        "introduced lineless: %d, left to match %d from %d",
        len(introduced_lineless),
        len(old_lineless_to_match),
        len(old_lineless),
    )

    # get all candidates from new msgs that match above info, collect for all available line info
    introduced_candidates = [
        x for x in new_msgs if (x.split(":")[0:1] + x.split(":")[2:]) in introduced_lineless
    ]
    log.debug("introduced full candidates: %r", introduced_candidates)

    # drop all candidates that appear in the old msgs with the same line number
    introduced = []
    old_msgs_to_match = old_msgs[:]
    for x in introduced_candidates:
        log.debug("Analyze %s", x)
        if x in old_msgs_to_match:
            old_msgs_to_match.remove(x)
        else:
            introduced.append(x.rstrip())
    log.debug("Left %d from %d messages to match", len(old_msgs_to_match), len(old_msgs))

    # present introduced msgs, each at most once
    for msg in sorted(set(introduced)):
        print (msg)

    # indicate error in case we spotted new defects
    return 0 if len(introduced) == 0 else 1