Last active
November 20, 2020 19:08
-
-
Save x4fx77x4f/9246e07bbf3ea2aa3e43919cd6e62bcf to your computer and use it in GitHub Desktop.
Preprocessor and minifier for Quake/Source Engine .cfg files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env luajit | |
local input = arg[1] and io.open(arg[1], 'r') or io.stdin | |
local output = arg[2] and io.open(arg[2], 'w+') or io.stdout | |
local inbrace = false | |
local firstbrace = false | |
for line in input:lines() do | |
if line:find('^[ \t]*//') or line == '' then | |
-- skip | |
elseif inbrace then | |
local o = line:find('}') | |
if o then | |
output:write('"') | |
output:write(line:sub(o+1)) | |
output:write('\n') | |
inbrace = false | |
else | |
if not firstbrace then | |
output:write(';') | |
end | |
line = line:gsub('^[ \t]*', '') | |
output:write(line) | |
firstbrace = false | |
end | |
else | |
local o = line:find('{') | |
if o then | |
output:write(line:sub(1, o-1)) | |
output:write('"') | |
inbrace = true | |
firstbrace = true | |
else | |
output:write(line) | |
output:write('\n') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment