mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-12 16:50:39 +00:00
Backport Guenter's layout2layout fixes.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@32065 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b056523706
commit
639d105ad8
@ -52,17 +52,6 @@ def error(message):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def trim_eol(line):
|
|
||||||
" Remove end of line char(s)."
|
|
||||||
if line[-2:-1] == '\r':
|
|
||||||
return line[:-2]
|
|
||||||
elif line[-1:] == '\r' or line[-1:] == '\n':
|
|
||||||
return line[:-1]
|
|
||||||
else:
|
|
||||||
# file with no EOL in last line
|
|
||||||
return line
|
|
||||||
|
|
||||||
|
|
||||||
def trim_bom(line):
|
def trim_bom(line):
|
||||||
" Remove byte order mark."
|
" Remove byte order mark."
|
||||||
if line[0:3] == "\357\273\277":
|
if line[0:3] == "\357\273\277":
|
||||||
@ -71,25 +60,16 @@ def trim_bom(line):
|
|||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
def read(input):
|
def read(source):
|
||||||
" Read input file and strip lineendings."
|
" Read input file and strip lineendings."
|
||||||
lines = list()
|
lines = source.read().splitlines()
|
||||||
first_line = 1
|
lines[0] = trim_bom(lines[0])
|
||||||
while 1:
|
|
||||||
line = input.readline()
|
|
||||||
if not line:
|
|
||||||
break
|
|
||||||
if (first_line):
|
|
||||||
line = trim_bom(line)
|
|
||||||
first_line = 0
|
|
||||||
lines.append(trim_eol(line))
|
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
|
||||||
def write(output, lines):
|
def write(output, lines):
|
||||||
" Write output file with native lineendings."
|
" Write output file with native lineendings."
|
||||||
for line in lines:
|
output.write(os.linesep.join(lines) + os.linesep)
|
||||||
output.write(line + os.linesep)
|
|
||||||
|
|
||||||
|
|
||||||
# Concatenates old and new in an intelligent way:
|
# Concatenates old and new in an intelligent way:
|
||||||
@ -503,16 +483,16 @@ def main(argv):
|
|||||||
|
|
||||||
# Open files
|
# Open files
|
||||||
if len(argv) == 1:
|
if len(argv) == 1:
|
||||||
input = sys.stdin
|
source = sys.stdin
|
||||||
output = sys.stdout
|
output = sys.stdout
|
||||||
elif len(argv) == 3:
|
elif len(argv) == 3:
|
||||||
input = open(argv[1], 'rb')
|
source = open(argv[1], 'rb')
|
||||||
output = open(argv[2], 'wb')
|
output = open(argv[2], 'wb')
|
||||||
else:
|
else:
|
||||||
error(usage(argv[0]))
|
error(usage(argv[0]))
|
||||||
|
|
||||||
# Do the real work
|
# Do the real work
|
||||||
lines = read(input)
|
lines = read(source)
|
||||||
format = 1
|
format = 1
|
||||||
while (format < currentFormat):
|
while (format < currentFormat):
|
||||||
format = convert(lines)
|
format = convert(lines)
|
||||||
@ -520,7 +500,7 @@ def main(argv):
|
|||||||
|
|
||||||
# Close files
|
# Close files
|
||||||
if len(argv) == 3:
|
if len(argv) == 3:
|
||||||
input.close()
|
source.close()
|
||||||
output.close()
|
output.close()
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
Reference in New Issue
Block a user