Add and fixed.

This commit is contained in:
Saturneic 2018-08-21 16:26:31 +08:00
parent 6a00c6bead
commit c5890b4c1f
16 changed files with 1490 additions and 639 deletions

View File

@ -8,14 +8,12 @@
/* Begin PBXBuildFile section */
9233C310212292B000FB2485 /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = 9233C30F212292B000FB2485 /* md5.c */; };
9246995F20CE655900B4E894 /* tree.c in Sources */ = {isa = PBXBuildFile; fileRef = 9246995E20CE655900B4E894 /* tree.c */; };
9269D4E8210F1B3D00161557 /* stack_expand.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4E7210F1B3D00161557 /* stack_expand.c */; };
9269D4EA210F1B4B00161557 /* list_expand.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4E9210F1B4B00161557 /* list_expand.c */; };
9269D4ED210F1B5E00161557 /* test.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4EB210F1B5E00161557 /* test.c */; };
9269D4F4210F1BB000161557 /* id.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4F2210F1BB000161557 /* id.c */; };
9269D4F5210F1BCE00161557 /* list.c in Sources */ = {isa = PBXBuildFile; fileRef = 9246994F20CD000300B4E894 /* list.c */; };
9269D4F6210F1CD900161557 /* stack.c in Sources */ = {isa = PBXBuildFile; fileRef = 9246995920CE52A700B4E894 /* stack.c */; };
9269D4F8210F1D0B00161557 /* tree_expand.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4F7210F1D0B00161557 /* tree_expand.c */; };
9286EB7A211400C900752977 /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = 9286EB79211400C900752977 /* error.c */; };
9286EB7E2114022A00752977 /* communicate.c in Sources */ = {isa = PBXBuildFile; fileRef = 9286EB7D2114022A00752977 /* communicate.c */; };
/* End PBXBuildFile section */
@ -55,7 +53,7 @@
927993BD20CB87D6008CE3A9 /* ZE-Standard-Libraries */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "ZE-Standard-Libraries"; sourceTree = BUILT_PRODUCTS_DIR; };
9286EB79211400C900752977 /* error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = error.c; path = error/error.c; sourceTree = "<group>"; };
9286EB7B211400D000752977 /* error.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = error.h; path = error/error.h; sourceTree = "<group>"; };
9286EB7D2114022A00752977 /* communicate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = communicate.c; path = communicate/communicate.c; sourceTree = "<group>"; };
9286EB7D2114022A00752977 /* communicate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; name = communicate.c; path = communicate/communicate.c; sourceTree = "<group>"; };
9286EB7F2114022F00752977 /* communicate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = communicate.h; path = communicate/communicate.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -235,8 +233,6 @@
9286EB7E2114022A00752977 /* communicate.c in Sources */,
9269D4EA210F1B4B00161557 /* list_expand.c in Sources */,
9269D4F4210F1BB000161557 /* id.c in Sources */,
9269D4F8210F1D0B00161557 /* tree_expand.c in Sources */,
9246995F20CE655900B4E894 /* tree.c in Sources */,
9269D4ED210F1B5E00161557 /* test.c in Sources */,
9269D4F5210F1BCE00161557 /* list.c in Sources */,
);

View File

@ -24,6 +24,12 @@
<ContextState
contextName = "initS_id:id.c">
</ContextState>
<ContextState
contextName = "printStandardData:communicate.c">
</ContextState>
<ContextState
contextName = "initStandardData:communicate.c">
</ContextState>
<ContextState
contextName = "getByIntForNode:list_expand.c">
<PersistentStrings>
@ -35,6 +41,9 @@
<ContextState
contextName = "listThrough:list_expand.c">
</ContextState>
<ContextState
contextName = "readStandardData:communicate.c">
</ContextState>
<ContextState
contextName = "initStandardDBlocks:communicate.c">
</ContextState>
@ -96,6 +105,17 @@
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "printListForCustom:list_expand.c">
</ContextState>
<ContextState
contextName = "standardDataToList:communicate.c">
<PersistentStrings>
<PersistentString
value = "(STD_BLOCKS *)p_std-&gt;pd_blocklst-&gt;head-&gt;value">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "_doStandardDataInfoWrite:communicate.c">
</ContextState>
@ -110,12 +130,18 @@
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "copyS_id:id.c">
</ContextState>
<ContextState
contextName = "dataFileWriteIn:communicate.c">
</ContextState>
<ContextState
contextName = "freeS_id:id.c">
</ContextState>
<ContextState
contextName = "setS_idWithString:id.c">
</ContextState>
<ContextState
contextName = "s_idToASCIIString:id.c">
<PersistentStrings>
@ -131,16 +157,22 @@
contextName = "main:test.c">
<PersistentStrings>
<PersistentString
value = "(int *)p_node-&gt;value">
value = "strlen(string)">
</PersistentString>
<PersistentString
value = "((STD_DATA *)(p_dfiler-&gt;pf_stdlst-&gt;head-&gt;value))-&gt;pd_blocklst">
</PersistentString>
<PersistentString
value = "strlen(string)">
value = "(int *)p_node-&gt;value">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "readDataFileInfo:communicate.c">
</ContextState>
<ContextState
contextName = "_doStandardDataToList:communicate.c">
</ContextState>
<ContextState
contextName = "init_list:list.h">
</ContextState>

View File

