fix read line, and add read line regression tests
parent
549e17a539
commit
3712ae68e5
|
@ -1,4 +1,4 @@
|
||||||
!:folding=indent:collapseFolds=1:
|
! :folding=indent:collapseFolds=1:
|
||||||
|
|
||||||
! $Id$
|
! $Id$
|
||||||
!
|
!
|
||||||
|
@ -38,7 +38,6 @@ USE: math
|
||||||
USE: namespaces
|
USE: namespaces
|
||||||
USE: parser
|
USE: parser
|
||||||
USE: prettyprint
|
USE: prettyprint
|
||||||
USE: regexp
|
|
||||||
USE: stack
|
USE: stack
|
||||||
USE: stdio
|
USE: stdio
|
||||||
USE: streams
|
USE: streams
|
||||||
|
@ -71,7 +70,7 @@ USE: unparser
|
||||||
: irc-stream-write ( string -- )
|
: irc-stream-write ( string -- )
|
||||||
dup "buf" get sbuf-append
|
dup "buf" get sbuf-append
|
||||||
ends-with-newline? [
|
ends-with-newline? [
|
||||||
"buf" get >str
|
"buf" get sbuf>str
|
||||||
0 "buf" get set-sbuf-length
|
0 "buf" get set-sbuf-length
|
||||||
"\n" split [ dup f-or-"" [ drop ] [ "recepient" get irc-message ] ifte ] each
|
"\n" split [ dup f-or-"" [ drop ] [ "recepient" get irc-message ] ifte ] each
|
||||||
] when ;
|
] when ;
|
||||||
|
@ -112,25 +111,15 @@ USE: unparser
|
||||||
: irc-action-handler ( recepient message -- )
|
: irc-action-handler ( recepient message -- )
|
||||||
" " split1 swap irc-action-quot call ;
|
" " split1 swap irc-action-quot call ;
|
||||||
|
|
||||||
: irc-handle-privmsg ( [ recepient message ] -- )
|
|
||||||
uncons car irc-action-handler ;
|
|
||||||
|
|
||||||
: irc-handle-join ( [ joined channel ] -- )
|
|
||||||
uncons car
|
|
||||||
[
|
|
||||||
dup "nick" get = [
|
|
||||||
"Hi " swap cat2 print
|
|
||||||
] unless
|
|
||||||
] with-irc-stream ;
|
|
||||||
|
|
||||||
: irc-input ( line -- )
|
: irc-input ( line -- )
|
||||||
#! Handle a line of IRC input.
|
#! Handle a line of IRC input.
|
||||||
dup
|
dup
|
||||||
":.+?!.+? PRIVMSG (.+)?:(.+)" groups [
|
" PRIVMSG " split1 nip [
|
||||||
irc-handle-privmsg
|
":" split1 dup [
|
||||||
] when*
|
irc-action-handler
|
||||||
dup ":(.+)!.+ JOIN :(.+)" groups [
|
] [
|
||||||
irc-handle-join
|
drop
|
||||||
|
] ifte
|
||||||
] when*
|
] when*
|
||||||
|
|
||||||
global [ print ] bind ;
|
global [ print ] bind ;
|
||||||
|
@ -148,7 +137,7 @@ USE: unparser
|
||||||
|
|
||||||
: irc ( channels -- )
|
: irc ( channels -- )
|
||||||
irc-register
|
irc-register
|
||||||
! "identify foobar" "NickServ" irc-message
|
"identify foobar" "NickServ" irc-message
|
||||||
[ irc-join ] each
|
[ irc-join ] each
|
||||||
irc-loop ;
|
irc-loop ;
|
||||||
|
|
||||||
|
@ -161,5 +150,3 @@ USE: unparser
|
||||||
"irc.freenode.net" 6667 <client> [
|
"irc.freenode.net" 6667 <client> [
|
||||||
[ "#factor" ] irc
|
[ "#factor" ] irc
|
||||||
] with-stream ;
|
] with-stream ;
|
||||||
|
|
||||||
!! "factor/irc.factor" run-file
|
|
||||||
|
|
|
@ -186,7 +186,6 @@ USE: words
|
||||||
nip
|
nip
|
||||||
] [
|
] [
|
||||||
drop
|
drop
|
||||||
"Forward reference: " write dup .
|
|
||||||
! Remember where we are, and add the reference later
|
! Remember where we are, and add the reference later
|
||||||
dup fixup-word-later
|
dup fixup-word-later
|
||||||
] ifte ;
|
] ifte ;
|
||||||
|
|
|
@ -99,6 +99,9 @@ USE: strings
|
||||||
: resource-path ( -- path )
|
: resource-path ( -- path )
|
||||||
"resource-path" get [ "." ] unless* ;
|
"resource-path" get [ "." ] unless* ;
|
||||||
|
|
||||||
|
: <resource-stream> ( path -- stream )
|
||||||
|
resource-path swap cat2 <filecr> ;
|
||||||
|
|
||||||
: parse-resource ( path -- quot )
|
: parse-resource ( path -- quot )
|
||||||
#! Resources are loaded from the resource-path variable, or
|
#! Resources are loaded from the resource-path variable, or
|
||||||
#! the current directory if it is not set. Words defined in
|
#! the current directory if it is not set. Words defined in
|
||||||
|
@ -106,9 +109,7 @@ USE: strings
|
||||||
#! resource:. This allows words that operate on source
|
#! resource:. This allows words that operate on source
|
||||||
#! files, like "jedit", to use a different resource path
|
#! files, like "jedit", to use a different resource path
|
||||||
#! at run time than was used at parse time.
|
#! at run time than was used at parse time.
|
||||||
"resource:" over cat2
|
"resource:" over cat2 swap <resource-stream> parse-stream ;
|
||||||
swap resource-path swap cat2 <filecr>
|
|
||||||
parse-stream ;
|
|
||||||
|
|
||||||
: run-resource ( file -- )
|
: run-resource ( file -- )
|
||||||
parse-resource call ;
|
parse-resource call ;
|
||||||
|
|
|
@ -10,11 +10,6 @@ USE: test
|
||||||
"<html>&'sgml'"
|
"<html>&'sgml'"
|
||||||
] [ "<html>&'sgml'" chars>entities ] unit-test
|
] [ "<html>&'sgml'" chars>entities ] unit-test
|
||||||
|
|
||||||
[ "Hello world" ]
|
|
||||||
[
|
|
||||||
"Hello world" f html-attr-string
|
|
||||||
] unit-test
|
|
||||||
|
|
||||||
[ "<span style=\"color: #ff00ff; font-family: Monospaced; \">car</span>" ]
|
[ "<span style=\"color: #ff00ff; font-family: Monospaced; \">car</span>" ]
|
||||||
[
|
[
|
||||||
"car"
|
"car"
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
IN: scratchpad
|
||||||
|
USE: namespaces
|
||||||
|
USE: parser
|
||||||
|
USE: stack
|
||||||
|
USE: streams
|
||||||
|
USE: test
|
||||||
|
|
||||||
|
[ 4 ] [ "/library/test/io/no-trailing-eol.factor" run-resource ] unit-test
|
||||||
|
|
||||||
|
: lines-test ( stream -- line1 line2 )
|
||||||
|
dup freadln swap dup freadln swap fclose ;
|
||||||
|
|
||||||
|
[
|
||||||
|
"This is a line."
|
||||||
|
"This is another line."
|
||||||
|
] [
|
||||||
|
"/library/test/io/windows-eol.txt" <resource-stream> lines-test
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[
|
||||||
|
"This is a line."
|
||||||
|
"This is another line."
|
||||||
|
] [
|
||||||
|
"/library/test/io/mac-os-eol.txt" <resource-stream> lines-test
|
||||||
|
] unit-test
|
|
@ -0,0 +1 @@
|
||||||
|
This is a line.
This is another line.
|
|
@ -0,0 +1,2 @@
|
||||||
|
USE: arithmetic
|
||||||
|
2 2 +
|
|
@ -0,0 +1,2 @@
|
||||||
|
This is a line.
|
||||||
|
This is another line.
|
|
@ -77,6 +77,7 @@ USE: unparser
|
||||||
"parse-number"
|
"parse-number"
|
||||||
"prettyprint"
|
"prettyprint"
|
||||||
"inspector"
|
"inspector"
|
||||||
|
"io/io"
|
||||||
"vectors"
|
"vectors"
|
||||||
"words"
|
"words"
|
||||||
"unparser"
|
"unparser"
|
||||||
|
|
|
@ -42,8 +42,6 @@ void init_line_buffer(PORT* port, FIXNUM count)
|
||||||
{
|
{
|
||||||
if(port->line == F)
|
if(port->line == F)
|
||||||
port->line = tag_object(sbuf(LINE_SIZE));
|
port->line = tag_object(sbuf(LINE_SIZE));
|
||||||
else
|
|
||||||
untag_sbuf(port->line)->top = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void primitive_portp(void)
|
void primitive_portp(void)
|
||||||
|
|
|
@ -59,6 +59,10 @@ bool read_line_step(PORT* port)
|
||||||
if(ch == '\n')
|
if(ch == '\n')
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
port->buf_pos = i + 1;
|
||||||
|
port->line_ready = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ch == '\n')
|
if(ch == '\n')
|
||||||
|
@ -110,8 +114,6 @@ void primitive_add_read_line_io_task(void)
|
||||||
|
|
||||||
bool perform_read_line_io_task(PORT* port)
|
bool perform_read_line_io_task(PORT* port)
|
||||||
{
|
{
|
||||||
SBUF* line;
|
|
||||||
|
|
||||||
if(port->buf_pos >= port->buf_fill)
|
if(port->buf_pos >= port->buf_fill)
|
||||||
{
|
{
|
||||||
if(!read_step(port))
|
if(!read_step(port))
|
||||||
|
@ -123,17 +125,14 @@ bool perform_read_line_io_task(PORT* port)
|
||||||
/* EOF */
|
/* EOF */
|
||||||
if(port->line != F)
|
if(port->line != F)
|
||||||
{
|
{
|
||||||
line = untag_sbuf(port->line);
|
if(untag_sbuf(port->line)->top == 0)
|
||||||
if(line->top == 0)
|
|
||||||
port->line = F;
|
port->line = F;
|
||||||
}
|
}
|
||||||
port->line_ready = true;
|
port->line_ready = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return read_line_step(port);
|
return read_line_step(port);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void primitive_read_line_8(void)
|
void primitive_read_line_8(void)
|
||||||
|
|
Loading…
Reference in New Issue