Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
6dfe533b
Commit
6dfe533b
authored
Jul 17, 2009
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.eter:/people/yv/packages/uniset
parents
028d4e56
72839840
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
370 additions
and
251 deletions
+370
-251
JrnTest.cc
Utilities/JrnTests/JrnTest.cc
+104
-31
Storages.h
include/Storages.h
+11
-13
UniXML.h
include/UniXML.h
+2
-1
CycleStorage.cc
src/Various/CycleStorage.cc
+94
-155
TableStorage.cc
src/Various/TableStorage.cc
+159
-51
No files found.
Utilities/JrnTests/JrnTest.cc
View file @
6dfe533b
/* This file is part of the UniSet project
/* This file is part of the UniSet project
* Copyright (c) 200
2
Free Software Foundation, Inc.
* Copyright (c) 200
9
Free Software Foundation, Inc.
* Copyright (c) 200
2
Ivan Donchevskiy
* Copyright (c) 200
9
Ivan Donchevskiy
*
*
* This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by
...
@@ -19,14 +19,17 @@
...
@@ -19,14 +19,17 @@
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
/*! \file
/*! \file
* \author Ivan Donchevskiy
* \author Ivan Donchevskiy
* \date $Date: 2009/07/1
4 16:59
:00 $
* \date $Date: 2009/07/1
5 15:55
:00 $
* \version $Id: Jrn.h,v 1.0 2009/07/1
4 16:59
:00 vpashka Exp $
* \version $Id: Jrn.h,v 1.0 2009/07/1
5 15:55
:00 vpashka Exp $
*/
*/
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#include "stdio.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "string.h"
#include "Storages.h"
#include "Storages.h"
#include "UniXML.h"
char
*
itoa
(
int
val
,
int
base
)
char
*
itoa
(
int
val
,
int
base
)
{
{
...
@@ -46,35 +49,45 @@ char* itoa(int val, int base)
...
@@ -46,35 +49,45 @@ char* itoa(int val, int base)
void
testTable
(
void
)
void
testTable
(
void
)
{
{
char
*
chr
=
new
char
[
2
]
;
char
*
chr
=
(
char
*
)
malloc
(
20
)
;
char
*
val
=
new
char
[
2
]
;
char
*
val
=
(
char
*
)
malloc
(
40
)
;
TableStorage
*
t
;
TableStorage
*
t
;
t
=
new
TableStorage
(
"table.test"
,
600
0
,
0
);
t
=
new
TableStorage
(
"table.test"
,
40
,
122
0
,
0
);
int
i
;
int
i
;
printf
(
"testTable
\n
size = %d
\n
"
,
t
->
size
);
printf
(
"testTable
\n
size = %d
\n
"
,
t
->
size
);
for
(
i
=
0
;
i
<
t
->
size
+
5
;
i
++
)
for
(
i
=
0
;
i
<
t
->
size
;
i
++
)
{
{
chr
[
0
]
=
i
%
256
;
chr
[
0
]
=
i
;
if
(
t
->
AddRow
(
chr
,
chr
)
==
1
)
printf
(
"elem number %d - no space in TableStorage
\n
"
,
i
);
val
=
itoa
(
i
,
10
);
t
->
AddRow
(
chr
,
val
);
}
}
printf
(
"elements with values=keys added
\n
"
);
//printf("elements with values=keys added\nvalues from keys 25-59\n");
for
(
i
=
40
;
i
<
60
;
i
++
)
printf
(
"elements with values=keys added:
\n
"
);
for
(
i
=
0
;
i
<
40
;
i
++
)
{
{
chr
[
0
]
=
i
%
256
;
chr
[
0
]
=
i
;
if
(
t
->
FindKeyValue
(
chr
,
val
)
!=
0
)
printf
(
"%s, "
,
val
);
}
printf
(
"
\n
"
);
for
(
i
=
9
;
i
<
15
;
i
++
)
{
chr
[
0
]
=
i
;
t
->
DelRow
(
chr
);
t
->
DelRow
(
chr
);
}
}
printf
(
"elements with keys from 40 to 60 deleted
\n
"
);
//printf("elements with keys from 40 to 60 deleted\n");
for
(
i
=
30
;
i
<
50
;
i
++
)
printf
(
"elements with keys from 9 to 14 deleted
\n
"
);
for
(
i
=
9
;
i
<
15
;
i
++
)
{
{
chr
[
0
]
=
i
;
chr
[
0
]
=
i
;
val
[
0
]
=
i
+
40
;
val
=
itoa
(
i
+
40
,
10
)
;
t
->
AddRow
(
chr
,
val
);
t
->
AddRow
(
chr
,
val
);
}
}
printf
(
"elements with keys from 30 to 50 with values=key+40 added
\n
values from keys 25-59
\n
"
);
//printf("elements with keys from 30 to 50 with values=key+40 added\nvalues from keys 25-59\n");
for
(
i
=
25
;
i
<
60
;
i
++
)
printf
(
"elements with keys from 9 to 14 with values=key+40 added, all elements:
\n
"
);
for
(
i
=
0
;
i
<
40
;
i
++
)
{
{
chr
[
0
]
=
i
;
chr
[
0
]
=
i
;
if
(
t
->
FindKeyValue
(
chr
,
val
)
!=
0
)
printf
(
"%
d, "
,
val
[
0
]
);
if
(
t
->
FindKeyValue
(
chr
,
val
)
!=
0
)
printf
(
"%
s, "
,
val
);
}
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
...
@@ -83,11 +96,11 @@ void testJournal1(void)
...
@@ -83,11 +96,11 @@ void testJournal1(void)
{
{
CycleStorage
*
j
;
CycleStorage
*
j
;
int
i
;
int
i
;
char
*
str
=
new
char
[
6
]
;
char
*
str
=
(
char
*
)
malloc
(
30
)
;
printf
(
"journal test 1
\n
"
);
printf
(
"journal test 1
\n
"
);
j
=
new
CycleStorage
(
"journal.test"
,
2
000000
,
0
);
j
=
new
CycleStorage
(
"journal.test"
,
30
,
1
000000
,
0
);
printf
(
"size = %d
\n
"
,
j
->
size
);
printf
(
"size = %d
\n
"
,
j
->
size
);
for
(
i
=
1
;
i
<
3
0000
;
i
++
)
for
(
i
=
1
;
i
<
4
0000
;
i
++
)
{
{
str
=
itoa
(
i
,
10
);
str
=
itoa
(
i
,
10
);
j
->
AddRow
(
str
);
j
->
AddRow
(
str
);
...
@@ -108,42 +121,102 @@ void testJournal1(void)
...
@@ -108,42 +121,102 @@ void testJournal1(void)
}
}
j
->
ViewRows
(
0
,
20
);
j
->
ViewRows
(
0
,
20
);
printf
(
"
\n
the same after reopen:
\n
"
);
printf
(
"
\n
the same after reopen:
\n
"
);
delete
j
;
j
=
new
CycleStorage
(
"journal.test"
,
30
,
2000000
,
0
);
j
=
new
CycleStorage
(
"journal.test"
,
2000000
,
0
);
j
->
ViewRows
(
0
,
20
);
j
->
ViewRows
(
0
,
20
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
j
->
ExportToXML
(
"Xml.xml"
);
}
}
void
testJournal2
(
void
)
void
testJournal2
(
void
)
{
{
CycleStorage
*
j
;
CycleStorage
*
j
;
int
i
,
k
;
int
i
,
k
;
char
*
str
=
new
char
[
4
]
;
char
*
str
=
(
char
*
)
malloc
(
30
)
;
j
=
new
CycleStorage
(
"journal.test"
,
2
000000
,
0
);
j
=
new
CycleStorage
(
"journal.test"
,
30
,
1
000000
,
0
);
printf
(
"journal test 2 - checking number of iterations to find head/tail
\n
"
);
printf
(
"journal test 2 - checking number of iterations to find head/tail
\n
"
);
printf
(
"size = %d
\n\n
"
,
j
->
size
);
printf
(
"size = %d
\n\n
"
,
j
->
size
);
printf
(
"iterations = %d
\n
"
,
j
->
iter
);
printf
(
"iterations = %d
\n
"
,
j
->
iter
);
for
(
i
=
0
;
i
<
20
;
i
++
)
for
(
i
=
0
;
i
<
20
;
i
++
)
{
{
for
(
k
=
0
;
k
<
1
000
;
k
++
)
for
(
k
=
1000
;
k
<
3
000
;
k
++
)
{
{
str
=
itoa
(
k
,
10
);
str
=
itoa
(
k
,
10
);
j
->
AddRow
(
str
);
j
->
AddRow
(
str
);
}
}
delete
j
;
j
=
new
CycleStorage
(
"journal.test"
,
30
,
2000000
,
0
);
j
=
new
CycleStorage
(
"journal.test"
,
2000000
,
0
);
printf
(
"iterations = %d
\n
"
,
j
->
iter
);
printf
(
"iterations = %d
\n
"
,
j
->
iter
);
}
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
int
main
(
void
)
int
main
(
int
args
,
char
**
argv
)
{
{
/*if(args<2)
{
printf("Correct usage: jrntest File_name\n");
return 0;
}
CycleStorage *j = new CycleStorage(argv[1],99,1000,0);
printf("commands:\nadd\ndelete\nview\ntoxml\ndel_all\nenter q or quit to exit\n\n");
char* com=new char[8];
char* str=new char[99];
int num,count;
strcpy(com,"qwerty");
while(strcmp(com,"q")&&strcmp(com,"quit"))
{
scanf("%s",com);
if(!strcmp(com,"add"))
{
printf("string to add: ");
if(scanf("%99s",str)>0)
{
j->AddRow(str);
printf("\n");
}
}
else if(!strcmp(com,"delete"))
{
printf("number of string to delete: ");
if(scanf("%d",&num)>0)
{
j->DelRow(num);
printf("\n");
}
}
else if(!strcmp(com,"view"))
{
printf("start number and count (0 0 for all): ");
if(scanf("%d%d",&num,&count)>1)
{
j->ViewRows(num,count);
printf("\n");
}
}
else if(!strcmp(com,"del_all"))
{
printf("are you sure? (y/n) ");
if(scanf("%s",str)>0)
if(!strcmp(str,"y"))
{
j->DelAllRows();
printf("\n");
}
}
else if(!strcmp(com,"toxml"))
{
printf("enter file name: ");
if(scanf("%25s",str)>0)
{
j->ExportToXML(str);
printf("\n");
}
}
else printf("commands:\nadd\ndelete\nview\ntoxml\ndel_all\nenter q or quit to exit\n\n");
}*/
testTable
();
testTable
();
testJournal1
();
testJournal1
();
testJournal2
();
testJournal2
();
return
0
;
return
0
;
...
...
include/Storages.h
View file @
6dfe533b
...
@@ -19,8 +19,8 @@
...
@@ -19,8 +19,8 @@
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
/*! \file
/*! \file
* \author Ivan Donchevskiy
* \author Ivan Donchevskiy
* \date $Date: 2009/07/1
4 16:59
:00 $
* \date $Date: 2009/07/1
5 15:55
:00 $
* \version $Id: Jrn.h,v 1.0 2009/07/1
4 16:59
:00 vpashka Exp $
* \version $Id: Jrn.h,v 1.0 2009/07/1
5 15:55
:00 vpashka Exp $
*/
*/
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
...
@@ -29,31 +29,29 @@
...
@@ -29,31 +29,29 @@
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <UniXML.h>
#define str_size 80
#define key_size 20
#define key_size 20
#define val_size 40
struct
TableStorageElem
struct
TableStorageElem
{
{
char
status
;
char
key
[
key_size
];
char
key
[
key_size
];
char
value
[
val_size
];
}
__attribute__
((
__packed__
));
}
__attribute__
((
__packed__
));
struct
CycleStorageElem
struct
CycleStorageElem
{
{
char
str
[
str_size
];
char
status
;
int
status
;
}
__attribute__
((
__packed__
));
}
__attribute__
((
__packed__
));
class
TableStorage
class
TableStorage
{
{
FILE
*
file
;
FILE
*
file
;
int
seekpos
;
int
seekpos
,
inf_size
;
int
head
;
public
:
public
:
int
size
;
int
size
;
TableStorage
();
TableStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
);
TableStorage
(
const
char
*
name
,
int
sz
,
int
seek
);
~
TableStorage
();
~
TableStorage
();
int
AddRow
(
char
*
key
,
char
*
val
);
int
AddRow
(
char
*
key
,
char
*
val
);
int
DelRow
(
char
*
key
);
int
DelRow
(
char
*
key
);
...
@@ -63,17 +61,17 @@ class TableStorage
...
@@ -63,17 +61,17 @@ class TableStorage
class
CycleStorage
class
CycleStorage
{
{
FILE
*
file
;
FILE
*
file
;
int
seekpos
;
int
seekpos
,
inf_size
;
int
head
,
tail
;
int
head
,
tail
;
public
:
public
:
int
size
,
iter
;
int
size
,
iter
;
CycleStorage
();
CycleStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
);
CycleStorage
(
const
char
*
name
,
int
sz
,
int
seek
);
~
CycleStorage
();
~
CycleStorage
();
int
AddRow
(
char
*
str
);
int
AddRow
(
char
*
str
);
int
DelRow
(
int
row
);
int
DelRow
(
int
row
);
int
DelAllRows
(
void
);
int
DelAllRows
(
void
);
int
ViewRows
(
int
beg
,
int
num
);
int
ViewRows
(
int
beg
,
int
num
);
int
ExportToXML
(
const
char
*
name
);
};
};
#endif
#endif
include/UniXML.h
View file @
6dfe533b
...
@@ -75,9 +75,10 @@ public:
...
@@ -75,9 +75,10 @@ public:
// , .
// , .
static
const
xmlChar
*
local2xml
(
std
::
string
text
);
static
const
xmlChar
*
local2xml
(
std
::
string
text
);
//
name node
//
XML-
void
newDoc
(
const
std
::
string
&
root_node
,
std
::
string
xml_ver
=
"1.0"
);
void
newDoc
(
const
std
::
string
&
root_node
,
std
::
string
xml_ver
=
"1.0"
);
// name node
static
std
::
string
getProp
(
xmlNode
*
node
,
const
std
::
string
name
);
static
std
::
string
getProp
(
xmlNode
*
node
,
const
std
::
string
name
);
// name node
// name node
...
...
src/Various/CycleStorage.cc
View file @
6dfe533b
/* This file is part of the UniSet project
/* This file is part of the UniSet project
* Copyright (c) 200
2
Free Software Foundation, Inc.
* Copyright (c) 200
9
Free Software Foundation, Inc.
* Copyright (c) 200
2
Ivan Donchevskiy
* Copyright (c) 200
9
Ivan Donchevskiy
*
*
* This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by
...
@@ -19,127 +19,30 @@
...
@@ -19,127 +19,30 @@
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
/*! \file
/*! \file
* \author Ivan Donchevskiy
* \author Ivan Donchevskiy
* \date $Date: 2009/07/1
4 16:59
:00 $
* \date $Date: 2009/07/1
5 15:55
:00 $
* \version $Id: Jrn.h,v 1.0 2009/07/1
4 16:59
:00 vpashka Exp $
* \version $Id: Jrn.h,v 1.0 2009/07/1
5 15:55
:00 vpashka Exp $
*/
*/
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include "Storages.h"
#include "Storages.h"
CycleStorage
::
CycleStorage
()
{
CycleStorageElem
*
jrn
=
new
CycleStorageElem
();
file
=
fopen
(
"jrn"
,
"r+"
);
size
=
100
;
seekpos
=
0
;
int
l
=-
1
,
r
=
size
,
mid
;
iter
=
0
;
if
(
file
==
NULL
)
{
file
=
fopen
(
"jrn"
,
"w"
);
CycleStorageElem
*
t
=
new
CycleStorageElem
();
for
(
int
i
=
0
;
i
<
100
;
i
++
)
fwrite
(
t
,
sizeof
(
*
t
),
1
,
file
);
fclose
(
file
);
file
=
fopen
(
"jrn"
,
"r+"
);
head
=-
1
;
tail
=-
1
;
}
else
{
fseek
(
file
,
seekpos
,
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
if
(
jrn
->
status
==
0
)
{
head
=-
1
;
tail
=-
1
;
}
else
if
((
jrn
->
status
==
1
)
||
(
jrn
->
status
==
6
))
{
head
=
0
;
while
(
r
-
l
>
1
)
{
mid
=
(
l
+
r
)
/
2
;
fseek
(
file
,
seekpos
+
mid
*
sizeof
(
*
jrn
),
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
iter
++
;
if
(
jrn
->
status
==
0
)
r
=
mid
;
else
l
=
mid
;
}
if
(
r
<
size
)
{
fseek
(
file
,
seekpos
+
r
*
sizeof
(
*
jrn
),
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
tail
=
r
-
1
;
}
else
tail
=
size
-
1
;
}
else
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
{
while
((
jrn
->
status
!=
1
)
&&
(
jrn
->
status
!=
6
)
&&
(
r
-
l
>
1
))
{
mid
=
(
l
+
r
)
/
2
;
fseek
(
file
,
seekpos
+
mid
*
sizeof
(
*
jrn
),
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
iter
++
;
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
l
=
mid
;
else
if
((
jrn
->
status
==
4
)
||
(
jrn
->
status
==
5
))
r
=
mid
;
else
{
r
=
mid
;
break
;
}
}
if
(
r
<
size
)
head
=
r
;
else
head
=
size
-
1
;
tail
=
head
-
1
;
if
(
tail
<
0
)
tail
=
size
-
1
;
}
else
{
while
((
jrn
->
status
!=
1
)
&&
(
jrn
->
status
!=
6
)
&&
(
r
-
l
>
1
))
{
mid
=
(
l
+
r
)
/
2
;
fseek
(
file
,
seekpos
+
mid
*
sizeof
(
*
jrn
),
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
iter
++
;
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
r
=
mid
;
else
if
((
jrn
->
status
==
4
)
||
(
jrn
->
status
==
5
))
l
=
mid
;
else
{
r
=
mid
;
break
;
}
}
if
(
r
<
size
)
head
=
r
;
else
head
=
size
-
1
;
tail
=
head
-
1
;
if
(
tail
<
0
)
tail
=
size
-
1
;
}
}
}
CycleStorage
::
CycleStorage
(
const
char
*
name
,
int
sz
,
int
seek
)
CycleStorage
::
CycleStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
)
{
{
CycleStorageElem
*
jrn
=
new
CycleStorageElem
(
);
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
malloc
(
sizeof
(
CycleStorageElem
)
+
inf_sz
);
file
=
fopen
(
name
,
"r+"
);
file
=
fopen
(
name
,
"r+"
);
size
=
sz
/
sizeof
(
CycleStorageElem
);
size
=
sz
/
(
sizeof
(
CycleStorageElem
)
+
inf_sz
);
int
l
=-
1
,
r
=
size
,
mid
;
int
l
=-
1
,
r
=
size
,
mid
;
iter
=
0
;
iter
=
0
;
inf_size
=
inf_sz
;
if
(
file
==
NULL
)
if
(
file
==
NULL
)
{
{
file
=
fopen
(
name
,
"w"
);
file
=
fopen
(
name
,
"w"
);
CycleStorageElem
*
t
=
new
CycleStorageElem
();
for
(
int
i
=
0
;
i
<
size
;
i
++
)
fwrite
(
jrn
,(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
fwrite
(
t
,
sizeof
(
*
t
),
1
,
file
);
fclose
(
file
);
fclose
(
file
);
file
=
fopen
(
name
,
"r+"
);
file
=
fopen
(
name
,
"r+"
);
seekpos
=
0
;
seekpos
=
0
;
...
@@ -150,7 +53,7 @@ CycleStorage::CycleStorage(const char* name, int sz, int seek)
...
@@ -150,7 +53,7 @@ CycleStorage::CycleStorage(const char* name, int sz, int seek)
{
{
seekpos
=
seek
;
seekpos
=
seek
;
fseek
(
file
,
seekpos
,
0
);
fseek
(
file
,
seekpos
,
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
if
(
jrn
->
status
==
0
)
if
(
jrn
->
status
==
0
)
{
{
head
=-
1
;
head
=-
1
;
...
@@ -162,8 +65,8 @@ CycleStorage::CycleStorage(const char* name, int sz, int seek)
...
@@ -162,8 +65,8 @@ CycleStorage::CycleStorage(const char* name, int sz, int seek)
while
(
r
-
l
>
1
)
while
(
r
-
l
>
1
)
{
{
mid
=
(
l
+
r
)
/
2
;
mid
=
(
l
+
r
)
/
2
;
fseek
(
file
,
seekpos
+
mid
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
mid
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
iter
++
;
iter
++
;
if
(
jrn
->
status
==
0
)
if
(
jrn
->
status
==
0
)
r
=
mid
;
r
=
mid
;
...
@@ -171,8 +74,8 @@ CycleStorage::CycleStorage(const char* name, int sz, int seek)
...
@@ -171,8 +74,8 @@ CycleStorage::CycleStorage(const char* name, int sz, int seek)
}
}
if
(
r
<
size
)
if
(
r
<
size
)
{
{
fseek
(
file
,
seekpos
+
r
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
r
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
tail
=
r
-
1
;
tail
=
r
-
1
;
}
}
else
tail
=
size
-
1
;
else
tail
=
size
-
1
;
...
@@ -182,8 +85,8 @@ CycleStorage::CycleStorage(const char* name, int sz, int seek)
...
@@ -182,8 +85,8 @@ CycleStorage::CycleStorage(const char* name, int sz, int seek)
while
((
jrn
->
status
!=
1
)
&&
(
jrn
->
status
!=
6
)
&&
(
r
-
l
>
1
))
while
((
jrn
->
status
!=
1
)
&&
(
jrn
->
status
!=
6
)
&&
(
r
-
l
>
1
))
{
{
mid
=
(
l
+
r
)
/
2
;
mid
=
(
l
+
r
)
/
2
;
fseek
(
file
,
seekpos
+
mid
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
mid
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
iter
++
;
iter
++
;
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
l
=
mid
;
l
=
mid
;
...
@@ -206,8 +109,8 @@ CycleStorage::CycleStorage(const char* name, int sz, int seek)
...
@@ -206,8 +109,8 @@ CycleStorage::CycleStorage(const char* name, int sz, int seek)
while
((
jrn
->
status
!=
1
)
&&
(
jrn
->
status
!=
6
)
&&
(
r
-
l
>
1
))
while
((
jrn
->
status
!=
1
)
&&
(
jrn
->
status
!=
6
)
&&
(
r
-
l
>
1
))
{
{
mid
=
(
l
+
r
)
/
2
;
mid
=
(
l
+
r
)
/
2
;
fseek
(
file
,
seekpos
+
mid
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
mid
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
iter
++
;
iter
++
;
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
r
=
mid
;
r
=
mid
;
...
@@ -235,31 +138,33 @@ CycleStorage::~CycleStorage()
...
@@ -235,31 +138,33 @@ CycleStorage::~CycleStorage()
int
CycleStorage
::
AddRow
(
char
*
str
)
int
CycleStorage
::
AddRow
(
char
*
str
)
{
{
CycleStorageElem
*
jrn
=
new
CycleStorageElem
(
);
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
malloc
(
sizeof
(
CycleStorageElem
)
+
inf_size
);
int
i
;
int
i
,
k
;
if
(
file
!=
NULL
)
if
(
file
!=
NULL
)
{
{
if
(
head
==-
1
)
if
(
head
==-
1
)
{
{
fseek
(
file
,
seekpos
,
0
);
fseek
(
file
,
seekpos
,
0
);
strcpy
(
jrn
->
str
,
str
);
for
(
k
=
0
;
k
<
inf_size
;
k
++
)
*
((
char
*
)(
jrn
)
+
sizeof
(
CycleStorageElem
)
+
k
)
=*
(
str
+
k
);
jrn
->
status
=
1
;
jrn
->
status
=
1
;
fwrite
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fwrite
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
head
=
0
;
head
=
0
;
tail
=
0
;
tail
=
0
;
return
0
;
return
0
;
}
}
if
(
head
==
tail
)
if
(
head
==
tail
)
{
{
fseek
(
file
,
seekpos
+
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
strcpy
(
jrn
->
str
,
str
);
for
(
k
=
0
;
k
<
inf_size
;
k
++
)
*
((
char
*
)(
jrn
)
+
sizeof
(
CycleStorageElem
)
+
k
)
=*
(
str
+
k
);
jrn
->
status
=
2
;
jrn
->
status
=
2
;
fwrite
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fwrite
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
tail
=
1
;
tail
=
1
;
return
0
;
return
0
;
}
}
fseek
(
file
,
seekpos
+
tail
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
tail
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
if
((
jrn
->
status
==
2
)
||
(
jrn
->
status
==
3
))
i
=
2
;
i
=
2
;
else
i
=
4
;
else
i
=
4
;
...
@@ -271,30 +176,32 @@ int CycleStorage::AddRow(char* str)
...
@@ -271,30 +176,32 @@ int CycleStorage::AddRow(char* str)
else
i
=
2
;
else
i
=
2
;
}
}
else
tail
++
;
else
tail
++
;
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
if
(
jrn
->
status
==
0
)
if
(
jrn
->
status
==
0
)
{
{
fseek
(
file
,
seekpos
+
tail
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
tail
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
strcpy
(
jrn
->
str
,
str
);
for
(
k
=
0
;
k
<
inf_size
;
k
++
)
*
((
char
*
)(
jrn
)
+
sizeof
(
CycleStorageElem
)
+
k
)
=*
(
str
+
k
);
jrn
->
status
=
2
;
jrn
->
status
=
2
;
fwrite
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fwrite
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
return
0
;
return
0
;
}
}
else
else
{
{
head
++
;
head
++
;
if
(
head
>=
size
)
head
=
0
;
if
(
head
>=
size
)
head
=
0
;
fseek
(
file
,
seekpos
+
tail
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
tail
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
strcpy
(
jrn
->
str
,
str
);
for
(
k
=
0
;
k
<
inf_size
;
k
++
)
*
((
char
*
)(
jrn
)
+
sizeof
(
CycleStorageElem
)
+
k
)
=*
(
str
+
k
);
jrn
->
status
=
i
;
jrn
->
status
=
i
;
if
(
tail
==
0
)
fseek
(
file
,
seekpos
,
0
);
if
(
tail
==
0
)
fseek
(
file
,
seekpos
,
0
);
fwrite
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fwrite
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
fseek
(
file
,
seekpos
+
head
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
head
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
if
((
jrn
->
status
==
3
)
||
(
jrn
->
status
==
5
))
jrn
->
status
=
6
;
if
((
jrn
->
status
==
3
)
||
(
jrn
->
status
==
5
))
jrn
->
status
=
6
;
else
jrn
->
status
=
1
;
else
jrn
->
status
=
1
;
fseek
(
file
,
seekpos
+
head
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
head
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fwrite
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fwrite
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
return
0
;
return
0
;
}
}
}
}
...
@@ -303,33 +210,33 @@ int CycleStorage::AddRow(char* str)
...
@@ -303,33 +210,33 @@ int CycleStorage::AddRow(char* str)
int
CycleStorage
::
DelRow
(
int
row
)
int
CycleStorage
::
DelRow
(
int
row
)
{
{
CycleStorageElem
*
jrn
=
new
CycleStorageElem
();
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
malloc
(
sizeof
(
CycleStorageElem
)
+
inf_size
);
int
i
=
(
head
+
row
)
%
size
,
j
;
int
i
=
(
head
+
row
)
%
size
,
j
;
if
(
row
>=
size
)
return
1
;
if
(
row
>=
size
)
return
1
;
if
(
file
!=
NULL
)
if
(
file
!=
NULL
)
{
{
fseek
(
file
,
seekpos
+
i
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
i
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
if
(
jrn
->
status
==
1
)
if
(
jrn
->
status
==
1
)
{
{
jrn
->
status
=
6
;
jrn
->
status
=
6
;
fseek
(
file
,
seekpos
+
i
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
i
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fwrite
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fwrite
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
return
0
;
return
0
;
}
}
if
(
jrn
->
status
==
2
)
j
=
3
;
if
(
jrn
->
status
==
2
)
j
=
3
;
else
if
(
jrn
->
status
==
4
)
j
=
5
;
else
if
(
jrn
->
status
==
4
)
j
=
5
;
else
return
1
;
else
return
1
;
fseek
(
file
,
seekpos
+
i
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
i
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
jrn
->
status
=
j
;
jrn
->
status
=
j
;
fwrite
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fwrite
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
}
}
return
1
;
return
1
;
}
}
int
CycleStorage
::
DelAllRows
()
int
CycleStorage
::
DelAllRows
()
{
{
CycleStorageElem
*
jrn
=
new
CycleStorageElem
();
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
malloc
(
sizeof
(
CycleStorageElem
)
+
inf_size
);
int
i
;
int
i
;
if
(
file
!=
NULL
)
if
(
file
!=
NULL
)
{
{
...
@@ -339,36 +246,37 @@ int CycleStorage::DelAllRows()
...
@@ -339,36 +246,37 @@ int CycleStorage::DelAllRows()
i
=
1
;
i
=
1
;
while
(
i
!=
0
)
while
(
i
!=
0
)
{
{
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
jrn
->
status
=
0
;
jrn
->
status
=
0
;
fseek
(
file
,
seekpos
+
i
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
i
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fwrite
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fwrite
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
i
=
jrn
->
status
;
i
=
jrn
->
status
;
}
}
}
}
for
(
i
=
0
;
i
<
size
;
i
++
)
for
(
i
=
0
;
i
<
size
;
i
++
)
{
{
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
if
(
jrn
->
status
!=
0
)
if
(
jrn
->
status
!=
0
)
{
{
jrn
->
status
=
0
;
jrn
->
status
=
0
;
fseek
(
file
,
seekpos
+
i
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
i
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
fwrite
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fwrite
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
}
}
}
}
head
=
tail
=-
1
;
}
}
return
1
;
return
1
;
}
}
int
CycleStorage
::
ViewRows
(
int
beg
,
int
num
)
int
CycleStorage
::
ViewRows
(
int
beg
,
int
num
)
{
{
CycleStorageElem
*
jrn
=
new
CycleStorageElem
();
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
malloc
(
sizeof
(
CycleStorageElem
)
+
inf_size
);
int
i
,
j
=
(
head
+
beg
)
%
size
,
n
=
num
;
int
i
,
j
=
(
head
+
beg
)
%
size
,
n
=
num
,
k
;
if
(
num
==
0
)
n
=
size
;
if
(
num
==
0
)
n
=
size
;
if
(
num
>
size
)
n
=
size
;
if
(
num
>
size
)
n
=
size
;
if
(
file
!=
NULL
)
if
(
file
!=
NULL
)
{
{
fseek
(
file
,
seekpos
+
j
*
sizeof
(
*
jrn
),
0
);
fseek
(
file
,
seekpos
+
j
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
for
(
i
=
0
;
i
<
n
;
i
++
)
for
(
i
=
0
;
i
<
n
;
i
++
)
{
{
if
(
j
==
size
)
if
(
j
==
size
)
...
@@ -376,10 +284,12 @@ int CycleStorage::ViewRows(int beg, int num)
...
@@ -376,10 +284,12 @@ int CycleStorage::ViewRows(int beg, int num)
j
=
0
;
j
=
0
;
fseek
(
file
,
seekpos
,
0
);
fseek
(
file
,
seekpos
,
0
);
}
}
fread
(
jrn
,
sizeof
(
*
jrn
),
1
,
file
);
fread
(
jrn
,
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
if
((
jrn
->
status
!=
0
)
&&
(
jrn
->
status
!=
3
)
&&
(
jrn
->
status
!=
5
)
&&
(
jrn
->
status
!=
6
))
if
((
jrn
->
status
!=
0
)
&&
(
jrn
->
status
!=
3
)
&&
(
jrn
->
status
!=
5
)
&&
(
jrn
->
status
!=
6
))
{
{
printf
(
"%s
\n
"
,
jrn
->
str
);
for
(
k
=
0
;
k
<
inf_size
;
k
++
)
printf
(
"%c"
,((
char
*
)(
jrn
)
+
sizeof
(
CycleStorageElem
))[
k
]);
printf
(
"
\n
"
);
}
}
j
++
;
j
++
;
}
}
...
@@ -388,3 +298,31 @@ int CycleStorage::ViewRows(int beg, int num)
...
@@ -388,3 +298,31 @@ int CycleStorage::ViewRows(int beg, int num)
return
1
;
return
1
;
}
}
int
CycleStorage
::
ExportToXML
(
const
char
*
name
)
{
CycleStorageElem
*
jrn
=
(
CycleStorageElem
*
)
malloc
(
sizeof
(
CycleStorageElem
)
+
inf_size
);
int
i
,
j
=
head
;
if
(
file
!=
NULL
)
{
UniXML
*
f
=
new
UniXML
();
f
->
newDoc
(
"!"
);
fseek
(
file
,
seekpos
+
j
*
(
sizeof
(
CycleStorageElem
)
+
inf_size
),
0
);
for
(
i
=
0
;
i
<
size
;
i
++
)
{
if
(
j
==
size
)
{
j
=
0
;
fseek
(
file
,
seekpos
,
0
);
}
fread
(
jrn
,(
sizeof
(
CycleStorageElem
)
+
inf_size
),
1
,
file
);
if
((
jrn
->
status
!=
0
)
&&
(
jrn
->
status
!=
3
)
&&
(
jrn
->
status
!=
5
)
&&
(
jrn
->
status
!=
6
))
{
f
->
createNext
(
f
->
cur
,
"!"
,((
char
*
)(
jrn
)
+
sizeof
(
CycleStorageElem
)));
}
j
++
;
}
f
->
save
(
name
);
return
0
;
}
return
1
;
}
\ No newline at end of file
src/Various/TableStorage.cc
View file @
6dfe533b
...
@@ -19,45 +19,90 @@
...
@@ -19,45 +19,90 @@
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
/*! \file
/*! \file
* \author Ivan Donchevskiy
* \author Ivan Donchevskiy
* \date $Date: 2009/07/1
4 16:59
:00 $
* \date $Date: 2009/07/1
5 15:55
:00 $
* \version $Id: Jrn.h,v 1.0 2009/07/1
4 16:59:00
vpashka Exp $
* \version $Id: Jrn.h,v 1.0 2009/07/1
5 15:55:00
vpashka Exp $
*/
*/
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include "Storages.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
)
TableStorage
::
TableStorage
(
const
char
*
name
,
int
inf_sz
,
int
sz
,
int
seek
)
{
{
file
=
fopen
(
name
,
"r+"
);
file
=
fopen
(
name
,
"r+"
);
size
=
sz
/
sizeof
(
TableStorageElem
);
inf_size
=
inf_sz
;
int
l
=-
1
,
r
=
size
,
mid
;
size
=
sz
/
(
sizeof
(
TableStorageElem
)
+
inf_size
);
TableStorageElem
*
t
=
(
TableStorageElem
*
)
malloc
(
sizeof
(
TableStorageElem
)
+
inf_size
);
if
(
file
==
NULL
)
if
(
file
==
NULL
)
{
{
file
=
fopen
(
name
,
"w"
);
file
=
fopen
(
name
,
"w"
);
TableStorageElem
*
t
=
new
TableStorageElem
();
for
(
int
i
=
0
;
i
<
size
;
i
++
)
fwrite
(
t
,(
sizeof
(
TableStorageElem
)
+
inf_size
),
1
,
file
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
fwrite
(
t
,
sizeof
(
*
t
),
1
,
file
);
fclose
(
file
);
fclose
(
file
);
file
=
fopen
(
name
,
"r+"
);
file
=
fopen
(
name
,
"r+"
);
seekpos
=
0
;
seekpos
=
0
;
head
=-
1
;
}
else
{
seekpos
=
seek
;
fseek
(
file
,
seekpos
,
0
);
fread
(
t
,(
sizeof
(
TableStorageElem
)
+
inf_size
),
1
,
file
);
if
(
t
->
status
==
0
)
{
head
=-
1
;
}
else
if
((
t
->
status
==
1
)
||
(
t
->
status
==
6
))
{
head
=
0
;
}
else
if
((
t
->
status
==
2
)
||
(
t
->
status
==
3
))
{
while
((
t
->
status
!=
1
)
&&
(
t
->
status
!=
6
)
&&
(
r
-
l
>
1
))
{
mid
=
(
l
+
r
)
/
2
;
fseek
(
file
,
seekpos
+
mid
*
(
sizeof
(
TableStorageElem
)
+
inf_size
),
0
);
fread
(
t
,(
sizeof
(
TableStorageElem
)
+
inf_size
),
1
,
file
);
if
((
t
->
status
==
2
)
||
(
t
->
status
==
3
))
l
=
mid
;
else
if
((
t
->
status
==
4
)
||
(
t
->
status
==
5
))
r
=
mid
;
else
{
r
=
mid
;
break
;
}
}
if
(
r
<
size
)
head
=
r
;
else
head
=
size
-
1
;
}
else
{
while
((
t
->
status
!=
1
)
&&
(
t
->
status
!=
6
)
&&
(
r
-
l
>
1
))
{
mid
=
(
l
+
r
)
/
2
;
fseek
(
file
,
seekpos
+
mid
*
(
sizeof
(
TableStorageElem
)
+
inf_size
),
0
);
fread
(
t
,(
sizeof
(
TableStorageElem
)
+
inf_size
),
1
,
file
);
if
((
t
->
status
==
2
)
||
(
t
->
status
==
3
))
r
=
mid
;
else
if
((
t
->
status
==
4
)
||
(
t
->
status
==
5
))
l
=
mid
;
else
{
r
=
mid
;
break
;
}
}
if
(
r
<
size
)
head
=
r
;
else
head
=
size
-
1
;
}
}
}
else
seekpos
=
seek
;
}
}
TableStorage
::~
TableStorage
()
TableStorage
::~
TableStorage
()
...
@@ -67,56 +112,118 @@ TableStorage::~TableStorage()
...
@@ -67,56 +112,118 @@ TableStorage::~TableStorage()
int
TableStorage
::
AddRow
(
char
*
key
,
char
*
value
)
int
TableStorage
::
AddRow
(
char
*
key
,
char
*
value
)
{
{
TableStorageElem
*
tbl
=
new
TableStorageElem
(
);
TableStorageElem
*
tbl
=
(
TableStorageElem
*
)
malloc
(
sizeof
(
TableStorageElem
)
+
inf_size
);
int
i
;
int
i
,
k
,
j
,
st
;
if
(
file
!=
NULL
)
if
(
file
!=
NULL
)
{
{
fseek
(
file
,
seekpos
,
0
);
if
(
head
==-
1
)
{
fseek
(
file
,
seekpos
,
0
);
tbl
->
status
=
1
;
strcpy
(
tbl
->
key
,
key
);
for
(
k
=
0
;
k
<
inf_size
;
k
++
)
*
((
char
*
)(
tbl
)
+
sizeof
(
TableStorageElem
)
+
k
)
=*
(
value
+
k
);
fwrite
(
tbl
,(
sizeof
(
TableStorageElem
)
+
inf_size
),
1
,
file
);
head
=
0
;
return
0
;
}
fseek
(
file
,
seekpos
+
head
*
(
sizeof
(
TableStorageElem
)
+
inf_size
),
0
);
j
=
head
;
for
(
i
=
0
;
i
<
size
;
i
++
)
for
(
i
=
0
;
i
<
size
;
i
++
)
{
{
fread
(
tbl
,
sizeof
(
*
tbl
),
1
,
file
);
fread
(
tbl
,(
sizeof
(
TableStorageElem
)
+
inf_size
),
1
,
file
);
if
(
!
strcmp
(
tbl
->
key
,
key
))
if
(
tbl
->
status
==
0
)
break
;
{
if
(
!
strcmp
(
tbl
->
key
,
key
)
&&
((
tbl
->
status
==
2
)
||
(
tbl
->
status
==
4
)
||
(
tbl
->
status
==
1
)))
strcpy
(
tbl
->
value
,
value
);
{
fseek
(
file
,
seekpos
+
i
*
sizeof
(
*
tbl
),
0
);
for
(
k
=
0
;
k
<
inf_size
;
k
++
)
fwrite
(
tbl
,
sizeof
(
*
tbl
),
1
,
file
);
*
((
char
*
)(
tbl
)
+
sizeof
(
TableStorageElem
)
+
k
)
=*
(
value
+
k
);
fseek
(
file
,
seekpos
+
i
*
(
sizeof
(
TableStorageElem
)
+
inf_size
),
0
);
fwrite
(
tbl
,(
sizeof
(
TableStorageElem
)
+
inf_size
),
1
,
file
);
return
0
;
return
0
;
}
}
j
++
;
if
(
j
>=
size
)
{
j
=
0
;
fseek
(
file
,
seekpos
,
0
);
}
}
}
fseek
(
file
,
seekpos
,
0
);
fseek
(
file
,
seekpos
+
j
*
(
sizeof
(
TableStorageElem
)
+
inf_size
),
0
);
for
(
i
=
0
;
i
<
size
;
i
++
)
if
(
j
==
head
)
{
if
((
tbl
->
status
==
2
)
||
(
tbl
->
status
==
3
))
st
=
2
;
else
st
=
4
;
if
(
j
==
0
)
if
(
st
==
2
)
st
=
4
;
else
st
=
2
;
tbl
->
status
=
st
;
strcpy
(
tbl
->
key
,
key
);
for
(
k
=
0
;
k
<
inf_size
;
k
++
)
*
((
char
*
)(
tbl
)
+
sizeof
(
TableStorageElem
)
+
k
)
=*
(
value
+
k
);
fwrite
(
tbl
,(
sizeof
(
TableStorageElem
)
+
inf_size
),
1
,
file
);
j
++
;
if
(
j
>=
size
)
{
j
=
0
;
fseek
(
file
,
seekpos
,
0
);
}
fread
(
tbl
,(
sizeof
(
TableStorageElem
)
+
inf_size
),
1
,
file
);
if
((
tbl
->
status
==
3
)
||
(
tbl
->
status
==
5
))
tbl
->
status
=
6
;
else
tbl
->
status
=
1
;
fseek
(
file
,
seekpos
+
j
*
(
sizeof
(
TableStorageElem
)
+
inf_size
),
0
);
fwrite
(
tbl
,(
sizeof
(
TableStorageElem
)
+
inf_size
),
1
,
file
);
head
++
;
if
(
head
>=
size
)
head
=
0
;
return
0
;
}
/*for(i=0;i<size;i++)
{
{
fread
(
tbl
,
sizeof
(
*
tbl
),
1
,
file
);
fread(tbl,
(sizeof(TableStorageElem)+inf_size
),1,file);
if
(
*
(
tbl
->
key
)
==
0
)
if(
tbl->key[0]
==0)
{
{
strcpy(tbl->key,key);
strcpy(tbl->key,key);
strcpy
(
tbl
->
value
,
value
);
for(k=0;k<inf_size;k++)
fseek
(
file
,
seekpos
+
i
*
sizeof
(
*
tbl
),
0
);
*((char*)(tbl)+sizeof(TableStorageElem)+k)=*(value+k);
fwrite
(
tbl
,
sizeof
(
*
tbl
),
1
,
file
);
fseek(file,seekpos+i*(sizeof(TableStorageElem)+inf_size),0);
fwrite(tbl,(sizeof(TableStorageElem)+inf_size),1,file);
return 0;
return 0;
}
}
}
}
*/
}
}
return
1
;
return
1
;
}
}
int
TableStorage
::
DelRow
(
char
*
key
)
int
TableStorage
::
DelRow
(
char
*
key
)
{
{
TableStorageElem
*
tbl
=
new
TableStorageElem
(
);
TableStorageElem
*
tbl
=
(
TableStorageElem
*
)
malloc
(
sizeof
(
TableStorageElem
)
+
inf_size
);
int
i
;
int
i
,
j
;
if
(
file
!=
NULL
)
if
(
file
!=
NULL
)
{
{
fseek
(
file
,
seekpos
,
0
);
fseek
(
file
,
seekpos
+
head
*
(
sizeof
(
TableStorageElem
)
+
inf_size
),
0
);
j
=
head
;
for
(
i
=
0
;
i
<
size
;
i
++
)
for
(
i
=
0
;
i
<
size
;
i
++
)
{
{
fread
(
tbl
,(
key_size
+
val
_size
),
1
,
file
);
fread
(
tbl
,(
sizeof
(
TableStorageElem
)
+
inf
_size
),
1
,
file
);
if
(
!
strcmp
(
tbl
->
key
,
key
))
if
(
!
strcmp
(
tbl
->
key
,
key
)
&&
((
tbl
->
status
==
2
)
||
(
tbl
->
status
==
4
)
||
(
tbl
->
status
==
1
))
)
{
{
tbl
->
key
[
0
]
=
0
;
//tbl->key[0]=0;
fseek
(
file
,
seekpos
+
i
*
(
key_size
+
val_size
),
0
);
if
(
tbl
->
status
==
1
)
tbl
->
status
=
6
;
fwrite
(
tbl
,(
key_size
+
val_size
),
1
,
file
);
else
if
(
tbl
->
status
==
2
)
tbl
->
status
=
3
;
else
tbl
->
status
=
5
;
fseek
(
file
,
seekpos
+
j
*
(
sizeof
(
TableStorageElem
)
+
inf_size
),
0
);
fwrite
(
tbl
,(
sizeof
(
TableStorageElem
)
+
inf_size
),
1
,
file
);
return
0
;
return
0
;
}
}
j
++
;
if
(
j
>=
size
)
{
j
=
0
;
fseek
(
file
,
seekpos
,
0
);
}
}
}
}
}
return
1
;
return
1
;
...
@@ -124,17 +231,18 @@ int TableStorage::DelRow(char* key)
...
@@ -124,17 +231,18 @@ int TableStorage::DelRow(char* key)
char
*
TableStorage
::
FindKeyValue
(
char
*
key
,
char
*
val
)
char
*
TableStorage
::
FindKeyValue
(
char
*
key
,
char
*
val
)
{
{
TableStorageElem
*
tbl
=
new
TableStorageElem
(
);
TableStorageElem
*
tbl
=
(
TableStorageElem
*
)
malloc
(
sizeof
(
TableStorageElem
)
+
inf_size
);
int
i
;
int
i
,
k
;
if
(
file
!=
NULL
)
if
(
file
!=
NULL
)
{
{
fseek
(
file
,
seekpos
,
0
);
fseek
(
file
,
seekpos
,
0
);
for
(
i
=
0
;
i
<
size
;
i
++
)
for
(
i
=
0
;
i
<
size
;
i
++
)
{
{
fread
(
tbl
,(
key_size
+
val
_size
),
1
,
file
);
fread
(
tbl
,(
sizeof
(
TableStorageElem
)
+
inf
_size
),
1
,
file
);
if
(
!
strcmp
(
tbl
->
key
,
key
))
if
(
!
strcmp
(
tbl
->
key
,
key
)
&&
((
tbl
->
status
==
2
)
||
(
tbl
->
status
==
4
)
||
(
tbl
->
status
==
1
))
)
{
{
strcpy
(
val
,
tbl
->
value
);
for
(
k
=
0
;
k
<
inf_size
;
k
++
)
*
(
val
+
k
)
=*
((
char
*
)(
tbl
)
+
sizeof
(
TableStorageElem
)
+
k
);
return
val
;
return
val
;
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment