/* main.c generated by valac 0.56.19, the Vala compiler
 * generated from main.vala, do not modify */

/* SPDX-License-Identifier: GPL-3.0-or-later*/

#include "graphs.h"
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

typedef enum  {
	GRAPHS_COLUMNS_DELIMITER_WHITESPACE,
	GRAPHS_COLUMNS_DELIMITER_TAB,
	GRAPHS_COLUMNS_DELIMITER_COLON,
	GRAPHS_COLUMNS_DELIMITER_SEMICOLON,
	GRAPHS_COLUMNS_DELIMITER_COMMA,
	GRAPHS_COLUMNS_DELIMITER_PERIOD,
	GRAPHS_COLUMNS_DELIMITER_CUSTOM
} GraphsColumnsDelimiter;

#define GRAPHS_TYPE_COLUMNS_DELIMITER (graphs_columns_delimiter_get_type ())
#define _g_free0(var) (var = (g_free (var), NULL))
typedef enum  {
	GRAPHS_COLUMNS_SEPARATOR_COMMA,
	GRAPHS_COLUMNS_SEPARATOR_PERIOD
} GraphsColumnsSeparator;

#define GRAPHS_TYPE_COLUMNS_SEPARATOR (graphs_columns_separator_get_type ())

VALA_EXTERN GType graphs_columns_delimiter_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gchar* graphs_columns_delimiter_friendly_string (GraphsColumnsDelimiter self);
VALA_EXTERN GraphsColumnsDelimiter graphs_columns_delimiter_parse (const gchar* delimiter);
VALA_EXTERN gchar* graphs_columns_delimiter_to_regex_pattern (GraphsColumnsDelimiter self,
                                                  const gchar* custom_delimiter,
                                                  GError** error);
VALA_EXTERN GType graphs_columns_separator_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gchar* graphs_columns_separator_friendly_string (GraphsColumnsSeparator self);
VALA_EXTERN gunichar graphs_columns_separator_as_unichar (GraphsColumnsSeparator self);
VALA_EXTERN GraphsColumnsSeparator graphs_columns_separator_parse (const gchar* separator);

GQuark
graphs_columns_parse_error_quark (void)
{
	return g_quark_from_static_string ("graphs-columns-parse-error-quark");
}

static GType
graphs_columns_parse_error_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_COLUMNS_PARSE_ERROR_INDEX_ERROR, "GRAPHS_COLUMNS_PARSE_ERROR_INDEX_ERROR", "index-error"}, {GRAPHS_COLUMNS_PARSE_ERROR_IMPORT_ERROR, "GRAPHS_COLUMNS_PARSE_ERROR_IMPORT_ERROR", "import-error"}, {GRAPHS_COLUMNS_PARSE_ERROR_INVALID_CONFIGURATION, "GRAPHS_COLUMNS_PARSE_ERROR_INVALID_CONFIGURATION", "invalid-configuration"}, {0, NULL, NULL}};
	GType graphs_columns_parse_error_type_id;
	graphs_columns_parse_error_type_id = g_enum_register_static ("GraphsColumnsParseError", values);
	return graphs_columns_parse_error_type_id;
}

GType
graphs_columns_parse_error_get_type (void)
{
	static volatile gsize graphs_columns_parse_error_type_id__once = 0;
	if (g_once_init_enter (&graphs_columns_parse_error_type_id__once)) {
		GType graphs_columns_parse_error_type_id;
		graphs_columns_parse_error_type_id = graphs_columns_parse_error_get_type_once ();
		g_once_init_leave (&graphs_columns_parse_error_type_id__once, graphs_columns_parse_error_type_id);
	}
	return graphs_columns_parse_error_type_id__once;
}

