#!/usr/bin/perl
use utf8;

$number_of_words = 1004; # ($number_of_words + 1) % $out_columns must be 0!
$out_columns = 3;
$input = "syn2010_lemma";



### header

print <<"EOF";
\\mainlanguage[cz]
\\language[cz]
\\enableregime[utf]

\\setupbodyfont[14pt]  
\\enablemode[A4,paper]

\\setuplayout[%
	width=200mm,%
	height=286mm,%
	header=0mm, %
	footer=0mm, %
	topspace=5mm, %
	leftmargin=0mm, %
	rightmargin=0mm, %
	leftedge=0mm,
	backspace=5mm,
]

\\starttext

\\bTABLE[split=repeat,offset=\\dimexpr1mm]
\\setupTABLE[column][each][width=6.65cm]
\\setupTABLE[row][odd][height=4.6cm,style={\\ss\\bf},align={center,lohi},bottomframe=off]
\\setupTABLE[row][even][height=1cm,align={flushright,low},topframe=off]
\\bTABLEbody
EOF

### process input file 

$fp = open(FH, $input);
$i = 0;
$j = 1; # count out collums from one.

while($line = <FH>)
{

	@cols = split('\t', $line);

	if(substr($cols[0], 0, 1) == '#') { next; }

	if($j == 1){ print "\\bTR\n"; }

	print "\t\\bTD " . $cols[1] . " \\eTD\n";

	if($j++ == $out_columns)
	{
		print "\\eTR\n";
		print "\\bTR\\bTD " . ($i - 1)  . ".\\eTD\\bTD " . ($i)  . ".\\eTD\\bTD " . ($i + 1)  . ".\\eTD\\eTR\n";
		$j = 1;
	}


	if($i++ == $number_of_words)
	{
		last;
	}
}

### bottom
print <<"EOF";
\\eTABLEbody
\\eTABLE

\\stoptext
EOF

