1 -- Lua script used to clean up tabs and spaces in C, CPP and H files.
2 -- Copyright (c) 2014, bel
3 -- MIT License (http://opensource.org/licenses/mit-license.php)
5 -- It can be used from the command line:
6 -- Call Lua5.1 or Lua5.2 + this script file + the C/CPP/H file to clean
8 -- It can be used in Visual Studio as an external tool:
9 -- command: Lua5.1.exe or Lua5.2.exe
10 -- argument: "X:\civetweb\resources\cleanup.lua" $(ItemPath)
14 print("Cleaning " .. clean)
16 lines = io.lines(clean)
18 print("Can not open file " .. clean)
23 return s:match "^(.-)%s*$"
27 local tabspace = false
37 local lt = trimright(l)
42 local mcmt = l:find("%/%*");
45 print("line " .. lineno .. " nested comment")
47 if not (l:sub(mcmt):find("%*%/")) then
48 -- multiline comment begins here
52 if not l:find("^%s*%*") then
53 print("line " .. lineno .. " multiline comment without leading *")
55 if l:find("%*%/") then
59 local cmt = l:find("//")
60 if (cmt) and (l:sub(cmt-5, cmt+1) ~= "http://") and (l:sub(cmt-6, cmt+1) ~= "https://") then
61 print("line " .. lineno .. " has C++ comment //")
64 local lts = lt:gsub('\t', ' ')
70 local b = string.byte(lts,i)
71 if b<32 or b>=127 then
72 print("Letter " .. string.byte(l,i) .. " (" .. b .. ") found in line " .. lts)
77 newfile[#newfile + 1] = lts
80 print("Line endings trimmed: " .. tostring(lineend))
81 print("Tabs converted to spaces: " .. tostring(tabspace))
82 print("Invalid characters: " .. tostring(invalid))
85 local f = io.open(clean, "wb")