source: OGRE/trunk/ogrenew/Other/rem_endspc.py @ 690

Revision 690, 1.8 KB checked in by mattausch, 19 years ago (diff)

added ogre 1.07 main

Line 
1#! /usr/bin/env python
2
3import sys
4import os
5import getopt
6import string
7import re
8
9def fnParse( arg, dirname, files ):
10    for file in files:
11        for ext in arg:
12            if file.rfind( ext, len(file)-len(ext), len(file) ) != -1 and not os.path.isdir( dirname + "/" + file ):
13                print "Parsing file " + dirname + "/" + file + "..."
14                fo = open( dirname + "/" + file, "r" )
15                lines = fo.readlines()
16                fo.close()
17                fo = open( dirname + "/" + file, "r" )
18                newlines = fo.readlines()
19                changed = 0
20                for i in range(0, len(newlines) - 1):
21                    newlines[i] = re.sub( "[ \t]+$", "", newlines[i] )
22                    changed = 1
23                if changed == 1:
24                    backup = open( dirname + "/" + file + "~", "w" )
25                    backup.writelines( lines )
26                    backup.close()
27
28                    fo.close()
29                    fo = open( dirname + "/" + file, "w" )
30                    fo.writelines( newlines )
31
32                    print "File " + dirname + "/" + file + " was changed."
33                fo.close()
34
35def fnHelp():
36    helpstr = """
37This program deletes all the 'dangling' spaces at the end
38of all the lines in all the files with the passed extensions
39within the directory tree from whose root it was called
40(i.e. recurses into sub-directories)
41
42Syntax:
43    rem_endspc [ext1] [ext2] [...]
44
45Extensions are given in the form:
46    .cpp .h .txt (no asterisk at the beginning)
47
48Copyright (c) 2002 by Adrian Cearnau (cearny@cearny.ro)
49Any use, commercial or not, is allowed
50"""
51    print helpstr
52
53if len(sys.argv) < 2:
54    fnHelp()
55else:
56    exts = sys.argv[1].split()
57    currdir = os.getcwd()
58    os.path.walk( currdir, fnParse, exts )
59    #print "\nTotally", num_files, "files were patched\n"
60    print "done"
Note: See TracBrowser for help on using the repository browser.