@ -7,6 +7,7 @@ STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long lon
}
else p_stdb->sid = NULL;
p_stdb->if_data = 0;
p_stdb->location = 0;
unsigned int blocks_num = (unsigned int)(data_size/sizeof(char));
p_stdb->blocks_num = blocks_num;
p_stdb->type = type;
@ -28,16 +29,22 @@ STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid){
STD_CTN *p_stdc = (STD_CTN *)malloc(sizeof(STD_CTN));
p_stdc->f_sid = s_idToASCIIString(f_sid);
p_stdc->s_sid = s_idToASCIIString(s_sid);
p_stdc->location = 0;
return p_stdc;
}
STD_DATA *initStandardData(unsigned int type){
STD_DATA *initStandardData(unsigned int type, SID *s_id){
STD_DATA *p_std = (STD_DATA *)malloc(sizeof(STD_DATA));
p_std->pd_blocklst = initList(0);
p_std->pd_ctnlst = initList(0);
p_std->lock = 0;
p_std->type = type;
p_std->s_id = NULL;
p_std->size = 0;
p_std->location = 0;
if(s_id == NULL) p_std->s_id = getS_id(STANDARD_DATA, 2);
else p_std->s_id = copyS_id(s_id);
setSidToASCIIString(p_std->s_id);
return p_std;
}
@ -84,71 +91,47 @@ int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){
int dataFileWriteIn(D_FILE *p_dfile){
fwrite(p_dfile->pf_head->head_test, sizeof(char), 18, p_dfile->fp);
fwrite(&p_dfile->pf_head->data_num, sizeof(unsigned long long), 1, p_dfile->fp);
fwrite("HEAD_END", sizeof(char), 9, p_dfile->fp);
List *er_list = initList(0);
insertInTail(er_list, nodeWithPointer(p_dfile->fp,0));
/*fwrite("STDINFO", sizeof(char), 8, p_dfile->fp);
listThrough(p_dfile->pf_stdlst, _doStandardDataInfoWrite, er_list);*/
/*fwrite("STDLST", sizeof(char), 7, p_dfile->fp);*/
listThrough(p_dfile->pf_stdlst, _doStandardDataWrite, er_list);
releaseList(er_list);
fwrite("STDINFO", sizeof(char), 8, p_dfile->fp);
listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(StandardDataInfoWrite), __SEND_ARG("%p", p_dfile->fp));
fwrite("STDLST", sizeof(char), 7, p_dfile->fp);
listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(StandardDataWrite), __SEND_ARG("%p", p_dfile->fp));
return 0;
}
List *_doStandardDataInfoWrite(unsigned int type, void *value, List *er_list){
List *p_rtnlst = initList(0);
FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0));
STD_DATA *p_std = value;
insertInTail(p_rtnlst, nodeWithInt(0,0));
int if_sid = 0;
if(p_std->s_id != NULL){
if_sid = 1;
char *string_sid = s_idToASCIIString(p_std->s_id);
fwrite(&if_sid, sizeof(int), 1, fp);
fwrite(string_sid, sizeof(char), SID_LEN, fp);
free(string_sid);
}
else{
fwrite(&if_sid, sizeof(int), 1, fp);
}
fwrite(&p_std->type, sizeof(unsigned long), 1, fp);
fwrite(&p_std->pd_ctnlst->length, sizeof(unsigned long long), 1, fp);
fwrite(&p_std->pd_blocklst->length, sizeof(unsigned long long), 1, fp);
return p_rtnlst;
}
List *_doStandardDataWrite(unsigned int type, void *value, List *er_list){
List *p_rtnlst = initList(0);
FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0));
insertInTail(p_rtnlst, nodeWithInt(0,0));
STD_DATA *p_std = value;
List *erc_list = initList(0);
insertInTail(erc_list, nodeWithPointer(fp,0));
fwrite("STD", sizeof(char), 4, fp);
__CALLBACK_DEFINE(StandardDataInfoWrite){
FILE *fp = __ARGS_P(0, FILE);
STD_DATA *p_std = __VALUE(STD_DATA *);
fwrite(p_std->s_id->decrypt_str, sizeof(char), SID_LEN, fp);
fwrite(&p_std->type, sizeof(unsigned int), 1, fp);
fwrite(&p_std->pd_ctnlst->length, sizeof(unsigned long long), 1, fp);
fwrite(&p_std->pd_blocklst->length, sizeof(unsigned long long), 1, fp);
listThrough(p_std->pd_ctnlst, _doStandardDConnectionWrite, erc_list);
listThrough(p_std->pd_blocklst, _doStandardDBlockWrite, erc_list);
releaseList(erc_list);
return p_rtnlst;
unsigned long long std_size = calStandardData(p_std);
p_std->size = std_size;
fwrite(&std_size, sizeof(unsigned long long), 1, fp);
return __CRETURN__;
}
List *_doStandardDConnectionWrite(unsigned int type, void *value, List *er_list){
List *p_rtnlst = initList(0);
insertInTail(p_rtnlst, nodeWithInt(0,0));
FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0));
STD_CTN *p_stdc = value;
__CALLBACK_DEFINE(StandardDataWrite){
FILE *fp = __ARGS_P(0, FILE);
STD_DATA *p_std = __VALUE(STD_DATA *);
fwrite("STD", sizeof(char), 4, fp);
fwrite(p_std->s_id->decrypt_str, sizeof(char), SID_LEN, fp);
fwrite(&p_std->pd_ctnlst->length, sizeof(unsigned long long), 1, fp);
fwrite(&p_std->pd_blocklst->length, sizeof(unsigned long long), 1, fp);
listThrough(p_std->pd_ctnlst, __CALLBACK_CALL(StandardDConnectionWrite), __SEND_ARG("%p", fp));
listThrough(p_std->pd_blocklst, __CALLBACK_CALL(StandardDBlockWrite), __SEND_ARG("%p", fp));
return __CRETURN__;
}
__CALLBACK_DEFINE(StandardDConnectionWrite){
FILE *fp = __ARGS_P(0, FILE);
STD_CTN *p_stdc = __VALUE(STD_CTN *);
fwrite(p_stdc->f_sid, sizeof(char), SID_LEN, fp);
fwrite(p_stdc->s_sid, sizeof(char), SID_LEN, fp);
return p_rtnlst;
return __CRETURN__;
}
List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list){
List *p_rtnlst = initList(0);
insertInTail(p_rtnlst, nodeWithInt(0,0));
__CALLBACK_DEFINE(StandardDBlockWrite){
STD_BLOCKS *p_stdb = value;
FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0));
FILE *fp = __ARGS_P(0, FILE);
unsigned long blocks_num = p_stdb->blocks_num;
int if_sid = 0;
if(p_stdb->sid != NULL){
@ -162,13 +145,16 @@ List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list){
fwrite(&p_stdb->type, sizeof(unsigned int), 1, fp);
fwrite(&blocks_num, sizeof(unsigned long), 1, fp);
fwrite(p_stdb->buff, sizeof(char), p_stdb->blocks_num, fp);
return p_rtnlst;
return __CRETURN__;
}
STD_DATA *listToSTD(List *p_list){
STD_DATA *p_std = initStandardData(LIST);
Node *p_node = p_list->head;
if (p_list->s_id != NULL) p_std->s_id = copyS_id(p_list->s_id);
STD_DATA *p_std = NULL;
if (p_list->s_id != NULL){
p_std = initStandardData(LIST,p_list->s_id);
}
else p_std = initStandardData(LIST, NULL);
while (p_node != NULL) {
if(p_node->type == HOLE) continue;
unsigned long long data_size = 0;
@ -183,80 +169,20 @@ STD_DATA *listToSTD(List *p_list){
}
int dataFileReadOut(D_FILE *p_dfile){
char test_info[FILE_TSET_LEN],head_test_info[HEAD_TEST_LEN];
fread(test_info, sizeof(char), FILE_TSET_LEN, p_dfile->fp);
strcpy(p_dfile->pf_head->head_test, test_info);
if(!strcmp(test_info, "ZESTDLIB_STDDFILE")){
unsigned long long std_num = 0;
fread(&std_num, sizeof(unsigned long long), 1, p_dfile->fp);
p_dfile->pf_head->data_num = std_num;
fread(head_test_info, sizeof(char), 9, p_dfile->fp);
if (!strcmp(head_test_info, "HEAD_END")) {
for(int i = 0; i < std_num; i++){
char std_test_info[4];
fread(std_test_info, sizeof(char), 4, p_dfile->fp);
if(!strcmp(std_test_info, "STD")){
unsigned long long ctn_num = 0, blk_num = 0;
int if_sid = 0;
unsigned int type = 0;
fread(&if_sid, sizeof(int), 1, p_dfile->fp);
char *string_sid = NULL;
if(if_sid){
string_sid = (char *)malloc(sizeof(char) * SID_LEN);
fread(string_sid, sizeof(char), SID_LEN, p_dfile->fp);
}
fread(&type, sizeof(unsigned int), 1, p_dfile->fp);
STD_DATA *p_std = initStandardData(type);
freeS_id(p_std->s_id);
p_std->s_id = asciiStringToS_id(string_sid);
dataFileAddStandardData(p_dfile, p_std);
if(string_sid != NULL) free(string_sid);
fread(&ctn_num, sizeof(unsigned long long), 1, p_dfile->fp);
fread(&blk_num, sizeof(unsigned long long), 1, p_dfile->fp);
for(int j = 0; j < ctn_num; j++){
char *fstring_sid = (char *)malloc(sizeof(char) * SID_LEN);
fread(fstring_sid, sizeof(char), SID_LEN, p_dfile->fp);
char *sstring_sid = (char *)malloc(sizeof(char) * SID_LEN);
fread(sstring_sid, sizeof(char), SID_LEN, p_dfile->fp);
SID *fs_id = asciiStringToS_id(fstring_sid), *ss_id = asciiStringToS_id(sstring_sid);
standardDataAddConnection(p_std, fs_id,ss_id);
freeS_id(fs_id);
freeS_id(ss_id);
free(fstring_sid);
free(sstring_sid);
}
for(int k = 0; k < blk_num; k++){
fread(&if_sid, sizeof(int), 1, p_dfile->fp);
char *string_sid = NULL;
if(if_sid){
string_sid = (char *)malloc(sizeof(char) * SID_LEN);
fread(string_sid, sizeof(char), SID_LEN, p_dfile->fp);
}
unsigned long blk_len = 0;
fread(&blk_len, sizeof(unsigned long), 1, p_dfile->fp);
char *content = (char *)malloc(sizeof(char) * blk_len);
fread(content, sizeof(char), blk_len, p_dfile->fp);
SID *s_id = asciiStringToS_id(string_sid);
unsigned int type = VOID;
fread(&type, sizeof(unsigned int), 1, p_dfile->fp);
standardDataAddBlock(p_std, s_id, type, content, blk_len);
freeS_id(s_id);
if(string_sid != NULL) free(string_sid);
free(content);
}
return 0;
}
else break;
}
}
else{
}
if(!readDataFileInfo(p_dfile)){
listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(dataFileReadOut), __SEND_ARG("%p", p_dfile));
}
showError(pushError(DATA_FILE, STANDARD, initInfo("dataFileReadOut()", "Datafile not complete.")));
return -1;
}
__CALLBACK_DEFINE(dataFileReadOut){
D_FILE *p_dfile = __ARGS_P(0, D_FILE);
readStandardData(p_dfile, __VALUE(STD_DATA *));
return __CRETURN__;
}
int releaseSTDConnection(STD_CTN *p_stdc){
free(p_stdc->f_sid);
free(p_stdc->s_sid);
@ -274,6 +200,7 @@ int releaseSTDBlocks(STD_BLOCKS *p_stdb){
int releaseStandardData(STD_DATA *p_std){
releaseListForCustom(p_std->pd_blocklst, (int (*)(void *))releaseSTDBlocks);
releaseListForCustom(p_std->pd_ctnlst, (int (*)(void *))releaseSTDConnection);
freeS_id(p_std->s_id);
free(p_std);
return 0;
}
@ -288,36 +215,60 @@ int releaseDFile(D_FILE *p_dfile){
List *standardDataToList(STD_DATA *p_std){
List *p_list = initList(0);
List *er_list = initList(0);
insertInTail(er_list, nodeWithPointer(er_list,0));
listThrough(p_std->pd_blocklst, _doStandardDataToList, er_list);
listThrough(p_std->pd_blocklst, __CALLBACK_CALL(StandardDataToList), __SEND_ARG("%p", p_list));
return p_list;
}
List *_doStandardDataToList(unsigned int type, void *value, List *er_list){
List *rtn_list = initList(0);
insertInTail(rtn_list, nodeWithInt(0,0));
List *p_list = getByPointerForNode(findByIndexForNode(er_list, 0));
STD_BLOCKS *p_stdb = value;
__CALLBACK_DEFINE(StandardDataToList){
List *p_list = __ARGS_P(0, List);
STD_BLOCKS *p_stdb = __VALUE(STD_BLOCKS *);
Node *p_node = initNode(0);
p_node->s_id = asciiStringToS_id(p_stdb->sid);
p_node->s_id = setS_idWithString(p_stdb->sid);
p_node->type = p_stdb->type;
p_node->value = malloc(sizeof(p_stdb->blocks_num));
memcpy(p_node->value, p_stdb->buff, sizeof(p_stdb->blocks_num));
insertInTail(p_list, p_node);
return rtn_list;
return __CRETURN__;
}
unsigned long calStandardData(STD_DATA *p_std){
unsigned long size = sizeof(unsigned int) + 9;
if(p_std->s_id != NULL) size += 32;
listThrough(p_std->pd_ctnlst, CALLBACK_CALL(calStandardDataCTN), SEND_ARG("%d", size));
return 0;
unsigned long long calStandardData(STD_DATA *p_std){
List *rtn_lst = NULL;
unsigned long long size = 4 + sizeof(unsigned long long) * 2;
if(p_std->s_id != NULL) size += SID_LEN * sizeof(char);
rtn_lst = listThrough(p_std->pd_ctnlst, __CALLBACK_CALL(calStandardDataCTN), __SEND_ARG("%d", size));
if(rtn_lst != NULL){
size = __RTN_ARGS(rtn_lst, 0, unsigned long long);
releaseList(rtn_lst);
}
rtn_lst = listThrough(p_std->pd_blocklst, __CALLBACK_CALL(calStandardDataBLK), __SEND_ARG("%d", size));
if(rtn_lst != NULL){
size = __RTN_ARGS(rtn_lst, 0, unsigned long long);
releaseList(rtn_lst);
}
return size;
}
CALLBACK_DEFINE(calStandardDataCTN){
return C_RETURN;
__CALLBACK_DEFINE(calStandardDataCTN){
unsigned long long size = __ARGS(0, unsigned long long);
size += 64;
//unsigned long long temp = __NOW_INDEX;
if(__NOW_INDEX == __LIST_LEN - 1){
__RETURN("%ull", size);
}
return __CRETURN__;
}
__CALLBACK_DEFINE(calStandardDataBLK){
unsigned long long size = __ARGS(0, unsigned long long);
STD_BLOCKS *p_stdb = __VALUE(STD_BLOCKS *);
if(p_stdb->sid != NULL) size += SID_LEN + sizeof(int);
else size += sizeof(int);
size += p_stdb->blocks_num + sizeof(unsigned int) + sizeof(unsigned long);
//unsigned long long temp = __NOW_INDEX;
if(__NOW_INDEX == __LIST_LEN - 1){
return __RETURN("%ull", size);
}
return __CRETURN__;
}
MSG *createMessage(char *title, void *data, unsigned long data_size){
@ -362,3 +313,111 @@ MSG *createMessage(char *title, void *data, unsigned long data_size){
close(client_sockfd);
return -1;
}*/
int readDataFileInfo(D_FILE *p_dfile){
if(checkIfDataFile(p_dfile)){
unsigned long long std_num = 0,std_size;
unsigned int std_type = VOID;
char info_begin[INFO_TEST_LEN], s_id[SID_LEN];
unsigned long long location = 0;
fread(&std_num, sizeof(unsigned long long), 1, p_dfile->fp);
fread(info_begin, sizeof(char),INFO_TEST_LEN,p_dfile->fp);
location += INFO_TEST_LEN + sizeof(unsigned long long) + FILE_TSET_LEN;
if(!strcmp(info_begin, "STDINFO")){
location += std_num * 45 + 7;
for(int i = 0; i < std_num; i++){
fread(s_id, sizeof(char), SID_LEN, p_dfile->fp);
fread(&std_type, sizeof(unsigned int), 1, p_dfile->fp);
fread(&std_size, sizeof(unsigned long long), 1, p_dfile->fp);
SID *temp_sid = setS_idWithString(s_id);
STD_DATA *p_std = initStandardData(std_type,temp_sid);
freeS_id(temp_sid);
p_std->size = std_size;
p_std->type = std_type;
p_std->location = location;
dataFileAddStandardData(p_dfile, p_std);
location += std_size;
}
}
}
return 0;
}
int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){
char s_id[SID_LEN],std_text[STD_TEXT_LEN];
fseek(p_dfile->fp, p_std->location, SEEK_SET);
fread(std_text, sizeof(char), STD_TEXT_LEN, p_dfile->fp);
if(strcmp(std_text, "STD")) return -1;
fread(s_id, sizeof(char), SID_LEN, p_dfile->fp);
if(!strcmp(s_id, p_std->s_id->decrypt_str)){
unsigned long long ctn_num = 0, blk_num = 0;
fread(&ctn_num, sizeof(unsigned long long), 1, p_dfile->fp);
fread(&blk_num, sizeof(unsigned long long), 1, p_dfile->fp);
for(int i = 0; i < ctn_num; i++){
SID *fs_id = NULL, *ss_id = NULL;
char t_sid[SID_LEN];
fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp);
fs_id = setS_idWithString(t_sid);
fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp);
ss_id = setS_idWithString(t_sid);
standardDataAddConnection(p_std, fs_id, ss_id);
freeS_id(fs_id);
freeS_id(ss_id);
}
for(int i = 0; i < blk_num; i++){
int if_sid = 0;
unsigned int type = VOID;
unsigned long blk_size = 0;
char t_sid[SID_LEN];
fread(&if_sid, sizeof(int), 1, p_dfile->fp);
if(if_sid){
fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp);
}
fread(&type, sizeof(int), 1, p_dfile->fp);
fread(&blk_size, sizeof(unsigned long), 1, p_dfile->fp);
char *buff = malloc(sizeof(char) * blk_size);
fread(buff, sizeof(char), blk_size, p_dfile->fp);
SID *sb_sid = NULL;
if (if_sid) setS_idWithString(t_sid);
standardDataAddBlock(p_std, sb_sid, type, buff, blk_size);
free(buff);
freeS_id(sb_sid);
}
}
return 0;
}
int checkIfDataFile(D_FILE *p_dfile){
char test_info[FILE_TSET_LEN];
fread(test_info, sizeof(char), FILE_TSET_LEN, p_dfile->fp);
strcpy(p_dfile->pf_head->head_test, test_info);
if(!strcmp(test_info, "ZESTDLIB_STDDFILE"))return 1;
return 0;
}
void printStandardData(void *value){
STD_DATA *p_std = (STD_DATA *)value;
printf("SID:%s\n",p_std->s_id->decrypt_str);
printf("Loaction:%llu\n",p_std->location);
printf("Size:%llu\n",p_std->size);
printf("Ctn number:%llu\n",p_std->pd_ctnlst->length);
printf("Blk number:%llu\n",p_std->pd_blocklst->length);
}
int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid){
List *rtn = listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(findStandardDataBySid), __SEND_ARG("%p", p_sid));
//STD_DATA *p_std = __RTN_ARGS_P(rtn, 0, STD_DATA);
releaseList(rtn);
//if(p_std != NULL) readStandardData(p_dfile, p_std);
return 0;
}
__CALLBACK_DEFINE(findStandardDataBySid){
SID *t_sid = __ARGS_P(0, SID);
STD_DATA *p_std = __VALUE(STD_DATA *);
if(simFitS_id(p_std->s_id, t_sid)){
return __RETURN("%p", p_std);
}
return __CRETURN__;
}

View File

@ -16,7 +16,7 @@ D_FILE *initDataFileForWrite(char *route);
D_FILE *initDataFileForRead(char *route);
STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long long data_size);
STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid);
STD_DATA *initStandardData(unsigned int type);
STD_DATA *initStandardData(unsigned int type, SID *s_id);
int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data);
int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std);
@ -24,25 +24,35 @@ int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,unsigned int type, void *d
int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid);
int dataFileWriteIn(D_FILE *p_dfile);
int dataFileReadOut(D_FILE *p_dfile);
__CALLBACK_STATE(dataFileReadOut);
int releaseSTDBlocks(STD_BLOCKS *p_stdb);
int releaseStandardData(STD_DATA *p_std);
int releaseSTDConnection(STD_CTN *p_stdc);
int releaseDFile(D_FILE *p_file);
unsigned long calStandardData(STD_DATA *p_std);
CALLBACK_STATE(calStandardDataCTN);
unsigned long long calStandardData(STD_DATA *p_std);
__CALLBACK_STATE(calStandardDataCTN);
__CALLBACK_STATE(calStandardDataBLK);
List *_doStandardDataInfoWrite(unsigned int type, void *value, List *er_list);
List *_doStandardDataWrite(unsigned int type, void *value, List *er_list);
List *_doStandardDConnectionWrite(unsigned int type, void *value, List *er_list);
List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list);
__CALLBACK_STATE(StandardDataInfoWrite);
__CALLBACK_STATE(StandardDataWrite);
__CALLBACK_STATE(StandardDConnectionWrite);
__CALLBACK_STATE(StandardDBlockWrite);
STD_DATA *listToSTD(List *);
List *standardDataToList(STD_DATA *);
List *_doStandardDataToList(unsigned int type, void *value, List *er_list);
__CALLBACK_STATE(StandardDataToList);
int readDataFileInfo(D_FILE *p_dfile);
int readStandardData(D_FILE *p_dfile, STD_DATA *p_std);
int readSTDBlocks(STD_BLOCKS *p_stdb);
int checkIfDataFile(D_FILE *p_dfile);
int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid);
__CALLBACK_STATE(findStandardDataBySid);
MSG *createMessage(char *title, void *data, unsigned long data_size);
int sendMessageIPv4(MSG *p_msg, char *ip, unsigned int port);
void printStandardData(void *value);
//STD_DATA *stackToSTD(Stack *);
//STD_DATA *treeToSTD(Tree *);

