1. Piotr Wach
  2. LiquidMastachEngine

Source

LiquidMastachEngine / Backup / 18.01.04 / Libaries / savfile.cpp


/*
	Obsluga plikow SAV.
	By CEPA 2002
*/



#include "savfile.h"
#include <string.h>

SAVFile::SAVFile()
  : File()
{}

SAVFile::SAVFile(char *_filename,int _mode)
  : File(_filename,_mode)
{}

void SAVFile::GetString(char *val,char *buf)
{
  char b[255];
  Seek(0);
  for(long j = 0; j < Lines(); j++)
  {
    SeekLine(j);
    Scanf("%s",b);
    if(strcmp(b,val) == 0)
    {
      Scanf("%s%c%[^\n]",NULL,NULL,buf);
    }
  }
}

char SAVFile::GetChar(char *val)
{
  char c = 0;
  char b[255];
  Seek(0);
  for(long j = 0; j < Lines(); j++)
  {
    SeekLine(j);
    Scanf("%s",b);
    if(strcmp(b,val) == 0)
    {
      Scanf("%s%c%c",NULL,NULL,&c);
    }
  }
  return c;
}

int SAVFile::GetInt(char *val)
{
  int i = 0;
  char b[255];
  Seek(0);
  for(long j = 0; j < Lines(); j++)
  {
    SeekLine(j);
    Scanf("%s",b);
    if(strcmp(b,val) == 0)
    {
      Scanf("%s%c%d",NULL,NULL,&i);
    }
  }
  return i;
}

long SAVFile::GetLong(char *val)
{
  long l = 0;
  char b[255];
  Seek(0);
  for(long j = 0; j < Lines(); j++)
  {
    SeekLine(j);
    Scanf("%s",b);
    if(strcmp(b,val) == 0)
    {
      Scanf("%s%c%ld",NULL,NULL,&l);
    }
  }
  return l;
}

double SAVFile::GetDouble(char *val)
{
  double d = 0;
  char b[255];
  Seek(0);
  for(long j = 0; j < Lines(); j++)
  {
    SeekLine(j);
    Scanf("%s",b);
    if(strcmp(b,val) == 0)
    {
      Scanf("%s%c%lf",NULL,NULL,&d);
    }
  }
  return d;
}

void SAVFile::SetString(char *val,char *buf)
{
  SeekEnd();
  Printf("\n%s = %s",val,buf);
}

void SAVFile::SetChar(char *val,char c)
{
  SeekEnd();
  Printf("\n%s = %c",val,c);
}

void SAVFile::SetInt(char *val,int i)
{
  SeekEnd();
  Printf("\n%s = %d",val,i);
}

void SAVFile::SetLong(char *val,long l)
{
  SeekEnd();
  Printf("\n%s = %D",val,l);
}

void SAVFile::SetDouble(char *val,double d)
{
  SeekEnd();
  Printf("\n%s = %G",val,d);
}