summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--enc/trans/escape.trans66
-rw-r--r--tool/transcode-tblgen.rb12
-rw-r--r--transcode.c8
-rw-r--r--transcode_data.h4
5 files changed, 52 insertions, 51 deletions
diff --git a/ChangeLog b/ChangeLog
index 54384f75c0..4654478f90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Sun Sep 7 18:10:28 2008 Tanaka Akira <akr@fsij.org>
+
+ * transcode_data.h (STR1): defined for a string up to 255 bytes.
+ (STR1_BYTEINDEX): defined.
+ (makeSTR1): defined.
+
+ * tool/transcode-tblgen.rb: generate STR1.
+
+ * transcode.c (transcode_restartable0): interpret STR1.
+
+ * enc/trans/escape.trans (fun_so_escape_xml_chref): removed. STR1 is
+ used instead.
+
Sun Sep 7 17:54:45 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* configure.in: Mac OS X's crypt(2) is broken with invalid salt.
diff --git a/enc/trans/escape.trans b/enc/trans/escape.trans
index a64114f533..1003e211d4 100644
--- a/enc/trans/escape.trans
+++ b/enc/trans/escape.trans
@@ -1,69 +1,33 @@
#include "transcode_data.h"
-static int
-fun_so_escape_xml_chref(void *statep, const unsigned char *s, size_t l, unsigned char *o)
-{
- switch (*s) {
- case '&':
- o[0] = '&';
- o[1] = 'a';
- o[2] = 'm';
- o[3] = 'p';
- o[4] = ';';
- return 5;
-
- case '<':
- o[0] = '&';
- o[1] = 'l';
- o[2] = 't';
- o[3] = ';';
- return 4;
-
- case '>':
- o[0] = '&';
- o[1] = 'g';
- o[2] = 't';
- o[3] = ';';
- return 4;
-
- case '"':
- o[0] = '&';
- o[1] = 'q';
- o[2] = 'u';
- o[3] = 'o';
- o[4] = 't';
- o[5] = ';';
- return 6;
-
- default:
- rb_bug("unexpected char");
- }
-}
<%
+ def str1(str)
+ str.unpack("H*")[0]
+ end
+
map_amp = {}
map_amp["{00-25,27-FF}"] = :nomap
- map_amp["26"] = :func_so
+ map_amp["26"] = str1("&amp;")
transcode_generate_node(ActionMap.parse(map_amp), "escape_amp_as_chref")
map_xml_text = {}
map_xml_text["{00-25,27-3B,3D,3F-FF}"] = :nomap
- map_xml_text["26"] = :func_so
- map_xml_text["3C"] = :func_so
- map_xml_text["3E"] = :func_so
+ map_xml_text["26"] = str1("&amp;")
+ map_xml_text["3C"] = str1("&lt;")
+ map_xml_text["3E"] = str1("&gt;")
transcode_generate_node(ActionMap.parse(map_xml_text), "escape_xml_text")
map_xml_attr_content = {}
map_xml_attr_content["{00-21,23-25,27-3B,3D,3F-FF}"] = :nomap
- map_xml_attr_content["22"] = :func_so
- map_xml_attr_content["26"] = :func_so
- map_xml_attr_content["3C"] = :func_so
- map_xml_attr_content["3E"] = :func_so
+ map_xml_attr_content["22"] = str1("&quot;")
+ map_xml_attr_content["26"] = str1("&amp;")
+ map_xml_attr_content["3C"] = str1("&lt;")
+ map_xml_attr_content["3E"] = str1("&gt;")
transcode_generate_node(ActionMap.parse(map_xml_attr_content), "escape_xml_attr_content")
map_xml_attr_quote = {}
map_xml_attr_quote["{00-FF}"] = :func_so
transcode_generate_node(ActionMap.parse(map_xml_attr_quote), "escape_xml_attr_quote")
-
%>
<%= transcode_generated_code %>
@@ -77,7 +41,7 @@ rb_escape_amp_as_chref = {
5, /* max_output */
stateless_converter, /* stateful_type */
0, NULL, NULL,
- NULL, NULL, NULL, &fun_so_escape_xml_chref
+ NULL, NULL, NULL, NULL
};
static const rb_transcoder
@@ -89,7 +53,7 @@ rb_escape_xml_text = {
5, /* max_output */
stateless_converter, /* stateful_type */
0, NULL, NULL,
- NULL, NULL, NULL, &fun_so_escape_xml_chref
+ NULL, NULL, NULL, NULL
};
static const rb_transcoder
@@ -101,7 +65,7 @@ rb_escape_xml_attr_content = {
6, /* max_output */
stateless_converter, /* stateful_type */
0, NULL, NULL,
- NULL, NULL, NULL, &fun_so_escape_xml_chref
+ NULL, NULL, NULL, NULL
};
#define END 0
diff --git a/tool/transcode-tblgen.rb b/tool/transcode-tblgen.rb
index 6f98f10ea3..95031c43a0 100644
--- a/tool/transcode-tblgen.rb
+++ b/tool/transcode-tblgen.rb
@@ -301,6 +301,14 @@ class ActionMap
"o3(0x#$1,0x#$2,0x#$3)"
when /\A(f[0-7])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])\z/i
"o4(0x#$1,0x#$2,0x#$3,0x#$4)"
+ when /\A([0-9a-f][0-9a-f]){0,255}\z/i
+ bytes = info
+ len = info.length/2
+ size = @bytes_code.length
+ @bytes_code.insert_at_last(1 + len,
+ "\#define str1_#{size} makeSTR1(#{size})\n" +
+ " #{len}," + info.gsub(/../, ' 0x\&,') + "\n")
+ "str1_#{size}"
when /\A\/\*BYTE_LOOKUP\*\// # pointer to BYTE_LOOKUP structure
$'.to_s
else
@@ -414,7 +422,11 @@ End
end
def gennode(bytes_code, words_code, name_hint=nil, valid_encoding=nil)
+ @bytes_code = bytes_code
+ @words_code = words_code
name = generate_node(bytes_code, words_code, name_hint, valid_encoding)
+ @bytes_code = nil
+ @words_code = nil
return name
end
end
diff --git a/transcode.c b/transcode.c
index 1fdd27d7de..9d1d2a9b97 100644
--- a/transcode.c
+++ b/transcode.c
@@ -534,6 +534,7 @@ transcode_restartable0(const unsigned char **in_pos, unsigned char **out_pos,
case 25: goto resume_label25;
case 26: goto resume_label26;
case 27: goto resume_label27;
+ case 28: goto resume_label28;
}
while (1) {
@@ -602,6 +603,13 @@ transcode_restartable0(const unsigned char **in_pos, unsigned char **out_pos,
SUSPEND_OBUF(18); *out_p++ = getBT2(next_info);
SUSPEND_OBUF(19); *out_p++ = getBT3(next_info);
continue;
+ case STR1:
+ next_byte = 0; /* index */
+ while (next_byte < BYTE_ADDR(STR1_BYTEINDEX(next_info))[0]) {
+ SUSPEND_OBUF(28); *out_p++ = BYTE_ADDR(STR1_BYTEINDEX(next_info))[1+next_byte];
+ next_byte++;
+ }
+ continue;
case FUNii:
next_info = (VALUE)(*tr->func_ii)(TRANSCODING_STATE(tc), next_info);
goto follow_info;
diff --git a/transcode_data.h b/transcode_data.h
index 8729b3b4e9..4587815c67 100644
--- a/transcode_data.h
+++ b/transcode_data.h
@@ -34,6 +34,10 @@
#define FUNsi (PType 0x0D) /* function from start to info */
#define FUNio (PType 0x0E) /* function from info to output */
#define FUNso (PType 0x0F) /* function from start to output */
+#define STR1 (PType 0x11) /* string up to 255 bytes: 1byte length + content */
+
+#define STR1_BYTEINDEX(w) ((w) >> 6)
+#define makeSTR1(bi) (((bi) << 6) | STR1)
#define o1(b1) (PType((((unsigned char)(b1))<<8)|ONEbt))
#define o2(b1,b2) (PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|TWObt))