Subject: pTeX for JIS encoded file

From: [email-masked] (Hiroto Kagotani)
Date: 6 Nov 90 06:43:28 GMT

籠谷です。

ASCII 版の pTeX に JIS コードファイルをくわせるためのパッチです。
  % cd ptex/ptex; patch -p <このファイル
とし、必要に応じて site.h で #define JIS をして下さい。
--
私に煙草の煙を吸わせないで下さい。私に煙草の臭いをつけないで下さい。
                                        籠谷裕人 (篭／籠の難しい方)
                                        [email-masked]

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