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 */