doprnt with custom function

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

doprnt with custom function

Post 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?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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)
Every good solution is obvious once you've found it.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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...).
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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...?
Every good solution is obvious once you've found it.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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.
Every good solution is obvious once you've found it.
Post Reply