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

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

added ogre 1.07 main

RevLine 
[690]1import sys
2import os
3import getopt
4import string
5
6def fnParse( arg, dirname, files ):
7    for file in files:
8        for ext in arg:
9            if file.rfind( ext, len(file)-len(ext), len(file) ) != -1 and not os.path.isdir( dirname + "/" + file ):
10                fo = open( dirname + "/" + file, "rb" )
11                lines = fo.read()
12                if not '\0' in lines and lines[len(lines)-1] != '\n':
13                    newlines = lines + '\n'
14                    fo.close()
15                    fo = open( dirname + "/" + file, "wb" )
16                    fo.write(newlines)
17                    print "File " + dirname + "/" + file + " was changed."
18                fo.close()
19
20def fnHelp():
21    helpstr = """
22This nifty little program adds a CR/LF at the end of every
23file with the given extension within the directory tree
24from where it was called (i.e. recurses in sub-directories).
25
26Syntax:
27    add_crlf [ext1] [ext2] [...]
28
29Extensions are given in the form:
30    .cpp .h .txt (no asterisk at the beginning)
31
32Copyright (c) 2002 by Adrian Cearnau (cearny@cearny.ro)
33Any use, commercial or not, is allowed
34"""
35    print helpstr
36
37if len(sys.argv) < 2:
38    fnHelp()
39else:
40    exts = sys.argv[1].split()
41    currdir = os.getcwd()
42    os.path.walk( currdir, fnParse, exts )
43    #print "\nTotally", num_files, "files were patched\n"
44    print "done"
Note: See TracBrowser for help on using the repository browser.