Vincent van Ravesteijn wrote:
> I would especially like to ask whether someone is willing to check the
> lyx2lyx part ?

Everything untested, and I'm not really a Pythonist either. Just some thoughts 
on how I would have done it.

> Vincent
> author_ids2.patch

> Index: lib/lyx2lyx/lyx_2_0.py
> ===================================================================
> --- lib/lyx2lyx/lyx_2_0.py      (revision 30748)
> +++ lib/lyx2lyx/lyx_2_0.py      (working copy)
> @@ -947,7 +947,65 @@
>            document.body[i:i+3] = subst
>        i = i + 2
>  
> +def convert_author_id(document):
> +    " Add the author_id to the \\author definition and make sure 0 is not
> used" +    i = 0
> +    j = 1
> +    while True:
> +        i = find_token(document.header, "\\author", i)
> +        if i == -1:
> +            break
> +        document.header[i] = document.header[i][:8] \
> +                             + str(j) + document.header[i][7:]
> +        j = j + 1
> +        i = i + 1

+        i = find_token(document.header, "\\author", i)
+        if i == -1:
+            break
+        name = get_value(document.header, '\\author', i)
+        document.header[i] = "\\author " + str(j) + ' ' + name
+        j = j + 1
+        i = i + 1


> +    k = 0
> +    while True:
> +        k = find_token(document.body, "\\change_", k)
> +        
> +        if k == -1:
> +            break
> +        l = document.body[k].find(" ")
> +        m = document.body[k].rfind(" ")
> +        
> +        if (l > -1) and (m > -1) and (l != m):
> +            val = string.atoi(document.body[k][l:m])
> +            document.body[k] = document.body[k][:l] \
> +                               + ' ' + str(val + 1) \
> +                               + document.body[k][m:]
> +        k = k + 1

+        k = find_token(document.body, "\\change_", k)
+        
+        if k == -1:
+            break
+        change = document.body[k].split(' ')
+        if len(change) == 3:    
+            val = string.atoi(change[1])
+            document.body[k] = change[0] \
+                               + ' ' + str(val + 1) \
+                               + ' ' + change[2]
+        k = k + 1


> +def revert_author_id(document):
> +    " Remove the author_id from the \\author definition "
> +    i = 0
> +    j = 0
> +    while True:
> +        i = find_token(document.header, "\\author", i)
> +        if i == -1:
> +            return
> +        n = document.header[i].find('\"')
> +        if n == -1:
> +            continue
> +        document.warning(document.header[i][8:(n-1)])
> +        k = 0
> +        aid = string.atoi(document.header[i][8:(n-1)])
> +        while True:
> +            k = find_token(document.body, "\\change_", k)
> +            if k == -1:
> +                break
> +            l = document.body[k].find(" ")
> +            m = document.body[k].rfind(" ")
> +            if (l > -1) and (m > -1) and (l != m):
> +                val = string.atoi(document.body[k][l:m])
> +                if (val == aid):
> +                    document.body[k] = document.body[k][:l] \
> +                                       + ' ' + str(j) \
> +                                       + document.body[k][m:]
> +            k = k + 1
> +        document.header[i] = document.header[i][:8] +
> document.header[i][n:] +        j = j + 1
> +        i = i + 1
> +

+        i = find_token(document.header, "\\author", i)
+        if i == -1:
+            return
+        line = document.header[i]
+        r = re.compile(r'(\\author) (\d+) (\".*\")$')
+        m = r.match(line)
+        if m != None:
+            k = 0
+            aid = string.atoi(m.group(1))
+            while True:
+                k = find_token(document.body, "\\change_", k)
+                if k == -1:
+                    break
+                change = document.body[k].split(' ')
+                if len(change) == 3:    
+                    val = string.atoi(change[1])
+                    if (val == aid):
+                        document.body[k] = change[0] \
+                                           + ' ' + str(j) \
+                                           + ' ' + change[2]
+                k = k + 1
+            document.header[i] = m.group(0) + m.group(2)
+            j = j + 1
+        i = i + 1
+

Jürgen

Reply via email to