#!/usr/bin/env python
##
## Analyze a *.vcproj file, and assess whether there are files that are missing
##

import sys
import glob
from xml.dom import minidom, Node

#import re
#import math
#import os
#import types
#from sets import Set
#from exact_globals import *


def analyze_vcproj(filename):
  ans = []
  #
  # Parse XML
  #
  try:
    doc = minidom.parse(filename)
  except:
    print "ERROR: problem parsing XML file " + filename
    return ans
  #
  # Process XML Tree
  #
  for child in doc.documentElement.childNodes:
    if child.nodeType == Node.ELEMENT_NODE and child.nodeName == "Files":
       for gchild in child.childNodes:
         if gchild.nodeType == Node.ELEMENT_NODE and gchild.nodeName == "Filter":
            for ggchild in gchild.childNodes:
              if ggchild.nodeType == Node.ELEMENT_NODE and ggchild.nodeName == "File":
                 for (name,value) in ggchild.attributes.items():
                   if name=="RelativePath":
		      ans.append(str(value))
  return ans


##
## MAIN
##
if (len(sys.argv) == 1):
   print "  vcproj_summary <vcproj> <src-dirs>"
   sys.exit(1)
#
# Process vcproj file
#
vcproj=sys.argv[1]
vcproj_files = analyze_vcproj(vcproj)
if len(vcproj_files) == 0:
   sys.exit(1)
for file in vcproj_files:
  print file
#
# Process user-specified files, and see if they are in the vcproj file
#
files=glob.glob(sys.argv[2])
for file in files:
  print file
