1
/* @(#)ast_error.c 19.1 (ES0-DMD) 02/25/03 13:53:53 */
2
/*===========================================================================
3
Copyright (C) 1995 European Southern Observatory (ESO)
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public
16
License along with this program; if not, write to the Free
17
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
20
Corresponding concerning ESO-MIDAS should be addressed as follows:
21
Internet e-mail: midas@eso.org
22
Postal address: European Southern Observatory
23
Data Management Division
24
Karl-Schwarzschild-Strasse 2
25
D 85748 Garching bei Muenchen
27
===========================================================================*/
29
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
.IDENTIFICATION error.c
33
.AUTHOR Alan Richmond [ST-ECF]
35
.KEYWORDS Error handling.
37
.COMMENTS Error Handler.
38
This module contains the error state: a flag which is TRUE
39
if an error has been reported, and an associated message.
40
In the ST implementation ( import_ST is defined),
41
the error state is passed down to the ST interface.
42
A future implementation may use a/the stack structure; the
43
present version is primarily designed for use with the
44
Dialogue Manager prompting facility, which reports the error
45
to the user. Currently no record of `underlying' errors is
46
required, but this may change.
47
.VERSION 1.0 13-Dec-1985: Creation
48
.VERSION 1.1 28-Apr-1986: check_range added.
49
.VERSION 2.0 23-May-1986: Removed ST staff (at lower level).
50
.VERSION 2.1 12-Jun-1987: Removed bug in eh_ed_str2
52
.VERSION 2.2 25-Jun-1987: Made availabler with SW_Level
53
(0 = Minimal - 1 = Full)
54
.VERSION 2.3 23-Feb-1988: MIDAS compatibility
55
.VERSION 2.4 08-Dec-1988: Truncate text to ensure logged message.
56
Be sure eh_ed_str2 logs the mesage.
57
.VERSION 2.5 14-Jul-1989: Added eh_ed_as, to be sure that null pointers
58
don't result in a crash...
60
-----------------------------*/
66
#define LINESIZE (sizeof(locbuf)-1)
67
/* Maximum size of a line */
69
static char locbuf[81]="";
70
static char error_state = 0;
71
static char avoid[] = "";
72
static int keep_bytes = 0; /* To be sure to get complete message */
73
static int error_lev = _ERROR_; /* Error or Warning Level */
75
/*==========================================================================*/
76
static int edval (x, i)
78
.PURPOSE Edit the long integer number
79
.RETURNS The new index in locbuf
82
long int x; /* IN: Number ot edit */
83
int i; /* IN: Index in locbuf */
87
STATIC char edbuf[12] = " ";
91
for (k = sizeof(edbuf); ;)
92
{ edbuf[--k]= (j%10) + '0';
96
if (x < 0) edbuf[--k] = '-';
98
i += oscopy(&locbuf[i], &edbuf[k], sizeof(edbuf)-k);
102
/*=========================================================================*/
103
/* Public Routines */
104
/*=========================================================================*/
107
.PURPOSE Test for error state, i.e. any error was reported, and not yet cleared
108
.RETURNS 0 if no error, 1 if error exists.
114
/*=========================================================================*/
117
.PURPOSE Define error level for next message
119
.REMARKS Class is _ERROR_ or _WARNING_
121
int class; /* _ERROR_ or _WARNING_ */
128
/*=========================================================================*/
129
int eh_put (subr, message, class)
131
.PURPOSE Store error message.
132
.RETURNS 0 (Not an error) / 1 (Is a error)
133
.REMARKS Class is _ERROR_ or _WARNING_
135
char *subr; /* IN: subroutine name (unused) */
136
char *message; /* IN: message text */
137
int class; /* _ERROR_ or _WARNING_ */
139
return(eh_put2(subr, message, class, strlen(message)));
142
/*=========================================================================*/
143
int eh_put2 (subr, message, class, lmsg)
145
.PURPOSE Store error message.
146
.RETURNS 0 (Not an error) / 1 (Is a error)
147
.REMARKS Class is _ERROR_ or _WARNING_
149
char *subr; /* IN: subroutine name (unused) */
150
char *message; /* IN: message text */
151
int class; /* _ERROR_ or _WARNING_ */
152
int lmsg; /* IN: Length of message */
157
if (!message) return(0); /* No message at all ... */
159
pm_tr2(class, message, lmsg);
161
if (message != locbuf)
162
{ for (p = message, i = 0; (i < LINESIZE) && (*p); )
163
locbuf[i++] = *(p++);
167
if(class == _ERROR_) error_state = 1;
169
error_lev = _ERROR_; /* Error or Warning Level */
174
/*=========================================================================*/
175
char *eh_loc (level, subr, class)
177
.PURPOSE Retrieve address of a stored error message
178
.RETURNS Address of message / NULL if no message
182
char *subr; /* OUT: subroutine name (unused) */
185
return (error_state ? locbuf : NULL_PTR(char));
188
/*=========================================================================*/
191
.PURPOSE Clear error state.
201
/***************************************************************************
203
****************************************************************************/
205
static int eh_ed0(text)
207
.PURPOSE Copies the text to internal buffer
208
.RETURNS Index of first useable character in internal buffer
209
.REMARKS Routine not traced. Leaves at least keep_bytes.
211
char *text; /* IN: text to copy */
216
l = LINESIZE - keep_bytes;
217
for (i=0, p=text; (i < l) && (*p); )
218
locbuf[i++] = *(p++);
219
if ( (*p == '\0') && (*(p-1) != ' '))
220
locbuf[i++] = ' '; /* Add blank */
222
if ( (*p) && (i >= 4) ) /* Too long text... */
224
*(p++) = '.', *(p++) = '.', *(p++) = '.';
231
/*=========================================================================*/
232
int eh_ed_as(text, string)
234
.PURPOSE Error: text followed by EOS string
236
.REMARKS string can be a null pointer.
238
char *text; /* IN: Text to insert */
239
char *string; /* IN: String to insert, terminated with EOS */
243
p = (string ? string : "<NuLL>");
245
return(eh_ed_str2(text, p, strlen(p)));
248
/*=========================================================================*/
249
int eh_ed_str2 (text, string, length)
251
.PURPOSE Error: text followed by string
253
.REMARKS Routine not traced
255
char *text; /* IN: Text to insert */
256
char *string; /* IN: String to insert */
257
int length; /* IN: length of string */
266
for (p = string, l = length; (i < LINESIZE) && (--l >= 0) ; )
267
locbuf[i++] = *(p++);
271
return(eh_put2(avoid, locbuf, error_lev, i));
274
/*=========================================================================*/
275
int eh_ed_i (text, value)
277
.PURPOSE Store error message followed by a number.
279
.REMARKS Routine not traced
281
char *text; /* IN: EOS-terminated Text to insert*/
282
int value; /* IN: value to edit */
290
if (i < LINESIZE - 11)
296
return(eh_put2(avoid, locbuf, error_lev, i));