~ubuntu-branches/ubuntu/edgy/ggz-client-libs/edgy

« back to all changes in this revision

Viewing changes to ggzcore/module.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Eisentraut, Josef Spillner, Peter Eisentraut
  • Date: 2006-09-09 13:37:14 UTC
  • mfrom: (2.1.2 edgy)
  • Revision ID: james.westby@ubuntu.com-20060909133714-q49a9kvjfkc0wcc3
Tags: 0.0.13-3
[ Josef Spillner ]
* Change ggzcore-bin dependency from ggzmod to recommends from ggzcore
  (closes: #384671).

[ Peter Eisentraut ]
* Make package dependencies binNMU-safe through use of ${binary:Version}
  (closes: #386126)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * Author: Brent Hendricks
4
4
 * Project: GGZ Core Client Lib
5
5
 * Date: 11/23/00
6
 
 * $Id: module.c,v 1.24 2002/11/05 10:18:41 jdorje Exp $
 
6
 * $Id: module.c 7889 2006-03-07 09:57:32Z josef $
7
7
 *
8
8
 * This fils contains functions for handling client-side game modules
9
9
 *
10
10
 * Copyright (C) 2000 Brent Hendricks.
11
11
 *
12
 
 * This program is free software; you can redistribute it and/or modify
13
 
 * it under the terms of the GNU General Public License as published by
14
 
 * the Free Software Foundation; either version 2 of the License, or
15
 
 * (at your option) any later version.
16
 
 *
17
 
 * This program is distributed in the hope that it will be useful,
 
12
 * This library is free software; you can redistribute it and/or
 
13
 * modify it under the terms of the GNU Lesser General Public
 
14
 * License as published by the Free Software Foundation; either
 
15
 * version 2.1 of the License, or (at your option) any later version.
 
16
 * 
 
17
 * This library is distributed in the hope that it will be useful,
18
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 
 * GNU General Public License for more details.
21
 
 *
22
 
 * You should have received a copy of the GNU General Public License
23
 
 * along with this program; if not, write to the Free Software
24
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
20
 * Lesser General Public License for more details.
 
21
 * 
 
22
 * You should have received a copy of the GNU Lesser General Public
 
23
 * License along with this library; if not, write to the Free Software
 
24
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25
25
 */
26
26
 
27
27
#ifdef HAVE_CONFIG_H
28
 
#  include <config.h>           /* Site-specific config */
 
28
#  include <config.h>   /* Site-specific config */
29
29
#endif
30
30
 
31
31
#include <stdlib.h>
38
38
 
39
39
#define GGZ_MOD_RC "ggz.modules"
40
40
 
41
 
       
 
41
 
 
42
/* Structure describing particular client-side game module */
 
43
struct _GGZModule {
 
44
 
 
45
        /* Name of module */
 
46
        const char *name;
 
47
 
 
48
        /* Game module version */
 
49
        const char *version;
 
50
 
 
51
        /* Protocol engine implemented */
 
52
        const char *prot_engine;
 
53
 
 
54
        /* Protocol version implemented */
 
55
        const char *prot_version;
 
56
 
 
57
        /* Supported games */
 
58
        char **games;
 
59
 
 
60
        /* Module author */
 
61
        const char *author;
 
62
 
 
63
        /* Native frontend */
 
64
        const char *frontend;
 
65
 
 
66
        /* Hopepage for this module */
 
67
        const char *url;
 
68
 
 
69
        /* Commandline for executing module */
 
70
        char **argv;
 
71
 
 
72
        /* Path to icon for this game module */
 
73
        const char *icon;
 
74
 
 
75
        /* Path to help file */
 
76
        const char *help;
 
77
 
 
78
        /* Preferred runtime environment */
 
79
        GGZModuleEnvironment environment;
 
80
};
 
81
 
42
82
/* List of modules */
43
83
static GGZList *module_list;
44
84
static unsigned int num_modules;
45
85
static int mod_handle = -1;
 
86
static int embedded_module = 0;
46
87
 
47
88
/* static internal functions */
48
 
static struct _GGZModule* _ggzcore_module_new(void);
 
89
static GGZModule *_ggzcore_module_new(void);
49
90
#if 0
50
 
static void _ggzcore_module_init(struct _GGZModule *module,
 
91
static void _ggzcore_module_init(GGZModule * module,
51
92
                                 const char *name,
52
93
                                 const char *version,
53
94
                                 const char *prot_engine,
59
100
                                 const char *icon_path,
60
101
                                 const char *help_path);
61
102
#endif /* #if 0 */
62
 
static void _ggzcore_module_free(struct _GGZModule *module);
63
 
static void _ggzcore_module_read(struct _GGZModule *mod, char *id);
64
 
static int _ggzcore_module_add(struct _GGZModule *module);
 
103
static void _ggzcore_module_free(GGZModule * module);
 
104
static void _ggzcore_module_read(GGZModule * mod, char *id);
 
105
static int _ggzcore_module_add(GGZModule * module);
65
106
 
66
 
static char* _ggzcore_module_conf_filename(void);
67
 
static void _ggzcore_module_print(struct _GGZModule*);
 
107
static char *_ggzcore_module_conf_filename(void);
 
108
static void _ggzcore_module_print(const GGZModule *);
68
109
static void _ggzcore_module_list_print(void);
69
110
/* Utility functions used by ggz_list */
70
111
static void _ggz_free_chars(char **argv);
71
 
static int   _ggzcore_module_compare(void *p, void *q);
 
112
static int _ggzcore_module_compare(const void *p, const void *q);
72
113
#if 0
73
 
static void* _ggzcore_module_create(void* p);
 
114
static void *_ggzcore_module_create(void *p);
74
115
#endif /* #if 0 */
75
 
static void  _ggzcore_module_destroy(void* p);
 
116
static void _ggzcore_module_destroy(void *p);
76
117
 
77
118
 
78
119
/* Publicly exported functions */
86
127
 
87
128
 
88
129
/* Returns how many modules support this game and protocol */
89
 
int ggzcore_module_get_num_by_type(const char *game, 
90
 
                                   const char *engine,
91
 
                                   const char *version)
 
130
int ggzcore_module_get_num_by_type(const char *game,
 
131
                                   const char *engine, const char *version)
92
132
{
93
133
        /* A NULL version means any version */
94
134
        if (!game || !engine)
99
139
 
100
140
 
101
141
/* Returns n-th module that supports this game and protocol */
102
 
GGZModule* ggzcore_module_get_nth_by_type(const char *game, 
 
142
GGZModule *ggzcore_module_get_nth_by_type(const char *game,
103
143
                                          const char *engine,
104
144
                                          const char *version,
105
145
                                          const unsigned int num)
115
155
/* This adds a local module to the list.  It returns 0 if successful or
116
156
   -1 on failure. */
117
157
int ggzcore_module_add(const char *name,
118
 
                       const char *version,
119
 
                       const char *prot_engine,
120
 
                       const char *prot_version,
121
 
                       const char *author,
 
158
                       const char *version,
 
159
                       const char *prot_engine,
 
160
                       const char *prot_version,
 
161
                       const char *author,
122
162
                       const char *frontend,
123
163
                       const char *url,
124
164
                       const char *exe_path,
125
165
                       const char *icon_path,
126
 
                       const char *help_path)
 
166
                       const char *help_path,
 
167
                       GGZModuleEnvironment environment)
127
168
{
128
169
        return -1;
129
170
}
130
171
 
131
172
 
132
 
/* This attempts to launch the specified module and returns 0 is
133
 
   successful or -1 on error. */
134
 
int ggzcore_module_launch(GGZModule *module)
135
 
{
136
 
        if (!module)
137
 
                return -1;
138
 
        
139
 
        return _ggzcore_module_launch(module);  
140
 
}
141
 
 
142
 
 
143
173
/* These functions lookup a particular property of a module.  I've added
144
174
   icon to the list we discussed at the meeting.  This is an optional xpm
145
175
   file that the module can provide to use for representing the game
146
176
   graphically.*/
147
 
const char * ggzcore_module_get_name(GGZModule *module)
148
 
{       
 
177
const char *ggzcore_module_get_name(GGZModule * module)
 
178
{
149
179
        if (!module)
150
180
                return NULL;
151
181
 
153
183
}
154
184
 
155
185
 
156
 
const char * ggzcore_module_get_version(GGZModule *module)
157
 
{       
 
186
const char *ggzcore_module_get_version(GGZModule * module)
 
187
{
158
188
        if (!module)
159
189
                return NULL;
160
190
 
162
192
}
163
193
 
164
194
 
165
 
const char * ggzcore_module_get_prot_engine(GGZModule *module)
166
 
{       
 
195
const char *ggzcore_module_get_prot_engine(GGZModule * module)
 
196
{
167
197
        if (!module)
168
198
                return NULL;
169
199
 
171
201
}
172
202
 
173
203
 
174
 
const char * ggzcore_module_get_prot_version(GGZModule *module)
175
 
{       
 
204
const char *ggzcore_module_get_prot_version(GGZModule * module)
 
205
{
176
206
        if (!module)
177
207
                return NULL;
178
208
 
180
210
}
181
211
 
182
212
 
183
 
const char * ggzcore_module_get_author(GGZModule *module)
184
 
{       
 
213
const char *ggzcore_module_get_author(GGZModule * module)
 
214
{
185
215
        if (!module)
186
216
                return NULL;
187
217
 
189
219
}
190
220
 
191
221
 
192
 
const char * ggzcore_module_get_frontend(GGZModule *module)
193
 
{       
 
222
const char *ggzcore_module_get_frontend(GGZModule * module)
 
223
{
194
224
        if (!module)
195
225
                return NULL;
196
226
 
198
228
}
199
229
 
200
230
 
201
 
const char * ggzcore_module_get_url(GGZModule *module)
202
 
{       
 
231
const char *ggzcore_module_get_url(GGZModule * module)
 
232
{
203
233
        if (!module)
204
234
                return NULL;
205
235
 
207
237
}
208
238
 
209
239
 
210
 
const char * ggzcore_module_get_icon_path(GGZModule *module)
211
 
{       
 
240
const char *ggzcore_module_get_icon_path(GGZModule * module)
 
241
{
212
242
        if (!module)
213
243
                return NULL;
214
244
 
216
246
}
217
247
 
218
248
 
219
 
const char * ggzcore_module_get_help_path(GGZModule *module)
220
 
{       
 
249
const char *ggzcore_module_get_help_path(GGZModule * module)
 
250
{
221
251
        if (!module)
222
252
                return NULL;
223
253
 
225
255
}
226
256
 
227
257
 
228
 
char** ggzcore_module_get_argv(GGZModule *module)
229
 
{       
 
258
char **ggzcore_module_get_argv(GGZModule * module)
 
259
{
230
260
        if (!module)
231
261
                return NULL;
232
262
 
234
264
}
235
265
 
236
266
 
 
267
GGZModuleEnvironment ggzcore_module_get_environment(GGZModule * module)
 
268
{
 
269
        if (!module)
 
270
                return GGZ_ENVIRONMENT_PASSIVE;
 
271
 
 
272
        return _ggzcore_module_get_environment(module);
 
273
}
 
274
 
237
275
/* Internal library functions (prototypes in module.h) */
238
276
 
239
277
 
250
288
        char **ids;
251
289
        char **games;
252
290
        int i, j, count_types, count_modules, status;
253
 
        struct _GGZModule *module;
 
291
        GGZModule *module;
254
292
 
255
293
        if (mod_handle != -1) {
256
 
                ggz_debug(GGZCORE_DBG_MODULE, "module_setup() called twice");
 
294
                ggz_debug(GGZCORE_DBG_MODULE,
 
295
                          "module_setup() called twice");
257
296
                return -1;
258
297
        }
259
298
 
260
 
        
 
299
 
261
300
        module_list = ggz_list_create(_ggzcore_module_compare, NULL,
262
301
                                      _ggzcore_module_destroy, 0);
263
302
        num_modules = 0;
267
306
        mod_handle = ggz_conf_parse(file, GGZ_CONF_RDONLY);
268
307
        /* Free up space taken by name */
269
308
        ggz_free(file);
270
 
        
 
309
 
271
310
        if (mod_handle == -1) {
272
311
                ggz_debug(GGZCORE_DBG_MODULE,
273
312
                          "Unable to load module conffile");
274
313
                return -1;
275
314
        }
276
 
        
 
315
 
277
316
        /* Read in list of supported gametypes */
278
 
        status = ggz_conf_read_list(mod_handle, "Games", "*Engines*", 
 
317
        status = ggz_conf_read_list(mod_handle, "Games", "*Engines*",
279
318
                                    &count_types, &games);
280
319
        if (status < 0) {
281
320
                ggz_debug(GGZCORE_DBG_MODULE, "Couldn't read engine list");
282
321
                return -1;
283
 
        }       
 
322
        }
284
323
        ggz_debug(GGZCORE_DBG_MODULE,
285
324
                  "%d game engines supported", count_types);
286
 
        
 
325
 
287
326
        for (i = 0; i < count_types; i++) {
288
 
                status = ggz_conf_read_list(mod_handle, "Games", games[i], 
 
327
                status = ggz_conf_read_list(mod_handle, "Games", games[i],
289
328
                                            &count_modules, &ids);
290
 
                                            
 
329
 
291
330
 
292
331
                ggz_debug(GGZCORE_DBG_MODULE,
293
332
                          "%d modules for %s", count_modules, games[i]);
296
335
                        module = _ggzcore_module_new();
297
336
                        _ggzcore_module_read(module, ids[j]);
298
337
                        _ggzcore_module_add(module);
299
 
                        ggz_debug(GGZCORE_DBG_MODULE, "Module %d: %s", j, 
300
 
                                      ids[j]);
 
338
                        ggz_debug(GGZCORE_DBG_MODULE, "Module %d: %s", j,
 
339
                                  ids[j]);
301
340
 
302
341
                }
303
 
                
 
342
 
304
343
                _ggz_free_chars(ids);
305
344
        }
306
345
 
307
346
        _ggz_free_chars(games);
308
347
 
309
348
        _ggzcore_module_list_print();
310
 
        
 
349
 
311
350
        return 0;
312
351
}
313
352
 
318
357
}
319
358
 
320
359
 
 
360
void _ggzcore_module_set_embedded(void)
 
361
{
 
362
        embedded_module = 1;
 
363
}
 
364
 
 
365
 
 
366
int _ggzcore_module_is_embedded(void)
 
367
{
 
368
        return embedded_module;
 
369
}
 
370
 
 
371
 
321
372
/* FIXME: do this right.  We should parse through module_list not
322
373
   re-read the config file */
323
 
int _ggzcore_module_get_num_by_type(const char *game, 
 
374
int _ggzcore_module_get_num_by_type(const char *game,
324
375
                                    const char *engine,
325
376
                                    const char *version)
326
377
{
327
378
        int count, status, i, numcount;
328
379
        char **ids;
329
 
        struct _GGZModule module;
 
380
        GGZModule module;
330
381
 
331
382
        /* Get total count for this engine (regardless of version) */
332
 
        status = ggz_conf_read_list(mod_handle, "Games", engine, &count, &ids);
333
 
                                    
 
383
        status =
 
384
            ggz_conf_read_list(mod_handle, "Games", engine, &count, &ids);
 
385
 
334
386
        if (status < 0)
335
387
                return 0;
336
 
        
 
388
 
337
389
        numcount = count;
338
390
        for (i = 0; i < count; i++) {
339
391
                _ggzcore_module_read(&module, ids[i]);
340
392
                /* Subtract out modules that aren't the same protocol */
341
 
                if (strcmp(engine, module.prot_engine) != 0
342
 
                    || (version && strcmp(version, module.prot_version) != 0)
343
 
                    /* || game not included in game list */)
 
393
                if (ggz_strcmp(engine, module.prot_engine) != 0
 
394
                    || (version
 
395
                        && ggz_strcmp(version, module.prot_version) != 0)
 
396
                    /* || game not included in game list */
 
397
                    )
344
398
                        numcount--;
345
399
        }
346
400
 
353
407
 
354
408
/* FIXME: do this right.  We should parse through module_list not
355
409
   re-read the config file */
356
 
struct _GGZModule* _ggzcore_module_get_nth_by_type(const char *game, 
357
 
                                                   const char *engine,
358
 
                                                   const char *version,
359
 
                                                   const unsigned int num)
 
410
GGZModule *_ggzcore_module_get_nth_by_type(const char *game,
 
411
                                           const char *engine,
 
412
                                           const char *version,
 
413
                                           const unsigned int num)
360
414
{
361
415
        int i, total, status, count;
362
416
        char **ids;
363
 
        struct _GGZModule *module, *found = NULL;
 
417
        GGZModule *module, *found = NULL;
364
418
        GGZListEntry *entry;
365
419
 
366
 
        status = ggz_conf_read_list(mod_handle, "Games", engine, &total, &ids);
367
 
        
368
 
        ggz_debug(GGZCORE_DBG_MODULE, "Found %d modules matching %s", total,
369
 
                      engine);
370
 
        
 
420
        status =
 
421
            ggz_conf_read_list(mod_handle, "Games", engine, &total, &ids);
 
422
 
 
423
        ggz_debug(GGZCORE_DBG_MODULE, "Found %d modules matching %s",
 
424
                  total, engine);
 
425
 
371
426
        if (status < 0)
372
427
                return NULL;
373
428
 
380
435
        for (i = 0; i < total; i++) {
381
436
                module = _ggzcore_module_new();
382
437
                _ggzcore_module_read(module, ids[i]);
383
 
                if (strcmp(version, module->prot_version) == 0) {
 
438
                if (ggz_strcmp(version, module->prot_version) == 0) {
384
439
                        /* FIXME:  also check to see if 'game' is in supported list */
385
440
                        if (count++ == num) {
386
441
                                /* Now find same module in list */
387
 
                                entry = ggz_list_search(module_list, module);
 
442
                                entry =
 
443
                                    ggz_list_search(module_list, module);
388
444
                                found = ggz_list_get_data(entry);
389
445
                                _ggzcore_module_free(module);
390
446
                                break;
395
451
 
396
452
        /* Free the rest of the ggz_conf memory */
397
453
        _ggz_free_chars(ids);
398
 
        
399
 
        
 
454
 
 
455
 
400
456
        /* Return found module (if any) */
401
457
        return found;
402
458
}
403
459
 
404
460
 
405
 
const char* _ggzcore_module_get_name(struct _GGZModule *module)
 
461
const char *_ggzcore_module_get_name(const GGZModule * module)
406
462
{
407
463
        return module->name;
408
464
}
409
465
 
410
466
 
411
 
const char* _ggzcore_module_get_version(struct _GGZModule *module)
 
467
const char *_ggzcore_module_get_version(const GGZModule * module)
412
468
{
413
469
        return module->version;
414
470
}
415
471
 
416
472
 
417
 
const char* _ggzcore_module_get_prot_engine(struct _GGZModule *module)
 
473
const char *_ggzcore_module_get_prot_engine(const GGZModule * module)
418
474
{
419
475
        return module->prot_engine;
420
476
}
421
477
 
422
478
 
423
 
const char* _ggzcore_module_get_prot_version(struct _GGZModule *module)
 
479
const char *_ggzcore_module_get_prot_version(const GGZModule * module)
424
480
{
425
481
        return module->prot_version;
426
482
}
427
483
 
428
484
 
429
 
const char* _ggzcore_module_get_author(struct _GGZModule *module)
 
485
const char *_ggzcore_module_get_author(const GGZModule * module)
430
486
{
431
487
        return module->author;
432
488
}
433
489
 
434
490
 
435
 
const char* _ggzcore_module_get_frontend(struct _GGZModule *module)
 
491
const char *_ggzcore_module_get_frontend(const GGZModule * module)
436
492
{
437
493
        return module->frontend;
438
494
}
439
495
 
440
496
 
441
 
const char* _ggzcore_module_get_url(struct _GGZModule *module)
 
497
const char *_ggzcore_module_get_url(const GGZModule * module)
442
498
{
443
499
        return module->url;
444
500
}
445
501
 
446
502
 
447
 
const char* _ggzcore_module_get_icon_path(struct _GGZModule *module)
 
503
const char *_ggzcore_module_get_icon_path(const GGZModule * module)
448
504
{
449
505
        return module->icon;
450
506
}
451
507
 
452
508
 
453
 
const char* _ggzcore_module_get_help_path(struct _GGZModule *module)
 
509
const char *_ggzcore_module_get_help_path(const GGZModule * module)
454
510
{
455
511
        return module->help;
456
512
}
457
513
 
458
514
 
459
 
char** _ggzcore_module_get_argv(struct _GGZModule *module)
 
515
char **_ggzcore_module_get_argv(const GGZModule * module)
460
516
{
461
517
        return module->argv;
462
518
}
463
519
 
464
520
 
465
 
int _ggzcore_module_launch(struct _GGZModule *module)
 
521
GGZModuleEnvironment _ggzcore_module_get_environment(const GGZModule *
 
522
                                                     module)
466
523
{
467
 
        ggz_debug(GGZCORE_DBG_MODULE, "Launching module: ");
468
 
        _ggzcore_module_print(module);
469
 
 
470
 
        return -1;
 
524
        return module->environment;
471
525
}
472
526
 
473
527
 
476
530
        if (module_list)
477
531
                ggz_list_free(module_list);
478
532
        num_modules = 0;
479
 
        /* FIXME: do we need to close the file? */
 
533
 
 
534
        ggz_conf_close(mod_handle);
 
535
        mod_handle = -1;
480
536
}
481
537
 
482
538
 
483
539
/* Static functions internal to this file */
484
540
 
485
 
static struct _GGZModule* _ggzcore_module_new(void)
 
541
static GGZModule *_ggzcore_module_new(void)
486
542
{
487
 
        struct _GGZModule *module;
 
543
        GGZModule *module;
488
544
 
489
 
        module = ggz_malloc(sizeof(struct _GGZModule));
 
545
        module = ggz_malloc(sizeof(*module));
490
546
 
491
547
        return module;
492
548
}
493
549
 
494
550
#if 0
495
 
static void _ggzcore_module_init(struct _GGZModule *module,
 
551
static void _ggzcore_module_init(GGZModule * module,
496
552
                                 const char *name,
497
553
                                 const char *version,
498
554
                                 const char *prot_engine,
511
567
        module->author = ggz_strdup(author);
512
568
        module->frontend = ggz_strdup(frontend);
513
569
        module->url = ggz_strdup(url);
514
 
        /* module->path = ggz_strdup(exec_path);*/
 
570
        /* module->path = ggz_strdup(exec_path); */
515
571
        module->icon = ggz_strdup(icon_path);
516
572
        module->help = ggz_strdup(help_path);
517
573
}
518
574
#endif /* #if 0 */
519
575
 
520
576
 
521
 
static void _ggzcore_module_free(struct _GGZModule *module)
 
577
static void _ggzcore_module_free(GGZModule * module)
522
578
{
523
 
        
 
579
 
524
580
        if (module->name)
525
581
                ggz_free(module->name);
526
582
        if (module->version)
543
599
                _ggz_free_chars(module->games);
544
600
        if (module->argv)
545
601
                _ggz_free_chars(module->argv);
546
 
        
 
602
 
547
603
        ggz_free(module);
548
604
}
549
605
 
550
606
 
551
 
static int _ggzcore_module_add(struct _GGZModule *module)
 
607
static int _ggzcore_module_add(GGZModule * module)
552
608
{
553
609
        int status;
554
 
        
555
 
        if ( (status = ggz_list_insert(module_list, module)) == 0)
 
610
 
 
611
        if ((status = ggz_list_insert(module_list, module)) == 0)
556
612
                num_modules++;
557
613
 
558
614
        return status;
559
615
}
560
616
 
561
617
 
562
 
static char* _ggzcore_module_conf_filename(void)
 
618
static char *_ggzcore_module_conf_filename(void)
563
619
{
564
620
        char *filename;
565
621
        int new_len;
576
632
}
577
633
 
578
634
 
579
 
static void _ggzcore_module_read(struct _GGZModule *mod, char *id)
 
635
static void _ggzcore_module_read(GGZModule * mod, char *id)
580
636
{
581
637
        int argc;
 
638
        char *environment;
582
639
        /* FIXME: check for errors on all of these */
583
640
 
584
641
        /* Note: the memory allocated here is freed in _ggzcore_module_free */
585
642
        mod->name = ggz_conf_read_string(mod_handle, id, "Name", NULL);
586
 
        mod->version = ggz_conf_read_string(mod_handle, id, "Version", NULL);
587
 
        mod->prot_engine = ggz_conf_read_string(mod_handle, id, 
588
 
                                                "ProtocolEngine", NULL);
589
 
        mod->prot_version = ggz_conf_read_string(mod_handle, id, 
590
 
                                                 "ProtocolVersion", NULL);
591
 
        ggz_conf_read_list(mod_handle, id, "SupportedGames", &argc, 
 
643
        mod->version =
 
644
            ggz_conf_read_string(mod_handle, id, "Version", NULL);
 
645
        mod->prot_engine =
 
646
            ggz_conf_read_string(mod_handle, id, "ProtocolEngine", NULL);
 
647
        mod->prot_version =
 
648
            ggz_conf_read_string(mod_handle, id, "ProtocolVersion", NULL);
 
649
        ggz_conf_read_list(mod_handle, id, "SupportedGames", &argc,
592
650
                           &mod->games);
593
651
        mod->author = ggz_conf_read_string(mod_handle, id, "Author", NULL);
594
 
        mod->frontend = ggz_conf_read_string(mod_handle, id, "Frontend", NULL);
 
652
        mod->frontend =
 
653
            ggz_conf_read_string(mod_handle, id, "Frontend", NULL);
595
654
        mod->url = ggz_conf_read_string(mod_handle, id, "Homepage", NULL);
596
 
        ggz_conf_read_list(mod_handle, id, "CommandLine", &argc, &mod->argv);
 
655
        ggz_conf_read_list(mod_handle, id, "CommandLine", &argc,
 
656
                           &mod->argv);
597
657
        mod->icon = ggz_conf_read_string(mod_handle, id, "IconPath", NULL);
598
 
        mod->help = ggz_conf_read_string(mod_handle, id, "HelpPath",  NULL);
 
658
        mod->help = ggz_conf_read_string(mod_handle, id, "HelpPath", NULL);
 
659
 
 
660
        environment =
 
661
            ggz_conf_read_string(mod_handle, id, "Environment", NULL);
 
662
        if (!environment)
 
663
                mod->environment = GGZ_ENVIRONMENT_XWINDOW;
 
664
        else if (!ggz_strcmp(environment, "xwindow"))
 
665
                mod->environment = GGZ_ENVIRONMENT_XWINDOW;
 
666
        else if (!ggz_strcmp(environment, "xfullscreen"))
 
667
                mod->environment = GGZ_ENVIRONMENT_XFULLSCREEN;
 
668
        else if (!ggz_strcmp(environment, "passive"))
 
669
                mod->environment = GGZ_ENVIRONMENT_PASSIVE;
 
670
        else if (!ggz_strcmp(environment, "console"))
 
671
                mod->environment = GGZ_ENVIRONMENT_CONSOLE;
 
672
        else
 
673
                mod->environment = GGZ_ENVIRONMENT_XWINDOW;
 
674
        if (environment)
 
675
                ggz_free(environment);
599
676
}
600
677
 
601
678
 
602
 
static void _ggzcore_module_print(struct _GGZModule *module)
 
679
static void _ggzcore_module_print(const GGZModule * module)
603
680
{
604
 
        int i=0;
605
 
        
 
681
        int i = 0;
 
682
 
606
683
        ggz_debug(GGZCORE_DBG_MODULE, "Name: %s", module->name);
607
684
        ggz_debug(GGZCORE_DBG_MODULE, "Version: %s", module->version);
608
 
        ggz_debug(GGZCORE_DBG_MODULE, "ProtocolEngine: %s", module->prot_engine);       
 
685
        ggz_debug(GGZCORE_DBG_MODULE, "ProtocolEngine: %s",
 
686
                  module->prot_engine);
609
687
        ggz_debug(GGZCORE_DBG_MODULE, "ProtocolVersion: %s",
610
688
                  module->prot_version);
611
689
        if (module->games)
612
690
                while (module->games[i]) {
613
 
                        ggz_debug(GGZCORE_DBG_MODULE, "Game[%d]: %s", i, 
 
691
                        ggz_debug(GGZCORE_DBG_MODULE, "Game[%d]: %s", i,
614
692
                                  module->games[i]);
615
693
                        ++i;
616
694
                }
620
698
        ggz_debug(GGZCORE_DBG_MODULE, "URL: %s", module->url);
621
699
        ggz_debug(GGZCORE_DBG_MODULE, "Icon: %s", module->icon);
622
700
        ggz_debug(GGZCORE_DBG_MODULE, "Help: %s", module->help);
623
 
        while (module->argv[i]) {
624
 
                ggz_debug(GGZCORE_DBG_MODULE, "Argv[%d]: %s", i, 
 
701
        while (module->argv && module->argv[i]) {
 
702
                ggz_debug(GGZCORE_DBG_MODULE, "Argv[%d]: %s", i,
625
703
                          module->argv[i]);
626
704
                ++i;
627
705
        }
631
709
static void _ggzcore_module_list_print(void)
632
710
{
633
711
        GGZListEntry *cur;
634
 
        
635
 
        for (cur = ggz_list_head(module_list); cur; cur = ggz_list_next(cur))
 
712
 
 
713
        for (cur = ggz_list_head(module_list); cur;
 
714
             cur = ggz_list_next(cur))
636
715
                _ggzcore_module_print(ggz_list_get_data(cur));
637
716
}
638
717
 
642
721
static void _ggz_free_chars(char **argv)
643
722
{
644
723
        int i;
645
 
        
 
724
 
646
725
        for (i = 0; argv[i]; i++)
647
726
                ggz_free(argv[i]);
648
 
        
 
727
 
649
728
        ggz_free(argv);
650
729
}
651
730
 
652
731
 
653
732
/* Match game module by 'name', 'prot_engine', 'prot_version' */
654
 
static int _ggzcore_module_compare(void *p, void *q)
 
733
static int _ggzcore_module_compare(const void *p, const void *q)
655
734
{
656
735
        int compare;
657
 
 
658
 
        struct _GGZModule *pmod = (struct _GGZModule*)p;
659
 
        struct _GGZModule *qmod = (struct _GGZModule*)q;
660
 
 
661
 
        compare = strcmp(pmod->name, qmod->name);
662
 
        if (compare != 0) return compare;
663
 
 
664
 
        compare = strcmp(pmod->prot_engine, qmod->prot_engine);
665
 
        if (compare != 0) return compare;
666
 
        
667
 
        compare = strcmp(pmod->prot_version, qmod->prot_version);
668
 
        if (compare != 0) return compare;
669
 
        
670
 
        compare = strcmp(pmod->frontend, qmod->frontend);
671
 
        
672
 
        return compare; 
 
736
        const GGZModule *pmod = p, *qmod = q;
 
737
 
 
738
        compare = ggz_strcmp(pmod->name, qmod->name);
 
739
        if (compare != 0)
 
740
                return compare;
 
741
 
 
742
        compare = ggz_strcmp(pmod->prot_engine, qmod->prot_engine);
 
743
        if (compare != 0)
 
744
                return compare;
 
745
 
 
746
        compare = ggz_strcmp(pmod->prot_version, qmod->prot_version);
 
747
        if (compare != 0)
 
748
                return compare;
 
749
 
 
750
        compare = ggz_strcmp(pmod->frontend, qmod->frontend);
 
751
 
 
752
        return compare;
673
753
}
674
754
 
675
755
#if 0
676
 
static void* _ggzcore_module_create(void* p)
 
756
static void *_ggzcore_module_create(void *p)
677
757
{
678
 
        struct _GGZModule *new, *src = p;
 
758
        GGZModule *new, *src = p;
679
759
 
680
760
        new = _ggzcore_module_new();
681
 
        
682
 
        _ggzcore_module_init(new, src->name, src->version, 
 
761
 
 
762
        _ggzcore_module_init(new, src->name, src->version,
683
763
                             src->prot_engine, src->prot_version,
684
 
                             src->author, src->frontend, src->url, 
 
764
                             src->author, src->frontend, src->url,
685
765
                             src->argv[0], src->icon, src->help);
686
 
                             
687
 
 
688
 
        return (void*)new;
 
766
 
 
767
 
 
768
        return new;
689
769
}
690
770
#endif /* #if 0 */
691
771
 
692
 
static void _ggzcore_module_destroy(void* p)
 
772
static void _ggzcore_module_destroy(void *p)
693
773
{
694
774
        /* Quick sanity check */
695
775
        if (!p)