static gchar*
string_slice (const gchar* self,
              glong start,
              glong end)
{
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	if (start < ((glong) 0)) {
		start = string_length + start;
	}
	if (end < ((glong) 0)) {
		end = string_length + end;
	}
	if (start >= ((glong) 0)) {
		_tmp2_ = start <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	if (end >= ((glong) 0)) {
		_tmp3_ = end <= string_length;
	} else {
		_tmp3_ = FALSE;
	}
	g_return_val_if_fail (_tmp3_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	_tmp4_ = g_strndup (((gchar*) self) + start, (gsize) (end - start));
	result = _tmp4_;
	return result;
}

gchar*
graphs_columns_delimiter_friendly_string (GraphsColumnsDelimiter self)
{
	GEnumValue* _tmp0_;
	GEnumValue* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* result;
	_tmp0_ = g_enum_get_value (g_type_class_ref (GRAPHS_TYPE_COLUMNS_DELIMITER), self);
	_tmp1_ = g_enum_get_value (g_type_class_ref (GRAPHS_TYPE_COLUMNS_DELIMITER), self);
	_tmp2_ = strlen ((_tmp1_ != NULL) ? _tmp1_->value_name : NULL);
	_tmp3_ = _tmp2_;
	_tmp4_ = string_slice ((_tmp1_ != NULL) ? _tmp1_->value_name : NULL, (glong) 25, (glong) _tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_utf8_strdown (_tmp5_, (gssize) -1);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	result = _tmp7_;
	return result;
}

GraphsColumnsDelimiter
graphs_columns_delimiter_parse (const gchar* delimiter)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	static GQuark _tmp1_label4 = 0;
	static GQuark _tmp1_label5 = 0;
	static GQuark _tmp1_label6 = 0;
	GraphsColumnsDelimiter result;
	g_return_val_if_fail (delimiter != NULL, 0);
	_tmp0_ = delimiter;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("whitespace")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_COLUMNS_DELIMITER_WHITESPACE;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("tab")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_COLUMNS_DELIMITER_TAB;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("colon")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_COLUMNS_DELIMITER_COLON;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("semicolon")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_COLUMNS_DELIMITER_SEMICOLON;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label4) ? _tmp1_label4 : (_tmp1_label4 = g_quark_from_static_string ("comma")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_COLUMNS_DELIMITER_COMMA;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label5) ? _tmp1_label5 : (_tmp1_label5 = g_quark_from_static_string ("period")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_COLUMNS_DELIMITER_PERIOD;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label6) ? _tmp1_label6 : (_tmp1_label6 = g_quark_from_static_string ("custom")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_COLUMNS_DELIMITER_CUSTOM;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				g_assert_not_reached ();
			}
		}
	}
}

gchar*
graphs_columns_delimiter_to_regex_pattern (GraphsColumnsDelimiter self,
                                           const gchar* custom_delimiter,
                                           GError** error)
{
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (custom_delimiter != NULL, NULL);
	switch (self) {
		case GRAPHS_COLUMNS_DELIMITER_WHITESPACE:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup ("\\s+");
			result = _tmp0_;
			return result;
		}
		case GRAPHS_COLUMNS_DELIMITER_TAB:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("\\t");
			result = _tmp1_;
			return result;
		}
		case GRAPHS_COLUMNS_DELIMITER_COLON:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup (":");
			result = _tmp2_;
			return result;
		}
		case GRAPHS_COLUMNS_DELIMITER_SEMICOLON:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup (";");
			result = _tmp3_;
			return result;
		}
		case GRAPHS_COLUMNS_DELIMITER_COMMA:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup (",");
			result = _tmp4_;
			return result;
		}
		case GRAPHS_COLUMNS_DELIMITER_PERIOD:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup ("\\.");
			result = _tmp5_;
			return result;
		}
		case GRAPHS_COLUMNS_DELIMITER_CUSTOM:
		{
			gint _tmp6_;
			gint _tmp7_;
			gchar* _tmp9_;
			_tmp6_ = strlen (custom_delimiter);
			_tmp7_ = _tmp6_;
			if (_tmp7_ == 0) {
				GError* _tmp8_;
				_tmp8_ = g_error_new_literal (GRAPHS_COLUMNS_PARSE_ERROR, GRAPHS_COLUMNS_PARSE_ERROR_INVALID_CONFIGURATION, _ ("Custom delimiter cannot be empty"));
				_inner_error0_ = _tmp8_;
				if (_inner_error0_->domain == GRAPHS_COLUMNS_PARSE_ERROR) {
					g_propagate_error (error, _inner_error0_);
					return NULL;
				} else {
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return NULL;
				}
			}
			_tmp9_ = g_strdup (custom_delimiter);
			result = _tmp9_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

static GType
graphs_columns_delimiter_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_COLUMNS_DELIMITER_WHITESPACE, "GRAPHS_COLUMNS_DELIMITER_WHITESPACE", "whitespace"}, {GRAPHS_COLUMNS_DELIMITER_TAB, "GRAPHS_COLUMNS_DELIMITER_TAB", "tab"}, {GRAPHS_COLUMNS_DELIMITER_COLON, "GRAPHS_COLUMNS_DELIMITER_COLON", "colon"}, {GRAPHS_COLUMNS_DELIMITER_SEMICOLON, "GRAPHS_COLUMNS_DELIMITER_SEMICOLON", "semicolon"}, {GRAPHS_COLUMNS_DELIMITER_COMMA, "GRAPHS_COLUMNS_DELIMITER_COMMA", "comma"}, {GRAPHS_COLUMNS_DELIMITER_PERIOD, "GRAPHS_COLUMNS_DELIMITER_PERIOD", "period"}, {GRAPHS_COLUMNS_DELIMITER_CUSTOM, "GRAPHS_COLUMNS_DELIMITER_CUSTOM", "custom"}, {0, NULL, NULL}};
	GType graphs_columns_delimiter_type_id;
	graphs_columns_delimiter_type_id = g_enum_register_static ("GraphsColumnsDelimiter", values);
	return graphs_columns_delimiter_type_id;
}

