File: err.c

package info (click to toggle)
ruby-ox 2.14.23-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,504 kB
  • sloc: xml: 39,683; ansic: 9,626; ruby: 6,441; sh: 47; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* err.c
 * Copyright (c) 2011, Peter Ohler
 * All rights reserved.
 */

#include "err.h"

#include <stdarg.h>

void ox_err_set(Err e, VALUE clas, const char *format, ...) {
    va_list ap;

    va_start(ap, format);
    e->clas = clas;
    vsnprintf(e->msg, sizeof(e->msg) - 1, format, ap);
    va_end(ap);
}

#if __GNUC__ > 4
_Noreturn void
#else
void
#endif
ox_err_raise(Err e) {
    rb_raise(e->clas, "%s", e->msg);
}

void _ox_err_set_with_location(Err         err,
                               const char *msg,
                               const char *xml,
                               const char *current,
                               const char *file,
                               int         line) {
    int xline = 1;
    int col   = 1;

    for (; xml < current && '\n' != *current; current--) {
        col++;
    }
    for (; xml < current; current--) {
        if ('\n' == *current) {
            xline++;
        }
    }
    ox_err_set(err, ox_parse_error_class, "%s at line %d, column %d [%s:%d]\n", msg, xline, col, file, line);
}