/* debug.c */

#include <string.h>

#include "main.h"
#include "debug.h"

static char *z( char *s )
{ static char z = 0;
  return s ? s : &z;
}  

void debug_init( char *path )
{ char buffer[256];

  strncpy( buffer, path, 256 );
  strcat( buffer, ".logfile" );
  debug = fopen( buffer, "w" );
}

void debug_action( Action *a )
{ int i;

  if( !debug ) return;
  fprintf( debug, "\nline      %i\n", a->line );
  fprintf( debug, "object    %x\n", a->object );
  fprintf( debug, "component %x\n", a->component );
  fprintf( debug, "event     %x\n", a->event );
  fprintf( debug, "value     %s\n", z(a->value) );
  fprintf( debug, "action    %c\n", a->action );
  for( i = 0; i < MAX_ARG; i++ )
    fprintf( debug, "parameter %i %s\n", i, z(a->arg[i]) );
  fflush( debug );
}
    
void debug_actionList( Action *a )
{ if( !debug ) return;
  while( a )
  { debug_action( a );
    a = a->next;
  }
  fputs( "", debug );
}

/* end of debug.c */
