16 CodeRay #{CodeRay::VERSION} (http://rd.cYcnus.de/coderay)
\r
18 coderay -<lang> [-<format>] < file > output
\r
19 coderay file [-<format>]
\r
21 coderay -ruby -statistic < foo.rb
\r
22 coderay codegen.c # generates codegen.c.html
\r
26 first, second = ARGV
\r
29 if first[/-(\w+)/] == first
\r
39 tokens = CodeRay.scan_file file
\r
40 output_filename, output_ext = file, /#{Regexp.escape(File.extname(file))}$/
\r
43 puts 'No lang/file given.'
\r
48 if second[/-(\w+)/] == second
\r
51 raise 'Invalid format (must be -xxx).'
\r
54 $stderr.puts 'No format given; setting to default (HTML Page)'
\r
58 # TODO: allow streaming
\r
60 output = CodeRay::Duo[lang => format].highlight input #, :stream => true
\r
62 output = tokens.encode format
\r
66 output_filename += '.' + CodeRay::Encoders[format]::FILE_EXTENSION
\r
67 if File.exist? output_filename
\r
68 err 'File %s already exists.' % output_filename
\r
71 out = File.open output_filename, 'w'
\r
77 err "Error: #{boom.message}\n"
\r