Commit 3afa2bb4 authored by Mart Lubbers's avatar Mart Lubbers
Browse files

change readline"

parent 71526f6a
...@@ -23,6 +23,7 @@ instance zero TTYSettings ...@@ -23,6 +23,7 @@ instance zero TTYSettings
TTYclose :: !*TTY !*env -> (!Bool, !*env) TTYclose :: !*TTY !*env -> (!Bool, !*env)
TTYerror :: !*env -> (!String, !*env) TTYerror :: !*env -> (!String, !*env)
TTYopen :: !String !TTYSettings !*env -> (!Bool,!*TTY,!*env) TTYopen :: !String !TTYSettings !*env -> (!Bool,!*TTY,!*env)
TTYread :: !*TTY -> (!Int, !*TTY)
TTYreadline :: !*TTY -> (!String, !*TTY) TTYreadline :: !*TTY -> (!String, !*TTY)
TTYavailable :: !*TTY -> (!Bool, !*TTY) TTYavailable :: !*TTY -> (!Bool, !*TTY)
TTYwrite :: !String !*TTY -> *TTY TTYwrite :: !String !*TTY -> *TTY
implementation module TTY implementation module TTY
import _SystemArray
import StdClass import StdClass
import StdString
import StdChar
import code from "ctty." import code from "ctty."
...@@ -50,11 +53,18 @@ TTYclose _ _ = code { ...@@ -50,11 +53,18 @@ TTYclose _ _ = code {
ccall ttyclose "I:I:A" ccall ttyclose "I:I:A"
} }
TTYreadline :: !*TTY -> (!String, !*TTY) TTYread :: !*TTY -> (!Int, !*TTY)
TTYreadline _ = code { TTYread _ = code {
ccall ttyreadline "I:VSI" ccall ttyread "I:VII"
} }
TTYreadline :: !*TTY -> (!String, !*TTY)
TTYreadline tty = case TTYread tty of
(10, tty) = ("", tty)
(c, tty)
# (rest, tty) = TTYreadline tty
= ({#toChar c} +++ rest, tty)
TTYwrite :: !String !*TTY -> *TTY TTYwrite :: !String !*TTY -> *TTY
TTYwrite _ _ = code { TTYwrite _ _ = code {
ccall ttywrite "SI:I" ccall ttywrite "SI:I"
......
...@@ -146,7 +146,8 @@ void ttyopen(CleanString fn, int baudrate, int bytesize, int parity, ...@@ -146,7 +146,8 @@ void ttyopen(CleanString fn, int baudrate, int bytesize, int parity,
tio.c_cflag &= ~IXON; tio.c_cflag &= ~IXON;
//Set //Set
tio.c_oflag = 0; tio.c_oflag = 0;
tio.c_lflag |= ICANON; tio.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
// tio.c_lflag |= ICANON;
tio.c_cc[VMIN]=5; tio.c_cc[VMIN]=5;
tio.c_cc[VTIME]=0; tio.c_cc[VTIME]=0;
...@@ -173,33 +174,17 @@ void ttyerror(CleanString *result) ...@@ -173,33 +174,17 @@ void ttyerror(CleanString *result)
debug("ttyerror-done"); debug("ttyerror-done");
} }
unsigned long *readlinecl = NULL; void ttyread(int fd, int *ch, int *fdo)
void ttyreadline(int fd, CleanString *result, int *fdo)
{ {
debug("ttyreadline"); debug("ttyread");
size_t bufsize = INITIAL_BUFFERSIZE; unsigned int c;
char *buf = NULL; if(read(fd, &c, 1) == -1){
ssize_t cr, charsread = 0; die("read");
while(buf == NULL || buf[charsread-1] != '\n'){
if((buf = realloc(buf, (bufsize*=2)+1)) == NULL)
die("realloc");
if((cr = read(fd, buf+charsread, bufsize-charsread)) < 0)
die("read");
charsread += cr;
} }
buf[charsread] = '\0'; printf("read: %o\n", c);
*ch = (int)c;
if(readlinecl != NULL)
free(readlinecl);
readlinecl = my_malloc(
sizeof(unsigned long)*CleanStringSizeInts(charsread));
*result = (CleanString) readlinecl;
memcpy(CleanStringCharacters(readlinecl), buf, charsread);
CleanStringLength(readlinecl) = charsread;
*fdo = fd; *fdo = fd;
debug("ttyread done");
free(buf);
debug("ttyreadline-done");
} }
void ttyavailable(int fd, int *r, int *fdo) void ttyavailable(int fd, int *r, int *fdo)
...@@ -223,7 +208,11 @@ void ttyavailable(int fd, int *r, int *fdo) ...@@ -223,7 +208,11 @@ void ttyavailable(int fd, int *r, int *fdo)
int ttywrite(CleanString s, int fd) int ttywrite(CleanString s, int fd)
{ {
debug("ttywrite"); debug("ttywrite");
write(fd, CleanStringCharacters(s), CleanStringLength(s)); for(int i = 0; i< CleanStringLength(s); i++){
unsigned char c = ((unsigned char*)CleanStringCharacters(s))[i];
printf("%02x(%u) ", c, c);
}
write(fd, (void *)CleanStringCharacters(s), CleanStringLength(s));
tcdrain(fd); tcdrain(fd);
debug("ttywrite-done"); debug("ttywrite-done");
return fd; return fd;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment