Extract out checking for duplicate/conflicting proto files.

This logic is used by both protobuf_gen and wire_gen. Put this logic
into a module function in protobuf_gen so that it can be re-used.