3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-06 09:34:08 +00:00

fixing eol

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2012-10-26 21:50:08 -07:00
parent 00935cffd2
commit 276befb78e
2 changed files with 45 additions and 1 deletions

View file

@ -9,6 +9,7 @@
from mk_util import *
parse_options()
check_eol()
add_lib('util', [])
add_lib('polynomial', ['util'], 'math/polynomial')

View file

@ -13,6 +13,7 @@ import getopt
import sys
import shutil
from mk_exception import *
from fnmatch import fnmatch
BUILD_DIR='build'
REV_BUILD_DIR='..'
@ -26,6 +27,48 @@ ONLY_MAKEFILES = False
PYTHON_DIR=None
VS_PROJ = False
def is_cr_lf(fname):
# Check whether text files use cr/lf
f = open(fname, 'r')
line = f.readline()
sz = len(line)
return sz >= 2 and line[sz-2] == '\r' and line[sz-1] == '\n'
# dos2unix in python
# cr/lf --> lf
def dos2unix(fname):
if is_cr_lf(fname):
fin = open(fname, 'r')
fname_new = '%s.new' % fname
fout = open(fname_new, 'w')
for line in fin:
line = line.rstrip('\r\n')
fout.write(line)
fout.write('\n')
fin.close()
fout.close()
shutil.move(fname_new, fname)
if is_verbose():
print "dos2unix '%s'" % fname
def dos2unix_tree_core(pattern, dir, files):
for filename in files:
if fnmatch(filename, pattern):
fname = os.path.join(dir, filename)
if not os.path.isdir(fname):
dos2unix(fname)
def dos2unix_tree():
os.path.walk('src', dos2unix_tree_core, '*')
def check_eol():
if not IS_WINDOW:
# Linux/OSX/BSD check if the end-of-line is cr/lf
if is_cr_lf('LICENSE.txt'):
if is_verbose():
print "Fixing end of line..."
dos2unix_tree()
if os.name == 'nt':
IS_WINDOW=True
# Visual Studio already displays the files being compiled
@ -81,7 +124,7 @@ def parse_options():
VS_PROJ = True
else:
raise MKException("Invalid command line option '%s'" % opt)
# Return a list containing a file names included using '#include' in
# the given C/C++ file named fname.
def extract_c_includes(fname):