Printf/Write callback!

From: Atmapuri (janez.makovsek_at_usa.net)
Date: 07/20/04


Date: Tue, 20 Jul 2004 14:17:19 +0200

Hi!

I would like to apply the code below the fortran write command.
The purpose is to route the write command to a device
which writes the strings to a memory stream, this memory
stream is then passed as a PChar array to a callback
functions previously set.

In this way, it is possible to "intercept" the printf calls in C
code and have the code running from the dll and calling
a user defined function, each time there is a need to print
something. Same purpose here.

How do I do that in Fortran?

Thanks!
Atmapuri

PrintCallback* printCallback = 0;

int _stdcall aPrintf (const char *format, ...)
{
  va_list arglist;
  char buf[1024];
  int n;

  va_start (arglist, format);
  memset (buf, 0, sizeof(buf));
  n = _vsnprintf (buf, sizeof(buf), format, arglist);
  if (printCallback != 0)
                   printCallback (buf);
  return n;
}

GLOBAL void set_printf_callback (PrintCallback cb)
{
  printCallback = cb;
}