diff --git a/ZE-Standard-Libraries.xcodeproj/project.pbxproj b/ZE-Standard-Libraries.xcodeproj/project.pbxproj index 0d05af7..f464100 100644 --- a/ZE-Standard-Libraries.xcodeproj/project.pbxproj +++ b/ZE-Standard-Libraries.xcodeproj/project.pbxproj @@ -8,6 +8,15 @@ /* Begin PBXBuildFile section */ 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 */ /* Begin PBXCopyFilesBuildPhase section */ @@ -31,7 +40,20 @@ 9246995B20CE5C8900B4E894 /* stack_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack_expand.h; sourceTree = ""; }; 9246995D20CE655900B4E894 /* tree.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tree.h; sourceTree = ""; }; 9246995E20CE655900B4E894 /* tree.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = tree.c; sourceTree = ""; }; + 9269D4E7210F1B3D00161557 /* stack_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = stack_expand.c; sourceTree = ""; }; + 9269D4E9210F1B4B00161557 /* list_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = list_expand.c; sourceTree = ""; }; + 9269D4EB210F1B5E00161557 /* test.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = test.c; sourceTree = ""; }; + 9269D4EC210F1B5E00161557 /* test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = test.h; sourceTree = ""; }; + 9269D4F0210F1B8000161557 /* type.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = type.h; path = type/type.h; sourceTree = ""; }; + 9269D4F2210F1BB000161557 /* id.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = id.c; path = id/id.c; sourceTree = ""; }; + 9269D4F3210F1BB000161557 /* id.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = id.h; path = id/id.h; sourceTree = ""; }; + 9269D4F7210F1D0B00161557 /* tree_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tree_expand.c; sourceTree = ""; }; + 9269D4F9210F1D0F00161557 /* tree_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tree_expand.h; sourceTree = ""; }; 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 = ""; }; + 9286EB7F2114022F00752977 /* communicate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = communicate.h; path = communicate/communicate.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -50,6 +72,7 @@ children = ( 9246994F20CD000300B4E894 /* list.c */, 9246995020CD000300B4E894 /* list_expand.h */, + 9269D4E9210F1B4B00161557 /* list_expand.c */, 9246995120CD000300B4E894 /* list.h */, ); path = list; @@ -60,6 +83,7 @@ children = ( 9246995820CE52A700B4E894 /* stack.h */, 9246995920CE52A700B4E894 /* stack.c */, + 9269D4E7210F1B3D00161557 /* stack_expand.c */, 9246995B20CE5C8900B4E894 /* stack_expand.h */, ); path = stack; @@ -70,16 +94,41 @@ children = ( 9246995D20CE655900B4E894 /* tree.h */, 9246995E20CE655900B4E894 /* tree.c */, + 9269D4F9210F1D0F00161557 /* tree_expand.h */, + 9269D4F7210F1D0B00161557 /* tree_expand.c */, ); path = tree; sourceTree = ""; }; + 9269D4EF210F1B7800161557 /* type */ = { + isa = PBXGroup; + children = ( + 9269D4F0210F1B8000161557 /* type.h */, + ); + name = type; + sourceTree = ""; + }; + 9269D4F1210F1B9E00161557 /* id */ = { + isa = PBXGroup; + children = ( + 9269D4F2210F1BB000161557 /* id.c */, + 9269D4F3210F1BB000161557 /* id.h */, + ); + name = id; + sourceTree = ""; + }; 927993B420CB87D6008CE3A9 = { isa = PBXGroup; children = ( + 9286EB7C2114021E00752977 /* communicate */, + 9286EB78211400BD00752977 /* error */, + 9269D4F1210F1B9E00161557 /* id */, + 9269D4EF210F1B7800161557 /* type */, 9246995C20CE654600B4E894 /* tree */, 9246995720CE507900B4E894 /* stack */, 9246994E20CD000300B4E894 /* list */, + 9269D4EB210F1B5E00161557 /* test.c */, + 9269D4EC210F1B5E00161557 /* test.h */, 927993BE20CB87D6008CE3A9 /* Products */, ); sourceTree = ""; @@ -92,6 +141,24 @@ name = Products; sourceTree = ""; }; + 9286EB78211400BD00752977 /* error */ = { + isa = PBXGroup; + children = ( + 9286EB79211400C900752977 /* error.c */, + 9286EB7B211400D000752977 /* error.h */, + ); + name = error; + sourceTree = ""; + }; + 9286EB7C2114021E00752977 /* communicate */ = { + isa = PBXGroup; + children = ( + 9286EB7F2114022F00752977 /* communicate.h */, + 9286EB7D2114022A00752977 /* communicate.c */, + ); + name = communicate; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -148,7 +215,16 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 9269D4F6210F1CD900161557 /* stack.c in Sources */, + 9286EB7A211400C900752977 /* error.c in Sources */, + 9269D4E8210F1B3D00161557 /* stack_expand.c in Sources */, + 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 */, ); runOnlyForDeploymentPostprocessing = 0; }; 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 f56e272..c5081b3 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 = "554017478.314317" + timestampString = "554959944.593868" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "64" @@ -170,7 +170,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "tree/tree_expand.c" - timestampString = "554017478.3148969" + timestampString = "554638722.806551" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "60" diff --git a/communicate/communicate.c b/communicate/communicate.c index 97e91a1..32dc9ac 100644 --- a/communicate/communicate.c +++ b/communicate/communicate.c @@ -1,9 +1 @@ -// -// communicate.c -// ZE-Standard-Libraries -// -// Created by 胡一兵 on 2018/7/25. -// Copyright © 2018年 ZE. All rights reserved. -// - #include "communicate.h" diff --git a/communicate/communicate.h b/communicate/communicate.h index 4dde066..4798a3f 100644 --- a/communicate/communicate.h +++ b/communicate/communicate.h @@ -1,11 +1,3 @@ -// -// communicate.h -// ZE-Standard-Libraries -// -// Created by 胡一兵 on 2018/7/25. -// Copyright © 2018年 ZE. All rights reserved. -// - #ifndef communicate_h #define communicate_h diff --git a/error/error.c b/error/error.c index d3b8e66..f11f8b5 100644 --- a/error/error.c +++ b/error/error.c @@ -9,15 +9,13 @@ int initErrorSystem(void) { int setLogDirectory(const char *path) { logfile.id = getId(); - int memory_space = strlen(path) + 256; + unsigned long memory_space = strlen(path) + 256; char *file_path = (char *)malloc(sizeof(char)*memory_space); - //ļ· strcat(file_path, path); strcat(file_path, "log"); - sprintf(file_path, "%d", logfile.id); + sprintf(file_path, "%lu", logfile.id); - //ļ,ʧ,0 if ((logfile.fp = fopen(file_path, "w")) == NULL) { printf("Cannot set logfile!"); return 0; @@ -46,6 +44,7 @@ int closeLogDirectory(void) { if_error = 0; fclose(logfile.fp); logfile.if_enable = 0; + return 0; } int loadFromFile(FILE *fp,char* number) { @@ -58,6 +57,7 @@ int pushInfo(Info *p_info, const char *head, const char *body) { 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) { @@ -66,6 +66,7 @@ int pushError(unsigned int type, int pri, Info *p_info) { error.priority = pri; error.p_info = p_info; error.time = time(NULL); + return 0; } int pushNotice(unsigned int type, Info *p_info) { @@ -73,6 +74,7 @@ int pushNotice(unsigned int type, Info *p_info) { notice.type = type; notice.p_info = p_info; notice.time = time(NULL); + return 0; } static int saveError(Error *p_error) { @@ -87,6 +89,7 @@ static int saveError(Error *p_error) { %s\n\ ---------------------\n", p_error->type, p_error->priority, ctime( &(p_error->time) ), p_error->p_info->head, p_error->p_info->body); + return 0; } static int saveNotice(Notice *p_notice) { fprintf(logfile.fp, @@ -99,4 +102,5 @@ static int saveNotice(Notice *p_notice) { %s\n\ ----------------------\n", p_notice->type, ctime( &(p_notice->time) ), p_notice->p_info->head, p_notice->p_info->body); -} \ No newline at end of file + return 0; +} diff --git a/id/id.c b/id/id.c index 4836b92..7676809 100644 --- a/id/id.c +++ b/id/id.c @@ -173,7 +173,7 @@ 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[string_len - 1]; + unsigned int *buff = (unsigned int *) malloc(sizeof(string_len - 1)); for(int i = 0; i < string_len; i++){ buff[i] = string[i] - 48; } @@ -221,6 +221,7 @@ SID *asciiStringToS_id(const char *string){ (*s_id->value_deepest)[i] /= 10; } } + free(buff); return s_id; } diff --git a/list/list.c b/list/list.c index 2734d38..c392166 100644 --- a/list/list.c +++ b/list/list.c @@ -1,8 +1,8 @@ #include "list.h" static int if_safeModeForNode = 0; -static List *node_list = NULL; //储存声明过的节点. -static List *list_list = NULL; //储存声明过的链表. +static List *node_list = NULL; +static List *list_list = NULL; int safeModeForNode(int ifon) { if (ifon == 1) { diff --git a/list/list.h b/list/list.h index 461f669..c1f02e4 100644 --- a/list/list.h +++ b/list/list.h @@ -9,66 +9,61 @@ #include "../id/id.h" typedef struct Node{ - SID *s_id;//唯一标识符 + SID *s_id; void *value; - _Bool if_malloc;//记录是否已经初始化值 + _Bool if_malloc; _Bool if_sid; - unsigned int type;//记录值的类型 + unsigned int type; struct Node *next; struct Node *last; } Node; typedef struct List{ - SID *s_id;//唯一标识符 + SID *s_id; Node *head; Node *tail; - unsigned long long length;//链表长度 + unsigned long long length; } List; -int safeModeForNode(int ifon);//安全模式确保显式声明过的内存都会被释放 -int releaseSingleListForsafeModeForNode(List *p_list);//释放list_list -int releaseSingleNodeForsafeModeForNode(List *p_list);//释放node_list -int releaseAllForNode(void);//安全模式最后调用的函数 +int safeModeForNode(int ifon); +int releaseSingleListForsafeModeForNode(List *p_list); +int releaseSingleNodeForsafeModeForNode(List *p_list); +int releaseAllForNode(void); List *initList(void); Node *initNode(void); -int initMallocValueForNode(Node *,unsigned int,void *);//赋予已分配内存的值,并标明类型 +int initMallocValueForNode(Node *,unsigned int,void *); -/*插入函数*/ int insertInHead(List *p_list, Node *p_node); int insertInTail(List *p_list, Node *p_node); -/*交换函数*/ int exchangeLocation(Node *p_node,Node *t_node); -/*复制函数*/ Node *copyNode(Node *); -/*移除函数*/ int removeById(List *p_list, const 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);//查看链表的长度 +unsigned long long len(List *p_list); -Node *findByIdForNode(List *p_list, const SID *s_id);//通过id查找目标链表中的匹配节点 -Node *findByValue(List *p_list, unsigned int type, const void *value);//通过值来查找目标链表中的匹配节点 -List *mply_findByValue(List *p_list, unsigned int type, const void *value);//寻找多个值匹配的节点 +Node *findByIdForNode(List *p_list, const 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); -int releaseList(List *p_list);//释放List并可选择是否释放中所有的其中的Node -int releaseListForSingle(List *p_list);//单独释放List -int releaseNode(Node *p_node);//释放Node -int releaseOnlyNode(Node *p_node);//释放Node +int releaseList(List *p_list); +int releaseListForSingle(List *p_list); +int releaseNode(Node *p_node); +int releaseOnlyNode(Node *p_node); -int isListEmpty(List *p_list);//判断List是否为空 -List *copyList(List *p_list);//复制链表 +int isListEmpty(List *p_list); +List *copyList(List *p_list); -/*有关安全模式的变量*/ static int if_safeModeForNode; -static List *node_list; //储存声明过的节点. -static List *list_list; //储存声明过的链表. +static List *node_list; +static List *list_list; #endif \ No newline at end of file diff --git a/list/list_expand.h b/list/list_expand.h index fc6d10c..df331ab 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -1,42 +1,41 @@ #ifndef LIST_EXPAND_H #define LIST_EXPAND_H -#include "list.c" +#include "list.h" -Node *nodeWithInt(int);//快速初始化一个单一值节点并赋值 -Node *nodeWithDouble(double);//快速初始化一个节单一值点并赋值 -Node *nodeWithString(const char *);//快速初始化一个单一值节点并赋值 -Node *nodeWithPointer(void *);//快速初始化一个单一值节点并赋值 +Node *nodeWithInt(int); +Node *nodeWithDouble(double); +Node *nodeWithString(const char *); +Node *nodeWithPointer(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 *);//为复合节点添加一个特定类型的值 +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 *); -Node *findByIndexForNode(List *, unsigned long long);//根据位置查找一个节点 -Node *findByIntForNode(List *, int);//依照特定类型查找一个节点 -Node *findByDoubleForNode(List *, double);//依照特定类型查找一个节点 -Node *findByStringForNode(List *, char *);//依照特定类型查找一个节点 -Node *findByPointerForNode(List *, void *);//依照特定类型查找一个节点 +Node *findByIndexForNode(List *, unsigned long long); +Node *findByIntForNode(List *, int); +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 *m_findByIntForNode(List*, int); +List *m_findByDoubleForNode(List*, double); +List *m_findByStringForNode(List*, char *); +List *m_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 printListInfo(List *p_list,int priority); +void printNodeInfo(Node *p_node,int priority); +void printList(List *); +void printNode(Node *p_node); -int getByIntForNode(Node *);//直接得到节点的值 -double getByDoubleForNode(Node *);//直接得到节点的值 -char *getByStringForNode(Node *);//直接得到节点的值 -void *getByPointerForNode(Node *);//直接得到节点的值 +int getByIntForNode(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));//遍历链表并不断调用目标函数。目标函数将接受节点储存值的指针及其类型。 - +int listThrough(List *p_list, int (*p_func)(unsigned int type, void *value)); unsigned long long calListMemory(List *); #endif diff --git a/test.c b/test.c index c7a718b..8ce8cfe 100644 --- a/test.c +++ b/test.c @@ -84,7 +84,7 @@ int stack(void) { int main(int argc, char **argv) { //tree(); init_rand(); - SID *p_sid = getS_id(LIST_NODE, 3); + 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);