[#6219] Ruby連載 第4話 — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

32 messages 1998/02/04
[#6221] Re: Ruby連載 第4話 — Shin-ichiro HARA <sinara@...> 1998/02/04

原です。

[#6224] Re: Ruby連載 第4話 — Yasunari Momoi <conan@...> 1998/02/04

ももちゃん@あるもにこすです.

[#6225] Re: Ruby連載 第4話 — matz@... (Yukihiro Matsumoto) 1998/02/04

まつもと ゆきひろです

[#6249] Re: i++ — 助田 雅紀 <masaki.suketa@...>

助田です。

33 messages 1998/02/04
[#6252] Re: i++ — gotoken@... (GOTO Kentaro) 1998/02/05

ことけんです

[#6255] Re: i++ — matz@... (Yukihiro Matsumoto) 1998/02/05

まつもと ゆきひろです

[#6260] Re: i++ — Yuji Shigehiro <sigehiro@...> 1998/02/05

しげひろです.

[#6314] RE: ruby's design policy (Re: I'd like to subscr ibe this ML) — 助田 雅紀 <masaki.suketa@...>

オブジェクト指向周辺をぶらぶらしている助田です。

11 messages 1998/02/06

[#6333] ruby 流に添削して下さい — nkon@...2.3web.ne.jp

13 messages 1998/02/07
[#6335] Re: ruby 流に添削して下さい — OZAWA Sakuro <crouton@...> 1998/02/07

さくです.

[#6372] ruby 1.1b7 released — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

24 messages 1998/02/10
[#6402] parsedate (Re: ruby 1.1b7 released) — WATANABE Hirofumi <watanabe@...> 1998/02/13

わたなべです.

[#6405] Re: parsedate (Re: ruby 1.1b7 released) — Tadayoshi Funaba <tadf@...> 1998/02/13

ふなばです。

[#6407] Re: parsedate (Re: ruby 1.1b7 released) — matz@... (Yukihiro Matsumoto) 1998/02/13

まつもと ゆきひろです

[#6373] call for scripts — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

133 messages 1998/02/10
[#6414] Re: call for scripts — Terutuoshi Kaneshiro <k-teru@...06.odn.ne.jp> 1998/02/14

金城です.

[#6428] Re: call for scripts — matz@... (Yukihiro Matsumoto) 1998/02/16

まつもと ゆきひろです

[#6448] Re: call for scripts — Terutuoshi Kaneshiro <k-teru@...06.odn.ne.jp> 1998/02/16

金城です.

[#6452] Re: call for scripts — matz@... (Yukihiro Matsumoto) 1998/02/17

まつもと ゆきひろです

[#6481] Re: call for scripts — Kikutani Makoto <kikutani@...> 1998/02/17

きくたに@ぷ〜たろ〜です。

[#6483] Re: call for scripts — OZAWA Sakuro <crouton@...> 1998/02/17

さくです.

[#6495] Re: call for scripts — WATANABE Hirofumi <watanabe@...> 1998/02/18

わたなべです.

[#6416] Re: call for scripts — shugo@... (Shugo Maeda) 1998/02/14

前田です。

[#6417] rgrep (Re: call for scripts) — shugo@... (Shugo Maeda) 1998/02/15

前田です。

[#6423] Re: rgrep (Re: call for scripts) — matz@... (Yukihiro Matsumoto) 1998/02/16

まつもと ゆきひろです

[#6612] Re: call for scripts — Tadayoshi Funaba <tadf@...> 1998/02/21

ふなばです。

[#6582] File::Separator on cygwin — OZAWA Sakuro <ozawa@...>

小澤さくです。

19 messages 1998/02/20
[#6583] Re: File::Separator on cygwin — WATANABE Hirofumi <watanabe@...> 1998/02/20

わたなべです.

[#6586] Re: File::Separator on cygwin — OZAWA Sakuro <ozawa@...> 1998/02/20

小澤さくです。

[#6591] ruby 1.1b8 released — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

32 messages 1998/02/20
[#6620] rbc.rb and binding — shugo@... (Shugo Maeda) 1998/02/22

前田です。

[#6629] Re: rbc.rb and binding — keiju@... (石塚圭樹 ) 1998/02/23

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

[#6643] Re: rbc.rb and binding — shugo@... (Shugo Maeda) 1998/02/23

前田です。

[#6649] Re: rbc.rb and binding — keiju@... (石塚圭樹 ) 1998/02/23

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

[#6650] Re: rbc.rb and binding — matz@... (Yukihiro Matsumoto) 1998/02/23

まつもと ゆきひろです

[#6667] JRI 0.5 worked (was Re: rbc.rb and binding) — OZAWA Sakuro <crouton@...> 1998/02/23

さくです.

[#6687] Re: JRI 0.5 worked (was Re: rbc.rb and binding) — shugo@... (Shugo Maeda) 1998/02/24

前田です。

[#6712] JRI and JDBC — OZAWA Sakuro <ozawa@...> 1998/02/24

小澤さくです。

[#6635] hello — WATANABE Tetsuya <tetsu@...>

渡辺哲也と申します。

15 messages 1998/02/23

[#6706] Re: Counter class — toyofuku@...

豊福@パパイヤです。

12 messages 1998/02/24

[#6735] Mutex/ConditionVariable/Queue — shugo@... (Shugo Maeda)

前田です。

27 messages 1998/02/24
[#6746] Re: Mutex/ConditionVariable/Queue — keiju@... (石塚圭樹 ) 1998/02/25

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

[#6747] Re: Mutex/ConditionVariable/Queue — shugo@... (Shugo Maeda) 1998/02/25

前田です。

[#6752] Re: Mutex/ConditionVariable/Queue — senda@... 1998/02/25

From: shugo@po.aianet.ne.jp (Shugo Maeda)

[#6754] Re: Mutex/ConditionVariable/Queue — shugo@... (Shugo Maeda) 1998/02/25

前田です。

[#6756] Re: Mutex/ConditionVariable/Queue — senda@... 1998/02/25

From: shugo@po.aianet.ne.jp (Shugo Maeda)

[#6786] Re: Mutex/ConditionVariable/Queue — senda@...

From: shugo@po.aianet.ne.jp (Shugo Maeda)

33 messages 1998/02/26
[#6791] Re: Mutex/ConditionVariable/Queue — shugo@... (Shugo Maeda) 1998/02/26

前田です。

[#6794] Re: Mutex/ConditionVariable/Queue — shugo@... (Shugo Maeda) 1998/02/26

前田です。

[#6796] Re: Mutex/ConditionVariable/Queue — keiju@... (石塚圭樹 ) 1998/02/26

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

[ruby-list:6851] again hd.rb

From: WATANABE Tetsuya <tetsu@...>
Date: 1998-02-28 08:41:31 UTC
List: ruby-list #6851
Ruby を書きはじめてまるまる 1 週間たちました。この一週
間、Ruby らしく? 書けるようにと(まだまだですが)。

自分なりにはちょっとよくなったと思う hd.rb (hex dump) 
ですが、みなさんの意見を聞かせていただけませんか?

課題としては、「bin_to_str」を汎用的にする(イニシャラ
イズの点など <- グローバル変数を使用している)というも
のがあるのですが... (再利用するかな?)

組み込みの kconv は、入力がきれい? な場合にはいいので
すが、いきなりバイナリを読ませてしまうと、後の処理がう
まく行かないようなので、正規表現で対象を限定しています。

この正規表現部分は、漢字コードとしての定義的には含まれ
る部分でも、実際に変換した後いろいろなコマンド(おもに
表示のための less)の対応などから若干範囲を狭くしていま
す。文字が表示される範囲(フォントが用意されている範囲?)
に対しては抜けがないとは思います。Mule の 
tm(tiny-mime) などは、もう少し範囲を限定した方がよさそ
うです(この部分もどうしたものかと思っていますが)。

ということで、お時間がありましたら試してみていただけま
せんでしょうか?

オプション

-s     入力を SJIS として処理
-S     出力漢字コードを SJIS に
-e     入力を EUC として処理   デフォルト
-E     出力漢字コードを EUC に デフォルト
-数字  ファイルの hex dump 表示をはじめるオフセット指定
       -0x「16 進文字列」 で 16 進数指定可能
       -0「8 新文字列」で 8 進数指定可能

------------------------------
#! /usr/local/bin/ruby
# /home/tetsu/src/ruby/hd.rb
# Created: February 22,1998 Sunday 18:39:06
# Author: tetsu(WATANABE Tetsuya)
# $Id: hd.rb,v 1.8 1998/02/28 07:58:00 tetsu Exp $
# usage:

require "kconv"
include Kconv

def usage
  STDERR.print <<E
usage: #$0 [-seSE] [-(num|0xhex|0oct)] [files ...]
 -[0-9]+  offset
 -0[0-7]+          octal
 -0x[0-9a-fA-F]+   hex
 -s     sjis/input code
 -e     euc /input code
 -S     sjis/output code
 -E     euc /output code (default)
E
  exit 1
end

def hd(f, offset)
  f.pos = offset if offset > 0 and f != STDIN

  while $_ = f.read(16) and $_.length == 16
    bin = $_.unpack('N4')

    printf("%8.8x  %8.8x %8.8x %8.8x %8.8x", offset, *bin);
    print '  ', $_.tr("\000-\037\177", '.').bin_to_str, "\n";

    offset += 16
  end

  if $_ and $_.length > 0
    bin = $_.unpack('C*')

    bin.each_index { |i|
      bin[i] = sprintf('%2.2x', bin[i])
    }

    for i in bin.length .. 16 - 1
      bin.push('  ')
    end

    printf("%8.8x  %s%s%s%s %s%s%s%s %s%s%s%s %s%s%s%s", offset, *bin);
    print '  ', $_.tr("\000-\037\177", '.').bin_to_str, "\n";
  end
end

class String
  def bin_to_str
    w = ($kanji_chip + self).gsub($kanji_re) {
      Kconv.kconv($1, Kconv::JIS, $in_kanji_code)
    }.gsub($kana_re) {
      Kconv.kconv($1, Kconv::JIS, $in_kanji_code)
    }

    w[0,1] = '' if $kanji_chip == w[0,1]

    $kanji_chip = if $kanji_chip_re =~ w[-1,1]; w[-1,1] else nil end

    Kconv.kconv(w.tr("\200-\377", '.'), $out_kanji_code, Kconv::JIS)
  end
end

$in_kanji_code = Kconv::EUC
$out_kanji_code = Kconv::EUC

offset = 0

while $_ = ARGV[0] and /^-/
  ARGV.shift
  if /[se]/i
    $in_kanji_code   = if /s/; Kconv::SJIS elsif /e/; Kconv::EUC end
    $out_kanji_code  = if /S/; Kconv::SJIS elsif /E/; Kconv::EUC end
  elsif /^-0([0-7]+)$/
    offset = $1.oct
  elsif /^-0x([\da-fA-F]+)$/
    offset = $1.hex
  elsif /^-(\d+)$/
    offset = $1.to_i
  else
    usage
  end
end

if $in_kanji_code == Kconv::EUC
  $kanji_re = /((?:[\241-\376][\241-\376])+)/n
  $kana_re = /((?:\216[\241-\337])+)/n
  $kanji_chip_re = /^[\216\241-\376]$/n
else
  $kanji_re = /((?:[\201-\237\340-\357][\100-\176\200-\374])+)/n
  $kana_re = /([\241-\337]+)/n
  $kanji_chip_re = /^[\201-\237\340-\357]$/n
end

if ARGV.length == 0
  hd(STDIN, 0)			# non offset
else
  while file = ARGV.shift
    f = File.open(file)
    hd(f, offset)
    f.close
  end
end

exit
------------------------------

--
WATANABE Tetsuya HP Japan PSO
e-mail  tetsu@jpn.hp.com

In This Thread

Prev Next