Page 1 of 2

printf... how to do it?

Posted: Sun Mar 09, 2008 3:30 am
by eddyb
i need to write some functions....
yah and i am at printf :? ...

Code: Select all

int printf ( const char * format, ...);
i thinked at a method, but i heve no idea how to get something from that
... (the args). have anyone a idea?

Posted: Sun Mar 09, 2008 4:16 am
by JamesM
Yeah, nick vsprintf from linux 0.01 and build around that. That's what I and most people do. Printf is hugely monolithic and difficult to debug without... you guessed it, printfs!

Printf

Posted: Sun Mar 09, 2008 5:08 am
by princeharrry
Maybe you find this interesting :
http://freenet-homepage.de/puppylinux/index.html
This what I am working on, it is for Dex OS ,output is fasm but
i think you could easy adapt the funktions.
If you need halp let me know.! :) :)
Hope it help :!:
Bye

Posted: Sun Mar 09, 2008 5:15 am
by eddyb
thanks for help, but i need only a tip for how i can use something "hidden" in that ...
Knows anyone?

Posted: Sun Mar 09, 2008 5:55 am
by JamesM
STFW!! STFW!!

Google for variable argument lists!

Posted: Sun Mar 09, 2008 7:29 am
by eddyb
yah i found :)
but i'm at writing strcat and this don't work(work, but only if the string is empty)

Code: Select all

char *strcat(char *destination[], const char *source[])
{
	int i;
	for(i=0;i<strlen(source);i++)
		destination[i+strlen(destination)] = source[i];
	return destination;
}
:roll:

Posted: Sun Mar 09, 2008 7:41 am
by lukem95
http://www.koders.com/c/fid2BD5D01DE7B9 ... B519C.aspx

Look at all the sources in that lib, it will tell you how to implement all the string functions etc.

as for printf, i stole it from linux 1.0 as JamesM suggests. Its very easy to port.

Posted: Sun Mar 09, 2008 9:33 am
by piranha
Yeah, nick vsprintf from linux 0.01 and build around that. That's what I and most people do. Printf is hugely monolithic and difficult to debug without... you guessed it, printfs!
Ya know, I opened this thread thinking "I'll add that Linux 0.01 printf is easy to port", and you guys beat me to it.

And use the Linux 0.01 version, there are less file that you don't need so you find the file easier.

-JL

Posted: Sun Mar 09, 2008 9:41 am
by eddyb
i like to do it, and is very simple

Posted: Sun Mar 09, 2008 9:59 am
by jzgriffin
lukem_95 wrote:http://www.koders.com/c/fid2BD5D01DE7B95EC45A02D8BB25D555988ADB519C.aspx

Look at all the sources in that lib, it will tell you how to implement all the string functions etc.
MinGW improperly implements some things...

Posted: Sun Mar 09, 2008 12:55 pm
by JamesM
i like to do it, and is very simple
No it's not. Not to do it properly (including hex/octal/decimal numbers, padding with 0/space to user defined lengths, the '%*' specifier...)

Posted: Sun Mar 09, 2008 2:03 pm
by Solar
PDCLib printf() doesn't do floating points (yet), but is otherwise complete (padding, alignment, ...) and - it's Public Domain, meaning you don't have to place your printf() under GPL as you would have if you took Linux as a starting point. See my signature.

Posted: Sun Mar 09, 2008 4:27 pm
by Brynet-Inc
Solar wrote:PDCLib printf() doesn't do floating points (yet), but is otherwise complete (padding, alignment, ...) and - it's Public Domain, meaning you don't have to place your printf() under GPL as you would have if you took Linux as a starting point. See my signature.
I don't think the initial Linux kernel release was under the GPL, it was under fairly simplistic licence that simply disallowed selling it commercially IIRC.

But I agree, even that is a bit... restrictive. :wink:

Posted: Sun Mar 09, 2008 4:57 pm
by jzgriffin
I don't actually even remember there being a license for 0.01...just a copyright. Can't remember.

On the topic of printf()'s, you could use Chris Giese's doprintf and friends. There doesn't seem to be a copyright anywhere, so I'm assuming it's public domain. Some things aren't implemented, but it gives a nice base to extend upon.

Posted: Sun Mar 09, 2008 4:59 pm
by Solar
Let's say the pre-GPL license is even more unwieldly, as it doesn't even say anything about derivative works. ;-)