Date: Thu, 21 Jan 2010 22:05:23 +0100 From: Tobias Rehbein <tobias.rehbein@web.de> To: freebsd-current@freebsd.org Subject: [patch] Let indent(1) handle widecharacter literals correctly Message-ID: <20100121210523.GA1442@sushi.pseudo.local>
next in thread | raw e-mail | index | archive | help
--nmemrqcdn5VTmUEE
Content-Type: multipart/mixed; boundary="PmA2V3Z32TCmWXqI"
Content-Disposition: inline
--PmA2V3Z32TCmWXqI
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
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"str=
ing")
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) qui=
te
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
=20
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:
=20
=3D=3D=3D=3D=3D=3D=3D=3D diff -u wcsxfrm.old.c wcsxfrm.new.c =3D=3D=3D=3D=
=3D=3D=3D=3D
--- wcsxfrm.old.c 2010-01-21 18:49:04.000000000 +0100
+++ wcsxfrm.new.c 2010-01-21 18:49:48.000000000 +0100
@@ -49,9 +49,9 @@
size_t slen;
char *mbsrc, *s, *ss;
=20
- if (*src =3D=3D L '\0') {
+ if (*src =3D=3D L'\0') {
if (len !=3D 0)
- *dest =3D L '\0';
+ *dest =3D L'\0';
return (0);
}
if (__collate_load_error || MB_CUR_MAX > 1) {
@@ -61,7 +61,7 @@
wcscpy(dest, src);
else {
wcsncpy(dest, src, len - 1);
- dest[len - 1] =3D L '\0';
+ dest[len - 1] =3D L'\0';
}
}
return (slen);
@@ -87,7 +87,7 @@
free(ss);
free(mbsrc);
if (len !=3D 0)
- *dest =3D L '\0';
+ *dest =3D L'\0';
=20
return (slen);
}
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
Regards
--=20
Tobias Rehbein
PGP key: 4F2AE314
server: keys.gnupg.net
fingerprint: ECDA F300 1B6E 9B87 8524 8663 E8B6 3138 4F2A E314
--PmA2V3Z32TCmWXqI
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="indent.diff"
Content-Transfer-Encoding: quoted-printable
diff -u /usr/src/usr.bin/indent/Makefile usr.bin/indent/Makefile
--- /usr/src/usr.bin/indent/Makefile 2010-01-20 23:59:33.000000000 +0100
+++ usr.bin/indent/Makefile 2010-01-21 19:01:13.000000000 +0100
@@ -3,4 +3,6 @@
PROG=3D indent
SRCS=3D indent.c io.c lexi.c parse.c pr_comment.c args.c
=20
+WARNS?=3D 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-20 23:59:33.000000000 +0100
+++ usr.bin/indent/lexi.c 2010-01-21 18:52:49.000000000 +0100
@@ -221,6 +221,13 @@
} else
break;
}
+ if (*buf_ptr =3D=3D 'L' && (*(buf_ptr + 1) =3D=3D '\'' || =
*(buf_ptr + 1) =3D=3D '"' ) && (s_token =3D=3D e_token)) {
+ /* widecharacter literal */
+ *e_token++ =3D *buf_ptr++; /* copy L */
+ *e_token++ =3D *buf_ptr; /* copy ' or " */
+ qchar =3D *buf_ptr++; /* set string de=
limeter */
+ goto found_string;
+ }
CHECK_SIZE_TOKEN;
/* copy it over */
*e_token++ =3D *buf_ptr++;
@@ -361,6 +368,7 @@
case '\'': /* start of quoted character */
case '"': /* start of string */
qchar =3D *token;
+found_string:
if (troff) {
e_token[-1] =3D '`';
if (qchar =3D=3D '"')
--PmA2V3Z32TCmWXqI--
--nmemrqcdn5VTmUEE
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)
iEYEARECAAYFAktYwZEACgkQ6LYxOE8q4xSYWgCeJKty9Ypk6BCr1V+54q+R0xo8
jNgAoIcvAger3Oc9rsna5A0RXdnKeFrc
=0vBN
-----END PGP SIGNATURE-----
--nmemrqcdn5VTmUEE--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100121210523.GA1442>
