--- gnuvd-1.0.3.orig/src/main.c +++ gnuvd-1.0.3/src/main.c @@ -21,10 +21,18 @@ #include #endif /*HAVE_CONFIG*/ +#define _GNU_SOURCE /*for vasprintf*/ + #include +#include #include #include #include +#include +#include +#include +#include +#include #include "gnuvd.h" @@ -37,6 +45,8 @@ /* internal functions */ static void show_results (Buffer *results, int keep_entities); static char get_special_char (char *str); +static int iconv_str (iconv_t cd, char **output, char *input); +static void fprintf_iconv (FILE *f, iconv_t cd, const char *fmt, ...); static void help (); int @@ -44,10 +54,13 @@ { int keep_entities = 0; char *word = NULL; + iconv_t cd; VDQuery *vd_query = NULL; VDError vd_ex; + setlocale(LC_CTYPE, ""); + while (1) { int c = getopt (argc, argv, "kh"); @@ -73,10 +86,17 @@ break; } + cd = iconv_open("ISO-8859-1", nl_langinfo(CODESET)); + if (cd != (iconv_t)(-1)) { + iconv_str(cd, &word, argv[optind]); + iconv_close(cd); + } + if (!word) + /* let's hope for the best */ word = argv[optind]; - vd_ex = VD_ERR_OK; /* prepare query */ + vd_ex = VD_ERR_OK; vd_query = vd_query_new (word, &vd_ex); if (!vd_query) { if (vd_ex != VD_ERR_OK) @@ -116,9 +136,18 @@ char s_kars[S_KARS_MAX + 2]; int skip_spc = 1; int stress_pos; + iconv_t cd; FILE *out = stdout; + cd = iconv_open(nl_langinfo(CODESET), "ISO-8859-1"); + if (cd == (iconv_t)(-1)) { + fprintf(stderr, + "Can't convert from ISO-8859-1 to your locale's charset. " + "Complain to your\noperating system vendor."); + exit(1); + } + /* output to PAGER or to STDOUT? */ if (isatty(fileno(stdin)) && isatty(fileno(stdout))) { char *pager = getenv("PAGER"); @@ -129,7 +158,6 @@ } } - /* strip superfluous space after */ for (i = buffer_end (buffer) - 1; i >= buffer_begin(buffer) + 3; --i) if ((buffer_at (buffer, i-3) == 'D') && @@ -144,7 +172,7 @@ /* Keep <=> */ if (buffer_end(buffer) - j > 3) { if ((strncmp (buffer_data_pos(buffer,j), "<=>", 3) == 0)) { - fprintf (out, "<=>"); + fprintf_iconv (out, cd, "<=>"); j+= 2; continue; } @@ -161,7 +189,7 @@ /* SMALL -> */ if (buffer_end(buffer) - j > 7) { if ((strncmp (buffer_data_pos(buffer,j),"", 7) == 0)) { - fprintf (out, " ("); + fprintf_iconv (out, cd, " ("); j += 6; continue; } @@ -170,7 +198,7 @@ /* /SMALL -> */ if (buffer_end(buffer) - j > 8) { if ((strncmp (buffer_data_pos(buffer,j),"", 8) == 0)) { - fprintf (out, ")"); + fprintf_iconv (out, cd, ")"); j += 7; continue; } @@ -181,7 +209,7 @@ if (buffer_end(buffer) - j > 8 && strncmp(buffer_data_pos(buffer,j), "
", 7) == 0) { j += 6; - fprintf (out, "\n"); + fprintf_iconv (out, cd, "\n"); continue; } @@ -202,7 +230,7 @@ m_pos = buffer_find_offset (buffer,j,"·",6); if (stress_pos!=buffer_end(buffer) && stress_pos < dd_pos && stress_pos < m_pos) { - fprintf (out, "`"); + fprintf_iconv (out, cd, "`"); j += (strncmp(buffer_data_pos(buffer,j),"", 5) == 0) ? 4 : 5; continue; } @@ -228,7 +256,7 @@ k = get_special_char (s_kars); if (k) - fprintf (out, "%c", k); + fprintf_iconv (out, cd, "%c", k); } continue; } @@ -240,8 +268,17 @@ else skip_spc = 0; } - fprintf (out, "%c", buffer_at(buffer,j)); - } + + /* convert DOS-style CR/LF line-endings to Unix-style LF */ + if (buffer_at(buffer,j) == 13) + continue; + + fprintf_iconv (out, cd, "%c", buffer_at(buffer,j)); + } + + iconv_close(cd); + + fprintf (out, "\n"); /* if we were outputing to PAGER, close it */ if (out != stdout) { @@ -364,6 +401,77 @@ return '?'; } +static int +iconv_str (iconv_t cd, char **output, char *input) +{ + size_t inleft; + size_t outsize, outleft; + size_t result; + char *outbuf; + + if (!input) + return -1; + + outsize = outleft = 16; + *output = outbuf = malloc(outsize); + if (!*output) + return -1; + + inleft = strlen(input) + 1; + while (inleft > 0) { + result = iconv(cd, &input, &inleft, &outbuf, &outleft); + if (result == (size_t)(-1)) { + /* iconv might error out because the output buffer is + * full, or because there's something wrong with the + * input (an incomplete multibyte character, for + * example). We only deal with the first case. + */ + if (errno == E2BIG) { + char *new; + outleft += outsize; + outsize *= 2; + new = realloc(*output, outsize); + if (!new) + goto fail; + *output = new; + outbuf = *output + outsize - outleft; + } else + goto fail; + } + } + + return outsize - outleft; + +fail: + /* Something went wrong. Reset iconv and free the output buffer */ + iconv(cd, 0, 0, 0, 0); + free(*output); + *output = 0; + return -1; +} + +static void +fprintf_iconv (FILE *f, iconv_t cd, const char *fmt, ...) +{ + va_list va; + char *str, *converted; + int result; + + va_start(va, fmt); + result = vasprintf(&str, fmt, va); + if (result < 0) + return; /*out of memory...*/ + va_end(va); + + result = iconv_str(cd, &converted, str); + free(str); + if (result < 0) + return; /*out or memory, or something even nastier...*/ + + fputs(converted, f); + free(converted); +} + static void help() --- gnuvd-1.0.3.orig/src/gnuvd.c +++ gnuvd-1.0.3/src/gnuvd.c @@ -50,16 +50,16 @@ "q=0.2,text/css,*/*;q=0.1\r\n" \ "Accept-Language: nl, en\r\n" \ "Accept-Charset: ISO-8859-1\r\n" \ -"Keep-Alive: 300\r\n" \ -"Connection: keep-alive\r\n" \ "Referer: http://www.vandale.nl/opzoeken/woordenboek/?zoekwoord=%s\r\n" \ "\r\n" +//"Keep-Alive: 300\r\n" \ +//"Connection: keep-alive\r\n" \ #define HTTP_REQUEST \ "GET /opzoeken/woordenboek/?zoekwoord=%s HTTP/1.1\r\n" HTTP_HEADERS #define HTTP_REQUEST_PROXY \ -"GET http://www.vandale.nl/opzoeken/woordenboek/?zoekwoord=%s HTTP/1.1\r\n" HTTP_HEADERS +"GET http://www.vandale.nl/opzoeken/woordenboek/?zoekwoord=%s HTTP/1.0\r\n" HTTP_HEADERS static char* HTTP_PROXY_HOST = NULL; static char* HTTP_PROXY_PORT = NULL; @@ -299,9 +299,28 @@ static char* vd_construct_http_query (const char *search_term, VDError *ex) { - char *query; - int len= strlen(HTTP_PROXY_HOST ? HTTP_REQUEST_PROXY : HTTP_REQUEST) + - strlen(search_term) * 2; + char *query, *encoded_search_term, *pos; + int len, i; + + /* The worst that can happen is that all chars need encoding */ + encoded_search_term = + (char *) malloc((3 * strlen(search_term) + 1) * sizeof(char)); + pos = encoded_search_term; + + if (!pos) { + *ex = VD_ERR_MEM; + return NULL; + } + + for (i=0; i on +Wed, 22 Aug 2001 12:05:15 +0200. + +It was downloaded from http://linux.denhaag.org/gnuvd/ + +Upstream Author: Dirk-Jan C. Binnema + +Copyright: + +GPL version 2, see /usr/share/common-licenses/GPL. --- gnuvd-1.0.3.orig/debian/gnuvd-gnome.dirs +++ gnuvd-1.0.3/debian/gnuvd-gnome.dirs @@ -0,0 +1 @@ +/usr/bin --- gnuvd-1.0.3.orig/debian/gnuvd-gnome.files +++ gnuvd-1.0.3/debian/gnuvd-gnome.files @@ -0,0 +1,2 @@ +usr/bin/gnovd +usr/share/man/man1/gnovd.1 --- gnuvd-1.0.3.orig/debian/gnuvd.dirs +++ gnuvd-1.0.3/debian/gnuvd.dirs @@ -0,0 +1 @@ +/usr/bin --- gnuvd-1.0.3.orig/debian/gnuvd.files +++ gnuvd-1.0.3/debian/gnuvd.files @@ -0,0 +1,2 @@ +usr/bin/gnuvd +usr/share/man/man1/gnuvd.1 --- gnuvd-1.0.3.orig/debian/gnuvd-gnome.menu +++ gnuvd-1.0.3/debian/gnuvd-gnome.menu @@ -0,0 +1,3 @@ +?package(gnuvd-gnome):command="/usr/bin/gnovd" \ + needs="x11" section="Apps/Text" \ + title="Gnuvd" --- gnuvd-1.0.3.orig/debian/gnuvd-gnome.docs +++ gnuvd-1.0.3/debian/gnuvd-gnome.docs @@ -0,0 +1,2 @@ +README +README.nl --- gnuvd-1.0.3.orig/debian/gnuvd.docs +++ gnuvd-1.0.3/debian/gnuvd.docs @@ -0,0 +1,2 @@ +README +README.nl --- gnuvd-1.0.3.orig/debian/rules +++ gnuvd-1.0.3/debian/rules @@ -0,0 +1,85 @@ +#!/usr/bin/make -f +# Sample debian/rules that uses debhelper. +# GNU copyright 1997 to 1999 by Joey Hess. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + ./configure --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info + + touch configure-stamp + +build: configure-stamp build-stamp +build-stamp: + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + #/usr/bin/docbook-to-man debian/gnuvd.sgml > gnuvd.1 + + touch build-stamp + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + -$(MAKE) distclean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/tmp. + $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp + install contrib/gnovd.sh debian/tmp/usr/bin/gnovd + install -m 644 debian/gnovd.1 debian/tmp/usr/share/man/man1/ + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_movefiles + +# dh_installdebconf + dh_installdocs + dh_installexamples + dh_installmenu +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_installinit + dh_installcron + dh_installman + dh_installinfo +# dh_undocumented + dh_installchangelogs + dh_link + dh_strip + dh_compress + dh_fixperms + dh_makeshlibs + dh_installdeb +# dh_perl + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure --- gnuvd-1.0.3.orig/debian/gnovd.1 +++ gnuvd-1.0.3/debian/gnovd.1 @@ -0,0 +1,29 @@ +.Dd 2001-04-03 +.Dt GNOVD 8 +.Os "Debian GNU/Linux" +.\" Manual page created by Guus Sliepen +.Sh NAME +.Nm gnovd +.Nd Query the online Dutch Van Dale dictionary. +.Sh SYNOPSIS +.Nm +.Op Ar word +.Sh DESCRIPTION +.Nm +is a Gnome frontend for the online Van Dale dictionary. +It will search any word in the dictionary and return it's description in Dutch. +.Sh NOTES +You need to have an active internet connection in order to use this +program. Also, if you're behind a proxy-server, you have to set the +http_proxy environment variable as in Lynx. +.Sh SEE ALSO +.Xr gnuvd 1 , +.Pa http://www.vandale.nl/ +.Sh AUTHOR +.Nm +has been written by +.An Dirk-Jan C. Binnema Aq djcb@djcbsoftware.nl . +.Pp +This manual page was written by +.An Guus Sliepen Aq guus@sliepen.warande.net +for the Debian GNU/Linux system. --- gnuvd-1.0.3.orig/debian/control +++ gnuvd-1.0.3/debian/control @@ -0,0 +1,30 @@ +Source: gnuvd +Section: contrib/text +Priority: optional +Maintainer: Guus Sliepen +Build-Depends: debhelper (>> 4.0.0) +Standards-Version: 3.7.2 + +Package: gnuvd +Architecture: any +Section: contrib/text +Depends: ${shlibs:Depends} +Description: Query the online Dutch Van Dale dictionary + This program is a frontend for the online Van Dale dictionary, + http://www.vandale.nl/. It will search any word in the dictionary and return + its description in Dutch. Van Dale is a well known producer of dictionaries + in the Netherlands. + . + This package provides the commandline frontend. + +Package: gnuvd-gnome +Architecture: all +Section: contrib/text +Depends: ${shlibs:Depends}, zenity, recode, gnuvd +Description: Query the online Dutch Van Dale dictionary - Gnome frontend + This program is a frontend for the online Van Dale dictionary, + http://www.vandale.nl/. It will search any word in the dictionary and return + its description in Dutch. Van Dale is a well known producer of dictionaries + in the Netherlands. + . + This package provides the Gnome frontend. --- gnuvd-1.0.3.orig/debian/compat +++ gnuvd-1.0.3/debian/compat @@ -0,0 +1 @@ +4 --- gnuvd-1.0.3.orig/debian/changelog +++ gnuvd-1.0.3/debian/changelog @@ -0,0 +1,143 @@ +gnuvd (1.0.3-4) unstable; urgency=low + + * Properly terminate the encoded search string. Really closes: #235819 + + -- Guus Sliepen Wed, 11 Apr 2007 14:30:19 +0200 + +gnuvd (1.0.3-3) unstable; urgency=low + + * Apply patch from Tim Dijkstra properly encoding the request URL. + Closes: #235819 + * Apply patch from Tim Dijkstra recoding the output to the user's current + locale's character set. Closes: #189456, #368736 + + -- Guus Sliepen Thu, 05 Apr 2007 13:35:00 +0200 + +gnuvd (1.0.3-2) unstable; urgency=low + + * Add newline to output. Closes: #417470 + + -- Guus Sliepen Tue, 03 Apr 2007 12:40:56 +0200 + +gnuvd (1.0.3-1) unstable; urgency=low + + * New upstream release. Closes: #345333 + * Disable keep-alive header in HTTP request and use HTTP/1.0 when talking to + proxies, because gnuvd expects the server to close the connection. + + -- Guus Sliepen Wed, 4 Jan 2006 00:04:40 +0100 + +gnuvd (1.0-1) unstable; urgency=low + + * New upstream release. + + -- Guus Sliepen Sat, 12 Feb 2005 13:50:39 +0100 + +gnuvd (0.9.8+1.0beta5-1) unstable; urgency=low + + * New upstream release. Closes: #263966 + + -- Guus Sliepen Sat, 9 Oct 2004 13:58:48 +0200 + +gnuvd (0.9.8+1.0beta4-1) unstable; urgency=low + + * New upstream release. + + -- Guus Sliepen Mon, 4 Aug 2003 11:45:53 +0200 + +gnuvd (0.9.8+1.0beta3-1) unstable; urgency=low + + * New upstream release. + + -- Guus Sliepen Fri, 27 Jun 2003 17:30:04 +0200 + +gnuvd (0.9.8+1.0beta1-1) unstable; urgency=low + + * New upstream release. + * Compile against libgal23. Closes: #191979 + + -- Guus Sliepen Wed, 7 May 2003 10:05:08 +0200 + +gnuvd (0.9.8+0.9.9-beta-2) unstable; urgency=low + + * Show helpful error message when connection fails. Closes: #170770 + * Fix compiler warnings. + + -- Guus Sliepen Wed, 27 Nov 2002 14:18:24 +0100 + +gnuvd (0.9.8+0.9.9-beta-1) unstable; urgency=low + + * New upstream release. Closes: #145056 + + -- Guus Sliepen Sun, 19 May 2002 11:09:12 +0200 + +gnuvd (0.9.8-3) unstable; urgency=low + + * Fix libgnuvd to handle new layout of the Van Dale website. + Closes: #140307 + + -- Guus Sliepen Sun, 31 Mar 2002 14:21:07 +0200 + +gnuvd (0.9.8-2) unstable; urgency=low + + * Recompile against libgal19. Closes: #133839 + + -- Guus Sliepen Thu, 14 Feb 2002 10:23:37 +0100 + +gnuvd (0.9.8-1) unstable; urgency=low + + * New upstream release. Closes: #128297 + + -- Guus Sliepen Thu, 10 Jan 2002 14:54:39 +0100 + +gnuvd (0.9.7-5) unstable; urgency=low + + * Added entry to Debian's menu system. + + -- Guus Sliepen Wed, 12 Dec 2001 23:11:40 +0100 + +gnuvd (0.9.7-4) unstable; urgency=low + + * Recompile against libgal18 and libgtkhtml19. Closes: #119169 + + -- Guus Sliepen Mon, 12 Nov 2001 17:00:32 +0100 + +gnuvd (0.9.7-3) unstable; urgency=low + + * Recompile against libgal17 and libgtkhtml18. + + -- Guus Sliepen Tue, 6 Nov 2001 16:12:49 +0100 + +gnuvd (0.9.7-2) unstable; urgency=low + + * Moved packages from main to contrib, since gnuvd relies on the non-free + www.vandale.nl site. + * Recompile against libgal13. + + -- Guus Sliepen Tue, 9 Oct 2001 15:20:53 +0200 + +gnuvd (0.9.7-1) unstable; urgency=low + + * New upstream release. Closes: #110404 + + -- Guus Sliepen Sat, 8 Sep 2001 15:07:49 +0200 + +gnuvd (0.9.6-2) unstable; urgency=low + + * Fixed typo in description. Closes: #110054 + * Recompile against latest libgal packages. Closes: #110752 + * Use correct section for library and development package. + + -- Guus Sliepen Fri, 31 Aug 2001 11:26:56 +0200 + +gnuvd (0.9.6-1) unstable; urgency=low + + * New upstream release. + + -- Guus Sliepen Fri, 24 Aug 2001 19:31:32 +0200 + +gnuvd (0.9.5-1) unstable; urgency=low + + * Initial Release. + + -- Guus Sliepen Wed, 22 Aug 2001 12:05:15 +0200