date and time created 88/07/21 17:35:50 by marc
[unix-history] / usr / src / local / sccscmds / sccscmds.ok / util / fatal.c
CommitLineData
455d17bb
JL
1static char Sccsid[] = "@(#)fatal.c 1.2 %G%";
2
82bd445e
JL
3# include "../hdr/macros.h"
4# include "../hdr/fatal.h"
82bd445e
JL
5
6/*
7 General purpose error handler.
8 Typically, low level subroutines which detect error conditions
9 (an open or create routine, for example) return the
10 value of calling fatal with an appropriate error message string.
11 E.g., return(fatal("can't do it"));
12 Higher level routines control the execution of fatal
13 via the global word Fflags.
14 The macros FSAVE and FRSTR in <fatal.h> can be used by higher
15 level subroutines to save and restore the Fflags word.
16
17 The argument to fatal is a pointer to an error message string.
18 The action of this routine is driven completely from
19 the "Fflags" global word (see <fatal.h>).
20 The following discusses the interpretation of the various bits
21 of Fflags.
22
23 The FTLMSG bit controls the writing of the error
24 message on file descriptor 2. The message is preceded
25 by the string "ERROR: ", unless the global character pointer
26 "Ffile" is non-zero, in which case the message is preceded
27 by the string "ERROR [<Ffile>]: ". A newline is written
28 after the user supplied message.
29
30 If the FTLCLN bit is on, clean_up is called with an
31 argument of 0 (see clean.c).
32
33 If the FTLFUNC bit is on, the function pointed to by the global
34 function pointer "Ffunc" is called with the user supplied
35 error message pointer as argument.
36 (This feature can be used to log error messages).
37
38 The FTLACT bits determine how fatal should return.
39 If the FTLJMP bit is on longjmp(Fjmp) is
40 called (Fjmp is a global vector of 10 words, see
41 setjmp, longjmp documentation).
42
43 If the FTLEXIT bit is on the value of userexit(1) is
44 passed as an argument to exit(II)
45 (see userexit.c).
46
47 If none of the FTLACT bits are on
48 (the default value for Fflags is 0), the global word
49 "Fvalue" (initialized to -1) is returned.
50
51 If all fatal globals have their default values, fatal simply
52 returns -1.
53*/
54
55int Fcnt;
56int Fflags;
57char *Ffile;
455d17bb 58int Fvalue = -1;
82bd445e
JL
59int (*Ffunc)();
60int Fjmp[10];
61
62
63fatal(msg)
64char *msg;
65{
66 ++Fcnt;
67 if (Fflags & FTLMSG) {
68 syswrite(2,"ERROR",5);
69 if (Ffile) {
70 syswrite(2," [",2);
71 syswrite(2,Ffile,length(Ffile));
72 syswrite(2,"]",1);
73 }
74 syswrite(2,": ",2);
75 syswrite(2,msg,length(msg));
76 syswrite(2,"\n",1);
77 }
78 if (Fflags & FTLCLN)
79 clean_up(0);
80 if (Fflags & FTLFUNC)
81 (*Ffunc)(msg);
82 switch (Fflags & FTLACT) {
83 case FTLJMP:
84 longjmp(Fjmp, 1);
85 case FTLEXIT:
86 exit(userexit(1));
87 case FTLRET:
88 return(Fvalue);
89 }
90}