From owner-freebsd-questions@FreeBSD.ORG Mon Jan 26 22:59:25 2009 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7B6661065725 for ; Mon, 26 Jan 2009 22:59:25 +0000 (UTC) (envelope-from svein.h@lvor.halvorsen.cc) Received: from bene2.itea.ntnu.no (bene2.itea.ntnu.no [IPv6:2001:700:300:3::57]) by mx1.freebsd.org (Postfix) with ESMTP id BAD0D8FC13 for ; Mon, 26 Jan 2009 22:59:24 +0000 (UTC) (envelope-from svein.h@lvor.halvorsen.cc) Received: from localhost (localhost [127.0.0.1]) by bene2.itea.ntnu.no (Postfix) with ESMTP id 1FEE990006 for ; Mon, 26 Jan 2009 23:59:23 +0100 (CET) Received: from maren.thelosingend.net (maren.math.ntnu.no [129.241.211.48]) by bene2.itea.ntnu.no (Postfix) with SMTP id AB5E690004 for ; Mon, 26 Jan 2009 23:59:22 +0100 (CET) Received: (qmail 29420 invoked by uid 88); 26 Jan 2009 23:56:41 +0100 Received: from maren.math.ntnu.no (HELO [127.0.0.1]) (129.241.211.48) by maren.thelosingend.net (qpsmtpd/0.31.1) with ESMTP; Mon, 26 Jan 2009 23:56:41 +0100 Message-ID: <497E41B8.2030203@lvor.halvorsen.cc> Date: Tue, 27 Jan 2009 00:05:28 +0100 From: Svein Halvor Halvorsen User-Agent: Thunderbird 2.0.0.18 (X11/20081205) MIME-Version: 1.0 To: Chuck Swiger References: <497E31EE.9010202@lvor.halvorsen.cc> <0B02CEE8-D38A-4D94-B76D-49721BDDACF0@mac.com> In-Reply-To: <0B02CEE8-D38A-4D94-B76D-49721BDDACF0@mac.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Debian amavisd-new at bene2.itea.ntnu.no Cc: questions@freebsd.org Subject: Re: printf and utf-8 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Jan 2009 22:59:25 -0000 Chuck Swiger wrote: > On Jan 26, 2009, at 1:58 PM, Svein Halvor Halvorsen wrote: >> As far as I can see, printf is not calculating strings lengths >> correctly when using utf-8 encoding. Either that, or I'm using byte >> count, and can't find the character count :-/ > > printf(1) explicitly states that it works with ASCII and ANSI > X3.159-1989 (``ANSI C89'') character escapes, and it also notes: > > Multibyte characters are not recognized in format strings (this is > only a > problem if `%' can appear inside a multibyte character). > > Some platforms have a printf_l(3) which is locale/xlocale-aware, but > there doesn't seem to be a corresponding CLI utility which understands > Unicode/UTF8/widechars. Thanks for your explanation. Do you have a suggestion to solve the following problem without using printf(1): I have a text file that I want to print in a "box" on a terminal from a shell script. Now I've padded the lines with spaces to a certain length using printf %-70s and appended the box drawing character. Is there another simple way that will work with utf-8? sv.