1994-11-04 16:29:24 +00:00
|
|
|
/* Implementation of GNU Objective C byte stream
|
1996-01-23 21:04:49 +00:00
|
|
|
Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
1996-01-23 21:04:49 +00:00
|
|
|
Created: July 1994
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
1996-04-17 15:34:35 +00:00
|
|
|
#include <gnustep/base/preface.h>
|
1996-04-17 15:23:00 +00:00
|
|
|
#include <gnustep/base/Stream.h>
|
|
|
|
#include <gnustep/base/Coder.h>
|
|
|
|
#include <gnustep/base/Coder.h>
|
|
|
|
#include <gnustep/base/NSString.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-09-17 20:41:37 +00:00
|
|
|
NSString* StreamException = @"StreamException";
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
@implementation Stream
|
|
|
|
|
1996-01-23 21:04:49 +00:00
|
|
|
/* This is the designated initializer. */
|
1994-11-04 16:29:24 +00:00
|
|
|
- init
|
|
|
|
{
|
1995-04-15 19:57:25 +00:00
|
|
|
return [super init];
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) writeByte: (unsigned char)b
|
|
|
|
{
|
|
|
|
return [self writeBytes:&b length:1];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) readByte: (unsigned char*)b
|
|
|
|
{
|
|
|
|
return [self readBytes:b length:1];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) writeBytes: (const void*)b length: (int)l
|
|
|
|
{
|
1996-01-23 21:04:49 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1994-11-04 16:29:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) readBytes: (void*)b length: (int)l
|
|
|
|
{
|
1996-01-23 21:04:49 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1994-11-04 16:29:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-01-24 14:12:19 +00:00
|
|
|
- (int) writeFormat: (id <String>)format
|
|
|
|
arguments: (va_list)arg
|
|
|
|
{
|
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-01-23 21:04:49 +00:00
|
|
|
- (int) writeFormat: (id <String>)format, ...
|
1996-01-24 14:12:19 +00:00
|
|
|
{
|
1996-09-17 20:41:37 +00:00
|
|
|
int ret;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
ret = [self writeFormat: format arguments: ap];
|
|
|
|
va_end(ap);
|
|
|
|
return ret;
|
1996-01-24 14:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) readFormat: (id <String>)format
|
|
|
|
arguments: (va_list)arg
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-01-23 21:04:49 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1994-11-04 16:29:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-01-23 21:04:49 +00:00
|
|
|
- (int) readFormat: (id <String>)format, ...
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-01-23 21:04:49 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1994-11-04 16:29:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-01-23 21:04:49 +00:00
|
|
|
- (void) writeLine: (id <String>)l
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-01-23 22:30:56 +00:00
|
|
|
const char *s = [l cStringNoCopy];
|
|
|
|
[self writeBytes:s length:strlen(s)];
|
|
|
|
[self writeBytes:"\n" length:1];
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1996-01-23 21:04:49 +00:00
|
|
|
- (id <String>) readLine
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
|
|
|
char *l;
|
1996-01-23 22:59:23 +00:00
|
|
|
[self readFormat: @"%a[^\n]\n", &l];
|
1996-01-23 21:04:49 +00:00
|
|
|
return [NSString stringWithCStringNoCopy:l];
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) flushStream
|
|
|
|
{
|
1996-01-25 15:14:32 +00:00
|
|
|
/* Do nothing. */
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1996-02-24 16:37:55 +00:00
|
|
|
- (void) close
|
1996-01-24 15:37:09 +00:00
|
|
|
{
|
1996-01-25 15:14:32 +00:00
|
|
|
/* Do nothing. */
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isClosed
|
|
|
|
{
|
|
|
|
return NO;
|
1996-01-24 15:37:09 +00:00
|
|
|
}
|
|
|
|
|
1996-09-17 20:41:37 +00:00
|
|
|
- (void) setStreamPosition: (unsigned)i seekMode: (seek_mode_t)mode
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-01-23 21:04:49 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1996-09-17 20:41:37 +00:00
|
|
|
- (void) setStreamPosition: (unsigned)i
|
|
|
|
{
|
|
|
|
[self setStreamPosition: i seekMode: STREAM_SEEK_FROM_START];
|
|
|
|
}
|
|
|
|
|
1996-01-23 22:59:23 +00:00
|
|
|
- (void) rewindStream
|
|
|
|
{
|
|
|
|
[self setStreamPosition:0];
|
|
|
|
}
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
- (unsigned) streamPosition
|
|
|
|
{
|
1996-01-23 21:04:49 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1994-11-04 16:29:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-04-17 20:43:29 +00:00
|
|
|
- (BOOL) isAtEof
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-01-23 21:04:49 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1994-11-04 16:29:24 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
1995-04-15 19:57:25 +00:00
|
|
|
- (BOOL) isWritable
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-01-23 21:04:49 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1995-04-15 19:57:25 +00:00
|
|
|
return NO;
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1995-04-09 01:53:53 +00:00
|
|
|
- (void) encodeWithCoder: anEncoder
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-01-23 21:04:49 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1995-04-15 19:57:25 +00:00
|
|
|
- initWithCoder: aDecoder
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-01-23 21:04:49 +00:00
|
|
|
[self subclassResponsibility:_cmd];
|
1994-11-04 16:29:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|