Think I nailed it?
This commit is contained in:
parent
cbd7bf625b
commit
b24b0f33d2
1 changed files with 14 additions and 8 deletions
22
main.c
22
main.c
|
@ -40,6 +40,9 @@
|
||||||
#define ZX_CHAR_TOKEN_HIGH(c) \
|
#define ZX_CHAR_TOKEN_HIGH(c) \
|
||||||
(c >= 0xc0)
|
(c >= 0xc0)
|
||||||
|
|
||||||
|
#define ZX_CHAR_TOKEN(c) \
|
||||||
|
(ZX_CHAR_TOKEN_LOW(c) || ZX_CHAR_TOKEN_HIGH(c))
|
||||||
|
|
||||||
#define ZX_BASIC_STATE_LEN 116
|
#define ZX_BASIC_STATE_LEN 116
|
||||||
|
|
||||||
#define ZX_CHAR_TOKEN_INTEGRAL(c) \
|
#define ZX_CHAR_TOKEN_INTEGRAL(c) \
|
||||||
|
@ -268,7 +271,7 @@ static ssize_t zx_dump_basic(int fd) {
|
||||||
while (1) {
|
while (1) {
|
||||||
ssize_t readlen, len, i;
|
ssize_t readlen, len, i;
|
||||||
zx_basic_line line;
|
zx_basic_line line;
|
||||||
uint8_t last = 0;
|
uint8_t last = 0xc0;
|
||||||
|
|
||||||
if ((readlen = read(fd, &line, sizeof(line))) < 0) {
|
if ((readlen = read(fd, &line, sizeof(line))) < 0) {
|
||||||
goto error_io;
|
goto error_io;
|
||||||
|
@ -276,27 +279,30 @@ static ssize_t zx_dump_basic(int fd) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
len = le16toh(line.len);
|
||||||
|
|
||||||
|
if (be16toh(line.num) == len) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (printf("%d", (int)be16toh(line.num)) < 0) {
|
if (printf("%d", (int)be16toh(line.num)) < 0) {
|
||||||
goto error_io;
|
goto error_io;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = le16toh(line.len);
|
|
||||||
|
|
||||||
if (read(fd, buf, len) < 0) {
|
if (read(fd, buf, len) < 0) {
|
||||||
goto error_io;
|
goto error_io;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<len; i++) {
|
for (i=0; i<len; i++) {
|
||||||
uint8_t c = ((uint8_t *)buf)[i];
|
uint8_t c = ((uint8_t *)buf)[i];
|
||||||
|
int token = ZX_CHAR_TOKEN(c),
|
||||||
|
token_last = ZX_CHAR_TOKEN(last);
|
||||||
|
|
||||||
if (ZX_CHAR_TOKEN_LOW(c) || ZX_CHAR_TOKEN_HIGH(c)
|
if (token || token_last) {
|
||||||
|| ZX_CHAR_TOKEN_LOW(last) || ZX_CHAR_TOKEN_HIGH(last)) {
|
|
||||||
if (putchar(' ') < 0) {
|
if (putchar(' ') < 0) {
|
||||||
goto error_io;
|
goto error_io;
|
||||||
}
|
}
|
||||||
}
|
} else if (ZX_CHAR_TOKEN_INTEGRAL(c) || ZX_CHAR_TOKEN_FLOAT(c)) {
|
||||||
|
|
||||||
if (ZX_CHAR_TOKEN_INTEGRAL(c) || ZX_CHAR_TOKEN_FLOAT(c)) {
|
|
||||||
i += 5;
|
i += 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue