~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/dmx/config/dmxparse.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86$ */
 
2
/*
 
3
 * Copyright 2002 Red Hat Inc., Durham, North Carolina.
 
4
 *
 
5
 * All Rights Reserved.
 
6
 *
 
7
 * Permission is hereby granted, free of charge, to any person obtaining
 
8
 * a copy of this software and associated documentation files (the
 
9
 * "Software"), to deal in the Software without restriction, including
 
10
 * without limitation on the rights to use, copy, modify, merge,
 
11
 * publish, distribute, sublicense, and/or sell copies of the Software,
 
12
 * and to permit persons to whom the Software is furnished to do so,
 
13
 * subject to the following conditions:
 
14
 *
 
15
 * The above copyright notice and this permission notice (including the
 
16
 * next paragraph) shall be included in all copies or substantial
 
17
 * portions of the Software.
 
18
 *
 
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
20
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
21
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
22
 * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
 
23
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
24
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
25
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
26
 * SOFTWARE.
 
27
 */
 
28
 
 
29
/*
 
30
 * Authors:
 
31
 *   Rickard E. (Rik) Faith <faith@redhat.com>
 
32
 *
 
33
 */
 
34
 
 
35
/** \file
 
36
 *
 
37
 * This file provides support routines and helper functions to be used
 
38
 * by the DMX configuration file parser.
 
39
 *
 
40
 * Because the DMX configuration file parsing should be capable of being
 
41
 * used in a stand-alone fashion (i.e., independent from the DMX server
 
42
 * source tree), no dependencies on other DMX routines are made. */
 
43
 
 
44
#ifdef HAVE_DMX_CONFIG_H
 
45
#include <dmx-config.h>
 
46
#endif
 
47
 
 
48
#include <stdio.h>
 
49
#include <stdlib.h>
 
50
#include <string.h>
 
51
#include <stdarg.h>
 
52
#include "dmxparse.h"
 
53
 
 
54
/** A general error logging routine that does not depend on the dmxLog
 
55
 * functions. */
 
56
void dmxConfigLog(const char *format, ...)
 
57
{
 
58
    va_list args;
 
59
    
 
60
    va_start(args, format);
 
61
    vprintf(format, args);      /* RATS: All calls to dmxConfigLog from
 
62
                                 * dmxparse.c and dmxprint.c use a
 
63
                                 * trusted format. */
 
64
    va_end(args);
 
65
}
 
66
 
 
67
void *dmxConfigAlloc(unsigned long bytes)
 
68
{
 
69
    void *area = malloc(bytes);
 
70
    if (!area) {
 
71
        dmxConfigLog("dmxConfigAlloc: out of memory\n");
 
72
        return NULL;
 
73
    }
 
74
    memset(area, 0, bytes);
 
75
    return area;
 
76
}
 
77
 
 
78
void *dmxConfigRealloc(void *orig, unsigned long orig_bytes,
 
79
                       unsigned long bytes)
 
80
{
 
81
    unsigned char *area = realloc(orig, bytes);
 
82
    if (!area) {
 
83
        dmxConfigLog("dmxConfigRealloc: out of memory\n");
 
84
        return NULL;
 
85
    }
 
86
    memset(area + orig_bytes, 0, bytes - orig_bytes);
 
87
    return area;
 
88
}
 
89
 
 
90
const char *dmxConfigCopyString(const char *string, int length)
 
91
{
 
92
    char *copy;
 
93
    
 
94
    if (!length) length = strlen(string);
 
95
    copy = dmxConfigAlloc(length + 1);
 
96
    if (length) strncpy(copy, string, length);
 
97
    copy[length] = '\0';
 
98
    return copy;
 
99
}
 
100
 
 
101
void dmxConfigFree(void *area)
 
102
{
 
103
    if (area) free(area);
 
104
}
 
105
 
 
106
DMXConfigTokenPtr dmxConfigCreateToken(int token, int line,
 
107
                                       const char *comment)
 
108
{
 
109
    DMXConfigTokenPtr pToken = dmxConfigAlloc(sizeof(*pToken));
 
110
    pToken->token   = token;
 
111
    pToken->line    = line;
 
112
    pToken->comment = comment;
 
113
    return pToken;
 
114
}
 
115
 
 
116
void dmxConfigFreeToken(DMXConfigTokenPtr p)
 
117
{
 
118
    if (!p) return;
 
119
    dmxConfigFree((void *)p->comment);
 
120
    dmxConfigFree(p);
 
121
}
 
