[#3747] constants (or class vriable?) — Wakou Aoyama <wakou@...>

青山です。

20 messages 1998/12/06
[#3751] Re: constants (or class vriable?) — Shin-ichro Hara <sinara@...> 1998/12/07

原です。

[#3763] Re: constants (or class vriable?) — Wakou Aoyama <wakou@...> 1998/12/07

青山です。

[#3764] Re: constants (or class vriable?) — matz@... (Yukihiro Matsumoto) 1998/12/08

まつもと ゆきひろです

[#3767] Re: constants (or class vriable?) — kjana@... (YANAGAWA Kazuhisa) 1998/12/08

In message <199812080034.JAA05946@picachu.netlab.co.jp>

[#3826] ruby 1.1d0 released — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

35 messages 1998/12/16

[#3873] (?: ) does not work? — shugo@... (MAEDA Shugo)

前田です。

15 messages 1998/12/19

[#3881] I want to catch all jump — shugo@... (Shugo Maeda)

前田です。

17 messages 1998/12/21
[#3895] Re: I want to catch all jump — matz@... (Yukihiro Matsumoto) 1998/12/22

まつもと ゆきひろです

[#3894] ruby 1.1d1 released — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

25 messages 1998/12/22

[#3899] interpreter reinitialization — shugo@... (Shugo Maeda)

前田です。

22 messages 1998/12/22
[#3923] Re: interpreter reinitialization — matz@... (Yukihiro Matsumoto) 1998/12/23

まつもと ゆきひろです

[#3926] Re: interpreter reinitialization — shugo@... (Shugo Maeda) 1998/12/23

前田です。

[#3931] Re: interpreter reinitialization — matz@... (Yukihiro Matsumoto) 1998/12/24

まつもと ゆきひろです

[#3956] Re: interpreter reinitialization — shugo@... (Shugo Maeda) 1998/12/24

前田です。

[#3960] Re: interpreter reinitialization — matz@... (Yukihiro Matsumoto) 1998/12/24

まつもと ゆきひろです

[#4002] config.guess — Koji Arai <JCA02266@...>

新井です。

24 messages 1998/12/26
[#4039] Re: config.guess — matz@... (Yukihiro Matsumoto) 1998/12/29

まつもと ゆきひろです

[#4045] Re: config.guess — Koji Arai <JCA02266@...> 1998/12/31

新井です。

[#4047] Re: config.guess — matz@... (Yukihiro Matsumoto) 1999/01/01

まつもと ゆきひろです

[#4048] Re: config.guess — Koji Arai <JCA02266@...> 1999/01/01

新井です。

[#4049] Re: config.guess — matz@... (Yukihiro Matsumoto) 1999/01/02

まつもと ゆきひろです

[#4050] Re: config.guess — Motoyuki Kasahara <m-kasahr@...> 1999/01/04

笠原です。

[#4030] module Precision — gotoken@... (GOTO Kentaro)

ごとけんです

78 messages 1998/12/28
[#4310] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/01/21

ごとけんです

[#4311] Re: module Precision — matz@... (Yukihiro Matsumoto) 1999/01/21

まつもと ゆきひろです

[#4312] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/01/21

ごとけんです

[#4317] Re: module Precision — keiju@... (石塚圭樹 ) 1999/01/21

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

[#4364] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/01/25

ごとけんです

[#4478] Re: module Precision — matz@... (Yukihiro Matsumoto) 1999/01/28

まつもと ゆきひろです

[#4506] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/01/30

ごとけんです

[#4552] Re: module Precision — matz@... (Yukihiro Matsumoto) 1999/02/01

まつもと ゆきひろです

[#4557] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/02/01

ごとけんです

[#4632] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/02/03

ごとけんです

[#4647] Re: module Precision — keiju@... (石塚圭樹 ) 1999/02/03

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

[#4648] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/02/03

ごとけんです

[#4633] Re: module Precision — matz@... (Yukihiro Matsumoto) 1999/02/03

まつもと ゆきひろです

[#4636] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/02/03

ごとけんです

[#4836] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/02/08

ごとけんです

[#4843] Re: module Precision — keiju@... (石塚圭樹 ) 1999/02/08

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

[#4849] Re: module Precision — gotoken@... (GOTO Kentaro) 1999/02/08

ごとけんです

[#4924] Re: module Precision — keiju@... (石塚圭樹 ) 1999/02/09

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

[#4976] a genericity — gotoken@... (GOTO Kentaro) 1999/02/10

ごとけんです

[#5008] Re: a genericity — keiju@... (石塚圭樹 ) 1999/02/11

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

[#5018] Re: a genericity — gotoken@... (GOTO Kentaro) 1999/02/11

ごとけんです

[#5171] Re: a genericity — keiju@... (石塚圭樹 ) 1999/02/16

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

[ruby-dev:3783] Re: pack("M")/unpack("M")

From: shugo@... (MAEDA Shugo)
Date: 1998-12-09 05:48:45 UTC
List: ruby-dev #3783
前田です。

>>>>> In [ruby-dev:3773]
>>>>> "前田" == MAEDA Shugo <shugo@aianet.ne.jp> san wrote:

前田> 手元のmmencodeが、なぜか-oオプションを処理してくれないようなので、
前田> pack("M")/unpack("M")を実装して、mmencode.rbというのを書いてみました。

前田> [2 pack.c.diff.gz <application/octet-stream (base64)>]

すいません、これは捨てて、こちらを使ってください。


-- 
前田 修吾 (mailto:shugo@aianet.ne.jp)

Attachments (1)

pack.c.diff (3 KB, text/x-diff)
--- pack.c.orig	Tue Dec  8 00:12:12 1998
+++ pack.c	Wed Dec  9 13:37:12 1998
@@ -77,6 +77,7 @@
 static char *toofew = "too few arguments";
 
 static void encodes _((VALUE,char*,int,int));
+static void qpencode _((VALUE,VALUE,int));
 
 static void
 pack_add_ptr(str, add)
@@ -469,6 +470,13 @@
 	    }
 	    break;
 
+	  case 'M':
+	    from = obj_as_string(NEXTFROM);
+	    if (len <= 1)
+		len = 72;
+	    qpencode(res, from, len);
+	    break;
+
 	  case 'P':
 	    len = 1;
 	    /* FALL THROUGH */
@@ -539,6 +547,86 @@
     str_cat(str, "\n", 1);
 }
 
+static char hex_table[] = "0123456789ABCDEF";
+
+static void
+qpencode(str, from, len)
+    VALUE str, from;
+    int len;
+{
+    char buff[1024];
+    int i = 0, n = 0, prev = EOF;
+    unsigned char *s = RSTRING(from)->ptr;
+    unsigned char *send = s + RSTRING(from)->len;
+
+    while (s < send) {
+        if ((*s > 126) ||
+	    (*s < 32 && *s != '\n' && *s != '\t') ||
+	    (*s == '=')) {
+	    buff[i++] = '=';
+	    buff[i++] = hex_table[*s >> 4];
+	    buff[i++] = hex_table[*s & 0x0f];
+            n += 3;
+            prev = EOF;
+        }
+	else if (*s == '\n') {
+            if (prev == ' ' || prev == '\t') {
+		buff[i++] = '=';
+		buff[i++] = *s;
+            }
+	    buff[i++] = *s;
+            n = 0;
+            prev = *s;
+        }
+	else {
+	    buff[i++] = *s;
+            n++;
+            prev = *s;
+        }
+        if (n > len) {
+	    buff[i++] = '=';
+	    buff[i++] = '\n';
+            n = 0;
+            prev = '\n';
+        }
+	if (i > 1024 - 5) {
+	    str_cat(str, buff, i);
+	    i = 0;
+	}
+	s++;
+    }
+    if (n > 0) {
+	buff[i++] = '=';
+	buff[i++] = '\n';
+    }
+    if (i > 0) {
+	str_cat(str, buff, i);
+    }
+}
+
+#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(RUBY_NO_INLINE)
+static __inline__ int
+#else
+static int
+#endif
+hex2num(c)
+    char c;
+{
+    switch (c) {
+    case '0': case '1': case '2': case '3': case '4':
+    case '5': case '6': case '7': case '8': case '9':
+        return c - '0';
+    case 'a': case 'b': case 'c':
+    case 'd': case 'e': case 'f':
+	return c - 'a' + 10;
+    case 'A': case 'B': case 'C':
+    case 'D': case 'E': case 'F':
+	return c - 'A' + 10;
+    default:
+	return -1;
+    }
+}
+
 static VALUE
 pack_unpack(str, fmt)
     VALUE str, fmt;
@@ -923,6 +1011,32 @@
 		if (a != -1 && b != -1 && c != -1 && s[3] == '=') {
 		    *ptr++ = a << 2 | b >> 4;
 		    *ptr++ = b << 4 | c >> 2;
+		}
+		RSTRING(str)->len = ptr - RSTRING(str)->ptr;
+		ary_push(ary, str);
+	    }
+	    break;
+
+	  case 'M':
+	    {
+		VALUE str = str_new(0, send - s);
+		char *ptr = RSTRING(str)->ptr;
+		int c1, c2;
+
+		while (s < send) {
+		    if (*s == '=') {
+			if (++s == send) break;
+			if (*s != '\n' && s < send - 1) {
+			    if ((c1 = hex2num(*s)) == -1) break;
+			    if (++s == send) break;
+			    if ((c2 = hex2num(*s)) == -1) break;
+			    *ptr++ = c1 << 4 | c2;
+			}
+		    }
+		    else {
+			*ptr++ = *s;
+		    }
+		    s++;
 		}
 		RSTRING(str)->len = ptr - RSTRING(str)->ptr;
 		ary_push(ary, str);

In This Thread