]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx2lyx
Small fix
[lyx.git] / lib / lyx2lyx / lyx2lyx
index 51e830babd553325afd364c4de986012c3de1826..f87b7ed77d350d6155edacbc4ba5a18eb74a6f53 100755 (executable)
@@ -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, check_token
 
 version = "0.0.2"
 
@@ -37,9 +37,8 @@ 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"}
+lst_ft = ["210", "215", "216", "217", "218", "220", "221"]
+
 def usage():
     print """Usage: lyx2lyx [options] file1
 Convert old lyx file <file1> to newer format.
@@ -114,6 +113,8 @@ def lyxformat(fmt):
 def read_file(file, header, body):
     """Reads a file into the header and body parts"""
     fmt = None
+    preamble = 0
+
     while 1:
         line = file.readline()
         if not line:
@@ -121,7 +122,12 @@ def read_file(file, header, body):
             sys.exit(3)
 
         line = line[:-1]
-        if not line:
+        if check_token(line, '\\begin_preamble'):
+            preamble = 1
+        if check_token(line, '\\end_preamble'):
+            preamble = 0
+
+        if not line and not preamble:
             break
 
         header.append(line)
@@ -164,9 +170,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__":