122
 
 
123
DMXConfigStringPtr dmxConfigCreateString(int token, int line,
 
124
                                         const char *comment,
 
125
                                         const char *string)
 
126
{
 
127
    DMXConfigStringPtr pString = dmxConfigAlloc(sizeof(*pString));
 
128
 
 
129
    pString->token   = token;
 
130
    pString->line    = line;
 
131
    pString->comment = comment;
 
132
    pString->string  = string;
 
133
    return pString;
 
134
}
 
135
 
 
136
void dmxConfigFreeString(DMXConfigStringPtr p)
 
137
{
 
138
    DMXConfigStringPtr next;
 
139
 
 
140
    if (!p) return;
 
141
    do {
 
142
        next = p->next;
 
143
        dmxConfigFree((void *)p->comment);
 
144
        dmxConfigFree((void *)p->string);
 
145
        dmxConfigFree(p);
 
146
    } while ((p = next));
 
147
}
 
148
 
 
149
DMXConfigNumberPtr dmxConfigCreateNumber(int token, int line,
 
150
                                         const char *comment,
 
151
                                         int number)
 
152
{
 
153
    DMXConfigNumberPtr pNumber = dmxConfigAlloc(sizeof(*pNumber));
 
154
 
 
155
    pNumber->token   = token;
 
156
    pNumber->line    = line;
 
157
    pNumber->comment = comment;
 
158
    pNumber->number  = number;
 
159
    return pNumber;
 
160
}
 
161
 
 
162
void dmxConfigFreeNumber(DMXConfigNumberPtr p)
 
163
{
 
164
    if (!p) return;
 
165
    dmxConfigFree((void *)p->comment);
 
166
    dmxConfigFree(p);
 
167
}
 
168
 
 
169
DMXConfigPairPtr dmxConfigCreatePair(int token, int line,
 
170
                                     const char *comment,
 
171
                                     int x, int y,
 
172
                                     int xsign, int ysign)
 
173
{
 
174
    DMXConfigPairPtr pPair = dmxConfigAlloc(sizeof(*pPair));
 
175
 
 
176
    pPair->token   = token;
 
177
    pPair->line    = line;
 
178
    pPair->comment = comment;
 
179
    pPair->x       = x;
 
180
    pPair->y       = y;
 
181
    pPair->xsign   = (xsign < 0) ? -1 : 1;
 
182
    pPair->ysign   = (ysign < 0) ? -1 : 1;
 
183
    return pPair;
 
184
}
 
185
 
 
186
void dmxConfigFreePair(DMXConfigPairPtr p)
 
187
{
 
188
    if (!p) return;
 
189
    dmxConfigFree((void *)p->comment);
 
190
    dmxConfigFree(p);
 
191
}
 
192
 
 
193
DMXConfigCommentPtr dmxConfigCreateComment(int token, int line,
 
194
                                           const char *comment)
 
195
{
 
196
    DMXConfigCommentPtr pComment = dmxConfigAlloc(sizeof(*pComment));
 
197
 
 
198
    pComment->token   = token;
 
199
    pComment->line    = line;
 
200
    pComment->comment = comment;
 
201
    return pComment;
 
202
}
 
203
 
 
204
void dmxConfigFreeComment(DMXConfigCommentPtr p)
 
205
{
 
206
    if (!p) return;
 
207
    dmxConfigFree((void *)p->comment);
 
208
    dmxConfigFree(p);
 
209
}
 
210
 
 
211
DMXConfigPartDimPtr dmxConfigCreatePartDim(DMXConfigPairPtr pDim,
 
212
                                           DMXConfigPairPtr pOffset)
 
213
{
 
214
    DMXConfigPartDimPtr pPart = dmxConfigAlloc(sizeof(*pPart));
 
215
    pPart->dim    = pDim;
 
216
    pPart->offset = pOffset;
 
217
    return pPart;
 
218
}
 
219
 
 
220
void dmxConfigFreePartDim(DMXConfigPartDimPtr p)
 
221
{
 
222
    if (!p) return;
 
223
    dmxConfigFreePair(p->dim);
 
224
    dmxConfigFreePair(p->offset);
 
225
    dmxConfigFree(p);
 
226
}
 
227
 
 
228
DMXConfigFullDimPtr dmxConfigCreateFullDim(DMXConfigPartDimPtr pScrn,
 
229
                                           DMXConfigPartDimPtr pRoot)
 
230
{
 
231
    DMXConfigFullDimPtr pFull = dmxConfigAlloc(sizeof(*pFull));
 
232
    pFull->scrn = pScrn;
 
233
    pFull->root = pRoot;
 
234
    return pFull;
 
235
}
 
236
 
 
237
void dmxConfigFreeFullDim(DMXConfigFullDimPtr p)
 
238
{
 
239
    if (!p) return;
 
240
    dmxConfigFreePartDim(p->scrn);
 
241
    dmxConfigFreePartDim(p->root);
 
242
    dmxConfigFree(p);
 
243
}
 
244
 
 
245
DMXConfigDisplayPtr dmxConfigCreateDisplay(DMXConfigTokenPtr pStart,
 
246
                                           DMXConfigStringPtr pName,
 
247
                                           DMXConfigFullDimPtr pDim,
 
248
                                           DMXConfigPairPtr pOrigin,
 
249
                                           DMXConfigTokenPtr pEnd)
 
250
{
 
251
    DMXConfigDisplayPtr pDisplay = dmxConfigAlloc(sizeof(*pDisplay));
 
252
 
 
253
    memset(pDisplay, 0, sizeof(*pDisplay));
 
254
 
 
255
    pDisplay->start          = pStart;
 
256
    pDisplay->dname          = pName;
 
257
    pDisplay->dim            = pDim;
 
258
    pDisplay->origin         = pOrigin;
 
259
    pDisplay->end            = pEnd;
 
260
 
 
261
    pDisplay->name           = pName ? pName->string : NULL;
 
262
    pDisplay->rootXOrigin    = pOrigin ? pOrigin->x : 0;
 
263
    pDisplay->rootYOrigin    = pOrigin ? pOrigin->y : 0;
 
264
 
 
265
    if (pDim && pDim->scrn && pDim->scrn->dim) {
 
266
        pDisplay->scrnWidth  = pDim->scrn->dim->x;
 
267
        pDisplay->scrnHeight = pDim->scrn->dim->y;
 
268
    }
 
269
    if (pDim && pDim->scrn && pDim->scrn->offset) {
 
270
        pDisplay->scrnX      = pDim->scrn->offset->x;
 
271
        pDisplay->scrnY      = pDim->scrn->offset->y;
 
272
        pDisplay->scrnXSign  = pDim->scrn->offset->xsign;
 
273
        pDisplay->scrnYSign  = pDim->scrn->offset->ysign;
 
274
    }
 
275
    
 
276
    if (pDim && pDim->root) {
 
277
        if (pDim->root->dim) {
 
278
            pDisplay->rootWidth  = pDim->root->dim->x;
 
279
            pDisplay->rootHeight = pDim->root->dim->y;
 
280
        }
 
281
        if (pDim->root->offset) {
 
282
            pDisplay->rootX      = pDim->root->offset->x;
 
283
            pDisplay->rootY      = pDim->root->offset->y;
 
284
            pDisplay->rootXSign  = pDim->root->offset->xsign;
 
285
            pDisplay->rootYSign  = pDim->root->offset->ysign;
 
286
        }
 
287
    } else {                    /* If no root specification, copy width
 
288
                                 * and height from scrn -- leave offset
 
289
                                 * as zero, since it is relative to
 
290
                                 * scrn. */
 
291
        pDisplay->rootWidth  = pDisplay->scrnWidth;
 
292
        pDisplay->rootHeight = pDisplay->scrnHeight;
 
293
    }
 
294
 
 
295
 
 
296
    return pDisplay;
 
297
}
 
298
 
 
299
void dmxConfigFreeDisplay(DMXConfigDisplayPtr p)
 
300
{
 
301
    if (!p) return;
 
302
    dmxConfigFreeToken(p->start);
 
303
    dmxConfigFreeString(p->dname);
 
304
    dmxConfigFreeFullDim(p->dim);
 
305
    dmxConfigFreeToken(p->end);
 
306
    dmxConfigFree(p);
 
307
}
 
308
 
 
309
DMXConfigWallPtr dmxConfigCreateWall(DMXConfigTokenPtr pStart,
 
310
                                     DMXConfigPairPtr pWallDim,
 
311
                                     DMXConfigPairPtr pDisplayDim,
 
312
                                     DMXConfigStringPtr pNameList,
 
313
                                     DMXConfigTokenPtr pEnd)
 
