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