- Subject: [slang-users] Fwd: translate patch
- From: "Brian McQueen" <mcqueenorama@xxxxxxxxx>
- Date: Thu, 8 Mar 2007 09:16:35 -0800
Here is a patch for translate so it uses the new curl features. Its a
bit of a shame to remove your cool encoder though.
*** ./slcurl-0.1.2/demo/translate Wed Feb 28 17:59:58 2007
--- translate Thu Mar 8 09:07:12 2007
***************
*** 70,95 ****
throw NotImplementedError, "Translating from $from to $to is not
supported"$;
}
-
- private define make_encode_table ()
- {
- variable table = array_map (String_Type, &sprintf, ("%%%02X", [0:255]));
- variable ok = [['A':'Z'], ['a':'z'], ['0':'9'], '.', '-', '*',
'_', '/', '~'];
- table[ok] = array_map (String_Type, &char, ok);
- table[' '] = "+";
- return table;
- }
- private variable Encode_Table = make_encode_table ();
-
- private define encode (text)
- {
- variable len = strlen (text);
- variable new_text = String_Type[len];
- variable i;
- _for i (0, len-1, 1)
- new_text[i] = Encode_Table[text[i]];
- return strjoin (new_text, "");
- }
private define parse_output (str)
{
--- 70,75 ----
***************
*** 119,126 ****
define babelfish (from, to, text)
{
variable c = curl_new
("http://babelfish.altavista.com/babelfish/tr?il=en");
variable postdata =
! strcat ("doit=done&urltext=", text,
"&lp=", lookup_translation (from, to),
"&Submit=Translate", "&enc=utf8");
--- 99,109 ----
define babelfish (from, to, text)
{
variable c = curl_new
("http://babelfish.altavista.com/babelfish/tr?il=en");
+
+ variable in_str = curl_easy_escape(c, text);
+
variable postdata =
! strcat ("doit=done&urltext=", in_str,
"&lp=", lookup_translation (from, to),
"&Submit=Translate", "&enc=utf8");
***************
*** 148,153 ****
--- 131,137 ----
{
variable lang_out = My_Language, lang_in = NULL;
variable i = 1;
+
while (i < __argc)
{
variable arg = __argv[i];
***************
*** 179,186 ****
text = "";
variable line;
while (-1 != fgets (&line, stdin))
! text = strcat (text, encode (line));
}
message (babelfish (lang_in, lang_out, text));
}
--- 163,171 ----
text = "";
variable line;
while (-1 != fgets (&line, stdin))
! text = strcat (text, line);
}
+
message (babelfish (lang_in, lang_out, text));
}
[2007 date index]
[2007 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]