| 
									
										
										
										
											2017-04-27 20:18:03 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2017-03-11 22:08:31 +02:00
										 |  |  | #ifdef __clang__
 | 
					
						
							| 
									
										
										
										
											2016-03-09 15:19:22 -03:00
										 |  |  | // Clang has a bug on zero-initialization of C structs.
 | 
					
						
							|  |  |  | #pragma clang diagnostic ignored "-Wmissing-field-initializers"
 | 
					
						
							| 
									
										
										
										
											2017-03-11 22:08:31 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-03-09 15:19:22 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | #include "save-html.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-21 06:37:24 -07:00
										 |  |  | #include "qthelperfromc.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | #include "gettext.h"
 | 
					
						
							| 
									
										
										
										
											2014-06-08 07:56:54 +03:00
										 |  |  | #include "stdio.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | void write_attribute(struct membuffer *b, const char *att_name, const char *value, const char *separator) | 
					
						
							| 
									
										
										
										
											2014-06-08 16:09:24 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (!value) | 
					
						
							|  |  |  | 		value = "--"; | 
					
						
							|  |  |  | 	put_format(b, "\"%s\":\"", att_name); | 
					
						
							|  |  |  | 	put_HTML_quoted(b, value); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	put_format(b, "\"%s", separator); | 
					
						
							| 
									
										
										
										
											2014-06-08 16:09:24 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-13 23:36:35 +02:00
										 |  |  | void save_photos(struct membuffer *b, const char *photos_dir, struct dive *dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct picture *pic = dive->picture_list; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!pic) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	char *separator = "\"photos\":["; | 
					
						
							|  |  |  | 	do { | 
					
						
							|  |  |  | 		put_string(b, separator); | 
					
						
							|  |  |  | 		separator = ", "; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:55:40 -07:00
										 |  |  | 		char *fname = get_file_name(local_file_path(pic)); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		put_format(b, "{\"filename\":\"%s\"}", fname); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:55:40 -07:00
										 |  |  | 		copy_image_and_overwrite(local_file_path(pic), photos_dir, fname); | 
					
						
							| 
									
										
										
										
											2014-08-17 10:42:47 -07:00
										 |  |  | 		free(fname); | 
					
						
							| 
									
										
										
										
											2014-07-13 23:36:35 +02:00
										 |  |  | 		pic = pic->next; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	} while (pic); | 
					
						
							| 
									
										
										
										
											2014-07-13 23:36:35 +02:00
										 |  |  | 	put_string(b, "],"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-23 22:22:24 +03:00
										 |  |  | void write_divecomputers(struct membuffer *b, struct dive *dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	put_string(b, "\"divecomputers\":["); | 
					
						
							|  |  |  | 	struct divecomputer *dc; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	char *separator = ""; | 
					
						
							|  |  |  | 	for_each_dc (dive, dc) { | 
					
						
							|  |  |  | 		put_string(b, separator); | 
					
						
							|  |  |  | 		separator = ", "; | 
					
						
							| 
									
										
										
										
											2014-08-23 22:22:24 +03:00
										 |  |  | 		put_format(b, "{"); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		write_attribute(b, "model", dc->model, ", "); | 
					
						
							| 
									
										
										
										
											2014-08-23 22:22:24 +03:00
										 |  |  | 		if (dc->deviceid) | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 			put_format(b, "\"deviceid\":\"%08x\", ", dc->deviceid); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			put_string(b, "\"deviceid\":\"--\", "); | 
					
						
							| 
									
										
										
										
											2014-08-23 22:22:24 +03:00
										 |  |  | 		if (dc->diveid) | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 			put_format(b, "\"diveid\":\"%08x\" ", dc->diveid); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			put_string(b, "\"diveid\":\"--\" "); | 
					
						
							|  |  |  | 		put_format(b, "}"); | 
					
						
							| 
									
										
										
										
											2014-08-23 22:22:24 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	put_string(b, "],"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-11 03:26:21 +02:00
										 |  |  | void write_dive_status(struct membuffer *b, struct dive *dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	put_format(b, "\"sac\":\"%d\",", dive->sac); | 
					
						
							|  |  |  | 	put_format(b, "\"otu\":\"%d\",", dive->otu); | 
					
						
							|  |  |  | 	put_format(b, "\"cns\":\"%d\",", dive->cns); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 21:40:06 +03:00
										 |  |  | void put_HTML_bookmarks(struct membuffer *b, struct dive *dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct event *ev = dive->dc.events; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!ev) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	char *separator = "\"events\":["; | 
					
						
							|  |  |  | 	do { | 
					
						
							|  |  |  | 		put_string(b, separator); | 
					
						
							|  |  |  | 		separator = ", "; | 
					
						
							| 
									
										
										
										
											2014-06-24 21:40:06 +03:00
										 |  |  | 		put_format(b, "{\"name\":\"%s\",", ev->name); | 
					
						
							| 
									
										
										
										
											2014-07-19 05:09:48 +02:00
										 |  |  | 		put_format(b, "\"value\":\"%d\",", ev->value); | 
					
						
							| 
									
										
										
										
											2014-07-26 16:29:16 +02:00
										 |  |  | 		put_format(b, "\"type\":\"%d\",", ev->type); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		put_format(b, "\"time\":\"%d\"}", ev->time.seconds); | 
					
						
							| 
									
										
										
										
											2014-06-24 21:40:06 +03:00
										 |  |  | 		ev = ev->next; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	} while (ev); | 
					
						
							| 
									
										
										
										
											2014-06-24 21:40:06 +03:00
										 |  |  | 	put_string(b, "],"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-27 21:38:50 +02:00
										 |  |  | static void put_weightsystem_HTML(struct membuffer *b, struct dive *dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i, nr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	nr = nr_weightsystems(dive); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	put_string(b, "\"Weights\":["); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	char *separator = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-27 21:38:50 +02:00
										 |  |  | 	for (i = 0; i < nr; i++) { | 
					
						
							|  |  |  | 		weightsystem_t *ws = dive->weightsystem + i; | 
					
						
							|  |  |  | 		int grams = ws->weight.grams; | 
					
						
							|  |  |  | 		const char *description = ws->description; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		put_string(b, separator); | 
					
						
							|  |  |  | 		separator = ", "; | 
					
						
							| 
									
										
										
										
											2014-07-27 21:38:50 +02:00
										 |  |  | 		put_string(b, "{"); | 
					
						
							| 
									
										
										
										
											2014-10-19 19:30:11 +02:00
										 |  |  | 		put_HTML_weight_units(b, grams, "\"weight\":\"", "\","); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		write_attribute(b, "description", description, " "); | 
					
						
							|  |  |  | 		put_string(b, "}"); | 
					
						
							| 
									
										
										
										
											2014-07-27 21:38:50 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	put_string(b, "],"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-08 16:09:24 +03:00
										 |  |  | static void put_cylinder_HTML(struct membuffer *b, struct dive *dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i, nr; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	char *separator = "\"Cylinders\":["; | 
					
						
							| 
									
										
										
										
											2014-06-08 16:09:24 +03:00
										 |  |  | 	nr = nr_cylinders(dive); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	if (!nr) | 
					
						
							|  |  |  | 		put_string(b, separator); | 
					
						
							| 
									
										
										
										
											2014-06-08 16:09:24 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < nr; i++) { | 
					
						
							|  |  |  | 		cylinder_t *cylinder = dive->cylinder + i; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		put_format(b, "%s{", separator); | 
					
						
							|  |  |  | 		separator = ", "; | 
					
						
							|  |  |  | 		write_attribute(b, "Type", cylinder->type.description, ", "); | 
					
						
							| 
									
										
										
										
											2014-06-08 16:09:24 +03:00
										 |  |  | 		if (cylinder->type.size.mliter) { | 
					
						
							| 
									
										
										
										
											2015-06-17 17:25:44 -07:00
										 |  |  | 			int volume = cylinder->type.size.mliter; | 
					
						
							|  |  |  | 			if (prefs.units.volume == CUFT && cylinder->type.workingpressure.mbar) | 
					
						
							| 
									
										
										
										
											2017-03-09 23:07:30 +07:00
										 |  |  | 				volume = lrint(volume * bar_to_atm(cylinder->type.workingpressure.mbar / 1000.0)); | 
					
						
							| 
									
										
										
										
											2015-06-17 17:25:44 -07:00
										 |  |  | 			put_HTML_volume_units(b, volume, "\"Size\":\"", " \", "); | 
					
						
							| 
									
										
										
										
											2014-06-08 16:09:24 +03:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 			write_attribute(b, "Size", "--", ", "); | 
					
						
							| 
									
										
										
										
											2014-06-08 16:09:24 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-10-19 19:30:11 +02:00
										 |  |  | 		put_HTML_pressure_units(b, cylinder->type.workingpressure, "\"WPressure\":\"", " \", "); | 
					
						
							| 
									
										
										
										
											2014-06-28 17:14:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (cylinder->start.mbar) { | 
					
						
							| 
									
										
										
										
											2014-10-19 19:30:11 +02:00
										 |  |  | 			put_HTML_pressure_units(b, cylinder->start, "\"SPressure\":\"", " \", "); | 
					
						
							| 
									
										
										
										
											2014-06-28 17:14:29 +02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 			write_attribute(b, "SPressure", "--", ", "); | 
					
						
							| 
									
										
										
										
											2014-06-28 17:14:29 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (cylinder->end.mbar) { | 
					
						
							| 
									
										
										
										
											2014-10-19 19:30:11 +02:00
										 |  |  | 			put_HTML_pressure_units(b, cylinder->end, "\"EPressure\":\"", " \", "); | 
					
						
							| 
									
										
										
										
											2014-06-28 17:14:29 +02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 			write_attribute(b, "EPressure", "--", ", "); | 
					
						
							| 
									
										
										
										
											2014-06-28 17:14:29 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-08 16:09:24 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (cylinder->gasmix.o2.permille) { | 
					
						
							| 
									
										
										
										
											2015-03-09 22:33:14 +02:00
										 |  |  | 			put_format(b, "\"O2\":\"%u.%u%%\",", FRACTION(cylinder->gasmix.o2.permille, 10)); | 
					
						
							|  |  |  | 			put_format(b, "\"He\":\"%u.%u%%\"", FRACTION(cylinder->gasmix.he.permille, 10)); | 
					
						
							| 
									
										
										
										
											2014-06-08 16:09:24 +03:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 			write_attribute(b, "O2", "Air", ""); | 
					
						
							| 
									
										
										
										
											2014-06-08 16:09:24 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-03-09 22:33:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		put_string(b, "}"); | 
					
						
							| 
									
										
										
										
											2014-06-08 16:09:24 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	put_string(b, "],"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-08 07:56:54 +03:00
										 |  |  | void put_HTML_samples(struct membuffer *b, struct dive *dive) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	put_format(b, "\"maxdepth\":%d,", dive->dc.maxdepth.mm); | 
					
						
							|  |  |  | 	put_format(b, "\"duration\":%d,", dive->dc.duration.seconds); | 
					
						
							|  |  |  | 	struct sample *s = dive->dc.sample; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!dive->dc.samples) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	char *separator = "\"samples\":["; | 
					
						
							| 
									
										
										
										
											2014-06-08 07:56:54 +03:00
										 |  |  | 	for (i = 0; i < dive->dc.samples; i++) { | 
					
						
							| 
									
										
										
										
											2017-07-20 14:39:02 -07:00
										 |  |  | 		put_format(b, "%s[%d,%d,%d,%d]", separator, s->time.seconds, s->depth.mm, s->pressure[0].mbar, s->temperature.mkelvin); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		separator = ", "; | 
					
						
							| 
									
										
										
										
											2014-06-08 07:56:54 +03:00
										 |  |  | 		s++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	put_string(b, "],"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-14 06:32:47 +03:00
										 |  |  | void put_HTML_coordinates(struct membuffer *b, struct dive *dive) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-02-12 19:01:27 -08:00
										 |  |  | 	struct dive_site *ds = get_dive_site_for_dive(dive); | 
					
						
							|  |  |  | 	if (!ds) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	degrees_t latitude = ds->latitude; | 
					
						
							|  |  |  | 	degrees_t longitude = ds->longitude; | 
					
						
							| 
									
										
										
										
											2014-08-14 06:32:47 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//don't put coordinates if in (0,0)
 | 
					
						
							|  |  |  | 	if (!latitude.udeg && !longitude.udeg) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	put_string(b, "\"coordinates\":{"); | 
					
						
							|  |  |  | 	put_degrees(b, latitude, "\"lat\":\"", "\","); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	put_degrees(b, longitude, "\"lon\":\"", "\""); | 
					
						
							| 
									
										
										
										
											2014-08-14 06:32:47 +03:00
										 |  |  | 	put_string(b, "},"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | void put_HTML_date(struct membuffer *b, struct dive *dive, const char *pre, const char *post) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct tm tm; | 
					
						
							|  |  |  | 	utc_mkdate(dive->when, &tm); | 
					
						
							| 
									
										
										
										
											2016-04-28 15:13:30 -07:00
										 |  |  | 	put_format(b, "%s%04u-%02u-%02u%s", pre, tm.tm_year, tm.tm_mon + 1, tm.tm_mday, post); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-02 20:10:54 +03:00
										 |  |  | void put_HTML_quoted(struct membuffer *b, const char *text) | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-02 20:10:54 +03:00
										 |  |  | 	int is_html = 1, is_attribute = 1; | 
					
						
							|  |  |  | 	put_quoted(b, text, is_attribute, is_html); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void put_HTML_notes(struct membuffer *b, struct dive *dive, const char *pre, const char *post) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-19 01:49:30 +02:00
										 |  |  | 	put_string(b, pre); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | 	if (dive->notes) { | 
					
						
							| 
									
										
										
										
											2014-06-02 20:10:54 +03:00
										 |  |  | 		put_HTML_quoted(b, dive->notes); | 
					
						
							| 
									
										
										
										
											2014-07-19 01:49:30 +02:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		put_string(b, "--"); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-07-19 01:49:30 +02:00
										 |  |  | 	put_string(b, post); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-19 19:30:11 +02:00
										 |  |  | void put_HTML_pressure_units(struct membuffer *b, pressure_t pressure, const char *pre, const char *post) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *unit; | 
					
						
							|  |  |  | 	double value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!pressure.mbar) { | 
					
						
							|  |  |  | 		put_format(b, "%s%s", pre, post); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	value = get_pressure_units(pressure.mbar, &unit); | 
					
						
							|  |  |  | 	put_format(b, "%s%.1f %s%s", pre, value, unit, post); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void put_HTML_volume_units(struct membuffer *b, unsigned int ml, const char *pre, const char *post) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *unit; | 
					
						
							|  |  |  | 	double value; | 
					
						
							|  |  |  | 	int frac; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	value = get_volume_units(ml, &frac, &unit); | 
					
						
							|  |  |  | 	put_format(b, "%s%.1f %s%s", pre, value, unit, post); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void put_HTML_weight_units(struct membuffer *b, unsigned int grams, const char *pre, const char *post) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *unit; | 
					
						
							|  |  |  | 	double value; | 
					
						
							|  |  |  | 	int frac; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	value = get_weight_units(grams, &frac, &unit); | 
					
						
							|  |  |  | 	put_format(b, "%s%.1f %s%s", pre, value, unit, post); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | void put_HTML_time(struct membuffer *b, struct dive *dive, const char *pre, const char *post) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct tm tm; | 
					
						
							|  |  |  | 	utc_mkdate(dive->when, &tm); | 
					
						
							|  |  |  | 	put_format(b, "%s%02u:%02u:%02u%s", pre, tm.tm_hour, tm.tm_min, tm.tm_sec, post); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 12:12:39 +02:00
										 |  |  | void put_HTML_depth(struct membuffer *b, struct dive *dive, const char *pre, const char *post) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *unit; | 
					
						
							|  |  |  | 	double value; | 
					
						
							|  |  |  | 	struct units *units_p = get_units(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!dive->maxdepth.mm) { | 
					
						
							|  |  |  | 		put_format(b, "%s--%s", pre, post); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	value = get_depth_units(dive->maxdepth.mm, NULL, &unit); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (units_p->length) { | 
					
						
							|  |  |  | 	case METERS: | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		put_format(b, "%s%.1f %s%s", pre, value, unit, post); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case FEET: | 
					
						
							|  |  |  | 		put_format(b, "%s%.0f %s%s", pre, value, unit, post); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | void put_HTML_airtemp(struct membuffer *b, struct dive *dive, const char *pre, const char *post) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *unit; | 
					
						
							|  |  |  | 	double value; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 	if (!dive->airtemp.mkelvin) { | 
					
						
							|  |  |  | 		put_format(b, "%s--%s", pre, post); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | 	value = get_temp_units(dive->airtemp.mkelvin, &unit); | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 	put_format(b, "%s%.1f %s%s", pre, value, unit, post); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void put_HTML_watertemp(struct membuffer *b, struct dive *dive, const char *pre, const char *post) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const char *unit; | 
					
						
							|  |  |  | 	double value; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 	if (!dive->watertemp.mkelvin) { | 
					
						
							|  |  |  | 		put_format(b, "%s--%s", pre, post); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | 	value = get_temp_units(dive->watertemp.mkelvin, &unit); | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 	put_format(b, "%s%.1f %s%s", pre, value, unit, post); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void put_HTML_tags(struct membuffer *b, struct dive *dive, const char *pre, const char *post) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	put_string(b, pre); | 
					
						
							|  |  |  | 	struct tag_entry *tag = dive->tag_list; | 
					
						
							| 
									
										
										
										
											2014-05-28 14:43:57 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!tag) | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		put_string(b, "[\"--\""); | 
					
						
							| 
									
										
										
										
											2014-05-28 14:43:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	char *separator = "["; | 
					
						
							| 
									
										
										
										
											2014-05-28 20:52:05 +03:00
										 |  |  | 	while (tag) { | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		put_format(b, "%s\"", separator); | 
					
						
							|  |  |  | 		separator = ", "; | 
					
						
							| 
									
										
										
										
											2014-06-02 20:10:54 +03:00
										 |  |  | 		put_HTML_quoted(b, tag->tag->name); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		put_string(b, "\""); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | 		tag = tag->next; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-28 20:52:05 +03:00
										 |  |  | 	put_string(b, "]"); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | 	put_string(b, post); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:49 +03:00
										 |  |  | /* if exporting list_only mode, we neglect exporting the samples, bookmarks and cylinders */ | 
					
						
							| 
									
										
										
										
											2014-07-13 23:36:35 +02:00
										 |  |  | void write_one_dive(struct membuffer *b, struct dive *dive, const char *photos_dir, int *dive_no, const bool list_only) | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 	put_string(b, "{"); | 
					
						
							|  |  |  | 	put_format(b, "\"number\":%d,", *dive_no); | 
					
						
							|  |  |  | 	put_format(b, "\"subsurface_number\":%d,", dive->number); | 
					
						
							|  |  |  | 	put_HTML_date(b, dive, "\"date\":\"", "\","); | 
					
						
							|  |  |  | 	put_HTML_time(b, dive, "\"time\":\"", "\","); | 
					
						
							| 
									
										
										
										
											2015-02-12 19:01:27 -08:00
										 |  |  | 	write_attribute(b, "location", get_dive_location(dive), ", "); | 
					
						
							| 
									
										
										
										
											2014-08-14 06:32:47 +03:00
										 |  |  | 	put_HTML_coordinates(b, dive); | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 	put_format(b, "\"rating\":%d,", dive->rating); | 
					
						
							|  |  |  | 	put_format(b, "\"visibility\":%d,", dive->visibility); | 
					
						
							| 
									
										
										
										
											2014-08-07 17:11:42 +03:00
										 |  |  | 	put_format(b, "\"dive_duration\":\"%u:%02u min\",", | 
					
						
							|  |  |  | 		   FRACTION(dive->duration.seconds, 60)); | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 	put_string(b, "\"temperature\":{"); | 
					
						
							|  |  |  | 	put_HTML_airtemp(b, dive, "\"air\":\"", "\","); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	put_HTML_watertemp(b, dive, "\"water\":\"", "\""); | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 	put_string(b, "	},"); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	write_attribute(b, "buddy", dive->buddy, ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "divemaster", dive->divemaster, ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "suit", dive->suit, ", "); | 
					
						
							| 
									
										
										
										
											2014-05-28 20:52:05 +03:00
										 |  |  | 	put_HTML_tags(b, dive, "\"tags\":", ","); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:49 +03:00
										 |  |  | 	if (!list_only) { | 
					
						
							|  |  |  | 		put_cylinder_HTML(b, dive); | 
					
						
							| 
									
										
										
										
											2014-07-27 21:38:50 +02:00
										 |  |  | 		put_weightsystem_HTML(b, dive); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:49 +03:00
										 |  |  | 		put_HTML_samples(b, dive); | 
					
						
							| 
									
										
										
										
											2014-06-24 21:40:06 +03:00
										 |  |  | 		put_HTML_bookmarks(b, dive); | 
					
						
							| 
									
										
										
										
											2014-07-16 14:38:20 +02:00
										 |  |  | 		write_dive_status(b, dive); | 
					
						
							| 
									
										
										
										
											2015-03-13 15:36:52 +02:00
										 |  |  | 		if (photos_dir && strcmp(photos_dir, "")) | 
					
						
							| 
									
										
										
										
											2014-09-21 16:11:58 +02:00
										 |  |  | 			save_photos(b, photos_dir, dive); | 
					
						
							| 
									
										
										
										
											2014-08-23 22:22:24 +03:00
										 |  |  | 		write_divecomputers(b, dive); | 
					
						
							| 
									
										
										
										
											2014-06-24 16:01:49 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	put_HTML_notes(b, dive, "\"notes\":\"", "\""); | 
					
						
							|  |  |  | 	put_string(b, "}\n"); | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 	(*dive_no)++; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | void write_no_trip(struct membuffer *b, int *dive_no, bool selected_only, const char *photos_dir, const bool list_only, char *sep) | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | 	struct dive *dive; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	char *separator = ""; | 
					
						
							| 
									
										
										
										
											2014-08-15 08:07:17 +03:00
										 |  |  | 	bool found_sel_dive = 0; | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-29 07:30:33 -07:00
										 |  |  | 	for_each_dive (i, dive) { | 
					
						
							| 
									
										
										
										
											2014-08-14 05:30:36 +03:00
										 |  |  | 		// write dive if it doesn't belong to any trip and the dive is selected
 | 
					
						
							|  |  |  | 		// or we are in exporting all dives mode.
 | 
					
						
							| 
									
										
										
										
											2014-08-15 08:07:17 +03:00
										 |  |  | 		if (!dive->divetrip && (dive->selected || !selected_only)) { | 
					
						
							|  |  |  | 			if (!found_sel_dive) { | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 				put_format(b, "%c{", *sep); | 
					
						
							|  |  |  | 				(*sep) = ','; | 
					
						
							| 
									
										
										
										
											2014-08-15 08:07:17 +03:00
										 |  |  | 				put_format(b, "\"name\":\"Other\","); | 
					
						
							|  |  |  | 				put_format(b, "\"dives\":["); | 
					
						
							|  |  |  | 				found_sel_dive = 1; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 			put_string(b, separator); | 
					
						
							|  |  |  | 			separator = ", "; | 
					
						
							| 
									
										
										
										
											2014-07-13 23:36:35 +02:00
										 |  |  | 			write_one_dive(b, dive, photos_dir, dive_no, list_only); | 
					
						
							| 
									
										
										
										
											2014-08-15 08:07:17 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-15 08:07:17 +03:00
										 |  |  | 	if (found_sel_dive) | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		put_format(b, "]}\n\n"); | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | void write_trip(struct membuffer *b, dive_trip_t *trip, int *dive_no, bool selected_only, const char *photos_dir, const bool list_only, char *sep) | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct dive *dive; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	char *separator = ""; | 
					
						
							| 
									
										
										
										
											2014-08-14 05:30:36 +03:00
										 |  |  | 	bool found_sel_dive = 0; | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-29 07:30:33 -07:00
										 |  |  | 	for (dive = trip->dives; dive != NULL; dive = dive->next) { | 
					
						
							| 
									
										
										
										
											2014-08-14 05:30:36 +03:00
										 |  |  | 		if (!dive->selected && selected_only) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// save trip if found at least one selected dive.
 | 
					
						
							|  |  |  | 		if (!found_sel_dive) { | 
					
						
							|  |  |  | 			found_sel_dive = 1; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 			put_format(b, "%c {", *sep); | 
					
						
							|  |  |  | 			(*sep) = ','; | 
					
						
							| 
									
										
										
										
											2014-08-14 05:30:36 +03:00
										 |  |  | 			put_format(b, "\"name\":\"%s\",", trip->location); | 
					
						
							|  |  |  | 			put_format(b, "\"dives\":["); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		put_string(b, separator); | 
					
						
							|  |  |  | 		separator = ", "; | 
					
						
							| 
									
										
										
										
											2014-07-13 23:36:35 +02:00
										 |  |  | 		write_one_dive(b, dive, photos_dir, dive_no, list_only); | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-14 05:30:36 +03:00
										 |  |  | 	// close the trip object if contain dives.
 | 
					
						
							|  |  |  | 	if (found_sel_dive) | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		put_format(b, "]}\n\n"); | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-13 23:36:35 +02:00
										 |  |  | void write_trips(struct membuffer *b, const char *photos_dir, bool selected_only, const bool list_only) | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i, dive_no = 0; | 
					
						
							|  |  |  | 	struct dive *dive; | 
					
						
							|  |  |  | 	dive_trip_t *trip; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	char sep_ = ' '; | 
					
						
							|  |  |  | 	char *sep = &sep_; | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (trip = dive_trip_list; trip != NULL; trip = trip->next) | 
					
						
							|  |  |  | 		trip->index = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-14 05:30:36 +03:00
										 |  |  | 	for_each_dive (i, dive) { | 
					
						
							|  |  |  | 		trip = dive->divetrip; | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-14 05:30:36 +03:00
										 |  |  | 		/*Continue if the dive have no trips or we have seen this trip before*/ | 
					
						
							|  |  |  | 		if (!trip || trip->index) | 
					
						
							|  |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-14 05:30:36 +03:00
										 |  |  | 		/* We haven't seen this trip before - save it and all dives */ | 
					
						
							|  |  |  | 		trip->index = 1; | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 		write_trip(b, trip, &dive_no, selected_only, photos_dir, list_only, sep); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-14 05:30:36 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*Save all remaining trips into Others*/ | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	write_no_trip(b, &dive_no, selected_only, photos_dir, list_only, sep); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-13 23:36:35 +02:00
										 |  |  | void export_list(struct membuffer *b, const char *photos_dir, bool selected_only, const bool list_only) | 
					
						
							| 
									
										
										
										
											2014-05-29 07:30:33 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-28 00:06:56 +03:00
										 |  |  | 	put_string(b, "trips=["); | 
					
						
							| 
									
										
										
										
											2014-07-13 23:36:35 +02:00
										 |  |  | 	write_trips(b, photos_dir, selected_only, list_only); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | 	put_string(b, "]"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-13 23:36:35 +02:00
										 |  |  | void export_HTML(const char *file_name, const char *photos_dir, const bool selected_only, const bool list_only) | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	FILE *f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct membuffer buf = { 0 }; | 
					
						
							| 
									
										
										
										
											2014-07-13 23:36:35 +02:00
										 |  |  | 	export_list(&buf, photos_dir, selected_only, list_only); | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-08 07:35:20 +03:00
										 |  |  | 	f = subsurface_fopen(file_name, "w+"); | 
					
						
							| 
									
										
										
										
											2015-06-18 12:23:58 -07:00
										 |  |  | 	if (!f) { | 
					
						
							| 
									
										
										
										
											2014-06-08 07:35:20 +03:00
										 |  |  | 		report_error(translate("gettextFromC", "Can't open file %s"), file_name); | 
					
						
							| 
									
										
										
										
											2015-06-18 12:23:58 -07:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		flush_buffer(&buf, f); /*check for writing errors? */ | 
					
						
							|  |  |  | 		fclose(f); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-23 21:49:49 +03:00
										 |  |  | 	free_buffer(&buf); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-08-10 10:12:29 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-10 18:29:25 +03:00
										 |  |  | void export_translation(const char *file_name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-10 10:12:29 +03:00
										 |  |  | 	FILE *f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct membuffer buf = { 0 }; | 
					
						
							|  |  |  | 	struct membuffer *b = &buf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//export translated words here
 | 
					
						
							|  |  |  | 	put_format(b, "translate={"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//Dive list view
 | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	write_attribute(b, "Number", translate("gettextFromC", "Number"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Date", translate("gettextFromC", "Date"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Time", translate("gettextFromC", "Time"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Location", translate("gettextFromC", "Location"), ", "); | 
					
						
							| 
									
										
										
										
											2014-11-25 15:47:25 +00:00
										 |  |  | 	write_attribute(b, "Air_Temp", translate("gettextFromC", "Air temp."), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Water_Temp", translate("gettextFromC", "Water temp."), ", "); | 
					
						
							| 
									
										
										
										
											2014-09-11 22:56:36 +01:00
										 |  |  | 	write_attribute(b, "dives", translate("gettextFromC", "Dives"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Expand_All", translate("gettextFromC", "Expand all"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Collapse_All", translate("gettextFromC", "Collapse all"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "trips", translate("gettextFromC", "Trips"), ", "); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	write_attribute(b, "Statistics", translate("gettextFromC", "Statistics"), ", "); | 
					
						
							| 
									
										
										
										
											2014-09-11 22:56:36 +01:00
										 |  |  | 	write_attribute(b, "Advanced_Search", translate("gettextFromC", "Advanced search"), ", "); | 
					
						
							| 
									
										
										
										
											2014-08-10 10:12:29 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//Dive expanded view
 | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	write_attribute(b, "Rating", translate("gettextFromC", "Rating"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Visibility", translate("gettextFromC", "Visibility"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Duration", translate("gettextFromC", "Duration"), ", "); | 
					
						
							| 
									
										
										
										
											2014-09-11 22:56:36 +01:00
										 |  |  | 	write_attribute(b, "DiveMaster", translate("gettextFromC", "Divemaster"), ", "); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	write_attribute(b, "Buddy", translate("gettextFromC", "Buddy"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Suit", translate("gettextFromC", "Suit"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Tags", translate("gettextFromC", "Tags"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Notes", translate("gettextFromC", "Notes"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Show_more_details", translate("gettextFromC", "Show more details"), ", "); | 
					
						
							| 
									
										
										
										
											2014-08-10 10:12:29 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//Yearly statistics view
 | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	write_attribute(b, "Yearly_statistics", translate("gettextFromC", "Yearly statistics"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Year", translate("gettextFromC", "Year"), ", "); | 
					
						
							| 
									
										
										
										
											2014-09-11 22:56:36 +01:00
										 |  |  | 	write_attribute(b, "Total_Time", translate("gettextFromC", "Total time"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Average_Time", translate("gettextFromC", "Average time"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Shortest_Time", translate("gettextFromC", "Shortest time"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Longest_Time", translate("gettextFromC", "Longest time"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Average_Depth", translate("gettextFromC", "Average depth"), ", "); | 
					
						
							| 
									
										
										
										
											2014-11-25 15:47:25 +00:00
										 |  |  | 	write_attribute(b, "Min_Depth", translate("gettextFromC", "Min. depth"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Max_Depth", translate("gettextFromC", "Max. depth"), ", "); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	write_attribute(b, "Average_SAC", translate("gettextFromC", "Average SAC"), ", "); | 
					
						
							| 
									
										
										
										
											2014-11-25 15:47:25 +00:00
										 |  |  | 	write_attribute(b, "Min_SAC", translate("gettextFromC", "Min. SAC"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Max_SAC", translate("gettextFromC", "Max. SAC"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Average_Temp", translate("gettextFromC", "Average temp."), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Min_Temp", translate("gettextFromC", "Min. temp."), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Max_Temp", translate("gettextFromC", "Max. temp."), ", "); | 
					
						
							| 
									
										
										
										
											2014-09-11 22:56:36 +01:00
										 |  |  | 	write_attribute(b, "Back_to_List", translate("gettextFromC", "Back to list"), ", "); | 
					
						
							| 
									
										
										
										
											2014-08-10 10:12:29 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//dive detailed view
 | 
					
						
							| 
									
										
										
										
											2017-02-20 10:42:25 +01:00
										 |  |  | 	write_attribute(b, "Dive_No", translate("gettextFromC", "Dive #"), ", "); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	write_attribute(b, "Dive_profile", translate("gettextFromC", "Dive profile"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Dive_information", translate("gettextFromC", "Dive information"), ", "); | 
					
						
							| 
									
										
										
										
											2014-09-11 22:56:36 +01:00
										 |  |  | 	write_attribute(b, "Dive_equipment", translate("gettextFromC", "Dive equipment"), ", "); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	write_attribute(b, "Type", translate("gettextFromC", "Type"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Size", translate("gettextFromC", "Size"), ", "); | 
					
						
							| 
									
										
										
										
											2014-09-11 22:56:36 +01:00
										 |  |  | 	write_attribute(b, "Work_Pressure", translate("gettextFromC", "Work pressure"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Start_Pressure", translate("gettextFromC", "Start pressure"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "End_Pressure", translate("gettextFromC", "End pressure"), ", "); | 
					
						
							| 
									
										
										
										
											2014-08-27 20:19:20 +03:00
										 |  |  | 	write_attribute(b, "Gas", translate("gettextFromC", "Gas"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Weight", translate("gettextFromC", "Weight"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Type", translate("gettextFromC", "Type"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Events", translate("gettextFromC", "Events"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Name", translate("gettextFromC", "Name"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Value", translate("gettextFromC", "Value"), ", "); | 
					
						
							|  |  |  | 	write_attribute(b, "Coordinates", translate("gettextFromC", "Coordinates"), ", "); | 
					
						
							| 
									
										
										
										
											2014-09-11 22:56:36 +01:00
										 |  |  | 	write_attribute(b, "Dive_Status", translate("gettextFromC", "Dive status"), " "); | 
					
						
							| 
									
										
										
										
											2014-08-10 10:12:29 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	put_format(b, "}"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	f = subsurface_fopen(file_name, "w+"); | 
					
						
							| 
									
										
										
										
											2015-06-18 12:23:58 -07:00
										 |  |  | 	if (!f) { | 
					
						
							| 
									
										
										
										
											2014-08-10 10:12:29 +03:00
										 |  |  | 		report_error(translate("gettextFromC", "Can't open file %s"), file_name); | 
					
						
							| 
									
										
										
										
											2015-06-18 12:23:58 -07:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		flush_buffer(&buf, f); /*check for writing errors? */ | 
					
						
							|  |  |  | 		fclose(f); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-10 10:12:29 +03:00
										 |  |  | 	free_buffer(&buf); | 
					
						
							|  |  |  | } |