summaryrefslogtreecommitdiff
path: root/minix/commands/cawf/error.c
blob: 171c017af4adfb740f68489e71f2cb18ffa85eb3 (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
/*
 *	error.c - error handling functions for cawf(1)
 */

/*
 *	Copyright (c) 1991 Purdue University Research Foundation,
 *	West Lafayette, Indiana 47907.  All rights reserved.
 *
 *	Written by Victor A. Abell <abe@mace.cc.purdue.edu>,  Purdue
 *	University Computing Center.  Not derived from licensed software;
 *	derived from awf(1) by Henry Spencer of the University of Toronto.
 *
 *	Permission is granted to anyone to use this software for any
 *	purpose on any computer system, and to alter it and redistribute
 *	it freely, subject to the following restrictions:
 *
 *	1. The author is not responsible for any consequences of use of
 *	   this software, even if they arise from flaws in it.
 *
 *	2. The origin of this software must not be misrepresented, either
 *	   by explicit claim or by omission.  Credits must appear in the
 *	   documentation.
 *
 *	3. Altered versions must be plainly marked as such, and must not
 *	   be misrepresented as being the original software.  Credits must
 *	   appear in the documentation.
 *
 *	4. This notice may not be removed or altered.
 */

#include "cawf.h"


/*
 * Error(t, l, s1, s2) - issue error message
 */

void Error(int t, int l, char *s1, char *s2) {
/* type: WARN or FATAL t
 * LINE: display Line[] l
 * optional text s1 and s2
 */
	char msg[MAXLINE];		/* message */

	if (t == WARN && !Dowarn) return;

	if (l == LINE)
		(void) fprintf(Efs, "%s: (%s, %d):%s%s - %s\n",
			Pname,
			Inname,
			NR,
			(s1 == NULL) ? "" : s1,
			(s2 == NULL) ? "" : s2,
			Line);
	else
		(void) fprintf(Efs, "%s:%s%s\n",
			Pname,
			(s1 == NULL) ? "" : s1,
			(s2 == NULL) ? "" : s2);
	if (t == FATAL)
		exit(1);
	Err = 1;
	return;
}


/*
 * Error3(len, word, sarg, narg) - process error in pass3
 */

void Error3(int len, char* word, char *sarg, int narg, char *msg) {
/* length (negative is special) len
 * word word
 * string argument sarg
 * numeric argument narg
 * message msg
 */
	if (len == MESSAGE) {
		(void) fprintf(Efs, "%s: (%s, %d) %s\n",
			Pname,
			(word == NULL) ? "<none>" : word,
			narg,
			(sarg == NULL) ? "<none>" : sarg);
		return;
	}
	(void) fprintf(Efs,
		"%s: pass3, len=%d, word=\"%s\", sarg=\"%s\", narg=%d%s%s\n",
		Pname, len,
		(word == NULL) ? "" : word,
		(sarg == NULL) ? "" : sarg,
		narg,
		(msg == NULL) ? "" : " - ",
		(msg == NULL) ? "" : msg);
	Err = 1;
}