Skip to content

Commit

Permalink
Added static and const keywords in bunches of places
Browse files Browse the repository at this point in the history
This helps in self-documenting the interfaces, keeping the
global namespace clean, and providing optimization hints
to the compiler.
  • Loading branch information
dfandrich committed Aug 18, 2012
1 parent 4cc0312 commit df88775
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 88 deletions.
31 changes: 15 additions & 16 deletions correlate.c
Expand Up @@ -36,20 +36,21 @@
#include "unixtime.h" #include "unixtime.h"


/* Internal functions used to make it work. */ /* Internal functions used to make it work. */
void Round(struct GPSPoint* First, struct GPSPoint* Result, static void Round(const struct GPSPoint* First, struct GPSPoint* Result,
struct CorrelateOptions* Options, time_t PhotoTime); time_t PhotoTime);
void Interpolate(struct GPSPoint* First, struct GPSPoint* Result, static void Interpolate(const struct GPSPoint* First, struct GPSPoint* Result,
struct CorrelateOptions* Options, time_t PhotoTime); time_t PhotoTime);


/* This function returns a GPSPoint with the point selected for the /* This function returns a GPSPoint with the point selected for the
* file. This allows us to do funky stuff like not actually write * file. This allows us to do funky stuff like not actually write
* the files - ie, just correlate and keep into memory... */ * the files - ie, just correlate and keep into memory... */


