commit
d8ad8792f8
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
################################################################################
|
||||||
|
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
/Debug
|
||||||
|
/.vs/ZE-Standard-Libraries/v15
|
||||||
|
/ZE-Standard-Libraries
|
||||||
|
/ZE-Standard-Libraries.sln
|
||||||
|
/.vs
|
23
README.md
23
README.md
@ -1 +1,22 @@
|
|||||||
# ZE-Standard-Libraries
|
# ZE-Standard-Libraries
|
||||||
|
### --我们需要更快更方便的基于C语言的软件工程
|
||||||
|
|
||||||
|
## 简介
|
||||||
|
该函数库用于提供一些基础的数据结构的操作、运算、储存的函数,旨在加快基于C语言的软件工程的构建速度。运用该函数库提供的操作函数,可以省去工程中遇到的大量繁复的的高级数据结构的建构操作以及内存储存管理操作。
|
||||||
|
|
||||||
|
## 特性
|
||||||
|
- 函数库提供高级数据结构实体以及配套的多样的操作函数,开发者得以主要注意力集中在主要的功能实现上。
|
||||||
|
- 函数库提供相关函数,可以对高级数据结构快速进行基于文件的储存和基于网络的传输等工作。
|
||||||
|
- 函数库中构建的高级数据结构有唯一的识别码,很方便可以进行查找,替换操作。
|
||||||
|
- 函数库还提供工程的错误管理功能,使得开发者可以及时定位错误,或者让程序自动储存错误或者警告消息至文件。
|
||||||
|
|
||||||
|
## 分类
|
||||||
|
该函数库主要提供以下基本数据结构操作、运算和储存函数:
|
||||||
|
- 链表 list
|
||||||
|
- 词典 dict
|
||||||
|
- 树 tree
|
||||||
|
- 图 graph
|
||||||
|
- 栈 stack
|
||||||
|
- 信息 message
|
||||||
|
## 代码风格
|
||||||
|
本函数库秉承着可视性、稳定性与扩展性优先的原则,将在基本框架不变的情况下不断进行的优化。
|
||||||
|
391
ZE-Standard-Libraries.xcodeproj/project.pbxproj
Normal file
391
ZE-Standard-Libraries.xcodeproj/project.pbxproj
Normal file
@ -0,0 +1,391 @@
|
|||||||
|
// !$*UTF8*$!
|
||||||
|
{
|
||||||
|
archiveVersion = 1;
|
||||||
|
classes = {
|
||||||
|
};
|
||||||
|
objectVersion = 50;
|
||||||
|
objects = {
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
927993BB20CB87D6008CE3A9 /* CopyFiles */ = {
|
||||||
|
isa = PBXCopyFilesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
dstPath = /usr/share/man/man1/;
|
||||||
|
dstSubfolderSpec = 0;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 1;
|
||||||
|
};
|
||||||
|
/* End PBXCopyFilesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXFileReference section */
|
||||||
|
9246994F20CD000300B4E894 /* list.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list.c; sourceTree = "<group>"; };
|
||||||
|
9246995020CD000300B4E894 /* list_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list_expand.h; sourceTree = "<group>"; };
|
||||||
|
9246995120CD000300B4E894 /* list.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list.h; sourceTree = "<group>"; };
|
||||||
|
9246995820CE52A700B4E894 /* stack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack.h; sourceTree = "<group>"; };
|
||||||
|
9246995920CE52A700B4E894 /* stack.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = stack.c; sourceTree = "<group>"; };
|
||||||
|
9246995B20CE5C8900B4E894 /* stack_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack_expand.h; sourceTree = "<group>"; };
|
||||||
|
9246995D20CE655900B4E894 /* tree.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tree.h; sourceTree = "<group>"; };
|
||||||
|
9246995E20CE655900B4E894 /* tree.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = tree.c; sourceTree = "<group>"; };
|
||||||
|
9269D4E7210F1B3D00161557 /* stack_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = stack_expand.c; sourceTree = "<group>"; };
|
||||||
|
9269D4E9210F1B4B00161557 /* list_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = list_expand.c; sourceTree = "<group>"; };
|
||||||
|
9269D4EB210F1B5E00161557 /* test.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = test.c; sourceTree = "<group>"; };
|
||||||
|
9269D4EC210F1B5E00161557 /* test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = test.h; sourceTree = "<group>"; };
|
||||||
|
9269D4F0210F1B8000161557 /* type.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = type.h; path = type/type.h; sourceTree = "<group>"; };
|
||||||
|
9269D4F2210F1BB000161557 /* id.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = id.c; path = id/id.c; sourceTree = "<group>"; };
|
||||||
|
9269D4F3210F1BB000161557 /* id.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = id.h; path = id/id.h; sourceTree = "<group>"; };
|
||||||
|
9269D4F7210F1D0B00161557 /* tree_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tree_expand.c; sourceTree = "<group>"; };
|
||||||
|
9269D4F9210F1D0F00161557 /* tree_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tree_expand.h; sourceTree = "<group>"; };
|
||||||
|
927993BD20CB87D6008CE3A9 /* ZE-Standard-Libraries */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "ZE-Standard-Libraries"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
|
9286EB79211400C900752977 /* error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = error.c; path = error/error.c; sourceTree = "<group>"; };
|
||||||
|
9286EB7B211400D000752977 /* error.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = error.h; path = error/error.h; sourceTree = "<group>"; };
|
||||||
|
9286EB7D2114022A00752977 /* communicate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = communicate.c; path = communicate/communicate.c; sourceTree = "<group>"; };
|
||||||
|
9286EB7F2114022F00752977 /* communicate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = communicate.h; path = communicate/communicate.h; sourceTree = "<group>"; };
|
||||||
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
927993BA20CB87D6008CE3A9 /* Frameworks */ = {
|
||||||
|
isa = PBXFrameworksBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXFrameworksBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXGroup section */
|
||||||
|
9246994E20CD000300B4E894 /* list */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
9246994F20CD000300B4E894 /* list.c */,
|
||||||
|
9246995020CD000300B4E894 /* list_expand.h */,
|
||||||
|
9269D4E9210F1B4B00161557 /* list_expand.c */,
|
||||||
|
9246995120CD000300B4E894 /* list.h */,
|
||||||
|
);
|
||||||
|
path = list;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
9246995720CE507900B4E894 /* stack */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
9246995820CE52A700B4E894 /* stack.h */,
|
||||||
|
9246995920CE52A700B4E894 /* stack.c */,
|
||||||
|
9269D4E7210F1B3D00161557 /* stack_expand.c */,
|
||||||
|
9246995B20CE5C8900B4E894 /* stack_expand.h */,
|
||||||
|
);
|
||||||
|
path = stack;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
9246995C20CE654600B4E894 /* tree */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
9246995D20CE655900B4E894 /* tree.h */,
|
||||||
|
9246995E20CE655900B4E894 /* tree.c */,
|
||||||
|
9269D4F9210F1D0F00161557 /* tree_expand.h */,
|
||||||
|
9269D4F7210F1D0B00161557 /* tree_expand.c */,
|
||||||
|
);
|
||||||
|
path = tree;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
9269D4EF210F1B7800161557 /* type */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
9269D4F0210F1B8000161557 /* type.h */,
|
||||||
|
);
|
||||||
|
name = type;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
9269D4F1210F1B9E00161557 /* id */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
9269D4F2210F1BB000161557 /* id.c */,
|
||||||
|
9269D4F3210F1BB000161557 /* id.h */,
|
||||||
|
);
|
||||||
|
name = id;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
927993B420CB87D6008CE3A9 = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
92A15CFC211442C700826FB8 /* graph */,
|
||||||
|
9286EB7C2114021E00752977 /* communicate */,
|
||||||
|
9286EB78211400BD00752977 /* error */,
|
||||||
|
9269D4F1210F1B9E00161557 /* id */,
|
||||||
|
9269D4EF210F1B7800161557 /* type */,
|
||||||
|
9246995C20CE654600B4E894 /* tree */,
|
||||||
|
9246995720CE507900B4E894 /* stack */,
|
||||||
|
9246994E20CD000300B4E894 /* list */,
|
||||||
|
9269D4EB210F1B5E00161557 /* test.c */,
|
||||||
|
9269D4EC210F1B5E00161557 /* test.h */,
|
||||||
|
927993BE20CB87D6008CE3A9 /* Products */,
|
||||||
|
);
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
927993BE20CB87D6008CE3A9 /* Products */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
927993BD20CB87D6008CE3A9 /* ZE-Standard-Libraries */,
|
||||||
|
);
|
||||||
|
name = Products;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
9286EB78211400BD00752977 /* error */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
9286EB79211400C900752977 /* error.c */,
|
||||||
|
9286EB7B211400D000752977 /* error.h */,
|
||||||
|
);
|
||||||
|
name = error;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
9286EB7C2114021E00752977 /* communicate */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
9286EB7F2114022F00752977 /* communicate.h */,
|
||||||
|
9286EB7D2114022A00752977 /* communicate.c */,
|
||||||
|
);
|
||||||
|
name = communicate;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
92A15CFC211442C700826FB8 /* graph */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
);
|
||||||
|
name = graph;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
/* End PBXGroup section */
|
||||||
|
|
||||||
|
/* Begin PBXNativeTarget section */
|
||||||
|
927993BC20CB87D6008CE3A9 /* ZE-Standard-Libraries */ = {
|
||||||
|
isa = PBXNativeTarget;
|
||||||
|
buildConfigurationList = 927993C420CB87D6008CE3A9 /* Build configuration list for PBXNativeTarget "ZE-Standard-Libraries" */;
|
||||||
|
buildPhases = (
|
||||||
|
927993B920CB87D6008CE3A9 /* Sources */,
|
||||||
|
927993BA20CB87D6008CE3A9 /* Frameworks */,
|
||||||
|
927993BB20CB87D6008CE3A9 /* CopyFiles */,
|
||||||
|
);
|
||||||
|
buildRules = (
|
||||||
|
);
|
||||||
|
dependencies = (
|
||||||
|
);
|
||||||
|
name = "ZE-Standard-Libraries";
|
||||||
|
productName = "ZE-Standard-Libraries";
|
||||||
|
productReference = 927993BD20CB87D6008CE3A9 /* ZE-Standard-Libraries */;
|
||||||
|
productType = "com.apple.product-type.tool";
|
||||||
|
};
|
||||||
|
/* End PBXNativeTarget section */
|
||||||
|
|
||||||
|
/* Begin PBXProject section */
|
||||||
|
927993B520CB87D6008CE3A9 /* Project object */ = {
|
||||||
|
isa = PBXProject;
|
||||||
|
attributes = {
|
||||||
|
LastUpgradeCheck = 0940;
|
||||||
|
ORGANIZATIONNAME = ZE;
|
||||||
|
TargetAttributes = {
|
||||||
|
927993BC20CB87D6008CE3A9 = {
|
||||||
|
CreatedOnToolsVersion = 9.4;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
buildConfigurationList = 927993B820CB87D6008CE3A9 /* Build configuration list for PBXProject "ZE-Standard-Libraries" */;
|
||||||
|
compatibilityVersion = "Xcode 9.3";
|
||||||
|
developmentRegion = en;
|
||||||
|
hasScannedForEncodings = 0;
|
||||||
|
knownRegions = (
|
||||||
|
en,
|
||||||
|
);
|
||||||
|
mainGroup = 927993B420CB87D6008CE3A9;
|
||||||
|
productRefGroup = 927993BE20CB87D6008CE3A9 /* Products */;
|
||||||
|
projectDirPath = "";
|
||||||
|
projectRoot = "";
|
||||||
|
targets = (
|
||||||
|
927993BC20CB87D6008CE3A9 /* ZE-Standard-Libraries */,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
/* End PBXProject section */
|
||||||
|
|
||||||
|
/* Begin PBXSourcesBuildPhase section */
|
||||||
|
927993B920CB87D6008CE3A9 /* Sources */ = {
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
/* End PBXSourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin XCBuildConfiguration section */
|
||||||
|
927993C220CB87D6008CE3A9 /* Debug */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
|
CLANG_ANALYZER_NONNULL = YES;
|
||||||
|
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||||
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
|
||||||
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
|
CLANG_ENABLE_MODULES = YES;
|
||||||
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||||
|
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||||
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_COMMA = YES;
|
||||||
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||||
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
|
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||||
|
CLANG_WARN_EMPTY_BODY = YES;
|
||||||
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
|
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||||
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||||
|
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
|
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||||
|
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||||
|
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||||
|
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||||
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
|
CODE_SIGN_IDENTITY = "-";
|
||||||
|
COPY_PHASE_STRIP = NO;
|
||||||
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
|
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||||
|
ENABLE_TESTABILITY = YES;
|
||||||
|
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||||
|
GCC_DYNAMIC_NO_PIC = NO;
|
||||||
|
GCC_NO_COMMON_BLOCKS = YES;
|
||||||
|
GCC_OPTIMIZATION_LEVEL = 0;
|
||||||
|
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||||
|
"DEBUG=1",
|
||||||
|
"$(inherited)",
|
||||||
|
);
|
||||||
|
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||||
|
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||||
|
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||||
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
|
MACOSX_DEPLOYMENT_TARGET = 10.13;
|
||||||
|
MTL_ENABLE_DEBUG_INFO = YES;
|
||||||
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
|
SDKROOT = macosx;
|
||||||
|
};
|
||||||
|
name = Debug;
|
||||||
|
};
|
||||||
|
927993C320CB87D6008CE3A9 /* Release */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
|
CLANG_ANALYZER_NONNULL = YES;
|
||||||
|
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||||
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
|
||||||
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
|
CLANG_ENABLE_MODULES = YES;
|
||||||
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||||
|
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||||
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_COMMA = YES;
|
||||||
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||||
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
|
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||||
|
CLANG_WARN_EMPTY_BODY = YES;
|
||||||
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
|
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||||
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||||
|
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
|
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||||
|
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||||
|
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||||
|
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||||
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
|
CODE_SIGN_IDENTITY = "-";
|
||||||
|
COPY_PHASE_STRIP = NO;
|
||||||
|
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||||
|
ENABLE_NS_ASSERTIONS = NO;
|
||||||
|
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||||
|
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||||
|
GCC_NO_COMMON_BLOCKS = YES;
|
||||||
|
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||||
|
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||||
|
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||||
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
|
MACOSX_DEPLOYMENT_TARGET = 10.13;
|
||||||
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
|
SDKROOT = macosx;
|
||||||
|
};
|
||||||
|
name = Release;
|
||||||
|
};
|
||||||
|
927993C520CB87D6008CE3A9 /* Debug */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
CODE_SIGN_STYLE = Automatic;
|
||||||
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
};
|
||||||
|
name = Debug;
|
||||||
|
};
|
||||||
|
927993C620CB87D6008CE3A9 /* Release */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
CODE_SIGN_STYLE = Automatic;
|
||||||
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
};
|
||||||
|
name = Release;
|
||||||
|
};
|
||||||
|
/* End XCBuildConfiguration section */
|
||||||
|
|
||||||
|
/* Begin XCConfigurationList section */
|
||||||
|
927993B820CB87D6008CE3A9 /* Build configuration list for PBXProject "ZE-Standard-Libraries" */ = {
|
||||||
|
isa = XCConfigurationList;
|
||||||
|
buildConfigurations = (
|
||||||
|
927993C220CB87D6008CE3A9 /* Debug */,
|
||||||
|
927993C320CB87D6008CE3A9 /* Release */,
|
||||||
|
);
|
||||||
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
|
};
|
||||||
|
927993C420CB87D6008CE3A9 /* Build configuration list for PBXNativeTarget "ZE-Standard-Libraries" */ = {
|
||||||
|
isa = XCConfigurationList;
|
||||||
|
buildConfigurations = (
|
||||||
|
927993C520CB87D6008CE3A9 /* Debug */,
|
||||||
|
927993C620CB87D6008CE3A9 /* Release */,
|
||||||
|
);
|
||||||
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
|
};
|
||||||
|
/* End XCConfigurationList section */
|
||||||
|
};
|
||||||
|
rootObject = 927993B520CB87D6008CE3A9 /* Project object */;
|
||||||
|
}
|
7
ZE-Standard-Libraries.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
7
ZE-Standard-Libraries.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Workspace
|
||||||
|
version = "1.0">
|
||||||
|
<FileRef
|
||||||
|
location = "self:">
|
||||||
|
</FileRef>
|
||||||
|
</Workspace>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>IDEDidComputeMac32BitWarning</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
@ -0,0 +1,148 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<VariablesViewState
|
||||||
|
version = "1.0">
|
||||||
|
<ContextStates>
|
||||||
|
<ContextState
|
||||||
|
contextName = "init_node:list.h">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "list_list">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "listToSTD:communicate.c">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "(int *)p_node->value">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "releaseMalloc:list.h">
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "initS_id:id.c">
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "getByIntForNode:list_expand.c">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "(int *)p_node->value">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "listThrough:list_expand.c">
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "initStandardDBlocks:communicate.c">
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "dataForStandardDBlock:communicate.c">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "(int *)p_stdb->buff">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "insertInTail:list.h">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "node_list">
|
||||||
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "list_list">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "releaseNULLList:list.h">
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "asciiStringToS_id:id.c">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "buff[string_len-1]">
|
||||||
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "5 + i * 5 + j">
|
||||||
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "s_id->value[i]">
|
||||||
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "strlen(string)">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "_doStandardDBlockWrite:communicate.c">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "&p_stdb->blocks_num">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "dataFileReadOut:communicate.c">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "strlen(string_sid)">
|
||||||
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "(int *)content">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "_doStandardDataInfoWrite:communicate.c">
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "standardDataAddBlock:communicate.c">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "(int *)data">
|
||||||
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "(int *)p_stdb->buff">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "dataFileWriteIn:communicate.c">
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "freeS_id:id.c">
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "s_idToASCIIString:id.c">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "sizeof(char)">
|
||||||
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "buff[buff_count]">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "main:test.c">
|
||||||
|
<PersistentStrings>
|
||||||
|
<PersistentString
|
||||||
|
value = "(int *)p_node->value">
|
||||||
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "((STD_DATA *)(p_dfiler->pf_stdlst->head->value))->pd_blocklst">
|
||||||
|
</PersistentString>
|
||||||
|
<PersistentString
|
||||||
|
value = "strlen(string)">
|
||||||
|
</PersistentString>
|
||||||
|
</PersistentStrings>
|
||||||
|
</ContextState>
|
||||||
|
<ContextState
|
||||||
|
contextName = "init_list:list.h">
|
||||||
|
</ContextState>
|
||||||
|
</ContextStates>
|
||||||
|
</VariablesViewState>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>SchemeUserState</key>
|
||||||
|
<dict>
|
||||||
|
<key>ZE-Standard-Libraries.xcscheme</key>
|
||||||
|
<dict>
|
||||||
|
<key>orderHint</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
338
communicate/communicate.c
Normal file
338
communicate/communicate.c
Normal file
@ -0,0 +1,338 @@
|
|||||||
|
#include "communicate.h"
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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, 1);
|
||||||
|
return p_std;
|
||||||
|
}
|
||||||
|
|
||||||
|
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, type,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(&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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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->type, 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);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
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;
|
||||||
|
}*/
|
47
communicate/communicate.h
Normal file
47
communicate/communicate.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#ifndef communicate_h
|
||||||
|
#define communicate_h
|
||||||
|
|
||||||
|
#include "../type/type.h"
|
||||||
|
#include "../list/list_expand.h"
|
||||||
|
|
||||||
|
typedef struct message{
|
||||||
|
SID *p_sid;
|
||||||
|
time_t time;
|
||||||
|
char titile[16];
|
||||||
|
unsigned long size;
|
||||||
|
char content[0];
|
||||||
|
}MSG;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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 ,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);
|
||||||
|
|
||||||
|
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 *);
|
||||||
|
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 *);
|
||||||
|
|
||||||
|
#endif /* communicate_h */
|
81
error/error.c
Normal file
81
error/error.c
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
#include "error.h"
|
||||||
|
|
||||||
|
int initErrorSystem(void) {
|
||||||
|
error_list = initList();
|
||||||
|
notice_list = initList();
|
||||||
|
if_error = 1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int setLogDirectory(const char *path) {
|
||||||
|
logfile.id = getId();
|
||||||
|
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, "%lu", logfile.id);
|
||||||
|
|
||||||
|
if ((logfile.fp = fopen(file_path, "w")) == NULL) {
|
||||||
|
printf("Cannot set logfile!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
logfile.if_enable = 1;
|
||||||
|
|
||||||
|
free(file_path);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int closeLogDirectory(void) {
|
||||||
|
Node *p = error_list->head;
|
||||||
|
while (p != NULL) {
|
||||||
|
saveError(p->value);
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = notice_list->head;
|
||||||
|
while (p != NULL) {
|
||||||
|
saveNotice(p->value);
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseList(error_list);
|
||||||
|
releaseList(notice_list);
|
||||||
|
if_error = 0;
|
||||||
|
fclose(logfile.fp);
|
||||||
|
logfile.if_enable = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int loadFromFile(FILE *fp,char* number) {
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int saveError(Error *p_error) {
|
||||||
|
fprintf(logfile.fp,
|
||||||
|
"--------------------\n\
|
||||||
|
ERROR\n\
|
||||||
|
Type : %ud\n\
|
||||||
|
Priority : %d\n\
|
||||||
|
Time : %s\n\
|
||||||
|
Info : \n\
|
||||||
|
%s\n\
|
||||||
|
%s\n\
|
||||||
|
---------------------\n",
|
||||||
|
p_error->type, p_error->priority, ctime( &(p_error->time) ), p_error->info.head, p_error->info.body);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int saveNotice(Notice *p_notice) {
|
||||||
|
fprintf(logfile.fp,
|
||||||
|
"--------------------\n\
|
||||||
|
NOTICE\n\
|
||||||
|
Type : %ud\n\
|
||||||
|
Time : %s\n\
|
||||||
|
Info : \n\
|
||||||
|
%s\n\
|
||||||
|
%s\n\
|
||||||
|
----------------------\n",
|
||||||
|
p_notice->type, ctime( &(p_notice->time) ), p_notice->info.head, p_notice->info.body);
|
||||||
|
return 0;
|
||||||
|
}
|
22
error/error.h
Normal file
22
error/error.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef ERROR_H
|
||||||
|
#define ERROR_H
|
||||||
|
|
||||||
|
#include "../type/type.h"
|
||||||
|
#include "../list/list_expand.h"
|
||||||
|
|
||||||
|
Log logfile;
|
||||||
|
List *error_list = NULL;
|
||||||
|
List *notice_list = NULL;
|
||||||
|
int if_error = 0;
|
||||||
|
|
||||||
|
int initErrorSystem(void);
|
||||||
|
|
||||||
|
int setLogDirectory(const char *path);
|
||||||
|
int closeLogDirectory(void);
|
||||||
|
|
||||||
|
int loadFromFile(FILE *fp,char* number);
|
||||||
|
|
||||||
|
int saveError(Error *p_error);
|
||||||
|
int saveNotice(Notice *p_notice);
|
||||||
|
|
||||||
|
#endif
|
1
graph/graph.c
Normal file
1
graph/graph.c
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "graph.h"
|
24
graph/graph.h
Normal file
24
graph/graph.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef GRAPH_H
|
||||||
|
#define GRAPH_H
|
||||||
|
|
||||||
|
#include "../list/list_expand.h"
|
||||||
|
|
||||||
|
typedef struct GNode{
|
||||||
|
SID *s_id;
|
||||||
|
void *value;
|
||||||
|
List *routes;
|
||||||
|
int if_setValue;
|
||||||
|
}GNode;
|
||||||
|
|
||||||
|
typedef struct route{
|
||||||
|
SID *s_id;
|
||||||
|
double distance;
|
||||||
|
int if_setValue;
|
||||||
|
GNode from, to;
|
||||||
|
}Route;
|
||||||
|
|
||||||
|
GNode *initGNode(void);
|
||||||
|
Route *initRoute(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
253
id/id.c
Normal file
253
id/id.c
Normal file
@ -0,0 +1,253 @@
|
|||||||
|
#include "id.h"
|
||||||
|
|
||||||
|
void init_rand(void) {
|
||||||
|
srand((unsigned)time(NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long long getId(void) {
|
||||||
|
int i;
|
||||||
|
unsigned long long id = 0;
|
||||||
|
id = ((rand() % 9) + 1);
|
||||||
|
for (i = 0; i < 15; i++) {
|
||||||
|
id *= 10;
|
||||||
|
id += rand() % 10;
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
SID *getS_id(unsigned int type, unsigned int deep_level){
|
||||||
|
SID *p_sid = initS_id(deep_level);
|
||||||
|
p_sid->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 simFitS_id(const SID *fs_id, const SID *ss_id){
|
||||||
|
return !fitS_id(fs_id, ss_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *s_idToASCIIString(const SID *s_id){
|
||||||
|
char *string = NULL;
|
||||||
|
int deep_len = 0, temp, buff_count, string_count;
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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;
|
||||||
|
for (int i = 0; i < DATA_BIT; i++) buff[i] = 0;
|
||||||
|
while(buff_count >= 0){
|
||||||
|
buff[buff_count] = temp % 10;
|
||||||
|
string[buff_count] = buff[buff_count] + 48;
|
||||||
|
temp /= 10;
|
||||||
|
buff_count--;
|
||||||
|
}
|
||||||
|
deep_len -= DATA_BIT;
|
||||||
|
for(int i = 0; i < DEEPC_LEN; 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;
|
||||||
|
while (buff_count >= 0) {
|
||||||
|
buff[buff_count] = temp % 10;
|
||||||
|
temp /= 10;
|
||||||
|
buff_count--;
|
||||||
|
}
|
||||||
|
for(int i = DATA_BIT - 1; i >= 0; i--) string[string_count + i] = buff[i] + 48;
|
||||||
|
}
|
||||||
|
deep_len -= DEEPC_LEN * DATA_BIT;
|
||||||
|
if(deep_len > 0)
|
||||||
|
for(int i = 0; i < DEEPB_LEN; 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;
|
||||||
|
while (buff_count >= 0) {
|
||||||
|
buff[buff_count] = temp % 10;
|
||||||
|
temp /= 10;
|
||||||
|
buff_count--;
|
||||||
|
}
|
||||||
|
for(int i = DATA_BIT - 1; i >= 0; i--) string[string_count + i] = buff[i] + 48;
|
||||||
|
}
|
||||||
|
|
||||||
|
deep_len -= DEEPB_LEN * DATA_BIT;
|
||||||
|
if(deep_len > 0)
|
||||||
|
for(int i = 0; i < DEEPA_LEN; 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;
|
||||||
|
while (buff_count >= 0) {
|
||||||
|
buff[buff_count] = temp % 10;
|
||||||
|
string[string_count] = buff[buff_count] + 48;
|
||||||
|
temp /= 10;
|
||||||
|
buff_count--;
|
||||||
|
}
|
||||||
|
for(int i = DATA_BIT - 1; i >= 0; i--) string[string_count + i] = buff[i] + 48;
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
SID *asciiStringToS_id(const char *string){
|
||||||
|
SID *s_id = NULL;
|
||||||
|
unsigned long long string_len = strlen(string);
|
||||||
|
|
||||||
|
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));
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
s_id->type = 0;
|
||||||
|
for (int i = 0; i < 5; i++){
|
||||||
|
s_id->type += buff[i] ;
|
||||||
|
s_id->type *= 10u;
|
||||||
|
}
|
||||||
|
s_id->type /= 10u;
|
||||||
|
|
||||||
|
if (string_len >= 25){
|
||||||
|
for(int i = 0; i < DEEPC_LEN; i++){
|
||||||
|
s_id->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string_len >= 65){
|
||||||
|
for(int i = 0; i < DEEPB_LEN; i++){
|
||||||
|
s_id->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (string_len >= 225){
|
||||||
|
for(int i = 0; i < DEEPA_LEN; i++){
|
||||||
|
s_id->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(buff);
|
||||||
|
return s_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
free(s_id);
|
||||||
|
return 0;
|
||||||
|
}
|
24
id/id.h
Normal file
24
id/id.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef id_h
|
||||||
|
#define id_h
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "../type/type.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);
|
||||||
|
|
||||||
|
char *s_idToASCIIString(const SID *s_id);
|
||||||
|
SID *asciiStringToS_id(const char *string);
|
||||||
|
|
||||||
|
SID *initS_id(unsigned int deep_level);
|
||||||
|
int freeS_id(SID *s_id);
|
||||||
|
|
||||||
|
#endif /* id_h */
|
567
list/list.c
Normal file
567
list/list.c
Normal file
@ -0,0 +1,567 @@
|
|||||||
|
#include "list.h"
|
||||||
|
|
||||||
|
static int if_safeModeForNode = 0;
|
||||||
|
static List *node_list = NULL;
|
||||||
|
static List *list_list = NULL;
|
||||||
|
|
||||||
|
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 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 getting the memory of list_list.")));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
list_list->head = NULL;
|
||||||
|
list_list->length = 0;
|
||||||
|
list_list->tail = NULL;
|
||||||
|
|
||||||
|
node_list->head = NULL;
|
||||||
|
node_list->length = 0;
|
||||||
|
node_list->tail = NULL;
|
||||||
|
|
||||||
|
if_safeModeForNode = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ifon;
|
||||||
|
}
|
||||||
|
|
||||||
|
int releaseSingleListForsafeModeForNode(List *p_list) {
|
||||||
|
Node *p_node = p_list->head;
|
||||||
|
List *plv_node = NULL;
|
||||||
|
while (p_node != NULL) {
|
||||||
|
plv_node = (List *)p_node->value;
|
||||||
|
freeS_id(plv_node->s_id);
|
||||||
|
plv_node->head = NULL;
|
||||||
|
plv_node->length = 0;
|
||||||
|
plv_node->tail = NULL;
|
||||||
|
free(plv_node);
|
||||||
|
p_node = p_node->next;
|
||||||
|
}
|
||||||
|
p_list->head = NULL;
|
||||||
|
p_list->length = 0;
|
||||||
|
p_list->tail = NULL;
|
||||||
|
freeS_id(p_list->s_id);
|
||||||
|
free(p_list);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int releaseSingleNodeForsafeModeForNode(List *p_list) {
|
||||||
|
Node *p_node = p_list->head;
|
||||||
|
Node *pnv_node = NULL;
|
||||||
|
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;
|
||||||
|
pnv_node->value = NULL;
|
||||||
|
free(pnv_node);
|
||||||
|
p_node = p_node->next;
|
||||||
|
}
|
||||||
|
free(p_list->s_id);
|
||||||
|
p_list->head = NULL;
|
||||||
|
p_list->length = 0;
|
||||||
|
p_list->tail = NULL;
|
||||||
|
free(p_list);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int releaseAllForNode(void) {
|
||||||
|
if (if_safeModeForNode == 1) {
|
||||||
|
if_safeModeForNode = 0;
|
||||||
|
releaseSingleNodeForsafeModeForNode(node_list);
|
||||||
|
releaseSingleListForsafeModeForNode(list_list);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node *initNode(void) {
|
||||||
|
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;
|
||||||
|
p_node->next = NULL;
|
||||||
|
p_node->last = NULL;
|
||||||
|
p_node->type = VOID;
|
||||||
|
if (if_safeModeForNode) {
|
||||||
|
if_safeModeForNode = 0;
|
||||||
|
prec_node = initNode();
|
||||||
|
if_safeModeForNode = 1;
|
||||||
|
initMallocValueForNode(prec_node, POINTER, (void *)p_node);
|
||||||
|
insertInTail(node_list, prec_node);
|
||||||
|
}
|
||||||
|
return p_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 getting the memory of list.")));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
if (if_safeModeForNode) {
|
||||||
|
if_safeModeForNode = 0;
|
||||||
|
p_node = initNode();
|
||||||
|
if_safeModeForNode = 1;
|
||||||
|
initMallocValueForNode(p_node, POINTER, (void *)p_list);
|
||||||
|
insertInTail(list_list, p_node);
|
||||||
|
}
|
||||||
|
return p_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
int insertInHead(List *p_list, Node *p_node) {
|
||||||
|
if (isListEmpty(p_list)) {
|
||||||
|
p_list->head = p_node;
|
||||||
|
p_list->tail = p_node;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p_list->head->last = p_node;
|
||||||
|
p_node->last = NULL;
|
||||||
|
p_node->next = p_list->head;
|
||||||
|
p_list->head = p_node;
|
||||||
|
}
|
||||||
|
p_list->length += 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int insertInTail(List *p_list, Node *p_node) {
|
||||||
|
if (isListEmpty(p_list)) {
|
||||||
|
p_list->head = p_node;
|
||||||
|
p_list->tail = p_node;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p_list->tail->next = p_node;
|
||||||
|
p_node->next = NULL;
|
||||||
|
p_node->last = p_list->tail;
|
||||||
|
p_list->tail = p_node;
|
||||||
|
}
|
||||||
|
p_list->length += 1;
|
||||||
|
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->type != POINTER) {
|
||||||
|
if (p_node->type == LIST) {
|
||||||
|
releaseList((List *)p_node->value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
free(p_node->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 releaseList(List *p_list) {
|
||||||
|
Node *p_node, *pl_node;
|
||||||
|
p_node = p_list->head;
|
||||||
|
if (if_safeModeForNode == 1) {
|
||||||
|
Node *tar_list = findByValue(list_list, POINTER, (void *)p_list);//turn pointer in to int to compare.
|
||||||
|
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;
|
||||||
|
releaseNode(pl_node);
|
||||||
|
}
|
||||||
|
p_list->head = NULL;
|
||||||
|
p_list->tail = NULL;
|
||||||
|
p_list->length = 0;
|
||||||
|
freeS_id(p_list->s_id);
|
||||||
|
free(p_list);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int releaseListForSingle(List *p_list) {
|
||||||
|
p_list->head = NULL;
|
||||||
|
p_list->tail = NULL;
|
||||||
|
freeS_id(p_list->s_id);
|
||||||
|
p_list->length = 0;
|
||||||
|
free(p_list);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long long len(List *p_list) {
|
||||||
|
return p_list->length;
|
||||||
|
}
|
||||||
|
|
||||||
|
int removeById(List *p_list, const SID *s_id) {
|
||||||
|
Node *tmp = p_list->head;
|
||||||
|
if (isListEmpty(p_list))
|
||||||
|
return -1;
|
||||||
|
do {
|
||||||
|
if (simFitS_id(tmp->s_id, s_id)) {
|
||||||
|
if (tmp != p_list->head) {
|
||||||
|
tmp->last->next = tmp->next;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p_list->head = tmp->next;
|
||||||
|
}
|
||||||
|
if (tmp != p_list->tail) {
|
||||||
|
tmp->next->last = tmp->last;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p_list->tail = tmp->last;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_list->length -= 1;
|
||||||
|
return 1;//found
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
} while (tmp != NULL);
|
||||||
|
|
||||||
|
return 0;//not find
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
} while (tmp != NULL);
|
||||||
|
|
||||||
|
return 0;//not find
|
||||||
|
}
|
||||||
|
|
||||||
|
int popFromHead(List *p_list) {
|
||||||
|
if (isListEmpty(p_list))
|
||||||
|
return -1;
|
||||||
|
else {
|
||||||
|
//Node *tmp = p_list->head;
|
||||||
|
p_list->head->next->last = NULL;
|
||||||
|
p_list->head = p_list->head->next;
|
||||||
|
//releaseNode(tmp); not necessary
|
||||||
|
p_list->length -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isListEmpty(p_list)) {
|
||||||
|
p_list->head = NULL;
|
||||||
|
p_list->tail = NULL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int popFromTail(List *p_list) {
|
||||||
|
if (isListEmpty(p_list))
|
||||||
|
return -1;
|
||||||
|
else {
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node *findByIdForNode(List *p_list, const SID *s_id) {
|
||||||
|
Node *ph_node = p_list->head;
|
||||||
|
Node *pt_node = p_list->tail;
|
||||||
|
int direction = 0;
|
||||||
|
while (ph_node != pt_node) {
|
||||||
|
if (direction == 0) {
|
||||||
|
if (simFitS_id(ph_node->s_id, s_id)) {
|
||||||
|
return ph_node;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ph_node = ph_node->next;
|
||||||
|
}
|
||||||
|
direction = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (simFitS_id(pt_node->s_id, s_id)) {
|
||||||
|
return pt_node;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pt_node = pt_node->last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Node *findByValue(List *p_list, unsigned int type, const void *value) {
|
||||||
|
Node *p_node = p_list->head;
|
||||||
|
while (p_node != NULL) {
|
||||||
|
if (p_node->type != type) {
|
||||||
|
p_node = p_node->next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (type == INT) {
|
||||||
|
if (*((int *)p_node->value) == *((int *)value)) {
|
||||||
|
return copyNode(p_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == DOUBLE) {
|
||||||
|
if (*((double *)p_node->value) == *((double *)value)) {
|
||||||
|
return copyNode(p_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == STRING) {
|
||||||
|
if (!strcmp((char *)p_node->value, (char *)value))
|
||||||
|
{
|
||||||
|
return copyNode(p_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == POINTER) {
|
||||||
|
if (p_node->value == value) {
|
||||||
|
return copyNode(p_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p_node = p_node->next;
|
||||||
|
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
List *mply_findByValue(List *p_list, unsigned int type, const void *value) {
|
||||||
|
List *f_list = initList();
|
||||||
|
Node *p_node = p_list->head;
|
||||||
|
while (p_node != NULL) {
|
||||||
|
if (p_node->type != type) {
|
||||||
|
p_node = p_node->next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (type == INT) {
|
||||||
|
if (*((int *)p_node->value) == *((int *)value)) {
|
||||||
|
Node *f_node = copyNode(p_node);
|
||||||
|
insertInTail(f_list, f_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == DOUBLE) {
|
||||||
|
if (*((double *)p_node->value) == *((double *)value)) {
|
||||||
|
Node *f_node = copyNode(p_node);
|
||||||
|
insertInTail(f_list, f_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == STRING) {
|
||||||
|
if (!strcmp((char *)p_node->value, (char *)value))
|
||||||
|
{
|
||||||
|
Node *f_node = copyNode(p_node);
|
||||||
|
insertInTail(f_list, f_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == POINTER) {
|
||||||
|
if (p_node->value == value) {
|
||||||
|
Node *f_node = copyNode(p_node);
|
||||||
|
insertInTail(f_list, f_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p_node = p_node->next;
|
||||||
|
|
||||||
|
}
|
||||||
|
return f_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
int isListEmpty(List *p_list) {
|
||||||
|
if (p_list->head == NULL || p_list->tail == NULL)// If its head or tail is NULL,it would be thought as empty.
|
||||||
|
return 1; // But we should ensure that both of them are NULL when we
|
||||||
|
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();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
List *copyList(List *p_list) {
|
||||||
|
Node *p_node;
|
||||||
|
Node *t_node;
|
||||||
|
List *t_list = initList();
|
||||||
|
t_list->head = p_list->head;
|
||||||
|
t_list->tail = p_list->tail;
|
||||||
|
t_list->s_id = p_list->s_id;
|
||||||
|
p_node = p_list->head;
|
||||||
|
while (p_node != NULL) {
|
||||||
|
t_node = copyNode(p_node);
|
||||||
|
insertInTail(t_list, t_node);
|
||||||
|
p_node = p_node->next;
|
||||||
|
}
|
||||||
|
return t_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
int releaseOnlyNode(Node *p_node) {
|
||||||
|
freeS_id(p_node->s_id);
|
||||||
|
p_node->if_malloc = 0;
|
||||||
|
p_node->last = NULL;
|
||||||
|
p_node->next = NULL;
|
||||||
|
p_node->type = VOID;
|
||||||
|
p_node->value = NULL;
|
||||||
|
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;
|
||||||
|
}
|
58
list/list.h
Normal file
58
list/list.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#ifndef LIST_H
|
||||||
|
#define LIST_H
|
||||||
|
#include "../type/type.h"
|
||||||
|
#include "../id/id.h"
|
||||||
|
|
||||||
|
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,const 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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
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;
|
||||||
|
|
||||||
|
#endif
|
475
list/list_expand.c
Normal file
475
list/list_expand.c
Normal file
@ -0,0 +1,475 @@
|
|||||||
|
#include "list_expand.h"
|
||||||
|
|
||||||
|
Node *nodeWithInt(int m_int) {
|
||||||
|
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.")));
|
||||||
|
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));
|
||||||
|
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);
|
||||||
|
return p_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node *nodeWithString(const char *m_string) {
|
||||||
|
Node *p_node;
|
||||||
|
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(const void *m_pointer) {
|
||||||
|
Node *p_node = initNode();
|
||||||
|
initMallocValueForNode(p_node, POINTER, m_pointer);
|
||||||
|
return p_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node *nodeWithComplex(void) {
|
||||||
|
Node *p_node = initNode();
|
||||||
|
p_node->type = LIST;
|
||||||
|
p_node->value = initList();
|
||||||
|
p_node->if_malloc = 1;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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 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) {
|
||||||
|
if (p_node->type == STRING) return (char *)(p_node->value);
|
||||||
|
else return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
double getByDoubleForNode(Node *p_node) {
|
||||||
|
if (p_node->type == DOUBLE) return *(double *)(p_node->value);
|
||||||
|
else return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *getByPointerForNode(Node *p_node) {
|
||||||
|
if (p_node->type == POINTER) return (void *)(p_node->value);
|
||||||
|
else return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printListInfo(List *p_list, int priority) {
|
||||||
|
int i = 0;
|
||||||
|
Node *p_node;
|
||||||
|
for (i = 0; i < priority; i++) printf(" ");
|
||||||
|
printf("###LIST(location:%p, id:%s){\n", p_list, s_idToASCIIString(p_list->s_id));
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("HEAD->%p / Tail->%p / Length:%llu\n", p_list->head, p_list->tail, p_list->length);
|
||||||
|
p_node = p_list->head;
|
||||||
|
while (p_node != NULL) {
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("%d.... \n", i);
|
||||||
|
printNodeInfo(p_node, priority + 1);
|
||||||
|
p_node = p_node->next;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
for (i = 0; i < priority; i++) printf(" ");
|
||||||
|
printf("}\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void printList(List *p_list) {
|
||||||
|
int if_nearLast = 0;
|
||||||
|
Node *p_node = p_list->head;
|
||||||
|
printf("[");
|
||||||
|
while (p_node != NULL) {
|
||||||
|
if (!if_nearLast && p_node->next == NULL) if_nearLast = 1;
|
||||||
|
if (p_node->type == INT) {
|
||||||
|
printf("%d", *(int *)(p_node->value));
|
||||||
|
}
|
||||||
|
else if (p_node->type == DOUBLE) {
|
||||||
|
printf("%a", *(double *)(p_node->value));
|
||||||
|
}
|
||||||
|
else if (p_node->type == STRING) {
|
||||||
|
printf("%s", (char *)(p_node->value));
|
||||||
|
}
|
||||||
|
else if (p_node->type == POINTER) {
|
||||||
|
printf("%p", (char *)(p_node->value));
|
||||||
|
}
|
||||||
|
else if (p_node->type == LIST) {
|
||||||
|
printList((List *)p_node->value);
|
||||||
|
}
|
||||||
|
if (!if_nearLast) {
|
||||||
|
printf(", ");
|
||||||
|
}
|
||||||
|
p_node = p_node->next;
|
||||||
|
}
|
||||||
|
printf("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
void printNodeInfo(Node *p_node, int priority) {
|
||||||
|
int i;
|
||||||
|
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);
|
||||||
|
if (p_node->type == INT) {
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("VALUE(int):%d\n", *(int *)(p_node->value));
|
||||||
|
}
|
||||||
|
else if (p_node->type == DOUBLE) {
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("VALUE(double):%a\n", *(double *)(p_node->value));
|
||||||
|
}
|
||||||
|
else if (p_node->type == STRING) {
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("VALUE(string):%s\n", (char *)(p_node->value));
|
||||||
|
}
|
||||||
|
else if (p_node->type == POINTER) {
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("VALUE(pointer):%s\n", (char *)(p_node->value));
|
||||||
|
}
|
||||||
|
else if (p_node->type == LIST) {
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("VALUE(List):\n");
|
||||||
|
printListInfo((List *)p_node->value, priority + 2);
|
||||||
|
}
|
||||||
|
for (i = 0; i < priority; i++) printf(" ");
|
||||||
|
printf("}\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void printNode(Node *p_node) {
|
||||||
|
int i;
|
||||||
|
printf("#NODE(location:%p, id:%s){\n", p_node, s_idToASCIIString(p_node->s_id));
|
||||||
|
printf(" ");
|
||||||
|
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) {
|
||||||
|
printf("YES\n");
|
||||||
|
for (i = 0; i < 1; i++) printf(" ");
|
||||||
|
printf("Value(type: %d): ", p_node->type);
|
||||||
|
if (p_node->type == INT) {
|
||||||
|
printf("%d", *(int *)(p_node->value));
|
||||||
|
}
|
||||||
|
else if (p_node->type == DOUBLE) {
|
||||||
|
printf("%a\n", *(double *)(p_node->value));
|
||||||
|
}
|
||||||
|
else if (p_node->type == STRING) {
|
||||||
|
printf("%s\n", (char *)(p_node->value));
|
||||||
|
}
|
||||||
|
else if (p_node->type == POINTER) {
|
||||||
|
printf("%p\n", (char *)(p_node->value));
|
||||||
|
}
|
||||||
|
else if (p_node->type == LIST) {
|
||||||
|
printList((List *)p_node->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else printf("NO\n");
|
||||||
|
|
||||||
|
printf("}\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Node *findByIntForNode(List *p_list, int target) {
|
||||||
|
Node *t_node;
|
||||||
|
int *p_target = (int *)malloc(sizeof(int));
|
||||||
|
*p_target = target;
|
||||||
|
t_node = findByValue(p_list, INT, p_target);
|
||||||
|
free(p_target);
|
||||||
|
return t_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node *findByDoubleForNode(List *p_list, double target) {
|
||||||
|
Node *t_node;
|
||||||
|
double *p_target = (double *)malloc(sizeof(double));
|
||||||
|
*p_target = target;
|
||||||
|
t_node = findByValue(p_list, DOUBLE, p_target);
|
||||||
|
free(p_target);
|
||||||
|
return t_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node *findByStringForNode(List *p_list, char *target) {
|
||||||
|
Node *t_node;
|
||||||
|
char *p_temp = (char *)malloc(sizeof(char)*(strlen(target) + 1));
|
||||||
|
strcpy(p_temp, target);
|
||||||
|
t_node = findByValue(p_list, STRING, p_temp);
|
||||||
|
free(p_temp);
|
||||||
|
return t_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node *findByPointerForNode(List *p_list, void *target) {
|
||||||
|
Node *t_node = findByValue(p_list, POINTER, target);
|
||||||
|
return t_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
int addValueForComplex(Node * p_node, int type, void *value) {
|
||||||
|
List *c_list;
|
||||||
|
Node *c_node;
|
||||||
|
if (p_node->type == LIST) {
|
||||||
|
c_list = (List *)p_node->value;
|
||||||
|
c_node = initNode();
|
||||||
|
initMallocValueForNode(c_node, type, value);
|
||||||
|
insertInTail(c_list, c_node);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int addIntForComplex(Node *p_node, int temp) {
|
||||||
|
if (p_node->type == LIST) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int addDoubleForComplex(Node *p_node, double temp) {
|
||||||
|
if (p_node->type == LIST) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int addStringForComplex(Node *p_node, char *temp) {
|
||||||
|
if (p_node->type == LIST) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int addPointerForComplex(Node *p_node, void *temp) {
|
||||||
|
if (p_node->type == LIST) {
|
||||||
|
addValueForComplex(p_node, POINTER, temp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
List *m_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.")));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
List *t_list;
|
||||||
|
*p_temp = temp;
|
||||||
|
t_list = mply_findByValue(p_list, INT, (void *)p_temp);
|
||||||
|
free(p_temp);
|
||||||
|
return t_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
List *m_findByDouble(List* p_list, double temp) {
|
||||||
|
List *t_list;
|
||||||
|
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);
|
||||||
|
return t_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
List *m_findByString(List* p_list, char *temp) {
|
||||||
|
List *t_list;
|
||||||
|
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);
|
||||||
|
return t_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
List *m_findByPointer(List* p_list, void *temp) {
|
||||||
|
List *t_list = mply_findByValue(p_list, DOUBLE, (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;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
List *m_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.")));
|
||||||
|
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));
|
||||||
|
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));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
List *m_findByPointerForNode(List* p_list, void *temp) {
|
||||||
|
return mply_findByValue(p_list, POINTER, (void *)temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long long calListMemory(List * p_list){
|
||||||
|
Node *p_node = p_list->head;
|
||||||
|
unsigned long long nodes_size = 0LL;
|
||||||
|
unsigned long long list_size = sizeof(p_list);
|
||||||
|
while(p_node != NULL){
|
||||||
|
nodes_size += sizeof(p_node);
|
||||||
|
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;
|
||||||
|
}
|
50
list/list_expand.h
Normal file
50
list/list_expand.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#ifndef LIST_EXPAND_H
|
||||||
|
#define LIST_EXPAND_H
|
||||||
|
|
||||||
|
#include "list.h"
|
||||||
|
|
||||||
|
Node *nodeWithInt(int);
|
||||||
|
Node *nodeWithUInt(unsigned int);
|
||||||
|
Node *nodeWithDouble(double);
|
||||||
|
Node *nodeWithString(const char *);
|
||||||
|
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 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);
|
||||||
|
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 *);
|
||||||
|
|
||||||
|
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 *);
|
||||||
|
unsigned int getByUIntForNode(Node *);
|
||||||
|
double getByDoubleForNode(Node *);
|
||||||
|
char *getByStringForNode(Node *);
|
||||||
|
void *getByPointerForNode(Node *);
|
||||||
|
unsigned long long getIndexByNode(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 *);
|
||||||
|
|
||||||
|
#endif
|
76
stack/stack.c
Normal file
76
stack/stack.c
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include "stack.h"
|
||||||
|
|
||||||
|
Stack *initStack(void) {
|
||||||
|
Stack *p_stack = (Stack *)malloc(sizeof(Stack));
|
||||||
|
if(p_stack == NULL){
|
||||||
|
showError(pushError(STACK, STANDARD, initInfo("initStack()", "Error in getting the memory of stack.")));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
p_stack->s_id = getS_id(STACK, 1);
|
||||||
|
p_stack->length = 0;
|
||||||
|
p_stack->top = NULL;
|
||||||
|
return p_stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode *initSNode(void) {
|
||||||
|
SNode *p_snode = (SNode *)malloc(sizeof(SNode));
|
||||||
|
if(p_snode == NULL){
|
||||||
|
showError(pushError(STACK_NODE, STANDARD, initInfo("initSNode()", "Error in getting the memory of snode.")));
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode *popStack(Stack *p_stack) {
|
||||||
|
if (p_stack->top != NULL) {
|
||||||
|
SNode *p_snode = p_stack->top;
|
||||||
|
p_stack->top = p_snode->next;
|
||||||
|
p_snode->next = NULL;
|
||||||
|
p_stack->length -= 1;
|
||||||
|
return p_snode;
|
||||||
|
}
|
||||||
|
else return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pushStack(Stack *p_stack, SNode *p_snode) {
|
||||||
|
SNode *pn_snode = p_stack->top;
|
||||||
|
p_stack->top = p_snode;
|
||||||
|
p_snode->next = pn_snode;
|
||||||
|
p_stack->length -= 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int releaseStack(Stack *p_stack) {
|
||||||
|
SNode *p_sndoe = p_stack->top;
|
||||||
|
while (p_sndoe != NULL) {
|
||||||
|
SNode *pl_snode = p_sndoe;
|
||||||
|
p_sndoe = p_sndoe->next;
|
||||||
|
releaseSNode(pl_snode);
|
||||||
|
}
|
||||||
|
freeS_id(p_stack->s_id);
|
||||||
|
p_stack->top = NULL;
|
||||||
|
p_stack->length = 0;
|
||||||
|
free(p_stack);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
16
stack/stack.h
Normal file
16
stack/stack.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef STACK_H
|
||||||
|
#define STACK_H
|
||||||
|
#include "../type/type.h"
|
||||||
|
#include "../list/list_expand.h"
|
||||||
|
|
||||||
|
Stack *initStack(void);
|
||||||
|
SNode *initSNode(void);
|
||||||
|
int initMallocValueForSNode(SNode *p_snode, unsigned int type, void *value);
|
||||||
|
|
||||||
|
SNode *popStack(Stack *p_stack);
|
||||||
|
int pushStack(Stack *p_stack, SNode *p_snode);
|
||||||
|
|
||||||
|
int releaseStack(Stack *p_stack);
|
||||||
|
int releaseSNode(SNode *p_snode);
|
||||||
|
|
||||||
|
#endif /* stack_h */
|
63
stack/stack_expand.c
Normal file
63
stack/stack_expand.c
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#include "stack_expand.h"
|
||||||
|
|
||||||
|
SNode *snodeWithInt(int temp) {
|
||||||
|
SNode *p_snode = initSNode();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode *snodeWithDouble(double temp) {
|
||||||
|
SNode *p_snode = initSNode();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode *snodeWithString(char *temp) {
|
||||||
|
SNode *p_snode = initSNode();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode *snodeWithPointer(void *temp) {
|
||||||
|
SNode *p_snode = initSNode();
|
||||||
|
initMallocValueForSNode(p_snode, POINTER, temp);
|
||||||
|
return p_snode;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getValueByIntForSNode(SNode *p_snode) {
|
||||||
|
if (p_snode->type == INT) return *(int *)p_snode->value;
|
||||||
|
else return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double getValueByDoubleForSNode(SNode *p_snode) {
|
||||||
|
if (p_snode->type == DOUBLE) return *(double *)p_snode->value;
|
||||||
|
else return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *getValueByStringForSNode(SNode *p_snode) {
|
||||||
|
if (p_snode->type == STRING) return (char *)p_snode->value;
|
||||||
|
else return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *getValueByPointerForSNode(SNode *p_snode) {
|
||||||
|
if (p_snode->type == POINTER) return (void *)p_snode->value;
|
||||||
|
else return NULL;
|
||||||
|
}
|
16
stack/stack_expand.h
Normal file
16
stack/stack_expand.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef STACK_EXPAND_H
|
||||||
|
#define STACK_EXPAND_H
|
||||||
|
|
||||||
|
#include "stack.h"
|
||||||
|
|
||||||
|
SNode *snodeWithInt(int);
|
||||||
|
SNode *snodeWithDouble(double);
|
||||||
|
SNode *snodeWithString(char *);
|
||||||
|
SNode *snodeWithPointer(void *);
|
||||||
|
|
||||||
|
int getValueByIntForSNode(SNode *);
|
||||||
|
double getValueByDoubleForSNode(SNode *);
|
||||||
|
char *getValueByStringForSNode(SNode *);
|
||||||
|
void *getValueByPointerForSNode(SNode *);
|
||||||
|
|
||||||
|
#endif /* stack_expand_h */
|
100
test.c
Normal file
100
test.c
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _useTreeThroughDown(TNode *p_tnode, unsigned long long height) {
|
||||||
|
printTNode(p_tnode,0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int tree(void) {
|
||||||
|
TNode *t_tnode, *cr_tnode, *cl_tnode;
|
||||||
|
Tree *t_tree;
|
||||||
|
TNode *gs_tnode;
|
||||||
|
safeModeForTree(1);
|
||||||
|
t_tree = initTree();
|
||||||
|
t_tnode = tnodeWithInt(1);
|
||||||
|
cr_tnode = tnodeWithInt(3);
|
||||||
|
cl_tnode = tnodeWithInt(2);
|
||||||
|
addChildInRight(t_tnode, cl_tnode);
|
||||||
|
addChildInRight(t_tnode, cr_tnode);
|
||||||
|
addChildInRight(cl_tnode, tnodeWithInt(4));
|
||||||
|
gs_tnode = tnodeWithInt(5);
|
||||||
|
addChildInRight(cl_tnode,gs_tnode);
|
||||||
|
addChildInRight(cr_tnode, tnodeWithInt(6));
|
||||||
|
addChildInRight(cr_tnode, tnodeWithInt(7));
|
||||||
|
addChildInRight(gs_tnode, tnodeWithInt(8));
|
||||||
|
setRoot(t_tree, t_tnode);
|
||||||
|
TreeThroughUp(t_tree, _useTreeThroughDown);
|
||||||
|
//printTNodeWithFamily(t_tnode, 0);
|
||||||
|
releaseAllForTree();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int stack(void) {
|
||||||
|
int i;
|
||||||
|
Stack *t_stack = initStack();
|
||||||
|
for (i = 0; i < 10; i++) {
|
||||||
|
pushStack(t_stack, snodeWithInt(i));
|
||||||
|
}
|
||||||
|
for (i = 0; i < 10; i++) {
|
||||||
|
printf("%d", getValueByIntForSNode(popStack(t_stack)));
|
||||||
|
}
|
||||||
|
releaseStack(t_stack);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
return 0;
|
||||||
|
}
|
14
test.h
Normal file
14
test.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef TEST_H
|
||||||
|
#define TEST_H
|
||||||
|
|
||||||
|
#include "type/type.h"
|
||||||
|
#include "list/list_expand.h"
|
||||||
|
#include "stack/stack_expand.h"
|
||||||
|
#include "tree/tree_expand.h"
|
||||||
|
#include "communicate/communicate.h"
|
||||||
|
|
||||||
|
int stack(void);
|
||||||
|
int list(void);
|
||||||
|
int tree(void);
|
||||||
|
|
||||||
|
#endif // TEST_H
|
497
tree/tree.c
Normal file
497
tree/tree.c
Normal file
@ -0,0 +1,497 @@
|
|||||||
|
#include"tree.h"
|
||||||
|
|
||||||
|
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));
|
||||||
|
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;
|
||||||
|
|
||||||
|
tnode_list->head = NULL;
|
||||||
|
tnode_list->length = 0;
|
||||||
|
tnode_list->tail = NULL;
|
||||||
|
|
||||||
|
if_safeModeForTree = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 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 getting the memory of tnode.")));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
p_tnode->s_id = getS_id(TREE_NODE, 1);
|
||||||
|
p_tnode->if_sid = 1;
|
||||||
|
p_tnode->child_num = 0;
|
||||||
|
p_tnode->father = NULL;
|
||||||
|
p_tnode->if_malloc = 0;
|
||||||
|
p_tnode->value = NULL;
|
||||||
|
p_tnode->type = VOID;
|
||||||
|
p_tnode->home = initList();
|
||||||
|
p_tnode->room = NULL;
|
||||||
|
if (if_safeModeForTree) {
|
||||||
|
if (if_safeModeForNode) {
|
||||||
|
if_safeModeForNode = 0;
|
||||||
|
s_node = initNode();
|
||||||
|
initMallocValueForNode(s_node, POINTER, (void *)p_tnode);
|
||||||
|
insertInTail(tnode_list, s_node);
|
||||||
|
if_safeModeForNode = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_node = initNode();
|
||||||
|
initMallocValueForNode(s_node, POINTER, (void *)p_tnode);
|
||||||
|
insertInTail(tnode_list, s_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p_tnode;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 getting the memory of tree.")));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
p_tree->s_id = getS_id(TREE, 1);
|
||||||
|
p_tree->if_sid = 1;
|
||||||
|
p_tree->root = NULL;
|
||||||
|
if (if_safeModeForTree) {
|
||||||
|
if (if_safeModeForNode) {
|
||||||
|
if_safeModeForNode = 0;
|
||||||
|
s_node = initNode();
|
||||||
|
initMallocValueForNode(s_node, POINTER, (void *)p_tree);
|
||||||
|
if_safeModeForNode = 1;
|
||||||
|
insertInTail(tree_list, s_node);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_node = initNode();
|
||||||
|
initMallocValueForNode(s_node, POINTER, (void *)p_tree);
|
||||||
|
insertInTail(tree_list, s_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p_tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
int *initMallocValueForTNode(TNode *p_tnode, unsigned int type, void *value) {
|
||||||
|
p_tnode->type = type;
|
||||||
|
p_tnode->value = value;
|
||||||
|
p_tnode->if_malloc = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int addChildInLeft(TNode *f_tnode, TNode *c_tnode) {
|
||||||
|
Node *p_node = initNode();
|
||||||
|
initMallocValueForNode(p_node, POINTER, c_tnode);
|
||||||
|
insertInHead(f_tnode->home, p_node);
|
||||||
|
c_tnode->father = f_tnode;
|
||||||
|
c_tnode->room = p_node;
|
||||||
|
f_tnode->child_num++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int addChildInRight(TNode *f_tnode, TNode *c_tnode) {
|
||||||
|
Node *p_node = initNode();
|
||||||
|
initMallocValueForNode(p_node, POINTER, c_tnode);
|
||||||
|
insertInTail(f_tnode->home, p_node);
|
||||||
|
c_tnode->father = f_tnode;
|
||||||
|
c_tnode->room = p_node;
|
||||||
|
f_tnode->child_num++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TNode *getBrotherInLeft(TNode *p_tnode) {
|
||||||
|
List *p_home = p_tnode->father->home;
|
||||||
|
Node *p_node = p_tnode->room;
|
||||||
|
unsigned long long index = getIndexByNode(p_home, p_node);
|
||||||
|
if (index > 0) return (TNode *)(findByIndexForNode(p_home, index - 1)->value);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
TNode *getBrotherInRight(TNode *p_tnode) {
|
||||||
|
List *p_home = p_tnode->father->home;
|
||||||
|
Node *p_node = p_home->head;
|
||||||
|
unsigned long long index = getIndexByNode(p_home, p_node);
|
||||||
|
if (index < p_home->length - 1) return (TNode *)(findByIndexForNode(p_home, index + 1)->value);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int removeChildInLeft(TNode *p_tnode) {
|
||||||
|
TNode *c_tnode = (TNode *)p_tnode->home->head->value;
|
||||||
|
c_tnode->father = NULL;
|
||||||
|
releaseOnlyNode(c_tnode->room);
|
||||||
|
c_tnode->room = NULL;
|
||||||
|
p_tnode->child_num--;
|
||||||
|
popFromHead(p_tnode->home);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int removeChildInRight(TNode *p_tnode) {
|
||||||
|
TNode *c_tnode = (TNode *)p_tnode->home->tail->value;
|
||||||
|
c_tnode->father = NULL;
|
||||||
|
releaseOnlyNode(c_tnode->room);
|
||||||
|
c_tnode->room = NULL;
|
||||||
|
p_tnode->child_num--;
|
||||||
|
popFromTail(p_tnode->home);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TNode *getChildById(TNode *p_tnode, const SID *s_id) {
|
||||||
|
List *p_home = p_tnode->home;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
insertInTail(rtn_list, nodeWithInt(-1));
|
||||||
|
insertInTail(rtn_list, nodeWithPointer(target_value_sid));
|
||||||
|
return rtn_list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
insertInTail(rtn_list, nodeWithInt(0));
|
||||||
|
return rtn_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
insertInTail(rtn_list, nodeWithInt(-1));
|
||||||
|
insertInTail(rtn_list, nodeWithPointer(p_tode));
|
||||||
|
return rtn_list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
insertInTail(rtn_list, nodeWithInt(0));
|
||||||
|
return rtn_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
int removeChildById(TNode *p_tnode, const SID *s_id) {
|
||||||
|
TNode *t_tnode = getChildById(p_tnode, s_id);
|
||||||
|
if (t_tnode != NULL) {
|
||||||
|
TNode *p_fnode = t_tnode->father;
|
||||||
|
p_fnode->child_num--;
|
||||||
|
removeById(p_fnode->home, t_tnode->room->s_id);
|
||||||
|
releaseOnlyNode(t_tnode->room);
|
||||||
|
t_tnode->room = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int removeChildByValue(TNode *p_tnode, unsigned int type, void *value) {
|
||||||
|
TNode *t_tnode = getChildByValue(p_tnode, type, value);
|
||||||
|
if (t_tnode != NULL) {
|
||||||
|
TNode *p_fnode = t_tnode->father;
|
||||||
|
p_fnode->child_num--;
|
||||||
|
removeById(p_fnode->home, t_tnode->room->s_id);
|
||||||
|
releaseOnlyNode(t_tnode->room);
|
||||||
|
t_tnode->room = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
TNode *getChildByIndex(TNode *p_tnode, unsigned long long index) {
|
||||||
|
List *p_home = p_tnode->home;
|
||||||
|
Node *p_node = p_home->head;
|
||||||
|
int m_index = 0;
|
||||||
|
if (index < p_tnode->child_num)
|
||||||
|
{
|
||||||
|
while (p_node != NULL && m_index < index) {
|
||||||
|
m_index++;
|
||||||
|
p_node = p_node->next;
|
||||||
|
}
|
||||||
|
return (TNode *)p_node->value;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode) {
|
||||||
|
List *p_home = f_tnode->home;
|
||||||
|
Node *p_node = p_home->head;
|
||||||
|
int m_index = 0;
|
||||||
|
while (p_node != NULL) {
|
||||||
|
TNode *p_tnode = (TNode *)p_node->value;
|
||||||
|
if (p_tnode->s_id == c_tnode->s_id) {
|
||||||
|
return m_index;
|
||||||
|
}
|
||||||
|
m_index++;
|
||||||
|
p_node = p_node->next;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int removeChildByIndex(TNode *p_tnode, unsigned long long index) {
|
||||||
|
TNode *t_tnode = getChildByIndex(p_tnode, index);
|
||||||
|
if (t_tnode != NULL) {
|
||||||
|
TNode *p_fnode = t_tnode->father;
|
||||||
|
p_fnode->child_num--;
|
||||||
|
removeById(p_fnode->home, t_tnode->room->s_id);
|
||||||
|
releaseOnlyNode(t_tnode->room);
|
||||||
|
t_tnode->room = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) {
|
||||||
|
int i;
|
||||||
|
TNode *p_tnode = p_tree->root;
|
||||||
|
if (p_tnode != NULL) {
|
||||||
|
if (p_tnode->child_num > 0) {
|
||||||
|
for (i = 0; i < p_tnode->child_num; i++) {
|
||||||
|
if (_doTreeThroughUp(getChildByIndex(p_tnode, i), 1, func) == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func(p_tnode, 0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) {
|
||||||
|
int i, func_back;
|
||||||
|
|
||||||
|
if (p_tnode->child_num > 0) {
|
||||||
|
for (i = 0; i < p_tnode->child_num; i++) {
|
||||||
|
if (_doTreeThroughUp(getChildByIndex(p_tnode, i), height + 1, func)) return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func_back = func(p_tnode, height);
|
||||||
|
if (func_back == -1)return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) {
|
||||||
|
int i;
|
||||||
|
TNode *p_tnode = p_tree->root;
|
||||||
|
if (p_tree->root != NULL) {
|
||||||
|
func(p_tnode, 0);
|
||||||
|
if (p_tree->root->child_num > 0) {
|
||||||
|
for (i = 0; i < p_tnode->child_num; i++) {
|
||||||
|
if (_doTreeThroughDown(getChildByIndex(p_tnode, i), 1, func) == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) {
|
||||||
|
int i;
|
||||||
|
int func_back = func(p_tnode, height);
|
||||||
|
if (p_tnode->child_num > 0) {
|
||||||
|
for (i = 0; i < p_tnode->child_num; i++) {
|
||||||
|
if (_doTreeThroughDown(getChildByIndex(p_tnode, i), height + 1, func)) return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (func_back == -1)return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) {
|
||||||
|
TNode *p_tnode = p_tree->root;
|
||||||
|
unsigned long long height = 0;
|
||||||
|
if (p_tnode != NULL) {
|
||||||
|
int func_back = func(p_tnode, height);
|
||||||
|
while (func_back > -2) {
|
||||||
|
if (func_back > -1) {
|
||||||
|
p_tnode = getChildByIndex(p_tnode, func_back);
|
||||||
|
func(p_tnode, height + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p_tnode = p_tnode->father;
|
||||||
|
func(p_tnode, height - 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int releaseTNode(TNode *p_tnode) {
|
||||||
|
if (p_tnode->child_num == 0) {
|
||||||
|
releaseList(p_tnode->home);
|
||||||
|
if (p_tnode->father != NULL) {
|
||||||
|
removeChildById(p_tnode->father, p_tnode->s_id);
|
||||||
|
}
|
||||||
|
if (p_tnode->type != POINTER) {
|
||||||
|
if (p_tnode->type == LIST) {
|
||||||
|
releaseList((List *)p_tnode->value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
free(p_tnode->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p_tnode->value = NULL;
|
||||||
|
p_tnode->type = VOID;
|
||||||
|
freeS_id(p_tnode->s_id);
|
||||||
|
p_tnode->if_malloc = 0;
|
||||||
|
free(p_tnode);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int releaseTree(Tree *p_tree) {
|
||||||
|
TreeThroughUp(p_tree, _doreleaseTree);
|
||||||
|
p_tree->root = NULL;
|
||||||
|
freeS_id(p_tree->s_id);
|
||||||
|
free(p_tree);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _doreleaseTree(TNode *p_tnode, unsigned long long height) {
|
||||||
|
releaseTNode(p_tnode);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int releaseOnlyTree(Tree *p_tree) {
|
||||||
|
freeS_id(p_tree->s_id);
|
||||||
|
p_tree->root = NULL;
|
||||||
|
free(p_tree);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int releaseOnlyTNode(TNode *p_tnode) {
|
||||||
|
releaseList(p_tnode->home);
|
||||||
|
if (p_tnode->if_malloc) {
|
||||||
|
if (p_tnode->type != STRING) {
|
||||||
|
if (p_tnode->type == LIST) {
|
||||||
|
releaseList((List *)p_tnode->value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
free(p_tnode->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p_tnode->value = NULL;
|
||||||
|
p_tnode->type = VOID;
|
||||||
|
freeS_id(p_tnode->s_id);
|
||||||
|
p_tnode->if_malloc = 0;
|
||||||
|
free(p_tnode);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int releaseAllForTree(void) {
|
||||||
|
Node *p_node;
|
||||||
|
Tree *p_tree;
|
||||||
|
if (if_safeModeForTree) {
|
||||||
|
if_safeModeForTree = 0;
|
||||||
|
p_node = tnode_list->head;
|
||||||
|
while (p_node != NULL) {
|
||||||
|
TNode *p_tnode = (TNode *)p_node->value;
|
||||||
|
releaseOnlyTNode(p_tnode);
|
||||||
|
p_node = p_node->next;
|
||||||
|
}
|
||||||
|
p_node = tree_list->head;
|
||||||
|
while (p_node != NULL) {
|
||||||
|
p_tree = (Tree *)p_node->value;
|
||||||
|
releaseOnlyTree(p_tree);
|
||||||
|
p_node = p_node->next;
|
||||||
|
}
|
||||||
|
releaseList(tnode_list);
|
||||||
|
releaseList(tree_list);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int setRoot(Tree *p_tree, TNode *p_tnode) {
|
||||||
|
p_tree->root = p_tnode;
|
||||||
|
return 0;
|
||||||
|
}
|
56
tree/tree.h
Normal file
56
tree/tree.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#ifndef TREE_H
|
||||||
|
#define TREE_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "../list/list_expand.h"
|
||||||
|
|
||||||
|
int safeModeForTree(int ifon);
|
||||||
|
int releaseAllForTree(void);
|
||||||
|
|
||||||
|
TNode *initTNode(void);
|
||||||
|
Tree *initTree(void);
|
||||||
|
int *initMallocValueForTNode(TNode *p_tnode, unsigned int type, void *value);
|
||||||
|
|
||||||
|
int addChildInLeft(TNode *f_tnode, TNode *c_tnode);
|
||||||
|
int addChildInRight(TNode *f_tnode, TNode *c_tnode);
|
||||||
|
TNode *getBrotherInLeft(TNode *p_tnode);
|
||||||
|
TNode *getBrotherInRight(TNode *p_node);
|
||||||
|
int removeChildInLeft(TNode *p_tnode);
|
||||||
|
int removeChildInRight(TNode *p_tnode);
|
||||||
|
TNode *getChildById(TNode *p_tnode, const SID *s_id);
|
||||||
|
TNode *getChildByValue(TNode *p_tnode, unsigned int type, void *value);
|
||||||
|
TNode *getChildByIndex(TNode *p_tnode, unsigned long long index);
|
||||||
|
unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode);
|
||||||
|
int removeChildById(TNode *p_tnode, const SID *s_id);
|
||||||
|
int removeChildByIndex(TNode *p_tnode, unsigned long long index);
|
||||||
|
int removeChildByValue(TNode *p_tnode, unsigned int type, void *value);
|
||||||
|
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));
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
int releaseTree(Tree *p_tree);
|
||||||
|
int releaseOnlyTree(Tree *p_tree);
|
||||||
|
int releaseTNode(TNode *p_tnode);
|
||||||
|
int releaseOnlyTNode(TNode *p_tnode);
|
||||||
|
|
||||||
|
int setRoot(Tree *p_tree, TNode *p_tnode);
|
||||||
|
|
||||||
|
static int target_type;
|
||||||
|
static void *target_value;
|
||||||
|
static TNode *target_value_value;
|
||||||
|
|
||||||
|
static SID *target_sid;
|
||||||
|
static TNode *target_value_sid;
|
||||||
|
|
||||||
|
static List *tree_list;
|
||||||
|
static List *tnode_list;
|
||||||
|
static int if_safeModeForTree;
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
239
tree/tree_expand.c
Normal file
239
tree/tree_expand.c
Normal file
@ -0,0 +1,239 @@
|
|||||||
|
#include "tree_expand.h"
|
||||||
|
|
||||||
|
TNode *tnodeWithInt(int temp) {
|
||||||
|
TNode *p_tnode = initTNode();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
TNode *tnodeWithDouble(double temp) {
|
||||||
|
TNode *p_tnode = initTNode();
|
||||||
|
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));
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
TNode *tnodeWithPointer(void *temp) {
|
||||||
|
TNode *p_tnode = initTNode();
|
||||||
|
initMallocValueForTNode(p_tnode, POINTER, temp);
|
||||||
|
return p_tnode;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getValueByIntForTree(TNode *p_tnode) {
|
||||||
|
if (p_tnode->type == INT) {
|
||||||
|
return *(int *)p_tnode->value;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double getValueByDoubleForTree(TNode *p_tnode) {
|
||||||
|
if (p_tnode->type == DOUBLE) {
|
||||||
|
return *(double *)p_tnode->value;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *getValueByStringForTree(TNode *p_tnode) {
|
||||||
|
if (p_tnode->type == STRING) {
|
||||||
|
return (char *)p_tnode->value;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *getValueByPointerForTree(TNode *p_tnode) {
|
||||||
|
if (p_tnode->type == POINTER) {
|
||||||
|
return p_tnode->value;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int printTNode(TNode *p_tnode, int priority) {
|
||||||
|
int i;
|
||||||
|
if (p_tnode != NULL) {
|
||||||
|
for (i = 0; i < priority; i++) printf(" ");
|
||||||
|
if (priority == 0) printf("###");
|
||||||
|
else printf("#");
|
||||||
|
|
||||||
|
printf("TNode(id: %s)\n", s_idToASCIIString(p_tnode->s_id));
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("ifMalloc: ");
|
||||||
|
if (p_tnode->if_malloc) {
|
||||||
|
printf("YES\n");
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("Value(type: %d): ", p_tnode->type);
|
||||||
|
if (p_tnode->type == INT) {
|
||||||
|
printf("%d\n", *(int *)(p_tnode->value));
|
||||||
|
}
|
||||||
|
else if (p_tnode->type == DOUBLE) {
|
||||||
|
printf("%a\n", *(double *)(p_tnode->value));
|
||||||
|
}
|
||||||
|
else if (p_tnode->type == STRING) {
|
||||||
|
printf("%s\n", (char *)(p_tnode->value));
|
||||||
|
}
|
||||||
|
else if (p_tnode->type == POINTER) {
|
||||||
|
printf("%p\n", (char *)(p_tnode->value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else printf("NO\n");
|
||||||
|
|
||||||
|
if (p_tnode->child_num > 0) {
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("Child number: %llu\n", p_tnode->child_num);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int printTNodeWithHome(TNode *p_tnode,int priority) {
|
||||||
|
int i;
|
||||||
|
List *p_home;
|
||||||
|
Node *p_node;
|
||||||
|
if (p_tnode != NULL) {
|
||||||
|
if (priority == 0) printf("###");
|
||||||
|
else printf("#");
|
||||||
|
printf("TNode(id: %s)\n", s_idToASCIIString(p_tnode->s_id));
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("ifMalloc: ");
|
||||||
|
if (p_tnode->if_malloc) {
|
||||||
|
printf("YES\n");
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("Value(type: %d): ", p_tnode->type);
|
||||||
|
if (p_tnode->type == INT) {
|
||||||
|
printf("%d\n", *(int *)(p_tnode->value));
|
||||||
|
}
|
||||||
|
else if (p_tnode->type == DOUBLE) {
|
||||||
|
printf("%a\n", *(double *)(p_tnode->value));
|
||||||
|
}
|
||||||
|
else if (p_tnode->type == STRING) {
|
||||||
|
printf("%s\n", (char *)(p_tnode->value));
|
||||||
|
}
|
||||||
|
else if (p_tnode->type == POINTER) {
|
||||||
|
printf("%p\n", (char *)(p_tnode->value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else printf("NO\n");
|
||||||
|
|
||||||
|
if (p_tnode->father != NULL) {
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("Father id: %s\n", s_idToASCIIString(p_tnode->father->s_id));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("Father: NO\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_tnode->child_num > 0) {
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("Child(number: %llu):\n", p_tnode->child_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
p_home = p_tnode->home;
|
||||||
|
p_node = p_home->head;
|
||||||
|
while (p_node != NULL) {
|
||||||
|
printTNode((TNode *)p_node->value, priority + 2);
|
||||||
|
p_node = p_node->next;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int printTNodeWithFamily(TNode *p_tnode, int priority) {
|
||||||
|
int i;
|
||||||
|
List *p_home;
|
||||||
|
Node *p_node;
|
||||||
|
if (p_tnode != NULL) {
|
||||||
|
for (i = 0; i < priority; i++) printf(" ");
|
||||||
|
if (priority == 0) printf("###");
|
||||||
|
else printf("#");
|
||||||
|
printf("TNode(id: %s)\n", s_idToASCIIString(p_tnode->s_id));
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("ifMalloc: ");
|
||||||
|
if (p_tnode->if_malloc) {
|
||||||
|
printf("YES\n");
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("Value(type: %d): ", p_tnode->type);
|
||||||
|
if (p_tnode->type == INT) {
|
||||||
|
printf("%d\n", *(int *)(p_tnode->value));
|
||||||
|
}
|
||||||
|
else if (p_tnode->type == DOUBLE) {
|
||||||
|
printf("%a\n", *(double *)(p_tnode->value));
|
||||||
|
}
|
||||||
|
else if (p_tnode->type == STRING) {
|
||||||
|
printf("%s\n", (char *)(p_tnode->value));
|
||||||
|
}
|
||||||
|
else if (p_tnode->type == POINTER) {
|
||||||
|
printf("%p\n", (char *)(p_tnode->value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else printf("NO\n");
|
||||||
|
|
||||||
|
if (p_tnode->father != NULL) {
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("Father id: %s\n", s_idToASCIIString(p_tnode->father->s_id));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("Father: NO\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_tnode->child_num > 0) {
|
||||||
|
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||||
|
printf("Child(number: %llu):\n", p_tnode->child_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
p_home = p_tnode->home;
|
||||||
|
p_node = p_home->head;
|
||||||
|
while (p_node != NULL) {
|
||||||
|
printTNodeWithFamily((TNode *)p_node->value, priority + 2);
|
||||||
|
p_node = p_node->next;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int printTree(Tree *p_tree) {
|
||||||
|
printf("###");
|
||||||
|
printf("Tree(id: %s)",s_idToASCIIString(p_tree->s_id));
|
||||||
|
printTNodeWithFamily(p_tree->root,0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned long long tnodes_size = 0LL;
|
||||||
|
|
||||||
|
unsigned long long calTreeMemory(Tree *p_tree){
|
||||||
|
tnodes_size = 0LL;
|
||||||
|
TreeThroughDown(p_tree, _doCalTreeMemory);
|
||||||
|
return sizeof(p_tree) + tnodes_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _doCalTreeMemory(TNode *p_tnode, unsigned long long height){
|
||||||
|
tnodes_size += sizeof(p_tnode);
|
||||||
|
return 0;
|
||||||
|
}
|
27
tree/tree_expand.h
Normal file
27
tree/tree_expand.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef TREE_EXPAND_H
|
||||||
|
#define TREE_EXPAND_H
|
||||||
|
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
|
TNode *tnodeWithInt(int);
|
||||||
|
TNode *tnodeWithDouble(double);
|
||||||
|
TNode *tnodeWithString(char *);
|
||||||
|
TNode *tnodeWithPointer(void *);
|
||||||
|
|
||||||
|
int getValueByIntForTree(TNode *);
|
||||||
|
double getValueByDoubleForTree(TNode *);
|
||||||
|
char *getValueByStringForTree(TNode *);
|
||||||
|
void *getValueByPointerForTree(TNode *);
|
||||||
|
|
||||||
|
int printTree(Tree *p_tree);
|
||||||
|
int printTNodeWithHome(TNode *p_tnode, int priority);
|
||||||
|
int printTNodeWithFamily(TNode *p_tnode, int priority);
|
||||||
|
int printTNode(TNode *p_tnode, int priority);
|
||||||
|
|
||||||
|
unsigned long long calTreeMemory(Tree *);
|
||||||
|
int _doCalTreeMemory(TNode *p_tnode, unsigned long long height);
|
||||||
|
|
||||||
|
List *treeToList(Tree *p_tree);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
178
type/type.h
Normal file
178
type/type.h
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
#ifndef type_h
|
||||||
|
#define type_h
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define VOID 0
|
||||||
|
#define INT 1
|
||||||
|
#define DOUBLE 2
|
||||||
|
#define STRING 3
|
||||||
|
#define POINTER 4
|
||||||
|
#define LIST 5
|
||||||
|
#define STACK 6
|
||||||
|
#define TREE 7
|
||||||
|
#define LIST_NODE 8
|
||||||
|
#define TREE_NODE 9
|
||||||
|
#define STACK_NODE 10
|
||||||
|
#define T_SID 11
|
||||||
|
#define UINT 12
|
||||||
|
#define STANDARD_DATA 13
|
||||||
|
#define DATA_FILE 14
|
||||||
|
#define MESSAGE 15
|
||||||
|
|
||||||
|
#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 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
|
||||||
|
#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 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;
|
||||||
|
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;
|
||||||
|
|
||||||
|
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 */
|
Loading…
Reference in New Issue
Block a user