projects
/
smouse
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
foo
[smouse]
/
src
/
unix
/
serial.c
diff --git
a/src/unix/serial.c
b/src/unix/serial.c
index
fe8aeb3
..
cdcdb88
100644
(file)
--- a/
src/unix/serial.c
+++ b/
src/unix/serial.c
@@
-137,7
+137,6
@@
char *ser_getline(int fd, char *buf, int bsz)
static char linebuf[512];
static int widx;
int i, rd, size;
static char linebuf[512];
static int widx;
int i, rd, size;
- char *ptr;
size = sizeof linebuf - widx;
while(size && (rd = read(fd, linebuf + widx, size)) > 0) {
size = sizeof linebuf - widx;
while(size && (rd = read(fd, linebuf + widx, size)) > 0) {
@@
-145,27
+144,28
@@
char *ser_getline(int fd, char *buf, int bsz)
size -= rd;
}
size -= rd;
}
- ptr = linebuf;
for(i=0; i<widx; i++) {
for(i=0; i<widx; i++) {
- if(*ptr == '\r' || *ptr == '\n') {
- *ptr++ = '\n';
- if(i < widx - 1 && ptr[1] == '\n') {
- *ptr++ = 0;
- }
-
- size = widx >= bsz ? bsz - 1 : widx;
+ if(linebuf[i] == '\r' || linebuf[i] == '\n') {
+ size = i >= bsz ? bsz - 1 : i;
memcpy(buf, linebuf, size);
buf[size] = 0;
memcpy(buf, linebuf, size);
buf[size] = 0;
- memmove(linebuf, linebuf + widx, sizeof linebuf - widx);
+ memmove(linebuf, linebuf + i + 1, sizeof linebuf - i - 1);
+ printf("ser_getline-> \"%s\"\n", buf);
return buf;
return buf;
- } else {
- ++ptr;
}
}
return 0;
}
}
}
return 0;
}
+char *ser_getline_block(int fd, char *buf, int bsz)
+{
+ if(!ser_wait(fd, -1)) {
+ return 0;
+ }
+ return ser_getline(fd, buf, bsz);
+}
+
static int baud_id(int baud)
{
switch(baud) {
static int baud_id(int baud)
{
switch(baud) {