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