mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-15 02:08:40 -09:00
dir_import.c: Various fixes
- errors in item() didn't propagate properly
- empty [] and {} values weren't allowed
- fractional numbers weren't allowed
- parsing of escaped characters didn't ensure that enough data was in
the buffer
- E() didn't propagate errors properly in all cases
I'll do some more testing later on, but the current code seems to be
working quite well already.
This commit is contained in:
parent
e6eaec30ba
commit
38b2c8f012
1 changed files with 13 additions and 5 deletions
|
|
@ -125,8 +125,9 @@ static int fill(int n) {
|
||||||
|
|
||||||
/* Two macros that break function calling behaviour, but are damn convenient */
|
/* Two macros that break function calling behaviour, but are damn convenient */
|
||||||
#define E(_x, _m) do {\
|
#define E(_x, _m) do {\
|
||||||
if((_x) && !dir_fatalerr) {\
|
if(_x) {\
|
||||||
dir_seterr("Line %d byte %d: %s", ctx->line, ctx->byte, _m);\
|
if(!dir_fatalerr)\
|
||||||
|
dir_seterr("Line %d byte %d: %s", ctx->line, ctx->byte, _m);\
|
||||||
return 1;\
|
return 1;\
|
||||||
}\
|
}\
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
@ -186,6 +187,8 @@ static int cons() {
|
||||||
static int rstring_esc(char **dest, int *destlen) {
|
static int rstring_esc(char **dest, int *destlen) {
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
|
|
||||||
|
C(rfill1);
|
||||||
|
|
||||||
#define ap(c) if(*destlen > 1) { *((*dest)++) = c; (*destlen)--; }
|
#define ap(c) if(*destlen > 1) { *((*dest)++) = c; (*destlen)--; }
|
||||||
switch(*ctx->buf) {
|
switch(*ctx->buf) {
|
||||||
case '"': ap('"'); con(1); break;
|
case '"': ap('"'); con(1); break;
|
||||||
|
|
@ -290,7 +293,7 @@ static int rnum() {
|
||||||
C(rfill1);
|
C(rfill1);
|
||||||
while(1) {
|
while(1) {
|
||||||
C(!*ctx->buf && fill(1));
|
C(!*ctx->buf && fill(1));
|
||||||
if(*ctx->buf == 'e' || *ctx->buf == 'E' || *ctx->buf == '-' || *ctx->buf == '+' || (*ctx->buf >= '0' && *ctx->buf <= '9')) {
|
if(*ctx->buf == 'e' || *ctx->buf == 'E' || *ctx->buf == '-' || *ctx->buf == '+' || *ctx->buf == '.' || (*ctx->buf >= '0' && *ctx->buf <= '9')) {
|
||||||
haschar = 1;
|
haschar = 1;
|
||||||
con(1);
|
con(1);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -341,6 +344,9 @@ static int rval() {
|
||||||
case '{': /* object */
|
case '{': /* object */
|
||||||
con(1);
|
con(1);
|
||||||
while(1) {
|
while(1) {
|
||||||
|
C(cons());
|
||||||
|
if(*ctx->buf == '}')
|
||||||
|
break;
|
||||||
C(rkey(NULL, 0) || rval() || cons());
|
C(rkey(NULL, 0) || rval() || cons());
|
||||||
if(*ctx->buf == '}')
|
if(*ctx->buf == '}')
|
||||||
break;
|
break;
|
||||||
|
|
@ -352,6 +358,9 @@ static int rval() {
|
||||||
case '[': /* array */
|
case '[': /* array */
|
||||||
con(1);
|
con(1);
|
||||||
while(1) {
|
while(1) {
|
||||||
|
C(cons());
|
||||||
|
if(*ctx->buf == ']')
|
||||||
|
break;
|
||||||
C(cons() || rval() || cons());
|
C(cons() || rval() || cons());
|
||||||
if(*ctx->buf == ']')
|
if(*ctx->buf == ']')
|
||||||
break;
|
break;
|
||||||
|
|
@ -409,8 +418,7 @@ static int itemdir(uint64_t dev) {
|
||||||
break;
|
break;
|
||||||
E(*ctx->buf != ',', "Expected ',' or ']'");
|
E(*ctx->buf != ',', "Expected ',' or ']'");
|
||||||
con(1);
|
con(1);
|
||||||
C(cons());
|
C(cons() || item(dev));
|
||||||
item(dev);
|
|
||||||
}
|
}
|
||||||
con(1);
|
con(1);
|
||||||
C(cons());
|
C(cons());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue