From ecb5e15dabf26ab3d5eb6548acd67ea6441a2a78 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Wed, 28 May 2014 14:43:57 +0300 Subject: Fix json exporter output The note is prefixed by a colon Fix the output of Null values of dive master, dive suit, location and buddy. Signed-off-by: Gehad elrobey Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- save-html.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/save-html.c b/save-html.c index e2222b3f6..8f16fdfe8 100644 --- a/save-html.c +++ b/save-html.c @@ -59,7 +59,7 @@ void put_HTML_notes(struct membuffer *b, struct dive *dive, const char *pre, con { if (dive->notes) { char *notes = quote(dive->notes); - put_format(b, "%s: %s %s", pre, notes, post); + put_format(b, "%s%s%s", pre, notes, post); free(notes); } } @@ -101,6 +101,10 @@ void put_HTML_tags(struct membuffer *b, struct dive *dive, const char *pre, cons { put_string(b, pre); struct tag_entry *tag = dive->tag_list; + + if (!tag) + put_string(b, "--"); + while(tag){ put_format(b, "%s ", tag->tag->name); tag = tag->next; @@ -108,6 +112,13 @@ void put_HTML_tags(struct membuffer *b, struct dive *dive, const char *pre, cons put_string(b, post); } +void write_attribute(struct membuffer *b, const char *att_name, const char *value) +{ + if(!value) + value="--"; + put_format(b, "\"%s\":\"%s\",", att_name, value); +} + void write_one_dive(struct membuffer *b, struct dive *dive, int *dive_no) { put_string(b, "{"); @@ -115,16 +126,16 @@ void write_one_dive(struct membuffer *b, struct dive *dive, int *dive_no) put_format(b, "\"subsurface_number\":%d,", dive->number); put_HTML_date(b, dive, "\"date\":\"", "\","); put_HTML_time(b, dive, "\"time\":\"", "\","); - put_format(b, "\"location\":\"%s\",", dive->location); + write_attribute(b, "location", dive->location); put_format(b, "\"rating\":%d,", dive->rating); put_format(b, "\"visibility\":%d,", dive->visibility); put_string(b, "\"temperature\":{"); put_HTML_airtemp(b, dive, "\"air\":\"", "\","); put_HTML_watertemp(b, dive, "\"water\":\"", "\","); put_string(b, " },"); - put_format(b, "\"buddy\":\"%s\",", dive->buddy); - put_format(b, "\"divemaster\":\"%s\",", dive->divemaster); - put_format(b, "\"suit\":\"%s\",", dive->suit); + write_attribute(b, "buddy", dive->buddy); + write_attribute(b, "divemaster", dive->divemaster); + write_attribute(b, "suit", dive->suit); put_HTML_tags(b, dive, "\"tags\":\"", "\","); put_HTML_notes(b, dive ,"\"notes\":\"" ,"\","); put_string(b, "},\n"); -- cgit v1.2.3-70-g09d2