314
{
 
315
    DMXConfigWallPtr pWall = dmxConfigAlloc(sizeof(*pWall));
 
316
 
 
317
    pWall->start      = pStart;
 
318
    pWall->wallDim    = pWallDim;
 
319
    pWall->displayDim = pDisplayDim;
 
320
    pWall->nameList   = pNameList;
 
321
    pWall->end        = pEnd;
 
322
 
 
323
    pWall->width      = pDisplayDim ? pDisplayDim->x : 0;
 
324
    pWall->height     = pDisplayDim ? pDisplayDim->y : 0;
 
325
    pWall->xwall      = pWallDim    ? pWallDim->x    : 0;
 
326
    pWall->ywall      = pWallDim    ? pWallDim->y    : 0;
 
327
 
 
328
    return pWall;
 
329
}
 
330
 
 
331
void dmxConfigFreeWall(DMXConfigWallPtr p)
 
332
{
 
333
    if (!p) return;
 
334
    dmxConfigFreeToken(p->start);
 
335
    dmxConfigFreePair(p->wallDim);
 
336
    dmxConfigFreePair(p->displayDim);
 
337
    dmxConfigFreeString(p->nameList);
 
338
    dmxConfigFreeToken(p->end);
 
339
    dmxConfigFree(p);
 
340
}
 
341
 
 
342
DMXConfigOptionPtr dmxConfigCreateOption(DMXConfigTokenPtr pStart,
 
343
                                         DMXConfigStringPtr pOption,
 
344
                                         DMXConfigTokenPtr pEnd)
 
345
{
 
346
    int                length = 0;
 
347
    int                offset = 0;
 
348
    DMXConfigStringPtr p;
 
349
    DMXConfigOptionPtr option = dmxConfigAlloc(sizeof(*option));
 
350
 
 
351
    for (p = pOption; p; p = p->next) {
 
352
        if (p->string) length += strlen(p->string) + 1;
 
353
    }
 
354
 
 
355
    option->string = dmxConfigAlloc(length + 1);
 
356
    
 
357
    for (p = pOption; p; p = p->next) {
 
358
        if (p->string) {
 
359
            int len = strlen(p->string);
 
360
            strncpy(option->string + offset, p->string, len);
 
361
            offset += len;
 
362
            if (p->next) option->string[offset++] = ' ';
 
363
        }
 
364
    }
 
365
    option->string[offset] = '\0';
 
366
 
 
367
    option->start  = pStart;
 
368
    option->option = pOption;
 
369
    option->end    = pEnd;
 
370
 
 
371
    return option;
 
372
}
 
373
 
 
374
void dmxConfigFreeOption(DMXConfigOptionPtr p)
 
375
{
 
376
    if (!p) return;
 
377
    if (p->string) free(p->string);
 
378
    dmxConfigFreeToken(p->start);
 
379
    dmxConfigFreeString(p->option);
 
380
    dmxConfigFreeToken(p->end);
 
381
    dmxConfigFree(p);
 
382
}
 
383
 
 
384
const char **dmxConfigLookupParam(DMXConfigParamPtr p, const char *key,
 
385
                                  int *argc)
 
386
{
 
387
    DMXConfigParamPtr pt;
 
388
 
 
389
    for (pt = p; pt; pt = pt->next) {
 
390
        if (pt->argv && !strcasecmp(pt->argv[0], key)) {
 
391
            *argc = pt->argc;
 
392
            return pt->argv;
 
393
        }
 
394
    }
 
395
    *argc  = 0;
 
396
    return NULL;
 
397
}
 
398
 
 
399
DMXConfigParamPtr dmxConfigCreateParam(DMXConfigTokenPtr pStart,
 
400
                                       DMXConfigTokenPtr pOpen,
 
401
                                       DMXConfigStringPtr pParam,
 
402
                                       DMXConfigTokenPtr pClose,
 
403
                                       DMXConfigTokenPtr pEnd)
 
404
{
 
405
    DMXConfigParamPtr  param = dmxConfigAlloc(sizeof(*param));
 
406
    DMXConfigStringPtr pt;
 
407
 
 
408
    param->argc = 0;
 
409
    param->argv = NULL;
 
410
    for (pt = pParam; pt; pt = pt->next) {
 
411
        if (pt->string) {
 
412
            param->argv = realloc(param->argv,
 
413
                                  (param->argc+2) * sizeof(*param->argv));
 
414
            param->argv[param->argc] = pt->string;
 
415
            ++param->argc;
 
416
        }
 
417
    }
 
418
    if (param->argv) param->argv[param->argc] = NULL;
 
419
 
 
420
    param->start = pStart;
 
421
    param->open  = pOpen;
 
422
    param->param = pParam;
 
423
    param->close = pClose;
 
424
    param->end   = pEnd;
 
425
 
 
426
    return param;
 
427
}
 
