-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathate_errors.c
132 lines (108 loc) · 3.21 KB
/
ate_errors.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* @file ate_errors.c
* @brief Single location for printing error messages. Prepares development
* to disable messages in a single place.
*/
#include <builtins.h>
#ifndef EXECUTION_FAILURE
#include <shell.h>
#endif
#include <stdio.h>
#include <assert.h>
#include <stdarg.h>
// Declared in ate.c
extern const char Error_Name[];
#include "ate_utilities.h"
void save_to_error_shell_var(const char *str)
{
SHELL_VAR *var = find_variable(Error_Name);
if (var == NULL)
var = bind_variable(Error_Name, (char*)str, 0);
else
{
ate_dispose_variable_value(var);
var->value = savestring(str);
var->attributes = 0;
}
}
void ate_register_error(const char *format, ...)
{
va_list args_list;
int len = 0;
char *buffer = NULL;
while(1)
{
va_start(args_list, format);
len = vsnprintf(buffer, len, format, args_list);
va_end(args_list);
if (buffer == NULL)
buffer = alloca(++len);
else
{
save_to_error_shell_var(buffer);
break;
}
}
}
void ate_register_unknown_option(char option)
{
ate_register_error("option '-%c' is not recognized", option);
}
void ate_register_wrong_report_type(char option, const char *action)
{
char instead = option=='a'?'v':'a';
ate_register_error("reporting option -%c not supported by action '%s', use -%c", option, action, instead);
}
void ate_register_option_missing_argument(char option)
{
ate_register_error("option '-%c' must be followed by a non-option argument", option);
}
void ate_register_variable_not_found(const char *name)
{
ate_register_error("variable '%s' is not found", name);
}
void ate_register_function_not_found(const char *name)
{
ate_register_error("function '%s' is not found", name);
}
void ate_register_variable_wrong_type(const char *name, const char *desired_type)
{
ate_register_error("variable '%s' should be type %s", name, desired_type);
}
void ate_register_argument_wrong_type(const char *value, const char *desired_type)
{
ate_register_error("argument value '%s' should be type %s", value, desired_type);
}
void ate_register_empty_table(const char *handle_name)
{
ate_register_error("ate handle '%s' is empty or unindexed", handle_name);
}
void ate_register_corrupt_table(void)
{
ate_register_error("the ate handle is corrupted");
}
void ate_register_not_an_int(const char *str, const char *action)
{
ate_register_error("'%s' will not convert to an integer in action '%s'", str, action);
}
void ate_register_invalid_row_index(int requested, int available)
{
ate_register_error("index %d is invalid in list of %d rows", requested, available);
}
void ate_register_invalid_row_size(int row_size, int el_count)
{
ate_register_error("invalid row size: %d does not divide evenly into %d elements",
row_size, el_count);
}
void ate_register_missing_argument(const char *name, const char *action)
{
ate_register_error("missing '%s' argument in action '%s'", name, action);
}
void ate_register_failed_to_create(const char *name)
{
ate_register_error("failed to create variable '%s'", name);
}
void ate_register_unexpected_error(const char *doing)
{
ate_register_error("encountered unexpected error while %s", doing);
}