Index: less/charset.c
diff -u less/charset.c:1.55 less/charset.c:1.56
--- less/charset.c:1.55	Fri May  1 01:41:14 1998
+++ less/charset.c	Thu Jul 16 05:59:36 1998
@@ -164,6 +164,8 @@
 	{ "ja_JP.sdeckanji",	"japanese-ujis"	},
 	/* BSDI's */
 	{ "Japanese-EUC",	"japanese-ujis"	},
+	/* Win32 */
+	{ "Japanese_Japan.932",	"japanese-sjis"	},
 # endif
 	{ NULL }
 };
Index: less/help.c
diff -u less/help.c:1.8 less/help.c:1.9
--- less/help.c:1.8	Sat Nov 30 14:55:49 1996
+++ less/help.c	Sat Aug  8 12:25:01 1998
@@ -73,6 +73,7 @@
 ' ',' ',':','p',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ','E','x','a','m','i','n','e',' ','t','h','e',' ','(','_','\b','N','-','t','h',')',' ','p','r','e','v','i','o','u','s',' ','f','i','l','e',' ','f','r','o','m',' ','t','h','e',' ','c','o','m','m','a','n','d',' ','l','i','n','e','.','\n',
 ' ',' ',':','x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*',' ',' ','E','x','a','m','i','n','e',' ','t','h','e',' ','f','i','r','s','t',' ','(','o','r',' ','_','\b','N','-','t','h',')',' ','f','i','l','e',' ','f','r','o','m',' ','t','h','e',' ','c','o','m','m','a','n','d',' ','l','i','n','e','.','\n',
 ' ',' ','=',' ',' ','^','G',' ',' ',':','f',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','P','r','i','n','t',' ','c','u','r','r','e','n','t',' ','f','i','l','e',' ','n','a','m','e','.','\n',
+' ',' ','@',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','R','o','t','a','t','e',' ','t','h','e',' ','c','o','d','e',' ','r','e','c','o','g','n','i','t','i','o','n',' ','m','e','t','h','o','d',' ','o','f',' ','t','h','e',' ','c','u','r','r','e','n','t',' ','f','i','l','e','.','\n',
 ' ',' ','V',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','P','r','i','n','t',' ','v','e','r','s','i','o','n',' ','n','u','m','b','e','r',' ','o','f',' ','"','l','e','s','s','"','.','\n',
 '\n',
 ' ',' ','-','_','\b','<','_','\b','f','_','\b','l','_','\b','a','_','\b','g','_','\b','>',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','T','o','g','g','l','e',' ','a',' ','c','o','m','m','a','n','d',' ','l','i','n','e',' ','o','p','t','i','o','n',' ','[','s','e','e',' ','O','P','T','I','O','N','S',' ','b','e','l','o','w',']','.','\n',
@@ -104,6 +105,7 @@
 ' ',' ','-','I',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','I','g','n','o','r','e',' ','c','a','s','e',' ','i','n',' ','s','e','a','r','c','h','e','s',' ','a','n','d',' ','i','n',' ','s','e','a','r','c','h',' ','p','a','t','t','e','r','n','s','.','\n',
 ' ',' ','-','j',' ','[','_','\b','N',']',' ',' ',' ',' ',' ',' ',' ',' ','S','c','r','e','e','n',' ','p','o','s','i','t','i','o','n',' ','o','f',' ','t','a','r','g','e','t',' ','l','i','n','e','s','.','\n',
 ' ',' ','-','k',' ','[','_','\b','f','_','\b','i','_','\b','l','_','\b','e',']',' ',' ',' ',' ',' ','U','s','e',' ','a',' ','l','e','s','s','k','e','y',' ','f','i','l','e','.','\n',
