diff --git a/aegisub/build/libaegisub/libaegisub.vcxproj b/aegisub/build/libaegisub/libaegisub.vcxproj
index 0f4655767..0861fc556 100644
--- a/aegisub/build/libaegisub/libaegisub.vcxproj
+++ b/aegisub/build/libaegisub/libaegisub.vcxproj
@@ -57,7 +57,6 @@
-
@@ -78,6 +77,7 @@
+
diff --git a/aegisub/build/libaegisub/libaegisub.vcxproj.filters b/aegisub/build/libaegisub/libaegisub.vcxproj.filters
index 75b180c34..559cec348 100644
--- a/aegisub/build/libaegisub/libaegisub.vcxproj.filters
+++ b/aegisub/build/libaegisub/libaegisub.vcxproj.filters
@@ -74,9 +74,6 @@
Header Files
-
- Header Files
-
Header Files
@@ -152,6 +149,9 @@
Header Files
+
+ Header Files
+
diff --git a/aegisub/libaegisub/common/log.cpp b/aegisub/libaegisub/common/log.cpp
index 8486a575e..5430e09d4 100644
--- a/aegisub/libaegisub/common/log.cpp
+++ b/aegisub/libaegisub/common/log.cpp
@@ -23,7 +23,6 @@
#include "libaegisub/cajun/elements.h"
#include "libaegisub/cajun/writer.h"
#include "libaegisub/io.h"
-#include "libaegisub/types.h"
#include "libaegisub/util.h"
#include
@@ -45,7 +44,7 @@ const char *Severity_ID = "EAWID";
SinkMessage::SinkMessage(const char *section, Severity severity,
const char *file, const char *func, int line,
- agi_timeval tv)
+ timeval tv)
: section(section)
, severity(severity)
, file(file)
@@ -97,9 +96,7 @@ Message::Message(const char *section,
, buf(new char[len])
, msg(buf, len)
{
- agi_timeval tv;
- util::time_log(tv);
- sm = new SinkMessage(section, severity, file, func, line, tv);
+ sm = new SinkMessage(section, severity, file, func, line, util::time_log());
}
Message::~Message() {
@@ -109,18 +106,17 @@ Message::~Message() {
}
JsonEmitter::JsonEmitter(agi::fs::path const& directory, const agi::log::LogSink *log_sink)
-: directory(directory)
+: time_start(util::time_log())
+, directory(directory)
, log_sink(log_sink)
{
- util::time_log(time_start);
}
JsonEmitter::~JsonEmitter() {
json::Object root;
json::Array &array = root["log"];
- agi_timeval time_close;
- util::time_log(time_close);
+ auto time_close = util::time_log();
Sink const& sink = *log_sink->GetSink();
for (unsigned int i=0; i < sink.size(); i++) {
diff --git a/aegisub/libaegisub/include/libaegisub/log.h b/aegisub/libaegisub/include/libaegisub/log.h
index 197f4539a..5c42824d6 100644
--- a/aegisub/libaegisub/include/libaegisub/log.h
+++ b/aegisub/libaegisub/include/libaegisub/log.h
@@ -17,7 +17,7 @@
/// @ingroup libaegisub
#include
-#include
+#include
#include
#include
@@ -80,8 +80,7 @@ public:
/// @param func Function name
/// @param line Source line
/// @param tv Log time
- SinkMessage(const char *section, Severity severity, const char *file,
- const char *func, int line, agi_timeval tv);
+ SinkMessage(const char *section, Severity severity, const char *file, const char *func, int line, timeval tv);
/// Destructor
~SinkMessage();
@@ -144,10 +143,10 @@ public:
/// A simple emitter which writes the log to a file in json format when it's destroyed
class JsonEmitter : public Emitter {
/// Init time
- agi_timeval time_start;
+ timeval time_start;
/// Directory to write the log file in
- agi::fs::path directory;
+ const agi::fs::path directory;
/// Parent sink to get messages from
const agi::log::LogSink *log_sink;
diff --git a/aegisub/libaegisub/include/libaegisub/time.h b/aegisub/libaegisub/include/libaegisub/time.h
new file mode 100644
index 000000000..0152c8f81
--- /dev/null
+++ b/aegisub/libaegisub/include/libaegisub/time.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2013, Thomas Goyne
+//
+// Permission to use, copy, modify, and distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+//
+// Aegisub Project http://www.aegisub.org/
+
+#pragma once
+
+#ifdef HAVE_SYS_TIME_H
+# include
+#else
+# include
+#endif
+
+#ifdef _WIN32
+// timeval on windows is defined by winsock, which is a bit much to drag in for
+// a pair of longs
+struct agi_timeval {
+ long tv_sec;
+ long tv_usec;
+};
+#else
+typedef timeval agi_timeval;
+#endif
diff --git a/aegisub/libaegisub/include/libaegisub/types.h b/aegisub/libaegisub/include/libaegisub/types.h
deleted file mode 100644
index 85ac1d9ef..000000000
--- a/aegisub/libaegisub/include/libaegisub/types.h
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) 2010, Amar Takhar
-//
-// Permission to use, copy, modify, and distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-/// @file types.h
-/// @brief Platform specific types.
-/// @ingroup libaegisub
-
-#ifdef HAVE_SYS_TIME_H
-# include
-#else
-# include
-#endif
-
-
-#pragma once
-
-namespace agi {
- namespace type {
-
- namespace win {
-typedef struct timeval {
- long tv_sec; ///< seconds
- long tv_usec; ///< microseconds
-} timeval;
-
-
-typedef struct tm {
- int tm_sec; ///< seconds (0-59)
- int tm_min; ///< minutes (0-59)
- int tm_hour; ///< hours (0-23)
- int tm_mday; ///< day of the month (1-31)
- int tm_mon; ///< months since january (0-11)
- int tm_year; ///< years since 1900
- int tm_wday; ///< day of the week since sunday (0-6)
- int tm_yday; ///< days since january 1 (0-365)
- int tm_isdst; ///< whether in DST or not
- long tm_gmtoff; ///< GMT offset in seconds
- char *tm_zone; ///< TZ abrivation
-} tm;
-
- } // namespace win
-
-
-
- // u_nix beacuse some compilers set "unix" to 1 if it's unix. -> ARGH.
- namespace u_nix {
- } // namespace unix
-
- namespace osx {
- } // namespace osx
-
-
- } // namespace type
-} // namespace agi
-
-
-#ifdef _WIN32
-
-typedef agi::type::win::timeval agi_timeval;
-
-#else // Unix / OSX
-
-typedef timeval agi_timeval;
-
-#endif // if _WIN32
diff --git a/aegisub/libaegisub/include/libaegisub/util.h b/aegisub/libaegisub/include/libaegisub/util.h
index f622dfa95..ff71d9658 100644
--- a/aegisub/libaegisub/include/libaegisub/util.h
+++ b/aegisub/libaegisub/include/libaegisub/util.h
@@ -16,12 +16,12 @@
/// @brief Public interface for general utilities.
/// @ingroup libaegisub
+#include
+
#include
#include
#include
-#include
-
struct tm;
namespace agi {
@@ -30,8 +30,7 @@ namespace agi {
template inline T mid(T a, T b, T c) { return std::max(a, std::min(b, c)); }
/// Get time suitable for logging mechanisms.
- /// @param tv timeval
- void time_log(agi_timeval &tv);
+ agi_timeval time_log();
bool try_parse(std::string const& str, double *out);
bool try_parse(std::string const& str, int *out);
diff --git a/aegisub/libaegisub/unix/util.cpp b/aegisub/libaegisub/unix/util.cpp
index 4511637b0..7ccaafbad 100644
--- a/aegisub/libaegisub/unix/util.cpp
+++ b/aegisub/libaegisub/unix/util.cpp
@@ -22,8 +22,10 @@
namespace agi { namespace util {
-void time_log(timeval &tv) {
- gettimeofday(&tv, (struct timezone *)NULL);
+timeval time_log() {
+ timeval tv;
+ gettimeofday(&tv, nullptr);
+ return tv;
}
} }
diff --git a/aegisub/libaegisub/windows/util_win.cpp b/aegisub/libaegisub/windows/util_win.cpp
index b416cb089..3abaacb24 100644
--- a/aegisub/libaegisub/windows/util_win.cpp
+++ b/aegisub/libaegisub/windows/util_win.cpp
@@ -16,12 +16,12 @@
/// @brief Windows utility methods.
/// @ingroup libaegisub windows
+#include "../config.h"
+
+#include "libaegisub/util.h"
#include "libaegisub/util_win.h"
-#include
-
#include "libaegisub/charset_conv_win.h"
-#include "libaegisub/types.h"
namespace agi {
namespace util {
@@ -44,13 +44,8 @@ std::string ErrorString(DWORD error) {
/// @brief Get seconds and microseconds.
/// @param tv[out] agi_timeval struct
/// This code is from http://www.suacommunity.com/dictionary/gettimeofday-entry.php
-void time_log(agi_timeval &tv) {
-#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
+agi_timeval time_log() {
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
-#else
-#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
-#endif
-
// Define a structure to receive the current Windows filetime
FILETIME ft;
@@ -75,8 +70,8 @@ void time_log(agi_timeval &tv) {
// Finally change microseconds to seconds and place in the seconds value.
// The modulus picks up the microseconds.
- tv.tv_sec = (long)(tmpres / 1000000UL);
- tv.tv_usec = (long)(tmpres % 1000000UL);
+ agi_timeval tv = { (long)(tmpres / 1000000UL), (long)(tmpres % 1000000UL) };
+ return tv;
}
} // namespace io
diff --git a/aegisub/tests/libaegisub_util.cpp b/aegisub/tests/libaegisub_util.cpp
index 82af8e0d4..36935c273 100644
--- a/aegisub/tests/libaegisub_util.cpp
+++ b/aegisub/tests/libaegisub_util.cpp
@@ -14,6 +14,8 @@
//
// Aegisub Project http://www.aegisub.org/
+#include "../libaegisub/config.h"
+
#include
#include "main.h"