GType
graphs_columns_delimiter_get_type (void)
{
	static volatile gsize graphs_columns_delimiter_type_id__once = 0;
	if (g_once_init_enter (&graphs_columns_delimiter_type_id__once)) {
		GType graphs_columns_delimiter_type_id;
		graphs_columns_delimiter_type_id = graphs_columns_delimiter_get_type_once ();
		g_once_init_leave (&graphs_columns_delimiter_type_id__once, graphs_columns_delimiter_type_id);
	}
	return graphs_columns_delimiter_type_id__once;
}

gchar*
graphs_columns_separator_friendly_string (GraphsColumnsSeparator self)
{
	GEnumValue* _tmp0_;
	GEnumValue* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* result;
	_tmp0_ = g_enum_get_value (g_type_class_ref (GRAPHS_TYPE_COLUMNS_SEPARATOR), self);
	_tmp1_ = g_enum_get_value (g_type_class_ref (GRAPHS_TYPE_COLUMNS_SEPARATOR), self);
	_tmp2_ = strlen ((_tmp1_ != NULL) ? _tmp1_->value_name : NULL);
	_tmp3_ = _tmp2_;
	_tmp4_ = string_slice ((_tmp1_ != NULL) ? _tmp1_->value_name : NULL, (glong) 25, (glong) _tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_utf8_strdown (_tmp5_, (gssize) -1);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	result = _tmp7_;
	return result;
}

gunichar
graphs_columns_separator_as_unichar (GraphsColumnsSeparator self)
{
	gchar _tmp0_ = '\0';
	gunichar result;
	if (self == GRAPHS_COLUMNS_SEPARATOR_COMMA) {
		_tmp0_ = ',';
	} else {
		_tmp0_ = '.';
	}
	result = (gunichar) _tmp0_;
	return result;
}

GraphsColumnsSeparator
graphs_columns_separator_parse (const gchar* separator)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	GraphsColumnsSeparator result;
	g_return_val_if_fail (separator != NULL, 0);
	_tmp0_ = separator;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("comma")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_COLUMNS_SEPARATOR_COMMA;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("period")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_COLUMNS_SEPARATOR_PERIOD;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				g_assert_not_reached ();
			}
		}
	}
}

static GType
graphs_columns_separator_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_COLUMNS_SEPARATOR_COMMA, "GRAPHS_COLUMNS_SEPARATOR_COMMA", "comma"}, {GRAPHS_COLUMNS_SEPARATOR_PERIOD, "GRAPHS_COLUMNS_SEPARATOR_PERIOD", "period"}, {0, NULL, NULL}};
	GType graphs_columns_separator_type_id;
	graphs_columns_separator_type_id = g_enum_register_static ("GraphsColumnsSeparator", values);
	return graphs_columns_separator_type_id;
}

