34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# CDDL HEADER START
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# The contents of this file are subject to the terms of the
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# Common Development and Distribution License (the "License").
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# You may not use this file except in compliance with the License.
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# See the License for the specific language governing permissions
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# and limitations under the License.
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# When distributing Covered Code, include this CDDL HEADER in each
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# If applicable, add the following below this CDDL HEADER, with the
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# fields enclosed by brackets "[]" replaced with your own identifying
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# information: Portions Copyright [yyyy] [name of copyright owner]
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# CDDL HEADER END
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# This test checks whether arithmetric operator '<character>
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# This was reported as CR #6805794 ('[ku1] printf returns "invalid character constant" for $ printf "%d\n" "'<euro>"'):
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# ------------ snip ------------
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# There seems be a bug in how ast-ksh.2008-11-04's "printf" builtin
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# handles multibyte characters. For example if I try this in the
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# en_US.UTF-8 locale ("<euro>" needs to be replace with the EURO symbol):
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# $ printf "%d\n" "'<euro>"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# -ksh93: printf: warning: ': invalid character constant
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# AFAIK the correct behaviour was to return the numeric value of the
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# <euro> symbol in this case (hexadecimal "20ac", decimal 8364), e.g.
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# $ printf "%d\n"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# Steps to Reproduce
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# Enter this in an interractive shell:
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# $ printf "%d\n" "'<euro>"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# Expected Result
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# $ printf "%d\n"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# Actual Result
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# $ printf "%d\n" "'<euro>"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# -ksh93: printf: warning: ': invalid character constant
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# Error Message(s)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# printf: warning: ': invalid character constant
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# printf "%d\n" "'<euro>"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# ------------ snip ------------
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# declare variables
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz# test whether the locale uses an UTF-8 (-like) encoding and override it on demand
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ "$(printf "\u[20ac]")" == $'\342\202\254' ]] || LC_ALL=en_US.UTF-8
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzif [[ "$(printf "\u[20ac]")" != $'\342\202\254' ]] ; then
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzstr=$(print $'printf "%d\\\\n" "\'\342\202\254"' | source /dev/stdin)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ "${str}" == "8364" ]] || err_exit "expected 8364, got ${str}"