/* chess-pgn.c generated by valac 0.34.2.2-0a595, the Vala compiler
 * generated from chess-pgn.vala, do not modify */

/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * Copyright (C) 2010-2014 Robert Ancell
 * Copyright (C) 2015-2016 Sahil Sareen
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
 * license.
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
#include <stdio.h>


#define TYPE_PGN_GAME (pgn_game_get_type ())
#define PGN_GAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PGN_GAME, PGNGame))
#define PGN_GAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PGN_GAME, PGNGameClass))
#define IS_PGN_GAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PGN_GAME))
#define IS_PGN_GAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PGN_GAME))
#define PGN_GAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PGN_GAME, PGNGameClass))

typedef struct _PGNGame PGNGame;
typedef struct _PGNGameClass PGNGameClass;
typedef struct _PGNGamePrivate PGNGamePrivate;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define __g_list_free__g_free0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__g_free0_ (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_list_free0(var) ((var == NULL) ? NULL : (var = (g_list_free (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))

#define TYPE_STATE (state_get_type ())

#define TYPE_PGN (pgn_get_type ())
#define PGN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PGN, PGN))
#define PGN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PGN, PGNClass))
#define IS_PGN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PGN))
#define IS_PGN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PGN))
#define PGN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PGN, PGNClass))

typedef struct _PGN PGN;
typedef struct _PGNClass PGNClass;
typedef struct _PGNPrivate PGNPrivate;
#define __g_list_free__g_object_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__g_object_unref0_ (var), NULL)))

#define TYPE_CLOCK_TYPE (clock_type_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

typedef enum  {
	PGN_ERROR_LOAD_ERROR
} PGNError;
#define PGN_ERROR pgn_error_quark ()
struct _PGNGame {
	GObject parent_instance;
	PGNGamePrivate * priv;
	GHashTable* tags;
	GList* moves;
};

struct _PGNGameClass {
	GObjectClass parent_class;
};

typedef enum  {
	STATE_TAGS,
	STATE_MOVE_TEXT,
	STATE_LINE_COMMENT,
	STATE_BRACE_COMMENT,
	STATE_TAG_START,
	STATE_TAG_NAME,
	STATE_PRE_TAG_VALUE,
	STATE_TAG_VALUE,
	STATE_POST_TAG_VALUE,
	STATE_SYMBOL,
	STATE_PERIOD,
	STATE_NAG,
	STATE_ERROR
} State;

struct _PGN {
	GObject parent_instance;
	PGNPrivate * priv;
	GList* games;
};

struct _PGNClass {
	GObjectClass parent_class;
};

typedef enum  {
	CLOCK_TYPE_SIMPLE,
	CLOCK_TYPE_FISCHER,
	CLOCK_TYPE_BRONSTEIN,
	CLOCK_TYPE_INVALID
} ClockType;


static gpointer pgn_game_parent_class = NULL;
extern gchar* pgn_game_RESULT_IN_PROGRESS;
gchar* pgn_game_RESULT_IN_PROGRESS = NULL;
extern gchar* pgn_game_RESULT_DRAW;
gchar* pgn_game_RESULT_DRAW = NULL;
extern gchar* pgn_game_RESULT_WHITE;
gchar* pgn_game_RESULT_WHITE = NULL;
extern gchar* pgn_game_RESULT_BLACK;
gchar* pgn_game_RESULT_BLACK = NULL;
extern gchar* pgn_game_TERMINATE_ABANDONED;
gchar* pgn_game_TERMINATE_ABANDONED = NULL;
extern gchar* pgn_game_TERMINATE_ADJUDICATION;
gchar* pgn_game_TERMINATE_ADJUDICATION = NULL;
extern gchar* pgn_game_TERMINATE_DEATH;
gchar* pgn_game_TERMINATE_DEATH = NULL;
extern gchar* pgn_game_TERMINATE_EMERGENCY;
gchar* pgn_game_TERMINATE_EMERGENCY = NULL;
extern gchar* pgn_game_TERMINATE_NORMAL;
gchar* pgn_game_TERMINATE_NORMAL = NULL;
extern gchar* pgn_game_TERMINATE_RULES_INFRACTION;
gchar* pgn_game_TERMINATE_RULES_INFRACTION = NULL;
extern gchar* pgn_game_TERMINATE_TIME_FORFEIT;
gchar* pgn_game_TERMINATE_TIME_FORFEIT = NULL;
extern gchar* pgn_game_TERMINATE_UNTERMINATED;
gchar* pgn_game_TERMINATE_UNTERMINATED = NULL;
static gpointer pgn_parent_class = NULL;

gint str_index (const gchar* name);
gint compare_tag (const gchar* name0, const gchar* name1);
GQuark pgn_error_quark (void);
GType pgn_game_get_type (void) G_GNUC_CONST;
enum  {
	PGN_GAME_DUMMY_PROPERTY,
	PGN_GAME_EVENT,
	PGN_GAME_SITE,
	PGN_GAME_DATE,
	PGN_GAME_TIME,
	PGN_GAME_ROUND,
	PGN_GAME_WHITE,
	PGN_GAME_BLACK,
	PGN_GAME_RESULT,
	PGN_GAME_ANNOTATOR,
	PGN_GAME_TIME_CONTROL,
	PGN_GAME_WHITE_TIME_LEFT,
	PGN_GAME_BLACK_TIME_LEFT,
	PGN_GAME_CLOCK_TYPE,
	PGN_GAME_TIMER_INCREMENT,
	PGN_GAME_SET_UP,
	PGN_GAME_FEN,
	PGN_GAME_TERMINATION,
	PGN_GAME_WHITE_AI,
	PGN_GAME_WHITE_LEVEL,
	PGN_GAME_BLACK_AI,
	PGN_GAME_BLACK_LEVEL
};
static void _g_free0_ (gpointer var);
static void _g_list_free__g_free0_ (GList* self);
PGNGame* pgn_game_new (void);
PGNGame* pgn_game_construct (GType object_type);
gchar* pgn_game_escape (PGNGame* self, const gchar* value);
void pgn_game_write (PGNGame* self, GFile* file, GError** error);
const gchar* pgn_game_get_result (PGNGame* self);
const gchar* pgn_game_get_event (PGNGame* self);
void pgn_game_set_event (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_site (PGNGame* self);
void pgn_game_set_site (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_date (PGNGame* self);
void pgn_game_set_date (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_time (PGNGame* self);
void pgn_game_set_time (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_round (PGNGame* self);
void pgn_game_set_round (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_white (PGNGame* self);
void pgn_game_set_white (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_black (PGNGame* self);
void pgn_game_set_black (PGNGame* self, const gchar* value);
void pgn_game_set_result (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_annotator (PGNGame* self);
void pgn_game_set_annotator (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_time_control (PGNGame* self);
void pgn_game_set_time_control (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_white_time_left (PGNGame* self);
void pgn_game_set_white_time_left (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_black_time_left (PGNGame* self);
void pgn_game_set_black_time_left (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_clock_type (PGNGame* self);
void pgn_game_set_clock_type (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_timer_increment (PGNGame* self);
void pgn_game_set_timer_increment (PGNGame* self, const gchar* value);
gboolean pgn_game_get_set_up (PGNGame* self);
void pgn_game_set_set_up (PGNGame* self, gboolean value);
const gchar* pgn_game_get_fen (PGNGame* self);
void pgn_game_set_fen (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_termination (PGNGame* self);
void pgn_game_set_termination (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_white_ai (PGNGame* self);
void pgn_game_set_white_ai (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_white_level (PGNGame* self);
void pgn_game_set_white_level (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_black_ai (PGNGame* self);
void pgn_game_set_black_ai (PGNGame* self, const gchar* value);
const gchar* pgn_game_get_black_level (PGNGame* self);
void pgn_game_set_black_level (PGNGame* self, const gchar* value);
static void pgn_game_finalize (GObject* obj);
static void _vala_pgn_game_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_pgn_game_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
GType state_get_type (void) G_GNUC_CONST;
GType pgn_get_type (void) G_GNUC_CONST;
enum  {
	PGN_DUMMY_PROPERTY
};
static void _g_object_unref0_ (gpointer var);
static void _g_list_free__g_object_unref0_ (GList* self);
static void pgn_insert_tag (PGN* self, PGNGame* game, const gchar* tag_name, const gchar* tag_value);
GType clock_type_get_type (void) G_GNUC_CONST;
ClockType clock_type_string_to_enum (const gchar* s);
PGN* pgn_new_from_string (const gchar* data, GError** error);
PGN* pgn_construct_from_string (GType object_type, const gchar* data, GError** error);
PGN* pgn_new_from_file (GFile* file, GError** error);
PGN* pgn_construct_from_file (GType object_type, GFile* file, GError** error);
PGN* pgn_new (void);
PGN* pgn_construct (GType object_type);
static void pgn_finalize (GObject* obj);


gint str_index (const gchar* name) {
	gint result = 0;
	const gchar* _tmp0_ = NULL;
	g_return_val_if_fail (name != NULL, 0);
	_tmp0_ = name;
	if (g_strcmp0 (_tmp0_, "Event") == 0) {
		result = 0;
		return result;
	} else {
		const gchar* _tmp1_ = NULL;
		_tmp1_ = name;
		if (g_strcmp0 (_tmp1_, "Site") == 0) {
			result = 1;
			return result;
		} else {
			const gchar* _tmp2_ = NULL;
			_tmp2_ = name;
			if (g_strcmp0 (_tmp2_, "Date") == 0) {
				result = 2;
				return result;
			} else {
				const gchar* _tmp3_ = NULL;
				_tmp3_ = name;
				if (g_strcmp0 (_tmp3_, "Round") == 0) {
					result = 3;
					return result;
				} else {
					const gchar* _tmp4_ = NULL;
					_tmp4_ = name;
					if (g_strcmp0 (_tmp4_, "White") == 0) {
						result = 4;
						return result;
					} else {
						const gchar* _tmp5_ = NULL;
						_tmp5_ = name;
						if (g_strcmp0 (_tmp5_, "Black") == 0) {
							result = 5;
							return result;
						} else {
							const gchar* _tmp6_ = NULL;
							_tmp6_ = name;
							if (g_strcmp0 (_tmp6_, "Result") == 0) {
								result = 6;
								return result;
							} else {
								result = 7;
								return result;
							}
						}
					}
				}
			}
		}
	}
}


gint compare_tag (const gchar* name0, const gchar* name1) {
	gint result = 0;
	gint str_index0 = 0;
	const gchar* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	gint str_index1 = 0;
	const gchar* _tmp2_ = NULL;
	gint _tmp3_ = 0;
	gboolean _tmp4_ = FALSE;
	gint _tmp5_ = 0;
	g_return_val_if_fail (name0 != NULL, 0);
	g_return_val_if_fail (name1 != NULL, 0);
	_tmp0_ = name0;
	_tmp1_ = str_index (_tmp0_);
	str_index0 = _tmp1_;
	_tmp2_ = name1;
	_tmp3_ = str_index (_tmp2_);
	str_index1 = _tmp3_;
	_tmp5_ = str_index0;
	if (_tmp5_ == 7) {
		gint _tmp6_ = 0;
		_tmp6_ = str_index1;
		_tmp4_ = _tmp6_ == 7;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		GCompareFunc _tmp7_ = NULL;
		const gchar* _tmp8_ = NULL;
		const gchar* _tmp9_ = NULL;
		gint _tmp10_ = 0;
		_tmp7_ = g_strcmp0;
		_tmp8_ = name0;
		_tmp9_ = name1;
		_tmp10_ = _tmp7_ (_tmp8_, _tmp9_);
		result = _tmp10_;
		return result;
	} else {
		gint _tmp11_ = 0;
		gint _tmp12_ = 0;
		_tmp11_ = str_index0;
		_tmp12_ = str_index1;
		result = _tmp11_ - _tmp12_;
		return result;
	}
}


GQuark pgn_error_quark (void) {
	return g_quark_from_static_string ("pgn_error-quark");
}


static void _g_free0_ (gpointer var) {
	var = (g_free (var), NULL);
}


static void _g_list_free__g_free0_ (GList* self) {
	g_list_foreach (self, (GFunc) _g_free0_, NULL);
	g_list_free (self);
}


PGNGame* pgn_game_construct (GType object_type) {
	PGNGame * self = NULL;
	GHashFunc _tmp0_ = NULL;
	GEqualFunc _tmp1_ = NULL;
	GHashTable* _tmp2_ = NULL;
	GHashTable* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	GHashTable* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_ = NULL;
	GHashTable* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	GHashTable* _tmp12_ = NULL;
	gchar* _tmp13_ = NULL;
	gchar* _tmp14_ = NULL;
	GHashTable* _tmp15_ = NULL;
	gchar* _tmp16_ = NULL;
	gchar* _tmp17_ = NULL;
	GHashTable* _tmp18_ = NULL;
	gchar* _tmp19_ = NULL;
	gchar* _tmp20_ = NULL;
	GHashTable* _tmp21_ = NULL;
	gchar* _tmp22_ = NULL;
	const gchar* _tmp23_ = NULL;
	gchar* _tmp24_ = NULL;
	self = (PGNGame*) g_object_new (object_type, NULL);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _g_free0_);
	_g_hash_table_unref0 (self->tags);
	self->tags = _tmp2_;
	_tmp3_ = self->tags;
	_tmp4_ = g_strdup ("Event");
	_tmp5_ = g_strdup ("?");
	g_hash_table_insert (_tmp3_, _tmp4_, _tmp5_);
	_tmp6_ = self->tags;
	_tmp7_ = g_strdup ("Site");
	_tmp8_ = g_strdup ("?");
	g_hash_table_insert (_tmp6_, _tmp7_, _tmp8_);
	_tmp9_ = self->tags;
	_tmp10_ = g_strdup ("Date");
	_tmp11_ = g_strdup ("????.??.??");
	g_hash_table_insert (_tmp9_, _tmp10_, _tmp11_);
	_tmp12_ = self->tags;
	_tmp13_ = g_strdup ("Round");
	_tmp14_ = g_strdup ("?");
	g_hash_table_insert (_tmp12_, _tmp13_, _tmp14_);
	_tmp15_ = self->tags;
	_tmp16_ = g_strdup ("White");
	_tmp17_ = g_strdup ("?");
	g_hash_table_insert (_tmp15_, _tmp16_, _tmp17_);
	_tmp18_ = self->tags;
	_tmp19_ = g_strdup ("Black");
	_tmp20_ = g_strdup ("?");
	g_hash_table_insert (_tmp18_, _tmp19_, _tmp20_);
	_tmp21_ = self->tags;
	_tmp22_ = g_strdup ("Result");
	_tmp23_ = pgn_game_RESULT_IN_PROGRESS;
	_tmp24_ = g_strdup (_tmp23_);
	g_hash_table_insert (_tmp21_, _tmp22_, _tmp24_);
	return self;
}


PGNGame* pgn_game_new (void) {
	return pgn_game_construct (TYPE_PGN_GAME);
}


static gchar* string_replace (const gchar* self, const gchar* old, const gchar* replacement) {
	gchar* result = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	{
		GRegex* regex = NULL;
		const gchar* _tmp0_ = NULL;
		gchar* _tmp1_ = NULL;
		gchar* _tmp2_ = NULL;
		GRegex* _tmp3_ = NULL;
		GRegex* _tmp4_ = NULL;
		gchar* _tmp5_ = NULL;
		GRegex* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		gchar* _tmp8_ = NULL;
		gchar* _tmp9_ = NULL;
		_tmp0_ = old;
		_tmp1_ = g_regex_escape_string (_tmp0_, -1);
		_tmp2_ = _tmp1_;
		_tmp3_ = g_regex_new (_tmp2_, 0, 0, &_inner_error_);
		_tmp4_ = _tmp3_;
		_g_free0 (_tmp2_);
		regex = _tmp4_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
		_tmp6_ = regex;
		_tmp7_ = replacement;
		_tmp8_ = g_regex_replace_literal (_tmp6_, self, (gssize) -1, 0, _tmp7_, 0, &_inner_error_);
		_tmp5_ = _tmp8_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_regex_unref0 (regex);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
		_tmp9_ = _tmp5_;
		_tmp5_ = NULL;
		result = _tmp9_;
		_g_free0 (_tmp5_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_assert_not_reached ();
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
}


gchar* pgn_game_escape (PGNGame* self, const gchar* value) {
	gchar* result = NULL;
	gchar* a = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (value != NULL, NULL);
	_tmp0_ = value;
	_tmp1_ = string_replace (_tmp0_, "\\", "\\\\");
	a = _tmp1_;
	_tmp2_ = string_replace (a, "\"", "\\\"");
	result = _tmp2_;
	_g_free0 (a);
	return result;
}


static guint8* string_get_data (const gchar* self, int* result_length1) {
	guint8* result;
	guint8* res = NULL;
	gint res_length1 = 0;
	gint _res_size_ = 0;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	guint8* _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	guint8* _tmp4_ = NULL;
	gint _tmp4__length1 = 0;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res_length1;
	_tmp3_ = res;
	_tmp3__length1 = res_length1;
	_tmp4_ = _tmp3_;
	_tmp4__length1 = _tmp3__length1;
	if (result_length1) {
		*result_length1 = _tmp4__length1;
	}
	result = _tmp4_;
	return result;
}


void pgn_game_write (PGNGame* self, GFile* file, GError** error) {
	GString* data = NULL;
	GString* _tmp0_ = NULL;
	GList* keys = NULL;
	GHashTable* _tmp1_ = NULL;
	GList* _tmp2_ = NULL;
	GList* _tmp3_ = NULL;
	GString* _tmp13_ = NULL;
	gint i = 0;
	GList* _tmp14_ = NULL;
	GString* _tmp25_ = NULL;
	const gchar* _tmp26_ = NULL;
	const gchar* _tmp27_ = NULL;
	GString* _tmp28_ = NULL;
	GFile* _tmp29_ = NULL;
	GString* _tmp30_ = NULL;
	const gchar* _tmp31_ = NULL;
	guint8* _tmp32_ = NULL;
	gint _tmp32__length1 = 0;
	guint8* _tmp33_ = NULL;
	gint _tmp33__length1 = 0;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (file != NULL);
	_tmp0_ = g_string_new ("");
	data = _tmp0_;
	_tmp1_ = self->tags;
	_tmp2_ = g_hash_table_get_keys (_tmp1_);
	keys = _tmp2_;
	keys = g_list_sort (keys, (GCompareFunc) compare_tag);
	_tmp3_ = keys;
	{
		GList* key_collection = NULL;
		GList* key_it = NULL;
		key_collection = _tmp3_;
		for (key_it = key_collection; key_it != NULL; key_it = key_it->next) {
			const gchar* key = NULL;
			key = (const gchar*) key_it->data;
			{
				GString* _tmp4_ = NULL;
				const gchar* _tmp5_ = NULL;
				GHashTable* _tmp6_ = NULL;
				const gchar* _tmp7_ = NULL;
				gconstpointer _tmp8_ = NULL;
				gchar* _tmp9_ = NULL;
				gchar* _tmp10_ = NULL;
				gchar* _tmp11_ = NULL;
				gchar* _tmp12_ = NULL;
				_tmp4_ = data;
				_tmp5_ = key;
				_tmp6_ = self->tags;
				_tmp7_ = key;
				_tmp8_ = g_hash_table_lookup (_tmp6_, _tmp7_);
				_tmp9_ = pgn_game_escape (self, (const gchar*) _tmp8_);
				_tmp10_ = _tmp9_;
				_tmp11_ = g_strdup_printf ("[%s \"%s\"]\n", _tmp5_, _tmp10_);
				_tmp12_ = _tmp11_;
				g_string_append (_tmp4_, _tmp12_);
				_g_free0 (_tmp12_);
				_g_free0 (_tmp10_);
			}
		}
	}
	_tmp13_ = data;
	g_string_append (_tmp13_, "\n");
	i = 0;
	_tmp14_ = self->moves;
	{
		GList* move_collection = NULL;
		GList* move_it = NULL;
		move_collection = _tmp14_;
		for (move_it = move_collection; move_it != NULL; move_it = move_it->next) {
			gchar* _tmp15_ = NULL;
			gchar* move = NULL;
			_tmp15_ = g_strdup ((const gchar*) move_it->data);
			move = _tmp15_;
			{
				gint _tmp16_ = 0;
				GString* _tmp21_ = NULL;
				const gchar* _tmp22_ = NULL;
				GString* _tmp23_ = NULL;
				gint _tmp24_ = 0;
				_tmp16_ = i;
				if ((_tmp16_ % 2) == 0) {
					GString* _tmp17_ = NULL;
					gint _tmp18_ = 0;
					gchar* _tmp19_ = NULL;
					gchar* _tmp20_ = NULL;
					_tmp17_ = data;
					_tmp18_ = i;
					_tmp19_ = g_strdup_printf ("%d. ", (_tmp18_ / 2) + 1);
					_tmp20_ = _tmp19_;
					g_string_append (_tmp17_, _tmp20_);
					_g_free0 (_tmp20_);
				}
				_tmp21_ = data;
				_tmp22_ = move;
				g_string_append (_tmp21_, _tmp22_);
				_tmp23_ = data;
				g_string_append (_tmp23_, " ");
				_tmp24_ = i;
				i = _tmp24_ + 1;
				_g_free0 (move);
			}
		}
	}
	_tmp25_ = data;
	_tmp26_ = pgn_game_get_result (self);
	_tmp27_ = _tmp26_;
	g_string_append (_tmp25_, _tmp27_);
	_tmp28_ = data;
	g_string_append (_tmp28_, "\n");
	_tmp29_ = file;
	_tmp30_ = data;
	_tmp31_ = _tmp30_->str;
	_tmp32_ = string_get_data (_tmp31_, &_tmp32__length1);
	_tmp33_ = _tmp32_;
	_tmp33__length1 = _tmp32__length1;
	g_file_replace_contents (_tmp29_, _tmp33_, (gsize) _tmp33__length1, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_list_free0 (keys);
		_g_string_free0 (data);
		return;
	}
	_g_list_free0 (keys);
	_g_string_free0 (data);
}


const gchar* pgn_game_get_event (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Event");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_event (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Event");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "event");
}


const gchar* pgn_game_get_site (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Site");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_site (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Site");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "site");
}


const gchar* pgn_game_get_date (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Date");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_date (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Date");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "date");
}


const gchar* pgn_game_get_time (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Time");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_time (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Time");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "time");
}


const gchar* pgn_game_get_round (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Round");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_round (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Round");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "round");
}


const gchar* pgn_game_get_white (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "White");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_white (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("White");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "white");
}


const gchar* pgn_game_get_black (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Black");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_black (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Black");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "black");
}


const gchar* pgn_game_get_result (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Result");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_result (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Result");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "result");
}


const gchar* pgn_game_get_annotator (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Annotator");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_annotator (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Annotator");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "annotator");
}


const gchar* pgn_game_get_time_control (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "TimeControl");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_time_control (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("TimeControl");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "time-control");
}


const gchar* pgn_game_get_white_time_left (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "WhiteTimeLeft");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_white_time_left (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("WhiteTimeLeft");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "white-time-left");
}


const gchar* pgn_game_get_black_time_left (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "BlackTimeLeft");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_black_time_left (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("BlackTimeLeft");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "black-time-left");
}


const gchar* pgn_game_get_clock_type (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "X-GNOME-ClockType");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_clock_type (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("X-GNOME-ClockType");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "clock-type");
}


const gchar* pgn_game_get_timer_increment (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "X-GNOME-TimerIncrement");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_timer_increment (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("X-GNOME-TimerIncrement");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "timer-increment");
}


gboolean pgn_game_get_set_up (PGNGame* self) {
	gboolean result;
	gchar* v = NULL;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "SetUp");
	_tmp2_ = g_strdup ((const gchar*) _tmp1_);
	v = _tmp2_;
	_tmp5_ = v;
	if (_tmp5_ != NULL) {
		const gchar* _tmp6_ = NULL;
		_tmp6_ = v;
		_tmp4_ = g_strcmp0 (_tmp6_, "1") == 0;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		_tmp3_ = TRUE;
	} else {
		_tmp3_ = FALSE;
	}
	result = _tmp3_;
	_g_free0 (v);
	return result;
}


void pgn_game_set_set_up (PGNGame* self, gboolean value) {
	const gchar* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	GHashTable* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp1_ = value;
	if (_tmp1_) {
		_tmp0_ = "1";
	} else {
		_tmp0_ = "0";
	}
	_tmp2_ = self->tags;
	_tmp3_ = g_strdup ("SetUp");
	_tmp4_ = g_strdup (_tmp0_);
	g_hash_table_insert (_tmp2_, _tmp3_, _tmp4_);
	g_object_notify ((GObject *) self, "set-up");
}