GType
graphs_columns_separator_get_type (void)
{
	static volatile gsize graphs_columns_separator_type_id__once = 0;
	if (g_once_init_enter (&graphs_columns_separator_type_id__once)) {
		GType graphs_columns_separator_type_id;
		graphs_columns_separator_type_id = graphs_columns_separator_get_type_once ();
		g_once_init_leave (&graphs_columns_separator_type_id__once, graphs_columns_separator_type_id);
	}
	return graphs_columns_separator_type_id__once;
}

void
graphs_columns_item_settings_load_from_variant (GraphsColumnsItemSettings *self,
                                                GVariant* variant)
{
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	gboolean _tmp6_ = FALSE;
	gchar* _tmp7_ = NULL;
	g_return_if_fail (variant != NULL);
	g_variant_get (variant, "(iiiibbbs)", &_tmp0_, &_tmp1_, &_tmp2_, &_tmp3_, &_tmp4_, &_tmp5_, &_tmp6_, &_tmp7_, NULL);
	(*self).column_x = _tmp0_;
	(*self).column_y = _tmp1_;
	(*self).xerr_index = _tmp2_;
	(*self).yerr_index = _tmp3_;
	(*self).single_column = _tmp4_;
	(*self).use_xerr = _tmp5_;
	(*self).use_yerr = _tmp6_;
	_g_free0 ((*self).equation);
	(*self).equation = _tmp7_;
}

GVariant*
graphs_columns_item_settings_to_variant (GraphsColumnsItemSettings *self)
{
	const gchar* _tmp0_;
	GVariant* _tmp1_;
	GVariant* result;
	_tmp0_ = (*self).equation;
	_tmp1_ = g_variant_new ("(iiiibbbs)", (*self).column_x, (*self).column_y, (*self).xerr_index, (*self).yerr_index, (*self).single_column, (*self).use_xerr, (*self).use_yerr, _tmp0_, NULL);
	g_variant_ref_sink (_tmp1_);
	result = _tmp1_;
	return result;
}

void
graphs_columns_item_settings_copy (const GraphsColumnsItemSettings* self,
                                   GraphsColumnsItemSettings* dest)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	(*dest).column_x = (*self).column_x;
	(*dest).column_y = (*self).column_y;
	(*dest).xerr_index = (*self).xerr_index;
	(*dest).yerr_index = (*self).yerr_index;
	(*dest).single_column = (*self).single_column;
	(*dest).use_xerr = (*self).use_xerr;
	(*dest).use_yerr = (*self).use_yerr;
	_tmp0_ = (*self).equation;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 ((*dest).equation);
	(*dest).equation = _tmp1_;
}

void
graphs_columns_item_settings_destroy (GraphsColumnsItemSettings* self)
{
	_g_free0 ((*self).equation);
}

GraphsColumnsItemSettings*
graphs_columns_item_settings_dup (const GraphsColumnsItemSettings* self)
{
	GraphsColumnsItemSettings* dup;
	dup = g_new0 (GraphsColumnsItemSettings, 1);
	graphs_columns_item_settings_copy (self, dup);
	return dup;
}

void
graphs_columns_item_settings_free (GraphsColumnsItemSettings* self)
{
	graphs_columns_item_settings_destroy (self);
	g_free (self);
}

static GType
graphs_columns_item_settings_get_type_once (void)
{
	GType graphs_columns_item_settings_type_id;
	graphs_columns_item_settings_type_id = g_boxed_type_register_static ("GraphsColumnsItemSettings", (GBoxedCopyFunc) graphs_columns_item_settings_dup, (GBoxedFreeFunc) graphs_columns_item_settings_free);
	return graphs_columns_item_settings_type_id;
}

GType
graphs_columns_item_settings_get_type (void)
{
	static volatile gsize graphs_columns_item_settings_type_id__once = 0;
	if (g_once_init_enter (&graphs_columns_item_settings_type_id__once)) {
		GType graphs_columns_item_settings_type_id;
		graphs_columns_item_settings_type_id = graphs_columns_item_settings_get_type_once ();
		g_once_init_leave (&graphs_columns_item_settings_type_id__once, graphs_columns_item_settings_type_id);
	}
	return graphs_columns_item_settings_type_id__once;
}

