文件夹加密工具(开源代码)
软件作者:dyforc
发现文件夹加密的软件较少
源代码在线查看: map.c
#include "map.h"
void MapAssign(Map *pmap, char *str, char *value)
{
int cmp;
if(pmap == NULL)
return;
if(*pmap == NULL){
if((*pmap = (Map)malloc(sizeof(MapNode))) == NULL){
fprintf(stderr, "Failed to allocate map node.\n");
return;
}
(*pmap)->str = strdup(str);
(*pmap)->value = strdup(value);
(*pmap)->left = NULL;
(*pmap)->right = NULL;
}else{
cmp = strcmp(str, (*pmap)->str);
if(cmp == 0){
free(value);
value = strdup(value);
}else if(cmp < 0)
MapAssign(&(*pmap)->left, str, value);
else
MapAssign(&(*pmap)->right, str, value);
}
}
char* MapFind(Map map, char *str)
{
int cmp;
if(map == NULL || str == NULL)
return NULL;
cmp = strcmp(str, map->str);
if(cmp == 0)
return map->value;
if(cmp < 0)
return MapFind(map->left, str);
return MapFind(map->right, str);
}
void MapClear(Map map)
{
if(map == NULL)
return;
if(map->left)
MapClear(map->left);
if(map->right)
MapClear(map->right);
if(map->str)
free(map->str);
if(map->value)
free(map->value);
free(map);
}