/******************************************************************************/
/*                                                                            */
/*  AUDIT - Keep an audit log                                                 */
/*                                                                            */
/******************************************************************************/

#define STRICT
#include <windows.h>
#include <commctrl.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include "const.h"
#include "classes.h"
#include "funcdefs.h"
#include "lin.rh"
#include "extern.h"

static char audit_log[512] = { "LIN.LOG" } ;
static char tempfile[512] = { "" } ;

void audit ( const char *text )
{
   FILE *fp ;
   char line[4096] ;
   SYSTEMTIME systime ;

   if (! strlen ( tempfile )) {   // If this has not yet been called
      strcpy_s ( tempfile , audit_log ) ;
      _fullpath ( audit_log , tempfile , 512 ) ;
      if (fopen_s ( &fp , audit_log , "wt" )) {
         sprintf_s ( line , "Cannot open log file %s", audit_log ) ;
         MessageBox ( hwndFrame , line , "ERROR" , MB_ICONSTOP | MB_OK ) ;
         return ;
         }
      GetLocalTime ( &systime ) ;
      sprintf_s ( line , "LIN 1.0 (%s)  %d/%d/%02d  %d:%02d:%02d" ,
         audit_log,
         systime.wMonth, systime.wDay, systime.wYear%100,
         systime.wHour, systime.wMinute, systime.wSecond ) ;
      fprintf ( fp , "%s", line ) ;
      fclose ( fp ) ;
      }

   if (! fopen_s ( &fp , audit_log , "at" )) {
      fprintf ( fp , "\n%s", text ) ;
      fclose ( fp ) ;
      }
}