summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorno author <noone@nowhere>2005-09-26 02:58:54 +0000
committerno author <noone@nowhere>2005-09-26 02:58:54 +0000
commit84b8431608174e74a4c0d2394eb330a6621bc74b (patch)
treeffc2bd7ce21708a9147247c80b0e7fc7728ea063 /bin
downloadcoderay-84b8431608174e74a4c0d2394eb330a6621bc74b.tar.gz
New Repository, initial import
Diffstat (limited to 'bin')
-rw-r--r--bin/coderay62
1 files changed, 62 insertions, 0 deletions
diff --git a/bin/coderay b/bin/coderay
new file mode 100644
index 0000000..d4239fd
--- /dev/null
+++ b/bin/coderay
@@ -0,0 +1,62 @@
+#!C:/ruby/bin/ruby
+
+# CodeRay Executable
+#
+# Version: 0.1
+# Author: murphy
+
+require 'optparse'
+
+def err msg
+ $stderr.puts msg
+end
+
+begin
+ require 'coderay'
+
+ if ARGV.empty?
+ puts <<-USAGE
+Usage:
+ 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
+ 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
+ else
+ file = lang
+ tokens = CodeRay.scan_file file
+ output_filename = file[0...-File.extname(file).size]
+ 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
+
+rescue => boom
+ err "Error: #{boom.message}\n"
+ err boom.backtrace
+ err '-' * 50
+ err ARGV.options
+ exit 1
+end