$B2,It$G$9(B.
Hironori Sakamoto <h-saka@lsi.nec.co.jp> writes:
> ($B0JA0$+$i$N8=>]$J$N$G$9$,(B) text/plain $B$J%U%!%$%k$r!"(B-dump $B$9$k$H(B
> $B%U%!%$%k$NKvHx$KM>7W$J(B '\n' $B$,$D$-$^$9!#(B
>
> % echo a > 1.txt
> # od -c 1.txt
> 0000000 a \n
> 0000002
> % w3m 1.txt -dump | od -c
> 0000000 a \n \n
> 0000003
>
> loadBuffer() $B$GFI$_9~$`;~$K(B end-of-file $B$KE~C#$7$F$$$F$b!"(B
> lineBuf2 $B$K6uJ8;zNs$,F~$C$F$-$F(B 1$B9TM>J,$KDI2C$5$l$F$$$k$h$&$G$9!#(B
InputStream $B$N(B iseos $B%U%i%0$r99?7$9$k%?%$%_%s%0$KLdBj$,$"$j$^$9$M(B.
$B<!$N%Q%C%A$G$I$&$G$7$g$&$+(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 09:23:43
@@ -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,20 @@
return len;
}
+static void
+init_base_stream(InputStream stream, int bufsize)
+{
+ BaseStream base = &stream->base;
+ StreamBuffer sb = &base->stream;
+ sb->size = bufsize;
+ if (bufsize > 0)
+ sb->buf = NewAtom_N(uchar, sb->size);
+ else
+ sb->buf = NULL;
+ base->iseos = FALSE;
+ do_update(base);
+}
+
InputStream
newInputStream(int des)
{
@@ -73,12 +74,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, STREAM_BUF_SIZE);
return stream;
}
@@ -89,7 +90,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 +99,7 @@
stream->file.handle->close = (void (*)()) fclose;
stream->file.read = (int (*)()) file_read;
stream->file.close = (void (*)()) file_close;
+ init_base_stream(stream, STREAM_BUF_SIZE);
return stream;
}
@@ -109,7 +110,6 @@
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;
@@ -117,6 +117,7 @@
stream->str.handle = s;
stream->str.read = (int (*)()) str_read;
stream->str.close = NULL;
+ init_base_stream(stream, 0);
return stream;
}
@@ -128,13 +129,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, SSL_BUF_SIZE);
return stream;
}
#endif
@@ -146,7 +147,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 +155,7 @@
stream->ens.handle->s = NULL;
stream->ens.read = (int (*)()) ens_read;
stream->ens.close = (void (*)()) ens_close;
+ init_base_stream(stream, STREAM_BUF_SIZE);
return stream;
}
@@ -173,12 +174,16 @@
ISgetc(InputStream stream)
{
BaseStream base;
+ int c;
if (stream == NULL)
return '\0';
base = &stream->base;
- if (MUST_BE_UPDATED(base))
+ if (!base->iseos && MUST_BE_UPDATED(base))
+ do_update(base);
+ c = POP_CHAR(base);
+ if (!base->iseos && MUST_BE_UPDATED(base))
do_update(base);
- return POP_CHAR(base);
+ return c;
}
int
@@ -210,7 +215,7 @@
base = &stream->base;
sb = &base->stream;
- while (!stream->base.iseos) {
+ while (!base->iseos) {
if (MUST_BE_UPDATED(base)) {
do_update(base);
}
@@ -221,7 +226,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 +237,10 @@
}
}
+ done:
+ if (!base->iseos && MUST_BE_UPDATED(base)) {
+ do_update(base);
+ }
if (s == NULL)
return Strnew();
return s;
@@ -250,7 +259,7 @@
base = &stream->base;
sb = &base->stream;
- while (!stream->base.iseos) {
+ while (!base->iseos) {
if (MUST_BE_UPDATED(base)) {
do_update(base);
}
@@ -258,7 +267,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 +279,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 +290,10 @@
}
}
+ done:
+ if (!base->iseos && MUST_BE_UPDATED(base)) {
+ do_update(base);
+ }
if (s == NULL)
return Strnew();
return s;
--
$B2,It9nLi(B
e-mail: okabek@guitar.ocn.ne.jp
------------------------------------------------
This archive was generated by hypermail 2b29 : Wed Dec 27 2000 - 04:33:55 CST