1
/* ai-profile.c generated by valac 0.12.0, the Vala compiler
2
* generated from ai-profile.vala, do not modify */
6
#include <glib-object.h>
9
#include <gobject/gvaluecollector.h>
12
#define TYPE_AI_PROFILE (ai_profile_get_type ())
13
#define AI_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_AI_PROFILE, AIProfile))
14
#define AI_PROFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_AI_PROFILE, AIProfileClass))
15
#define IS_AI_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_AI_PROFILE))
16
#define IS_AI_PROFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_AI_PROFILE))
17
#define AI_PROFILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_AI_PROFILE, AIProfileClass))
19
typedef struct _AIProfile AIProfile;
20
typedef struct _AIProfileClass AIProfileClass;
21
typedef struct _AIProfilePrivate AIProfilePrivate;
22
#define _g_free0(var) (var = (g_free (var), NULL))
23
typedef struct _ParamSpecAIProfile ParamSpecAIProfile;
24
#define _g_key_file_free0(var) ((var == NULL) ? NULL : (var = (g_key_file_free (var), NULL)))
25
#define __g_list_free__ai_profile_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__ai_profile_unref0_ (var), NULL)))
26
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
27
#define _ai_profile_unref0(var) ((var == NULL) ? NULL : (var = (ai_profile_unref (var), NULL)))
30
GTypeInstance parent_instance;
31
volatile int ref_count;
32
AIProfilePrivate * priv;
39
gint easy_options_length1;
40
gchar** normal_options;
41
gint normal_options_length1;
43
gint hard_options_length1;
46
struct _AIProfileClass {
47
GTypeClass parent_class;
48
void (*finalize) (AIProfile *self);
51
struct _ParamSpecAIProfile {
52
GParamSpec parent_instance;
56
static gpointer ai_profile_parent_class = NULL;
58
gpointer ai_profile_ref (gpointer instance);
59
void ai_profile_unref (gpointer instance);
60
GParamSpec* param_spec_ai_profile (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
61
void value_set_ai_profile (GValue* value, gpointer v_object);
62
void value_take_ai_profile (GValue* value, gpointer v_object);
63
gpointer value_get_ai_profile (const GValue* value);
64
GType ai_profile_get_type (void) G_GNUC_CONST;
66
AI_PROFILE_DUMMY_PROPERTY
68
AIProfile* ai_profile_new (void);
69
AIProfile* ai_profile_construct (GType object_type);
70
static void ai_profile_finalize (AIProfile* obj);
71
GList* load_ai_profiles (const gchar* filename);
72
static void _ai_profile_unref0_ (gpointer var);
73
static void _g_list_free__ai_profile_unref0_ (GList* self);
74
gchar** load_options (GKeyFile* file, const gchar* name, const gchar* difficulty, int* result_length1, GError** error);
75
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
76
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
79
AIProfile* ai_profile_construct (GType object_type) {
80
AIProfile* self = NULL;
81
self = (AIProfile*) g_type_create_instance (object_type);
86
AIProfile* ai_profile_new (void) {
87
return ai_profile_construct (TYPE_AI_PROFILE);
91
static void value_ai_profile_init (GValue* value) {
92
value->data[0].v_pointer = NULL;
96
static void value_ai_profile_free_value (GValue* value) {
97
if (value->data[0].v_pointer) {
98
ai_profile_unref (value->data[0].v_pointer);
103
static void value_ai_profile_copy_value (const GValue* src_value, GValue* dest_value) {
104
if (src_value->data[0].v_pointer) {
105
dest_value->data[0].v_pointer = ai_profile_ref (src_value->data[0].v_pointer);
107
dest_value->data[0].v_pointer = NULL;
112
static gpointer value_ai_profile_peek_pointer (const GValue* value) {
113
return value->data[0].v_pointer;
117
static gchar* value_ai_profile_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
118
if (collect_values[0].v_pointer) {
120
object = collect_values[0].v_pointer;
121
if (object->parent_instance.g_class == NULL) {
122
return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
123
} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
124
return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
126
value->data[0].v_pointer = ai_profile_ref (object);
128
value->data[0].v_pointer = NULL;
134
static gchar* value_ai_profile_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
135
AIProfile** object_p;
136
object_p = collect_values[0].v_pointer;
138
return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
140
if (!value->data[0].v_pointer) {
142
} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
143
*object_p = value->data[0].v_pointer;
145
*object_p = ai_profile_ref (value->data[0].v_pointer);
151
GParamSpec* param_spec_ai_profile (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
152
ParamSpecAIProfile* spec;
153
g_return_val_if_fail (g_type_is_a (object_type, TYPE_AI_PROFILE), NULL);
154
spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
155
G_PARAM_SPEC (spec)->value_type = object_type;
156
return G_PARAM_SPEC (spec);
160
gpointer value_get_ai_profile (const GValue* value) {
161
g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_AI_PROFILE), NULL);
162
return value->data[0].v_pointer;
166
void value_set_ai_profile (GValue* value, gpointer v_object) {
168
g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_AI_PROFILE));
169
old = value->data[0].v_pointer;
171
g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_AI_PROFILE));
172
g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
173
value->data[0].v_pointer = v_object;
174
ai_profile_ref (value->data[0].v_pointer);
176
value->data[0].v_pointer = NULL;
179
ai_profile_unref (old);
184
void value_take_ai_profile (GValue* value, gpointer v_object) {
186
g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_AI_PROFILE));
187
old = value->data[0].v_pointer;
189
g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_AI_PROFILE));
190
g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
191
value->data[0].v_pointer = v_object;
193
value->data[0].v_pointer = NULL;
196
ai_profile_unref (old);
201
static void ai_profile_class_init (AIProfileClass * klass) {
202
ai_profile_parent_class = g_type_class_peek_parent (klass);
203
AI_PROFILE_CLASS (klass)->finalize = ai_profile_finalize;
207
static void ai_profile_instance_init (AIProfile * self) {
209
_tmp0_ = g_strdup ("");
215
static void ai_profile_finalize (AIProfile* obj) {
217
self = AI_PROFILE (obj);
218
_g_free0 (self->name);
219
_g_free0 (self->protocol);
220
_g_free0 (self->binary);
221
_g_free0 (self->path);
222
_g_free0 (self->args);
223
self->easy_options = (_vala_array_free (self->easy_options, self->easy_options_length1, (GDestroyNotify) g_free), NULL);
224
self->normal_options = (_vala_array_free (self->normal_options, self->normal_options_length1, (GDestroyNotify) g_free), NULL);
225
self->hard_options = (_vala_array_free (self->hard_options, self->hard_options_length1, (GDestroyNotify) g_free), NULL);
229
GType ai_profile_get_type (void) {
230
static volatile gsize ai_profile_type_id__volatile = 0;
231
if (g_once_init_enter (&ai_profile_type_id__volatile)) {
232
static const GTypeValueTable g_define_type_value_table = { value_ai_profile_init, value_ai_profile_free_value, value_ai_profile_copy_value, value_ai_profile_peek_pointer, "p", value_ai_profile_collect_value, "p", value_ai_profile_lcopy_value };
233
static const GTypeInfo g_define_type_info = { sizeof (AIProfileClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ai_profile_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (AIProfile), 0, (GInstanceInitFunc) ai_profile_instance_init, &g_define_type_value_table };
234
static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
235
GType ai_profile_type_id;
236
ai_profile_type_id = g_type_register_fundamental (g_type_fundamental_next (), "AIProfile", &g_define_type_info, &g_define_type_fundamental_info, 0);
237
g_once_init_leave (&ai_profile_type_id__volatile, ai_profile_type_id);
239
return ai_profile_type_id__volatile;
243
gpointer ai_profile_ref (gpointer instance) {
246
g_atomic_int_inc (&self->ref_count);
251
void ai_profile_unref (gpointer instance) {
254
if (g_atomic_int_dec_and_test (&self->ref_count)) {
255
AI_PROFILE_GET_CLASS (self)->finalize (self);
256
g_type_free_instance ((GTypeInstance *) self);
261
static void _ai_profile_unref0_ (gpointer var) {
262
(var == NULL) ? NULL : (var = (ai_profile_unref (var), NULL));
266
static void _g_list_free__ai_profile_unref0_ (GList* self) {
267
g_list_foreach (self, (GFunc) _ai_profile_unref0_, NULL);
272
static gpointer _ai_profile_ref0 (gpointer self) {
273
return self ? ai_profile_ref (self) : NULL;
277
GList* load_ai_profiles (const gchar* filename) {
278
GList* result = NULL;
280
GKeyFile* _tmp0_ = NULL;
283
gchar** _tmp2_ = NULL;
284
GError * _inner_error_ = NULL;
285
g_return_val_if_fail (filename != NULL, NULL);
287
_tmp0_ = g_key_file_new ();
289
g_key_file_load_from_file (file, filename, G_KEY_FILE_NONE, &_inner_error_);
290
if (_inner_error_ != NULL) {
291
if (_inner_error_->domain == G_KEY_FILE_ERROR) {
292
goto __catch7_g_key_file_error;
294
if (_inner_error_->domain == G_FILE_ERROR) {
295
goto __catch7_g_file_error;
297
_g_key_file_free0 (file);
298
__g_list_free__ai_profile_unref0_0 (profiles);
299
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);
300
g_clear_error (&_inner_error_);
304
__catch7_g_key_file_error:
308
_inner_error_ = NULL;
309
g_warning ("ai-profile.vala:24: Failed to load AI profiles: %s", e->message);
312
_g_key_file_free0 (file);
316
__catch7_g_file_error:
320
_inner_error_ = NULL;
321
g_warning ("ai-profile.vala:29: Failed to load AI profiles: %s", e->message);
324
_g_key_file_free0 (file);
328
if (_inner_error_ != NULL) {
329
_g_key_file_free0 (file);
330
__g_list_free__ai_profile_unref0_0 (profiles);
331
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);
332
g_clear_error (&_inner_error_);
335
_tmp2_ = g_key_file_get_groups (file, &_tmp1_);
337
gchar** name_collection;
338
int name_collection_length1;
340
name_collection = _tmp2_;
341
name_collection_length1 = _tmp1_;
342
for (name_it = 0; name_it < _tmp1_; name_it = name_it + 1) {
345
_tmp3_ = g_strdup (name_collection[name_it]);
348
AIProfile* _tmp4_ = NULL;
351
gchar* _tmp6_ = NULL;
353
gchar* _tmp8_ = NULL;
358
gchar** _tmp15_ = NULL;
360
gint _tmp16__length1;
363
gchar** _tmp18_ = NULL;
365
gint _tmp19__length1;
368
gchar** _tmp21_ = NULL;
370
gint _tmp22__length1;
372
gchar* _tmp23_ = NULL;
374
g_debug ("ai-profile.vala:35: Loading AI profile %s", name);
375
_tmp4_ = ai_profile_new ();
377
_tmp5_ = g_strdup (name);
378
_g_free0 (profile->name);
379
profile->name = _tmp5_;
380
_tmp6_ = g_key_file_get_value (file, name, "protocol", &_inner_error_);
382
if (_inner_error_ != NULL) {
383
if (_inner_error_->domain == G_KEY_FILE_ERROR) {
384
goto __catch8_g_key_file_error;
386
_ai_profile_unref0 (profile);
388
name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
389
_g_key_file_free0 (file);
390
__g_list_free__ai_profile_unref0_0 (profiles);
391
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);
392
g_clear_error (&_inner_error_);
395
_g_free0 (profile->protocol);
396
profile->protocol = _tmp7_;
397
_tmp8_ = g_key_file_get_value (file, name, "binary", &_inner_error_);
399
if (_inner_error_ != NULL) {
400
if (_inner_error_->domain == G_KEY_FILE_ERROR) {
401
goto __catch8_g_key_file_error;
403
_ai_profile_unref0 (profile);
405
name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
406
_g_key_file_free0 (file);
407
__g_list_free__ai_profile_unref0_0 (profiles);
408
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);
409
g_clear_error (&_inner_error_);
412
_g_free0 (profile->binary);
413
profile->binary = _tmp9_;
414
_tmp10_ = g_key_file_has_key (file, name, "args", &_inner_error_);
416
if (_inner_error_ != NULL) {
417
if (_inner_error_->domain == G_KEY_FILE_ERROR) {
418
goto __catch8_g_key_file_error;
420
_ai_profile_unref0 (profile);
422
name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
423
_g_key_file_free0 (file);
424
__g_list_free__ai_profile_unref0_0 (profiles);
425
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);
426
g_clear_error (&_inner_error_);
430
gchar* _tmp12_ = NULL;
432
_tmp12_ = g_key_file_get_value (file, name, "args", &_inner_error_);
434
if (_inner_error_ != NULL) {
435
if (_inner_error_->domain == G_KEY_FILE_ERROR) {
436
goto __catch8_g_key_file_error;
438
_ai_profile_unref0 (profile);
440
name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
441
_g_key_file_free0 (file);
442
__g_list_free__ai_profile_unref0_0 (profiles);
443
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);
444
g_clear_error (&_inner_error_);
447
_g_free0 (profile->args);
448
profile->args = _tmp13_;
450
_tmp15_ = load_options (file, name, "easy", &_tmp14_, &_inner_error_);
452
_tmp16__length1 = _tmp14_;
453
__tmp16__size_ = _tmp14_;
454
if (_inner_error_ != NULL) {
455
if (_inner_error_->domain == G_KEY_FILE_ERROR) {
456
goto __catch8_g_key_file_error;
458
_ai_profile_unref0 (profile);
460
name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
461
_g_key_file_free0 (file);
462
__g_list_free__ai_profile_unref0_0 (profiles);
463
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);
464
g_clear_error (&_inner_error_);
467
profile->easy_options = (_vala_array_free (profile->easy_options, profile->easy_options_length1, (GDestroyNotify) g_free), NULL);
468
profile->easy_options = _tmp16_;
469
profile->easy_options_length1 = _tmp16__length1;
470
_tmp18_ = load_options (file, name, "normal", &_tmp17_, &_inner_error_);
472
_tmp19__length1 = _tmp17_;
473
__tmp19__size_ = _tmp17_;
474
if (_inner_error_ != NULL) {
475
if (_inner_error_->domain == G_KEY_FILE_ERROR) {
476
goto __catch8_g_key_file_error;
478
_ai_profile_unref0 (profile);
480
name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
481
_g_key_file_free0 (file);
482
__g_list_free__ai_profile_unref0_0 (profiles);
483
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);
484
g_clear_error (&_inner_error_);
487
profile->normal_options = (_vala_array_free (profile->normal_options, profile->normal_options_length1, (GDestroyNotify) g_free), NULL);
488
profile->normal_options = _tmp19_;
489
profile->normal_options_length1 = _tmp19__length1;
490
_tmp21_ = load_options (file, name, "hard", &_tmp20_, &_inner_error_);
492
_tmp22__length1 = _tmp20_;
493
__tmp22__size_ = _tmp20_;
494
if (_inner_error_ != NULL) {
495
if (_inner_error_->domain == G_KEY_FILE_ERROR) {
496
goto __catch8_g_key_file_error;
498
_ai_profile_unref0 (profile);
500
name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
501
_g_key_file_free0 (file);
502
__g_list_free__ai_profile_unref0_0 (profiles);
503
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);
504
g_clear_error (&_inner_error_);
507
profile->hard_options = (_vala_array_free (profile->hard_options, profile->hard_options_length1, (GDestroyNotify) g_free), NULL);
508
profile->hard_options = _tmp22_;
509
profile->hard_options_length1 = _tmp22__length1;
511
__catch8_g_key_file_error:
515
_inner_error_ = NULL;
517
_ai_profile_unref0 (profile);
522
if (_inner_error_ != NULL) {
523
_ai_profile_unref0 (profile);
525
name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
526
_g_key_file_free0 (file);
527
__g_list_free__ai_profile_unref0_0 (profiles);
528
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);
529
g_clear_error (&_inner_error_);
532
_tmp23_ = g_find_program_in_path (profile->binary);
537
_tmp24_ = g_strdup (path);
538
_g_free0 (profile->path);
539
profile->path = _tmp24_;
540
_tmp25_ = _ai_profile_ref0 (profile);
541
profiles = g_list_append (profiles, _tmp25_);
544
_ai_profile_unref0 (profile);
548
name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
551
_g_key_file_free0 (file);
556
gchar** load_options (GKeyFile* file, const gchar* name, const gchar* difficulty, int* result_length1, GError** error) {
557
gchar** result = NULL;
559
gchar** _tmp5_ = NULL;
561
gint options_length1;
564
GError * _inner_error_ = NULL;
565
g_return_val_if_fail (file != NULL, NULL);
566
g_return_val_if_fail (name != NULL, NULL);
567
g_return_val_if_fail (difficulty != NULL, NULL);
570
gchar* _tmp0_ = NULL;
575
_tmp0_ = g_strdup_printf ("option-%s-%d", difficulty, count);
577
_tmp2_ = g_key_file_has_key (file, name, _tmp1_, &_inner_error_);
581
if (_inner_error_ != NULL) {
582
if (_inner_error_->domain == G_KEY_FILE_ERROR) {
583
g_propagate_error (error, _inner_error_);
586
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);
587
g_clear_error (&_inner_error_);
596
_tmp5_ = g_new0 (gchar*, count + 1);
598
options_length1 = count;
599
_options_size_ = count;
607
gchar* _tmp7_ = NULL;
609
gchar* _tmp9_ = NULL;
620
_tmp7_ = g_strdup_printf ("option-%s-%d", difficulty, i);
622
_tmp9_ = g_key_file_get_value (file, name, _tmp8_, &_inner_error_);
626
if (_inner_error_ != NULL) {
627
if (_inner_error_->domain == G_KEY_FILE_ERROR) {
628
g_propagate_error (error, _inner_error_);
629
options = (_vala_array_free (options, options_length1, (GDestroyNotify) g_free), NULL);
632
options = (_vala_array_free (options, options_length1, (GDestroyNotify) g_free), NULL);
633
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);
634
g_clear_error (&_inner_error_);
639
_g_free0 (options[i]);
640
options[i] = _tmp12_;
645
*result_length1 = options_length1;
651
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
652
if ((array != NULL) && (destroy_func != NULL)) {
654
for (i = 0; i < array_length; i = i + 1) {
655
if (((gpointer*) array)[i] != NULL) {
656
destroy_func (((gpointer*) array)[i]);
663
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
664
_vala_array_destroy (array, array_length, destroy_func);