kv.h代码如下: #define UT_BASE_NODE_T(TYPE) struct { TYPE *start; TYPE *end; } typedef struct _kv { char *k; char *v; unsigned int klen; unsigned int vlen; unsigned int id; struct _kv *next; }kv; typedef struct _map { char *base; unsigned int id; unsigned int kv_count; //number of maps UT_BASE_NODE_T(struct _kv) bt; struct _map *next; }map; typedef struct _table { unsigned int map_count; UT_BASE_NODE_T(struct _map) info; }table; /* * read map info from file */ extern table *Map_init(const char *path); /* * acroding a index of key,get a basename, key,value */ extern char **Get_bkv(table *tb,int map_id,int key_index); /* * */ extern void Map_free(table *tb); /* * */ extern void *Map_prt(table *tb);
kv.c代码如下: #include <stdio.h> #include <stdlib.h> #include <string.h> #include "kv.h" #define MAX 1024 #define CFLAG 10 #define L 91 #define R 93 char *trim(char *msg) { int msg_len=strlen(msg); char *trunc=strchr(msg,CFLAG); int trunc_len=strlen(trunc); *(msg+msg_len-trunc_len)='