#/bin/sh
#
# LI18NUX2K.L1/utils/pr/pr.sh
#
# Copyright (c) 1991, 1992, 1997, 1998, 1999, 2001 X/Open Company Ltd.
# (X/Open)
# trading as The Open Group
# Copyright (c) 2001, 2003 International Business Machines Corp.
# All rights reserved except as granted by this License.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the "Artistic License" which comes with this
# Kit, with the following modification:
# a) "executable(s)" should be interpreted to include
# "test case(s)"
# b) if you wish to make changes as defined in clause 2 and 3, and
# distribute a modified version of this package, then
# clauses 3c and 4c are required
# c) Clause 7 is rephrased as follows: "Subroutines supplied by you
# and linked into this Package shall not be considered part of this
# Package".
#
#
# X/OPEN, TRADING AS THE OPEN GROUP, AND IBM CORP. DISCLAIM ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL X/OPEN OR IBM CORP. BE
# LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# You should have received a copy of the Artistic License with this
# Kit, in the file named "Artistic".  If not, we'll be glad to provide one.


tet_startup="startup"			# startup function
tet_cleanup="cleanup"			# cleanup function
iclist="ic1"
ic1="tp1 tp2 tp3 tp4 tp5 tp6"

targetlocale="LTP_1.UTF-8"

tp1()
{
	tet_infoline "* When -w option is specified, verify this utility truncates the lines to make the length of the lines be less than or equal to the assigned width."
	tet_infoline " "

	export LANG=$targetlocale

	pr -2 -w60 -t whns_opt_test.I >out.stdout 2>out.stderr
	diff out.stdout w_opt_test.O 2>&1 >/dev/null

	result_output_code $? "Can't truncates the input lines correctly."
}

tp2()
{
	tet_infoline "* When -h option is specified, verify this utility uses the given string to replace the contents of the file operand in the page header even if the given string is written in multibyte characters."
	tet_infoline " "

	export LANG=$targetlocale

	titlestr="AÄあaäぁ"
	pr -h "$titlestr" whns_opt_test.I >out.stdout 2>out.stderr
	head -5 out.stdout | grep "$titlestr" >/dev/null 2>&1

	result_output_code $? "Can't print header including multibyte characters."
}

tp3()
{
	tet_infoline "* When -n option is specified, verify this utility uses the given character as the separator between line number and first column."
	tet_infoline " "

	export LANG=$targetlocale

	pr -2 -nー2 -w60 -t whns_opt_test.I >out.stdout 2>out.stderr
	diff out.stdout n_opt_test.O 2>&1 >/dev/null

	result_output_code $? "Can't interpret character as the separator between line number and first column."
}

tp4()
{
	tet_infoline "* When -s option is specified, verify this utility uses the given character as the separator during the columns."
	tet_infoline " "

	export LANG=$targetlocale

	pr -2 -sー -w60 -t whns_opt_test.I >out.stdout 2>out.stderr
	diff out.stdout s_opt_test.O 2>&1 >/dev/null

	result_output_code $? "Can't interpret character as the separator during the columns."
}

tp5()
{
	tet_infoline "* When -i option is specified, verify this utility uses the given character as the character which multiple space characters is replaced with. The replaced space characters are to the next tab stop."
	tet_infoline " "

	export LANG=$targetlocale

	pr -t -iあ5 i_opt_test.I >out.stdout 2>out.stderr
	diff out.stdout i_opt_test.O 2>&1 >/dev/null

	result_output_code $? "Can't replace the taget spaces with the character correctry."
}

tp6()
{
	tet_infoline "* When -e option is specified, verify this utility uses the given character as the character which is replaced with multiple space characters. The number of space characters is defined so that next character stands at tab_stop."
	tet_infoline " "

	export LANG=$targetlocale

	pr -eあ5 -t e_opt_test.I >out.stdout 2>out.stderr
	diff out.stdout e_opt_test.O 2>&1 >/dev/null

	result_output_code $? "Can't replace the character with the spaces correctry."
}

startup() # startup function
{
	rm -f out.stdout out.stderr >/dev/null 2>&1
}

cleanup() # clean-up function
{
	rm -f out.stdout out.stderr >/dev/null 2>&1
}

# source common shell functions

. $TET_EXECUTE/LIB/i18nfuncs.sh
. $TET_EXECUTE/LIB/shfuncs.sh
. $TET_EXECUTE/LIB/lsbfuncs.sh

# execute shell test case manager - must be last line
. $TET_ROOT/lib/xpg3sh/tcm.sh
