26 |
#include "alloc.h" |
#include "alloc.h" |
27 |
#include "command.h" |
#include "command.h" |
28 |
#include "getline.h" |
#include "getline.h" |
29 |
|
#include "glob.h" |
30 |
|
#include "lexer.h" |
31 |
#include "main.h" |
#include "main.h" |
32 |
#include "output.h" |
#include "output.h" |
33 |
#include "settings.h" |
#include "settings.h" |
53 |
void |
void |
54 |
tmsg (int class, const char *title, const char *format, ...) |
tmsg (int class, const char *title, const char *format, ...) |
55 |
{ |
{ |
56 |
char buf[1024]; |
struct error e; |
57 |
|
va_list args; |
|
/* Format the message into BUF. */ |
|
|
{ |
|
|
va_list args; |
|
|
|
|
|
va_start (args, format); |
|
|
vsnprintf (buf, 1024, format, args); |
|
|
va_end (args); |
|
|
} |
|
|
|
|
|
/* Output the message. */ |
|
|
{ |
|
|
struct error e; |
|
58 |
|
|
59 |
e.class = class; |
e.class = class; |
60 |
err_location (&e.where); |
err_location (&e.where); |
61 |
e.title = title; |
e.title = title; |
62 |
e.text = buf; |
|
63 |
err_vmsg (&e); |
va_start (args, format); |
64 |
} |
err_vmsg (&e, format, args); |
65 |
|
va_end (args); |
66 |
} |
} |
67 |
|
|
68 |
/* Writes error message in CLASS, with text FORMAT, formatted with |
/* Writes error message in CLASS, with text FORMAT, formatted with |
70 |
void |
void |
71 |
msg (int class, const char *format, ...) |
msg (int class, const char *format, ...) |
72 |
{ |
{ |
73 |
struct string buf; |
struct error e; |
74 |
|
va_list args; |
|
ds_init (&buf, 1024); |
|
|
|
|
|
/* Format the message into BUF. */ |
|
|
{ |
|
|
va_list args; |
|
|
|
|
|
va_start (args, format); |
|
|
ds_vprintf (&buf, format, args); |
|
|
va_end (args); |
|
|
} |
|
|
|
|
|
/* Output the message. */ |
|
|
{ |
|
|
struct error e; |
|
|
|
|
|
e.class = class; |
|
|
err_location (&e.where); |
|
|
e.title = NULL; |
|
|
e.text = buf.string; |
|
|
err_vmsg (&e); |
|
|
} |
|
75 |
|
|
76 |
ds_destroy (&buf); |
e.class = class; |
77 |
|
err_location (&e.where); |
78 |
|
e.title = NULL; |
79 |
|
|
80 |
|
va_start (args, format); |
81 |
|
err_vmsg (&e, format, args); |
82 |
|
va_end (args); |
83 |
} |
} |
84 |
|
|
85 |
/* Terminate due to fatal error in input. */ |
/* Terminate due to fatal error in input. */ |
215 |
void (*func) (const char *), unsigned width); |
void (*func) (const char *), unsigned width); |
216 |
|
|
217 |
void |
void |
218 |
err_vmsg (const struct error *e) |
err_vmsg (const struct error *e, const char *format, va_list args) |
219 |
{ |
{ |
220 |
/* Class flags. */ |
/* Class flags. */ |
221 |
enum |
enum |
261 |
class &= ERR_CLASS_MASK; |
class &= ERR_CLASS_MASK; |
262 |
|
|
263 |
assert (class >= 0 && class < ERR_CLASS_COUNT); |
assert (class >= 0 && class < ERR_CLASS_COUNT); |
264 |
assert (e->text != NULL); |
assert (format != NULL); |
265 |
|
|
266 |
ds_init (&msg, 64); |
ds_init (&msg, 64); |
267 |
if (e->where.filename && (error_classes[class].flags & ERR_WITH_FILE)) |
if (e->where.filename && (error_classes[class].flags & ERR_WITH_FILE)) |
286 |
if (e->title) |
if (e->title) |
287 |
ds_puts (&msg, e->title); |
ds_puts (&msg, e->title); |
288 |
|
|
289 |
ds_puts (&msg, e->text); |
ds_vprintf (&msg, format, args); |
290 |
|
|
291 |
/* FIXME: Check set_messages and set_errors to determine where to |
/* FIXME: Check set_messages and set_errors to determine where to |
292 |
send errors and messages. |
send errors and messages. |
480 |
memset (buf, ' ', indent); |
memset (buf, ' ', indent); |
481 |
memcpy (&buf[indent], cp, cp2 - cp); |
memcpy (&buf[indent], cp, cp2 - cp); |
482 |
|
|
|
if ( hard_break) |
|
|
{ |
|
|
buf[indent + idx + cp2 - cp] = '\n'; |
|
|
++idx; |
|
|
} |
|
483 |
buf[indent + idx + cp2 - cp] = '\0'; |
buf[indent + idx + cp2 - cp] = '\0'; |
484 |
func (buf); |
func (buf); |
485 |
cp = cp2; |
cp = cp2; |