From be3f8f560565d987152c6cd5fee75712b73b5875 Mon Sep 17 00:00:00 2001 From: xiyoo0812 Date: Wed, 8 May 2024 06:39:22 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0xml=E5=BA=93=E5=92=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96zip=E5=BA=93=201=E3=80=81=E6=B7=BB=E5=8A=A0xm?= =?UTF-8?q?l=E5=BA=93=E6=94=AF=E6=8C=81=202=E3=80=81zip=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BB=8Equanta=E5=89=A5=E7=A6=BB=EF=BC=8C=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=E6=88=90=E5=BA=93=203=E3=80=81lmake=E5=8A=9F=E8=83=BD=E6=89=A9?= =?UTF-8?q?=E5=B1=95=EF=BC=8C=E6=94=AF=E6=8C=81=E5=A4=9A=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9B=AE=E5=BD=95=EF=BC=8C=E4=BC=98=E5=8C=96=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E7=94=9F=E6=88=90=204=E3=80=81=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=BC=96=E8=AF=91=E8=AD=A6=E5=91=8A=205?= =?UTF-8?q?=E3=80=81excel=E5=8C=BA=E5=9F=9F=E8=8E=B7=E5=8F=96=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .luacheckrc | 2 +- Makefile | 3 +- core/luabus/luabus.lmak | 7 +- core/luabus/luabus.mak | 47 +- core/luabus/luabus.vcxproj | 2 +- core/luabus/luabus.vcxproj.filters | 25 +- core/luabus/src/socket_router.cpp | 3 +- core/luabus/src/socket_router.h | 2 +- core/quanta/quanta.lmak | 8 +- core/quanta/quanta.mak | 35 +- core/quanta/quanta.vcxproj | 9 +- core/quanta/quanta.vcxproj.filters | 14 +- core/quanta/src/main.cpp | 5 +- core/quanta/src/quanta.cpp | 137 -- core/quanta/src/quanta.h | 13 - extend/laoi/laoi.mak | 34 +- extend/laoi/laoi.vcxproj.filters | 5 +- extend/lbson/lbson.mak | 34 +- extend/lbson/lbson.vcxproj.filters | 5 +- extend/lbson/src/bson.h | 2 +- extend/lbson/src/lbson.cpp | 2 +- extend/lcodec/lcodec.lmak | 4 + extend/lcodec/lcodec.mak | 35 +- extend/lcodec/lcodec.vcxproj.filters | 21 +- extend/lcodec/src/guid.h | 4 +- extend/lcodec/src/mysql.h | 2 +- extend/lcodec/src/websocket.h | 2 +- extend/ldetour/ldetour.lmak | 6 +- extend/ldetour/ldetour.mak | 50 +- extend/ldetour/ldetour.vcxproj.filters | 43 +- extend/ljson/ljson.lmak | 4 - extend/ljson/ljson.mak | 36 +- extend/ljson/ljson.vcxproj.filters | 7 +- extend/ljson/src/ljson.h | 25 +- extend/lmake/lmake.lua | 52 +- extend/lmake/share.lua | 16 +- extend/lmake/tmpl/filters.tpl | 22 +- extend/lmake/tmpl/make.tpl | 68 +- extend/lmake/tmpl/vcxproj.tpl | 10 +- extend/lmake/tmpl/vcxprojps.tpl | 11 +- extend/lmdb/lmdb.lmak | 4 - extend/lmdb/lmdb.mak | 37 +- extend/lmdb/lmdb.vcxproj.filters | 9 +- .../miniz.lmak => lminiz/lminiz.lmak} | 27 +- .../{luaxlsx/miniz.mak => lminiz/lminiz.mak} | 44 +- .../miniz.vcxproj => lminiz/lminiz.vcxproj} | 24 +- .../lminiz.vcxproj.filters} | 17 +- extend/lminiz/src/lminiz.cpp | 169 +++ extend/lminiz/src/lminiz.h | 10 + extend/{luaxlsx => lminiz}/src/miniz.c | 0 extend/{luaxlsx => lminiz}/src/miniz.h | 0 extend/lsqlite/lsqlite.mak | 36 +- extend/lsqlite/lsqlite.vcxproj.filters | 7 +- extend/lssl/lssl.lmak | 9 +- extend/lssl/lssl.mak | 203 +-- extend/lssl/lssl.vcxproj | 36 - extend/lssl/lssl.vcxproj.filters | 622 ++++----- extend/lssl/src/ssl/lssl.cpp | 8 +- extend/lssl/src/ssl/lssl.h | 4 +- extend/lstdfs/lstdfs.mak | 34 +- extend/ltimer/ltimer.lmak | 3 - extend/ltimer/ltimer.mak | 34 +- extend/ltimer/ltimer.vcxproj | 4 +- extend/ltimer/ltimer.vcxproj.filters | 9 +- extend/ltimer/{ltimer => src}/ltimer.cpp | 0 extend/ltimer/{ltimer => src}/ltimer.h | 0 extend/lua/lua.lmak | 4 +- extend/lua/lua.mak | 33 +- extend/lua/lua.vcxproj | 102 -- extend/lua/lua.vcxproj.filters | 167 +-- extend/lua/luac.lmak | 4 +- extend/lua/luac.mak | 33 +- extend/lua/luac.vcxproj | 102 -- extend/lua/luac.vcxproj.filters | 167 +-- extend/lua/lualib.lmak | 4 +- extend/lua/lualib.mak | 33 +- extend/lua/lualib.vcxproj | 102 -- extend/lua/lualib.vcxproj.filters | 167 +-- extend/luakit/include/lua_base.h | 18 + extend/luakit/include/lua_codec.h | 27 +- extend/luakit/include/lua_reference.h | 2 +- extend/luakit/luakit.lmak | 4 +- extend/lualog/lualog.lmak | 4 +- extend/lualog/lualog.mak | 35 +- extend/lualog/lualog.vcxproj.filters | 13 +- extend/luapb/luapb.lmak | 4 +- extend/luapb/luapb.mak | 33 +- extend/luapb/luapb.vcxproj | 3 - extend/luapb/luapb.vcxproj.filters | 8 +- extend/luaxlsx/luaxlsx.lmak | 20 +- extend/luaxlsx/luaxlsx.mak | 41 +- extend/luaxlsx/luaxlsx.vcxproj | 11 +- extend/luaxlsx/luaxlsx.vcxproj.filters | 32 +- extend/luaxlsx/src/excel.h | 41 +- extend/luaxml/luaxml.lmak | 38 + extend/luaxml/luaxml.mak | 129 ++ extend/luaxml/luaxml.vcxproj | 79 ++ extend/luaxml/luaxml.vcxproj.filters | 21 + extend/luaxml/src/luaxml.cpp | 216 +++ extend/{luaxlsx => luaxml}/src/tinyxml2.cpp | 1186 ++++++++++++----- extend/{luaxlsx => luaxml}/src/tinyxml2.h | 774 +++++++---- extend/lunqlite/lunqlite.lmak | 1 + extend/lunqlite/lunqlite.mak | 36 +- extend/lunqlite/lunqlite.vcxproj.filters | 7 +- extend/lworker/lworker.lmak | 2 +- extend/lworker/lworker.mak | 36 +- extend/lworker/lworker.vcxproj | 2 +- extend/lworker/lworker.vcxproj.filters | 7 +- extend/mimalloc/mimalloc.lmak | 19 +- extend/mimalloc/mimalloc.mak | 60 +- extend/mimalloc/mimalloc.vcxproj | 13 +- extend/mimalloc/mimalloc.vcxproj.filters | 61 +- quanta.sln | 27 +- script/basic/library.lua | 4 + script/kernel/protobuf_mgr.lua | 2 +- script/sandbox.lua | 3 +- server/test.lua | 3 +- server/test/xml_test.lua | 113 ++ 118 files changed, 3410 insertions(+), 2805 deletions(-) rename extend/{luaxlsx/miniz.lmak => lminiz/lminiz.lmak} (56%) rename extend/{luaxlsx/miniz.mak => lminiz/lminiz.mak} (74%) rename extend/{luaxlsx/miniz.vcxproj => lminiz/lminiz.vcxproj} (78%) rename extend/{luaxlsx/miniz.vcxproj.filters => lminiz/lminiz.vcxproj.filters} (58%) create mode 100644 extend/lminiz/src/lminiz.cpp create mode 100644 extend/lminiz/src/lminiz.h rename extend/{luaxlsx => lminiz}/src/miniz.c (100%) rename extend/{luaxlsx => lminiz}/src/miniz.h (100%) rename extend/ltimer/{ltimer => src}/ltimer.cpp (100%) rename extend/ltimer/{ltimer => src}/ltimer.h (100%) create mode 100644 extend/luaxml/luaxml.lmak create mode 100644 extend/luaxml/luaxml.mak create mode 100644 extend/luaxml/luaxml.vcxproj create mode 100644 extend/luaxml/luaxml.vcxproj.filters create mode 100644 extend/luaxml/src/luaxml.cpp rename extend/{luaxlsx => luaxml}/src/tinyxml2.cpp (65%) rename extend/{luaxlsx => luaxml}/src/tinyxml2.h (71%) create mode 100644 server/test/xml_test.lua diff --git a/.luacheckrc b/.luacheckrc index 974bef55..b5a49403 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -7,7 +7,7 @@ stds.quanta = { "import", "class", "enum", "mixin", "property", "singleton", "super", "implemented", "logfeature", "db_property", "classof", "is_class", "is_subclass", "instanceof", "conv_class", "class_review", "codec", "stdfs", "luabus", "luakit", "json", "protobuf", "timer", "aoi", "log", "worker", "http", "bson", - "detour", "lmdb", "unqlite", "sqlite", "ssl" + "detour", "lmdb", "unqlite", "sqlite", "ssl", "xml", "zip" } } std = "max+quanta" diff --git a/Makefile b/Makefile index 29c3122c..fe9ba284 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,7 @@ luaext: cd extend/ldetour; make SOLUTION_DIR=$(CUR_DIR) -f ldetour.mak; cd extend/ljson; make SOLUTION_DIR=$(CUR_DIR) -f ljson.mak; cd extend/lmdb; make SOLUTION_DIR=$(CUR_DIR) -f lmdb.mak; + cd extend/lminiz; make SOLUTION_DIR=$(CUR_DIR) -f lminiz.mak; cd extend/lsqlite; make SOLUTION_DIR=$(CUR_DIR) -f lsqlite.mak; cd extend/lssl; make SOLUTION_DIR=$(CUR_DIR) -f lssl.mak; cd extend/lstdfs; make SOLUTION_DIR=$(CUR_DIR) -f lstdfs.mak; @@ -37,10 +38,10 @@ luaext: cd extend/lualog; make SOLUTION_DIR=$(CUR_DIR) -f lualog.mak; cd extend/luapb; make SOLUTION_DIR=$(CUR_DIR) -f luapb.mak; cd extend/luaxlsx; make SOLUTION_DIR=$(CUR_DIR) -f luaxlsx.mak; + cd extend/luaxml; make SOLUTION_DIR=$(CUR_DIR) -f luaxml.mak; cd extend/lunqlite; make SOLUTION_DIR=$(CUR_DIR) -f lunqlite.mak; cd extend/lworker; make SOLUTION_DIR=$(CUR_DIR) -f lworker.mak; share: cd extend/mimalloc; make SOLUTION_DIR=$(CUR_DIR) -f mimalloc.mak; - cd extend/luaxlsx; make SOLUTION_DIR=$(CUR_DIR) -f miniz.mak; diff --git a/core/luabus/luabus.lmak b/core/luabus/luabus.lmak index 977ce57f..c3af77f8 100644 --- a/core/luabus/luabus.lmak +++ b/core/luabus/luabus.lmak @@ -7,13 +7,14 @@ TARGET_NAME = "luabus" --工程类型: static/dynamic/exe PROJECT_TYPE = "dynamic" ---是否生效 -ENABLE = true +FLAGS = { + "Wno-extra" +} --需要的include目录 INCLUDES = { "../../extend/lua/lua", - "../../extend/ltimer/ltimer", + "../../extend/ltimer/src", "../../extend/luakit/include" } diff --git a/core/luabus/luabus.mak b/core/luabus/luabus.mak index d7c432d7..15fbb0e6 100644 --- a/core/luabus/luabus.mak +++ b/core/luabus/luabus.mak @@ -15,13 +15,12 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas +MYCFLAGS += -Wno-extra #c标准库版本 #gnu99/gnu11/gnu17 @@ -33,7 +32,7 @@ STDCPP = -std=c++17 #需要的include目录 MYCFLAGS += -I../../extend/lua/lua -MYCFLAGS += -I../../extend/ltimer/ltimer +MYCFLAGS += -I../../extend/ltimer/src MYCFLAGS += -I../../extend/luakit/include #需要定义的选项 @@ -42,12 +41,6 @@ MYCFLAGS += -I../../extend/luakit/include LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -67,8 +60,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -99,21 +92,32 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/lua_socket_mgr.cpp +SOURCES += src/lua_socket_node.cpp +SOURCES += src/luabus.cpp +SOURCES += src/socket_helper.cpp +SOURCES += src/socket_listener.cpp +SOURCES += src/socket_mgr.cpp +SOURCES += src/socket_router.cpp +SOURCES += src/socket_stream.cpp +SOURCES += src/socket_tcp.cpp +SOURCES += src/socket_udp.cpp +SOURCES += src/stdafx.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -130,6 +134,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/core/luabus/luabus.vcxproj b/core/luabus/luabus.vcxproj index 028c8cc6..9c87ecbe 100644 --- a/core/luabus/luabus.vcxproj +++ b/core/luabus/luabus.vcxproj @@ -65,7 +65,7 @@ Disabled - ..\..\extend\lua\lua;..\..\extend\ltimer\ltimer;..\..\extend\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) + ..\..\extend\lua\lua;..\..\extend\ltimer\src;..\..\extend\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default MultiThreadedDLL diff --git a/core/luabus/luabus.vcxproj.filters b/core/luabus/luabus.vcxproj.filters index 2d30afae..1b15cfd2 100644 --- a/core/luabus/luabus.vcxproj.filters +++ b/core/luabus/luabus.vcxproj.filters @@ -2,37 +2,37 @@ - inc + src - inc + src - inc + src - inc + src - inc + src - inc + src - inc + src - inc + src - inc + src - inc + src - inc + src @@ -71,9 +71,6 @@ - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/core/luabus/src/socket_router.cpp b/core/luabus/src/socket_router.cpp index f7c554d3..a90ebb54 100644 --- a/core/luabus/src/socket_router.cpp +++ b/core/luabus/src/socket_router.cpp @@ -80,7 +80,7 @@ bool socket_router::do_forward_master(router_header* header, char* data, size_t return true; } -bool socket_router::do_forward_broadcast(router_header* header, int source, char* data, size_t data_len, size_t& broadcast_num) { +bool socket_router::do_forward_broadcast(router_header* header, uint32_t source, char* data, size_t data_len, size_t& broadcast_num) { uint16_t service_id = (uint16_t)header->target_id; uint8_t flag = header->context & 0xf; @@ -89,7 +89,6 @@ bool socket_router::do_forward_broadcast(router_header* header, int source, char auto& services = m_services[service_id]; auto& nodes = services.nodes; - int count = (int)nodes.size(); for (auto& target : nodes) { if (target.token != 0 && target.token != source) { m_mgr->sendv(target.token, items, _countof(items)); diff --git a/core/luabus/src/socket_router.h b/core/luabus/src/socket_router.h index 3c7ae16c..f946f0a5 100644 --- a/core/luabus/src/socket_router.h +++ b/core/luabus/src/socket_router.h @@ -56,7 +56,7 @@ class socket_router bool do_forward_hash(router_header* header, char* data, size_t data_len); bool do_forward_target(router_header* header, char* data, size_t data_len); bool do_forward_master(router_header* header, char* data, size_t data_len); - bool do_forward_broadcast(router_header* header, int source, char* data, size_t data_len, size_t& broadcast_num); + bool do_forward_broadcast(router_header* header, uint32_t source, char* data, size_t data_len, size_t& broadcast_num); private: size_t m_route_count = 0; diff --git a/core/quanta/quanta.lmak b/core/quanta/quanta.lmak index 15791e38..fb091294 100644 --- a/core/quanta/quanta.lmak +++ b/core/quanta/quanta.lmak @@ -24,7 +24,6 @@ INCLUDES = { --需要连接的库文件 LIBS = { "lua", - "miniz", "lualog" } @@ -34,10 +33,6 @@ LINUX_LIBS = { "stdc++fs" } -OBJS = { - "quanta.cpp", "main.cpp" -} - --非WINDOWS预编译命令 --格式: cmd --"cp -r bin/libcurl-x64.dll $(SolutionDir)bin" @@ -54,7 +49,8 @@ NWINDOWS_POSTBUILDS = { --依赖项目 DEPS = { - "miniz", + "lminiz", + "luabus", "lualog" } diff --git a/core/quanta/quanta.mak b/core/quanta/quanta.mak index a0c90256..633a359d 100644 --- a/core/quanta/quanta.mak +++ b/core/quanta/quanta.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas #c标准库版本 #gnu99/gnu11/gnu17 @@ -45,12 +43,6 @@ MYCFLAGS += -DFMT_HEADER_ONLY LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -60,7 +52,6 @@ MYCFLAGS += -I$(SOLUTION_DIR)extend/mimalloc/mimalloc/include -include ../../mim endif #自定义库 LIBS += -llua -LIBS += -lminiz LIBS += -llualog ifeq ($(UNAME_S), Linux) LIBS += -lstdc++fs @@ -75,8 +66,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -96,20 +87,23 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -COBJS = $(patsubst %.c, $(INT_DIR)/%.o, quanta.cpp main.cpp) -MOBJS = $(patsubst %.m, $(INT_DIR)/%.o, $(COBJS)) -CCOBJS = $(patsubst %.cc, $(INT_DIR)/%.o, $(MOBJS)) -OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCOBJS)) +SOURCES = +SOURCES += src/main.cpp +SOURCES += src/quanta.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_EXECUTE) : $(OBJS) @@ -126,6 +120,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src ln -s $(TARGET_DIR)/lualog.so $(TARGET_DIR)/liblualog.so #后编译 diff --git a/core/quanta/quanta.vcxproj b/core/quanta/quanta.vcxproj index b9563ec9..6f2078f7 100644 --- a/core/quanta/quanta.vcxproj +++ b/core/quanta/quanta.vcxproj @@ -7,17 +7,10 @@ - - - true - - - true - @@ -71,7 +64,7 @@ Console $(SolutionDir)library\$(Platform)\$(TargetName).lib $(SolutionDir)temp\$(ProjectName)\$(Platform)\$(TargetName).pdb - lua.lib;miniz.lib;lualog.lib;mimalloc.lib;%(AdditionalDependencies) + lua.lib;lualog.lib;mimalloc.lib;%(AdditionalDependencies) diff --git a/core/quanta/quanta.vcxproj.filters b/core/quanta/quanta.vcxproj.filters index f809558c..9f252f96 100644 --- a/core/quanta/quanta.vcxproj.filters +++ b/core/quanta/quanta.vcxproj.filters @@ -1,31 +1,19 @@  - - inc - - inc + src - - src - src - - src - src - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/core/quanta/src/main.cpp b/core/quanta/src/main.cpp index de04781c..e5911b84 100644 --- a/core/quanta/src/main.cpp +++ b/core/quanta/src/main.cpp @@ -8,10 +8,11 @@ int main(int argc, const char* argv[]) { - setlocale(LC_ALL, ""); +#ifdef WIN32 + setlocale(LC_ALL, ".UTF8"); +#endif #if !(defined(__ORBIS__) || defined(__PROSPERO__)) tzset(); - system("echo quanta engine init."); #endif quanta_app q_app; q_app.set_env("QUANTA_DYNAMIC", "1"); diff --git a/core/quanta/src/quanta.cpp b/core/quanta/src/quanta.cpp index d752d2a4..9c7c7cac 100644 --- a/core/quanta/src/quanta.cpp +++ b/core/quanta/src/quanta.cpp @@ -75,17 +75,6 @@ static void check_input(luakit::kit_state& lua) { #endif } -quanta_app::quanta_app() { - mz_zip_zero_struct(&m_archive); -} - -quanta_app::~quanta_app() { - if (m_archive.m_pState){ - mz_zip_reader_end(&m_archive); - mz_zip_zero_struct(&m_archive); - } -} - void quanta_app::set_signal(uint32_t n, bool b) { uint32_t mask = 1 << n; if (b) { @@ -119,126 +108,6 @@ void quanta_app::set_path(std::string field, std::string path) { #endif } -bool quanta_app::initzip(const char* zfile) { - memset(&m_archive, 0, sizeof(m_archive)); - if(!mz_zip_reader_init_file(&m_archive, zfile, 0)){ - return false; - } - m_lua.set_searchers([&](lua_State* L) { - const char* fname = luaL_checkstring(L, 1); - int index = find_zip_file(L, fname); - if (index < 0) { - lua_pushstring(L, fmt::format("file {} not found in zip!", fname).c_str()); - return 1; - } - if (load_zip_data(L, fname, index) == LUA_OK) { - lua_pushstring(L, fname); /* will be 2nd argument to module */ - return 2; /* return open function and file name */ - } - return luaL_error(L, "error loading module '%s' from file '%s':\n\t%s", lua_tostring(L, 1), fname, lua_tostring(L, -1)); - }); - m_lua.set_function("dofile", [&](lua_State* L) { - const char* fname = luaL_optstring(L, 1, NULL); - lua_settop(L, 1); - if (load_zip_file(L) != LUA_OK) { - return lua_error(L); - } - auto kf = [](lua_State* L, int d1, lua_KContext d2) { return lua_gettop(L) - 1; }; - lua_callk(L, 0, LUA_MULTRET, 0, kf); - return kf(L, 0, 0); - }); - m_lua.set_function("loadfile", [&](lua_State* L) { - int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */ - if (load_zip_file(L) == LUA_OK) { - if (env != 0) { /* 'env' parameter? */ - lua_pushvalue(L, env); /* environment for loaded function */ - if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */ - lua_pop(L, 1); /* remove 'env' if not used by previous call */ - } - return 1; - } - //error(message is on top of the stack)* / - lua_pushnil(L); - lua_insert(L, -2); - return 2; - }); - return true; -} - -int quanta_app::find_zip_file(lua_State* L, std::string filename) { - size_t start_pos = 0; - luakit::lua_guard g(L); - lua_getglobal(L, LUA_LOADLIBNAME); - lua_getfield(L, -1, "path"); - std::string path = lua_tostring(L, -1); - while ((start_pos = filename.find(".", start_pos)) != std::string::npos) { - filename.replace(start_pos, strlen("."), LUA_DIRSEP); - start_pos += strlen(LUA_DIRSEP); - } - start_pos = 0; - while ((start_pos = path.find(LUA_PATH_MARK, start_pos)) != std::string::npos) { - path.replace(start_pos, strlen(LUA_PATH_MARK), filename); - start_pos += filename.size(); - } - start_pos = 0; - while ((start_pos = path.find(LUA_DIRSEP, start_pos)) != std::string::npos) { - path.replace(start_pos, strlen(LUA_DIRSEP), "/"); - start_pos += strlen("/"); - } - size_t cur = 0, pos = 0; - while ((pos = path.find(LUA_PATH_SEP, cur)) != std::string::npos) { - std::string sub = path.substr(cur, pos - cur); - int index = mz_zip_reader_locate_file(&m_archive, sub.c_str(), nullptr, MZ_ZIP_FLAG_CASE_SENSITIVE); - if (index > 0) { - return index; - } - cur = pos + strlen(LUA_PATH_SEP); - } - if (path.size() > cur) { - std::string sub = path.substr(cur); - return mz_zip_reader_locate_file(&m_archive, sub.c_str(), nullptr, MZ_ZIP_FLAG_CASE_SENSITIVE); - } - return -1; -} - -bool quanta_app::zip_exist(const char* fname) { - return mz_zip_reader_locate_file(&m_archive, fname, nullptr, MZ_ZIP_FLAG_CASE_SENSITIVE) > 0; -} - -int quanta_app::zip_load(lua_State* L) { - const char* fname = luaL_optstring(L, 1, nullptr); - int index = mz_zip_reader_locate_file(&m_archive, fname, nullptr, MZ_ZIP_FLAG_CASE_SENSITIVE); - if (index <= 0) return 0; - size_t size = 0; - const char* data = (const char*)mz_zip_reader_extract_to_heap(&m_archive, index, &size, MZ_ZIP_FLAG_CASE_SENSITIVE); - if (!data) return 0; - lua_pushlstring(L, data, size); - delete[] data; - return 1; -} - -int quanta_app::load_zip_file(lua_State* L) { - const char* fname = luaL_optstring(L, 1, nullptr); - int index = mz_zip_reader_locate_file(&m_archive, fname, nullptr, MZ_ZIP_FLAG_CASE_SENSITIVE); - if (index <= 0) { - lua_pushstring(L, fmt::format("file {} not found in zip!", fname).c_str()); - return LUA_ERRERR; - } - return load_zip_data(L, fname, index); -} - -int quanta_app::load_zip_data(lua_State* L, const char* filename, int index) { - size_t size = 0; - const char* data = (const char*)mz_zip_reader_extract_to_heap(&m_archive, index, &size, MZ_ZIP_FLAG_CASE_SENSITIVE); - if (!data) { - lua_pushstring(L, "file read failed!"); - return LUA_ERRERR; - } - int status = luaL_loadbufferx(L, data, size, filename, luaL_optstring(L, 2, nullptr)); - delete[] data; - return status; -} - void quanta_app::setup(int argc, const char* argv[]) { srand((unsigned)time(nullptr)); //初始化日志 @@ -272,7 +141,6 @@ void quanta_app::load(int argc, const char* argv[]) { if (i == 1){ //加载LUA配置 m_lua.set("platform", get_platform()); - m_lua.set_function("init_zip", [&](std::string zfile) { return initzip(zfile.c_str()); }); m_lua.set_function("set_env", [&](std::string key, std::string value) { return set_env(key, value, 1); }); m_lua.set_function("set_path", [&](std::string field, std::string path) { return set_path(field, path); }); m_lua.run_script(fmt::format("dofile('{}')", argv[1]), [&](std::string_view err) { @@ -295,8 +163,6 @@ luakit::lua_table quanta_app::init() { quanta.set_function("ignore_signal", [](int n) { signal(n, SIG_IGN); }); quanta.set_function("default_signal", [](int n) { signal(n, SIG_DFL); }); quanta.set_function("register_signal", [](int n) { signal(n, on_signal); }); - quanta.set_function("zload", [&](lua_State* L) { return zip_load(L); }); - quanta.set_function("zexist", [&](const char* fn) { return zip_exist(fn); }); quanta.set_function("getenv", [&](const char* key) { return get_env(key); }); quanta.set_function("setenv", [&](std::string key, std::string value) { return set_env(key, value, 1); }); @@ -306,9 +172,6 @@ luakit::lua_table quanta_app::init() { const char* env_service = get_env("QUANTA_SERVICE"); logger::get_logger()->option(env_log_path, env_service, env_index); } -#ifdef WIN32 - m_lua.run_script("os.setlocale('.UTF8')"); -#endif m_lua.run_script(fmt::format("require '{}'", get_env("QUANTA_SANDBOX")), [&](std::string_view err) { exception_handler("load sandbox err: {}", err); }); diff --git a/core/quanta/src/quanta.h b/core/quanta/src/quanta.h index 504dafff..18948260 100644 --- a/core/quanta/src/quanta.h +++ b/core/quanta/src/quanta.h @@ -2,16 +2,11 @@ #include #include "logger.h" -#include "miniz.h" class quanta_app final { public: - quanta_app(); - ~quanta_app(); - void run(); - bool initzip(const char* zfile); void setup(int argc, const char* argv[]); void load(int argc, const char* argv[]); void set_signal(uint32_t n, bool b = true); @@ -26,17 +21,9 @@ class quanta_app final void set_path(std::string field, std::string path); const char* get_env(const char* key); - int zip_load(lua_State* L); - bool zip_exist(const char* fname); - - int load_zip_file(lua_State* L); - int find_zip_file(lua_State* L, std::string filename); - int load_zip_data(lua_State* L, const char* filename, int index); - private: uint64_t m_signal = 0; luakit::kit_state m_lua; - mz_zip_archive m_archive; std::map m_environs; }; diff --git a/extend/laoi/laoi.mak b/extend/laoi/laoi.mak index 6e299f2d..f99225c0 100644 --- a/extend/laoi/laoi.mak +++ b/extend/laoi/laoi.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas #c标准库版本 #gnu99/gnu11/gnu17 @@ -41,12 +39,6 @@ MYCFLAGS += -I../luakit/include LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -66,8 +58,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -98,21 +90,22 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/laoi.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -129,6 +122,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/laoi/laoi.vcxproj.filters b/extend/laoi/laoi.vcxproj.filters index b412b4e8..58a01018 100644 --- a/extend/laoi/laoi.vcxproj.filters +++ b/extend/laoi/laoi.vcxproj.filters @@ -2,7 +2,7 @@ - inc + src @@ -11,9 +11,6 @@ - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/extend/lbson/lbson.mak b/extend/lbson/lbson.mak index 68b8e72c..952f66bc 100644 --- a/extend/lbson/lbson.mak +++ b/extend/lbson/lbson.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas #c标准库版本 #gnu99/gnu11/gnu17 @@ -41,12 +39,6 @@ MYCFLAGS += -I../luakit/include LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -66,8 +58,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -98,21 +90,22 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/lbson.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -129,6 +122,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/lbson/lbson.vcxproj.filters b/extend/lbson/lbson.vcxproj.filters index 73e87354..30a51d16 100644 --- a/extend/lbson/lbson.vcxproj.filters +++ b/extend/lbson/lbson.vcxproj.filters @@ -2,7 +2,7 @@ - inc + src @@ -11,9 +11,6 @@ - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/extend/lbson/src/bson.h b/extend/lbson/src/bson.h index d48c462f..8081d36e 100644 --- a/extend/lbson/src/bson.h +++ b/extend/lbson/src/bson.h @@ -235,7 +235,7 @@ namespace lbson { if (depth > max_bson_depth) { luaL_error(L, "Too depth while encoding bson"); } - size_t raw_len = lua_rawlen(L, -1); + int raw_len = lua_rawlen(L, -1); bson_type type = check_doctype(L, raw_len); write_key(type, key, len); if (type == bson_type::BSON_DOCUMENT) { diff --git a/extend/lbson/src/lbson.cpp b/extend/lbson/src/lbson.cpp index 63f87094..16ac366a 100644 --- a/extend/lbson/src/lbson.cpp +++ b/extend/lbson/src/lbson.cpp @@ -32,7 +32,7 @@ namespace lbson { } static void init_static_bson() { - for (int i = 0; i < max_bson_index; ++i) { + for (uint32_t i = 0; i < max_bson_index; ++i) { char tmp[8]; bson_numstr_len[i] = sprintf(tmp, "%d", i); memcpy(bson_numstrs[i], tmp, bson_numstr_len[i]); diff --git a/extend/lcodec/lcodec.lmak b/extend/lcodec/lcodec.lmak index 8c6ca840..838e9e7e 100644 --- a/extend/lcodec/lcodec.lmak +++ b/extend/lcodec/lcodec.lmak @@ -13,6 +13,10 @@ INCLUDES = { "../luakit/include" } +FLAGS = { + "Wno-implicit-fallthrough" +} + --需要连接的库文件 LIBS = { "lua" diff --git a/extend/lcodec/lcodec.mak b/extend/lcodec/lcodec.mak index e2d4dcc0..22e053d9 100644 --- a/extend/lcodec/lcodec.mak +++ b/extend/lcodec/lcodec.mak @@ -15,13 +15,12 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas +MYCFLAGS += -Wno-implicit-fallthrough #c标准库版本 #gnu99/gnu11/gnu17 @@ -41,12 +40,6 @@ MYCFLAGS += -I../luakit/include LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -66,8 +59,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -98,21 +91,22 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/lcodec.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -129,6 +123,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/lcodec/lcodec.vcxproj.filters b/extend/lcodec/lcodec.vcxproj.filters index bee2d6bb..bd7a67ab 100644 --- a/extend/lcodec/lcodec.vcxproj.filters +++ b/extend/lcodec/lcodec.vcxproj.filters @@ -2,31 +2,31 @@ - inc + src - inc + src - inc + src - inc + src - inc + src - inc + src - inc + src - inc + src - inc + src @@ -35,9 +35,6 @@ - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/extend/lcodec/src/guid.h b/extend/lcodec/src/guid.h index b6d1951c..4371c555 100644 --- a/extend/lcodec/src/guid.h +++ b/extend/lcodec/src/guid.h @@ -84,7 +84,7 @@ namespace lcodec { char tmp[LETTER_LEN]; memset(tmp, 0, LETTER_LEN); uint64_t val = (lua_gettop(L) > 0) ? lua_tointeger(L, 1) : guid_new(0, 0); - for (int i = 0; i < LETTER_LEN - 1; ++i) { + for (uint32_t i = 0; i < LETTER_LEN - 1; ++i) { tmp[i] = letter[val % LETTER_SIZE]; val /= LETTER_SIZE; if (val == 0) break; @@ -103,7 +103,7 @@ namespace lcodec { uint64_t val = 0; size_t len = sval.size(); const char* cval = sval.c_str(); - for (int i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) { val += uint64_t(find_index(cval[i]) * pow(LETTER_SIZE, i)); } return val; diff --git a/extend/lcodec/src/mysql.h b/extend/lcodec/src/mysql.h index a705b4b4..db3762d7 100644 --- a/extend/lcodec/src/mysql.h +++ b/extend/lcodec/src/mysql.h @@ -255,7 +255,7 @@ namespace lcodec { size_t column_count = decode_length_encoded_number(); // field metadata mysql_columns columns; - for (int i = 0; i < column_count; ++i) { + for (size_t i = 0; i < column_count; ++i) { recv_packet(); field_decode(columns); } diff --git a/extend/lcodec/src/websocket.h b/extend/lcodec/src/websocket.h index cc4861f7..ebfb7c52 100644 --- a/extend/lcodec/src/websocket.h +++ b/extend/lcodec/src/websocket.h @@ -105,7 +105,7 @@ namespace lcodec { protected: char* xor_byte(char* buffer, char* mask, size_t blen, size_t mlen) { - for (int i = 0; i < blen; i++) { + for (size_t i = 0; i < blen; i++) { buffer[i] = buffer[i] ^ mask[i % mlen]; } return buffer; diff --git a/extend/ldetour/ldetour.lmak b/extend/ldetour/ldetour.lmak index 32877809..9a771b7e 100644 --- a/extend/ldetour/ldetour.lmak +++ b/extend/ldetour/ldetour.lmak @@ -7,6 +7,10 @@ TARGET_NAME = "ldetour" ----工程类型: static/dynamic/exe PROJECT_TYPE = "dynamic" +FLAGS = { + "Wno-class-memaccess" +} + --需要的include目录 INCLUDES = { "src/detour", @@ -14,8 +18,6 @@ INCLUDES = { "../luakit/include" } -AUTO_SUB_DIR = true - --WINDOWS需要定义的选项 WINDOWS_DEFINES = { "LUA_BUILD_AS_DLL" diff --git a/extend/ldetour/ldetour.mak b/extend/ldetour/ldetour.mak index 1186158c..50f9e7ac 100644 --- a/extend/ldetour/ldetour.mak +++ b/extend/ldetour/ldetour.mak @@ -15,13 +15,12 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas +MYCFLAGS += -Wno-class-memaccess #c标准库版本 #gnu99/gnu11/gnu17 @@ -42,12 +41,6 @@ MYCFLAGS += -I../luakit/include LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -67,8 +60,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -99,26 +92,30 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#子目录 -OBJS += $(patsubst $(SRC_DIR)/detour/%.c, $(INT_DIR)/detour/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/detour/*.c))) -OBJS += $(patsubst $(SRC_DIR)/detour/%.m, $(INT_DIR)/detour/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/detour/*.m))) -OBJS += $(patsubst $(SRC_DIR)/detour/%.cc, $(INT_DIR)/detour/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/detour/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/detour/%.cpp, $(INT_DIR)/detour/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/detour/*.cpp))) -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/detour.cpp +SOURCES += src/detour/DetourAlloc.cpp +SOURCES += src/detour/DetourAssert.cpp +SOURCES += src/detour/DetourCommon.cpp +SOURCES += src/detour/DetourNavMesh.cpp +SOURCES += src/detour/DetourNavMeshBuilder.cpp +SOURCES += src/detour/DetourNavMeshQuery.cpp +SOURCES += src/detour/DetourNode.cpp +SOURCES += src/ldetor.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -135,7 +132,8 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) - mkdir -p $(INT_DIR)/detour + mkdir -p $(INT_DIR)/src + mkdir -p $(INT_DIR)/src/detour #后编译 post_build: diff --git a/extend/ldetour/ldetour.vcxproj.filters b/extend/ldetour/ldetour.vcxproj.filters index cbd5f76f..5d4ac8b0 100644 --- a/extend/ldetour/ldetour.vcxproj.filters +++ b/extend/ldetour/ldetour.vcxproj.filters @@ -2,34 +2,34 @@ - inc + src - detour + src\detour - detour + src\detour - detour + src\detour - detour + src\detour - detour + src\detour - detour + src\detour - detour + src\detour - detour + src\detour - detour + src\detour @@ -37,39 +37,36 @@ src - detour + src\detour - detour + src\detour - detour + src\detour - detour + src\detour - detour + src\detour - detour + src\detour - detour + src\detour src - - {5B5D3B00-AE0E-BE9F-AA15-2BBC0E9A59BE} - - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} + + {1ED4BF59-E23D-DD28-6A90-AA5C8A07060C} + \ No newline at end of file diff --git a/extend/ljson/ljson.lmak b/extend/ljson/ljson.lmak index ace92963..4151186b 100644 --- a/extend/ljson/ljson.lmak +++ b/extend/ljson/ljson.lmak @@ -7,10 +7,6 @@ TARGET_NAME = "ljson" ----工程类型: static/dynamic/exe PROJECT_TYPE = "dynamic" -FLAGS = { - "Wno-implicit-fallthrough" -} - --需要的include目录 INCLUDES = { "../lua/lua", diff --git a/extend/ljson/ljson.mak b/extend/ljson/ljson.mak index fd4b77d0..e7d163a2 100644 --- a/extend/ljson/ljson.mak +++ b/extend/ljson/ljson.mak @@ -15,14 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas -MYCFLAGS += -Wno-implicit-fallthrough #c标准库版本 #gnu99/gnu11/gnu17 @@ -42,12 +39,6 @@ MYCFLAGS += -I../luakit/include LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -64,8 +55,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -96,21 +87,23 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/ljson.cpp +SOURCES += src/yyjson.c + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -127,6 +120,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/ljson/ljson.vcxproj.filters b/extend/ljson/ljson.vcxproj.filters index 740428e0..9bf3c145 100644 --- a/extend/ljson/ljson.vcxproj.filters +++ b/extend/ljson/ljson.vcxproj.filters @@ -2,10 +2,10 @@ - inc + src - inc + src @@ -17,9 +17,6 @@ - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/extend/ljson/src/ljson.h b/extend/ljson/src/ljson.h index 298dae2f..c33e2d25 100644 --- a/extend/ljson/src/ljson.h +++ b/extend/ljson/src/ljson.h @@ -86,29 +86,6 @@ namespace ljson { } protected: - bool is_array(lua_State* L, int index, bool emy_as_arr) { - size_t raw_len = lua_rawlen(L, index); - if (raw_len == 0 && !emy_as_arr) { - return false; - } - lua_guard g(L); - lua_pushnil(L); - size_t cur_len = 0; - while (lua_next(L, index) != 0) { - if (!lua_isinteger(L, -2)) { - return false; - } - size_t key = lua_tointeger(L, -2); - if (key <= 0 || key > raw_len) { - return false; - } - lua_pop(L, 1); - cur_len++; - } - if (cur_len == 0) return true; - return cur_len == raw_len; - } - yyjson_mut_val* encode_one(lua_State* L, yyjson_mut_doc* doc, bool emy_as_arr, int idx, int depth) { if (depth > max_encode_depth) { throw lua_exception("encode can't pack too depth table"); @@ -169,7 +146,7 @@ namespace ljson { yyjson_mut_val* table_encode(lua_State* L, yyjson_mut_doc* doc, bool emy_as_arr, int index, int depth) { index = lua_absindex(L, index); - if (!is_array(L, index, emy_as_arr)) { + if (!is_lua_array(L, index, emy_as_arr)) { lua_pushnil(L); yyjson_mut_val* object = yyjson_mut_obj(doc); if (!object) throw lua_exception("json encode memory not enough!"); diff --git a/extend/lmake/lmake.lua b/extend/lmake/lmake.lua index 69b217e3..9628a6ae 100644 --- a/extend/lmake/lmake.lua +++ b/extend/lmake/lmake.lua @@ -114,14 +114,18 @@ local function init_solution_env(env) env.GROUPS = sgroup end +local function is_cpp_file(ext_name) + return ext_name == ".c" or ext_name == ".cc" or ext_name == ".cpp" or ext_name == ".m" +end + --收集文件 -local function collect_files(collect_dir, project_dir, source_dir, args, group, collects, is_hfile) +local function collect_files(collect_dir, project_dir, source_dir, args, sub_dir, collects, is_hfile) local dir_files = ldir(collect_dir) for _, file in pairs(dir_files) do if file.type == "directory" then - local sub_dir = path_cut(file.name, source_dir) - if args.AUTO_SUB_DIR or tcontain(args.SUB_DIR, sub_dir) then - collect_files(file.name, project_dir, source_dir, args, sub_dir, collects, is_hfile) + if args.RECURSION then + local rec_sub_dir = path_cut(file.name, project_dir) + collect_files(file.name, project_dir, source_dir, args, rec_sub_dir, collects, is_hfile) end goto continue end @@ -131,52 +135,37 @@ local function collect_files(collect_dir, project_dir, source_dir, args, group, local fmt_name_c = sgsub(fmt_name, '/', '\\') if is_hfile then if ext_name == ".h" or ext_name == ".hpp" then - collects[#collects + 1] = {fmt_name_c, group, false, false} + collects[#collects + 1] = { fmt_name_c, sub_dir } end goto continue end - if ext_name == ".c" or ext_name == ".cc" or ext_name == ".cpp" then + if is_cpp_file(ext_name) then local cmp_name = path_cut(fullname, source_dir) local is_obj = tcontain(args.OBJS, cmp_name) local cmp_name_c = sgsub(cmp_name, '/', '\\') local is_exclude = tcontain(path_fmt(args.EXCLUDE_FILE), cmp_name_c) - collects[#collects + 1] = {fmt_name_c, group, is_exclude, is_obj} + if is_obj or ((#args.OBJS == 0) and not is_exclude) then + collects[#collects + 1] = { fmt_name_c, sub_dir } + end end :: continue :: end end --vs工程收集源文件 -local function collect_sources(project_dir, src_dir, args) +local function collect_sources(project_dir, src_dirs, args) local includes, sources = {}, {} - local source_dir = lappend(project_dir, src_dir) - collect_files(source_dir, project_dir, source_dir, args, "inc", includes, true) - collect_files(source_dir, project_dir, source_dir, args, "src", sources, false) + for _, src_dir in ipairs(src_dirs) do + local source_dir = lappend(project_dir, src_dir) + local sub_dir = path_cut(source_dir, project_dir) + collect_files(source_dir, project_dir, source_dir, args, sub_dir, includes, true) + collect_files(source_dir, project_dir, source_dir, args, sub_dir, sources, false) + end tsort(includes, files_sort) tsort(sources, files_sort) return includes, sources end ---收集目录 -local function collect_dirs(collect_dir, source_dir, sub_dirs, auto_sub_dir) - local dir_files = ldir(collect_dir) - for _, file in pairs(dir_files) do - if file.type == "directory" and auto_sub_dir then - local sub_dir = path_cut(file.name, source_dir) - if not tcontain(sub_dirs, sub_dir) then - sub_dirs[#sub_dirs + 1] = sub_dir - end - collect_dirs(file.name, source_dir, sub_dirs, auto_sub_dir) - end - end -end - ---linux工程收集子目录 -local function collect_sub_dir(project_dir, src_dir, sub_dirs, auto_sub_dir) - local source_dir = lappend(project_dir, src_dir) - collect_dirs(source_dir, source_dir, sub_dirs, auto_sub_dir) -end - --初始化项目环境变量 local function init_project_env(project_dir) local lguid = require("lguid") @@ -184,7 +173,6 @@ local function init_project_env(project_dir) WORK_DIR = project_dir, GUID_NEW = lguid.guid, COLLECT_SOURCES = collect_sources, - COLLECT_SUBDIRS = collect_sub_dir, } end diff --git a/extend/lmake/share.lua b/extend/lmake/share.lua index f384a65a..9d64ca03 100644 --- a/extend/lmake/share.lua +++ b/extend/lmake/share.lua @@ -12,13 +12,11 @@ ENABLE = true --需要的FLAGS BASE_FLAGS = { - "Wsign-compare", "Wno-sign-compare", "Wno-unused-variable", "Wno-unused-parameter", "Wno-unused-but-set-variable", - "Wno-unused-but-set-parameter", - "Wno-unknown-pragmas" + "Wno-unused-but-set-parameter" } --FLAGS @@ -86,7 +84,9 @@ DARWIN_LIBRARY_DIR = { } --源文件路径 -SRC_DIR = "src" +SRC_DIRS = { + "src" +} --目标文件生成路径 --.so/.exe/.dll @@ -101,12 +101,8 @@ MS_VERSION = "143" VS_SHR_VERSION = "17" VS_FUL_VERSION = "17.4.33103.184" ---子目录路径 -SUB_DIR = { -} - ---自动搜索子目录 -AUTO_SUB_DIR = false +--递归搜索子目录 +RECURSION = true --需要排除的源文件,目录基于$(SRC_DIR) EXCLUDE_FILE = { diff --git a/extend/lmake/tmpl/filters.tpl b/extend/lmake/tmpl/filters.tpl index 475adb86..edd50e53 100644 --- a/extend/lmake/tmpl/filters.tpl +++ b/extend/lmake/tmpl/filters.tpl @@ -1,8 +1,8 @@  {{% local TEMPS, GROUPS = {}, {} %}} - {{% local ARGS = {AUTO_SUB_DIR = AUTO_SUB_DIR, SUB_DIR = SUB_DIR, OBJS = OBJS, EXCLUDE_FILE = EXCLUDE_FILE } %}} - {{% local CINCLUDES, CSOURCES = COLLECT_SOURCES(WORK_DIR, SRC_DIR, ARGS) %}} + {{% local ARGS = {RECURSION = RECURSION, OBJS = OBJS, EXCLUDE_FILE = EXCLUDE_FILE } %}} + {{% local CINCLUDES, CSOURCES = COLLECT_SOURCES(WORK_DIR, SRC_DIRS, ARGS) %}} {{% for _, CINC in pairs(CINCLUDES or {}) do %}} @@ -14,21 +14,21 @@ {{% for _, CSRC in pairs(CSOURCES or {}) do %}} - {{% TEMPS[CSRC[2]] = true %}} + {{% local FGROUP = CSRC[2] %}} + {{% TEMPS[FGROUP] = true %}} + {{% local i, j = FGROUP:find("\\") %}} + {{% while i do %}} + {{% local TITLE = FGROUP:sub(1, i - 1) %}} + {{% TEMPS[TITLE] = true %}} + {{% i, j = FGROUP:find("\\", j + 1) %}} + {{% end %}} {{%= CSRC[2] %}} {{% end %}} {{% for GROUP in pairs(TEMPS or {}) do %}} - {{% local FGROUP = string.gsub(GROUP, '/', '\\') %}} - {{% table.insert(GROUPS, FGROUP) %}} - {{% local i, j = FGROUP:find("\\") %}} - {{% while i do %}} - {{% local TITLE = FGROUP:sub(1, i - 1) %}} - {{% table.insert(GROUPS, TITLE) %}} - {{% i, j = FGROUP:find("\\", j + 1) %}} - {{% end %}} + {{% table.insert(GROUPS, GROUP) %}} {{% end %}} {{% table.sort(GROUPS, function(a, b) return a < b end) %}} {{% for _, GROUP in pairs(GROUPS or {}) do %}} diff --git a/extend/lmake/tmpl/make.tpl b/extend/lmake/tmpl/make.tpl index 9d0ca7fc..ac7eed44 100644 --- a/extend/lmake/tmpl/make.tpl +++ b/extend/lmake/tmpl/make.tpl @@ -129,19 +129,6 @@ LDFLAGS += -L{{%= lib_dir %}} endif {{% end %}} -#源文件路径 -{{% if SRC_DIR then %}} -SRC_DIR = {{%= SRC_DIR %}} -{{% else %}} -SRC_DIR = src -{{% end %}} - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = -{{% for _, exclude in ipairs(EXCLUDE_FILE) do %}} -EXCLUDE += $(SRC_DIR)/{{%= exclude %}} -{{% end %}} - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -181,8 +168,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -228,38 +215,32 @@ LDFLAGS += -L$(SOLUTION_DIR){{%= DST_DIR %}} LDFLAGS += -L$(SOLUTION_DIR){{%= DST_LIB_DIR %}} #自动生成目标 -OBJS = -{{% if next(OBJS) then %}} -{{% local OBJS = table.concat(OBJS, " ") %}} -COBJS = $(patsubst %.c, $(INT_DIR)/%.o, {{%= OBJS %}}) -MOBJS = $(patsubst %.m, $(INT_DIR)/%.o, $(COBJS)) -CCOBJS = $(patsubst %.cc, $(INT_DIR)/%.o, $(MOBJS)) -OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCOBJS)) -{{% else %}} -{{% COLLECT_SUBDIRS(WORK_DIR, SRC_DIR, SUB_DIR, AUTO_SUB_DIR) %}} -{{% for _, sub_dir in ipairs(SUB_DIR) do %}} -#子目录 -{{% local fmtsub_dir = string.gsub(sub_dir, '\\', '/') %}} -OBJS += $(patsubst $(SRC_DIR)/{{%= fmtsub_dir%}}/%.c, $(INT_DIR)/{{%= fmtsub_dir%}}/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/{{%= fmtsub_dir%}}/*.c))) -OBJS += $(patsubst $(SRC_DIR)/{{%= fmtsub_dir%}}/%.m, $(INT_DIR)/{{%= fmtsub_dir%}}/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/{{%= fmtsub_dir%}}/*.m))) -OBJS += $(patsubst $(SRC_DIR)/{{%= fmtsub_dir%}}/%.cc, $(INT_DIR)/{{%= fmtsub_dir%}}/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/{{%= fmtsub_dir%}}/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/{{%= fmtsub_dir%}}/%.cpp, $(INT_DIR)/{{%= fmtsub_dir%}}/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/{{%= fmtsub_dir%}}/*.cpp))) -{{% end %}} -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +{{% local TEMPS, GROUPS = {}, {} %}} +{{% local ARGS = {RECURSION = RECURSION, OBJS = OBJS, EXCLUDE_FILE = EXCLUDE_FILE } %}} +{{% local _, CSOURCES = COLLECT_SOURCES(WORK_DIR, SRC_DIRS, ARGS) %}} +{{% for _, CSRC in ipairs(CSOURCES) do %}} +{{% local fmtsrc = string.gsub(CSRC[1], '\\', '/') %}} +SOURCES += {{%= fmtsrc %}} +{{% TEMPS[CSRC[2]] = true %}} +{{% end %}} +{{% for CSRC in pairs(TEMPS) do %}} +{{% GROUPS[#GROUPS+1] = CSRC %}} {{% end %}} +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) + # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ {{% if PROJECT_TYPE == "static" then %}} @@ -293,8 +274,9 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) -{{% for _, sub_dir in ipairs(SUB_DIR) do %}} - {{% local fmtsub_dir = string.gsub(sub_dir, '\\', '/') %}} +{{% table.sort(GROUPS, function(a, b) return a < b end) %}} +{{% for _, CSRC in ipairs(GROUPS) do %}} +{{% local fmtsub_dir = string.gsub(CSRC, '\\', '/') %}} mkdir -p $(INT_DIR)/{{%= fmtsub_dir %}} {{% end %}} {{% for _, pre_cmd in ipairs(NWINDOWS_PREBUILDS) do %}} diff --git a/extend/lmake/tmpl/vcxproj.tpl b/extend/lmake/tmpl/vcxproj.tpl index b1037502..dd8a821d 100644 --- a/extend/lmake/tmpl/vcxproj.tpl +++ b/extend/lmake/tmpl/vcxproj.tpl @@ -41,8 +41,8 @@ {{% local FMT_INCLUDES = table.concat(AINCLUDES, ";") %}} {{% local FMT_LIBRARY_DIR = table.concat(ALIBDIRS, ";") %}} {{% local FMT_DEFINES = table.concat(ADEFINES or {}, ";") %}} -{{% local ARGS = {AUTO_SUB_DIR = AUTO_SUB_DIR, SUB_DIR = SUB_DIR, OBJS = OBJS, EXCLUDE_FILE = EXCLUDE_FILE } %}} -{{% local CINCLUDES, CSOURCES = COLLECT_SOURCES(WORK_DIR, SRC_DIR, ARGS) %}} +{{% local ARGS = {RECURSION = RECURSION, OBJS = OBJS, EXCLUDE_FILE = EXCLUDE_FILE } %}} +{{% local CINCLUDES, CSOURCES = COLLECT_SOURCES(WORK_DIR, SRC_DIRS, ARGS) %}} @@ -63,13 +63,7 @@ Create {{% else %}} - {{% if CSRC[4] or (#OBJS == 0 and not CSRC[3]) then %}} - {{% else %}} - - true - - {{% end %}} {{% end %}} {{% end %}} diff --git a/extend/lmake/tmpl/vcxprojps.tpl b/extend/lmake/tmpl/vcxprojps.tpl index 14577ce7..a9f20c8a 100644 --- a/extend/lmake/tmpl/vcxprojps.tpl +++ b/extend/lmake/tmpl/vcxprojps.tpl @@ -30,8 +30,8 @@ {{% end %}} {{% local FMT_INCLUDES = table.concat(AINCLUDES, ";") %}} {{% local FMT_LIBRARY_DIR = table.concat(ALIBDIRS, ";") %}} -{{% local ARGS = {AUTO_SUB_DIR = AUTO_SUB_DIR, SUB_DIR = SUB_DIR, OBJS = OBJS, EXCLUDE_FILE = EXCLUDE_FILE } %}} -{{% local CINCLUDES, CSOURCES = COLLECT_SOURCES(WORK_DIR, SRC_DIR, ARGS) %}} +{{% local ARGS = {RECURSION = RECURSION, OBJS = OBJS, EXCLUDE_FILE = EXCLUDE_FILE } %}} +{{% local CINCLUDES, CSOURCES = COLLECT_SOURCES(WORK_DIR, SRC_DIRS, ARGS) %}} @@ -50,14 +50,7 @@ {{% for _, CSRC in pairs(CSOURCES or {}) do %}} - {{% if CSRC[4] or (#OBJS == 0 and not CSRC[3]) then %}} - {{% else %}} - - true - true - - {{% end %}} {{% end %}} diff --git a/extend/lmdb/lmdb.lmak b/extend/lmdb/lmdb.lmak index 17ceab51..96078b31 100644 --- a/extend/lmdb/lmdb.lmak +++ b/extend/lmdb/lmdb.lmak @@ -7,10 +7,6 @@ TARGET_NAME = "lmdb" ----工程类型: static/dynamic/exe PROJECT_TYPE = "dynamic" -FLAGS = { - "Wno-implicit-fallthrough" -} - --需要的include目录 INCLUDES = { "../lua/lua", diff --git a/extend/lmdb/lmdb.mak b/extend/lmdb/lmdb.mak index c36322d1..f16e0788 100644 --- a/extend/lmdb/lmdb.mak +++ b/extend/lmdb/lmdb.mak @@ -15,14 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas -MYCFLAGS += -Wno-implicit-fallthrough #c标准库版本 #gnu99/gnu11/gnu17 @@ -42,12 +39,6 @@ MYCFLAGS += -I../luakit/include LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -64,8 +55,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -96,21 +87,24 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/llmdb.cpp +SOURCES += src/mdb.c +SOURCES += src/midl.c + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -127,6 +121,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/lmdb/lmdb.vcxproj.filters b/extend/lmdb/lmdb.vcxproj.filters index a1b58c7c..21e261c0 100644 --- a/extend/lmdb/lmdb.vcxproj.filters +++ b/extend/lmdb/lmdb.vcxproj.filters @@ -2,13 +2,13 @@ - inc + src - inc + src - inc + src @@ -23,9 +23,6 @@ - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/extend/luaxlsx/miniz.lmak b/extend/lminiz/lminiz.lmak similarity index 56% rename from extend/luaxlsx/miniz.lmak rename to extend/lminiz/lminiz.lmak index 2a09ca96..486b4d1a 100644 --- a/extend/luaxlsx/miniz.lmak +++ b/extend/lminiz/lminiz.lmak @@ -1,21 +1,16 @@ --工程名字 -PROJECT_NAME = "miniz" +PROJECT_NAME = "lminiz" --目标名字 -TARGET_NAME = "miniz" +TARGET_NAME = "lminiz" ----工程类型: static/dynamic/exe PROJECT_TYPE = "dynamic" ---目标文件前缀 -LIB_PREFIX = 1 - -FLAGS = { - "Wno-implicit-fallthrough" -} - --需要的include目录 INCLUDES = { + "../../extend/lua/lua", + "../../extend/luakit/include" } --LINUX需要定义的选项 @@ -30,21 +25,21 @@ DARWIN_DEFINES = { --WINDOWS需要定义的选项 WINDOWS_DEFINES = { - "MINIZ_EXPORT=__declspec(dllexport)" + "LUA_BUILD_AS_DLL" } ---目标文件,可以在这里定义,如果没有定义,share.mak会自动生成 -OBJS = { - "miniz.c" +DEFINES = { } -DEFINES = { +--需要连接的库文件 +LIBS = { + "lua" } --依赖项目 DEPS = { - "mimalloc" + "lualib" } --分组定义 -GROUP = "share" +GROUP = "luaext" diff --git a/extend/luaxlsx/miniz.mak b/extend/lminiz/lminiz.mak similarity index 74% rename from extend/luaxlsx/miniz.mak rename to extend/lminiz/lminiz.mak index 733e72ed..86e76ffe 100644 --- a/extend/luaxlsx/miniz.mak +++ b/extend/lminiz/lminiz.mak @@ -1,8 +1,8 @@ #工程名字 -PROJECT_NAME = miniz +PROJECT_NAME = lminiz #目标名字 -TARGET_NAME = miniz +TARGET_NAME = lminiz #系统环境 UNAME_S = $(shell uname -s) @@ -15,14 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas -MYCFLAGS += -Wno-implicit-fallthrough #c标准库版本 #gnu99/gnu11/gnu17 @@ -33,6 +30,8 @@ STDC = -std=gnu99 STDCPP = -std=c++17 #需要的include目录 +MYCFLAGS += -I../../extend/lua/lua +MYCFLAGS += -I../../extend/luakit/include #需要定义的选项 ifeq ($(UNAME_S), Linux) @@ -46,12 +45,6 @@ endif LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -60,6 +53,7 @@ LIBS += -lmimalloc MYCFLAGS += -I$(SOLUTION_DIR)extend/mimalloc/mimalloc/include -include ../../mimalloc-ex.h endif #自定义库 +LIBS += -llua #系统库 LIBS += -lm -ldl -lstdc++ -lpthread @@ -70,8 +64,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -82,7 +76,7 @@ endif INT_DIR = $(SOLUTION_DIR)temp/$(PROJECT_NAME) #目标文件前缀,定义则.so和.a加lib前缀,否则不加 -PROJECT_PREFIX = lib +PROJECT_PREFIX = #目标定义 MYCFLAGS += -fPIC @@ -102,20 +96,23 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -COBJS = $(patsubst %.c, $(INT_DIR)/%.o, miniz.c) -MOBJS = $(patsubst %.m, $(INT_DIR)/%.o, $(COBJS)) -CCOBJS = $(patsubst %.cc, $(INT_DIR)/%.o, $(MOBJS)) -OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCOBJS)) +SOURCES = +SOURCES += src/lminiz.cpp +SOURCES += src/miniz.c + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -132,6 +129,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/luaxlsx/miniz.vcxproj b/extend/lminiz/lminiz.vcxproj similarity index 78% rename from extend/luaxlsx/miniz.vcxproj rename to extend/lminiz/lminiz.vcxproj index c845f3bf..773bcc15 100644 --- a/extend/luaxlsx/miniz.vcxproj +++ b/extend/lminiz/lminiz.vcxproj @@ -7,25 +7,19 @@ - + - - - true - + - - true - - {EF1771A7-1C29-952D-C38C-5845D2AFAC62} - miniz + {046236D4-E56A-9382-7F53-467FBDB243B5} + lminiz Win32Proj 10.0 - miniz + lminiz @@ -44,15 +38,15 @@ <_ProjectFileVersion>11.0.50727.1 - miniz + lminiz $(SolutionDir)temp\bin\$(Platform)\ $(SolutionDir)temp\$(ProjectName)\$(Platform)\ Disabled - $(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;MINIZ_EXPORT=__declspec(dllexport);%(PreprocessorDefinitions) + ..\..\extend\lua\lua;..\..\extend\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default MultiThreadedDLL @@ -70,7 +64,7 @@ Console $(SolutionDir)library\$(Platform)\$(TargetName).lib $(SolutionDir)temp\$(ProjectName)\$(Platform)\$(TargetName).pdb - mimalloc.lib;%(AdditionalDependencies) + lua.lib;mimalloc.lib;%(AdditionalDependencies) diff --git a/extend/luaxlsx/miniz.vcxproj.filters b/extend/lminiz/lminiz.vcxproj.filters similarity index 58% rename from extend/luaxlsx/miniz.vcxproj.filters rename to extend/lminiz/lminiz.vcxproj.filters index 55b517b3..f6685ade 100644 --- a/extend/luaxlsx/miniz.vcxproj.filters +++ b/extend/lminiz/lminiz.vcxproj.filters @@ -1,31 +1,22 @@  - - inc + + src - inc - - - inc + src - + src src - - src - - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/extend/lminiz/src/lminiz.cpp b/extend/lminiz/src/lminiz.cpp new file mode 100644 index 00000000..8aadea46 --- /dev/null +++ b/extend/lminiz/src/lminiz.cpp @@ -0,0 +1,169 @@ +#define LUA_LIB + +#include "miniz.h" +#include "lminiz.h" + +namespace lminiz { + + thread_local mz_zip_archive thread_archive; + + static int find_zip_file(lua_State* L, std::string filename) { + size_t start_pos = 0; + luakit::lua_guard g(L); + lua_getglobal(L, LUA_LOADLIBNAME); + lua_getfield(L, -1, "path"); + std::string path = lua_tostring(L, -1); + while ((start_pos = filename.find(".", start_pos)) != std::string::npos) { + filename.replace(start_pos, strlen("."), LUA_DIRSEP); + start_pos += strlen(LUA_DIRSEP); + } + start_pos = 0; + while ((start_pos = path.find(LUA_PATH_MARK, start_pos)) != std::string::npos) { + path.replace(start_pos, strlen(LUA_PATH_MARK), filename); + start_pos += filename.size(); + } + start_pos = 0; + while ((start_pos = path.find(LUA_DIRSEP, start_pos)) != std::string::npos) { + path.replace(start_pos, strlen(LUA_DIRSEP), "/"); + start_pos += strlen("/"); + } + size_t cur = 0, pos = 0; + while ((pos = path.find(LUA_PATH_SEP, cur)) != std::string::npos) { + std::string sub = path.substr(cur, pos - cur); + int index = mz_zip_reader_locate_file(&thread_archive, sub.c_str(), nullptr, MZ_ZIP_FLAG_CASE_SENSITIVE); + if (index > 0) { + return index; + } + cur = pos + strlen(LUA_PATH_SEP); + } + if (path.size() > cur) { + std::string sub = path.substr(cur); + return mz_zip_reader_locate_file(&thread_archive, sub.c_str(), nullptr, MZ_ZIP_FLAG_CASE_SENSITIVE); + } + return -1; + } + + bool zip_exist(const char* fname) { + return mz_zip_reader_locate_file(&thread_archive, fname, nullptr, MZ_ZIP_FLAG_CASE_SENSITIVE) > 0; + } + + static int zip_load(lua_State* L) { + const char* fname = luaL_optstring(L, 1, nullptr); + int index = mz_zip_reader_locate_file(&thread_archive, fname, nullptr, MZ_ZIP_FLAG_CASE_SENSITIVE); + if (index <= 0) return 0; + size_t size = 0; + const char* data = (const char*)mz_zip_reader_extract_to_heap(&thread_archive, index, &size, MZ_ZIP_FLAG_CASE_SENSITIVE); + if (!data) return 0; + lua_pushlstring(L, data, size); + delete[] data; + return 1; + } + + static int load_zip_data(lua_State* L, const char* filename, int index) { + size_t size = 0; + const char* data = (const char*)mz_zip_reader_extract_to_heap(&thread_archive, index, &size, MZ_ZIP_FLAG_CASE_SENSITIVE); + if (!data) { + lua_pushstring(L, "file read failed!"); + return LUA_ERRERR; + } + int status = luaL_loadbufferx(L, data, size, filename, luaL_optstring(L, 2, nullptr)); + delete[] data; + return status; + } + + static int load_zip_file(lua_State* L) { + const char* fname = luaL_optstring(L, 1, nullptr); + int index = mz_zip_reader_locate_file(&thread_archive, fname, nullptr, MZ_ZIP_FLAG_CASE_SENSITIVE); + if (index <= 0) { + luaL_Buffer buf; + luaL_buffinit(L, &buf); + luaL_addstring(&buf, fname); + luaL_addstring(&buf, " not found in zip"); + luaL_pushresult(&buf); + return LUA_ERRERR; + } + return load_zip_data(L, fname, index); + } + + static void close_zip() { + if (thread_archive.m_pState) { + mz_zip_reader_end(&thread_archive); + mz_zip_zero_struct(&thread_archive); + } + } + + bool init_zip(lua_State* L, const char* zfile) { + close_zip(); + if (!mz_zip_reader_init_file(&thread_archive, zfile, 0)) { + return false; + } + luakit::kit_state lua(L); + lua.set_searchers([&](lua_State* L) { + const char* fname = luaL_checkstring(L, 1); + int index = find_zip_file(L, fname); + if (index < 0) { + luaL_Buffer buf; + luaL_buffinit(L, &buf); + luaL_addstring(&buf, fname); + luaL_addstring(&buf, " not found in zip"); + luaL_pushresult(&buf); + return 1; + } + if (load_zip_data(L, fname, index) == LUA_OK) { + lua_pushstring(L, fname); /* will be 2nd argument to module */ + return 2; /* return open function and file name */ + } + return luaL_error(L, "error loading module '%s' from file '%s':\n\t%s", lua_tostring(L, 1), fname, lua_tostring(L, -1)); + }); + lua.set_function("dofile", [&](lua_State* L) { + const char* fname = luaL_optstring(L, 1, NULL); + lua_settop(L, 1); + if (load_zip_file(L) != LUA_OK) { + return lua_error(L); + } + auto kf = [](lua_State* L, int d1, lua_KContext d2) { return lua_gettop(L) - 1; }; + lua_callk(L, 0, LUA_MULTRET, 0, kf); + return kf(L, 0, 0); + }); + lua.set_function("loadfile", [&](lua_State* L) { + int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */ + if (load_zip_file(L) == LUA_OK) { + if (env != 0) { /* 'env' parameter? */ + lua_pushvalue(L, env); /* environment for loaded function */ + if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */ + lua_pop(L, 1); /* remove 'env' if not used by previous call */ + } + return 1; + } + //error(message is on top of the stack)* / + lua_pushnil(L); + lua_insert(L, -2); + return 2; + }); + return true; + } + + luakit::lua_table open_lminiz(lua_State* L) { + luakit::kit_state kit_state(L); + luakit::lua_table miniz = kit_state.new_table("zip"); + miniz.set_function("exist", zip_exist); + miniz.set_function("load", [](lua_State* L) { return zip_load(L); }); + return miniz; + } +} + +extern "C" { + LUALIB_API int luaopen_lminiz(lua_State* L) { + auto miniz = lminiz::open_lminiz(L); + return miniz.push_stack(); + } + + LUALIB_API bool lua_initzip(lua_State* L, const char* zfile) { + return lminiz::init_zip(L, zfile); + } + + LUALIB_API void lua_closezip() { + lminiz::close_zip(); + } + +} diff --git a/extend/lminiz/src/lminiz.h b/extend/lminiz/src/lminiz.h new file mode 100644 index 00000000..f5cf1a1c --- /dev/null +++ b/extend/lminiz/src/lminiz.h @@ -0,0 +1,10 @@ +#pragma once + +#include "lua_kit.h" + +extern "C" { + + LUALIB_API bool lua_initzip(lua_State* L, const char* zfile); + + LUALIB_API void lua_closezip(); +} diff --git a/extend/luaxlsx/src/miniz.c b/extend/lminiz/src/miniz.c similarity index 100% rename from extend/luaxlsx/src/miniz.c rename to extend/lminiz/src/miniz.c diff --git a/extend/luaxlsx/src/miniz.h b/extend/lminiz/src/miniz.h similarity index 100% rename from extend/luaxlsx/src/miniz.h rename to extend/lminiz/src/miniz.h diff --git a/extend/lsqlite/lsqlite.mak b/extend/lsqlite/lsqlite.mak index be89dc65..d03d610e 100644 --- a/extend/lsqlite/lsqlite.mak +++ b/extend/lsqlite/lsqlite.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas MYCFLAGS += -Wno-implicit-fallthrough #c标准库版本 @@ -48,12 +46,6 @@ endif LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -70,8 +62,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -102,21 +94,24 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/lsqlite.cpp +SOURCES += src/os_ps.c +SOURCES += src/sqlite3.c + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -133,6 +128,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/lsqlite/lsqlite.vcxproj.filters b/extend/lsqlite/lsqlite.vcxproj.filters index d2fc45b5..15ab50f3 100644 --- a/extend/lsqlite/lsqlite.vcxproj.filters +++ b/extend/lsqlite/lsqlite.vcxproj.filters @@ -2,10 +2,10 @@ - inc + src - inc + src @@ -20,9 +20,6 @@ - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/extend/lssl/lssl.lmak b/extend/lssl/lssl.lmak index 736d3ef3..2ddf102b 100644 --- a/extend/lssl/lssl.lmak +++ b/extend/lssl/lssl.lmak @@ -8,7 +8,7 @@ TARGET_NAME = "lssl" PROJECT_TYPE = "dynamic" FLAGS = { - "Wno-implicit-fallthrough" + "Wno-implicit-function-declaration" } --需要的include目录 @@ -18,10 +18,6 @@ INCLUDES = { "../luakit/include" } ---LINUX需要定义的选项 -LINUX_DEFINES = { -} - --DARWIN需要定义的选项 DARWIN_DEFINES = { "WOLFSSL_APPLE_NATIVE_CERT_VALIDATION" @@ -45,9 +41,6 @@ DEFINES = { "WOLFSSL_USER_SETTINGS" } ---自动搜索子目录 -AUTO_SUB_DIR = true - --需要排除的源文件,目录基于$(SRC_DIR) EXCLUDE_FILE = { "src/ssl_bn.c", diff --git a/extend/lssl/lssl.mak b/extend/lssl/lssl.mak index ac9fe710..8556c4eb 100644 --- a/extend/lssl/lssl.mak +++ b/extend/lssl/lssl.mak @@ -15,14 +15,12 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas -MYCFLAGS += -Wno-implicit-fallthrough +MYCFLAGS += -Wno-implicit-function-declaration #c标准库版本 #gnu99/gnu11/gnu17 @@ -55,24 +53,6 @@ LDFLAGS += -framework Security endif -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = -EXCLUDE += $(SRC_DIR)/src\ssl_bn.c -EXCLUDE += $(SRC_DIR)/src\ssl_misc.c -EXCLUDE += $(SRC_DIR)/src\ssl_asn1.c -EXCLUDE += $(SRC_DIR)/src\ssl_crypto.c -EXCLUDE += $(SRC_DIR)/src\ssl_certman.c -EXCLUDE += $(SRC_DIR)/wolfcrypt\src\evp.c -EXCLUDE += $(SRC_DIR)/wolfcrypt\src\misc.c -EXCLUDE += $(SRC_DIR)/src\x509_str.c -EXCLUDE += $(SRC_DIR)/src\x509.c -EXCLUDE += $(SRC_DIR)/src\conf.c -EXCLUDE += $(SRC_DIR)/src\bio.c -EXCLUDE += $(SRC_DIR)/src\pk.c - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -92,8 +72,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -124,56 +104,133 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#子目录 -OBJS += $(patsubst $(SRC_DIR)/src/%.c, $(INT_DIR)/src/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/src/*.c))) -OBJS += $(patsubst $(SRC_DIR)/src/%.m, $(INT_DIR)/src/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/src/*.m))) -OBJS += $(patsubst $(SRC_DIR)/src/%.cc, $(INT_DIR)/src/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/src/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/src/%.cpp, $(INT_DIR)/src/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/src/*.cpp))) -#子目录 -OBJS += $(patsubst $(SRC_DIR)/ssl/%.c, $(INT_DIR)/ssl/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/ssl/*.c))) -OBJS += $(patsubst $(SRC_DIR)/ssl/%.m, $(INT_DIR)/ssl/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/ssl/*.m))) -OBJS += $(patsubst $(SRC_DIR)/ssl/%.cc, $(INT_DIR)/ssl/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/ssl/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/ssl/%.cpp, $(INT_DIR)/ssl/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/ssl/*.cpp))) -#子目录 -OBJS += $(patsubst $(SRC_DIR)/wolfcrypt/%.c, $(INT_DIR)/wolfcrypt/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfcrypt/*.c))) -OBJS += $(patsubst $(SRC_DIR)/wolfcrypt/%.m, $(INT_DIR)/wolfcrypt/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfcrypt/*.m))) -OBJS += $(patsubst $(SRC_DIR)/wolfcrypt/%.cc, $(INT_DIR)/wolfcrypt/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfcrypt/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/wolfcrypt/%.cpp, $(INT_DIR)/wolfcrypt/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfcrypt/*.cpp))) -#子目录 -OBJS += $(patsubst $(SRC_DIR)/wolfcrypt/src/%.c, $(INT_DIR)/wolfcrypt/src/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfcrypt/src/*.c))) -OBJS += $(patsubst $(SRC_DIR)/wolfcrypt/src/%.m, $(INT_DIR)/wolfcrypt/src/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfcrypt/src/*.m))) -OBJS += $(patsubst $(SRC_DIR)/wolfcrypt/src/%.cc, $(INT_DIR)/wolfcrypt/src/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfcrypt/src/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/wolfcrypt/src/%.cpp, $(INT_DIR)/wolfcrypt/src/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfcrypt/src/*.cpp))) -#子目录 -OBJS += $(patsubst $(SRC_DIR)/wolfssl/%.c, $(INT_DIR)/wolfssl/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfssl/*.c))) -OBJS += $(patsubst $(SRC_DIR)/wolfssl/%.m, $(INT_DIR)/wolfssl/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfssl/*.m))) -OBJS += $(patsubst $(SRC_DIR)/wolfssl/%.cc, $(INT_DIR)/wolfssl/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfssl/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/wolfssl/%.cpp, $(INT_DIR)/wolfssl/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfssl/*.cpp))) -#子目录 -OBJS += $(patsubst $(SRC_DIR)/wolfssl/openssl/%.c, $(INT_DIR)/wolfssl/openssl/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfssl/openssl/*.c))) -OBJS += $(patsubst $(SRC_DIR)/wolfssl/openssl/%.m, $(INT_DIR)/wolfssl/openssl/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfssl/openssl/*.m))) -OBJS += $(patsubst $(SRC_DIR)/wolfssl/openssl/%.cc, $(INT_DIR)/wolfssl/openssl/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfssl/openssl/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/wolfssl/openssl/%.cpp, $(INT_DIR)/wolfssl/openssl/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfssl/openssl/*.cpp))) -#子目录 -OBJS += $(patsubst $(SRC_DIR)/wolfssl/wolfcrypt/%.c, $(INT_DIR)/wolfssl/wolfcrypt/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfssl/wolfcrypt/*.c))) -OBJS += $(patsubst $(SRC_DIR)/wolfssl/wolfcrypt/%.m, $(INT_DIR)/wolfssl/wolfcrypt/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfssl/wolfcrypt/*.m))) -OBJS += $(patsubst $(SRC_DIR)/wolfssl/wolfcrypt/%.cc, $(INT_DIR)/wolfssl/wolfcrypt/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfssl/wolfcrypt/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/wolfssl/wolfcrypt/%.cpp, $(INT_DIR)/wolfssl/wolfcrypt/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/wolfssl/wolfcrypt/*.cpp))) -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/src/crl.c +SOURCES += src/src/dtls.c +SOURCES += src/src/dtls13.c +SOURCES += src/src/internal.c +SOURCES += src/src/keys.c +SOURCES += src/src/ocsp.c +SOURCES += src/src/quic.c +SOURCES += src/src/sniffer.c +SOURCES += src/src/ssl.c +SOURCES += src/src/tls.c +SOURCES += src/src/tls13.c +SOURCES += src/src/wolfio.c +SOURCES += src/ssl/crc.c +SOURCES += src/ssl/hmac_sha.c +SOURCES += src/ssl/lssl.cpp +SOURCES += src/ssl/lz4.c +SOURCES += src/ssl/xxtea.c +SOURCES += src/wolfcrypt/src/aes.c +SOURCES += src/wolfcrypt/src/arc4.c +SOURCES += src/wolfcrypt/src/asm.c +SOURCES += src/wolfcrypt/src/asn.c +SOURCES += src/wolfcrypt/src/blake2b.c +SOURCES += src/wolfcrypt/src/blake2s.c +SOURCES += src/wolfcrypt/src/camellia.c +SOURCES += src/wolfcrypt/src/chacha.c +SOURCES += src/wolfcrypt/src/chacha20_poly1305.c +SOURCES += src/wolfcrypt/src/cmac.c +SOURCES += src/wolfcrypt/src/coding.c +SOURCES += src/wolfcrypt/src/compress.c +SOURCES += src/wolfcrypt/src/cpuid.c +SOURCES += src/wolfcrypt/src/cryptocb.c +SOURCES += src/wolfcrypt/src/curve25519.c +SOURCES += src/wolfcrypt/src/curve448.c +SOURCES += src/wolfcrypt/src/des3.c +SOURCES += src/wolfcrypt/src/dh.c +SOURCES += src/wolfcrypt/src/dilithium.c +SOURCES += src/wolfcrypt/src/dsa.c +SOURCES += src/wolfcrypt/src/ecc.c +SOURCES += src/wolfcrypt/src/ecc_fp.c +SOURCES += src/wolfcrypt/src/eccsi.c +SOURCES += src/wolfcrypt/src/ed25519.c +SOURCES += src/wolfcrypt/src/ed448.c +SOURCES += src/wolfcrypt/src/error.c +SOURCES += src/wolfcrypt/src/ext_kyber.c +SOURCES += src/wolfcrypt/src/ext_lms.c +SOURCES += src/wolfcrypt/src/ext_xmss.c +SOURCES += src/wolfcrypt/src/falcon.c +SOURCES += src/wolfcrypt/src/fe_448.c +SOURCES += src/wolfcrypt/src/fe_low_mem.c +SOURCES += src/wolfcrypt/src/fe_operations.c +SOURCES += src/wolfcrypt/src/ge_448.c +SOURCES += src/wolfcrypt/src/ge_low_mem.c +SOURCES += src/wolfcrypt/src/ge_operations.c +SOURCES += src/wolfcrypt/src/hash.c +SOURCES += src/wolfcrypt/src/hmac.c +SOURCES += src/wolfcrypt/src/hpke.c +SOURCES += src/wolfcrypt/src/integer.c +SOURCES += src/wolfcrypt/src/kdf.c +SOURCES += src/wolfcrypt/src/logging.c +SOURCES += src/wolfcrypt/src/md2.c +SOURCES += src/wolfcrypt/src/md4.c +SOURCES += src/wolfcrypt/src/md5.c +SOURCES += src/wolfcrypt/src/memory.c +SOURCES += src/wolfcrypt/src/pkcs12.c +SOURCES += src/wolfcrypt/src/pkcs7.c +SOURCES += src/wolfcrypt/src/poly1305.c +SOURCES += src/wolfcrypt/src/pwdbased.c +SOURCES += src/wolfcrypt/src/random.c +SOURCES += src/wolfcrypt/src/rc2.c +SOURCES += src/wolfcrypt/src/ripemd.c +SOURCES += src/wolfcrypt/src/rsa.c +SOURCES += src/wolfcrypt/src/sakke.c +SOURCES += src/wolfcrypt/src/sha.c +SOURCES += src/wolfcrypt/src/sha256.c +SOURCES += src/wolfcrypt/src/sha3.c +SOURCES += src/wolfcrypt/src/sha512.c +SOURCES += src/wolfcrypt/src/signature.c +SOURCES += src/wolfcrypt/src/siphash.c +SOURCES += src/wolfcrypt/src/sm2.c +SOURCES += src/wolfcrypt/src/sm3.c +SOURCES += src/wolfcrypt/src/sm4.c +SOURCES += src/wolfcrypt/src/sp_arm32.c +SOURCES += src/wolfcrypt/src/sp_arm64.c +SOURCES += src/wolfcrypt/src/sp_armthumb.c +SOURCES += src/wolfcrypt/src/sp_c32.c +SOURCES += src/wolfcrypt/src/sp_c64.c +SOURCES += src/wolfcrypt/src/sp_cortexm.c +SOURCES += src/wolfcrypt/src/sp_dsp32.c +SOURCES += src/wolfcrypt/src/sp_int.c +SOURCES += src/wolfcrypt/src/sp_sm2_arm32.c +SOURCES += src/wolfcrypt/src/sp_sm2_arm64.c +SOURCES += src/wolfcrypt/src/sp_sm2_armthumb.c +SOURCES += src/wolfcrypt/src/sp_sm2_c32.c +SOURCES += src/wolfcrypt/src/sp_sm2_c64.c +SOURCES += src/wolfcrypt/src/sp_sm2_cortexm.c +SOURCES += src/wolfcrypt/src/sp_sm2_x86_64.c +SOURCES += src/wolfcrypt/src/sp_x86_64.c +SOURCES += src/wolfcrypt/src/sphincs.c +SOURCES += src/wolfcrypt/src/srp.c +SOURCES += src/wolfcrypt/src/tfm.c +SOURCES += src/wolfcrypt/src/wc_dsp.c +SOURCES += src/wolfcrypt/src/wc_encrypt.c +SOURCES += src/wolfcrypt/src/wc_kyber.c +SOURCES += src/wolfcrypt/src/wc_kyber_poly.c +SOURCES += src/wolfcrypt/src/wc_lms.c +SOURCES += src/wolfcrypt/src/wc_lms_impl.c +SOURCES += src/wolfcrypt/src/wc_pkcs11.c +SOURCES += src/wolfcrypt/src/wc_port.c +SOURCES += src/wolfcrypt/src/wc_xmss.c +SOURCES += src/wolfcrypt/src/wc_xmss_impl.c +SOURCES += src/wolfcrypt/src/wolfevent.c +SOURCES += src/wolfcrypt/src/wolfmath.c + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -190,13 +247,9 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) - mkdir -p $(INT_DIR)/src - mkdir -p $(INT_DIR)/ssl - mkdir -p $(INT_DIR)/wolfcrypt - mkdir -p $(INT_DIR)/wolfcrypt/src - mkdir -p $(INT_DIR)/wolfssl - mkdir -p $(INT_DIR)/wolfssl/openssl - mkdir -p $(INT_DIR)/wolfssl/wolfcrypt + mkdir -p $(INT_DIR)/src/src + mkdir -p $(INT_DIR)/src/ssl + mkdir -p $(INT_DIR)/src/wolfcrypt/src #后编译 post_build: diff --git a/extend/lssl/lssl.vcxproj b/extend/lssl/lssl.vcxproj index 4c6ffc2c..9e72dd82 100644 --- a/extend/lssl/lssl.vcxproj +++ b/extend/lssl/lssl.vcxproj @@ -173,48 +173,18 @@ - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - @@ -246,9 +216,6 @@ - - true - @@ -269,9 +236,6 @@ - - true - diff --git a/extend/lssl/lssl.vcxproj.filters b/extend/lssl/lssl.vcxproj.filters index 0df54323..3afcf386 100644 --- a/extend/lssl/lssl.vcxproj.filters +++ b/extend/lssl/lssl.vcxproj.filters @@ -2,902 +2,860 @@ - ssl + src\ssl - ssl + src\ssl - ssl + src\ssl - ssl + src\ssl - ssl + src\ssl - inc + src - wolfssl + src\wolfssl - wolfssl + src\wolfssl - wolfssl + src\wolfssl - wolfssl + src\wolfssl - wolfssl + src\wolfssl - wolfssl + src\wolfssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl\openssl + src\wolfssl\openssl - wolfssl + src\wolfssl - wolfssl + src\wolfssl - wolfssl + src\wolfssl - wolfssl + src\wolfssl - wolfssl + src\wolfssl - wolfssl + src\wolfssl - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl\wolfcrypt + src\wolfssl\wolfcrypt - wolfssl + src\wolfssl - - src - - - src - - src + src\src - src + src\src - src + src\src - src + src\src - src + src\src - src - - - src + src\src - src + src\src - src + src\src - src - - - src - - - src - - - src - - - src - - - src + src\src - src + src\src - src + src\src - src - - - src - - - src + src\src - ssl + src\ssl - ssl + src\ssl - ssl + src\ssl - ssl + src\ssl - ssl + src\ssl - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src - - - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src - - - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - wolfcrypt\src + src\wolfcrypt\src - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} - - {F9D5C16A-7F42-203F-8C19-5432354A3271} - - - {C8227F1E-1230-D136-C404-7A7A8BBF9E5E} + + {71CC2570-F9AA-7764-F598-7875102685F6} - - {59C33CA5-01BD-4B37-3CA3-F2CB5FBBE3DE} + + {6AC8DFA0-47B3-9DD3-0B3A-E268BDD8095B} - - {3DA82D46-2DB4-5A66-7931-0FB1CA0A9F02} + + {ABCB5A45-7018-EC07-08C6-2289EFB4F8FC} - - {3DA82D46-2DB4-5A66-7931-0FB1CA0A9F02} + + {F930362F-656A-3B38-F2C8-505942495381} - - {3DA82D46-2DB4-5A66-7931-0FB1CA0A9F02} + + {AADFCED3-9F1D-B24B-D50A-A82347B0362F} - - {06035986-7A29-BB5B-56E3-8BDC59552F18} + + {82AE7BA3-A32C-4B53-A4E6-399482E1786B} - - {0A0E8D6B-782B-7C06-A96D-5EAED73F4B0A} + + {C95F4505-8E1A-6EAD-788B-8F5BBE246D57} \ No newline at end of file diff --git a/extend/lssl/src/ssl/lssl.cpp b/extend/lssl/src/ssl/lssl.cpp index e56e8706..3ea18b0a 100644 --- a/extend/lssl/src/ssl/lssl.cpp +++ b/extend/lssl/src/ssl/lssl.cpp @@ -49,7 +49,7 @@ namespace lssl { if (sz > UCHAR_MAX / 2) { buffer = (char*)lua_newuserdata(L, sz * 2); } - for (int i = 0; i < sz; i++) { + for (size_t i = 0; i < sz; i++) { buffer[i * 2] = hex[text[i] >> 4]; buffer[i * 2 + 1] = hex[text[i] & 0xf]; } @@ -80,14 +80,14 @@ namespace lssl { size_t sz = 0; const unsigned char* text = (const unsigned char*)luaL_checklstring(L, 1, &sz); if (sz & 2) { - return luaL_error(L, "Invalid hex text size %d", (int)sz); + return luaL_error(L, "Invalid hex text size %lu", (int)sz); } char tmp[UCHAR_MAX]; char* buffer = tmp; if (sz > UCHAR_MAX * 2) { buffer = (char*)lua_newuserdata(L, sz / 2); } - int i; + size_t i; for (i = 0; i < sz; i += 2) { char hi, low; HEX(hi, text[i]); @@ -289,7 +289,7 @@ namespace lssl { } luaL_Buffer b; char* buffer = luaL_buffinitsize(L, &b, len1); - int i; + size_t i; for (i = 0; i < len1; i++) { buffer[i] = s1[i] ^ s2[i % len2]; } diff --git a/extend/lssl/src/ssl/lssl.h b/extend/lssl/src/ssl/lssl.h index 84f11ba5..2f784f5c 100644 --- a/extend/lssl/src/ssl/lssl.h +++ b/extend/lssl/src/ssl/lssl.h @@ -171,7 +171,7 @@ namespace lssl { size_t slen = 0; uint8_t* body = m_hcodec->encode(L, index, &slen); while (slen > 0) { - int written = SSL_write(ssl, body, slen); + size_t written = SSL_write(ssl, body, slen); if (written <= 0 || written > slen) { int err = SSL_get_error(ssl, written); ERR_clear_error(); @@ -295,7 +295,7 @@ namespace lssl { void bio_write(lua_State* L, uint8_t* data, size_t sz) { while (sz > 0) { - int written = BIO_write(in_bio, data, sz); + size_t written = BIO_write(in_bio, data, sz); if (written <= 0 || written > sz) { throw lua_exception("BIO_write error:%d", written); } diff --git a/extend/lstdfs/lstdfs.mak b/extend/lstdfs/lstdfs.mak index cb129f65..beb96eb2 100644 --- a/extend/lstdfs/lstdfs.mak +++ b/extend/lstdfs/lstdfs.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas #c标准库版本 #gnu99/gnu11/gnu17 @@ -41,12 +39,6 @@ MYCFLAGS += -I../luakit/include LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -69,8 +61,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -101,21 +93,22 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/lstdfs.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -132,6 +125,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/ltimer/ltimer.lmak b/extend/ltimer/ltimer.lmak index 43f3fd32..45918cdd 100644 --- a/extend/ltimer/ltimer.lmak +++ b/extend/ltimer/ltimer.lmak @@ -13,9 +13,6 @@ INCLUDES = { "../luakit/include" } ---源文件路径 -SRC_DIR = "ltimer" - --需要连接的库文件 LIBS = { "lua" diff --git a/extend/ltimer/ltimer.mak b/extend/ltimer/ltimer.mak index 4059f707..ce7cccec 100644 --- a/extend/ltimer/ltimer.mak +++ b/extend/ltimer/ltimer.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas #c标准库版本 #gnu99/gnu11/gnu17 @@ -41,12 +39,6 @@ MYCFLAGS += -I../luakit/include LDFLAGS = -#源文件路径 -SRC_DIR = ltimer - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -66,8 +58,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -98,21 +90,22 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/ltimer.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -129,6 +122,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/ltimer/ltimer.vcxproj b/extend/ltimer/ltimer.vcxproj index 6679a6a1..4ea091f1 100644 --- a/extend/ltimer/ltimer.vcxproj +++ b/extend/ltimer/ltimer.vcxproj @@ -7,10 +7,10 @@ - + - + {2DE9C09F-02F5-DF2B-524C-FFBEBC8DE5EE} diff --git a/extend/ltimer/ltimer.vcxproj.filters b/extend/ltimer/ltimer.vcxproj.filters index 1879d910..3e7a073f 100644 --- a/extend/ltimer/ltimer.vcxproj.filters +++ b/extend/ltimer/ltimer.vcxproj.filters @@ -1,19 +1,16 @@  - - inc + + src - + src - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/extend/ltimer/ltimer/ltimer.cpp b/extend/ltimer/src/ltimer.cpp similarity index 100% rename from extend/ltimer/ltimer/ltimer.cpp rename to extend/ltimer/src/ltimer.cpp diff --git a/extend/ltimer/ltimer/ltimer.h b/extend/ltimer/src/ltimer.h similarity index 100% rename from extend/ltimer/ltimer/ltimer.h rename to extend/ltimer/src/ltimer.h diff --git a/extend/lua/lua.lmak b/extend/lua/lua.lmak index b3d27963..f977e339 100644 --- a/extend/lua/lua.lmak +++ b/extend/lua/lua.lmak @@ -31,7 +31,9 @@ DARWIN_DEFINES = { } --源文件路径 -SRC_DIR = "lua" +SRC_DIRS = { + "lua" +} --目标文件,可以在这里定义,如果没有定义,share.mak会自动生成 OBJS = { diff --git a/extend/lua/lua.mak b/extend/lua/lua.mak index 0cc909b4..c1924434 100644 --- a/extend/lua/lua.mak +++ b/extend/lua/lua.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas #c标准库版本 #gnu99/gnu11/gnu17 @@ -47,12 +45,6 @@ endif LDFLAGS = -#源文件路径 -SRC_DIR = lua - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -68,8 +60,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -89,20 +81,22 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -COBJS = $(patsubst %.c, $(INT_DIR)/%.o, onelua.c) -MOBJS = $(patsubst %.m, $(INT_DIR)/%.o, $(COBJS)) -CCOBJS = $(patsubst %.cc, $(INT_DIR)/%.o, $(MOBJS)) -OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCOBJS)) +SOURCES = +SOURCES += lua/onelua.c + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_EXECUTE) : $(OBJS) @@ -119,6 +113,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/lua #后编译 post_build: diff --git a/extend/lua/lua.vcxproj b/extend/lua/lua.vcxproj index 754e8db6..aa5ddcb8 100644 --- a/extend/lua/lua.vcxproj +++ b/extend/lua/lua.vcxproj @@ -37,108 +37,6 @@ - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - diff --git a/extend/lua/lua.vcxproj.filters b/extend/lua/lua.vcxproj.filters index 77b96fc6..335f9e1e 100644 --- a/extend/lua/lua.vcxproj.filters +++ b/extend/lua/lua.vcxproj.filters @@ -2,203 +2,98 @@ - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - src + lua - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - - - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} + + {F8DBBBDB-3B80-B4F1-70A8-272978F579EB} \ No newline at end of file diff --git a/extend/lua/luac.lmak b/extend/lua/luac.lmak index 23ab9621..b2c50796 100644 --- a/extend/lua/luac.lmak +++ b/extend/lua/luac.lmak @@ -32,7 +32,9 @@ DARWIN_DEFINES = { } --源文件路径 -SRC_DIR = "lua" +SRC_DIRS = { + "lua" +} --目标文件,可以在这里定义,如果没有定义,share.mak会自动生成 OBJS = { diff --git a/extend/lua/luac.mak b/extend/lua/luac.mak index 4b317e3a..0354ea8b 100644 --- a/extend/lua/luac.mak +++ b/extend/lua/luac.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas #c标准库版本 #gnu99/gnu11/gnu17 @@ -48,12 +46,6 @@ endif LDFLAGS = -#源文件路径 -SRC_DIR = lua - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -69,8 +61,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -90,20 +82,22 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -COBJS = $(patsubst %.c, $(INT_DIR)/%.o, onelua.c) -MOBJS = $(patsubst %.m, $(INT_DIR)/%.o, $(COBJS)) -CCOBJS = $(patsubst %.cc, $(INT_DIR)/%.o, $(MOBJS)) -OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCOBJS)) +SOURCES = +SOURCES += lua/onelua.c + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_EXECUTE) : $(OBJS) @@ -120,6 +114,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/lua #后编译 post_build: diff --git a/extend/lua/luac.vcxproj b/extend/lua/luac.vcxproj index 6c2c678d..79404912 100644 --- a/extend/lua/luac.vcxproj +++ b/extend/lua/luac.vcxproj @@ -37,108 +37,6 @@ - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - diff --git a/extend/lua/luac.vcxproj.filters b/extend/lua/luac.vcxproj.filters index 77b96fc6..335f9e1e 100644 --- a/extend/lua/luac.vcxproj.filters +++ b/extend/lua/luac.vcxproj.filters @@ -2,203 +2,98 @@ - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - src + lua - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - - - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} + + {F8DBBBDB-3B80-B4F1-70A8-272978F579EB} \ No newline at end of file diff --git a/extend/lua/lualib.lmak b/extend/lua/lualib.lmak index 37d30843..d0d0316e 100644 --- a/extend/lua/lualib.lmak +++ b/extend/lua/lualib.lmak @@ -37,7 +37,9 @@ WINDOWS_DEFINES = { } --源文件路径 -SRC_DIR = "lua" +SRC_DIRS = { + "lua" +} --目标文件,可以在这里定义,如果没有定义,share.mak会自动生成 OBJS = { diff --git a/extend/lua/lualib.mak b/extend/lua/lualib.mak index d321655b..613bfebf 100644 --- a/extend/lua/lualib.mak +++ b/extend/lua/lualib.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas #c标准库版本 #gnu99/gnu11/gnu17 @@ -46,12 +44,6 @@ endif LDFLAGS = -#源文件路径 -SRC_DIR = lua - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -70,8 +62,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -102,20 +94,22 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -COBJS = $(patsubst %.c, $(INT_DIR)/%.o, onelua.c) -MOBJS = $(patsubst %.m, $(INT_DIR)/%.o, $(COBJS)) -CCOBJS = $(patsubst %.cc, $(INT_DIR)/%.o, $(MOBJS)) -OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCOBJS)) +SOURCES = +SOURCES += lua/onelua.c + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -132,6 +126,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/lua #后编译 post_build: diff --git a/extend/lua/lualib.vcxproj b/extend/lua/lualib.vcxproj index 2826b1f3..c3cb1d03 100644 --- a/extend/lua/lualib.vcxproj +++ b/extend/lua/lualib.vcxproj @@ -37,108 +37,6 @@ - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - - - true - diff --git a/extend/lua/lualib.vcxproj.filters b/extend/lua/lualib.vcxproj.filters index 77b96fc6..335f9e1e 100644 --- a/extend/lua/lualib.vcxproj.filters +++ b/extend/lua/lualib.vcxproj.filters @@ -2,203 +2,98 @@ - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - inc + lua - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - src + lua - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - - - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} + + {F8DBBBDB-3B80-B4F1-70A8-272978F579EB} \ No newline at end of file diff --git a/extend/luakit/include/lua_base.h b/extend/luakit/include/lua_base.h index f04e638c..53b54858 100644 --- a/extend/luakit/include/lua_base.h +++ b/extend/luakit/include/lua_base.h @@ -52,6 +52,24 @@ namespace luakit { lua_State* m_L = nullptr; }; + inline bool is_lua_array(lua_State* L, int index, bool emy_as_arr = false) { + if (lua_type(L, index) != LUA_TTABLE) return false; + size_t raw_len = lua_rawlen(L, index); + if (raw_len == 0 && !emy_as_arr) return false; + index = lua_absindex(L, index); + lua_guard g(L); + lua_pushnil(L); + size_t curlen = 0; + while (lua_next(L, index) != 0) { + if (!lua_isinteger(L, -2)) return false; + size_t key = lua_tointeger(L, -2); + if (key <= 0 || key > raw_len) return false; + lua_pop(L, 1); + curlen++; + } + return curlen == raw_len; + } + class lua_exception : public std::logic_error { public: template diff --git a/extend/luakit/include/lua_codec.h b/extend/luakit/include/lua_codec.h index f9e78762..c06bf0c5 100644 --- a/extend/luakit/include/lua_codec.h +++ b/extend/luakit/include/lua_codec.h @@ -45,25 +45,6 @@ namespace luakit { return *value; } - inline bool is_array(lua_State* L, int idx, size_t raw_len) { - if (raw_len == 0) return false; - lua_guard g(L); - size_t cur_len = 0; - lua_pushnil(L); - while (lua_next(L, idx) != 0) { - if (!lua_isinteger(L, -2)) { - return false; - } - size_t key = lua_tointeger(L, -2); - if (key <= 0 || key > raw_len) { - return false; - } - cur_len++; - lua_pop(L, 1); - } - return cur_len == raw_len; - } - inline void string_encode(lua_State* L, luabuf* buff, int index) { size_t sz = 0; const char* ptr = lua_tolstring(L, index, &sz); @@ -106,8 +87,8 @@ namespace luakit { inline void table_encode(lua_State* L, luabuf* buff, int index, int depth) { index = lua_absindex(L, index); value_encode(buff, type_tab_head); - size_t rawlen = lua_rawlen(L, index); - if (is_array(L, index, rawlen)) { + if (is_lua_array(L, index)) { + int rawlen = lua_rawlen(L, index); for (int i = 1; i <= rawlen; ++i) { lua_rawgeti(L, index, i); integer_encode(buff, i); @@ -298,9 +279,9 @@ namespace luakit { inline void serialize_table(lua_State* L, luabuf* buff, int index, int depth, int line) { int size = 0; index = lua_absindex(L, index); - size_t rawlen = lua_rawlen(L, index); serialize_value(buff, "{"); - if (is_array(L, index, rawlen)) { + if (is_lua_array(L, index)) { + int rawlen = lua_rawlen(L, index); for (int i = 1; i <= rawlen; ++i){ if (size++ > 0) { serialize_value(buff, ","); diff --git a/extend/luakit/include/lua_reference.h b/extend/luakit/include/lua_reference.h index 694342c0..35d8b000 100644 --- a/extend/luakit/include/lua_reference.h +++ b/extend/luakit/include/lua_reference.h @@ -31,7 +31,7 @@ namespace luakit { protected: lua_State* m_L = nullptr; - uint32_t m_index = LUA_NOREF; + int32_t m_index = LUA_NOREF; }; template <> diff --git a/extend/luakit/luakit.lmak b/extend/luakit/luakit.lmak index de83296f..9dc01751 100644 --- a/extend/luakit/luakit.lmak +++ b/extend/luakit/luakit.lmak @@ -11,7 +11,9 @@ PROJECT_TYPE = "exe" ENABLE = false --源文件路径 -SRC_DIR = "test" +SRC_DIRS = { + "test" +} --需要的include目录 INCLUDES = { diff --git a/extend/lualog/lualog.lmak b/extend/lualog/lualog.lmak index a15a2d76..6a60c873 100644 --- a/extend/lualog/lualog.lmak +++ b/extend/lualog/lualog.lmak @@ -34,7 +34,9 @@ PSLIBS = { } --源文件路径 -SRC_DIR = "lualog" +SRC_DIRS = { + "lualog" +} --LINUX需要连接的库文件 --gcc9.1前filesystem需要链接stdc++fs diff --git a/extend/lualog/lualog.mak b/extend/lualog/lualog.mak index bec0c2c0..f11c0e82 100644 --- a/extend/lualog/lualog.mak +++ b/extend/lualog/lualog.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas #c标准库版本 #gnu99/gnu11/gnu17 @@ -43,12 +41,6 @@ MYCFLAGS += -DFMT_HEADER_ONLY LDFLAGS = -#源文件路径 -SRC_DIR = lualog - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -71,8 +63,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -103,21 +95,23 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += lualog/logger.cpp +SOURCES += lualog/lualog.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -134,6 +128,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/lualog #后编译 post_build: diff --git a/extend/lualog/lualog.vcxproj.filters b/extend/lualog/lualog.vcxproj.filters index 4b748885..b7ef6f45 100644 --- a/extend/lualog/lualog.vcxproj.filters +++ b/extend/lualog/lualog.vcxproj.filters @@ -2,23 +2,20 @@ - inc + lualog - src + lualog - src + lualog - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - - - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} + + {E44F97F7-1DE3-A547-6B58-30AEE63F22F5} \ No newline at end of file diff --git a/extend/luapb/luapb.lmak b/extend/luapb/luapb.lmak index a4583dbe..aaaf34d2 100644 --- a/extend/luapb/luapb.lmak +++ b/extend/luapb/luapb.lmak @@ -19,14 +19,12 @@ WINDOWS_DEFINES = { "LUA_BUILD_AS_DLL" } ---源文件路径v -SRC_DIR = "src" - --需要连接的库文件 LIBS = { "lua" } +--目标文件 OBJS = { "luapb.cpp" } diff --git a/extend/luapb/luapb.mak b/extend/luapb/luapb.mak index 27f658a9..f20c1f0f 100644 --- a/extend/luapb/luapb.mak +++ b/extend/luapb/luapb.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas #c标准库版本 #gnu99/gnu11/gnu17 @@ -41,12 +39,6 @@ MYCFLAGS += -I../luakit/include LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -66,8 +58,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -98,20 +90,22 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -COBJS = $(patsubst %.c, $(INT_DIR)/%.o, luapb.cpp) -MOBJS = $(patsubst %.m, $(INT_DIR)/%.o, $(COBJS)) -CCOBJS = $(patsubst %.cc, $(INT_DIR)/%.o, $(MOBJS)) -OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCOBJS)) +SOURCES = +SOURCES += src/luapb.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -128,6 +122,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/luapb/luapb.vcxproj b/extend/luapb/luapb.vcxproj index f6d50c6f..4aa71121 100644 --- a/extend/luapb/luapb.vcxproj +++ b/extend/luapb/luapb.vcxproj @@ -11,9 +11,6 @@ - - true - {2967F038-B90B-EBF5-B268-BE3BAF66D417} diff --git a/extend/luapb/luapb.vcxproj.filters b/extend/luapb/luapb.vcxproj.filters index a8c53da0..07cf8a91 100644 --- a/extend/luapb/luapb.vcxproj.filters +++ b/extend/luapb/luapb.vcxproj.filters @@ -2,21 +2,15 @@ - inc + src src - - src - - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/extend/luaxlsx/luaxlsx.lmak b/extend/luaxlsx/luaxlsx.lmak index 24096061..bbe222f4 100644 --- a/extend/luaxlsx/luaxlsx.lmak +++ b/extend/luaxlsx/luaxlsx.lmak @@ -7,13 +7,11 @@ TARGET_NAME = "luaxlsx" ----工程类型: static/dynamic/exe PROJECT_TYPE = "dynamic" -FLAGS = { - "Wno-implicit-fallthrough" -} - --需要的include目录 INCLUDES = { "../lua/lua", + "../lminiz/src", + "../luaxml/src", "../luakit/include" } @@ -32,6 +30,20 @@ WINDOWS_DEFINES = { "LUA_BUILD_AS_DLL" } +--源文件路径 +SRC_DIRS = { + "src", + "../lminiz/src", + "../luaxml/src", +} + +--目标文件 +OBJS = { + "miniz.c", + "luaxlsx.cpp", + "tinyxml2.cpp", +} + --需要连接的库文件 LIBS = { "lua" diff --git a/extend/luaxlsx/luaxlsx.mak b/extend/luaxlsx/luaxlsx.mak index 145663eb..3f3236b2 100644 --- a/extend/luaxlsx/luaxlsx.mak +++ b/extend/luaxlsx/luaxlsx.mak @@ -15,14 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas -MYCFLAGS += -Wno-implicit-fallthrough #c标准库版本 #gnu99/gnu11/gnu17 @@ -34,6 +31,8 @@ STDCPP = -std=c++17 #需要的include目录 MYCFLAGS += -I../lua/lua +MYCFLAGS += -I../lminiz/src +MYCFLAGS += -I../luaxml/src MYCFLAGS += -I../luakit/include #需要定义的选项 @@ -48,12 +47,6 @@ endif LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -73,8 +66,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -105,21 +98,24 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += ../lminiz/src/miniz.c +SOURCES += ../luaxml/src/tinyxml2.cpp +SOURCES += src/luaxlsx.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -136,6 +132,9 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/../lminiz/src + mkdir -p $(INT_DIR)/../luaxml/src + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/luaxlsx/luaxlsx.vcxproj b/extend/luaxlsx/luaxlsx.vcxproj index 45c283bd..c50a36b2 100644 --- a/extend/luaxlsx/luaxlsx.vcxproj +++ b/extend/luaxlsx/luaxlsx.vcxproj @@ -7,14 +7,15 @@ + + + - - + + - - {B2999D78-279A-1A53-CC82-74D494144722} @@ -47,7 +48,7 @@ Disabled - ..\lua\lua;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) + ..\lua\lua;..\lminiz\src;..\luaxml\src;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default MultiThreadedDLL diff --git a/extend/luaxlsx/luaxlsx.vcxproj.filters b/extend/luaxlsx/luaxlsx.vcxproj.filters index 55b517b3..e19b1227 100644 --- a/extend/luaxlsx/luaxlsx.vcxproj.filters +++ b/extend/luaxlsx/luaxlsx.vcxproj.filters @@ -1,30 +1,36 @@  - - inc + + ../lminiz/src - - inc + + ../lminiz/src - - inc + + ../luaxml/src + + + src - - src + + ../lminiz/src - - src + + ../luaxml/src - + src - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} + + {61EA48A1-7D7B-D6A6-82EE-822A0D98FD3E} + + + {26B37F58-52B6-3446-0ADC-EC1C9B3CF2D5} {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/extend/luaxlsx/src/excel.h b/extend/luaxlsx/src/excel.h index 0e438de4..934334f4 100644 --- a/extend/luaxlsx/src/excel.h +++ b/extend/luaxlsx/src/excel.h @@ -128,13 +128,10 @@ namespace lxlsx XMLElement* root = doc.FirstChildElement("worksheet"); XMLElement* dim = root->FirstChildElement("dimension"); - if (dim) { - parse_range(dim->Attribute("ref"), sh); - } + XMLElement* shdata = root->FirstChildElement("sheetData"); + parse_range(dim, shdata, sh); sh->cells.resize(sh->last_col * sh->last_row); - - XMLElement* row = root->FirstChildElement("sheetData"); - row = row->FirstChildElement("row"); + XMLElement* row = shdata->FirstChildElement("row"); while (row) { uint32_t row_idx = row->IntAttribute("r"); XMLElement* c = row->FirstChildElement("c"); @@ -327,15 +324,29 @@ namespace lxlsx } } - void parse_range(const string& value, sheet* sh) { - size_t index = value.find_first_of(':'); - if (index != string::npos) { - parse_cell(value.substr(0, index), sh->first_row, sh->first_col); - parse_cell(value.substr(index + 1), sh->last_row, sh->last_col); - } else { - parse_cell(value, sh->first_row, sh->first_col); - sh->last_col = sh->first_col; - sh->last_row = sh->first_row; + void parse_range(XMLElement* dim, XMLElement* shdata, sheet* sh) { + if (dim) { + std::string value = dim->Attribute("ref"); + size_t index = value.find_first_of(':'); + if (index != string::npos) { + parse_cell(value.substr(0, index), sh->first_row, sh->first_col); + parse_cell(value.substr(index + 1), sh->last_row, sh->last_col); + return; + } + } + XMLElement* row = shdata->FirstChildElement("row"); + while (row) { + sh->last_row = row->IntAttribute("r"); + if (sh->first_row == 0) sh->first_row = sh->last_row; + if (sh->last_col == 0) { + sh->first_col = 1; + XMLElement* c = row->FirstChildElement("c"); + while (c ) { + c = c->NextSiblingElement("c"); + sh->last_col++; + } + } + row = row->NextSiblingElement("row"); } } diff --git a/extend/luaxml/luaxml.lmak b/extend/luaxml/luaxml.lmak new file mode 100644 index 00000000..f680d638 --- /dev/null +++ b/extend/luaxml/luaxml.lmak @@ -0,0 +1,38 @@ +--工程名字 +PROJECT_NAME = "luaxml" + +--目标名字 +TARGET_NAME = "luaxml" + +----工程类型: static/dynamic/exe +PROJECT_TYPE = "dynamic" + +--目标文件前缀 +LIB_PREFIX = 1 + +--需要的include目录 +INCLUDES = { + "../../extend/lua/lua", + "../../extend/luakit/include" +} + +--WINDOWS需要定义的选项 +WINDOWS_DEFINES = { + "LUA_BUILD_AS_DLL" +} + +--需要连接的库文件 +LIBS = { + "lua" +} + +DEFINES = { +} + +--依赖项目 +DEPS = { + "lualib" +} + +--分组定义 +GROUP = "luaext" diff --git a/extend/luaxml/luaxml.mak b/extend/luaxml/luaxml.mak new file mode 100644 index 00000000..a8fde7c9 --- /dev/null +++ b/extend/luaxml/luaxml.mak @@ -0,0 +1,129 @@ +#工程名字 +PROJECT_NAME = luaxml + +#目标名字 +TARGET_NAME = luaxml + +#系统环境 +UNAME_S = $(shell uname -s) + +#伪目标 +.PHONY: clean all target pre_build post_build +all : pre_build target post_build + +#CFLAG +MYCFLAGS = + +#需要定义的FLAG +MYCFLAGS += -Wno-sign-compare +MYCFLAGS += -Wno-unused-variable +MYCFLAGS += -Wno-unused-parameter +MYCFLAGS += -Wno-unused-but-set-variable +MYCFLAGS += -Wno-unused-but-set-parameter + +#c标准库版本 +#gnu99/gnu11/gnu17 +STDC = -std=gnu99 + +#c++标准库版本 +#c++11/c++14/c++17/c++20 +STDCPP = -std=c++17 + +#需要的include目录 +MYCFLAGS += -I../../extend/lua/lua +MYCFLAGS += -I../../extend/luakit/include + +#需要定义的选项 + +#LDFLAGS +LDFLAGS = + + +#需要连接的库文件 +LIBS = +ifneq ($(UNAME_S), Darwin) +#是否启用mimalloc库 +LIBS += -lmimalloc +MYCFLAGS += -I$(SOLUTION_DIR)extend/mimalloc/mimalloc/include -include ../../mimalloc-ex.h +endif +#自定义库 +LIBS += -llua +#系统库 +LIBS += -lm -ldl -lstdc++ -lpthread + +#定义基础的编译选项 +ifndef CC +CC = gcc +endif +ifndef CX +CX = c++ +endif +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) + +#项目目录 +ifndef SOLUTION_DIR +SOLUTION_DIR=./ +endif + +#临时文件目录 +INT_DIR = $(SOLUTION_DIR)temp/$(PROJECT_NAME) + +#目标文件前缀,定义则.so和.a加lib前缀,否则不加 +PROJECT_PREFIX = lib + +#目标定义 +MYCFLAGS += -fPIC +TARGET_DIR = $(SOLUTION_DIR)bin +TARGET_DYNAMIC = $(TARGET_DIR)/$(PROJECT_PREFIX)$(TARGET_NAME).so +#soname +ifeq ($(UNAME_S), Linux) +LDFLAGS += -Wl,-soname,$(PROJECT_PREFIX)$(TARGET_NAME).so +endif +#install_name +ifeq ($(UNAME_S), Darwin) +LDFLAGS += -Wl,-install_name,$(PROJECT_PREFIX)$(TARGET_NAME).so +endif + +#link添加.so目录 +LDFLAGS += -L$(SOLUTION_DIR)bin +LDFLAGS += -L$(SOLUTION_DIR)library + +#自动生成目标 +SOURCES = +SOURCES += src/luaxml.cpp +SOURCES += src/tinyxml2.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) + +# 编译所有源文件 +$(INT_DIR)/%.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ +$(INT_DIR)/%.o : %.m + $(CC) $(CFLAGS) -c $< -o $@ +$(INT_DIR)/%.o : %.cc + $(CX) $(CXXFLAGS) -c $< -o $@ +$(INT_DIR)/%.o : %.cpp + $(CX) $(CXXFLAGS) -c $< -o $@ + +$(TARGET_DYNAMIC) : $(OBJS) + $(CC) -o $@ -shared $(OBJS) $(LDFLAGS) $(LIBS) + +#target伪目标 +target : $(TARGET_DYNAMIC) + +#clean伪目标 +clean : + rm -rf $(INT_DIR) + +#预编译 +pre_build: + mkdir -p $(INT_DIR) + mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src + +#后编译 +post_build: diff --git a/extend/luaxml/luaxml.vcxproj b/extend/luaxml/luaxml.vcxproj new file mode 100644 index 00000000..c36a3c0d --- /dev/null +++ b/extend/luaxml/luaxml.vcxproj @@ -0,0 +1,79 @@ + + + + + Develop + x64 + + + + + + + + + + + {EC638E2A-A355-0936-373E-A893B2B596DC} + luaxml + Win32Proj + 10.0 + luaxml + + + + DynamicLibrary + v143 + MultiByte + + + + + + + + + + <_ProjectFileVersion>11.0.50727.1 + + + luaxml + $(SolutionDir)temp\bin\$(Platform)\ + $(SolutionDir)temp\$(ProjectName)\$(Platform)\ + + + + Disabled + ..\..\extend\lua\lua;..\..\extend\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) + Default + MultiThreadedDLL + + Level3 + ProgramDatabase + Default + ..\..\mimalloc-ex.h + stdcpp17 + true + + + $(OutDir)$(TargetName)$(TargetExt) + $(SolutionDir)library\$(Platform);;%(AdditionalLibraryDirectories) + true + Console + $(SolutionDir)library\$(Platform)\$(TargetName).lib + $(SolutionDir)temp\$(ProjectName)\$(Platform)\$(TargetName).pdb + lua.lib;mimalloc.lib;%(AdditionalDependencies) + + + + + + + copy /y $(TargetPath) $(SolutionDir)bin + + + + + + \ No newline at end of file diff --git a/extend/luaxml/luaxml.vcxproj.filters b/extend/luaxml/luaxml.vcxproj.filters new file mode 100644 index 00000000..40bf7c43 --- /dev/null +++ b/extend/luaxml/luaxml.vcxproj.filters @@ -0,0 +1,21 @@ + + + + + src + + + + + src + + + src + + + + + {25D902C2-4283-AB8C-FBAC-54DFA101AD31} + + + \ No newline at end of file diff --git a/extend/luaxml/src/luaxml.cpp b/extend/luaxml/src/luaxml.cpp new file mode 100644 index 00000000..76344e62 --- /dev/null +++ b/extend/luaxml/src/luaxml.cpp @@ -0,0 +1,216 @@ +#define LUA_LIB + +#include "lua_kit.h" +#include "tinyxml2.h" + +using namespace luakit; +using namespace tinyxml2; + +namespace luaxml { + + static void push_elem2lua(lua_State* L, const XMLElement* elem) { + uint32_t count = elem->ChildElementCount(); + const XMLAttribute* attr = elem->FirstAttribute(); + const char* value = elem->GetText(); + if (count == 0 && attr == nullptr) { + value = value ? value : ""; + if (lua_stringtonumber(L, value) == 0) { + lua_pushstring(L, value); + } + return; + } + lua_createtable(L, 0, 4); + if (value) { + if (lua_stringtonumber(L, value) == 0) { + lua_pushstring(L, value); + } + lua_seti(L, -2, 1); + } + if (attr) { + lua_createtable(L, 0, 4); + while (attr) { + if (lua_stringtonumber(L, attr->Value()) == 0) { + lua_pushstring(L, attr->Value()); + } + lua_setfield(L, -2, attr->Name()); + attr = attr->Next(); + } + lua_setfield(L, -2, "_attr"); + } + if (count > 0) { + const XMLElement* child = elem->FirstChildElement(); + std::map> elems; + while (child) { + auto it = elems.find(child->Name()); + if (it != elems.end()) { + it->second.push_back(child); + } else { + elems.insert(std::make_pair(child->Name(), std::vector{ child })); + } + child = child->NextSiblingElement(); + } + for (auto it : elems) { + size_t child_size = it.second.size(); + if (child_size == 1) { + push_elem2lua(L, it.second[0]); + } else { + lua_createtable(L, 0, 4); + for (size_t i = 0; i < child_size; ++i) { + push_elem2lua(L, it.second[i]); + lua_seti(L, -2, i + 1); + } + } + lua_setfield(L, -2, it.first.c_str()); + } + } + } + static void load_elem4lua(lua_State* L, XMLPrinter* printer); + static void load_table4lua(lua_State* L, XMLPrinter* printer) { + lua_guard g(L); + if (lua_getfield(L, -1, "_attr") == LUA_TTABLE) { + lua_pushnil(L); + while (lua_next(L, -2) != 0) { + const char* key = lua_tostring(L, -2); + switch (lua_type(L, -1)) { + case LUA_TSTRING: printer->PushAttribute(key, lua_tostring(L, -1)); break; + case LUA_TBOOLEAN: printer->PushAttribute(key, lua_toboolean(L, -1)); break; + case LUA_TNUMBER: lua_isinteger(L, -1) ? printer->PushAttribute(key, int64_t(lua_tointeger(L, -1))) : printer->PushAttribute(key, lua_tonumber(L, -1)); break; + } + lua_pop(L, 1); + } + } + lua_pushnil(L); + lua_setfield(L, -3, "_attr"); + switch (lua_geti(L, -2, 1)) { + case LUA_TSTRING: printer->PushText(lua_tostring(L, -1)); break; + case LUA_TBOOLEAN: printer->PushText(lua_toboolean(L, -1)); break; + case LUA_TNUMBER: lua_isinteger(L, -1) ? printer->PushText(int64_t(lua_tointeger(L, -1))) : printer->PushText(lua_tonumber(L, -1)); break; + } + lua_pushnil(L); + lua_seti(L, -4, 1); + lua_pushnil(L); + while (lua_next(L, -4) != 0) { + load_elem4lua(L, printer); + lua_pop(L, 1); + } + } + + static void load_elem4lua(lua_State* L, XMLPrinter* printer) { + const char* key = lua_tostring(L, -2); + if (!is_lua_array(L, -1)) { + printer->OpenElement(key); + switch (lua_type(L, -1)) { + case LUA_TTABLE: load_table4lua(L, printer); break; + case LUA_TSTRING: printer->PushText(lua_tostring(L, -1)); break; + case LUA_TBOOLEAN: printer->PushText(lua_toboolean(L, -1)); break; + case LUA_TNUMBER: lua_isinteger(L, -1) ? printer->PushText(int64_t(lua_tointeger(L, -1))) : printer->PushText(lua_tonumber(L, -1)); break; + } + printer->CloseElement(); + return; + } + lua_pushstring(L, key); + int raw_len = lua_rawlen(L, -2); + for (int i = 1; i <= raw_len; ++i) { + lua_rawgeti(L, -2, i); + load_elem4lua(L, printer); + lua_pop(L, 1); + } + lua_pop(L, 1); + } + + static int decode_xml(lua_State* L, const char* xml) { + XMLDocument doc; + if (doc.Parse(xml) != XML_SUCCESS) { + lua_pushnil(L); + lua_pushstring(L, "parse xml doc failed!"); + return 2; + } + lua_createtable(L, 0, 4); + const XMLElement* root = doc.RootElement(); + push_elem2lua(L, root); + lua_setfield(L, -2, root->Name()); + return 1; + } + + static int encode_xml(lua_State* L) { + XMLPrinter printer; + const char* header = luaL_optstring(L, 3, nullptr); + if (header) { + printer.PushDeclaration(header); + } else { + printer.PushHeader(false, true); + } + lua_pushnil(L); + while (lua_next(L, 1) != 0) { + load_elem4lua(L, &printer); + lua_pop(L, 1); + } + lua_pushlstring(L, printer.CStr(), printer.CStrSize()); + return 1; + } + + static int open_xml(lua_State* L, const char* xmlfile) { + XMLDocument doc; + if (doc.LoadFile(xmlfile) != XML_SUCCESS) { + lua_pushnil(L); + lua_pushstring(L, "parse xml doc failed!"); + return 2; + } + lua_createtable(L, 0, 4); + const XMLElement* root = doc.RootElement(); + push_elem2lua(L, root); + lua_setfield(L, -2, root->Name()); + return 1; + } + + static FILE* fopenxml(const char* filepath, const char* mode) { +#if defined(_MSC_VER) + FILE* fp = 0; + const errno_t err = fopen_s(&fp, filepath, mode); + if (err) return 0; +#else + FILE* fp = fopen(filepath, mode); +#endif + return fp; + } + + static int save_xml(lua_State* L, const char* xmlfile) { + FILE* fp = fopenxml(xmlfile, "w"); + if (fp == nullptr) { + lua_pushboolean(L, false); + lua_pushstring(L, "file dont open, save xml failed!"); + return 2; + } + XMLPrinter printer(fp); + const char* header = luaL_optstring(L, 3, nullptr); + if (header) { + printer.PushDeclaration(header); + } else { + printer.PushHeader(false, true); + } + lua_pushnil(L); + while (lua_next(L, 2) != 0) { + load_elem4lua(L, &printer); + lua_pop(L, 1); + } + fclose(fp); + return 1; + } + + lua_table open_luaxml(lua_State* L) { + kit_state kit_state(L); + lua_table lxml = kit_state.new_table("xml"); + lxml.set_function("decode", decode_xml); + lxml.set_function("encode", encode_xml); + lxml.set_function("open", open_xml); + lxml.set_function("save", save_xml); + return lxml; + } +} + +extern "C" { + LUALIB_API int luaopen_luaxml(lua_State* L) { + auto luaxlsx = luaxml::open_luaxml(L); + return luaxlsx.push_stack(); + } +} diff --git a/extend/luaxlsx/src/tinyxml2.cpp b/extend/luaxml/src/tinyxml2.cpp similarity index 65% rename from extend/luaxlsx/src/tinyxml2.cpp rename to extend/luaxml/src/tinyxml2.cpp index a4977098..155d8958 100644 --- a/extend/luaxlsx/src/tinyxml2.cpp +++ b/extend/luaxml/src/tinyxml2.cpp @@ -24,7 +24,7 @@ distribution. #include "tinyxml2.h" #include // yes, this one new style header, is in the Android SDK. -#if defined(ANDROID_NDK) || defined(__QNXNTO__) +#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__) # include # include #else @@ -45,14 +45,14 @@ distribution. { va_list va; va_start( va, format ); - int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va ); + const int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va ); va_end( va ); return result; } static inline int TIXML_VSNPRINTF( char* buffer, size_t size, const char* format, va_list va ) { - int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va ); + const int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va ); return result; } @@ -100,10 +100,24 @@ distribution. #define TIXML_SSCANF sscanf #endif +#if defined(_WIN64) + #define TIXML_FSEEK _fseeki64 + #define TIXML_FTELL _ftelli64 +#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__CYGWIN__) + #define TIXML_FSEEK fseeko + #define TIXML_FTELL ftello +#elif defined(__ANDROID__) && __ANDROID_API__ > 24 + #define TIXML_FSEEK fseeko64 + #define TIXML_FTELL ftello64 +#else + #define TIXML_FSEEK fseek + #define TIXML_FTELL ftell +#endif + -static const char LINE_FEED = (char)0x0a; // all line endings are normalized to LF +static const char LINE_FEED = static_cast(0x0a); // all line endings are normalized to LF static const char LF = LINE_FEED; -static const char CARRIAGE_RETURN = (char)0x0d; // CR gets filtered out +static const char CARRIAGE_RETURN = static_cast(0x0d); // CR gets filtered out static const char CR = CARRIAGE_RETURN; static const char SINGLE_QUOTE = '\''; static const char DOUBLE_QUOTE = '\"'; @@ -149,6 +163,7 @@ void StrPair::TransferTo( StrPair* other ) // This in effect implements the assignment operator by "moving" // ownership (as in auto_ptr). + TIXMLASSERT( other != 0 ); TIXMLASSERT( other->_flags == 0 ); TIXMLASSERT( other->_start == 0 ); TIXMLASSERT( other->_end == 0 ); @@ -164,6 +179,7 @@ void StrPair::TransferTo( StrPair* other ) _end = 0; } + void StrPair::Reset() { if ( _flags & NEEDS_DELETE ) { @@ -188,12 +204,14 @@ void StrPair::SetStr( const char* str, int flags ) } -char* StrPair::ParseText( char* p, const char* endTag, int strFlags ) +char* StrPair::ParseText( char* p, const char* endTag, int strFlags, int* curLineNumPtr ) { + TIXMLASSERT( p ); TIXMLASSERT( endTag && *endTag ); + TIXMLASSERT(curLineNumPtr); char* start = p; - char endChar = *endTag; + const char endChar = *endTag; size_t length = strlen( endTag ); // Inner loop of text parsing. @@ -201,8 +219,11 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags ) if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) { Set( start, p, strFlags ); return p + length; + } else if (*p == '\n') { + ++(*curLineNumPtr); } ++p; + TIXMLASSERT( p ); } return 0; } @@ -213,13 +234,13 @@ char* StrPair::ParseName( char* p ) if ( !p || !(*p) ) { return 0; } - if ( !XMLUtil::IsNameStartChar( *p ) ) { + if ( !XMLUtil::IsNameStartChar( (unsigned char) *p ) ) { return 0; } char* const start = p; ++p; - while ( *p && XMLUtil::IsNameChar( *p ) ) { + while ( *p && XMLUtil::IsNameChar( (unsigned char) *p ) ) { ++p; } @@ -233,15 +254,15 @@ void StrPair::CollapseWhitespace() // Adjusting _start would cause undefined behavior on delete[] TIXMLASSERT( ( _flags & NEEDS_DELETE ) == 0 ); // Trim leading space. - _start = XMLUtil::SkipWhiteSpace( _start ); + _start = XMLUtil::SkipWhiteSpace( _start, 0 ); if ( *_start ) { - char* p = _start; // the read pointer + const char* p = _start; // the read pointer char* q = _start; // the write pointer while( *p ) { if ( XMLUtil::IsWhiteSpace( *p )) { - p = XMLUtil::SkipWhiteSpace( p ); + p = XMLUtil::SkipWhiteSpace( p, 0 ); if ( *p == 0 ) { break; // don't write to q; this trims the trailing space. } @@ -266,7 +287,7 @@ const char* StrPair::GetStr() _flags ^= NEEDS_FLUSH; if ( _flags ) { - char* p = _start; // the read pointer + const char* p = _start; // the read pointer char* q = _start; // the write pointer while( p < _end ) { @@ -280,7 +301,8 @@ const char* StrPair::GetStr() else { ++p; } - *q++ = LF; + *q = LF; + ++q; } else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) { if ( *(p+1) == CR ) { @@ -289,7 +311,8 @@ const char* StrPair::GetStr() else { ++p; } - *q++ = LF; + *q = LF; + ++q; } else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) { // Entities handled by tinyXML2: @@ -301,7 +324,7 @@ const char* StrPair::GetStr() const int buflen = 10; char buf[buflen] = { 0 }; int len = 0; - char* adjusted = const_cast( XMLUtil::GetCharacterRef( p, buf, &len ) ); + const char* adjusted = const_cast( XMLUtil::GetCharacterRef( p, buf, &len ) ); if ( adjusted == 0 ) { *q = *p; ++p; @@ -360,6 +383,19 @@ const char* StrPair::GetStr() // --------- XMLUtil ----------- // +const char* XMLUtil::writeBoolTrue = "true"; +const char* XMLUtil::writeBoolFalse = "false"; + +void XMLUtil::SetBoolSerialization(const char* writeTrue, const char* writeFalse) +{ + static const char* defTrue = "true"; + static const char* defFalse = "false"; + + writeBoolTrue = (writeTrue) ? writeTrue : defTrue; + writeBoolFalse = (writeFalse) ? writeFalse : defFalse; +} + + const char* XMLUtil::ReadBOM( const char* p, bool* bom ) { TIXMLASSERT( p ); @@ -403,23 +439,27 @@ void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length output += *length; - // Scary scary fall throughs. + // Scary scary fall throughs are annotated with carefully designed comments + // to suppress compiler warnings such as -Wimplicit-fallthrough in gcc switch (*length) { case 4: --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); + *output = static_cast((input | BYTE_MARK) & BYTE_MASK); input >>= 6; + //fall through case 3: --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); + *output = static_cast((input | BYTE_MARK) & BYTE_MASK); input >>= 6; + //fall through case 2: --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); + *output = static_cast((input | BYTE_MARK) & BYTE_MASK); input >>= 6; + //fall through case 1: --output; - *output = (char)(input | FIRST_BYTE_MARK[*length]); + *output = static_cast(input | FIRST_BYTE_MARK[*length]); break; default: TIXMLASSERT( false ); @@ -471,7 +511,7 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length ) else { return 0; } - TIXMLASSERT( digit >= 0 && digit < 16); + TIXMLASSERT( digit < 16 ); TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit ); const unsigned int digitScaled = mult * digit; TIXMLASSERT( ucs <= ULONG_MAX - digitScaled ); @@ -501,7 +541,7 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length ) while ( *q != '#' ) { if ( *q >= '0' && *q <= '9' ) { const unsigned int digit = *q - '0'; - TIXMLASSERT( digit >= 0 && digit < 10); + TIXMLASSERT( digit < 10 ); TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit ); const unsigned int digitScaled = mult * digit; TIXMLASSERT( ucs <= ULONG_MAX - digitScaled ); @@ -537,7 +577,7 @@ void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize ) void XMLUtil::ToStr( bool v, char* buffer, int bufferSize ) { - TIXML_SNPRINTF( buffer, bufferSize, "%d", v ? 1 : 0 ); + TIXML_SNPRINTF( buffer, bufferSize, "%s", v ? writeBoolTrue : writeBoolFalse); } /* @@ -556,17 +596,38 @@ void XMLUtil::ToStr( double v, char* buffer, int bufferSize ) } -bool XMLUtil::ToInt( const char* str, int* value ) +void XMLUtil::ToStr( int64_t v, char* buffer, int bufferSize ) { - if ( TIXML_SSCANF( str, "%d", value ) == 1 ) { - return true; + // horrible syntax trick to make the compiler happy about %lld + TIXML_SNPRINTF(buffer, bufferSize, "%lld", static_cast(v)); +} + +void XMLUtil::ToStr( uint64_t v, char* buffer, int bufferSize ) +{ + // horrible syntax trick to make the compiler happy about %llu + TIXML_SNPRINTF(buffer, bufferSize, "%llu", (long long)v); +} + +bool XMLUtil::ToInt(const char* str, int* value) +{ + if (IsPrefixHex(str)) { + unsigned v; + if (TIXML_SSCANF(str, "%x", &v) == 1) { + *value = static_cast(v); + return true; + } + } + else { + if (TIXML_SSCANF(str, "%d", value) == 1) { + return true; + } } return false; } -bool XMLUtil::ToUnsigned( const char* str, unsigned *value ) +bool XMLUtil::ToUnsigned(const char* str, unsigned* value) { - if ( TIXML_SSCANF( str, "%u", value ) == 1 ) { + if (TIXML_SSCANF(str, IsPrefixHex(str) ? "%x" : "%u", value) == 1) { return true; } return false; @@ -579,13 +640,20 @@ bool XMLUtil::ToBool( const char* str, bool* value ) *value = (ival==0) ? false : true; return true; } - if ( StringEqual( str, "true" ) ) { - *value = true; - return true; + static const char* TRUE_VALS[] = { "true", "True", "TRUE", 0 }; + static const char* FALSE_VALS[] = { "false", "False", "FALSE", 0 }; + + for (int i = 0; TRUE_VALS[i]; ++i) { + if (StringEqual(str, TRUE_VALS[i])) { + *value = true; + return true; + } } - else if ( StringEqual( str, "false" ) ) { - *value = false; - return true; + for (int i = 0; FALSE_VALS[i]; ++i) { + if (StringEqual(str, FALSE_VALS[i])) { + *value = false; + return true; + } } return false; } @@ -599,6 +667,7 @@ bool XMLUtil::ToFloat( const char* str, float* value ) return false; } + bool XMLUtil::ToDouble( const char* str, double* value ) { if ( TIXML_SSCANF( str, "%lf", value ) == 1 ) { @@ -608,12 +677,43 @@ bool XMLUtil::ToDouble( const char* str, double* value ) } -char* XMLDocument::Identify( char* p, XMLNode** node ) +bool XMLUtil::ToInt64(const char* str, int64_t* value) +{ + if (IsPrefixHex(str)) { + unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llx + if (TIXML_SSCANF(str, "%llx", &v) == 1) { + *value = static_cast(v); + return true; + } + } + else { + long long v = 0; // horrible syntax trick to make the compiler happy about %lld + if (TIXML_SSCANF(str, "%lld", &v) == 1) { + *value = static_cast(v); + return true; + } + } + return false; +} + + +bool XMLUtil::ToUnsigned64(const char* str, uint64_t* value) { + unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llu + if(TIXML_SSCANF(str, IsPrefixHex(str) ? "%llx" : "%llu", &v) == 1) { + *value = (uint64_t)v; + return true; + } + return false; +} + + +char* XMLDocument::Identify( char* p, XMLNode** node, bool first ) { TIXMLASSERT( node ); TIXMLASSERT( p ); char* const start = p; - p = XMLUtil::SkipWhiteSpace( p ); + int const startLine = _parseCurLineNum; + p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum ); if( !*p ) { *node = 0; TIXMLASSERT( p ); @@ -637,42 +737,47 @@ char* XMLDocument::Identify( char* p, XMLNode** node ) TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool XMLNode* returnNode = 0; if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) { - TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() ); - returnNode = new (_commentPool.Alloc()) XMLDeclaration( this ); - returnNode->_memPool = &_commentPool; + returnNode = CreateUnlinkedNode( _commentPool ); + returnNode->_parseLineNum = _parseCurLineNum; p += xmlHeaderLen; } else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) { - TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() ); - returnNode = new (_commentPool.Alloc()) XMLComment( this ); - returnNode->_memPool = &_commentPool; + returnNode = CreateUnlinkedNode( _commentPool ); + returnNode->_parseLineNum = _parseCurLineNum; p += commentHeaderLen; } else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) { - TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() ); - XMLText* text = new (_textPool.Alloc()) XMLText( this ); + XMLText* text = CreateUnlinkedNode( _textPool ); returnNode = text; - returnNode->_memPool = &_textPool; + returnNode->_parseLineNum = _parseCurLineNum; p += cdataHeaderLen; text->SetCData( true ); } else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) { - TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() ); - returnNode = new (_commentPool.Alloc()) XMLUnknown( this ); - returnNode->_memPool = &_commentPool; + returnNode = CreateUnlinkedNode( _commentPool ); + returnNode->_parseLineNum = _parseCurLineNum; p += dtdHeaderLen; } else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) { - TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() ); - returnNode = new (_elementPool.Alloc()) XMLElement( this ); - returnNode->_memPool = &_elementPool; - p += elementHeaderLen; + + // Preserve whitespace pedantically before closing tag, when it's immediately after opening tag + if (WhitespaceMode() == PEDANTIC_WHITESPACE && first && p != start && *(p + elementHeaderLen) == '/') { + returnNode = CreateUnlinkedNode(_textPool); + returnNode->_parseLineNum = startLine; + p = start; // Back it up, all the text counts. + _parseCurLineNum = startLine; + } + else { + returnNode = CreateUnlinkedNode(_elementPool); + returnNode->_parseLineNum = _parseCurLineNum; + p += elementHeaderLen; + } } else { - TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() ); - returnNode = new (_textPool.Alloc()) XMLText( this ); - returnNode->_memPool = &_textPool; + returnNode = CreateUnlinkedNode( _textPool ); + returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character p = start; // Back it up, all the text counts. + _parseCurLineNum = startLine; } TIXMLASSERT( returnNode ); @@ -701,8 +806,11 @@ bool XMLDocument::Accept( XMLVisitor* visitor ) const XMLNode::XMLNode( XMLDocument* doc ) : _document( doc ), _parent( 0 ), + _value(), + _parseLineNum( 0 ), _firstChild( 0 ), _lastChild( 0 ), _prev( 0 ), _next( 0 ), + _userData( 0 ), _memPool( 0 ) { } @@ -716,9 +824,37 @@ XMLNode::~XMLNode() } } -const char* XMLNode::Value() const +// ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2. + +int XMLNode::ChildElementCount(const char *value) const { + int count = 0; + + const XMLElement *e = FirstChildElement(value); + + while (e) { + e = e->NextSiblingElement(value); + count++; + } + + return count; +} + +int XMLNode::ChildElementCount() const { + int count = 0; + + const XMLElement *e = FirstChildElement(); + + while (e) { + e = e->NextSiblingElement(); + count++; + } + + return count; +} + +const char* XMLNode::Value() const { - // Catch an edge case: XMLDocuments don't have a a Value. Carefully return nullptr. + // Edge case: XMLDocuments don't have a Value. Return null. if ( this->ToDocument() ) return 0; return _value.GetStr(); @@ -734,16 +870,24 @@ void XMLNode::SetValue( const char* str, bool staticMem ) } } +XMLNode* XMLNode::DeepClone(XMLDocument* target) const +{ + XMLNode* clone = this->ShallowClone(target); + if (!clone) return 0; + + for (const XMLNode* child = this->FirstChild(); child; child = child->NextSibling()) { + XMLNode* childClone = child->DeepClone(target); + TIXMLASSERT(childClone); + clone->InsertEndChild(childClone); + } + return clone; +} void XMLNode::DeleteChildren() { while( _firstChild ) { TIXMLASSERT( _lastChild ); - TIXMLASSERT( _firstChild->_document == _document ); - XMLNode* node = _firstChild; - Unlink( node ); - - DeleteNode( node ); + DeleteChild( _firstChild ); } _firstChild = _lastChild = 0; } @@ -767,6 +911,8 @@ void XMLNode::Unlink( XMLNode* child ) if ( child->_next ) { child->_next->_prev = child->_prev; } + child->_next = 0; + child->_prev = 0; child->_parent = 0; } @@ -777,6 +923,9 @@ void XMLNode::DeleteChild( XMLNode* node ) TIXMLASSERT( node->_document == _document ); TIXMLASSERT( node->_parent == this ); Unlink( node ); + TIXMLASSERT(node->_prev == 0); + TIXMLASSERT(node->_next == 0); + TIXMLASSERT(node->_parent == 0); DeleteNode( node ); } @@ -856,6 +1005,13 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ) TIXMLASSERT( false ); return 0; } + if ( afterThis == addThis ) { + // Current state: BeforeThis -> AddThis -> OneAfterAddThis + // Now AddThis must disappear from it's location and then + // reappear between BeforeThis and OneAfterAddThis. + // So just leave it where it is. + return addThis; + } if ( afterThis->_next == 0 ) { // The last node or the only node. @@ -876,11 +1032,9 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ) const XMLElement* XMLNode::FirstChildElement( const char* name ) const { for( const XMLNode* node = _firstChild; node; node = node->_next ) { - const XMLElement* element = node->ToElement(); + const XMLElement* element = node->ToElementWithName( name ); if ( element ) { - if ( !name || XMLUtil::StringEqual( element->Name(), name ) ) { - return element; - } + return element; } } return 0; @@ -890,11 +1044,9 @@ const XMLElement* XMLNode::FirstChildElement( const char* name ) const const XMLElement* XMLNode::LastChildElement( const char* name ) const { for( const XMLNode* node = _lastChild; node; node = node->_prev ) { - const XMLElement* element = node->ToElement(); + const XMLElement* element = node->ToElementWithName( name ); if ( element ) { - if ( !name || XMLUtil::StringEqual( element->Name(), name ) ) { - return element; - } + return element; } } return 0; @@ -904,9 +1056,8 @@ const XMLElement* XMLNode::LastChildElement( const char* name ) const const XMLElement* XMLNode::NextSiblingElement( const char* name ) const { for( const XMLNode* node = _next; node; node = node->_next ) { - const XMLElement* element = node->ToElement(); - if ( element - && (!name || XMLUtil::StringEqual( name, element->Name() ))) { + const XMLElement* element = node->ToElementWithName( name ); + if ( element ) { return element; } } @@ -917,9 +1068,8 @@ const XMLElement* XMLNode::NextSiblingElement( const char* name ) const const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const { for( const XMLNode* node = _prev; node; node = node->_prev ) { - const XMLElement* element = node->ToElement(); - if ( element - && (!name || XMLUtil::StringEqual( name, element->Name() ))) { + const XMLElement* element = node->ToElementWithName( name ); + if ( element ) { return element; } } @@ -927,7 +1077,7 @@ const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const } -char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) +char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) { // This is a recursive method, but thinking about it "at the current level" // it is a pretty simple flat list: @@ -946,41 +1096,70 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) // 'endTag' is the end tag for this node, it is returned by a call to a child. // 'parentEnd' is the end tag for the parent, which is filled in and returned. - while( p && *p ) { + XMLDocument::DepthTracker tracker(_document); + if (_document->Error()) + return 0; + + bool first = true; + while( p && *p ) { XMLNode* node = 0; - p = _document->Identify( p, &node ); + p = _document->Identify( p, &node, first ); + TIXMLASSERT( p ); if ( node == 0 ) { break; } + first = false; + + const int initialLineNum = node->_parseLineNum; StrPair endTag; - p = node->ParseDeep( p, &endTag ); + p = node->ParseDeep( p, &endTag, curLineNumPtr ); if ( !p ) { - DeleteNode( node ); + _document->DeleteNode( node ); if ( !_document->Error() ) { - _document->SetError( XML_ERROR_PARSING, 0, 0 ); + _document->SetError( XML_ERROR_PARSING, initialLineNum, 0); } break; } - XMLDeclaration* decl = node->ToDeclaration(); + const XMLDeclaration* const decl = node->ToDeclaration(); if ( decl ) { - // A declaration can only be the first child of a document. - // Set error, if document already has children. - if ( !_document->NoChildren() ) { - _document->SetError( XML_ERROR_PARSING_DECLARATION, decl->Value(), 0); - DeleteNode( decl ); - break; + // Declarations are only allowed at document level + // + // Multiple declarations are allowed but all declarations + // must occur before anything else. + // + // Optimized due to a security test case. If the first node is + // a declaration, and the last node is a declaration, then only + // declarations have so far been added. + bool wellLocated = false; + + if (ToDocument()) { + if (FirstChild()) { + wellLocated = + FirstChild() && + FirstChild()->ToDeclaration() && + LastChild() && + LastChild()->ToDeclaration(); } + else { + wellLocated = true; + } + } + if ( !wellLocated ) { + _document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "XMLDeclaration value=%s", decl->Value()); + _document->DeleteNode( node ); + break; + } } XMLElement* ele = node->ToElement(); if ( ele ) { // We read the end tag. Return it to the parent. if ( ele->ClosingType() == XMLElement::CLOSING ) { - if ( parentEnd ) { - ele->_value.TransferTo( parentEnd ); + if ( parentEndTag ) { + ele->_value.TransferTo( parentEndTag ); } node->_memPool->SetTracked(); // created and then immediately deleted. DeleteNode( node ); @@ -1004,8 +1183,8 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) } } if ( mismatch ) { - _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, ele->Name(), 0 ); - DeleteNode( node ); + _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "XMLElement name=%s", ele->Name()); + _document->DeleteNode( node ); break; } } @@ -1014,11 +1193,16 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) return 0; } -void XMLNode::DeleteNode( XMLNode* node ) +/*static*/ void XMLNode::DeleteNode( XMLNode* node ) { if ( node == 0 ) { return; } + TIXMLASSERT(node->_document); + if (!node->ToDocument()) { + node->_document->MarkInUse(node); + } + MemPool* pool = node->_memPool; node->~XMLNode(); pool->Free( node ); @@ -1029,20 +1213,37 @@ void XMLNode::InsertChildPreamble( XMLNode* insertThis ) const TIXMLASSERT( insertThis ); TIXMLASSERT( insertThis->_document == _document ); - if ( insertThis->_parent ) + if (insertThis->_parent) { insertThis->_parent->Unlink( insertThis ); - else + } + else { + insertThis->_document->MarkInUse(insertThis); insertThis->_memPool->SetTracked(); + } +} + +const XMLElement* XMLNode::ToElementWithName( const char* name ) const +{ + const XMLElement* element = this->ToElement(); + if ( element == 0 ) { + return 0; + } + if ( name == 0 ) { + return element; + } + if ( XMLUtil::StringEqual( element->Name(), name ) ) { + return element; + } + return 0; } // --------- XMLText ---------- // -char* XMLText::ParseDeep( char* p, StrPair* ) +char* XMLText::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) { - const char* start = p; if ( this->CData() ) { - p = _value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION ); + p = _value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( !p ) { - _document->SetError( XML_ERROR_PARSING_CDATA, start, 0 ); + _document->SetError( XML_ERROR_PARSING_CDATA, _parseLineNum, 0 ); } return p; } @@ -1052,12 +1253,12 @@ char* XMLText::ParseDeep( char* p, StrPair* ) flags |= StrPair::NEEDS_WHITESPACE_COLLAPSING; } - p = _value.ParseText( p, "<", flags ); + p = _value.ParseText( p, "<", flags, curLineNumPtr ); if ( p && *p ) { return p-1; } if ( !p ) { - _document->SetError( XML_ERROR_PARSING_TEXT, start, 0 ); + _document->SetError( XML_ERROR_PARSING_TEXT, _parseLineNum, 0 ); } } return 0; @@ -1077,6 +1278,7 @@ XMLNode* XMLText::ShallowClone( XMLDocument* doc ) const bool XMLText::ShallowEqual( const XMLNode* compare ) const { + TIXMLASSERT( compare ); const XMLText* text = compare->ToText(); return ( text && XMLUtil::StringEqual( text->Value(), Value() ) ); } @@ -1101,13 +1303,12 @@ XMLComment::~XMLComment() } -char* XMLComment::ParseDeep( char* p, StrPair* ) +char* XMLComment::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) { // Comment parses as text. - const char* start = p; - p = _value.ParseText( p, "-->", StrPair::COMMENT ); + p = _value.ParseText( p, "-->", StrPair::COMMENT, curLineNumPtr ); if ( p == 0 ) { - _document->SetError( XML_ERROR_PARSING_COMMENT, start, 0 ); + _document->SetError( XML_ERROR_PARSING_COMMENT, _parseLineNum, 0 ); } return p; } @@ -1151,13 +1352,12 @@ XMLDeclaration::~XMLDeclaration() } -char* XMLDeclaration::ParseDeep( char* p, StrPair* ) +char* XMLDeclaration::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) { // Declaration parses as text. - const char* start = p; - p = _value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION ); + p = _value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( p == 0 ) { - _document->SetError( XML_ERROR_PARSING_DECLARATION, start, 0 ); + _document->SetError( XML_ERROR_PARSING_DECLARATION, _parseLineNum, 0 ); } return p; } @@ -1200,14 +1400,12 @@ XMLUnknown::~XMLUnknown() } -char* XMLUnknown::ParseDeep( char* p, StrPair* ) +char* XMLUnknown::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) { // Unknown parses as text. - const char* start = p; - - p = _value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION ); + p = _value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( !p ) { - _document->SetError( XML_ERROR_PARSING_UNKNOWN, start, 0 ); + _document->SetError( XML_ERROR_PARSING_UNKNOWN, _parseLineNum, 0 ); } return p; } @@ -1239,17 +1437,17 @@ bool XMLUnknown::Accept( XMLVisitor* visitor ) const // --------- XMLAttribute ---------- // -const char* XMLAttribute::Name() const +const char* XMLAttribute::Name() const { return _name.GetStr(); } -const char* XMLAttribute::Value() const +const char* XMLAttribute::Value() const { return _value.GetStr(); } -char* XMLAttribute::ParseDeep( char* p, bool processEntities ) +char* XMLAttribute::ParseDeep( char* p, bool processEntities, int* curLineNumPtr ) { // Parse using the name rules: bug fix, was using ParseText before p = _name.ParseName( p ); @@ -1258,21 +1456,21 @@ char* XMLAttribute::ParseDeep( char* p, bool processEntities ) } // Skip white space before = - p = XMLUtil::SkipWhiteSpace( p ); + p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); if ( *p != '=' ) { return 0; } ++p; // move up to opening quote - p = XMLUtil::SkipWhiteSpace( p ); + p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); if ( *p != '\"' && *p != '\'' ) { return 0; } - char endTag[2] = { *p, 0 }; + const char endTag[2] = { *p, 0 }; ++p; // move past opening quote - p = _value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES ); + p = _value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES, curLineNumPtr ); return p; } @@ -1286,7 +1484,7 @@ void XMLAttribute::SetName( const char* n ) XMLError XMLAttribute::QueryIntValue( int* value ) const { if ( XMLUtil::ToInt( Value(), value )) { - return XML_NO_ERROR; + return XML_SUCCESS; } return XML_WRONG_ATTRIBUTE_TYPE; } @@ -1295,7 +1493,25 @@ XMLError XMLAttribute::QueryIntValue( int* value ) const XMLError XMLAttribute::QueryUnsignedValue( unsigned int* value ) const { if ( XMLUtil::ToUnsigned( Value(), value )) { - return XML_NO_ERROR; + return XML_SUCCESS; + } + return XML_WRONG_ATTRIBUTE_TYPE; +} + + +XMLError XMLAttribute::QueryInt64Value(int64_t* value) const +{ + if (XMLUtil::ToInt64(Value(), value)) { + return XML_SUCCESS; + } + return XML_WRONG_ATTRIBUTE_TYPE; +} + + +XMLError XMLAttribute::QueryUnsigned64Value(uint64_t* value) const +{ + if(XMLUtil::ToUnsigned64(Value(), value)) { + return XML_SUCCESS; } return XML_WRONG_ATTRIBUTE_TYPE; } @@ -1304,7 +1520,7 @@ XMLError XMLAttribute::QueryUnsignedValue( unsigned int* value ) const XMLError XMLAttribute::QueryBoolValue( bool* value ) const { if ( XMLUtil::ToBool( Value(), value )) { - return XML_NO_ERROR; + return XML_SUCCESS; } return XML_WRONG_ATTRIBUTE_TYPE; } @@ -1313,7 +1529,7 @@ XMLError XMLAttribute::QueryBoolValue( bool* value ) const XMLError XMLAttribute::QueryFloatValue( float* value ) const { if ( XMLUtil::ToFloat( Value(), value )) { - return XML_NO_ERROR; + return XML_SUCCESS; } return XML_WRONG_ATTRIBUTE_TYPE; } @@ -1322,7 +1538,7 @@ XMLError XMLAttribute::QueryFloatValue( float* value ) const XMLError XMLAttribute::QueryDoubleValue( double* value ) const { if ( XMLUtil::ToDouble( Value(), value )) { - return XML_NO_ERROR; + return XML_SUCCESS; } return XML_WRONG_ATTRIBUTE_TYPE; } @@ -1350,6 +1566,21 @@ void XMLAttribute::SetAttribute( unsigned v ) } +void XMLAttribute::SetAttribute(int64_t v) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + _value.SetStr(buf); +} + +void XMLAttribute::SetAttribute(uint64_t v) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + _value.SetStr(buf); +} + + void XMLAttribute::SetAttribute( bool v ) { char buf[BUF_SIZE]; @@ -1374,7 +1605,7 @@ void XMLAttribute::SetAttribute( float v ) // --------- XMLElement ---------- // XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ), - _closingType( 0 ), + _closingType( OPEN ), _rootAttribute( 0 ) { } @@ -1413,11 +1644,69 @@ const char* XMLElement::Attribute( const char* name, const char* value ) const return 0; } +int XMLElement::IntAttribute(const char* name, int defaultValue) const +{ + int i = defaultValue; + QueryIntAttribute(name, &i); + return i; +} + +unsigned XMLElement::UnsignedAttribute(const char* name, unsigned defaultValue) const +{ + unsigned i = defaultValue; + QueryUnsignedAttribute(name, &i); + return i; +} + +int64_t XMLElement::Int64Attribute(const char* name, int64_t defaultValue) const +{ + int64_t i = defaultValue; + QueryInt64Attribute(name, &i); + return i; +} + +uint64_t XMLElement::Unsigned64Attribute(const char* name, uint64_t defaultValue) const +{ + uint64_t i = defaultValue; + QueryUnsigned64Attribute(name, &i); + return i; +} + +bool XMLElement::BoolAttribute(const char* name, bool defaultValue) const +{ + bool b = defaultValue; + QueryBoolAttribute(name, &b); + return b; +} + +double XMLElement::DoubleAttribute(const char* name, double defaultValue) const +{ + double d = defaultValue; + QueryDoubleAttribute(name, &d); + return d; +} + +float XMLElement::FloatAttribute(const char* name, float defaultValue) const +{ + float f = defaultValue; + QueryFloatAttribute(name, &f); + return f; +} const char* XMLElement::GetText() const { - if ( FirstChild() && FirstChild()->ToText() ) { - return FirstChild()->Value(); + /* skip comment node */ + const XMLNode* node = FirstChild(); + while (node) { + if (node->ToComment()) { + node = node->NextSibling(); + continue; + } + break; + } + + if ( node && node->ToText() ) { + return node->Value(); } return 0; } @@ -1434,7 +1723,7 @@ void XMLElement::SetText( const char* inText ) } -void XMLElement::SetText( int v ) +void XMLElement::SetText( int v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); @@ -1442,7 +1731,7 @@ void XMLElement::SetText( int v ) } -void XMLElement::SetText( unsigned v ) +void XMLElement::SetText( unsigned v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); @@ -1450,7 +1739,21 @@ void XMLElement::SetText( unsigned v ) } -void XMLElement::SetText( bool v ) +void XMLElement::SetText(int64_t v) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + SetText(buf); +} + +void XMLElement::SetText(uint64_t v) { + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + SetText(buf); +} + + +void XMLElement::SetText( bool v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); @@ -1458,7 +1761,7 @@ void XMLElement::SetText( bool v ) } -void XMLElement::SetText( float v ) +void XMLElement::SetText( float v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); @@ -1466,7 +1769,7 @@ void XMLElement::SetText( float v ) } -void XMLElement::SetText( double v ) +void XMLElement::SetText( double v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); @@ -1500,6 +1803,32 @@ XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const } +XMLError XMLElement::QueryInt64Text(int64_t* ival) const +{ + if (FirstChild() && FirstChild()->ToText()) { + const char* t = FirstChild()->Value(); + if (XMLUtil::ToInt64(t, ival)) { + return XML_SUCCESS; + } + return XML_CAN_NOT_CONVERT_TEXT; + } + return XML_NO_TEXT_NODE; +} + + +XMLError XMLElement::QueryUnsigned64Text(uint64_t* uval) const +{ + if(FirstChild() && FirstChild()->ToText()) { + const char* t = FirstChild()->Value(); + if(XMLUtil::ToUnsigned64(t, uval)) { + return XML_SUCCESS; + } + return XML_CAN_NOT_CONVERT_TEXT; + } + return XML_NO_TEXT_NODE; +} + + XMLError XMLElement::QueryBoolText( bool* bval ) const { if ( FirstChild() && FirstChild()->ToText() ) { @@ -1538,6 +1867,54 @@ XMLError XMLElement::QueryFloatText( float* fval ) const return XML_NO_TEXT_NODE; } +int XMLElement::IntText(int defaultValue) const +{ + int i = defaultValue; + QueryIntText(&i); + return i; +} + +unsigned XMLElement::UnsignedText(unsigned defaultValue) const +{ + unsigned i = defaultValue; + QueryUnsignedText(&i); + return i; +} + +int64_t XMLElement::Int64Text(int64_t defaultValue) const +{ + int64_t i = defaultValue; + QueryInt64Text(&i); + return i; +} + +uint64_t XMLElement::Unsigned64Text(uint64_t defaultValue) const +{ + uint64_t i = defaultValue; + QueryUnsigned64Text(&i); + return i; +} + +bool XMLElement::BoolText(bool defaultValue) const +{ + bool b = defaultValue; + QueryBoolText(&b); + return b; +} + +double XMLElement::DoubleText(double defaultValue) const +{ + double d = defaultValue; + QueryDoubleText(&d); + return d; +} + +float XMLElement::FloatText(float defaultValue) const +{ + float f = defaultValue; + QueryFloatText(&f); + return f; +} XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name ) @@ -1552,17 +1929,17 @@ XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name ) } } if ( !attrib ) { - TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() ); - attrib = new (_document->_attributePool.Alloc() ) XMLAttribute(); - attrib->_memPool = &_document->_attributePool; + attrib = CreateAttribute(); + TIXMLASSERT( attrib ); if ( last ) { + TIXMLASSERT( last->_next == 0 ); last->_next = attrib; } else { + TIXMLASSERT( _rootAttribute == 0 ); _rootAttribute = attrib; } attrib->SetName( name ); - attrib->_memPool->SetTracked(); // always created and linked. } return attrib; } @@ -1587,30 +1964,30 @@ void XMLElement::DeleteAttribute( const char* name ) } -char* XMLElement::ParseAttributes( char* p ) +char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) { - const char* start = p; XMLAttribute* prevAttribute = 0; // Read the attributes. while( p ) { - p = XMLUtil::SkipWhiteSpace( p ); + p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); if ( !(*p) ) { - _document->SetError( XML_ERROR_PARSING_ELEMENT, start, Name() ); + _document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, "XMLElement name=%s", Name() ); return 0; } // attribute. - if (XMLUtil::IsNameStartChar( *p ) ) { - TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() ); - XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute(); - attrib->_memPool = &_document->_attributePool; - attrib->_memPool->SetTracked(); + if (XMLUtil::IsNameStartChar( (unsigned char) *p ) ) { + XMLAttribute* attrib = CreateAttribute(); + TIXMLASSERT( attrib ); + attrib->_parseLineNum = _document->_parseCurLineNum; - p = attrib->ParseDeep( p, _document->ProcessEntities() ); + const int attrLineNum = attrib->_parseLineNum; + + p = attrib->ParseDeep( p, _document->ProcessEntities(), curLineNumPtr ); if ( !p || Attribute( attrib->Name() ) ) { DeleteAttribute( attrib ); - _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p ); + _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, attrLineNum, "XMLElement name=%s", Name() ); return 0; } // There is a minor bug here: if the attribute in the source xml @@ -1619,9 +1996,11 @@ char* XMLElement::ParseAttributes( char* p ) // avoids re-scanning the attribute list. Preferring performance for // now, may reconsider in the future. if ( prevAttribute ) { + TIXMLASSERT( prevAttribute->_next == 0 ); prevAttribute->_next = attrib; } else { + TIXMLASSERT( _rootAttribute == 0 ); _rootAttribute = attrib; } prevAttribute = attrib; @@ -1637,7 +2016,7 @@ char* XMLElement::ParseAttributes( char* p ) return p+2; // done; sealed element. } else { - _document->SetError( XML_ERROR_PARSING_ELEMENT, start, p ); + _document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, 0 ); return 0; } } @@ -1654,14 +2033,57 @@ void XMLElement::DeleteAttribute( XMLAttribute* attribute ) pool->Free( attribute ); } +XMLAttribute* XMLElement::CreateAttribute() +{ + TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() ); + XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute(); + TIXMLASSERT( attrib ); + attrib->_memPool = &_document->_attributePool; + attrib->_memPool->SetTracked(); + return attrib; +} + + +XMLElement* XMLElement::InsertNewChildElement(const char* name) +{ + XMLElement* node = _document->NewElement(name); + return InsertEndChild(node) ? node : 0; +} + +XMLComment* XMLElement::InsertNewComment(const char* comment) +{ + XMLComment* node = _document->NewComment(comment); + return InsertEndChild(node) ? node : 0; +} + +XMLText* XMLElement::InsertNewText(const char* text) +{ + XMLText* node = _document->NewText(text); + return InsertEndChild(node) ? node : 0; +} + +XMLDeclaration* XMLElement::InsertNewDeclaration(const char* text) +{ + XMLDeclaration* node = _document->NewDeclaration(text); + return InsertEndChild(node) ? node : 0; +} + +XMLUnknown* XMLElement::InsertNewUnknown(const char* text) +{ + XMLUnknown* node = _document->NewUnknown(text); + return InsertEndChild(node) ? node : 0; +} + + + // // // foobar // -char* XMLElement::ParseDeep( char* p, StrPair* strPair ) +char* XMLElement::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) { // Read the element name. - p = XMLUtil::SkipWhiteSpace( p ); + p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); // The closing element is the form. It is // parsed just like a regular element then deleted from @@ -1676,12 +2098,12 @@ char* XMLElement::ParseDeep( char* p, StrPair* strPair ) return 0; } - p = ParseAttributes( p ); - if ( !p || !*p || _closingType ) { + p = ParseAttributes( p, curLineNumPtr ); + if ( !p || !*p || _closingType != OPEN ) { return p; } - p = XMLNode::ParseDeep( p, strPair ); + p = XMLNode::ParseDeep( p, parentEndTag, curLineNumPtr ); return p; } @@ -1750,10 +2172,8 @@ const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = { "XML_ERROR_FILE_NOT_FOUND", "XML_ERROR_FILE_COULD_NOT_BE_OPENED", "XML_ERROR_FILE_READ_ERROR", - "XML_ERROR_ELEMENT_MISMATCH", "XML_ERROR_PARSING_ELEMENT", "XML_ERROR_PARSING_ATTRIBUTE", - "XML_ERROR_IDENTIFYING_TAG", "XML_ERROR_PARSING_TEXT", "XML_ERROR_PARSING_CDATA", "XML_ERROR_PARSING_COMMENT", @@ -1763,19 +2183,27 @@ const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = { "XML_ERROR_MISMATCHED_ELEMENT", "XML_ERROR_PARSING", "XML_CAN_NOT_CONVERT_TEXT", - "XML_NO_TEXT_NODE" + "XML_NO_TEXT_NODE", + "XML_ELEMENT_DEPTH_EXCEEDED" }; -XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) : +XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) : XMLNode( 0 ), _writeBOM( false ), _processEntities( processEntities ), - _errorID( XML_NO_ERROR ), - _whitespace( whitespace ), - _errorStr1( 0 ), - _errorStr2( 0 ), - _charBuffer( 0 ) + _errorID(XML_SUCCESS), + _whitespaceMode( whitespaceMode ), + _errorStr(), + _errorLineNum( 0 ), + _charBuffer( 0 ), + _parseCurLineNum( 0 ), + _parsingDepth(0), + _unlinked(), + _elementPool(), + _attributePool(), + _textPool(), + _commentPool() { // avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+) _document = this; @@ -1788,19 +2216,34 @@ XMLDocument::~XMLDocument() } +void XMLDocument::MarkInUse(const XMLNode* const node) +{ + TIXMLASSERT(node); + TIXMLASSERT(node->_parent == 0); + + for (int i = 0; i < _unlinked.Size(); ++i) { + if (node == _unlinked[i]) { + _unlinked.SwapRemove(i); + break; + } + } +} + void XMLDocument::Clear() { DeleteChildren(); + while( _unlinked.Size()) { + DeleteNode(_unlinked[0]); // Will remove from _unlinked as part of delete. + } -#ifdef DEBUG +#ifdef TINYXML2_DEBUG const bool hadError = Error(); #endif - _errorID = XML_NO_ERROR; - _errorStr1 = 0; - _errorStr2 = 0; + ClearError(); delete [] _charBuffer; _charBuffer = 0; + _parsingDepth = 0; #if 0 _textPool.Trace( "text" ); @@ -1808,8 +2251,8 @@ void XMLDocument::Clear() _commentPool.Trace( "comment" ); _attributePool.Trace( "attribute" ); #endif - -#ifdef DEBUG + +#ifdef TINYXML2_DEBUG if ( !hadError ) { TIXMLASSERT( _elementPool.CurrentAllocs() == _elementPool.Untracked() ); TIXMLASSERT( _attributePool.CurrentAllocs() == _attributePool.Untracked() ); @@ -1820,11 +2263,22 @@ void XMLDocument::Clear() } +void XMLDocument::DeepCopy(XMLDocument* target) const +{ + TIXMLASSERT(target); + if (target == this) { + return; // technically success - a no-op. + } + + target->Clear(); + for (const XMLNode* node = this->FirstChild(); node; node = node->NextSibling()) { + target->InsertEndChild(node->DeepClone(target)); + } +} + XMLElement* XMLDocument::NewElement( const char* name ) { - TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() ); - XMLElement* ele = new (_elementPool.Alloc()) XMLElement( this ); - ele->_memPool = &_elementPool; + XMLElement* ele = CreateUnlinkedNode( _elementPool ); ele->SetName( name ); return ele; } @@ -1832,9 +2286,7 @@ XMLElement* XMLDocument::NewElement( const char* name ) XMLComment* XMLDocument::NewComment( const char* str ) { - TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() ); - XMLComment* comment = new (_commentPool.Alloc()) XMLComment( this ); - comment->_memPool = &_commentPool; + XMLComment* comment = CreateUnlinkedNode( _commentPool ); comment->SetValue( str ); return comment; } @@ -1842,9 +2294,7 @@ XMLComment* XMLDocument::NewComment( const char* str ) XMLText* XMLDocument::NewText( const char* str ) { - TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() ); - XMLText* text = new (_textPool.Alloc()) XMLText( this ); - text->_memPool = &_textPool; + XMLText* text = CreateUnlinkedNode( _textPool ); text->SetValue( str ); return text; } @@ -1852,9 +2302,7 @@ XMLText* XMLDocument::NewText( const char* str ) XMLDeclaration* XMLDocument::NewDeclaration( const char* str ) { - TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() ); - XMLDeclaration* dec = new (_commentPool.Alloc()) XMLDeclaration( this ); - dec->_memPool = &_commentPool; + XMLDeclaration* dec = CreateUnlinkedNode( _commentPool ); dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" ); return dec; } @@ -1862,9 +2310,7 @@ XMLDeclaration* XMLDocument::NewDeclaration( const char* str ) XMLUnknown* XMLDocument::NewUnknown( const char* str ) { - TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() ); - XMLUnknown* unk = new (_commentPool.Alloc()) XMLUnknown( this ); - unk->_memPool = &_commentPool; + XMLUnknown* unk = CreateUnlinkedNode( _commentPool ); unk->SetValue( str ); return unk; } @@ -1875,7 +2321,7 @@ static FILE* callfopen( const char* filepath, const char* mode ) TIXMLASSERT( mode ); #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE) FILE* fp = 0; - errno_t err = fopen_s( &fp, filepath, mode ); + const errno_t err = fopen_s( &fp, filepath, mode ); if ( err ) { return 0; } @@ -1884,7 +2330,7 @@ static FILE* callfopen( const char* filepath, const char* mode ) #endif return fp; } - + void XMLDocument::DeleteNode( XMLNode* node ) { TIXMLASSERT( node ); TIXMLASSERT(node->_document == this ); @@ -1905,10 +2351,16 @@ void XMLDocument::DeleteNode( XMLNode* node ) { XMLError XMLDocument::LoadFile( const char* filename ) { + if ( !filename ) { + TIXMLASSERT( false ); + SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=" ); + return _errorID; + } + Clear(); FILE* fp = callfopen( filename, "rb" ); if ( !fp ) { - SetError( XML_ERROR_FILE_NOT_FOUND, filename, 0 ); + SetError( XML_ERROR_FILE_NOT_FOUND, 0, "filename=%s", filename ); return _errorID; } LoadFile( fp ); @@ -1916,47 +2368,34 @@ XMLError XMLDocument::LoadFile( const char* filename ) return _errorID; } -// This is likely overengineered template art to have a check that unsigned long value incremented -// by one still fits into size_t. If size_t type is larger than unsigned long type -// (x86_64-w64-mingw32 target) then the check is redundant and gcc and clang emit -// -Wtype-limits warning. This piece makes the compiler select code with a check when a check -// is useful and code with no check when a check is redundant depending on how size_t and unsigned long -// types sizes relate to each other. -template -= sizeof(size_t))> -struct LongFitsIntoSizeTMinusOne { - static bool Fits( unsigned long value ) - { - return value < (size_t)-1; - } -}; - -template <> -bool LongFitsIntoSizeTMinusOne::Fits( unsigned long /*value*/ ) -{ - return true; -} - XMLError XMLDocument::LoadFile( FILE* fp ) { Clear(); - fseek( fp, 0, SEEK_SET ); + TIXML_FSEEK( fp, 0, SEEK_SET ); if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) { SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; } - fseek( fp, 0, SEEK_END ); - const long filelength = ftell( fp ); - fseek( fp, 0, SEEK_SET ); - if ( filelength == -1L ) { - SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); - return _errorID; + TIXML_FSEEK( fp, 0, SEEK_END ); + + unsigned long long filelength; + { + const long long fileLengthSigned = TIXML_FTELL( fp ); + TIXML_FSEEK( fp, 0, SEEK_SET ); + if ( fileLengthSigned == -1L ) { + SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); + return _errorID; + } + TIXMLASSERT( fileLengthSigned >= 0 ); + filelength = static_cast(fileLengthSigned); } - TIXMLASSERT( filelength >= 0 ); - if ( !LongFitsIntoSizeTMinusOne<>::Fits( filelength ) ) { + const size_t maxSizeT = static_cast(-1); + // We'll do the comparison as an unsigned long long, because that's guaranteed to be at + // least 8 bytes, even on a 32-bit platform. + if ( filelength >= static_cast(maxSizeT) ) { // Cannot handle files which won't fit in buffer together with null terminator SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; @@ -1967,10 +2406,10 @@ XMLError XMLDocument::LoadFile( FILE* fp ) return _errorID; } - const size_t size = filelength; + const size_t size = static_cast(filelength); TIXMLASSERT( _charBuffer == 0 ); _charBuffer = new char[size+1]; - size_t read = fread( _charBuffer, 1, size, fp ); + const size_t read = fread( _charBuffer, 1, size, fp ); if ( read != size ) { SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; @@ -1985,9 +2424,15 @@ XMLError XMLDocument::LoadFile( FILE* fp ) XMLError XMLDocument::SaveFile( const char* filename, bool compact ) { + if ( !filename ) { + TIXMLASSERT( false ); + SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=" ); + return _errorID; + } + FILE* fp = callfopen( filename, "w" ); if ( !fp ) { - SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, filename, 0 ); + SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=%s", filename ); return _errorID; } SaveFile(fp, compact); @@ -2000,28 +2445,28 @@ XMLError XMLDocument::SaveFile( FILE* fp, bool compact ) { // Clear any error from the last save, otherwise it will get reported // for *this* call. - SetError( XML_NO_ERROR, 0, 0 ); + ClearError(); XMLPrinter stream( fp, compact ); Print( &stream ); return _errorID; } -XMLError XMLDocument::Parse( const char* p, size_t len ) +XMLError XMLDocument::Parse( const char* xml, size_t nBytes ) { Clear(); - if ( len == 0 || !p || !*p ) { + if ( nBytes == 0 || !xml || !*xml ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return _errorID; } - if ( len == (size_t)(-1) ) { - len = strlen( p ); + if ( nBytes == static_cast(-1) ) { + nBytes = strlen( xml ); } TIXMLASSERT( _charBuffer == 0 ); - _charBuffer = new char[ len+1 ]; - memcpy( _charBuffer, p, len ); - _charBuffer[len] = 0; + _charBuffer = new char[ nBytes+1 ]; + memcpy( _charBuffer, xml, nBytes ); + _charBuffer[nBytes] = 0; Parse(); if ( Error() ) { @@ -2050,66 +2495,106 @@ void XMLDocument::Print( XMLPrinter* streamer ) const } -void XMLDocument::SetError( XMLError error, const char* str1, const char* str2 ) +void XMLDocument::ClearError() { + _errorID = XML_SUCCESS; + _errorLineNum = 0; + _errorStr.Reset(); +} + + +void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... ) { - TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT ); + TIXMLASSERT(error >= 0 && error < XML_ERROR_COUNT); _errorID = error; - _errorStr1 = str1; - _errorStr2 = str2; + _errorLineNum = lineNum; + _errorStr.Reset(); + + const size_t BUFFER_SIZE = 1000; + char* buffer = new char[BUFFER_SIZE]; + + TIXMLASSERT(sizeof(error) <= sizeof(int)); + TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d", + ErrorIDToName(error), static_cast(error), static_cast(error), lineNum); + + if (format) { + size_t len = strlen(buffer); + TIXML_SNPRINTF(buffer + len, BUFFER_SIZE - len, ": "); + len = strlen(buffer); + + va_list va; + va_start(va, format); + TIXML_VSNPRINTF(buffer + len, BUFFER_SIZE - len, format, va); + va_end(va); + } + _errorStr.SetStr(buffer); + delete[] buffer; } -const char* XMLDocument::ErrorName() const + +/*static*/ const char* XMLDocument::ErrorIDToName(XMLError errorID) { - TIXMLASSERT( _errorID >= 0 && _errorID < XML_ERROR_COUNT ); - const char* errorName = _errorNames[_errorID]; + TIXMLASSERT( errorID >= 0 && errorID < XML_ERROR_COUNT ); + const char* errorName = _errorNames[errorID]; TIXMLASSERT( errorName && errorName[0] ); return errorName; } -void XMLDocument::PrintError() const +const char* XMLDocument::ErrorStr() const { - if ( Error() ) { - static const int LEN = 20; - char buf1[LEN] = { 0 }; - char buf2[LEN] = { 0 }; + return _errorStr.Empty() ? "" : _errorStr.GetStr(); +} - if ( _errorStr1 ) { - TIXML_SNPRINTF( buf1, LEN, "%s", _errorStr1 ); - } - if ( _errorStr2 ) { - TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2 ); - } - // Should check INT_MIN <= _errorID && _errorId <= INT_MAX, but that - // causes a clang "always true" -Wtautological-constant-out-of-range-compare warning - TIXMLASSERT( 0 <= _errorID && XML_ERROR_COUNT - 1 <= INT_MAX ); - printf( "XMLDocument error id=%d '%s' str1=%s str2=%s\n", - static_cast( _errorID ), ErrorName(), buf1, buf2 ); - } +void XMLDocument::PrintError() const +{ + printf("%s\n", ErrorStr()); +} + +const char* XMLDocument::ErrorName() const +{ + return ErrorIDToName(_errorID); } void XMLDocument::Parse() { TIXMLASSERT( NoChildren() ); // Clear() must have been called previously TIXMLASSERT( _charBuffer ); + _parseCurLineNum = 1; + _parseLineNum = 1; char* p = _charBuffer; - p = XMLUtil::SkipWhiteSpace( p ); + p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum ); p = const_cast( XMLUtil::ReadBOM( p, &_writeBOM ) ); if ( !*p ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return; } - ParseDeep(p, 0 ); + ParseDeep(p, 0, &_parseCurLineNum ); +} + +void XMLDocument::PushDepth() +{ + _parsingDepth++; + if (_parsingDepth == TINYXML2_MAX_ELEMENT_DEPTH) { + SetError(XML_ELEMENT_DEPTH_EXCEEDED, _parseCurLineNum, "Element nesting is too deep." ); + } +} + +void XMLDocument::PopDepth() +{ + TIXMLASSERT(_parsingDepth > 0); + --_parsingDepth; } XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) : _elementJustOpened( false ), + _stack(), _firstElement( true ), _fp( file ), _depth( depth ), _textDepth( -1 ), _processEntities( true ), - _compactMode( compact ) + _compactMode( compact ), + _buffer() { for( int i=0; i(entityValue); + TIXMLASSERT( flagIndex < ENTITY_RANGE ); + _entityFlag[flagIndex] = true; } - _restrictedEntityFlag[(unsigned char)'&'] = true; - _restrictedEntityFlag[(unsigned char)'<'] = true; - _restrictedEntityFlag[(unsigned char)'>'] = true; // not required, but consistency is nice + _restrictedEntityFlag[static_cast('&')] = true; + _restrictedEntityFlag[static_cast('<')] = true; + _restrictedEntityFlag[static_cast('>')] = true; // not required, but consistency is nice _buffer.Push( 0 ); } @@ -2149,10 +2635,36 @@ void XMLPrinter::Print( const char* format, ... ) } +void XMLPrinter::Write( const char* data, size_t size ) +{ + if ( _fp ) { + fwrite ( data , sizeof(char), size, _fp); + } + else { + char* p = _buffer.PushArr( static_cast(size) ) - 1; // back up over the null terminator. + memcpy( p, data, size ); + p[size] = 0; + } +} + + +void XMLPrinter::Putc( char ch ) +{ + if ( _fp ) { + fputc ( ch, _fp); + } + else { + char* p = _buffer.PushArr( sizeof(char) ) - 1; // back up over the null terminator. + p[0] = ch; + p[1] = 0; + } +} + + void XMLPrinter::PrintSpace( int depth ) { for( int i=0; i(*q)] ) { while ( p < q ) { const size_t delta = q - p; - // %.*s accepts type int as "precision" - const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta; - Print( "%.*s", toPrint, p ); + const int toPrint = ( INT_MAX < delta ) ? INT_MAX : static_cast(delta); + Write( p, toPrint ); p += toPrint; } bool entityPatternPrinted = false; for( int i=0; i(delta); + Write( p, toPrint ); + } } - // Flush the remaining string. This will be the entire - // string if an entity wasn't found. - TIXMLASSERT( p <= q ); - if ( !_processEntities || ( p < q ) ) { - Print( "%s", p ); + else { + Write( p ); } } @@ -2211,29 +2728,40 @@ void XMLPrinter::PushHeader( bool writeBOM, bool writeDec ) { if ( writeBOM ) { static const unsigned char bom[] = { TIXML_UTF_LEAD_0, TIXML_UTF_LEAD_1, TIXML_UTF_LEAD_2, 0 }; - Print( "%s", bom ); + Write( reinterpret_cast< const char* >( bom ) ); } if ( writeDec ) { PushDeclaration( "xml version=\"1.0\"" ); } } - -void XMLPrinter::OpenElement( const char* name, bool compactMode ) +void XMLPrinter::PrepareForNewNode( bool compactMode ) { SealElementIfJustOpened(); - _stack.Push( name ); - if ( _textDepth < 0 && !_firstElement && !compactMode ) { - Print( "\n" ); + if ( compactMode ) { + return; } - if ( !compactMode ) { + + if ( _firstElement ) { + PrintSpace (_depth); + } else if ( _textDepth < 0) { + Putc( '\n' ); PrintSpace( _depth ); } - Print( "<%s", name ); - _elementJustOpened = true; _firstElement = false; +} + +void XMLPrinter::OpenElement( const char* name, bool compactMode ) +{ + PrepareForNewNode( compactMode ); + _stack.Push( name ); + + Write ( "<" ); + Write ( name ); + + _elementJustOpened = true; ++_depth; } @@ -2241,9 +2769,11 @@ void XMLPrinter::OpenElement( const char* name, bool compactMode ) void XMLPrinter::PushAttribute( const char* name, const char* value ) { TIXMLASSERT( _elementJustOpened ); - Print( " %s=\"", name ); + Putc ( ' ' ); + Write( name ); + Write( "=\"" ); PrintString( value, false ); - Print( "\"" ); + Putc ( '\"' ); } @@ -2263,6 +2793,22 @@ void XMLPrinter::PushAttribute( const char* name, unsigned v ) } +void XMLPrinter::PushAttribute(const char* name, int64_t v) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + PushAttribute(name, buf); +} + + +void XMLPrinter::PushAttribute(const char* name, uint64_t v) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(v, buf, BUF_SIZE); + PushAttribute(name, buf); +} + + void XMLPrinter::PushAttribute( const char* name, bool v ) { char buf[BUF_SIZE]; @@ -2285,21 +2831,23 @@ void XMLPrinter::CloseElement( bool compactMode ) const char* name = _stack.Pop(); if ( _elementJustOpened ) { - Print( "/>" ); + Write( "/>" ); } else { if ( _textDepth < 0 && !compactMode) { - Print( "\n" ); + Putc( '\n' ); PrintSpace( _depth ); } - Print( "", name ); + Write ( "" ); } if ( _textDepth == _depth ) { _textDepth = -1; } if ( _depth == 0 && !compactMode) { - Print( "\n" ); + Putc( '\n' ); } _elementJustOpened = false; } @@ -2311,7 +2859,7 @@ void XMLPrinter::SealElementIfJustOpened() return; } _elementJustOpened = false; - Print( ">" ); + Putc( '>' ); } @@ -2321,13 +2869,32 @@ void XMLPrinter::PushText( const char* text, bool cdata ) SealElementIfJustOpened(); if ( cdata ) { - Print( "", text ); + Write( "" ); } else { PrintString( text, true ); } } + +void XMLPrinter::PushText( int64_t value ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr( value, buf, BUF_SIZE ); + PushText( buf, false ); +} + + +void XMLPrinter::PushText( uint64_t value ) +{ + char buf[BUF_SIZE]; + XMLUtil::ToStr(value, buf, BUF_SIZE); + PushText(buf, false); +} + + void XMLPrinter::PushText( int value ) { char buf[BUF_SIZE]; @@ -2370,37 +2937,31 @@ void XMLPrinter::PushText( double value ) void XMLPrinter::PushComment( const char* comment ) { - SealElementIfJustOpened(); - if ( _textDepth < 0 && !_firstElement && !_compactMode) { - Print( "\n" ); - PrintSpace( _depth ); - } - _firstElement = false; - Print( "", comment ); + PrepareForNewNode( _compactMode ); + + Write( "" ); } void XMLPrinter::PushDeclaration( const char* value ) { - SealElementIfJustOpened(); - if ( _textDepth < 0 && !_firstElement && !_compactMode) { - Print( "\n" ); - PrintSpace( _depth ); - } - _firstElement = false; - Print( "", value ); + PrepareForNewNode( _compactMode ); + + Write( "" ); } void XMLPrinter::PushUnknown( const char* value ) { - SealElementIfJustOpened(); - if ( _textDepth < 0 && !_firstElement && !_compactMode) { - Print( "\n" ); - PrintSpace( _depth ); - } - _firstElement = false; - Print( "", value ); + PrepareForNewNode( _compactMode ); + + Write( "' ); } @@ -2464,4 +3025,3 @@ bool XMLPrinter::Visit( const XMLUnknown& unknown ) } } // namespace tinyxml2 - diff --git a/extend/luaxlsx/src/tinyxml2.h b/extend/luaxml/src/tinyxml2.h similarity index 71% rename from extend/luaxlsx/src/tinyxml2.h rename to extend/luaxml/src/tinyxml2.h index 06eee304..8b918511 100644 --- a/extend/luaxlsx/src/tinyxml2.h +++ b/extend/luaxml/src/tinyxml2.h @@ -30,6 +30,9 @@ distribution. # include # include # include +# if defined(__PS3__) +# include +# endif #else # include # include @@ -37,21 +40,19 @@ distribution. # include # include #endif +#include -/* - TODO: intern strings instead of allocation. -*/ /* gcc: - g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe + g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe Formatting, Artistic Style: AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h */ -#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__) -# ifndef DEBUG -# define DEBUG +#if defined( _DEBUG ) || defined (__DEBUG__) +# ifndef TINYXML2_DEBUG +# define TINYXML2_DEBUG # endif #endif @@ -60,7 +61,7 @@ distribution. # pragma warning(disable: 4251) #endif -#ifdef _WIN32 +#ifdef _MSC_VER # ifdef TINYXML2_EXPORT # define TINYXML2_LIB __declspec(dllexport) # elif defined(TINYXML2_IMPORT) @@ -68,34 +69,48 @@ distribution. # else # define TINYXML2_LIB # endif +#elif __GNUC__ >= 4 +# define TINYXML2_LIB __attribute__((visibility("default"))) #else # define TINYXML2_LIB #endif -#if defined(DEBUG) +#if !defined(TIXMLASSERT) +#if defined(TINYXML2_DEBUG) # if defined(_MSC_VER) # // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like -# define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); } +# define TIXMLASSERT( x ) do { if ( !((void)0,(x))) { __debugbreak(); } } while(false) # elif defined (ANDROID_NDK) # include -# define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } +# define TIXMLASSERT( x ) do { if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } } while(false) # else # include # define TIXMLASSERT assert # endif #else -# define TIXMLASSERT( x ) {} +# define TIXMLASSERT( x ) do {} while(false) +#endif #endif - /* Versioning, past 1.0.14: http://semver.org/ */ -static const int TIXML2_MAJOR_VERSION = 3; +static const int TIXML2_MAJOR_VERSION = 10; static const int TIXML2_MINOR_VERSION = 0; static const int TIXML2_PATCH_VERSION = 0; +#define TINYXML2_MAJOR_VERSION 10 +#define TINYXML2_MINOR_VERSION 0 +#define TINYXML2_PATCH_VERSION 0 + +// A fixed element depth limit is problematic. There needs to be a +// limit to avoid a stack overflow. However, that limit varies per +// system, and the capacity of the stack. On the other hand, it's a trivial +// attack that can result from ill, malicious, or even correctly formed XML, +// so there needs to be a limit in place. +static const int TINYXML2_MAX_ELEMENT_DEPTH = 500; + namespace tinyxml2 { class XMLDocument; @@ -112,27 +127,31 @@ class XMLPrinter; pointers into the XML file itself, and will apply normalization and entity translation if actually read. Can also store (and memory manage) a traditional char[] + + Isn't clear why TINYXML2_LIB is needed; but seems to fix #719 */ -class StrPair +class TINYXML2_LIB StrPair { public: - enum { + enum Mode { NEEDS_ENTITY_PROCESSING = 0x01, NEEDS_NEWLINE_NORMALIZATION = 0x02, NEEDS_WHITESPACE_COLLAPSING = 0x04, - TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, + TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, - ATTRIBUTE_NAME = 0, - ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, - ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, - COMMENT = NEEDS_NEWLINE_NORMALIZATION + ATTRIBUTE_NAME = 0, + ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, + ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, + COMMENT = NEEDS_NEWLINE_NORMALIZATION }; StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {} ~StrPair(); void Set( char* start, char* end, int flags ) { + TIXMLASSERT( start ); + TIXMLASSERT( end ); Reset(); _start = start; _end = end; @@ -152,13 +171,13 @@ class StrPair void SetStr( const char* str, int flags=0 ); - char* ParseText( char* in, const char* endTag, int strFlags ); + char* ParseText( char* in, const char* endTag, int strFlags, int* curLineNumPtr ); char* ParseName( char* in ); void TransferTo( StrPair* other ); + void Reset(); private: - void Reset(); void CollapseWhitespace(); enum { @@ -171,7 +190,7 @@ class StrPair char* _end; StrPair( const StrPair& other ); // not supported - void operator=( StrPair& other ); // not supported, use TransferTo() + void operator=( const StrPair& other ); // not supported, use TransferTo() }; @@ -184,10 +203,11 @@ template class DynArray { public: - DynArray() { - _mem = _pool; - _allocated = INITIAL_SIZE; - _size = 0; + DynArray() : + _mem( _pool ), + _allocated( INITIAL_SIZE ), + _size( 0 ) + { } ~DynArray() { @@ -203,7 +223,8 @@ class DynArray void Push( T t ) { TIXMLASSERT( _size < INT_MAX ); EnsureCapacity( _size+1 ); - _mem[_size++] = t; + _mem[_size] = t; + ++_size; } T* PushArr( int count ) { @@ -217,7 +238,8 @@ class DynArray T Pop() { TIXMLASSERT( _size > 0 ); - return _mem[--_size]; + --_size; + return _mem[_size]; } void PopArr( int count ) { @@ -254,12 +276,19 @@ class DynArray return _allocated; } + void SwapRemove(int i) { + TIXMLASSERT(i >= 0 && i < _size); + TIXMLASSERT(_size > 0); + _mem[i] = _mem[_size - 1]; + --_size; + } + const T* Mem() const { TIXMLASSERT( _mem ); return _mem; } - T* Mem() { + T* Mem() { TIXMLASSERT( _mem ); return _mem; } @@ -272,9 +301,10 @@ class DynArray TIXMLASSERT( cap > 0 ); if ( cap > _allocated ) { TIXMLASSERT( cap <= INT_MAX / 2 ); - int newAllocated = cap * 2; - T* newMem = new T[newAllocated]; - memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs + const int newAllocated = cap * 2; + T* newMem = new T[static_cast(newAllocated)]; + TIXMLASSERT( newAllocated >= _size ); + memcpy( newMem, _mem, sizeof(T)*static_cast(_size) ); // warning: not using constructors, only works for PODs if ( _mem != _pool ) { delete [] _mem; } @@ -284,7 +314,7 @@ class DynArray } T* _mem; - T _pool[INITIAL_SIZE]; + T _pool[static_cast(INITIAL_SIZE)]; int _allocated; // objects allocated int _size; // number objects in use }; @@ -304,27 +334,26 @@ class MemPool virtual void* Alloc() = 0; virtual void Free( void* ) = 0; virtual void SetTracked() = 0; - virtual void Clear() = 0; }; /* Template child class to create pools of the correct type. */ -template< int SIZE > +template< int ITEM_SIZE > class MemPoolT : public MemPool { public: - MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} + MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} ~MemPoolT() { - Clear(); + MemPoolT< ITEM_SIZE >::Clear(); } - + void Clear() { // Delete the blocks. while( !_blockPtrs.Empty()) { - Block* b = _blockPtrs.Pop(); - delete b; + Block* lastBlock = _blockPtrs.Pop(); + delete lastBlock; } _root = 0; _currentAllocs = 0; @@ -333,56 +362,59 @@ class MemPoolT : public MemPool _nUntracked = 0; } - virtual int ItemSize() const { - return SIZE; + virtual int ItemSize() const override{ + return ITEM_SIZE; } int CurrentAllocs() const { return _currentAllocs; } - virtual void* Alloc() { + virtual void* Alloc() override{ if ( !_root ) { // Need a new block. - Block* block = new Block(); + Block* block = new Block; _blockPtrs.Push( block ); - for( int i=0; ichunk[i].next = &block->chunk[i+1]; + Item* blockItems = block->items; + for( int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) { + blockItems[i].next = &(blockItems[i + 1]); } - block->chunk[COUNT-1].next = 0; - _root = block->chunk; + blockItems[ITEMS_PER_BLOCK - 1].next = 0; + _root = blockItems; } - void* result = _root; + Item* const result = _root; + TIXMLASSERT( result != 0 ); _root = _root->next; ++_currentAllocs; if ( _currentAllocs > _maxAllocs ) { _maxAllocs = _currentAllocs; } - _nAllocs++; - _nUntracked++; + ++_nAllocs; + ++_nUntracked; return result; } - - virtual void Free( void* mem ) { + + virtual void Free( void* mem ) override { if ( !mem ) { return; } --_currentAllocs; - Chunk* chunk = static_cast( mem ); -#ifdef DEBUG - memset( chunk, 0xfe, sizeof(Chunk) ); + Item* item = static_cast( mem ); +#ifdef TINYXML2_DEBUG + memset( item, 0xfe, sizeof( *item ) ); #endif - chunk->next = _root; - _root = chunk; + item->next = _root; + _root = item; } void Trace( const char* name ) { printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n", - name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size() ); + name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs, + ITEM_SIZE, _nAllocs, _blockPtrs.Size() ); } - void SetTracked() { - _nUntracked--; + void SetTracked() override { + --_nUntracked; } int Untracked() const { @@ -398,21 +430,23 @@ class MemPoolT : public MemPool // 16k: 5200 // 32k: 4300 // 64k: 4000 21000 - enum { COUNT = (4*1024)/SIZE }; // Some compilers do not accept to use COUNT in private part if COUNT is private + // Declared public because some compilers do not accept to use ITEMS_PER_BLOCK + // in private part if ITEMS_PER_BLOCK is private + enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE }; private: MemPoolT( const MemPoolT& ); // not supported void operator=( const MemPoolT& ); // not supported - union Chunk { - Chunk* next; - char mem[SIZE]; + union Item { + Item* next; + char itemData[static_cast(ITEM_SIZE)]; }; struct Block { - Chunk chunk[COUNT]; + Item items[ITEMS_PER_BLOCK]; }; DynArray< Block*, 10 > _blockPtrs; - Chunk* _root; + Item* _root; int _currentAllocs; int _nAllocs; @@ -485,16 +519,13 @@ class TINYXML2_LIB XMLVisitor // WARNING: must match XMLDocument::_errorNames[] enum XMLError { XML_SUCCESS = 0, - XML_NO_ERROR = 0, XML_NO_ATTRIBUTE, XML_WRONG_ATTRIBUTE_TYPE, XML_ERROR_FILE_NOT_FOUND, XML_ERROR_FILE_COULD_NOT_BE_OPENED, XML_ERROR_FILE_READ_ERROR, - XML_ERROR_ELEMENT_MISMATCH, XML_ERROR_PARSING_ELEMENT, XML_ERROR_PARSING_ATTRIBUTE, - XML_ERROR_IDENTIFYING_TAG, XML_ERROR_PARSING_TEXT, XML_ERROR_PARSING_CDATA, XML_ERROR_PARSING_COMMENT, @@ -505,6 +536,7 @@ enum XMLError { XML_ERROR_PARSING, XML_CAN_NOT_CONVERT_TEXT, XML_NO_TEXT_NODE, + XML_ELEMENT_DEPTH_EXCEEDED, XML_ERROR_COUNT }; @@ -513,19 +545,23 @@ enum XMLError { /* Utility functionality. */ -class XMLUtil +class TINYXML2_LIB XMLUtil { public: - static const char* SkipWhiteSpace( const char* p ) { + static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) { TIXMLASSERT( p ); + while( IsWhiteSpace(*p) ) { + if (curLineNumPtr && *p == '\n') { + ++(*curLineNumPtr); + } ++p; } TIXMLASSERT( p ); return p; } - static char* SkipWhiteSpace( char* p ) { - return const_cast( SkipWhiteSpace( const_cast(p) ) ); + static char* SkipWhiteSpace( char* const p, int* curLineNumPtr ) { + return const_cast( SkipWhiteSpace( const_cast(p), curLineNumPtr ) ); } // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't @@ -533,7 +569,7 @@ class XMLUtil static bool IsWhiteSpace( char p ) { return !IsUTF8Continuation(p) && isspace( static_cast(p) ); } - + inline static bool IsNameStartChar( unsigned char ch ) { if ( ch >= 128 ) { // This is a heuristic guess in attempt to not implement Unicode-aware isalpha() @@ -544,7 +580,7 @@ class XMLUtil } return ch == ':' || ch == '_'; } - + inline static bool IsNameChar( unsigned char ch ) { return IsNameStartChar( ch ) || isdigit( ch ) @@ -552,14 +588,22 @@ class XMLUtil || ch == '-'; } + inline static bool IsPrefixHex( const char* p) { + p = SkipWhiteSpace(p, 0); + return p && *p == '0' && ( *(p + 1) == 'x' || *(p + 1) == 'X'); + } + inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) { if ( p == q ) { return true; } - return strncmp( p, q, nChar ) == 0; + TIXMLASSERT( p ); + TIXMLASSERT( q ); + TIXMLASSERT( nChar >= 0 ); + return strncmp( p, q, static_cast(nChar) ) == 0; } - - inline static bool IsUTF8Continuation( char p ) { + + inline static bool IsUTF8Continuation( const char p ) { return ( p & 0x80 ) != 0; } @@ -575,6 +619,8 @@ class XMLUtil static void ToStr( bool v, char* buffer, int bufferSize ); static void ToStr( float v, char* buffer, int bufferSize ); static void ToStr( double v, char* buffer, int bufferSize ); + static void ToStr(int64_t v, char* buffer, int bufferSize); + static void ToStr(uint64_t v, char* buffer, int bufferSize); // converts strings to primitive types static bool ToInt( const char* str, int* value ); @@ -582,6 +628,18 @@ class XMLUtil static bool ToBool( const char* str, bool* value ); static bool ToFloat( const char* str, float* value ); static bool ToDouble( const char* str, double* value ); + static bool ToInt64(const char* str, int64_t* value); + static bool ToUnsigned64(const char* str, uint64_t* value); + // Changes what is serialized for a boolean value. + // Default to "true" and "false". Shouldn't be changed + // unless you have a special testing or compatibility need. + // Be careful: static, global, & not thread safe. + // Be sure to set static const memory as parameters. + static void SetBoolSerialization(const char* writeTrue, const char* writeFalse); + +private: + static const char* writeBoolTrue; + static const char* writeBoolFalse; }; @@ -671,6 +729,12 @@ class TINYXML2_LIB XMLNode return 0; } + // ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2. + + int ChildElementCount(const char *value) const; + + int ChildElementCount() const; + /** The meaning of 'value' changes for the specific type. @verbatim Document: empty (NULL is returned, not an empty string) @@ -687,6 +751,9 @@ class TINYXML2_LIB XMLNode */ void SetValue( const char* val, bool staticMem=false ); + /// Gets the line number the node is in, if the document was parsed from a file. + int GetLineNum() const { return _parseLineNum; } + /// Get the parent of this node on the DOM. const XMLNode* Parent() const { return _parent; @@ -820,6 +887,21 @@ class TINYXML2_LIB XMLNode */ virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0; + /** + Make a copy of this node and all its children. + + If the 'target' is null, then the nodes will + be allocated in the current document. If 'target' + is specified, the memory will be allocated is the + specified XMLDocument. + + NOTE: This is probably not the correct tool to + copy a document, since XMLDocuments can have multiple + top level XMLNodes. You probably want to use + XMLDocument::DeepCopy() + */ + XMLNode* DeepClone( XMLDocument* target ) const; + /** Test if 2 nodes are the same, but don't test children. The 2 nodes do not need to be in the same Document. @@ -852,15 +934,30 @@ class TINYXML2_LIB XMLNode */ virtual bool Accept( XMLVisitor* visitor ) const = 0; + /** + Set user data into the XMLNode. TinyXML-2 in + no way processes or interprets user data. + It is initially 0. + */ + void SetUserData(void* userData) { _userData = userData; } + + /** + Get user data set into the XMLNode. TinyXML-2 in + no way processes or interprets user data. + It is initially 0. + */ + void* GetUserData() const { return _userData; } + protected: - XMLNode( XMLDocument* ); + explicit XMLNode( XMLDocument* ); virtual ~XMLNode(); - virtual char* ParseDeep( char*, StrPair* ); + virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr); XMLDocument* _document; XMLNode* _parent; mutable StrPair _value; + int _parseLineNum; XMLNode* _firstChild; XMLNode* _lastChild; @@ -868,11 +965,14 @@ class TINYXML2_LIB XMLNode XMLNode* _prev; XMLNode* _next; + void* _userData; + private: MemPool* _memPool; void Unlink( XMLNode* child ); static void DeleteNode( XMLNode* node ); void InsertChildPreamble( XMLNode* insertThis ) const; + const XMLElement* ToElementWithName( const char* name ) const; XMLNode( const XMLNode& ); // not supported XMLNode& operator=( const XMLNode& ); // not supported @@ -893,15 +993,14 @@ class TINYXML2_LIB XMLNode */ class TINYXML2_LIB XMLText : public XMLNode { - friend class XMLBase; friend class XMLDocument; public: - virtual bool Accept( XMLVisitor* visitor ) const; + virtual bool Accept( XMLVisitor* visitor ) const override; - virtual XMLText* ToText() { + virtual XMLText* ToText() override { return this; } - virtual const XMLText* ToText() const { + virtual const XMLText* ToText() const override { return this; } @@ -914,14 +1013,14 @@ class TINYXML2_LIB XMLText : public XMLNode return _isCData; } - virtual XMLNode* ShallowClone( XMLDocument* document ) const; - virtual bool ShallowEqual( const XMLNode* compare ) const; + virtual XMLNode* ShallowClone( XMLDocument* document ) const override; + virtual bool ShallowEqual( const XMLNode* compare ) const override; protected: - XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {} + explicit XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {} virtual ~XMLText() {} - char* ParseDeep( char*, StrPair* endTag ); + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override; private: bool _isCData; @@ -936,23 +1035,23 @@ class TINYXML2_LIB XMLComment : public XMLNode { friend class XMLDocument; public: - virtual XMLComment* ToComment() { + virtual XMLComment* ToComment() override { return this; } - virtual const XMLComment* ToComment() const { + virtual const XMLComment* ToComment() const override { return this; } - virtual bool Accept( XMLVisitor* visitor ) const; + virtual bool Accept( XMLVisitor* visitor ) const override; - virtual XMLNode* ShallowClone( XMLDocument* document ) const; - virtual bool ShallowEqual( const XMLNode* compare ) const; + virtual XMLNode* ShallowClone( XMLDocument* document ) const override; + virtual bool ShallowEqual( const XMLNode* compare ) const override; protected: - XMLComment( XMLDocument* doc ); + explicit XMLComment( XMLDocument* doc ); virtual ~XMLComment(); - char* ParseDeep( char*, StrPair* endTag ); + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr) override; private: XMLComment( const XMLComment& ); // not supported @@ -975,23 +1074,23 @@ class TINYXML2_LIB XMLDeclaration : public XMLNode { friend class XMLDocument; public: - virtual XMLDeclaration* ToDeclaration() { + virtual XMLDeclaration* ToDeclaration() override { return this; } - virtual const XMLDeclaration* ToDeclaration() const { + virtual const XMLDeclaration* ToDeclaration() const override { return this; } - virtual bool Accept( XMLVisitor* visitor ) const; + virtual bool Accept( XMLVisitor* visitor ) const override; - virtual XMLNode* ShallowClone( XMLDocument* document ) const; - virtual bool ShallowEqual( const XMLNode* compare ) const; + virtual XMLNode* ShallowClone( XMLDocument* document ) const override; + virtual bool ShallowEqual( const XMLNode* compare ) const override; protected: - XMLDeclaration( XMLDocument* doc ); + explicit XMLDeclaration( XMLDocument* doc ); virtual ~XMLDeclaration(); - char* ParseDeep( char*, StrPair* endTag ); + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override; private: XMLDeclaration( const XMLDeclaration& ); // not supported @@ -1010,23 +1109,23 @@ class TINYXML2_LIB XMLUnknown : public XMLNode { friend class XMLDocument; public: - virtual XMLUnknown* ToUnknown() { + virtual XMLUnknown* ToUnknown() override { return this; } - virtual const XMLUnknown* ToUnknown() const { + virtual const XMLUnknown* ToUnknown() const override { return this; } - virtual bool Accept( XMLVisitor* visitor ) const; + virtual bool Accept( XMLVisitor* visitor ) const override; - virtual XMLNode* ShallowClone( XMLDocument* document ) const; - virtual bool ShallowEqual( const XMLNode* compare ) const; + virtual XMLNode* ShallowClone( XMLDocument* document ) const override; + virtual bool ShallowEqual( const XMLNode* compare ) const override; protected: - XMLUnknown( XMLDocument* doc ); + explicit XMLUnknown( XMLDocument* doc ); virtual ~XMLUnknown(); - char* ParseDeep( char*, StrPair* endTag ); + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override; private: XMLUnknown( const XMLUnknown& ); // not supported @@ -1051,6 +1150,9 @@ class TINYXML2_LIB XMLAttribute /// The value of the attribute. const char* Value() const; + /// Gets the line number the attribute is in, if the document was parsed from a file. + int GetLineNum() const { return _parseLineNum; } + /// The next attribute in the list. const XMLAttribute* Next() const { return _next; @@ -1060,11 +1162,24 @@ class TINYXML2_LIB XMLAttribute If the value isn't an integer, 0 will be returned. There is no error checking; use QueryIntValue() if you need error checking. */ - int IntValue() const { - int i=0; - QueryIntValue( &i ); + int IntValue() const { + int i = 0; + QueryIntValue(&i); + return i; + } + + int64_t Int64Value() const { + int64_t i = 0; + QueryInt64Value(&i); + return i; + } + + uint64_t Unsigned64Value() const { + uint64_t i = 0; + QueryUnsigned64Value(&i); return i; } + /// Query as an unsigned integer. See IntValue() unsigned UnsignedValue() const { unsigned i=0; @@ -1091,13 +1206,17 @@ class TINYXML2_LIB XMLAttribute } /** QueryIntValue interprets the attribute as an integer, and returns the value - in the provided parameter. The function will return XML_NO_ERROR on success, + in the provided parameter. The function will return XML_SUCCESS on success, and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful. */ XMLError QueryIntValue( int* value ) const; /// See QueryIntValue XMLError QueryUnsignedValue( unsigned int* value ) const; + /// See QueryIntValue + XMLError QueryInt64Value(int64_t* value) const; /// See QueryIntValue + XMLError QueryUnsigned64Value(uint64_t* value) const; + /// See QueryIntValue XMLError QueryBoolValue( bool* value ) const; /// See QueryIntValue XMLError QueryDoubleValue( double* value ) const; @@ -1110,6 +1229,10 @@ class TINYXML2_LIB XMLAttribute void SetAttribute( int value ); /// Set the attribute to value. void SetAttribute( unsigned value ); + /// Set the attribute to value. + void SetAttribute(int64_t value); + /// Set the attribute to value. + void SetAttribute(uint64_t value); /// Set the attribute to value. void SetAttribute( bool value ); /// Set the attribute to value. @@ -1120,17 +1243,18 @@ class TINYXML2_LIB XMLAttribute private: enum { BUF_SIZE = 200 }; - XMLAttribute() : _next( 0 ), _memPool( 0 ) {} + XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {} virtual ~XMLAttribute() {} XMLAttribute( const XMLAttribute& ); // not supported void operator=( const XMLAttribute& ); // not supported void SetName( const char* name ); - char* ParseDeep( char* p, bool processEntities ); + char* ParseDeep( char* p, bool processEntities, int* curLineNumPtr ); mutable StrPair _name; mutable StrPair _value; + int _parseLineNum; XMLAttribute* _next; MemPool* _memPool; }; @@ -1142,7 +1266,6 @@ class TINYXML2_LIB XMLAttribute */ class TINYXML2_LIB XMLElement : public XMLNode { - friend class XMLBase; friend class XMLDocument; public: /// Get the name of an element (which is the Value() of the node.) @@ -1154,13 +1277,13 @@ class TINYXML2_LIB XMLElement : public XMLNode SetValue( str, staticMem ); } - virtual XMLElement* ToElement() { + virtual XMLElement* ToElement() override { return this; } - virtual const XMLElement* ToElement() const { + virtual const XMLElement* ToElement() const override { return this; } - virtual bool Accept( XMLVisitor* visitor ) const; + virtual bool Accept( XMLVisitor* visitor ) const override; /** Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none @@ -1188,42 +1311,27 @@ class TINYXML2_LIB XMLElement : public XMLNode const char* Attribute( const char* name, const char* value=0 ) const; /** Given an attribute name, IntAttribute() returns the value - of the attribute interpreted as an integer. 0 will be - returned if there is an error. For a method with error - checking, see QueryIntAttribute() + of the attribute interpreted as an integer. The default + value will be returned if the attribute isn't present, + or if there is an error. (For a method with error + checking, see QueryIntAttribute()). */ - int IntAttribute( const char* name ) const { - int i=0; - QueryIntAttribute( name, &i ); - return i; - } + int IntAttribute(const char* name, int defaultValue = 0) const; /// See IntAttribute() - unsigned UnsignedAttribute( const char* name ) const { - unsigned i=0; - QueryUnsignedAttribute( name, &i ); - return i; - } + unsigned UnsignedAttribute(const char* name, unsigned defaultValue = 0) const; + /// See IntAttribute() + int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const; /// See IntAttribute() - bool BoolAttribute( const char* name ) const { - bool b=false; - QueryBoolAttribute( name, &b ); - return b; - } + uint64_t Unsigned64Attribute(const char* name, uint64_t defaultValue = 0) const; + /// See IntAttribute() + bool BoolAttribute(const char* name, bool defaultValue = false) const; /// See IntAttribute() - double DoubleAttribute( const char* name ) const { - double d=0; - QueryDoubleAttribute( name, &d ); - return d; - } + double DoubleAttribute(const char* name, double defaultValue = 0) const; /// See IntAttribute() - float FloatAttribute( const char* name ) const { - float f=0; - QueryFloatAttribute( name, &f ); - return f; - } + float FloatAttribute(const char* name, float defaultValue = 0) const; /** Given an attribute name, QueryIntAttribute() returns - XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion + XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion can't be performed, or XML_NO_ATTRIBUTE if the attribute doesn't exist. If successful, the result of the conversion will be written to 'value'. If not successful, nothing will @@ -1242,7 +1350,8 @@ class TINYXML2_LIB XMLElement : public XMLNode } return a->QueryIntValue( value ); } - /// See QueryIntAttribute() + + /// See QueryIntAttribute() XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { @@ -1250,7 +1359,26 @@ class TINYXML2_LIB XMLElement : public XMLNode } return a->QueryUnsignedValue( value ); } + + /// See QueryIntAttribute() + XMLError QueryInt64Attribute(const char* name, int64_t* value) const { + const XMLAttribute* a = FindAttribute(name); + if (!a) { + return XML_NO_ATTRIBUTE; + } + return a->QueryInt64Value(value); + } + /// See QueryIntAttribute() + XMLError QueryUnsigned64Attribute(const char* name, uint64_t* value) const { + const XMLAttribute* a = FindAttribute(name); + if(!a) { + return XML_NO_ATTRIBUTE; + } + return a->QueryUnsigned64Value(value); + } + + /// See QueryIntAttribute() XMLError QueryBoolAttribute( const char* name, bool* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { @@ -1275,14 +1403,25 @@ class TINYXML2_LIB XMLElement : public XMLNode return a->QueryFloatValue( value ); } - + /// See QueryIntAttribute() + XMLError QueryStringAttribute(const char* name, const char** value) const { + const XMLAttribute* a = FindAttribute(name); + if (!a) { + return XML_NO_ATTRIBUTE; + } + *value = a->Value(); + return XML_SUCCESS; + } + + + /** Given an attribute name, QueryAttribute() returns - XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion + XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion can't be performed, or XML_NO_ATTRIBUTE if the attribute doesn't exist. It is overloaded for the primitive types, and is a generally more convenient replacement of QueryIntAttribute() and related functions. - + If successful, the result of the conversion will be written to 'value'. If not successful, nothing will be written to 'value'. This allows you to provide default @@ -1293,26 +1432,38 @@ class TINYXML2_LIB XMLElement : public XMLNode QueryAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 @endverbatim */ - int QueryAttribute( const char* name, int* value ) const { + XMLError QueryAttribute( const char* name, int* value ) const { return QueryIntAttribute( name, value ); } - int QueryAttribute( const char* name, unsigned int* value ) const { + XMLError QueryAttribute( const char* name, unsigned int* value ) const { return QueryUnsignedAttribute( name, value ); } - int QueryAttribute( const char* name, bool* value ) const { + XMLError QueryAttribute(const char* name, int64_t* value) const { + return QueryInt64Attribute(name, value); + } + + XMLError QueryAttribute(const char* name, uint64_t* value) const { + return QueryUnsigned64Attribute(name, value); + } + + XMLError QueryAttribute( const char* name, bool* value ) const { return QueryBoolAttribute( name, value ); } - int QueryAttribute( const char* name, double* value ) const { + XMLError QueryAttribute( const char* name, double* value ) const { return QueryDoubleAttribute( name, value ); } - int QueryAttribute( const char* name, float* value ) const { + XMLError QueryAttribute( const char* name, float* value ) const { return QueryFloatAttribute( name, value ); } + XMLError QueryAttribute(const char* name, const char** value) const { + return QueryStringAttribute(name, value); + } + /// Sets the named attribute to value. void SetAttribute( const char* name, const char* value ) { XMLAttribute* a = FindOrCreateAttribute( name ); @@ -1328,6 +1479,19 @@ class TINYXML2_LIB XMLElement : public XMLNode XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } + + /// Sets the named attribute to value. + void SetAttribute(const char* name, int64_t value) { + XMLAttribute* a = FindOrCreateAttribute(name); + a->SetAttribute(value); + } + + /// Sets the named attribute to value. + void SetAttribute(const char* name, uint64_t value) { + XMLAttribute* a = FindOrCreateAttribute(name); + a->SetAttribute(value); + } + /// Sets the named attribute to value. void SetAttribute( const char* name, bool value ) { XMLAttribute* a = FindOrCreateAttribute( name ); @@ -1410,7 +1574,7 @@ class TINYXML2_LIB XMLElement : public XMLNode @verbatim Hullaballoo!This is text @endverbatim - + For this XML: @verbatim @@ -1424,13 +1588,17 @@ class TINYXML2_LIB XMLElement : public XMLNode /// Convenience method for setting text inside an element. See SetText() for important limitations. void SetText( int value ); /// Convenience method for setting text inside an element. See SetText() for important limitations. - void SetText( unsigned value ); + void SetText( unsigned value ); + /// Convenience method for setting text inside an element. See SetText() for important limitations. + void SetText(int64_t value); /// Convenience method for setting text inside an element. See SetText() for important limitations. - void SetText( bool value ); + void SetText(uint64_t value); + /// Convenience method for setting text inside an element. See SetText() for important limitations. + void SetText( bool value ); /// Convenience method for setting text inside an element. See SetText() for important limitations. - void SetText( double value ); + void SetText( double value ); /// Convenience method for setting text inside an element. See SetText() for important limitations. - void SetText( float value ); + void SetText( float value ); /** Convenience method to query the value of a child text node. This is probably best @@ -1461,27 +1629,61 @@ class TINYXML2_LIB XMLElement : public XMLNode XMLError QueryIntText( int* ival ) const; /// See QueryIntText() XMLError QueryUnsignedText( unsigned* uval ) const; - /// See QueryIntText() + /// See QueryIntText() + XMLError QueryInt64Text(int64_t* uval) const; + /// See QueryIntText() + XMLError QueryUnsigned64Text(uint64_t* uval) const; + /// See QueryIntText() XMLError QueryBoolText( bool* bval ) const; /// See QueryIntText() XMLError QueryDoubleText( double* dval ) const; /// See QueryIntText() XMLError QueryFloatText( float* fval ) const; + int IntText(int defaultValue = 0) const; + + /// See QueryIntText() + unsigned UnsignedText(unsigned defaultValue = 0) const; + /// See QueryIntText() + int64_t Int64Text(int64_t defaultValue = 0) const; + /// See QueryIntText() + uint64_t Unsigned64Text(uint64_t defaultValue = 0) const; + /// See QueryIntText() + bool BoolText(bool defaultValue = false) const; + /// See QueryIntText() + double DoubleText(double defaultValue = 0) const; + /// See QueryIntText() + float FloatText(float defaultValue = 0) const; + + /** + Convenience method to create a new XMLElement and add it as last (right) + child of this node. Returns the created and inserted element. + */ + XMLElement* InsertNewChildElement(const char* name); + /// See InsertNewChildElement() + XMLComment* InsertNewComment(const char* comment); + /// See InsertNewChildElement() + XMLText* InsertNewText(const char* text); + /// See InsertNewChildElement() + XMLDeclaration* InsertNewDeclaration(const char* text); + /// See InsertNewChildElement() + XMLUnknown* InsertNewUnknown(const char* text); + + // internal: - enum { + enum ElementClosingType { OPEN, // CLOSED, // CLOSING // }; - int ClosingType() const { + ElementClosingType ClosingType() const { return _closingType; } - virtual XMLNode* ShallowClone( XMLDocument* document ) const; - virtual bool ShallowEqual( const XMLNode* compare ) const; + virtual XMLNode* ShallowClone( XMLDocument* document ) const override; + virtual bool ShallowEqual( const XMLNode* compare ) const override; protected: - char* ParseDeep( char* p, StrPair* endTag ); + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override; private: XMLElement( XMLDocument* doc ); @@ -1489,16 +1691,13 @@ class TINYXML2_LIB XMLElement : public XMLNode XMLElement( const XMLElement& ); // not supported void operator=( const XMLElement& ); // not supported - XMLAttribute* FindAttribute( const char* name ) { - return const_cast(const_cast(this)->FindAttribute( name )); - } XMLAttribute* FindOrCreateAttribute( const char* name ); - //void LinkAttribute( XMLAttribute* attrib ); - char* ParseAttributes( char* p ); + char* ParseAttributes( char* p, int* curLineNumPtr ); static void DeleteAttribute( XMLAttribute* attribute ); + XMLAttribute* CreateAttribute(); enum { BUF_SIZE = 200 }; - int _closingType; + ElementClosingType _closingType; // The attribute list is ordered; there is no 'lastAttribute' // because the list needs to be scanned for dupes before adding // a new attribute. @@ -1508,7 +1707,8 @@ class TINYXML2_LIB XMLElement : public XMLNode enum Whitespace { PRESERVE_WHITESPACE, - COLLAPSE_WHITESPACE + COLLAPSE_WHITESPACE, + PEDANTIC_WHITESPACE }; @@ -1520,23 +1720,30 @@ enum Whitespace { class TINYXML2_LIB XMLDocument : public XMLNode { friend class XMLElement; + // Gives access to SetError and Push/PopDepth, but over-access for everything else. + // Wishing C++ had "internal" scope. + friend class XMLNode; + friend class XMLText; + friend class XMLComment; + friend class XMLDeclaration; + friend class XMLUnknown; public: /// constructor - XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE ); + XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE ); ~XMLDocument(); - virtual XMLDocument* ToDocument() { + virtual XMLDocument* ToDocument() override { TIXMLASSERT( this == _document ); return this; } - virtual const XMLDocument* ToDocument() const { + virtual const XMLDocument* ToDocument() const override { TIXMLASSERT( this == _document ); return this; } /** Parse an XML file from a character string. - Returns XML_NO_ERROR (0) on success, or + Returns XML_SUCCESS (0) on success, or an errorID. You may optionally pass in the 'nBytes', which is @@ -1544,31 +1751,31 @@ class TINYXML2_LIB XMLDocument : public XMLNode specified, TinyXML-2 will assume 'xml' points to a null terminated string. */ - XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) ); + XMLError Parse( const char* xml, size_t nBytes=static_cast(-1) ); /** Load an XML file from disk. - Returns XML_NO_ERROR (0) on success, or + Returns XML_SUCCESS (0) on success, or an errorID. */ XMLError LoadFile( const char* filename ); /** Load an XML file from disk. You are responsible - for providing and closing the FILE*. - + for providing and closing the FILE*. + NOTE: The file should be opened as binary ("rb") not text in order for TinyXML-2 to correctly do newline normalization. - Returns XML_NO_ERROR (0) on success, or + Returns XML_SUCCESS (0) on success, or an errorID. */ XMLError LoadFile( FILE* ); /** Save the XML file to disk. - Returns XML_NO_ERROR (0) on success, or + Returns XML_SUCCESS (0) on success, or an errorID. */ XMLError SaveFile( const char* filename, bool compact = false ); @@ -1577,7 +1784,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode Save the XML file to disk. You are responsible for providing and closing the FILE*. - Returns XML_NO_ERROR (0) on success, or + Returns XML_SUCCESS (0) on success, or an errorID. */ XMLError SaveFile( FILE* fp, bool compact = false ); @@ -1586,7 +1793,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode return _processEntities; } Whitespace WhitespaceMode() const { - return _whitespace; + return _whitespaceMode; } /** @@ -1626,7 +1833,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode @endverbatim */ void Print( XMLPrinter* streamer=0 ) const; - virtual bool Accept( XMLVisitor* visitor ) const; + virtual bool Accept( XMLVisitor* visitor ) const override; /** Create a new Element associated with @@ -1671,39 +1878,56 @@ class TINYXML2_LIB XMLDocument : public XMLNode */ void DeleteNode( XMLNode* node ); - void SetError( XMLError error, const char* str1, const char* str2 ); + /// Clears the error flags. + void ClearError(); /// Return true if there was an error parsing the document. bool Error() const { - return _errorID != XML_NO_ERROR; + return _errorID != XML_SUCCESS; } /// Return the errorID. XMLError ErrorID() const { return _errorID; } const char* ErrorName() const; + static const char* ErrorIDToName(XMLError errorID); - /// Return a possibly helpful diagnostic location or string. - const char* GetErrorStr1() const { - return _errorStr1; - } - /// Return a possibly helpful secondary diagnostic location or string. - const char* GetErrorStr2() const { - return _errorStr2; - } - /// If there is an error, print it to stdout. + /** Returns a "long form" error description. A hopefully helpful + diagnostic with location, line number, and/or additional info. + */ + const char* ErrorStr() const; + + /// A (trivial) utility function that prints the ErrorStr() to stdout. void PrintError() const; - + + /// Return the line where the error occurred, or zero if unknown. + int ErrorLineNum() const + { + return _errorLineNum; + } + /// Clear the document, resetting it to the initial state. void Clear(); - // internal - char* Identify( char* p, XMLNode** node ); + /** + Copies this document to a target document. + The target will be completely cleared before the copy. + If you want to copy a sub-tree, see XMLNode::DeepClone(). + + NOTE: that the 'target' must be non-null. + */ + void DeepCopy(XMLDocument* target) const; + + // internal + char* Identify( char* p, XMLNode** node, bool first ); - virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const { + // internal + void MarkInUse(const XMLNode* const); + + virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const override{ return 0; } - virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const { + virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const override{ return false; } @@ -1711,13 +1935,22 @@ class TINYXML2_LIB XMLDocument : public XMLNode XMLDocument( const XMLDocument& ); // not supported void operator=( const XMLDocument& ); // not supported - bool _writeBOM; - bool _processEntities; - XMLError _errorID; - Whitespace _whitespace; - const char* _errorStr1; - const char* _errorStr2; - char* _charBuffer; + bool _writeBOM; + bool _processEntities; + XMLError _errorID; + Whitespace _whitespaceMode; + mutable StrPair _errorStr; + int _errorLineNum; + char* _charBuffer; + int _parseCurLineNum; + int _parsingDepth; + // Memory tracking does add some overhead. + // However, the code assumes that you don't + // have a bunch of unlinked nodes around. + // Therefore it takes less memory to track + // in the document vs. a linked list in the XMLNode, + // and the performance is the same. + DynArray _unlinked; MemPoolT< sizeof(XMLElement) > _elementPool; MemPoolT< sizeof(XMLAttribute) > _attributePool; @@ -1727,8 +1960,43 @@ class TINYXML2_LIB XMLDocument : public XMLNode static const char* _errorNames[XML_ERROR_COUNT]; void Parse(); + + void SetError( XMLError error, int lineNum, const char* format, ... ); + + // Something of an obvious security hole, once it was discovered. + // Either an ill-formed XML or an excessively deep one can overflow + // the stack. Track stack depth, and error out if needed. + class DepthTracker { + public: + explicit DepthTracker(XMLDocument * document) { + this->_document = document; + document->PushDepth(); + } + ~DepthTracker() { + _document->PopDepth(); + } + private: + XMLDocument * _document; + }; + void PushDepth(); + void PopDepth(); + + template + NodeType* CreateUnlinkedNode( MemPoolT& pool ); }; +template +inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT& pool ) +{ + TIXMLASSERT( sizeof( NodeType ) == PoolElementSize ); + TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() ); + NodeType* returnNode = new (pool.Alloc()) NodeType( this ); + TIXMLASSERT( returnNode ); + returnNode->_memPool = &pool; + + _unlinked.Push(returnNode); + return returnNode; +} /** A XMLHandle is a class that wraps a node pointer with null checks; this is @@ -1789,16 +2057,13 @@ class TINYXML2_LIB XMLHandle { public: /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. - XMLHandle( XMLNode* node ) { - _node = node; + explicit XMLHandle( XMLNode* node ) : _node( node ) { } /// Create a handle from a node. - XMLHandle( XMLNode& node ) { - _node = &node; + explicit XMLHandle( XMLNode& node ) : _node( &node ) { } /// Copy constructor - XMLHandle( const XMLHandle& ref ) { - _node = ref._node; + XMLHandle( const XMLHandle& ref ) : _node( ref._node ) { } /// Assignment XMLHandle& operator=( const XMLHandle& ref ) { @@ -1845,19 +2110,19 @@ class TINYXML2_LIB XMLHandle } /// Safe cast to XMLElement. This can return null. XMLElement* ToElement() { - return ( ( _node == 0 ) ? 0 : _node->ToElement() ); + return ( _node ? _node->ToElement() : 0 ); } /// Safe cast to XMLText. This can return null. XMLText* ToText() { - return ( ( _node == 0 ) ? 0 : _node->ToText() ); + return ( _node ? _node->ToText() : 0 ); } /// Safe cast to XMLUnknown. This can return null. XMLUnknown* ToUnknown() { - return ( ( _node == 0 ) ? 0 : _node->ToUnknown() ); + return ( _node ? _node->ToUnknown() : 0 ); } /// Safe cast to XMLDeclaration. This can return null. XMLDeclaration* ToDeclaration() { - return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() ); + return ( _node ? _node->ToDeclaration() : 0 ); } private: @@ -1872,14 +2137,11 @@ class TINYXML2_LIB XMLHandle class TINYXML2_LIB XMLConstHandle { public: - XMLConstHandle( const XMLNode* node ) { - _node = node; + explicit XMLConstHandle( const XMLNode* node ) : _node( node ) { } - XMLConstHandle( const XMLNode& node ) { - _node = &node; + explicit XMLConstHandle( const XMLNode& node ) : _node( &node ) { } - XMLConstHandle( const XMLConstHandle& ref ) { - _node = ref._node; + XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) { } XMLConstHandle& operator=( const XMLConstHandle& ref ) { @@ -1917,16 +2179,16 @@ class TINYXML2_LIB XMLConstHandle return _node; } const XMLElement* ToElement() const { - return ( ( _node == 0 ) ? 0 : _node->ToElement() ); + return ( _node ? _node->ToElement() : 0 ); } const XMLText* ToText() const { - return ( ( _node == 0 ) ? 0 : _node->ToText() ); + return ( _node ? _node->ToText() : 0 ); } const XMLUnknown* ToUnknown() const { - return ( ( _node == 0 ) ? 0 : _node->ToUnknown() ); + return ( _node ? _node->ToUnknown() : 0 ); } const XMLDeclaration* ToDeclaration() const { - return ( ( _node == 0 ) ? 0 : _node->ToDeclaration() ); + return ( _node ? _node->ToDeclaration() : 0 ); } private: @@ -1998,7 +2260,9 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor void PushAttribute( const char* name, const char* value ); void PushAttribute( const char* name, int value ); void PushAttribute( const char* name, unsigned value ); - void PushAttribute( const char* name, bool value ); + void PushAttribute( const char* name, int64_t value ); + void PushAttribute( const char* name, uint64_t value ); + void PushAttribute( const char* name, bool value ); void PushAttribute( const char* name, double value ); /// If streaming, close the Element. virtual void CloseElement( bool compactMode=false ); @@ -2009,7 +2273,11 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor void PushText( int value ); /// Add a text node from an unsigned. void PushText( unsigned value ); - /// Add a text node from a bool. + /// Add a text node from a signed 64bit integer. + void PushText( int64_t value ); + /// Add a text node from an unsigned 64bit integer. + void PushText( uint64_t value ); + /// Add a text node from a bool. void PushText( bool value ); /// Add a text node from a float. void PushText( float value ); @@ -2022,18 +2290,18 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor void PushDeclaration( const char* value ); void PushUnknown( const char* value ); - virtual bool VisitEnter( const XMLDocument& /*doc*/ ); - virtual bool VisitExit( const XMLDocument& /*doc*/ ) { + virtual bool VisitEnter( const XMLDocument& /*doc*/ ) override; + virtual bool VisitExit( const XMLDocument& /*doc*/ ) override { return true; } - virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute ); - virtual bool VisitExit( const XMLElement& element ); + virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute ) override; + virtual bool VisitExit( const XMLElement& element ) override; - virtual bool Visit( const XMLText& text ); - virtual bool Visit( const XMLComment& comment ); - virtual bool Visit( const XMLDeclaration& declaration ); - virtual bool Visit( const XMLUnknown& unknown ); + virtual bool Visit( const XMLText& text ) override; + virtual bool Visit( const XMLComment& comment ) override; + virtual bool Visit( const XMLDeclaration& declaration ) override; + virtual bool Visit( const XMLUnknown& unknown ) override; /** If in print to memory mode, return a pointer to @@ -2054,9 +2322,10 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor If in print to memory mode, reset the buffer to the beginning. */ - void ClearBuffer() { + void ClearBuffer( bool resetToFirstElement = true ) { _buffer.Clear(); _buffer.Push(0); + _firstElement = resetToFirstElement; } protected: @@ -2066,13 +2335,22 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor the space and tabs used. A PrintSpace() override should call Print(). */ virtual void PrintSpace( int depth ); - void Print( const char* format, ... ); + virtual void Print( const char* format, ... ); + virtual void Write( const char* data, size_t size ); + virtual void Putc( char ch ); + + inline void Write(const char* data) { Write(data, strlen(data)); } void SealElementIfJustOpened(); bool _elementJustOpened; DynArray< const char*, 10 > _stack; private: + /** + Prepares to write a new node. This includes sealing an element that was + just opened, and writing any whitespace necessary if not in compact mode. + */ + void PrepareForNewNode( bool compactMode ); void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities. bool _firstElement; @@ -2090,6 +2368,10 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor bool _restrictedEntityFlag[ENTITY_RANGE]; DynArray< char, 20 > _buffer; + + // Prohibit cloning, intentionally not implemented + XMLPrinter( const XMLPrinter& ); + XMLPrinter& operator=( const XMLPrinter& ); }; diff --git a/extend/lunqlite/lunqlite.lmak b/extend/lunqlite/lunqlite.lmak index 1da1d332..f4a57782 100644 --- a/extend/lunqlite/lunqlite.lmak +++ b/extend/lunqlite/lunqlite.lmak @@ -8,6 +8,7 @@ TARGET_NAME = "lunqlite" PROJECT_TYPE = "dynamic" FLAGS = { + "Wno-misleading-indentation", "Wno-implicit-fallthrough" } diff --git a/extend/lunqlite/lunqlite.mak b/extend/lunqlite/lunqlite.mak index a1d7b84a..dcdcc279 100644 --- a/extend/lunqlite/lunqlite.mak +++ b/extend/lunqlite/lunqlite.mak @@ -15,13 +15,12 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas +MYCFLAGS += -Wno-misleading-indentation MYCFLAGS += -Wno-implicit-fallthrough #c标准库版本 @@ -42,12 +41,6 @@ MYCFLAGS += -I../luakit/include LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -67,8 +60,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -99,21 +92,23 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/lunqlite.cpp +SOURCES += src/unqlite.c + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -130,6 +125,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/lunqlite/lunqlite.vcxproj.filters b/extend/lunqlite/lunqlite.vcxproj.filters index 1b567a85..8e10b854 100644 --- a/extend/lunqlite/lunqlite.vcxproj.filters +++ b/extend/lunqlite/lunqlite.vcxproj.filters @@ -2,10 +2,10 @@ - inc + src - inc + src @@ -17,9 +17,6 @@ - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/extend/lworker/lworker.lmak b/extend/lworker/lworker.lmak index 836828c2..49acc87a 100644 --- a/extend/lworker/lworker.lmak +++ b/extend/lworker/lworker.lmak @@ -10,8 +10,8 @@ PROJECT_TYPE = "dynamic" --需要的include目录 INCLUDES = { "../lua/lua", + "../ltimer/src", "../fmt/include", - "../ltimer/ltimer", "../luakit/include" } diff --git a/extend/lworker/lworker.mak b/extend/lworker/lworker.mak index a1e1b37c..ac2c7f27 100644 --- a/extend/lworker/lworker.mak +++ b/extend/lworker/lworker.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas #c标准库版本 #gnu99/gnu11/gnu17 @@ -33,8 +31,8 @@ STDCPP = -std=c++17 #需要的include目录 MYCFLAGS += -I../lua/lua +MYCFLAGS += -I../ltimer/src MYCFLAGS += -I../fmt/include -MYCFLAGS += -I../ltimer/ltimer MYCFLAGS += -I../luakit/include #需要定义的选项 @@ -44,12 +42,6 @@ MYCFLAGS += -DFMT_HEADER_ONLY LDFLAGS = -#源文件路径 -SRC_DIR = src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -69,8 +61,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -101,21 +93,22 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += src/lworker.cpp + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -132,6 +125,7 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) + mkdir -p $(INT_DIR)/src #后编译 post_build: diff --git a/extend/lworker/lworker.vcxproj b/extend/lworker/lworker.vcxproj index c6e5a871..1d3b75d6 100644 --- a/extend/lworker/lworker.vcxproj +++ b/extend/lworker/lworker.vcxproj @@ -44,7 +44,7 @@ Disabled - ..\lua\lua;..\fmt\include;..\ltimer\ltimer;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) + ..\lua\lua;..\ltimer\src;..\fmt\include;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;FMT_HEADER_ONLY;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default MultiThreadedDLL diff --git a/extend/lworker/lworker.vcxproj.filters b/extend/lworker/lworker.vcxproj.filters index 6fe96e5a..862174af 100644 --- a/extend/lworker/lworker.vcxproj.filters +++ b/extend/lworker/lworker.vcxproj.filters @@ -2,10 +2,10 @@ - inc + src - inc + src @@ -14,9 +14,6 @@ - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} diff --git a/extend/mimalloc/mimalloc.lmak b/extend/mimalloc/mimalloc.lmak index 070044e4..01b65134 100644 --- a/extend/mimalloc/mimalloc.lmak +++ b/extend/mimalloc/mimalloc.lmak @@ -12,11 +12,6 @@ INCLUDES = { "mimalloc/include" } ---子目录路径 -SUB_DIR = { - "prim" -} - --目标文件前缀 LIB_PREFIX = 1 @@ -29,11 +24,21 @@ DEFINES = { } --源文件路径 -SRC_DIR = "mimalloc/src" +SRC_DIRS = { + "mimalloc/src" +} --需要排除的源文件,目录基于$(SRC_DIR) EXCLUDE_FILE={ - "static.c", "page-queue.c", "alloc-override.c", "free.c" + "free.c", + "static.c", + "page-queue.c", + "alloc-override.c", + "prim/osx/prim.c", + "prim/unix/prim.c", + "prim/wasi/prim.c", + "prim/windows/prim.c", + "prim/osx/alloc-override-zone.c" } --WINDOWS需要连接的库文件 diff --git a/extend/mimalloc/mimalloc.mak b/extend/mimalloc/mimalloc.mak index 1a9ea357..49568e1b 100644 --- a/extend/mimalloc/mimalloc.mak +++ b/extend/mimalloc/mimalloc.mak @@ -15,13 +15,11 @@ all : pre_build target post_build MYCFLAGS = #需要定义的FLAG -MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter -MYCFLAGS += -Wno-unknown-pragmas #c标准库版本 #gnu99/gnu11/gnu17 @@ -44,16 +42,6 @@ MYCFLAGS += -DNDEBUG LDFLAGS = -#源文件路径 -SRC_DIR = mimalloc/src - -#需要排除的源文件,目录基于$(SRC_DIR) -EXCLUDE = -EXCLUDE += $(SRC_DIR)/static.c -EXCLUDE += $(SRC_DIR)/page-queue.c -EXCLUDE += $(SRC_DIR)/alloc-override.c -EXCLUDE += $(SRC_DIR)/free.c - #需要连接的库文件 LIBS = ifneq ($(UNAME_S), Darwin) @@ -69,8 +57,8 @@ endif ifndef CX CX = c++ endif -CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS) -CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS) +CFLAGS = -g -O2 -Wall -Wno-deprecated $(STDC) $(MYCFLAGS) +CXXFLAGS = -g -O2 -Wall -Wno-deprecated $(STDCPP) $(MYCFLAGS) #项目目录 ifndef SOLUTION_DIR @@ -101,26 +89,37 @@ LDFLAGS += -L$(SOLUTION_DIR)bin LDFLAGS += -L$(SOLUTION_DIR)library #自动生成目标 -OBJS = -#子目录 -OBJS += $(patsubst $(SRC_DIR)/prim/%.c, $(INT_DIR)/prim/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/prim/*.c))) -OBJS += $(patsubst $(SRC_DIR)/prim/%.m, $(INT_DIR)/prim/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/prim/*.m))) -OBJS += $(patsubst $(SRC_DIR)/prim/%.cc, $(INT_DIR)/prim/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/prim/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/prim/%.cpp, $(INT_DIR)/prim/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/prim/*.cpp))) -#根目录 -OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c))) -OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m))) -OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc))) -OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp))) +SOURCES = +SOURCES += mimalloc/src/alloc-aligned.c +SOURCES += mimalloc/src/alloc-posix.c +SOURCES += mimalloc/src/alloc.c +SOURCES += mimalloc/src/arena.c +SOURCES += mimalloc/src/bitmap.c +SOURCES += mimalloc/src/heap.c +SOURCES += mimalloc/src/init.c +SOURCES += mimalloc/src/libc.c +SOURCES += mimalloc/src/options.c +SOURCES += mimalloc/src/os.c +SOURCES += mimalloc/src/page.c +SOURCES += mimalloc/src/prim/prim.c +SOURCES += mimalloc/src/random.c +SOURCES += mimalloc/src/segment-map.c +SOURCES += mimalloc/src/segment.c +SOURCES += mimalloc/src/stats.c + +CSOURCES = $(patsubst %.c, $(INT_DIR)/%.o, $(SOURCES)) +MSOURCES = $(patsubst %.m, $(INT_DIR)/%.o, $(CSOURCES)) +CCSOURCES = $(patsubst %.cc, $(INT_DIR)/%.o, $(MSOURCES)) +OBJS = $(patsubst %.cpp, $(INT_DIR)/%.o, $(CCSOURCES)) # 编译所有源文件 -$(INT_DIR)/%.o : $(SRC_DIR)/%.c +$(INT_DIR)/%.o : %.c $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.m +$(INT_DIR)/%.o : %.m $(CC) $(CFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cc +$(INT_DIR)/%.o : %.cc $(CX) $(CXXFLAGS) -c $< -o $@ -$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp +$(INT_DIR)/%.o : %.cpp $(CX) $(CXXFLAGS) -c $< -o $@ $(TARGET_DYNAMIC) : $(OBJS) @@ -137,7 +136,8 @@ clean : pre_build: mkdir -p $(INT_DIR) mkdir -p $(TARGET_DIR) - mkdir -p $(INT_DIR)/prim + mkdir -p $(INT_DIR)/mimalloc/src + mkdir -p $(INT_DIR)/mimalloc/src/prim #后编译 post_build: diff --git a/extend/mimalloc/mimalloc.vcxproj b/extend/mimalloc/mimalloc.vcxproj index 50abd33d..fcb7fed0 100644 --- a/extend/mimalloc/mimalloc.vcxproj +++ b/extend/mimalloc/mimalloc.vcxproj @@ -8,35 +8,24 @@ + - - true - - - true - - - true - - - true - diff --git a/extend/mimalloc/mimalloc.vcxproj.filters b/extend/mimalloc/mimalloc.vcxproj.filters index 3299425b..08c5506e 100644 --- a/extend/mimalloc/mimalloc.vcxproj.filters +++ b/extend/mimalloc/mimalloc.vcxproj.filters @@ -2,80 +2,71 @@ - inc + mimalloc/src + + + mimalloc/src\prim\windows - src - - - src + mimalloc/src - src + mimalloc/src - src + mimalloc/src - src + mimalloc/src - src - - - src + mimalloc/src - src + mimalloc/src - src + mimalloc/src - src + mimalloc/src - src + mimalloc/src - src - - - src + mimalloc/src - src + mimalloc/src - prim + mimalloc/src\prim - src + mimalloc/src - src + mimalloc/src - src - - - src + mimalloc/src - src + mimalloc/src - - {CF9F3FDE-7326-F1D8-E642-05F0E07A3695} + + {8215DE2D-85CB-48A1-6D8A-03CC19252F74} - - {60BEC1A8-0A84-D025-8EDC-5AAF54952563} + + {BEEE3C53-4DD4-A571-E61A-3E5ED09A5F30} - - {25D902C2-4283-AB8C-FBAC-54DFA101AD31} + + {9118B0C9-5993-829F-1046-4BA353D0FFA7} \ No newline at end of file diff --git a/quanta.sln b/quanta.sln index 888657fe..2094a976 100644 --- a/quanta.sln +++ b/quanta.sln @@ -14,7 +14,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "luabus", "core\luabus\luabu EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "quanta", "core\quanta\quanta.vcxproj", "{2CE1C7DB-EA72-ED68-C587-CA3383754760}" ProjectSection(ProjectDependencies) = postProject - {EF1771A7-1C29-952D-C38C-5845D2AFAC62} = {EF1771A7-1C29-952D-C38C-5845D2AFAC62} + {046236D4-E56A-9382-7F53-467FBDB243B5} = {046236D4-E56A-9382-7F53-467FBDB243B5} + {EC8C4743-6D5F-E10D-3D10-98330150B2C9} = {EC8C4743-6D5F-E10D-3D10-98330150B2C9} {E44F97F7-1DE3-A547-6B58-30AEE63F22F5} = {E44F97F7-1DE3-A547-6B58-30AEE63F22F5} EndProjectSection EndProject @@ -50,6 +51,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lmdb", "extend\lmdb\lmdb.vc {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} = {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lminiz", "extend\lminiz\lminiz.vcxproj", "{046236D4-E56A-9382-7F53-467FBDB243B5}" + ProjectSection(ProjectDependencies) = postProject + {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} = {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lsqlite", "extend\lsqlite\lsqlite.vcxproj", "{1026823D-89D3-3E2E-15C2-661CDB0001EB}" ProjectSection(ProjectDependencies) = postProject {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} = {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} @@ -85,6 +91,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "luaxlsx", "extend\luaxlsx\l {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} = {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "luaxml", "extend\luaxml\luaxml.vcxproj", "{EC638E2A-A355-0936-373E-A893B2B596DC}" + ProjectSection(ProjectDependencies) = postProject + {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} = {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lunqlite", "extend\lunqlite\lunqlite.vcxproj", "{A950ABA2-0770-696C-6244-512CDCB2378A}" ProjectSection(ProjectDependencies) = postProject {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} = {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} @@ -116,11 +127,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "share", "share", "{D19A19B1 EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mimalloc", "extend\mimalloc\mimalloc.vcxproj", "{6805C141-3788-A994-7DCA-ADD6574D1386}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniz", "extend\luaxlsx\miniz.vcxproj", "{EF1771A7-1C29-952D-C38C-5845D2AFAC62}" - ProjectSection(ProjectDependencies) = postProject - {6805C141-3788-A994-7DCA-ADD6574D1386} = {6805C141-3788-A994-7DCA-ADD6574D1386} - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Develop|x64 = Develop|x64 @@ -142,6 +148,8 @@ Global {D2FD53CE-5F95-C3EC-13A1-11D91B9A412C}.Develop|x64.Build.0 = Develop|x64 {23753351-8C67-4966-7E36-7F900FE18D1B}.Develop|x64.ActiveCfg = Develop|x64 {23753351-8C67-4966-7E36-7F900FE18D1B}.Develop|x64.Build.0 = Develop|x64 + {046236D4-E56A-9382-7F53-467FBDB243B5}.Develop|x64.ActiveCfg = Develop|x64 + {046236D4-E56A-9382-7F53-467FBDB243B5}.Develop|x64.Build.0 = Develop|x64 {1026823D-89D3-3E2E-15C2-661CDB0001EB}.Develop|x64.ActiveCfg = Develop|x64 {1026823D-89D3-3E2E-15C2-661CDB0001EB}.Develop|x64.Build.0 = Develop|x64 {84F375C5-F73A-B81D-CB09-550FBC2BCBF9}.Develop|x64.ActiveCfg = Develop|x64 @@ -156,6 +164,8 @@ Global {2967F038-B90B-EBF5-B268-BE3BAF66D417}.Develop|x64.Build.0 = Develop|x64 {B2999D78-279A-1A53-CC82-74D494144722}.Develop|x64.ActiveCfg = Develop|x64 {B2999D78-279A-1A53-CC82-74D494144722}.Develop|x64.Build.0 = Develop|x64 + {EC638E2A-A355-0936-373E-A893B2B596DC}.Develop|x64.ActiveCfg = Develop|x64 + {EC638E2A-A355-0936-373E-A893B2B596DC}.Develop|x64.Build.0 = Develop|x64 {A950ABA2-0770-696C-6244-512CDCB2378A}.Develop|x64.ActiveCfg = Develop|x64 {A950ABA2-0770-696C-6244-512CDCB2378A}.Develop|x64.Build.0 = Develop|x64 {7186BCD3-4393-85B5-963F-880AC8A6F795}.Develop|x64.ActiveCfg = Develop|x64 @@ -168,8 +178,6 @@ Global {1BD1853E-C5E4-992D-7266-AA4AA72600AB}.Develop|x64.Build.0 = Develop|x64 {6805C141-3788-A994-7DCA-ADD6574D1386}.Develop|x64.ActiveCfg = Develop|x64 {6805C141-3788-A994-7DCA-ADD6574D1386}.Develop|x64.Build.0 = Develop|x64 - {EF1771A7-1C29-952D-C38C-5845D2AFAC62}.Develop|x64.ActiveCfg = Develop|x64 - {EF1771A7-1C29-952D-C38C-5845D2AFAC62}.Develop|x64.Build.0 = Develop|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -183,6 +191,7 @@ Global {086B9D7D-2973-47BD-8CF0-82BB5A9BFA55} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} {D2FD53CE-5F95-C3EC-13A1-11D91B9A412C} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} {23753351-8C67-4966-7E36-7F900FE18D1B} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} + {046236D4-E56A-9382-7F53-467FBDB243B5} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} {1026823D-89D3-3E2E-15C2-661CDB0001EB} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} {84F375C5-F73A-B81D-CB09-550FBC2BCBF9} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} {8667E717-B97C-935C-4FDF-2878AF7DAB1A} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} @@ -190,13 +199,13 @@ Global {E44F97F7-1DE3-A547-6B58-30AEE63F22F5} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} {2967F038-B90B-EBF5-B268-BE3BAF66D417} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} {B2999D78-279A-1A53-CC82-74D494144722} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} + {EC638E2A-A355-0936-373E-A893B2B596DC} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} {A950ABA2-0770-696C-6244-512CDCB2378A} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} {7186BCD3-4393-85B5-963F-880AC8A6F795} = {DEDA8889-2128-69C7-B2CC-3996BC8EB907} {B0AEF51E-FBD8-3472-DB40-2C819DE2E5DF} = {EEE587B4-691E-274F-5E0D-3D4754F2B4B6} {F8DBBBDB-3B80-B4F1-70A8-272978F579EB} = {EEE587B4-691E-274F-5E0D-3D4754F2B4B6} {1BD1853E-C5E4-992D-7266-AA4AA72600AB} = {EEE587B4-691E-274F-5E0D-3D4754F2B4B6} {6805C141-3788-A994-7DCA-ADD6574D1386} = {D19A19B1-8C4C-8963-0B32-A63B866BF960} - {EF1771A7-1C29-952D-C38C-5845D2AFAC62} = {D19A19B1-8C4C-8963-0B32-A63B866BF960} {AB6A8F06-D7BB-8801-F776-B07145542020} = {1A3E0FD4-F765-A5C3-A989-0F78B8FA23A3} {DEDA8889-2128-69C7-B2CC-3996BC8EB907} = {1A3E0FD4-F765-A5C3-A989-0F78B8FA23A3} {EEE587B4-691E-274F-5E0D-3D4754F2B4B6} = {1A3E0FD4-F765-A5C3-A989-0F78B8FA23A3} diff --git a/script/basic/library.lua b/script/basic/library.lua index 14bcb694..4d2cbccb 100644 --- a/script/basic/library.lua +++ b/script/basic/library.lua @@ -36,5 +36,9 @@ if qgetenv("QUANTA_DYNAMIC") then require("lsqlite") --lmdb require("lmdb") + --lminiz + require("lminiz") + --luaxml + require("luaxml") end end diff --git a/script/kernel/protobuf_mgr.lua b/script/kernel/protobuf_mgr.lua index 4b1c0919..5cf4d3da 100644 --- a/script/kernel/protobuf_mgr.lua +++ b/script/kernel/protobuf_mgr.lua @@ -77,7 +77,7 @@ function ProtobufMgr:load_protos() local proto_file = env_get("QUANTA_PROTO_FILE") if proto_file then if env_get("QUANTA_ZIP_MODE") then - protobuf.load(quanta.zload(proto_file)) + protobuf.load(zip.zload(proto_file)) log_debug("[ProtobufMgr][load_protos] load zip pb file: {}", proto_file) else protobuf.loadfile(proto_file) diff --git a/script/sandbox.lua b/script/sandbox.lua index 3beaf3c4..441fc8bb 100644 --- a/script/sandbox.lua +++ b/script/sandbox.lua @@ -10,7 +10,6 @@ local sgsub = string.gsub local sformat = string.format local traceback = debug.traceback local qgetenv = quanta.getenv -local zexist = quanta.zexist local LOG_LEVEL = log.LOG_LEVEL local QUANTA_ZIP = qgetenv("QUANTA_ZIP_MODE") @@ -66,7 +65,7 @@ end local function fexist(fname) if QUANTA_ZIP then - return zexist(fname) + return zip.zexist(fname) end local file = iopen(fname) if file then diff --git a/server/test.lua b/server/test.lua index 178ec159..3823fc5a 100644 --- a/server/test.lua +++ b/server/test.lua @@ -31,6 +31,7 @@ quanta.startup(function()--初始化test import("test/unqlite_test.lua") import("test/sqlite_test.lua") import("test/ssl_test.lua") + import("test/xml_test.lua") ]] - import("test/redis_test.lua") + import("test/xml_test.lua") end) diff --git a/server/test/xml_test.lua b/server/test/xml_test.lua new file mode 100644 index 00000000..dc2b2b80 --- /dev/null +++ b/server/test/xml_test.lua @@ -0,0 +1,113 @@ +--xml_test.lua +--luacheck: ignore 631 + +local log_dump = logger.dump + +local cxml = [[ + + + + Jäne.Roe@tübingen.com + 0.5.0 + 2004-11-23 - 2006-08-18 + a demonstration application for veLib Lua scripting + [ -i(ini.xml) ] + + + + + + veLua + 0 + 0.0 + 0 + 0 + 24 + 0 + + 800 + 600 + 0.5 0.6 0.7 + + + + 1.0 1.0 1.0 0.2 + 1.0 0.0 1.0 0.7 + 0.0 0.5 1.0 0.7 + 1.0 1.0 1.0 1.0 + + -1.0 + -1.0 + 1.0 + 1.0 + + + + 0 1 2 3 4 5 + 1 1 1 1 1 1 + 0 0 0 0 0 0 + + + + 0.1 + 2000 + -1.0 + 1.0 + -.75 + .75 + 1 + + + + + + + 1 + 330.0 + 1.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]] + +local xlua, err = xml.decode(cxml) +log_dump("luaxml decode err: {}, xml:{}", err, xlua) +local exml = xml.encode(xlua) +log_dump("luaxml encode xml:{}", exml) + +local xxlua = xml.decode(cxml) +local ok = xml.save("./bb.xml", xxlua, 'xml version="1.0" encoding="gbk"') +log_dump("luaxml save xml:{}", ok) +local flua, ferr = xml.open("./bb.xml") +log_dump("luaxml open err: {}, xml:{}", ferr, flua) +