[#14133] Thread safe eRuby — Yoshinori Toki <toki@...>

土岐です。

20 messages 1999/05/05

[#14203] class def in class def — kikutani@...

きくたにです。なんか初歩的質問で恥ずかしいけど。

46 messages 1999/05/10
[#14205] Re: class def in class def — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/05/11

なひです.

[#14209] private inner class (Re: Re: class def in class def) — matz@... (Yukihiro Matsumoto) 1999/05/11

[#14210] Re: private inner class (Re: Re: class def in class def) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/05/11

なひです.

[#14211] Re: private inner class (Re: Re: class def in class def) — matz@... (Yukihiro Matsumoto) 1999/05/11

まつもと ゆきひろです

[#14214] Re: private inner class (Re: Re: class def in class def) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/05/11

なひです.

[#14216] Re: private inner class (Re: Re: class def in class def) — matz@... (Yukihiro Matsumoto) 1999/05/11

まつもと ゆきひろです

[#14228] Re: private inner class (Re: Re: class def in class def) — 中村暁史 <anakamur@...> 1999/05/12

[#14229] Re: private inner class (Re: Re: class def in class def) — Shugo Maeda <shugo@...> 1999/05/12

前田です。

[#14234] Re: private inner class (Re: Re: class def in class def) — Takayuki SAGIJIMA <sat@...> 1999/05/12

五樹島です。お世話になっております。

[#14237] Re: private inner class (Re: Re: class def in class def) — 中村暁史 <anakamur@...> 1999/05/12

[#14239] Re: private inner class (Re: Re: class def in class def) — hisanori@... 1999/05/12

松尾です。

[#14243] Re: private inner class (Re: Re: class def in class def) — a1602hi@... 1999/05/12

石橋秀仁です. はじめまして.

[#14244] Re: private inner class (Re: Re: class def in class def) — Shugo Maeda <shugo@...> 1999/05/12

前田です。

[#14282] What's |n| ? — Kohji IKEDA <kid@...>

はじめまして、池田@ソフトサイエンスです。

23 messages 1999/05/13
[#14288] Re: What's |n| ? — Tomoyuki Kosimizu <greentea@...2.so-net.ne.jp> 1999/05/13

From: Kohji IKEDA <kid@mwc.biglobe.ne.jp>

[#14289] Re: What's |n| ? — Kohji IKEDA <kid@...> 1999/05/13

ども、池田@ソフトサイエンスです。

[#14336] archive.rb — Takashi Nishimoto <g96p0935@...>

必要のため、統合アーカイバを書いてみました。

19 messages 1999/05/15

[#14379] Ruby as the First Language — Hideto Ishibashi <a1602hi@...>

石橋秀仁です.

17 messages 1999/05/18

[#14417] はじめまして — Kenji Horikoshi <k-horix@...>

はじめまして,堀越と申します.

12 messages 1999/05/21

[#14428] sort — Koyama Hideo<fa8h-kym@...>

もとcobol屋の小山と申します。

18 messages 1999/05/22

[#14441] ConditionVariable (thread.rb) — SEKI <m_seki@...>

44 messages 1999/05/23
[#14445] Re: ConditionVariable (thread.rb) — SEKI <m_seki@...> 1999/05/23

[#14472] Re: ConditionVariable (thread.rb) — Shin-ichiro Hara <sinara@...> 1999/05/24

原です。

[#14473] Re: ConditionVariable (thread.rb) — Shugo Maeda <shugo@...> 1999/05/24

前田です。

[#14504] Re: ConditionVariable (thread.rb) — Shugo Maeda <shugo@...> 1999/05/25

前田です。

[#14509] Re: ConditionVariable (thread.rb) — Shin-ichiro Hara <sinara@...> 1999/05/25

原です。

[#14512] Re: ConditionVariable (thread.rb) — Shugo Maeda <shugo@...> 1999/05/25

前田です。

[#14807] ConditionVariable (again) — Shin-ichiro Hara <sinara@...> 1999/06/04

原です。

[#14809] Re: ConditionVariable (again) — Shin-ichiro Hara <sinara@...> 1999/06/04

原です。

[#14813] Re: ConditionVariable (again) — Shugo Maeda <shugo@...> 1999/06/04

前田です。

[#14513] Hater — cercine@... (Takashi Ikeda)

池田です。

144 messages 1999/05/25
[#14563] Re: Hater — Kenji Horikoshi <k-horix@...> 1999/05/26

こんにちは,堀越です.

[#14565] Re: Hater — Ataru NAKATA <anakata@...> 1999/05/26

中田@Vectorです。こんな話の時だけ。

[#14574] Re: Hater — Kenji Horikoshi <k-horix@...> 1999/05/26

こんにちは,堀越です.

[#14608] Re: Hater — 中村暁史 <anakamur@...> 1999/05/27

[#14624] Re: Hater — Kenji Horikoshi <k-horix@...> 1999/05/27

こんにちは,堀越です.

[#14635] Re: Hater — 中村暁史 <anakamur@...> 1999/05/28

[#14644] Teach PO first, then OO? (Re: Hater) — Hideto Ishibashi <s34204@...> 1999/05/28

石橋秀仁です.

[#14664] Re: Teach PO first, then OO? (Re: Hater) — Kenji Horikoshi <k-horix@...> 1999/05/28

こんにちは,堀越です.

[#14678] Re: Teach PO first, then OO? (Re: Hater) — Hideto Ishibashi <s34204@...> 1999/05/29

石橋秀仁です. こんにちは.

[#14680] Re: Teach PO first, then OO? (Re: Hater) — Koyama Hideo<fa8h-kym@...> 1999/05/29

もと、大型機使いの小山です。

[#14692] Re: Teach PO first, then OO? (Re: Hater) — 中村暁史 <anakamur@...> 1999/05/31

[#14695] Re: Teach PO first, then OO? (Re: Hater) — ARIMA Yasuhiro <fit0298@...> 1999/05/31

有馬@FITECです。

[#14703] Re: Teach PO first, then OO? (Re: Hater) — Koji Arai <JCA02266@...> 1999/05/31

新井です。

[#14706] Re: Teach PO first, then OO? (Re: Hater) — ARIMA Yasuhiro <fit0298@...> 1999/06/01

有馬@FITECです。

[#14526] Re: Hater — matz@... (Yukihiro Matsumoto) 1999/05/26

まつもと ゆきひろです

[#14533] Re: Hater — Katsuya Tanaka <tanaka@...> 1999/05/26

[#14537] 中学生に Ruby (Re: Re: Hater) — matz@... (Yukihiro Matsumoto) 1999/05/26

まつもと ゆきひろです

[#14553] Re: 中学生に Ruby (Re: Re: Hater) — Ryuichi Danno <daxanya@...4u.or.jp> 1999/05/26

だんのです。

[#14555] Re: 中学生に Ruby (Re: Re: Hater) — matz@... (Yukihiro Matsumoto) 1999/05/26

まつもと ゆきひろです

[#14557] Re: 中学生に Ruby (Re: Re: Hater) — 中村暁史 <anakamur@...> 1999/05/26

[#14558] Re: 中学生に Ruby (Re: Re: Hater) — Hideto Ishibashi <s34204@...> 1999/05/26

石橋秀仁%チュートリアル構想中です.

[#14572] Re: 中学生に Ruby (Re: Re: Hater) — gotoken@... (GOTO Kentaro) 1999/05/26

ごとけんです

[#14605] Re: 中学生に Ruby (Re: Re: Hater) — 中村暁史 <anakamur@...> 1999/05/27

[#14632] Re: 中学生に Ruby (Re: Re: Hater) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/05/28

なひです.

[#14636] Re: 中学生に Ruby (Re: Re: Hater) — Hideto Ishibashi <s34204@...> 1999/05/28

石橋秀仁です.

[#14665] Re: 中学生に Ruby (Re: Re: Hater) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/05/28

なひです.大学では自然言語処理や知識表現について研究しておりました.

[#14614] Re: 中学生に Ruby (Re: Re: Hater) — Hideto Ishibashi <s34204@...> 1999/05/27

石橋秀仁です.

[#14569] Re: 中学生に Ruby (Re: Hater) — Ryo HAYASAKA <hayasaka@...21.u-aizu.ac.jp> 1999/05/26

早坂@会津大学といいます。

[#14521] ruby の書き方 ? — goto@...

後藤@横河工事です。以前、ここでお世話になったおかげで、なんとか

20 messages 1999/05/26

[#14696] Ruby traps & tips — Akira Endo <akendo@...3.rim.or.jp>

遠藤です。

19 messages 1999/05/31

[ruby-list:14662] magic parser

From: gotoken@... (GOTO Kentaro)
Date: 1999-05-28 13:05:06 UTC
List: ruby-list #14662
ごとけんです

magic(5) のパーザーを書いてみました。ほんとは file(1) を
書こうと思ったんですけど力尽きました。だれか育てて下さい(__;;

クラス MagicFile

  MagicFile は magic(5) のパーザークラスです。

クラスメソッド
  new([filename])

  filename で与えられたファイルを読み、 MagicFile オブジェクトを返します。
  MagicFile オブジェクトは配列のように扱うことができ、この配列の各要素は、
  オフセット、型、テスト、メッセージ、追加テストの5つの要素からなる配列です。
  オフセット、型、テスト、メッセージは文字列で、追加テストは MagicFile と
  同じ構造の配列です。filename が与えられない場合は /etc/magic を読みます。

-- gotoken


#
# class MagicFile
#
#   MagicFile is a class as magic(5) parser. 
#
# class methods
#
#   new([filname])
#
#     Reads filename and return MagicFile object. A MagicFile object can be
#     treat as an array, which consists of arrays. Each member of MagicFile 
#     consists of five members -- offset, type, test, message and more test. 
#     Each of offset, type, test and message is a string. The more test is
#     an array which is structured as same as MagicFile.  If filename is 
#     omitted the /etc/magic is read. 
#

class MagicFile
  TraditionalMagicFile = "/etc/magic"

  def initialize(file = TraditionalMagicFile)
    if file.kind_of?(String)
      @file = open(File.expand_path(file)).read.split("\n").
	delete_if{|i| i =~ /^\s*(#.*)?$/} # delete comment or null line
    else
      raise ArgumentError.new("filename")
    end
    @magic = []

    pat = /^(>*)(.*)/
    shellword = /(?:[^\\\s]|\\.)+/
    level = 0
    stack = []

    @file.each_with_index do |line,nr|
      os, type, data, *msg = line.scan(shellword)
      message = msg.join(' ')
      lv, offset = os.scan(pat)[0]
      lv = lv.size

      cur = [offset, type, data, message, []]

      if lv == 0
	@magic.push(stack[0]) unless nr == 0  # push!!
	stack = [cur]
      elsif lv <= level + 1  # 0 < lv
	(level-lv+1).times{ stack.pop }
	stack[-1][-1].push cur
	stack.push cur
      else
	raise "`>' nest illegal"
      end

      level = lv
    end

    @magic.push(stack[0]) # push!!
  end
  
  def method_missing(mid, *arg, &blk)
    @magic.__send__(mid, *arg, &blk)
  end

  def a2s(ary, lv)
    if ary[4].empty?
      ">"*lv + ary[0..3].join("\t")
    else
      ">"*lv + ary[0..3].join("\t") + "\n" + 
	ary[4].filter{|i| a2s(i, lv+1)}.join("\n")
    end
  end

  def to_s
    @magic.collect{|i| a2s(i,0)}.join("\n")
  end
  private :a2s
end

if __FILE__ == $0
  magic = MagicFile.new
  print magic, "\n"
end

In This Thread

Prev Next