$BFbIt(B HTML $B%=!<%9$NFI$_9~$_$,$&$^$/F0$$$F$$$^$;$s$G$7$?(B.
[w3m-dev 01587] $B$O(B, $B<!$N%Q%C%A$GCV$-49$($^$7$?(B.
Index: istream.c
===================================================================
RCS file: /home/okabe/CVS_DB/w3m/istream.c,v
retrieving revision 1.1.2.14
diff -u -r1.1.2.14 istream.c
--- istream.c 2000/12/26 06:17:30 1.1.2.14
+++ istream.c 2000/12/27 11:43:47
@@ -10,7 +10,7 @@
#define MUST_BE_UPDATED(bs) ((bs)->stream.cur==(bs)->stream.next)
-#define POP_CHAR(bs) ((bs)->iseos?'\0':(bs)->stream.buf[(bs)->stream.cur++])
+#define POP_CHAR(bs) ((bs)->stream.buf[(bs)->stream.cur++])
static void basic_close(int *handle);
static int basic_read(int *handle, char *buf, int len);
@@ -29,19 +29,6 @@
static void ens_close(struct ens_handle *handle);
static void
-init_base_stream(BaseStream base, int bufsize)
-{
- StreamBuffer sb = &base->stream;
- sb->cur = sb->next = 0;
- sb->size = bufsize;
- if (bufsize > 0)
- sb->buf = NewAtom_N(uchar, sb->size);
- else
- sb->buf = NULL;
- base->iseos = FALSE;
-}
-
-static void
do_update(BaseStream base)
{
int len;
@@ -66,6 +53,32 @@
return len;
}
+static void
+init_buffer(BaseStream base, char *buf, int bufsize, int len)
+{
+ StreamBuffer sb = &base->stream;
+ sb->buf = buf;
+ sb->size = bufsize;
+ sb->cur = 0;
+ sb->next = len;
+ base->iseos = FALSE;
+}
+
+static void
+init_base_stream(BaseStream base, int bufsize)
+{
+ init_buffer(base, NewAtom_N(uchar, bufsize), bufsize, 0);
+ do_update(base);
+}
+
+static void
+init_str_stream(BaseStream base, Str s)
+{
+ init_buffer(base, s->ptr, s->length, s->length);
+ if (s->length == 0)
+ base->iseos = TRUE;
+}
+
InputStream
newInputStream(int des)
{
@@ -73,12 +86,12 @@
if (des < 0)
return NULL;
stream = New(union input_stream);
- init_base_stream(&stream->base, STREAM_BUF_SIZE);
stream->base.type = IST_BASIC;
stream->base.handle = New(int);
*(int *)stream->base.handle = des;
stream->base.read = (int (*)()) basic_read;
stream->base.close = (void (*)()) basic_close;
+ init_base_stream(&stream->base, STREAM_BUF_SIZE);
return stream;
}
@@ -89,7 +102,6 @@
if (f == NULL)
return NULL;
stream = New(union input_stream);
- init_base_stream(&stream->base, STREAM_BUF_SIZE);
stream->file.type = IST_FILE;
stream->file.handle = New(struct file_handle);
stream->file.handle->f = f;
@@ -99,6 +111,7 @@
stream->file.handle->close = (void (*)()) fclose;
stream->file.read = (int (*)()) file_read;
stream->file.close = (void (*)()) file_close;
+ init_base_stream(&stream->base, STREAM_BUF_SIZE);
return stream;
}
@@ -109,14 +122,11 @@
if (s == NULL)
return NULL;
stream = New(union input_stream);
- init_base_stream(&stream->base, 0);
- stream->str.stream.next = s->length;
- stream->str.stream.size = s->length;
- stream->str.stream.buf = s->ptr;
stream->str.type = IST_STR;
stream->str.handle = s;
stream->str.read = (int (*)()) str_read;
stream->str.close = NULL;
+ init_str_stream(&stream->base, s);
return stream;
}
@@ -128,13 +138,13 @@
if (sock < 0)
return NULL;
stream = New(union input_stream);
- init_base_stream(&stream->base, SSL_BUF_SIZE);
stream->ssl.type = IST_SSL;
stream->ssl.handle = New(struct ssl_handle);
stream->ssl.handle->ssl = ssl;
stream->ssl.handle->sock = sock;
stream->ssl.read = (int (*)()) ssl_read;
stream->ssl.close = (void (*)()) ssl_close;
+ init_base_stream(&stream->base, SSL_BUF_SIZE);
return stream;
}
#endif
@@ -146,7 +156,6 @@
if (is == NULL || (encoding != ENC_QUOTE && encoding != ENC_BASE64))
return is;
stream = New(union input_stream);
- init_base_stream(&stream->base, STREAM_BUF_SIZE);
stream->ens.type = IST_ENCODED;
stream->ens.handle = New(struct ens_handle);
stream->ens.handle->is = is;
@@ -155,6 +164,7 @@
stream->ens.handle->s = NULL;
stream->ens.read = (int (*)()) ens_read;
stream->ens.close = (void (*)()) ens_close;
+ init_base_stream(&stream->base, STREAM_BUF_SIZE);
return stream;
}
@@ -173,12 +183,13 @@
ISgetc(InputStream stream)
{
BaseStream base;
- if (stream == NULL)
+ int c;
+ if (stream == NULL || (base = &stream->base)->iseos)
return '\0';
- base = &stream->base;
+ c = POP_CHAR(base);
if (MUST_BE_UPDATED(base))
do_update(base);
- return POP_CHAR(base);
+ return c;
}
int
@@ -206,11 +217,11 @@
int len;
if (stream == NULL)
- return '\0';
+ return NULL;
base = &stream->base;
sb = &base->stream;
- while (!stream->base.iseos) {
+ while (!base->iseos) {
if (MUST_BE_UPDATED(base)) {
do_update(base);
}
@@ -221,7 +232,7 @@
s = Strnew_size(len);
Strcat_charp_n(s, &sb->buf[sb->cur], len);
sb->cur += len;
- return s;
+ goto done;
}
else {
if (s == NULL)
@@ -232,6 +243,10 @@
}
}
+ done:
+ if (!base->iseos && MUST_BE_UPDATED(base)) {
+ do_update(base);
+ }
if (s == NULL)
return Strnew();
return s;
@@ -250,7 +265,7 @@
base = &stream->base;
sb = &base->stream;
- while (!stream->base.iseos) {
+ while (!base->iseos) {
if (MUST_BE_UPDATED(base)) {
do_update(base);
}
@@ -258,7 +273,7 @@
if (s && Strlastchar(s) == '\r') {
if (sb->buf[sb->cur] == '\n')
Strcat_char(s, sb->buf[sb->cur++]);
- return s;
+ goto done;
}
for (i = sb->cur;
i < sb->next && sb->buf[i] != '\n' && sb->buf[i] != '\r';
@@ -270,7 +285,7 @@
Strcat_charp_n(s, &sb->buf[sb->cur], len);
sb->cur = i + 1;
if (sb->buf[i] == '\n')
- return s;
+ goto done;
}
else {
if (s == NULL)
@@ -281,6 +296,10 @@
}
}
+ done:
+ if (!base->iseos && MUST_BE_UPDATED(base)) {
+ do_update(base);
+ }
if (s == NULL)
return Strnew();
return s;
@@ -303,6 +322,8 @@
base->iseos = TRUE;
len = 0;
}
+ else
+ do_update(base);
rest -= len;
}
Strtruncate(buf, count - rest);
--
$B2,It9nLi(B
e-mail: okabek@guitar.ocn.ne.jp
------------------------------------------------
This archive was generated by hypermail 2b29 : Wed Dec 27 2000 - 06:03:13 CST