+' ',' ','-','K',' ','[','_','\b','c','_','\b','h','_','\b','a','_','\b','r','_','\b','s','_','\b','e','_','\b','t',']',' ',' ','S','p','e','c','i','f','y',' ','c','h','a','r','a','c','t','e','r',' ','s','e','t','.','\n',
 ' ',' ','-','m',' ',' ','-','M',' ',' ',' ',' ',' ',' ',' ',' ','S','e','t',' ','p','r','o','m','p','t',' ','s','t','y','l','e','.','\n',
 ' ',' ','-','n',' ',' ','-','N',' ',' ',' ',' ',' ',' ',' ',' ','U','s','e',' ','l','i','n','e',' ','n','u','m','b','e','r','s','.','\n',
 ' ',' ','-','o',' ','[','_','\b','f','_','\b','i','_','\b','l','_','\b','e',']',' ',' ',' ',' ',' ','C','o','p','y',' ','t','o',' ','l','o','g',' ','f','i','l','e',' ','(','s','t','a','n','d','a','r','d',' ','i','n','p','u','t',' ','o','n','l','y',')','.','\n',
@@ -119,10 +121,12 @@
 ' ',' ','-','u',' ',' ','-','U',' ',' ',' ',' ',' ',' ',' ',' ','C','h','a','n','g','e',' ','h','a','n','d','l','i','n','g',' ','o','f',' ','b','a','c','k','s','p','a','c','e','s','.','\n',
 ' ',' ','-','V',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','D','i','s','p','l','a','y',' ','t','h','e',' ','v','e','r','s','i','o','n',' ','n','u','m','b','e','r',' ','o','f',' ','"','l','e','s','s','"','.','\n',
 ' ',' ','-','w',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','D','i','s','p','l','a','y',' ','~',' ','f','o','r',' ','l','i','n','e','s',' ','a','f','t','e','r',' ','e','n','d','-','o','f','-','f','i','l','e','.','\n',
+' ',' ','-','W',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','D','i','s','p','l','a','y',' ','m','a','r','k',' ','c','h','a','r','a','c','t','e','r',' ','i','n','s','t','e','a','d',' ','o','f',' ','w','r','o','n','g',' ','c','h','a','r','a','c','t','e','r','.','\n',
 ' ',' ','-','x',' ','[','_','\b','N',']',' ',' ',' ',' ',' ',' ',' ',' ','S','e','t',' ','t','a','b',' ','s','t','o','p','s','.','\n',
 ' ',' ','-','X',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','D','o','n','\'','t',' ','u','s','e',' ','t','e','r','m','c','a','p',' ','i','n','i','t','/','d','e','i','n','i','t',' ','s','t','r','i','n','g','s','.','\n',
 ' ',' ','-','y',' ','[','_','\b','N',']',' ',' ',' ',' ',' ',' ',' ',' ','F','o','r','w','a','r','d',' ','s','c','r','o','l','l',' ','l','i','m','i','t','.','\n',
 ' ',' ','-','z',' ','[','_','\b','N',']',' ',' ',' ',' ',' ',' ',' ',' ','S','e','t',' ','s','i','z','e',' ','o','f',' ','w','i','n','d','o','w','.','\n',
+' ',' ','-','Z',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','G','i','v','e',' ','p','r','i','o','r','i','t','y',' ','t','o',' ','t','h','e',' ','S','J','I','S',' ','o','v','e','r',' ','t','h','e',' ','U','J','I','S',' ','i','f',' ','y','o','u',' ','u','s','e',' ','J','a','p','a','n','e','s','e','.','\n',
 '\n',
 '\n',
 ' ',' ',' ',' ',' ',' ',' ',' ','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','\n',
Index: less/less.hlp
diff -u less/less.hlp:1.10 less/less.hlp:1.11
--- less/less.hlp:1.10	Thu Jan 16 21:21:16 1997
+++ less/less.hlp	Sat Aug  8 12:25:02 1998
@@ -102,6 +102,7 @@
   -I            Ignore case in searches and in search patterns.
   -j [_N]        Screen position of target lines.
   -k [_f_i_l_e]     Use a lesskey file.
+  -K [_c_h_a_r_s_e_t]  Specify character set.
   -m  -M        Set prompt style.
   -n  -N        Use line numbers.
   -o [_f_i_l_e]     Copy to log file (standard input only).
