prelude.c.tmpl: escape comments

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-12-01 04:27:32 +00:00
Родитель e4b67f7d74
Коммит a8a25b36f1
1 изменённых файлов: 7 добавлений и 5 удалений

Просмотреть файл

@ -9,6 +9,8 @@ class Prelude
LINE_LIMIT = 509 # by C89 LINE_LIMIT = 509 # by C89
C_ESC = { C_ESC = {
"/*" => "/\\*",
"*/" => "*\\/",
"\\" => "\\\\", "\\" => "\\\\",
'"' => '\"', '"' => '\"',
"\n" => '\n', "\n" => '\n',
@ -19,7 +21,7 @@ class Prelude
C_ESC_PAT = Regexp.union(*C_ESC.keys) C_ESC_PAT = Regexp.union(*C_ESC.keys)
def c_esc(str) def c_esc(str)
'"' + str.gsub(C_ESC_PAT) { C_ESC[$&] } + '"' str.gsub(C_ESC_PAT) { C_ESC[$&] }
end end
def prelude_base(filename) def prelude_base(filename)
filename.chomp(".rb") filename.chomp(".rb")
@ -83,7 +85,7 @@ Prelude.new(output && output[/\w+(?=_prelude.c\b)/] || 'prelude', ARGV, vpath).i
% preludes = @preludes.values.sort % preludes = @preludes.values.sort
% preludes.each {|i, prelude, lines, sub| % preludes.each {|i, prelude, lines, sub|
static const char prelude_name<%=i%><%=%>[] = <%=c_esc(prelude_name(*prelude))%><%=%>; static const char prelude_name<%=i%><%=%>[] = "<%=c_esc(prelude_name(*prelude))%>";
static const struct { static const struct {
% size = beg = 0 % size = beg = 0
% lines.each_with_index {|(line, comment), n| % lines.each_with_index {|(line, comment), n|
@ -100,15 +102,15 @@ static const struct {
% end % end
} prelude_code<%=i%><%=%> = { } prelude_code<%=i%><%=%> = {
% size = 0 % size = 0
#line 1 <%=c_esc(prelude)%> #line 1 "<%=c_esc(prelude)%>"
% lines.each_with_index {|(line, comment), n| % lines.each_with_index {|(line, comment), n|
% if size + line.size >= Prelude::LINE_LIMIT % if size + line.size >= Prelude::LINE_LIMIT
% size = 0 % size = 0
, ,
#line <%=n+1%> <%=c_esc(prelude)%> #line <%=n+1%> "<%=c_esc(prelude)%>"
% end % end
% size += line.size % size += line.size
<%=c_esc(line)%><%=%><%if comment%>/* <%=comment%> */<%end%> "<%=c_esc(line)%>"<%if comment%>/* <%=c_esc(comment)%> */<%end%>
% } % }
#line <%=_erbout.count("\n")+2%> "<%=@init_name%>.c" #line <%=_erbout.count("\n")+2%> "<%=@init_name%>.c"
}; };