]> git.pld-linux.org Git - packages/dos2unix.git/blame - dos2unix-safeconv.patch
- up
[packages/dos2unix.git] / dos2unix-safeconv.patch
CommitLineData
62371aa3
AM
1* Fix http://bugzilla.redhat.com/57508 (make dos2unix not modify Mac
2 files unless in mac2unix mode)
3* Make mac2unix mode not create duplicate Unix line delimiters when
4 run on a DOS file. (mschwendt@users.sf.net)
5
6diff -Nur dos2unix-3.1-orig/dos2unix.c dos2unix-3.1/dos2unix.c
7--- dos2unix-3.1-orig/dos2unix.c 1998-11-19 13:19:25.000000000 +0100
8+++ dos2unix-3.1/dos2unix.c 2004-09-26 20:57:41.606587616 +0200
9@@ -153,6 +153,24 @@
10 }
11
12
13+void StripDelimiter(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, int CurChar)
14+{
15+ int TempNextChar;
16+ /* Don't modify Mac files when in dos2unix mode. */
17+ if ( (TempNextChar = getc(ipInF)) != EOF) {
18+ ungetc( TempNextChar, ipInF ); /* put back peek char */
19+ if ( TempNextChar != '\x0a' ) {
20+ putc( CurChar, ipOutF ); /* Mac line, put back CR */
21+ }
22+ }
23+ else if ( CurChar == '\x0d' ) { /* EOF: last Mac line delimiter (CR)? */
24+ putc( CurChar, ipOutF );
25+ }
26+ if (ipFlag->NewLine) { /* add additional LF? */
27+ putc('\n', ipOutF);
28+ }
29+}
30+
31 /* converts stream ipInF to UNIX format text and write to stream ipOutF
32 * RetVal: 0 if success
33 * -1 otherwise
34@@ -161,6 +179,7 @@
35 {
36 int RetVal = 0;
37 int TempChar;
38+ int TempNextChar;
39
40 if ( macmode )
41 ipFlag->ConvMode = 3;
42@@ -177,9 +196,7 @@
43 break;
44 }
45 } else {
46- if (ipFlag->NewLine) {
47- putc('\n', ipOutF);
48- }
49+ StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
50 }
51 }
52 break;
53@@ -193,9 +210,7 @@
54 break;
55 }
56 } else {
57- if (ipFlag->NewLine) {
58- putc('\n', ipOutF);
59- }
60+ StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
61 }
62 }
63 break;
64@@ -209,9 +224,7 @@
65 break;
66 }
67 } else {
68- if (ipFlag->NewLine) {
69- putc('\n', ipOutF);
70- }
71+ StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
72 }
73 }
74 break;
75@@ -227,6 +240,13 @@
76 }
77 }
78 else{
79+ if ( (TempNextChar = getc(ipInF)) != EOF) {
80+ ungetc( TempNextChar, ipInF ); /* put back peek char */
81+ /* Don't touch this delimiter if it's a CR,LF pair. */
82+ if ( TempNextChar == '\x0a' ) {
83+ continue;
84+ }
85+ }
86 if (putc('\x0a', ipOutF) == EOF)
87 {
88 RetVal = -1;
This page took 0.095223 seconds and 4 git commands to generate.