No. 183/622 Index Prev Next
Path: titcca!ccut!ascgw!flab!ichikawa
From: ichikawa@flab.flab.fujitsu.JUNET (I.Ichikawa)
Newsgroups: fj.kanji,fj.sources
Subject: NKF patch #1 (bug fix and rot13/47)
Message-ID: < 1504@flab.flab.fujitsu.JUNET> 
Date: 17 Sep 87 05:17:24 GMT
Reply-To: ichikawa@flab.flab.fujitsu.JUNET (I.Ichikawa)
Distribution: fj
Organization: Fujitsu Laboratories Ltd., Kawasaki, Japan
Lines: 287
Xref: titcca fj.kanji:241 fj.sources:451
Posted: Thu Sep 17 14:17:24 1987

Hello, folks.
NKFのバグをフィックスし、あわせて、ROT13/47対応にしてしまうという、パッ
チファイルを配ります。とても、小規模の変更です。

で、-rオプションで、ROT13/47をします。

まあ、動作は一応確認しましたが、αテストぐらいなもんで、もうひとつ自身が
ありません。

それでは、cut here以降を切りとって、patch nkf.c < FILE として下さい。
patchがない方は、手でどうぞ。
---	富士通研究所 ソフト3研		市川
This is the patch file for nkf. 
	(a silly bug was fixed, and ROT13/47 {en,de}cryption is enable)
----------------------------cut here----------------------------------
*** nkf.c.rev0	Fri Aug 21 15:48:39 1987
--- nkf.c.rev1	Thu Sep 17 13:59:01 1987
***************
*** 1,4
! /** Network Kanji Filter. (PDS Version)
  ************************************************************************
  ************************************************************************
  ** Copyright (C) Fujitsu LTD. (Itaru ICHIKAWA), 1987

--- 1,4 -----
! /** Network Kanji Filter. (PDS Version, rev 1)
  ************************************************************************
  ************************************************************************
  ** Copyright (C) Fujitsu LTD. (Itaru ICHIKAWA), 1987
***************
*** 33,38
  ** BJ	= iBoJ			
  ** BB	= iBoB 	
  **
  **/
  
  #include 

--- 33,42 -----
  ** BJ	= iBoJ			
  ** BB	= iBoB 	
  **
+ **	New Option
+ **
+ ** r	{de/en}crypt ROT13/47
+ **
  **/
  
  #include 
***************
*** 81,86
  int             e_oconv ();
  int             j_oconv ();
  int             s_oconv ();
  int             (*iconv) ();
  int             (*oconv) ();
  

--- 85,95 -----
  int             e_oconv ();
  int             j_oconv ();
  int             s_oconv ();
+ 
+ unsigned int		rot13 ();
+ unsigned int		rot47 ();
+ unsigned int		nops ();
+ 
  int             (*iconv) ();
  unsigned int		(*r1conv) ();
  unsigned int		(*r2conv) ();
***************
*** 82,87
  int             j_oconv ();
  int             s_oconv ();
  int             (*iconv) ();
  int             (*oconv) ();
  
  /* Global states */

--- 91,98 -----
  unsigned int		nops ();
  
  int             (*iconv) ();
+ unsigned int		(*r1conv) ();
+ unsigned int		(*r2conv) ();
  int             (*oconv) ();
  
  /* Global states */
