Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -Nrup hunspell-1.3.2.orig/hunspelld-example.php hunspell-1.3.2.devel/hunspelld-example.php
- --- hunspell-1.3.2.orig/hunspelld-example.php 1970-01-01 01:00:00.000000000 +0100
- +++ hunspell-1.3.2.devel/hunspelld-example.php 2013-01-27 13:14:55.459509674 +0100
- @@ -0,0 +1,61 @@
- +Example web interface for hunspelld.<br>
- +Source: http://brousant.nl/wiki/index.php/Online_spellingcontrole<br>
- +See also: hunspelld executable
- +<br><br>
- +<?php
- +$buf = "";
- +$name = "localhost";
- +$port = 5678;
- +
- +$checkword = ($_POST['checkword']);
- +echo "<br>";
- +$socket = socket_create(AF_INET, SOCK_DGRAM, getprotobyname("udp"));
- +if ($socket == FALSE) {
- + echo "socket not created<br>";
- +}
- +socket_sendto ($socket, $checkword, strlen($checkword), 0, "localhost", 5678);
- +
- +$write=NULL;
- +$except=NULL;
- +$recword="";
- +for ($i=0; $i<3; $i++) {
- + $read=array($socket);
- + $num_changed_sockets= socket_select (&$read, &$write, &$except, 3);
- + if ($num_changed_sockets==1) {
- + socket_recvfrom($socket, &$buf, 200, 0, &$name, &$port);
- + $wordlen=strpos($buf, ";");
- + $recword=substr ($buf , 0, $wordlen);
- + if ($recword==$checkword) {
- + break;
- + }
- + }
- +}
- +if ($recword!=$checkword) {
- + echo "<i>no response from hunspelld</i><br>";
- +}
- +else {
- + echo substr ($buf , 0, $wordlen);
- + $rescode =substr ($buf, $wordlen+1, 1);
- + if ($rescode == "0") {
- + echo ": incorrect. <br>Suggestions: ";
- + echo substr ($buf, $wordlen+3);
- + }
- + else if ($rescode == "1") {
- + echo ": correct.";
- + }
- + else if ($rescode == "2") {
- + echo ": correct (buit possibly confusing).";
- + }
- +}
- +echo "<br>" ;
- +socket_close ($socket);
- +?>
- +
- +<form method="post" action="hunspelld-example.php">
- + <p>Woord om te controleren:
- + <input type="text" name="checkword">
- + </p>
- + <p>
- + <input type="submit" name="submit" value="Check">
- + </p>
- +</form>
- diff -Nrup hunspell-1.3.2.orig/src/tools/hunspelld.cxx hunspell-1.3.2.devel/src/tools/hunspelld.cxx
- --- hunspell-1.3.2.orig/src/tools/hunspelld.cxx 1970-01-01 01:00:00.000000000 +0100
- +++ hunspell-1.3.2.devel/src/tools/hunspelld.cxx 2013-01-27 13:25:14.159510305 +0100
- @@ -0,0 +1,107 @@
- +// Source: http://brousant.nl/wiki/index.php/Online_spellingcontrole
- +// See also hunspelld-example.php
- +#include <stdio.h>
- +#include <stdlib.h>
- +#include <unistd.h>
- +#include <errno.h>
- +#include <string.h>
- +#include <sys/types.h>
- +#include <sys/socket.h>
- +#include <netinet/in.h>
- +#include <arpa/inet.h>
- +#include "../hunspell/hunspell.h"
- +
- +#define MYPORT 5678
- +
- +#define MAXINBUFLEN 100
- +#define MAXOUTBUFLEN 200
- +
- +#define DESC "hunspelld - offer hunspell spell checker as a daemon on an UDP socket\n" \
- +"This is much faster than starting hunspell again and again because initialisation is done only once.\n" \
- +"Usage: hunspelld file.aff file.dic [port_num]\n" \
- +"file.aff is e.g. /usr/share/hunspell/en_US.aff\n" \
- +"file.dic is e.g. /usr/share/hunspell/en_US.dic\n" \
- +"port_num is by default 5678\n"
- +
- +int main(int argc, char **argv)
- +{
- + int port = MYPORT;
- + int sockfd;
- + struct sockaddr_in my_adress;
- + struct sockaddr_in rem_adress;
- + int adress_len, word_len, num_bytes;
- + char inbuf[MAXINBUFLEN];
- + char outbuf[MAXOUTBUFLEN];
- + int count=0, i, result;
- + Hunhandle *pHunspell;
- + char **sugs;
- + int numsugs;
- +
- + if (argc < 3 or argc > 4) {
- + fprintf(stderr, DESC, NULL);
- + return 1;
- + }
- + if (argc == 4) {
- + port = atoi(argv[3]);
- + if (port == 0) {
- + port = MYPORT;
- + fprintf(stderr, "incorrect port number\n", NULL);
- + return 1;
- + }
- + }
- +
- + pHunspell=Hunspell_create(argv[1], argv[2]);
- +
- + if (pHunspell==NULL) {
- + perror("Hunspell_create");
- + exit(1);
- + }
- +
- + if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
- + perror("socket");
- + exit(1);
- + }
- +
- + my_adress.sin_family = AF_INET;
- + my_adress.sin_port = htons(MYPORT);
- + my_adress.sin_addr.s_addr = INADDR_ANY;
- + memset(&(my_adress.sin_zero), '\0', 8);
- +
- + if (bind(sockfd, (struct sockaddr *)&my_adress, sizeof(struct sockaddr)) == -1) {
- + perror("bind");
- + exit(1);
- + }
- +
- + printf ("hunspell daemon running...\n");
- + adress_len = sizeof(struct sockaddr);
- + while (1)
- + {
- + if ((word_len = recvfrom(sockfd, inbuf, MAXINBUFLEN - 1 , 0, (struct sockaddr *)&rem_adress, (socklen_t *)&adress_len)) == -1) {
- + perror("recvfrom");
- + continue;
- + }
- +
- + inbuf[word_len] = '\0';
- + printf("%s\n",inbuf);
- + if ((result=Hunspell_spell(pHunspell, inbuf))==0) {
- + // printf("word not found\n");
- + numsugs=Hunspell_suggest (pHunspell, &sugs, inbuf);
- + //printf ("number of suggestions=%i\n", numsugs);
- + sprintf(outbuf, "%s;0", inbuf);
- + for (i=0; i<numsugs; i++) {
- + sprintf (outbuf+strlen(outbuf),",%s", sugs[i]);
- + }
- + Hunspell_free_list(pHunspell, &sugs, numsugs);
- + }
- + else {
- + sprintf(outbuf, "%s;%i", inbuf, result);
- + }
- +
- + if ((num_bytes = sendto(sockfd, outbuf , strlen(outbuf) , 0, (struct sockaddr *)&rem_adress, sizeof(struct sockaddr))) == -1) {
- + perror("sendto");
- + }
- + }
- + // should not come here
- + close(sockfd);
- + return 0;
- +}
- diff -Nrup hunspell-1.3.2.orig/src/tools/Makefile.am hunspell-1.3.2.devel/src/tools/Makefile.am
- --- hunspell-1.3.2.orig/src/tools/Makefile.am 2011-02-16 15:34:51.000000000 +0100
- +++ hunspell-1.3.2.devel/src/tools/Makefile.am 2013-01-27 13:11:19.423509455 +0100
- @@ -1,4 +1,4 @@
- -bin_PROGRAMS=analyze chmorph hunspell munch unmunch hzip hunzip
- +bin_PROGRAMS=analyze chmorph hunspell munch unmunch hzip hunzip hunspelld
- INCLUDES=-I${top_srcdir}/src/hunspell -I${top_srcdir}/src/parsers
- @@ -22,6 +22,9 @@ analyze_LDADD = ../hunspell/libhunspell-
- chmorph_SOURCES=chmorph.cxx
- chmorph_LDADD = ../parsers/libparsers.a ../hunspell/libhunspell-1.3.la
- +hunspelld_SOURCES=hunspelld.c
- +hunspelld_LDADD = ../hunspell/libhunspell-1.3.la
- +
- noinst_PROGRAMS=example
- dist_bin_SCRIPTS=makealias affixcompress wordforms ispellaff2myspell wordlist2hunspell
- diff -Nrup hunspell-1.3.2.orig/src/tools/Makefile.in hunspell-1.3.2.devel/src/tools/Makefile.in
- --- hunspell-1.3.2.orig/src/tools/Makefile.in 2011-02-16 15:43:09.000000000 +0100
- +++ hunspell-1.3.2.devel/src/tools/Makefile.in 2013-01-27 13:10:54.303509429 +0100
- @@ -37,7 +37,8 @@ build_triplet = @build@
- host_triplet = @host@
- target_triplet = @target@
- bin_PROGRAMS = analyze$(EXEEXT) chmorph$(EXEEXT) hunspell$(EXEEXT) \
- - munch$(EXEEXT) unmunch$(EXEEXT) hzip$(EXEEXT) hunzip$(EXEEXT)
- + munch$(EXEEXT) unmunch$(EXEEXT) hzip$(EXEEXT) hunzip$(EXEEXT) \
- + hunspelld$(EXEEXT)
- noinst_PROGRAMS = example$(EXEEXT)
- subdir = src/tools
- DIST_COMMON = $(dist_bin_SCRIPTS) $(srcdir)/Makefile.am \
- @@ -86,6 +87,9 @@ hunspell_DEPENDENCIES = ../parsers/libpa
- am_hunzip_OBJECTS = hunzip.$(OBJEXT)
- hunzip_OBJECTS = $(am_hunzip_OBJECTS)
- hunzip_DEPENDENCIES = ../hunspell/libhunspell-1.3.la
- +am_hunspelld_OBJECTS = hunspelld.$(OBJEXT)
- +hunspelld_OBJECTS = $(am_hunspelld_OBJECTS)
- +hunspelld_DEPENDENCIES = ../hunspell/libhunspell-1.3.la
- am_hzip_OBJECTS = hzip.$(OBJEXT)
- hzip_OBJECTS = $(am_hzip_OBJECTS)
- hzip_LDADD = $(LDADD)
- @@ -141,10 +145,11 @@ CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBT
- $(LDFLAGS) -o $@
- SOURCES = $(analyze_SOURCES) $(chmorph_SOURCES) $(example_SOURCES) \
- $(hunspell_SOURCES) $(hunzip_SOURCES) $(hzip_SOURCES) \
- - $(munch_SOURCES) $(unmunch_SOURCES)
- + $(munch_SOURCES) $(unmunch_SOURCES) $(hunspelld_SOURCES)
- DIST_SOURCES = $(analyze_SOURCES) $(chmorph_SOURCES) \
- $(example_SOURCES) $(hunspell_SOURCES) $(hunzip_SOURCES) \
- - $(hzip_SOURCES) $(munch_SOURCES) $(unmunch_SOURCES)
- + $(hzip_SOURCES) $(munch_SOURCES) $(unmunch_SOURCES) \
- + $(hunspelld_SOURCES)
- ETAGS = etags
- CTAGS = ctags
- DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
- @@ -326,6 +331,8 @@ INCLUDES = -I${top_srcdir}/src/hunspell
- hzip_SOURCES = hzip.c
- hunzip_SOURCES = hunzip.cxx
- hunzip_LDADD = ../hunspell/libhunspell-1.3.la
- +hunspelld_SOURCES = hunspelld.cxx
- +hunspelld_LDADD = ../hunspell/libhunspell-1.3.la
- munch_SOURCES = munch.c munch.h
- unmunch_SOURCES = unmunch.c unmunch.h
- example_SOURCES = example.cxx
- @@ -440,6 +447,9 @@ hunspell$(EXEEXT): $(hunspell_OBJECTS) $
- hunzip$(EXEEXT): $(hunzip_OBJECTS) $(hunzip_DEPENDENCIES)
- @rm -f hunzip$(EXEEXT)
- $(CXXLINK) $(hunzip_OBJECTS) $(hunzip_LDADD) $(LIBS)
- +hunspelld$(EXEEXT): $(hunspelld_OBJECTS) $(hunspelld_DEPENDENCIES)
- + @rm -f hunspelld$(EXEEXT)
- + $(CXXLINK) $(hunspelld_OBJECTS) $(hunspelld_LDADD) $(LIBS)
- hzip$(EXEEXT): $(hzip_OBJECTS) $(hzip_DEPENDENCIES)
- @rm -f hzip$(EXEEXT)
- $(LINK) $(hzip_OBJECTS) $(hzip_LDADD) $(LIBS)
- @@ -495,6 +505,7 @@ distclean-compile:
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/example.Po@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hunspell.Po@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hunzip.Po@am__quote@
- +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hunspelld.Po@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hzip.Po@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/munch.Po@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unmunch.Po@am__quote@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement