Skip to content

Commit

Permalink
Reformat using 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibo committed Feb 27, 2014
1 parent 7f9dd7d commit 952b8c7
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 49 deletions.
28 changes: 10 additions & 18 deletions activity.c
Expand Up @@ -4,31 +4,21 @@
#include "gpx.h"
#include "tcx.h"

#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#define DEFAULT_WRITE_FORMAT CSV

/* indexed by FileFormat */
static ReadFn *readers[] = {
csv_read,
fit_read,
gpx_read,
tcx_read
};
static ReadFn *readers[] = { csv_read, fit_read, gpx_read, tcx_read };

/* indexed by FileFormat */
static WriteFn *writers[] = {
csv_write,
fit_write,
gpx_write,
tcx_write
};
static WriteFn *writers[] = { csv_write, fit_write, gpx_write, tcx_write };

static FileFormat file_format_from_name(char *filename) {
char ext[4];
unsigned i;
size_t len = strlen(filename);
for (i = 2; i >= 0; i++) {
ext[i] = tolower(*(filename+len-3+i));
ext[i] = tolower(*(filename + len - 3 + i));
}
ext[3] = '\0';

Expand All @@ -54,7 +44,7 @@ int activity_read(Activity *activity, char *filename) {
}
}

return 1;
return 1;
}
int activity_write(Activity *activity, char *filename) {
FileFormat format = file_format_from_name(filename);
Expand All @@ -64,11 +54,13 @@ int activity_write(Activity *activity, char *filename) {
return activity_write_format(activity, filename, format);
}

int activity_read_format(Activity *activity, char *filename, FileFormat format) {
int activity_read_format(Activity *activity, char *filename,
FileFormat format) {
return readers[format](filename, activity);
}

int activity_write_format(Activity *activity, char *filename, FileFormat format) {
int activity_write_format(Activity *activity, char *filename,
FileFormat format) {
return writers[format](filename, activity);
}

Expand Down Expand Up @@ -131,7 +123,7 @@ int activity_add_point(Activity *a, uint32_t timestamp, double latitude,
// TODO
int activity_add_lap(uint32_t lap) {
if (activity->laps) {
// see if theres enough space else realloc
// see if theres enough space else realloc
} else {
// alloc a certain amount of space
}
Expand Down
8 changes: 7 additions & 1 deletion activity.h
Expand Up @@ -118,7 +118,13 @@ typedef struct {
typedef int (*ReadFn)(char *, Activity *);
typedef int (*WriteFn)(char *, Activity *);

typedef enum { CSV, GPX, TCX, FIT, UnknownFileFormat } FileFormat;
typedef enum {
CSV,
GPX,
TCX,
FIT,
UnknownFileFormat
} FileFormat;

#define activity_new() \
{ UnknownSport, NULL, NULL }
Expand Down
8 changes: 2 additions & 6 deletions csv.c
@@ -1,9 +1,5 @@
#include "csv.h"

int csv_read(char *filename, Activity *activity) {
return 1;
}
int csv_read(char *filename, Activity *activity) { return 1; }

int csv_write(char *filename, Activity *activity) {
return 1;
}
int csv_write(char *filename, Activity *activity) { return 1; }
8 changes: 2 additions & 6 deletions fit.c
@@ -1,9 +1,5 @@
#include "fit.h"

int fit_read(char *filename, Activity *activity) {
return 1;
}
int fit_read(char *filename, Activity *activity) { return 1; }

int fit_write(char *filename, Activity *activity) {
return 1;
}
int fit_write(char *filename, Activity *activity) { return 1; }
19 changes: 11 additions & 8 deletions gpx.c
Expand Up @@ -6,7 +6,10 @@
#include "mxml.h"
#include "util.h"

typedef enum { false, true } bool;
typedef enum {
false,
true
} bool;

typedef struct {
bool metadata;
Expand Down Expand Up @@ -67,19 +70,19 @@ static int sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *sax_data) {
state->data.altitude = (int32_t)(strtod(data, &end) * 1000);
if (*end) state->data.altitude = UNSET_ALTITUDE;
} else if (!strcmp(name, "gpxtpx:hr")) {
state->data.heart_rate = (uint8_t)strtod(data, &end);
state->data.heart_rate = (uint8_t) strtod(data, &end);
if (*end) state->data.heart_rate = UNSET_HEART_RATE;
} else if (!strcmp(name, "gpxdata:hr")) {
state->data.heart_rate = (uint8_t)strtod(data, &end);
state->data.heart_rate = (uint8_t) strtod(data, &end);
if (*end) state->data.heart_rate = UNSET_HEART_RATE;
} else if (!strcmp(name, "gpxdata:temp")) {
state->data.temperature = (int8_t)strtod(data, &end);
state->data.temperature = (int8_t) strtod(data, &end);
if (*end) state->data.temperature = UNSET_TEMPERATURE;
} else if (!strcmp(name, "gpxdata:cadence")) {
state->data.cadence = (uint8_t)strtod(data, &end);
state->data.cadence = (uint8_t) strtod(data, &end);
if (*end) state->data.cadence = UNSET_CADENCE;
} else if (!strcmp(name, "gpxdata:bikepower")) {
state->data.power = (uint16_t)strtod(data, &end);
state->data.power = (uint16_t) strtod(data, &end);
if (*end) state->data.power = UNSET_POWER;
} else if (!strcmp(name, "trkpt")) {
/* TODO */
Expand All @@ -95,8 +98,8 @@ static int sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *sax_data) {

int gpx_read(char *filename, Activity *activity) {
FILE *f = NULL;
State state = {false /* metadata */, true /* first_element */,
true /* first_time */, UNSET_DATA_POINT};
State state = { false /* metadata */, true /* first_element */,
true /* first_time */, UNSET_DATA_POINT };
if (!(f = fopen(filename, "r"))) {
return 1;
}
Expand Down
8 changes: 2 additions & 6 deletions tcx.c
@@ -1,9 +1,5 @@
#include "tcx.h"

int tcx_read(char *filename, Activity *activity) {
return 1;
}
int tcx_read(char *filename, Activity *activity) { return 1; }

int tcx_write(char *filename, Activity *activity) {
return 1;
}
int tcx_write(char *filename, Activity *activity) { return 1; }
7 changes: 3 additions & 4 deletions util.c
Expand Up @@ -8,13 +8,12 @@
uint32_t parse_timestamp(const char *date) {
unsigned long timestamp;
int offset;
return (parse_date_basic(date, &timestamp, &offset) < 0)
? 0
: (uint32_t)timestamp;
return (parse_date_basic(date, &timestamp, &offset) < 0) ? 0 : (uint32_t)
timestamp;
}

int format_timestamp(char *buf, uint32_t timestamp) {
time_t time = (time_t)timestamp;
time_t time = (time_t) timestamp;
struct tm *tm = gmtime(&time);
return !strftime(buf, 21, "%Y-%m-%dT%H:%M:%SZ", tm) ? -1 : 0;
}

0 comments on commit 952b8c7

Please sign in to comment.