#! /usr/local/bin/python
# grabs version strings out of source files,
# creates the source file 'version.c'

import sys

#this is a hack, sortof.
sys.path.append('maint')

import os
from getver import *
import string
import regsub

strings = []

def usage ():
	print 'version.py file ...'

if len(sys.argv) < 2:
	usage()
	sys.exit()
	
try:
	fout = open ('version.c', 'w')
except IOError:
	print "Couldn't open version.c for output"
	sys.exit()
	
fout.write('static char * version_string[] = {\n')
print 'grabbing version strings...'

# this is a little tricky, to be safe with the commas.

flag = 0
for x in sys.argv[1:]:
	print x + '...'
	vstr = find_version(x)
	vstr = regsub.gsub (' ','   \t',vstr)
	if vstr != '':
		if flag == 1: fout.write(',\n')
		fout.write('"'+vstr+'"')
		flag = 1

fout.write('};\n')
