Figuring out line numbers is painful if all you have is a character offset into the preprocessed source, or something similar. Why? You make a map from line number to starting character number and do a binary search.