9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Acid bug ?
@ 2002-02-22 15:04 Philippe Anel
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Anel @ 2002-02-22 15:04 UTC (permalink / raw)
  To: 9fans


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,




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9fans] Acid bug ?
@ 2002-02-22 17:27 rob pike
  0 siblings, 0 replies; 2+ messages in thread
From: rob pike @ 2002-02-22 17:27 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 1437 bytes --]

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';
}


[-- Attachment #2: message.txt --]
[-- Type: message/rfc822, Size: 2503 bytes --]

From: Philippe Anel <philippe.anel@noos.fr>
To: 9fans <9fans@cse.psu.edu>
Subject: [9fans] Acid bug ?
Date: Fri, 22 Feb 2002 16:04:10 +0100
Message-ID: <3C765DEA.5040102@noos.fr>


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,


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-02-22 17:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-22 15:04 [9fans] Acid bug ? Philippe Anel
2002-02-22 17:27 rob pike

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).