[#21736] OBJECTDAY 2000 — 助田 雅紀 <masaki.suketa@...>

助田です.

29 messages 2000/04/03
[#21748] Re: OBJECTDAY 2000 — keiju@... (石塚圭樹) 2000/04/04

けいじゅ@日本ラショナルソフトウェアです.

[#21753] Re: OBJECTDAY 2000 — Hideto ISHIBASHI <hideto-i@...4u.or.jp> 2000/04/05

石橋秀仁です。

[#21755] Re: OBJECTDAY 2000 — keiju@... (石塚圭樹) 2000/04/05

けいじゅ@日本ラショナルソフトウェアです.

[#21837] site_ruby & Linux distribution — OZAWA Sakuro <crouton@...>

小澤さくです。

14 messages 2000/04/10

[#21922] ruby-1.4.4 binary for BeOS 5 (Intel) — tenmei@... (Noriaki Harada)

はらだです。

23 messages 2000/04/15
[#21923] Re: ruby-1.4.4 binary for BeOS 5 (Intel) — NAITOH Jun <naitoh@...> 2000/04/15

はじめまして、内藤と申します。

[#21926] Re: ruby-1.4.4 binary for BeOS 5 (Intel) — tenmei@... (Noriaki Harada) 2000/04/16

>はじめまして、内藤と申します。

[#21930] Re: ruby-1.4.4 binary for BeOS 5 (Intel) — NAITOH Jun <naitoh@...> 2000/04/16

内藤です。

[#21968] Re: ruby-1.4.4 binary for BeOS 5 (Intel) — Katsuyuki Komatsu <komatsu@...> 2000/04/17

小松です。

[#21969] Re: ruby-1.4.4 binary for BeOS 5 (Intel) — NAITOH Jun <naitoh@...> 2000/04/17

再び内藤です。

[#21956] Thread & STDIN — Masato Toyoshima <mt@...>

はじめまして、豊島といいます。

16 messages 2000/04/17

[#21981] rd2man — WATANABE Hirofumi <eban@...>

わたなべです.

29 messages 2000/04/18
[#21982] Re: rd2man — Toshiro Kuwabara <toshirok@...3.so-net.ne.jp> 2000/04/18

Toshです。

[#21985] Re: rd2man — WATANABE Hirofumi <Hirofumi.Watanabe@...> 2000/04/19

わたなべです.

[#22036] Re: rd2man — Wakou Aoyama <wakou@...> 2000/04/20

青山です。

[#22040] Re: rd2man — Toshiro Kuwabara <toshirok@...3.so-net.ne.jp> 2000/04/21

Toshです。

[#22014] shell interactive — WATANABE Daisaku <dwata@...3.rim.or.jp>

31 messages 2000/04/20
[#22016] Re: shell interactive — 時田幸粋 <ktokita@...> 2000/04/20

こんにちは、時田です。

[#22017] Re: shell interactive — nobu.nakada@... 2000/04/20

なかだです。

[#22018] Re: shell interactive — WATANABE Hirofumi <Hirofumi.Watanabe@...> 2000/04/20

わたなべです.

[#22027] Re: shell interactive — 時田幸粋 <ktokita@...> 2000/04/20

こんにちは、時田です。

[#22103] Please put ruby-1.4.4.tar.gz in pub/lang/ruby/1.4/ — "Akinori -Aki- MUSHA" <knu@...>

 お願いがあるのですが、 ruby-1.4.4.tar.gz を FTP ツリーの 1.4/

16 messages 2000/04/25
[#22199] Where to put ruby-i.j.k.tar.gz on? (Re: ) — SUGIHARA Hiroshi <maili31s@...> 2000/04/28

[ruby-list:22103]におきまして、2000/04/25 12:38ほどに、

[#22117] StateGraph: state machine interpreter — Hideto ISHIBASHI <hideto-i@...4u.or.jp>

石橋 "rubyholic" 秀仁です。

16 messages 2000/04/25

[#22159] $LOAD_PATH への追加について — "Sugawara Hajime" <sugawara@...>

 はじめまして、菅原@ホビー・データです。

13 messages 2000/04/27

[#22181] Can't Use optparse — Yamada Kenji <kyamada@...>

28 messages 2000/04/28
[#22186] Re: Can't Use optparse — akira yamada / やまだあきら <akira@...> 2000/04/28

[#22195] Re: Can't Use optparse — Toshiro Kuwabara <toshirok@...3.so-net.ne.jp> 2000/04/28

Toshです。

[#22261] Re: Can't Use optparse — nobu.nakada@... 2000/05/04

なかだです。

[#22264] Re: Can't Use optparse — Toshiro Kuwabara <toshirok@...3.so-net.ne.jp> 2000/05/04

Toshです。

[#22270] Re: Can't Use optparse — nobu.nakada@... 2000/05/04

なかだです。

[#22272] Re: Can't Use optparse — Toshiro Kuwabara <toshirok@...3.so-net.ne.jp> 2000/05/04

Toshです。

[#22300] Re: Can't Use optparse — Koji Arai <JCA02266@...> 2000/05/05

新井です。

[ruby-list:21981] rd2man

From: WATANABE Hirofumi <eban@...>
Date: 2000-04-18 16:24:06 UTC
List: ruby-list #21981
わたなべです.

漢ならやっぱ man だろ? ってことで rd2man です.
この程度で満足しちゃったので出します.
ちょっとあやしげではあるけど, それなりに nroff は理解してくます.

% rd2 -r rd2man hoge.rd > hoge.1
Linux の場合だと
% man ./hoge.1
で見れます. (./ がミソ)

=begin
= rd2man.rb
=end

require "rd/rdvisitor"

module RD
  class RD2MANVisitor < RDVisitor
    include AutoLabel
    include MethodParse

    # must-have constants
    OUTPUT_SUFFIX = "1"
    INCLUDE_SUFFIX = ["1"]

    def initialize
      @enumcounter = 0
    end

    def visit(tree)
      prepare_labels(tree, "")
      super(tree)
    end

    def apply_to_DocumentElement(element, content)
      content = content.join
      title = @filename || ARGF.filename || "Untitled"
      <<"EOT"
.\" DO NOT MODIFY THIS FILE! it was generated by rd2
.TH #{title} 1 "#{Time.now.strftime '%B %Y'}"
#{content}
EOT
    end

    def apply_to_Headline(element, title)
      ".SH #{title}.PP\n"
    end

    # RDVisitor#apply_to_Include

    def apply_to_TextBlock(element, content)
      content.join
    end

    def apply_to_Verbatim(element)
      content = []
      element.each_line do |i|
	content.push(apply_to_String(i))
      end
      # Can we use BLOCKQUOTE such like?
      %Q[.nf\n\\&    #{content.join("\\&    ")}.fi\n]
    end

    def apply_to_ItemList(element, items)
      items = items.join(".TP\n.B\n\\(bu ")
      ".TP\n.B\n\\(bu " + items
    end

    def apply_to_EnumList(element, items)
      @enumcounter = 0
      "\n" + items.join + "\n.PP\n"
    end

    def apply_to_DescList(element, items)
      items.join("\n")
    end

    def apply_to_MethodList(element, items)
      items.join("\n")
    end

    def apply_to_ItemListItem(element, content)
      content.join("\n")
    end

    def apply_to_EnumListItem(element, content)
      @enumcounter += 1
      %Q[.IP #{@enumcounter}.\n#{content.join("\n")}]
    end

    def apply_to_DescListItem(element, term, description)
      anchor = refer(element)
      if description.empty?
	"\n.TP\n.fi\n.B\n#{term}"
      else
        %[\n.TP\n.fi\n.B\n#{term}\n#{description.join("\n")}]
      end
    end

    def apply_to_MethodListItem(element, term, description)
      term = parse_method(term)  # maybe: term -> element.term
      anchor = refer(element)
      if description.empty?
	"\n.TP\n.fi\n.B\n#{term}"
      else
        %[\n.TP\n.fi\n.B\n#{term}\n#{description.join("\n")}]
      end
    end

    def parse_method(method)
      klass, kind, method, args = MethodParse.analize_method(method)
      
      if kind == :function
	klass = kind = nil
      else
	kind = MethodParse.kind2str(kind)
      end
      
      case method
      when "[]"
	args.strip!
	args.sub!(/^\((.*)\)$/, '\\1')
	"#{klass}#{kind}[#{args}]"
      when "[]="
	args.strip!
	args.sub!(/^\((.*)\)$/, '\\1')
	args, val = /^(.*),([^,]*)$/.match(args)[1,2]
	args.strip!
	val.strip!

	"#{klass}#{kind}[#{args}] = #{val}"
      else
	"#{klass}#{kind}#{method}#{args}"
      end
    end
    private :parse_method

    def apply_to_StringElement(element)
      apply_to_String(element.content)
    end

    def apply_to_Emphasis(element, content)
      %Q[\\fI#{content.join}\\fP]
    end

    def apply_to_Code(element, content)
      %{\\fB#{content.join}\\fP}
    end

    def apply_to_Var(element, content)
      content.join
    end

    def apply_to_Keyboard(element, content)
      content.join
    end

    def apply_to_Index(element, content)
      tmp = []
      element.each do |i|
	tmp.push(i) if i.is_a?(String)
      end
      key = meta_char_escape(tmp.join)
      if @index.has_key?(key)
	# warning?
	""
      else
	num = @index[key] = @index.size
	content.join
      end
    end

    def apply_to_Reference(element, content)
      case element.label
      when Reference::URL
	apply_to_RefToURL(element, content)
      when Reference::RDLabel
	if element.label.filename
	  apply_to_RefToOtherFile(element, content)
	else
	  apply_to_RefToElement(element, content)
	end
      end
    end

    def apply_to_RefToElement(element, content)
      content = content.join
      content.sub(/^function#/, "")
    end

    def apply_to_RefToOtherFile(element, content)
      content.join
    end
  
    def apply_to_RefToURL(element, content)
      content.join
    end

    def apply_to_Footnote(element, content)
      ""
    end

    def apply_to_Verb(element)
      apply_to_String(element.content)
    end

    def apply_to_String(element)
      meta_char_escape(element)
    end

    def meta_char_escape(str)
      str.gsub(/[-\\]/, '\\\\\\&').gsub(/^[.']/, '\\&')
    end
    private :meta_char_escape

  end # RD2MANVisitor
end # RD

$Visitor_Class = RD::RD2MANVisitor

=begin
== script info.
 RD to MAN translate library for rdfmt.rb
 $Id$

== changes
:0.1.0 (2000/04/09)
  * first release version
=end

In This Thread

Prev Next