***************
*** 100,105
      register char  *cp;
  
      oconv = j_oconv;
      for (argv++; (argc > 1) & &  **argv == '-'; argc--, argv++) {
  	cp = *argv;
  	while (*cp)

--- 111,118 -----
      register char  *cp;
  
      oconv = j_oconv;
+     r1conv = nops;
+     r2conv = nops;
      for (argv++; (argc > 1) & &  **argv == '-'; argc--, argv++) {
  	cp = *argv;
  	while (*cp)
***************
*** 147,152
  		k_in = '@';
  		k_out = 'H';
  		continue;
  	    default:
  		/* bogus option but ignored */
  		continue;

--- 160,169 -----
  		k_in = '@';
  		k_out = 'H';
  		continue;
+ 	    case 'r':
+ 		r1conv = rot13;
+ 		r2conv = rot47;
+ 		continue;
  	    default:
  		/* bogus option but ignored */
  		continue;
***************
*** 456,462
      if (c2 == EOF)
  	return;
      else if (c2 == 0)
! 	putchar ((c1 &  0x7f));
      else {
  	putchar (((c2 &  0x7f) | 0x080));
  	putchar (((c1 &  0x7f) | 0x080));

--- 473,479 -----
      if (c2 == EOF)
  	return;
      else if (c2 == 0)
! 	putchar ((*r1conv) (c1));
      else {
  	putchar (((*r2conv) (c2)) | 0x080);
  	putchar (((*r2conv) (c1)) | 0x080);
***************
*** 458,465
      else if (c2 == 0)
  	putchar ((c1 &  0x7f));
      else {
! 	putchar (((c2 &  0x7f) | 0x080));
! 	putchar (((c1 &  0x7f) | 0x080));
      }
  }
  

--- 475,482 -----
      else if (c2 == 0)
  	putchar ((*r1conv) (c1));
      else {
! 	putchar (((*r2conv) (c2)) | 0x080);
! 	putchar (((*r2conv) (c1)) | 0x080);
      }
  }
  
***************
*** 474,480
      if (c2 == EOF)
  	return;
      else if (c2 == 0)
! 	putchar ((c1 &  0x7f));
      else {
  	c2 & = 0x07f;
  	c1 & = 0x07f;

--- 491,497 -----
      if (c2 == EOF)
  	return;
      else if (c2 == 0)
! 	putchar ((*r1conv) (c1));
      else {
  	c2 = (*r2conv) (c2);
  	c1 = (*r2conv) (c1);
***************
*** 476,484
      else if (c2 == 0)
  	putchar ((c1 &  0x7f));
      else {
! 	c2 & = 0x07f;
! 	c1 & = 0x07f;
! 	putchar ((((c2 - 1) >> 1) + ((c2 < = 0x51) ? 0x71 : 0xb1)));
  	putchar ((c1 + ((c2 &  1) ? ((c1 < 0x60) ? 0x1f : 0x20) : 0x7e)));
      }
  }

--- 493,501 -----
      else if (c2 == 0)
  	putchar ((*r1conv) (c1));
      else {
! 	c2 = (*r2conv) (c2);
! 	c1 = (*r2conv) (c1);
! 	putchar ((((c2 - 1) >> 1) + ((c2 < = 0x5e) ? 0x71 : 0xb1)));
  	putchar ((c1 + ((c2 &  1) ? ((c1 < 0x60) ? 0x1f : 0x20) : 0x7e)));
      }
  }
***************
*** 500,506
  	    putchar (k_out);
  	    in_kanji = FALSE;
  	}
! 	putchar ((c1 &  0x7f));
      } else {
  	if (in_kanji == FALSE) {
  	    putchar (ESC);

--- 517,523 -----
  	    putchar (k_out);
  	    in_kanji = FALSE;
  	}
! 	putchar ((*r1conv)(c1));
      } else {
  	if (in_kanji == FALSE) {
  	    putchar (ESC);
***************
*** 508,515
  	    putchar (k_in);
  	    in_kanji = TRUE;
  	}
! 	putchar ((c2 &  0x7f));
! 	putchar ((c1 &  0x7f));
      }
  }
  

--- 525,532 -----
  	    putchar (k_in);
  	    in_kanji = TRUE;
  	}
! 	putchar ((*r2conv)(c2));
! 	putchar ((*r2conv)(c1));
      }
  }
  
***************
*** 511,515
  	putchar ((c2 &  0x7f));
  	putchar ((c1 &  0x7f));
      }
  }
  

--- 528,563 -----
  	putchar ((*r2conv)(c2));
  	putchar ((*r2conv)(c1));
      }
+ }
+ 
+ 
+ unsigned int	nops (c)
+ 	char	c;
+ {
+ 	return (c &  0x07f);
+ }
+ 
+ 
+ unsigned int	rot13 (c)
+ 	char	c;
+ {
+ 	c & = 0x07f;
+ 	if ( c <  'A' ) return (c);
+ 	else if (c < = 'M') return (c + 13);
+ 	else if (c < = 'Z') return (c - 13);
+ 	else if (c <  'a') return (c);
+ 	else if (c < = 'm') return (c + 13);
+ 	else if (c < = 'z') return (c - 13);
+ 	else return (c);
+ }
+ 
+ unsigned int	rot47 (c)
+ 	char	c;
+ {
+ 	c & = 0x07f;
+ 	if ( c <  '!' ) return (c);
+ 	else if ( c < = 'O' ) return (c + 47);
+ 	else if ( c < = '~' ) return (c - 47);
+ 	else return (c);
  }
  
Next
Continue