~ubuntu-branches/ubuntu/maverick/libvirt/maverick

« back to all changes in this revision

Viewing changes to src/sexpr.c

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2008-06-25 18:51:21 UTC
  • mto: (3.1.1 lenny) (1.2.1 upstream) (0.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20080625185121-8dku38gpoluks1bx
Tags: upstream-0.4.4
ImportĀ upstreamĀ versionĀ 0.4.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include <stdio.h>
16
16
#include <stdlib.h>
17
17
#include <string.h>
18
 
#include <ctype.h>
 
18
#include "c-ctype.h"
19
19
#include <errno.h>
20
20
 
21
21
#include "internal.h"
22
22
#include "sexpr.h"
 
23
#include "util.h"
 
24
#include "memory.h"
23
25
 
24
26
/**
25
27
 * virSexprError:
54
56
{
55
57
    struct sexpr *ret;
56
58
 
57
 
    ret = (struct sexpr *) malloc(sizeof(*ret));
58
 
    if (ret == NULL) {
 
59
    if (VIR_ALLOC(ret) < 0) {
59
60
        virSexprError(VIR_ERR_NO_MEMORY, _("failed to allocate a node"));
60
61
        return (NULL);
61
62
    }
84
85
            sexpr_free(sexpr->u.s.cdr);
85
86
            break;
86
87
        case SEXPR_VALUE:
87
 
            free(sexpr->u.value);
 
88
            VIR_FREE(sexpr->u.value);
88
89
            break;
89
90
        case SEXPR_NIL:
90
91
            break;
91
92
    }
92
93
 
93
 
    free(sexpr);
 
94
    VIR_FREE(sexpr);
94
95
 
95
96
    errno = serrno;
96
97
}
170
171
 *
171
172
 * Internal operation appending a value at the end of an existing list
172
173
 */
173
 
static void
 
174
static int
174
175
append(struct sexpr *lst, const struct sexpr *value)
175
176
{
 
177
    struct sexpr *nil = sexpr_nil();
 
178
 
 
179
    if (nil == NULL)
 
180
        return -1;
 
181
 
176
182
    while (lst->kind != SEXPR_NIL) {
177
183
        lst = lst->u.s.cdr;
178
184
    }
179
185
 
180
186
    lst->kind = SEXPR_CONS;
181
187
    lst->u.s.car = (struct sexpr *) value;
182
 
    lst->u.s.cdr = sexpr_nil();
 
188
    lst->u.s.cdr = nil;
 
189
 
 
190
    return 0;
183
191
}
184
192
 
185
193
/**
197
205
        return (NULL);
198
206
    if (value == NULL)
199
207
        return (lst);
200
 
    append(lst, value);
 
208
    if (append(lst, value) < 0)
 
209
        return (NULL);
201
210
    return (lst);
202
211
}
203
212
 
317
326
 
318
327
            tmp = _string2sexpr(ptr, &tmp_len);
319
328
            if (tmp == NULL)
320
 
                return NULL;
321
 
            append(ret, tmp);
 
329
                goto error;
 
330
            if (append(ret, tmp) < 0) {
 
331
                sexpr_free(tmp);
 
332
                goto error;
 
333
            }
322
334
#if 0
323
335
            if (0) {
324
336
                char buf[4096];
350
362
            if (ret->u.value == NULL) {
351
363
                virSexprError(VIR_ERR_NO_MEMORY,
352
364
                              _("failed to copy a string"));
 
365
                goto error;
353
366
            }
354
367
 
355
368
            if (*ptr == '\'')
357
370
        } else {
358
371
            start = ptr;
359
372
 
360
 
            while (*ptr && !isspace(*ptr) && *ptr != ')' && *ptr != '(') {
 
373
            while (*ptr && !c_isspace(*ptr)
 
374
                   && *ptr != ')' && *ptr != '(') {
361
375
                ptr++;
362
376
            }
363
377
 
365
379
            if (ret->u.value == NULL) {
366
380
                virSexprError(VIR_ERR_NO_MEMORY,
367
381
                              _("failed to copy a string"));
 
382
                goto error;
368
383
            }
369
384
        }
370
385
 
431
446
        return NULL;
432
447
    }
433
448
 
434
 
    if (strcmp(sexpr->u.s.car->u.value, token) != 0) {
 
449
    if (STRNEQ(sexpr->u.s.car->u.value, token)) {
435
450
        return NULL;
436
451
    }
437
452
 
449
464
                continue;
450
465
            }
451
466
 
452
 
            if (strcmp(i->u.s.car->u.s.car->u.value, token) == 0) {
 
467
            if (STREQ(i->u.s.car->u.s.car->u.value, token)) {
453
468
                sexpr = i->u.s.car;
454
469
                break;
455
470
            }
483
498
    struct sexpr *s = sexpr_lookup_key(sexpr, node);
484
499
 
485
500
    if (s == NULL)
486
 
        return NULL;
 
501
        return NULL;
487
502
 
488
503
    if (s->kind != SEXPR_CONS || s->u.s.cdr->kind != SEXPR_CONS)
489
504
        return NULL;
509
524
    struct sexpr *s = sexpr_lookup_key(sexpr, node);
510
525
 
511
526
    if (s == NULL)
512
 
        return 0;
 
527
        return 0;
513
528
 
514
529
    if (s->kind != SEXPR_CONS)
515
530
        return 0;