From owner-freebsd-hackers@FreeBSD.ORG Sun Apr 27 21:03:11 2008 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 60C07106564A for ; Sun, 27 Apr 2008 21:03:11 +0000 (UTC) (envelope-from jrisom@gmail.com) Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.180]) by mx1.freebsd.org (Postfix) with ESMTP id 128308FC0A for ; Sun, 27 Apr 2008 21:03:10 +0000 (UTC) (envelope-from jrisom@gmail.com) Received: by py-out-1112.google.com with SMTP id u52so7305615pyb.10 for ; Sun, 27 Apr 2008 14:03:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:in-reply-to:references:mime-version:content-type:message-id:content-transfer-encoding:cc:from:subject:date:to:x-mailer; bh=p9S2oNJE/E1yX9ejGR1PN8gyh2uM2FYDN3dPdOyOoNQ=; b=UJ8GdBcUm/m415w+hJddHJjYaVLVAL3ylO6s0ZXn8NBqDn0z5FdUhfRGuEqXGT2eNZ2unCpuJ+jf+wHR/pSAc3MYuHY6zfo9Wpvx2l6nIzdYd5RF/Cp0fOVh+1Eo8vefWrb8YseSzUEYdTX4rRqlicIBp8yuBbFo60VP+eQwZXo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=in-reply-to:references:mime-version:content-type:message-id:content-transfer-encoding:cc:from:subject:date:to:x-mailer; b=x1WWhIeI+8fAvgCpkAzy4vKDUGuTO+qBMHj39irKosknBH696/bza6lzlwwHLDXiRW/TczCOYvFLDDe7KA1Ww28zVHXxBydyT0rN2vOvF9uqdJc4mjU8yLxy1gmAwPeKKZy2hle3OPFjxwHsamXvLENyFFVhSx4ARrxEvoxQjKE= Received: by 10.35.86.19 with SMTP id o19mr11663692pyl.43.1209328569572; Sun, 27 Apr 2008 13:36:09 -0700 (PDT) Received: from ?192.168.1.4? ( [98.212.164.35]) by mx.google.com with ESMTPS id a48sm13598412pyh.24.2008.04.27.13.36.03 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 27 Apr 2008 13:36:06 -0700 (PDT) In-Reply-To: <20080426213557.GA88577@marvin.blogreen.org> References: <20080426213557.GA88577@marvin.blogreen.org> Mime-Version: 1.0 (Apple Message framework v624) Content-Type: text/plain; charset=ISO-8859-1; format=flowed Message-Id: Content-Transfer-Encoding: quoted-printable From: Joshua Isom Date: Sun, 27 Apr 2008 15:38:54 -0500 To: =?ISO-8859-1?Q?Romain_Tarti=E8re?= X-Mailer: Apple Mail (2.624) Cc: hackers@freebsd.org, 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 21:03:11 -0000 On Apr 26, 2008, at 4:35 PM, Romain Tarti=E8re wrote: > Hello FreeBSD hackers! > > I'm using avr-gcc from the ports and relying on the 0b prefix notation > for binary constants, that is: > > foo =3D 0b00101010; > > Thanks to /usr/ports/devel/avr-gcc/files/patch-0b-constants this is > possible :-) > > But I would like to use indent(1) to reformat contributed code > automatically. Unfortunately, the 0b notation is not supported by that > program, and the resulting code looks like this: > > foo =3D 0 b00101010; > > ... then compilation fails, bla bla bla... > > A quick look at indent(1) source code leaded me to tweak > /usr/src/usr.bin/indent/lexi.c so that the 0b notation is supported > (patch attached). > > I was so wondering how useful(less) it was to support this extension = in > FreeBSD indent(1) program. The version of gcc provided with the base > system does not support this syntax, and AFAIK, only the avr-gcc port > support this kind of constructs... > > So options are: > - Add support for 0b notation to FreeBSD indent(1) (maybe requiring > the use of an extra command line argument to support this = feature); > - Provide a patch for indent(1) that can be conditionally applied on > the code when compiling the world; > - Create another port, say avr-indent(1), that is not more than a=20 > copy > of indent(1) with support of 0b constructs; > - Do nothing: tweaking indent(1) for supporting this is so trivial > that the few individuals interested in this can have their local > version of indent. > > Can you please tell me your opinion about this? > > Thank you in advance, > Romain > > PS: I also took a look at GNU indent (gindent(1) from the ports), but=20= > it > does not support 0b notation too. > > --=20 > Romain Tarti=E8re =20 > http://romain.blogreen.org/ > pgp: 8DAB A124 0DA4 7024 F82A E748 D8E9 A33F FF56 FF43 (ID:=20 > 0xFF56FF43) > (plain text =3Dnon-HTML=3D PGP/GPG encrypted/signed e-mail much=20 > appreciated) > Why not just have a base2.h file that is a list of defines such as: #define b00000001 1 #define b00000010 2 Then you just use a b00 syntax, perfectly valid, and all's well=20 everywhere. Considering that the 0b syntax isn't valid without a patch=20= that's only available with one compiler that's probably not regularly=20 used, it'd probably be much more maintainable and not require anyone=20 compiling the program to install that specific port with that specific=20= patch. But of course, writing software that deals directly with bit fiddling=20 is annoying without using binary representation. The man page for indent does say "it has a 'forgiving' parser" so I=20 don't see why it can't just treat any token starting with a zero as=20 special, treat 0b01, 0x0A, 0f4 and 010 as a number regardless of the=20 base, even if it doesn't know the base.=