From d8cac27242204e6e6577b4cfe688e6984744f3dc Mon Sep 17 00:00:00 2001 From: Saturneic Date: Tue, 7 Aug 2018 12:10:55 +0800 Subject: [PATCH 01/12] Add and Fixed. --- .../xcdebugger/Expressions.xcexplist | 136 +++- .../xcdebugger/Breakpoints_v2.xcbkptlist | 706 +++++++++++++++++- communicate/communicate.c | 265 +++++++ communicate/communicate.h | 71 ++ list/list.c | 14 +- list/list.h | 2 +- list/list_expand.c | 155 +++- list/list_expand.h | 18 +- stack/stack.c | 4 +- stack/stack.h | 17 +- stack/stack_expand.c | 18 +- test.c | 23 +- test.h | 3 +- tree/tree.c | 93 ++- tree/tree.h | 4 +- tree/tree_expand.c | 18 +- type/type.h | 26 + 17 files changed, 1399 insertions(+), 174 deletions(-) diff --git a/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist b/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist index d8ca57a..1d0c1c5 100644 --- a/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist +++ b/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -3,7 +3,62 @@ version = "1.0"> + contextName = "init_node:list.h"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -22,6 +77,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -33,44 +127,22 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index e74a180..c3ec7ec 100644 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -154,7 +154,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "554986718.90595" + timestampString = "555307651.589517" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "64" @@ -186,7 +186,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "554986718.906109" + timestampString = "555307651.589684" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "19" @@ -202,12 +202,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "554986718.906213" + timestampString = "555307651.589751" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "99" endingLineNumber = "99" - landmarkName = "simFitS_id" + landmarkName = "s_idToASCIIString" landmarkType = "9"> @@ -218,13 +218,13 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "554986718.906307" + timestampString = "555307651.589806" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "102" endingLineNumber = "102" - landmarkName = "unknown" - landmarkType = "0"> + landmarkName = "s_idToASCIIString" + landmarkType = "9"> + + + + @@ -397,23 +413,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "554986718.90746" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "184" - endingLineNumber = "184" - landmarkName = "s_idToASCIIString" - landmarkType = "9"> - - - - @@ -509,7 +509,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "554986718.908048" + timestampString = "555307651.590819" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "217" @@ -518,5 +518,629 @@ landmarkType = "9"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/communicate/communicate.c b/communicate/communicate.c index 32dc9ac..73a86a5 100644 --- a/communicate/communicate.c +++ b/communicate/communicate.c @@ -1 +1,266 @@ #include "communicate.h" + +STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned long long data_size){ + STD_BLOCKS *p_stdb = (STD_BLOCKS *)malloc(sizeof(STD_BLOCKS)); + p_stdb->sid = s_idToASCIIString(p_sid); + p_stdb->if_data = 0; + unsigned int blocks_num = (unsigned int)(data_size/sizeof(char)); + p_stdb->blocks_num = blocks_num; + p_stdb->buff = (char *)malloc(sizeof(char) * blocks_num); + return p_stdb; +} + +int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data){ + char *t_data = (char *)data; + /*unsigned int data_size = sizeof(data);*/ + + for(int i = 0; i < p_stdb->blocks_num; i++){ + p_stdb->buff[i] = t_data[i]; + } + p_stdb->if_data = 1; + return 0; +} + +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); + return p_stdc; +} + +STD_DATA *initStandardData(unsigned int type){ + STD_DATA *p_std = (STD_DATA *)malloc(sizeof(STD_DATA)); + p_std->pd_blocklst = initList(); + p_std->pd_ctnlst = initList(); + p_std->lock = 0; + p_std->type = type; + p_std->s_id = getS_id(STANDARD_DATA, 2); + return p_std; +} + +int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,void *data, unsigned long long data_size){ + if (p_std->lock) return -1; + STD_BLOCKS *p_stdb = initStandardDBlocks(p_sid, data_size); + dataForStandardDBlock(p_stdb, data); + insertInTail(p_std->pd_blocklst, nodeWithPointer(p_stdb)); + return 0; +} + +int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid){ + if (p_std->lock) return -1; + STD_CTN *p_stdb = initStandardDConnection(f_sid, s_sid); + insertInTail(p_std->pd_ctnlst, nodeWithPointer(p_stdb)); + return 0; +} + +D_FILE *initDataFileForWrite(char *route){ + D_FILE *p_dfile = (D_FILE *)malloc(sizeof(D_FILE)); + p_dfile->fp = fopen(route, "wb"); + p_dfile->pf_head = (F_HEAD *)malloc(sizeof(F_HEAD)); + strcpy(p_dfile->pf_head->head_test,"ZESTDLIB_STDDFILE"); + p_dfile->pf_head->data_num = 0; + p_dfile->pf_stdlst = initList(); + return p_dfile; +} + +D_FILE *initDataFileForRead(char *route){ + D_FILE *p_dfile = (D_FILE *)malloc(sizeof(D_FILE)); + p_dfile->fp = fopen(route, "rb"); + p_dfile->pf_head = (F_HEAD *)malloc(sizeof(F_HEAD)); + p_dfile->pf_head->data_num = 0; + p_dfile->pf_stdlst = initList(); + return p_dfile; +} + +int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){ + insertInTail(p_dfile->pf_stdlst, nodeWithPointer(p_std)); + p_dfile->pf_head->data_num = p_dfile->pf_stdlst->length; + return 0; +} + +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(); + insertInTail(er_list, nodeWithPointer(p_dfile->fp)); + /*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); + return 0; +} +List *_doStandardDataInfoWrite(unsigned int type, void *value, List *er_list){ + List *p_rtnlst = initList(); + FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); + STD_DATA *p_std = value; + insertInTail(p_rtnlst, nodeWithInt(0)); + char *string_sid = s_idToASCIIString(p_std->s_id); + fwrite(string_sid, sizeof(char), DEEPER_LEN, fp); + free(string_sid); + 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(); + FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); + insertInTail(p_rtnlst, nodeWithInt(0)); + STD_DATA *p_std = value; + List *erc_list = initList(); + insertInTail(erc_list, nodeWithPointer(fp)); + fwrite("STD", sizeof(char), 4, fp); + char *string_sid = s_idToASCIIString(p_std->s_id); + unsigned long sid_len = strlen(string_sid) + 1; + fwrite(&sid_len, sizeof(unsigned long), 1, fp); + char *sid_w = s_idToASCIIString(p_std->s_id); + fwrite(sid_w, 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); + free(sid_w); + free(string_sid); + return p_rtnlst; +} + +List *_doStandardDConnectionWrite(unsigned int type, void *value, List *er_list){ + List *p_rtnlst = initList(); + insertInTail(p_rtnlst, nodeWithInt(0)); + FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); + STD_CTN *p_stdc = value; + unsigned long fsid_len = strlen(p_stdc->f_sid) + 1, ssid_len = strlen(p_stdc->s_sid)+1; + fwrite(&fsid_len, sizeof(unsigned long), 1, fp); + fwrite(p_stdc->f_sid, sizeof(char), fsid_len, fp); + fwrite(&ssid_len, sizeof(unsigned long), 1, fp); + fwrite(p_stdc->s_sid, sizeof(char), ssid_len, fp); + return p_rtnlst; +} + +List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list){ + List *p_rtnlst = initList(); + insertInTail(p_rtnlst, nodeWithInt(0)); + STD_BLOCKS *p_stdb = value; + FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); + unsigned long sid_len = strlen(p_stdb->sid)+1, blocks_num = p_stdb->blocks_num; + fwrite(&sid_len, sizeof(unsigned long), 1, fp); + fwrite(p_stdb->sid, sizeof(char), sid_len, fp); + fwrite(&blocks_num, sizeof(unsigned long), 1, fp); + fwrite(p_stdb->buff, sizeof(char), p_stdb->blocks_num, fp); + return p_rtnlst; +} + +STD_DATA *listToSTD(List *p_list){ + STD_DATA *p_std = initStandardData(LIST); + Node *p_node = p_list->head; + while (p_node != NULL) { + unsigned long long data_size = 0; + if(p_node->type == INT) data_size = sizeof(int); + else if (p_node->type == DOUBLE) data_size = sizeof(double); + else if (p_node->type == STRING) data_size = strlen((char *)p_node->value) + 1; + else data_size = sizeof(void *); + standardDataAddBlock(p_std, p_node->s_id, p_node->value, data_size); + p_node = p_node->next; + } + return p_std; +} + +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 sid_len = 0, ctn_num = 0, blk_num = 0; + unsigned int type = 0; + fread(&sid_len, sizeof(unsigned long), 1, p_dfile->fp); + char *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); + 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++){ + fread(&sid_len, sizeof(unsigned long), 1, p_dfile->fp); + char *fstring_sid = (char *)malloc(sizeof(char) * sid_len); + fread(fstring_sid, sizeof(char), sid_len, p_dfile->fp); + fread(&sid_len, sizeof(unsigned long), 1, 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(&sid_len, sizeof(unsigned long), 1, p_dfile->fp); + char *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); + standardDataAddBlock(p_std, s_id, content, blk_len); + freeS_id(s_id); + free(string_sid); + free(content); + } + return 0; + } + else break; + } + } + } + showError(pushError(DATA_FILE, STANDARD, initInfo("dataFileReadOut()", "Datafile not complete."))); + return -1; +} + +int releaseSTDConnection(STD_CTN *p_stdc){ + free(p_stdc->f_sid); + free(p_stdc->s_sid); + free(p_stdc); + return 0; +} + +int releaseSTDBlocks(STD_BLOCKS *p_stdb){ + free(p_stdb->sid); + free(p_stdb->buff); + free(p_stdb); + return 0; +} + +int releaseStandardData(STD_DATA *p_std){ + freeS_id(p_std->s_id); + releaseListForCustom(p_std->pd_blocklst, (int (*)(void *))releaseSTDBlocks); + releaseListForCustom(p_std->pd_ctnlst, (int (*)(void *))releaseSTDConnection); + free(p_std); + return 0; +} + +int releaseDFile(D_FILE *p_dfile){ + releaseListForCustom(p_dfile->pf_stdlst, (int (*)(void *))releaseStandardData); + fclose(p_dfile->fp); + free(p_dfile->pf_head); + free(p_dfile); + return 0; +} diff --git a/communicate/communicate.h b/communicate/communicate.h index 4798a3f..bb15f73 100644 --- a/communicate/communicate.h +++ b/communicate/communicate.h @@ -1,6 +1,77 @@ #ifndef communicate_h #define communicate_h +#include "../type/type.h" +#include "../list/list_expand.h" +typedef struct message{ + SID *p_sid; + char titile[16]; + char content[0]; +}MSG; + +typedef struct file_head{ + char head_test[18]; + unsigned long long data_num; +}F_HEAD; + +typedef struct data_file{ + FILE *fp; + F_HEAD *pf_head; + List *pf_stdlst; +}D_FILE; + +typedef struct standard_data_blocks{ + unsigned int type; + char *sid; + _Bool if_data; + unsigned int blocks_num; + char *buff; +}STD_BLOCKS; + +typedef struct standard_data_connection{ + char *f_sid; + char *s_sid; +}STD_CTN; + +typedef struct standard_data_head{ + unsigned long long data_blk_num; + unsigned long long data_ctn_num; +}STD_HEAD; + +typedef struct standard_data{ + SID *s_id; + unsigned int type; + _Bool lock; + List *pd_blocklst; + List *pd_ctnlst; +}STD_DATA; + +D_FILE *initDataFileForWrite(char *route); +D_FILE *initDataFileForRead(char *route); +STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned long long data_size); +STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid); +STD_DATA *initStandardData(unsigned int type); + +int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data); +int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std); +int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,void *data, unsigned long long data_size); +int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid); +int dataFileWriteIn(D_FILE *p_dfile); +int dataFileReadOut(D_FILE *p_dfile); + +int releaseSTDBlocks(STD_BLOCKS *p_stdb); +int releaseStandardData(STD_DATA *p_std); +int releaseSTDConnection(STD_CTN *p_stdc); +int releaseDFile(D_FILE *p_file); + +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); + +STD_DATA *listToSTD(List *); +STD_DATA *stackToSTD(Stack *); +STD_DATA *treeToSTD(Tree *); #endif /* communicate_h */ diff --git a/list/list.c b/list/list.c index b4c3abd..2c86746 100644 --- a/list/list.c +++ b/list/list.c @@ -9,12 +9,12 @@ int safeModeForNode(int ifon) { if (node_list == NULL && list_list == NULL) { node_list = (List *)malloc(sizeof(List)); if(node_list == NULL){ - showError(pushError(LIST, HIGH, initInfo("safeModeForNode()", "Error in get the memory of node_list."))); + showError(pushError(LIST, HIGH, initInfo("safeModeForNode()", "Error in getting the memory of node_list."))); return -1; } list_list = (List *)malloc(sizeof(List)); if(list_list == NULL){ - showError(pushError(LIST, HIGH, initInfo("safeModeForNode()", "Error in get the memory of list_list."))); + showError(pushError(LIST, HIGH, initInfo("safeModeForNode()", "Error in getting the memory of list_list."))); return -1; } list_list->head = NULL; @@ -89,7 +89,7 @@ int releaseAllForNode(void) { Node *initNode(void) { Node *p_node = (Node *)malloc(sizeof(Node)); if(p_node == NULL){ - showError(pushError(LIST_NODE, STANDARD, initInfo("initNode()", "Error in get the memory of node."))); + showError(pushError(LIST_NODE, STANDARD, initInfo("initNode()", "Error in getting the memory of node."))); return NULL; } Node *prec_node = NULL; @@ -113,7 +113,7 @@ List *initList(void) { Node *p_node = NULL; List *p_list = (List *)malloc(sizeof(List)); if(p_list == NULL){ - showError(pushError(LIST_NODE, STANDARD, initInfo("initList()", "Error in get the memory of list."))); + showError(pushError(LIST_NODE, STANDARD, initInfo("initList()", "Error in getting the memory of list."))); return NULL; } p_list->s_id = getS_id(LIST, 1); @@ -131,10 +131,10 @@ List *initList(void) { return p_list; } -int initMallocValueForNode(Node *p_node, unsigned int type, void *p_value) { +int initMallocValueForNode(Node *p_node, unsigned int type, const void *p_value) { p_node->if_malloc = 1; p_node->type = type; - p_node->value = p_value; + p_node->value = (void *)p_value; return 0; } @@ -479,7 +479,7 @@ int releaseNodeForCustom(Node *p_node, int (*func)(void *)){ removeByNode(node_list, p_node); } if (p_node->if_malloc == 1) { - if (!func(p_node->value)) + if (func(p_node->value)) showError(pushError(LIST_NODE, STANDARD, initInfo("releaseNodeForCustom()", "Error in using custom freeing value function."))); p_node->value = NULL; } diff --git a/list/list.h b/list/list.h index 349b525..9124f4b 100644 --- a/list/list.h +++ b/list/list.h @@ -11,7 +11,7 @@ int releaseAllForNode(void); List *initList(void); Node *initNode(void); -int initMallocValueForNode(Node *,unsigned int,void *); +int initMallocValueForNode(Node *,unsigned int,const void *); int insertInHead(List *p_list, Node *p_node); int insertInTail(List *p_list, Node *p_node); diff --git a/list/list_expand.c b/list/list_expand.c index e0cf001..411163d 100644 --- a/list/list_expand.c +++ b/list/list_expand.c @@ -2,16 +2,37 @@ Node *nodeWithInt(int m_int) { Node *p_node; - int *p_int = (int *)malloc(sizeof(int)); + int *p_int = (int *)malloc(sizeof(int)); + if(p_int == NULL){ + showError(pushError(INT, STANDARD, initInfo("nodeWithInt()", "Error in getting the memory of int."))); + return NULL; + } *p_int = m_int; p_node = initNode(); initMallocValueForNode(p_node, INT, (void *)p_int); return p_node; +} + +Node *nodeWithUInt(unsigned int m_uint){ + Node *p_node; + unsigned int *pu_int = (unsigned int *)malloc(sizeof(unsigned int)); + if(pu_int == NULL){ + showError(pushError(INT, STANDARD, initInfo("nodeWithUInt()", "Error in getting the memory of int."))); + return NULL; + } + *pu_int = m_uint; + p_node = initNode(); + initMallocValueForNode(p_node, INT, (void *)pu_int); + return p_node; } Node *nodeWithDouble(double m_double) { Node *p_node; - double *p_double = (double *)malloc(sizeof(double)); + double *p_double = (double *)malloc(sizeof(double)); + if(p_double == NULL){ + showError(pushError(DOUBLE, STANDARD, initInfo("nodeWithDouble()", "Error in getting the memory of double."))); + return NULL; + } *p_double = m_double; p_node = initNode(); initMallocValueForNode(p_node, DOUBLE, (void *)p_double); @@ -20,14 +41,18 @@ Node *nodeWithDouble(double m_double) { Node *nodeWithString(const char *m_string) { Node *p_node; - char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string) + 1)); + char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string) + 1)); + if(p_string == NULL){ + showError(pushError(STRING, STANDARD, initInfo("initWithString()", "Error in getting the memory of string."))); + return NULL; + } strcpy(p_string, m_string); p_node = initNode(); initMallocValueForNode(p_node, STRING, (void *)p_string); return p_node; } -Node *nodeWithPointer(void *m_pointer) { +Node *nodeWithPointer(const void *m_pointer) { Node *p_node = initNode(); initMallocValueForNode(p_node, POINTER, m_pointer); return p_node; @@ -50,28 +75,38 @@ Node *findByIndexForNode(List *p_list, unsigned long long m_index) { return p_node; } -int listThrough(List *p_list, int(*p_func)(unsigned int, void *)) { - Node *p_node = p_list->head; +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; while (p_node != NULL) { if (p_node->if_malloc == 1) { - int m_return = (*p_func)(p_node->type, p_node->value); - if (m_return == -1) break; - else if (m_return == 1) { - p_node = p_node->last; + List *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) { + p_node = p_node->last; + releaseList(m_rtnlst); + m_rtnlst = NULL; continue; } else { - + releaseList(m_rtnlst); + m_rtnlst = NULL; } } p_node = p_node->next; } - return 0; + return m_rtnlst; } int getByIntForNode(Node *p_node) { if (p_node->type == INT) return *(int *)(p_node->value); else return -1; +} + +unsigned int getByUIntForNode(Node *p_node){ + if (p_node->type == UINT) return *(unsigned int *)(p_node->value); + else return -1; } char *getByStringForNode(Node *p_node) { @@ -249,7 +284,11 @@ int addValueForComplex(Node * p_node, int type, void *value) { int addIntForComplex(Node *p_node, int temp) { if (p_node->type == LIST) { - int *p_temp = (int *)malloc(sizeof(int)); + int *p_temp = (int *)malloc(sizeof(int)); + if(p_temp == NULL){ + showError(pushError(INT, STANDARD, initInfo("addIntForComplex()", "Error in getting the memory of int."))); + return -1; + } *p_temp = temp; addValueForComplex(p_node, INT, p_temp); return 0; @@ -259,7 +298,11 @@ int addIntForComplex(Node *p_node, int temp) { int addDoubleForComplex(Node *p_node, double temp) { if (p_node->type == LIST) { - double *p_temp = (double *)malloc(sizeof(double)); + double *p_temp = (double *)malloc(sizeof(double)); + if(p_temp == NULL){ + showError(pushError(DOUBLE, STANDARD, initInfo("addDoubleForComplex()", "Error in getting the memory of double."))); + return -1; + } *p_temp = temp; addValueForComplex(p_node, DOUBLE, p_temp); return 0; @@ -269,7 +312,11 @@ int addDoubleForComplex(Node *p_node, double temp) { int addStringForComplex(Node *p_node, char *temp) { if (p_node->type == LIST) { - char *p_temp = (char *)malloc(sizeof(strlen(temp) + 1)); + char *p_temp = (char *)malloc(sizeof(strlen(temp) + 1)); + if(p_temp == NULL){ + showError(pushError(STRING, STANDARD, initInfo("addStringForComplex()", "Error in getting the memory of string."))); + return -1; + } strcpy(p_temp, temp); addValueForComplex(p_node, STRING, p_temp); return 0; @@ -286,7 +333,11 @@ int addPointerForComplex(Node *p_node, void *temp) { } List *m_findByInt(List* p_list, int temp) { - int *p_temp = (int *)malloc(sizeof(int)); + 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."))); + return NULL; + } List *t_list; *p_temp = temp; t_list = mply_findByValue(p_list, INT, (void *)p_temp); @@ -296,7 +347,11 @@ List *m_findByInt(List* p_list, int temp) { List *m_findByDouble(List* p_list, double temp) { List *t_list; - double *p_temp = (double *)malloc(sizeof(double)); + double *p_temp = (double *)malloc(sizeof(double)); + if(p_temp == NULL){ + showError(pushError(DOUBLE, STANDARD, initInfo("m_findByDouble()", "Error in getting the memory of double."))); + return NULL; + } *p_temp = temp; t_list = mply_findByValue(p_list, DOUBLE, (void *)p_temp); free(p_temp); @@ -305,7 +360,11 @@ List *m_findByDouble(List* p_list, double temp) { List *m_findByString(List* p_list, char *temp) { List *t_list; - char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); + char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); + if(p_temp == NULL){ + showError(pushError(STRING, STANDARD, initInfo("m_findByString()", "Error in getting the memory of string."))); + return NULL; + } strcpy(p_temp, temp); t_list = mply_findByValue(p_list, STRING, (void *)p_temp); free(p_temp); @@ -329,19 +388,31 @@ unsigned long long getIndexByNode(List *p_list, Node *p_node) { } List *m_findByIntForNode(List* p_list, int temp) { - int *p_temp = (int *)malloc(sizeof(int)); + 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."))); + return NULL; + } *p_temp = temp; return mply_findByValue(p_list, INT, (void *)p_temp); } List *m_findByDoubleForNode(List* p_list, double temp) { - double *p_temp = (double *)malloc(sizeof(double)); + double *p_temp = (double *)malloc(sizeof(double)); + if(p_temp == NULL){ + showError(pushError(DOUBLE, STANDARD, initInfo("m_findByDoubleForNode()", "Error in getting the memory of double."))); + return NULL; + } *p_temp = temp; return mply_findByValue(p_list, DOUBLE, (void *)p_temp); } List *m_findByStringForNode(List* p_list, char *temp) { - char *p_temp = (char *)malloc(sizeof(char) * (strlen(temp) + 1)); + char *p_temp = (char *)malloc(sizeof(char) * (strlen(temp) + 1)); + if(p_temp == NULL){ + showError(pushError(STRING, STANDARD, initInfo("m_findByStringForNode()", "Error in getting the memory of string."))); + return NULL; + } strcpy(p_temp, temp); return mply_findByValue(p_list, STRING, (void *)p_temp); } @@ -359,4 +430,46 @@ unsigned long long calListMemory(List * p_list){ p_node = p_node->next; } return list_size + nodes_size; +} + +int updateValueWithInt(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."))); + return -1; + } + *p_value = value; + free(p_node->value); + p_node->value = p_value; + return 0; } + +int updateValueWithDouble(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."))); + return -1; + } + *p_value = value; + free(p_node->value); + p_node->value = p_value; + return 0; +} + +int updateValueWithString(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."))); + return -1; + } + strcpy(p_value, string); + free(p_node->value); + p_node->value = p_value; + return 0; +} + +int updateValueWithPointer(Node *p_node, void *pointer){ + free(p_node->value); + p_node->value = pointer; + return 0; +} diff --git a/list/list_expand.h b/list/list_expand.h index 1d8d97e..dff20b7 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -3,17 +3,24 @@ #include "list.h" -Node *nodeWithInt(int); +Node *nodeWithInt(int); +Node *nodeWithUInt(unsigned int); Node *nodeWithDouble(double); Node *nodeWithString(const char *); -Node *nodeWithPointer(void *); +Node *nodeWithPointer(const void *); Node *nodeWithComplex(void); int addValueForComplex(Node *, int type, void *value); int addIntForComplex(Node *, int); int addDoubleForComplex(Node *, double); int addStringForComplex(Node *, char *); -int addPointerForComplex(Node *, void *); +int addPointerForComplex(Node *, void *); + +int updateValueWithInt(Node *,int); +int updateValueWithDouble(Node *,double); +int updateValueWithString(Node *,char *); +int updateValueWithPointer(Node *,void *); + Node *findByIndexForNode(List *, unsigned long long); Node *findByIntForNode(List *, int); @@ -31,12 +38,13 @@ void printNodeInfo(Node *p_node,int priority); void printList(List *); void printNode(Node *p_node); -int getByIntForNode(Node *); +int getByIntForNode(Node *); +unsigned int getByUIntForNode(Node *); double getByDoubleForNode(Node *); char *getByStringForNode(Node *); void *getByPointerForNode(Node *); unsigned long long getIndexByNode(List *p_list,Node *p_node); -int listThrough(List *p_list, int (*p_func)(unsigned int type, void *value)); +List *listThrough(List *p_list, List *(*p_func)(unsigned int type, void *value, List *), List *expand_resources); unsigned long long calListMemory(List *); #endif diff --git a/stack/stack.c b/stack/stack.c index acaee3f..f4b8ae1 100644 --- a/stack/stack.c +++ b/stack/stack.c @@ -3,7 +3,7 @@ Stack *initStack(void) { Stack *p_stack = (Stack *)malloc(sizeof(Stack)); if(p_stack == NULL){ - showError(pushError(STACK, STANDARD, initInfo("initStack()", "Error in get the memory of stack."))); + showError(pushError(STACK, STANDARD, initInfo("initStack()", "Error in getting the memory of stack."))); return NULL; } p_stack->s_id = getS_id(STACK, 1); @@ -15,7 +15,7 @@ Stack *initStack(void) { SNode *initSNode(void) { SNode *p_snode = (SNode *)malloc(sizeof(SNode)); if(p_snode == NULL){ - showError(pushError(STACK_NODE, STANDARD, initInfo("initSNode()", "Error in get the memory of snode."))); + showError(pushError(STACK_NODE, STANDARD, initInfo("initSNode()", "Error in getting the memory of snode."))); return NULL; } p_snode->s_id = getS_id(STACK_NODE, 2); diff --git a/stack/stack.h b/stack/stack.h index d20f752..ef36892 100644 --- a/stack/stack.h +++ b/stack/stack.h @@ -1,23 +1,8 @@ #ifndef STACK_H #define STACK_H +#include "../type/type.h" #include "../list/list_expand.h" -typedef struct stack_node{ - SID *s_id; - _Bool if_malloc; - _Bool if_sid; - unsigned int type; - void *value; - struct stack_node *next; -} SNode; - -typedef struct stack{ - SID *s_id; - unsigned long long length; - SNode *top; - _Bool if_sid; -} Stack; - Stack *initStack(void); SNode *initSNode(void); int initMallocValueForSNode(SNode *p_snode, unsigned int type, void *value); diff --git a/stack/stack_expand.c b/stack/stack_expand.c index f48ad09..b0b3aa1 100644 --- a/stack/stack_expand.c +++ b/stack/stack_expand.c @@ -2,7 +2,11 @@ SNode *snodeWithInt(int temp) { SNode *p_snode = initSNode(); - int *p_temp = (int *)malloc(sizeof(int)); + int *p_temp = (int *)malloc(sizeof(int)); + if(p_temp == NULL){ + showError(pushError(INT, STANDARD, initInfo("snodeWithInt()", "Error in getting the memory of int."))); + return NULL; + } *p_temp = temp; initMallocValueForSNode(p_snode, INT, p_temp); return p_snode; @@ -10,7 +14,11 @@ SNode *snodeWithInt(int temp) { SNode *snodeWithDouble(double temp) { SNode *p_snode = initSNode(); - double *p_temp = (double *)malloc(sizeof(double)); + double *p_temp = (double *)malloc(sizeof(double)); + if(p_temp == NULL){ + showError(pushError(DOUBLE, STANDARD, initInfo("snodeWithDouble()", "Error in getting the memory of double."))); + return NULL; + } *p_temp = temp; initMallocValueForSNode(p_snode, DOUBLE, p_temp); return p_snode; @@ -18,7 +26,11 @@ SNode *snodeWithDouble(double temp) { SNode *snodeWithString(char *temp) { SNode *p_snode = initSNode(); - char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); + char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); + if(p_temp == NULL){ + showError(pushError(STRING, STANDARD, initInfo("snodeWithString()", "Error in getting the memory of string."))); + return NULL; + } strcpy(p_temp, temp); initMallocValueForSNode(p_snode, STRING, p_temp); return p_snode; diff --git a/test.c b/test.c index bd9d494..7de1db3 100644 --- a/test.c +++ b/test.c @@ -81,8 +81,25 @@ int stack(void) { } -int main(int argc, char **argv) { - //tree(); - init_rand(); +int main(int argc, char **argv) { + init_rand(); + for (int j = 0; j < 65535; j++) { + List *t_list = initList(); + for (int i = 0; i < 12; i++) { + insertInHead(t_list, nodeWithInt(i)); + } + STD_DATA *p_std = listToSTD(t_list); + D_FILE *p_dfilew = initDataFileForWrite("data.df"); + dataFileAddStandardData(p_dfilew, p_std); + dataFileWriteIn(p_dfilew); + releaseDFile(p_dfilew); + D_FILE *p_dfiler = initDataFileForRead("data.df"); + dataFileReadOut(p_dfiler); + releaseDFile(p_dfiler); + releaseList(t_list); + + printf("%d\n",j); + usleep(2000); + } return 0; } diff --git a/test.h b/test.h index dfa8642..6dcdf20 100644 --- a/test.h +++ b/test.h @@ -4,7 +4,8 @@ #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); int list(void); diff --git a/tree/tree.c b/tree/tree.c index 276304d..af965d8 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -1,7 +1,5 @@ #include"tree.h" -static SID *target_sid = NULL; -static TNode *target_value_sid = NULL; static int if_safeModeForTree = 0; int safeModeForTree(int ifon) { @@ -39,7 +37,7 @@ TNode *initTNode(void) { Node *s_node; TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); if(p_tnode == NULL){ - showError(pushError(TREE_NODE, STANDARD, initInfo("initTNode()", "Error in get the memory of tnode."))); + showError(pushError(TREE_NODE, STANDARD, initInfo("initTNode()", "Error in getting the memory of tnode."))); return NULL; } p_tnode->s_id = getS_id(TREE_NODE, 2); @@ -73,7 +71,7 @@ Tree *initTree(void) { Node *s_node; Tree *p_tree = (Tree *)malloc(sizeof(Tree)); if(p_tree == NULL){ - showError(pushError(TREE, STANDARD, initInfo("initTree()", "Error in get the memory of tree."))); + showError(pushError(TREE, STANDARD, initInfo("initTree()", "Error in getting the memory of tree."))); return NULL; } p_tree->s_id = getS_id(TREE, 1); @@ -163,79 +161,100 @@ int removeChildInRight(TNode *p_tnode) { TNode *getChildById(TNode *p_tnode, const SID *s_id) { List *p_home = p_tnode->home; - target_sid = NULL; - target_value_sid = NULL; - listThrough(p_home, _dogetChildById); - if (target_value_sid != NULL) { - return target_value_sid; + target_value_sid = NULL; + List *er_list = initList(); + insertInTail(er_list, nodeWithPointer(s_id)); + List *rtnc_list = listThrough(p_home, _dogetChildById, er_list); + free(er_list); + Node *p_node= findByIndexForNode(rtnc_list, 1); + if (p_node != NULL) { + TNode *p_tnode = getByPointerForNode(p_node); + free(rtnc_list); + return p_tnode; } return NULL; } -int _dogetChildById(unsigned int type, void *value) { +List *_dogetChildById(unsigned int type, void *value, List *er_list) { + SID *target_sid = getByPointerForNode(findByIndexForNode(er_list, 0)); + List *rtn_list = initList(); if (type == POINTER) { TNode *p_tode = (TNode *)value; if (simFitS_id(p_tode->s_id, target_sid)) { - target_value_sid = p_tode; - return -1; + target_value_sid = p_tode; + insertInTail(rtn_list, nodeWithInt(-1)); + insertInTail(rtn_list, nodeWithPointer(target_value_sid)); + return rtn_list; } - } - return 0; + } + insertInTail(rtn_list, nodeWithInt(0)); + return rtn_list; } -static int target_type = VOID; -static void *target_value = NULL; -static TNode *target_value_value = NULL; - TNode *getChildByValue(TNode *p_tnode, unsigned int type, void *value) { List *p_home = p_tnode->home; target_value = value; target_type = type; - target_value_value = NULL; - listThrough(p_home, _dogetChildByValue); - if (target_value_value != NULL) { - return target_value_value; + target_value_value = NULL; + List *er_list = initList(); + insertInTail(er_list, nodeWithUInt(type)); + insertInTail(er_list, nodeWithPointer(value)); + List *rtnc_list = listThrough(p_home, _dogetChildByValue,er_list); + free(er_list); + Node *p_node = NULL; + if ((p_node = findByIndexForNode(rtnc_list, 1)) != NULL) { + TNode *p_tnode = getByPointerForNode(p_node); + free(rtnc_list); + return p_tnode; } return NULL; } -int _dogetChildByValue(unsigned int type, void *value) { +List *_dogetChildByValue(unsigned int type, void *value, List *er_list) { + List *rtn_list = initList(); + unsigned int target_type = getByUIntForNode(findByIndexForNode(rtn_list, 0)); + void *target_value = getByPointerForNode(findByIndexForNode(rtn_list, 1)); if (type == target_type) { TNode *p_tode = (TNode *)value; if (target_type == INT) { if (*(int *)p_tode->value == *(int *)target_value) - { - target_value_value = p_tode; - return -1; + { + insertInTail(rtn_list, nodeWithInt(-1)); + insertInTail(rtn_list, nodeWithPointer(p_tode)); + return rtn_list; } } else if (target_type == DOUBLE) { if (*(double *)p_tode->value == *(double *)target_value) - { - target_value_value = p_tode; - return -1; + { + insertInTail(rtn_list, nodeWithInt(-1)); + insertInTail(rtn_list, nodeWithPointer(p_tode)); + return rtn_list; } } else if (target_type == STRING) { if (!strcmp((char *)p_tode->value, (char *)target_value)) - { - target_value_value = p_tode; - return -1; + { + insertInTail(rtn_list, nodeWithInt(-1)); + insertInTail(rtn_list, nodeWithPointer(p_tode)); + return rtn_list; } } else if (target_type == POINTER) { if (p_tode->value == target_value) - { - target_value_value = p_tode; - return -1; + { + insertInTail(rtn_list, nodeWithInt(-1)); + insertInTail(rtn_list, nodeWithPointer(p_tode)); + return rtn_list; } } - } - return 0; + } + insertInTail(rtn_list, nodeWithInt(0)); + return rtn_list; } int removeChildById(TNode *p_tnode, const SID *s_id) { diff --git a/tree/tree.h b/tree/tree.h index 2504c6f..d4b8a3d 100644 --- a/tree/tree.h +++ b/tree/tree.h @@ -28,8 +28,8 @@ int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height) int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)); -int _dogetChildById(unsigned int type, void *value); -int _dogetChildByValue(unsigned int type, void *value); +List *_dogetChildById(unsigned int type, void *value, List *er_list); +List *_dogetChildByValue(unsigned int type, void *value, List *er_list); int _doreleaseTree(TNode *p_tnode, unsigned long long height); int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)); int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)); diff --git a/tree/tree_expand.c b/tree/tree_expand.c index e188663..5d9992d 100644 --- a/tree/tree_expand.c +++ b/tree/tree_expand.c @@ -2,7 +2,11 @@ TNode *tnodeWithInt(int temp) { TNode *p_tnode = initTNode(); - int *p_temp = (int *)malloc(sizeof(int)); + int *p_temp = (int *)malloc(sizeof(int)); + if(p_temp == NULL){ + showError(pushError(INT, STANDARD, initInfo("tnodeWithInt()", "Error in getting the memory of int."))); + return NULL; + } *p_temp = temp; initMallocValueForTNode(p_tnode, INT, p_temp); return p_tnode; @@ -10,14 +14,22 @@ TNode *tnodeWithInt(int temp) { TNode *tnodeWithDouble(double temp) { TNode *p_tnode = initTNode(); - double *p_temp = (double *)malloc(sizeof(double)); + double *p_temp = (double *)malloc(sizeof(double)); + if(p_temp == NULL){ + showError(pushError(DOUBLE, STANDARD, initInfo("tnodeWithDouble()", "Error in getting the memory of double."))); + return NULL; + } *p_temp = temp; initMallocValueForTNode(p_tnode, DOUBLE, p_temp); return p_tnode; } TNode *tnodeWithString(char *temp) { TNode *p_tnode = initTNode(); - char *p_temp = (char *)malloc(sizeof(temp)); + char *p_temp = (char *)malloc(sizeof(temp)); + if(p_temp == NULL){ + showError(pushError(STRING, STANDARD, initInfo("tnodeWithString()", "Error in getting the memory of string."))); + return NULL; + } strcpy(p_temp, temp); initMallocValueForTNode(p_tnode, STRING, p_temp); return p_tnode; diff --git a/type/type.h b/type/type.h index 47f5cca..b93035b 100644 --- a/type/type.h +++ b/type/type.h @@ -5,6 +5,7 @@ #include #include #include +#include #define VOID 0 #define INT 1 @@ -18,6 +19,9 @@ #define TREE_NODE 9 #define STACK_NODE 10 #define T_SID 11 +#define UINT 12 +#define STANDARD_DATA 13 +#define DATA_FILE 14 #define DEEPC 1 #define DEEPB 2 @@ -27,6 +31,12 @@ #define DEEPB_LEN 8 #define DEEPA_LEN 32 #define DATA_BIT 5 +#define DEEP_LEN 25 +#define DEEPER_LEN 65 +#define DEEPEST_LEN 225 +#define FILE_TSET_LEN 18 +#define HEAD_TEST_LEN 9 + #define HIGH 0x3 #define STANDARD 0x2 @@ -83,6 +93,22 @@ typedef struct Log{ unsigned long int id; }Log; +typedef struct stack_node{ + SID *s_id; + _Bool if_malloc; + _Bool if_sid; + unsigned int type; + void *value; + struct stack_node *next; +} SNode; + +typedef struct stack{ + SID *s_id; + unsigned long long length; + SNode *top; + _Bool if_sid; +} Stack; + typedef struct tree_node { SID *s_id; From 3ce69ae8e555b09e325d8d0da8710f4bfb6edcc8 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Tue, 7 Aug 2018 12:55:59 +0800 Subject: [PATCH 02/12] Add and Fixed. --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 182 +++++++----------- communicate/communicate.c | 41 +++- communicate/communicate.h | 48 +---- list/list.c | 2 +- stack/stack.c | 2 +- test.c | 29 ++- tree/tree.c | 2 +- type/type.h | 37 ++++ 8 files changed, 159 insertions(+), 184 deletions(-) diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index c3ec7ec..abe8217 100644 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -154,7 +154,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "555307651.589517" + timestampString = "555310052.789754" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "64" @@ -175,7 +175,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "60" endingLineNumber = "60" - landmarkName = "printTNode" + landmarkName = "getValueByStringForTree" landmarkType = "9"> @@ -525,11 +525,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "555307651.590879" + timestampString = "555310052.790392" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "89" - endingLineNumber = "89" + startingLineNumber = "88" + endingLineNumber = "88" landmarkName = "main" landmarkType = "9"> @@ -541,11 +541,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "555307651.5910259" + timestampString = "555310052.790665" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "91" - endingLineNumber = "91" + startingLineNumber = "90" + endingLineNumber = "90" landmarkName = "main" landmarkType = "9"> @@ -557,7 +557,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list_expand.c" - timestampString = "555307651.591181" + timestampString = "555309906.510792" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "83" @@ -573,11 +573,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "555307651.591266" + timestampString = "555310052.790953" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "93" - endingLineNumber = "93" + startingLineNumber = "92" + endingLineNumber = "92" landmarkName = "main" landmarkType = "9"> @@ -589,7 +589,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.591457" + timestampString = "555310052.791223" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "102" @@ -605,7 +605,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.592109" + timestampString = "555310052.791289" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "137" @@ -621,7 +621,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.592618" + timestampString = "555310052.791344" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "124" @@ -630,22 +630,6 @@ landmarkType = "9"> - - - - + startingLineNumber = "100" + endingLineNumber = "100"> @@ -749,7 +731,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.595166" + timestampString = "555310052.792271" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "231" @@ -765,7 +747,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.595765" + timestampString = "555310052.792323" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "186" @@ -781,7 +763,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.596207" + timestampString = "555310052.7923729" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "38" @@ -797,7 +779,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.596637" + timestampString = "555310052.792423" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "120" @@ -813,7 +795,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.597056" + timestampString = "555310052.792475" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "194" @@ -829,7 +811,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.597474" + timestampString = "555310052.792524" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "217" @@ -861,7 +843,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.597941" + timestampString = "555310052.792592" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "224" @@ -877,7 +859,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.598327" + timestampString = "555310052.792645" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "17" @@ -893,7 +875,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.598729" + timestampString = "555310052.792713" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "7" @@ -909,7 +891,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.599126" + timestampString = "555310052.7927589" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "43" @@ -925,7 +907,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.599665" + timestampString = "555310052.792803" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "170" @@ -941,7 +923,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.6000921" + timestampString = "555310052.7928669" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "221" @@ -957,7 +939,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.600467" + timestampString = "555310052.792913" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "223" @@ -973,7 +955,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.600853" + timestampString = "555310052.792958" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "151" @@ -989,7 +971,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.601244" + timestampString = "555310052.7930011" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "153" @@ -1005,7 +987,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555307651.601626" + timestampString = "555310052.793045" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "226" @@ -1021,7 +1003,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list_expand.c" - timestampString = "555307651.602327" + timestampString = "555309906.512913" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "103" @@ -1037,13 +1019,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "555307651.6025029" + timestampString = "555310052.793105" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "104" - endingLineNumber = "104" - landmarkName = "main" - landmarkType = "9"> + startingLineNumber = "99" + endingLineNumber = "99"> + + + + - - - - - - - - - - - - diff --git a/communicate/communicate.c b/communicate/communicate.c index 73a86a5..c3cf45f 100644 --- a/communicate/communicate.c +++ b/communicate/communicate.c @@ -1,11 +1,12 @@ #include "communicate.h" -STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned long long data_size){ +STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long long data_size){ STD_BLOCKS *p_stdb = (STD_BLOCKS *)malloc(sizeof(STD_BLOCKS)); p_stdb->sid = s_idToASCIIString(p_sid); p_stdb->if_data = 0; unsigned int blocks_num = (unsigned int)(data_size/sizeof(char)); p_stdb->blocks_num = blocks_num; + p_stdb->type = type; p_stdb->buff = (char *)malloc(sizeof(char) * blocks_num); return p_stdb; } @@ -34,13 +35,13 @@ STD_DATA *initStandardData(unsigned int type){ p_std->pd_ctnlst = initList(); p_std->lock = 0; p_std->type = type; - p_std->s_id = getS_id(STANDARD_DATA, 2); + p_std->s_id = getS_id(STANDARD_DATA, 1); return p_std; } -int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,void *data, unsigned long long data_size){ +int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,unsigned int type, void *data, unsigned long long data_size){ if (p_std->lock) return -1; - STD_BLOCKS *p_stdb = initStandardDBlocks(p_sid, data_size); + STD_BLOCKS *p_stdb = initStandardDBlocks(p_sid, type,data_size); dataForStandardDBlock(p_stdb, data); insertInTail(p_std->pd_blocklst, nodeWithPointer(p_stdb)); return 0; @@ -150,6 +151,7 @@ List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list){ unsigned long sid_len = strlen(p_stdb->sid)+1, blocks_num = p_stdb->blocks_num; fwrite(&sid_len, sizeof(unsigned long), 1, fp); fwrite(p_stdb->sid, sizeof(char), sid_len, fp); + 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; @@ -164,7 +166,7 @@ STD_DATA *listToSTD(List *p_list){ else if (p_node->type == DOUBLE) data_size = sizeof(double); else if (p_node->type == STRING) data_size = strlen((char *)p_node->value) + 1; else data_size = sizeof(void *); - standardDataAddBlock(p_std, p_node->s_id, p_node->value, data_size); + standardDataAddBlock(p_std, p_node->s_id, p_node->type, p_node->value, data_size); p_node = p_node->next; } return p_std; @@ -220,7 +222,9 @@ int dataFileReadOut(D_FILE *p_dfile){ char *content = (char *)malloc(sizeof(char) * blk_len); fread(content, sizeof(char), blk_len, p_dfile->fp); SID *s_id = asciiStringToS_id(string_sid); - standardDataAddBlock(p_std, s_id, content, blk_len); + 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); free(string_sid); free(content); @@ -230,6 +234,9 @@ int dataFileReadOut(D_FILE *p_dfile){ else break; } } + else{ + + } } showError(pushError(DATA_FILE, STANDARD, initInfo("dataFileReadOut()", "Datafile not complete."))); return -1; @@ -264,3 +271,25 @@ int releaseDFile(D_FILE *p_dfile){ free(p_dfile); return 0; } + +List *standardDataToList(STD_DATA *p_std){ + List *p_list = initList(); + List *er_list = initList(); + insertInTail(er_list, nodeWithPointer(er_list)); + listThrough(p_std->pd_blocklst, _doStandardDataToList, er_list); + return p_list; +} + +List *_doStandardDataToList(unsigned int type, void *value, List *er_list){ + List *rtn_list = initList(); + insertInTail(rtn_list, nodeWithInt(0)); + List *p_list = getByPointerForNode(findByIndexForNode(er_list, 0)); + STD_BLOCKS *p_stdb = value; + Node *p_node = initNode(); + p_node->s_id = asciiStringToS_id(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; +} diff --git a/communicate/communicate.h b/communicate/communicate.h index bb15f73..f73ea90 100644 --- a/communicate/communicate.h +++ b/communicate/communicate.h @@ -7,55 +7,19 @@ typedef struct message{ SID *p_sid; char titile[16]; + unsigned long size; char content[0]; }MSG; -typedef struct file_head{ - char head_test[18]; - unsigned long long data_num; -}F_HEAD; - -typedef struct data_file{ - FILE *fp; - F_HEAD *pf_head; - List *pf_stdlst; -}D_FILE; - -typedef struct standard_data_blocks{ - unsigned int type; - char *sid; - _Bool if_data; - unsigned int blocks_num; - char *buff; -}STD_BLOCKS; - -typedef struct standard_data_connection{ - char *f_sid; - char *s_sid; -}STD_CTN; - -typedef struct standard_data_head{ - unsigned long long data_blk_num; - unsigned long long data_ctn_num; -}STD_HEAD; - -typedef struct standard_data{ - SID *s_id; - unsigned int type; - _Bool lock; - List *pd_blocklst; - List *pd_ctnlst; -}STD_DATA; - D_FILE *initDataFileForWrite(char *route); D_FILE *initDataFileForRead(char *route); -STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned long long data_size); +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); int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data); int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std); -int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,void *data, unsigned long long data_size); +int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,unsigned int type, void *data, unsigned long long data_size); int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid); int dataFileWriteIn(D_FILE *p_dfile); int dataFileReadOut(D_FILE *p_dfile); @@ -71,7 +35,9 @@ List *_doStandardDConnectionWrite(unsigned int type, void *value, List *er_list) List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list); STD_DATA *listToSTD(List *); -STD_DATA *stackToSTD(Stack *); -STD_DATA *treeToSTD(Tree *); +List *standardDataToList(STD_DATA *); +List *_doStandardDataToList(unsigned int type, void *value, List *er_list); +//STD_DATA *stackToSTD(Stack *); +//STD_DATA *treeToSTD(Tree *); #endif /* communicate_h */ diff --git a/list/list.c b/list/list.c index 2c86746..67dcc73 100644 --- a/list/list.c +++ b/list/list.c @@ -93,7 +93,7 @@ Node *initNode(void) { return NULL; } Node *prec_node = NULL; - p_node->s_id = getS_id(LIST_NODE, 2); + p_node->s_id = getS_id(LIST_NODE, 1); p_node->if_sid = 1; p_node->if_malloc = 0; p_node->next = NULL; diff --git a/stack/stack.c b/stack/stack.c index f4b8ae1..7981445 100644 --- a/stack/stack.c +++ b/stack/stack.c @@ -18,7 +18,7 @@ SNode *initSNode(void) { showError(pushError(STACK_NODE, STANDARD, initInfo("initSNode()", "Error in getting the memory of snode."))); return NULL; } - p_snode->s_id = getS_id(STACK_NODE, 2); + p_snode->s_id = getS_id(STACK_NODE, 1); p_snode->if_malloc = 0; p_snode->next = NULL; p_snode->value = NULL; diff --git a/test.c b/test.c index 7de1db3..ee234f9 100644 --- a/test.c +++ b/test.c @@ -83,23 +83,18 @@ int stack(void) { int main(int argc, char **argv) { init_rand(); - for (int j = 0; j < 65535; j++) { - List *t_list = initList(); - for (int i = 0; i < 12; i++) { - insertInHead(t_list, nodeWithInt(i)); - } - STD_DATA *p_std = listToSTD(t_list); - D_FILE *p_dfilew = initDataFileForWrite("data.df"); - dataFileAddStandardData(p_dfilew, p_std); - dataFileWriteIn(p_dfilew); - releaseDFile(p_dfilew); - D_FILE *p_dfiler = initDataFileForRead("data.df"); - dataFileReadOut(p_dfiler); - releaseDFile(p_dfiler); - releaseList(t_list); - - printf("%d\n",j); - usleep(2000); + List *t_list = initList(); + for (int i = 0; i < 100; i++) { + insertInHead(t_list, nodeWithInt(i)); } + STD_DATA *p_std = listToSTD(t_list); + D_FILE *p_dfilew = initDataFileForWrite("data.df"); + dataFileAddStandardData(p_dfilew, p_std); + dataFileWriteIn(p_dfilew); + releaseDFile(p_dfilew); + D_FILE *p_dfiler = initDataFileForRead("data.df"); + dataFileReadOut(p_dfiler); + releaseDFile(p_dfiler); + releaseList(t_list); return 0; } diff --git a/tree/tree.c b/tree/tree.c index af965d8..87794fa 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -40,7 +40,7 @@ TNode *initTNode(void) { showError(pushError(TREE_NODE, STANDARD, initInfo("initTNode()", "Error in getting the memory of tnode."))); return NULL; } - p_tnode->s_id = getS_id(TREE_NODE, 2); + p_tnode->s_id = getS_id(TREE_NODE, 1); p_tnode->if_sid = 1; p_tnode->child_num = 0; p_tnode->father = NULL; diff --git a/type/type.h b/type/type.h index b93035b..2cc99a5 100644 --- a/type/type.h +++ b/type/type.h @@ -6,6 +6,7 @@ #include #include #include +#include #define VOID 0 #define INT 1 @@ -129,5 +130,41 @@ typedef struct tree TNode *root; }Tree; +typedef struct file_head{ + char head_test[18]; + unsigned long long data_num; +}F_HEAD; + +typedef struct data_file{ + FILE *fp; + F_HEAD *pf_head; + List *pf_stdlst; +}D_FILE; + +typedef struct standard_data_blocks{ + unsigned int type; + char *sid; + _Bool if_data; + unsigned int blocks_num; + char *buff; +}STD_BLOCKS; + +typedef struct standard_data_connection{ + char *f_sid; + char *s_sid; +}STD_CTN; + +typedef struct standard_data_head{ + unsigned long long data_blk_num; + unsigned long long data_ctn_num; +}STD_HEAD; + +typedef struct standard_data{ + SID *s_id; + unsigned int type; + _Bool lock; + List *pd_blocklst; + List *pd_ctnlst; +}STD_DATA; #endif /* type_h */ From b9b36653a3d42c9e7454568f3e23df5f6faf1dab Mon Sep 17 00:00:00 2001 From: Saturneic Date: Tue, 7 Aug 2018 17:43:42 +0800 Subject: [PATCH 03/12] Fixed --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 10 +++-- communicate/communicate.c | 43 +++++++++++++++++++ communicate/communicate.h | 4 ++ type/type.h | 8 ++++ 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index abe8217..ee2d7ff 100644 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -633,7 +633,7 @@ + endingLineNumber = "100" + landmarkName = "main" + landmarkType = "9"> + endingLineNumber = "99" + landmarkName = "main" + landmarkType = "9"> p_sid = getS_id(MESSAGE, 1); + p_msg->time = time(NULL); + return p_msg; +} + +/*int sendMessageIPv4(MSG *p_msg, char *ip, unsigned int port){ + int client_sockfd; + struct sockaddr_in remote_addr; + char buf[BUFSIZ]; + memcpy(buf, "ZEMSG", 5); + memset(&remote_addr,0,sizeof(remote_addr)); + remote_addr.sin_family=AF_INET; + remote_addr.sin_addr.s_addr=inet_addr(ip); + remote_addr.sin_port=htons(port); + client_sockfd=socket(PF_INET,SOCK_STREAM,0); + connect(client_sockfd,(struct sockaddr *)&remote_addr,sizeof(struct sockaddr)); + send(client_sockfd,buf,strlen(buf),0); + unsigned long bkmsg_len = 0; + bkmsg_len = recv(client_sockfd, buf, BUFSIZ, 0); + buf[bkmsg_len] = '\0'; + if(!strcmp(buf, "TITLE_REV_READY")){ + memcpy(buf, p_msg->titile, strlen(p_msg->titile)); + bkmsg_len = recv(client_sockfd, buf, BUFSIZ, 0); + buf[bkmsg_len] = '\0'; + if(!strcmp(buf, "CONTENT_LEN_REV_READY")){ + memcpy(buf, (char *)p_msg->size, sizeof(unsigned int)); + send(client_sockfd,buf,sizeof(unsigned int),0); + bkmsg_len = recv(client_sockfd, buf, BUFSIZ, 0); + buf[bkmsg_len] = '\0'; + if(!strcmp(buf, "CONTENT_REV_READY")){ + memcpy(buf, p_msg->content, p_msg->size); + send(client_sockfd,buf,p_msg->size,0); + close(client_sockfd); + return 0; + } + } + } + close(client_sockfd); + return -1; +}*/ diff --git a/communicate/communicate.h b/communicate/communicate.h index f73ea90..cff8f99 100644 --- a/communicate/communicate.h +++ b/communicate/communicate.h @@ -6,6 +6,7 @@ typedef struct message{ SID *p_sid; + time_t time; char titile[16]; unsigned long size; char content[0]; @@ -37,6 +38,9 @@ List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list); STD_DATA *listToSTD(List *); List *standardDataToList(STD_DATA *); List *_doStandardDataToList(unsigned int type, void *value, List *er_list); + +MSG *createMessage(char *title, void *data, unsigned long data_size); +int sendMessageIPv4(MSG *p_msg, char *ip, unsigned int port); //STD_DATA *stackToSTD(Stack *); //STD_DATA *treeToSTD(Tree *); diff --git a/type/type.h b/type/type.h index 2cc99a5..a1dbaa1 100644 --- a/type/type.h +++ b/type/type.h @@ -8,6 +8,13 @@ #include #include +/* +#include +#include +#include +#include +*/ + #define VOID 0 #define INT 1 #define DOUBLE 2 @@ -23,6 +30,7 @@ #define UINT 12 #define STANDARD_DATA 13 #define DATA_FILE 14 +#define MESSAGE 15 #define DEEPC 1 #define DEEPB 2 From e4c123fff8a202aa3809715f9f78474985d3be7d Mon Sep 17 00:00:00 2001 From: Saturn&Eric Date: Tue, 7 Aug 2018 18:13:35 +0800 Subject: [PATCH 04/12] Update README.md Add. --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a119f9d..720dd88 100644 --- a/README.md +++ b/README.md @@ -1 +1,22 @@ -# ZE-Standard-Libraries \ No newline at end of file +# ZE-Standard-Libraries +### --我们需要更快更方便的基于C语言的软件工程 + +## 简介 +该函数库用于提供一些基础的数据结构的操作、运算、储存的函数,旨在加快基于C语言的软件工程的构建速度。运用该函数库提供的操作函数,可以省去工程中遇到的大量繁复的的高级数据结构的建构操作以及内存储存管理操作。 + +## 特性 +- 函数库提供高级数据结构实体以及配套的多样的操作函数,开发者得以主要注意力集中在主要的功能实现上。 +- 函数库提供相关函数,可以对高级数据结构快速进行基于文件的储存和基于网络的传输等工作。 +- 函数库中构建的高级数据结构有唯一的识别码,很方便可以进行查找,替换操作。 +- 函数库还提供工程的错误管理功能,使得开发者可以及时定位错误,或者让程序自动储存错误或者警告消息至文件。 + +## 分类 +该函数库主要提供以下基本数据结构操作、运算和储存函数: +- 链表 list +- 词典 dict +- 树 tree +- 图 graph +- 栈 stack +- 信息 message +## 代码风格 +本函数库秉承着可视性、稳定性与扩展性优先的原则,将在基本框架不变的情况下不断进行的优化。 From 6ddf35b26bec89fd0ddfe6e6c0265ff06694b26b Mon Sep 17 00:00:00 2001 From: Saturneic Date: Tue, 14 Aug 2018 23:59:55 +0800 Subject: [PATCH 05/12] Fixed. --- .../project.pbxproj | 10 +- .../xcdebugger/Breakpoints_v2.xcbkptlist | 72 ++----- communicate/communicate.c | 35 ++-- id/id.c | 194 +++++++++++------- id/id.h | 14 +- id/md5.c | 167 +++++++++++++++ id/md5.h | 44 ++++ list/list.c | 158 ++++++++++---- list/list.h | 21 +- list/list_expand.c | 128 ++++++++---- list/list_expand.h | 27 ++- type/type.h | 72 +++++-- 12 files changed, 678 insertions(+), 264 deletions(-) create mode 100644 id/md5.c create mode 100644 id/md5.h diff --git a/ZE-Standard-Libraries.xcodeproj/project.pbxproj b/ZE-Standard-Libraries.xcodeproj/project.pbxproj index 2186f17..c3239cb 100644 --- a/ZE-Standard-Libraries.xcodeproj/project.pbxproj +++ b/ZE-Standard-Libraries.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* 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 */; }; @@ -32,6 +33,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 9233C30E212292B000FB2485 /* md5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = md5.h; path = id/md5.h; sourceTree = ""; }; + 9233C30F212292B000FB2485 /* md5.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = md5.c; path = id/md5.c; sourceTree = ""; }; 9246994F20CD000300B4E894 /* list.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list.c; sourceTree = ""; }; 9246995020CD000300B4E894 /* list_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list_expand.h; sourceTree = ""; }; 9246995120CD000300B4E894 /* list.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list.h; sourceTree = ""; }; @@ -70,10 +73,10 @@ 9246994E20CD000300B4E894 /* list */ = { isa = PBXGroup; children = ( + 9246995120CD000300B4E894 /* list.h */, 9246994F20CD000300B4E894 /* list.c */, 9246995020CD000300B4E894 /* list_expand.h */, 9269D4E9210F1B4B00161557 /* list_expand.c */, - 9246995120CD000300B4E894 /* list.h */, ); path = list; sourceTree = ""; @@ -111,8 +114,10 @@ 9269D4F1210F1B9E00161557 /* id */ = { isa = PBXGroup; children = ( - 9269D4F2210F1BB000161557 /* id.c */, 9269D4F3210F1BB000161557 /* id.h */, + 9269D4F2210F1BB000161557 /* id.c */, + 9233C30E212292B000FB2485 /* md5.h */, + 9233C30F212292B000FB2485 /* md5.c */, ); name = id; sourceTree = ""; @@ -223,6 +228,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 9233C310212292B000FB2485 /* md5.c in Sources */, 9269D4F6210F1CD900161557 /* stack.c in Sources */, 9286EB7A211400C900752977 /* error.c in Sources */, 9269D4E8210F1B3D00161557 /* stack_expand.c in Sources */, diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index ee2d7ff..79ccac5 100644 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -191,8 +191,8 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "19" endingLineNumber = "19" - landmarkName = "initS_id" - landmarkType = "9"> + landmarkName = "unknown" + landmarkType = "0"> @@ -223,7 +223,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "102" endingLineNumber = "102" - landmarkName = "s_idToASCIIString" + landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -239,7 +239,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "122" endingLineNumber = "122" - landmarkName = "s_idToASCIIString" + landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -255,7 +255,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "136" endingLineNumber = "136" - landmarkName = "s_idToASCIIString" + landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -272,7 +272,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "128" endingLineNumber = "128" - landmarkName = "s_idToASCIIString" + landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -305,7 +305,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "133" endingLineNumber = "133" - landmarkName = "s_idToASCIIString" + landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -322,7 +322,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "139" endingLineNumber = "139" - landmarkName = "s_idToASCIIString" + landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -338,7 +338,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "143" endingLineNumber = "143" - landmarkName = "s_idToASCIIString" + landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -354,7 +354,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "147" endingLineNumber = "147" - landmarkName = "s_idToASCIIString" + landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -386,7 +386,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "240" endingLineNumber = "240" - landmarkName = "freeS_id" + landmarkName = "freeSidRaw" landmarkType = "9"> @@ -466,7 +466,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "126" endingLineNumber = "126" - landmarkName = "s_idToASCIIString" + landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -498,7 +498,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "239" endingLineNumber = "239" - landmarkName = "freeS_id" + landmarkName = "freeSidRaw" landmarkType = "9"> @@ -562,7 +562,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "83" endingLineNumber = "83" - landmarkName = "listThrough" + landmarkName = "s_findByIndexForNode" landmarkType = "9"> @@ -694,22 +694,6 @@ landmarkType = "9"> - - - - @@ -854,22 +838,6 @@ landmarkType = "9"> - - - - @@ -1042,8 +1010,8 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "266" endingLineNumber = "266" - landmarkName = "unknown" - landmarkType = "0"> + landmarkName = "releaseDFile" + landmarkType = "9"> diff --git a/communicate/communicate.c b/communicate/communicate.c index 5dfdac9..81c1593 100644 --- a/communicate/communicate.c +++ b/communicate/communicate.c @@ -14,7 +14,6 @@ STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long lon int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data){ char *t_data = (char *)data; /*unsigned int data_size = sizeof(data);*/ - for(int i = 0; i < p_stdb->blocks_num; i++){ p_stdb->buff[i] = t_data[i]; } @@ -31,11 +30,11 @@ STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid){ STD_DATA *initStandardData(unsigned int type){ STD_DATA *p_std = (STD_DATA *)malloc(sizeof(STD_DATA)); - p_std->pd_blocklst = initList(); - p_std->pd_ctnlst = initList(); + p_std->pd_blocklst = initList(0); + p_std->pd_ctnlst = initList(0); p_std->lock = 0; p_std->type = type; - p_std->s_id = getS_id(STANDARD_DATA, 1); + p_std->s_id = NULL; return p_std; } @@ -60,7 +59,7 @@ D_FILE *initDataFileForWrite(char *route){ p_dfile->pf_head = (F_HEAD *)malloc(sizeof(F_HEAD)); strcpy(p_dfile->pf_head->head_test,"ZESTDLIB_STDDFILE"); p_dfile->pf_head->data_num = 0; - p_dfile->pf_stdlst = initList(); + p_dfile->pf_stdlst = initList(0); return p_dfile; } @@ -69,7 +68,7 @@ D_FILE *initDataFileForRead(char *route){ p_dfile->fp = fopen(route, "rb"); p_dfile->pf_head = (F_HEAD *)malloc(sizeof(F_HEAD)); p_dfile->pf_head->data_num = 0; - p_dfile->pf_stdlst = initList(); + p_dfile->pf_stdlst = initList(0); return p_dfile; } @@ -83,7 +82,7 @@ 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(); + List *er_list = initList(0); insertInTail(er_list, nodeWithPointer(p_dfile->fp)); /*fwrite("STDINFO", sizeof(char), 8, p_dfile->fp); listThrough(p_dfile->pf_stdlst, _doStandardDataInfoWrite, er_list);*/ @@ -93,7 +92,7 @@ int dataFileWriteIn(D_FILE *p_dfile){ return 0; } List *_doStandardDataInfoWrite(unsigned int type, void *value, List *er_list){ - List *p_rtnlst = initList(); + List *p_rtnlst = initList(0); FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); STD_DATA *p_std = value; insertInTail(p_rtnlst, nodeWithInt(0)); @@ -107,11 +106,11 @@ List *_doStandardDataInfoWrite(unsigned int type, void *value, List *er_list){ } List *_doStandardDataWrite(unsigned int type, void *value, List *er_list){ - List *p_rtnlst = initList(); + List *p_rtnlst = initList(0); FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); insertInTail(p_rtnlst, nodeWithInt(0)); STD_DATA *p_std = value; - List *erc_list = initList(); + List *erc_list = initList(0); insertInTail(erc_list, nodeWithPointer(fp)); fwrite("STD", sizeof(char), 4, fp); char *string_sid = s_idToASCIIString(p_std->s_id); @@ -131,7 +130,7 @@ List *_doStandardDataWrite(unsigned int type, void *value, List *er_list){ } List *_doStandardDConnectionWrite(unsigned int type, void *value, List *er_list){ - List *p_rtnlst = initList(); + List *p_rtnlst = initList(0); insertInTail(p_rtnlst, nodeWithInt(0)); FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); STD_CTN *p_stdc = value; @@ -144,7 +143,7 @@ List *_doStandardDConnectionWrite(unsigned int type, void *value, List *er_list) } List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list){ - List *p_rtnlst = initList(); + List *p_rtnlst = initList(0); insertInTail(p_rtnlst, nodeWithInt(0)); STD_BLOCKS *p_stdb = value; FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); @@ -160,6 +159,7 @@ List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list){ 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 = p_list->s_id; while (p_node != NULL) { unsigned long long data_size = 0; if(p_node->type == INT) data_size = sizeof(int); @@ -250,14 +250,13 @@ int releaseSTDConnection(STD_CTN *p_stdc){ } int releaseSTDBlocks(STD_BLOCKS *p_stdb){ - free(p_stdb->sid); free(p_stdb->buff); + free(p_stdb->sid); free(p_stdb); return 0; } int releaseStandardData(STD_DATA *p_std){ - freeS_id(p_std->s_id); releaseListForCustom(p_std->pd_blocklst, (int (*)(void *))releaseSTDBlocks); releaseListForCustom(p_std->pd_ctnlst, (int (*)(void *))releaseSTDConnection); free(p_std); @@ -273,19 +272,19 @@ int releaseDFile(D_FILE *p_dfile){ } List *standardDataToList(STD_DATA *p_std){ - List *p_list = initList(); - List *er_list = initList(); + List *p_list = initList(0); + List *er_list = initList(0); insertInTail(er_list, nodeWithPointer(er_list)); listThrough(p_std->pd_blocklst, _doStandardDataToList, er_list); return p_list; } List *_doStandardDataToList(unsigned int type, void *value, List *er_list){ - List *rtn_list = initList(); + List *rtn_list = initList(0); insertInTail(rtn_list, nodeWithInt(0)); List *p_list = getByPointerForNode(findByIndexForNode(er_list, 0)); STD_BLOCKS *p_stdb = value; - Node *p_node = initNode(); + Node *p_node = initNode(0); p_node->s_id = asciiStringToS_id(p_stdb->sid); p_node->type = p_stdb->type; p_node->value = malloc(sizeof(p_stdb->blocks_num)); diff --git a/id/id.c b/id/id.c index 2c862da..1781ad2 100644 --- a/id/id.c +++ b/id/id.c @@ -1,5 +1,7 @@ #include "id.h" +static _Bool if_rand = 0; + void init_rand(void) { srand((unsigned)time(NULL)); } @@ -16,30 +18,33 @@ unsigned long long getId(void) { } SID *initS_id(unsigned int deep_level){ + if (!if_rand) init_rand(); SID *p_sid = (SID *) malloc(sizeof(SID)); if(p_sid == NULL){ printf("\ninitS_id(): Error in getting the memory of sid.\n"); } - p_sid->type = VOID; + p_sid->sr = malloc(sizeof(struct sid_raw)); + p_sid->sr->type = VOID; p_sid->deep = deep_level; - p_sid->value = NULL; - p_sid->value_deeper = NULL; - p_sid->value_deepest = NULL; + p_sid->sr->value = NULL; + p_sid->sr->value_deeper = NULL; + p_sid->sr->value_deepest = NULL; + p_sid->md5 = NULL; if (deep_level > 0) { - p_sid->value = (unsigned int *)malloc(sizeof(unsigned int)*DEEPC_LEN); - if(p_sid->value == NULL){ + p_sid->sr->value = (unsigned int *)malloc(sizeof(unsigned int)*DEEPC_LEN); + if(p_sid->sr->value == NULL){ printf("\ninitS_id(): Error in getting the memory of sid.value.\n"); } } if (deep_level > 1){ - p_sid->value_deeper = (unsigned int *)malloc(sizeof(unsigned int)*DEEPB_LEN); - if(p_sid->value_deeper == NULL){ + p_sid->sr->value_deeper = (unsigned int *)malloc(sizeof(unsigned int)*DEEPB_LEN); + if(p_sid->sr->value_deeper == NULL){ printf("\ninitS_id(): Error in getting the memory of sid.value_deeper.\n"); } } if (deep_level > 2){ - p_sid->value_deepest = (unsigned int *)malloc(sizeof(unsigned int)*DEEPA_LEN); - if(p_sid->value_deepest == NULL){ + p_sid->sr->value_deepest = (unsigned int *)malloc(sizeof(unsigned int)*DEEPA_LEN); + if(p_sid->sr->value_deepest == NULL){ printf("\ninitS_id(): Error in getting the memory of sid.value_deepest.\n"); } } @@ -48,55 +53,44 @@ SID *initS_id(unsigned int deep_level){ SID *getS_id(unsigned int type, unsigned int deep_level){ SID *p_sid = initS_id(deep_level); - p_sid->type = type; + p_sid->sr->type = type; if(deep_level > 0){ - for(int i = 0; i < DEEPC_LEN; i++) p_sid->value[i] = rand()%65535; - if(deep_level > 1) for(int i = 0; i < DEEPB_LEN; i++) p_sid->value_deeper[i] = rand()%65535; - if (deep_level > 2) for(int i = 0; i < DEEPA_LEN; i++) p_sid->value_deepest[i] = rand()%65535; + for(register int i = 0; i < DEEPC_LEN; i++) p_sid->sr->value[i] = rand()%65535; + if(deep_level > 1) for(register int i = 0; i < DEEPB_LEN; i++) p_sid->sr->value_deeper[i] = rand()%65535; + if (deep_level > 2) for(register int i = 0; i < DEEPA_LEN; i++) p_sid->sr->value_deepest[i] = rand()%65535; } - + s_idToMD5(p_sid); return p_sid; } -int fitS_id(const SID *fs_id, const SID *ss_id){ - if(fs_id->type == ss_id->type){ - if(fs_id->deep == ss_id->deep){ - if (fs_id->deep > 0) - for(int i = 0; i < DEEPC_LEN; i++){ - if(fs_id->value[i] == ss_id->value[i]) continue; - else if(fs_id->value[i] > ss_id->value[i]) return 1; - else return -1; - } - if (fs_id->deep > 1) - for(int i = 0; i < DEEPB_LEN; i++){ - if(fs_id->value_deeper[i] == ss_id->value_deeper[i]) continue; - else if(fs_id->value_deeper[i] > ss_id->value_deeper[i]) return 1; - else return -1; - } - if (fs_id->deep > 2) - for(int i = 0; i < DEEPA_LEN; i++){ - if(fs_id->value_deepest[i] == ss_id->value_deepest[i]) continue; - else if(fs_id->value_deepest[i] > ss_id->value_deepest[i]) return 1; - else return -1; - } - } - else{ - if(fs_id->deep > ss_id->deep) return 1; - else return -1; - } - } - else{ - if (fs_id->type > ss_id->type) return 1; - else return -1; - } - return 0; +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); + return strcmp(fs_id->decrypt_str, ss_id->decrypt_str); } -int simFitS_id(const SID *fs_id, const SID *ss_id){ +int simFitS_id(SID * const fs_id, SID * const ss_id){ return !fitS_id(fs_id, ss_id); } -char *s_idToASCIIString(const SID *s_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; + } + return s_id->decrypt_str; +} + +char *s_idToASCIIRawString(SID * const s_id){ char *string = NULL; int deep_len = 0, temp, buff_count, string_count; unsigned int buff[DATA_BIT]; @@ -120,7 +114,7 @@ char *s_idToASCIIString(const SID *s_id){ printf("\ns_idToASCIIString(): Error in getting the memory of string.\n"); } string[deep_len] = '\0'; - temp = s_id->type; + temp = s_id->sr->type; buff_count = DATA_BIT - 1; for (int i = 0; i < DATA_BIT; i++) buff[i] = 0; while(buff_count >= 0){ @@ -131,7 +125,7 @@ char *s_idToASCIIString(const SID *s_id){ } deep_len -= DATA_BIT; for(int i = 0; i < DEEPC_LEN; i++){ - temp = s_id->value[i]; + temp = s_id->sr->value[i]; for (int i = 0; i < DATA_BIT; i++) buff[i] = 0; string_count = TYPE_LEN + (i) * 5; buff_count = DATA_BIT - 1; @@ -145,7 +139,7 @@ char *s_idToASCIIString(const SID *s_id){ deep_len -= DEEPC_LEN * DATA_BIT; if(deep_len > 0) for(int i = 0; i < DEEPB_LEN; i++){ - temp = s_id->value_deeper[i]; + temp = s_id->sr->value_deeper[i]; for (int i = 0; i < DATA_BIT; i++) buff[i] = 0; string_count = TYPE_LEN + DEEPC_LEN * DATA_BIT + (i) * DATA_BIT; buff_count = DATA_BIT - 1; @@ -160,7 +154,7 @@ char *s_idToASCIIString(const SID *s_id){ deep_len -= DEEPB_LEN * DATA_BIT; if(deep_len > 0) for(int i = 0; i < DEEPA_LEN; i++){ - temp = s_id->value_deepest[i]; + temp = s_id->sr->value_deepest[i]; for (int i = 0; i < DATA_BIT; i++) buff[i] = 0; string_count = TYPE_LEN + (DEEPC_LEN + DEEPB_LEN) * DATA_BIT + (i) * DATA_BIT; buff_count = DATA_BIT - 1; @@ -179,7 +173,7 @@ char *s_idToASCIIString(const SID *s_id){ } } -SID *asciiStringToS_id(const char *string){ +SID *asciiStringToS_id(char * const string){ SID *s_id = NULL; unsigned long long string_len = strlen(string); @@ -196,38 +190,38 @@ SID *asciiStringToS_id(const char *string){ buff[i] = (unsigned int)string[i] - 48; } - s_id->type = 0; + s_id->sr->type = 0; for (int i = 0; i < 5; i++){ - s_id->type += buff[i] ; - s_id->type *= 10u; + s_id->sr->type += buff[i] ; + s_id->sr->type *= 10u; } - s_id->type /= 10u; + s_id->sr->type /= 10u; if (string_len >= 25){ for(int i = 0; i < DEEPC_LEN; i++){ - s_id->value[i] = 0; + s_id->sr->value[i] = 0; for (int j = 0; j < 5; j++){ - s_id->value[i] += (unsigned int)buff[5 + i * 5 + j]; - if(j < 4) s_id->value[i] *= 10; + s_id->sr->value[i] += (unsigned int)buff[5 + i * 5 + j]; + if(j < 4) s_id->sr->value[i] *= 10; } } } if (string_len >= 65){ for(int i = 0; i < DEEPB_LEN; i++){ - s_id->value_deeper[i] = 0; + s_id->sr->value_deeper[i] = 0; for (int j = 0; j < 5; j++){ - s_id->value_deeper[i] += buff[25 + i * 5 + j]; - if(j < 4) s_id->value_deeper[i] *= 10; + s_id->sr->value_deeper[i] += buff[25 + i * 5 + j]; + if(j < 4) s_id->sr->value_deeper[i] *= 10; } } } if (string_len >= 225){ for(int i = 0; i < DEEPA_LEN; i++){ - s_id->value_deepest[i] = 0; + s_id->sr->value_deepest[i] = 0; for (int j = 0; j < 5; j++){ - s_id->value_deepest[i] += buff[65 + i * 5 + j]; - if(j < 4) s_id->value_deepest[i] *= 10; + s_id->sr->value_deepest[i] += buff[65 + i * 5 + j]; + if(j < 4) s_id->sr->value_deepest[i] *= 10; } } } @@ -236,18 +230,60 @@ SID *asciiStringToS_id(const char *string){ } int freeS_id(SID *s_id){ - if(s_id->value != NULL){ - free(s_id->value); - s_id->value = NULL; - } - if(s_id->value_deeper != NULL){ - free(s_id->value_deeper); - s_id->value_deeper = NULL; - } - if(s_id->value_deepest != NULL){ - free(s_id->value_deepest); - s_id->value_deepest = NULL; - } + freeSidRaw(s_id); + if (s_id->md5 != NULL) free(s_id->md5); free(s_id); return 0; } + +int freeSidRaw(SID *s_id){ + if (s_id->sr != NULL){ + if(s_id->sr->value != NULL){ + free(s_id->sr->value); + s_id->sr->value = NULL; + } + if(s_id->sr->value_deeper != NULL){ + free(s_id->sr->value_deeper); + s_id->sr->value_deeper = NULL; + } + if(s_id->sr->value_deepest != NULL){ + free(s_id->sr->value_deepest); + s_id->sr->value_deepest = 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); + 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; +} + +char hexToChar(unsigned char n){ + switch (n) { + case 1:return '1'; + case 2:return '2'; + case 3:return '3'; + case 4:return '4'; + case 5:return '5'; + case 6:return '6'; + case 7:return '7'; + case 8:return '8'; + case 9:return '9'; + case 10:return 'a'; + case 11:return 'b'; + case 12:return 'c'; + case 13:return 'd'; + case 14:return 'e'; + case 15:return 'f'; + default: + break; + } + return '0'; +} diff --git a/id/id.h b/id/id.h index abe4499..de5c239 100644 --- a/id/id.h +++ b/id/id.h @@ -6,19 +6,25 @@ #include #include #include "../type/type.h" +#include "md5.h" void init_rand(void); unsigned long long getId(void); SID *getS_id(unsigned int type, unsigned int deep_level); -int fitS_id(const SID *fs_id, const SID *ss_id); -int simFitS_id(const SID *fs_id, const SID *ss_id); +int fitS_id(SID * const fs_id, SID * const ss_id); +int simFitS_id(SID * const fs_id, SID * const ss_id); -char *s_idToASCIIString(const SID *s_id); -SID *asciiStringToS_id(const char *string); +char *s_idToASCIIString(SID * const s_id); +SID *asciiStringToS_id(char * const string); + +void s_idToMD5(SID *s_id); +char hexToChar(unsigned char); SID *initS_id(unsigned int deep_level); +int freeSidRaw(SID *s_id); int freeS_id(SID *s_id); +static _Bool if_rand; #endif /* id_h */ diff --git a/id/md5.c b/id/md5.c new file mode 100644 index 0000000..6f1c539 --- /dev/null +++ b/id/md5.c @@ -0,0 +1,167 @@ +#include "md5.h" + +unsigned char PADDING[] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +void MD5Init(MD5_CTX *context) +{ + context->count[0] = 0; + context->count[1] = 0; + context->state[0] = 0x67452301; + context->state[1] = 0xEFCDAB89; + context->state[2] = 0x98BADCFE; + context->state[3] = 0x10325476; +} + +void MD5Update(MD5_CTX *context, unsigned char *input, unsigned long inputlen) +{ + unsigned int i = 0, index = 0, partlen = 0; + index = (context->count[0] >> 3) & 0x3F; + partlen = 64 - index; + context->count[0] += inputlen << 3; + if (context->count[0] < (inputlen << 3)) + context->count[1]++; + context->count[1] += inputlen >> 29; + + if (inputlen >= partlen) + { + memcpy(&context->buffer[index], input, partlen); + MD5Transform(context->state, context->buffer); + for (i = partlen; i + 64 <= inputlen; i += 64) + MD5Transform(context->state, &input[i]); + index = 0; + } + else + { + i = 0; + } + memcpy(&context->buffer[index], &input[i], inputlen - i); +} + +void MD5Final(MD5_CTX *context, unsigned char digest[16]) +{ + unsigned int index = 0, padlen = 0; + unsigned char bits[8]; + index = (context->count[0] >> 3) & 0x3F; + padlen = (index < 56) ? (56 - index) : (120 - index); + MD5Encode(bits, context->count, 8); + MD5Update(context, PADDING, padlen); + MD5Update(context, bits, 8); + MD5Encode(digest, context->state, 16); +} + +void MD5Encode(unsigned char *output, unsigned int *input, unsigned long len) +{ + unsigned int i = 0, j = 0; + while (j < len) + { + output[j] = input[i] & 0xFF; + output[j + 1] = (input[i] >> 8) & 0xFF; + output[j + 2] = (input[i] >> 16) & 0xFF; + output[j + 3] = (input[i] >> 24) & 0xFF; + i++; + j += 4; + } +} + +void MD5Decode(unsigned int *output, unsigned char *input, unsigned long len) +{ + unsigned int i = 0, j = 0; + while (j < len) + { + output[i] = (input[j]) | + (input[j + 1] << 8) | + (input[j + 2] << 16) | + (input[j + 3] << 24); + i++; + j += 4; + } +} + +void MD5Transform(unsigned int state[4], unsigned char block[64]) +{ + unsigned int a = state[0]; + unsigned int b = state[1]; + unsigned int c = state[2]; + unsigned int d = state[3]; + unsigned int x[64]; + + MD5Decode(x, block, 64); + FF(a, b, c, d, x[0], 7, 0xd76aa478); + FF(d, a, b, c, x[1], 12, 0xe8c7b756); + FF(c, d, a, b, x[2], 17, 0x242070db); + FF(b, c, d, a, x[3], 22, 0xc1bdceee); + FF(a, b, c, d, x[4], 7, 0xf57c0faf); + FF(d, a, b, c, x[5], 12, 0x4787c62a); + FF(c, d, a, b, x[6], 17, 0xa8304613); + FF(b, c, d, a, x[7], 22, 0xfd469501); + FF(a, b, c, d, x[8], 7, 0x698098d8); + FF(d, a, b, c, x[9], 12, 0x8b44f7af); + FF(c, d, a, b, x[10], 17, 0xffff5bb1); + FF(b, c, d, a, x[11], 22, 0x895cd7be); + FF(a, b, c, d, x[12], 7, 0x6b901122); + FF(d, a, b, c, x[13], 12, 0xfd987193); + FF(c, d, a, b, x[14], 17, 0xa679438e); + FF(b, c, d, a, x[15], 22, 0x49b40821); + + + GG(a, b, c, d, x[1], 5, 0xf61e2562); + GG(d, a, b, c, x[6], 9, 0xc040b340); + GG(c, d, a, b, x[11], 14, 0x265e5a51); + GG(b, c, d, a, x[0], 20, 0xe9b6c7aa); + GG(a, b, c, d, x[5], 5, 0xd62f105d); + GG(d, a, b, c, x[10], 9, 0x2441453); + GG(c, d, a, b, x[15], 14, 0xd8a1e681); + GG(b, c, d, a, x[4], 20, 0xe7d3fbc8); + GG(a, b, c, d, x[9], 5, 0x21e1cde6); + GG(d, a, b, c, x[14], 9, 0xc33707d6); + GG(c, d, a, b, x[3], 14, 0xf4d50d87); + GG(b, c, d, a, x[8], 20, 0x455a14ed); + GG(a, b, c, d, x[13], 5, 0xa9e3e905); + GG(d, a, b, c, x[2], 9, 0xfcefa3f8); + GG(c, d, a, b, x[7], 14, 0x676f02d9); + GG(b, c, d, a, x[12], 20, 0x8d2a4c8a); + + + HH(a, b, c, d, x[5], 4, 0xfffa3942); + HH(d, a, b, c, x[8], 11, 0x8771f681); + HH(c, d, a, b, x[11], 16, 0x6d9d6122); + HH(b, c, d, a, x[14], 23, 0xfde5380c); + HH(a, b, c, d, x[1], 4, 0xa4beea44); + HH(d, a, b, c, x[4], 11, 0x4bdecfa9); + HH(c, d, a, b, x[7], 16, 0xf6bb4b60); + HH(b, c, d, a, x[10], 23, 0xbebfbc70); + HH(a, b, c, d, x[13], 4, 0x289b7ec6); + HH(d, a, b, c, x[0], 11, 0xeaa127fa); + HH(c, d, a, b, x[3], 16, 0xd4ef3085); + HH(b, c, d, a, x[6], 23, 0x4881d05); + HH(a, b, c, d, x[9], 4, 0xd9d4d039); + HH(d, a, b, c, x[12], 11, 0xe6db99e5); + HH(c, d, a, b, x[15], 16, 0x1fa27cf8); + HH(b, c, d, a, x[2], 23, 0xc4ac5665); + + + II(a, b, c, d, x[0], 6, 0xf4292244); + II(d, a, b, c, x[7], 10, 0x432aff97); + II(c, d, a, b, x[14], 15, 0xab9423a7); + II(b, c, d, a, x[5], 21, 0xfc93a039); + II(a, b, c, d, x[12], 6, 0x655b59c3); + II(d, a, b, c, x[3], 10, 0x8f0ccc92); + II(c, d, a, b, x[10], 15, 0xffeff47d); + II(b, c, d, a, x[1], 21, 0x85845dd1); + II(a, b, c, d, x[8], 6, 0x6fa87e4f); + II(d, a, b, c, x[15], 10, 0xfe2ce6e0); + II(c, d, a, b, x[6], 15, 0xa3014314); + II(b, c, d, a, x[13], 21, 0x4e0811a1); + II(a, b, c, d, x[4], 6, 0xf7537e82); + II(d, a, b, c, x[11], 10, 0xbd3af235); + II(c, d, a, b, x[2], 15, 0x2ad7d2bb); + II(b, c, d, a, x[9], 21, 0xeb86d391); + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; +} diff --git a/id/md5.h b/id/md5.h new file mode 100644 index 0000000..35a686d --- /dev/null +++ b/id/md5.h @@ -0,0 +1,44 @@ +#ifndef md5_h +#define md5_h + +#include "../type/type.h" + +#define F(x,y,z) ((x & y) | (~x & z)) +#define G(x,y,z) ((x & z) | (y & ~z)) +#define H(x,y,z) (x^y^z) +#define I(x,y,z) (y ^ (x | ~z)) +#define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n))) + +#define FF(a,b,c,d,x,s,ac) { \ +a += F(b, c, d) + x + ac; \ +a = ROTATE_LEFT(a, s); \ +a += b; \ +} + +#define GG(a,b,c,d,x,s,ac) { \ +a += G(b, c, d) + x + ac; \ +a = ROTATE_LEFT(a, s); \ +a += b; \ +} + +#define HH(a,b,c,d,x,s,ac) { \ +a += H(b, c, d) + x + ac; \ +a = ROTATE_LEFT(a, s); \ +a += b; \ +} +#define II(a,b,c,d,x,s,ac) { \ +a += I(b, c, d) + x + ac; \ +a = ROTATE_LEFT(a, s); \ +a += b; \ +} + + +void MD5Init(MD5_CTX *context); +void MD5Update(MD5_CTX *context, unsigned char *input, unsigned long inputlen); +void MD5Final(MD5_CTX *context, unsigned char digest[16]); + +void MD5Transform(unsigned int state[4], unsigned char block[64]); +void MD5Encode(unsigned char *output, unsigned int *input, unsigned long len); +void MD5Decode(unsigned int *output, unsigned char *input, unsigned long len); + +#endif /* md5_h */ diff --git a/list/list.c b/list/list.c index 67dcc73..0eda5f6 100644 --- a/list/list.c +++ b/list/list.c @@ -61,7 +61,6 @@ int releaseSingleNodeForsafeModeForNode(List *p_list) { while (p_node != NULL) { pnv_node = (Node *)p_node->value; freeS_id(pnv_node->s_id); - pnv_node->if_malloc = 0; pnv_node->last = NULL; pnv_node->next = NULL; pnv_node->type = VOID; @@ -86,22 +85,22 @@ int releaseAllForNode(void) { return 0; } -Node *initNode(void) { +Node *initNode(_Bool if_sid) { Node *p_node = (Node *)malloc(sizeof(Node)); if(p_node == NULL){ showError(pushError(LIST_NODE, STANDARD, initInfo("initNode()", "Error in getting the memory of node."))); return NULL; } Node *prec_node = NULL; - p_node->s_id = getS_id(LIST_NODE, 1); - p_node->if_sid = 1; - p_node->if_malloc = 0; + if (if_sid)p_node->s_id = getS_id(LIST_NODE, 1); + else p_node->s_id = NULL; p_node->next = NULL; p_node->last = NULL; p_node->type = VOID; + p_node->f_number = 0; if (if_safeModeForNode) { if_safeModeForNode = 0; - prec_node = initNode(); + prec_node = initNode(0); if_safeModeForNode = 1; initMallocValueForNode(prec_node, POINTER, (void *)p_node); insertInTail(node_list, prec_node); @@ -109,21 +108,29 @@ Node *initNode(void) { return p_node; } -List *initList(void) { +inline s_Node *s_initNode(void){ + s_Node *s_p_node = (s_Node *)malloc(sizeof(s_Node)); + s_p_node->next = NULL; + return s_p_node; +} + +List *initList(_Bool if_sid) { Node *p_node = NULL; List *p_list = (List *)malloc(sizeof(List)); if(p_list == NULL){ showError(pushError(LIST_NODE, STANDARD, initInfo("initList()", "Error in getting the memory of list."))); return NULL; } - p_list->s_id = getS_id(LIST, 1); - p_list->if_sid = 1; + if(if_sid) p_list->s_id = getS_id(LIST, 1); + else p_list->s_id = NULL; p_list->head = NULL; p_list->tail = NULL; p_list->length = 0; + p_list->p_lq = NULL; + p_list->s_head = NULL; if (if_safeModeForNode) { if_safeModeForNode = 0; - p_node = initNode(); + p_node = initNode(0); if_safeModeForNode = 1; initMallocValueForNode(p_node, POINTER, (void *)p_list); insertInTail(list_list, p_node); @@ -132,7 +139,6 @@ List *initList(void) { } int initMallocValueForNode(Node *p_node, unsigned int type, const void *p_value) { - p_node->if_malloc = 1; p_node->type = type; p_node->value = (void *)p_value; return 0; @@ -153,6 +159,18 @@ int insertInHead(List *p_list, Node *p_node) { return 0; } +inline int s_insertInHead(List *p_list, s_Node *s_p_node){ + if(p_list->s_head == NULL && p_list->s_tail == NULL){ + p_list->s_head = s_p_node; + p_list->s_tail = s_p_node; + } + else{ + s_p_node->next = p_list->s_head; + p_list->s_head = s_p_node; + } + return 0; +} + int insertInTail(List *p_list, Node *p_node) { if (isListEmpty(p_list)) { p_list->head = p_node; @@ -168,17 +186,29 @@ int insertInTail(List *p_list, Node *p_node) { return 0; } +inline int s_insertInTail(List *p_list, s_Node *s_p_node){ + if(p_list->s_head == NULL && p_list->s_tail == NULL){ + p_list->s_head = s_p_node; + p_list->s_tail = s_p_node; + } + else{ + p_list->s_tail->next = s_p_node; + p_list->s_tail = s_p_node; + } + return 0; +} + int releaseNode(Node *p_node) { if (if_safeModeForNode == 1) { removeByNode(node_list, p_node); } - if (p_node->if_malloc == 1) { + if (p_node->value != NULL) { if (p_node->type != POINTER) { if (p_node->type == LIST) { releaseList((List *)p_node->value); } else { - free(p_node->value); + //free(p_node->value); } } p_node->value = NULL; @@ -187,12 +217,16 @@ int releaseNode(Node *p_node) { p_node->next = NULL; p_node->type = VOID; p_node->value = NULL; - freeS_id(p_node->s_id); - p_node->if_malloc = 0; + if (p_node->s_id != NULL) freeS_id(p_node->s_id); free(p_node); return 0; } +inline int s_releaseNode(s_Node *s_p_node){ + free(s_p_node); + return 0; +} + int releaseList(List *p_list) { Node *p_node, *pl_node; @@ -211,7 +245,7 @@ int releaseList(List *p_list) { p_list->head = NULL; p_list->tail = NULL; p_list->length = 0; - freeS_id(p_list->s_id); + if (p_list->s_id != NULL) freeS_id(p_list->s_id); free(p_list); return 0; } @@ -219,7 +253,7 @@ int releaseList(List *p_list) { int releaseListForSingle(List *p_list) { p_list->head = NULL; p_list->tail = NULL; - freeS_id(p_list->s_id); + if (p_list->s_id != NULL) freeS_id(p_list->s_id); p_list->length = 0; free(p_list); return 0; @@ -377,7 +411,7 @@ Node *findByValue(List *p_list, unsigned int type, const void *value) { } List *mply_findByValue(List *p_list, unsigned int type, const void *value) { - List *f_list = initList(); + List *f_list = initList(0); Node *p_node = p_list->head; while (p_node != NULL) { if (p_node->type != type) { @@ -422,26 +456,13 @@ int isListEmpty(List *p_list) { return 0; // want to make a list empty. } -int exchangeLocation(Node *p_node, Node *t_node) { - Node *temp_next = p_node->next; - Node *temp_last = p_node->last; - p_node->last->next = t_node; - p_node->next->last = t_node; - t_node->last->next = p_node; - t_node->next->last = p_node; - p_node->next = t_node->next; - p_node->last = t_node->last; - t_node->next = temp_next; - t_node->last = temp_last; - return 0; -} - Node *copyNode(Node *p_node) { - Node *t_node = initNode(); + Node *t_node = NULL; + if (p_node->s_id == NULL) t_node = initNode(0); + else t_node = initNode(p_node->s_id->deep); t_node->s_id = p_node->s_id; t_node->last = p_node->last; t_node->next = p_node->next; - t_node->if_malloc = p_node->if_malloc; t_node->type = p_node->type; t_node->value = p_node->value; return t_node; @@ -450,7 +471,9 @@ Node *copyNode(Node *p_node) { List *copyList(List *p_list) { Node *p_node; Node *t_node; - List *t_list = initList(); + List *t_list = NULL; + if (p_list->s_id == NULL) t_list = initList(0); + else t_list = initList(p_list->s_id->deep); t_list->head = p_list->head; t_list->tail = p_list->tail; t_list->s_id = p_list->s_id; @@ -464,8 +487,7 @@ List *copyList(List *p_list) { } int releaseOnlyNode(Node *p_node) { - freeS_id(p_node->s_id); - p_node->if_malloc = 0; + if (p_node->s_id != NULL) freeS_id(p_node->s_id); p_node->last = NULL; p_node->next = NULL; p_node->type = VOID; @@ -475,10 +497,10 @@ int releaseOnlyNode(Node *p_node) { } int releaseNodeForCustom(Node *p_node, int (*func)(void *)){ - if (if_safeModeForNode == 1) { + if (if_safeModeForNode) { removeByNode(node_list, p_node); } - if (p_node->if_malloc == 1) { + if (p_node->value != NULL) { if (func(p_node->value)) showError(pushError(LIST_NODE, STANDARD, initInfo("releaseNodeForCustom()", "Error in using custom freeing value function."))); p_node->value = NULL; @@ -487,12 +509,17 @@ int releaseNodeForCustom(Node *p_node, int (*func)(void *)){ p_node->next = NULL; p_node->type = VOID; p_node->value = NULL; - freeS_id(p_node->s_id); - p_node->if_malloc = 0; + if (p_node->s_id != NULL) freeS_id(p_node->s_id); free(p_node); return 0; } +inline int s_releaseNodeForCustom(s_Node *s_p_node, int (*func)(void *)){ + func(s_p_node->value); + free(s_p_node); + return 0; +} + int releaseListForCustom(List *p_list, int (*func)(void *)){ Node *p_node, *pl_node; p_node = p_list->head; @@ -510,7 +537,20 @@ int releaseListForCustom(List *p_list, int (*func)(void *)){ p_list->head = NULL; p_list->tail = NULL; p_list->length = 0; - freeS_id(p_list->s_id); + if (p_list->s_id != NULL) freeS_id(p_list->s_id); + free(p_list); + return 0; +} + +int s_releaseListForCustom(List *p_list, int (*func)(void *)){ + register s_Node *s_p_node, *s_pl_node; + s_p_node = p_list->s_head; + while (s_p_node != NULL) { + s_pl_node = s_p_node; + s_p_node = s_p_node->next; + s_pl_node->next = NULL; + s_releaseNodeForCustom(s_pl_node,func); + } free(p_list); return 0; } @@ -565,3 +605,37 @@ int showWarning(Notice *p_notice){ free(p_notice); return 0; } + +int replaceNode(List *p_list, Node *pt_node, Node *p_node){ + p_node->next = pt_node->next; + p_node->last = pt_node->last; + if (p_list->head != pt_node) pt_node->last->next = p_node; + else p_list->head = p_node; + if(p_list->tail != pt_node) pt_node->next->last = p_node; + else p_list->tail = p_node; + return 0; +} + +int sortListById(List *p_list){ + +} + +int enableListQuick(List *p_list){ + if(p_list->length > 1500){ + p_list->p_lq = malloc(sizeof(struct list_quick)); + register Node *p_node = p_list->head; + unsigned long long i = 0; + p_list->p_lq->rlst_len = p_list->length; + p_list->p_lq->fn_node = malloc(sizeof(Node *) * p_list->length); + p_list->p_lq->p_lindex = 0; + p_list->p_lq->head_index = 0; + p_list->p_lq->tail_index = p_list->length - 1; + while (p_node != NULL) { + p_node->f_number = i++; + p_list->p_lq->fn_node[i] = p_node; + p_node = p_node->next; + } + return 0; + } + return -1; +} diff --git a/list/list.h b/list/list.h index 9124f4b..3dddefa 100644 --- a/list/list.h +++ b/list/list.h @@ -8,15 +8,18 @@ int releaseSingleListForsafeModeForNode(List *p_list); int releaseSingleNodeForsafeModeForNode(List *p_list); int releaseAllForNode(void); -List *initList(void); -Node *initNode(void); +List *initList(_Bool if_sid); +Node *initNode(_Bool if_sid); +s_Node *s_initNode(void); int initMallocValueForNode(Node *,unsigned int,const void *); int insertInHead(List *p_list, Node *p_node); int insertInTail(List *p_list, Node *p_node); +int s_insertInHead(List *p_list, s_Node *s_p_node); +int s_insertInTail(List *p_list, s_Node *s_p_node); -int exchangeLocation(Node *p_node,Node *t_node); +int replaceNode(List *p_list, Node *pt_node, Node *p_node); Node *copyNode(Node *); @@ -32,10 +35,19 @@ Node *findByValue(List *p_list, unsigned int type, const void *value); List *mply_findByValue(List *p_list, unsigned int type, const void *value); int releaseList(List *p_list); +int s_releaseList(List *p_list); + int releaseListForCustom(List *p_list, int (*func)(void *)); +int s_releaseListForCustom(List *p_list, int (*func)(void *)); + int releaseListForSingle(List *p_list); + int releaseNode(Node *p_node); +int s_releaseNode(s_Node *s_p_node); + int releaseNodeForCustom(Node *p_node, int (*func)(void *)); +int s_releaseNodeForCustom(s_Node *s_p_node, int (*func)(void *)); + int releaseOnlyNode(Node *p_node); int isListEmpty(List *p_list); @@ -51,6 +63,9 @@ Notice *createWarning(Info *info, unsigned int type, int pri); int showError(Error *); int showWarning(Notice *); +int enableListQuick(List *p_list); +int sortListById(List *p_list); + static int if_safeModeForNode; static List *node_list; static List *list_list; diff --git a/list/list_expand.c b/list/list_expand.c index 411163d..3c42536 100644 --- a/list/list_expand.c +++ b/list/list_expand.c @@ -1,6 +1,6 @@ #include "list_expand.h" -Node *nodeWithInt(int m_int) { +Node *nodeWithInt(int m_int, _Bool if_sid) { Node *p_node; int *p_int = (int *)malloc(sizeof(int)); if(p_int == NULL){ @@ -8,12 +8,12 @@ Node *nodeWithInt(int m_int) { return NULL; } *p_int = m_int; - p_node = initNode(); + p_node = initNode(if_sid); initMallocValueForNode(p_node, INT, (void *)p_int); return p_node; } -Node *nodeWithUInt(unsigned int m_uint){ +Node *nodeWithUInt(unsigned int m_uint, _Bool if_sid){ Node *p_node; unsigned int *pu_int = (unsigned int *)malloc(sizeof(unsigned int)); if(pu_int == NULL){ @@ -21,12 +21,12 @@ Node *nodeWithUInt(unsigned int m_uint){ return NULL; } *pu_int = m_uint; - p_node = initNode(); + p_node = initNode(if_sid); initMallocValueForNode(p_node, INT, (void *)pu_int); return p_node; } -Node *nodeWithDouble(double m_double) { +Node *nodeWithDouble(double m_double, _Bool if_sid) { Node *p_node; double *p_double = (double *)malloc(sizeof(double)); if(p_double == NULL){ @@ -34,12 +34,12 @@ Node *nodeWithDouble(double m_double) { return NULL; } *p_double = m_double; - p_node = initNode(); + p_node = initNode(if_sid); initMallocValueForNode(p_node, DOUBLE, (void *)p_double); return p_node; } -Node *nodeWithString(const char *m_string) { +Node *nodeWithString(const char *m_string, _Bool if_sid) { Node *p_node; char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string) + 1)); if(p_string == NULL){ @@ -47,39 +47,53 @@ Node *nodeWithString(const char *m_string) { return NULL; } strcpy(p_string, m_string); - p_node = initNode(); + p_node = initNode(if_sid); initMallocValueForNode(p_node, STRING, (void *)p_string); return p_node; } -Node *nodeWithPointer(const void *m_pointer) { - Node *p_node = initNode(); +Node *nodeWithPointer(const void *m_pointer, _Bool if_sid) { + Node *p_node = initNode(if_sid); initMallocValueForNode(p_node, POINTER, m_pointer); return p_node; } Node *nodeWithComplex(void) { - Node *p_node = initNode(); + Node *p_node = initNode(0); p_node->type = LIST; - p_node->value = initList(); - p_node->if_malloc = 1; + p_node->value = initList(0); return p_node; } -Node *findByIndexForNode(List *p_list, unsigned long long m_index) { - Node *p_node = p_list->head; - unsigned long long i; - for (i = 0; i < m_index; i++) { - p_node = p_node->next; - } - return p_node; +Node *findByIndexForNode(List *p_list, unsigned long long m_index) { + if(p_list->p_lq != NULL){ + register struct list_quick *p_lq = p_list->p_lq; + if(m_index > p_lq->head_index && p_lq->last_index) return p_lq->fn_node[m_index]; + } + else{ + Node *p_node = p_list->head; + unsigned long long i; + for (i = 0; i < m_index; i++) { + p_node = p_node->next; + } + return p_node; + } +} + +s_Node *s_findByIndexForNode(List *p_list, unsigned long long m_index) { + s_Node *s_p_node = p_list->s_head; + unsigned long long i; + for (i = 0; i < m_index; i++) { + s_p_node = s_p_node->next; + } + return s_p_node; } 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; while (p_node != NULL) { - if (p_node->if_malloc == 1) { + if (p_node->value != NULL) { List *m_rtnlst = (*p_func)(p_node->type, p_node->value, expand_resources); int status = getByIntForNode(findByIndexForNode(m_rtnlst, 0)); if (status == -1) break; @@ -178,7 +192,7 @@ void printNodeInfo(Node *p_node, int priority) { for (i = 0; i < priority; i++) printf(" "); printf("#NODE(location:%p, id:%s){\n", p_node, s_idToASCIIString(p_node->s_id)); for (i = 0; i < priority + 1; i++) printf(" "); - printf("NEXT->%p / LAST->%p / MALLOC:%d\n", p_node->next, p_node->last, p_node->if_malloc); + printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last); if (p_node->type == INT) { for (i = 0; i < priority + 1; i++) printf(" "); printf("VALUE(int):%d\n", *(int *)(p_node->value)); @@ -211,7 +225,7 @@ void printNode(Node *p_node) { printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last); for (i = 0; i < 1; i++) printf(" "); printf("ifMalloc: "); - if (p_node->if_malloc) { + if (p_node->value != NULL) { printf("YES\n"); for (i = 0; i < 1; i++) printf(" "); printf("Value(type: %d): ", p_node->type); @@ -274,7 +288,7 @@ int addValueForComplex(Node * p_node, int type, void *value) { Node *c_node; if (p_node->type == LIST) { c_list = (List *)p_node->value; - c_node = initNode(); + c_node = initNode(0); initMallocValueForNode(c_node, type, value); insertInTail(c_list, c_node); return 0; @@ -376,18 +390,25 @@ List *m_findByPointer(List* p_list, void *temp) { return t_list; } -unsigned long long getIndexByNode(List *p_list, Node *p_node) { - Node *t_node = p_list->head; - unsigned long long index = 0; - while (t_node != NULL) { - if (p_node->s_id == t_node->s_id) return index; - index++; - t_node = t_node->next; - } +unsigned long long getIndexByNode(List *p_list, Node *p_node) { + if (p_list->p_lq != NULL){ + register Node **p_fn_node = p_list->p_lq->fn_node; + register Node *rp_node = p_node; + for (register int i = 0; i < p_list->length; i++) if (p_fn_node[i] == rp_node) return i; + } + else{ + register Node *t_node = p_list->head; + register unsigned long long index = 0; + while (t_node != NULL) { + if (p_node->s_id == t_node->s_id) return index; + index++; + t_node = t_node->next; + } + } return 0; } -List *m_findByIntForNode(List* p_list, int temp) { +List *plym_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."))); @@ -397,7 +418,7 @@ List *m_findByIntForNode(List* p_list, int temp) { return mply_findByValue(p_list, INT, (void *)p_temp); } -List *m_findByDoubleForNode(List* p_list, double temp) { +List *mply_findByDoubleForNode(List* p_list, double temp) { double *p_temp = (double *)malloc(sizeof(double)); if(p_temp == NULL){ showError(pushError(DOUBLE, STANDARD, initInfo("m_findByDoubleForNode()", "Error in getting the memory of double."))); @@ -407,7 +428,7 @@ List *m_findByDoubleForNode(List* p_list, double temp) { return mply_findByValue(p_list, DOUBLE, (void *)p_temp); } -List *m_findByStringForNode(List* p_list, char *temp) { +List *mply_findByStringForNode(List* p_list, char *temp) { char *p_temp = (char *)malloc(sizeof(char) * (strlen(temp) + 1)); if(p_temp == NULL){ showError(pushError(STRING, STANDARD, initInfo("m_findByStringForNode()", "Error in getting the memory of string."))); @@ -417,7 +438,7 @@ List *m_findByStringForNode(List* p_list, char *temp) { return mply_findByValue(p_list, STRING, (void *)p_temp); } -List *m_findByPointerForNode(List* p_list, void *temp) { +List *mply_findByPointerForNode(List* p_list, void *temp) { return mply_findByValue(p_list, POINTER, (void *)temp); } @@ -473,3 +494,38 @@ int updateValueWithPointer(Node *p_node, void *pointer){ p_node->value = pointer; return 0; } + +inline s_Node *s_nodeWithInt(int t_int){ + s_Node *s_p_node = s_initNode(); + int *pt_int = malloc(sizeof(int)); + *pt_int = t_int; + s_p_node->value = pt_int; + return s_p_node; +} + +inline s_Node *s_nodeWithUInt(unsigned int t_uint){ + s_Node *s_p_node = s_initNode(); + unsigned int *pt_uint = malloc(sizeof(unsigned int)); + *pt_uint = t_uint; + s_p_node->value = pt_uint; + return s_p_node; +} +inline s_Node *s_nodeWithDouble(double t_double){ + s_Node *s_p_node = s_initNode(); + unsigned int *pt_double = malloc(sizeof(double)); + *pt_double = t_double; + s_p_node->value = pt_double; + return s_p_node; +} +inline s_Node *s_nodeWithString(const char *t_string){ + s_Node *s_p_node = s_initNode(); + char *pt_string = malloc(strlen(t_string) + 1); + strcpy(pt_string, t_string); + s_p_node->value = pt_string; + return s_p_node; +} +inline s_Node *s_nodeWithPointer(const void *t_pointer){ + s_Node *s_p_node = s_initNode(); + s_p_node->value = (void *) t_pointer; + return s_p_node; +} diff --git a/list/list_expand.h b/list/list_expand.h index dff20b7..ea35fcc 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -7,7 +7,13 @@ Node *nodeWithInt(int); Node *nodeWithUInt(unsigned int); Node *nodeWithDouble(double); Node *nodeWithString(const char *); -Node *nodeWithPointer(const void *); +Node *nodeWithPointer(const void *); + +s_Node *s_nodeWithInt(int); +s_Node *s_nodeWithUInt(unsigned int); +s_Node *s_nodeWithDouble(double); +s_Node *s_nodeWithString(const char *); +s_Node *s_nodeWithPointer(const void *); Node *nodeWithComplex(void); int addValueForComplex(Node *, int type, void *value); @@ -16,11 +22,10 @@ int addDoubleForComplex(Node *, double); int addStringForComplex(Node *, char *); int addPointerForComplex(Node *, void *); -int updateValueWithInt(Node *,int); -int updateValueWithDouble(Node *,double); -int updateValueWithString(Node *,char *); -int updateValueWithPointer(Node *,void *); - +int updateValueWithIntForNode(Node *,int); +int updateValueWithDoubleForNode(Node *,double); +int updateValueWithStringForNode(Node *,char *); +int updateValueWithPointerForNode(Node *,void *); Node *findByIndexForNode(List *, unsigned long long); Node *findByIntForNode(List *, int); @@ -28,10 +33,10 @@ Node *findByDoubleForNode(List *, double); Node *findByStringForNode(List *, char *); Node *findByPointerForNode(List *, void *); -List *m_findByIntForNode(List*, int); -List *m_findByDoubleForNode(List*, double); -List *m_findByStringForNode(List*, char *); -List *m_findByPointerForNode(List*, void *); +List *mply_findByIntForNode(List*, int); +List *mply_findByDoubleForNode(List*, double); +List *mply_findByStringForNode(List*, char *); +List *mply_findByPointerForNode(List*, void *); void printListInfo(List *p_list,int priority); void printNodeInfo(Node *p_node,int priority); @@ -43,7 +48,7 @@ unsigned int getByUIntForNode(Node *); double getByDoubleForNode(Node *); char *getByStringForNode(Node *); void *getByPointerForNode(Node *); -unsigned long long getIndexByNode(List *p_list,Node *p_node); +unsigned long long getIndexForNode(List *p_list,Node *p_node); List *listThrough(List *p_list, List *(*p_func)(unsigned int type, void *value, List *), List *expand_resources); unsigned long long calListMemory(List *); diff --git a/type/type.h b/type/type.h index a1dbaa1..f07ca18 100644 --- a/type/type.h +++ b/type/type.h @@ -51,33 +51,71 @@ #define STANDARD 0x2 #define LOW 0x1 -typedef struct s_id{ +typedef struct md5_ctx{ + unsigned int count[2]; + unsigned int state[4]; + unsigned char buffer[64]; +}MD5_CTX; + +struct sid_raw{ unsigned int type; unsigned int *value;//4 unsigned int *value_deeper;//8 unsigned int *value_deepest;//32 +}; + +typedef struct s_id{ + struct sid_raw *sr; unsigned int deep; + MD5_CTX *md5; + unsigned char decrypt_hex[16]; + char *decrypt_str; + }SID; typedef struct Node{ - SID *s_id; - void *value; - _Bool if_malloc; - _Bool if_sid; + unsigned long long f_number; unsigned int type; + void *value; struct Node *next; struct Node *last; + SID *s_id; } Node; +typedef struct simple_Node{ + void *value; + struct simple_Node *next; +}s_Node; + +struct lst_std_id{ + unsigned long long start_idx; + unsigned long long end_idx; + SID *sid; +}; + +struct list_quick; typedef struct List{ - SID *s_id; Node *head; Node *tail; - _Bool if_sid; + s_Node *s_head; + s_Node *s_tail; + struct list_quick *p_lq; unsigned long long length; + SID *s_id; } List; +struct list_quick{ + Node **fn_node; + unsigned long long last_index; + Node *p_lindex; + unsigned long long head_index; + unsigned long long tail_index; + unsigned long long rlst_len; + FILE *fp; + List *stdid_lst; +}; + typedef struct Info{ char head[64]; char body[256]; @@ -86,14 +124,14 @@ typedef struct Info{ typedef struct Error{ unsigned int type; int priority; - Info info; time_t time; + Info info; }Error; typedef struct Notice{ unsigned int type; - Info info; time_t time; + Info info; }Notice; typedef struct Log{ @@ -103,19 +141,16 @@ typedef struct Log{ }Log; typedef struct stack_node{ - SID *s_id; - _Bool if_malloc; - _Bool if_sid; unsigned int type; void *value; struct stack_node *next; + SID *s_id; } SNode; typedef struct stack{ - SID *s_id; unsigned long long length; SNode *top; - _Bool if_sid; + SID *s_id; } Stack; typedef struct tree_node @@ -127,15 +162,18 @@ typedef struct tree_node unsigned long long child_num; unsigned int type; void *value; - _Bool if_malloc; - _Bool if_sid; }TNode; +typedef struct simple_tree_node{ + void *value; + struct simple_tree_node *childs[2]; +}s_TNode; + typedef struct tree { SID *s_id; - _Bool if_sid; TNode *root; + s_TNode *s_root; }Tree; typedef struct file_head{ From 6a00c6bead23593443427be59eef4c4acf251b7c Mon Sep 17 00:00:00 2001 From: Saturneic Date: Fri, 17 Aug 2018 16:58:15 +0800 Subject: [PATCH 06/12] Changed. --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 126 +----- communicate/communicate.c | 119 +++--- communicate/communicate.h | 2 + id/id.c | 27 +- id/id.h | 4 +- list/list.c | 363 ++++++++++++++++-- list/list.h | 54 ++- list/list_expand.c | 89 ++++- list/list_expand.h | 40 +- test.c | 18 +- type/type.h | 23 +- 11 files changed, 612 insertions(+), 253 deletions(-) diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 79ccac5..7e920d0 100644 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -386,7 +386,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "240" endingLineNumber = "240" - landmarkName = "freeSidRaw" + landmarkName = "freeS_id" landmarkType = "9"> @@ -498,7 +498,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "239" endingLineNumber = "239" - landmarkName = "freeSidRaw" + landmarkName = "freeS_id" landmarkType = "9"> @@ -518,38 +518,6 @@ landmarkType = "9"> - - - - - - - - - - - - @@ -598,22 +550,6 @@ landmarkType = "9"> - - - - + endingLineNumber = "100"> @@ -866,8 +800,8 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "43" endingLineNumber = "43" - landmarkName = "standardDataAddBlock" - landmarkType = "9"> + landmarkName = "unknown" + landmarkType = "0"> - - - - - - - - + endingLineNumber = "99"> + landmarkName = "unknown" + landmarkType = "0"> @@ -1042,7 +942,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "267" endingLineNumber = "267" - landmarkName = "releaseDFile" + landmarkName = "releaseSTDBlocks" landmarkType = "9"> @@ -1058,7 +958,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "508" endingLineNumber = "508" - landmarkName = "releaseNodeForCustom" + landmarkName = "copyNode" landmarkType = "9"> diff --git a/communicate/communicate.c b/communicate/communicate.c index 81c1593..d451b32 100644 --- a/communicate/communicate.c +++ b/communicate/communicate.c @@ -2,7 +2,10 @@ STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long long data_size){ STD_BLOCKS *p_stdb = (STD_BLOCKS *)malloc(sizeof(STD_BLOCKS)); - p_stdb->sid = s_idToASCIIString(p_sid); + if(p_sid != NULL){ + p_stdb->sid = s_idToASCIIString(p_sid); + } + else p_stdb->sid = NULL; p_stdb->if_data = 0; unsigned int blocks_num = (unsigned int)(data_size/sizeof(char)); p_stdb->blocks_num = blocks_num; @@ -42,14 +45,14 @@ int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,unsigned int type, void *d if (p_std->lock) return -1; STD_BLOCKS *p_stdb = initStandardDBlocks(p_sid, type,data_size); dataForStandardDBlock(p_stdb, data); - insertInTail(p_std->pd_blocklst, nodeWithPointer(p_stdb)); + insertInTail(p_std->pd_blocklst, nodeWithPointer(p_stdb,0)); return 0; } int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid){ if (p_std->lock) return -1; STD_CTN *p_stdb = initStandardDConnection(f_sid, s_sid); - insertInTail(p_std->pd_ctnlst, nodeWithPointer(p_stdb)); + insertInTail(p_std->pd_ctnlst, nodeWithPointer(p_stdb,0)); return 0; } @@ -73,7 +76,7 @@ D_FILE *initDataFileForRead(char *route){ } int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){ - insertInTail(p_dfile->pf_stdlst, nodeWithPointer(p_std)); + insertInTail(p_dfile->pf_stdlst, nodeWithPointer(p_std,0)); p_dfile->pf_head->data_num = p_dfile->pf_stdlst->length; return 0; } @@ -83,7 +86,7 @@ int dataFileWriteIn(D_FILE *p_dfile){ 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)); + 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);*/ @@ -91,14 +94,23 @@ int dataFileWriteIn(D_FILE *p_dfile){ releaseList(er_list); 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)); - char *string_sid = s_idToASCIIString(p_std->s_id); - fwrite(string_sid, sizeof(char), DEEPER_LEN, fp); - free(string_sid); + 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); @@ -108,48 +120,45 @@ List *_doStandardDataInfoWrite(unsigned int type, void *value, List *er_list){ 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)); + insertInTail(p_rtnlst, nodeWithInt(0,0)); STD_DATA *p_std = value; List *erc_list = initList(0); - insertInTail(erc_list, nodeWithPointer(fp)); + insertInTail(erc_list, nodeWithPointer(fp,0)); fwrite("STD", sizeof(char), 4, fp); - char *string_sid = s_idToASCIIString(p_std->s_id); - unsigned long sid_len = strlen(string_sid) + 1; - fwrite(&sid_len, sizeof(unsigned long), 1, fp); - char *sid_w = s_idToASCIIString(p_std->s_id); - fwrite(sid_w, 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); - free(sid_w); - free(string_sid); return p_rtnlst; } List *_doStandardDConnectionWrite(unsigned int type, void *value, List *er_list){ List *p_rtnlst = initList(0); - insertInTail(p_rtnlst, nodeWithInt(0)); + insertInTail(p_rtnlst, nodeWithInt(0,0)); FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); STD_CTN *p_stdc = value; - unsigned long fsid_len = strlen(p_stdc->f_sid) + 1, ssid_len = strlen(p_stdc->s_sid)+1; - fwrite(&fsid_len, sizeof(unsigned long), 1, fp); - fwrite(p_stdc->f_sid, sizeof(char), fsid_len, fp); - fwrite(&ssid_len, sizeof(unsigned long), 1, fp); - fwrite(p_stdc->s_sid, sizeof(char), ssid_len, fp); + fwrite(p_stdc->f_sid, sizeof(char), SID_LEN, fp); + fwrite(p_stdc->s_sid, sizeof(char), SID_LEN, fp); return p_rtnlst; } List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list){ List *p_rtnlst = initList(0); - insertInTail(p_rtnlst, nodeWithInt(0)); + insertInTail(p_rtnlst, nodeWithInt(0,0)); STD_BLOCKS *p_stdb = value; FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); - unsigned long sid_len = strlen(p_stdb->sid)+1, blocks_num = p_stdb->blocks_num; - fwrite(&sid_len, sizeof(unsigned long), 1, fp); - fwrite(p_stdb->sid, sizeof(char), sid_len, fp); + unsigned long blocks_num = p_stdb->blocks_num; + int if_sid = 0; + if(p_stdb->sid != NULL){ + if_sid = 1; + fwrite(&if_sid, sizeof(int), 1, fp); + fwrite(p_stdb->sid, sizeof(char), SID_LEN, fp); + } + else{ + fwrite(&if_sid, sizeof(int), 1, fp); + } 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); @@ -159,8 +168,9 @@ List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list){ 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 = p_list->s_id; + if (p_list->s_id != NULL) p_std->s_id = copyS_id(p_list->s_id); while (p_node != NULL) { + if(p_node->type == HOLE) continue; unsigned long long data_size = 0; if(p_node->type == INT) data_size = sizeof(int); else if (p_node->type == DOUBLE) data_size = sizeof(double); @@ -186,26 +196,28 @@ int dataFileReadOut(D_FILE *p_dfile){ char std_test_info[4]; fread(std_test_info, sizeof(char), 4, p_dfile->fp); if(!strcmp(std_test_info, "STD")){ - unsigned long long sid_len = 0, ctn_num = 0, blk_num = 0; + unsigned long long ctn_num = 0, blk_num = 0; + int if_sid = 0; unsigned int type = 0; - fread(&sid_len, sizeof(unsigned long), 1, p_dfile->fp); - char *string_sid = (char *)malloc(sizeof(char) * sid_len); - fread(string_sid, sizeof(char), sid_len, p_dfile->fp); + 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); - free(string_sid); + 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++){ - fread(&sid_len, sizeof(unsigned long), 1, p_dfile->fp); - char *fstring_sid = (char *)malloc(sizeof(char) * sid_len); - fread(fstring_sid, sizeof(char), sid_len, p_dfile->fp); - fread(&sid_len, sizeof(unsigned long), 1, p_dfile->fp); - char *sstring_sid = (char *)malloc(sizeof(char) * sid_len); - fread(sstring_sid, sizeof(char), sid_len, p_dfile->fp); + 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); @@ -214,9 +226,12 @@ int dataFileReadOut(D_FILE *p_dfile){ free(sstring_sid); } for(int k = 0; k < blk_num; k++){ - fread(&sid_len, sizeof(unsigned long), 1, p_dfile->fp); - char *string_sid = (char *)malloc(sizeof(char) * sid_len); - fread(string_sid, sizeof(char), sid_len, p_dfile->fp); + 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); @@ -226,7 +241,7 @@ int dataFileReadOut(D_FILE *p_dfile){ fread(&type, sizeof(unsigned int), 1, p_dfile->fp); standardDataAddBlock(p_std, s_id, type, content, blk_len); freeS_id(s_id); - free(string_sid); + if(string_sid != NULL) free(string_sid); free(content); } return 0; @@ -274,14 +289,14 @@ 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)); + insertInTail(er_list, nodeWithPointer(er_list,0)); listThrough(p_std->pd_blocklst, _doStandardDataToList, er_list); return p_list; } List *_doStandardDataToList(unsigned int type, void *value, List *er_list){ List *rtn_list = initList(0); - insertInTail(rtn_list, nodeWithInt(0)); + insertInTail(rtn_list, nodeWithInt(0,0)); List *p_list = getByPointerForNode(findByIndexForNode(er_list, 0)); STD_BLOCKS *p_stdb = value; Node *p_node = initNode(0); @@ -293,6 +308,18 @@ List *_doStandardDataToList(unsigned int type, void *value, List *er_list){ return rtn_list; } +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; +} + +CALLBACK_DEFINE(calStandardDataCTN){ + + return C_RETURN; +} + MSG *createMessage(char *title, void *data, unsigned long data_size){ MSG *p_msg = malloc(sizeof(MSG) + data_size); p_msg->p_sid = getS_id(MESSAGE, 1); diff --git a/communicate/communicate.h b/communicate/communicate.h index cff8f99..cf9e7d7 100644 --- a/communicate/communicate.h +++ b/communicate/communicate.h @@ -29,6 +29,8 @@ 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); List *_doStandardDataInfoWrite(unsigned int type, void *value, List *er_list); List *_doStandardDataWrite(unsigned int type, void *value, List *er_list); diff --git a/id/id.c b/id/id.c index 1781ad2..f65ceb6 100644 --- a/id/id.c +++ b/id/id.c @@ -30,6 +30,10 @@ SID *initS_id(unsigned int deep_level){ p_sid->sr->value_deeper = NULL; p_sid->sr->value_deepest = NULL; p_sid->md5 = NULL; + return p_sid; +} + +void getRawS_id(SID *p_sid, unsigned int type, unsigned int deep_level){ if (deep_level > 0) { p_sid->sr->value = (unsigned int *)malloc(sizeof(unsigned int)*DEEPC_LEN); if(p_sid->sr->value == NULL){ @@ -48,17 +52,17 @@ SID *initS_id(unsigned int deep_level){ printf("\ninitS_id(): Error in getting the memory of sid.value_deepest.\n"); } } - return p_sid; -} - -SID *getS_id(unsigned int type, unsigned int deep_level){ - SID *p_sid = initS_id(deep_level); p_sid->sr->type = type; if(deep_level > 0){ for(register int i = 0; i < DEEPC_LEN; i++) p_sid->sr->value[i] = rand()%65535; if(deep_level > 1) for(register int i = 0; i < DEEPB_LEN; i++) p_sid->sr->value_deeper[i] = rand()%65535; if (deep_level > 2) for(register int i = 0; i < DEEPA_LEN; i++) p_sid->sr->value_deepest[i] = rand()%65535; } +} + +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); return p_sid; } @@ -69,7 +73,7 @@ int fitS_id(SID * const fs_id, SID * const ss_id){ return strcmp(fs_id->decrypt_str, ss_id->decrypt_str); } -int simFitS_id(SID * const fs_id, SID * const ss_id){ +int simFitS_id(SID * fs_id, SID * ss_id){ return !fitS_id(fs_id, ss_id); } @@ -87,7 +91,9 @@ char *s_idToASCIIString(SID * const s_id){ free(s_id->md5); s_id->md5 = NULL; } - return s_id->decrypt_str; + char *rtn_str = malloc(sizeof(char) * 33); + strcpy(rtn_str, s_id->decrypt_str); + return rtn_str; } char *s_idToASCIIRawString(SID * const s_id){ @@ -287,3 +293,10 @@ char hexToChar(unsigned char n){ } return '0'; } + +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; +} diff --git a/id/id.h b/id/id.h index de5c239..59b9d10 100644 --- a/id/id.h +++ b/id/id.h @@ -14,13 +14,15 @@ unsigned long long getId(void); SID *getS_id(unsigned int type, unsigned int deep_level); int fitS_id(SID * const fs_id, SID * const ss_id); -int simFitS_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 s_idToMD5(SID *s_id); char hexToChar(unsigned char); +SID *copyS_id(SID *f_sid); +void getRawS_id(SID *s_id, unsigned int type, unsigned int deep_level); SID *initS_id(unsigned int deep_level); int freeSidRaw(SID *s_id); diff --git a/list/list.c b/list/list.c index 0eda5f6..46accec 100644 --- a/list/list.c +++ b/list/list.c @@ -145,6 +145,18 @@ int initMallocValueForNode(Node *p_node, unsigned int type, const void *p_value) } int insertInHead(List *p_list, Node *p_node) { + if(p_list->p_lq != NULL && p_list->p_lq->if_sort) return -1; + if(p_list->p_lq != NULL){ + if(p_list->head->type == HOLE){ + Node *t_node = p_list->head; + replaceNode(p_list, p_list->head, p_node); + p_list->p_lq->fn_node[0] = p_node; + releaseNode(t_node); + indexChange(p_list, 0, 1); + return 0; + } + indexChange(p_list, 0, 1); + } if (isListEmpty(p_list)) { p_list->head = p_node; p_list->tail = p_node; @@ -172,6 +184,7 @@ inline int s_insertInHead(List *p_list, s_Node *s_p_node){ } int insertInTail(List *p_list, Node *p_node) { + if(p_list->p_lq != NULL && p_list->p_lq->if_sort) return -1; if (isListEmpty(p_list)) { p_list->head = p_node; p_list->tail = p_node; @@ -182,6 +195,15 @@ int insertInTail(List *p_list, Node *p_node) { p_node->last = p_list->tail; p_list->tail = p_node; } + + if(p_list->p_lq != NULL){ + p_node->f_number = p_list->p_lq->rlst_len; + if(p_list->p_lq->rlst_len >= p_list->p_lq->rlst_len + FN_NODE_SPARE) + p_list->p_lq->fn_node = realloc(p_list->p_lq->fn_node, sizeof(Node *) * (p_list->p_lq->rlst_len + FN_NODE_SPARE)); + p_list->p_lq->fn_node[p_list->p_lq->rlst_len] = p_node; + p_list->p_lq->rlst_len++; + } + p_list->length += 1; return 0; } @@ -213,6 +235,7 @@ int releaseNode(Node *p_node) { } p_node->value = NULL; } + p_node->f_number = 0; p_node->last = NULL; p_node->next = NULL; p_node->type = VOID; @@ -246,6 +269,7 @@ int releaseList(List *p_list) { p_list->tail = NULL; p_list->length = 0; if (p_list->s_id != NULL) freeS_id(p_list->s_id); + if(p_list->p_lq != NULL) disableListQuick(p_list); free(p_list); return 0; } @@ -254,6 +278,7 @@ 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); return 0; @@ -263,7 +288,7 @@ unsigned long long len(List *p_list) { return p_list->length; } -int removeById(List *p_list, const SID *s_id) { +int removeById(List *p_list, SID *s_id) { Node *tmp = p_list->head; if (isListEmpty(p_list)) return -1; @@ -294,39 +319,56 @@ int removeById(List *p_list, const SID *s_id) { } int removeByNode(List *p_list, Node *p_node) { - Node *tmp = p_list->head; if (isListEmpty(p_list)) return -1; - do { - if (tmp == p_node) { - tmp->last->next = tmp->next; - tmp->next->last = tmp->last; - p_list->length -= 1; - return 1;//found + if(p_node == p_list->head){ + popFromHead(p_list); + return 0; + } + else if(p_node == p_list->tail){ + popFromTail(p_list); + return 0; + } + if(p_list->p_lq == NULL){ + p_node->last->next = p_node->next; + p_node->next->last = p_node->last; + } + else{ + if(p_node != p_list->head){ + if(p_node->f_number == 0){ + Node *fn_node = findFnNode(p_list, p_node); + indexChange(p_list, fn_node->f_number, -1); + p_node->last->next = p_node->next; + p_node->next->last = p_node->last; + } + else{ + digHole(p_list, p_node); + } } - else { - tmp = tmp->next; - } - } while (tmp != NULL); - + p_list->length -= 1; + } return 0;//not find } int popFromHead(List *p_list) { if (isListEmpty(p_list)) return -1; - else { + if(p_list->p_lq != NULL){ + if(p_list->p_lq->fn_node[0] == p_list->head){ + digHole(p_list, p_list->head); + } + } + else{ //Node *tmp = p_list->head; p_list->head->next->last = NULL; p_list->head = p_list->head->next; //releaseNode(tmp); not necessary + if (isListEmpty(p_list)) { + p_list->head = NULL; + p_list->tail = NULL; + } p_list->length -= 1; } - - if (isListEmpty(p_list)) { - p_list->head = NULL; - p_list->tail = NULL; - } return 0; } @@ -334,21 +376,25 @@ int popFromTail(List *p_list) { if (isListEmpty(p_list)) return -1; else { + if(p_list->p_lq != NULL){ + if(p_list->p_lq->fn_node[p_list->p_lq->rlst_len] == p_list->tail) + p_list->p_lq->fn_node = realloc(p_list->p_lq->fn_node, sizeof(p_list->p_lq->rlst_len - 1)); + } //Node *tmp = p_list->tail; p_list->tail->last->next = NULL; p_list->tail = p_list->tail->last; //releaseNode(tmp); not necessary - p_list->length -= 1; } if (isListEmpty(p_list)) { p_list->head = NULL; p_list->tail = NULL; } + p_list->length -= 1; return 0; } -Node *findByIdForNode(List *p_list, const SID *s_id) { +Node *findByIdForNode(List *p_list, SID * s_id) { Node *ph_node = p_list->head; Node *pt_node = p_list->tail; int direction = 0; @@ -460,11 +506,12 @@ Node *copyNode(Node *p_node) { Node *t_node = NULL; if (p_node->s_id == NULL) t_node = initNode(0); else t_node = initNode(p_node->s_id->deep); - t_node->s_id = p_node->s_id; + t_node->s_id = copyS_id(p_node->s_id); t_node->last = p_node->last; t_node->next = p_node->next; t_node->type = p_node->type; t_node->value = p_node->value; + t_node->f_number = p_node->f_number; return t_node; } @@ -477,11 +524,16 @@ List *copyList(List *p_list) { t_list->head = p_list->head; t_list->tail = p_list->tail; t_list->s_id = p_list->s_id; + t_list->s_head = p_list->s_head; + t_list->length = p_list->length; + t_list->s_tail = p_list->s_tail; + if(p_list->head != NULL && p_list->tail != NULL){ p_node = p_list->head; - while (p_node != NULL) { - t_node = copyNode(p_node); - insertInTail(t_list, t_node); - p_node = p_node->next; + while (p_node != NULL) { + t_node = copyNode(p_node); + insertInTail(t_list, t_node); + p_node = p_node->next; + } } return t_list; } @@ -538,6 +590,7 @@ int releaseListForCustom(List *p_list, int (*func)(void *)){ p_list->tail = NULL; p_list->length = 0; if (p_list->s_id != NULL) freeS_id(p_list->s_id); + if(p_list->p_lq != NULL) disableListQuick(p_list); free(p_list); return 0; } @@ -613,23 +666,101 @@ int replaceNode(List *p_list, Node *pt_node, Node *p_node){ else p_list->head = p_node; if(p_list->tail != pt_node) pt_node->next->last = p_node; else p_list->tail = p_node; + + if(p_list->p_lq != NULL){ + if(pt_node->f_number == 0 && p_list->p_lq->fn_node[0] != pt_node){ + p_node->f_number = pt_node->f_number; + } + else{ + p_list->p_lq->fn_node[pt_node->f_number] = p_node; + p_node->f_number = pt_node->f_number; + } + } return 0; } -int sortListById(List *p_list){ +int exchangeNode(List *p_list, Node *f_node, Node *s_node){ + Node *fl_node = f_node->last, *fn_node = f_node->next; + if(p_list->head != f_node) f_node->last->next = s_node; + else p_list->head = s_node; + if(p_list->tail != f_node) f_node->next->last = s_node; + else p_list->tail = s_node; + if(p_list->head != s_node) s_node->last->next = f_node; + else p_list->head = f_node; + if(p_list->tail != s_node) s_node->next->last = f_node; + else p_list->tail = f_node; + f_node->next = s_node->next; + f_node->last = s_node->last; + s_node->next = fn_node; + s_node->last = fl_node; + if(p_list->p_lq != NULL){ + p_list->p_lq->fn_node[f_node->f_number] = s_node; + p_list->p_lq->fn_node[s_node->f_number] = f_node; + unsigned long long temp = f_node->f_number; + f_node->f_number = s_node->f_number; + s_node->f_number = temp; + } + return 0; +} + +int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node)){ + unsigned long long target_index = begin; + register Node *t_node = findByIndexForNode(p_list, target_index); + register Node *i_node = NULL, *j_node = NULL; + + register unsigned long long i = end,j = begin; + for(; i >= begin; i--){ + if(i <= j) break; + i_node = findByIndexForNode(p_list, i); + if(func(t_node, i_node) < 0){ + exchangeNode(p_list, t_node, i_node); + for(; j <= end; j++){ + if(j >= i) break; + j_node = findByIndexForNode(p_list, j); + if(func(t_node, j_node) > 0){ + exchangeNode(p_list, t_node, j_node); + break; + } + } + } + } + if(end - begin > 3){ + if(t_node->f_number - begin > 2) + sortList(p_list, begin, t_node->f_number, func); + if(end - t_node->f_number > 2) + sortList(p_list, t_node->f_number, end, func); + } + return 0; +} + +int sortListByCustom(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; } int enableListQuick(List *p_list){ - if(p_list->length > 1500){ + if(p_list->length > ENABLE_LIST_QUICK){ p_list->p_lq = malloc(sizeof(struct list_quick)); + register struct list_quick *p_lq = p_list->p_lq; + p_lq->rlst_len = p_list->length; + p_lq->fn_node = malloc(sizeof(Node *) * (p_list->length + FN_NODE_SPARE)); + p_lq->if_sort = 0; + refreshFnNode(p_list); + //sortListById(p_list, 0, p_list->length); + return 0; + } + return -1; +} + +int refreshFnNode(List *p_list){ + if(p_list->p_lq != NULL){ + initIdxcList(p_list); + if(p_list->p_lq->fn_node != NULL) free(p_list->p_lq->fn_node); + p_list->p_lq->fn_node = malloc(sizeof(Node *) * p_list->length); register Node *p_node = p_list->head; unsigned long long i = 0; - p_list->p_lq->rlst_len = p_list->length; - p_list->p_lq->fn_node = malloc(sizeof(Node *) * p_list->length); - p_list->p_lq->p_lindex = 0; - p_list->p_lq->head_index = 0; - p_list->p_lq->tail_index = p_list->length - 1; while (p_node != NULL) { p_node->f_number = i++; p_list->p_lq->fn_node[i] = p_node; @@ -639,3 +770,169 @@ int enableListQuick(List *p_list){ } return -1; } + +int indexChange(List *p_list, unsigned long long c_index, int move){ + if(p_list->p_lq != NULL){ + struct index_change *t_idxc; + struct list_quick *p_lq = p_list->p_lq; + if(p_lq->idxc_count >= INDEX_CHANGE_MAX){ + refreshFnNode(p_list); + for(int i = 0; i < INDEX_CHANGE_MAX; i++){ + free(p_lq->idxc_lst[i]); + p_lq->idxc_lst[i] = NULL; + } + return 0; + } + for(int i = 0; p_lq->idxc_lst[i] != NULL; i++){ + if(p_lq->idxc_lst[i]->c_index == c_index){ + p_lq->idxc_lst[i]->f_count += move; + return 0; + } + } + if(p_lq->idxc_count == 0) { + p_lq->idxc_lst[0] = malloc(sizeof(struct index_change)); + t_idxc = p_lq->idxc_lst[0]; + } + else { + p_lq->idxc_lst[p_lq->idxc_count] = malloc(sizeof(struct index_change)); + t_idxc = p_lq->idxc_lst[p_lq->idxc_count]; + } + t_idxc->c_index = c_index; + t_idxc->f_count = move; + p_lq->idxc_count++; + } + return 0; +} + +int indexTransfromer(List *p_list, unsigned long long m_index){ + int total_move = 0; + struct list_quick *p_lq = p_list->p_lq; + struct index_change **p_idxclst = p_lq->idxc_lst; + if(p_lq->idxc_lst[0] != NULL){ + for (int i = 0; p_idxclst[i] != NULL && i < INDEX_CHANGE_MAX; i++) { + if(p_idxclst[i]->c_index <= m_index) total_move += p_idxclst[i]->f_count; + if(total_move >= 65535){ + refreshFnNode(p_list); + return 0; + } + } + } + return total_move; +} + +Node *getNodeByFnNode(List *p_list, unsigned long long index){ + if(p_list->p_lq != NULL){ + struct list_quick *p_lq = p_list->p_lq; + Node *p_node = p_lq->fn_node[index]; + if(p_lq->idxc_count > 0){ + int total_move = indexTransfromer(p_list, index); + if(total_move >=0){ + for(int i = 0; i < ABS(total_move); i++) p_node = p_node->last; + } + else{ + for(int i = 0; i < ABS(total_move); i++) p_node = p_node->next; + } + return p_node; + } + else{ + return p_lq->fn_node[index]; + } + + } + return NULL; +} + +int insertAfterNode(List *p_list, Node *t_node, Node *p_node){ + if(t_node == p_list->tail){ + insertInTail(p_list, p_node); + return 0; + } + if(p_list->p_lq != NULL){ + if(t_node->next->type == HOLE){ + Node *temp_node = t_node->next; + replaceNode(p_list, t_node->next, p_node); + p_node->f_number = temp_node->f_number; + releaseNode(temp_node); + p_list->p_lq->fn_node[p_node->f_number] = p_node; + indexChange(p_list, p_node->f_number, 1); + } + } + p_node->next = t_node->next; + p_node->last = t_node; + if(p_list->tail != t_node) + t_node->next->last = p_node; + else + p_list->tail = p_node; + + t_node->next = p_node; + + if(p_list->p_lq != NULL){ + Node *fn_node = findFnNode(p_list, p_node); + while(fn_node->f_number != 0) fn_node = fn_node->next; + indexChange(p_list, fn_node->f_number, 1); + } + p_list->length += 1; + return 0; +} + +int insertBeforeNode(List *p_list, Node*t_node, Node *p_node){ + if(t_node == p_list->head){ + insertInHead(p_list, p_node); + return 0; + } + if(p_list->p_lq != NULL){ + if(t_node->last->type == HOLE){ + Node *temp_node = t_node->last; + replaceNode(p_list, t_node->last, p_node); + p_node->f_number = temp_node->f_number; + releaseNode(temp_node); + p_list->p_lq->fn_node[p_node->f_number] = p_node; + indexChange(p_list, p_node->f_number, 1); + return 0; + } + } + p_node->last = t_node->last; + p_node->next = t_node; + if(p_list->head != t_node) + t_node->last->next = p_node; + else + p_list->head = p_node; + t_node->last = p_node; + if(p_list->p_lq != NULL){ + Node *fn_node = findFnNode(p_list, p_node); + indexChange(p_list, fn_node->f_number, 1); + } + p_list->length += 1; + return 0; +} + +Node *findFnNode(List *p_list, Node *p_node){ + Node *fn_node = p_node; + while(fn_node->f_number != 0) fn_node = fn_node->next; + return fn_node; +} + +void initIdxcList(List *p_list){ + struct list_quick *p_lq = p_list->p_lq; + for(int i = 0; i < INDEX_CHANGE_MAX; i++){ + if(p_lq->idxc_lst[i] != NULL) free(p_lq->idxc_lst[i]); + p_lq->idxc_lst[i] = NULL; + } + p_lq->idxc_count = 0; +} + +void digHole(List *p_list, Node *p_node){ + Node *c_node = copyNode(p_node); + freeS_id(c_node->s_id); + replaceNode(p_list, p_node, c_node); + c_node->value = NULL; + c_node->type = HOLE; + indexChange(p_list, p_node->f_number, -1); +} + +int disableListQuick(List *p_list){ + free(p_list->p_lq->fn_node); + initIdxcList(p_list); + free(p_list->p_lq); + return 0; +} diff --git a/list/list.h b/list/list.h index 3dddefa..678e617 100644 --- a/list/list.h +++ b/list/list.h @@ -3,6 +3,26 @@ #include "../type/type.h" #include "../id/id.h" +#define lni(x) nodeWithInt(x,0) +#define lnd(x) nodeWithDouble(x,0) +#define lns(x) nodeWithString(x,0) +#define lnp(x) nodeWithPointer(x,0) + +#define lsni(x) nodeWithInt(x,1) +#define lsnd(x) nodeWithDouble(x,1) +#define lsns(x) nodeWithString(x,1) +#define lsnp(x) nodeWithPointer(x,1) + +#define lisrti(list, x) insertInTail(list, lni(x)); +#define lisrtd(list, x) insertInTail(list, lnd(x)); +#define lisrtp(list, x) insertInTail(list, lnp(x)); +#define lisrts(list, x) insertInTail(list, lns(x)); + +#define lidxp(list, x) getByPointerForNode(findByIndexForNode(list, x)) +#define lidxi(list, x) getByIntForNode(findByIndexForNode(list, x)) +#define lidxd(list, x) getByDoubleForNode(findByIndexForNode(list, x)) +#define lidxs(list, x) getByStringForNode(findByIndexForNode(list, x)) + int safeModeForNode(int ifon); int releaseSingleListForsafeModeForNode(List *p_list); int releaseSingleNodeForsafeModeForNode(List *p_list); @@ -16,21 +36,24 @@ int initMallocValueForNode(Node *,unsigned int,const void *); int insertInHead(List *p_list, Node *p_node); int insertInTail(List *p_list, Node *p_node); +int insertAfterNode(List *p_list, Node *t_node, Node *p_node); +int insertBeforeNode(List *p_list, Node*t_node, Node *p_node); int s_insertInHead(List *p_list, s_Node *s_p_node); int s_insertInTail(List *p_list, s_Node *s_p_node); int replaceNode(List *p_list, Node *pt_node, Node *p_node); +int exchangeNode(List *p_list, Node *f_node, Node *s_node); Node *copyNode(Node *); -int removeById(List *p_list, const SID *s_id); +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); unsigned long long len(List *p_list); -Node *findByIdForNode(List *p_list, const SID *s_id); +Node *findByIdForNode(List *p_list, SID * s_id); Node *findByValue(List *p_list, unsigned int type, const void *value); List *mply_findByValue(List *p_list, unsigned int type, const void *value); @@ -64,7 +87,32 @@ int showError(Error *); int showWarning(Notice *); int enableListQuick(List *p_list); -int sortListById(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 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); +Node *findFnNode(List *p_list, Node *p_node); +void initIdxcList(List *p_list); +void digHole(List *p_list, Node *p_node); +int disableListQuick(List *p_list); + +Node *findByIndexForNode(List *, unsigned long long); +Node *findByIntForNode(List *, int); +Node *findByDoubleForNode(List *, double); +Node *findByStringForNode(List *, char *); +Node *findByPointerForNode(List *, void *); + +Node *getListTail(List *); +Node *updateNodeByIndex(List *, void *, unsigned long long); + +int getByIntForNode(Node *); +unsigned int getByUIntForNode(Node *); +double getByDoubleForNode(Node *); +char *getByStringForNode(Node *); +void *getByPointerForNode(Node *); +unsigned long long getIndexForNode(List *p_list,Node *p_node); static int if_safeModeForNode; static List *node_list; diff --git a/list/list_expand.c b/list/list_expand.c index 3c42536..169a1de 100644 --- a/list/list_expand.c +++ b/list/list_expand.c @@ -4,7 +4,7 @@ Node *nodeWithInt(int m_int, _Bool if_sid) { Node *p_node; int *p_int = (int *)malloc(sizeof(int)); if(p_int == NULL){ - showError(pushError(INT, STANDARD, initInfo("nodeWithInt()", "Error in getting the memory of int."))); + showError(pushError(INT, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of int."))); return NULL; } *p_int = m_int; @@ -17,7 +17,7 @@ Node *nodeWithUInt(unsigned int m_uint, _Bool if_sid){ Node *p_node; unsigned int *pu_int = (unsigned int *)malloc(sizeof(unsigned int)); if(pu_int == NULL){ - showError(pushError(INT, STANDARD, initInfo("nodeWithUInt()", "Error in getting the memory of int."))); + showError(pushError(INT, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of int."))); return NULL; } *pu_int = m_uint; @@ -25,12 +25,25 @@ Node *nodeWithUInt(unsigned int m_uint, _Bool if_sid){ initMallocValueForNode(p_node, INT, (void *)pu_int); return p_node; } + +Node *nodeWithULLInt(unsigned long long m_ullint, _Bool if_sid) { + Node *p_node; + unsigned long long *p_ullint = (unsigned long long *)malloc(sizeof(unsigned long long)); + if(p_ullint == NULL){ + showError(pushError(INT, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of int."))); + return NULL; + } + *p_ullint = m_ullint; + p_node = initNode(if_sid); + initMallocValueForNode(p_node, ULLINT, (void *)p_ullint); + return p_node; +} Node *nodeWithDouble(double m_double, _Bool if_sid) { Node *p_node; double *p_double = (double *)malloc(sizeof(double)); if(p_double == NULL){ - showError(pushError(DOUBLE, STANDARD, initInfo("nodeWithDouble()", "Error in getting the memory of double."))); + showError(pushError(DOUBLE, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of double."))); return NULL; } *p_double = m_double; @@ -68,16 +81,14 @@ Node *nodeWithComplex(void) { Node *findByIndexForNode(List *p_list, unsigned long long m_index) { if(p_list->p_lq != NULL){ register struct list_quick *p_lq = p_list->p_lq; - if(m_index > p_lq->head_index && p_lq->last_index) return p_lq->fn_node[m_index]; - } - else{ - Node *p_node = p_list->head; - unsigned long long i; - for (i = 0; i < m_index; i++) { - p_node = p_node->next; - } - return p_node; + if(p_lq->fn_node != NULL) return getNodeByFnNode(p_list, m_index); } + Node *p_node = p_list->head; + unsigned long long i; + for (i = 0; i < m_index; i++) { + p_node = p_node->next; + } + return p_node; } s_Node *s_findByIndexForNode(List *p_list, unsigned long long m_index) { @@ -91,7 +102,9 @@ 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; + List *m_rtnlst = NULL; + unsigned long long count = 0; + insertInTail(expand_resources, nodeWithULLInt(count, 0)); while (p_node != NULL) { if (p_node->value != NULL) { List *m_rtnlst = (*p_func)(p_node->type, p_node->value, expand_resources); @@ -510,6 +523,7 @@ inline s_Node *s_nodeWithUInt(unsigned int t_uint){ s_p_node->value = pt_uint; return s_p_node; } + inline s_Node *s_nodeWithDouble(double t_double){ s_Node *s_p_node = s_initNode(); unsigned int *pt_double = malloc(sizeof(double)); @@ -517,6 +531,7 @@ inline s_Node *s_nodeWithDouble(double t_double){ s_p_node->value = pt_double; return s_p_node; } + inline s_Node *s_nodeWithString(const char *t_string){ s_Node *s_p_node = s_initNode(); char *pt_string = malloc(strlen(t_string) + 1); @@ -524,8 +539,56 @@ inline s_Node *s_nodeWithString(const char *t_string){ s_p_node->value = pt_string; return s_p_node; } + inline s_Node *s_nodeWithPointer(const void *t_pointer){ s_Node *s_p_node = s_initNode(); s_p_node->value = (void *) t_pointer; return s_p_node; } + + + +List *newReturn(int if_status ,int status, char *argc, ...){ + List *p_list = initList(0); + if(if_status){ + lisrti(p_list, status); + } + if(status != 0){ + va_list args; + va_start(args, argc); + char p_ch = argc[0]; + char t_ch[256]; + int count = 0, t_count = 0; + while(p_ch != '\0'){ + if(p_ch == '%'){ + switch (argc[count + 1]) { + case 'd': + lisrti(p_list, va_arg(args, int)); + break; + case 's': + t_count = 0; + while ((t_ch[t_count] = va_arg(args, int)) != '\0') t_count++; + t_ch[t_count] = '\0'; + lisrts(p_list, t_ch); + break; + case 'f': + lisrtd(p_list, va_arg(args, double)); + break; + case 'p': + lisrtp(p_list, va_arg(args, void *)); + break; + default: + break; + } + count++; + } + p_ch = argc[++count]; + } + va_end(args); + } + return p_list; +} + +List *newCReturn(void){ + return newReturn(1, 0, NULL); +} diff --git a/list/list_expand.h b/list/list_expand.h index ea35fcc..b484f58 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -1,13 +1,27 @@ #ifndef LIST_EXPAND_H #define LIST_EXPAND_H -#include "list.h" +#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 -Node *nodeWithInt(int); -Node *nodeWithUInt(unsigned int); -Node *nodeWithDouble(double); -Node *nodeWithString(const char *); -Node *nodeWithPointer(const void *); +Node *nodeWithInt(int, _Bool if_sid); +Node *nodeWithUInt(unsigned int, _Bool if_sid); +Node *nodeWithULLInt(unsigned long long, _Bool if_sid); +Node *nodeWithDouble(double, _Bool if_sid); +Node *nodeWithString(const char *, _Bool if_sid); +Node *nodeWithPointer(const void *, _Bool if_sid); s_Node *s_nodeWithInt(int); s_Node *s_nodeWithUInt(unsigned int); @@ -27,12 +41,6 @@ int updateValueWithDoubleForNode(Node *,double); int updateValueWithStringForNode(Node *,char *); int updateValueWithPointerForNode(Node *,void *); -Node *findByIndexForNode(List *, unsigned long long); -Node *findByIntForNode(List *, int); -Node *findByDoubleForNode(List *, double); -Node *findByStringForNode(List *, char *); -Node *findByPointerForNode(List *, void *); - List *mply_findByIntForNode(List*, int); List *mply_findByDoubleForNode(List*, double); List *mply_findByStringForNode(List*, char *); @@ -43,13 +51,9 @@ void printNodeInfo(Node *p_node,int priority); void printList(List *); void printNode(Node *p_node); -int getByIntForNode(Node *); -unsigned int getByUIntForNode(Node *); -double getByDoubleForNode(Node *); -char *getByStringForNode(Node *); -void *getByPointerForNode(Node *); -unsigned long long getIndexForNode(List *p_list,Node *p_node); 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 calListMemory(List *); #endif diff --git a/test.c b/test.c index ee234f9..a77ea4e 100644 --- a/test.c +++ b/test.c @@ -82,19 +82,9 @@ int stack(void) { int main(int argc, char **argv) { - init_rand(); - List *t_list = initList(); - for (int i = 0; i < 100; i++) { - insertInHead(t_list, nodeWithInt(i)); - } - STD_DATA *p_std = listToSTD(t_list); - D_FILE *p_dfilew = initDataFileForWrite("data.df"); - dataFileAddStandardData(p_dfilew, p_std); - dataFileWriteIn(p_dfilew); - releaseDFile(p_dfilew); - D_FILE *p_dfiler = initDataFileForRead("data.df"); - dataFileReadOut(p_dfiler); - releaseDFile(p_dfiler); - releaseList(t_list); + SID *p_sid = getS_id(VOID, 2); + s_idToASCIIString(p_sid); + printf("%s",p_sid->decrypt_str); + freeS_id(p_sid); return 0; } diff --git a/type/type.h b/type/type.h index f07ca18..d551fc1 100644 --- a/type/type.h +++ b/type/type.h @@ -7,6 +7,7 @@ #include #include #include +#include /* #include @@ -31,6 +32,8 @@ #define STANDARD_DATA 13 #define DATA_FILE 14 #define MESSAGE 15 +#define HOLE 16 +#define ULLINT 17 #define DEEPC 1 #define DEEPB 2 @@ -43,14 +46,20 @@ #define DEEP_LEN 25 #define DEEPER_LEN 65 #define DEEPEST_LEN 225 +#define SID_LEN 32 #define FILE_TSET_LEN 18 #define HEAD_TEST_LEN 9 - +#define ENABLE_LIST_QUICK 1500 +#define FN_NODE_SPARE 12 +#define INDEX_CHANGE_MAX 500 +#define INDEX_DISTANCE_MAX 120 #define HIGH 0x3 #define STANDARD 0x2 #define LOW 0x1 +#define ABS(x) (x>0)?(x):(-x) + typedef struct md5_ctx{ unsigned int count[2]; unsigned int state[4]; @@ -105,12 +114,16 @@ typedef struct List{ SID *s_id; } List; +struct index_change{ + unsigned long long c_index; + int f_count; +}; + struct list_quick{ Node **fn_node; - unsigned long long last_index; - Node *p_lindex; - unsigned long long head_index; - unsigned long long tail_index; + _Bool if_sort; + unsigned int idxc_count; + struct index_change *idxc_lst[INDEX_CHANGE_MAX]; unsigned long long rlst_len; FILE *fp; List *stdid_lst; From c5890b4c1f6203a0c06b6148b488e2638c08cde0 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Tue, 21 Aug 2018 16:26:31 +0800 Subject: [PATCH 07/12] Add and fixed. --- .../project.pbxproj | 6 +- .../xcdebugger/Expressions.xcexplist | 36 +- .../xcdebugger/Breakpoints_v2.xcbkptlist | 1372 ++++++++++++----- communicate/communicate.c | 351 +++-- communicate/communicate.h | 26 +- error/error.c | 4 +- id/id.c | 80 +- id/id.h | 6 +- list/list.c | 28 +- list/list.h | 13 +- list/list_expand.c | 88 +- list/list_expand.h | 34 +- stack/stack.c | 3 - test.c | 70 +- test.h | 2 +- type/type.h | 10 +- 16 files changed, 1490 insertions(+), 639 deletions(-) diff --git a/ZE-Standard-Libraries.xcodeproj/project.pbxproj b/ZE-Standard-Libraries.xcodeproj/project.pbxproj index c3239cb..e48fef6 100644 --- a/ZE-Standard-Libraries.xcodeproj/project.pbxproj +++ b/ZE-Standard-Libraries.xcodeproj/project.pbxproj @@ -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 = ""; }; 9286EB7B211400D000752977 /* error.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = error.h; path = error/error.h; sourceTree = ""; }; - 9286EB7D2114022A00752977 /* communicate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = communicate.c; path = communicate/communicate.c; sourceTree = ""; }; + 9286EB7D2114022A00752977 /* communicate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; name = communicate.c; path = communicate/communicate.c; sourceTree = ""; }; 9286EB7F2114022F00752977 /* communicate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = communicate.h; path = communicate/communicate.h; sourceTree = ""; }; /* 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 */, ); diff --git a/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist b/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist index 1d0c1c5..9334bd2 100644 --- a/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist +++ b/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -24,6 +24,12 @@ + + + + @@ -35,6 +41,9 @@ + + @@ -96,6 +105,17 @@ + + + + + + + + @@ -110,12 +130,18 @@ + + + + @@ -131,16 +157,22 @@ contextName = "main:test.c"> + value = "strlen(string)"> + value = "(int *)p_node->value"> + + + + diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 7e920d0..555e5a0 100644 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -154,13 +154,13 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "555310052.789754" + timestampString = "556532739.104131" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "64" - endingLineNumber = "64" - landmarkName = "tree" - landmarkType = "9"> + startingLineNumber = "45" + endingLineNumber = "45" + landmarkName = "unknown" + landmarkType = "0"> + + + + @@ -218,11 +234,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.589806" + timestampString = "556532739.104495" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "102" - endingLineNumber = "102" + startingLineNumber = "137" + endingLineNumber = "137" landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -234,27 +250,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.589859" + timestampString = "556532739.10456" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "122" - endingLineNumber = "122" - landmarkName = "s_idToASCIIRawString" - landmarkType = "9"> - - - - @@ -267,73 +267,7 @@ condition = "buff_count == 26" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.589964" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "128" - endingLineNumber = "128" - landmarkName = "s_idToASCIIRawString" - landmarkType = "9"> - - - - - - - - - - - - - - - - + + + + + + + + @@ -365,12 +333,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.5902719" + timestampString = "556532739.104877" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "197" - endingLineNumber = "197" - landmarkName = "asciiStringToS_id" + startingLineNumber = "158" + endingLineNumber = "158" + landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -381,12 +349,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.590323" + timestampString = "556532739.1049449" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "240" - endingLineNumber = "240" - landmarkName = "freeS_id" + startingLineNumber = "162" + endingLineNumber = "162" + landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -397,12 +365,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.590374" + timestampString = "556532739.1050349" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "184" - endingLineNumber = "184" - landmarkName = "asciiStringToS_id" + startingLineNumber = "212" + endingLineNumber = "212" + landmarkName = "asciiRawStringToS_id" landmarkType = "9"> @@ -413,11 +381,43 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.5904239" + timestampString = "556532739.105131" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "23" - endingLineNumber = "23" + startingLineNumber = "255" + endingLineNumber = "255" + landmarkName = "unknown" + landmarkType = "0"> + + + + + + + + @@ -429,12 +429,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.590529" + timestampString = "556532739.1054161" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "196" - endingLineNumber = "196" - landmarkName = "asciiStringToS_id" + startingLineNumber = "211" + endingLineNumber = "211" + landmarkName = "asciiRawStringToS_id" landmarkType = "9"> @@ -445,12 +445,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.5906" + timestampString = "556532739.10551" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "204" - endingLineNumber = "204" - landmarkName = "asciiStringToS_id" + startingLineNumber = "219" + endingLineNumber = "219" + landmarkName = "asciiRawStringToS_id" landmarkType = "9"> @@ -461,11 +461,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.590657" + timestampString = "556532739.105608" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "126" - endingLineNumber = "126" + startingLineNumber = "141" + endingLineNumber = "141" landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -477,12 +477,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.590712" + timestampString = "556532739.105705" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "206" - endingLineNumber = "206" - landmarkName = "asciiStringToS_id" + startingLineNumber = "221" + endingLineNumber = "221" + landmarkName = "asciiRawStringToS_id" landmarkType = "9"> @@ -493,12 +493,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.590765" + timestampString = "556532739.105774" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "239" - endingLineNumber = "239" - landmarkName = "freeS_id" + startingLineNumber = "254" + endingLineNumber = "254" + landmarkName = "asciiRawStringToS_id" landmarkType = "9"> @@ -509,12 +509,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.590819" + timestampString = "556532739.1058379" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "217" - endingLineNumber = "217" - landmarkName = "asciiStringToS_id" + startingLineNumber = "232" + endingLineNumber = "232" + landmarkName = "asciiRawStringToS_id" landmarkType = "9"> @@ -525,11 +525,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list_expand.c" - timestampString = "555309906.510792" + timestampString = "556532739.105913" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "83" - endingLineNumber = "83" + startingLineNumber = "84" + endingLineNumber = "84" landmarkName = "findByIndexForNode" landmarkType = "9"> @@ -541,28 +541,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555310052.791223" + timestampString = "556532739.1063139" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "102" - endingLineNumber = "102" - landmarkName = "_doStandardDataInfoWrite" - landmarkType = "9"> - - - - @@ -573,11 +557,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "555310052.7917579" + timestampString = "556532739.106467" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "100" - endingLineNumber = "100"> + startingLineNumber = "83" + endingLineNumber = "83"> @@ -603,12 +587,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555310052.792091" + timestampString = "556532739.106678" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "118" - endingLineNumber = "118" - landmarkName = "_doStandardDataInfoWrite" + startingLineNumber = "222" + endingLineNumber = "222" + landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -619,12 +603,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555310052.792145" + timestampString = "556532739.106815" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "203" - endingLineNumber = "203" - landmarkName = "dataFileReadOut" + startingLineNumber = "214" + endingLineNumber = "214" + landmarkName = "releaseDFile" landmarkType = "9"> @@ -635,12 +619,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555310052.792217" + timestampString = "556532739.106931" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "241" - endingLineNumber = "241" - landmarkName = "dataFileReadOut" + startingLineNumber = "168" + endingLineNumber = "168" + landmarkName = "listToSTD" landmarkType = "9"> @@ -651,39 +635,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555310052.792271" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "231" - endingLineNumber = "231" - landmarkName = "dataFileReadOut" - landmarkType = "9"> - - - - - - - - - - - - - - - - @@ -747,11 +667,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "555307651.597877" + timestampString = "556532739.107306" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "252" - endingLineNumber = "252" + startingLineNumber = "270" + endingLineNumber = "270" landmarkName = "freeSidRaw" landmarkType = "9"> @@ -763,23 +683,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555310052.792592" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "224" - endingLineNumber = "224" - landmarkName = "dataFileReadOut" - landmarkType = "9"> - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - @@ -891,11 +779,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "555310052.793105" + timestampString = "556532739.10843" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "99" - endingLineNumber = "99"> + startingLineNumber = "83" + endingLineNumber = "83"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -921,12 +935,28 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555310052.793792" + timestampString = "556532739.1098109" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "270" - endingLineNumber = "270" - landmarkName = "releaseSTDBlocks" + startingLineNumber = "308" + endingLineNumber = "308" + landmarkName = "unknown" + landmarkType = "0"> + + + + @@ -937,12 +967,28 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "555310052.7938451" + timestampString = "556532739.110184" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "267" - endingLineNumber = "267" - landmarkName = "releaseSTDBlocks" + startingLineNumber = "300" + endingLineNumber = "300" + landmarkName = "unknown" + landmarkType = "0"> + + + + @@ -952,13 +998,621 @@ shouldBeEnabled = "No" ignoreCount = "0" continueAfterRunningActions = "No" - filePath = "list/list.c" - timestampString = "555310052.793896" + filePath = "list/list_expand.c" + timestampString = "556532739.110571" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "508" - endingLineNumber = "508" - landmarkName = "copyNode" + startingLineNumber = "113" + endingLineNumber = "113" + landmarkName = "listThrough" + landmarkType = "9"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/communicate/communicate.c b/communicate/communicate.c index d451b32..2e66286 100644 --- a/communicate/communicate.c +++ b/communicate/communicate.c @@ -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__; +} diff --git a/communicate/communicate.h b/communicate/communicate.h index cf9e7d7..991bf3b 100644 --- a/communicate/communicate.h +++ b/communicate/communicate.h @@ -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 *); diff --git a/error/error.c b/error/error.c index 0b34a2f..9756a3c 100644 --- a/error/error.c +++ b/error/error.c @@ -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; } diff --git a/id/id.c b/id/id.c index f65ceb6..a2182b0 100644 --- a/id/id.c +++ b/id/id.c @@ -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; } diff --git a/id/id.h b/id/id.h index 59b9d10..fdda689 100644 --- a/id/id.h +++ b/id/id.h @@ -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); diff --git a/list/list.c b/list/list.c index 46accec..39d86df 100644 --- a/list/list.c +++ b/list/list.c @@ -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; diff --git a/list/list.h b/list/list.h index 678e617..2c5fb79 100644 --- a/list/list.h +++ b/list/list.h @@ -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); diff --git a/list/list_expand.c b/list/list_expand.c index 169a1de..72426b0 100644 --- a/list/list_expand.c +++ b/list/list_expand.c @@ -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__; +} diff --git a/list/list_expand.h b/list/list_expand.h index b484f58..0cc5894 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -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 diff --git a/stack/stack.c b/stack/stack.c index 7981445..320ff40 100644 --- a/stack/stack.c +++ b/stack/stack.c @@ -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; diff --git a/test.c b/test.c index a77ea4e..77ed001 100644 --- a/test.c +++ b/test.c @@ -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; } diff --git a/test.h b/test.h index 6dcdf20..b5f7cb8 100644 --- a/test.h +++ b/test.h @@ -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); diff --git a/type/type.h b/type/type.h index d551fc1..2bea1ab 100644 --- a/type/type.h +++ b/type/type.h @@ -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; From b153b11a2900cb88731c5dc3ae45191dd96a3e31 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Wed, 22 Aug 2018 16:36:26 +0800 Subject: [PATCH 08/12] Fixed. --- .../xcdebugger/Expressions.xcexplist | 203 +-- .../xcdebugger/Breakpoints_v2.xcbkptlist | 1106 ++++++++--------- communicate/communicate.c | 3 + list/list.c | 115 +- list/list.h | 7 + test.c | 53 +- test.h | 7 +- type/type.h | 8 +- 8 files changed, 797 insertions(+), 705 deletions(-) diff --git a/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist b/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist index 9334bd2..52a1b4f 100644 --- a/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist +++ b/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -3,32 +3,52 @@ version = "1.0"> + contextName = "_doStandardDataToList:communicate.c"> + + + value = "sizeof(char)"> + + + contextName = "standardDataAddBlock:communicate.c"> + value = "(int *)data"> + + + contextName = "setS_idWithString:id.c"> + contextName = "initStandardDBlocks:communicate.c"> + contextName = "readStandardData:communicate.c"> + contextName = "dataForStandardDBlock:communicate.c"> + + + + + + + + @@ -39,22 +59,36 @@ + contextName = "freeS_id:id.c"> - - - - + contextName = "dataFileReadOut:communicate.c"> + value = "strlen(string_sid)"> + + + + + + + + + + + + + + @@ -67,7 +101,52 @@ + contextName = "releaseMalloc:list.h"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -86,95 +165,33 @@ - - - - - - - - - - - - - - - - - - - - - - + contextName = "dataFileWriteIn:communicate.c"> + + - - + value = "ABS(total_move)"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 555e5a0..d08de4d 100644 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -154,7 +154,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "556532739.104131" + timestampString = "556616657.914873" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "45" @@ -186,7 +186,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.104285" + timestampString = "556538937.086658" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "19" @@ -202,7 +202,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.104363" + timestampString = "556538937.08676" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "114" @@ -218,7 +218,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.10443" + timestampString = "556538937.086839" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "117" @@ -234,7 +234,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.104495" + timestampString = "556538937.0869139" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "137" @@ -250,7 +250,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.10456" + timestampString = "556538937.08699" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "151" @@ -267,7 +267,7 @@ condition = "buff_count == 26" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.104624" + timestampString = "556538937.087065" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "143" @@ -284,7 +284,7 @@ condition = "string_len != 25" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.10469" + timestampString = "556538937.087142" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "206" @@ -300,7 +300,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.104753" + timestampString = "556538937.087216" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "148" @@ -317,7 +317,7 @@ condition = "buff_count == 26" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.104815" + timestampString = "556538937.087289" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "154" @@ -333,7 +333,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.104877" + timestampString = "556538937.087364" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "158" @@ -349,7 +349,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.1049449" + timestampString = "556538937.087438" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "162" @@ -365,7 +365,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.1050349" + timestampString = "556538937.08751" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "212" @@ -381,7 +381,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.105131" + timestampString = "556538937.087581" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "255" @@ -397,7 +397,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.105234" + timestampString = "556538937.087653" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "199" @@ -413,7 +413,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.105329" + timestampString = "556538937.087724" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "26" @@ -429,7 +429,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.1054161" + timestampString = "556538937.087793" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "211" @@ -445,7 +445,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.10551" + timestampString = "556538937.087862" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "219" @@ -461,7 +461,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.105608" + timestampString = "556538937.087935" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "141" @@ -477,7 +477,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.105705" + timestampString = "556538937.0880049" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "221" @@ -493,7 +493,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.105774" + timestampString = "556538937.088075" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "254" @@ -509,7 +509,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.1058379" + timestampString = "556538937.088147" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "232" @@ -525,7 +525,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list_expand.c" - timestampString = "556532739.105913" + timestampString = "556615437.3113" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "84" @@ -541,41 +541,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.1063139" + timestampString = "556616657.915619" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "109" - endingLineNumber = "109" - landmarkName = "__CALLBACK_DEFINE" - landmarkType = "9"> - - - - - - - - @@ -587,11 +557,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.106678" + timestampString = "556616657.91573" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "222" - endingLineNumber = "222" + startingLineNumber = "107" + endingLineNumber = "107" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -603,11 +573,27 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.106815" + timestampString = "556616657.915815" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "214" - endingLineNumber = "214" + startingLineNumber = "224" + endingLineNumber = "224" + landmarkName = "__CALLBACK_DEFINE" + landmarkType = "9"> + + + + @@ -619,11 +605,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.106931" + timestampString = "556616657.915984" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "168" - endingLineNumber = "168" + startingLineNumber = "170" + endingLineNumber = "170" landmarkName = "listToSTD" landmarkType = "9"> @@ -635,7 +621,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.107067" + timestampString = "556616657.916069" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "38" @@ -651,11 +637,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.107172" + timestampString = "556616657.916149" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "107" - endingLineNumber = "107" + startingLineNumber = "109" + endingLineNumber = "109" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -667,7 +653,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.107306" + timestampString = "556538937.089959" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "270" @@ -683,7 +669,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.107371" + timestampString = "556616657.9162461" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "7" @@ -699,11 +685,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.107476" + timestampString = "556616657.916327" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "45" - endingLineNumber = "45" + startingLineNumber = "46" + endingLineNumber = "46" landmarkName = "initStandardData" landmarkType = "9"> @@ -715,11 +701,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.107699" + timestampString = "556616657.9164079" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "148" - endingLineNumber = "148" + startingLineNumber = "150" + endingLineNumber = "150" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -731,27 +717,27 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.107849" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "129" - endingLineNumber = "129" - landmarkName = "__CALLBACK_DEFINE" - landmarkType = "9"> - - - - + + + + @@ -763,7 +749,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list_expand.c" - timestampString = "556532739.108109" + timestampString = "556615437.311588" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "104" @@ -772,20 +758,6 @@ landmarkType = "9"> - - - - @@ -809,11 +781,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.108696" + timestampString = "556616657.91676" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "255" - endingLineNumber = "255" + startingLineNumber = "257" + endingLineNumber = "257" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -825,11 +797,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.108857" + timestampString = "556616657.916842" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "252" - endingLineNumber = "252" + startingLineNumber = "254" + endingLineNumber = "254" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -841,12 +813,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list.c" - timestampString = "556532739.1090209" + timestampString = "556616657.916931" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "506" - endingLineNumber = "506" - landmarkName = "copyNode" + startingLineNumber = "514" + endingLineNumber = "514" + landmarkName = "mply_findByValue" landmarkType = "9"> @@ -857,7 +829,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.1091371" + timestampString = "556538937.091882" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "101" @@ -873,7 +845,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556532739.109255" + timestampString = "556538937.091946" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "107" @@ -889,11 +861,13 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "556532739.1093611" + timestampString = "556616657.917055" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "83" - endingLineNumber = "83"> + startingLineNumber = "103" + endingLineNumber = "103" + landmarkName = "main" + landmarkType = "9"> @@ -919,11 +893,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.109664" + timestampString = "556616657.917469" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "296" - endingLineNumber = "296" + startingLineNumber = "298" + endingLineNumber = "298" landmarkName = "unknown" landmarkType = "0"> @@ -935,135 +909,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.1098109" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "308" - endingLineNumber = "308" - landmarkName = "unknown" - landmarkType = "0"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - @@ -1207,31 +1165,15 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.1124049" + timestampString = "556616657.918712" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "326" - endingLineNumber = "326" + startingLineNumber = "328" + endingLineNumber = "328" landmarkName = "readDataFileInfo" landmarkType = "9"> - - - - @@ -1255,11 +1197,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.11274" + timestampString = "556616657.918874" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "332" - endingLineNumber = "332" + startingLineNumber = "334" + endingLineNumber = "334" landmarkName = "readDataFileInfo" landmarkType = "9"> @@ -1271,23 +1213,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.112847" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "86" - endingLineNumber = "86" - landmarkName = "dataFileAddStandardData" - landmarkType = "9"> - - - - + + + + @@ -1351,11 +1293,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.113662" + timestampString = "556616657.919297" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "400" - endingLineNumber = "400" + startingLineNumber = "403" + endingLineNumber = "403" landmarkName = "printStandardData" landmarkType = "9"> @@ -1367,11 +1309,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.113796" + timestampString = "556616657.919366" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "347" - endingLineNumber = "347" + startingLineNumber = "349" + endingLineNumber = "349" landmarkName = "readStandardData" landmarkType = "9"> @@ -1383,11 +1325,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.113898" + timestampString = "556616657.919434" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "353" - endingLineNumber = "353" + startingLineNumber = "355" + endingLineNumber = "355" landmarkName = "readStandardData" landmarkType = "9"> @@ -1398,13 +1340,13 @@ shouldBeEnabled = "No" ignoreCount = "0" continueAfterRunningActions = "No" - filePath = "test.c" - timestampString = "556532739.114037" + filePath = "communicate/communicate.c" + timestampString = "556616657.919505" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "75" - endingLineNumber = "75" - landmarkName = "main" + startingLineNumber = "230" + endingLineNumber = "230" + landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -1415,7 +1357,87 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556532739.114136" + timestampString = "556616657.919574" + startingColumnNumber = "9223372036854775807" + endingColumnNumber = "9223372036854775807" + startingLineNumber = "220" + endingLineNumber = "220" + landmarkName = "standardDataToList" + landmarkType = "9"> + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/communicate/communicate.c b/communicate/communicate.c index 2e66286..72a05ce 100644 --- a/communicate/communicate.c +++ b/communicate/communicate.c @@ -41,6 +41,7 @@ STD_DATA *initStandardData(unsigned int type, SID *s_id){ p_std->type = type; p_std->size = 0; p_std->location = 0; + p_std->read_data = 0; if(s_id == NULL) p_std->s_id = getS_id(STANDARD_DATA, 2); else p_std->s_id = copyS_id(s_id); @@ -89,6 +90,7 @@ 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("STDINFO", sizeof(char), 8, p_dfile->fp); @@ -385,6 +387,7 @@ int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){ freeS_id(sb_sid); } } + p_std->read_data = 1; return 0; } diff --git a/list/list.c b/list/list.c index 39d86df..186fd8c 100644 --- a/list/list.c +++ b/list/list.c @@ -138,7 +138,7 @@ List *initList(_Bool if_sid) { return p_list; } -int initMallocValueForNode(Node *p_node, unsigned int type, const void *p_value) { +inline int initMallocValueForNode(Node *p_node, unsigned int type, const void *p_value) { p_node->type = type; p_node->value = (void *)p_value; return 0; @@ -149,10 +149,11 @@ int insertInHead(List *p_list, Node *p_node) { if(p_list->p_lq != NULL){ if(p_list->head->type == HOLE){ Node *t_node = p_list->head; - replaceNode(p_list, p_list->head, p_node); - p_list->p_lq->fn_node[0] = p_node; - releaseNode(t_node); - indexChange(p_list, 0, 1); + while(t_node->type == HOLE) t_node = t_node->next; + replaceNode(p_list, t_node->last, p_node); + p_list->p_lq->fn_node[t_node->last->f_number] = p_node; + indexChange(p_list, t_node->last->f_number, 1); + releaseNode(t_node->last); return 0; } indexChange(p_list, 0, 1); @@ -198,8 +199,10 @@ int insertInTail(List *p_list, Node *p_node) { if(p_list->p_lq != NULL){ p_node->f_number = p_list->p_lq->rlst_len; - if(p_list->p_lq->rlst_len >= p_list->p_lq->rlst_len + FN_NODE_SPARE) - p_list->p_lq->fn_node = realloc(p_list->p_lq->fn_node, sizeof(Node *) * (p_list->p_lq->rlst_len + FN_NODE_SPARE)); + if(p_list->p_lq->rlst_len >= p_list->p_lq->fn_len){ + p_list->p_lq->fn_node = realloc(p_list->p_lq->fn_node, sizeof(Node *) * (p_list->p_lq->fn_len + FN_NODE_SPARE)); + p_list->p_lq->fn_len += FN_NODE_SPARE; + } p_list->p_lq->fn_node[p_list->p_lq->rlst_len] = p_node; p_list->p_lq->rlst_len++; } @@ -225,7 +228,7 @@ int releaseNode(Node *p_node) { removeByNode(node_list, p_node); } if (p_node->value != NULL) { - if (p_node->type != POINTER) { + if (p_node->type != POINTER && p_node->type != HOLE) { if (p_node->type == LIST) { releaseList((List *)p_node->value); } @@ -331,16 +334,14 @@ int removeByNode(List *p_list, Node *p_node) { p_node->next->last = p_node->last; } else{ - if(p_node != p_list->head){ - if(p_node->f_number == 0){ - Node *fn_node = findFnNode(p_list, p_node); - indexChange(p_list, fn_node->f_number, -1); - p_node->last->next = p_node->next; - p_node->next->last = p_node->last; - } - else{ - digHole(p_list, p_node); - } + if(p_node->f_number == 0){ + Node *fn_node = findFnNode(p_list, p_node); + indexChange(p_list, fn_node->f_number, -1); + p_node->last->next = p_node->next; + p_node->next->last = p_node->last; + } + else{ + digHole(p_list, p_node); } p_list->length -= 1; } @@ -352,8 +353,22 @@ Node *popFromHead(List *p_list) { 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); + if(p_list->head->type == HOLE){ + Node *t_node = p_list->head; + while(t_node->type == HOLE) t_node = t_node->next; + if(t_node->f_number != 0){ + Node *r_node = t_node; + digHole(p_list, t_node); + return r_node; + } + p_node = t_node; + } + else{ + if(p_list->p_lq->fn_node[0] == p_list->head){ + Node *r_node = p_list->head; + digHole(p_list, p_list->head); + return r_node; + } } } else{ @@ -376,8 +391,14 @@ Node *popFromTail(List *p_list) { 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) - p_list->p_lq->fn_node = realloc(p_list->p_lq->fn_node, sizeof(p_list->p_lq->rlst_len - 1)); + if(p_list->p_lq->fn_node[p_list->p_lq->rlst_len - 1] == p_list->tail){ + p_list->p_lq->fn_node[p_list->p_lq->rlst_len - 1] = NULL; + p_list->p_lq->rlst_len--; + if(p_list->p_lq->fn_len - p_list->p_lq->rlst_len > FN_NODE_SPARE * 2){ + p_list->p_lq->fn_node = realloc(p_list->p_lq->fn_node, sizeof(p_list->p_lq->fn_len - FN_NODE_SPARE)); + p_list->p_lq->fn_len -= FN_NODE_SPARE; + } + } } //Node *tmp = p_list->tail; p_list->tail->last->next = NULL; @@ -743,27 +764,41 @@ int enableListQuick(List *p_list){ p_list->p_lq = malloc(sizeof(struct list_quick)); register struct list_quick *p_lq = p_list->p_lq; p_lq->rlst_len = p_list->length; - p_lq->fn_node = malloc(sizeof(Node *) * (p_list->length + FN_NODE_SPARE)); + p_lq->fn_node = NULL; p_lq->if_sort = 0; + p_lq->idxc_count = 0; + p_lq->stdid_lst = initList(0); + for(int i = 0; i < INDEX_CHANGE_MAX; i++) p_lq->idxc_lst[i] = NULL; refreshFnNode(p_list); //sortListById(p_list, 0, p_list->length); - return 0; } - return -1; + return 0; } int refreshFnNode(List *p_list){ if(p_list->p_lq != NULL){ + struct list_quick *blk_plq = p_list->p_lq; initIdxcList(p_list); if(p_list->p_lq->fn_node != NULL) free(p_list->p_lq->fn_node); - p_list->p_lq->fn_node = malloc(sizeof(Node *) * p_list->length); + p_list->p_lq->fn_node = malloc(sizeof(Node *) * (p_list->length + FN_NODE_SPARE)); + p_list->p_lq->fn_len = p_list->length + FN_NODE_SPARE; + p_list->p_lq->rlst_len = p_list->length; register Node *p_node = p_list->head; unsigned long long i = 0; + p_list->p_lq = NULL; while (p_node != NULL) { - p_node->f_number = i++; + if(p_node->type == HOLE){ + removeByNode(p_list, p_node); + releaseNode(p_node); + p_node = p_node->next; + continue; + } + p_node->f_number = i; p_list->p_lq->fn_node[i] = p_node; p_node = p_node->next; + i++; } + p_list->p_lq = blk_plq; return 0; } return -1; @@ -821,14 +856,29 @@ int indexTransfromer(List *p_list, unsigned long long m_index){ Node *getNodeByFnNode(List *p_list, unsigned long long index){ if(p_list->p_lq != NULL){ struct list_quick *p_lq = p_list->p_lq; - Node *p_node = p_lq->fn_node[index]; + Node *p_node = NULL; + if(p_lq->rlst_len > index) p_node = p_lq->fn_node[index]; + else p_node = p_lq->fn_node[p_lq->rlst_len - 1]; if(p_lq->idxc_count > 0){ int total_move = indexTransfromer(p_list, index); - if(total_move >=0){ - for(int i = 0; i < ABS(total_move); i++) p_node = p_node->last; + int temp = ABS(total_move); + if(p_lq->rlst_len > index){ + if(total_move >=0){ + for(int i = 0; i < temp; ){ + p_node = p_node->last; + if(p_node->type != HOLE) i++; + } + } + else{ + for(int i = 0; i < temp; ){ + p_node = p_node->next; + if(p_node->type != HOLE) i--; + } + } } else{ - for(int i = 0; i < ABS(total_move); i++) p_node = p_node->next; + unsigned long long jump = index - temp; + for(int i = 0; i < jump; i++) p_node = p_node->next; } return p_node; } @@ -866,7 +916,6 @@ int insertAfterNode(List *p_list, Node *t_node, Node *p_node){ if(p_list->p_lq != NULL){ Node *fn_node = findFnNode(p_list, p_node); - while(fn_node->f_number != 0) fn_node = fn_node->next; indexChange(p_list, fn_node->f_number, 1); } p_list->length += 1; @@ -906,7 +955,7 @@ int insertBeforeNode(List *p_list, Node*t_node, Node *p_node){ Node *findFnNode(List *p_list, Node *p_node){ Node *fn_node = p_node; - while(fn_node->f_number != 0) fn_node = fn_node->next; + while(fn_node->f_number == 0) fn_node = fn_node->next; return fn_node; } diff --git a/list/list.h b/list/list.h index 2c5fb79..bfe0099 100644 --- a/list/list.h +++ b/list/list.h @@ -22,6 +22,13 @@ #define lisrtp(list, x) insertInTail(list, lnp(x)); #define lisrts(list, x) insertInTail(list, lns(x)); +#define lisrhi(list, x) insertInHead(list, lni(x)); +#define lisrhd(list, x) insertInHead(list, lnd(x)); +#define lisrhu(list, x) insertInHead(list, lnu(x)); +#define lisrhull(list, x) insertInHead(list, lnull(x)); +#define lisrhp(list, x) insertInHead(list, lnp(x)); +#define lisrhs(list, x) insertInHead(list, lns(x)); + #define lidxp(list, x) getByPointerForNode(findByIndexForNode(list, x)) #define lidxi(list, x) getByIntForNode(findByIndexForNode(list, x)) #define lidxd(list, x) getByDoubleForNode(findByIndexForNode(list, x)) diff --git a/test.c b/test.c index 77ed001..3438b13 100644 --- a/test.c +++ b/test.c @@ -60,23 +60,44 @@ int stack(void) { releaseStack(t_stack); return 0; } - + +int time_avg(void){ + List *t_list = initList(0); + int64_t time_all = 0; + for(int i = 0; i < 65535; i++) insertInTail(t_list,nodeWithInt(i, 0)); + for(int i = 0; i < 65535; i++) insertInTail(t_list,nodeWithInt(i, 0)); + for(int i = 0; i < 65535; i++) insertInTail(t_list,nodeWithInt(i, 0)); + for(int i = 0; i < 65535; i++) insertInTail(t_list,nodeWithInt(i, 0)); + for(int i = 0; i < 65535; i++) insertInTail(t_list,nodeWithInt(i, 0)); + enableListQuick(t_list); + for (int i = 0; i < 100; i++){ + struct timeval start,stop; + gettimeofday(&start,0); + findByIndexForNode(t_list, 200000); + gettimeofday(&stop,0); + time_all += (int64_t)(stop.tv_usec-start.tv_usec); + + } + double avg_time = (double) (time_all/(int64_t)100); + printf("TIME: %fus\n",avg_time); + releaseList(t_list); + return 0; +} int main(int argc, char **argv) { - - 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); - } + //time_avg(); + List *t_list = initList(0); + for(int i = 0; i < 65535; i++) lisrti(t_list, i); + for(int i = 0; i < 65535; i++) lisrti(t_list, i); + for(int i = 0; i < 65535; i++) lisrti(t_list, i); + for(int i = 0; i < 65535; i++) lisrti(t_list, i); + for(int i = 0; i < 65535; i++) lisrti(t_list, i); + enableListQuick(t_list); + findByIndexForNode(t_list, 300000); + lisrhi(t_list, -1); + insertBeforeNode(t_list, findByIndexForNode(t_list, 5), lni(6)); + popFromHead(t_list); + Node *p_node = findByIndexForNode(t_list, 7); + releaseList(t_list); return 0; } diff --git a/test.h b/test.h index b5f7cb8..8993740 100644 --- a/test.h +++ b/test.h @@ -1,5 +1,7 @@ #ifndef TEST_H -#define TEST_H +#define TEST_H + +#include #include "type/type.h" #include "list/list_expand.h" @@ -9,6 +11,7 @@ int stack(void); int list(void); -int tree(void); +int tree(void); +int time_avg(void); #endif // TEST_H diff --git a/type/type.h b/type/type.h index 2bea1ab..beef564 100644 --- a/type/type.h +++ b/type/type.h @@ -50,8 +50,8 @@ #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 ENABLE_LIST_QUICK 65535 +#define FN_NODE_SPARE 500 #define INDEX_CHANGE_MAX 500 #define INDEX_DISTANCE_MAX 120 #define STD_TEXT_LEN 4 @@ -60,7 +60,7 @@ #define STANDARD 0x2 #define LOW 0x1 -#define ABS(x) (x>0)?(x):(-x) +#define ABS(x) ((x>0)?(x):(-x)) typedef struct md5_ctx{ unsigned int count[2]; @@ -125,6 +125,7 @@ struct list_quick{ Node **fn_node; _Bool if_sort; unsigned int idxc_count; + unsigned long long fn_len; struct index_change *idxc_lst[INDEX_CHANGE_MAX]; unsigned long long rlst_len; FILE *fp; @@ -224,6 +225,7 @@ typedef struct standard_data_head{ typedef struct standard_data{ SID *s_id; + int read_data; unsigned int type; unsigned long long size; unsigned long long location; From aec58814c3cc8ba4b65a15cf75a500fa6efa22d5 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Wed, 22 Aug 2018 19:02:33 +0800 Subject: [PATCH 09/12] Fixed. --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 158 +++++++++--------- list/list.c | 2 +- list/list.h | 8 + 3 files changed, 87 insertions(+), 81 deletions(-) diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index d08de4d..9781d19 100644 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -154,7 +154,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "556616657.914873" + timestampString = "556628194.418951" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "45" @@ -541,7 +541,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.915619" + timestampString = "556628194.419407" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "111" @@ -557,7 +557,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.91573" + timestampString = "556628194.419521" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "107" @@ -573,7 +573,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.915815" + timestampString = "556628194.41959" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "224" @@ -589,7 +589,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.9158961" + timestampString = "556628194.419654" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "216" @@ -605,7 +605,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.915984" + timestampString = "556628194.419724" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "170" @@ -621,7 +621,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.916069" + timestampString = "556628194.4197839" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "38" @@ -637,7 +637,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.916149" + timestampString = "556628194.419843" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "109" @@ -669,7 +669,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.9162461" + timestampString = "556628194.4199179" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "7" @@ -685,7 +685,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.916327" + timestampString = "556628194.419981" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "46" @@ -701,7 +701,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.9164079" + timestampString = "556628194.420041" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "150" @@ -717,7 +717,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.916494" + timestampString = "556628194.420101" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "131" @@ -733,7 +733,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.9165781" + timestampString = "556628194.4201601" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "133" @@ -765,7 +765,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.916675" + timestampString = "556628194.42024" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "253" @@ -781,7 +781,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.91676" + timestampString = "556628194.420329" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "257" @@ -797,7 +797,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556616657.916842" + timestampString = "556628194.420463" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "254" @@ -813,12 +813,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list.c" - timestampString = "556616657.916931" + timestampString = "556628194.4205739" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "514" - endingLineNumber = "514" - landmarkName = "mply_findByValue" + startingLineNumber = "527" + endingLineNumber = "527" + landmarkName = "copyNode" landmarkType = "9"> @@ -861,13 +861,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "556616657.917055" + timestampString = "556628194.421555" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "103" - endingLineNumber = "103" - landmarkName = "main" - landmarkType = "9"> + startingLineNumber = "104" + endingLineNumber = "104"> @@ -1517,11 +1515,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "556616657.9201781" + timestampString = "556628194.4248281" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "100" - endingLineNumber = "100" + startingLineNumber = "101" + endingLineNumber = "101" landmarkName = "main" landmarkType = "9"> @@ -1533,7 +1531,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list.c" - timestampString = "556616657.920482" + timestampString = "556628194.4249229" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "148" @@ -1549,12 +1547,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list.c" - timestampString = "556616657.920566" + timestampString = "556628194.425414" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "844" - endingLineNumber = "844" - landmarkName = "indexTransfromer" + startingLineNumber = "866" + endingLineNumber = "866" + landmarkName = "getNodeByFnNode" landmarkType = "9"> @@ -1565,12 +1563,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list.c" - timestampString = "556616657.920644" + timestampString = "556628194.425916" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "846" - endingLineNumber = "846" - landmarkName = "indexTransfromer" + startingLineNumber = "868" + endingLineNumber = "868" + landmarkName = "getNodeByFnNode" landmarkType = "9"> @@ -1581,7 +1579,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "556616657.920717" + timestampString = "556628194.426397" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "98" @@ -1597,13 +1595,13 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list.c" - timestampString = "556616657.920998" + timestampString = "556628194.426484" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "892" - endingLineNumber = "892" - landmarkName = "unknown" - landmarkType = "0"> + startingLineNumber = "918" + endingLineNumber = "918" + landmarkName = "insertAfterNode" + landmarkType = "9"> diff --git a/list/list.c b/list/list.c index 186fd8c..d627027 100644 --- a/list/list.c +++ b/list/list.c @@ -794,7 +794,7 @@ int refreshFnNode(List *p_list){ continue; } p_node->f_number = i; - p_list->p_lq->fn_node[i] = p_node; + blk_plq->fn_node[i] = p_node; p_node = p_node->next; i++; } diff --git a/list/list.h b/list/list.h index bfe0099..314d7dd 100644 --- a/list/list.h +++ b/list/list.h @@ -36,6 +36,14 @@ #define lupdull(list,x,value) updateValueWithULLIntForNode(findByIndexForNode(list, x),value) +#define lidxvle(list,x) (findByIndexForNode(list, x)->value) +#define lrmvidx(list,x) removeByNode(list, findByIndexForNode(list, x) +#define lpoph(list) popFromHead(list) +#define lpopt(list) popFromTail(list) +#define lfndsid(list,sid) (findByIdForNode(list,sid)->value) +#define lstns() initList(0); +#define lstn() initList(0); + int safeModeForNode(int ifon); int releaseSingleListForsafeModeForNode(List *p_list); int releaseSingleNodeForsafeModeForNode(List *p_list); From 5eaafa0b647b682de75c666783abc2237066c875 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Wed, 22 Aug 2018 22:03:33 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=B7=BB=E5=8A=A0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project.pbxproj | 2 +- list/list.h | 540 +++++++++++++++--- 2 files changed, 476 insertions(+), 66 deletions(-) diff --git a/ZE-Standard-Libraries.xcodeproj/project.pbxproj b/ZE-Standard-Libraries.xcodeproj/project.pbxproj index e48fef6..a485e40 100644 --- a/ZE-Standard-Libraries.xcodeproj/project.pbxproj +++ b/ZE-Standard-Libraries.xcodeproj/project.pbxproj @@ -35,7 +35,7 @@ 9233C30F212292B000FB2485 /* md5.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = md5.c; path = id/md5.c; sourceTree = ""; }; 9246994F20CD000300B4E894 /* list.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list.c; sourceTree = ""; }; 9246995020CD000300B4E894 /* list_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list_expand.h; sourceTree = ""; }; - 9246995120CD000300B4E894 /* list.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list.h; sourceTree = ""; }; + 9246995120CD000300B4E894 /* list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list.h; sourceTree = ""; }; 9246995820CE52A700B4E894 /* stack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack.h; sourceTree = ""; }; 9246995920CE52A700B4E894 /* stack.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = stack.c; sourceTree = ""; }; 9246995B20CE5C8900B4E894 /* stack_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack_expand.h; sourceTree = ""; }; diff --git a/list/list.h b/list/list.h index 314d7dd..c9265f1 100644 --- a/list/list.h +++ b/list/list.h @@ -3,141 +3,551 @@ #include "../type/type.h" #include "../id/id.h" +/************************************************ + *节点快速初始化相关宏 + ************************************************/ + +/**** + *不带ID相关 + */ + +/*直接获取一个以整型值初始化的节点不带ID的缩略*/ #define lni(x) nodeWithInt(x,0) + +/*直接获取一个以无符号整型值初始化的不带ID节点的缩略*/ #define lnu(x) nodeWithUInt(x,0) + +/*直接获取一个以无符号长整形值初始化的节点的缩略*/ #define lnull(x) nodeWithULLInt(x,0) + +/*直接获取一个以浮点值初始化的不带ID节点的缩略*/ #define lnd(x) nodeWithDouble(x,0) + +/*直接获取一个以字符串值初始化的不带ID节点的缩略*/ #define lns(x) nodeWithString(x,0) + +/*直接获取一个以指针值初始化的不带ID节点的缩略*/ #define lnp(x) nodeWithPointer(x,0) +/**** + *带ID相关 + */ + +/*直接获取一个以整型值初始化的带ID节点的缩略*/ #define lsni(x) nodeWithInt(x,1) + +/*直接获取一个以浮点值初始化的带ID节点的缩略*/ #define lsnd(x) nodeWithDouble(x,1) + +/*直接获取一个以字符串值初始化的带ID节点的缩略*/ #define lsns(x) nodeWithString(x,1) + +/*直接获取一个以指针值初始化的节点的缩略*/ #define lsnp(x) nodeWithPointer(x,1) + + + +/************************************************ + *链表快速插入相关宏 + ************************************************/ + +/**** + *尾部相关 + */ + +/*在链表尾部直接加入一个已经用整型值初始化的不带ID的节点*/ #define lisrti(list, x) insertInTail(list, lni(x)); + +/*在链表尾部直接加入一个已经用浮点值初始化的不带ID的节点*/ #define lisrtd(list, x) insertInTail(list, lnd(x)); + +/*在链表尾部直接加入一个已经用无符号整型值初始化的不带ID的节点*/ #define lisrtu(list, x) insertInTail(list, lnu(x)); + +/*在链表尾部直接加入一个已经用无符号长整型值初始化的不带ID的节点*/ #define lisrtull(list, x) insertInTail(list, lnull(x)); + +/*在链表尾部直接加入一个已经用指针值初始化的不带ID的节点*/ #define lisrtp(list, x) insertInTail(list, lnp(x)); + +/*在链表尾部直接加入一个已经用字符串值初始化的不带ID的节点*/ #define lisrts(list, x) insertInTail(list, lns(x)); +/**** + *头部相关 + */ + +/*在链表头部直接加入一个已经用整型值初始化的不带ID的节点*/ #define lisrhi(list, x) insertInHead(list, lni(x)); + +/*在链表头部直接加入一个已经用浮点值初始化的不带ID的节点*/ #define lisrhd(list, x) insertInHead(list, lnd(x)); + +/*在链表头部直接加入一个已经用无符号整型值初始化的不带ID的节点*/ #define lisrhu(list, x) insertInHead(list, lnu(x)); + +/*在链表头部直接加入一个已经用无符号长整型值初始化的不带ID的节点*/ #define lisrhull(list, x) insertInHead(list, lnull(x)); + +/*在链表头部直接加入一个已经用指针值初始化的不带ID的节点*/ #define lisrhp(list, x) insertInHead(list, lnp(x)); + +/*在链表头部直接加入一个已经用字符串值初始化的不带ID的节点*/ #define lisrhs(list, x) insertInHead(list, lns(x)); + + + +/************************************************ + *节点快速获得储存值相关宏 + ************************************************/ + +/*快速获得指针类型的节点所储存的值*/ #define lidxp(list, x) getByPointerForNode(findByIndexForNode(list, x)) + +/*快速获得整型类型的节点所储存的值*/ #define lidxi(list, x) getByIntForNode(findByIndexForNode(list, x)) + +/*快速获得浮点类型的节点所储存的值*/ #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) -#define lidxvle(list,x) (findByIndexForNode(list, x)->value) + + + +/************************************************ + *其他快速操作相关宏 + ************************************************/ + +/*通过节点的序号直接得到它的值*/ +#define lidxvle(list,x) (findByIndexForNode(list, x)->value) + +/*通过节点序号直接移除节点*/ #define lrmvidx(list,x) removeByNode(list, findByIndexForNode(list, x) + +/*从列表头移除节点的缩略*/ #define lpoph(list) popFromHead(list) + +/*从列表尾移除节点的缩略*/ #define lpopt(list) popFromTail(list) + +/*通过节点的ID直接获得节点的值*/ #define lfndsid(list,sid) (findByIdForNode(list,sid)->value) + +/*创建一个不带ID的链表的缩略*/ #define lstns() initList(0); -#define lstn() initList(0); -int safeModeForNode(int ifon); -int releaseSingleListForsafeModeForNode(List *p_list); -int releaseSingleNodeForsafeModeForNode(List *p_list); -int releaseAllForNode(void); +/*创建一个带有ID的链表缩略*/ +#define lstn() initList(1); -List *initList(_Bool if_sid); -Node *initNode(_Bool if_sid); -s_Node *s_initNode(void); +/********************************************************************************************************/ -int initMallocValueForNode(Node *,unsigned int,const void *); +/********************************************************************************************************* + *安全模式开启函数:在开启安全模式后,记录代码段区间所有用户已经分配过内存的链表和节点.在结束时,释放记录在案的还未释放的链表和节点. + *注意:在开启后,只有使用库提供的初始化函数的时候才有效.安全模式打开后,只有调用安全模式结束函数后,才可以重新打开. + *运用:可以在逻辑较为复杂的代码段使用,预防内存泄漏的情况发生.可以免去繁琐的内存泄漏检查过程. + *返回: 若成功函数返回0,若失败函数返回-1. + ********************************************************************************************************/ +extern int safeModeForNode(int ifon); -int insertInHead(List *p_list, Node *p_node); -int insertInTail(List *p_list, Node *p_node); -int insertAfterNode(List *p_list, Node *t_node, Node *p_node); -int insertBeforeNode(List *p_list, Node*t_node, Node *p_node); -int s_insertInHead(List *p_list, s_Node *s_p_node); -int s_insertInTail(List *p_list, s_Node *s_p_node); +/*属于安全模式操作内部调用,释放链表而不释放其中的值.*/ +static int releaseSingleListForsafeModeForNode(List *p_list); -int replaceNode(List *p_list, Node *pt_node, Node *p_node); -int exchangeNode(List *p_list, Node *f_node, Node *s_node); +/*属于安全模式操作内部调用,释放节点而不释放其中的值.*/ +static int releaseSingleNodeForsafeModeForNode(List *p_list); -Node *copyNode(Node *); +/*安全模式结束时调用,调用后将会释放所有在安全模式区间内用户已经分配过的链表和节点,安全模式将会关闭.*/ +extern int releaseAllForNode(void); -int removeById(List *p_list, SID *s_id); -int removeByNode(List *p_list, Node *p_node); -Node *popFromHead(List *p_list); -Node *popFromTail(List *p_list); +/* + *初始化链表,并返回指向新链表的指针,参数if_sid指示是否为新链表分配ID号 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern List *initList(_Bool if_sid); -unsigned long long len(List *p_list); +/* + *初始化节点,并返回指向新链表的指针,参数if_sid指示是否为新节点分配ID号 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *initNode(_Bool if_sid); -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); -int releaseList(List *p_list); -int s_releaseList(List *p_list); -int releaseListForCustom(List *p_list, int (*func)(void *)); -int s_releaseListForCustom(List *p_list, int (*func)(void *)); -int releaseListForSingle(List *p_list); +/************************************************ + *链表的初始化相关函数 + ************************************************/ -int releaseNode(Node *p_node); -int s_releaseNode(s_Node *s_p_node); +/* + *初始化单向链表节点,该种类节点可以与普通储存在List结构中. + *单向链表的引入主要在于对于简单问题提供更小开销的解决方案.但相应的操作函数较少,不如一般链表方便. + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern s_Node *s_initNode(void); -int releaseNodeForCustom(Node *p_node, int (*func)(void *)); -int s_releaseNodeForCustom(s_Node *s_p_node, int (*func)(void *)); +/*库中内部调用函数,旨在为新节点的储存值获取内存,并将相应的储存值储存在获取到的内存中,并指明储存值的类型.*/ +static int initMallocValueForNode(Node *,unsigned int,const void *); -int releaseOnlyNode(Node *p_node); -int isListEmpty(List *p_list); + + +/************************************************* + *节点的插入: 节点的插入操作相关函数 + *************************************************/ + +/* + *在链表的头部插入一个节点* + *返回: 若成功函数返回0,若失败函数返回-1.*/ +extern int insertInHead(List *p_list, Node *p_node); + +/* + *在链表的尾部插入一个节点 + *返回: 若成功函数返回0,若失败函数返回-1.*/ +extern int insertInTail(List *p_list, Node *p_node); + +/* + *在一个节点的后面插入一个节点 + *参数说明: t_node为指向目标节点的指针;p_node为指向新节点的指针; + *返回: 若成功函数返回0,若失败函数返回-1.*/ +extern int insertAfterNode(List *p_list, Node *t_node, Node *p_node); + +/* + *在一个节点的前面插入一个节点 + *参数: t_node为指向目标节点的指针;p_node为指向新节点的指针; + *返回: 若成功函数返回0,若失败函数返回-1.*/ +extern int insertBeforeNode(List *p_list, Node*t_node, Node *p_node); + +/*在单项链表的头部插入一个节点 + *返回: 若成功函数返回0,若失败函数返回-1.*/ +extern int s_insertInHead(List *p_list, s_Node *s_p_node); + +/* + *在单项链表的尾部插入一个节点 + *返回: 若成功函数返回0,若失败函数返回-1.*/ +extern int s_insertInTail(List *p_list, s_Node *s_p_node); + + + + +/*********************************************** + 节点的替换与调换: 节点的替换与调换相关的函数 + ***********************************************/ + +/* + *用一个新节点,替换掉链表中已经存在的节点 + *参数: t_node为指向目标节点的指针;p_node为指向新节点的指针; + */ +extern int replaceNode(List *p_list, Node *t_node, Node *p_node); + +/* + *交换两个已经在链表中的节点的位置 + *参数: t_node为指向目标节点的指针;p_node为指向新节点的指针; + */ + +extern int exchangeNode(List *p_list, Node *f_node, Node *s_node); + + + + +/********************************************** + *链表或节点的复制: 链表与节点复制相关函数 + *********************************************/ + +/* + *节点的复制,复制将会为新节点重新分配内存,并将源节点的所有值拷贝入新节点. + *注意: 源节点与新节点ID相同. + *返回: 若成功函数返回指向新节点的指针,若失败则返回NULL*/ +extern Node *copyNode(Node *); + +/* + *链表的复制,复制将会为新链表重新分配内存,并将源链表的所有节点复制. + *注意: 源链表与新链表ID相同. + *返回: 若成功函数返回指向新链表的指针,若失败则返回NULL*/ List *copyList(List *p_list); -int pushInfo(Info *p_info, const char *head,const char *body); -Error *pushError(unsigned int type, int pri, Info *p_info); -Notice *pushNotice(unsigned int type, Info *p_info); -Info *initInfo(const char *head, const char *body); -Error *createError(Info *info,unsigned int type,int pri); -Notice *createWarning(Info *info, unsigned int type, int pri); -int showError(Error *); -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 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); -Node *findFnNode(List *p_list, Node *p_node); -void initIdxcList(List *p_list); -void digHole(List *p_list, Node *p_node); -int disableListQuick(List *p_list); -Node *findByIndexForNode(List *, unsigned long long); -Node *findByIntForNode(List *, int); -Node *findByDoubleForNode(List *, double); -Node *findByStringForNode(List *, char *); -Node *findByPointerForNode(List *, void *); +/*********************************************** + *节点的删除: 节点移除相关函数 + ***********************************************/ -Node *getListTail(List *); -Node *updateNodeByIndex(List *, void *, unsigned long long); +/* + *通过ID查找链表中的特定节点并从链表中移除相关节点,但并不释放节点内存. + *若成功函数返回0,若失败函数返回-1.*/ +extern int removeById(List *p_list, SID *s_id); +/* + *通过指向节点的指针直接从链表中移除相关节点,但不释放节点内存 + *若成功函数返回0,若失败函数返回-1.*/ +extern int removeByNode(List *p_list, Node *p_node); + +/* + *从链表头部移除第一个节点,不释放节点内存,返回节点指向该节点的指针,方便后续操作 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *popFromHead(List *p_list); + +/* + *从链表尾部移除最后一个节点,不释放节点内存,返回节点指向该节点的指针,方便后续操作 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *popFromTail(List *p_list); + + + + +/*********************************************** + *链表或节点的属性:获取或更新链表或节点属性有关的函数 + ***********************************************/ + +/* + *返回链表长度*/ +extern unsigned long long len(List *p_list); + +/* + *查询链表是否为空 + *返回: 如果链表为空返回1,如果链表不为空则返回0.*/ +int isListEmpty(List *p_list); + +/* + *直接获得节点中的整型值 + *返回: 返回该节点储存的整型值*/ int getByIntForNode(Node *); + +/* + *直接获得节点中的无符号整型值 + *返回: 返回该节点储存的无符号整型值*/ unsigned int getByUIntForNode(Node *); + +/* + *直接获得节点中的浮点值 + *返回: 返回该节点储存的浮点值*/ double getByDoubleForNode(Node *); + +/* + *直接获得节点中的字符串值 + *返回: 返回该节点储存的字符串值*/ char *getByStringForNode(Node *); + +/* + *直接获得节点中的指针值 + *返回: 返回该节点储存的指针值*/ void *getByPointerForNode(Node *); + +/* + *直接获得节点的序号 + *返回: 返回该节点在链表中的序号*/ unsigned long long getIndexForNode(List *p_list,Node *p_node); +/* + *通过节点的序号找到节点中相关的值,并更新其中的储存的值的指针. + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL*/ +Node *updateNodeByIndex(List *p_list, void *new_value, unsigned long long index); + + + + +/*********************************************** + *链表查找:查找链表中的指定节点有关的函数 + **********************************************/ + +/* + *通过ID查找链表中相关的单个节点 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByIdForNode(List *p_list, SID * s_id); + +/* + *通过节点中的值查找相关单个节点 + *参数: type指明相关值的类型;value为指向储存相关值的内存的指针. + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByValue(List *p_list, unsigned int type, const void *value); + +/* + *通过序号查找相关的单个节点 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByIndexForNode(List *, unsigned long long); + +/* + *通过整型值查找储存该值的单个节点 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByIntForNode(List *, int); + +/* + *通过浮点值查找储存该值的单个节点 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByDoubleForNode(List *, double); + +/* + *通过字符串中查找储存该值的单个节点. + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByStringForNode(List *, char *); + +/* + *通过指针值查找储存该值的单个节点. + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByPointerForNode(List *, void *); + +//void *findByIdForCustom(List *p_list, SID *s_id, int func(SID *)); + +/* + *通过节点中的值查找相关多个节点. + *参数: type指明相关值的类型;value为指向储存相关值的内存的指针. + *返回: 如果成功返回一个链表,储存所有满足该值的节点的指针.如果失败则返回NULL.*/ +extern List *mply_findByValue(List *p_list, unsigned int type, const void *value); + + + + +/*********************************************** + *链表的排序: 使用快速排序算法,按照指定规则排序链表 + **********************************************/ + +/* + *内部函数: 通过节点中的值查找相关多个节点. + *参数: type指明相关值的类型;value为指向储存相关值的内存的指针. + *返回: 如果成功返回0,如果失败则返回-1.*/ +static int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node)); + +/* + *自定义排序链表. + *参数: func是一个函数指针, 指向的函数接受两个指向链表中节点的指针,并对他们进行比较 + 如果前一的相关值个大于后一个得相关值则返会大于0的数, 反之则返回小于0的数. + *返回: 如果成功返回0,如果失败则返回-1.*/ +extern int sortListForCustom(List *p_list, int(*func)(Node *f_node, Node *s_node)); + + + + +/*********************************************** + *链表或节点的释放: 释放链表或节点所占内存的相关函数 + **********************************************/ + +/* + *释放链表所占的内存空间 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int releaseList(List *p_list); + +/* + *释放单向链表所占的内存空间 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int s_releaseList(List *p_list); + +/* + *自定义释放链表所占的内存空间 + *参数: func是一个函数指针,它指向的函数现在每次释放节点时调用,用于释放用户自定义的结构体的所占用内存. + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int releaseListForCustom(List *p_list, int (*func)(void *)); + +/* + *自定义释放单向链表所占的内存空间 + *参数: func是一个函数指针,它指向的函数现在每次释放节点时调用, + * 接收储存在节点中的值的指针,释放用户自定义的结构体的所占用内存. + * 回调函数返回0代表释放成功,返回-1代表释放失败. + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int s_releaseListForCustom(List *p_list, int (*func)(void *)); + +/* + *释放链表所占的内存,但不释放链表中的节点所占的内存空间 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int releaseListForSingle(List *p_list); + +/* + *释放相关节点所占的内存空间 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int releaseNode(Node *p_node); + +/* + *释放单向节点所占的内存空间 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int s_releaseNode(s_Node *s_p_node); + +/* + *自定义释放节点所占的内存空间 + *参数: func是一个函数指针,它指向的函数现在每次释放节点时调用, + * 接收储存在节点中的值的指针,释放用户自定义的结构体的所占用内存. + * 回调函数返回0代表释放成功,返回-1代表释放失败. + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int releaseNodeForCustom(Node *p_node, int (*func)(void *)); + +/* + *自定义释放单向节点所占的内存空间 + *参数: func是一个函数指针,它指向的函数现在每次释放单项节点时调用, + * 接收储存在单项节点中的值得指针,释放用户自定义的结构体的所占用内存. + * 回调函数返回0代表释放成功,返回-1代表释放失败. + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int s_releaseNodeForCustom(s_Node *s_p_node, int (*func)(void *)); + +/* + *释放节点所占的内存空间,不释放节点所储存的值所占的内存空间 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int releaseOnlyNode(Node *p_node); + +/*********************************************** + *错误的提示:出现错误时,以下函数用于快捷地通报错误信息, + * 以便根据信息快速找到错误原因. + **********************************************/ + +extern int pushInfo(Info *p_info, const char *head,const char *body); + +extern Error *pushError(unsigned int type, int pri, Info *p_info); + +extern Notice *pushNotice(unsigned int type, Info *p_info); + +extern Info *initInfo(const char *head, const char *body); + +extern Error *createError(Info *info,unsigned int type,int pri); + +extern Notice *createWarning(Info *info, unsigned int type, int pri); + +extern int showError(Error *); + +extern int showWarning(Notice *); + +/*********************************************** + *长链表模式:当链表长度很长时,链表查找的代价将会很大. + * 该模式用于优化长链表的查找过程.降低时间复杂度. + ***********************************************/ +/* + *打开长链表模式 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int enableListQuick(List *p_list); + +/* + *关闭长链表模式 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int disableListQuick(List *p_list); + +static int refreshFnNode(List *p_list); + +static int indexTransfromer(List *p_list, unsigned long long m_index); + +static int indexChange(List *p_list, unsigned long long c_index, int move); + +static Node *getNodeByFnNode(List *p_list, unsigned long long index); + +static Node *findFnNode(List *p_list, Node *p_node); + +static void initIdxcList(List *p_list); + +static void digHole(List *p_list, Node *p_node); + + +//Node *getListTail(List *); + + + + +/*********************************************** + *相关的全局变量 + ***********************************************/ + static int if_safeModeForNode; static List *node_list; static List *list_list; + + + #endif From 8dd9e194770ce19780b3ba9c1571db0f19cf9617 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Wed, 22 Aug 2018 22:50:08 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/list_expand.h | 374 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 329 insertions(+), 45 deletions(-) diff --git a/list/list_expand.h b/list/list_expand.h index 0cc5894..0ceb7e7 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -3,63 +3,347 @@ #include "list.h" -#define __RETURN(argc, args...) newReturn(1, -1, argc , args) -#define __CRETURN__ newCReturn() + + + +/************************************************ + *回调函数的便捷操作相关宏 + ************************************************/ + +/**** + *母函数相关 + */ + +/* + *若需要母函数需要向毁掉函数传递相关参数则使用该宏 + *参数: argc指示传递参数的类型格式;args为需要返回的参数.*/ #define __SEND_ARG(argc, args...) newReturn(0, -1, argc , args) + +/* + *若快速声明回调函数则使用该宏 + *参数: name为回调函数名.*/ #define __CALLBACK_STATE(name) List *_do##name(unsigned int, void *, List *) + +/* + *若快速定义回调函数则使用该宏 + *参数: name为回调函数名.*/ #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); + +/* + *若传递回调函数指针则使用该宏 + *参数: name为回调函数名.*/ #define __CALLBACK_CALL(name) _do##name -#define __LIST_LEN getInfoForListThrough(expand_resources,0) -#define __NOW_INDEX getInfoForListThrough(expand_resources,1) + +/* + *若母函数获取回调函数返回的指针则使用该宏 + *参数: x为该值的顺序号, type为获取的指针值的类型.*/ #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); -Node *nodeWithULLInt(unsigned long long, _Bool if_sid); -Node *nodeWithDouble(double, _Bool if_sid); -Node *nodeWithString(const char *, _Bool if_sid); -Node *nodeWithPointer(const void *, _Bool if_sid); -s_Node *s_nodeWithInt(int); -s_Node *s_nodeWithUInt(unsigned int); -s_Node *s_nodeWithDouble(double); -s_Node *s_nodeWithString(const char *); -s_Node *s_nodeWithPointer(const void *); - -Node *nodeWithComplex(void); -int addValueForComplex(Node *, int type, void *value); -int addIntForComplex(Node *, int); -int addDoubleForComplex(Node *, double); -int addStringForComplex(Node *, char *); -int addPointerForComplex(Node *, void *); +/* + *若母函数获取回调函数返回的值则使用该宏 + *参数: x为该值的顺序号, type为获取的值的类型.*/ +#define __RTN_ARGS(list,x,type) *((type *) lidxp(list, x)); + +/**** + *回调函数相关 + */ + +/* + *若回调函数获取遍历链表中的当前节点的值则使用该宏 + *参数: c_type为获取值的类型.*/ +#define __VALUE(c_type) (c_type)value + +/* + *若回调函数获取母函数传递的参数则使用该宏 + *参数: x为该值的顺序号, type为获取值的类型.*/ +#define __ARGS(x, type) *((type *) lidxp(expand_resources, x)); + +/* + *若回调函数获取母函数传递的指针参数则使用该宏 + *参数: x为该值的顺序号, type为获取的指针值的类型.*/ +#define __ARGS_P(x, type) (type *) lidxp(expand_resources, x); + +/* + *若回调函数获取遍历链表的长度则使用该宏 + */ +#define __LIST_LEN getInfoForListThrough(expand_resources,0) + +/* + *若回调函数获取遍历链表中当前节点的序号则使用该宏 + */ +#define __NOW_INDEX getInfoForListThrough(expand_resources,1) + +/* + *若需要终止遍历或终止遍历并向母函数返回相关参数则使用该宏 + *参数: argc指示返回参数的个数;args为需要返回的参数.*/ +#define __RETURN(argc, args...) newReturn(1, -1, argc , args) + +/* + *若继续遍历则使用该宏 + */ +#define __CRETURN__ newCReturn() + + + + +/************************************************ + *节点的快速初始化: 为新节点分配内存空间, + * 并使用输入值对其进行初始化. + ************************************************/ + +/* + *为新节点获取内存空间, 并使用整型值初始化新节点 + *参数if_sid指示函数是否为节点获取ID + *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ +extern Node *nodeWithInt(int, _Bool if_sid); + +/* + *为新节点获取内存空间, 并使用无符号整型值初始化新节点 + *参数if_sid指示函数是否为节点获取ID + *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ +extern Node *nodeWithUInt(unsigned int, _Bool if_sid); + +/* + *为新节点获取内存空间, 并使用无符号长整型值初始化新节点 + *参数if_sid指示函数是否为节点获取ID + *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ +extern Node *nodeWithULLInt(unsigned long long, _Bool if_sid); + +/* + *为新节点获取内存空间, 并使用浮点值初始化新节点 + *参数if_sid指示函数是否为节点获取ID + *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ +extern Node *nodeWithDouble(double, _Bool if_sid); + +/* + *为新节点获取内存空间, 并使用字符串值初始化新节点 + *参数if_sid指示函数是否为节点获取ID + *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ +extern Node *nodeWithString(const char *, _Bool if_sid); + +/* + *为新节点获取内存空间, 并使用指针值初始化新节点 + *参数if_sid指示函数是否为节点获取ID + *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ +extern Node *nodeWithPointer(const void *, _Bool if_sid); + + + + + +/************************************************ + *单向节点的快速初始化: 为新节点分配内存空间, + * 并使用输入值对其进行初始化. + ************************************************/ + +/* + *为新单向节点获取内存空间, 并使用整型值初始化新单向节点 + *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ +extern s_Node *s_nodeWithInt(int); + +/* + *为新单向节点获取内存空间, 并使用无符号整型值初始化新单向节点 + *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ +extern s_Node *s_nodeWithUInt(unsigned int); + +/* + *为新单向节点获取内存空间, 并使用浮点值初始化新单向节点 + *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ +extern s_Node *s_nodeWithDouble(double); + +/* + *为新单向节点获取内存空间, 并使用字符串值初始化新单向节点 + *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ +extern s_Node *s_nodeWithString(const char *); + +/* + *为新单向节点获取内存空间, 并使用指针值初始化新单向节点 + *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ +extern s_Node *s_nodeWithPointer(const void *); + + -int updateValueWithIntForNode(Node *,int); -int updateValueWithULLIntForNode(Node *, unsigned long long); -int updateValueWithDoubleForNode(Node *,double); -int updateValueWithStringForNode(Node *,char *); -int updateValueWithPointerForNode(Node *,void *); -List *mply_findByIntForNode(List*, int); -List *mply_findByDoubleForNode(List*, double); -List *mply_findByStringForNode(List*, char *); +/************************************************ + *嵌套节点的快速初始化: 为嵌套节点节点分配内存空间, + * 并使用输入值对其进行初始化 + *说明: 嵌套节点指储存一个链表指针的节点. + ************************************************/ + +/* + *为新嵌套节点获取内存空间 + *返回: 若成功指向新嵌套节点的指针,若失败函数返回NULL.*/ +extern Node *nodeWithComplex(void); + +/* + *用输入的值初始化嵌套节点 + *参数: type指明所输入值的类型,value为指向所输入值的内存空间的指针 + *返回: 若成功则返回0,若失败函数返回-1.*/ +extern int addValueForComplex(Node *, int type, void *value); + +/* + *用输入的整型值初始化嵌套节点 + *返回: 若成功则返回0,若失败函数返回-1.*/ +extern int addIntForComplex(Node *, int); + +/* + *用输入的浮点值初始化嵌套节点 + *返回: 若成功则返回0,若失败函数返回-1.*/ +extern int addDoubleForComplex(Node *, double); + +/* + *用输入的字符串初始化嵌套节点 + *返回: 若成功则返回0,若失败函数返回-1.*/ +extern int addStringForComplex(Node *, char *); + +/* + *用输入的指针值初始化嵌套节点 + *返回: 若成功则返回0,若失败函数返回-1.*/ +extern int addPointerForComplex(Node *, void *); + + + + +/************************************************ + *节点值的更新: 更新既有节点中的值,并用新值直接替换旧值 + ************************************************/ + +/* + *用输入的整型值更新节点中的值 + *返回: 若成功则返回0,若失败函数返回-1.*/ +extern int updateValueWithIntForNode(Node *,int); + +/* + *用输入的无符号长整型值更新节点中的值 + *返回: 若成功则返回0,若失败函数返回-1.*/ +extern int updateValueWithULLIntForNode(Node *, unsigned long long); + +/* + *用输入的浮点值更新节点中的值 + *返回: 若成功则返回0,若失败函数返回-1.*/ +extern int updateValueWithDoubleForNode(Node *,double); + +/* + *用输入的字符串值更新节点中的值 + *返回: 若成功则返回0,若失败函数返回-1.*/ +extern int updateValueWithStringForNode(Node *,char *); + +/* + *用输入的指针值更新节点中的值 + *返回: 若成功则返回0,若失败函数返回-1.*/ +extern int updateValueWithPointerForNode(Node *,void *); + + + + +/************************************************ + *链表的查找: 依据输入值,查找链表中的多个特定类型的节点 + ************************************************/ + +/* + *通过输入的整型值,查找链表中多个含有该值的节点 + *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ +List *mply_findByIntForNode(List*, int); + +/* + *通过输入的浮点值,查找链表中多个含有该值的节点 + *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ +List *mply_findByDoubleForNode(List*, double); + +/* + *通过输入的字符串值,查找链表中多个含有该值的节点 + *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ +List *mply_findByStringForNode(List*, char *); + +/* + *通过输入的指针值,查找链表中多个含有该值的节点 + *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ List *mply_findByPointerForNode(List*, void *); - -void printListInfo(List *p_list,int priority); -void printNodeInfo(Node *p_node,int priority); -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, ...); + + + + +/************************************************ + *链表或节点的输出: 格式化输出链表或节点的属性 + ************************************************/ + +/* + *输出链表及其中节点的相关信息 + *参数: priority为每行输出信息前的空格数除以4*/ +void printListInfo(List *p_list,int priority); + +/* + *输出节点中的相关信息 + *参数: priority为每行输出信息前的空格数乘以4*/ +void printNodeInfo(Node *p_node,int priority); + +/* + *输出链表及其中节点的相关信息 + */ +void printList(List *); + +/* + *自定义输出链表及其中节点的相关信息 + *参数: func为一个函数指针, 指向函数的职能在于输出节点中的用户自定义结构的相关信息*/ +void printListForCustom(List *p_list,void (*func)(void *value)); + +/* + *printListForCustom函数的回调函数 + */ +__CALLBACK_STATE(printListForCustom); + +/* + *输出节点中的相关信息 + */ +void printNode(Node *p_node); + + + + + +/************************************************ + *链表的遍历: 遍历链表相关函数 + ************************************************/ + +/* + *链表的遍历 + *参数: p_func为一个函数指针, 指向的回调函数的职能在于接受每个节点的类型(type)/值指针(value)/传入参数链表(args), + 然后进行相关操作,并返回一个链表,其中包含返回状态,若有,也可以包含想要传递给母函数的值 + expand_resources为一个链表,储存母函数想要传递给回调函数的值 + *返回: 如果回调函数有需要返回给母函数的值,则返回包含这些值的链表,否则返回NULL.*/ +extern List *listThrough(List *p_list, List *(*p_func)(unsigned int type, void *value, List *args), List *expand_resources); + +/* + *回调函数相关宏操作的辅助函数,用于给回调函数给母函数返回值提供便利 + */ +extern 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 From 56d58cb04696b02845381377155e75ce90db7cad Mon Sep 17 00:00:00 2001 From: Saturneic Date: Wed, 22 Aug 2018 23:19:08 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=B7=BB=E5=8A=A0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- type/type.h | 269 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 186 insertions(+), 83 deletions(-) diff --git a/type/type.h b/type/type.h index beef564..9cc4887 100644 --- a/type/type.h +++ b/type/type.h @@ -15,7 +15,14 @@ #include #include */ - + + + + +/************************************************ + *库相关类型的编号 + ************************************************/ + #define VOID 0 #define INT 1 #define DOUBLE 2 @@ -35,6 +42,14 @@ #define HOLE 16 #define ULLINT 17 + + + + +/************************************************ + *库相关参数的定义 + ************************************************/ + #define DEEPC 1 #define DEEPB 2 #define DEEPA 3 @@ -55,19 +70,40 @@ #define INDEX_CHANGE_MAX 500 #define INDEX_DISTANCE_MAX 120 #define STD_TEXT_LEN 4 - #define HIGH 0x3 #define STANDARD 0x2 #define LOW 0x1 + + + + +/************************************************ + *库相关操作宏的定义 + ************************************************/ + #define ABS(x) ((x>0)?(x):(-x)) + + + + +/************************************************ + *库相关结构的定义 + ************************************************/ + +/* + *MD5的管理及操作的结构 + */ typedef struct md5_ctx{ unsigned int count[2]; unsigned int state[4]; unsigned char buffer[64]; }MD5_CTX; +/* + *SID的初始值管理及操作的结构 + */ struct sid_raw{ unsigned int type; unsigned int *value;//4 @@ -75,29 +111,41 @@ struct sid_raw{ unsigned int *value_deepest;//32 }; +/* + *SID的管理及操作的结构 + */ typedef struct s_id{ - struct sid_raw *sr; - unsigned int deep; - MD5_CTX *md5; - unsigned char *decrypt_hex; - char *decrypt_str; + struct sid_raw *sr;//指向SID初始值 + unsigned int deep;//SID初始值的复杂度 + MD5_CTX *md5;//指向MD5结构 + unsigned char *decrypt_hex;//指向MD5的Hex信息 + char *decrypt_str;//指向MD5的Hex信息转化成的字符串 }SID; +/* + *节点的管理及操作的结构 + */ typedef struct Node{ - unsigned long long f_number; - unsigned int type; - void *value; - struct Node *next; - struct Node *last; + unsigned long long f_number;//长链表模式下,分派的数组节点编号 + unsigned int type;//类型 + void *value;//值指针 + struct Node *next;//指向下一个节点 + struct Node *last;//指向上一个节点 SID *s_id; } Node; +/* + *单向节点的管理及操作的结构 + */ typedef struct simple_Node{ - void *value; - struct simple_Node *next; + void *value;//值指针 + struct simple_Node *next;//指向下一个节点 }s_Node; +/* + *长链表模式下链表缓存块的记录结构 + */ struct lst_std_id{ unsigned long long start_idx; unsigned long long end_idx; @@ -106,132 +154,187 @@ struct lst_std_id{ struct list_quick; +/* + *链表的管理及操作的结构 + */ typedef struct List{ - Node *head; - Node *tail; - s_Node *s_head; - s_Node *s_tail; + Node *head;//指向第一个节点 + Node *tail;//指向最后一个节点 + s_Node *s_head;//指向第一个单向节点 + s_Node *s_tail;//指向最后一个单向节点 + /*如果长链表模式开启则指向对应的长链表模式的管理结构,如果未开启则为NULL*/ struct list_quick *p_lq; - unsigned long long length; + unsigned long long length;//链表的长度 SID *s_id; } List; +/* + *长链表模式下链表改动偏移量的记录结构 + */ struct index_change{ - unsigned long long c_index; - int f_count; + unsigned long long c_index;//偏移量,有正负之分 + int f_count;//偏移量所对应的数组对的节点 }; +/* + *长链表模式的管理及操作的结构 + */ struct list_quick{ - Node **fn_node; - _Bool if_sort; - unsigned int idxc_count; - unsigned long long fn_len; - struct index_change *idxc_lst[INDEX_CHANGE_MAX]; - unsigned long long rlst_len; - FILE *fp; + Node **fn_node;//指向链表各个节点的映射数组 + unsigned long long fn_len;//映射数组的总长度 + unsigned long long rlst_len;//在映射数组实际被占用的长度 + _Bool if_sort;//链表是否有序 + unsigned int idxc_count;//链的删减增的操作次数 + struct index_change *idxc_lst[INDEX_CHANGE_MAX];//储存链表的删减增操作的记录 + FILE *fp;//链表缓存文件 List *stdid_lst; }; +/* + *错误管理中信息的管理及操作的结构 + */ typedef struct Info{ - char head[64]; - char body[256]; + char head[64];//信息头 + char body[256];//信息内容 }Info; +/* + *错误管理中错误的管理及操作的结构 + */ typedef struct Error{ - unsigned int type; - int priority; - time_t time; - Info info; + unsigned int type;//错误类型号 + int priority;//优先级 + time_t time;//错误产生的时间 + Info info;//信息指针 }Error; +/* + *错误管理中警告的管理及操作的结构 + */ typedef struct Notice{ - unsigned int type; - time_t time; - Info info; + unsigned int type;//警告类型号 + time_t time;//警告产生的时间 + Info info;//信息指针 }Notice; +/* + *错误管理中日志信息的管理及操作的结构 + */ typedef struct Log{ - FILE *fp; - int if_enable; - unsigned long int id; + FILE *fp;//日志文件的指针 + int if_enable;//日志文件是否启用 + unsigned long int id;//日志文件的ID }Log; +/* + *栈节点的管理及操作的结构 + */ typedef struct stack_node{ - unsigned int type; - void *value; - struct stack_node *next; - SID *s_id; + unsigned int type;//栈节点的类型 + void *value;//值指针 + struct stack_node *next;//下一个栈节点 + SID *s_id;//栈节点的ID } SNode; +/* + *栈的管理及操作的结构 + */ typedef struct stack{ - unsigned long long length; - SNode *top; - SID *s_id; + unsigned long long length;//栈的长度 + SNode *top;//指向栈顶的栈节点 + SID *s_id;//栈的ID } Stack; +/* + *超级树节点的管理及操作的结构 + */ typedef struct tree_node { - SID *s_id; - List *home; - struct tree_node *father; - Node *room; - unsigned long long child_num; - unsigned int type; - void *value; + SID *s_id;//超级树节点的ID + List *home;//超级树节点的子节点列表 + struct tree_node *father;//超级树节点的父节点 + Node *room;//超级树节点的父节点的子节点列表 + unsigned long long child_num;//超级树节点的子节点数量 + unsigned int type;//超级树节点的类型 + void *value;//值指针 }TNode; +/* + *二叉树节点的管理及操作的结构 + */ typedef struct simple_tree_node{ - void *value; - struct simple_tree_node *childs[2]; + void *value;//值指针 + struct simple_tree_node *childs[2];//子节点 }s_TNode; +/* + *树的管理及操作的结构 + */ typedef struct tree { - SID *s_id; - TNode *root; - s_TNode *s_root; + SID *s_id;//超级树的SID + TNode *root;//超级树根节点 + s_TNode *s_root;//二叉树的根节点 }Tree; +/* + *文件头信息的管理及操作的结构 + */ typedef struct file_head{ - char head_test[18]; - unsigned long long data_num; + char head_test[18];//数据文件头部的验证信息 + unsigned long long data_num;//数据文件中的标准数据结构的数目 }F_HEAD; +/* + *数据文件的管理及操作的结构 + */ typedef struct data_file{ - FILE *fp; - F_HEAD *pf_head; - List *pf_stdlst; + FILE *fp;//数据文件 + F_HEAD *pf_head;//数据文件头 + List *pf_stdlst;//数据文件的标志数据结构的储存链表 }D_FILE; +/* + *标准数据结构的管理及操作的结构 + */ typedef struct standard_data_blocks{ - unsigned int type; - unsigned long long location; - char *sid; - _Bool if_data; - unsigned int blocks_num; - char *buff; + unsigned int type;//数据块的类型 + unsigned long long location;//数据块在数据文件中的定位 + char *sid;//数据块的ID + _Bool if_data;//数据块是否赋值 + unsigned int blocks_num;//数据块字节大小 + char *buff;//指向数据块储存值内存空间的指针 }STD_BLOCKS; +/* + *标准数据结构中数据块的连接关系的管理及操作的结构 + */ typedef struct standard_data_connection{ - unsigned long long location; - char *f_sid; - char *s_sid; + unsigned long long location;//数据块链接关系结构在文件中的定位 + char *f_sid;//前一个数据块的ID + char *s_sid;//后一个数据块的ID }STD_CTN; +/* + *标准数据结构头的管理及操作的结构 + */ typedef struct standard_data_head{ - unsigned long long data_blk_num; - unsigned long long data_ctn_num; + unsigned long long data_blk_num;//数据块的数目 + unsigned long long data_ctn_num;//数据块链接关系结构的数目 }STD_HEAD; +/* + *标准数据结构的管理及操作的结构 + */ typedef struct standard_data{ - SID *s_id; - int read_data; - unsigned int type; - unsigned long long size; - unsigned long long location; - _Bool lock; - List *pd_blocklst; - List *pd_ctnlst; + SID *s_id;//标准数据结构的ID + int read_data;//标准数据结构是否已经读取完整 + unsigned int type;//标准数据结构所对应的类型 + unsigned long long size;//标准数据结构在数据文件中的大小 + unsigned long long location;//标准数据结构的头在数据文件中的定位 + _Bool lock;//标准数据文件是否被锁住 + List *pd_blocklst;//数据块储存链表 + List *pd_ctnlst;//数据块连接关系结构的储存链表 }STD_DATA; #endif /* type_h */