📄 wdictcli.cpp
字号:
#include "soapH.h"#include <string.h>const char defServer[300]="http://gnudict.cosoft.org.cn/cgi-bin/webdict2.cgi";const long MAXSIZE = 30000;void usage(void){ printf("DiCT client software , version 0.2.0 - Larry <caiyu@yahoo.com>\n"); printf("===============================================================\n"); printf("Usage wdictcli -l|-s|[-p<proxy>]|[-h<host>]|[-d<dict> <word/phrase>]\n"); printf(" -l : list the available dictionaries\n"); printf(" -s : check the server's status\n"); printf(" -p<proxy> : use proxy to access DiCT server\n"); printf(" -h : point host name, add http:// before \n"); printf(" Default is %s\n",defServer); printf(" -d<no> : query dictionary no, see -l result\n"); printf(" Default is 0\n"); printf(" <word/phrase> : query word \n"); printf(" i.e. wdictcli -l -s welcome\n"); printf(" wdictcli -l -pproxy.gnu.com:8080\n"); printf(" wdictcli -d1 hao\n\n");}void soapfault(struct soap soap){ printf(" SOAP fault "); if(soap.fault!=NULL && soap.fault->faultstring!=NULL) { printf(">> %s\n",soap.fault->faultstring); if(soap.fault->detail!=NULL) printf(">> Detail: %s",soap.fault->detail); } printf("\n");}void dbArray::print(void){ printf(">> Total %d databases are available.\n",__size); for (int i = 0; i < __size; i++) { printf("no. %s\n",__ptr[i].number); printf("name: %s\n",__ptr[i].name); printf("short desc: %s\n",__ptr[i].sdesc); printf("language: %s\n",__ptr[i].language); printf("supported startegy: %s\n",__ptr[i].strategy); printf("type: %s\n",__ptr[i].type); printf("\n"); }}void main(int argc, char** argv){ // char rate[2000]; struct ns1__statusResponse ret; struct ns1__lookupResponse result; struct getdatabaseResponse dbresult; char word[200]="hello"; char definition[MAXSIZE+1]=""; long size; struct soap soap; soap_init(&soap); char optch; char proxy[1000]; char server[300]=""; char dict[200]; int checklist=0; int checkstatus=0; int checkword=0; char *pos; while((optch = getopt(argc, argv, "lsp:d:h:")) != EOF) { switch(optch) { case 'd': sprintf(dict,"%d",atoi(optarg)); break; case 'p': strcpy(proxy,optarg); soap.proxy_host = ""; soap.proxy_port = 80; if((pos=(strchr(proxy,':')))!=NULL) { soap.proxy_port= atoi(pos+1); *pos='\0'; } soap.proxy_host = proxy; printf("set proxy: http://%s:%ld\n",soap.proxy_host,soap.proxy_port); break; case 's': checkstatus=1; break; case 'l': checklist=1; break; case 'h': strcpy(server,optarg); break; case '?': usage(); return 0; } } if(strncasecmp(server,"http://",7)!=0) { strcpy(server,defServer); } if(optind < argc) { checkword=1; strcpy(word,argv[optind]); } if(!checkstatus && !checklist && !checkword){ usage(); return 0; } if(checkstatus) { if (soap_call_ns1__status(&soap,server,"","status",ret) == 0) { printf("== Get all the available databases from DiCT ====\n"); printf(">> Host : %s\n",server); printf("<< Send querying :\"status\"\n"); printf("<< Result : %s\n\n",ret.status); }else { soapfault(soap); } } if(checklist) { if(soap_call_ns1__getdatabase(&soap,server,"", "command line wdictcli", "all", "DiCT 0.0.1", dbresult)==0) { printf("== Get all the available databases from DiCT ====\n"); printf(">> Host : %s\n",server); printf(">> Version is %s\n",dbresult.dictversion); printf(">> Status is %s\n",dbresult.status); dbresult.dbs.print(); }else { soapfault(soap); } } if(checkword) { if(soap_call_ns1__lookup(&soap,server,"", dict,word,"define+match","similar", result)==0) {// size=result.definition.__size; if(size > MAXSIZE) size = MAXSIZE;// strncpy(definition,(const char *)result.definition.__ptr,size);// definition[size]='\0'; // result.definition.__ptr[strlen((char *)result.definition.__ptr)]='\0'; printf("%s:%s\n",result.word,result.definition); }else { soapfault(soap); } } soap_end(&soap);}struct Namespace namespaces[] ={ { "SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/" }, { "SOAP-ENC","http://schemas.xmlsoap.org/soap/encoding/"}, { "xsi", "http://www.w3.org/1999/XMLSchema-instance" }, { "xsd", "http://www.w3.org/1999/XMLSchema" }, { "ns1", "urn:wdict"}, { NULL, NULL }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -