回文章列表
作者lzch.bbs@cpu.tfcis.org (lzch) 看板: itoc
標題Re: [功能] dict.c Yahoo! 線上字典
時間動力核心 (2007/12/07 Fri 11:38:19)
好像是因為中文網址編碼改了

所以查中文時會錯

(順便改一點點排板)


: dict.c

#if 0

  普通
! http://tw.dictionary.yahoo.com/search?ei=UTF-8&p=hello

#endif

...
...

! #define CGI_yahoo           "/search?ei=UTF-8&p="


: dict.c:encode_from_utf8_to_big5_and_more_out()

      /* skip KK: []*/
      if( !strncmp( bufout, " KK: []", 7 ) ){
              continue;
      }
+     /* skip 釋義  (不過這樣在查 "釋義" "變化形" 時, 不會錯嗎...) */
+     if( !strncmp( bufout, "釋義", 4 ) ){
+             continue;
+     }
+     /* skip 同義字/反義字*/
+     if( !strncmp( bufout, "同義字/反義字", 13 ) ){
+             continue;
+     }
+     /* skip 變化形*/
+     if( !strncmp( bufout, "變化形", 4 ) ){
+             continue;
+     }



: dict.c:write_file()

  int show, start_show;
  int space;                /* 在 html 中,連續的 space 只會算一次 */
+ int chinese = 0;  /* 是否查詢中文 */
+ char *identify_chinese = "<div class=\"chinese-explain pexplain\">";

  ...
  ...

  char *newline_str[] =         /* 取代換行字元的符號 */
  {
    "<br>",
    "</td>",
+   identify_chinese,
+   "</li>",

    ...
    ...

  }

  ...
  ...

    for (i = 0; newline_str[i] != NULL; i++)
    {
      if (!str_ncmp(xhead, newline_str[i], strlen(newline_str[i])))
      {
+       /* 如果是英文查詢, 則遇到 <\li> 時, 不換行 */
+       if( !(chinese == 0 && !strncmp( xhead, "</li>", 5 )) )
+       {
+           fputc('\n', fp);
+       }

        ...
        ...

        else if( !strncmp( xhead, "<br>\n<li>", 9 ) ){
            fprintf( fp, "lzch_explain000" ); /* 標記此為譯詞 */
        }
+       else if( !strncmp( xhead, identify_chinese, strlen(identify_chinese) ) ){
+           chinese = 1;
+       }



: dict.c:main_dreye()

+ char *encFrom = "BIG-5", *encTo = "UTF-8";
+ iconv_t c_pt;
+ int lenin, lenout;
+ char word_utf8[100];
+ char *sin, *sout;

  ...
  ...

  while (1)
  {
    ...
    ...

    if (!vget(8, 0, "查詢字彙:", word, 30, DOECHO))
      break;

+   if ((c_pt = iconv_open(encTo, encFrom)) == (iconv_t)-1) {
+     return -1;
+   }

+   lenin = strlen(word);
+   lenout = 100;
+   sin = word;
+   sout = word_utf8;

+   iconv( c_pt, &sin, &lenin, &sout, &lenout );

+   for( sin++, lenin--; lenin > 0; sin++, lenin--){
+       iconv( c_pt, &sin, &lenin, &sout, &lenout );
+   }

+   word_utf8[100-lenout] = '\0';

!   yahoo_dict(word_utf8);
  }


==
應該是就改這些吧

真是可怕的 code..  不過算了 可以用就好...


也可以整個換掉~

http://web.ntnu.edu.tw/~49308014/dict.c



--
=[:摃��:﹎Origin ]|[  Ocpu.tfcis.org  ]|[�搟說:]=
=[:摃�╱�:Author ]|[  lzch.sdorm.ntnu.edu.tw  ]|[�:]=
文章選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