Commit b72b5783 authored by Vitaly Lipatov's avatar Vitaly Lipatov

rename Jrn to Storage family, add Makefile.am for build test

parent 4ff8b8fa
......@@ -26,7 +26,7 @@
#include "stdio.h"
#include "string.h"
#include "Jrn.h"
#include "Storages.h"
char* itoa(int val, int base)
{
......@@ -48,14 +48,14 @@ void testTable(void)
{
char *chr=new char[2];
char *val=new char[2];
StorageTable *t;
t = new StorageTable("table.test", 6000, 0);
TableStorage *t;
t = new TableStorage("table.test", 6000, 0);
int i;
printf("testTable\nsize = %d\n",t->size);
for(i=0;i<t->size+5;i++)
{
chr[0]=i%256;
if(t->AddRow(chr,chr)==1) printf("elem number %d - no space in StorageTable\n",i);
if(t->AddRow(chr,chr)==1) printf("elem number %d - no space in TableStorage\n",i);
}
printf("elements with values=keys added\n");
for(i=40;i<60;i++)
......@@ -81,11 +81,11 @@ void testTable(void)
void testJournal1(void)
{
CycleJournal *j;
CycleStorage *j;
int i;
char *str=new char[6];
printf("journal test 1\n");
j = new CycleJournal("journal.test",2000000,0);
j = new CycleStorage("journal.test",2000000,0);
printf("size = %d\n",j->size);
for(i=1;i<30000;i++)
{
......@@ -109,17 +109,17 @@ void testJournal1(void)
j->ViewRows(0,20);
printf("\nthe same after reopen:\n");
delete j;
j = new CycleJournal("journal.test",2000000,0);
j = new CycleStorage("journal.test",2000000,0);
j->ViewRows(0,20);
printf("\n");
}
void testJournal2(void)
{
CycleJournal *j;
CycleStorage *j;
int i,k;
char *str=new char[4];
j = new CycleJournal("journal.test",2000000,0);
j = new CycleStorage("journal.test",2000000,0);
printf("journal test 2 - checking number of iterations to find head/tail\n");
printf("size = %d\n\n",j->size);
printf("iterations = %d\n",j->iter);
......@@ -131,7 +131,7 @@ void testJournal2(void)
j->AddRow(str);
}
delete j;
j = new CycleJournal("journal.test",2000000,0);
j = new CycleStorage("journal.test",2000000,0);
printf("iterations = %d\n",j->iter);
}
printf("\n");
......
############################################################################
# This file is part of the UniSet library #
############################################################################
bin_PROGRAMS = jrntest
jrntest_SOURCES = JrnTest.cc
jrntest_LDADD = $(top_builddir)/lib/libUniSet.la
jrntest_CPPFLAGS = -I$(top_builddir)/include
include $(top_builddir)/conf/setting.mk
......@@ -3,7 +3,7 @@
############################################################################
UTILS = scripts Admin NullController SViewer-text \
InfoServer SMonit MBTester codegen
InfoServer SMonit MBTester codegen JrnTests
#MapSourceParser ClassGen
if DISABLE_MYSQL
......
......@@ -67,7 +67,7 @@ AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
ETAGS = etags
CTAGS = ctags
DIST_SUBDIRS = scripts Admin NullController SViewer-text InfoServer \
SMonit MBTester codegen DBServer-MySQL
SMonit MBTester codegen JrnTests DBServer-MySQL
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
am__relativize = \
dir0=`pwd`; \
......@@ -226,7 +226,7 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
UTILS = scripts Admin NullController SViewer-text \
InfoServer SMonit MBTester codegen
InfoServer SMonit MBTester codegen JrnTests
@DISABLE_MYSQL_FALSE@SUBDIRS = ${UTILS} DBServer-MySQL
#MapSourceParser ClassGen
......
......@@ -18579,7 +18579,7 @@ fi
done
ac_config_files="$ac_config_files Makefile libUniSet.pc lib/Makefile IDL/Makefile IDL/UniSetTypes/Makefile IDL/Processes/Makefile IDL/Services/Makefile src/Communications/Makefile src/Communications/Modbus/Makefile src/IOs/Makefile src/Interfaces/Makefile src/ObjectRepository/Makefile src/Processes/Makefile src/Services/Makefile src/Threads/Makefile src/Timers/Makefile src/Various/Makefile src/Makefile include/Makefile include/modbus/Makefile include/IOs/Makefile docs/Makefile docs/UniSetDox.cfg docs/UniSetDoxDevel.cfg Utilities/Makefile Utilities/scripts/Makefile Utilities/Admin/Makefile Utilities/NullController/Makefile Utilities/SViewer-text/Makefile Utilities/SMonit/Makefile Utilities/InfoServer/Makefile Utilities/MBTester/Makefile Utilities/DBServer-MySQL/Makefile Utilities/codegen/Makefile Utilities/codegen/uniset-codegen Utilities/codegen/tests/Makefile extensions/Makefile extensions/libUniSetExtensions.pc extensions/lib/Makefile extensions/include/Makefile extensions/IOControl/Makefile extensions/IOControl/libUniSetIOControl.pc extensions/RTUExchange/Makefile extensions/RTUExchange/libUniSetRTU.pc extensions/UDPExchange/Makefile extensions/UDPExchange/libUniSetUDP.pc extensions/ModbusSlave/Makefile extensions/ModbusSlave/libUniSetMBSlave.pc extensions/MBTCPMaster/Makefile extensions/MBTCPMaster/libUniSetMBTCPMaster.pc extensions/LogicProcessor/Makefile extensions/LogicProcessor/libUniSetLogicProcessor.pc extensions/SMViewer/Makefile extensions/SharedMemory/Makefile extensions/SharedMemory/libUniSetSharedMemory.pc extensions/SharedMemoryPlus/Makefile"
ac_config_files="$ac_config_files Makefile libUniSet.pc lib/Makefile IDL/Makefile IDL/UniSetTypes/Makefile IDL/Processes/Makefile IDL/Services/Makefile src/Communications/Makefile src/Communications/Modbus/Makefile src/IOs/Makefile src/Interfaces/Makefile src/ObjectRepository/Makefile src/Processes/Makefile src/Services/Makefile src/Threads/Makefile src/Timers/Makefile src/Various/Makefile src/Makefile include/Makefile include/modbus/Makefile include/IOs/Makefile docs/Makefile docs/UniSetDox.cfg docs/UniSetDoxDevel.cfg Utilities/Makefile Utilities/scripts/Makefile Utilities/Admin/Makefile Utilities/NullController/Makefile Utilities/SViewer-text/Makefile Utilities/SMonit/Makefile Utilities/InfoServer/Makefile Utilities/MBTester/Makefile Utilities/DBServer-MySQL/Makefile Utilities/JrnTests/Makefile Utilities/codegen/Makefile Utilities/codegen/uniset-codegen Utilities/codegen/tests/Makefile extensions/Makefile extensions/libUniSetExtensions.pc extensions/lib/Makefile extensions/include/Makefile extensions/IOControl/Makefile extensions/IOControl/libUniSetIOControl.pc extensions/RTUExchange/Makefile extensions/RTUExchange/libUniSetRTU.pc extensions/UDPExchange/Makefile extensions/UDPExchange/libUniSetUDP.pc extensions/ModbusSlave/Makefile extensions/ModbusSlave/libUniSetMBSlave.pc extensions/MBTCPMaster/Makefile extensions/MBTCPMaster/libUniSetMBTCPMaster.pc extensions/LogicProcessor/Makefile extensions/LogicProcessor/libUniSetLogicProcessor.pc extensions/SMViewer/Makefile extensions/SharedMemory/Makefile extensions/SharedMemory/libUniSetSharedMemory.pc extensions/SharedMemoryPlus/Makefile"
cat >confcache <<\_ACEOF
......@@ -19638,6 +19638,7 @@ do
"Utilities/InfoServer/Makefile") CONFIG_FILES="$CONFIG_FILES Utilities/InfoServer/Makefile" ;;
"Utilities/MBTester/Makefile") CONFIG_FILES="$CONFIG_FILES Utilities/MBTester/Makefile" ;;
"Utilities/DBServer-MySQL/Makefile") CONFIG_FILES="$CONFIG_FILES Utilities/DBServer-MySQL/Makefile" ;;
"Utilities/JrnTests/Makefile") CONFIG_FILES="$CONFIG_FILES Utilities/JrnTests/Makefile" ;;
"Utilities/codegen/Makefile") CONFIG_FILES="$CONFIG_FILES Utilities/codegen/Makefile" ;;
"Utilities/codegen/uniset-codegen") CONFIG_FILES="$CONFIG_FILES Utilities/codegen/uniset-codegen" ;;
"Utilities/codegen/tests/Makefile") CONFIG_FILES="$CONFIG_FILES Utilities/codegen/tests/Makefile" ;;
......
......@@ -174,6 +174,7 @@ AC_CONFIG_FILES([Makefile
Utilities/InfoServer/Makefile
Utilities/MBTester/Makefile
Utilities/DBServer-MySQL/Makefile
Utilities/JrnTests/Makefile
Utilities/codegen/Makefile
Utilities/codegen/uniset-codegen
Utilities/codegen/tests/Makefile
......
/* This file is part of the UniSet project
* Copyright (c) 2002 Free Software Foundation, Inc.
* Copyright (c) 2002 Ivan Donchevskiy
* Copyright (c) 2009 Free Software Foundation, Inc.
* Copyright (c) 2009 Ivan Donchevskiy
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -24,51 +24,56 @@
*/
// --------------------------------------------------------------------------
#include "stdio.h"
#include "string.h"
#ifndef Storages_H_
#define Storages_H_
#include <stdio.h>
#include <string.h>
#define str_size 80
#define key_size 20
#define val_size 40
struct StorageTableElem
struct TableStorageElem
{
char key[key_size];
char value[val_size];
} __attribute__((__packed__));
struct CycleJournalElem
struct CycleStorageElem
{
char str[str_size];
int status;
} __attribute__((__packed__));
class StorageTable
class TableStorage
{
FILE *file;
int seekpos;
public:
int size;
StorageTable();
StorageTable(const char* name, int sz, int seek);
~StorageTable();
TableStorage();
TableStorage(const char* name, int sz, int seek);
~TableStorage();
int AddRow(char* key, char* val);
int DelRow(char* key);
char* FindKeyValue(char* key, char* val);
};
class CycleJournal
class CycleStorage
{
FILE *file;
int seekpos;
int head,tail;
public:
int size, iter;
CycleJournal();
CycleJournal(const char* name, int sz, int seek);
~CycleJournal();
CycleStorage();
CycleStorage(const char* name, int sz, int seek);
~CycleStorage();
int AddRow(char* str);
int DelRow(int row);
int DelAllRows(void);
int ViewRows(int beg, int num);
};
#endif
......@@ -76,7 +76,7 @@ class UniSetObject:
virtual CORBA::Boolean exist();
virtual char* getName(){return (char*)myname.c_str();}
virtual UniSetTypes::ObjectId getId(){ return myid; }
virtual UniSetTypes::ObjectType getType() { return "UniSetObject"; }
virtual UniSetTypes::ObjectType getType() { static UniSetTypes::ObjectType ot("UniSetObject"); return ot; }
virtual UniSetTypes::SimpleInfo* getInfo();
friend std::ostream& operator<<(std::ostream& os, UniSetObject& obj );
......
......@@ -24,126 +24,14 @@
*/
// --------------------------------------------------------------------------
#include "stdio.h"
#include "string.h"
#include "Jrn.h"
#include <stdio.h>
#include <string.h>
StorageTable::StorageTable()
{
file = fopen("tbl", "r+");
if(file==NULL)
{
file = fopen("tbl","w");
StorageTableElem *t = new StorageTableElem();
for(int i=0;i<100;i++) fwrite(t,sizeof(*t),1,file);
fclose(file);
file = fopen("tbl","r+");
}
size=100;
seekpos=0;
}
StorageTable::StorageTable(const char* name, int sz, int seek)
{
file = fopen(name, "r+");
size=sz/sizeof(StorageTableElem);
if(file==NULL)
{
file = fopen(name,"w");
StorageTableElem *t = new StorageTableElem();
for(int i=0;i<size;i++) fwrite(t,sizeof(*t),1,file);
fclose(file);
file = fopen(name,"r+");
seekpos=0;
}
else seekpos=seek;
}
StorageTable::~StorageTable()
{
fclose(file);
}
int StorageTable::AddRow(char* key, char* value)
{
StorageTableElem *tbl = new StorageTableElem();
int i;
if(file!=NULL)
{
fseek(file,seekpos,0);
for(i=0;i<size;i++)
{
fread(tbl,sizeof(*tbl),1,file);
if(!strcmp(tbl->key,key))
{
strcpy(tbl->value,value);
fseek(file,seekpos+i*sizeof(*tbl),0);
fwrite(tbl,sizeof(*tbl),1,file);
return 0;
}
}
fseek(file,seekpos,0);
for(i=0;i<size;i++)
{
fread(tbl,sizeof(*tbl),1,file);
if(*(tbl->key)==0)
{
strcpy(tbl->key,key);
strcpy(tbl->value,value);
fseek(file,seekpos+i*sizeof(*tbl),0);
fwrite(tbl,sizeof(*tbl),1,file);
return 0;
}
}
}
return 1;
}
int StorageTable::DelRow(char* key)
{
StorageTableElem *tbl = new StorageTableElem();
int i;
if(file!=NULL)
{
fseek(file,seekpos,0);
for(i=0;i<size;i++)
{
fread(tbl,(key_size+val_size),1,file);
if(!strcmp(tbl->key,key))
{
tbl->key[0]=0;
fseek(file,seekpos+i*(key_size+val_size),0);
fwrite(tbl,(key_size+val_size),1,file);
return 0;
}
}
}
return 1;
}
char* StorageTable::FindKeyValue(char* key, char* val)
{
StorageTableElem *tbl = new StorageTableElem();
int i;
if(file!=NULL)
{
fseek(file,seekpos,0);
for(i=0;i<size;i++)
{
fread(tbl,(key_size+val_size),1,file);
if(!strcmp(tbl->key,key))
{
strcpy(val,tbl->value);
return val;
}
}
}
return 0;
}
#include "Storages.h"
CycleJournal::CycleJournal()
CycleStorage::CycleStorage()
{
CycleJournalElem *jrn = new CycleJournalElem();
CycleStorageElem *jrn = new CycleStorageElem();
file = fopen("jrn", "r+");
size=100;
seekpos=0;
......@@ -152,7 +40,7 @@ CycleJournal::CycleJournal()
if(file==NULL)
{
file = fopen("jrn","w");
CycleJournalElem *t = new CycleJournalElem();
CycleStorageElem *t = new CycleStorageElem();
for(int i=0;i<100;i++) fwrite(t,sizeof(*t),1,file);
fclose(file);
file = fopen("jrn","r+");
......@@ -240,17 +128,17 @@ CycleJournal::CycleJournal()
}
}
CycleJournal::CycleJournal(const char* name, int sz, int seek)
CycleStorage::CycleStorage(const char* name, int sz, int seek)
{
CycleJournalElem *jrn = new CycleJournalElem();
CycleStorageElem *jrn = new CycleStorageElem();
file = fopen(name, "r+");
size=sz/sizeof(CycleJournalElem);
size=sz/sizeof(CycleStorageElem);
int l=-1,r=size,mid;
iter=0;
if(file==NULL)
{
file = fopen(name,"w");
CycleJournalElem *t = new CycleJournalElem();
CycleStorageElem *t = new CycleStorageElem();
for(int i=0;i<size;i++) fwrite(t,sizeof(*t),1,file);
fclose(file);
file = fopen(name,"r+");
......@@ -340,14 +228,14 @@ CycleJournal::CycleJournal(const char* name, int sz, int seek)
}
}
CycleJournal::~CycleJournal()
CycleStorage::~CycleStorage()
{
fclose(file);
}
int CycleJournal::AddRow(char* str)
int CycleStorage::AddRow(char* str)
{
CycleJournalElem *jrn = new CycleJournalElem();
CycleStorageElem *jrn = new CycleStorageElem();
int i;
if(file!=NULL)
{
......@@ -413,9 +301,9 @@ int CycleJournal::AddRow(char* str)
return 1;
}
int CycleJournal::DelRow(int row)
int CycleStorage::DelRow(int row)
{
CycleJournalElem *jrn = new CycleJournalElem();
CycleStorageElem *jrn = new CycleStorageElem();
int i=(head+row)%size,j;
if( row >= size ) return 1;
if(file!=NULL)
......@@ -439,9 +327,9 @@ int CycleJournal::DelRow(int row)
return 1;
}
int CycleJournal::DelAllRows()
int CycleStorage::DelAllRows()
{
CycleJournalElem *jrn = new CycleJournalElem();
CycleStorageElem *jrn = new CycleStorageElem();
int i;
if(file!=NULL)
{
......@@ -472,9 +360,9 @@ int CycleJournal::DelAllRows()
return 1;
}
int CycleJournal::ViewRows(int beg, int num)
int CycleStorage::ViewRows(int beg, int num)
{
CycleJournalElem *jrn = new CycleJournalElem();
CycleStorageElem *jrn = new CycleStorageElem();
int i,j=(head+beg)%size,n=num;
if(num==0) n=size;
if(num>size) n=size;
......
......@@ -10,7 +10,8 @@ libVarious_la_SOURCES = DebugStream.cc Debug.cc UniXML.cc MessageType.cc Config
NCRestorer.cc NCRestorer_XML.cc \
ISRestorer.cc ISRestorer_XML.cc \
RunLock.cc Mutex.cc SViewer.cc SMonitor.cc LT_Object.cc \
MessageInterface_XML.cc MessageInterface_idXML.cc WDTInterface.cc
MessageInterface_XML.cc MessageInterface_idXML.cc WDTInterface.cc \
CycleStorage.cc TableStorage.cc
include $(top_builddir)/conf/setting.mk
......
......@@ -65,7 +65,8 @@ am_libVarious_la_OBJECTS = libVarious_la-DebugStream.lo \
libVarious_la-SMonitor.lo libVarious_la-LT_Object.lo \
libVarious_la-MessageInterface_XML.lo \
libVarious_la-MessageInterface_idXML.lo \
libVarious_la-WDTInterface.lo
libVarious_la-WDTInterface.lo libVarious_la-CycleStorage.lo \
libVarious_la-TableStorage.lo
libVarious_la_OBJECTS = $(am_libVarious_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
......@@ -224,7 +225,8 @@ libVarious_la_SOURCES = DebugStream.cc Debug.cc UniXML.cc MessageType.cc Configu
NCRestorer.cc NCRestorer_XML.cc \
ISRestorer.cc ISRestorer_XML.cc \
RunLock.cc Mutex.cc SViewer.cc SMonitor.cc LT_Object.cc \
MessageInterface_XML.cc MessageInterface_idXML.cc WDTInterface.cc
MessageInterface_XML.cc MessageInterface_idXML.cc WDTInterface.cc \
CycleStorage.cc TableStorage.cc
all: all-am
......@@ -279,6 +281,7 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libVarious_la-Configuration.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libVarious_la-CycleStorage.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libVarious_la-Debug.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libVarious_la-DebugStream.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libVarious_la-ISRestorer.Plo@am__quote@
......@@ -295,6 +298,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libVarious_la-SMonitor.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libVarious_la-SViewer.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libVarious_la-SystemGuard.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libVarious_la-TableStorage.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libVarious_la-TextIndex.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libVarious_la-UniXML.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libVarious_la-WDTInterface.Plo@am__quote@
......@@ -460,6 +464,20 @@ libVarious_la-WDTInterface.lo: WDTInterface.cc
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libVarious_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libVarious_la-WDTInterface.lo `test -f 'WDTInterface.cc' || echo '$(srcdir)/'`WDTInterface.cc
libVarious_la-CycleStorage.lo: CycleStorage.cc
@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libVarious_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libVarious_la-CycleStorage.lo -MD -MP -MF $(DEPDIR)/libVarious_la-CycleStorage.Tpo -c -o libVarious_la-CycleStorage.lo `test -f 'CycleStorage.cc' || echo '$(srcdir)/'`CycleStorage.cc
@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/libVarious_la-CycleStorage.Tpo $(DEPDIR)/libVarious_la-CycleStorage.Plo
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='CycleStorage.cc' object='libVarious_la-CycleStorage.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libVarious_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libVarious_la-CycleStorage.lo `test -f 'CycleStorage.cc' || echo '$(srcdir)/'`CycleStorage.cc
libVarious_la-TableStorage.lo: TableStorage.cc
@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libVarious_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libVarious_la-TableStorage.lo -MD -MP -MF $(DEPDIR)/libVarious_la-TableStorage.Tpo -c -o libVarious_la-TableStorage.lo `test -f 'TableStorage.cc' || echo '$(srcdir)/'`TableStorage.cc
@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/libVarious_la-TableStorage.Tpo $(DEPDIR)/libVarious_la-TableStorage.Plo
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='TableStorage.cc' object='libVarious_la-TableStorage.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libVarious_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libVarious_la-TableStorage.lo `test -f 'TableStorage.cc' || echo '$(srcdir)/'`TableStorage.cc
mostlyclean-libtool:
-rm -f *.lo
......
/* This file is part of the UniSet project
* Copyright (c) 2009 Free Software Foundation, Inc.
* Copyright (c) 2009 Ivan Donchevskiy
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// --------------------------------------------------------------------------
/*! \file
* \author Ivan Donchevskiy
* \date $Date: 2009/07/14 16:59:00 $
* \version $Id: Jrn.h,v 1.0 2009/07/14 16:59:00 vpashka Exp $
*/
// --------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include "Storages.h"
TableStorage::TableStorage()
{
file = fopen("tbl", "r+");
if(file==NULL)
{
file = fopen("tbl","w");
TableStorageElem *t = new TableStorageElem();
for(int i=0;i<100;i++) fwrite(t,sizeof(*t),1,file);
fclose(file);
file = fopen("tbl","r+");
}
size=100;
seekpos=0;
}
TableStorage::TableStorage(const char* name, int sz, int seek)
{
file = fopen(name, "r+");
size=sz/sizeof(TableStorageElem);
if(file==NULL)
{
file = fopen(name,"w");
TableStorageElem *t = new TableStorageElem();
for(int i=0;i<size;i++) fwrite(t,sizeof(*t),1,file);
fclose(file);
file = fopen(name,"r+");
seekpos=0;
}
else seekpos=seek;
}
TableStorage::~TableStorage()
{
fclose(file);
}
int TableStorage::AddRow(char* key, char* value)
{
TableStorageElem *tbl = new TableStorageElem();
int i;
if(file!=NULL)
{
fseek(file,seekpos,0);
for(i=0;i<size;i++)
{
fread(tbl,sizeof(*tbl),1,file);
if(!strcmp(tbl->key,key))
{
strcpy(tbl->value,value);
fseek(file,seekpos+i*sizeof(*tbl),0);
fwrite(tbl,sizeof(*tbl),1,file);
return 0;
}
}
fseek(file,seekpos,0);
for(i=0;i<size;i++)
{
fread(tbl,sizeof(*tbl),1,file);
if(*(tbl->key)==0)
{
strcpy(tbl->key,key);
strcpy(tbl->value,value);
fseek(file,seekpos+i*sizeof(*tbl),0);
fwrite(tbl,sizeof(*tbl),1,file);
return 0;
}
}
}
return 1;
}
int TableStorage::DelRow(char* key)
{
TableStorageElem *tbl = new TableStorageElem();
int i;
if(file!=NULL)
{
fseek(file,seekpos,0);
for(i=0;i<size;i++)
{
fread(tbl,(key_size+val_size),1,file);
if(!strcmp(tbl->key,key))
{
tbl->key[0]=0;
fseek(file,seekpos+i*(key_size+val_size),0);
fwrite(tbl,(key_size+val_size),1,file);
return 0;
}
}
}
return 1;
}
char* TableStorage::FindKeyValue(char* key, char* val)
{
TableStorageElem *tbl = new TableStorageElem();
int i;
if(file!=NULL)
{
fseek(file,seekpos,0);
for(i=0;i<size;i++)
{
fread(tbl,(key_size+val_size),1,file);
if(!strcmp(tbl->key,key))
{
strcpy(val,tbl->value);
return val;
}
}
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment