[#8815] Segfault in libc strlen, via rb_str_new2 — "Sean E. Russell" <ser@...>

Howdy,

12 messages 2006/09/09
[#8817] Re: Segfault in libc strlen, via rb_str_new2 — Eric Hodel <drbrain@...7.net> 2006/09/09

On Sep 8, 2006, at 10:10 PM, Sean E. Russell wrote:

Re: [PATCH] rdoc capture output (help message)

From: "greg weber" <eegreg@...>
Date: 2006-09-27 02:57:28 UTC
List: ruby-core #8937
there was a bug in original implementation.  attached is a new rdoc.rb diff

Greg Weber

Attachments (1)

rdoc_capture_outpur.diff (3.17 KB, text/x-diff)
--- /desktop/rdoc.rb	2006-09-26 21:51:35.609375000 -0500
+++ ./rdoc.rb	2006-09-26 21:44:02.546875000 -0500
@@ -203,6 +203,70 @@
       normalized_file_list(options, Dir.glob(File.join(dir, "*")), false, options.exclude)
     end
 
+    # --capture-output option: capture resulting output from script execution
+    # to run rdoc in a directory and capture the help infromation for only files containing 'optparse'
+    # and place that infromation below the current rdoc header, use the following:
+    # rdoc -C arg=--help,header=Usage,pos=bot,trigger="(require|load).*optparse"
+    def capture_output(filename, content, options)
+
+      # determine the start and finish of the rdoc header documentation
+      # then we can place the help_doc before, after, or overriding it
+      rdoc_start, rdoc_finish = nil, nil
+      content = content.to_a
+      return content.to_s unless content.each_with_index do |line, index|
+        next if index == 0 and line =~ /^#\!/
+
+        if rdoc_start.nil?
+          break true unless line =~ /(^#)|(^\s*$)/
+          rdoc_start = index if $1
+
+        elsif rdoc_finish.nil?
+          if line =~ /^[^#]/
+            rdoc_finish = index
+            break true unless options[:trigger]
+          end
+
+        elsif line =~ options[:trigger]
+          break true
+        end
+      end
+
+      # in this case there is no rdoc header
+      if rdoc_start.nil? 
+        rdoc_start = rdoc_finish = 0
+      end
+
+      # hack to fix a bug that I don't know why it occurs:
+      # there is no special rdoc formatting applied if there are spaces between the '#' and the text.
+      # remove one white space character
+      content[rdoc_start...rdoc_finish] = content[rdoc_start...rdoc_finish].map{|line| line.sub(/^#\s/, '#') }
+
+      # command to capture output from file.  Do not chomp the output.
+      command = "ruby #{filename} #{ options[:args] ? options[:args].join(' ') : '' }"
+
+      # remove one space for previously mentioned bug
+      # find given headers and insert '==' to make them appear as headers
+      if options[:headers]
+        headers = options[:headers]
+
+        help_doc = %x{ #{command} }.map do |line|
+          headers.reject! do |header|
+            line = "==#$1" << ($` or '') << "\n"   if line =~ /\s*(#{header})/
+          end
+
+          line.sub(/^\s?/, '#')
+        end
+
+      else
+        help_doc = %x{ #{command} }.map{ |line| line.sub(/^\s?/, '#') }
+      end
+
+      case options[:position] # default is :bottom
+        when :top      then (content[0...rdoc_start] + help_doc + content[rdoc_start..-1]).to_s
+        when :override then (help_doc + content[rdoc_finish..-1]).to_s
+        else                (content[0...rdoc_finish] + help_doc + content[rdoc_finish..-1]).to_s
+      end
+    end
 
     # Parse each file on the command line, recursively entering
     # directories
@@ -221,6 +285,8 @@
         
         content = File.open(fn, "r") {|f| f.read}
 
+        content = capture_output(fn, content, options.capture_output) if options.capture_output
+
         top_level = TopLevel.new(fn)
         parser = ParserFactory.parser_for(top_level, fn, content, options, @stats)
         file_info << parser.scan

In This Thread