ispell is working
This commit is contained in:
parent
931f3652e8
commit
da202786ec
|
@ -32,8 +32,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
WITH REGARD TO THIS SOFTWARE.
|
WITH REGARD TO THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define CONSOLE_DEBUG 1
|
|
||||||
|
|
||||||
UxnSubprocess children[CONSOLE_MAX_CHILDREN];
|
UxnSubprocess children[CONSOLE_MAX_CHILDREN];
|
||||||
static char *fork_args[4] = {"/bin/sh", "-c", "", NULL};
|
static char *fork_args[4] = {"/bin/sh", "-c", "", NULL};
|
||||||
static int to_child_fd[2], from_child_fd[2];
|
static int to_child_fd[2], from_child_fd[2];
|
||||||
|
@ -173,9 +171,12 @@ std_put(Uint8 c, FILE *fd)
|
||||||
static void
|
static void
|
||||||
proc_put(Uxn *u, Uint8 *d)
|
proc_put(Uxn *u, Uint8 *d)
|
||||||
{
|
{
|
||||||
Uint8 c = d[0x2];
|
Uint8 c = d[0xa];
|
||||||
int n = d[0xe] & 0x3;
|
int n = d[0xe] & 0x3;
|
||||||
|
if (CONSOLE_DEBUG)
|
||||||
|
fprintf(stderr, " fd %d: write %02x\n", children[n].fd_in, c);
|
||||||
write(children[n].fd_in, &c, 1);
|
write(children[n].fd_in, &c, 1);
|
||||||
|
fdatasync(children[n].fd_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -304,6 +305,7 @@ int
|
||||||
console_input(Uxn *u, int port, char c, int type)
|
console_input(Uxn *u, int port, char c, int type)
|
||||||
{
|
{
|
||||||
Uint8 *d = &u->dev[0x10];
|
Uint8 *d = &u->dev[0x10];
|
||||||
|
d[0x2] = d[0x4] = d[0x5] = 0;
|
||||||
d[port] = c;
|
d[port] = c;
|
||||||
d[0x7] = type;
|
d[0x7] = type;
|
||||||
return uxn_eval(u, PEEK2(d));
|
return uxn_eval(u, PEEK2(d));
|
||||||
|
|
|
@ -11,6 +11,8 @@ WITH REGARD TO THIS SOFTWARE.
|
||||||
|
|
||||||
#define CONSOLE_VERSION 1
|
#define CONSOLE_VERSION 1
|
||||||
|
|
||||||
|
#define CONSOLE_DEBUG 0
|
||||||
|
|
||||||
#define CONSOLE_NONE 0x00
|
#define CONSOLE_NONE 0x00
|
||||||
#define CONSOLE_STDIN 0x01
|
#define CONSOLE_STDIN 0x01
|
||||||
#define CONSOLE_ARG 0x02
|
#define CONSOLE_ARG 0x02
|
||||||
|
|
17
src/uxncli.c
17
src/uxncli.c
|
@ -50,12 +50,18 @@ handle_input(Uxn *u, int fd, int port, int argdata, int argend)
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
int n = read(fd, &buf, 32);
|
int n = read(fd, &buf, 32);
|
||||||
if(n == 0)
|
if(n == 0) {
|
||||||
|
if(CONSOLE_DEBUG)
|
||||||
|
fprintf(stderr, " fd %d: closed\n", fd);
|
||||||
console_input(u, port, 0x00, argend);
|
console_input(u, port, 0x00, argend);
|
||||||
else
|
} else {
|
||||||
for(int i = 0; i < n; i++)
|
for(int i = 0; i < n; i++) {
|
||||||
|
if(CONSOLE_DEBUG)
|
||||||
|
fprintf(stderr, " fd %d: read %02x\n", fd, buf[i]);
|
||||||
console_input(u, port, buf[i], argdata);
|
console_input(u, port, buf[i], argdata);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
init_rfds(fd_set *rfds)
|
init_rfds(fd_set *rfds)
|
||||||
|
@ -68,11 +74,8 @@ init_rfds(fd_set *rfds)
|
||||||
UxnSubprocess *child = get_child(i);
|
UxnSubprocess *child = get_child(i);
|
||||||
int fd = child->fd_out;
|
int fd = child->fd_out;
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
/* printf("ok: %d/%d (%d, %d)\n", i, child->id, fd, child->pid); */
|
|
||||||
FD_SET(fd, rfds);
|
FD_SET(fd, rfds);
|
||||||
if (fd >= nfds) nfds = fd + 1;
|
if (fd >= nfds) nfds = fd + 1;
|
||||||
/* } else { */
|
|
||||||
/* printf("nope: %d/%d (%d, %d)\n", i, child->id, fd, child->pid); */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nfds;
|
return nfds;
|
||||||
|
@ -87,7 +90,7 @@ emu_run(Uxn *u)
|
||||||
while(!u->dev[0x0f]) {
|
while(!u->dev[0x0f]) {
|
||||||
int nfds = init_rfds(&rfds);
|
int nfds = init_rfds(&rfds);
|
||||||
/* tv.tv_sec = 0; */
|
/* tv.tv_sec = 0; */
|
||||||
tv.tv_sec = 1;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 1000;
|
tv.tv_usec = 1000;
|
||||||
int retval = select(nfds, &rfds, NULL, NULL, &tv);
|
int retval = select(nfds, &rfds, NULL, NULL, &tv);
|
||||||
if(retval > 0) {
|
if(retval > 0) {
|
||||||
|
|
136
test/ispell.tal
136
test/ispell.tal
|
@ -1,107 +1,85 @@
|
||||||
|
( ispell.tal )
|
||||||
|
( )
|
||||||
|
( note that this is not a production spell-checker and is currently )
|
||||||
|
( kind of brittle in the same ways as `ispell -a` on raw input )
|
||||||
|
|
||||||
|10 @Console [
|
|10 @Console [
|
||||||
&vector $2 &stdin $1 &pad1 $1 &proc-get $1 &host-get $1 &pad2 $1 &type $1
|
&vector $2 &stdin $1 &pad1 $1 &proc-get $1 &host-get $1 &pad2 $1 &type $1
|
||||||
&stdout $1 &stderr $1 &proc-put $1 &pad3 $1 ¶m $2 &opts $1 &host-put $1
|
&stdout $1 &stderr $1 &proc-put $1 &pad3 $1 ¶m $2 &opts $1 &host-put $1
|
||||||
]
|
]
|
||||||
|
|
||||||
|0000
|
|0000
|
||||||
@word-buf $100
|
@ready $1 ( ; are we ready? or still reading ispell startup banner? )
|
||||||
@word-pos $2
|
@correct $1 ( ; was the last word spelled ok? )
|
||||||
@spelled-ok $1 ( ; was the last word spelled ok? )
|
|
||||||
@resume $2 ( ; if set should have effect ` -- BRK` )
|
|
||||||
|
|
||||||
|0100 ( -> BRK )
|
|0100 ( -> BRK )
|
||||||
;on-console-init .Console/vector DEO2 ( ; set up console vector callback )
|
;on-console-read .Console/vector DEO2 ( ; set up console vector callback )
|
||||||
init-ispell ( ; set up ispell child process )
|
word-reset ( ; initialize word buffer )
|
||||||
word-reset BRK
|
#31 .Console/opts DEO ( ; child 1: write child.in, read child.out )
|
||||||
|
|
||||||
@init-ispell ( -- )
|
|
||||||
LIT "! print
|
|
||||||
#31 .Console/opts DEO ( ; child 1: write to stdin, read from stdout )
|
|
||||||
;ispell-cmd .Console/param DEO2 ( ; set up `ispell -a` to run )
|
;ispell-cmd .Console/param DEO2 ( ; set up `ispell -a` to run )
|
||||||
#01 .Console/host-put DEO JMP2r ( ; run the command now and return )
|
#01 .Console/host-put DEO BRK ( ; run the command now and return )
|
||||||
|
|
||||||
@on-console-init ( -- BRK )
|
|
||||||
( LIT "? print )
|
|
||||||
.Console/type DEI #21 EQU ?{ LIT "u print BRK } ( ; 0x21 signals input from child 1 )
|
|
||||||
( LIT ". print )
|
|
||||||
( .Console/proc-get DEI emit/byte )
|
|
||||||
.Console/proc-get DEI #0a EQU ?{ BRK } ( ; skip ispell's one line banner )
|
|
||||||
LIT "> print
|
|
||||||
;on-console-read .Console/vector DEO2 ( ; finished banner, checker is ready )
|
|
||||||
BRK
|
|
||||||
|
|
||||||
@word-reset ( -> )
|
@word-reset ( -> )
|
||||||
;word-buf ;word-pos STA2 ( ; reset word-pos pointer )
|
;word-buf ;word-pos STA2 ( ; reset word-pos pointer )
|
||||||
#00 ;word-buf STA JMP2r ( ; write zero into word buffer )
|
#00 ;word-buf STA JMP2r ( ; write zero into word buffer )
|
||||||
|
|
||||||
@on-console-read
|
|
||||||
LIT ", print
|
|
||||||
( .Console/type emit/byte )
|
|
||||||
.Console/type DEI #21 EQU ?on-ispell-input
|
|
||||||
.Console/type DEI #01 EQU ?on-stdin
|
|
||||||
BRK
|
|
||||||
|
|
||||||
@on-stdin
|
|
||||||
.Console/stdin DEI DUP #0a NEQ ?word-append
|
|
||||||
POP ;word-buf ;finish !check-spelling
|
|
||||||
|
|
||||||
@on-ispell-input ( -> BRK )
|
|
||||||
LIT "i print
|
|
||||||
.Console/proc-get DEI emit/byte
|
|
||||||
.Console/proc-get DEI LIT "* EQU ( ; line starting with "*" means ok )
|
|
||||||
.spelled-ok STZ ( ; store spelling result )
|
|
||||||
LIT "- print LIT "0 .spelled-ok LDZ ADD print
|
|
||||||
#00 ,on-ispell-drain/done STR ( ; drain two lines )
|
|
||||||
;on-ispell-drain .Console/vector DEO2 ( ; ignore rest of line )
|
|
||||||
BRK
|
|
||||||
|
|
||||||
@word-append ( c^ -> BRK )
|
@word-append ( c^ -> BRK )
|
||||||
LIT "% print
|
|
||||||
DUP print
|
|
||||||
;word-pos LDA2 STA ( ; pos<-c )
|
;word-pos LDA2 STA ( ; pos<-c )
|
||||||
;word-pos LDA2 INC2 ;word-pos STA2 ( ; pos<-pos+1 )
|
;word-pos LDA2 INC2 ;word-pos STA2 ( ; pos<-pos+1 )
|
||||||
#00 ;word-pos LDA2 STA BRK ( ; pos<-00 )
|
#00 ;word-pos LDA2 STA BRK ( ; pos<-00 )
|
||||||
|
|
||||||
@finish ( -> BRK )
|
@on-console-read
|
||||||
LIT "f print
|
.Console/type DEI ( ; what kind of input is this? )
|
||||||
LIT "0 .spelled-ok LDZ ADD println
|
DUP #21 NEQ ?{ POP !on-ispell-input } ( ; input from ispell process )
|
||||||
LIT "> print
|
DUP #01 NEQ ?{ POP !on-stdin } ( ; input from stdin, i.e. user )
|
||||||
word-reset BRK
|
POP BRK ( ; otherwise skip )
|
||||||
|
|
||||||
@ispell-cmd "ispell 20 "-a 00 ( ; "ispell -a" )
|
@on-stdin
|
||||||
|
.Console/stdin DEI #0a EQU ?check ( ; if newline, check spelling )
|
||||||
|
.Console/stdin DEI DUP !word-append ( ; if not newline, append to buffer )
|
||||||
|
|
||||||
@on-ispell-drain ( -- BRK )
|
@on-ispell-input ( -> BRK )
|
||||||
LIT "d print
|
.ready LDZ ?{ !on-console-init } ( ; if not ready, parse ispell banner )
|
||||||
|
.Console/proc-get DEI LIT "* EQU ( ; line starting with "*" means ok )
|
||||||
|
.Console/proc-get DEI LIT "+ EQU ORA ( ; line starting with "+" means ok too )
|
||||||
|
.correct STZ ( ; store spelling result )
|
||||||
|
#20 print ( ; print a space )
|
||||||
|
LIT "0 .correct LDZ ADD println ( ; print 1 if ok, 0 otherwise )
|
||||||
|
#00 ;on-ispell-drain/done STA ( ; drain two lines )
|
||||||
|
;on-ispell-drain .Console/vector DEO2 ( ; ignore rest of line )
|
||||||
|
BRK
|
||||||
|
|
||||||
|
@on-console-init ( -- BRK )
|
||||||
|
.Console/proc-get DEI #0a EQU ?{ BRK } ( ; skip ispell's one line banner )
|
||||||
|
#01 .ready STZ ( ; after newline we are ready )
|
||||||
|
LIT "> print BRK ( ; print simple prompt and return )
|
||||||
|
|
||||||
|
@on-ispell-drain ( -> BRK )
|
||||||
.Console/type DEI #21 EQU ?{ BRK } ( ; 0x21 signals input from child 1 )
|
.Console/type DEI #21 EQU ?{ BRK } ( ; 0x21 signals input from child 1 )
|
||||||
.Console/proc-get DEI #0a EQU ?{ BRK } ( ; skip ispell's outupt )
|
.Console/proc-get DEI #0a EQU ?{ BRK } ( ; skip ispell's outupt )
|
||||||
LIT [ &done $1 ] ?{ ( ; is this the second newline? )
|
LIT &done $1 ?{ #01 ,&done STR BRK } ( ; only exit if second newline )
|
||||||
#01 ,on-ispell-drain/done STR BRK ( ; no, but next one will be. )
|
|
||||||
}
|
|
||||||
;on-console-read .Console/vector DEO2 ( ; drain finished, checker is ready )
|
;on-console-read .Console/vector DEO2 ( ; drain finished, checker is ready )
|
||||||
;resume LDA2 JMP2 ( ; resume whatever we wanted to do after checking )
|
word-reset LIT "> print BRK ( ; reset buffer, print prompt, return )
|
||||||
|
|
||||||
@check-spelling ( word* continue* -- BRK )
|
@check ( word* -> BRK )
|
||||||
LIT "$ print
|
.ready LDZ ?{ !check-not-ready }
|
||||||
;resume STA2 ( ; write continuation to resume )
|
;word-buf #01 .Console/opts DEO ( ; prepare buffer, act on child 1 )
|
||||||
#01 .Console/opts DEO ( ; act on child 1 )
|
&loop LDAk ?{ POP2 #0a send BRK } ( ; when we read \0 we are done )
|
||||||
LIT "< print
|
LDAk DUP print send INC2 !&loop ( ; send byte to child 1 and loop )
|
||||||
&loop LIT ": print LDAk ( #00 NEQ ) ?{
|
|
||||||
POP2
|
|
||||||
"> print
|
|
||||||
#0a .Console/proc-put DEO BRK
|
|
||||||
} ( ; when we read \0 we are done )
|
|
||||||
LDAk print
|
|
||||||
LDAk .Console/proc-put DEO INC2 !&loop ( ; send byte to child 1 and loop )
|
|
||||||
|
|
||||||
@print
|
@check-not-ready
|
||||||
.Console/stdout DEO JMP2r
|
#20 print LIT "? println ( ; print " ?\n" )
|
||||||
|
word-reset LIT "> print BRK ( ; reset the buffer, print prompt, return )
|
||||||
|
|
||||||
@println
|
@send ( c^ -> )
|
||||||
.Console/stdout DEO #0a .Console/stdout DEO JMP2r
|
.Console/proc-put DEO JMP2r ( ; send character to ispell process )
|
||||||
|
|
||||||
@emit
|
@print ( c^ -> )
|
||||||
&long SWP2 ,&short JSR
|
.Console/stdout DEO JMP2r ( ; send character to stdout )
|
||||||
&short SWP ,&byte JSR
|
|
||||||
&byte DUP #04 SFT ,&char JSR
|
@println ( c^ -> )
|
||||||
&char #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
|
print #0a .Console/stdout DEO JMP2r ( ; send character and newline to stdout )
|
||||||
JMP2r
|
|
||||||
|
@ispell-cmd "ispell 20 "-a 00 ( ; "ispell -a" )
|
||||||
|
@word-pos $2 ( ; position in word-buf )
|
||||||
|
@word-buf $100 ( ; buffer for input characters )
|
||||||
|
|
Loading…
Reference in New Issue