]> git.lyx.org Git - lyx.git/blob - lib/scripts/fen2ascii.py
Converters: slightly more pythonic code.
[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 from __future__ import print_function
13 import sys,string,os
14
15 os.close(0)
16 os.close(1)
17 sys.stdin = open(sys.argv[1],"r")
18 sys.stdout = open(sys.argv[2],"w")
19
20 line = sys.stdin.readline()
21 if line[-1] == '\n':
22     line = line[:-1]
23
24 line=string.split(line,' ')[0]
25 comp=string.split(line,'/')
26
27 cont=1
28 margin= " "*6
29
30 print (margin+'   +'+"-"*15+'+')
31 for i in range(8):
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 ')