mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
fix to allow reading from stdin
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31221 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e67a8b6e5b
commit
ea423f1f64
3 changed files with 33 additions and 22 deletions
|
@ -1,6 +1,6 @@
|
|||
2010-08-31 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* 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 <rfm@gnu.org>
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue