Added Lanczos interpolation to the NCSF plugin, and cleaned up a bit of the other code, as well as removing pstdint.h since it's no longer needed.
Added Lanczos interpolation to the NCSF plugin, and cleaned up a bit of the other code, as well as removing pstdint.h since it's no longer needed.

--- a/src/in_2sf/XSFPlayer_2SF.cpp
+++ b/src/in_2sf/XSFPlayer_2SF.cpp
@@ -1,7 +1,7 @@
 /*
  * xSF - 2SF Player
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-04-17
+ * Last modification on 2013-04-23
  *
  * Based on a modified vio2sf v0.22c
  *
@@ -185,12 +185,12 @@
 
 XSFPlayer_2SF::XSFPlayer_2SF(const std::string &filename) : XSFPlayer()
 {
-	this->xSF = new XSFFile(filename, 4, 8);
+	this->xSF.reset(new XSFFile(filename, 4, 8));
 }
 
 XSFPlayer_2SF::XSFPlayer_2SF(const std::wstring &filename) : XSFPlayer()
 {
-	this->xSF = new XSFFile(filename, 4, 8);
+	this->xSF.reset(new XSFFile(filename, 4, 8));
 }
 
 bool XSFPlayer_2SF::Load()
@@ -199,7 +199,7 @@
 	sndifwork.sync_type = this->xSF->GetTagValue("_2sf_sync_type", 0);
 
 	sndifwork.xfs_load = false;
-	if (!this->Load2SF(this->xSF))
+	if (!this->Load2SF(this->xSF.get()))
 		return false;
 
 	if (NDS_Init())

--- a/src/in_2sf/desmume/metaspu/SoundTouch/RateTransposer.cpp
+++ b/src/in_2sf/desmume/metaspu/SoundTouch/RateTransposer.cpp
@@ -221,7 +221,7 @@
 {
 	if (!nSamples)
 		return;
-	assert(this->pAAFilter.get());
+	assert(this->pAAFilter);
 
 	// If anti-alias filter is turned off, simply transpose without applying
 	// the filter

--- a/src/in_2sf/desmume/metaspu/SoundTouch/STTypes.h
+++ b/src/in_2sf/desmume/metaspu/SoundTouch/STTypes.h
@@ -39,7 +39,7 @@
 #ifndef STTypes_H
 #define STTypes_H
 
-#include "pstdint.h"
+#include <cstdint>
 
 namespace soundtouch
 {

--- a/src/in_2sf/desmume/metaspu/SoundTouch/SoundTouch.cpp
+++ b/src/in_2sf/desmume/metaspu/SoundTouch/SoundTouch.cpp
@@ -328,7 +328,7 @@
 /// Returns number of samples currently unprocessed.
 uint32_t SoundTouch::numUnprocessedSamples() const
 {
-	if (this->pTDStretch.get())
+	if (this->pTDStretch)
 	{
 		FIFOSamplePipe *psp = this->pTDStretch->getInput();
 		if (psp)

--- a/src/in_2sf/desmume/types.h
+++ b/src/in_2sf/desmume/types.h
@@ -19,7 +19,7 @@
 #ifndef TYPES_HPP
 #define TYPES_HPP
 
-#include "pstdint.h"
+#include <cstdint>
 
 #ifdef _WINDOWS
 # define HAVE_LIBAGG

--- a/src/in_2sf/desmume/utils/AsmJit/core/build.h
+++ b/src/in_2sf/desmume/utils/AsmJit/core/build.h
@@ -164,7 +164,7 @@
 // [AsmJit - Types]
 // ============================================================================
 
-#include "pstdint.h"
+#include <cstdint>
 
 #ifdef ASMJIT_X86
 typedef int32_t sysint_t;

--- a/src/in_2sf/desmume/utils/dlditool.cpp
+++ b/src/in_2sf/desmume/utils/dlditool.cpp
@@ -60,7 +60,7 @@
 #include <cstdlib>
 #include <cstdarg>
 
-#include "pstdint.h"
+#include <cstdint>
 #ifndef _MSC_VER
 # include <unistd.h>
 # include <sys/param.h>

--- a/src/in_gsf/XSFPlayer_GSF.cpp
+++ b/src/in_gsf/XSFPlayer_GSF.cpp
@@ -1,7 +1,7 @@
 /*
  * xSF - GSF Player
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-30
+ * Last modification on 2013-04-23
  *
  * Based on a modified viogsf v0.08
  *
@@ -192,17 +192,17 @@
 
 XSFPlayer_GSF::XSFPlayer_GSF(const std::string &filename) : XSFPlayer()
 {
-	this->xSF = new XSFFile(filename, 8, 12);
+	this->xSF.reset(new XSFFile(filename, 8, 12));
 }
 
 XSFPlayer_GSF::XSFPlayer_GSF(const std::wstring &filename) : XSFPlayer()
 {
-	this->xSF = new XSFFile(filename, 8, 12);
+	this->xSF.reset(new XSFFile(filename, 8, 12));
 }
 
 bool XSFPlayer_GSF::Load()
 {
-	if (!Load2SF(this->xSF))
+	if (!Load2SF(this->xSF.get()))
 		return false;
 
 	cpuIsMultiBoot = (loaderwork.entry >> 24) == 2;

--- a/src/in_ncsf/SSEQPlayer/Channel.cpp
+++ b/src/in_ncsf/SSEQPlayer/Channel.cpp
@@ -1,7 +1,7 @@
 /*
  * SSEQ Player - Channel structures
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-04-18
+ * Last modification on 2013-04-23
  *
  * Adapted from source code of FeOS Sound System
  * By fincs
@@ -11,8 +11,7 @@
  * http://desmume.org/
  */
 
-#define _USE_MATH_DEFINES
-#include <cmath>
+#include "XSFCommon.h"
 #include "Channel.h"
 #include "Player.h"
 #include "common.h"
@@ -43,11 +42,33 @@
 {
 }
 
+bool Channel::initializedLUTs = false;
+double Channel::cosine_lut[Channel::COSINE_RESOLUTION];
+double Channel::lanczos_lut[Channel::LANCZOS_SAMPLES];
+
+#ifndef M_PI
+static const double M_PI = 3.14159265358979323846;
+#endif
+
+static inline double sinc(double x)
+{
+	return fEqual(x, 0.0) ? 1.0 : std::sin(x * M_PI) / (x * M_PI);
+}
+
 Channel::Channel() : chnId(-1), tempReg(), state(CS_NONE), trackId(-1), prio(0), manualSweep(false), flags(), pan(0), extAmpl(0), velocity(0), extPan(0),
 	key(0), ampl(0), extTune(0), orgKey(0), modType(0), modSpeed(0), modDepth(0), modRange(0), modDelay(0), modDelayCnt(0), modCounter(0),
 	sweepLen(0), sweepCnt(0), sweepPitch(0), attackLvl(0), sustainLvl(0x7F), decayRate(0), releaseRate(0xFFFF), noteLength(-1), vol(0), ply(nullptr), reg()
 {
 	this->clearHistory();
+	if (!this->initializedLUTs)
+	{
+		for (unsigned i = 0; i < COSINE_RESOLUTION; ++i)
+			this->cosine_lut[i] = (1.0 - std::cos((static_cast<double>(i) / COSINE_RESOLUTION) * M_PI)) * 0.5;
+		double dx = static_cast<double>(LANCZOS_WIDTH) / LANCZOS_SAMPLES, x = 0.0;
+		for (unsigned i = 0; i < LANCZOS_SAMPLES; ++i, x += dx)
+			this->lanczos_lut[i] = std::abs(x) < LANCZOS_WIDTH ? sinc(x) * sinc(x / LANCZOS_WIDTH) : 0.0;
+		this->initializedLUTs = true;
+	}
 }
 
 void Channel::UpdateVol(const Track &trk)
@@ -575,10 +596,6 @@
 	{ -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF, -0x7FFF }
 };
 
-#ifndef M_PI
-static const double M_PI = 3.14159265358979323846;
-#endif
-
 // Linear and Cosine interpolation code originally from DeSmuME
 // B-spline and Osculating come from Olli Niemitalo:
 // http://www.student.oulu.fi/~oniemita/dsp/deip.pdf
@@ -612,7 +629,7 @@
 				c5 = 1 / 120.0 * (d - y) + 1 / 24.0 * (z - c) + 1 / 12.0 * (b - a);
 				return static_cast<int32_t>(((((c5 * ratio + c4) * ratio + c3) * ratio + c2) * ratio + c1) * ratio + c0);
 			}
-			else // INTERPOLATION_6POINTOSCULATING
+			else if (this->ply->interpolation == INTERPOLATION_6POINTOSCULATING)
 			{
 				ratio -= 0.5;
 				double even1 = y + d, odd1 = y - d;
@@ -626,6 +643,19 @@
 				c5 = 25 / 24.0 * odd2 - 25 / 12.0 * odd3 - 5 / 24.0 * odd1;
 				return static_cast<int32_t>(((((c5 * ratio + c4) * ratio + c3) * ratio + c2) * ratio + c1) * ratio + c0);
 			}
+			else // INTERPOLATION_6POINTLANCZOS
+			{
+				double kernel[6], kernel_sum = 0.0;
+				int i = 3, shift = static_cast<int>(std::floor(ratio * LANCZOS_RESOLUTION));
+				for (; i >= -2; --i)
+				{
+					int pos = i * LANCZOS_RESOLUTION;
+					kernel_sum += kernel[i + 2] = this->lanczos_lut[std::abs(shift - pos)];
+				}
+				for (i = 0; i < 6; ++i)
+					kernel[i] /= kernel_sum;
+				return static_cast<int32_t>(y * kernel[0] + z * kernel[1] + a * kernel[2] + b * kernel[3] + c * kernel[4] + d * kernel[5]);
+			}
 		}
 		else // INTERPOLATION_4POINTBSPLINE
 		{
@@ -638,10 +668,7 @@
 		}
 	}
 	else if (this->ply->interpolation == INTERPOLATION_COSINE)
-	{
-		double ratio2 = (1.0 - std::cos(ratio * M_PI)) * 0.5;
-		return static_cast<int32_t>(a + ratio2 * (b - a));
-	}
+		return static_cast<int32_t>(a + this->cosine_lut[static_cast<unsigned>(ratio * COSINE_RESOLUTION)] * (b - a));
 	else // INTERPOLATION_LINEAR
 		return static_cast<int32_t>(a + ratio * (b - a));
 }

--- a/src/in_ncsf/SSEQPlayer/Channel.h
+++ b/src/in_ncsf/SSEQPlayer/Channel.h
@@ -1,7 +1,7 @@
 /*
  * SSEQ Player - Channel structures
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-04-18
+ * Last modification on 2013-04-23
  *
  * Adapted from source code of FeOS Sound System
  * By fincs
@@ -15,10 +15,9 @@
 #define SSEQPLAYER_CHANNEL_H
 
 #include <bitset>
-#include <tuple>
+#include <cstdint>
 #include "SWAV.h"
 #include "Track.h"
-#include "pstdint.h"
 
 /*
  * This structure is meant to be similar to what is stored in the actual
@@ -135,6 +134,20 @@
 	uint32_t sampleHistoryPtr;
 	int16_t sampleHistory[16];
 
+	/*
+	 * Lookup tables for the cosine and Lanczos Sinc interpolations, to
+	 * avoid the need to call the sin/cos functions all the time.
+	 * These are static as they will not change between channels or runs
+	 * of the program.
+	 */
+	static bool initializedLUTs;
+	static const unsigned COSINE_RESOLUTION = 8192;
+	static const unsigned LANCZOS_RESOLUTION = 8192;
+	static const unsigned LANCZOS_WIDTH = 3;
+	static const unsigned LANCZOS_SAMPLES = LANCZOS_RESOLUTION * LANCZOS_WIDTH;
+	static double cosine_lut[COSINE_RESOLUTION];
+	static double lanczos_lut[LANCZOS_SAMPLES];
+
 	Channel();
 
 	void UpdateVol(const Track &trk);

--- a/src/in_ncsf/SSEQPlayer/common.h
+++ b/src/in_ncsf/SSEQPlayer/common.h
@@ -1,7 +1,7 @@
 /*
  * SSEQ Player - Common functions
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-3
+ * Last modification on 2013-04-23
  *
  * Some code from FeOS Sound System
  * By fincs
@@ -14,7 +14,7 @@
 #include <string>
 #include <vector>
 #include <cstring>
-#include "pstdint.h"
+#include <cstdint>
 
 /*
  * Pseudo-file data structure

--- a/src/in_ncsf/SSEQPlayer/consts.h
+++ b/src/in_ncsf/SSEQPlayer/consts.h
@@ -1,7 +1,7 @@
 /*
  * SSEQ Player - Constants/Macros
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-04-12
+ * Last modification on 2013-04-23
  *
  * Adapted from source code of FeOS Sound System
  * By fincs
@@ -14,7 +14,7 @@
 #ifndef SSEQPLAYER_CONSTS_H
 #define SSEQPLAYER_CONSTS_H
 
-#include "pstdint.h"
+#include <cstdint>
 
 const uint32_t ARM7_CLOCK = 33513982;
 const double SecondsPerClockCycle = 64.0 * 2728.0 / ARM7_CLOCK;
@@ -58,7 +58,8 @@
 	INTERPOLATION_COSINE,
 	INTERPOLATION_4POINTBSPLINE,
 	INTERPOLATION_6POINTOSCULATING,
-	INTERPOLATION_6POINTBSPLINE
+	INTERPOLATION_6POINTBSPLINE,
+	INTERPOLATION_6POINTLANCZOS
 };
 
 #endif

--- a/src/in_ncsf/XSFConfig_NCSF.cpp
+++ b/src/in_ncsf/XSFConfig_NCSF.cpp
@@ -1,7 +1,7 @@
 /*
  * xSF - NCSF configuration
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-04-18
+ * Last modification on 2013-04-23
  *
  * Partially based on the vio*sf framework
  */
@@ -42,7 +42,7 @@
 
 unsigned XSFConfig::initSampleRate = 44100;
 std::wstring XSFConfig::commonName = L"NCSF Decoder";
-std::wstring XSFConfig::versionNumber = L"1.5";
+std::wstring XSFConfig::versionNumber = L"1.6";
 unsigned XSFConfig_NCSF::initInterpolation = 5;
 std::wstring XSFConfig_NCSF::initMutes = L"0000000000000000";
 
@@ -101,6 +101,7 @@
 			SendMessageW(GetDlgItem(hwndDlg, idInterpolation), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"4-point, 3rd-order B-spline"));
 			SendMessageW(GetDlgItem(hwndDlg, idInterpolation), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"6-point, 5th-order Osculating"));
 			SendMessageW(GetDlgItem(hwndDlg, idInterpolation), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"6-point, 5th-order B-spline"));
+			SendMessageW(GetDlgItem(hwndDlg, idInterpolation), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"6-point Lanczos (Sinc)"));
 			SendMessageW(GetDlgItem(hwndDlg, idInterpolation), CB_SETCURSEL, this->interpolation, 0);
 			// Mutes
 			for (int x = 0, numMutes = this->mutes.size(); x < numMutes; ++x)

--- a/src/in_ncsf/XSFPlayer_NCSF.cpp
+++ b/src/in_ncsf/XSFPlayer_NCSF.cpp
@@ -1,7 +1,7 @@
 /*
  * xSF - NCSF Player
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-04-01
+ * Last modification on 2013-04-23
  *
  * Partially based on the vio*sf framework
  *
@@ -96,17 +96,17 @@
 
 bool XSFPlayer_NCSF::LoadNCSF()
 {
-	return this->RecursiveLoadNCSF(this->xSF, 1);
+	return this->RecursiveLoadNCSF(this->xSF.get(), 1);
 }
 
 XSFPlayer_NCSF::XSFPlayer_NCSF(const std::string &filename) : XSFPlayer()
 {
-	this->xSF = new XSFFile(filename, 8, 12);
+	this->xSF.reset(new XSFFile(filename, 8, 12));
 }
 
 XSFPlayer_NCSF::XSFPlayer_NCSF(const std::wstring &filename) : XSFPlayer()
 {
-	this->xSF = new XSFFile(filename, 8, 12);
+	this->xSF.reset(new XSFFile(filename, 8, 12));
 }
 
 bool XSFPlayer_NCSF::Load()

--- a/src/in_snsf/XSFPlayer_SNSF.cpp
+++ b/src/in_snsf/XSFPlayer_SNSF.cpp
@@ -1,7 +1,7 @@
 /*
  * xSF - SNSF Player
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-30
+ * Last modification on 2013-04-23
  *
  * Based on a modified in_snsf by Caitsith2
  * http://snsf.caitsith2.net/
@@ -207,17 +207,17 @@
 
 XSFPlayer_SNSF::XSFPlayer_SNSF(const std::string &filename) : XSFPlayer()
 {
-	this->xSF = new XSFFile(filename, 4, 8);
+	this->xSF.reset(new XSFFile(filename, 4, 8));
 }
 
 XSFPlayer_SNSF::XSFPlayer_SNSF(const std::wstring &filename) : XSFPlayer()
 {
-	this->xSF = new XSFFile(filename, 4, 8);
+	this->xSF.reset(new XSFFile(filename, 4, 8));
 }
 
 bool XSFPlayer_SNSF::Load()
 {
-	if (!Load2SF(this->xSF))
+	if (!Load2SF(this->xSF.get()))
 		return false;
 
 	Settings.SoundSync = true;

--- a/src/in_snsf/snes9x/port.h
+++ b/src/in_snsf/snes9x/port.h
@@ -211,7 +211,7 @@
 #define PIXEL_FORMAT RGB555
 #endif
 
-#include "pstdint.h"
+#include <cstdint>
 /*#ifndef snes9x_types_defined
 #define snes9x_types_defined
 typedef unsigned char		bool8;

--- a/src/in_xsf_framework/DialogBuilder.cpp
+++ b/src/in_xsf_framework/DialogBuilder.cpp
@@ -1,7 +1,7 @@
 /*
  * Windows Dynamic Dialog Builder framework
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-30
+ * Last modification on 2013-04-23
  */
 
 #include "DialogBuilder.h"
@@ -16,13 +16,33 @@
 	return origNum + 4 - remainder;
 }
 
