mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-23 10:30:16 +00:00
Track line number for error reports
This commit is contained in:
parent
46120e84c4
commit
a74444af28
@ -88,7 +88,7 @@ void process(FILE *f) {
|
||||
}
|
||||
|
||||
if (jp->error != NULL) {
|
||||
fprintf(stderr, "%s\n", jp->error);
|
||||
fprintf(stderr, "%d: %s\n", jp->line, jp->error);
|
||||
}
|
||||
}
|
||||
|
||||
|
25
jsonpull.c
25
jsonpull.c
@ -9,19 +9,24 @@ typedef enum json_expect {
|
||||
JSON_ITEM, JSON_COMMA, JSON_COLON, JSON_KEY, JSON_VALUE,
|
||||
} json_expect;
|
||||
|
||||
static int read_file(json_pull *p) {
|
||||
return fgetc(p->source);
|
||||
static int read_file(json_pull *j) {
|
||||
int c = fgetc(j->source);
|
||||
if (c == '\n') {
|
||||
j->line++;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static int peek_file(json_pull *p) {
|
||||
int c = getc(p->source);
|
||||
ungetc(c, p->source);
|
||||
static int peek_file(json_pull *j) {
|
||||
int c = getc(j->source);
|
||||
ungetc(c, j->source);
|
||||
return c;
|
||||
}
|
||||
|
||||
json_pull *json_begin_file(FILE *f) {
|
||||
json_pull *j = malloc(sizeof(json_pull));
|
||||
j->container = NULL;
|
||||
j->line = 1;
|
||||
|
||||
j->read = read_file;
|
||||
j->peek = peek_file;
|
||||
@ -30,14 +35,17 @@ json_pull *json_begin_file(FILE *f) {
|
||||
return j;
|
||||
}
|
||||
|
||||
static int read_string(json_pull *p) {
|
||||
char *cp = p->source;
|
||||
static int read_string(json_pull *j) {
|
||||
char *cp = j->source;
|
||||
if (*cp == '\0') {
|
||||
return EOF;
|
||||
}
|
||||
int c = (unsigned char) *cp;
|
||||
cp++;
|
||||
p->source = cp;
|
||||
j->source = cp;
|
||||
if (c == '\n') {
|
||||
j->line++;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -52,6 +60,7 @@ static int peek_string(json_pull *p) {
|
||||
json_pull *json_begin_string(char *s) {
|
||||
json_pull *j = malloc(sizeof(json_pull));
|
||||
j->container = NULL;
|
||||
j->line = 1;
|
||||
|
||||
j->read = read_string;
|
||||
j->peek = peek_string;
|
||||
|
@ -24,6 +24,7 @@ struct json_pull {
|
||||
int (*read)(struct json_pull *);
|
||||
int (*peek)(struct json_pull *);
|
||||
void *source;
|
||||
int line;
|
||||
};
|
||||
typedef struct json_pull json_pull;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user