Testing problems with mavl_del

FossilOrigin-Name: f7d0d891db6d23d94c00d2a569958d37215ba4821e391e86b9d7e97267fdd459
This commit is contained in:
7u83@mail.ru
2018-04-24 05:02:23 +00:00
parent 74c96ab343
commit 06ff52d5e3
10 changed files with 134 additions and 21 deletions

View File

@ -136,6 +136,7 @@ KTVSRC=\
cw_ktv_std_types.c\
cw_ktv_base_exists.c\
cw_ktv_save.c\
cw_ktv_del_sub.c\
LWSRC=\

22
src/cw/cw_ktv_del_sub.c Normal file
View File

@ -0,0 +1,22 @@
#include "ktv.h"
void cw_ktv_del_sub(mavl_t ktvstore, const char *basekey)
{
cw_KTV_t * result, search;
while (1){
search.key=(char*)basekey;
result = mavl_get_first(ktvstore,&search);
if (result == NULL)
return;
if (strncmp(result->key,basekey,strlen(basekey))!=0)
break;
search.key = result->key;
mavl_del(ktvstore,&search);
}
}

View File

@ -16,10 +16,27 @@ int cw_ktv_read_struct(mavl_t ktv,const cw_KTVStruct_t * stru, const char *pkey,
pos=stru[i].position;
sprintf(key,"%s/%s",pkey,stru[i].key);
if (stru[i].len==-1)
l = len-pos;
else
l = stru[i].len;
switch (stru[i].len){
case CW_KTVSTRUCT_L8:
l = cw_get_byte(data+pos);
pos ++;
break;
case CW_KTVSTRUCT_L16:
l = cw_get_word(data+pos);
pos ++;
break;
case -1:
l = len-pos;
break;
default:
l = stru[i].len;
if (pos+l > l){
l = len-pos;
}
}
result = cw_ktv_add(ktv,key,stru[i].type,data+pos,l);
stru[i].type->to_str(result,dbstr,100);

View File

@ -95,6 +95,9 @@ struct cw_KTVStruct {
typedef struct cw_KTVStruct cw_KTVStruct_t;
#define CW_KTVSTRUCT_L16 -2
#define CW_KTVSTRUCT_L8 -3
struct cw_KTVEnum{
int value;
const char * name;
@ -141,6 +144,8 @@ void cw_kvstore_mavl_delete(const void *data);
cw_KTV_t *cw_ktv_add(mavl_t kvstore, const char *key, const struct cw_Type *type,
const uint8_t * data, int len);
void cw_ktv_del_sub(mavl_t ktvstore, const char *basekey);
cw_KTV_t * cw_ktv_replace(mavl_t kvtstore, const char *key, const struct cw_Type *type,
const uint8_t * data, int len);