aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/sam/error.c
blob: eb4e48f459eb8ae4e19f7867f6789031f0a8e7e7 (plain)
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
#include "sam.h"

static char *emsg[]={
	/* error_s */
	"can't open",
	"can't create",
	"not in menu:",
	"changes to",
	"I/O error:",
	"can't write while changing:",
	/* error_c */
	"unknown command",
	"no operand for",
	"bad delimiter",
	/* error */
	"can't fork",
	"interrupt",
	"address",
	"search",
	"pattern",
	"newline expected",
	"blank expected",
	"pattern expected",
	"can't nest X or Y",
	"unmatched `}'",
	"command takes no address",
	"addresses overlap",
	"substitution",
	"& match too long",
	"bad \\ in rhs",
	"address range",
	"changes not in sequence",
	"addresses out of order",
	"no file name",
	"unmatched `('",
	"unmatched `)'",
	"malformed `[]'",
	"malformed regexp",
	"reg. exp. list overflow",
	"plan 9 command",
	"can't pipe",
	"no current file",
	"string too long",
	"changed files",
	"empty string",
	"file search",
	"non-unique match for \"\"",
	"tag match too long",
	"too many subexpressions",
	"temporary file too large",
	"file is append-only",
	"no destination for plumb message",
	"internal read error in buffer load"
};
static char *wmsg[]={
	/* warn_s */
	"duplicate file name",
	"no such file",
	"write might change good version of",
	/* warn_S */
	"files might be aliased",
	/* warn */
	"null characters elided",
	"can't run pwd",
	"last char not newline",
	"exit status not 0"
};

void
error(Err s)
{
	char buf[512];

	sprint(buf, "?%s", emsg[s]);
	hiccough(buf);
}

void
error_s(Err s, char *a)
{
	char buf[512];

	sprint(buf, "?%s \"%s\"", emsg[s], a);
	hiccough(buf);
}

void
error_r(Err s, char *a)
{
	char buf[512];

	sprint(buf, "?%s \"%s\": %r", emsg[s], a);
	hiccough(buf);
}

void
error_c(Err s, int c)
{
	char buf[512];

	sprint(buf, "?%s `%C'", emsg[s], c);
	hiccough(buf);
}

void
warn(Warn s)
{
	dprint("?warning: %s\n", wmsg[s]);
}

void
warn_S(Warn s, String *a)
{
	print_s(wmsg[s], a);
}

void
warn_SS(Warn s, String *a, String *b)
{
	print_ss(wmsg[s], a, b);
}

void
warn_s(Warn s, char *a)
{
	dprint("?warning: %s `%s'\n", wmsg[s], a);
}

void
termwrite(char *s)
{
	String *p;

	if(downloaded){
		p = tmpcstr(s);
		if(cmd)
			loginsert(cmd, cmdpt, p->s, p->n);
		else
			Strinsert(&cmdstr, p, cmdstr.n);
		cmdptadv += p->n;
		free(p);
	}else
		Write(2, s, strlen(s));
}