// 
// File name: Config.cpp
//
// Discription: Описание методов класса Конфигурация
//
// Programmer: Vladimir P. Stasevich (SV)
//
// History: 
//    Created 24.02.2000 (SV)
//

#include "Config.h"

TConfig config;

int TConfig::SaveToFile
(
   const char *fileName, 
   unsigned& fx, 
   unsigned& fz, 
   unsigned& my 
)
{
   fxMistake = fx;
   fzMistake = fz;
   myMistake = my;

   FILE *fp;
   fp = fopen( fileName, "wt" );
   
   if( fp == NULL ) 
      return 1;
   
   fprintf( fp, "+Fx Mistake%u", fxMistake );
   fprintf( fp, "\n+Fz Mistake%u", fzMistake );
   fprintf( fp, "\n+My Mistake%u", myMistake );

   strcpy( name, fileName );

   fclose(fp);
   return 0;
}

int TConfig::LoadFromFile
(
   const char *fileName, 
   unsigned& fx, 
   unsigned& fz, 
   unsigned& my 
)
{
   unsigned myFx; 
   unsigned myFz; 
   unsigned myMy;
   
   FILE         *fp;
   fp = fopen( fileName, "rt" );
      
   if( fp == NULL ) 
      return 1;
      
   fscanf( fp, "+Fx Mistake%u\n", &myFx );
   fscanf( fp, "+Fz Mistake%u\n", &myFz );
   fscanf( fp, "+My Mistake%u\n", &myMy );

   fx = myFx;
   fz = myFz;
   my = myMy;
            
   strcpy( name, fileName );

   fclose(fp);
   return 0;
}