428
 
 
429
void dmxConfigFreeParam(DMXConfigParamPtr p)
 
430
{
 
431
    DMXConfigParamPtr next;
 
432
 
 
433
    if (!p) return;
 
434
    do {
 
435
        next = p->next;
 
436
        dmxConfigFreeToken(p->start);
 
437
        dmxConfigFreeToken(p->open);
 
438
        dmxConfigFreeString(p->param);
 
439
        dmxConfigFreeToken(p->close);
 
440
        dmxConfigFreeToken(p->end);
 
441
        dmxConfigFree(p->argv);
 
442
        dmxConfigFree(p);
 
443
    } while ((p = next));
 
444
}
 
445
 
 
446
DMXConfigSubPtr dmxConfigCreateSub(DMXConfigType type,
 
447
                                   DMXConfigCommentPtr comment,
 
448
                                   DMXConfigDisplayPtr display,
 
449
                                   DMXConfigWallPtr wall,
 
450
                                   DMXConfigOptionPtr option,
 
451
                                   DMXConfigParamPtr param)
 
452
{
 
453
    DMXConfigSubPtr pSub = dmxConfigAlloc(sizeof(*pSub));
 
454
    pSub->type = type;
 
455
    switch (type) {
 
456
    case dmxConfigComment: pSub->comment = comment;                     break;
 
457
    case dmxConfigDisplay: pSub->display = display;                     break;
 
458
    case dmxConfigWall:    pSub->wall    = wall;                        break;
 
459
    case dmxConfigOption:  pSub->option  = option;                      break;
 
460
    case dmxConfigParam:   pSub->param   = param;                       break;
 
461
    default: dmxConfigLog("Type %d not supported in subentry\n", type); break;
 
462
    }
 
463
    return pSub;
 
464
}
 
465
 
 
466
void dmxConfigFreeSub(DMXConfigSubPtr sub)
 
467
{
 
468
    DMXConfigSubPtr pt;
 
469
 
 
470
    for (pt = sub; pt; pt = pt->next) {
 
471
        switch (pt->type) {
 
472
        case dmxConfigComment: dmxConfigFreeComment(pt->comment); break;
 
473
        case dmxConfigDisplay: dmxConfigFreeDisplay(pt->display); break;
 
474
        case dmxConfigWall:    dmxConfigFreeWall(pt->wall);       break;
 
475
        case dmxConfigOption:  dmxConfigFreeOption(pt->option);   break;
 
476
        case dmxConfigParam:   dmxConfigFreeParam(pt->param);     break;
 
477
        default:
 
478
            dmxConfigLog("Type %d not supported in subentry\n", pt->type);
 
479
            break;
 
480
        }
 
481
    }
 
482
    dmxConfigFree(sub);
 
483
}
 
484
 
 
485
DMXConfigSubPtr dmxConfigSubComment(DMXConfigCommentPtr comment)
 
486
{
 
487
    return dmxConfigCreateSub(dmxConfigComment, comment, NULL, NULL, NULL,
 
488
                              NULL);
 
489
}
 
490
 
 
491
DMXConfigSubPtr dmxConfigSubDisplay(DMXConfigDisplayPtr display)
 
492
{
 
493
    return dmxConfigCreateSub(dmxConfigDisplay, NULL, display, NULL, NULL,
 
494
                              NULL);
 
495
}
 
496
 
 
497
DMXConfigSubPtr dmxConfigSubWall(DMXConfigWallPtr wall)
 
498
{
 
499
    return dmxConfigCreateSub(dmxConfigWall, NULL, NULL, wall, NULL, NULL);
 
500
}
 
501
 
 
502
DMXConfigSubPtr dmxConfigSubOption(DMXConfigOptionPtr option)
 
503
{
 
504
    return dmxConfigCreateSub(dmxConfigOption, NULL, NULL, NULL, option, NULL);
 
505
}
 
506
 
 
507
DMXConfigSubPtr dmxConfigSubParam(DMXConfigParamPtr param)
 
508
{
 
509
    return dmxConfigCreateSub(dmxConfigParam, NULL, NULL, NULL, NULL, param);
 
510
}
 
511
 
 
512
extern DMXConfigSubPtr dmxConfigAddSub(DMXConfigSubPtr head,
 
513
                                       DMXConfigSubPtr sub)
 
