--- po/hunspell.pot~	2011-02-16 16:45:11.000000000 +0200
+++ po/hunspell.pot	2012-03-21 08:06:41.376862300 +0200
@@ -75,50 +75,50 @@
 msgstr ""
 
 #: src/tools/hunspell.cxx:1017
-msgid "R\tReplace the misspelled word completely.\n"
+msgid "R       Replace the misspelled word completely.\n"
 msgstr ""
 
 #: src/tools/hunspell.cxx:1018
-msgid "Space\tAccept the word this time only.\n"
+msgid "Space   Accept the word this time only.\n"
 msgstr ""
 
 #: src/tools/hunspell.cxx:1019
-msgid "A\tAccept the word for the rest of this session.\n"
+msgid "A       Accept the word for the rest of this session.\n"
 msgstr ""
 
 #: src/tools/hunspell.cxx:1020
-msgid "I\tAccept the word, and put it in your private dictionary.\n"
+msgid "I       Accept the word, and put it in your private dictionary.\n"
 msgstr ""
 
 #: src/tools/hunspell.cxx:1021
-msgid "U\tAccept and add lowercase version to private dictionary.\n"
+msgid "U       Accept and add lowercase version to private dictionary.\n"
 msgstr ""
 
 #: src/tools/hunspell.cxx:1023
 msgid ""
-"S\tAsk a stem and a model word and store them in the private dictionary.\n"
-"\tThe stem will be accepted also with the affixes of the model word.\n"
+"S       Ask a stem and a model word and store them in the private dictionary.\n"
+"        The stem will be accepted also with the affixes of the model word.\n"
 msgstr ""
 
 #: src/tools/hunspell.cxx:1026
-msgid "0-n\tReplace with one of the suggested words.\n"
+msgid "0-n     Replace with one of the suggested words.\n"
 msgstr ""
 
 #: src/tools/hunspell.cxx:1027
 msgid ""
-"X\tWrite the rest of this file, ignoring misspellings, and start next file.\n"
+"X       Write the rest of this file, ignoring misspellings, and start next file.\n"
 msgstr ""
 
 #: src/tools/hunspell.cxx:1028
-msgid "Q\tQuit immediately. Asks for confirmation. Leaves file unchanged.\n"
+msgid "Q       Quit immediately. Asks for confirmation. Leaves file unchanged.\n"
 msgstr ""
 
 #: src/tools/hunspell.cxx:1029
-msgid "^Z\tSuspend program. Restart with fg command.\n"
+msgid "^Z      Suspend program. Restart with fg command.\n"
 msgstr ""
 
 #: src/tools/hunspell.cxx:1030
-msgid "?\tShow this help screen.\n"
+msgid "?       Show this help screen.\n"
 msgstr ""
 
 #: src/tools/hunspell.cxx:1031
--- po/it.po~	2011-02-16 16:45:11.000000000 +0200
+++ po/it.po	2012-03-21 08:13:37.345612300 +0200
@@ -93,59 +93,59 @@
 "\n"
 
 #: src/tools/hunspell.cxx:1017
-msgid "R\tReplace the misspelled word completely.\n"
-msgstr "R\tSostituisce la parola sbagliata\n"
+msgid "R       Replace the misspelled word completely.\n"
+msgstr "R       Sostituisce la parola sbagliata\n"
 
 #: src/tools/hunspell.cxx:1018
-msgid "Space\tAccept the word this time only.\n"
-msgstr "Spazio\tAccetta la parola solo per questa volta\n"
+msgid "Space   Accept the word this time only.\n"
+msgstr "Spazio  Accetta la parola solo per questa volta\n"
 
 #: src/tools/hunspell.cxx:1019
-msgid "A\tAccept the word for the rest of this session.\n"
-msgstr "A\tAccetta la parola per il resto di questa sessione\n"
+msgid "A       Accept the word for the rest of this session.\n"
+msgstr "A       Accetta la parola per il resto di questa sessione\n"
 
 #: src/tools/hunspell.cxx:1020
-msgid "I\tAccept the word, and put it in your private dictionary.\n"
-msgstr "I\tAccetta la parola e la inserisce nel dizionario privato\n"
+msgid "I       Accept the word, and put it in your private dictionary.\n"
+msgstr "I       Accetta la parola e la inserisce nel dizionario privato\n"
 
 #: src/tools/hunspell.cxx:1021
-msgid "U\tAccept and add lowercase version to private dictionary.\n"
+msgid "U       Accept and add lowercase version to private dictionary.\n"
 msgstr ""
-"U\tAccetta la parola e la inserisce in minuscolo nel dizionario privato\n"
+"U       Accetta la parola e la inserisce in minuscolo nel dizionario privato\n"
 
 #: src/tools/hunspell.cxx:1023
 msgid ""
