Re: [xml] functions using varargs



Hello Daniel,

Is there any option to receive the text already formated ? It seems that it
would (again) require extending the API... or is there
any simpler option that I missed ?

   Valid point. There is no such API. I need to think more about it
first.
   What's happen when one of the existing callbacks contains only
the formatting string and no other parameter. I'm not too enthusiastic
about duplicating the full error API, and would prefer make it an
option to change the existing behaviour.

I was experimenting with one solution - in few words, exported C formater - and
it seems to be easy to both implement and use:

- I added a new function, to "error.c" (hopefully the correct place):
---------------------
int
xmlFormatMessage(char* buf, const char** msg)
{
    va_list args;
    int sz;
    va_start(args, *msg);
    sz = vsprintf(buf, *msg, args);
    va_end(args);
    return sz;
}
---------------------
- added the relevant entry to libxml2.def.src
- (and should also add it to error.h)

Now, in my Pascal handler, I just call this formater, passing back address of
the argument:
---------------------
procedure myGenericErrorFunc(ctx: pointer; msg: PChar); cdecl;
var
  s: String;
begin
  SetLength(s, 10000);
  SetLength(s, xmlFormatMessage(PChar(s), @msg)); // <-- HERE
  OutputDebugString(PChar(s));
end;
---------------------

The code here is meant just to show the idea; I think it is really simple and is
usable the same way for SAX and any other message reporting functions.
What do you think about the approach ?

Petr





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]