From owner-freebsd-hackers@FreeBSD.ORG Sun Apr 27 13:38:40 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 950B7106564A for ; Sun, 27 Apr 2008 13:38:40 +0000 (UTC) (envelope-from romain@blogreen.org) Received: from postfix1-g20.free.fr (postfix1-g20.free.fr [212.27.60.42]) by mx1.freebsd.org (Postfix) with ESMTP id 204038FC22 for ; Sun, 27 Apr 2008 13:38:40 +0000 (UTC) (envelope-from romain@blogreen.org) Received: from smtp3-g19.free.fr (smtp3-g19.free.fr [212.27.42.29]) by postfix1-g20.free.fr (Postfix) with ESMTP id E39512583FB3 for ; Sun, 27 Apr 2008 15:12:20 +0200 (CEST) Received: from smtp3-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp3-g19.free.fr (Postfix) with ESMTP id D5BAB17B550; Sun, 27 Apr 2008 15:12:18 +0200 (CEST) Received: from marvin.blogreen.org (marvin.blogreen.org [82.247.213.140]) by smtp3-g19.free.fr (Postfix) with ESMTP id 8530217B54B; Sun, 27 Apr 2008 15:12:18 +0200 (CEST) Received: by marvin.blogreen.org (Postfix, from userid 1001) id 4CC0C5C059; Sun, 27 Apr 2008 15:12:18 +0200 (CEST) Date: Sun, 27 Apr 2008 15:12:18 +0200 From: Romain =?iso-8859-1?Q?Tarti=E8re?= To: freebsd-hackers@freebsd.org, hackers@freebsd.org Message-ID: <20080427131218.GA27750@marvin.blogreen.org> Mail-Followup-To: freebsd-hackers@freebsd.org, hackers@freebsd.org, Romuald Conty References: <20080426213557.GA88577@marvin.blogreen.org> <200804270201.53271.max@love2party.net> <20080427102053.GA7293@server.vk2pj.dyndns.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="3lcZGd9BuhuYXNfi" Content-Disposition: inline In-Reply-To: <20080427102053.GA7293@server.vk2pj.dyndns.org> User-Agent: Mutt/1.4.2.3i X-PGP-Key: http://romain.blogreen.org/pubkey.asc Cc: Romuald Conty Subject: Re: indent(1) support for gcc(1) 0b prefix X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Apr 2008 13:38:40 -0000 --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 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--