Debian Codegraph @

CorsixTH/Bitmap/mkbootstrap.lua

raw
1 --[[
2 Copyright (c) 2010 Peter "Corsix" Cawley
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE. --]]
21
22 -- Create the data files
23 assert(loadfile((debug.getinfo(1, "S").source:match("@(.*[" .. package.config
24 :sub(1, 1) .. "])") or "") .. "mkfont.lua"))("bootstrap_font.bmp", 9, 12, 5)
25
26 -- Merge them into bootstrap.cpp
27 local lines = {}
28
29 local function merge(filename, globalname)
30 lines[#lines + 1] = "/* Data from " .. filename .. " inserted by mkbootstrap.lua: */"
31 lines[#lines + 1] = "const unsigned char " .. globalname .. "[] = {"
32 local f = assert(io.open(filename, "rb"))
33 while true do
34 local s = f:read(13)
35 if s == nil then
36 break
37 end
38 lines[#lines + 1] = s:gsub(".", function(c) return ("0x%.02X, "):format(c:byte()) end)
39 end
40 lines[#lines] = lines[#lines]:sub(1, -3)
41 f:close()
42 lines[#lines + 1] = "};"
43 end
44
45 local f, s, l = assert(io.lines("../Src/bootstrap.cpp"))
46 repeat
47 l = f(s, l)
48 lines[#lines + 1] = l
49 until l == "/* Start autogenerated content */"
50 merge("bootstrap_font.tab", "bootstrap_font_tab")
51 merge("bootstrap_font.dat", "bootstrap_font_dat")
52 merge("bootstrap_font.pal", "bootstrap_font_pal")
53 while l ~= "/* End autogenerated content */" do
54 l = f(s, l)
55 end
56 while l do
57 lines[#lines + 1] = l
58 l = f(s, l)
59 end
60
61 local linebreak = io.open("mkbootstrap.lua", "rb"):read(2000):match"[\r\n]+"
62 io.open("../Src/bootstrap.cpp", "wb"):write(table.concat(lines, linebreak))