@@ -117,6 +118,7 @@
   -u  -U        Change handling of backspaces.
   -V            Display the version number of "less".
   -w            Display ~ for lines after end-of-file.
+  -W            Display mark character instead of wrong character.
   -x [_N]        Set tab stops.
   -X            Don't use termcap init/deinit strings.
   -y [_N]        Forward scroll limit.
Index: less/less.nro
diff -u less/less.nro:1.39 less/less.nro:1.40
--- less/less.nro:1.39	Fri Mar  6 17:06:52 1998
+++ less/less.nro	Sat Aug  8 12:25:04 1998
@@ -10,7 +10,7 @@
 .br
 .B "less --version"
 .br
-.B "less [-[+]aBcCdeEfgGiImMnNqQrsSuUVwXZ]"
+.B "less [-[+]aBcCdeEfgGiImMnNqQrsSuUVWwXZ]"
 .br
 .B "     [-b \fIbufs\fP] [-h \fIlines\fP] [-j \fIline\fP] [-k \fIkeyfile\fP]"
 .br
@@ -683,6 +683,9 @@
 past the end of the file.
 By default,
 a tilde character (~) is used.
+.IP -W
+Causes mark characters to be used to represent wrong characters.
+By default, such wrong characters displayed as binary.
 .IP -x\fIn\fP
 Sets tab stops every \fIn\fP positions.
 The default for \fIn\fP is 8.
Index: less/multi.c
diff -u less/multi.c:1.98 less/multi.c:1.99
--- less/multi.c:1.98	Thu Jul  2 02:29:30 1998
+++ less/multi.c	Sat Aug  8 12:16:06 1998
@@ -51,6 +51,9 @@
 
 #if JAPANESE
 
+int markwrongchar = 1;
+
+
 /*
  * Kanji convetion
  */
@@ -199,13 +202,84 @@
 		mp->multiindex = 0;
 	}
 }
+
+/*
+ * Internalize and mark all codes as wrong since code is not valid.
+ */
+static void internalize_wrongcode(mp)
+MULBUF *mp;
+{
+	register int i;
+
+	assert(mp->intindex + mp->multiindex <= sizeof(mp->multiint));
+	for (i = 0; i < mp->multiindex; i++)
+	{
+		mp->multiint[mp->intindex + i] = mp->multibuf[i];
+		mp->multics[mp->intindex + i] = WRONGCS;
+	}
+	mp->intindex += mp->multiindex;
+	mp->multiindex = 0;
+}
 
