>From 5481eb20d5590fe03ea0f9a837f3cf316bb32650 Mon Sep 17 00:00:00 2001
From: Jef Driesen <jefdriesen@users.sourceforge.net>
Date: Fri, 31 Oct 2014 22:10:39 +0100
Subject: [PATCH 1/3] Fix naming conventions.

---
 src/suunto_eonsteel.c        | 65 ++++++++++++++++++++++---------------------
 src/suunto_eonsteel_parser.c | 66 ++++++++++++++++++++++++--------------------
 2 files changed, 70 insertions(+), 61 deletions(-)

diff --git a/src/suunto_eonsteel.c b/src/suunto_eonsteel.c
index 328a8e9..435747b 100644
--- a/src/suunto_eonsteel.c
+++ b/src/suunto_eonsteel.c
@@ -44,14 +44,14 @@
 
 #include <libusb-1.0/libusb.h>
 
-struct eonsteel {
+typedef struct suunto_eonsteel_device_t {
 	dc_device_t base;
 
 	libusb_context *ctx;
 	libusb_device_handle *handle;
 	unsigned int magic;
 	unsigned short seq;
-};
+} suunto_eonsteel_device_t;
 
 // The EON Steel implements a small filesystem
 #define DIRTYPE_FILE 0x0001
@@ -82,6 +82,19 @@ struct directory_entry {
 #define READDIR_CMD    0x0910
 #define DIR_CLOSE_CMD  0x0a10
 
+static dc_status_t suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
+static dc_status_t suunto_eonsteel_device_close(dc_device_t *abstract);
+
+static const dc_device_vtable_t suunto_eonsteel_device_vtable = {
+	DC_FAMILY_SUUNTO_EONSTEEL,
+	NULL, /* set_fingerprint */
+	NULL, /* read */
+	NULL, /* write */
+	NULL, /* dump */
+	suunto_eonsteel_device_foreach, /* foreach */
+	suunto_eonsteel_device_close /* close */
+};
+
 static const char *dive_directory = "0:/dives";
 
 static struct directory_entry *alloc_dirent(int type, int len, const char *name)
@@ -160,7 +173,7 @@ static void debug_text(const char *name, const char *buf, int len)
 	printf("\nend of text\n");
 }
 
-static int receive_data(struct eonsteel *eon, unsigned char *buffer, int size)
+static int receive_data(suunto_eonsteel_device_t *eon, unsigned char *buffer, int size)
 {
 	const int InEndpoint = 0x82;
 	unsigned char buf[64];
@@ -191,7 +204,7 @@ static int receive_data(struct eonsteel *eon, unsigned char *buffer, int size)
 	return ret;
 }
 
