diff --git a/Net.xcodeproj/project.pbxproj b/Net.xcodeproj/project.pbxproj index ae6e932..c4edade 100644 --- a/Net.xcodeproj/project.pbxproj +++ b/Net.xcodeproj/project.pbxproj @@ -7,10 +7,18 @@ objects = { /* Begin PBXBuildFile section */ - 9221DA1121EB5FB8007310A7 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9221DA1021EB5FB8007310A7 /* main.cpp */; }; - 925A13A621EC68D500CBD427 /* cpart.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 925A13A421EC67C900CBD427 /* cpart.cpp */; }; - 925A13A921EC973000CBD427 /* cmap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 925A13A721EC973000CBD427 /* cmap.cpp */; }; - 92A1F2A821F365D800340EFA /* memory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 92A1F29F21F1663300340EFA /* memory.cpp */; }; + 9277A15E21FD725F009C5F11 /* addr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15221FD725F009C5F11 /* addr.cpp */; }; + 9277A15F21FD725F009C5F11 /* socket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15321FD725F009C5F11 /* socket.cpp */; }; + 9277A16021FD725F009C5F11 /* md5.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15421FD725F009C5F11 /* md5.cpp */; }; + 9277A16121FD725F009C5F11 /* cproj.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15521FD725F009C5F11 /* cproj.cpp */; }; + 9277A16221FD725F009C5F11 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15621FD725F009C5F11 /* main.cpp */; }; + 9277A16321FD725F009C5F11 /* cthread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15721FD725F009C5F11 /* cthread.cpp */; }; + 9277A16421FD725F009C5F11 /* server.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15821FD725F009C5F11 /* server.cpp */; }; + 9277A16521FD725F009C5F11 /* cmap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15921FD725F009C5F11 /* cmap.cpp */; }; + 9277A16621FD725F009C5F11 /* cpart.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15A21FD725F009C5F11 /* cpart.cpp */; }; + 9277A16721FD725F009C5F11 /* memory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15B21FD725F009C5F11 /* memory.cpp */; }; + 9277A16821FD725F009C5F11 /* clock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15C21FD725F009C5F11 /* clock.cpp */; }; + 9277A16921FD725F009C5F11 /* client.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15D21FD725F009C5F11 /* client.cpp */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -27,27 +35,32 @@ /* Begin PBXFileReference section */ 9221D9EB21EA5142007310A7 /* Net */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Net; sourceTree = BUILT_PRODUCTS_DIR; }; - 9221DA0F21EB5FB8007310A7 /* net.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = net.h; sourceTree = ""; }; - 9221DA1021EB5FB8007310A7 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; - 9221DA1421EB62F6007310A7 /* cpart.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cpart.h; sourceTree = ""; }; 9221DA1621EB8C02007310A7 /* pcs.map */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; name = pcs.map; path = build/Debug/PCS/pcs.map; sourceTree = ""; }; - 925A13A421EC67C900CBD427 /* cpart.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = cpart.cpp; sourceTree = ""; }; - 925A13A721EC973000CBD427 /* cmap.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = cmap.cpp; sourceTree = ""; }; - 925A13A821EC973000CBD427 /* cmap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cmap.h; sourceTree = ""; }; - 925A13AB21EC9DB900CBD427 /* cthread.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = cthread.cpp; sourceTree = ""; }; - 925A13AC21EC9DB900CBD427 /* cthread.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cthread.h; sourceTree = ""; }; - 92A1F29721F0C19500340EFA /* socket.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = socket.cpp; sourceTree = ""; }; - 92A1F29921F0C5CC00340EFA /* clock.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = clock.cpp; sourceTree = ""; }; - 92A1F29A21F0C5CC00340EFA /* clock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = clock.h; sourceTree = ""; }; - 92A1F29C21F0C67600340EFA /* type.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = type.h; sourceTree = ""; }; - 92A1F29D21F0C72C00340EFA /* addr.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = addr.cpp; sourceTree = ""; }; - 92A1F29F21F1663300340EFA /* memory.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = memory.cpp; sourceTree = ""; }; - 92A1F2A021F1663300340EFA /* memory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = memory.h; sourceTree = ""; }; + 9277A14521FD7246009C5F11 /* cproj.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = cproj.hpp; path = include/cproj.hpp; sourceTree = ""; }; + 9277A14621FD7246009C5F11 /* cmap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cmap.h; path = include/cmap.h; sourceTree = ""; }; + 9277A14721FD7246009C5F11 /* server.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = server.h; path = include/server.h; sourceTree = ""; }; + 9277A14821FD7246009C5F11 /* net.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = net.h; path = include/net.h; sourceTree = ""; }; + 9277A14921FD7246009C5F11 /* compute.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = compute.h; path = include/compute.h; sourceTree = ""; }; + 9277A14A21FD7246009C5F11 /* cthread.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cthread.h; path = include/cthread.h; sourceTree = ""; }; + 9277A14B21FD7246009C5F11 /* cpart.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cpart.h; path = include/cpart.h; sourceTree = ""; }; + 9277A14C21FD7246009C5F11 /* clock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = clock.h; path = include/clock.h; sourceTree = ""; }; + 9277A14D21FD7246009C5F11 /* md5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = md5.h; path = include/md5.h; sourceTree = ""; }; + 9277A14E21FD7246009C5F11 /* memory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = memory.h; path = include/memory.h; sourceTree = ""; }; + 9277A14F21FD7246009C5F11 /* memory_type.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = memory_type.h; path = include/memory_type.h; sourceTree = ""; }; + 9277A15021FD7246009C5F11 /* type.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = type.h; path = include/type.h; sourceTree = ""; }; + 9277A15221FD725F009C5F11 /* addr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = addr.cpp; path = src/addr.cpp; sourceTree = ""; }; + 9277A15321FD725F009C5F11 /* socket.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = socket.cpp; path = src/socket.cpp; sourceTree = ""; }; + 9277A15421FD725F009C5F11 /* md5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = md5.cpp; path = src/md5.cpp; sourceTree = ""; }; + 9277A15521FD725F009C5F11 /* cproj.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = cproj.cpp; path = src/cproj.cpp; sourceTree = ""; }; + 9277A15621FD725F009C5F11 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = src/main.cpp; sourceTree = ""; }; + 9277A15721FD725F009C5F11 /* cthread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = cthread.cpp; path = src/cthread.cpp; sourceTree = ""; }; + 9277A15821FD725F009C5F11 /* server.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = server.cpp; path = src/server.cpp; sourceTree = ""; }; + 9277A15921FD725F009C5F11 /* cmap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = cmap.cpp; path = src/cmap.cpp; sourceTree = ""; }; + 9277A15A21FD725F009C5F11 /* cpart.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = cpart.cpp; path = src/cpart.cpp; sourceTree = ""; }; + 9277A15B21FD725F009C5F11 /* memory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = memory.cpp; path = src/memory.cpp; sourceTree = ""; }; + 9277A15C21FD725F009C5F11 /* clock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = clock.cpp; path = src/clock.cpp; sourceTree = ""; }; + 9277A15D21FD725F009C5F11 /* client.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = client.cpp; path = src/client.cpp; sourceTree = ""; }; 92A1F2A421F21DC700340EFA /* a.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = a.cpp; path = build/Debug/PCS/a.cpp; sourceTree = ""; }; - 92A1F2A621F2412500340EFA /* compute.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = compute.h; sourceTree = ""; }; - 92A1F2A721F242C900340EFA /* memory_type.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = memory_type.h; sourceTree = ""; }; - 92D6CE6721EE4920005AEF3B /* server.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = server.cpp; sourceTree = ""; }; - 92D6CE6821EE4920005AEF3B /* server.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = server.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -80,18 +93,10 @@ 9221DA0E21EB5FAD007310A7 /* Net */ = { isa = PBXGroup; children = ( + 9277A15121FD724C009C5F11 /* src */, 92A1F2A421F21DC700340EFA /* a.cpp */, 925A13AA21EC989500CBD427 /* include */, - 9221DA1021EB5FB8007310A7 /* main.cpp */, - 92A1F29721F0C19500340EFA /* socket.cpp */, 9221DA1621EB8C02007310A7 /* pcs.map */, - 925A13A421EC67C900CBD427 /* cpart.cpp */, - 925A13A721EC973000CBD427 /* cmap.cpp */, - 925A13AB21EC9DB900CBD427 /* cthread.cpp */, - 92D6CE6721EE4920005AEF3B /* server.cpp */, - 92A1F29921F0C5CC00340EFA /* clock.cpp */, - 92A1F29D21F0C72C00340EFA /* addr.cpp */, - 92A1F29F21F1663300340EFA /* memory.cpp */, ); name = Net; sourceTree = ""; @@ -99,20 +104,41 @@ 925A13AA21EC989500CBD427 /* include */ = { isa = PBXGroup; children = ( - 92A1F2A021F1663300340EFA /* memory.h */, - 92A1F29A21F0C5CC00340EFA /* clock.h */, - 925A13A821EC973000CBD427 /* cmap.h */, - 9221DA1421EB62F6007310A7 /* cpart.h */, - 925A13AC21EC9DB900CBD427 /* cthread.h */, - 9221DA0F21EB5FB8007310A7 /* net.h */, - 92D6CE6821EE4920005AEF3B /* server.h */, - 92A1F29C21F0C67600340EFA /* type.h */, - 92A1F2A621F2412500340EFA /* compute.h */, - 92A1F2A721F242C900340EFA /* memory_type.h */, + 9277A14C21FD7246009C5F11 /* clock.h */, + 9277A14621FD7246009C5F11 /* cmap.h */, + 9277A14921FD7246009C5F11 /* compute.h */, + 9277A14B21FD7246009C5F11 /* cpart.h */, + 9277A14521FD7246009C5F11 /* cproj.hpp */, + 9277A14A21FD7246009C5F11 /* cthread.h */, + 9277A14D21FD7246009C5F11 /* md5.h */, + 9277A14F21FD7246009C5F11 /* memory_type.h */, + 9277A14E21FD7246009C5F11 /* memory.h */, + 9277A14821FD7246009C5F11 /* net.h */, + 9277A14721FD7246009C5F11 /* server.h */, + 9277A15021FD7246009C5F11 /* type.h */, ); name = include; sourceTree = ""; }; + 9277A15121FD724C009C5F11 /* src */ = { + isa = PBXGroup; + children = ( + 9277A15221FD725F009C5F11 /* addr.cpp */, + 9277A15D21FD725F009C5F11 /* client.cpp */, + 9277A15C21FD725F009C5F11 /* clock.cpp */, + 9277A15921FD725F009C5F11 /* cmap.cpp */, + 9277A15A21FD725F009C5F11 /* cpart.cpp */, + 9277A15521FD725F009C5F11 /* cproj.cpp */, + 9277A15721FD725F009C5F11 /* cthread.cpp */, + 9277A15621FD725F009C5F11 /* main.cpp */, + 9277A15421FD725F009C5F11 /* md5.cpp */, + 9277A15B21FD725F009C5F11 /* memory.cpp */, + 9277A15821FD725F009C5F11 /* server.cpp */, + 9277A15321FD725F009C5F11 /* socket.cpp */, + ); + name = src; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -169,10 +195,18 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 9221DA1121EB5FB8007310A7 /* main.cpp in Sources */, - 92A1F2A821F365D800340EFA /* memory.cpp in Sources */, - 925A13A621EC68D500CBD427 /* cpart.cpp in Sources */, - 925A13A921EC973000CBD427 /* cmap.cpp in Sources */, + 9277A16721FD725F009C5F11 /* memory.cpp in Sources */, + 9277A16821FD725F009C5F11 /* clock.cpp in Sources */, + 9277A16921FD725F009C5F11 /* client.cpp in Sources */, + 9277A16621FD725F009C5F11 /* cpart.cpp in Sources */, + 9277A16121FD725F009C5F11 /* cproj.cpp in Sources */, + 9277A16021FD725F009C5F11 /* md5.cpp in Sources */, + 9277A16521FD725F009C5F11 /* cmap.cpp in Sources */, + 9277A15F21FD725F009C5F11 /* socket.cpp in Sources */, + 9277A16321FD725F009C5F11 /* cthread.cpp in Sources */, + 9277A16221FD725F009C5F11 /* main.cpp in Sources */, + 9277A16421FD725F009C5F11 /* server.cpp in Sources */, + 9277A15E21FD725F009C5F11 /* addr.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/cmap.h b/cmap.h deleted file mode 100644 index e485abd..0000000 --- a/cmap.h +++ /dev/null @@ -1,198 +0,0 @@ -// -// cmap.hpp -// Net -// -// Created by 胡一兵 on 2019/1/14. -// Copyright © 2019年 Bakantu. All rights reserved. -// - -#ifndef cmap_h -#define cmap_h - -#include "type.h" -#include "cpart.h" - - -//计算模块管理对象间的依赖关系管理结构 -class cp_depend{ -public: -// 指向某计算模块对象 - CPart *f_cpart; -// 记录所依赖的子计算模块对象及其参数信息 - map > cdpd; -// 记录其父计算模块对象及其参数信息 - map > fdpd; -}; - -class Proj{ -// 计算工程描述文件所在的地址 - string proj_path; - string proj_file; -// 工程名 - string name; -// 计算工程读入流 - ifstream ifsproj; -// 源文件所在的目录 - vector src_paths; -// 关系描述文件所在的目录 - vector map_paths; -// 模块描述文件所在目录 - vector cpt_paths; -// 动态链接库存放的目录 - string lib_path; -// 判断参数是否为字符串 - bool if_string(string &arg){ - if(arg[0] == '\"' && arg[arg.size()-1] == '\"') return true; - else return false; - } -// 判断下一条命令的有无 - bool if_continue(string &arg){ - if(arg.find(",") != string::npos && arg[arg.size()-1] == ',') return true; - else return false; - } -// 消去字符串的双引号 - string cut_string(string &arg){ - return arg.substr(1,arg.size()-2); - } -// 处理描述文件的命令 - void deal_order(string tag, string arg){ - if(tag == "cpt"){ - cpt_paths.push_back(arg); - } - else if (tag == "map"){ - map_paths.push_back(arg); - } - else if(tag == "src_dir"){ - src_paths.push_back(arg); - } - else if(tag == "lib_dir"){ - this->lib_path = arg; - } - else throw "syntax error"; - } -protected: -// 检查路径或文件 - void check_paths(vector paths){ - for(auto path : paths){ - if(!~access((proj_path+path).data(),F_OK)) throw path+" is abnormal"; - } - } -// 检查字符是否合法 - bool if_illegal(char c){ - if(isalnum(c) || c == '_') return true; - else return false; - } -// 寻找保留字 - bool search_key(ifstream &ifsfile,string key){ - string line; - do{ - ifsfile>>line; - }while(line.find("proj") == string::npos && ifsfile.eof() == false); - if(ifsfile.eof()) return false; - return true; - } -public: - Proj(string t_projpath, string t_projfile){ -// 检查工程描述文件是否可读 - if(!~access(t_projpath.data(), R_OK)) throw "project directory state is abnormal"; - if(proj_path[proj_path.find_last_not_of(" ")] != '/') - t_projpath += "/"; - proj_path = t_projpath; - if(!~access((t_projpath+t_projfile).data(), R_OK)) throw "project file state is abnormal"; - - - proj_file = t_projfile; - ifsproj.open(proj_path+proj_file); - if(ifsproj.good()){ - string line; -// 寻找保留字 - if(!search_key(ifsproj,"proj")) throw "project struct not found"; -// 读取下一段信息 - ifsproj>>line; -// 大括号位置 - string::size_type qb_idx = line.find("{"); -// 寻找任务工程名 - string t_name; - if(qb_idx == string::npos) t_name = line; - else t_name = line.substr(0,qb_idx); -// 检查工程名是否含有非法字符 - for(auto c:t_name){ - if(if_illegal(c)); - else throw "project's name has illegal char"; - } - name = t_name; -// 寻找左大括号 - if(qb_idx == string::npos){ - ifsproj>>line; - if((qb_idx = line.find("{")) == string::npos) throw "syntax error"; - } -// 逐行分析语句 - string tag,cma,arg; - bool if_ctn = false; - do{ -// 读取命令标签 - ifsproj>>tag; -// 读取冒号 - ifsproj>>cma; -// 读取命令变量 - ifsproj>>arg; -// 检查参数是否含有非法字符 - for(auto c:t_name){ - if(if_illegal(c)); - else throw " arg has illegal char"; - } - if(cma != ":") throw "syntax error"; - if((if_ctn = if_continue(arg)) == true){ -// 消掉逗号 - arg = arg.substr(0,arg.size()-1); - } - if(if_string(arg)){ - deal_order(tag, cut_string(arg)); - } - else throw "syntax error"; - }while(if_ctn); - ifsproj>>line; - if(line != "};") throw "syntax error"; - } - else throw "fail to open project file"; -// 检查目录以及描述文件是否存在 - if(!~access((proj_path+lib_path).data(),W_OK)) throw "lib path is abnormal"; - check_paths(src_paths); - check_paths(map_paths); - check_paths(cpt_paths); - } - -}; - -class Cpt:public Proj{ - -}; - -class Map: public Cpt{ - -}; - -//计算任务图类 -class CMap{ -public: -// 计算任务图中包含的的计算模块列表 - map cparts; -// 记录计算模块依赖关系图 - map depends; -// 构造函数传入图包所在的目录 - CMap(string proj_path); -// 根据图的表述文件构造计算模块列表 - void BuildCPart(ifstream &map); -// 根据图表述文件中的描述信息,处理并转化为形式输入或输出参数列表 - vector BuidArgs(string &line); -// 根据图的表述文件构造计算模块之间的依赖关系 - void BuildConnection(ifstream &map); -// 根据图描述文件依赖关系描述语句所提供的信息转化为依赖关系结构 -// Depends ReadItem(string item); - -// 由某个节点递归向下遍历 - static void MapThrough(CPart *pcp,void(*func)(void *,CPart *),void *); - -}; - -#endif /* cmap_h */ diff --git a/clock.h b/include/clock.h similarity index 100% rename from clock.h rename to include/clock.h diff --git a/include/cmap.h b/include/cmap.h new file mode 100644 index 0000000..266a653 --- /dev/null +++ b/include/cmap.h @@ -0,0 +1,440 @@ +// +// cmap.hpp +// Net +// +// Created by 胡一兵 on 2019/1/14. +// Copyright © 2019年 Bakantu. All rights reserved. +// + +#ifndef cmap_h +#define cmap_h + +#include "type.h" +#include "cpart.h" +#include "md5.h" + +class Proj; + +//计算模块管理对象间的依赖关系管理结构 +class cp_depend{ +public: +// 指向某计算模块对象 + CPart *f_cpart; +// 记录所依赖的子计算模块对象及其参数信息 + map > cdpd; +// 记录其父计算模块对象及其参数信息 + map > fdpd; +}; + + +class setting_file{ +protected: + // 检查路径或文件 + void check_paths(string main_path, vector paths){ + for(auto path : paths){ + if(!~access((main_path+path).data(),F_OK)) throw path+" is abnormal"; + } + } + // 检查字符是否合法 + bool if_illegal(char c){ + if(isalnum(c) || c == '_') return true; + else return false; + } + // 寻找保留字 + bool search_key(ifstream &ifsfile,string key){ + string line; + do{ + ifsfile>>line; + }while(line.find(key) == string::npos && ifsfile.eof() == false); + + if(ifsfile.eof() == true) return false; + return true; + } +}; + + +struct cpt_func_args{ + string type; + int size; + string key; +}; + +class Cpt:public setting_file{ + friend Proj; + vector cparts; + vector src_files; +// 源文件内含有的入口函数 + map> funcs; +// 入口函数的输入与输出参数格式 + map> fargs_in,fargs_out; + string path; + ifstream ifscpt; + string name; +public: + + Cpt(string path, string proj_name){ + ifscpt.open(path); + string line; + if(search_key(ifscpt, "cparts")){ +// 读取下一段信息 + ifscpt>>line; +// 大括号位置 + string::size_type qb_idx = line.find("{"); +// 寻找任务工程名 + string t_name; + if(qb_idx == string::npos) t_name = line; + else t_name = line.substr(0,qb_idx); +// 检查工程名是否含有非法字符 + for(auto c:t_name){ + if(if_illegal(c)); + else throw "project's name has illegal char"; + } +// 检查工程名 + if(t_name == proj_name) name = t_name; + else throw "project's name confilct"; +// 寻找左大括号 + if(qb_idx == string::npos){ + ifscpt>>line; + if((qb_idx = line.find("{")) == string::npos) throw "syntax error"; + } +// 源文件描述遍历 + while(search_key(ifscpt, "srcfile")){ + ifscpt>>line; +// 大括号位置 + string::size_type qb_idx = line.find("{"); +// 寻找源文件名 + string tsrc_name; + if(qb_idx == string::npos) tsrc_name = line; + else tsrc_name = line.substr(0,qb_idx); + tsrc_name = tsrc_name.substr(1,tsrc_name.size()-2); +// 记录源文件名 + src_files.push_back(tsrc_name); + funcs.insert({tsrc_name,{}}); +// 寻找左大括号 + if(qb_idx == string::npos){ + ifscpt>>line; + if((qb_idx = line.find("{")) == string::npos) throw "syntax error"; + } +// 入口函数描述遍历 + while(getline(ifscpt,line)){ + string real_line; + for(auto c:line){ + if(isgraph(c) || c == ' ') real_line.push_back(c); + } + if(real_line.empty()) continue; + if(real_line != "};"){ +// 分离输出参数列表 + string::size_type dq_l = real_line.find("{"); + string::size_type dq_r = real_line.find("}"); + if(dq_l == string::npos || dq_r == string::npos) throw "syntax error"; + string str_argout = real_line.substr(dq_l+1,dq_r-dq_l-1); + vector cfgo = deal_args(str_argout); +// 分离输入参数列表 + string::size_type yq_l = real_line.find("("); + string::size_type yq_r = real_line.find(")"); + if(yq_l == string::npos || yq_r == string::npos) throw "syntax error"; + string str_argin = real_line.substr(yq_l+1,yq_r-yq_l-1); + vector cfgi = deal_args(str_argin); + +// 分离入口函数名 + string func = real_line.substr(dq_r+1,yq_l-dq_r-1); + string real_func; + for(auto c : func){ + if(isgraph(c)){ + real_func.push_back(c); + if(!if_illegal(c)) throw "func name has illegal char"; + } + } +// 添加相关参数 + fargs_out.insert({real_func,cfgo}); + fargs_in.insert({real_func,cfgi}); + + } + else break; + } + + } + + } + else throw "fail to find key word"; + } + + vector deal_args(string args){ + string::size_type lcma_dix = 0; + string::size_type cma_idx = args.find(",",0); + vector cfgs; +// 分割逗号 + while(cma_idx != string::npos){ + string arg = args.substr(lcma_dix,cma_idx-lcma_dix); + deal_arg(arg); + lcma_dix = cma_idx+1; + cma_idx = args.find(",",lcma_dix); + if(cma_idx == string::npos && lcma_dix != string::npos){ + arg = args.substr(lcma_dix,args.size()-lcma_dix); + cpt_func_args ncfg = deal_arg(arg); + cfgs.push_back(ncfg); + } + + } + return cfgs; + } + + cpt_func_args deal_arg(string arg){ + cpt_func_args ncfa; + std::stringstream ss,sr; + ss<>key; +// 读取数组标号 + string::size_type fq_l = key.find("["); + string::size_type fq_r = key.find("]"); + int size = 1; + string type; + if(fq_l != string::npos && fq_r != string::npos){ + string size_str = key.substr(fq_l+1,fq_r-fq_l-1); + sr<>size; + type = key.substr(0,fq_l); + + + } + else if (fq_r == string::npos && fq_r == string::npos){ + type = key.substr(0,fq_l); + } + else throw "syntax error"; + ncfa.size = size; + ncfa.type = type; + ss>>ncfa.key; + return ncfa; + } + +}; + +class Map: public Cpt{ + +}; + + +class Proj{ +// 计算工程描述文件所在的地址 + string proj_path; + string proj_file; +// 工程名 + string name; +// 计算工程读入流 + ifstream ifsproj; +// 源文件所在的目录 + vector src_paths; +// 源文件 + map src_files; +// 源文件的MD5 + map src_md5; +// 关系描述文件所在的目录 + vector map_paths; +// 模块描述文件所在目录 + vector cpt_paths; +// 模块描述对象 + vector cpts; +// 关系描述对象 + vector maps; +// 动态链接库存放的目录 + string lib_path; +// 判断参数是否为字符串 + bool if_string(string &arg){ + if(arg[0] == '\"' && arg[arg.size()-1] == '\"') return true; + else return false; + } +// 判断下一条命令的有无 + bool if_continue(string &arg){ + if(arg.find(",") != string::npos && arg[arg.size()-1] == ',') return true; + else return false; + } +// 消去字符串的双引号 + string cut_string(string &arg){ + return arg.substr(1,arg.size()-2); + } +// 处理描述文件的命令 + void deal_order(string tag, string arg){ + if(tag == "cpt"){ + cpt_paths.push_back(arg); + } + else if (tag == "map"){ + map_paths.push_back(arg); + } + else if(tag == "src_dir"){ + src_paths.push_back(arg); + } + else if(tag == "lib_dir"){ + this->lib_path = arg; + } + else throw "syntax error"; + } +protected: +// 检查路径或文件 + void check_paths(string main_path, vector paths){ + for(auto path : paths){ + if(!~access((main_path+path).data(),F_OK)) throw path+" is abnormal"; + } + } +// 检查字符是否合法 + bool if_illegal(char c){ + if(isalnum(c) || c == '_') return true; + else return false; + } +// 寻找保留字 + bool search_key(ifstream &ifsfile,string key){ + string line; + do{ + ifsfile>>line; + }while(line.find(key) == string::npos && ifsfile.eof() == false); + if(ifsfile.eof()) return false; + return true; + } + void build_cpts(void){ + for(auto cptp : cpt_paths){ + Cpt *ncpt = new Cpt(proj_path + cptp, name); + cpts.push_back(ncpt); + } + } + void check_cpt(void){ + + } +// 搜寻源文件目录 + void search_src(int idx,string path){ + DIR *pdir = opendir(path.data()); + struct dirent *ptr; + if(pdir != NULL){ + while ((ptr = readdir(pdir)) != NULL) { +// 如果是文件 + if(ptr->d_type == 8){ + string file = ptr->d_name; +// 含有.cpp的文件 + if(file.find(".cpp") != string::npos){ + src_files.insert({file,idx}); +// 计算源文件的MD5 + string md5; + ComputeFile(path+"/"+file, md5); + src_md5.insert({file,md5}); + } + } + } + } + else throw "path is abnormal"; + } +public: + Proj(string t_projpath, string t_projfile){ +// 检查工程描述文件是否可读 + if(!~access(t_projpath.data(), R_OK)) throw "project directory state is abnormal"; + if(proj_path[proj_path.find_last_not_of(" ")] != '/') + t_projpath += "/"; + proj_path = t_projpath; + if(!~access((t_projpath+t_projfile).data(), R_OK)) throw "project file state is abnormal"; + + + proj_file = t_projfile; + ifsproj.open(proj_path+proj_file); + if(ifsproj.good()){ + string line; +// 寻找保留字 + if(!search_key(ifsproj,"proj")) throw "project struct not found"; +// 读取下一段信息 + ifsproj>>line; +// 大括号位置 + string::size_type qb_idx = line.find("{"); +// 寻找任务工程名 + string t_name; + if(qb_idx == string::npos) t_name = line; + else t_name = line.substr(0,qb_idx); +// 检查工程名是否含有非法字符 + for(auto c:t_name){ + if(if_illegal(c)); + else throw "project's name has illegal char"; + } + name = t_name; +// 寻找左大括号 + if(qb_idx == string::npos){ + ifsproj>>line; + if((qb_idx = line.find("{")) == string::npos) throw "syntax error"; + } +// 逐行分析语句 + string tag,cma,arg; + bool if_ctn = false; + do{ +// 读取命令标签 + ifsproj>>tag; +// 读取冒号 + ifsproj>>cma; +// 读取命令变量 + ifsproj>>arg; +// 检查参数是否含有非法字符 + for(auto c:t_name){ + if(if_illegal(c)); + else throw " arg has illegal char"; + } + if(cma != ":") throw "syntax error"; + if((if_ctn = if_continue(arg)) == true){ +// 消掉逗号 + arg = arg.substr(0,arg.size()-1); + } + if(if_string(arg)){ + deal_order(tag, cut_string(arg)); + } + else throw "syntax error"; + }while(if_ctn); + ifsproj>>line; + if(line != "};") throw "syntax error"; + } + else throw "fail to open project file"; +// 检查目录以及描述文件是否存在 + if(!~access((proj_path+lib_path).data(),W_OK)) throw "lib path is abnormal"; + check_paths(proj_path,src_paths); + check_paths(proj_path,map_paths); + check_paths(proj_path,cpt_paths); + } + + void SearchPathInfo(void){ + int idx = 0; +// 遍历源文件储存目录 + for(auto path : src_paths) search_src(idx++, proj_path+path); +// 读取cpt文件 + build_cpts(); + + } + + void CheckInfo(void){ + for(auto cpt:cpts){ + for(auto file:cpt->src_files){ + if(src_files.find(file) == src_files.end()) throw "source file not exist"; + } + } + } + + +}; + + + +//计算任务图类 +class CMap{ +public: +// 计算任务图中包含的的计算模块列表 + map cparts; +// 记录计算模块依赖关系图 + map depends; +// 构造函数传入图包所在的目录 + CMap(string proj_path); +// 根据图的表述文件构造计算模块列表 + void BuildCPart(ifstream &map); +// 根据图表述文件中的描述信息,处理并转化为形式输入或输出参数列表 + vector BuidArgs(string &line); +// 根据图的表述文件构造计算模块之间的依赖关系 + void BuildConnection(ifstream &map); +// 根据图描述文件依赖关系描述语句所提供的信息转化为依赖关系结构 +// Depends ReadItem(string item); + +// 由某个节点递归向下遍历 + static void MapThrough(CPart *pcp,void(*func)(void *,CPart *),void *); + +}; + +#endif /* cmap_h */ diff --git a/compute.h b/include/compute.h similarity index 100% rename from compute.h rename to include/compute.h diff --git a/cpart.h b/include/cpart.h similarity index 100% rename from cpart.h rename to include/cpart.h diff --git a/include/cproj.hpp b/include/cproj.hpp new file mode 100644 index 0000000..2ddb6e5 --- /dev/null +++ b/include/cproj.hpp @@ -0,0 +1,14 @@ +// +// cproj.h +// Net +// +// Created by 胡一兵 on 2019/1/22. +// Copyright © 2019年 Bakantu. All rights reserved. +// + +#ifndef cproj_h +#define cproj_h + + + +#endif /* cproj_h */ diff --git a/cthread.h b/include/cthread.h similarity index 100% rename from cthread.h rename to include/cthread.h diff --git a/include/md5.h b/include/md5.h new file mode 100644 index 0000000..410a311 --- /dev/null +++ b/include/md5.h @@ -0,0 +1,51 @@ + +#ifndef MD5_H +#define MD5_H + +typedef struct +{ + unsigned int count[2]; + unsigned int state[4]; + unsigned char buffer[64]; +} MD5_CTX; + + +#define F(x,y,z) ((x & y) | (~x & z)) +#define G(x,y,z) ((x & z) | (y & ~z)) +#define H(x,y,z) (x^y^z) +#define I(x,y,z) (y ^ (x | ~z)) +#define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n))) + +#define FF(a,b,c,d,x,s,ac) \ +{ \ +a += F(b,c,d) + x + ac; \ +a = ROTATE_LEFT(a,s); \ +a += b; \ +} +#define GG(a,b,c,d,x,s,ac) \ +{ \ +a += G(b,c,d) + x + ac; \ +a = ROTATE_LEFT(a,s); \ +a += b; \ +} +#define HH(a,b,c,d,x,s,ac) \ +{ \ +a += H(b,c,d) + x + ac; \ +a = ROTATE_LEFT(a,s); \ +a += b; \ +} +#define II(a,b,c,d,x,s,ac) \ +{ \ +a += I(b,c,d) + x + ac; \ +a = ROTATE_LEFT(a,s); \ +a += b; \ +} +void MD5Init(MD5_CTX *context); +void MD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputlen); +void MD5Final(MD5_CTX *context, unsigned char digest[16]); +void MD5Transform(unsigned int state[4], unsigned char block[64]); +void MD5Encode(unsigned char *output, unsigned int *input, unsigned int len); +void MD5Decode(unsigned int *output, unsigned char *input, unsigned int len); +void ComputeFile(string path, string &md5_str); + +#endif diff --git a/memory.h b/include/memory.h similarity index 100% rename from memory.h rename to include/memory.h diff --git a/memory_type.h b/include/memory_type.h similarity index 100% rename from memory_type.h rename to include/memory_type.h diff --git a/net.h b/include/net.h similarity index 100% rename from net.h rename to include/net.h diff --git a/server.h b/include/server.h similarity index 100% rename from server.h rename to include/server.h diff --git a/type.h b/include/type.h similarity index 95% rename from type.h rename to include/type.h index dd939f0..1a8ff4c 100644 --- a/type.h +++ b/include/type.h @@ -33,6 +33,8 @@ #include #include #include +#include +#include using std::string; using std::vector; diff --git a/addr.cpp b/src/addr.cpp similarity index 100% rename from addr.cpp rename to src/addr.cpp diff --git a/client.cpp b/src/client.cpp similarity index 100% rename from client.cpp rename to src/client.cpp diff --git a/clock.cpp b/src/clock.cpp similarity index 100% rename from clock.cpp rename to src/clock.cpp diff --git a/cmap.cpp b/src/cmap.cpp similarity index 100% rename from cmap.cpp rename to src/cmap.cpp diff --git a/cpart.cpp b/src/cpart.cpp similarity index 100% rename from cpart.cpp rename to src/cpart.cpp diff --git a/src/cproj.cpp b/src/cproj.cpp new file mode 100644 index 0000000..bb735e3 --- /dev/null +++ b/src/cproj.cpp @@ -0,0 +1,9 @@ +// +// CProj.cpp +// Net +// +// Created by 胡一兵 on 2019/1/22. +// Copyright © 2019年 Bakantu. All rights reserved. +// + +#include "cproj.hpp" diff --git a/cthread.cpp b/src/cthread.cpp similarity index 100% rename from cthread.cpp rename to src/cthread.cpp diff --git a/main.cpp b/src/main.cpp similarity index 85% rename from main.cpp rename to src/main.cpp index b5077bf..b4c78b6 100644 --- a/main.cpp +++ b/src/main.cpp @@ -15,9 +15,13 @@ #include "cthread.h" -int main(void){ +int main(int argc, char *argv[]){ try{ Proj nproj("./PCS","pcs.proj"); + nproj.SearchPathInfo(); + nproj.CheckInfo(); + //Cpt ncpt("./PCS/pcs.cpt","CPTest"); + } catch(char const *error_info){ printf("%s\n",error_info); diff --git a/src/md5.cpp b/src/md5.cpp new file mode 100644 index 0000000..6a11594 --- /dev/null +++ b/src/md5.cpp @@ -0,0 +1,206 @@ +#include "type.h" +#include "md5.h" + + +unsigned char PADDING[] = +{ + 0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +}; + +void MD5Init(MD5_CTX *context) +{ + context->count[0] = 0; + context->count[1] = 0; + context->state[0] = 0x67452301; + context->state[1] = 0xEFCDAB89; + context->state[2] = 0x98BADCFE; + context->state[3] = 0x10325476; +} + +void MD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputlen) +{ + unsigned int i = 0; + unsigned int index = 0; + unsigned int partlen = 0; + + index = (context->count[0] >> 3) & 0x3F; + partlen = 64 - index; + context->count[0] += inputlen << 3; + + if(context->count[0] < (inputlen << 3)) + context->count[1]++; + context->count[1] += inputlen >> 29; + + if(inputlen >= partlen) + { + memcpy(&context->buffer[index], input,partlen); + MD5Transform(context->state, context->buffer); + + for(i = partlen; i+64 <= inputlen; i+=64) + MD5Transform(context->state, &input[i]); + + index = 0; + } + else + { + i = 0; + } + memcpy(&context->buffer[index], &input[i], inputlen-i); +} + +void MD5Final(MD5_CTX *context, unsigned char digest[16]) +{ + unsigned int index = 0,padlen = 0; + unsigned char bits[8]; + + index = (context->count[0] >> 3) & 0x3F; + padlen = (index < 56)?(56-index):(120-index); + MD5Encode(bits, context->count, 8); + MD5Update(context, PADDING, padlen); + MD5Update(context, bits, 8); + MD5Encode(digest, context->state, 16); +} + +void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len) +{ + unsigned int i = 0; + unsigned int j = 0; + + while(j < len) + { + output[j] = input[i] & 0xFF; + output[j+1] = (input[i] >> 8) & 0xFF; + output[j+2] = (input[i] >> 16) & 0xFF; + output[j+3] = (input[i] >> 24) & 0xFF; + i++; + j += 4; + } +} + +void MD5Decode(unsigned int *output, unsigned char *input, unsigned int len) +{ + unsigned int i = 0; + unsigned int j = 0; + + while(j < len) + { + output[i] = (input[j]) | + (input[j+1] << 8) | + (input[j+2] << 16) | + (input[j+3] << 24); + i++; + j += 4; + } +} + +void MD5Transform(unsigned int state[4], unsigned char block[64]) +{ + unsigned int a = state[0]; + unsigned int b = state[1]; + unsigned int c = state[2]; + unsigned int d = state[3]; + unsigned int x[64]; + + MD5Decode(x,block,64); + + FF(a, b, c, d, x[ 0], 7, 0xd76aa478); /* 1 */ + FF(d, a, b, c, x[ 1], 12, 0xe8c7b756); /* 2 */ + FF(c, d, a, b, x[ 2], 17, 0x242070db); /* 3 */ + FF(b, c, d, a, x[ 3], 22, 0xc1bdceee); /* 4 */ + FF(a, b, c, d, x[ 4], 7, 0xf57c0faf); /* 5 */ + FF(d, a, b, c, x[ 5], 12, 0x4787c62a); /* 6 */ + FF(c, d, a, b, x[ 6], 17, 0xa8304613); /* 7 */ + FF(b, c, d, a, x[ 7], 22, 0xfd469501); /* 8 */ + FF(a, b, c, d, x[ 8], 7, 0x698098d8); /* 9 */ + FF(d, a, b, c, x[ 9], 12, 0x8b44f7af); /* 10 */ + FF(c, d, a, b, x[10], 17, 0xffff5bb1); /* 11 */ + FF(b, c, d, a, x[11], 22, 0x895cd7be); /* 12 */ + FF(a, b, c, d, x[12], 7, 0x6b901122); /* 13 */ + FF(d, a, b, c, x[13], 12, 0xfd987193); /* 14 */ + FF(c, d, a, b, x[14], 17, 0xa679438e); /* 15 */ + FF(b, c, d, a, x[15], 22, 0x49b40821); /* 16 */ + + /* Round 2 */ + GG(a, b, c, d, x[ 1], 5, 0xf61e2562); /* 17 */ + GG(d, a, b, c, x[ 6], 9, 0xc040b340); /* 18 */ + GG(c, d, a, b, x[11], 14, 0x265e5a51); /* 19 */ + GG(b, c, d, a, x[ 0], 20, 0xe9b6c7aa); /* 20 */ + GG(a, b, c, d, x[ 5], 5, 0xd62f105d); /* 21 */ + GG(d, a, b, c, x[10], 9, 0x2441453); /* 22 */ + GG(c, d, a, b, x[15], 14, 0xd8a1e681); /* 23 */ + GG(b, c, d, a, x[ 4], 20, 0xe7d3fbc8); /* 24 */ + GG(a, b, c, d, x[ 9], 5, 0x21e1cde6); /* 25 */ + GG(d, a, b, c, x[14], 9, 0xc33707d6); /* 26 */ + GG(c, d, a, b, x[ 3], 14, 0xf4d50d87); /* 27 */ + GG(b, c, d, a, x[ 8], 20, 0x455a14ed); /* 28 */ + GG(a, b, c, d, x[13], 5, 0xa9e3e905); /* 29 */ + GG(d, a, b, c, x[ 2], 9, 0xfcefa3f8); /* 30 */ + GG(c, d, a, b, x[ 7], 14, 0x676f02d9); /* 31 */ + GG(b, c, d, a, x[12], 20, 0x8d2a4c8a); /* 32 */ + + /* Round 3 */ + HH(a, b, c, d, x[ 5], 4, 0xfffa3942); /* 33 */ + HH(d, a, b, c, x[ 8], 11, 0x8771f681); /* 34 */ + HH(c, d, a, b, x[11], 16, 0x6d9d6122); /* 35 */ + HH(b, c, d, a, x[14], 23, 0xfde5380c); /* 36 */ + HH(a, b, c, d, x[ 1], 4, 0xa4beea44); /* 37 */ + HH(d, a, b, c, x[ 4], 11, 0x4bdecfa9); /* 38 */ + HH(c, d, a, b, x[ 7], 16, 0xf6bb4b60); /* 39 */ + HH(b, c, d, a, x[10], 23, 0xbebfbc70); /* 40 */ + HH(a, b, c, d, x[13], 4, 0x289b7ec6); /* 41 */ + HH(d, a, b, c, x[ 0], 11, 0xeaa127fa); /* 42 */ + HH(c, d, a, b, x[ 3], 16, 0xd4ef3085); /* 43 */ + HH(b, c, d, a, x[ 6], 23, 0x4881d05); /* 44 */ + HH(a, b, c, d, x[ 9], 4, 0xd9d4d039); /* 45 */ + HH(d, a, b, c, x[12], 11, 0xe6db99e5); /* 46 */ + HH(c, d, a, b, x[15], 16, 0x1fa27cf8); /* 47 */ + HH(b, c, d, a, x[ 2], 23, 0xc4ac5665); /* 48 */ + + /* Round 4 */ + II(a, b, c, d, x[ 0], 6, 0xf4292244); /* 49 */ + II(d, a, b, c, x[ 7], 10, 0x432aff97); /* 50 */ + II(c, d, a, b, x[14], 15, 0xab9423a7); /* 51 */ + II(b, c, d, a, x[ 5], 21, 0xfc93a039); /* 52 */ + II(a, b, c, d, x[12], 6, 0x655b59c3); /* 53 */ + II(d, a, b, c, x[ 3], 10, 0x8f0ccc92); /* 54 */ + II(c, d, a, b, x[10], 15, 0xffeff47d); /* 55 */ + II(b, c, d, a, x[ 1], 21, 0x85845dd1); /* 56 */ + II(a, b, c, d, x[ 8], 6, 0x6fa87e4f); /* 57 */ + II(d, a, b, c, x[15], 10, 0xfe2ce6e0); /* 58 */ + II(c, d, a, b, x[ 6], 15, 0xa3014314); /* 59 */ + II(b, c, d, a, x[13], 21, 0x4e0811a1); /* 60 */ + II(a, b, c, d, x[ 4], 6, 0xf7537e82); /* 61 */ + II(d, a, b, c, x[11], 10, 0xbd3af235); /* 62 */ + II(c, d, a, b, x[ 2], 15, 0x2ad7d2bb); /* 63 */ + II(b, c, d, a, x[ 9], 21, 0xeb86d391); /* 64 */ + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; +} + +void ComputeFile(string path, string &md5_str){ + int fd; + ssize_t ret; + unsigned char buff[1024],md5_value[16]; + MD5_CTX md5; + fd = open(path.data(), O_RDONLY); + MD5Init(&md5); + while (1){ + ret = read(fd, (void *)buff, 1024); + MD5Update(&md5, buff, (unsigned int)ret); + if (0 == ret || ret < 1024) break; + } + close(fd); + MD5Final(&md5, md5_value); + char tmp[33]; + + for(int i = 0; i < 16; i++){ + snprintf(tmp+i*2, 3, "%02x", md5_value[i]); + } + tmp[32] = '\0'; + md5_str = tmp; +} diff --git a/memory.cpp b/src/memory.cpp similarity index 100% rename from memory.cpp rename to src/memory.cpp diff --git a/server.cpp b/src/server.cpp similarity index 100% rename from server.cpp rename to src/server.cpp diff --git a/socket.cpp b/src/socket.cpp similarity index 100% rename from socket.cpp rename to src/socket.cpp