Advertisement
Guest User

Untitled

a guest
Jan 27th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.35 KB | None | 0 0
  1. diff -Nrup hunspell-1.3.2.orig/hunspelld-example.php hunspell-1.3.2.devel/hunspelld-example.php
  2. --- hunspell-1.3.2.orig/hunspelld-example.php 1970-01-01 01:00:00.000000000 +0100
  3. +++ hunspell-1.3.2.devel/hunspelld-example.php 2013-01-27 13:14:55.459509674 +0100
  4. @@ -0,0 +1,61 @@
  5. +Example web interface for hunspelld.<br>
  6. +Source: http://brousant.nl/wiki/index.php/Online_spellingcontrole<br>
  7. +See also: hunspelld executable
  8. +<br><br>
  9. +<?php
  10. +$buf = "";
  11. +$name = "localhost";
  12. +$port = 5678;
  13. +
  14. +$checkword = ($_POST['checkword']);
  15. +echo "<br>";
  16. +$socket = socket_create(AF_INET, SOCK_DGRAM, getprotobyname("udp"));
  17. +if ($socket == FALSE) {
  18. + echo "socket not created<br>";
  19. +}
  20. +socket_sendto ($socket, $checkword, strlen($checkword), 0, "localhost", 5678);
  21. +
  22. +$write=NULL;
  23. +$except=NULL;
  24. +$recword="";
  25. +for ($i=0; $i<3; $i++) {
  26. + $read=array($socket);
  27. + $num_changed_sockets= socket_select (&$read, &$write, &$except, 3);
  28. + if ($num_changed_sockets==1) {
  29. + socket_recvfrom($socket, &$buf, 200, 0, &$name, &$port);
  30. + $wordlen=strpos($buf, ";");
  31. + $recword=substr ($buf , 0, $wordlen);
  32. + if ($recword==$checkword) {
  33. + break;
  34. + }
  35. + }
  36. +}
  37. +if ($recword!=$checkword) {
  38. + echo "<i>no response from hunspelld</i><br>";
  39. +}
  40. +else {
  41. + echo substr ($buf , 0, $wordlen);
  42. + $rescode =substr ($buf, $wordlen+1, 1);
  43. + if ($rescode == "0") {
  44. + echo ": incorrect. <br>Suggestions: ";
  45. + echo substr ($buf, $wordlen+3);
  46. + }
  47. + else if ($rescode == "1") {
  48. + echo ": correct.";
  49. + }
  50. + else if ($rescode == "2") {
  51. + echo ": correct (buit possibly confusing).";
  52. + }
  53. +}
  54. +echo "<br>" ;
  55. +socket_close ($socket);
  56. +?>
  57. +
  58. +<form method="post" action="hunspelld-example.php">
  59. + <p>Woord om te controleren:
  60. + <input type="text" name="checkword">
  61. + </p>
  62. + <p>
  63. + <input type="submit" name="submit" value="Check">
  64. + </p>
  65. +</form>
  66. diff -Nrup hunspell-1.3.2.orig/src/tools/hunspelld.cxx hunspell-1.3.2.devel/src/tools/hunspelld.cxx
  67. --- hunspell-1.3.2.orig/src/tools/hunspelld.cxx 1970-01-01 01:00:00.000000000 +0100
  68. +++ hunspell-1.3.2.devel/src/tools/hunspelld.cxx 2013-01-27 13:25:14.159510305 +0100
  69. @@ -0,0 +1,107 @@
  70. +// Source: http://brousant.nl/wiki/index.php/Online_spellingcontrole
  71. +// See also hunspelld-example.php
  72. +#include <stdio.h>
  73. +#include <stdlib.h>
  74. +#include <unistd.h>
  75. +#include <errno.h>
  76. +#include <string.h>
  77. +#include <sys/types.h>
  78. +#include <sys/socket.h>
  79. +#include <netinet/in.h>
  80. +#include <arpa/inet.h>
  81. +#include "../hunspell/hunspell.h"
  82. +
  83. +#define MYPORT 5678
  84. +
  85. +#define MAXINBUFLEN 100
  86. +#define MAXOUTBUFLEN 200
  87. +
  88. +#define DESC "hunspelld - offer hunspell spell checker as a daemon on an UDP socket\n" \
  89. +"This is much faster than starting hunspell again and again because initialisation is done only once.\n" \
  90. +"Usage: hunspelld file.aff file.dic [port_num]\n" \
  91. +"file.aff is e.g. /usr/share/hunspell/en_US.aff\n" \
  92. +"file.dic is e.g. /usr/share/hunspell/en_US.dic\n" \
  93. +"port_num is by default 5678\n"
  94. +
  95. +int main(int argc, char **argv)
  96. +{
  97. + int port = MYPORT;
  98. + int sockfd;
  99. + struct sockaddr_in my_adress;
  100. + struct sockaddr_in rem_adress;
  101. + int adress_len, word_len, num_bytes;
  102. + char inbuf[MAXINBUFLEN];
  103. + char outbuf[MAXOUTBUFLEN];
  104. + int count=0, i, result;
  105. + Hunhandle *pHunspell;
  106. + char **sugs;
  107. + int numsugs;
  108. +
  109. + if (argc < 3 or argc > 4) {
  110. + fprintf(stderr, DESC, NULL);
  111. + return 1;
  112. + }
  113. + if (argc == 4) {
  114. + port = atoi(argv[3]);
  115. + if (port == 0) {
  116. + port = MYPORT;
  117. + fprintf(stderr, "incorrect port number\n", NULL);
  118. + return 1;
  119. + }
  120. + }
  121. +
  122. + pHunspell=Hunspell_create(argv[1], argv[2]);
  123. +
  124. + if (pHunspell==NULL) {
  125. + perror("Hunspell_create");
  126. + exit(1);
  127. + }
  128. +
  129. + if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
  130. + perror("socket");
  131. + exit(1);
  132. + }
  133. +
  134. + my_adress.sin_family = AF_INET;
  135. + my_adress.sin_port = htons(MYPORT);
  136. + my_adress.sin_addr.s_addr = INADDR_ANY;
  137. + memset(&(my_adress.sin_zero), '\0', 8);
  138. +
  139. + if (bind(sockfd, (struct sockaddr *)&my_adress, sizeof(struct sockaddr)) == -1) {
  140. + perror("bind");
  141. + exit(1);
  142. + }
  143. +
  144. + printf ("hunspell daemon running...\n");
  145. + adress_len = sizeof(struct sockaddr);
  146. + while (1)
  147. + {
  148. + if ((word_len = recvfrom(sockfd, inbuf, MAXINBUFLEN - 1 , 0, (struct sockaddr *)&rem_adress, (socklen_t *)&adress_len)) == -1) {
  149. + perror("recvfrom");
  150. + continue;
  151. + }
  152. +
  153. + inbuf[word_len] = '\0';
  154. + printf("%s\n",inbuf);
  155. + if ((result=Hunspell_spell(pHunspell, inbuf))==0) {
  156. + // printf("word not found\n");
  157. + numsugs=Hunspell_suggest (pHunspell, &sugs, inbuf);
  158. + //printf ("number of suggestions=%i\n", numsugs);
  159. + sprintf(outbuf, "%s;0", inbuf);
  160. + for (i=0; i<numsugs; i++) {
  161. + sprintf (outbuf+strlen(outbuf),",%s", sugs[i]);
  162. + }
  163. + Hunspell_free_list(pHunspell, &sugs, numsugs);
  164. + }
  165. + else {
  166. + sprintf(outbuf, "%s;%i", inbuf, result);
  167. + }
  168. +
  169. + if ((num_bytes = sendto(sockfd, outbuf , strlen(outbuf) , 0, (struct sockaddr *)&rem_adress, sizeof(struct sockaddr))) == -1) {
  170. + perror("sendto");
  171. + }
  172. + }
  173. + // should not come here
  174. + close(sockfd);
  175. + return 0;
  176. +}
  177. diff -Nrup hunspell-1.3.2.orig/src/tools/Makefile.am hunspell-1.3.2.devel/src/tools/Makefile.am
  178. --- hunspell-1.3.2.orig/src/tools/Makefile.am 2011-02-16 15:34:51.000000000 +0100
  179. +++ hunspell-1.3.2.devel/src/tools/Makefile.am 2013-01-27 13:11:19.423509455 +0100
  180. @@ -1,4 +1,4 @@
  181. -bin_PROGRAMS=analyze chmorph hunspell munch unmunch hzip hunzip
  182. +bin_PROGRAMS=analyze chmorph hunspell munch unmunch hzip hunzip hunspelld
  183.  
  184. INCLUDES=-I${top_srcdir}/src/hunspell -I${top_srcdir}/src/parsers
  185.  
  186. @@ -22,6 +22,9 @@ analyze_LDADD = ../hunspell/libhunspell-
  187. chmorph_SOURCES=chmorph.cxx
  188. chmorph_LDADD = ../parsers/libparsers.a ../hunspell/libhunspell-1.3.la
  189.  
  190. +hunspelld_SOURCES=hunspelld.c
  191. +hunspelld_LDADD = ../hunspell/libhunspell-1.3.la
  192. +
  193. noinst_PROGRAMS=example
  194.  
  195. dist_bin_SCRIPTS=makealias affixcompress wordforms ispellaff2myspell wordlist2hunspell
  196. diff -Nrup hunspell-1.3.2.orig/src/tools/Makefile.in hunspell-1.3.2.devel/src/tools/Makefile.in
  197. --- hunspell-1.3.2.orig/src/tools/Makefile.in 2011-02-16 15:43:09.000000000 +0100
  198. +++ hunspell-1.3.2.devel/src/tools/Makefile.in 2013-01-27 13:10:54.303509429 +0100
  199. @@ -37,7 +37,8 @@ build_triplet = @build@
  200. host_triplet = @host@
  201. target_triplet = @target@
  202. bin_PROGRAMS = analyze$(EXEEXT) chmorph$(EXEEXT) hunspell$(EXEEXT) \
  203. - munch$(EXEEXT) unmunch$(EXEEXT) hzip$(EXEEXT) hunzip$(EXEEXT)
  204. + munch$(EXEEXT) unmunch$(EXEEXT) hzip$(EXEEXT) hunzip$(EXEEXT) \
  205. + hunspelld$(EXEEXT)
  206. noinst_PROGRAMS = example$(EXEEXT)
  207. subdir = src/tools
  208. DIST_COMMON = $(dist_bin_SCRIPTS) $(srcdir)/Makefile.am \
  209. @@ -86,6 +87,9 @@ hunspell_DEPENDENCIES = ../parsers/libpa
  210. am_hunzip_OBJECTS = hunzip.$(OBJEXT)
  211. hunzip_OBJECTS = $(am_hunzip_OBJECTS)
  212. hunzip_DEPENDENCIES = ../hunspell/libhunspell-1.3.la
  213. +am_hunspelld_OBJECTS = hunspelld.$(OBJEXT)
  214. +hunspelld_OBJECTS = $(am_hunspelld_OBJECTS)
  215. +hunspelld_DEPENDENCIES = ../hunspell/libhunspell-1.3.la
  216. am_hzip_OBJECTS = hzip.$(OBJEXT)
  217. hzip_OBJECTS = $(am_hzip_OBJECTS)
  218. hzip_LDADD = $(LDADD)
  219. @@ -141,10 +145,11 @@ CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBT
  220. $(LDFLAGS) -o $@
  221. SOURCES = $(analyze_SOURCES) $(chmorph_SOURCES) $(example_SOURCES) \
  222. $(hunspell_SOURCES) $(hunzip_SOURCES) $(hzip_SOURCES) \
  223. - $(munch_SOURCES) $(unmunch_SOURCES)
  224. + $(munch_SOURCES) $(unmunch_SOURCES) $(hunspelld_SOURCES)
  225. DIST_SOURCES = $(analyze_SOURCES) $(chmorph_SOURCES) \
  226. $(example_SOURCES) $(hunspell_SOURCES) $(hunzip_SOURCES) \
  227. - $(hzip_SOURCES) $(munch_SOURCES) $(unmunch_SOURCES)
  228. + $(hzip_SOURCES) $(munch_SOURCES) $(unmunch_SOURCES) \
  229. + $(hunspelld_SOURCES)
  230. ETAGS = etags
  231. CTAGS = ctags
  232. DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
  233. @@ -326,6 +331,8 @@ INCLUDES = -I${top_srcdir}/src/hunspell
  234. hzip_SOURCES = hzip.c
  235. hunzip_SOURCES = hunzip.cxx
  236. hunzip_LDADD = ../hunspell/libhunspell-1.3.la
  237. +hunspelld_SOURCES = hunspelld.cxx
  238. +hunspelld_LDADD = ../hunspell/libhunspell-1.3.la
  239. munch_SOURCES = munch.c munch.h
  240. unmunch_SOURCES = unmunch.c unmunch.h
  241. example_SOURCES = example.cxx
  242. @@ -440,6 +447,9 @@ hunspell$(EXEEXT): $(hunspell_OBJECTS) $
  243. hunzip$(EXEEXT): $(hunzip_OBJECTS) $(hunzip_DEPENDENCIES)
  244. @rm -f hunzip$(EXEEXT)
  245. $(CXXLINK) $(hunzip_OBJECTS) $(hunzip_LDADD) $(LIBS)
  246. +hunspelld$(EXEEXT): $(hunspelld_OBJECTS) $(hunspelld_DEPENDENCIES)
  247. + @rm -f hunspelld$(EXEEXT)
  248. + $(CXXLINK) $(hunspelld_OBJECTS) $(hunspelld_LDADD) $(LIBS)
  249. hzip$(EXEEXT): $(hzip_OBJECTS) $(hzip_DEPENDENCIES)
  250. @rm -f hzip$(EXEEXT)
  251. $(LINK) $(hzip_OBJECTS) $(hzip_LDADD) $(LIBS)
  252. @@ -495,6 +505,7 @@ distclean-compile:
  253. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/example.Po@am__quote@
  254. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hunspell.Po@am__quote@
  255. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hunzip.Po@am__quote@
  256. +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hunspelld.Po@am__quote@
  257. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hzip.Po@am__quote@
  258. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/munch.Po@am__quote@
  259. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unmunch.Po@am__quote@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement