]> git.lyx.org Git - lyx.git/commitdiff
whitespace, bugfixes, and convertions dependent on the document type, if need.
authorJosé Matox <jamatos@lyx.org>
Tue, 11 May 2004 16:13:33 +0000 (16:13 +0000)
committerJosé Matox <jamatos@lyx.org>
Tue, 11 May 2004 16:13:33 +0000 (16:13 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8749 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ChangeLog
lib/layouts/db_stdtitle.inc
lib/lyx2lyx/ChangeLog
lib/lyx2lyx/lyx2lyx
lib/lyx2lyx/lyx_1_4.py
lib/lyx2lyx/parser_tools.py

index d016268632d1b20504057e45b593fd778598ded7..ff28bd90e7a86a70ce6bfef8110f50e3649f7172 100644 (file)
@@ -1,3 +1,7 @@
+2004-05-11  José Matos  <jamatos@lyx.org>
+
+       * layouts/db_stdtitle.inc: obsolete FirstName and Surname.
+
 2004-05-03  José Matos  <jamatos@lyx.org>
 
        * scripts/legacy_lyxpreview2ppm.py: bug fix for temporary file
index 97067bf6455a1c98dd6f467c1c3ba570bb446765..d95264364768fcd9e63c92a26b67b7edb003191b 100644 (file)
@@ -20,7 +20,6 @@ End
 Style Author
        LatexType             Environment
        LatexName             author
-       KeepEmpty             1
 End
 
 
@@ -32,30 +31,6 @@ Style Authorgroup
 End
 
 
-Style FirstName
-       Margin                Static
-       LatexType             Paragraph
-       LatexName             firstname
-       ParIndent             MM
-       ParSkip               0.4
-       Align                 Center
-       AlignPossible         Center
-       LabelType             No_Label
-End
-
-
-Style Surname
-       Margin                Static
-       LatexType             Paragraph
-       LatexName             surname
-       ParIndent             MM
-       ParSkip               0.4
-       Align                 Center
-       AlignPossible         Center
-       LabelType             No_Label
-End
-
-
 Style Date
        LatexType             Paragraph
        LatexName             date
@@ -116,3 +91,12 @@ Style RevisionRemark
        AlignPossible         Block
        LabelType             No_Label
 End
+
+
+Style FirstName
+        ObsoletedBy   Standard
+End
+
+Style Surname
+       ObsoletedBy   Standard
+End
\ No newline at end of file
index 68fa99d36bab51e245c04232b1178cb7dd931f81..d69e9740c952e96a012d6dd6b2edab8cfe0dd2bd 100644 (file)
@@ -1,3 +1,16 @@
+2004-05-11  José Matos  <jamatos@lyx.org>
+
+
+       * parser_tools.py (get_backend): get the document backend.
+       * lyx2lyx (main): new member of the document structure,
+       the textclass and backend, that default to article and latex.
+       * lyx_1_4.py (add_end_layout): fix bug of mixed \begin_deeper
+       and \end_layout
+       (insert_tracking_changes): insert \tracking_changes 0, if not present
+       in the header.
+       (convert_names, revert_names): for docbook documents transform
+       the styles FirstName and Surname into character styles.
+
 2004-05-03  José Matos  <jamatos@lyx.org>
 
        * lyx_1_4.py (convert_graphics):
index ffe36e893c2220bf4a3804f4e54d540688e8a08d..f1489147ce906dd988691f9931ab6f1ae26e7c5f 100755 (executable)
@@ -21,7 +21,8 @@ import gzip
 import sys
 import os.path
 from parser_tools import read_file, write_file, read_version, set_version, \
-     read_format, set_format, chain, lyxformat, get_value
+     read_format, set_format, chain, lyxformat, get_value, get_backend
+
 
 # Allow the dummy object to be able to carry related data
 # like a C struct
@@ -34,6 +35,8 @@ class struct:
         self.dir = ""
         self.start = None
         self.end = None
+        self.backend = "latex"
+        self.textclass = "article"
 
     def warning(self, message, debug_level= 1):
         if debug_level <= self.debug:
@@ -44,6 +47,7 @@ class struct:
         self.warning("Quiting.")
         sys.exit(1)
 
+
 def usage():
     print """Usage: lyx2lyx [options] [file]
 Convert old lyx file <file> to newer format, files can be compressed with gzip.
@@ -104,6 +108,7 @@ def parse_options(argv, version, opt):
         except:
             opt.input = open(file)
 
+
 def main(argv):
     version = "1.4.0cvs"
 
@@ -117,6 +122,9 @@ def main(argv):
     read_file(header, body, opt)
 
     initial_version = read_version(header)
+
+    opt.textclass = get_value(header, "\\textclass", 0)
+    opt.backend = get_backend( opt.textclass)
     opt.format  = read_format(header, opt)
     opt.language = get_value(header, "\\language", 0)
     if opt.language == "":
@@ -133,5 +141,6 @@ def main(argv):
     set_format(header, opt.format)
     write_file(header, body, opt)
 
+
 if __name__ == "__main__":
     main(sys.argv)
index 50a42c468e3a1ce53310da9a4ab9e9abe60de05c..5282d0e77a6b1d35af6b39790290903bb9c085f6 100644 (file)
@@ -248,6 +248,7 @@ def add_end_layout(lines):
 
     i = i + 1
     struct_stack = ["\\layout"]
+
     while 1:
         i = find_tokens(lines, ["\\begin_inset", "\\end_inset", "\\layout",
                                 "\\begin_deeper", "\\end_deeper", "\\the_end"], i)
@@ -262,8 +263,9 @@ def add_end_layout(lines):
         if token == "\\end_inset":
             tail = struct_stack.pop()
             if tail == "\\layout":
+                lines.insert(i,"")
                 lines.insert(i,"\\end_layout")
-                i = i + 1
+                i = i + 2
                 #Check if it is the correct tag
                 struct_stack.pop()
             i = i + 1
@@ -272,20 +274,32 @@ def add_end_layout(lines):
         if token == "\\layout":
             tail = struct_stack.pop()
             if tail == token:
+                lines.insert(i,"")
                 lines.insert(i,"\\end_layout")
-                i = i + 2
+                i = i + 3
             else:
                 struct_stack.append(tail)
                 i = i + 1
             struct_stack.append(token)
             continue
 
-        if token == "\\begin_deeper" or token == "\\end_deeper":
+        if token == "\\begin_deeper":
+            lines.insert(i,"")
             lines.insert(i,"\\end_layout")
-            i = i + 2
+            i = i + 3
+            struct_stack.append(token)
+            continue
+
+        if token == "\\end_deeper":
+            lines.insert(i,"")
+            lines.insert(i,"\\end_layout")
+            i = i + 3
+            while struct_stack[-1] != "\\begin_deeper":
+                struct_stack.pop()
             continue
 
         #case \end_document
+        lines.insert(i, "")
         lines.insert(i, "\\end_layout")
         return
 
@@ -302,8 +316,13 @@ def rm_end_layout(lines):
 
 
 ##
-# Remove change tracking keywords
+# Handle change tracking keywords
 #
+def insert_tracking_changes(lines):
+    i = find_token(lines, "\\tracking_changes", 0)
+    if i == -1:
+        lines.append("\\tracking_changes 0")
+
 def rm_tracking_changes(lines):
     i = find_token(lines, "\\author", 0)
     if i != -1:
@@ -1118,6 +1137,7 @@ def revert_float(lines, opt):
         del_token(lines, 'sideways', i, j)
         i = i + 1
 
+
 def convert_graphics(lines, opt):
     """ Add extension to filenames of insetgraphics if necessary.
     """
@@ -1138,7 +1158,7 @@ def convert_graphics(lines, opt):
            # We could use a heuristic and take the current directory,
            # and we could try to find out if filename has an extension,
            # but that would be just guesses and could be wrong.
-           opt.warning("""Warning: Can not determine wether file
+           opt.warning("""Warning: Can not determine whether file
          %s
          needs an extension when reading from standard input.
          You may need to correct the file manually or run
@@ -1154,12 +1174,98 @@ def convert_graphics(lines, opt):
            lines[j] = replace(lines[j], filename, filename + ".eps")
 
 
+##
+# Convert firstname and surname from styles -> char styles
+#
+def convert_names(lines, opt):
+    """ Convert in the docbook backend from firstname and surname style
+    to charstyles.
+    """
+    if opt.backend != "docbook":
+        return
+
+    i = 0
+
+    while 1:
+        i = find_token(lines, "\\begin_layout Author", i)
+        if i == -1:
+            return
+
+        i = i + 1
+        while lines[i] == "":
+            i = i + 1
+
+        if lines[i][:11] != "\\end_layout" or lines[i+2][:13] != "\\begin_deeper":
+            i = i + 1
+            continue
+
+        k = i
+        i = find_end_of( lines, i+3, "\\begin_deeper","\\end_deeper")
+        if i == -1:
+            # something is really wrong, abort
+            opt.warning("Missing \\end_deeper,after style Author")
+            opt.warning("Aborted attempt to parse FirstName and Surname")
+            return
+        firstname, surname = "", ""
+
+        name = lines[k:i]
+
+        j = find_token(name, "\\begin_layout FirstName", 0)
+        if j != -1:
+            j = j + 1
+            while(name[j] != "\\end_layout"):
+                firstname = firstname + name[j]
+                j = j + 1
+
+        j = find_token(name, "\\begin_layout Surname", 0)
+        if j != -1:
+            j = j + 1
+            while(name[j] != "\\end_layout"):
+                surname = surname + name[j]
+                j = j + 1
+
+        # delete name
+        del lines[k+2:i+1]
+
+        lines[k-1:k-1] = ["", "",
+                          "\\begin_inset CharStyle Firstname",
+                          "status inlined",
+                          "",
+                          "\\begin_layout Standard",
+                          "",
+                          "%s" % firstname,
+                          "\end_layout",
+                          "",
+                          "\end_inset ",
+                          "",
+                          "",
+                          "\\begin_inset CharStyle Surname",
+                          "status inlined",
+                          "",
+                          "\\begin_layout Standard",
+                          "",
+                          "%s" % surname,
+                          "\\end_layout",
+                          "",
+                          "\\end_inset ",
+                          ""]
+
+
+def revert_names(lines, opt):
+    """ Revert in the docbook backend from firstname and surname char style
+    to styles.
+    """
+    if opt.backend != "docbook":
+        return
+
+
 ##
 # Convertion hub
 #
 
 def convert(header, body, opt):
     if opt.format < 223:
+        insert_tracking_changes(header)
        add_end_header(header)
        convert_spaces(body)
        convert_bibtex(body)
@@ -1220,10 +1326,12 @@ def convert(header, body, opt):
 
     if opt.format < 233:
         convert_graphics(body, opt)
+        convert_names(body, opt)
        opt.format = 233
 
 def revert(header, body, opt):
     if opt.format > 232:
+        revert_names(body, opt)
        opt.format = 232
     if opt.end == opt.format: return
 
index ac4651c4c380e162e055254d64d437f5447e2018..676710f4b758decf68141430fc210485f9b4d9e1 100644 (file)
 import string
 import re
 
+
 def check_token(line, token):
     if line[:len(token)] == token:
        return 1
     return 0
 
+
 # We need to check that the char after the token is space, but I think
 # we can ignore this
 def find_token(lines, token, start, end = 0):
@@ -35,6 +37,7 @@ def find_token(lines, token, start, end = 0):
            return i
     return -1
 
+
 def find_token2(lines, token, start, end = 0):
     if end == 0:
        end = len(lines)
@@ -44,6 +47,7 @@ def find_token2(lines, token, start, end = 0):
            return i
     return -1
 
+
 def find_tokens(lines, tokens, start, end = 0):
     if end == 0:
        end = len(lines)
@@ -54,6 +58,7 @@ def find_tokens(lines, tokens, start, end = 0):
                return i
     return -1
 
+
 def find_re(lines, rexp, start, end = 0):
     if end == 0:
        end = len(lines)
@@ -62,6 +67,7 @@ def find_re(lines, rexp, start, end = 0):
                return i
     return -1
 
+
 def find_token_backwards(lines, token, start):
     m = len(token)
     for i in xrange(start, -1, -1):
@@ -70,6 +76,7 @@ def find_token_backwards(lines, token, start):
            return i
     return -1
 
+
 def find_tokens_backwards(lines, tokens, start):
     for i in xrange(start, -1, -1):
        line = lines[i]
@@ -78,6 +85,7 @@ def find_tokens_backwards(lines, tokens, start):
                return i
     return -1
 
+
 def get_value(lines, token, start, end = 0):
     i = find_token2(lines, token, start, end)
     if i == -1:
@@ -87,6 +95,7 @@ def get_value(lines, token, start, end = 0):
     else:
         return ""
 
+
 def del_token(lines, token, i, j):
     k = find_token2(lines, token, i, j)
     if k == -1:
@@ -95,6 +104,7 @@ def del_token(lines, token, i, j):
        del lines[k]
        return j-1
 
+
 # Finds the paragraph that contains line i.
 def get_paragraph(lines, i):
     while i != -1:
@@ -105,6 +115,7 @@ def get_paragraph(lines, i):
        i = find_beginning_of_inset(lines, i)
     return -1
 
+
 # Finds the paragraph after the paragraph that contains line i.
 def get_next_paragraph(lines, i):
     while i != -1:
@@ -114,6 +125,7 @@ def get_next_paragraph(lines, i):
        i = find_end_of_inset(lines, i)
     return -1
 
+
 def find_end_of(lines, i, start_token, end_token):
     count = 1
     n = len(lines)
@@ -127,6 +139,7 @@ def find_end_of(lines, i, start_token, end_token):
            return i
     return -1
 
+
 # Finds the matching \end_inset
 def find_beginning_of(lines, i, start_token, end_token):
     count = 1
@@ -140,17 +153,21 @@ def find_beginning_of(lines, i, start_token, end_token):
            return i
     return -1
 
+
 # Finds the matching \end_inset
 def find_end_of_inset(lines, i):
     return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
 
+
 # Finds the matching \end_inset
 def find_beginning_of_inset(lines, i):
     return find_beginning_of(lines, i, "\\begin_inset", "\\end_inset")
 
+
 def find_end_of_tabular(lines, i):
     return find_end_of(lines, i, "<lyxtabular", "</lyxtabular")
 
+
 def get_tabular_lines(lines, i):
     result = []
     i = i+1
@@ -166,9 +183,11 @@ def get_tabular_lines(lines, i):
            i = i+1
     return result
 
+
 def is_nonempty_line(line):
     return line != " "*len(line)
 
+
 def find_nonempty_line(lines, start, end = 0):
     if end == 0:
        end = len(lines)
@@ -177,6 +196,7 @@ def find_nonempty_line(lines, start, end = 0):
            return i
     return -1
 
+
 ##
 # Tools for file reading
 #
@@ -209,6 +229,7 @@ def read_file(header, body, opt):
             break
         body.append(line[:-1])
 
+
 def write_file(header, body, opt):
     for line in header:
         opt.output.write(line+"\n")
@@ -216,6 +237,7 @@ def write_file(header, body, opt):
     for line in body:
         opt.output.write(line+"\n")
 
+
 ##
 # lyx version
 #
@@ -231,6 +253,7 @@ def read_version(header):
             return result.group(1)
     return None
 
+
 def set_version(lines, version):
     lines[0] = "#LyX %s created this file. For more info see http://www.lyx.org/" % version
     if lines[1][0] == '#':
@@ -256,6 +279,7 @@ format_relation = [("0_10",  [210], ["0.10.7","0.10"]),
                    ("1_3", [221], ["1.3.0","1.3.1","1.3.2","1.3.3","1.3.4","1.3"]),
                    ("1_4", [223,224,225,226,227,228,229,230,231,232,233], ["1.4.0cvs","1.4"])]
 
+
 def lyxformat(format, opt):
     result = format_re.match(format)
     if result:
@@ -269,6 +293,7 @@ def lyxformat(format, opt):
     opt.error(str(format) + ": " + "Format no supported.")
     return None
 
+
 def read_format(header, opt):
     for line in header:
         result = fileformat.match(line)
@@ -278,15 +303,26 @@ def read_format(header, opt):
         opt.error("Invalid LyX File.")
     return None
 
+
 def set_format(lines, number):
     if int(number) <= 217:
         number = float(number)/100
     i = find_token(lines, "\\lyxformat", 0)
     lines[i] = "\\lyxformat %s" % number
 
+
 def get_end_format():
     return format_relation[-1:][0][1][-1:][0]
 
+
+def get_backend(textclass):
+    if textclass == "linuxdoc" or textclass == "manpage":
+        return "linuxdoc"
+    if textclass[:7] == "docbook":
+        return "docbook"
+    return "latex"
+
+
 def chain(opt, initial_version):
     """ This is where all the decisions related with the convertion are taken"""