View File

@ -1,8 +1,8 @@
#include "error.h"
int initErrorSystem(void) {
error_list = initList();
notice_list = initList();
error_list = initList(0);
notice_list = initList(0);
if_error = 1;
return 1;
}

80
id/id.c
View File

@ -18,7 +18,10 @@ unsigned long long getId(void) {
}
SID *initS_id(unsigned int deep_level){
if (!if_rand) init_rand();
if (!if_rand){
init_rand();
if_rand = 1;
}
SID *p_sid = (SID *) malloc(sizeof(SID));
if(p_sid == NULL){
printf("\ninitS_id(): Error in getting the memory of sid.\n");
@ -30,6 +33,8 @@ SID *initS_id(unsigned int deep_level){
p_sid->sr->value_deeper = NULL;
p_sid->sr->value_deepest = NULL;
p_sid->md5 = NULL;
p_sid->decrypt_str = NULL;
p_sid->decrypt_hex = NULL;
return p_sid;
}
@ -64,35 +69,48 @@ SID *getS_id(unsigned int type, unsigned int deep_level){
SID *p_sid = initS_id(deep_level);
getRawS_id(p_sid, type, deep_level);
s_idToMD5(p_sid);
setSidToASCIIString(p_sid);
return p_sid;
}
int fitS_id(SID * const fs_id, SID * const ss_id){
if(fs_id->decrypt_str == NULL) s_idToASCIIString(fs_id);
if(ss_id->decrypt_str == NULL) s_idToASCIIString(ss_id);
if(fs_id->decrypt_str == NULL) setSidToASCIIString(fs_id);
if(ss_id->decrypt_str == NULL) setSidToASCIIString(ss_id);
return strcmp(fs_id->decrypt_str, ss_id->decrypt_str);
}
void setSidToASCIIString(SID * const s_id){
if(s_id->decrypt_str == NULL){
s_id->decrypt_str = malloc(sizeof(char) * 33);
s_id->decrypt_str[32] = '\0';
for(register int i = 0; i < 16; i++){
unsigned int temp_dyt = s_id->decrypt_hex[i];
//printf("%d\n",(unsigned int)temp_dyt);
unsigned int k = 0;
for (k = 0; (temp_dyt - (k * 16)) >= 16; k++);
s_id->decrypt_str[i * 2] = hexToChar(k);
//printf("HEX:%c",hexToChar(k));
s_id->decrypt_str[i * 2 + 1] = hexToChar(temp_dyt - k * 16);
//printf("HEX:%c",hexToChar(temp_dyt - k * 16));
}
}
}
int simFitS_id(SID * fs_id, SID * ss_id){
return !fitS_id(fs_id, ss_id);
}
char *s_idToASCIIString(SID * const s_id){
if(s_id->decrypt_str == NULL){
s_id->decrypt_str = malloc(sizeof(char) * 33);
s_id->decrypt_str[32] = '\0';
for(register int i = 0; i < 16; i++){
unsigned char temp_dyt = s_id->decrypt_hex[i];
unsigned char k = 0;
for (k = 0; temp_dyt - k * 0x10 > 0; k++);
s_id->decrypt_str[i * 2] = hexToChar(k);
s_id->decrypt_str[i * 2 + 1] = hexToChar(temp_dyt - k * 0x10);
}
free(s_id->md5);
s_id->md5 = NULL;
setSidToASCIIString(s_id);
}
free(s_id->md5);
s_id->md5 = NULL;
//printf("s_id->decrypt_str: %s",s_id->decrypt_str);
char *rtn_str = malloc(sizeof(char) * 33);
strcpy(rtn_str, s_id->decrypt_str);
free(s_id->decrypt_hex);
s_id->decrypt_hex = NULL;
return rtn_str;
}
@ -179,7 +197,7 @@ char *s_idToASCIIRawString(SID * const s_id){
}
}
SID *asciiStringToS_id(char * const string){
SID *asciiRawStringToS_id(char * const string){
SID *s_id = NULL;
unsigned long long string_len = strlen(string);
@ -236,14 +254,17 @@ SID *asciiStringToS_id(char * const string){
}
int freeS_id(SID *s_id){
if(s_id == NULL) return 0;
if(s_id->decrypt_hex != NULL) free(s_id->decrypt_hex);
freeSidRaw(s_id);
if (s_id->md5 != NULL) free(s_id->md5);
free(s_id->decrypt_str);
free(s_id);
return 0;
}
int freeSidRaw(SID *s_id){
if (s_id->sr != NULL){
if (s_id != NULL && s_id->sr != NULL){
if(s_id->sr->value != NULL){
free(s_id->sr->value);
s_id->sr->value = NULL;
@ -256,22 +277,25 @@ int freeSidRaw(SID *s_id){
free(s_id->sr->value_deepest);
s_id->sr->value_deepest = NULL;
}
free(s_id->sr);
s_id->sr = NULL;
}
free(s_id->sr);
return 0;
}
void s_idToMD5(SID *s_id){
if(s_id->md5 == NULL) s_id->md5 = malloc(sizeof(MD5_CTX));
char *sid_string = s_idToASCIIRawString(s_id);
s_id->decrypt_hex = malloc(sizeof(unsigned char) * 16);
//printf("%s\n",sid_string);
MD5Init(s_id->md5);
MD5Update(s_id->md5, (unsigned char *) sid_string, strlen(sid_string));
MD5Final(s_id->md5, s_id->decrypt_hex);
freeSidRaw(s_id);
s_id->sr = NULL;
free(sid_string);
}
char hexToChar(unsigned char n){
char hexToChar(unsigned int n){
switch (n) {
case 1:return '1';
case 2:return '2';
@ -296,7 +320,19 @@ char hexToChar(unsigned char n){
SID *copyS_id(SID *f_sid){
SID *s_sid = initS_id(f_sid->deep);
for(int i = 0; i < 16; i++)
s_sid->decrypt_hex[i] = f_sid->decrypt_hex[i];
return 0;
if(s_sid->decrypt_str == NULL) s_sid->decrypt_str = malloc(sizeof(char) * SID_LEN);
if (f_sid->decrypt_str != NULL) strcpy(s_sid->decrypt_str, f_sid->decrypt_str);
else{
freeS_id(s_sid);
return NULL;
};
return s_sid;
}
SID *setS_idWithString(char *p_string){
if(p_string == NULL) return NULL;
SID *p_sid = initS_id(0);
if(p_sid->decrypt_str == NULL) p_sid->decrypt_str = malloc(sizeof(char) * SID_LEN);
strcpy(p_sid->decrypt_str, p_string);
return p_sid;
}

View File

@ -17,10 +17,12 @@ int fitS_id(SID * const fs_id, SID * const ss_id);
int simFitS_id(SID * fs_id, SID * ss_id);
char *s_idToASCIIString(SID * const s_id);
SID *asciiStringToS_id(char * const string);
void setSidToASCIIString(SID * const s_id);
SID *asciiRawStringToS_id(char * const string);
SID *setS_idWithString(char *);
void s_idToMD5(SID *s_id);
char hexToChar(unsigned char);
char hexToChar(unsigned int);
SID *copyS_id(SID *f_sid);
void getRawS_id(SID *s_id, unsigned int type, unsigned int deep_level);

View File

@ -230,7 +230,7 @@ int releaseNode(Node *p_node) {
releaseList((List *)p_node->value);
}
else {
//free(p_node->value);
free(p_node->value);
}
}
p_node->value = NULL;
@ -268,6 +268,8 @@ int releaseList(List *p_list) {
p_list->head = NULL;
p_list->tail = NULL;
p_list->length = 0;
p_list->s_head = NULL;
p_list->s_tail = NULL;
if (p_list->s_id != NULL) freeS_id(p_list->s_id);
if(p_list->p_lq != NULL) disableListQuick(p_list);
free(p_list);
@ -275,12 +277,7 @@ int releaseList(List *p_list) {
}
int releaseListForSingle(List *p_list) {
p_list->head = NULL;
p_list->tail = NULL;
if (p_list->s_id != NULL) freeS_id(p_list->s_id);
if(p_list->p_lq != NULL) disableListQuick(p_list);
p_list->length = 0;
free(p_list);
releaseList(p_list);
return 0;
}
@ -350,9 +347,10 @@ int removeByNode(List *p_list, Node *p_node) {
return 0;//not find
}
int popFromHead(List *p_list) {
Node *popFromHead(List *p_list) {
if (isListEmpty(p_list))
return -1;
return NULL;
Node *p_node = p_list->head;
if(p_list->p_lq != NULL){
if(p_list->p_lq->fn_node[0] == p_list->head){
digHole(p_list, p_list->head);
@ -369,12 +367,13 @@ int popFromHead(List *p_list) {
}
p_list->length -= 1;
}
return 0;
return p_node;
}
int popFromTail(List *p_list) {
Node *popFromTail(List *p_list) {
Node *p_node = p_list->tail;
if (isListEmpty(p_list))
return -1;
return NULL;
else {
if(p_list->p_lq != NULL){
if(p_list->p_lq->fn_node[p_list->p_lq->rlst_len] == p_list->tail)
@ -391,7 +390,7 @@ int popFromTail(List *p_list) {
p_list->tail = NULL;
}
p_list->length -= 1;
return 0;
return p_node;
}
Node *findByIdForNode(List *p_list, SID * s_id) {
@ -420,7 +419,6 @@ Node *findByIdForNode(List *p_list, SID * s_id) {
return NULL;
}
Node *findByValue(List *p_list, unsigned int type, const void *value) {
Node *p_node = p_list->head;
while (p_node != NULL) {
@ -734,7 +732,7 @@ int sortList(List *p_list, unsigned long long begin, unsigned long long end, int
return 0;
}
int sortListByCustom(List *p_list, int(*func)(Node *f_node, Node *s_node)){
int sortListForCustom(List *p_list, int(*func)(Node *f_node, Node *s_node)){
if(p_list->p_lq != NULL && !p_list->p_lq->if_sort) p_list->p_lq->if_sort = 1;
sortList(p_list, 0, p_list->length-1, func);
return 0;

View File

@ -4,6 +4,8 @@
#include "../id/id.h"
#define lni(x) nodeWithInt(x,0)
#define lnu(x) nodeWithUInt(x,0)
#define lnull(x) nodeWithULLInt(x,0)
#define lnd(x) nodeWithDouble(x,0)
#define lns(x) nodeWithString(x,0)
#define lnp(x) nodeWithPointer(x,0)
@ -15,6 +17,8 @@
#define lisrti(list, x) insertInTail(list, lni(x));
#define lisrtd(list, x) insertInTail(list, lnd(x));
#define lisrtu(list, x) insertInTail(list, lnu(x));
#define lisrtull(list, x) insertInTail(list, lnull(x));
#define lisrtp(list, x) insertInTail(list, lnp(x));
#define lisrts(list, x) insertInTail(list, lns(x));
@ -23,6 +27,8 @@
#define lidxd(list, x) getByDoubleForNode(findByIndexForNode(list, x))
#define lidxs(list, x) getByStringForNode(findByIndexForNode(list, x))
#define lupdull(list,x,value) updateValueWithULLIntForNode(findByIndexForNode(list, x),value)
int safeModeForNode(int ifon);
int releaseSingleListForsafeModeForNode(List *p_list);
int releaseSingleNodeForsafeModeForNode(List *p_list);
@ -48,12 +54,13 @@ Node *copyNode(Node *);
int removeById(List *p_list, SID *s_id);
int removeByNode(List *p_list, Node *p_node);
int popFromHead(List *p_list);
int popFromTail(List *p_list);
Node *popFromHead(List *p_list);
Node *popFromTail(List *p_list);
unsigned long long len(List *p_list);
Node *findByIdForNode(List *p_list, SID * s_id);
void *findByIdForCustom(List *p_list, SID *s_id, int func(SID *));
Node *findByValue(List *p_list, unsigned int type, const void *value);
List *mply_findByValue(List *p_list, unsigned int type, const void *value);
@ -89,7 +96,7 @@ int showWarning(Notice *);
int enableListQuick(List *p_list);
int refreshFnNode(List *p_list);
int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node));
int sortListByCustom(List *p_list, int(*func)(Node *f_node, Node *s_node));
int sortListForCustom(List *p_list, int(*func)(Node *f_node, Node *s_node));
int indexTransfromer(List *p_list, unsigned long long m_index);
int indexChange(List *p_list, unsigned long long c_index, int move);
Node *getNodeByFnNode(List *p_list, unsigned long long index);

View File

@ -79,6 +79,7 @@ Node *nodeWithComplex(void) {
}
Node *findByIndexForNode(List *p_list, unsigned long long m_index) {
if(p_list == NULL) return NULL;
if(p_list->p_lq != NULL){
register struct list_quick *p_lq = p_list->p_lq;
if(p_lq->fn_node != NULL) return getNodeByFnNode(p_list, m_index);
@ -103,11 +104,12 @@ s_Node *s_findByIndexForNode(List *p_list, unsigned long long m_index) {
List *listThrough(List *p_list, List *(*p_func)(unsigned int, void *, List *), List *expand_resources) {
Node *p_node = p_list->head;
List *m_rtnlst = NULL;
unsigned long long count = 0;
insertInTail(expand_resources, nodeWithULLInt(count, 0));
unsigned long long index = 0;
insertInTail(expand_resources, nodeWithULLInt(index, 0));
insertInTail(expand_resources, nodeWithULLInt(p_list->length, 0));
while (p_node != NULL) {
if (p_node->value != NULL) {
List *m_rtnlst = (*p_func)(p_node->type, p_node->value, expand_resources);
m_rtnlst = (*p_func)(p_node->type, p_node->value, expand_resources);
int status = getByIntForNode(findByIndexForNode(m_rtnlst, 0));
if (status == -1) break;
else if (status == 1) {
@ -120,10 +122,23 @@ List *listThrough(List *p_list, List *(*p_func)(unsigned int, void *, List *), L
releaseList(m_rtnlst);
m_rtnlst = NULL;
}
}
}
lupdull(expand_resources,expand_resources->length-2,++index);
p_node = p_node->next;
}
}
releaseList(expand_resources);
if(m_rtnlst != NULL) releaseNode(popFromHead(m_rtnlst));
return m_rtnlst;
}
unsigned long long getInfoForListThrough(List *expand_resources, int type){
Node *p_node = NULL;
if (type == 0) {
p_node = findByIndexForNode(expand_resources, expand_resources->length-1);
}else{
p_node = findByIndexForNode(expand_resources, expand_resources->length-2);
}
return *((unsigned long long *)p_node->value);
}
int getByIntForNode(Node *p_node) {
@ -147,8 +162,7 @@ double getByDoubleForNode(Node *p_node) {
}
void *getByPointerForNode(Node *p_node) {
if (p_node->type == POINTER) return (void *)(p_node->value);
else return NULL;
return (void *)(p_node->value);
}
void printListInfo(List *p_list, int priority) {
@ -359,7 +373,7 @@ int addPointerForComplex(Node *p_node, void *temp) {
return -1;
}
List *m_findByInt(List* p_list, int temp) {
List *mply_findByInt(List* p_list, int temp) {
int *p_temp = (int *)malloc(sizeof(int));
if(p_temp == NULL){
showError(pushError(INT, STANDARD, initInfo("m_findByInt()", "Error in getting the memory of int.")));
@ -372,7 +386,7 @@ List *m_findByInt(List* p_list, int temp) {
return t_list;
}
List *m_findByDouble(List* p_list, double temp) {
List *mply_findByDouble(List* p_list, double temp) {
List *t_list;
double *p_temp = (double *)malloc(sizeof(double));
if(p_temp == NULL){
@ -385,7 +399,7 @@ List *m_findByDouble(List* p_list, double temp) {
return t_list;
}
List *m_findByString(List* p_list, char *temp) {
List *mply_findByString(List* p_list, char *temp) {
List *t_list;
char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1));
if(p_temp == NULL){
@ -398,7 +412,7 @@ List *m_findByString(List* p_list, char *temp) {
return t_list;
}
List *m_findByPointer(List* p_list, void *temp) {
List *mply_findByPointer(List* p_list, void *temp) {
List *t_list = mply_findByValue(p_list, DOUBLE, (void *)temp);
return t_list;
}
@ -421,7 +435,7 @@ unsigned long long getIndexByNode(List *p_list, Node *p_node) {
return 0;
}
List *plym_findByIntForNode(List* p_list, int temp) {
List *mply_findByIntForNode(List* p_list, int temp) {
int *p_temp = (int *)malloc(sizeof(int));
if(p_temp == NULL){
showError(pushError(INT, STANDARD, initInfo("m_findByIntForNode()", "Error in getting the memory of int.")));
@ -466,7 +480,7 @@ unsigned long long calListMemory(List * p_list){
return list_size + nodes_size;
}
int updateValueWithInt(Node *p_node,int value){
int updateValueWithIntForNode(Node *p_node,int value){
int *p_value = (int *)malloc(sizeof(int));
if(p_value == NULL){
showError(pushError(INT, STANDARD, initInfo("updateValueWithInt()", "Error in getting the memory of int.")));
@ -476,9 +490,21 @@ int updateValueWithInt(Node *p_node,int value){
free(p_node->value);
p_node->value = p_value;
return 0;
}
int updateValueWithULLIntForNode(Node *p_node, unsigned long long value){
unsigned long long *p_value = (unsigned long long *)malloc(sizeof(unsigned long long));
if(p_value == NULL){
showError(pushError(INT, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of int.")));
return -1;
}
*p_value = value;
free(p_node->value);
p_node->value = p_value;
return 0;
}
int updateValueWithDouble(Node *p_node, double value){
int updateValueWithDoubleForNode(Node *p_node, double value){
double *p_value = (double *)malloc(sizeof(double));
if(p_value == NULL){
showError(pushError(DOUBLE, STANDARD, initInfo("updateValueWithDouble()", "Error in getting the memory of double.")));
@ -490,7 +516,7 @@ int updateValueWithDouble(Node *p_node, double value){
return 0;
}
int updateValueWithString(Node *p_node, char *string){
int updateValueWithStringForNode(Node *p_node, char *string){
char *p_value = (char *)malloc(sizeof(strlen(string)) + 1);
if(p_value == NULL){
showError(pushError(STRING, STANDARD, initInfo("updateValueWithString()", "Error in getting the memory of string.")));
@ -502,7 +528,7 @@ int updateValueWithString(Node *p_node, char *string){
return 0;
}
int updateValueWithPointer(Node *p_node, void *pointer){
int updateValueWithPointerForNode(Node *p_node, void *pointer){
free(p_node->value);
p_node->value = pointer;
return 0;
@ -577,6 +603,20 @@ List *newReturn(int if_status ,int status, char *argc, ...){
case 'p':
lisrtp(p_list, va_arg(args, void *));
break;
case 'u':
if(argc[count + 2] == 'l'){
if(argc[count + 3] == 'l'){
lisrtull(p_list, va_arg(args, unsigned long long));
count += 2;
}
else{
count++;
}
}
else{
lisrtu(p_list, va_arg(args, unsigned int));
}
break;
default:
break;
}
@ -592,3 +632,19 @@ List *newReturn(int if_status ,int status, char *argc, ...){
List *newCReturn(void){
return newReturn(1, 0, NULL);
}
void printListForCustom(List *p_list,void (*func)(void *value)){
printf("###LIST (LEN:%llu ",p_list->length);
if(p_list->s_id != NULL) printf("SID:%s",p_list->s_id->decrypt_str);
printf(")\n");
listThrough(p_list, __CALLBACK_CALL(printListForCustom), __SEND_ARG("%p", func));
}
__CALLBACK_DEFINE(printListForCustom){
void (*func)(void *) = __ARGS_P(0, void);
printf("NODE (IDX:%llu ",__NOW_INDEX);
printf(")\n");
func(__VALUE(void *));
printf("\n");
return __CRETURN__;
}

View File

@ -3,18 +3,19 @@
#include "list.h"
#define RETURN(argc, args...) newReturn(1, -1, argc , args)
#define C_RETURN newCReturn()
#define SEND_ARG(argc, args...) newReturn(0, -1, argc , args)
#define CALLBACK_STATE(name) List *do_##name(unsigned int, void *, List *)
#define CALLBACK_DEFINE(name) List *do_##name(unsigned int type, void *value, List *args)
#define VALUE(c_type) (c_type)value
#define ARGS(x, type)\
if(#type == "int") lidxi(args, x);\
else if if(#type == "double") lidxd(args, x);\
else if(#type == "string") lidxs(args, x);\
else lidxi(args, x);
#define CALLBACK_CALL(name) do_##name
#define __RETURN(argc, args...) newReturn(1, -1, argc , args)
#define __CRETURN__ newCReturn()
#define __SEND_ARG(argc, args...) newReturn(0, -1, argc , args)
#define __CALLBACK_STATE(name) List *_do##name(unsigned int, void *, List *)
#define __CALLBACK_DEFINE(name) List *_do##name(unsigned int type, void *value, List *expand_resources)
#define __VALUE(c_type) (c_type)value
#define __ARGS(x, type) *((type *) lidxp(expand_resources, x));
#define __ARGS_P(x, type) (type *) lidxp(expand_resources, x);
#define __CALLBACK_CALL(name) _do##name
#define __LIST_LEN getInfoForListThrough(expand_resources,0)
#define __NOW_INDEX getInfoForListThrough(expand_resources,1)
#define __RTN_ARGS_P(list,x,type) (type *) lidxp(list, x);
#define __RTN_ARGS(list,x,type) *((type *) lidxp(list, x));
Node *nodeWithInt(int, _Bool if_sid);
Node *nodeWithUInt(unsigned int, _Bool if_sid);
@ -37,6 +38,7 @@ int addStringForComplex(Node *, char *);
int addPointerForComplex(Node *, void *);
int updateValueWithIntForNode(Node *,int);
int updateValueWithULLIntForNode(Node *, unsigned long long);
int updateValueWithDoubleForNode(Node *,double);
int updateValueWithStringForNode(Node *,char *);
int updateValueWithPointerForNode(Node *,void *);
@ -48,12 +50,16 @@ List *mply_findByPointerForNode(List*, void *);
void printListInfo(List *p_list,int priority);
void printNodeInfo(Node *p_node,int priority);
void printList(List *);
void printNode(Node *p_node);
void printList(List *);
void printListForCustom(List *p_list,void (*func)(void *value));
void printNode(Node *p_node);
__CALLBACK_STATE(printListForCustom);
List *listThrough(List *p_list, List *(*p_func)(unsigned int type, void *value, List *), List *expand_resources);
List *newReturn(int if_status ,int status, char *argc, ...);
List *newCReturn(void);
unsigned long long getInfoForListThrough(List *expand_resources, int type);
unsigned long long calListMemory(List *);
#endif

View File

@ -19,7 +19,6 @@ SNode *initSNode(void) {
return NULL;
}
p_snode->s_id = getS_id(STACK_NODE, 1);
p_snode->if_malloc = 0;
p_snode->next = NULL;
p_snode->value = NULL;
return p_snode;
@ -61,7 +60,6 @@ int releaseStack(Stack *p_stack) {
int releaseSNode(SNode *p_snode) {
freeS_id(p_snode->s_id);
free(p_snode->value);
p_snode->if_malloc = 0;
p_snode->value = NULL;
p_snode->type = VOID;
free(p_snode);
@ -69,7 +67,6 @@ int releaseSNode(SNode *p_snode) {
}
int initMallocValueForSNode(SNode *p_snode, unsigned int type, void *value) {
p_snode->if_malloc = 1;
p_snode->type = type;
p_snode->value = value;
return 0;

70
test.c
View File

@ -2,48 +2,29 @@
int list(void) {
List *t_list, *m_list;;
safeModeForNode(1);
t_list = initList();
/*for(int i = 0; i < 9; i++){
Node *t_node = initNode();
int *t_i = (int *)malloc(sizeof(int));
*t_i = i;
initMallocValue(t_node,"int",(void *)t_i);
insertInTail(t_list,t_node);
}*/
/*Node *t_node = initNode();
insertInTail(t_list,t_node);
initMalllocValue(t_node,(void *)"there");*/
for (int i = 0; i < 12; i++) {
insertInHead(t_list, nodeWithInt(i));
insertInTail(t_list, nodeWithInt(i));
}
printListInfo(t_list, 0);
printList(t_list);
m_list = m_findByIntForNode(t_list, 5);
printList(m_list);
printf("\n");
releaseAllForNode();
List *p_list = initList(1);
for(int i = 0; i < 12; i++){
insertInTail(p_list, nodeWithInt(i, 0));
}
D_FILE *pd_file = initDataFileForWrite("data.db");
STD_DATA *p_std = listToSTD(p_list);
STD_DATA *pa_std = listToSTD(p_list);
dataFileAddStandardData(pd_file, p_std);
dataFileAddStandardData(pd_file, pa_std);
dataFileWriteIn(pd_file);
releaseList(p_list);
releaseDFile(pd_file);
return 0;
}
int _useTreeThroughDown(TNode *p_tnode, unsigned long long height) {
/*int _useTreeThroughDown(TNode *p_tnode, unsigned long long height) {
printTNode(p_tnode,0);
return 0;
}
}*/
int tree(void) {
/*int tree(void) {
TNode *t_tnode, *cr_tnode, *cl_tnode;
Tree *t_tree;
TNode *gs_tnode;
@ -65,7 +46,7 @@ int tree(void) {
//printTNodeWithFamily(t_tnode, 0);
releaseAllForTree();
return 0;
}
}*/
int stack(void) {
int i;
@ -82,9 +63,20 @@ int stack(void) {
int main(int argc, char **argv) {
SID *p_sid = getS_id(VOID, 2);
s_idToASCIIString(p_sid);
printf("%s",p_sid->decrypt_str);
freeS_id(p_sid);
for (int i = 0; i < 65535; i++){
list();
/*D_FILE *p_dfile = initDataFileForRead("data.db");
readDataFileInfo(p_dfile);
SID *temp_sid = setS_idWithString("f7dd8f0a75a0c20e4dca1b78347083cf");
readStandardDataBySid(p_dfile, temp_sid);
freeS_id(temp_sid);
printListForCustom(p_dfile->pf_stdlst, printStandardData);
List *t_list = standardDataToList(p_dfile->pf_stdlst->head->value);
printList(t_list);
releaseList(t_list);
releaseDFile(p_dfile);*/
usleep(500);
}
return 0;
}

2
test.h
View File

@ -4,7 +4,7 @@
#include "type/type.h"
#include "list/list_expand.h"
#include "stack/stack_expand.h"
#include "tree/tree_expand.h"
//#include "tree/tree_expand.h"
#include "communicate/communicate.h"
int stack(void);

View File

@ -46,13 +46,15 @@
#define DEEP_LEN 25
#define DEEPER_LEN 65
#define DEEPEST_LEN 225
#define SID_LEN 32
#define SID_LEN 33
#define FILE_TSET_LEN 18
#define HEAD_TEST_LEN 9
#define INFO_TEST_LEN 8
#define ENABLE_LIST_QUICK 1500
#define FN_NODE_SPARE 12
#define INDEX_CHANGE_MAX 500
#define INDEX_DISTANCE_MAX 120
#define STD_TEXT_LEN 4
#define HIGH 0x3
#define STANDARD 0x2
@ -77,7 +79,7 @@ typedef struct s_id{
struct sid_raw *sr;
unsigned int deep;
MD5_CTX *md5;
unsigned char decrypt_hex[16];
unsigned char *decrypt_hex;
char *decrypt_str;
}SID;
@ -202,6 +204,7 @@ typedef struct data_file{
typedef struct standard_data_blocks{
unsigned int type;
unsigned long long location;
char *sid;
_Bool if_data;
unsigned int blocks_num;
@ -209,6 +212,7 @@ typedef struct standard_data_blocks{
}STD_BLOCKS;
typedef struct standard_data_connection{
unsigned long long location;
char *f_sid;
char *s_sid;
}STD_CTN;
@ -221,6 +225,8 @@ typedef struct standard_data_head{
typedef struct standard_data{
SID *s_id;
unsigned int type;
unsigned long long size;
unsigned long long location;
_Bool lock;
List *pd_blocklst;
List *pd_ctnlst;