#!/usr/bin/env python

import string

f = file(raw_input("File to test for well formedness:"))
lineNum = 0
tagHash={}

for l in f.readlines():
	lineNum += 1
	if len(l)>0 and string.find(l, '<') > -1:
		tags = string.split(l,'<')
		for tag in tags[1:]:
			closing=0
			if string.find(tag, '/>') > 0:
				print "Empty tag in line %i: %s" %(lineNum, tag)
			elif len(tag) > 0:
				if tag[0] == '/':
					# closing tag
					closing=1
					tag = tag[1:]
				tagEndIdx = string.find(tag,'>')
				altIdx = string.find(tag,' ')
				if altIdx > 0 and altIdx < tagEndIdx:
					tagEndIdx = altIdx
				tagName = string.strip( tag[:tagEndIdx] )
				if not tagHash.has_key(tagName):
					tagHash[tagName] = 0
				if closing:
					tagHash[tagName] -= 1
					# print "%ith line: closing %s" %(lineNum, tagName)
					pass
				else:
					tagHash[tagName] += 1
					if tagHash[tagName] > 1:
						print "%ith line: opening %s without closing" %(lineNum, tagName)
						die
						pass
print "%s lines in total." %lineNum

