X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fscripts%2Ffen2ascii.py;h=74087440e20ed8890bca120435c9fe23b8279086;hb=1a36fee79dc2f4ce83f47db44c8093831d20e6c0;hp=6a60964a9776f97cc6df4a14551a6b44d6d295c6;hpb=cff50172f32f3f9203155790c67601225ea1e354;p=lyx.git diff --git a/lib/scripts/fen2ascii.py b/lib/scripts/fen2ascii.py index 6a60964a97..74087440e2 100644 --- a/lib/scripts/fen2ascii.py +++ b/lib/scripts/fen2ascii.py @@ -1,6 +1,3 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- - # file fen2ascii.py # This file is part of LyX, the document processor. # Licence details can be found in the file COPYING. @@ -12,23 +9,13 @@ # This script will convert a chess position in the FEN # format to an ascii representation of the position. -import sys, string, os, locale - -# We expect two args, the names of the input and output files. -if len(sys.argv) != 3: - sys.exit(1) - -language, output_encoding = locale.getdefaultlocale() -if output_encoding == None: - output_encoding = 'latin1' - -input = unicode(sys.argv[1], 'utf8').encode(output_encoding) -output = unicode(sys.argv[2], 'utf8').encode(output_encoding) +from __future__ import print_function +import sys,string,os os.close(0) os.close(1) -sys.stdin = open(input, "r") -sys.stdout = open(output, "w") +sys.stdin = open(sys.argv[1],"r") +sys.stdout = open(sys.argv[2],"w") line = sys.stdin.readline() if line[-1] == '\n': @@ -40,24 +27,23 @@ comp=string.split(line,'/') cont=1 margin= " "*6 -print margin+' +'+"-"*15+'+' +print (margin+' +'+"-"*15+'+') for i in range(8): - cont = cont + 1 tmp="" for j in comp[i]: - if j>='0' and j <= '9': - for k in range(int(j)): - cont = cont + 1 - x, mod = divmod(cont,2) - if mod : tmp = tmp + '| ' - else : tmp = tmp + '|*' - else : - tmp = tmp + '|' + j - cont = cont + 1 + if j>='0' and j <= '9': + for k in range(int(j)): + cont = cont + 1 + x, mod = divmod(cont,2) + if mod : tmp = tmp + '| ' + else : tmp = tmp + '|*' + else : + tmp = tmp + '|' + j + cont = cont + 1 row = 8 - i - print margin, row, tmp+"|" + print (margin, row, tmp+"|") -print margin+' +'+"-"*15+'+' -print margin+' a b c d e f g h ' +print (margin+' +'+"-"*15+'+') +print (margin+' a b c d e f g h ')