projects
/
tedtools.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4c55f26
)
Add optional length to SFSFindData
author
teodor
<teodor>
Wed, 9 Jul 2008 14:24:33 +0000
(14:24 +0000)
committer
teodor
<teodor>
Wed, 9 Jul 2008 14:24:33 +0000
(14:24 +0000)
sfxstr.c
patch
|
blob
|
history
sfxstr.h
patch
|
blob
|
history
sfxtest.c
patch
|
blob
|
history
diff --git
a/sfxstr.c
b/sfxstr.c
index
b9a048e
..
0dd5fa7
100644
(file)
--- a/
sfxstr.c
+++ b/
sfxstr.c
@@
-139,17
+139,21
@@
SFSInit_c(SFSTree *info, char **in) {
return info;
}
return info;
}
+#define ISEND(p,w,l) ( (l>0) ? ( ((char*)(p))-(w) < (l) ) : ( *(p) == '\0' ) )
+
void*
void*
-SFSFindData(SFSTree *info, char *word) {
+SFSFindData(SFSTree *info, char *word
, int len
) {
SFSNode *node = info->node;
SFSNodeData *StopLow, *StopHigh, *StopMiddle;
u_int8_t *ptr =(u_int8_t*)word;
SFSNode *node = info->node;
SFSNodeData *StopLow, *StopHigh, *StopMiddle;
u_int8_t *ptr =(u_int8_t*)word;
- while( node &&
*ptr
) {
+ while( node &&
!ISEND(ptr, word, len)
) {
if ( node->isskip ) {
if ( node->isskip ) {
- if ( STRNCMP(ptr, ((char*)node)+node->dataptr, node->nchar) ) {
+ if ( len>0 && len - (((char*)ptr) - word) > node->nchar )
+ return NULL;
+ else if ( STRNCMP(ptr, ((char*)node)+node->dataptr, node->nchar) ) {
ptr+=node->nchar;
ptr+=node->nchar;
- if (
*ptr=='\0'
&& node->isword) {
+ if (
ISEND(ptr, word, len)
&& node->isword) {
return (void*) ( ((char*)(node->data)) + ((node->haschild) ? sizeof(SFSNode*) : 0) );
} else if ( node->haschild ) {
node = getSkipChildPointer(info, node);
return (void*) ( ((char*)(node->data)) + ((node->haschild) ? sizeof(SFSNode*) : 0) );
} else if ( node->haschild ) {
node = getSkipChildPointer(info, node);
@@
-165,7
+169,7
@@
SFSFindData(SFSTree *info, char *word) {
StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
if ( StopMiddle->val == *ptr ) {
ptr++;
StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
if ( StopMiddle->val == *ptr ) {
ptr++;
- if (
*ptr=='\0'
&& StopMiddle->isword ) {
+ if (
ISEND(ptr, word, len)
&& StopMiddle->isword ) {
return (void*)( ((char*)node) + node->dataptr + info->datasize * StopMiddle->data );
} else if ( StopMiddle->haschild ) {
node = getChildPointer(info, StopMiddle);
return (void*)( ((char*)node) + node->dataptr + info->datasize * StopMiddle->data );
} else if ( StopMiddle->haschild ) {
node = getChildPointer(info, StopMiddle);
diff --git
a/sfxstr.h
b/sfxstr.h
index
84b708e
..
22f8410
100644
(file)
--- a/
sfxstr.h
+++ b/
sfxstr.h
@@
-183,7
+183,7
@@
void SFSAdd(SFSTree *info, SFSDataIO *in);
* ðÏÉÓË ÚÎÁÞÅÎÉÑ ÐÏ ËÌÀÞÕ, × ÓÌÕÞÁÅ ÕÓÐÅÈÁ ×ÏÚ×ÒÁÝÁÅÔ
* ÕËÁÚÁÔÅÌØ ÎÁ ÚÎÁÞÅÎÉÅ, ÉÎÁÞÅ - NULL
*/
* ðÏÉÓË ÚÎÁÞÅÎÉÑ ÐÏ ËÌÀÞÕ, × ÓÌÕÞÁÅ ÕÓÐÅÈÁ ×ÏÚ×ÒÁÝÁÅÔ
* ÕËÁÚÁÔÅÌØ ÎÁ ÚÎÁÞÅÎÉÅ, ÉÎÁÞÅ - NULL
*/
-void* SFSFindData(SFSTree *info, char *word);
+void* SFSFindData(SFSTree *info, char *word
, int len /* optional */
);
/*
* éÎÉÃÉÁÌÉÚÁÃÉÑ ÉÔÅÒÁÔÏÒÁ × ÎÁÞÁÌÏ ÄÅÒÅ×Á
/*
* éÎÉÃÉÁÌÉÚÁÃÉÑ ÉÔÅÒÁÔÏÒÁ × ÎÁÞÁÌÏ ÄÅÒÅ×Á
diff --git
a/sfxtest.c
b/sfxtest.c
index
393aff5
..
e42e925
100644
(file)
--- a/
sfxtest.c
+++ b/
sfxtest.c
@@
-352,7
+352,7
@@
main(int argn, char *argv[]) {
len = clrspace(buf);
if (!len) continue;
len = clrspace(buf);
if (!len) continue;
- res = SFSFindData(&info,buf);
+ res = SFSFindData(&info,buf
,0
);
if (verbose) {
if (enumerate && res)
printf("%d\n", *(int*)(res));
if (verbose) {
if (enumerate && res)
printf("%d\n", *(int*)(res));