--3lcZGd9BuhuYXNfi
Content-Type: multipart/mixed; boundary="ikeVEW9yuYc//A+q"
Content-Disposition: inline
--ikeVEW9yuYc//A+q
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Sun, Apr 27, 2008 at 08:20:53PM +1000, Peter Jeremy wrote:
> By inserting whitespace, indent(1) is changing the syntax of the input
> and, IMHO, indent should not be doing that - its brief is to
> re-arrange whitespace to (hopefully) improve legibility, not make
> syntactic changes.
>=20
> I would support changing indent to bring its tokenisation more into
> line with the C preprocessor.
I share your point of view. I tweaked a bit more indent(1) so that it
tries to detect invalid numeric tokens, and in such circumstances output
a warning message and does NOT change the code.
Comments are welcomed.
Regards,
Romain
--=20
Romain Tarti=E8re <romain@blogreen.org> http://romain.blogreen.org/
pgp: 8DAB A124 0DA4 7024 F82A E748 D8E9 A33F FF56 FF43 (ID: 0xFF56FF43)
(plain text =3Dnon-HTML=3D PGP/GPG encrypted/signed e-mail much appreciated)
--ikeVEW9yuYc//A+q
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="lexi.c.diff"
Content-Transfer-Encoding: quoted-printable
--- /usr/src/usr.bin/indent/lexi.c 2005-11-20 14:48:15.000000000 +0100
+++ lexi.c 2008-04-27 15:09:21.000000000 +0200
@@ -121,6 +121,10 @@
1, 1, 1, 0, 3, 0, 3, 0
};
=20
+enum base {
+ BASE_2, BASE_8, BASE_10, BASE_16
+};
+
int
lexi(void)
{
@@ -158,16 +162,37 @@
int seendot =3D 0,
seenexp =3D 0,
seensfx =3D 0;
- if (*buf_ptr =3D=3D '0' &&
- (buf_ptr[1] =3D=3D 'x' || buf_ptr[1] =3D=3D 'X')) {
- *e_token++ =3D *buf_ptr++;
- *e_token++ =3D *buf_ptr++;
- while (isxdigit(*buf_ptr)) {
+ enum base in_base =3D BASE_10;
+
+ if (*buf_ptr =3D=3D '0') {
+ if (buf_ptr[1] =3D=3D 'b' || buf_ptr[1] =3D=3D 'B')
+ in_base =3D BASE_2;
+ else if (buf_ptr[1] =3D=3D 'x' || buf_ptr[1] =3D=3D 'X')
+ in_base =3D BASE_16;
+ else
+ in_base =3D BASE_8;
+ }
+
+ *e_token++ =3D *buf_ptr++;
+ if (in_base =3D=3D BASE_2 || in_base =3D=3D BASE_16)
+ *e_token++ =3D *buf_ptr++; /* Read the second character from
+ * 0b... / 0x... expressions.
+ */
+
+ switch (in_base) {
+ case BASE_2:
+ while (*buf_ptr =3D=3D '0' || *buf_ptr =3D=3D '1') {
CHECK_SIZE_TOKEN;
*e_token++ =3D *buf_ptr++;
}
- }
- else
+ break;
+ case BASE_8:
+ while (*buf_ptr >=3D '0' && *buf_ptr <=3D '8') {
+ CHECK_SIZE_TOKEN;
+ *e_token++ =3D *buf_ptr++;
+ }
+ break;
+ case BASE_10:
while (1) {
if (*buf_ptr =3D=3D '.') {
if (seendot)
@@ -209,6 +234,29 @@
}
break;
}
+
+ break;
+ case BASE_16:
+ while (isxdigit(*buf_ptr)) {
+ CHECK_SIZE_TOKEN;
+ *e_token++ =3D *buf_ptr++;
+ }
+ break;
+ }
+ if (isalnum(*buf_ptr)) {
+ char *buf;
+ /* current token is malformed */
+ if (asprintf(&buf, "Ignoring invalid numeric "
+ "expression '%s%c...'", s_token, *buf_ptr)) {
+ diag2(0, buf);
+ free(buf);
+ }
+ /* finish to eat the current token */
+ while (isalnum(*buf_ptr)) {
+ CHECK_SIZE_TOKEN;
+ *e_token++ =3D *buf_ptr++;
+ }
+ }
}
else
while (chartype[(int)*buf_ptr] =3D=3D alphanum || *buf_ptr =3D=3D BAC=
KSLASH) {
--ikeVEW9yuYc//A+q--
--3lcZGd9BuhuYXNfi
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.8 (FreeBSD)
iEYEARECAAYFAkgUe7IACgkQ2OmjP/9W/0MhoACeK0qhAaMthPMw2aWzVvDpeihg
k7UAn3oC1vOUyVRKkzkmD275LZ5+ZXvb
=ka6I
-----END PGP SIGNATURE-----
--3lcZGd9BuhuYXNfi--