const gchar* pgn_game_get_fen (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "FEN");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_fen (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("FEN");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "fen");
}


const gchar* pgn_game_get_termination (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "Termination");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_termination (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("Termination");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "termination");
}


const gchar* pgn_game_get_white_ai (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "WhiteAI");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_white_ai (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("WhiteAI");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "white-ai");
}


const gchar* pgn_game_get_white_level (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "WhiteLevel");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_white_level (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("WhiteLevel");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "white-level");
}


const gchar* pgn_game_get_black_ai (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "BlackAI");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_black_ai (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("BlackAI");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "black-ai");
}


const gchar* pgn_game_get_black_level (PGNGame* self) {
	const gchar* result;
	GHashTable* _tmp0_ = NULL;
	gconstpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_hash_table_lookup (_tmp0_, "BlackLevel");
	result = (const gchar*) _tmp1_;
	return result;
}


void pgn_game_set_black_level (PGNGame* self, const gchar* value) {
	GHashTable* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tags;
	_tmp1_ = g_strdup ("BlackLevel");
	_tmp2_ = value;
	_tmp3_ = g_strdup (_tmp2_);
	g_hash_table_insert (_tmp0_, _tmp1_, _tmp3_);
	g_object_notify ((GObject *) self, "black-level");
}


static void pgn_game_class_init (PGNGameClass * klass) {
	gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	pgn_game_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->get_property = _vala_pgn_game_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_pgn_game_set_property;
	G_OBJECT_CLASS (klass)->finalize = pgn_game_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_EVENT, g_param_spec_string ("event", "event", "event", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_SITE, g_param_spec_string ("site", "site", "site", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_DATE, g_param_spec_string ("date", "date", "date", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_TIME, g_param_spec_string ("time", "time", "time", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_ROUND, g_param_spec_string ("round", "round", "round", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_WHITE, g_param_spec_string ("white", "white", "white", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_BLACK, g_param_spec_string ("black", "black", "black", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_RESULT, g_param_spec_string ("result", "result", "result", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_ANNOTATOR, g_param_spec_string ("annotator", "annotator", "annotator", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_TIME_CONTROL, g_param_spec_string ("time-control", "time-control", "time-control", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_WHITE_TIME_LEFT, g_param_spec_string ("white-time-left", "white-time-left", "white-time-left", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_BLACK_TIME_LEFT, g_param_spec_string ("black-time-left", "black-time-left", "black-time-left", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_CLOCK_TYPE, g_param_spec_string ("clock-type", "clock-type", "clock-type", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_TIMER_INCREMENT, g_param_spec_string ("timer-increment", "timer-increment", "timer-increment", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_SET_UP, g_param_spec_boolean ("set-up", "set-up", "set-up", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_FEN, g_param_spec_string ("fen", "fen", "fen", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_TERMINATION, g_param_spec_string ("termination", "termination", "termination", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_WHITE_AI, g_param_spec_string ("white-ai", "white-ai", "white-ai", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_WHITE_LEVEL, g_param_spec_string ("white-level", "white-level", "white-level", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_BLACK_AI, g_param_spec_string ("black-ai", "black-ai", "black-ai", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), PGN_GAME_BLACK_LEVEL, g_param_spec_string ("black-level", "black-level", "black-level", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	_tmp0_ = g_strdup ("*");
	pgn_game_RESULT_IN_PROGRESS = _tmp0_;
	_tmp1_ = g_strdup ("1/2-1/2");
	pgn_game_RESULT_DRAW = _tmp1_;
	_tmp2_ = g_strdup ("1-0");
	pgn_game_RESULT_WHITE = _tmp2_;
	_tmp3_ = g_strdup ("0-1");
	pgn_game_RESULT_BLACK = _tmp3_;
	_tmp4_ = g_strdup ("abandoned");
	pgn_game_TERMINATE_ABANDONED = _tmp4_;
	_tmp5_ = g_strdup ("adjudication");
	pgn_game_TERMINATE_ADJUDICATION = _tmp5_;
	_tmp6_ = g_strdup ("death");
	pgn_game_TERMINATE_DEATH = _tmp6_;
	_tmp7_ = g_strdup ("emergency");
	pgn_game_TERMINATE_EMERGENCY = _tmp7_;
	_tmp8_ = g_strdup ("normal");
	pgn_game_TERMINATE_NORMAL = _tmp8_;
	_tmp9_ = g_strdup ("rules infraction");
	pgn_game_TERMINATE_RULES_INFRACTION = _tmp9_;
	_tmp10_ = g_strdup ("time forfeit");
	pgn_game_TERMINATE_TIME_FORFEIT = _tmp10_;
	_tmp11_ = g_strdup ("unterminated");
	pgn_game_TERMINATE_UNTERMINATED = _tmp11_;
}


static void pgn_game_instance_init (PGNGame * self) {
}


static void pgn_game_finalize (GObject* obj) {
	PGNGame * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_PGN_GAME, PGNGame);
	_g_hash_table_unref0 (self->tags);
	__g_list_free__g_free0_0 (self->moves);
	G_OBJECT_CLASS (pgn_game_parent_class)->finalize (obj);
}


GType pgn_game_get_type (void) {
	static volatile gsize pgn_game_type_id__volatile = 0;
	if (g_once_init_enter (&pgn_game_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (PGNGameClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pgn_game_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PGNGame), 0, (GInstanceInitFunc) pgn_game_instance_init, NULL };
		GType pgn_game_type_id;
		pgn_game_type_id = g_type_register_static (G_TYPE_OBJECT, "PGNGame", &g_define_type_info, 0);
		g_once_init_leave (&pgn_game_type_id__volatile, pgn_game_type_id);
	}
	return pgn_game_type_id__volatile;
}


static void _vala_pgn_game_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	PGNGame * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_PGN_GAME, PGNGame);
	switch (property_id) {
		case PGN_GAME_EVENT:
		g_value_set_string (value, pgn_game_get_event (self));
		break;
		case PGN_GAME_SITE:
		g_value_set_string (value, pgn_game_get_site (self));
		break;
		case PGN_GAME_DATE:
		g_value_set_string (value, pgn_game_get_date (self));
		break;
		case PGN_GAME_TIME:
		g_value_set_string (value, pgn_game_get_time (self));
		break;
		case PGN_GAME_ROUND:
		g_value_set_string (value, pgn_game_get_round (self));
		break;
		case PGN_GAME_WHITE:
		g_value_set_string (value, pgn_game_get_white (self));
		break;
		case PGN_GAME_BLACK:
		g_value_set_string (value, pgn_game_get_black (self));
		break;
		case PGN_GAME_RESULT:
		g_value_set_string (value, pgn_game_get_result (self));
		break;
		case PGN_GAME_ANNOTATOR:
		g_value_set_string (value, pgn_game_get_annotator (self));
		break;
		case PGN_GAME_TIME_CONTROL:
		g_value_set_string (value, pgn_game_get_time_control (self));
		break;
		case PGN_GAME_WHITE_TIME_LEFT:
		g_value_set_string (value, pgn_game_get_white_time_left (self));
		break;
		case PGN_GAME_BLACK_TIME_LEFT:
		g_value_set_string (value, pgn_game_get_black_time_left (self));
		break;
		case PGN_GAME_CLOCK_TYPE:
		g_value_set_string (value, pgn_game_get_clock_type (self));
		break;
		case PGN_GAME_TIMER_INCREMENT:
		g_value_set_string (value, pgn_game_get_timer_increment (self));
		break;
		case PGN_GAME_SET_UP:
		g_value_set_boolean (value, pgn_game_get_set_up (self));
		break;
		case PGN_GAME_FEN:
		g_value_set_string (value, pgn_game_get_fen (self));
		break;
		case PGN_GAME_TERMINATION:
		g_value_set_string (value, pgn_game_get_termination (self));
		break;
		case PGN_GAME_WHITE_AI:
		g_value_set_string (value, pgn_game_get_white_ai (self));
		break;
		case PGN_GAME_WHITE_LEVEL:
		g_value_set_string (value, pgn_game_get_white_level (self));
		break;
		case PGN_GAME_BLACK_AI:
		g_value_set_string (value, pgn_game_get_black_ai (self));
		break;
		case PGN_GAME_BLACK_LEVEL:
		g_value_set_string (value, pgn_game_get_black_level (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_pgn_game_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	PGNGame * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_PGN_GAME, PGNGame);
	switch (property_id) {
		case PGN_GAME_EVENT:
		pgn_game_set_event (self, g_value_get_string (value));
		break;
		case PGN_GAME_SITE:
		pgn_game_set_site (self, g_value_get_string (value));
		break;
		case PGN_GAME_DATE:
		pgn_game_set_date (self, g_value_get_string (value));
		break;
		case PGN_GAME_TIME:
		pgn_game_set_time (self, g_value_get_string (value));
		break;
		case PGN_GAME_ROUND:
		pgn_game_set_round (self, g_value_get_string (value));
		break;
		case PGN_GAME_WHITE:
		pgn_game_set_white (self, g_value_get_string (value));
		break;
		case PGN_GAME_BLACK:
		pgn_game_set_black (self, g_value_get_string (value));
		break;
		case PGN_GAME_RESULT:
		pgn_game_set_result (self, g_value_get_string (value));
		break;
		case PGN_GAME_ANNOTATOR:
		pgn_game_set_annotator (self, g_value_get_string (value));
		break;
		case PGN_GAME_TIME_CONTROL:
		pgn_game_set_time_control (self, g_value_get_string (value));
		break;
		case PGN_GAME_WHITE_TIME_LEFT:
		pgn_game_set_white_time_left (self, g_value_get_string (value));
		break;
		case PGN_GAME_BLACK_TIME_LEFT:
		pgn_game_set_black_time_left (self, g_value_get_string (value));
		break;
		case PGN_GAME_CLOCK_TYPE:
		pgn_game_set_clock_type (self, g_value_get_string (value));
		break;
		case PGN_GAME_TIMER_INCREMENT:
		pgn_game_set_timer_increment (self, g_value_get_string (value));
		break;
		case PGN_GAME_SET_UP:
		pgn_game_set_set_up (self, g_value_get_boolean (value));
		break;
		case PGN_GAME_FEN:
		pgn_game_set_fen (self, g_value_get_string (value));
		break;
		case PGN_GAME_TERMINATION:
		pgn_game_set_termination (self, g_value_get_string (value));
		break;
		case PGN_GAME_WHITE_AI:
		pgn_game_set_white_ai (self, g_value_get_string (value));
		break;
		case PGN_GAME_WHITE_LEVEL:
		pgn_game_set_white_level (self, g_value_get_string (value));
		break;
		case PGN_GAME_BLACK_AI:
		pgn_game_set_black_ai (self, g_value_get_string (value));
		break;
		case PGN_GAME_BLACK_LEVEL:
		pgn_game_set_black_level (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


GType state_get_type (void) {
	static volatile gsize state_type_id__volatile = 0;
	if (g_once_init_enter (&state_type_id__volatile)) {
		static const GEnumValue values[] = {{STATE_TAGS, "STATE_TAGS", "tags"}, {STATE_MOVE_TEXT, "STATE_MOVE_TEXT", "move-text"}, {STATE_LINE_COMMENT, "STATE_LINE_COMMENT", "line-comment"}, {STATE_BRACE_COMMENT, "STATE_BRACE_COMMENT", "brace-comment"}, {STATE_TAG_START, "STATE_TAG_START", "tag-start"}, {STATE_TAG_NAME, "STATE_TAG_NAME", "tag-name"}, {STATE_PRE_TAG_VALUE, "STATE_PRE_TAG_VALUE", "pre-tag-value"}, {STATE_TAG_VALUE, "STATE_TAG_VALUE", "tag-value"}, {STATE_POST_TAG_VALUE, "STATE_POST_TAG_VALUE", "post-tag-value"}, {STATE_SYMBOL, "STATE_SYMBOL", "symbol"}, {STATE_PERIOD, "STATE_PERIOD", "period"}, {STATE_NAG, "STATE_NAG", "nag"}, {STATE_ERROR, "STATE_ERROR", "error"}, {0, NULL, NULL}};
		GType state_type_id;
		state_type_id = g_enum_register_static ("State", values);
		g_once_init_leave (&state_type_id__volatile, state_type_id);
	}
	return state_type_id__volatile;
}


static void _g_object_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


static void _g_list_free__g_object_unref0_ (GList* self) {
	g_list_foreach (self, (GFunc) _g_object_unref0_, NULL);
	g_list_free (self);
}


static gboolean int64_try_parse (const gchar* str, gint64* _result_) {
	gint64 _vala_result = 0LL;
	gboolean result = FALSE;
	gchar* endptr = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gint64 _tmp2_ = 0LL;
	gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	const gchar* _tmp5_ = NULL;
	gint _tmp6_ = 0;
	gint _tmp7_ = 0;
	g_return_val_if_fail (str != NULL, FALSE);
	_tmp0_ = str;
	_tmp2_ = g_ascii_strtoll (_tmp0_, &_tmp1_, (guint) 0);
	endptr = _tmp1_;
	_vala_result = _tmp2_;
	_tmp3_ = endptr;
	_tmp4_ = str;
	_tmp5_ = str;
	_tmp6_ = strlen (_tmp5_);
	_tmp7_ = _tmp6_;
	if (_tmp3_ == (((gchar*) _tmp4_) + _tmp7_)) {
		result = TRUE;
		if (_result_) {
			*_result_ = _vala_result;
		}
		return result;
	} else {
		result = FALSE;
		if (_result_) {
			*_result_ = _vala_result;
		}
		return result;
	}
	if (_result_) {
		*_result_ = _vala_result;
	}
}


static void pgn_insert_tag (PGN* self, PGNGame* game, const gchar* tag_name, const gchar* tag_value) {
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	GQuark _tmp3_ = 0U;
	static GQuark _tmp2_label0 = 0;
	static GQuark _tmp2_label1 = 0;
	static GQuark _tmp2_label2 = 0;
	static GQuark _tmp2_label3 = 0;
	static GQuark _tmp2_label4 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (game != NULL);
	g_return_if_fail (tag_name != NULL);
	g_return_if_fail (tag_value != NULL);
	_tmp0_ = tag_name;
	_tmp1_ = _tmp0_;
	_tmp3_ = (NULL == _tmp1_) ? 0 : g_quark_from_string (_tmp1_);
	if (_tmp3_ == ((0 != _tmp2_label0) ? _tmp2_label0 : (_tmp2_label0 = g_quark_from_static_string ("WhiteTimeLeft")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp4_ = NULL;
				gboolean _tmp5_ = FALSE;
				_tmp4_ = tag_value;
				_tmp5_ = int64_try_parse (_tmp4_, NULL);
				if (_tmp5_ == FALSE) {
					const gchar* _tmp6_ = NULL;
					const gchar* _tmp7_ = NULL;
					const gchar* _tmp8_ = NULL;
					_tmp6_ = _ ("Invalid %s : %s in PGN, setting timer to infinity.");
					_tmp7_ = tag_name;
					_tmp8_ = tag_value;
					g_warning (_tmp6_, _tmp7_, _tmp8_);
				} else {
					PGNGame* _tmp9_ = NULL;
					GHashTable* _tmp10_ = NULL;
					const gchar* _tmp11_ = NULL;
					gchar* _tmp12_ = NULL;
					const gchar* _tmp13_ = NULL;
					gchar* _tmp14_ = NULL;
					_tmp9_ = game;
					_tmp10_ = _tmp9_->tags;
					_tmp11_ = tag_name;
					_tmp12_ = g_strdup (_tmp11_);
					_tmp13_ = tag_value;
					_tmp14_ = g_strdup (_tmp13_);
					g_hash_table_insert (_tmp10_, _tmp12_, _tmp14_);
				}
				break;
			}
		}
	} else if (_tmp3_ == ((0 != _tmp2_label1) ? _tmp2_label1 : (_tmp2_label1 = g_quark_from_static_string ("BlackTimeLeft")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp15_ = NULL;
				gboolean _tmp16_ = FALSE;
				_tmp15_ = tag_value;
				_tmp16_ = int64_try_parse (_tmp15_, NULL);
				if (_tmp16_ == FALSE) {
					const gchar* _tmp17_ = NULL;
					const gchar* _tmp18_ = NULL;
					const gchar* _tmp19_ = NULL;
					_tmp17_ = _ ("Invalid %s : %s in PGN, setting timer to infinity.");
					_tmp18_ = tag_name;
					_tmp19_ = tag_value;
					g_warning (_tmp17_, _tmp18_, _tmp19_);
				} else {
					PGNGame* _tmp20_ = NULL;
					GHashTable* _tmp21_ = NULL;
					const gchar* _tmp22_ = NULL;
					gchar* _tmp23_ = NULL;
					const gchar* _tmp24_ = NULL;
					gchar* _tmp25_ = NULL;
					_tmp20_ = game;
					_tmp21_ = _tmp20_->tags;
					_tmp22_ = tag_name;
					_tmp23_ = g_strdup (_tmp22_);
					_tmp24_ = tag_value;
					_tmp25_ = g_strdup (_tmp24_);
					g_hash_table_insert (_tmp21_, _tmp23_, _tmp25_);
				}
				break;
			}
		}
	} else if (_tmp3_ == ((0 != _tmp2_label2) ? _tmp2_label2 : (_tmp2_label2 = g_quark_from_static_string ("TimeControl")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp26_ = NULL;
				gboolean _tmp27_ = FALSE;
				_tmp26_ = tag_value;
				_tmp27_ = int64_try_parse (_tmp26_, NULL);
				if (_tmp27_ == TRUE) {
					gboolean _tmp28_ = FALSE;
					PGNGame* _tmp29_ = NULL;
					GHashTable* _tmp30_ = NULL;
					gconstpointer _tmp31_ = NULL;
					_tmp29_ = game;
					_tmp30_ = _tmp29_->tags;
					_tmp31_ = g_hash_table_lookup (_tmp30_, "WhiteTimeLeft");
					if (((const gchar*) _tmp31_) != NULL) {
						PGNGame* _tmp32_ = NULL;
						GHashTable* _tmp33_ = NULL;
						gconstpointer _tmp34_ = NULL;
						_tmp32_ = game;
						_tmp33_ = _tmp32_->tags;
						_tmp34_ = g_hash_table_lookup (_tmp33_, "BlackTimeLeft");
						_tmp28_ = ((const gchar*) _tmp34_) != NULL;
					} else {
						_tmp28_ = FALSE;
					}
					if (_tmp28_) {
						PGNGame* _tmp35_ = NULL;
						GHashTable* _tmp36_ = NULL;
						const gchar* _tmp37_ = NULL;
						gchar* _tmp38_ = NULL;
						const gchar* _tmp39_ = NULL;
						gchar* _tmp40_ = NULL;
						_tmp35_ = game;
						_tmp36_ = _tmp35_->tags;
						_tmp37_ = tag_name;
						_tmp38_ = g_strdup (_tmp37_);
						_tmp39_ = tag_value;
						_tmp40_ = g_strdup (_tmp39_);
						g_hash_table_insert (_tmp36_, _tmp38_, _tmp40_);
					}
				} else {
					const gchar* _tmp41_ = NULL;
					const gchar* _tmp42_ = NULL;
					const gchar* _tmp43_ = NULL;
					_tmp41_ = _ ("Invalid %s : %s in PGN, setting timer to infinity.");
					_tmp42_ = tag_name;
					_tmp43_ = tag_value;
					g_warning (_tmp41_, _tmp42_, _tmp43_);
				}
				break;
			}
		}
	} else if (_tmp3_ == ((0 != _tmp2_label3) ? _tmp2_label3 : (_tmp2_label3 = g_quark_from_static_string ("X-GNOME-ClockType")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp44_ = NULL;
				ClockType _tmp45_ = 0;
				_tmp44_ = tag_value;
				_tmp45_ = clock_type_string_to_enum (_tmp44_);
				if (_tmp45_ == CLOCK_TYPE_INVALID) {
					const gchar* _tmp46_ = NULL;
					const gchar* _tmp47_ = NULL;
					PGNGame* _tmp48_ = NULL;
					GHashTable* _tmp49_ = NULL;
					const gchar* _tmp50_ = NULL;
					gchar* _tmp51_ = NULL;
					gchar* _tmp52_ = NULL;
					_tmp46_ = _ ("Invalid clock type in PGN: %s, using a simple clock.");
					_tmp47_ = tag_value;
					g_warning (_tmp46_, _tmp47_);
					_tmp48_ = game;
					_tmp49_ = _tmp48_->tags;
					_tmp50_ = tag_name;
					_tmp51_ = g_strdup (_tmp50_);
					_tmp52_ = g_strdup ("simple");
					g_hash_table_insert (_tmp49_, _tmp51_, _tmp52_);
				}
				break;
			}
		}
	} else if (_tmp3_ == ((0 != _tmp2_label4) ? _tmp2_label4 : (_tmp2_label4 = g_quark_from_static_string ("X-GNOME-TimerIncrement")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp53_ = NULL;
				gboolean _tmp54_ = FALSE;
				_tmp53_ = tag_value;
				_tmp54_ = int64_try_parse (_tmp53_, NULL);
				if (_tmp54_ == FALSE) {
					const gchar* _tmp55_ = NULL;
					const gchar* _tmp56_ = NULL;
					PGNGame* _tmp57_ = NULL;
					GHashTable* _tmp58_ = NULL;
					gchar* _tmp59_ = NULL;
					gchar* _tmp60_ = NULL;
					PGNGame* _tmp61_ = NULL;
					GHashTable* _tmp62_ = NULL;
					const gchar* _tmp63_ = NULL;
					gchar* _tmp64_ = NULL;
					gchar* _tmp65_ = NULL;
					_tmp55_ = _ ("Invalid timer increment in PGN: %s, using a simple clock.");
					_tmp56_ = tag_value;
					g_warning (_tmp55_, _tmp56_);
					_tmp57_ = game;
					_tmp58_ = _tmp57_->tags;
					_tmp59_ = g_strdup ("X-GNOME-ClockType");
					_tmp60_ = g_strdup ("simple");
					g_hash_table_insert (_tmp58_, _tmp59_, _tmp60_);
					_tmp61_ = game;
					_tmp62_ = _tmp61_->tags;
					_tmp63_ = tag_name;
					_tmp64_ = g_strdup (_tmp63_);
					_tmp65_ = g_strdup ("0");
					g_hash_table_insert (_tmp62_, _tmp64_, _tmp65_);
				}
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				PGNGame* _tmp66_ = NULL;
				GHashTable* _tmp67_ = NULL;
				const gchar* _tmp68_ = NULL;
				gchar* _tmp69_ = NULL;
				const gchar* _tmp70_ = NULL;
				gchar* _tmp71_ = NULL;
				_tmp66_ = game;
				_tmp67_ = _tmp66_->tags;
				_tmp68_ = tag_name;
				_tmp69_ = g_strdup (_tmp68_);
				_tmp70_ = tag_value;
				_tmp71_ = g_strdup (_tmp70_);
				g_hash_table_insert (_tmp67_, _tmp69_, _tmp71_);
				break;
			}
		}
	}
}


static gchar string_get (const gchar* self, glong index) {
	gchar result = '\0';
	glong _tmp0_ = 0L;
	gchar _tmp1_ = '\0';
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = index;
	_tmp1_ = ((gchar*) self)[_tmp0_];
	result = _tmp1_;
	return result;
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static gchar* string_slice (const gchar* self, glong start, glong end) {
	gchar* result = NULL;
	glong string_length = 0L;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	glong _tmp2_ = 0L;
	glong _tmp5_ = 0L;
	gboolean _tmp8_ = FALSE;
	glong _tmp9_ = 0L;
	gboolean _tmp12_ = FALSE;
	glong _tmp13_ = 0L;
	glong _tmp16_ = 0L;
	glong _tmp17_ = 0L;
	glong _tmp18_ = 0L;
	glong _tmp19_ = 0L;
	glong _tmp20_ = 0L;
	gchar* _tmp21_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	_tmp2_ = start;
	if (_tmp2_ < ((glong) 0)) {
		glong _tmp3_ = 0L;
		glong _tmp4_ = 0L;
		_tmp3_ = string_length;
		_tmp4_ = start;
		start = _tmp3_ + _tmp4_;
	}
	_tmp5_ = end;
	if (_tmp5_ < ((glong) 0)) {
		glong _tmp6_ = 0L;
		glong _tmp7_ = 0L;
		_tmp6_ = string_length;
		_tmp7_ = end;
		end = _tmp6_ + _tmp7_;
	}
	_tmp9_ = start;
	if (_tmp9_ >= ((glong) 0)) {
		glong _tmp10_ = 0L;
		glong _tmp11_ = 0L;
		_tmp10_ = start;
		_tmp11_ = string_length;
		_tmp8_ = _tmp10_ <= _tmp11_;
	} else {
		_tmp8_ = FALSE;
	}
	g_return_val_if_fail (_tmp8_, NULL);
	_tmp13_ = end;
	if (_tmp13_ >= ((glong) 0)) {
		glong _tmp14_ = 0L;
		glong _tmp15_ = 0L;
		_tmp14_ = end;
		_tmp15_ = string_length;
		_tmp12_ = _tmp14_ <= _tmp15_;
	} else {
		_tmp12_ = FALSE;
	}
	g_return_val_if_fail (_tmp12_, NULL);
	_tmp16_ = start;
	_tmp17_ = end;
	g_return_val_if_fail (_tmp16_ <= _tmp17_, NULL);
	_tmp18_ = start;
	_tmp19_ = end;
	_tmp20_ = start;
	_tmp21_ = g_strndup (((gchar*) self) + _tmp18_, (gsize) (_tmp19_ - _tmp20_));
	result = _tmp21_;
	return result;
}


PGN* pgn_construct_from_string (GType object_type, const gchar* data, GError** error) {
	PGN * self = NULL;
	State state = 0;
	State home_state = 0;
	PGNGame* game = NULL;
	PGNGame* _tmp0_ = NULL;
	gboolean in_escape = FALSE;
	gsize token_start = 0UL;
	gsize line_offset = 0UL;
	gchar* tag_name = NULL;
	gchar* _tmp1_ = NULL;
	GString* tag_value = NULL;
	GString* _tmp2_ = NULL;
	gint line = 0;
	gint rav_level = 0;
	gboolean _tmp165_ = FALSE;
	PGNGame* _tmp166_ = NULL;
	GList* _tmp167_ = NULL;
	guint _tmp168_ = 0U;
	GList* _tmp174_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (data != NULL, NULL);
	self = (PGN*) g_object_new (object_type, NULL);
	state = STATE_TAGS;
	home_state = STATE_TAGS;
	_tmp0_ = pgn_game_new ();
	game = _tmp0_;
	in_escape = FALSE;
	token_start = (gsize) 0;
	line_offset = (gsize) 0;
	_tmp1_ = g_strdup ("");
	tag_name = _tmp1_;
	_tmp2_ = g_string_new ("");
	tag_value = _tmp2_;
	line = 1;
	rav_level = 0;
	{
		gsize offset = 0UL;
		offset = (gsize) 0;
		{
			gboolean _tmp3_ = FALSE;
			_tmp3_ = TRUE;
			while (TRUE) {
				gsize _tmp5_ = 0UL;
				const gchar* _tmp6_ = NULL;
				gint _tmp7_ = 0;
				gint _tmp8_ = 0;
				gunichar c = 0U;
				const gchar* _tmp9_ = NULL;
				gsize _tmp10_ = 0UL;
				gchar _tmp11_ = '\0';
				gunichar _tmp12_ = 0U;
				State _tmp15_ = 0;
				if (!_tmp3_) {
					gsize _tmp4_ = 0UL;
					_tmp4_ = offset;
					offset = _tmp4_ + 1;
				}
				_tmp3_ = FALSE;
				_tmp5_ = offset;
				_tmp6_ = data;
				_tmp7_ = strlen (_tmp6_);
				_tmp8_ = _tmp7_;
				if (!(_tmp5_ <= ((gsize) _tmp8_))) {
					break;
				}
				_tmp9_ = data;
				_tmp10_ = offset;
				_tmp11_ = string_get (_tmp9_, (glong) _tmp10_);
				c = (gunichar) _tmp11_;
				_tmp12_ = c;
				if (_tmp12_ == ((gunichar) '\n')) {
					gint _tmp13_ = 0;
					gsize _tmp14_ = 0UL;
					_tmp13_ = line;
					line = _tmp13_ + 1;
					_tmp14_ = offset;
					line_offset = _tmp14_ + 1;
				}
				_tmp15_ = state;
				switch (_tmp15_) {
					case STATE_TAGS:
					{
						gunichar _tmp16_ = 0U;
						home_state = STATE_TAGS;
						_tmp16_ = c;
						if (_tmp16_ == ((gunichar) ';')) {
							state = STATE_LINE_COMMENT;
						} else {
							gunichar _tmp17_ = 0U;
							_tmp17_ = c;
							if (_tmp17_ == ((gunichar) '{')) {
								state = STATE_BRACE_COMMENT;
							} else {
								gunichar _tmp18_ = 0U;
								_tmp18_ = c;
								if (_tmp18_ == ((gunichar) '[')) {
									state = STATE_TAG_START;
								} else {
									gunichar _tmp19_ = 0U;
									gboolean _tmp20_ = FALSE;
									_tmp19_ = c;
									_tmp20_ = g_unichar_isspace (_tmp19_);
									if (!_tmp20_) {
										gsize _tmp21_ = 0UL;
										_tmp21_ = offset;
										offset = _tmp21_ - 1;
										state = STATE_MOVE_TEXT;
										continue;
									}
								}
							}
						}
						break;
					}
					case STATE_MOVE_TEXT:
					{
						gunichar _tmp22_ = 0U;
						home_state = STATE_MOVE_TEXT;
						_tmp22_ = c;
						if (_tmp22_ == ((gunichar) ';')) {
							state = STATE_LINE_COMMENT;
						} else {
							gunichar _tmp23_ = 0U;
							_tmp23_ = c;
							if (_tmp23_ == ((gunichar) '{')) {
								state = STATE_BRACE_COMMENT;
							} else {
								gunichar _tmp24_ = 0U;
								_tmp24_ = c;
								if (_tmp24_ == ((gunichar) '*')) {
									gint _tmp25_ = 0;
									_tmp25_ = rav_level;
									if (_tmp25_ == 0) {
										PGNGame* _tmp26_ = NULL;
										const gchar* _tmp27_ = NULL;
										PGNGame* _tmp28_ = NULL;
										PGNGame* _tmp29_ = NULL;
										PGNGame* _tmp30_ = NULL;
										_tmp26_ = game;
										_tmp27_ = pgn_game_RESULT_IN_PROGRESS;
										pgn_game_set_result (_tmp26_, _tmp27_);
										_tmp28_ = game;
										_tmp29_ = _g_object_ref0 (_tmp28_);
										self->games = g_list_append (self->games, _tmp29_);
										_tmp30_ = pgn_game_new ();
										_g_object_unref0 (game);
										game = _tmp30_;
										state = STATE_TAGS;
									}
								} else {
									gunichar _tmp31_ = 0U;
									_tmp31_ = c;
									if (_tmp31_ == ((gunichar) '.')) {
										gsize _tmp32_ = 0UL;
										_tmp32_ = offset;
										offset = _tmp32_ - 1;
										state = STATE_PERIOD;
									} else {
										gunichar _tmp33_ = 0U;
										gboolean _tmp34_ = FALSE;
										_tmp33_ = c;
										_tmp34_ = g_unichar_isalnum (_tmp33_);
										if (_tmp34_) {
											gsize _tmp35_ = 0UL;
											_tmp35_ = offset;
											token_start = _tmp35_;
											state = STATE_SYMBOL;
										} else {
											gunichar _tmp36_ = 0U;
											_tmp36_ = c;
											if (_tmp36_ == ((gunichar) '$')) {
												gsize _tmp37_ = 0UL;
												_tmp37_ = offset;
												token_start = _tmp37_ + 1;
												state = STATE_NAG;
											} else {
												gunichar _tmp38_ = 0U;
												_tmp38_ = c;
												if (_tmp38_ == ((gunichar) '(')) {
													gint _tmp39_ = 0;
													_tmp39_ = rav_level;
													rav_level = _tmp39_ + 1;
													continue;
												} else {
													gunichar _tmp40_ = 0U;
													_tmp40_ = c;
													if (_tmp40_ == ((gunichar) ')')) {
														gint _tmp41_ = 0;
														_tmp41_ = rav_level;
														if (_tmp41_ == 0) {
															state = STATE_ERROR;
														} else {
															gint _tmp42_ = 0;
															_tmp42_ = rav_level;
															rav_level = _tmp42_ - 1;
														}
													} else {
														gunichar _tmp43_ = 0U;
														gboolean _tmp44_ = FALSE;
														_tmp43_ = c;
														_tmp44_ = g_unichar_isspace (_tmp43_);
														if (!_tmp44_) {
															state = STATE_ERROR;
														}
													}
												}
											}
										}
									}
								}
							}
						}
						break;
					}
					case STATE_LINE_COMMENT:
					{
						gunichar _tmp45_ = 0U;
						_tmp45_ = c;
						if (_tmp45_ == ((gunichar) '\n')) {
							State _tmp46_ = 0;
							_tmp46_ = home_state;
							state = _tmp46_;
						}
						break;
					}
					case STATE_BRACE_COMMENT:
					{
						gunichar _tmp47_ = 0U;
						_tmp47_ = c;
						if (_tmp47_ == ((gunichar) '}')) {
							State _tmp48_ = 0;
							_tmp48_ = home_state;
							state = _tmp48_;
						}
						break;
					}
					case STATE_TAG_START:
					{
						gunichar _tmp49_ = 0U;
						gboolean _tmp50_ = FALSE;
						_tmp49_ = c;
						_tmp50_ = g_unichar_isspace (_tmp49_);
						if (_tmp50_) {
							continue;
						} else {
							gunichar _tmp51_ = 0U;
							gboolean _tmp52_ = FALSE;
							_tmp51_ = c;
							_tmp52_ = g_unichar_isalnum (_tmp51_);
							if (_tmp52_) {
								gsize _tmp53_ = 0UL;
								_tmp53_ = offset;
								token_start = _tmp53_;
								state = STATE_TAG_NAME;
							} else {
								state = STATE_ERROR;
							}
						}
						break;
					}
					case STATE_TAG_NAME:
					{
						gunichar _tmp54_ = 0U;
						gboolean _tmp55_ = FALSE;
						_tmp54_ = c;
						_tmp55_ = g_unichar_isspace (_tmp54_);
						if (_tmp55_) {
							const gchar* _tmp56_ = NULL;
							gsize _tmp57_ = 0UL;
							gsize _tmp58_ = 0UL;
							gchar* _tmp59_ = NULL;
							_tmp56_ = data;
							_tmp57_ = token_start;
							_tmp58_ = offset;
							_tmp59_ = string_slice (_tmp56_, (glong) _tmp57_, (glong) _tmp58_);
							_g_free0 (tag_name);
							tag_name = _tmp59_;
							state = STATE_PRE_TAG_VALUE;
						} else {
							gboolean _tmp60_ = FALSE;
							gboolean _tmp61_ = FALSE;
							gboolean _tmp62_ = FALSE;
							gboolean _tmp63_ = FALSE;
							gboolean _tmp64_ = FALSE;
							gboolean _tmp65_ = FALSE;
							gunichar _tmp66_ = 0U;
							gboolean _tmp67_ = FALSE;
							_tmp66_ = c;
							_tmp67_ = g_unichar_isalnum (_tmp66_);
							if (_tmp67_) {
								_tmp65_ = TRUE;
							} else {
								gunichar _tmp68_ = 0U;
								_tmp68_ = c;
								_tmp65_ = _tmp68_ == ((gunichar) '_');
							}
							if (_tmp65_) {
								_tmp64_ = TRUE;
							} else {
								gunichar _tmp69_ = 0U;
								_tmp69_ = c;
								_tmp64_ = _tmp69_ == ((gunichar) '+');
							}
							if (_tmp64_) {
								_tmp63_ = TRUE;
							} else {
								gunichar _tmp70_ = 0U;
								_tmp70_ = c;
								_tmp63_ = _tmp70_ == ((gunichar) '#');
							}
							if (_tmp63_) {
								_tmp62_ = TRUE;
							} else {
								gunichar _tmp71_ = 0U;
								_tmp71_ = c;
								_tmp62_ = _tmp71_ == ((gunichar) '=');
							}
							if (_tmp62_) {
								_tmp61_ = TRUE;
							} else {
								gunichar _tmp72_ = 0U;
								_tmp72_ = c;
								_tmp61_ = _tmp72_ == ((gunichar) ':');
							}
							if (_tmp61_) {
								_tmp60_ = TRUE;
							} else {
								gunichar _tmp73_ = 0U;
								_tmp73_ = c;
								_tmp60_ = _tmp73_ == ((gunichar) '-');
							}
							if (_tmp60_) {
								continue;
							} else {
								state = STATE_ERROR;
							}
						}
						break;
					}
					case STATE_PRE_TAG_VALUE:
					{
						gunichar _tmp74_ = 0U;
						gboolean _tmp75_ = FALSE;
						_tmp74_ = c;
						_tmp75_ = g_unichar_isspace (_tmp74_);
						if (_tmp75_) {
							continue;
						} else {
							gunichar _tmp76_ = 0U;
							_tmp76_ = c;
							if (_tmp76_ == ((gunichar) '"')) {
								GString* _tmp77_ = NULL;
								state = STATE_TAG_VALUE;
								_tmp77_ = tag_value;
								g_string_erase (_tmp77_, (gssize) 0, (gssize) -1);
								in_escape = FALSE;
							} else {
								state = STATE_ERROR;
							}
						}
						break;
					}
					case STATE_TAG_VALUE:
					{
						gboolean _tmp78_ = FALSE;
						gunichar _tmp79_ = 0U;
						_tmp79_ = c;
						if (_tmp79_ == ((gunichar) '\\')) {
							gboolean _tmp80_ = FALSE;
							_tmp80_ = in_escape;
							_tmp78_ = !_tmp80_;
						} else {
							_tmp78_ = FALSE;
						}
						if (_tmp78_) {
							in_escape = TRUE;
						} else {
							gboolean _tmp81_ = FALSE;
							gunichar _tmp82_ = 0U;
							_tmp82_ = c;
							if (_tmp82_ == ((gunichar) '"')) {
								gboolean _tmp83_ = FALSE;
								_tmp83_ = in_escape;
								_tmp81_ = !_tmp83_;
							} else {
								_tmp81_ = FALSE;
							}
							if (_tmp81_) {
								state = STATE_POST_TAG_VALUE;
							} else {
								gunichar _tmp84_ = 0U;
								gboolean _tmp85_ = FALSE;
								_tmp84_ = c;
								_tmp85_ = g_unichar_isprint (_tmp84_);
								if (_tmp85_) {
									GString* _tmp86_ = NULL;
									gunichar _tmp87_ = 0U;
									_tmp86_ = tag_value;
									_tmp87_ = c;
									g_string_append_unichar (_tmp86_, _tmp87_);
									in_escape = FALSE;
								} else {
									state = STATE_ERROR;
								}
							}
						}
						break;
					}
					case STATE_POST_TAG_VALUE:
					{
						gunichar _tmp88_ = 0U;
						gboolean _tmp89_ = FALSE;
						_tmp88_ = c;
						_tmp89_ = g_unichar_isspace (_tmp88_);
						if (_tmp89_) {
							continue;
						} else {
							gunichar _tmp90_ = 0U;
							_tmp90_ = c;
							if (_tmp90_ == ((gunichar) ']')) {
								PGNGame* _tmp91_ = NULL;
								const gchar* _tmp92_ = NULL;
								GString* _tmp93_ = NULL;
								const gchar* _tmp94_ = NULL;
								_tmp91_ = game;
								_tmp92_ = tag_name;
								_tmp93_ = tag_value;
								_tmp94_ = _tmp93_->str;
								pgn_insert_tag (self, _tmp91_, _tmp92_, _tmp94_);
								state = STATE_TAGS;
							} else {
								state = STATE_ERROR;
							}
						}
						break;
					}
					case STATE_SYMBOL:
					{
						gboolean _tmp95_ = FALSE;
						gboolean _tmp96_ = FALSE;
						gboolean _tmp97_ = FALSE;
						gboolean _tmp98_ = FALSE;
						gboolean _tmp99_ = FALSE;
						gboolean _tmp100_ = FALSE;
						gboolean _tmp101_ = FALSE;
						gunichar _tmp102_ = 0U;
						gboolean _tmp103_ = FALSE;
						_tmp102_ = c;
						_tmp103_ = g_unichar_isalnum (_tmp102_);
						if (_tmp103_) {
							_tmp101_ = TRUE;
						} else {
							gunichar _tmp104_ = 0U;
							_tmp104_ = c;
							_tmp101_ = _tmp104_ == ((gunichar) '_');
						}
						if (_tmp101_) {
							_tmp100_ = TRUE;
						} else {
							gunichar _tmp105_ = 0U;
							_tmp105_ = c;
							_tmp100_ = _tmp105_ == ((gunichar) '+');
						}
						if (_tmp100_) {
							_tmp99_ = TRUE;
						} else {
							gunichar _tmp106_ = 0U;
							_tmp106_ = c;
							_tmp99_ = _tmp106_ == ((gunichar) '#');
						}
						if (_tmp99_) {
							_tmp98_ = TRUE;
						} else {
							gunichar _tmp107_ = 0U;
							_tmp107_ = c;
							_tmp98_ = _tmp107_ == ((gunichar) '=');
						}
						if (_tmp98_) {
							_tmp97_ = TRUE;
						} else {
							gunichar _tmp108_ = 0U;
							_tmp108_ = c;
							_tmp97_ = _tmp108_ == ((gunichar) ':');
						}
						if (_tmp97_) {
							_tmp96_ = TRUE;
						} else {
							gunichar _tmp109_ = 0U;
							_tmp109_ = c;
							_tmp96_ = _tmp109_ == ((gunichar) '-');
						}
						if (_tmp96_) {
							_tmp95_ = TRUE;
						} else {
							gunichar _tmp110_ = 0U;
							_tmp110_ = c;
							_tmp95_ = _tmp110_ == ((gunichar) '/');
						}
						if (_tmp95_) {
							continue;
						} else {
							gchar* symbol = NULL;
							const gchar* _tmp111_ = NULL;
							gsize _tmp112_ = 0UL;
							gsize _tmp113_ = 0UL;
							gchar* _tmp114_ = NULL;
							gboolean is_number = FALSE;
							gsize _tmp125_ = 0UL;
							gboolean _tmp126_ = FALSE;
							gboolean _tmp127_ = FALSE;
							const gchar* _tmp128_ = NULL;
							const gchar* _tmp129_ = NULL;
							_tmp111_ = data;
							_tmp112_ = token_start;
							_tmp113_ = offset;
							_tmp114_ = string_slice (_tmp111_, (glong) _tmp112_, (glong) _tmp113_);
							symbol = _tmp114_;
							is_number = TRUE;
							{
								gint i = 0;
								i = 0;
								{
									gboolean _tmp115_ = FALSE;
									_tmp115_ = TRUE;
									while (TRUE) {
										gint _tmp117_ = 0;
										const gchar* _tmp118_ = NULL;
										gint _tmp119_ = 0;
										gint _tmp120_ = 0;
										const gchar* _tmp121_ = NULL;
										gint _tmp122_ = 0;
										gchar _tmp123_ = '\0';
										gboolean _tmp124_ = FALSE;
										if (!_tmp115_) {
											gint _tmp116_ = 0;
											_tmp116_ = i;
											i = _tmp116_ + 1;
										}
										_tmp115_ = FALSE;
										_tmp117_ = i;
										_tmp118_ = symbol;
										_tmp119_ = strlen (_tmp118_);
										_tmp120_ = _tmp119_;
										if (!(_tmp117_ < _tmp120_)) {
											break;
										}
										_tmp121_ = symbol;
										_tmp122_ = i;
										_tmp123_ = string_get (_tmp121_, (glong) _tmp122_);
										_tmp124_ = g_ascii_isdigit (_tmp123_);
										if (!_tmp124_) {
											is_number = FALSE;
										}
									}
								}
							}
							state = STATE_MOVE_TEXT;
							_tmp125_ = offset;
							offset = _tmp125_ - 1;
							_tmp128_ = symbol;
							_tmp129_ = pgn_game_RESULT_DRAW;
							if (g_strcmp0 (_tmp128_, _tmp129_) == 0) {
								_tmp127_ = TRUE;
							} else {
								const gchar* _tmp130_ = NULL;
								const gchar* _tmp131_ = NULL;
								_tmp130_ = symbol;
								_tmp131_ = pgn_game_RESULT_WHITE;
								_tmp127_ = g_strcmp0 (_tmp130_, _tmp131_) == 0;
							}
							if (_tmp127_) {
								_tmp126_ = TRUE;
							} else {
								const gchar* _tmp132_ = NULL;
								const gchar* _tmp133_ = NULL;
								_tmp132_ = symbol;
								_tmp133_ = pgn_game_RESULT_BLACK;
								_tmp126_ = g_strcmp0 (_tmp132_, _tmp133_) == 0;
							}
							if (_tmp126_) {
								gint _tmp134_ = 0;
								_tmp134_ = rav_level;
								if (_tmp134_ == 0) {
									PGNGame* _tmp135_ = NULL;
									const gchar* _tmp136_ = NULL;
									PGNGame* _tmp137_ = NULL;
									PGNGame* _tmp138_ = NULL;
									PGNGame* _tmp139_ = NULL;
									_tmp135_ = game;
									_tmp136_ = symbol;
									pgn_game_set_result (_tmp135_, _tmp136_);
									_tmp137_ = game;
									_tmp138_ = _g_object_ref0 (_tmp137_);
									self->games = g_list_append (self->games, _tmp138_);
									_tmp139_ = pgn_game_new ();
									_g_object_unref0 (game);
									game = _tmp139_;
									state = STATE_TAGS;
								}
							} else {
								gboolean _tmp140_ = FALSE;
								_tmp140_ = is_number;
								if (!_tmp140_) {
									gint _tmp141_ = 0;
									_tmp141_ = rav_level;
									if (_tmp141_ == 0) {
										PGNGame* _tmp142_ = NULL;
										const gchar* _tmp143_ = NULL;
										gchar* _tmp144_ = NULL;
										_tmp142_ = game;
										_tmp143_ = symbol;
										_tmp144_ = g_strdup (_tmp143_);
										_tmp142_->moves = g_list_append (_tmp142_->moves, _tmp144_);
									}
								}
							}
							_g_free0 (symbol);
						}
						break;
					}
					case STATE_PERIOD:
					{
						state = STATE_MOVE_TEXT;
						break;
					}
					case STATE_NAG:
					{
						gunichar _tmp145_ = 0U;
						gboolean _tmp146_ = FALSE;
						_tmp145_ = c;
						_tmp146_ = g_unichar_isdigit (_tmp145_);
						if (_tmp146_) {
							continue;
						} else {
							gsize _tmp147_ = 0UL;
							state = STATE_MOVE_TEXT;
							_tmp147_ = offset;
							offset = _tmp147_ - 1;
						}
						break;
					}
					case STATE_ERROR:
					{
						gsize char_offset = 0UL;
						gsize _tmp148_ = 0UL;
						gsize _tmp149_ = 0UL;
						FILE* _tmp150_ = NULL;
						gint _tmp151_ = 0;
						gsize _tmp152_ = 0UL;
						FILE* _tmp153_ = NULL;
						const gchar* _tmp154_ = NULL;
						gsize _tmp155_ = 0UL;
						gsize _tmp156_ = 0UL;
						gchar* _tmp157_ = NULL;
						gchar* _tmp158_ = NULL;
						FILE* _tmp164_ = NULL;
						_tmp148_ = offset;
						_tmp149_ = line_offset;
						char_offset = (_tmp148_ - _tmp149_) - 1;
						_tmp150_ = stderr;
						_tmp151_ = line;
						_tmp152_ = char_offset;
						fprintf (_tmp150_, "%d.%d: error: Unexpected character\n", _tmp151_, (gint) (_tmp152_ + 1));
						_tmp153_ = stderr;
						_tmp154_ = data;
						_tmp155_ = line_offset;
						_tmp156_ = offset;
						_tmp157_ = string_slice (_tmp154_, (glong) _tmp155_, (glong) _tmp156_);
						_tmp158_ = _tmp157_;
						fprintf (_tmp153_, "%s\n", _tmp158_);
						_g_free0 (_tmp158_);
						{
							gint i = 0;
							i = 0;
							{
								gboolean _tmp159_ = FALSE;
								_tmp159_ = TRUE;
								while (TRUE) {
									gint _tmp161_ = 0;
									gsize _tmp162_ = 0UL;
									FILE* _tmp163_ = NULL;
									if (!_tmp159_) {
										gint _tmp160_ = 0;
										_tmp160_ = i;
										i = _tmp160_ + 1;
									}
									_tmp159_ = FALSE;
									_tmp161_ = i;
									_tmp162_ = char_offset;
									if (!(((gsize) _tmp161_) < _tmp162_)) {
										break;
									}
									_tmp163_ = stderr;
									fprintf (_tmp163_, " ");
								}
							}
						}
						_tmp164_ = stderr;
						fprintf (_tmp164_, "^\n");
						_g_string_free0 (tag_value);
						_g_free0 (tag_name);
						_g_object_unref0 (game);
						return self;
					}
					default:
					break;
				}
			}
		}
	}
	_tmp166_ = game;
	_tmp167_ = _tmp166_->moves;
	_tmp168_ = g_list_length (_tmp167_);
	if (_tmp168_ > ((guint) 0)) {
		_tmp165_ = TRUE;
	} else {
		PGNGame* _tmp169_ = NULL;
		GHashTable* _tmp170_ = NULL;
		guint _tmp171_ = 0U;
		_tmp169_ = game;
		_tmp170_ = _tmp169_->tags;
		_tmp171_ = g_hash_table_size (_tmp170_);
		_tmp165_ = _tmp171_ > ((guint) 0);
	}
	if (_tmp165_) {
		PGNGame* _tmp172_ = NULL;
		PGNGame* _tmp173_ = NULL;
		_tmp172_ = game;
		_tmp173_ = _g_object_ref0 (_tmp172_);
		self->games = g_list_append (self->games, _tmp173_);
	}
	_tmp174_ = self->games;
	if (_tmp174_ == NULL) {
		GError* _tmp175_ = NULL;
		_tmp175_ = g_error_new_literal (PGN_ERROR, PGN_ERROR_LOAD_ERROR, "No games in PGN file");
		_inner_error_ = _tmp175_;
		if (_inner_error_->domain == PGN_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_string_free0 (tag_value);
			_g_free0 (tag_name);
			_g_object_unref0 (game);
			_g_object_unref0 (self);
			return NULL;
		} else {
			_g_string_free0 (tag_value);
			_g_free0 (tag_name);
			_g_object_unref0 (game);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_g_string_free0 (tag_value);
	_g_free0 (tag_name);
	_g_object_unref0 (game);
	return self;
}


PGN* pgn_new_from_string (const gchar* data, GError** error) {
	return pgn_construct_from_string (TYPE_PGN, data, error);
}


PGN* pgn_construct_from_file (GType object_type, GFile* file, GError** error) {
	PGN * self = NULL;
	guint8* contents = NULL;
	gint contents_length1 = 0;
	gint _contents_size_ = 0;
	GFile* _tmp0_ = NULL;
	guint8* _tmp1_ = NULL;
	gsize _tmp2_;
	guint8* _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (file != NULL, NULL);
	_tmp0_ = file;
	g_file_load_contents (_tmp0_, NULL, &_tmp1_, &_tmp2_, NULL, &_inner_error_);
	contents = (g_free (contents), NULL);
	contents = _tmp1_;
	contents_length1 = _tmp2_;
	_contents_size_ = contents_length1;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		contents = (g_free (contents), NULL);
		_g_object_unref0 (self);
		return NULL;
	}
	_tmp3_ = contents;
	_tmp3__length1 = contents_length1;
	self = (PGN*) pgn_construct_from_string (object_type, (const gchar*) _tmp3_, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		contents = (g_free (contents), NULL);
		_g_object_unref0 (self);
		return NULL;
	}
	contents = (g_free (contents), NULL);
	return self;
}


PGN* pgn_new_from_file (GFile* file, GError** error) {
	return pgn_construct_from_file (TYPE_PGN, file, error);
}


PGN* pgn_construct (GType object_type) {
	PGN * self = NULL;
	self = (PGN*) g_object_new (object_type, NULL);
	return self;
}


PGN* pgn_new (void) {
	return pgn_construct (TYPE_PGN);
}


static void pgn_class_init (PGNClass * klass) {
	pgn_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = pgn_finalize;
}


static void pgn_instance_init (PGN * self) {
}


static void pgn_finalize (GObject* obj) {
	PGN * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_PGN, PGN);
	__g_list_free__g_object_unref0_0 (self->games);
	G_OBJECT_CLASS (pgn_parent_class)->finalize (obj);
}


GType pgn_get_type (void) {
	static volatile gsize pgn_type_id__volatile = 0;
	if (g_once_init_enter (&pgn_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (PGNClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pgn_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PGN), 0, (GInstanceInitFunc) pgn_instance_init, NULL };
		GType pgn_type_id;
		pgn_type_id = g_type_register_static (G_TYPE_OBJECT, "PGN", &g_define_type_info, 0);
		g_once_init_leave (&pgn_type_id__volatile, pgn_type_id);
	}
	return pgn_type_id__volatile;
}



