safer conversion w/ mac2unix (fix from bz #57508)
This commit is contained in:
		
							parent
							
								
									5dfcf9c160
								
							
						
					
					
						commit
						755e19b1bf
					
				
							
								
								
									
										88
									
								
								dos2unix-3.1-safeconv.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								dos2unix-3.1-safeconv.patch
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,88 @@ | |||||||
|  | * Fix http://bugzilla.redhat.com/57508 (make dos2unix not modify Mac | ||||||
|  |   files unless in mac2unix mode) | ||||||
|  | * Make mac2unix mode not create duplicate Unix line delimiters when | ||||||
|  |   run on a DOS file. (mschwendt@users.sf.net) | ||||||
|  | 
 | ||||||
|  | diff -Nur dos2unix-3.1-orig/dos2unix.c dos2unix-3.1/dos2unix.c
 | ||||||
|  | --- dos2unix-3.1-orig/dos2unix.c	1998-11-19 13:19:25.000000000 +0100
 | ||||||
|  | +++ dos2unix-3.1/dos2unix.c	2004-09-26 20:57:41.606587616 +0200
 | ||||||
|  | @@ -153,6 +153,24 @@
 | ||||||
|  |  } | ||||||
|  |   | ||||||
|  |   | ||||||
|  | +int StripDelimiter(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, int CurChar)
 | ||||||
|  | +{
 | ||||||
|  | +  int TempNextChar;
 | ||||||
|  | +  /* Don't modify Mac files when in dos2unix mode. */
 | ||||||
|  | +  if ( (TempNextChar = getc(ipInF)) != EOF) {
 | ||||||
|  | +    ungetc( TempNextChar, ipInF );  /* put back peek char */
 | ||||||
|  | +    if ( TempNextChar != '\x0a' ) {
 | ||||||
|  | +      putc( CurChar, ipOutF );  /* Mac line, put back CR */
 | ||||||
|  | +    }
 | ||||||
|  | +  }
 | ||||||
|  | +  else if ( CurChar == '\x0d' ) {  /* EOF: last Mac line delimiter (CR)? */
 | ||||||
|  | +    putc( CurChar, ipOutF );
 | ||||||
|  | +  }
 | ||||||
|  | +  if (ipFlag->NewLine) {  /* add additional LF? */
 | ||||||
|  | +    putc('\n', ipOutF);
 | ||||||
|  | +  }
 | ||||||
|  | +}
 | ||||||
|  | +
 | ||||||
|  |  /* converts stream ipInF to UNIX format text and write to stream ipOutF | ||||||
|  |   * RetVal: 0  if success | ||||||
|  |   *         -1  otherwise | ||||||
|  | @@ -161,6 +179,7 @@
 | ||||||
|  |  { | ||||||
|  |      int RetVal = 0; | ||||||
|  |      int TempChar; | ||||||
|  | +    int TempNextChar;
 | ||||||
|  |       | ||||||
|  |      if ( macmode ) | ||||||
|  |        ipFlag->ConvMode = 3; | ||||||
|  | @@ -177,9 +196,7 @@
 | ||||||
|  |  		break; | ||||||
|  |  	      }  | ||||||
|  |  	    } else { | ||||||
|  | -	      if (ipFlag->NewLine) {
 | ||||||
|  | -		putc('\n', ipOutF);
 | ||||||
|  | -	      }
 | ||||||
|  | +	      StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
 | ||||||
|  |  	    } | ||||||
|  |  	  } | ||||||
|  |  	  break; | ||||||
|  | @@ -193,9 +210,7 @@
 | ||||||
|  |  		break; | ||||||
|  |  	      } | ||||||
|  |  	    } else { | ||||||
|  | -	      if (ipFlag->NewLine) {
 | ||||||
|  | -		putc('\n', ipOutF);
 | ||||||
|  | -	      }
 | ||||||
|  | +	      StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
 | ||||||
|  |  	    } | ||||||
|  |  	  } | ||||||
|  |  	  break; | ||||||
|  | @@ -209,9 +224,7 @@
 | ||||||
|  |  		break; | ||||||
|  |  	      } | ||||||
|  |  	    } else { | ||||||
|  | -	      if (ipFlag->NewLine) {
 | ||||||
|  | -		putc('\n', ipOutF);
 | ||||||
|  | -	      }
 | ||||||
|  | +	      StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
 | ||||||
|  |  	    } | ||||||
|  |  	  } | ||||||
|  |  	  break; | ||||||
|  | @@ -227,6 +240,13 @@
 | ||||||
|  |  		} | ||||||
|  |  	      } | ||||||
|  |  	    else{ | ||||||
|  | +	      if ( (TempNextChar = getc(ipInF)) != EOF) {
 | ||||||
|  | +		ungetc( TempNextChar, ipInF );  /* put back peek char */
 | ||||||
