Graphviz 13.0.0~dev.20241220.2304
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 <string.h>
20#include <errno.h>
21#include <util/exit.h>
22
24
25void setErrorLine (int line) { error_info.line = line; }
26void setErrorFileLine (char* src, int line) {
27 error_info.file = src;
28 error_info.line = line;
29}
30void setErrorId (char* id) { error_info.id = id; }
32int getErrorErrors (void) { return error_info.errors; }
33void setTraceLevel (int i) { error_info.trace = i; }
34
35void errorv(const char *id, int level, const char *s, va_list ap)
36{
37 int flags;
38
39 if (level < error_info.trace) return;
40 if (level < 0)
41 flags = 0;
42 else {
43 flags = level & ~ERROR_LEVEL;
44 level &= ERROR_LEVEL;
45 }
46 const char *prefix;
47 if (level && ((prefix = error_info.id) || (prefix = id))) {
48 if (flags & ERROR_USAGE)
49 fprintf(stderr, "Usage: %s ", prefix);
50 else
51 fprintf(stderr, "%s: ", prefix);
52 }
53 if (flags & ERROR_USAGE)
54 /*nop */ ;
55 else if (level < 0) {
56 int i;
57 for (i = 0; i < error_info.indent; i++)
58 fprintf(stderr, " ");
59 fprintf(stderr, "debug%d: ", level);
60 } else if (level) {
61 if (level == ERROR_WARNING) {
62 fprintf(stderr, "warning: ");
64 } else {
66 if (level == ERROR_PANIC)
67 fprintf(stderr, "panic: ");
68 }
69 if (error_info.line) {
71 fprintf(stderr, "\"%s\", ", error_info.file);
72 fprintf(stderr, "line %d: ", error_info.line);
73 }
74 }
75 vfprintf(stderr, s, ap);
76 if (flags & ERROR_SYSTEM)
77 fprintf(stderr, "\n%s", strerror(errno));
78 fprintf(stderr, "\n");
79 if (level >= ERROR_FATAL)
80 graphviz_exit(level - ERROR_FATAL + 1);
81}
82
83void error(int level, const char *s, ...)
84{
85 va_list ap;
86
87 va_start(ap, s);
88 errorv(NULL, level, s, ap);
89 va_end(ap);
90}
91
92void errorf(void *handle, void *discipline, int level, const char *s, ...)
93{
94 va_list ap;
95
96 va_start(ap, s);
97 errorv((discipline
98 && handle) ? *((char **) handle) : (char *) handle, level, s, ap);
99 va_end(ap);
100}
void setTraceLevel(int i)
Definition error.c:33
int getErrorErrors(void)
Definition error.c:32
Error_info_t error_info
Definition error.c:23
void errorf(void *handle, void *discipline, int level, const char *s,...)
Definition error.c:92
void setErrorLine(int line)
Definition error.c:25
void setErrorFileLine(char *src, int line)
Definition error.c:26
void errorv(const char *id, int level, const char *s, va_list ap)
Definition error.c:35
void setErrorId(char *id)
Definition error.c:30
void setErrorErrors(int errors)
Definition error.c:31
#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_SYSTEM
Definition error.h:41
#define ERROR_USAGE
Definition error.h:42
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:846
node NULL
Definition grammar.y:163
static uint64_t id
Definition gv2gml.c:42
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:93