From 5861513364e18dbcbcb3fea307ac1df8bae578b9 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 8 Jun 2014 16:09:24 +0300 Subject: HTML: Write cylinder data to the JSON files. Iterate the cylinders in each dive and write cylinders data to the exported JSON files. Moving the write attribute function to the top of the file. Signed-off-by: Gehad elrobey Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- save-html.c | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) (limited to 'save-html.c') diff --git a/save-html.c b/save-html.c index 61c453d88..e77f79a43 100644 --- a/save-html.c +++ b/save-html.c @@ -2,6 +2,48 @@ #include "gettext.h" #include "stdio.h" +void write_attribute(struct membuffer *b, const char *att_name, const char *value) +{ + if (!value) + value = "--"; + put_format(b, "\"%s\":\"", att_name); + put_HTML_quoted(b, value); + put_string(b, "\","); +} + +static void put_cylinder_HTML(struct membuffer *b, struct dive *dive) +{ + int i, nr; + + nr = nr_cylinders(dive); + + put_string(b, "\"Cylinders\":["); + + for (i = 0; i < nr; i++) { + cylinder_t *cylinder = dive->cylinder + i; + put_string(b, "{"); + write_attribute(b, "Type", cylinder->type.description); + if (cylinder->type.size.mliter) { + put_milli(b, "\"Size\":\"", cylinder->type.size.mliter, " l\","); + } else { + write_attribute(b, "Size", "--"); + } + put_pressure(b, cylinder->type.workingpressure, "\"WPressure\":\"", " bar\","); + put_pressure(b, cylinder->start, "\"SPressure\":\"", " bar\","); + put_pressure(b, cylinder->end, "\"EPressure\":\"", " bar\","); + + if (cylinder->gasmix.o2.permille) { + put_format(b, "\"O2\":\"%u.%u%%\",", FRACTION(cylinder->gasmix.o2.permille, 10)); + } else { + write_attribute(b, "O2", "--"); + } + put_string(b, "},"); + } + + put_string(b, "],"); +} + + void put_HTML_samples(struct membuffer *b, struct dive *dive) { int i; @@ -90,15 +132,6 @@ 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\":\"", att_name); - put_HTML_quoted(b, value); - put_string(b, "\","); -} - void write_one_dive(struct membuffer *b, struct dive *dive, int *dive_no) { put_string(b, "{"); @@ -118,6 +151,7 @@ void write_one_dive(struct membuffer *b, struct dive *dive, int *dive_no) write_attribute(b, "suit", dive->suit); put_HTML_tags(b, dive, "\"tags\":", ","); put_HTML_notes(b, dive, "\"notes\":\"", "\","); + put_cylinder_HTML(b, dive); put_HTML_samples(b, dive); put_string(b, "},\n"); (*dive_no)++; -- cgit v1.2.3-70-g09d2