summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2006-07-10 00:32:57 +0000
committermurphy <murphy@rubychan.de>2006-07-10 00:32:57 +0000
commit9f4c7ab7553f9be7c9d14da0ba7462ad746c2f5d (patch)
tree686ee95cc9010314278846936476d1cf0bf04353 /bin
parent42436798565c36a7d9582fcf587946d273083ab1 (diff)
downloadcoderay-9f4c7ab7553f9be7c9d14da0ba7462ad746c2f5d.tar.gz
Big re-indenting - no more tabs!
Diffstat (limited to 'bin')
-rw-r--r--bin/coderay110
1 files changed, 54 insertions, 56 deletions
diff --git a/bin/coderay b/bin/coderay
index e0a4788..9c6b026 100644
--- a/bin/coderay
+++ b/bin/coderay
@@ -1,18 +1,18 @@
#!/usr/bin/env ruby
# CodeRay Executable
-#
+#
# Version: 0.1
# Author: murphy
def err msg
- $stderr.puts msg
+ $stderr.puts msg
end
begin
- require 'coderay'
+ require 'coderay'
- if ARGV.empty?
- puts <<-USAGE
+ if ARGV.empty?
+ puts <<-USAGE
CodeRay #{CodeRay::Version} (http://rd.cYcnus.de/coderay)
Usage:
coderay -<lang> [-<format>] < file > output
@@ -20,60 +20,58 @@ Usage:
Example:
coderay -ruby -statistic < foo.rb
coderay codegen.c # generates codegen.c.html
- USAGE
- end
-
- first, second = ARGV
+ USAGE
+ end
- 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
- puts 'No lang/file given.'
- exit 1
- end
+ first, second = ARGV
- if second
- if second[/-(\w+)/] == second
- format = $1.to_sym
- else
- raise 'Invalid format (must be -xxx).'
- end
- else
- $stderr.puts 'No format given; setting to default (HTML Page)'
- format = :page
- end
+ 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
+ puts 'No lang/file given.'
+ exit 1
+ end
- output = tokens.encode format
- out = $stdout
- if output_filename
- output_filename += '.' + CodeRay::Encoders[format]::FILE_EXTENSION
- if File.exist? output_filename
- err 'File %s already exists.' % output_filename
- exit
- else
- out = File.open output_filename, 'w'
- end
- else
-
- end
- out.print output
+ if second
+ if second[/-(\w+)/] == second
+ format = $1.to_sym
+ else
+ raise 'Invalid format (must be -xxx).'
+ end
+ else
+ $stderr.puts 'No format given; setting to default (HTML Page)'
+ format = :page
+ end
+
+ output = tokens.encode format
+ out = $stdout
+ if output_filename
+ output_filename += '.' + CodeRay::Encoders[format]::FILE_EXTENSION
+ if File.exist? output_filename
+ err 'File %s already exists.' % output_filename
+ exit
+ else
+ out = File.open output_filename, 'w'
+ end
+ end
+ out.print output
rescue => boom
- err "Error: #{boom.message}\n"
- err boom.backtrace
- err '-' * 50
- err ARGV.options
- exit 1
+ err "Error: #{boom.message}\n"
+ err boom.backtrace
+ err '-' * 50
+ err ARGV.options
+ exit 1
end