-static void internalize_wrong(mp)
+/*
+ * Put a wrongmark into internalize buffer.
+ */
+static void internalize_wrongmark(mp)
 MULBUF *mp;
 {
+	mp->multiint[mp->intindex + 0] = '"';
+	mp->multiint[mp->intindex + 1] = '.';
+	mp->multics[mp->intindex + 0] = JISX0208KANJI;
+	mp->multics[mp->intindex + 1] = REST_MASK |
+		JISX0208KANJI;
+	mp->intindex += 2;
+	mp->multiindex = 0;
+}
+
+/*
+ * Internalize and mark all codes as wrong since character is not valid.
+ * It is not same as internalize_wrongcode because code is valid.
+ */
+static void internalize_wrongchar(mp)
+MULBUF *mp;
+{
 	register int i;
 
 	assert(mp->intindex + mp->multiindex <= sizeof(mp->multiint));
+	if (markwrongchar)
+	{
+		switch (mp->multics[mp->intindex]) {
+		case JISX0201KANA:
+		case JISX0201ROMAN:
+		case LATIN1:
+		case LATIN2:
+		case LATIN3:
+		case LATIN4:
+		case GREEK:
+		case ARABIC:
+		case HEBREW:
+		case CYRILLIC:
+		case LATIN5:
+			assert(mp->multiindex == 1);
+			internalize_wrongmark(mp);
+			return;
+			break;
+		case JISX0208_78KANJI:
+		case JISX0208KANJI:
+		case JISX0208_90KANJI:
+		case JISX0212KANJISUP:
+		case UJIS:
+		case SJIS:
+			assert(mp->multiindex == 2);
+			internalize_wrongmark(mp);
+			return;
+			break;
+		case GB2312:
+		case KSC5601:
+		default:
+			break;
+		}
+	}
 	for (i = 0; i < mp->multiindex; i++)
 	{
 		mp->multiint[mp->intindex + i] = mp->multibuf[i];
@@ -274,13 +348,17 @@
 	/*
 	 * Eliminate some wrong codes
 	 */
-	cheliminate_cs(&mp->multiint[mp->intindex],
-		       &mp->multics[mp->intindex],
-		       &mp->multiint[mp->intindex],
-		       &mp->multics[mp->intindex]);
-
-	mp->intindex += mp->multiindex;
-	mp->multiindex = 0;
+	if (chisvalid_cs(&mp->multiint[mp->intindex],
+			 &mp->multics[mp->intindex])) {
+		mp->intindex += mp->multiindex;
+		mp->multiindex = 0;
+	} else
+	{
+		/*
+		 * less ignore the undefined codes
+		 */
+		internalize_wrongchar(mp);
+	}
 }
 
 #if JAPANESE
@@ -307,23 +385,18 @@
 			mp->multiint[mp->intindex + 1] = mp->multibuf[1];
 			mp->multics[mp->intindex + 1] = REST_MASK | UJIS;
 
+#if 0
 			/*
-			 * Eliminate some wrong codes
+			 * less ignore the user defined area
 			 */
-			cheliminate_cs(&mp->multiint[mp->intindex],
-				       &mp->multics[mp->intindex],
-				       &mp->multiint[mp->intindex],
-				       &mp->multics[mp->intindex]);
-
-			mp->multiint[mp->intindex] &= ~0x80;
-			mp->multics[mp->intindex] = mp->cs;
-			mp->multiint[mp->intindex + 1] &= ~0x80;
-			mp->multics[mp->intindex + 1] = REST_MASK | mp->cs;
-			mp->intindex += 2;
-			mp->multiindex = 0;
-
-#if 0
 			if (mp->multibuf[0] < 85 + 0xa0) {
+			}
+#endif
+			/*
+			 * Eliminate some wrong codes
+			 */
+			if (chisvalid_cs(&mp->multiint[mp->intindex],
+					 &mp->multics[mp->intindex])) {
 				mp->multiint[mp->intindex] =
 					mp->multibuf[0] & ~0x80;
 				mp->multics[mp->intindex] = mp->cs;
@@ -336,11 +409,10 @@
 			} else
 			{
 				/*
-				 * less ignore the user defined area
+				 * less ignore the undefined codes
 				 */
-				internalize_wrong(mp);
+				internalize_wrongchar(mp);
 			}
-#endif
 		}
 	} else if (mp->multiindex == 3 &&
 		   ISUJISKANJISUP(mp->multibuf[0], mp->multibuf[1],
@@ -366,7 +438,7 @@
 				/*
 				 * less ignore the user defined area
 				 */
-				internalize_wrong(mp);
+				internalize_wrongchar(mp);
 			}
 		}
 	} else
@@ -403,29 +475,18 @@
 		mp->multiint[mp->intindex + 1] = mp->multibuf[1];
 		mp->multics[mp->intindex + 1] = REST_MASK | SJIS;
 
+#if 0
 		/*
+		 * less ignore the user defined area
+		 */
+		if (mp->multibuf[0] < (85 - 1) / 2 + 0x81 + 0x40) {
+		}
+#endif
+		/*
 		 * Eliminate some wrong codes
 		 */