struct GPSPoint* CorrelatePhoto(char* Filename, struct GPSPoint* CorrelatePhoto(const char* Filename,
struct CorrelateOptions* Options) struct CorrelateOptions* Options)
{ {
/* Read out the timestamp from the EXIF data. */ /* Read out the timestamp from the EXIF data. */
char* TimeTemp; int IncludesGPS = 0; char* TimeTemp;
int IncludesGPS = 0;
TimeTemp = ReadExifDate(Filename, &IncludesGPS); TimeTemp = ReadExifDate(Filename, &IncludesGPS);
if (!TimeTemp) if (!TimeTemp)
{ {
Expand Down Expand Up @@ -144,7 +145,7 @@ struct GPSPoint* CorrelatePhoto(char* Filename,
/* Time to run through the list, and see if our PhotoTime /* Time to run through the list, and see if our PhotoTime
* is in between two points. Alternately, it might be * is in between two points. Alternately, it might be
* exactly on a point... even better... */ * exactly on a point... even better... */
struct GPSPoint* Search; const struct GPSPoint* Search;
struct GPSPoint* Actual = malloc(sizeof(struct GPSPoint)); struct GPSPoint* Actual = malloc(sizeof(struct GPSPoint));


Options->Result = CORR_NOMATCH; /* For convenience later */ Options->Result = CORR_NOMATCH; /* For convenience later */
Expand Down Expand Up @@ -232,14 +233,12 @@ struct GPSPoint* CorrelatePhoto(char* Filename,
if (Options->NoInterpolate) if (Options->NoInterpolate)
{ {
/* No interpolation. Round. */ /* No interpolation. Round. */
Round(Search, Actual, Round(Search, Actual, PhotoTime);
Options, PhotoTime);
Options->Result = CORR_ROUND; Options->Result = CORR_ROUND;
break; break;
} else { } else {
/* Interpolate away! */ /* Interpolate away! */
Interpolate(Search, Actual, Interpolate(Search, Actual, PhotoTime);
Options, PhotoTime);
Options->Result = CORR_INTERPOLATED; Options->Result = CORR_INTERPOLATED;
break; break;
} }
Expand Down Expand Up @@ -279,12 +278,12 @@ struct GPSPoint* CorrelatePhoto(char* Filename,
return NULL; return NULL;
}; };


void Round(struct GPSPoint* First, struct GPSPoint* Result, void Round(const struct GPSPoint* First, struct GPSPoint* Result,
struct CorrelateOptions* Options, time_t PhotoTime) time_t PhotoTime)
{ {
/* Round the point between the two points - ie, it will end /* Round the point between the two points - ie, it will end
* up being one or the other point. */ * up being one or the other point. */
struct GPSPoint* CopyFrom = NULL; const struct GPSPoint* CopyFrom = NULL;


/* Determine the difference between the two points. /* Determine the difference between the two points.
* We're using the scale function used by interpolate. * We're using the scale function used by interpolate.
Expand Down Expand Up @@ -312,8 +311,8 @@ void Round(struct GPSPoint* First, struct GPSPoint* Result,


} }


void Interpolate(struct GPSPoint* First, struct GPSPoint* Result, void Interpolate(const struct GPSPoint* First, struct GPSPoint* Result,
struct CorrelateOptions* Options, time_t PhotoTime) time_t PhotoTime)
{ {
/* Interpolate between the two points. The first point /* Interpolate between the two points. The first point
* is First, the other First->Next. Results into Result. */ * is First, the other First->Next. Results into Result. */
Expand Down
2 changes: 1 addition & 1 deletion correlate.h
Expand Up @@ -77,6 +77,6 @@ struct CorrelateOptions {
#define CORR_GPSDATAEXISTS 8 #define CORR_GPSDATAEXISTS 8




struct GPSPoint* CorrelatePhoto(char* Filename, struct GPSPoint* CorrelatePhoto(const char* Filename,
struct CorrelateOptions* Options); struct CorrelateOptions* Options);


13 changes: 7 additions & 6 deletions exif-gps.cpp
Expand Up @@ -83,7 +83,7 @@ int main(int argc, char* argv[])
}; };
*/ */


char* ReadExifDate(char* File, int* IncludesGPS) char* ReadExifDate(const char* File, int* IncludesGPS)
{ {
// Open and read the file. // Open and read the file.
Exiv2::ExifData ExifRead; Exiv2::ExifData ExifRead;
Expand Down Expand Up @@ -143,7 +143,7 @@ char* ReadExifDate(char* File, int* IncludesGPS)
return Copy; // Its up to the caller to free this. return Copy; // Its up to the caller to free this.
}; };


char* ReadExifData(char* File, double* Lat, double* Long, double* Elev, int* IncludesGPS) char* ReadExifData(const char* File, double* Lat, double* Long, double* Elev, int* IncludesGPS)
{ {
// This function varies in that it reads // This function varies in that it reads
// much more data than the last, specifically // much more data than the last, specifically
Expand Down Expand Up @@ -282,7 +282,7 @@ char* ReadExifData(char* File, double* Lat, double* Long, double* Elev, int* Inc


// This function is for the --fix-datestamp option. // This function is for the --fix-datestamp option.
// DateStamp and TimeStamp should be 12-char strings. // DateStamp and TimeStamp should be 12-char strings.
char* ReadGPSTimestamp(char* File, char* DateStamp, char* TimeStamp, int* IncludesGPS) char* ReadGPSTimestamp(const char* File, char* DateStamp, char* TimeStamp, int* IncludesGPS)
{ {
// This function varies in that it reads // This function varies in that it reads
// much more data than the last, specifically // much more data than the last, specifically
Expand Down Expand Up @@ -436,7 +436,8 @@ void ConvertToRational(double Number,


} }


int WriteGPSData(char* File, struct GPSPoint* Point, char* Datum, int NoChangeMtime, int DegMinSecs) int WriteGPSData(const char* File, const struct GPSPoint* Point,
const char* Datum, int NoChangeMtime, int DegMinSecs)
{ {
// Write the GPS data to the file... // Write the GPS data to the file...


Expand Down Expand Up @@ -651,7 +652,7 @@ int WriteGPSData(char* File, struct GPSPoint* Point, char* Datum, int NoChangeMt


}; };


int WriteFixedDatestamp(char* File, time_t Time) int WriteFixedDatestamp(const char* File, time_t Time)
{ {
// Write the GPS data to the file... // Write the GPS data to the file...


Expand Down Expand Up @@ -728,7 +729,7 @@ int WriteFixedDatestamp(char* File, time_t Time)
return 1; return 1;
} }


int RemoveGPSExif(char* File, int NoChangeMtime) int RemoveGPSExif(const char* File, int NoChangeMtime)
{ {
struct stat statbuf; struct stat statbuf;
struct stat statbuf2; struct stat statbuf2;
Expand Down
13 changes: 7 additions & 6 deletions exif-gps.h
Expand Up @@ -31,12 +31,13 @@
extern "C" { extern "C" {
#endif #endif


char* ReadExifDate(char* File, int* IncludesGPS); char* ReadExifDate(const char* File, int* IncludesGPS);
char* ReadExifData(char* File, double* Lat, double* Long, double* Elevation, int* IncludesGPS); char* ReadExifData(const char* File, double* Lat, double* Long, double* Elevation, int* IncludesGPS);
char* ReadGPSTimestamp(char* File, char* DateStamp, char* TimeStamp, int* IncludesGPS); char* ReadGPSTimestamp(const char* File, char* DateStamp, char* TimeStamp, int* IncludesGPS);
int WriteGPSData(char* File, struct GPSPoint* Point, char* Datum, int NoChangeMtime, int DegMinSecs); int WriteGPSData(const char* File, const struct GPSPoint* Point,
int WriteFixedDatestamp(char* File, time_t TimeStamp); const char* Datum, int NoChangeMtime, int DegMinSecs);
int RemoveGPSExif(char* File, int NoChangeMtime); int WriteFixedDatestamp(const char* File, time_t TimeStamp);
int RemoveGPSExif(const char* File, int NoChangeMtime);


#ifdef __cplusplus #ifdef __cplusplus
} }
Expand Down
43 changes: 21 additions & 22 deletions gpx-read.c
Expand Up @@ -35,26 +35,26 @@
#include "unixtime.h" #include "unixtime.h"
#include "gpsstructure.h" #include "gpsstructure.h"


struct GPSPoint* FirstPoint; static struct GPSPoint* FirstPoint;
struct GPSPoint* LastPoint; static struct GPSPoint* LastPoint;


void ExtractTrackPoints(xmlNodePtr Start) static void ExtractTrackPoints(xmlNodePtr Start)
{ {
/* The pointer passed to us should be the start /* The pointer passed to us should be the start
* of a heap of trkpt's. So walk though them, * of a heap of trkpt's. So walk though them,
* extracting what we need. */ * extracting what we need. */
xmlNodePtr Current = NULL; xmlNodePtr Current = NULL;
xmlNodePtr CCurrent = NULL; xmlNodePtr CCurrent = NULL;
xmlAttrPtr Properties = NULL; xmlAttrPtr Properties = NULL;
char* Lat; const char* Lat;
char* Long; const char* Long;
char* Elev; const char* Elev;
char* Time; const char* Time;


for (Current = Start; Current; Current = Current->next) for (Current = Start; Current; Current = Current->next)
{ {
if ((Current->type == XML_ELEMENT_NODE) && if ((Current->type == XML_ELEMENT_NODE) &&
(strcmp((char *)Current->name, "trkpt") == 0)) (strcmp((const char *)Current->name, "trkpt") == 0))
{ {
/* This is indeed a trackpoint. Extract! */ /* This is indeed a trackpoint. Extract! */


Expand All @@ -72,13 +72,13 @@ void ExtractTrackPoints(xmlNodePtr Start)
Properties; Properties;
Properties = Properties->next) Properties = Properties->next)
{ {
if (strcmp((char *)Properties->name, "lat") == 0) if (strcmp((const char *)Properties->name, "lat") == 0)
{ {
Lat = (char *)Properties->children->content; Lat = (const char *)Properties->children->content;
} }
if (strcmp((char *)Properties->name, "lon") == 0) if (strcmp((const char *)Properties->name, "lon") == 0)
{ {
Long = (char *)Properties->children->content; Long = (const char *)Properties->children->content;
} }
} }


Expand All @@ -90,15 +90,15 @@ void ExtractTrackPoints(xmlNodePtr Start)
CCurrent; CCurrent;
CCurrent = CCurrent->next) CCurrent = CCurrent->next)
{ {
if (strcmp((char *)CCurrent->name, "ele") == 0) if (strcmp((const char *)CCurrent->name, "ele") == 0)
{ {
if (CCurrent->children) if (CCurrent->children)
Elev = (char *)CCurrent->children->content; Elev = (const char *)CCurrent->children->content;
} }
if (strcmp((char *)CCurrent->name, "time") == 0) if (strcmp((const char *)CCurrent->name, "time") == 0)
{ {
if (CCurrent->children) if (CCurrent->children)
Time = (char *)CCurrent->children->content; Time = (const char *)CCurrent->children->content;
} }
} }


Expand Down Expand Up @@ -153,15 +153,15 @@ void ExtractTrackPoints(xmlNodePtr Start)
/* Return control to the recursive function... */ /* Return control to the recursive function... */
} }


void FindTrackSeg(xmlNodePtr Start) static void FindTrackSeg(xmlNodePtr Start)
{ {
/* Go recursive till we find a <trgseg> tag. */ /* Go recursive till we find a <trgseg> tag. */
xmlNodePtr Current = NULL; xmlNodePtr Current = NULL;


for (Current = Start; Current; Current = Current->next) for (Current = Start; Current; Current = Current->next)
{ {
if ((Current->type == XML_ELEMENT_NODE) && if ((Current->type == XML_ELEMENT_NODE) &&
(strcmp((char *)Current->name, "trkseg") == 0)) (strcmp((const char *)Current->name, "trkseg") == 0))
{ {
/* Found it... the children should /* Found it... the children should
* all be trkpt's. */ * all be trkpt's. */
Expand All @@ -181,7 +181,7 @@ void FindTrackSeg(xmlNodePtr Start)
} }




struct GPSPoint* ReadGPX(char* File) struct GPSPoint* ReadGPX(const char* File)
{ {
/* Init the libxml library. Also checks version. */ /* Init the libxml library. Also checks version. */
LIBXML_TEST_VERSION LIBXML_TEST_VERSION
Expand Down Expand Up @@ -209,7 +209,7 @@ struct GPSPoint* ReadGPX(char* File)


/* Check that this is indeed a GPX - the root node /* Check that this is indeed a GPX - the root node
* should be "gpx". */ * should be "gpx". */
if (strcmp((char *)GPXRoot->name, "gpx") == 0) if (strcmp((const char *)GPXRoot->name, "gpx") == 0)
{ {
/* Ok, it is a GPX file. */ /* Ok, it is a GPX file. */
} else { } else {
Expand Down Expand Up @@ -246,7 +246,7 @@ struct GPSPoint* ReadGPX(char* File)
FirstPoint = NULL; FirstPoint = NULL;
LastPoint = NULL; LastPoint = NULL;


char* OldLocale = setlocale(LC_NUMERIC, NULL); const char* OldLocale = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");


FindTrackSeg(GPXRoot); FindTrackSeg(GPXRoot);
Expand Down Expand Up @@ -275,4 +275,3 @@ void FreePointList(struct GPSPoint* List)
CurrentFree = NextFree; CurrentFree = NextFree;
} }
}; };

2 changes: 1 addition & 1 deletion gpx-read.h
Expand Up @@ -25,5 +25,5 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */


struct GPSPoint* ReadGPX(char* File); struct GPSPoint* ReadGPX(const char* File);
void FreePointList(struct GPSPoint* List); void FreePointList(struct GPSPoint* List);

0 comments on commit df88775

Please sign in to comment.