]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/parser_tools.py
7a8b356b68ae4628642388226c8b4b41a3e417fd
[lyx.git] / lib / lyx2lyx / parser_tools.py
1 # This file is part of lyx2lyx
2 # Copyright (C) 2002 Dekel Tsur <dekel@lyx.org>, José Matos <jamatos@lyx.org>
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
18 def check_token(lines, token, i):
19     if lines[i][:len(token)] == token:
20         return 1
21     return 0
22
23 def find_token(lines, token, start):
24     n = len(lines)
25     m = len(token)
26     i = start
27     while i < n:
28         line = lines[i]
29         if line[:m] == token:
30             return i
31         i = i+1
32     return -1
33
34 def find_token2(lines, token1, token2, start):
35     n = len(lines)
36     m1 = len(token1)
37     m2 = len(token2)
38     i = start
39     while i < n:
40         line = lines[i]
41         if line[:m1] == token1 or line[:m2] == token2:
42             return i
43         i = i+1
44     return -1
45
46 def find_token_backwards(lines, token, start):
47     n = len(lines)
48     m = len(token)
49     i = start
50     while i >= 0:
51         line = lines[i]
52         if line[:m] == token:
53             return i
54         i = i-1
55     return -1
56
57 def set_format(lines, number):
58     i = find_token(lines, "\\lyxformat", 0)
59     lines[i] = "\\lyxformat %s" % number