From tobias.rehbein@web.de  Fri Jan 22 18:35:40 2010
Return-Path: <tobias.rehbein@web.de>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id D628610656A4
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 22 Jan 2010 18:35:40 +0000 (UTC)
	(envelope-from tobias.rehbein@web.de)
Received: from fmmailgate02.web.de (fmmailgate02.web.de [217.72.192.227])
	by mx1.freebsd.org (Postfix) with ESMTP id 638298FC2F
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 22 Jan 2010 18:35:40 +0000 (UTC)
Received: from smtp06.web.de (fmsmtp06.dlan.cinetic.de [172.20.5.172])
	by fmmailgate02.web.de (Postfix) with ESMTP id D050314C5AC86
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 22 Jan 2010 19:35:38 +0100 (CET)
Received: from [95.88.224.31] (helo=sushi.pseudo.local)
	by smtp06.web.de with asmtp (TLSv1:AES256-SHA:256)
	(WEB.DE 4.110 #314)
	id 1NYOM6-0004jP-00
	for FreeBSD-gnats-submit@freebsd.org; Fri, 22 Jan 2010 19:35:38 +0100
Received: from sushi.pseudo.local (localhost [127.0.0.1])
	by sushi.pseudo.local (8.14.3/8.14.3) with ESMTP id o0MIZbVP011433
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 22 Jan 2010 19:35:37 +0100 (CET)
	(envelope-from tobi@sushi.pseudo.local)
Received: (from tobi@localhost)
	by sushi.pseudo.local (8.14.3/8.14.3/Submit) id o0MIZbLZ011432;
	Fri, 22 Jan 2010 19:35:37 +0100 (CET)
	(envelope-from tobi)
Message-Id: <201001221835.o0MIZbLZ011432@sushi.pseudo.local>
Date: Fri, 22 Jan 2010 19:35:37 +0100 (CET)
From: Tobias Rehbein <tobias.rehbein@web.de>
Sender: tobias.rehbein@web.de
Reply-To: Tobias Rehbein <tobias.rehbein@web.de>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] Let indent(1) handle widecharacter literals correctly
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         143090
>Category:       bin
>Synopsis:       [PATCH] Let indent(1) handle widecharacter literals correctly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 22 18:40:02 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Tobias Rehbein
>Release:        FreeBSD 8.0-RELEASE-p2 i386
>Organization:
>Environment:
System: FreeBSD sushi.pseudo.local 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #5: Fri Jan 15 19:16:49 CET 2010 tobi@sushi.pseudo.local:/usr/obj/usr/src/sys/SUSHI i386


	
>Description:
        I noticed that indent(1) handles widecharacter literals (e.g. L'c' or
        L"string") incorrectly. indent(1)s parser treats the L-prefix and the
        quoted part as seperate tokens. The result is:

                L'c'            ->      L 'c'
                L"string"       ->      L "string"

        Of course this breaks any code using widecharacters. As I use indent(1)
        quite extensively I decided to fix this issue. 
        
        As this is my first patch against the FreeBSD user land feel free to
        comment!

        The first version of this patch including examples was posted to
        freebsd-current@freebsd.org:

        http://archive.netbsd.se/?ml=freebsd-current&a=2010-01&m=12274166
>How-To-Repeat:
        indent /usr/src/lib/libc/string/wcsxfrm.c
>Fix:

	

--- indent.diff begins here ---
diff -u /usr/src/usr.bin/indent/Makefile usr.bin/indent/Makefile
--- /usr/src/usr.bin/indent/Makefile	2010-01-22 19:18:41.000000000 +0100
+++ usr.bin/indent/Makefile	2010-01-21 19:01:13.000000000 +0100
@@ -3,4 +3,6 @@
 PROG=	indent
 SRCS=	indent.c io.c lexi.c parse.c pr_comment.c args.c
 
+WARNS?=		6
+
 .include <bsd.prog.mk>
diff -u /usr/src/usr.bin/indent/lexi.c usr.bin/indent/lexi.c
--- /usr/src/usr.bin/indent/lexi.c	2010-01-22 19:18:41.000000000 +0100
+++ usr.bin/indent/lexi.c	2010-01-22 19:14:00.000000000 +0100
@@ -222,6 +222,14 @@
 			    break;
 		}
 		CHECK_SIZE_TOKEN;
+		if ((s_token == e_token) && *buf_ptr == 'L' &&
+			(*(buf_ptr + 1) == '\'' || *(buf_ptr + 1) == '"' )) {
+		    /* widecharacter literal */
+		    *e_token++ = *buf_ptr++;        /* copy L */
+		    *e_token++ = *buf_ptr;          /* copy ' or " */
+		    qchar = *buf_ptr++;             /* set string delimeter */
+		    goto found_string;
+		}
 		/* copy it over */
 		*e_token++ = *buf_ptr++;
 		if (buf_ptr >= buf_end)
@@ -361,6 +369,7 @@
     case '\'':			/* start of quoted character */
     case '"':			/* start of string */
 	qchar = *token;
+found_string:
 	if (troff) {
 	    e_token[-1] = '`';
 	    if (qchar == '"')
--- indent.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:
