| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 import sys | |
| 4 import fileinput | |
| 5 | |
| 6 # Defaults | |
| 7 TABSIZE = 4 | |
| 8 | |
| 9 usage = """ | |
| 10 Replaces all TAB characters with %(TABSIZE)d space characters. | |
| 11 In addition, all trailing space characters are removed. | |
| 12 usage: trim file ... | |
| 13 file ... : files are changed in place without taking any backup. | |
| 14 """ % vars() | |
| 15 | |
| 16 def main(): | |
| 17 | |
| 18 if len(sys.argv) == 1: | |
| 19 sys.stderr.write(usage) | |
| 20 sys.exit(2) | |
| 21 | |
| 22 # Iterate over the lines of all files listed in sys.argv[1:] | |
| 23 for line in fileinput.input(sys.argv[1:], inplace=True): | |
| 24 line = line.replace('\t',' '*TABSIZE); # replace TABs | |
| 25 line = line.rstrip(None) # remove trailing whitespaces | |
| 26 print line # modify the file | |
| 27 | |
| 28 if __name__ == '__main__': | |
| 29 main() | |
| OLD | NEW |