Graphviz 12.0.1~dev.20240716.0800
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 v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.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 <assert.h>
19#include <cgraph/exit.h>
20#include <expr/exlib.h>
21#include <stdarg.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
26/*
27 * library error handler
28 */
29
30static char *make_msg(const char *format, va_list ap) {
31
32 // retrieve buffered message
33 char buf[64];
34 excontext(expr.program, buf, sizeof(buf));
35
36 // how many bytes do we need to construct the message?
37 size_t len = (size_t)snprintf(NULL, 0, "%s\n -- ", buf);
38 {
39 va_list ap2;
40 va_copy(ap2, ap);
41 int r = vsnprintf(NULL, 0, format, ap2);
42 va_end(ap2);
43 if (r < 0) {
44 return strdup("malformed format");
45 }
46 len += (size_t)r + 1; // +1 for NUL
47 }
48
49 char *s = malloc(len);
50 if (s == NULL) {
51 return NULL;
52 }
53
54 int offset = snprintf(s, len, "%s\n -- ", buf);
55 assert(offset > 0);
56 vsnprintf(s + offset, len - (size_t)offset, format, ap);
57
58 return s;
59}
60
61void
62exerror(const char* format, ...)
63{
64 if (expr.program->disc->errorf && !expr.program->errors)
65 {
66 va_list ap;
67
68 expr.program->errors = 1;
69 va_start(ap, format);
70 char *s = make_msg(format, ap);
71 va_end(ap);
72 expr.program->disc->errorf(expr.program, expr.program->disc, 2, "%s",
73 s ? s : "out of space");
74 free(s);
75 }
76}
77
78void
79exwarn(const char *format, ...)
80{
81 if (expr.program->disc->errorf) {
82 va_list ap;
83
84 va_start(ap, format);
85 char *s = make_msg(format, ap);
86 va_end(ap);
87 expr.program->disc->errorf(expr.program, expr.program->disc,
88 ERROR_WARNING, "%s", s ? s : "out of space");
89 free(s);
90 }
91}
#define ERROR_WARNING
Definition error.h:35
char * excontext(Expr_t *p, char *buf, int n)
Definition excontext.c:27
void exwarn(const char *format,...)
Definition exerror.c:79
static char * make_msg(const char *format, va_list ap)
Definition exerror.c:30
void exerror(const char *format,...)
Definition exerror.c:62
Exstate_t expr
static double len(glCompPoint p)
Definition glutils.c:150
void * malloc(YYSIZE_T)
void free(void *)
node NULL
Definition grammar.y:149
swig_ptr_object_handlers offset
Definition gv_php.cpp:5915
GVIO_API const char * format
Definition gvio.h:51
Expr_t * program
Definition exlib.h:157
Definition grammar.c:93