OSDN Git Service

重村さんのパッチをもとに、-F の改行保存の改行として CR/CRLF/LF
authorRei FURUKAWA <rei_furukawa@users.sourceforge.jp>
Fri, 6 Dec 2002 05:52:39 +0000 (05:52 +0000)
committerRei FURUKAWA <rei_furukawa@users.sourceforge.jp>
Fri, 6 Dec 2002 05:52:39 +0000 (05:52 +0000)
を保存するようにした

nkf.c
nkf_test.pl

diff --git a/nkf.c b/nkf.c
index 4340616..b247ee2 100644 (file)
--- a/nkf.c
+++ b/nkf.c
@@ -2320,19 +2320,27 @@ int c2,c1;
     int prev0;
     int fold_state=0;
 
-    if (c1== '\r') {
-       fold_state=0;  /* ignroe cr */
+    if (c1== '\r' && !fold_preserve_f) {
+       fold_state=0;  /* ignore cr */
+    }else if (c1== '\n'&&f_prev=='\r' && fold_preserve_f) {
+        f_prev = '\n';
+       fold_state=0;  /* ignore cr */
     } else if (c1== BS) {
         if (f_line>0) f_line--;
         fold_state =  1;
     } else if (c2==EOF && f_line != 0) {    /* close open last line */
             fold_state = '\n';
-    } else if (c1=='\n') {
+    } else if ((c1=='\n' && !fold_preserve_f)
+               || ((c1=='\r'||(c1=='\n'&&f_prev!='\r'))
+                   && fold_preserve_f)) {
         /* new line */
         if (fold_preserve_f) { 
-                f_line = 0;
-                fold_state =  '\r';
-       } else if (f_prev == c1) {        /* duplicate newline */
+            f_prev = c1;
+            f_line = 0;
+            fold_state =  '\r';
+       } else if ((f_prev == c1 && !fold_preserve_f)
+                   || (f_prev == '\n' && fold_preserve_f)
+                   ) {        /* duplicate newline */
             if (f_line) {
                 f_line = 0;
                 fold_state =  '\n';    /* output two newline */
index 44ac41b..84f72ea 100644 (file)
@@ -423,15 +423,19 @@ print "test_data/fixed-qencode    ";
 $example{'test_data/long-fold-1'} = unpack('u',<<'eofeof');
 MI,JDK*2DI,JDK*2DI,JDK*'!I*2DKJ3GI*:DK*2BI.JDWJ2WI,:AHJ2SI.RD
 M\J2]I,ZDWJ3>I**DQ*2KI*:DR*&BI,FDIJ3BI-^DT*2HI*RD[Z3KI*2DMZ&B
-MI,BDP:3EI*:DQZ3!I.>D\Z2NI.RDZZ2KI.*DMZ3SI,JDI*&C"J2SI+.DS\.[
-'I*2YU*&C"@``
+MI,BDP:3EI*:DQZ3!I.>D\Z2NI.RDZZ2KI.*DMZ3SI,JDI*&C"J2SI+.DSR!#
+M4B],1B"DSKG4H:,-"J2SI+.DSR!#4B"DSKG4H:,-I+.DLZ3/($Q&+T-2(*3.
+9N=2AHPH-"J2SI+.DSR!,1B"DSKG4H:,*"@``
 eofeof
 
 $example{'test_data/long-fold-1.ans'} = unpack('u',<<'eofeof');
 M&R1")$HD+"0D)$HD+"0D)$HD+"%!)"0D+B1G)"8D+"0B)&HD7B0W)$8A(B0S
 M)&PD<B0])$XD7B1>)"(D1"0K&RA""ALD0B0F)$@A(B1))"8D8B1?)%`D*"0L
 M)&\D:R0D)#<A(B1()$$D920F)$<D021G)',D+B1L)&LD*R1B)#<D<QLH0@H;
-A)$(D2B0D(2,;*$(*&R1")#,D,R1/0SLD)#E4(2,;*$(*
+M)$(D2B0D(2,;*$(*&R1")#,D,R1/&RA"($-2+TQ&(!LD0B1..50A(QLH0@H;
+M)$(D,R0S)$\;*$(@0U(@&R1")$XY5"$C&RA""ALD0B0S)#,D3QLH0B!,1B]#
+M4B`;)$(D3CE4(2,;*$(*"ALD0B0S)#,D3QLH0B!,1B`;)$(D3CE4(2,;*$(*
+!"@``
 eofeof
 
 print "test_data/long-fold-1    ";