From: Nils Faerber Date: Sat, 6 Jul 2013 21:11:49 +0000 (+0200) Subject: Handle newline X-Git-Url: https://git.karo-electronics.de/?p=oswald.git;a=commitdiff_plain;h=8d5205584b7db9a3edd298af2d2061f7f3f66403 Handle newline --- diff --git a/linux-bt/l2cap_client.c b/linux-bt/l2cap_client.c index a3fb782..3c427b4 100644 --- a/linux-bt/l2cap_client.c +++ b/linux-bt/l2cap_client.c @@ -15,12 +15,54 @@ #include #include +typedef enum { + CMD_NULL = 0, + CMD_INVAL, + CMD_QUIT, +} cmd_t; + +// replace "markups" with appropr. chars +char *parse_buffer(char *inbuf, int *cmd) +{ + int i,o; + static char outbuf[240]; + + memset(outbuf,0,240); + + *cmd = CMD_NULL; + + // if a line starts with a \ then it is an internal command + if (inbuf[0] == '\\') { + switch (inbuf[1]) { + case 'q': + *cmd = CMD_QUIT; + break; + default: + *cmd = CMD_INVAL; + break; + } + return NULL; + } + o=0; + for (i=0; i 0) { - status = write(s, buf, len); - if (status < 0) - perror("write"); - fsync(s); + // status = write(s, buf, len); + out = parse_buffer(buf, &cmd); + if (cmd != CMD_NULL) { + if (cmd == CMD_QUIT) { + close(s); + exit(0); + } + } else { + len = strlen(out); + status = write(s, out, len); + if (status < 0) + perror("write"); + fsync(s); + } } } else if (FD_ISSET(s, &infds)) { len = read(s, buf, 240);