Sha256: 66475d86035c502490ca72246f8d4622e67e75ce1ef77340a8158df5336a68aa

Contents?: true

Size: 1.38 KB

Versions: 41

Compression:

Stored size: 1.38 KB

Contents

c_file = File.read("ext/priority_queue/CPriorityQueue/priority_queue.c")
rb_file = File.read("lib/priority_queue/ruby_priority_queue.rb")

c_comments = Hash.new { "" }

c_file.scan(%r(/\*(.*?)\*/\s*static\s+\w+\s*pq_(\w+)\(.*?\))m).each do | match |
  c_comments[match[1]] = match[0].gsub(%r(\n\s*\* {0,1})m, "\n").strip
end

rb_comments = Hash.new { "" }

rb_file.scan(%r(((?:\n\s*#[^\n]*)*)\s*def\s+(\w+))m).each do | match |
  rb_comments[match[1]] = match[0].gsub(%r(\n\s*# {0,1})m, "\n").strip
end

add_comments = Hash.new

(rb_comments.keys + c_comments.keys).uniq.each do | key |
  #next if rb_comments[key].gsub(/\s+/m, " ") == c_comments[key].gsub(/\s+/m, " ")
  if c_comments[key].empty?
    add_comments[key] = rb_comments[key]
  elsif rb_comments[key].empty?
    add_comments[key] = c_comments[key]
  elsif rb_comments[key] != c_comments[key]

    puts key
    puts "Ruby"
    puts rb_comments[key]
    puts "C"
    puts c_comments[key]
    puts
    puts "Choose [c,r]"
    1 until /^([cr])/ =~ gets
    add_comments[key] = ($1 == "c" ? c_comments : rb_comments)[key]
    puts "-" * 80
    puts
  else
    add_comments[key] = rb_comments[key]
  end

end

File.open("lib/priority_queue/ruby_priority_queue.new.rb", "wb") do | o |
  o << 
    rb_file.gsub(%r(((?:\n\s*#[^\n]*)*)(\s*def\s+(\w+)))m) do | match |
      name, all =  $3, $2
      "\n" + (add_comments[name].gsub(/^/, "#")) + all
    end
end

Version data entries

41 entries across 41 versions & 8 rubygems

Version Path
auser-poolparty-1.3.0 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.1 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.10 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.11 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.12 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.13 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.14 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.15 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.16 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.17 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.2 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.3 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.4 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.5 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.6 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.7 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
auser-poolparty-1.3.8 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
fairchild-poolparty-1.3.17 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
fairchild-poolparty-1.3.5 vendor/gems/gratr/lib/priority-queue/compare_comments.rb
gratr19-0.4.4.1 lib/priority-queue/compare_comments.rb