#!/usr/bin/python 
# -*- coding: utf-8 -*-

import math
import os
import sys
import string
def stop():
   raise 'STOP'

def argus(list, infile, outfile):
   lin=False
   lout=False
   for i in list:
   
      if (i.lower()=='-in') and (not lin): 
	   lin=True
	   lout=False
      if (i.lower()=='-in') and lin:
	   continue
      if (i.lower()=='-out') and (not lout): 
	   lout=True
	   lin=False
      if (i.lower()=='-out') and lout: 
	   continue

      if lin:
	   infile.append(i)
      if lout:
	   outfile.append(i)	   
 

outfile=[]
infile=[]
list=sys.argv[1:]
lines=[]		
lines_out=[]		

argus(list,infile,outfile)




if (len(infile)==0) or (len(outfile)==0):
	print "USAGE:"
	print "changeSTLsnappy -in <filenames> -out <filenames>"
	print " "
	print "Changes , into . and puts all in-files together into out-file(s)"
	print "Names STL solids according the filenames"
	print " "
	print "(c) Christoph Hossfeld FECT 2010"
	stop()
	
for dat in infile:
	print "Reading: ",dat
	solidname=dat[:dat.find('.')]
	
	fd = open(dat, "r")
   	lines=[]
        no=0
	for line in fd:
      		no=no+1
		line=line.rstrip()
		line_temp=line.replace(",",".")
		line=line_temp
      		if line=="":
         		continue
      		
		lines.append(line)
	
	fd.close()
        print "Total of lines:", no
	print "Working on lines"
	for ll in lines:

		wort=ll.split()

		if wort[0].lower()=='solid':
			ll='solid '+solidname
		lines_out.append(ll)	







for dat in outfile:
	print "Writing: ",dat
	fd = open(dat, "w")
	for oo in lines_out:
		print >> fd, oo
        fd.close()