-		cheliminate_cs(&mp->multiint[mp->intindex],
-			       &mp->multics[mp->intindex],
-			       &mp->multiint[mp->intindex],
-			       &mp->multics[mp->intindex]);
-
-		c1 = mp->multiint[mp->intindex] - 0x81 -
-			(mp->multiint[mp->intindex] >= 0xe0 ?
-			 0xe0 - 0xa0 : 0x0);
-		c2 = mp->multiint[mp->intindex + 1] -
-			(mp->multiint[mp->intindex + 1] >= 0x80 ? 1 : 0);
-		mp->multiint[mp->intindex] =
-			(c1 * 2 + (c2 >= 0x9e ? 1 + 0x21 : 0x21));
-		mp->multics[mp->intindex] = mp->cs;
-		mp->multiint[mp->intindex + 1] =
-			(c2 - (c2 >= 0x9e ? 0x9e - 0x21 : 0x40 - 0x21));
-		mp->multics[mp->intindex + 1] = REST_MASK | mp->cs;
-		mp->intindex += 2;
-		mp->multiindex = 0;
-#if 0
-		if (mp->multibuf[0] < 0xeb) {
+		if (chisvalid_cs(&mp->multiint[mp->intindex],
+				 &mp->multics[mp->intindex])) {
 			register int c1, c2;
 			c1 = mp->multibuf[0] - 0x81 -
 				(mp->multibuf[0] >= 0xe0 ? 0xe0 - 0xa0 : 0x0);
@@ -442,11 +503,10 @@
 		} else
 		{
 			/*
-			 * less ignore the user defined area
+			 * less ignore the undefined codes
 			 */
-			internalize_wrong(mp);
+			internalize_wrongchar(mp);
 		}
-#endif
 	} else
 	{
 		rebuffering_multi(mp);
@@ -468,7 +528,7 @@
 			mp->sequence_counter = 0;
 #endif
 			if (control_char(c))
-				internalize_wrong(mp);
+				internalize_wrongcode(mp);
 			else
 				internalize_noconv(mp);
 			return;
@@ -487,7 +547,7 @@
 #if JAPANESE
 			mp->sequence_counter = 0;
 #endif
-			internalize_wrong(mp);
+			internalize_wrongcode(mp);
 			return;
 		} else if (c <= 0x7f ||
 			   (mp->io.right == iso8 && (0xa0 <= c && c <= 0xff)))
@@ -534,7 +594,7 @@
 #if JAPANESE
 			mp->sequence_counter = 0;
 #endif
-			internalize_wrong(mp);
+			internalize_wrongcode(mp);
 			return;
 		}
 #if JAPANESE
@@ -566,7 +626,7 @@
 		}
 		mp->sequence_counter = 0;
 #endif
-		internalize_wrong(mp);
+		internalize_wrongcode(mp);
 		return;
 	}
 
Index: less/multi.h
diff -u less/multi.h:1.8 less/multi.h:1.9
--- less/multi.h:1.8	Wed Jul  1 18:04:42 1998
+++ less/multi.h	Sat Aug  8 12:16:07 1998
@@ -214,4 +214,4 @@
 extern void chconvert_cs();
 extern void chunify_cs();
 extern int chcmp_cs();
-extern void cheliminate_cs();
+extern int chisvalid_cs();
Index: less/opttbl.c
diff -u less/opttbl.c:1.19 less/opttbl.c:1.20
--- less/opttbl.c:1.19	Fri May  1 01:41:31 1998
+++ less/opttbl.c	Sat Aug  8 12:16:09 1998
@@ -66,6 +66,7 @@
 #endif
 #if JAPANESE
 public int opt_Z_var;		/* Initial variable for opt_Z */
+extern int markwrongchar;	/* Display marker instead of wrong character */
 #endif
 
 /*
@@ -213,6 +214,13 @@
 		"Display ~ for lines after end-of-file",
 		NULL
 	},
+#if JAPANESE
+	{ 'W', BOOL|REPAINT, OPT_OFF, &markwrongchar, NULL,
+		"Display marker instead of wrong character",
+		"Display wrong character",
+		NULL
+	},
+#endif
 	{ 'x', NUMBER|REPAINT, 8, &tabstop, NULL,
 		"Tab stops: ",
 		"Tab stops every %d spaces", 
Index: less/unify.c
diff -u less/unify.c:1.15 less/unify.c:1.18
--- less/unify.c:1.15	Thu Jul  2 04:08:16 1998
+++ less/unify.c	Sat Aug  8 12:16:10 1998
@@ -791,8 +791,8 @@
 	{ "/!", "/~", "\".", JISX0208KANJI },
 	/* 47-KU 0x4F54($@OT(B)-0x4F7E($@O~(B) -> 0x222E($B".(B) */
 	{ "OT", "O~", "\".", JISX0208KANJI },
