Class: Hsss::CSplit
Constant Summary
Constants inherited
from COutput
Hsss::COutput::EXT
Instance Attribute Summary
Attributes inherited from COutput
#all_hashes_string_name, #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
#all_hashes_string_macro, #cased_prefix, #check_script, #count_macro, #cquote, #failed?
Constructor Details
#initialize(files, opt = {}) ⇒ CSplit
Returns a new instance of CSplit.
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/hsss.rb', line 140
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
195
196
197
198
199
200
201
202
203
204
|
# File 'lib/hsss.rb', line 195
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
159
160
161
|
# File 'lib/hsss.rb', line 159
def script_name_line(name)
"char *#{name};"
end
|
#script_string(name, script) ⇒ Object
163
164
165
|
# File 'lib/hsss.rb', line 163
def script_string(name, script)
" //#{name}\n#{cquote(script, " ")}"
end
|
#to_s ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/hsss.rb', line 167
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 << all_hashes_string_macro
out << count_macro
out << iter_macro
end
out
end
|