Revision a12eeaaa qerror.c

b/qerror.c
326 326
    return qerr;
327 327
}
328 328

  
329
static void parse_error(const QError *qerror, int c)
329
static void parse_error(const QErrorStringTable *entry, int c)
330 330
{
331
    qerror_abort(qerror, "expected '%c' in '%s'", c, qerror->entry->desc);
331
    fprintf(stderr, "expected '%c' in '%s'", c, entry->desc);
332
    abort();
332 333
}
333 334

  
334
static const char *append_field(QString *outstr, const QError *qerror,
335
static const char *append_field(QDict *error, QString *outstr,
336
                                const QErrorStringTable *entry,
335 337
                                const char *start)
336 338
{
337 339
    QObject *obj;
......
340 342
    const char *end, *key;
341 343

  
342 344
    if (*start != '%')
343
        parse_error(qerror, '%');
345
        parse_error(entry, '%');
344 346
    start++;
345 347
    if (*start != '(')
346
        parse_error(qerror, '(');
348
        parse_error(entry, '(');
347 349
    start++;
348 350

  
349 351
    end = strchr(start, ')');
350 352
    if (!end)
351
        parse_error(qerror, ')');
353
        parse_error(entry, ')');
352 354

  
353 355
    key_qs = qstring_from_substr(start, 0, end - start - 1);
354 356
    key = qstring_get_str(key_qs);
355 357

  
356
    qdict = qobject_to_qdict(qdict_get(qerror->error, "data"));
358
    qdict = qobject_to_qdict(qdict_get(error, "data"));
357 359
    obj = qdict_get(qdict, key);
358 360
    if (!obj) {
359
        qerror_abort(qerror, "key '%s' not found in QDict", key);
361
        abort();
360 362
    }
361 363

  
362 364
    switch (qobject_type(obj)) {
......
367 369
            qstring_append_int(outstr, qdict_get_int(qdict, key));
368 370
            break;
369 371
        default:
370
            qerror_abort(qerror, "invalid type '%c'", qobject_type(obj));
372
            abort();
371 373
    }
372 374

  
373 375
    QDECREF(key_qs);
374 376
    return ++end;
375 377
}
376 378

  
377
/**
378
 * qerror_human(): Format QError data into human-readable string.
379
 *
380
 * Formats according to member 'desc' of the specified QError object.
381
 */
382
QString *qerror_human(const QError *qerror)
379
static QString *qerror_format_desc(QDict *error,
380
                                   const QErrorStringTable *entry)
383 381
{
384
    const char *p;
385 382
    QString *qstring;
383
    const char *p;
386 384

  
387
    assert(qerror->entry != NULL);
385
    assert(entry != NULL);
388 386

  
389 387
    qstring = qstring_new();
390 388

  
391
    for (p = qerror->entry->desc; *p != '\0';) {
389
    for (p = entry->desc; *p != '\0';) {
392 390
        if (*p != '%') {
393 391
            qstring_append_chr(qstring, *p++);
394 392
        } else if (*(p + 1) == '%') {
395 393
            qstring_append_chr(qstring, '%');
396 394
            p += 2;
397 395
        } else {
398
            p = append_field(qstring, qerror, p);
396
            p = append_field(error, qstring, entry, p);
399 397
        }
400 398
    }
401 399

  
......
403 401
}
404 402

  
405 403
/**
404
 * qerror_human(): Format QError data into human-readable string.
405
 */
406
QString *qerror_human(const QError *qerror)
407
{
408
    return qerror_format_desc(qerror->error, qerror->entry);
409
}
410

  
411
/**
406 412
 * qerror_print(): Print QError data
407 413
 *
408 414
 * This function will print the member 'desc' of the specified QError object,

Also available in: Unified diff