Page 1 of 1

doprnt with custom function

Posted: Mon Jan 22, 2007 8:58 pm
by pcmattman
Hello, does anyone know anywhere where I can get code for _doprnt that takes a custom character output function? I have a version in a book but there is 4 pages worth of code and I'd prefer to avoid writing all that...

For instance, if the character output function is 'kputc' which takes 1 argument (the character), I could call _doprnt like so:

_doprnt( format, args, kputc );

Does anyone know where to find code for this?

Posted: Mon Jan 22, 2007 10:28 pm
by pcmattman
Never mind, I found a 'cprintf' in the libraries that come with Turbo C that uses BIOS interrupts. Turns out, there are a lot of functions in Turbo C that use BIOS interrupts... very useful!

Posted: Tue Jan 23, 2007 5:37 am
by Solar
Hmmm... a macro that takes the name of a character delivery function as parameter?

There's an idea I haven't come across so far. I have to think this over... thanks for the hint! 8)

Posted: Tue Jan 23, 2007 7:09 pm
by pcmattman
Yeah, it's useful for something like _doprnt because it means that you don't have to write 8 different versions for your 8 different character handling routines (like putc,kputc,fputc etc...)

However, Turbo C already comes with a whole lot of console stuff that uses BIOS interrupts which means that I can concentrate on other parts of my OS (like memory management, tasks etc...).

Posted: Wed Jan 24, 2007 1:09 am
by Solar
pcmattman wrote:Yeah, it's useful for something like _doprnt because it means that you don't have to write 8 different versions for your 8 different character handling routines (like putc,kputc,fputc etc...)
I am not sure I can follow you there. I can understand where _doprnt() might be a nice solution for using the same format parsing code for kernel space (kputc) and user space (fputc), but beyond those two? putc() is defined to be the same as fputc() in effect, only that it may be a macro...?

Posted: Wed Jan 24, 2007 3:55 am
by pcmattman
Some variants of _doprnt take a function pointer as an argument. It's not a macro, it's just using a function pointer to allow custom character output routines.

Posted: Wed Jan 24, 2007 5:58 am
by Solar
*cough*

Nah, I don't want an additional pointer indirection on each character written... I'm just evaluating how much sense a macro would make to create a format parser that can be used unchanged in kernel and user space.