-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_and_warnings.c
161 lines (139 loc) · 4.88 KB
/
errors_and_warnings.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
#include "common_header.h" // all the standard stuff
#include <gtk/gtk.h> // sudo apt-get install libgtk-3-dev
#define TEXT_BUFFER_SIZE 4096
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
extern GtkWidget *window;
extern GtkWidget *console;
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
void gui_program_error_dialog_box
(
const char *path_file, int line, const char *function_name,
const char *control, ...
)
{
va_list parms;
char text[TEXT_BUFFER_SIZE];
GtkWidget *dialog;
va_start(parms, control);
vsnprintf(text, TEXT_BUFFER_SIZE, control, parms);
printf(ANSI_COLOR_RED"** error ** %-40s\n", text);
printf("(in file: %s at line: %d in function: %s)\n"ANSI_COLOR_RESET,
(path_file), line, function_name);
dialog = gtk_message_dialog_new
(
GTK_WINDOW(window),
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"%s\nin function '%s'\nin file '%s' line %d",
text, function_name, (path_file), line
);
//gtk_window_set_title(GTK_WINDOW(dialog),
//"Okay, Houston, we've had a problem here.");
gtk_window_set_title(GTK_WINDOW(dialog),
"Oh, shit ! ");
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
exit(EXIT_FAILURE);
va_end(parms);
}
/*------------------------------------------------------------------------------
gui_warning_dialog_box(__FILE__, __LINE__, __FUNC__, "a test warning");
------------------------------------------------------------------------------*/
void gui_warning_dialog_box
(
const char *path_file, int line, const char *function_name,
const char *control, ...
)
{
va_list parms;
char text[TEXT_BUFFER_SIZE];
GtkWidget *dialog;
va_start(parms, control);
vsnprintf(text, TEXT_BUFFER_SIZE, control, parms);
printf("** warning ** %-40s\n", text);
printf("(in file: %s at line: %d\nin function: %s)\n",
(path_file), line, function_name);
dialog = gtk_message_dialog_new
(
GTK_WINDOW(window),
GTK_DIALOG_MODAL,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_CLOSE,
"%s\nin function '%s'\nin file '%s' line %d",
text, function_name, (path_file), line
);
gtk_window_set_title(GTK_WINDOW(dialog), "Oh dear ! ");
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
va_end(parms);
}
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
void gui_information_dialog_box(const char *control, ...)
{
va_list parms;
char text[TEXT_BUFFER_SIZE];
GtkWidget *dialog;
va_start(parms, control);
vsnprintf(text, TEXT_BUFFER_SIZE, control, parms);
printf("gtk_message_dialog_new='%s'", text);
dialog = gtk_message_dialog_new
(
GTK_WINDOW(window),
GTK_DIALOG_MODAL,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_CLOSE,
"%s", text
);
gtk_window_set_title(GTK_WINDOW(dialog), "information");
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
va_end(parms);
}
/*------------------------------------------------------------------------------
this is a gui version of printf that prints to the Gtk console window
------------------------------------------------------------------------------*/
void gui_printf(const char *control, ...)
{
va_list parms;
GtkTextBuffer *console_buffer;
GtkTextMark *console_mark;
char text[TEXT_BUFFER_SIZE];
va_start(parms, control);
vsnprintf(text, TEXT_BUFFER_SIZE, control, parms);
//vsprintf(text, control, parms);
console_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(console));
//printf("OK '%s' %d\n", text, __LINE__);
gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(console_buffer), text, -1);
//printf("OK '%s' %d\n", text, __LINE__);
console_mark = gtk_text_buffer_get_insert(GTK_TEXT_BUFFER(console_buffer));
gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(console), console_mark);
va_end(parms);
while(gtk_events_pending()) gtk_main_iteration();
}
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
void program_information
(
const char *path_file, int line, const char *func,
const char *control, ...
)
{
va_list parms;
char text[4096]; // text expansion buffer
printf(ANSI_COLOR_GREEN);
va_start(parms, control);
vsprintf(text, control, parms);
printf("\n* information * %s\n", text);
printf("(in file: %s at line: %d in function: %s)\n",
path_file, line, func);
printf(ANSI_COLOR_RESET);
va_end(parms);
}
/*------------------------------------------------------------------------------
------------------------------------------------------------------------------*/