/usr/bin/rt2 is in rttool 1.0.3.0-4.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | #! /usr/bin/ruby
=begin
= NAME
rt2 - converter from RT to other mark-up language.
= SYNOPSIS
rt2 [-r <visitor>] [options] <file>
= DESCRIPTION
rt2 inputs from ((|<file>|)) and outputs in (({STDOUT})). you can
choose ((|<visitor>|)) to select output format. For example, use
"rt/rt2html-lib.rb" to turn it into HTML.
= OPTIONS
please check the output of
% rt2 --help
and
% rt2 -r rt/rt2html-lib.rb --help
= FILES
* ~/.rt2rc - User configuration file.
= SEE ALSO
ruby(1)
=end
require "kconv"
require "optparse"
require "rt/rtparser"
def Kconv.name2const(name)
case name
when "iso-2022-jp"
Kconv::JIS
when "euc-jp"
Kconv::EUC
when "shift_jis"
Kconv::SJIS
end
end
include RT
# global vars
$Visitor = nil
$RT2_Sub_OptionParser = nil
# local vars
include_path = []
with_part = []
output_file = nil
output_index = nil
out_code = nil
from_rto = nil
# user option
$DEFAULT_FORMAT_LIB = "rt/rt2txt-lib"
$RC = {}
# initialize OptionParser
ARGV.options = OptionParser.new("Usage: #{$0} [options] rt-file > output\n") do
|q|
q.version = "1.0.3"
q.on_head("global options:")
q.on("-rLIB", "--require=LIB",
String,
"choose format library.") do |i|
# require LIB
require i
if $Visitor_Class && !$Visitor
$Visitor = $Visitor_Class.new()
if $RT2_Sub_OptionParser
require $RT2_Sub_OptionParser
$RT2_Sub_OptionParser = nil
end
end
end
q.on("-oNAME",
String,
"indicate base name of output file") do |i|
output_file = i
end
q.on("--out-code=KCODE",
String,
"character encoding of output.(jis|euc|sjis)") do |i|
case i
when /sjis|shift-jis/i
out_code = "shift_jis"
when /jis|iso-2022-jp/i
out_code = "iso-2022-jp"
when /euc|euc-jp/i
out_code = "euc-jp"
end
end
q.on("-IPATH", "--include-path=PATH",
String,
"add PATH to list of include path") do |i|
# add to include path
include_path.unshift(i)
end
q.on_tail("--help",
"print this message") do
STDERR.print(q.to_s)
exit(0)
end
end # OptionParser.new
# require format lib implicitly
unless File.basename($0) == "rt2"
require "rt/" + File.basename($0) + "-lib.rb"
require $RT2_Sub_OptionParser if $RT2_Sub_OptionParser
# make visitor
$Visitor = $Visitor_Class.new()
end
begin
ARGV.parse!
rescue
STDERR.print("Error: " + $!.inspect + "\n")
STDERR.print(ARGV.options.to_s)
exit(1)
end
unless $Visitor_Class
require $DEFAULT_FORMAT_LIB
$Visitor = $Visitor_Class.new
end
# file base name setup
$Visitor.filename = output_file if output_file
# character encoding
if out_code
begin
$Visitor.charcode = out_code
rescue NameError
end
end
parsed = RTParser::parse(readlines.join)
# output
out = $Visitor.visit(parsed)
# character encoding convert
out = Kconv.kconv(out, Kconv.name2const(out_code), Kconv::AUTO) if out_code
if output_file
filename = output_file + "." + $Visitor.type::OUTPUT_SUFFIX
file = open(filename, "w")
file.print(out)
file.close
STDERR.print("#{$0}: output to #{filename}...\n")
else
print(out)
end
|