1433d6423SLionel Sambuc /*
2433d6423SLionel Sambuc * error.c - error handling functions for cawf(1)
3433d6423SLionel Sambuc */
4433d6423SLionel Sambuc
5433d6423SLionel Sambuc /*
6433d6423SLionel Sambuc * Copyright (c) 1991 Purdue University Research Foundation,
7433d6423SLionel Sambuc * West Lafayette, Indiana 47907. All rights reserved.
8433d6423SLionel Sambuc *
9433d6423SLionel Sambuc * Written by Victor A. Abell <abe@mace.cc.purdue.edu>, Purdue
10433d6423SLionel Sambuc * University Computing Center. Not derived from licensed software;
11433d6423SLionel Sambuc * derived from awf(1) by Henry Spencer of the University of Toronto.
12433d6423SLionel Sambuc *
13433d6423SLionel Sambuc * Permission is granted to anyone to use this software for any
14433d6423SLionel Sambuc * purpose on any computer system, and to alter it and redistribute
15433d6423SLionel Sambuc * it freely, subject to the following restrictions:
16433d6423SLionel Sambuc *
17433d6423SLionel Sambuc * 1. The author is not responsible for any consequences of use of
18433d6423SLionel Sambuc * this software, even if they arise from flaws in it.
19433d6423SLionel Sambuc *
20433d6423SLionel Sambuc * 2. The origin of this software must not be misrepresented, either
21433d6423SLionel Sambuc * by explicit claim or by omission. Credits must appear in the
22433d6423SLionel Sambuc * documentation.
23433d6423SLionel Sambuc *
24433d6423SLionel Sambuc * 3. Altered versions must be plainly marked as such, and must not
25433d6423SLionel Sambuc * be misrepresented as being the original software. Credits must
26433d6423SLionel Sambuc * appear in the documentation.
27433d6423SLionel Sambuc *
28433d6423SLionel Sambuc * 4. This notice may not be removed or altered.
29433d6423SLionel Sambuc */
30433d6423SLionel Sambuc
31433d6423SLionel Sambuc #include "cawf.h"
32433d6423SLionel Sambuc
33433d6423SLionel Sambuc
34433d6423SLionel Sambuc /*
35433d6423SLionel Sambuc * Error(t, l, s1, s2) - issue error message
36433d6423SLionel Sambuc */
37433d6423SLionel Sambuc
Error(int t,int l,char * s1,char * s2)38*d9494baaSJacob Adams void Error(int t, int l, char *s1, char *s2) {
39*d9494baaSJacob Adams /* type: WARN or FATAL t
40*d9494baaSJacob Adams * LINE: display Line[] l
41*d9494baaSJacob Adams * optional text s1 and s2
42*d9494baaSJacob Adams */
43433d6423SLionel Sambuc char msg[MAXLINE]; /* message */
44433d6423SLionel Sambuc
45433d6423SLionel Sambuc if (t == WARN && !Dowarn) return;
46433d6423SLionel Sambuc
47433d6423SLionel Sambuc if (l == LINE)
48433d6423SLionel Sambuc (void) fprintf(Efs, "%s: (%s, %d):%s%s - %s\n",
49433d6423SLionel Sambuc Pname,
50433d6423SLionel Sambuc Inname,
51433d6423SLionel Sambuc NR,
52433d6423SLionel Sambuc (s1 == NULL) ? "" : s1,
53433d6423SLionel Sambuc (s2 == NULL) ? "" : s2,
54433d6423SLionel Sambuc Line);
55433d6423SLionel Sambuc else
56433d6423SLionel Sambuc (void) fprintf(Efs, "%s:%s%s\n",
57433d6423SLionel Sambuc Pname,
58433d6423SLionel Sambuc (s1 == NULL) ? "" : s1,
59433d6423SLionel Sambuc (s2 == NULL) ? "" : s2);
60433d6423SLionel Sambuc if (t == FATAL)
61433d6423SLionel Sambuc exit(1);
62433d6423SLionel Sambuc Err = 1;
63433d6423SLionel Sambuc return;
64433d6423SLionel Sambuc }
65433d6423SLionel Sambuc
66433d6423SLionel Sambuc
67433d6423SLionel Sambuc /*
68433d6423SLionel Sambuc * Error3(len, word, sarg, narg) - process error in pass3
69433d6423SLionel Sambuc */
70433d6423SLionel Sambuc
Error3(int len,char * word,char * sarg,int narg,char * msg)71*d9494baaSJacob Adams void Error3(int len, char* word, char *sarg, int narg, char *msg) {
72*d9494baaSJacob Adams /* length (negative is special) len
73*d9494baaSJacob Adams * word word
74*d9494baaSJacob Adams * string argument sarg
75*d9494baaSJacob Adams * numeric argument narg
76*d9494baaSJacob Adams * message msg
77*d9494baaSJacob Adams */
78433d6423SLionel Sambuc if (len == MESSAGE) {
79433d6423SLionel Sambuc (void) fprintf(Efs, "%s: (%s, %d) %s\n",
80433d6423SLionel Sambuc Pname,
81433d6423SLionel Sambuc (word == NULL) ? "<none>" : word,
82433d6423SLionel Sambuc narg,
83433d6423SLionel Sambuc (sarg == NULL) ? "<none>" : sarg);
84433d6423SLionel Sambuc return;
85433d6423SLionel Sambuc }
86433d6423SLionel Sambuc (void) fprintf(Efs,
87433d6423SLionel Sambuc "%s: pass3, len=%d, word=\"%s\", sarg=\"%s\", narg=%d%s%s\n",
88433d6423SLionel Sambuc Pname, len,
89433d6423SLionel Sambuc (word == NULL) ? "" : word,
90433d6423SLionel Sambuc (sarg == NULL) ? "" : sarg,
91433d6423SLionel Sambuc narg,
92433d6423SLionel Sambuc (msg == NULL) ? "" : " - ",
93433d6423SLionel Sambuc (msg == NULL) ? "" : msg);
94433d6423SLionel Sambuc Err = 1;
95433d6423SLionel Sambuc }
96