-	/* 84-KU 0x7425($@t%(B)-0x747E($@t~(B) -> 0x222E($B".(B) */
-	{ "t%", "t~", "\".", JISX0208KANJI },
+	/* 84-KU 0x7421($@t!(B)-0x747E($@t~(B) -> 0x222E($B".(B) */
+	{ "t!", "t~", "\".", JISX0208KANJI },
 	/* 85-KU 0x7521($@u!(B)-0x757E($@u~(B) -> 0x222E($B".(B) */
 	{ "u!", "u~", "\".", JISX0208KANJI },
 	/* 86-KU 0x7621($@v!(B)-0x767E($@v~(B) -> 0x222E($B".(B) */
@@ -1246,14 +1246,7 @@
 	/* initialize output buffer */
 	i = 0;
 	do {
-#if MSB_ENABLE
-		if (CSISASCII(ics[i]) || CSISWRONG(ics[i]))
-			ostr[i] = istr[i];
-		else
-			ostr[i] = istr[i] & ~0x80;
-#else
 		ostr[i] = istr[i];
-#endif
 		ocs[i] = ics[i];
 		i++;
 	} while (CSISREST(ics[i]));
@@ -1369,6 +1362,54 @@
 		cs2++;
 	} while (CSISREST(*cs1));
 	return 0;
+}
+
+int chisvalid_cs(istr, ics)
+char* istr;
+CHARSET* ics;
+{
+	int i;
+	convtab* ptab;
+
+	if (istr[0] == NULCH && CSISNULLCS(ics[0]))
+		return 0;
+
+	/* check wrong codes if it is some traditional character set */
+	if (CS2CHARSET(*ics) == JISX0208_78KANJI) {
+		ptab = find_convtab(&etable_jisx0208_78, istr);
+		if (ptab)
+			return 0;
+		else
+			return 1;
+	} else if (CS2CHARSET(*ics) == JISX0208KANJI) {
+		ptab = find_convtab(&etable_jisx0208_83, istr);
+		if (ptab)
+			return 0;
+		else
+			return 1;
+	} else if (CS2CHARSET(*ics) == JISX0208_90KANJI) {
+		/* eliminate wrong codes */
+		ptab = find_convtab(&etable_jisx0208_90, istr);
+		if (ptab)
+			return 0;
+		else
+			return 1;
+	} else if (CS2CHARSET(*ics) == SJIS) {
+		/* eliminate wrong codes */
+		ptab = find_convtab(&etable_sjis, istr);
+		if (ptab)
+			return 0;
+		else
+			return 1;
+	} else if (CS2CHARSET(*ics) == UJIS) {
+		/* eliminate wrong codes */
+		ptab = find_convtab(&etable_ujis, istr);
+		if (ptab)
+			return 0;
+		else
+			return 1;
+		/* TODO: G2 */
+	}
 }
 
 void cheliminate_cs(istr, ics, ostr, ocs)
Index: less/version.c
diff -u less/version.c:1.84 less/version.c:1.86
--- less/version.c:1.84	Thu Jul  2 04:16:36 1998
+++ less/version.c	Sat Aug  8 12:25:05 1998
@@ -635,6 +635,10 @@
 		and 1990.
 iso244 7/2/98	Add elimination of wrong characters for SJIS and UJIS.
 iso245 7/2/98	Fix a bug about elimination for SJIS.
+iso246 8/8/98	Add one locale for Win32, eliminate all MSB_ENABLE stuff
+		from unify.c, and fix eliminating table for JIS X0208.1978.
+iso247 8/8/98	Add -W option.  And change the point of putting a mark.  Now
+		multi.c call checking function, them mark wrong characters.
 */
 
-char version[] = "332+iso245";
+char version[] = "332+iso247";