-static int send_cmd(struct eonsteel *eon,
+static int send_cmd(suunto_eonsteel_device_t *eon,
 	unsigned short cmd,
 	unsigned int len,
 	const unsigned char *buffer)
@@ -249,7 +262,7 @@ static int send_cmd(struct eonsteel *eon,
  * send_cmd() side. The offsets are the same in the actual raw
  * packet.
  */
-static int send_receive(struct eonsteel *eon,
+static int send_receive(suunto_eonsteel_device_t *eon,
 	unsigned short cmd,
 	unsigned int len_out, const unsigned char *out,
 	unsigned int len_in, unsigned char *in)
@@ -280,7 +293,7 @@ static int send_receive(struct eonsteel *eon,
 	return actual;
 }
 
-static int read_file(struct eonsteel *eon, const char *filename, dc_buffer_t *buf)
+static int read_file(suunto_eonsteel_device_t *eon, const char *filename, dc_buffer_t *buf)
 {
 	unsigned char result[2560];
 	unsigned char cmdbuf[64];
@@ -381,7 +394,7 @@ static struct directory_entry *parse_dirent(int nr, const unsigned char *p, int
 	return old;
 }
 
-static int get_file_list(struct eonsteel *eon, struct directory_entry **res)
+static int get_file_list(suunto_eonsteel_device_t *eon, struct directory_entry **res)
 {
 	struct directory_entry *de = NULL;
 	unsigned char cmd[64];
@@ -429,21 +442,7 @@ static int get_file_list(struct eonsteel *eon, struct directory_entry **res)
 	return 0;
 }
 
-
-static dc_status_t eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
-static dc_status_t eonsteel_device_close(dc_device_t *abstract);
-
-static const dc_device_vtable_t eonsteel_device_vtable = {
-	DC_FAMILY_SUUNTO_EONSTEEL,
-	NULL, /* set_fingerprint */
-	NULL, /* read */
-	NULL, /* write */
-	NULL, /* dump */
-	eonsteel_device_foreach, /* foreach */
-	eonsteel_device_close /* close */
-};
-
-static int initialize_eonsteel(struct eonsteel *eon)
+static int initialize_eonsteel(suunto_eonsteel_device_t *eon)
 {
 	const int InEndpoint = 0x82;
 	unsigned char buf[64];
@@ -471,15 +470,16 @@ static int initialize_eonsteel(struct eonsteel *eon)
 	return 0;
 }
 
-dc_status_t suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, const char *name, unsigned int model)
+dc_status_t
+suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, const char *name, unsigned int model)
 {
 	int rc;
-	struct eonsteel *eon;
+	suunto_eonsteel_device_t *eon;
 
 	if (out == NULL)
 		return DC_STATUS_INVALIDARGS;
 
-	eon = calloc(1, sizeof(struct eonsteel));
+	eon = calloc(1, sizeof(suunto_eonsteel_device_t));
 	if (!eon)
 		return DC_STATUS_NOMEMORY;
 
@@ -488,7 +488,7 @@ dc_status_t suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context
 	eon->seq = INIT_SEQ;
 
 	// Set up the libdivecomputer interfaces
-	device_init(&eon->base, context, &eonsteel_device_vtable);
+	device_init(&eon->base, context, &suunto_eonsteel_device_vtable);
 	*out = (void *) eon;
 
 	if (libusb_init(&eon->ctx)) {
@@ -525,11 +525,12 @@ static int count_dir_entries(struct directory_entry *de)
 	return count;
 }
 
-static dc_status_t eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callback, void *userdata)
+static dc_status_t
+suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callback, void *userdata)
 {
 	int skip = 0, rc;
 	struct directory_entry *de;
-	struct eonsteel *eon = (struct eonsteel *) abstract;
+	suunto_eonsteel_device_t *eon = (suunto_eonsteel_device_t *) abstract;
 	dc_buffer_t *file;
 	char pathname[64];
 	unsigned int time;
@@ -592,9 +593,10 @@ static dc_status_t eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callba
 	return device_is_cancelled(abstract) ? DC_STATUS_CANCELLED : DC_STATUS_SUCCESS;
 }
 
-static dc_status_t eonsteel_device_close(dc_device_t *abstract)
+static dc_status_t
+suunto_eonsteel_device_close(dc_device_t *abstract)
 {
-	struct eonsteel *eon = (struct eonsteel *) abstract;
+	suunto_eonsteel_device_t *eon = (suunto_eonsteel_device_t *) abstract;
 
 	libusb_close(eon->handle);
 	libusb_exit(eon->ctx);
@@ -605,7 +607,8 @@ static dc_status_t eonsteel_device_close(dc_device_t *abstract)
 
 #else // no LIBUSB support
 
-dc_status_t suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, const char *name, unsigned int model)
+dc_status_t
+suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, const char *name, unsigned int model)
 {
 	ERROR(context, "The Suunto EON Steel backend needs libusb-1.0");
 	return DC_STATUS_UNSUPPORTED;
diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c
index 1d035b9..325866d 100644
--- a/src/suunto_eonsteel_parser.c
+++ b/src/suunto_eonsteel_parser.c
@@ -42,7 +42,7 @@ struct type_desc {
 #define MAXTYPE 512
 #define MAXGASES 16
 
-struct eon_parser {
+typedef struct suunto_eonsteel_parser_t {
 	dc_parser_t base;
 	struct type_desc type_desc[MAXTYPE];
 	// field cache
@@ -56,7 +56,7 @@ struct eon_parser {
 		dc_salinity_t salinity;
 		double surface_pressure;
 	} cache;
-};
+} suunto_eonsteel_parser_t;
 
 
 static int report_error(const char *fmt, ...)
@@ -111,7 +111,7 @@ static void debug_text(const char *name, const char *buf, int len)
 
 typedef int (*eon_data_cb_t)(unsigned short type, const struct type_desc *desc, const void *data, int len, void *user);
 
-static int record_type(struct eon_parser *eon, unsigned short type, const char *name, int namelen)
+static int record_type(suunto_eonsteel_parser_t *eon, unsigned short type, const char *name, int namelen)
 {
 	struct type_desc desc;
 	const char *next;
@@ -161,7 +161,7 @@ static int record_type(struct eon_parser *eon, unsigned short type, const char *
 	return 0;
 }
 
-static int traverse_entry(struct eon_parser *eon, const unsigned char *p, int len, eon_data_cb_t callback, void *user)
+static int traverse_entry(suunto_eonsteel_parser_t *eon, const unsigned char *p, int len, eon_data_cb_t callback, void *user)
 {
 	const unsigned char *name, *data, *end, *last, *one_past_end = p + len;
 	int textlen, type;
@@ -229,7 +229,7 @@ static int traverse_entry(struct eon_parser *eon, const unsigned char *p, int le
 	return end - p;
 }
 
-static int traverse_data(struct eon_parser *eon, eon_data_cb_t callback, void *user)
+static int traverse_data(suunto_eonsteel_parser_t *eon, eon_data_cb_t callback, void *user)
 {
 	const unsigned char *data = eon->base.data;
 	int len = eon->base.size;
@@ -254,7 +254,7 @@ static int traverse_data(struct eon_parser *eon, eon_data_cb_t callback, void *u
 }
 
 struct sample_data {
-	struct eon_parser *eon;
+	suunto_eonsteel_parser_t *eon;
 	dc_sample_callback_t callback;
 	void *userdata;
 	unsigned int time;
@@ -345,9 +345,10 @@ static int traverse_samples(unsigned short type, const struct type_desc *desc, c
 	return 0;
 }
 
-static dc_status_t eonsteel_parser_samples_foreach(dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata)
+static dc_status_t
+suunto_eonsteel_parser_samples_foreach(dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata)
 {
-	struct eon_parser *eon = (void *)abstract;
+	suunto_eonsteel_parser_t *eon = (void *)abstract;
 	struct sample_data data = { eon, callback, userdata, 0 };
 
 	traverse_data(eon, traverse_samples, &data);
@@ -359,9 +360,10 @@ static dc_status_t eonsteel_parser_samples_foreach(dc_parser_t *abstract, dc_sam
 #define field_value(p, set) \
 	memcpy((p), &(set), sizeof(set))
 
-static dc_status_t eonsteel_parser_get_field(dc_parser_t *parser, dc_field_type_t type, unsigned int flags, void *value)
+static dc_status_t
+suunto_eonsteel_parser_get_field(dc_parser_t *parser, dc_field_type_t type, unsigned int flags, void *value)
 {
-	struct eon_parser *eon = (struct eon_parser *)parser;
+	suunto_eonsteel_parser_t *eon = (suunto_eonsteel_parser_t *)parser;
 
 	if (!(eon->cache.initialized >> type))
 		return DC_STATUS_UNSUPPORTED;
@@ -399,7 +401,8 @@ static dc_status_t eonsteel_parser_get_field(dc_parser_t *parser, dc_field_type_
  * and we've saved it off as the four first bytes
  * of the dive data (in little-endian format).
  */
-static dc_status_t eonsteel_parser_get_datetime(dc_parser_t *parser, dc_datetime_t *datetime)
+static dc_status_t
+suunto_eonsteel_parser_get_datetime(dc_parser_t *parser, dc_datetime_t *datetime)
 {
 	unsigned int t;
 
@@ -411,13 +414,13 @@ static dc_status_t eonsteel_parser_get_datetime(dc_parser_t *parser, dc_datetime
 }
 
 // time in ms
-static void add_time_field(struct eon_parser *eon, unsigned short time_delta_ms)
+static void add_time_field(suunto_eonsteel_parser_t *eon, unsigned short time_delta_ms)
 {
 	eon->cache.divetime += time_delta_ms;
 }
 
 // depth in cm
-static void set_depth_field(struct eon_parser *eon, unsigned short d)
+static void set_depth_field(suunto_eonsteel_parser_t *eon, unsigned short d)
 {
 	if (d != 0xffff) {
 		double depth = d / 100.0;
@@ -428,7 +431,7 @@ static void set_depth_field(struct eon_parser *eon, unsigned short d)
 }
 
 // gas type: 0=Off,1=Primary,2=?,3=Diluent
-static void add_gas_type(struct eon_parser *eon, unsigned char type)
+static void add_gas_type(suunto_eonsteel_parser_t *eon, unsigned char type)
 {
 	if (eon->cache.ngases < MAXGASES)
 		eon->cache.ngases++;
@@ -436,7 +439,7 @@ static void add_gas_type(struct eon_parser *eon, unsigned char type)
 }
 
 // O2 percentage as a byte
-static void add_gas_o2(struct eon_parser *eon, unsigned char o2)
+static void add_gas_o2(suunto_eonsteel_parser_t *eon, unsigned char o2)
 {
 	int idx = eon->cache.ngases-1;
 	if (idx >= 0)
@@ -445,7 +448,7 @@ static void add_gas_o2(struct eon_parser *eon, unsigned char o2)
 }
 
 // He percentage as a byte
-static void add_gas_he(struct eon_parser *eon, unsigned char he)
+static void add_gas_he(suunto_eonsteel_parser_t *eon, unsigned char he)
 {
 	int idx = eon->cache.ngases-1;
 	if (idx >= 0)
@@ -455,7 +458,7 @@ static void add_gas_he(struct eon_parser *eon, unsigned char he)
 
 static int traverse_fields(unsigned short type, const struct type_desc *desc, const void *data, int len, void *user)
 {
-	struct eon_parser *eon = user;
+	suunto_eonsteel_parser_t *eon = user;
 
 	switch (type) {
 	case 0x0001: // group: time in first word, depth in second
@@ -482,7 +485,7 @@ static int traverse_fields(unsigned short type, const struct type_desc *desc, co
 }
 
 
-static void initialize_field_caches(struct eon_parser *eon)
+static void initialize_field_caches(suunto_eonsteel_parser_t *eon)
 {
 	memset(&eon->cache, 0, sizeof(eon->cache));
 	eon->cache.initialized = 1 << DC_FIELD_DIVETIME;
@@ -494,38 +497,41 @@ static void initialize_field_caches(struct eon_parser *eon)
 	eon->cache.divetime /= 1000;
 }
 
-static dc_status_t eonsteel_parser_set_data(dc_parser_t *parser, const unsigned char *data, unsigned int size)
+static dc_status_t
+suunto_eonsteel_parser_set_data(dc_parser_t *parser, const unsigned char *data, unsigned int size)
 {
-	struct eon_parser *eon = (void *)parser;
+	suunto_eonsteel_parser_t *eon = (void *)parser;
 	memset(eon->type_desc, 0, sizeof(eon->type_desc));
 	initialize_field_caches(eon);
 	return DC_STATUS_SUCCESS;
 }
 
-static dc_status_t eonsteel_parser_destroy(dc_parser_t *parser)
+static dc_status_t
+suunto_eonsteel_parser_destroy(dc_parser_t *parser)
 {
 	free(parser);
 	return DC_STATUS_SUCCESS;
 }
 
-static const dc_parser_vtable_t eonsteel_parser_vtable = {
+static const dc_parser_vtable_t suunto_eonsteel_parser_vtable = {
 	DC_FAMILY_SUUNTO_EONSTEEL,
-	eonsteel_parser_set_data, /* set_data */
-	eonsteel_parser_get_datetime, /* datetime */
-	eonsteel_parser_get_field, /* fields */
-	eonsteel_parser_samples_foreach, /* samples_foreach */
-	eonsteel_parser_destroy /* destroy */
+	suunto_eonsteel_parser_set_data, /* set_data */
+	suunto_eonsteel_parser_get_datetime, /* datetime */
+	suunto_eonsteel_parser_get_field, /* fields */
+	suunto_eonsteel_parser_samples_foreach, /* samples_foreach */
+	suunto_eonsteel_parser_destroy /* destroy */
 };
 
-dc_status_t suunto_eonsteel_parser_create(dc_parser_t **out, dc_context_t *context, unsigned int model)
+dc_status_t
+suunto_eonsteel_parser_create(dc_parser_t **out, dc_context_t *context, unsigned int model)
 {
-	struct eon_parser *eon;
+	suunto_eonsteel_parser_t *eon;
 
 	if (out == NULL)
 		return DC_STATUS_INVALIDARGS;
 
 	eon = calloc(1, sizeof(*eon));
-	parser_init(&eon->base, context, &eonsteel_parser_vtable);
+	parser_init(&eon->base, context, &suunto_eonsteel_parser_vtable);
 	*out = &eon->base;
 
 	return DC_STATUS_SUCCESS;
-- 
1.9.1

