#!/lusr/bin/ruby

if (ARGV.length < 1)
  puts "Usage is \"print-global-lisp-variables.rb dir/foo.lisp [dir2/foo2.lisp]\""
  exit
end

def FindUniqueVarsForFile(filename)

  puts "Processing " + filename
  all = ""
  
  File.open(filename, "r") do |infile|
    while (line = infile.gets())
      all = all + " " + line
    end
  end
  
  words = all.split(" ")
  
  variables = []
  
  words.each do |word|
    if (word[0] == 42) # 42 is *
      variables.push(word.chomp(",").chomp(".").chomp(")").chomp(")") \
                       .chomp(")").chomp(")").chomp(")").chomp(",") \
                       .chomp("."))
    end
  end
  
  variables = variables.uniq.sort

  return variables
end

file_one_vars = FindUniqueVarsForFile(ARGV[0])
puts "\nUnique words for file 1: "
puts file_one_vars

file_two_vars = FindUniqueVarsForFile(ARGV[1])
puts "\nUnique words for file 2: "
puts file_two_vars

puts "\nIntersection of the two files:"
puts file_one_vars & file_two_vars

