Top Level Namespace

Defined Under Namespace

Classes: Addrinfo, BasicSocket, IPSocket, SOCKSSocket, Socket, TCPServer, TCPSocket, UDPSocket, UNIXServer, UNIXSocket

Constant Summary collapse

C_ESC =
{
  "\\" => "\\\\",
  '"' => '\"',
  "\n" => '\n',
}
C_ESC_PAT =
Regexp.union(*C_ESC.keys)
COMMENTS =
Hash.new { |h, name| h[name] = name }
DEFS =
h.to_a
NAME_TO_INT_DEFS =
[]
INTERN_DEFS =
[]

Instance Method Summary collapse

Instance Method Details

#c_str(str) ⇒ Object



31
32
33
# File 'mkconstants.rb', line 31

def c_str(str)
  '"' + str.gsub(C_ESC_PAT) {|s| C_ESC[s]} + '"'
end

#def_intern(func_name, pat, prefix_optional = nil) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'mkconstants.rb', line 238

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) ⇒ Object



195
196
197
198
199
# File 'mkconstants.rb', line 195

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_constObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'mkconstants.rb', line 57

def each_const
  DEFS.each {|name, default_value|
    if name =~ /\AINADDR_/
      make_value = "UINT2NUM"
    else
      make_value = "INT2NUM"
    end
    guard = nil
    if /\A(AF_INET6|PF_INET6|IPV6_.*)\z/ =~ name
      # IPv6 is not supported although AF_INET6 is defined on bcc32/mingw
      guard = "defined(INET6)"
    end
    yield guard, make_value, name, default_value
  }
end

#each_name(pat) ⇒ Object



73
74
75
76
77
78
# File 'mkconstants.rb', line 73

def each_name(pat)
  DEFS.each {|name, default_value|
    next if pat !~ name
    yield name
  }
end

#each_names_with_len(pat, prefix_optional = nil) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'mkconstants.rb', line 122

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) ⇒ Object



115
116
117
118
119
120
# File 'mkconstants.rb', line 115

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) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
# File 'mkconstants.rb', line 201

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