File: die.c

package info (click to toggle)
aoeui 1.7%2B20160302.git4e5dee9-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 532 kB
  • sloc: ansic: 6,860; makefile: 296; sh: 11
file content (68 lines) | stat: -rw-r--r-- 1,606 bytes parent folder | download | duplicates (4)
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
/* Copyright 2007, 2008 Peter Klausler.  See COPYING for license. */
#include "all.h"

/* Error messaging */

void die(const char *msg, ...)
{
	int err = errno;
	va_list ap;

	tcsetattr(1, TCSANOW, &original_termios);
	fputs("\afatal editor error: ", stderr);
	va_start(ap, msg);
	vfprintf(stderr, msg, ap);
	va_end(ap);
	if (err)
		fprintf(stderr, ": %s", strerror(err));
	fputc('\n', stderr);
	exit(EXIT_FAILURE);
}

void message(const char *msg, ...)
{
	int err = errno;
	va_list ap;
	struct view *view = view_find("* ATTENTION *");
	position_t start;

	if (!view)
		view = text_create("* ATTENTION *", TEXT_EDITOR);
	view->text->flags &= ~TEXT_RDONLY;
	view_insert(view, "\n", view->bytes, 1);
	start = view->bytes;
	va_start(ap, msg);
	view_vprintf(view, msg, ap);
	va_end(ap);
	if (err)
		view_printf(view, "\n(System error code: %s)", strerror(err));
	view_insert(view, " ", view->bytes, 1);
	view->text->flags |= TEXT_RDONLY;
	locus_set(view, CURSOR, start);
	window_below(NULL, view, 3 + !!err);
}

static struct view *status_view;

void status(const char *msg, ...)
{
	va_list ap;

	if (!status_view)
		status_view = text_create("* STATUS *", TEXT_EDITOR);
	status_view->text->flags &= ~TEXT_RDONLY;
	view_delete(status_view, 0, status_view->bytes);
	va_start(ap, msg);
	view_vprintf(status_view, msg, ap);
	va_end(ap);
	view_insert(status_view, " ", status_view->bytes, 1);
	locus_set(status_view, CURSOR, status_view->bytes-1);
	status_view->text->flags |= TEXT_RDONLY;
	window_below(NULL, status_view, 3);
}

void status_hide(void)
{
	if (status_view)
		window_destroy(status_view->window);
}