/* LICENSE:
  =========================================================================
    CMPack'04 Source Code Release for OPEN-R SDK 1.1.5-r2 for ERS7
    Copyright (C) 2004 Multirobot Lab [Project Head: Manuela Veloso]
    School of Computer Science, Carnegie Mellon University
    All rights reserved.
  ========================================================================= */

#include <stdarg.h>
#include <stdio.h>

static FILE *log = NULL;

bool lprintf_open(char *file)
{
  if(log) fclose(log);
  log = fopen(file,"wt");
  return(log != NULL);
}

bool lprintf_close()
{
  int ret;

  ret = fclose(log);
  log = NULL;

  return(ret == 0);
}

int lprintf(char *fmt, ...)
{
  va_list al;
  int ret;

  if(log){
    va_start(al,fmt);
    vfprintf(log, fmt, al);
    va_end(al);
  }

  va_start(al,fmt);
  ret = vprintf(fmt, al);
  va_end(al);

  return(ret);
}
