summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2005-10-04 04:04:07 +0000
committermurphy <murphy@rubychan.de>2005-10-04 04:04:07 +0000
commit48e144a20829faaeca9a7db8fbc6128f1f5d7297 (patch)
tree24326041ae8a5cc12a87ab96b8cdc67dba1e585e /bin
parent0ae9f844faf25d3be9f6fe5f8157f6bfebb30942 (diff)
downloadcoderay-48e144a20829faaeca9a7db8fbc6128f1f5d7297.tar.gz
Two new encoders: debug and xml.
encoder.rb: new token handling encoders/statistic.rb: using new handling ruby_helper.rb: small improvements ruby.rb: - escapes in subtoken - Float detection changed - some multi-char operators are now scanned as one token - def and module definition handling changed bin/coderay: improved, new interface (still in progress) plugin.rb: more expressive load error message
Diffstat (limited to 'bin')
-rw-r--r--bin/coderay44
1 files changed, 30 insertions, 14 deletions
diff --git a/bin/coderay b/bin/coderay
index d4239fd..a382a84 100644
--- a/bin/coderay
+++ b/bin/coderay
@@ -16,32 +16,48 @@ begin
if ARGV.empty?
puts <<-USAGE
+CodeRay #{CodeRay::Version} (http://rd.cYcnus.de/coderay)
Usage:
- coderay lang [format] < file > output
- coderay file [format]
+ coderay -lang [-format] < file > output
+ coderay file [-format]
USAGE
end
- unless format = ARGV[1]
- $stderr.puts 'No format given; setting to default (HTML)'
- format = :html
+ first, second = ARGV
+
+ if first
+ if first[/-(\w+)/] == first
+ lang = $1.to_sym
+ input = $stdin.read
+ tokens = CodeRay.scan input, lang
+ elsif first == '-'
+ lang = $1.to_sym
+ input = $stdin.read
+ tokens = CodeRay.scan input, lang
+ else
+ file = first
+ tokens = CodeRay.scan_file file
+ output_filename, output_ext = file, /#{Regexp.escape(File.extname(file))}$/
+ end
+ else
+ raise 'No lang/file given.'
end
- lang = ARGV[0] or raise 'No lang/file given.'
- if lang[/\A:(\w+)\z/]
- lang = $1.to_sym
- input = $stdin.read
- tokens = CodeRay.scan input, lang
+ if second
+ if second[/-(\w+)/] == second
+ format = $1.to_sym
+ else
+ raise 'Invalid format (must be -xxx).'
+ end
else
- file = lang
- tokens = CodeRay.scan_file file
- output_filename = file[0...-File.extname(file).size]
+ $stderr.puts 'No format given; setting to default (HTML)'
+ format = :html
end
output = tokens.encode format
out = $stdout
if output_filename
- output_filename << '.' << CodeRay::Encoders[format]::FILE_EXTENSION
+ output_filename.sub output_ext, CodeRay::Encoders[format]::FILE_EXTENSION
if File.exist? output_filename
err 'File %s already exists.' % output_filename
exit