[前][次][番号順一覧][スレッド一覧]

ruby-changes:7657

From: akr <ko1@a...>
Date: Sat, 6 Sep 2008 14:16:54 +0900 (JST)
Subject: [ruby-changes:7657] Ruby:r19178 (trunk): * transcode.c (struct trans_open_t): defined to pass num_additional.

akr	2008-09-06 14:16:40 +0900 (Sat, 06 Sep 2008)

  New Revision: 19178

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19178

  Log:
    * transcode.c (struct trans_open_t): defined to pass num_additional.
      (trans_open_i): use struct trans_open_t.
      (rb_econv_open): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/transcode.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19177)
+++ ChangeLog	(revision 19178)
@@ -1,3 +1,9 @@
+Sat Sep  6 14:15:25 2008  Tanaka Akira  <akr@f...>
+
+	* transcode.c (struct trans_open_t): defined to pass num_additional.
+	  (trans_open_i): use struct trans_open_t.
+	  (rb_econv_open): ditto.
+
 Sat Sep  6 13:43:20 2008  Tanaka Akira  <akr@f...>
 
 	* enc/trans/escape.trans (fun_so_escape_html_attr): fix return type.
Index: transcode.c
===================================================================
--- transcode.c	(revision 19177)
+++ transcode.c	(revision 19178)
@@ -857,20 +857,20 @@
     return ec;
 }
 
+struct trans_open_t {
+    transcoder_entry_t **entries;
+    int num_additional;
+};
+
 static void
 trans_open_i(const char *sname, const char *dname, int depth, void *arg)
 {
-    transcoder_entry_t ***entries_ptr = arg;
-    transcoder_entry_t **entries;
+    struct trans_open_t *toarg = arg;
 
-    if (!*entries_ptr) {
-        entries = ALLOC_N(transcoder_entry_t *, depth+1+2);
-        *entries_ptr = entries;
+    if (!toarg->entries) {
+        toarg->entries = ALLOC_N(transcoder_entry_t *, depth+1+toarg->num_additional);
     }
-    else {
-        entries = *entries_ptr;
-    }
-    entries[depth] = get_transcoder_entry(sname, dname);
+    toarg->entries[depth] = get_transcoder_entry(sname, dname);
 }
 
 rb_econv_t *
@@ -878,13 +878,36 @@
 {
     transcoder_entry_t **entries = NULL;
     int num_trans;
-    int num_additional;
     static rb_econv_t *ec;
     int universal_newline_decoder_added = 0;
 
     rb_encoding *senc, *denc;
     int sidx, didx;
 
+    int num_encoders, num_decoders;
+    transcoder_entry_t *encoders[4], *decoders[1];
+
+    if ((ecflags & ECONV_CRLF_NEWLINE_ENCODER) &&
+        (ecflags & ECONV_CR_NEWLINE_ENCODER))
+        return NULL;
+
+    if ((ecflags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER)) &&
+        (ecflags & ECONV_UNIVERSAL_NEWLINE_DECODER))
+        return NULL;
+
+    num_encoders = 0;
+    if (ecflags & ECONV_CRLF_NEWLINE_ENCODER)
+        if (!(encoders[num_encoders++] = get_transcoder_entry("", "crlf_newline")))
+            return NULL;
+    if (ecflags & ECONV_CR_NEWLINE_ENCODER)
+        if (!(encoders[num_encoders++] = get_transcoder_entry("", "cr_newline")))
+            return NULL;
+
+    num_decoders = 0;
+    if (ecflags & ECONV_UNIVERSAL_NEWLINE_DECODER)
+        if (!(decoders[num_decoders++] = get_transcoder_entry("universal_newline", "")))
+            return NULL;
+
     senc = NULL;
     if (*sname) {
         sidx = rb_enc_find_index(sname);
@@ -901,12 +924,22 @@
         }
     }
 
+    if (*sname && (!senc || !rb_enc_asciicompat(senc)) && num_encoders)
+        return NULL;
+
+    if (*dname && (!denc || !rb_enc_asciicompat(denc)) && num_decoders)
+        return NULL;
+
     if (*sname == '\0' && *dname == '\0') {
         num_trans = 0;
-        entries = ALLOC_N(transcoder_entry_t *, 1+2);
+        entries = ALLOC_N(transcoder_entry_t *, num_encoders+num_decoders);
     }
     else {
-        num_trans = transcode_search_path(sname, dname, trans_open_i, (void *)&entries);
+        struct trans_open_t toarg;
+        toarg.entries = NULL;
+        toarg.num_additional = num_encoders+num_decoders;
+        num_trans = transcode_search_path(sname, dname, trans_open_i, (void *)&toarg);
+        entries = toarg.entries;
     }
 
     if (num_trans < 0 || !entries) {
@@ -914,48 +947,12 @@
         return NULL;
     }
 
-    num_additional = 0;
+    MEMMOVE(entries+num_encoders, entries, transcoder_entry_t *, num_trans);
+    MEMMOVE(entries, encoders, transcoder_entry_t *, num_encoders);
+    MEMMOVE(entries+num_encoders+num_trans, decoders, transcoder_entry_t *, num_decoders);
 
-    if (*sname && (!senc || !rb_enc_asciicompat(senc)) &&
-        (ecflags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER))) {
-        xfree(entries);
-        return NULL;
-    }
+    num_trans += num_encoders + num_decoders;
 
-    if (*dname && (!denc || !rb_enc_asciicompat(denc)) &&
-        (ecflags & (ECONV_UNIVERSAL_NEWLINE_DECODER))) {
-        xfree(entries);
-        return NULL;
-    }
-
-    if (ecflags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER)) {
-        const char *name = (ecflags & ECONV_CRLF_NEWLINE_ENCODER) ? "crlf_newline" : "cr_newline";
-        transcoder_entry_t *e = get_transcoder_entry("", name);
-        if (ecflags & ECONV_CRLF_NEWLINE_ENCODER)
-            ecflags &= ~ECONV_CR_NEWLINE_ENCODER;
-        else
-            ecflags &= ~ECONV_CRLF_NEWLINE_ENCODER;
-        if (!e) {
-            xfree(entries);
-            return NULL;
-        }
-        MEMMOVE(entries+1, entries, transcoder_entry_t *, num_trans);
-        entries[0] = e;
-        num_trans++;
-        num_additional++;
-    }
-
-    if (ecflags & ECONV_UNIVERSAL_NEWLINE_DECODER) {
-        transcoder_entry_t *e = get_transcoder_entry("universal_newline", "");
-        if (!e) {
-            xfree(entries);
-            return NULL;
-        }
-        entries[num_trans++] = e;
-        num_additional++;
-        universal_newline_decoder_added = 1;
-    }
-
     ec = rb_econv_open_by_transcoder_entries(num_trans, entries);
     xfree(entries);
     if (!ec)
@@ -965,7 +962,7 @@
     ec->source_encoding_name = sname;
     ec->destination_encoding_name = dname;
 
-    if (num_trans == num_additional) {
+    if (num_trans == num_encoders + num_decoders) {
         ec->last_tc = NULL;
         ec->last_trans_index = -1;
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]