over-riding printf() in VM

Bert Freudenberg bert at isg.cs.uni-magdeburg.de
Mon Jun 16 10:29:16 UTC 2003


Am Montag, 16.06.03 um 02:03 Uhr schrieb Tim Rowledge:

> In various places in interp.c we have uses of printf() and putchar().
> Since they go to the bit-bucket on my OS this is a bit pointless.
>
> I'd like to over-ride printf() so I can do something more useful. I
> could possibly change the VM code to use sprintf() to a string buffer
> and then pass to a platform specific macro but that means spreading the
> hassle (small though it be) to everyone playing with VM code. I feel
> sure there should be some way to use var-args and vfprintf() etc to 
> work
> around this but damned if I can find anything actually helpful right
> now. Has anyone actually done this and do yo uave a code snippet I can
> borrow from?

This is from the unix browser support code (sqUnixMozilla.c):

#ifdef DEBUG
void DPRINT(char *format, ...)
{
   static int debug= 42;
   if (42 == debug)
     debug= (NULL != getenv("NPSQUEAK_DEBUG"));

   if (!debug)
     {
       return;
     }
   else
     {
       static FILE *file= 0;
       if (!file)
         {
           file= fopen("/tmp/npsqueak.log", "a+");
         }

       if (file) {
         va_list ap;
         va_start(ap, format);
         vfprintf(file, format, ap);
         va_end(ap);
         fflush(file);
       }
     }
}
#else
void DPRINT(char *, ...) { }
#endif

-- Bert



More information about the Squeak-dev mailing list