Index: less/Makefile.aut
diff -u less/Makefile.aut:1.1.1.2 less/Makefile.aut:1.3
--- less/Makefile.aut:1.1.1.2	Sun Dec  1 05:41:04 1996
+++ less/Makefile.aut	Sun Dec  1 05:55:40 1996
@@ -12,7 +12,7 @@
 	help.c ifile.c input.c jump.c line.c linenum.c \
 	lsystem.c mark.c optfunc.c option.c opttbl.c os.c \
 	output.c position.c prompt.c search.c signal.c \
-	tags.c ttyin.c version.c  
+	tags.c ttyin.c version.c multi.c  
 DISTFILES_W = \
 	defines.ds  Makefile.dsb Makefile.dsg Makefile.dsm \
 	defines.o2  Makefile.o2e \
Index: less/Makefile.dsb
diff -u less/Makefile.dsb:1.1.1.1 less/Makefile.dsb:1.2
--- less/Makefile.dsb:1.1.1.1	Sun Dec  1 05:41:23 1996
+++ less/Makefile.dsb	Sun Dec  1 06:03:45 1996
@@ -23,7 +23,7 @@
 	input.obj jump.obj line.obj linenum.obj lsystem.obj \
 	mark.obj optfunc.obj option.obj opttbl.obj os.obj output.obj \
 	position.obj prompt.obj search.obj signal.obj tags.obj \
-	ttyin.obj version.obj
+	ttyin.obj version.obj multi.obj
 
 all: less$(EXT) lesskey$(EXT)
 
Index: less/Makefile.dsg
diff -u less/Makefile.dsg:1.1.1.1 less/Makefile.dsg:1.2
--- less/Makefile.dsg:1.1.1.1	Sun Dec  1 05:41:23 1996
+++ less/Makefile.dsg	Sun Dec  1 06:03:45 1996
@@ -26,7 +26,7 @@
 	help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \
 	lsystem.${O} mark.${O} optfunc.${O} option.${O} opttbl.${O} os.${O} \
 	output.${O} position.${O} prompt.${O} search.${O} signal.${O} \
-	tags.${O} ttyin.${O} version.${O}
+	tags.${O} ttyin.${O} version.${O} multi.${O}
 
 all: less lesskey
 
Index: less/Makefile.dsm
diff -u less/Makefile.dsm:1.1.1.1 less/Makefile.dsm:1.2
--- less/Makefile.dsm:1.1.1.1	Sun Dec  1 05:41:23 1996
+++ less/Makefile.dsm	Sun Dec  1 06:03:46 1996
@@ -32,7 +32,7 @@
 	input.obj jump.obj line.obj linenum.obj lsystem.obj \
 	mark.obj optfunc.obj option.obj opttbl.obj os.obj output.obj \
 	position.obj prompt.obj search.obj signal.obj tags.obj \
-	ttyin.obj version.obj
+	ttyin.obj version.obj multi.obj
 
 all: less lesskey
 
Index: less/Makefile.in
diff -u less/Makefile.in:1.1.1.8 less/Makefile.in:1.9
--- less/Makefile.in:1.1.1.8	Sun Dec  1 05:41:04 1996
+++ less/Makefile.in	Sun Dec  1 05:55:40 1996
@@ -42,7 +42,7 @@
 	help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \
 	lsystem.${O} mark.${O} optfunc.${O} option.${O} opttbl.${O} os.${O} \
 	output.${O} position.${O} prompt.${O} search.${O} signal.${O} \
-	tags.${O} ttyin.${O} version.${O}  @REGEX_O@
+	tags.${O} ttyin.${O} version.${O}  @REGEX_O@ multi.${O}
 
 all: less lesskey lessecho
 
Index: less/Makefile.o2e
diff -u less/Makefile.o2e:1.1.1.1 less/Makefile.o2e:1.2
--- less/Makefile.o2e:1.1.1.1	Sun Dec  1 05:41:23 1996
+++ less/Makefile.o2e	Sun Dec  1 06:03:46 1996
@@ -23,7 +23,7 @@
 	help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \
 	lsystem.${O} mark.${O} optfunc.${O} option.${O} opttbl.${O} os.${O} \
 	output.${O} position.${O} prompt.${O} search.${O} signal.${O} \
-	tags.${O} ttyin.${O} version.${O}  regexp.${O}
+	tags.${O} ttyin.${O} version.${O}  regexp.${O} multi.${O}
 
 all:    less.exe lesskey.exe
 
Index: less/Makefile.o9c
diff -u less/Makefile.o9c:1.1.1.2 less/Makefile.o9c:1.3
--- less/Makefile.o9c:1.1.1.2	Sun Dec  1 05:41:24 1996
+++ less/Makefile.o9c	Sun Dec  1 05:55:41 1996
@@ -27,7 +27,7 @@
 	help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \
 	lsystem.${O} mark.${O} optfunc.${O} option.${O} opttbl.${O} os.${O} \
 	output.${O} position.${O} prompt.${O} search.${O} signal.${O} \
-	tags.${O} ttyin.${O} version.${O}  regexp.${O}
+	tags.${O} ttyin.${O} version.${O}  regexp.${O} multi.${O}
 
 all: less lessecho lesskey
 
Index: less/Makefile.o9u
diff -u less/Makefile.o9u:1.1.1.1 less/Makefile.o9u:1.2
--- less/Makefile.o9u:1.1.1.1	Sat Sep 14 00:36:40 1996
+++ less/Makefile.o9u	Sat Sep 14 01:00:23 1996
@@ -26,7 +26,7 @@
 	help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \
 	lsystem.${O} mark.${O} optfunc.${O} option.${O} opttbl.${O} os.${O} \
 	output.${O} position.${O} prompt.${O} search.${O} signal.${O} \
-	tags.${O} ttyin.${O} version.${O}  regexp.${O}
+	tags.${O} ttyin.${O} version.${O}  regexp.${O} multi.${O}
 
 all: less lesskey
 
Index: less/Makefile.wnb
diff -u less/Makefile.wnb:1.1.1.1 less/Makefile.wnb:1.2
--- less/Makefile.wnb:1.1.1.1	Sun Dec  1 05:41:25 1996
+++ less/Makefile.wnb	Sun Dec  1 06:03:48 1996
@@ -23,7 +23,7 @@
 	input.obj jump.obj line.obj linenum.obj lsystem.obj \
 	mark.obj optfunc.obj option.obj opttbl.obj os.obj output.obj \
 	position.obj prompt.obj search.obj signal.obj tags.obj \
-	ttyin.obj version.obj regexp.obj
+	ttyin.obj version.obj regexp.obj multi.obj
 
 all: less lesskey
 
Index: less/Makefile.wnm
diff -u less/Makefile.wnm:1.1.1.1 less/Makefile.wnm:1.2
--- less/Makefile.wnm:1.1.1.1	Sun Dec  1 05:41:25 1996
+++ less/Makefile.wnm	Sun Dec  1 06:03:48 1996
@@ -22,7 +22,7 @@
 	input.obj jump.obj line.obj linenum.obj lsystem.obj \
 	mark.obj optfunc.obj option.obj opttbl.obj os.obj output.obj \
 	position.obj prompt.obj search.obj signal.obj tags.obj \
-	ttyin.obj version.obj regexp.obj
+	ttyin.obj version.obj regexp.obj multi.obj
 
 all: less.exe lesskey.exe
 
Index: less/README.iso
diff -u /dev/null less/README.iso:1.9
--- /dev/null	Sun Mar  9 23:07:13 1997
+++ less/README.iso	Sat Jan 25 07:12:41 1997
@@ -0,0 +1,173 @@
+=========================================================================
+    This is the distribution of less, version iso210, released 12 Jan 97
+    It support ISO 2022 code extension techniques and Japanese codes.
+    Please report any problems of it to the author at jam@poboxes.com.
+    See http://www.io.com/~kazushi/less/ for the latest info.
+=========================================================================
+
+
+**Features**
+ - Support ISO 2022 code extension techniques in 7bits and 8bits.
+ - Understand all escape sequences of ISO 2022 level 3, a special
+   sequence, ESC 2/4[$] 2/12[,] FE, which is used in MULE and Japanese 
+   codes which are UJIS and SJIS.
+ - Support some environment of users.  Output as CTEXT, which is
+   defined in X11, if a user use iso8.  Output only GZDM4, GZD4,
+   G1DM4, G1DM6, G1D4, G1D6, SI and SO escape sequences if a user use
+   iso7.  Output some Japanese codes if a user use it.
+ - Automatic invoking of zcat.
+
+**Problems**
+ - To compare for search, less convert data and a pattern into
+   internal codes.  Thus some codes which has a gap in internal
+   representation is not found by less.  Such codes are Right Half of
+   JIS X0201 Japanese (Katakana) in UJIS, JIS X0212-1990 Japanese
+   Supplement in UJIS and codes which contain escape sequence.
+ - I didn't make any multi bytes code enhancements for regular
+   expression library.  Thus less don't understand regular expression
+   to such multi bytes codes.  If you have an UJIS regular expression
+   library, you may use it with a definition of UJIS_REGEXP to 1.
+
+**Enhancements**
+ - JLESSCHARET environment variable choose codes for input and output.
+   For example, if you set "japanese-iso7", less read all Japanese
+   codes and iso7 and write iso7.  If you set "ujis", less read and
+   write only UJIS.  Currently you can use followings.
+     Same as LESSCHARSET: ascii, latin1, dos, koi8-r, next
+     Others: iso7, iso8, ujis-iso7, euc-iso7, sjis-iso7, jis,
+	     ujis-jis, euc-jis, sjis-jis, ujis, euc, jis-ujis,
+	     jis-euc, sjis, jis-sjis, japanese, japanese-iso7,
+	     japanese-jis, japanese-ujis, japanese-euc, japanese-sjis
+ - Following values of JLESSCHARSET are treated for input and output
+   separately.  For example, if you set "ujis-sjis", less read only
+   UJIS and write only SJIS.
+     Values: ujis-sjis, euc-sjis, sjis-ujis, sjis-euc
+ - JLESSPLANESET environment variable choose plane of iso8 and iso7.
+   Please read a manual about details.
+ - JLESSKEYCHARET environment variable choose codes for input from
+   keyboard.  All values for JLESSCHARSET environment variable are
+   used for this.
+ - Sometime less may mistake automatic handling of Japanese codes.
+   The user change the status for it by '@' key.  The function name
+   of it is "rotate-right".
+
+**History about Japanized and ISO 2022-ized less**
+ - About Japanization of less
+   - Kato-san changed less-123 (maybe) for JIS code.
+   - There are many patches for less.
+   - I changed less-177 for all Japanese codes.
+   - Kusakabe-san changed less-178 by using patches for less-177.
+   - Senda-san add printing function of Japanese code for less-177.
+   - Sakai-san changed less-200 by using patches for less-178.
+   - I changed less-205 for all Japanese codes and ISO 2022 codes.
+   - Ushine-san changed less-321 by using patches for less-290.
+   - I changed less-330 by using patches for less-290.  It is named
+     iso202.
+   - I removed some bugs and made jless-330-iso203.
+   - I re-wrote jless and made jless-330-iso208.
+   - I released patches to correct bugs.
+
+ - About jless
+   - I put 2 unofficial patches of KANJI searching enhancements for
+     ISO 2022-ized less-237 on ftp.
+   - I put an unofficial patch to use gawk-2.15.6-mb1.04's KANJI
+     regular expression library for jless-330-iso210 on ftp.  It will
+     works with iso212 and following.
+   - I put a less.hlp file which is translated into Japanese.  It will 
+     works with iso212 and following.
+
+**FAQ**
+ Q: When I try to view Japanese text, the less show inverse characters
+    only.  How do I view them?
+ A: You have to set "japanese" to JLESSCHARSET environment variable.
+    Otherwise you have to set "ja_JP" to LANG environment variable if
+    your computer support it.
+
+ Q: When I try to view Japanese text, the less show strange characters
+    only like '$' and others.  How do I view them?
+ A: Does your terminal or terminal emulator have ability to show
+    Japanese?  If your terminal has such ability, you have to adjust
+    the Japanese code by setting "japanese-ujis" or "japanese-sjis" to 
+    JLESSCHARSET environment variable.
+
+ Q: When I try to view compressed text, less doesn't work.  How do I
+    view them?
+ A: The less use the name of text file to check that it is compressed
+    and use "zcat" program to uncompress it.  It means that the
+    compressed file has to have ".z", ".gz" or ".Z" as the extension
+    name and the "zcat" has ability to uncompress them.  I think you
+    should install GNU's gzip as "zcat".
+
+ Q: How to set the default value of JLESSCHARSET environment variable.
+ A: You can use DEFCHARSET declaration in "defines.h".  If your
+    computer has a LANG property, you have to set HAVE_LOCALE to 0 in
+    "defines.h".  Note: before editing it, you should execute
+    "configure" program.
+
+ Q: Sometime my terminal shows not ASCII characters only.
+ A: Some terminal emulator has bugs in handling the ISO 2022.  You
+    should tell the less to display only JIS by setting "japanese-jis" 
+    to JLESSCHARSET environment variable.
+
+ Q: Sometime the less shows wrong Japanese when I try to view SJIS
+    code files.
+ A: My automatic Japanese code handling routine has some problem
+    because same value of data become different character in each
+    code.  You should type '^L' to re-view it.  If it doesn't work,
+    you should type '@' to change it to the manually handling routine.
+
+    On the other hand, if you use less with a -Z option, less give
+    priority to SJIS over UJIS in automatic handling routine.  And you
+    can change the default value of priority and invert the means of a
+    -Z option by compiling with SJIS_PRE declaration.
+
+    Or if you know the file is SJIS before executing the less, you
+    should set "sjis" to JLESSCHARSET environment variable to diable
+    the automatic handling routine.
+
+ Q: How do I use SJIS as input string?
+ A: You should set "sjis-jis" to JLESSKEYCHARSET environment
+    variable.  Otherwise you should set "sjis-jis" to DEFKEYCHARSET
+    declaration in "defines.h".
+
+ Q: How do I input search pattern by JIS?
+ A: Normally the less use "\e$" sequence.  You should write following
+    in your "~/.lesskey" file and execute "lesskey" program to cancel
+    it.
+
+#line-edit
+\e$	insert ^V\e$
+
+ Q: How do I use emacs-like key binding?
+ A: You should write following in your "~/.lesskey" file and execute
+    "lesskey" program.
+
+#line-edit
+^A	home
+^E	end
+^P	up
+^N	down
+^F	right
+^B	left
+\ef	word-right
+^D	delete
+\ed	word-delete
+
+ Q: The os.c was not compiled on NEWS-OS 4.0C.
+ A: Add following before "#include <setjmp.h>".
+
+#define LANGUAGE_C   1
+
+**Conclusion**
+ - Current problem is searching of multi byte characters with regular
+   expression.
+ - Please mail to "jam@poboxes.com" if you have problem or suggestion.
+ - At "ftp://ftp.aist-nara.ac.jp/pub/personal/kazusi-m/less", I will
+   keep all patches and contributed patches about jless.  If you make
+   any patches, please mail to me about it.
+
+
+Local Variables:
+mode: indented-text
+fill-column: 70
+End:
Index: less/README.iso.jp
diff -u /dev/null less/README.iso.jp:1.8
--- /dev/null	Sun Mar  9 23:07:13 1997
+++ less/README.iso.jp	Sat Jan 25 07:12:42 1997
@@ -0,0 +1,203 @@
+=========================================================================
+    This is the distribution of less, version iso210, released 12 Jan 97
+    It support ISO 2022 code extension techniques and Japanese codes.
+    Please report any problems of it to the author at jam@poboxes.com.
+    See http://www.io.com/~kazushi/less/ for the latest info.
+=========================================================================
+    This file is written by Japanese and JIS code and contains
+    almost same information in README.iso.
+=========================================================================
+
+
+**$BFCD'(B**
+ - ISO 2022 in 7bits$B$H!"(Bin 8bits$B$r%5%]!<%H!#(B
+ - $BF~NO$H$7$F$O!"(BISO 2022$B$N<BAu%l%Y%k(B3$BAjEv$H!"(BMULE$B$GMxMQ$5$l(B
+   $B$F$$$k(BESC 2/4[$] 2/12[,] FE$B$H$$$&FC<l$J3dEv$H!"(BUJIS$B!"(BSJIS
+   $B$H$$$C$?F|K\8l%3!<%I$r!"2r<a$G$-$k!#(B
+ - $B=PNO$H$7$F$O!"(Biso8$B4D6-$K=PNO$9$k>l9g$O(BX11$B$J$I$G8@$&=j$N(B
+   CTEXT$B$H$7$F=PNO!#(Biso7$B4D6-$KBP$7$F=PNO$9$k>l9g$O(BG0$B!"(BG1$B$X$N(B
+   $B8F$S=P$7%7!<%1%s%9$H(BSI, SO$B$@$1$r;H$C$F=PNO!#(B
+ - compress$B$d(Bgzip$B$5$l$?%U%!%$%k$r4JC1$KD/$a$k$3$H$,$G$-$k!#(B
+
+**$BLdBjE@(B**
+ - $BF|K\8l$d(BISO 2022$B$N8!:w$O!"FbIt%3!<%I$G=hM}$7$^$9!#$=$NJQ(B
+   $B49$N:]$K7d4V$,H/@8$9$k4A;z%3!<%I$K$D$$$F$O!"8!:w$,$G$-$^(B
+   $B$;$s!#$=$&$7$?%3!<%I$O!"(BUJIS$B$GI=8=$5$l$?(BRight Half of JIS
+   X0201 Japanese(Katakana)$B$d(BJIS X0212-1990 Japanese
+   Supplement$B$K$J$j$^$9!#$^$?!"(BJIS$B!"(BISO 2022$B$GMxMQ$5$l$k%(%9(B
+   $B%1!<%W%7!<%1%s%9$r$O$5$s$@J8;zNs$b8!:w$G$-$^$;$s!#(B
+ - $B@55,I=8=%i%$%V%i%j$K$O<j$r2C$($F$$$J$$$N$G!"J8;z<o$N0c$$(B
+   $B$OH=CG$G$-$^$;$s$7!"J#?t%P%$%HJ8;z$N@55,I=8=$X$bBP1~$7$F(B
+   $B$$$^$;$s!#$b$7!"(BUJIS$B$N@55,I=8=%i%$%V%i%j$,MxMQ$G$-$k$J$i!"(B
+   UJIS_REGEXP$B$r(B1$B$KDj5A$9$k$3$H$G!"A0<T$NLdBj$N0lIt$H8e<T$N(B
+   $BLdBj$r2r7h$G$-$k2DG=@-$,$"$j$^$9(B($BKM$O$=$N$h$&$J%i%$%V%i%j(B
+   $B$rMxMQ$G$-$J$$$?$a!"%F%9%H$J$I$O9T$J$C$F$$$^$;$s(B)$B!#(B
+
+**$B3HD%E@(B**
+ - JLESSCHARET$B4D6-JQ?t$G!"F~NO$H=PNO$KMxMQ$9$k%3!<%I$r;XDj$G(B
+   $B$-$^$9!#Nc$($P!"(B"japanese-iso7"$B$H$9$k$H!"F|K\8l$N%3!<%I$9(B
+   $B$Y$F$H(Biso7$B$rF~NO$H$7$F<h$j07$$!"$=$l$r(Biso7$B$G=PNO$7$^$9!#(B
+   $B$^$?!"(B"ujis"$B$H$9$k$H!"(BUJIS$B$@$1$rF~NO$H=PNO$KMxMQ$7$^$9!#(B
+   $B8=:_0J2<$NCM$,MxMQ$G$-$^$9!#(B
+     $B:G=i$+$i$"$C$?$b$N(B: ascii, latin1, dos, koi8-r, next
+     $B3HD%$7$?$b$N(B: iso7, iso8, ujis-iso7, euc-iso7,
+		   sjis-iso7, jis, ujis-jis, euc-jis,
+		   sjis-jis, ujis, euc, jis-ujis, jis-euc,
+		   sjis, jis-sjis, japanese, japanese-iso7,
+		   japanese-jis, japanese-ujis,
+		   japanese-euc, japanese-sjis
+   $B$^$?!"FC<l$J$b$N$H$7$F!"$"$k%3!<%I$rF~NO$7!"$"$k%3!<%I$G(B
+   $B=P$9$H$$$&;XDj$b$"$j$^$9!#Nc$($P!"(B"ujis-sjis"$B$H$9$k$H!"(B
+   UJIS$B$@$1$rF~NO$H$7$F07$$!"$=$l$r(BSJIS$B$KJQ49$7$F=PNO$7$^$9!#(B
+     $BFC<l$J$b$N(B: ujis-sjis, euc-sjis, sjis-ujis, sjis-euc
+
+ - JLESSPLANESET$B4D6-JQ?t$G!"(Biso8$B$d(Biso7$B$N(Bplane$B$r7h$a$k$3$H$,(B
+   $B$G$-$^$9!#>\$7$/$O%^%K%e%"%k$rFI$s$G2<$5$$!#(B
+ - JLESSKEYCHARET$B4D6-JQ?t$G!"%-!<%\!<%I$+$i$NF~NO$KMxMQ$9$k(B
+   $B%3!<%I$r;XDj$G$-$^$9!#(BJLESSCHARSET$B$HF1$8CM$,MxMQ$G$-$^$9!#(B
+ - $B<+F0H=JL$@$1$G$OET9g$,0-$$$3$H$b$"$k$?$a!":G>e0L%S%C%H$,(B
+   $BN)$C$?%3!<%I$NH=JLJ}K!$r=g!9$KJQ99$9$k$?$a$N%-!<$rMQ0U$7(B
+   $B$F$$$^$9!#(B'@'$B%-!<!"5!G=L>$O(B"rotate-right"$B$G$9!#(B
+
+**less$B$NF|K\8l2=$d4XO"$7$?%Q%C%A$NNr;K(B**
+ - less$B$NF|K\8l2=$K4X$7$F(B
+   - less-123($B!)(B)$B$r2CF#$5$s$,(BJIS$B2=$5$l$?!#(B
+   - $B$=$NB>?'!9$J%Q%C%A$,=P$?!#(B
+   - less-177$B$r$+$:$7$,F|K\8l2=$7$?!#(B
+   - less-178$B$K(Bless-177$B$N%Q%C%AB>$r$"$F$?$b$N$r$/$5$+$Y$5$s(B
+     $B$,Ej9F$5$l$?!#(B
+   - less-177$B$K@gED$5$s$,4A;z%3!<%II=<(5!G=$rDI2C$5$l$?!#(B
+   - less-200$B$K(Bless-178$B$N%Q%C%AB>$r$"$F$?$b$N$r<r0f$5$s$,Ej(B
+     $B9F$5$l$?!#(B
+   - less-205$B$r$+$:$7$,(BISO 2022$B2=$H$7$FEj9F$7$?!#(B
+   - less-321$B$K(Bless-290$B$N(BISO 2022$B2=$r$"$F$?$b$N$r5m:,$5$s$,(B
+     $BEj9F$5$l$?!#(B
+   - less-330$B$K2a5n$N(BISO 2022$B2=$r$=$N$^$^N.MQ$7$?(B
+     jless-330-iso202$B$r$+$:$7$,Ej9F$7$?!#(B
+   - $B%P%0$r<h$C$F(Bjless-330-iso203$B$H$7$FEj9F$7$?!#(B
+   - $BBgI}$K=q$-D>$7$F(Bjless-330-iso208$B$H$7$FEj9F$7$?!#(B
+   - $B?'!9$H%P%0$r<h$C$FEj9F!"8x3+$7$?!#(B
+
+ - jless$B$K4X$7$F(B
+   - less-237$B$r(BISO 2022$B2=$7$?$b$N$KBP$9$k4A;z8!:w%Q%C%A(B2$B<o$r(B
+     $B8x3+$7$?!#(B
+   - jless-330-iso210$B$G(Bgawk-2.15.6-mb1.04$B$N4A;z@55,I=8=%i%$(B
+     $B%V%i%j$rMxMQ$9$k$?$a$N%Q%C%A$r8x3+$7$?!#(Biso212$B0J9_$G$b(B
+     $BMxMQ2DG=!#(B
+   - jless-330-iso212$B$N(Bless.hlp$B$rF|K\8l2=$7$?$b$N$r8x3+$7$?!#(B
+     iso212$B0J9_$G$bMxMQ2DG=!#(B
+
+**FAQ**
+ Q: $BF|K\8l$,I=<($5$l$^$;$s!#2hLL>e$O!"H?E>I=<($5$l$?J8;z$G0l(B
+    $BGU$G$9!#(B
+ A: JLESSCHARSET$B4D6-JQ?t$K(B"japanese"$B$H@_Dj$7$^$7$g$&!#(BLANG$B4D(B
+    $B6-JQ?t$K(B"ja_JP"$B$J$I@_Dj$9$k$H$$$&J}K!$b$"$j$^$9!#9%$-$J(B
+    $BJ}K!$rA*$s$G2<$5$$!#(B
+
+ Q: $BF|K\8l$,I=<($5$l$^$;$s!#2hLL>e$O!"$J$s$+5-9f$G0lGU$G$9!#(B
+ A: less$B$,=PNO$7$F$$$k4A;z$rC<Kv$G<h$j07$($F$$$J$$$h$&$G$9!#(B
+    JLESSCHARSET$B4D6-JQ?t$K(B"japanese-ujis"$B$d(B"japanese-sjis"$B$J(B
+    $B$I!"MxMQ$7$F$kC<Kv$GI=<($G$-$k4A;z%3!<%I$r;XDj$7$F2<$5$$!#(B
+
+ Q: $B05=L$5$l$?%U%!%$%k$rFI$`$3$H$,$G$-$^$;$s!#(B
+ A: $B05=L$5$l$?%U%!%$%k$O(B".z"$B$d(B".gz"$B!"(B".Z"$B$H$$$C$?3HD%;R$K$h$C(B
+    $B$F6hJL$5$l$F$^$9!#$^$?!"$=$N%U%!%$%k$rE83+$9$k$K$O!"C1$K(B
+    "zcat"$B$r<B9T$7$F$$$^$9!#(BGNU$B$N(Bgzip$B$r(Bzcat$B$H$$$&L>A0$G%$%s(B
+    $B%9%H!<%k$7$F$*$/$3$H$r$*A&$a$7$^$9!#(B
+
+ Q: $BAG?M$N?M$G$b!"4A;z$,I=<($G$-$k$h$&$K!"%G%#%U%)%k%H$N@_Dj(B
+    $B$r$7$F%$%s%9%H!<%k$7$?$$$N$G$9$,!#(B
+ A: JLESSCHARSET$B$J$I$N4D6-JQ?t$,@_Dj$5$l$F$$$J$$>l9g$O!"(B
+    defines.h$BCf$N(BDEFCHARSET$B%^%/%m$NJ8;zNs$rMxMQ$7$^$9!#$3$l(B
+    $B$NJQ99$K$O!"$^$:(Bconfigure$B$r<B9T$7$F$*$/I,MW$,$"$j$^$9!#(B
+    $B$=$N8e$K!"(BDEFCHARSET$B%^%/%m$K(B"japanese"$B$J$I$NJ8;zNs$r@_Dj(B
+    $B$7!"<!$K(BHAVE_LOCALE$B%^%/%m$r(B0$B$K$7$F!"%3%s%Q%$%k$7$F2<$5$$!#(B
+
+ Q: $B$"$k%U%!%$%k$rFI$`$H!"2hLL$KI=<($5$l$kJ8;z$,2u$l$F$7$^$$!"(B
+    $B85$KLa$j$^$;$s!#(B
+ A: $BC<Kv$K$h$C$F$O(BISO 2022$B$r$A$c$s$H%5%]!<%H$7$F$$$^$;$s!#$=(B
+    $B$&$$$C$?C<Kv$rMxMQ$7$F$$$k>l9g$O!"(BJLESSCHARSET$B4D6-JQ?t$K!"(B
+    "japanese-jis"$B$J$I$H!"(BJIS$B$@$1$rMxMQ$9$k$3$H$rL@3N$K@_Dj(B
+    $B$7$F;H$C$F2<$5$$!#(B
+
+ Q: SJIS$B$N%U%!%$%k$rFI$`$H!"$?$^$KJQ$JJ8;z$,I=<($5$l$^$9!#(B
+ A: $B4A;z$N<+F0H=JL$O40`z$G$O$"$j$^$;$s!#$=$N$?$a!"B?>/LdBj$,(B
+    $BH/@8$7$^$9!#(B'^L'$B$HF~NO$7!"2hLL$r:FIA2h$9$k$HD>$k>l9g$,B?(B
+    $B$$$G$9!#$=$l$G$bBLL\$J$i!"(B'@'$B%-!<$r?t2s2!$7$F!"2hLL2<$K(B
+    "sjis codeset..."$B$HI=<($5$;$F2<$5$$!#<+F0H=JL$r6X;_$G$-(B
+    $B$^$9!#85$N>uBV$KLa$9$K$O!"$3$N%-!<$r7+$jJV$72!$7$F2<$5$$!#(B
+
+    $B0lJ}!"0z?t$K(B-Z$B$H;XDj$9$k$3$H$G!"(BSJIS$B$rM%@h$7$F<+F0H=JL$r(B
+    $B9T$&$3$H$b$G$-$^$9!#%3%s%Q%$%k;~$K(BSJIS_PRE$B$rDj5A$9$l$P!"(B
+    $B:G=i$+$i(BSJIS$B$rM%@h$7!"(B-Z$B$G:#EY$O5U$K(BUJIS$B$rM%@h$9$k$H$$$C(B
+    $B$?!"5U$NF0:n$r$9$k$h$&$K$b$G$-$^$9!#(B
+
+    $B$^$?!"(BJLESSCHARSET$B4D6-JQ?t$r(B"sjis"$B$K$9$k$3$H$G!":G=i$+$i(B
+    $B<+F0H=JL$r6X;_$9$k$3$H$b$G$-$^$9!#(B
+
+    $B$D$$$G$G$9$N$G!"<+F0H=JL$K$D$$$F!"$A$g$C$H@bL@$7$F$*$-$^(B
+    $B$9!#$^$:!"(Bless$B$G$O!"%P%C%U%!%j%s%0L5$7$GH=JL$r?J$a$k$?$a!"(B
+    $B4V0c$$$,B?$$$G$9!#$7$+$7!"0l2hLLJ,H=JL$7$?8e$K$OH=JL$,>e(B
+    $B<j$/$$$C$F$$$k$H9M$($i$l$k$?$a!"$=$l$G:Q$^$7$F$$$^$9!#(B
+
+    $BH=JLJ}K!<+BN$O!"IaDL$NJ}K!$G$9!#(BSJIS$B$H(BUJIS$B$H$G=E$J$C$F$$(B
+    $B$k%3!<%I$K$D$$$F$O!"H=JL8e$K8mH=JL$7$F$$$J$$$+$I$&$+D4::(B
+    $B$9$k$3$H$K$h$C$F!"H=JL$N<:GTN($r2<$2$F$$$k$D$b$j$G$9!#6q(B
+    $BBNE*$K$O!"(BSJIS$B$G8=$o$5$l$?(BJIS X0201 Japanese(Katakana)$B$H(B
+    $BH=CG$7$?Ns$NCf$K!"(B0xa4$B$,(B1$BJ8;z$*$-$K=P$F$-$?>l9g!"(BUJIS$B$N(B
+    $BJ?2>L>$NNs$G$"$k$H$7$F!"H=JL7k2L$rJQ99$7$F$$$^$9!#5U$r8@(B
+    $B$&$H!"(BSJIS$B$G8=$o$7$?(BJIS X0201 Japanese(Katakana)$B$NNs$NCf(B
+    $B$K!V(I$$B!W$r(B3$B2sB3$1$F(B1$BJ8;z$*$-$KF~$l$k$H!"8mH=JL$,H/@8$9$k(B
+    $B2DG=@-$,9b$/$J$j$^$9!#(B
+
+ Q: SJIS$B$G8!:w$9$kF|K\8l$rF~$l$k$HJQ$K$J$j$^$9!#(B
+ A: JLESSKEYCHARSET$B4D6-JQ?t$K(B"sjis-jis"$B$H@_Dj$7$^$7$g$&!#$^(B
+    $B$?%3%s%Q%$%k$9$k:]$K!"(Bdefines.h$BCf$G!"(BDEFKEYCHARSET$B$KDj5A(B
+    $B$7$F$$$kJ8;zNs$r!"(B"sjis-jis"$B$KJQ49$9$k$H$$$&<j$b$"$j$^$9!#(B
+
+ Q: $B8!:w$N;~$K4A;z$r(BJIS$B$GF~NO$7$h$&$H;W$&$N$G$9$,!">e<j$/$G(B
+    $B$-$^$;$s!#(B
+ A: $B%G%#%U%)%k%H$N@_Dj$G$O!"(B\e$$B$H$$$&%-!<F~NO$,MxMQ$5$l$F$$(B
+    $B$^$9!#(B"~/.lesskey"$B%U%!%$%k$K0J2<$r=q$-!"(Blesskey$B$r<B9T$7(B
+    $B$F$*$/$3$H$K$h$j!"(BJIS$B$GF~NO$G$-$k$h$&$K$J$j$^$9!#(B
+
+#line-edit
+\e$	insert ^V\e$
+
+ Q: $B:G2<9T$G$NJT=8$r(Bemacs-like$B$K$d$j$?$$$G$9!#(B
+ A: "~/.lesskey"$B%U%!%$%k$K0J2<$r=q$-!"(Blesskey$B$r<B9T$7$F2<$5(B
+    $B$$!#(B
+
+#line-edit
+^A	home
+^E	end
+^P	up
+^N	down
+^F	right
+^B	left
+\ef	word-right
+^D	delete
+\ed	word-delete
+
+ Q: NEWS-OS 4.0C$B$G$O!"(Bos.c$B$,%3%s%Q%$%k$G$-$^$;$s!#(B
+ A: "#include <setjmp.h>"$B$NA0$K!"0J2<$NDj5A$rF~$l$F2<$5$$!#(B
+
+#define LANGUAGE_C   1
+
+**$B:G8e$K(B**
+ - $B;D$k2]Bj$O!"J#?t%P%$%H$N8!:w$G$9!#$7$+$7!"$3$l$r=$@5$9$k(B
+   $B$K$O!"@55,I=8=%i%$%V%i%j$H??LLL\$K8~$-$"$&I,MW$,$"$j$^$9!#(B
+   $B:#$N=j!"$=$NM=Dj$O$"$j$^$;$s!#%Q%C%A$J$I!"4?7^$7$^$9!#(B
+ - $BLdBj$d2~A1MW5a$,$"$l$P(Bjam@poboxes.com$B$K%a%$%k$7$F2<$5$$!#(B
+   $BBP=h$G$-$k$+$b$7$l$^$;$s!#$^$?!"2~A1MW5a$K$D$$$F$O!"B??t(B
+   $B=8$^$l$P!"BP=h$9$k2DG=@-$b9b$/$J$j$^$9!#(B
+ - ftp://ftp.aist-nara.ac.jp/pub/personal/kazusi-m/less$B$K%Q%C(B
+   $B%AN`$r$^$H$a$h$&$H;W$C$F$$$^$9$N$G!"2?$+(Bunofficial patch
+   $B$H$7$FEj9F(B/$B%j%j!<%9$7$h$&$H;W$C$?J}$O!"KM$^$G%a%$%k$7$F$b(B
+   $B$i$($k$H4r$7$$$G$9!#(B
+
+
+Local Variables:
+mode: indented-text
+fill-column: 60
+End:
Index: less/charset.c
diff -u less/charset.c:1.1.1.9 less/charset.c:1.49
--- less/charset.c:1.1.1.9	Sun Dec  1 05:40:45 1996
+++ less/charset.c	Sun Jan 12 18:15:23 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -38,20 +41,139 @@
 
 /*
  * Predefined character sets,
- * selected by the LESSCHARSET environment variable.
+ * selected by the JLESSCHARSET or LESSCHARSET environment variable.
  */
 struct charset {
 	char *name;
 	char *desc;
+	CODESET left;
+	CODESET right;
+	CODESET output;
 } charsets[] = {
-	{ "ascii",	"8bcccbcc18b95.b"		},
-	{ "latin1",	"8bcccbcc18b95.33b."		},
-	{ "dos",	"8bcccbcc12bc5b95.b."		},
-	{ "koi8-r",	"8bcccbcc18b95.b128."		},
-	{ "next",	"8bcccbcc18b95.bb125.bb"	},
+	{ "ascii",	"8bcccbcc18b95.b",
+		noconv,		none,		noconv		},
+	{ "latin1",	"8bcccbcc18b95.33b.",
+		noconv,		noconv,		noconv		},
+	{ "dos",	"8bcccbcc12bc5b95.b.",
+		noconv,		noconv,		noconv		},
+	{ "koi8-r",	"8bcccbcc18b95.b128.",
+		noconv,		noconv,		noconv		},
+	{ "next",	"8bcccbcc18b95.bb125.bb",
+		noconv,		noconv,		noconv		},
+#if ISO
+	{ "iso7",	"8bcccb4c11bc4b96.b",
+		iso7,		noconv,		iso7		},
+	{ "iso8",	"8bcccb4c11bc4b95.15b2.16b.",
+		iso7,		iso8,		iso8		},
+# if JAPANESE
+	/* read some of KANJI code sets and iso7, write iso7. */
+	{ "ujis-iso7",	"8bcccb4c11bc4b96.14b2.17b94.b",
+		iso7,		ujis,		iso7		},
+	{ "euc-iso7",	"8bcccb4c11bc4b96.14b2.17b94.b",
+		iso7,		ujis,		iso7		},
+	{ "sjis-iso7",	"8bcccb4c11bc4b221.b",
+		iso7,		sjis,		iso7		},
+	/* read some of KANJI code sets, write jis. */
+	{ "jis",	"8bcccb4c11bc4b95.b",
+		jis,		none,		jis		},
+	{ "ujis-jis",	"8bcccb4c11bc4b95.15b2.17b94.b",
+		jis,		ujis,		jis		},
+	{ "euc-jis",	"8bcccb4c11bc4b95.15b2.17b94.b",
+		jis,		ujis,		jis		},
+	{ "sjis-jis",	"8bcccb4c11bc4b95.b125.3b",
+		jis,		sjis,		jis		},
+	/* read some of KANJI code sets, write ujis. */
+	{ "ujis",	"8bcccbcc18b95.15b2.17b94.b",
+		noconv,		ujis,		ujis		},
+	{ "euc",	"8bcccbcc18b95.15b2.17b94.b",
+		noconv,		ujis,		ujis		},
+	{ "jis-ujis",	"8bcccb4c11bc4b95.15b2.17b94.b",
+		jis,		ujis,		ujis		},
+	{ "jis-euc",	"8bcccb4c11bc4b95.15b2.17b94.b",
+		jis,		ujis,		ujis		},
+	/* read some of KANJI code sets, write sjis. */
+	{ "sjis",	"8bcccbcc18b95.b125.3b",
+		noconv,		sjis,		sjis		},
+	{ "jis-sjis",	"8bcccb4c11bc4b95.b125.3b",
+		jis,		sjis,		sjis		},
+	/* read all KANJI code sets, write iso7. */
+	{ "japanese-iso7",	"8bcccb4c11bc4b95.b127.b",
+		iso7,		japanese,	iso7		},
+	/* read all KANJI code sets, write some of KANJI code set. */
+	{ "japanese",		"8bcccb4c11bc4b95.b127.b",
+		jis,		japanese,	jis		},
+	{ "japanese-jis",	"8bcccb4c11bc4b95.b127.b",
+		jis,		japanese,	jis		},
+	{ "japanese-ujis",	"8bcccb4c11bc4b95.b127.b",
+		jis,		japanese,	ujis		},
+	{ "japanese-euc", 	"8bcccb4c11bc4b95.b127.b",
+		jis,		japanese,	ujis		},
+	{ "japanese-sjis",	"8bcccb4c11bc4b95.b127.b",
+		jis,		japanese,	sjis		},
+	/* following entries are special. */
+	/* read ujis, write sjis */
+	{ "ujis-sjis",	"8bcccbcc18b95.15b.18b94.b",
+		noconv,		ujis,		sjis		},
+	{ "euc-sjis",	"8bcccbcc18b95.15b.18b94.b",
+		noconv,		ujis,		sjis		},
+	/* read sjis, write ujis */
+	{ "sjis-ujis",	"8bcccbcc18b95.b125.3b",
+		noconv,		sjis,		ujis		},
+	{ "sjis-euc",	"8bcccbcc18b95.b125.3b",
+		noconv,		sjis,		ujis		},
+# endif
+#endif
 	{ NULL }
 };
 
+#if HAVE_LOCALE && ISO
+/*
+ * Predefined local languages,
+ * selected by the setlocale().
+ */
+struct charlocale {
+	char *name;
+	char *charset;
+} charlocales[] = {
+	{ "C",			"ascii"	},
+	{ "wr_WR.ct",		"iso8"	},
+	{ "ja_JP.jis8",		"iso8"		},
+# if JAPANESE
+	{ "ja_JP.JIS",		"japanese-jis"	},
+	{ "ja_JP.jis7",		"japanese-jis"	},
+	{ "ja_JP.EUC",		"japanese-ujis"	},
+	{ "ja_JP.ujis",		"japanese-ujis"	},
+	{ "ja_JP.SJIS",		"japanese-sjis"	},
+	{ "ja_JP.mscode",	"japanese-sjis"	},
+/* Other local locales */
+#  ifdef _AIX
+	/* AIX's */
+	{ "Ja_JP",		"japanese-sjis" },
+	{ "ja_JP.IBM-eucJP",	"japanese-ujis" },
+	{ "Ja_JP.IBM-932",	"japanese-sjis" },
+#  endif
+#  ifdef __hpux
+	/* HPUX */
+	{ "japanese",		"japanese-sjis" },
+	{ "japanese.euc",	"japanese-ujis" },
+#  endif
+	{ "ja",			"japanese-ujis" },
+	{ "ja_JP",		"japanese-ujis" },
+	{ "japan",		"japanese-ujis"	},
+	{ "Japan",		"japanese-ujis"	},
+	{ "japanese",		"japanese-ujis"	},
+	{ "Japanese",		"japanese-ujis"	},
+	/* DEC OSF/1's */
+	{ "ja_JP.eucJP",	"japanese-ujis"	},
+	{ "ja_JP.deckanji",	"japanese-ujis"	},
+	{ "ja_JP.sdeckanji",	"japanese-ujis"	},
+	/* BSDI's */
+	{ "Japanese-EUC",	"japanese-ujis"	},
+# endif
+	{ NULL }
+};
+#endif
+
 #define	IS_BINARY_CHAR	01
 #define	IS_CONTROL_CHAR	02
 
@@ -61,6 +183,36 @@
 
 
 /*
+ * Return the CODESET of left plane of named charset.
+ */
+	public CODESET
+left_codeset_of_charset(name)
+	register char *name;
+{
+	register struct charset *p;
+
+	for (p = charsets;  p->name != NULL;  p++)
+		if (name && strcmp(name, p->name) == 0)
+			return (p->left);
+	return (noconv);
+}
+
+/*
+ * Return the CODESET of right plane of named charset.
+ */
+	public CODESET
+right_codeset_of_charset(name)
+	register char *name;
+{
+	register struct charset *p;
+
+	for (p = charsets;  p->name != NULL;  p++)
+		if (name && strcmp(name, p->name) == 0)
+			return (p->right);
+	return (none);
+}
+
+/*
  * Define a charset, given a description string.
  * The string consists of 256 letters,
  * one for each character in the charset.
@@ -145,6 +297,9 @@
 		if (strcmp(name, p->name) == 0)
 		{
 			ichardef(p->desc);
+#if ISO
+			init_multi(p->left, p->right, p->output);
+#endif
 			return (1);
 		}
 	}
@@ -162,6 +317,41 @@
 ilocale()
 {
 	register int c;
+#if ISO
+	/*
+	 * We cannot trust in a system's ctype because it
+	 * cannot treat any coding system are not like EUC.
+	 */
+	register char *name;
+	register struct charlocale *p;
+
+#if UJIS_REGEXP
+	/* HP-UX is used LC_COLLATE to specify codes in the regexp library. */
+	(void) setlocale(LC_COLLATE, "");
+#endif
+	name = setlocale(LC_CTYPE, "");
+#ifdef __hpux
+	if (name != NULL)
+		name = getlocale(LOCALE_STATUS)->LC_CTYPE_D;
+#endif
+	/*
+	 * Search some environment variable like a setlocale()
+	 * because some poor system's setlocale treat only
+	 * system's local locale.
+	 */
+	if (name == NULL)
+		name = getenv("LC_CTYPE");
+	if (name == NULL)
+		name = getenv("LANG");
+	for (p = charlocales; name && p->name != NULL; p++)
+	{
+		if (strcmp(name, p->name) == 0)
+		{
+			(void) icharset(p->charset);
+			return;
+		}
+	}
+#endif
 
 	setlocale(LC_ALL, "");
 	for (c = 0;  c < sizeof(chardef);  c++)
@@ -214,6 +404,21 @@
 	s = lgetenv("LESSBINFMT");
 	setbinfmt(s);
 	
+#if ISO
+	s = getenv("JLESSPLANESET");
+	if (s == NULL)
+		s = DEFPLANESET;
+	set_planeset(s);
+#endif
+
+#if ISO
+	/*
+	 * See if environment variable JLESSCHARSET is defined.
+	 */
+	s = lgetenv("JLESSCHARSET");
+	if (icharset(s))
+		return;
+#endif
 	/*
 	 * See if environment variable LESSCHARSET is defined.
 	 */
@@ -221,7 +426,7 @@
 	if (icharset(s))
 		return;
 	/*
-	 * LESSCHARSET is not defined: try LESSCHARDEF.
+	 * JLESSCHARSET and LESSCHARSET are not defined: try LESSCHARDEF.
 	 */
 	s = lgetenv("LESSCHARDEF");
 	if (s != NULL && *s != '\0')
@@ -236,9 +441,10 @@
 	ilocale();
 #else
 	/*
-	 * Default to "ascii".
+	 * All variables are not defined either, default to DEFCHARSET.
+	 * DEFCHARSET is defined in defines.h.
 	 */
-	(void) icharset("ascii");
+	(void) icharset(DEFCHARSET);
 #endif
 }
 
@@ -264,18 +470,38 @@
 	return (chardef[c] & IS_CONTROL_CHAR);
 }
 
+#if ISO
+/*
+ * Change a database to check "control" character.
+ *  This function is called by multi.c only to support iso2022 charset.
+ */
+	public void
+change_control_char(c, flag)
+	int c, flag;
+{
+	c &= 0377;
+	if (flag)
+		chardef[c] |= IS_CONTROL_CHAR;
+	else
+		chardef[c] &= ~IS_CONTROL_CHAR;
+}
+#endif
+
 /*
  * Return the printable form of a character.
  * For example, in the "ascii" charset '\3' is printed as "^C".
  */
 	public char *
-prchar(c)
+prchar(c, cs)
 	int c;
+	CHARSET cs;
 {
 	static char buf[8];
 
 	c &= 0377;
-	if (!control_char(c))
+	if (CSISWRONG(cs) && c > 127)
+		sprintf(buf, binfmt, c);
+	else if (!control_char(c))
 		sprintf(buf, "%c", c);
 	else if (c == ESC)
 		sprintf(buf, "ESC");
Index: less/cmd.h
diff -u less/cmd.h:1.1.1.7 less/cmd.h:1.10
--- less/cmd.h:1.1.1.7	Sat Sep 14 00:36:04 1996
+++ less/cmd.h	Sun Jan 12 18:15:24 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -78,6 +81,10 @@
 #define	A_OPT_UNSET		49
 #define	A_F_FOREVER		50
 #define	A_GOPOS			51
+
+#if JAPANESE
+#define A_ROT_RCODESET		80
+#endif
 
 #define	A_INVALID		100
 #define	A_NOACTION		101
Index: less/cmdbuf.c
diff -u less/cmdbuf.c:1.1.1.9 less/cmdbuf.c:1.25
--- less/cmdbuf.c:1.1.1.9	Sun Dec  1 05:40:46 1996
+++ less/cmdbuf.c	Sun Jan 12 18:15:25 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -41,6 +44,11 @@
 static char *cp;		/* Pointer into cmdbuf */
 static int cmd_offset;		/* Index into cmdbuf of first displayed char */
 static int literal;		/* Next input char should not be interpreted */
+static CHARSET cmdcs[CMDBUF_SIZE]; /* Buffer for holding a CHARSET of cmdbuf */
+static CHARSET *csp;		/* Pointer into cmdcs */
+#if ISO
+static MULBUF *mp = NULL;
+#endif
 
 #if TAB_COMPLETE_FILENAME
 static int cmd_complete();
@@ -73,6 +81,7 @@
 	struct mlist *prev;
 	struct mlist *curr_mp;
 	char *string;
+	CHARSET *charset;
 };
 
 /*
@@ -110,6 +119,25 @@
 
 
 /*
+ * Count the width of strings.
+ */
+	static int
+strwidth(s, cs)
+	char *s;
+	CHARSET cs;
+{
+#if ISO
+	int w = 0;
+
+	while (*s != '\0')
+		w += mwidth(*s++, cs);
+	return (w);
+#else
+	return (strlen(s));
+#endif
+}
+
+/*
  * Reset command buffer (to empty).
  */
 	public void
@@ -117,9 +145,23 @@
 {
 	cp = cmdbuf;
 	*cp = '\0';
+	csp = cmdcs;
 	cmd_col = 0;
 	cmd_offset = 0;
 	literal = 0;
+#if ISO
+	if (mp == NULL)
+	{
+		char *s = NULL;
+		mp = new_multi();
+		s = getenv("JLESSKEYCHARSET");
+		if (s == NULL)
+			s = DEFKEYCHARSET;
+		set_codesets(mp, left_codeset_of_charset(s),
+			     right_codeset_of_charset(s));
+	}
+	prewind_multi(mp, -1);
+#endif
 }
 
 /*
@@ -140,8 +182,8 @@
 	char *s;
 {
 	putstr(s);
-	cmd_col += strlen(s);
-	prompt_col += strlen(s);
+	cmd_col += strwidth(s, ASCII);
+	prompt_col += strwidth(s, ASCII);
 }
 
 /*
@@ -167,13 +209,13 @@
 	 * Repaint the line from the current position.
 	 */
 	clear_eol();
-	for ( ;  *cp != '\0';  cp++)
+	for ( ;  *cp != '\0';  cp++, csp++)
 	{
-		p = prchar(*cp);
-		if (cmd_col + strlen(p) >= sc_width)
+		p = prchar(*cp, *csp);
+		if (cmd_col + strwidth(p, *csp) >= sc_width)
 			break;
-		putstr(p);
-		cmd_col += strlen(p);
+		putmchrs(p, *csp);
+		cmd_col += strwidth(p, *csp);
 	}
 
 	/*
@@ -197,6 +239,7 @@
 	}
 
 	cp = &cmdbuf[cmd_offset];
+	csp = &cmdcs[cmd_offset];
 }
 
 /*
@@ -206,6 +249,7 @@
 cmd_lshift()
 {
 	char *s;
+	CHARSET *t;
 	char *save_cp;
 	int cols;
 
@@ -214,9 +258,10 @@
 	 * right we'd have to move to reach the center of the screen.
 	 */
 	s = cmdbuf + cmd_offset;
-	cols = 0;
-	while (cols < (sc_width - prompt_col) / 2 && *s != '\0')
-		cols += strlen(prchar(*s++));
+	t = cmdcs + cmd_offset;
+	for (cols = 0; cols < (sc_width - prompt_col) / 2 && *s != '\0';
+	     s++, t++)
+		cols += strwidth(prchar(*s, *t), *t);
 
 	cmd_offset = s - cmdbuf;
 	save_cp = cp;
@@ -231,6 +276,7 @@
 cmd_rshift()
 {
 	char *s;
+	CHARSET *t;
 	char *p;
 	char *save_cp;
 	int cols;
@@ -241,11 +287,12 @@
 	 * of displayed characters.
 	 */
 	s = cmdbuf + cmd_offset;
+	t = cmdcs + cmd_offset;
 	cols = 0;
 	while (cols < (sc_width - prompt_col) / 2 && s > cmdbuf)
 	{
-		p = prchar(*--s);
-		cols += strlen(p);
+		p = prchar(*--s, *--t);
+		cols += strwidth(p, *t);
 	}
 
 	cmd_offset = s - cmdbuf;
@@ -262,6 +309,9 @@
 {
 	char *p;
 	
+#if ISO
+	do {
+#endif
 	if (*cp == '\0')
 	{
 		/* 
@@ -269,14 +319,18 @@
 		 */
 		return (CC_OK);
 	}
-	p = prchar(*cp);
-	if (cmd_col + strlen(p) >= sc_width)
+	p = prchar(*cp, *csp);
+	if (cmd_col + strwidth(p, *csp) >= sc_width)
 		cmd_lshift();
-	else if (cmd_col + strlen(p) == sc_width - 1 && cp[1] != '\0')
+	else if (cmd_col + strwidth(p, *csp) == sc_width - 1 && cp[1] != '\0')
 		cmd_lshift();
+	putmchrs(p, *csp);
+	cmd_col += strwidth(p, *csp);
 	cp++;
-	putstr(p);
-	cmd_col += strlen(p);
+	csp++;
+#if ISO
+	} while (CSISREST(*csp));
+#endif
 	return (CC_OK);
 }
 
@@ -288,18 +342,25 @@
 {
 	char *p;
 	
+#if ISO
+	do {
+#endif
 	if (cp <= cmdbuf)
 	{
 		/* Already at the beginning of the line */
 		return (CC_OK);
 	}
-	p = prchar(cp[-1]);
-	if (cmd_col < prompt_col + strlen(p))
+	p = prchar(cp[-1], csp[-1]);
+	if (cmd_col < prompt_col + strwidth(p, csp[-1]))
 		cmd_rshift();
 	cp--;
-	cmd_col -= strlen(p);
+	csp--;
+	cmd_col -= strwidth(p, *csp);
 	while (*p++ != '\0')
 		putbs();
+#if ISO
+	} while (CSISREST(*csp));
+#endif
 	return (CC_OK);
 }
 
@@ -311,8 +372,13 @@
 	int c;
 {
 	char *s;
+	CHARSET *t;
 	
+#if ISO
+	if (strlen(cmdbuf) >= sizeof(cmdbuf)-5)
+#else
 	if (strlen(cmdbuf) >= sizeof(cmdbuf)-2)
+#endif
 	{
 		/*
 		 * No room in the command buffer for another char.
@@ -324,9 +390,44 @@
 	/*
 	 * Insert the character into the buffer.
 	 */
-	for (s = &cmdbuf[strlen(cmdbuf)];  s >= cp;  s--)
+#if ISO
+	if (in_mca())
+	{
+		char *cbuf;
+		CHARSET *csbuf;
+		int i, j;
+
+		buffering_multi(mp, c, &cbuf, &csbuf, &i);
+		if (i > 0)
+			for ((s = &cmdbuf[strlen(cmdbuf)]),
+			     t = &cmdcs[strlen(cmdbuf)];  s >= cp;  s--, t--)
+			{
+				s[i] = s[0];
+				t[i] = t[0];
+			}
+		for (j = 0; j < i; j++)
+		{
+			cp[j] = cbuf[j];
+			csp[j] = csbuf[j];
+		}
+		cbuf = &cp[i];
+		/*
+		 * Reprint the tail of the line from the inserted char.
+		 */
+		cmd_repaint(cp);
+		while (cp < cbuf)
+			cmd_right();
+		return (CC_OK);
+	}
+#endif
+	for ((s = &cmdbuf[strlen(cmdbuf)]), t = &cmdcs[strlen(cmdbuf)];
+	     s >= cp;  s--, t--)
+	{
 		s[1] = s[0];
+		t[1] = t[0];
+	}
 	*cp = c;
+	*csp = ASCII;
 	/*
 	 * Reprint the tail of the line from the inserted char.
 	 */
@@ -343,6 +444,8 @@
 cmd_erase()
 {
 	register char *s;
+	register CHARSET *t;
+	int num;
 
 	if (cp == cmdbuf)
 	{
@@ -355,12 +458,17 @@
 	/*
 	 * Move cursor left (to the char being erased).
 	 */
+	s = cp;
 	cmd_left();
+	num = s - cp;
 	/*
 	 * Remove the char from the buffer (shift the buffer left).
 	 */
-	for (s = cp;  *s != '\0';  s++)
-		s[0] = s[1];
+	for ((s = cp), t = csp;  *s != '\0';  s++, t++)
+	{
+		s[0] = s[num];
+		t[0] = t[num];
+	}
 	/*
 	 * Repaint the buffer after the erased char.
 	 */
@@ -498,6 +606,8 @@
 	int action;
 {
 	char *s;
+	CHARSET *t;
+	int i;
 	
 	if (curr_mlist == NULL)
 	{
@@ -520,14 +630,17 @@
 	 * Copy the entry into cmdbuf and echo it on the screen.
 	 */
 	s = curr_mlist->curr_mp->string;
+	t = curr_mlist->curr_mp->charset;
 	if (s == NULL)
 		s = "";
-	for (cp = cmdbuf;  *s != '\0';  s++)
+	for ((cp = cmdbuf), (csp = cmdcs), i = 0;  *s != '\0';  s++, t++, i++)
 	{
-		*cp = *s;
-		cmd_right();
+		cp[i] = *s;
+		csp[i] = *t;
 	}
-	*cp = '\0';
+	cp[i] = '\0';
+	while (*cp != '\0')
+		cmd_right();
 	return (CC_OK);
 }
 #endif
@@ -569,6 +682,9 @@
 		 */
 		ml = (struct mlist *) ecalloc(1, sizeof(struct mlist));
 		ml->string = save(cmdbuf);
+		ml->charset = (CHARSET *)
+			ecalloc(strlen(cmdbuf), sizeof(CHARSET));
+		memcpy(ml->charset, cmdcs, strlen(cmdbuf) * sizeof(CHARSET));
 		ml->next = curr_mlist;
 		ml->prev = curr_mlist->prev;
 		curr_mlist->prev->next = ml;
@@ -1023,4 +1139,13 @@
 get_cmdbuf()
 {
 	return (cmdbuf);
+}
+
+/*
+ * Return a pointer to the character set bufffer of the command buffer.
+ */
+	public CHARSET *
+get_cmdcs()
+{
+	return (cmdcs);
 }
Index: less/command.c
diff -u less/command.c:1.1.1.11 less/command.c:1.16
--- less/command.c:1.1.1.11	Sun Dec  1 05:40:47 1996
+++ less/command.c	Sun Jan 12 18:15:26 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -152,15 +155,17 @@
 exec_mca()
 {
 	register char *cbuf;
+	CHARSET *csbuf;
 
 	cmd_exec();
 	cbuf = get_cmdbuf();
+	csbuf = get_cmdcs();
 
 	switch (mca)
 	{
 	case A_F_SEARCH:
 	case A_B_SEARCH:
-		multi_search(cbuf, number);
+		multi_search(cbuf, csbuf, number);
 		break;
 	case A_FIRSTCMD:
 		/*
@@ -593,8 +598,9 @@
  * If SRCH_PAST_EOF is set, continue the search thru multiple files.
  */
 	static void
-multi_search(pattern, n)
+multi_search(pattern, charset, n)
 	char *pattern;
+	CHARSET *charset;
 	int n;
 {
 	register int nomore;
@@ -625,7 +631,7 @@
 
 	for (;;)
 	{
-		n = search(search_type, pattern, n);
+		n = search(search_type, pattern, charset, n);
 		/*
 		 * The SRCH_NO_MOVE flag doesn't "stick": it gets cleared
 		 * after being used once.  This allows "n" to work after
@@ -1056,7 +1062,7 @@
 #define	DO_SEARCH()	if (number <= 0) number = 1;	\
 			mca_search();			\
 			cmd_exec();			\
-			multi_search((char *)NULL, number);
+			multi_search((char *)NULL, (CHARSET *)NULL, number);
 
 
 		case A_F_SEARCH:
@@ -1359,6 +1365,16 @@
 			}
 			c = getcc();
 			goto again;
+
+#if JAPANESE
+		case A_ROT_RCODESET:
+			parg.p_string =
+				rotate_right_codeset(get_mulbuf(curr_ifile));
+			screen_trashed = 1;
+			make_display();
+			error("%s codeset is used in right plane", &parg);
+			break;
+#endif
 
 		case A_NOACTION:
 			break;
Index: less/decode.c
diff -u less/decode.c:1.1.1.11 less/decode.c:1.14
--- less/decode.c:1.1.1.11	Sun Dec  1 05:40:47 1996
+++ less/decode.c	Sun Jan 12 18:15:26 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -154,6 +157,10 @@
 	'v',0,				A_VISUAL,
 	'!',0,				A_SHELL,
 	'+',0,				A_FIRSTCMD,
+
+#if JAPANESE
+	'@',0,				A_ROT_RCODESET,
+#endif
 
 	'H',0,				A_HELP,
 	'h',0,				A_HELP,
Index: less/defines.ds
diff -u less/defines.ds:1.1.1.1 less/defines.ds:1.5
--- less/defines.ds:1.1.1.1	Sun Dec  1 05:41:22 1996
+++ less/defines.ds	Sun Jan 12 18:15:27 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -187,6 +190,46 @@
  * HAVE_DUP is 1 if your system has the dup() call.
  */
 #define	HAVE_DUP	1
+
+/*
+ * COMPRESS is 1 if you want to read comressed file.
+ */
+#define	COMPRESS	1
+
+/*
+ * ISO is 1 if you want to read code which contain many character sets
+ * by using iso 2022 code extension techniques.
+ */
+#define	ISO		1
+
+/*
+ * JAPANESE is 1 if you want to read several KANJI code.
+ */
+#define	JAPANESE	1
+#if JAPANESE && !ISO
+# define ISO 1
+#endif
+
+/*
+ * DEFCHARSET is name of the default character set.
+ * This used as LESSCHARSET envrionment variable if user did not define it.
+ * The value of this must equal one of the available value which can use as
+ * LESSCHARSET environment variable
+ */
+#define	DEFCHARSET	"iso8"
+
+/*
+ * DEFPLANESET is name of the default plane set of iso 2022 extension.
+ * This used as LESSPLANESET envrionment variable if user did not define it.
+ * The value of this must equal one of the available value which can use as
+ * LESSPLANESET environment variable or any escape sequence for setting up.
+ */
+#define	DEFPLANESET	"ctext"
+
+/*
+ * DEFKEYCHARSET is name of the default character set for keyboard input.
+ */
+#define	DEFKEYCHARSET	"sjis-jis"
 
 /*
  * Sizes of various buffers.
Index: less/defines.h.in
diff -u less/defines.h.in:1.1.1.10 less/defines.h.in:1.23
--- less/defines.h.in:1.1.1.10	Sun Dec  1 05:41:14 1996
+++ less/defines.h.in	Sat Jan 11 01:27:03 1997
@@ -158,6 +158,46 @@
 #define	HAVE_DUP	1
 
 /*
+ * COMPRESS is 1 if you want to read comressed file.
+ */
+#define	COMPRESS	1
+
+/*
+ * ISO is 1 if you want to read code which contain many character sets
+ * by using iso 2022 code extension techniques.
+ */
+#define	ISO		1
+
+/*
+ * JAPANESE is 1 if you want to read several KANJI code.
+ */
+#define	JAPANESE	1
+#if JAPANESE && !ISO
+# define ISO 1
+#endif
+
+/*
+ * DEFCHARSET is name of the default character set.
+ * This used as LESSCHARSET envrionment variable if user did not define it.
+ * The value of this must equal one of the available value which can use as
+ * LESSCHARSET environment variable
+ */
+#define	DEFCHARSET	"iso8"
+
+/*
+ * DEFPLANESET is name of the default plane set of iso 2022 extension.
+ * This used as LESSPLANESET envrionment variable if user did not define it.
+ * The value of this must equal one of the available value which can use as
+ * LESSPLANESET environment variable or any escape sequence for setting up.
+ */
+#define	DEFPLANESET	"ctext"
+
+/*
+ * DEFKEYCHARSET is name of the default character set for keyboard input.
+ */
+#define	DEFKEYCHARSET	"japanese"
+
+/*
  * Sizes of various buffers.
  */
 #define	CMDBUF_SIZE	512	/* Buffer for multichar commands */
Index: less/defines.h.top
diff -u less/defines.h.top:1.1.1.8 less/defines.h.top:1.21
--- less/defines.h.top:1.1.1.8	Sun Dec  1 05:41:15 1996
+++ less/defines.h.top	Sat Jan 11 01:27:04 1997
@@ -157,6 +157,46 @@
 #define	HAVE_DUP	1
 
 /*
+ * COMPRESS is 1 if you want to read comressed file.
+ */
+#define	COMPRESS	1
+
+/*
+ * ISO is 1 if you want to read code which contain many character sets
+ * by using iso 2022 code extension techniques.
+ */
+#define	ISO		1
+
+/*
+ * JAPANESE is 1 if you want to read several KANJI code.
+ */
+#define	JAPANESE	1
+#if JAPANESE && !ISO
+# define ISO 1
+#endif
+
+/*
+ * DEFCHARSET is name of the default character set.
+ * This used as LESSCHARSET envrionment variable if user did not define it.
+ * The value of this must equal one of the available value which can use as
+ * LESSCHARSET environment variable
+ */
+#define	DEFCHARSET	"iso8"
+
+/*
+ * DEFPLANESET is name of the default plane set of iso 2022 extension.
+ * This used as LESSPLANESET envrionment variable if user did not define it.
+ * The value of this must equal one of the available value which can use as
+ * LESSPLANESET environment variable or any escape sequence for setting up.
+ */
+#define	DEFPLANESET	"ctext"
+
+/*
+ * DEFKEYCHARSET is name of the default character set for keyboard input.
+ */
+#define	DEFKEYCHARSET	"japanese"
+
+/*
  * Sizes of various buffers.
  */
 #define	CMDBUF_SIZE	512	/* Buffer for multichar commands */
Index: less/defines.o2
diff -u less/defines.o2:1.1.1.1 less/defines.o2:1.5
--- less/defines.o2:1.1.1.1	Sun Dec  1 05:41:23 1996
+++ less/defines.o2	Sun Jan 12 18:16:09 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -167,6 +170,46 @@
  * HAVE_DUP is 1 if your system has the dup() call.
  */
 #define	HAVE_DUP	1
+
+/*
+ * COMPRESS is 1 if you want to read comressed file.
+ */
+#define	COMPRESS	1
+
+/*
+ * ISO is 1 if you want to read code which contain many character sets
+ * by using iso 2022 code extension techniques.
+ */
+#define	ISO		1
+
+/*
+ * JAPANESE is 1 if you want to read several KANJI code.
+ */
+#define	JAPANESE	1
+#if JAPANESE && !ISO
+# define ISO 1
+#endif
+
+/*
+ * DEFCHARSET is name of the default character set.
+ * This used as LESSCHARSET envrionment variable if user did not define it.
+ * The value of this must equal one of the available value which can use as
+ * LESSCHARSET environment variable
+ */
+#define	DEFCHARSET	"iso8"
+
+/*
+ * DEFPLANESET is name of the default plane set of iso 2022 extension.
+ * This used as LESSPLANESET envrionment variable if user did not define it.
+ * The value of this must equal one of the available value which can use as
+ * LESSPLANESET environment variable or any escape sequence for setting up.
+ */
+#define	DEFPLANESET	"ctext"
+
+/*
+ * DEFKEYCHARSET is name of the default character set for keyboard input.
+ */
+#define	DEFKEYCHARSET	"japanese"
 
 /*
  * Sizes of various buffers.
Index: less/defines.o9
diff -u less/defines.o9:1.1.1.2 less/defines.o9:1.6
--- less/defines.o9:1.1.1.2	Sun Dec  1 05:41:24 1996
+++ less/defines.o9	Sun Jan 12 18:16:10 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -180,6 +183,46 @@
  * HAVE_DUP is 1 if your system has the dup() call.
  */
 #define	HAVE_DUP 0
+
+/*
+ * COMPRESS is 1 if you want to read comressed file.
+ */
+#define	COMPRESS	1
+
+/*
+ * ISO is 1 if you want to read code which contain many character sets
+ * by using iso 2022 code extension techniques.
+ */
+#define	ISO		1
+
+/*
+ * JAPANESE is 1 if you want to read several KANJI code.
+ */
+#define	JAPANESE	1
+#if JAPANESE && !ISO
+# define ISO 1
+#endif
+
+/*
+ * DEFCHARSET is name of the default character set.
+ * This used as LESSCHARSET envrionment variable if user did not define it.
+ * The value of this must equal one of the available value which can use as
+ * LESSCHARSET environment variable
+ */
+#define	DEFCHARSET	"iso8"
+
+/*
+ * DEFPLANESET is name of the default plane set of iso 2022 extension.
+ * This used as LESSPLANESET envrionment variable if user did not define it.
+ * The value of this must equal one of the available value which can use as
+ * LESSPLANESET environment variable or any escape sequence for setting up.
+ */
+#define	DEFPLANESET	"ctext"
+
+/*
+ * DEFKEYCHARSET is name of the default character set for keyboard input.
+ */
+#define	DEFKEYCHARSET	"japanese"
 
 /*
  * Sizes of various buffers.
Index: less/defines.wn
diff -u less/defines.wn:1.1.1.1 less/defines.wn:1.5
--- less/defines.wn:1.1.1.1	Sun Dec  1 05:41:25 1996
+++ less/defines.wn	Sun Jan 12 18:16:10 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -168,6 +171,46 @@
  * HAVE_DUP is 1 if your system has the dup() call.
  */
 #define	HAVE_DUP	1
+
+/*
+ * COMPRESS is 1 if you want to read comressed file.
+ */
+#define	COMPRESS	1
+
+/*
+ * ISO is 1 if you want to read code which contain many character sets
+ * by using iso 2022 code extension techniques.
+ */
+#define	ISO		1
+
+/*
+ * JAPANESE is 1 if you want to read several KANJI code.
+ */
+#define	JAPANESE	1
+#if JAPANESE && !ISO
+# define ISO 1
+#endif
+
+/*
+ * DEFCHARSET is name of the default character set.
+ * This used as LESSCHARSET envrionment variable if user did not define it.
+ * The value of this must equal one of the available value which can use as
+ * LESSCHARSET environment variable
+ */
+#define	DEFCHARSET	"iso8"
+
+/*
+ * DEFPLANESET is name of the default plane set of iso 2022 extension.
+ * This used as LESSPLANESET envrionment variable if user did not define it.
+ * The value of this must equal one of the available value which can use as
+ * LESSPLANESET environment variable or any escape sequence for setting up.
+ */
+#define	DEFPLANESET	"ctext"
+
+/*
+ * DEFKEYCHARSET is name of the default character set for keyboard input.
+ */
+#define	DEFKEYCHARSET	"sjis-jis"
 
 /*
  * Sizes of various buffers.
Index: less/filename.c
diff -u less/filename.c:1.1.1.10 less/filename.c:1.16
--- less/filename.c:1.1.1.10	Sun Dec  1 05:40:49 1996
+++ less/filename.c	Sun Jan 12 18:16:11 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of compress file treating routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -769,6 +772,25 @@
 	return (gfilename);
 }
 
+#if COMPRESS
+/*
+ * Check a name of input file and easy execution some uncompressing program.
+ */
+	static char*
+easy_lessopen_for_zcatfile(filename)
+	register char *filename;
+{
+	register int length = strlen(filename);
+
+	if (strcmp(".Z", &filename[length - 2]) == 0 ||
+	    strcmp(".z", &filename[length - 2]) == 0 ||
+	    strcmp(".gz", &filename[length - 3]) == 0)
+		return ("| zcat %s");
+	else
+		return (NULL);
+}
+#endif
+
 /*
  * See if we should open a "replacement file" 
  * instead of the file we're about to open.
@@ -794,6 +816,9 @@
 		return (NULL);
 	ch_ungetchar(-1);
 	if ((lessopen = lgetenv("LESSOPEN")) == NULL)
+#if COMPRESS
+	    if ((lessopen = easy_lessopen_for_zcatfile(filename)) == NULL)
+#endif
 		return (NULL);
 	if (strcmp(filename, "-") == 0)
 		return (NULL);
Index: less/funcs.h
diff -u less/funcs.h:1.1.1.10 less/funcs.h:1.29
--- less/funcs.h:1.1.1.10	Sun Dec  1 05:41:10 1996
+++ less/funcs.h	Sat Jan 11 01:27:06 1997
@@ -47,9 +47,12 @@
 	public void ch_close ();
 	public int ch_getflags ();
 	public void ch_dump ();
+	public CODESET left_codeset_of_charset ();
+	public CODESET right_codeset_of_charset ();
 	public void init_charset ();
 	public int binary_char ();
 	public int control_char ();
+	public void change_control_char ();
 	public char * prchar ();
 	public void cmd_reset ();
 	public void clear_cmd ();
@@ -60,6 +63,7 @@
 	public int cmd_char ();
 	public int cmd_int ();
 	public char * get_cmdbuf ();
+	public CHARSET * get_cmdcs ();
 	public int in_mca ();
 	public void dispversion ();
 	public int getcc ();
@@ -121,6 +125,7 @@
 	public void store_pos ();
 	public void get_pos ();
 	public void set_open ();
+	public MULBUF * get_mulbuf ();
 	public int opened ();
 	public void hold_ifile ();
 	public int held_ifile ();
@@ -167,6 +172,7 @@
 	public void opt__P ();
 	public void opt_b ();
 	public void opt_i ();
+	public void opt_Z ();
 	public void opt__V ();
 	public void opt_D ();
 	public void opt_quote ();
@@ -191,8 +197,13 @@
 	public int  isatty ();
 	public void put_line ();
 	public void flush ();
+	public int putchr_raw ();
+	public void putstr_raw ();
 	public int putchr ();
 	public void putstr ();
+	public int putmchr ();
+	public int putmchrs ();
+	public void putmstr ();
 	public void get_return ();
 	public void error ();
 	public void ierror ();
@@ -207,6 +218,25 @@
 	public int empty_lines ();
 	public void get_scrpos ();
 	public int adjsline ();
+	public void set_planeset ();
+	public void init_multi ();
+	public void init_def_priority ();
+	public void init_priority ();
+	public CODESET get_priority ();
+	public void set_priority ();
+	public MULBUF * new_multi ();
+	public void prewind_multi ();
+	public void buffering_multi ();
+	public void parsing_multi ();
+	public void pdone_multi ();
+	public void set_codesets ();
+	public int get_bufbytes ();
+	public void set_bufbytes ();
+	public char * get_icharset_string ();
+	public char * outchar();
+	public char * outbuf();
+	public int mwidth();
+	public char * rotate_right_codeset ();
 	public void init_prompt ();
 	public char * pr_expand ();
 	public char * eq_message ();
Index: less/ifile.c
diff -u less/ifile.c:1.1.1.8 less/ifile.c:1.11
--- less/ifile.c:1.1.1.8	Sun Dec  1 05:40:51 1996
+++ less/ifile.c	Sun Jan 12 18:16:11 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -49,6 +52,7 @@
 	int h_hold;			/* Hold count */
 	char h_opened;			/* Has this ifile been opened? */
 	struct scrpos h_scrpos;		/* Saved position within the file */
+	MULBUF *h_mp;			/* MULBUF for multi bytes character */
 };
 
 /*
@@ -128,6 +132,9 @@
 	p->h_opened = 0;
 	p->h_hold = 0;
 	p->h_filestate = NULL;
+#if ISO
+	p->h_mp = new_multi();
+#endif
 	link_ifile(p, prev);
 	return (p);
 }
@@ -152,6 +159,9 @@
 	p = int_ifile(h);
 	unlink_ifile(p);
 	free(p->h_filename);
+#if ISO
+	free(p->h_mp);
+#endif
 	free(p);
 }
 
@@ -285,6 +295,20 @@
 	struct scrpos *scrpos;
 {
 	*scrpos = int_ifile(ifile)->h_scrpos;
+}
+
+/*
+ * Get the MULBUF associated with a ifile.
+ */
+	public MULBUF *
+get_mulbuf(ifile)
+	IFILE ifile;
+{
+#if ISO
+	if (ifile != NULL)
+		return (int_ifile(ifile)->h_mp);
+#endif
+	return (NULL);
 }
 
 /*
Index: less/input.c
diff -u less/input.c:1.1.1.6 less/input.c:1.18
--- less/input.c:1.1.1.6	Sat Sep 14 00:35:11 1996
+++ less/input.c	Sun Jan 12 18:16:12 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -45,6 +48,7 @@
 extern int hilite_search;
 extern int size_linebuf;
 #endif
+extern IFILE curr_ifile;
 
 /*
  * Get the next line.
@@ -85,7 +89,7 @@
 		return (NULL_POSITION);
 	}
 
-	prewind();
+	prewind(curr_pos);
 	plinenum(curr_pos);
 	(void) ch_seek(curr_pos);
 
@@ -129,19 +133,32 @@
 				do
 				{
 					c = ch_forw_get();
+#if ISO
+					/*
+					 * Parse all character for finding
+					 * escape sequences.
+					 */
+					parsing_multi(get_mulbuf(curr_ifile),
+						      c);
+#endif
 				} while (c != '\n' && c != EOI);
 				new_pos = ch_tell();
 				endline = 1;
 			} else
 			{
+#if ISO
+				new_pos = ch_tell() -
+					get_bufbytes(get_mulbuf(curr_ifile));
+#else
 				new_pos = ch_tell() - 1;
+#endif
 				endline = 0;
 			}
 			break;
 		}
 		c = ch_forw_get();
 	}
-	pdone(endline);
+	pdone(endline, new_pos);
 
 	if (squeeze && blankline)
 	{
@@ -276,7 +293,7 @@
 	endline = 0;
     loop:
 	begin_new_pos = new_pos;
-	prewind();
+	prewind(new_pos);
 	plinenum(new_pos);
 	(void) ch_seek(new_pos);
 
@@ -306,14 +323,24 @@
 				endline = 1;
 				break;
 			}
-			pdone(0);
+#if ISO
+			for (c = get_bufbytes(get_mulbuf(curr_ifile));
+			     --c >= 0; )
+			{
+				(void) ch_back_get();
+				new_pos--;
+			}
+			pdone(0, new_pos);
+#else
+			pdone(0, new_pos);
 			(void) ch_back_get();
 			new_pos--;
+#endif
 			goto loop;
 		}
 	} while (new_pos < curr_pos);
 
-	pdone(endline);
+	pdone(endline, new_pos);
 
 	return (begin_new_pos);
 }
Index: less/less.h
diff -u less/less.h:1.1.1.12 less/less.h:1.39
--- less/less.h:1.1.1.12	Sun Dec  1 05:41:11 1996
+++ less/less.h	Sat Jan 18 03:45:54 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -281,6 +284,103 @@
 #define	AT_BLINK	(3)
 #define	AT_INVIS	(4)
 #define	AT_STANDOUT	(5)
+
+
+/*
+ * Definition of values to specify the character set.
+ * And definitions some well known character sets and a types of set.
+ */
+typedef unsigned short CHARSET;
+
+#define	WRONG_CHAR		0x8000	/* Display this as binary characters */
+#define CSISWRONG(cs)		((cs) & WRONG_CHAR)
+
+#define	REST_MASK		0x4000	/* Rest bytes of character */
+#define CSISHEAD(cs)		(!((cs) & REST_MASK))
+#define CSISREST(cs)		((cs) & REST_MASK)
+
+#define IRR_MASK		0x3f00
+#define IRR_SHIFT		8
+#define CS2IRR(cs)		(((cs) & IRR_MASK) >> IRR_SHIFT)
+#define IRR2CS(irr)		(((irr) << IRR_SHIFT) & IRR_MASK)
+
+#define CODE_MASK		0x003f
+#define CODE_DIFF		0x0040
+#define IRR2CODE(irr)		((((irr) - 1) & CODE_MASK) + CODE_DIFF)
+#define CODE2IRR(code)		((((code) - CODE_DIFF) & CODE_MASK) + 1)
+
+#define TYPE_94_CHARSET		0x0000
+#define TYPE_96_CHARSET		0x0040
+#define TYPE_94N_CHARSET	0x0080
+#define TYPE_96N_CHARSET	0x00c0
+#define TYPE_MASK		0x00c0
+#define CS2TYPE(cs)		((cs) & TYPE_MASK)
+#define TYPE2CS(type)		((type) & TYPE_MASK)
+
+#define FT_MASK			0x003f
+#define FT_DIFF			0x0040
+#define CS2FT(cs)		(((cs) & FT_MASK) + FT_DIFF)
+#define FT2CS(ft)		(((ft) - FT_DIFF) & FT_MASK)
+
+#define CHARSET_MASK		(IRR_MASK | TYPE_MASK | FT_MASK)
+#define CS2CHARSET(cs)		((cs) & CHARSET_MASK)
+#define ISASCII(cs)		(CS2CHARSET(cs) == ASCII)
+
+#define ASCII			(TYPE_94_CHARSET | FT2CS('B'))
+#if ISO
+#define JISX0201KANA		(TYPE_94_CHARSET | FT2CS('I'))
+#define JISX0201ROMAN		(TYPE_94_CHARSET | FT2CS('J'))
+#define LATIN1			(TYPE_96_CHARSET | FT2CS('A'))
+#define LATIN2			(TYPE_96_CHARSET | FT2CS('B'))
+#define LATIN3			(TYPE_96_CHARSET | FT2CS('C'))
+#define LATIN4			(TYPE_96_CHARSET | FT2CS('D'))
+#define GREEK			(TYPE_96_CHARSET | FT2CS('F'))
+#define ARABIC			(TYPE_96_CHARSET | FT2CS('G'))
+#define HEBREW			(TYPE_96_CHARSET | FT2CS('H'))
+#define CYRILLIC		(TYPE_96_CHARSET | FT2CS('L'))
+#define LATIN5			(TYPE_96_CHARSET | FT2CS('M'))
+#define JISX0208_78KANJI	(TYPE_94N_CHARSET | FT2CS('@'))
+#define GB2312			(TYPE_94N_CHARSET | FT2CS('A'))
+#define JISX0208KANJI		(TYPE_94N_CHARSET | FT2CS('B'))
+#define JISX0208_90KANJI	(IRR2CS(1) | TYPE_94N_CHARSET | FT2CS('B'))
+#define KSC5601			(TYPE_94N_CHARSET | FT2CS('C'))
+#define JISX0212KANJISUP	(TYPE_94N_CHARSET | FT2CS('D'))
+
+#if JAPANESE
+/*
+ * Special number for Japanese code set.  Only input_set use following with
+ * above definitions.
+ */
+#define SJIS			(IRR2CS(1) | TYPE_94N_CHARSET | FT_MASK)
+#define UJIS			(IRR2CS(2) | TYPE_94N_CHARSET | FT_MASK)
+#endif
+#endif
+
+
+/*
+ * Definition of code sets.  The code set is not character set.
+ * It is only means of code, and we use these value when we
+ * decide what input data are.
+ */
+typedef enum {
+	/* code sets for left, right and output plane */
+	noconv,		/* A code set which doesn't need converting */
+	/* code sets for left and output plane */
+	jis,		/* JIS means a sub set of iso2022 */
+	iso7,		/* A code set which is extented by iso2022 */
+	/* code sets for only right plane */
+	none,		/* No code set */
+	japanese,	/* Both of UJIS and SJIS */
+	/* code sets for right and output plane */
+	ujis,		/* Japanese code set named UJIS */
+	sjis,		/* Japanese code set named SJIS */
+	iso8,		/* A code set which is extented by iso2022 */
+} CODESET;
+
+
+typedef struct multibuf MULBUF;
+
+
 
 #define	CONTROL(c)	((c)&037)
 #define	ESC		CONTROL('[')
Index: less/less.hlp
diff -u less/less.hlp:1.1.1.8 less/less.hlp:1.10
--- less/less.hlp:1.1.1.8	Sun Dec  1 05:41:21 1996
+++ less/less.hlp	Fri Jan 17 12:21:16 1997
@@ -70,6 +70,7 @@
   :p                *  Examine the (_N-th) previous file from the command line.
   :x                *  Examine the first (or _N-th) file from the command line.
   =  ^G  :f            Print current file name.
+  @                    Rotate the code recognition method of the current file.
   V                    Print version number of "less".
 
   -_<_f_l_a_g_>              Toggle a command line option [see OPTIONS below].
@@ -120,6 +121,7 @@
   -X            Don't use termcap init/deinit strings.
   -y [_N]        Forward scroll limit.
   -z [_N]        Set size of window.
+  -Z            Give priority to the SJIS over the UJIS if you use Japanese.
 
 
         ---------------------------------------------------
Index: less/less.nro
diff -u less/less.nro:1.1.1.11 less/less.nro:1.33
--- less/less.nro:1.1.1.11	Sun Dec  1 05:41:13 1996
+++ less/less.nro	Fri Jan 17 12:21:17 1997
@@ -10,7 +10,7 @@
 .br
 .B "less --version"
 .br
-.B "less [-[+]aBcCdeEfgGiImMnNqQrsSuUVwX]"
+.B "less [-[+]aBcCdeEfgGiImMnNqQrsSuUVwXZ]"
 .br
 .B "     [-b \fIbufs\fP] [-h \fIlines\fP] [-j \fIline\fP] [-k \fIkeyfile\fP]"
 .br
@@ -287,6 +287,13 @@
 If possible, it also prints the length of the file,
 the number of lines in the file
 and the percent of the file above the last displayed line.
+.IP "@"
+Rotate the code recognition method of the current file.
+Enhanced
+.I less
+has 7 methods for recognition, default (which is chosen
+by JLESSCHARSET environment variable), japanese, ujis, sjis,
+iso8, noconv and none.
 .IP \-
 Followed by one of the command line option letters (see below),
 this will change the setting of that option
@@ -698,6 +705,10 @@
 For example, if the screen is 24 lines, \fI-z-4\fP sets the 
 scrolling window to 20 lines.  If the screen is resized to 40 lines,
 the scrolling window automatically changes to 36 lines.
+.IP -Z
+Causes to give priority to the SJIS over the UJIS if japanese was selected
+as JLESSCHARSET environment variable.  The default is
+to give priority to the UJIS over the SJIS.
 .IP -"
 Changes the filename quoting character.
 This may be necessary if you are trying to name a file
@@ -971,8 +982,16 @@
 .PP
 A "character set" is simply a description of which characters are to
 be considered normal, control, and binary.
-The LESSCHARSET environment variable may be used to select a character set.
-Possible values for LESSCHARSET are:
+The JLESSCHARSET and LESSCHARSET environment variable may be used to select
+a character set.  There is no difference between them in program of
+.I less.
+But some value for it is allowed on only japanized
+.I less
+and it means you should use JLESSCHARSET
+if you want to use one of Japanese character sets.
+Because if you used LESSCHARSET and had used original less,
+it would make error about wrong LESSCHARSET value.
+Possible values for them are:
 .IP ascii
 The default character set.
 BS, TAB, NL, CR, and formfeed are control characters,
@@ -989,6 +1008,151 @@
 .IP next
 Selects a character set appropriate for NeXT computers.
 .PP
+And possible values for JLESSCHARSET are:
+.IP iso7
+Multi character sets with the ISO 2022 code extension techniques
+in 7 bits are assumed.
+Characters with values between 128 and 255 are treated as binary.
+The level of implementation of
+.I Less
+is level 3 of IOS 2022.
+.IP iso8
+Multi character sets with the ISO 2022 code extension techniques
+in 8 bits are assumed.
+The level of implementation of
+.I Less
+is level 3 of IOS 2022.
+.IP jis
+Only Japanese character sets with the ISO 2022 code extension
+techniques in 7 bits are assumed.
+.IP ujis
+If characters has values between 32 and 127,
+the ASCII character set are assumed.
+If characters has values between 162 and 254,
+the JISX 0208 character set,
+a right half of the JISX 0201 character set and
+the JISX 0212 character set with the UJIS coding are assumed.
+Otherwise, characters are treated as binary.
+.IP euc
+Same as ujis.
+.IP sjis
+If characters has values between 32 and 127,
+the ASCII character set are assumed.
+If characters has values between 128 and 252,
+the JISX 0208 character set and
+a right half of the JISX 0201 character set with the UJIS coding are assumed.
+Otherwise, characters are treated as binary.
+.IP japanese
+All Japanese character sets, jis, ujis and sjis, are assumed.  But
+.I less
+output only the jis.
+.PP
+Japanese has several code sets (not character sets).
+Thus
+.I less
+must convert among them to display it correctly.
+Possible values with this conversion for JLESSCHARSET are:
+.IP ujis-iso7
+The ujis and iso7 are assumend.  But
+.I less
+output only the iso7.
+.IP euc-iso7
+Same as ujis-iso7.
+.IP sjis-iso7
+The sjis and iso7 are assumend.  But
+.I less
+output only the iso7.
+.IP ujis-jis
+The ujis and jis are assumend.  But
+.I less
+output only the jis.
+.IP euc-jis
+Same as ujis-jis.
+.IP sjis-jis
+The sjis and jis are assumend.  But
+.I less
+output only the jis.
+.IP jis-ujis
+The jis and ujis are assumend.  But
+.I less
+output only the ujis.
+.IP jis-euc
+Same as jis-ujis.
+.IP jis-sjis
+The jis and sjis are assumend.  But
+.I less
+output only the sjis.
+.IP japanese-iso7
+The japanese and iso7 are assumend.  But
+.I less
+output only the iso7.
+.IP japanese-jis
+The japanese is assumend.  But
+.I less
+output only the jis.
+Same as japanese.
+.IP japanese-ujis
+The japanese is assumend.  But
+.I less
+output only the ujis.
+.IP japanese-euc
+Same as japanese-ujis.
+.IP japanese-sjis
+The japanese is assumend.  But
+.I less
+output only the sjis.
+.IP ujis-sjis
+The ujis is assumend.  But
+.I less
+output only the sjis.
+.IP euc-sjis
+Same as ujis-sjis.
+.IP sjis-ujis
+The sjis is assumend.  But
+.I less
+output only the ujis.
+.IP sjis-euc
+Same as sjis-ujis.
+.PP
+Other way to select a character set is to use the LANG environment variable.
+If it start with "ja_JP" or "japan",
+.I less
+read all Japanese coded characters as some Japanese character set,
+and a rest of the LANG environment variable specify output coding.
+.PP
+The ISO 2022 code extension techniques define
+4 planes for displaying many character sets easy.
+Default setting of planes is selected by
+the JLESSPLANESET environment variable.
+If the JLESSPLANESET vriable is equal to "japanese", "ujis" or "euc",
+.I less
+treat g1 plane as JISX 0208, g2 plane as JISX 0201 right half, g3 plane
+as JISX 0212.  If it is equal to "latin1", "latin2", "latin3", "latin4",
+"greek", "alabic", "hebrew", "cyrillic" or "latin5",
+.I less
+treat g1 plane as one of ISO 8859.
+Otherwise,
+.I less
+try to parse the JLESSPLANESET variable as 
+real escape sequence for setting up, and "\\e" in JLESSPLANESET
+is treated as escape code when parsing.
+.PP
+.I Less
+understand almost all escape sequence about character set
+in the ISO 2022 code extension techniques.  There are many escape sequences
+to select the character set.  On the one hand,
+.I less
+output only 6 escape sequences to select a character
+set: '^[(', '^[-', '^[$(', '^[$-', '^N' and '^O'.
+It means
+.I less
+is terminal friendly.
+.PP
+And there is special "character set" for keyboard inputs.
+The JLESSKEYCHARSET environment variable is used
+for such purpose.  Possible values of it are equal
+to the JLESSCHARSET environment variable.
+.PP
 In special cases, it may be desired to tailor
 .I less
 to use a character set other than the ones definable by LESSCHARSET.
@@ -1093,6 +1257,8 @@
 Usually used at the end of the string, but may appear anywhere.
 .IP "%x"
 Replaced by the name of the next input file in the list.
+.IP "%K"
+Replaced by the name of the last non ASCII character set or code set.
 .PP
 If any item is unknown (for example, the file size if input
 is a pipe), a question mark is printed instead.
@@ -1258,8 +1424,14 @@
 Format for displaying non-printable, non-control characters.
 .IP LESSCHARDEF
 Defines a character set.
-.IP LESSCHARSET
+.IP JLESSCHARSET
 Selects a predefined character set.
+.IP LESSCHARSET
+Selects a predefined character set if JLESSCHARSET is not defined.
+.IP JLESSKEYCHARSET
+Selects a predefined character set for keyboard inputs.
+.IP JLESSPLANESET
+Selects a predefined plane set of the ISO 2022 code extension techniques.
 .IP LESSCLOSE
 Command line to invoke the (optional) input-postprocessor.
 .IP LESSECHO
@@ -1335,4 +1507,8 @@
 Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
 .br
 Comments to: marknu@netcom.com
+.br
+Copyright (c) 1994,1995,1996,1997  Kazushi (Jam) Marukawa, Japanized routines only
+.br
+Comments to: jam@poboxes.com
 
Index: less/lesskey.c
diff -u less/lesskey.c:1.1.1.12 less/lesskey.c:1.15
--- less/lesskey.c:1.1.1.12	Sun Dec  1 05:41:09 1996
+++ less/lesskey.c	Sun Jan 12 18:16:13 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -161,6 +164,9 @@
 	"undo-hilite",		A_UNDO_SEARCH,
 	"version",		A_VERSION,
 	"visual",		A_VISUAL,
+#if JAPANESE
+	"rotate-right",		A_ROT_RCODESET,
+#endif
 	NULL,			0
 };
 
Index: less/lesskey.nro
diff -u less/lesskey.nro:1.1.1.9 less/lesskey.nro:1.12
--- less/lesskey.nro:1.1.1.9	Sun Dec  1 05:41:16 1996
+++ less/lesskey.nro	Sun Jan 12 18:16:14 1997
@@ -177,6 +177,7 @@
 	v		visual 
 	!		shell 
 	+		firstcmd 
+	@		rotate-right 
 	H		help 
 	h		help 
 	V		version 
@@ -297,3 +298,7 @@
 Copyright (c) 1984,1985,1989,1994,1995  Mark Nudelman
 .br
 Comments to: marknu@netcom.com
+.br
+Copyright (c) 1994,1995,1996,1997  Kazushi (Jam) Marukawa, Japanized routines only
+.br
+Comments to: jam@poboxes.com
Index: less/line.c
diff -u less/line.c:1.1.1.8 less/line.c:1.68
--- less/line.c:1.1.1.8	Sat Sep 14 00:35:15 1996
+++ less/line.c	Sat Jan 25 01:17:49 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -40,6 +43,8 @@
 public int cshift;		/* Current left-shift of output line buffer */
 public int hshift;		/* Desired left-shift of output line buffer */
 
+static CHARSET charset[LINEBUF_SIZE];
+				/* Extension of linebuf to hold character set */
 static char attr[LINEBUF_SIZE];	/* Extension of linebuf to hold attributes */
 static int curr;		/* Index into linebuf */
 static int column;		/* Printable length, accounting for
@@ -49,7 +54,9 @@
 static char pendc;
 static POSITION pendpos;
 
+static int pwidth();
 static int do_append();
+static int real_do_append();
 
 extern int bs_mode;
 extern int tabstop;
@@ -63,12 +70,14 @@
 extern int bl_s_width, bl_e_width;
 extern int so_s_width, so_e_width;
 extern int sc_width, sc_height;
+extern IFILE curr_ifile;
 
 /*
  * Rewind the line buffer.
  */
 	public void
-prewind()
+prewind(pos)
+	POSITION pos;
 {
 	curr = 0;
 	column = 0;
@@ -76,6 +85,9 @@
 	overstrike = 0;
 	is_null_line = 0;
 	pendc = '\0';
+#if ISO
+	prewind_multi(get_mulbuf(curr_ifile), pos);
+#endif
 }
 
 /*
@@ -108,7 +120,10 @@
 	n = strlen(&linebuf[curr]);
 	column += n;
 	for (i = 0;  i < n;  i++)
-		attr[curr++] = 0;
+	{
+		charset[curr] = ASCII;
+		attr[curr++] = AT_NORMAL;
+	}
 
 	/*
 	 * Append enough spaces to bring us to the next tab stop.
@@ -120,6 +135,7 @@
 	do
 	{
 		linebuf[curr] = ' ';
+		charset[curr] = ASCII;
 		attr[curr++] = AT_NORMAL;
 		column++;
 	} while (((column + cshift) % tabstop) != 0);
@@ -134,20 +150,48 @@
 	int shift;
 {
 	int i;
+	int j;
+	int exact_shift;		/* exact columns to shift */
+	int exact_length;	/* exact bytes to shift */
 
 	if (shift > column)
 		shift = column;
 	if (shift > curr)
 		shift = curr;
 
-	for (i = 0;  i < curr - shift;  i++)
+	/*
+	 * Calculate exact bytes to shift.
+	 */
+	exact_shift = 0;
+	exact_length = 0;
+	for (j = 0; j < curr && exact_shift < shift; j++)
 	{
-		linebuf[i] = linebuf[i + shift];
-		attr[i] = attr[i + shift];
+		/*
+		 * Use pwidth to compute exact columns.
+		 */
+		exact_shift += pwidth(linebuf[j], charset[j], attr[j]);
+		exact_length++;
+	}
+	while (j < curr && pwidth(linebuf[j], charset[j], attr[j]) == 0)
+	{
+		/*
+		 * Multi bytes character has 0 column information,
+		 * thus we have to skip them.
+		 */
+		exact_length++;
+		j++;
 	}
-	column -= shift;
-	curr -= shift;
-	cshift += shift;
+
+	for (i = 0;  i < curr - exact_length;  i++)
+	{
+		linebuf[i] = linebuf[i + exact_length];
+		charset[i] = charset[i + exact_length];
+		attr[i] = attr[i + exact_length];
+	}
+
+	column -= exact_shift;
+	curr -= exact_length;
+	cshift += exact_shift;
 }
 
 /*
@@ -193,8 +237,9 @@
  * attribute sequence to be inserted, so this must be taken into account.
  */
 	static int
-pwidth(c, a)
+pwidth(c, cs, a)
 	int c;
+	int cs;
 	int a;
 {
 	register int w;
@@ -217,7 +262,11 @@
 	 * Other characters take one space,
 	 * plus the width of any attribute enter/exit sequence.
 	 */
+#if ISO
+	w = mwidth(c, cs);
+#else
 	w = 1;
+#endif
 	if (curr > 0 && attr[curr-1] != a)
 		w += attr_ewidth(attr[curr-1]);
 	if (a && (curr == 0 || attr[curr-1] != a))
@@ -231,16 +280,24 @@
 	static void
 backc()
 {
-	curr--;
-	column -= pwidth(linebuf[curr], attr[curr]);
+	/* remove garbage in the buffer. */
+	if (CSISREST(charset[curr]))
+		charset[curr] = 0;
+	/* delete the previous character. */
+	do
+	{
+		curr--;
+		column -= pwidth(linebuf[curr], charset[curr], attr[curr]);
+	} while (curr > 0 && CSISREST(charset[curr]));
 }
 
 /*
  * Append a character and attribute to the line buffer.
  */
 	static int
-storec(c, a, pos)
+storec(c, cs, a, pos)
 	int c;
+	int cs;
 	int a;
 	POSITION pos;
 {
@@ -253,8 +310,28 @@
 		 * Override the attribute passed in.
 		 */
 		a = AT_STANDOUT;
+#if ISO
+	/*
+	 * All data of multi bytes character has same position.
+	 * However search mark data position and not character position.
+	 * Thus we must check all data position of each character.
+	 */
+	else if (CSISREST(cs))
+	{
+		register int i;
+		for (i = 1; CSISREST(charset[curr - i]); i++)
+			;
+		if (is_hilited(pos - i, pos, 0))
+		{
+			for (i = curr - 1; CSISREST(charset[i]); --i)
+				attr[i] = AT_STANDOUT;
+			attr[i] = AT_STANDOUT;
+			a = AT_STANDOUT;
+		}
+	}
 #endif
-	w = pwidth(c, a);
+#endif
+	w = pwidth(c, cs, a);
 	if (ctldisp > 0 && column + w + attr_ewidth(a) > sc_width)
 		/*
 		 * Won't fit on screen.
@@ -301,6 +378,7 @@
 	/* End of magic cookie handling. */
 
 	linebuf[curr] = c;
+	charset[curr] = cs;
 	attr[curr] = a;
 	column += w;
 	return (0);
@@ -358,15 +436,55 @@
 	int c;
 	POSITION pos;
 {
+#if ISO
+	char *cbuf;
+	CHARSET *csbuf;
+	int i, j;
+
+	buffering_multi(get_mulbuf(curr_ifile), c, &cbuf, &csbuf, &i);
+	j = i;
+	while (--i >= 0)
+	{
+		if (real_do_append(*cbuf++, *csbuf++, pos))
+		{
+			set_bufbytes(get_mulbuf(curr_ifile),
+				     get_bufbytes(get_mulbuf(curr_ifile)) -
+				     (j - (i + 1)));
+			return (1);
+		}
+	}
+	return (0);
+#else
+	return (real_do_append(c, ASCII, pos));
+#endif
+}
+
+	static int
+real_do_append(c, cs, pos)
+	register int c;
+	register CHARSET cs;
+	POSITION pos;
+{
 	register char *s;
 	register int a;
 
-#define	STOREC(c,a) \
-	if (storec((c),(a),pos)) return (1); else curr++
+#define	STOREC(c,cs,a) \
+	if (storec((c),(cs),(a),pos)) return (1); else curr++
 
+	if (CSISWRONG(cs))
+		goto do_control_char;
 	if (overstrike)
 	{
 		/*
+		 * Check about multi '\b' for multi bytes character.
+		 */
+		if (c == '\b')
+			if (linebuf[curr] == '_' && ISASCII(charset[curr]))
+				goto do_bs_char; /* do backc on underline */
+			else
+				return (0);		/* ignore it */
+
+		/*
 		 * Overstrike the character at the current position
 		 * in the line buffer.  This will cause either 
 		 * underline (if a "_" is overstruck), 
@@ -374,28 +492,37 @@
 		 * or just deletion of the character in the buffer.
 		 */
 		overstrike = 0;
-		if ((char)c == linebuf[curr])
-			STOREC(linebuf[curr], AT_BOLD);
-		else if (c == '_')
-			STOREC(linebuf[curr], AT_UNDERLINE);
-		else if (linebuf[curr] == '_')
-			STOREC(c, AT_UNDERLINE);
-		else if (control_char(c))
+		if (ISASCII(cs) && control_char(c))
 			goto do_control_char;
+		if ((char)c == linebuf[curr] && charset[curr] == cs)
+			STOREC(c, cs, AT_BOLD);
+		else if (c == '_' && ISASCII(cs))
+		{
+			STOREC(linebuf[curr], charset[curr], AT_UNDERLINE);
+#if ISO
+			while (CSISREST(charset[curr]))
+				STOREC(linebuf[curr], charset[curr],
+				       AT_UNDERLINE);
+#endif
+		} else if (linebuf[curr] == '_' && ISASCII(charset[curr]))
+			STOREC(c, cs, AT_UNDERLINE);
 		else
-			STOREC(c, AT_NORMAL);
+			STOREC(c, cs, AT_NORMAL);
 	} else if (c == '\b')
 	{
+	do_bs_char:
 		switch (bs_mode)
 		{
 		case BS_NORMAL:
-			STOREC(c, AT_NORMAL);
+			STOREC(c, cs, AT_NORMAL);
 			break;
 		case BS_CONTROL:
 			goto do_control_char;
 		case BS_SPECIAL:
 			if (curr == 0)
-				break;
+				goto do_control_char;
+			if (CSISWRONG(charset[curr - 1]))
+				goto do_control_char;
 			backc();
 			overstrike = 1;
 			break;
@@ -415,11 +542,11 @@
 		case BS_SPECIAL:
 			do
 			{
-				STOREC(' ', AT_NORMAL);
+				STOREC(' ', ASCII, AT_NORMAL);
 			} while (((column + cshift) % tabstop) != 0);
 			break;
 		}
-	} else if (control_char(c))
+	} else if (ISASCII(cs) && control_char(c))
 	{
 	do_control_char:
 		if (ctldisp == 0)
@@ -427,13 +554,14 @@
 			/*
 			 * Output as a normal character.
 			 */
-			STOREC(c, AT_NORMAL);
+			STOREC(c, cs, AT_NORMAL);
 		} else 
 		{
 			/*
 			 * Convert to printable representation.
 			 */
-			s = prchar(c);  
+			s = prchar(c, cs);  
+		binout:
 			a = binattr;
 
 			/*
@@ -445,11 +573,16 @@
 				return (1);
 
 			for ( ;  *s != 0;  s++)
-				STOREC(*s, a);
+				STOREC(*s, WRONG_CHAR | ASCII, a);
 		}
+#if ISO
+	} else if (CSISREST(cs))
+	{
+		STOREC(c, cs, attr[curr - 1]);
+#endif
 	} else
 	{
-		STOREC(c, AT_NORMAL);
+		STOREC(c, cs, AT_NORMAL);
 	}
 
 	return (0);
@@ -459,9 +592,17 @@
  * Terminate the line in the line buffer.
  */
 	public void
-pdone(endline)
+pdone(endline, pos)
 	int endline;
+	POSITION pos;
 {
+#if ISO
+	/*
+	 * Check and flush some buffering characters.
+	 */
+	(void) do_append(-1, pos);
+#endif
+
 	if (pendc && (pendc != '\r' || !endline))
 		/*
 		 * If we had a pending character, put it in the buffer.
@@ -483,11 +624,16 @@
 	if (column < sc_width || !auto_wrap || ignaw || ctldisp == 0)
 	{
 		linebuf[curr] = '\n';
+		charset[curr] = ASCII;
 		attr[curr] = AT_NORMAL;
 		curr++;
 	}
 	linebuf[curr] = '\0';
+	charset[curr] = ASCII;
 	attr[curr] = AT_NORMAL;
+#if ISO
+	pdone_multi(get_mulbuf(curr_ifile), pos);
+#endif
 }
 
 /*
@@ -496,8 +642,9 @@
  * and the character attribute in *ap.
  */
 	public int
-gline(i, ap)
+gline(i, csp, ap)
 	register int i;
+	register int *csp;
 	register int *ap;
 {
 	char *s;
@@ -508,11 +655,13 @@
 		 * If there is no current line, we pretend the line is
 		 * either "~" or "", depending on the "twiddle" flag.
 		 */
+		*csp = ASCII;
 		*ap = AT_NORMAL;
 		s = (twiddle) ? "~\n" : "\n";
 		return (s[i]);
 	}
 
+	*csp = charset[i];
 	*ap = attr[i];
 	return (linebuf[i] & 0377);
 }
Index: less/multi.c
diff -u /dev/null less/multi.c:1.81
--- /dev/null	Sun Mar  9 23:07:35 1997
+++ less/multi.c	Sun Mar  9 22:54:09 1997
@@ -0,0 +1,1552 @@
+/*
+ * Copyright (c) 1994,1996,1997  Kazushi (Jam) Marukawa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice in the documentation and/or other materials provided with 
+ *    the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+/*
+ * Routines to manipulate the "line buffer".
+ * The line buffer holds a line of output as it is being built
+ * in preparation for output to the screen.
+ */
+
+#include "less.h"
+
+#if ISO
+
+#include <stdio.h>
+#include <assert.h>
+
+
+static void rebuffering_multi();
+
+
+#if JAPANESE
+
+/*
+ * Kanji convetion
+ */
+#define ISJIS(c)		(0x21 <= (c) && (c) <= 0x7e)
+#define ISUJIS(c)		(0xa1 <= (c) && (c) <= 0xfe)
+#define ISUJISSS(c)		((c) == 0x8e || (c) == 0x8f)
+#define ISUJISKANJI(c1,c2)	(ISUJIS(c1) && ISUJIS(c2))
+#define ISUJISKANA(c1,c2)	((c1) == 0x8e && ISUJIS(c2))
+#define ISUJISKANA1(c)		((c) == 0x8e)
+#define ISUJISKANJISUP(c1,c2,c3) ((c1) == 0x8f && ISUJIS(c2) && ISUJIS(c3))
+#define ISSJISKANJI(c1,c2)	(((0x81 <= (c1) && (c1) <= 0x9f) || \
+				  (0xe0 <= (c1) && (c1) <= 0xfc)) && \
+				 (0x40 <= (c2) && (c2) <= 0xfc && (c2) != 0x7f))
+#define ISSJISKANA(c)		(0xa1 <= (c) && (c) <= 0xdf)
+#endif
+
+
+/*
+ * Definitions for understanding the escape sequence.
+ * Following escape sequences which be understood by less:
+ *  ESC 2/4 2/8,2/9,2/10,2/11,2/13,2/14,2/15 F
+ *  ESC 2/4 4/0,4/1,4/2
+ *  ESC 2/6 F
+ *  ESC 2/8,2/9,2/10,2/11,2/13,2/14,2/15 F
+ *  ESC 2/12 F		This is used in MULE.  Less support this as input.
+ *  0/14,0/15
+ *  ESC 4/14,4/15,6/14,6/15,7/12,7/13,7/14
+ *  8/14,8/15
+ */
+enum escape_sequence {
+	NOESC,		/* No */	ESC_,		/* ^[ */
+	ESC_2_4,	/* ^[$ */	ESC_2_4_8,	/* ^[$( */
+	ESC_2_4_9,	/* ^[$) */	ESC_2_4_10,	/* ^[$* */
+	ESC_2_4_11,	/* ^[$+ */	ESC_2_4_13,	/* ^[$- */
+	ESC_2_4_14,	/* ^[$. */	ESC_2_4_15,	/* ^[$/ */
+	ESC_2_6,	/* ^[& */	ESC_2_8,	/* ^[( */
+	ESC_2_9,	/* ^[) */	ESC_2_10,	/* ^[* */
+	ESC_2_11,	/* ^[+ */	ESC_2_12,	/* ^[, */
+	ESC_2_13,	/* ^[- */	ESC_2_14,	/* ^[. */
+	ESC_2_15	/* ^[/ */
+};
+
+
+static CODESET def_left = iso7;		/* Default code set of left plane */
+static CODESET def_right = iso8;	/* Default code set of right plane */
+static int def_g0 = ASCII;		/* Default g0 plane status */
+static int def_g1 = ASCII;		/* Default g1 plane status */
+static int def_g2 = ASCII;		/* Default g2 plane status */
+static int def_g3 = ASCII;		/* Default g3 plane status */
+
+static CODESET output = iso8;		/* Code set for output */
+#if JAPANESE
+static CODESET def_priority = ujis;	/* Which code was given priority. */
+#endif
+
+struct multibuf {
+	struct {
+		CODESET left;
+		CODESET right;
+	} io;
+
+	CODESET orig_io_right;
+	int rotation_io_right;
+
+	enum escape_sequence eseq;
+	/*
+	 * Variables to control of escape sequences as output.
+	 */
+	int disp;		/* Current character set */
+	int g0;			/* Current g0 plane status */
+	int g1;			/* Current g1 plane status */
+	int g2;			/* Current g2 plane status */
+	int g3;			/* Current g3 plane status */
+	int *gl;		/* Current gl plane status */
+	int *gr;		/* Current gr plane status */
+	int *sg;		/* Current status of single-shifted plane */
+	int irr;		/* Identify revised registration number */
+#if JAPANESE
+	CODESET priority;	/* Which code was given priority. */
+	int sequence_counter;	/* Special counter for detect UJIS KANJI. */
+#endif
+
+	int icharset;		/* Last non ASCII character set of input */
+
+	/*
+	 * Buffers to keep all bytes of a multi-bytes character until it is
+	 * proved to be right sequence.
+	 */
+	unsigned char multibuf[10]; 	/* Buffer for multi bytes data */
+	int multiindex;			/* Index of multibuf */
+	unsigned char multiint[10]; 	/* Buffer for translate data in */
+					/* multibuf into internal data */
+	CHARSET multics[10];		/* Buffer for CHARSET of translated */
+					/* data */
+	int intindex;			/* Index of multiint */
+	int bufbytes;		/* The length of multi bytes character */
+				/* before converting, and use this to adjust */
+				/* a current position if a character doesn't */
+				/* fit a screen. */
+
+
+	/*
+	 * Last position of inputs.  This is used of continues of reading.
+	 */
+	POSITION last_position;	/* last position */
+};
+
+
+	static int
+code_length(disp)
+	int disp;
+{
+	switch (CS2TYPE(disp))
+	{
+	case TYPE_94_CHARSET:
+	case TYPE_96_CHARSET:
+		return (1);
+	case TYPE_94N_CHARSET:
+	case TYPE_96N_CHARSET:
+		switch (CS2FT(disp) & 0x70)
+		{
+		case 0x30:		/* for private use */
+			return (2);
+		case 0x40:
+		case 0x50:
+			return (2);
+		case 0x60:
+			return (3);
+		case 0x70:
+			return (4);	/* or more bytes */
+		}
+	}
+	assert(0);
+}
+
+/*
+ * Check and normalize all codes which don't need conversion.
+ */
+	static void
+internalize_noconv(mp)
+	MULBUF *mp;
+{
+	if (mp->multiindex != 1)
+	{
+		rebuffering_multi(mp);
+	} else
+	{
+		mp->multiint[mp->intindex] = mp->multibuf[0];
+		mp->multics[mp->intindex] = ASCII;
+		mp->intindex += 1;
+		mp->multiindex = 0;
+	}
+}
+
+	static void
+internalize_wrong(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] = WRONG_CHAR | ASCII;
+	}
+	mp->intindex += mp->multiindex;
+	mp->multiindex = 0;
+}
+
+/*
+ * Check and normalize all ISO codes
+ */
+	static void
+internalize_iso(mp)
+	MULBUF *mp;
+{
+	register int i;
+
+	/*
+	 * Reject DEL and SPACE codes if currently 94 character set is
+	 * selected.
+	 */
+	if (CS2TYPE(mp->disp) == TYPE_94_CHARSET ||
+	    CS2TYPE(mp->disp) == TYPE_94N_CHARSET)
+	{
+		if ((mp->multibuf[mp->multiindex - 1] & 0x7f) == 0x7f)
+		{
+			rebuffering_multi(mp);
+			return;
+		} else if ((mp->multibuf[mp->multiindex - 1] & 0x7f) == 0x20)
+		{
+			internalize_noconv(mp);
+			return;
+		}
+	}
+
+	/*
+	 * Buffering all ISO 2022 coding.  If multi bytes code
+	 * finished, flush them.
+	 */
+	if (mp->multiindex < code_length(mp->disp))
+		return;
+
+	/*
+	 * Normalize all codes
+	 */
+	mp->multiint[mp->intindex] = mp->multibuf[0] & ~0x80;
+	mp->multics[mp->intindex] = mp->disp;
+	for (i = 1; i < mp->multiindex; i++)
+	{
+		mp->multiint[mp->intindex + i] = mp->multibuf[i] & ~0x80;
+		mp->multics[mp->intindex + i] = REST_MASK | mp->disp;
+	}
+	mp->intindex += mp->multiindex;
+	mp->multiindex = 0;
+}
+
+#if JAPANESE
+/*
+ * Check and normalize all UJIS codes
+ */
+	static void
+internalize_ujis(mp)
+	MULBUF *mp;
+{
+	if (mp->multiindex == 1)
+	{
+	} else if (mp->multiindex == 2)
+	{
+		if (ISUJISKANA(mp->multibuf[0], mp->multibuf[1]))
+		{
+			mp->multiint[mp->intindex] = mp->multibuf[1] & ~0x80;
+			mp->multics[mp->intindex] = mp->disp;
+			mp->intindex += 1;
+			mp->multiindex = 0;
+		} else if (ISUJISKANJI(mp->multibuf[0], mp->multibuf[1]))
+		{
+			mp->multiint[mp->intindex] = mp->multibuf[0] & ~0x80;
+			mp->multics[mp->intindex] = mp->disp;
+			mp->multiint[mp->intindex + 1] =
+				mp->multibuf[1] & ~0x80;
+			mp->multics[mp->intindex + 1] = REST_MASK | mp->disp;
+			mp->intindex += 2;
+			mp->multiindex = 0;
+		}
+	} else if (mp->multiindex == 3 &&
+		   ISUJISKANJISUP(mp->multibuf[0], mp->multibuf[1],
+				  mp->multibuf[2]))
+	{
+		if (output == sjis)
+		{
+			rebuffering_multi(mp);
+		} else
+		{
+			mp->multiint[mp->intindex] = mp->multibuf[1] & ~0x80;
+			mp->multics[mp->intindex] = mp->disp;
+			mp->multiint[mp->intindex + 1] =
+				mp->multibuf[2] & ~0x80;
+			mp->multics[mp->intindex + 1] = REST_MASK | mp->disp;
+			mp->intindex += 2;
+			mp->multiindex = 0;
+		}
+	} else
+	{
+		rebuffering_multi(mp);
+	}
+}
+
+/*
+ * Check and normalize all SJIS codes
+ */
+	static void
+internalize_sjis(mp)
+	MULBUF *mp;
+{
+	if (mp->multiindex == 1)
+	{
+		if (!ISSJISKANA(mp->multibuf[0]))
+		{
+			rebuffering_multi(mp);
+		} else
+		{
+			mp->multiint[mp->intindex] = mp->multibuf[0] & ~0x80;
+			mp->multics[mp->intindex] = mp->disp;
+			mp->intindex += 1;
+			mp->multiindex = 0;
+		}
+	} else if (mp->multiindex == 2 &&
+		   ISSJISKANJI(mp->multibuf[0], mp->multibuf[1]))
+	{
+		register int c1, c2;
+		c1 = mp->multibuf[0] - (mp->multibuf[0] >= 0xe0 ? 0x40 : 0);
+		c2 = mp->multibuf[1] - (mp->multibuf[1] >= 0x80 ? 1 : 0);
+		mp->multiint[mp->intindex] =
+			((c1 - 0x81) * 2 + (c2 >= 0x9e ? 1 + 0x21 : 0x21));
+		mp->multics[mp->intindex] = mp->disp;
+		mp->multiint[mp->intindex + 1] =
+			(c2 - (c2 >= 0x9e ? 0x9e - 0x21 : 0x40 - 0x21));
+		mp->multics[mp->intindex + 1] = REST_MASK | mp->disp;
+		mp->intindex += 2;
+		mp->multiindex = 0;
+	} else
+	{
+		rebuffering_multi(mp);
+	}
+}
+#endif
+
+	static void
+internalize(mp)
+	MULBUF *mp;
+{
+	int c = mp->multibuf[mp->multiindex - 1];
+
+	if (mp->multiindex == 1)
+	{
+		if (c <= 0x7f && mp->io.left == noconv ||
+		    c >= 0x80 && mp->io.right == noconv)
+		{
+#if JAPANESE
+			mp->sequence_counter = 0;
+#endif
+			internalize_noconv(mp);
+			return;
+		} else if (c >= 0x80 && mp->io.right == none)
+		{
+#if JAPANESE
+			mp->sequence_counter = 0;
+#endif
+			rebuffering_multi(mp);
+			return;
+		}
+
+		mp->disp = ASCII;
+		if (c < 0x20)
+		{
+#if JAPANESE
+			mp->sequence_counter = 0;
+#endif
+			internalize_noconv(mp);
+			return;
+		} else if (c <= 0x7f ||
+			   mp->io.right == iso8 && (0xa0 <= c && c <= 0xff))
+		{
+#if JAPANESE
+			mp->sequence_counter = 0;
+#endif
+			/*
+			 * Decide current character set.
+			 */
+			mp->disp = (mp->sg ? *mp->sg :
+					(c & 0x80) ? *mp->gr : *mp->gl);
+			/*
+			 * Check disp that fit for output code set.
+			 */
+			if (output == ujis && mp->disp != ASCII &&
+			    mp->disp != JISX0201KANA &&
+			    mp->disp != JISX0201ROMAN &&
+			    mp->disp != JISX0208_78KANJI &&
+			    mp->disp != JISX0208KANJI &&
+			    mp->disp != JISX0208_90KANJI &&
+			    mp->disp != JISX0212KANJISUP)
+			{
+				rebuffering_multi(mp);
+				return;
+			}
+			if (output == sjis && mp->disp != ASCII &&
+			    mp->disp != JISX0201KANA &&
+			    mp->disp != JISX0201ROMAN &&
+			    mp->disp != JISX0208_78KANJI &&
+			    mp->disp != JISX0208KANJI &&
+			    mp->disp != JISX0208_90KANJI)
+			{
+				rebuffering_multi(mp);
+				return;
+			}
+
+			if (mp->disp != ASCII)
+				mp->icharset = mp->disp;
+			internalize_iso(mp);
+			return;
+		} else if (control_char(c))
+		{
+#if JAPANESE
+			mp->sequence_counter = 0;
+#endif
+			internalize_noconv(mp);
+			return;
+		}
+#if JAPANESE
+		if (mp->priority == sjis && ISSJISKANA(c))
+		{
+			if (mp->io.right == japanese)
+			{
+				mp->sequence_counter++;
+				if (mp->sequence_counter % 2 == 1 &&
+				    mp->multibuf[0] != 0xa4)
+					mp->sequence_counter = 0;
+				if (mp->sequence_counter >= 6)
+					/*
+					 * It looks like a sequence of UJIS
+					 * hiragana.  Thus we give priority
+					 * to not sjis.
+					 */
+					mp->priority = ujis;
+			}
+			mp->disp = JISX0201KANA;
+			mp->icharset = SJIS;
+			internalize_sjis(mp);
+			return;
+		} else if (mp->io.right == ujis || mp->io.right == sjis ||
+			   mp->io.right == japanese)
+		{
+			mp->sequence_counter = 0;
+			return;
+		}
+		mp->sequence_counter = 0;
+#endif
+		internalize_wrong(mp);
+		return;
+	}
+
+#if JAPANESE
+	assert(mp->sequence_counter == 0);
+#endif
+	if (c < 0x20)
+	{
+		rebuffering_multi(mp);
+		return;
+	} else if (mp->disp != ASCII &&
+		   (c <= 0x7f ||
+		    mp->io.right == iso8 && 0xa0 <= c && c <= 0xff))
+	{
+		if (mp->disp != (mp->sg ? *mp->sg :
+					(c & 0x80) ? *mp->gr : *mp->gl))
+			rebuffering_multi(mp);
+		else
+			internalize_iso(mp);
+		return;
+	} else if (control_char(c))
+	{
+		rebuffering_multi(mp);
+		return;
+	}
+#if JAPANESE
+	if (mp->multiindex == 2)
+	{
+		if (mp->priority == sjis && ISSJISKANJI(mp->multibuf[0], c))
+		{
+			mp->disp = JISX0208KANJI;
+			mp->icharset = SJIS;
+			internalize_sjis(mp);
+			return;
+		} else if (mp->priority == ujis)
+		{
+			if (ISUJISKANA(mp->multibuf[0], c))
+			{
+				mp->disp = JISX0201KANA;
+				mp->icharset = UJIS;
+				internalize_ujis(mp);
+				return;
+			} else if (ISUJISKANJI(mp->multibuf[0], c))
+			{
+				mp->disp = JISX0208KANJI;
+				mp->icharset = UJIS;
+				internalize_ujis(mp);
+				return;
+			} else if (ISUJISKANJISUP(mp->multibuf[0], c, 0xa1))
+			{
+				return;
+			}
+		}
+
+		if ((mp->io.right == sjis || mp->io.right == japanese) &&
+		    ISSJISKANJI(mp->multibuf[0], c))
+		{
+			mp->disp = JISX0208KANJI;
+			mp->priority = sjis;
+			mp->icharset = SJIS;
+			internalize_sjis(mp);
+			return;
+		} else if ((mp->io.right == ujis || mp->io.right == japanese))
+		{
+			if (ISUJISKANA(mp->multibuf[0], c))
+			{
+				mp->disp = JISX0201KANA;
+				mp->priority = ujis;
+				mp->icharset = UJIS;
+				internalize_ujis(mp);
+				return;
+			} else if (ISUJISKANJI(mp->multibuf[0], c))
+			{
+				mp->disp = JISX0208KANJI;
+				mp->priority = ujis;
+				mp->icharset = UJIS;
+				internalize_ujis(mp);
+				return;
+			} else if (ISUJISKANJISUP(mp->multibuf[0], c, 0xa1))
+			{
+				return;
+			}
+		}
+	} else if (mp->multiindex == 3 &&
+		   (mp->priority == ujis ||
+		    mp->io.right == ujis || mp->io.right == japanese) &&
+		   ISUJISKANJISUP(mp->multibuf[0], mp->multibuf[1], c))
+	{
+		mp->disp = JISX0212KANJISUP;
+		mp->priority = ujis;
+		mp->icharset = UJIS;
+		internalize_ujis(mp);
+		return;
+	}
+#endif
+	rebuffering_multi(mp);
+}
+
+/*
+ * Check routines 
+ */
+	static int
+check_ft(mp, c, type, plane)
+	MULBUF *mp;
+	register int c;
+	int type;
+	int *plane;
+{
+	if (mp->io.left == jis)
+	{
+		if (type == TYPE_94N_CHARSET &&
+		    (c == '@' || c == 'B' || c == 'D') ||
+		    type == TYPE_94_CHARSET &&
+		    (c == 'B' || c == 'I' || c == 'J'))
+		{
+			*plane = (mp->irr ? IRR2CS(mp->irr) : 0) |
+				TYPE2CS(type) | FT2CS(c);
+			mp->irr = 0;
+			mp->eseq = NOESC;
+			return (0);
+		}
+	} else if (0x40 <= c && c <= 0x7e)
+	{
+		*plane = (mp->irr ? IRR2CS(mp->irr) : 0) |
+			TYPE2CS(type) | FT2CS(c);
+		mp->irr = 0;
+		mp->eseq = NOESC;
+		return (0);
+	}
+	return (-1);
+}
+
+	static int
+check_irr(mp, c)
+	MULBUF *mp;
+	register int c;
+{
+	if (0x40 <= c && c <= 0x7e)
+	{
+		mp->irr = CODE2IRR(c);
+		mp->eseq = NOESC;
+		return (0);
+	}
+	return (-1);
+}
+
+	static void
+fix_status_for_escape_sequence(mp)
+	MULBUF *mp;
+{
+	if (mp->eseq == NOESC)
+	{
+		switch (CS2TYPE(mp->sg ? *mp->sg : *mp->gl))
+		{
+		case TYPE_96_CHARSET:
+		case TYPE_96N_CHARSET:
+			change_control_char(0177, 0);
+			break;
+		case TYPE_94_CHARSET:
+		case TYPE_94N_CHARSET:
+			change_control_char(0177, 1);
+			break;
+		}
+		switch (CS2TYPE(mp->sg ? *mp->sg : *mp->gr))
+		{
+		case TYPE_96_CHARSET:
+		case TYPE_96N_CHARSET:
+			change_control_char(0377, 0);
+			break;
+		case TYPE_94_CHARSET:
+		case TYPE_94N_CHARSET:
+			change_control_char(0377, 1);
+			break;
+		}
+	}
+}
+
+	static int
+check_escape_sequence(mp)
+	MULBUF *mp;
+{
+	int c = mp->multibuf[mp->multiindex - 1];
+
+	switch (mp->eseq)
+	{
+	case ESC_:
+		switch (c)
+		{
+		case '$': mp->eseq = ESC_2_4; break;
+		case '&': mp->eseq = ESC_2_6; break;
+		case '(': mp->eseq = ESC_2_8; break;
+		case ')': mp->eseq = ESC_2_9; break;
+		case '*': mp->eseq = ESC_2_10; break;
+		case '+': mp->eseq = ESC_2_11; break;
+		case ',': mp->eseq = ESC_2_12; break;
+		case '-': mp->eseq = ESC_2_13; break;
+		case '.': mp->eseq = ESC_2_14; break;
+		case '/': mp->eseq = ESC_2_15; break;
+		case 'N': mp->sg = &mp->g2; mp->eseq = NOESC; /*SS2*/break;
+		case 'O': mp->sg = &mp->g3; mp->eseq = NOESC; /*SS3*/break;
+		case 'n': mp->gl = &mp->g2; mp->eseq = NOESC; break;
+		case 'o': mp->gl = &mp->g3; mp->eseq = NOESC; break;
+		case '|': if (mp->io.right != iso8) goto wrong;
+			  mp->gr = &mp->g3; mp->eseq = NOESC; break;
+		case '}': if (mp->io.right != iso8) goto wrong;
+			  mp->gr = &mp->g2; mp->eseq = NOESC; break;
+		case '~': if (mp->io.right != iso8) goto wrong;
+			  mp->gr = &mp->g1; mp->eseq = NOESC; break;
+		default:  goto wrong;
+		}
+		break;
+	case ESC_2_4:
+		switch (c)
+		{
+		case '(': mp->eseq = ESC_2_4_8; break;
+		case ')': mp->eseq = ESC_2_4_9; break;
+		case '*': mp->eseq = ESC_2_4_10; break;
+		case '+': mp->eseq = ESC_2_4_11; break;
+		case '-': mp->eseq = ESC_2_4_13; break;
+		case '.': mp->eseq = ESC_2_4_14; break;
+		case '/': mp->eseq = ESC_2_4_15; break;
+		case '@':
+		case 'A':
+		case 'B': if (check_ft(mp, c, TYPE_94N_CHARSET, &mp->g0) == 0)
+				break;
+		default:  goto wrong;
+		}
+		break;
+	case ESC_2_6:
+		if (check_irr(mp, c) == 0)
+			break;
+		goto wrong;
+	case ESC_2_8:
+		if (check_ft(mp, c, TYPE_94_CHARSET, &mp->g0) == 0)
+			break;
+		goto wrong;
+	case ESC_2_9:
+		if (check_ft(mp, c, TYPE_94_CHARSET, &mp->g1) == 0)
+			break;
+		goto wrong;
+	case ESC_2_10:
+		if (check_ft(mp, c, TYPE_94_CHARSET, &mp->g2) == 0)
+			break;
+		goto wrong;
+	case ESC_2_11:
+		if (check_ft(mp, c, TYPE_94_CHARSET, &mp->g3) == 0)
+			break;
+		goto wrong;
+	case ESC_2_12:
+		if (check_ft(mp, c, TYPE_96_CHARSET, &mp->g0) == 0)
+			break;
+		goto wrong;
+	case ESC_2_13:
+		if (check_ft(mp, c, TYPE_96_CHARSET, &mp->g1) == 0)
+			break;
+		goto wrong;
+	case ESC_2_14:
+		if (check_ft(mp, c, TYPE_96_CHARSET, &mp->g2) == 0)
+			break;
+		goto wrong;
+	case ESC_2_15:
+		if (check_ft(mp, c, TYPE_96_CHARSET, &mp->g3) == 0)
+			break;
+		goto wrong;
+	case ESC_2_4_8:
+		if (check_ft(mp, c, TYPE_94N_CHARSET, &mp->g0) == 0)
+			break;
+		goto wrong;
+	case ESC_2_4_9:
+		if (check_ft(mp, c, TYPE_94N_CHARSET, &mp->g1) == 0)
+			break;
+		goto wrong;
+	case ESC_2_4_10:
+		if (check_ft(mp, c, TYPE_94N_CHARSET, &mp->g2) == 0)
+			break;
+		goto wrong;
+	case ESC_2_4_11:
+		if (check_ft(mp, c, TYPE_94N_CHARSET, &mp->g3) == 0)
+			break;
+		goto wrong;
+	case ESC_2_4_13:
+		if (check_ft(mp, c, TYPE_96N_CHARSET, &mp->g1) == 0)
+			break;
+		goto wrong;
+	case ESC_2_4_14:
+		if (check_ft(mp, c, TYPE_96N_CHARSET, &mp->g2) == 0)
+			break;
+		goto wrong;
+	case ESC_2_4_15:
+		if (check_ft(mp, c, TYPE_96N_CHARSET, &mp->g3) == 0)
+			break;
+		goto wrong;
+	case NOESC:
+		/*
+		 * If this sequences are wrong if currently does buffering.
+		 */
+		if (mp->multiindex != 1)
+		{
+			switch (c)
+			{
+			case 0033:
+			case 0016:
+			case 0017:
+			case 0031: goto wrong;
+			case 0216:
+			case 0217: if (mp->io.right == iso8) goto wrong;
+			default:   goto wrongone;
+			}
+		}
+		switch (c)
+		{
+		case 0033: mp->eseq = ESC_; break;
+		case 0016: mp->gl = &mp->g1; mp->eseq = NOESC; break;
+		case 0017: mp->gl = &mp->g0; mp->eseq = NOESC; break;
+		case 0031: mp->sg = &mp->g2; mp->eseq = NOESC; /*SS2*/ break;
+		case 0216: if (mp->io.right != iso8) goto wrongone;
+			   mp->sg = &mp->g2; mp->eseq = NOESC; /*SS2*/ break;
+		case 0217: if (mp->io.right != iso8) goto wrongone;
+			   mp->sg = &mp->g3; mp->eseq = NOESC; /*SS3*/ break;
+		default:   goto wrongone;
+		}
+		break;
+	default:
+		assert(0);
+	}
+	if (mp->eseq == NOESC)
+	{
+		fix_status_for_escape_sequence(mp);
+		mp->multiindex = 0;
+		return (0);
+	}
+	return (0);
+wrong:
+	if (mp->eseq != NOESC)
+	{
+		mp->eseq = NOESC;
+		fix_status_for_escape_sequence(mp);
+	}
+	assert(mp->multiindex != 1);
+	rebuffering_multi(mp);
+	return (0);
+wrongone:
+	assert(mp->eseq == NOESC);
+	return (-1);
+}
+
+struct planeset {
+	char *name;
+	char *planeset;
+} planesets[] = {
+	{ "ascii",		""	},
+	{ "ctext",		"\\e-A"	},
+	{ "latin1",		"\\e-A"	},
+	{ "latin2",		"\\e-B"	},
+	{ "latin3",		"\\e-C"	},
+	{ "latin4",		"\\e-D"	},
+	{ "greek",		"\\e-F"	},
+	{ "alabic",		"\\e-G"	},
+	{ "hebrew",		"\\e-H"	},
+	{ "cyrillic",		"\\e-L"	},
+	{ "latin5",		"\\e-M"	},
+	{ "japanese",		"\\e$)B\\e*I\\e$+D"	},
+	{ "ujis",		"\\e$)B\\e*I\\e$+D"	},
+	{ "euc",		"\\e$)B\\e*I\\e$+D"	},
+	{ NULL }
+};
+
+	public void
+set_planeset(name)
+	register char *name;
+{
+	register struct planeset *p;
+	MULBUF *mp;
+	int ret;
+
+	if (name == NULL)
+		return;
+	for (p = planesets; p->name != NULL; p++)
+		if (strcmp(name, p->name) == 0)
+		{
+			name = p->planeset;
+			break;
+		}
+	mp = new_multi();
+	mp->multiindex = 1;
+	mp->intindex = 0;
+	while (*name)
+	{
+		if (*name == '\\' &&
+		    (*(name + 1) == 'e' || *(name + 1) == 'E'))
+		{
+			mp->multibuf[0] = '\033';
+			ret = check_escape_sequence(mp);
+			name += 2;
+		} else
+		{
+			mp->multibuf[0] = *name++;
+			ret = check_escape_sequence(mp);
+		}
+		if (ret < 0 || mp->intindex > 0)
+		{
+			error("invalid plane set", NULL_PARG);
+			quit(1);
+			/*NOTREACHED*/
+		}
+	}
+	def_g0 = mp->g0;
+	def_g1 = mp->g1;
+	def_g2 = mp->g2;
+	def_g3 = mp->g3;
+	free(mp);
+}
+
+	public void
+init_multi(left, right, out)
+	CODESET left;
+	CODESET right;
+	CODESET out;
+{
+	def_left = left;
+	def_right = right;
+	output = out;
+}
+
+	public void
+init_def_priority(pri)
+	CODESET pri;
+{
+#if JAPANESE
+	assert(pri == sjis || pri == ujis);
+	def_priority = pri;
+#endif
+}
+
+	public void
+init_priority(mp)
+	MULBUF *mp;
+{
+#if JAPANESE
+	if (mp->io.right == sjis)
+		mp->priority = sjis;
+	else if (mp->io.right == ujis)
+		mp->priority = ujis;
+	else if (mp->io.right == japanese)
+		mp->priority = def_priority;
+	else
+		mp->priority = noconv;
+	mp->sequence_counter = 0;
+#endif
+}
+
+	public CODESET
+get_priority(mp)
+	MULBUF *mp;
+{
+#if JAPANESE
+	return (mp->priority);
+#else
+	return (noconv);
+#endif
+}
+
+	public void
+set_priority(mp, pri)
+	MULBUF *mp;
+	CODESET pri;
+{
+#if JAPANESE
+	assert(pri == sjis || pri == ujis || pri == noconv);
+	mp->priority = pri;
+#endif
+}
+
+	public MULBUF *
+new_multi()
+{
+	MULBUF *mp = (MULBUF*) ecalloc(1, sizeof(MULBUF));
+	mp->io.left = def_left;
+	mp->io.right = def_right;
+	mp->orig_io_right = def_right;
+	mp->rotation_io_right = 0;
+	mp->eseq = NOESC;
+	mp->disp = ASCII;
+	mp->g0 = def_g0;
+	mp->g1 = def_g1;
+	mp->g2 = def_g2;
+	mp->g3 = def_g3;
+	mp->gl = &mp->g0;
+	mp->gr = &mp->g1;
+	mp->sg = NULL;
+	mp->irr = 0;
+	init_priority(mp);
+	mp->icharset = ASCII;
+	mp->multiindex = 0;
+	mp->intindex = 0;
+	mp->bufbytes = 0;
+	mp->last_position = -1;
+	return (mp);
+}
+
+/*
+ * Initialize some status for buffering.
+ * If last position is not equal to current position,
+ * initialize all plane status.
+ */
+	public void
+prewind_multi(mp, pos)
+	MULBUF *mp;
+	POSITION pos;
+{
+	mp->multiindex = 0;
+	mp->intindex = 0;
+	mp->bufbytes = 0;
+	if (mp->last_position != pos || pos < 0)
+	{
+		if (mp->eseq != NOESC)
+		{
+			mp->eseq = NOESC;
+			fix_status_for_escape_sequence(mp);
+		}
+		mp->g0 = def_g0;
+		mp->g1 = def_g1;
+		mp->g2 = def_g2;
+		mp->g3 = def_g3;
+		mp->gl = &mp->g0;
+		mp->gr = &mp->g1;
+		mp->sg = NULL;
+		mp->irr = 0;
+#if JAPANESE
+		mp->sequence_counter = 0;
+#endif
+		mp->icharset = ASCII;
+	}
+}
+
+/*
+ * Buffering characters untile get a guarantee that it is right sequence.
+ */
+	static void
+buffering_multi_internal(mp, c)
+	MULBUF *mp;
+	int c;
+{
+	mp->multibuf[mp->multiindex] = c;
+	mp->multiindex++;
+	mp->bufbytes++;
+
+	if (mp->io.left == jis || mp->io.left == iso7 ||
+	    mp->io.right == iso8)
+		if (check_escape_sequence(mp) == 0)
+			return;		/* going process well */
+
+	/* it is not a escape sequence, try to use it as character */
+	internalize(mp);
+}
+
+	static void
+rebuffering_multi(mp)
+	MULBUF *mp;
+{
+	int i;
+	int oldindex;
+
+	/*
+	 * Convert first buffered data as wrong multi bytes data.
+	 */
+	assert(mp->intindex + 1 <= sizeof(mp->multiint));
+	mp->multiint[mp->intindex] = mp->multibuf[0];
+	mp->multics[mp->intindex] = WRONG_CHAR | ASCII;
+	mp->intindex++;
+
+#if JAPANESE
+	/*
+	 * Check SJIS KANA code.
+	 */
+	if ((mp->priority == sjis ||
+	     mp->io.right == sjis || mp->io.right == japanese) && 
+	    ISSJISKANA(mp->multiint[mp->intindex - 1]))
+	{
+		mp->disp = JISX0201KANA;
+		mp->priority = sjis;
+		mp->icharset = SJIS;
+		mp->multics[mp->intindex - 1] = mp->disp;
+	}
+#endif
+
+	/*
+	 * Retry to parse rest of buffered data.
+	 */
+	oldindex = mp->multiindex;
+	mp->bufbytes -= mp->multiindex - 1;
+	mp->multiindex = 0;
+	for (i = 1; i < oldindex; i++)
+		buffering_multi_internal(mp, mp->multibuf[i]);
+}
+
+/*
+ * Buffering characters untile get a guarantee that it is right sequence.
+ */
+	public void
+buffering_multi(mp, c, strbuf, csbuf, length)
+	MULBUF *mp;
+	int c;
+	unsigned char **strbuf;
+	CHARSET **csbuf;
+	unsigned int *length;
+{
+	assert(mp->intindex == 0);
+	mp->bufbytes = mp->multiindex;
+
+	if (c < 0)
+	{
+		/*
+		 * Force to flush out buffered characters.
+		 */
+		if (mp->eseq != NOESC)
+		{
+			mp->eseq = NOESC;
+			fix_status_for_escape_sequence(mp);
+		}
+		if (mp->multiindex)
+			rebuffering_multi(mp);
+	} else
+	{
+		/*
+		 * Put it into buffer and parse it.
+		 */
+		buffering_multi_internal(mp, c);
+	}
+
+	if (mp->sg)
+	{
+		mp->sg = NULL;
+		fix_status_for_escape_sequence(mp);
+	}
+
+	*strbuf = mp->multiint;
+	*csbuf = mp->multics;
+	*length = mp->intindex;
+	mp->intindex = 0;
+}
+
+/*
+ * Parse and discard characters.  This routine is used for chopping line.
+ */
+	public void
+parsing_multi(mp, c)
+	MULBUF *mp;
+	int c;
+{
+	unsigned char *strbuf;
+	CHARSET *csbuf;
+	unsigned int length;
+
+	buffering_multi(mp, c, &strbuf, &csbuf, &length);
+}
+
+/*
+ * Save current position to check it when next prewind_multi().
+ */
+	public void
+pdone_multi(mp, pos)
+	MULBUF *mp;
+	POSITION pos;
+{
+	mp->last_position = pos;
+}
+
+	public void
+set_codesets(mp, left, right)
+	MULBUF *mp;
+	CODESET left;
+	CODESET right;
+{
+	mp->io.left = left;
+	mp->io.right = right;
+}
+
+/*
+ * Return the number of buffering characters.
+ */
+	public int
+get_bufbytes(mp)
+	MULBUF *mp;
+{
+	return (mp->bufbytes);
+}
+
+/*
+ * Adjust the number of buffering characters.
+ */
+	public void
+set_bufbytes(mp, bufbytes)
+	MULBUF *mp;
+	int bufbytes;
+{
+	mp->bufbytes = bufbytes;
+}
+
+/*
+ * Return string representation about multi bytes character
+ * which was buffered.
+ */
+	public char*
+get_icharset_string(mp)
+	MULBUF *mp;
+{
+	static char buf[10];
+
+	switch (mp->icharset)
+	{
+#if JAPANESE
+	/*
+	 * Code set
+	 */
+	case SJIS:		return ("SJIS");
+	case UJIS:		return ("UJIS");
+#endif
+	/*
+	 * Character set
+	 */
+	case ASCII:		return ("ASCII");
+	case JISX0201KANA:	return ("JIS-KANA");
+	case JISX0201ROMAN:	return ("JIS-ROMAN");
+	case LATIN1:		return ("LATIN1");
+	case LATIN2:		return ("LATIN2");
+	case LATIN3:		return ("LATIN3");
+	case LATIN4:		return ("LATIN4");
+	case GREEK:		return ("GREEK");
+	case ARABIC:		return ("ARABIC");
+	case HEBREW:		return ("HEBREW");
+	case CYRILLIC:		return ("CYRILLIC");
+	case LATIN5:		return ("LATIN5");
+	case JISX0208_78KANJI:	return ("JIS-78KANJI");
+	case GB2312:		return ("GB2312");
+	case JISX0208KANJI:	return ("JIS-83KANJI");
+	case JISX0208_90KANJI:	return ("JIS-90KANJI");
+	case KSC5601:		return ("KSC5601");
+	case JISX0212KANJISUP:	return ("JIS-KANJISUP");
+	}
+	switch (CS2TYPE(mp->icharset))
+	{
+	case TYPE_94_CHARSET:
+		strcpy(buf, "94( )");
+		buf[3] = CS2FT(mp->icharset);
+		break;
+	case TYPE_96_CHARSET:
+		strcpy(buf, "96( )");
+		buf[3] = CS2FT(mp->icharset);
+		break;
+	case TYPE_94N_CHARSET:
+		strcpy(buf, "94N( )");
+		buf[4] = CS2FT(mp->icharset);
+		break;
+	case TYPE_96N_CHARSET:
+		strcpy(buf, "96N( )");
+		buf[4] = CS2FT(mp->icharset);
+		break;
+	default:
+		assert(0);
+	}
+	if (CS2IRR(mp->icharset) > 0)
+	{
+		char num[3];
+		sprintf(num, "%d", CS2IRR(mp->icharset));
+		strcat(buf, num);
+	}
+	return (buf);
+}
+
+static int old_output_charset = ASCII;	/* Last displayed character set */
+
+	static unsigned char*
+make_escape_sequence(charset)
+	int charset;
+{
+	static unsigned char p[9];
+	int len;
+
+	p[0] = '\033';
+	len = 1;
+	if ((output == iso7 || output == iso8) && CS2IRR(charset) > 0)
+	{
+		p[len] = '&';
+		p[len + 1] = IRR2CODE(CS2IRR(charset));
+		p[len + 2] = '\033';
+		len += 3;
+	}
+	switch (CS2TYPE(charset))
+	{
+	case TYPE_94_CHARSET:
+		p[len] = '(';
+		p[len + 1] = CS2FT(charset);
+		len += 2;
+		break;
+	case TYPE_94N_CHARSET:
+		switch (CS2FT(charset))
+		{
+		case '@':
+		case 'A':
+		case 'B':
+			p[len] = '$';
+			p[len + 1] = CS2FT(charset);
+			len += 2;
+			break;
+		default:
+			p[len] = '$';
+			p[len + 1] = '(';
+			p[len + 2] = CS2FT(charset);
+			len += 3;
+			break;
+		}
+		break;
+	case TYPE_96_CHARSET:
+		p[len] = '-';
+		p[len + 1] = CS2FT(charset);
+		len += 2;
+		break;
+	case TYPE_96N_CHARSET:
+		p[len] = '$';
+		p[len + 1] = '-';
+		p[len + 2] = CS2FT(charset);
+		len += 3;
+		break;
+	}
+	if (output != iso8)
+	{
+		switch (CS2TYPE(charset))
+		{
+		case TYPE_94_CHARSET:
+		case TYPE_94N_CHARSET:
+			switch (CS2TYPE(old_output_charset))
+			{
+			case TYPE_96_CHARSET:
+			case TYPE_96N_CHARSET:
+				p[len] = '\017';
+				len++;
+			}
+			break;
+		case TYPE_96_CHARSET:
+		case TYPE_96N_CHARSET:
+			switch (CS2TYPE(old_output_charset))
+			{
+			case TYPE_94_CHARSET:
+			case TYPE_94N_CHARSET:
+				p[len] = '\016';
+				len++;
+			}
+			break;
+		}
+	}
+	p[len] = '\0';
+	return (p);
+}
+
+static char cvbuffer[32];
+static int cvindex = 0;
+static char *nullcvbuffer = "";
+
+
+	static char*
+convert_to_iso(c, cs)
+	int c;
+	int cs;
+{
+	register unsigned char *p;
+	static char buffer2[2];
+
+	if (output == iso8 && c != 0 &&
+	    (CS2TYPE(cs) == TYPE_96_CHARSET ||
+	     CS2TYPE(cs) == TYPE_96N_CHARSET))
+		c |= 0x80;
+
+	buffer2[0] = c;
+	buffer2[1] = '\0';
+
+	if (CSISREST(cs))
+	{
+	    return (buffer2);
+	}
+
+	cs = CS2CHARSET(cs);
+
+	if (cs == old_output_charset)
+	{
+		return (buffer2);
+	}
+	else
+	{
+		p = make_escape_sequence(cs);
+		old_output_charset = cs;
+		strcpy(cvbuffer, p);
+		strcat(cvbuffer, buffer2);
+		return (cvbuffer);
+	}
+}
+
+#if JAPANESE
+	static char*
+convert_to_ujis(c, cs)
+	int c;
+	int cs;
+{
+	if (c == 0)
+	{
+		cvindex = 0;
+		return (nullcvbuffer);
+	}
+
+	cvbuffer[cvindex++] = c;
+	cvbuffer[cvindex] = '\0';
+
+	cs = CS2CHARSET(cs);
+
+	if (cs == ASCII || cs == JISX0201ROMAN)
+	{
+		assert(cvindex == 1);
+		cvindex = 0;
+		return (cvbuffer);
+	} else if (cs == JISX0201KANA)
+	{
+		assert(cvindex == 1);
+		cvbuffer[2] = '\0';
+		cvbuffer[1] = cvbuffer[0] | 0x80;
+		cvbuffer[0] = 0x8e;
+		cvindex = 0;
+		return (cvbuffer);
+	} else if (cs == JISX0208_78KANJI || cs == JISX0208KANJI ||
+		   cs == JISX0208_90KANJI)
+	{
+		if (cvindex == 1)
+			return (nullcvbuffer);
+		assert(cvindex == 2);
+		cvbuffer[0] |= 0x80;
+		cvbuffer[1] |= 0x80;
+		cvindex = 0;
+		return (cvbuffer);
+	} else if (cs == JISX0212KANJISUP)
+	{
+		if (cvindex == 1)
+			return (nullcvbuffer);
+		assert(cvindex == 2);
+		cvbuffer[2] = cvbuffer[1] | 0x80;
+		cvbuffer[1] = cvbuffer[0] | 0x80;
+		cvbuffer[0] = 0x8f;
+		cvbuffer[3] = '\0';
+		cvindex = 0;
+		return (cvbuffer);
+	}
+	assert(0);
+	return (nullcvbuffer);
+}
+
+	static char*
+convert_to_sjis(c, cs)
+	int c;
+	int cs;
+{
+	if (c == 0)
+	{
+		cvindex = 0;
+		return (nullcvbuffer);
+	}
+
+	cvbuffer[cvindex++] = c;
+	cvbuffer[cvindex] = '\0';
+
+	cs = CS2CHARSET(cs);
+
+	if (cs == ASCII || cs == JISX0201ROMAN)
+	{
+		assert(cvindex == 1);
+		cvindex = 0;
+		return (cvbuffer);
+	} else if (cs == JISX0201KANA)
+	{
+		assert(cvindex == 1);
+		cvbuffer[0] |= 0x80;
+		cvindex = 0;
+		return (cvbuffer);
+	} else if (cs == JISX0208_78KANJI || cs == JISX0208KANJI ||
+		   cs == JISX0208_90KANJI)
+	{
+		register int c1, c2;
+		if (cvindex == 1)
+			return (nullcvbuffer);
+		assert(cvindex == 2);
+		c1 = ((cvbuffer[0] & ~0x80) - 0x21) / 2 + 0x81;
+		c2 = (cvbuffer[1] & ~0x80) +
+		     ((cvbuffer[0] & 1) ? 0x40 - 0x21 : 0x9e - 0x21);
+		cvbuffer[0] = c1 + (c1 >= 0xa0 ? 0x40 : 0);
+		cvbuffer[1] = c2 + (c2 >= 0x7f ? 1 : 0);
+		cvindex = 0;
+		return (cvbuffer);
+	}
+	assert(0);
+	return (nullcvbuffer);
+}
+#endif
+
+	extern char*
+outchar(c, cs)
+	int c;
+	CHARSET cs;
+{
+	if (c < 0)
+	{
+		c = 0;
+		cs = ASCII;
+	}
+
+	if (output == jis || output == iso7 || output == iso8)
+		return (convert_to_iso(c, cs));
+#if JAPANESE
+	if (output == ujis)
+		return (convert_to_ujis(c, cs));
+	if (output == sjis)
+		return (convert_to_sjis(c, cs));
+#endif
+	cvbuffer[0] = c;
+	cvbuffer[1] = '\0';
+	return (cvbuffer);
+}
+
+	extern char*
+outbuf(p, cs)
+	unsigned char *p;
+	CHARSET cs;
+{
+	static char buffer[1024];
+	char *s;
+	int i = 0;
+
+	while (*p != '\0')
+	{
+		s = outchar(*p++, cs);
+		while (*s != '\0')
+			buffer[i++] = *s++;
+		assert(i < sizeof(buffer));
+	}
+	buffer[i] = '\0';
+	return (buffer);
+}
+
+	extern int
+mwidth(c, cs)
+	int c;
+	CHARSET cs;
+{
+	if (CSISREST(cs))
+		return (0);
+	switch (CS2TYPE(cs))
+	{
+	case TYPE_94_CHARSET:
+	case TYPE_96_CHARSET:
+		return (1);
+	case TYPE_94N_CHARSET:
+	case TYPE_96N_CHARSET:
+		return (2);
+	default:
+		assert(0);
+	}
+}
+
+	public char *
+rotate_right_codeset(mp)
+	MULBUF *mp;
+{
+	char *p;
+
+	mp->rotation_io_right++;
+	mp->rotation_io_right %= 7;
+	switch (mp->rotation_io_right) {
+	case 0: p = "original"; mp->io.right = mp->orig_io_right; break;
+	case 1: p = "japanese"; mp->io.right = japanese; break;
+	case 2: p = "ujis"; mp->io.right = ujis; break;
+	case 3: p = "sjis"; mp->io.right = sjis; break;
+	case 4: p = "iso8"; mp->io.right = iso8; break;
+	case 5: p = "noconv"; mp->io.right = noconv; break;
+	case 6: p = "none"; mp->io.right = none; break;
+	deafult: assert(0); break;
+	}
+	init_priority(mp);
+	return (p);
+}
+#endif
Index: less/optfunc.c
diff -u less/optfunc.c:1.1.1.10 less/optfunc.c:1.14
--- less/optfunc.c:1.1.1.10	Sun Dec  1 05:40:54 1996
+++ less/optfunc.c	Sat Jan 25 07:12:42 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -76,6 +79,9 @@
 extern int so_fg_color, so_bg_color;
 extern int bl_fg_color, bl_bg_color;
 #endif
+#if JAPANESE
+extern int opt_Z_var;
+#endif
 
 
 #if LOGFILE
@@ -360,6 +366,48 @@
 		break;
 	}
 }
+
+#if JAPANESE
+/*
+ * Handler for the -Z option.
+ */
+	/*ARGSUSED*/
+	public void
+opt_Z(type, s)
+	int type;
+	char *s;
+{
+	switch (type)
+	{
+	case INIT:
+		if (opt_Z_var == OPT_ON)
+			init_def_priority(sjis);
+		else if (opt_Z_var == OPT_OFF)
+			init_def_priority(ujis);
+		break;
+	case QUERY:
+		break;
+	case TOGGLE:
+		switch (get_priority(get_mulbuf(curr_ifile))) {
+		case sjis:
+			opt_Z_var = OPT_OFF;
+			break;
+		case ujis:
+			opt_Z_var = OPT_ON;
+			break;
+		case noconv:
+			opt_Z_var = OPT_ONPLUS;	/* we use this to mean error */
+			return;
+		}
+		if (opt_Z_var == OPT_ON)
+			init_def_priority(sjis);
+		else if (opt_Z_var == OPT_OFF)
+			init_def_priority(ujis);
+		init_priority(get_mulbuf(curr_ifile));
+		break;
+	}
+}
+#endif
 
 /*
  * Handler for the -V option.
Index: less/option.c
diff -u less/option.c:1.1.1.6 less/option.c:1.11
--- less/option.c:1.1.1.6	Sun Dec  1 05:40:55 1996
+++ less/option.c	Sun Jan 12 18:16:16 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -408,7 +411,7 @@
 {
 	static char buf[8];
 
-	sprintf(buf, "-%s", prchar(c));
+	sprintf(buf, "-%s", prchar(c, ASCII));
 	return (buf);
 }
 
Index: less/opttbl.c
diff -u less/opttbl.c:1.1.1.10 less/opttbl.c:1.16
--- less/opttbl.c:1.1.1.10	Sun Dec  1 05:40:56 1996
+++ less/opttbl.c	Sat Jan 25 07:12:43 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -61,6 +64,9 @@
 #if HILITE_SEARCH
 public int hilite_search;	/* Highlight matched search patterns? */
 #endif
+#if JAPANESE
+public int opt_Z_var;		/* Initial variable for opt_Z */
+#endif
 
 /*
  * Table of all options and their semantics.
@@ -222,6 +228,18 @@
 		"Scroll window size is %d lines",
 		NULL
 	},
+#if JAPANESE
+#ifdef SJIS_PRE
+#define OPT_Z OPT_ON
+#else
+#define OPT_Z OPT_OFF
+#endif
+	{ 'Z', BOOL|REPAINT, OPT_Z, &opt_Z_var, opt_Z,
+		"Give priority to the UJIS over the SJIS",
+		"Give priority to the SJIS over the UJIS",
+		"Cannot give priority since Japanese was not treated now",
+	},
+#endif
 	{ '"', STRING, 0, NULL, opt_quote,
 		"quotes: ", NULL, NULL
 	},
@@ -248,6 +266,12 @@
 		if (o->ovar != NULL)
 			*(o->ovar) = o->odefault;
 	}
+#if JAPANESE
+	if (opt_Z_var == OPT_ON)
+		init_def_priority(sjis);
+	else if (opt_Z_var == OPT_OFF)
+		init_def_priority(ujis);
+#endif
 }
 
 /*
Index: less/output.c
diff -u less/output.c:1.1.1.9 less/output.c:1.25
--- less/output.c:1.1.1.9	Sun Dec  1 05:40:57 1996
+++ less/output.c	Wed Jan 22 21:12:01 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -53,6 +56,7 @@
 	register int c;
 	register int i;
 	int a;
+	int cs;
 	int curr_attr;
 
 	if (ABORT_SIGS())
@@ -66,7 +70,7 @@
 
 	curr_attr = AT_NORMAL;
 
-	for (i = 0;  (c = gline(i, &a)) != '\0';  i++)
+	for (i = 0;  (c = gline(i, &cs, &a)) != '\0';  i++)
 	{
 		if (a != curr_attr)
 		{
@@ -96,7 +100,11 @@
 		if (c == '\b')
 			putbs();
 		else
+#if ISO
+			putmchr(c, cs);
+#else
 			putchr(c);
+#endif
 	}
 
 	switch (curr_attr)
@@ -208,7 +216,7 @@
  * Output a character.
  */
 	public int
-putchr(c)
+putchr_raw(c)
 	int c;
 {
 	if (need_clr)
@@ -218,11 +226,11 @@
 	}
 #if MSDOS_COMPILER
 	if (c == '\n' && is_tty)
-		putchr('\r');
+		putchr_raw('\r');
 #else
 #ifdef _OSK
 	if (c == '\n' && is_tty)  /* In OS-9, '\n' == 0x0D */
-		putchr(0x0A);
+		putchr_raw(0x0A);
 #endif
 #endif
 	/*
@@ -239,11 +247,85 @@
  * Output a string.
  */
 	public void
-putstr(s)
+putstr_raw(s)
 	register char *s;
 {
 	while (*s != '\0')
-		putchr(*s++);
+		putchr_raw(*s++);
+}
+
+/*
+ * Output a character as ASCII.
+ */
+	public int
+putchr(c)
+	int c;
+{
+#if ISO
+	char *p = outchar(c & 0377, ASCII);
+	putstr_raw(p);
+	return (c);
+#else
+	return (putchr_raw(c));
+#endif
+}
+
+/*
+ * Output a string as ASCII.
+ */
+	public void
+putstr(s)
+	char *s;
+{
+#if ISO
+	char *p = outbuf(s, ASCII);
+	putstr_raw(p);
+#else
+	putstr_raw(s);
+#endif
+}
+
+/*
+ * Output a character which is a part of multi-bytes character.
+ */
+	public int
+putmchr(c, cs)
+	int c;
+	CHARSET cs;
+{
+#if ISO
+	char *p = outchar(c & 0377, cs);
+	putstr_raw(p);
+#else
+	putchr_raw(c);
+#endif
+	return (c);
+}
+
+/*
+ * Output a part of multi-bytes character.
+ */
+	public int
+putmchrs(s, cs)
+	char *s;
+	CHARSET cs;
+{
+	int c = *s;
+	while (*s != '\0')
+		putmchr(*s++, cs);
+	return (c);
+}
+
+/*
+ * Output a string of multi-bytes character.
+ */
+	public void
+putmstr(s, cs)
+	char *s;
+	CHARSET *cs;
+{
+	while (*s != '\0')
+		putmchr(*s++, *cs++);
 }
 
 
Index: less/prompt.c
diff -u less/prompt.c:1.1.1.8 less/prompt.c:1.14
--- less/prompt.c:1.1.1.8	Sun Dec  1 05:40:58 1996
+++ less/prompt.c	Sun Jan 12 18:16:18 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -60,8 +63,8 @@
   "?n?f%f .?m(file %i of %m) ..?e(END) ?x- Next\\: %x.:?pB%pB\\%:byte %bB?s/%s...%t";
 static constant char M_proto[] =
   "?f%f .?n?m(file %i of %m) ..?ltline %lt?L/%L. :byte %bB?s/%s. .?e(END) ?x- Next\\: %x.:?pB%pB\\%..%t";
-static constant char e_proto[] =
-  "?f%f .?m(file %i of %m) .?ltline %lt?L/%L. .byte %bB?s/%s. ?e(END) :?pB%pB\\%..%t";
+static char e_proto[] =
+  "?f%f .?m(file %i of %m) .?ltline %lt?L/%L. .byte %bB?s/%s. ?e(END) :?pB%pB\\%.. code %K%t";
 static constant char h_proto[] =
   "HELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done";
 
@@ -282,6 +285,13 @@
 			free(s);
 		} else
 			ap_quest();
+		break;
+	case 'K':	/* Character set or code set of last non ASCII char. */
+#if ISO
+		ap_str(get_icharset_string(get_mulbuf(curr_ifile)));
+#else
+		ap_str("");
+#endif
 		break;
 	}
 }
Index: less/search.c
diff -u less/search.c:1.1.1.12 less/search.c:1.26
--- less/search.c:1.1.1.12	Sun Dec  1 05:40:59 1996
+++ less/search.c	Tue Jan 21 22:51:42 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -55,6 +58,10 @@
 #if HAVE_V8_REGCOMP
 #include "regexp.h"
 #endif
+#ifndef UJIS_REGEXP
+#define UJIS_REGEXP 0
+#endif
+
 
 static int match();
 
@@ -65,6 +72,7 @@
 extern int sc_height;
 extern int jump_sline;
 extern int bs_mode;
+extern IFILE curr_ifile;
 #if HILITE_SEARCH
 extern int hilite_search;
 extern int screen_trashed;
@@ -102,18 +110,108 @@
 #endif
 
 static int is_caseless;
+static int is_nascii_pattern;
 static int is_ucase_pattern;
 static int last_search_type;
 static char *last_pattern = NULL;
 
+#if ISO
+/*
+ * Normalize text.  Add quote some non ASCII characters which are
+ * mean that special in regexp.
+ */
+	static char *
+normalize_text(src, cs, search_type)
+	char *src;
+	CHARSET *cs;
+	int search_type;
+{
+	char *odst = (char *) ecalloc(strlen(src) * 2, sizeof(char));
+	register char *dst = odst;
+
+	while (*src != '\0')
+	{
+#if !NO_REGEX && ISO
+#if UJIS_REGEXP
+		switch (CS2CHARSET(*cs++)) {
+		case JISX0208_78KANJI:
+		case JISX0208KANJI:
+		case JISX0208_90KANJI:
+			*dst++ = *src++ | 0x80;
+			break;
+		default:
+			*dst++ = *src++;
+			break;
+		}
+#else
+		if (!ISASCII(*cs++) && !(search_type & SRCH_NO_REGEX))
+		{
+			switch (*src) {
+			/* Basic Regular Expressions */
+			case '[':
+			case ']':
+			case '.':
+			case '*':
+			case '\\':
+			case '^':
+			case '$':
+#if HAVE_POSIX_REGCOMP && defined(REG_EXTENDED)
+			/* Extended Regular Expressions */
+			case '+':
+			case '?':
+			case '|':
+			case '(':
+			case ')':
+			case '{':
+			case '}':
+#endif
+#if HAVE_RE_COMP
+			/* No Extended Regular Expressions */
+#endif
+#if HAVE_REGCMP
+			/* Extended Regular Expressions */
+			case '+':
+			case '(':
+			case ')':
+			case '{':
+			case '}':
+#endif
+#if HAVE_V8_REGCOMP
+			/* Extended Regular Expressions */
+			case '+':
+			case '?':
+			case '|':
+			case '(':
+			case ')':
+#endif
+				*dst++ = '\\';
+				/* fall through */
+			default:
+				*dst++ = *src++;
+				break;
+			}
+		} else
+			*dst++ = *src++;
+#endif
+#else
+		*dst++ = *src++;
+#endif
+	}
+	*dst = '\0';
+	return (odst);
+}
+#endif
+
 /*
  * Convert text.  Perform one or more of these transformations:
  */
 #define	CVT_TO_LC	01	/* Convert upper-case to lower-case */
 #define	CVT_BS		02	/* Do backspace processing */
+#define	CVT_TO_INT	04	/* Convert all multi bytes characters into */
+				/* internal form */
 
 	static void
-cvt_text(odst, osrc, ops)
+cvt_text_ascii(odst, osrc, ops)
 	char *odst;
 	char *osrc;
 	int ops;
@@ -132,21 +230,135 @@
 		else 
 			/* Just copy. */
 			*dst = *src;
+ 	}
+	*dst = '\0';
+}
+
+	static void
+cvt_text(odst, dstcs, osrc, srccs, ops)
+	char *odst;
+	CHARSET *dstcs;
+	char *osrc;
+	CHARSET *srccs;
+	int ops;
+{
+	register char *dst;
+	register char *src;
+	int bufcount;
+	char *cbuf;
+	CHARSET *csbuf;
+
+	if (!(ops & CVT_TO_INT) && srccs == NULL || !ISO)
+	{
+		cvt_text_ascii(odst, osrc, ops);
+		if (dstcs)
+			while (*odst++ != '\0')
+				*dstcs++ = ASCII;
+		return;
+	}
+
+#if ISO
+	if (ops & CVT_TO_INT)
+		prewind_multi(get_mulbuf(curr_ifile), ch_tell());
+
+	for (src = osrc, dst = odst;  *src != '\0';
+	     src++, dst++, srccs && srccs++, dstcs && dstcs++)
+	{
+		if ((ops & CVT_TO_INT) && srccs == NULL)
+		{
+			/* make charset */
+			buffering_multi(get_mulbuf(curr_ifile),
+					(unsigned char) *src,
+					&cbuf, &csbuf, &bufcount);
+			if (bufcount == 0)
+			{
+				*dst = '\1';
+				if (dstcs)
+					*dstcs = ASCII;
+				continue;
+			}
+		} else
+		{
+			static CHARSET dummy_cs[] = { ASCII };
+			bufcount = 1;
+			cbuf = src;
+			csbuf = srccs ? srccs : dummy_cs;
+		}
+
+		while (--bufcount >= 0)
+		{
+#if UJIS_REGEXP
+			if (!ISASCII(*csbuf))
+				*cbuf |= 0x80;
+#endif
+			if ((ops & CVT_TO_LC) && ISASCII(*csbuf) &&
+			    isupper((unsigned char) *cbuf))
+			{
+				/* Convert uppercase to lowercase. */
+				dst[-bufcount] = tolower((unsigned char) *cbuf);
+				if (dstcs)
+					dstcs[-bufcount] = *csbuf;
+			} else if ((ops & CVT_BS) &&
+				   *cbuf == '\b' && dst > odst)
+			{
+				/* Delete BS and preceding char. */
+				if (bufcount == 0)
+				{
+					dst -= 2;
+					if (dstcs)
+						dstcs -= 2;
+				} else
+				{
+					dst -= 1;
+					if (dstcs)
+						dstcs -= 2;
+				}
+			} else 
+			{
+				/* Just copy. */
+				dst[-bufcount] = *cbuf;
+				if (dstcs)
+					dstcs[-bufcount] = *csbuf;
+			}
+			cbuf++;
+			csbuf++;
+		}
 	}
 	*dst = '\0';
+
+	if (ops & CVT_TO_INT)
+		pdone_multi(get_mulbuf(curr_ifile), ch_tell());
+#endif
 }
 
 /*
  * Are there any uppercase letters in this string?
  */
 	static int
-is_ucase(s)
+is_ucase(s, cs)
 	char *s;
+	CHARSET *cs;
 {
 	register char *p;
 
-	for (p = s;  *p != '\0';  p++)
-		if (isupper((unsigned char) *p))
+	for (p = s;  *p != '\0';  p++, cs++)
+		if (ISASCII(*cs) && isupper((unsigned char) *p))
+			return (1);
+	return (0);
+}
+
+/*
+ * Are there any character which is not ASCII?
+ */
+	static int
+is_nascii(s, cs)
+	char *s;
+	CHARSET *cs;
+{
+	register char *p;
+
+	for (p = s;  *p != '\0';  p++, cs++)
+		if (!ISASCII(*cs))
 			return (1);
 	return (0);
 }
@@ -548,8 +760,9 @@
 			 * forward by 2 relative to the processed line
 			 * which was searched in hilite_line.
 			 */
-			npos += 2;
-			line += 2;
+			opos--;
+			npos++;
+			line++;
 		}
 	}
 }
@@ -765,6 +978,9 @@
 	int line_match;
 	POSITION linepos, oldpos;
 
+	static CHARSET *charset = NULL;
+	static int charset_len = 0;
+
 	linenum = find_linenum(pos);
 	oldpos = pos;
 	for (;;)
@@ -842,14 +1058,35 @@
 		 * If it's a caseless search, convert the line to lowercase.
 		 * If we're doing backspace processing, delete backspaces.
 		 */
-		if (is_caseless || bs_mode == BS_SPECIAL)
+		if (is_caseless || bs_mode == BS_SPECIAL || is_nascii_pattern)
 		{
 			int ops = 0;
+			int len;
+
 			if (is_caseless) 
 				ops |= CVT_TO_LC;
 			if (bs_mode == BS_SPECIAL)
 				ops |= CVT_BS;
-			cvt_text(line, line, ops);
+			if (is_nascii_pattern) 
+				ops |= CVT_TO_INT;
+
+			cvt_text(line, NULL, line, NULL, ops);
+#if 0
+			/* Currently we can make charset like following, */
+			/* but there is no regexp routine which understand */
+			/* it.  Thus we don't make it. */
+			len = (strlen(line) + 1023) / 1024 * 1024;
+			if (len > charset_len)
+			{
+				charset_len = len;
+				if (charset)
+					free(charset);
+				charset = (CHARSET *)
+					ecalloc(len, sizeof(CHARSET));
+			}
+
+			cvt_text(line, charset, line, NULL, ops);
+#endif
 		}
 
 		/*
@@ -911,9 +1148,10 @@
  * if less than n matches are found in this file.
  */
 	public int
-search(search_type, pattern, n)
+search(search_type, pattern, charset, n)
 	int search_type;
 	char *pattern;
+	CHARSET *charset;
 	int n;
 {
 	POSITION pos;
@@ -960,11 +1198,18 @@
 		/*
 		 * Compile the pattern.
 		 */
-		ucase = is_ucase(pattern);
+		ucase = is_ucase(pattern, charset);
+		is_nascii_pattern = is_nascii(pattern, charset);
 		if (caseless == OPT_ONPLUS)
-			cvt_text(pattern, pattern, CVT_TO_LC);
+			cvt_text(pattern, NULL, pattern, charset, CVT_TO_LC);
+#if ISO
+		pattern = normalize_text(pattern, charset, search_type);
+#endif
 		if (compile_pattern(pattern, search_type) < 0)
 			return (-1);
+#if ISO
+		free(pattern);
+#endif
 		/*
 		 * Ignore case if -I is set OR
 		 * -i is set AND the pattern is all lowercase.
Index: less/version.c
diff -u less/version.c:1.1.1.13 less/version.c:1.48
--- less/version.c:1.1.1.13	Sun Dec  1 05:41:02 1996
+++ less/version.c	Sun Mar  9 22:59:21 1997
@@ -2,6 +2,9 @@
  * Copyright (c) 1984,1985,1989,1994,1995,1996  Mark Nudelman
  * All rights reserved.
  *
+ * Copyright (c) 1997  Kazushi (Jam) Marukawa
+ * All rights of japanized routines reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -565,6 +568,34 @@
 		Add LESSMETACHARS, LESSMETAESCAPE.
 v330   10/21/96	Minor fixes.
 		Posted to Web page.
+-----------------------------------------------------------------
+   Other patches by jam@poboxes.com
+kanji  7/18/91	Support Kanji as one of the charset.
+zcat   4/21/94	Add easy uncompressing feature by invoking zcat.
+iso    8/11/94	Support ISO2022 encoding and special Japanese KANJI encodings
+		as one of the charset.
+iso2   9/21/94	Fix a variety of bugs of iso patch.
+iso2p1 10/22/94	Fix a variety of bugs.
+iso202 12/1/96  Chang to fit less version 330 and fixed some bugs.
+iso203 12/5/96  Fix line termination bug.
+iso204 12/15/96 Change all internal data structure.  Add CHARSET and
+		"CHARSET charset[]" in line.c.
+iso205 12/16/96 Add CODESET and structure of CODESET in multi.c and
+		made buffering_multi() recursively.
+iso206 12/21/96 Support multi bytes characters in command buffer.
+		And add rotate-right command for rotating the code set in the
+		right plane.
+iso207 12/22/96 Support search of multi bytes characters.
+iso208 12/23/96 Encapsulate multi bytes buffering data.  And change
+		the structure of CHARSET.
+iso209 1/5/97   Fix bugs of KANJI search and sophisticate SJIS routines.
+iso210 1/12/97  Fix BS handling and add priority argument of KANJI code.
+iso211 1/19/97  Add and change comments.
+iso212 1/21/97  Fix a bug about UJIS_REGEXP search.
+iso213 1/22/97  Fix a bug about 8-bit error message.
+iso214 1/24/97  Fix a bug about handling of BS character.
+iso215 1/25/97  Change to invert -Z option if SJIS_PRE is defined
+iso216 3/9/97   Fix a bug about buffering of KANJI supplement.
 */
 
-char version[] = "330";
+char version[] = "330+iso216";
