]> git.lyx.org Git - features.git/commitdiff
fix bug 4639
authorJosé Matox <jamatos@lyx.org>
Tue, 18 Mar 2008 19:41:50 +0000 (19:41 +0000)
committerJosé Matox <jamatos@lyx.org>
Tue, 18 Mar 2008 19:41:50 +0000 (19:41 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23813 a592a061-630c-0410-9148-cb99ea01b6c8

lib/lyx2lyx/LyX.py
lib/lyx2lyx/parser_tools.py

index 678647b4ac081ce875d8f9b4adeca9c8933fee8a..f0aa236dbdf3399031eebd053569cee201bb7511 100644 (file)
@@ -144,7 +144,7 @@ def get_encoding(language, inputencoding, format, cjk_encoding):
 #
 class LyX_base:
     """This class carries all the information of the LyX file."""
-    
+
     def __init__(self, end_format = 0, input = "", output = "", error = "",
                  debug = default_debug__, try_hard = 0, cjk_encoding = '',
                  language = "english", encoding = "auto"):
@@ -222,10 +222,10 @@ class LyX_base:
                     line = trim_eol(line)
                     if check_token(line, '\\end_preamble'):
                         break
-                    
+
                     if line.split()[:0] in ("\\layout",
                                             "\\begin_layout", "\\begin_body"):
-                        
+
                         self.warning("Malformed LyX file:"
                                      "Missing '\\end_preamble'."
                                      "\nAdding it now and hoping"
@@ -247,6 +247,12 @@ class LyX_base:
 
             self.header.append(line)
 
+        i = find_token(self.header, '\\textclass', 0)
+        if i == -1:
+            self.warning("Malformed LyX file: Missing '\\textclass'.")
+            i = find_token(self.header, '\\lyxformat', 0) + 1
+            self.header[i:i] = ['\\textclass article']
+
         self.textclass = get_value(self.header, "\\textclass", 0)
         self.backend = get_backend(self.textclass)
         self.format  = self.read_format()
@@ -284,10 +290,7 @@ class LyX_base:
         if self.preamble:
             i = find_token(self.header, '\\textclass', 0) + 1
             preamble = ['\\begin_preamble'] + self.preamble + ['\\end_preamble']
-            if i == 0:
-                self.error("Malformed LyX file: Missing '\\textclass'.")
-            else:
-                header = self.header[:i] + preamble + self.header[i:]
+            header = self.header[:i] + preamble + self.header[i:]
         else:
             header = self.header
 
@@ -309,7 +312,7 @@ class LyX_base:
             try:
                 gzip.open(input).readline()
                 self.input = gzip.open(input)
-                self.output = gzip.GzipFile(mode="wb", fileobj=self.output) 
+                self.output = gzip.GzipFile(mode="wb", fileobj=self.output)
             except:
                 self.input = open(input)
         else:
@@ -601,7 +604,7 @@ class LyX_base:
             # skip paragraph parameters
             while not self.body[k].strip() or self.body[k].split()[0] \
                       in allowed_parameters:
-                k += 1 
+                k += 1
 
             while k < j:
                 if check_token(self.body[k], '\\begin_inset'):
index 78459d21d9ce4afc59b7f5bee5ac35d700fc1a73..a2fea7af09b0b7429fc9c2331e88e6b22865782c 100644 (file)
@@ -84,7 +84,7 @@ def find_tokens(lines, tokens, start, end = 0, exact = False):
                 if len(x) < len(y):
                     continue
                 if x[:len(y)] == y:
-                    return i            
+                    return i
             else:
                 if lines[i][:len(token)] == token:
                     return i
@@ -149,7 +149,7 @@ def get_value(lines, token, start, end = 0, default = ""):
 
     i = find_token_exact(lines, token, start, end)
     if i == -1:
-        return ""
+        return default
     if len(lines[i].split()) > 1:
         return lines[i].split()[1]
     else: