diff --git a/lib/ChangeLog b/lib/ChangeLog index e99ae2f901..f3193b3165 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,9 @@ +2002-08-03 Dekel Tsur + + * lyx2lyx/lyxconvert_218.py (remove_oldert): Few fixes. + + * lyx2lyx/lyx2lyx: Change the comment at the top of the lyx file + 2002-08-02 Dekel Tsur * lyx2lyx/lyxconvert_218.py: Convert ERT and figinsets. diff --git a/lib/lyx2lyx/lyx2lyx b/lib/lyx2lyx/lyx2lyx index 51e830babd..7960ffd27b 100755 --- a/lib/lyx2lyx/lyx2lyx +++ b/lib/lyx2lyx/lyx2lyx @@ -17,7 +17,7 @@ import getopt, sys, string, re from error import error, warning -from parser_tools import set_format +from parser_tools import set_comment, set_format version = "0.0.2" @@ -38,8 +38,7 @@ opt.quiet = 0 format = re.compile(r"(\d)[\.,]?(\d\d)") fileformat = re.compile(r"\\lyxformat\s*(\S*)") lst_ft = ["210", "215", "216", "217", "218", "220"] -format_name = {"210" : "2.10", "215":"2.15", "216": "2.16", - "217" : "2.17", "218":"218" , "220":"220"} + def usage(): print """Usage: lyx2lyx [options] file1 Convert old lyx file to newer format. @@ -164,9 +163,10 @@ def main(argv): end = lst_ft.index(opt.end) for fmt in lst_ft[start:end]: - __import__("lyxconvert_" + fmt).convert(header,body) + __import__("lyxconvert_" + fmt).convert(header,body) - set_format(header,format_name[opt.end]) + set_comment(header, opt.end) + set_format(header, opt.end) write_file(opt.output, header, body) if __name__ == "__main__": diff --git a/lib/lyx2lyx/lyxconvert_218.py b/lib/lyx2lyx/lyxconvert_218.py index 42f9161a45..7e9e26acc4 100644 --- a/lib/lyx2lyx/lyxconvert_218.py +++ b/lib/lyx2lyx/lyxconvert_218.py @@ -171,10 +171,8 @@ def remove_oldert(lines): i = find_tokens(lines, ["\\latex latex", "\\layout LaTeX"], i) if i == -1: break - j = find_tokens(lines, ["\\latex default", "\\layout", "\\end_float"], + j = find_tokens(lines, ["\\latex default", "\\layout", "\\end_float", "\\the_end"], i+1) - if j == -1: - j = len(lines)-1 if check_token(lines[j], "\\layout"): while j-1 >= 0 and check_token(lines[j-1], "\\begin_deeper"): j = j-1 @@ -257,7 +255,8 @@ def combine_ert(lines): break if count >= 2: - lines[i+1:k] = text + j = find_token(lines, "\\layout", i+1) + lines[j:k] = text i = i+1 diff --git a/lib/lyx2lyx/parser_tools.py b/lib/lyx2lyx/parser_tools.py index f75eeac204..ffe8cfcee4 100644 --- a/lib/lyx2lyx/parser_tools.py +++ b/lib/lyx2lyx/parser_tools.py @@ -77,6 +77,23 @@ def find_nonempty_line(lines, start, end = 0): return i return -1 + +def set_comment(lines, number): + x = int(number) + if x < 216: + # It is not worth the trouble to handle this case + return + elif x < 220: + version = "1.1" + else: + version = "1.2" + + lines[0] = "#LyX %s created this file. For more info see http://www.lyx.org/" % version + if lines[1][0] == '#': + del lines[1] + def set_format(lines, number): + if int(number) <= 217: + number = float(number)/100 i = find_token(lines, "\\lyxformat", 0) lines[i] = "\\lyxformat %s" % number