|
riel |
755e19b |
* Fix http://bugzilla.redhat.com/57508 (make dos2unix not modify Mac
|
|
riel |
755e19b |
files unless in mac2unix mode)
|
|
riel |
755e19b |
* Make mac2unix mode not create duplicate Unix line delimiters when
|
|
riel |
755e19b |
run on a DOS file. (mschwendt@users.sf.net)
|
|
riel |
755e19b |
|
|
riel |
755e19b |
diff -Nur dos2unix-3.1-orig/dos2unix.c dos2unix-3.1/dos2unix.c
|
|
riel |
755e19b |
--- dos2unix-3.1-orig/dos2unix.c 1998-11-19 13:19:25.000000000 +0100
|
|
riel |
755e19b |
+++ dos2unix-3.1/dos2unix.c 2004-09-26 20:57:41.606587616 +0200
|
|
riel |
755e19b |
@@ -153,6 +153,24 @@
|
|
riel |
755e19b |
}
|
|
riel |
755e19b |
|
|
riel |
755e19b |
|
|
![](https://seccdn.libravatar.org/avatar/3e8757f2b083a633b561bed99e8b66f5da75d6f392ddc34a6cfa3f4aec6dffc0?s=16&d=retro) |
c230060 |
+void StripDelimiter(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, int CurChar)
|
|
riel |
755e19b |
+{
|
|
riel |
755e19b |
+ int TempNextChar;
|
|
riel |
755e19b |
+ /* Don't modify Mac files when in dos2unix mode. */
|
|
riel |
755e19b |
+ if ( (TempNextChar = getc(ipInF)) != EOF) {
|
|
riel |
755e19b |
+ ungetc( TempNextChar, ipInF ); /* put back peek char */
|
|
riel |
755e19b |
+ if ( TempNextChar != '\x0a' ) {
|
|
riel |
755e19b |
+ putc( CurChar, ipOutF ); /* Mac line, put back CR */
|
|
riel |
755e19b |
+ }
|
|
riel |
755e19b |
+ }
|
|
riel |
755e19b |
+ else if ( CurChar == '\x0d' ) { /* EOF: last Mac line delimiter (CR)? */
|
|
riel |
755e19b |
+ putc( CurChar, ipOutF );
|
|
riel |
755e19b |
+ }
|
|
riel |
755e19b |
+ if (ipFlag->NewLine) { /* add additional LF? */
|
|
riel |
755e19b |
+ putc('\n', ipOutF);
|
|
riel |
755e19b |
+ }
|
|
riel |
755e19b |
+}
|
|
riel |
755e19b |
+
|
|
riel |
755e19b |
/* converts stream ipInF to UNIX format text and write to stream ipOutF
|
|
riel |
755e19b |
* RetVal: 0 if success
|
|
riel |
755e19b |
* -1 otherwise
|
|
riel |
755e19b |
@@ -161,6 +179,7 @@
|
|
riel |
755e19b |
{
|
|
riel |
755e19b |
int RetVal = 0;
|
|
riel |
755e19b |
int TempChar;
|
|
riel |
755e19b |
+ int TempNextChar;
|
|
riel |
755e19b |
|
|
riel |
755e19b |
if ( macmode )
|
|
riel |
755e19b |
ipFlag->ConvMode = 3;
|
|
riel |
755e19b |
@@ -177,9 +196,7 @@
|
|
riel |
755e19b |
break;
|
|
riel |
755e19b |
}
|
|
riel |
755e19b |
} else {
|
|
riel |
755e19b |
- if (ipFlag->NewLine) {
|
|
riel |
755e19b |
- putc('\n', ipOutF);
|
|
riel |
755e19b |
- }
|
|
riel |
755e19b |
+ StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
|
|
riel |
755e19b |
}
|
|
riel |
755e19b |
}
|
|
riel |
755e19b |
break;
|
|
riel |
755e19b |
@@ -193,9 +210,7 @@
|
|
riel |
755e19b |
break;
|
|
riel |
755e19b |
}
|
|
riel |
755e19b |
} else {
|
|
riel |
755e19b |
- if (ipFlag->NewLine) {
|
|
riel |
755e19b |
- putc('\n', ipOutF);
|
|
riel |
755e19b |
- }
|
|
riel |
755e19b |
+ StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
|
|
riel |
755e19b |
}
|
|
riel |
755e19b |
}
|
|
riel |
755e19b |
break;
|
|
riel |
755e19b |
@@ -209,9 +224,7 @@
|
|
riel |
755e19b |
break;
|
|
riel |
755e19b |
}
|
|
riel |
755e19b |
} else {
|
|
riel |
755e19b |
- if (ipFlag->NewLine) {
|
|
riel |
755e19b |
- putc('\n', ipOutF);
|
|
riel |
755e19b |
- }
|
|
riel |
755e19b |
+ StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
|
|
riel |
755e19b |
}
|
|
riel |
755e19b |
}
|
|
riel |
755e19b |
break;
|
|
riel |
755e19b |
@@ -227,6 +240,13 @@
|
|
riel |
755e19b |
}
|
|
riel |
755e19b |
}
|
|
riel |
755e19b |
else{
|
|
riel |
755e19b |
+ if ( (TempNextChar = getc(ipInF)) != EOF) {
|
|
riel |
755e19b |
+ ungetc( TempNextChar, ipInF ); /* put back peek char */
|
|
riel |
755e19b |
+ /* Don't touch this delimiter if it's a CR,LF pair. */
|
|
riel |
755e19b |
+ if ( TempNextChar == '\x0a' ) {
|
|
riel |
755e19b |
+ continue;
|
|
riel |
755e19b |
+ }
|
|
riel |
755e19b |
+ }
|
|
riel |
755e19b |
if (putc('\x0a', ipOutF) == EOF)
|
|
riel |
755e19b |
{
|
|
riel |
755e19b |
RetVal = -1;
|