#include "Relooper.h"
#include <string.h>
#include <stdlib.h>
#include <list>
#include <stack>
#if EMSCRIPTEN
#include "ministring.h"
#else
#include <string>
typedef std::string ministring;
#endif
template <class T, class U> bool contains(const T& container, const U& contained) {
return container.find(contained) != container.end();
}
#if DEBUG
static void PrintDebug(const char *Format, ...);
#define DebugDump(x, ...) Debugging::Dump(x, __VA_ARGS__)
#else
#define PrintDebug(x, ...)
#define DebugDump(x, ...)
#endif
#define INDENTATION 1
struct Indenter {
static int CurrIndent;
static void Indent() { CurrIndent++; }
static void Unindent() { CurrIndent--; }
};
static void PrintIndented(const char *Format, ...);
static void PutIndented(const char *String);
static char *OutputBufferRoot = NULL;
static char *OutputBuffer = NULL;
static int OutputBufferSize = 0;
void PrintIndented(const char *Format, ...) {
assert(OutputBuffer);
assert(OutputBuffer + Indenter::CurrIndent*INDENTATION - OutputBufferRoot < OutputBufferSize);
for (int i = 0; i < Indenter::CurrIndent*INDENTATION; i++, OutputBuffer++) *OutputBuffer = ' ';
va_list Args;
va_start(Args, Format);
int left = OutputBufferSize - (OutputBuffer - OutputBufferRoot);
int written = vsnprintf(OutputBuffer, left, Format, Args);
assert(written < left);
OutputBuffer += written;
va_end(Args);
}
void PutIndented(const char *String) {
assert(OutputBuffer);
assert(OutputBuffer + Indenter::CurrIndent*INDENTATION - OutputBufferRoot < OutputBufferSize);
for (int i = 0; i < Indenter::CurrIndent*INDENTATION; i++, OutputBuffer++) *OutputBuffer = ' ';
int left =