class Hsss::CSplit

Public Class Methods

new(files, opt={}) click to toggle source
Calls superclass method Hsss::COutput::new
# File lib/hsss.rb, line 117
    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

Public Instance Methods

iter_macro() click to toggle source
# File lib/hsss.rb, line 170
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) click to toggle source
# File lib/hsss.rb, line 136
def script_name_line(name)
  "char *#{name};"
end
script_string(name, script) click to toggle source
# File lib/hsss.rb, line 140
def script_string(name, script)
  "  //#{name}\n#{cquote(script, "  ")}"
end
to_s() click to toggle source
# File lib/hsss.rb, line 144
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 << iter_macro
  end
  
  out
end