diff --git a/ChangeLog b/ChangeLog index b91c93a82..ecea341b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,6 @@ 2010-08-31 Richard Frith-Macdonald - * Tools/cvtenc.m: Add -Unicode option + * Tools/cvtenc.m: Add -Unicode option. Fix to allow reading from stdin * Tools/cvtenc.1: update 2010-08-30 Richard Frith-Macdonald diff --git a/Source/GSFileHandle.m b/Source/GSFileHandle.m index a54d049c8..4abe7cdf6 100644 --- a/Source/GSFileHandle.m +++ b/Source/GSFileHandle.m @@ -243,14 +243,14 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin) - (void) dealloc { - RELEASE(address); - RELEASE(service); - RELEASE(protocol); + DESTROY(address); + DESTROY(service); + DESTROY(protocol); [self finalize]; - RELEASE(readInfo); - RELEASE(writeInfo); + DESTROY(readInfo); + DESTROY(writeInfo); [super dealloc]; } @@ -273,6 +273,7 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin) if (gzDescriptor != 0) { gzclose(gzDescriptor); + gzDescriptor = 0; } #endif if (descriptor != -1) @@ -1023,10 +1024,10 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; { self = [self initWithFileDescriptor: 2 closeOnDealloc: NO]; fh_stderr = self; - } - if (self) - { - readOK = NO; + if (self) + { + readOK = NO; + } } return self; } @@ -1041,10 +1042,10 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; { self = [self initWithFileDescriptor: 0 closeOnDealloc: NO]; fh_stdin = self; - } - if (self) - { - writeOK = NO; + if (self) + { + writeOK = NO; + } } return self; } @@ -1059,10 +1060,10 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; { self = [self initWithFileDescriptor: 1 closeOnDealloc: NO]; fh_stdout = self; - } - if (self) - { - readOK = NO; + if (self) + { + readOK = NO; + } } return self; } @@ -1810,9 +1811,9 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; if ([writeInfo count] > 0) { - NSMutableDictionary* info = [writeInfo objectAtIndex: 0]; + NSMutableDictionary *info = [writeInfo objectAtIndex: 0]; - modes=(NSArray*)[info objectForKey: NSFileHandleNotificationMonitorModes]; + modes = [info objectForKey: NSFileHandleNotificationMonitorModes]; } if (modes && [modes count]) diff --git a/Tools/cvtenc.m b/Tools/cvtenc.m index 8f0a86fcc..c942c753d 100644 --- a/Tools/cvtenc.m +++ b/Tools/cvtenc.m @@ -139,7 +139,7 @@ main(int argc, char** argv, char **env) { NSString *file = [args objectAtIndex: i]; - if ([file hasPrefix: @"-"] == YES) + if ([file hasPrefix: @"-"] == YES && NO == [file isEqual: @"-"]) { i++; continue; @@ -149,7 +149,15 @@ main(int argc, char** argv, char **env) { NSData *myData; - myData = [[NSData alloc] initWithContentsOfFile: file]; + if (YES == [file isEqual: @"-"]) + { + myData = [[[NSFileHandle fileHandleWithStandardInput] + readDataToEndOfFile] retain]; + } + else + { + myData = [[NSData alloc] initWithContentsOfFile: file]; + } if (myData == nil) { NSLog(@"File read operation failed for %@.", file); @@ -299,10 +307,12 @@ main(int argc, char** argv, char **env) else { NSFileHandle *out; + CREATE_AUTORELEASE_POOL(arp); out = [NSFileHandle fileHandleWithStandardOutput]; [out writeData: myData]; [out synchronizeFile]; + RELEASE(arp); } } }