]> git.lyx.org Git - lyx.git/blob - lib/scripts/fen2ascii.py
Check path of Qt tools if qtchooser is detected
[lyx.git] / lib / scripts / fen2ascii.py
1 # file fen2ascii.py
2 # This file is part of LyX, the document processor.
3 # Licence details can be found in the file COPYING.
4
5 # author Kayvan A. Sylvan
6
7 # Full author contact details are available in file CREDITS.
8
9 # This script will convert a chess position in the FEN
10 # format to an ascii representation of the position.
11
12 import sys,string,os
13
14 os.close(0)
15 os.close(1)
16 sys.stdin = open(sys.argv[1],"r")
17 sys.stdout = open(sys.argv[2],"w")
18
19 line = sys.stdin.readline()
20 if line[-1] == '\n':
21     line = line[:-1]
22
23 line=string.split(line,' ')[0]
24 comp=string.split(line,'/')
25
26 cont=1
27 margin= " "*6
28
29 print margin+'   +'+"-"*15+'+'
30 for i in range(8):
31
32     cont = cont + 1
33     tmp=""
34     for j in comp[i]:
35         if j>='0' and j <= '9':
36             for k in range(int(j)):
37                 cont = cont + 1
38                 x, mod = divmod(cont,2)
39                 if mod : tmp = tmp + '| '
40                 else : tmp = tmp + '|*'
41         else :
42             tmp = tmp + '|' + j
43             cont = cont + 1
44
45     row = 8 - i
46     print margin, row, tmp+"|"
47
48 print margin+'   +'+"-"*15+'+'
49 print margin+'    a b c d e f g h '