[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    RE: kDebug format codes
From:       Geert Jansen <g.t.jansen () stud ! tue ! nl>
Date:       2000-01-26 12:13:08
[Download RAW message or body]

David Faure wrote:
> > Hi.
> > 
> > I found myself typing a whole lot of 
> > 
> >   kDebugInfo("error: %s\n",strerror(errno)) 
> > 
> > lately. Thus, I made a patch to kdebug, making it accept kde-specific
> > format codes. Currently, there's one: %r expands to strerror(errno).
> > 
> > Shall I commit this?
> >     Geert Jansen                       
> 
> Out of interest, doesn't this slow it down a lot ?
> You probably have to parse the format string (as opposed
> to let sprintf do the job - well in addition to it)...

I't not too bad. I expand the codes in two passes.

The first pass finds all extended format codes and stores their value. If it
doesn't find any, it stops. So if no codes are found, it the cost is one
character by character traversal of the string, which is not very bad.

If there are extended format codes, pass 2 allocates memory for the expanded
string and replaces the codes with their values from pass 1.

> Perhaps better to simply add kDebugStrerror() ?

Well, I like a printf solution better because then I can format the
message the way I like...

Greetings,
 -- 
    Geert Jansen                       email: <g.t.jansen at stud.tue.nl>
    Phylosopher, Physicist,                    email: <jansen at kde.org>           
    KDE enthusiast                                 PGP key ID: 0xD2B5E7CE            

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic