From kagotani@cs.titech.ac.jp Wed Nov 28 19:29:30 1990
Path: toumon!wnoc-tyo-news!titcca!cs.titech!koudai!kagotani
From: kagotani@cs.titech.ac.jp (Hiroto Kagotani)
Newsgroups: fj.sources
Subject: pTeX for JIS encoded file
Message-ID: <KAGOTANI.90Nov6154328@sami.cs.titech.ac.jp>
Date: 6 Nov 90 06:43:28 GMT
Sender: news@cs.titech.ac.jp
Distribution: fj
Organization: Tokyo Institute of Tech., Dept. of Computer Science, Japan
Lines: 201

$@dFC+$G$9!#(J

ASCII $@HG$N(J pTeX $@$K(J JIS $@%3!<%I%U%!%$%k$r$/$o$;$k$?$a$N%Q%C%A$G$9!#(J
  % cd ptex/ptex; patch -p <$@$3$N%U%!%$%k(J
$@$H$7!"I,MW$K1~$8$F(J site.h $@$G(J #define JIS $@$r$7$F2<$5$$!#(J
--
$@;d$K1lAp$N1l$r5[$o$;$J$$$G2<$5$$!#;d$K1lAp$N=-$$$r$D$1$J$$$G2<$5$$!#(J
                                        $@dFC+M5?M(J ($@O6!?dF$NFq$7$$J}(J)
                                        kagotani@cs.titech.ac.jp

diff -rc ../ptex.orig/ctex/Makefile ./ctex/Makefile
*** ../ptex.orig/ctex/Makefile	Tue Sep 18 12:00:06 1990
--- ./ctex/Makefile	Tue Nov  6 13:55:19 1990
***************
*** 144,149 ****
--- 144,155 ----
  clean:
  		$(RM) -f *tex*.o *extra.o code.o *.fmt core
  
+ jplain.fmt:	initex
+ 		./initex 'jplain \dump'
+ 
+ jlplain.fmt:	initex
+ 		./initex 'jlplain \dump'
+ 
  plain.fmt:	initex
  		./initex 'plain \dump'
  
diff -rc ../ptex.orig/ctex/extra.c ./ctex/extra.c
*** ../ptex.orig/ctex/extra.c	Tue Sep 18 12:00:07 1990
--- ./ctex/extra.c	Tue Nov  6 13:55:20 1990
***************
*** 394,399 ****
--- 394,440 ----
  #ifdef	BSD
      if (f == stdin) clearerr(stdin);
  #endif
+ #ifdef	JIS
+     while ( last < bufsize-3 && ((i = getc(f)) != EOF) && i != '\n') {
+ 	static int kmode = 0;
+ 	if (i == '\033') {      /* ESC */
+ 	    if ((i = getc(f)) == '(') {
+ 		i = getc(f);
+ 		if (i == 'J' || i == 'B') {
+ 		    kmode = 0;
+ 		} else {
+ 		    buffer[last++] = '\033';
+ 		    buffer[last++] = '(';
+ 		    buffer[last++] = i;
+ 		}
+ 	    } else if (i == '$') {
+ 		i = getc(f);
+ 		if (i == '@' || i == 'B') {
+ 		    kmode = 1;
+ 		} else {
+ 		    buffer[last++] = '\033';
+ 		    buffer[last++] = '$';
+ 		    buffer[last++] = i;
+ 		}
+ 	    } else {
+ 		buffer[last++] = '\033';
+ 		buffer[last++] = i;
+ 	    }
+ 	} else {      /* rather than ESC */
+ 	    if (kmode == 0) {
+ 		buffer[last++] = i;
+ 	    } else {
+ # ifdef	EUC
+ 		i = JIStoEUC(i << 8 | getc(f));
+ # else
+ 		i = JIStoSJIS(i << 8 | getc(f));
+ # endif
+ 		buffer[last++] = (i >> 8) & 0xff;
+ 		buffer[last++] = i & 0xff;
+ 	    }
+ 	}
+     }
+ #else	/* !JIS */
      while ( last < bufsize && ((i = getc(f)) != EOF) && i != '\n') {
  #ifdef	NONASCII
  	buffer[last++] = i;
***************
*** 405,410 ****
--- 446,452 ----
  # endif
  #endif
      }
+ #endif	/* !JIS */
      if (i == EOF && last == first)
  	return(false);
      if (i != EOF && i != '\n') {
diff -rc ../ptex.orig/ctex/jextra.c ./ctex/jextra.c
*** ../ptex.orig/ctex/jextra.c	Fri Sep 21 12:28:16 1990
--- ./ctex/jextra.c	Tue Nov  6 14:20:21 1990
***************
*** 4,9 ****
--- 4,10 ----
   */
  
  #define	EXTERN	extern
+ #define	JEXTRA
  #include "texd.h"
  
  void
***************
*** 104,106 ****
--- 105,151 ----
  }
  
  #endif /* BUGCOMPATIBLE */
+ 
+ #ifdef JIS
+ #include <sys/param.h>
+ void
+ putc2(c, fp)
+ ASCIIcode c;
+ FILE *fp;
+ {
+ 	static int kanji[NOFILE];
+ 	static ASCIIcode c1[NOFILE];
+ 	KANJIcode jc;
+ 	register fd;
+ 
+ 	fd = fileno(fp);
+ 
+ 	if (kanji[fd] == 1) {
+ 		jc = (c1[fd] << 8) | c;
+ # ifdef EUC
+ 		jc = EUCtoJIS(jc);
+ # else
+ 		jc = SJIStoJIS(jc);
+ # endif
+ 		(void) putc(jc >> 8, fp);
+ 		(void) putc(jc & 0xff, fp);
+ 		kanji[fd] = 2;
+ 	} else if (iskanji(c)) {
+ 		if (kanji[fd] == 0) {
+ 			(void) putc('\033', fp);
+ 			(void) putc('$', fp);
+ 			(void) putc('B', fp);
+ 		}
+ 		c1[fd] = c;
+ 		kanji[fd] = 1;
+ 	} else {
+ 		if (kanji[fd] == 2) {
+ 			(void) putc('\033', fp);
+ 			(void) putc('(', fp);
+ 			(void) putc('B', fp);
+ 			kanji[fd] = 0;
+ 		}
+ 		(void) putc(c, fp);
+ 	}
+ }
+ #endif /* JIS */
diff -rc ../ptex.orig/ctex/tex.h ./ctex/tex.h
*** ../ptex.orig/ctex/tex.h	Tue Sep 18 12:00:10 1990
--- ./ctex/tex.h	Tue Nov  6 13:55:20 1990
***************
*** 105,107 ****
--- 105,112 ----
  #define	amakenamestring(f)	makenamestring()
  #define	bmakenamestring(f)	makenamestring()
  #define	wmakenamestring(f)	makenamestring()
+ 
+ #if defined(JIS) && !defined(JEXTRA)
+ # undef		putc
+ # define	putc(c,fp)	putc2(c,fp)
+ #endif
diff -rc ../ptex.orig/site.h ./site.h
*** ../ptex.orig/site.h	Wed Sep 19 18:28:29 1990
--- ./site.h	Tue Nov  6 15:04:21 1990
***************
*** 40,50 ****
  
  /*
   * Our japanese character coding
!  *     SJIS or EUC or JIS
   */
  #define	KANJI
  #define	SJIS
  #undef	EUC
  
  /* Define if we're running under System V */
  #undef	SYSV
--- 40,55 ----
  
  /*
   * Our japanese character coding
!  *     SJIS or EUC
   */
  #define	KANJI
  #define	SJIS
  #undef	EUC
+ /*
+  * You can define JIS independently of SJIS or EUC. It allows you
+  * to feed JIS encoded text files and creates JIS encoded log files.
+  */
+ #undef	JIS
  
  /* Define if we're running under System V */
  #undef	SYSV

