#! /usr/local/bin/python

# force a files into DOS EOL format (\r\n)
# please, no mac format files!

import sys
import os

def usage ():
	print 'todos.py file [file...]'
	sys.exit()

if len(sys.argv) < 2:
	usage()
	
files = sys.argv[1:]

for x in files:
	fin = open(x, 'r')
	outname = 'tmp.'+str(os.getpid())
	fout = open(outname, 'w')
	print x+' -> dos'
	while 1:
		line = fin.readline()
		if line == '':
			break
		# single blank unix-format line
		if len(line) == 1:
			fout.write ('\r\n')
		# line already in dos format.
		elif line[-2:] == '\r\n':
			fout.write(line)
		# probably unix-format
		else:
			fout.write(line[:-1]+'\r\n')
	
	fin.close()
	fout.close()
	os.unlink (x)
	os.rename (outname, x)
