1#! /usr/bin/env python
2
3"Replace LF with CRLF in argument files.  Print names of changed files."
4
5import sys, re, os
6
7def main():
8    for filename in sys.argv[1:]:
9        if os.path.isdir(filename):
10            print filename, "Directory!"
11            continue
12        data = open(filename, "rb").read()
13        if '\0' in data:
14            print filename, "Binary!"
15            continue
16        newdata = re.sub("\r?\n", "\r\n", data)
17        if newdata != data:
18            print filename
19            f = open(filename, "wb")
20            f.write(newdata)
21            f.close()
22
23if __name__ == '__main__':
24    main()
25