-"S\tAsk a stem and a model word and store them in the private dictionary.\n"
-"\tThe stem will be accepted also with the affixes of the model word.\n"
+"S       Ask a stem and a model word and store them in the private dictionary.\n"
+"        The stem will be accepted also with the affixes of the model word.\n"
 msgstr ""
-"S\tChiede la parte principale e il modello di una parola e li archivia nel "
+"S       Chiede la parte principale e il modello di una parola e li archivia nel "
 "dizionario privato;\n"
-"\tla parte principale viene accettata anche con gli affissi della parola "
+"        la parte principale viene accettata anche con gli affissi della parola "
 "modello\n"
 
 #: src/tools/hunspell.cxx:1026
-msgid "0-n\tReplace with one of the suggested words.\n"
-msgstr "0-n\tSostituisce con una delle parole suggerite\n"
+msgid "0-n     Replace with one of the suggested words.\n"
+msgstr "0-n     Sostituisce con una delle parole suggerite\n"
 
 #: src/tools/hunspell.cxx:1027
 msgid ""
-"X\tWrite the rest of this file, ignoring misspellings, and start next file.\n"
+"X       Write the rest of this file, ignoring misspellings, and start next file.\n"
 msgstr ""
-"X\tScrive il resto del file ignorando gli errori e inizia con il file "
+"X       Scrive il resto del file ignorando gli errori e inizia con il file "
 "successivo\n"
 
 #: src/tools/hunspell.cxx:1028
-msgid "Q\tQuit immediately. Asks for confirmation. Leaves file unchanged.\n"
+msgid "Q       Quit immediately. Asks for confirmation. Leaves file unchanged.\n"
 msgstr ""
-"Q\tChiude immediatamente, chiede conferma e lascia il file non modificato\n"
+"Q       Chiude immediatamente, chiede conferma e lascia il file non modificato\n"
 
 #: src/tools/hunspell.cxx:1029
-msgid "^Z\tSuspend program. Restart with fg command.\n"
-msgstr "^Z\tSospende il programma; per riavviarlo, usare il comando fg\n"
+msgid "^Z      Suspend program. Restart with fg command.\n"
+msgstr "^Z      Sospende il programma; per riavviarlo, usare il comando fg\n"
 
 #: src/tools/hunspell.cxx:1030
-msgid "?\tShow this help screen.\n"
-msgstr "?\tMostra questo aiuto\n"
+msgid "?       Show this help screen.\n"
+msgstr "?       Mostra questo aiuto\n"
 
 #: src/tools/hunspell.cxx:1031
 msgid ""
--- po/hu.po~	2012-03-21 08:06:30.000000000 +0200
+++ po/hu.po	2012-03-21 15:50:26.360512300 +0200
@@ -93,25 +93,30 @@
 msgstr "C       A hibás szó kicserélése egy megadott szóra.\n"
 
 #: src/tools/hunspell.cxx:1018
-msgid "Space    Accept the word this time only.\n"
+#, fuzzy
+msgid "Space   Accept the word this time only.\n"
 msgstr "Szóköz   A szó egyszeri átugrása változtatás nélkül.\n"
 
 #: src/tools/hunspell.cxx:1019
 msgid "A       Accept the word for the rest of this session.\n"
-msgstr "J       A szó minden előfordulását jónak tekinti a program futása során.\n"
+msgstr ""
+"J       A szó minden előfordulását jónak tekinti a program futása során.\n"
 
 #: src/tools/hunspell.cxx:1020
 msgid "I       Accept the word, and put it in your private dictionary.\n"
 msgstr ""
-"F       A szót felveszi a saját szótárba, így új indításkor is ismerni fogja.\n"
+"F       A szót felveszi a saját szótárba, így új indításkor is ismerni "
+"fogja.\n"
 
 #: src/tools/hunspell.cxx:1021
 msgid "U       Accept and add lowercase version to private dictionary.\n"
-msgstr "K       Mint az előző, de a szót kisbetűsen veszi fel a saját szótárba.\n"
+msgstr ""
+"K       Mint az előző, de a szót kisbetűsen veszi fel a saját szótárba.\n"
 
 #: src/tools/hunspell.cxx:1023
 msgid ""
-"S       Ask a stem and a model word and store them in the private dictionary.\n"
+"S       Ask a stem and a model word and store them in the private "
+"dictionary.\n"
 "        The stem will be accepted also with the affixes of the model word.\n"
 msgstr ""
 "T       Szótő és mintaszó bekérése és saját szótárban való tárolása.\n"
@@ -123,12 +128,15 @@
 
 #: src/tools/hunspell.cxx:1027
 msgid ""
-"X       Write the rest of this file, ignoring misspellings, and start next file.\n"
+"X       Write the rest of this file, ignoring misspellings, and start next "
+"file.\n"
 msgstr "V       Menti az eddigi javításokat, és rátér a következő fájlra.\n"
 
 #: src/tools/hunspell.cxx:1028
