Permalink
Browse files

Added static and const keywords in bunches of places

This helps in self-documenting the interfaces, keeping the
global namespace clean, and providing optimization hints
to the compiler.
  • Loading branch information...
1 parent 4cc0312 commit df88775fc1f48e5a19b356a8c5ceed925a168e80 @dfandrich dfandrich committed Aug 18, 2012
Showing with 82 additions and 88 deletions.
  1. +15 −16 correlate.c
  2. +1 −1 correlate.h
  3. +7 −6 exif-gps.cpp
  4. +7 −6 exif-gps.h
  5. +21 −22 gpx-read.c
  6. +1 −1 gpx-read.h
  7. +16 −20 gui.c
  8. +5 −5 gui.h
  9. +7 −9 main-command.c
  10. +1 −1 unixtime.c
  11. +1 −1 unixtime.h
View
@@ -36,20 +36,21 @@
#include "unixtime.h"
/* Internal functions used to make it work. */
-void Round(struct GPSPoint* First, struct GPSPoint* Result,
- struct CorrelateOptions* Options, time_t PhotoTime);
-void Interpolate(struct GPSPoint* First, struct GPSPoint* Result,
- struct CorrelateOptions* Options, time_t PhotoTime);
+static void Round(const struct GPSPoint* First, struct GPSPoint* Result,
+ time_t PhotoTime);
+static void Interpolate(const struct GPSPoint* First, struct GPSPoint* Result,
+ time_t PhotoTime);
/* This function returns a GPSPoint with the point selected for the
* file. This allows us to do funky stuff like not actually write
* the files - ie, just correlate and keep into memory... */
-struct GPSPoint* CorrelatePhoto(char* Filename,
+struct GPSPoint* CorrelatePhoto(const char* Filename,
struct CorrelateOptions* Options)
{
/* Read out the timestamp from the EXIF data. */
- char* TimeTemp; int IncludesGPS = 0;
+ char* TimeTemp;
+ int IncludesGPS = 0;
TimeTemp = ReadExifDate(Filename, &IncludesGPS);
if (!TimeTemp)
{
@@ -144,7 +145,7 @@ struct GPSPoint* CorrelatePhoto(char* Filename,
/* Time to run through the list, and see if our PhotoTime
* is in between two points. Alternately, it might be
* exactly on a point... even better... */
- struct GPSPoint* Search;
+ const struct GPSPoint* Search;
struct GPSPoint* Actual = malloc(sizeof(struct GPSPoint));
Options->Result = CORR_NOMATCH; /* For convenience later */
@@ -232,14 +233,12 @@ struct GPSPoint* CorrelatePhoto(char* Filename,
if (Options->NoInterpolate)
{
/* No interpolation. Round. */
- Round(Search, Actual,
- Options, PhotoTime);
+ Round(Search, Actual, PhotoTime);
Options->Result = CORR_ROUND;
break;
} else {
/* Interpolate away! */
- Interpolate(Search, Actual,
- Options, PhotoTime);
+ Interpolate(Search, Actual, PhotoTime);
Options->Result = CORR_INTERPOLATED;
break;
}
@@ -279,12 +278,12 @@ struct GPSPoint* CorrelatePhoto(char* Filename,
return NULL;
};
-void Round(struct GPSPoint* First, struct GPSPoint* Result,
- struct CorrelateOptions* Options, time_t PhotoTime)
+void Round(const struct GPSPoint* First, struct GPSPoint* Result,
+ time_t PhotoTime)
{
/* Round the point between the two points - ie, it will end
* up being one or the other point. */
- struct GPSPoint* CopyFrom = NULL;
+ const struct GPSPoint* CopyFrom = NULL;
/* Determine the difference between the two points.
* We're using the scale function used by interpolate.
@@ -312,8 +311,8 @@ void Round(struct GPSPoint* First, struct GPSPoint* Result,
}
-void Interpolate(struct GPSPoint* First, struct GPSPoint* Result,
- struct CorrelateOptions* Options, time_t PhotoTime)
+void Interpolate(const struct GPSPoint* First, struct GPSPoint* Result,
+ time_t PhotoTime)
{
/* Interpolate between the two points. The first point
* is First, the other First->Next. Results into Result. */
View
@@ -77,6 +77,6 @@ struct CorrelateOptions {
#define CORR_GPSDATAEXISTS 8
-struct GPSPoint* CorrelatePhoto(char* Filename,
+struct GPSPoint* CorrelatePhoto(const char* Filename,
struct CorrelateOptions* Options);
View
@@ -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.
Exiv2::ExifData ExifRead;
@@ -143,7 +143,7 @@ char* ReadExifDate(char* File, int* IncludesGPS)
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
// much more data than the last, specifically
@@ -282,7 +282,7 @@ char* ReadExifData(char* File, double* Lat, double* Long, double* Elev, int* Inc
// This function is for the --fix-datestamp option.
// 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
// much more data than the last, specifically
@@ -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...
@@ -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...
@@ -728,7 +729,7 @@ int WriteFixedDatestamp(char* File, time_t Time)
return 1;
}
-int RemoveGPSExif(char* File, int NoChangeMtime)
+int RemoveGPSExif(const char* File, int NoChangeMtime)
{
struct stat statbuf;
struct stat statbuf2;
View
@@ -31,12 +31,13 @@
extern "C" {
#endif
-char* ReadExifDate(char* File, int* IncludesGPS);
-char* ReadExifData(char* File, double* Lat, double* Long, double* Elevation, int* IncludesGPS);
-char* ReadGPSTimestamp(char* File, char* DateStamp, char* TimeStamp, int* IncludesGPS);
-int WriteGPSData(char* File, struct GPSPoint* Point, char* Datum, int NoChangeMtime, int DegMinSecs);
-int WriteFixedDatestamp(char* File, time_t TimeStamp);
-int RemoveGPSExif(char* File, int NoChangeMtime);
+char* ReadExifDate(const char* File, int* IncludesGPS);
+char* ReadExifData(const char* File, double* Lat, double* Long, double* Elevation, int* IncludesGPS);
+char* ReadGPSTimestamp(const char* File, char* DateStamp, char* TimeStamp, int* IncludesGPS);
+int WriteGPSData(const char* File, const struct GPSPoint* Point,
+ const char* Datum, int NoChangeMtime, int DegMinSecs);
+int WriteFixedDatestamp(const char* File, time_t TimeStamp);
+int RemoveGPSExif(const char* File, int NoChangeMtime);
#ifdef __cplusplus
}
View
@@ -35,26 +35,26 @@
#include "unixtime.h"
#include "gpsstructure.h"
-struct GPSPoint* FirstPoint;
-struct GPSPoint* LastPoint;
+static struct GPSPoint* FirstPoint;
+static struct GPSPoint* LastPoint;
-void ExtractTrackPoints(xmlNodePtr Start)
+static void ExtractTrackPoints(xmlNodePtr Start)
{
/* The pointer passed to us should be the start
* of a heap of trkpt's. So walk though them,
* extracting what we need. */
xmlNodePtr Current = NULL;
xmlNodePtr CCurrent = NULL;
xmlAttrPtr Properties = NULL;
- char* Lat;
- char* Long;
- char* Elev;
- char* Time;
+ const char* Lat;
+ const char* Long;
+ const char* Elev;
+ const char* Time;
for (Current = Start; Current; Current = Current->next)
{
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! */
@@ -72,13 +72,13 @@ void ExtractTrackPoints(xmlNodePtr Start)
Properties;
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;
}
}
@@ -90,15 +90,15 @@ void ExtractTrackPoints(xmlNodePtr Start)
CCurrent;
CCurrent = CCurrent->next)
{
- if (strcmp((char *)CCurrent->name, "ele") == 0)
+ if (strcmp((const char *)CCurrent->name, "ele") == 0)
{
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)
- Time = (char *)CCurrent->children->content;
+ Time = (const char *)CCurrent->children->content;
}
}
@@ -153,15 +153,15 @@ void ExtractTrackPoints(xmlNodePtr Start)
/* Return control to the recursive function... */
}
-void FindTrackSeg(xmlNodePtr Start)
+static void FindTrackSeg(xmlNodePtr Start)
{
/* Go recursive till we find a <trgseg> tag. */
xmlNodePtr Current = NULL;
for (Current = Start; Current; Current = Current->next)
{
if ((Current->type == XML_ELEMENT_NODE) &&
- (strcmp((char *)Current->name, "trkseg") == 0))
+ (strcmp((const char *)Current->name, "trkseg") == 0))
{
/* Found it... the children should
* all be trkpt's. */
@@ -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. */
LIBXML_TEST_VERSION
@@ -209,7 +209,7 @@ struct GPSPoint* ReadGPX(char* File)
/* Check that this is indeed a GPX - the root node
* should be "gpx". */
- if (strcmp((char *)GPXRoot->name, "gpx") == 0)
+ if (strcmp((const char *)GPXRoot->name, "gpx") == 0)
{
/* Ok, it is a GPX file. */
} else {
@@ -246,7 +246,7 @@ struct GPSPoint* ReadGPX(char* File)
FirstPoint = NULL;
LastPoint = NULL;
- char* OldLocale = setlocale(LC_NUMERIC, NULL);
+ const char* OldLocale = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, "C");
FindTrackSeg(GPXRoot);
@@ -275,4 +275,3 @@ void FreePointList(struct GPSPoint* List)
CurrentFree = NextFree;
}
};
-
View
@@ -25,5 +25,5 @@
* 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);
Oops, something went wrong.

0 comments on commit df88775

Please sign in to comment.