下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
#!/usr/bin/env lua--------------------------------------------------------------------------------- this LUA script is aim to generate include shutcut file in ./inc/-- First,it will find all *.h and *.hpp files in current path. Then,find out -- all class which defined in head file. Next,build a file in ./inc/ which be -- named with class name. Last,write "#include "./<headfile>"" into that file.-- auth : Chunjun li <[email protected]>-- date : 2013-10-02---------------------------------------------------------------------------------------------------------------------------------------------------------------- get_class_List_in_file-- \berif find all class which is defined in head file,and return class name -- table.-------------------------------------------------------------------------------function get_class_List_in_file(file_name) local class_List = {} local headfile = assert(io.open(file_name,"r")) while true do local line = headfile:read("*line") if line == nil then break end if string.find(line,"^class%s+") then if not string.find(line,"^class%s+%a[%w_]*%s*;$") then local _,_,class_name = string.find(line,"^class%s+(%a[%w_]*)") if class_name then table.insert(class_List,class_name) end end end end headfile:close() return class_Listend--------------------------------------------------------------------------------- build_class_include_file-- \berif build a file in ./inc/ and named as class name. then write C include -- statent insIDe.-------------------------------------------------------------------------------function build_class_include_file(class_name,file_name) local context = "#include \"../" .. file_name .. "\"\n" local outfile = assert(io.open("inc/" .. class_name,"a")) outfile:write(context) outfile:close()end--------------------------------------------------------------------------------- do_file-- \berif find classes and build class include files in ./inc/-------------------------------------------------------------------------------function do_file(file_name) class_List = get_class_List_in_file(file_name) for _,class_name in pairs(class_List) do build_class_include_file(class_name,file_name) print(class_name .. " --> " .. file_name) endend--------------------------------------------------------------------------------- scan_head_files-- \berif find all head file and run do_file() each-------------------------------------------------------------------------------function scan_head_files(path) local tmp_file_name = "head_file_List.tmp" local find_cmd = "find " .. path .. " -type f -name \"*.h\" -or -name \"*.hpp\" > " .. tmp_file_name os.execute "rm -rf ./inc" os.execute "mkdir ./inc" os.execute(find_cmd) local file = assert(io.open(tmp_file_name,"r")) while true do local line = file:read("*line") if line == nil then break end do_file(line) end file:close() os.remove(tmp_file_name)endscan_head_files("./")
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的自动生成类包含头文件全部内容,希望文章能够帮你解决自动生成类包含头文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)