|
|
@@ -26,25 +26,24 @@
|
|
|
|
|
|
|
|
|
extern char *line_eof;
|
|
|
+static int ge_dump_line(int ln, char *buffer);
|
|
|
+
|
|
|
+/* yeah, you know, the color_printk() in that book :-) */
|
|
|
+#define color_error(mode, fg, msg, ...) \
|
|
|
+ ansi_csi_st(stderr, mode, fg, BG_BLACK); \
|
|
|
+ fprintf(stderr, msg, ##__VA_ARGS__); \
|
|
|
+ ansi_csi_ed(stderr); \
|
|
|
+
|
|
|
|
|
|
int generic_error(char *msg, char *line, int lno) {
|
|
|
char *buffer = strndup(line, line_eof - line + 1);
|
|
|
|
|
|
- ansi_csi_st(stderr, MODE_HIGHLIGHT, FG_WHITE, BG_BLACK);
|
|
|
- fprintf(stderr, "tripl: %s:%d: ", fname, lno);
|
|
|
- ansi_csi_ed(stderr);
|
|
|
-
|
|
|
- ansi_csi_st(stderr, MODE_HIGHLIGHT, FG_RED, BG_BLACK);
|
|
|
- fprintf(stderr, "error: ");
|
|
|
- ansi_csi_ed(stderr);
|
|
|
+ color_error(MODE_HIGHLIGHT, FG_WHITE, "tripl: %s:%d: ", fname, lno);
|
|
|
+ color_error(MODE_HIGHLIGHT, FG_RED, "error: ");
|
|
|
|
|
|
fprintf(stderr, "%s\n", msg);
|
|
|
|
|
|
- fprintf(stderr, "%5d | ", lno);
|
|
|
-
|
|
|
- ansi_csi_st(stderr, MODE_LINE, FG_WHITE, BG_BLACK);
|
|
|
- fprintf(stderr, "%s\n", buffer);
|
|
|
- ansi_csi_ed(stderr);
|
|
|
+ ge_dump_line(lno, buffer);
|
|
|
|
|
|
free(buffer);
|
|
|
|
|
|
@@ -52,3 +51,13 @@ int generic_error(char *msg, char *line, int lno) {
|
|
|
}
|
|
|
|
|
|
|
|
|
+static int ge_dump_line(int ln, char *buffer) {
|
|
|
+ while (*buffer && *buffer++ == '\n')
|
|
|
+ ;
|
|
|
+
|
|
|
+ fprintf(stderr, "%5d | %s\n", ln, buffer);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|