|  | +		/* Don't touch this delimiter if it's a CR,LF pair. */
 | ||||||
|  | +		if ( TempNextChar == '\x0a' ) {
 | ||||||
|  | +		  continue;
 | ||||||
|  | +		}
 | ||||||
|  | +	      }
 | ||||||
|  |  	      if (putc('\x0a', ipOutF) == EOF) | ||||||
|  |  		{ | ||||||
|  |  		  RetVal = -1; | ||||||
| @ -1,12 +1,13 @@ | |||||||
| Summary: Text file format converter | Summary: Text file format converter | ||||||
| Name: dos2unix | Name: dos2unix | ||||||
| Version: 3.1 | Version: 3.1 | ||||||
| Release: 18 | Release: 19 | ||||||
| Group: Applications/Text | Group: Applications/Text | ||||||
| License: Freely distributable | License: Freely distributable | ||||||
| Source: %{name}-%{version}.tar.bz2 | Source: %{name}-%{version}.tar.bz2 | ||||||
| Patch0: %{name}-%{version}.patch | Patch0: %{name}-%{version}.patch | ||||||
| Patch1: dos2unix-3.1-segfault.patch | Patch1: dos2unix-3.1-segfault.patch | ||||||
|  | Patch2: dos2unix-3.1-safeconv.patch | ||||||
| Buildroot: %{_tmppath}/%{name}-%{version}-root | Buildroot: %{_tmppath}/%{name}-%{version}-root | ||||||
| 
 | 
 | ||||||
| %description | %description | ||||||
| @ -16,6 +17,7 @@ Dos2unix converts DOS or MAC text files to UNIX format. | |||||||
| %setup -q | %setup -q | ||||||
| %patch0 -p1 -b .orig | %patch0 -p1 -b .orig | ||||||
| %patch1 -p1 -b .segf | %patch1 -p1 -b .segf | ||||||
|  | %patch2 -p1 -b .safe | ||||||
| for I in *.[ch]; do | for I in *.[ch]; do | ||||||
| 	sed -e 's,#endif.*,#endif,g' -e 's,#else.*,#else,g' $I > $I.new | 	sed -e 's,#endif.*,#endif,g' -e 's,#else.*,#else,g' $I > $I.new | ||||||
| 	mv -f $I.new $I | 	mv -f $I.new $I | ||||||
| @ -46,6 +48,9 @@ install -m444 mac2unix.1 $RPM_BUILD_ROOT%{_mandir}/man1 | |||||||
| rm -rf $RPM_BUILD_ROOT | rm -rf $RPM_BUILD_ROOT | ||||||
| 
 | 
 | ||||||
| %changelog | %changelog | ||||||
|  | * Sun Sep 26 2004 Rik van Riel <riel@redhat.com> 3.1-19 | ||||||
|  | - safer conversion w/ mac2unix (fix from bz #57508) | ||||||
|  | 
 | ||||||
| * Tue Jun 15 2004 Elliot Lee <sopwith@redhat.com> | * Tue Jun 15 2004 Elliot Lee <sopwith@redhat.com> | ||||||
| - rebuilt | - rebuilt | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user