xref: /plan9/sys/src/cmd/sam/error.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
1 #include "sam.h"
2 
3 static char *emsg[]={
4 	/* error_s */
5 	"can't open",
6 	"can't create",
7 	"not in menu:",
8 	"changes to",
9 	"I/O error:",
10 	/* error_c */
11 	"unknown command",
12 	"no operand for",
13 	"bad delimiter",
14 	/* error */
15 	"can't fork",
16 	"interrupt",
17 	"address",
18 	"search",
19 	"pattern",
20 	"newline expected",
21 	"blank expected",
22 	"pattern expected",
23 	"can't nest X or Y",
24 	"unmatched `}'",
25 	"command takes no address",
26 	"addresses overlap",
27 	"substitution",
28 	"& match too long",
29 	"bad \\ in rhs",
30 	"address range",
31 	"changes not in sequence",
32 	"addresses out of order",
33 	"no file name",
34 	"unmatched `('",
35 	"unmatched `)'",
36 	"malformed `[]'",
37 	"malformed regexp",
38 	"reg. exp. list overflow",
39 	"plan 9 command",
40 	"can't pipe",
41 	"no current file",
42 	"string too long",
43 	"changed files",
44 	"empty string",
45 	"file search",
46 	"non-unique match for \"\"",
47 	"tag match too long",
48 	"too many subexpressions",
49 	"temporary file too large",
50 	"file is append-only",
51 };
52 static char *wmsg[]={
53 	/* warn_s */
54 	"duplicate file name",
55 	"no such file",
56 	"write might change good version of",
57 	/* warn_S */
58 	"files might be aliased",
59 	/* warn */
60 	"null characters elided",
61 	"can't run pwd",
62 	"last char not newline",
63 	"exit status not 0",
64 };
65 
66 void
67 error(Err s)
68 {
69 	char buf[512];
70 
71 	sprint(buf, "?%s", emsg[s]);
72 	hiccough(buf);
73 }
74 
75 void
76 error_s(Err s, char *a)
77 {
78 	char buf[512];
79 
80 	sprint(buf, "?%s \"%s\"", emsg[s], a);
81 	hiccough(buf);
82 }
83 
84 void
85 error_c(Err s, int c)
86 {
87 	char buf[512];
88 
89 	sprint(buf, "?%s `%C'", emsg[s], c);
90 	hiccough(buf);
91 }
92 
93 void
94 warn(Warn s)
95 {
96 	dprint("?warning: %s\n", wmsg[s]);
97 }
98 
99 void
100 warn_S(Warn s, String *a)
101 {
102 	print_s(wmsg[s], a);
103 }
104 
105 void
106 warn_SS(Warn s, String *a, String *b)
107 {
108 	print_ss(wmsg[s], a, b);
109 }
110 
111 void
112 warn_s(Warn s, char *a)
113 {
114 	dprint("?warning: %s `%s'\n", wmsg[s], a);
115 }
116 
117 void
118 termwrite(char *s)
119 {
120 	String *p;
121 
122 	if(downloaded){
123 		p = tmpcstr(s);
124 		if(cmd)
125 			Finsert(cmd, p, cmdpt);
126 		else
127 			Strinsert(&cmdstr, p, cmdstr.n);
128 		cmdptadv += p->n;
129 	}else
130 		Write(2, s, strlen(s));
131 }
132