xref: /minix3/minix/commands/cawf/error.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /*
2*433d6423SLionel Sambuc  *	error.c - error handling functions for cawf(1)
3*433d6423SLionel Sambuc  */
4*433d6423SLionel Sambuc 
5*433d6423SLionel Sambuc /*
6*433d6423SLionel Sambuc  *	Copyright (c) 1991 Purdue University Research Foundation,
7*433d6423SLionel Sambuc  *	West Lafayette, Indiana 47907.  All rights reserved.
8*433d6423SLionel Sambuc  *
9*433d6423SLionel Sambuc  *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
10*433d6423SLionel Sambuc  *	University Computing Center.  Not derived from licensed software;
11*433d6423SLionel Sambuc  *	derived from awf(1) by Henry Spencer of the University of Toronto.
12*433d6423SLionel Sambuc  *
13*433d6423SLionel Sambuc  *	Permission is granted to anyone to use this software for any
14*433d6423SLionel Sambuc  *	purpose on any computer system, and to alter it and redistribute
15*433d6423SLionel Sambuc  *	it freely, subject to the following restrictions:
16*433d6423SLionel Sambuc  *
17*433d6423SLionel Sambuc  *	1. The author is not responsible for any consequences of use of
18*433d6423SLionel Sambuc  *	   this software, even if they arise from flaws in it.
19*433d6423SLionel Sambuc  *
20*433d6423SLionel Sambuc  *	2. The origin of this software must not be misrepresented, either
21*433d6423SLionel Sambuc  *	   by explicit claim or by omission.  Credits must appear in the
22*433d6423SLionel Sambuc  *	   documentation.
23*433d6423SLionel Sambuc  *
24*433d6423SLionel Sambuc  *	3. Altered versions must be plainly marked as such, and must not
25*433d6423SLionel Sambuc  *	   be misrepresented as being the original software.  Credits must
26*433d6423SLionel Sambuc  *	   appear in the documentation.
27*433d6423SLionel Sambuc  *
28*433d6423SLionel Sambuc  *	4. This notice may not be removed or altered.
29*433d6423SLionel Sambuc  */
30*433d6423SLionel Sambuc 
31*433d6423SLionel Sambuc #include "cawf.h"
32*433d6423SLionel Sambuc 
33*433d6423SLionel Sambuc 
34*433d6423SLionel Sambuc /*
35*433d6423SLionel Sambuc  * Error(t, l, s1, s2) - issue error message
36*433d6423SLionel Sambuc  */
37*433d6423SLionel Sambuc 
38*433d6423SLionel Sambuc void
39*433d6423SLionel Sambuc Error(t, l, s1, s2)
40*433d6423SLionel Sambuc 	int t;				/* type: WARN or FATAL */
41*433d6423SLionel Sambuc 	int l;				/* LINE: display Line[] */
42*433d6423SLionel Sambuc 	char *s1, *s2;			/* optional text */
43*433d6423SLionel Sambuc {
44*433d6423SLionel Sambuc 	char msg[MAXLINE];		/* message */
45*433d6423SLionel Sambuc 
46*433d6423SLionel Sambuc 	if (t == WARN && !Dowarn) return;
47*433d6423SLionel Sambuc 
48*433d6423SLionel Sambuc 	if (l == LINE)
49*433d6423SLionel Sambuc 		(void) fprintf(Efs, "%s: (%s, %d):%s%s - %s\n",
50*433d6423SLionel Sambuc 			Pname,
51*433d6423SLionel Sambuc 			Inname,
52*433d6423SLionel Sambuc 			NR,
53*433d6423SLionel Sambuc 			(s1 == NULL) ? "" : s1,
54*433d6423SLionel Sambuc 			(s2 == NULL) ? "" : s2,
55*433d6423SLionel Sambuc 			Line);
56*433d6423SLionel Sambuc 	else
57*433d6423SLionel Sambuc 		(void) fprintf(Efs, "%s:%s%s\n",
58*433d6423SLionel Sambuc 			Pname,
59*433d6423SLionel Sambuc 			(s1 == NULL) ? "" : s1,
60*433d6423SLionel Sambuc 			(s2 == NULL) ? "" : s2);
61*433d6423SLionel Sambuc 	if (t == FATAL)
62*433d6423SLionel Sambuc 		exit(1);
63*433d6423SLionel Sambuc 	Err = 1;
64*433d6423SLionel Sambuc 	return;
65*433d6423SLionel Sambuc }
66*433d6423SLionel Sambuc 
67*433d6423SLionel Sambuc 
68*433d6423SLionel Sambuc /*
69*433d6423SLionel Sambuc  * Error3(len, word, sarg, narg) - process error in pass3
70*433d6423SLionel Sambuc  */
71*433d6423SLionel Sambuc 
72*433d6423SLionel Sambuc void
73*433d6423SLionel Sambuc Error3(len, word, sarg, narg, msg)
74*433d6423SLionel Sambuc 	int len;			/* length (negative is special */
75*433d6423SLionel Sambuc         char *word;			/* word */
76*433d6423SLionel Sambuc         char *sarg;			/* string argument */
77*433d6423SLionel Sambuc         int narg;                       /* numeric argument */
78*433d6423SLionel Sambuc 	char *msg;			/* message */
79*433d6423SLionel Sambuc {
80*433d6423SLionel Sambuc 	if (len == MESSAGE) {
81*433d6423SLionel Sambuc 		(void) fprintf(Efs, "%s: (%s, %d) %s\n",
82*433d6423SLionel Sambuc 			Pname,
83*433d6423SLionel Sambuc 			(word == NULL) ? "<none>" : word,
84*433d6423SLionel Sambuc 			narg,
85*433d6423SLionel Sambuc 			(sarg == NULL) ? "<none>" : sarg);
86*433d6423SLionel Sambuc 		return;
87*433d6423SLionel Sambuc 	}
88*433d6423SLionel Sambuc 	(void) fprintf(Efs,
89*433d6423SLionel Sambuc 		"%s: pass3, len=%d, word=\"%s\", sarg=\"%s\", narg=%d%s%s\n",
90*433d6423SLionel Sambuc 		Pname, len,
91*433d6423SLionel Sambuc 		(word == NULL) ? "" : word,
92*433d6423SLionel Sambuc 		(sarg == NULL) ? "" : sarg,
93*433d6423SLionel Sambuc 		narg,
94*433d6423SLionel Sambuc 		(msg == NULL) ? "" : " - ",
95*433d6423SLionel Sambuc 		(msg == NULL) ? "" : msg);
96*433d6423SLionel Sambuc 	Err = 1;
97*433d6423SLionel Sambuc }
98