From 498d988a5ed82bdba81596a4da8e195b193092ec Mon Sep 17 00:00:00 2001 From: Saturneic Date: Fri, 3 Aug 2018 18:32:20 +0800 Subject: [PATCH 1/3] Added some functions and fixed. --- .../project.pbxproj | 8 + .../xcdebugger/Expressions.xcexplist | 46 ++- .../xcdebugger/Breakpoints_v2.xcbkptlist | 341 +++++++++++++++++- error/error.c | 33 +- error/error.h | 45 +-- id/id.c | 88 ++--- id/id.h | 18 +- list/list.c | 97 ++++- list/list.h | 35 +- list/list_expand.h | 3 +- stack/stack.h | 2 - stack/stack_expand.h | 1 - test.c | 7 +- test.h | 4 +- tree/tree.c | 6 +- tree/tree.h | 21 -- type/type.h | 86 ++++- 17 files changed, 638 insertions(+), 203 deletions(-) diff --git a/ZE-Standard-Libraries.xcodeproj/project.pbxproj b/ZE-Standard-Libraries.xcodeproj/project.pbxproj index f464100..2186f17 100644 --- a/ZE-Standard-Libraries.xcodeproj/project.pbxproj +++ b/ZE-Standard-Libraries.xcodeproj/project.pbxproj @@ -120,6 +120,7 @@ 927993B420CB87D6008CE3A9 = { isa = PBXGroup; children = ( + 92A15CFC211442C700826FB8 /* graph */, 9286EB7C2114021E00752977 /* communicate */, 9286EB78211400BD00752977 /* error */, 9269D4F1210F1B9E00161557 /* id */, @@ -159,6 +160,13 @@ name = communicate; sourceTree = ""; }; + 92A15CFC211442C700826FB8 /* graph */ = { + isa = PBXGroup; + children = ( + ); + name = graph; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ 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 12f5903..d8ca57a 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,10 +3,33 @@ version = "1.0"> + contextName = "freeS_id:id.c"> + + + value = "buff[string_len-1]"> + + + + + + + + + + + + + + @@ -27,8 +50,27 @@ + + + + + + + + + + + + + + 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 c5081b3..2c76f28 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 = "554959944.593868" + timestampString = "554985107.001519" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "64" @@ -179,5 +179,344 @@ landmarkType = "9"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/error/error.c b/error/error.c index f11f8b5..0b34a2f 100644 --- a/error/error.c +++ b/error/error.c @@ -52,32 +52,7 @@ int loadFromFile(FILE *fp,char* number) { return 1; } -int pushInfo(Info *p_info, const char *head, const char *body) { - p_info->head = (char *)malloc(sizeof(char) * strlen(head)); - p_info->body = (char *)malloc(sizeof(char) * strlen(body)); - strcpy(p_info->head, head); - strcpy(p_info->body, body); - return 0; -} - -int pushError(unsigned int type, int pri, Info *p_info) { - Error error; - error.type = type; - error.priority = pri; - error.p_info = p_info; - error.time = time(NULL); - return 0; -} - -int pushNotice(unsigned int type, Info *p_info) { - Notice notice; - notice.type = type; - notice.p_info = p_info; - notice.time = time(NULL); - return 0; -} - -static int saveError(Error *p_error) { +int saveError(Error *p_error) { fprintf(logfile.fp, "--------------------\n\ ERROR\n\ @@ -88,10 +63,10 @@ static int saveError(Error *p_error) { %s\n\ %s\n\ ---------------------\n", - p_error->type, p_error->priority, ctime( &(p_error->time) ), p_error->p_info->head, p_error->p_info->body); + p_error->type, p_error->priority, ctime( &(p_error->time) ), p_error->info.head, p_error->info.body); return 0; } -static int saveNotice(Notice *p_notice) { +int saveNotice(Notice *p_notice) { fprintf(logfile.fp, "--------------------\n\ NOTICE\n\ @@ -101,6 +76,6 @@ static int saveNotice(Notice *p_notice) { %s\n\ %s\n\ ----------------------\n", - p_notice->type, ctime( &(p_notice->time) ), p_notice->p_info->head, p_notice->p_info->body); + p_notice->type, ctime( &(p_notice->time) ), p_notice->info.head, p_notice->info.body); return 0; } diff --git a/error/error.h b/error/error.h index fb342e7..f1e8d41 100644 --- a/error/error.h +++ b/error/error.h @@ -1,37 +1,8 @@ -#include "../list/list_expand.h" -#include -#include - #ifndef ERROR_H #define ERROR_H -#define HIGH 0x3 -#define STANDARD 0x2 -#define LOW 0x1 - -typedef struct Info{ - char *head; - char *body; -}Info; - -typedef struct Error{ - unsigned int type; - int priority; - Info *p_info; - time_t time; -}Error; - -typedef struct Notice{ - unsigned int type; - Info *p_info; - time_t time; -}Notice; - -typedef struct Log{ - FILE *fp; - int if_enable; - unsigned long int id; -}Log; +#include "../type/type.h" +#include "../list/list_expand.h" Log logfile; List *error_list = NULL; @@ -42,14 +13,10 @@ int initErrorSystem(void); int setLogDirectory(const char *path); int closeLogDirectory(void); + int loadFromFile(FILE *fp,char* number); -int pushInfo(Info *p_info, const char *head,const char *body); -int pushError(unsigned int type, int pri, Info *p_info); -int pushNotice(unsigned int type, Info *p_info); +int saveError(Error *p_error); +int saveNotice(Notice *p_notice); -//为保证处理效果,不允许外调下列函数 -static int saveError(Error *p_error); -static int saveNotice(Notice *p_notice); - -#endif \ No newline at end of file +#endif diff --git a/id/id.c b/id/id.c index a9ebb3f..22960d3 100644 --- a/id/id.c +++ b/id/id.c @@ -16,36 +16,25 @@ unsigned long long getId(void) { } SID *initS_id(unsigned int deep_level){ - SID *p_sid = (SID *)malloc(sizeof(SID)); + SID *p_sid = (SID *) malloc(sizeof(SID)); p_sid->type = VOID; p_sid->deep = deep_level; p_sid->value = NULL; p_sid->value_deeper = NULL; p_sid->value_deepest = NULL; - if (deep_level > 0) p_sid->value = (unsigned int (*)[DEEPC_LEN])malloc(sizeof(unsigned int)*DEEPC_LEN); - if (deep_level > 1) p_sid->value_deeper = (unsigned int (*)[DEEPB_LEN])malloc(sizeof(unsigned int)*DEEPB_LEN); - if (deep_level > 2) p_sid->value_deepest = (unsigned int (*)[DEEPA_LEN])malloc(sizeof(unsigned int)*DEEPA_LEN); + if (deep_level > 0) p_sid->value = (unsigned int *)malloc(sizeof(unsigned int)*DEEPC_LEN); + if (deep_level > 1) p_sid->value_deeper = (unsigned int *)malloc(sizeof(unsigned int)*DEEPB_LEN); + if (deep_level > 2) p_sid->value_deepest = (unsigned int *)malloc(sizeof(unsigned int)*DEEPA_LEN); return p_sid; } SID *getS_id(unsigned int type, unsigned int deep_level){ - SID *p_sid = (SID *)malloc(sizeof(SID)); + SID *p_sid = initS_id(deep_level); p_sid->type = type; - p_sid->deep = deep_level; - p_sid->value = NULL; - p_sid->value_deeper = NULL; - p_sid->value_deepest = NULL; if(deep_level > 0){ - p_sid->value = (unsigned int (*)[DEEPC_LEN])malloc(sizeof(unsigned int)*DEEPC_LEN); - for(int i = 0; i < DEEPC_LEN; i++) (*p_sid->value)[i] = rand()%65535; - if(deep_level > 1){ - p_sid->value_deeper = (unsigned int (*)[DEEPB_LEN])malloc(sizeof(unsigned int)*DEEPB_LEN); - for(int i = 0; i < DEEPB_LEN; i++) (*p_sid->value_deeper)[i] = rand()%65535; - } - if (deep_level > 2) { - p_sid->value_deepest = (unsigned int (*)[DEEPA_LEN])malloc(sizeof(unsigned int)*DEEPA_LEN); - for(int i = 0; i < DEEPA_LEN; i++) (*p_sid->value_deepest)[i] = rand()%65535; - } + 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; } return p_sid; @@ -56,20 +45,20 @@ int fitS_id(const SID *fs_id, const SID *ss_id){ 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; + 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; + 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; + 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; } } @@ -95,17 +84,17 @@ char *s_idToASCIIString(const SID *s_id){ unsigned int buff[DATA_BIT]; if(s_id->deep > 0){ if (s_id->deep == DEEPC){ - string = (char *) malloc(sizeof(char) * (DEEPC_LEN + 1) * DATA_BIT + 1); + string = (char *) malloc(sizeof(char) * (DEEPC_LEN + 1) * DATA_BIT); deep_len = DEEPC_LEN + 1; deep_len *= DATA_BIT; } else if (s_id->deep == DEEPB){ - string = (char *) malloc(sizeof(char) * (DEEPC_LEN + DEEPB_LEN + 1) * DATA_BIT + 1); + string = (char *) malloc(sizeof(char) * (DEEPC_LEN + DEEPB_LEN + 1) * DATA_BIT); deep_len = DEEPC_LEN + DEEPB_LEN + 1; deep_len *= DATA_BIT; } else{ - string = (char *)malloc(sizeof(char) * (DEEPC_LEN + DEEPB_LEN + DEEPA_LEN + 1) * DATA_BIT + 1); + string = (char *)malloc(sizeof(char) * (DEEPC_LEN + DEEPB_LEN + DEEPA_LEN + 1) * DATA_BIT); deep_len = DEEPC_LEN + DEEPB_LEN + DEEPA_LEN + 1; deep_len *= DATA_BIT; } @@ -121,7 +110,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->value[i]; for (int i = 0; i < DATA_BIT; i++) buff[i] = 0; string_count = TYPE_LEN + (i) * 5; buff_count = DATA_BIT - 1; @@ -135,7 +124,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->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; @@ -150,7 +139,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->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; @@ -162,7 +151,6 @@ char *s_idToASCIIString(const SID *s_id){ } for(int i = DATA_BIT - 1; i >= 0; i--) string[string_count + i] = buff[i] + 48; } - printf("%s",string); return string; } else{ @@ -173,52 +161,52 @@ char *s_idToASCIIString(const SID *s_id){ SID *asciiStringToS_id(const char *string){ SID *s_id = NULL; unsigned long long string_len = strlen(string); - unsigned int *buff = (unsigned int *) malloc(sizeof(string_len - 1)); - for(int i = 0; i < string_len; i++){ - buff[i] = string[i] - 48; - } + if (string_len == 25) s_id = initS_id(1); else if (string_len == 65) s_id = initS_id(2); else if (string_len == 225) s_id = initS_id(3); else return NULL; + unsigned int *buff = (unsigned int *) malloc(sizeof(unsigned int) * (string_len)); + for(int i = 0; i < string_len; i++){ + buff[i] = (unsigned int)string[i] - 48; + } + printf("%s\n",string); + s_id->type = 0; for (int i = 0; i < 5; i++){ s_id->type += buff[i] ; - s_id->type *= 10; + s_id->type *= 10u; } - s_id->type /= 10; + s_id->type /= 10u; if (string_len >= 25){ for(int i = 0; i < DEEPC_LEN; i++){ - (*s_id->value)[i] = 0; + s_id->value[i] = 0; for (int j = 0; j < 5; j++){ - (*s_id->value)[i] += (int)buff[5 + i * 5 + j]; - (*s_id->value)[i] *= 10; + s_id->value[i] += (unsigned int)buff[5 + i * 5 + j]; + if(j < 4) s_id->value[i] *= 10; } - (*s_id->value)[i] /= 10; } } if (string_len >= 65){ for(int i = 0; i < DEEPB_LEN; i++){ - (*s_id->value_deeper)[i] = 0; + s_id->value_deeper[i] = 0; for (int j = 0; j < 5; j++){ - (*s_id->value_deeper)[i] += buff[25 + i * 5 + j]; - (*s_id->value_deeper)[i] *= 10; + s_id->value_deeper[i] += buff[25 + i * 5 + j]; + if(j < 4) s_id->value_deeper[i] *= 10; } - (*s_id->value_deeper)[i] /= 10; } } if (string_len >= 225){ for(int i = 0; i < DEEPA_LEN; i++){ - (*s_id->value_deepest)[i] = 0; + s_id->value_deepest[i] = 0; for (int j = 0; j < 5; j++){ - (*s_id->value_deepest)[i] += buff[65 + i * 5 + j]; - (*s_id->value_deepest)[i] *= 10; + s_id->value_deepest[i] += buff[65 + i * 5 + j]; + if(j < 4) s_id->value_deepest[i] *= 10; } - (*s_id->value_deepest)[i] /= 10; } } free(buff); diff --git a/id/id.h b/id/id.h index 9c8a038..abe4499 100644 --- a/id/id.h +++ b/id/id.h @@ -1,11 +1,3 @@ -// -// id.h -// ZE-Standard-Libraries -// -// Created by 鑳′竴鍏 on 2018/7/25. -// Copyright 漏 2018骞 ZE. All rights reserved. -// - #ifndef id_h #define id_h @@ -15,18 +7,10 @@ #include #include "../type/type.h" -typedef struct s_id{ - unsigned int type; - unsigned int (*value)[DEEPC_LEN];//4 - unsigned int (*value_deeper)[DEEPB_LEN];//8 - unsigned int (*value_deepest)[DEEPA_LEN];//32 - unsigned int deep; -}SID; - void init_rand(void); unsigned long long getId(void); -SID *getS_id(unsigned int type ,unsigned int deep_level); +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); diff --git a/list/list.c b/list/list.c index c392166..ff7ba19 100644 --- a/list/list.c +++ b/list/list.c @@ -83,6 +83,7 @@ Node *initNode(void) { Node *p_node = (Node *)malloc(sizeof(Node)); Node *prec_node = NULL; p_node->s_id = getS_id(LIST_NODE, 2); + p_node->if_sid = 1; p_node->if_malloc = 0; p_node->next = NULL; p_node->last = NULL; @@ -101,6 +102,7 @@ List *initList(void) { Node *p_node; List *p_list = (List *)malloc(sizeof(List)); p_list->s_id = getS_id(LIST, 1); + p_list->if_sid = 1; p_list->head = NULL; p_list->tail = NULL; p_list->length = 0; @@ -297,7 +299,6 @@ int popFromTail(List *p_list) { return 0; } -/*璇ュ嚱鏁扮畻娉曢渶瑕佹敼杩*/ Node *findByIdForNode(List *p_list, const SID *s_id) { Node *ph_node = p_list->head; Node *pt_node = p_list->tail; @@ -330,7 +331,7 @@ Node *findByValue(List *p_list, unsigned int type, const void *value) { while (p_node != NULL) { if (p_node->type != type) { p_node = p_node->next; - continue;//璺宠繃涓嶅悎绫诲瀷鐨勮妭鐐 + continue; } if (type == INT) { if (*((int *)p_node->value) == *((int *)value)) { @@ -457,3 +458,95 @@ int releaseOnlyNode(Node *p_node) { free(p_node); return 0; } + +int releaseNodeForCustom(Node *p_node, int (*func)(void *)){ + if (if_safeModeForNode == 1) { + removeByNode(node_list, p_node); + } + if (p_node->if_malloc == 1) { + if (!func(p_node->value)) + showError(pushError(LIST_NODE, STANDARD, initInfo("releaseNodeForCustom()", "Error in using custom freeing value function."))); + p_node->value = NULL; + } + p_node->last = NULL; + p_node->next = NULL; + p_node->type = VOID; + p_node->value = NULL; + freeS_id(p_node->s_id); + p_node->if_malloc = 0; + free(p_node); + return 0; +} + +int releaseListForCustom(List *p_list, int (*func)(void *)){ + Node *p_node, *pl_node; + p_node = p_list->head; + if (if_safeModeForNode == 1) { + Node *tar_list = findByValue(list_list, POINTER, (void *)p_list); + removeByNode(list_list, tar_list); + } + while (p_node != NULL) { + pl_node = p_node; + p_node = p_node->next; + pl_node->next = NULL; + pl_node->last = NULL; + releaseNodeForCustom(pl_node,func); + } + p_list->head = NULL; + p_list->tail = NULL; + p_list->length = 0; + freeS_id(p_list->s_id); + free(p_list); + return 0; +} + +int pushInfo(Info *p_info, const char *head, const char *body) { + strcpy(p_info->head, head); + strcpy(p_info->body, body); + return 0; +} + +Error *pushError(unsigned int type, int pri, Info *p_info) { + Error *p_error = (Error *)malloc(sizeof(Error)); + p_error->type = type; + p_error->priority = pri; + p_error->info = *p_info; + p_error->time = time(NULL); + free(p_info); + return p_error; +} + +Notice *pushNotice(unsigned int type, Info *p_info) { + Notice *p_notice = (Notice *)malloc(sizeof(Notice)); + p_notice->type = type; + p_notice->info = *p_info; + p_notice->time = time(NULL); + free(p_info); + return p_notice; +} + +Info *initInfo(const char *head, const char *body){ + Info *p_info = (Info *)malloc(sizeof(Info)); + pushInfo(p_info, head, body); + return p_info; +} + +int showError(Error *p_error){ + printf("\n"); + for (int i = 0; i < p_error->priority; i++) { + printf("!"); + } + + printf("(Error) %s\n",asctime(localtime(&p_error->time))); + printf("%s: %s.\n",p_error->info.head,p_error->info.body); + free(p_error); + return 0; +} + +int showWarning(Notice *p_notice){ + printf("\n@"); + printf("(Warning) %s\n",asctime(localtime(&p_notice->time))); + printf("%s: %s.\n",p_notice->info.head,p_notice->info.body); + free(p_notice); + return 0; +} diff --git a/list/list.h b/list/list.h index f43248f..349b525 100644 --- a/list/list.h +++ b/list/list.h @@ -1,31 +1,8 @@ #ifndef LIST_H #define LIST_H - -#include -#include -#include -#include #include "../type/type.h" #include "../id/id.h" -typedef struct Node{ - SID *s_id; - void *value; - _Bool if_malloc; - _Bool if_sid; - unsigned int type; - struct Node *next; - struct Node *last; -} Node; - - -typedef struct List{ - SID *s_id; - Node *head; - Node *tail; - unsigned long long length; -} List; - int safeModeForNode(int ifon); int releaseSingleListForsafeModeForNode(List *p_list); int releaseSingleNodeForsafeModeForNode(List *p_list); @@ -55,13 +32,25 @@ 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 releaseListForCustom(List *p_list, int (*func)(void *)); int releaseListForSingle(List *p_list); int releaseNode(Node *p_node); +int releaseNodeForCustom(Node *p_node, int (*func)(void *)); int releaseOnlyNode(Node *p_node); int isListEmpty(List *p_list); 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 *); + static int if_safeModeForNode; static List *node_list; static List *list_list; diff --git a/list/list_expand.h b/list/list_expand.h index 63bb773..1d8d97e 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -1,5 +1,6 @@ #ifndef LIST_EXPAND_H -#define LIST_EXPAND_H +#define LIST_EXPAND_H + #include "list.h" Node *nodeWithInt(int); diff --git a/stack/stack.h b/stack/stack.h index 7990edf..d20f752 100644 --- a/stack/stack.h +++ b/stack/stack.h @@ -1,5 +1,3 @@ -#include - #ifndef STACK_H #define STACK_H #include "../list/list_expand.h" diff --git a/stack/stack_expand.h b/stack/stack_expand.h index ba739f7..95978c1 100644 --- a/stack/stack_expand.h +++ b/stack/stack_expand.h @@ -1,7 +1,6 @@ #ifndef STACK_EXPAND_H #define STACK_EXPAND_H -#include #include "stack.h" SNode *snodeWithInt(int); diff --git a/test.c b/test.c index 8ce8cfe..bd9d494 100644 --- a/test.c +++ b/test.c @@ -83,11 +83,6 @@ int stack(void) { int main(int argc, char **argv) { //tree(); - init_rand(); - SID *p_sid = getS_id(LIST_NODE, 1); - char *string = s_idToASCIIString(p_sid); - SID *t_sid = asciiStringToS_id(string); - int if_same = simFitS_id(p_sid, t_sid); - getchar(); + init_rand(); return 0; } diff --git a/test.h b/test.h index eed9bbc..dfa8642 100644 --- a/test.h +++ b/test.h @@ -1,11 +1,9 @@ #ifndef TEST_H #define TEST_H -#include - +#include "type/type.h" #include "list/list_expand.h" #include "stack/stack_expand.h" -#include "tree/tree.h" #include "tree/tree_expand.h" int stack(void); diff --git a/tree/tree.c b/tree/tree.c index e9b4c87..bf5efd4 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -31,7 +31,8 @@ int safeModeForTree(int ifon) { TNode *initTNode(void) { Node *s_node; TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); - p_tnode->s_id = getS_id(TREE_NODE, 2); + p_tnode->s_id = getS_id(TREE_NODE, 2); + p_tnode->if_sid = 1; p_tnode->child_num = 0; p_tnode->father = NULL; p_tnode->if_malloc = 0; @@ -60,7 +61,8 @@ TNode *initTNode(void) { Tree *initTree(void) { Node *s_node; Tree *p_tree = (Tree *)malloc(sizeof(Tree)); - p_tree->s_id = getS_id(TREE, 1); + p_tree->s_id = getS_id(TREE, 1); + p_tree->if_sid = 1; p_tree->root = NULL; if (if_safeModeForTree) { if (if_safeModeForNode) { diff --git a/tree/tree.h b/tree/tree.h index f230b57..2504c6f 100644 --- a/tree/tree.h +++ b/tree/tree.h @@ -4,27 +4,6 @@ #include #include "../list/list_expand.h" -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; - _Bool if_malloc; - _Bool if_sid; -}TNode; - -typedef struct tree -{ - SID *s_id; - _Bool if_sid; - TNode *root; -}Tree; - - int safeModeForTree(int ifon); int releaseAllForTree(void); diff --git a/type/type.h b/type/type.h index af3ee92..4be9d31 100644 --- a/type/type.h +++ b/type/type.h @@ -1,6 +1,11 @@ #ifndef type_h #define type_h +#include +#include +#include +#include + #define VOID 0 #define INT 1 #define DOUBLE 2 @@ -13,16 +18,89 @@ #define TREE_NODE 9 #define STACK_NODE 10 -#define TYPE_LEN 5 - #define DEEPC 1 #define DEEPB 2 #define DEEPA 3 - +#define TYPE_LEN 5 #define DEEPC_LEN 4 #define DEEPB_LEN 8 #define DEEPA_LEN 32 - #define DATA_BIT 5 +#define HIGH 0x3 +#define STANDARD 0x2 +#define LOW 0x1 + +typedef struct s_id{ + unsigned int type; + unsigned int *value;//4 + unsigned int *value_deeper;//8 + unsigned int *value_deepest;//32 + unsigned int deep; +}SID; + +typedef struct Node{ + SID *s_id; + void *value; + _Bool if_malloc; + _Bool if_sid; + unsigned int type; + struct Node *next; + struct Node *last; +} Node; + + +typedef struct List{ + SID *s_id; + Node *head; + Node *tail; + _Bool if_sid; + unsigned long long length; +} List; + +typedef struct Info{ + char head[64]; + char body[256]; +}Info; + +typedef struct Error{ + unsigned int type; + int priority; + Info info; + time_t time; +}Error; + +typedef struct Notice{ + unsigned int type; + Info info; + time_t time; +}Notice; + +typedef struct Log{ + FILE *fp; + int if_enable; + unsigned long int id; +}Log; + +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; + _Bool if_malloc; + _Bool if_sid; +}TNode; + +typedef struct tree +{ + SID *s_id; + _Bool if_sid; + TNode *root; +}Tree; + + #endif /* type_h */ From ac54c07010b76b476be6a93d59b818343900a6be Mon Sep 17 00:00:00 2001 From: Saturneic Date: Fri, 3 Aug 2018 18:35:10 +0800 Subject: [PATCH 2/3] Fixed --- list/list_expand.c | 2 +- tree/tree_expand.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/list/list_expand.c b/list/list_expand.c index 84b8157..e0cf001 100644 --- a/list/list_expand.c +++ b/list/list_expand.c @@ -355,7 +355,7 @@ unsigned long long calListMemory(List * p_list){ unsigned long long nodes_size = 0LL; unsigned long long list_size = sizeof(p_list); while(p_node != NULL){ - nodes_size += sizeof(p_node) + sizeof(*p_node->value); + nodes_size += sizeof(p_node); p_node = p_node->next; } return list_size + nodes_size; diff --git a/tree/tree_expand.c b/tree/tree_expand.c index 48e891a..e188663 100644 --- a/tree/tree_expand.c +++ b/tree/tree_expand.c @@ -222,6 +222,6 @@ unsigned long long calTreeMemory(Tree *p_tree){ } int _doCalTreeMemory(TNode *p_tnode, unsigned long long height){ - tnodes_size += sizeof(p_tnode) + sizeof(*p_tnode->value); + tnodes_size += sizeof(p_tnode); return 0; } From c4315326d3dece36ce3de10f5b6865c5700cf5bb Mon Sep 17 00:00:00 2001 From: Saturneic Date: Fri, 3 Aug 2018 18:58:49 +0800 Subject: [PATCH 3/3] Fixed --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 464 +++++++++--------- id/id.c | 32 +- list/list.c | 19 +- stack/stack.c | 8 + tree/tree.c | 19 +- type/type.h | 1 + 6 files changed, 302 insertions(+), 241 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 2c76f28..e74a180 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 = "554985107.001519" + timestampString = "554986718.90595" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "64" @@ -170,7 +170,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "tree/tree_expand.c" - timestampString = "554638722.806551" + timestampString = "554986718.906049" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "60" @@ -186,7 +186,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "554985107.0016969" + timestampString = "554986718.906109" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "19" @@ -202,12 +202,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "554985107.001803" + timestampString = "554986718.906213" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "81" - endingLineNumber = "81" - landmarkName = "s_idToASCIIString" + startingLineNumber = "99" + endingLineNumber = "99" + landmarkName = "simFitS_id" landmarkType = "9"> @@ -218,13 +218,13 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "554985107.001882" + timestampString = "554986718.906307" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "84" - endingLineNumber = "84" - landmarkName = "s_idToASCIIString" - landmarkType = "9"> + startingLineNumber = "102" + endingLineNumber = "102" + landmarkName = "unknown" + landmarkType = "0"> - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -381,27 +493,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "554985107.002624" + timestampString = "554986718.9079241" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "218" - endingLineNumber = "218" - landmarkName = "freeS_id" - landmarkType = "9"> - - - - @@ -413,107 +509,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "554985107.002749" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "20" - endingLineNumber = "20" - landmarkName = "initS_id" - landmarkType = "9"> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/id/id.c b/id/id.c index 22960d3..2c862da 100644 --- a/id/id.c +++ b/id/id.c @@ -17,14 +17,32 @@ unsigned long long getId(void) { SID *initS_id(unsigned int deep_level){ 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->deep = deep_level; p_sid->value = NULL; p_sid->value_deeper = NULL; p_sid->value_deepest = NULL; - if (deep_level > 0) p_sid->value = (unsigned int *)malloc(sizeof(unsigned int)*DEEPC_LEN); - if (deep_level > 1) p_sid->value_deeper = (unsigned int *)malloc(sizeof(unsigned int)*DEEPB_LEN); - if (deep_level > 2) p_sid->value_deepest = (unsigned int *)malloc(sizeof(unsigned int)*DEEPA_LEN); + if (deep_level > 0) { + p_sid->value = (unsigned int *)malloc(sizeof(unsigned int)*DEEPC_LEN); + if(p_sid->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){ + 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){ + printf("\ninitS_id(): Error in getting the memory of sid.value_deepest.\n"); + } + } return p_sid; } @@ -98,6 +116,9 @@ char *s_idToASCIIString(const SID *s_id){ deep_len = DEEPC_LEN + DEEPB_LEN + DEEPA_LEN + 1; deep_len *= DATA_BIT; } + if(string == NULL){ + printf("\ns_idToASCIIString(): Error in getting the memory of string.\n"); + } string[deep_len] = '\0'; temp = s_id->type; buff_count = DATA_BIT - 1; @@ -168,12 +189,13 @@ SID *asciiStringToS_id(const char *string){ else return NULL; unsigned int *buff = (unsigned int *) malloc(sizeof(unsigned int) * (string_len)); + if(buff == NULL){ + printf("\ns_idToASCIIString(): Error in getting the memory of string.\n"); + } for(int i = 0; i < string_len; i++){ buff[i] = (unsigned int)string[i] - 48; } - printf("%s\n",string); - s_id->type = 0; for (int i = 0; i < 5; i++){ s_id->type += buff[i] ; diff --git a/list/list.c b/list/list.c index ff7ba19..b4c3abd 100644 --- a/list/list.c +++ b/list/list.c @@ -8,8 +8,15 @@ int safeModeForNode(int ifon) { if (ifon == 1) { 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."))); + 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."))); + return -1; + } list_list->head = NULL; list_list->length = 0; list_list->tail = NULL; @@ -81,6 +88,10 @@ 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."))); + return NULL; + } Node *prec_node = NULL; p_node->s_id = getS_id(LIST_NODE, 2); p_node->if_sid = 1; @@ -99,8 +110,12 @@ Node *initNode(void) { } List *initList(void) { - Node *p_node; + 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."))); + return NULL; + } p_list->s_id = getS_id(LIST, 1); p_list->if_sid = 1; p_list->head = NULL; diff --git a/stack/stack.c b/stack/stack.c index 66580bd..acaee3f 100644 --- a/stack/stack.c +++ b/stack/stack.c @@ -2,6 +2,10 @@ 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."))); + return NULL; + } p_stack->s_id = getS_id(STACK, 1); p_stack->length = 0; p_stack->top = NULL; @@ -10,6 +14,10 @@ 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."))); + return NULL; + } p_snode->s_id = getS_id(STACK_NODE, 2); p_snode->if_malloc = 0; p_snode->next = NULL; diff --git a/tree/tree.c b/tree/tree.c index bf5efd4..276304d 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -7,9 +7,16 @@ static int if_safeModeForTree = 0; int safeModeForTree(int ifon) { if (ifon == 1) { if (tnode_list == NULL && tree_list == NULL) { - tnode_list = (List *)malloc(sizeof(List)); + tnode_list = (List *)malloc(sizeof(List)); + if(tnode_list == NULL){ + showError(pushError(TREE_NODE, HIGH, initInfo("safeModeForTree()", "Error in get the memory of tnode_list."))); + return -1; + } tree_list = (List *)malloc(sizeof(List)); - + if(tree_list == NULL){ + showError(pushError(TREE_NODE, HIGH, initInfo("safeModeForTree()", "Error in get the memory of tree_list."))); + return -1; + } tree_list->head = NULL; tree_list->length = 0; tree_list->tail = NULL; @@ -31,6 +38,10 @@ int safeModeForTree(int ifon) { 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."))); + return NULL; + } p_tnode->s_id = getS_id(TREE_NODE, 2); p_tnode->if_sid = 1; p_tnode->child_num = 0; @@ -61,6 +72,10 @@ TNode *initTNode(void) { 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."))); + return NULL; + } p_tree->s_id = getS_id(TREE, 1); p_tree->if_sid = 1; p_tree->root = NULL; diff --git a/type/type.h b/type/type.h index 4be9d31..47f5cca 100644 --- a/type/type.h +++ b/type/type.h @@ -17,6 +17,7 @@ #define LIST_NODE 8 #define TREE_NODE 9 #define STACK_NODE 10 +#define T_SID 11 #define DEEPC 1 #define DEEPB 2