在ubuntu9.04的时代,自带的输入法一直认为不够好用,看到了搜狗的云输入法,故产生了移植的想法.
通过chrome的inspect Element功能,我发现了搜狗、百度、QQ云输入法的接口.公布一下,供大家参考.
百度http://olime.baidu.com/py?py=bit&rn=0&pn=5
搜狗http://web.pinyin.sogou.com/api/py?key=938cdfe9e1e39f8dd5da428b1a6a69cb&query=bit
QQhttp://ime.qq.com/fcgi-bin/getword?key=f56b884eebd87625cb4f87fcf125b0db&cb=window.QQWebIME.callback238&q=y
写了一段百度的测试了一下,之后只用正则表达式就好了,后来看到google code上面有人开发了基于ibus的搜狗的云输入法,故决定停止开发吧.
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <string.h>
- #include <netdb.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <fcntl.h>
- #include <sys/time.h>
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <sys/socket.h>
- #include<iconv.h>
- #define MaxRecvLen 255
-
-
- struct DOMAIN
- {
- char url[255];
- char host[20];
- int port;
- };
- typedef struct DOMAIN domain;
-
-
- int gb2312toutf8(char *sourcebuf,size_t sourcelen,char *destbuf,size_t destlen)
- {
- iconv_t cd;
- if( (cd = iconv_open("utf-8","gb2312")) ==0 )
- return -1;
- memset(destbuf,0,destlen);
- char **source = &sourcebuf;
- char **dest = &destbuf;
-
- if(-1 == iconv(cd,source,&sourcelen,dest,&destlen))
- return -1;
- iconv_close(cd);
- return 0;
-
- }
-
-
- char* Getword(domain web_domain)
- {
-
-
-
- int sock_id;
-
- struct hostent *hostbyname;
- struct sockaddr_in remote_addr;
-
-
-
-
- struct timeval timeout;
- fd_set sockid_readable;
-
-
-
- char send_str[255];
- char temp[2048];
- char result[512];
- char word[2048];
- char *recBuf;
-
- int recv_numb;
-
- timeout.tv_sec = 10;
- timeout.tv_usec = 5000;
-
-
-
-
-
- hostbyname = gethostbyname(web_domain.host);
- if((sock_id=socket(PF_INET,SOCK_STREAM,0))==-1)
- {
- perror("socket");
- exit(1);
- }
-
-
- remote_addr.sin_family=AF_INET;
- remote_addr.sin_port=htons(web_domain.port);
- remote_addr.sin_addr=*((struct in_addr *)hostbyname->h_addr);
- bzero(&(remote_addr.sin_zero),8);
-
-
- if(connect(sock_id,(struct sockaddr *)&remote_addr,sizeof(remote_addr))==-1)
- {
- perror("connect");
- exit(1);
- }
-
-
-
- sprintf(send_str,"GET %s HTTP/1.1nAccept: */*nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)nHost: %snn",web_domain.url,web_domain.host);
-
-
- if(send(sock_id,send_str,strlen(send_str),0)==-1)
- {
- perror("send");
- exit(1);
- }
- recBuf=(char *)malloc(MaxRecvLen);
-
- while(1)
- {
-
-
- FD_ZERO(&sockid_readable);
- FD_SET(sock_id,&sockid_readable);
- select(sock_id 1, &sockid_readable, NULL, NULL, &timeout);
- if (!FD_ISSET(sock_id, &sockid_readable))
- {
- printf("Timed out.n");
-
- }
|