| 
									
										
										
										
											1994-05-06 14:16:55 +00:00
										 |  |  | #! /usr/local/bin/python | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-08-19 10:51:31 +00:00
										 |  |  | # Replace \r by \n -- useful after transferring files from the Mac... | 
					
						
							|  |  |  | # Run this on UNIX. | 
					
						
							|  |  |  | # Usage: crlf.py file ... | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-05-06 14:16:55 +00:00
										 |  |  | import sys | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import string | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							|  |  |  | 	args = sys.argv[1:] | 
					
						
							|  |  |  | 	if not args: | 
					
						
							| 
									
										
										
										
											1994-08-19 10:51:31 +00:00
										 |  |  | 		print 'usage:', sys.argv[0], 'file ...' | 
					
						
							|  |  |  | 		sys.exit(2) | 
					
						
							| 
									
										
										
										
											1994-05-06 14:16:55 +00:00
										 |  |  | 	for file in args: | 
					
						
							|  |  |  | 		print file, '...' | 
					
						
							|  |  |  | 		data = open(file, 'r').read() | 
					
						
							|  |  |  | 		lines = string.splitfields(data, '\r') | 
					
						
							|  |  |  | 		newdata = string.joinfields(lines, '\n') | 
					
						
							|  |  |  | 		if newdata != data: | 
					
						
							|  |  |  | 			print 'rewriting...' | 
					
						
							|  |  |  | 			os.rename(file, file + '~') | 
					
						
							|  |  |  | 			open(file, 'w').write(newdata) | 
					
						
							|  |  |  | 			print 'done.' | 
					
						
							|  |  |  | 		else: | 
					
						
							|  |  |  | 			print 'no change.' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | main() |