Graphviz
15.0.1~dev.20260609.0243
Loading...
Searching...
No Matches
exerror.c
Go to the documentation of this file.
1
/*************************************************************************
2
* Copyright (c) 2011 AT&T Intellectual Property
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v2.0
5
* which accompanies this distribution, and is available at
6
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
7
*
8
* Contributors: Details at https://graphviz.org
9
*************************************************************************/
10
11
/*
12
* Glenn Fowler
13
* AT&T Research
14
*
15
* expression library
16
*/
17
18
#include "config.h"
19
20
#include <assert.h>
21
#include <
expr/exlib.h
>
22
#include <stdarg.h>
23
#include <stdio.h>
24
#include <stdlib.h>
25
#include <string.h>
26
#include <
util/exit.h
>
27
28
/*
29
* library error handler
30
*/
31
32
static
char
*
make_msg
(
const
char
*
format
, va_list ap) {
33
34
// retrieve buffered message
35
char
buf[64];
36
excontext
(
expr
.
program
, buf,
sizeof
(buf));
37
38
// how many bytes do we need to construct the message?
39
size_t
len
= (size_t)snprintf(
NULL
, 0,
"%s\n -- "
, buf);
40
{
41
va_list ap2;
42
va_copy(ap2, ap);
43
int
r = vsnprintf(
NULL
, 0,
format
, ap2);
44
va_end(ap2);
45
if
(r < 0) {
46
return
strdup(
"malformed format"
);
47
}
48
len
+= (size_t)r + 1;
// +1 for NUL
49
}
50
51
char
*
s
=
malloc
(
len
);
52
if
(
s
==
NULL
) {
53
return
NULL
;
54
}
55
56
int
offset = snprintf(
s
,
len
,
"%s\n -- "
, buf);
57
assert(offset > 0);
58
vsnprintf(
s
+ offset,
len
- (
size_t
)offset,
format
, ap);
59
60
return
s
;
61
}
62
63
void
exerror
(
const
char
*
format
, ...) {
64
if
(
expr
.
program
->disc->errorf && !
expr
.
program
->errors) {
65
va_list ap;
66
67
expr
.
program
->errors = 1;
68
va_start(ap,
format
);
69
char
*
s
=
make_msg
(
format
, ap);
70
va_end(ap);
71
expr
.
program
->disc->errorf(
expr
.
program
->
id
,
expr
.
program
->disc->user, 2,
72
"%s"
,
s
?
s
:
"out of space"
);
73
free
(
s
);
74
}
75
}
76
77
void
exwarn
(
const
char
*
format
, ...) {
78
if
(
expr
.
program
->disc->errorf) {
79
va_list ap;
80
81
va_start(ap,
format
);
82
char
*
s
=
make_msg
(
format
, ap);
83
va_end(ap);
84
expr
.
program
->disc->errorf(
expr
.
program
->
id
,
expr
.
program
->disc->user,
85
ERROR_WARNING
,
"%s"
,
s
?
s
:
"out of space"
);
86
free
(
s
);
87
}
88
}
ERROR_WARNING
#define ERROR_WARNING
Definition
error.h:35
excontext
char * excontext(Expr_t *p, char *buf, int n)
Definition
excontext.c:29
exwarn
void exwarn(const char *format,...)
Definition
exerror.c:77
make_msg
static char * make_msg(const char *format, va_list ap)
Definition
exerror.c:32
exerror
void exerror(const char *format,...)
Definition
exerror.c:63
exit.h
exlib.h
expr
Exstate_t expr
len
static double len(glCompPoint p)
Definition
glutils.c:138
malloc
void * malloc(YYSIZE_T)
free
void free(void *)
NULL
node NULL
Definition
grammar.y:181
format
GVIO_API const char * format
Definition
gvio.h:51
Expr_s::id
const char * id
Definition
expr.h:208
Exstate_t::program
Expr_t * program
Definition
exlib.h:157
s
Definition
grammar.c:90
lib
expr
exerror.c
Generated by
1.9.8