-msgid "Q       Quit immediately. Asks for confirmation. Leaves file unchanged.\n"
-msgstr "M       Kilép a javítások mentése nélkül, de előtte megerősítést kér.\n"
+msgid ""
+"Q       Quit immediately. Asks for confirmation. Leaves file unchanged.\n"
+msgstr ""
+"M       Kilép a javítások mentése nélkül, de előtte megerősítést kér.\n"
 
 #: src/tools/hunspell.cxx:1029
 msgid "^Z      Suspend program. Restart with fg command.\n"
--- src/hunspell/suggestmgr.cxx~0	2011-02-06 23:01:37.000000000 +0200
+++ src/hunspell/suggestmgr.cxx	2013-02-07 10:08:50.176410900 +0200
@@ -678,7 +678,7 @@ int SuggestMgr::extrachar(char** wlst, c
 // error is missing a letter it needs
 int SuggestMgr::forgotchar(char ** wlst, const char * word, int ns, int cpdsuggest)
 {
-   char candidate[MAXSWUTF8L];
+   char candidate[MAXSWUTF8L + 4];
    char * p;
    clock_t timelimit = clock();
    int timer = MINTIMER;
@@ -700,8 +700,8 @@ int SuggestMgr::forgotchar(char ** wlst,
 // error is missing a letter it needs
 int SuggestMgr::forgotchar_utf(char ** wlst, const w_char * word, int wl, int ns, int cpdsuggest)
 {
-   w_char  candidate_utf[MAXSWL];
-   char    candidate[MAXSWUTF8L];
+   w_char  candidate_utf[MAXSWL + 1];
+   char    candidate[MAXSWUTF8L + 4];
    w_char * p;
    clock_t timelimit = clock();
    int timer = MINTIMER;
--- src/parsers/latexparser.cxx~0	2011-01-24 10:32:45.000000000 +0200
+++ src/parsers/latexparser.cxx	2013-02-07 11:30:23.117666300 +0200
@@ -217,6 +217,10 @@ char * LaTeXParser::next_token()
 		} // case
                 if (next_char(line[actual], &head)) {
 			if (state == 5) state = 0;
+			if (state == 4) {
+				if (depth == 0 && arg == 0 && PATTERN[pattern_num].arg == 1)
+					state = 0;
+			}
 			return NULL;
 		}
 	}
--- src/tools/hunspell.cxx~0	2011-01-21 19:01:29.000000000 +0200
+++ src/tools/hunspell.cxx	2013-02-07 10:11:54.443610900 +0200
@@ -6,6 +6,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <ctype.h>
 #include "config.h"
 #include "hunspell.hxx"
 #include "csutil.hxx"
@@ -28,20 +29,31 @@
 #ifdef WIN32
 
 #define LIBDIR "C:\\Hunspell\\"
-#define USEROOODIR "Application Data\\OpenOffice.org 2\\user\\wordbook"
+#define USEROOODIR ".openoffice.org\\3\\user\\wordbook"
+#define USEROOODIR2 "Application Data\\OpenOffice.org 2\\user\\wordbook"
 #define OOODIR \
     "C:\\Program files\\OpenOffice.org 2.4\\share\\dict\\ooo\\;" \
     "C:\\Program files\\OpenOffice.org 2.3\\share\\dict\\ooo\\;" \
     "C:\\Program files\\OpenOffice.org 2.2\\share\\dict\\ooo\\;" \
     "C:\\Program files\\OpenOffice.org 2.1\\share\\dict\\ooo\\;" \
     "C:\\Program files\\OpenOffice.org 2.0\\share\\dict\\ooo\\"
-#define HOME "%USERPROFILE%\\"
+#define HOME getenv("HOME")
+#define HOME2 getenv("USERPROFILE")
 #define DICBASENAME "hunspell_"
-#define LOGFILE "C:\\Hunspell\\log"
+#define LOGFILE add(mystrdup(getenv("TEMP")),"\\hunspell.log")
 #define DIRSEPCH '\\'
 #define DIRSEP "\\"
 #define PATHSEP ";"
+#define FNCMP stricmp
+#define TOLOWER(S) tolower(S)
 
+#ifdef __MINGW32__
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
+#endif
+#include <process.h>
 #include "textparser.hxx"
 #include "htmlparser.hxx"
 #include "latexparser.hxx"
@@ -70,6 +82,7 @@
     ".openoffice.org2/user/wordbook:" \
     ".openoffice.org2.0/user/wordbook:" \
     "Library/Spelling"
+#define USEROOODIR2 NULL
 #define OOODIR \
     "/opt/openoffice.org/basis3.0/share/dict/ooo:" \
     "/usr/lib/openoffice.org/basis3.0/share/dict/ooo:" \
@@ -84,11 +97,14 @@
     "/opt/openoffice.org2.0/share/dict/ooo:" \
     "/usr/lib/openoffice.org2.0/share/dict/ooo"
 #define HOME getenv("HOME")
+#define HOME2 NULL
 #define DICBASENAME ".hunspell_"
 #define LOGFILE "/tmp/hunspell.log"
 #define DIRSEPCH '/'
 #define DIRSEP "/"
 #define PATHSEP ":"
+#define FNCMP strcmp
+#define TOLOWER(S) (S)
 #endif
 
 #ifdef HAVE_ICONV
@@ -128,9 +144,13 @@ char text_conv[MAXLNLEN];
 #define readline scanline
 #endif
 
-#define TEMPNAME "hunSPELL.bak"
+#define TEMPNAME "hunSPELL%lu.bak"
 
 extern char * mystrdup(const char * s);
+#ifdef WIN32
+static char * w32exe_relative(const char * d);
+static char * w32console_codepage(void);
+#endif
 
 // file formats:
 
@@ -205,6 +225,7 @@ char * chenc(char * st, const char * enc
 	    fprintf(stderr, gettext("error - iconv_open: %s -> %s\n"), enc2, enc1);
 	} else {	
 	    size_t res = iconv(conv, (ICONV_CONST char **) &source, &c1, &dest, &c2);
+	    iconv(conv, NULL, NULL, &dest, &c2);
 	    iconv_close(conv);
 	    if (res != (size_t) -1) out = text_conv;
 	}
@@ -227,12 +248,15 @@ TextParser * get_parser(int format, char
 		io_utf8 = 1;
 		io_enc = "UTF-8";
 	}
+	if (filter_mode == PIPE)
+		ui_enc = io_enc;
     } else if (ui_enc) {
 	io_enc = ui_enc;
 	if (strcmp(ui_enc, "UTF-8") == 0) io_utf8 = 1;	
     } else {
 	io_enc = denc;
 	if (strcmp(denc, "UTF-8") == 0) io_utf8 = 1;
+	ui_enc = io_enc;
     }
 
     if (io_utf8) {
@@ -250,6 +274,7 @@ TextParser * get_parser(int format, char
 	        wordchars_utf16_len = 0;
 	    } else {
 	        iconv(conv, (ICONV_CONST char **) &wchars, &c1, &dest, &c2);
+		iconv(conv, NULL, NULL, &dest, &c2);
 	        iconv_close(conv);
 	        wordchars_utf16 = (unsigned short *) malloc(sizeof(unsigned short) * wlen);
 	        int n = u8_u16((w_char *) wordchars_utf16, wlen, text_conv);
@@ -282,6 +307,7 @@ TextParser * get_parser(int format, char
 	        if (res != (size_t) -1) {
 		    unsigned short idx;
 		    w_char w;
+		    iconv(conv, NULL, NULL, &dest, &c2);
 		    w.l = 0;
 		    w.h = 0;
 		    u8_u16(&w, 1, u8);
@@ -313,6 +339,7 @@ TextParser * get_parser(int format, char
 	        fprintf(stderr, gettext("error - iconv_open: %s -> %s\n"), io_enc, denc);
 	    } else {
 	        iconv(conv, (ICONV_CONST char **) &wchars, &c1, &dest, &c2);
+		iconv(conv, NULL, NULL, &dest, &c2);
 	        iconv_close(conv);
 	        *dest = '\0';
 	    }
@@ -352,9 +379,9 @@ TextParser * get_parser(int format, char
     }
 
     if ((!p) && (extension)) {
-	if ((strcmp(extension, "html") == 0) ||
-    	    (strcmp(extension, "htm") == 0) ||
-	    (strcmp(extension, "xml") == 0)) {
+	if ((FNCMP(extension, "html") == 0) ||
+    	    (FNCMP(extension, "htm") == 0) ||
+	    (FNCMP(extension, "xml") == 0)) {
                 if (io_utf8) {
                     p = new HTMLParser(wordchars_utf16, wordchars_utf16_len);
                 } else {
@@ -366,7 +393,7 @@ TextParser * get_parser(int format, char
                 } else {
 	            p = new ManParser(wordchars);
                 }
-	} else if ((strcmp(extension, "tex") == 0)) {
+	} else if ((FNCMP(extension, "tex") == 0)) {
                 if (io_utf8) {
                     p = new LaTeXParser(wordchars_utf16, wordchars_utf16_len);
                 } else {
@@ -476,6 +503,15 @@ char * basename(char * s, char c) {
     char * p = s + strlen(s);
     while ((*p != c) && (p != s)) p--;
     if (*p == c) p++;
+#ifdef WIN32
+    if (c == DIRSEPCH) {
+	// Handle mixed forward- and back-slashes
+	char * p2 = basename(p, '/');
+	if (p2 > p) p = p2;
+	// Handle d:foo
+	if (p == s && s[0] && s[1] == ':') p = s + 2;
+    }
+#endif
     return p;
 }
 
@@ -561,13 +597,12 @@ nextline: while(fgets(buf, MAXLNLEN, fil
         break;
     }
     case '#': {
-	if (HOME) strcpy(buf,HOME); else {
+	if (HOME) strcpy(buf,HOME);
+	else if (HOME2) strcpy(buf,HOME2); else {
 	    fprintf(stderr, gettext("error - missing HOME variable\n"));
 	    continue;
 	}
-#ifndef WIN32
-	strcat(buf,"/");
-#endif
+	strcat(buf,DIRSEP);
 	buf2 = buf+strlen(buf);
 	if (!privdicname) {
 		strcat(buf,DICBASENAME);
@@ -583,6 +618,9 @@ nextline: while(fgets(buf, MAXLNLEN, fil
     case '^': {
 		pos = 1;
     }
+    case '~': {	// not implemented -- ignore the entire line
+	break;
+    }
 
     default: {
 	pos = 0;
@@ -710,13 +748,22 @@ if (pos >= 0) {
 			fflush(stdout);
 		} else {
 			char ** wlst = NULL;
-			int ns = pMS[d]->suggest(&wlst, token);
+			int byte_offset = parser->get_tokenpos() + pos;
+			int char_offset = 0;
+			if (strcmp(io_enc, "UTF-8") == 0) {
+				for (int i = 0; i < byte_offset; i++) {
+					if ((buf[i] & 0xc0) != 0x80)
+						char_offset++;
+				}
+			} else {
+				char_offset = byte_offset;
+			}
+			int ns = pMS[d]->suggest(&wlst, chenc(token, io_enc, dic_enc[d]));
 			if (ns == 0) {
-		    		fprintf(stdout,"# %s %d", token,
-		    		    parser->get_tokenpos() + pos);
+		    		fprintf(stdout,"# %s %d", token, char_offset);
 			} else {
 				fprintf(stdout,"& %s %d %d: ", token, ns,
-				    parser->get_tokenpos() + pos);
+					char_offset);
 				fprintf(stdout,"%s", chenc(wlst[0], dic_enc[d], io_enc));
 			}
 			for (int j = 1; j < ns; j++) {
@@ -745,13 +792,23 @@ if (pos >= 0) {
 			if (root) free(root);
 		} else {
 			char ** wlst = NULL;
+			int byte_offset = parser->get_tokenpos() + pos;
+			int char_offset = 0;
+			if (strcmp(io_enc, "UTF-8") == 0) {
+				for (int i = 0; i < byte_offset; i++) {
+					if ((buf[i] & 0xc0) != 0x80)
+						char_offset++;
+				}
+			} else {
+				char_offset = byte_offset;
+			}
 			int ns = pMS[d]->suggest(&wlst, chenc(token, io_enc, dic_enc[d]));
 			if (ns == 0) {
 		    		fprintf(stdout,"# %s %d", chenc(token, io_enc, ui_enc),
-		    		    parser->get_tokenpos() + pos);
+		    		    char_offset);
 			} else {
 				fprintf(stdout,"& %s %d %d: ", chenc(token, io_enc, ui_enc), ns,
-				    parser->get_tokenpos() + pos);
+				    char_offset);
 				fprintf(stdout,"%s", chenc(wlst[0], dic_enc[d], ui_enc));
 			}
 			for (int j = 1; j < ns; j++) {
@@ -887,9 +944,16 @@ void dialogscreen(TextParser * parser, c
 	getmaxyx(stdscr,y,x);
 	clear();
 
-	if (forbidden & SPELL_FORBIDDEN) printw(gettext("FORBIDDEN!")); else
-	  if (forbidden & SPELL_WARN) printw(gettext("Spelling mistake?"));
-	printw(gettext("\t%s\t\tFile: %s\n\n"), chenc(token, io_enc, ui_enc), filename);
+	// handle tabs in header line
+	snprintf(line, sizeof(line), "%s\t%s\t\t",
+		 (forbidden & SPELL_FORBIDDEN)
+		 ? gettext("FORBIDDEN!")
+		 : ((forbidden & SPELL_WARN)
+		    ? gettext("Spelling mistake?")
+		    : ""),
+		 chenc(token, io_enc, ui_enc));
+	expand_tab(line2, line, MAXLNLEN);
+	printw("%sFile: %s\n\n", line2, filename);
 
 	// handle long lines and tabulators
 
@@ -1014,20 +1078,19 @@ printw(gettext("Whenever a word is found
     "next to each one.  You have the option of replacing the word\n"
     "completely, or choosing one of the suggested words.\n"));
 printw(gettext("\nCommands are:\n\n"));
-printw(gettext("R	Replace the misspelled word completely.\n"));
-printw(gettext("Space	Accept the word this time only.\n"));
-printw(gettext("A	Accept the word for the rest of this session.\n"));
-printw(gettext("I	Accept the word, and put it in your private dictionary.\n"));
-printw(gettext("U	Accept and add lowercase version to private dictionary.\n"));
-printw(gettext(
-"S\tAsk a stem and a model word and store them in the private dictionary.\n"
-"\tThe stem will be accepted also with the affixes of the model word.\n"
+printw(gettext("R       Replace the misspelled word completely.\n"));
+printw(gettext("Space   Accept the word this time only.\n"));
+printw(gettext("A       Accept the word for the rest of this session.\n"));
+printw(gettext("I       Accept the word, and put it in your private dictionary.\n"));
+printw(gettext("U       Accept and add lowercase version to private dictionary.\n"));
+printw(gettext("S       Ask a stem and a model word and store them in the private dictionary.\n"
+               "        The stem will be accepted also with the affixes of the model word.\n"
 ));
-printw(gettext("0-n	Replace with one of the suggested words.\n"));
-printw(gettext("X	Write the rest of this file, ignoring misspellings, and start next file.\n"));
-printw(gettext("Q	Quit immediately. Asks for confirmation. Leaves file unchanged.\n"));
-printw(gettext("^Z	Suspend program. Restart with fg command.\n"));
-printw(gettext("?	Show this help screen.\n"));
+printw(gettext("0-n     Replace with one of the suggested words.\n"));
+printw(gettext("X       Write the rest of this file, ignoring misspellings, and start next file.\n"));
+printw(gettext("Q       Quit immediately. Asks for confirmation. Leaves file unchanged.\n"));
+printw(gettext("^Z      Suspend program. Restart with fg command.\n"));
+printw(gettext("?       Show this help screen.\n"));
 printw(gettext("\n-- Type space to continue -- \n"));
 	    while (getch()!=' ');
 	}
@@ -1035,6 +1098,29 @@ printw(gettext("\n-- Type space to conti
     	    dialogscreen(parser, token, filename, forbidden, wlst, ns);
 	    break;
 	}
+#ifdef WIN32
+	case 26: {
+	    /* Simulate Posix SIGTSTP signal by spawning a
+	       subsidiary shell.  */
+	    const char *argv[2];
+	    const char *shell = getenv ("COMSPEC");
+
+	    if (shell) {
+		argv[0] = " /k";
+		argv[1] = NULL;
+#ifdef HAVE_READLINE
+		endwin();
+#endif
+		_spawnvp (_P_WAIT, shell, argv);
+#ifdef HAVE_READLINE
+		initscr();
+		cbreak();
+#endif
+		dialogscreen(parser, token, filename, forbidden, wlst, ns);
+	    }
+	    break;
+	}
+#endif
 	default: {
 /* TRANSLATORS: translate this letter according to the shortcut letter used
    previously in the  translation of "R)epl" before */
@@ -1080,13 +1166,12 @@ printw(gettext("\n-- Type space to conti
 		i->next = dicwords;
 		dicwords = i;
 		// save
-		if (HOME) strcpy(buf,HOME); else {
+		if (HOME) strcpy(buf,HOME);
+		else if (HOME2) strcpy(buf,HOME2); else {
 		    fprintf(stderr, gettext("error - missing HOME variable\n"));
 		    break;
 		}
-#ifndef WIN32
-		strcat(buf,"/");
-#endif
+		strcat(buf,DIRSEP);
 		buf2 = buf+strlen(buf);
 		if (!privdicname) {
 			strcat(buf,DICBASENAME);
@@ -1210,13 +1295,12 @@ printw(gettext("\n-- Type space to conti
 		    }
 		    // save
 		    		    
-		    if (HOME) strcpy(buf,HOME); else {
+		    if (HOME) strcpy(buf,HOME);
+		    else if (HOME2) strcpy(buf,HOME2); else {
 			fprintf(stderr, gettext("error - missing HOME variable\n"));
 			continue;
 		    }
-#ifndef WIN32
-		    strcat(buf,"/");
-#endif
+		    strcat(buf,DIRSEP);
 		    buf2 = buf + strlen(buf);
 		    if (!privdicname) {
 			    strcat(buf,DICBASENAME);
@@ -1316,9 +1400,9 @@ void interactive_interface(Hunspell ** p
     char * extension = basename(filename, '.');
     parser = get_parser(format, extension, pMS[0]);
 
-    char * tempname = (char *) malloc(strlen(filename) + strlen(TEMPNAME) + 1);
+    char * tempname = (char *) malloc(strlen(filename) + strlen(TEMPNAME) + 11);
     strcpy(tempname, filename);
-    strcpy(basename(tempname, DIRSEPCH), TEMPNAME);
+    sprintf(basename(tempname, DIRSEPCH), TEMPNAME, getpid());
     
     FILE *tempfile;
 
@@ -1337,6 +1421,7 @@ void interactive_interface(Hunspell ** p
 		    case -1: {
 			clear();
 			refresh();
+			fclose(tempfile);
 			unlink(tempname);
 			endwin();
 			exit(0);
@@ -1356,7 +1441,20 @@ void interactive_interface(Hunspell ** p
 	if (! modified) {
 	    unlink(tempname);
 	} else {
+#ifdef WIN32
+	    // On Windows, rename fails when the target already
+	    // exists.  Fix that, and also preserve the read-only bit
+	    // of the original file, while at that.
+	    int readonly = _access (filename, 2) == -1 && errno == EACCES;
+	    if (readonly)
+		_chmod(filename, _S_IWRITE);
+	    unlink(filename);
+	    rename(tempname, filename);
+	    if (readonly)
+		_chmod(filename, _S_IREAD);
+#else
             rename(tempname, filename);
+#endif
 	}
         free(tempname);
 }
@@ -1389,22 +1487,29 @@ char * exist2(char * dir, int len, const
 	return NULL;
 }
 
-#ifndef WIN32
+#if !defined(WIN32) || defined(__MINGW32__)
 int listdicpath(char * dir, int len) {
 	char buf[MAXLNLEN];
-	const char * sep = (len == 0) ? "": DIRSEP;
-	strncpy(buf, dir, len);
-	strcpy(buf + len, sep);
+	const char * sep =
+	  (len == 0
+	   || dir[len-1] == DIRSEPCH
+#ifdef _WIN32
+	   || dir[len-1] == '/'
+#endif
+	   )
+	  ? "": DIRSEP;
+	buf[0] = '\0';
+	strncat(buf, dir, len);
 	DIR *d = opendir(buf);
 	if (!d) return 0;
 	struct dirent * de;
 	while ((de = readdir(d))) {
 		int len = strlen(de->d_name);
-		if ((len > 4 && strcmp(de->d_name + len - 4, ".dic") == 0) ||
-		   (len > 7 && strcmp(de->d_name + len - 7, ".dic.hz") == 0)) {
+		if ((len > 4 && FNCMP(de->d_name + len - 4, ".dic") == 0) ||
+		   (len > 7 && FNCMP(de->d_name + len - 7, ".dic.hz") == 0)) {
 		    char * s = mystrdup(de->d_name);
-		    s[len - ((s[len - 1] == 'z') ? 7 : 4)] = '\0';
-		    fprintf(stderr, "%s%s\n", buf, s);
+		    s[len - ((TOLOWER(s[len - 1]) == 'z') ? 7 : 4)] = '\0';
+		    fprintf(stderr, "%s%s%s\n", buf, sep, s);
 		    free(s);
 		}
 	}
@@ -1422,7 +1527,7 @@ char * search(char * begin, char * name,
 	    if (name) {
 	    	res = exist2(begin, end - begin, name, ext);
 	    } else {
-#ifndef WIN32
+#if !defined(WIN32) || defined(__MINGW32__)
 		listdicpath(begin, end - begin);
 #endif
 	    }
@@ -1447,6 +1552,10 @@ int main(int argc, char** argv)
 	textdomain("hunspell");
 #    ifdef HAVE_LANGINFO_CODESET
 	ui_enc = nl_langinfo(CODESET);
+#    else
+#      ifdef WIN32
+	ui_enc = w32console_codepage();
+#      endif
 #    endif
 #  endif
 #endif
@@ -1531,8 +1640,6 @@ int main(int argc, char** argv)
 			exit(0);
 		} else if ((strcmp(argv[i],"-a")==0)) {
 			filter_mode = PIPE;
-			fprintf(stdout,gettext(HUNSPELL_PIPE_HEADING));
-			fflush(stdout);
 		} else if ((strcmp(argv[i],"-m")==0)) {
             /*
              if -a was used, don't override, i.e. keep ispell compatability
@@ -1613,7 +1720,6 @@ int main(int argc, char** argv)
 			showpath = 1;
 		} else if ((strcmp(argv[i],"-r")==0)) {
 			warn = 1;
-fprintf(stderr, "BEKAPCS");
 		} else if ((strcmp(argv[i],"--check-url")==0)) {
 			checkurl = 1;
 		} else if ((arg_files==-1) && ((argv[i][0] != '-') && (argv[i][0] != '\0'))) {
@@ -1664,13 +1770,23 @@ fprintf(stderr, "BEKAPCS");
 	path = add(path, PATHSEP);          // <- check path in root directory
 	if (getenv("DICPATH")) path = add(add(path, getenv("DICPATH")), PATHSEP);
 	path = add(add(path, LIBDIR), PATHSEP);
-	if (HOME) path = add(add(add(add(path, HOME), DIRSEP), USEROOODIR), PATHSEP);
+	if (HOME) {
+	    path = add(add(path, HOME), DIRSEP);
+	    path = add(add(path, USEROOODIR), PATHSEP);
+	} else if (HOME2 && USEROOODIR2) {
+	    path = add(add(path, HOME2), DIRSEP);
+	    path = add(add(path, USEROOODIR2), PATHSEP);
+	}
+#ifdef WIN32
+	// Add ../share/hunspell relative to where the executable lives
+	path = add(add(path, w32exe_relative("..\\share\\hunspell")), PATHSEP);
+#endif
 	path = add(path, OOODIR);
 
 	if (showpath) {
 		fprintf(stderr, gettext("SEARCH PATH:\n%s\n"), path);
 		fprintf(stderr, gettext("AVAILABLE DICTIONARIES (path is not mandatory for -d option):\n"));
 		search(path, NULL, NULL);
 	}
 
 	if (!privdicname) privdicname = mystrdup(getenv("WORDLIST"));
@@ -1696,11 +1813,19 @@ fprintf(stderr, "BEKAPCS");
 	            dic = search(path, dicname2, ".dic");
                     if (aff && dic) {
                         if (dmax < DMAX) {
-                            pMS[dmax] = new Hunspell(aff, dic, key);
-                            dic_enc[dmax] = pMS[dmax]->get_dic_encoding();
-                            dmax++;
+			    if (showpath) {
+			        fprintf(stderr, gettext("LOADED DICTIONARY:\n%s\n%s\n"), aff, dic);
+			    }
+			    pMS[dmax] = new Hunspell(aff, dic, key);
+			    dic_enc[dmax] = pMS[dmax]->get_dic_encoding();
+			    dmax++;
                         } else fprintf(stderr, gettext("error - %s exceeds dictionary limit.\n"), dicname2);
-                    } else if (dic) pMS[dmax-1]->add_dic(dic);
+                    } else if (dic) {
+		        pMS[dmax-1]->add_dic(dic);
+			if (showpath) {
+			    fprintf(stderr, gettext("LOADED DICTIONARY:\n%s\n"), dic);
+			}
+		    }
 		}
 	} else {
 		fprintf(stderr,gettext("Can't open affix or dictionary files for dictionary named \"%s\".\n"), dicname);
@@ -1708,11 +1833,10 @@ fprintf(stderr, "BEKAPCS");
 	}
 
 	/* open the private dictionaries */
-	if (HOME) {
-	    strcpy(buf,HOME);
-#ifndef WIN32
-            strcat(buf,"/");
-#endif
+	if (HOME || HOME2) {
+	    if (HOME) strcpy(buf,HOME);
+	    else if (HOME2) strcpy(buf,HOME2);
+            strcat(buf,DIRSEP);
 	    if (!privdicname) {
 		strcat(buf,DICBASENAME);
 		strcat(buf,basename(dicname,DIRSEPCH));
@@ -1728,6 +1852,17 @@ fprintf(stderr, "BEKAPCS");
 	    }
         }
 
+	/*
+	   If in pipe mode, output pipe mode version string only when
+	   hunspell has properly been started.
+	   Emacs and may be others relies in the English version format.
+	   Do not gettextize.
+	*/
+	if (filter_mode == PIPE) {
+		fprintf(stdout,HUNSPELL_PIPE_HEADING);
+		fflush(stdout);
+	}
+
 	if (arg_files==-1) {
 		pipe_interface(pMS, format, stdin);
 	} else if (filter_mode != NORMAL) {
@@ -1783,3 +1918,32 @@ fprintf(stderr, "BEKAPCS");
 	for (int i = 0; i < dmax; i++) delete pMS[i];
 	return 0;
 }
+
+#ifdef WIN32
+#include <windows.h>
+
+static char *
+w32exe_relative(const char *d) {
+      char dir_name[MAX_PATH], *p;
+
+      if (!GetModuleFileName(NULL, dir_name, MAX_PATH)
+	  || (p = strrchr (dir_name, '\\')) == NULL)
+	  strcpy(dir_name, ".\\");
+      else {
+	  p[1] = '\0';
+	  strcat(dir_name, d);
+      }
+      return mystrdup(dir_name);
+}
+
+static char *
+w32console_codepage(void) {
+  static char cpname[MAX_PATH];
+  UINT cp = GetConsoleOutputCP();
+
+  if (!cp)
+	cp = GetOEMCP();
+  sprintf(cpname, "CP%u", cp);
+  return cpname;
+}
+#endif
