Class: Hsss::CSplit
Constant Summary
Constants inherited
from COutput
Hsss::COutput::EXT
Instance Attribute Summary
Attributes inherited from COutput
#count_macro_name, #count_name, #hashes_struct, #iter_macro_name, #names_struct, #row_struct_name, #scripts_struct, #struct_name
Instance Method Summary
collapse
Methods inherited from COutput
#cased_prefix, #check_script, #count_macro, #cquote, #failed?
Constructor Details
#initialize(files, opt = {}) ⇒ CSplit
Returns a new instance of CSplit.
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/hsss.rb', line 128
def initialize(files, opt={})
super
@head= <<-EOS.gsub(/^ {8}/, '')
// don't edit this please, it was auto-generated by hsss
// https://github.com/slact/hsss
typedef struct {
%s
} #{struct_name};
EOS
@struct_fmt= <<-EOS.gsub(/^ {8}/, '')
#{@static}#{struct_name} %s = {
%s
};
EOS
end
|
Instance Method Details
#iter_macro ⇒ Object
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/hsss.rb', line 182
def iter_macro
if @include_iter_macro
macro = []
macro << "#define #{iter_macro_name}(script_src, script_name, script_hash) \\"
macro << "for((script_src)=(char **)&#{scripts_struct}, (script_hash)=(char **)&#{hashes_struct}, (script_name)=(char **)&#{names_struct}; (script_src) < (char **)(&#{scripts_struct} + 1); (script_src)++, (script_hash)++, (script_name)++) "
macro.join("\n")
else
""
end
end
|
#script_name_line(name) ⇒ Object
147
148
149
|
# File 'lib/hsss.rb', line 147
def script_name_line(name)
"char *#{name};"
end
|
#script_string(name, script) ⇒ Object
151
152
153
|
# File 'lib/hsss.rb', line 151
def script_string(name, script)
" //#{name}\n#{cquote(script, " ")}"
end
|
#to_s ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/hsss.rb', line 155
def to_s
out = ""
if @header_only
out << sprintf(@head, @struct.join("\n"))
out << "#{@static}#{struct_name} #{hashes_struct};\n" if hashes_struct
out << "#{@static}#{struct_name} #{names_struct};\n" if names_struct
out << "#{@static}#{struct_name} #{scripts_struct};\n" if scripts_struct
out << "const int #{@count_name};\n" if @include_count
out << iter_macro
else
out = ""
out << sprintf(@head, @struct.join("\n")) unless @data_only
if @scripts.count > 0
out << sprintf(@struct_fmt, hashes_struct, @hashed_table.map{|v|" \"#{v}\""}.join(",\n")) if hashes_struct
out << sprintf(@struct_fmt, names_struct, @name_table.map{|v|" \"#{v}\","}.join("\n")) if names_struct
out << sprintf(@struct_fmt, scripts_struct, @script_table.join(",\n\n")) if scripts_struct
else
out << "//no scrpts\n"
end
out << "const int #{@count_name}=#{@scripts.count};\n" if @include_count
out << count_macro
out << iter_macro
end
out
end
|