summaryrefslogtreecommitdiff
path: root/lib/rdoc
diff options
context:
space:
mode:
authorocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-08-29 10:56:05 +0000
committerocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-08-29 10:56:05 +0000
commit7c755d4174414e6ab7677736673092ba6f84357c (patch)
treef9dece92cd5fa5c9d3a04fe63af58136e202ae4b /lib/rdoc
parent6f23ba054a76fe13d2be54ddb86e42bb9f246964 (diff)
* lib/rdoc/usage.rb: improper exceptions. [ruby-dev:26870]
* lib/rdoc/usage.rb: support the case when non-ruby code exists before shebang. (this is needed when ri.bat is executed on windows) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc')
-rw-r--r--lib/rdoc/usage.rb37
1 files changed, 22 insertions, 15 deletions
diff --git a/lib/rdoc/usage.rb b/lib/rdoc/usage.rb
index 3e64cd6433..3a3718e2d3 100644
--- a/lib/rdoc/usage.rb
+++ b/lib/rdoc/usage.rb
@@ -128,24 +128,31 @@ module RDoc
# Find the first comment in the file (that isn't a shebang line)
# If the file doesn't start with a comment, report the fact
- # and return nil
+ # and return empty string
- def RDoc.find_comment(file)
- # skip leading blank lines and shebangs
- while line = file.gets
- break unless line =~ /^(#!|\s*$)/
+ def RDoc.gets(file)
+ if (line = file.gets) && (line =~ /^#!/) # shebang
+ throw :exit, find_comment(file)
+ else
+ line
end
+ end
- comment = []
+ def RDoc.find_comment(file)
+ catch (:exit) do
+ # skip leading blank lines
+ 0 while (line = gets(file)) && (line =~ /^\s*$/)
+
+ comment = []
+ while line && line =~ /^\s*#/
+ comment << line
+ line = gets(file)
+ end
- while line && line =~ /^\s*#/
- comment << line
- line = file.gets
+ 0 while line && (line = gets(file))
+ return no_comment if comment.empty?
+ return comment.join
end
-
- return no_comment if comment.empty?
-
- comment.join
end
@@ -167,7 +174,7 @@ module RDoc
if copy_upto_level && item.level >= copy_upto_level
copy_upto_level = nil
else
- if item.text[0].downcase == name
+ if item.text.downcase == name
result << item
copy_upto_level = item.level
end
@@ -191,7 +198,7 @@ module RDoc
# Report the fact that no doc comment count be found
def RDoc.no_comment
$stderr.puts "No usage information available for this program"
- nil
+ ""
end
end