From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <2798085ca5c5ec875b24a62dad2d8348@plan9.bell-labs.com> To: 9fans@cse.psu.edu Subject: Re: [9fans] Acid bug ? From: "rob pike" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-nhrsdouazlymfhbveragngazdq" Date: Fri, 22 Feb 2002 12:27:16 -0500 Topicbox-Message-UUID: 54540642-eaca-11e9-9e20-41e7f4b1d025 This is a multi-part message in MIME format. --upas-nhrsdouazlymfhbveragngazdq Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit The documentation is wrong, although perhaps the code should be fixed to match the documentation rather than the other way around. In fact, I think I'll do that. There is not a good way to add extensions to the builtins. Coincidentally, though, I rewrote itoa() last weekend to make it easier to control the format in which an integer appears. With the code below you can say, besides the old itoa(27), itoa(27, "%x"), itoa(27, "value is %#.8x"), etc. The format string is a general print format that a) must accept ints and b) has the sense of %#x inverted. I fully acknowledge the utter hackedness of this. A better idea should be employed. -rob In main.c, int xconv(va_list *arg, Fconv *f) { f->f3 ^= 1<<2; /* was |= */ return numbconv(arg, f); } In builtin.c, void cvtitoa(Node *r, Node *args) { Node res; Node *av[Maxarg]; int ival; char buf[128], *fmt; if(args == 0) err: error("itoa(number [, printformat]): arg count"); na = 0; flatten(av, args); if(na == 0 || na > 2) goto err; expr(av[0], &res); if(res.type != TINT) error("itoa(integer): arg type"); ival = (int)res.ival; fmt = "%d"; if(na == 2){ expr(av[1], &res); if(res.type != TSTRING) error("itoa(integer, string): arg type"); fmt = res.string->string; } sprint(buf, fmt, ival); r->op = OCONST; r->type = TSTRING; r->string = strnode(buf); r->fmt = 's'; } --upas-nhrsdouazlymfhbveragngazdq Content-Type: message/rfc822 Content-Disposition: inline; filename=message.txt Received: from plan9.cs.bell-labs.com ([135.104.9.2]) by plan9; Fri Feb 22 10:25:16 EST 2002 Received: from mail.cse.psu.edu ([130.203.4.6]) by plan9; Fri Feb 22 10:25:15 EST 2002 Received: from psuvax1.cse.psu.edu (psuvax1.cse.psu.edu [130.203.16.6]) by mail.cse.psu.edu (CSE Mail Server) with ESMTP id 4B6CF19A6C; Fri, 22 Feb 2002 10:25:09 -0500 (EST) Delivered-To: 9fans@cse.psu.edu Received: from smtp.noos.fr (verlaine.noos.net [212.198.2.73]) by mail.cse.psu.edu (CSE Mail Server) with ESMTP id 8CBF419992 for <9fans@cse.psu.edu>; Fri, 22 Feb 2002 10:24:05 -0500 (EST) Received: (qmail 16150442 invoked by uid 0); 22 Feb 2002 15:04:04 -0000 Received: from unknown (HELO noos.fr) ([195.132.21.162]) (envelope-sender ) by 212.198.2.73 (qmail-ldap-1.03) with SMTP for <9fans@cse.psu.edu>; 22 Feb 2002 15:04:04 -0000 Message-ID: <3C765DEA.5040102@noos.fr> From: Philippe Anel User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:0.9.8) Gecko/20020209 X-Accept-Language: en-us MIME-Version: 1.0 To: 9fans <9fans@cse.psu.edu> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: [9fans] Acid bug ? Sender: 9fans-admin@cse.psu.edu Errors-To: 9fans-admin@cse.psu.edu X-BeenThere: 9fans@cse.psu.edu X-Mailman-Version: 2.0.8 Precedence: bulk Reply-To: 9fans@cse.psu.edu List-Help: List-Id: Fans of the OS Plan 9 from Bell Labs <9fans.cse.psu.edu> List-Archive: Date: Fri, 22 Feb 2002 16:04:10 +0100 Hi, According to the Acid Manual, The supported format characters are : -------------------------------------------------------cut-here---------------------- Formats ... b print byte in "hexadecimal". .... -------------------------------------------------------cut-here---------------------- But in /sys/src/cmd/acid/buildin.c, we have in the function "void patom(char type, Store *res)" : -------------------------------------------------------cut-here---------------------- switch(res->fmt) { ... case 'b': Bprint(bout, "%3d", (int)res->ival&0xff); break; ... } -------------------------------------------------------cut-here---------------------- Do you know a good way to add extensions to the builtin functions of acid ? (without modifing the acid sources) Philippe, --upas-nhrsdouazlymfhbveragngazdq--