514
{
 
515
    DMXConfigSubPtr pt;
 
516
    
 
517
    if (!head) return sub;
 
518
    for (pt = head; pt->next; pt = pt->next);
 
519
    pt->next = sub;
 
520
    return head;
 
521
}
 
522
 
 
523
DMXConfigVirtualPtr dmxConfigCreateVirtual(DMXConfigTokenPtr pStart,
 
524
                                           DMXConfigStringPtr pName,
 
525
                                           DMXConfigPairPtr pDim,
 
526
                                           DMXConfigTokenPtr pOpen,
 
527
                                           DMXConfigSubPtr pSubentry,
 
528
                                           DMXConfigTokenPtr pClose)
 
529
{
 
530
    DMXConfigVirtualPtr pVirtual = dmxConfigAlloc(sizeof(*pVirtual));
 
531
 
 
532
    pVirtual->start    = pStart;
 
533
    pVirtual->vname    = pName;
 
534
    pVirtual->dim      = pDim;
 
535
    pVirtual->open     = pOpen;
 
536
    pVirtual->subentry = pSubentry;
 
537
    pVirtual->close    = pClose;
 
538
 
 
539
    pVirtual->name     = pName ? pName->string : NULL;
 
540
    pVirtual->width    = pDim ? pDim->x : 0;
 
541
    pVirtual->height   = pDim ? pDim->y : 0;
 
542
    
 
543
    return pVirtual;
 
544
}
 
545
 
 
546
void dmxConfigFreeVirtual(DMXConfigVirtualPtr virtual)
 
547
{
 
548
    dmxConfigFreeToken(virtual->start);
 
549
    dmxConfigFreeString(virtual->vname);
 
550
    dmxConfigFreePair(virtual->dim);
 
551
    dmxConfigFreeToken(virtual->open);
 
552
    dmxConfigFreeSub(virtual->subentry);
 
553
    dmxConfigFreeToken(virtual->close);
 
554
    dmxConfigFree(virtual);
 
555
}
 
556
 
 
557
DMXConfigEntryPtr dmxConfigCreateEntry(DMXConfigType type,
 
558
                                       DMXConfigCommentPtr comment,
 
559
                                       DMXConfigVirtualPtr virtual)
 
560
{
 
561
    DMXConfigEntryPtr pEntry = dmxConfigAlloc(sizeof(*pEntry));
 
562
    pEntry->type = type;
 
563
    switch (type) {
 
564
    case dmxConfigComment: pEntry->comment = comment;                break;
 
565
    case dmxConfigVirtual: pEntry->virtual = virtual;                break;
 
566
    default: dmxConfigLog("Type %d not supported in entry\n", type); break;
 
567
    }
 
568
    return pEntry;
 
569
}
 
570
 
 
571
void dmxConfigFreeEntry(DMXConfigEntryPtr entry)
 
572
{
 
573
    DMXConfigEntryPtr pt;
 
574
 
 
575
    for (pt = entry; pt; pt = pt->next) {
 
576
        switch (pt->type) {
 
577
        case dmxConfigComment: dmxConfigFreeComment(pt->comment); break;
 
578
        case dmxConfigVirtual: dmxConfigFreeVirtual(pt->virtual); break;
 
579
        default:
 
580
            dmxConfigLog("Type %d not supported in entry\n", pt->type);
 
581
            break;
 
582
        }
 
583
    }
 
584
    dmxConfigFree(entry);
 
585
}
 
586
 
 
587
DMXConfigEntryPtr dmxConfigAddEntry(DMXConfigEntryPtr head,
 
588
                                    DMXConfigType type,
 
589
                                    DMXConfigCommentPtr comment,
 
590
                                    DMXConfigVirtualPtr virtual)
 
591
{
 
592
    DMXConfigEntryPtr child = dmxConfigCreateEntry(type, comment, virtual);
 
593
    DMXConfigEntryPtr pt;
 
594
 
 
595
    if (!head) return child;
 
596
 
 
597
    for (pt = head; pt->next; pt = pt->next);
 
598
    pt->next = child;
 
599
 
 
600
    return head;
 
601
}
 
602
 
 
603
DMXConfigEntryPtr dmxConfigEntryComment(DMXConfigCommentPtr comment)
 
604
{
 
605
    return dmxConfigCreateEntry(dmxConfigComment, comment, NULL);
 
606
}
 
607
 
 
608
DMXConfigEntryPtr dmxConfigEntryVirtual(DMXConfigVirtualPtr virtual)
 
609
{
 
610
    return dmxConfigCreateEntry(dmxConfigVirtual, NULL, virtual);
 
611
}