Graphviz 13.1.2~dev.20250722.1051
Loading...
Searching...
No Matches
error.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 * standalone mini error implementation
13 */
14
15#include <ast/ast.h>
16#include <ast/error.h>
17#include <stddef.h>
18#include <stdio.h>
19#include <errno.h>
20#include <util/exit.h>
21
23
24void setErrorLine (int line) { error_info.line = line; }
25void setErrorFileLine (char* src, int line) {
26 error_info.file = src;
27 error_info.line = line;
28}
29void setErrorId (char* id) { error_info.id = id; }
31int getErrorErrors (void) { return error_info.errors; }
32void setTraceLevel (int i) { error_info.trace = i; }
33
34void errorv(const char *id, int level, const char *s, va_list ap)
35{
36 int flags;
37
38 if (level < error_info.trace) return;
39 if (level < 0)
40 flags = 0;
41 else {
42 flags = level & ~ERROR_LEVEL;
43 level &= ERROR_LEVEL;
44 }
45 const char *prefix;
46 if (level && ((prefix = error_info.id) || (prefix = id))) {
47 if (flags & ERROR_USAGE)
48 fprintf(stderr, "Usage: %s ", prefix);
49 else
50 fprintf(stderr, "%s: ", prefix);
51 }
52 if (flags & ERROR_USAGE)
53 /*nop */ ;
54 else if (level < 0) {
55 int i;
56 for (i = 0; i < error_info.indent; i++)
57 fprintf(stderr, " ");
58 fprintf(stderr, "debug%d: ", level);
59 } else if (level) {
60 if (level == ERROR_WARNING) {
61 fprintf(stderr, "warning: ");
63 } else {
65 if (level == ERROR_PANIC)
66 fprintf(stderr, "panic: ");
67 }
68 if (error_info.line) {
70 fprintf(stderr, "\"%s\", ", error_info.file);
71 fprintf(stderr, "line %d: ", error_info.line);
72 }
73 }
74 vfprintf(stderr, s, ap);
75 fprintf(stderr, "\n");
76 if (level >= ERROR_FATAL)
77 graphviz_exit(level - ERROR_FATAL + 1);
78}
79
80void error(int level, const char *s, ...)
81{
82 va_list ap;
83
84 va_start(ap, s);
85 errorv(NULL, level, s, ap);
86 va_end(ap);
87}
88
89void errorf(void *handle, void *discipline, int level, const char *s, ...)
90{
91 va_list ap;
92
93 va_start(ap, s);
94 errorv((discipline
95 && handle) ? *((char **) handle) : (char *) handle, level, s, ap);
96 va_end(ap);
97}
void setTraceLevel(int i)
Definition error.c:32
int getErrorErrors(void)
Definition error.c:31
Error_info_t error_info
Definition error.c:22
void errorf(void *handle, void *discipline, int level, const char *s,...)
Definition error.c:89
void setErrorLine(int line)
Definition error.c:24
void setErrorFileLine(char *src, int line)
Definition error.c:25
void errorv(const char *id, int level, const char *s, va_list ap)
Definition error.c:34
void setErrorId(char *id)
Definition error.c:29
void setErrorErrors(int errors)
Definition error.c:30
#define ERROR_WARNING
Definition error.h:35
#define ERROR_FATAL
Definition error.h:37
#define ERROR_LEVEL
Definition error.h:40
#define ERROR_PANIC
Definition error.h:38
#define ERROR_USAGE
Definition error.h:41
static NORETURN void graphviz_exit(int status)
Definition exit.h:23
static int flags
Definition gc.c:61
require define api prefix
Definition gmlparse.y:17
static int errors
Definition gmlscan.c:847
node NULL
Definition grammar.y:180
static uint64_t id
Definition gv2gml.c:40
table Syntax error
Definition htmlparse.y:294
int trace
Definition error.h:29
int indent
Definition error.h:26
char * id
Definition error.h:31
int warnings
Definition error.h:28
char * file
Definition error.h:30
int line
Definition error.h:27
int errors
Definition error.h:25
Definition grammar.c:89