Support for the Ruby 2.4 series has ended. See here for reference.

In Files

  • socket/mkconstants.rb

Object

Public Instance Methods

c_str(str) click to toggle source
 
               # File socket/mkconstants.rb, line 32
def c_str(str)
  '"' + str.gsub(C_ESC_PAT) {|s| C_ESC[s]} + '"'
end
            
def_intern(func_name, pat, prefix_optional=nil) click to toggle source
 
               # File socket/mkconstants.rb, line 234
def def_intern(func_name, pat, prefix_optional=nil)
  prefix_pat = nil
  if prefix_optional
    if Regexp === prefix_optional
      prefix_pat = prefix_optional
    else
      prefix_pat = /\A#{Regexp.escape prefix_optional}/
    end
  end
  hash_var = "#{func_name}_hash"
  vardef = "static st_table *#{hash_var};"
  gen_hash = gen_int_to_name_hash(hash_var, pat, prefix_pat)
  decl = gen_int_to_name_decl(func_name, hash_var)
  func = gen_int_to_name_func(func_name, hash_var)
  INTERN_DEFS << [vardef, gen_hash, decl, func]
end
            
def_name_to_int(funcname, pat, prefix_optional, guard=nil) click to toggle source
 
               # File socket/mkconstants.rb, line 191
def def_name_to_int(funcname, pat, prefix_optional, guard=nil)
  decl = gen_name_to_int_decl(funcname, pat, prefix_optional, guard)
  func = gen_name_to_int_func(funcname, pat, prefix_optional, guard)
  NAME_TO_INT_DEFS << [decl, func]
end
            
each_const() click to toggle source
 
               # File socket/mkconstants.rb, line 58
def each_const
  DEFS.each {|name, default_value|
    guard = nil
    if /\A(AF_INET6|PF_INET6|IPV6_.*)\z/ =~ name
      # IPv6 is not supported although AF_INET6 is defined on mingw
      guard = "defined(INET6)"
    end
    yield guard, name, default_value
  }
end
            
each_name(pat) click to toggle source
 
               # File socket/mkconstants.rb, line 69
def each_name(pat)
  DEFS.each {|name, default_value|
    next if pat !~ name
    yield name
  }
end
            
each_names_with_len(pat, prefix_optional=nil) click to toggle source
 
               # File socket/mkconstants.rb, line 118
def each_names_with_len(pat, prefix_optional=nil)
  h = {}
  DEFS.each {|name, default_value|
    next if pat !~ name
    (h[name.length] ||= []) << [name, name]
  }
  if prefix_optional
    if Regexp === prefix_optional
      prefix_pat = prefix_optional
    else
      prefix_pat = /\A#{Regexp.escape prefix_optional}/
    end
    DEFS.each {|const, default_value|
      next if pat !~ const
      next if prefix_pat !~ const
      name = $'
      (h[name.length] ||= []) << [name, const]
    }
  end
  hh = {}
  h.each {|len, pairs|
    pairs.each {|name, const|
      raise "name crash: #{name}" if hh[name]
      hh[name] = true
    }
  }
  h.keys.sort.each {|len|
    yield h[len], len
  }
end
            
reverse_each_name(pat) click to toggle source
 
               # File socket/mkconstants.rb, line 111
def reverse_each_name(pat)
  DEFS.reverse_each {|name, default_value|
    next if pat !~ name
    yield name
  }
end
            
reverse_each_name_with_prefix_optional(pat, prefix_pat) click to toggle source
 
               # File socket/mkconstants.rb, line 197
def reverse_each_name_with_prefix_optional(pat, prefix_pat)
  reverse_each_name(pat) {|n|
    yield n, n
  }
  if prefix_pat
    reverse_each_name(pat) {|n|
      next if prefix_pat !~ n
      yield n, $'
    }
  end
end