[patch] Let indent(1) handle widecharacter literals correctly

From: Tobias Rehbein <tobias.rehbein_at_web.de>
Date: Thu, 21 Jan 2010 22:05:23 +0100
Hi.

I am not subscribed to this list, so please answer me off-list or cc me.

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!

Find attached:

        indent.diff: the patch

        wcsxfrm.old.c: the result of `indent wcsxfrm.c`; using the indent(1)
                version from the base system
        
        wcsxfrm.new.c: the result of `indent wcsxfrm.c`; using the patched
                indent(1)

Please note the diff between wcsxfrm.old.c and wcsxfrm.new.c:
        
======== diff -u wcsxfrm.old.c wcsxfrm.new.c ========
--- wcsxfrm.old.c	2010-01-21 18:49:04.000000000 +0100
+++ wcsxfrm.new.c	2010-01-21 18:49:48.000000000 +0100
_at__at_ -49,9 +49,9 _at__at_
        size_t		slen;
        char           *mbsrc, *s, *ss;
 
-	if (*src == L '\0') {
+	if (*src == L'\0') {
                if (len != 0)
-			*dest = L '\0';
+			*dest = L'\0';
                return (0);
        }
        if (__collate_load_error || MB_CUR_MAX > 1) {
_at__at_ -61,7 +61,7 _at__at_
                                wcscpy(dest, src);
                        else {
                                wcsncpy(dest, src, len - 1);
-				dest[len - 1] = L '\0';
+				dest[len - 1] = L'\0';
                        }
                }
                return (slen);
_at__at_ -87,7 +87,7 _at__at_
        free(ss);
        free(mbsrc);
        if (len != 0)
-		*dest = L '\0';
+		*dest = L'\0';
 
        return (slen);
 }
=====================================================

Regards

-- 
Tobias Rehbein

PGP key:         4F2AE314
    server:      keys.gnupg.net
    fingerprint: ECDA F300 1B6E 9B87 8524  8663 E8B6 3138 4F2A E314

Received on Thu Jan 21 2010 - 20:23:51 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:00 UTC