+Point<short> RelativePosition::CalculatePosition(const Rect<short> &child, const Rect<short> &other)
+{
+	Point<short> newPosition = child.position;
+	if (this->relativePosition.y != -1)
+	{
+		if (this->positionType == FROM_TOP || this->positionType == FROM_TOPLEFT || this->positionType == FROM_TOPRIGHT)
+			newPosition.y = other.position.y + this->relativePosition.y;
+		if (this->positionType == FROM_BOTTOM || this->positionType == FROM_BOTTOMLEFT || this->positionType == FROM_BOTTOMRIGHT)
+			newPosition.y = other.position.y + other.size.height + this->relativePosition.y;
+	}
+	if (this->relativePosition.x != -1)
+	{
+		if (this->positionType == FROM_LEFT || this->positionType == FROM_TOPLEFT || this->positionType == FROM_BOTTOMLEFT)
+			newPosition.x = other.position.x + this->relativePosition.x;
+		if (this->positionType == FROM_RIGHT || this->positionType == FROM_TOPRIGHT || this->positionType == FROM_BOTTOMRIGHT)
+			newPosition.x = other.position.x + other.size.width + this->relativePosition.x;
+	}
+	return newPosition;
+}
+
 void DialogTemplate::DialogGroup::CalculatePositions(bool doRightAndBottom)
 {
 	short x = 0, num = this->controls.empty() ? 0 : this->controls.size();
 	for (; x < num; ++x)
 	{
 		auto &control = this->controls[x];
-		if (control->relativePosition.get())
+		if (control->relativePosition)
 		{
 			bool valid = true;
 			if (!doRightAndBottom && control->relativePosition->type == RelativePosition::TO_PARENT)
@@ -61,7 +81,7 @@
 	std::for_each(this->controls.begin(), this->controls.end(), [&](const std::unique_ptr<DialogControl> &control)
 	{
 		bool usePosition = true;
-		if (control->relativePosition.get())
+		if (control->relativePosition)
 		{
 			if (control->relativePosition->type == RelativePosition::TO_PARENT)
 			{
@@ -129,6 +149,7 @@
 std::vector<uint8_t> DialogTemplate::DialogControlWithoutLabel::GenerateControlTemplate() const
 {
 	auto data = std::vector<uint8_t>(getNextMultipleOf4(24 + sizeof(wchar_t)), 0);
+
 	*reinterpret_cast<uint32_t *>(&data[0]) = WS_CHILD | WS_VISIBLE | this->style;
 	*reinterpret_cast<uint32_t *>(&data[4]) = this->exstyle;
 	*reinterpret_cast<uint16_t *>(&data[8]) = this->rect.position.x;
@@ -145,6 +166,7 @@
 std::vector<uint8_t> DialogTemplate::DialogControlWithLabel::GenerateControlTemplate() const
 {
 	auto data = std::vector<uint8_t>(getNextMultipleOf4(24 + sizeof(wchar_t) * (this->label.length() + 1)), 0);
+
 	*reinterpret_cast<uint32_t *>(&data[0]) = WS_CHILD | WS_VISIBLE | this->style;
 	*reinterpret_cast<uint32_t *>(&data[4]) = this->exstyle;
 	*reinterpret_cast<uint16_t *>(&data[8]) = this->rect.position.x;
@@ -168,7 +190,7 @@
 
 void DialogTemplate::AddGroupControl(const DialogControlBuilder<DialogGroupBuilder> &builder)
 {
-	std::unique_ptr<DialogControl> newGroup = DialogGroup::CreateControl(builder);
+	auto newGroup = DialogGroup::CreateControl(builder);
 	if (builder.index == -1)
 		this->controls.push_back(std::move(newGroup));
 	else
@@ -209,7 +231,7 @@
 {
 	auto &control = this->controls[index];
 	bool valid = true;
-	if (control->relativePosition.get())
+	if (control->relativePosition)
 	{
 		if (!doRightAndBottom && control->relativePosition->type == RelativePosition::TO_PARENT)
 		{
@@ -247,7 +269,7 @@
 	std::for_each(this->controls.begin(), this->controls.end(), [&](const std::unique_ptr<DialogControl> &control)
 	{
 		bool usePosition = true;
-		if (control->relativePosition.get())
+		if (control->relativePosition)
 		{
 			if (control->relativePosition->type == RelativePosition::TO_PARENT)
 			{
@@ -319,6 +341,7 @@
 	this->templateData.clear();
 	uint16_t controlCount = this->GetTotalControlCount();
 	this->templateData.resize(getNextMultipleOf4(24 + sizeof(wchar_t) * (this->title.length() + 1 + (this->fontName.empty() ? 0 : this->fontName.length() + 1))), 0);
+
 	*reinterpret_cast<uint32_t *>(&this->templateData[0]) = this->style | (this->fontName.empty() ? 0 : DS_SETFONT);
 	*reinterpret_cast<uint32_t *>(&this->templateData[4]) = this->exstyle;
 	*reinterpret_cast<uint16_t *>(&this->templateData[8]) = controlCount;

--- a/src/in_xsf_framework/DialogBuilder.h
+++ /dev/null
@@ -1,696 +1,1 @@
-/*
- * Windows Dynamic Dialog Builder framework
- * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-30
- */
 
-#ifndef DIALOG_BUILDER_H
-#define DIALOG_BUILDER_H
-
-#include <string>
-#include <memory>
-#include <vector>
-#include <algorithm>
-#include <stdexcept>
-#include "pstdint.h"
-#include "windowsh_wrapper.h"
-#include "UtfConverter.h"
-
-template<typename T> struct Point
-{
-	T x, y;
-
-	Point() : x(), y() { }
-	Point(T X, T Y) : x(X), y(Y) { }
-};
-
-template<typename T> struct Size
-{
-	T width, height;
-
-	Size() : width(), height() { }
-	Size(T Width, T Height) : width(Width), height(Height) { }
-};
-
-template<typename T> struct Rect
-{
-	Point<T> position;
-	Size<T> size;
-
-	Rect() : position(), size() { }
-	Rect(Point<T> Position, Size<T> Sz) : position(Position), size(Sz) { }
-	Rect(T X, T Y, T Width, T Height) : position(X, Y), size(Width, Height) { }
-};
-
-class RelativePosition
-{
-public:
-	Point<short> relativePosition;
-	enum BaseType
-	{
-		TO_PARENT,
-		TO_SIBLING
-	} type;
-	enum PositionType
-	{
-		FROM_TOP,
-		FROM_BOTTOM,
-		FROM_LEFT,
-		FROM_RIGHT,
-		FROM_TOPLEFT,
-		FROM_BOTTOMLEFT,
-		FROM_TOPRIGHT,
-		FROM_BOTTOMRIGHT
-	} positionType;
-
-	RelativePosition(Point<short> RelPosition, BaseType Type, PositionType PosType) : relativePosition(RelPosition), type(Type), positionType(PosType) { }
-	virtual ~RelativePosition() { }
-	virtual RelativePosition *Clone() const = 0;
-	Point<short> CalculatePosition(Rect<short> child, Rect<short> other)
-	{
-		Point<short> newPosition = child.position;
-		if (this->relativePosition.y != -1)
-		{
-			if (this->positionType == FROM_TOP || this->positionType == FROM_TOPLEFT || this->positionType == FROM_TOPRIGHT)
-				newPosition.y = other.position.y + this->relativePosition.y;
-			if (this->positionType == FROM_BOTTOM || this->positionType == FROM_BOTTOMLEFT || this->positionType == FROM_BOTTOMRIGHT)
-				newPosition.y = other.position.y + other.size.height + this->relativePosition.y;
-		}
-		if (this->relativePosition.x != -1)
-		{
-			if (this->positionType == FROM_LEFT || this->positionType == FROM_TOPLEFT || this->positionType == FROM_BOTTOMLEFT)
-				newPosition.x = other.position.x + this->relativePosition.x;
-			if (this->positionType == FROM_RIGHT || this->positionType == FROM_TOPRIGHT || this->positionType == FROM_BOTTOMRIGHT)
-				newPosition.x = other.position.x + other.size.width + this->relativePosition.x;
-		}
-		return newPosition;
-	}
-};
-
-class RelativePositionToParent : public RelativePosition
-{
-public:
-	RelativePositionToParent(Point<short> RelPosition, PositionType PosType) : RelativePosition(RelPosition, TO_PARENT, PosType) { }
-	RelativePositionToParent *Clone() const { return new RelativePositionToParent(this->relativePosition, this->positionType); }
-};
-
-class RelativePositionToSibling : public RelativePosition
-{
-public:
-	short siblingsBack;
-
-	RelativePositionToSibling(Point<short> RelPosition, PositionType PosType, short SiblingsBack = 1) : RelativePosition(RelPosition, TO_SIBLING, PosType), siblingsBack(SiblingsBack) { }
-	RelativePositionToSibling *Clone() const { return new RelativePositionToSibling(this->relativePosition, this->positionType, this->siblingsBack); }
-};
-
-enum DialogControlType
-{
-	NO_CONTROL,
-	GROUP_CONTROL,
-	EDITBOX_CONTROL,
-	LABEL_CONTROL,
-	CHECKBOX_CONTROL,
-	BUTTON_CONTROL,
-	LISTBOX_CONTROL,
-	COMBOBOX_CONTROL
-};
-
-class DialogTemplate;
-
-class DialogBuilder
-{
-protected:
-	friend class DialogTemplate;
-	std::wstring title, fontName;
-	uint32_t style, exstyle;
-	uint16_t fontSizeInPts;
-	Size<short> size;
-	bool resetControls;
-public:
-	DialogBuilder() : title(L""), fontName(L""), style(0), exstyle(0), fontSizeInPts(0), size(), resetControls(false) { }
-	DialogBuilder &WithTitle(const std::wstring &Title) { this->title = Title; return *this; }
-	DialogBuilder &WithFont(const std::wstring &FontName, uint16_t FontSizeInPts) { this->fontName = FontName; this->fontSizeInPts = FontSizeInPts; return *this; }
-	DialogBuilder &WithSize(short Width, short Height) { this->size.width = Width; this->size.height = Height; return *this; }
-	DialogBuilder &WithSize(Size<short> Sz) { this->size = Sz; return *this; }
-	DialogBuilder &ResetControls(bool Reset = true) { this->resetControls = Reset; return *this; }
-	DialogBuilder &IsOverlapped() { this->style &= ~(WS_OVERLAPPED | WS_POPUP | WS_CHILD); this->style |= WS_OVERLAPPED; return *this; }
-	DialogBuilder &IsPopup() { this->style &= ~(WS_OVERLAPPED | WS_POPUP | WS_CHILD); this->style |= WS_POPUP; return *this; }
-	DialogBuilder &IsChild() { this->style &= ~(WS_OVERLAPPED | WS_POPUP | WS_CHILD); this->style |= WS_CHILD; return *this; }
-	DialogBuilder &WithBorder(bool Border = true) { if (Border) this->style |= WS_BORDER; else this->style &= ~WS_BORDER; return *this; }
-	DialogBuilder &WithDialogFrame(bool DialogFrame = true) { if (DialogFrame) this->style |= WS_DLGFRAME; else this->style &= ~WS_DLGFRAME; return *this; }
-	DialogBuilder &WithVerticalScrollbar(bool VerticalScrollbar = true) { if (VerticalScrollbar) this->style |= WS_VSCROLL; else this->style &= ~WS_VSCROLL; return *this; }
-	DialogBuilder &WithHorizontalScrollbar(bool HorizontalScrollbar = true) { if (HorizontalScrollbar) this->style |= WS_HSCROLL; else this->style &= ~WS_HSCROLL; return *this; }
-	DialogBuilder &WithSystemMenu(bool SystemMenu = true) { if (SystemMenu) this->style |= WS_SYSMENU; else this->style &= ~WS_SYSMENU; return *this; }
-	DialogBuilder &WithSizingBorder(bool SizingBorder = true) { if (SizingBorder) this->style |= WS_THICKFRAME; else this->style &= ~WS_THICKFRAME; return *this; }
-	DialogBuilder &WithMinimizeBox(bool MinimizeBox = true) { if (MinimizeBox) this->style |= WS_MINIMIZEBOX; else this->style &= ~WS_MINIMIZEBOX; return *this; }
-	DialogBuilder &WithMaximizeBox(bool MaximizeBox = true) { if (MaximizeBox) this->style |= WS_MAXIMIZEBOX; else this->style &= ~WS_MAXIMIZEBOX; return *this; }
-	DialogBuilder &WithDialogModalFrame(bool DialogModalFrame = true) { if (DialogModalFrame) this->exstyle |= WS_EX_DLGMODALFRAME; else this->exstyle &= ~WS_EX_DLGMODALFRAME; return *this; }
-#if WINVER >= 0x0400
-	DialogBuilder &WithRaisedEdge(bool RaisedEdge = true) { if (RaisedEdge) this->exstyle |= WS_EX_WINDOWEDGE; else this->exstyle &= ~WS_EX_WINDOWEDGE; return *this; }
-	DialogBuilder &WithSunkenEdge(bool SunkenEdge = true) { if (SunkenEdge) this->exstyle |= WS_EX_CLIENTEDGE; else this->exstyle &= ~WS_EX_CLIENTEDGE; return *this; }
-	DialogBuilder &WithContextHelp(bool ContextHelp = true) { if (ContextHelp) this->exstyle |= WS_EX_CONTEXTHELP; else this->exstyle &= ~WS_EX_CONTEXTHELP; return *this; }
-	DialogBuilder &IsControlWindow(bool ControlWindow = true) { if (ControlWindow) this->style |= DS_CONTROL; else this->style &= ~DS_CONTROL; return *this; }
-	DialogBuilder &IsCentered(bool Centered = true) { if (Centered) this->style |= DS_CENTER; else this->style &= ~DS_CENTER; return *this; }
-#endif
-};
-
-template<class T> class DialogControlBuilder
-{
-protected:
-	friend class DialogTemplate;
-	DialogControlType controlType;
-	uint32_t style, exstyle;
-	Rect<short> rect;
-	short id;
-	int index;
-	std::unique_ptr<RelativePosition> relativePosition;
-
-	T &me() { return dynamic_cast<T &>(*this); }
-public:
-	DialogControlBuilder(DialogControlType Type = NO_CONTROL) : controlType(Type), style(0), exstyle(0), rect(), id(-1), index(-1), relativePosition() { }
-	virtual ~DialogControlBuilder() { }
-	T &WithPosition(short X, short Y) { this->rect.position.x = X; this->rect.position.y = Y; return this->me(); }
-	T &WithPosition(Point<short> Position) { this->rect.position = Position; return this->me(); }
-	T &WithRelativePositionToParent(RelativePosition::PositionType PosType, Point<short> RelativePosition)
-	{
-		this->relativePosition.reset(new RelativePositionToParent(RelativePosition, PosType));
-		return this->me();
-	}
-	T &WithRelativePositionToSibling(RelativePosition::PositionType PosType, Point<short> RelativePosition, short SiblingsBack = 1)
-	{
-		this->relativePosition.reset(new RelativePositionToSibling(RelativePosition, PosType, SiblingsBack));
-		return this->me();
-	}
-	T &WithSize(short Width, short Height) { this->rect.size.width = Width; this->rect.size.height = Height; return this->me(); }
-	T &WithSize(Size<short> Sz) { this->rect.size = Sz; return this->me(); }
-	T &WithID(short ID) { this->id = ID; return this->me(); }
-	T &AtIndex(int Index) { this->index = Index; return this->me(); }
-	T &IsDisabled(bool Disabled = true) { if (Disabled) this->style |= WS_DISABLED; else this->style &= ~WS_DISABLED; return this->me(); }
-	T &WithBorder(bool ThinBorder = true) { if (ThinBorder) this->style |= WS_BORDER; else this->style &= ~WS_BORDER; return this->me(); }
-	T &WithVerticalScrollbar(bool VerticalScrollbar = true) { if (VerticalScrollbar) this->style |= WS_VSCROLL; else this->style &= ~WS_VSCROLL; return this->me(); }
-	T &WithHorizontalScrollbar(bool HorizontalScrollbar = true) { if (HorizontalScrollbar) this->style |= WS_HSCROLL; else this->style &= ~WS_HSCROLL; return this->me(); }
-	T &WithTabStop(bool TabStop = true) { if (TabStop) this->style |= WS_TABSTOP; else this->style &= ~WS_TABSTOP; return this->me(); }
-#if WINVER >= 0x0400
-	T &WithRaisedEdge(bool RaisedEdge = true) { if (RaisedEdge) this->exstyle |= WS_EX_WINDOWEDGE; else this->exstyle &= ~WS_EX_WINDOWEDGE; return this->me(); }
-	T &WithSunkenEdge(bool SunkenEdge = true) { if (SunkenEdge) this->exstyle |= WS_EX_CLIENTEDGE; else this->exstyle &= ~WS_EX_CLIENTEDGE; return this->me(); }
-#endif
-};
-
-class DialogGroupBuilder : public DialogControlBuilder<DialogGroupBuilder>
-{
-protected:
-	friend class DialogTemplate;
-	std::wstring groupName;
-public:
-	DialogGroupBuilder(const std::wstring &newGroupName) : DialogControlBuilder(GROUP_CONTROL), groupName(newGroupName) { }
-};
-
-template<class T> class DialogInGroupBuilder : public DialogControlBuilder<T>
-{
-protected:
-	friend class DialogTemplate;
-	std::wstring groupName;
-public:
-	DialogInGroupBuilder(DialogControlType Type) : DialogControlBuilder<T>(Type), groupName(L"") { }
-	T &InGroup(const std::wstring &GroupName) { this->groupName = GroupName; return this->me(); }
-};
-
-class DialogEditBoxBuilder : public DialogInGroupBuilder<DialogEditBoxBuilder>
-{
-protected:
-	friend class DialogTemplate;
-public:
-	DialogEditBoxBuilder() : DialogInGroupBuilder(EDITBOX_CONTROL) { }
-	DialogEditBoxBuilder &IsLeftJustified() { this->style &= ~(ES_LEFT | ES_CENTER | ES_RIGHT); this->style |= ES_LEFT; return this->me(); }
-	DialogEditBoxBuilder &IsCenterJustified() { this->style &= ~(ES_LEFT | ES_CENTER | ES_RIGHT); this->style |= ES_CENTER; return this->me(); }
-	DialogEditBoxBuilder &IsRightJustified() { this->style &= ~(ES_LEFT | ES_CENTER | ES_RIGHT); this->style |= ES_RIGHT; return this->me(); }
-	DialogEditBoxBuilder &IsMultiline(bool Multiline = true) { if (Multiline) this->style |= ES_MULTILINE; else this->style &= ~ES_MULTILINE; return this->me(); }
-	DialogEditBoxBuilder &WithAllUppercase(bool AllUppercase = true) { if (AllUppercase) this->style |= ES_UPPERCASE; else this->style &= ~ES_UPPERCASE; return this->me(); }
-	DialogEditBoxBuilder &WithAllLowercase(bool AllLowercase = true) { if (AllLowercase) this->style |= ES_LOWERCASE; else this->style &= ~ES_LOWERCASE; return this->me(); }
-	DialogEditBoxBuilder &IsPasswordInput(bool PasswordInput = true) { if (PasswordInput) this->style |= ES_PASSWORD; else this->style &= ~ES_PASSWORD; return this->me(); }
-	DialogEditBoxBuilder &WithAutoVScroll(bool AutoVScroll = true) { if (AutoVScroll) this->style |= ES_AUTOVSCROLL; else this->style &= ~ES_AUTOVSCROLL; return this->me(); }
-	DialogEditBoxBuilder &WithAutoHScroll(bool AutoHScroll = true) { if (AutoHScroll) this->style |= ES_AUTOHSCROLL; else this->style &= ~ES_AUTOHSCROLL; return this->me(); }
-	DialogEditBoxBuilder &WithDontHideSelection(bool DontHideSelection = true) { if (DontHideSelection) this->style |= ES_NOHIDESEL; else this->style &= ~ES_NOHIDESEL; return this->me(); }
-	DialogEditBoxBuilder &IsReadOnly(bool ReadOnly = true) { if (ReadOnly) this->style |= ES_READONLY; else this->style &= ~ES_READONLY; return this->me(); }
-	DialogEditBoxBuilder &WithWantReturn(bool WantReturn = true) { if (WantReturn) this->style |= ES_WANTRETURN; else this->style &= ~ES_WANTRETURN; return this->me(); }
-};
-
-template<class T> class DialogControlWithLabelBuilder : public DialogInGroupBuilder<T>
-{
-protected:
-	friend class DialogTemplate;
-	std::wstring label;
-public:
-	DialogControlWithLabelBuilder(DialogControlType Type, const std::wstring &Label) : DialogInGroupBuilder<T>(Type), label(Label) { }
-};
-
-class DialogLabelBuilder : public DialogControlWithLabelBuilder<DialogLabelBuilder>
-{
-protected:
-	friend class DialogTemplate;
-public:
-	DialogLabelBuilder(const std::wstring &Label) : DialogControlWithLabelBuilder(LABEL_CONTROL, Label) { }
-	DialogLabelBuilder &IsLeftJustified(bool WithWordWrap = false)
-	{
-		this->style &= ~(SS_LEFT | SS_CENTER | SS_RIGHT | SS_LEFTNOWORDWRAP);
-		if (WithWordWrap)
-			this->style |= SS_LEFTNOWORDWRAP;
-		else
-			this->style |= SS_LEFT;
-		return this->me();
-	}
-	DialogLabelBuilder &IsCenterJustified() { this->style &= ~(SS_LEFT | SS_CENTER | SS_RIGHT | SS_LEFTNOWORDWRAP); this->style |= SS_CENTER; return this->me(); }
-	DialogLabelBuilder &IsRightJustified() { this->style &= ~(SS_LEFT | SS_CENTER | SS_RIGHT | SS_LEFTNOWORDWRAP); this->style |= SS_RIGHT; return this->me(); }
-	DialogLabelBuilder &WithAmpsNotTranslated(bool AmpsNotTranslated = true) { if (AmpsNotTranslated) this->style |= SS_NOPREFIX; else this->style &= ~SS_NOPREFIX; return this->me(); }
-#if WINVER >= 0x0400
-	DialogLabelBuilder &WithNotify(bool Notify = true) { if (Notify) this->style |= SS_NOTIFY; else this->style &= ~SS_NOTIFY; return this->me(); }
-#endif
-};
-
-template<class T> class DialogButtonBaseBuilder : public DialogControlWithLabelBuilder<T>
-{
-protected:
-	friend class DialogTemplate;
-public:
-	DialogButtonBaseBuilder(DialogControlType Type, const std::wstring &Label) : DialogControlWithLabelBuilder<T>(Type, Label) { }
-#if WINVER >= 0x0400
-	T &IsLeftJustified(bool LeftJustified = true)
-	{
-		if (LeftJustified)
-		{
-			this->style |= BS_LEFT;
-			this->style &= ~BS_RIGHT;
-		}
-		else
-			this->style &= ~BS_LEFT;
-		return this->me();
-	}
-	T &IsRightJustified(bool RightJustified = true)
-	{
-		if (RightJustified)
-		{
-			this->style |= BS_RIGHT;
-			this->style &= ~BS_LEFT;
-		}
-		else
-			this->style &= ~BS_RIGHT;
-		return this->me();
-	}
-	T &IsCenterJustified(bool CenterJustified = true) { if (CenterJustified) this->style |= BS_CENTER; else this->style &= ~BS_CENTER; return this->me(); }
-	T &WithVerticalTop(bool VerticalTop = true)
-	{
-		if (VerticalTop)
-		{
-			this->style |= BS_TOP;
-			this->style &= ~BS_BOTTOM;
-		}
-		else
-			this->style &= ~BS_TOP;
-		return this->me();
-	}
-	T &WithVerticalBottom(bool VerticalBottom = true)
-	{
-		if (VerticalBottom)
-		{
-			this->style |= BS_BOTTOM;
-			this->style &= ~BS_TOP;
-		}
-		else
-			this->style &= ~BS_BOTTOM;
-		return this->me();
-	}
-	T &WithVerticalCenter(bool VerticalCenter = true) { if (VerticalCenter) this->style |= BS_VCENTER; else this->style &= ~BS_VCENTER; return this->me(); }
-	T &IsMultiline(bool Multiline = true) { if (Multiline) this->style |= BS_MULTILINE; else this->style &= ~BS_MULTILINE; return this->me(); }
-	T &WithNotify(bool Notify = true) { if (Notify) this->style |= BS_NOTIFY; else this->style &= ~BS_NOTIFY; return this->me(); }
-	T &IsFlat(bool Flat = true) { if (Flat) this->style |= BS_FLAT; else this->style &= ~BS_FLAT; return this->me(); }
-#endif
-};
-
-class DialogButtonBuilder : public DialogButtonBaseBuilder<DialogButtonBuilder>
-{
-protected:
-	friend class DialogTemplate;
-public:
-	DialogButtonBuilder(const std::wstring &Label) : DialogButtonBaseBuilder(BUTTON_CONTROL, Label) { }
-	DialogButtonBuilder &IsDefault(bool Default = true) { if (Default) this->style |= BS_DEFPUSHBUTTON; else this->style &= ~BS_DEFPUSHBUTTON; return this->me(); }
-};
-
-class DialogCheckBoxBuilder : public DialogButtonBaseBuilder<DialogCheckBoxBuilder>
-{
-protected:
-	friend class DialogTemplate;
-public:
-	DialogCheckBoxBuilder(const std::wstring &Label) : DialogButtonBaseBuilder(CHECKBOX_CONTROL, Label) { this->style |= BS_AUTOCHECKBOX; }
-	DialogCheckBoxBuilder &WithTextOnLeft(bool TextOnLeft = true) { if (TextOnLeft) this->style |= BS_LEFTTEXT; else this->style &= ~BS_LEFTTEXT; return this->me(); }
-	DialogCheckBoxBuilder &LikePushButton(bool PushButton = true) { if (PushButton) this->style |= BS_PUSHLIKE; else this->style &= ~BS_PUSHLIKE; return this->me(); }
-};
-
-class DialogListBoxBuilder : public DialogInGroupBuilder<DialogListBoxBuilder>
-{
-protected:
-	friend class DialogTemplate;
-public:
-	DialogListBoxBuilder() : DialogInGroupBuilder(LISTBOX_CONTROL) { }
-	DialogListBoxBuilder &WithNotify(bool Notify = true) { if (Notify) this->style |= LBS_NOTIFY; else this->style &= ~LBS_NOTIFY; return this->me(); }
-	DialogListBoxBuilder &WithSort(bool Sort = true) { if (Sort) this->style |= LBS_SORT; else this->style &= ~LBS_SORT; return this->me(); }
-	DialogListBoxBuilder &WithMultipleSelect(bool MultipleSelect = true) { if (MultipleSelect) this->style |= LBS_MULTIPLESEL; else this->style &= ~LBS_MULTIPLESEL; return this->me(); }
-	DialogListBoxBuilder &WithExactHeight(bool ExactHeight = true) { if (ExactHeight) this->style |= LBS_NOINTEGRALHEIGHT; else this->style &= ~LBS_NOINTEGRALHEIGHT; return this->me(); }
-	DialogListBoxBuilder &WithMultipleColumns(bool MultipleColumns = true) { if (MultipleColumns) this->style |= LBS_MULTICOLUMN; else this->style &= ~LBS_MULTICOLUMN; return this->me(); }
-	DialogListBoxBuilder &WithExtendedSelect(bool ExtendedSelect = true) { if (ExtendedSelect) this->style |= LBS_EXTENDEDSEL; else this->style &= ~LBS_EXTENDEDSEL; return this->me(); }
-	DialogListBoxBuilder &WithDisabledNoScroll(bool DisabledNoScroll = true) { if (DisabledNoScroll) this->style |= LBS_DISABLENOSCROLL; else this->style &= ~LBS_DISABLENOSCROLL; return this->me(); }
-#if WINVER >= 0x0400
-	DialogListBoxBuilder &WithNoSelect(bool NoSelect = true) { if (NoSelect) this->style |= LBS_NOSEL; else this->style &= ~LBS_NOSEL; return this->me(); }
-#endif
-};
-
-class DialogComboBoxBuilder : public DialogInGroupBuilder<DialogComboBoxBuilder>
-{
-protected:
-	friend class DialogTemplate;
-public:
-	DialogComboBoxBuilder() : DialogInGroupBuilder(COMBOBOX_CONTROL) { }
-	DialogComboBoxBuilder &IsSimple() { this->style &= ~(CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST); this->style |= CBS_SIMPLE; return this->me(); }
-	DialogComboBoxBuilder &IsDropDown() { this->style &= ~(CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST); this->style |= CBS_DROPDOWN; return this->me(); }
-	DialogComboBoxBuilder &IsDropDownList() { this->style &= ~(CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST); this->style |= CBS_DROPDOWNLIST; return this->me(); }
-	DialogComboBoxBuilder &WithAutoHScroll(bool AutoHScroll = true) { if (AutoHScroll) this->style |= CBS_AUTOHSCROLL; else this->style &= ~CBS_AUTOHSCROLL; return this->me(); }
-	DialogComboBoxBuilder &WithSort(bool Sort = true) { if (Sort) this->style |= CBS_SORT; else this->style &= ~CBS_SORT; return this->me(); }
-	DialogComboBoxBuilder &WithExactHeight(bool ExactHeight = true) { if (ExactHeight) this->style |= CBS_NOINTEGRALHEIGHT; else this->style &= ~CBS_NOINTEGRALHEIGHT; return this->me(); }
-	DialogComboBoxBuilder &WithDisabledNoScroll(bool DisabledNoScroll = true) { if (DisabledNoScroll) this->style |= CBS_DISABLENOSCROLL; else this->style &= ~CBS_DISABLENOSCROLL; return this->me(); }
-#if WINVER >= 0x0400
-	DialogComboBoxBuilder &WithAllLowercase(bool AllLowercase = true) { if (AllLowercase) this->style |= CBS_LOWERCASE; else this->style &= ~CBS_LOWERCASE; return this->me(); }
-	DialogComboBoxBuilder &WithAllUppercase(bool AllUppercase = true) { if (AllUppercase) this->style |= CBS_UPPERCASE; else this->style &= ~CBS_UPPERCASE; return this->me(); }
-#endif
-};
-
-class DialogTemplate
-{
-	class DialogControl;
-
-	typedef std::vector<std::unique_ptr<DialogControl>> Controls;
-
-	class DialogControl
-	{
-	protected:
-		DialogControlType controlType;
-		uint32_t style, exstyle;
-		Rect<short> rect;
-		short id;
-		std::unique_ptr<RelativePosition> relativePosition;
-
-		friend class DialogTemplate;
-		DialogControl() : controlType(NO_CONTROL), style(0), exstyle(0), rect(), id(-1), relativePosition() { }
-		DialogControl(const DialogControl &control) : controlType(control.controlType), style(control.style), exstyle(control.exstyle), rect(control.rect), id(control.id),
-			relativePosition(control.relativePosition.get() ? control.relativePosition->Clone() : nullptr) { }
-		DialogControl &operator=(const DialogControl &control)
-		{
-			this->controlType = control.controlType;
-			this->style = control.style;
-			this->exstyle = control.exstyle;
-			this->rect = control.rect;
-			this->id = control.id;
-			if (control.relativePosition.get())
-				this->relativePosition.reset(control.relativePosition->Clone());
-			else
-				this->relativePosition.reset();
-
-			return *this;
-		}
-	public:
-		virtual ~DialogControl() { }
-		template<typename Control, typename Builder> static std::unique_ptr<Control> CreateControl(const DialogControlBuilder<Builder> &builder)
-		{
-			auto control = std::unique_ptr<Control>(new Control());
-
-			control->controlType = builder.controlType;
-			control->style = builder.style;
-			control->exstyle = builder.exstyle;
-			control->rect = builder.rect;
-			control->id = builder.id;
-			if (builder.relativePosition.get())
-				control->relativePosition.reset(builder.relativePosition->Clone());
-
-			return control;
-		}
-		virtual uint16_t GetControlCount() const { return 1; }
-		virtual short GetControlHeight() const { return this->rect.size.height; }
-		virtual std::vector<uint8_t> GenerateControlTemplate() const = 0;
-		virtual DialogControl *Clone() const = 0;
-	};
-
-	class DialogGroup : public DialogControl
-	{
-	protected:
-		DialogTemplate::Controls controls;
-		std::wstring groupName;
-
-		friend class DialogTemplate;
-		friend class DialogControl;
-		DialogGroup() : DialogControl(), controls(), groupName(L"") { }
-		DialogGroup(const DialogGroup &control) : DialogControl(control), controls(), groupName(control.groupName)
-		{
-			std::for_each(control.controls.begin(), control.controls.end(), [&](const std::unique_ptr<DialogControl> &control) { this->controls.push_back(std::unique_ptr<DialogControl>(control->Clone())); });
-		}
-		DialogGroup &operator=(const DialogGroup &control)
-		{
-			DialogControl::operator=(control);
-
-			this->controls.clear();
-			std::for_each(control.controls.begin(), control.controls.end(), [&](const std::unique_ptr<DialogControl> &control) { this->controls.push_back(std::unique_ptr<DialogControl>(control->Clone())); });
-
-			this->groupName = control.groupName;
-
-			return *this;
-		}
-	public:
-		static std::unique_ptr<DialogGroup> CreateControl(const DialogControlBuilder<DialogGroupBuilder> &builder)
-		{
-			auto control = DialogControl::CreateControl<DialogGroup>(builder);
-
-			control->groupName = dynamic_cast<const DialogGroupBuilder &>(builder).groupName;
-
-			return control;
-		}
-		void CalculatePositions(bool doRightAndBottom = false);
-		void CalculateSize();
-		uint16_t GetControlCount() const;
-		std::vector<uint8_t> GenerateControlTemplate() const;
-		DialogGroup *Clone() const { return new DialogGroup(*this); }
-	};
-
-	class DialogControlWithoutLabel : public DialogControl
-	{
-	protected:
-		uint16_t type;
-
-		friend class DialogTemplate;
-		friend class DialogControl;
-		DialogControlWithoutLabel() : DialogControl(), type(0) { }
-		DialogControlWithoutLabel(const DialogControlWithoutLabel &control) : DialogControl(control), type(control.type) { }
-		DialogControlWithoutLabel &operator=(const DialogControlWithoutLabel &control)
-		{
-			DialogControl::operator=(control);
-
-			this->type = control.type;
-
-			return *this;
-		}
-	public:
-		template<typename Control, typename Builder> static std::unique_ptr<Control> CreateControl(const DialogControlBuilder<Builder> &builder, uint16_t Type)
-		{
-			auto control = DialogControl::CreateControl<Control>(builder);
-
-			control->type = Type;
-
-			return control;
-		}
-		virtual std::vector<uint8_t> GenerateControlTemplate() const;
-		virtual DialogControlWithoutLabel *Clone() const { return new DialogControlWithoutLabel(*this); }
-	};
-
-	class DialogControlWithLabel : public DialogControl
-	{
-	protected:
-		uint16_t type;
-		std::wstring label;
-
-		friend class DialogTemplate;
-		friend class DialogControl;
-		DialogControlWithLabel() : DialogControl(), type(0), label(L"") { }
-		DialogControlWithLabel(const DialogControlWithLabel &control) : DialogControl(control), type(control.type), label(control.label) { }
-		DialogControlWithLabel &operator=(const DialogControlWithLabel &control)
-		{
-			DialogControl::operator=(control);
-
-			this->type = control.type;
-			this->label = control.label;
-
-			return *this;
-		}
-	public:
-		template<typename Control, typename Builder> static std::unique_ptr<Control> CreateControl(const DialogControlBuilder<Builder> &builder, uint16_t Type)
-		{
-			auto control = DialogControl::CreateControl<Control>(builder);
-
-			control->type = Type;
-			control->label = dynamic_cast<const DialogControlWithLabelBuilder<Builder> &>(builder).label;
-
-			return control;
-		}
-		virtual std::vector<uint8_t> GenerateControlTemplate() const;
-		virtual DialogControlWithLabel *Clone() const { return new DialogControlWithLabel(*this); }
-	};
-
-	class DialogEditBox : public DialogControlWithoutLabel
-	{
-	protected:
-		friend class DialogTemplate;
-		friend class DialogControl;
-		DialogEditBox() : DialogControlWithoutLabel() { }
-	public:
-		static std::unique_ptr<DialogEditBox> CreateControl(const DialogControlBuilder<DialogEditBoxBuilder> &builder)
-		{
-			return DialogControlWithoutLabel::CreateControl<DialogEditBox>(builder, 0x0081);
-		}
-	};
-
-	class DialogLabel : public DialogControlWithLabel
-	{
-	protected:
-		friend class DialogTemplate;
-		friend class DialogControl;
-		DialogLabel() : DialogControlWithLabel() { }
-	public:
-		static std::unique_ptr<DialogLabel> CreateControl(const DialogControlBuilder<DialogLabelBuilder> &builder)
-		{
-			return DialogControlWithLabel::CreateControl<DialogLabel>(builder, 0x0082);
-		}
-	};
-
-	class DialogButton : public DialogControlWithLabel
-	{
-	protected:
-		friend class DialogTemplate;
-		friend class DialogControl;
-		DialogButton() : DialogControlWithLabel() { }
-	public:
-		template<typename Builder> static std::unique_ptr<DialogButton> CreateControl(const DialogControlBuilder<Builder> &builder)
-		{
-			return DialogControlWithLabel::CreateControl<DialogButton>(builder, 0x0080);
-		}
-	};
-
-	class DialogListBox : public DialogControlWithoutLabel
-	{
-	protected:
-		friend class DialogTemplate;
-		friend class DialogControl;
-		DialogListBox() : DialogControlWithoutLabel() { }
-	public:
-		static std::unique_ptr<DialogListBox> CreateControl(const DialogControlBuilder<DialogListBoxBuilder> &builder)
-		{
-			return DialogControlWithoutLabel::CreateControl<DialogListBox>(builder, 0x0083);
-		}
-	};
-
-	class DialogComboBox : public DialogControlWithoutLabel
-	{
-	protected:
-		friend class DialogTemplate;
-		friend class DialogControl;
-		DialogComboBox() : DialogControlWithoutLabel() { }
-	public:
-		static std::unique_ptr<DialogComboBox> CreateControl(const DialogControlBuilder<DialogComboBoxBuilder> &builder)
-		{
-			return DialogControlWithoutLabel::CreateControl<DialogComboBox>(builder, 0x0085);
-		}
-		short GetControlHeight() const { return (this->style & CBS_SIMPLE && !(this->style & CBS_DROPDOWNLIST)) ? this->rect.size.height : 14; }
-	};
-
-	std::wstring title;
-	uint32_t style, exstyle;
-	std::wstring fontName;
-	uint16_t fontSizeInPts;
-	Size<short> size;
-	DialogTemplate::Controls controls;
-	std::vector<uint8_t> templateData;
-
-	template<typename Builder> void AddControlToGroup(std::unique_ptr<DialogControl> &&control, const DialogControlBuilder<Builder> &builder)
-	{
-		const DialogInGroupBuilder<Builder> &groupBuilder = dynamic_cast<const DialogInGroupBuilder<Builder> &>(builder);
-		if (groupBuilder.groupName.empty())
-		{
-			if (builder.index == -1)
-				this->controls.push_back(std::move(control));
-			else
-				this->controls.insert(this->controls.begin() + builder.index, std::move(control));
-		}
-		else
-		{
-			for (auto curr = this->controls.begin(), end = this->controls.end(); curr != end; ++curr)
-			{
-				if ((*curr)->controlType != GROUP_CONTROL)
-					continue;
-				DialogGroup *group = dynamic_cast<DialogGroup *>(curr->get());
-				if (group->groupName == groupBuilder.groupName)
-				{
-					if (builder.index == -1)
-						group->controls.push_back(std::move(control));
-					else
-						group->controls.insert(group->controls.begin() + builder.index, std::move(control));
-					return;
-				}
-			}
-			throw std::runtime_error("Group " + UtfConverter::ToUtf8(groupBuilder.groupName) + " was not found.");
-		}
-	}
-	uint16_t GetTotalControlCount() const;
-	bool CalculateControlPosition(short index, bool doRightAndBottom = false);
-	void CalculateSize();
-public:
-	DialogTemplate() : title(L""), style(0), exstyle(0), fontName(L""), fontSizeInPts(0), size(), controls(), templateData() { }
-	DialogTemplate(const DialogBuilder &builder) : title(builder.title), style(builder.style), exstyle(builder.exstyle), fontName(builder.fontName), fontSizeInPts(builder.fontSizeInPts),
-		size(builder.size), controls(), templateData() { }
-	DialogTemplate(const DialogTemplate &dlg) : title(dlg.title), style(dlg.style), exstyle(dlg.style), fontName(dlg.fontName), fontSizeInPts(dlg.fontSizeInPts), size(dlg.size),
-		controls(), templateData()
-	{
-		std::for_each(dlg.controls.begin(), dlg.controls.end(), [&](const std::unique_ptr<DialogControl> &control) { this->controls.push_back(std::unique_ptr<DialogControl>(control->Clone())); });
-	}
-	DialogTemplate &operator=(const DialogBuilder &builder)
-	{
-		this->title = builder.title;
-		this->style = builder.style;
-		this->exstyle = builder.exstyle;
-		this->fontName = builder.fontName;
-		this->fontSizeInPts = builder.fontSizeInPts;
-		this->size = builder.size;
-		if (builder.resetControls)
-			this->controls.clear();
-
-		return *this;
-	}
-	DialogTemplate &operator=(const DialogTemplate &dlg)
-	{
-		this->title = dlg.title;
-		this->style = dlg.style;
-		this->exstyle = dlg.exstyle;
-		this->fontName = dlg.fontName;
-		this->fontSizeInPts = dlg.fontSizeInPts;
-		this->size = dlg.size;
-		this->controls.clear();
-		std::for_each(dlg.controls.begin(), dlg.controls.end(), [&](const std::unique_ptr<DialogControl> &control) { this->controls.push_back(std::unique_ptr<DialogControl>(control->Clone())); });
-
-		return *this;
-	}
-	void AddGroupControl(const DialogControlBuilder<DialogGroupBuilder> &builder);
-	void AddEditBoxControl(const DialogControlBuilder<DialogEditBoxBuilder> &builder);
-	void AddLabelControl(const DialogControlBuilder<DialogLabelBuilder> &builder);
-	void AddCheckBoxControl(const DialogControlBuilder<DialogCheckBoxBuilder> &builder);
-	void AddButtonControl(const DialogControlBuilder<DialogButtonBuilder> &builder);
-	void AddListBoxControl(const DialogControlBuilder<DialogListBoxBuilder> &builder);
-	void AddComboBoxControl(const DialogControlBuilder<DialogComboBoxBuilder> &builder);
-	void AutoSize();
-	const DLGTEMPLATE *GenerateTemplate();
-};
-
-#endif
-

--- a/src/in_xsf_framework/UTFEncodeDecode.h
+++ b/src/in_xsf_framework/UTFEncodeDecode.h
@@ -17,11 +17,11 @@
 	const std::locale loc;
 public:
 	cp_converter(const std::locale &L = std::locale::classic()) : loc(L) { }
-	inline std::wstring widen(const std::string &in)
+	std::wstring widen(const std::string &in)
 	{
 		return this->convert<char, wchar_t>(in);
 	}
-	inline std::string narrow(const std::wstring &in)
+	std::string narrow(const std::wstring &in)
 	{
 		return this->convert<wchar_t, char>(in);
 	}
@@ -29,13 +29,13 @@
 	typedef std::codecvt<wchar_t, char, mbstate_t> codecvt_facet;
 
 	// widen
-	inline codecvt_facet::result cv(const codecvt_facet &facet, mbstate_t &s, const char *f1, const char *l1, const char *&n1, wchar_t *f2, wchar_t *l2, wchar_t *&n2) const
+	codecvt_facet::result cv(const codecvt_facet &facet, mbstate_t &s, const char *f1, const char *l1, const char *&n1, wchar_t *f2, wchar_t *l2, wchar_t *&n2) const
 	{
 		return facet.in(s, f1, l1, n1, f2, l2, n2);
 	}
 
 	// narrow
-	inline codecvt_facet::result cv(const codecvt_facet &facet, mbstate_t &s, const wchar_t *f1, const wchar_t *l1, const wchar_t *&n1, char *f2, char *l2, char *&n2) const
+	codecvt_facet::result cv(const codecvt_facet &facet, mbstate_t &s, const wchar_t *f1, const wchar_t *l1, const wchar_t *&n1, char *f2, char *l2, char *&n2) const
 	{
 		return facet.out(s, f1, l1, n1, f2, l2, n2);
 	}

--- a/src/in_xsf_framework/XSFCommon.h
+++ b/src/in_xsf_framework/XSFCommon.h
@@ -1,7 +1,7 @@
 /*
  * xSF - Common functions
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-21
+ * Last modification on 2013-04-23
  *
  * Partially based on the vio*sf framework
  */
@@ -14,7 +14,7 @@
 #include <string>
 #define _USE_MATH_DEFINES
 #include <cmath>
-#include "pstdint.h"
+#include <cstdint>
 
 // Code from http://learningcppisfun.blogspot.com/2010/04/comparing-floating-point-numbers.html
 template<typename T> inline bool fEqual(T x, T y, int N = 1)
@@ -39,7 +39,7 @@
 // This gets the directory for the path, including the final forward/backward slash
 template<typename T> inline std::basic_string<T> ExtractDirectoryFromPath(const std::basic_string<T> &fullPath)
 {
-	size_t lastSlash = fullPath.rfind('\\');
+	auto lastSlash = fullPath.rfind('\\');
 	if (lastSlash == std::basic_string<T>::npos)
 		lastSlash = fullPath.rfind('/');
 	return lastSlash != std::basic_string<T>::npos ? fullPath.substr(0, lastSlash + 1) : std::basic_string<T>();
@@ -48,7 +48,7 @@
 // This gets the filename for the path
 template<typename T> inline std::basic_string<T> ExtractFilenameFromPath(const std::basic_string<T> &fullPath)
 {
-	size_t lastSlash = fullPath.rfind('\\');
+	auto lastSlash = fullPath.rfind('\\');
 	if (lastSlash == std::basic_string<T>::npos)
 		lastSlash = fullPath.rfind('/');
 	return lastSlash != std::basic_string<T>::npos ? fullPath.substr(lastSlash + 1) : std::basic_string<T>();
@@ -56,7 +56,7 @@
 
 // Code from the following answer on Stack Overflow:
 // http://stackoverflow.com/a/15479212
-template<typename T> static inline T NextHighestPowerOf2(T value)
+template<typename T> inline T NextHighestPowerOf2(T value)
 {
 	if (value < 1)
 		return 1;

--- a/src/in_xsf_framework/XSFConfig.cpp
+++ b/src/in_xsf_framework/XSFConfig.cpp
@@ -1,7 +1,7 @@
 /*
  * xSF - Core configuration handler
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-04-02
+ * Last modification on 2013-04-23
  *
  * Partially based on the vio*sf framework
  */
@@ -57,7 +57,7 @@
 std::wstring XSFConfig::GetTextFromWindow(HWND hwnd)
 {
 	LRESULT length = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0);
-	std::vector<wchar_t> value(length + 1);
+	auto value = std::vector<wchar_t>(length + 1);
 	length = SendMessageW(hwnd, WM_GETTEXT, length + 1, reinterpret_cast<LPARAM>(&value[0]));
 	return std::wstring(value.begin(), value.begin() + length);
 }
@@ -340,7 +340,7 @@
 	SetWindowTextW(GetDlgItem(hwndDlg, idVolume), wstringify(XSFConfig::initVolume).c_str());
 	SendMessageW(GetDlgItem(hwndDlg, idReplayGain), CB_SETCURSEL, XSFConfig::initVolumeType, 0);
 	SendMessageW(GetDlgItem(hwndDlg, idClipProtect), CB_SETCURSEL, XSFConfig::initPeakType, 0);
-	std::vector<unsigned>::const_iterator found = std::find(this->supportedSampleRates.begin(), this->supportedSampleRates.end(), XSFConfig::initSampleRate);
+	auto found = std::find(this->supportedSampleRates.begin(), this->supportedSampleRates.end(), XSFConfig::initSampleRate);
 	SendMessageW(GetDlgItem(hwndDlg, idSampleRate), CB_SETCURSEL, found - this->supportedSampleRates.begin(), 0);
 	SetWindowTextW(GetDlgItem(hwndDlg, idTitleFormat), XSFConfig::initTitleFormat.c_str());
 

--- a/src/in_xsf_framework/XSFConfig_Winamp.cpp
+++ b/src/in_xsf_framework/XSFConfig_Winamp.cpp
@@ -1,7 +1,7 @@
 /*
  * xSF - Winamp-specification configuration handler
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-30
+ * Last modification on 2013-04-23
  *
  * Partially based on the vio*sf framework
  */
@@ -36,7 +36,7 @@
 		this->iniFilename = String(reinterpret_cast<char *>(SendMessage(inMod.hMainWindow, WM_WA_IPC, 0, IPC_GETINIFILE))).GetWStr();
 	else
 	{
-		std::vector<wchar_t> executablePath(MAX_PATH / 2);
+		auto executablePath = std::vector<wchar_t>(MAX_PATH / 2);
 
 		DWORD result;
 		do
@@ -59,7 +59,7 @@
 
 std::wstring XSFConfigIO_Winamp::GetValueString(const std::wstring &name, const std::wstring &defaultValue)
 {
-	std::vector<wchar_t> value(MAX_PATH / 2);
+	auto value = std::vector<wchar_t>(MAX_PATH / 2);
 
 	DWORD result;
 	do

--- a/src/in_xsf_framework/XSFFile.h
+++ b/src/in_xsf_framework/XSFFile.h
@@ -1,7 +1,7 @@
 /*
  * xSF - File structure
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-21
+ * Last modification on 2013-04-23
  *
  * Partially based on the vio*sf framework
  */
@@ -9,9 +9,9 @@
 #ifndef XSFFILE_H
 #define XSFFILE_H
 
+#include <cstdint>
 #include "TagList.h"
 #include "BigSString.h"
-#include "pstdint.h"
 
 enum VolumeType
 {

--- a/src/in_xsf_framework/XSFPlayer.cpp
+++ b/src/in_xsf_framework/XSFPlayer.cpp
@@ -1,7 +1,7 @@
 /*
  * xSF - Core Player
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-30
+ * Last modification on 2013-04-23
  *
  * Partially based on the vio*sf framework
  */
@@ -13,8 +13,8 @@
 
 extern XSFConfig *xSFConfig;
 
-XSFPlayer::XSFPlayer() : xSF(nullptr), sampleRate(0), detectedSilenceSample(0), detectedSilenceSec(0), skipSilenceOnStartSec(5), lengthSample(0), fadeSample(0), currentSample(0),
-	prevSampleL(XSFPlayer::CHECK_SILENCE_BIAS), prevSampleR(XSFPlayer::CHECK_SILENCE_BIAS), lengthInMS(-1), fadeInMS(-1), volume(1.0), ignoreVolume(false)
+XSFPlayer::XSFPlayer() : xSF(), sampleRate(0), detectedSilenceSample(0), detectedSilenceSec(0), skipSilenceOnStartSec(5), lengthSample(0), fadeSample(0), currentSample(0),
+	prevSampleL(CHECK_SILENCE_BIAS), prevSampleR(CHECK_SILENCE_BIAS), lengthInMS(-1), fadeInMS(-1), volume(1.0), ignoreVolume(false)
 {
 }
 
@@ -30,7 +30,7 @@
 	if (this != &xSFPlayer)
 	{
 		if (!this->xSF)
-			this->xSF = new XSFFile();
+			this->xSF.reset(new XSFFile());
 		*this->xSF = *xSFPlayer.xSF;
 		this->sampleRate = xSFPlayer.sampleRate;
 		this->detectedSilenceSample = xSFPlayer.detectedSilenceSample;
@@ -65,8 +65,8 @@
 			{
 				short *bufShort = reinterpret_cast<short *>(&buf[0]);
 				unsigned long sampleL = bufShort[2 * (offset + ofs)], sampleR = bufShort[2 * (offset + ofs) + 1];
-				bool silence = (sampleL + XSFPlayer::CHECK_SILENCE_BIAS + XSFPlayer::CHECK_SILENCE_LEVEL) - this->prevSampleL <= XSFPlayer::CHECK_SILENCE_LEVEL * 2 &&
-					(sampleR + XSFPlayer::CHECK_SILENCE_BIAS + XSFPlayer::CHECK_SILENCE_LEVEL) - this->prevSampleR <= XSFPlayer::CHECK_SILENCE_LEVEL * 2;
+				bool silence = (sampleL + CHECK_SILENCE_BIAS + CHECK_SILENCE_LEVEL) - this->prevSampleL <= CHECK_SILENCE_LEVEL * 2 &&
+					(sampleR + CHECK_SILENCE_BIAS + CHECK_SILENCE_LEVEL) - this->prevSampleR <= CHECK_SILENCE_LEVEL * 2;
 
 				if (silence)
 				{
@@ -93,15 +93,15 @@
 					}
 				}
 
-				prevSampleL = sampleL + XSFPlayer::CHECK_SILENCE_BIAS;
-				prevSampleR = sampleR + XSFPlayer::CHECK_SILENCE_BIAS;
+				prevSampleL = sampleL + CHECK_SILENCE_BIAS;
+				prevSampleR = sampleR + CHECK_SILENCE_BIAS;
 			}
 
 			if (!this->skipSilenceOnStartSec)
 			{
 				if (skipOffset)
 				{
-					std::vector<uint8_t> tmpBuf = std::vector<uint8_t>(2 * skipOffset);
+					auto tmpBuf = std::vector<uint8_t>(2 * skipOffset);
 					memcpy(&tmpBuf[0], &buf[offset + 2 * skipOffset], 2 * skipOffset);
 					memcpy(&buf[offset], &tmpBuf[0], 2 * skipOffset);
 					pos += skipOffset;
@@ -186,11 +186,10 @@
 {
 	this->skipSilenceOnStartSec = xSFConfig->GetSkipSilenceOnStartSec();
 	this->currentSample = this->detectedSilenceSec = this->detectedSilenceSample = 0;
-	this->prevSampleL = this->prevSampleR = XSFPlayer::CHECK_SILENCE_BIAS;
+	this->prevSampleL = this->prevSampleR = CHECK_SILENCE_BIAS;
 }
 
 #ifdef WINAMP_PLUGIN
-
 static inline DWORD TicksDiff(DWORD prev, DWORD cur) { return cur >= prev ? cur - prev : 0xFFFFFFFF - prev + cur; }
 
 int XSFPlayer::Seek(unsigned seekPosition, volatile int *killswitch, std::vector<uint8_t> &buf, Out_Module *outMod)
@@ -229,6 +228,5 @@
 		outMod->Flush(seekPosition);
 	return 0;
 }
-
 #endif
 

--- a/src/in_xsf_framework/XSFPlayer.h
+++ b/src/in_xsf_framework/XSFPlayer.h
@@ -1,7 +1,7 @@
 /*
  * xSF - Core Player
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-25
+ * Last modification on 2013-04-23
  *
  * Partially based on the vio*sf framework
  */
@@ -22,7 +22,7 @@
 	static const unsigned CHECK_SILENCE_BIAS = 0x8000000;
 	static const unsigned CHECK_SILENCE_LEVEL = 7;
 
-	XSFFile *xSF;
+	std::unique_ptr<XSFFile> xSF;
 	unsigned sampleRate, detectedSilenceSample, detectedSilenceSec, skipSilenceOnStartSec, lengthSample, fadeSample, currentSample;
 	unsigned long prevSampleL, prevSampleR;
 	int lengthInMS, fadeInMS;
@@ -38,10 +38,10 @@
 	static XSFPlayer *Create(const std::string &fn);
 	static XSFPlayer *Create(const std::wstring &fn);
 
-	virtual ~XSFPlayer() { if (this->xSF) delete this->xSF; }
+	virtual ~XSFPlayer() { }
 	XSFPlayer &operator=(const XSFPlayer &xSFPlayer);
-	XSFFile *GetXSFFile() { return this->xSF; }
-	const XSFFile *GetXSFFile() const { return this->xSF; }
+	XSFFile *GetXSFFile() { return this->xSF.get(); }
+	const XSFFile *GetXSFFile() const { return this->xSF.get(); }
 	unsigned GetLengthInSamples() const { return this->lengthSample + this->fadeSample; }
 	unsigned GetSampleRate() const { return this->sampleRate; }
 	void SetSampleRate(unsigned newSampleRate) { this->sampleRate = newSampleRate; }

--- a/src/in_xsf_framework/convert.h
+++ b/src/in_xsf_framework/convert.h
@@ -1,7 +1,7 @@
 /*
  * Common conversion functions
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-30
+ * Last modification on 2013-04-23
  */
 
 #ifndef _CONVERT_H_
@@ -66,14 +66,14 @@
 class ConvertFuncs
 {
 private:
-	static inline bool IsDigitsOnly(const std::string &input, const std::locale &loc = std::locale::classic())
+	template<typename T> static bool IsDigitsOnly(const std::basic_string<T> &input, const std::locale &loc = std::locale::classic())
 	{
-		auto inputChars = std::vector<char>(input.begin(), input.end());
+		auto inputChars = std::vector<T>(input.begin(), input.end());
 		size_t length = inputChars.size();
-		auto masks = std::vector<std::ctype<char>::mask>(length);
-		std::use_facet<std::ctype<char>>(loc).is(&inputChars[0], &inputChars[length], &masks[0]);
+		auto masks = std::vector<std::ctype<T>::mask>(length);
+		std::use_facet<std::ctype<T>>(loc).is(&inputChars[0], &inputChars[length], &masks[0]);
 		for (size_t x = 0; x < length; ++x)
-			if (inputChars[x] != '.' && !(masks[x] & std::ctype<char>::digit))
+			if (inputChars[x] != '.' && !(masks[x] & std::ctype<T>::digit))
 				return false;
 		return true;
 	}

--- /dev/null
+++ b/src/in_xsf_framework/ialogBuilder.h
@@ -1,1 +1,678 @@
-
+/*
+ * Windows Dynamic Dialog Builder framework
+ * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
+ * Last modification on 2013-04-23
+ */
+
+#ifndef DIALOG_BUILDER_H
+#define DIALOG_BUILDER_H
+
+#include <string>
+#include <memory>
+#include <vector>
+#include <algorithm>
+#include <stdexcept>
+#include <cstdint>
+#include "windowsh_wrapper.h"
+#include "UtfConverter.h"
+
+template<typename T> struct Point
+{
+	T x, y;
+
+	Point() : x(), y() { }
+	Point(T X, T Y) : x(X), y(Y) { }
+};
+
+template<typename T> struct Size
+{
+	T width, height;
+
+	Size() : width(), height() { }
+	Size(T Width, T Height) : width(Width), height(Height) { }
+};
+
+template<typename T> struct Rect
+{
+	Point<T> position;
+	Size<T> size;
+
+	Rect() : position(), size() { }
+	Rect(const Point<T> &Position, const Size<T> &Sz) : position(Position), size(Sz) { }
+	Rect(T X, T Y, T Width, T Height) : position(X, Y), size(Width, Height) { }
+};
+
+class RelativePosition
+{
+public:
+	Point<short> relativePosition;
+	enum BaseType
+	{
+		TO_PARENT,
+		TO_SIBLING
+	} type;
+	enum PositionType
+	{
+		FROM_TOP,
+		FROM_BOTTOM,
+		FROM_LEFT,
+		FROM_RIGHT,
+		FROM_TOPLEFT,
+		FROM_BOTTOMLEFT,
+		FROM_TOPRIGHT,
+		FROM_BOTTOMRIGHT
+	} positionType;
+
+	RelativePosition(const Point<short> &RelPosition, BaseType Type, PositionType PosType) : relativePosition(RelPosition), type(Type), positionType(PosType) { }
+	virtual ~RelativePosition() { }
+	virtual RelativePosition *Clone() const = 0;
+	Point<short> CalculatePosition(const Rect<short> &child, const Rect<short> &other);
+};
+
+class RelativePositionToParent : public RelativePosition
+{
+public:
+	RelativePositionToParent(const Point<short> &RelPosition, PositionType PosType) : RelativePosition(RelPosition, TO_PARENT, PosType) { }
+	RelativePositionToParent *Clone() const { return new RelativePositionToParent(this->relativePosition, this->positionType); }
+};
+
+class RelativePositionToSibling : public RelativePosition
+{
+public:
+	short siblingsBack;
+
+	RelativePositionToSibling(const Point<short> &RelPosition, PositionType PosType, short SiblingsBack = 1) : RelativePosition(RelPosition, TO_SIBLING, PosType), siblingsBack(SiblingsBack) { }
+	RelativePositionToSibling *Clone() const { return new RelativePositionToSibling(this->relativePosition, this->positionType, this->siblingsBack); }
+};
+
+enum DialogControlType
+{
+	NO_CONTROL,
+	GROUP_CONTROL,
+	EDITBOX_CONTROL,
+	LABEL_CONTROL,
+	CHECKBOX_CONTROL,
+	BUTTON_CONTROL,
+	LISTBOX_CONTROL,
+	COMBOBOX_CONTROL
+};
+
+class DialogTemplate;
+
+class DialogBuilder
+{
+protected:
+	friend class DialogTemplate;
+	std::wstring title, fontName;
+	uint32_t style, exstyle;
+	uint16_t fontSizeInPts;
+	Size<short> size;
+	bool resetControls;
+public:
+	DialogBuilder() : title(L""), fontName(L""), style(0), exstyle(0), fontSizeInPts(0), size(), resetControls(false) { }
+	DialogBuilder &WithTitle(const std::wstring &Title) { this->title = Title; return *this; }
+	DialogBuilder &WithFont(const std::wstring &FontName, uint16_t FontSizeInPts) { this->fontName = FontName; this->fontSizeInPts = FontSizeInPts; return *this; }
+	DialogBuilder &WithSize(short Width, short Height) { this->size.width = Width; this->size.height = Height; return *this; }
+	DialogBuilder &WithSize(const Size<short> &Sz) { this->size = Sz; return *this; }
+	DialogBuilder &ResetControls(bool Reset = true) { this->resetControls = Reset; return *this; }
+	DialogBuilder &IsOverlapped() { this->style &= ~(WS_OVERLAPPED | WS_POPUP | WS_CHILD); this->style |= WS_OVERLAPPED; return *this; }
+	DialogBuilder &IsPopup() { this->style &= ~(WS_OVERLAPPED | WS_POPUP | WS_CHILD); this->style |= WS_POPUP; return *this; }
+	DialogBuilder &IsChild() { this->style &= ~(WS_OVERLAPPED | WS_POPUP | WS_CHILD); this->style |= WS_CHILD; return *this; }
+	DialogBuilder &WithBorder(bool Border = true) { if (Border) this->style |= WS_BORDER; else this->style &= ~WS_BORDER; return *this; }
+	DialogBuilder &WithDialogFrame(bool DialogFrame = true) { if (DialogFrame) this->style |= WS_DLGFRAME; else this->style &= ~WS_DLGFRAME; return *this; }
+	DialogBuilder &WithVerticalScrollbar(bool VerticalScrollbar = true) { if (VerticalScrollbar) this->style |= WS_VSCROLL; else this->style &= ~WS_VSCROLL; return *this; }
+	DialogBuilder &WithHorizontalScrollbar(bool HorizontalScrollbar = true) { if (HorizontalScrollbar) this->style |= WS_HSCROLL; else this->style &= ~WS_HSCROLL; return *this; }
+	DialogBuilder &WithSystemMenu(bool SystemMenu = true) { if (SystemMenu) this->style |= WS_SYSMENU; else this->style &= ~WS_SYSMENU; return *this; }
+	DialogBuilder &WithSizingBorder(bool SizingBorder = true) { if (SizingBorder) this->style |= WS_THICKFRAME; else this->style &= ~WS_THICKFRAME; return *this; }
+	DialogBuilder &WithMinimizeBox(bool MinimizeBox = true) { if (MinimizeBox) this->style |= WS_MINIMIZEBOX; else this->style &= ~WS_MINIMIZEBOX; return *this; }
+	DialogBuilder &WithMaximizeBox(bool MaximizeBox = true) { if (MaximizeBox) this->style |= WS_MAXIMIZEBOX; else this->style &= ~WS_MAXIMIZEBOX; return *this; }
+	DialogBuilder &WithDialogModalFrame(bool DialogModalFrame = true) { if (DialogModalFrame) this->exstyle |= WS_EX_DLGMODALFRAME; else this->exstyle &= ~WS_EX_DLGMODALFRAME; return *this; }
+#if WINVER >= 0x0400
+	DialogBuilder &WithRaisedEdge(bool RaisedEdge = true) { if (RaisedEdge) this->exstyle |= WS_EX_WINDOWEDGE; else this->exstyle &= ~WS_EX_WINDOWEDGE; return *this; }
+	DialogBuilder &WithSunkenEdge(bool SunkenEdge = true) { if (SunkenEdge) this->exstyle |= WS_EX_CLIENTEDGE; else this->exstyle &= ~WS_EX_CLIENTEDGE; return *this; }
+	DialogBuilder &WithContextHelp(bool ContextHelp = true) { if (ContextHelp) this->exstyle |= WS_EX_CONTEXTHELP; else this->exstyle &= ~WS_EX_CONTEXTHELP; return *this; }
+	DialogBuilder &IsControlWindow(bool ControlWindow = true) { if (ControlWindow) this->style |= DS_CONTROL; else this->style &= ~DS_CONTROL; return *this; }
+	DialogBuilder &IsCentered(bool Centered = true) { if (Centered) this->style |= DS_CENTER; else this->style &= ~DS_CENTER; return *this; }
+#endif
+};
+
+template<class T> class DialogControlBuilder
+{
+protected:
+	friend class DialogTemplate;
+	DialogControlType controlType;
+	uint32_t style, exstyle;
+	Rect<short> rect;
+	short id;
+	int index;
+	std::unique_ptr<RelativePosition> relativePosition;
+
+	T &me() { return dynamic_cast<T &>(*this); }
+public:
+	DialogControlBuilder(DialogControlType Type = NO_CONTROL) : controlType(Type), style(0), exstyle(0), rect(), id(-1), index(-1), relativePosition() { }
+	virtual ~DialogControlBuilder() { }
+	T &WithPosition(short X, short Y) { this->rect.position.x = X; this->rect.position.y = Y; return this->me(); }
+	T &WithPosition(const Point<short> &Position) { this->rect.position = Position; return this->me(); }
+	T &WithRelativePositionToParent(RelativePosition::PositionType PosType, const Point<short> &RelativePosition)
+	{
+		this->relativePosition.reset(new RelativePositionToParent(RelativePosition, PosType));
+		return this->me();
+	}
+	T &WithRelativePositionToSibling(RelativePosition::PositionType PosType, const Point<short> &RelativePosition, short SiblingsBack = 1)
+	{
+		this->relativePosition.reset(new RelativePositionToSibling(RelativePosition, PosType, SiblingsBack));
+		return this->me();
+	}
+	T &WithSize(short Width, short Height) { this->rect.size.width = Width; this->rect.size.height = Height; return this->me(); }
+	T &WithSize(const Size<short> &Sz) { this->rect.size = Sz; return this->me(); }
+	T &WithID(short ID) { this->id = ID; return this->me(); }
+	T &AtIndex(int Index) { this->index = Index; return this->me(); }
+	T &IsDisabled(bool Disabled = true) { if (Disabled) this->style |= WS_DISABLED; else this->style &= ~WS_DISABLED; return this->me(); }
+	T &WithBorder(bool ThinBorder = true) { if (ThinBorder) this->style |= WS_BORDER; else this->style &= ~WS_BORDER; return this->me(); }
+	T &WithVerticalScrollbar(bool VerticalScrollbar = true) { if (VerticalScrollbar) this->style |= WS_VSCROLL; else this->style &= ~WS_VSCROLL; return this->me(); }
+	T &WithHorizontalScrollbar(bool HorizontalScrollbar = true) { if (HorizontalScrollbar) this->style |= WS_HSCROLL; else this->style &= ~WS_HSCROLL; return this->me(); }
+	T &WithTabStop(bool TabStop = true) { if (TabStop) this->style |= WS_TABSTOP; else this->style &= ~WS_TABSTOP; return this->me(); }
+#if WINVER >= 0x0400
+	T &WithRaisedEdge(bool RaisedEdge = true) { if (RaisedEdge) this->exstyle |= WS_EX_WINDOWEDGE; else this->exstyle &= ~WS_EX_WINDOWEDGE; return this->me(); }
+	T &WithSunkenEdge(bool SunkenEdge = true) { if (SunkenEdge) this->exstyle |= WS_EX_CLIENTEDGE; else this->exstyle &= ~WS_EX_CLIENTEDGE; return this->me(); }
+#endif
+};
+
+class DialogGroupBuilder : public DialogControlBuilder<DialogGroupBuilder>
+{
+protected:
+	friend class DialogTemplate;
+	std::wstring groupName;
+public:
+	DialogGroupBuilder(const std::wstring &newGroupName) : DialogControlBuilder(GROUP_CONTROL), groupName(newGroupName) { }
+};
+
+template<class T> class DialogInGroupBuilder : public DialogControlBuilder<T>
+{
+protected:
+	friend class DialogTemplate;
+	std::wstring groupName;
+public:
+	DialogInGroupBuilder(DialogControlType Type) : DialogControlBuilder<T>(Type), groupName(L"") { }
+	T &InGroup(const std::wstring &GroupName) { this->groupName = GroupName; return this->me(); }
+};
+
+class DialogEditBoxBuilder : public DialogInGroupBuilder<DialogEditBoxBuilder>
+{
+protected:
+	friend class DialogTemplate;
+public:
+	DialogEditBoxBuilder() : DialogInGroupBuilder(EDITBOX_CONTROL) { }
+	DialogEditBoxBuilder &IsLeftJustified() { this->style &= ~(ES_LEFT | ES_CENTER | ES_RIGHT); this->style |= ES_LEFT; return this->me(); }
+	DialogEditBoxBuilder &IsCenterJustified() { this->style &= ~(ES_LEFT | ES_CENTER | ES_RIGHT); this->style |= ES_CENTER; return this->me(); }
+	DialogEditBoxBuilder &IsRightJustified() { this->style &= ~(ES_LEFT | ES_CENTER | ES_RIGHT); this->style |= ES_RIGHT; return this->me(); }
+	DialogEditBoxBuilder &IsMultiline(bool Multiline = true) { if (Multiline) this->style |= ES_MULTILINE; else this->style &= ~ES_MULTILINE; return this->me(); }
+	DialogEditBoxBuilder &WithAllUppercase(bool AllUppercase = true) { if (AllUppercase) this->style |= ES_UPPERCASE; else this->style &= ~ES_UPPERCASE; return this->me(); }
+	DialogEditBoxBuilder &WithAllLowercase(bool AllLowercase = true) { if (AllLowercase) this->style |= ES_LOWERCASE; else this->style &= ~ES_LOWERCASE; return this->me(); }
+	DialogEditBoxBuilder &IsPasswordInput(bool PasswordInput = true) { if (PasswordInput) this->style |= ES_PASSWORD; else this->style &= ~ES_PASSWORD; return this->me(); }
+	DialogEditBoxBuilder &WithAutoVScroll(bool AutoVScroll = true) { if (AutoVScroll) this->style |= ES_AUTOVSCROLL; else this->style &= ~ES_AUTOVSCROLL; return this->me(); }
+	DialogEditBoxBuilder &WithAutoHScroll(bool AutoHScroll = true) { if (AutoHScroll) this->style |= ES_AUTOHSCROLL; else this->style &= ~ES_AUTOHSCROLL; return this->me(); }
+	DialogEditBoxBuilder &WithDontHideSelection(bool DontHideSelection = true) { if (DontHideSelection) this->style |= ES_NOHIDESEL; else this->style &= ~ES_NOHIDESEL; return this->me(); }
+	DialogEditBoxBuilder &IsReadOnly(bool ReadOnly = true) { if (ReadOnly) this->style |= ES_READONLY; else this->style &= ~ES_READONLY; return this->me(); }
+	DialogEditBoxBuilder &WithWantReturn(bool WantReturn = true) { if (WantReturn) this->style |= ES_WANTRETURN; else this->style &= ~ES_WANTRETURN; return this->me(); }
+};
+
+template<class T> class DialogControlWithLabelBuilder : public DialogInGroupBuilder<T>
+{
+protected:
+	friend class DialogTemplate;
+	std::wstring label;
+public:
+	DialogControlWithLabelBuilder(DialogControlType Type, const std::wstring &Label) : DialogInGroupBuilder<T>(Type), label(Label) { }
+};
+
+class DialogLabelBuilder : public DialogControlWithLabelBuilder<DialogLabelBuilder>
+{
+protected:
+	friend class DialogTemplate;
+public:
+	DialogLabelBuilder(const std::wstring &Label) : DialogControlWithLabelBuilder(LABEL_CONTROL, Label) { }
+	DialogLabelBuilder &IsLeftJustified(bool WithWordWrap = false)
+	{
+		this->style &= ~(SS_LEFT | SS_CENTER | SS_RIGHT | SS_LEFTNOWORDWRAP);
+		if (WithWordWrap)
+			this->style |= SS_LEFTNOWORDWRAP;
+		else
+			this->style |= SS_LEFT;
+		return this->me();
+	}
+	DialogLabelBuilder &IsCenterJustified() { this->style &= ~(SS_LEFT | SS_CENTER | SS_RIGHT | SS_LEFTNOWORDWRAP); this->style |= SS_CENTER; return this->me(); }
+	DialogLabelBuilder &IsRightJustified() { this->style &= ~(SS_LEFT | SS_CENTER | SS_RIGHT | SS_LEFTNOWORDWRAP); this->style |= SS_RIGHT; return this->me(); }
+	DialogLabelBuilder &WithAmpsNotTranslated(bool AmpsNotTranslated = true) { if (AmpsNotTranslated) this->style |= SS_NOPREFIX; else this->style &= ~SS_NOPREFIX; return this->me(); }
+#if WINVER >= 0x0400
+	DialogLabelBuilder &WithNotify(bool Notify = true) { if (Notify) this->style |= SS_NOTIFY; else this->style &= ~SS_NOTIFY; return this->me(); }
+#endif
+};
+
+template<class T> class DialogButtonBaseBuilder : public DialogControlWithLabelBuilder<T>
+{
+protected:
+	friend class DialogTemplate;
+public:
+	DialogButtonBaseBuilder(DialogControlType Type, const std::wstring &Label) : DialogControlWithLabelBuilder<T>(Type, Label) { }
+#if WINVER >= 0x0400
+	T &IsLeftJustified(bool LeftJustified = true)
+	{
+		if (LeftJustified)
+		{
+			this->style |= BS_LEFT;
+			this->style &= ~BS_RIGHT;
+		}
+		else
+			this->style &= ~BS_LEFT;
+		return this->me();
+	}
+	T &IsRightJustified(bool RightJustified = true)
+	{
+		if (RightJustified)
+		{
+			this->style |= BS_RIGHT;
+			this->style &= ~BS_LEFT;
+		}
+		else
+			this->style &= ~BS_RIGHT;
+		return this->me();
+	}
+	T &IsCenterJustified(bool CenterJustified = true) { if (CenterJustified) this->style |= BS_CENTER; else this->style &= ~BS_CENTER; return this->me(); }
+	T &WithVerticalTop(bool VerticalTop = true)
+	{
+		if (VerticalTop)
+		{
+			this->style |= BS_TOP;
+			this->style &= ~BS_BOTTOM;
+		}
+		else
+			this->style &= ~BS_TOP;
+		return this->me();
+	}
+	T &WithVerticalBottom(bool VerticalBottom = true)
+	{
+		if (VerticalBottom)
+		{
+			this->style |= BS_BOTTOM;
+			this->style &= ~BS_TOP;
+		}
+		else
+			this->style &= ~BS_BOTTOM;
+		return this->me();
+	}
+	T &WithVerticalCenter(bool VerticalCenter = true) { if (VerticalCenter) this->style |= BS_VCENTER; else this->style &= ~BS_VCENTER; return this->me(); }
+	T &IsMultiline(bool Multiline = true) { if (Multiline) this->style |= BS_MULTILINE; else this->style &= ~BS_MULTILINE; return this->me(); }
+	T &WithNotify(bool Notify = true) { if (Notify) this->style |= BS_NOTIFY; else this->style &= ~BS_NOTIFY; return this->me(); }
+	T &IsFlat(bool Flat = true) { if (Flat) this->style |= BS_FLAT; else this->style &= ~BS_FLAT; return this->me(); }
+#endif
+};
+
+class DialogButtonBuilder : public DialogButtonBaseBuilder<DialogButtonBuilder>
+{
+protected:
+	friend class DialogTemplate;
+public:
+	DialogButtonBuilder(const std::wstring &Label) : DialogButtonBaseBuilder(BUTTON_CONTROL, Label) { }
+	DialogButtonBuilder &IsDefault(bool Default = true) { if (Default) this->style |= BS_DEFPUSHBUTTON; else this->style &= ~BS_DEFPUSHBUTTON; return this->me(); }
+};
+
+class DialogCheckBoxBuilder : public DialogButtonBaseBuilder<DialogCheckBoxBuilder>
+{
+protected:
+	friend class DialogTemplate;
+public:
+	DialogCheckBoxBuilder(const std::wstring &Label) : DialogButtonBaseBuilder(CHECKBOX_CONTROL, Label) { this->style |= BS_AUTOCHECKBOX; }
+	DialogCheckBoxBuilder &WithTextOnLeft(bool TextOnLeft = true) { if (TextOnLeft) this->style |= BS_LEFTTEXT; else this->style &= ~BS_LEFTTEXT; return this->me(); }
+	DialogCheckBoxBuilder &LikePushButton(bool PushButton = true) { if (PushButton) this->style |= BS_PUSHLIKE; else this->style &= ~BS_PUSHLIKE; return this->me(); }
+};
+
+class DialogListBoxBuilder : public DialogInGroupBuilder<DialogListBoxBuilder>
+{
+protected:
+	friend class DialogTemplate;
+public:
+	DialogListBoxBuilder() : DialogInGroupBuilder(LISTBOX_CONTROL) { }
+	DialogListBoxBuilder &WithNotify(bool Notify = true) { if (Notify) this->style |= LBS_NOTIFY; else this->style &= ~LBS_NOTIFY; return this->me(); }
+	DialogListBoxBuilder &WithSort(bool Sort = true) { if (Sort) this->style |= LBS_SORT; else this->style &= ~LBS_SORT; return this->me(); }
+	DialogListBoxBuilder &WithMultipleSelect(bool MultipleSelect = true) { if (MultipleSelect) this->style |= LBS_MULTIPLESEL; else this->style &= ~LBS_MULTIPLESEL; return this->me(); }
+	DialogListBoxBuilder &WithExactHeight(bool ExactHeight = true) { if (ExactHeight) this->style |= LBS_NOINTEGRALHEIGHT; else this->style &= ~LBS_NOINTEGRALHEIGHT; return this->me(); }
+	DialogListBoxBuilder &WithMultipleColumns(bool MultipleColumns = true) { if (MultipleColumns) this->style |= LBS_MULTICOLUMN; else this->style &= ~LBS_MULTICOLUMN; return this->me(); }
+	DialogListBoxBuilder &WithExtendedSelect(bool ExtendedSelect = true) { if (ExtendedSelect) this->style |= LBS_EXTENDEDSEL; else this->style &= ~LBS_EXTENDEDSEL; return this->me(); }
+	DialogListBoxBuilder &WithDisabledNoScroll(bool DisabledNoScroll = true) { if (DisabledNoScroll) this->style |= LBS_DISABLENOSCROLL; else this->style &= ~LBS_DISABLENOSCROLL; return this->me(); }
+#if WINVER >= 0x0400
+	DialogListBoxBuilder &WithNoSelect(bool NoSelect = true) { if (NoSelect) this->style |= LBS_NOSEL; else this->style &= ~LBS_NOSEL; return this->me(); }
+#endif
+};
+
+class DialogComboBoxBuilder : public DialogInGroupBuilder<DialogComboBoxBuilder>
+{
+protected:
+	friend class DialogTemplate;
+public:
+	DialogComboBoxBuilder() : DialogInGroupBuilder(COMBOBOX_CONTROL) { }
+	DialogComboBoxBuilder &IsSimple() { this->style &= ~(CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST); this->style |= CBS_SIMPLE; return this->me(); }
+	DialogComboBoxBuilder &IsDropDown() { this->style &= ~(CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST); this->style |= CBS_DROPDOWN; return this->me(); }
+	DialogComboBoxBuilder &IsDropDownList() { this->style &= ~(CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST); this->style |= CBS_DROPDOWNLIST; return this->me(); }
+	DialogComboBoxBuilder &WithAutoHScroll(bool AutoHScroll = true) { if (AutoHScroll) this->style |= CBS_AUTOHSCROLL; else this->style &= ~CBS_AUTOHSCROLL; return this->me(); }
+	DialogComboBoxBuilder &WithSort(bool Sort = true) { if (Sort) this->style |= CBS_SORT; else this->style &= ~CBS_SORT; return this->me(); }
+	DialogComboBoxBuilder &WithExactHeight(bool ExactHeight = true) { if (ExactHeight) this->style |= CBS_NOINTEGRALHEIGHT; else this->style &= ~CBS_NOINTEGRALHEIGHT; return this->me(); }
+	DialogComboBoxBuilder &WithDisabledNoScroll(bool DisabledNoScroll = true) { if (DisabledNoScroll) this->style |= CBS_DISABLENOSCROLL; else this->style &= ~CBS_DISABLENOSCROLL; return this->me(); }
+#if WINVER >= 0x0400
+	DialogComboBoxBuilder &WithAllLowercase(bool AllLowercase = true) { if (AllLowercase) this->style |= CBS_LOWERCASE; else this->style &= ~CBS_LOWERCASE; return this->me(); }
+	DialogComboBoxBuilder &WithAllUppercase(bool AllUppercase = true) { if (AllUppercase) this->style |= CBS_UPPERCASE; else this->style &= ~CBS_UPPERCASE; return this->me(); }
+#endif
+};
+
+class DialogTemplate
+{
+	class DialogControl;
+
+	typedef std::vector<std::unique_ptr<DialogControl>> Controls;
+
+	class DialogControl
+	{
+	protected:
+		DialogControlType controlType;
+		uint32_t style, exstyle;
+		Rect<short> rect;
+		short id;
+		std::unique_ptr<RelativePosition> relativePosition;
+
+		friend class DialogTemplate;
+		DialogControl() : controlType(NO_CONTROL), style(0), exstyle(0), rect(), id(-1), relativePosition() { }
+		DialogControl(const DialogControl &control) : controlType(control.controlType), style(control.style), exstyle(control.exstyle), rect(control.rect), id(control.id),
+			relativePosition(control.relativePosition ? control.relativePosition->Clone() : nullptr) { }
+		DialogControl &operator=(const DialogControl &control)
+		{
+			this->controlType = control.controlType;
+			this->style = control.style;
+			this->exstyle = control.exstyle;
+			this->rect = control.rect;
+			this->id = control.id;
+			if (control.relativePosition)
+				this->relativePosition.reset(control.relativePosition->Clone());
+			else
+				this->relativePosition.reset();
+
+			return *this;
+		}
+	public:
+		virtual ~DialogControl() { }
+		template<typename Control, typename Builder> static std::unique_ptr<Control> CreateControl(const DialogControlBuilder<Builder> &builder)
+		{
+			auto control = std::unique_ptr<Control>(new Control());
+
+			control->controlType = builder.controlType;
+			control->style = builder.style;
+			control->exstyle = builder.exstyle;
+			control->rect = builder.rect;
+			control->id = builder.id;
+			if (builder.relativePosition)
+				control->relativePosition.reset(builder.relativePosition->Clone());
+
+			return control;
+		}
+		virtual uint16_t GetControlCount() const { return 1; }
+		virtual short GetControlHeight() const { return this->rect.size.height; }
+		virtual std::vector<uint8_t> GenerateControlTemplate() const = 0;
+		virtual DialogControl *Clone() const = 0;
+	};
+
+	class DialogGroup : public DialogControl
+	{
+	protected:
+		DialogTemplate::Controls controls;
+		std::wstring groupName;
+
+		friend class DialogTemplate;
+		friend class DialogControl;
+		DialogGroup() : DialogControl(), controls(), groupName(L"") { }
+		DialogGroup(const DialogGroup &control) : DialogControl(control), controls(), groupName(control.groupName)
+		{
+			std::for_each(control.controls.begin(), control.controls.end(), [&](const std::unique_ptr<DialogControl> &control) { this->controls.push_back(std::unique_ptr<DialogControl>(control->Clone())); });
+		}
+		DialogGroup &operator=(const DialogGroup &control)
+		{
+			DialogControl::operator=(control);
+
+			this->controls.clear();
+			std::for_each(control.controls.begin(), control.controls.end(), [&](const std::unique_ptr<DialogControl> &control) { this->controls.push_back(std::unique_ptr<DialogControl>(control->Clone())); });
+
+			this->groupName = control.groupName;
+
+			return *this;
+		}
+	public:
+		static std::unique_ptr<DialogGroup> CreateControl(const DialogControlBuilder<DialogGroupBuilder> &builder)
+		{
+			auto control = DialogControl::CreateControl<DialogGroup>(builder);
+
+			control->groupName = dynamic_cast<const DialogGroupBuilder &>(builder).groupName;
+
+			return control;
+		}
+		void CalculatePositions(bool doRightAndBottom = false);
+		void CalculateSize();
+		uint16_t GetControlCount() const;
+		std::vector<uint8_t> GenerateControlTemplate() const;
+		DialogGroup *Clone() const { return new DialogGroup(*this); }
+	};
+
+	class DialogControlWithoutLabel : public DialogControl
+	{
+	protected:
+		uint16_t type;
+
+		friend class DialogTemplate;
+		friend class DialogControl;
+		DialogControlWithoutLabel() : DialogControl(), type(0) { }
+		DialogControlWithoutLabel(const DialogControlWithoutLabel &control) : DialogControl(control), type(control.type) { }
+		DialogControlWithoutLabel &operator=(const DialogControlWithoutLabel &control)
+		{
+			DialogControl::operator=(control);
+
+			this->type = control.type;
+
+			return *this;
+		}
+	public:
+		template<typename Control, typename Builder> static std::unique_ptr<Control> CreateControl(const DialogControlBuilder<Builder> &builder, uint16_t Type)
+		{
+			auto control = DialogControl::CreateControl<Control>(builder);
+
+			control->type = Type;
+
+			return control;
+		}
+		virtual std::vector<uint8_t> GenerateControlTemplate() const;
+		virtual DialogControlWithoutLabel *Clone() const { return new DialogControlWithoutLabel(*this); }
+	};
+
+	class DialogControlWithLabel : public DialogControl
+	{
+	protected:
+		uint16_t type;
+		std::wstring label;
+
+		friend class DialogTemplate;
+		friend class DialogControl;
+		DialogControlWithLabel() : DialogControl(), type(0), label(L"") { }
+		DialogControlWithLabel(const DialogControlWithLabel &control) : DialogControl(control), type(control.type), label(control.label) { }
+		DialogControlWithLabel &operator=(const DialogControlWithLabel &control)
+		{
+			DialogControl::operator=(control);
+
+			this->type = control.type;
+			this->label = control.label;
+
+			return *this;
+		}
+	public:
+		template<typename Control, typename Builder> static std::unique_ptr<Control> CreateControl(const DialogControlBuilder<Builder> &builder, uint16_t Type)
+		{
+			auto control = DialogControl::CreateControl<Control>(builder);
+
+			control->type = Type;
+			control->label = dynamic_cast<const DialogControlWithLabelBuilder<Builder> &>(builder).label;
+
+			return control;
+		}
+		virtual std::vector<uint8_t> GenerateControlTemplate() const;
+		virtual DialogControlWithLabel *Clone() const { return new DialogControlWithLabel(*this); }
+	};
+
+	class DialogEditBox : public DialogControlWithoutLabel
+	{
+	protected:
+		friend class DialogTemplate;
+		friend class DialogControl;
+		DialogEditBox() : DialogControlWithoutLabel() { }
+	public:
+		static std::unique_ptr<DialogEditBox> CreateControl(const DialogControlBuilder<DialogEditBoxBuilder> &builder)
+		{
+			return DialogControlWithoutLabel::CreateControl<DialogEditBox>(builder, 0x0081);
+		}
+	};
+
+	class DialogLabel : public DialogControlWithLabel
+	{
+	protected:
+		friend class DialogTemplate;
+		friend class DialogControl;
+		DialogLabel() : DialogControlWithLabel() { }
+	public:
+		static std::unique_ptr<DialogLabel> CreateControl(const DialogControlBuilder<DialogLabelBuilder> &builder)
+		{
+			return DialogControlWithLabel::CreateControl<DialogLabel>(builder, 0x0082);
+		}
+	};
+
+	class DialogButton : public DialogControlWithLabel
+	{
+	protected:
+		friend class DialogTemplate;
+		friend class DialogControl;
+		DialogButton() : DialogControlWithLabel() { }
+	public:
+		template<typename Builder> static std::unique_ptr<DialogButton> CreateControl(const DialogControlBuilder<Builder> &builder)
+		{
+			return DialogControlWithLabel::CreateControl<DialogButton>(builder, 0x0080);
+		}
+	};
+
+	class DialogListBox : public DialogControlWithoutLabel
+	{
+	protected:
+		friend class DialogTemplate;
+		friend class DialogControl;
+		DialogListBox() : DialogControlWithoutLabel() { }
+	public:
+		static std::unique_ptr<DialogListBox> CreateControl(const DialogControlBuilder<DialogListBoxBuilder> &builder)
+		{
+			return DialogControlWithoutLabel::CreateControl<DialogListBox>(builder, 0x0083);
+		}
+	};
+
+	class DialogComboBox : public DialogControlWithoutLabel
+	{
+	protected:
+		friend class DialogTemplate;
+		friend class DialogControl;
+		DialogComboBox() : DialogControlWithoutLabel() { }
+	public:
+		static std::unique_ptr<DialogComboBox> CreateControl(const DialogControlBuilder<DialogComboBoxBuilder> &builder)
+		{
+			return DialogControlWithoutLabel::CreateControl<DialogComboBox>(builder, 0x0085);
+		}
+		short GetControlHeight() const { return (this->style & CBS_SIMPLE && !(this->style & CBS_DROPDOWNLIST)) ? this->rect.size.height : 14; }
+	};
+
+	std::wstring title;
+	uint32_t style, exstyle;
+	std::wstring fontName;
+	uint16_t fontSizeInPts;
+	Size<short> size;
+	DialogTemplate::Controls controls;
+	std::vector<uint8_t> templateData;
+
+	template<typename Builder> void AddControlToGroup(std::unique_ptr<DialogControl> &&control, const DialogControlBuilder<Builder> &builder)
+	{
+		const auto &groupBuilder = dynamic_cast<const DialogInGroupBuilder<Builder> &>(builder);
+		if (groupBuilder.groupName.empty())
+		{
+			if (builder.index == -1)
+				this->controls.push_back(std::move(control));
+			else
+				this->controls.insert(this->controls.begin() + builder.index, std::move(control));
+		}
+		else
+		{
+			for (auto curr = this->controls.begin(), end = this->controls.end(); curr != end; ++curr)
+			{
+				if ((*curr)->controlType != GROUP_CONTROL)
+					continue;
+				DialogGroup *group = dynamic_cast<DialogGroup *>(curr->get());
+				if (group->groupName == groupBuilder.groupName)
+				{
+					if (builder.index == -1)
+						group->controls.push_back(std::move(control));
+					else
+						group->controls.insert(group->controls.begin() + builder.index, std::move(control));
+					return;
+				}
+			}
+			throw std::runtime_error("Group " + UtfConverter::ToUtf8(groupBuilder.groupName) + " was not found.");
+		}
+	}
+	uint16_t GetTotalControlCount() const;
+	bool CalculateControlPosition(short index, bool doRightAndBottom = false);
+	void CalculateSize();
+public:
+	DialogTemplate() : title(L""), style(0), exstyle(0), fontName(L""), fontSizeInPts(0), size(), controls(), templateData() { }
+	DialogTemplate(const DialogBuilder &builder) : title(builder.title), style(builder.style), exstyle(builder.exstyle), fontName(builder.fontName), fontSizeInPts(builder.fontSizeInPts),
+		size(builder.size), controls(), templateData() { }
+	DialogTemplate(const DialogTemplate &dlg) : title(dlg.title), style(dlg.style), exstyle(dlg.style), fontName(dlg.fontName), fontSizeInPts(dlg.fontSizeInPts), size(dlg.size),
+		controls(), templateData()
+	{
+		std::for_each(dlg.controls.begin(), dlg.controls.end(), [&](const std::unique_ptr<DialogControl> &control) { this->controls.push_back(std::unique_ptr<DialogControl>(control->Clone())); });
+	}
+	DialogTemplate &operator=(const DialogBuilder &builder)
+	{
+		this->title = builder.title;
+		this->style = builder.style;
+		this->exstyle = builder.exstyle;
+		this->fontName = builder.fontName;
+		this->fontSizeInPts = builder.fontSizeInPts;
+		this->size = builder.size;
+		if (builder.resetControls)
+			this->controls.clear();
+
+		return *this;
+	}
+	DialogTemplate &operator=(const DialogTemplate &dlg)
+	{
+		this->title = dlg.title;
+		this->style = dlg.style;
+		this->exstyle = dlg.exstyle;
+		this->fontName = dlg.fontName;
+		this->fontSizeInPts = dlg.fontSizeInPts;
+		this->size = dlg.size;
+		this->controls.clear();
+		std::for_each(dlg.controls.begin(), dlg.controls.end(), [&](const std::unique_ptr<DialogControl> &control) { this->controls.push_back(std::unique_ptr<DialogControl>(control->Clone())); });
+
+		return *this;
+	}
+	void AddGroupControl(const DialogControlBuilder<DialogGroupBuilder> &builder);
+	void AddEditBoxControl(const DialogControlBuilder<DialogEditBoxBuilder> &builder);
+	void AddLabelControl(const DialogControlBuilder<DialogLabelBuilder> &builder);
+	void AddCheckBoxControl(const DialogControlBuilder<DialogCheckBoxBuilder> &builder);
+	void AddButtonControl(const DialogControlBuilder<DialogButtonBuilder> &builder);
+	void AddListBoxControl(const DialogControlBuilder<DialogListBoxBuilder> &builder);
+	void AddComboBoxControl(const DialogControlBuilder<DialogComboBoxBuilder> &builder);
+	void AutoSize();
+	const DLGTEMPLATE *GenerateTemplate();
+};
+
+#endif
+

--- a/src/in_xsf_framework/in_xsf.cpp
+++ b/src/in_xsf_framework/in_xsf.cpp
@@ -1,7 +1,7 @@
 /*
  * xSF - Winamp plugin
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-04-10
+ * Last modification on 2013-04-23
  *
  * Partially based on the vio*sf framework
  */
@@ -308,7 +308,7 @@
 
 static eq_str eqstr;
 
-extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, const char *data, char *dest, size_t destlen)
+template<typename T> int wrapperWinampGetExtendedFileInfo(const XSFFile &file, const char *data, T *dest, size_t destlen)
 {
 	if (eqstr(data, "type"))
 	{
@@ -324,7 +324,6 @@
 	{
 		try
 		{
-			XSFFile file = XSFFile(fn);
 			std::string tagToGet = data;
 			if (eqstr(data, "album"))
 				tagToGet = "game";
@@ -336,7 +335,7 @@
 			}
 			else if (eqstr(tagToGet, "length"))
 			{
-				strcpy(dest, stringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade())).c_str());
+				String(stringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade()))).Substring(0, destlen - 1).CopyToString(dest, true);
 				return 1;
 			}
 			file.GetTagValue(tagToGet).Substring(0, destlen - 1).CopyToString(dest, true);
@@ -349,44 +348,29 @@
 	}
 }
 
+extern "C" __declspec(dllexport) int winampGetExtendedFileInfo(const char *fn, const char *data, char *dest, size_t destlen)
+{
+	try
+	{
+		auto file = XSFFile(fn);
+		return wrapperWinampGetExtendedFileInfo(file, data, dest, destlen);
+	}
+	catch (const std::exception &)
+	{
+		return 0;
+	}
+}
+
 extern "C" __declspec(dllexport) int winampGetExtendedFileInfoW(const wchar_t *fn, const char *data, wchar_t *dest, size_t destlen)
 {
-	if (eqstr(data, "type"))
-	{
-		dest[0] = L'0';
-		dest[1] = 0;
-		return 1;
-	}
-	else if (eqstr(data, "family"))
-	{
-		return 0;
-	}
-	else
-	{
-		try
-		{
-			XSFFile file = XSFFile(fn);
-			std::string tagToGet = data;
-			if (eqstr(data, "album"))
-				tagToGet = "game";
-			if (!file.GetTagExists(tagToGet))
-			{
-				if (eqstr(tagToGet, "replaygain_track_gain"))
-					return 1;
-				return 0;
-			}
-			else if (eqstr(tagToGet, "length"))
-			{
-				wcscpy(dest, wstringify(file.GetLengthMS(xSFConfig->GetDefaultLength()) + file.GetFadeMS(xSFConfig->GetDefaultFade())).c_str());
-				return 1;
-			}
-			file.GetTagValue(tagToGet).Substring(0, destlen - 1).CopyToString(dest);
-			return 1;
-		}
-		catch (const std::exception &)
-		{
-			return 0;
-		}
+	try
+	{
+		auto file = XSFFile(fn);
+		return wrapperWinampGetExtendedFileInfo(file, data, dest, destlen);
+	}
+	catch (const std::exception &)
+	{
+		return 0;
 	}
 }
 
@@ -402,7 +386,7 @@
 {
 	try
 	{
-		if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().GetStr() != fn)
+		if (!extendedXSFFile || extendedXSFFile->GetFilename().GetStr() != fn)
 			extendedXSFFile.reset(new XSFFile(fn));
 		return wrapperWinampSetExtendedFileInfo(data, val);
 	}
@@ -416,7 +400,7 @@
 {
 	try
 	{
-		if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().GetWStr() != fn)
+		if (!extendedXSFFile || extendedXSFFile->GetFilename().GetWStr() != fn)
 			extendedXSFFile.reset(new XSFFile(fn));
 		return wrapperWinampSetExtendedFileInfo(data, val);
 	}
@@ -428,7 +412,7 @@
 
 extern "C" __declspec(dllexport) int winampWriteExtendedFileInfo()
 {
-	if (!extendedXSFFile.get() || extendedXSFFile->GetFilename().empty())
+	if (!extendedXSFFile || extendedXSFFile->GetFilename().empty())
 		return 0;
 	extendedXSFFile->SaveFile();
 	return 1;

--- a/src/in_xsf_framework/pstdint.h
+++ /dev/null
@@ -1,801 +1,1 @@
-/*  A portable stdint.h
- ****************************************************************************
- *  BSD License:
- ****************************************************************************
- *
- *  Copyright (c) 2005-2011 Paul Hsieh
- *  All rights reserved.
- *
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions
- *  are met:
- *
- *  1. Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *  2. Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *  3. The name of the author may not be used to endorse or promote products
- *     derived from this software without specific prior written permission.
- *
- *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- *  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************
- *
- *  Version 0.1.12
- *
- *  The ANSI C standard committee, for the C99 standard, specified the
- *  inclusion of a new standard include file called stdint.h.  This is
- *  a very useful and long desired include file which contains several
- *  very precise definitions for integer scalar types that is
- *  critically important for making portable several classes of
- *  applications including cryptography, hashing, variable length
- *  integer libraries and so on.  But for most developers its likely
- *  useful just for programming sanity.
- *
- *  The problem is that most compiler vendors have decided not to
- *  implement the C99 standard, and the next C++ language standard
- *  (which has a lot more mindshare these days) will be a long time in
- *  coming and its unknown whether or not it will include stdint.h or
- *  how much adoption it will have.  Either way, it will be a long time
- *  before all compilers come with a stdint.h and it also does nothing
- *  for the extremely large number of compilers available today which
- *  do not include this file, or anything comparable to it.
- *
- *  So that's what this file is all about.  Its an attempt to build a
- *  single universal include file that works on as many platforms as
- *  possible to deliver what stdint.h is supposed to.  A few things
- *  that should be noted about this file:
- *
- *    1) It is not guaranteed to be portable and/or present an identical
- *       interface on all platforms.  The extreme variability of the
- *       ANSI C standard makes this an impossibility right from the
- *       very get go. Its really only meant to be useful for the vast
- *       majority of platforms that possess the capability of
- *       implementing usefully and precisely defined, standard sized
- *       integer scalars.  Systems which are not intrinsically 2s
- *       complement may produce invalid constants.
- *
- *    2) There is an unavoidable use of non-reserved symbols.
- *
- *    3) Other standard include files are invoked.
- *
- *    4) This file may come in conflict with future platforms that do
- *       include stdint.h.  The hope is that one or the other can be
- *       used with no real difference.
- *
- *    5) In the current verison, if your platform can't represent
- *       int32_t, int16_t and int8_t, it just dumps out with a compiler
- *       error.
- *
- *    6) 64 bit integers may or may not be defined.  Test for their
- *       presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
- *       Note that this is different from the C99 specification which
- *       requires the existence of 64 bit support in the compiler.  If
- *       this is not defined for your platform, yet it is capable of
- *       dealing with 64 bits then it is because this file has not yet
- *       been extended to cover all of your system's capabilities.
- *
- *    7) (u)intptr_t may or may not be defined.  Test for its presence
- *       with the test: #ifdef PTRDIFF_MAX.  If this is not defined
- *       for your platform, then it is because this file has not yet
- *       been extended to cover all of your system's capabilities, not
- *       because its optional.
- *
- *    8) The following might not been defined even if your platform is
- *       capable of defining it:
- *
- *       WCHAR_MIN
- *       WCHAR_MAX
- *       (u)int64_t
- *       PTRDIFF_MIN
- *       PTRDIFF_MAX
- *       (u)intptr_t
- *
- *    9) The following have not been defined:
- *
- *       WINT_MIN
- *       WINT_MAX
- *
- *   10) The criteria for defining (u)int_least(*)_t isn't clear,
- *       except for systems which don't have a type that precisely
- *       defined 8, 16, or 32 bit types (which this include file does
- *       not support anyways). Default definitions have been given.
- *
- *   11) The criteria for defining (u)int_fast(*)_t isn't something I
- *       would trust to any particular compiler vendor or the ANSI C
- *       committee.  It is well known that "compatible systems" are
- *       commonly created that have very different performance
- *       characteristics from the systems they are compatible with,
- *       especially those whose vendors make both the compiler and the
- *       system.  Default definitions have been given, but its strongly
- *       recommended that users never use these definitions for any
- *       reason (they do *NOT* deliver any serious guarantee of
- *       improved performance -- not in this file, nor any vendor's
- *       stdint.h).
- *
- *   12) The following macros:
- *
- *       PRINTF_INTMAX_MODIFIER
- *       PRINTF_INT64_MODIFIER
- *       PRINTF_INT32_MODIFIER
- *       PRINTF_INT16_MODIFIER
- *       PRINTF_LEAST64_MODIFIER
- *       PRINTF_LEAST32_MODIFIER
- *       PRINTF_LEAST16_MODIFIER
- *       PRINTF_INTPTR_MODIFIER
- *
- *       are strings which have been defined as the modifiers required
- *       for the "d", "u" and "x" printf formats to correctly output
- *       (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
- *       (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
- *       PRINTF_INTPTR_MODIFIER is not defined for some systems which
- *       provide their own stdint.h.  PRINTF_INT64_MODIFIER is not
- *       defined if INT64_MAX is not defined.  These are an extension
- *       beyond what C99 specifies must be in stdint.h.
- *
- *       In addition, the following macros are defined:
- *
- *       PRINTF_INTMAX_HEX_WIDTH
- *       PRINTF_INT64_HEX_WIDTH
- *       PRINTF_INT32_HEX_WIDTH
- *       PRINTF_INT16_HEX_WIDTH
- *       PRINTF_INT8_HEX_WIDTH
- *       PRINTF_INTMAX_DEC_WIDTH
- *       PRINTF_INT64_DEC_WIDTH
- *       PRINTF_INT32_DEC_WIDTH
- *       PRINTF_INT16_DEC_WIDTH
- *       PRINTF_INT8_DEC_WIDTH
- *
- *       Which specifies the maximum number of characters required to
- *       print the number of that type in either hexadecimal or decimal.
- *       These are an extension beyond what C99 specifies must be in
- *       stdint.h.
- *
- *  Compilers tested (all with 0 warnings at their highest respective
- *  settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
- *  bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
- *  .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
- *
- *  This file should be considered a work in progress.  Suggestions for
- *  improvements, especially those which increase coverage are strongly
- *  encouraged.
- *
- *  Acknowledgements
- *
- *  The following people have made significant contributions to the
- *  development and testing of this file:
- *
- *  Chris Howie
- *  John Steele Scott
- *  Dave Thorup
- *  John Dill
- *
- */
 
-#include <cstddef>
-#include <climits>
-#include <csignal>
-
-/*
- *  For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
- *  do nothing else.  On the Mac OS X version of gcc this is _STDINT_H_.
- */
-
-#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)) ) || (defined(_MSC_VER) && _MSC_VER >= 1600)) && !defined (_PSTDINT_H_INCLUDED)
-#include <stdint.h>
-#define _PSTDINT_H_INCLUDED
-# ifndef PRINTF_INT64_MODIFIER
-#  define PRINTF_INT64_MODIFIER "ll"
-# endif
-# ifndef PRINTF_INT32_MODIFIER
-#  define PRINTF_INT32_MODIFIER "l"
-# endif
-# ifndef PRINTF_INT16_MODIFIER
-#  define PRINTF_INT16_MODIFIER "h"
-# endif
-# ifndef PRINTF_INTMAX_MODIFIER
-#  define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
-# endif
-# ifndef PRINTF_INT64_HEX_WIDTH
-#  define PRINTF_INT64_HEX_WIDTH "16"
-# endif
-# ifndef PRINTF_INT32_HEX_WIDTH
-#  define PRINTF_INT32_HEX_WIDTH "8"
-# endif
-# ifndef PRINTF_INT16_HEX_WIDTH
-#  define PRINTF_INT16_HEX_WIDTH "4"
-# endif
-# ifndef PRINTF_INT8_HEX_WIDTH
-#  define PRINTF_INT8_HEX_WIDTH "2"
-# endif
-# ifndef PRINTF_INT64_DEC_WIDTH
-#  define PRINTF_INT64_DEC_WIDTH "20"
-# endif
-# ifndef PRINTF_INT32_DEC_WIDTH
-#  define PRINTF_INT32_DEC_WIDTH "10"
-# endif
-# ifndef PRINTF_INT16_DEC_WIDTH
-#  define PRINTF_INT16_DEC_WIDTH "5"
-# endif
-# ifndef PRINTF_INT8_DEC_WIDTH
-#  define PRINTF_INT8_DEC_WIDTH "3"
-# endif
-# ifndef PRINTF_INTMAX_HEX_WIDTH
-#  define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
-# endif
-# ifndef PRINTF_INTMAX_DEC_WIDTH
-#  define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
-# endif
-
-/*
- *  Something really weird is going on with Open Watcom.  Just pull some of
- *  these duplicated definitions from Open Watcom's stdint.h file for now.
- */
-
-# if defined (__WATCOMC__) && __WATCOMC__ >= 1250
-#  if !defined (INT64_C)
-#   define INT64_C(x)   (x + (INT64_MAX - INT64_MAX))
-#  endif
-#  if !defined (UINT64_C)
-#   define UINT64_C(x)  (x + (UINT64_MAX - UINT64_MAX))
-#  endif
-#  if !defined (INT32_C)
-#   define INT32_C(x)   (x + (INT32_MAX - INT32_MAX))
-#  endif
-#  if !defined (UINT32_C)
-#   define UINT32_C(x)  (x + (UINT32_MAX - UINT32_MAX))
-#  endif
-#  if !defined (INT16_C)
-#   define INT16_C(x)   (x)
-#  endif
-#  if !defined (UINT16_C)
-#   define UINT16_C(x)  (x)
-#  endif
-#  if !defined (INT8_C)
-#   define INT8_C(x)   (x)
-#  endif
-#  if !defined (UINT8_C)
-#   define UINT8_C(x)  (x)
-#  endif
-#  if !defined (UINT64_MAX)
-#   define UINT64_MAX  18446744073709551615ULL
-#  endif
-#  if !defined (INT64_MAX)
-#   define INT64_MAX  9223372036854775807LL
-#  endif
-#  if !defined (UINT32_MAX)
-#   define UINT32_MAX  4294967295UL
-#  endif
-#  if !defined (INT32_MAX)
-#   define INT32_MAX  2147483647L
-#  endif
-#  if !defined (INTMAX_MAX)
-#   define INTMAX_MAX INT64_MAX
-#  endif
-#  if !defined (INTMAX_MIN)
-#   define INTMAX_MIN INT64_MIN
-#  endif
-# endif
-#endif
-
-#ifndef _PSTDINT_H_INCLUDED
-#define _PSTDINT_H_INCLUDED
-
-#ifndef SIZE_MAX
-# define SIZE_MAX (~(size_t)0)
-#endif
-
-/*
- *  Deduce the type assignments from limits.h under the assumption that
- *  integer sizes in bits are powers of 2, and follow the ANSI
- *  definitions.
- */
-
-#ifndef UINT8_MAX
-# define UINT8_MAX 0xff
-#endif
-#ifndef uint8_t
-# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
-    typedef unsigned char uint8_t;
-#   define UINT8_C(v) ((uint8_t) v)
-# else
-#   error "Platform not supported"
-# endif
-#endif
-
-#ifndef INT8_MAX
-# define INT8_MAX 0x7f
-#endif
-#ifndef INT8_MIN
-# define INT8_MIN INT8_C(0x80)
-#endif
-#ifndef int8_t
-# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
-    typedef signed char int8_t;
-#   define INT8_C(v) ((int8_t) v)
-# else
-#   error "Platform not supported"
-# endif
-#endif
-
-#ifndef UINT16_MAX
-# define UINT16_MAX 0xffff
-#endif
-#ifndef uint16_t
-#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
-  typedef unsigned int uint16_t;
-# ifndef PRINTF_INT16_MODIFIER
-#  define PRINTF_INT16_MODIFIER ""
-# endif
-# define UINT16_C(v) ((uint16_t) (v))
-#elif (USHRT_MAX == UINT16_MAX)
-  typedef unsigned short uint16_t;
-# define UINT16_C(v) ((uint16_t) (v))
-# ifndef PRINTF_INT16_MODIFIER
-#  define PRINTF_INT16_MODIFIER "h"
-# endif
-#else
-#error "Platform not supported"
-#endif
-#endif
-
-#ifndef INT16_MAX
-# define INT16_MAX 0x7fff
-#endif
-#ifndef INT16_MIN
-# define INT16_MIN INT16_C(0x8000)
-#endif
-#ifndef int16_t
-#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
-  typedef signed int int16_t;
-# define INT16_C(v) ((int16_t) (v))
-# ifndef PRINTF_INT16_MODIFIER
-#  define PRINTF_INT16_MODIFIER ""
-# endif
-#elif (SHRT_MAX == INT16_MAX)
-  typedef signed short int16_t;
-# define INT16_C(v) ((int16_t) (v))
-# ifndef PRINTF_INT16_MODIFIER
-#  define PRINTF_INT16_MODIFIER "h"
-# endif
-#else
-#error "Platform not supported"
-#endif
-#endif
-
-#ifndef UINT32_MAX
-# define UINT32_MAX (0xffffffffUL)
-#endif
-#ifndef uint32_t
-#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
-  typedef unsigned long uint32_t;
-# define UINT32_C(v) v ## UL
-# ifndef PRINTF_INT32_MODIFIER
-#  define PRINTF_INT32_MODIFIER "l"
-# endif
-#elif (UINT_MAX == UINT32_MAX)
-  typedef unsigned int uint32_t;
-# ifndef PRINTF_INT32_MODIFIER
-#  define PRINTF_INT32_MODIFIER ""
-# endif
-# define UINT32_C(v) v ## U
-#elif (USHRT_MAX == UINT32_MAX)
-  typedef unsigned short uint32_t;
-# define UINT32_C(v) ((unsigned short) (v))
-# ifndef PRINTF_INT32_MODIFIER
-#  define PRINTF_INT32_MODIFIER ""
-# endif
-#else
-#error "Platform not supported"
-#endif
-#endif
-
-#ifndef INT32_MAX
-# define INT32_MAX (0x7fffffffL)
-#endif
-#ifndef INT32_MIN
-# define INT32_MIN INT32_C(0x80000000)
-#endif
-#ifndef int32_t
-#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
-  typedef signed long int32_t;
-# define INT32_C(v) v ## L
-# ifndef PRINTF_INT32_MODIFIER
-#  define PRINTF_INT32_MODIFIER "l"
-# endif
-#elif (INT_MAX == INT32_MAX)
-  typedef signed int int32_t;
-# define INT32_C(v) v
-# ifndef PRINTF_INT32_MODIFIER
-#  define PRINTF_INT32_MODIFIER ""
-# endif
-#elif (SHRT_MAX == INT32_MAX)
-  typedef signed short int32_t;
-# define INT32_C(v) ((short) (v))
-# ifndef PRINTF_INT32_MODIFIER
-#  define PRINTF_INT32_MODIFIER ""
-# endif
-#else
-#error "Platform not supported"
-#endif
-#endif
-
-/*
- *  The macro stdint_int64_defined is temporarily used to record
- *  whether or not 64 integer support is available.  It must be
- *  defined for any 64 integer extensions for new platforms that are
- *  added.
- */
-
-#undef stdint_int64_defined
-#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
-# if (__STDC__ && __STDC_VERSION__ >= 199901L) || defined (S_SPLINT_S)
-#  define stdint_int64_defined
-   typedef long long int64_t;
-   typedef unsigned long long uint64_t;
-#  define UINT64_C(v) v ## ULL
-#  define  INT64_C(v) v ## LL
-#  ifndef PRINTF_INT64_MODIFIER
-#   define PRINTF_INT64_MODIFIER "ll"
-#  endif
-# endif
-#endif
-
-#if !defined (stdint_int64_defined)
-# if defined(__GNUC__)
-#  define stdint_int64_defined
-   __extension__ typedef long long int64_t;
-   __extension__ typedef unsigned long long uint64_t;
-#  define UINT64_C(v) v ## ULL
-#  define  INT64_C(v) v ## LL
-#  ifndef PRINTF_INT64_MODIFIER
-#   define PRINTF_INT64_MODIFIER "ll"
-#  endif
-# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
-#  define stdint_int64_defined
-   typedef long long int64_t;
-   typedef unsigned long long uint64_t;
-#  define UINT64_C(v) v ## ULL
-#  define  INT64_C(v) v ## LL
-#  ifndef PRINTF_INT64_MODIFIER
-#   define PRINTF_INT64_MODIFIER "ll"
-#  endif
-# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
-#  define stdint_int64_defined
-   typedef __int64 int64_t;
-   typedef unsigned __int64 uint64_t;
-#  define UINT64_C(v) v ## UI64
-#  define  INT64_C(v) v ## I64
-#  ifndef PRINTF_INT64_MODIFIER
-#   define PRINTF_INT64_MODIFIER "I64"
-#  endif
-# endif
-#endif
-
-#if !defined (LONG_LONG_MAX) && defined (INT64_C)
-# define LONG_LONG_MAX INT64_C (9223372036854775807)
-#endif
-#ifndef ULONG_LONG_MAX
-# define ULONG_LONG_MAX UINT64_C (18446744073709551615)
-#endif
-
-#if !defined (INT64_MAX) && defined (INT64_C)
-# define INT64_MAX INT64_C (9223372036854775807)
-#endif
-#if !defined (INT64_MIN) && defined (INT64_C)
-# define INT64_MIN INT64_C (-9223372036854775808)
-#endif
-#if !defined (UINT64_MAX) && defined (INT64_C)
-# define UINT64_MAX UINT64_C (18446744073709551615)
-#endif
-
-/*
- *  Width of hexadecimal for number field.
- */
-
-#ifndef PRINTF_INT64_HEX_WIDTH
-# define PRINTF_INT64_HEX_WIDTH "16"
-#endif
-#ifndef PRINTF_INT32_HEX_WIDTH
-# define PRINTF_INT32_HEX_WIDTH "8"
-#endif
-#ifndef PRINTF_INT16_HEX_WIDTH
-# define PRINTF_INT16_HEX_WIDTH "4"
-#endif
-#ifndef PRINTF_INT8_HEX_WIDTH
-# define PRINTF_INT8_HEX_WIDTH "2"
-#endif
-
-#ifndef PRINTF_INT64_DEC_WIDTH
-# define PRINTF_INT64_DEC_WIDTH "20"
-#endif
-#ifndef PRINTF_INT32_DEC_WIDTH
-# define PRINTF_INT32_DEC_WIDTH "10"
-#endif
-#ifndef PRINTF_INT16_DEC_WIDTH
-# define PRINTF_INT16_DEC_WIDTH "5"
-#endif
-#ifndef PRINTF_INT8_DEC_WIDTH
-# define PRINTF_INT8_DEC_WIDTH "3"
-#endif
-
-/*
- *  Ok, lets not worry about 128 bit integers for now.  Moore's law says
- *  we don't need to worry about that until about 2040 at which point
- *  we'll have bigger things to worry about.
- */
-
-#ifdef stdint_int64_defined
-  typedef int64_t intmax_t;
-  typedef uint64_t uintmax_t;
-# define  INTMAX_MAX   INT64_MAX
-# define  INTMAX_MIN   INT64_MIN
-# define UINTMAX_MAX  UINT64_MAX
-# define UINTMAX_C(v) UINT64_C(v)
-# define  INTMAX_C(v)  INT64_C(v)
-# ifndef PRINTF_INTMAX_MODIFIER
-#   define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
-# endif
-# ifndef PRINTF_INTMAX_HEX_WIDTH
-#  define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
-# endif
-# ifndef PRINTF_INTMAX_DEC_WIDTH
-#  define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
-# endif
-#else
-  typedef int32_t intmax_t;
-  typedef uint32_t uintmax_t;
-# define  INTMAX_MAX   INT32_MAX
-# define UINTMAX_MAX  UINT32_MAX
-# define UINTMAX_C(v) UINT32_C(v)
-# define  INTMAX_C(v)  INT32_C(v)
-# ifndef PRINTF_INTMAX_MODIFIER
-#   define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
-# endif
-# ifndef PRINTF_INTMAX_HEX_WIDTH
-#  define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
-# endif
-# ifndef PRINTF_INTMAX_DEC_WIDTH
-#  define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
-# endif
-#endif
-
-/*
- *  Because this file currently only supports platforms which have
- *  precise powers of 2 as bit sizes for the default integers, the
- *  least definitions are all trivial.  Its possible that a future
- *  version of this file could have different definitions.
- */
-
-#ifndef stdint_least_defined
-  typedef   int8_t   int_least8_t;
-  typedef  uint8_t  uint_least8_t;
-  typedef  int16_t  int_least16_t;
-  typedef uint16_t uint_least16_t;
-  typedef  int32_t  int_least32_t;
-  typedef uint32_t uint_least32_t;
-# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
-# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
-# define  UINT_LEAST8_MAX  UINT8_MAX
-# define   INT_LEAST8_MAX   INT8_MAX
-# define UINT_LEAST16_MAX UINT16_MAX
-# define  INT_LEAST16_MAX  INT16_MAX
-# define UINT_LEAST32_MAX UINT32_MAX
-# define  INT_LEAST32_MAX  INT32_MAX
-# define   INT_LEAST8_MIN   INT8_MIN
-# define  INT_LEAST16_MIN  INT16_MIN
-# define  INT_LEAST32_MIN  INT32_MIN
-# ifdef stdint_int64_defined
-    typedef  int64_t  int_least64_t;
-    typedef uint64_t uint_least64_t;
-#   define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
-#   define UINT_LEAST64_MAX UINT64_MAX
-#   define  INT_LEAST64_MAX  INT64_MAX
-#   define  INT_LEAST64_MIN  INT64_MIN
-# endif
-#endif
-#undef stdint_least_defined
-
-/*
- *  The ANSI C committee pretending to know or specify anything about
- *  performance is the epitome of misguided arrogance.  The mandate of
- *  this file is to *ONLY* ever support that absolute minimum
- *  definition of the fast integer types, for compatibility purposes.
- *  No extensions, and no attempt to suggest what may or may not be a
- *  faster integer type will ever be made in this file.  Developers are
- *  warned to stay away from these types when using this or any other
- *  stdint.h.
- */
-
-typedef   int_least8_t   int_fast8_t;
-typedef  uint_least8_t  uint_fast8_t;
-typedef  int_least16_t  int_fast16_t;
-typedef uint_least16_t uint_fast16_t;
-typedef  int_least32_t  int_fast32_t;
-typedef uint_least32_t uint_fast32_t;
-#define  UINT_FAST8_MAX  UINT_LEAST8_MAX
-#define   INT_FAST8_MAX   INT_LEAST8_MAX
-#define UINT_FAST16_MAX UINT_LEAST16_MAX
-#define  INT_FAST16_MAX  INT_LEAST16_MAX
-#define UINT_FAST32_MAX UINT_LEAST32_MAX
-#define  INT_FAST32_MAX  INT_LEAST32_MAX
-#define   INT_FAST8_MIN   INT_LEAST8_MIN
-#define  INT_FAST16_MIN  INT_LEAST16_MIN
-#define  INT_FAST32_MIN  INT_LEAST32_MIN
-#ifdef stdint_int64_defined
-  typedef  int_least64_t  int_fast64_t;
-  typedef uint_least64_t uint_fast64_t;
-# define UINT_FAST64_MAX UINT_LEAST64_MAX
-# define  INT_FAST64_MAX  INT_LEAST64_MAX
-# define  INT_FAST64_MIN  INT_LEAST64_MIN
-#endif
-
-#undef stdint_int64_defined
-
-/*
- *  Whatever piecemeal, per compiler thing we can do about the wchar_t
- *  type limits.
- */
-
-#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
-# include <wchar.h>
-# ifndef WCHAR_MIN
-#  define WCHAR_MIN 0
-# endif
-# ifndef WCHAR_MAX
-#  define WCHAR_MAX ((wchar_t)-1)
-# endif
-#endif
-
-/*
- *  Whatever piecemeal, per compiler/platform thing we can do about the
- *  (u)intptr_t types and limits.
- */
-
-#if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)
-# define STDINT_H_UINTPTR_T_DEFINED
-#endif
-
-#ifndef STDINT_H_UINTPTR_T_DEFINED
-# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)
-#  define stdint_intptr_bits 64
-# elif defined (__WATCOMC__) || defined (__TURBOC__)
-#  if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
-#    define stdint_intptr_bits 16
-#  else
-#    define stdint_intptr_bits 32
-#  endif
-# elif defined (__i386__) || defined (_WIN32) || defined (WIN32)
-#  define stdint_intptr_bits 32
-# elif defined (__INTEL_COMPILER)
-/* TODO -- what did Intel do about x86-64? */
-# endif
-
-# ifdef stdint_intptr_bits
-#  define stdint_intptr_glue3_i(a,b,c)  a##b##c
-#  define stdint_intptr_glue3(a,b,c)    stdint_intptr_glue3_i(a,b,c)
-#  ifndef PRINTF_INTPTR_MODIFIER
-#    define PRINTF_INTPTR_MODIFIER      stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
-#  endif
-#  ifndef PTRDIFF_MAX
-#    define PTRDIFF_MAX                 stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
-#  endif
-#  ifndef PTRDIFF_MIN
-#    define PTRDIFF_MIN                 stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
-#  endif
-#  ifndef UINTPTR_MAX
-#    define UINTPTR_MAX                 stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
-#  endif
-#  ifndef INTPTR_MAX
-#    define INTPTR_MAX                  stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
-#  endif
-#  ifndef INTPTR_MIN
-#    define INTPTR_MIN                  stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
-#  endif
-#  ifndef INTPTR_C
-#    define INTPTR_C(x)                 stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
-#  endif
-#  ifndef UINTPTR_C
-#    define UINTPTR_C(x)                stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
-#  endif
-  typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
-  typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t)  intptr_t;
-# else
-/* TODO -- This following is likely wrong for some platforms, and does
-   nothing for the definition of uintptr_t. */
-  typedef ptrdiff_t intptr_t;
-# endif
-# define STDINT_H_UINTPTR_T_DEFINED
-#endif
-
-/*
- *  Assumes sig_atomic_t is signed and we have a 2s complement machine.
- */
-
-#ifndef SIG_ATOMIC_MAX
-# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
-#endif
-
-#endif
-
-#if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
-
-/*
- *  Please compile with the maximum warning settings to make sure macros are not
- *  defined more than once.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#define glue3_aux(x,y,z) x ## y ## z
-#define glue3(x,y,z) glue3_aux(x,y,z)
-
-#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0);
-#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0);
-
-#define DECL(us,bits) glue3(DECL,us,) (bits)
-
-#define TESTUMAX(bits) glue3(u,bits,=) glue3(~,u,bits); if (glue3(UINT,bits,_MAX) glue3(!=,u,bits)) printf ("Something wrong with UINT%d_MAX\n", bits)
-
-int main () {
-	DECL(I,8)
-	DECL(U,8)
-	DECL(I,16)
-	DECL(U,16)
-	DECL(I,32)
-	DECL(U,32)
-#ifdef INT64_MAX
-	DECL(I,64)
-	DECL(U,64)
-#endif
-	intmax_t imax = INTMAX_C(0);
-	uintmax_t umax = UINTMAX_C(0);
-	char str0[256], str1[256];
-
-	sprintf (str0, "%d %x\n", 0, ~0);
-
-	sprintf (str1, "%d %x\n",  i8, ~0);
-	if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);
-	sprintf (str1, "%u %x\n",  u8, ~0);
-	if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);
-	sprintf (str1, "%d %x\n",  i16, ~0);
-	if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);
-	sprintf (str1, "%u %x\n",  u16, ~0);
-	if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1);
-	sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n",  i32, ~0);
-	if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);
-	sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n",  u32, ~0);
-	if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);
-#ifdef INT64_MAX
-	sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n",  i64, ~0);
-	if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);
-#endif
-	sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n",  imax, ~0);
-	if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);
-	sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n",  umax, ~0);
-	if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1);
-
-	TESTUMAX(8);
-	TESTUMAX(16);
-	TESTUMAX(32);
-#ifdef INT64_MAX
-	TESTUMAX(64);
-#endif
-
-	return EXIT_SUCCESS;
-}
-
-#endif
-