Page 2 of 2
Posted: Sun Mar 09, 2008 5:04 pm
by jzgriffin
Even more unwieldy than the GPL? Wow. Didn't know that was possible.
In short, there seem to be two good public domain printfs out there, just use those. Or, better yet, read them and figure out how they work, then do your own.
Posted: Sun Mar 09, 2008 8:10 pm
by Brynet-Inc
Jeremiah Griffin wrote:There doesn't seem to be a copyright anywhere, so I'm assuming it's public domain.
That's a very bad assumption to make, and IMHO.. and illegal one..
http://en.wikipedia.org/wiki/Berne_Conv ... stic_Works
Posted: Mon Mar 10, 2008 12:51 am
by Solar
Brynet-Inc wrote:Jeremiah Griffin wrote:There doesn't seem to be a copyright anywhere, so I'm assuming it's public domain.
That's a very bad assumption to make, and IMHO.. and illegal one..
My point exactly. A common misbelief (especially among hobbyist coders) is that if a license doesn't forbid something, it's implicitly allowed. The contrary is the case in most countries. The original Linux license said you are allowed to redistribute the kernel as long as you provide source and don't ask a commercial fee for it. It doesn't say zilch about modifying, using parts of it or anything. Linus
might agree to you using early code snippets under GPL terms, but legally speaking that would still require written consent of
all authors involved...
Ah, copyright law. Good thing I haven't had breakfast yet.
Posted: Mon Mar 10, 2008 2:31 am
by eddyb
for the begin:
Code: Select all
void printf (char format[], ... )
{
va_list arguments; // A place to store the list of arguments
int i, dz_fl=0;
char ch;
unsigned char uctmp;
signed char sctmp;
unsigned short ustmp;
signed short sstmp;
unsigned int uitmp;
signed int sitmp;
va_start(arguments, format);
for(i=0;i<strlen(format);i++)
{
ch = format[i];
if(dz_fl)
{
switch(ch)
{
case '%':
putch('%');
break;
case 'c':
putch(va_arg(arguments, char));
break;
case 's':
puts(va_arg(arguments, char));
break;
default:
break;
}
}
else
{
switch(ch)
{
case '%':
dz_fl=1;
break;
default:
if(ch != '%')
putch(ch);
break;
}
}
}
va_end(arguments);
}
But i have problems: strings(%s) don't work, and it prints the % symbol(normally, it mustn't) chars(%c) work
Posted: Mon Mar 10, 2008 3:22 am
by JamesM
Deal with it yourself. We are not here to debug your code. I am sick of your mindless spamposts, when it is obvious you have put NO effort in yourself.
Posted: Mon Mar 10, 2008 3:28 am
by Solar
Uh-huh...
- None of your temporary variables is actually used.
- dz_fl - which I take is the flag for "now I am within a format specifier" - is never reset to 0.
- For strings, you pull a char from the stack (should be char *).
All in all, this looks like a classic: You jumped at what looked the easiest part of the implementation,
before you had a clear design in mind. While this might result in
some success immediately, it also results in
much redesign later on.
Note that printf() is effectively a call to fprintf() with stdout as target stream. fprintf() in turn is simply a wrapper for vfprintf()...
and you need the same format-parsing logic for the sprintf() family, too.
And perhaps you want to keep in mind that "%#+6.3d" is a valid format specifier, and that for implementing that you have to go far beyond a simple switch...
Posted: Mon Mar 10, 2008 4:08 am
by JamesM
Lets not forget the classic "%*" which will **** up the logic in an ill-designed system.
Posted: Mon Mar 10, 2008 9:11 am
by quok
In my system, I just ported over Solar's excellent printf from PDCLib. As he says, it doesn't do floats yet, but that's not a big deal to me.
I also ported some functions from OpenBSD's libc.
Once long ago I did use Chris Giese's printf() implementation. That one is safe to use from a licensing standpoint; he explicity denies copyright to the code and places it in the public domain. Okay, well, some countries don't have the concept of public domain, but that code should still be safe to use. Just don't strip the header information from those files.
Beware there are limitations to this implementation as well (it also doesn't do floats, and a lot of other things that PDCLib does do).
So, IMO, when it comes to printf() and friends, you have three choices.
1) Solar's PDCLib
2) Chris Geise's printf() implementation (
http://my.execpc.com/~geezer/osd/libc/printf.c)
3) Rip it from OpenBSD. Their code is ISC and BSD licensed, so it's safe to use even for those of you that are creating closed-source projects.
Posted: Tue Mar 11, 2008 2:30 am
by eddyb
now works well
. I'm gonna implement other format types