#!/usr/bin/python3

# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# the COPYING file included with this distribution or
# http://sam.zoy.org/wtfpl/COPYING for more details.

import sys
from bps.io import read_bps
from bps.validate import check_stream, CorruptFile

iterable = check_stream(read_bps(open(sys.argv[1], 'rb')))

i = 0
try:
	for i, item in enumerate(iterable):
		pass

except CorruptFile as e:
	sys.stdout.flush()
	sys.stderr.flush()
	print("Problem with opcode {0} in the patch: {1!s}".format(i, e),
			file=sys.stderr)
	sys.exit(1)
